aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/e1000/e1000_ethtool.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/e1000/e1000_ethtool.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/net/e1000/e1000_ethtool.c')
-rw-r--r--drivers/net/e1000/e1000_ethtool.c1673
1 files changed, 1673 insertions, 0 deletions
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
new file mode 100644
index 000000000000..0a2ca7c73a41
--- /dev/null
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -0,0 +1,1673 @@
1/*******************************************************************************
2
3
4 Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 The full GNU General Public License is included in this distribution in the
21 file called LICENSE.
22
23 Contact Information:
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* ethtool support for e1000 */
30
31#include "e1000.h"
32
33#include <asm/uaccess.h>
34
35extern char e1000_driver_name[];
36extern char e1000_driver_version[];
37
38extern int e1000_up(struct e1000_adapter *adapter);
39extern void e1000_down(struct e1000_adapter *adapter);
40extern void e1000_reset(struct e1000_adapter *adapter);
41extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
42extern int e1000_setup_rx_resources(struct e1000_adapter *adapter);
43extern int e1000_setup_tx_resources(struct e1000_adapter *adapter);
44extern void e1000_free_rx_resources(struct e1000_adapter *adapter);
45extern void e1000_free_tx_resources(struct e1000_adapter *adapter);
46extern void e1000_update_stats(struct e1000_adapter *adapter);
47
48struct e1000_stats {
49 char stat_string[ETH_GSTRING_LEN];
50 int sizeof_stat;
51 int stat_offset;
52};
53
54#define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
55 offsetof(struct e1000_adapter, m)
56static const struct e1000_stats e1000_gstrings_stats[] = {
57 { "rx_packets", E1000_STAT(net_stats.rx_packets) },
58 { "tx_packets", E1000_STAT(net_stats.tx_packets) },
59 { "rx_bytes", E1000_STAT(net_stats.rx_bytes) },
60 { "tx_bytes", E1000_STAT(net_stats.tx_bytes) },
61 { "rx_errors", E1000_STAT(net_stats.rx_errors) },
62 { "tx_errors", E1000_STAT(net_stats.tx_errors) },
63 { "rx_dropped", E1000_STAT(net_stats.rx_dropped) },
64 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
65 { "multicast", E1000_STAT(net_stats.multicast) },
66 { "collisions", E1000_STAT(net_stats.collisions) },
67 { "rx_length_errors", E1000_STAT(net_stats.rx_length_errors) },
68 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
69 { "rx_crc_errors", E1000_STAT(net_stats.rx_crc_errors) },
70 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
71 { "rx_fifo_errors", E1000_STAT(net_stats.rx_fifo_errors) },
72 { "rx_missed_errors", E1000_STAT(net_stats.rx_missed_errors) },
73 { "tx_aborted_errors", E1000_STAT(net_stats.tx_aborted_errors) },
74 { "tx_carrier_errors", E1000_STAT(net_stats.tx_carrier_errors) },
75 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
76 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
77 { "tx_window_errors", E1000_STAT(net_stats.tx_window_errors) },
78 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
79 { "tx_deferred_ok", E1000_STAT(stats.dc) },
80 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
81 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
82 { "rx_long_length_errors", E1000_STAT(stats.roc) },
83 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
84 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
85 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
86 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
87 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
88 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
89 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
90 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
91 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
92 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
93 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) }
94};
95#define E1000_STATS_LEN \
96 sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats)
97static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
98 "Register test (offline)", "Eeprom test (offline)",
99 "Interrupt test (offline)", "Loopback test (offline)",
100 "Link test (on/offline)"
101};
102#define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN
103
104static int
105e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
106{
107 struct e1000_adapter *adapter = netdev->priv;
108 struct e1000_hw *hw = &adapter->hw;
109
110 if(hw->media_type == e1000_media_type_copper) {
111
112 ecmd->supported = (SUPPORTED_10baseT_Half |
113 SUPPORTED_10baseT_Full |
114 SUPPORTED_100baseT_Half |
115 SUPPORTED_100baseT_Full |
116 SUPPORTED_1000baseT_Full|
117 SUPPORTED_Autoneg |
118 SUPPORTED_TP);
119
120 ecmd->advertising = ADVERTISED_TP;
121
122 if(hw->autoneg == 1) {
123 ecmd->advertising |= ADVERTISED_Autoneg;
124
125 /* the e1000 autoneg seems to match ethtool nicely */
126
127 ecmd->advertising |= hw->autoneg_advertised;
128 }
129
130 ecmd->port = PORT_TP;
131 ecmd->phy_address = hw->phy_addr;
132
133 if(hw->mac_type == e1000_82543)
134 ecmd->transceiver = XCVR_EXTERNAL;
135 else
136 ecmd->transceiver = XCVR_INTERNAL;
137
138 } else {
139 ecmd->supported = (SUPPORTED_1000baseT_Full |
140 SUPPORTED_FIBRE |
141 SUPPORTED_Autoneg);
142
143 ecmd->advertising = (SUPPORTED_1000baseT_Full |
144 SUPPORTED_FIBRE |
145 SUPPORTED_Autoneg);
146
147 ecmd->port = PORT_FIBRE;
148
149 if(hw->mac_type >= e1000_82545)
150 ecmd->transceiver = XCVR_INTERNAL;
151 else
152 ecmd->transceiver = XCVR_EXTERNAL;
153 }
154
155 if(netif_carrier_ok(adapter->netdev)) {
156
157 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
158 &adapter->link_duplex);
159 ecmd->speed = adapter->link_speed;
160
161 /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
162 * and HALF_DUPLEX != DUPLEX_HALF */
163
164 if(adapter->link_duplex == FULL_DUPLEX)
165 ecmd->duplex = DUPLEX_FULL;
166 else
167 ecmd->duplex = DUPLEX_HALF;
168 } else {
169 ecmd->speed = -1;
170 ecmd->duplex = -1;
171 }
172
173 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
174 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
175 return 0;
176}
177
178static int
179e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
180{
181 struct e1000_adapter *adapter = netdev->priv;
182 struct e1000_hw *hw = &adapter->hw;
183
184 if(ecmd->autoneg == AUTONEG_ENABLE) {
185 hw->autoneg = 1;
186 hw->autoneg_advertised = 0x002F;
187 ecmd->advertising = 0x002F;
188 } else
189 if(e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex))
190 return -EINVAL;
191
192 /* reset the link */
193
194 if(netif_running(adapter->netdev)) {
195 e1000_down(adapter);
196 e1000_reset(adapter);
197 e1000_up(adapter);
198 } else
199 e1000_reset(adapter);
200
201 return 0;
202}
203
204static void
205e1000_get_pauseparam(struct net_device *netdev,
206 struct ethtool_pauseparam *pause)
207{
208 struct e1000_adapter *adapter = netdev->priv;
209 struct e1000_hw *hw = &adapter->hw;
210
211 pause->autoneg =
212 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
213
214 if(hw->fc == e1000_fc_rx_pause)
215 pause->rx_pause = 1;
216 else if(hw->fc == e1000_fc_tx_pause)
217 pause->tx_pause = 1;
218 else if(hw->fc == e1000_fc_full) {
219 pause->rx_pause = 1;
220 pause->tx_pause = 1;
221 }
222}
223
224static int
225e1000_set_pauseparam(struct net_device *netdev,
226 struct ethtool_pauseparam *pause)
227{
228 struct e1000_adapter *adapter = netdev->priv;
229 struct e1000_hw *hw = &adapter->hw;
230
231 adapter->fc_autoneg = pause->autoneg;
232
233 if(pause->rx_pause && pause->tx_pause)
234 hw->fc = e1000_fc_full;
235 else if(pause->rx_pause && !pause->tx_pause)
236 hw->fc = e1000_fc_rx_pause;
237 else if(!pause->rx_pause && pause->tx_pause)
238 hw->fc = e1000_fc_tx_pause;
239 else if(!pause->rx_pause && !pause->tx_pause)
240 hw->fc = e1000_fc_none;
241
242 hw->original_fc = hw->fc;
243
244 if(adapter->fc_autoneg == AUTONEG_ENABLE) {
245 if(netif_running(adapter->netdev)) {
246 e1000_down(adapter);
247 e1000_up(adapter);
248 } else
249 e1000_reset(adapter);
250 }
251 else
252 return ((hw->media_type == e1000_media_type_fiber) ?
253 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
254
255 return 0;
256}
257
258static uint32_t
259e1000_get_rx_csum(struct net_device *netdev)
260{
261 struct e1000_adapter *adapter = netdev->priv;
262 return adapter->rx_csum;
263}
264
265static int
266e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
267{
268 struct e1000_adapter *adapter = netdev->priv;
269 adapter->rx_csum = data;
270
271 if(netif_running(netdev)) {
272 e1000_down(adapter);
273 e1000_up(adapter);
274 } else
275 e1000_reset(adapter);
276 return 0;
277}
278
279static uint32_t
280e1000_get_tx_csum(struct net_device *netdev)
281{
282 return (netdev->features & NETIF_F_HW_CSUM) != 0;
283}
284
285static int
286e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
287{
288 struct e1000_adapter *adapter = netdev->priv;
289
290 if(adapter->hw.mac_type < e1000_82543) {
291 if (!data)
292 return -EINVAL;
293 return 0;
294 }
295
296 if (data)
297 netdev->features |= NETIF_F_HW_CSUM;
298 else
299 netdev->features &= ~NETIF_F_HW_CSUM;
300
301 return 0;
302}
303
304#ifdef NETIF_F_TSO
305static int
306e1000_set_tso(struct net_device *netdev, uint32_t data)
307{
308 struct e1000_adapter *adapter = netdev->priv;
309 if ((adapter->hw.mac_type < e1000_82544) ||
310 (adapter->hw.mac_type == e1000_82547))
311 return data ? -EINVAL : 0;
312
313 if (data)
314 netdev->features |= NETIF_F_TSO;
315 else
316 netdev->features &= ~NETIF_F_TSO;
317 return 0;
318}
319#endif /* NETIF_F_TSO */
320
321static uint32_t
322e1000_get_msglevel(struct net_device *netdev)
323{
324 struct e1000_adapter *adapter = netdev->priv;
325 return adapter->msg_enable;
326}
327
328static void
329e1000_set_msglevel(struct net_device *netdev, uint32_t data)
330{
331 struct e1000_adapter *adapter = netdev->priv;
332 adapter->msg_enable = data;
333}
334
335static int
336e1000_get_regs_len(struct net_device *netdev)
337{
338#define E1000_REGS_LEN 32
339 return E1000_REGS_LEN * sizeof(uint32_t);
340}
341
342static void
343e1000_get_regs(struct net_device *netdev,
344 struct ethtool_regs *regs, void *p)
345{
346 struct e1000_adapter *adapter = netdev->priv;
347 struct e1000_hw *hw = &adapter->hw;
348 uint32_t *regs_buff = p;
349 uint16_t phy_data;
350
351 memset(p, 0, E1000_REGS_LEN * sizeof(uint32_t));
352
353 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
354
355 regs_buff[0] = E1000_READ_REG(hw, CTRL);
356 regs_buff[1] = E1000_READ_REG(hw, STATUS);
357
358 regs_buff[2] = E1000_READ_REG(hw, RCTL);
359 regs_buff[3] = E1000_READ_REG(hw, RDLEN);
360 regs_buff[4] = E1000_READ_REG(hw, RDH);
361 regs_buff[5] = E1000_READ_REG(hw, RDT);
362 regs_buff[6] = E1000_READ_REG(hw, RDTR);
363
364 regs_buff[7] = E1000_READ_REG(hw, TCTL);
365 regs_buff[8] = E1000_READ_REG(hw, TDLEN);
366 regs_buff[9] = E1000_READ_REG(hw, TDH);
367 regs_buff[10] = E1000_READ_REG(hw, TDT);
368 regs_buff[11] = E1000_READ_REG(hw, TIDV);
369
370 regs_buff[12] = adapter->hw.phy_type; /* PHY type (IGP=1, M88=0) */
371 if(hw->phy_type == e1000_phy_igp) {
372 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
373 IGP01E1000_PHY_AGC_A);
374 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
375 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
376 regs_buff[13] = (uint32_t)phy_data; /* cable length */
377 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
378 IGP01E1000_PHY_AGC_B);
379 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
380 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
381 regs_buff[14] = (uint32_t)phy_data; /* cable length */
382 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
383 IGP01E1000_PHY_AGC_C);
384 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
385 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
386 regs_buff[15] = (uint32_t)phy_data; /* cable length */
387 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
388 IGP01E1000_PHY_AGC_D);
389 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
390 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
391 regs_buff[16] = (uint32_t)phy_data; /* cable length */
392 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
393 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
394 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
395 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
396 regs_buff[18] = (uint32_t)phy_data; /* cable polarity */
397 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
398 IGP01E1000_PHY_PCS_INIT_REG);
399 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
400 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
401 regs_buff[19] = (uint32_t)phy_data; /* cable polarity */
402 regs_buff[20] = 0; /* polarity correction enabled (always) */
403 regs_buff[22] = 0; /* phy receive errors (unavailable) */
404 regs_buff[23] = regs_buff[18]; /* mdix mode */
405 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
406 } else {
407 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
408 regs_buff[13] = (uint32_t)phy_data; /* cable length */
409 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
410 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
411 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
412 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
413 regs_buff[17] = (uint32_t)phy_data; /* extended 10bt distance */
414 regs_buff[18] = regs_buff[13]; /* cable polarity */
415 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
416 regs_buff[20] = regs_buff[17]; /* polarity correction */
417 /* phy receive errors */
418 regs_buff[22] = adapter->phy_stats.receive_errors;
419 regs_buff[23] = regs_buff[13]; /* mdix mode */
420 }
421 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
422 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
423 regs_buff[24] = (uint32_t)phy_data; /* phy local receiver status */
424 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
425 if(hw->mac_type >= e1000_82540 &&
426 hw->media_type == e1000_media_type_copper) {
427 regs_buff[26] = E1000_READ_REG(hw, MANC);
428 }
429}
430
431static int
432e1000_get_eeprom_len(struct net_device *netdev)
433{
434 struct e1000_adapter *adapter = netdev->priv;
435 return adapter->hw.eeprom.word_size * 2;
436}
437
438static int
439e1000_get_eeprom(struct net_device *netdev,
440 struct ethtool_eeprom *eeprom, uint8_t *bytes)
441{
442 struct e1000_adapter *adapter = netdev->priv;
443 struct e1000_hw *hw = &adapter->hw;
444 uint16_t *eeprom_buff;
445 int first_word, last_word;
446 int ret_val = 0;
447 uint16_t i;
448
449 if(eeprom->len == 0)
450 return -EINVAL;
451
452 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
453
454 first_word = eeprom->offset >> 1;
455 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
456
457 eeprom_buff = kmalloc(sizeof(uint16_t) *
458 (last_word - first_word + 1), GFP_KERNEL);
459 if(!eeprom_buff)
460 return -ENOMEM;
461
462 if(hw->eeprom.type == e1000_eeprom_spi)
463 ret_val = e1000_read_eeprom(hw, first_word,
464 last_word - first_word + 1,
465 eeprom_buff);
466 else {
467 for (i = 0; i < last_word - first_word + 1; i++)
468 if((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
469 &eeprom_buff[i])))
470 break;
471 }
472
473 /* Device's eeprom is always little-endian, word addressable */
474 for (i = 0; i < last_word - first_word + 1; i++)
475 le16_to_cpus(&eeprom_buff[i]);
476
477 memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
478 eeprom->len);
479 kfree(eeprom_buff);
480
481 return ret_val;
482}
483
484static int
485e1000_set_eeprom(struct net_device *netdev,
486 struct ethtool_eeprom *eeprom, uint8_t *bytes)
487{
488 struct e1000_adapter *adapter = netdev->priv;
489 struct e1000_hw *hw = &adapter->hw;
490 uint16_t *eeprom_buff;
491 void *ptr;
492 int max_len, first_word, last_word, ret_val = 0;
493 uint16_t i;
494
495 if(eeprom->len == 0)
496 return -EOPNOTSUPP;
497
498 if(eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
499 return -EFAULT;
500
501 max_len = hw->eeprom.word_size * 2;
502
503 first_word = eeprom->offset >> 1;
504 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
505 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
506 if(!eeprom_buff)
507 return -ENOMEM;
508
509 ptr = (void *)eeprom_buff;
510
511 if(eeprom->offset & 1) {
512 /* need read/modify/write of first changed EEPROM word */
513 /* only the second byte of the word is being modified */
514 ret_val = e1000_read_eeprom(hw, first_word, 1,
515 &eeprom_buff[0]);
516 ptr++;
517 }
518 if(((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
519 /* need read/modify/write of last changed EEPROM word */
520 /* only the first byte of the word is being modified */
521 ret_val = e1000_read_eeprom(hw, last_word, 1,
522 &eeprom_buff[last_word - first_word]);
523 }
524
525 /* Device's eeprom is always little-endian, word addressable */
526 for (i = 0; i < last_word - first_word + 1; i++)
527 le16_to_cpus(&eeprom_buff[i]);
528
529 memcpy(ptr, bytes, eeprom->len);
530
531 for (i = 0; i < last_word - first_word + 1; i++)
532 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
533
534 ret_val = e1000_write_eeprom(hw, first_word,
535 last_word - first_word + 1, eeprom_buff);
536
537 /* Update the checksum over the first part of the EEPROM if needed */
538 if((ret_val == 0) && first_word <= EEPROM_CHECKSUM_REG)
539 e1000_update_eeprom_checksum(hw);
540
541 kfree(eeprom_buff);
542 return ret_val;
543}
544
545static void
546e1000_get_drvinfo(struct net_device *netdev,
547 struct ethtool_drvinfo *drvinfo)
548{
549 struct e1000_adapter *adapter = netdev->priv;
550
551 strncpy(drvinfo->driver, e1000_driver_name, 32);
552 strncpy(drvinfo->version, e1000_driver_version, 32);
553 strncpy(drvinfo->fw_version, "N/A", 32);
554 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
555 drvinfo->n_stats = E1000_STATS_LEN;
556 drvinfo->testinfo_len = E1000_TEST_LEN;
557 drvinfo->regdump_len = e1000_get_regs_len(netdev);
558 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
559}
560
561static void
562e1000_get_ringparam(struct net_device *netdev,
563 struct ethtool_ringparam *ring)
564{
565 struct e1000_adapter *adapter = netdev->priv;
566 e1000_mac_type mac_type = adapter->hw.mac_type;
567 struct e1000_desc_ring *txdr = &adapter->tx_ring;
568 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
569
570 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
571 E1000_MAX_82544_RXD;
572 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
573 E1000_MAX_82544_TXD;
574 ring->rx_mini_max_pending = 0;
575 ring->rx_jumbo_max_pending = 0;
576 ring->rx_pending = rxdr->count;
577 ring->tx_pending = txdr->count;
578 ring->rx_mini_pending = 0;
579 ring->rx_jumbo_pending = 0;
580}
581
582static int
583e1000_set_ringparam(struct net_device *netdev,
584 struct ethtool_ringparam *ring)
585{
586 struct e1000_adapter *adapter = netdev->priv;
587 e1000_mac_type mac_type = adapter->hw.mac_type;
588 struct e1000_desc_ring *txdr = &adapter->tx_ring;
589 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
590 struct e1000_desc_ring tx_old, tx_new, rx_old, rx_new;
591 int err;
592
593 tx_old = adapter->tx_ring;
594 rx_old = adapter->rx_ring;
595
596 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
597 return -EINVAL;
598
599 if(netif_running(adapter->netdev))
600 e1000_down(adapter);
601
602 rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
603 rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
604 E1000_MAX_RXD : E1000_MAX_82544_RXD));
605 E1000_ROUNDUP(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
606
607 txdr->count = max(ring->tx_pending,(uint32_t)E1000_MIN_TXD);
608 txdr->count = min(txdr->count,(uint32_t)(mac_type < e1000_82544 ?
609 E1000_MAX_TXD : E1000_MAX_82544_TXD));
610 E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
611
612 if(netif_running(adapter->netdev)) {
613 /* Try to get new resources before deleting old */
614 if((err = e1000_setup_rx_resources(adapter)))
615 goto err_setup_rx;
616 if((err = e1000_setup_tx_resources(adapter)))
617 goto err_setup_tx;
618
619 /* save the new, restore the old in order to free it,
620 * then restore the new back again */
621
622 rx_new = adapter->rx_ring;
623 tx_new = adapter->tx_ring;
624 adapter->rx_ring = rx_old;
625 adapter->tx_ring = tx_old;
626 e1000_free_rx_resources(adapter);
627 e1000_free_tx_resources(adapter);
628 adapter->rx_ring = rx_new;
629 adapter->tx_ring = tx_new;
630 if((err = e1000_up(adapter)))
631 return err;
632 }
633
634 return 0;
635err_setup_tx:
636 e1000_free_rx_resources(adapter);
637err_setup_rx:
638 adapter->rx_ring = rx_old;
639 adapter->tx_ring = tx_old;
640 e1000_up(adapter);
641 return err;
642}
643
644#define REG_PATTERN_TEST(R, M, W) \
645{ \
646 uint32_t pat, value; \
647 uint32_t test[] = \
648 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; \
649 for(pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) { \
650 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \
651 value = E1000_READ_REG(&adapter->hw, R); \
652 if(value != (test[pat] & W & M)) { \
653 *data = (adapter->hw.mac_type < e1000_82543) ? \
654 E1000_82542_##R : E1000_##R; \
655 return 1; \
656 } \
657 } \
658}
659
660#define REG_SET_AND_CHECK(R, M, W) \
661{ \
662 uint32_t value; \
663 E1000_WRITE_REG(&adapter->hw, R, W & M); \
664 value = E1000_READ_REG(&adapter->hw, R); \
665 if ((W & M) != (value & M)) { \
666 *data = (adapter->hw.mac_type < e1000_82543) ? \
667 E1000_82542_##R : E1000_##R; \
668 return 1; \
669 } \
670}
671
672static int
673e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
674{
675 uint32_t value;
676 uint32_t i;
677
678 /* The status register is Read Only, so a write should fail.
679 * Some bits that get toggled are ignored.
680 */
681 value = (E1000_READ_REG(&adapter->hw, STATUS) & (0xFFFFF833));
682 E1000_WRITE_REG(&adapter->hw, STATUS, (0xFFFFFFFF));
683 if(value != (E1000_READ_REG(&adapter->hw, STATUS) & (0xFFFFF833))) {
684 *data = 1;
685 return 1;
686 }
687
688 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
689 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
690 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
691 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
692 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
693 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
694 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
695 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
696 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
697 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
698 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
699 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
700 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
701 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
702
703 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
704 REG_SET_AND_CHECK(RCTL, 0x06DFB3FE, 0x003FFFFB);
705 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
706
707 if(adapter->hw.mac_type >= e1000_82543) {
708
709 REG_SET_AND_CHECK(RCTL, 0x06DFB3FE, 0xFFFFFFFF);
710 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
711 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
712 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
713 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
714
715 for(i = 0; i < E1000_RAR_ENTRIES; i++) {
716 REG_PATTERN_TEST(RA + ((i << 1) << 2), 0xFFFFFFFF,
717 0xFFFFFFFF);
718 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
719 0xFFFFFFFF);
720 }
721
722 } else {
723
724 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
725 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
726 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
727 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
728
729 }
730
731 for(i = 0; i < E1000_MC_TBL_SIZE; i++)
732 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
733
734 *data = 0;
735 return 0;
736}
737
738static int
739e1000_eeprom_test(struct e1000_adapter *adapter, uint64_t *data)
740{
741 uint16_t temp;
742 uint16_t checksum = 0;
743 uint16_t i;
744
745 *data = 0;
746 /* Read and add up the contents of the EEPROM */
747 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
748 if((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) {
749 *data = 1;
750 break;
751 }
752 checksum += temp;
753 }
754
755 /* If Checksum is not Correct return error else test passed */
756 if((checksum != (uint16_t) EEPROM_SUM) && !(*data))
757 *data = 2;
758
759 return *data;
760}
761
762static irqreturn_t
763e1000_test_intr(int irq,
764 void *data,
765 struct pt_regs *regs)
766{
767 struct net_device *netdev = (struct net_device *) data;
768 struct e1000_adapter *adapter = netdev->priv;
769
770 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);
771
772 return IRQ_HANDLED;
773}
774
775static int
776e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
777{
778 struct net_device *netdev = adapter->netdev;
779 uint32_t mask, i=0, shared_int = TRUE;
780 uint32_t irq = adapter->pdev->irq;
781
782 *data = 0;
783
784 /* Hook up test interrupt handler just for this test */
785 if(!request_irq(irq, &e1000_test_intr, 0, netdev->name, netdev)) {
786 shared_int = FALSE;
787 } else if(request_irq(irq, &e1000_test_intr, SA_SHIRQ,
788 netdev->name, netdev)){
789 *data = 1;
790 return -1;
791 }
792
793 /* Disable all the interrupts */
794 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
795 msec_delay(10);
796
797 /* Test each interrupt */
798 for(; i < 10; i++) {
799
800 /* Interrupt to test */
801 mask = 1 << i;
802
803 if(!shared_int) {
804 /* Disable the interrupt to be reported in
805 * the cause register and then force the same
806 * interrupt and see if one gets posted. If
807 * an interrupt was posted to the bus, the
808 * test failed.
809 */
810 adapter->test_icr = 0;
811 E1000_WRITE_REG(&adapter->hw, IMC, mask);
812 E1000_WRITE_REG(&adapter->hw, ICS, mask);
813 msec_delay(10);
814
815 if(adapter->test_icr & mask) {
816 *data = 3;
817 break;
818 }
819 }
820
821 /* Enable the interrupt to be reported in
822 * the cause register and then force the same
823 * interrupt and see if one gets posted. If
824 * an interrupt was not posted to the bus, the
825 * test failed.
826 */
827 adapter->test_icr = 0;
828 E1000_WRITE_REG(&adapter->hw, IMS, mask);
829 E1000_WRITE_REG(&adapter->hw, ICS, mask);
830 msec_delay(10);
831
832 if(!(adapter->test_icr & mask)) {
833 *data = 4;
834 break;
835 }
836
837 if(!shared_int) {
838 /* Disable the other interrupts to be reported in
839 * the cause register and then force the other
840 * interrupts and see if any get posted. If
841 * an interrupt was posted to the bus, the
842 * test failed.
843 */
844 adapter->test_icr = 0;
845 E1000_WRITE_REG(&adapter->hw, IMC,
846 (~mask & 0x00007FFF));
847 E1000_WRITE_REG(&adapter->hw, ICS,
848 (~mask & 0x00007FFF));
849 msec_delay(10);
850
851 if(adapter->test_icr) {
852 *data = 5;
853 break;
854 }
855 }
856 }
857
858 /* Disable all the interrupts */
859 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
860 msec_delay(10);
861
862 /* Unhook test interrupt handler */
863 free_irq(irq, netdev);
864
865 return *data;
866}
867
868static void
869e1000_free_desc_rings(struct e1000_adapter *adapter)
870{
871 struct e1000_desc_ring *txdr = &adapter->test_tx_ring;
872 struct e1000_desc_ring *rxdr = &adapter->test_rx_ring;
873 struct pci_dev *pdev = adapter->pdev;
874 int i;
875
876 if(txdr->desc && txdr->buffer_info) {
877 for(i = 0; i < txdr->count; i++) {
878 if(txdr->buffer_info[i].dma)
879 pci_unmap_single(pdev, txdr->buffer_info[i].dma,
880 txdr->buffer_info[i].length,
881 PCI_DMA_TODEVICE);
882 if(txdr->buffer_info[i].skb)
883 dev_kfree_skb(txdr->buffer_info[i].skb);
884 }
885 }
886
887 if(rxdr->desc && rxdr->buffer_info) {
888 for(i = 0; i < rxdr->count; i++) {
889 if(rxdr->buffer_info[i].dma)
890 pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
891 rxdr->buffer_info[i].length,
892 PCI_DMA_FROMDEVICE);
893 if(rxdr->buffer_info[i].skb)
894 dev_kfree_skb(rxdr->buffer_info[i].skb);
895 }
896 }
897
898 if(txdr->desc)
899 pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
900 if(rxdr->desc)
901 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
902
903 if(txdr->buffer_info)
904 kfree(txdr->buffer_info);
905 if(rxdr->buffer_info)
906 kfree(rxdr->buffer_info);
907
908 return;
909}
910
911static int
912e1000_setup_desc_rings(struct e1000_adapter *adapter)
913{
914 struct e1000_desc_ring *txdr = &adapter->test_tx_ring;
915 struct e1000_desc_ring *rxdr = &adapter->test_rx_ring;
916 struct pci_dev *pdev = adapter->pdev;
917 uint32_t rctl;
918 int size, i, ret_val;
919
920 /* Setup Tx descriptor ring and Tx buffers */
921
922 txdr->count = 80;
923
924 size = txdr->count * sizeof(struct e1000_buffer);
925 if(!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
926 ret_val = 1;
927 goto err_nomem;
928 }
929 memset(txdr->buffer_info, 0, size);
930
931 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
932 E1000_ROUNDUP(txdr->size, 4096);
933 if(!(txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma))) {
934 ret_val = 2;
935 goto err_nomem;
936 }
937 memset(txdr->desc, 0, txdr->size);
938 txdr->next_to_use = txdr->next_to_clean = 0;
939
940 E1000_WRITE_REG(&adapter->hw, TDBAL,
941 ((uint64_t) txdr->dma & 0x00000000FFFFFFFF));
942 E1000_WRITE_REG(&adapter->hw, TDBAH, ((uint64_t) txdr->dma >> 32));
943 E1000_WRITE_REG(&adapter->hw, TDLEN,
944 txdr->count * sizeof(struct e1000_tx_desc));
945 E1000_WRITE_REG(&adapter->hw, TDH, 0);
946 E1000_WRITE_REG(&adapter->hw, TDT, 0);
947 E1000_WRITE_REG(&adapter->hw, TCTL,
948 E1000_TCTL_PSP | E1000_TCTL_EN |
949 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
950 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
951
952 for(i = 0; i < txdr->count; i++) {
953 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
954 struct sk_buff *skb;
955 unsigned int size = 1024;
956
957 if(!(skb = alloc_skb(size, GFP_KERNEL))) {
958 ret_val = 3;
959 goto err_nomem;
960 }
961 skb_put(skb, size);
962 txdr->buffer_info[i].skb = skb;
963 txdr->buffer_info[i].length = skb->len;
964 txdr->buffer_info[i].dma =
965 pci_map_single(pdev, skb->data, skb->len,
966 PCI_DMA_TODEVICE);
967 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
968 tx_desc->lower.data = cpu_to_le32(skb->len);
969 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
970 E1000_TXD_CMD_IFCS |
971 E1000_TXD_CMD_RPS);
972 tx_desc->upper.data = 0;
973 }
974
975 /* Setup Rx descriptor ring and Rx buffers */
976
977 rxdr->count = 80;
978
979 size = rxdr->count * sizeof(struct e1000_buffer);
980 if(!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
981 ret_val = 4;
982 goto err_nomem;
983 }
984 memset(rxdr->buffer_info, 0, size);
985
986 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
987 if(!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
988 ret_val = 5;
989 goto err_nomem;
990 }
991 memset(rxdr->desc, 0, rxdr->size);
992 rxdr->next_to_use = rxdr->next_to_clean = 0;
993
994 rctl = E1000_READ_REG(&adapter->hw, RCTL);
995 E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
996 E1000_WRITE_REG(&adapter->hw, RDBAL,
997 ((uint64_t) rxdr->dma & 0xFFFFFFFF));
998 E1000_WRITE_REG(&adapter->hw, RDBAH, ((uint64_t) rxdr->dma >> 32));
999 E1000_WRITE_REG(&adapter->hw, RDLEN, rxdr->size);
1000 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1001 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1002 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1003 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1004 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1005 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1006
1007 for(i = 0; i < rxdr->count; i++) {
1008 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1009 struct sk_buff *skb;
1010
1011 if(!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
1012 GFP_KERNEL))) {
1013 ret_val = 6;
1014 goto err_nomem;
1015 }
1016 skb_reserve(skb, NET_IP_ALIGN);
1017 rxdr->buffer_info[i].skb = skb;
1018 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1019 rxdr->buffer_info[i].dma =
1020 pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
1021 PCI_DMA_FROMDEVICE);
1022 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1023 memset(skb->data, 0x00, skb->len);
1024 }
1025
1026 return 0;
1027
1028err_nomem:
1029 e1000_free_desc_rings(adapter);
1030 return ret_val;
1031}
1032
1033static void
1034e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1035{
1036 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1037 e1000_write_phy_reg(&adapter->hw, 29, 0x001F);
1038 e1000_write_phy_reg(&adapter->hw, 30, 0x8FFC);
1039 e1000_write_phy_reg(&adapter->hw, 29, 0x001A);
1040 e1000_write_phy_reg(&adapter->hw, 30, 0x8FF0);
1041}
1042
1043static void
1044e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
1045{
1046 uint16_t phy_reg;
1047
1048 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1049 * Extended PHY Specific Control Register to 25MHz clock. This
1050 * value defaults back to a 2.5MHz clock when the PHY is reset.
1051 */
1052 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1053 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
1054 e1000_write_phy_reg(&adapter->hw,
1055 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1056
1057 /* In addition, because of the s/w reset above, we need to enable
1058 * CRS on TX. This must be set for both full and half duplex
1059 * operation.
1060 */
1061 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1062 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1063 e1000_write_phy_reg(&adapter->hw,
1064 M88E1000_PHY_SPEC_CTRL, phy_reg);
1065}
1066
1067static int
1068e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
1069{
1070 uint32_t ctrl_reg;
1071 uint16_t phy_reg;
1072
1073 /* Setup the Device Control Register for PHY loopback test. */
1074
1075 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1076 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1077 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1078 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1079 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1080 E1000_CTRL_FD); /* Force Duplex to FULL */
1081
1082 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1083
1084 /* Read the PHY Specific Control Register (0x10) */
1085 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1086
1087 /* Clear Auto-Crossover bits in PHY Specific Control Register
1088 * (bits 6:5).
1089 */
1090 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
1091 e1000_write_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
1092
1093 /* Perform software reset on the PHY */
1094 e1000_phy_reset(&adapter->hw);
1095
1096 /* Have to setup TX_CLK and TX_CRS after software reset */
1097 e1000_phy_reset_clk_and_crs(adapter);
1098
1099 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8100);
1100
1101 /* Wait for reset to complete. */
1102 udelay(500);
1103
1104 /* Have to setup TX_CLK and TX_CRS after software reset */
1105 e1000_phy_reset_clk_and_crs(adapter);
1106
1107 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1108 e1000_phy_disable_receiver(adapter);
1109
1110 /* Set the loopback bit in the PHY control register. */
1111 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1112 phy_reg |= MII_CR_LOOPBACK;
1113 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1114
1115 /* Setup TX_CLK and TX_CRS one more time. */
1116 e1000_phy_reset_clk_and_crs(adapter);
1117
1118 /* Check Phy Configuration */
1119 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1120 if(phy_reg != 0x4100)
1121 return 9;
1122
1123 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1124 if(phy_reg != 0x0070)
1125 return 10;
1126
1127 e1000_read_phy_reg(&adapter->hw, 29, &phy_reg);
1128 if(phy_reg != 0x001A)
1129 return 11;
1130
1131 return 0;
1132}
1133
1134static int
1135e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1136{
1137 uint32_t ctrl_reg = 0;
1138 uint32_t stat_reg = 0;
1139
1140 adapter->hw.autoneg = FALSE;
1141
1142 if(adapter->hw.phy_type == e1000_phy_m88) {
1143 /* Auto-MDI/MDIX Off */
1144 e1000_write_phy_reg(&adapter->hw,
1145 M88E1000_PHY_SPEC_CTRL, 0x0808);
1146 /* reset to update Auto-MDI/MDIX */
1147 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x9140);
1148 /* autoneg off */
1149 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8140);
1150 }
1151 /* force 1000, set loopback */
1152 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140);
1153
1154 /* Now set up the MAC to the same speed/duplex as the PHY. */
1155 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1156 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1157 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1158 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1159 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1160 E1000_CTRL_FD); /* Force Duplex to FULL */
1161
1162 if(adapter->hw.media_type == e1000_media_type_copper &&
1163 adapter->hw.phy_type == e1000_phy_m88) {
1164 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1165 } else {
1166 /* Set the ILOS bit on the fiber Nic is half
1167 * duplex link is detected. */
1168 stat_reg = E1000_READ_REG(&adapter->hw, STATUS);
1169 if((stat_reg & E1000_STATUS_FD) == 0)
1170 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1171 }
1172
1173 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1174
1175 /* Disable the receiver on the PHY so when a cable is plugged in, the
1176 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1177 */
1178 if(adapter->hw.phy_type == e1000_phy_m88)
1179 e1000_phy_disable_receiver(adapter);
1180
1181 udelay(500);
1182
1183 return 0;
1184}
1185
1186static int
1187e1000_set_phy_loopback(struct e1000_adapter *adapter)
1188{
1189 uint16_t phy_reg = 0;
1190 uint16_t count = 0;
1191
1192 switch (adapter->hw.mac_type) {
1193 case e1000_82543:
1194 if(adapter->hw.media_type == e1000_media_type_copper) {
1195 /* Attempt to setup Loopback mode on Non-integrated PHY.
1196 * Some PHY registers get corrupted at random, so
1197 * attempt this 10 times.
1198 */
1199 while(e1000_nonintegrated_phy_loopback(adapter) &&
1200 count++ < 10);
1201 if(count < 11)
1202 return 0;
1203 }
1204 break;
1205
1206 case e1000_82544:
1207 case e1000_82540:
1208 case e1000_82545:
1209 case e1000_82545_rev_3:
1210 case e1000_82546:
1211 case e1000_82546_rev_3:
1212 case e1000_82541:
1213 case e1000_82541_rev_2:
1214 case e1000_82547:
1215 case e1000_82547_rev_2:
1216 return e1000_integrated_phy_loopback(adapter);
1217 break;
1218
1219 default:
1220 /* Default PHY loopback work is to read the MII
1221 * control register and assert bit 14 (loopback mode).
1222 */
1223 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1224 phy_reg |= MII_CR_LOOPBACK;
1225 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1226 return 0;
1227 break;
1228 }
1229
1230 return 8;
1231}
1232
1233static int
1234e1000_setup_loopback_test(struct e1000_adapter *adapter)
1235{
1236 uint32_t rctl;
1237
1238 if(adapter->hw.media_type == e1000_media_type_fiber ||
1239 adapter->hw.media_type == e1000_media_type_internal_serdes) {
1240 if(adapter->hw.mac_type == e1000_82545 ||
1241 adapter->hw.mac_type == e1000_82546 ||
1242 adapter->hw.mac_type == e1000_82545_rev_3 ||
1243 adapter->hw.mac_type == e1000_82546_rev_3)
1244 return e1000_set_phy_loopback(adapter);
1245 else {
1246 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1247 rctl |= E1000_RCTL_LBM_TCVR;
1248 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1249 return 0;
1250 }
1251 } else if(adapter->hw.media_type == e1000_media_type_copper)
1252 return e1000_set_phy_loopback(adapter);
1253
1254 return 7;
1255}
1256
1257static void
1258e1000_loopback_cleanup(struct e1000_adapter *adapter)
1259{
1260 uint32_t rctl;
1261 uint16_t phy_reg;
1262
1263 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1264 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1265 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1266
1267 if(adapter->hw.media_type == e1000_media_type_copper ||
1268 ((adapter->hw.media_type == e1000_media_type_fiber ||
1269 adapter->hw.media_type == e1000_media_type_internal_serdes) &&
1270 (adapter->hw.mac_type == e1000_82545 ||
1271 adapter->hw.mac_type == e1000_82546 ||
1272 adapter->hw.mac_type == e1000_82545_rev_3 ||
1273 adapter->hw.mac_type == e1000_82546_rev_3))) {
1274 adapter->hw.autoneg = TRUE;
1275 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1276 if(phy_reg & MII_CR_LOOPBACK) {
1277 phy_reg &= ~MII_CR_LOOPBACK;
1278 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1279 e1000_phy_reset(&adapter->hw);
1280 }
1281 }
1282}
1283
1284static void
1285e1000_create_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1286{
1287 memset(skb->data, 0xFF, frame_size);
1288 frame_size = (frame_size % 2) ? (frame_size - 1) : frame_size;
1289 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1290 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1291 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1292}
1293
1294static int
1295e1000_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1296{
1297 frame_size = (frame_size % 2) ? (frame_size - 1) : frame_size;
1298 if(*(skb->data + 3) == 0xFF) {
1299 if((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1300 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1301 return 0;
1302 }
1303 }
1304 return 13;
1305}
1306
1307static int
1308e1000_run_loopback_test(struct e1000_adapter *adapter)
1309{
1310 struct e1000_desc_ring *txdr = &adapter->test_tx_ring;
1311 struct e1000_desc_ring *rxdr = &adapter->test_rx_ring;
1312 struct pci_dev *pdev = adapter->pdev;
1313 int i, ret_val;
1314
1315 E1000_WRITE_REG(&adapter->hw, RDT, rxdr->count - 1);
1316
1317 for(i = 0; i < 64; i++) {
1318 e1000_create_lbtest_frame(txdr->buffer_info[i].skb, 1024);
1319 pci_dma_sync_single_for_device(pdev, txdr->buffer_info[i].dma,
1320 txdr->buffer_info[i].length,
1321 PCI_DMA_TODEVICE);
1322 }
1323 E1000_WRITE_REG(&adapter->hw, TDT, i);
1324
1325 msec_delay(200);
1326
1327 i = 0;
1328 do {
1329 pci_dma_sync_single_for_cpu(pdev, rxdr->buffer_info[i].dma,
1330 rxdr->buffer_info[i].length,
1331 PCI_DMA_FROMDEVICE);
1332
1333 ret_val = e1000_check_lbtest_frame(rxdr->buffer_info[i].skb,
1334 1024);
1335 i++;
1336 } while (ret_val != 0 && i < 64);
1337
1338 return ret_val;
1339}
1340
1341static int
1342e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data)
1343{
1344 if((*data = e1000_setup_desc_rings(adapter))) goto err_loopback;
1345 if((*data = e1000_setup_loopback_test(adapter))) goto err_loopback;
1346 *data = e1000_run_loopback_test(adapter);
1347 e1000_loopback_cleanup(adapter);
1348 e1000_free_desc_rings(adapter);
1349err_loopback:
1350 return *data;
1351}
1352
1353static int
1354e1000_link_test(struct e1000_adapter *adapter, uint64_t *data)
1355{
1356 *data = 0;
1357
1358 if (adapter->hw.media_type == e1000_media_type_internal_serdes) {
1359 int i = 0;
1360 adapter->hw.serdes_link_down = TRUE;
1361
1362 /* on some blade server designs link establishment */
1363 /* could take as long as 2-3 minutes. */
1364 do {
1365 e1000_check_for_link(&adapter->hw);
1366 if (adapter->hw.serdes_link_down == FALSE)
1367 return *data;
1368 msec_delay(20);
1369 } while (i++ < 3750);
1370
1371 *data = 1;
1372 } else {
1373 e1000_check_for_link(&adapter->hw);
1374
1375 if(!(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) {
1376 *data = 1;
1377 }
1378 }
1379 return *data;
1380}
1381
1382static int
1383e1000_diag_test_count(struct net_device *netdev)
1384{
1385 return E1000_TEST_LEN;
1386}
1387
1388static void
1389e1000_diag_test(struct net_device *netdev,
1390 struct ethtool_test *eth_test, uint64_t *data)
1391{
1392 struct e1000_adapter *adapter = netdev->priv;
1393 boolean_t if_running = netif_running(netdev);
1394
1395 if(eth_test->flags == ETH_TEST_FL_OFFLINE) {
1396 /* Offline tests */
1397
1398 /* save speed, duplex, autoneg settings */
1399 uint16_t autoneg_advertised = adapter->hw.autoneg_advertised;
1400 uint8_t forced_speed_duplex = adapter->hw.forced_speed_duplex;
1401 uint8_t autoneg = adapter->hw.autoneg;
1402
1403 /* Link test performed before hardware reset so autoneg doesn't
1404 * interfere with test result */
1405 if(e1000_link_test(adapter, &data[4]))
1406 eth_test->flags |= ETH_TEST_FL_FAILED;
1407
1408 if(if_running)
1409 e1000_down(adapter);
1410 else
1411 e1000_reset(adapter);
1412
1413 if(e1000_reg_test(adapter, &data[0]))
1414 eth_test->flags |= ETH_TEST_FL_FAILED;
1415
1416 e1000_reset(adapter);
1417 if(e1000_eeprom_test(adapter, &data[1]))
1418 eth_test->flags |= ETH_TEST_FL_FAILED;
1419
1420 e1000_reset(adapter);
1421 if(e1000_intr_test(adapter, &data[2]))
1422 eth_test->flags |= ETH_TEST_FL_FAILED;
1423
1424 e1000_reset(adapter);
1425 if(e1000_loopback_test(adapter, &data[3]))
1426 eth_test->flags |= ETH_TEST_FL_FAILED;
1427
1428 /* restore speed, duplex, autoneg settings */
1429 adapter->hw.autoneg_advertised = autoneg_advertised;
1430 adapter->hw.forced_speed_duplex = forced_speed_duplex;
1431 adapter->hw.autoneg = autoneg;
1432
1433 e1000_reset(adapter);
1434 if(if_running)
1435 e1000_up(adapter);
1436 } else {
1437 /* Online tests */
1438 if(e1000_link_test(adapter, &data[4]))
1439 eth_test->flags |= ETH_TEST_FL_FAILED;
1440
1441 /* Offline tests aren't run; pass by default */
1442 data[0] = 0;
1443 data[1] = 0;
1444 data[2] = 0;
1445 data[3] = 0;
1446 }
1447}
1448
1449static void
1450e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1451{
1452 struct e1000_adapter *adapter = netdev->priv;
1453 struct e1000_hw *hw = &adapter->hw;
1454
1455 switch(adapter->hw.device_id) {
1456 case E1000_DEV_ID_82542:
1457 case E1000_DEV_ID_82543GC_FIBER:
1458 case E1000_DEV_ID_82543GC_COPPER:
1459 case E1000_DEV_ID_82544EI_FIBER:
1460 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1461 case E1000_DEV_ID_82545EM_FIBER:
1462 case E1000_DEV_ID_82545EM_COPPER:
1463 wol->supported = 0;
1464 wol->wolopts = 0;
1465 return;
1466
1467 case E1000_DEV_ID_82546EB_FIBER:
1468 case E1000_DEV_ID_82546GB_FIBER:
1469 /* Wake events only supported on port A for dual fiber */
1470 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
1471 wol->supported = 0;
1472 wol->wolopts = 0;
1473 return;
1474 }
1475 /* Fall Through */
1476
1477 default:
1478 wol->supported = WAKE_UCAST | WAKE_MCAST |
1479 WAKE_BCAST | WAKE_MAGIC;
1480
1481 wol->wolopts = 0;
1482 if(adapter->wol & E1000_WUFC_EX)
1483 wol->wolopts |= WAKE_UCAST;
1484 if(adapter->wol & E1000_WUFC_MC)
1485 wol->wolopts |= WAKE_MCAST;
1486 if(adapter->wol & E1000_WUFC_BC)
1487 wol->wolopts |= WAKE_BCAST;
1488 if(adapter->wol & E1000_WUFC_MAG)
1489 wol->wolopts |= WAKE_MAGIC;
1490 return;
1491 }
1492}
1493
1494static int
1495e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1496{
1497 struct e1000_adapter *adapter = netdev->priv;
1498 struct e1000_hw *hw = &adapter->hw;
1499
1500 switch(adapter->hw.device_id) {
1501 case E1000_DEV_ID_82542:
1502 case E1000_DEV_ID_82543GC_FIBER:
1503 case E1000_DEV_ID_82543GC_COPPER:
1504 case E1000_DEV_ID_82544EI_FIBER:
1505 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1506 case E1000_DEV_ID_82545EM_FIBER:
1507 case E1000_DEV_ID_82545EM_COPPER:
1508 return wol->wolopts ? -EOPNOTSUPP : 0;
1509
1510 case E1000_DEV_ID_82546EB_FIBER:
1511 case E1000_DEV_ID_82546GB_FIBER:
1512 /* Wake events only supported on port A for dual fiber */
1513 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
1514 return wol->wolopts ? -EOPNOTSUPP : 0;
1515 /* Fall Through */
1516
1517 default:
1518 if(wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1519 return -EOPNOTSUPP;
1520
1521 adapter->wol = 0;
1522
1523 if(wol->wolopts & WAKE_UCAST)
1524 adapter->wol |= E1000_WUFC_EX;
1525 if(wol->wolopts & WAKE_MCAST)
1526 adapter->wol |= E1000_WUFC_MC;
1527 if(wol->wolopts & WAKE_BCAST)
1528 adapter->wol |= E1000_WUFC_BC;
1529 if(wol->wolopts & WAKE_MAGIC)
1530 adapter->wol |= E1000_WUFC_MAG;
1531 }
1532
1533 return 0;
1534}
1535
1536/* toggle LED 4 times per second = 2 "blinks" per second */
1537#define E1000_ID_INTERVAL (HZ/4)
1538
1539/* bit defines for adapter->led_status */
1540#define E1000_LED_ON 0
1541
1542static void
1543e1000_led_blink_callback(unsigned long data)
1544{
1545 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1546
1547 if(test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1548 e1000_led_off(&adapter->hw);
1549 else
1550 e1000_led_on(&adapter->hw);
1551
1552 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1553}
1554
1555static int
1556e1000_phys_id(struct net_device *netdev, uint32_t data)
1557{
1558 struct e1000_adapter *adapter = netdev->priv;
1559
1560 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
1561 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
1562
1563 if(!adapter->blink_timer.function) {
1564 init_timer(&adapter->blink_timer);
1565 adapter->blink_timer.function = e1000_led_blink_callback;
1566 adapter->blink_timer.data = (unsigned long) adapter;
1567 }
1568
1569 e1000_setup_led(&adapter->hw);
1570 mod_timer(&adapter->blink_timer, jiffies);
1571
1572 msleep_interruptible(data * 1000);
1573 del_timer_sync(&adapter->blink_timer);
1574 e1000_led_off(&adapter->hw);
1575 clear_bit(E1000_LED_ON, &adapter->led_status);
1576 e1000_cleanup_led(&adapter->hw);
1577
1578 return 0;
1579}
1580
1581static int
1582e1000_nway_reset(struct net_device *netdev)
1583{
1584 struct e1000_adapter *adapter = netdev->priv;
1585 if(netif_running(netdev)) {
1586 e1000_down(adapter);
1587 e1000_up(adapter);
1588 }
1589 return 0;
1590}
1591
1592static int
1593e1000_get_stats_count(struct net_device *netdev)
1594{
1595 return E1000_STATS_LEN;
1596}
1597
1598static void
1599e1000_get_ethtool_stats(struct net_device *netdev,
1600 struct ethtool_stats *stats, uint64_t *data)
1601{
1602 struct e1000_adapter *adapter = netdev->priv;
1603 int i;
1604
1605 e1000_update_stats(adapter);
1606 for(i = 0; i < E1000_STATS_LEN; i++) {
1607 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1608 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1609 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
1610 }
1611}
1612
1613static void
1614e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
1615{
1616 int i;
1617
1618 switch(stringset) {
1619 case ETH_SS_TEST:
1620 memcpy(data, *e1000_gstrings_test,
1621 E1000_TEST_LEN*ETH_GSTRING_LEN);
1622 break;
1623 case ETH_SS_STATS:
1624 for (i=0; i < E1000_STATS_LEN; i++) {
1625 memcpy(data + i * ETH_GSTRING_LEN,
1626 e1000_gstrings_stats[i].stat_string,
1627 ETH_GSTRING_LEN);
1628 }
1629 break;
1630 }
1631}
1632
1633struct ethtool_ops e1000_ethtool_ops = {
1634 .get_settings = e1000_get_settings,
1635 .set_settings = e1000_set_settings,
1636 .get_drvinfo = e1000_get_drvinfo,
1637 .get_regs_len = e1000_get_regs_len,
1638 .get_regs = e1000_get_regs,
1639 .get_wol = e1000_get_wol,
1640 .set_wol = e1000_set_wol,
1641 .get_msglevel = e1000_get_msglevel,
1642 .set_msglevel = e1000_set_msglevel,
1643 .nway_reset = e1000_nway_reset,
1644 .get_link = ethtool_op_get_link,
1645 .get_eeprom_len = e1000_get_eeprom_len,
1646 .get_eeprom = e1000_get_eeprom,
1647 .set_eeprom = e1000_set_eeprom,
1648 .get_ringparam = e1000_get_ringparam,
1649 .set_ringparam = e1000_set_ringparam,
1650 .get_pauseparam = e1000_get_pauseparam,
1651 .set_pauseparam = e1000_set_pauseparam,
1652 .get_rx_csum = e1000_get_rx_csum,
1653 .set_rx_csum = e1000_set_rx_csum,
1654 .get_tx_csum = e1000_get_tx_csum,
1655 .set_tx_csum = e1000_set_tx_csum,
1656 .get_sg = ethtool_op_get_sg,
1657 .set_sg = ethtool_op_set_sg,
1658#ifdef NETIF_F_TSO
1659 .get_tso = ethtool_op_get_tso,
1660 .set_tso = e1000_set_tso,
1661#endif
1662 .self_test_count = e1000_diag_test_count,
1663 .self_test = e1000_diag_test,
1664 .get_strings = e1000_get_strings,
1665 .phys_id = e1000_phys_id,
1666 .get_stats_count = e1000_get_stats_count,
1667 .get_ethtool_stats = e1000_get_ethtool_stats,
1668};
1669
1670void e1000_set_ethtool_ops(struct net_device *netdev)
1671{
1672 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1673}