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