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