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