author | Florian Pose <fp@igh-essen.com> |
Thu, 12 May 2011 08:57:40 +0200 | |
branch | stable-1.5 |
changeset 2063 | 06f3292f5b71 |
parent 2050 | a3e59f2a8589 |
child 2252 | 6001f50617a7 |
permissions | -rw-r--r-- |
1900 | 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 |
vim: noexpandtab |
|
28 |
||
29 |
*******************************************************************************/ |
|
30 |
||
31 |
#include "e1000-2.6.27-ethercat.h" |
|
32 |
#include <net/ip6_checksum.h> |
|
33 |
||
34 |
char e1000_driver_name[] = "ec_e1000"; |
|
35 |
static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; |
|
36 |
#define DRV_VERSION "7.3.21-k3-NAPI" |
|
37 |
const char e1000_driver_version[] = DRV_VERSION; |
|
38 |
static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; |
|
39 |
||
40 |
/* e1000_pci_tbl - PCI Device ID Table |
|
41 |
* |
|
42 |
* Last entry must be all 0s |
|
43 |
* |
|
44 |
* Macro expands to... |
|
45 |
* {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)} |
|
46 |
*/ |
|
47 |
static struct pci_device_id e1000_pci_tbl[] = { |
|
48 |
INTEL_E1000_ETHERNET_DEVICE(0x1000), |
|
49 |
INTEL_E1000_ETHERNET_DEVICE(0x1001), |
|
50 |
INTEL_E1000_ETHERNET_DEVICE(0x1004), |
|
51 |
INTEL_E1000_ETHERNET_DEVICE(0x1008), |
|
52 |
INTEL_E1000_ETHERNET_DEVICE(0x1009), |
|
53 |
INTEL_E1000_ETHERNET_DEVICE(0x100C), |
|
54 |
INTEL_E1000_ETHERNET_DEVICE(0x100D), |
|
55 |
INTEL_E1000_ETHERNET_DEVICE(0x100E), |
|
56 |
INTEL_E1000_ETHERNET_DEVICE(0x100F), |
|
57 |
INTEL_E1000_ETHERNET_DEVICE(0x1010), |
|
58 |
INTEL_E1000_ETHERNET_DEVICE(0x1011), |
|
59 |
INTEL_E1000_ETHERNET_DEVICE(0x1012), |
|
60 |
INTEL_E1000_ETHERNET_DEVICE(0x1013), |
|
61 |
INTEL_E1000_ETHERNET_DEVICE(0x1014), |
|
62 |
INTEL_E1000_ETHERNET_DEVICE(0x1015), |
|
63 |
INTEL_E1000_ETHERNET_DEVICE(0x1016), |
|
64 |
INTEL_E1000_ETHERNET_DEVICE(0x1017), |
|
65 |
INTEL_E1000_ETHERNET_DEVICE(0x1018), |
|
66 |
INTEL_E1000_ETHERNET_DEVICE(0x1019), |
|
67 |
INTEL_E1000_ETHERNET_DEVICE(0x101A), |
|
68 |
INTEL_E1000_ETHERNET_DEVICE(0x101D), |
|
69 |
INTEL_E1000_ETHERNET_DEVICE(0x101E), |
|
70 |
INTEL_E1000_ETHERNET_DEVICE(0x1026), |
|
71 |
INTEL_E1000_ETHERNET_DEVICE(0x1027), |
|
72 |
INTEL_E1000_ETHERNET_DEVICE(0x1028), |
|
73 |
INTEL_E1000_ETHERNET_DEVICE(0x1075), |
|
74 |
INTEL_E1000_ETHERNET_DEVICE(0x1076), |
|
75 |
INTEL_E1000_ETHERNET_DEVICE(0x1077), |
|
76 |
INTEL_E1000_ETHERNET_DEVICE(0x1078), |
|
77 |
INTEL_E1000_ETHERNET_DEVICE(0x1079), |
|
78 |
INTEL_E1000_ETHERNET_DEVICE(0x107A), |
|
79 |
INTEL_E1000_ETHERNET_DEVICE(0x107B), |
|
80 |
INTEL_E1000_ETHERNET_DEVICE(0x107C), |
|
81 |
INTEL_E1000_ETHERNET_DEVICE(0x108A), |
|
82 |
INTEL_E1000_ETHERNET_DEVICE(0x1099), |
|
83 |
INTEL_E1000_ETHERNET_DEVICE(0x10B5), |
|
84 |
/* required last entry */ |
|
85 |
{0,} |
|
86 |
}; |
|
87 |
||
88 |
// do not auto-load driver |
|
89 |
// MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
|
90 |
||
91 |
int e1000_up(struct e1000_adapter *adapter); |
|
92 |
void e1000_down(struct e1000_adapter *adapter); |
|
93 |
void e1000_reinit_locked(struct e1000_adapter *adapter); |
|
94 |
void e1000_reset(struct e1000_adapter *adapter); |
|
95 |
int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx); |
|
96 |
int e1000_setup_all_tx_resources(struct e1000_adapter *adapter); |
|
97 |
int e1000_setup_all_rx_resources(struct e1000_adapter *adapter); |
|
98 |
void e1000_free_all_tx_resources(struct e1000_adapter *adapter); |
|
99 |
void e1000_free_all_rx_resources(struct e1000_adapter *adapter); |
|
100 |
static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
|
101 |
struct e1000_tx_ring *txdr); |
|
102 |
static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
|
103 |
struct e1000_rx_ring *rxdr); |
|
104 |
static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
|
105 |
struct e1000_tx_ring *tx_ring); |
|
106 |
static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
|
107 |
struct e1000_rx_ring *rx_ring); |
|
108 |
void e1000_update_stats(struct e1000_adapter *adapter); |
|
109 |
||
110 |
static int e1000_init_module(void); |
|
111 |
static void e1000_exit_module(void); |
|
112 |
static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
|
113 |
static void __devexit e1000_remove(struct pci_dev *pdev); |
|
114 |
static int e1000_alloc_queues(struct e1000_adapter *adapter); |
|
115 |
static int e1000_sw_init(struct e1000_adapter *adapter); |
|
116 |
static int e1000_open(struct net_device *netdev); |
|
117 |
static int e1000_close(struct net_device *netdev); |
|
118 |
static void e1000_configure_tx(struct e1000_adapter *adapter); |
|
119 |
static void e1000_configure_rx(struct e1000_adapter *adapter); |
|
120 |
static void e1000_setup_rctl(struct e1000_adapter *adapter); |
|
121 |
static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter); |
|
122 |
static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter); |
|
123 |
static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
|
124 |
struct e1000_tx_ring *tx_ring); |
|
125 |
static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
|
126 |
struct e1000_rx_ring *rx_ring); |
|
127 |
static void e1000_set_rx_mode(struct net_device *netdev); |
|
128 |
static void e1000_update_phy_info(unsigned long data); |
|
129 |
static void e1000_watchdog(unsigned long data); |
|
130 |
static void e1000_82547_tx_fifo_stall(unsigned long data); |
|
131 |
static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
|
132 |
static struct net_device_stats * e1000_get_stats(struct net_device *netdev); |
|
133 |
static int e1000_change_mtu(struct net_device *netdev, int new_mtu); |
|
134 |
static int e1000_set_mac(struct net_device *netdev, void *p); |
|
135 |
void ec_poll(struct net_device *); |
|
136 |
static irqreturn_t e1000_intr(int irq, void *data); |
|
137 |
static irqreturn_t e1000_intr_msi(int irq, void *data); |
|
138 |
static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, |
|
139 |
struct e1000_tx_ring *tx_ring); |
|
140 |
static int e1000_clean(struct napi_struct *napi, int budget); |
|
141 |
static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
|
142 |
struct e1000_rx_ring *rx_ring, |
|
143 |
int *work_done, int work_to_do); |
|
144 |
static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
|
145 |
struct e1000_rx_ring *rx_ring, |
|
146 |
int *work_done, int work_to_do); |
|
147 |
static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
|
148 |
struct e1000_rx_ring *rx_ring, |
|
149 |
int cleaned_count); |
|
150 |
static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
|
151 |
struct e1000_rx_ring *rx_ring, |
|
152 |
int cleaned_count); |
|
153 |
static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); |
|
154 |
static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
|
155 |
int cmd); |
|
156 |
static void e1000_enter_82542_rst(struct e1000_adapter *adapter); |
|
157 |
static void e1000_leave_82542_rst(struct e1000_adapter *adapter); |
|
158 |
static void e1000_tx_timeout(struct net_device *dev); |
|
159 |
static void e1000_reset_task(struct work_struct *work); |
|
160 |
static void e1000_smartspeed(struct e1000_adapter *adapter); |
|
161 |
static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
|
162 |
struct sk_buff *skb); |
|
163 |
||
164 |
static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp); |
|
165 |
static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid); |
|
166 |
static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid); |
|
167 |
static void e1000_restore_vlan(struct e1000_adapter *adapter); |
|
168 |
||
169 |
static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); |
|
170 |
#ifdef CONFIG_PM |
|
171 |
static int e1000_resume(struct pci_dev *pdev); |
|
172 |
#endif |
|
173 |
static void e1000_shutdown(struct pci_dev *pdev); |
|
174 |
||
175 |
#ifdef CONFIG_NET_POLL_CONTROLLER |
|
176 |
/* for netdump / net console */ |
|
177 |
static void e1000_netpoll (struct net_device *netdev); |
|
178 |
#endif |
|
179 |
||
180 |
#define COPYBREAK_DEFAULT 256 |
|
181 |
static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT; |
|
182 |
module_param(copybreak, uint, 0644); |
|
183 |
MODULE_PARM_DESC(copybreak, |
|
184 |
"Maximum size of packet that is copied to a new buffer on receive"); |
|
185 |
||
186 |
static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
|
187 |
pci_channel_state_t state); |
|
188 |
static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); |
|
189 |
static void e1000_io_resume(struct pci_dev *pdev); |
|
190 |
||
191 |
static struct pci_error_handlers e1000_err_handler = { |
|
192 |
.error_detected = e1000_io_error_detected, |
|
193 |
.slot_reset = e1000_io_slot_reset, |
|
194 |
.resume = e1000_io_resume, |
|
195 |
}; |
|
196 |
||
197 |
static struct pci_driver e1000_driver = { |
|
198 |
.name = e1000_driver_name, |
|
199 |
.id_table = e1000_pci_tbl, |
|
200 |
.probe = e1000_probe, |
|
201 |
.remove = __devexit_p(e1000_remove), |
|
202 |
#ifdef CONFIG_PM |
|
203 |
/* Power Managment Hooks */ |
|
204 |
.suspend = e1000_suspend, |
|
205 |
.resume = e1000_resume, |
|
206 |
#endif |
|
207 |
.shutdown = e1000_shutdown, |
|
208 |
.err_handler = &e1000_err_handler |
|
209 |
}; |
|
210 |
||
211 |
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
|
212 |
MODULE_DESCRIPTION("EtherCAT-capable Intel(R) PRO/1000 Network Driver"); |
|
213 |
MODULE_LICENSE("GPL"); |
|
214 |
MODULE_VERSION(DRV_VERSION); |
|
215 |
||
216 |
static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
|
217 |
module_param(debug, int, 0); |
|
218 |
MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
|
219 |
||
220 |
/** |
|
221 |
* e1000_init_module - Driver Registration Routine |
|
222 |
* |
|
223 |
* e1000_init_module is the first routine called when the driver is |
|
224 |
* loaded. All it does is register with the PCI subsystem. |
|
225 |
**/ |
|
226 |
||
227 |
static int __init e1000_init_module(void) |
|
228 |
{ |
|
229 |
int ret; |
|
230 |
printk(KERN_INFO "%s - version %s\n", |
|
231 |
e1000_driver_string, e1000_driver_version); |
|
232 |
||
233 |
printk(KERN_INFO "%s\n", e1000_copyright); |
|
234 |
||
235 |
ret = pci_register_driver(&e1000_driver); |
|
236 |
if (copybreak != COPYBREAK_DEFAULT) { |
|
237 |
if (copybreak == 0) |
|
238 |
printk(KERN_INFO "e1000: copybreak disabled\n"); |
|
239 |
else |
|
240 |
printk(KERN_INFO "e1000: copybreak enabled for " |
|
241 |
"packets <= %u bytes\n", copybreak); |
|
242 |
} |
|
243 |
return ret; |
|
244 |
} |
|
245 |
||
246 |
module_init(e1000_init_module); |
|
247 |
||
248 |
/** |
|
249 |
* e1000_exit_module - Driver Exit Cleanup Routine |
|
250 |
* |
|
251 |
* e1000_exit_module is called just before the driver is removed |
|
252 |
* from memory. |
|
253 |
**/ |
|
254 |
||
255 |
static void __exit e1000_exit_module(void) |
|
256 |
{ |
|
257 |
pci_unregister_driver(&e1000_driver); |
|
258 |
} |
|
259 |
||
260 |
module_exit(e1000_exit_module); |
|
261 |
||
262 |
static int e1000_request_irq(struct e1000_adapter *adapter) |
|
263 |
{ |
|
264 |
struct e1000_hw *hw = &adapter->hw; |
|
265 |
struct net_device *netdev = adapter->netdev; |
|
266 |
irq_handler_t handler = e1000_intr; |
|
267 |
int irq_flags = IRQF_SHARED; |
|
268 |
int err; |
|
269 |
||
270 |
if (adapter->ecdev) |
|
271 |
return 0; |
|
272 |
||
273 |
if (hw->mac_type >= e1000_82571) { |
|
274 |
adapter->have_msi = !pci_enable_msi(adapter->pdev); |
|
275 |
if (adapter->have_msi) { |
|
276 |
handler = e1000_intr_msi; |
|
277 |
irq_flags = 0; |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name, |
|
282 |
netdev); |
|
283 |
if (err) { |
|
284 |
if (adapter->have_msi) |
|
285 |
pci_disable_msi(adapter->pdev); |
|
286 |
DPRINTK(PROBE, ERR, |
|
287 |
"Unable to allocate interrupt Error: %d\n", err); |
|
288 |
} |
|
289 |
||
290 |
return err; |
|
291 |
} |
|
292 |
||
293 |
static void e1000_free_irq(struct e1000_adapter *adapter) |
|
294 |
{ |
|
295 |
struct net_device *netdev = adapter->netdev; |
|
296 |
||
297 |
if (adapter->ecdev) |
|
298 |
return; |
|
299 |
||
300 |
free_irq(adapter->pdev->irq, netdev); |
|
301 |
||
302 |
if (adapter->have_msi) |
|
303 |
pci_disable_msi(adapter->pdev); |
|
304 |
} |
|
305 |
||
306 |
/** |
|
307 |
* e1000_irq_disable - Mask off interrupt generation on the NIC |
|
308 |
* @adapter: board private structure |
|
309 |
**/ |
|
310 |
||
311 |
static void e1000_irq_disable(struct e1000_adapter *adapter) |
|
312 |
{ |
|
313 |
struct e1000_hw *hw = &adapter->hw; |
|
314 |
||
315 |
if (adapter->ecdev) |
|
316 |
return; |
|
317 |
||
318 |
ew32(IMC, ~0); |
|
319 |
E1000_WRITE_FLUSH(); |
|
320 |
synchronize_irq(adapter->pdev->irq); |
|
321 |
} |
|
322 |
||
323 |
/** |
|
324 |
* e1000_irq_enable - Enable default interrupt generation settings |
|
325 |
* @adapter: board private structure |
|
326 |
**/ |
|
327 |
||
328 |
static void e1000_irq_enable(struct e1000_adapter *adapter) |
|
329 |
{ |
|
330 |
struct e1000_hw *hw = &adapter->hw; |
|
331 |
||
332 |
if (adapter->ecdev) |
|
333 |
return; |
|
334 |
||
335 |
ew32(IMS, IMS_ENABLE_MASK); |
|
336 |
E1000_WRITE_FLUSH(); |
|
337 |
} |
|
338 |
||
339 |
static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
|
340 |
{ |
|
341 |
struct e1000_hw *hw = &adapter->hw; |
|
342 |
struct net_device *netdev = adapter->netdev; |
|
343 |
u16 vid = hw->mng_cookie.vlan_id; |
|
344 |
u16 old_vid = adapter->mng_vlan_id; |
|
345 |
if (adapter->vlgrp) { |
|
346 |
if (!vlan_group_get_device(adapter->vlgrp, vid)) { |
|
347 |
if (hw->mng_cookie.status & |
|
348 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { |
|
349 |
e1000_vlan_rx_add_vid(netdev, vid); |
|
350 |
adapter->mng_vlan_id = vid; |
|
351 |
} else |
|
352 |
adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
|
353 |
||
354 |
if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && |
|
355 |
(vid != old_vid) && |
|
356 |
!vlan_group_get_device(adapter->vlgrp, old_vid)) |
|
357 |
e1000_vlan_rx_kill_vid(netdev, old_vid); |
|
358 |
} else |
|
359 |
adapter->mng_vlan_id = vid; |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
/** |
|
364 |
* e1000_release_hw_control - release control of the h/w to f/w |
|
365 |
* @adapter: address of board private structure |
|
366 |
* |
|
367 |
* e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
|
368 |
* For ASF and Pass Through versions of f/w this means that the |
|
369 |
* driver is no longer loaded. For AMT version (only with 82573) i |
|
370 |
* of the f/w this means that the network i/f is closed. |
|
371 |
* |
|
372 |
**/ |
|
373 |
||
374 |
static void e1000_release_hw_control(struct e1000_adapter *adapter) |
|
375 |
{ |
|
376 |
u32 ctrl_ext; |
|
377 |
u32 swsm; |
|
378 |
struct e1000_hw *hw = &adapter->hw; |
|
379 |
||
380 |
/* Let firmware taken over control of h/w */ |
|
381 |
switch (hw->mac_type) { |
|
382 |
case e1000_82573: |
|
383 |
swsm = er32(SWSM); |
|
384 |
ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
|
385 |
break; |
|
386 |
case e1000_82571: |
|
387 |
case e1000_82572: |
|
388 |
case e1000_80003es2lan: |
|
389 |
case e1000_ich8lan: |
|
390 |
ctrl_ext = er32(CTRL_EXT); |
|
391 |
ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
|
392 |
break; |
|
393 |
default: |
|
394 |
break; |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
/** |
|
399 |
* e1000_get_hw_control - get control of the h/w from f/w |
|
400 |
* @adapter: address of board private structure |
|
401 |
* |
|
402 |
* e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
|
403 |
* For ASF and Pass Through versions of f/w this means that |
|
404 |
* the driver is loaded. For AMT version (only with 82573) |
|
405 |
* of the f/w this means that the network i/f is open. |
|
406 |
* |
|
407 |
**/ |
|
408 |
||
409 |
static void e1000_get_hw_control(struct e1000_adapter *adapter) |
|
410 |
{ |
|
411 |
u32 ctrl_ext; |
|
412 |
u32 swsm; |
|
413 |
struct e1000_hw *hw = &adapter->hw; |
|
414 |
||
415 |
/* Let firmware know the driver has taken over */ |
|
416 |
switch (hw->mac_type) { |
|
417 |
case e1000_82573: |
|
418 |
swsm = er32(SWSM); |
|
419 |
ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
|
420 |
break; |
|
421 |
case e1000_82571: |
|
422 |
case e1000_82572: |
|
423 |
case e1000_80003es2lan: |
|
424 |
case e1000_ich8lan: |
|
425 |
ctrl_ext = er32(CTRL_EXT); |
|
426 |
ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
|
427 |
break; |
|
428 |
default: |
|
429 |
break; |
|
430 |
} |
|
431 |
} |
|
432 |
||
433 |
static void e1000_init_manageability(struct e1000_adapter *adapter) |
|
434 |
{ |
|
435 |
struct e1000_hw *hw = &adapter->hw; |
|
436 |
||
437 |
if (adapter->en_mng_pt) { |
|
438 |
u32 manc = er32(MANC); |
|
439 |
||
440 |
/* disable hardware interception of ARP */ |
|
441 |
manc &= ~(E1000_MANC_ARP_EN); |
|
442 |
||
443 |
/* enable receiving management packets to the host */ |
|
444 |
/* this will probably generate destination unreachable messages |
|
445 |
* from the host OS, but the packets will be handled on SMBUS */ |
|
446 |
if (hw->has_manc2h) { |
|
447 |
u32 manc2h = er32(MANC2H); |
|
448 |
||
449 |
manc |= E1000_MANC_EN_MNG2HOST; |
|
450 |
#define E1000_MNG2HOST_PORT_623 (1 << 5) |
|
451 |
#define E1000_MNG2HOST_PORT_664 (1 << 6) |
|
452 |
manc2h |= E1000_MNG2HOST_PORT_623; |
|
453 |
manc2h |= E1000_MNG2HOST_PORT_664; |
|
454 |
ew32(MANC2H, manc2h); |
|
455 |
} |
|
456 |
||
457 |
ew32(MANC, manc); |
|
458 |
} |
|
459 |
} |
|
460 |
||
461 |
static void e1000_release_manageability(struct e1000_adapter *adapter) |
|
462 |
{ |
|
463 |
struct e1000_hw *hw = &adapter->hw; |
|
464 |
||
465 |
if (adapter->en_mng_pt) { |
|
466 |
u32 manc = er32(MANC); |
|
467 |
||
468 |
/* re-enable hardware interception of ARP */ |
|
469 |
manc |= E1000_MANC_ARP_EN; |
|
470 |
||
471 |
if (hw->has_manc2h) |
|
472 |
manc &= ~E1000_MANC_EN_MNG2HOST; |
|
473 |
||
474 |
/* don't explicitly have to mess with MANC2H since |
|
475 |
* MANC has an enable disable that gates MANC2H */ |
|
476 |
||
477 |
ew32(MANC, manc); |
|
478 |
} |
|
479 |
} |
|
480 |
||
481 |
/** |
|
482 |
* e1000_configure - configure the hardware for RX and TX |
|
483 |
* @adapter = private board structure |
|
484 |
**/ |
|
485 |
static void e1000_configure(struct e1000_adapter *adapter) |
|
486 |
{ |
|
487 |
struct net_device *netdev = adapter->netdev; |
|
488 |
int i; |
|
489 |
||
490 |
e1000_set_rx_mode(netdev); |
|
491 |
||
492 |
e1000_restore_vlan(adapter); |
|
493 |
e1000_init_manageability(adapter); |
|
494 |
||
495 |
e1000_configure_tx(adapter); |
|
496 |
e1000_setup_rctl(adapter); |
|
497 |
e1000_configure_rx(adapter); |
|
498 |
/* call E1000_DESC_UNUSED which always leaves |
|
499 |
* at least 1 descriptor unused to make sure |
|
500 |
* next_to_use != next_to_clean */ |
|
501 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
|
502 |
struct e1000_rx_ring *ring = &adapter->rx_ring[i]; |
|
503 |
if (adapter->ecdev) { |
|
504 |
/* fill rx ring completely! */ |
|
505 |
adapter->alloc_rx_buf(adapter, ring, ring->count); |
|
506 |
} else { |
|
507 |
/* this one leaves the last ring element unallocated! */ |
|
508 |
adapter->alloc_rx_buf(adapter, ring, |
|
509 |
E1000_DESC_UNUSED(ring)); |
|
510 |
} |
|
511 |
} |
|
512 |
||
513 |
adapter->tx_queue_len = netdev->tx_queue_len; |
|
514 |
} |
|
515 |
||
516 |
int e1000_up(struct e1000_adapter *adapter) |
|
517 |
{ |
|
518 |
struct e1000_hw *hw = &adapter->hw; |
|
519 |
||
520 |
/* hardware has been reset, we need to reload some things */ |
|
521 |
e1000_configure(adapter); |
|
522 |
||
523 |
clear_bit(__E1000_DOWN, &adapter->flags); |
|
524 |
||
525 |
if (!adapter->ecdev) { |
|
526 |
napi_enable(&adapter->napi); |
|
527 |
||
528 |
e1000_irq_enable(adapter); |
|
529 |
||
530 |
/* fire a link change interrupt to start the watchdog */ |
|
531 |
ew32(ICS, E1000_ICS_LSC); |
|
532 |
} |
|
533 |
return 0; |
|
534 |
} |
|
535 |
||
536 |
/** |
|
537 |
* e1000_power_up_phy - restore link in case the phy was powered down |
|
538 |
* @adapter: address of board private structure |
|
539 |
* |
|
540 |
* The phy may be powered down to save power and turn off link when the |
|
541 |
* driver is unloaded and wake on lan is not enabled (among others) |
|
542 |
* *** this routine MUST be followed by a call to e1000_reset *** |
|
543 |
* |
|
544 |
**/ |
|
545 |
||
546 |
void e1000_power_up_phy(struct e1000_adapter *adapter) |
|
547 |
{ |
|
548 |
struct e1000_hw *hw = &adapter->hw; |
|
549 |
u16 mii_reg = 0; |
|
550 |
||
551 |
/* Just clear the power down bit to wake the phy back up */ |
|
552 |
if (hw->media_type == e1000_media_type_copper) { |
|
553 |
/* according to the manual, the phy will retain its |
|
554 |
* settings across a power-down/up cycle */ |
|
555 |
e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg); |
|
556 |
mii_reg &= ~MII_CR_POWER_DOWN; |
|
557 |
e1000_write_phy_reg(hw, PHY_CTRL, mii_reg); |
|
558 |
} |
|
559 |
} |
|
560 |
||
561 |
static void e1000_power_down_phy(struct e1000_adapter *adapter) |
|
562 |
{ |
|
563 |
struct e1000_hw *hw = &adapter->hw; |
|
564 |
||
565 |
/* Power down the PHY so no link is implied when interface is down * |
|
566 |
* The PHY cannot be powered down if any of the following is true * |
|
567 |
* (a) WoL is enabled |
|
568 |
* (b) AMT is active |
|
569 |
* (c) SoL/IDER session is active */ |
|
570 |
if (!adapter->wol && hw->mac_type >= e1000_82540 && |
|
571 |
hw->media_type == e1000_media_type_copper) { |
|
572 |
u16 mii_reg = 0; |
|
573 |
||
574 |
switch (hw->mac_type) { |
|
575 |
case e1000_82540: |
|
576 |
case e1000_82545: |
|
577 |
case e1000_82545_rev_3: |
|
578 |
case e1000_82546: |
|
579 |
case e1000_82546_rev_3: |
|
580 |
case e1000_82541: |
|
581 |
case e1000_82541_rev_2: |
|
582 |
case e1000_82547: |
|
583 |
case e1000_82547_rev_2: |
|
584 |
if (er32(MANC) & E1000_MANC_SMBUS_EN) |
|
585 |
goto out; |
|
586 |
break; |
|
587 |
case e1000_82571: |
|
588 |
case e1000_82572: |
|
589 |
case e1000_82573: |
|
590 |
case e1000_80003es2lan: |
|
591 |
case e1000_ich8lan: |
|
592 |
if (e1000_check_mng_mode(hw) || |
|
593 |
e1000_check_phy_reset_block(hw)) |
|
594 |
goto out; |
|
595 |
break; |
|
596 |
default: |
|
597 |
goto out; |
|
598 |
} |
|
599 |
e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg); |
|
600 |
mii_reg |= MII_CR_POWER_DOWN; |
|
601 |
e1000_write_phy_reg(hw, PHY_CTRL, mii_reg); |
|
602 |
mdelay(1); |
|
603 |
} |
|
604 |
out: |
|
605 |
return; |
|
606 |
} |
|
607 |
||
608 |
void e1000_down(struct e1000_adapter *adapter) |
|
609 |
{ |
|
610 |
struct net_device *netdev = adapter->netdev; |
|
611 |
||
612 |
/* signal that we're down so the interrupt handler does not |
|
613 |
* reschedule our watchdog timer */ |
|
614 |
set_bit(__E1000_DOWN, &adapter->flags); |
|
615 |
||
616 |
if (!adapter->ecdev) { |
|
617 |
napi_disable(&adapter->napi); |
|
618 |
||
619 |
e1000_irq_disable(adapter); |
|
620 |
||
621 |
del_timer_sync(&adapter->tx_fifo_stall_timer); |
|
622 |
del_timer_sync(&adapter->watchdog_timer); |
|
623 |
del_timer_sync(&adapter->phy_info_timer); |
|
624 |
} |
|
625 |
||
626 |
netdev->tx_queue_len = adapter->tx_queue_len; |
|
627 |
adapter->link_speed = 0; |
|
628 |
adapter->link_duplex = 0; |
|
629 |
if (!adapter->ecdev) { |
|
630 |
netif_carrier_off(netdev); |
|
631 |
netif_stop_queue(netdev); |
|
632 |
} |
|
633 |
||
634 |
e1000_reset(adapter); |
|
635 |
e1000_clean_all_tx_rings(adapter); |
|
636 |
e1000_clean_all_rx_rings(adapter); |
|
637 |
} |
|
638 |
||
639 |
void e1000_reinit_locked(struct e1000_adapter *adapter) |
|
640 |
{ |
|
641 |
WARN_ON(in_interrupt()); |
|
642 |
while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
|
643 |
msleep(1); |
|
644 |
e1000_down(adapter); |
|
645 |
e1000_up(adapter); |
|
646 |
clear_bit(__E1000_RESETTING, &adapter->flags); |
|
647 |
} |
|
648 |
||
649 |
void e1000_reset(struct e1000_adapter *adapter) |
|
650 |
{ |
|
651 |
struct e1000_hw *hw = &adapter->hw; |
|
652 |
u32 pba = 0, tx_space, min_tx_space, min_rx_space; |
|
653 |
u16 fc_high_water_mark = E1000_FC_HIGH_DIFF; |
|
654 |
bool legacy_pba_adjust = false; |
|
655 |
||
656 |
/* Repartition Pba for greater than 9k mtu |
|
657 |
* To take effect CTRL.RST is required. |
|
658 |
*/ |
|
659 |
||
660 |
switch (hw->mac_type) { |
|
661 |
case e1000_82542_rev2_0: |
|
662 |
case e1000_82542_rev2_1: |
|
663 |
case e1000_82543: |
|
664 |
case e1000_82544: |
|
665 |
case e1000_82540: |
|
666 |
case e1000_82541: |
|
667 |
case e1000_82541_rev_2: |
|
668 |
legacy_pba_adjust = true; |
|
669 |
pba = E1000_PBA_48K; |
|
670 |
break; |
|
671 |
case e1000_82545: |
|
672 |
case e1000_82545_rev_3: |
|
673 |
case e1000_82546: |
|
674 |
case e1000_82546_rev_3: |
|
675 |
pba = E1000_PBA_48K; |
|
676 |
break; |
|
677 |
case e1000_82547: |
|
678 |
case e1000_82547_rev_2: |
|
679 |
legacy_pba_adjust = true; |
|
680 |
pba = E1000_PBA_30K; |
|
681 |
break; |
|
682 |
case e1000_82571: |
|
683 |
case e1000_82572: |
|
684 |
case e1000_80003es2lan: |
|
685 |
pba = E1000_PBA_38K; |
|
686 |
break; |
|
687 |
case e1000_82573: |
|
688 |
pba = E1000_PBA_20K; |
|
689 |
break; |
|
690 |
case e1000_ich8lan: |
|
691 |
pba = E1000_PBA_8K; |
|
692 |
case e1000_undefined: |
|
693 |
case e1000_num_macs: |
|
694 |
break; |
|
695 |
} |
|
696 |
||
697 |
if (legacy_pba_adjust) { |
|
698 |
if (adapter->netdev->mtu > E1000_RXBUFFER_8192) |
|
699 |
pba -= 8; /* allocate more FIFO for Tx */ |
|
700 |
||
701 |
if (hw->mac_type == e1000_82547) { |
|
702 |
adapter->tx_fifo_head = 0; |
|
703 |
adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; |
|
704 |
adapter->tx_fifo_size = |
|
705 |
(E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; |
|
706 |
atomic_set(&adapter->tx_fifo_stall, 0); |
|
707 |
} |
|
708 |
} else if (hw->max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) { |
|
709 |
/* adjust PBA for jumbo frames */ |
|
710 |
ew32(PBA, pba); |
|
711 |
||
712 |
/* To maintain wire speed transmits, the Tx FIFO should be |
|
713 |
* large enough to accomodate two full transmit packets, |
|
714 |
* rounded up to the next 1KB and expressed in KB. Likewise, |
|
715 |
* the Rx FIFO should be large enough to accomodate at least |
|
716 |
* one full receive packet and is similarly rounded up and |
|
717 |
* expressed in KB. */ |
|
718 |
pba = er32(PBA); |
|
719 |
/* upper 16 bits has Tx packet buffer allocation size in KB */ |
|
720 |
tx_space = pba >> 16; |
|
721 |
/* lower 16 bits has Rx packet buffer allocation size in KB */ |
|
722 |
pba &= 0xffff; |
|
723 |
/* don't include ethernet FCS because hardware appends/strips */ |
|
724 |
min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE + |
|
725 |
VLAN_TAG_SIZE; |
|
726 |
min_tx_space = min_rx_space; |
|
727 |
min_tx_space *= 2; |
|
728 |
min_tx_space = ALIGN(min_tx_space, 1024); |
|
729 |
min_tx_space >>= 10; |
|
730 |
min_rx_space = ALIGN(min_rx_space, 1024); |
|
731 |
min_rx_space >>= 10; |
|
732 |
||
733 |
/* If current Tx allocation is less than the min Tx FIFO size, |
|
734 |
* and the min Tx FIFO size is less than the current Rx FIFO |
|
735 |
* allocation, take space away from current Rx allocation */ |
|
736 |
if (tx_space < min_tx_space && |
|
737 |
((min_tx_space - tx_space) < pba)) { |
|
738 |
pba = pba - (min_tx_space - tx_space); |
|
739 |
||
740 |
/* PCI/PCIx hardware has PBA alignment constraints */ |
|
741 |
switch (hw->mac_type) { |
|
742 |
case e1000_82545 ... e1000_82546_rev_3: |
|
743 |
pba &= ~(E1000_PBA_8K - 1); |
|
744 |
break; |
|
745 |
default: |
|
746 |
break; |
|
747 |
} |
|
748 |
||
749 |
/* if short on rx space, rx wins and must trump tx |
|
750 |
* adjustment or use Early Receive if available */ |
|
751 |
if (pba < min_rx_space) { |
|
752 |
switch (hw->mac_type) { |
|
753 |
case e1000_82573: |
|
754 |
/* ERT enabled in e1000_configure_rx */ |
|
755 |
break; |
|
756 |
default: |
|
757 |
pba = min_rx_space; |
|
758 |
break; |
|
759 |
} |
|
760 |
} |
|
761 |
} |
|
762 |
} |
|
763 |
||
764 |
ew32(PBA, pba); |
|
765 |
||
766 |
/* flow control settings */ |
|
767 |
/* Set the FC high water mark to 90% of the FIFO size. |
|
768 |
* Required to clear last 3 LSB */ |
|
769 |
fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; |
|
770 |
/* We can't use 90% on small FIFOs because the remainder |
|
771 |
* would be less than 1 full frame. In this case, we size |
|
772 |
* it to allow at least a full frame above the high water |
|
773 |
* mark. */ |
|
774 |
if (pba < E1000_PBA_16K) |
|
775 |
fc_high_water_mark = (pba * 1024) - 1600; |
|
776 |
||
777 |
hw->fc_high_water = fc_high_water_mark; |
|
778 |
hw->fc_low_water = fc_high_water_mark - 8; |
|
779 |
if (hw->mac_type == e1000_80003es2lan) |
|
780 |
hw->fc_pause_time = 0xFFFF; |
|
781 |
else |
|
782 |
hw->fc_pause_time = E1000_FC_PAUSE_TIME; |
|
783 |
hw->fc_send_xon = 1; |
|
784 |
hw->fc = hw->original_fc; |
|
785 |
||
786 |
/* Allow time for pending master requests to run */ |
|
787 |
e1000_reset_hw(hw); |
|
788 |
if (hw->mac_type >= e1000_82544) |
|
789 |
ew32(WUC, 0); |
|
790 |
||
791 |
if (e1000_init_hw(hw)) |
|
792 |
DPRINTK(PROBE, ERR, "Hardware Error\n"); |
|
793 |
e1000_update_mng_vlan(adapter); |
|
794 |
||
795 |
/* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ |
|
796 |
if (hw->mac_type >= e1000_82544 && |
|
797 |
hw->mac_type <= e1000_82547_rev_2 && |
|
798 |
hw->autoneg == 1 && |
|
799 |
hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
|
800 |
u32 ctrl = er32(CTRL); |
|
801 |
/* clear phy power management bit if we are in gig only mode, |
|
802 |
* which if enabled will attempt negotiation to 100Mb, which |
|
803 |
* can cause a loss of link at power off or driver unload */ |
|
804 |
ctrl &= ~E1000_CTRL_SWDPIN3; |
|
805 |
ew32(CTRL, ctrl); |
|
806 |
} |
|
807 |
||
808 |
/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
|
809 |
ew32(VET, ETHERNET_IEEE_VLAN_TYPE); |
|
810 |
||
811 |
e1000_reset_adaptive(hw); |
|
812 |
e1000_phy_get_info(hw, &adapter->phy_info); |
|
813 |
||
814 |
if (!adapter->smart_power_down && |
|
815 |
(hw->mac_type == e1000_82571 || |
|
816 |
hw->mac_type == e1000_82572)) { |
|
817 |
u16 phy_data = 0; |
|
818 |
/* speed up time to link by disabling smart power down, ignore |
|
819 |
* the return value of this function because there is nothing |
|
820 |
* different we would do if it failed */ |
|
821 |
e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
|
822 |
&phy_data); |
|
823 |
phy_data &= ~IGP02E1000_PM_SPD; |
|
824 |
e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
|
825 |
phy_data); |
|
826 |
} |
|
827 |
||
828 |
e1000_release_manageability(adapter); |
|
829 |
} |
|
830 |
||
831 |
/** |
|
832 |
* Dump the eeprom for users having checksum issues |
|
833 |
**/ |
|
834 |
static void e1000_dump_eeprom(struct e1000_adapter *adapter) |
|
835 |
{ |
|
836 |
struct net_device *netdev = adapter->netdev; |
|
837 |
struct ethtool_eeprom eeprom; |
|
838 |
const struct ethtool_ops *ops = netdev->ethtool_ops; |
|
839 |
u8 *data; |
|
840 |
int i; |
|
841 |
u16 csum_old, csum_new = 0; |
|
842 |
||
843 |
eeprom.len = ops->get_eeprom_len(netdev); |
|
844 |
eeprom.offset = 0; |
|
845 |
||
846 |
data = kmalloc(eeprom.len, GFP_KERNEL); |
|
847 |
if (!data) { |
|
848 |
printk(KERN_ERR "Unable to allocate memory to dump EEPROM" |
|
849 |
" data\n"); |
|
850 |
return; |
|
851 |
} |
|
852 |
||
853 |
ops->get_eeprom(netdev, &eeprom, data); |
|
854 |
||
855 |
csum_old = (data[EEPROM_CHECKSUM_REG * 2]) + |
|
856 |
(data[EEPROM_CHECKSUM_REG * 2 + 1] << 8); |
|
857 |
for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2) |
|
858 |
csum_new += data[i] + (data[i + 1] << 8); |
|
859 |
csum_new = EEPROM_SUM - csum_new; |
|
860 |
||
861 |
printk(KERN_ERR "/*********************/\n"); |
|
862 |
printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old); |
|
863 |
printk(KERN_ERR "Calculated : 0x%04x\n", csum_new); |
|
864 |
||
865 |
printk(KERN_ERR "Offset Values\n"); |
|
866 |
printk(KERN_ERR "======== ======\n"); |
|
867 |
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0); |
|
868 |
||
869 |
printk(KERN_ERR "Include this output when contacting your support " |
|
870 |
"provider.\n"); |
|
871 |
printk(KERN_ERR "This is not a software error! Something bad " |
|
872 |
"happened to your hardware or\n"); |
|
873 |
printk(KERN_ERR "EEPROM image. Ignoring this " |
|
874 |
"problem could result in further problems,\n"); |
|
875 |
printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n"); |
|
876 |
printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, " |
|
877 |
"which is invalid\n"); |
|
878 |
printk(KERN_ERR "and requires you to set the proper MAC " |
|
879 |
"address manually before continuing\n"); |
|
880 |
printk(KERN_ERR "to enable this network device.\n"); |
|
881 |
printk(KERN_ERR "Please inspect the EEPROM dump and report the issue " |
|
882 |
"to your hardware vendor\n"); |
|
883 |
printk(KERN_ERR "or Intel Customer Support.\n"); |
|
884 |
printk(KERN_ERR "/*********************/\n"); |
|
885 |
||
886 |
kfree(data); |
|
887 |
} |
|
888 |
||
889 |
/** |
|
890 |
* e1000_is_need_ioport - determine if an adapter needs ioport resources or not |
|
891 |
* @pdev: PCI device information struct |
|
892 |
* |
|
893 |
* Return true if an adapter needs ioport resources |
|
894 |
**/ |
|
895 |
static int e1000_is_need_ioport(struct pci_dev *pdev) |
|
896 |
{ |
|
897 |
switch (pdev->device) { |
|
898 |
case E1000_DEV_ID_82540EM: |
|
899 |
case E1000_DEV_ID_82540EM_LOM: |
|
900 |
case E1000_DEV_ID_82540EP: |
|
901 |
case E1000_DEV_ID_82540EP_LOM: |
|
902 |
case E1000_DEV_ID_82540EP_LP: |
|
903 |
case E1000_DEV_ID_82541EI: |
|
904 |
case E1000_DEV_ID_82541EI_MOBILE: |
|
905 |
case E1000_DEV_ID_82541ER: |
|
906 |
case E1000_DEV_ID_82541ER_LOM: |
|
907 |
case E1000_DEV_ID_82541GI: |
|
908 |
case E1000_DEV_ID_82541GI_LF: |
|
909 |
case E1000_DEV_ID_82541GI_MOBILE: |
|
910 |
case E1000_DEV_ID_82544EI_COPPER: |
|
911 |
case E1000_DEV_ID_82544EI_FIBER: |
|
912 |
case E1000_DEV_ID_82544GC_COPPER: |
|
913 |
case E1000_DEV_ID_82544GC_LOM: |
|
914 |
case E1000_DEV_ID_82545EM_COPPER: |
|
915 |
case E1000_DEV_ID_82545EM_FIBER: |
|
916 |
case E1000_DEV_ID_82546EB_COPPER: |
|
917 |
case E1000_DEV_ID_82546EB_FIBER: |
|
918 |
case E1000_DEV_ID_82546EB_QUAD_COPPER: |
|
919 |
return true; |
|
920 |
default: |
|
921 |
return false; |
|
922 |
} |
|
923 |
} |
|
924 |
||
925 |
/** |
|
926 |
* e1000_probe - Device Initialization Routine |
|
927 |
* @pdev: PCI device information struct |
|
928 |
* @ent: entry in e1000_pci_tbl |
|
929 |
* |
|
930 |
* Returns 0 on success, negative on failure |
|
931 |
* |
|
932 |
* e1000_probe initializes an adapter identified by a pci_dev structure. |
|
933 |
* The OS initialization, configuring of the adapter private structure, |
|
934 |
* and a hardware reset occur. |
|
935 |
**/ |
|
936 |
static int __devinit e1000_probe(struct pci_dev *pdev, |
|
937 |
const struct pci_device_id *ent) |
|
938 |
{ |
|
939 |
struct net_device *netdev; |
|
940 |
struct e1000_adapter *adapter; |
|
941 |
struct e1000_hw *hw; |
|
942 |
||
943 |
static int cards_found = 0; |
|
944 |
static int global_quad_port_a = 0; /* global ksp3 port a indication */ |
|
945 |
int i, err, pci_using_dac; |
|
946 |
u16 eeprom_data = 0; |
|
947 |
u16 eeprom_apme_mask = E1000_EEPROM_APME; |
|
948 |
int bars, need_ioport; |
|
949 |
DECLARE_MAC_BUF(mac); |
|
950 |
||
951 |
/* do not allocate ioport bars when not needed */ |
|
952 |
need_ioport = e1000_is_need_ioport(pdev); |
|
953 |
if (need_ioport) { |
|
954 |
bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); |
|
955 |
err = pci_enable_device(pdev); |
|
956 |
} else { |
|
957 |
bars = pci_select_bars(pdev, IORESOURCE_MEM); |
|
958 |
err = pci_enable_device_mem(pdev); |
|
959 |
} |
|
960 |
if (err) |
|
961 |
return err; |
|
962 |
||
963 |
if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) && |
|
964 |
!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) { |
|
965 |
pci_using_dac = 1; |
|
966 |
} else { |
|
967 |
err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
|
968 |
if (err) { |
|
969 |
err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
|
970 |
if (err) { |
|
971 |
E1000_ERR("No usable DMA configuration, " |
|
972 |
"aborting\n"); |
|
973 |
goto err_dma; |
|
974 |
} |
|
975 |
} |
|
976 |
pci_using_dac = 0; |
|
977 |
} |
|
978 |
||
979 |
err = pci_request_selected_regions(pdev, bars, e1000_driver_name); |
|
980 |
if (err) |
|
981 |
goto err_pci_reg; |
|
982 |
||
983 |
pci_set_master(pdev); |
|
984 |
||
985 |
err = -ENOMEM; |
|
986 |
netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
|
987 |
if (!netdev) |
|
988 |
goto err_alloc_etherdev; |
|
989 |
||
990 |
SET_NETDEV_DEV(netdev, &pdev->dev); |
|
991 |
||
992 |
pci_set_drvdata(pdev, netdev); |
|
993 |
adapter = netdev_priv(netdev); |
|
994 |
adapter->netdev = netdev; |
|
995 |
adapter->pdev = pdev; |
|
996 |
adapter->msg_enable = (1 << debug) - 1; |
|
997 |
adapter->bars = bars; |
|
998 |
adapter->need_ioport = need_ioport; |
|
999 |
||
1000 |
hw = &adapter->hw; |
|
1001 |
hw->back = adapter; |
|
1002 |
||
1003 |
err = -EIO; |
|
1004 |
hw->hw_addr = ioremap(pci_resource_start(pdev, BAR_0), |
|
1005 |
pci_resource_len(pdev, BAR_0)); |
|
1006 |
if (!hw->hw_addr) |
|
1007 |
goto err_ioremap; |
|
1008 |
||
1009 |
if (adapter->need_ioport) { |
|
1010 |
for (i = BAR_1; i <= BAR_5; i++) { |
|
1011 |
if (pci_resource_len(pdev, i) == 0) |
|
1012 |
continue; |
|
1013 |
if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
|
1014 |
hw->io_base = pci_resource_start(pdev, i); |
|
1015 |
break; |
|
1016 |
} |
|
1017 |
} |
|
1018 |
} |
|
1019 |
||
1020 |
netdev->open = &e1000_open; |
|
1021 |
netdev->stop = &e1000_close; |
|
1022 |
netdev->hard_start_xmit = &e1000_xmit_frame; |
|
1023 |
netdev->get_stats = &e1000_get_stats; |
|
1024 |
netdev->set_rx_mode = &e1000_set_rx_mode; |
|
1025 |
netdev->set_mac_address = &e1000_set_mac; |
|
1026 |
netdev->change_mtu = &e1000_change_mtu; |
|
1027 |
netdev->do_ioctl = &e1000_ioctl; |
|
1028 |
e1000_set_ethtool_ops(netdev); |
|
1029 |
netdev->tx_timeout = &e1000_tx_timeout; |
|
1030 |
netdev->watchdog_timeo = 5 * HZ; |
|
1031 |
netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
|
1032 |
netdev->vlan_rx_register = e1000_vlan_rx_register; |
|
1033 |
netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; |
|
1034 |
netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid; |
|
1035 |
#ifdef CONFIG_NET_POLL_CONTROLLER |
|
1036 |
netdev->poll_controller = e1000_netpoll; |
|
1037 |
#endif |
|
1038 |
strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
|
1039 |
||
1040 |
adapter->bd_number = cards_found; |
|
1041 |
||
1042 |
/* setup the private structure */ |
|
1043 |
||
1044 |
err = e1000_sw_init(adapter); |
|
1045 |
if (err) |
|
1046 |
goto err_sw_init; |
|
1047 |
||
1048 |
err = -EIO; |
|
1049 |
/* Flash BAR mapping must happen after e1000_sw_init |
|
1050 |
* because it depends on mac_type */ |
|
1051 |
if ((hw->mac_type == e1000_ich8lan) && |
|
1052 |
(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
|
1053 |
hw->flash_address = |
|
1054 |
ioremap(pci_resource_start(pdev, 1), |
|
1055 |
pci_resource_len(pdev, 1)); |
|
1056 |
if (!hw->flash_address) |
|
1057 |
goto err_flashmap; |
|
1058 |
} |
|
1059 |
||
1060 |
if (e1000_check_phy_reset_block(hw)) |
|
1061 |
DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); |
|
1062 |
||
1063 |
if (hw->mac_type >= e1000_82543) { |
|
1064 |
netdev->features = NETIF_F_SG | |
|
1065 |
NETIF_F_HW_CSUM | |
|
1066 |
NETIF_F_HW_VLAN_TX | |
|
1067 |
NETIF_F_HW_VLAN_RX | |
|
1068 |
NETIF_F_HW_VLAN_FILTER; |
|
1069 |
if (hw->mac_type == e1000_ich8lan) |
|
1070 |
netdev->features &= ~NETIF_F_HW_VLAN_FILTER; |
|
1071 |
} |
|
1072 |
||
1073 |
if ((hw->mac_type >= e1000_82544) && |
|
1074 |
(hw->mac_type != e1000_82547)) |
|
1075 |
netdev->features |= NETIF_F_TSO; |
|
1076 |
||
1077 |
if (hw->mac_type > e1000_82547_rev_2) |
|
1078 |
netdev->features |= NETIF_F_TSO6; |
|
1079 |
if (pci_using_dac) |
|
1080 |
netdev->features |= NETIF_F_HIGHDMA; |
|
1081 |
||
1082 |
netdev->features |= NETIF_F_LLTX; |
|
1083 |
||
1084 |
adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw); |
|
1085 |
||
1086 |
/* initialize eeprom parameters */ |
|
1087 |
if (e1000_init_eeprom_params(hw)) { |
|
1088 |
E1000_ERR("EEPROM initialization failed\n"); |
|
1089 |
goto err_eeprom; |
|
1090 |
} |
|
1091 |
||
1092 |
/* before reading the EEPROM, reset the controller to |
|
1093 |
* put the device in a known good starting state */ |
|
1094 |
||
1095 |
e1000_reset_hw(hw); |
|
1096 |
||
1097 |
/* make sure the EEPROM is good */ |
|
1098 |
if (e1000_validate_eeprom_checksum(hw) < 0) { |
|
1099 |
DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); |
|
1100 |
e1000_dump_eeprom(adapter); |
|
1101 |
/* |
|
1102 |
* set MAC address to all zeroes to invalidate and temporary |
|
1103 |
* disable this device for the user. This blocks regular |
|
1104 |
* traffic while still permitting ethtool ioctls from reaching |
|
1105 |
* the hardware as well as allowing the user to run the |
|
1106 |
* interface after manually setting a hw addr using |
|
1107 |
* `ip set address` |
|
1108 |
*/ |
|
1109 |
memset(hw->mac_addr, 0, netdev->addr_len); |
|
1110 |
} else { |
|
1111 |
/* copy the MAC address out of the EEPROM */ |
|
1112 |
if (e1000_read_mac_addr(hw)) |
|
1113 |
DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); |
|
1114 |
} |
|
1115 |
/* don't block initalization here due to bad MAC address */ |
|
1116 |
memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len); |
|
1117 |
memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len); |
|
1118 |
||
1119 |
if (!is_valid_ether_addr(netdev->perm_addr)) |
|
1120 |
DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); |
|
1121 |
||
1122 |
e1000_get_bus_info(hw); |
|
1123 |
||
1124 |
init_timer(&adapter->tx_fifo_stall_timer); |
|
1125 |
adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; |
|
1126 |
adapter->tx_fifo_stall_timer.data = (unsigned long)adapter; |
|
1127 |
||
1128 |
init_timer(&adapter->watchdog_timer); |
|
1129 |
adapter->watchdog_timer.function = &e1000_watchdog; |
|
1130 |
adapter->watchdog_timer.data = (unsigned long) adapter; |
|
1131 |
||
1132 |
init_timer(&adapter->phy_info_timer); |
|
1133 |
adapter->phy_info_timer.function = &e1000_update_phy_info; |
|
1134 |
adapter->phy_info_timer.data = (unsigned long)adapter; |
|
1135 |
||
1136 |
INIT_WORK(&adapter->reset_task, e1000_reset_task); |
|
1137 |
||
1138 |
e1000_check_options(adapter); |
|
1139 |
||
1140 |
/* Initial Wake on LAN setting |
|
1141 |
* If APM wake is enabled in the EEPROM, |
|
1142 |
* enable the ACPI Magic Packet filter |
|
1143 |
*/ |
|
1144 |
||
1145 |
switch (hw->mac_type) { |
|
1146 |
case e1000_82542_rev2_0: |
|
1147 |
case e1000_82542_rev2_1: |
|
1148 |
case e1000_82543: |
|
1149 |
break; |
|
1150 |
case e1000_82544: |
|
1151 |
e1000_read_eeprom(hw, |
|
1152 |
EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
|
1153 |
eeprom_apme_mask = E1000_EEPROM_82544_APM; |
|
1154 |
break; |
|
1155 |
case e1000_ich8lan: |
|
1156 |
e1000_read_eeprom(hw, |
|
1157 |
EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data); |
|
1158 |
eeprom_apme_mask = E1000_EEPROM_ICH8_APME; |
|
1159 |
break; |
|
1160 |
case e1000_82546: |
|
1161 |
case e1000_82546_rev_3: |
|
1162 |
case e1000_82571: |
|
1163 |
case e1000_80003es2lan: |
|
1164 |
if (er32(STATUS) & E1000_STATUS_FUNC_1){ |
|
1165 |
e1000_read_eeprom(hw, |
|
1166 |
EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
|
1167 |
break; |
|
1168 |
} |
|
1169 |
/* Fall Through */ |
|
1170 |
default: |
|
1171 |
e1000_read_eeprom(hw, |
|
1172 |
EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
|
1173 |
break; |
|
1174 |
} |
|
1175 |
if (eeprom_data & eeprom_apme_mask) |
|
1176 |
adapter->eeprom_wol |= E1000_WUFC_MAG; |
|
1177 |
||
1178 |
/* now that we have the eeprom settings, apply the special cases |
|
1179 |
* where the eeprom may be wrong or the board simply won't support |
|
1180 |
* wake on lan on a particular port */ |
|
1181 |
switch (pdev->device) { |
|
1182 |
case E1000_DEV_ID_82546GB_PCIE: |
|
1183 |
adapter->eeprom_wol = 0; |
|
1184 |
break; |
|
1185 |
case E1000_DEV_ID_82546EB_FIBER: |
|
1186 |
case E1000_DEV_ID_82546GB_FIBER: |
|
1187 |
case E1000_DEV_ID_82571EB_FIBER: |
|
1188 |
/* Wake events only supported on port A for dual fiber |
|
1189 |
* regardless of eeprom setting */ |
|
1190 |
if (er32(STATUS) & E1000_STATUS_FUNC_1) |
|
1191 |
adapter->eeprom_wol = 0; |
|
1192 |
break; |
|
1193 |
case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
|
1194 |
case E1000_DEV_ID_82571EB_QUAD_COPPER: |
|
1195 |
case E1000_DEV_ID_82571EB_QUAD_FIBER: |
|
1196 |
case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
|
1197 |
case E1000_DEV_ID_82571PT_QUAD_COPPER: |
|
1198 |
/* if quad port adapter, disable WoL on all but port A */ |
|
1199 |
if (global_quad_port_a != 0) |
|
1200 |
adapter->eeprom_wol = 0; |
|
1201 |
else |
|
1202 |
adapter->quad_port_a = 1; |
|
1203 |
/* Reset for multiple quad port adapters */ |
|
1204 |
if (++global_quad_port_a == 4) |
|
1205 |
global_quad_port_a = 0; |
|
1206 |
break; |
|
1207 |
} |
|
1208 |
||
1209 |
/* initialize the wol settings based on the eeprom settings */ |
|
1210 |
adapter->wol = adapter->eeprom_wol; |
|
1211 |
device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
|
1212 |
||
1213 |
/* print bus type/speed/width info */ |
|
1214 |
DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", |
|
1215 |
((hw->bus_type == e1000_bus_type_pcix) ? "-X" : |
|
1216 |
(hw->bus_type == e1000_bus_type_pci_express ? " Express":"")), |
|
1217 |
((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
|
1218 |
(hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : |
|
1219 |
(hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : |
|
1220 |
(hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : |
|
1221 |
(hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), |
|
1222 |
((hw->bus_width == e1000_bus_width_64) ? "64-bit" : |
|
1223 |
(hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" : |
|
1224 |
(hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" : |
|
1225 |
"32-bit")); |
|
1226 |
||
1227 |
printk("%s\n", print_mac(mac, netdev->dev_addr)); |
|
1228 |
||
1229 |
if (hw->bus_type == e1000_bus_type_pci_express) { |
|
1230 |
DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no " |
|
1231 |
"longer be supported by this driver in the future.\n", |
|
1232 |
pdev->vendor, pdev->device); |
|
1233 |
DPRINTK(PROBE, WARNING, "please use the \"e1000e\" " |
|
1234 |
"driver instead.\n"); |
|
1235 |
} |
|
1236 |
||
1237 |
/* reset the hardware with the new settings */ |
|
1238 |
e1000_reset(adapter); |
|
1239 |
||
1240 |
/* If the controller is 82573 and f/w is AMT, do not set |
|
1241 |
* DRV_LOAD until the interface is up. For all other cases, |
|
1242 |
* let the f/w know that the h/w is now under the control |
|
1243 |
* of the driver. */ |
|
1244 |
if (hw->mac_type != e1000_82573 || |
|
1245 |
!e1000_check_mng_mode(hw)) |
|
1246 |
e1000_get_hw_control(adapter); |
|
1247 |
||
1248 |
// offer device to EtherCAT master module |
|
1249 |
adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE); |
|
1250 |
if (adapter->ecdev) { |
|
1251 |
if (ecdev_open(adapter->ecdev)) { |
|
1252 |
ecdev_withdraw(adapter->ecdev); |
|
1253 |
goto err_register; |
|
1254 |
} |
|
1255 |
} else { |
|
1256 |
/* tell the stack to leave us alone until e1000_open() is called */ |
|
1257 |
netif_carrier_off(netdev); |
|
1258 |
netif_stop_queue(netdev); |
|
1259 |
||
1260 |
strcpy(netdev->name, "eth%d"); |
|
1261 |
err = register_netdev(netdev); |
|
1262 |
if (err) |
|
1263 |
goto err_register; |
|
1264 |
} |
|
1265 |
||
1266 |
DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
|
1267 |
||
1268 |
cards_found++; |
|
1269 |
return 0; |
|
1270 |
||
1271 |
err_register: |
|
1272 |
e1000_release_hw_control(adapter); |
|
1273 |
err_eeprom: |
|
1274 |
if (!e1000_check_phy_reset_block(hw)) |
|
1275 |
e1000_phy_hw_reset(hw); |
|
1276 |
||
1277 |
if (hw->flash_address) |
|
1278 |
iounmap(hw->flash_address); |
|
1279 |
err_flashmap: |
|
1280 |
for (i = 0; i < adapter->num_rx_queues; i++) |
|
1281 |
dev_put(&adapter->polling_netdev[i]); |
|
1282 |
||
1283 |
kfree(adapter->tx_ring); |
|
1284 |
kfree(adapter->rx_ring); |
|
1285 |
kfree(adapter->polling_netdev); |
|
1286 |
err_sw_init: |
|
1287 |
iounmap(hw->hw_addr); |
|
1288 |
err_ioremap: |
|
1289 |
free_netdev(netdev); |
|
1290 |
err_alloc_etherdev: |
|
1291 |
pci_release_selected_regions(pdev, bars); |
|
1292 |
err_pci_reg: |
|
1293 |
err_dma: |
|
1294 |
pci_disable_device(pdev); |
|
1295 |
return err; |
|
1296 |
} |
|
1297 |
||
1298 |
/** |
|
1299 |
* e1000_remove - Device Removal Routine |
|
1300 |
* @pdev: PCI device information struct |
|
1301 |
* |
|
1302 |
* e1000_remove is called by the PCI subsystem to alert the driver |
|
1303 |
* that it should release a PCI device. The could be caused by a |
|
1304 |
* Hot-Plug event, or because the driver is going to be removed from |
|
1305 |
* memory. |
|
1306 |
**/ |
|
1307 |
||
1308 |
static void __devexit e1000_remove(struct pci_dev *pdev) |
|
1309 |
{ |
|
1310 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
1311 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1312 |
struct e1000_hw *hw = &adapter->hw; |
|
1313 |
int i; |
|
1314 |
||
1315 |
cancel_work_sync(&adapter->reset_task); |
|
1316 |
||
1317 |
e1000_release_manageability(adapter); |
|
1318 |
||
1319 |
/* Release control of h/w to f/w. If f/w is AMT enabled, this |
|
1320 |
* would have already happened in close and is redundant. */ |
|
1321 |
e1000_release_hw_control(adapter); |
|
1322 |
||
1323 |
for (i = 0; i < adapter->num_rx_queues; i++) |
|
1324 |
dev_put(&adapter->polling_netdev[i]); |
|
1325 |
||
1326 |
if (adapter->ecdev) { |
|
1327 |
ecdev_close(adapter->ecdev); |
|
1328 |
ecdev_withdraw(adapter->ecdev); |
|
1329 |
} else { |
|
1330 |
unregister_netdev(netdev); |
|
1331 |
} |
|
1332 |
||
1333 |
if (!e1000_check_phy_reset_block(hw)) |
|
1334 |
e1000_phy_hw_reset(hw); |
|
1335 |
||
1336 |
kfree(adapter->tx_ring); |
|
1337 |
kfree(adapter->rx_ring); |
|
1338 |
kfree(adapter->polling_netdev); |
|
1339 |
||
1340 |
iounmap(hw->hw_addr); |
|
1341 |
if (hw->flash_address) |
|
1342 |
iounmap(hw->flash_address); |
|
1343 |
pci_release_selected_regions(pdev, adapter->bars); |
|
1344 |
||
1345 |
free_netdev(netdev); |
|
1346 |
||
1347 |
pci_disable_device(pdev); |
|
1348 |
} |
|
1349 |
||
1350 |
/** |
|
1351 |
* e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
|
1352 |
* @adapter: board private structure to initialize |
|
1353 |
* |
|
1354 |
* e1000_sw_init initializes the Adapter private data structure. |
|
1355 |
* Fields are initialized based on PCI device information and |
|
1356 |
* OS network device settings (MTU size). |
|
1357 |
**/ |
|
1358 |
||
1359 |
static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
|
1360 |
{ |
|
1361 |
struct e1000_hw *hw = &adapter->hw; |
|
1362 |
struct net_device *netdev = adapter->netdev; |
|
1363 |
struct pci_dev *pdev = adapter->pdev; |
|
1364 |
int i; |
|
1365 |
||
1366 |
/* PCI config space info */ |
|
1367 |
||
1368 |
hw->vendor_id = pdev->vendor; |
|
1369 |
hw->device_id = pdev->device; |
|
1370 |
hw->subsystem_vendor_id = pdev->subsystem_vendor; |
|
1371 |
hw->subsystem_id = pdev->subsystem_device; |
|
1372 |
hw->revision_id = pdev->revision; |
|
1373 |
||
1374 |
pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
|
1375 |
||
1376 |
adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
|
1377 |
adapter->rx_ps_bsize0 = E1000_RXBUFFER_128; |
|
1378 |
hw->max_frame_size = netdev->mtu + |
|
1379 |
ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
|
1380 |
hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
|
1381 |
||
1382 |
/* identify the MAC */ |
|
1383 |
||
1384 |
if (e1000_set_mac_type(hw)) { |
|
1385 |
DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
|
1386 |
return -EIO; |
|
1387 |
} |
|
1388 |
||
1389 |
switch (hw->mac_type) { |
|
1390 |
default: |
|
1391 |
break; |
|
1392 |
case e1000_82541: |
|
1393 |
case e1000_82547: |
|
1394 |
case e1000_82541_rev_2: |
|
1395 |
case e1000_82547_rev_2: |
|
1396 |
hw->phy_init_script = 1; |
|
1397 |
break; |
|
1398 |
} |
|
1399 |
||
1400 |
e1000_set_media_type(hw); |
|
1401 |
||
1402 |
hw->wait_autoneg_complete = false; |
|
1403 |
hw->tbi_compatibility_en = true; |
|
1404 |
hw->adaptive_ifs = true; |
|
1405 |
||
1406 |
/* Copper options */ |
|
1407 |
||
1408 |
if (hw->media_type == e1000_media_type_copper) { |
|
1409 |
hw->mdix = AUTO_ALL_MODES; |
|
1410 |
hw->disable_polarity_correction = false; |
|
1411 |
hw->master_slave = E1000_MASTER_SLAVE; |
|
1412 |
} |
|
1413 |
||
1414 |
adapter->num_tx_queues = 1; |
|
1415 |
adapter->num_rx_queues = 1; |
|
1416 |
||
1417 |
if (e1000_alloc_queues(adapter)) { |
|
1418 |
DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
|
1419 |
return -ENOMEM; |
|
1420 |
} |
|
1421 |
||
1422 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
|
1423 |
adapter->polling_netdev[i].priv = adapter; |
|
1424 |
dev_hold(&adapter->polling_netdev[i]); |
|
1425 |
set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state); |
|
1426 |
} |
|
1427 |
spin_lock_init(&adapter->tx_queue_lock); |
|
1428 |
||
1429 |
/* Explicitly disable IRQ since the NIC can be in any state. */ |
|
1430 |
e1000_irq_disable(adapter); |
|
1431 |
||
1432 |
spin_lock_init(&adapter->stats_lock); |
|
1433 |
||
1434 |
set_bit(__E1000_DOWN, &adapter->flags); |
|
1435 |
||
1436 |
return 0; |
|
1437 |
} |
|
1438 |
||
1439 |
/** |
|
1440 |
* e1000_alloc_queues - Allocate memory for all rings |
|
1441 |
* @adapter: board private structure to initialize |
|
1442 |
* |
|
1443 |
* We allocate one ring per queue at run-time since we don't know the |
|
1444 |
* number of queues at compile-time. The polling_netdev array is |
|
1445 |
* intended for Multiqueue, but should work fine with a single queue. |
|
1446 |
**/ |
|
1447 |
||
1448 |
static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
|
1449 |
{ |
|
1450 |
adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
|
1451 |
sizeof(struct e1000_tx_ring), GFP_KERNEL); |
|
1452 |
if (!adapter->tx_ring) |
|
1453 |
return -ENOMEM; |
|
1454 |
||
1455 |
adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
|
1456 |
sizeof(struct e1000_rx_ring), GFP_KERNEL); |
|
1457 |
if (!adapter->rx_ring) { |
|
1458 |
kfree(adapter->tx_ring); |
|
1459 |
return -ENOMEM; |
|
1460 |
} |
|
1461 |
||
1462 |
adapter->polling_netdev = kcalloc(adapter->num_rx_queues, |
|
1463 |
sizeof(struct net_device), |
|
1464 |
GFP_KERNEL); |
|
1465 |
if (!adapter->polling_netdev) { |
|
1466 |
kfree(adapter->tx_ring); |
|
1467 |
kfree(adapter->rx_ring); |
|
1468 |
return -ENOMEM; |
|
1469 |
} |
|
1470 |
||
1471 |
return E1000_SUCCESS; |
|
1472 |
} |
|
1473 |
||
1474 |
/** |
|
1475 |
* e1000_open - Called when a network interface is made active |
|
1476 |
* @netdev: network interface device structure |
|
1477 |
* |
|
1478 |
* Returns 0 on success, negative value on failure |
|
1479 |
* |
|
1480 |
* The open entry point is called when a network interface is made |
|
1481 |
* active by the system (IFF_UP). At this point all resources needed |
|
1482 |
* for transmit and receive operations are allocated, the interrupt |
|
1483 |
* handler is registered with the OS, the watchdog timer is started, |
|
1484 |
* and the stack is notified that the interface is ready. |
|
1485 |
**/ |
|
1486 |
||
1487 |
static int e1000_open(struct net_device *netdev) |
|
1488 |
{ |
|
1489 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1490 |
struct e1000_hw *hw = &adapter->hw; |
|
1491 |
int err; |
|
1492 |
||
1493 |
/* disallow open during test */ |
|
1494 |
if (test_bit(__E1000_TESTING, &adapter->flags)) |
|
1495 |
return -EBUSY; |
|
1496 |
||
1497 |
/* allocate transmit descriptors */ |
|
1498 |
err = e1000_setup_all_tx_resources(adapter); |
|
1499 |
if (err) |
|
1500 |
goto err_setup_tx; |
|
1501 |
||
1502 |
/* allocate receive descriptors */ |
|
1503 |
err = e1000_setup_all_rx_resources(adapter); |
|
1504 |
if (err) |
|
1505 |
goto err_setup_rx; |
|
1506 |
||
1507 |
e1000_power_up_phy(adapter); |
|
1508 |
||
1509 |
adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
|
1510 |
if ((hw->mng_cookie.status & |
|
1511 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
|
1512 |
e1000_update_mng_vlan(adapter); |
|
1513 |
} |
|
1514 |
||
1515 |
/* If AMT is enabled, let the firmware know that the network |
|
1516 |
* interface is now open */ |
|
1517 |
if (hw->mac_type == e1000_82573 && |
|
1518 |
e1000_check_mng_mode(hw)) |
|
1519 |
e1000_get_hw_control(adapter); |
|
1520 |
||
1521 |
/* before we allocate an interrupt, we must be ready to handle it. |
|
1522 |
* Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
|
1523 |
* as soon as we call pci_request_irq, so we have to setup our |
|
1524 |
* clean_rx handler before we do so. */ |
|
1525 |
e1000_configure(adapter); |
|
1526 |
||
1527 |
err = e1000_request_irq(adapter); |
|
1528 |
if (err) |
|
1529 |
goto err_req_irq; |
|
1530 |
||
1531 |
/* From here on the code is the same as e1000_up() */ |
|
1532 |
clear_bit(__E1000_DOWN, &adapter->flags); |
|
1533 |
||
1534 |
napi_enable(&adapter->napi); |
|
1535 |
||
1536 |
e1000_irq_enable(adapter); |
|
1537 |
||
1538 |
netif_start_queue(netdev); |
|
1539 |
||
1540 |
/* fire a link status change interrupt to start the watchdog */ |
|
1541 |
ew32(ICS, E1000_ICS_LSC); |
|
1542 |
||
1543 |
return E1000_SUCCESS; |
|
1544 |
||
1545 |
err_req_irq: |
|
1546 |
e1000_release_hw_control(adapter); |
|
1547 |
e1000_power_down_phy(adapter); |
|
1548 |
e1000_free_all_rx_resources(adapter); |
|
1549 |
err_setup_rx: |
|
1550 |
e1000_free_all_tx_resources(adapter); |
|
1551 |
err_setup_tx: |
|
1552 |
e1000_reset(adapter); |
|
1553 |
||
1554 |
return err; |
|
1555 |
} |
|
1556 |
||
1557 |
/** |
|
1558 |
* e1000_close - Disables a network interface |
|
1559 |
* @netdev: network interface device structure |
|
1560 |
* |
|
1561 |
* Returns 0, this is not allowed to fail |
|
1562 |
* |
|
1563 |
* The close entry point is called when an interface is de-activated |
|
1564 |
* by the OS. The hardware is still under the drivers control, but |
|
1565 |
* needs to be disabled. A global MAC reset is issued to stop the |
|
1566 |
* hardware, and all transmit and receive resources are freed. |
|
1567 |
**/ |
|
1568 |
||
1569 |
static int e1000_close(struct net_device *netdev) |
|
1570 |
{ |
|
1571 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1572 |
struct e1000_hw *hw = &adapter->hw; |
|
1573 |
||
1574 |
WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
|
1575 |
e1000_down(adapter); |
|
1576 |
e1000_power_down_phy(adapter); |
|
1577 |
e1000_free_irq(adapter); |
|
1578 |
||
1579 |
e1000_free_all_tx_resources(adapter); |
|
1580 |
e1000_free_all_rx_resources(adapter); |
|
1581 |
||
1582 |
/* kill manageability vlan ID if supported, but not if a vlan with |
|
1583 |
* the same ID is registered on the host OS (let 8021q kill it) */ |
|
1584 |
if ((hw->mng_cookie.status & |
|
1585 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
|
1586 |
!(adapter->vlgrp && |
|
1587 |
vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) { |
|
1588 |
e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
|
1589 |
} |
|
1590 |
||
1591 |
/* If AMT is enabled, let the firmware know that the network |
|
1592 |
* interface is now closed */ |
|
1593 |
if (hw->mac_type == e1000_82573 && |
|
1594 |
e1000_check_mng_mode(hw)) |
|
1595 |
e1000_release_hw_control(adapter); |
|
1596 |
||
1597 |
return 0; |
|
1598 |
} |
|
1599 |
||
1600 |
/** |
|
1601 |
* e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
|
1602 |
* @adapter: address of board private structure |
|
1603 |
* @start: address of beginning of memory |
|
1604 |
* @len: length of memory |
|
1605 |
**/ |
|
1606 |
static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start, |
|
1607 |
unsigned long len) |
|
1608 |
{ |
|
1609 |
struct e1000_hw *hw = &adapter->hw; |
|
1610 |
unsigned long begin = (unsigned long)start; |
|
1611 |
unsigned long end = begin + len; |
|
1612 |
||
1613 |
/* First rev 82545 and 82546 need to not allow any memory |
|
1614 |
* write location to cross 64k boundary due to errata 23 */ |
|
1615 |
if (hw->mac_type == e1000_82545 || |
|
1616 |
hw->mac_type == e1000_82546) { |
|
1617 |
return ((begin ^ (end - 1)) >> 16) != 0 ? false : true; |
|
1618 |
} |
|
1619 |
||
1620 |
return true; |
|
1621 |
} |
|
1622 |
||
1623 |
/** |
|
1624 |
* e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
|
1625 |
* @adapter: board private structure |
|
1626 |
* @txdr: tx descriptor ring (for a specific queue) to setup |
|
1627 |
* |
|
1628 |
* Return 0 on success, negative on failure |
|
1629 |
**/ |
|
1630 |
||
1631 |
static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
|
1632 |
struct e1000_tx_ring *txdr) |
|
1633 |
{ |
|
1634 |
struct pci_dev *pdev = adapter->pdev; |
|
1635 |
int size; |
|
1636 |
||
1637 |
size = sizeof(struct e1000_buffer) * txdr->count; |
|
1638 |
txdr->buffer_info = vmalloc(size); |
|
1639 |
if (!txdr->buffer_info) { |
|
1640 |
DPRINTK(PROBE, ERR, |
|
1641 |
"Unable to allocate memory for the transmit descriptor ring\n"); |
|
1642 |
return -ENOMEM; |
|
1643 |
} |
|
1644 |
memset(txdr->buffer_info, 0, size); |
|
1645 |
||
1646 |
/* round up to nearest 4K */ |
|
1647 |
||
1648 |
txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
|
1649 |
txdr->size = ALIGN(txdr->size, 4096); |
|
1650 |
||
1651 |
txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
|
1652 |
if (!txdr->desc) { |
|
1653 |
setup_tx_desc_die: |
|
1654 |
vfree(txdr->buffer_info); |
|
1655 |
DPRINTK(PROBE, ERR, |
|
1656 |
"Unable to allocate memory for the transmit descriptor ring\n"); |
|
1657 |
return -ENOMEM; |
|
1658 |
} |
|
1659 |
||
1660 |
/* Fix for errata 23, can't cross 64kB boundary */ |
|
1661 |
if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
|
1662 |
void *olddesc = txdr->desc; |
|
1663 |
dma_addr_t olddma = txdr->dma; |
|
1664 |
DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
|
1665 |
"at %p\n", txdr->size, txdr->desc); |
|
1666 |
/* Try again, without freeing the previous */ |
|
1667 |
txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
|
1668 |
/* Failed allocation, critical failure */ |
|
1669 |
if (!txdr->desc) { |
|
1670 |
pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
|
1671 |
goto setup_tx_desc_die; |
|
1672 |
} |
|
1673 |
||
1674 |
if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
|
1675 |
/* give up */ |
|
1676 |
pci_free_consistent(pdev, txdr->size, txdr->desc, |
|
1677 |
txdr->dma); |
|
1678 |
pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
|
1679 |
DPRINTK(PROBE, ERR, |
|
1680 |
"Unable to allocate aligned memory " |
|
1681 |
"for the transmit descriptor ring\n"); |
|
1682 |
vfree(txdr->buffer_info); |
|
1683 |
return -ENOMEM; |
|
1684 |
} else { |
|
1685 |
/* Free old allocation, new allocation was successful */ |
|
1686 |
pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
|
1687 |
} |
|
1688 |
} |
|
1689 |
memset(txdr->desc, 0, txdr->size); |
|
1690 |
||
1691 |
txdr->next_to_use = 0; |
|
1692 |
txdr->next_to_clean = 0; |
|
1693 |
spin_lock_init(&txdr->tx_lock); |
|
1694 |
||
1695 |
return 0; |
|
1696 |
} |
|
1697 |
||
1698 |
/** |
|
1699 |
* e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
|
1700 |
* (Descriptors) for all queues |
|
1701 |
* @adapter: board private structure |
|
1702 |
* |
|
1703 |
* Return 0 on success, negative on failure |
|
1704 |
**/ |
|
1705 |
||
1706 |
int e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
|
1707 |
{ |
|
1708 |
int i, err = 0; |
|
1709 |
||
1710 |
for (i = 0; i < adapter->num_tx_queues; i++) { |
|
1711 |
err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
|
1712 |
if (err) { |
|
1713 |
DPRINTK(PROBE, ERR, |
|
1714 |
"Allocation for Tx Queue %u failed\n", i); |
|
1715 |
for (i-- ; i >= 0; i--) |
|
1716 |
e1000_free_tx_resources(adapter, |
|
1717 |
&adapter->tx_ring[i]); |
|
1718 |
break; |
|
1719 |
} |
|
1720 |
} |
|
1721 |
||
1722 |
return err; |
|
1723 |
} |
|
1724 |
||
1725 |
/** |
|
1726 |
* e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
|
1727 |
* @adapter: board private structure |
|
1728 |
* |
|
1729 |
* Configure the Tx unit of the MAC after a reset. |
|
1730 |
**/ |
|
1731 |
||
1732 |
static void e1000_configure_tx(struct e1000_adapter *adapter) |
|
1733 |
{ |
|
1734 |
u64 tdba; |
|
1735 |
struct e1000_hw *hw = &adapter->hw; |
|
1736 |
u32 tdlen, tctl, tipg, tarc; |
|
1737 |
u32 ipgr1, ipgr2; |
|
1738 |
||
1739 |
/* Setup the HW Tx Head and Tail descriptor pointers */ |
|
1740 |
||
1741 |
switch (adapter->num_tx_queues) { |
|
1742 |
case 1: |
|
1743 |
default: |
|
1744 |
tdba = adapter->tx_ring[0].dma; |
|
1745 |
tdlen = adapter->tx_ring[0].count * |
|
1746 |
sizeof(struct e1000_tx_desc); |
|
1747 |
ew32(TDLEN, tdlen); |
|
1748 |
ew32(TDBAH, (tdba >> 32)); |
|
1749 |
ew32(TDBAL, (tdba & 0x00000000ffffffffULL)); |
|
1750 |
ew32(TDT, 0); |
|
1751 |
ew32(TDH, 0); |
|
1752 |
adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); |
|
1753 |
adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT); |
|
1754 |
break; |
|
1755 |
} |
|
1756 |
||
1757 |
/* Set the default values for the Tx Inter Packet Gap timer */ |
|
1758 |
if (hw->mac_type <= e1000_82547_rev_2 && |
|
1759 |
(hw->media_type == e1000_media_type_fiber || |
|
1760 |
hw->media_type == e1000_media_type_internal_serdes)) |
|
1761 |
tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
|
1762 |
else |
|
1763 |
tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
|
1764 |
||
1765 |
switch (hw->mac_type) { |
|
1766 |
case e1000_82542_rev2_0: |
|
1767 |
case e1000_82542_rev2_1: |
|
1768 |
tipg = DEFAULT_82542_TIPG_IPGT; |
|
1769 |
ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
|
1770 |
ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
|
1771 |
break; |
|
1772 |
case e1000_80003es2lan: |
|
1773 |
ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
|
1774 |
ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
|
1775 |
break; |
|
1776 |
default: |
|
1777 |
ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
|
1778 |
ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
|
1779 |
break; |
|
1780 |
} |
|
1781 |
tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
|
1782 |
tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
|
1783 |
ew32(TIPG, tipg); |
|
1784 |
||
1785 |
/* Set the Tx Interrupt Delay register */ |
|
1786 |
||
1787 |
ew32(TIDV, adapter->tx_int_delay); |
|
1788 |
if (hw->mac_type >= e1000_82540) |
|
1789 |
ew32(TADV, adapter->tx_abs_int_delay); |
|
1790 |
||
1791 |
/* Program the Transmit Control Register */ |
|
1792 |
||
1793 |
tctl = er32(TCTL); |
|
1794 |
tctl &= ~E1000_TCTL_CT; |
|
1795 |
tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
|
1796 |
(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
|
1797 |
||
1798 |
if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
|
1799 |
tarc = er32(TARC0); |
|
1800 |
/* set the speed mode bit, we'll clear it if we're not at |
|
1801 |
* gigabit link later */ |
|
1802 |
tarc |= (1 << 21); |
|
1803 |
ew32(TARC0, tarc); |
|
1804 |
} else if (hw->mac_type == e1000_80003es2lan) { |
|
1805 |
tarc = er32(TARC0); |
|
1806 |
tarc |= 1; |
|
1807 |
ew32(TARC0, tarc); |
|
1808 |
tarc = er32(TARC1); |
|
1809 |
tarc |= 1; |
|
1810 |
ew32(TARC1, tarc); |
|
1811 |
} |
|
1812 |
||
1813 |
e1000_config_collision_dist(hw); |
|
1814 |
||
1815 |
/* Setup Transmit Descriptor Settings for eop descriptor */ |
|
1816 |
adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
|
1817 |
||
1818 |
/* only set IDE if we are delaying interrupts using the timers */ |
|
1819 |
if (adapter->tx_int_delay) |
|
1820 |
adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
|
1821 |
||
1822 |
if (hw->mac_type < e1000_82543) |
|
1823 |
adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
|
1824 |
else |
|
1825 |
adapter->txd_cmd |= E1000_TXD_CMD_RS; |
|
1826 |
||
1827 |
/* Cache if we're 82544 running in PCI-X because we'll |
|
1828 |
* need this to apply a workaround later in the send path. */ |
|
1829 |
if (hw->mac_type == e1000_82544 && |
|
1830 |
hw->bus_type == e1000_bus_type_pcix) |
|
1831 |
adapter->pcix_82544 = 1; |
|
1832 |
||
1833 |
ew32(TCTL, tctl); |
|
1834 |
||
1835 |
} |
|
1836 |
||
1837 |
/** |
|
1838 |
* e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
|
1839 |
* @adapter: board private structure |
|
1840 |
* @rxdr: rx descriptor ring (for a specific queue) to setup |
|
1841 |
* |
|
1842 |
* Returns 0 on success, negative on failure |
|
1843 |
**/ |
|
1844 |
||
1845 |
static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
|
1846 |
struct e1000_rx_ring *rxdr) |
|
1847 |
{ |
|
1848 |
struct e1000_hw *hw = &adapter->hw; |
|
1849 |
struct pci_dev *pdev = adapter->pdev; |
|
1850 |
int size, desc_len; |
|
1851 |
||
1852 |
size = sizeof(struct e1000_buffer) * rxdr->count; |
|
1853 |
rxdr->buffer_info = vmalloc(size); |
|
1854 |
if (!rxdr->buffer_info) { |
|
1855 |
DPRINTK(PROBE, ERR, |
|
1856 |
"Unable to allocate memory for the receive descriptor ring\n"); |
|
1857 |
return -ENOMEM; |
|
1858 |
} |
|
1859 |
memset(rxdr->buffer_info, 0, size); |
|
1860 |
||
1861 |
rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page), |
|
1862 |
GFP_KERNEL); |
|
1863 |
if (!rxdr->ps_page) { |
|
1864 |
vfree(rxdr->buffer_info); |
|
1865 |
DPRINTK(PROBE, ERR, |
|
1866 |
"Unable to allocate memory for the receive descriptor ring\n"); |
|
1867 |
return -ENOMEM; |
|
1868 |
} |
|
1869 |
||
1870 |
rxdr->ps_page_dma = kcalloc(rxdr->count, |
|
1871 |
sizeof(struct e1000_ps_page_dma), |
|
1872 |
GFP_KERNEL); |
|
1873 |
if (!rxdr->ps_page_dma) { |
|
1874 |
vfree(rxdr->buffer_info); |
|
1875 |
kfree(rxdr->ps_page); |
|
1876 |
DPRINTK(PROBE, ERR, |
|
1877 |
"Unable to allocate memory for the receive descriptor ring\n"); |
|
1878 |
return -ENOMEM; |
|
1879 |
} |
|
1880 |
||
1881 |
if (hw->mac_type <= e1000_82547_rev_2) |
|
1882 |
desc_len = sizeof(struct e1000_rx_desc); |
|
1883 |
else |
|
1884 |
desc_len = sizeof(union e1000_rx_desc_packet_split); |
|
1885 |
||
1886 |
/* Round up to nearest 4K */ |
|
1887 |
||
1888 |
rxdr->size = rxdr->count * desc_len; |
|
1889 |
rxdr->size = ALIGN(rxdr->size, 4096); |
|
1890 |
||
1891 |
rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
|
1892 |
||
1893 |
if (!rxdr->desc) { |
|
1894 |
DPRINTK(PROBE, ERR, |
|
1895 |
"Unable to allocate memory for the receive descriptor ring\n"); |
|
1896 |
setup_rx_desc_die: |
|
1897 |
vfree(rxdr->buffer_info); |
|
1898 |
kfree(rxdr->ps_page); |
|
1899 |
kfree(rxdr->ps_page_dma); |
|
1900 |
return -ENOMEM; |
|
1901 |
} |
|
1902 |
||
1903 |
/* Fix for errata 23, can't cross 64kB boundary */ |
|
1904 |
if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
|
1905 |
void *olddesc = rxdr->desc; |
|
1906 |
dma_addr_t olddma = rxdr->dma; |
|
1907 |
DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
|
1908 |
"at %p\n", rxdr->size, rxdr->desc); |
|
1909 |
/* Try again, without freeing the previous */ |
|
1910 |
rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
|
1911 |
/* Failed allocation, critical failure */ |
|
1912 |
if (!rxdr->desc) { |
|
1913 |
pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
|
1914 |
DPRINTK(PROBE, ERR, |
|
1915 |
"Unable to allocate memory " |
|
1916 |
"for the receive descriptor ring\n"); |
|
1917 |
goto setup_rx_desc_die; |
|
1918 |
} |
|
1919 |
||
1920 |
if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
|
1921 |
/* give up */ |
|
1922 |
pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
|
1923 |
rxdr->dma); |
|
1924 |
pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
|
1925 |
DPRINTK(PROBE, ERR, |
|
1926 |
"Unable to allocate aligned memory " |
|
1927 |
"for the receive descriptor ring\n"); |
|
1928 |
goto setup_rx_desc_die; |
|
1929 |
} else { |
|
1930 |
/* Free old allocation, new allocation was successful */ |
|
1931 |
pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
|
1932 |
} |
|
1933 |
} |
|
1934 |
memset(rxdr->desc, 0, rxdr->size); |
|
1935 |
||
1936 |
rxdr->next_to_clean = 0; |
|
1937 |
rxdr->next_to_use = 0; |
|
1938 |
||
1939 |
return 0; |
|
1940 |
} |
|
1941 |
||
1942 |
/** |
|
1943 |
* e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
|
1944 |
* (Descriptors) for all queues |
|
1945 |
* @adapter: board private structure |
|
1946 |
* |
|
1947 |
* Return 0 on success, negative on failure |
|
1948 |
**/ |
|
1949 |
||
1950 |
int e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
|
1951 |
{ |
|
1952 |
int i, err = 0; |
|
1953 |
||
1954 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
|
1955 |
err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
|
1956 |
if (err) { |
|
1957 |
DPRINTK(PROBE, ERR, |
|
1958 |
"Allocation for Rx Queue %u failed\n", i); |
|
1959 |
for (i-- ; i >= 0; i--) |
|
1960 |
e1000_free_rx_resources(adapter, |
|
1961 |
&adapter->rx_ring[i]); |
|
1962 |
break; |
|
1963 |
} |
|
1964 |
} |
|
1965 |
||
1966 |
return err; |
|
1967 |
} |
|
1968 |
||
1969 |
/** |
|
1970 |
* e1000_setup_rctl - configure the receive control registers |
|
1971 |
* @adapter: Board private structure |
|
1972 |
**/ |
|
1973 |
#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
|
1974 |
(((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
|
1975 |
static void e1000_setup_rctl(struct e1000_adapter *adapter) |
|
1976 |
{ |
|
1977 |
struct e1000_hw *hw = &adapter->hw; |
|
1978 |
u32 rctl, rfctl; |
|
1979 |
u32 psrctl = 0; |
|
1980 |
#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
|
1981 |
u32 pages = 0; |
|
1982 |
#endif |
|
1983 |
||
1984 |
rctl = er32(RCTL); |
|
1985 |
||
1986 |
rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
|
1987 |
||
1988 |
rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
|
1989 |
E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
|
1990 |
(hw->mc_filter_type << E1000_RCTL_MO_SHIFT); |
|
1991 |
||
1992 |
if (hw->tbi_compatibility_on == 1) |
|
1993 |
rctl |= E1000_RCTL_SBP; |
|
1994 |
else |
|
1995 |
rctl &= ~E1000_RCTL_SBP; |
|
1996 |
||
1997 |
if (adapter->netdev->mtu <= ETH_DATA_LEN) |
|
1998 |
rctl &= ~E1000_RCTL_LPE; |
|
1999 |
else |
|
2000 |
rctl |= E1000_RCTL_LPE; |
|
2001 |
||
2002 |
/* Setup buffer sizes */ |
|
2003 |
rctl &= ~E1000_RCTL_SZ_4096; |
|
2004 |
rctl |= E1000_RCTL_BSEX; |
|
2005 |
switch (adapter->rx_buffer_len) { |
|
2006 |
case E1000_RXBUFFER_256: |
|
2007 |
rctl |= E1000_RCTL_SZ_256; |
|
2008 |
rctl &= ~E1000_RCTL_BSEX; |
|
2009 |
break; |
|
2010 |
case E1000_RXBUFFER_512: |
|
2011 |
rctl |= E1000_RCTL_SZ_512; |
|
2012 |
rctl &= ~E1000_RCTL_BSEX; |
|
2013 |
break; |
|
2014 |
case E1000_RXBUFFER_1024: |
|
2015 |
rctl |= E1000_RCTL_SZ_1024; |
|
2016 |
rctl &= ~E1000_RCTL_BSEX; |
|
2017 |
break; |
|
2018 |
case E1000_RXBUFFER_2048: |
|
2019 |
default: |
|
2020 |
rctl |= E1000_RCTL_SZ_2048; |
|
2021 |
rctl &= ~E1000_RCTL_BSEX; |
|
2022 |
break; |
|
2023 |
case E1000_RXBUFFER_4096: |
|
2024 |
rctl |= E1000_RCTL_SZ_4096; |
|
2025 |
break; |
|
2026 |
case E1000_RXBUFFER_8192: |
|
2027 |
rctl |= E1000_RCTL_SZ_8192; |
|
2028 |
break; |
|
2029 |
case E1000_RXBUFFER_16384: |
|
2030 |
rctl |= E1000_RCTL_SZ_16384; |
|
2031 |
break; |
|
2032 |
} |
|
2033 |
||
2034 |
#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
|
2035 |
/* 82571 and greater support packet-split where the protocol |
|
2036 |
* header is placed in skb->data and the packet data is |
|
2037 |
* placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
|
2038 |
* In the case of a non-split, skb->data is linearly filled, |
|
2039 |
* followed by the page buffers. Therefore, skb->data is |
|
2040 |
* sized to hold the largest protocol header. |
|
2041 |
*/ |
|
2042 |
/* allocations using alloc_page take too long for regular MTU |
|
2043 |
* so only enable packet split for jumbo frames */ |
|
2044 |
pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
|
2045 |
if ((hw->mac_type >= e1000_82571) && (pages <= 3) && |
|
2046 |
PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE)) |
|
2047 |
adapter->rx_ps_pages = pages; |
|
2048 |
else |
|
2049 |
adapter->rx_ps_pages = 0; |
|
2050 |
#endif |
|
2051 |
if (adapter->rx_ps_pages) { |
|
2052 |
/* Configure extra packet-split registers */ |
|
2053 |
rfctl = er32(RFCTL); |
|
2054 |
rfctl |= E1000_RFCTL_EXTEN; |
|
2055 |
/* disable packet split support for IPv6 extension headers, |
|
2056 |
* because some malformed IPv6 headers can hang the RX */ |
|
2057 |
rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
|
2058 |
E1000_RFCTL_NEW_IPV6_EXT_DIS); |
|
2059 |
||
2060 |
ew32(RFCTL, rfctl); |
|
2061 |
||
2062 |
rctl |= E1000_RCTL_DTYP_PS; |
|
2063 |
||
2064 |
psrctl |= adapter->rx_ps_bsize0 >> |
|
2065 |
E1000_PSRCTL_BSIZE0_SHIFT; |
|
2066 |
||
2067 |
switch (adapter->rx_ps_pages) { |
|
2068 |
case 3: |
|
2069 |
psrctl |= PAGE_SIZE << |
|
2070 |
E1000_PSRCTL_BSIZE3_SHIFT; |
|
2071 |
case 2: |
|
2072 |
psrctl |= PAGE_SIZE << |
|
2073 |
E1000_PSRCTL_BSIZE2_SHIFT; |
|
2074 |
case 1: |
|
2075 |
psrctl |= PAGE_SIZE >> |
|
2076 |
E1000_PSRCTL_BSIZE1_SHIFT; |
|
2077 |
break; |
|
2078 |
} |
|
2079 |
||
2080 |
ew32(PSRCTL, psrctl); |
|
2081 |
} |
|
2082 |
||
2083 |
ew32(RCTL, rctl); |
|
2084 |
} |
|
2085 |
||
2086 |
/** |
|
2087 |
* e1000_configure_rx - Configure 8254x Receive Unit after Reset |
|
2088 |
* @adapter: board private structure |
|
2089 |
* |
|
2090 |
* Configure the Rx unit of the MAC after a reset. |
|
2091 |
**/ |
|
2092 |
||
2093 |
static void e1000_configure_rx(struct e1000_adapter *adapter) |
|
2094 |
{ |
|
2095 |
u64 rdba; |
|
2096 |
struct e1000_hw *hw = &adapter->hw; |
|
2097 |
u32 rdlen, rctl, rxcsum, ctrl_ext; |
|
2098 |
||
2099 |
if (adapter->rx_ps_pages) { |
|
2100 |
/* this is a 32 byte descriptor */ |
|
2101 |
rdlen = adapter->rx_ring[0].count * |
|
2102 |
sizeof(union e1000_rx_desc_packet_split); |
|
2103 |
adapter->clean_rx = e1000_clean_rx_irq_ps; |
|
2104 |
adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
|
2105 |
} else { |
|
2106 |
rdlen = adapter->rx_ring[0].count * |
|
2107 |
sizeof(struct e1000_rx_desc); |
|
2108 |
adapter->clean_rx = e1000_clean_rx_irq; |
|
2109 |
adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
|
2110 |
} |
|
2111 |
||
2112 |
/* disable receives while setting up the descriptors */ |
|
2113 |
rctl = er32(RCTL); |
|
2114 |
ew32(RCTL, rctl & ~E1000_RCTL_EN); |
|
2115 |
||
2116 |
/* set the Receive Delay Timer Register */ |
|
2117 |
ew32(RDTR, adapter->rx_int_delay); |
|
2118 |
||
2119 |
if (hw->mac_type >= e1000_82540) { |
|
2120 |
ew32(RADV, adapter->rx_abs_int_delay); |
|
2121 |
if (adapter->itr_setting != 0) |
|
2122 |
ew32(ITR, 1000000000 / (adapter->itr * 256)); |
|
2123 |
} |
|
2124 |
||
2125 |
if (hw->mac_type >= e1000_82571) { |
|
2126 |
ctrl_ext = er32(CTRL_EXT); |
|
2127 |
/* Reset delay timers after every interrupt */ |
|
2128 |
ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
|
2129 |
/* Auto-Mask interrupts upon ICR access */ |
|
2130 |
ctrl_ext |= E1000_CTRL_EXT_IAME; |
|
2131 |
ew32(IAM, 0xffffffff); |
|
2132 |
ew32(CTRL_EXT, ctrl_ext); |
|
2133 |
E1000_WRITE_FLUSH(); |
|
2134 |
} |
|
2135 |
||
2136 |
/* Setup the HW Rx Head and Tail Descriptor Pointers and |
|
2137 |
* the Base and Length of the Rx Descriptor Ring */ |
|
2138 |
switch (adapter->num_rx_queues) { |
|
2139 |
case 1: |
|
2140 |
default: |
|
2141 |
rdba = adapter->rx_ring[0].dma; |
|
2142 |
ew32(RDLEN, rdlen); |
|
2143 |
ew32(RDBAH, (rdba >> 32)); |
|
2144 |
ew32(RDBAL, (rdba & 0x00000000ffffffffULL)); |
|
2145 |
ew32(RDT, 0); |
|
2146 |
ew32(RDH, 0); |
|
2147 |
adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); |
|
2148 |
adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT); |
|
2149 |
break; |
|
2150 |
} |
|
2151 |
||
2152 |
/* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
|
2153 |
if (hw->mac_type >= e1000_82543) { |
|
2154 |
rxcsum = er32(RXCSUM); |
|
2155 |
if (adapter->rx_csum) { |
|
2156 |
rxcsum |= E1000_RXCSUM_TUOFL; |
|
2157 |
||
2158 |
/* Enable 82571 IPv4 payload checksum for UDP fragments |
|
2159 |
* Must be used in conjunction with packet-split. */ |
|
2160 |
if ((hw->mac_type >= e1000_82571) && |
|
2161 |
(adapter->rx_ps_pages)) { |
|
2162 |
rxcsum |= E1000_RXCSUM_IPPCSE; |
|
2163 |
} |
|
2164 |
} else { |
|
2165 |
rxcsum &= ~E1000_RXCSUM_TUOFL; |
|
2166 |
/* don't need to clear IPPCSE as it defaults to 0 */ |
|
2167 |
} |
|
2168 |
ew32(RXCSUM, rxcsum); |
|
2169 |
} |
|
2170 |
||
2171 |
/* enable early receives on 82573, only takes effect if using > 2048 |
|
2172 |
* byte total frame size. for example only for jumbo frames */ |
|
2173 |
#define E1000_ERT_2048 0x100 |
|
2174 |
if (hw->mac_type == e1000_82573) |
|
2175 |
ew32(ERT, E1000_ERT_2048); |
|
2176 |
||
2177 |
/* Enable Receives */ |
|
2178 |
ew32(RCTL, rctl); |
|
2179 |
} |
|
2180 |
||
2181 |
/** |
|
2182 |
* e1000_free_tx_resources - Free Tx Resources per Queue |
|
2183 |
* @adapter: board private structure |
|
2184 |
* @tx_ring: Tx descriptor ring for a specific queue |
|
2185 |
* |
|
2186 |
* Free all transmit software resources |
|
2187 |
**/ |
|
2188 |
||
2189 |
static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
|
2190 |
struct e1000_tx_ring *tx_ring) |
|
2191 |
{ |
|
2192 |
struct pci_dev *pdev = adapter->pdev; |
|
2193 |
||
2194 |
e1000_clean_tx_ring(adapter, tx_ring); |
|
2195 |
||
2196 |
vfree(tx_ring->buffer_info); |
|
2197 |
tx_ring->buffer_info = NULL; |
|
2198 |
||
2199 |
pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
|
2200 |
||
2201 |
tx_ring->desc = NULL; |
|
2202 |
} |
|
2203 |
||
2204 |
/** |
|
2205 |
* e1000_free_all_tx_resources - Free Tx Resources for All Queues |
|
2206 |
* @adapter: board private structure |
|
2207 |
* |
|
2208 |
* Free all transmit software resources |
|
2209 |
**/ |
|
2210 |
||
2211 |
void e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
|
2212 |
{ |
|
2213 |
int i; |
|
2214 |
||
2215 |
for (i = 0; i < adapter->num_tx_queues; i++) |
|
2216 |
e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
|
2217 |
} |
|
2218 |
||
2219 |
static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
|
2220 |
struct e1000_buffer *buffer_info) |
|
2221 |
{ |
|
2222 |
if (adapter->ecdev) |
|
2223 |
return; |
|
2224 |
||
2225 |
if (buffer_info->dma) { |
|
2226 |
pci_unmap_page(adapter->pdev, |
|
2227 |
buffer_info->dma, |
|
2228 |
buffer_info->length, |
|
2229 |
PCI_DMA_TODEVICE); |
|
2230 |
buffer_info->dma = 0; |
|
2231 |
} |
|
2232 |
if (buffer_info->skb) { |
|
2233 |
dev_kfree_skb_any(buffer_info->skb); |
|
2234 |
buffer_info->skb = NULL; |
|
2235 |
} |
|
2236 |
/* buffer_info must be completely set up in the transmit path */ |
|
2237 |
} |
|
2238 |
||
2239 |
/** |
|
2240 |
* e1000_clean_tx_ring - Free Tx Buffers |
|
2241 |
* @adapter: board private structure |
|
2242 |
* @tx_ring: ring to be cleaned |
|
2243 |
**/ |
|
2244 |
||
2245 |
static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
|
2246 |
struct e1000_tx_ring *tx_ring) |
|
2247 |
{ |
|
2248 |
struct e1000_hw *hw = &adapter->hw; |
|
2249 |
struct e1000_buffer *buffer_info; |
|
2250 |
unsigned long size; |
|
2251 |
unsigned int i; |
|
2252 |
||
2253 |
/* Free all the Tx ring sk_buffs */ |
|
2254 |
||
2255 |
for (i = 0; i < tx_ring->count; i++) { |
|
2256 |
buffer_info = &tx_ring->buffer_info[i]; |
|
2257 |
e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
|
2258 |
} |
|
2259 |
||
2260 |
size = sizeof(struct e1000_buffer) * tx_ring->count; |
|
2261 |
memset(tx_ring->buffer_info, 0, size); |
|
2262 |
||
2263 |
/* Zero out the descriptor ring */ |
|
2264 |
||
2265 |
memset(tx_ring->desc, 0, tx_ring->size); |
|
2266 |
||
2267 |
tx_ring->next_to_use = 0; |
|
2268 |
tx_ring->next_to_clean = 0; |
|
2269 |
tx_ring->last_tx_tso = 0; |
|
2270 |
||
2271 |
writel(0, hw->hw_addr + tx_ring->tdh); |
|
2272 |
writel(0, hw->hw_addr + tx_ring->tdt); |
|
2273 |
} |
|
2274 |
||
2275 |
/** |
|
2276 |
* e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
|
2277 |
* @adapter: board private structure |
|
2278 |
**/ |
|
2279 |
||
2280 |
static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
|
2281 |
{ |
|
2282 |
int i; |
|
2283 |
||
2284 |
for (i = 0; i < adapter->num_tx_queues; i++) |
|
2285 |
e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
|
2286 |
} |
|
2287 |
||
2288 |
/** |
|
2289 |
* e1000_free_rx_resources - Free Rx Resources |
|
2290 |
* @adapter: board private structure |
|
2291 |
* @rx_ring: ring to clean the resources from |
|
2292 |
* |
|
2293 |
* Free all receive software resources |
|
2294 |
**/ |
|
2295 |
||
2296 |
static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
|
2297 |
struct e1000_rx_ring *rx_ring) |
|
2298 |
{ |
|
2299 |
struct pci_dev *pdev = adapter->pdev; |
|
2300 |
||
2301 |
e1000_clean_rx_ring(adapter, rx_ring); |
|
2302 |
||
2303 |
vfree(rx_ring->buffer_info); |
|
2304 |
rx_ring->buffer_info = NULL; |
|
2305 |
kfree(rx_ring->ps_page); |
|
2306 |
rx_ring->ps_page = NULL; |
|
2307 |
kfree(rx_ring->ps_page_dma); |
|
2308 |
rx_ring->ps_page_dma = NULL; |
|
2309 |
||
2310 |
pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
|
2311 |
||
2312 |
rx_ring->desc = NULL; |
|
2313 |
} |
|
2314 |
||
2315 |
/** |
|
2316 |
* e1000_free_all_rx_resources - Free Rx Resources for All Queues |
|
2317 |
* @adapter: board private structure |
|
2318 |
* |
|
2319 |
* Free all receive software resources |
|
2320 |
**/ |
|
2321 |
||
2322 |
void e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
|
2323 |
{ |
|
2324 |
int i; |
|
2325 |
||
2326 |
for (i = 0; i < adapter->num_rx_queues; i++) |
|
2327 |
e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
|
2328 |
} |
|
2329 |
||
2330 |
/** |
|
2331 |
* e1000_clean_rx_ring - Free Rx Buffers per Queue |
|
2332 |
* @adapter: board private structure |
|
2333 |
* @rx_ring: ring to free buffers from |
|
2334 |
**/ |
|
2335 |
||
2336 |
static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
|
2337 |
struct e1000_rx_ring *rx_ring) |
|
2338 |
{ |
|
2339 |
struct e1000_hw *hw = &adapter->hw; |
|
2340 |
struct e1000_buffer *buffer_info; |
|
2341 |
struct e1000_ps_page *ps_page; |
|
2342 |
struct e1000_ps_page_dma *ps_page_dma; |
|
2343 |
struct pci_dev *pdev = adapter->pdev; |
|
2344 |
unsigned long size; |
|
2345 |
unsigned int i, j; |
|
2346 |
||
2347 |
/* Free all the Rx ring sk_buffs */ |
|
2348 |
for (i = 0; i < rx_ring->count; i++) { |
|
2349 |
buffer_info = &rx_ring->buffer_info[i]; |
|
2350 |
if (buffer_info->skb) { |
|
2351 |
pci_unmap_single(pdev, |
|
2352 |
buffer_info->dma, |
|
2353 |
buffer_info->length, |
|
2354 |
PCI_DMA_FROMDEVICE); |
|
2355 |
||
2356 |
dev_kfree_skb(buffer_info->skb); |
|
2357 |
buffer_info->skb = NULL; |
|
2358 |
} |
|
2359 |
ps_page = &rx_ring->ps_page[i]; |
|
2360 |
ps_page_dma = &rx_ring->ps_page_dma[i]; |
|
2361 |
for (j = 0; j < adapter->rx_ps_pages; j++) { |
|
2362 |
if (!ps_page->ps_page[j]) break; |
|
2363 |
pci_unmap_page(pdev, |
|
2364 |
ps_page_dma->ps_page_dma[j], |
|
2365 |
PAGE_SIZE, PCI_DMA_FROMDEVICE); |
|
2366 |
ps_page_dma->ps_page_dma[j] = 0; |
|
2367 |
put_page(ps_page->ps_page[j]); |
|
2368 |
ps_page->ps_page[j] = NULL; |
|
2369 |
} |
|
2370 |
} |
|
2371 |
||
2372 |
size = sizeof(struct e1000_buffer) * rx_ring->count; |
|
2373 |
memset(rx_ring->buffer_info, 0, size); |
|
2374 |
size = sizeof(struct e1000_ps_page) * rx_ring->count; |
|
2375 |
memset(rx_ring->ps_page, 0, size); |
|
2376 |
size = sizeof(struct e1000_ps_page_dma) * rx_ring->count; |
|
2377 |
memset(rx_ring->ps_page_dma, 0, size); |
|
2378 |
||
2379 |
/* Zero out the descriptor ring */ |
|
2380 |
||
2381 |
memset(rx_ring->desc, 0, rx_ring->size); |
|
2382 |
||
2383 |
rx_ring->next_to_clean = 0; |
|
2384 |
rx_ring->next_to_use = 0; |
|
2385 |
||
2386 |
writel(0, hw->hw_addr + rx_ring->rdh); |
|
2387 |
writel(0, hw->hw_addr + rx_ring->rdt); |
|
2388 |
} |
|
2389 |
||
2390 |
/** |
|
2391 |
* e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
|
2392 |
* @adapter: board private structure |
|
2393 |
**/ |
|
2394 |
||
2395 |
static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
|
2396 |
{ |
|
2397 |
int i; |
|
2398 |
||
2399 |
for (i = 0; i < adapter->num_rx_queues; i++) |
|
2400 |
e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
|
2401 |
} |
|
2402 |
||
2403 |
/* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
|
2404 |
* and memory write and invalidate disabled for certain operations |
|
2405 |
*/ |
|
2406 |
static void e1000_enter_82542_rst(struct e1000_adapter *adapter) |
|
2407 |
{ |
|
2408 |
struct e1000_hw *hw = &adapter->hw; |
|
2409 |
struct net_device *netdev = adapter->netdev; |
|
2410 |
u32 rctl; |
|
2411 |
||
2412 |
e1000_pci_clear_mwi(hw); |
|
2413 |
||
2414 |
rctl = er32(RCTL); |
|
2415 |
rctl |= E1000_RCTL_RST; |
|
2416 |
ew32(RCTL, rctl); |
|
2417 |
E1000_WRITE_FLUSH(); |
|
2418 |
mdelay(5); |
|
2419 |
||
2420 |
if (!adapter->ecdev && netif_running(netdev)) |
|
2421 |
e1000_clean_all_rx_rings(adapter); |
|
2422 |
} |
|
2423 |
||
2424 |
static void e1000_leave_82542_rst(struct e1000_adapter *adapter) |
|
2425 |
{ |
|
2426 |
struct e1000_hw *hw = &adapter->hw; |
|
2427 |
struct net_device *netdev = adapter->netdev; |
|
2428 |
u32 rctl; |
|
2429 |
||
2430 |
rctl = er32(RCTL); |
|
2431 |
rctl &= ~E1000_RCTL_RST; |
|
2432 |
ew32(RCTL, rctl); |
|
2433 |
E1000_WRITE_FLUSH(); |
|
2434 |
mdelay(5); |
|
2435 |
||
2436 |
if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
|
2437 |
e1000_pci_set_mwi(hw); |
|
2438 |
||
2439 |
if (!adapter->netdev && netif_running(netdev)) { |
|
2440 |
/* No need to loop, because 82542 supports only 1 queue */ |
|
2441 |
struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
|
2442 |
e1000_configure_rx(adapter); |
|
2443 |
if (adapter->ecdev) { |
|
2444 |
/* fill rx ring completely! */ |
|
2445 |
adapter->alloc_rx_buf(adapter, ring, ring->count); |
|
2446 |
} else { |
|
2447 |
/* this one leaves the last ring element unallocated! */ |
|
2448 |
adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
|
2449 |
} |
|
2450 |
||
2451 |
} |
|
2452 |
} |
|
2453 |
||
2454 |
/** |
|
2455 |
* e1000_set_mac - Change the Ethernet Address of the NIC |
|
2456 |
* @netdev: network interface device structure |
|
2457 |
* @p: pointer to an address structure |
|
2458 |
* |
|
2459 |
* Returns 0 on success, negative on failure |
|
2460 |
**/ |
|
2461 |
||
2462 |
static int e1000_set_mac(struct net_device *netdev, void *p) |
|
2463 |
{ |
|
2464 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
2465 |
struct e1000_hw *hw = &adapter->hw; |
|
2466 |
struct sockaddr *addr = p; |
|
2467 |
||
2468 |
if (!is_valid_ether_addr(addr->sa_data)) |
|
2469 |
return -EADDRNOTAVAIL; |
|
2470 |
||
2471 |
/* 82542 2.0 needs to be in reset to write receive address registers */ |
|
2472 |
||
2473 |
if (hw->mac_type == e1000_82542_rev2_0) |
|
2474 |
e1000_enter_82542_rst(adapter); |
|
2475 |
||
2476 |
memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
|
2477 |
memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len); |
|
2478 |
||
2479 |
e1000_rar_set(hw, hw->mac_addr, 0); |
|
2480 |
||
2481 |
/* With 82571 controllers, LAA may be overwritten (with the default) |
|
2482 |
* due to controller reset from the other port. */ |
|
2483 |
if (hw->mac_type == e1000_82571) { |
|
2484 |
/* activate the work around */ |
|
2485 |
hw->laa_is_present = 1; |
|
2486 |
||
2487 |
/* Hold a copy of the LAA in RAR[14] This is done so that |
|
2488 |
* between the time RAR[0] gets clobbered and the time it |
|
2489 |
* gets fixed (in e1000_watchdog), the actual LAA is in one |
|
2490 |
* of the RARs and no incoming packets directed to this port |
|
2491 |
* are dropped. Eventaully the LAA will be in RAR[0] and |
|
2492 |
* RAR[14] */ |
|
2493 |
e1000_rar_set(hw, hw->mac_addr, |
|
2494 |
E1000_RAR_ENTRIES - 1); |
|
2495 |
} |
|
2496 |
||
2497 |
if (hw->mac_type == e1000_82542_rev2_0) |
|
2498 |
e1000_leave_82542_rst(adapter); |
|
2499 |
||
2500 |
return 0; |
|
2501 |
} |
|
2502 |
||
2503 |
/** |
|
2504 |
* e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set |
|
2505 |
* @netdev: network interface device structure |
|
2506 |
* |
|
2507 |
* The set_rx_mode entry point is called whenever the unicast or multicast |
|
2508 |
* address lists or the network interface flags are updated. This routine is |
|
2509 |
* responsible for configuring the hardware for proper unicast, multicast, |
|
2510 |
* promiscuous mode, and all-multi behavior. |
|
2511 |
**/ |
|
2512 |
||
2513 |
static void e1000_set_rx_mode(struct net_device *netdev) |
|
2514 |
{ |
|
2515 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
2516 |
struct e1000_hw *hw = &adapter->hw; |
|
2517 |
struct dev_addr_list *uc_ptr; |
|
2518 |
struct dev_addr_list *mc_ptr; |
|
2519 |
u32 rctl; |
|
2520 |
u32 hash_value; |
|
2521 |
int i, rar_entries = E1000_RAR_ENTRIES; |
|
2522 |
int mta_reg_count = (hw->mac_type == e1000_ich8lan) ? |
|
2523 |
E1000_NUM_MTA_REGISTERS_ICH8LAN : |
|
2524 |
E1000_NUM_MTA_REGISTERS; |
|
2525 |
||
2526 |
if (hw->mac_type == e1000_ich8lan) |
|
2527 |
rar_entries = E1000_RAR_ENTRIES_ICH8LAN; |
|
2528 |
||
2529 |
/* reserve RAR[14] for LAA over-write work-around */ |
|
2530 |
if (hw->mac_type == e1000_82571) |
|
2531 |
rar_entries--; |
|
2532 |
||
2533 |
/* Check for Promiscuous and All Multicast modes */ |
|
2534 |
||
2535 |
rctl = er32(RCTL); |
|
2536 |
||
2537 |
if (netdev->flags & IFF_PROMISC) { |
|
2538 |
rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
|
2539 |
rctl &= ~E1000_RCTL_VFE; |
|
2540 |
} else { |
|
2541 |
if (netdev->flags & IFF_ALLMULTI) { |
|
2542 |
rctl |= E1000_RCTL_MPE; |
|
2543 |
} else { |
|
2544 |
rctl &= ~E1000_RCTL_MPE; |
|
2545 |
} |
|
2546 |
if (adapter->hw.mac_type != e1000_ich8lan) |
|
2547 |
rctl |= E1000_RCTL_VFE; |
|
2548 |
} |
|
2549 |
||
2550 |
uc_ptr = NULL; |
|
2551 |
if (netdev->uc_count > rar_entries - 1) { |
|
2552 |
rctl |= E1000_RCTL_UPE; |
|
2553 |
} else if (!(netdev->flags & IFF_PROMISC)) { |
|
2554 |
rctl &= ~E1000_RCTL_UPE; |
|
2555 |
uc_ptr = netdev->uc_list; |
|
2556 |
} |
|
2557 |
||
2558 |
ew32(RCTL, rctl); |
|
2559 |
||
2560 |
/* 82542 2.0 needs to be in reset to write receive address registers */ |
|
2561 |
||
2562 |
if (hw->mac_type == e1000_82542_rev2_0) |
|
2563 |
e1000_enter_82542_rst(adapter); |
|
2564 |
||
2565 |
/* load the first 14 addresses into the exact filters 1-14. Unicast |
|
2566 |
* addresses take precedence to avoid disabling unicast filtering |
|
2567 |
* when possible. |
|
2568 |
* |
|
2569 |
* RAR 0 is used for the station MAC adddress |
|
2570 |
* if there are not 14 addresses, go ahead and clear the filters |
|
2571 |
* -- with 82571 controllers only 0-13 entries are filled here |
|
2572 |
*/ |
|
2573 |
mc_ptr = netdev->mc_list; |
|
2574 |
||
2575 |
for (i = 1; i < rar_entries; i++) { |
|
2576 |
if (uc_ptr) { |
|
2577 |
e1000_rar_set(hw, uc_ptr->da_addr, i); |
|
2578 |
uc_ptr = uc_ptr->next; |
|
2579 |
} else if (mc_ptr) { |
|
2580 |
e1000_rar_set(hw, mc_ptr->da_addr, i); |
|
2581 |
mc_ptr = mc_ptr->next; |
|
2582 |
} else { |
|
2583 |
E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
|
2584 |
E1000_WRITE_FLUSH(); |
|
2585 |
E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
|
2586 |
E1000_WRITE_FLUSH(); |
|
2587 |
} |
|
2588 |
} |
|
2589 |
WARN_ON(uc_ptr != NULL); |
|
2590 |
||
2591 |
/* clear the old settings from the multicast hash table */ |
|
2592 |
||
2593 |
for (i = 0; i < mta_reg_count; i++) { |
|
2594 |
E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
|
2595 |
E1000_WRITE_FLUSH(); |
|
2596 |
} |
|
2597 |
||
2598 |
/* load any remaining addresses into the hash table */ |
|
2599 |
||
2600 |
for (; mc_ptr; mc_ptr = mc_ptr->next) { |
|
2601 |
hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr); |
|
2602 |
e1000_mta_set(hw, hash_value); |
|
2603 |
} |
|
2604 |
||
2605 |
if (hw->mac_type == e1000_82542_rev2_0) |
|
2606 |
e1000_leave_82542_rst(adapter); |
|
2607 |
} |
|
2608 |
||
2609 |
/* Need to wait a few seconds after link up to get diagnostic information from |
|
2610 |
* the phy */ |
|
2611 |
||
2612 |
static void e1000_update_phy_info(unsigned long data) |
|
2613 |
{ |
|
2614 |
struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
|
2615 |
struct e1000_hw *hw = &adapter->hw; |
|
2616 |
e1000_phy_get_info(hw, &adapter->phy_info); |
|
2617 |
} |
|
2618 |
||
2619 |
/** |
|
2620 |
* e1000_82547_tx_fifo_stall - Timer Call-back |
|
2621 |
* @data: pointer to adapter cast into an unsigned long |
|
2622 |
**/ |
|
2623 |
||
2624 |
static void e1000_82547_tx_fifo_stall(unsigned long data) |
|
2625 |
{ |
|
2626 |
struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
|
2627 |
struct e1000_hw *hw = &adapter->hw; |
|
2628 |
struct net_device *netdev = adapter->netdev; |
|
2629 |
u32 tctl; |
|
2630 |
||
2631 |
if (atomic_read(&adapter->tx_fifo_stall)) { |
|
2632 |
if ((er32(TDT) == er32(TDH)) && |
|
2633 |
(er32(TDFT) == er32(TDFH)) && |
|
2634 |
(er32(TDFTS) == er32(TDFHS))) { |
|
2635 |
tctl = er32(TCTL); |
|
2636 |
ew32(TCTL, tctl & ~E1000_TCTL_EN); |
|
2637 |
ew32(TDFT, adapter->tx_head_addr); |
|
2638 |
ew32(TDFH, adapter->tx_head_addr); |
|
2639 |
ew32(TDFTS, adapter->tx_head_addr); |
|
2640 |
ew32(TDFHS, adapter->tx_head_addr); |
|
2641 |
ew32(TCTL, tctl); |
|
2642 |
E1000_WRITE_FLUSH(); |
|
2643 |
||
2644 |
adapter->tx_fifo_head = 0; |
|
2645 |
atomic_set(&adapter->tx_fifo_stall, 0); |
|
2646 |
if (!adapter->ecdev) netif_wake_queue(netdev); |
|
2647 |
} else { |
|
2648 |
if (!adapter->ecdev) |
|
2649 |
mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
|
2650 |
} |
|
2651 |
} |
|
2652 |
} |
|
2653 |
||
2654 |
/** |
|
2655 |
* e1000_watchdog - Timer Call-back |
|
2656 |
* @data: pointer to adapter cast into an unsigned long |
|
2657 |
**/ |
|
2658 |
static void e1000_watchdog(unsigned long data) |
|
2659 |
{ |
|
2660 |
struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
|
2661 |
struct e1000_hw *hw = &adapter->hw; |
|
2662 |
struct net_device *netdev = adapter->netdev; |
|
2663 |
struct e1000_tx_ring *txdr = adapter->tx_ring; |
|
2664 |
u32 link, tctl; |
|
2665 |
s32 ret_val; |
|
2666 |
||
2667 |
ret_val = e1000_check_for_link(hw); |
|
2668 |
if ((ret_val == E1000_ERR_PHY) && |
|
2669 |
(hw->phy_type == e1000_phy_igp_3) && |
|
2670 |
(er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
|
2671 |
/* See e1000_kumeran_lock_loss_workaround() */ |
|
2672 |
DPRINTK(LINK, INFO, |
|
2673 |
"Gigabit has been disabled, downgrading speed\n"); |
|
2674 |
} |
|
2675 |
||
2676 |
if (hw->mac_type == e1000_82573) { |
|
2677 |
e1000_enable_tx_pkt_filtering(hw); |
|
2678 |
if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id) |
|
2679 |
e1000_update_mng_vlan(adapter); |
|
2680 |
} |
|
2681 |
||
2682 |
if ((hw->media_type == e1000_media_type_internal_serdes) && |
|
2683 |
!(er32(TXCW) & E1000_TXCW_ANE)) |
|
2684 |
link = !hw->serdes_link_down; |
|
2685 |
else |
|
2686 |
link = er32(STATUS) & E1000_STATUS_LU; |
|
2687 |
||
2688 |
if (link) { |
|
2689 |
if ((adapter->ecdev && !ecdev_get_link(adapter->ecdev)) |
|
2690 |
|| (!adapter->ecdev && !netif_carrier_ok(netdev))) { |
|
2691 |
u32 ctrl; |
|
2692 |
bool txb2b = true; |
|
2693 |
e1000_get_speed_and_duplex(hw, |
|
2694 |
&adapter->link_speed, |
|
2695 |
&adapter->link_duplex); |
|
2696 |
||
2697 |
ctrl = er32(CTRL); |
|
2698 |
DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, " |
|
2699 |
"Flow Control: %s\n", |
|
2700 |
adapter->link_speed, |
|
2701 |
adapter->link_duplex == FULL_DUPLEX ? |
|
2702 |
"Full Duplex" : "Half Duplex", |
|
2703 |
((ctrl & E1000_CTRL_TFCE) && (ctrl & |
|
2704 |
E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl & |
|
2705 |
E1000_CTRL_RFCE) ? "RX" : ((ctrl & |
|
2706 |
E1000_CTRL_TFCE) ? "TX" : "None" ))); |
|
2707 |
||
2708 |
/* tweak tx_queue_len according to speed/duplex |
|
2709 |
* and adjust the timeout factor */ |
|
2710 |
netdev->tx_queue_len = adapter->tx_queue_len; |
|
2711 |
adapter->tx_timeout_factor = 1; |
|
2712 |
switch (adapter->link_speed) { |
|
2713 |
case SPEED_10: |
|
2714 |
txb2b = false; |
|
2715 |
netdev->tx_queue_len = 10; |
|
2716 |
adapter->tx_timeout_factor = 8; |
|
2717 |
break; |
|
2718 |
case SPEED_100: |
|
2719 |
txb2b = false; |
|
2720 |
netdev->tx_queue_len = 100; |
|
2721 |
/* maybe add some timeout factor ? */ |
|
2722 |
break; |
|
2723 |
} |
|
2724 |
||
2725 |
if ((hw->mac_type == e1000_82571 || |
|
2726 |
hw->mac_type == e1000_82572) && |
|
2727 |
!txb2b) { |
|
2728 |
u32 tarc0; |
|
2729 |
tarc0 = er32(TARC0); |
|
2730 |
tarc0 &= ~(1 << 21); |
|
2731 |
ew32(TARC0, tarc0); |
|
2732 |
} |
|
2733 |
||
2734 |
/* disable TSO for pcie and 10/100 speeds, to avoid |
|
2735 |
* some hardware issues */ |
|
2736 |
if (!adapter->tso_force && |
|
2737 |
hw->bus_type == e1000_bus_type_pci_express){ |
|
2738 |
switch (adapter->link_speed) { |
|
2739 |
case SPEED_10: |
|
2740 |
case SPEED_100: |
|
2741 |
DPRINTK(PROBE,INFO, |
|
2742 |
"10/100 speed: disabling TSO\n"); |
|
2743 |
netdev->features &= ~NETIF_F_TSO; |
|
2744 |
netdev->features &= ~NETIF_F_TSO6; |
|
2745 |
break; |
|
2746 |
case SPEED_1000: |
|
2747 |
netdev->features |= NETIF_F_TSO; |
|
2748 |
netdev->features |= NETIF_F_TSO6; |
|
2749 |
break; |
|
2750 |
default: |
|
2751 |
/* oops */ |
|
2752 |
break; |
|
2753 |
} |
|
2754 |
} |
|
2755 |
||
2756 |
/* enable transmits in the hardware, need to do this |
|
2757 |
* after setting TARC0 */ |
|
2758 |
tctl = er32(TCTL); |
|
2759 |
tctl |= E1000_TCTL_EN; |
|
2760 |
ew32(TCTL, tctl); |
|
2761 |
||
2762 |
if (adapter->ecdev) { |
|
2763 |
ecdev_set_link(adapter->ecdev, 1); |
|
2764 |
} else { |
|
2765 |
netif_carrier_on(netdev); |
|
2766 |
netif_wake_queue(netdev); |
|
2767 |
mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
|
2768 |
} |
|
2769 |
adapter->smartspeed = 0; |
|
2770 |
} else { |
|
2771 |
/* make sure the receive unit is started */ |
|
2772 |
if (hw->rx_needs_kicking) { |
|
2773 |
u32 rctl = er32(RCTL); |
|
2774 |
ew32(RCTL, rctl | E1000_RCTL_EN); |
|
2775 |
} |
|
2776 |
} |
|
2777 |
} else { |
|
2778 |
if ((adapter->ecdev && ecdev_get_link(adapter->ecdev)) |
|
2779 |
|| (!adapter->ecdev && netif_carrier_ok(netdev))) { |
|
2780 |
adapter->link_speed = 0; |
|
2781 |
adapter->link_duplex = 0; |
|
2782 |
DPRINTK(LINK, INFO, "NIC Link is Down\n"); |
|
2783 |
if (adapter->ecdev) { |
|
2784 |
ecdev_set_link(adapter->ecdev, 0); |
|
2785 |
} else { |
|
2786 |
netif_carrier_off(netdev); |
|
2787 |
netif_stop_queue(netdev); |
|
2788 |
mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
|
2789 |
} |
|
2790 |
||
2791 |
/* 80003ES2LAN workaround-- |
|
2792 |
* For packet buffer work-around on link down event; |
|
2793 |
* disable receives in the ISR and |
|
2794 |
* reset device here in the watchdog |
|
2795 |
*/ |
|
2796 |
if (hw->mac_type == e1000_80003es2lan) |
|
2797 |
/* reset device */ |
|
2798 |
schedule_work(&adapter->reset_task); |
|
2799 |
} |
|
2800 |
||
2801 |
e1000_smartspeed(adapter); |
|
2802 |
} |
|
2803 |
||
2804 |
e1000_update_stats(adapter); |
|
2805 |
||
2806 |
hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
|
2807 |
adapter->tpt_old = adapter->stats.tpt; |
|
2808 |
hw->collision_delta = adapter->stats.colc - adapter->colc_old; |
|
2809 |
adapter->colc_old = adapter->stats.colc; |
|
2810 |
||
2811 |
adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
|
2812 |
adapter->gorcl_old = adapter->stats.gorcl; |
|
2813 |
adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
|
2814 |
adapter->gotcl_old = adapter->stats.gotcl; |
|
2815 |
||
2816 |
e1000_update_adaptive(hw); |
|
2817 |
||
2818 |
if (!adapter->ecdev && !netif_carrier_ok(netdev)) { |
|
2819 |
if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
|
2820 |
/* We've lost link, so the controller stops DMA, |
|
2821 |
* but we've got queued Tx work that's never going |
|
2822 |
* to get done, so reset controller to flush Tx. |
|
2823 |
* (Do the reset outside of interrupt context). */ |
|
2824 |
adapter->tx_timeout_count++; |
|
2825 |
schedule_work(&adapter->reset_task); |
|
2826 |
} |
|
2827 |
} |
|
2828 |
||
2829 |
/* Cause software interrupt to ensure rx ring is cleaned */ |
|
2830 |
ew32(ICS, E1000_ICS_RXDMT0); |
|
2831 |
||
2832 |
/* Force detection of hung controller every watchdog period */ |
|
2833 |
if (!adapter->ecdev) adapter->detect_tx_hung = true; |
|
2834 |
||
2835 |
/* With 82571 controllers, LAA may be overwritten due to controller |
|
2836 |
* reset from the other port. Set the appropriate LAA in RAR[0] */ |
|
2837 |
if (hw->mac_type == e1000_82571 && hw->laa_is_present) |
|
2838 |
e1000_rar_set(hw, hw->mac_addr, 0); |
|
2839 |
||
2840 |
/* Reset the timer */ |
|
2841 |
if (!adapter->ecdev) |
|
2842 |
mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
|
2843 |
} |
|
2844 |
||
2845 |
enum latency_range { |
|
2846 |
lowest_latency = 0, |
|
2847 |
low_latency = 1, |
|
2848 |
bulk_latency = 2, |
|
2849 |
latency_invalid = 255 |
|
2850 |
}; |
|
2851 |
||
2852 |
/** |
|
2853 |
* e1000_update_itr - update the dynamic ITR value based on statistics |
|
2854 |
* Stores a new ITR value based on packets and byte |
|
2855 |
* counts during the last interrupt. The advantage of per interrupt |
|
2856 |
* computation is faster updates and more accurate ITR for the current |
|
2857 |
* traffic pattern. Constants in this function were computed |
|
2858 |
* based on theoretical maximum wire speed and thresholds were set based |
|
2859 |
* on testing data as well as attempting to minimize response time |
|
2860 |
* while increasing bulk throughput. |
|
2861 |
* this functionality is controlled by the InterruptThrottleRate module |
|
2862 |
* parameter (see e1000_param.c) |
|
2863 |
* @adapter: pointer to adapter |
|
2864 |
* @itr_setting: current adapter->itr |
|
2865 |
* @packets: the number of packets during this measurement interval |
|
2866 |
* @bytes: the number of bytes during this measurement interval |
|
2867 |
**/ |
|
2868 |
static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
|
2869 |
u16 itr_setting, int packets, int bytes) |
|
2870 |
{ |
|
2871 |
unsigned int retval = itr_setting; |
|
2872 |
struct e1000_hw *hw = &adapter->hw; |
|
2873 |
||
2874 |
if (unlikely(hw->mac_type < e1000_82540)) |
|
2875 |
goto update_itr_done; |
|
2876 |
||
2877 |
if (packets == 0) |
|
2878 |
goto update_itr_done; |
|
2879 |
||
2880 |
switch (itr_setting) { |
|
2881 |
case lowest_latency: |
|
2882 |
/* jumbo frames get bulk treatment*/ |
|
2883 |
if (bytes/packets > 8000) |
|
2884 |
retval = bulk_latency; |
|
2885 |
else if ((packets < 5) && (bytes > 512)) |
|
2886 |
retval = low_latency; |
|
2887 |
break; |
|
2888 |
case low_latency: /* 50 usec aka 20000 ints/s */ |
|
2889 |
if (bytes > 10000) { |
|
2890 |
/* jumbo frames need bulk latency setting */ |
|
2891 |
if (bytes/packets > 8000) |
|
2892 |
retval = bulk_latency; |
|
2893 |
else if ((packets < 10) || ((bytes/packets) > 1200)) |
|
2894 |
retval = bulk_latency; |
|
2895 |
else if ((packets > 35)) |
|
2896 |
retval = lowest_latency; |
|
2897 |
} else if (bytes/packets > 2000) |
|
2898 |
retval = bulk_latency; |
|
2899 |
else if (packets <= 2 && bytes < 512) |
|
2900 |
retval = lowest_latency; |
|
2901 |
break; |
|
2902 |
case bulk_latency: /* 250 usec aka 4000 ints/s */ |
|
2903 |
if (bytes > 25000) { |
|
2904 |
if (packets > 35) |
|
2905 |
retval = low_latency; |
|
2906 |
} else if (bytes < 6000) { |
|
2907 |
retval = low_latency; |
|
2908 |
} |
|
2909 |
break; |
|
2910 |
} |
|
2911 |
||
2912 |
update_itr_done: |
|
2913 |
return retval; |
|
2914 |
} |
|
2915 |
||
2916 |
static void e1000_set_itr(struct e1000_adapter *adapter) |
|
2917 |
{ |
|
2918 |
struct e1000_hw *hw = &adapter->hw; |
|
2919 |
u16 current_itr; |
|
2920 |
u32 new_itr = adapter->itr; |
|
2921 |
||
2922 |
if (unlikely(hw->mac_type < e1000_82540)) |
|
2923 |
return; |
|
2924 |
||
2925 |
/* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
|
2926 |
if (unlikely(adapter->link_speed != SPEED_1000)) { |
|
2927 |
current_itr = 0; |
|
2928 |
new_itr = 4000; |
|
2929 |
goto set_itr_now; |
|
2930 |
} |
|
2931 |
||
2932 |
adapter->tx_itr = e1000_update_itr(adapter, |
|
2933 |
adapter->tx_itr, |
|
2934 |
adapter->total_tx_packets, |
|
2935 |
adapter->total_tx_bytes); |
|
2936 |
/* conservative mode (itr 3) eliminates the lowest_latency setting */ |
|
2937 |
if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
|
2938 |
adapter->tx_itr = low_latency; |
|
2939 |
||
2940 |
adapter->rx_itr = e1000_update_itr(adapter, |
|
2941 |
adapter->rx_itr, |
|
2942 |
adapter->total_rx_packets, |
|
2943 |
adapter->total_rx_bytes); |
|
2944 |
/* conservative mode (itr 3) eliminates the lowest_latency setting */ |
|
2945 |
if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
|
2946 |
adapter->rx_itr = low_latency; |
|
2947 |
||
2948 |
current_itr = max(adapter->rx_itr, adapter->tx_itr); |
|
2949 |
||
2950 |
switch (current_itr) { |
|
2951 |
/* counts and packets in update_itr are dependent on these numbers */ |
|
2952 |
case lowest_latency: |
|
2953 |
new_itr = 70000; |
|
2954 |
break; |
|
2955 |
case low_latency: |
|
2956 |
new_itr = 20000; /* aka hwitr = ~200 */ |
|
2957 |
break; |
|
2958 |
case bulk_latency: |
|
2959 |
new_itr = 4000; |
|
2960 |
break; |
|
2961 |
default: |
|
2962 |
break; |
|
2963 |
} |
|
2964 |
||
2965 |
set_itr_now: |
|
2966 |
if (new_itr != adapter->itr) { |
|
2967 |
/* this attempts to bias the interrupt rate towards Bulk |
|
2968 |
* by adding intermediate steps when interrupt rate is |
|
2969 |
* increasing */ |
|
2970 |
new_itr = new_itr > adapter->itr ? |
|
2971 |
min(adapter->itr + (new_itr >> 2), new_itr) : |
|
2972 |
new_itr; |
|
2973 |
adapter->itr = new_itr; |
|
2974 |
ew32(ITR, 1000000000 / (new_itr * 256)); |
|
2975 |
} |
|
2976 |
||
2977 |
return; |
|
2978 |
} |
|
2979 |
||
2980 |
#define E1000_TX_FLAGS_CSUM 0x00000001 |
|
2981 |
#define E1000_TX_FLAGS_VLAN 0x00000002 |
|
2982 |
#define E1000_TX_FLAGS_TSO 0x00000004 |
|
2983 |
#define E1000_TX_FLAGS_IPV4 0x00000008 |
|
2984 |
#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
|
2985 |
#define E1000_TX_FLAGS_VLAN_SHIFT 16 |
|
2986 |
||
2987 |
static int e1000_tso(struct e1000_adapter *adapter, |
|
2988 |
struct e1000_tx_ring *tx_ring, struct sk_buff *skb) |
|
2989 |
{ |
|
2990 |
struct e1000_context_desc *context_desc; |
|
2991 |
struct e1000_buffer *buffer_info; |
|
2992 |
unsigned int i; |
|
2993 |
u32 cmd_length = 0; |
|
2994 |
u16 ipcse = 0, tucse, mss; |
|
2995 |
u8 ipcss, ipcso, tucss, tucso, hdr_len; |
|
2996 |
int err; |
|
2997 |
||
2998 |
if (skb_is_gso(skb)) { |
|
2999 |
if (skb_header_cloned(skb)) { |
|
3000 |
err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
|
3001 |
if (err) |
|
3002 |
return err; |
|
3003 |
} |
|
3004 |
||
3005 |
hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
|
3006 |
mss = skb_shinfo(skb)->gso_size; |
|
3007 |
if (skb->protocol == htons(ETH_P_IP)) { |
|
3008 |
struct iphdr *iph = ip_hdr(skb); |
|
3009 |
iph->tot_len = 0; |
|
3010 |
iph->check = 0; |
|
3011 |
tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
|
3012 |
iph->daddr, 0, |
|
3013 |
IPPROTO_TCP, |
|
3014 |
0); |
|
3015 |
cmd_length = E1000_TXD_CMD_IP; |
|
3016 |
ipcse = skb_transport_offset(skb) - 1; |
|
3017 |
} else if (skb->protocol == htons(ETH_P_IPV6)) { |
|
3018 |
ipv6_hdr(skb)->payload_len = 0; |
|
3019 |
tcp_hdr(skb)->check = |
|
3020 |
~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
|
3021 |
&ipv6_hdr(skb)->daddr, |
|
3022 |
0, IPPROTO_TCP, 0); |
|
3023 |
ipcse = 0; |
|
3024 |
} |
|
3025 |
ipcss = skb_network_offset(skb); |
|
3026 |
ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
|
3027 |
tucss = skb_transport_offset(skb); |
|
3028 |
tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
|
3029 |
tucse = 0; |
|
3030 |
||
3031 |
cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
|
3032 |
E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
|
3033 |
||
3034 |
i = tx_ring->next_to_use; |
|
3035 |
context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
|
3036 |
buffer_info = &tx_ring->buffer_info[i]; |
|
3037 |
||
3038 |
context_desc->lower_setup.ip_fields.ipcss = ipcss; |
|
3039 |
context_desc->lower_setup.ip_fields.ipcso = ipcso; |
|
3040 |
context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
|
3041 |
context_desc->upper_setup.tcp_fields.tucss = tucss; |
|
3042 |
context_desc->upper_setup.tcp_fields.tucso = tucso; |
|
3043 |
context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
|
3044 |
context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
|
3045 |
context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
|
3046 |
context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
|
3047 |
||
3048 |
buffer_info->time_stamp = jiffies; |
|
3049 |
buffer_info->next_to_watch = i; |
|
3050 |
||
3051 |
if (++i == tx_ring->count) i = 0; |
|
3052 |
tx_ring->next_to_use = i; |
|
3053 |
||
3054 |
return true; |
|
3055 |
} |
|
3056 |
return false; |
|
3057 |
} |
|
3058 |
||
3059 |
static bool e1000_tx_csum(struct e1000_adapter *adapter, |
|
3060 |
struct e1000_tx_ring *tx_ring, struct sk_buff *skb) |
|
3061 |
{ |
|
3062 |
struct e1000_context_desc *context_desc; |
|
3063 |
struct e1000_buffer *buffer_info; |
|
3064 |
unsigned int i; |
|
3065 |
u8 css; |
|
3066 |
||
3067 |
if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
|
3068 |
css = skb_transport_offset(skb); |
|
3069 |
||
3070 |
i = tx_ring->next_to_use; |
|
3071 |
buffer_info = &tx_ring->buffer_info[i]; |
|
3072 |
context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
|
3073 |
||
3074 |
context_desc->lower_setup.ip_config = 0; |
|
3075 |
context_desc->upper_setup.tcp_fields.tucss = css; |
|
3076 |
context_desc->upper_setup.tcp_fields.tucso = |
|
3077 |
css + skb->csum_offset; |
|
3078 |
context_desc->upper_setup.tcp_fields.tucse = 0; |
|
3079 |
context_desc->tcp_seg_setup.data = 0; |
|
3080 |
context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); |
|
3081 |
||
3082 |
buffer_info->time_stamp = jiffies; |
|
3083 |
buffer_info->next_to_watch = i; |
|
3084 |
||
3085 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
3086 |
tx_ring->next_to_use = i; |
|
3087 |
||
3088 |
return true; |
|
3089 |
} |
|
3090 |
||
3091 |
return false; |
|
3092 |
} |
|
3093 |
||
3094 |
#define E1000_MAX_TXD_PWR 12 |
|
3095 |
#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
|
3096 |
||
3097 |
static int e1000_tx_map(struct e1000_adapter *adapter, |
|
3098 |
struct e1000_tx_ring *tx_ring, |
|
3099 |
struct sk_buff *skb, unsigned int first, |
|
3100 |
unsigned int max_per_txd, unsigned int nr_frags, |
|
3101 |
unsigned int mss) |
|
3102 |
{ |
|
3103 |
struct e1000_hw *hw = &adapter->hw; |
|
3104 |
struct e1000_buffer *buffer_info; |
|
3105 |
unsigned int len = skb->len; |
|
3106 |
unsigned int offset = 0, size, count = 0, i; |
|
3107 |
unsigned int f; |
|
3108 |
len -= skb->data_len; |
|
3109 |
||
3110 |
i = tx_ring->next_to_use; |
|
3111 |
||
3112 |
while (len) { |
|
3113 |
buffer_info = &tx_ring->buffer_info[i]; |
|
3114 |
size = min(len, max_per_txd); |
|
3115 |
/* Workaround for Controller erratum -- |
|
3116 |
* descriptor for non-tso packet in a linear SKB that follows a |
|
3117 |
* tso gets written back prematurely before the data is fully |
|
3118 |
* DMA'd to the controller */ |
|
3119 |
if (!skb->data_len && tx_ring->last_tx_tso && |
|
3120 |
!skb_is_gso(skb)) { |
|
3121 |
tx_ring->last_tx_tso = 0; |
|
3122 |
size -= 4; |
|
3123 |
} |
|
3124 |
||
3125 |
/* Workaround for premature desc write-backs |
|
3126 |
* in TSO mode. Append 4-byte sentinel desc */ |
|
3127 |
if (unlikely(mss && !nr_frags && size == len && size > 8)) |
|
3128 |
size -= 4; |
|
3129 |
/* work-around for errata 10 and it applies |
|
3130 |
* to all controllers in PCI-X mode |
|
3131 |
* The fix is to make sure that the first descriptor of a |
|
3132 |
* packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
|
3133 |
*/ |
|
3134 |
if (unlikely((hw->bus_type == e1000_bus_type_pcix) && |
|
3135 |
(size > 2015) && count == 0)) |
|
3136 |
size = 2015; |
|
3137 |
||
3138 |
/* Workaround for potential 82544 hang in PCI-X. Avoid |
|
3139 |
* terminating buffers within evenly-aligned dwords. */ |
|
3140 |
if (unlikely(adapter->pcix_82544 && |
|
3141 |
!((unsigned long)(skb->data + offset + size - 1) & 4) && |
|
3142 |
size > 4)) |
|
3143 |
size -= 4; |
|
3144 |
||
3145 |
buffer_info->length = size; |
|
3146 |
buffer_info->dma = |
|
3147 |
pci_map_single(adapter->pdev, |
|
3148 |
skb->data + offset, |
|
3149 |
size, |
|
3150 |
PCI_DMA_TODEVICE); |
|
3151 |
buffer_info->time_stamp = jiffies; |
|
3152 |
buffer_info->next_to_watch = i; |
|
3153 |
||
3154 |
len -= size; |
|
3155 |
offset += size; |
|
3156 |
count++; |
|
3157 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
3158 |
} |
|
3159 |
||
3160 |
for (f = 0; f < nr_frags; f++) { |
|
3161 |
struct skb_frag_struct *frag; |
|
3162 |
||
3163 |
frag = &skb_shinfo(skb)->frags[f]; |
|
3164 |
len = frag->size; |
|
3165 |
offset = frag->page_offset; |
|
3166 |
||
3167 |
while (len) { |
|
3168 |
buffer_info = &tx_ring->buffer_info[i]; |
|
3169 |
size = min(len, max_per_txd); |
|
3170 |
/* Workaround for premature desc write-backs |
|
3171 |
* in TSO mode. Append 4-byte sentinel desc */ |
|
3172 |
if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
|
3173 |
size -= 4; |
|
3174 |
/* Workaround for potential 82544 hang in PCI-X. |
|
3175 |
* Avoid terminating buffers within evenly-aligned |
|
3176 |
* dwords. */ |
|
3177 |
if (unlikely(adapter->pcix_82544 && |
|
3178 |
!((unsigned long)(frag->page+offset+size-1) & 4) && |
|
3179 |
size > 4)) |
|
3180 |
size -= 4; |
|
3181 |
||
3182 |
buffer_info->length = size; |
|
3183 |
buffer_info->dma = |
|
3184 |
pci_map_page(adapter->pdev, |
|
3185 |
frag->page, |
|
3186 |
offset, |
|
3187 |
size, |
|
3188 |
PCI_DMA_TODEVICE); |
|
3189 |
buffer_info->time_stamp = jiffies; |
|
3190 |
buffer_info->next_to_watch = i; |
|
3191 |
||
3192 |
len -= size; |
|
3193 |
offset += size; |
|
3194 |
count++; |
|
3195 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
3196 |
} |
|
3197 |
} |
|
3198 |
||
3199 |
i = (i == 0) ? tx_ring->count - 1 : i - 1; |
|
3200 |
tx_ring->buffer_info[i].skb = skb; |
|
3201 |
tx_ring->buffer_info[first].next_to_watch = i; |
|
3202 |
||
3203 |
return count; |
|
3204 |
} |
|
3205 |
||
3206 |
static void e1000_tx_queue(struct e1000_adapter *adapter, |
|
3207 |
struct e1000_tx_ring *tx_ring, int tx_flags, |
|
3208 |
int count) |
|
3209 |
{ |
|
3210 |
struct e1000_hw *hw = &adapter->hw; |
|
3211 |
struct e1000_tx_desc *tx_desc = NULL; |
|
3212 |
struct e1000_buffer *buffer_info; |
|
3213 |
u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
|
3214 |
unsigned int i; |
|
3215 |
||
3216 |
if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
|
3217 |
txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
|
3218 |
E1000_TXD_CMD_TSE; |
|
3219 |
txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
|
3220 |
||
3221 |
if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
|
3222 |
txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
|
3223 |
} |
|
3224 |
||
3225 |
if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
|
3226 |
txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
|
3227 |
txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
|
3228 |
} |
|
3229 |
||
3230 |
if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
|
3231 |
txd_lower |= E1000_TXD_CMD_VLE; |
|
3232 |
txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
|
3233 |
} |
|
3234 |
||
3235 |
i = tx_ring->next_to_use; |
|
3236 |
||
3237 |
while (count--) { |
|
3238 |
buffer_info = &tx_ring->buffer_info[i]; |
|
3239 |
tx_desc = E1000_TX_DESC(*tx_ring, i); |
|
3240 |
tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
|
3241 |
tx_desc->lower.data = |
|
3242 |
cpu_to_le32(txd_lower | buffer_info->length); |
|
3243 |
tx_desc->upper.data = cpu_to_le32(txd_upper); |
|
3244 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
3245 |
} |
|
3246 |
||
3247 |
tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
|
3248 |
||
3249 |
/* Force memory writes to complete before letting h/w |
|
3250 |
* know there are new descriptors to fetch. (Only |
|
3251 |
* applicable for weak-ordered memory model archs, |
|
3252 |
* such as IA-64). */ |
|
3253 |
wmb(); |
|
3254 |
||
3255 |
tx_ring->next_to_use = i; |
|
3256 |
writel(i, hw->hw_addr + tx_ring->tdt); |
|
3257 |
/* we need this if more than one processor can write to our tail |
|
3258 |
* at a time, it syncronizes IO on IA64/Altix systems */ |
|
3259 |
mmiowb(); |
|
3260 |
} |
|
3261 |
||
3262 |
/** |
|
3263 |
* 82547 workaround to avoid controller hang in half-duplex environment. |
|
3264 |
* The workaround is to avoid queuing a large packet that would span |
|
3265 |
* the internal Tx FIFO ring boundary by notifying the stack to resend |
|
3266 |
* the packet at a later time. This gives the Tx FIFO an opportunity to |
|
3267 |
* flush all packets. When that occurs, we reset the Tx FIFO pointers |
|
3268 |
* to the beginning of the Tx FIFO. |
|
3269 |
**/ |
|
3270 |
||
3271 |
#define E1000_FIFO_HDR 0x10 |
|
3272 |
#define E1000_82547_PAD_LEN 0x3E0 |
|
3273 |
||
3274 |
static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
|
3275 |
struct sk_buff *skb) |
|
3276 |
{ |
|
3277 |
u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
|
3278 |
u32 skb_fifo_len = skb->len + E1000_FIFO_HDR; |
|
3279 |
||
3280 |
skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR); |
|
3281 |
||
3282 |
if (adapter->link_duplex != HALF_DUPLEX) |
|
3283 |
goto no_fifo_stall_required; |
|
3284 |
||
3285 |
if (atomic_read(&adapter->tx_fifo_stall)) |
|
3286 |
return 1; |
|
3287 |
||
3288 |
if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
|
3289 |
atomic_set(&adapter->tx_fifo_stall, 1); |
|
3290 |
return 1; |
|
3291 |
} |
|
3292 |
||
3293 |
no_fifo_stall_required: |
|
3294 |
adapter->tx_fifo_head += skb_fifo_len; |
|
3295 |
if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
|
3296 |
adapter->tx_fifo_head -= adapter->tx_fifo_size; |
|
3297 |
return 0; |
|
3298 |
} |
|
3299 |
||
3300 |
#define MINIMUM_DHCP_PACKET_SIZE 282 |
|
3301 |
static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
|
3302 |
struct sk_buff *skb) |
|
3303 |
{ |
|
3304 |
struct e1000_hw *hw = &adapter->hw; |
|
3305 |
u16 length, offset; |
|
3306 |
if (vlan_tx_tag_present(skb)) { |
|
3307 |
if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) && |
|
3308 |
( hw->mng_cookie.status & |
|
3309 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
|
3310 |
return 0; |
|
3311 |
} |
|
3312 |
if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
|
3313 |
struct ethhdr *eth = (struct ethhdr *)skb->data; |
|
3314 |
if ((htons(ETH_P_IP) == eth->h_proto)) { |
|
3315 |
const struct iphdr *ip = |
|
3316 |
(struct iphdr *)((u8 *)skb->data+14); |
|
3317 |
if (IPPROTO_UDP == ip->protocol) { |
|
3318 |
struct udphdr *udp = |
|
3319 |
(struct udphdr *)((u8 *)ip + |
|
3320 |
(ip->ihl << 2)); |
|
3321 |
if (ntohs(udp->dest) == 67) { |
|
3322 |
offset = (u8 *)udp + 8 - skb->data; |
|
3323 |
length = skb->len - offset; |
|
3324 |
||
3325 |
return e1000_mng_write_dhcp_info(hw, |
|
3326 |
(u8 *)udp + 8, |
|
3327 |
length); |
|
3328 |
} |
|
3329 |
} |
|
3330 |
} |
|
3331 |
} |
|
3332 |
return 0; |
|
3333 |
} |
|
3334 |
||
3335 |
static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
|
3336 |
{ |
|
3337 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3338 |
struct e1000_tx_ring *tx_ring = adapter->tx_ring; |
|
3339 |
||
3340 |
netif_stop_queue(netdev); |
|
3341 |
/* Herbert's original patch had: |
|
3342 |
* smp_mb__after_netif_stop_queue(); |
|
3343 |
* but since that doesn't exist yet, just open code it. */ |
|
3344 |
smp_mb(); |
|
3345 |
||
3346 |
/* We need to check again in a case another CPU has just |
|
3347 |
* made room available. */ |
|
3348 |
if (likely(E1000_DESC_UNUSED(tx_ring) < size)) |
|
3349 |
return -EBUSY; |
|
3350 |
||
3351 |
/* A reprieve! */ |
|
3352 |
netif_start_queue(netdev); |
|
3353 |
++adapter->restart_queue; |
|
3354 |
return 0; |
|
3355 |
} |
|
3356 |
||
3357 |
static int e1000_maybe_stop_tx(struct net_device *netdev, |
|
3358 |
struct e1000_tx_ring *tx_ring, int size) |
|
3359 |
{ |
|
3360 |
if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) |
|
3361 |
return 0; |
|
3362 |
return __e1000_maybe_stop_tx(netdev, size); |
|
3363 |
} |
|
3364 |
||
3365 |
#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
|
3366 |
static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
|
3367 |
{ |
|
3368 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3369 |
struct e1000_hw *hw = &adapter->hw; |
|
3370 |
struct e1000_tx_ring *tx_ring; |
|
3371 |
unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
|
3372 |
unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
|
3373 |
unsigned int tx_flags = 0; |
|
3374 |
unsigned int len = skb->len - skb->data_len; |
|
3375 |
unsigned long flags = 0; |
|
3376 |
unsigned int nr_frags = 0; |
|
3377 |
unsigned int mss = 0; |
|
3378 |
int count = 0; |
|
3379 |
int tso; |
|
3380 |
unsigned int f; |
|
3381 |
||
3382 |
/* This goes back to the question of how to logically map a tx queue |
|
3383 |
* to a flow. Right now, performance is impacted slightly negatively |
|
3384 |
* if using multiple tx queues. If the stack breaks away from a |
|
3385 |
* single qdisc implementation, we can look at this again. */ |
|
3386 |
tx_ring = adapter->tx_ring; |
|
3387 |
||
3388 |
if (unlikely(skb->len <= 0)) { |
|
3389 |
if (!adapter->ecdev) |
|
3390 |
dev_kfree_skb_any(skb); |
|
3391 |
return NETDEV_TX_OK; |
|
3392 |
} |
|
3393 |
||
3394 |
/* 82571 and newer doesn't need the workaround that limited descriptor |
|
3395 |
* length to 4kB */ |
|
3396 |
if (hw->mac_type >= e1000_82571) |
|
3397 |
max_per_txd = 8192; |
|
3398 |
||
3399 |
mss = skb_shinfo(skb)->gso_size; |
|
3400 |
/* The controller does a simple calculation to |
|
3401 |
* make sure there is enough room in the FIFO before |
|
3402 |
* initiating the DMA for each buffer. The calc is: |
|
3403 |
* 4 = ceil(buffer len/mss). To make sure we don't |
|
3404 |
* overrun the FIFO, adjust the max buffer len if mss |
|
3405 |
* drops. */ |
|
3406 |
if (mss) { |
|
3407 |
u8 hdr_len; |
|
3408 |
max_per_txd = min(mss << 2, max_per_txd); |
|
3409 |
max_txd_pwr = fls(max_per_txd) - 1; |
|
3410 |
||
3411 |
/* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
|
3412 |
* points to just header, pull a few bytes of payload from |
|
3413 |
* frags into skb->data */ |
|
3414 |
hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
|
3415 |
if (skb->data_len && hdr_len == len) { |
|
3416 |
switch (hw->mac_type) { |
|
3417 |
unsigned int pull_size; |
|
3418 |
case e1000_82544: |
|
3419 |
/* Make sure we have room to chop off 4 bytes, |
|
3420 |
* and that the end alignment will work out to |
|
3421 |
* this hardware's requirements |
|
3422 |
* NOTE: this is a TSO only workaround |
|
3423 |
* if end byte alignment not correct move us |
|
3424 |
* into the next dword */ |
|
3425 |
if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4) |
|
3426 |
break; |
|
3427 |
/* fall through */ |
|
3428 |
case e1000_82571: |
|
3429 |
case e1000_82572: |
|
3430 |
case e1000_82573: |
|
3431 |
case e1000_ich8lan: |
|
3432 |
pull_size = min((unsigned int)4, skb->data_len); |
|
3433 |
if (!__pskb_pull_tail(skb, pull_size)) { |
|
3434 |
DPRINTK(DRV, ERR, |
|
3435 |
"__pskb_pull_tail failed.\n"); |
|
3436 |
dev_kfree_skb_any(skb); |
|
3437 |
return NETDEV_TX_OK; |
|
3438 |
} |
|
3439 |
len = skb->len - skb->data_len; |
|
3440 |
break; |
|
3441 |
default: |
|
3442 |
/* do nothing */ |
|
3443 |
break; |
|
3444 |
} |
|
3445 |
} |
|
3446 |
} |
|
3447 |
||
3448 |
/* reserve a descriptor for the offload context */ |
|
3449 |
if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
|
3450 |
count++; |
|
3451 |
count++; |
|
3452 |
||
3453 |
/* Controller Erratum workaround */ |
|
3454 |
if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb)) |
|
3455 |
count++; |
|
3456 |
||
3457 |
count += TXD_USE_COUNT(len, max_txd_pwr); |
|
3458 |
||
3459 |
if (adapter->pcix_82544) |
|
3460 |
count++; |
|
3461 |
||
3462 |
/* work-around for errata 10 and it applies to all controllers |
|
3463 |
* in PCI-X mode, so add one more descriptor to the count |
|
3464 |
*/ |
|
3465 |
if (unlikely((hw->bus_type == e1000_bus_type_pcix) && |
|
3466 |
(len > 2015))) |
|
3467 |
count++; |
|
3468 |
||
3469 |
nr_frags = skb_shinfo(skb)->nr_frags; |
|
3470 |
for (f = 0; f < nr_frags; f++) |
|
3471 |
count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
|
3472 |
max_txd_pwr); |
|
3473 |
if (adapter->pcix_82544) |
|
3474 |
count += nr_frags; |
|
3475 |
||
3476 |
||
3477 |
if (hw->tx_pkt_filtering && |
|
3478 |
(hw->mac_type == e1000_82573)) |
|
3479 |
e1000_transfer_dhcp_info(adapter, skb); |
|
3480 |
||
3481 |
if (!adapter->ecdev && |
|
3482 |
!spin_trylock_irqsave(&tx_ring->tx_lock, flags)) |
|
3483 |
/* Collision - tell upper layer to requeue */ |
|
3484 |
return NETDEV_TX_LOCKED; |
|
3485 |
||
3486 |
/* need: count + 2 desc gap to keep tail from touching |
|
3487 |
* head, otherwise try next time */ |
|
3488 |
if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) { |
|
3489 |
if (!adapter->ecdev) { |
|
3490 |
spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
|
3491 |
} |
|
3492 |
return NETDEV_TX_BUSY; |
|
3493 |
} |
|
3494 |
||
3495 |
if (unlikely(hw->mac_type == e1000_82547)) { |
|
3496 |
if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
|
3497 |
if (!adapter->ecdev) { |
|
3498 |
netif_stop_queue(netdev); |
|
3499 |
mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
|
3500 |
spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
|
3501 |
} |
|
3502 |
return NETDEV_TX_BUSY; |
|
3503 |
} |
|
3504 |
} |
|
3505 |
||
3506 |
if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
|
3507 |
tx_flags |= E1000_TX_FLAGS_VLAN; |
|
3508 |
tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
|
3509 |
} |
|
3510 |
||
3511 |
first = tx_ring->next_to_use; |
|
3512 |
||
3513 |
tso = e1000_tso(adapter, tx_ring, skb); |
|
3514 |
if (tso < 0) { |
|
3515 |
if (!adapter->ecdev) { |
|
3516 |
dev_kfree_skb_any(skb); |
|
3517 |
spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
|
3518 |
} |
|
3519 |
return NETDEV_TX_OK; |
|
3520 |
} |
|
3521 |
||
3522 |
if (likely(tso)) { |
|
3523 |
tx_ring->last_tx_tso = 1; |
|
3524 |
tx_flags |= E1000_TX_FLAGS_TSO; |
|
3525 |
} else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
|
3526 |
tx_flags |= E1000_TX_FLAGS_CSUM; |
|
3527 |
||
3528 |
/* Old method was to assume IPv4 packet by default if TSO was enabled. |
|
3529 |
* 82571 hardware supports TSO capabilities for IPv6 as well... |
|
3530 |
* no longer assume, we must. */ |
|
3531 |
if (likely(skb->protocol == htons(ETH_P_IP))) |
|
3532 |
tx_flags |= E1000_TX_FLAGS_IPV4; |
|
3533 |
||
3534 |
e1000_tx_queue(adapter, tx_ring, tx_flags, |
|
3535 |
e1000_tx_map(adapter, tx_ring, skb, first, |
|
3536 |
max_per_txd, nr_frags, mss)); |
|
3537 |
||
3538 |
netdev->trans_start = jiffies; |
|
3539 |
||
3540 |
if (!adapter->ecdev) { |
|
3541 |
/* Make sure there is space in the ring for the next send. */ |
|
3542 |
e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); |
|
3543 |
||
3544 |
spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
|
3545 |
} |
|
3546 |
return NETDEV_TX_OK; |
|
3547 |
} |
|
3548 |
||
3549 |
/** |
|
3550 |
* e1000_tx_timeout - Respond to a Tx Hang |
|
3551 |
* @netdev: network interface device structure |
|
3552 |
**/ |
|
3553 |
||
3554 |
static void e1000_tx_timeout(struct net_device *netdev) |
|
3555 |
{ |
|
3556 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3557 |
||
3558 |
/* Do the reset outside of interrupt context */ |
|
3559 |
adapter->tx_timeout_count++; |
|
3560 |
schedule_work(&adapter->reset_task); |
|
3561 |
} |
|
3562 |
||
3563 |
static void e1000_reset_task(struct work_struct *work) |
|
3564 |
{ |
|
3565 |
struct e1000_adapter *adapter = |
|
3566 |
container_of(work, struct e1000_adapter, reset_task); |
|
3567 |
||
3568 |
e1000_reinit_locked(adapter); |
|
3569 |
} |
|
3570 |
||
3571 |
/** |
|
3572 |
* e1000_get_stats - Get System Network Statistics |
|
3573 |
* @netdev: network interface device structure |
|
3574 |
* |
|
3575 |
* Returns the address of the device statistics structure. |
|
3576 |
* The statistics are actually updated from the timer callback. |
|
3577 |
**/ |
|
3578 |
||
3579 |
static struct net_device_stats *e1000_get_stats(struct net_device *netdev) |
|
3580 |
{ |
|
3581 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3582 |
||
3583 |
/* only return the current stats */ |
|
3584 |
return &adapter->net_stats; |
|
3585 |
} |
|
3586 |
||
3587 |
/** |
|
3588 |
* e1000_change_mtu - Change the Maximum Transfer Unit |
|
3589 |
* @netdev: network interface device structure |
|
3590 |
* @new_mtu: new value for maximum frame size |
|
3591 |
* |
|
3592 |
* Returns 0 on success, negative on failure |
|
3593 |
**/ |
|
3594 |
||
3595 |
static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
|
3596 |
{ |
|
3597 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3598 |
struct e1000_hw *hw = &adapter->hw; |
|
3599 |
int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
|
3600 |
u16 eeprom_data = 0; |
|
3601 |
||
3602 |
if (adapter->ecdev) |
|
3603 |
return -EBUSY; |
|
3604 |
||
3605 |
if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
|
3606 |
(max_frame > MAX_JUMBO_FRAME_SIZE)) { |
|
3607 |
DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
|
3608 |
return -EINVAL; |
|
3609 |
} |
|
3610 |
||
3611 |
/* Adapter-specific max frame size limits. */ |
|
3612 |
switch (hw->mac_type) { |
|
3613 |
case e1000_undefined ... e1000_82542_rev2_1: |
|
3614 |
case e1000_ich8lan: |
|
3615 |
if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
|
3616 |
DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
|
3617 |
return -EINVAL; |
|
3618 |
} |
|
3619 |
break; |
|
3620 |
case e1000_82573: |
|
3621 |
/* Jumbo Frames not supported if: |
|
3622 |
* - this is not an 82573L device |
|
3623 |
* - ASPM is enabled in any way (0x1A bits 3:2) */ |
|
3624 |
e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1, |
|
3625 |
&eeprom_data); |
|
3626 |
if ((hw->device_id != E1000_DEV_ID_82573L) || |
|
3627 |
(eeprom_data & EEPROM_WORD1A_ASPM_MASK)) { |
|
3628 |
if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
|
3629 |
DPRINTK(PROBE, ERR, |
|
3630 |
"Jumbo Frames not supported.\n"); |
|
3631 |
return -EINVAL; |
|
3632 |
} |
|
3633 |
break; |
|
3634 |
} |
|
3635 |
/* ERT will be enabled later to enable wire speed receives */ |
|
3636 |
||
3637 |
/* fall through to get support */ |
|
3638 |
case e1000_82571: |
|
3639 |
case e1000_82572: |
|
3640 |
case e1000_80003es2lan: |
|
3641 |
#define MAX_STD_JUMBO_FRAME_SIZE 9234 |
|
3642 |
if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
|
3643 |
DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
|
3644 |
return -EINVAL; |
|
3645 |
} |
|
3646 |
break; |
|
3647 |
default: |
|
3648 |
/* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
|
3649 |
break; |
|
3650 |
} |
|
3651 |
||
3652 |
/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
|
3653 |
* means we reserve 2 more, this pushes us to allocate from the next |
|
3654 |
* larger slab size |
|
3655 |
* i.e. RXBUFFER_2048 --> size-4096 slab */ |
|
3656 |
||
3657 |
if (max_frame <= E1000_RXBUFFER_256) |
|
3658 |
adapter->rx_buffer_len = E1000_RXBUFFER_256; |
|
3659 |
else if (max_frame <= E1000_RXBUFFER_512) |
|
3660 |
adapter->rx_buffer_len = E1000_RXBUFFER_512; |
|
3661 |
else if (max_frame <= E1000_RXBUFFER_1024) |
|
3662 |
adapter->rx_buffer_len = E1000_RXBUFFER_1024; |
|
3663 |
else if (max_frame <= E1000_RXBUFFER_2048) |
|
3664 |
adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
|
3665 |
else if (max_frame <= E1000_RXBUFFER_4096) |
|
3666 |
adapter->rx_buffer_len = E1000_RXBUFFER_4096; |
|
3667 |
else if (max_frame <= E1000_RXBUFFER_8192) |
|
3668 |
adapter->rx_buffer_len = E1000_RXBUFFER_8192; |
|
3669 |
else if (max_frame <= E1000_RXBUFFER_16384) |
|
3670 |
adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
|
3671 |
||
3672 |
/* adjust allocation if LPE protects us, and we aren't using SBP */ |
|
3673 |
if (!hw->tbi_compatibility_on && |
|
3674 |
((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) || |
|
3675 |
(max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) |
|
3676 |
adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
|
3677 |
||
3678 |
netdev->mtu = new_mtu; |
|
3679 |
hw->max_frame_size = max_frame; |
|
3680 |
||
3681 |
if (netif_running(netdev)) |
|
3682 |
e1000_reinit_locked(adapter); |
|
3683 |
||
3684 |
return 0; |
|
3685 |
} |
|
3686 |
||
3687 |
/** |
|
3688 |
* e1000_update_stats - Update the board statistics counters |
|
3689 |
* @adapter: board private structure |
|
3690 |
**/ |
|
3691 |
||
3692 |
void e1000_update_stats(struct e1000_adapter *adapter) |
|
3693 |
{ |
|
3694 |
struct e1000_hw *hw = &adapter->hw; |
|
3695 |
struct pci_dev *pdev = adapter->pdev; |
|
3696 |
unsigned long flags = 0; |
|
3697 |
u16 phy_tmp; |
|
3698 |
||
3699 |
#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
|
3700 |
||
3701 |
/* |
|
3702 |
* Prevent stats update while adapter is being reset, or if the pci |
|
3703 |
* connection is down. |
|
3704 |
*/ |
|
3705 |
if (adapter->link_speed == 0) |
|
3706 |
return; |
|
3707 |
if (pci_channel_offline(pdev)) |
|
3708 |
return; |
|
3709 |
||
3710 |
if (!adapter->ecdev) |
|
3711 |
spin_lock_irqsave(&adapter->stats_lock, flags); |
|
3712 |
||
3713 |
/* these counters are modified from e1000_tbi_adjust_stats, |
|
3714 |
* called from the interrupt context, so they must only |
|
3715 |
* be written while holding adapter->stats_lock |
|
3716 |
*/ |
|
3717 |
||
3718 |
adapter->stats.crcerrs += er32(CRCERRS); |
|
3719 |
adapter->stats.gprc += er32(GPRC); |
|
3720 |
adapter->stats.gorcl += er32(GORCL); |
|
3721 |
adapter->stats.gorch += er32(GORCH); |
|
3722 |
adapter->stats.bprc += er32(BPRC); |
|
3723 |
adapter->stats.mprc += er32(MPRC); |
|
3724 |
adapter->stats.roc += er32(ROC); |
|
3725 |
||
3726 |
if (hw->mac_type != e1000_ich8lan) { |
|
3727 |
adapter->stats.prc64 += er32(PRC64); |
|
3728 |
adapter->stats.prc127 += er32(PRC127); |
|
3729 |
adapter->stats.prc255 += er32(PRC255); |
|
3730 |
adapter->stats.prc511 += er32(PRC511); |
|
3731 |
adapter->stats.prc1023 += er32(PRC1023); |
|
3732 |
adapter->stats.prc1522 += er32(PRC1522); |
|
3733 |
} |
|
3734 |
||
3735 |
adapter->stats.symerrs += er32(SYMERRS); |
|
3736 |
adapter->stats.mpc += er32(MPC); |
|
3737 |
adapter->stats.scc += er32(SCC); |
|
3738 |
adapter->stats.ecol += er32(ECOL); |
|
3739 |
adapter->stats.mcc += er32(MCC); |
|
3740 |
adapter->stats.latecol += er32(LATECOL); |
|
3741 |
adapter->stats.dc += er32(DC); |
|
3742 |
adapter->stats.sec += er32(SEC); |
|
3743 |
adapter->stats.rlec += er32(RLEC); |
|
3744 |
adapter->stats.xonrxc += er32(XONRXC); |
|
3745 |
adapter->stats.xontxc += er32(XONTXC); |
|
3746 |
adapter->stats.xoffrxc += er32(XOFFRXC); |
|
3747 |
adapter->stats.xofftxc += er32(XOFFTXC); |
|
3748 |
adapter->stats.fcruc += er32(FCRUC); |
|
3749 |
adapter->stats.gptc += er32(GPTC); |
|
3750 |
adapter->stats.gotcl += er32(GOTCL); |
|
3751 |
adapter->stats.gotch += er32(GOTCH); |
|
3752 |
adapter->stats.rnbc += er32(RNBC); |
|
3753 |
adapter->stats.ruc += er32(RUC); |
|
3754 |
adapter->stats.rfc += er32(RFC); |
|
3755 |
adapter->stats.rjc += er32(RJC); |
|
3756 |
adapter->stats.torl += er32(TORL); |
|
3757 |
adapter->stats.torh += er32(TORH); |
|
3758 |
adapter->stats.totl += er32(TOTL); |
|
3759 |
adapter->stats.toth += er32(TOTH); |
|
3760 |
adapter->stats.tpr += er32(TPR); |
|
3761 |
||
3762 |
if (hw->mac_type != e1000_ich8lan) { |
|
3763 |
adapter->stats.ptc64 += er32(PTC64); |
|
3764 |
adapter->stats.ptc127 += er32(PTC127); |
|
3765 |
adapter->stats.ptc255 += er32(PTC255); |
|
3766 |
adapter->stats.ptc511 += er32(PTC511); |
|
3767 |
adapter->stats.ptc1023 += er32(PTC1023); |
|
3768 |
adapter->stats.ptc1522 += er32(PTC1522); |
|
3769 |
} |
|
3770 |
||
3771 |
adapter->stats.mptc += er32(MPTC); |
|
3772 |
adapter->stats.bptc += er32(BPTC); |
|
3773 |
||
3774 |
/* used for adaptive IFS */ |
|
3775 |
||
3776 |
hw->tx_packet_delta = er32(TPT); |
|
3777 |
adapter->stats.tpt += hw->tx_packet_delta; |
|
3778 |
hw->collision_delta = er32(COLC); |
|
3779 |
adapter->stats.colc += hw->collision_delta; |
|
3780 |
||
3781 |
if (hw->mac_type >= e1000_82543) { |
|
3782 |
adapter->stats.algnerrc += er32(ALGNERRC); |
|
3783 |
adapter->stats.rxerrc += er32(RXERRC); |
|
3784 |
adapter->stats.tncrs += er32(TNCRS); |
|
3785 |
adapter->stats.cexterr += er32(CEXTERR); |
|
3786 |
adapter->stats.tsctc += er32(TSCTC); |
|
3787 |
adapter->stats.tsctfc += er32(TSCTFC); |
|
3788 |
} |
|
3789 |
if (hw->mac_type > e1000_82547_rev_2) { |
|
3790 |
adapter->stats.iac += er32(IAC); |
|
3791 |
adapter->stats.icrxoc += er32(ICRXOC); |
|
3792 |
||
3793 |
if (hw->mac_type != e1000_ich8lan) { |
|
3794 |
adapter->stats.icrxptc += er32(ICRXPTC); |
|
3795 |
adapter->stats.icrxatc += er32(ICRXATC); |
|
3796 |
adapter->stats.ictxptc += er32(ICTXPTC); |
|
3797 |
adapter->stats.ictxatc += er32(ICTXATC); |
|
3798 |
adapter->stats.ictxqec += er32(ICTXQEC); |
|
3799 |
adapter->stats.ictxqmtc += er32(ICTXQMTC); |
|
3800 |
adapter->stats.icrxdmtc += er32(ICRXDMTC); |
|
3801 |
} |
|
3802 |
} |
|
3803 |
||
3804 |
/* Fill out the OS statistics structure */ |
|
3805 |
adapter->net_stats.multicast = adapter->stats.mprc; |
|
3806 |
adapter->net_stats.collisions = adapter->stats.colc; |
|
3807 |
||
3808 |
/* Rx Errors */ |
|
3809 |
||
3810 |
/* RLEC on some newer hardware can be incorrect so build |
|
3811 |
* our own version based on RUC and ROC */ |
|
3812 |
adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
|
3813 |
adapter->stats.crcerrs + adapter->stats.algnerrc + |
|
3814 |
adapter->stats.ruc + adapter->stats.roc + |
|
3815 |
adapter->stats.cexterr; |
|
3816 |
adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; |
|
3817 |
adapter->net_stats.rx_length_errors = adapter->stats.rlerrc; |
|
3818 |
adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
|
3819 |
adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
|
3820 |
adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
|
3821 |
||
3822 |
/* Tx Errors */ |
|
3823 |
adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; |
|
3824 |
adapter->net_stats.tx_errors = adapter->stats.txerrc; |
|
3825 |
adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
|
3826 |
adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
|
3827 |
adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
|
3828 |
if (hw->bad_tx_carr_stats_fd && |
|
3829 |
adapter->link_duplex == FULL_DUPLEX) { |
|
3830 |
adapter->net_stats.tx_carrier_errors = 0; |
|
3831 |
adapter->stats.tncrs = 0; |
|
3832 |
} |
|
3833 |
||
3834 |
/* Tx Dropped needs to be maintained elsewhere */ |
|
3835 |
||
3836 |
/* Phy Stats */ |
|
3837 |
if (hw->media_type == e1000_media_type_copper) { |
|
3838 |
if ((adapter->link_speed == SPEED_1000) && |
|
3839 |
(!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
|
3840 |
phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
|
3841 |
adapter->phy_stats.idle_errors += phy_tmp; |
|
3842 |
} |
|
3843 |
||
3844 |
if ((hw->mac_type <= e1000_82546) && |
|
3845 |
(hw->phy_type == e1000_phy_m88) && |
|
3846 |
!e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
|
3847 |
adapter->phy_stats.receive_errors += phy_tmp; |
|
3848 |
} |
|
3849 |
||
3850 |
/* Management Stats */ |
|
3851 |
if (hw->has_smbus) { |
|
3852 |
adapter->stats.mgptc += er32(MGTPTC); |
|
3853 |
adapter->stats.mgprc += er32(MGTPRC); |
|
3854 |
adapter->stats.mgpdc += er32(MGTPDC); |
|
3855 |
} |
|
3856 |
||
3857 |
if (!adapter->ecdev) |
|
3858 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
3859 |
} |
|
3860 |
||
3861 |
void ec_poll(struct net_device *netdev) |
|
3862 |
{ |
|
3863 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3864 |
||
3865 |
if (jiffies - adapter->ec_watchdog_jiffies >= 2 * HZ) { |
|
3866 |
e1000_watchdog((unsigned long) adapter); |
|
3867 |
adapter->ec_watchdog_jiffies = jiffies; |
|
3868 |
} |
|
3869 |
||
3870 |
#ifdef CONFIG_PCI_MSI |
|
3871 |
e1000_intr_msi(0, netdev); |
|
3872 |
#else |
|
3873 |
e1000_intr(0, netdev); |
|
3874 |
#endif |
|
3875 |
} |
|
3876 |
||
3877 |
/** |
|
3878 |
* e1000_intr_msi - Interrupt Handler |
|
3879 |
* @irq: interrupt number |
|
3880 |
* @data: pointer to a network interface device structure |
|
3881 |
**/ |
|
3882 |
||
3883 |
static irqreturn_t e1000_intr_msi(int irq, void *data) |
|
3884 |
{ |
|
3885 |
struct net_device *netdev = data; |
|
3886 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3887 |
struct e1000_hw *hw = &adapter->hw; |
|
3888 |
u32 icr = er32(ICR); |
|
3889 |
||
3890 |
if (adapter->ecdev) { |
|
3891 |
int i, ec_work_done = 0; |
|
3892 |
for (i = 0; i < E1000_MAX_INTR; i++) { |
|
3893 |
if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring, |
|
2050
a3e59f2a8589
Changed accidentally used & operator to &&.
Florian Pose <fp@igh-essen.com>
parents:
1900
diff
changeset
|
3894 |
&ec_work_done, 100) && |
1900 | 3895 |
!e1000_clean_tx_irq(adapter, adapter->tx_ring))) { |
3896 |
break; |
|
3897 |
} |
|
3898 |
} |
|
3899 |
} else { |
|
3900 |
/* in NAPI mode read ICR disables interrupts using IAM */ |
|
3901 |
||
3902 |
if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
|
3903 |
hw->get_link_status = 1; |
|
3904 |
/* 80003ES2LAN workaround-- For packet buffer work-around on |
|
3905 |
* link down event; disable receives here in the ISR and reset |
|
3906 |
* adapter in watchdog */ |
|
3907 |
if (netif_carrier_ok(netdev) && |
|
3908 |
(hw->mac_type == e1000_80003es2lan)) { |
|
3909 |
/* disable receives */ |
|
3910 |
u32 rctl = er32(RCTL); |
|
3911 |
ew32(RCTL, rctl & ~E1000_RCTL_EN); |
|
3912 |
} |
|
3913 |
/* guard against interrupt when we're going down */ |
|
3914 |
if (!test_bit(__E1000_DOWN, &adapter->flags)) |
|
3915 |
mod_timer(&adapter->watchdog_timer, jiffies + 1); |
|
3916 |
} |
|
3917 |
||
3918 |
if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) { |
|
3919 |
adapter->total_tx_bytes = 0; |
|
3920 |
adapter->total_tx_packets = 0; |
|
3921 |
adapter->total_rx_bytes = 0; |
|
3922 |
adapter->total_rx_packets = 0; |
|
3923 |
__netif_rx_schedule(netdev, &adapter->napi); |
|
3924 |
} else |
|
3925 |
e1000_irq_enable(adapter); |
|
3926 |
} |
|
3927 |
||
3928 |
return IRQ_HANDLED; |
|
3929 |
} |
|
3930 |
||
3931 |
/** |
|
3932 |
* e1000_intr - Interrupt Handler |
|
3933 |
* @irq: interrupt number |
|
3934 |
* @data: pointer to a network interface device structure |
|
3935 |
**/ |
|
3936 |
||
3937 |
static irqreturn_t e1000_intr(int irq, void *data) |
|
3938 |
{ |
|
3939 |
struct net_device *netdev = data; |
|
3940 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3941 |
struct e1000_hw *hw = &adapter->hw; |
|
3942 |
u32 rctl, icr = er32(ICR); |
|
3943 |
||
3944 |
if (unlikely((!icr) || test_bit(__E1000_RESETTING, &adapter->flags))) |
|
3945 |
return IRQ_NONE; /* Not our interrupt */ |
|
3946 |
||
3947 |
/* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
|
3948 |
* not set, then the adapter didn't send an interrupt */ |
|
3949 |
if (unlikely(hw->mac_type >= e1000_82571 && |
|
3950 |
!(icr & E1000_ICR_INT_ASSERTED))) |
|
3951 |
return IRQ_NONE; |
|
3952 |
||
3953 |
/* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No |
|
3954 |
* need for the IMC write */ |
|
3955 |
||
3956 |
if (!adapter->ecdev && unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
|
3957 |
hw->get_link_status = 1; |
|
3958 |
/* 80003ES2LAN workaround-- |
|
3959 |
* For packet buffer work-around on link down event; |
|
3960 |
* disable receives here in the ISR and |
|
3961 |
* reset adapter in watchdog |
|
3962 |
*/ |
|
3963 |
if (netif_carrier_ok(netdev) && |
|
3964 |
(hw->mac_type == e1000_80003es2lan)) { |
|
3965 |
/* disable receives */ |
|
3966 |
rctl = er32(RCTL); |
|
3967 |
ew32(RCTL, rctl & ~E1000_RCTL_EN); |
|
3968 |
} |
|
3969 |
/* guard against interrupt when we're going down */ |
|
3970 |
if (!test_bit(__E1000_DOWN, &adapter->flags)) |
|
3971 |
mod_timer(&adapter->watchdog_timer, jiffies + 1); |
|
3972 |
} |
|
3973 |
||
3974 |
if (adapter->ecdev) { |
|
3975 |
int i, ec_work_done = 0; |
|
3976 |
for (i = 0; i < E1000_MAX_INTR; i++) { |
|
3977 |
if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring, |
|
2050
a3e59f2a8589
Changed accidentally used & operator to &&.
Florian Pose <fp@igh-essen.com>
parents:
1900
diff
changeset
|
3978 |
&ec_work_done, 100) && |
1900 | 3979 |
!e1000_clean_tx_irq(adapter, adapter->tx_ring))) { |
3980 |
break; |
|
3981 |
} |
|
3982 |
} |
|
3983 |
} else { |
|
3984 |
if (unlikely(hw->mac_type < e1000_82571)) { |
|
3985 |
/* disable interrupts, without the synchronize_irq bit */ |
|
3986 |
ew32(IMC, ~0); |
|
3987 |
E1000_WRITE_FLUSH(); |
|
3988 |
} |
|
3989 |
if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) { |
|
3990 |
adapter->total_tx_bytes = 0; |
|
3991 |
adapter->total_tx_packets = 0; |
|
3992 |
adapter->total_rx_bytes = 0; |
|
3993 |
adapter->total_rx_packets = 0; |
|
3994 |
__netif_rx_schedule(netdev, &adapter->napi); |
|
3995 |
} else |
|
3996 |
/* this really should not happen! if it does it is basically a |
|
3997 |
* bug, but not a hard error, so enable ints and continue */ |
|
3998 |
e1000_irq_enable(adapter); |
|
3999 |
} |
|
4000 |
||
4001 |
return IRQ_HANDLED; |
|
4002 |
} |
|
4003 |
||
4004 |
/** |
|
4005 |
* e1000_clean - NAPI Rx polling callback |
|
4006 |
* @adapter: board private structure |
|
4007 |
* EtherCAT: never called |
|
4008 |
**/ |
|
4009 |
static int e1000_clean(struct napi_struct *napi, int budget) |
|
4010 |
{ |
|
4011 |
struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
|
4012 |
struct net_device *poll_dev = adapter->netdev; |
|
4013 |
int tx_cleaned = 0, work_done = 0; |
|
4014 |
||
4015 |
/* Must NOT use netdev_priv macro here. */ |
|
4016 |
adapter = poll_dev->priv; |
|
4017 |
||
4018 |
/* e1000_clean is called per-cpu. This lock protects |
|
4019 |
* tx_ring[0] from being cleaned by multiple cpus |
|
4020 |
* simultaneously. A failure obtaining the lock means |
|
4021 |
* tx_ring[0] is currently being cleaned anyway. */ |
|
4022 |
if (spin_trylock(&adapter->tx_queue_lock)) { |
|
4023 |
tx_cleaned = e1000_clean_tx_irq(adapter, |
|
4024 |
&adapter->tx_ring[0]); |
|
4025 |
spin_unlock(&adapter->tx_queue_lock); |
|
4026 |
} |
|
4027 |
||
4028 |
adapter->clean_rx(adapter, &adapter->rx_ring[0], |
|
4029 |
&work_done, budget); |
|
4030 |
||
4031 |
if (tx_cleaned) |
|
4032 |
work_done = budget; |
|
4033 |
||
4034 |
/* If budget not fully consumed, exit the polling mode */ |
|
4035 |
if (work_done < budget) { |
|
4036 |
if (likely(adapter->itr_setting & 3)) |
|
4037 |
e1000_set_itr(adapter); |
|
4038 |
netif_rx_complete(poll_dev, napi); |
|
4039 |
e1000_irq_enable(adapter); |
|
4040 |
} |
|
4041 |
||
4042 |
return work_done; |
|
4043 |
} |
|
4044 |
||
4045 |
/** |
|
4046 |
* e1000_clean_tx_irq - Reclaim resources after transmit completes |
|
4047 |
* @adapter: board private structure |
|
4048 |
**/ |
|
4049 |
static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, |
|
4050 |
struct e1000_tx_ring *tx_ring) |
|
4051 |
{ |
|
4052 |
struct e1000_hw *hw = &adapter->hw; |
|
4053 |
struct net_device *netdev = adapter->netdev; |
|
4054 |
struct e1000_tx_desc *tx_desc, *eop_desc; |
|
4055 |
struct e1000_buffer *buffer_info; |
|
4056 |
unsigned int i, eop; |
|
4057 |
unsigned int count = 0; |
|
4058 |
bool cleaned = false; |
|
4059 |
unsigned int total_tx_bytes=0, total_tx_packets=0; |
|
4060 |
||
4061 |
i = tx_ring->next_to_clean; |
|
4062 |
eop = tx_ring->buffer_info[i].next_to_watch; |
|
4063 |
eop_desc = E1000_TX_DESC(*tx_ring, eop); |
|
4064 |
||
4065 |
while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { |
|
4066 |
for (cleaned = false; !cleaned; ) { |
|
4067 |
tx_desc = E1000_TX_DESC(*tx_ring, i); |
|
4068 |
buffer_info = &tx_ring->buffer_info[i]; |
|
4069 |
cleaned = (i == eop); |
|
4070 |
||
4071 |
if (cleaned) { |
|
4072 |
struct sk_buff *skb = buffer_info->skb; |
|
4073 |
unsigned int segs, bytecount; |
|
4074 |
segs = skb_shinfo(skb)->gso_segs ?: 1; |
|
4075 |
/* multiply data chunks by size of headers */ |
|
4076 |
bytecount = ((segs - 1) * skb_headlen(skb)) + |
|
4077 |
skb->len; |
|
4078 |
total_tx_packets += segs; |
|
4079 |
total_tx_bytes += bytecount; |
|
4080 |
} |
|
4081 |
e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
|
4082 |
tx_desc->upper.data = 0; |
|
4083 |
||
4084 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
4085 |
} |
|
4086 |
||
4087 |
eop = tx_ring->buffer_info[i].next_to_watch; |
|
4088 |
eop_desc = E1000_TX_DESC(*tx_ring, eop); |
|
4089 |
#define E1000_TX_WEIGHT 64 |
|
4090 |
/* weight of a sort for tx, to avoid endless transmit cleanup */ |
|
4091 |
if (count++ == E1000_TX_WEIGHT) |
|
4092 |
break; |
|
4093 |
} |
|
4094 |
||
4095 |
tx_ring->next_to_clean = i; |
|
4096 |
||
4097 |
#define TX_WAKE_THRESHOLD 32 |
|
4098 |
if (!adapter->ecdev && unlikely(cleaned && netif_carrier_ok(netdev) && |
|
4099 |
E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { |
|
4100 |
/* Make sure that anybody stopping the queue after this |
|
4101 |
* sees the new next_to_clean. |
|
4102 |
*/ |
|
4103 |
smp_mb(); |
|
4104 |
if (netif_queue_stopped(netdev)) { |
|
4105 |
netif_wake_queue(netdev); |
|
4106 |
++adapter->restart_queue; |
|
4107 |
} |
|
4108 |
} |
|
4109 |
||
4110 |
if (!adapter->ecdev && adapter->detect_tx_hung) { |
|
4111 |
/* Detect a transmit hang in hardware, this serializes the |
|
4112 |
* check with the clearing of time_stamp and movement of i */ |
|
4113 |
adapter->detect_tx_hung = false; |
|
4114 |
if (tx_ring->buffer_info[eop].dma && |
|
4115 |
time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + |
|
4116 |
(adapter->tx_timeout_factor * HZ)) |
|
4117 |
&& !(er32(STATUS) & E1000_STATUS_TXOFF)) { |
|
4118 |
||
4119 |
/* detected Tx unit hang */ |
|
4120 |
DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
|
4121 |
" Tx Queue <%lu>\n" |
|
4122 |
" TDH <%x>\n" |
|
4123 |
" TDT <%x>\n" |
|
4124 |
" next_to_use <%x>\n" |
|
4125 |
" next_to_clean <%x>\n" |
|
4126 |
"buffer_info[next_to_clean]\n" |
|
4127 |
" time_stamp <%lx>\n" |
|
4128 |
" next_to_watch <%x>\n" |
|
4129 |
" jiffies <%lx>\n" |
|
4130 |
" next_to_watch.status <%x>\n", |
|
4131 |
(unsigned long)((tx_ring - adapter->tx_ring) / |
|
4132 |
sizeof(struct e1000_tx_ring)), |
|
4133 |
readl(hw->hw_addr + tx_ring->tdh), |
|
4134 |
readl(hw->hw_addr + tx_ring->tdt), |
|
4135 |
tx_ring->next_to_use, |
|
4136 |
tx_ring->next_to_clean, |
|
4137 |
tx_ring->buffer_info[eop].time_stamp, |
|
4138 |
eop, |
|
4139 |
jiffies, |
|
4140 |
eop_desc->upper.fields.status); |
|
4141 |
netif_stop_queue(netdev); |
|
4142 |
} |
|
4143 |
} |
|
4144 |
adapter->total_tx_bytes += total_tx_bytes; |
|
4145 |
adapter->total_tx_packets += total_tx_packets; |
|
4146 |
adapter->net_stats.tx_bytes += total_tx_bytes; |
|
4147 |
adapter->net_stats.tx_packets += total_tx_packets; |
|
4148 |
return cleaned; |
|
4149 |
} |
|
4150 |
||
4151 |
/** |
|
4152 |
* e1000_rx_checksum - Receive Checksum Offload for 82543 |
|
4153 |
* @adapter: board private structure |
|
4154 |
* @status_err: receive descriptor status and error fields |
|
4155 |
* @csum: receive descriptor csum field |
|
4156 |
* @sk_buff: socket buffer with received data |
|
4157 |
**/ |
|
4158 |
||
4159 |
static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
|
4160 |
u32 csum, struct sk_buff *skb) |
|
4161 |
{ |
|
4162 |
struct e1000_hw *hw = &adapter->hw; |
|
4163 |
u16 status = (u16)status_err; |
|
4164 |
u8 errors = (u8)(status_err >> 24); |
|
4165 |
skb->ip_summed = CHECKSUM_NONE; |
|
4166 |
||
4167 |
/* 82543 or newer only */ |
|
4168 |
if (unlikely(hw->mac_type < e1000_82543)) return; |
|
4169 |
/* Ignore Checksum bit is set */ |
|
4170 |
if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
|
4171 |
/* TCP/UDP checksum error bit is set */ |
|
4172 |
if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
|
4173 |
/* let the stack verify checksum errors */ |
|
4174 |
adapter->hw_csum_err++; |
|
4175 |
return; |
|
4176 |
} |
|
4177 |
/* TCP/UDP Checksum has not been calculated */ |
|
4178 |
if (hw->mac_type <= e1000_82547_rev_2) { |
|
4179 |
if (!(status & E1000_RXD_STAT_TCPCS)) |
|
4180 |
return; |
|
4181 |
} else { |
|
4182 |
if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
|
4183 |
return; |
|
4184 |
} |
|
4185 |
/* It must be a TCP or UDP packet with a valid checksum */ |
|
4186 |
if (likely(status & E1000_RXD_STAT_TCPCS)) { |
|
4187 |
/* TCP checksum is good */ |
|
4188 |
skb->ip_summed = CHECKSUM_UNNECESSARY; |
|
4189 |
} else if (hw->mac_type > e1000_82547_rev_2) { |
|
4190 |
/* IP fragment with UDP payload */ |
|
4191 |
/* Hardware complements the payload checksum, so we undo it |
|
4192 |
* and then put the value in host order for further stack use. |
|
4193 |
*/ |
|
4194 |
__sum16 sum = (__force __sum16)htons(csum); |
|
4195 |
skb->csum = csum_unfold(~sum); |
|
4196 |
skb->ip_summed = CHECKSUM_COMPLETE; |
|
4197 |
} |
|
4198 |
adapter->hw_csum_good++; |
|
4199 |
} |
|
4200 |
||
4201 |
/** |
|
4202 |
* e1000_clean_rx_irq - Send received data up the network stack; legacy |
|
4203 |
* @adapter: board private structure |
|
4204 |
**/ |
|
4205 |
static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
|
4206 |
struct e1000_rx_ring *rx_ring, |
|
4207 |
int *work_done, int work_to_do) |
|
4208 |
{ |
|
4209 |
struct e1000_hw *hw = &adapter->hw; |
|
4210 |
struct net_device *netdev = adapter->netdev; |
|
4211 |
struct pci_dev *pdev = adapter->pdev; |
|
4212 |
struct e1000_rx_desc *rx_desc, *next_rxd; |
|
4213 |
struct e1000_buffer *buffer_info, *next_buffer; |
|
4214 |
unsigned long flags; |
|
4215 |
u32 length; |
|
4216 |
u8 last_byte; |
|
4217 |
unsigned int i; |
|
4218 |
int cleaned_count = 0; |
|
4219 |
bool cleaned = false; |
|
4220 |
unsigned int total_rx_bytes=0, total_rx_packets=0; |
|
4221 |
||
4222 |
i = rx_ring->next_to_clean; |
|
4223 |
rx_desc = E1000_RX_DESC(*rx_ring, i); |
|
4224 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4225 |
||
4226 |
while (rx_desc->status & E1000_RXD_STAT_DD) { |
|
4227 |
struct sk_buff *skb; |
|
4228 |
u8 status; |
|
4229 |
||
4230 |
if (*work_done >= work_to_do) |
|
4231 |
break; |
|
4232 |
(*work_done)++; |
|
4233 |
||
4234 |
status = rx_desc->status; |
|
4235 |
skb = buffer_info->skb; |
|
4236 |
if (!adapter->ecdev) buffer_info->skb = NULL; |
|
4237 |
||
4238 |
prefetch(skb->data - NET_IP_ALIGN); |
|
4239 |
||
4240 |
if (++i == rx_ring->count) i = 0; |
|
4241 |
next_rxd = E1000_RX_DESC(*rx_ring, i); |
|
4242 |
prefetch(next_rxd); |
|
4243 |
||
4244 |
next_buffer = &rx_ring->buffer_info[i]; |
|
4245 |
||
4246 |
cleaned = true; |
|
4247 |
cleaned_count++; |
|
4248 |
pci_unmap_single(pdev, |
|
4249 |
buffer_info->dma, |
|
4250 |
buffer_info->length, |
|
4251 |
PCI_DMA_FROMDEVICE); |
|
4252 |
||
4253 |
length = le16_to_cpu(rx_desc->length); |
|
4254 |
/* !EOP means multiple descriptors were used to store a single |
|
4255 |
* packet, if thats the case we need to toss it. In fact, we |
|
4256 |
* to toss every packet with the EOP bit clear and the next |
|
4257 |
* frame that _does_ have the EOP bit set, as it is by |
|
4258 |
* definition only a frame fragment |
|
4259 |
*/ |
|
4260 |
if (unlikely(!(status & E1000_RXD_STAT_EOP))) |
|
4261 |
set_bit(__E1000_DISCARDING, &adapter->flags); |
|
4262 |
||
4263 |
if (test_bit(__E1000_DISCARDING, &adapter->flags)) { |
|
4264 |
/* All receives must fit into a single buffer */ |
|
4265 |
E1000_DBG("%s: Receive packet consumed multiple" |
|
4266 |
" buffers\n", netdev->name); |
|
4267 |
/* recycle */ |
|
4268 |
buffer_info->skb = skb; |
|
4269 |
if (status & E1000_RXD_STAT_EOP) |
|
4270 |
clear_bit(__E1000_DISCARDING, &adapter->flags); |
|
4271 |
goto next_desc; |
|
4272 |
} |
|
4273 |
||
4274 |
if (!adapter->ecdev && |
|
4275 |
unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
|
4276 |
last_byte = *(skb->data + length - 1); |
|
4277 |
if (TBI_ACCEPT(hw, status, rx_desc->errors, length, |
|
4278 |
last_byte)) { |
|
4279 |
spin_lock_irqsave(&adapter->stats_lock, flags); |
|
4280 |
e1000_tbi_adjust_stats(hw, &adapter->stats, |
|
4281 |
length, skb->data); |
|
4282 |
spin_unlock_irqrestore(&adapter->stats_lock, |
|
4283 |
flags); |
|
4284 |
length--; |
|
4285 |
} else { |
|
4286 |
/* recycle */ |
|
4287 |
buffer_info->skb = skb; |
|
4288 |
goto next_desc; |
|
4289 |
} |
|
4290 |
} |
|
4291 |
||
4292 |
/* adjust length to remove Ethernet CRC, this must be |
|
4293 |
* done after the TBI_ACCEPT workaround above */ |
|
4294 |
length -= 4; |
|
4295 |
||
4296 |
/* probably a little skewed due to removing CRC */ |
|
4297 |
total_rx_bytes += length; |
|
4298 |
total_rx_packets++; |
|
4299 |
||
4300 |
/* code added for copybreak, this should improve |
|
4301 |
* performance for small packets with large amounts |
|
4302 |
* of reassembly being done in the stack */ |
|
4303 |
if (!adapter->ecdev && length < copybreak) { |
|
4304 |
struct sk_buff *new_skb = |
|
4305 |
netdev_alloc_skb(netdev, length + NET_IP_ALIGN); |
|
4306 |
if (new_skb) { |
|
4307 |
skb_reserve(new_skb, NET_IP_ALIGN); |
|
4308 |
skb_copy_to_linear_data_offset(new_skb, |
|
4309 |
-NET_IP_ALIGN, |
|
4310 |
(skb->data - |
|
4311 |
NET_IP_ALIGN), |
|
4312 |
(length + |
|
4313 |
NET_IP_ALIGN)); |
|
4314 |
/* save the skb in buffer_info as good */ |
|
4315 |
buffer_info->skb = skb; |
|
4316 |
skb = new_skb; |
|
4317 |
} |
|
4318 |
/* else just continue with the old one */ |
|
4319 |
} |
|
4320 |
/* end copybreak code */ |
|
4321 |
skb_put(skb, length); |
|
4322 |
||
4323 |
/* Receive Checksum Offload */ |
|
4324 |
e1000_rx_checksum(adapter, |
|
4325 |
(u32)(status) | |
|
4326 |
((u32)(rx_desc->errors) << 24), |
|
4327 |
le16_to_cpu(rx_desc->csum), skb); |
|
4328 |
||
4329 |
if (adapter->ecdev) { |
|
4330 |
ecdev_receive(adapter->ecdev, skb->data, length); |
|
4331 |
||
4332 |
// No need to detect link status as |
|
4333 |
// long as frames are received: Reset watchdog. |
|
4334 |
adapter->ec_watchdog_jiffies = jiffies; |
|
4335 |
} else { |
|
4336 |
skb->protocol = eth_type_trans(skb, netdev); |
|
4337 |
||
4338 |
if (unlikely(adapter->vlgrp && |
|
4339 |
(status & E1000_RXD_STAT_VP))) { |
|
4340 |
vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
|
4341 |
le16_to_cpu(rx_desc->special)); |
|
4342 |
} else { |
|
4343 |
netif_receive_skb(skb); |
|
4344 |
} |
|
4345 |
} |
|
4346 |
||
4347 |
netdev->last_rx = jiffies; |
|
4348 |
||
4349 |
next_desc: |
|
4350 |
rx_desc->status = 0; |
|
4351 |
||
4352 |
/* return some buffers to hardware, one at a time is too slow */ |
|
4353 |
if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
|
4354 |
adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
|
4355 |
cleaned_count = 0; |
|
4356 |
} |
|
4357 |
||
4358 |
/* use prefetched values */ |
|
4359 |
rx_desc = next_rxd; |
|
4360 |
buffer_info = next_buffer; |
|
4361 |
} |
|
4362 |
rx_ring->next_to_clean = i; |
|
4363 |
||
4364 |
cleaned_count = E1000_DESC_UNUSED(rx_ring); |
|
4365 |
if (cleaned_count) |
|
4366 |
adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
|
4367 |
||
4368 |
adapter->total_rx_packets += total_rx_packets; |
|
4369 |
adapter->total_rx_bytes += total_rx_bytes; |
|
4370 |
adapter->net_stats.rx_bytes += total_rx_bytes; |
|
4371 |
adapter->net_stats.rx_packets += total_rx_packets; |
|
4372 |
return cleaned; |
|
4373 |
} |
|
4374 |
||
4375 |
/** |
|
4376 |
* e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
|
4377 |
* @adapter: board private structure |
|
4378 |
**/ |
|
4379 |
||
4380 |
static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
|
4381 |
struct e1000_rx_ring *rx_ring, |
|
4382 |
int *work_done, int work_to_do) |
|
4383 |
{ |
|
4384 |
union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
|
4385 |
struct net_device *netdev = adapter->netdev; |
|
4386 |
struct pci_dev *pdev = adapter->pdev; |
|
4387 |
struct e1000_buffer *buffer_info, *next_buffer; |
|
4388 |
struct e1000_ps_page *ps_page; |
|
4389 |
struct e1000_ps_page_dma *ps_page_dma; |
|
4390 |
struct sk_buff *skb; |
|
4391 |
unsigned int i, j; |
|
4392 |
u32 length, staterr; |
|
4393 |
int cleaned_count = 0; |
|
4394 |
bool cleaned = false; |
|
4395 |
unsigned int total_rx_bytes=0, total_rx_packets=0; |
|
4396 |
||
4397 |
i = rx_ring->next_to_clean; |
|
4398 |
rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
|
4399 |
staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
|
4400 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4401 |
||
4402 |
while (staterr & E1000_RXD_STAT_DD) { |
|
4403 |
ps_page = &rx_ring->ps_page[i]; |
|
4404 |
ps_page_dma = &rx_ring->ps_page_dma[i]; |
|
4405 |
||
4406 |
if (unlikely(*work_done >= work_to_do)) |
|
4407 |
break; |
|
4408 |
(*work_done)++; |
|
4409 |
||
4410 |
skb = buffer_info->skb; |
|
4411 |
||
4412 |
/* in the packet split case this is header only */ |
|
4413 |
prefetch(skb->data - NET_IP_ALIGN); |
|
4414 |
||
4415 |
if (++i == rx_ring->count) i = 0; |
|
4416 |
next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
|
4417 |
prefetch(next_rxd); |
|
4418 |
||
4419 |
next_buffer = &rx_ring->buffer_info[i]; |
|
4420 |
||
4421 |
cleaned = true; |
|
4422 |
cleaned_count++; |
|
4423 |
pci_unmap_single(pdev, buffer_info->dma, |
|
4424 |
buffer_info->length, |
|
4425 |
PCI_DMA_FROMDEVICE); |
|
4426 |
||
4427 |
if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) { |
|
4428 |
E1000_DBG("%s: Packet Split buffers didn't pick up" |
|
4429 |
" the full packet\n", netdev->name); |
|
4430 |
if (!adapter->ecdev) dev_kfree_skb_irq(skb); |
|
4431 |
goto next_desc; |
|
4432 |
} |
|
4433 |
||
4434 |
if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) { |
|
4435 |
if (!adapter->ecdev) dev_kfree_skb_irq(skb); |
|
4436 |
goto next_desc; |
|
4437 |
} |
|
4438 |
||
4439 |
length = le16_to_cpu(rx_desc->wb.middle.length0); |
|
4440 |
||
4441 |
if (unlikely(!length)) { |
|
4442 |
E1000_DBG("%s: Last part of the packet spanning" |
|
4443 |
" multiple descriptors\n", netdev->name); |
|
4444 |
if (!adapter->ecdev) dev_kfree_skb_irq(skb); |
|
4445 |
goto next_desc; |
|
4446 |
} |
|
4447 |
||
4448 |
/* Good Receive */ |
|
4449 |
skb_put(skb, length); |
|
4450 |
||
4451 |
{ |
|
4452 |
/* this looks ugly, but it seems compiler issues make it |
|
4453 |
more efficient than reusing j */ |
|
4454 |
int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
|
4455 |
||
4456 |
/* page alloc/put takes too long and effects small packet |
|
4457 |
* throughput, so unsplit small packets and save the alloc/put*/ |
|
4458 |
if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) { |
|
4459 |
u8 *vaddr; |
|
4460 |
/* there is no documentation about how to call |
|
4461 |
* kmap_atomic, so we can't hold the mapping |
|
4462 |
* very long */ |
|
4463 |
pci_dma_sync_single_for_cpu(pdev, |
|
4464 |
ps_page_dma->ps_page_dma[0], |
|
4465 |
PAGE_SIZE, |
|
4466 |
PCI_DMA_FROMDEVICE); |
|
4467 |
vaddr = kmap_atomic(ps_page->ps_page[0], |
|
4468 |
KM_SKB_DATA_SOFTIRQ); |
|
4469 |
memcpy(skb_tail_pointer(skb), vaddr, l1); |
|
4470 |
kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
|
4471 |
pci_dma_sync_single_for_device(pdev, |
|
4472 |
ps_page_dma->ps_page_dma[0], |
|
4473 |
PAGE_SIZE, PCI_DMA_FROMDEVICE); |
|
4474 |
/* remove the CRC */ |
|
4475 |
l1 -= 4; |
|
4476 |
skb_put(skb, l1); |
|
4477 |
goto copydone; |
|
4478 |
} /* if */ |
|
4479 |
} |
|
4480 |
||
4481 |
for (j = 0; j < adapter->rx_ps_pages; j++) { |
|
4482 |
length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
|
4483 |
if (!length) |
|
4484 |
break; |
|
4485 |
pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j], |
|
4486 |
PAGE_SIZE, PCI_DMA_FROMDEVICE); |
|
4487 |
ps_page_dma->ps_page_dma[j] = 0; |
|
4488 |
skb_add_rx_frag(skb, j, ps_page->ps_page[j], 0, length); |
|
4489 |
ps_page->ps_page[j] = NULL; |
|
4490 |
} |
|
4491 |
||
4492 |
/* strip the ethernet crc, problem is we're using pages now so |
|
4493 |
* this whole operation can get a little cpu intensive */ |
|
4494 |
pskb_trim(skb, skb->len - 4); |
|
4495 |
||
4496 |
copydone: |
|
4497 |
total_rx_bytes += skb->len; |
|
4498 |
total_rx_packets++; |
|
4499 |
||
4500 |
e1000_rx_checksum(adapter, staterr, |
|
4501 |
le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); |
|
4502 |
if (adapter->ecdev) { |
|
4503 |
ecdev_receive(adapter->ecdev, skb->data, length); |
|
4504 |
} else { |
|
4505 |
skb->protocol = eth_type_trans(skb, netdev); |
|
4506 |
||
4507 |
if (likely(rx_desc->wb.upper.header_status & |
|
4508 |
cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))) |
|
4509 |
adapter->rx_hdr_split++; |
|
4510 |
||
4511 |
if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
|
4512 |
vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
|
4513 |
le16_to_cpu(rx_desc->wb.middle.vlan)); |
|
4514 |
} else { |
|
4515 |
netif_receive_skb(skb); |
|
4516 |
} |
|
4517 |
} |
|
4518 |
||
4519 |
netdev->last_rx = jiffies; |
|
4520 |
||
4521 |
next_desc: |
|
4522 |
rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
|
4523 |
if (!adapter->ecdev) buffer_info->skb = NULL; |
|
4524 |
||
4525 |
/* return some buffers to hardware, one at a time is too slow */ |
|
4526 |
if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
|
4527 |
adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
|
4528 |
cleaned_count = 0; |
|
4529 |
} |
|
4530 |
||
4531 |
/* use prefetched values */ |
|
4532 |
rx_desc = next_rxd; |
|
4533 |
buffer_info = next_buffer; |
|
4534 |
||
4535 |
staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
|
4536 |
} |
|
4537 |
rx_ring->next_to_clean = i; |
|
4538 |
||
4539 |
cleaned_count = E1000_DESC_UNUSED(rx_ring); |
|
4540 |
if (cleaned_count) |
|
4541 |
adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
|
4542 |
||
4543 |
adapter->total_rx_packets += total_rx_packets; |
|
4544 |
adapter->total_rx_bytes += total_rx_bytes; |
|
4545 |
adapter->net_stats.rx_bytes += total_rx_bytes; |
|
4546 |
adapter->net_stats.rx_packets += total_rx_packets; |
|
4547 |
return cleaned; |
|
4548 |
} |
|
4549 |
||
4550 |
/** |
|
4551 |
* e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
|
4552 |
* @adapter: address of board private structure |
|
4553 |
**/ |
|
4554 |
||
4555 |
static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
|
4556 |
struct e1000_rx_ring *rx_ring, |
|
4557 |
int cleaned_count) |
|
4558 |
{ |
|
4559 |
struct e1000_hw *hw = &adapter->hw; |
|
4560 |
struct net_device *netdev = adapter->netdev; |
|
4561 |
struct pci_dev *pdev = adapter->pdev; |
|
4562 |
struct e1000_rx_desc *rx_desc; |
|
4563 |
struct e1000_buffer *buffer_info; |
|
4564 |
struct sk_buff *skb; |
|
4565 |
unsigned int i; |
|
4566 |
unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
|
4567 |
||
4568 |
i = rx_ring->next_to_use; |
|
4569 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4570 |
||
4571 |
while (cleaned_count--) { |
|
4572 |
skb = buffer_info->skb; |
|
4573 |
if (skb) { |
|
4574 |
skb_trim(skb, 0); |
|
4575 |
goto map_skb; |
|
4576 |
} |
|
4577 |
||
4578 |
skb = netdev_alloc_skb(netdev, bufsz); |
|
4579 |
if (unlikely(!skb)) { |
|
4580 |
/* Better luck next round */ |
|
4581 |
adapter->alloc_rx_buff_failed++; |
|
4582 |
break; |
|
4583 |
} |
|
4584 |
||
4585 |
/* Fix for errata 23, can't cross 64kB boundary */ |
|
4586 |
if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
|
4587 |
struct sk_buff *oldskb = skb; |
|
4588 |
DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
|
4589 |
"at %p\n", bufsz, skb->data); |
|
4590 |
/* Try again, without freeing the previous */ |
|
4591 |
skb = netdev_alloc_skb(netdev, bufsz); |
|
4592 |
/* Failed allocation, critical failure */ |
|
4593 |
if (!skb) { |
|
4594 |
dev_kfree_skb(oldskb); |
|
4595 |
break; |
|
4596 |
} |
|
4597 |
||
4598 |
if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
|
4599 |
/* give up */ |
|
4600 |
dev_kfree_skb(skb); |
|
4601 |
dev_kfree_skb(oldskb); |
|
4602 |
break; /* while !buffer_info->skb */ |
|
4603 |
} |
|
4604 |
||
4605 |
/* Use new allocation */ |
|
4606 |
dev_kfree_skb(oldskb); |
|
4607 |
} |
|
4608 |
/* Make buffer alignment 2 beyond a 16 byte boundary |
|
4609 |
* this will result in a 16 byte aligned IP header after |
|
4610 |
* the 14 byte MAC header is removed |
|
4611 |
*/ |
|
4612 |
skb_reserve(skb, NET_IP_ALIGN); |
|
4613 |
||
4614 |
buffer_info->skb = skb; |
|
4615 |
buffer_info->length = adapter->rx_buffer_len; |
|
4616 |
map_skb: |
|
4617 |
buffer_info->dma = pci_map_single(pdev, |
|
4618 |
skb->data, |
|
4619 |
adapter->rx_buffer_len, |
|
4620 |
PCI_DMA_FROMDEVICE); |
|
4621 |
||
4622 |
/* Fix for errata 23, can't cross 64kB boundary */ |
|
4623 |
if (!e1000_check_64k_bound(adapter, |
|
4624 |
(void *)(unsigned long)buffer_info->dma, |
|
4625 |
adapter->rx_buffer_len)) { |
|
4626 |
DPRINTK(RX_ERR, ERR, |
|
4627 |
"dma align check failed: %u bytes at %p\n", |
|
4628 |
adapter->rx_buffer_len, |
|
4629 |
(void *)(unsigned long)buffer_info->dma); |
|
4630 |
if (!adapter->ecdev) { |
|
4631 |
dev_kfree_skb(skb); |
|
4632 |
buffer_info->skb = NULL; |
|
4633 |
} |
|
4634 |
||
4635 |
pci_unmap_single(pdev, buffer_info->dma, |
|
4636 |
adapter->rx_buffer_len, |
|
4637 |
PCI_DMA_FROMDEVICE); |
|
4638 |
||
4639 |
break; /* while !buffer_info->skb */ |
|
4640 |
} |
|
4641 |
rx_desc = E1000_RX_DESC(*rx_ring, i); |
|
4642 |
rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
|
4643 |
||
4644 |
if (unlikely(++i == rx_ring->count)) |
|
4645 |
i = 0; |
|
4646 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4647 |
} |
|
4648 |
||
4649 |
if (likely(rx_ring->next_to_use != i)) { |
|
4650 |
rx_ring->next_to_use = i; |
|
4651 |
if (unlikely(i-- == 0)) |
|
4652 |
i = (rx_ring->count - 1); |
|
4653 |
||
4654 |
/* Force memory writes to complete before letting h/w |
|
4655 |
* know there are new descriptors to fetch. (Only |
|
4656 |
* applicable for weak-ordered memory model archs, |
|
4657 |
* such as IA-64). */ |
|
4658 |
wmb(); |
|
4659 |
writel(i, hw->hw_addr + rx_ring->rdt); |
|
4660 |
} |
|
4661 |
} |
|
4662 |
||
4663 |
/** |
|
4664 |
* e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
|
4665 |
* @adapter: address of board private structure |
|
4666 |
**/ |
|
4667 |
||
4668 |
static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
|
4669 |
struct e1000_rx_ring *rx_ring, |
|
4670 |
int cleaned_count) |
|
4671 |
{ |
|
4672 |
struct e1000_hw *hw = &adapter->hw; |
|
4673 |
struct net_device *netdev = adapter->netdev; |
|
4674 |
struct pci_dev *pdev = adapter->pdev; |
|
4675 |
union e1000_rx_desc_packet_split *rx_desc; |
|
4676 |
struct e1000_buffer *buffer_info; |
|
4677 |
struct e1000_ps_page *ps_page; |
|
4678 |
struct e1000_ps_page_dma *ps_page_dma; |
|
4679 |
struct sk_buff *skb; |
|
4680 |
unsigned int i, j; |
|
4681 |
||
4682 |
i = rx_ring->next_to_use; |
|
4683 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4684 |
ps_page = &rx_ring->ps_page[i]; |
|
4685 |
ps_page_dma = &rx_ring->ps_page_dma[i]; |
|
4686 |
||
4687 |
while (cleaned_count--) { |
|
4688 |
rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
|
4689 |
||
4690 |
for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
|
4691 |
if (j < adapter->rx_ps_pages) { |
|
4692 |
if (likely(!ps_page->ps_page[j])) { |
|
4693 |
ps_page->ps_page[j] = |
|
4694 |
netdev_alloc_page(netdev); |
|
4695 |
if (unlikely(!ps_page->ps_page[j])) { |
|
4696 |
adapter->alloc_rx_buff_failed++; |
|
4697 |
goto no_buffers; |
|
4698 |
} |
|
4699 |
ps_page_dma->ps_page_dma[j] = |
|
4700 |
pci_map_page(pdev, |
|
4701 |
ps_page->ps_page[j], |
|
4702 |
0, PAGE_SIZE, |
|
4703 |
PCI_DMA_FROMDEVICE); |
|
4704 |
} |
|
4705 |
/* Refresh the desc even if buffer_addrs didn't |
|
4706 |
* change because each write-back erases |
|
4707 |
* this info. |
|
4708 |
*/ |
|
4709 |
rx_desc->read.buffer_addr[j+1] = |
|
4710 |
cpu_to_le64(ps_page_dma->ps_page_dma[j]); |
|
4711 |
} else |
|
4712 |
rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0); |
|
4713 |
} |
|
4714 |
||
4715 |
skb = netdev_alloc_skb(netdev, |
|
4716 |
adapter->rx_ps_bsize0 + NET_IP_ALIGN); |
|
4717 |
||
4718 |
if (unlikely(!skb)) { |
|
4719 |
adapter->alloc_rx_buff_failed++; |
|
4720 |
break; |
|
4721 |
} |
|
4722 |
||
4723 |
/* Make buffer alignment 2 beyond a 16 byte boundary |
|
4724 |
* this will result in a 16 byte aligned IP header after |
|
4725 |
* the 14 byte MAC header is removed |
|
4726 |
*/ |
|
4727 |
skb_reserve(skb, NET_IP_ALIGN); |
|
4728 |
||
4729 |
buffer_info->skb = skb; |
|
4730 |
buffer_info->length = adapter->rx_ps_bsize0; |
|
4731 |
buffer_info->dma = pci_map_single(pdev, skb->data, |
|
4732 |
adapter->rx_ps_bsize0, |
|
4733 |
PCI_DMA_FROMDEVICE); |
|
4734 |
||
4735 |
rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
|
4736 |
||
4737 |
if (unlikely(++i == rx_ring->count)) i = 0; |
|
4738 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4739 |
ps_page = &rx_ring->ps_page[i]; |
|
4740 |
ps_page_dma = &rx_ring->ps_page_dma[i]; |
|
4741 |
} |
|
4742 |
||
4743 |
no_buffers: |
|
4744 |
if (likely(rx_ring->next_to_use != i)) { |
|
4745 |
rx_ring->next_to_use = i; |
|
4746 |
if (unlikely(i-- == 0)) i = (rx_ring->count - 1); |
|
4747 |
||
4748 |
/* Force memory writes to complete before letting h/w |
|
4749 |
* know there are new descriptors to fetch. (Only |
|
4750 |
* applicable for weak-ordered memory model archs, |
|
4751 |
* such as IA-64). */ |
|
4752 |
wmb(); |
|
4753 |
/* Hardware increments by 16 bytes, but packet split |
|
4754 |
* descriptors are 32 bytes...so we increment tail |
|
4755 |
* twice as much. |
|
4756 |
*/ |
|
4757 |
writel(i<<1, hw->hw_addr + rx_ring->rdt); |
|
4758 |
} |
|
4759 |
} |
|
4760 |
||
4761 |
/** |
|
4762 |
* e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
|
4763 |
* @adapter: |
|
4764 |
**/ |
|
4765 |
||
4766 |
static void e1000_smartspeed(struct e1000_adapter *adapter) |
|
4767 |
{ |
|
4768 |
struct e1000_hw *hw = &adapter->hw; |
|
4769 |
u16 phy_status; |
|
4770 |
u16 phy_ctrl; |
|
4771 |
||
4772 |
if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg || |
|
4773 |
!(hw->autoneg_advertised & ADVERTISE_1000_FULL)) |
|
4774 |
return; |
|
4775 |
||
4776 |
if (adapter->smartspeed == 0) { |
|
4777 |
/* If Master/Slave config fault is asserted twice, |
|
4778 |
* we assume back-to-back */ |
|
4779 |
e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); |
|
4780 |
if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
|
4781 |
e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); |
|
4782 |
if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
|
4783 |
e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); |
|
4784 |
if (phy_ctrl & CR_1000T_MS_ENABLE) { |
|
4785 |
phy_ctrl &= ~CR_1000T_MS_ENABLE; |
|
4786 |
e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
|
4787 |
phy_ctrl); |
|
4788 |
adapter->smartspeed++; |
|
4789 |
if (!e1000_phy_setup_autoneg(hw) && |
|
4790 |
!e1000_read_phy_reg(hw, PHY_CTRL, |
|
4791 |
&phy_ctrl)) { |
|
4792 |
phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
|
4793 |
MII_CR_RESTART_AUTO_NEG); |
|
4794 |
e1000_write_phy_reg(hw, PHY_CTRL, |
|
4795 |
phy_ctrl); |
|
4796 |
} |
|
4797 |
} |
|
4798 |
return; |
|
4799 |
} else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
|
4800 |
/* If still no link, perhaps using 2/3 pair cable */ |
|
4801 |
e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); |
|
4802 |
phy_ctrl |= CR_1000T_MS_ENABLE; |
|
4803 |
e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl); |
|
4804 |
if (!e1000_phy_setup_autoneg(hw) && |
|
4805 |
!e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) { |
|
4806 |
phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
|
4807 |
MII_CR_RESTART_AUTO_NEG); |
|
4808 |
e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl); |
|
4809 |
} |
|
4810 |
} |
|
4811 |
/* Restart process after E1000_SMARTSPEED_MAX iterations */ |
|
4812 |
if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
|
4813 |
adapter->smartspeed = 0; |
|
4814 |
} |
|
4815 |
||
4816 |
/** |
|
4817 |
* e1000_ioctl - |
|
4818 |
* @netdev: |
|
4819 |
* @ifreq: |
|
4820 |
* @cmd: |
|
4821 |
**/ |
|
4822 |
||
4823 |
static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
|
4824 |
{ |
|
4825 |
switch (cmd) { |
|
4826 |
case SIOCGMIIPHY: |
|
4827 |
case SIOCGMIIREG: |
|
4828 |
case SIOCSMIIREG: |
|
4829 |
return e1000_mii_ioctl(netdev, ifr, cmd); |
|
4830 |
default: |
|
4831 |
return -EOPNOTSUPP; |
|
4832 |
} |
|
4833 |
} |
|
4834 |
||
4835 |
/** |
|
4836 |
* e1000_mii_ioctl - |
|
4837 |
* @netdev: |
|
4838 |
* @ifreq: |
|
4839 |
* @cmd: |
|
4840 |
**/ |
|
4841 |
||
4842 |
static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
|
4843 |
int cmd) |
|
4844 |
{ |
|
4845 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
4846 |
struct e1000_hw *hw = &adapter->hw; |
|
4847 |
struct mii_ioctl_data *data = if_mii(ifr); |
|
4848 |
int retval; |
|
4849 |
u16 mii_reg; |
|
4850 |
u16 spddplx; |
|
4851 |
unsigned long flags; |
|
4852 |
||
4853 |
if (hw->media_type != e1000_media_type_copper) |
|
4854 |
return -EOPNOTSUPP; |
|
4855 |
||
4856 |
switch (cmd) { |
|
4857 |
case SIOCGMIIPHY: |
|
4858 |
data->phy_id = hw->phy_addr; |
|
4859 |
break; |
|
4860 |
case SIOCGMIIREG: |
|
4861 |
if (adapter->ecdev || !capable(CAP_NET_ADMIN)) |
|
4862 |
return -EPERM; |
|
4863 |
spin_lock_irqsave(&adapter->stats_lock, flags); |
|
4864 |
if (e1000_read_phy_reg(hw, data->reg_num & 0x1F, |
|
4865 |
&data->val_out)) { |
|
4866 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
4867 |
return -EIO; |
|
4868 |
} |
|
4869 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
4870 |
break; |
|
4871 |
case SIOCSMIIREG: |
|
4872 |
if (adapter->ecdev || !capable(CAP_NET_ADMIN)) |
|
4873 |
return -EPERM; |
|
4874 |
if (data->reg_num & ~(0x1F)) |
|
4875 |
return -EFAULT; |
|
4876 |
mii_reg = data->val_in; |
|
4877 |
spin_lock_irqsave(&adapter->stats_lock, flags); |
|
4878 |
if (e1000_write_phy_reg(hw, data->reg_num, |
|
4879 |
mii_reg)) { |
|
4880 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
4881 |
return -EIO; |
|
4882 |
} |
|
4883 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
4884 |
if (hw->media_type == e1000_media_type_copper) { |
|
4885 |
switch (data->reg_num) { |
|
4886 |
case PHY_CTRL: |
|
4887 |
if (mii_reg & MII_CR_POWER_DOWN) |
|
4888 |
break; |
|
4889 |
if (mii_reg & MII_CR_AUTO_NEG_EN) { |
|
4890 |
hw->autoneg = 1; |
|
4891 |
hw->autoneg_advertised = 0x2F; |
|
4892 |
} else { |
|
4893 |
if (mii_reg & 0x40) |
|
4894 |
spddplx = SPEED_1000; |
|
4895 |
else if (mii_reg & 0x2000) |
|
4896 |
spddplx = SPEED_100; |
|
4897 |
else |
|
4898 |
spddplx = SPEED_10; |
|
4899 |
spddplx += (mii_reg & 0x100) |
|
4900 |
? DUPLEX_FULL : |
|
4901 |
DUPLEX_HALF; |
|
4902 |
retval = e1000_set_spd_dplx(adapter, |
|
4903 |
spddplx); |
|
4904 |
if (retval) |
|
4905 |
return retval; |
|
4906 |
} |
|
4907 |
if (netif_running(adapter->netdev)) |
|
4908 |
e1000_reinit_locked(adapter); |
|
4909 |
else |
|
4910 |
e1000_reset(adapter); |
|
4911 |
break; |
|
4912 |
case M88E1000_PHY_SPEC_CTRL: |
|
4913 |
case M88E1000_EXT_PHY_SPEC_CTRL: |
|
4914 |
if (e1000_phy_reset(hw)) |
|
4915 |
return -EIO; |
|
4916 |
break; |
|
4917 |
} |
|
4918 |
} else { |
|
4919 |
switch (data->reg_num) { |
|
4920 |
case PHY_CTRL: |
|
4921 |
if (mii_reg & MII_CR_POWER_DOWN) |
|
4922 |
break; |
|
4923 |
if (netif_running(adapter->netdev)) |
|
4924 |
e1000_reinit_locked(adapter); |
|
4925 |
else |
|
4926 |
e1000_reset(adapter); |
|
4927 |
break; |
|
4928 |
} |
|
4929 |
} |
|
4930 |
break; |
|
4931 |
default: |
|
4932 |
return -EOPNOTSUPP; |
|
4933 |
} |
|
4934 |
return E1000_SUCCESS; |
|
4935 |
} |
|
4936 |
||
4937 |
void e1000_pci_set_mwi(struct e1000_hw *hw) |
|
4938 |
{ |
|
4939 |
struct e1000_adapter *adapter = hw->back; |
|
4940 |
int ret_val = pci_set_mwi(adapter->pdev); |
|
4941 |
||
4942 |
if (ret_val) |
|
4943 |
DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
|
4944 |
} |
|
4945 |
||
4946 |
void e1000_pci_clear_mwi(struct e1000_hw *hw) |
|
4947 |
{ |
|
4948 |
struct e1000_adapter *adapter = hw->back; |
|
4949 |
||
4950 |
pci_clear_mwi(adapter->pdev); |
|
4951 |
} |
|
4952 |
||
4953 |
int e1000_pcix_get_mmrbc(struct e1000_hw *hw) |
|
4954 |
{ |
|
4955 |
struct e1000_adapter *adapter = hw->back; |
|
4956 |
return pcix_get_mmrbc(adapter->pdev); |
|
4957 |
} |
|
4958 |
||
4959 |
void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc) |
|
4960 |
{ |
|
4961 |
struct e1000_adapter *adapter = hw->back; |
|
4962 |
pcix_set_mmrbc(adapter->pdev, mmrbc); |
|
4963 |
} |
|
4964 |
||
4965 |
s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) |
|
4966 |
{ |
|
4967 |
struct e1000_adapter *adapter = hw->back; |
|
4968 |
u16 cap_offset; |
|
4969 |
||
4970 |
cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
|
4971 |
if (!cap_offset) |
|
4972 |
return -E1000_ERR_CONFIG; |
|
4973 |
||
4974 |
pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
|
4975 |
||
4976 |
return E1000_SUCCESS; |
|
4977 |
} |
|
4978 |
||
4979 |
void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value) |
|
4980 |
{ |
|
4981 |
outl(value, port); |
|
4982 |
} |
|
4983 |
||
4984 |
static void e1000_vlan_rx_register(struct net_device *netdev, |
|
4985 |
struct vlan_group *grp) |
|
4986 |
{ |
|
4987 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
4988 |
struct e1000_hw *hw = &adapter->hw; |
|
4989 |
u32 ctrl, rctl; |
|
4990 |
||
4991 |
if (!test_bit(__E1000_DOWN, &adapter->flags)) |
|
4992 |
e1000_irq_disable(adapter); |
|
4993 |
adapter->vlgrp = grp; |
|
4994 |
||
4995 |
if (grp) { |
|
4996 |
/* enable VLAN tag insert/strip */ |
|
4997 |
ctrl = er32(CTRL); |
|
4998 |
ctrl |= E1000_CTRL_VME; |
|
4999 |
ew32(CTRL, ctrl); |
|
5000 |
||
5001 |
if (adapter->hw.mac_type != e1000_ich8lan) { |
|
5002 |
/* enable VLAN receive filtering */ |
|
5003 |
rctl = er32(RCTL); |
|
5004 |
rctl &= ~E1000_RCTL_CFIEN; |
|
5005 |
ew32(RCTL, rctl); |
|
5006 |
e1000_update_mng_vlan(adapter); |
|
5007 |
} |
|
5008 |
} else { |
|
5009 |
/* disable VLAN tag insert/strip */ |
|
5010 |
ctrl = er32(CTRL); |
|
5011 |
ctrl &= ~E1000_CTRL_VME; |
|
5012 |
ew32(CTRL, ctrl); |
|
5013 |
||
5014 |
if (adapter->hw.mac_type != e1000_ich8lan) { |
|
5015 |
if (adapter->mng_vlan_id != |
|
5016 |
(u16)E1000_MNG_VLAN_NONE) { |
|
5017 |
e1000_vlan_rx_kill_vid(netdev, |
|
5018 |
adapter->mng_vlan_id); |
|
5019 |
adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
|
5020 |
} |
|
5021 |
} |
|
5022 |
} |
|
5023 |
||
5024 |
if (!test_bit(__E1000_DOWN, &adapter->flags)) |
|
5025 |
e1000_irq_enable(adapter); |
|
5026 |
} |
|
5027 |
||
5028 |
static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
|
5029 |
{ |
|
5030 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5031 |
struct e1000_hw *hw = &adapter->hw; |
|
5032 |
u32 vfta, index; |
|
5033 |
||
5034 |
if ((hw->mng_cookie.status & |
|
5035 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
|
5036 |
(vid == adapter->mng_vlan_id)) |
|
5037 |
return; |
|
5038 |
/* add VID to filter table */ |
|
5039 |
index = (vid >> 5) & 0x7F; |
|
5040 |
vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); |
|
5041 |
vfta |= (1 << (vid & 0x1F)); |
|
5042 |
e1000_write_vfta(hw, index, vfta); |
|
5043 |
} |
|
5044 |
||
5045 |
static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
|
5046 |
{ |
|
5047 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5048 |
struct e1000_hw *hw = &adapter->hw; |
|
5049 |
u32 vfta, index; |
|
5050 |
||
5051 |
if (!test_bit(__E1000_DOWN, &adapter->flags)) |
|
5052 |
e1000_irq_disable(adapter); |
|
5053 |
vlan_group_set_device(adapter->vlgrp, vid, NULL); |
|
5054 |
if (!test_bit(__E1000_DOWN, &adapter->flags)) |
|
5055 |
e1000_irq_enable(adapter); |
|
5056 |
||
5057 |
if ((hw->mng_cookie.status & |
|
5058 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
|
5059 |
(vid == adapter->mng_vlan_id)) { |
|
5060 |
/* release control to f/w */ |
|
5061 |
e1000_release_hw_control(adapter); |
|
5062 |
return; |
|
5063 |
} |
|
5064 |
||
5065 |
/* remove VID from filter table */ |
|
5066 |
index = (vid >> 5) & 0x7F; |
|
5067 |
vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); |
|
5068 |
vfta &= ~(1 << (vid & 0x1F)); |
|
5069 |
e1000_write_vfta(hw, index, vfta); |
|
5070 |
} |
|
5071 |
||
5072 |
static void e1000_restore_vlan(struct e1000_adapter *adapter) |
|
5073 |
{ |
|
5074 |
e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
|
5075 |
||
5076 |
if (adapter->vlgrp) { |
|
5077 |
u16 vid; |
|
5078 |
for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
|
5079 |
if (!vlan_group_get_device(adapter->vlgrp, vid)) |
|
5080 |
continue; |
|
5081 |
e1000_vlan_rx_add_vid(adapter->netdev, vid); |
|
5082 |
} |
|
5083 |
} |
|
5084 |
} |
|
5085 |
||
5086 |
int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx) |
|
5087 |
{ |
|
5088 |
struct e1000_hw *hw = &adapter->hw; |
|
5089 |
||
5090 |
hw->autoneg = 0; |
|
5091 |
||
5092 |
/* Fiber NICs only allow 1000 gbps Full duplex */ |
|
5093 |
if ((hw->media_type == e1000_media_type_fiber) && |
|
5094 |
spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
|
5095 |
DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
|
5096 |
return -EINVAL; |
|
5097 |
} |
|
5098 |
||
5099 |
switch (spddplx) { |
|
5100 |
case SPEED_10 + DUPLEX_HALF: |
|
5101 |
hw->forced_speed_duplex = e1000_10_half; |
|
5102 |
break; |
|
5103 |
case SPEED_10 + DUPLEX_FULL: |
|
5104 |
hw->forced_speed_duplex = e1000_10_full; |
|
5105 |
break; |
|
5106 |
case SPEED_100 + DUPLEX_HALF: |
|
5107 |
hw->forced_speed_duplex = e1000_100_half; |
|
5108 |
break; |
|
5109 |
case SPEED_100 + DUPLEX_FULL: |
|
5110 |
hw->forced_speed_duplex = e1000_100_full; |
|
5111 |
break; |
|
5112 |
case SPEED_1000 + DUPLEX_FULL: |
|
5113 |
hw->autoneg = 1; |
|
5114 |
hw->autoneg_advertised = ADVERTISE_1000_FULL; |
|
5115 |
break; |
|
5116 |
case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
|
5117 |
default: |
|
5118 |
DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
|
5119 |
return -EINVAL; |
|
5120 |
} |
|
5121 |
return 0; |
|
5122 |
} |
|
5123 |
||
5124 |
static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
|
5125 |
{ |
|
5126 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5127 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5128 |
struct e1000_hw *hw = &adapter->hw; |
|
5129 |
u32 ctrl, ctrl_ext, rctl, status; |
|
5130 |
u32 wufc = adapter->wol; |
|
5131 |
#ifdef CONFIG_PM |
|
5132 |
int retval = 0; |
|
5133 |
#endif |
|
5134 |
||
5135 |
if (adapter->ecdev) |
|
5136 |
return -EBUSY; |
|
5137 |
||
5138 |
netif_device_detach(netdev); |
|
5139 |
||
5140 |
if (netif_running(netdev)) { |
|
5141 |
WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
|
5142 |
e1000_down(adapter); |
|
5143 |
} |
|
5144 |
||
5145 |
#ifdef CONFIG_PM |
|
5146 |
retval = pci_save_state(pdev); |
|
5147 |
if (retval) |
|
5148 |
return retval; |
|
5149 |
#endif |
|
5150 |
||
5151 |
status = er32(STATUS); |
|
5152 |
if (status & E1000_STATUS_LU) |
|
5153 |
wufc &= ~E1000_WUFC_LNKC; |
|
5154 |
||
5155 |
if (wufc) { |
|
5156 |
e1000_setup_rctl(adapter); |
|
5157 |
e1000_set_rx_mode(netdev); |
|
5158 |
||
5159 |
/* turn on all-multi mode if wake on multicast is enabled */ |
|
5160 |
if (wufc & E1000_WUFC_MC) { |
|
5161 |
rctl = er32(RCTL); |
|
5162 |
rctl |= E1000_RCTL_MPE; |
|
5163 |
ew32(RCTL, rctl); |
|
5164 |
} |
|
5165 |
||
5166 |
if (hw->mac_type >= e1000_82540) { |
|
5167 |
ctrl = er32(CTRL); |
|
5168 |
/* advertise wake from D3Cold */ |
|
5169 |
#define E1000_CTRL_ADVD3WUC 0x00100000 |
|
5170 |
/* phy power management enable */ |
|
5171 |
#define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
|
5172 |
ctrl |= E1000_CTRL_ADVD3WUC | |
|
5173 |
E1000_CTRL_EN_PHY_PWR_MGMT; |
|
5174 |
ew32(CTRL, ctrl); |
|
5175 |
} |
|
5176 |
||
5177 |
if (hw->media_type == e1000_media_type_fiber || |
|
5178 |
hw->media_type == e1000_media_type_internal_serdes) { |
|
5179 |
/* keep the laser running in D3 */ |
|
5180 |
ctrl_ext = er32(CTRL_EXT); |
|
5181 |
ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
|
5182 |
ew32(CTRL_EXT, ctrl_ext); |
|
5183 |
} |
|
5184 |
||
5185 |
/* Allow time for pending master requests to run */ |
|
5186 |
e1000_disable_pciex_master(hw); |
|
5187 |
||
5188 |
ew32(WUC, E1000_WUC_PME_EN); |
|
5189 |
ew32(WUFC, wufc); |
|
5190 |
pci_enable_wake(pdev, PCI_D3hot, 1); |
|
5191 |
pci_enable_wake(pdev, PCI_D3cold, 1); |
|
5192 |
} else { |
|
5193 |
ew32(WUC, 0); |
|
5194 |
ew32(WUFC, 0); |
|
5195 |
pci_enable_wake(pdev, PCI_D3hot, 0); |
|
5196 |
pci_enable_wake(pdev, PCI_D3cold, 0); |
|
5197 |
} |
|
5198 |
||
5199 |
e1000_release_manageability(adapter); |
|
5200 |
||
5201 |
/* make sure adapter isn't asleep if manageability is enabled */ |
|
5202 |
if (adapter->en_mng_pt) { |
|
5203 |
pci_enable_wake(pdev, PCI_D3hot, 1); |
|
5204 |
pci_enable_wake(pdev, PCI_D3cold, 1); |
|
5205 |
} |
|
5206 |
||
5207 |
if (hw->phy_type == e1000_phy_igp_3) |
|
5208 |
e1000_phy_powerdown_workaround(hw); |
|
5209 |
||
5210 |
if (netif_running(netdev)) |
|
5211 |
e1000_free_irq(adapter); |
|
5212 |
||
5213 |
/* Release control of h/w to f/w. If f/w is AMT enabled, this |
|
5214 |
* would have already happened in close and is redundant. */ |
|
5215 |
e1000_release_hw_control(adapter); |
|
5216 |
||
5217 |
pci_disable_device(pdev); |
|
5218 |
||
5219 |
pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
|
5220 |
||
5221 |
return 0; |
|
5222 |
} |
|
5223 |
||
5224 |
#ifdef CONFIG_PM |
|
5225 |
static int e1000_resume(struct pci_dev *pdev) |
|
5226 |
{ |
|
5227 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5228 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5229 |
struct e1000_hw *hw = &adapter->hw; |
|
5230 |
u32 err; |
|
5231 |
||
5232 |
if (adapter->ecdev) |
|
5233 |
return -EBUSY; |
|
5234 |
||
5235 |
pci_set_power_state(pdev, PCI_D0); |
|
5236 |
pci_restore_state(pdev); |
|
5237 |
||
5238 |
if (adapter->need_ioport) |
|
5239 |
err = pci_enable_device(pdev); |
|
5240 |
else |
|
5241 |
err = pci_enable_device_mem(pdev); |
|
5242 |
if (err) { |
|
5243 |
printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); |
|
5244 |
return err; |
|
5245 |
} |
|
5246 |
pci_set_master(pdev); |
|
5247 |
||
5248 |
pci_enable_wake(pdev, PCI_D3hot, 0); |
|
5249 |
pci_enable_wake(pdev, PCI_D3cold, 0); |
|
5250 |
||
5251 |
if (netif_running(netdev)) { |
|
5252 |
err = e1000_request_irq(adapter); |
|
5253 |
if (err) |
|
5254 |
return err; |
|
5255 |
} |
|
5256 |
||
5257 |
e1000_power_up_phy(adapter); |
|
5258 |
e1000_reset(adapter); |
|
5259 |
ew32(WUS, ~0); |
|
5260 |
||
5261 |
e1000_init_manageability(adapter); |
|
5262 |
||
5263 |
if (netif_running(netdev)) |
|
5264 |
e1000_up(adapter); |
|
5265 |
||
5266 |
if (!adapter->ecdev) netif_device_attach(netdev); |
|
5267 |
||
5268 |
/* If the controller is 82573 and f/w is AMT, do not set |
|
5269 |
* DRV_LOAD until the interface is up. For all other cases, |
|
5270 |
* let the f/w know that the h/w is now under the control |
|
5271 |
* of the driver. */ |
|
5272 |
if (hw->mac_type != e1000_82573 || |
|
5273 |
!e1000_check_mng_mode(hw)) |
|
5274 |
e1000_get_hw_control(adapter); |
|
5275 |
||
5276 |
return 0; |
|
5277 |
} |
|
5278 |
#endif |
|
5279 |
||
5280 |
static void e1000_shutdown(struct pci_dev *pdev) |
|
5281 |
{ |
|
5282 |
e1000_suspend(pdev, PMSG_SUSPEND); |
|
5283 |
} |
|
5284 |
||
5285 |
#ifdef CONFIG_NET_POLL_CONTROLLER |
|
5286 |
/* |
|
5287 |
* Polling 'interrupt' - used by things like netconsole to send skbs |
|
5288 |
* without having to re-enable interrupts. It's not called while |
|
5289 |
* the interrupt routine is executing. |
|
5290 |
*/ |
|
5291 |
static void e1000_netpoll(struct net_device *netdev) |
|
5292 |
{ |
|
5293 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5294 |
||
5295 |
disable_irq(adapter->pdev->irq); |
|
5296 |
e1000_intr(adapter->pdev->irq, netdev); |
|
5297 |
enable_irq(adapter->pdev->irq); |
|
5298 |
} |
|
5299 |
#endif |
|
5300 |
||
5301 |
/** |
|
5302 |
* e1000_io_error_detected - called when PCI error is detected |
|
5303 |
* @pdev: Pointer to PCI device |
|
5304 |
* @state: The current pci conneection state |
|
5305 |
* |
|
5306 |
* This function is called after a PCI bus error affecting |
|
5307 |
* this device has been detected. |
|
5308 |
*/ |
|
5309 |
static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
|
5310 |
pci_channel_state_t state) |
|
5311 |
{ |
|
5312 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5313 |
struct e1000_adapter *adapter = netdev->priv; |
|
5314 |
||
5315 |
netif_device_detach(netdev); |
|
5316 |
||
5317 |
if (state == pci_channel_io_perm_failure) |
|
5318 |
return PCI_ERS_RESULT_DISCONNECT; |
|
5319 |
||
5320 |
if (netif_running(netdev)) |
|
5321 |
e1000_down(adapter); |
|
5322 |
pci_disable_device(pdev); |
|
5323 |
||
5324 |
/* Request a slot slot reset. */ |
|
5325 |
return PCI_ERS_RESULT_NEED_RESET; |
|
5326 |
} |
|
5327 |
||
5328 |
/** |
|
5329 |
* e1000_io_slot_reset - called after the pci bus has been reset. |
|
5330 |
* @pdev: Pointer to PCI device |
|
5331 |
* |
|
5332 |
* Restart the card from scratch, as if from a cold-boot. Implementation |
|
5333 |
* resembles the first-half of the e1000_resume routine. |
|
5334 |
*/ |
|
5335 |
static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
|
5336 |
{ |
|
5337 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5338 |
struct e1000_adapter *adapter = netdev->priv; |
|
5339 |
struct e1000_hw *hw = &adapter->hw; |
|
5340 |
int err; |
|
5341 |
||
5342 |
if (adapter->need_ioport) |
|
5343 |
err = pci_enable_device(pdev); |
|
5344 |
else |
|
5345 |
err = pci_enable_device_mem(pdev); |
|
5346 |
if (err) { |
|
5347 |
printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n"); |
|
5348 |
return PCI_ERS_RESULT_DISCONNECT; |
|
5349 |
} |
|
5350 |
pci_set_master(pdev); |
|
5351 |
||
5352 |
pci_enable_wake(pdev, PCI_D3hot, 0); |
|
5353 |
pci_enable_wake(pdev, PCI_D3cold, 0); |
|
5354 |
||
5355 |
e1000_reset(adapter); |
|
5356 |
ew32(WUS, ~0); |
|
5357 |
||
5358 |
return PCI_ERS_RESULT_RECOVERED; |
|
5359 |
} |
|
5360 |
||
5361 |
/** |
|
5362 |
* e1000_io_resume - called when traffic can start flowing again. |
|
5363 |
* @pdev: Pointer to PCI device |
|
5364 |
* |
|
5365 |
* This callback is called when the error recovery driver tells us that |
|
5366 |
* its OK to resume normal operation. Implementation resembles the |
|
5367 |
* second-half of the e1000_resume routine. |
|
5368 |
*/ |
|
5369 |
static void e1000_io_resume(struct pci_dev *pdev) |
|
5370 |
{ |
|
5371 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5372 |
struct e1000_adapter *adapter = netdev->priv; |
|
5373 |
struct e1000_hw *hw = &adapter->hw; |
|
5374 |
||
5375 |
e1000_init_manageability(adapter); |
|
5376 |
||
5377 |
if (netif_running(netdev)) { |
|
5378 |
if (e1000_up(adapter)) { |
|
5379 |
printk("e1000: can't bring device back up after reset\n"); |
|
5380 |
return; |
|
5381 |
} |
|
5382 |
} |
|
5383 |
||
5384 |
netif_device_attach(netdev); |
|
5385 |
||
5386 |
/* If the controller is 82573 and f/w is AMT, do not set |
|
5387 |
* DRV_LOAD until the interface is up. For all other cases, |
|
5388 |
* let the f/w know that the h/w is now under the control |
|
5389 |
* of the driver. */ |
|
5390 |
if (hw->mac_type != e1000_82573 || |
|
5391 |
!e1000_check_mng_mode(hw)) |
|
5392 |
e1000_get_hw_control(adapter); |
|
5393 |
||
5394 |
} |
|
5395 |
||
5396 |
/* e1000_main.c */ |