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