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