author | Florian Pose <fp@igh-essen.com> |
Fri, 18 Dec 2015 12:30:45 +0100 | |
branch | stable-1.5 |
changeset 2632 | 08aa7305b9ba |
parent 2582 | 87e502828b3f |
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 |
|
2421 | 26 |
|
1325
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) { |
2582
87e502828b3f
Use return value of ecdev_open(); thanks to Patrick Bruenn.
Florian Pose <fp@igh-essen.com>
parents:
2471
diff
changeset
|
1193 |
err = ecdev_open(adapter->ecdev); |
87e502828b3f
Use return value of ecdev_open(); thanks to Patrick Bruenn.
Florian Pose <fp@igh-essen.com>
parents:
2471
diff
changeset
|
1194 |
if (err) { |
680 | 1195 |
ecdev_withdraw(adapter->ecdev); |
1196 |
goto err_register; |
|
1197 |
} |
|
1198 |
} else { |
|
1199 |
strcpy(netdev->name, "eth%d"); |
|
1200 |
if ((err = register_netdev(netdev))) { |
|
1201 |
goto err_register; |
|
1202 |
} |
|
1203 |
||
1204 |
/* tell the stack to leave us alone until e1000_open() is called */ |
|
1205 |
netif_carrier_off(netdev); |
|
1206 |
netif_stop_queue(netdev); |
|
1207 |
} |
|
1208 |
||
1209 |
DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
|
1210 |
||
1211 |
cards_found++; |
|
1212 |
return 0; |
|
1213 |
||
1214 |
err_register: |
|
1215 |
e1000_release_hw_control(adapter); |
|
1216 |
err_eeprom: |
|
1217 |
if (!e1000_check_phy_reset_block(&adapter->hw)) |
|
1218 |
e1000_phy_hw_reset(&adapter->hw); |
|
1219 |
||
1220 |
if (adapter->hw.flash_address) |
|
1221 |
iounmap(adapter->hw.flash_address); |
|
1222 |
err_flashmap: |
|
1223 |
#ifdef CONFIG_E1000_NAPI |
|
1224 |
for (i = 0; i < adapter->num_rx_queues; i++) |
|
1225 |
dev_put(&adapter->polling_netdev[i]); |
|
1226 |
#endif |
|
1227 |
||
1228 |
kfree(adapter->tx_ring); |
|
1229 |
kfree(adapter->rx_ring); |
|
1230 |
#ifdef CONFIG_E1000_NAPI |
|
1231 |
kfree(adapter->polling_netdev); |
|
1232 |
#endif |
|
1233 |
err_sw_init: |
|
1234 |
iounmap(adapter->hw.hw_addr); |
|
1235 |
err_ioremap: |
|
1236 |
free_netdev(netdev); |
|
1237 |
err_alloc_etherdev: |
|
1238 |
pci_release_regions(pdev); |
|
1239 |
err_pci_reg: |
|
1240 |
err_dma: |
|
1241 |
pci_disable_device(pdev); |
|
1242 |
return err; |
|
1243 |
} |
|
1244 |
||
1245 |
/** |
|
1246 |
* e1000_remove - Device Removal Routine |
|
1247 |
* @pdev: PCI device information struct |
|
1248 |
* |
|
1249 |
* e1000_remove is called by the PCI subsystem to alert the driver |
|
1250 |
* that it should release a PCI device. The could be caused by a |
|
1251 |
* Hot-Plug event, or because the driver is going to be removed from |
|
1252 |
* memory. |
|
1253 |
**/ |
|
1254 |
||
1255 |
static void __devexit |
|
1256 |
e1000_remove(struct pci_dev *pdev) |
|
1257 |
{ |
|
1258 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
1259 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1260 |
#ifdef CONFIG_E1000_NAPI |
|
1261 |
int i; |
|
1262 |
#endif |
|
1263 |
||
1264 |
flush_scheduled_work(); |
|
1265 |
||
1266 |
e1000_release_manageability(adapter); |
|
1267 |
||
1268 |
/* Release control of h/w to f/w. If f/w is AMT enabled, this |
|
1269 |
* would have already happened in close and is redundant. */ |
|
1270 |
e1000_release_hw_control(adapter); |
|
1271 |
||
1272 |
if (adapter->ecdev) { |
|
1273 |
ecdev_close(adapter->ecdev); |
|
1274 |
ecdev_withdraw(adapter->ecdev); |
|
1275 |
} else { |
|
1276 |
unregister_netdev(netdev); |
|
1277 |
} |
|
1278 |
#ifdef CONFIG_E1000_NAPI |
|
1279 |
for (i = 0; i < adapter->num_rx_queues; i++) |
|
1280 |
dev_put(&adapter->polling_netdev[i]); |
|
1281 |
#endif |
|
1282 |
||
1283 |
if (!e1000_check_phy_reset_block(&adapter->hw)) |
|
1284 |
e1000_phy_hw_reset(&adapter->hw); |
|
1285 |
||
1286 |
kfree(adapter->tx_ring); |
|
1287 |
kfree(adapter->rx_ring); |
|
1288 |
#ifdef CONFIG_E1000_NAPI |
|
1289 |
kfree(adapter->polling_netdev); |
|
1290 |
#endif |
|
1291 |
||
1292 |
iounmap(adapter->hw.hw_addr); |
|
1293 |
if (adapter->hw.flash_address) |
|
1294 |
iounmap(adapter->hw.flash_address); |
|
1295 |
pci_release_regions(pdev); |
|
1296 |
||
1297 |
free_netdev(netdev); |
|
1298 |
||
1299 |
pci_disable_device(pdev); |
|
1300 |
} |
|
1301 |
||
1302 |
/** |
|
1303 |
* e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
|
1304 |
* @adapter: board private structure to initialize |
|
1305 |
* |
|
1306 |
* e1000_sw_init initializes the Adapter private data structure. |
|
1307 |
* Fields are initialized based on PCI device information and |
|
1308 |
* OS network device settings (MTU size). |
|
1309 |
**/ |
|
1310 |
||
1311 |
static int __devinit |
|
1312 |
e1000_sw_init(struct e1000_adapter *adapter) |
|
1313 |
{ |
|
1314 |
struct e1000_hw *hw = &adapter->hw; |
|
1315 |
struct net_device *netdev = adapter->netdev; |
|
1316 |
struct pci_dev *pdev = adapter->pdev; |
|
1317 |
#ifdef CONFIG_E1000_NAPI |
|
1318 |
int i; |
|
1319 |
#endif |
|
1320 |
||
1321 |
/* PCI config space info */ |
|
1322 |
||
1323 |
hw->vendor_id = pdev->vendor; |
|
1324 |
hw->device_id = pdev->device; |
|
1325 |
hw->subsystem_vendor_id = pdev->subsystem_vendor; |
|
1326 |
hw->subsystem_id = pdev->subsystem_device; |
|
1327 |
||
1328 |
pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
|
1329 |
||
1330 |
pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
|
1331 |
||
1332 |
adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
|
1333 |
adapter->rx_ps_bsize0 = E1000_RXBUFFER_128; |
|
1334 |
hw->max_frame_size = netdev->mtu + |
|
1335 |
ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
|
1336 |
hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
|
1337 |
||
1338 |
/* identify the MAC */ |
|
1339 |
||
1340 |
if (e1000_set_mac_type(hw)) { |
|
1341 |
DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
|
1342 |
return -EIO; |
|
1343 |
} |
|
1344 |
||
1345 |
switch (hw->mac_type) { |
|
1346 |
default: |
|
1347 |
break; |
|
1348 |
case e1000_82541: |
|
1349 |
case e1000_82547: |
|
1350 |
case e1000_82541_rev_2: |
|
1351 |
case e1000_82547_rev_2: |
|
1352 |
hw->phy_init_script = 1; |
|
1353 |
break; |
|
1354 |
} |
|
1355 |
||
1356 |
e1000_set_media_type(hw); |
|
1357 |
||
1358 |
hw->wait_autoneg_complete = FALSE; |
|
1359 |
hw->tbi_compatibility_en = TRUE; |
|
1360 |
hw->adaptive_ifs = TRUE; |
|
1361 |
||
1362 |
/* Copper options */ |
|
1363 |
||
1364 |
if (hw->media_type == e1000_media_type_copper) { |
|
1365 |
hw->mdix = AUTO_ALL_MODES; |
|
1366 |
hw->disable_polarity_correction = FALSE; |
|
1367 |
hw->master_slave = E1000_MASTER_SLAVE; |
|
1368 |
} |
|
1369 |
||
1370 |
adapter->num_tx_queues = 1; |
|
1371 |
adapter->num_rx_queues = 1; |
|
1372 |
||
1373 |
if (e1000_alloc_queues(adapter)) { |
|
1374 |
DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
|
1375 |
return -ENOMEM; |
|
1376 |
} |
|
1377 |
||
1378 |
#ifdef CONFIG_E1000_NAPI |
|
1379 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
|
1380 |
adapter->polling_netdev[i].priv = adapter; |
|
1381 |
adapter->polling_netdev[i].poll = &e1000_clean; |
|
1382 |
adapter->polling_netdev[i].weight = 64; |
|
1383 |
dev_hold(&adapter->polling_netdev[i]); |
|
1384 |
set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state); |
|
1385 |
} |
|
1386 |
spin_lock_init(&adapter->tx_queue_lock); |
|
1387 |
#endif |
|
1388 |
||
1389 |
atomic_set(&adapter->irq_sem, 1); |
|
1390 |
spin_lock_init(&adapter->stats_lock); |
|
1391 |
||
1392 |
set_bit(__E1000_DOWN, &adapter->flags); |
|
1393 |
||
1394 |
return 0; |
|
1395 |
} |
|
1396 |
||
1397 |
/** |
|
1398 |
* e1000_alloc_queues - Allocate memory for all rings |
|
1399 |
* @adapter: board private structure to initialize |
|
1400 |
* |
|
1401 |
* We allocate one ring per queue at run-time since we don't know the |
|
1402 |
* number of queues at compile-time. The polling_netdev array is |
|
1403 |
* intended for Multiqueue, but should work fine with a single queue. |
|
1404 |
**/ |
|
1405 |
||
1406 |
static int __devinit |
|
1407 |
e1000_alloc_queues(struct e1000_adapter *adapter) |
|
1408 |
{ |
|
1409 |
int size; |
|
1410 |
||
1411 |
size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues; |
|
1412 |
adapter->tx_ring = kmalloc(size, GFP_KERNEL); |
|
1413 |
if (!adapter->tx_ring) |
|
1414 |
return -ENOMEM; |
|
1415 |
memset(adapter->tx_ring, 0, size); |
|
1416 |
||
1417 |
size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues; |
|
1418 |
adapter->rx_ring = kmalloc(size, GFP_KERNEL); |
|
1419 |
if (!adapter->rx_ring) { |
|
1420 |
kfree(adapter->tx_ring); |
|
1421 |
return -ENOMEM; |
|
1422 |
} |
|
1423 |
memset(adapter->rx_ring, 0, size); |
|
1424 |
||
1425 |
#ifdef CONFIG_E1000_NAPI |
|
1426 |
size = sizeof(struct net_device) * adapter->num_rx_queues; |
|
1427 |
adapter->polling_netdev = kmalloc(size, GFP_KERNEL); |
|
1428 |
if (!adapter->polling_netdev) { |
|
1429 |
kfree(adapter->tx_ring); |
|
1430 |
kfree(adapter->rx_ring); |
|
1431 |
return -ENOMEM; |
|
1432 |
} |
|
1433 |
memset(adapter->polling_netdev, 0, size); |
|
1434 |
#endif |
|
1435 |
||
1436 |
return E1000_SUCCESS; |
|
1437 |
} |
|
1438 |
||
1439 |
/** |
|
1440 |
* e1000_open - Called when a network interface is made active |
|
1441 |
* @netdev: network interface device structure |
|
1442 |
* |
|
1443 |
* Returns 0 on success, negative value on failure |
|
1444 |
* |
|
1445 |
* The open entry point is called when a network interface is made |
|
1446 |
* active by the system (IFF_UP). At this point all resources needed |
|
1447 |
* for transmit and receive operations are allocated, the interrupt |
|
1448 |
* handler is registered with the OS, the watchdog timer is started, |
|
1449 |
* and the stack is notified that the interface is ready. |
|
1450 |
**/ |
|
1451 |
||
1452 |
static int |
|
1453 |
e1000_open(struct net_device *netdev) |
|
1454 |
{ |
|
1455 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1456 |
int err; |
|
1457 |
||
1458 |
/* disallow open during test */ |
|
1459 |
if (test_bit(__E1000_TESTING, &adapter->flags)) |
|
1460 |
return -EBUSY; |
|
1461 |
||
1462 |
/* allocate transmit descriptors */ |
|
1463 |
if ((err = e1000_setup_all_tx_resources(adapter))) |
|
1464 |
goto err_setup_tx; |
|
1465 |
||
1466 |
/* allocate receive descriptors */ |
|
1467 |
if ((err = e1000_setup_all_rx_resources(adapter))) |
|
1468 |
goto err_setup_rx; |
|
1469 |
||
1470 |
err = e1000_request_irq(adapter); |
|
1471 |
if (err) |
|
1472 |
goto err_req_irq; |
|
1473 |
||
1474 |
e1000_power_up_phy(adapter); |
|
1475 |
||
1476 |
if ((err = e1000_up(adapter))) |
|
1477 |
goto err_up; |
|
1478 |
adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
|
1479 |
if ((adapter->hw.mng_cookie.status & |
|
1480 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
|
1481 |
e1000_update_mng_vlan(adapter); |
|
1482 |
} |
|
1483 |
||
1484 |
/* If AMT is enabled, let the firmware know that the network |
|
1485 |
* interface is now open */ |
|
1486 |
if (adapter->hw.mac_type == e1000_82573 && |
|
1487 |
e1000_check_mng_mode(&adapter->hw)) |
|
1488 |
e1000_get_hw_control(adapter); |
|
1489 |
||
1490 |
return E1000_SUCCESS; |
|
1491 |
||
1492 |
err_up: |
|
1493 |
e1000_power_down_phy(adapter); |
|
1494 |
e1000_free_irq(adapter); |
|
1495 |
err_req_irq: |
|
1496 |
e1000_free_all_rx_resources(adapter); |
|
1497 |
err_setup_rx: |
|
1498 |
e1000_free_all_tx_resources(adapter); |
|
1499 |
err_setup_tx: |
|
1500 |
e1000_reset(adapter); |
|
1501 |
||
1502 |
return err; |
|
1503 |
} |
|
1504 |
||
1505 |
/** |
|
1506 |
* e1000_close - Disables a network interface |
|
1507 |
* @netdev: network interface device structure |
|
1508 |
* |
|
1509 |
* Returns 0, this is not allowed to fail |
|
1510 |
* |
|
1511 |
* The close entry point is called when an interface is de-activated |
|
1512 |
* by the OS. The hardware is still under the drivers control, but |
|
1513 |
* needs to be disabled. A global MAC reset is issued to stop the |
|
1514 |
* hardware, and all transmit and receive resources are freed. |
|
1515 |
**/ |
|
1516 |
||
1517 |
static int |
|
1518 |
e1000_close(struct net_device *netdev) |
|
1519 |
{ |
|
1520 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
1521 |
||
1522 |
WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
|
1523 |
e1000_down(adapter); |
|
1524 |
e1000_power_down_phy(adapter); |
|
1525 |
e1000_free_irq(adapter); |
|
1526 |
||
1527 |
e1000_free_all_tx_resources(adapter); |
|
1528 |
e1000_free_all_rx_resources(adapter); |
|
1529 |
||
1530 |
/* kill manageability vlan ID if supported, but not if a vlan with |
|
1531 |
* the same ID is registered on the host OS (let 8021q kill it) */ |
|
1532 |
if ((adapter->hw.mng_cookie.status & |
|
1533 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
|
1534 |
!(adapter->vlgrp && |
|
1535 |
adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) { |
|
1536 |
e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
|
1537 |
} |
|
1538 |
||
1539 |
/* If AMT is enabled, let the firmware know that the network |
|
1540 |
* interface is now closed */ |
|
1541 |
if (adapter->hw.mac_type == e1000_82573 && |
|
1542 |
e1000_check_mng_mode(&adapter->hw)) |
|
1543 |
e1000_release_hw_control(adapter); |
|
1544 |
||
1545 |
return 0; |
|
1546 |
} |
|
1547 |
||
1548 |
/** |
|
1549 |
* e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
|
1550 |
* @adapter: address of board private structure |
|
1551 |
* @start: address of beginning of memory |
|
1552 |
* @len: length of memory |
|
1553 |
**/ |
|
1554 |
static boolean_t |
|
1555 |
e1000_check_64k_bound(struct e1000_adapter *adapter, |
|
1556 |
void *start, unsigned long len) |
|
1557 |
{ |
|
1558 |
unsigned long begin = (unsigned long) start; |
|
1559 |
unsigned long end = begin + len; |
|
1560 |
||
1561 |
/* First rev 82545 and 82546 need to not allow any memory |
|
1562 |
* write location to cross 64k boundary due to errata 23 */ |
|
1563 |
if (adapter->hw.mac_type == e1000_82545 || |
|
1564 |
adapter->hw.mac_type == e1000_82546) { |
|
1565 |
return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE; |
|
1566 |
} |
|
1567 |
||
1568 |
return TRUE; |
|
1569 |
} |
|
1570 |
||
1571 |
/** |
|
1572 |
* e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
|
1573 |
* @adapter: board private structure |
|
1574 |
* @txdr: tx descriptor ring (for a specific queue) to setup |
|
1575 |
* |
|
1576 |
* Return 0 on success, negative on failure |
|
1577 |
**/ |
|
1578 |
||
1579 |
static int |
|
1580 |
e1000_setup_tx_resources(struct e1000_adapter *adapter, |
|
1581 |
struct e1000_tx_ring *txdr) |
|
1582 |
{ |
|
1583 |
struct pci_dev *pdev = adapter->pdev; |
|
1584 |
int size; |
|
1585 |
||
1586 |
size = sizeof(struct e1000_buffer) * txdr->count; |
|
1587 |
txdr->buffer_info = vmalloc(size); |
|
1588 |
if (!txdr->buffer_info) { |
|
1589 |
DPRINTK(PROBE, ERR, |
|
1590 |
"Unable to allocate memory for the transmit descriptor ring\n"); |
|
1591 |
return -ENOMEM; |
|
1592 |
} |
|
1593 |
memset(txdr->buffer_info, 0, size); |
|
1594 |
||
1595 |
/* round up to nearest 4K */ |
|
1596 |
||
1597 |
txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
|
1598 |
E1000_ROUNDUP(txdr->size, 4096); |
|
1599 |
||
1600 |
txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
|
1601 |
if (!txdr->desc) { |
|
1602 |
setup_tx_desc_die: |
|
1603 |
vfree(txdr->buffer_info); |
|
1604 |
DPRINTK(PROBE, ERR, |
|
1605 |
"Unable to allocate memory for the transmit descriptor ring\n"); |
|
1606 |
return -ENOMEM; |
|
1607 |
} |
|
1608 |
||
1609 |
/* Fix for errata 23, can't cross 64kB boundary */ |
|
1610 |
if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
|
1611 |
void *olddesc = txdr->desc; |
|
1612 |
dma_addr_t olddma = txdr->dma; |
|
1613 |
DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
|
1614 |
"at %p\n", txdr->size, txdr->desc); |
|
1615 |
/* Try again, without freeing the previous */ |
|
1616 |
txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
|
1617 |
/* Failed allocation, critical failure */ |
|
1618 |
if (!txdr->desc) { |
|
1619 |
pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
|
1620 |
goto setup_tx_desc_die; |
|
1621 |
} |
|
1622 |
||
1623 |
if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
|
1624 |
/* give up */ |
|
1625 |
pci_free_consistent(pdev, txdr->size, txdr->desc, |
|
1626 |
txdr->dma); |
|
1627 |
pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
|
1628 |
DPRINTK(PROBE, ERR, |
|
1629 |
"Unable to allocate aligned memory " |
|
1630 |
"for the transmit descriptor ring\n"); |
|
1631 |
vfree(txdr->buffer_info); |
|
1632 |
return -ENOMEM; |
|
1633 |
} else { |
|
1634 |
/* Free old allocation, new allocation was successful */ |
|
1635 |
pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
|
1636 |
} |
|
1637 |
} |
|
1638 |
memset(txdr->desc, 0, txdr->size); |
|
1639 |
||
1640 |
txdr->next_to_use = 0; |
|
1641 |
txdr->next_to_clean = 0; |
|
1642 |
spin_lock_init(&txdr->tx_lock); |
|
1643 |
||
1644 |
return 0; |
|
1645 |
} |
|
1646 |
||
1647 |
/** |
|
1648 |
* e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
|
1649 |
* (Descriptors) for all queues |
|
1650 |
* @adapter: board private structure |
|
1651 |
* |
|
1652 |
* Return 0 on success, negative on failure |
|
1653 |
**/ |
|
1654 |
||
1655 |
int |
|
1656 |
e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
|
1657 |
{ |
|
1658 |
int i, err = 0; |
|
1659 |
||
1660 |
for (i = 0; i < adapter->num_tx_queues; i++) { |
|
1661 |
err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
|
1662 |
if (err) { |
|
1663 |
DPRINTK(PROBE, ERR, |
|
1664 |
"Allocation for Tx Queue %u failed\n", i); |
|
1665 |
for (i-- ; i >= 0; i--) |
|
1666 |
e1000_free_tx_resources(adapter, |
|
1667 |
&adapter->tx_ring[i]); |
|
1668 |
break; |
|
1669 |
} |
|
1670 |
} |
|
1671 |
||
1672 |
return err; |
|
1673 |
} |
|
1674 |
||
1675 |
/** |
|
1676 |
* e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
|
1677 |
* @adapter: board private structure |
|
1678 |
* |
|
1679 |
* Configure the Tx unit of the MAC after a reset. |
|
1680 |
**/ |
|
1681 |
||
1682 |
static void |
|
1683 |
e1000_configure_tx(struct e1000_adapter *adapter) |
|
1684 |
{ |
|
1685 |
uint64_t tdba; |
|
1686 |
struct e1000_hw *hw = &adapter->hw; |
|
1687 |
uint32_t tdlen, tctl, tipg, tarc; |
|
1688 |
uint32_t ipgr1, ipgr2; |
|
1689 |
||
1690 |
/* Setup the HW Tx Head and Tail descriptor pointers */ |
|
1691 |
||
1692 |
switch (adapter->num_tx_queues) { |
|
1693 |
case 1: |
|
1694 |
default: |
|
1695 |
tdba = adapter->tx_ring[0].dma; |
|
1696 |
tdlen = adapter->tx_ring[0].count * |
|
1697 |
sizeof(struct e1000_tx_desc); |
|
1698 |
E1000_WRITE_REG(hw, TDLEN, tdlen); |
|
1699 |
E1000_WRITE_REG(hw, TDBAH, (tdba >> 32)); |
|
1700 |
E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL)); |
|
1701 |
E1000_WRITE_REG(hw, TDT, 0); |
|
1702 |
E1000_WRITE_REG(hw, TDH, 0); |
|
1703 |
adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); |
|
1704 |
adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT); |
|
1705 |
break; |
|
1706 |
} |
|
1707 |
||
1708 |
/* Set the default values for the Tx Inter Packet Gap timer */ |
|
1709 |
if (adapter->hw.mac_type <= e1000_82547_rev_2 && |
|
1710 |
(hw->media_type == e1000_media_type_fiber || |
|
1711 |
hw->media_type == e1000_media_type_internal_serdes)) |
|
1712 |
tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
|
1713 |
else |
|
1714 |
tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
|
1715 |
||
1716 |
switch (hw->mac_type) { |
|
1717 |
case e1000_82542_rev2_0: |
|
1718 |
case e1000_82542_rev2_1: |
|
1719 |
tipg = DEFAULT_82542_TIPG_IPGT; |
|
1720 |
ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
|
1721 |
ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
|
1722 |
break; |
|
1723 |
case e1000_80003es2lan: |
|
1724 |
ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
|
1725 |
ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
|
1726 |
break; |
|
1727 |
default: |
|
1728 |
ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
|
1729 |
ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
|
1730 |
break; |
|
1731 |
} |
|
1732 |
tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
|
1733 |
tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
|
1734 |
E1000_WRITE_REG(hw, TIPG, tipg); |
|
1735 |
||
1736 |
/* Set the Tx Interrupt Delay register */ |
|
1737 |
||
1738 |
E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay); |
|
1739 |
if (hw->mac_type >= e1000_82540) |
|
1740 |
E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay); |
|
1741 |
||
1742 |
/* Program the Transmit Control Register */ |
|
1743 |
||
1744 |
tctl = E1000_READ_REG(hw, TCTL); |
|
1745 |
tctl &= ~E1000_TCTL_CT; |
|
1746 |
tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
|
1747 |
(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
|
1748 |
||
1749 |
if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
|
1750 |
tarc = E1000_READ_REG(hw, TARC0); |
|
1751 |
/* set the speed mode bit, we'll clear it if we're not at |
|
1752 |
* gigabit link later */ |
|
1753 |
tarc |= (1 << 21); |
|
1754 |
E1000_WRITE_REG(hw, TARC0, tarc); |
|
1755 |
} else if (hw->mac_type == e1000_80003es2lan) { |
|
1756 |
tarc = E1000_READ_REG(hw, TARC0); |
|
1757 |
tarc |= 1; |
|
1758 |
E1000_WRITE_REG(hw, TARC0, tarc); |
|
1759 |
tarc = E1000_READ_REG(hw, TARC1); |
|
1760 |
tarc |= 1; |
|
1761 |
E1000_WRITE_REG(hw, TARC1, tarc); |
|
1762 |
} |
|
1763 |
||
1764 |
e1000_config_collision_dist(hw); |
|
1765 |
||
1766 |
/* Setup Transmit Descriptor Settings for eop descriptor */ |
|
1767 |
adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
|
1768 |
||
1769 |
/* only set IDE if we are delaying interrupts using the timers */ |
|
1770 |
if (adapter->tx_int_delay) |
|
1771 |
adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
|
1772 |
||
1773 |
if (hw->mac_type < e1000_82543) |
|
1774 |
adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
|
1775 |
else |
|
1776 |
adapter->txd_cmd |= E1000_TXD_CMD_RS; |
|
1777 |
||
1778 |
/* Cache if we're 82544 running in PCI-X because we'll |
|
1779 |
* need this to apply a workaround later in the send path. */ |
|
1780 |
if (hw->mac_type == e1000_82544 && |
|
1781 |
hw->bus_type == e1000_bus_type_pcix) |
|
1782 |
adapter->pcix_82544 = 1; |
|
1783 |
||
1784 |
E1000_WRITE_REG(hw, TCTL, tctl); |
|
1785 |
||
1786 |
} |
|
1787 |
||
1788 |
/** |
|
1789 |
* e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
|
1790 |
* @adapter: board private structure |
|
1791 |
* @rxdr: rx descriptor ring (for a specific queue) to setup |
|
1792 |
* |
|
1793 |
* Returns 0 on success, negative on failure |
|
1794 |
**/ |
|
1795 |
||
1796 |
static int |
|
1797 |
e1000_setup_rx_resources(struct e1000_adapter *adapter, |
|
1798 |
struct e1000_rx_ring *rxdr) |
|
1799 |
{ |
|
1800 |
struct pci_dev *pdev = adapter->pdev; |
|
1801 |
int size, desc_len; |
|
1802 |
||
1803 |
size = sizeof(struct e1000_buffer) * rxdr->count; |
|
1804 |
rxdr->buffer_info = vmalloc(size); |
|
1805 |
if (!rxdr->buffer_info) { |
|
1806 |
DPRINTK(PROBE, ERR, |
|
1807 |
"Unable to allocate memory for the receive descriptor ring\n"); |
|
1808 |
return -ENOMEM; |
|
1809 |
} |
|
1810 |
memset(rxdr->buffer_info, 0, size); |
|
1811 |
||
1812 |
size = sizeof(struct e1000_ps_page) * rxdr->count; |
|
1813 |
rxdr->ps_page = kmalloc(size, GFP_KERNEL); |
|
1814 |
if (!rxdr->ps_page) { |
|
1815 |
vfree(rxdr->buffer_info); |
|
1816 |
DPRINTK(PROBE, ERR, |
|
1817 |
"Unable to allocate memory for the receive descriptor ring\n"); |
|
1818 |
return -ENOMEM; |
|
1819 |
} |
|
1820 |
memset(rxdr->ps_page, 0, size); |
|
1821 |
||
1822 |
size = sizeof(struct e1000_ps_page_dma) * rxdr->count; |
|
1823 |
rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL); |
|
1824 |
if (!rxdr->ps_page_dma) { |
|
1825 |
vfree(rxdr->buffer_info); |
|
1826 |
kfree(rxdr->ps_page); |
|
1827 |
DPRINTK(PROBE, ERR, |
|
1828 |
"Unable to allocate memory for the receive descriptor ring\n"); |
|
1829 |
return -ENOMEM; |
|
1830 |
} |
|
1831 |
memset(rxdr->ps_page_dma, 0, size); |
|
1832 |
||
1833 |
if (adapter->hw.mac_type <= e1000_82547_rev_2) |
|
1834 |
desc_len = sizeof(struct e1000_rx_desc); |
|
1835 |
else |
|
1836 |
desc_len = sizeof(union e1000_rx_desc_packet_split); |
|
1837 |
||
1838 |
/* Round up to nearest 4K */ |
|
1839 |
||
1840 |
rxdr->size = rxdr->count * desc_len; |
|
1841 |
E1000_ROUNDUP(rxdr->size, 4096); |
|
1842 |
||
1843 |
rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
|
1844 |
||
1845 |
if (!rxdr->desc) { |
|
1846 |
DPRINTK(PROBE, ERR, |
|
1847 |
"Unable to allocate memory for the receive descriptor ring\n"); |
|
1848 |
setup_rx_desc_die: |
|
1849 |
vfree(rxdr->buffer_info); |
|
1850 |
kfree(rxdr->ps_page); |
|
1851 |
kfree(rxdr->ps_page_dma); |
|
1852 |
return -ENOMEM; |
|
1853 |
} |
|
1854 |
||
1855 |
/* Fix for errata 23, can't cross 64kB boundary */ |
|
1856 |
if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
|
1857 |
void *olddesc = rxdr->desc; |
|
1858 |
dma_addr_t olddma = rxdr->dma; |
|
1859 |
DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
|
1860 |
"at %p\n", rxdr->size, rxdr->desc); |
|
1861 |
/* Try again, without freeing the previous */ |
|
1862 |
rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
|
1863 |
/* Failed allocation, critical failure */ |
|
1864 |
if (!rxdr->desc) { |
|
1865 |
pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
|
1866 |
DPRINTK(PROBE, ERR, |
|
1867 |
"Unable to allocate memory " |
|
1868 |
"for the receive descriptor ring\n"); |
|
1869 |
goto setup_rx_desc_die; |
|
1870 |
} |
|
1871 |
||
1872 |
if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
|
1873 |
/* give up */ |
|
1874 |
pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
|
1875 |
rxdr->dma); |
|
1876 |
pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
|
1877 |
DPRINTK(PROBE, ERR, |
|
1878 |
"Unable to allocate aligned memory " |
|
1879 |
"for the receive descriptor ring\n"); |
|
1880 |
goto setup_rx_desc_die; |
|
1881 |
} else { |
|
1882 |
/* Free old allocation, new allocation was successful */ |
|
1883 |
pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
|
1884 |
} |
|
1885 |
} |
|
1886 |
memset(rxdr->desc, 0, rxdr->size); |
|
1887 |
||
1888 |
rxdr->next_to_clean = 0; |
|
1889 |
rxdr->next_to_use = 0; |
|
1890 |
||
1891 |
return 0; |
|
1892 |
} |
|
1893 |
||
1894 |
/** |
|
1895 |
* e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
|
1896 |
* (Descriptors) for all queues |
|
1897 |
* @adapter: board private structure |
|
1898 |
* |
|
1899 |
* Return 0 on success, negative on failure |
|
1900 |
**/ |
|
1901 |
||
1902 |
int |
|
1903 |
e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
|
1904 |
{ |
|
1905 |
int i, err = 0; |
|
1906 |
||
1907 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
|
1908 |
err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
|
1909 |
if (err) { |
|
1910 |
DPRINTK(PROBE, ERR, |
|
1911 |
"Allocation for Rx Queue %u failed\n", i); |
|
1912 |
for (i-- ; i >= 0; i--) |
|
1913 |
e1000_free_rx_resources(adapter, |
|
1914 |
&adapter->rx_ring[i]); |
|
1915 |
break; |
|
1916 |
} |
|
1917 |
} |
|
1918 |
||
1919 |
return err; |
|
1920 |
} |
|
1921 |
||
1922 |
/** |
|
1923 |
* e1000_setup_rctl - configure the receive control registers |
|
1924 |
* @adapter: Board private structure |
|
1925 |
**/ |
|
1926 |
#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
|
1927 |
(((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
|
1928 |
static void |
|
1929 |
e1000_setup_rctl(struct e1000_adapter *adapter) |
|
1930 |
{ |
|
1931 |
uint32_t rctl, rfctl; |
|
1932 |
uint32_t psrctl = 0; |
|
1933 |
#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
|
1934 |
uint32_t pages = 0; |
|
1935 |
#endif |
|
1936 |
||
1937 |
rctl = E1000_READ_REG(&adapter->hw, RCTL); |
|
1938 |
||
1939 |
rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
|
1940 |
||
1941 |
rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
|
1942 |
E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
|
1943 |
(adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); |
|
1944 |
||
1945 |
if (adapter->hw.tbi_compatibility_on == 1) |
|
1946 |
rctl |= E1000_RCTL_SBP; |
|
1947 |
else |
|
1948 |
rctl &= ~E1000_RCTL_SBP; |
|
1949 |
||
1950 |
if (adapter->netdev->mtu <= ETH_DATA_LEN) |
|
1951 |
rctl &= ~E1000_RCTL_LPE; |
|
1952 |
else |
|
1953 |
rctl |= E1000_RCTL_LPE; |
|
1954 |
||
1955 |
/* Setup buffer sizes */ |
|
1956 |
rctl &= ~E1000_RCTL_SZ_4096; |
|
1957 |
rctl |= E1000_RCTL_BSEX; |
|
1958 |
switch (adapter->rx_buffer_len) { |
|
1959 |
case E1000_RXBUFFER_256: |
|
1960 |
rctl |= E1000_RCTL_SZ_256; |
|
1961 |
rctl &= ~E1000_RCTL_BSEX; |
|
1962 |
break; |
|
1963 |
case E1000_RXBUFFER_512: |
|
1964 |
rctl |= E1000_RCTL_SZ_512; |
|
1965 |
rctl &= ~E1000_RCTL_BSEX; |
|
1966 |
break; |
|
1967 |
case E1000_RXBUFFER_1024: |
|
1968 |
rctl |= E1000_RCTL_SZ_1024; |
|
1969 |
rctl &= ~E1000_RCTL_BSEX; |
|
1970 |
break; |
|
1971 |
case E1000_RXBUFFER_2048: |
|
1972 |
default: |
|
1973 |
rctl |= E1000_RCTL_SZ_2048; |
|
1974 |
rctl &= ~E1000_RCTL_BSEX; |
|
1975 |
break; |
|
1976 |
case E1000_RXBUFFER_4096: |
|
1977 |
rctl |= E1000_RCTL_SZ_4096; |
|
1978 |
break; |
|
1979 |
case E1000_RXBUFFER_8192: |
|
1980 |
rctl |= E1000_RCTL_SZ_8192; |
|
1981 |
break; |
|
1982 |
case E1000_RXBUFFER_16384: |
|
1983 |
rctl |= E1000_RCTL_SZ_16384; |
|
1984 |
break; |
|
1985 |
} |
|
1986 |
||
1987 |
#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
|
1988 |
/* 82571 and greater support packet-split where the protocol |
|
1989 |
* header is placed in skb->data and the packet data is |
|
1990 |
* placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
|
1991 |
* In the case of a non-split, skb->data is linearly filled, |
|
1992 |
* followed by the page buffers. Therefore, skb->data is |
|
1993 |
* sized to hold the largest protocol header. |
|
1994 |
*/ |
|
1995 |
/* allocations using alloc_page take too long for regular MTU |
|
1996 |
* so only enable packet split for jumbo frames */ |
|
1997 |
pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
|
1998 |
if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) && |
|
1999 |
PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE)) |
|
2000 |
adapter->rx_ps_pages = pages; |
|
2001 |
else |
|
2002 |
adapter->rx_ps_pages = 0; |
|
2003 |
#endif |
|
2004 |
if (adapter->rx_ps_pages) { |
|
2005 |
/* Configure extra packet-split registers */ |
|
2006 |
rfctl = E1000_READ_REG(&adapter->hw, RFCTL); |
|
2007 |
rfctl |= E1000_RFCTL_EXTEN; |
|
2008 |
/* disable packet split support for IPv6 extension headers, |
|
2009 |
* because some malformed IPv6 headers can hang the RX */ |
|
2010 |
rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
|
2011 |
E1000_RFCTL_NEW_IPV6_EXT_DIS); |
|
2012 |
||
2013 |
E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl); |
|
2014 |
||
2015 |
rctl |= E1000_RCTL_DTYP_PS; |
|
2016 |
||
2017 |
psrctl |= adapter->rx_ps_bsize0 >> |
|
2018 |
E1000_PSRCTL_BSIZE0_SHIFT; |
|
2019 |
||
2020 |
switch (adapter->rx_ps_pages) { |
|
2021 |
case 3: |
|
2022 |
psrctl |= PAGE_SIZE << |
|
2023 |
E1000_PSRCTL_BSIZE3_SHIFT; |
|
2024 |
case 2: |
|
2025 |
psrctl |= PAGE_SIZE << |
|
2026 |
E1000_PSRCTL_BSIZE2_SHIFT; |
|
2027 |
case 1: |
|
2028 |
psrctl |= PAGE_SIZE >> |
|
2029 |
E1000_PSRCTL_BSIZE1_SHIFT; |
|
2030 |
break; |
|
2031 |
} |
|
2032 |
||
2033 |
E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl); |
|
2034 |
} |
|
2035 |
||
2036 |
E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
|
2037 |
} |
|
2038 |
||
2039 |
/** |
|
2040 |
* e1000_configure_rx - Configure 8254x Receive Unit after Reset |
|
2041 |
* @adapter: board private structure |
|
2042 |
* |
|
2043 |
* Configure the Rx unit of the MAC after a reset. |
|
2044 |
**/ |
|
2045 |
||
2046 |
static void |
|
2047 |
e1000_configure_rx(struct e1000_adapter *adapter) |
|
2048 |
{ |
|
2049 |
uint64_t rdba; |
|
2050 |
struct e1000_hw *hw = &adapter->hw; |
|
2051 |
uint32_t rdlen, rctl, rxcsum, ctrl_ext; |
|
2052 |
||
2053 |
if (adapter->rx_ps_pages) { |
|
2054 |
/* this is a 32 byte descriptor */ |
|
2055 |
rdlen = adapter->rx_ring[0].count * |
|
2056 |
sizeof(union e1000_rx_desc_packet_split); |
|
2057 |
adapter->clean_rx = e1000_clean_rx_irq_ps; |
|
2058 |
adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
|
2059 |
} else { |
|
2060 |
rdlen = adapter->rx_ring[0].count * |
|
2061 |
sizeof(struct e1000_rx_desc); |
|
2062 |
adapter->clean_rx = e1000_clean_rx_irq; |
|
2063 |
adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
|
2064 |
} |
|
2065 |
||
2066 |
/* disable receives while setting up the descriptors */ |
|
2067 |
rctl = E1000_READ_REG(hw, RCTL); |
|
2068 |
E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
|
2069 |
||
2070 |
/* set the Receive Delay Timer Register */ |
|
2071 |
E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay); |
|
2072 |
||
2073 |
if (hw->mac_type >= e1000_82540) { |
|
2074 |
E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay); |
|
2075 |
if (adapter->itr_setting != 0) |
|
2076 |
E1000_WRITE_REG(hw, ITR, |
|
2077 |
1000000000 / (adapter->itr * 256)); |
|
2078 |
} |
|
2079 |
||
2080 |
if (hw->mac_type >= e1000_82571) { |
|
2081 |
ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
|
2082 |
/* Reset delay timers after every interrupt */ |
|
2083 |
ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
|
2084 |
#ifdef CONFIG_E1000_NAPI |
|
2085 |
/* Auto-Mask interrupts upon ICR access */ |
|
2086 |
ctrl_ext |= E1000_CTRL_EXT_IAME; |
|
2087 |
E1000_WRITE_REG(hw, IAM, 0xffffffff); |
|
2088 |
#endif |
|
2089 |
E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
|
2090 |
E1000_WRITE_FLUSH(hw); |
|
2091 |
} |
|
2092 |
||
2093 |
/* Setup the HW Rx Head and Tail Descriptor Pointers and |
|
2094 |
* the Base and Length of the Rx Descriptor Ring */ |
|
2095 |
switch (adapter->num_rx_queues) { |
|
2096 |
case 1: |
|
2097 |
default: |
|
2098 |
rdba = adapter->rx_ring[0].dma; |
|
2099 |
E1000_WRITE_REG(hw, RDLEN, rdlen); |
|
2100 |
E1000_WRITE_REG(hw, RDBAH, (rdba >> 32)); |
|
2101 |
E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL)); |
|
2102 |
E1000_WRITE_REG(hw, RDT, 0); |
|
2103 |
E1000_WRITE_REG(hw, RDH, 0); |
|
2104 |
adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); |
|
2105 |
adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT); |
|
2106 |
break; |
|
2107 |
} |
|
2108 |
||
2109 |
/* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
|
2110 |
if (hw->mac_type >= e1000_82543) { |
|
2111 |
rxcsum = E1000_READ_REG(hw, RXCSUM); |
|
2112 |
if (adapter->rx_csum == TRUE) { |
|
2113 |
rxcsum |= E1000_RXCSUM_TUOFL; |
|
2114 |
||
2115 |
/* Enable 82571 IPv4 payload checksum for UDP fragments |
|
2116 |
* Must be used in conjunction with packet-split. */ |
|
2117 |
if ((hw->mac_type >= e1000_82571) && |
|
2118 |
(adapter->rx_ps_pages)) { |
|
2119 |
rxcsum |= E1000_RXCSUM_IPPCSE; |
|
2120 |
} |
|
2121 |
} else { |
|
2122 |
rxcsum &= ~E1000_RXCSUM_TUOFL; |
|
2123 |
/* don't need to clear IPPCSE as it defaults to 0 */ |
|
2124 |
} |
|
2125 |
E1000_WRITE_REG(hw, RXCSUM, rxcsum); |
|
2126 |
} |
|
2127 |
||
2128 |
/* enable early receives on 82573, only takes effect if using > 2048 |
|
2129 |
* byte total frame size. for example only for jumbo frames */ |
|
2130 |
#define E1000_ERT_2048 0x100 |
|
2131 |
if (hw->mac_type == e1000_82573) |
|
2132 |
E1000_WRITE_REG(hw, ERT, E1000_ERT_2048); |
|
2133 |
||
2134 |
/* Enable Receives */ |
|
2135 |
E1000_WRITE_REG(hw, RCTL, rctl); |
|
2136 |
} |
|
2137 |
||
2138 |
/** |
|
2139 |
* e1000_free_tx_resources - Free Tx Resources per Queue |
|
2140 |
* @adapter: board private structure |
|
2141 |
* @tx_ring: Tx descriptor ring for a specific queue |
|
2142 |
* |
|
2143 |
* Free all transmit software resources |
|
2144 |
**/ |
|
2145 |
||
2146 |
static void |
|
2147 |
e1000_free_tx_resources(struct e1000_adapter *adapter, |
|
2148 |
struct e1000_tx_ring *tx_ring) |
|
2149 |
{ |
|
2150 |
struct pci_dev *pdev = adapter->pdev; |
|
2151 |
||
2152 |
e1000_clean_tx_ring(adapter, tx_ring); |
|
2153 |
||
2154 |
vfree(tx_ring->buffer_info); |
|
2155 |
tx_ring->buffer_info = NULL; |
|
2156 |
||
2157 |
pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
|
2158 |
||
2159 |
tx_ring->desc = NULL; |
|
2160 |
} |
|
2161 |
||
2162 |
/** |
|
2163 |
* e1000_free_all_tx_resources - Free Tx Resources for All Queues |
|
2164 |
* @adapter: board private structure |
|
2165 |
* |
|
2166 |
* Free all transmit software resources |
|
2167 |
**/ |
|
2168 |
||
2169 |
void |
|
2170 |
e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
|
2171 |
{ |
|
2172 |
int i; |
|
2173 |
||
2174 |
for (i = 0; i < adapter->num_tx_queues; i++) |
|
2175 |
e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
|
2176 |
} |
|
2177 |
||
2178 |
static void |
|
2179 |
e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
|
2180 |
struct e1000_buffer *buffer_info) |
|
2181 |
{ |
|
2182 |
if (adapter->ecdev) |
|
2183 |
return; |
|
2184 |
||
2185 |
if (buffer_info->dma) { |
|
2186 |
pci_unmap_page(adapter->pdev, |
|
2187 |
buffer_info->dma, |
|
2188 |
buffer_info->length, |
|
2189 |
PCI_DMA_TODEVICE); |
|
2190 |
buffer_info->dma = 0; |
|
2191 |
} |
|
2192 |
if (buffer_info->skb) { |
|
2193 |
dev_kfree_skb_any(buffer_info->skb); |
|
2194 |
buffer_info->skb = NULL; |
|
2195 |
} |
|
2196 |
/* buffer_info must be completely set up in the transmit path */ |
|
2197 |
} |
|
2198 |
||
2199 |
/** |
|
2200 |
* e1000_clean_tx_ring - Free Tx Buffers |
|
2201 |
* @adapter: board private structure |
|
2202 |
* @tx_ring: ring to be cleaned |
|
2203 |
**/ |
|
2204 |
||
2205 |
static void |
|
2206 |
e1000_clean_tx_ring(struct e1000_adapter *adapter, |
|
2207 |
struct e1000_tx_ring *tx_ring) |
|
2208 |
{ |
|
2209 |
struct e1000_buffer *buffer_info; |
|
2210 |
unsigned long size; |
|
2211 |
unsigned int i; |
|
2212 |
||
2213 |
/* Free all the Tx ring sk_buffs */ |
|
2214 |
||
2215 |
for (i = 0; i < tx_ring->count; i++) { |
|
2216 |
buffer_info = &tx_ring->buffer_info[i]; |
|
2217 |
e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
|
2218 |
} |
|
2219 |
||
2220 |
size = sizeof(struct e1000_buffer) * tx_ring->count; |
|
2221 |
memset(tx_ring->buffer_info, 0, size); |
|
2222 |
||
2223 |
/* Zero out the descriptor ring */ |
|
2224 |
||
2225 |
memset(tx_ring->desc, 0, tx_ring->size); |
|
2226 |
||
2227 |
tx_ring->next_to_use = 0; |
|
2228 |
tx_ring->next_to_clean = 0; |
|
2229 |
tx_ring->last_tx_tso = 0; |
|
2230 |
||
2231 |
writel(0, adapter->hw.hw_addr + tx_ring->tdh); |
|
2232 |
writel(0, adapter->hw.hw_addr + tx_ring->tdt); |
|
2233 |
} |
|
2234 |
||
2235 |
/** |
|
2236 |
* e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
|
2237 |
* @adapter: board private structure |
|
2238 |
**/ |
|
2239 |
||
2240 |
static void |
|
2241 |
e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
|
2242 |
{ |
|
2243 |
int i; |
|
2244 |
||
2245 |
for (i = 0; i < adapter->num_tx_queues; i++) |
|
2246 |
e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
|
2247 |
} |
|
2248 |
||
2249 |
/** |
|
2250 |
* e1000_free_rx_resources - Free Rx Resources |
|
2251 |
* @adapter: board private structure |
|
2252 |
* @rx_ring: ring to clean the resources from |
|
2253 |
* |
|
2254 |
* Free all receive software resources |
|
2255 |
**/ |
|
2256 |
||
2257 |
static void |
|
2258 |
e1000_free_rx_resources(struct e1000_adapter *adapter, |
|
2259 |
struct e1000_rx_ring *rx_ring) |
|
2260 |
{ |
|
2261 |
struct pci_dev *pdev = adapter->pdev; |
|
2262 |
||
2263 |
e1000_clean_rx_ring(adapter, rx_ring); |
|
2264 |
||
2265 |
vfree(rx_ring->buffer_info); |
|
2266 |
rx_ring->buffer_info = NULL; |
|
2267 |
kfree(rx_ring->ps_page); |
|
2268 |
rx_ring->ps_page = NULL; |
|
2269 |
kfree(rx_ring->ps_page_dma); |
|
2270 |
rx_ring->ps_page_dma = NULL; |
|
2271 |
||
2272 |
pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
|
2273 |
||
2274 |
rx_ring->desc = NULL; |
|
2275 |
} |
|
2276 |
||
2277 |
/** |
|
2278 |
* e1000_free_all_rx_resources - Free Rx Resources for All Queues |
|
2279 |
* @adapter: board private structure |
|
2280 |
* |
|
2281 |
* Free all receive software resources |
|
2282 |
**/ |
|
2283 |
||
2284 |
void |
|
2285 |
e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
|
2286 |
{ |
|
2287 |
int i; |
|
2288 |
||
2289 |
for (i = 0; i < adapter->num_rx_queues; i++) |
|
2290 |
e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
|
2291 |
} |
|
2292 |
||
2293 |
/** |
|
2294 |
* e1000_clean_rx_ring - Free Rx Buffers per Queue |
|
2295 |
* @adapter: board private structure |
|
2296 |
* @rx_ring: ring to free buffers from |
|
2297 |
**/ |
|
2298 |
||
2299 |
static void |
|
2300 |
e1000_clean_rx_ring(struct e1000_adapter *adapter, |
|
2301 |
struct e1000_rx_ring *rx_ring) |
|
2302 |
{ |
|
2303 |
struct e1000_buffer *buffer_info; |
|
2304 |
struct e1000_ps_page *ps_page; |
|
2305 |
struct e1000_ps_page_dma *ps_page_dma; |
|
2306 |
struct pci_dev *pdev = adapter->pdev; |
|
2307 |
unsigned long size; |
|
2308 |
unsigned int i, j; |
|
2309 |
||
2310 |
/* Free all the Rx ring sk_buffs */ |
|
2311 |
for (i = 0; i < rx_ring->count; i++) { |
|
2312 |
buffer_info = &rx_ring->buffer_info[i]; |
|
2313 |
if (buffer_info->skb) { |
|
2314 |
pci_unmap_single(pdev, |
|
2315 |
buffer_info->dma, |
|
2316 |
buffer_info->length, |
|
2317 |
PCI_DMA_FROMDEVICE); |
|
2318 |
||
2319 |
dev_kfree_skb(buffer_info->skb); |
|
2320 |
buffer_info->skb = NULL; |
|
2321 |
} |
|
2322 |
ps_page = &rx_ring->ps_page[i]; |
|
2323 |
ps_page_dma = &rx_ring->ps_page_dma[i]; |
|
2324 |
for (j = 0; j < adapter->rx_ps_pages; j++) { |
|
2325 |
if (!ps_page->ps_page[j]) break; |
|
2326 |
pci_unmap_page(pdev, |
|
2327 |
ps_page_dma->ps_page_dma[j], |
|
2328 |
PAGE_SIZE, PCI_DMA_FROMDEVICE); |
|
2329 |
ps_page_dma->ps_page_dma[j] = 0; |
|
2330 |
put_page(ps_page->ps_page[j]); |
|
2331 |
ps_page->ps_page[j] = NULL; |
|
2332 |
} |
|
2333 |
} |
|
2334 |
||
2335 |
size = sizeof(struct e1000_buffer) * rx_ring->count; |
|
2336 |
memset(rx_ring->buffer_info, 0, size); |
|
2337 |
size = sizeof(struct e1000_ps_page) * rx_ring->count; |
|
2338 |
memset(rx_ring->ps_page, 0, size); |
|
2339 |
size = sizeof(struct e1000_ps_page_dma) * rx_ring->count; |
|
2340 |
memset(rx_ring->ps_page_dma, 0, size); |
|
2341 |
||
2342 |
/* Zero out the descriptor ring */ |
|
2343 |
||
2344 |
memset(rx_ring->desc, 0, rx_ring->size); |
|
2345 |
||
2346 |
rx_ring->next_to_clean = 0; |
|
2347 |
rx_ring->next_to_use = 0; |
|
2348 |
||
2349 |
writel(0, adapter->hw.hw_addr + rx_ring->rdh); |
|
2350 |
writel(0, adapter->hw.hw_addr + rx_ring->rdt); |
|
2351 |
} |
|
2352 |
||
2353 |
/** |
|
2354 |
* e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
|
2355 |
* @adapter: board private structure |
|
2356 |
**/ |
|
2357 |
||
2358 |
static void |
|
2359 |
e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
|
2360 |
{ |
|
2361 |
int i; |
|
2362 |
||
2363 |
for (i = 0; i < adapter->num_rx_queues; i++) |
|
2364 |
e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
|
2365 |
} |
|
2366 |
||
2367 |
/* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
|
2368 |
* and memory write and invalidate disabled for certain operations |
|
2369 |
*/ |
|
2370 |
static void |
|
2371 |
e1000_enter_82542_rst(struct e1000_adapter *adapter) |
|
2372 |
{ |
|
2373 |
struct net_device *netdev = adapter->netdev; |
|
2374 |
uint32_t rctl; |
|
2375 |
||
2376 |
e1000_pci_clear_mwi(&adapter->hw); |
|
2377 |
||
2378 |
rctl = E1000_READ_REG(&adapter->hw, RCTL); |
|
2379 |
rctl |= E1000_RCTL_RST; |
|
2380 |
E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
|
2381 |
E1000_WRITE_FLUSH(&adapter->hw); |
|
2382 |
mdelay(5); |
|
2383 |
||
2384 |
if (!adapter->ecdev && netif_running(netdev)) |
|
2385 |
e1000_clean_all_rx_rings(adapter); |
|
2386 |
} |
|
2387 |
||
2388 |
static void |
|
2389 |
e1000_leave_82542_rst(struct e1000_adapter *adapter) |
|
2390 |
{ |
|
2391 |
struct net_device *netdev = adapter->netdev; |
|
2392 |
uint32_t rctl; |
|
2393 |
||
2394 |
rctl = E1000_READ_REG(&adapter->hw, RCTL); |
|
2395 |
rctl &= ~E1000_RCTL_RST; |
|
2396 |
E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
|
2397 |
E1000_WRITE_FLUSH(&adapter->hw); |
|
2398 |
mdelay(5); |
|
2399 |
||
2400 |
if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE) |
|
2401 |
e1000_pci_set_mwi(&adapter->hw); |
|
2402 |
||
2403 |
if (!adapter->netdev && netif_running(netdev)) { |
|
2404 |
/* No need to loop, because 82542 supports only 1 queue */ |
|
2405 |
struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
|
2406 |
e1000_configure_rx(adapter); |
|
2421 | 2407 |
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
|
2408 |
/* 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
|
2409 |
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
|
2410 |
} else { |
16aacb421bd4
merge -c1602 branches/stable-1.4: Fixed e1000 ring bug.
Florian Pose <fp@igh-essen.com>
parents:
1154
diff
changeset
|
2411 |
/* 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
|
2412 |
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
|
2413 |
} |
16aacb421bd4
merge -c1602 branches/stable-1.4: Fixed e1000 ring bug.
Florian Pose <fp@igh-essen.com>
parents:
1154
diff
changeset
|
2414 |
|
680 | 2415 |
} |
2416 |
} |
|
2417 |
||
2418 |
/** |
|
2419 |
* e1000_set_mac - Change the Ethernet Address of the NIC |
|
2420 |
* @netdev: network interface device structure |
|
2421 |
* @p: pointer to an address structure |
|
2422 |
* |
|
2423 |
* Returns 0 on success, negative on failure |
|
2424 |
**/ |
|
2425 |
||
2426 |
static int |
|
2427 |
e1000_set_mac(struct net_device *netdev, void *p) |
|
2428 |
{ |
|
2429 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
2430 |
struct sockaddr *addr = p; |
|
2431 |
||
2432 |
if (!is_valid_ether_addr(addr->sa_data)) |
|
2433 |
return -EADDRNOTAVAIL; |
|
2434 |
||
2435 |
/* 82542 2.0 needs to be in reset to write receive address registers */ |
|
2436 |
||
2437 |
if (adapter->hw.mac_type == e1000_82542_rev2_0) |
|
2438 |
e1000_enter_82542_rst(adapter); |
|
2439 |
||
2440 |
memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
|
2441 |
memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len); |
|
2442 |
||
2443 |
e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
|
2444 |
||
2445 |
/* With 82571 controllers, LAA may be overwritten (with the default) |
|
2446 |
* due to controller reset from the other port. */ |
|
2447 |
if (adapter->hw.mac_type == e1000_82571) { |
|
2448 |
/* activate the work around */ |
|
2449 |
adapter->hw.laa_is_present = 1; |
|
2450 |
||
2451 |
/* Hold a copy of the LAA in RAR[14] This is done so that |
|
2452 |
* between the time RAR[0] gets clobbered and the time it |
|
2453 |
* gets fixed (in e1000_watchdog), the actual LAA is in one |
|
2454 |
* of the RARs and no incoming packets directed to this port |
|
2455 |
* are dropped. Eventaully the LAA will be in RAR[0] and |
|
2456 |
* RAR[14] */ |
|
2457 |
e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, |
|
2458 |
E1000_RAR_ENTRIES - 1); |
|
2459 |
} |
|
2460 |
||
2461 |
if (adapter->hw.mac_type == e1000_82542_rev2_0) |
|
2462 |
e1000_leave_82542_rst(adapter); |
|
2463 |
||
2464 |
return 0; |
|
2465 |
} |
|
2466 |
||
2467 |
/** |
|
2468 |
* e1000_set_multi - Multicast and Promiscuous mode set |
|
2469 |
* @netdev: network interface device structure |
|
2470 |
* |
|
2471 |
* The set_multi entry point is called whenever the multicast address |
|
2472 |
* list or the network interface flags are updated. This routine is |
|
2473 |
* responsible for configuring the hardware for proper multicast, |
|
2474 |
* promiscuous mode, and all-multi behavior. |
|
2475 |
**/ |
|
2476 |
||
2477 |
static void |
|
2478 |
e1000_set_multi(struct net_device *netdev) |
|
2479 |
{ |
|
2480 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
2481 |
struct e1000_hw *hw = &adapter->hw; |
|
2482 |
struct dev_mc_list *mc_ptr; |
|
2483 |
uint32_t rctl; |
|
2484 |
uint32_t hash_value; |
|
2485 |
int i, rar_entries = E1000_RAR_ENTRIES; |
|
2486 |
int mta_reg_count = (hw->mac_type == e1000_ich8lan) ? |
|
2487 |
E1000_NUM_MTA_REGISTERS_ICH8LAN : |
|
2488 |
E1000_NUM_MTA_REGISTERS; |
|
2489 |
||
2490 |
if (adapter->hw.mac_type == e1000_ich8lan) |
|
2491 |
rar_entries = E1000_RAR_ENTRIES_ICH8LAN; |
|
2492 |
||
2493 |
/* reserve RAR[14] for LAA over-write work-around */ |
|
2494 |
if (adapter->hw.mac_type == e1000_82571) |
|
2495 |
rar_entries--; |
|
2496 |
||
2497 |
/* Check for Promiscuous and All Multicast modes */ |
|
2498 |
||
2499 |
rctl = E1000_READ_REG(hw, RCTL); |
|
2500 |
||
2501 |
if (netdev->flags & IFF_PROMISC) { |
|
2502 |
rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
|
2503 |
} else if (netdev->flags & IFF_ALLMULTI) { |
|
2504 |
rctl |= E1000_RCTL_MPE; |
|
2505 |
rctl &= ~E1000_RCTL_UPE; |
|
2506 |
} else { |
|
2507 |
rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
|
2508 |
} |
|
2509 |
||
2510 |
E1000_WRITE_REG(hw, RCTL, rctl); |
|
2511 |
||
2512 |
/* 82542 2.0 needs to be in reset to write receive address registers */ |
|
2513 |
||
2514 |
if (hw->mac_type == e1000_82542_rev2_0) |
|
2515 |
e1000_enter_82542_rst(adapter); |
|
2516 |
||
2517 |
/* load the first 14 multicast address into the exact filters 1-14 |
|
2518 |
* RAR 0 is used for the station MAC adddress |
|
2519 |
* if there are not 14 addresses, go ahead and clear the filters |
|
2520 |
* -- with 82571 controllers only 0-13 entries are filled here |
|
2521 |
*/ |
|
2522 |
mc_ptr = netdev->mc_list; |
|
2523 |
||
2524 |
for (i = 1; i < rar_entries; i++) { |
|
2525 |
if (mc_ptr) { |
|
2526 |
e1000_rar_set(hw, mc_ptr->dmi_addr, i); |
|
2527 |
mc_ptr = mc_ptr->next; |
|
2528 |
} else { |
|
2529 |
E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
|
2530 |
E1000_WRITE_FLUSH(hw); |
|
2531 |
E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
|
2532 |
E1000_WRITE_FLUSH(hw); |
|
2533 |
} |
|
2534 |
} |
|
2535 |
||
2536 |
/* clear the old settings from the multicast hash table */ |
|
2537 |
||
2538 |
for (i = 0; i < mta_reg_count; i++) { |
|
2539 |
E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
|
2540 |
E1000_WRITE_FLUSH(hw); |
|
2541 |
} |
|
2542 |
||
2543 |
/* load any remaining addresses into the hash table */ |
|
2544 |
||
2545 |
for (; mc_ptr; mc_ptr = mc_ptr->next) { |
|
2546 |
hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr); |
|
2547 |
e1000_mta_set(hw, hash_value); |
|
2548 |
} |
|
2549 |
||
2550 |
if (hw->mac_type == e1000_82542_rev2_0) |
|
2551 |
e1000_leave_82542_rst(adapter); |
|
2552 |
} |
|
2553 |
||
2554 |
/* Need to wait a few seconds after link up to get diagnostic information from |
|
2555 |
* the phy */ |
|
2556 |
||
2557 |
static void |
|
2558 |
e1000_update_phy_info(unsigned long data) |
|
2559 |
{ |
|
2560 |
struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
|
2561 |
e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
|
2562 |
} |
|
2563 |
||
2564 |
/** |
|
2565 |
* e1000_82547_tx_fifo_stall - Timer Call-back |
|
2566 |
* @data: pointer to adapter cast into an unsigned long |
|
2567 |
**/ |
|
2568 |
||
2569 |
static void |
|
2570 |
e1000_82547_tx_fifo_stall(unsigned long data) |
|
2571 |
{ |
|
2572 |
struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
|
2573 |
struct net_device *netdev = adapter->netdev; |
|
2574 |
uint32_t tctl; |
|
2575 |
||
2576 |
if (atomic_read(&adapter->tx_fifo_stall)) { |
|
2577 |
if ((E1000_READ_REG(&adapter->hw, TDT) == |
|
2578 |
E1000_READ_REG(&adapter->hw, TDH)) && |
|
2579 |
(E1000_READ_REG(&adapter->hw, TDFT) == |
|
2580 |
E1000_READ_REG(&adapter->hw, TDFH)) && |
|
2581 |
(E1000_READ_REG(&adapter->hw, TDFTS) == |
|
2582 |
E1000_READ_REG(&adapter->hw, TDFHS))) { |
|
2583 |
tctl = E1000_READ_REG(&adapter->hw, TCTL); |
|
2584 |
E1000_WRITE_REG(&adapter->hw, TCTL, |
|
2585 |
tctl & ~E1000_TCTL_EN); |
|
2586 |
E1000_WRITE_REG(&adapter->hw, TDFT, |
|
2587 |
adapter->tx_head_addr); |
|
2588 |
E1000_WRITE_REG(&adapter->hw, TDFH, |
|
2589 |
adapter->tx_head_addr); |
|
2590 |
E1000_WRITE_REG(&adapter->hw, TDFTS, |
|
2591 |
adapter->tx_head_addr); |
|
2592 |
E1000_WRITE_REG(&adapter->hw, TDFHS, |
|
2593 |
adapter->tx_head_addr); |
|
2594 |
E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
|
2595 |
E1000_WRITE_FLUSH(&adapter->hw); |
|
2596 |
||
2597 |
adapter->tx_fifo_head = 0; |
|
2598 |
atomic_set(&adapter->tx_fifo_stall, 0); |
|
2599 |
if (!adapter->ecdev) netif_wake_queue(netdev); |
|
2600 |
} else { |
|
2601 |
if (!adapter->ecdev) |
|
2602 |
mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
|
2603 |
} |
|
2604 |
} |
|
2605 |
} |
|
2606 |
||
2607 |
/** |
|
2608 |
* e1000_watchdog - Timer Call-back |
|
2609 |
* @data: pointer to adapter cast into an unsigned long |
|
2610 |
**/ |
|
2611 |
static void |
|
2612 |
e1000_watchdog(unsigned long data) |
|
2613 |
{ |
|
2614 |
struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
|
2615 |
struct net_device *netdev = adapter->netdev; |
|
2616 |
struct e1000_tx_ring *txdr = adapter->tx_ring; |
|
2617 |
uint32_t link, tctl; |
|
2618 |
int32_t ret_val; |
|
2619 |
||
2620 |
ret_val = e1000_check_for_link(&adapter->hw); |
|
2621 |
if ((ret_val == E1000_ERR_PHY) && |
|
2622 |
(adapter->hw.phy_type == e1000_phy_igp_3) && |
|
2623 |
(E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
|
2624 |
/* See e1000_kumeran_lock_loss_workaround() */ |
|
2625 |
DPRINTK(LINK, INFO, |
|
2626 |
"Gigabit has been disabled, downgrading speed\n"); |
|
2627 |
} |
|
2628 |
||
2629 |
if (adapter->hw.mac_type == e1000_82573) { |
|
2630 |
e1000_enable_tx_pkt_filtering(&adapter->hw); |
|
2631 |
if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id) |
|
2632 |
e1000_update_mng_vlan(adapter); |
|
2633 |
} |
|
2634 |
||
2635 |
if ((adapter->hw.media_type == e1000_media_type_internal_serdes) && |
|
2636 |
!(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE)) |
|
2637 |
link = !adapter->hw.serdes_link_down; |
|
2638 |
else |
|
2639 |
link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU; |
|
2640 |
||
2641 |
if (link) { |
|
2642 |
if ((adapter->ecdev && !ecdev_get_link(adapter->ecdev)) |
|
2643 |
|| (!adapter->ecdev && !netif_carrier_ok(netdev))) { |
|
2644 |
boolean_t txb2b = 1; |
|
2645 |
e1000_get_speed_and_duplex(&adapter->hw, |
|
2646 |
&adapter->link_speed, |
|
2647 |
&adapter->link_duplex); |
|
2648 |
||
2649 |
DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n", |
|
2650 |
adapter->link_speed, |
|
2651 |
adapter->link_duplex == FULL_DUPLEX ? |
|
2652 |
"Full Duplex" : "Half Duplex"); |
|
2653 |
||
2654 |
/* tweak tx_queue_len according to speed/duplex |
|
2655 |
* and adjust the timeout factor */ |
|
2656 |
netdev->tx_queue_len = adapter->tx_queue_len; |
|
2657 |
adapter->tx_timeout_factor = 1; |
|
2658 |
switch (adapter->link_speed) { |
|
2659 |
case SPEED_10: |
|
2660 |
txb2b = 0; |
|
2661 |
netdev->tx_queue_len = 10; |
|
2662 |
adapter->tx_timeout_factor = 8; |
|
2663 |
break; |
|
2664 |
case SPEED_100: |
|
2665 |
txb2b = 0; |
|
2666 |
netdev->tx_queue_len = 100; |
|
2667 |
/* maybe add some timeout factor ? */ |
|
2668 |
break; |
|
2669 |
} |
|
2670 |
||
2671 |
if ((adapter->hw.mac_type == e1000_82571 || |
|
2672 |
adapter->hw.mac_type == e1000_82572) && |
|
2673 |
txb2b == 0) { |
|
2674 |
uint32_t tarc0; |
|
2675 |
tarc0 = E1000_READ_REG(&adapter->hw, TARC0); |
|
2676 |
tarc0 &= ~(1 << 21); |
|
2677 |
E1000_WRITE_REG(&adapter->hw, TARC0, tarc0); |
|
2678 |
} |
|
2679 |
||
2680 |
#ifdef NETIF_F_TSO |
|
2681 |
/* disable TSO for pcie and 10/100 speeds, to avoid |
|
2682 |
* some hardware issues */ |
|
2683 |
if (!adapter->tso_force && |
|
2684 |
adapter->hw.bus_type == e1000_bus_type_pci_express){ |
|
2685 |
switch (adapter->link_speed) { |
|
2686 |
case SPEED_10: |
|
2687 |
case SPEED_100: |
|
2688 |
DPRINTK(PROBE,INFO, |
|
2689 |
"10/100 speed: disabling TSO\n"); |
|
2690 |
netdev->features &= ~NETIF_F_TSO; |
|
2691 |
#ifdef NETIF_F_TSO6 |
|
2692 |
netdev->features &= ~NETIF_F_TSO6; |
|
2693 |
#endif |
|
2694 |
break; |
|
2695 |
case SPEED_1000: |
|
2696 |
netdev->features |= NETIF_F_TSO; |
|
2697 |
#ifdef NETIF_F_TSO6 |
|
2698 |
netdev->features |= NETIF_F_TSO6; |
|
2699 |
#endif |
|
2700 |
break; |
|
2701 |
default: |
|
2702 |
/* oops */ |
|
2703 |
break; |
|
2704 |
} |
|
2705 |
} |
|
2706 |
#endif |
|
2707 |
||
2708 |
/* enable transmits in the hardware, need to do this |
|
2709 |
* after setting TARC0 */ |
|
2710 |
tctl = E1000_READ_REG(&adapter->hw, TCTL); |
|
2711 |
tctl |= E1000_TCTL_EN; |
|
2712 |
E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
|
2713 |
||
2714 |
if (adapter->ecdev) { |
|
2715 |
ecdev_set_link(adapter->ecdev, 1); |
|
2716 |
} else { |
|
2717 |
netif_carrier_on(netdev); |
|
2718 |
netif_wake_queue(netdev); |
|
2719 |
mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); |
|
2720 |
} |
|
2721 |
adapter->smartspeed = 0; |
|
2722 |
} else { |
|
2723 |
/* make sure the receive unit is started */ |
|
2724 |
if (adapter->hw.rx_needs_kicking) { |
|
2725 |
struct e1000_hw *hw = &adapter->hw; |
|
2726 |
uint32_t rctl = E1000_READ_REG(hw, RCTL); |
|
2727 |
E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN); |
|
2728 |
} |
|
2729 |
} |
|
2730 |
} else { |
|
2731 |
if ((adapter->ecdev && ecdev_get_link(adapter->ecdev)) |
|
2732 |
|| (!adapter->ecdev && netif_carrier_ok(netdev))) { |
|
2733 |
adapter->link_speed = 0; |
|
2734 |
adapter->link_duplex = 0; |
|
2735 |
DPRINTK(LINK, INFO, "NIC Link is Down\n"); |
|
2736 |
if (adapter->ecdev) { |
|
2737 |
ecdev_set_link(adapter->ecdev, 0); |
|
2738 |
} else { |
|
2739 |
netif_carrier_off(netdev); |
|
2740 |
netif_stop_queue(netdev); |
|
2741 |
mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); |
|
2742 |
} |
|
2743 |
||
2744 |
/* 80003ES2LAN workaround-- |
|
2745 |
* For packet buffer work-around on link down event; |
|
2746 |
* disable receives in the ISR and |
|
2747 |
* reset device here in the watchdog |
|
2748 |
*/ |
|
2749 |
if (adapter->hw.mac_type == e1000_80003es2lan) |
|
2750 |
/* reset device */ |
|
2751 |
schedule_work(&adapter->reset_task); |
|
2752 |
} |
|
2753 |
||
2754 |
e1000_smartspeed(adapter); |
|
2755 |
} |
|
2756 |
||
2757 |
e1000_update_stats(adapter); |
|
2758 |
||
2759 |
adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
|
2760 |
adapter->tpt_old = adapter->stats.tpt; |
|
2761 |
adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old; |
|
2762 |
adapter->colc_old = adapter->stats.colc; |
|
2763 |
||
2764 |
adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
|
2765 |
adapter->gorcl_old = adapter->stats.gorcl; |
|
2766 |
adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
|
2767 |
adapter->gotcl_old = adapter->stats.gotcl; |
|
2768 |
||
2769 |
e1000_update_adaptive(&adapter->hw); |
|
2770 |
||
2771 |
if (!adapter->ecdev && !netif_carrier_ok(netdev)) { |
|
2772 |
if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
|
2773 |
/* We've lost link, so the controller stops DMA, |
|
2774 |
* but we've got queued Tx work that's never going |
|
2775 |
* to get done, so reset controller to flush Tx. |
|
2776 |
* (Do the reset outside of interrupt context). */ |
|
2777 |
adapter->tx_timeout_count++; |
|
2778 |
schedule_work(&adapter->reset_task); |
|
2779 |
} |
|
2780 |
} |
|
2781 |
||
2782 |
/* Cause software interrupt to ensure rx ring is cleaned */ |
|
2783 |
E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0); |
|
2784 |
||
2785 |
/* Force detection of hung controller every watchdog period */ |
|
2786 |
if (!adapter->ecdev) adapter->detect_tx_hung = TRUE; |
|
2787 |
||
2788 |
/* With 82571 controllers, LAA may be overwritten due to controller |
|
2789 |
* reset from the other port. Set the appropriate LAA in RAR[0] */ |
|
2790 |
if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present) |
|
2791 |
e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
|
2792 |
||
2793 |
/* Reset the timer */ |
|
2794 |
if (!adapter->ecdev) |
|
2795 |
mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
|
2796 |
} |
|
2797 |
||
2798 |
enum latency_range { |
|
2799 |
lowest_latency = 0, |
|
2800 |
low_latency = 1, |
|
2801 |
bulk_latency = 2, |
|
2802 |
latency_invalid = 255 |
|
2803 |
}; |
|
2804 |
||
2805 |
/** |
|
2806 |
* e1000_update_itr - update the dynamic ITR value based on statistics |
|
2807 |
* Stores a new ITR value based on packets and byte |
|
2808 |
* counts during the last interrupt. The advantage of per interrupt |
|
2809 |
* computation is faster updates and more accurate ITR for the current |
|
2810 |
* traffic pattern. Constants in this function were computed |
|
2811 |
* based on theoretical maximum wire speed and thresholds were set based |
|
2812 |
* on testing data as well as attempting to minimize response time |
|
2813 |
* while increasing bulk throughput. |
|
2814 |
* this functionality is controlled by the InterruptThrottleRate module |
|
2815 |
* parameter (see e1000_param.c) |
|
2816 |
* @adapter: pointer to adapter |
|
2817 |
* @itr_setting: current adapter->itr |
|
2818 |
* @packets: the number of packets during this measurement interval |
|
2819 |
* @bytes: the number of bytes during this measurement interval |
|
2820 |
**/ |
|
2821 |
static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
|
2822 |
uint16_t itr_setting, |
|
2823 |
int packets, |
|
2824 |
int bytes) |
|
2825 |
{ |
|
2826 |
unsigned int retval = itr_setting; |
|
2827 |
struct e1000_hw *hw = &adapter->hw; |
|
2828 |
||
2829 |
if (unlikely(hw->mac_type < e1000_82540)) |
|
2830 |
goto update_itr_done; |
|
2831 |
||
2832 |
if (packets == 0) |
|
2833 |
goto update_itr_done; |
|
2834 |
||
2835 |
switch (itr_setting) { |
|
2836 |
case lowest_latency: |
|
2837 |
/* jumbo frames get bulk treatment*/ |
|
2838 |
if (bytes/packets > 8000) |
|
2839 |
retval = bulk_latency; |
|
2840 |
else if ((packets < 5) && (bytes > 512)) |
|
2841 |
retval = low_latency; |
|
2842 |
break; |
|
2843 |
case low_latency: /* 50 usec aka 20000 ints/s */ |
|
2844 |
if (bytes > 10000) { |
|
2845 |
/* jumbo frames need bulk latency setting */ |
|
2846 |
if (bytes/packets > 8000) |
|
2847 |
retval = bulk_latency; |
|
2848 |
else if ((packets < 10) || ((bytes/packets) > 1200)) |
|
2849 |
retval = bulk_latency; |
|
2850 |
else if ((packets > 35)) |
|
2851 |
retval = lowest_latency; |
|
2852 |
} else if (bytes/packets > 2000) |
|
2853 |
retval = bulk_latency; |
|
2854 |
else if (packets <= 2 && bytes < 512) |
|
2855 |
retval = lowest_latency; |
|
2856 |
break; |
|
2857 |
case bulk_latency: /* 250 usec aka 4000 ints/s */ |
|
2858 |
if (bytes > 25000) { |
|
2859 |
if (packets > 35) |
|
2860 |
retval = low_latency; |
|
2861 |
} else if (bytes < 6000) { |
|
2862 |
retval = low_latency; |
|
2863 |
} |
|
2864 |
break; |
|
2865 |
} |
|
2866 |
||
2867 |
update_itr_done: |
|
2868 |
return retval; |
|
2869 |
} |
|
2870 |
||
2871 |
static void e1000_set_itr(struct e1000_adapter *adapter) |
|
2872 |
{ |
|
2873 |
struct e1000_hw *hw = &adapter->hw; |
|
2874 |
uint16_t current_itr; |
|
2875 |
uint32_t new_itr = adapter->itr; |
|
2876 |
||
2877 |
if (unlikely(hw->mac_type < e1000_82540)) |
|
2878 |
return; |
|
2879 |
||
2880 |
/* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
|
2881 |
if (unlikely(adapter->link_speed != SPEED_1000)) { |
|
2882 |
current_itr = 0; |
|
2883 |
new_itr = 4000; |
|
2884 |
goto set_itr_now; |
|
2885 |
} |
|
2886 |
||
2887 |
adapter->tx_itr = e1000_update_itr(adapter, |
|
2888 |
adapter->tx_itr, |
|
2889 |
adapter->total_tx_packets, |
|
2890 |
adapter->total_tx_bytes); |
|
2891 |
/* conservative mode (itr 3) eliminates the lowest_latency setting */ |
|
2892 |
if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
|
2893 |
adapter->tx_itr = low_latency; |
|
2894 |
||
2895 |
adapter->rx_itr = e1000_update_itr(adapter, |
|
2896 |
adapter->rx_itr, |
|
2897 |
adapter->total_rx_packets, |
|
2898 |
adapter->total_rx_bytes); |
|
2899 |
/* conservative mode (itr 3) eliminates the lowest_latency setting */ |
|
2900 |
if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
|
2901 |
adapter->rx_itr = low_latency; |
|
2902 |
||
2903 |
current_itr = max(adapter->rx_itr, adapter->tx_itr); |
|
2904 |
||
2905 |
switch (current_itr) { |
|
2906 |
/* counts and packets in update_itr are dependent on these numbers */ |
|
2907 |
case lowest_latency: |
|
2908 |
new_itr = 70000; |
|
2909 |
break; |
|
2910 |
case low_latency: |
|
2911 |
new_itr = 20000; /* aka hwitr = ~200 */ |
|
2912 |
break; |
|
2913 |
case bulk_latency: |
|
2914 |
new_itr = 4000; |
|
2915 |
break; |
|
2916 |
default: |
|
2917 |
break; |
|
2918 |
} |
|
2919 |
||
2920 |
set_itr_now: |
|
2921 |
if (new_itr != adapter->itr) { |
|
2922 |
/* this attempts to bias the interrupt rate towards Bulk |
|
2923 |
* by adding intermediate steps when interrupt rate is |
|
2924 |
* increasing */ |
|
2925 |
new_itr = new_itr > adapter->itr ? |
|
2926 |
min(adapter->itr + (new_itr >> 2), new_itr) : |
|
2927 |
new_itr; |
|
2928 |
adapter->itr = new_itr; |
|
2929 |
E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256)); |
|
2930 |
} |
|
2931 |
||
2932 |
return; |
|
2933 |
} |
|
2934 |
||
2935 |
#define E1000_TX_FLAGS_CSUM 0x00000001 |
|
2936 |
#define E1000_TX_FLAGS_VLAN 0x00000002 |
|
2937 |
#define E1000_TX_FLAGS_TSO 0x00000004 |
|
2938 |
#define E1000_TX_FLAGS_IPV4 0x00000008 |
|
2939 |
#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
|
2940 |
#define E1000_TX_FLAGS_VLAN_SHIFT 16 |
|
2941 |
||
2942 |
static int |
|
2943 |
e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
|
2944 |
struct sk_buff *skb) |
|
2945 |
{ |
|
2946 |
#ifdef NETIF_F_TSO |
|
2947 |
struct e1000_context_desc *context_desc; |
|
2948 |
struct e1000_buffer *buffer_info; |
|
2949 |
unsigned int i; |
|
2950 |
uint32_t cmd_length = 0; |
|
2951 |
uint16_t ipcse = 0, tucse, mss; |
|
2952 |
uint8_t ipcss, ipcso, tucss, tucso, hdr_len; |
|
2953 |
int err; |
|
2954 |
||
2955 |
if (skb_is_gso(skb)) { |
|
2956 |
if (skb_header_cloned(skb)) { |
|
2957 |
err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
|
2958 |
if (err) |
|
2959 |
return err; |
|
2960 |
} |
|
2961 |
||
2962 |
hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2)); |
|
2963 |
mss = skb_shinfo(skb)->gso_size; |
|
2964 |
if (skb->protocol == htons(ETH_P_IP)) { |
|
2965 |
skb->nh.iph->tot_len = 0; |
|
2966 |
skb->nh.iph->check = 0; |
|
2967 |
skb->h.th->check = |
|
2968 |
~csum_tcpudp_magic(skb->nh.iph->saddr, |
|
2969 |
skb->nh.iph->daddr, |
|
2970 |
0, |
|
2971 |
IPPROTO_TCP, |
|
2972 |
0); |
|
2973 |
cmd_length = E1000_TXD_CMD_IP; |
|
2974 |
ipcse = skb->h.raw - skb->data - 1; |
|
2975 |
#ifdef NETIF_F_TSO6 |
|
2976 |
} else if (skb->protocol == htons(ETH_P_IPV6)) { |
|
2977 |
skb->nh.ipv6h->payload_len = 0; |
|
2978 |
skb->h.th->check = |
|
2979 |
~csum_ipv6_magic(&skb->nh.ipv6h->saddr, |
|
2980 |
&skb->nh.ipv6h->daddr, |
|
2981 |
0, |
|
2982 |
IPPROTO_TCP, |
|
2983 |
0); |
|
2984 |
ipcse = 0; |
|
2985 |
#endif |
|
2986 |
} |
|
2987 |
ipcss = skb->nh.raw - skb->data; |
|
2988 |
ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data; |
|
2989 |
tucss = skb->h.raw - skb->data; |
|
2990 |
tucso = (void *)&(skb->h.th->check) - (void *)skb->data; |
|
2991 |
tucse = 0; |
|
2992 |
||
2993 |
cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
|
2994 |
E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
|
2995 |
||
2996 |
i = tx_ring->next_to_use; |
|
2997 |
context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
|
2998 |
buffer_info = &tx_ring->buffer_info[i]; |
|
2999 |
||
3000 |
context_desc->lower_setup.ip_fields.ipcss = ipcss; |
|
3001 |
context_desc->lower_setup.ip_fields.ipcso = ipcso; |
|
3002 |
context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
|
3003 |
context_desc->upper_setup.tcp_fields.tucss = tucss; |
|
3004 |
context_desc->upper_setup.tcp_fields.tucso = tucso; |
|
3005 |
context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
|
3006 |
context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
|
3007 |
context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
|
3008 |
context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
|
3009 |
||
3010 |
buffer_info->time_stamp = jiffies; |
|
3011 |
buffer_info->next_to_watch = i; |
|
3012 |
||
3013 |
if (++i == tx_ring->count) i = 0; |
|
3014 |
tx_ring->next_to_use = i; |
|
3015 |
||
3016 |
return TRUE; |
|
3017 |
} |
|
3018 |
#endif |
|
3019 |
||
3020 |
return FALSE; |
|
3021 |
} |
|
3022 |
||
3023 |
static boolean_t |
|
3024 |
e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
|
3025 |
struct sk_buff *skb) |
|
3026 |
{ |
|
3027 |
struct e1000_context_desc *context_desc; |
|
3028 |
struct e1000_buffer *buffer_info; |
|
3029 |
unsigned int i; |
|
3030 |
uint8_t css; |
|
3031 |
||
3032 |
if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
|
3033 |
css = skb->h.raw - skb->data; |
|
3034 |
||
3035 |
i = tx_ring->next_to_use; |
|
3036 |
buffer_info = &tx_ring->buffer_info[i]; |
|
3037 |
context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
|
3038 |
||
3039 |
context_desc->upper_setup.tcp_fields.tucss = css; |
|
3040 |
context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset; |
|
3041 |
context_desc->upper_setup.tcp_fields.tucse = 0; |
|
3042 |
context_desc->tcp_seg_setup.data = 0; |
|
3043 |
context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); |
|
3044 |
||
3045 |
buffer_info->time_stamp = jiffies; |
|
3046 |
buffer_info->next_to_watch = i; |
|
3047 |
||
3048 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
3049 |
tx_ring->next_to_use = i; |
|
3050 |
||
3051 |
return TRUE; |
|
3052 |
} |
|
3053 |
||
3054 |
return FALSE; |
|
3055 |
} |
|
3056 |
||
3057 |
#define E1000_MAX_TXD_PWR 12 |
|
3058 |
#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
|
3059 |
||
3060 |
static int |
|
3061 |
e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
|
3062 |
struct sk_buff *skb, unsigned int first, unsigned int max_per_txd, |
|
3063 |
unsigned int nr_frags, unsigned int mss) |
|
3064 |
{ |
|
3065 |
struct e1000_buffer *buffer_info; |
|
3066 |
unsigned int len = skb->len; |
|
3067 |
unsigned int offset = 0, size, count = 0, i; |
|
3068 |
unsigned int f; |
|
3069 |
len -= skb->data_len; |
|
3070 |
||
3071 |
i = tx_ring->next_to_use; |
|
3072 |
||
3073 |
while (len) { |
|
3074 |
buffer_info = &tx_ring->buffer_info[i]; |
|
3075 |
size = min(len, max_per_txd); |
|
3076 |
#ifdef NETIF_F_TSO |
|
3077 |
/* Workaround for Controller erratum -- |
|
3078 |
* descriptor for non-tso packet in a linear SKB that follows a |
|
3079 |
* tso gets written back prematurely before the data is fully |
|
3080 |
* DMA'd to the controller */ |
|
3081 |
if (!skb->data_len && tx_ring->last_tx_tso && |
|
3082 |
!skb_is_gso(skb)) { |
|
3083 |
tx_ring->last_tx_tso = 0; |
|
3084 |
size -= 4; |
|
3085 |
} |
|
3086 |
||
3087 |
/* Workaround for premature desc write-backs |
|
3088 |
* in TSO mode. Append 4-byte sentinel desc */ |
|
3089 |
if (unlikely(mss && !nr_frags && size == len && size > 8)) |
|
3090 |
size -= 4; |
|
3091 |
#endif |
|
3092 |
/* work-around for errata 10 and it applies |
|
3093 |
* to all controllers in PCI-X mode |
|
3094 |
* The fix is to make sure that the first descriptor of a |
|
3095 |
* packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
|
3096 |
*/ |
|
3097 |
if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
|
3098 |
(size > 2015) && count == 0)) |
|
3099 |
size = 2015; |
|
3100 |
||
3101 |
/* Workaround for potential 82544 hang in PCI-X. Avoid |
|
3102 |
* terminating buffers within evenly-aligned dwords. */ |
|
3103 |
if (unlikely(adapter->pcix_82544 && |
|
3104 |
!((unsigned long)(skb->data + offset + size - 1) & 4) && |
|
3105 |
size > 4)) |
|
3106 |
size -= 4; |
|
3107 |
||
3108 |
buffer_info->length = size; |
|
3109 |
buffer_info->dma = |
|
3110 |
pci_map_single(adapter->pdev, |
|
3111 |
skb->data + offset, |
|
3112 |
size, |
|
3113 |
PCI_DMA_TODEVICE); |
|
3114 |
buffer_info->time_stamp = jiffies; |
|
3115 |
buffer_info->next_to_watch = i; |
|
3116 |
||
3117 |
len -= size; |
|
3118 |
offset += size; |
|
3119 |
count++; |
|
3120 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
3121 |
} |
|
3122 |
||
3123 |
for (f = 0; f < nr_frags; f++) { |
|
3124 |
struct skb_frag_struct *frag; |
|
3125 |
||
3126 |
frag = &skb_shinfo(skb)->frags[f]; |
|
3127 |
len = frag->size; |
|
3128 |
offset = frag->page_offset; |
|
3129 |
||
3130 |
while (len) { |
|
3131 |
buffer_info = &tx_ring->buffer_info[i]; |
|
3132 |
size = min(len, max_per_txd); |
|
3133 |
#ifdef NETIF_F_TSO |
|
3134 |
/* Workaround for premature desc write-backs |
|
3135 |
* in TSO mode. Append 4-byte sentinel desc */ |
|
3136 |
if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
|
3137 |
size -= 4; |
|
3138 |
#endif |
|
3139 |
/* Workaround for potential 82544 hang in PCI-X. |
|
3140 |
* Avoid terminating buffers within evenly-aligned |
|
3141 |
* dwords. */ |
|
3142 |
if (unlikely(adapter->pcix_82544 && |
|
3143 |
!((unsigned long)(frag->page+offset+size-1) & 4) && |
|
3144 |
size > 4)) |
|
3145 |
size -= 4; |
|
3146 |
||
3147 |
buffer_info->length = size; |
|
3148 |
buffer_info->dma = |
|
3149 |
pci_map_page(adapter->pdev, |
|
3150 |
frag->page, |
|
3151 |
offset, |
|
3152 |
size, |
|
3153 |
PCI_DMA_TODEVICE); |
|
3154 |
buffer_info->time_stamp = jiffies; |
|
3155 |
buffer_info->next_to_watch = i; |
|
3156 |
||
3157 |
len -= size; |
|
3158 |
offset += size; |
|
3159 |
count++; |
|
3160 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
3161 |
} |
|
3162 |
} |
|
3163 |
||
3164 |
i = (i == 0) ? tx_ring->count - 1 : i - 1; |
|
3165 |
tx_ring->buffer_info[i].skb = skb; |
|
3166 |
tx_ring->buffer_info[first].next_to_watch = i; |
|
3167 |
||
3168 |
return count; |
|
3169 |
} |
|
3170 |
||
3171 |
static void |
|
3172 |
e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
|
3173 |
int tx_flags, int count) |
|
3174 |
{ |
|
3175 |
struct e1000_tx_desc *tx_desc = NULL; |
|
3176 |
struct e1000_buffer *buffer_info; |
|
3177 |
uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
|
3178 |
unsigned int i; |
|
3179 |
||
3180 |
if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
|
3181 |
txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
|
3182 |
E1000_TXD_CMD_TSE; |
|
3183 |
txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
|
3184 |
||
3185 |
if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
|
3186 |
txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
|
3187 |
} |
|
3188 |
||
3189 |
if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
|
3190 |
txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
|
3191 |
txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
|
3192 |
} |
|
3193 |
||
3194 |
if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
|
3195 |
txd_lower |= E1000_TXD_CMD_VLE; |
|
3196 |
txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
|
3197 |
} |
|
3198 |
||
3199 |
i = tx_ring->next_to_use; |
|
3200 |
||
3201 |
while (count--) { |
|
3202 |
buffer_info = &tx_ring->buffer_info[i]; |
|
3203 |
tx_desc = E1000_TX_DESC(*tx_ring, i); |
|
3204 |
tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
|
3205 |
tx_desc->lower.data = |
|
3206 |
cpu_to_le32(txd_lower | buffer_info->length); |
|
3207 |
tx_desc->upper.data = cpu_to_le32(txd_upper); |
|
3208 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
3209 |
} |
|
3210 |
||
3211 |
tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
|
3212 |
||
3213 |
/* Force memory writes to complete before letting h/w |
|
3214 |
* know there are new descriptors to fetch. (Only |
|
3215 |
* applicable for weak-ordered memory model archs, |
|
3216 |
* such as IA-64). */ |
|
3217 |
wmb(); |
|
3218 |
||
3219 |
tx_ring->next_to_use = i; |
|
3220 |
writel(i, adapter->hw.hw_addr + tx_ring->tdt); |
|
3221 |
/* we need this if more than one processor can write to our tail |
|
3222 |
* at a time, it syncronizes IO on IA64/Altix systems */ |
|
3223 |
mmiowb(); |
|
3224 |
} |
|
3225 |
||
3226 |
/** |
|
3227 |
* 82547 workaround to avoid controller hang in half-duplex environment. |
|
3228 |
* The workaround is to avoid queuing a large packet that would span |
|
3229 |
* the internal Tx FIFO ring boundary by notifying the stack to resend |
|
3230 |
* the packet at a later time. This gives the Tx FIFO an opportunity to |
|
3231 |
* flush all packets. When that occurs, we reset the Tx FIFO pointers |
|
3232 |
* to the beginning of the Tx FIFO. |
|
3233 |
**/ |
|
3234 |
||
3235 |
#define E1000_FIFO_HDR 0x10 |
|
3236 |
#define E1000_82547_PAD_LEN 0x3E0 |
|
3237 |
||
3238 |
static int |
|
3239 |
e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb) |
|
3240 |
{ |
|
3241 |
uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
|
3242 |
uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR; |
|
3243 |
||
3244 |
E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR); |
|
3245 |
||
3246 |
if (adapter->link_duplex != HALF_DUPLEX) |
|
3247 |
goto no_fifo_stall_required; |
|
3248 |
||
3249 |
if (atomic_read(&adapter->tx_fifo_stall)) |
|
3250 |
return 1; |
|
3251 |
||
3252 |
if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
|
3253 |
atomic_set(&adapter->tx_fifo_stall, 1); |
|
3254 |
return 1; |
|
3255 |
} |
|
3256 |
||
3257 |
no_fifo_stall_required: |
|
3258 |
adapter->tx_fifo_head += skb_fifo_len; |
|
3259 |
if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
|
3260 |
adapter->tx_fifo_head -= adapter->tx_fifo_size; |
|
3261 |
return 0; |
|
3262 |
} |
|
3263 |
||
3264 |
#define MINIMUM_DHCP_PACKET_SIZE 282 |
|
3265 |
static int |
|
3266 |
e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb) |
|
3267 |
{ |
|
3268 |
struct e1000_hw *hw = &adapter->hw; |
|
3269 |
uint16_t length, offset; |
|
3270 |
if (vlan_tx_tag_present(skb)) { |
|
3271 |
if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
|
3272 |
( adapter->hw.mng_cookie.status & |
|
3273 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
|
3274 |
return 0; |
|
3275 |
} |
|
3276 |
if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
|
3277 |
struct ethhdr *eth = (struct ethhdr *) skb->data; |
|
3278 |
if ((htons(ETH_P_IP) == eth->h_proto)) { |
|
3279 |
const struct iphdr *ip = |
|
3280 |
(struct iphdr *)((uint8_t *)skb->data+14); |
|
3281 |
if (IPPROTO_UDP == ip->protocol) { |
|
3282 |
struct udphdr *udp = |
|
3283 |
(struct udphdr *)((uint8_t *)ip + |
|
3284 |
(ip->ihl << 2)); |
|
3285 |
if (ntohs(udp->dest) == 67) { |
|
3286 |
offset = (uint8_t *)udp + 8 - skb->data; |
|
3287 |
length = skb->len - offset; |
|
3288 |
||
3289 |
return e1000_mng_write_dhcp_info(hw, |
|
3290 |
(uint8_t *)udp + 8, |
|
3291 |
length); |
|
3292 |
} |
|
3293 |
} |
|
3294 |
} |
|
3295 |
} |
|
3296 |
return 0; |
|
3297 |
} |
|
3298 |
||
3299 |
static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
|
3300 |
{ |
|
3301 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3302 |
struct e1000_tx_ring *tx_ring = adapter->tx_ring; |
|
3303 |
||
2471
fc64a4b1ec1a
Fixed __e1000_maybe_stop_tx().
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
3304 |
if (adapter->ecdev) { |
fc64a4b1ec1a
Fixed __e1000_maybe_stop_tx().
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
3305 |
return -EBUSY; |
fc64a4b1ec1a
Fixed __e1000_maybe_stop_tx().
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
3306 |
} |
fc64a4b1ec1a
Fixed __e1000_maybe_stop_tx().
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
3307 |
|
680 | 3308 |
netif_stop_queue(netdev); |
3309 |
/* Herbert's original patch had: |
|
3310 |
* smp_mb__after_netif_stop_queue(); |
|
3311 |
* but since that doesn't exist yet, just open code it. */ |
|
3312 |
smp_mb(); |
|
3313 |
||
3314 |
/* We need to check again in a case another CPU has just |
|
3315 |
* made room available. */ |
|
3316 |
if (likely(E1000_DESC_UNUSED(tx_ring) < size)) |
|
3317 |
return -EBUSY; |
|
3318 |
||
3319 |
/* A reprieve! */ |
|
3320 |
netif_start_queue(netdev); |
|
3321 |
++adapter->restart_queue; |
|
3322 |
return 0; |
|
3323 |
} |
|
3324 |
||
3325 |
static int e1000_maybe_stop_tx(struct net_device *netdev, |
|
3326 |
struct e1000_tx_ring *tx_ring, int size) |
|
3327 |
{ |
|
3328 |
if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) |
|
3329 |
return 0; |
|
3330 |
return __e1000_maybe_stop_tx(netdev, size); |
|
3331 |
} |
|
3332 |
||
3333 |
#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
|
3334 |
static int |
|
3335 |
e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
|
3336 |
{ |
|
3337 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3338 |
struct e1000_tx_ring *tx_ring; |
|
3339 |
unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
|
3340 |
unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
|
3341 |
unsigned int tx_flags = 0; |
|
3342 |
unsigned int len = skb->len; |
|
3343 |
unsigned long flags = 0; |
|
3344 |
unsigned int nr_frags = 0; |
|
3345 |
unsigned int mss = 0; |
|
3346 |
int count = 0; |
|
3347 |
int tso; |
|
3348 |
unsigned int f; |
|
3349 |
len -= skb->data_len; |
|
3350 |
||
3351 |
/* This goes back to the question of how to logically map a tx queue |
|
3352 |
* to a flow. Right now, performance is impacted slightly negatively |
|
3353 |
* if using multiple tx queues. If the stack breaks away from a |
|
3354 |
* single qdisc implementation, we can look at this again. */ |
|
3355 |
tx_ring = adapter->tx_ring; |
|
3356 |
||
3357 |
if (unlikely(skb->len <= 0)) { |
|
3358 |
if (!adapter->ecdev) |
|
3359 |
dev_kfree_skb_any(skb); |
|
3360 |
return NETDEV_TX_OK; |
|
3361 |
} |
|
3362 |
||
3363 |
/* 82571 and newer doesn't need the workaround that limited descriptor |
|
3364 |
* length to 4kB */ |
|
3365 |
if (adapter->hw.mac_type >= e1000_82571) |
|
3366 |
max_per_txd = 8192; |
|
3367 |
||
3368 |
#ifdef NETIF_F_TSO |
|
3369 |
mss = skb_shinfo(skb)->gso_size; |
|
3370 |
/* The controller does a simple calculation to |
|
3371 |
* make sure there is enough room in the FIFO before |
|
3372 |
* initiating the DMA for each buffer. The calc is: |
|
3373 |
* 4 = ceil(buffer len/mss). To make sure we don't |
|
3374 |
* overrun the FIFO, adjust the max buffer len if mss |
|
3375 |
* drops. */ |
|
3376 |
if (mss) { |
|
3377 |
uint8_t hdr_len; |
|
3378 |
max_per_txd = min(mss << 2, max_per_txd); |
|
3379 |
max_txd_pwr = fls(max_per_txd) - 1; |
|
3380 |
||
3381 |
/* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
|
3382 |
* points to just header, pull a few bytes of payload from |
|
3383 |
* frags into skb->data */ |
|
3384 |
hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2)); |
|
3385 |
if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) { |
|
3386 |
switch (adapter->hw.mac_type) { |
|
3387 |
unsigned int pull_size; |
|
3388 |
case e1000_82544: |
|
3389 |
/* Make sure we have room to chop off 4 bytes, |
|
3390 |
* and that the end alignment will work out to |
|
3391 |
* this hardware's requirements |
|
3392 |
* NOTE: this is a TSO only workaround |
|
3393 |
* if end byte alignment not correct move us |
|
3394 |
* into the next dword */ |
|
3395 |
if ((unsigned long)(skb->tail - 1) & 4) |
|
3396 |
break; |
|
3397 |
/* fall through */ |
|
3398 |
case e1000_82571: |
|
3399 |
case e1000_82572: |
|
3400 |
case e1000_82573: |
|
3401 |
case e1000_ich8lan: |
|
3402 |
pull_size = min((unsigned int)4, skb->data_len); |
|
3403 |
if (!__pskb_pull_tail(skb, pull_size)) { |
|
3404 |
DPRINTK(DRV, ERR, |
|
3405 |
"__pskb_pull_tail failed.\n"); |
|
3406 |
dev_kfree_skb_any(skb); |
|
3407 |
return NETDEV_TX_OK; |
|
3408 |
} |
|
3409 |
len = skb->len - skb->data_len; |
|
3410 |
break; |
|
3411 |
default: |
|
3412 |
/* do nothing */ |
|
3413 |
break; |
|
3414 |
} |
|
3415 |
} |
|
3416 |
} |
|
3417 |
||
3418 |
/* reserve a descriptor for the offload context */ |
|
3419 |
if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
|
3420 |
count++; |
|
3421 |
count++; |
|
3422 |
#else |
|
3423 |
if (skb->ip_summed == CHECKSUM_PARTIAL) |
|
3424 |
count++; |
|
3425 |
#endif |
|
3426 |
||
3427 |
#ifdef NETIF_F_TSO |
|
3428 |
/* Controller Erratum workaround */ |
|
3429 |
if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb)) |
|
3430 |
count++; |
|
3431 |
#endif |
|
3432 |
||
3433 |
count += TXD_USE_COUNT(len, max_txd_pwr); |
|
3434 |
||
3435 |
if (adapter->pcix_82544) |
|
3436 |
count++; |
|
3437 |
||
3438 |
/* work-around for errata 10 and it applies to all controllers |
|
3439 |
* in PCI-X mode, so add one more descriptor to the count |
|
3440 |
*/ |
|
3441 |
if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
|
3442 |
(len > 2015))) |
|
3443 |
count++; |
|
3444 |
||
3445 |
nr_frags = skb_shinfo(skb)->nr_frags; |
|
3446 |
for (f = 0; f < nr_frags; f++) |
|
3447 |
count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
|
3448 |
max_txd_pwr); |
|
3449 |
if (adapter->pcix_82544) |
|
3450 |
count += nr_frags; |
|
3451 |
||
3452 |
||
3453 |
if (adapter->hw.tx_pkt_filtering && |
|
3454 |
(adapter->hw.mac_type == e1000_82573)) |
|
3455 |
e1000_transfer_dhcp_info(adapter, skb); |
|
3456 |
||
3457 |
if (!adapter->ecdev) { |
|
3458 |
local_irq_save(flags); |
|
3459 |
if (!spin_trylock(&tx_ring->tx_lock)) { |
|
3460 |
/* Collision - tell upper layer to requeue */ |
|
3461 |
local_irq_restore(flags); |
|
3462 |
return NETDEV_TX_LOCKED; |
|
3463 |
} |
|
3464 |
} |
|
3465 |
||
3466 |
/* need: count + 2 desc gap to keep tail from touching |
|
3467 |
* head, otherwise try next time */ |
|
3468 |
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
|
3469 |
if (!adapter->ecdev) { |
04bcd38cf8dc
Fixed missing protection for a spin_lock_irqrestore() call.
Florian Pose <fp@igh-essen.com>
parents:
1152
diff
changeset
|
3470 |
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
|
3471 |
} |
680 | 3472 |
return NETDEV_TX_BUSY; |
3473 |
} |
|
3474 |
||
3475 |
if (unlikely(adapter->hw.mac_type == e1000_82547)) { |
|
3476 |
if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
|
3477 |
if (!adapter->ecdev) { |
|
3478 |
netif_stop_queue(netdev); |
|
3479 |
mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
|
3480 |
spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
|
3481 |
} |
|
3482 |
return NETDEV_TX_BUSY; |
|
3483 |
} |
|
3484 |
} |
|
3485 |
||
3486 |
if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
|
3487 |
tx_flags |= E1000_TX_FLAGS_VLAN; |
|
3488 |
tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
|
3489 |
} |
|
3490 |
||
3491 |
first = tx_ring->next_to_use; |
|
3492 |
||
3493 |
tso = e1000_tso(adapter, tx_ring, skb); |
|
3494 |
if (tso < 0) { |
|
3495 |
if (!adapter->ecdev) { |
|
3496 |
dev_kfree_skb_any(skb); |
|
3497 |
spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
|
3498 |
} |
|
3499 |
return NETDEV_TX_OK; |
|
3500 |
} |
|
3501 |
||
3502 |
if (likely(tso)) { |
|
3503 |
tx_ring->last_tx_tso = 1; |
|
3504 |
tx_flags |= E1000_TX_FLAGS_TSO; |
|
3505 |
} else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
|
3506 |
tx_flags |= E1000_TX_FLAGS_CSUM; |
|
3507 |
||
3508 |
/* Old method was to assume IPv4 packet by default if TSO was enabled. |
|
3509 |
* 82571 hardware supports TSO capabilities for IPv6 as well... |
|
3510 |
* no longer assume, we must. */ |
|
3511 |
if (likely(skb->protocol == htons(ETH_P_IP))) |
|
3512 |
tx_flags |= E1000_TX_FLAGS_IPV4; |
|
3513 |
||
3514 |
e1000_tx_queue(adapter, tx_ring, tx_flags, |
|
3515 |
e1000_tx_map(adapter, tx_ring, skb, first, |
|
3516 |
max_per_txd, nr_frags, mss)); |
|
3517 |
||
3518 |
netdev->trans_start = jiffies; |
|
3519 |
||
3520 |
if (!adapter->ecdev) { |
|
3521 |
/* Make sure there is space in the ring for the next send. */ |
|
3522 |
e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); |
|
3523 |
||
3524 |
spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
|
3525 |
} |
|
3526 |
return NETDEV_TX_OK; |
|
3527 |
} |
|
3528 |
||
3529 |
/** |
|
3530 |
* e1000_tx_timeout - Respond to a Tx Hang |
|
3531 |
* @netdev: network interface device structure |
|
3532 |
**/ |
|
3533 |
||
3534 |
static void |
|
3535 |
e1000_tx_timeout(struct net_device *netdev) |
|
3536 |
{ |
|
3537 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3538 |
||
3539 |
/* Do the reset outside of interrupt context */ |
|
3540 |
adapter->tx_timeout_count++; |
|
3541 |
schedule_work(&adapter->reset_task); |
|
3542 |
} |
|
3543 |
||
3544 |
static void |
|
3545 |
e1000_reset_task(struct work_struct *work) |
|
3546 |
{ |
|
3547 |
struct e1000_adapter *adapter = |
|
3548 |
container_of(work, struct e1000_adapter, reset_task); |
|
3549 |
||
3550 |
e1000_reinit_locked(adapter); |
|
3551 |
} |
|
3552 |
||
3553 |
/** |
|
3554 |
* e1000_get_stats - Get System Network Statistics |
|
3555 |
* @netdev: network interface device structure |
|
3556 |
* |
|
3557 |
* Returns the address of the device statistics structure. |
|
3558 |
* The statistics are actually updated from the timer callback. |
|
3559 |
**/ |
|
3560 |
||
3561 |
static struct net_device_stats * |
|
3562 |
e1000_get_stats(struct net_device *netdev) |
|
3563 |
{ |
|
3564 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3565 |
||
3566 |
/* only return the current stats */ |
|
3567 |
return &adapter->net_stats; |
|
3568 |
} |
|
3569 |
||
3570 |
/** |
|
3571 |
* e1000_change_mtu - Change the Maximum Transfer Unit |
|
3572 |
* @netdev: network interface device structure |
|
3573 |
* @new_mtu: new value for maximum frame size |
|
3574 |
* |
|
3575 |
* Returns 0 on success, negative on failure |
|
3576 |
**/ |
|
3577 |
||
3578 |
static int |
|
3579 |
e1000_change_mtu(struct net_device *netdev, int new_mtu) |
|
3580 |
{ |
|
3581 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3582 |
int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
|
3583 |
uint16_t eeprom_data = 0; |
|
3584 |
||
3585 |
if (adapter->ecdev) |
|
3586 |
return -EBUSY; |
|
3587 |
||
3588 |
if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
|
3589 |
(max_frame > MAX_JUMBO_FRAME_SIZE)) { |
|
3590 |
DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
|
3591 |
return -EINVAL; |
|
3592 |
} |
|
3593 |
||
3594 |
/* Adapter-specific max frame size limits. */ |
|
3595 |
switch (adapter->hw.mac_type) { |
|
3596 |
case e1000_undefined ... e1000_82542_rev2_1: |
|
3597 |
case e1000_ich8lan: |
|
3598 |
if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
|
3599 |
DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
|
3600 |
return -EINVAL; |
|
3601 |
} |
|
3602 |
break; |
|
3603 |
case e1000_82573: |
|
3604 |
/* Jumbo Frames not supported if: |
|
3605 |
* - this is not an 82573L device |
|
3606 |
* - ASPM is enabled in any way (0x1A bits 3:2) */ |
|
3607 |
e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1, |
|
3608 |
&eeprom_data); |
|
3609 |
if ((adapter->hw.device_id != E1000_DEV_ID_82573L) || |
|
3610 |
(eeprom_data & EEPROM_WORD1A_ASPM_MASK)) { |
|
3611 |
if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
|
3612 |
DPRINTK(PROBE, ERR, |
|
3613 |
"Jumbo Frames not supported.\n"); |
|
3614 |
return -EINVAL; |
|
3615 |
} |
|
3616 |
break; |
|
3617 |
} |
|
3618 |
/* ERT will be enabled later to enable wire speed receives */ |
|
3619 |
||
3620 |
/* fall through to get support */ |
|
3621 |
case e1000_82571: |
|
3622 |
case e1000_82572: |
|
3623 |
case e1000_80003es2lan: |
|
3624 |
#define MAX_STD_JUMBO_FRAME_SIZE 9234 |
|
3625 |
if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
|
3626 |
DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
|
3627 |
return -EINVAL; |
|
3628 |
} |
|
3629 |
break; |
|
3630 |
default: |
|
3631 |
/* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
|
3632 |
break; |
|
3633 |
} |
|
3634 |
||
3635 |
/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
|
3636 |
* means we reserve 2 more, this pushes us to allocate from the next |
|
3637 |
* larger slab size |
|
3638 |
* i.e. RXBUFFER_2048 --> size-4096 slab */ |
|
3639 |
||
3640 |
if (max_frame <= E1000_RXBUFFER_256) |
|
3641 |
adapter->rx_buffer_len = E1000_RXBUFFER_256; |
|
3642 |
else if (max_frame <= E1000_RXBUFFER_512) |
|
3643 |
adapter->rx_buffer_len = E1000_RXBUFFER_512; |
|
3644 |
else if (max_frame <= E1000_RXBUFFER_1024) |
|
3645 |
adapter->rx_buffer_len = E1000_RXBUFFER_1024; |
|
3646 |
else if (max_frame <= E1000_RXBUFFER_2048) |
|
3647 |
adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
|
3648 |
else if (max_frame <= E1000_RXBUFFER_4096) |
|
3649 |
adapter->rx_buffer_len = E1000_RXBUFFER_4096; |
|
3650 |
else if (max_frame <= E1000_RXBUFFER_8192) |
|
3651 |
adapter->rx_buffer_len = E1000_RXBUFFER_8192; |
|
3652 |
else if (max_frame <= E1000_RXBUFFER_16384) |
|
3653 |
adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
|
3654 |
||
3655 |
/* adjust allocation if LPE protects us, and we aren't using SBP */ |
|
3656 |
if (!adapter->hw.tbi_compatibility_on && |
|
3657 |
((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) || |
|
3658 |
(max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) |
|
3659 |
adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
|
3660 |
||
3661 |
netdev->mtu = new_mtu; |
|
3662 |
adapter->hw.max_frame_size = max_frame; |
|
3663 |
||
3664 |
if (netif_running(netdev)) |
|
3665 |
e1000_reinit_locked(adapter); |
|
3666 |
||
3667 |
return 0; |
|
3668 |
} |
|
3669 |
||
3670 |
/** |
|
3671 |
* e1000_update_stats - Update the board statistics counters |
|
3672 |
* @adapter: board private structure |
|
3673 |
**/ |
|
3674 |
||
3675 |
void |
|
3676 |
e1000_update_stats(struct e1000_adapter *adapter) |
|
3677 |
{ |
|
3678 |
struct e1000_hw *hw = &adapter->hw; |
|
3679 |
struct pci_dev *pdev = adapter->pdev; |
|
3680 |
unsigned long flags = 0; |
|
3681 |
uint16_t phy_tmp; |
|
3682 |
||
3683 |
#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
|
3684 |
||
3685 |
/* |
|
3686 |
* Prevent stats update while adapter is being reset, or if the pci |
|
3687 |
* connection is down. |
|
3688 |
*/ |
|
3689 |
if (adapter->link_speed == 0) |
|
3690 |
return; |
|
3691 |
if (pdev->error_state && pdev->error_state != pci_channel_io_normal) |
|
3692 |
return; |
|
3693 |
||
3694 |
if (!adapter->ecdev) |
|
3695 |
spin_lock_irqsave(&adapter->stats_lock, flags); |
|
3696 |
||
3697 |
/* these counters are modified from e1000_adjust_tbi_stats, |
|
3698 |
* called from the interrupt context, so they must only |
|
3699 |
* be written while holding adapter->stats_lock |
|
3700 |
*/ |
|
3701 |
||
3702 |
adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS); |
|
3703 |
adapter->stats.gprc += E1000_READ_REG(hw, GPRC); |
|
3704 |
adapter->stats.gorcl += E1000_READ_REG(hw, GORCL); |
|
3705 |
adapter->stats.gorch += E1000_READ_REG(hw, GORCH); |
|
3706 |
adapter->stats.bprc += E1000_READ_REG(hw, BPRC); |
|
3707 |
adapter->stats.mprc += E1000_READ_REG(hw, MPRC); |
|
3708 |
adapter->stats.roc += E1000_READ_REG(hw, ROC); |
|
3709 |
||
3710 |
if (adapter->hw.mac_type != e1000_ich8lan) { |
|
3711 |
adapter->stats.prc64 += E1000_READ_REG(hw, PRC64); |
|
3712 |
adapter->stats.prc127 += E1000_READ_REG(hw, PRC127); |
|
3713 |
adapter->stats.prc255 += E1000_READ_REG(hw, PRC255); |
|
3714 |
adapter->stats.prc511 += E1000_READ_REG(hw, PRC511); |
|
3715 |
adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023); |
|
3716 |
adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522); |
|
3717 |
} |
|
3718 |
||
3719 |
adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS); |
|
3720 |
adapter->stats.mpc += E1000_READ_REG(hw, MPC); |
|
3721 |
adapter->stats.scc += E1000_READ_REG(hw, SCC); |
|
3722 |
adapter->stats.ecol += E1000_READ_REG(hw, ECOL); |
|
3723 |
adapter->stats.mcc += E1000_READ_REG(hw, MCC); |
|
3724 |
adapter->stats.latecol += E1000_READ_REG(hw, LATECOL); |
|
3725 |
adapter->stats.dc += E1000_READ_REG(hw, DC); |
|
3726 |
adapter->stats.sec += E1000_READ_REG(hw, SEC); |
|
3727 |
adapter->stats.rlec += E1000_READ_REG(hw, RLEC); |
|
3728 |
adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC); |
|
3729 |
adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC); |
|
3730 |
adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC); |
|
3731 |
adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC); |
|
3732 |
adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC); |
|
3733 |
adapter->stats.gptc += E1000_READ_REG(hw, GPTC); |
|
3734 |
adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL); |
|
3735 |
adapter->stats.gotch += E1000_READ_REG(hw, GOTCH); |
|
3736 |
adapter->stats.rnbc += E1000_READ_REG(hw, RNBC); |
|
3737 |
adapter->stats.ruc += E1000_READ_REG(hw, RUC); |
|
3738 |
adapter->stats.rfc += E1000_READ_REG(hw, RFC); |
|
3739 |
adapter->stats.rjc += E1000_READ_REG(hw, RJC); |
|
3740 |
adapter->stats.torl += E1000_READ_REG(hw, TORL); |
|
3741 |
adapter->stats.torh += E1000_READ_REG(hw, TORH); |
|
3742 |
adapter->stats.totl += E1000_READ_REG(hw, TOTL); |
|
3743 |
adapter->stats.toth += E1000_READ_REG(hw, TOTH); |
|
3744 |
adapter->stats.tpr += E1000_READ_REG(hw, TPR); |
|
3745 |
||
3746 |
if (adapter->hw.mac_type != e1000_ich8lan) { |
|
3747 |
adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64); |
|
3748 |
adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127); |
|
3749 |
adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255); |
|
3750 |
adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511); |
|
3751 |
adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023); |
|
3752 |
adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522); |
|
3753 |
} |
|
3754 |
||
3755 |
adapter->stats.mptc += E1000_READ_REG(hw, MPTC); |
|
3756 |
adapter->stats.bptc += E1000_READ_REG(hw, BPTC); |
|
3757 |
||
3758 |
/* used for adaptive IFS */ |
|
3759 |
||
3760 |
hw->tx_packet_delta = E1000_READ_REG(hw, TPT); |
|
3761 |
adapter->stats.tpt += hw->tx_packet_delta; |
|
3762 |
hw->collision_delta = E1000_READ_REG(hw, COLC); |
|
3763 |
adapter->stats.colc += hw->collision_delta; |
|
3764 |
||
3765 |
if (hw->mac_type >= e1000_82543) { |
|
3766 |
adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC); |
|
3767 |
adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC); |
|
3768 |
adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS); |
|
3769 |
adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR); |
|
3770 |
adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC); |
|
3771 |
adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC); |
|
3772 |
} |
|
3773 |
if (hw->mac_type > e1000_82547_rev_2) { |
|
3774 |
adapter->stats.iac += E1000_READ_REG(hw, IAC); |
|
3775 |
adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC); |
|
3776 |
||
3777 |
if (adapter->hw.mac_type != e1000_ich8lan) { |
|
3778 |
adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC); |
|
3779 |
adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC); |
|
3780 |
adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC); |
|
3781 |
adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC); |
|
3782 |
adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC); |
|
3783 |
adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC); |
|
3784 |
adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC); |
|
3785 |
} |
|
3786 |
} |
|
3787 |
||
3788 |
/* Fill out the OS statistics structure */ |
|
3789 |
adapter->net_stats.rx_packets = adapter->stats.gprc; |
|
3790 |
adapter->net_stats.tx_packets = adapter->stats.gptc; |
|
3791 |
adapter->net_stats.rx_bytes = adapter->stats.gorcl; |
|
3792 |
adapter->net_stats.tx_bytes = adapter->stats.gotcl; |
|
3793 |
adapter->net_stats.multicast = adapter->stats.mprc; |
|
3794 |
adapter->net_stats.collisions = adapter->stats.colc; |
|
3795 |
||
3796 |
/* Rx Errors */ |
|
3797 |
||
3798 |
/* RLEC on some newer hardware can be incorrect so build |
|
3799 |
* our own version based on RUC and ROC */ |
|
3800 |
adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
|
3801 |
adapter->stats.crcerrs + adapter->stats.algnerrc + |
|
3802 |
adapter->stats.ruc + adapter->stats.roc + |
|
3803 |
adapter->stats.cexterr; |
|
3804 |
adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; |
|
3805 |
adapter->net_stats.rx_length_errors = adapter->stats.rlerrc; |
|
3806 |
adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
|
3807 |
adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
|
3808 |
adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
|
3809 |
||
3810 |
/* Tx Errors */ |
|
3811 |
adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; |
|
3812 |
adapter->net_stats.tx_errors = adapter->stats.txerrc; |
|
3813 |
adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
|
3814 |
adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
|
3815 |
adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
|
3816 |
if (adapter->hw.bad_tx_carr_stats_fd && |
|
3817 |
adapter->link_duplex == FULL_DUPLEX) { |
|
3818 |
adapter->net_stats.tx_carrier_errors = 0; |
|
3819 |
adapter->stats.tncrs = 0; |
|
3820 |
} |
|
3821 |
||
3822 |
/* Tx Dropped needs to be maintained elsewhere */ |
|
3823 |
||
3824 |
/* Phy Stats */ |
|
3825 |
if (hw->media_type == e1000_media_type_copper) { |
|
3826 |
if ((adapter->link_speed == SPEED_1000) && |
|
3827 |
(!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
|
3828 |
phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
|
3829 |
adapter->phy_stats.idle_errors += phy_tmp; |
|
3830 |
} |
|
3831 |
||
3832 |
if ((hw->mac_type <= e1000_82546) && |
|
3833 |
(hw->phy_type == e1000_phy_m88) && |
|
3834 |
!e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
|
3835 |
adapter->phy_stats.receive_errors += phy_tmp; |
|
3836 |
} |
|
3837 |
||
3838 |
/* Management Stats */ |
|
3839 |
if (adapter->hw.has_smbus) { |
|
3840 |
adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC); |
|
3841 |
adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC); |
|
3842 |
adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC); |
|
3843 |
} |
|
3844 |
||
3845 |
if (!adapter->ecdev) |
|
3846 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
3847 |
} |
|
3848 |
||
3849 |
void ec_poll(struct net_device *netdev) |
|
3850 |
{ |
|
3851 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3852 |
||
3853 |
if (jiffies - adapter->ec_watchdog_jiffies >= 2 * HZ) { |
|
3854 |
e1000_watchdog((unsigned long) adapter); |
|
3855 |
adapter->ec_watchdog_jiffies = jiffies; |
|
3856 |
} |
|
3857 |
||
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3858 |
#ifdef CONFIG_PCI_MSI |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3859 |
e1000_intr_msi(0, netdev); |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3860 |
#else |
680 | 3861 |
e1000_intr(0, netdev); |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3862 |
#endif |
680 | 3863 |
} |
3864 |
||
3865 |
#ifdef CONFIG_PCI_MSI |
|
3866 |
/** |
|
3867 |
* e1000_intr_msi - Interrupt Handler |
|
3868 |
* @irq: interrupt number |
|
3869 |
* @data: pointer to a network interface device structure |
|
3870 |
**/ |
|
3871 |
||
3872 |
static |
|
3873 |
irqreturn_t e1000_intr_msi(int irq, void *data) |
|
3874 |
{ |
|
3875 |
struct net_device *netdev = data; |
|
3876 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3877 |
struct e1000_hw *hw = &adapter->hw; |
|
3878 |
int i; |
|
1325
16aacb421bd4
merge -c1602 branches/stable-1.4: Fixed e1000 ring bug.
Florian Pose <fp@igh-essen.com>
parents:
1154
diff
changeset
|
3879 |
|
16aacb421bd4
merge -c1602 branches/stable-1.4: Fixed e1000 ring bug.
Florian Pose <fp@igh-essen.com>
parents:
1154
diff
changeset
|
3880 |
if (adapter->ecdev) { |
680 | 3881 |
#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
|
3882 |
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
|
3883 |
#endif |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3884 |
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
|
3885 |
#ifdef CONFIG_E1000_NAPI |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3886 |
if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring, |
2050
a3e59f2a8589
Changed accidentally used & operator to &&.
Florian Pose <fp@igh-essen.com>
parents:
1325
diff
changeset
|
3887 |
&ec_work_done, 100) && |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3888 |
!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
|
3889 |
#else |
2050
a3e59f2a8589
Changed accidentally used & operator to &&.
Florian Pose <fp@igh-essen.com>
parents:
1325
diff
changeset
|
3890 |
if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) && |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3891 |
!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
|
3892 |
#endif |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3893 |
break; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3894 |
} else { |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3895 |
/* 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
|
3896 |
* 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
|
3897 |
if (++adapter->detect_link >= 1000) { |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3898 |
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
|
3899 |
#ifdef CONFIG_E1000_NAPI |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3900 |
/* 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
|
3901 |
* enable/disable accounting */ |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3902 |
atomic_inc(&adapter->irq_sem); |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3903 |
#endif |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3904 |
adapter->detect_link = 0; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3905 |
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
|
3906 |
(icr & E1000_ICR_INT_ASSERTED)) { |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3907 |
hw->get_link_status = 1; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3908 |
/* 80003ES2LAN workaround-- |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3909 |
* 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
|
3910 |
* disable receives here in the ISR and |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3911 |
* reset adapter in watchdog |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3912 |
*/ |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3913 |
if (netif_carrier_ok(netdev) && |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3914 |
(adapter->hw.mac_type == e1000_80003es2lan)) { |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3915 |
/* disable receives */ |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3916 |
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
|
3917 |
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
|
3918 |
} |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3919 |
/* 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
|
3920 |
if (!test_bit(__E1000_DOWN, &adapter->flags)) |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3921 |
mod_timer(&adapter->watchdog_timer, |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3922 |
jiffies + 1); |
680 | 3923 |
} |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3924 |
} else { |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3925 |
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
|
3926 |
E1000_ICR_LSC))); |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3927 |
/* 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
|
3928 |
* 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
|
3929 |
* 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
|
3930 |
E1000_WRITE_FLUSH(hw); |
680 | 3931 |
#ifdef CONFIG_E1000_NAPI |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3932 |
/* 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
|
3933 |
* 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
|
3934 |
* should account for it ASAP. */ |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3935 |
atomic_inc(&adapter->irq_sem); |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3936 |
#endif |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3937 |
} |
680 | 3938 |
|
3939 |
#ifdef CONFIG_E1000_NAPI |
|
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3940 |
if (likely(netif_rx_schedule_prep(netdev))) { |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3941 |
adapter->total_tx_bytes = 0; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3942 |
adapter->total_tx_packets = 0; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3943 |
adapter->total_rx_bytes = 0; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3944 |
adapter->total_rx_packets = 0; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3945 |
__netif_rx_schedule(netdev); |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3946 |
} else |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3947 |
e1000_irq_enable(adapter); |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3948 |
#else |
680 | 3949 |
adapter->total_tx_bytes = 0; |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3950 |
adapter->total_rx_bytes = 0; |
680 | 3951 |
adapter->total_tx_packets = 0; |
3952 |
adapter->total_rx_packets = 0; |
|
694
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 |
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
|
3955 |
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
|
3956 |
!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
|
3957 |
break; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3958 |
|
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3959 |
if (likely(adapter->itr_setting & 3)) |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3960 |
e1000_set_itr(adapter); |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3961 |
#endif |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
3962 |
} |
680 | 3963 |
|
3964 |
return IRQ_HANDLED; |
|
3965 |
} |
|
3966 |
#endif |
|
3967 |
||
3968 |
/** |
|
3969 |
* e1000_intr - Interrupt Handler |
|
3970 |
* @irq: interrupt number |
|
3971 |
* @data: pointer to a network interface device structure |
|
3972 |
**/ |
|
3973 |
||
3974 |
static irqreturn_t |
|
3975 |
e1000_intr(int irq, void *data) |
|
3976 |
{ |
|
3977 |
struct net_device *netdev = data; |
|
3978 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
3979 |
struct e1000_hw *hw = &adapter->hw; |
|
3980 |
uint32_t rctl, icr = E1000_READ_REG(hw, ICR); |
|
3981 |
int i; |
|
3982 |
if (unlikely(!icr)) |
|
3983 |
return IRQ_NONE; /* Not our interrupt */ |
|
3984 |
||
3985 |
#ifdef CONFIG_E1000_NAPI |
|
3986 |
/* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
|
3987 |
* not set, then the adapter didn't send an interrupt */ |
|
3988 |
if (unlikely(hw->mac_type >= e1000_82571 && |
|
3989 |
!(icr & E1000_ICR_INT_ASSERTED))) |
|
3990 |
return IRQ_NONE; |
|
3991 |
||
3992 |
/* Interrupt Auto-Mask...upon reading ICR, |
|
3993 |
* interrupts are masked. No need for the |
|
3994 |
* IMC write, but it does mean we should |
|
3995 |
* account for it ASAP. */ |
|
3996 |
if (!adapter->ecdev && likely(hw->mac_type >= e1000_82571)) |
|
3997 |
atomic_inc(&adapter->irq_sem); |
|
3998 |
#endif |
|
3999 |
||
4000 |
if (!adapter->ecdev && unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
|
4001 |
hw->get_link_status = 1; |
|
4002 |
/* 80003ES2LAN workaround-- |
|
4003 |
* For packet buffer work-around on link down event; |
|
4004 |
* disable receives here in the ISR and |
|
4005 |
* reset adapter in watchdog |
|
4006 |
*/ |
|
4007 |
if (netif_carrier_ok(netdev) && |
|
4008 |
(adapter->hw.mac_type == e1000_80003es2lan)) { |
|
4009 |
/* disable receives */ |
|
4010 |
rctl = E1000_READ_REG(hw, RCTL); |
|
4011 |
E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
|
4012 |
} |
|
4013 |
/* guard against interrupt when we're going down */ |
|
4014 |
if (!test_bit(__E1000_DOWN, &adapter->flags)) |
|
4015 |
mod_timer(&adapter->watchdog_timer, jiffies + 1); |
|
4016 |
} |
|
4017 |
||
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4018 |
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
|
4019 |
#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
|
4020 |
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
|
4021 |
#endif |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4022 |
for (i = 0; i < E1000_MAX_INTR; i++) |
680 | 4023 |
#ifdef CONFIG_E1000_NAPI |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4024 |
if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring, |
2050
a3e59f2a8589
Changed accidentally used & operator to &&.
Florian Pose <fp@igh-essen.com>
parents:
1325
diff
changeset
|
4025 |
&ec_work_done, 100) && |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4026 |
!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
|
4027 |
#else |
2050
a3e59f2a8589
Changed accidentally used & operator to &&.
Florian Pose <fp@igh-essen.com>
parents:
1325
diff
changeset
|
4028 |
if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) && |
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4029 |
!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
|
4030 |
#endif |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4031 |
break; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4032 |
} else { |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4033 |
#ifdef CONFIG_E1000_NAPI |
680 | 4034 |
if (unlikely(hw->mac_type < e1000_82571)) { |
4035 |
/* disable interrupts, without the synchronize_irq bit */ |
|
4036 |
atomic_inc(&adapter->irq_sem); |
|
4037 |
E1000_WRITE_REG(hw, IMC, ~0); |
|
4038 |
E1000_WRITE_FLUSH(hw); |
|
4039 |
} |
|
4040 |
if (likely(netif_rx_schedule_prep(netdev))) { |
|
4041 |
adapter->total_tx_bytes = 0; |
|
4042 |
adapter->total_tx_packets = 0; |
|
4043 |
adapter->total_rx_bytes = 0; |
|
4044 |
adapter->total_rx_packets = 0; |
|
4045 |
__netif_rx_schedule(netdev); |
|
4046 |
} else |
|
4047 |
/* this really should not happen! if it does it is basically a |
|
4048 |
* bug, but not a hard error, so enable ints and continue */ |
|
4049 |
e1000_irq_enable(adapter); |
|
4050 |
#else |
|
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4051 |
/* 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
|
4052 |
* 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
|
4053 |
* 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
|
4054 |
* 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
|
4055 |
* 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
|
4056 |
* 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
|
4057 |
* 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
|
4058 |
* 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
|
4059 |
* de-assertion state. |
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 |
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
|
4062 |
atomic_inc(&adapter->irq_sem); |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4063 |
E1000_WRITE_REG(hw, IMC, ~0); |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4064 |
} |
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 |
adapter->total_tx_bytes = 0; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4067 |
adapter->total_rx_bytes = 0; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4068 |
adapter->total_tx_packets = 0; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4069 |
adapter->total_rx_packets = 0; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4070 |
|
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4071 |
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
|
4072 |
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
|
4073 |
!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
|
4074 |
break; |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4075 |
|
680 | 4076 |
if (likely(adapter->itr_setting & 3)) |
4077 |
e1000_set_itr(adapter); |
|
4078 |
||
4079 |
if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) |
|
4080 |
e1000_irq_enable(adapter); |
|
694
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4081 |
|
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4082 |
#endif |
54a169382e28
e1000 also supporting PCI MSI interrupts.
Florian Pose <fp@igh-essen.com>
parents:
680
diff
changeset
|
4083 |
} |
680 | 4084 |
return IRQ_HANDLED; |
4085 |
} |
|
4086 |
||
4087 |
#ifdef CONFIG_E1000_NAPI |
|
4088 |
/** |
|
4089 |
* e1000_clean - NAPI Rx polling callback |
|
4090 |
* @adapter: board private structure |
|
4091 |
**/ |
|
4092 |
||
4093 |
static int |
|
4094 |
e1000_clean(struct net_device *poll_dev, int *budget) // EtherCAT: never called |
|
4095 |
{ |
|
4096 |
struct e1000_adapter *adapter; |
|
4097 |
int work_to_do = min(*budget, poll_dev->quota); |
|
4098 |
int tx_cleaned = 0, work_done = 0; |
|
4099 |
||
4100 |
/* Must NOT use netdev_priv macro here. */ |
|
4101 |
adapter = poll_dev->priv; |
|
4102 |
||
4103 |
/* Keep link state information with original netdev */ |
|
4104 |
if (!netif_carrier_ok(poll_dev)) |
|
4105 |
goto quit_polling; |
|
4106 |
||
4107 |
/* e1000_clean is called per-cpu. This lock protects |
|
4108 |
* tx_ring[0] from being cleaned by multiple cpus |
|
4109 |
* simultaneously. A failure obtaining the lock means |
|
4110 |
* tx_ring[0] is currently being cleaned anyway. */ |
|
4111 |
if (spin_trylock(&adapter->tx_queue_lock)) { |
|
4112 |
tx_cleaned = e1000_clean_tx_irq(adapter, |
|
4113 |
&adapter->tx_ring[0]); |
|
4114 |
spin_unlock(&adapter->tx_queue_lock); |
|
4115 |
} |
|
4116 |
||
4117 |
adapter->clean_rx(adapter, &adapter->rx_ring[0], |
|
4118 |
&work_done, work_to_do); |
|
4119 |
||
4120 |
*budget -= work_done; |
|
4121 |
poll_dev->quota -= work_done; |
|
4122 |
||
4123 |
/* If no Tx and not enough Rx work done, exit the polling mode */ |
|
4124 |
if ((!tx_cleaned && (work_done == 0)) || |
|
4125 |
!netif_running(poll_dev)) { |
|
4126 |
quit_polling: |
|
4127 |
if (likely(adapter->itr_setting & 3)) |
|
4128 |
e1000_set_itr(adapter); |
|
4129 |
netif_rx_complete(poll_dev); |
|
4130 |
e1000_irq_enable(adapter); |
|
4131 |
return 0; |
|
4132 |
} |
|
4133 |
||
4134 |
return 1; |
|
4135 |
} |
|
4136 |
||
4137 |
#endif |
|
4138 |
/** |
|
4139 |
* e1000_clean_tx_irq - Reclaim resources after transmit completes |
|
4140 |
* @adapter: board private structure |
|
4141 |
**/ |
|
4142 |
||
4143 |
static boolean_t |
|
4144 |
e1000_clean_tx_irq(struct e1000_adapter *adapter, |
|
4145 |
struct e1000_tx_ring *tx_ring) |
|
4146 |
{ |
|
4147 |
struct net_device *netdev = adapter->netdev; |
|
4148 |
struct e1000_tx_desc *tx_desc, *eop_desc; |
|
4149 |
struct e1000_buffer *buffer_info; |
|
4150 |
unsigned int i, eop; |
|
4151 |
#ifdef CONFIG_E1000_NAPI |
|
4152 |
unsigned int count = 0; |
|
4153 |
#endif |
|
4154 |
boolean_t cleaned = FALSE; |
|
4155 |
unsigned int total_tx_bytes=0, total_tx_packets=0; |
|
4156 |
||
4157 |
i = tx_ring->next_to_clean; |
|
4158 |
eop = tx_ring->buffer_info[i].next_to_watch; |
|
4159 |
eop_desc = E1000_TX_DESC(*tx_ring, eop); |
|
4160 |
||
4161 |
while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { |
|
4162 |
for (cleaned = FALSE; !cleaned; ) { |
|
4163 |
tx_desc = E1000_TX_DESC(*tx_ring, i); |
|
4164 |
buffer_info = &tx_ring->buffer_info[i]; |
|
4165 |
cleaned = (i == eop); |
|
4166 |
||
4167 |
if (cleaned) { |
|
4168 |
struct sk_buff *skb = buffer_info->skb; |
|
4169 |
unsigned int segs = skb_shinfo(skb)->gso_segs; |
|
4170 |
total_tx_packets += segs; |
|
4171 |
total_tx_packets++; |
|
4172 |
total_tx_bytes += skb->len; |
|
4173 |
} |
|
4174 |
e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
|
4175 |
tx_desc->upper.data = 0; |
|
4176 |
||
4177 |
if (unlikely(++i == tx_ring->count)) i = 0; |
|
4178 |
} |
|
4179 |
||
4180 |
eop = tx_ring->buffer_info[i].next_to_watch; |
|
4181 |
eop_desc = E1000_TX_DESC(*tx_ring, eop); |
|
4182 |
#ifdef CONFIG_E1000_NAPI |
|
4183 |
#define E1000_TX_WEIGHT 64 |
|
4184 |
/* weight of a sort for tx, to avoid endless transmit cleanup */ |
|
4185 |
if (count++ == E1000_TX_WEIGHT) break; |
|
4186 |
#endif |
|
4187 |
} |
|
4188 |
||
4189 |
tx_ring->next_to_clean = i; |
|
4190 |
||
4191 |
#define TX_WAKE_THRESHOLD 32 |
|
4192 |
if (!adapter->ecdev && unlikely(cleaned && netif_carrier_ok(netdev) && |
|
4193 |
E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { |
|
4194 |
/* Make sure that anybody stopping the queue after this |
|
4195 |
* sees the new next_to_clean. |
|
4196 |
*/ |
|
4197 |
smp_mb(); |
|
4198 |
if (netif_queue_stopped(netdev)) { |
|
4199 |
netif_wake_queue(netdev); |
|
4200 |
++adapter->restart_queue; |
|
4201 |
} |
|
4202 |
} |
|
4203 |
||
4204 |
if (!adapter->ecdev && adapter->detect_tx_hung) { |
|
4205 |
/* Detect a transmit hang in hardware, this serializes the |
|
4206 |
* check with the clearing of time_stamp and movement of i */ |
|
4207 |
adapter->detect_tx_hung = FALSE; |
|
4208 |
if (tx_ring->buffer_info[eop].dma && |
|
4209 |
time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + |
|
4210 |
(adapter->tx_timeout_factor * HZ)) |
|
4211 |
&& !(E1000_READ_REG(&adapter->hw, STATUS) & |
|
4212 |
E1000_STATUS_TXOFF)) { |
|
4213 |
||
4214 |
/* detected Tx unit hang */ |
|
4215 |
DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
|
4216 |
" Tx Queue <%lu>\n" |
|
4217 |
" TDH <%x>\n" |
|
4218 |
" TDT <%x>\n" |
|
4219 |
" next_to_use <%x>\n" |
|
4220 |
" next_to_clean <%x>\n" |
|
4221 |
"buffer_info[next_to_clean]\n" |
|
4222 |
" time_stamp <%lx>\n" |
|
4223 |
" next_to_watch <%x>\n" |
|
4224 |
" jiffies <%lx>\n" |
|
4225 |
" next_to_watch.status <%x>\n", |
|
4226 |
(unsigned long)((tx_ring - adapter->tx_ring) / |
|
4227 |
sizeof(struct e1000_tx_ring)), |
|
4228 |
readl(adapter->hw.hw_addr + tx_ring->tdh), |
|
4229 |
readl(adapter->hw.hw_addr + tx_ring->tdt), |
|
4230 |
tx_ring->next_to_use, |
|
4231 |
tx_ring->next_to_clean, |
|
4232 |
tx_ring->buffer_info[eop].time_stamp, |
|
4233 |
eop, |
|
4234 |
jiffies, |
|
4235 |
eop_desc->upper.fields.status); |
|
4236 |
netif_stop_queue(netdev); |
|
4237 |
} |
|
4238 |
} |
|
4239 |
adapter->total_tx_bytes += total_tx_bytes; |
|
4240 |
adapter->total_tx_packets += total_tx_packets; |
|
4241 |
return cleaned; |
|
4242 |
} |
|
4243 |
||
4244 |
/** |
|
4245 |
* e1000_rx_checksum - Receive Checksum Offload for 82543 |
|
4246 |
* @adapter: board private structure |
|
4247 |
* @status_err: receive descriptor status and error fields |
|
4248 |
* @csum: receive descriptor csum field |
|
4249 |
* @sk_buff: socket buffer with received data |
|
4250 |
**/ |
|
4251 |
||
4252 |
static void |
|
4253 |
e1000_rx_checksum(struct e1000_adapter *adapter, |
|
4254 |
uint32_t status_err, uint32_t csum, |
|
4255 |
struct sk_buff *skb) |
|
4256 |
{ |
|
4257 |
uint16_t status = (uint16_t)status_err; |
|
4258 |
uint8_t errors = (uint8_t)(status_err >> 24); |
|
4259 |
skb->ip_summed = CHECKSUM_NONE; |
|
4260 |
||
4261 |
/* 82543 or newer only */ |
|
4262 |
if (unlikely(adapter->hw.mac_type < e1000_82543)) return; |
|
4263 |
/* Ignore Checksum bit is set */ |
|
4264 |
if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
|
4265 |
/* TCP/UDP checksum error bit is set */ |
|
4266 |
if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
|
4267 |
/* let the stack verify checksum errors */ |
|
4268 |
adapter->hw_csum_err++; |
|
4269 |
return; |
|
4270 |
} |
|
4271 |
/* TCP/UDP Checksum has not been calculated */ |
|
4272 |
if (adapter->hw.mac_type <= e1000_82547_rev_2) { |
|
4273 |
if (!(status & E1000_RXD_STAT_TCPCS)) |
|
4274 |
return; |
|
4275 |
} else { |
|
4276 |
if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
|
4277 |
return; |
|
4278 |
} |
|
4279 |
/* It must be a TCP or UDP packet with a valid checksum */ |
|
4280 |
if (likely(status & E1000_RXD_STAT_TCPCS)) { |
|
4281 |
/* TCP checksum is good */ |
|
4282 |
skb->ip_summed = CHECKSUM_UNNECESSARY; |
|
4283 |
} else if (adapter->hw.mac_type > e1000_82547_rev_2) { |
|
4284 |
/* IP fragment with UDP payload */ |
|
4285 |
/* Hardware complements the payload checksum, so we undo it |
|
4286 |
* and then put the value in host order for further stack use. |
|
4287 |
*/ |
|
4288 |
csum = ntohl(csum ^ 0xFFFF); |
|
4289 |
skb->csum = csum; |
|
4290 |
skb->ip_summed = CHECKSUM_COMPLETE; |
|
4291 |
} |
|
4292 |
adapter->hw_csum_good++; |
|
4293 |
} |
|
4294 |
||
4295 |
/** |
|
4296 |
* e1000_clean_rx_irq - Send received data up the network stack; legacy |
|
4297 |
* @adapter: board private structure |
|
4298 |
**/ |
|
4299 |
||
4300 |
static boolean_t |
|
4301 |
#ifdef CONFIG_E1000_NAPI |
|
4302 |
e1000_clean_rx_irq(struct e1000_adapter *adapter, |
|
4303 |
struct e1000_rx_ring *rx_ring, |
|
4304 |
int *work_done, int work_to_do) |
|
4305 |
#else |
|
4306 |
e1000_clean_rx_irq(struct e1000_adapter *adapter, |
|
4307 |
struct e1000_rx_ring *rx_ring) |
|
4308 |
#endif |
|
4309 |
{ |
|
4310 |
struct net_device *netdev = adapter->netdev; |
|
4311 |
struct pci_dev *pdev = adapter->pdev; |
|
4312 |
struct e1000_rx_desc *rx_desc, *next_rxd; |
|
4313 |
struct e1000_buffer *buffer_info, *next_buffer; |
|
4314 |
unsigned long flags; |
|
4315 |
uint32_t length; |
|
4316 |
uint8_t last_byte; |
|
4317 |
unsigned int i; |
|
4318 |
int cleaned_count = 0; |
|
4319 |
boolean_t cleaned = FALSE; |
|
4320 |
unsigned int total_rx_bytes=0, total_rx_packets=0; |
|
4321 |
||
4322 |
i = rx_ring->next_to_clean; |
|
4323 |
rx_desc = E1000_RX_DESC(*rx_ring, i); |
|
4324 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4325 |
||
4326 |
while (rx_desc->status & E1000_RXD_STAT_DD) { |
|
4327 |
struct sk_buff *skb; |
|
4328 |
u8 status; |
|
4329 |
||
4330 |
#ifdef CONFIG_E1000_NAPI |
|
4331 |
if (*work_done >= work_to_do) |
|
4332 |
break; |
|
4333 |
(*work_done)++; |
|
4334 |
#endif |
|
4335 |
status = rx_desc->status; |
|
4336 |
skb = buffer_info->skb; |
|
4337 |
if (!adapter->ecdev) buffer_info->skb = NULL; |
|
4338 |
||
4339 |
prefetch(skb->data - NET_IP_ALIGN); |
|
4340 |
||
4341 |
if (++i == rx_ring->count) i = 0; |
|
4342 |
next_rxd = E1000_RX_DESC(*rx_ring, i); |
|
4343 |
prefetch(next_rxd); |
|
4344 |
||
4345 |
next_buffer = &rx_ring->buffer_info[i]; |
|
4346 |
||
4347 |
cleaned = TRUE; |
|
4348 |
cleaned_count++; |
|
4349 |
pci_unmap_single(pdev, |
|
4350 |
buffer_info->dma, |
|
4351 |
buffer_info->length, |
|
4352 |
PCI_DMA_FROMDEVICE); |
|
4353 |
||
4354 |
length = le16_to_cpu(rx_desc->length); |
|
4355 |
||
4356 |
if (unlikely(!(status & E1000_RXD_STAT_EOP))) { |
|
4357 |
/* All receives must fit into a single buffer */ |
|
4358 |
E1000_DBG("%s: Receive packet consumed multiple" |
|
4359 |
" buffers\n", netdev->name); |
|
4360 |
/* recycle */ |
|
4361 |
buffer_info->skb = skb; |
|
4362 |
goto next_desc; |
|
4363 |
} |
|
4364 |
||
4365 |
if (!adapter->ecdev && |
|
4366 |
unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
|
4367 |
last_byte = *(skb->data + length - 1); |
|
4368 |
if (TBI_ACCEPT(&adapter->hw, status, |
|
4369 |
rx_desc->errors, length, last_byte)) { |
|
4370 |
spin_lock_irqsave(&adapter->stats_lock, flags); |
|
4371 |
e1000_tbi_adjust_stats(&adapter->hw, |
|
4372 |
&adapter->stats, |
|
4373 |
length, skb->data); |
|
4374 |
spin_unlock_irqrestore(&adapter->stats_lock, |
|
4375 |
flags); |
|
4376 |
length--; |
|
4377 |
} else { |
|
4378 |
/* recycle */ |
|
4379 |
buffer_info->skb = skb; |
|
4380 |
goto next_desc; |
|
4381 |
} |
|
4382 |
} |
|
4383 |
||
4384 |
/* adjust length to remove Ethernet CRC, this must be |
|
4385 |
* done after the TBI_ACCEPT workaround above */ |
|
4386 |
length -= 4; |
|
4387 |
||
4388 |
/* probably a little skewed due to removing CRC */ |
|
4389 |
total_rx_bytes += length; |
|
4390 |
total_rx_packets++; |
|
4391 |
||
4392 |
/* code added for copybreak, this should improve |
|
4393 |
* performance for small packets with large amounts |
|
4394 |
* of reassembly being done in the stack */ |
|
4395 |
if (!adapter->ecdev && length < copybreak) { |
|
4396 |
struct sk_buff *new_skb = |
|
4397 |
netdev_alloc_skb(netdev, length + NET_IP_ALIGN); |
|
4398 |
if (new_skb) { |
|
4399 |
skb_reserve(new_skb, NET_IP_ALIGN); |
|
4400 |
memcpy(new_skb->data - NET_IP_ALIGN, |
|
4401 |
skb->data - NET_IP_ALIGN, |
|
4402 |
length + NET_IP_ALIGN); |
|
4403 |
/* save the skb in buffer_info as good */ |
|
4404 |
buffer_info->skb = skb; |
|
4405 |
skb = new_skb; |
|
4406 |
} |
|
4407 |
/* else just continue with the old one */ |
|
4408 |
} |
|
4409 |
/* end copybreak code */ |
|
4410 |
skb_put(skb, length); |
|
4411 |
||
4412 |
/* Receive Checksum Offload */ |
|
4413 |
e1000_rx_checksum(adapter, |
|
4414 |
(uint32_t)(status) | |
|
4415 |
((uint32_t)(rx_desc->errors) << 24), |
|
4416 |
le16_to_cpu(rx_desc->csum), skb); |
|
4417 |
||
4418 |
if (adapter->ecdev) { |
|
4419 |
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
|
4420 |
|
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
|
4421 |
// 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
|
4422 |
// 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
|
4423 |
adapter->ec_watchdog_jiffies = jiffies; |
680 | 4424 |
} else { |
4425 |
skb->protocol = eth_type_trans(skb, netdev); |
|
4426 |
#ifdef CONFIG_E1000_NAPI |
|
4427 |
if (unlikely(adapter->vlgrp && |
|
4428 |
(status & E1000_RXD_STAT_VP))) { |
|
4429 |
vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
|
4430 |
le16_to_cpu(rx_desc->special) & |
|
4431 |
E1000_RXD_SPC_VLAN_MASK); |
|
4432 |
} else { |
|
4433 |
netif_receive_skb(skb); |
|
4434 |
} |
|
4435 |
#else /* CONFIG_E1000_NAPI */ |
|
4436 |
if (unlikely(adapter->vlgrp && |
|
4437 |
(status & E1000_RXD_STAT_VP))) { |
|
4438 |
vlan_hwaccel_rx(skb, adapter->vlgrp, |
|
4439 |
le16_to_cpu(rx_desc->special) & |
|
4440 |
E1000_RXD_SPC_VLAN_MASK); |
|
4441 |
} else { |
|
4442 |
netif_rx(skb); |
|
4443 |
} |
|
4444 |
#endif /* CONFIG_E1000_NAPI */ |
|
4445 |
} |
|
4446 |
netdev->last_rx = jiffies; |
|
4447 |
||
4448 |
next_desc: |
|
4449 |
rx_desc->status = 0; |
|
4450 |
||
4451 |
/* return some buffers to hardware, one at a time is too slow */ |
|
4452 |
if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
|
4453 |
adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
|
4454 |
cleaned_count = 0; |
|
4455 |
} |
|
4456 |
||
4457 |
/* use prefetched values */ |
|
4458 |
rx_desc = next_rxd; |
|
4459 |
buffer_info = next_buffer; |
|
4460 |
} |
|
4461 |
rx_ring->next_to_clean = i; |
|
4462 |
||
4463 |
cleaned_count = E1000_DESC_UNUSED(rx_ring); |
|
4464 |
if (cleaned_count) |
|
4465 |
adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
|
4466 |
||
4467 |
adapter->total_rx_packets += total_rx_packets; |
|
4468 |
adapter->total_rx_bytes += total_rx_bytes; |
|
4469 |
return cleaned; |
|
4470 |
} |
|
4471 |
||
4472 |
/** |
|
4473 |
* e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
|
4474 |
* @adapter: board private structure |
|
4475 |
**/ |
|
4476 |
||
4477 |
static boolean_t |
|
4478 |
#ifdef CONFIG_E1000_NAPI |
|
4479 |
e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
|
4480 |
struct e1000_rx_ring *rx_ring, |
|
4481 |
int *work_done, int work_to_do) |
|
4482 |
#else |
|
4483 |
e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
|
4484 |
struct e1000_rx_ring *rx_ring) |
|
4485 |
#endif |
|
4486 |
{ |
|
4487 |
union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
|
4488 |
struct net_device *netdev = adapter->netdev; |
|
4489 |
struct pci_dev *pdev = adapter->pdev; |
|
4490 |
struct e1000_buffer *buffer_info, *next_buffer; |
|
4491 |
struct e1000_ps_page *ps_page; |
|
4492 |
struct e1000_ps_page_dma *ps_page_dma; |
|
4493 |
struct sk_buff *skb; |
|
4494 |
unsigned int i, j; |
|
4495 |
uint32_t length, staterr; |
|
4496 |
int cleaned_count = 0; |
|
4497 |
boolean_t cleaned = FALSE; |
|
4498 |
unsigned int total_rx_bytes=0, total_rx_packets=0; |
|
4499 |
||
4500 |
i = rx_ring->next_to_clean; |
|
4501 |
rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
|
4502 |
staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
|
4503 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4504 |
||
4505 |
while (staterr & E1000_RXD_STAT_DD) { |
|
4506 |
ps_page = &rx_ring->ps_page[i]; |
|
4507 |
ps_page_dma = &rx_ring->ps_page_dma[i]; |
|
4508 |
#ifdef CONFIG_E1000_NAPI |
|
4509 |
if (unlikely(*work_done >= work_to_do)) |
|
4510 |
break; |
|
4511 |
(*work_done)++; |
|
4512 |
#endif |
|
4513 |
skb = buffer_info->skb; |
|
4514 |
||
4515 |
/* in the packet split case this is header only */ |
|
4516 |
prefetch(skb->data - NET_IP_ALIGN); |
|
4517 |
||
4518 |
if (++i == rx_ring->count) i = 0; |
|
4519 |
next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
|
4520 |
prefetch(next_rxd); |
|
4521 |
||
4522 |
next_buffer = &rx_ring->buffer_info[i]; |
|
4523 |
||
4524 |
cleaned = TRUE; |
|
4525 |
cleaned_count++; |
|
4526 |
pci_unmap_single(pdev, buffer_info->dma, |
|
4527 |
buffer_info->length, |
|
4528 |
PCI_DMA_FROMDEVICE); |
|
4529 |
||
4530 |
if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) { |
|
4531 |
E1000_DBG("%s: Packet Split buffers didn't pick up" |
|
4532 |
" the full packet\n", netdev->name); |
|
4533 |
if (!adapter->ecdev) dev_kfree_skb_irq(skb); |
|
4534 |
goto next_desc; |
|
4535 |
} |
|
4536 |
||
4537 |
if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) { |
|
4538 |
if (!adapter->ecdev) dev_kfree_skb_irq(skb); |
|
4539 |
goto next_desc; |
|
4540 |
} |
|
4541 |
||
4542 |
length = le16_to_cpu(rx_desc->wb.middle.length0); |
|
4543 |
||
4544 |
if (unlikely(!length)) { |
|
4545 |
E1000_DBG("%s: Last part of the packet spanning" |
|
4546 |
" multiple descriptors\n", netdev->name); |
|
4547 |
if (!adapter->ecdev) dev_kfree_skb_irq(skb); |
|
4548 |
goto next_desc; |
|
4549 |
} |
|
4550 |
||
4551 |
/* Good Receive */ |
|
4552 |
skb_put(skb, length); |
|
4553 |
||
4554 |
{ |
|
4555 |
/* this looks ugly, but it seems compiler issues make it |
|
4556 |
more efficient than reusing j */ |
|
4557 |
int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
|
4558 |
||
4559 |
/* page alloc/put takes too long and effects small packet |
|
4560 |
* throughput, so unsplit small packets and save the alloc/put*/ |
|
4561 |
if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) { |
|
4562 |
u8 *vaddr; |
|
4563 |
/* there is no documentation about how to call |
|
4564 |
* kmap_atomic, so we can't hold the mapping |
|
4565 |
* very long */ |
|
4566 |
pci_dma_sync_single_for_cpu(pdev, |
|
4567 |
ps_page_dma->ps_page_dma[0], |
|
4568 |
PAGE_SIZE, |
|
4569 |
PCI_DMA_FROMDEVICE); |
|
4570 |
vaddr = kmap_atomic(ps_page->ps_page[0], |
|
4571 |
KM_SKB_DATA_SOFTIRQ); |
|
4572 |
memcpy(skb->tail, vaddr, l1); |
|
4573 |
kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
|
4574 |
pci_dma_sync_single_for_device(pdev, |
|
4575 |
ps_page_dma->ps_page_dma[0], |
|
4576 |
PAGE_SIZE, PCI_DMA_FROMDEVICE); |
|
4577 |
/* remove the CRC */ |
|
4578 |
l1 -= 4; |
|
4579 |
skb_put(skb, l1); |
|
4580 |
goto copydone; |
|
4581 |
} /* if */ |
|
4582 |
} |
|
4583 |
||
4584 |
for (j = 0; j < adapter->rx_ps_pages; j++) { |
|
4585 |
if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j]))) |
|
4586 |
break; |
|
4587 |
pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j], |
|
4588 |
PAGE_SIZE, PCI_DMA_FROMDEVICE); |
|
4589 |
ps_page_dma->ps_page_dma[j] = 0; |
|
4590 |
skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0, |
|
4591 |
length); |
|
4592 |
ps_page->ps_page[j] = NULL; |
|
4593 |
skb->len += length; |
|
4594 |
skb->data_len += length; |
|
4595 |
skb->truesize += length; |
|
4596 |
} |
|
4597 |
||
4598 |
/* strip the ethernet crc, problem is we're using pages now so |
|
4599 |
* this whole operation can get a little cpu intensive */ |
|
4600 |
pskb_trim(skb, skb->len - 4); |
|
4601 |
||
4602 |
copydone: |
|
4603 |
total_rx_bytes += skb->len; |
|
4604 |
total_rx_packets++; |
|
4605 |
||
4606 |
e1000_rx_checksum(adapter, staterr, |
|
4607 |
le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); |
|
4608 |
||
4609 |
if (likely(rx_desc->wb.upper.header_status & |
|
4610 |
cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))) |
|
4611 |
adapter->rx_hdr_split++; |
|
4612 |
if (adapter->ecdev) { |
|
4613 |
ecdev_receive(adapter->ecdev, skb->data, length); |
|
4614 |
} else { |
|
4615 |
skb->protocol = eth_type_trans(skb, netdev); |
|
4616 |
#ifdef CONFIG_E1000_NAPI |
|
4617 |
if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
|
4618 |
vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
|
4619 |
le16_to_cpu(rx_desc->wb.middle.vlan) & |
|
4620 |
E1000_RXD_SPC_VLAN_MASK); |
|
4621 |
} else { |
|
4622 |
netif_receive_skb(skb); |
|
4623 |
} |
|
4624 |
#else /* CONFIG_E1000_NAPI */ |
|
4625 |
if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
|
4626 |
vlan_hwaccel_rx(skb, adapter->vlgrp, |
|
4627 |
le16_to_cpu(rx_desc->wb.middle.vlan) & |
|
4628 |
E1000_RXD_SPC_VLAN_MASK); |
|
4629 |
} else { |
|
4630 |
netif_rx(skb); |
|
4631 |
} |
|
4632 |
#endif /* CONFIG_E1000_NAPI */ |
|
4633 |
} |
|
4634 |
netdev->last_rx = jiffies; |
|
4635 |
||
4636 |
next_desc: |
|
4637 |
rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
|
4638 |
if (!adapter->ecdev) buffer_info->skb = NULL; |
|
4639 |
||
4640 |
/* return some buffers to hardware, one at a time is too slow */ |
|
4641 |
if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
|
4642 |
adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
|
4643 |
cleaned_count = 0; |
|
4644 |
} |
|
4645 |
||
4646 |
/* use prefetched values */ |
|
4647 |
rx_desc = next_rxd; |
|
4648 |
buffer_info = next_buffer; |
|
4649 |
||
4650 |
staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
|
4651 |
} |
|
4652 |
rx_ring->next_to_clean = i; |
|
4653 |
||
4654 |
cleaned_count = E1000_DESC_UNUSED(rx_ring); |
|
4655 |
if (cleaned_count) |
|
4656 |
adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
|
4657 |
||
4658 |
adapter->total_rx_packets += total_rx_packets; |
|
4659 |
adapter->total_rx_bytes += total_rx_bytes; |
|
4660 |
return cleaned; |
|
4661 |
} |
|
4662 |
||
4663 |
/** |
|
4664 |
* e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
|
4665 |
* @adapter: address of board private structure |
|
4666 |
**/ |
|
4667 |
||
4668 |
static void |
|
4669 |
e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
|
4670 |
struct e1000_rx_ring *rx_ring, |
|
4671 |
int cleaned_count) |
|
4672 |
{ |
|
4673 |
struct net_device *netdev = adapter->netdev; |
|
4674 |
struct pci_dev *pdev = adapter->pdev; |
|
4675 |
struct e1000_rx_desc *rx_desc; |
|
4676 |
struct e1000_buffer *buffer_info; |
|
4677 |
struct sk_buff *skb; |
|
4678 |
unsigned int i; |
|
4679 |
unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
|
4680 |
||
4681 |
i = rx_ring->next_to_use; |
|
4682 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4683 |
||
4684 |
while (cleaned_count--) { |
|
4685 |
skb = buffer_info->skb; |
|
4686 |
if (skb) { |
|
4687 |
skb_trim(skb, 0); |
|
4688 |
goto map_skb; |
|
4689 |
} |
|
4690 |
||
4691 |
skb = netdev_alloc_skb(netdev, bufsz); |
|
4692 |
if (unlikely(!skb)) { |
|
4693 |
/* Better luck next round */ |
|
4694 |
adapter->alloc_rx_buff_failed++; |
|
4695 |
break; |
|
4696 |
} |
|
4697 |
||
4698 |
/* Fix for errata 23, can't cross 64kB boundary */ |
|
4699 |
if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
|
4700 |
struct sk_buff *oldskb = skb; |
|
4701 |
DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
|
4702 |
"at %p\n", bufsz, skb->data); |
|
4703 |
/* Try again, without freeing the previous */ |
|
4704 |
skb = netdev_alloc_skb(netdev, bufsz); |
|
4705 |
/* Failed allocation, critical failure */ |
|
4706 |
if (!skb) { |
|
4707 |
dev_kfree_skb(oldskb); |
|
4708 |
break; |
|
4709 |
} |
|
4710 |
||
4711 |
if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
|
4712 |
/* give up */ |
|
4713 |
dev_kfree_skb(skb); |
|
4714 |
dev_kfree_skb(oldskb); |
|
4715 |
break; /* while !buffer_info->skb */ |
|
4716 |
} |
|
4717 |
||
4718 |
/* Use new allocation */ |
|
4719 |
dev_kfree_skb(oldskb); |
|
4720 |
} |
|
4721 |
/* Make buffer alignment 2 beyond a 16 byte boundary |
|
4722 |
* this will result in a 16 byte aligned IP header after |
|
4723 |
* the 14 byte MAC header is removed |
|
4724 |
*/ |
|
4725 |
skb_reserve(skb, NET_IP_ALIGN); |
|
4726 |
||
4727 |
buffer_info->skb = skb; |
|
4728 |
buffer_info->length = adapter->rx_buffer_len; |
|
4729 |
map_skb: |
|
4730 |
buffer_info->dma = pci_map_single(pdev, |
|
4731 |
skb->data, |
|
4732 |
adapter->rx_buffer_len, |
|
4733 |
PCI_DMA_FROMDEVICE); |
|
4734 |
||
4735 |
/* Fix for errata 23, can't cross 64kB boundary */ |
|
4736 |
if (!e1000_check_64k_bound(adapter, |
|
4737 |
(void *)(unsigned long)buffer_info->dma, |
|
4738 |
adapter->rx_buffer_len)) { |
|
4739 |
DPRINTK(RX_ERR, ERR, |
|
4740 |
"dma align check failed: %u bytes at %p\n", |
|
4741 |
adapter->rx_buffer_len, |
|
4742 |
(void *)(unsigned long)buffer_info->dma); |
|
4743 |
if (!adapter->ecdev) { |
|
4744 |
dev_kfree_skb(skb); |
|
4745 |
buffer_info->skb = NULL; |
|
4746 |
} |
|
4747 |
||
4748 |
pci_unmap_single(pdev, buffer_info->dma, |
|
4749 |
adapter->rx_buffer_len, |
|
4750 |
PCI_DMA_FROMDEVICE); |
|
4751 |
||
4752 |
break; /* while !buffer_info->skb */ |
|
4753 |
} |
|
4754 |
rx_desc = E1000_RX_DESC(*rx_ring, i); |
|
4755 |
rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
|
4756 |
||
4757 |
if (unlikely(++i == rx_ring->count)) |
|
4758 |
i = 0; |
|
4759 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4760 |
} |
|
4761 |
||
4762 |
if (likely(rx_ring->next_to_use != i)) { |
|
4763 |
rx_ring->next_to_use = i; |
|
4764 |
if (unlikely(i-- == 0)) |
|
4765 |
i = (rx_ring->count - 1); |
|
4766 |
||
4767 |
/* Force memory writes to complete before letting h/w |
|
4768 |
* know there are new descriptors to fetch. (Only |
|
4769 |
* applicable for weak-ordered memory model archs, |
|
4770 |
* such as IA-64). */ |
|
4771 |
wmb(); |
|
4772 |
writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
|
4773 |
} |
|
4774 |
} |
|
4775 |
||
4776 |
/** |
|
4777 |
* e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
|
4778 |
* @adapter: address of board private structure |
|
4779 |
**/ |
|
4780 |
||
4781 |
static void |
|
4782 |
e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
|
4783 |
struct e1000_rx_ring *rx_ring, |
|
4784 |
int cleaned_count) |
|
4785 |
{ |
|
4786 |
struct net_device *netdev = adapter->netdev; |
|
4787 |
struct pci_dev *pdev = adapter->pdev; |
|
4788 |
union e1000_rx_desc_packet_split *rx_desc; |
|
4789 |
struct e1000_buffer *buffer_info; |
|
4790 |
struct e1000_ps_page *ps_page; |
|
4791 |
struct e1000_ps_page_dma *ps_page_dma; |
|
4792 |
struct sk_buff *skb; |
|
4793 |
unsigned int i, j; |
|
4794 |
||
4795 |
i = rx_ring->next_to_use; |
|
4796 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4797 |
ps_page = &rx_ring->ps_page[i]; |
|
4798 |
ps_page_dma = &rx_ring->ps_page_dma[i]; |
|
4799 |
||
4800 |
while (cleaned_count--) { |
|
4801 |
rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
|
4802 |
||
4803 |
for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
|
4804 |
if (j < adapter->rx_ps_pages) { |
|
4805 |
if (likely(!ps_page->ps_page[j])) { |
|
4806 |
ps_page->ps_page[j] = |
|
4807 |
alloc_page(GFP_ATOMIC); |
|
4808 |
if (unlikely(!ps_page->ps_page[j])) { |
|
4809 |
adapter->alloc_rx_buff_failed++; |
|
4810 |
goto no_buffers; |
|
4811 |
} |
|
4812 |
ps_page_dma->ps_page_dma[j] = |
|
4813 |
pci_map_page(pdev, |
|
4814 |
ps_page->ps_page[j], |
|
4815 |
0, PAGE_SIZE, |
|
4816 |
PCI_DMA_FROMDEVICE); |
|
4817 |
} |
|
4818 |
/* Refresh the desc even if buffer_addrs didn't |
|
4819 |
* change because each write-back erases |
|
4820 |
* this info. |
|
4821 |
*/ |
|
4822 |
rx_desc->read.buffer_addr[j+1] = |
|
4823 |
cpu_to_le64(ps_page_dma->ps_page_dma[j]); |
|
4824 |
} else |
|
4825 |
rx_desc->read.buffer_addr[j+1] = ~0; |
|
4826 |
} |
|
4827 |
||
4828 |
skb = netdev_alloc_skb(netdev, |
|
4829 |
adapter->rx_ps_bsize0 + NET_IP_ALIGN); |
|
4830 |
||
4831 |
if (unlikely(!skb)) { |
|
4832 |
adapter->alloc_rx_buff_failed++; |
|
4833 |
break; |
|
4834 |
} |
|
4835 |
||
4836 |
/* Make buffer alignment 2 beyond a 16 byte boundary |
|
4837 |
* this will result in a 16 byte aligned IP header after |
|
4838 |
* the 14 byte MAC header is removed |
|
4839 |
*/ |
|
4840 |
skb_reserve(skb, NET_IP_ALIGN); |
|
4841 |
||
4842 |
buffer_info->skb = skb; |
|
4843 |
buffer_info->length = adapter->rx_ps_bsize0; |
|
4844 |
buffer_info->dma = pci_map_single(pdev, skb->data, |
|
4845 |
adapter->rx_ps_bsize0, |
|
4846 |
PCI_DMA_FROMDEVICE); |
|
4847 |
||
4848 |
rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
|
4849 |
||
4850 |
if (unlikely(++i == rx_ring->count)) i = 0; |
|
4851 |
buffer_info = &rx_ring->buffer_info[i]; |
|
4852 |
ps_page = &rx_ring->ps_page[i]; |
|
4853 |
ps_page_dma = &rx_ring->ps_page_dma[i]; |
|
4854 |
} |
|
4855 |
||
4856 |
no_buffers: |
|
4857 |
if (likely(rx_ring->next_to_use != i)) { |
|
4858 |
rx_ring->next_to_use = i; |
|
4859 |
if (unlikely(i-- == 0)) i = (rx_ring->count - 1); |
|
4860 |
||
4861 |
/* Force memory writes to complete before letting h/w |
|
4862 |
* know there are new descriptors to fetch. (Only |
|
4863 |
* applicable for weak-ordered memory model archs, |
|
4864 |
* such as IA-64). */ |
|
4865 |
wmb(); |
|
4866 |
/* Hardware increments by 16 bytes, but packet split |
|
4867 |
* descriptors are 32 bytes...so we increment tail |
|
4868 |
* twice as much. |
|
4869 |
*/ |
|
4870 |
writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt); |
|
4871 |
} |
|
4872 |
} |
|
4873 |
||
4874 |
/** |
|
4875 |
* e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
|
4876 |
* @adapter: |
|
4877 |
**/ |
|
4878 |
||
4879 |
static void |
|
4880 |
e1000_smartspeed(struct e1000_adapter *adapter) |
|
4881 |
{ |
|
4882 |
uint16_t phy_status; |
|
4883 |
uint16_t phy_ctrl; |
|
4884 |
||
4885 |
if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg || |
|
4886 |
!(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL)) |
|
4887 |
return; |
|
4888 |
||
4889 |
if (adapter->smartspeed == 0) { |
|
4890 |
/* If Master/Slave config fault is asserted twice, |
|
4891 |
* we assume back-to-back */ |
|
4892 |
e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
|
4893 |
if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
|
4894 |
e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
|
4895 |
if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
|
4896 |
e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
|
4897 |
if (phy_ctrl & CR_1000T_MS_ENABLE) { |
|
4898 |
phy_ctrl &= ~CR_1000T_MS_ENABLE; |
|
4899 |
e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, |
|
4900 |
phy_ctrl); |
|
4901 |
adapter->smartspeed++; |
|
4902 |
if (!e1000_phy_setup_autoneg(&adapter->hw) && |
|
4903 |
!e1000_read_phy_reg(&adapter->hw, PHY_CTRL, |
|
4904 |
&phy_ctrl)) { |
|
4905 |
phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
|
4906 |
MII_CR_RESTART_AUTO_NEG); |
|
4907 |
e1000_write_phy_reg(&adapter->hw, PHY_CTRL, |
|
4908 |
phy_ctrl); |
|
4909 |
} |
|
4910 |
} |
|
4911 |
return; |
|
4912 |
} else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
|
4913 |
/* If still no link, perhaps using 2/3 pair cable */ |
|
4914 |
e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
|
4915 |
phy_ctrl |= CR_1000T_MS_ENABLE; |
|
4916 |
e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl); |
|
4917 |
if (!e1000_phy_setup_autoneg(&adapter->hw) && |
|
4918 |
!e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) { |
|
4919 |
phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
|
4920 |
MII_CR_RESTART_AUTO_NEG); |
|
4921 |
e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl); |
|
4922 |
} |
|
4923 |
} |
|
4924 |
/* Restart process after E1000_SMARTSPEED_MAX iterations */ |
|
4925 |
if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
|
4926 |
adapter->smartspeed = 0; |
|
4927 |
} |
|
4928 |
||
4929 |
/** |
|
4930 |
* e1000_ioctl - |
|
4931 |
* @netdev: |
|
4932 |
* @ifreq: |
|
4933 |
* @cmd: |
|
4934 |
**/ |
|
4935 |
||
4936 |
static int |
|
4937 |
e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
|
4938 |
{ |
|
4939 |
switch (cmd) { |
|
4940 |
case SIOCGMIIPHY: |
|
4941 |
case SIOCGMIIREG: |
|
4942 |
case SIOCSMIIREG: |
|
4943 |
return e1000_mii_ioctl(netdev, ifr, cmd); |
|
4944 |
default: |
|
4945 |
return -EOPNOTSUPP; |
|
4946 |
} |
|
4947 |
} |
|
4948 |
||
4949 |
/** |
|
4950 |
* e1000_mii_ioctl - |
|
4951 |
* @netdev: |
|
4952 |
* @ifreq: |
|
4953 |
* @cmd: |
|
4954 |
**/ |
|
4955 |
||
4956 |
static int |
|
4957 |
e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
|
4958 |
{ |
|
4959 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
4960 |
struct mii_ioctl_data *data = if_mii(ifr); |
|
4961 |
int retval; |
|
4962 |
uint16_t mii_reg; |
|
4963 |
uint16_t spddplx; |
|
4964 |
unsigned long flags; |
|
4965 |
||
4966 |
if (adapter->hw.media_type != e1000_media_type_copper) |
|
4967 |
return -EOPNOTSUPP; |
|
4968 |
||
4969 |
switch (cmd) { |
|
4970 |
case SIOCGMIIPHY: |
|
4971 |
data->phy_id = adapter->hw.phy_addr; |
|
4972 |
break; |
|
4973 |
case SIOCGMIIREG: |
|
4974 |
if (adapter->ecdev || !capable(CAP_NET_ADMIN)) |
|
4975 |
return -EPERM; |
|
4976 |
spin_lock_irqsave(&adapter->stats_lock, flags); |
|
4977 |
if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
|
4978 |
&data->val_out)) { |
|
4979 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
4980 |
return -EIO; |
|
4981 |
} |
|
4982 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
4983 |
break; |
|
4984 |
case SIOCSMIIREG: |
|
4985 |
if (adapter->ecdev || !capable(CAP_NET_ADMIN)) |
|
4986 |
return -EPERM; |
|
4987 |
if (data->reg_num & ~(0x1F)) |
|
4988 |
return -EFAULT; |
|
4989 |
mii_reg = data->val_in; |
|
4990 |
spin_lock_irqsave(&adapter->stats_lock, flags); |
|
4991 |
if (e1000_write_phy_reg(&adapter->hw, data->reg_num, |
|
4992 |
mii_reg)) { |
|
4993 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
4994 |
return -EIO; |
|
4995 |
} |
|
4996 |
if (adapter->hw.media_type == e1000_media_type_copper) { |
|
4997 |
switch (data->reg_num) { |
|
4998 |
case PHY_CTRL: |
|
4999 |
if (mii_reg & MII_CR_POWER_DOWN) |
|
5000 |
break; |
|
5001 |
if (mii_reg & MII_CR_AUTO_NEG_EN) { |
|
5002 |
adapter->hw.autoneg = 1; |
|
5003 |
adapter->hw.autoneg_advertised = 0x2F; |
|
5004 |
} else { |
|
5005 |
if (mii_reg & 0x40) |
|
5006 |
spddplx = SPEED_1000; |
|
5007 |
else if (mii_reg & 0x2000) |
|
5008 |
spddplx = SPEED_100; |
|
5009 |
else |
|
5010 |
spddplx = SPEED_10; |
|
5011 |
spddplx += (mii_reg & 0x100) |
|
5012 |
? DUPLEX_FULL : |
|
5013 |
DUPLEX_HALF; |
|
5014 |
retval = e1000_set_spd_dplx(adapter, |
|
5015 |
spddplx); |
|
5016 |
if (retval) { |
|
5017 |
spin_unlock_irqrestore( |
|
5018 |
&adapter->stats_lock, |
|
5019 |
flags); |
|
5020 |
return retval; |
|
5021 |
} |
|
5022 |
} |
|
5023 |
if (netif_running(adapter->netdev)) |
|
5024 |
e1000_reinit_locked(adapter); |
|
5025 |
else |
|
5026 |
e1000_reset(adapter); |
|
5027 |
break; |
|
5028 |
case M88E1000_PHY_SPEC_CTRL: |
|
5029 |
case M88E1000_EXT_PHY_SPEC_CTRL: |
|
5030 |
if (e1000_phy_reset(&adapter->hw)) { |
|
5031 |
spin_unlock_irqrestore( |
|
5032 |
&adapter->stats_lock, flags); |
|
5033 |
return -EIO; |
|
5034 |
} |
|
5035 |
break; |
|
5036 |
} |
|
5037 |
} else { |
|
5038 |
switch (data->reg_num) { |
|
5039 |
case PHY_CTRL: |
|
5040 |
if (mii_reg & MII_CR_POWER_DOWN) |
|
5041 |
break; |
|
5042 |
if (netif_running(adapter->netdev)) |
|
5043 |
e1000_reinit_locked(adapter); |
|
5044 |
else |
|
5045 |
e1000_reset(adapter); |
|
5046 |
break; |
|
5047 |
} |
|
5048 |
} |
|
5049 |
spin_unlock_irqrestore(&adapter->stats_lock, flags); |
|
5050 |
break; |
|
5051 |
default: |
|
5052 |
return -EOPNOTSUPP; |
|
5053 |
} |
|
5054 |
return E1000_SUCCESS; |
|
5055 |
} |
|
5056 |
||
5057 |
void |
|
5058 |
e1000_pci_set_mwi(struct e1000_hw *hw) |
|
5059 |
{ |
|
5060 |
struct e1000_adapter *adapter = hw->back; |
|
5061 |
int ret_val = pci_set_mwi(adapter->pdev); |
|
5062 |
||
5063 |
if (ret_val) |
|
5064 |
DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
|
5065 |
} |
|
5066 |
||
5067 |
void |
|
5068 |
e1000_pci_clear_mwi(struct e1000_hw *hw) |
|
5069 |
{ |
|
5070 |
struct e1000_adapter *adapter = hw->back; |
|
5071 |
||
5072 |
pci_clear_mwi(adapter->pdev); |
|
5073 |
} |
|
5074 |
||
5075 |
void |
|
5076 |
e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
|
5077 |
{ |
|
5078 |
struct e1000_adapter *adapter = hw->back; |
|
5079 |
||
5080 |
pci_read_config_word(adapter->pdev, reg, value); |
|
5081 |
} |
|
5082 |
||
5083 |
void |
|
5084 |
e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
|
5085 |
{ |
|
5086 |
struct e1000_adapter *adapter = hw->back; |
|
5087 |
||
5088 |
pci_write_config_word(adapter->pdev, reg, *value); |
|
5089 |
} |
|
5090 |
||
5091 |
int32_t |
|
5092 |
e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
|
5093 |
{ |
|
5094 |
struct e1000_adapter *adapter = hw->back; |
|
5095 |
uint16_t cap_offset; |
|
5096 |
||
5097 |
cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
|
5098 |
if (!cap_offset) |
|
5099 |
return -E1000_ERR_CONFIG; |
|
5100 |
||
5101 |
pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
|
5102 |
||
5103 |
return E1000_SUCCESS; |
|
5104 |
} |
|
5105 |
||
5106 |
void |
|
5107 |
e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value) |
|
5108 |
{ |
|
5109 |
outl(value, port); |
|
5110 |
} |
|
5111 |
||
5112 |
static void |
|
5113 |
e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) |
|
5114 |
{ |
|
5115 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5116 |
uint32_t ctrl, rctl; |
|
5117 |
||
5118 |
e1000_irq_disable(adapter); |
|
5119 |
adapter->vlgrp = grp; |
|
5120 |
||
5121 |
if (grp) { |
|
5122 |
/* enable VLAN tag insert/strip */ |
|
5123 |
ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
|
5124 |
ctrl |= E1000_CTRL_VME; |
|
5125 |
E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
|
5126 |
||
5127 |
if (adapter->hw.mac_type != e1000_ich8lan) { |
|
5128 |
/* enable VLAN receive filtering */ |
|
5129 |
rctl = E1000_READ_REG(&adapter->hw, RCTL); |
|
5130 |
rctl |= E1000_RCTL_VFE; |
|
5131 |
rctl &= ~E1000_RCTL_CFIEN; |
|
5132 |
E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
|
5133 |
e1000_update_mng_vlan(adapter); |
|
5134 |
} |
|
5135 |
} else { |
|
5136 |
/* disable VLAN tag insert/strip */ |
|
5137 |
ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
|
5138 |
ctrl &= ~E1000_CTRL_VME; |
|
5139 |
E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
|
5140 |
||
5141 |
if (adapter->hw.mac_type != e1000_ich8lan) { |
|
5142 |
/* disable VLAN filtering */ |
|
5143 |
rctl = E1000_READ_REG(&adapter->hw, RCTL); |
|
5144 |
rctl &= ~E1000_RCTL_VFE; |
|
5145 |
E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
|
5146 |
if (adapter->mng_vlan_id != |
|
5147 |
(uint16_t)E1000_MNG_VLAN_NONE) { |
|
5148 |
e1000_vlan_rx_kill_vid(netdev, |
|
5149 |
adapter->mng_vlan_id); |
|
5150 |
adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
|
5151 |
} |
|
5152 |
} |
|
5153 |
} |
|
5154 |
||
5155 |
e1000_irq_enable(adapter); |
|
5156 |
} |
|
5157 |
||
5158 |
static void |
|
5159 |
e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid) |
|
5160 |
{ |
|
5161 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5162 |
uint32_t vfta, index; |
|
5163 |
||
5164 |
if ((adapter->hw.mng_cookie.status & |
|
5165 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
|
5166 |
(vid == adapter->mng_vlan_id)) |
|
5167 |
return; |
|
5168 |
/* add VID to filter table */ |
|
5169 |
index = (vid >> 5) & 0x7F; |
|
5170 |
vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
|
5171 |
vfta |= (1 << (vid & 0x1F)); |
|
5172 |
e1000_write_vfta(&adapter->hw, index, vfta); |
|
5173 |
} |
|
5174 |
||
5175 |
static void |
|
5176 |
e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid) |
|
5177 |
{ |
|
5178 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5179 |
uint32_t vfta, index; |
|
5180 |
||
5181 |
e1000_irq_disable(adapter); |
|
5182 |
||
5183 |
if (adapter->vlgrp) |
|
5184 |
adapter->vlgrp->vlan_devices[vid] = NULL; |
|
5185 |
||
5186 |
e1000_irq_enable(adapter); |
|
5187 |
||
5188 |
if ((adapter->hw.mng_cookie.status & |
|
5189 |
E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
|
5190 |
(vid == adapter->mng_vlan_id)) { |
|
5191 |
/* release control to f/w */ |
|
5192 |
e1000_release_hw_control(adapter); |
|
5193 |
return; |
|
5194 |
} |
|
5195 |
||
5196 |
/* remove VID from filter table */ |
|
5197 |
index = (vid >> 5) & 0x7F; |
|
5198 |
vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
|
5199 |
vfta &= ~(1 << (vid & 0x1F)); |
|
5200 |
e1000_write_vfta(&adapter->hw, index, vfta); |
|
5201 |
} |
|
5202 |
||
5203 |
static void |
|
5204 |
e1000_restore_vlan(struct e1000_adapter *adapter) |
|
5205 |
{ |
|
5206 |
e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
|
5207 |
||
5208 |
if (adapter->vlgrp) { |
|
5209 |
uint16_t vid; |
|
5210 |
for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
|
5211 |
if (!adapter->vlgrp->vlan_devices[vid]) |
|
5212 |
continue; |
|
5213 |
e1000_vlan_rx_add_vid(adapter->netdev, vid); |
|
5214 |
} |
|
5215 |
} |
|
5216 |
} |
|
5217 |
||
5218 |
int |
|
5219 |
e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx) |
|
5220 |
{ |
|
5221 |
adapter->hw.autoneg = 0; |
|
5222 |
||
5223 |
/* Fiber NICs only allow 1000 gbps Full duplex */ |
|
5224 |
if ((adapter->hw.media_type == e1000_media_type_fiber) && |
|
5225 |
spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
|
5226 |
DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
|
5227 |
return -EINVAL; |
|
5228 |
} |
|
5229 |
||
5230 |
switch (spddplx) { |
|
5231 |
case SPEED_10 + DUPLEX_HALF: |
|
5232 |
adapter->hw.forced_speed_duplex = e1000_10_half; |
|
5233 |
break; |
|
5234 |
case SPEED_10 + DUPLEX_FULL: |
|
5235 |
adapter->hw.forced_speed_duplex = e1000_10_full; |
|
5236 |
break; |
|
5237 |
case SPEED_100 + DUPLEX_HALF: |
|
5238 |
adapter->hw.forced_speed_duplex = e1000_100_half; |
|
5239 |
break; |
|
5240 |
case SPEED_100 + DUPLEX_FULL: |
|
5241 |
adapter->hw.forced_speed_duplex = e1000_100_full; |
|
5242 |
break; |
|
5243 |
case SPEED_1000 + DUPLEX_FULL: |
|
5244 |
adapter->hw.autoneg = 1; |
|
5245 |
adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; |
|
5246 |
break; |
|
5247 |
case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
|
5248 |
default: |
|
5249 |
DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
|
5250 |
return -EINVAL; |
|
5251 |
} |
|
5252 |
return 0; |
|
5253 |
} |
|
5254 |
||
5255 |
#ifdef CONFIG_PM |
|
5256 |
/* Save/restore 16 or 64 dwords of PCI config space depending on which |
|
5257 |
* bus we're on (PCI(X) vs. PCI-E) |
|
5258 |
*/ |
|
5259 |
#define PCIE_CONFIG_SPACE_LEN 256 |
|
5260 |
#define PCI_CONFIG_SPACE_LEN 64 |
|
5261 |
static int |
|
5262 |
e1000_pci_save_state(struct e1000_adapter *adapter) |
|
5263 |
{ |
|
5264 |
struct pci_dev *dev = adapter->pdev; |
|
5265 |
int size; |
|
5266 |
int i; |
|
5267 |
||
5268 |
if (adapter->hw.mac_type >= e1000_82571) |
|
5269 |
size = PCIE_CONFIG_SPACE_LEN; |
|
5270 |
else |
|
5271 |
size = PCI_CONFIG_SPACE_LEN; |
|
5272 |
||
5273 |
WARN_ON(adapter->config_space != NULL); |
|
5274 |
||
5275 |
adapter->config_space = kmalloc(size, GFP_KERNEL); |
|
5276 |
if (!adapter->config_space) { |
|
5277 |
DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size); |
|
5278 |
return -ENOMEM; |
|
5279 |
} |
|
5280 |
for (i = 0; i < (size / 4); i++) |
|
5281 |
pci_read_config_dword(dev, i * 4, &adapter->config_space[i]); |
|
5282 |
return 0; |
|
5283 |
} |
|
5284 |
||
5285 |
static void |
|
5286 |
e1000_pci_restore_state(struct e1000_adapter *adapter) |
|
5287 |
{ |
|
5288 |
struct pci_dev *dev = adapter->pdev; |
|
5289 |
int size; |
|
5290 |
int i; |
|
5291 |
||
5292 |
if (adapter->config_space == NULL) |
|
5293 |
return; |
|
5294 |
||
5295 |
if (adapter->hw.mac_type >= e1000_82571) |
|
5296 |
size = PCIE_CONFIG_SPACE_LEN; |
|
5297 |
else |
|
5298 |
size = PCI_CONFIG_SPACE_LEN; |
|
5299 |
for (i = 0; i < (size / 4); i++) |
|
5300 |
pci_write_config_dword(dev, i * 4, adapter->config_space[i]); |
|
5301 |
kfree(adapter->config_space); |
|
5302 |
adapter->config_space = NULL; |
|
5303 |
return; |
|
5304 |
} |
|
5305 |
#endif /* CONFIG_PM */ |
|
5306 |
||
5307 |
static int |
|
5308 |
e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
|
5309 |
{ |
|
5310 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5311 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5312 |
uint32_t ctrl, ctrl_ext, rctl, status; |
|
5313 |
uint32_t wufc = adapter->wol; |
|
5314 |
#ifdef CONFIG_PM |
|
5315 |
int retval = 0; |
|
5316 |
#endif |
|
5317 |
||
5318 |
if (adapter->ecdev) |
|
5319 |
return -EBUSY; |
|
5320 |
||
5321 |
netif_device_detach(netdev); |
|
5322 |
||
5323 |
if (netif_running(netdev)) { |
|
5324 |
WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
|
5325 |
e1000_down(adapter); |
|
5326 |
} |
|
5327 |
||
5328 |
#ifdef CONFIG_PM |
|
5329 |
/* Implement our own version of pci_save_state(pdev) because pci- |
|
5330 |
* express adapters have 256-byte config spaces. */ |
|
5331 |
retval = e1000_pci_save_state(adapter); |
|
5332 |
if (retval) |
|
5333 |
return retval; |
|
5334 |
#endif |
|
5335 |
||
5336 |
status = E1000_READ_REG(&adapter->hw, STATUS); |
|
5337 |
if (status & E1000_STATUS_LU) |
|
5338 |
wufc &= ~E1000_WUFC_LNKC; |
|
5339 |
||
5340 |
if (wufc) { |
|
5341 |
e1000_setup_rctl(adapter); |
|
5342 |
e1000_set_multi(netdev); |
|
5343 |
||
5344 |
/* turn on all-multi mode if wake on multicast is enabled */ |
|
5345 |
if (wufc & E1000_WUFC_MC) { |
|
5346 |
rctl = E1000_READ_REG(&adapter->hw, RCTL); |
|
5347 |
rctl |= E1000_RCTL_MPE; |
|
5348 |
E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
|
5349 |
} |
|
5350 |
||
5351 |
if (adapter->hw.mac_type >= e1000_82540) { |
|
5352 |
ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
|
5353 |
/* advertise wake from D3Cold */ |
|
5354 |
#define E1000_CTRL_ADVD3WUC 0x00100000 |
|
5355 |
/* phy power management enable */ |
|
5356 |
#define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
|
5357 |
ctrl |= E1000_CTRL_ADVD3WUC | |
|
5358 |
E1000_CTRL_EN_PHY_PWR_MGMT; |
|
5359 |
E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
|
5360 |
} |
|
5361 |
||
5362 |
if (adapter->hw.media_type == e1000_media_type_fiber || |
|
5363 |
adapter->hw.media_type == e1000_media_type_internal_serdes) { |
|
5364 |
/* keep the laser running in D3 */ |
|
5365 |
ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
|
5366 |
ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
|
5367 |
E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext); |
|
5368 |
} |
|
5369 |
||
5370 |
/* Allow time for pending master requests to run */ |
|
5371 |
e1000_disable_pciex_master(&adapter->hw); |
|
5372 |
||
5373 |
E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN); |
|
5374 |
E1000_WRITE_REG(&adapter->hw, WUFC, wufc); |
|
5375 |
pci_enable_wake(pdev, PCI_D3hot, 1); |
|
5376 |
pci_enable_wake(pdev, PCI_D3cold, 1); |
|
5377 |
} else { |
|
5378 |
E1000_WRITE_REG(&adapter->hw, WUC, 0); |
|
5379 |
E1000_WRITE_REG(&adapter->hw, WUFC, 0); |
|
5380 |
pci_enable_wake(pdev, PCI_D3hot, 0); |
|
5381 |
pci_enable_wake(pdev, PCI_D3cold, 0); |
|
5382 |
} |
|
5383 |
||
5384 |
e1000_release_manageability(adapter); |
|
5385 |
||
5386 |
/* make sure adapter isn't asleep if manageability is enabled */ |
|
5387 |
if (adapter->en_mng_pt) { |
|
5388 |
pci_enable_wake(pdev, PCI_D3hot, 1); |
|
5389 |
pci_enable_wake(pdev, PCI_D3cold, 1); |
|
5390 |
} |
|
5391 |
||
5392 |
if (adapter->hw.phy_type == e1000_phy_igp_3) |
|
5393 |
e1000_phy_powerdown_workaround(&adapter->hw); |
|
5394 |
||
5395 |
if (netif_running(netdev)) |
|
5396 |
e1000_free_irq(adapter); |
|
5397 |
||
5398 |
/* Release control of h/w to f/w. If f/w is AMT enabled, this |
|
5399 |
* would have already happened in close and is redundant. */ |
|
5400 |
e1000_release_hw_control(adapter); |
|
5401 |
||
5402 |
pci_disable_device(pdev); |
|
5403 |
||
5404 |
pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
|
5405 |
||
5406 |
return 0; |
|
5407 |
} |
|
5408 |
||
5409 |
#ifdef CONFIG_PM |
|
5410 |
static int |
|
5411 |
e1000_resume(struct pci_dev *pdev) |
|
5412 |
{ |
|
5413 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5414 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5415 |
uint32_t err; |
|
5416 |
||
5417 |
if (adapter->ecdev) |
|
5418 |
return -EBUSY; |
|
5419 |
||
5420 |
pci_set_power_state(pdev, PCI_D0); |
|
5421 |
e1000_pci_restore_state(adapter); |
|
5422 |
if ((err = pci_enable_device(pdev))) { |
|
5423 |
printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); |
|
5424 |
return err; |
|
5425 |
} |
|
5426 |
pci_set_master(pdev); |
|
5427 |
||
5428 |
pci_enable_wake(pdev, PCI_D3hot, 0); |
|
5429 |
pci_enable_wake(pdev, PCI_D3cold, 0); |
|
5430 |
||
5431 |
if (netif_running(netdev) && (err = e1000_request_irq(adapter))) |
|
5432 |
return err; |
|
5433 |
||
5434 |
e1000_power_up_phy(adapter); |
|
5435 |
e1000_reset(adapter); |
|
5436 |
E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
|
5437 |
||
5438 |
e1000_init_manageability(adapter); |
|
5439 |
||
5440 |
if (netif_running(netdev)) |
|
5441 |
e1000_up(adapter); |
|
5442 |
||
5443 |
if (!adapter->ecdev) netif_device_attach(netdev); |
|
5444 |
||
5445 |
/* If the controller is 82573 and f/w is AMT, do not set |
|
5446 |
* DRV_LOAD until the interface is up. For all other cases, |
|
5447 |
* let the f/w know that the h/w is now under the control |
|
5448 |
* of the driver. */ |
|
5449 |
if (adapter->hw.mac_type != e1000_82573 || |
|
5450 |
!e1000_check_mng_mode(&adapter->hw)) |
|
5451 |
e1000_get_hw_control(adapter); |
|
5452 |
||
5453 |
return 0; |
|
5454 |
} |
|
5455 |
#endif |
|
5456 |
||
5457 |
static void e1000_shutdown(struct pci_dev *pdev) |
|
5458 |
{ |
|
5459 |
e1000_suspend(pdev, PMSG_SUSPEND); |
|
5460 |
} |
|
5461 |
||
5462 |
#ifdef CONFIG_NET_POLL_CONTROLLER |
|
5463 |
/* |
|
5464 |
* Polling 'interrupt' - used by things like netconsole to send skbs |
|
5465 |
* without having to re-enable interrupts. It's not called while |
|
5466 |
* the interrupt routine is executing. |
|
5467 |
*/ |
|
5468 |
static void |
|
5469 |
e1000_netpoll(struct net_device *netdev) |
|
5470 |
{ |
|
5471 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
|
5472 |
||
5473 |
disable_irq(adapter->pdev->irq); |
|
5474 |
e1000_intr(adapter->pdev->irq, netdev); |
|
5475 |
e1000_clean_tx_irq(adapter, adapter->tx_ring); |
|
5476 |
#ifndef CONFIG_E1000_NAPI |
|
5477 |
adapter->clean_rx(adapter, adapter->rx_ring); |
|
5478 |
#endif |
|
5479 |
enable_irq(adapter->pdev->irq); |
|
5480 |
} |
|
5481 |
#endif |
|
5482 |
||
5483 |
/** |
|
5484 |
* e1000_io_error_detected - called when PCI error is detected |
|
5485 |
* @pdev: Pointer to PCI device |
|
5486 |
* @state: The current pci conneection state |
|
5487 |
* |
|
5488 |
* This function is called after a PCI bus error affecting |
|
5489 |
* this device has been detected. |
|
5490 |
*/ |
|
5491 |
static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
|
5492 |
{ |
|
5493 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5494 |
struct e1000_adapter *adapter = netdev->priv; |
|
5495 |
||
5496 |
netif_device_detach(netdev); |
|
5497 |
||
5498 |
if (netif_running(netdev)) |
|
5499 |
e1000_down(adapter); |
|
5500 |
pci_disable_device(pdev); |
|
5501 |
||
5502 |
/* Request a slot slot reset. */ |
|
5503 |
return PCI_ERS_RESULT_NEED_RESET; |
|
5504 |
} |
|
5505 |
||
5506 |
/** |
|
5507 |
* e1000_io_slot_reset - called after the pci bus has been reset. |
|
5508 |
* @pdev: Pointer to PCI device |
|
5509 |
* |
|
5510 |
* Restart the card from scratch, as if from a cold-boot. Implementation |
|
5511 |
* resembles the first-half of the e1000_resume routine. |
|
5512 |
*/ |
|
5513 |
static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
|
5514 |
{ |
|
5515 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5516 |
struct e1000_adapter *adapter = netdev->priv; |
|
5517 |
||
5518 |
if (pci_enable_device(pdev)) { |
|
5519 |
printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n"); |
|
5520 |
return PCI_ERS_RESULT_DISCONNECT; |
|
5521 |
} |
|
5522 |
pci_set_master(pdev); |
|
5523 |
||
5524 |
pci_enable_wake(pdev, PCI_D3hot, 0); |
|
5525 |
pci_enable_wake(pdev, PCI_D3cold, 0); |
|
5526 |
||
5527 |
e1000_reset(adapter); |
|
5528 |
E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
|
5529 |
||
5530 |
return PCI_ERS_RESULT_RECOVERED; |
|
5531 |
} |
|
5532 |
||
5533 |
/** |
|
5534 |
* e1000_io_resume - called when traffic can start flowing again. |
|
5535 |
* @pdev: Pointer to PCI device |
|
5536 |
* |
|
5537 |
* This callback is called when the error recovery driver tells us that |
|
5538 |
* its OK to resume normal operation. Implementation resembles the |
|
5539 |
* second-half of the e1000_resume routine. |
|
5540 |
*/ |
|
5541 |
static void e1000_io_resume(struct pci_dev *pdev) |
|
5542 |
{ |
|
5543 |
struct net_device *netdev = pci_get_drvdata(pdev); |
|
5544 |
struct e1000_adapter *adapter = netdev->priv; |
|
5545 |
||
5546 |
e1000_init_manageability(adapter); |
|
5547 |
||
5548 |
if (netif_running(netdev)) { |
|
5549 |
if (e1000_up(adapter)) { |
|
5550 |
printk("e1000: can't bring device back up after reset\n"); |
|
5551 |
return; |
|
5552 |
} |
|
5553 |
} |
|
5554 |
||
5555 |
netif_device_attach(netdev); |
|
5556 |
||
5557 |
/* If the controller is 82573 and f/w is AMT, do not set |
|
5558 |
* DRV_LOAD until the interface is up. For all other cases, |
|
5559 |
* let the f/w know that the h/w is now under the control |
|
5560 |
* of the driver. */ |
|
5561 |
if (adapter->hw.mac_type != e1000_82573 || |
|
5562 |
!e1000_check_mng_mode(&adapter->hw)) |
|
5563 |
e1000_get_hw_control(adapter); |
|
5564 |
||
5565 |
} |
|
5566 |
||
5567 |
/* e1000_main.c */ |