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