Blackfin arch: Add label to call new GPIO API
[wrt350n-kernel.git] / drivers / net / e1000 / e1000_ethtool.c
blob9ecc3adcf6c189117e038426e0fc0550f08f60bd
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 /* ethtool support for e1000 */
31 #include "e1000.h"
33 #include <asm/uaccess.h>
35 extern char e1000_driver_name[];
36 extern char e1000_driver_version[];
38 extern int e1000_up(struct e1000_adapter *adapter);
39 extern void e1000_down(struct e1000_adapter *adapter);
40 extern void e1000_reinit_locked(struct e1000_adapter *adapter);
41 extern void e1000_reset(struct e1000_adapter *adapter);
42 extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
43 extern int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
44 extern int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
45 extern void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
46 extern void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
47 extern void e1000_update_stats(struct e1000_adapter *adapter);
50 struct e1000_stats {
51 char stat_string[ETH_GSTRING_LEN];
52 int sizeof_stat;
53 int stat_offset;
56 #define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
57 offsetof(struct e1000_adapter, m)
58 static const struct e1000_stats e1000_gstrings_stats[] = {
59 { "rx_packets", E1000_STAT(stats.gprc) },
60 { "tx_packets", E1000_STAT(stats.gptc) },
61 { "rx_bytes", E1000_STAT(stats.gorcl) },
62 { "tx_bytes", E1000_STAT(stats.gotcl) },
63 { "rx_broadcast", E1000_STAT(stats.bprc) },
64 { "tx_broadcast", E1000_STAT(stats.bptc) },
65 { "rx_multicast", E1000_STAT(stats.mprc) },
66 { "tx_multicast", E1000_STAT(stats.mptc) },
67 { "rx_errors", E1000_STAT(stats.rxerrc) },
68 { "tx_errors", E1000_STAT(stats.txerrc) },
69 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
70 { "multicast", E1000_STAT(stats.mprc) },
71 { "collisions", E1000_STAT(stats.colc) },
72 { "rx_length_errors", E1000_STAT(stats.rlerrc) },
73 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
74 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
75 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
76 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
77 { "rx_missed_errors", E1000_STAT(stats.mpc) },
78 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
79 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
80 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
81 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
82 { "tx_window_errors", E1000_STAT(stats.latecol) },
83 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
84 { "tx_deferred_ok", E1000_STAT(stats.dc) },
85 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
86 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
87 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
88 { "tx_restart_queue", E1000_STAT(restart_queue) },
89 { "rx_long_length_errors", E1000_STAT(stats.roc) },
90 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
91 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
92 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
93 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
94 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
95 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
96 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
97 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
98 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
99 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
100 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
101 { "rx_header_split", E1000_STAT(rx_hdr_split) },
102 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
103 { "tx_smbus", E1000_STAT(stats.mgptc) },
104 { "rx_smbus", E1000_STAT(stats.mgprc) },
105 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
108 #define E1000_QUEUE_STATS_LEN 0
109 #define E1000_GLOBAL_STATS_LEN \
110 sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats)
111 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
112 static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
113 "Register test (offline)", "Eeprom test (offline)",
114 "Interrupt test (offline)", "Loopback test (offline)",
115 "Link test (on/offline)"
117 #define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN
119 static int
120 e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
122 struct e1000_adapter *adapter = netdev_priv(netdev);
123 struct e1000_hw *hw = &adapter->hw;
125 if (hw->media_type == e1000_media_type_copper) {
127 ecmd->supported = (SUPPORTED_10baseT_Half |
128 SUPPORTED_10baseT_Full |
129 SUPPORTED_100baseT_Half |
130 SUPPORTED_100baseT_Full |
131 SUPPORTED_1000baseT_Full|
132 SUPPORTED_Autoneg |
133 SUPPORTED_TP);
134 if (hw->phy_type == e1000_phy_ife)
135 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
136 ecmd->advertising = ADVERTISED_TP;
138 if (hw->autoneg == 1) {
139 ecmd->advertising |= ADVERTISED_Autoneg;
140 /* the e1000 autoneg seems to match ethtool nicely */
141 ecmd->advertising |= hw->autoneg_advertised;
144 ecmd->port = PORT_TP;
145 ecmd->phy_address = hw->phy_addr;
147 if (hw->mac_type == e1000_82543)
148 ecmd->transceiver = XCVR_EXTERNAL;
149 else
150 ecmd->transceiver = XCVR_INTERNAL;
152 } else {
153 ecmd->supported = (SUPPORTED_1000baseT_Full |
154 SUPPORTED_FIBRE |
155 SUPPORTED_Autoneg);
157 ecmd->advertising = (ADVERTISED_1000baseT_Full |
158 ADVERTISED_FIBRE |
159 ADVERTISED_Autoneg);
161 ecmd->port = PORT_FIBRE;
163 if (hw->mac_type >= e1000_82545)
164 ecmd->transceiver = XCVR_INTERNAL;
165 else
166 ecmd->transceiver = XCVR_EXTERNAL;
169 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
171 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
172 &adapter->link_duplex);
173 ecmd->speed = adapter->link_speed;
175 /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
176 * and HALF_DUPLEX != DUPLEX_HALF */
178 if (adapter->link_duplex == FULL_DUPLEX)
179 ecmd->duplex = DUPLEX_FULL;
180 else
181 ecmd->duplex = DUPLEX_HALF;
182 } else {
183 ecmd->speed = -1;
184 ecmd->duplex = -1;
187 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
188 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
189 return 0;
192 static int
193 e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
195 struct e1000_adapter *adapter = netdev_priv(netdev);
196 struct e1000_hw *hw = &adapter->hw;
198 /* When SoL/IDER sessions are active, autoneg/speed/duplex
199 * cannot be changed */
200 if (e1000_check_phy_reset_block(hw)) {
201 DPRINTK(DRV, ERR, "Cannot change link characteristics "
202 "when SoL/IDER is active.\n");
203 return -EINVAL;
206 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
207 msleep(1);
209 if (ecmd->autoneg == AUTONEG_ENABLE) {
210 hw->autoneg = 1;
211 if (hw->media_type == e1000_media_type_fiber)
212 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
213 ADVERTISED_FIBRE |
214 ADVERTISED_Autoneg;
215 else
216 hw->autoneg_advertised = ecmd->advertising |
217 ADVERTISED_TP |
218 ADVERTISED_Autoneg;
219 ecmd->advertising = hw->autoneg_advertised;
220 } else
221 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
222 clear_bit(__E1000_RESETTING, &adapter->flags);
223 return -EINVAL;
226 /* reset the link */
228 if (netif_running(adapter->netdev)) {
229 e1000_down(adapter);
230 e1000_up(adapter);
231 } else
232 e1000_reset(adapter);
234 clear_bit(__E1000_RESETTING, &adapter->flags);
235 return 0;
238 static void
239 e1000_get_pauseparam(struct net_device *netdev,
240 struct ethtool_pauseparam *pause)
242 struct e1000_adapter *adapter = netdev_priv(netdev);
243 struct e1000_hw *hw = &adapter->hw;
245 pause->autoneg =
246 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
248 if (hw->fc == E1000_FC_RX_PAUSE)
249 pause->rx_pause = 1;
250 else if (hw->fc == E1000_FC_TX_PAUSE)
251 pause->tx_pause = 1;
252 else if (hw->fc == E1000_FC_FULL) {
253 pause->rx_pause = 1;
254 pause->tx_pause = 1;
258 static int
259 e1000_set_pauseparam(struct net_device *netdev,
260 struct ethtool_pauseparam *pause)
262 struct e1000_adapter *adapter = netdev_priv(netdev);
263 struct e1000_hw *hw = &adapter->hw;
264 int retval = 0;
266 adapter->fc_autoneg = pause->autoneg;
268 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
269 msleep(1);
271 if (pause->rx_pause && pause->tx_pause)
272 hw->fc = E1000_FC_FULL;
273 else if (pause->rx_pause && !pause->tx_pause)
274 hw->fc = E1000_FC_RX_PAUSE;
275 else if (!pause->rx_pause && pause->tx_pause)
276 hw->fc = E1000_FC_TX_PAUSE;
277 else if (!pause->rx_pause && !pause->tx_pause)
278 hw->fc = E1000_FC_NONE;
280 hw->original_fc = hw->fc;
282 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
283 if (netif_running(adapter->netdev)) {
284 e1000_down(adapter);
285 e1000_up(adapter);
286 } else
287 e1000_reset(adapter);
288 } else
289 retval = ((hw->media_type == e1000_media_type_fiber) ?
290 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
292 clear_bit(__E1000_RESETTING, &adapter->flags);
293 return retval;
296 static uint32_t
297 e1000_get_rx_csum(struct net_device *netdev)
299 struct e1000_adapter *adapter = netdev_priv(netdev);
300 return adapter->rx_csum;
303 static int
304 e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
306 struct e1000_adapter *adapter = netdev_priv(netdev);
307 adapter->rx_csum = data;
309 if (netif_running(netdev))
310 e1000_reinit_locked(adapter);
311 else
312 e1000_reset(adapter);
313 return 0;
316 static uint32_t
317 e1000_get_tx_csum(struct net_device *netdev)
319 return (netdev->features & NETIF_F_HW_CSUM) != 0;
322 static int
323 e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
325 struct e1000_adapter *adapter = netdev_priv(netdev);
327 if (adapter->hw.mac_type < e1000_82543) {
328 if (!data)
329 return -EINVAL;
330 return 0;
333 if (data)
334 netdev->features |= NETIF_F_HW_CSUM;
335 else
336 netdev->features &= ~NETIF_F_HW_CSUM;
338 return 0;
341 static int
342 e1000_set_tso(struct net_device *netdev, uint32_t data)
344 struct e1000_adapter *adapter = netdev_priv(netdev);
345 if ((adapter->hw.mac_type < e1000_82544) ||
346 (adapter->hw.mac_type == e1000_82547))
347 return data ? -EINVAL : 0;
349 if (data)
350 netdev->features |= NETIF_F_TSO;
351 else
352 netdev->features &= ~NETIF_F_TSO;
354 if (data)
355 netdev->features |= NETIF_F_TSO6;
356 else
357 netdev->features &= ~NETIF_F_TSO6;
359 DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
360 adapter->tso_force = TRUE;
361 return 0;
364 static uint32_t
365 e1000_get_msglevel(struct net_device *netdev)
367 struct e1000_adapter *adapter = netdev_priv(netdev);
368 return adapter->msg_enable;
371 static void
372 e1000_set_msglevel(struct net_device *netdev, uint32_t data)
374 struct e1000_adapter *adapter = netdev_priv(netdev);
375 adapter->msg_enable = data;
378 static int
379 e1000_get_regs_len(struct net_device *netdev)
381 #define E1000_REGS_LEN 32
382 return E1000_REGS_LEN * sizeof(uint32_t);
385 static void
386 e1000_get_regs(struct net_device *netdev,
387 struct ethtool_regs *regs, void *p)
389 struct e1000_adapter *adapter = netdev_priv(netdev);
390 struct e1000_hw *hw = &adapter->hw;
391 uint32_t *regs_buff = p;
392 uint16_t phy_data;
394 memset(p, 0, E1000_REGS_LEN * sizeof(uint32_t));
396 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
398 regs_buff[0] = E1000_READ_REG(hw, CTRL);
399 regs_buff[1] = E1000_READ_REG(hw, STATUS);
401 regs_buff[2] = E1000_READ_REG(hw, RCTL);
402 regs_buff[3] = E1000_READ_REG(hw, RDLEN);
403 regs_buff[4] = E1000_READ_REG(hw, RDH);
404 regs_buff[5] = E1000_READ_REG(hw, RDT);
405 regs_buff[6] = E1000_READ_REG(hw, RDTR);
407 regs_buff[7] = E1000_READ_REG(hw, TCTL);
408 regs_buff[8] = E1000_READ_REG(hw, TDLEN);
409 regs_buff[9] = E1000_READ_REG(hw, TDH);
410 regs_buff[10] = E1000_READ_REG(hw, TDT);
411 regs_buff[11] = E1000_READ_REG(hw, TIDV);
413 regs_buff[12] = adapter->hw.phy_type; /* PHY type (IGP=1, M88=0) */
414 if (hw->phy_type == e1000_phy_igp) {
415 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
416 IGP01E1000_PHY_AGC_A);
417 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
418 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
419 regs_buff[13] = (uint32_t)phy_data; /* cable length */
420 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
421 IGP01E1000_PHY_AGC_B);
422 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
423 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
424 regs_buff[14] = (uint32_t)phy_data; /* cable length */
425 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
426 IGP01E1000_PHY_AGC_C);
427 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
428 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
429 regs_buff[15] = (uint32_t)phy_data; /* cable length */
430 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
431 IGP01E1000_PHY_AGC_D);
432 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
433 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
434 regs_buff[16] = (uint32_t)phy_data; /* cable length */
435 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
436 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
437 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
438 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
439 regs_buff[18] = (uint32_t)phy_data; /* cable polarity */
440 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
441 IGP01E1000_PHY_PCS_INIT_REG);
442 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
443 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
444 regs_buff[19] = (uint32_t)phy_data; /* cable polarity */
445 regs_buff[20] = 0; /* polarity correction enabled (always) */
446 regs_buff[22] = 0; /* phy receive errors (unavailable) */
447 regs_buff[23] = regs_buff[18]; /* mdix mode */
448 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
449 } else {
450 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
451 regs_buff[13] = (uint32_t)phy_data; /* cable length */
452 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
453 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
454 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
455 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
456 regs_buff[17] = (uint32_t)phy_data; /* extended 10bt distance */
457 regs_buff[18] = regs_buff[13]; /* cable polarity */
458 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
459 regs_buff[20] = regs_buff[17]; /* polarity correction */
460 /* phy receive errors */
461 regs_buff[22] = adapter->phy_stats.receive_errors;
462 regs_buff[23] = regs_buff[13]; /* mdix mode */
464 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
465 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
466 regs_buff[24] = (uint32_t)phy_data; /* phy local receiver status */
467 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
468 if (hw->mac_type >= e1000_82540 &&
469 hw->mac_type < e1000_82571 &&
470 hw->media_type == e1000_media_type_copper) {
471 regs_buff[26] = E1000_READ_REG(hw, MANC);
475 static int
476 e1000_get_eeprom_len(struct net_device *netdev)
478 struct e1000_adapter *adapter = netdev_priv(netdev);
479 return adapter->hw.eeprom.word_size * 2;
482 static int
483 e1000_get_eeprom(struct net_device *netdev,
484 struct ethtool_eeprom *eeprom, uint8_t *bytes)
486 struct e1000_adapter *adapter = netdev_priv(netdev);
487 struct e1000_hw *hw = &adapter->hw;
488 uint16_t *eeprom_buff;
489 int first_word, last_word;
490 int ret_val = 0;
491 uint16_t i;
493 if (eeprom->len == 0)
494 return -EINVAL;
496 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
498 first_word = eeprom->offset >> 1;
499 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
501 eeprom_buff = kmalloc(sizeof(uint16_t) *
502 (last_word - first_word + 1), GFP_KERNEL);
503 if (!eeprom_buff)
504 return -ENOMEM;
506 if (hw->eeprom.type == e1000_eeprom_spi)
507 ret_val = e1000_read_eeprom(hw, first_word,
508 last_word - first_word + 1,
509 eeprom_buff);
510 else {
511 for (i = 0; i < last_word - first_word + 1; i++)
512 if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
513 &eeprom_buff[i])))
514 break;
517 /* Device's eeprom is always little-endian, word addressable */
518 for (i = 0; i < last_word - first_word + 1; i++)
519 le16_to_cpus(&eeprom_buff[i]);
521 memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
522 eeprom->len);
523 kfree(eeprom_buff);
525 return ret_val;
528 static int
529 e1000_set_eeprom(struct net_device *netdev,
530 struct ethtool_eeprom *eeprom, uint8_t *bytes)
532 struct e1000_adapter *adapter = netdev_priv(netdev);
533 struct e1000_hw *hw = &adapter->hw;
534 uint16_t *eeprom_buff;
535 void *ptr;
536 int max_len, first_word, last_word, ret_val = 0;
537 uint16_t i;
539 if (eeprom->len == 0)
540 return -EOPNOTSUPP;
542 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
543 return -EFAULT;
545 max_len = hw->eeprom.word_size * 2;
547 first_word = eeprom->offset >> 1;
548 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
549 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
550 if (!eeprom_buff)
551 return -ENOMEM;
553 ptr = (void *)eeprom_buff;
555 if (eeprom->offset & 1) {
556 /* need read/modify/write of first changed EEPROM word */
557 /* only the second byte of the word is being modified */
558 ret_val = e1000_read_eeprom(hw, first_word, 1,
559 &eeprom_buff[0]);
560 ptr++;
562 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
563 /* need read/modify/write of last changed EEPROM word */
564 /* only the first byte of the word is being modified */
565 ret_val = e1000_read_eeprom(hw, last_word, 1,
566 &eeprom_buff[last_word - first_word]);
569 /* Device's eeprom is always little-endian, word addressable */
570 for (i = 0; i < last_word - first_word + 1; i++)
571 le16_to_cpus(&eeprom_buff[i]);
573 memcpy(ptr, bytes, eeprom->len);
575 for (i = 0; i < last_word - first_word + 1; i++)
576 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
578 ret_val = e1000_write_eeprom(hw, first_word,
579 last_word - first_word + 1, eeprom_buff);
581 /* Update the checksum over the first part of the EEPROM if needed
582 * and flush shadow RAM for 82573 conrollers */
583 if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
584 (hw->mac_type == e1000_82573)))
585 e1000_update_eeprom_checksum(hw);
587 kfree(eeprom_buff);
588 return ret_val;
591 static void
592 e1000_get_drvinfo(struct net_device *netdev,
593 struct ethtool_drvinfo *drvinfo)
595 struct e1000_adapter *adapter = netdev_priv(netdev);
596 char firmware_version[32];
597 uint16_t eeprom_data;
599 strncpy(drvinfo->driver, e1000_driver_name, 32);
600 strncpy(drvinfo->version, e1000_driver_version, 32);
602 /* EEPROM image version # is reported as firmware version # for
603 * 8257{1|2|3} controllers */
604 e1000_read_eeprom(&adapter->hw, 5, 1, &eeprom_data);
605 switch (adapter->hw.mac_type) {
606 case e1000_82571:
607 case e1000_82572:
608 case e1000_82573:
609 case e1000_80003es2lan:
610 case e1000_ich8lan:
611 sprintf(firmware_version, "%d.%d-%d",
612 (eeprom_data & 0xF000) >> 12,
613 (eeprom_data & 0x0FF0) >> 4,
614 eeprom_data & 0x000F);
615 break;
616 default:
617 sprintf(firmware_version, "N/A");
620 strncpy(drvinfo->fw_version, firmware_version, 32);
621 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
622 drvinfo->n_stats = E1000_STATS_LEN;
623 drvinfo->testinfo_len = E1000_TEST_LEN;
624 drvinfo->regdump_len = e1000_get_regs_len(netdev);
625 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
628 static void
629 e1000_get_ringparam(struct net_device *netdev,
630 struct ethtool_ringparam *ring)
632 struct e1000_adapter *adapter = netdev_priv(netdev);
633 e1000_mac_type mac_type = adapter->hw.mac_type;
634 struct e1000_tx_ring *txdr = adapter->tx_ring;
635 struct e1000_rx_ring *rxdr = adapter->rx_ring;
637 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
638 E1000_MAX_82544_RXD;
639 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
640 E1000_MAX_82544_TXD;
641 ring->rx_mini_max_pending = 0;
642 ring->rx_jumbo_max_pending = 0;
643 ring->rx_pending = rxdr->count;
644 ring->tx_pending = txdr->count;
645 ring->rx_mini_pending = 0;
646 ring->rx_jumbo_pending = 0;
649 static int
650 e1000_set_ringparam(struct net_device *netdev,
651 struct ethtool_ringparam *ring)
653 struct e1000_adapter *adapter = netdev_priv(netdev);
654 e1000_mac_type mac_type = adapter->hw.mac_type;
655 struct e1000_tx_ring *txdr, *tx_old;
656 struct e1000_rx_ring *rxdr, *rx_old;
657 int i, err;
659 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
660 return -EINVAL;
662 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
663 msleep(1);
665 if (netif_running(adapter->netdev))
666 e1000_down(adapter);
668 tx_old = adapter->tx_ring;
669 rx_old = adapter->rx_ring;
671 err = -ENOMEM;
672 txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring), GFP_KERNEL);
673 if (!txdr)
674 goto err_alloc_tx;
676 rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring), GFP_KERNEL);
677 if (!rxdr)
678 goto err_alloc_rx;
680 adapter->tx_ring = txdr;
681 adapter->rx_ring = rxdr;
683 rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
684 rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
685 E1000_MAX_RXD : E1000_MAX_82544_RXD));
686 rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
688 txdr->count = max(ring->tx_pending,(uint32_t)E1000_MIN_TXD);
689 txdr->count = min(txdr->count,(uint32_t)(mac_type < e1000_82544 ?
690 E1000_MAX_TXD : E1000_MAX_82544_TXD));
691 txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
693 for (i = 0; i < adapter->num_tx_queues; i++)
694 txdr[i].count = txdr->count;
695 for (i = 0; i < adapter->num_rx_queues; i++)
696 rxdr[i].count = rxdr->count;
698 if (netif_running(adapter->netdev)) {
699 /* Try to get new resources before deleting old */
700 if ((err = e1000_setup_all_rx_resources(adapter)))
701 goto err_setup_rx;
702 if ((err = e1000_setup_all_tx_resources(adapter)))
703 goto err_setup_tx;
705 /* save the new, restore the old in order to free it,
706 * then restore the new back again */
708 adapter->rx_ring = rx_old;
709 adapter->tx_ring = tx_old;
710 e1000_free_all_rx_resources(adapter);
711 e1000_free_all_tx_resources(adapter);
712 kfree(tx_old);
713 kfree(rx_old);
714 adapter->rx_ring = rxdr;
715 adapter->tx_ring = txdr;
716 if ((err = e1000_up(adapter)))
717 goto err_setup;
720 clear_bit(__E1000_RESETTING, &adapter->flags);
721 return 0;
722 err_setup_tx:
723 e1000_free_all_rx_resources(adapter);
724 err_setup_rx:
725 adapter->rx_ring = rx_old;
726 adapter->tx_ring = tx_old;
727 kfree(rxdr);
728 err_alloc_rx:
729 kfree(txdr);
730 err_alloc_tx:
731 e1000_up(adapter);
732 err_setup:
733 clear_bit(__E1000_RESETTING, &adapter->flags);
734 return err;
737 #define REG_PATTERN_TEST(R, M, W) \
739 uint32_t pat, value; \
740 uint32_t test[] = \
741 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; \
742 for (pat = 0; pat < ARRAY_SIZE(test); pat++) { \
743 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \
744 value = E1000_READ_REG(&adapter->hw, R); \
745 if (value != (test[pat] & W & M)) { \
746 DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
747 "0x%08X expected 0x%08X\n", \
748 E1000_##R, value, (test[pat] & W & M)); \
749 *data = (adapter->hw.mac_type < e1000_82543) ? \
750 E1000_82542_##R : E1000_##R; \
751 return 1; \
756 #define REG_SET_AND_CHECK(R, M, W) \
758 uint32_t value; \
759 E1000_WRITE_REG(&adapter->hw, R, W & M); \
760 value = E1000_READ_REG(&adapter->hw, R); \
761 if ((W & M) != (value & M)) { \
762 DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
763 "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
764 *data = (adapter->hw.mac_type < e1000_82543) ? \
765 E1000_82542_##R : E1000_##R; \
766 return 1; \
770 static int
771 e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
773 uint32_t value, before, after;
774 uint32_t i, toggle;
776 /* The status register is Read Only, so a write should fail.
777 * Some bits that get toggled are ignored.
779 switch (adapter->hw.mac_type) {
780 /* there are several bits on newer hardware that are r/w */
781 case e1000_82571:
782 case e1000_82572:
783 case e1000_80003es2lan:
784 toggle = 0x7FFFF3FF;
785 break;
786 case e1000_82573:
787 case e1000_ich8lan:
788 toggle = 0x7FFFF033;
789 break;
790 default:
791 toggle = 0xFFFFF833;
792 break;
795 before = E1000_READ_REG(&adapter->hw, STATUS);
796 value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle);
797 E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
798 after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
799 if (value != after) {
800 DPRINTK(DRV, ERR, "failed STATUS register test got: "
801 "0x%08X expected: 0x%08X\n", after, value);
802 *data = 1;
803 return 1;
805 /* restore previous status */
806 E1000_WRITE_REG(&adapter->hw, STATUS, before);
808 if (adapter->hw.mac_type != e1000_ich8lan) {
809 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
810 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
811 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
812 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
815 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
816 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
817 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
818 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
819 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
820 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
821 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
822 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
823 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
824 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
826 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
828 before = (adapter->hw.mac_type == e1000_ich8lan ?
829 0x06C3B33E : 0x06DFB3FE);
830 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
831 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
833 if (adapter->hw.mac_type >= e1000_82543) {
835 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
836 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
837 if (adapter->hw.mac_type != e1000_ich8lan)
838 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
839 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
840 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
841 value = (adapter->hw.mac_type == e1000_ich8lan ?
842 E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
843 for (i = 0; i < value; i++) {
844 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
845 0xFFFFFFFF);
848 } else {
850 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
851 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
852 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
853 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
857 value = (adapter->hw.mac_type == e1000_ich8lan ?
858 E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
859 for (i = 0; i < value; i++)
860 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
862 *data = 0;
863 return 0;
866 static int
867 e1000_eeprom_test(struct e1000_adapter *adapter, uint64_t *data)
869 uint16_t temp;
870 uint16_t checksum = 0;
871 uint16_t i;
873 *data = 0;
874 /* Read and add up the contents of the EEPROM */
875 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
876 if ((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) {
877 *data = 1;
878 break;
880 checksum += temp;
883 /* If Checksum is not Correct return error else test passed */
884 if ((checksum != (uint16_t) EEPROM_SUM) && !(*data))
885 *data = 2;
887 return *data;
890 static irqreturn_t
891 e1000_test_intr(int irq, void *data)
893 struct net_device *netdev = (struct net_device *) data;
894 struct e1000_adapter *adapter = netdev_priv(netdev);
896 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);
898 return IRQ_HANDLED;
901 static int
902 e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
904 struct net_device *netdev = adapter->netdev;
905 uint32_t mask, i=0, shared_int = TRUE;
906 uint32_t irq = adapter->pdev->irq;
908 *data = 0;
910 /* NOTE: we don't test MSI interrupts here, yet */
911 /* Hook up test interrupt handler just for this test */
912 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
913 netdev))
914 shared_int = FALSE;
915 else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
916 netdev->name, netdev)) {
917 *data = 1;
918 return -1;
920 DPRINTK(HW, INFO, "testing %s interrupt\n",
921 (shared_int ? "shared" : "unshared"));
923 /* Disable all the interrupts */
924 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
925 msleep(10);
927 /* Test each interrupt */
928 for (; i < 10; i++) {
930 if (adapter->hw.mac_type == e1000_ich8lan && i == 8)
931 continue;
933 /* Interrupt to test */
934 mask = 1 << i;
936 if (!shared_int) {
937 /* Disable the interrupt to be reported in
938 * the cause register and then force the same
939 * interrupt and see if one gets posted. If
940 * an interrupt was posted to the bus, the
941 * test failed.
943 adapter->test_icr = 0;
944 E1000_WRITE_REG(&adapter->hw, IMC, mask);
945 E1000_WRITE_REG(&adapter->hw, ICS, mask);
946 msleep(10);
948 if (adapter->test_icr & mask) {
949 *data = 3;
950 break;
954 /* Enable the interrupt to be reported in
955 * the cause register and then force the same
956 * interrupt and see if one gets posted. If
957 * an interrupt was not posted to the bus, the
958 * test failed.
960 adapter->test_icr = 0;
961 E1000_WRITE_REG(&adapter->hw, IMS, mask);
962 E1000_WRITE_REG(&adapter->hw, ICS, mask);
963 msleep(10);
965 if (!(adapter->test_icr & mask)) {
966 *data = 4;
967 break;
970 if (!shared_int) {
971 /* Disable the other interrupts to be reported in
972 * the cause register and then force the other
973 * interrupts and see if any get posted. If
974 * an interrupt was posted to the bus, the
975 * test failed.
977 adapter->test_icr = 0;
978 E1000_WRITE_REG(&adapter->hw, IMC, ~mask & 0x00007FFF);
979 E1000_WRITE_REG(&adapter->hw, ICS, ~mask & 0x00007FFF);
980 msleep(10);
982 if (adapter->test_icr) {
983 *data = 5;
984 break;
989 /* Disable all the interrupts */
990 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
991 msleep(10);
993 /* Unhook test interrupt handler */
994 free_irq(irq, netdev);
996 return *data;
999 static void
1000 e1000_free_desc_rings(struct e1000_adapter *adapter)
1002 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1003 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1004 struct pci_dev *pdev = adapter->pdev;
1005 int i;
1007 if (txdr->desc && txdr->buffer_info) {
1008 for (i = 0; i < txdr->count; i++) {
1009 if (txdr->buffer_info[i].dma)
1010 pci_unmap_single(pdev, txdr->buffer_info[i].dma,
1011 txdr->buffer_info[i].length,
1012 PCI_DMA_TODEVICE);
1013 if (txdr->buffer_info[i].skb)
1014 dev_kfree_skb(txdr->buffer_info[i].skb);
1018 if (rxdr->desc && rxdr->buffer_info) {
1019 for (i = 0; i < rxdr->count; i++) {
1020 if (rxdr->buffer_info[i].dma)
1021 pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
1022 rxdr->buffer_info[i].length,
1023 PCI_DMA_FROMDEVICE);
1024 if (rxdr->buffer_info[i].skb)
1025 dev_kfree_skb(rxdr->buffer_info[i].skb);
1029 if (txdr->desc) {
1030 pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
1031 txdr->desc = NULL;
1033 if (rxdr->desc) {
1034 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
1035 rxdr->desc = NULL;
1038 kfree(txdr->buffer_info);
1039 txdr->buffer_info = NULL;
1040 kfree(rxdr->buffer_info);
1041 rxdr->buffer_info = NULL;
1043 return;
1046 static int
1047 e1000_setup_desc_rings(struct e1000_adapter *adapter)
1049 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1050 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1051 struct pci_dev *pdev = adapter->pdev;
1052 uint32_t rctl;
1053 int i, ret_val;
1055 /* Setup Tx descriptor ring and Tx buffers */
1057 if (!txdr->count)
1058 txdr->count = E1000_DEFAULT_TXD;
1060 if (!(txdr->buffer_info = kcalloc(txdr->count,
1061 sizeof(struct e1000_buffer),
1062 GFP_KERNEL))) {
1063 ret_val = 1;
1064 goto err_nomem;
1067 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1068 txdr->size = ALIGN(txdr->size, 4096);
1069 if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size,
1070 &txdr->dma))) {
1071 ret_val = 2;
1072 goto err_nomem;
1074 memset(txdr->desc, 0, txdr->size);
1075 txdr->next_to_use = txdr->next_to_clean = 0;
1077 E1000_WRITE_REG(&adapter->hw, TDBAL,
1078 ((uint64_t) txdr->dma & 0x00000000FFFFFFFF));
1079 E1000_WRITE_REG(&adapter->hw, TDBAH, ((uint64_t) txdr->dma >> 32));
1080 E1000_WRITE_REG(&adapter->hw, TDLEN,
1081 txdr->count * sizeof(struct e1000_tx_desc));
1082 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1083 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1084 E1000_WRITE_REG(&adapter->hw, TCTL,
1085 E1000_TCTL_PSP | E1000_TCTL_EN |
1086 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1087 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1089 for (i = 0; i < txdr->count; i++) {
1090 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
1091 struct sk_buff *skb;
1092 unsigned int size = 1024;
1094 if (!(skb = alloc_skb(size, GFP_KERNEL))) {
1095 ret_val = 3;
1096 goto err_nomem;
1098 skb_put(skb, size);
1099 txdr->buffer_info[i].skb = skb;
1100 txdr->buffer_info[i].length = skb->len;
1101 txdr->buffer_info[i].dma =
1102 pci_map_single(pdev, skb->data, skb->len,
1103 PCI_DMA_TODEVICE);
1104 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
1105 tx_desc->lower.data = cpu_to_le32(skb->len);
1106 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1107 E1000_TXD_CMD_IFCS |
1108 E1000_TXD_CMD_RPS);
1109 tx_desc->upper.data = 0;
1112 /* Setup Rx descriptor ring and Rx buffers */
1114 if (!rxdr->count)
1115 rxdr->count = E1000_DEFAULT_RXD;
1117 if (!(rxdr->buffer_info = kcalloc(rxdr->count,
1118 sizeof(struct e1000_buffer),
1119 GFP_KERNEL))) {
1120 ret_val = 4;
1121 goto err_nomem;
1124 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
1125 if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
1126 ret_val = 5;
1127 goto err_nomem;
1129 memset(rxdr->desc, 0, rxdr->size);
1130 rxdr->next_to_use = rxdr->next_to_clean = 0;
1132 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1133 E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
1134 E1000_WRITE_REG(&adapter->hw, RDBAL,
1135 ((uint64_t) rxdr->dma & 0xFFFFFFFF));
1136 E1000_WRITE_REG(&adapter->hw, RDBAH, ((uint64_t) rxdr->dma >> 32));
1137 E1000_WRITE_REG(&adapter->hw, RDLEN, rxdr->size);
1138 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1139 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1140 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1141 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1142 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1143 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1145 for (i = 0; i < rxdr->count; i++) {
1146 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1147 struct sk_buff *skb;
1149 if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
1150 GFP_KERNEL))) {
1151 ret_val = 6;
1152 goto err_nomem;
1154 skb_reserve(skb, NET_IP_ALIGN);
1155 rxdr->buffer_info[i].skb = skb;
1156 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1157 rxdr->buffer_info[i].dma =
1158 pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
1159 PCI_DMA_FROMDEVICE);
1160 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1161 memset(skb->data, 0x00, skb->len);
1164 return 0;
1166 err_nomem:
1167 e1000_free_desc_rings(adapter);
1168 return ret_val;
1171 static void
1172 e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1174 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1175 e1000_write_phy_reg(&adapter->hw, 29, 0x001F);
1176 e1000_write_phy_reg(&adapter->hw, 30, 0x8FFC);
1177 e1000_write_phy_reg(&adapter->hw, 29, 0x001A);
1178 e1000_write_phy_reg(&adapter->hw, 30, 0x8FF0);
1181 static void
1182 e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
1184 uint16_t phy_reg;
1186 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1187 * Extended PHY Specific Control Register to 25MHz clock. This
1188 * value defaults back to a 2.5MHz clock when the PHY is reset.
1190 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1191 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
1192 e1000_write_phy_reg(&adapter->hw,
1193 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1195 /* In addition, because of the s/w reset above, we need to enable
1196 * CRS on TX. This must be set for both full and half duplex
1197 * operation.
1199 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1200 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1201 e1000_write_phy_reg(&adapter->hw,
1202 M88E1000_PHY_SPEC_CTRL, phy_reg);
1205 static int
1206 e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
1208 uint32_t ctrl_reg;
1209 uint16_t phy_reg;
1211 /* Setup the Device Control Register for PHY loopback test. */
1213 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1214 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1215 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1216 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1217 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1218 E1000_CTRL_FD); /* Force Duplex to FULL */
1220 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1222 /* Read the PHY Specific Control Register (0x10) */
1223 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1225 /* Clear Auto-Crossover bits in PHY Specific Control Register
1226 * (bits 6:5).
1228 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
1229 e1000_write_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
1231 /* Perform software reset on the PHY */
1232 e1000_phy_reset(&adapter->hw);
1234 /* Have to setup TX_CLK and TX_CRS after software reset */
1235 e1000_phy_reset_clk_and_crs(adapter);
1237 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8100);
1239 /* Wait for reset to complete. */
1240 udelay(500);
1242 /* Have to setup TX_CLK and TX_CRS after software reset */
1243 e1000_phy_reset_clk_and_crs(adapter);
1245 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1246 e1000_phy_disable_receiver(adapter);
1248 /* Set the loopback bit in the PHY control register. */
1249 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1250 phy_reg |= MII_CR_LOOPBACK;
1251 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1253 /* Setup TX_CLK and TX_CRS one more time. */
1254 e1000_phy_reset_clk_and_crs(adapter);
1256 /* Check Phy Configuration */
1257 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1258 if (phy_reg != 0x4100)
1259 return 9;
1261 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1262 if (phy_reg != 0x0070)
1263 return 10;
1265 e1000_read_phy_reg(&adapter->hw, 29, &phy_reg);
1266 if (phy_reg != 0x001A)
1267 return 11;
1269 return 0;
1272 static int
1273 e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1275 uint32_t ctrl_reg = 0;
1276 uint32_t stat_reg = 0;
1278 adapter->hw.autoneg = FALSE;
1280 if (adapter->hw.phy_type == e1000_phy_m88) {
1281 /* Auto-MDI/MDIX Off */
1282 e1000_write_phy_reg(&adapter->hw,
1283 M88E1000_PHY_SPEC_CTRL, 0x0808);
1284 /* reset to update Auto-MDI/MDIX */
1285 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x9140);
1286 /* autoneg off */
1287 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8140);
1288 } else if (adapter->hw.phy_type == e1000_phy_gg82563)
1289 e1000_write_phy_reg(&adapter->hw,
1290 GG82563_PHY_KMRN_MODE_CTRL,
1291 0x1CC);
1293 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1295 if (adapter->hw.phy_type == e1000_phy_ife) {
1296 /* force 100, set loopback */
1297 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x6100);
1299 /* Now set up the MAC to the same speed/duplex as the PHY. */
1300 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1301 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1302 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1303 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1304 E1000_CTRL_FD); /* Force Duplex to FULL */
1305 } else {
1306 /* force 1000, set loopback */
1307 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140);
1309 /* Now set up the MAC to the same speed/duplex as the PHY. */
1310 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1311 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1312 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1313 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1314 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1315 E1000_CTRL_FD); /* Force Duplex to FULL */
1318 if (adapter->hw.media_type == e1000_media_type_copper &&
1319 adapter->hw.phy_type == e1000_phy_m88)
1320 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1321 else {
1322 /* Set the ILOS bit on the fiber Nic is half
1323 * duplex link is detected. */
1324 stat_reg = E1000_READ_REG(&adapter->hw, STATUS);
1325 if ((stat_reg & E1000_STATUS_FD) == 0)
1326 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1329 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1331 /* Disable the receiver on the PHY so when a cable is plugged in, the
1332 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1334 if (adapter->hw.phy_type == e1000_phy_m88)
1335 e1000_phy_disable_receiver(adapter);
1337 udelay(500);
1339 return 0;
1342 static int
1343 e1000_set_phy_loopback(struct e1000_adapter *adapter)
1345 uint16_t phy_reg = 0;
1346 uint16_t count = 0;
1348 switch (adapter->hw.mac_type) {
1349 case e1000_82543:
1350 if (adapter->hw.media_type == e1000_media_type_copper) {
1351 /* Attempt to setup Loopback mode on Non-integrated PHY.
1352 * Some PHY registers get corrupted at random, so
1353 * attempt this 10 times.
1355 while (e1000_nonintegrated_phy_loopback(adapter) &&
1356 count++ < 10);
1357 if (count < 11)
1358 return 0;
1360 break;
1362 case e1000_82544:
1363 case e1000_82540:
1364 case e1000_82545:
1365 case e1000_82545_rev_3:
1366 case e1000_82546:
1367 case e1000_82546_rev_3:
1368 case e1000_82541:
1369 case e1000_82541_rev_2:
1370 case e1000_82547:
1371 case e1000_82547_rev_2:
1372 case e1000_82571:
1373 case e1000_82572:
1374 case e1000_82573:
1375 case e1000_80003es2lan:
1376 case e1000_ich8lan:
1377 return e1000_integrated_phy_loopback(adapter);
1378 break;
1380 default:
1381 /* Default PHY loopback work is to read the MII
1382 * control register and assert bit 14 (loopback mode).
1384 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1385 phy_reg |= MII_CR_LOOPBACK;
1386 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1387 return 0;
1388 break;
1391 return 8;
1394 static int
1395 e1000_setup_loopback_test(struct e1000_adapter *adapter)
1397 struct e1000_hw *hw = &adapter->hw;
1398 uint32_t rctl;
1400 if (hw->media_type == e1000_media_type_fiber ||
1401 hw->media_type == e1000_media_type_internal_serdes) {
1402 switch (hw->mac_type) {
1403 case e1000_82545:
1404 case e1000_82546:
1405 case e1000_82545_rev_3:
1406 case e1000_82546_rev_3:
1407 return e1000_set_phy_loopback(adapter);
1408 break;
1409 case e1000_82571:
1410 case e1000_82572:
1411 #define E1000_SERDES_LB_ON 0x410
1412 e1000_set_phy_loopback(adapter);
1413 E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_ON);
1414 msleep(10);
1415 return 0;
1416 break;
1417 default:
1418 rctl = E1000_READ_REG(hw, RCTL);
1419 rctl |= E1000_RCTL_LBM_TCVR;
1420 E1000_WRITE_REG(hw, RCTL, rctl);
1421 return 0;
1423 } else if (hw->media_type == e1000_media_type_copper)
1424 return e1000_set_phy_loopback(adapter);
1426 return 7;
1429 static void
1430 e1000_loopback_cleanup(struct e1000_adapter *adapter)
1432 struct e1000_hw *hw = &adapter->hw;
1433 uint32_t rctl;
1434 uint16_t phy_reg;
1436 rctl = E1000_READ_REG(hw, RCTL);
1437 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1438 E1000_WRITE_REG(hw, RCTL, rctl);
1440 switch (hw->mac_type) {
1441 case e1000_82571:
1442 case e1000_82572:
1443 if (hw->media_type == e1000_media_type_fiber ||
1444 hw->media_type == e1000_media_type_internal_serdes) {
1445 #define E1000_SERDES_LB_OFF 0x400
1446 E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_OFF);
1447 msleep(10);
1448 break;
1450 /* Fall Through */
1451 case e1000_82545:
1452 case e1000_82546:
1453 case e1000_82545_rev_3:
1454 case e1000_82546_rev_3:
1455 default:
1456 hw->autoneg = TRUE;
1457 if (hw->phy_type == e1000_phy_gg82563)
1458 e1000_write_phy_reg(hw,
1459 GG82563_PHY_KMRN_MODE_CTRL,
1460 0x180);
1461 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1462 if (phy_reg & MII_CR_LOOPBACK) {
1463 phy_reg &= ~MII_CR_LOOPBACK;
1464 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1465 e1000_phy_reset(hw);
1467 break;
1471 static void
1472 e1000_create_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1474 memset(skb->data, 0xFF, frame_size);
1475 frame_size &= ~1;
1476 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1477 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1478 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1481 static int
1482 e1000_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1484 frame_size &= ~1;
1485 if (*(skb->data + 3) == 0xFF) {
1486 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1487 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1488 return 0;
1491 return 13;
1494 static int
1495 e1000_run_loopback_test(struct e1000_adapter *adapter)
1497 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1498 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1499 struct pci_dev *pdev = adapter->pdev;
1500 int i, j, k, l, lc, good_cnt, ret_val=0;
1501 unsigned long time;
1503 E1000_WRITE_REG(&adapter->hw, RDT, rxdr->count - 1);
1505 /* Calculate the loop count based on the largest descriptor ring
1506 * The idea is to wrap the largest ring a number of times using 64
1507 * send/receive pairs during each loop
1510 if (rxdr->count <= txdr->count)
1511 lc = ((txdr->count / 64) * 2) + 1;
1512 else
1513 lc = ((rxdr->count / 64) * 2) + 1;
1515 k = l = 0;
1516 for (j = 0; j <= lc; j++) { /* loop count loop */
1517 for (i = 0; i < 64; i++) { /* send the packets */
1518 e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
1519 1024);
1520 pci_dma_sync_single_for_device(pdev,
1521 txdr->buffer_info[k].dma,
1522 txdr->buffer_info[k].length,
1523 PCI_DMA_TODEVICE);
1524 if (unlikely(++k == txdr->count)) k = 0;
1526 E1000_WRITE_REG(&adapter->hw, TDT, k);
1527 msleep(200);
1528 time = jiffies; /* set the start time for the receive */
1529 good_cnt = 0;
1530 do { /* receive the sent packets */
1531 pci_dma_sync_single_for_cpu(pdev,
1532 rxdr->buffer_info[l].dma,
1533 rxdr->buffer_info[l].length,
1534 PCI_DMA_FROMDEVICE);
1536 ret_val = e1000_check_lbtest_frame(
1537 rxdr->buffer_info[l].skb,
1538 1024);
1539 if (!ret_val)
1540 good_cnt++;
1541 if (unlikely(++l == rxdr->count)) l = 0;
1542 /* time + 20 msecs (200 msecs on 2.4) is more than
1543 * enough time to complete the receives, if it's
1544 * exceeded, break and error off
1546 } while (good_cnt < 64 && jiffies < (time + 20));
1547 if (good_cnt != 64) {
1548 ret_val = 13; /* ret_val is the same as mis-compare */
1549 break;
1551 if (jiffies >= (time + 2)) {
1552 ret_val = 14; /* error code for time out error */
1553 break;
1555 } /* end loop count loop */
1556 return ret_val;
1559 static int
1560 e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data)
1562 /* PHY loopback cannot be performed if SoL/IDER
1563 * sessions are active */
1564 if (e1000_check_phy_reset_block(&adapter->hw)) {
1565 DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
1566 "when SoL/IDER is active.\n");
1567 *data = 0;
1568 goto out;
1571 if ((*data = e1000_setup_desc_rings(adapter)))
1572 goto out;
1573 if ((*data = e1000_setup_loopback_test(adapter)))
1574 goto err_loopback;
1575 *data = e1000_run_loopback_test(adapter);
1576 e1000_loopback_cleanup(adapter);
1578 err_loopback:
1579 e1000_free_desc_rings(adapter);
1580 out:
1581 return *data;
1584 static int
1585 e1000_link_test(struct e1000_adapter *adapter, uint64_t *data)
1587 *data = 0;
1588 if (adapter->hw.media_type == e1000_media_type_internal_serdes) {
1589 int i = 0;
1590 adapter->hw.serdes_link_down = TRUE;
1592 /* On some blade server designs, link establishment
1593 * could take as long as 2-3 minutes */
1594 do {
1595 e1000_check_for_link(&adapter->hw);
1596 if (adapter->hw.serdes_link_down == FALSE)
1597 return *data;
1598 msleep(20);
1599 } while (i++ < 3750);
1601 *data = 1;
1602 } else {
1603 e1000_check_for_link(&adapter->hw);
1604 if (adapter->hw.autoneg) /* if auto_neg is set wait for it */
1605 msleep(4000);
1607 if (!(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) {
1608 *data = 1;
1611 return *data;
1614 static int
1615 e1000_diag_test_count(struct net_device *netdev)
1617 return E1000_TEST_LEN;
1620 extern void e1000_power_up_phy(struct e1000_adapter *);
1622 static void
1623 e1000_diag_test(struct net_device *netdev,
1624 struct ethtool_test *eth_test, uint64_t *data)
1626 struct e1000_adapter *adapter = netdev_priv(netdev);
1627 boolean_t if_running = netif_running(netdev);
1629 set_bit(__E1000_TESTING, &adapter->flags);
1630 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1631 /* Offline tests */
1633 /* save speed, duplex, autoneg settings */
1634 uint16_t autoneg_advertised = adapter->hw.autoneg_advertised;
1635 uint8_t forced_speed_duplex = adapter->hw.forced_speed_duplex;
1636 uint8_t autoneg = adapter->hw.autoneg;
1638 DPRINTK(HW, INFO, "offline testing starting\n");
1640 /* Link test performed before hardware reset so autoneg doesn't
1641 * interfere with test result */
1642 if (e1000_link_test(adapter, &data[4]))
1643 eth_test->flags |= ETH_TEST_FL_FAILED;
1645 if (if_running)
1646 /* indicate we're in test mode */
1647 dev_close(netdev);
1648 else
1649 e1000_reset(adapter);
1651 if (e1000_reg_test(adapter, &data[0]))
1652 eth_test->flags |= ETH_TEST_FL_FAILED;
1654 e1000_reset(adapter);
1655 if (e1000_eeprom_test(adapter, &data[1]))
1656 eth_test->flags |= ETH_TEST_FL_FAILED;
1658 e1000_reset(adapter);
1659 if (e1000_intr_test(adapter, &data[2]))
1660 eth_test->flags |= ETH_TEST_FL_FAILED;
1662 e1000_reset(adapter);
1663 /* make sure the phy is powered up */
1664 e1000_power_up_phy(adapter);
1665 if (e1000_loopback_test(adapter, &data[3]))
1666 eth_test->flags |= ETH_TEST_FL_FAILED;
1668 /* restore speed, duplex, autoneg settings */
1669 adapter->hw.autoneg_advertised = autoneg_advertised;
1670 adapter->hw.forced_speed_duplex = forced_speed_duplex;
1671 adapter->hw.autoneg = autoneg;
1673 e1000_reset(adapter);
1674 clear_bit(__E1000_TESTING, &adapter->flags);
1675 if (if_running)
1676 dev_open(netdev);
1677 } else {
1678 DPRINTK(HW, INFO, "online testing starting\n");
1679 /* Online tests */
1680 if (e1000_link_test(adapter, &data[4]))
1681 eth_test->flags |= ETH_TEST_FL_FAILED;
1683 /* Online tests aren't run; pass by default */
1684 data[0] = 0;
1685 data[1] = 0;
1686 data[2] = 0;
1687 data[3] = 0;
1689 clear_bit(__E1000_TESTING, &adapter->flags);
1691 msleep_interruptible(4 * 1000);
1694 static int e1000_wol_exclusion(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
1696 struct e1000_hw *hw = &adapter->hw;
1697 int retval = 1; /* fail by default */
1699 switch (hw->device_id) {
1700 case E1000_DEV_ID_82542:
1701 case E1000_DEV_ID_82543GC_FIBER:
1702 case E1000_DEV_ID_82543GC_COPPER:
1703 case E1000_DEV_ID_82544EI_FIBER:
1704 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1705 case E1000_DEV_ID_82545EM_FIBER:
1706 case E1000_DEV_ID_82545EM_COPPER:
1707 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1708 case E1000_DEV_ID_82546GB_PCIE:
1709 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1710 /* these don't support WoL at all */
1711 wol->supported = 0;
1712 break;
1713 case E1000_DEV_ID_82546EB_FIBER:
1714 case E1000_DEV_ID_82546GB_FIBER:
1715 case E1000_DEV_ID_82571EB_FIBER:
1716 case E1000_DEV_ID_82571EB_SERDES:
1717 case E1000_DEV_ID_82571EB_COPPER:
1718 /* Wake events not supported on port B */
1719 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
1720 wol->supported = 0;
1721 break;
1723 /* return success for non excluded adapter ports */
1724 retval = 0;
1725 break;
1726 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1727 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1728 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1729 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1730 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1731 /* quad port adapters only support WoL on port A */
1732 if (!adapter->quad_port_a) {
1733 wol->supported = 0;
1734 break;
1736 /* return success for non excluded adapter ports */
1737 retval = 0;
1738 break;
1739 default:
1740 /* dual port cards only support WoL on port A from now on
1741 * unless it was enabled in the eeprom for port B
1742 * so exclude FUNC_1 ports from having WoL enabled */
1743 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1 &&
1744 !adapter->eeprom_wol) {
1745 wol->supported = 0;
1746 break;
1749 retval = 0;
1752 return retval;
1755 static void
1756 e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1758 struct e1000_adapter *adapter = netdev_priv(netdev);
1760 wol->supported = WAKE_UCAST | WAKE_MCAST |
1761 WAKE_BCAST | WAKE_MAGIC;
1762 wol->wolopts = 0;
1764 /* this function will set ->supported = 0 and return 1 if wol is not
1765 * supported by this hardware */
1766 if (e1000_wol_exclusion(adapter, wol))
1767 return;
1769 /* apply any specific unsupported masks here */
1770 switch (adapter->hw.device_id) {
1771 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1772 /* KSP3 does not suppport UCAST wake-ups */
1773 wol->supported &= ~WAKE_UCAST;
1775 if (adapter->wol & E1000_WUFC_EX)
1776 DPRINTK(DRV, ERR, "Interface does not support "
1777 "directed (unicast) frame wake-up packets\n");
1778 break;
1779 default:
1780 break;
1783 if (adapter->wol & E1000_WUFC_EX)
1784 wol->wolopts |= WAKE_UCAST;
1785 if (adapter->wol & E1000_WUFC_MC)
1786 wol->wolopts |= WAKE_MCAST;
1787 if (adapter->wol & E1000_WUFC_BC)
1788 wol->wolopts |= WAKE_BCAST;
1789 if (adapter->wol & E1000_WUFC_MAG)
1790 wol->wolopts |= WAKE_MAGIC;
1792 return;
1795 static int
1796 e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1798 struct e1000_adapter *adapter = netdev_priv(netdev);
1799 struct e1000_hw *hw = &adapter->hw;
1801 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1802 return -EOPNOTSUPP;
1804 if (e1000_wol_exclusion(adapter, wol))
1805 return wol->wolopts ? -EOPNOTSUPP : 0;
1807 switch (hw->device_id) {
1808 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1809 if (wol->wolopts & WAKE_UCAST) {
1810 DPRINTK(DRV, ERR, "Interface does not support "
1811 "directed (unicast) frame wake-up packets\n");
1812 return -EOPNOTSUPP;
1814 break;
1815 default:
1816 break;
1819 /* these settings will always override what we currently have */
1820 adapter->wol = 0;
1822 if (wol->wolopts & WAKE_UCAST)
1823 adapter->wol |= E1000_WUFC_EX;
1824 if (wol->wolopts & WAKE_MCAST)
1825 adapter->wol |= E1000_WUFC_MC;
1826 if (wol->wolopts & WAKE_BCAST)
1827 adapter->wol |= E1000_WUFC_BC;
1828 if (wol->wolopts & WAKE_MAGIC)
1829 adapter->wol |= E1000_WUFC_MAG;
1831 return 0;
1834 /* toggle LED 4 times per second = 2 "blinks" per second */
1835 #define E1000_ID_INTERVAL (HZ/4)
1837 /* bit defines for adapter->led_status */
1838 #define E1000_LED_ON 0
1840 static void
1841 e1000_led_blink_callback(unsigned long data)
1843 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1845 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1846 e1000_led_off(&adapter->hw);
1847 else
1848 e1000_led_on(&adapter->hw);
1850 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1853 static int
1854 e1000_phys_id(struct net_device *netdev, uint32_t data)
1856 struct e1000_adapter *adapter = netdev_priv(netdev);
1858 if (!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
1859 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
1861 if (adapter->hw.mac_type < e1000_82571) {
1862 if (!adapter->blink_timer.function) {
1863 init_timer(&adapter->blink_timer);
1864 adapter->blink_timer.function = e1000_led_blink_callback;
1865 adapter->blink_timer.data = (unsigned long) adapter;
1867 e1000_setup_led(&adapter->hw);
1868 mod_timer(&adapter->blink_timer, jiffies);
1869 msleep_interruptible(data * 1000);
1870 del_timer_sync(&adapter->blink_timer);
1871 } else if (adapter->hw.phy_type == e1000_phy_ife) {
1872 if (!adapter->blink_timer.function) {
1873 init_timer(&adapter->blink_timer);
1874 adapter->blink_timer.function = e1000_led_blink_callback;
1875 adapter->blink_timer.data = (unsigned long) adapter;
1877 mod_timer(&adapter->blink_timer, jiffies);
1878 msleep_interruptible(data * 1000);
1879 del_timer_sync(&adapter->blink_timer);
1880 e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
1881 } else {
1882 e1000_blink_led_start(&adapter->hw);
1883 msleep_interruptible(data * 1000);
1886 e1000_led_off(&adapter->hw);
1887 clear_bit(E1000_LED_ON, &adapter->led_status);
1888 e1000_cleanup_led(&adapter->hw);
1890 return 0;
1893 static int
1894 e1000_nway_reset(struct net_device *netdev)
1896 struct e1000_adapter *adapter = netdev_priv(netdev);
1897 if (netif_running(netdev))
1898 e1000_reinit_locked(adapter);
1899 return 0;
1902 static int
1903 e1000_get_stats_count(struct net_device *netdev)
1905 return E1000_STATS_LEN;
1908 static void
1909 e1000_get_ethtool_stats(struct net_device *netdev,
1910 struct ethtool_stats *stats, uint64_t *data)
1912 struct e1000_adapter *adapter = netdev_priv(netdev);
1913 int i;
1915 e1000_update_stats(adapter);
1916 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1917 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1918 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1919 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
1921 /* BUG_ON(i != E1000_STATS_LEN); */
1924 static void
1925 e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
1927 uint8_t *p = data;
1928 int i;
1930 switch (stringset) {
1931 case ETH_SS_TEST:
1932 memcpy(data, *e1000_gstrings_test,
1933 E1000_TEST_LEN*ETH_GSTRING_LEN);
1934 break;
1935 case ETH_SS_STATS:
1936 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1937 memcpy(p, e1000_gstrings_stats[i].stat_string,
1938 ETH_GSTRING_LEN);
1939 p += ETH_GSTRING_LEN;
1941 /* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
1942 break;
1946 static const struct ethtool_ops e1000_ethtool_ops = {
1947 .get_settings = e1000_get_settings,
1948 .set_settings = e1000_set_settings,
1949 .get_drvinfo = e1000_get_drvinfo,
1950 .get_regs_len = e1000_get_regs_len,
1951 .get_regs = e1000_get_regs,
1952 .get_wol = e1000_get_wol,
1953 .set_wol = e1000_set_wol,
1954 .get_msglevel = e1000_get_msglevel,
1955 .set_msglevel = e1000_set_msglevel,
1956 .nway_reset = e1000_nway_reset,
1957 .get_link = ethtool_op_get_link,
1958 .get_eeprom_len = e1000_get_eeprom_len,
1959 .get_eeprom = e1000_get_eeprom,
1960 .set_eeprom = e1000_set_eeprom,
1961 .get_ringparam = e1000_get_ringparam,
1962 .set_ringparam = e1000_set_ringparam,
1963 .get_pauseparam = e1000_get_pauseparam,
1964 .set_pauseparam = e1000_set_pauseparam,
1965 .get_rx_csum = e1000_get_rx_csum,
1966 .set_rx_csum = e1000_set_rx_csum,
1967 .get_tx_csum = e1000_get_tx_csum,
1968 .set_tx_csum = e1000_set_tx_csum,
1969 .get_sg = ethtool_op_get_sg,
1970 .set_sg = ethtool_op_set_sg,
1971 .get_tso = ethtool_op_get_tso,
1972 .set_tso = e1000_set_tso,
1973 .self_test_count = e1000_diag_test_count,
1974 .self_test = e1000_diag_test,
1975 .get_strings = e1000_get_strings,
1976 .phys_id = e1000_phys_id,
1977 .get_stats_count = e1000_get_stats_count,
1978 .get_ethtool_stats = e1000_get_ethtool_stats,
1981 void e1000_set_ethtool_ops(struct net_device *netdev)
1983 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);