1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Network device driver for Cell Processor-Based Blade 4 * 5 * (C) Copyright IBM Corp. 2005 6 * 7 * Authors : Utz Bacher <utz.bacher@de.ibm.com> 8 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com> 9 */ 10 11 #include <linux/netdevice.h> 12 #include <linux/ethtool.h> 13 #include <linux/pci.h> 14 15 #include "spider_net.h" 16 17 18 static struct { 19 const char str[ETH_GSTRING_LEN]; 20 } ethtool_stats_keys[] = { 21 { "tx_packets" }, 22 { "tx_bytes" }, 23 { "rx_packets" }, 24 { "rx_bytes" }, 25 { "tx_errors" }, 26 { "tx_dropped" }, 27 { "rx_dropped" }, 28 { "rx_descriptor_error" }, 29 { "tx_timeouts" }, 30 { "alloc_rx_skb_error" }, 31 { "rx_iommu_map_error" }, 32 { "tx_iommu_map_error" }, 33 { "rx_desc_unk_state" }, 34 }; 35 36 static int 37 spider_net_ethtool_get_link_ksettings(struct net_device *netdev, 38 struct ethtool_link_ksettings *cmd) 39 { 40 struct spider_net_card *card; 41 card = netdev_priv(netdev); 42 43 ethtool_link_ksettings_zero_link_mode(cmd, supported); 44 ethtool_link_ksettings_add_link_mode(cmd, supported, 1000baseT_Full); 45 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE); 46 47 ethtool_link_ksettings_zero_link_mode(cmd, advertising); 48 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1000baseT_Full); 49 ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE); 50 51 cmd->base.port = PORT_FIBRE; 52 cmd->base.speed = card->phy.speed; 53 cmd->base.duplex = DUPLEX_FULL; 54 55 return 0; 56 } 57 58 static void 59 spider_net_ethtool_get_drvinfo(struct net_device *netdev, 60 struct ethtool_drvinfo *drvinfo) 61 { 62 struct spider_net_card *card; 63 card = netdev_priv(netdev); 64 65 /* clear and fill out info */ 66 strlcpy(drvinfo->driver, spider_net_driver_name, 67 sizeof(drvinfo->driver)); 68 strlcpy(drvinfo->version, VERSION, sizeof(drvinfo->version)); 69 strlcpy(drvinfo->fw_version, "no information", 70 sizeof(drvinfo->fw_version)); 71 strlcpy(drvinfo->bus_info, pci_name(card->pdev), 72 sizeof(drvinfo->bus_info)); 73 } 74 75 static void 76 spider_net_ethtool_get_wol(struct net_device *netdev, 77 struct ethtool_wolinfo *wolinfo) 78 { 79 /* no support for wol */ 80 wolinfo->supported = 0; 81 wolinfo->wolopts = 0; 82 } 83 84 static u32 85 spider_net_ethtool_get_msglevel(struct net_device *netdev) 86 { 87 struct spider_net_card *card; 88 card = netdev_priv(netdev); 89 return card->msg_enable; 90 } 91 92 static void 93 spider_net_ethtool_set_msglevel(struct net_device *netdev, 94 u32 level) 95 { 96 struct spider_net_card *card; 97 card = netdev_priv(netdev); 98 card->msg_enable = level; 99 } 100 101 static int 102 spider_net_ethtool_nway_reset(struct net_device *netdev) 103 { 104 if (netif_running(netdev)) { 105 spider_net_stop(netdev); 106 spider_net_open(netdev); 107 } 108 return 0; 109 } 110 111 static void 112 spider_net_ethtool_get_ringparam(struct net_device *netdev, 113 struct ethtool_ringparam *ering) 114 { 115 struct spider_net_card *card = netdev_priv(netdev); 116 117 ering->tx_max_pending = SPIDER_NET_TX_DESCRIPTORS_MAX; 118 ering->tx_pending = card->tx_chain.num_desc; 119 ering->rx_max_pending = SPIDER_NET_RX_DESCRIPTORS_MAX; 120 ering->rx_pending = card->rx_chain.num_desc; 121 } 122 123 static int spider_net_get_sset_count(struct net_device *netdev, int sset) 124 { 125 switch (sset) { 126 case ETH_SS_STATS: 127 return ARRAY_SIZE(ethtool_stats_keys); 128 default: 129 return -EOPNOTSUPP; 130 } 131 } 132 133 static void spider_net_get_ethtool_stats(struct net_device *netdev, 134 struct ethtool_stats *stats, u64 *data) 135 { 136 struct spider_net_card *card = netdev_priv(netdev); 137 138 data[0] = netdev->stats.tx_packets; 139 data[1] = netdev->stats.tx_bytes; 140 data[2] = netdev->stats.rx_packets; 141 data[3] = netdev->stats.rx_bytes; 142 data[4] = netdev->stats.tx_errors; 143 data[5] = netdev->stats.tx_dropped; 144 data[6] = netdev->stats.rx_dropped; 145 data[7] = card->spider_stats.rx_desc_error; 146 data[8] = card->spider_stats.tx_timeouts; 147 data[9] = card->spider_stats.alloc_rx_skb_error; 148 data[10] = card->spider_stats.rx_iommu_map_error; 149 data[11] = card->spider_stats.tx_iommu_map_error; 150 data[12] = card->spider_stats.rx_desc_unk_state; 151 } 152 153 static void spider_net_get_strings(struct net_device *netdev, u32 stringset, 154 u8 *data) 155 { 156 memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys)); 157 } 158 159 const struct ethtool_ops spider_net_ethtool_ops = { 160 .get_drvinfo = spider_net_ethtool_get_drvinfo, 161 .get_wol = spider_net_ethtool_get_wol, 162 .get_msglevel = spider_net_ethtool_get_msglevel, 163 .set_msglevel = spider_net_ethtool_set_msglevel, 164 .get_link = ethtool_op_get_link, 165 .nway_reset = spider_net_ethtool_nway_reset, 166 .get_ringparam = spider_net_ethtool_get_ringparam, 167 .get_strings = spider_net_get_strings, 168 .get_sset_count = spider_net_get_sset_count, 169 .get_ethtool_stats = spider_net_get_ethtool_stats, 170 .get_link_ksettings = spider_net_ethtool_get_link_ksettings, 171 }; 172 173