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