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