1 /*******************************************************************************
4 Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
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)
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
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.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 /* ethtool support for ixgb */
33 #include <asm/uaccess.h>
35 extern char ixgb_driver_name[];
36 extern char ixgb_driver_version[];
38 extern int ixgb_up(struct ixgb_adapter *adapter);
39 extern void ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog);
42 char stat_string[ETH_GSTRING_LEN];
47 #define IXGB_STAT(m) sizeof(((struct ixgb_adapter *)0)->m), \
48 offsetof(struct ixgb_adapter, m)
49 static struct ixgb_stats ixgb_gstrings_stats[] = {
50 {"rx_packets", IXGB_STAT(net_stats.rx_packets)},
51 {"tx_packets", IXGB_STAT(net_stats.tx_packets)},
52 {"rx_bytes", IXGB_STAT(net_stats.rx_bytes)},
53 {"tx_bytes", IXGB_STAT(net_stats.tx_bytes)},
54 {"rx_errors", IXGB_STAT(net_stats.rx_errors)},
55 {"tx_errors", IXGB_STAT(net_stats.tx_errors)},
56 {"rx_dropped", IXGB_STAT(net_stats.rx_dropped)},
57 {"tx_dropped", IXGB_STAT(net_stats.tx_dropped)},
58 {"multicast", IXGB_STAT(net_stats.multicast)},
59 {"collisions", IXGB_STAT(net_stats.collisions)},
60 /* { "rx_length_errors", IXGB_STAT(net_stats.rx_length_errors) }, */
61 {"rx_over_errors", IXGB_STAT(net_stats.rx_over_errors)},
62 {"rx_crc_errors", IXGB_STAT(net_stats.rx_crc_errors)},
63 {"rx_frame_errors", IXGB_STAT(net_stats.rx_frame_errors)},
64 {"rx_fifo_errors", IXGB_STAT(net_stats.rx_fifo_errors)},
65 {"rx_missed_errors", IXGB_STAT(net_stats.rx_missed_errors)},
66 {"tx_aborted_errors", IXGB_STAT(net_stats.tx_aborted_errors)},
67 {"tx_carrier_errors", IXGB_STAT(net_stats.tx_carrier_errors)},
68 {"tx_fifo_errors", IXGB_STAT(net_stats.tx_fifo_errors)},
69 {"tx_heartbeat_errors", IXGB_STAT(net_stats.tx_heartbeat_errors)},
70 {"tx_window_errors", IXGB_STAT(net_stats.tx_window_errors)},
71 {"tx_deferred_ok", IXGB_STAT(stats.dc)},
72 {"rx_long_length_errors", IXGB_STAT(stats.roc)},
73 {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
75 {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)},
76 {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)},
78 {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)},
79 {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)},
80 {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)},
81 {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)},
82 {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)},
83 {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)},
84 {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)},
85 {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)}
88 #define IXGB_STATS_LEN \
89 sizeof(ixgb_gstrings_stats) / sizeof(struct ixgb_stats)
92 ixgb_ethtool_gset(struct net_device *netdev, struct ethtool_cmd *ecmd)
94 struct ixgb_adapter *adapter = netdev->priv;
95 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
96 ecmd->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
97 ecmd->port = PORT_FIBRE;
98 ecmd->transceiver = XCVR_EXTERNAL;
100 if (netif_carrier_ok(adapter->netdev)) {
101 ecmd->speed = SPEED_10000;
102 ecmd->duplex = DUPLEX_FULL;
108 ecmd->autoneg = AUTONEG_DISABLE;
113 ixgb_ethtool_sset(struct net_device *netdev, struct ethtool_cmd *ecmd)
115 struct ixgb_adapter *adapter = netdev->priv;
116 if (ecmd->autoneg == AUTONEG_ENABLE ||
117 ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)
120 ixgb_down(adapter, TRUE);
127 ixgb_ethtool_gpause(struct net_device *dev,
128 struct ethtool_pauseparam *epause)
130 struct ixgb_adapter *adapter = dev->priv;
131 struct ixgb_hw *hw = &adapter->hw;
133 epause->autoneg = AUTONEG_DISABLE;
135 if (hw->fc.type == ixgb_fc_rx_pause)
136 epause->rx_pause = 1;
137 else if (hw->fc.type == ixgb_fc_tx_pause)
138 epause->tx_pause = 1;
139 else if (hw->fc.type == ixgb_fc_full) {
140 epause->rx_pause = 1;
141 epause->tx_pause = 1;
146 ixgb_ethtool_spause(struct net_device *dev,
147 struct ethtool_pauseparam *epause)
149 struct ixgb_adapter *adapter = dev->priv;
150 struct ixgb_hw *hw = &adapter->hw;
152 if (epause->autoneg == AUTONEG_ENABLE)
155 if (epause->rx_pause && epause->tx_pause)
156 hw->fc.type = ixgb_fc_full;
157 else if (epause->rx_pause && !epause->tx_pause)
158 hw->fc.type = ixgb_fc_rx_pause;
159 else if (!epause->rx_pause && epause->tx_pause)
160 hw->fc.type = ixgb_fc_tx_pause;
161 else if (!epause->rx_pause && !epause->tx_pause)
162 hw->fc.type = ixgb_fc_none;
164 ixgb_down(adapter, TRUE);
171 ixgb_ethtool_gdrvinfo(struct net_device *netdev,
172 struct ethtool_drvinfo *drvinfo)
174 struct ixgb_adapter *adapter = netdev->priv;
175 strncpy(drvinfo->driver, ixgb_driver_name, 32);
176 strncpy(drvinfo->version, ixgb_driver_version, 32);
177 strncpy(drvinfo->fw_version, "N/A", 32);
178 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
181 #define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
183 ixgb_ethtool_gregs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
185 struct ixgb_adapter *adapter = dev->priv;
186 struct ixgb_hw *hw = &adapter->hw;
188 uint32_t *reg_start = reg;
192 (adapter->hw.device_id << 16) | adapter->hw.subsystem_id;
194 /* General Registers */
195 *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */
196 *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */
197 *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */
198 *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */
199 *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */
202 *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */
203 *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */
204 *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */
205 *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */
208 *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */
209 *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */
210 *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */
211 *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */
212 *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */
213 *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */
214 *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */
215 *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */
216 *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */
217 *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */
218 *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */
219 *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */
221 for (i = 0; i < IXGB_RAR_ENTRIES; i++) {
222 *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */
223 *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */
227 *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */
228 *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */
229 *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */
230 *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */
231 *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */
232 *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */
233 *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */
234 *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */
235 *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */
236 *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */
239 *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */
240 *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */
241 *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */
242 *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */
243 *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */
244 *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */
245 *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */
246 *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */
247 *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */
248 *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */
249 *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */
250 *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */
251 *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */
254 *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */
255 *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */
256 *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */
257 *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */
258 *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */
259 *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */
260 *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */
261 *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */
262 *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */
263 *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */
264 *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */
265 *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */
266 *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */
267 *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */
268 *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */
269 *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */
270 *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */
271 *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */
272 *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */
273 *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */
274 *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */
275 *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */
276 *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */
277 *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */
278 *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */
279 *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */
280 *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */
281 *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */
282 *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
283 *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
284 *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
285 *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
286 *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
287 *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
288 *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
289 *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
290 *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
291 *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
292 *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
293 *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
294 *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
295 *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
296 *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */
297 *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */
298 *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */
299 *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */
300 *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
301 *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */
302 *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */
303 *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */
304 *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */
305 *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */
306 *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */
307 *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
308 *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
309 *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */
310 *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */
311 *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */
312 *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */
313 *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */
315 regs->len = (reg - reg_start) * sizeof(uint32_t);
319 ixgb_ethtool_geeprom(struct net_device *dev,
320 struct ethtool_eeprom *eeprom, u8 *data)
322 struct ixgb_adapter *adapter = dev->priv;
323 struct ixgb_hw *hw = &adapter->hw;
325 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
327 /* use our function to read the eeprom and update our cache */
328 ixgb_get_eeprom_data(hw);
329 memcpy(data, (char *)hw->eeprom + eeprom->offset, eeprom->len);
334 ixgb_ethtool_seeprom(struct net_device *dev,
335 struct ethtool_eeprom *eeprom, u8 *data)
337 struct ixgb_adapter *adapter = dev->priv;
338 struct ixgb_hw *hw = &adapter->hw;
339 /* We are under rtnl, so static is OK */
340 static uint16_t eeprom_buff[IXGB_EEPROM_SIZE];
341 int i, first_word, last_word;
344 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
347 first_word = eeprom->offset >> 1;
348 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
349 ptr = (char *)eeprom_buff;
351 if (eeprom->offset & 1) {
352 /* need read/modify/write of first changed EEPROM word */
353 /* only the second byte of the word is being modified */
354 eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
357 if ((eeprom->offset + eeprom->len) & 1) {
358 /* need read/modify/write of last changed EEPROM word */
359 /* only the first byte of the word is being modified */
360 eeprom_buff[last_word - first_word]
361 = ixgb_read_eeprom(hw, last_word);
363 memcpy(ptr, data, eeprom->len);
365 for (i = 0; i <= (last_word - first_word); i++)
366 ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
368 /* Update the checksum over the first part of the EEPROM if needed */
369 if (first_word <= EEPROM_CHECKSUM_REG)
370 ixgb_update_eeprom_checksum(hw);
375 /* toggle LED 4 times per second = 2 "blinks" per second */
376 #define IXGB_ID_INTERVAL (HZ/4)
378 /* bit defines for adapter->led_status */
379 #define IXGB_LED_ON 0
381 static void ixgb_led_blink_callback(unsigned long data)
383 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
385 if (test_and_change_bit(IXGB_LED_ON, &adapter->led_status))
386 ixgb_led_off(&adapter->hw);
388 ixgb_led_on(&adapter->hw);
390 mod_timer(&adapter->blink_timer, jiffies + IXGB_ID_INTERVAL);
394 ixgb_ethtool_led_blink(struct net_device *netdev, u32 data)
396 struct ixgb_adapter *adapter = netdev->priv;
397 if (!adapter->blink_timer.function) {
398 init_timer(&adapter->blink_timer);
399 adapter->blink_timer.function = ixgb_led_blink_callback;
400 adapter->blink_timer.data = (unsigned long)adapter;
403 mod_timer(&adapter->blink_timer, jiffies);
405 set_current_state(TASK_INTERRUPTIBLE);
407 schedule_timeout(data * HZ);
409 schedule_timeout(MAX_SCHEDULE_TIMEOUT);
411 del_timer_sync(&adapter->blink_timer);
412 ixgb_led_off(&adapter->hw);
413 clear_bit(IXGB_LED_ON, &adapter->led_status);
418 static int ixgb_nway_reset(struct net_device *netdev)
420 if (netif_running(netdev)) {
421 struct ixgb_adapter *adapter = netdev->priv;
422 ixgb_down(adapter, TRUE);
428 static int ixgb_get_stats_count(struct net_device *dev)
430 return IXGB_STATS_LEN;
433 static void ixgb_get_strings(struct net_device *dev, u32 stringset, u8 *data)
436 for (i = 0; i < IXGB_STATS_LEN; i++) {
437 memcpy(data + i * ETH_GSTRING_LEN,
438 ixgb_gstrings_stats[i].stat_string,
443 static int ixgb_get_regs_len(struct net_device *dev)
445 return 136*sizeof(uint32_t);
448 static int ixgb_get_eeprom_len(struct net_device *dev)
450 /* return size in bytes */
451 return (IXGB_EEPROM_SIZE << 1);
454 static void get_ethtool_stats(struct net_device *dev,
455 struct ethtool_stats *stats, u64 *data)
457 struct ixgb_adapter *adapter = dev->priv;
460 for (i = 0; i < IXGB_STATS_LEN; i++) {
461 void *p = (char *)adapter + ixgb_gstrings_stats[i].stat_offset;
463 (ixgb_gstrings_stats[i].sizeof_stat == sizeof(uint64_t))
469 static u32 ixgb_get_rx_csum(struct net_device *dev)
471 struct ixgb_adapter *adapter = dev->priv;
472 return adapter->rx_csum;
475 static int ixgb_set_rx_csum(struct net_device *dev, u32 sum)
477 struct ixgb_adapter *adapter = dev->priv;
478 adapter->rx_csum = sum;
479 ixgb_down(adapter, TRUE);
484 static u32 ixgb_get_tx_csum(struct net_device *dev)
486 return (dev->features & NETIF_F_HW_CSUM) != 0;
489 static int ixgb_set_tx_csum(struct net_device *dev, u32 sum)
492 dev->features |= NETIF_F_HW_CSUM;
494 dev->features &= ~NETIF_F_HW_CSUM;
498 static u32 ixgb_get_sg(struct net_device *dev)
500 return (dev->features & NETIF_F_SG) != 0;
503 static int ixgb_set_sg(struct net_device *dev, u32 sum)
506 dev->features |= NETIF_F_SG;
508 dev->features &= ~NETIF_F_SG;
513 static u32 ixgb_get_tso(struct net_device *dev)
515 return (dev->features & NETIF_F_TSO) != 0;
518 static int ixgb_set_tso(struct net_device *dev, u32 sum)
521 dev->features |= NETIF_F_TSO;
523 dev->features &= ~NETIF_F_TSO;
528 struct ethtool_ops ixgb_ethtool_ops = {
529 .get_settings = ixgb_ethtool_gset,
530 .set_settings = ixgb_ethtool_sset,
531 .get_drvinfo = ixgb_ethtool_gdrvinfo,
532 .nway_reset = ixgb_nway_reset,
533 .get_link = ethtool_op_get_link,
534 .phys_id = ixgb_ethtool_led_blink,
535 .get_strings = ixgb_get_strings,
536 .get_stats_count = ixgb_get_stats_count,
537 .get_regs = ixgb_ethtool_gregs,
538 .get_regs_len = ixgb_get_regs_len,
539 .get_eeprom_len = ixgb_get_eeprom_len,
540 .get_eeprom = ixgb_ethtool_geeprom,
541 .set_eeprom = ixgb_ethtool_seeprom,
542 .get_pauseparam = ixgb_ethtool_gpause,
543 .set_pauseparam = ixgb_ethtool_spause,
544 .get_ethtool_stats = get_ethtool_stats,
545 .get_rx_csum = ixgb_get_rx_csum,
546 .set_rx_csum = ixgb_set_rx_csum,
547 .get_tx_csum = ixgb_get_tx_csum,
548 .set_tx_csum = ixgb_set_tx_csum,
549 .get_sg = ixgb_get_sg,
550 .set_sg = ixgb_set_sg,
552 .get_tso = ixgb_get_tso,
553 .set_tso = ixgb_set_tso,