0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/netdevice.h>
0010 #include <linux/ethtool.h>
0011 #include <linux/pci.h>
0012
0013 #include <asm/pasemi_dma.h>
0014 #include "pasemi_mac.h"
0015
0016 static struct {
0017 const char str[ETH_GSTRING_LEN];
0018 } ethtool_stats_keys[] = {
0019 { "rx-drops" },
0020 { "rx-bytes" },
0021 { "rx-packets" },
0022 { "rx-broadcast-packets" },
0023 { "rx-multicast-packets" },
0024 { "rx-crc-errors" },
0025 { "rx-undersize-errors" },
0026 { "rx-oversize-errors" },
0027 { "rx-short-fragment-errors" },
0028 { "rx-jabber-errors" },
0029 { "rx-64-byte-packets" },
0030 { "rx-65-127-byte-packets" },
0031 { "rx-128-255-byte-packets" },
0032 { "rx-256-511-byte-packets" },
0033 { "rx-512-1023-byte-packets" },
0034 { "rx-1024-1518-byte-packets" },
0035 { "rx-pause-frames" },
0036 { "tx-bytes" },
0037 { "tx-packets" },
0038 { "tx-broadcast-packets" },
0039 { "tx-multicast-packets" },
0040 { "tx-collisions" },
0041 { "tx-late-collisions" },
0042 { "tx-excessive-collisions" },
0043 { "tx-crc-errors" },
0044 { "tx-undersize-errors" },
0045 { "tx-oversize-errors" },
0046 { "tx-64-byte-packets" },
0047 { "tx-65-127-byte-packets" },
0048 { "tx-128-255-byte-packets" },
0049 { "tx-256-511-byte-packets" },
0050 { "tx-512-1023-byte-packets" },
0051 { "tx-1024-1518-byte-packets" },
0052 };
0053
0054 static u32
0055 pasemi_mac_ethtool_get_msglevel(struct net_device *netdev)
0056 {
0057 struct pasemi_mac *mac = netdev_priv(netdev);
0058 return mac->msg_enable;
0059 }
0060
0061 static void
0062 pasemi_mac_ethtool_set_msglevel(struct net_device *netdev,
0063 u32 level)
0064 {
0065 struct pasemi_mac *mac = netdev_priv(netdev);
0066 mac->msg_enable = level;
0067 }
0068
0069
0070 static void
0071 pasemi_mac_ethtool_get_ringparam(struct net_device *netdev,
0072 struct ethtool_ringparam *ering,
0073 struct kernel_ethtool_ringparam *kernel_ering,
0074 struct netlink_ext_ack *extack)
0075 {
0076 struct pasemi_mac *mac = netdev_priv(netdev);
0077
0078 ering->tx_max_pending = TX_RING_SIZE/2;
0079 ering->tx_pending = RING_USED(mac->tx)/2;
0080 ering->rx_max_pending = RX_RING_SIZE/4;
0081 ering->rx_pending = RING_USED(mac->rx)/4;
0082 }
0083
0084 static int pasemi_mac_get_sset_count(struct net_device *netdev, int sset)
0085 {
0086 switch (sset) {
0087 case ETH_SS_STATS:
0088 return ARRAY_SIZE(ethtool_stats_keys);
0089 default:
0090 return -EOPNOTSUPP;
0091 }
0092 }
0093
0094 static void pasemi_mac_get_ethtool_stats(struct net_device *netdev,
0095 struct ethtool_stats *stats, u64 *data)
0096 {
0097 struct pasemi_mac *mac = netdev_priv(netdev);
0098 int i;
0099
0100 data[0] = pasemi_read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if))
0101 >> PAS_DMA_RXINT_RCMDSTA_DROPS_S;
0102 for (i = 0; i < 32; i++)
0103 data[1+i] = pasemi_read_mac_reg(mac->dma_if, PAS_MAC_RMON(i));
0104 }
0105
0106 static void pasemi_mac_get_strings(struct net_device *netdev, u32 stringset,
0107 u8 *data)
0108 {
0109 memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
0110 }
0111
0112 const struct ethtool_ops pasemi_mac_ethtool_ops = {
0113 .get_msglevel = pasemi_mac_ethtool_get_msglevel,
0114 .set_msglevel = pasemi_mac_ethtool_set_msglevel,
0115 .get_link = ethtool_op_get_link,
0116 .get_ringparam = pasemi_mac_ethtool_get_ringparam,
0117 .get_strings = pasemi_mac_get_strings,
0118 .get_sset_count = pasemi_mac_get_sset_count,
0119 .get_ethtool_stats = pasemi_mac_get_ethtool_stats,
0120 .get_link_ksettings = phy_ethtool_get_link_ksettings,
0121 .set_link_ksettings = phy_ethtool_set_link_ksettings,
0122 };
0123