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