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