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