1 /*******************************************************************************
4 Copyright(c) 1999 - 2003 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
26 *******************************************************************************/
28 /* ethtool support for ixgb */
32 #include <asm/uaccess.h>
34 extern char ixgb_driver_name[];
35 extern char ixgb_driver_version[];
37 extern int ixgb_up(struct ixgb_adapter *adapter);
38 extern int ixgb_down(struct ixgb_adapter *adapter);
41 * ixgb_ethtool_ioctl - Ethtool Ioctl Support
42 * @netdev: net device structure
43 * @ifr: interface request structure
47 ixgb_eeprom_size(struct ixgb_hw *hw)
49 /* return size in bytes */
50 return (IXGB_EEPROM_SIZE << 1);
53 #define SPEED_10000 10000
56 ixgb_ethtool_gset(struct ixgb_adapter *adapter, struct ethtool_cmd *ecmd)
58 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
59 ecmd->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
60 ecmd->port = PORT_FIBRE;
61 ecmd->transceiver = XCVR_EXTERNAL;
63 if (netif_carrier_ok(adapter->netdev)) {
65 ecmd->duplex = DUPLEX_FULL;
71 ecmd->autoneg = AUTONEG_DISABLE;
75 ixgb_ethtool_sset(struct ixgb_adapter *adapter, struct ethtool_cmd *ecmd)
77 if (ecmd->autoneg == AUTONEG_ENABLE ||
78 ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)
90 ixgb_ethtool_promiscuous(struct ixgb_adapter *adapter,
91 struct ethtool_pmode *pmode)
93 u32 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
95 pmode->rctl_old = rctl;
97 rctl |= IXGB_RCTL_UPE;
99 rctl &= ~IXGB_RCTL_UPE;
102 rctl |= IXGB_RCTL_MPE;
104 rctl &= ~IXGB_RCTL_MPE;
106 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
108 pmode->rctl_new = IXGB_READ_REG(&adapter->hw, RCTL);
114 #define IXGB_REG_DUMP_LEN 136*sizeof(u32)
116 ixgb_ethtool_gdrvinfo(struct ixgb_adapter *adapter,
117 struct ethtool_drvinfo *drvinfo)
119 strncpy(drvinfo->driver, ixgb_driver_name, 32);
120 strncpy(drvinfo->version, ixgb_driver_version, 32);
121 strncpy(drvinfo->fw_version, "", 32);
122 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
124 drvinfo->regdump_len = IXGB_REG_DUMP_LEN;
125 #endif /* ETHTOOL_GREGS */
126 drvinfo->eedump_len = ixgb_eeprom_size(&adapter->hw);
130 #define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
132 ixgb_ethtool_gregs(struct ixgb_adapter *adapter,
133 struct ethtool_regs *regs, u8 * regs_buff)
135 struct ixgb_hw *hw = &adapter->hw;
136 u32 *reg = (u32 *) regs_buff;
137 u32 *reg_start = reg;
141 (adapter->hw.device_id << 16) | adapter->hw.subsystem_id;
143 /* General Registers */
144 *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */
145 *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */
146 *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */
147 *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */
148 *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */
151 *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */
152 *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */
153 *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */
154 *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */
157 *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */
158 *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */
159 *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */
160 *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */
161 *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */
162 *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */
163 *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */
164 *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */
165 *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */
166 *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */
167 *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */
168 *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */
170 for (i = 0; i < IXGB_RAR_ENTRIES; i++) {
171 *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */
172 *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */
176 *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */
177 *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */
178 *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */
179 *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */
180 *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */
181 *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */
182 *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */
183 *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */
184 *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */
185 *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */
188 *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */
189 *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */
190 *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */
191 *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */
192 *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */
193 *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */
194 *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */
195 *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */
196 *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */
197 *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */
198 *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */
199 *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */
200 *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */
204 reg[IXGB_WUFC] = IXGB_READ_REG(hw, WUFC);
205 reg[IXGB_WUS] = IXGB_READ_REG(hw, WUS);
206 reg[IXGB_FFLT] = IXGB_READ_REG(hw, FFLT);
207 reg[IXGB_FFMT] = IXGB_READ_REG(hw, FFMT);
208 reg[IXGB_FTVT] = IXGB_READ_REG(hw, FTVT);
212 *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */
213 *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */
214 *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */
215 *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */
216 *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */
217 *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */
218 *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */
219 *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */
220 *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */
221 *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */
222 *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */
223 *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */
224 *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */
225 *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */
226 *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */
227 *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */
228 *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */
229 *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */
230 *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */
231 *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */
232 *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */
233 *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */
234 *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */
235 *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */
236 *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */
237 *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */
238 *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */
239 *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */
240 *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
241 *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
242 *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
243 *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
244 *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
245 *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
246 *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
247 *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
248 *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
249 *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
250 *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
251 *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
252 *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
253 *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
254 *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */
255 *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */
256 *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */
257 *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */
258 *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
259 *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */
260 *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */
261 *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */
262 *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */
263 *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */
264 *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */
265 *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
266 *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
267 *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */
268 *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */
269 *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */
270 *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */
271 *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */
275 regs->len = (reg - reg_start) * sizeof (u32);
277 #endif /* ETHTOOL_GREGS */
280 ixgb_ethtool_geeprom(struct ixgb_adapter *adapter,
281 struct ethtool_eeprom *eeprom, u16 * eeprom_buff)
283 struct ixgb_hw *hw = &adapter->hw;
284 int i, max_len, first_word, last_word;
285 IXGB_DBG("ixgb_ethtool_geeprom\n");
287 if (eeprom->len == 0)
290 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
292 max_len = ixgb_eeprom_size(hw);
294 /* use our function to read the eeprom and update our cache */
295 ixgb_get_eeprom_data(hw);
297 if (eeprom->offset > eeprom->offset + eeprom->len)
300 if ((eeprom->offset + eeprom->len) > max_len)
301 eeprom->len = (max_len - eeprom->offset);
303 first_word = eeprom->offset >> 1;
304 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
306 for (i = 0; i <= (last_word - first_word); i++) {
307 eeprom_buff[i] = hw->eeprom[first_word + i];
313 ixgb_ethtool_seeprom(struct ixgb_adapter *adapter,
314 struct ethtool_eeprom *eeprom, void *user_data)
316 struct ixgb_hw *hw = &adapter->hw;
317 u16 eeprom_buff[256];
318 int i, max_len, first_word, last_word;
321 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
324 if (eeprom->len == 0)
327 max_len = ixgb_eeprom_size(hw);
329 if (eeprom->offset > eeprom->offset + eeprom->len)
332 if ((eeprom->offset + eeprom->len) > max_len)
333 eeprom->len = (max_len - eeprom->offset);
335 first_word = eeprom->offset >> 1;
336 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
337 ptr = (void *) eeprom_buff;
339 if (eeprom->offset & 1) {
340 /* need read/modify/write of first changed EEPROM word */
341 /* only the second byte of the word is being modified */
342 eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
345 if ((eeprom->offset + eeprom->len) & 1) {
346 /* need read/modify/write of last changed EEPROM word */
347 /* only the first byte of the word is being modified */
348 eeprom_buff[last_word - first_word]
349 = ixgb_read_eeprom(hw, last_word);
351 if (copy_from_user(ptr, user_data, eeprom->len))
354 for (i = 0; i <= (last_word - first_word); i++)
355 ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
357 /* Update the checksum over the first part of the EEPROM if needed */
358 if (first_word <= EEPROM_CHECKSUM_REG)
359 ixgb_update_eeprom_checksum(hw);
364 #ifdef ETHTOOL_PHYS_ID
366 /* toggle LED 4 times per second = 2 "blinks" per second */
367 #define IXGB_ID_INTERVAL (HZ/4)
369 /* bit defines for adapter->led_status */
370 #define IXGB_LED_ON 0
373 ixgb_led_blink_callback(unsigned long data)
375 struct ixgb_adapter *adapter = (struct ixgb_adapter *) data;
377 if (test_and_change_bit(IXGB_LED_ON, &adapter->led_status))
378 ixgb_led_off(&adapter->hw);
380 ixgb_led_on(&adapter->hw);
382 mod_timer(&adapter->blink_timer, jiffies + IXGB_ID_INTERVAL);
386 ixgb_ethtool_led_blink(struct ixgb_adapter *adapter, struct ethtool_value *id)
388 if (!adapter->blink_timer.function) {
389 init_timer(&adapter->blink_timer);
390 adapter->blink_timer.function = ixgb_led_blink_callback;
391 adapter->blink_timer.data = (unsigned long) adapter;
394 mod_timer(&adapter->blink_timer, jiffies);
396 set_current_state(TASK_INTERRUPTIBLE);
398 schedule_timeout(id->data * HZ);
400 schedule_timeout(MAX_SCHEDULE_TIMEOUT);
402 del_timer_sync(&adapter->blink_timer);
403 ixgb_led_off(&adapter->hw);
404 clear_bit(IXGB_LED_ON, &adapter->led_status);
408 #endif /* ETHTOOL_PHYS_ID */
411 ixgb_ethtool_ioctl(struct net_device *netdev, struct ifreq *ifr)
413 struct ixgb_adapter *adapter = netdev->priv;
414 void *addr = ifr->ifr_data;
417 if (get_user(cmd, (u32 *) addr))
422 case ETHTOOL_PROMISCUOUS:{
423 struct ethtool_pmode pmode;
425 if (copy_from_user(&pmode, addr, sizeof (pmode)))
428 ixgb_ethtool_promiscuous(adapter, &pmode);
430 if (copy_to_user(addr, &pmode, sizeof (pmode)))
435 case ETHTOOL_DOWN_UP:
436 ixgb_down(netdev->priv);
437 ixgb_up(netdev->priv);
441 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
443 ixgb_ethtool_gset(adapter, &ecmd);
444 if (copy_to_user(addr, &ecmd, sizeof (ecmd)))
449 struct ethtool_cmd ecmd;
451 if (copy_from_user(&ecmd, addr, sizeof (ecmd)))
453 return ixgb_ethtool_sset(adapter, &ecmd);
455 case ETHTOOL_GDRVINFO:
457 struct ethtool_drvinfo drvinfo = { ETHTOOL_GDRVINFO };
459 ixgb_ethtool_gdrvinfo(adapter, &drvinfo);
460 if (copy_to_user(addr, &drvinfo, sizeof (drvinfo)))
464 #if defined(ETHTOOL_GREGS) && defined(ETHTOOL_GEEPROM)
466 struct ethtool_regs regs = { ETHTOOL_GREGS };
467 u8 regs_buff[IXGB_REG_DUMP_LEN];
469 ixgb_ethtool_gregs(adapter, ®s, regs_buff);
471 if (copy_to_user(addr, ®s, sizeof (regs)))
474 addr += offsetof(struct ethtool_regs, data);
476 if (copy_to_user(addr, regs_buff, regs.len))
480 #endif /* ETHTOOL_GREGS */
481 case ETHTOOL_NWAY_RST:{
482 IXGB_DBG("ETHTOOL_NWAY_RST\n");
488 #ifdef ETHTOOL_PHYS_ID
489 case ETHTOOL_PHYS_ID:{
490 struct ethtool_value id;
492 IXGB_DBG("ETHTOOL_PHYS_ID\n");
493 if (copy_from_user(&id, addr, sizeof (id)))
495 return ixgb_ethtool_led_blink(adapter, &id);
497 #endif /* ETHTOOL_PHYS_ID */
499 struct ethtool_value link = { ETHTOOL_GLINK };
501 IXGB_DBG("ETHTOOL_GLINK\n");
502 link.data = netif_carrier_ok(netdev);
503 if (copy_to_user(addr, &link, sizeof (link)))
508 case ETHTOOL_GEEPROM:{
509 struct ethtool_eeprom eeprom = { ETHTOOL_GEEPROM };
510 u16 eeprom_buff[IXGB_EEPROM_SIZE];
514 IXGB_DBG("ETHTOOL_GEEPROM\n");
515 if (copy_from_user(&eeprom, addr, sizeof (eeprom)))
519 ixgb_ethtool_geeprom(adapter, &eeprom,
523 if (copy_to_user(addr, &eeprom, sizeof (eeprom)))
526 addr += offsetof(struct ethtool_eeprom, data);
528 ptr = ((void *) eeprom_buff) + (eeprom.offset & 1);
529 if (copy_to_user(addr, ptr, eeprom.len))
533 case ETHTOOL_SEEPROM:{
534 struct ethtool_eeprom eeprom;
536 IXGB_DBG("ETHTOOL_SEEPROM\n");
537 if (copy_from_user(&eeprom, addr, sizeof (eeprom)))
540 addr += offsetof(struct ethtool_eeprom, data);
541 return ixgb_ethtool_seeprom(adapter, &eeprom, addr);