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