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