Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | |
| 4 | Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the Free |
| 8 | Software Foundation; either version 2 of the License, or (at your option) |
| 9 | any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License along with |
| 17 | this program; if not, write to the Free Software Foundation, Inc., 59 |
| 18 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | |
| 20 | The full GNU General Public License is included in this distribution in the |
| 21 | file called LICENSE. |
| 22 | |
| 23 | Contact Information: |
| 24 | Linux NICS <linux.nics@intel.com> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | /* ethtool support for ixgb */ |
| 30 | |
| 31 | #include "ixgb.h" |
| 32 | |
| 33 | #include <asm/uaccess.h> |
| 34 | |
| 35 | extern char ixgb_driver_name[]; |
| 36 | extern char ixgb_driver_version[]; |
| 37 | |
| 38 | extern int ixgb_up(struct ixgb_adapter *adapter); |
| 39 | extern void ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog); |
| 40 | extern void ixgb_reset(struct ixgb_adapter *adapter); |
| 41 | extern int ixgb_setup_rx_resources(struct ixgb_adapter *adapter); |
| 42 | extern int ixgb_setup_tx_resources(struct ixgb_adapter *adapter); |
| 43 | extern void ixgb_free_rx_resources(struct ixgb_adapter *adapter); |
| 44 | extern void ixgb_free_tx_resources(struct ixgb_adapter *adapter); |
| 45 | extern void ixgb_update_stats(struct ixgb_adapter *adapter); |
| 46 | |
Auke Kok | c85fd6f | 2006-05-23 10:30:02 -0700 | [diff] [blame] | 47 | #define IXGB_ALL_RAR_ENTRIES 16 |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | struct ixgb_stats { |
| 50 | char stat_string[ETH_GSTRING_LEN]; |
| 51 | int sizeof_stat; |
| 52 | int stat_offset; |
| 53 | }; |
| 54 | |
| 55 | #define IXGB_STAT(m) sizeof(((struct ixgb_adapter *)0)->m), \ |
| 56 | offsetof(struct ixgb_adapter, m) |
| 57 | static struct ixgb_stats ixgb_gstrings_stats[] = { |
| 58 | {"rx_packets", IXGB_STAT(net_stats.rx_packets)}, |
| 59 | {"tx_packets", IXGB_STAT(net_stats.tx_packets)}, |
| 60 | {"rx_bytes", IXGB_STAT(net_stats.rx_bytes)}, |
| 61 | {"tx_bytes", IXGB_STAT(net_stats.tx_bytes)}, |
| 62 | {"rx_errors", IXGB_STAT(net_stats.rx_errors)}, |
| 63 | {"tx_errors", IXGB_STAT(net_stats.tx_errors)}, |
| 64 | {"rx_dropped", IXGB_STAT(net_stats.rx_dropped)}, |
| 65 | {"tx_dropped", IXGB_STAT(net_stats.tx_dropped)}, |
| 66 | {"multicast", IXGB_STAT(net_stats.multicast)}, |
| 67 | {"collisions", IXGB_STAT(net_stats.collisions)}, |
| 68 | |
| 69 | /* { "rx_length_errors", IXGB_STAT(net_stats.rx_length_errors) }, */ |
| 70 | {"rx_over_errors", IXGB_STAT(net_stats.rx_over_errors)}, |
| 71 | {"rx_crc_errors", IXGB_STAT(net_stats.rx_crc_errors)}, |
| 72 | {"rx_frame_errors", IXGB_STAT(net_stats.rx_frame_errors)}, |
| 73 | {"rx_fifo_errors", IXGB_STAT(net_stats.rx_fifo_errors)}, |
| 74 | {"rx_missed_errors", IXGB_STAT(net_stats.rx_missed_errors)}, |
| 75 | {"tx_aborted_errors", IXGB_STAT(net_stats.tx_aborted_errors)}, |
| 76 | {"tx_carrier_errors", IXGB_STAT(net_stats.tx_carrier_errors)}, |
| 77 | {"tx_fifo_errors", IXGB_STAT(net_stats.tx_fifo_errors)}, |
| 78 | {"tx_heartbeat_errors", IXGB_STAT(net_stats.tx_heartbeat_errors)}, |
| 79 | {"tx_window_errors", IXGB_STAT(net_stats.tx_window_errors)}, |
| 80 | {"tx_deferred_ok", IXGB_STAT(stats.dc)}, |
| 81 | {"rx_long_length_errors", IXGB_STAT(stats.roc)}, |
| 82 | {"rx_short_length_errors", IXGB_STAT(stats.ruc)}, |
| 83 | #ifdef NETIF_F_TSO |
| 84 | {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)}, |
| 85 | {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)}, |
| 86 | #endif |
| 87 | {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)}, |
| 88 | {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)}, |
| 89 | {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)}, |
| 90 | {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)}, |
| 91 | {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)}, |
| 92 | {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)}, |
| 93 | {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)}, |
| 94 | {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)} |
| 95 | }; |
| 96 | |
| 97 | #define IXGB_STATS_LEN \ |
| 98 | sizeof(ixgb_gstrings_stats) / sizeof(struct ixgb_stats) |
| 99 | |
| 100 | static int |
| 101 | ixgb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 102 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 103 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); |
Malli Chilakala | db0baca | 2005-08-11 13:59:20 -0700 | [diff] [blame] | 106 | ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | ecmd->port = PORT_FIBRE; |
| 108 | ecmd->transceiver = XCVR_EXTERNAL; |
| 109 | |
| 110 | if(netif_carrier_ok(adapter->netdev)) { |
| 111 | ecmd->speed = SPEED_10000; |
| 112 | ecmd->duplex = DUPLEX_FULL; |
| 113 | } else { |
| 114 | ecmd->speed = -1; |
| 115 | ecmd->duplex = -1; |
| 116 | } |
| 117 | |
| 118 | ecmd->autoneg = AUTONEG_DISABLE; |
| 119 | return 0; |
| 120 | } |
| 121 | |
Auke Kok | 4de17c8 | 2006-05-23 10:29:46 -0700 | [diff] [blame] | 122 | static void ixgb_set_speed_duplex(struct net_device *netdev) |
| 123 | { |
| 124 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
| 125 | /* be optimistic about our link, since we were up before */ |
| 126 | adapter->link_speed = 10000; |
| 127 | adapter->link_duplex = FULL_DUPLEX; |
| 128 | netif_carrier_on(netdev); |
| 129 | netif_wake_queue(netdev); |
| 130 | } |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | static int |
| 133 | ixgb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 134 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 135 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | if(ecmd->autoneg == AUTONEG_ENABLE || |
| 138 | ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL) |
| 139 | return -EINVAL; |
| 140 | |
| 141 | if(netif_running(adapter->netdev)) { |
| 142 | ixgb_down(adapter, TRUE); |
| 143 | ixgb_reset(adapter); |
| 144 | ixgb_up(adapter); |
Auke Kok | 4de17c8 | 2006-05-23 10:29:46 -0700 | [diff] [blame] | 145 | ixgb_set_speed_duplex(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } else |
| 147 | ixgb_reset(adapter); |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static void |
| 153 | ixgb_get_pauseparam(struct net_device *netdev, |
| 154 | struct ethtool_pauseparam *pause) |
| 155 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 156 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | struct ixgb_hw *hw = &adapter->hw; |
| 158 | |
| 159 | pause->autoneg = AUTONEG_DISABLE; |
| 160 | |
| 161 | if(hw->fc.type == ixgb_fc_rx_pause) |
| 162 | pause->rx_pause = 1; |
| 163 | else if(hw->fc.type == ixgb_fc_tx_pause) |
| 164 | pause->tx_pause = 1; |
| 165 | else if(hw->fc.type == ixgb_fc_full) { |
| 166 | pause->rx_pause = 1; |
| 167 | pause->tx_pause = 1; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | static int |
| 172 | ixgb_set_pauseparam(struct net_device *netdev, |
| 173 | struct ethtool_pauseparam *pause) |
| 174 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 175 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | struct ixgb_hw *hw = &adapter->hw; |
| 177 | |
| 178 | if(pause->autoneg == AUTONEG_ENABLE) |
| 179 | return -EINVAL; |
| 180 | |
| 181 | if(pause->rx_pause && pause->tx_pause) |
| 182 | hw->fc.type = ixgb_fc_full; |
| 183 | else if(pause->rx_pause && !pause->tx_pause) |
| 184 | hw->fc.type = ixgb_fc_rx_pause; |
| 185 | else if(!pause->rx_pause && pause->tx_pause) |
| 186 | hw->fc.type = ixgb_fc_tx_pause; |
| 187 | else if(!pause->rx_pause && !pause->tx_pause) |
| 188 | hw->fc.type = ixgb_fc_none; |
| 189 | |
| 190 | if(netif_running(adapter->netdev)) { |
| 191 | ixgb_down(adapter, TRUE); |
| 192 | ixgb_up(adapter); |
Auke Kok | 4de17c8 | 2006-05-23 10:29:46 -0700 | [diff] [blame] | 193 | ixgb_set_speed_duplex(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } else |
| 195 | ixgb_reset(adapter); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static uint32_t |
| 201 | ixgb_get_rx_csum(struct net_device *netdev) |
| 202 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 203 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return adapter->rx_csum; |
| 206 | } |
| 207 | |
| 208 | static int |
| 209 | ixgb_set_rx_csum(struct net_device *netdev, uint32_t data) |
| 210 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 211 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
| 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | adapter->rx_csum = data; |
| 214 | |
| 215 | if(netif_running(netdev)) { |
| 216 | ixgb_down(adapter,TRUE); |
| 217 | ixgb_up(adapter); |
Auke Kok | 4de17c8 | 2006-05-23 10:29:46 -0700 | [diff] [blame] | 218 | ixgb_set_speed_duplex(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } else |
| 220 | ixgb_reset(adapter); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | static uint32_t |
| 225 | ixgb_get_tx_csum(struct net_device *netdev) |
| 226 | { |
| 227 | return (netdev->features & NETIF_F_HW_CSUM) != 0; |
| 228 | } |
| 229 | |
| 230 | static int |
| 231 | ixgb_set_tx_csum(struct net_device *netdev, uint32_t data) |
| 232 | { |
| 233 | if (data) |
| 234 | netdev->features |= NETIF_F_HW_CSUM; |
| 235 | else |
| 236 | netdev->features &= ~NETIF_F_HW_CSUM; |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | #ifdef NETIF_F_TSO |
| 242 | static int |
| 243 | ixgb_set_tso(struct net_device *netdev, uint32_t data) |
| 244 | { |
| 245 | if(data) |
| 246 | netdev->features |= NETIF_F_TSO; |
| 247 | else |
| 248 | netdev->features &= ~NETIF_F_TSO; |
| 249 | return 0; |
| 250 | } |
| 251 | #endif /* NETIF_F_TSO */ |
| 252 | |
Auke Kok | ec9c3f5 | 2006-05-23 10:34:59 -0700 | [diff] [blame^] | 253 | static uint32_t |
| 254 | ixgb_get_msglevel(struct net_device *netdev) |
| 255 | { |
| 256 | struct ixgb_adapter *adapter = netdev->priv; |
| 257 | return adapter->msg_enable; |
| 258 | } |
| 259 | |
| 260 | static void |
| 261 | ixgb_set_msglevel(struct net_device *netdev, uint32_t data) |
| 262 | { |
| 263 | struct ixgb_adapter *adapter = netdev->priv; |
| 264 | adapter->msg_enable = data; |
| 265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | #define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_ |
| 267 | |
| 268 | static int |
| 269 | ixgb_get_regs_len(struct net_device *netdev) |
| 270 | { |
| 271 | #define IXGB_REG_DUMP_LEN 136*sizeof(uint32_t) |
| 272 | return IXGB_REG_DUMP_LEN; |
| 273 | } |
| 274 | |
| 275 | static void |
| 276 | ixgb_get_regs(struct net_device *netdev, |
| 277 | struct ethtool_regs *regs, void *p) |
| 278 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 279 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | struct ixgb_hw *hw = &adapter->hw; |
| 281 | uint32_t *reg = p; |
| 282 | uint32_t *reg_start = reg; |
| 283 | uint8_t i; |
| 284 | |
Malli Chilakala | 5e3c30d | 2005-04-28 19:04:07 -0700 | [diff] [blame] | 285 | /* the 1 (one) below indicates an attempt at versioning, if the |
Malli Chilakala | ab707da | 2005-08-11 13:59:59 -0700 | [diff] [blame] | 286 | * interface in ethtool or the driver changes, this 1 should be |
| 287 | * incremented */ |
Malli Chilakala | 5e3c30d | 2005-04-28 19:04:07 -0700 | [diff] [blame] | 288 | regs->version = (1<<24) | hw->revision_id << 16 | hw->device_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | /* General Registers */ |
| 291 | *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */ |
| 292 | *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */ |
| 293 | *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */ |
| 294 | *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */ |
| 295 | *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */ |
| 296 | |
| 297 | /* Interrupt */ |
| 298 | *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */ |
| 299 | *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */ |
| 300 | *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */ |
| 301 | *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */ |
| 302 | |
| 303 | /* Receive */ |
| 304 | *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */ |
| 305 | *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */ |
| 306 | *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */ |
| 307 | *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */ |
| 308 | *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */ |
| 309 | *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */ |
| 310 | *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */ |
| 311 | *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */ |
| 312 | *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */ |
| 313 | *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */ |
| 314 | *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */ |
| 315 | *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */ |
| 316 | |
Malli Chilakala | 9ef2eec | 2005-08-11 13:59:07 -0700 | [diff] [blame] | 317 | /* there are 16 RAR entries in hardware, we only use 3 */ |
Auke Kok | c85fd6f | 2006-05-23 10:30:02 -0700 | [diff] [blame] | 318 | for(i = 0; i < IXGB_ALL_RAR_ENTRIES; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */ |
| 320 | *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */ |
| 321 | } |
| 322 | |
| 323 | /* Transmit */ |
| 324 | *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */ |
| 325 | *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */ |
| 326 | *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */ |
| 327 | *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */ |
| 328 | *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */ |
| 329 | *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */ |
| 330 | *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */ |
| 331 | *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */ |
| 332 | *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */ |
| 333 | *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */ |
| 334 | |
| 335 | /* Physical */ |
| 336 | *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */ |
| 337 | *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */ |
| 338 | *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */ |
| 339 | *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */ |
| 340 | *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */ |
| 341 | *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */ |
| 342 | *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */ |
| 343 | *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */ |
| 344 | *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */ |
| 345 | *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */ |
| 346 | *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */ |
| 347 | *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */ |
| 348 | *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */ |
| 349 | |
| 350 | /* Statistics */ |
| 351 | *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */ |
| 352 | *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */ |
| 353 | *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */ |
| 354 | *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */ |
| 355 | *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */ |
| 356 | *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */ |
| 357 | *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */ |
| 358 | *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */ |
| 359 | *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */ |
| 360 | *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */ |
| 361 | *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */ |
| 362 | *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */ |
| 363 | *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */ |
| 364 | *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */ |
| 365 | *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */ |
| 366 | *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */ |
| 367 | *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */ |
| 368 | *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */ |
| 369 | *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */ |
| 370 | *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */ |
| 371 | *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */ |
| 372 | *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */ |
| 373 | *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */ |
| 374 | *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */ |
| 375 | *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */ |
| 376 | *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */ |
| 377 | *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */ |
| 378 | *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */ |
| 379 | *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */ |
| 380 | *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */ |
| 381 | *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */ |
| 382 | *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */ |
| 383 | *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */ |
| 384 | *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */ |
| 385 | *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */ |
| 386 | *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */ |
| 387 | *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */ |
| 388 | *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */ |
| 389 | *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */ |
| 390 | *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */ |
| 391 | *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */ |
| 392 | *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */ |
| 393 | *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */ |
| 394 | *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */ |
| 395 | *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */ |
| 396 | *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */ |
| 397 | *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */ |
| 398 | *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */ |
| 399 | *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */ |
| 400 | *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */ |
| 401 | *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */ |
| 402 | *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */ |
| 403 | *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */ |
| 404 | *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */ |
| 405 | *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */ |
| 406 | *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */ |
| 407 | *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */ |
| 408 | *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */ |
| 409 | *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */ |
| 410 | *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */ |
| 411 | |
| 412 | regs->len = (reg - reg_start) * sizeof(uint32_t); |
| 413 | } |
| 414 | |
| 415 | static int |
| 416 | ixgb_get_eeprom_len(struct net_device *netdev) |
| 417 | { |
| 418 | /* return size in bytes */ |
| 419 | return (IXGB_EEPROM_SIZE << 1); |
| 420 | } |
| 421 | |
| 422 | static int |
| 423 | ixgb_get_eeprom(struct net_device *netdev, |
| 424 | struct ethtool_eeprom *eeprom, uint8_t *bytes) |
| 425 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 426 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | struct ixgb_hw *hw = &adapter->hw; |
| 428 | uint16_t *eeprom_buff; |
| 429 | int i, max_len, first_word, last_word; |
| 430 | int ret_val = 0; |
| 431 | |
| 432 | if(eeprom->len == 0) { |
| 433 | ret_val = -EINVAL; |
| 434 | goto geeprom_error; |
| 435 | } |
| 436 | |
| 437 | eeprom->magic = hw->vendor_id | (hw->device_id << 16); |
| 438 | |
| 439 | max_len = ixgb_get_eeprom_len(netdev); |
| 440 | |
| 441 | if(eeprom->offset > eeprom->offset + eeprom->len) { |
| 442 | ret_val = -EINVAL; |
| 443 | goto geeprom_error; |
| 444 | } |
| 445 | |
| 446 | if((eeprom->offset + eeprom->len) > max_len) |
| 447 | eeprom->len = (max_len - eeprom->offset); |
| 448 | |
| 449 | first_word = eeprom->offset >> 1; |
| 450 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
| 451 | |
| 452 | eeprom_buff = kmalloc(sizeof(uint16_t) * |
| 453 | (last_word - first_word + 1), GFP_KERNEL); |
| 454 | if(!eeprom_buff) |
| 455 | return -ENOMEM; |
| 456 | |
| 457 | /* note the eeprom was good because the driver loaded */ |
| 458 | for(i = 0; i <= (last_word - first_word); i++) { |
| 459 | eeprom_buff[i] = ixgb_get_eeprom_word(hw, (first_word + i)); |
| 460 | } |
| 461 | |
| 462 | memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1), |
| 463 | eeprom->len); |
| 464 | kfree(eeprom_buff); |
| 465 | |
| 466 | geeprom_error: |
| 467 | return ret_val; |
| 468 | } |
| 469 | |
| 470 | static int |
| 471 | ixgb_set_eeprom(struct net_device *netdev, |
| 472 | struct ethtool_eeprom *eeprom, uint8_t *bytes) |
| 473 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 474 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | struct ixgb_hw *hw = &adapter->hw; |
| 476 | uint16_t *eeprom_buff; |
| 477 | void *ptr; |
| 478 | int max_len, first_word, last_word; |
| 479 | uint16_t i; |
| 480 | |
| 481 | if(eeprom->len == 0) |
| 482 | return -EINVAL; |
| 483 | |
| 484 | if(eeprom->magic != (hw->vendor_id | (hw->device_id << 16))) |
| 485 | return -EFAULT; |
| 486 | |
| 487 | max_len = ixgb_get_eeprom_len(netdev); |
| 488 | |
| 489 | if(eeprom->offset > eeprom->offset + eeprom->len) |
| 490 | return -EINVAL; |
| 491 | |
| 492 | if((eeprom->offset + eeprom->len) > max_len) |
| 493 | eeprom->len = (max_len - eeprom->offset); |
| 494 | |
| 495 | first_word = eeprom->offset >> 1; |
| 496 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
| 497 | eeprom_buff = kmalloc(max_len, GFP_KERNEL); |
| 498 | if(!eeprom_buff) |
| 499 | return -ENOMEM; |
| 500 | |
| 501 | ptr = (void *)eeprom_buff; |
| 502 | |
| 503 | if(eeprom->offset & 1) { |
| 504 | /* need read/modify/write of first changed EEPROM word */ |
| 505 | /* only the second byte of the word is being modified */ |
| 506 | eeprom_buff[0] = ixgb_read_eeprom(hw, first_word); |
| 507 | ptr++; |
| 508 | } |
| 509 | if((eeprom->offset + eeprom->len) & 1) { |
| 510 | /* need read/modify/write of last changed EEPROM word */ |
| 511 | /* only the first byte of the word is being modified */ |
| 512 | eeprom_buff[last_word - first_word] |
| 513 | = ixgb_read_eeprom(hw, last_word); |
| 514 | } |
| 515 | |
| 516 | memcpy(ptr, bytes, eeprom->len); |
| 517 | for(i = 0; i <= (last_word - first_word); i++) |
| 518 | ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]); |
| 519 | |
| 520 | /* Update the checksum over the first part of the EEPROM if needed */ |
| 521 | if(first_word <= EEPROM_CHECKSUM_REG) |
| 522 | ixgb_update_eeprom_checksum(hw); |
| 523 | |
| 524 | kfree(eeprom_buff); |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | static void |
| 529 | ixgb_get_drvinfo(struct net_device *netdev, |
| 530 | struct ethtool_drvinfo *drvinfo) |
| 531 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 532 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | strncpy(drvinfo->driver, ixgb_driver_name, 32); |
| 535 | strncpy(drvinfo->version, ixgb_driver_version, 32); |
| 536 | strncpy(drvinfo->fw_version, "N/A", 32); |
| 537 | strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32); |
| 538 | drvinfo->n_stats = IXGB_STATS_LEN; |
| 539 | drvinfo->regdump_len = ixgb_get_regs_len(netdev); |
| 540 | drvinfo->eedump_len = ixgb_get_eeprom_len(netdev); |
| 541 | } |
| 542 | |
| 543 | static void |
| 544 | ixgb_get_ringparam(struct net_device *netdev, |
| 545 | struct ethtool_ringparam *ring) |
| 546 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 547 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | struct ixgb_desc_ring *txdr = &adapter->tx_ring; |
| 549 | struct ixgb_desc_ring *rxdr = &adapter->rx_ring; |
| 550 | |
| 551 | ring->rx_max_pending = MAX_RXD; |
| 552 | ring->tx_max_pending = MAX_TXD; |
| 553 | ring->rx_mini_max_pending = 0; |
| 554 | ring->rx_jumbo_max_pending = 0; |
| 555 | ring->rx_pending = rxdr->count; |
| 556 | ring->tx_pending = txdr->count; |
| 557 | ring->rx_mini_pending = 0; |
| 558 | ring->rx_jumbo_pending = 0; |
| 559 | } |
| 560 | |
| 561 | static int |
| 562 | ixgb_set_ringparam(struct net_device *netdev, |
| 563 | struct ethtool_ringparam *ring) |
| 564 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 565 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | struct ixgb_desc_ring *txdr = &adapter->tx_ring; |
| 567 | struct ixgb_desc_ring *rxdr = &adapter->rx_ring; |
| 568 | struct ixgb_desc_ring tx_old, tx_new, rx_old, rx_new; |
| 569 | int err; |
| 570 | |
| 571 | tx_old = adapter->tx_ring; |
| 572 | rx_old = adapter->rx_ring; |
| 573 | |
| 574 | if((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 575 | return -EINVAL; |
| 576 | |
| 577 | if(netif_running(adapter->netdev)) |
| 578 | ixgb_down(adapter,TRUE); |
| 579 | |
| 580 | rxdr->count = max(ring->rx_pending,(uint32_t)MIN_RXD); |
| 581 | rxdr->count = min(rxdr->count,(uint32_t)MAX_RXD); |
| 582 | IXGB_ROUNDUP(rxdr->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE); |
| 583 | |
| 584 | txdr->count = max(ring->tx_pending,(uint32_t)MIN_TXD); |
| 585 | txdr->count = min(txdr->count,(uint32_t)MAX_TXD); |
| 586 | IXGB_ROUNDUP(txdr->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE); |
| 587 | |
| 588 | if(netif_running(adapter->netdev)) { |
| 589 | /* Try to get new resources before deleting old */ |
| 590 | if((err = ixgb_setup_rx_resources(adapter))) |
| 591 | goto err_setup_rx; |
| 592 | if((err = ixgb_setup_tx_resources(adapter))) |
| 593 | goto err_setup_tx; |
| 594 | |
| 595 | /* save the new, restore the old in order to free it, |
| 596 | * then restore the new back again */ |
| 597 | |
| 598 | rx_new = adapter->rx_ring; |
| 599 | tx_new = adapter->tx_ring; |
| 600 | adapter->rx_ring = rx_old; |
| 601 | adapter->tx_ring = tx_old; |
| 602 | ixgb_free_rx_resources(adapter); |
| 603 | ixgb_free_tx_resources(adapter); |
| 604 | adapter->rx_ring = rx_new; |
| 605 | adapter->tx_ring = tx_new; |
| 606 | if((err = ixgb_up(adapter))) |
| 607 | return err; |
Auke Kok | 4de17c8 | 2006-05-23 10:29:46 -0700 | [diff] [blame] | 608 | ixgb_set_speed_duplex(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | return 0; |
| 612 | err_setup_tx: |
| 613 | ixgb_free_rx_resources(adapter); |
| 614 | err_setup_rx: |
| 615 | adapter->rx_ring = rx_old; |
| 616 | adapter->tx_ring = tx_old; |
| 617 | ixgb_up(adapter); |
| 618 | return err; |
| 619 | } |
| 620 | |
| 621 | /* toggle LED 4 times per second = 2 "blinks" per second */ |
| 622 | #define IXGB_ID_INTERVAL (HZ/4) |
| 623 | |
| 624 | /* bit defines for adapter->led_status */ |
| 625 | #define IXGB_LED_ON 0 |
| 626 | |
| 627 | static void |
| 628 | ixgb_led_blink_callback(unsigned long data) |
| 629 | { |
| 630 | struct ixgb_adapter *adapter = (struct ixgb_adapter *)data; |
| 631 | |
| 632 | if(test_and_change_bit(IXGB_LED_ON, &adapter->led_status)) |
| 633 | ixgb_led_off(&adapter->hw); |
| 634 | else |
| 635 | ixgb_led_on(&adapter->hw); |
| 636 | |
| 637 | mod_timer(&adapter->blink_timer, jiffies + IXGB_ID_INTERVAL); |
| 638 | } |
| 639 | |
| 640 | static int |
| 641 | ixgb_phys_id(struct net_device *netdev, uint32_t data) |
| 642 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 643 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ)) |
| 646 | data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ); |
| 647 | |
| 648 | if(!adapter->blink_timer.function) { |
| 649 | init_timer(&adapter->blink_timer); |
| 650 | adapter->blink_timer.function = ixgb_led_blink_callback; |
| 651 | adapter->blink_timer.data = (unsigned long)adapter; |
| 652 | } |
| 653 | |
| 654 | mod_timer(&adapter->blink_timer, jiffies); |
| 655 | |
Nishanth Aravamudan | 3173c89 | 2005-09-11 02:09:55 -0700 | [diff] [blame] | 656 | if (data) |
| 657 | schedule_timeout_interruptible(data * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | else |
Nishanth Aravamudan | 3173c89 | 2005-09-11 02:09:55 -0700 | [diff] [blame] | 659 | schedule_timeout_interruptible(MAX_SCHEDULE_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | del_timer_sync(&adapter->blink_timer); |
| 662 | ixgb_led_off(&adapter->hw); |
| 663 | clear_bit(IXGB_LED_ON, &adapter->led_status); |
| 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | static int |
| 669 | ixgb_get_stats_count(struct net_device *netdev) |
| 670 | { |
| 671 | return IXGB_STATS_LEN; |
| 672 | } |
| 673 | |
| 674 | static void |
| 675 | ixgb_get_ethtool_stats(struct net_device *netdev, |
| 676 | struct ethtool_stats *stats, uint64_t *data) |
| 677 | { |
Malli Chilakala | 8908c6c | 2005-08-11 13:58:40 -0700 | [diff] [blame] | 678 | struct ixgb_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | int i; |
| 680 | |
| 681 | ixgb_update_stats(adapter); |
| 682 | for(i = 0; i < IXGB_STATS_LEN; i++) { |
| 683 | char *p = (char *)adapter+ixgb_gstrings_stats[i].stat_offset; |
| 684 | data[i] = (ixgb_gstrings_stats[i].sizeof_stat == |
| 685 | sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | static void |
| 690 | ixgb_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data) |
| 691 | { |
| 692 | int i; |
| 693 | |
| 694 | switch(stringset) { |
| 695 | case ETH_SS_STATS: |
| 696 | for(i=0; i < IXGB_STATS_LEN; i++) { |
| 697 | memcpy(data + i * ETH_GSTRING_LEN, |
| 698 | ixgb_gstrings_stats[i].stat_string, |
| 699 | ETH_GSTRING_LEN); |
| 700 | } |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | |
Adrian Bunk | e9ab1d1 | 2005-10-30 16:53:30 +0100 | [diff] [blame] | 705 | static struct ethtool_ops ixgb_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | .get_settings = ixgb_get_settings, |
| 707 | .set_settings = ixgb_set_settings, |
| 708 | .get_drvinfo = ixgb_get_drvinfo, |
| 709 | .get_regs_len = ixgb_get_regs_len, |
| 710 | .get_regs = ixgb_get_regs, |
| 711 | .get_link = ethtool_op_get_link, |
| 712 | .get_eeprom_len = ixgb_get_eeprom_len, |
| 713 | .get_eeprom = ixgb_get_eeprom, |
| 714 | .set_eeprom = ixgb_set_eeprom, |
| 715 | .get_ringparam = ixgb_get_ringparam, |
| 716 | .set_ringparam = ixgb_set_ringparam, |
| 717 | .get_pauseparam = ixgb_get_pauseparam, |
| 718 | .set_pauseparam = ixgb_set_pauseparam, |
| 719 | .get_rx_csum = ixgb_get_rx_csum, |
| 720 | .set_rx_csum = ixgb_set_rx_csum, |
| 721 | .get_tx_csum = ixgb_get_tx_csum, |
| 722 | .set_tx_csum = ixgb_set_tx_csum, |
| 723 | .get_sg = ethtool_op_get_sg, |
| 724 | .set_sg = ethtool_op_set_sg, |
Auke Kok | ec9c3f5 | 2006-05-23 10:34:59 -0700 | [diff] [blame^] | 725 | .get_msglevel = ixgb_get_msglevel, |
| 726 | .set_msglevel = ixgb_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | #ifdef NETIF_F_TSO |
| 728 | .get_tso = ethtool_op_get_tso, |
| 729 | .set_tso = ixgb_set_tso, |
| 730 | #endif |
| 731 | .get_strings = ixgb_get_strings, |
| 732 | .phys_id = ixgb_phys_id, |
| 733 | .get_stats_count = ixgb_get_stats_count, |
| 734 | .get_ethtool_stats = ixgb_get_ethtool_stats, |
John W. Linville | df859c5 | 2005-09-12 10:48:56 -0400 | [diff] [blame] | 735 | .get_perm_addr = ethtool_op_get_perm_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | }; |
| 737 | |
| 738 | void ixgb_set_ethtool_ops(struct net_device *netdev) |
| 739 | { |
| 740 | SET_ETHTOOL_OPS(netdev, &ixgb_ethtool_ops); |
| 741 | } |