|
1 /******************************************************************************* |
|
2 |
|
3 Intel PRO/1000 Linux driver |
|
4 Copyright(c) 1999 - 2008 Intel Corporation. |
|
5 |
|
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. |
|
9 |
|
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. |
|
14 |
|
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. |
|
18 |
|
19 The full GNU General Public License is included in this distribution in |
|
20 the file called "COPYING". |
|
21 |
|
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 |
|
26 |
|
27 *******************************************************************************/ |
|
28 |
|
29 /* ethtool support for e1000 */ |
|
30 |
|
31 #include <linux/netdevice.h> |
|
32 #include <linux/ethtool.h> |
|
33 #include <linux/pci.h> |
|
34 #include <linux/delay.h> |
|
35 |
|
36 #include "e1000.h" |
|
37 |
|
38 struct e1000_stats { |
|
39 char stat_string[ETH_GSTRING_LEN]; |
|
40 int sizeof_stat; |
|
41 int stat_offset; |
|
42 }; |
|
43 |
|
44 #define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \ |
|
45 offsetof(struct e1000_adapter, m) |
|
46 static const struct e1000_stats e1000_gstrings_stats[] = { |
|
47 { "rx_packets", E1000_STAT(stats.gprc) }, |
|
48 { "tx_packets", E1000_STAT(stats.gptc) }, |
|
49 { "rx_bytes", E1000_STAT(stats.gorc) }, |
|
50 { "tx_bytes", E1000_STAT(stats.gotc) }, |
|
51 { "rx_broadcast", E1000_STAT(stats.bprc) }, |
|
52 { "tx_broadcast", E1000_STAT(stats.bptc) }, |
|
53 { "rx_multicast", E1000_STAT(stats.mprc) }, |
|
54 { "tx_multicast", E1000_STAT(stats.mptc) }, |
|
55 { "rx_errors", E1000_STAT(net_stats.rx_errors) }, |
|
56 { "tx_errors", E1000_STAT(net_stats.tx_errors) }, |
|
57 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) }, |
|
58 { "multicast", E1000_STAT(stats.mprc) }, |
|
59 { "collisions", E1000_STAT(stats.colc) }, |
|
60 { "rx_length_errors", E1000_STAT(net_stats.rx_length_errors) }, |
|
61 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) }, |
|
62 { "rx_crc_errors", E1000_STAT(stats.crcerrs) }, |
|
63 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) }, |
|
64 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) }, |
|
65 { "rx_missed_errors", E1000_STAT(stats.mpc) }, |
|
66 { "tx_aborted_errors", E1000_STAT(stats.ecol) }, |
|
67 { "tx_carrier_errors", E1000_STAT(stats.tncrs) }, |
|
68 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) }, |
|
69 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) }, |
|
70 { "tx_window_errors", E1000_STAT(stats.latecol) }, |
|
71 { "tx_abort_late_coll", E1000_STAT(stats.latecol) }, |
|
72 { "tx_deferred_ok", E1000_STAT(stats.dc) }, |
|
73 { "tx_single_coll_ok", E1000_STAT(stats.scc) }, |
|
74 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) }, |
|
75 { "tx_timeout_count", E1000_STAT(tx_timeout_count) }, |
|
76 { "tx_restart_queue", E1000_STAT(restart_queue) }, |
|
77 { "rx_long_length_errors", E1000_STAT(stats.roc) }, |
|
78 { "rx_short_length_errors", E1000_STAT(stats.ruc) }, |
|
79 { "rx_align_errors", E1000_STAT(stats.algnerrc) }, |
|
80 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) }, |
|
81 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) }, |
|
82 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) }, |
|
83 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) }, |
|
84 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) }, |
|
85 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) }, |
|
86 { "rx_long_byte_count", E1000_STAT(stats.gorc) }, |
|
87 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) }, |
|
88 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) }, |
|
89 { "rx_header_split", E1000_STAT(rx_hdr_split) }, |
|
90 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) }, |
|
91 { "tx_smbus", E1000_STAT(stats.mgptc) }, |
|
92 { "rx_smbus", E1000_STAT(stats.mgprc) }, |
|
93 { "dropped_smbus", E1000_STAT(stats.mgpdc) }, |
|
94 { "rx_dma_failed", E1000_STAT(rx_dma_failed) }, |
|
95 { "tx_dma_failed", E1000_STAT(tx_dma_failed) }, |
|
96 }; |
|
97 |
|
98 #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats) |
|
99 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN) |
|
100 static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = { |
|
101 "Register test (offline)", "Eeprom test (offline)", |
|
102 "Interrupt test (offline)", "Loopback test (offline)", |
|
103 "Link test (on/offline)" |
|
104 }; |
|
105 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test) |
|
106 |
|
107 static int e1000_get_settings(struct net_device *netdev, |
|
108 struct ethtool_cmd *ecmd) |
|
109 { |
|
110 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
111 struct e1000_hw *hw = &adapter->hw; |
|
112 u32 status; |
|
113 |
|
114 if (hw->phy.media_type == e1000_media_type_copper) { |
|
115 |
|
116 ecmd->supported = (SUPPORTED_10baseT_Half | |
|
117 SUPPORTED_10baseT_Full | |
|
118 SUPPORTED_100baseT_Half | |
|
119 SUPPORTED_100baseT_Full | |
|
120 SUPPORTED_1000baseT_Full | |
|
121 SUPPORTED_Autoneg | |
|
122 SUPPORTED_TP); |
|
123 if (hw->phy.type == e1000_phy_ife) |
|
124 ecmd->supported &= ~SUPPORTED_1000baseT_Full; |
|
125 ecmd->advertising = ADVERTISED_TP; |
|
126 |
|
127 if (hw->mac.autoneg == 1) { |
|
128 ecmd->advertising |= ADVERTISED_Autoneg; |
|
129 /* the e1000 autoneg seems to match ethtool nicely */ |
|
130 ecmd->advertising |= hw->phy.autoneg_advertised; |
|
131 } |
|
132 |
|
133 ecmd->port = PORT_TP; |
|
134 ecmd->phy_address = hw->phy.addr; |
|
135 ecmd->transceiver = XCVR_INTERNAL; |
|
136 |
|
137 } else { |
|
138 ecmd->supported = (SUPPORTED_1000baseT_Full | |
|
139 SUPPORTED_FIBRE | |
|
140 SUPPORTED_Autoneg); |
|
141 |
|
142 ecmd->advertising = (ADVERTISED_1000baseT_Full | |
|
143 ADVERTISED_FIBRE | |
|
144 ADVERTISED_Autoneg); |
|
145 |
|
146 ecmd->port = PORT_FIBRE; |
|
147 ecmd->transceiver = XCVR_EXTERNAL; |
|
148 } |
|
149 |
|
150 status = er32(STATUS); |
|
151 if (status & E1000_STATUS_LU) { |
|
152 if (status & E1000_STATUS_SPEED_1000) |
|
153 ecmd->speed = 1000; |
|
154 else if (status & E1000_STATUS_SPEED_100) |
|
155 ecmd->speed = 100; |
|
156 else |
|
157 ecmd->speed = 10; |
|
158 |
|
159 if (status & E1000_STATUS_FD) |
|
160 ecmd->duplex = DUPLEX_FULL; |
|
161 else |
|
162 ecmd->duplex = DUPLEX_HALF; |
|
163 } else { |
|
164 ecmd->speed = -1; |
|
165 ecmd->duplex = -1; |
|
166 } |
|
167 |
|
168 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) || |
|
169 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE; |
|
170 |
|
171 /* MDI-X => 2; MDI =>1; Invalid =>0 */ |
|
172 if ((hw->phy.media_type == e1000_media_type_copper) && |
|
173 !hw->mac.get_link_status) |
|
174 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : |
|
175 ETH_TP_MDI; |
|
176 else |
|
177 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID; |
|
178 |
|
179 return 0; |
|
180 } |
|
181 |
|
182 static u32 e1000_get_link(struct net_device *netdev) |
|
183 { |
|
184 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
185 |
|
186 return e1000_has_link(adapter); |
|
187 } |
|
188 |
|
189 static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx) |
|
190 { |
|
191 struct e1000_mac_info *mac = &adapter->hw.mac; |
|
192 |
|
193 mac->autoneg = 0; |
|
194 |
|
195 /* Fiber NICs only allow 1000 gbps Full duplex */ |
|
196 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) && |
|
197 spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
|
198 e_err("Unsupported Speed/Duplex configuration\n"); |
|
199 return -EINVAL; |
|
200 } |
|
201 |
|
202 switch (spddplx) { |
|
203 case SPEED_10 + DUPLEX_HALF: |
|
204 mac->forced_speed_duplex = ADVERTISE_10_HALF; |
|
205 break; |
|
206 case SPEED_10 + DUPLEX_FULL: |
|
207 mac->forced_speed_duplex = ADVERTISE_10_FULL; |
|
208 break; |
|
209 case SPEED_100 + DUPLEX_HALF: |
|
210 mac->forced_speed_duplex = ADVERTISE_100_HALF; |
|
211 break; |
|
212 case SPEED_100 + DUPLEX_FULL: |
|
213 mac->forced_speed_duplex = ADVERTISE_100_FULL; |
|
214 break; |
|
215 case SPEED_1000 + DUPLEX_FULL: |
|
216 mac->autoneg = 1; |
|
217 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL; |
|
218 break; |
|
219 case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
|
220 default: |
|
221 e_err("Unsupported Speed/Duplex configuration\n"); |
|
222 return -EINVAL; |
|
223 } |
|
224 return 0; |
|
225 } |
|
226 |
|
227 static int e1000_set_settings(struct net_device *netdev, |
|
228 struct ethtool_cmd *ecmd) |
|
229 { |
|
230 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
231 struct e1000_hw *hw = &adapter->hw; |
|
232 |
|
233 /* |
|
234 * When SoL/IDER sessions are active, autoneg/speed/duplex |
|
235 * cannot be changed |
|
236 */ |
|
237 if (e1000_check_reset_block(hw)) { |
|
238 e_err("Cannot change link characteristics when SoL/IDER is " |
|
239 "active.\n"); |
|
240 return -EINVAL; |
|
241 } |
|
242 |
|
243 while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
|
244 msleep(1); |
|
245 |
|
246 if (ecmd->autoneg == AUTONEG_ENABLE) { |
|
247 hw->mac.autoneg = 1; |
|
248 if (hw->phy.media_type == e1000_media_type_fiber) |
|
249 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full | |
|
250 ADVERTISED_FIBRE | |
|
251 ADVERTISED_Autoneg; |
|
252 else |
|
253 hw->phy.autoneg_advertised = ecmd->advertising | |
|
254 ADVERTISED_TP | |
|
255 ADVERTISED_Autoneg; |
|
256 ecmd->advertising = hw->phy.autoneg_advertised; |
|
257 if (adapter->fc_autoneg) |
|
258 hw->fc.requested_mode = e1000_fc_default; |
|
259 } else { |
|
260 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) { |
|
261 clear_bit(__E1000_RESETTING, &adapter->state); |
|
262 return -EINVAL; |
|
263 } |
|
264 } |
|
265 |
|
266 /* reset the link */ |
|
267 |
|
268 if (netif_running(adapter->netdev)) { |
|
269 e1000e_down(adapter); |
|
270 e1000e_up(adapter); |
|
271 } else { |
|
272 e1000e_reset(adapter); |
|
273 } |
|
274 |
|
275 clear_bit(__E1000_RESETTING, &adapter->state); |
|
276 return 0; |
|
277 } |
|
278 |
|
279 static void e1000_get_pauseparam(struct net_device *netdev, |
|
280 struct ethtool_pauseparam *pause) |
|
281 { |
|
282 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
283 struct e1000_hw *hw = &adapter->hw; |
|
284 |
|
285 pause->autoneg = |
|
286 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE); |
|
287 |
|
288 if (hw->fc.current_mode == e1000_fc_rx_pause) { |
|
289 pause->rx_pause = 1; |
|
290 } else if (hw->fc.current_mode == e1000_fc_tx_pause) { |
|
291 pause->tx_pause = 1; |
|
292 } else if (hw->fc.current_mode == e1000_fc_full) { |
|
293 pause->rx_pause = 1; |
|
294 pause->tx_pause = 1; |
|
295 } |
|
296 } |
|
297 |
|
298 static int e1000_set_pauseparam(struct net_device *netdev, |
|
299 struct ethtool_pauseparam *pause) |
|
300 { |
|
301 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
302 struct e1000_hw *hw = &adapter->hw; |
|
303 int retval = 0; |
|
304 |
|
305 adapter->fc_autoneg = pause->autoneg; |
|
306 |
|
307 while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
|
308 msleep(1); |
|
309 |
|
310 if (adapter->fc_autoneg == AUTONEG_ENABLE) { |
|
311 hw->fc.requested_mode = e1000_fc_default; |
|
312 if (netif_running(adapter->netdev)) { |
|
313 e1000e_down(adapter); |
|
314 e1000e_up(adapter); |
|
315 } else { |
|
316 e1000e_reset(adapter); |
|
317 } |
|
318 } else { |
|
319 if (pause->rx_pause && pause->tx_pause) |
|
320 hw->fc.requested_mode = e1000_fc_full; |
|
321 else if (pause->rx_pause && !pause->tx_pause) |
|
322 hw->fc.requested_mode = e1000_fc_rx_pause; |
|
323 else if (!pause->rx_pause && pause->tx_pause) |
|
324 hw->fc.requested_mode = e1000_fc_tx_pause; |
|
325 else if (!pause->rx_pause && !pause->tx_pause) |
|
326 hw->fc.requested_mode = e1000_fc_none; |
|
327 |
|
328 hw->fc.current_mode = hw->fc.requested_mode; |
|
329 |
|
330 if (hw->phy.media_type == e1000_media_type_fiber) { |
|
331 retval = hw->mac.ops.setup_link(hw); |
|
332 /* implicit goto out */ |
|
333 } else { |
|
334 retval = e1000e_force_mac_fc(hw); |
|
335 if (retval) |
|
336 goto out; |
|
337 e1000e_set_fc_watermarks(hw); |
|
338 } |
|
339 } |
|
340 |
|
341 out: |
|
342 clear_bit(__E1000_RESETTING, &adapter->state); |
|
343 return retval; |
|
344 } |
|
345 |
|
346 static u32 e1000_get_rx_csum(struct net_device *netdev) |
|
347 { |
|
348 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
349 return (adapter->flags & FLAG_RX_CSUM_ENABLED); |
|
350 } |
|
351 |
|
352 static int e1000_set_rx_csum(struct net_device *netdev, u32 data) |
|
353 { |
|
354 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
355 |
|
356 if (data) |
|
357 adapter->flags |= FLAG_RX_CSUM_ENABLED; |
|
358 else |
|
359 adapter->flags &= ~FLAG_RX_CSUM_ENABLED; |
|
360 |
|
361 if (netif_running(netdev)) |
|
362 e1000e_reinit_locked(adapter); |
|
363 else |
|
364 e1000e_reset(adapter); |
|
365 return 0; |
|
366 } |
|
367 |
|
368 static u32 e1000_get_tx_csum(struct net_device *netdev) |
|
369 { |
|
370 return ((netdev->features & NETIF_F_HW_CSUM) != 0); |
|
371 } |
|
372 |
|
373 static int e1000_set_tx_csum(struct net_device *netdev, u32 data) |
|
374 { |
|
375 if (data) |
|
376 netdev->features |= NETIF_F_HW_CSUM; |
|
377 else |
|
378 netdev->features &= ~NETIF_F_HW_CSUM; |
|
379 |
|
380 return 0; |
|
381 } |
|
382 |
|
383 static int e1000_set_tso(struct net_device *netdev, u32 data) |
|
384 { |
|
385 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
386 |
|
387 if (data) { |
|
388 netdev->features |= NETIF_F_TSO; |
|
389 netdev->features |= NETIF_F_TSO6; |
|
390 } else { |
|
391 netdev->features &= ~NETIF_F_TSO; |
|
392 netdev->features &= ~NETIF_F_TSO6; |
|
393 } |
|
394 |
|
395 e_info("TSO is %s\n", data ? "Enabled" : "Disabled"); |
|
396 adapter->flags |= FLAG_TSO_FORCE; |
|
397 return 0; |
|
398 } |
|
399 |
|
400 static u32 e1000_get_msglevel(struct net_device *netdev) |
|
401 { |
|
402 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
403 return adapter->msg_enable; |
|
404 } |
|
405 |
|
406 static void e1000_set_msglevel(struct net_device *netdev, u32 data) |
|
407 { |
|
408 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
409 adapter->msg_enable = data; |
|
410 } |
|
411 |
|
412 static int e1000_get_regs_len(struct net_device *netdev) |
|
413 { |
|
414 #define E1000_REGS_LEN 32 /* overestimate */ |
|
415 return E1000_REGS_LEN * sizeof(u32); |
|
416 } |
|
417 |
|
418 static void e1000_get_regs(struct net_device *netdev, |
|
419 struct ethtool_regs *regs, void *p) |
|
420 { |
|
421 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
422 struct e1000_hw *hw = &adapter->hw; |
|
423 u32 *regs_buff = p; |
|
424 u16 phy_data; |
|
425 u8 revision_id; |
|
426 |
|
427 memset(p, 0, E1000_REGS_LEN * sizeof(u32)); |
|
428 |
|
429 pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id); |
|
430 |
|
431 regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device; |
|
432 |
|
433 regs_buff[0] = er32(CTRL); |
|
434 regs_buff[1] = er32(STATUS); |
|
435 |
|
436 regs_buff[2] = er32(RCTL); |
|
437 regs_buff[3] = er32(RDLEN); |
|
438 regs_buff[4] = er32(RDH); |
|
439 regs_buff[5] = er32(RDT); |
|
440 regs_buff[6] = er32(RDTR); |
|
441 |
|
442 regs_buff[7] = er32(TCTL); |
|
443 regs_buff[8] = er32(TDLEN); |
|
444 regs_buff[9] = er32(TDH); |
|
445 regs_buff[10] = er32(TDT); |
|
446 regs_buff[11] = er32(TIDV); |
|
447 |
|
448 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */ |
|
449 |
|
450 /* ethtool doesn't use anything past this point, so all this |
|
451 * code is likely legacy junk for apps that may or may not |
|
452 * exist */ |
|
453 if (hw->phy.type == e1000_phy_m88) { |
|
454 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
|
455 regs_buff[13] = (u32)phy_data; /* cable length */ |
|
456 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
|
457 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
|
458 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
|
459 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
|
460 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */ |
|
461 regs_buff[18] = regs_buff[13]; /* cable polarity */ |
|
462 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
|
463 regs_buff[20] = regs_buff[17]; /* polarity correction */ |
|
464 /* phy receive errors */ |
|
465 regs_buff[22] = adapter->phy_stats.receive_errors; |
|
466 regs_buff[23] = regs_buff[13]; /* mdix mode */ |
|
467 } |
|
468 regs_buff[21] = 0; /* was idle_errors */ |
|
469 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data); |
|
470 regs_buff[24] = (u32)phy_data; /* phy local receiver status */ |
|
471 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */ |
|
472 } |
|
473 |
|
474 static int e1000_get_eeprom_len(struct net_device *netdev) |
|
475 { |
|
476 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
477 return adapter->hw.nvm.word_size * 2; |
|
478 } |
|
479 |
|
480 static int e1000_get_eeprom(struct net_device *netdev, |
|
481 struct ethtool_eeprom *eeprom, u8 *bytes) |
|
482 { |
|
483 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
484 struct e1000_hw *hw = &adapter->hw; |
|
485 u16 *eeprom_buff; |
|
486 int first_word; |
|
487 int last_word; |
|
488 int ret_val = 0; |
|
489 u16 i; |
|
490 |
|
491 if (eeprom->len == 0) |
|
492 return -EINVAL; |
|
493 |
|
494 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16); |
|
495 |
|
496 first_word = eeprom->offset >> 1; |
|
497 last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
|
498 |
|
499 eeprom_buff = kmalloc(sizeof(u16) * |
|
500 (last_word - first_word + 1), GFP_KERNEL); |
|
501 if (!eeprom_buff) |
|
502 return -ENOMEM; |
|
503 |
|
504 if (hw->nvm.type == e1000_nvm_eeprom_spi) { |
|
505 ret_val = e1000_read_nvm(hw, first_word, |
|
506 last_word - first_word + 1, |
|
507 eeprom_buff); |
|
508 } else { |
|
509 for (i = 0; i < last_word - first_word + 1; i++) { |
|
510 ret_val = e1000_read_nvm(hw, first_word + i, 1, |
|
511 &eeprom_buff[i]); |
|
512 if (ret_val) |
|
513 break; |
|
514 } |
|
515 } |
|
516 |
|
517 if (ret_val) { |
|
518 /* a read error occurred, throw away the result */ |
|
519 memset(eeprom_buff, 0xff, sizeof(eeprom_buff)); |
|
520 } else { |
|
521 /* Device's eeprom is always little-endian, word addressable */ |
|
522 for (i = 0; i < last_word - first_word + 1; i++) |
|
523 le16_to_cpus(&eeprom_buff[i]); |
|
524 } |
|
525 |
|
526 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); |
|
527 kfree(eeprom_buff); |
|
528 |
|
529 return ret_val; |
|
530 } |
|
531 |
|
532 static int e1000_set_eeprom(struct net_device *netdev, |
|
533 struct ethtool_eeprom *eeprom, u8 *bytes) |
|
534 { |
|
535 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
536 struct e1000_hw *hw = &adapter->hw; |
|
537 u16 *eeprom_buff; |
|
538 void *ptr; |
|
539 int max_len; |
|
540 int first_word; |
|
541 int last_word; |
|
542 int ret_val = 0; |
|
543 u16 i; |
|
544 |
|
545 if (eeprom->len == 0) |
|
546 return -EOPNOTSUPP; |
|
547 |
|
548 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16))) |
|
549 return -EFAULT; |
|
550 |
|
551 if (adapter->flags & FLAG_READ_ONLY_NVM) |
|
552 return -EINVAL; |
|
553 |
|
554 max_len = hw->nvm.word_size * 2; |
|
555 |
|
556 first_word = eeprom->offset >> 1; |
|
557 last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
|
558 eeprom_buff = kmalloc(max_len, GFP_KERNEL); |
|
559 if (!eeprom_buff) |
|
560 return -ENOMEM; |
|
561 |
|
562 ptr = (void *)eeprom_buff; |
|
563 |
|
564 if (eeprom->offset & 1) { |
|
565 /* need read/modify/write of first changed EEPROM word */ |
|
566 /* only the second byte of the word is being modified */ |
|
567 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]); |
|
568 ptr++; |
|
569 } |
|
570 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) |
|
571 /* need read/modify/write of last changed EEPROM word */ |
|
572 /* only the first byte of the word is being modified */ |
|
573 ret_val = e1000_read_nvm(hw, last_word, 1, |
|
574 &eeprom_buff[last_word - first_word]); |
|
575 |
|
576 if (ret_val) |
|
577 goto out; |
|
578 |
|
579 /* Device's eeprom is always little-endian, word addressable */ |
|
580 for (i = 0; i < last_word - first_word + 1; i++) |
|
581 le16_to_cpus(&eeprom_buff[i]); |
|
582 |
|
583 memcpy(ptr, bytes, eeprom->len); |
|
584 |
|
585 for (i = 0; i < last_word - first_word + 1; i++) |
|
586 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]); |
|
587 |
|
588 ret_val = e1000_write_nvm(hw, first_word, |
|
589 last_word - first_word + 1, eeprom_buff); |
|
590 |
|
591 if (ret_val) |
|
592 goto out; |
|
593 |
|
594 /* |
|
595 * Update the checksum over the first part of the EEPROM if needed |
|
596 * and flush shadow RAM for applicable controllers |
|
597 */ |
|
598 if ((first_word <= NVM_CHECKSUM_REG) || |
|
599 (hw->mac.type == e1000_82574) || (hw->mac.type == e1000_82573)) |
|
600 ret_val = e1000e_update_nvm_checksum(hw); |
|
601 |
|
602 out: |
|
603 kfree(eeprom_buff); |
|
604 return ret_val; |
|
605 } |
|
606 |
|
607 static void e1000_get_drvinfo(struct net_device *netdev, |
|
608 struct ethtool_drvinfo *drvinfo) |
|
609 { |
|
610 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
611 char firmware_version[32]; |
|
612 |
|
613 strncpy(drvinfo->driver, e1000e_driver_name, 32); |
|
614 strncpy(drvinfo->version, e1000e_driver_version, 32); |
|
615 |
|
616 /* |
|
617 * EEPROM image version # is reported as firmware version # for |
|
618 * PCI-E controllers |
|
619 */ |
|
620 sprintf(firmware_version, "%d.%d-%d", |
|
621 (adapter->eeprom_vers & 0xF000) >> 12, |
|
622 (adapter->eeprom_vers & 0x0FF0) >> 4, |
|
623 (adapter->eeprom_vers & 0x000F)); |
|
624 |
|
625 strncpy(drvinfo->fw_version, firmware_version, 32); |
|
626 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32); |
|
627 drvinfo->regdump_len = e1000_get_regs_len(netdev); |
|
628 drvinfo->eedump_len = e1000_get_eeprom_len(netdev); |
|
629 } |
|
630 |
|
631 static void e1000_get_ringparam(struct net_device *netdev, |
|
632 struct ethtool_ringparam *ring) |
|
633 { |
|
634 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
635 struct e1000_ring *tx_ring = adapter->tx_ring; |
|
636 struct e1000_ring *rx_ring = adapter->rx_ring; |
|
637 |
|
638 ring->rx_max_pending = E1000_MAX_RXD; |
|
639 ring->tx_max_pending = E1000_MAX_TXD; |
|
640 ring->rx_mini_max_pending = 0; |
|
641 ring->rx_jumbo_max_pending = 0; |
|
642 ring->rx_pending = rx_ring->count; |
|
643 ring->tx_pending = tx_ring->count; |
|
644 ring->rx_mini_pending = 0; |
|
645 ring->rx_jumbo_pending = 0; |
|
646 } |
|
647 |
|
648 static int e1000_set_ringparam(struct net_device *netdev, |
|
649 struct ethtool_ringparam *ring) |
|
650 { |
|
651 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
652 struct e1000_ring *tx_ring, *tx_old; |
|
653 struct e1000_ring *rx_ring, *rx_old; |
|
654 int err; |
|
655 |
|
656 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
|
657 return -EINVAL; |
|
658 |
|
659 while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
|
660 msleep(1); |
|
661 |
|
662 if (netif_running(adapter->netdev)) |
|
663 e1000e_down(adapter); |
|
664 |
|
665 tx_old = adapter->tx_ring; |
|
666 rx_old = adapter->rx_ring; |
|
667 |
|
668 err = -ENOMEM; |
|
669 tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
|
670 if (!tx_ring) |
|
671 goto err_alloc_tx; |
|
672 /* |
|
673 * use a memcpy to save any previously configured |
|
674 * items like napi structs from having to be |
|
675 * reinitialized |
|
676 */ |
|
677 memcpy(tx_ring, tx_old, sizeof(struct e1000_ring)); |
|
678 |
|
679 rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
|
680 if (!rx_ring) |
|
681 goto err_alloc_rx; |
|
682 memcpy(rx_ring, rx_old, sizeof(struct e1000_ring)); |
|
683 |
|
684 adapter->tx_ring = tx_ring; |
|
685 adapter->rx_ring = rx_ring; |
|
686 |
|
687 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD); |
|
688 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD)); |
|
689 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE); |
|
690 |
|
691 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD); |
|
692 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD)); |
|
693 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE); |
|
694 |
|
695 if (netif_running(adapter->netdev)) { |
|
696 /* Try to get new resources before deleting old */ |
|
697 err = e1000e_setup_rx_resources(adapter); |
|
698 if (err) |
|
699 goto err_setup_rx; |
|
700 err = e1000e_setup_tx_resources(adapter); |
|
701 if (err) |
|
702 goto err_setup_tx; |
|
703 |
|
704 /* |
|
705 * restore the old in order to free it, |
|
706 * then add in the new |
|
707 */ |
|
708 adapter->rx_ring = rx_old; |
|
709 adapter->tx_ring = tx_old; |
|
710 e1000e_free_rx_resources(adapter); |
|
711 e1000e_free_tx_resources(adapter); |
|
712 kfree(tx_old); |
|
713 kfree(rx_old); |
|
714 adapter->rx_ring = rx_ring; |
|
715 adapter->tx_ring = tx_ring; |
|
716 err = e1000e_up(adapter); |
|
717 if (err) |
|
718 goto err_setup; |
|
719 } |
|
720 |
|
721 clear_bit(__E1000_RESETTING, &adapter->state); |
|
722 return 0; |
|
723 err_setup_tx: |
|
724 e1000e_free_rx_resources(adapter); |
|
725 err_setup_rx: |
|
726 adapter->rx_ring = rx_old; |
|
727 adapter->tx_ring = tx_old; |
|
728 kfree(rx_ring); |
|
729 err_alloc_rx: |
|
730 kfree(tx_ring); |
|
731 err_alloc_tx: |
|
732 e1000e_up(adapter); |
|
733 err_setup: |
|
734 clear_bit(__E1000_RESETTING, &adapter->state); |
|
735 return err; |
|
736 } |
|
737 |
|
738 static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, |
|
739 int reg, int offset, u32 mask, u32 write) |
|
740 { |
|
741 u32 pat, val; |
|
742 static const u32 test[] = |
|
743 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; |
|
744 for (pat = 0; pat < ARRAY_SIZE(test); pat++) { |
|
745 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset, |
|
746 (test[pat] & write)); |
|
747 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset); |
|
748 if (val != (test[pat] & write & mask)) { |
|
749 e_err("pattern test reg %04X failed: got 0x%08X " |
|
750 "expected 0x%08X\n", reg + offset, val, |
|
751 (test[pat] & write & mask)); |
|
752 *data = reg; |
|
753 return 1; |
|
754 } |
|
755 } |
|
756 return 0; |
|
757 } |
|
758 |
|
759 static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, |
|
760 int reg, u32 mask, u32 write) |
|
761 { |
|
762 u32 val; |
|
763 __ew32(&adapter->hw, reg, write & mask); |
|
764 val = __er32(&adapter->hw, reg); |
|
765 if ((write & mask) != (val & mask)) { |
|
766 e_err("set/check reg %04X test failed: got 0x%08X " |
|
767 "expected 0x%08X\n", reg, (val & mask), (write & mask)); |
|
768 *data = reg; |
|
769 return 1; |
|
770 } |
|
771 return 0; |
|
772 } |
|
773 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \ |
|
774 do { \ |
|
775 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \ |
|
776 return 1; \ |
|
777 } while (0) |
|
778 #define REG_PATTERN_TEST(reg, mask, write) \ |
|
779 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write) |
|
780 |
|
781 #define REG_SET_AND_CHECK(reg, mask, write) \ |
|
782 do { \ |
|
783 if (reg_set_and_check(adapter, data, reg, mask, write)) \ |
|
784 return 1; \ |
|
785 } while (0) |
|
786 |
|
787 static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data) |
|
788 { |
|
789 struct e1000_hw *hw = &adapter->hw; |
|
790 struct e1000_mac_info *mac = &adapter->hw.mac; |
|
791 u32 value; |
|
792 u32 before; |
|
793 u32 after; |
|
794 u32 i; |
|
795 u32 toggle; |
|
796 u32 mask; |
|
797 |
|
798 /* |
|
799 * The status register is Read Only, so a write should fail. |
|
800 * Some bits that get toggled are ignored. |
|
801 */ |
|
802 switch (mac->type) { |
|
803 /* there are several bits on newer hardware that are r/w */ |
|
804 case e1000_82571: |
|
805 case e1000_82572: |
|
806 case e1000_80003es2lan: |
|
807 toggle = 0x7FFFF3FF; |
|
808 break; |
|
809 default: |
|
810 toggle = 0x7FFFF033; |
|
811 break; |
|
812 } |
|
813 |
|
814 before = er32(STATUS); |
|
815 value = (er32(STATUS) & toggle); |
|
816 ew32(STATUS, toggle); |
|
817 after = er32(STATUS) & toggle; |
|
818 if (value != after) { |
|
819 e_err("failed STATUS register test got: 0x%08X expected: " |
|
820 "0x%08X\n", after, value); |
|
821 *data = 1; |
|
822 return 1; |
|
823 } |
|
824 /* restore previous status */ |
|
825 ew32(STATUS, before); |
|
826 |
|
827 if (!(adapter->flags & FLAG_IS_ICH)) { |
|
828 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF); |
|
829 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF); |
|
830 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF); |
|
831 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF); |
|
832 } |
|
833 |
|
834 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF); |
|
835 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF); |
|
836 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF); |
|
837 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF); |
|
838 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF); |
|
839 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8); |
|
840 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF); |
|
841 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF); |
|
842 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF); |
|
843 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF); |
|
844 |
|
845 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000); |
|
846 |
|
847 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE); |
|
848 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB); |
|
849 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000); |
|
850 |
|
851 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF); |
|
852 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF); |
|
853 if (!(adapter->flags & FLAG_IS_ICH)) |
|
854 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF); |
|
855 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF); |
|
856 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF); |
|
857 mask = 0x8003FFFF; |
|
858 switch (mac->type) { |
|
859 case e1000_ich10lan: |
|
860 case e1000_pchlan: |
|
861 mask |= (1 << 18); |
|
862 break; |
|
863 default: |
|
864 break; |
|
865 } |
|
866 for (i = 0; i < mac->rar_entry_count; i++) |
|
867 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), |
|
868 mask, 0xFFFFFFFF); |
|
869 |
|
870 for (i = 0; i < mac->mta_reg_count; i++) |
|
871 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF); |
|
872 |
|
873 *data = 0; |
|
874 return 0; |
|
875 } |
|
876 |
|
877 static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data) |
|
878 { |
|
879 u16 temp; |
|
880 u16 checksum = 0; |
|
881 u16 i; |
|
882 |
|
883 *data = 0; |
|
884 /* Read and add up the contents of the EEPROM */ |
|
885 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { |
|
886 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) { |
|
887 *data = 1; |
|
888 return *data; |
|
889 } |
|
890 checksum += temp; |
|
891 } |
|
892 |
|
893 /* If Checksum is not Correct return error else test passed */ |
|
894 if ((checksum != (u16) NVM_SUM) && !(*data)) |
|
895 *data = 2; |
|
896 |
|
897 return *data; |
|
898 } |
|
899 |
|
900 static irqreturn_t e1000_test_intr(int irq, void *data) |
|
901 { |
|
902 struct net_device *netdev = (struct net_device *) data; |
|
903 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
904 struct e1000_hw *hw = &adapter->hw; |
|
905 |
|
906 adapter->test_icr |= er32(ICR); |
|
907 |
|
908 return IRQ_HANDLED; |
|
909 } |
|
910 |
|
911 static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data) |
|
912 { |
|
913 struct net_device *netdev = adapter->netdev; |
|
914 struct e1000_hw *hw = &adapter->hw; |
|
915 u32 mask; |
|
916 u32 shared_int = 1; |
|
917 u32 irq = adapter->pdev->irq; |
|
918 int i; |
|
919 int ret_val = 0; |
|
920 int int_mode = E1000E_INT_MODE_LEGACY; |
|
921 |
|
922 *data = 0; |
|
923 |
|
924 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */ |
|
925 if (adapter->int_mode == E1000E_INT_MODE_MSIX) { |
|
926 int_mode = adapter->int_mode; |
|
927 e1000e_reset_interrupt_capability(adapter); |
|
928 adapter->int_mode = E1000E_INT_MODE_LEGACY; |
|
929 e1000e_set_interrupt_capability(adapter); |
|
930 } |
|
931 /* Hook up test interrupt handler just for this test */ |
|
932 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name, |
|
933 netdev)) { |
|
934 shared_int = 0; |
|
935 } else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED, |
|
936 netdev->name, netdev)) { |
|
937 *data = 1; |
|
938 ret_val = -1; |
|
939 goto out; |
|
940 } |
|
941 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared")); |
|
942 |
|
943 /* Disable all the interrupts */ |
|
944 ew32(IMC, 0xFFFFFFFF); |
|
945 msleep(10); |
|
946 |
|
947 /* Test each interrupt */ |
|
948 for (i = 0; i < 10; i++) { |
|
949 /* Interrupt to test */ |
|
950 mask = 1 << i; |
|
951 |
|
952 if (adapter->flags & FLAG_IS_ICH) { |
|
953 switch (mask) { |
|
954 case E1000_ICR_RXSEQ: |
|
955 continue; |
|
956 case 0x00000100: |
|
957 if (adapter->hw.mac.type == e1000_ich8lan || |
|
958 adapter->hw.mac.type == e1000_ich9lan) |
|
959 continue; |
|
960 break; |
|
961 default: |
|
962 break; |
|
963 } |
|
964 } |
|
965 |
|
966 if (!shared_int) { |
|
967 /* |
|
968 * Disable the interrupt to be reported in |
|
969 * the cause register and then force the same |
|
970 * interrupt and see if one gets posted. If |
|
971 * an interrupt was posted to the bus, the |
|
972 * test failed. |
|
973 */ |
|
974 adapter->test_icr = 0; |
|
975 ew32(IMC, mask); |
|
976 ew32(ICS, mask); |
|
977 msleep(10); |
|
978 |
|
979 if (adapter->test_icr & mask) { |
|
980 *data = 3; |
|
981 break; |
|
982 } |
|
983 } |
|
984 |
|
985 /* |
|
986 * Enable the interrupt to be reported in |
|
987 * the cause register and then force the same |
|
988 * interrupt and see if one gets posted. If |
|
989 * an interrupt was not posted to the bus, the |
|
990 * test failed. |
|
991 */ |
|
992 adapter->test_icr = 0; |
|
993 ew32(IMS, mask); |
|
994 ew32(ICS, mask); |
|
995 msleep(10); |
|
996 |
|
997 if (!(adapter->test_icr & mask)) { |
|
998 *data = 4; |
|
999 break; |
|
1000 } |
|
1001 |
|
1002 if (!shared_int) { |
|
1003 /* |
|
1004 * Disable the other interrupts to be reported in |
|
1005 * the cause register and then force the other |
|
1006 * interrupts and see if any get posted. If |
|
1007 * an interrupt was posted to the bus, the |
|
1008 * test failed. |
|
1009 */ |
|
1010 adapter->test_icr = 0; |
|
1011 ew32(IMC, ~mask & 0x00007FFF); |
|
1012 ew32(ICS, ~mask & 0x00007FFF); |
|
1013 msleep(10); |
|
1014 |
|
1015 if (adapter->test_icr) { |
|
1016 *data = 5; |
|
1017 break; |
|
1018 } |
|
1019 } |
|
1020 } |
|
1021 |
|
1022 /* Disable all the interrupts */ |
|
1023 ew32(IMC, 0xFFFFFFFF); |
|
1024 msleep(10); |
|
1025 |
|
1026 /* Unhook test interrupt handler */ |
|
1027 free_irq(irq, netdev); |
|
1028 |
|
1029 out: |
|
1030 if (int_mode == E1000E_INT_MODE_MSIX) { |
|
1031 e1000e_reset_interrupt_capability(adapter); |
|
1032 adapter->int_mode = int_mode; |
|
1033 e1000e_set_interrupt_capability(adapter); |
|
1034 } |
|
1035 |
|
1036 return ret_val; |
|
1037 } |
|
1038 |
|
1039 static void e1000_free_desc_rings(struct e1000_adapter *adapter) |
|
1040 { |
|
1041 struct e1000_ring *tx_ring = &adapter->test_tx_ring; |
|
1042 struct e1000_ring *rx_ring = &adapter->test_rx_ring; |
|
1043 struct pci_dev *pdev = adapter->pdev; |
|
1044 int i; |
|
1045 |
|
1046 if (tx_ring->desc && tx_ring->buffer_info) { |
|
1047 for (i = 0; i < tx_ring->count; i++) { |
|
1048 if (tx_ring->buffer_info[i].dma) |
|
1049 pci_unmap_single(pdev, |
|
1050 tx_ring->buffer_info[i].dma, |
|
1051 tx_ring->buffer_info[i].length, |
|
1052 PCI_DMA_TODEVICE); |
|
1053 if (tx_ring->buffer_info[i].skb) |
|
1054 dev_kfree_skb(tx_ring->buffer_info[i].skb); |
|
1055 } |
|
1056 } |
|
1057 |
|
1058 if (rx_ring->desc && rx_ring->buffer_info) { |
|
1059 for (i = 0; i < rx_ring->count; i++) { |
|
1060 if (rx_ring->buffer_info[i].dma) |
|
1061 pci_unmap_single(pdev, |
|
1062 rx_ring->buffer_info[i].dma, |
|
1063 2048, PCI_DMA_FROMDEVICE); |
|
1064 if (rx_ring->buffer_info[i].skb) |
|
1065 dev_kfree_skb(rx_ring->buffer_info[i].skb); |
|
1066 } |
|
1067 } |
|
1068 |
|
1069 if (tx_ring->desc) { |
|
1070 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
|
1071 tx_ring->dma); |
|
1072 tx_ring->desc = NULL; |
|
1073 } |
|
1074 if (rx_ring->desc) { |
|
1075 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
|
1076 rx_ring->dma); |
|
1077 rx_ring->desc = NULL; |
|
1078 } |
|
1079 |
|
1080 kfree(tx_ring->buffer_info); |
|
1081 tx_ring->buffer_info = NULL; |
|
1082 kfree(rx_ring->buffer_info); |
|
1083 rx_ring->buffer_info = NULL; |
|
1084 } |
|
1085 |
|
1086 static int e1000_setup_desc_rings(struct e1000_adapter *adapter) |
|
1087 { |
|
1088 struct e1000_ring *tx_ring = &adapter->test_tx_ring; |
|
1089 struct e1000_ring *rx_ring = &adapter->test_rx_ring; |
|
1090 struct pci_dev *pdev = adapter->pdev; |
|
1091 struct e1000_hw *hw = &adapter->hw; |
|
1092 u32 rctl; |
|
1093 int i; |
|
1094 int ret_val; |
|
1095 |
|
1096 /* Setup Tx descriptor ring and Tx buffers */ |
|
1097 |
|
1098 if (!tx_ring->count) |
|
1099 tx_ring->count = E1000_DEFAULT_TXD; |
|
1100 |
|
1101 tx_ring->buffer_info = kcalloc(tx_ring->count, |
|
1102 sizeof(struct e1000_buffer), |
|
1103 GFP_KERNEL); |
|
1104 if (!(tx_ring->buffer_info)) { |
|
1105 ret_val = 1; |
|
1106 goto err_nomem; |
|
1107 } |
|
1108 |
|
1109 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
|
1110 tx_ring->size = ALIGN(tx_ring->size, 4096); |
|
1111 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size, |
|
1112 &tx_ring->dma, GFP_KERNEL); |
|
1113 if (!tx_ring->desc) { |
|
1114 ret_val = 2; |
|
1115 goto err_nomem; |
|
1116 } |
|
1117 tx_ring->next_to_use = 0; |
|
1118 tx_ring->next_to_clean = 0; |
|
1119 |
|
1120 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF)); |
|
1121 ew32(TDBAH, ((u64) tx_ring->dma >> 32)); |
|
1122 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc)); |
|
1123 ew32(TDH, 0); |
|
1124 ew32(TDT, 0); |
|
1125 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR | |
|
1126 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT | |
|
1127 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT); |
|
1128 |
|
1129 for (i = 0; i < tx_ring->count; i++) { |
|
1130 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i); |
|
1131 struct sk_buff *skb; |
|
1132 unsigned int skb_size = 1024; |
|
1133 |
|
1134 skb = alloc_skb(skb_size, GFP_KERNEL); |
|
1135 if (!skb) { |
|
1136 ret_val = 3; |
|
1137 goto err_nomem; |
|
1138 } |
|
1139 skb_put(skb, skb_size); |
|
1140 tx_ring->buffer_info[i].skb = skb; |
|
1141 tx_ring->buffer_info[i].length = skb->len; |
|
1142 tx_ring->buffer_info[i].dma = |
|
1143 pci_map_single(pdev, skb->data, skb->len, |
|
1144 PCI_DMA_TODEVICE); |
|
1145 if (pci_dma_mapping_error(pdev, tx_ring->buffer_info[i].dma)) { |
|
1146 ret_val = 4; |
|
1147 goto err_nomem; |
|
1148 } |
|
1149 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma); |
|
1150 tx_desc->lower.data = cpu_to_le32(skb->len); |
|
1151 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP | |
|
1152 E1000_TXD_CMD_IFCS | |
|
1153 E1000_TXD_CMD_RS); |
|
1154 tx_desc->upper.data = 0; |
|
1155 } |
|
1156 |
|
1157 /* Setup Rx descriptor ring and Rx buffers */ |
|
1158 |
|
1159 if (!rx_ring->count) |
|
1160 rx_ring->count = E1000_DEFAULT_RXD; |
|
1161 |
|
1162 rx_ring->buffer_info = kcalloc(rx_ring->count, |
|
1163 sizeof(struct e1000_buffer), |
|
1164 GFP_KERNEL); |
|
1165 if (!(rx_ring->buffer_info)) { |
|
1166 ret_val = 5; |
|
1167 goto err_nomem; |
|
1168 } |
|
1169 |
|
1170 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc); |
|
1171 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size, |
|
1172 &rx_ring->dma, GFP_KERNEL); |
|
1173 if (!rx_ring->desc) { |
|
1174 ret_val = 6; |
|
1175 goto err_nomem; |
|
1176 } |
|
1177 rx_ring->next_to_use = 0; |
|
1178 rx_ring->next_to_clean = 0; |
|
1179 |
|
1180 rctl = er32(RCTL); |
|
1181 ew32(RCTL, rctl & ~E1000_RCTL_EN); |
|
1182 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF)); |
|
1183 ew32(RDBAH, ((u64) rx_ring->dma >> 32)); |
|
1184 ew32(RDLEN, rx_ring->size); |
|
1185 ew32(RDH, 0); |
|
1186 ew32(RDT, 0); |
|
1187 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 | |
|
1188 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE | |
|
1189 E1000_RCTL_SBP | E1000_RCTL_SECRC | |
|
1190 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
|
1191 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
|
1192 ew32(RCTL, rctl); |
|
1193 |
|
1194 for (i = 0; i < rx_ring->count; i++) { |
|
1195 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i); |
|
1196 struct sk_buff *skb; |
|
1197 |
|
1198 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL); |
|
1199 if (!skb) { |
|
1200 ret_val = 7; |
|
1201 goto err_nomem; |
|
1202 } |
|
1203 skb_reserve(skb, NET_IP_ALIGN); |
|
1204 rx_ring->buffer_info[i].skb = skb; |
|
1205 rx_ring->buffer_info[i].dma = |
|
1206 pci_map_single(pdev, skb->data, 2048, |
|
1207 PCI_DMA_FROMDEVICE); |
|
1208 if (pci_dma_mapping_error(pdev, rx_ring->buffer_info[i].dma)) { |
|
1209 ret_val = 8; |
|
1210 goto err_nomem; |
|
1211 } |
|
1212 rx_desc->buffer_addr = |
|
1213 cpu_to_le64(rx_ring->buffer_info[i].dma); |
|
1214 memset(skb->data, 0x00, skb->len); |
|
1215 } |
|
1216 |
|
1217 return 0; |
|
1218 |
|
1219 err_nomem: |
|
1220 e1000_free_desc_rings(adapter); |
|
1221 return ret_val; |
|
1222 } |
|
1223 |
|
1224 static void e1000_phy_disable_receiver(struct e1000_adapter *adapter) |
|
1225 { |
|
1226 /* Write out to PHY registers 29 and 30 to disable the Receiver. */ |
|
1227 e1e_wphy(&adapter->hw, 29, 0x001F); |
|
1228 e1e_wphy(&adapter->hw, 30, 0x8FFC); |
|
1229 e1e_wphy(&adapter->hw, 29, 0x001A); |
|
1230 e1e_wphy(&adapter->hw, 30, 0x8FF0); |
|
1231 } |
|
1232 |
|
1233 static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter) |
|
1234 { |
|
1235 struct e1000_hw *hw = &adapter->hw; |
|
1236 u32 ctrl_reg = 0; |
|
1237 u32 stat_reg = 0; |
|
1238 u16 phy_reg = 0; |
|
1239 |
|
1240 hw->mac.autoneg = 0; |
|
1241 |
|
1242 if (hw->phy.type == e1000_phy_m88) { |
|
1243 /* Auto-MDI/MDIX Off */ |
|
1244 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808); |
|
1245 /* reset to update Auto-MDI/MDIX */ |
|
1246 e1e_wphy(hw, PHY_CONTROL, 0x9140); |
|
1247 /* autoneg off */ |
|
1248 e1e_wphy(hw, PHY_CONTROL, 0x8140); |
|
1249 } else if (hw->phy.type == e1000_phy_gg82563) |
|
1250 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC); |
|
1251 |
|
1252 ctrl_reg = er32(CTRL); |
|
1253 |
|
1254 switch (hw->phy.type) { |
|
1255 case e1000_phy_ife: |
|
1256 /* force 100, set loopback */ |
|
1257 e1e_wphy(hw, PHY_CONTROL, 0x6100); |
|
1258 |
|
1259 /* Now set up the MAC to the same speed/duplex as the PHY. */ |
|
1260 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ |
|
1261 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ |
|
1262 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ |
|
1263 E1000_CTRL_SPD_100 |/* Force Speed to 100 */ |
|
1264 E1000_CTRL_FD); /* Force Duplex to FULL */ |
|
1265 break; |
|
1266 case e1000_phy_bm: |
|
1267 /* Set Default MAC Interface speed to 1GB */ |
|
1268 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg); |
|
1269 phy_reg &= ~0x0007; |
|
1270 phy_reg |= 0x006; |
|
1271 e1e_wphy(hw, PHY_REG(2, 21), phy_reg); |
|
1272 /* Assert SW reset for above settings to take effect */ |
|
1273 e1000e_commit_phy(hw); |
|
1274 mdelay(1); |
|
1275 /* Force Full Duplex */ |
|
1276 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg); |
|
1277 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C); |
|
1278 /* Set Link Up (in force link) */ |
|
1279 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg); |
|
1280 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040); |
|
1281 /* Force Link */ |
|
1282 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg); |
|
1283 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040); |
|
1284 /* Set Early Link Enable */ |
|
1285 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg); |
|
1286 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400); |
|
1287 /* fall through */ |
|
1288 default: |
|
1289 /* force 1000, set loopback */ |
|
1290 e1e_wphy(hw, PHY_CONTROL, 0x4140); |
|
1291 mdelay(250); |
|
1292 |
|
1293 /* Now set up the MAC to the same speed/duplex as the PHY. */ |
|
1294 ctrl_reg = er32(CTRL); |
|
1295 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ |
|
1296 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ |
|
1297 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ |
|
1298 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */ |
|
1299 E1000_CTRL_FD); /* Force Duplex to FULL */ |
|
1300 |
|
1301 if (adapter->flags & FLAG_IS_ICH) |
|
1302 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */ |
|
1303 } |
|
1304 |
|
1305 if (hw->phy.media_type == e1000_media_type_copper && |
|
1306 hw->phy.type == e1000_phy_m88) { |
|
1307 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */ |
|
1308 } else { |
|
1309 /* |
|
1310 * Set the ILOS bit on the fiber Nic if half duplex link is |
|
1311 * detected. |
|
1312 */ |
|
1313 stat_reg = er32(STATUS); |
|
1314 if ((stat_reg & E1000_STATUS_FD) == 0) |
|
1315 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU); |
|
1316 } |
|
1317 |
|
1318 ew32(CTRL, ctrl_reg); |
|
1319 |
|
1320 /* |
|
1321 * Disable the receiver on the PHY so when a cable is plugged in, the |
|
1322 * PHY does not begin to autoneg when a cable is reconnected to the NIC. |
|
1323 */ |
|
1324 if (hw->phy.type == e1000_phy_m88) |
|
1325 e1000_phy_disable_receiver(adapter); |
|
1326 |
|
1327 udelay(500); |
|
1328 |
|
1329 return 0; |
|
1330 } |
|
1331 |
|
1332 static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter) |
|
1333 { |
|
1334 struct e1000_hw *hw = &adapter->hw; |
|
1335 u32 ctrl = er32(CTRL); |
|
1336 int link = 0; |
|
1337 |
|
1338 /* special requirements for 82571/82572 fiber adapters */ |
|
1339 |
|
1340 /* |
|
1341 * jump through hoops to make sure link is up because serdes |
|
1342 * link is hardwired up |
|
1343 */ |
|
1344 ctrl |= E1000_CTRL_SLU; |
|
1345 ew32(CTRL, ctrl); |
|
1346 |
|
1347 /* disable autoneg */ |
|
1348 ctrl = er32(TXCW); |
|
1349 ctrl &= ~(1 << 31); |
|
1350 ew32(TXCW, ctrl); |
|
1351 |
|
1352 link = (er32(STATUS) & E1000_STATUS_LU); |
|
1353 |
|
1354 if (!link) { |
|
1355 /* set invert loss of signal */ |
|
1356 ctrl = er32(CTRL); |
|
1357 ctrl |= E1000_CTRL_ILOS; |
|
1358 ew32(CTRL, ctrl); |
|
1359 } |
|
1360 |
|
1361 /* |
|
1362 * special write to serdes control register to enable SerDes analog |
|
1363 * loopback |
|
1364 */ |
|
1365 #define E1000_SERDES_LB_ON 0x410 |
|
1366 ew32(SCTL, E1000_SERDES_LB_ON); |
|
1367 msleep(10); |
|
1368 |
|
1369 return 0; |
|
1370 } |
|
1371 |
|
1372 /* only call this for fiber/serdes connections to es2lan */ |
|
1373 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter) |
|
1374 { |
|
1375 struct e1000_hw *hw = &adapter->hw; |
|
1376 u32 ctrlext = er32(CTRL_EXT); |
|
1377 u32 ctrl = er32(CTRL); |
|
1378 |
|
1379 /* |
|
1380 * save CTRL_EXT to restore later, reuse an empty variable (unused |
|
1381 * on mac_type 80003es2lan) |
|
1382 */ |
|
1383 adapter->tx_fifo_head = ctrlext; |
|
1384 |
|
1385 /* clear the serdes mode bits, putting the device into mac loopback */ |
|
1386 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES; |
|
1387 ew32(CTRL_EXT, ctrlext); |
|
1388 |
|
1389 /* force speed to 1000/FD, link up */ |
|
1390 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
|
1391 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | |
|
1392 E1000_CTRL_SPD_1000 | E1000_CTRL_FD); |
|
1393 ew32(CTRL, ctrl); |
|
1394 |
|
1395 /* set mac loopback */ |
|
1396 ctrl = er32(RCTL); |
|
1397 ctrl |= E1000_RCTL_LBM_MAC; |
|
1398 ew32(RCTL, ctrl); |
|
1399 |
|
1400 /* set testing mode parameters (no need to reset later) */ |
|
1401 #define KMRNCTRLSTA_OPMODE (0x1F << 16) |
|
1402 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582 |
|
1403 ew32(KMRNCTRLSTA, |
|
1404 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII)); |
|
1405 |
|
1406 return 0; |
|
1407 } |
|
1408 |
|
1409 static int e1000_setup_loopback_test(struct e1000_adapter *adapter) |
|
1410 { |
|
1411 struct e1000_hw *hw = &adapter->hw; |
|
1412 u32 rctl; |
|
1413 |
|
1414 if (hw->phy.media_type == e1000_media_type_fiber || |
|
1415 hw->phy.media_type == e1000_media_type_internal_serdes) { |
|
1416 switch (hw->mac.type) { |
|
1417 case e1000_80003es2lan: |
|
1418 return e1000_set_es2lan_mac_loopback(adapter); |
|
1419 break; |
|
1420 case e1000_82571: |
|
1421 case e1000_82572: |
|
1422 return e1000_set_82571_fiber_loopback(adapter); |
|
1423 break; |
|
1424 default: |
|
1425 rctl = er32(RCTL); |
|
1426 rctl |= E1000_RCTL_LBM_TCVR; |
|
1427 ew32(RCTL, rctl); |
|
1428 return 0; |
|
1429 } |
|
1430 } else if (hw->phy.media_type == e1000_media_type_copper) { |
|
1431 return e1000_integrated_phy_loopback(adapter); |
|
1432 } |
|
1433 |
|
1434 return 7; |
|
1435 } |
|
1436 |
|
1437 static void e1000_loopback_cleanup(struct e1000_adapter *adapter) |
|
1438 { |
|
1439 struct e1000_hw *hw = &adapter->hw; |
|
1440 u32 rctl; |
|
1441 u16 phy_reg; |
|
1442 |
|
1443 rctl = er32(RCTL); |
|
1444 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC); |
|
1445 ew32(RCTL, rctl); |
|
1446 |
|
1447 switch (hw->mac.type) { |
|
1448 case e1000_80003es2lan: |
|
1449 if (hw->phy.media_type == e1000_media_type_fiber || |
|
1450 hw->phy.media_type == e1000_media_type_internal_serdes) { |
|
1451 /* restore CTRL_EXT, stealing space from tx_fifo_head */ |
|
1452 ew32(CTRL_EXT, adapter->tx_fifo_head); |
|
1453 adapter->tx_fifo_head = 0; |
|
1454 } |
|
1455 /* fall through */ |
|
1456 case e1000_82571: |
|
1457 case e1000_82572: |
|
1458 if (hw->phy.media_type == e1000_media_type_fiber || |
|
1459 hw->phy.media_type == e1000_media_type_internal_serdes) { |
|
1460 #define E1000_SERDES_LB_OFF 0x400 |
|
1461 ew32(SCTL, E1000_SERDES_LB_OFF); |
|
1462 msleep(10); |
|
1463 break; |
|
1464 } |
|
1465 /* Fall Through */ |
|
1466 default: |
|
1467 hw->mac.autoneg = 1; |
|
1468 if (hw->phy.type == e1000_phy_gg82563) |
|
1469 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180); |
|
1470 e1e_rphy(hw, PHY_CONTROL, &phy_reg); |
|
1471 if (phy_reg & MII_CR_LOOPBACK) { |
|
1472 phy_reg &= ~MII_CR_LOOPBACK; |
|
1473 e1e_wphy(hw, PHY_CONTROL, phy_reg); |
|
1474 e1000e_commit_phy(hw); |
|
1475 } |
|
1476 break; |
|
1477 } |
|
1478 } |
|
1479 |
|
1480 static void e1000_create_lbtest_frame(struct sk_buff *skb, |
|
1481 unsigned int frame_size) |
|
1482 { |
|
1483 memset(skb->data, 0xFF, frame_size); |
|
1484 frame_size &= ~1; |
|
1485 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1); |
|
1486 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1); |
|
1487 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1); |
|
1488 } |
|
1489 |
|
1490 static int e1000_check_lbtest_frame(struct sk_buff *skb, |
|
1491 unsigned int frame_size) |
|
1492 { |
|
1493 frame_size &= ~1; |
|
1494 if (*(skb->data + 3) == 0xFF) |
|
1495 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) && |
|
1496 (*(skb->data + frame_size / 2 + 12) == 0xAF)) |
|
1497 return 0; |
|
1498 return 13; |
|
1499 } |
|
1500 |
|
1501 static int e1000_run_loopback_test(struct e1000_adapter *adapter) |
|
1502 { |
|
1503 struct e1000_ring *tx_ring = &adapter->test_tx_ring; |
|
1504 struct e1000_ring *rx_ring = &adapter->test_rx_ring; |
|
1505 struct pci_dev *pdev = adapter->pdev; |
|
1506 struct e1000_hw *hw = &adapter->hw; |
|
1507 int i, j, k, l; |
|
1508 int lc; |
|
1509 int good_cnt; |
|
1510 int ret_val = 0; |
|
1511 unsigned long time; |
|
1512 |
|
1513 ew32(RDT, rx_ring->count - 1); |
|
1514 |
|
1515 /* |
|
1516 * Calculate the loop count based on the largest descriptor ring |
|
1517 * The idea is to wrap the largest ring a number of times using 64 |
|
1518 * send/receive pairs during each loop |
|
1519 */ |
|
1520 |
|
1521 if (rx_ring->count <= tx_ring->count) |
|
1522 lc = ((tx_ring->count / 64) * 2) + 1; |
|
1523 else |
|
1524 lc = ((rx_ring->count / 64) * 2) + 1; |
|
1525 |
|
1526 k = 0; |
|
1527 l = 0; |
|
1528 for (j = 0; j <= lc; j++) { /* loop count loop */ |
|
1529 for (i = 0; i < 64; i++) { /* send the packets */ |
|
1530 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb, |
|
1531 1024); |
|
1532 pci_dma_sync_single_for_device(pdev, |
|
1533 tx_ring->buffer_info[k].dma, |
|
1534 tx_ring->buffer_info[k].length, |
|
1535 PCI_DMA_TODEVICE); |
|
1536 k++; |
|
1537 if (k == tx_ring->count) |
|
1538 k = 0; |
|
1539 } |
|
1540 ew32(TDT, k); |
|
1541 msleep(200); |
|
1542 time = jiffies; /* set the start time for the receive */ |
|
1543 good_cnt = 0; |
|
1544 do { /* receive the sent packets */ |
|
1545 pci_dma_sync_single_for_cpu(pdev, |
|
1546 rx_ring->buffer_info[l].dma, 2048, |
|
1547 PCI_DMA_FROMDEVICE); |
|
1548 |
|
1549 ret_val = e1000_check_lbtest_frame( |
|
1550 rx_ring->buffer_info[l].skb, 1024); |
|
1551 if (!ret_val) |
|
1552 good_cnt++; |
|
1553 l++; |
|
1554 if (l == rx_ring->count) |
|
1555 l = 0; |
|
1556 /* |
|
1557 * time + 20 msecs (200 msecs on 2.4) is more than |
|
1558 * enough time to complete the receives, if it's |
|
1559 * exceeded, break and error off |
|
1560 */ |
|
1561 } while ((good_cnt < 64) && !time_after(jiffies, time + 20)); |
|
1562 if (good_cnt != 64) { |
|
1563 ret_val = 13; /* ret_val is the same as mis-compare */ |
|
1564 break; |
|
1565 } |
|
1566 if (jiffies >= (time + 20)) { |
|
1567 ret_val = 14; /* error code for time out error */ |
|
1568 break; |
|
1569 } |
|
1570 } /* end loop count loop */ |
|
1571 return ret_val; |
|
1572 } |
|
1573 |
|
1574 static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data) |
|
1575 { |
|
1576 /* |
|
1577 * PHY loopback cannot be performed if SoL/IDER |
|
1578 * sessions are active |
|
1579 */ |
|
1580 if (e1000_check_reset_block(&adapter->hw)) { |
|
1581 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n"); |
|
1582 *data = 0; |
|
1583 goto out; |
|
1584 } |
|
1585 |
|
1586 *data = e1000_setup_desc_rings(adapter); |
|
1587 if (*data) |
|
1588 goto out; |
|
1589 |
|
1590 *data = e1000_setup_loopback_test(adapter); |
|
1591 if (*data) |
|
1592 goto err_loopback; |
|
1593 |
|
1594 *data = e1000_run_loopback_test(adapter); |
|
1595 e1000_loopback_cleanup(adapter); |
|
1596 |
|
1597 err_loopback: |
|
1598 e1000_free_desc_rings(adapter); |
|
1599 out: |
|
1600 return *data; |
|
1601 } |
|
1602 |
|
1603 static int e1000_link_test(struct e1000_adapter *adapter, u64 *data) |
|
1604 { |
|
1605 struct e1000_hw *hw = &adapter->hw; |
|
1606 |
|
1607 *data = 0; |
|
1608 if (hw->phy.media_type == e1000_media_type_internal_serdes) { |
|
1609 int i = 0; |
|
1610 hw->mac.serdes_has_link = false; |
|
1611 |
|
1612 /* |
|
1613 * On some blade server designs, link establishment |
|
1614 * could take as long as 2-3 minutes |
|
1615 */ |
|
1616 do { |
|
1617 hw->mac.ops.check_for_link(hw); |
|
1618 if (hw->mac.serdes_has_link) |
|
1619 return *data; |
|
1620 msleep(20); |
|
1621 } while (i++ < 3750); |
|
1622 |
|
1623 *data = 1; |
|
1624 } else { |
|
1625 hw->mac.ops.check_for_link(hw); |
|
1626 if (hw->mac.autoneg) |
|
1627 msleep(4000); |
|
1628 |
|
1629 if (!(er32(STATUS) & |
|
1630 E1000_STATUS_LU)) |
|
1631 *data = 1; |
|
1632 } |
|
1633 return *data; |
|
1634 } |
|
1635 |
|
1636 static int e1000e_get_sset_count(struct net_device *netdev, int sset) |
|
1637 { |
|
1638 switch (sset) { |
|
1639 case ETH_SS_TEST: |
|
1640 return E1000_TEST_LEN; |
|
1641 case ETH_SS_STATS: |
|
1642 return E1000_STATS_LEN; |
|
1643 default: |
|
1644 return -EOPNOTSUPP; |
|
1645 } |
|
1646 } |
|
1647 |
|
1648 static void e1000_diag_test(struct net_device *netdev, |
|
1649 struct ethtool_test *eth_test, u64 *data) |
|
1650 { |
|
1651 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1652 u16 autoneg_advertised; |
|
1653 u8 forced_speed_duplex; |
|
1654 u8 autoneg; |
|
1655 bool if_running = netif_running(netdev); |
|
1656 |
|
1657 set_bit(__E1000_TESTING, &adapter->state); |
|
1658 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
|
1659 /* Offline tests */ |
|
1660 |
|
1661 /* save speed, duplex, autoneg settings */ |
|
1662 autoneg_advertised = adapter->hw.phy.autoneg_advertised; |
|
1663 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex; |
|
1664 autoneg = adapter->hw.mac.autoneg; |
|
1665 |
|
1666 e_info("offline testing starting\n"); |
|
1667 |
|
1668 /* |
|
1669 * Link test performed before hardware reset so autoneg doesn't |
|
1670 * interfere with test result |
|
1671 */ |
|
1672 if (e1000_link_test(adapter, &data[4])) |
|
1673 eth_test->flags |= ETH_TEST_FL_FAILED; |
|
1674 |
|
1675 if (if_running) |
|
1676 /* indicate we're in test mode */ |
|
1677 dev_close(netdev); |
|
1678 else |
|
1679 e1000e_reset(adapter); |
|
1680 |
|
1681 if (e1000_reg_test(adapter, &data[0])) |
|
1682 eth_test->flags |= ETH_TEST_FL_FAILED; |
|
1683 |
|
1684 e1000e_reset(adapter); |
|
1685 if (e1000_eeprom_test(adapter, &data[1])) |
|
1686 eth_test->flags |= ETH_TEST_FL_FAILED; |
|
1687 |
|
1688 e1000e_reset(adapter); |
|
1689 if (e1000_intr_test(adapter, &data[2])) |
|
1690 eth_test->flags |= ETH_TEST_FL_FAILED; |
|
1691 |
|
1692 e1000e_reset(adapter); |
|
1693 /* make sure the phy is powered up */ |
|
1694 e1000e_power_up_phy(adapter); |
|
1695 if (e1000_loopback_test(adapter, &data[3])) |
|
1696 eth_test->flags |= ETH_TEST_FL_FAILED; |
|
1697 |
|
1698 /* restore speed, duplex, autoneg settings */ |
|
1699 adapter->hw.phy.autoneg_advertised = autoneg_advertised; |
|
1700 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex; |
|
1701 adapter->hw.mac.autoneg = autoneg; |
|
1702 |
|
1703 /* force this routine to wait until autoneg complete/timeout */ |
|
1704 adapter->hw.phy.autoneg_wait_to_complete = 1; |
|
1705 e1000e_reset(adapter); |
|
1706 adapter->hw.phy.autoneg_wait_to_complete = 0; |
|
1707 |
|
1708 clear_bit(__E1000_TESTING, &adapter->state); |
|
1709 if (if_running) |
|
1710 dev_open(netdev); |
|
1711 } else { |
|
1712 e_info("online testing starting\n"); |
|
1713 /* Online tests */ |
|
1714 if (e1000_link_test(adapter, &data[4])) |
|
1715 eth_test->flags |= ETH_TEST_FL_FAILED; |
|
1716 |
|
1717 /* Online tests aren't run; pass by default */ |
|
1718 data[0] = 0; |
|
1719 data[1] = 0; |
|
1720 data[2] = 0; |
|
1721 data[3] = 0; |
|
1722 |
|
1723 clear_bit(__E1000_TESTING, &adapter->state); |
|
1724 } |
|
1725 msleep_interruptible(4 * 1000); |
|
1726 } |
|
1727 |
|
1728 static void e1000_get_wol(struct net_device *netdev, |
|
1729 struct ethtool_wolinfo *wol) |
|
1730 { |
|
1731 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1732 |
|
1733 wol->supported = 0; |
|
1734 wol->wolopts = 0; |
|
1735 |
|
1736 if (!(adapter->flags & FLAG_HAS_WOL) || |
|
1737 !device_can_wakeup(&adapter->pdev->dev)) |
|
1738 return; |
|
1739 |
|
1740 wol->supported = WAKE_UCAST | WAKE_MCAST | |
|
1741 WAKE_BCAST | WAKE_MAGIC | |
|
1742 WAKE_PHY | WAKE_ARP; |
|
1743 |
|
1744 /* apply any specific unsupported masks here */ |
|
1745 if (adapter->flags & FLAG_NO_WAKE_UCAST) { |
|
1746 wol->supported &= ~WAKE_UCAST; |
|
1747 |
|
1748 if (adapter->wol & E1000_WUFC_EX) |
|
1749 e_err("Interface does not support directed (unicast) " |
|
1750 "frame wake-up packets\n"); |
|
1751 } |
|
1752 |
|
1753 if (adapter->wol & E1000_WUFC_EX) |
|
1754 wol->wolopts |= WAKE_UCAST; |
|
1755 if (adapter->wol & E1000_WUFC_MC) |
|
1756 wol->wolopts |= WAKE_MCAST; |
|
1757 if (adapter->wol & E1000_WUFC_BC) |
|
1758 wol->wolopts |= WAKE_BCAST; |
|
1759 if (adapter->wol & E1000_WUFC_MAG) |
|
1760 wol->wolopts |= WAKE_MAGIC; |
|
1761 if (adapter->wol & E1000_WUFC_LNKC) |
|
1762 wol->wolopts |= WAKE_PHY; |
|
1763 if (adapter->wol & E1000_WUFC_ARP) |
|
1764 wol->wolopts |= WAKE_ARP; |
|
1765 } |
|
1766 |
|
1767 static int e1000_set_wol(struct net_device *netdev, |
|
1768 struct ethtool_wolinfo *wol) |
|
1769 { |
|
1770 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1771 |
|
1772 if (wol->wolopts & WAKE_MAGICSECURE) |
|
1773 return -EOPNOTSUPP; |
|
1774 |
|
1775 if (!(adapter->flags & FLAG_HAS_WOL) || |
|
1776 !device_can_wakeup(&adapter->pdev->dev)) |
|
1777 return wol->wolopts ? -EOPNOTSUPP : 0; |
|
1778 |
|
1779 /* these settings will always override what we currently have */ |
|
1780 adapter->wol = 0; |
|
1781 |
|
1782 if (wol->wolopts & WAKE_UCAST) |
|
1783 adapter->wol |= E1000_WUFC_EX; |
|
1784 if (wol->wolopts & WAKE_MCAST) |
|
1785 adapter->wol |= E1000_WUFC_MC; |
|
1786 if (wol->wolopts & WAKE_BCAST) |
|
1787 adapter->wol |= E1000_WUFC_BC; |
|
1788 if (wol->wolopts & WAKE_MAGIC) |
|
1789 adapter->wol |= E1000_WUFC_MAG; |
|
1790 if (wol->wolopts & WAKE_PHY) |
|
1791 adapter->wol |= E1000_WUFC_LNKC; |
|
1792 if (wol->wolopts & WAKE_ARP) |
|
1793 adapter->wol |= E1000_WUFC_ARP; |
|
1794 |
|
1795 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
|
1796 |
|
1797 return 0; |
|
1798 } |
|
1799 |
|
1800 /* toggle LED 4 times per second = 2 "blinks" per second */ |
|
1801 #define E1000_ID_INTERVAL (HZ/4) |
|
1802 |
|
1803 /* bit defines for adapter->led_status */ |
|
1804 #define E1000_LED_ON 0 |
|
1805 |
|
1806 static void e1000e_led_blink_task(struct work_struct *work) |
|
1807 { |
|
1808 struct e1000_adapter *adapter = container_of(work, |
|
1809 struct e1000_adapter, led_blink_task); |
|
1810 |
|
1811 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status)) |
|
1812 adapter->hw.mac.ops.led_off(&adapter->hw); |
|
1813 else |
|
1814 adapter->hw.mac.ops.led_on(&adapter->hw); |
|
1815 } |
|
1816 |
|
1817 static void e1000_led_blink_callback(unsigned long data) |
|
1818 { |
|
1819 struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
|
1820 |
|
1821 schedule_work(&adapter->led_blink_task); |
|
1822 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL); |
|
1823 } |
|
1824 |
|
1825 static int e1000_phys_id(struct net_device *netdev, u32 data) |
|
1826 { |
|
1827 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1828 struct e1000_hw *hw = &adapter->hw; |
|
1829 |
|
1830 if (!data) |
|
1831 data = INT_MAX; |
|
1832 |
|
1833 if ((hw->phy.type == e1000_phy_ife) || |
|
1834 (hw->mac.type == e1000_pchlan) || |
|
1835 (hw->mac.type == e1000_82574)) { |
|
1836 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task); |
|
1837 if (!adapter->blink_timer.function) { |
|
1838 init_timer(&adapter->blink_timer); |
|
1839 adapter->blink_timer.function = |
|
1840 e1000_led_blink_callback; |
|
1841 adapter->blink_timer.data = (unsigned long) adapter; |
|
1842 } |
|
1843 mod_timer(&adapter->blink_timer, jiffies); |
|
1844 msleep_interruptible(data * 1000); |
|
1845 del_timer_sync(&adapter->blink_timer); |
|
1846 if (hw->phy.type == e1000_phy_ife) |
|
1847 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0); |
|
1848 } else { |
|
1849 e1000e_blink_led(hw); |
|
1850 msleep_interruptible(data * 1000); |
|
1851 } |
|
1852 |
|
1853 hw->mac.ops.led_off(hw); |
|
1854 clear_bit(E1000_LED_ON, &adapter->led_status); |
|
1855 hw->mac.ops.cleanup_led(hw); |
|
1856 |
|
1857 return 0; |
|
1858 } |
|
1859 |
|
1860 static int e1000_get_coalesce(struct net_device *netdev, |
|
1861 struct ethtool_coalesce *ec) |
|
1862 { |
|
1863 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1864 |
|
1865 if (adapter->itr_setting <= 3) |
|
1866 ec->rx_coalesce_usecs = adapter->itr_setting; |
|
1867 else |
|
1868 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting; |
|
1869 |
|
1870 return 0; |
|
1871 } |
|
1872 |
|
1873 static int e1000_set_coalesce(struct net_device *netdev, |
|
1874 struct ethtool_coalesce *ec) |
|
1875 { |
|
1876 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1877 struct e1000_hw *hw = &adapter->hw; |
|
1878 |
|
1879 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) || |
|
1880 ((ec->rx_coalesce_usecs > 3) && |
|
1881 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) || |
|
1882 (ec->rx_coalesce_usecs == 2)) |
|
1883 return -EINVAL; |
|
1884 |
|
1885 if (ec->rx_coalesce_usecs <= 3) { |
|
1886 adapter->itr = 20000; |
|
1887 adapter->itr_setting = ec->rx_coalesce_usecs; |
|
1888 } else { |
|
1889 adapter->itr = (1000000 / ec->rx_coalesce_usecs); |
|
1890 adapter->itr_setting = adapter->itr & ~3; |
|
1891 } |
|
1892 |
|
1893 if (adapter->itr_setting != 0) |
|
1894 ew32(ITR, 1000000000 / (adapter->itr * 256)); |
|
1895 else |
|
1896 ew32(ITR, 0); |
|
1897 |
|
1898 return 0; |
|
1899 } |
|
1900 |
|
1901 static int e1000_nway_reset(struct net_device *netdev) |
|
1902 { |
|
1903 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1904 if (netif_running(netdev)) |
|
1905 e1000e_reinit_locked(adapter); |
|
1906 return 0; |
|
1907 } |
|
1908 |
|
1909 static void e1000_get_ethtool_stats(struct net_device *netdev, |
|
1910 struct ethtool_stats *stats, |
|
1911 u64 *data) |
|
1912 { |
|
1913 struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1914 int i; |
|
1915 |
|
1916 e1000e_update_stats(adapter); |
|
1917 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { |
|
1918 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset; |
|
1919 data[i] = (e1000_gstrings_stats[i].sizeof_stat == |
|
1920 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
|
1921 } |
|
1922 } |
|
1923 |
|
1924 static void e1000_get_strings(struct net_device *netdev, u32 stringset, |
|
1925 u8 *data) |
|
1926 { |
|
1927 u8 *p = data; |
|
1928 int i; |
|
1929 |
|
1930 switch (stringset) { |
|
1931 case ETH_SS_TEST: |
|
1932 memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test)); |
|
1933 break; |
|
1934 case ETH_SS_STATS: |
|
1935 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { |
|
1936 memcpy(p, e1000_gstrings_stats[i].stat_string, |
|
1937 ETH_GSTRING_LEN); |
|
1938 p += ETH_GSTRING_LEN; |
|
1939 } |
|
1940 break; |
|
1941 } |
|
1942 } |
|
1943 |
|
1944 static const struct ethtool_ops e1000_ethtool_ops = { |
|
1945 .get_settings = e1000_get_settings, |
|
1946 .set_settings = e1000_set_settings, |
|
1947 .get_drvinfo = e1000_get_drvinfo, |
|
1948 .get_regs_len = e1000_get_regs_len, |
|
1949 .get_regs = e1000_get_regs, |
|
1950 .get_wol = e1000_get_wol, |
|
1951 .set_wol = e1000_set_wol, |
|
1952 .get_msglevel = e1000_get_msglevel, |
|
1953 .set_msglevel = e1000_set_msglevel, |
|
1954 .nway_reset = e1000_nway_reset, |
|
1955 .get_link = e1000_get_link, |
|
1956 .get_eeprom_len = e1000_get_eeprom_len, |
|
1957 .get_eeprom = e1000_get_eeprom, |
|
1958 .set_eeprom = e1000_set_eeprom, |
|
1959 .get_ringparam = e1000_get_ringparam, |
|
1960 .set_ringparam = e1000_set_ringparam, |
|
1961 .get_pauseparam = e1000_get_pauseparam, |
|
1962 .set_pauseparam = e1000_set_pauseparam, |
|
1963 .get_rx_csum = e1000_get_rx_csum, |
|
1964 .set_rx_csum = e1000_set_rx_csum, |
|
1965 .get_tx_csum = e1000_get_tx_csum, |
|
1966 .set_tx_csum = e1000_set_tx_csum, |
|
1967 .get_sg = ethtool_op_get_sg, |
|
1968 .set_sg = ethtool_op_set_sg, |
|
1969 .get_tso = ethtool_op_get_tso, |
|
1970 .set_tso = e1000_set_tso, |
|
1971 .self_test = e1000_diag_test, |
|
1972 .get_strings = e1000_get_strings, |
|
1973 .phys_id = e1000_phys_id, |
|
1974 .get_ethtool_stats = e1000_get_ethtool_stats, |
|
1975 .get_sset_count = e1000e_get_sset_count, |
|
1976 .get_coalesce = e1000_get_coalesce, |
|
1977 .set_coalesce = e1000_set_coalesce, |
|
1978 }; |
|
1979 |
|
1980 void e1000e_set_ethtool_ops(struct net_device *netdev) |
|
1981 { |
|
1982 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops); |
|
1983 } |