1 /* 2 * Network device driver for Cell Processor-Based Blade 3 * 4 * (C) Copyright IBM Corp. 2005 5 * 6 * Authors : Utz Bacher <utz.bacher@de.ibm.com> 7 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com> 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2, or (at your option) 12 * any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 */ 23 24 #include <linux/netdevice.h> 25 #include <linux/ethtool.h> 26 #include <linux/pci.h> 27 28 #include "spider_net.h" 29 30 31 static struct { 32 const char str[ETH_GSTRING_LEN]; 33 } ethtool_stats_keys[] = { 34 { "tx_packets" }, 35 { "tx_bytes" }, 36 { "rx_packets" }, 37 { "rx_bytes" }, 38 { "tx_errors" }, 39 { "tx_dropped" }, 40 { "rx_dropped" }, 41 { "rx_descriptor_error" }, 42 { "tx_timeouts" }, 43 { "alloc_rx_skb_error" }, 44 { "rx_iommu_map_error" }, 45 { "tx_iommu_map_error" }, 46 { "rx_desc_unk_state" }, 47 }; 48 49 static int 50 spider_net_ethtool_get_link_ksettings(struct net_device *netdev, 51 struct ethtool_link_ksettings *cmd) 52 { 53 struct spider_net_card *card; 54 card = netdev_priv(netdev); 55 56 ethtool_link_ksettings_zero_link_mode(cmd, supported); 57 ethtool_link_ksettings_add_link_mode(cmd, supported, 1000baseT_Full); 58 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE); 59 60 ethtool_link_ksettings_zero_link_mode(cmd, advertising); 61 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1000baseT_Full); 62 ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE); 63 64 cmd->base.port = PORT_FIBRE; 65 cmd->base.speed = card->phy.speed; 66 cmd->base.duplex = DUPLEX_FULL; 67 68 return 0; 69 } 70 71 static void 72 spider_net_ethtool_get_drvinfo(struct net_device *netdev, 73 struct ethtool_drvinfo *drvinfo) 74 { 75 struct spider_net_card *card; 76 card = netdev_priv(netdev); 77 78 /* clear and fill out info */ 79 strlcpy(drvinfo->driver, spider_net_driver_name, 80 sizeof(drvinfo->driver)); 81 strlcpy(drvinfo->version, VERSION, sizeof(drvinfo->version)); 82 strlcpy(drvinfo->fw_version, "no information", 83 sizeof(drvinfo->fw_version)); 84 strlcpy(drvinfo->bus_info, pci_name(card->pdev), 85 sizeof(drvinfo->bus_info)); 86 } 87 88 static void 89 spider_net_ethtool_get_wol(struct net_device *netdev, 90 struct ethtool_wolinfo *wolinfo) 91 { 92 /* no support for wol */ 93 wolinfo->supported = 0; 94 wolinfo->wolopts = 0; 95 } 96 97 static u32 98 spider_net_ethtool_get_msglevel(struct net_device *netdev) 99 { 100 struct spider_net_card *card; 101 card = netdev_priv(netdev); 102 return card->msg_enable; 103 } 104 105 static void 106 spider_net_ethtool_set_msglevel(struct net_device *netdev, 107 u32 level) 108 { 109 struct spider_net_card *card; 110 card = netdev_priv(netdev); 111 card->msg_enable = level; 112 } 113 114 static int 115 spider_net_ethtool_nway_reset(struct net_device *netdev) 116 { 117 if (netif_running(netdev)) { 118 spider_net_stop(netdev); 119 spider_net_open(netdev); 120 } 121 return 0; 122 } 123 124 static void 125 spider_net_ethtool_get_ringparam(struct net_device *netdev, 126 struct ethtool_ringparam *ering) 127 { 128 struct spider_net_card *card = netdev_priv(netdev); 129 130 ering->tx_max_pending = SPIDER_NET_TX_DESCRIPTORS_MAX; 131 ering->tx_pending = card->tx_chain.num_desc; 132 ering->rx_max_pending = SPIDER_NET_RX_DESCRIPTORS_MAX; 133 ering->rx_pending = card->rx_chain.num_desc; 134 } 135 136 static int spider_net_get_sset_count(struct net_device *netdev, int sset) 137 { 138 switch (sset) { 139 case ETH_SS_STATS: 140 return ARRAY_SIZE(ethtool_stats_keys); 141 default: 142 return -EOPNOTSUPP; 143 } 144 } 145 146 static void spider_net_get_ethtool_stats(struct net_device *netdev, 147 struct ethtool_stats *stats, u64 *data) 148 { 149 struct spider_net_card *card = netdev_priv(netdev); 150 151 data[0] = netdev->stats.tx_packets; 152 data[1] = netdev->stats.tx_bytes; 153 data[2] = netdev->stats.rx_packets; 154 data[3] = netdev->stats.rx_bytes; 155 data[4] = netdev->stats.tx_errors; 156 data[5] = netdev->stats.tx_dropped; 157 data[6] = netdev->stats.rx_dropped; 158 data[7] = card->spider_stats.rx_desc_error; 159 data[8] = card->spider_stats.tx_timeouts; 160 data[9] = card->spider_stats.alloc_rx_skb_error; 161 data[10] = card->spider_stats.rx_iommu_map_error; 162 data[11] = card->spider_stats.tx_iommu_map_error; 163 data[12] = card->spider_stats.rx_desc_unk_state; 164 } 165 166 static void spider_net_get_strings(struct net_device *netdev, u32 stringset, 167 u8 *data) 168 { 169 memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys)); 170 } 171 172 const struct ethtool_ops spider_net_ethtool_ops = { 173 .get_drvinfo = spider_net_ethtool_get_drvinfo, 174 .get_wol = spider_net_ethtool_get_wol, 175 .get_msglevel = spider_net_ethtool_get_msglevel, 176 .set_msglevel = spider_net_ethtool_set_msglevel, 177 .get_link = ethtool_op_get_link, 178 .nway_reset = spider_net_ethtool_nway_reset, 179 .get_ringparam = spider_net_ethtool_get_ringparam, 180 .get_strings = spider_net_get_strings, 181 .get_sset_count = spider_net_get_sset_count, 182 .get_ethtool_stats = spider_net_get_ethtool_stats, 183 .get_link_ksettings = spider_net_ethtool_get_link_ksettings, 184 }; 185 186