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