blob: 2110d5f2da19037d11be071566c8ce882b8644e6 [file] [log] [blame]
Jeff Kirsherae06c702018-03-22 10:08:48 -07001// SPDX-License-Identifier: GPL-2.0
Jeff Kirsher51dce242018-04-26 08:08:09 -07002/* Copyright(c) 1999 - 2006 Intel Corporation. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
4#include "e1000.h"
Andrew Mortond0bb53e2006-11-14 10:35:03 -05005#include <net/ip6_checksum.h>
Dirk Brandewie5377a412011-01-06 14:29:54 +00006#include <linux/io.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -04007#include <linux/prefetch.h>
Jiri Pirko5622e402011-07-21 03:26:31 +00008#include <linux/bitops.h>
9#include <linux/if_vlan.h>
Dirk Brandewie5377a412011-01-06 14:29:54 +000010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011char e1000_driver_name[] = "e1000";
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010012static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Anupam Chandaab088532010-11-21 09:54:21 -080013#define DRV_VERSION "7.3.21-k8-NAPI"
Stephen Hemmingerabec42a2007-10-29 10:46:19 -070014const char e1000_driver_version[] = DRV_VERSION;
15static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17/* e1000_pci_tbl - PCI Device ID Table
18 *
19 * Last entry must be all 0s
20 *
21 * Macro expands to...
22 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
23 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020024static const struct pci_device_id e1000_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 INTEL_E1000_ETHERNET_DEVICE(0x1000),
26 INTEL_E1000_ETHERNET_DEVICE(0x1001),
27 INTEL_E1000_ETHERNET_DEVICE(0x1004),
28 INTEL_E1000_ETHERNET_DEVICE(0x1008),
29 INTEL_E1000_ETHERNET_DEVICE(0x1009),
30 INTEL_E1000_ETHERNET_DEVICE(0x100C),
31 INTEL_E1000_ETHERNET_DEVICE(0x100D),
32 INTEL_E1000_ETHERNET_DEVICE(0x100E),
33 INTEL_E1000_ETHERNET_DEVICE(0x100F),
34 INTEL_E1000_ETHERNET_DEVICE(0x1010),
35 INTEL_E1000_ETHERNET_DEVICE(0x1011),
36 INTEL_E1000_ETHERNET_DEVICE(0x1012),
37 INTEL_E1000_ETHERNET_DEVICE(0x1013),
38 INTEL_E1000_ETHERNET_DEVICE(0x1014),
39 INTEL_E1000_ETHERNET_DEVICE(0x1015),
40 INTEL_E1000_ETHERNET_DEVICE(0x1016),
41 INTEL_E1000_ETHERNET_DEVICE(0x1017),
42 INTEL_E1000_ETHERNET_DEVICE(0x1018),
43 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -070044 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 INTEL_E1000_ETHERNET_DEVICE(0x101D),
46 INTEL_E1000_ETHERNET_DEVICE(0x101E),
47 INTEL_E1000_ETHERNET_DEVICE(0x1026),
48 INTEL_E1000_ETHERNET_DEVICE(0x1027),
49 INTEL_E1000_ETHERNET_DEVICE(0x1028),
50 INTEL_E1000_ETHERNET_DEVICE(0x1075),
51 INTEL_E1000_ETHERNET_DEVICE(0x1076),
52 INTEL_E1000_ETHERNET_DEVICE(0x1077),
53 INTEL_E1000_ETHERNET_DEVICE(0x1078),
54 INTEL_E1000_ETHERNET_DEVICE(0x1079),
55 INTEL_E1000_ETHERNET_DEVICE(0x107A),
56 INTEL_E1000_ETHERNET_DEVICE(0x107B),
57 INTEL_E1000_ETHERNET_DEVICE(0x107C),
58 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080059 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080060 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Dirk Brandewie5377a412011-01-06 14:29:54 +000061 INTEL_E1000_ETHERNET_DEVICE(0x2E6E),
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 /* required last entry */
63 {0,}
64};
65
66MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
67
Nicholas Nunley35574762006-09-27 12:53:34 -070068int e1000_up(struct e1000_adapter *adapter);
69void e1000_down(struct e1000_adapter *adapter);
70void e1000_reinit_locked(struct e1000_adapter *adapter);
71void e1000_reset(struct e1000_adapter *adapter);
Nicholas Nunley35574762006-09-27 12:53:34 -070072int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
73int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
74void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
75void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010076static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Janusz Wolaka48954c2015-09-17 23:34:29 +020077 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010078static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Janusz Wolaka48954c2015-09-17 23:34:29 +020079 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010080static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Janusz Wolaka48954c2015-09-17 23:34:29 +020081 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010082static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Janusz Wolaka48954c2015-09-17 23:34:29 +020083 struct e1000_rx_ring *rx_ring);
Nicholas Nunley35574762006-09-27 12:53:34 -070084void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86static int e1000_init_module(void);
87static void e1000_exit_module(void);
88static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050089static void e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -040090static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static int e1000_sw_init(struct e1000_adapter *adapter);
Stefan Assmann1f2f83f2016-02-03 09:20:51 +010092int e1000_open(struct net_device *netdev);
93int e1000_close(struct net_device *netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static void e1000_configure_tx(struct e1000_adapter *adapter);
95static void e1000_configure_rx(struct e1000_adapter *adapter);
96static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -040097static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
98static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
99static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
Janusz Wolaka48954c2015-09-17 23:34:29 +0200100 struct e1000_tx_ring *tx_ring);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400101static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
Janusz Wolaka48954c2015-09-17 23:34:29 +0200102 struct e1000_rx_ring *rx_ring);
Patrick McHardydb0ce502007-11-13 20:54:59 -0800103static void e1000_set_rx_mode(struct net_device *netdev);
Jesse Brandeburg5cf42fc2010-09-22 18:22:17 +0000104static void e1000_update_phy_info_task(struct work_struct *work);
Jesse Brandeburga4010af2011-10-05 07:24:41 +0000105static void e1000_watchdog(struct work_struct *work);
Jesse Brandeburg5cf42fc2010-09-22 18:22:17 +0000106static void e1000_82547_tx_fifo_stall_task(struct work_struct *work);
Stephen Hemminger3b29a562009-08-31 19:50:55 +0000107static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
108 struct net_device *netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
110static int e1000_set_mac(struct net_device *netdev, void *p);
David Howells7d12e782006-10-05 14:55:46 +0100111static irqreturn_t e1000_intr(int irq, void *data);
Joe Perchesc3033b02008-03-21 11:06:25 -0700112static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
113 struct e1000_tx_ring *tx_ring);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700114static int e1000_clean(struct napi_struct *napi, int budget);
Joe Perchesc3033b02008-03-21 11:06:25 -0700115static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
116 struct e1000_rx_ring *rx_ring,
117 int *work_done, int work_to_do);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +0000118static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
119 struct e1000_rx_ring *rx_ring,
120 int *work_done, int work_to_do);
Sabrina Dubroca08e83312015-02-26 05:35:41 +0000121static void e1000_alloc_dummy_rx_buffers(struct e1000_adapter *adapter,
122 struct e1000_rx_ring *rx_ring,
123 int cleaned_count)
124{
125}
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400126static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +0000127 struct e1000_rx_ring *rx_ring,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800128 int cleaned_count);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +0000129static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
130 struct e1000_rx_ring *rx_ring,
131 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
133static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
134 int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
136static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
137static void e1000_tx_timeout(struct net_device *dev);
David Howells65f27f32006-11-22 14:55:48 +0000138static void e1000_reset_task(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700140static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
Janusz Wolaka48954c2015-09-17 23:34:29 +0200141 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Jiri Pirko5622e402011-07-21 03:26:31 +0000143static bool e1000_vlan_used(struct e1000_adapter *adapter);
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000144static void e1000_vlan_mode(struct net_device *netdev,
145 netdev_features_t features);
Jiri Pirko52f55092012-03-20 18:10:01 +0000146static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
147 bool filter_on);
Patrick McHardy80d5c362013-04-19 02:04:28 +0000148static int e1000_vlan_rx_add_vid(struct net_device *netdev,
149 __be16 proto, u16 vid);
150static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
151 __be16 proto, u16 vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152static void e1000_restore_vlan(struct e1000_adapter *adapter);
153
Auke Kok6fdfef12006-06-27 09:06:36 -0700154#ifdef CONFIG_PM
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +0000155static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156static int e1000_resume(struct pci_dev *pdev);
157#endif
Auke Kokc653e632006-05-23 13:35:57 -0700158static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160#ifdef CONFIG_NET_POLL_CONTROLLER
161/* for netdump / net console */
162static void e1000_netpoll (struct net_device *netdev);
163#endif
164
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100165#define COPYBREAK_DEFAULT 256
166static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
167module_param(copybreak, uint, 0644);
168MODULE_PARM_DESC(copybreak,
169 "Maximum size of packet that is copied to a new buffer on receive");
170
Auke Kok90267292006-06-08 09:30:24 -0700171static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
Janusz Wolaka48954c2015-09-17 23:34:29 +0200172 pci_channel_state_t state);
Auke Kok90267292006-06-08 09:30:24 -0700173static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
174static void e1000_io_resume(struct pci_dev *pdev);
175
Stephen Hemminger3646f0e2012-09-07 09:33:15 -0700176static const struct pci_error_handlers e1000_err_handler = {
Auke Kok90267292006-06-08 09:30:24 -0700177 .error_detected = e1000_io_error_detected,
178 .slot_reset = e1000_io_slot_reset,
179 .resume = e1000_io_resume,
180};
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static struct pci_driver e1000_driver = {
183 .name = e1000_driver_name,
184 .id_table = e1000_pci_tbl,
185 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -0500186 .remove = e1000_remove,
Auke Kokc4e24f02006-09-27 12:53:19 -0700187#ifdef CONFIG_PM
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300188 /* Power Management Hooks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 .suspend = e1000_suspend,
Auke Kokc653e632006-05-23 13:35:57 -0700190 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#endif
Auke Kok90267292006-06-08 09:30:24 -0700192 .shutdown = e1000_shutdown,
193 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194};
195
196MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
197MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
198MODULE_LICENSE("GPL");
199MODULE_VERSION(DRV_VERSION);
200
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000201#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
202static int debug = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203module_param(debug, int, 0);
204MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
205
206/**
Emil Tantilov675ad472010-04-27 14:02:58 +0000207 * e1000_get_hw_dev - return device
208 * used by hardware layer to print debugging information
209 *
210 **/
211struct net_device *e1000_get_hw_dev(struct e1000_hw *hw)
212{
213 struct e1000_adapter *adapter = hw->back;
214 return adapter->netdev;
215}
216
217/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 * e1000_init_module - Driver Registration Routine
219 *
220 * e1000_init_module is the first routine called when the driver is
221 * loaded. All it does is register with the PCI subsystem.
222 **/
Joe Perches64798842008-07-11 15:17:02 -0700223static int __init e1000_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
225 int ret;
Emil Tantilov675ad472010-04-27 14:02:58 +0000226 pr_info("%s - version %s\n", e1000_driver_string, e1000_driver_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Emil Tantilov675ad472010-04-27 14:02:58 +0000228 pr_info("%s\n", e1000_copyright);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Jeff Garzik29917622006-08-19 17:48:59 -0400230 ret = pci_register_driver(&e1000_driver);
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100231 if (copybreak != COPYBREAK_DEFAULT) {
232 if (copybreak == 0)
Emil Tantilov675ad472010-04-27 14:02:58 +0000233 pr_info("copybreak disabled\n");
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100234 else
Emil Tantilov675ad472010-04-27 14:02:58 +0000235 pr_info("copybreak enabled for "
236 "packets <= %u bytes\n", copybreak);
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return ret;
239}
240
241module_init(e1000_init_module);
242
243/**
244 * e1000_exit_module - Driver Exit Cleanup Routine
245 *
246 * e1000_exit_module is called just before the driver is removed
247 * from memory.
248 **/
Joe Perches64798842008-07-11 15:17:02 -0700249static void __exit e1000_exit_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 pci_unregister_driver(&e1000_driver);
252}
253
254module_exit(e1000_exit_module);
255
Auke Kok2db10a02006-06-27 09:06:28 -0700256static int e1000_request_irq(struct e1000_adapter *adapter)
257{
258 struct net_device *netdev = adapter->netdev;
Al Viro3e188262007-12-11 19:49:39 +0000259 irq_handler_t handler = e1000_intr;
Auke Koke94bd232007-05-16 01:49:46 -0700260 int irq_flags = IRQF_SHARED;
261 int err;
Auke Kok2db10a02006-06-27 09:06:28 -0700262
Auke Koke94bd232007-05-16 01:49:46 -0700263 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
Janusz Wolaka48954c2015-09-17 23:34:29 +0200264 netdev);
Auke Koke94bd232007-05-16 01:49:46 -0700265 if (err) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -0700266 e_err(probe, "Unable to allocate interrupt Error: %d\n", err);
Auke Koke94bd232007-05-16 01:49:46 -0700267 }
Auke Kok2db10a02006-06-27 09:06:28 -0700268
269 return err;
270}
271
272static void e1000_free_irq(struct e1000_adapter *adapter)
273{
274 struct net_device *netdev = adapter->netdev;
275
276 free_irq(adapter->pdev->irq, netdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700277}
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279/**
280 * e1000_irq_disable - Mask off interrupt generation on the NIC
281 * @adapter: board private structure
282 **/
Joe Perches64798842008-07-11 15:17:02 -0700283static void e1000_irq_disable(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Joe Perches1dc32912008-07-11 15:17:08 -0700285 struct e1000_hw *hw = &adapter->hw;
286
287 ew32(IMC, ~0);
288 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 synchronize_irq(adapter->pdev->irq);
290}
291
292/**
293 * e1000_irq_enable - Enable default interrupt generation settings
294 * @adapter: board private structure
295 **/
Joe Perches64798842008-07-11 15:17:02 -0700296static void e1000_irq_enable(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Joe Perches1dc32912008-07-11 15:17:08 -0700298 struct e1000_hw *hw = &adapter->hw;
299
300 ew32(IMS, IMS_ENABLE_MASK);
301 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100303
Joe Perches64798842008-07-11 15:17:02 -0700304static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700305{
Joe Perches1dc32912008-07-11 15:17:08 -0700306 struct e1000_hw *hw = &adapter->hw;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700307 struct net_device *netdev = adapter->netdev;
Joe Perches1dc32912008-07-11 15:17:08 -0700308 u16 vid = hw->mng_cookie.vlan_id;
Joe Perches406874a2008-04-03 10:06:32 -0700309 u16 old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800310
Jiri Pirko5622e402011-07-21 03:26:31 +0000311 if (!e1000_vlan_used(adapter))
312 return;
313
314 if (!test_bit(vid, adapter->active_vlans)) {
315 if (hw->mng_cookie.status &
316 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
Patrick McHardy80d5c362013-04-19 02:04:28 +0000317 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800318 adapter->mng_vlan_id = vid;
Jiri Pirko5622e402011-07-21 03:26:31 +0000319 } else {
320 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
321 }
322 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
323 (vid != old_vid) &&
324 !test_bit(old_vid, adapter->active_vlans))
Patrick McHardy80d5c362013-04-19 02:04:28 +0000325 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
326 old_vid);
Jiri Pirko5622e402011-07-21 03:26:31 +0000327 } else {
328 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700329 }
330}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800331
Joe Perches64798842008-07-11 15:17:02 -0700332static void e1000_init_manageability(struct e1000_adapter *adapter)
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500333{
Joe Perches1dc32912008-07-11 15:17:08 -0700334 struct e1000_hw *hw = &adapter->hw;
335
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500336 if (adapter->en_mng_pt) {
Joe Perches1dc32912008-07-11 15:17:08 -0700337 u32 manc = er32(MANC);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500338
339 /* disable hardware interception of ARP */
340 manc &= ~(E1000_MANC_ARP_EN);
341
Joe Perches1dc32912008-07-11 15:17:08 -0700342 ew32(MANC, manc);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500343 }
344}
345
Joe Perches64798842008-07-11 15:17:02 -0700346static void e1000_release_manageability(struct e1000_adapter *adapter)
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500347{
Joe Perches1dc32912008-07-11 15:17:08 -0700348 struct e1000_hw *hw = &adapter->hw;
349
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500350 if (adapter->en_mng_pt) {
Joe Perches1dc32912008-07-11 15:17:08 -0700351 u32 manc = er32(MANC);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500352
353 /* re-enable hardware interception of ARP */
354 manc |= E1000_MANC_ARP_EN;
355
Joe Perches1dc32912008-07-11 15:17:08 -0700356 ew32(MANC, manc);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500357 }
358}
359
Auke Koke0aac5a2007-03-06 08:57:21 -0800360/**
361 * e1000_configure - configure the hardware for RX and TX
362 * @adapter = private board structure
363 **/
364static void e1000_configure(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
366 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700367 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Patrick McHardydb0ce502007-11-13 20:54:59 -0800369 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 e1000_restore_vlan(adapter);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500372 e1000_init_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 e1000_configure_tx(adapter);
375 e1000_setup_rctl(adapter);
376 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800377 /* call E1000_DESC_UNUSED which always leaves
378 * at least 1 descriptor unused to make sure
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000379 * next_to_use != next_to_clean
380 */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800381 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800382 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800383 adapter->alloc_rx_buf(adapter, ring,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000384 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800385 }
Auke Koke0aac5a2007-03-06 08:57:21 -0800386}
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800387
Auke Koke0aac5a2007-03-06 08:57:21 -0800388int e1000_up(struct e1000_adapter *adapter)
389{
Joe Perches1dc32912008-07-11 15:17:08 -0700390 struct e1000_hw *hw = &adapter->hw;
391
Auke Koke0aac5a2007-03-06 08:57:21 -0800392 /* hardware has been reset, we need to reload some things */
393 e1000_configure(adapter);
Malli Chilakala5de55622005-04-28 19:39:30 -0700394
Auke Kok1314bbf2006-09-27 12:54:02 -0700395 clear_bit(__E1000_DOWN, &adapter->flags);
396
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700397 napi_enable(&adapter->napi);
Francois Romieuc3570ac2008-07-11 15:17:38 -0700398
Auke Koke0aac5a2007-03-06 08:57:21 -0800399 e1000_irq_enable(adapter);
400
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +0000401 netif_wake_queue(adapter->netdev);
402
Jesse Brandeburg79f3d392006-12-15 10:42:34 +0100403 /* fire a link change interrupt to start the watchdog */
Joe Perches1dc32912008-07-11 15:17:08 -0700404 ew32(ICS, E1000_ICS_LSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return 0;
406}
407
Auke Kok79f05bf2006-06-27 09:06:32 -0700408/**
409 * e1000_power_up_phy - restore link in case the phy was powered down
410 * @adapter: address of board private structure
411 *
412 * The phy may be powered down to save power and turn off link when the
413 * driver is unloaded and wake on lan is not enabled (among others)
414 * *** this routine MUST be followed by a call to e1000_reset ***
Auke Kok79f05bf2006-06-27 09:06:32 -0700415 **/
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700416void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700417{
Joe Perches1dc32912008-07-11 15:17:08 -0700418 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700419 u16 mii_reg = 0;
Auke Kok79f05bf2006-06-27 09:06:32 -0700420
421 /* Just clear the power down bit to wake the phy back up */
Joe Perches1dc32912008-07-11 15:17:08 -0700422 if (hw->media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700423 /* according to the manual, the phy will retain its
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000424 * settings across a power-down/up cycle
425 */
Joe Perches1dc32912008-07-11 15:17:08 -0700426 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700427 mii_reg &= ~MII_CR_POWER_DOWN;
Joe Perches1dc32912008-07-11 15:17:08 -0700428 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700429 }
430}
431
432static void e1000_power_down_phy(struct e1000_adapter *adapter)
433{
Joe Perches1dc32912008-07-11 15:17:08 -0700434 struct e1000_hw *hw = &adapter->hw;
435
Bruce Allan61c25052006-09-27 12:53:54 -0700436 /* Power down the PHY so no link is implied when interface is down *
Joe Perchesc3033b02008-03-21 11:06:25 -0700437 * The PHY cannot be powered down if any of the following is true *
Auke Kok79f05bf2006-06-27 09:06:32 -0700438 * (a) WoL is enabled
439 * (b) AMT is active
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000440 * (c) SoL/IDER session is active
441 */
Joe Perches1dc32912008-07-11 15:17:08 -0700442 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
443 hw->media_type == e1000_media_type_copper) {
Joe Perches406874a2008-04-03 10:06:32 -0700444 u16 mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700445
Joe Perches1dc32912008-07-11 15:17:08 -0700446 switch (hw->mac_type) {
Bruce Allan61c25052006-09-27 12:53:54 -0700447 case e1000_82540:
448 case e1000_82545:
449 case e1000_82545_rev_3:
450 case e1000_82546:
Dirk Brandewie5377a412011-01-06 14:29:54 +0000451 case e1000_ce4100:
Bruce Allan61c25052006-09-27 12:53:54 -0700452 case e1000_82546_rev_3:
453 case e1000_82541:
454 case e1000_82541_rev_2:
455 case e1000_82547:
456 case e1000_82547_rev_2:
Joe Perches1dc32912008-07-11 15:17:08 -0700457 if (er32(MANC) & E1000_MANC_SMBUS_EN)
Bruce Allan61c25052006-09-27 12:53:54 -0700458 goto out;
459 break;
Bruce Allan61c25052006-09-27 12:53:54 -0700460 default:
461 goto out;
462 }
Joe Perches1dc32912008-07-11 15:17:08 -0700463 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700464 mii_reg |= MII_CR_POWER_DOWN;
Joe Perches1dc32912008-07-11 15:17:08 -0700465 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +0000466 msleep(1);
Auke Kok79f05bf2006-06-27 09:06:32 -0700467 }
Bruce Allan61c25052006-09-27 12:53:54 -0700468out:
469 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700470}
471
Jesse Brandeburga4010af2011-10-05 07:24:41 +0000472static void e1000_down_and_stop(struct e1000_adapter *adapter)
473{
474 set_bit(__E1000_DOWN, &adapter->flags);
Tushar Dave8ce69092012-05-17 01:04:50 +0000475
Vladimir Davydov74a1b1e2013-11-23 07:18:01 +0000476 cancel_delayed_work_sync(&adapter->watchdog_task);
477
478 /*
479 * Since the watchdog task can reschedule other tasks, we should cancel
480 * it first, otherwise we can run into the situation when a work is
481 * still running after the adapter has been turned down.
482 */
483
484 cancel_delayed_work_sync(&adapter->phy_info_task);
485 cancel_delayed_work_sync(&adapter->fifo_stall_task);
486
Tushar Dave8ce69092012-05-17 01:04:50 +0000487 /* Only kill reset task if adapter is not resetting */
488 if (!test_bit(__E1000_RESETTING, &adapter->flags))
489 cancel_work_sync(&adapter->reset_task);
Jesse Brandeburga4010af2011-10-05 07:24:41 +0000490}
491
Joe Perches64798842008-07-11 15:17:02 -0700492void e1000_down(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Jesse Brandeburga6c42322009-03-25 21:59:22 +0000494 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 struct net_device *netdev = adapter->netdev;
Jesse Brandeburga6c42322009-03-25 21:59:22 +0000496 u32 rctl, tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Jesse Brandeburga6c42322009-03-25 21:59:22 +0000498 /* disable receives in the hardware */
499 rctl = er32(RCTL);
500 ew32(RCTL, rctl & ~E1000_RCTL_EN);
501 /* flush and sleep below */
502
Jesse Brandeburg51851072009-09-25 12:17:01 +0000503 netif_tx_disable(netdev);
Jesse Brandeburga6c42322009-03-25 21:59:22 +0000504
505 /* disable transmits in the hardware */
506 tctl = er32(TCTL);
507 tctl &= ~E1000_TCTL_EN;
508 ew32(TCTL, tctl);
509 /* flush both disables and wait for them to finish */
510 E1000_WRITE_FLUSH();
511 msleep(10);
512
Vincenzo Maffione44c445c2017-09-16 18:00:00 +0200513 /* Set the carrier off after transmits have been disabled in the
514 * hardware, to avoid race conditions with e1000_watchdog() (which
515 * may be running concurrently to us, checking for the carrier
516 * bit to decide whether it should enable transmits again). Such
517 * a race condition would result into transmission being disabled
518 * in the hardware until the next IFF_DOWN+IFF_UP cycle.
519 */
520 netif_carrier_off(netdev);
521
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700522 napi_disable(&adapter->napi);
Francois Romieuc3570ac2008-07-11 15:17:38 -0700523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800525
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000526 /* Setting DOWN must be after irq_disable to prevent
Anupam Chandaab088532010-11-21 09:54:21 -0800527 * a screaming interrupt. Setting DOWN also prevents
Jesse Brandeburga4010af2011-10-05 07:24:41 +0000528 * tasks from rescheduling.
Anupam Chandaab088532010-11-21 09:54:21 -0800529 */
Jesse Brandeburga4010af2011-10-05 07:24:41 +0000530 e1000_down_and_stop(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 adapter->link_speed = 0;
533 adapter->link_duplex = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400536 e1000_clean_all_tx_rings(adapter);
537 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Joe Perches64798842008-07-11 15:17:02 -0700540void e1000_reinit_locked(struct e1000_adapter *adapter)
Auke Kok2db10a02006-06-27 09:06:28 -0700541{
542 WARN_ON(in_interrupt());
543 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
544 msleep(1);
545 e1000_down(adapter);
546 e1000_up(adapter);
547 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
549
Joe Perches64798842008-07-11 15:17:02 -0700550void e1000_reset(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Joe Perches1dc32912008-07-11 15:17:08 -0700552 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700553 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
Joe Perchesc3033b02008-03-21 11:06:25 -0700554 bool legacy_pba_adjust = false;
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000555 u16 hwm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 /* Repartition Pba for greater than 9k mtu
558 * To take effect CTRL.RST is required.
559 */
560
Joe Perches1dc32912008-07-11 15:17:08 -0700561 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100562 case e1000_82542_rev2_0:
563 case e1000_82542_rev2_1:
564 case e1000_82543:
565 case e1000_82544:
566 case e1000_82540:
567 case e1000_82541:
568 case e1000_82541_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700569 legacy_pba_adjust = true;
Bruce Allan018ea442006-12-15 10:39:45 +0100570 pba = E1000_PBA_48K;
571 break;
572 case e1000_82545:
573 case e1000_82545_rev_3:
574 case e1000_82546:
Dirk Brandewie5377a412011-01-06 14:29:54 +0000575 case e1000_ce4100:
Bruce Allan018ea442006-12-15 10:39:45 +0100576 case e1000_82546_rev_3:
577 pba = E1000_PBA_48K;
578 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700579 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700580 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700581 legacy_pba_adjust = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700582 pba = E1000_PBA_30K;
583 break;
Bruce Allan018ea442006-12-15 10:39:45 +0100584 case e1000_undefined:
585 case e1000_num_macs:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700586 break;
587 }
588
Joe Perchesc3033b02008-03-21 11:06:25 -0700589 if (legacy_pba_adjust) {
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000590 if (hw->max_frame_size > E1000_RXBUFFER_8192)
Bruce Allan018ea442006-12-15 10:39:45 +0100591 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700592
Joe Perches1dc32912008-07-11 15:17:08 -0700593 if (hw->mac_type == e1000_82547) {
Bruce Allan018ea442006-12-15 10:39:45 +0100594 adapter->tx_fifo_head = 0;
595 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
596 adapter->tx_fifo_size =
597 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
598 atomic_set(&adapter->tx_fifo_stall, 0);
599 }
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000600 } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan018ea442006-12-15 10:39:45 +0100601 /* adjust PBA for jumbo frames */
Joe Perches1dc32912008-07-11 15:17:08 -0700602 ew32(PBA, pba);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700603
Bruce Allan018ea442006-12-15 10:39:45 +0100604 /* To maintain wire speed transmits, the Tx FIFO should be
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000605 * large enough to accommodate two full transmit packets,
Bruce Allan018ea442006-12-15 10:39:45 +0100606 * rounded up to the next 1KB and expressed in KB. Likewise,
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000607 * the Rx FIFO should be large enough to accommodate at least
Bruce Allan018ea442006-12-15 10:39:45 +0100608 * one full receive packet and is similarly rounded up and
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000609 * expressed in KB.
610 */
Joe Perches1dc32912008-07-11 15:17:08 -0700611 pba = er32(PBA);
Bruce Allan018ea442006-12-15 10:39:45 +0100612 /* upper 16 bits has Tx packet buffer allocation size in KB */
613 tx_space = pba >> 16;
614 /* lower 16 bits has Rx packet buffer allocation size in KB */
615 pba &= 0xffff;
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000616 /* the Tx fifo also stores 16 bytes of information about the Tx
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000617 * but don't include ethernet FCS because hardware appends it
618 */
619 min_tx_space = (hw->max_frame_size +
Janusz Wolaka48954c2015-09-17 23:34:29 +0200620 sizeof(struct e1000_tx_desc) -
621 ETH_FCS_LEN) * 2;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700622 min_tx_space = ALIGN(min_tx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100623 min_tx_space >>= 10;
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000624 /* software strips receive CRC, so leave room for it */
625 min_rx_space = hw->max_frame_size;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700626 min_rx_space = ALIGN(min_rx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100627 min_rx_space >>= 10;
628
629 /* If current Tx allocation is less than the min Tx FIFO size,
630 * and the min Tx FIFO size is less than the current Rx FIFO
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000631 * allocation, take space away from current Rx allocation
632 */
Bruce Allan018ea442006-12-15 10:39:45 +0100633 if (tx_space < min_tx_space &&
634 ((min_tx_space - tx_space) < pba)) {
635 pba = pba - (min_tx_space - tx_space);
636
637 /* PCI/PCIx hardware has PBA alignment constraints */
Joe Perches1dc32912008-07-11 15:17:08 -0700638 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100639 case e1000_82545 ... e1000_82546_rev_3:
640 pba &= ~(E1000_PBA_8K - 1);
641 break;
642 default:
643 break;
644 }
645
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000646 /* if short on Rx space, Rx wins and must trump Tx
647 * adjustment or use Early Receive if available
648 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000649 if (pba < min_rx_space)
650 pba = min_rx_space;
Bruce Allan018ea442006-12-15 10:39:45 +0100651 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700653
Joe Perches1dc32912008-07-11 15:17:08 -0700654 ew32(PBA, pba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000656 /* flow control settings:
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000657 * The high water mark must be low enough to fit one full frame
658 * (or the size used for early receive) above it in the Rx FIFO.
659 * Set it to the lower of:
660 * - 90% of the Rx FIFO size, and
661 * - the full Rx FIFO size minus the early receive size (for parts
662 * with ERT support assuming ERT set to E1000_ERT_2048), or
663 * - the full Rx FIFO size minus one full frame
664 */
665 hwm = min(((pba << 10) * 9 / 10),
666 ((pba << 10) - hw->max_frame_size));
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800667
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000668 hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
669 hw->fc_low_water = hw->fc_high_water - 8;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +0000670 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
Joe Perches1dc32912008-07-11 15:17:08 -0700671 hw->fc_send_xon = 1;
672 hw->fc = hw->original_fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700674 /* Allow time for pending master requests to run */
Joe Perches1dc32912008-07-11 15:17:08 -0700675 e1000_reset_hw(hw);
676 if (hw->mac_type >= e1000_82544)
677 ew32(WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700678
Joe Perches1dc32912008-07-11 15:17:08 -0700679 if (e1000_init_hw(hw))
Emil Tantilovfeb8f472010-07-26 23:37:21 -0700680 e_dev_err("Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700681 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100682
683 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
Joe Perches1dc32912008-07-11 15:17:08 -0700684 if (hw->mac_type >= e1000_82544 &&
Joe Perches1dc32912008-07-11 15:17:08 -0700685 hw->autoneg == 1 &&
686 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
687 u32 ctrl = er32(CTRL);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100688 /* clear phy power management bit if we are in gig only mode,
689 * which if enabled will attempt negotiation to 100Mb, which
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000690 * can cause a loss of link at power off or driver unload
691 */
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100692 ctrl &= ~E1000_CTRL_SWDPIN3;
Joe Perches1dc32912008-07-11 15:17:08 -0700693 ew32(CTRL, ctrl);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100694 }
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
Joe Perches1dc32912008-07-11 15:17:08 -0700697 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Joe Perches1dc32912008-07-11 15:17:08 -0700699 e1000_reset_adaptive(hw);
700 e1000_phy_get_info(hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700701
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500702 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
Ben Hutchings1aa8b472012-07-10 10:56:59 +0000705/* Dump the eeprom for users having checksum issues */
Adrian Bunkb4ea8952008-02-01 08:21:28 -0800706static void e1000_dump_eeprom(struct e1000_adapter *adapter)
Auke Kok67b3c272007-12-17 13:50:23 -0800707{
708 struct net_device *netdev = adapter->netdev;
709 struct ethtool_eeprom eeprom;
710 const struct ethtool_ops *ops = netdev->ethtool_ops;
711 u8 *data;
712 int i;
713 u16 csum_old, csum_new = 0;
714
715 eeprom.len = ops->get_eeprom_len(netdev);
716 eeprom.offset = 0;
717
718 data = kmalloc(eeprom.len, GFP_KERNEL);
Joe Perchese404dec2012-01-29 12:56:23 +0000719 if (!data)
Auke Kok67b3c272007-12-17 13:50:23 -0800720 return;
Auke Kok67b3c272007-12-17 13:50:23 -0800721
722 ops->get_eeprom(netdev, &eeprom, data);
723
724 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
725 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
726 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
727 csum_new += data[i] + (data[i + 1] << 8);
728 csum_new = EEPROM_SUM - csum_new;
729
Emil Tantilov675ad472010-04-27 14:02:58 +0000730 pr_err("/*********************/\n");
731 pr_err("Current EEPROM Checksum : 0x%04x\n", csum_old);
732 pr_err("Calculated : 0x%04x\n", csum_new);
Auke Kok67b3c272007-12-17 13:50:23 -0800733
Emil Tantilov675ad472010-04-27 14:02:58 +0000734 pr_err("Offset Values\n");
735 pr_err("======== ======\n");
Auke Kok67b3c272007-12-17 13:50:23 -0800736 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
737
Emil Tantilov675ad472010-04-27 14:02:58 +0000738 pr_err("Include this output when contacting your support provider.\n");
739 pr_err("This is not a software error! Something bad happened to\n");
740 pr_err("your hardware or EEPROM image. Ignoring this problem could\n");
741 pr_err("result in further problems, possibly loss of data,\n");
742 pr_err("corruption or system hangs!\n");
743 pr_err("The MAC Address will be reset to 00:00:00:00:00:00,\n");
744 pr_err("which is invalid and requires you to set the proper MAC\n");
745 pr_err("address manually before continuing to enable this network\n");
746 pr_err("device. Please inspect the EEPROM dump and report the\n");
747 pr_err("issue to your hardware vendor or Intel Customer Support.\n");
748 pr_err("/*********************/\n");
Auke Kok67b3c272007-12-17 13:50:23 -0800749
750 kfree(data);
751}
752
753/**
Taku Izumi81250292008-07-11 15:17:44 -0700754 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
755 * @pdev: PCI device information struct
756 *
757 * Return true if an adapter needs ioport resources
758 **/
759static int e1000_is_need_ioport(struct pci_dev *pdev)
760{
761 switch (pdev->device) {
762 case E1000_DEV_ID_82540EM:
763 case E1000_DEV_ID_82540EM_LOM:
764 case E1000_DEV_ID_82540EP:
765 case E1000_DEV_ID_82540EP_LOM:
766 case E1000_DEV_ID_82540EP_LP:
767 case E1000_DEV_ID_82541EI:
768 case E1000_DEV_ID_82541EI_MOBILE:
769 case E1000_DEV_ID_82541ER:
770 case E1000_DEV_ID_82541ER_LOM:
771 case E1000_DEV_ID_82541GI:
772 case E1000_DEV_ID_82541GI_LF:
773 case E1000_DEV_ID_82541GI_MOBILE:
774 case E1000_DEV_ID_82544EI_COPPER:
775 case E1000_DEV_ID_82544EI_FIBER:
776 case E1000_DEV_ID_82544GC_COPPER:
777 case E1000_DEV_ID_82544GC_LOM:
778 case E1000_DEV_ID_82545EM_COPPER:
779 case E1000_DEV_ID_82545EM_FIBER:
780 case E1000_DEV_ID_82546EB_COPPER:
781 case E1000_DEV_ID_82546EB_FIBER:
782 case E1000_DEV_ID_82546EB_QUAD_COPPER:
783 return true;
784 default:
785 return false;
786 }
787}
788
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000789static netdev_features_t e1000_fix_features(struct net_device *netdev,
790 netdev_features_t features)
Jiri Pirko5622e402011-07-21 03:26:31 +0000791{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000792 /* Since there is no support for separate Rx/Tx vlan accel
793 * enable/disable make sure Tx flag is always in same state as Rx.
Jiri Pirko5622e402011-07-21 03:26:31 +0000794 */
Patrick McHardyf6469682013-04-19 02:04:27 +0000795 if (features & NETIF_F_HW_VLAN_CTAG_RX)
796 features |= NETIF_F_HW_VLAN_CTAG_TX;
Jiri Pirko5622e402011-07-21 03:26:31 +0000797 else
Patrick McHardyf6469682013-04-19 02:04:27 +0000798 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
Jiri Pirko5622e402011-07-21 03:26:31 +0000799
800 return features;
801}
802
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000803static int e1000_set_features(struct net_device *netdev,
804 netdev_features_t features)
Michał Mirosławe97d3202011-06-08 08:36:42 +0000805{
806 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000807 netdev_features_t changed = features ^ netdev->features;
Michał Mirosławe97d3202011-06-08 08:36:42 +0000808
Patrick McHardyf6469682013-04-19 02:04:27 +0000809 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
Jiri Pirko5622e402011-07-21 03:26:31 +0000810 e1000_vlan_mode(netdev, features);
811
Ben Greeare825b732012-04-04 06:01:29 +0000812 if (!(changed & (NETIF_F_RXCSUM | NETIF_F_RXALL)))
Michał Mirosławe97d3202011-06-08 08:36:42 +0000813 return 0;
814
Ben Greeare825b732012-04-04 06:01:29 +0000815 netdev->features = features;
Michał Mirosławe97d3202011-06-08 08:36:42 +0000816 adapter->rx_csum = !!(features & NETIF_F_RXCSUM);
817
818 if (netif_running(netdev))
819 e1000_reinit_locked(adapter);
820 else
821 e1000_reset(adapter);
822
823 return 0;
824}
825
Stephen Hemminger0e7614b2008-11-19 22:18:22 -0800826static const struct net_device_ops e1000_netdev_ops = {
827 .ndo_open = e1000_open,
828 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -0800829 .ndo_start_xmit = e1000_xmit_frame,
Stephen Hemminger0e7614b2008-11-19 22:18:22 -0800830 .ndo_set_rx_mode = e1000_set_rx_mode,
831 .ndo_set_mac_address = e1000_set_mac,
Jiri Pirko5622e402011-07-21 03:26:31 +0000832 .ndo_tx_timeout = e1000_tx_timeout,
Stephen Hemminger0e7614b2008-11-19 22:18:22 -0800833 .ndo_change_mtu = e1000_change_mtu,
834 .ndo_do_ioctl = e1000_ioctl,
835 .ndo_validate_addr = eth_validate_addr,
Stephen Hemminger0e7614b2008-11-19 22:18:22 -0800836 .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
Jiri Pirko5622e402011-07-21 03:26:31 +0000841 .ndo_fix_features = e1000_fix_features,
842 .ndo_set_features = e1000_set_features,
Stephen Hemminger0e7614b2008-11-19 22:18:22 -0800843};
844
Taku Izumi81250292008-07-11 15:17:44 -0700845/**
Jesse Brandeburge508be12010-09-07 21:01:12 +0000846 * e1000_init_hw_struct - initialize members of hw struct
847 * @adapter: board private struct
848 * @hw: structure used by e1000_hw.c
849 *
850 * Factors out initialization of the e1000_hw struct to its own function
851 * that can be called very early at init (just after struct allocation).
852 * Fields are initialized based on PCI device information and
853 * OS network device settings (MTU size).
854 * Returns negative error codes if MAC type setup fails.
855 */
856static int e1000_init_hw_struct(struct e1000_adapter *adapter,
857 struct e1000_hw *hw)
858{
859 struct pci_dev *pdev = adapter->pdev;
860
861 /* PCI config space info */
862 hw->vendor_id = pdev->vendor;
863 hw->device_id = pdev->device;
864 hw->subsystem_vendor_id = pdev->subsystem_vendor;
865 hw->subsystem_id = pdev->subsystem_device;
866 hw->revision_id = pdev->revision;
867
868 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
869
870 hw->max_frame_size = adapter->netdev->mtu +
871 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
872 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
873
874 /* identify the MAC */
875 if (e1000_set_mac_type(hw)) {
876 e_err(probe, "Unknown MAC Type\n");
877 return -EIO;
878 }
879
880 switch (hw->mac_type) {
881 default:
882 break;
883 case e1000_82541:
884 case e1000_82547:
885 case e1000_82541_rev_2:
886 case e1000_82547_rev_2:
887 hw->phy_init_script = 1;
888 break;
889 }
890
891 e1000_set_media_type(hw);
892 e1000_get_bus_info(hw);
893
894 hw->wait_autoneg_complete = false;
895 hw->tbi_compatibility_en = true;
896 hw->adaptive_ifs = true;
897
898 /* Copper options */
899
900 if (hw->media_type == e1000_media_type_copper) {
901 hw->mdix = AUTO_ALL_MODES;
902 hw->disable_polarity_correction = false;
903 hw->master_slave = E1000_MASTER_SLAVE;
904 }
905
906 return 0;
907}
908
909/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 * e1000_probe - Device Initialization Routine
911 * @pdev: PCI device information struct
912 * @ent: entry in e1000_pci_tbl
913 *
914 * Returns 0 on success, negative on failure
915 *
916 * e1000_probe initializes an adapter identified by a pci_dev structure.
917 * The OS initialization, configuring of the adapter private structure,
918 * and a hardware reset occur.
919 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000920static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
922 struct net_device *netdev;
Tushar Dave0b76aae2017-12-06 02:26:29 +0530923 struct e1000_adapter *adapter = NULL;
Joe Perches1dc32912008-07-11 15:17:08 -0700924 struct e1000_hw *hw;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700925
Janusz Wolaka48954c2015-09-17 23:34:29 +0200926 static int cards_found;
927 static int global_quad_port_a; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700928 int i, err, pci_using_dac;
Joe Perches406874a2008-04-03 10:06:32 -0700929 u16 eeprom_data = 0;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000930 u16 tmp = 0;
Joe Perches406874a2008-04-03 10:06:32 -0700931 u16 eeprom_apme_mask = E1000_EEPROM_APME;
Taku Izumi81250292008-07-11 15:17:44 -0700932 int bars, need_ioport;
Tushar Dave0b76aae2017-12-06 02:26:29 +0530933 bool disable_dev = false;
Joe Perches0795af52007-10-03 17:59:30 -0700934
Taku Izumi81250292008-07-11 15:17:44 -0700935 /* do not allocate ioport bars when not needed */
936 need_ioport = e1000_is_need_ioport(pdev);
937 if (need_ioport) {
938 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
939 err = pci_enable_device(pdev);
940 } else {
941 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Karsten Keil4d7155b2009-02-03 15:18:01 -0800942 err = pci_enable_device_mem(pdev);
Taku Izumi81250292008-07-11 15:17:44 -0700943 }
Joe Perchesc7be73b2008-07-11 15:17:28 -0700944 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 return err;
946
Taku Izumi81250292008-07-11 15:17:44 -0700947 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
Joe Perchesc7be73b2008-07-11 15:17:28 -0700948 if (err)
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700949 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 pci_set_master(pdev);
Nick Nunleydbb5aae2010-02-03 14:49:48 +0000952 err = pci_save_state(pdev);
953 if (err)
954 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700956 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700958 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 SET_NETDEV_DEV(netdev, &pdev->dev);
962
963 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700964 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 adapter->netdev = netdev;
966 adapter->pdev = pdev;
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000967 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Taku Izumi81250292008-07-11 15:17:44 -0700968 adapter->bars = bars;
969 adapter->need_ioport = need_ioport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Joe Perches1dc32912008-07-11 15:17:08 -0700971 hw = &adapter->hw;
972 hw->back = adapter;
973
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700974 err = -EIO;
Arjan van de Ven275f1652008-10-20 21:42:39 -0700975 hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
Joe Perches1dc32912008-07-11 15:17:08 -0700976 if (!hw->hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Taku Izumi81250292008-07-11 15:17:44 -0700979 if (adapter->need_ioport) {
980 for (i = BAR_1; i <= BAR_5; i++) {
981 if (pci_resource_len(pdev, i) == 0)
982 continue;
983 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
984 hw->io_base = pci_resource_start(pdev, i);
985 break;
986 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 }
988 }
989
Jesse Brandeburge508be12010-09-07 21:01:12 +0000990 /* make ready for any if (hw->...) below */
991 err = e1000_init_hw_struct(adapter, hw);
992 if (err)
993 goto err_sw_init;
994
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000995 /* there is a workaround being applied below that limits
Jesse Brandeburge508be12010-09-07 21:01:12 +0000996 * 64-bit DMA addresses to 64-bit hardware. There are some
997 * 32-bit adapters that Tx hang when given 64-bit DMA addresses
998 */
999 pci_using_dac = 0;
1000 if ((hw->bus_type == e1000_bus_type_pcix) &&
Russell King9931a262013-06-26 23:49:11 +01001001 !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Jesse Brandeburge508be12010-09-07 21:01:12 +00001002 pci_using_dac = 1;
Jesse Brandeburge508be12010-09-07 21:01:12 +00001003 } else {
Russell King9931a262013-06-26 23:49:11 +01001004 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Dean Nelson19a0b672010-11-11 05:50:25 +00001005 if (err) {
1006 pr_err("No usable DMA config, aborting\n");
1007 goto err_dma;
1008 }
Jesse Brandeburge508be12010-09-07 21:01:12 +00001009 }
1010
Stephen Hemminger0e7614b2008-11-19 22:18:22 -08001011 netdev->netdev_ops = &e1000_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 e1000_set_ethtool_ops(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 netdev->watchdog_timeo = 5 * HZ;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001014 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Stephen Hemminger0e7614b2008-11-19 22:18:22 -08001015
Auke Kok0eb5a342006-09-27 12:53:17 -07001016 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 adapter->bd_number = cards_found;
1019
1020 /* setup the private structure */
1021
Joe Perchesc7be73b2008-07-11 15:17:28 -07001022 err = e1000_sw_init(adapter);
1023 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 goto err_sw_init;
1025
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001026 err = -EIO;
Dirk Brandewie5377a412011-01-06 14:29:54 +00001027 if (hw->mac_type == e1000_ce4100) {
Florian Fainelli13acde82012-01-04 20:23:35 +00001028 hw->ce4100_gbe_mdio_base_virt =
1029 ioremap(pci_resource_start(pdev, BAR_1),
Janusz Wolaka48954c2015-09-17 23:34:29 +02001030 pci_resource_len(pdev, BAR_1));
Dirk Brandewie5377a412011-01-06 14:29:54 +00001031
Florian Fainelli13acde82012-01-04 20:23:35 +00001032 if (!hw->ce4100_gbe_mdio_base_virt)
Dirk Brandewie5377a412011-01-06 14:29:54 +00001033 goto err_mdio_ioremap;
1034 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001035
Joe Perches1dc32912008-07-11 15:17:08 -07001036 if (hw->mac_type >= e1000_82543) {
Michał Mirosławe97d3202011-06-08 08:36:42 +00001037 netdev->hw_features = NETIF_F_SG |
Jiri Pirko5622e402011-07-21 03:26:31 +00001038 NETIF_F_HW_CSUM |
Patrick McHardyf6469682013-04-19 02:04:27 +00001039 NETIF_F_HW_VLAN_CTAG_RX;
1040 netdev->features = NETIF_F_HW_VLAN_CTAG_TX |
1041 NETIF_F_HW_VLAN_CTAG_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043
Joe Perches1dc32912008-07-11 15:17:08 -07001044 if ((hw->mac_type >= e1000_82544) &&
1045 (hw->mac_type != e1000_82547))
Michał Mirosławe97d3202011-06-08 08:36:42 +00001046 netdev->hw_features |= NETIF_F_TSO;
1047
Ben Greear11a78dc2012-02-11 15:40:01 +00001048 netdev->priv_flags |= IFF_SUPP_NOFCS;
1049
Michał Mirosławe97d3202011-06-08 08:36:42 +00001050 netdev->features |= netdev->hw_features;
Tushar Dave75006732012-06-12 13:03:29 +00001051 netdev->hw_features |= (NETIF_F_RXCSUM |
1052 NETIF_F_RXALL |
1053 NETIF_F_RXFCS);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001054
Yi Zou7b872a52010-09-22 17:57:58 +00001055 if (pci_using_dac) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00001057 netdev->vlan_features |= NETIF_F_HIGHDMA;
1058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Tushar Dave75006732012-06-12 13:03:29 +00001060 netdev->vlan_features |= (NETIF_F_TSO |
1061 NETIF_F_HW_CSUM |
1062 NETIF_F_SG);
Patrick McHardy20501a62008-10-11 12:25:59 -07001063
Francesco Ruggeria22bb0b2014-10-22 15:29:24 +00001064 /* Do not set IFF_UNICAST_FLT for VMWare's 82545EM */
1065 if (hw->device_id != E1000_DEV_ID_82545EM_COPPER ||
1066 hw->subsystem_vendor_id != PCI_VENDOR_ID_VMWARE)
1067 netdev->priv_flags |= IFF_UNICAST_FLT;
Jiri Pirko01789342011-08-16 06:29:00 +00001068
Jarod Wilson91c527a2016-10-17 15:54:05 -04001069 /* MTU range: 46 - 16110 */
1070 netdev->min_mtu = ETH_ZLEN - ETH_HLEN;
1071 netdev->max_mtu = MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
1072
Joe Perches1dc32912008-07-11 15:17:08 -07001073 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001074
Auke Kokcd94dd02006-06-27 09:08:22 -07001075 /* initialize eeprom parameters */
Joe Perches1dc32912008-07-11 15:17:08 -07001076 if (e1000_init_eeprom_params(hw)) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001077 e_err(probe, "EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001078 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001079 }
1080
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001081 /* before reading the EEPROM, reset the controller to
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001082 * put the device in a known good starting state
1083 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001084
Joe Perches1dc32912008-07-11 15:17:08 -07001085 e1000_reset_hw(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 /* make sure the EEPROM is good */
Joe Perches1dc32912008-07-11 15:17:08 -07001088 if (e1000_validate_eeprom_checksum(hw) < 0) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001089 e_err(probe, "The EEPROM Checksum Is Not Valid\n");
Auke Kok67b3c272007-12-17 13:50:23 -08001090 e1000_dump_eeprom(adapter);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001091 /* set MAC address to all zeroes to invalidate and temporary
Auke Kok67b3c272007-12-17 13:50:23 -08001092 * disable this device for the user. This blocks regular
1093 * traffic while still permitting ethtool ioctls from reaching
1094 * the hardware as well as allowing the user to run the
1095 * interface after manually setting a hw addr using
1096 * `ip set address`
1097 */
Joe Perches1dc32912008-07-11 15:17:08 -07001098 memset(hw->mac_addr, 0, netdev->addr_len);
Auke Kok67b3c272007-12-17 13:50:23 -08001099 } else {
1100 /* copy the MAC address out of the EEPROM */
Joe Perches1dc32912008-07-11 15:17:08 -07001101 if (e1000_read_mac_addr(hw))
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001102 e_err(probe, "EEPROM Read Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 }
Joe Perchesdbedd442015-03-06 20:49:12 -08001104 /* don't block initialization here due to bad MAC address */
Joe Perches1dc32912008-07-11 15:17:08 -07001105 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00001107 if (!is_valid_ether_addr(netdev->dev_addr))
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001108 e_err(probe, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
Jesse Brandeburga4010af2011-10-05 07:24:41 +00001111 INIT_DELAYED_WORK(&adapter->watchdog_task, e1000_watchdog);
1112 INIT_DELAYED_WORK(&adapter->fifo_stall_task,
1113 e1000_82547_tx_fifo_stall_task);
1114 INIT_DELAYED_WORK(&adapter->phy_info_task, e1000_update_phy_info_task);
David Howells65f27f32006-11-22 14:55:48 +00001115 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 e1000_check_options(adapter);
1118
1119 /* Initial Wake on LAN setting
1120 * If APM wake is enabled in the EEPROM,
1121 * enable the ACPI Magic Packet filter
1122 */
1123
Joe Perches1dc32912008-07-11 15:17:08 -07001124 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 case e1000_82542_rev2_0:
1126 case e1000_82542_rev2_1:
1127 case e1000_82543:
1128 break;
1129 case e1000_82544:
Joe Perches1dc32912008-07-11 15:17:08 -07001130 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1132 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1133 break;
1134 case e1000_82546:
1135 case e1000_82546_rev_3:
Janusz Wolaka48954c2015-09-17 23:34:29 +02001136 if (er32(STATUS) & E1000_STATUS_FUNC_1) {
Joe Perches1dc32912008-07-11 15:17:08 -07001137 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1139 break;
1140 }
1141 /* Fall Through */
1142 default:
Joe Perches1dc32912008-07-11 15:17:08 -07001143 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1145 break;
1146 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001147 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001148 adapter->eeprom_wol |= E1000_WUFC_MAG;
1149
1150 /* now that we have the eeprom settings, apply the special cases
1151 * where the eeprom may be wrong or the board simply won't support
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001152 * wake on lan on a particular port
1153 */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001154 switch (pdev->device) {
1155 case E1000_DEV_ID_82546GB_PCIE:
1156 adapter->eeprom_wol = 0;
1157 break;
1158 case E1000_DEV_ID_82546EB_FIBER:
1159 case E1000_DEV_ID_82546GB_FIBER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001160 /* Wake events only supported on port A for dual fiber
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001161 * regardless of eeprom setting
1162 */
Joe Perches1dc32912008-07-11 15:17:08 -07001163 if (er32(STATUS) & E1000_STATUS_FUNC_1)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001164 adapter->eeprom_wol = 0;
1165 break;
1166 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1167 /* if quad port adapter, disable WoL on all but port A */
1168 if (global_quad_port_a != 0)
1169 adapter->eeprom_wol = 0;
1170 else
Rusty Russell3db1cd52011-12-19 13:56:45 +00001171 adapter->quad_port_a = true;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001172 /* Reset for multiple quad port adapters */
1173 if (++global_quad_port_a == 4)
1174 global_quad_port_a = 0;
1175 break;
1176 }
1177
1178 /* initialize the wol settings based on the eeprom settings */
1179 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\de126482008-11-07 20:30:19 +00001180 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
Dirk Brandewie5377a412011-01-06 14:29:54 +00001182 /* Auto detect PHY address */
1183 if (hw->mac_type == e1000_ce4100) {
1184 for (i = 0; i < 32; i++) {
1185 hw->phy_addr = i;
1186 e1000_read_phy_reg(hw, PHY_ID2, &tmp);
Jean Sacren4e01f3a2015-09-19 05:08:40 -06001187
1188 if (tmp != 0 && tmp != 0xFF)
Dirk Brandewie5377a412011-01-06 14:29:54 +00001189 break;
1190 }
Jean Sacren4e01f3a2015-09-19 05:08:40 -06001191
1192 if (i >= 32)
1193 goto err_eeprom;
Dirk Brandewie5377a412011-01-06 14:29:54 +00001194 }
1195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 /* reset the hardware with the new settings */
1197 e1000_reset(adapter);
1198
Auke Kok416b5d12007-06-01 10:22:39 -07001199 strcpy(netdev->name, "eth%d");
Joe Perchesc7be73b2008-07-11 15:17:28 -07001200 err = register_netdev(netdev);
1201 if (err)
Auke Kok416b5d12007-06-01 10:22:39 -07001202 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001203
Jiri Pirko52f55092012-03-20 18:10:01 +00001204 e1000_vlan_filter_on_off(adapter, false);
Jiri Pirko5622e402011-07-21 03:26:31 +00001205
Emil Tantilov675ad472010-04-27 14:02:58 +00001206 /* print bus type/speed/width info */
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001207 e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n",
Joe Perches7837e582010-06-11 12:51:49 +00001208 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""),
1209 ((hw->bus_speed == e1000_bus_speed_133) ? 133 :
1210 (hw->bus_speed == e1000_bus_speed_120) ? 120 :
1211 (hw->bus_speed == e1000_bus_speed_100) ? 100 :
1212 (hw->bus_speed == e1000_bus_speed_66) ? 66 : 33),
1213 ((hw->bus_width == e1000_bus_width_64) ? 64 : 32),
1214 netdev->dev_addr);
Emil Tantilov675ad472010-04-27 14:02:58 +00001215
Jesse Brandeburgeb62efd2009-04-17 20:44:36 +00001216 /* carrier off reporting is important to ethtool even BEFORE open */
1217 netif_carrier_off(netdev);
1218
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001219 e_info(probe, "Intel(R) PRO/1000 Network Connection\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 cards_found++;
1222 return 0;
1223
1224err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001225err_eeprom:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001226 e1000_phy_hw_reset(hw);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001227
Joe Perches1dc32912008-07-11 15:17:08 -07001228 if (hw->flash_address)
1229 iounmap(hw->flash_address);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001230 kfree(adapter->tx_ring);
1231 kfree(adapter->rx_ring);
Jesse Brandeburge508be12010-09-07 21:01:12 +00001232err_dma:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233err_sw_init:
Dirk Brandewie5377a412011-01-06 14:29:54 +00001234err_mdio_ioremap:
Florian Fainelli13acde82012-01-04 20:23:35 +00001235 iounmap(hw->ce4100_gbe_mdio_base_virt);
Joe Perches1dc32912008-07-11 15:17:08 -07001236 iounmap(hw->hw_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237err_ioremap:
Tushar Dave0b76aae2017-12-06 02:26:29 +05301238 disable_dev = !test_and_set_bit(__E1000_DISABLED, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 free_netdev(netdev);
1240err_alloc_etherdev:
Taku Izumi81250292008-07-11 15:17:44 -07001241 pci_release_selected_regions(pdev, bars);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001242err_pci_reg:
Tushar Dave0b76aae2017-12-06 02:26:29 +05301243 if (!adapter || disable_dev)
1244 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 return err;
1246}
1247
1248/**
1249 * e1000_remove - Device Removal Routine
1250 * @pdev: PCI device information struct
1251 *
1252 * e1000_remove is called by the PCI subsystem to alert the driver
Jean Sacrenb6fad9f2015-09-19 05:08:41 -06001253 * that it should release a PCI device. That could be caused by a
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 * Hot-Plug event, or because the driver is going to be removed from
1255 * memory.
1256 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05001257static void e1000_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
1259 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001260 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001261 struct e1000_hw *hw = &adapter->hw;
Tushar Dave0b76aae2017-12-06 02:26:29 +05301262 bool disable_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Jesse Brandeburga4010af2011-10-05 07:24:41 +00001264 e1000_down_and_stop(adapter);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001265 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001267 unregister_netdev(netdev);
1268
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001269 e1000_phy_hw_reset(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001271 kfree(adapter->tx_ring);
1272 kfree(adapter->rx_ring);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001273
Florian Fainelli1c267502012-01-04 20:23:34 +00001274 if (hw->mac_type == e1000_ce4100)
Florian Fainelli13acde82012-01-04 20:23:35 +00001275 iounmap(hw->ce4100_gbe_mdio_base_virt);
Joe Perches1dc32912008-07-11 15:17:08 -07001276 iounmap(hw->hw_addr);
1277 if (hw->flash_address)
1278 iounmap(hw->flash_address);
Taku Izumi81250292008-07-11 15:17:44 -07001279 pci_release_selected_regions(pdev, adapter->bars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Tushar Dave0b76aae2017-12-06 02:26:29 +05301281 disable_dev = !test_and_set_bit(__E1000_DISABLED, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 free_netdev(netdev);
1283
Tushar Dave0b76aae2017-12-06 02:26:29 +05301284 if (disable_dev)
1285 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286}
1287
1288/**
1289 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1290 * @adapter: board private structure to initialize
1291 *
1292 * e1000_sw_init initializes the Adapter private data structure.
Jesse Brandeburge508be12010-09-07 21:01:12 +00001293 * e1000_init_hw_struct MUST be called before this function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05001295static int e1000_sw_init(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296{
Auke Kokeb0f8052006-07-14 16:14:48 -07001297 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001299 adapter->num_tx_queues = 1;
1300 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001301
1302 if (e1000_alloc_queues(adapter)) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001303 e_err(probe, "Unable to allocate memory for queues\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001304 return -ENOMEM;
1305 }
1306
Herbert Xu47313052007-05-29 15:07:31 -07001307 /* Explicitly disable IRQ since the NIC can be in any state. */
Herbert Xu47313052007-05-29 15:07:31 -07001308 e1000_irq_disable(adapter);
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Auke Kok1314bbf2006-09-27 12:54:02 -07001312 set_bit(__E1000_DOWN, &adapter->flags);
1313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 return 0;
1315}
1316
1317/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001318 * e1000_alloc_queues - Allocate memory for all rings
1319 * @adapter: board private structure to initialize
1320 *
1321 * We allocate one ring per queue at run-time since we don't know the
Wang Chen3e1d7cd2008-12-03 22:07:10 -08001322 * number of queues at compile-time.
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001323 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05001324static int e1000_alloc_queues(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001325{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001326 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Janusz Wolaka48954c2015-09-17 23:34:29 +02001327 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001328 if (!adapter->tx_ring)
1329 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001330
Yan Burman1c7e5b12007-03-06 08:58:04 -08001331 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Janusz Wolaka48954c2015-09-17 23:34:29 +02001332 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001333 if (!adapter->rx_ring) {
1334 kfree(adapter->tx_ring);
1335 return -ENOMEM;
1336 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001337
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001338 return E1000_SUCCESS;
1339}
1340
1341/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 * e1000_open - Called when a network interface is made active
1343 * @netdev: network interface device structure
1344 *
1345 * Returns 0 on success, negative value on failure
1346 *
1347 * The open entry point is called when a network interface is made
1348 * active by the system (IFF_UP). At this point all resources needed
1349 * for transmit and receive operations are allocated, the interrupt
Jesse Brandeburga4010af2011-10-05 07:24:41 +00001350 * handler is registered with the OS, the watchdog task is started,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 * and the stack is notified that the interface is ready.
1352 **/
Stefan Assmann1f2f83f2016-02-03 09:20:51 +01001353int e1000_open(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001355 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001356 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 int err;
1358
Auke Kok2db10a02006-06-27 09:06:28 -07001359 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001360 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001361 return -EBUSY;
1362
Jesse Brandeburgeb62efd2009-04-17 20:44:36 +00001363 netif_carrier_off(netdev);
1364
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001366 err = e1000_setup_all_tx_resources(adapter);
1367 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 goto err_setup_tx;
1369
1370 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001371 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001372 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001373 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001374
Auke Kok79f05bf2006-06-27 09:06:32 -07001375 e1000_power_up_phy(adapter);
1376
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001377 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Joe Perches1dc32912008-07-11 15:17:08 -07001378 if ((hw->mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001379 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1380 e1000_update_mng_vlan(adapter);
1381 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Auke Koke0aac5a2007-03-06 08:57:21 -08001383 /* before we allocate an interrupt, we must be ready to handle it.
1384 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1385 * as soon as we call pci_request_irq, so we have to setup our
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001386 * clean_rx handler before we do so.
1387 */
Auke Koke0aac5a2007-03-06 08:57:21 -08001388 e1000_configure(adapter);
1389
1390 err = e1000_request_irq(adapter);
1391 if (err)
1392 goto err_req_irq;
1393
1394 /* From here on the code is the same as e1000_up() */
1395 clear_bit(__E1000_DOWN, &adapter->flags);
1396
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001397 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001398
Auke Koke0aac5a2007-03-06 08:57:21 -08001399 e1000_irq_enable(adapter);
1400
Ben Hutchings076152d2008-07-18 17:50:57 -07001401 netif_start_queue(netdev);
1402
Auke Koke0aac5a2007-03-06 08:57:21 -08001403 /* fire a link status change interrupt to start the watchdog */
Joe Perches1dc32912008-07-11 15:17:08 -07001404 ew32(ICS, E1000_ICS_LSC);
Auke Koke0aac5a2007-03-06 08:57:21 -08001405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 return E1000_SUCCESS;
1407
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001408err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001409 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001410 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001412 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413err_setup_tx:
1414 e1000_reset(adapter);
1415
1416 return err;
1417}
1418
1419/**
1420 * e1000_close - Disables a network interface
1421 * @netdev: network interface device structure
1422 *
1423 * Returns 0, this is not allowed to fail
1424 *
1425 * The close entry point is called when an interface is de-activated
1426 * by the OS. The hardware is still under the drivers control, but
1427 * needs to be disabled. A global MAC reset is issued to stop the
1428 * hardware, and all transmit and receive resources are freed.
1429 **/
Stefan Assmann1f2f83f2016-02-03 09:20:51 +01001430int e1000_close(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001432 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001433 struct e1000_hw *hw = &adapter->hw;
yzhu16a7d64e2013-11-23 07:07:40 +00001434 int count = E1000_CHECK_RESET_COUNT;
1435
1436 while (test_bit(__E1000_RESETTING, &adapter->flags) && count--)
1437 usleep_range(10000, 20000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Auke Kok2db10a02006-06-27 09:06:28 -07001439 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001441 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001442 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001444 e1000_free_all_tx_resources(adapter);
1445 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Bruce Allan46665602006-09-27 12:54:08 -07001447 /* kill manageability vlan ID if supported, but not if a vlan with
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001448 * the same ID is registered on the host OS (let 8021q kill it)
1449 */
Joe Perches1dc32912008-07-11 15:17:08 -07001450 if ((hw->mng_cookie.status &
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001451 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1452 !test_bit(adapter->mng_vlan_id, adapter->active_vlans)) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00001453 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
1454 adapter->mng_vlan_id);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001455 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001456
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 return 0;
1458}
1459
1460/**
1461 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1462 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001463 * @start: address of beginning of memory
1464 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 **/
Joe Perches64798842008-07-11 15:17:02 -07001466static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1467 unsigned long len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
Joe Perches1dc32912008-07-11 15:17:08 -07001469 struct e1000_hw *hw = &adapter->hw;
Joe Perchese982f172008-07-11 15:17:18 -07001470 unsigned long begin = (unsigned long)start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 unsigned long end = begin + len;
1472
Malli Chilakala26483452005-04-28 19:44:46 -07001473 /* First rev 82545 and 82546 need to not allow any memory
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001474 * write location to cross 64k boundary due to errata 23
1475 */
Joe Perches1dc32912008-07-11 15:17:08 -07001476 if (hw->mac_type == e1000_82545 ||
Dirk Brandewie5377a412011-01-06 14:29:54 +00001477 hw->mac_type == e1000_ce4100 ||
Joe Perches1dc32912008-07-11 15:17:08 -07001478 hw->mac_type == e1000_82546) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001479 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 }
1481
Joe Perchesc3033b02008-03-21 11:06:25 -07001482 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483}
1484
1485/**
1486 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1487 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001488 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 *
1490 * Return 0 on success, negative on failure
1491 **/
Joe Perches64798842008-07-11 15:17:02 -07001492static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1493 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 struct pci_dev *pdev = adapter->pdev;
1496 int size;
1497
Florian Westphal580f3212014-09-03 13:34:31 +00001498 size = sizeof(struct e1000_tx_buffer) * txdr->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001499 txdr->buffer_info = vzalloc(size);
Joe Perches14f8dc42013-02-07 11:46:27 +00001500 if (!txdr->buffer_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
1503 /* round up to nearest 4K */
1504
1505 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001506 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001508 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
1509 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001510 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 vfree(txdr->buffer_info);
1513 return -ENOMEM;
1514 }
1515
Malli Chilakala26483452005-04-28 19:44:46 -07001516 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1518 void *olddesc = txdr->desc;
1519 dma_addr_t olddma = txdr->dma;
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001520 e_err(tx_err, "txdr align check failed: %u bytes at %p\n",
Emil Tantilov675ad472010-04-27 14:02:58 +00001521 txdr->size, txdr->desc);
Malli Chilakala26483452005-04-28 19:44:46 -07001522 /* Try again, without freeing the previous */
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001523 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size,
1524 &txdr->dma, GFP_KERNEL);
Malli Chilakala26483452005-04-28 19:44:46 -07001525 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001526 if (!txdr->desc) {
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001527 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1528 olddma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 goto setup_tx_desc_die;
1530 }
1531
1532 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1533 /* give up */
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001534 dma_free_coherent(&pdev->dev, txdr->size, txdr->desc,
1535 txdr->dma);
1536 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1537 olddma);
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001538 e_err(probe, "Unable to allocate aligned memory "
Emil Tantilov675ad472010-04-27 14:02:58 +00001539 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 vfree(txdr->buffer_info);
1541 return -ENOMEM;
1542 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001543 /* Free old allocation, new allocation was successful */
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001544 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1545 olddma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 }
1547 }
1548 memset(txdr->desc, 0, txdr->size);
1549
1550 txdr->next_to_use = 0;
1551 txdr->next_to_clean = 0;
1552
1553 return 0;
1554}
1555
1556/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001557 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1558 * (Descriptors) for all queues
1559 * @adapter: board private structure
1560 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001561 * Return 0 on success, negative on failure
1562 **/
Joe Perches64798842008-07-11 15:17:02 -07001563int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001564{
1565 int i, err = 0;
1566
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001567 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001568 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1569 if (err) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001570 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001571 for (i-- ; i >= 0; i--)
1572 e1000_free_tx_resources(adapter,
1573 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001574 break;
1575 }
1576 }
1577
1578 return err;
1579}
1580
1581/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1583 * @adapter: board private structure
1584 *
1585 * Configure the Tx unit of the MAC after a reset.
1586 **/
Joe Perches64798842008-07-11 15:17:02 -07001587static void e1000_configure_tx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588{
Joe Perches406874a2008-04-03 10:06:32 -07001589 u64 tdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001590 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001591 u32 tdlen, tctl, tipg;
Joe Perches406874a2008-04-03 10:06:32 -07001592 u32 ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594 /* Setup the HW Tx Head and Tail descriptor pointers */
1595
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001596 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001597 case 1:
1598 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001599 tdba = adapter->tx_ring[0].dma;
1600 tdlen = adapter->tx_ring[0].count *
1601 sizeof(struct e1000_tx_desc);
Joe Perches1dc32912008-07-11 15:17:08 -07001602 ew32(TDLEN, tdlen);
1603 ew32(TDBAH, (tdba >> 32));
1604 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1605 ew32(TDT, 0);
1606 ew32(TDH, 0);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001607 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ?
1608 E1000_TDH : E1000_82542_TDH);
1609 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ?
1610 E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001611 break;
1612 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
1614 /* Set the default values for the Tx Inter Packet Gap timer */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001615 if ((hw->media_type == e1000_media_type_fiber ||
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001616 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001617 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1618 else
1619 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1620
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001621 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 case e1000_82542_rev2_0:
1623 case e1000_82542_rev2_1:
1624 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001625 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1626 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 break;
1628 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001629 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1630 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1631 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001633 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1634 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Joe Perches1dc32912008-07-11 15:17:08 -07001635 ew32(TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
1637 /* Set the Tx Interrupt Delay register */
1638
Joe Perches1dc32912008-07-11 15:17:08 -07001639 ew32(TIDV, adapter->tx_int_delay);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001640 if (hw->mac_type >= e1000_82540)
Joe Perches1dc32912008-07-11 15:17:08 -07001641 ew32(TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
1643 /* Program the Transmit Control Register */
1644
Joe Perches1dc32912008-07-11 15:17:08 -07001645 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001647 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1649
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001650 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
1652 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001653 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1654
1655 /* only set IDE if we are delaying interrupts using the timers */
1656 if (adapter->tx_int_delay)
1657 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001659 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1661 else
1662 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1663
1664 /* Cache if we're 82544 running in PCI-X because we'll
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001665 * need this to apply a workaround later in the send path.
1666 */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001667 if (hw->mac_type == e1000_82544 &&
1668 hw->bus_type == e1000_bus_type_pcix)
Rusty Russell3db1cd52011-12-19 13:56:45 +00001669 adapter->pcix_82544 = true;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001670
Joe Perches1dc32912008-07-11 15:17:08 -07001671 ew32(TCTL, tctl);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001672
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
1675/**
1676 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1677 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001678 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 *
1680 * Returns 0 on success, negative on failure
1681 **/
Joe Perches64798842008-07-11 15:17:02 -07001682static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1683 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001686 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Florian Westphal93f0afe2014-09-03 13:34:26 +00001688 size = sizeof(struct e1000_rx_buffer) * rxdr->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001689 rxdr->buffer_info = vzalloc(size);
Joe Perches14f8dc42013-02-07 11:46:27 +00001690 if (!rxdr->buffer_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001693 desc_len = sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001694
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 /* Round up to nearest 4K */
1696
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001697 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001698 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001700 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
1701 GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001702 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 vfree(rxdr->buffer_info);
1705 return -ENOMEM;
1706 }
1707
Malli Chilakala26483452005-04-28 19:44:46 -07001708 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1710 void *olddesc = rxdr->desc;
1711 dma_addr_t olddma = rxdr->dma;
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001712 e_err(rx_err, "rxdr align check failed: %u bytes at %p\n",
Emil Tantilov675ad472010-04-27 14:02:58 +00001713 rxdr->size, rxdr->desc);
Malli Chilakala26483452005-04-28 19:44:46 -07001714 /* Try again, without freeing the previous */
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001715 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size,
1716 &rxdr->dma, GFP_KERNEL);
Malli Chilakala26483452005-04-28 19:44:46 -07001717 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001718 if (!rxdr->desc) {
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001719 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1720 olddma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 goto setup_rx_desc_die;
1722 }
1723
1724 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1725 /* give up */
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001726 dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc,
1727 rxdr->dma);
1728 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1729 olddma);
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001730 e_err(probe, "Unable to allocate aligned memory for "
1731 "the Rx descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001732 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001734 /* Free old allocation, new allocation was successful */
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001735 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1736 olddma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 }
1738 }
1739 memset(rxdr->desc, 0, rxdr->size);
1740
1741 rxdr->next_to_clean = 0;
1742 rxdr->next_to_use = 0;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00001743 rxdr->rx_skb_top = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
1745 return 0;
1746}
1747
1748/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001749 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1750 * (Descriptors) for all queues
1751 * @adapter: board private structure
1752 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001753 * Return 0 on success, negative on failure
1754 **/
Joe Perches64798842008-07-11 15:17:02 -07001755int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001756{
1757 int i, err = 0;
1758
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001759 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001760 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1761 if (err) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001762 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001763 for (i-- ; i >= 0; i--)
1764 e1000_free_rx_resources(adapter,
1765 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001766 break;
1767 }
1768 }
1769
1770 return err;
1771}
1772
1773/**
Malli Chilakala26483452005-04-28 19:44:46 -07001774 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 * @adapter: Board private structure
1776 **/
Joe Perches64798842008-07-11 15:17:02 -07001777static void e1000_setup_rctl(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778{
Joe Perches1dc32912008-07-11 15:17:08 -07001779 struct e1000_hw *hw = &adapter->hw;
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07001780 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Joe Perches1dc32912008-07-11 15:17:08 -07001782 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
1784 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1785
Dean Nelsond5bc77a2011-09-16 16:52:54 +00001786 rctl |= E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
1787 E1000_RCTL_RDMTS_HALF |
Joe Perches1dc32912008-07-11 15:17:08 -07001788 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Joe Perches1dc32912008-07-11 15:17:08 -07001790 if (hw->tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 rctl |= E1000_RCTL_SBP;
1792 else
1793 rctl &= ~E1000_RCTL_SBP;
1794
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001795 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1796 rctl &= ~E1000_RCTL_LPE;
1797 else
1798 rctl |= E1000_RCTL_LPE;
1799
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001801 rctl &= ~E1000_RCTL_SZ_4096;
1802 rctl |= E1000_RCTL_BSEX;
1803 switch (adapter->rx_buffer_len) {
Janusz Wolaka48954c2015-09-17 23:34:29 +02001804 case E1000_RXBUFFER_2048:
1805 default:
1806 rctl |= E1000_RCTL_SZ_2048;
1807 rctl &= ~E1000_RCTL_BSEX;
1808 break;
1809 case E1000_RXBUFFER_4096:
1810 rctl |= E1000_RCTL_SZ_4096;
1811 break;
1812 case E1000_RXBUFFER_8192:
1813 rctl |= E1000_RCTL_SZ_8192;
1814 break;
1815 case E1000_RXBUFFER_16384:
1816 rctl |= E1000_RCTL_SZ_16384;
1817 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001818 }
1819
Ben Greeare825b732012-04-04 06:01:29 +00001820 /* This is useful for sniffing bad packets. */
1821 if (adapter->netdev->features & NETIF_F_RXALL) {
1822 /* UPE and MPE will be handled by normal PROMISC logic
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001823 * in e1000e_set_rx_mode
1824 */
Ben Greeare825b732012-04-04 06:01:29 +00001825 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
1826 E1000_RCTL_BAM | /* RX All Bcast Pkts */
1827 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
1828
1829 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
1830 E1000_RCTL_DPF | /* Allow filtered pause */
1831 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
1832 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
1833 * and that breaks VLANs.
1834 */
1835 }
1836
Joe Perches1dc32912008-07-11 15:17:08 -07001837 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838}
1839
1840/**
1841 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1842 * @adapter: board private structure
1843 *
1844 * Configure the Rx unit of the MAC after a reset.
1845 **/
Joe Perches64798842008-07-11 15:17:02 -07001846static void e1000_configure_rx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847{
Joe Perches406874a2008-04-03 10:06:32 -07001848 u64 rdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001849 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001850 u32 rdlen, rctl, rxcsum;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001851
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00001852 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1853 rdlen = adapter->rx_ring[0].count *
Janusz Wolaka48954c2015-09-17 23:34:29 +02001854 sizeof(struct e1000_rx_desc);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00001855 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1856 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1857 } else {
1858 rdlen = adapter->rx_ring[0].count *
Janusz Wolaka48954c2015-09-17 23:34:29 +02001859 sizeof(struct e1000_rx_desc);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00001860 adapter->clean_rx = e1000_clean_rx_irq;
1861 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 /* disable receives while setting up the descriptors */
Joe Perches1dc32912008-07-11 15:17:08 -07001865 rctl = er32(RCTL);
1866 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
1868 /* set the Receive Delay Timer Register */
Joe Perches1dc32912008-07-11 15:17:08 -07001869 ew32(RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001871 if (hw->mac_type >= e1000_82540) {
Joe Perches1dc32912008-07-11 15:17:08 -07001872 ew32(RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08001873 if (adapter->itr_setting != 0)
Joe Perches1dc32912008-07-11 15:17:08 -07001874 ew32(ITR, 1000000000 / (adapter->itr * 256));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 }
1876
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001877 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001878 * the Base and Length of the Rx Descriptor Ring
1879 */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001880 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001881 case 1:
1882 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001883 rdba = adapter->rx_ring[0].dma;
Joe Perches1dc32912008-07-11 15:17:08 -07001884 ew32(RDLEN, rdlen);
1885 ew32(RDBAH, (rdba >> 32));
1886 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
1887 ew32(RDT, 0);
1888 ew32(RDH, 0);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001889 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ?
1890 E1000_RDH : E1000_82542_RDH);
1891 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ?
1892 E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001893 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001894 }
1895
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001897 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07001898 rxcsum = er32(RXCSUM);
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07001899 if (adapter->rx_csum)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001900 rxcsum |= E1000_RXCSUM_TUOFL;
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07001901 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001902 /* don't need to clear IPPCSE as it defaults to 0 */
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07001903 rxcsum &= ~E1000_RXCSUM_TUOFL;
Joe Perches1dc32912008-07-11 15:17:08 -07001904 ew32(RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 }
1906
1907 /* Enable Receives */
Dean Nelsond5bc77a2011-09-16 16:52:54 +00001908 ew32(RCTL, rctl | E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909}
1910
1911/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001912 * e1000_free_tx_resources - Free Tx Resources per Queue
1913 * @adapter: board private structure
1914 * @tx_ring: Tx descriptor ring for a specific queue
1915 *
1916 * Free all transmit software resources
1917 **/
Joe Perches64798842008-07-11 15:17:02 -07001918static void e1000_free_tx_resources(struct e1000_adapter *adapter,
1919 struct e1000_tx_ring *tx_ring)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001920{
1921 struct pci_dev *pdev = adapter->pdev;
1922
1923 e1000_clean_tx_ring(adapter, tx_ring);
1924
1925 vfree(tx_ring->buffer_info);
1926 tx_ring->buffer_info = NULL;
1927
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001928 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1929 tx_ring->dma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001930
1931 tx_ring->desc = NULL;
1932}
1933
1934/**
1935 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 * @adapter: board private structure
1937 *
1938 * Free all transmit software resources
1939 **/
Joe Perches64798842008-07-11 15:17:02 -07001940void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001942 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001944 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001945 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946}
1947
Florian Westphal580f3212014-09-03 13:34:31 +00001948static void
1949e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1950 struct e1000_tx_buffer *buffer_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951{
Alexander Duyck602c0552009-12-02 16:46:00 +00001952 if (buffer_info->dma) {
1953 if (buffer_info->mapped_as_page)
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001954 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1955 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck602c0552009-12-02 16:46:00 +00001956 else
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001957 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
Alexander Duyck602c0552009-12-02 16:46:00 +00001958 buffer_info->length,
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001959 DMA_TO_DEVICE);
Alexander Duyck602c0552009-12-02 16:46:00 +00001960 buffer_info->dma = 0;
1961 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08001962 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08001964 buffer_info->skb = NULL;
1965 }
Alexander Duyck37e73df2009-03-25 21:58:45 +00001966 buffer_info->time_stamp = 0;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08001967 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968}
1969
1970/**
1971 * e1000_clean_tx_ring - Free Tx Buffers
1972 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001973 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 **/
Joe Perches64798842008-07-11 15:17:02 -07001975static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
1976 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977{
Joe Perches1dc32912008-07-11 15:17:08 -07001978 struct e1000_hw *hw = &adapter->hw;
Florian Westphal580f3212014-09-03 13:34:31 +00001979 struct e1000_tx_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 unsigned long size;
1981 unsigned int i;
1982
1983 /* Free all the Tx ring sk_buffs */
1984
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001985 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 buffer_info = &tx_ring->buffer_info[i];
1987 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1988 }
1989
Otto Estuardo Solares Cabrera2f66fd32012-08-24 08:04:58 +00001990 netdev_reset_queue(adapter->netdev);
Florian Westphal580f3212014-09-03 13:34:31 +00001991 size = sizeof(struct e1000_tx_buffer) * tx_ring->count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 memset(tx_ring->buffer_info, 0, size);
1993
1994 /* Zero out the descriptor ring */
1995
1996 memset(tx_ring->desc, 0, tx_ring->size);
1997
1998 tx_ring->next_to_use = 0;
1999 tx_ring->next_to_clean = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00002000 tx_ring->last_tx_tso = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
Joe Perches1dc32912008-07-11 15:17:08 -07002002 writel(0, hw->hw_addr + tx_ring->tdh);
2003 writel(0, hw->hw_addr + tx_ring->tdt);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002004}
2005
2006/**
2007 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2008 * @adapter: board private structure
2009 **/
Joe Perches64798842008-07-11 15:17:02 -07002010static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002011{
2012 int i;
2013
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002014 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002015 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016}
2017
2018/**
2019 * e1000_free_rx_resources - Free Rx Resources
2020 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002021 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 *
2023 * Free all receive software resources
2024 **/
Joe Perches64798842008-07-11 15:17:02 -07002025static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2026 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 struct pci_dev *pdev = adapter->pdev;
2029
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002030 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
2032 vfree(rx_ring->buffer_info);
2033 rx_ring->buffer_info = NULL;
2034
Nick Nunleyb16f53b2010-04-27 13:08:45 +00002035 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2036 rx_ring->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
2038 rx_ring->desc = NULL;
2039}
2040
2041/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002042 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002044 *
2045 * Free all receive software resources
2046 **/
Joe Perches64798842008-07-11 15:17:02 -07002047void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002048{
2049 int i;
2050
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002051 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002052 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2053}
2054
Florian Westphal13809602014-09-03 13:34:36 +00002055#define E1000_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN)
2056static unsigned int e1000_frag_len(const struct e1000_adapter *a)
2057{
2058 return SKB_DATA_ALIGN(a->rx_buffer_len + E1000_HEADROOM) +
2059 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2060}
2061
2062static void *e1000_alloc_frag(const struct e1000_adapter *a)
2063{
2064 unsigned int len = e1000_frag_len(a);
2065 u8 *data = netdev_alloc_frag(len);
2066
2067 if (likely(data))
2068 data += E1000_HEADROOM;
2069 return data;
2070}
2071
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002072/**
2073 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2074 * @adapter: board private structure
2075 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 **/
Joe Perches64798842008-07-11 15:17:02 -07002077static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2078 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079{
Joe Perches1dc32912008-07-11 15:17:08 -07002080 struct e1000_hw *hw = &adapter->hw;
Florian Westphal93f0afe2014-09-03 13:34:26 +00002081 struct e1000_rx_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 struct pci_dev *pdev = adapter->pdev;
2083 unsigned long size;
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07002084 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
Florian Westphal13809602014-09-03 13:34:36 +00002086 /* Free all the Rx netfrags */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002087 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 buffer_info = &rx_ring->buffer_info[i];
Florian Westphal13809602014-09-03 13:34:36 +00002089 if (adapter->clean_rx == e1000_clean_rx_irq) {
2090 if (buffer_info->dma)
2091 dma_unmap_single(&pdev->dev, buffer_info->dma,
2092 adapter->rx_buffer_len,
2093 DMA_FROM_DEVICE);
2094 if (buffer_info->rxbuf.data) {
Alexander Duyck6bf93ba2015-05-06 21:12:20 -07002095 skb_free_frag(buffer_info->rxbuf.data);
Florian Westphal13809602014-09-03 13:34:36 +00002096 buffer_info->rxbuf.data = NULL;
2097 }
2098 } else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
2099 if (buffer_info->dma)
2100 dma_unmap_page(&pdev->dev, buffer_info->dma,
2101 adapter->rx_buffer_len,
2102 DMA_FROM_DEVICE);
2103 if (buffer_info->rxbuf.page) {
2104 put_page(buffer_info->rxbuf.page);
2105 buffer_info->rxbuf.page = NULL;
2106 }
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00002107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00002109 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 }
2111
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00002112 /* there also may be some cached data from a chained receive */
Florian Westphalde591c72014-09-03 13:34:42 +00002113 napi_free_frags(&adapter->napi);
2114 rx_ring->rx_skb_top = NULL;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00002115
Florian Westphal93f0afe2014-09-03 13:34:26 +00002116 size = sizeof(struct e1000_rx_buffer) * rx_ring->count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 memset(rx_ring->buffer_info, 0, size);
2118
2119 /* Zero out the descriptor ring */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 memset(rx_ring->desc, 0, rx_ring->size);
2121
2122 rx_ring->next_to_clean = 0;
2123 rx_ring->next_to_use = 0;
2124
Joe Perches1dc32912008-07-11 15:17:08 -07002125 writel(0, hw->hw_addr + rx_ring->rdh);
2126 writel(0, hw->hw_addr + rx_ring->rdt);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002127}
2128
2129/**
2130 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2131 * @adapter: board private structure
2132 **/
Joe Perches64798842008-07-11 15:17:02 -07002133static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002134{
2135 int i;
2136
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002137 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002138 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139}
2140
2141/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2142 * and memory write and invalidate disabled for certain operations
2143 */
Joe Perches64798842008-07-11 15:17:02 -07002144static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
Joe Perches1dc32912008-07-11 15:17:08 -07002146 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002148 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Joe Perches1dc32912008-07-11 15:17:08 -07002150 e1000_pci_clear_mwi(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
Joe Perches1dc32912008-07-11 15:17:08 -07002152 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 rctl |= E1000_RCTL_RST;
Joe Perches1dc32912008-07-11 15:17:08 -07002154 ew32(RCTL, rctl);
2155 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 mdelay(5);
2157
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002158 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002159 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160}
2161
Joe Perches64798842008-07-11 15:17:02 -07002162static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163{
Joe Perches1dc32912008-07-11 15:17:08 -07002164 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002166 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Joe Perches1dc32912008-07-11 15:17:08 -07002168 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 rctl &= ~E1000_RCTL_RST;
Joe Perches1dc32912008-07-11 15:17:08 -07002170 ew32(RCTL, rctl);
2171 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 mdelay(5);
2173
Joe Perches1dc32912008-07-11 15:17:08 -07002174 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2175 e1000_pci_set_mwi(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002177 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002178 /* No need to loop, because 82542 supports only 1 queue */
2179 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002180 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002181 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 }
2183}
2184
2185/**
2186 * e1000_set_mac - Change the Ethernet Address of the NIC
2187 * @netdev: network interface device structure
2188 * @p: pointer to an address structure
2189 *
2190 * Returns 0 on success, negative on failure
2191 **/
Joe Perches64798842008-07-11 15:17:02 -07002192static int e1000_set_mac(struct net_device *netdev, void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002194 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07002195 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 struct sockaddr *addr = p;
2197
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002198 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 return -EADDRNOTAVAIL;
2200
2201 /* 82542 2.0 needs to be in reset to write receive address registers */
2202
Joe Perches1dc32912008-07-11 15:17:08 -07002203 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 e1000_enter_82542_rst(adapter);
2205
2206 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Joe Perches1dc32912008-07-11 15:17:08 -07002207 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
Joe Perches1dc32912008-07-11 15:17:08 -07002209 e1000_rar_set(hw, hw->mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
Joe Perches1dc32912008-07-11 15:17:08 -07002211 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 e1000_leave_82542_rst(adapter);
2213
2214 return 0;
2215}
2216
2217/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002218 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 * @netdev: network interface device structure
2220 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002221 * The set_rx_mode entry point is called whenever the unicast or multicast
2222 * address lists or the network interface flags are updated. This routine is
2223 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 * promiscuous mode, and all-multi behavior.
2225 **/
Joe Perches64798842008-07-11 15:17:02 -07002226static void e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002228 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 struct e1000_hw *hw = &adapter->hw;
Jiri Pirkoccffad252009-05-22 23:22:17 +00002230 struct netdev_hw_addr *ha;
2231 bool use_uc = false;
Joe Perches406874a2008-04-03 10:06:32 -07002232 u32 rctl;
2233 u32 hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002234 int i, rar_entries = E1000_RAR_ENTRIES;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002235 int mta_reg_count = E1000_NUM_MTA_REGISTERS;
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002236 u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
2237
Joe Perches14f8dc42013-02-07 11:46:27 +00002238 if (!mcarray)
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002239 return;
Auke Kokcd94dd02006-06-27 09:08:22 -07002240
Malli Chilakala26483452005-04-28 19:44:46 -07002241 /* Check for Promiscuous and All Multicast modes */
2242
Joe Perches1dc32912008-07-11 15:17:08 -07002243 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002245 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002247 rctl &= ~E1000_RCTL_VFE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 } else {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002249 if (netdev->flags & IFF_ALLMULTI)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002250 rctl |= E1000_RCTL_MPE;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002251 else
Patrick McHardy746b9f02008-07-16 20:15:45 -07002252 rctl &= ~E1000_RCTL_MPE;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002253 /* Enable VLAN filter if there is a VLAN */
Jiri Pirko5622e402011-07-21 03:26:31 +00002254 if (e1000_vlan_used(adapter))
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002255 rctl |= E1000_RCTL_VFE;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002256 }
2257
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08002258 if (netdev_uc_count(netdev) > rar_entries - 1) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002259 rctl |= E1000_RCTL_UPE;
2260 } else if (!(netdev->flags & IFF_PROMISC)) {
2261 rctl &= ~E1000_RCTL_UPE;
Jiri Pirkoccffad252009-05-22 23:22:17 +00002262 use_uc = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 }
2264
Joe Perches1dc32912008-07-11 15:17:08 -07002265 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
2267 /* 82542 2.0 needs to be in reset to write receive address registers */
2268
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002269 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 e1000_enter_82542_rst(adapter);
2271
Patrick McHardydb0ce502007-11-13 20:54:59 -08002272 /* load the first 14 addresses into the exact filters 1-14. Unicast
2273 * addresses take precedence to avoid disabling unicast filtering
2274 * when possible.
2275 *
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04002276 * RAR 0 is used for the station MAC address
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 * if there are not 14 addresses, go ahead and clear the filters
2278 */
Jiri Pirkoccffad252009-05-22 23:22:17 +00002279 i = 1;
2280 if (use_uc)
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08002281 netdev_for_each_uc_addr(ha, netdev) {
Jiri Pirkoccffad252009-05-22 23:22:17 +00002282 if (i == rar_entries)
2283 break;
2284 e1000_rar_set(hw, ha->addr, i++);
2285 }
2286
Jiri Pirko22bedad32010-04-01 21:22:57 +00002287 netdev_for_each_mc_addr(ha, netdev) {
Jiri Pirko7a81e9f2010-02-22 09:10:44 +00002288 if (i == rar_entries) {
2289 /* load any remaining addresses into the hash table */
2290 u32 hash_reg, hash_bit, mta;
Jiri Pirko22bedad32010-04-01 21:22:57 +00002291 hash_value = e1000_hash_mc_addr(hw, ha->addr);
Jiri Pirko7a81e9f2010-02-22 09:10:44 +00002292 hash_reg = (hash_value >> 5) & 0x7F;
2293 hash_bit = hash_value & 0x1F;
2294 mta = (1 << hash_bit);
2295 mcarray[hash_reg] |= mta;
Jiri Pirko10886af2010-02-23 01:19:22 -08002296 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00002297 e1000_rar_set(hw, ha->addr, i++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 }
2299 }
2300
Jiri Pirko7a81e9f2010-02-22 09:10:44 +00002301 for (; i < rar_entries; i++) {
2302 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2303 E1000_WRITE_FLUSH();
2304 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2305 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 }
2307
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002308 /* write the hash table completely, write from bottom to avoid
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002309 * both stupid write combining chipsets, and flushing each write
2310 */
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002311 for (i = mta_reg_count - 1; i >= 0 ; i--) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002312 /* If we are on an 82544 has an errata where writing odd
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002313 * offsets overwrites the previous even offset, but writing
2314 * backwards over the range solves the issue by always
2315 * writing the odd offset first
2316 */
2317 E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
2318 }
2319 E1000_WRITE_FLUSH();
2320
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002321 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 e1000_leave_82542_rst(adapter);
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002323
2324 kfree(mcarray);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325}
2326
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002327/**
2328 * e1000_update_phy_info_task - get phy info
2329 * @work: work struct contained inside adapter struct
2330 *
2331 * Need to wait a few seconds after link up to get diagnostic information from
2332 * the phy
2333 */
Jesse Brandeburg5cf42fc2010-09-22 18:22:17 +00002334static void e1000_update_phy_info_task(struct work_struct *work)
2335{
2336 struct e1000_adapter *adapter = container_of(work,
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002337 struct e1000_adapter,
2338 phy_info_task.work);
Vladimir Davydovb2f963bf2013-11-23 07:17:56 +00002339
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002340 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341}
2342
2343/**
Jesse Brandeburg5cf42fc2010-09-22 18:22:17 +00002344 * e1000_82547_tx_fifo_stall_task - task to complete work
2345 * @work: work struct contained inside adapter struct
2346 **/
2347static void e1000_82547_tx_fifo_stall_task(struct work_struct *work)
2348{
2349 struct e1000_adapter *adapter = container_of(work,
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002350 struct e1000_adapter,
2351 fifo_stall_task.work);
Joe Perches1dc32912008-07-11 15:17:08 -07002352 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002354 u32 tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002356 if (atomic_read(&adapter->tx_fifo_stall)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002357 if ((er32(TDT) == er32(TDH)) &&
2358 (er32(TDFT) == er32(TDFH)) &&
2359 (er32(TDFTS) == er32(TDFHS))) {
2360 tctl = er32(TCTL);
2361 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2362 ew32(TDFT, adapter->tx_head_addr);
2363 ew32(TDFH, adapter->tx_head_addr);
2364 ew32(TDFTS, adapter->tx_head_addr);
2365 ew32(TDFHS, adapter->tx_head_addr);
2366 ew32(TCTL, tctl);
2367 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
2369 adapter->tx_fifo_head = 0;
2370 atomic_set(&adapter->tx_fifo_stall, 0);
2371 netif_wake_queue(netdev);
Jesse Brandeburgbaa34742009-09-25 12:17:23 +00002372 } else if (!test_bit(__E1000_DOWN, &adapter->flags)) {
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002373 schedule_delayed_work(&adapter->fifo_stall_task, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 }
2375 }
2376}
2377
Nick Nunleyb5481922010-02-03 14:49:28 +00002378bool e1000_has_link(struct e1000_adapter *adapter)
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002379{
2380 struct e1000_hw *hw = &adapter->hw;
2381 bool link_active = false;
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002382
Nicolas Schichan6d9e5132011-07-09 00:24:18 +00002383 /* get_link_status is set on LSC (link status) interrupt or rx
2384 * sequence error interrupt (except on intel ce4100).
2385 * get_link_status will stay false until the
2386 * e1000_check_for_link establishes link for copper adapters
2387 * ONLY
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002388 */
2389 switch (hw->media_type) {
2390 case e1000_media_type_copper:
Nicolas Schichan6d9e5132011-07-09 00:24:18 +00002391 if (hw->mac_type == e1000_ce4100)
2392 hw->get_link_status = 1;
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002393 if (hw->get_link_status) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002394 e1000_check_for_link(hw);
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002395 link_active = !hw->get_link_status;
2396 } else {
2397 link_active = true;
2398 }
2399 break;
2400 case e1000_media_type_fiber:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002401 e1000_check_for_link(hw);
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002402 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
2403 break;
2404 case e1000_media_type_internal_serdes:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002405 e1000_check_for_link(hw);
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002406 link_active = hw->serdes_has_link;
2407 break;
2408 default:
2409 break;
2410 }
2411
2412 return link_active;
2413}
2414
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415/**
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002416 * e1000_watchdog - work function
2417 * @work: work struct contained inside adapter struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 **/
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002419static void e1000_watchdog(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420{
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002421 struct e1000_adapter *adapter = container_of(work,
2422 struct e1000_adapter,
2423 watchdog_task.work);
Joe Perches1dc32912008-07-11 15:17:08 -07002424 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002426 struct e1000_tx_ring *txdr = adapter->tx_ring;
Joe Perches406874a2008-04-03 10:06:32 -07002427 u32 link, tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002429 link = e1000_has_link(adapter);
2430 if ((netif_carrier_ok(netdev)) && link)
2431 goto link_up;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002433 if (link) {
2434 if (!netif_carrier_ok(netdev)) {
Joe Perches406874a2008-04-03 10:06:32 -07002435 u32 ctrl;
Joe Perchesc3033b02008-03-21 11:06:25 -07002436 bool txb2b = true;
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002437 /* update snapshot of PHY registers on LSC */
Joe Perches1dc32912008-07-11 15:17:08 -07002438 e1000_get_speed_and_duplex(hw,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002439 &adapter->link_speed,
2440 &adapter->link_duplex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Joe Perches1dc32912008-07-11 15:17:08 -07002442 ctrl = er32(CTRL);
Emil Tantilov675ad472010-04-27 14:02:58 +00002443 pr_info("%s NIC Link is Up %d Mbps %s, "
2444 "Flow Control: %s\n",
2445 netdev->name,
2446 adapter->link_speed,
2447 adapter->link_duplex == FULL_DUPLEX ?
2448 "Full Duplex" : "Half Duplex",
2449 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2450 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2451 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2452 E1000_CTRL_TFCE) ? "TX" : "None")));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
Emil Tantilov39ca5f02010-03-26 11:25:58 +00002454 /* adjust timeout factor according to speed/duplex */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002455 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002456 switch (adapter->link_speed) {
2457 case SPEED_10:
Joe Perchesc3033b02008-03-21 11:06:25 -07002458 txb2b = false;
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002459 adapter->tx_timeout_factor = 16;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002460 break;
2461 case SPEED_100:
Joe Perchesc3033b02008-03-21 11:06:25 -07002462 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002463 /* maybe add some timeout factor ? */
2464 break;
2465 }
2466
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002467 /* enable transmits in the hardware */
Joe Perches1dc32912008-07-11 15:17:08 -07002468 tctl = er32(TCTL);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002469 tctl |= E1000_TCTL_EN;
Joe Perches1dc32912008-07-11 15:17:08 -07002470 ew32(TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002471
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 netif_carrier_on(netdev);
Jesse Brandeburgbaa34742009-09-25 12:17:23 +00002473 if (!test_bit(__E1000_DOWN, &adapter->flags))
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002474 schedule_delayed_work(&adapter->phy_info_task,
2475 2 * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 adapter->smartspeed = 0;
2477 }
2478 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002479 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 adapter->link_speed = 0;
2481 adapter->link_duplex = 0;
Emil Tantilov675ad472010-04-27 14:02:58 +00002482 pr_info("%s NIC Link is Down\n",
2483 netdev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 netif_carrier_off(netdev);
Jesse Brandeburgbaa34742009-09-25 12:17:23 +00002485
2486 if (!test_bit(__E1000_DOWN, &adapter->flags))
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002487 schedule_delayed_work(&adapter->phy_info_task,
2488 2 * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 }
2490
2491 e1000_smartspeed(adapter);
2492 }
2493
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002494link_up:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 e1000_update_stats(adapter);
2496
Joe Perches1dc32912008-07-11 15:17:08 -07002497 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 adapter->tpt_old = adapter->stats.tpt;
Joe Perches1dc32912008-07-11 15:17:08 -07002499 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 adapter->colc_old = adapter->stats.colc;
2501
2502 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2503 adapter->gorcl_old = adapter->stats.gorcl;
2504 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2505 adapter->gotcl_old = adapter->stats.gotcl;
2506
Joe Perches1dc32912008-07-11 15:17:08 -07002507 e1000_update_adaptive(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002509 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002510 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 /* We've lost link, so the controller stops DMA,
2512 * but we've got queued Tx work that's never going
2513 * to get done, so reset controller to flush Tx.
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002514 * (Do the reset outside of interrupt context).
2515 */
Jeff Kirsher87041632006-03-02 18:21:24 -08002516 adapter->tx_timeout_count++;
2517 schedule_work(&adapter->reset_task);
Jesse Brandeburg0ef4eed2011-10-05 07:24:51 +00002518 /* exit immediately since reset is imminent */
Vladimir Davydovb2f963bf2013-11-23 07:17:56 +00002519 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 }
2521 }
2522
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002523 /* Simple mode for Interrupt Throttle Rate (ITR) */
2524 if (hw->mac_type >= e1000_82540 && adapter->itr_setting == 4) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002525 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002526 * Total asymmetrical Tx or Rx gets ITR=8000;
2527 * everyone else is between 2000-8000.
2528 */
2529 u32 goc = (adapter->gotcl + adapter->gorcl) / 10000;
2530 u32 dif = (adapter->gotcl > adapter->gorcl ?
2531 adapter->gotcl - adapter->gorcl :
2532 adapter->gorcl - adapter->gotcl) / 10000;
2533 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2534
2535 ew32(ITR, 1000000000 / (itr * 256));
2536 }
2537
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 /* Cause software interrupt to ensure rx ring is cleaned */
Joe Perches1dc32912008-07-11 15:17:08 -07002539 ew32(ICS, E1000_ICS_RXDMT0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
Malli Chilakala26483452005-04-28 19:44:46 -07002541 /* Force detection of hung controller every watchdog period */
Joe Perchesc3033b02008-03-21 11:06:25 -07002542 adapter->detect_tx_hung = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002544 /* Reschedule the task */
Jesse Brandeburgbaa34742009-09-25 12:17:23 +00002545 if (!test_bit(__E1000_DOWN, &adapter->flags))
Jesse Brandeburga4010af2011-10-05 07:24:41 +00002546 schedule_delayed_work(&adapter->watchdog_task, 2 * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547}
2548
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002549enum latency_range {
2550 lowest_latency = 0,
2551 low_latency = 1,
2552 bulk_latency = 2,
2553 latency_invalid = 255
2554};
2555
2556/**
2557 * e1000_update_itr - update the dynamic ITR value based on statistics
Jesse Brandeburg8fce4732009-09-25 12:18:41 +00002558 * @adapter: pointer to adapter
2559 * @itr_setting: current adapter->itr
2560 * @packets: the number of packets during this measurement interval
2561 * @bytes: the number of bytes during this measurement interval
2562 *
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002563 * Stores a new ITR value based on packets and byte
2564 * counts during the last interrupt. The advantage of per interrupt
2565 * computation is faster updates and more accurate ITR for the current
2566 * traffic pattern. Constants in this function were computed
2567 * based on theoretical maximum wire speed and thresholds were set based
2568 * on testing data as well as attempting to minimize response time
2569 * while increasing bulk throughput.
2570 * this functionality is controlled by the InterruptThrottleRate module
2571 * parameter (see e1000_param.c)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002572 **/
2573static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
Joe Perches64798842008-07-11 15:17:02 -07002574 u16 itr_setting, int packets, int bytes)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002575{
2576 unsigned int retval = itr_setting;
2577 struct e1000_hw *hw = &adapter->hw;
2578
2579 if (unlikely(hw->mac_type < e1000_82540))
2580 goto update_itr_done;
2581
2582 if (packets == 0)
2583 goto update_itr_done;
2584
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002585 switch (itr_setting) {
2586 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002587 /* jumbo frames get bulk treatment*/
2588 if (bytes/packets > 8000)
2589 retval = bulk_latency;
2590 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002591 retval = low_latency;
2592 break;
2593 case low_latency: /* 50 usec aka 20000 ints/s */
2594 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002595 /* jumbo frames need bulk latency setting */
2596 if (bytes/packets > 8000)
2597 retval = bulk_latency;
2598 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002599 retval = bulk_latency;
2600 else if ((packets > 35))
2601 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002602 } else if (bytes/packets > 2000)
2603 retval = bulk_latency;
2604 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002605 retval = lowest_latency;
2606 break;
2607 case bulk_latency: /* 250 usec aka 4000 ints/s */
2608 if (bytes > 25000) {
2609 if (packets > 35)
2610 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002611 } else if (bytes < 6000) {
2612 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002613 }
2614 break;
2615 }
2616
2617update_itr_done:
2618 return retval;
2619}
2620
2621static void e1000_set_itr(struct e1000_adapter *adapter)
2622{
2623 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002624 u16 current_itr;
2625 u32 new_itr = adapter->itr;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002626
2627 if (unlikely(hw->mac_type < e1000_82540))
2628 return;
2629
2630 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2631 if (unlikely(adapter->link_speed != SPEED_1000)) {
2632 current_itr = 0;
2633 new_itr = 4000;
2634 goto set_itr_now;
2635 }
2636
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002637 adapter->tx_itr = e1000_update_itr(adapter, adapter->tx_itr,
2638 adapter->total_tx_packets,
2639 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002640 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2641 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2642 adapter->tx_itr = low_latency;
2643
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002644 adapter->rx_itr = e1000_update_itr(adapter, adapter->rx_itr,
2645 adapter->total_rx_packets,
2646 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002647 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2648 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2649 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002650
2651 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2652
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002653 switch (current_itr) {
2654 /* counts and packets in update_itr are dependent on these numbers */
2655 case lowest_latency:
2656 new_itr = 70000;
2657 break;
2658 case low_latency:
2659 new_itr = 20000; /* aka hwitr = ~200 */
2660 break;
2661 case bulk_latency:
2662 new_itr = 4000;
2663 break;
2664 default:
2665 break;
2666 }
2667
2668set_itr_now:
2669 if (new_itr != adapter->itr) {
2670 /* this attempts to bias the interrupt rate towards Bulk
2671 * by adding intermediate steps when interrupt rate is
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002672 * increasing
2673 */
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002674 new_itr = new_itr > adapter->itr ?
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002675 min(adapter->itr + (new_itr >> 2), new_itr) :
2676 new_itr;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002677 adapter->itr = new_itr;
Joe Perches1dc32912008-07-11 15:17:08 -07002678 ew32(ITR, 1000000000 / (new_itr * 256));
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002679 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002680}
2681
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682#define E1000_TX_FLAGS_CSUM 0x00000001
2683#define E1000_TX_FLAGS_VLAN 0x00000002
2684#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002685#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear11a78dc2012-02-11 15:40:01 +00002686#define E1000_TX_FLAGS_NO_FCS 0x00000010
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2688#define E1000_TX_FLAGS_VLAN_SHIFT 16
2689
Joe Perches64798842008-07-11 15:17:02 -07002690static int e1000_tso(struct e1000_adapter *adapter,
Vlad Yasevich06f4d032014-08-25 10:34:49 -04002691 struct e1000_tx_ring *tx_ring, struct sk_buff *skb,
2692 __be16 protocol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 struct e1000_context_desc *context_desc;
Florian Westphal580f3212014-09-03 13:34:31 +00002695 struct e1000_tx_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002697 u32 cmd_length = 0;
2698 u16 ipcse = 0, tucse, mss;
2699 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700
Herbert Xu89114af2006-07-08 13:34:32 -07002701 if (skb_is_gso(skb)) {
Francois Romieu4a54b1e2014-03-30 03:14:37 +00002702 int err;
2703
2704 err = skb_cow_head(skb, 0);
2705 if (err < 0)
2706 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002708 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002709 mss = skb_shinfo(skb)->gso_size;
Vlad Yasevich06f4d032014-08-25 10:34:49 -04002710 if (protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002711 struct iphdr *iph = ip_hdr(skb);
2712 iph->tot_len = 0;
2713 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002714 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2715 iph->daddr, 0,
2716 IPPROTO_TCP,
2717 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002718 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002719 ipcse = skb_transport_offset(skb) - 1;
Vlad Yasevich06f4d032014-08-25 10:34:49 -04002720 } else if (skb_is_gso_v6(skb)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002721 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002722 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002723 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2724 &ipv6_hdr(skb)->daddr,
2725 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002726 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002727 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002728 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002729 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002730 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002731 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 tucse = 0;
2733
2734 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002735 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002737 i = tx_ring->next_to_use;
2738 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002739 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740
2741 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2742 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2743 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2744 context_desc->upper_setup.tcp_fields.tucss = tucss;
2745 context_desc->upper_setup.tcp_fields.tucso = tucso;
2746 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2747 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2748 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2749 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2750
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002751 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002752 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002753
Janusz Wolaka48954c2015-09-17 23:34:29 +02002754 if (++i == tx_ring->count)
2755 i = 0;
2756
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002757 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758
Joe Perchesc3033b02008-03-21 11:06:25 -07002759 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 }
Joe Perchesc3033b02008-03-21 11:06:25 -07002761 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762}
2763
Joe Perches64798842008-07-11 15:17:02 -07002764static bool e1000_tx_csum(struct e1000_adapter *adapter,
Vlad Yasevich06f4d032014-08-25 10:34:49 -04002765 struct e1000_tx_ring *tx_ring, struct sk_buff *skb,
2766 __be16 protocol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767{
2768 struct e1000_context_desc *context_desc;
Florian Westphal580f3212014-09-03 13:34:31 +00002769 struct e1000_tx_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002771 u8 css;
Dave Graham3ed30672008-10-09 14:29:26 -07002772 u32 cmd_len = E1000_TXD_CMD_DEXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773
Dave Graham3ed30672008-10-09 14:29:26 -07002774 if (skb->ip_summed != CHECKSUM_PARTIAL)
2775 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
Vlad Yasevich06f4d032014-08-25 10:34:49 -04002777 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08002778 case cpu_to_be16(ETH_P_IP):
Dave Graham3ed30672008-10-09 14:29:26 -07002779 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2780 cmd_len |= E1000_TXD_CMD_TCP;
2781 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08002782 case cpu_to_be16(ETH_P_IPV6):
Dave Graham3ed30672008-10-09 14:29:26 -07002783 /* XXX not handling all IPV6 headers */
2784 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2785 cmd_len |= E1000_TXD_CMD_TCP;
2786 break;
2787 default:
2788 if (unlikely(net_ratelimit()))
Emil Tantilovfeb8f472010-07-26 23:37:21 -07002789 e_warn(drv, "checksum_partial proto=%x!\n",
2790 skb->protocol);
Dave Graham3ed30672008-10-09 14:29:26 -07002791 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 }
2793
Michał Mirosław0d0b1672010-12-14 15:24:08 +00002794 css = skb_checksum_start_offset(skb);
Dave Graham3ed30672008-10-09 14:29:26 -07002795
2796 i = tx_ring->next_to_use;
2797 buffer_info = &tx_ring->buffer_info[i];
2798 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2799
2800 context_desc->lower_setup.ip_config = 0;
2801 context_desc->upper_setup.tcp_fields.tucss = css;
2802 context_desc->upper_setup.tcp_fields.tucso =
2803 css + skb->csum_offset;
2804 context_desc->upper_setup.tcp_fields.tucse = 0;
2805 context_desc->tcp_seg_setup.data = 0;
2806 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
2807
2808 buffer_info->time_stamp = jiffies;
2809 buffer_info->next_to_watch = i;
2810
Janusz Wolaka48954c2015-09-17 23:34:29 +02002811 if (unlikely(++i == tx_ring->count))
2812 i = 0;
2813
Dave Graham3ed30672008-10-09 14:29:26 -07002814 tx_ring->next_to_use = i;
2815
2816 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817}
2818
2819#define E1000_MAX_TXD_PWR 12
2820#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2821
Joe Perches64798842008-07-11 15:17:02 -07002822static int e1000_tx_map(struct e1000_adapter *adapter,
2823 struct e1000_tx_ring *tx_ring,
2824 struct sk_buff *skb, unsigned int first,
2825 unsigned int max_per_txd, unsigned int nr_frags,
2826 unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827{
Joe Perches1dc32912008-07-11 15:17:08 -07002828 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck602c0552009-12-02 16:46:00 +00002829 struct pci_dev *pdev = adapter->pdev;
Florian Westphal580f3212014-09-03 13:34:31 +00002830 struct e1000_tx_buffer *buffer_info;
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002831 unsigned int len = skb_headlen(skb);
Alexander Duyck602c0552009-12-02 16:46:00 +00002832 unsigned int offset = 0, size, count = 0, i;
Dean Nelson31c15a22011-08-25 14:39:24 +00002833 unsigned int f, bytecount, segs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834
2835 i = tx_ring->next_to_use;
2836
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002837 while (len) {
Alexander Duyck37e73df2009-03-25 21:58:45 +00002838 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05002840 /* Workaround for Controller erratum --
2841 * descriptor for non-tso packet in a linear SKB that follows a
2842 * tso gets written back prematurely before the data is fully
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002843 * DMA'd to the controller
2844 */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002845 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07002846 !skb_is_gso(skb)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00002847 tx_ring->last_tx_tso = false;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002848 size -= 4;
2849 }
2850
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 /* Workaround for premature desc write-backs
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002852 * in TSO mode. Append 4-byte sentinel desc
2853 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002854 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07002856 /* work-around for errata 10 and it applies
2857 * to all controllers in PCI-X mode
2858 * The fix is to make sure that the first descriptor of a
2859 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2860 */
Joe Perches1dc32912008-07-11 15:17:08 -07002861 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
Janusz Wolaka48954c2015-09-17 23:34:29 +02002862 (size > 2015) && count == 0))
2863 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002864
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 /* Workaround for potential 82544 hang in PCI-X. Avoid
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002866 * terminating buffers within evenly-aligned dwords.
2867 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002868 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2870 size > 4))
2871 size -= 4;
2872
2873 buffer_info->length = size;
Jesse Brandeburgcdd75492009-09-25 12:18:07 +00002874 /* set time_stamp *before* dma to help avoid a possible race */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 buffer_info->time_stamp = jiffies;
Alexander Duyck602c0552009-12-02 16:46:00 +00002876 buffer_info->mapped_as_page = false;
Nick Nunleyb16f53b2010-04-27 13:08:45 +00002877 buffer_info->dma = dma_map_single(&pdev->dev,
2878 skb->data + offset,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002879 size, DMA_TO_DEVICE);
Nick Nunleyb16f53b2010-04-27 13:08:45 +00002880 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck602c0552009-12-02 16:46:00 +00002881 goto dma_error;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002882 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883
2884 len -= size;
2885 offset += size;
2886 count++;
Alexander Duyck37e73df2009-03-25 21:58:45 +00002887 if (len) {
2888 i++;
2889 if (unlikely(i == tx_ring->count))
2890 i = 0;
2891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 }
2893
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002894 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00002895 const struct skb_frag_struct *frag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
2897 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00002898 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00002899 offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002901 while (len) {
Ian Campbell877749b2011-08-29 23:18:26 +00002902 unsigned long bufend;
Alexander Duyck37e73df2009-03-25 21:58:45 +00002903 i++;
2904 if (unlikely(i == tx_ring->count))
2905 i = 0;
2906
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 buffer_info = &tx_ring->buffer_info[i];
2908 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 /* Workaround for premature desc write-backs
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002910 * in TSO mode. Append 4-byte sentinel desc
2911 */
2912 if (unlikely(mss && f == (nr_frags-1) &&
2913 size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 /* Workaround for potential 82544 hang in PCI-X.
2916 * Avoid terminating buffers within evenly-aligned
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002917 * dwords.
2918 */
Ian Campbell877749b2011-08-29 23:18:26 +00002919 bufend = (unsigned long)
2920 page_to_phys(skb_frag_page(frag));
2921 bufend += offset + size - 1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002922 if (unlikely(adapter->pcix_82544 &&
Ian Campbell877749b2011-08-29 23:18:26 +00002923 !(bufend & 4) &&
2924 size > 4))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 size -= 4;
2926
2927 buffer_info->length = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 buffer_info->time_stamp = jiffies;
Alexander Duyck602c0552009-12-02 16:46:00 +00002929 buffer_info->mapped_as_page = true;
Ian Campbell877749b2011-08-29 23:18:26 +00002930 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
2931 offset, size, DMA_TO_DEVICE);
Nick Nunleyb16f53b2010-04-27 13:08:45 +00002932 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck602c0552009-12-02 16:46:00 +00002933 goto dma_error;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002934 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
2936 len -= size;
2937 offset += size;
2938 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 }
2940 }
2941
Dean Nelson31c15a22011-08-25 14:39:24 +00002942 segs = skb_shinfo(skb)->gso_segs ?: 1;
2943 /* multiply data chunks by size of headers */
2944 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
2945
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 tx_ring->buffer_info[i].skb = skb;
Dean Nelson31c15a22011-08-25 14:39:24 +00002947 tx_ring->buffer_info[i].segs = segs;
2948 tx_ring->buffer_info[i].bytecount = bytecount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 tx_ring->buffer_info[first].next_to_watch = i;
2950
2951 return count;
Alexander Duyck602c0552009-12-02 16:46:00 +00002952
2953dma_error:
2954 dev_err(&pdev->dev, "TX DMA map failed\n");
2955 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00002956 if (count)
Alexander Duyck602c0552009-12-02 16:46:00 +00002957 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00002958
2959 while (count--) {
Janusz Wolaka48954c2015-09-17 23:34:29 +02002960 if (i == 0)
Alexander Duyck602c0552009-12-02 16:46:00 +00002961 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00002962 i--;
Alexander Duyck602c0552009-12-02 16:46:00 +00002963 buffer_info = &tx_ring->buffer_info[i];
2964 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2965 }
2966
2967 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968}
2969
Joe Perches64798842008-07-11 15:17:02 -07002970static void e1000_tx_queue(struct e1000_adapter *adapter,
2971 struct e1000_tx_ring *tx_ring, int tx_flags,
2972 int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 struct e1000_tx_desc *tx_desc = NULL;
Florian Westphal580f3212014-09-03 13:34:31 +00002975 struct e1000_tx_buffer *buffer_info;
Joe Perches406874a2008-04-03 10:06:32 -07002976 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 unsigned int i;
2978
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002979 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002981 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002982 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2983
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002984 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002985 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 }
2987
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002988 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2990 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2991 }
2992
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002993 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 txd_lower |= E1000_TXD_CMD_VLE;
2995 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2996 }
2997
Ben Greear11a78dc2012-02-11 15:40:01 +00002998 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
2999 txd_lower &= ~(E1000_TXD_CMD_IFCS);
3000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 i = tx_ring->next_to_use;
3002
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003003 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 buffer_info = &tx_ring->buffer_info[i];
3005 tx_desc = E1000_TX_DESC(*tx_ring, i);
3006 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3007 tx_desc->lower.data =
3008 cpu_to_le32(txd_lower | buffer_info->length);
3009 tx_desc->upper.data = cpu_to_le32(txd_upper);
Janusz Wolaka48954c2015-09-17 23:34:29 +02003010 if (unlikely(++i == tx_ring->count))
3011 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 }
3013
3014 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3015
Ben Greear11a78dc2012-02-11 15:40:01 +00003016 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
3017 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
3018 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
3019
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 /* Force memory writes to complete before letting h/w
3021 * know there are new descriptors to fetch. (Only
3022 * applicable for weak-ordered memory model archs,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003023 * such as IA-64).
3024 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 wmb();
3026
3027 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028}
3029
Ben Hutchings1aa8b472012-07-10 10:56:59 +00003030/* 82547 workaround to avoid controller hang in half-duplex environment.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 * The workaround is to avoid queuing a large packet that would span
3032 * the internal Tx FIFO ring boundary by notifying the stack to resend
3033 * the packet at a later time. This gives the Tx FIFO an opportunity to
3034 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3035 * to the beginning of the Tx FIFO.
Ben Hutchings1aa8b472012-07-10 10:56:59 +00003036 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037
3038#define E1000_FIFO_HDR 0x10
3039#define E1000_82547_PAD_LEN 0x3E0
3040
Joe Perches64798842008-07-11 15:17:02 -07003041static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3042 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043{
Joe Perches406874a2008-04-03 10:06:32 -07003044 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3045 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003047 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003049 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 goto no_fifo_stall_required;
3051
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003052 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 return 1;
3054
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003055 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 atomic_set(&adapter->tx_fifo_stall, 1);
3057 return 1;
3058 }
3059
3060no_fifo_stall_required:
3061 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003062 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3064 return 0;
3065}
3066
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003067static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3068{
3069 struct e1000_adapter *adapter = netdev_priv(netdev);
3070 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3071
3072 netif_stop_queue(netdev);
3073 /* Herbert's original patch had:
3074 * smp_mb__after_netif_stop_queue();
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003075 * but since that doesn't exist yet, just open code it.
3076 */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003077 smp_mb();
3078
3079 /* We need to check again in a case another CPU has just
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003080 * made room available.
3081 */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003082 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3083 return -EBUSY;
3084
3085 /* A reprieve! */
3086 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003087 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003088 return 0;
3089}
3090
3091static int e1000_maybe_stop_tx(struct net_device *netdev,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003092 struct e1000_tx_ring *tx_ring, int size)
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003093{
3094 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3095 return 0;
3096 return __e1000_maybe_stop_tx(netdev, size);
3097}
3098
Alexander Duyck847a1d62016-03-02 16:16:01 -05003099#define TXD_USE_COUNT(S, X) (((S) + ((1 << (X)) - 1)) >> (X))
Stephen Hemminger3b29a562009-08-31 19:50:55 +00003100static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
3101 struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003103 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07003104 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003105 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3107 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3108 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07003109 unsigned int len = skb_headlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003110 unsigned int nr_frags;
3111 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003113 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 unsigned int f;
Vlad Yasevich06f4d032014-08-25 10:34:49 -04003115 __be16 protocol = vlan_get_protocol(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003117 /* This goes back to the question of how to logically map a Tx queue
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003118 * to a flow. Right now, performance is impacted slightly negatively
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003119 * if using multiple Tx queues. If the stack breaks away from a
3120 * single qdisc implementation, we can look at this again.
3121 */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003122 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003123
Tushar Dave59d86c72012-09-15 10:16:57 +00003124 /* On PCI/PCI-X HW, if packet size is less than ETH_ZLEN,
3125 * packets may get corrupted during padding by HW.
3126 * To WA this issue, pad all small packets manually.
3127 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08003128 if (eth_skb_pad(skb))
3129 return NETDEV_TX_OK;
Tushar Dave59d86c72012-09-15 10:16:57 +00003130
Herbert Xu79671682006-06-22 02:40:14 -07003131 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003132 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 * make sure there is enough room in the FIFO before
3134 * initiating the DMA for each buffer. The calc is:
3135 * 4 = ceil(buffer len/mss). To make sure we don't
3136 * overrun the FIFO, adjust the max buffer len if mss
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003137 * drops.
3138 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003139 if (mss) {
Joe Perches406874a2008-04-03 10:06:32 -07003140 u8 hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 max_per_txd = min(mss << 2, max_per_txd);
3142 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003143
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003144 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003145 if (skb->data_len && hdr_len == len) {
Joe Perches1dc32912008-07-11 15:17:08 -07003146 switch (hw->mac_type) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003147 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003148 case e1000_82544:
3149 /* Make sure we have room to chop off 4 bytes,
3150 * and that the end alignment will work out to
3151 * this hardware's requirements
3152 * NOTE: this is a TSO only workaround
3153 * if end byte alignment not correct move us
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003154 * into the next dword
3155 */
3156 if ((unsigned long)(skb_tail_pointer(skb) - 1)
3157 & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003158 break;
3159 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003160 pull_size = min((unsigned int)4, skb->data_len);
3161 if (!__pskb_pull_tail(skb, pull_size)) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07003162 e_err(drv, "__pskb_pull_tail "
3163 "failed.\n");
Jeff Kirsher9f687882006-03-02 18:20:17 -08003164 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003165 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003166 }
Eric Dumazete743d312010-04-14 15:59:40 -07003167 len = skb_headlen(skb);
Jeff Kirsher9f687882006-03-02 18:20:17 -08003168 break;
3169 default:
3170 /* do nothing */
3171 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003172 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 }
3175
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003176 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003177 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003179 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003180
Jeff Kirsherfd803242005-12-13 00:06:22 -05003181 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003182 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003183 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003184
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 count += TXD_USE_COUNT(len, max_txd_pwr);
3186
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003187 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 count++;
3189
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003190 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003191 * in PCI-X mode, so add one more descriptor to the count
3192 */
Joe Perches1dc32912008-07-11 15:17:08 -07003193 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003194 (len > 2015)))
3195 count++;
3196
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003198 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00003199 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003201 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 count += nr_frags;
3203
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 /* need: count + 2 desc gap to keep tail from touching
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003205 * head, otherwise try next time
3206 */
Alexander Duyck80179432009-01-21 14:42:47 -08003207 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209
Jesse Brandeburga4010af2011-10-05 07:24:41 +00003210 if (unlikely((hw->mac_type == e1000_82547) &&
3211 (e1000_82547_fifo_workaround(adapter, skb)))) {
3212 netif_stop_queue(netdev);
3213 if (!test_bit(__E1000_DOWN, &adapter->flags))
3214 schedule_delayed_work(&adapter->fifo_stall_task, 1);
3215 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 }
3217
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01003218 if (skb_vlan_tag_present(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 tx_flags |= E1000_TX_FLAGS_VLAN;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01003220 tx_flags |= (skb_vlan_tag_get(skb) <<
3221 E1000_TX_FLAGS_VLAN_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 }
3223
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003224 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003225
Vlad Yasevich06f4d032014-08-25 10:34:49 -04003226 tso = e1000_tso(adapter, tx_ring, skb, protocol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 if (tso < 0) {
3228 dev_kfree_skb_any(skb);
3229 return NETDEV_TX_OK;
3230 }
3231
Jeff Kirsherfd803242005-12-13 00:06:22 -05003232 if (likely(tso)) {
Jesse Brandeburg8fce4732009-09-25 12:18:41 +00003233 if (likely(hw->mac_type != e1000_82544))
Rusty Russell3db1cd52011-12-19 13:56:45 +00003234 tx_ring->last_tx_tso = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 tx_flags |= E1000_TX_FLAGS_TSO;
Vlad Yasevich06f4d032014-08-25 10:34:49 -04003236 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb, protocol)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 tx_flags |= E1000_TX_FLAGS_CSUM;
3238
Vlad Yasevich06f4d032014-08-25 10:34:49 -04003239 if (protocol == htons(ETH_P_IP))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003240 tx_flags |= E1000_TX_FLAGS_IPV4;
3241
Ben Greear11a78dc2012-02-11 15:40:01 +00003242 if (unlikely(skb->no_fcs))
3243 tx_flags |= E1000_TX_FLAGS_NO_FCS;
3244
Alexander Duyck37e73df2009-03-25 21:58:45 +00003245 count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003246 nr_frags, mss);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247
Alexander Duyck37e73df2009-03-25 21:58:45 +00003248 if (count) {
Alexander Duycka4605fe2016-03-02 16:16:08 -05003249 /* The descriptors needed is higher than other Intel drivers
3250 * due to a number of workarounds. The breakdown is below:
3251 * Data descriptors: MAX_SKB_FRAGS + 1
3252 * Context Descriptor: 1
3253 * Keep head from touching tail: 2
3254 * Workarounds: 3
3255 */
3256 int desc_needed = MAX_SKB_FRAGS + 7;
3257
Otto Estuardo Solares Cabrera2f66fd32012-08-24 08:04:58 +00003258 netdev_sent_queue(netdev, skb->len);
Willem de Bruijneab467f2012-04-27 09:04:04 +00003259 skb_tx_timestamp(skb);
3260
Alexander Duyck37e73df2009-03-25 21:58:45 +00003261 e1000_tx_queue(adapter, tx_ring, tx_flags, count);
Alexander Duycka4605fe2016-03-02 16:16:08 -05003262
3263 /* 82544 potentially requires twice as many data descriptors
3264 * in order to guarantee buffers don't end on evenly-aligned
3265 * dwords
3266 */
3267 if (adapter->pcix_82544)
3268 desc_needed += MAX_SKB_FRAGS + 1;
3269
Alexander Duyck37e73df2009-03-25 21:58:45 +00003270 /* Make sure there is space in the ring for the next send. */
Alexander Duycka4605fe2016-03-02 16:16:08 -05003271 e1000_maybe_stop_tx(netdev, tx_ring, desc_needed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272
Florian Westphal8a4d0b92015-01-07 11:40:33 +00003273 if (!skb->xmit_more ||
3274 netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) {
3275 writel(tx_ring->next_to_use, hw->hw_addr + tx_ring->tdt);
3276 /* we need this if more than one processor can write to
3277 * our tail at a time, it synchronizes IO on IA64/Altix
3278 * systems
3279 */
3280 mmiowb();
3281 }
Alexander Duyck37e73df2009-03-25 21:58:45 +00003282 } else {
3283 dev_kfree_skb_any(skb);
3284 tx_ring->buffer_info[first].time_stamp = 0;
3285 tx_ring->next_to_use = first;
3286 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 return NETDEV_TX_OK;
3289}
3290
Tushar Daveb04e36b2012-01-27 09:00:46 +00003291#define NUM_REGS 38 /* 1 based count */
3292static void e1000_regdump(struct e1000_adapter *adapter)
3293{
3294 struct e1000_hw *hw = &adapter->hw;
3295 u32 regs[NUM_REGS];
3296 u32 *regs_buff = regs;
3297 int i = 0;
3298
Tushar Davee29b5d82012-02-10 08:06:36 +00003299 static const char * const reg_name[] = {
3300 "CTRL", "STATUS",
3301 "RCTL", "RDLEN", "RDH", "RDT", "RDTR",
3302 "TCTL", "TDBAL", "TDBAH", "TDLEN", "TDH", "TDT",
3303 "TIDV", "TXDCTL", "TADV", "TARC0",
3304 "TDBAL1", "TDBAH1", "TDLEN1", "TDH1", "TDT1",
3305 "TXDCTL1", "TARC1",
3306 "CTRL_EXT", "ERT", "RDBAL", "RDBAH",
3307 "TDFH", "TDFT", "TDFHS", "TDFTS", "TDFPC",
3308 "RDFH", "RDFT", "RDFHS", "RDFTS", "RDFPC"
Tushar Daveb04e36b2012-01-27 09:00:46 +00003309 };
3310
3311 regs_buff[0] = er32(CTRL);
3312 regs_buff[1] = er32(STATUS);
3313
3314 regs_buff[2] = er32(RCTL);
3315 regs_buff[3] = er32(RDLEN);
3316 regs_buff[4] = er32(RDH);
3317 regs_buff[5] = er32(RDT);
3318 regs_buff[6] = er32(RDTR);
3319
3320 regs_buff[7] = er32(TCTL);
3321 regs_buff[8] = er32(TDBAL);
3322 regs_buff[9] = er32(TDBAH);
3323 regs_buff[10] = er32(TDLEN);
3324 regs_buff[11] = er32(TDH);
3325 regs_buff[12] = er32(TDT);
3326 regs_buff[13] = er32(TIDV);
3327 regs_buff[14] = er32(TXDCTL);
3328 regs_buff[15] = er32(TADV);
3329 regs_buff[16] = er32(TARC0);
3330
3331 regs_buff[17] = er32(TDBAL1);
3332 regs_buff[18] = er32(TDBAH1);
3333 regs_buff[19] = er32(TDLEN1);
3334 regs_buff[20] = er32(TDH1);
3335 regs_buff[21] = er32(TDT1);
3336 regs_buff[22] = er32(TXDCTL1);
3337 regs_buff[23] = er32(TARC1);
3338 regs_buff[24] = er32(CTRL_EXT);
3339 regs_buff[25] = er32(ERT);
3340 regs_buff[26] = er32(RDBAL0);
3341 regs_buff[27] = er32(RDBAH0);
3342 regs_buff[28] = er32(TDFH);
3343 regs_buff[29] = er32(TDFT);
3344 regs_buff[30] = er32(TDFHS);
3345 regs_buff[31] = er32(TDFTS);
3346 regs_buff[32] = er32(TDFPC);
3347 regs_buff[33] = er32(RDFH);
3348 regs_buff[34] = er32(RDFT);
3349 regs_buff[35] = er32(RDFHS);
3350 regs_buff[36] = er32(RDFTS);
3351 regs_buff[37] = er32(RDFPC);
3352
3353 pr_info("Register dump\n");
Tushar Davee29b5d82012-02-10 08:06:36 +00003354 for (i = 0; i < NUM_REGS; i++)
3355 pr_info("%-15s %08x\n", reg_name[i], regs_buff[i]);
Tushar Daveb04e36b2012-01-27 09:00:46 +00003356}
3357
3358/*
3359 * e1000_dump: Print registers, tx ring and rx ring
3360 */
3361static void e1000_dump(struct e1000_adapter *adapter)
3362{
3363 /* this code doesn't handle multiple rings */
3364 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3365 struct e1000_rx_ring *rx_ring = adapter->rx_ring;
3366 int i;
3367
3368 if (!netif_msg_hw(adapter))
3369 return;
3370
3371 /* Print Registers */
3372 e1000_regdump(adapter);
3373
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003374 /* transmit dump */
Tushar Daveb04e36b2012-01-27 09:00:46 +00003375 pr_info("TX Desc ring0 dump\n");
3376
3377 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
3378 *
3379 * Legacy Transmit Descriptor
3380 * +--------------------------------------------------------------+
3381 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
3382 * +--------------------------------------------------------------+
3383 * 8 | Special | CSS | Status | CMD | CSO | Length |
3384 * +--------------------------------------------------------------+
3385 * 63 48 47 36 35 32 31 24 23 16 15 0
3386 *
3387 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
3388 * 63 48 47 40 39 32 31 16 15 8 7 0
3389 * +----------------------------------------------------------------+
3390 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
3391 * +----------------------------------------------------------------+
3392 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
3393 * +----------------------------------------------------------------+
3394 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
3395 *
3396 * Extended Data Descriptor (DTYP=0x1)
3397 * +----------------------------------------------------------------+
3398 * 0 | Buffer Address [63:0] |
3399 * +----------------------------------------------------------------+
3400 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
3401 * +----------------------------------------------------------------+
3402 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
3403 */
Tushar Davee29b5d82012-02-10 08:06:36 +00003404 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestmp bi->skb\n");
3405 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestmp bi->skb\n");
Tushar Daveb04e36b2012-01-27 09:00:46 +00003406
3407 if (!netif_msg_tx_done(adapter))
3408 goto rx_ring_summary;
3409
3410 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
3411 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
Florian Westphal580f3212014-09-03 13:34:31 +00003412 struct e1000_tx_buffer *buffer_info = &tx_ring->buffer_info[i];
Andrei Emeltchenkodd7f5c92012-03-25 17:49:25 +00003413 struct my_u { __le64 a; __le64 b; };
Tushar Daveb04e36b2012-01-27 09:00:46 +00003414 struct my_u *u = (struct my_u *)tx_desc;
Tushar Davee29b5d82012-02-10 08:06:36 +00003415 const char *type;
3416
Tushar Daveb04e36b2012-01-27 09:00:46 +00003417 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Tushar Davee29b5d82012-02-10 08:06:36 +00003418 type = "NTC/U";
Tushar Daveb04e36b2012-01-27 09:00:46 +00003419 else if (i == tx_ring->next_to_use)
Tushar Davee29b5d82012-02-10 08:06:36 +00003420 type = "NTU";
Tushar Daveb04e36b2012-01-27 09:00:46 +00003421 else if (i == tx_ring->next_to_clean)
Tushar Davee29b5d82012-02-10 08:06:36 +00003422 type = "NTC";
Tushar Daveb04e36b2012-01-27 09:00:46 +00003423 else
Tushar Davee29b5d82012-02-10 08:06:36 +00003424 type = "";
Tushar Daveb04e36b2012-01-27 09:00:46 +00003425
Tushar Davee29b5d82012-02-10 08:06:36 +00003426 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p %s\n",
3427 ((le64_to_cpu(u->b) & (1<<20)) ? 'd' : 'c'), i,
3428 le64_to_cpu(u->a), le64_to_cpu(u->b),
3429 (u64)buffer_info->dma, buffer_info->length,
3430 buffer_info->next_to_watch,
3431 (u64)buffer_info->time_stamp, buffer_info->skb, type);
Tushar Daveb04e36b2012-01-27 09:00:46 +00003432 }
3433
3434rx_ring_summary:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003435 /* receive dump */
Tushar Daveb04e36b2012-01-27 09:00:46 +00003436 pr_info("\nRX Desc ring dump\n");
3437
3438 /* Legacy Receive Descriptor Format
3439 *
3440 * +-----------------------------------------------------+
3441 * | Buffer Address [63:0] |
3442 * +-----------------------------------------------------+
3443 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
3444 * +-----------------------------------------------------+
3445 * 63 48 47 40 39 32 31 16 15 0
3446 */
Tushar Davee29b5d82012-02-10 08:06:36 +00003447 pr_info("R[desc] [address 63:0 ] [vl er S cks ln] [bi->dma ] [bi->skb]\n");
Tushar Daveb04e36b2012-01-27 09:00:46 +00003448
3449 if (!netif_msg_rx_status(adapter))
3450 goto exit;
3451
3452 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
3453 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
Florian Westphal93f0afe2014-09-03 13:34:26 +00003454 struct e1000_rx_buffer *buffer_info = &rx_ring->buffer_info[i];
Andrei Emeltchenkodd7f5c92012-03-25 17:49:25 +00003455 struct my_u { __le64 a; __le64 b; };
Tushar Daveb04e36b2012-01-27 09:00:46 +00003456 struct my_u *u = (struct my_u *)rx_desc;
Tushar Davee29b5d82012-02-10 08:06:36 +00003457 const char *type;
3458
Tushar Daveb04e36b2012-01-27 09:00:46 +00003459 if (i == rx_ring->next_to_use)
Tushar Davee29b5d82012-02-10 08:06:36 +00003460 type = "NTU";
Tushar Daveb04e36b2012-01-27 09:00:46 +00003461 else if (i == rx_ring->next_to_clean)
Tushar Davee29b5d82012-02-10 08:06:36 +00003462 type = "NTC";
Tushar Daveb04e36b2012-01-27 09:00:46 +00003463 else
Tushar Davee29b5d82012-02-10 08:06:36 +00003464 type = "";
Tushar Daveb04e36b2012-01-27 09:00:46 +00003465
Tushar Davee29b5d82012-02-10 08:06:36 +00003466 pr_info("R[0x%03X] %016llX %016llX %016llX %p %s\n",
3467 i, le64_to_cpu(u->a), le64_to_cpu(u->b),
Florian Westphal13809602014-09-03 13:34:36 +00003468 (u64)buffer_info->dma, buffer_info->rxbuf.data, type);
Tushar Daveb04e36b2012-01-27 09:00:46 +00003469 } /* for */
3470
3471 /* dump the descriptor caches */
3472 /* rx */
Tushar Davee29b5d82012-02-10 08:06:36 +00003473 pr_info("Rx descriptor cache in 64bit format\n");
Tushar Daveb04e36b2012-01-27 09:00:46 +00003474 for (i = 0x6000; i <= 0x63FF ; i += 0x10) {
Tushar Davee29b5d82012-02-10 08:06:36 +00003475 pr_info("R%04X: %08X|%08X %08X|%08X\n",
3476 i,
3477 readl(adapter->hw.hw_addr + i+4),
3478 readl(adapter->hw.hw_addr + i),
3479 readl(adapter->hw.hw_addr + i+12),
3480 readl(adapter->hw.hw_addr + i+8));
Tushar Daveb04e36b2012-01-27 09:00:46 +00003481 }
3482 /* tx */
Tushar Davee29b5d82012-02-10 08:06:36 +00003483 pr_info("Tx descriptor cache in 64bit format\n");
Tushar Daveb04e36b2012-01-27 09:00:46 +00003484 for (i = 0x7000; i <= 0x73FF ; i += 0x10) {
Tushar Davee29b5d82012-02-10 08:06:36 +00003485 pr_info("T%04X: %08X|%08X %08X|%08X\n",
3486 i,
3487 readl(adapter->hw.hw_addr + i+4),
3488 readl(adapter->hw.hw_addr + i),
3489 readl(adapter->hw.hw_addr + i+12),
3490 readl(adapter->hw.hw_addr + i+8));
Tushar Daveb04e36b2012-01-27 09:00:46 +00003491 }
3492exit:
3493 return;
3494}
3495
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496/**
3497 * e1000_tx_timeout - Respond to a Tx Hang
3498 * @netdev: network interface device structure
3499 **/
Joe Perches64798842008-07-11 15:17:02 -07003500static void e1000_tx_timeout(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003502 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503
3504 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003505 adapter->tx_timeout_count++;
3506 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507}
3508
Joe Perches64798842008-07-11 15:17:02 -07003509static void e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510{
David Howells65f27f32006-11-22 14:55:48 +00003511 struct e1000_adapter *adapter =
3512 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513
Tushar Daveb04e36b2012-01-27 09:00:46 +00003514 e_err(drv, "Reset adapter\n");
Vladimir Davydovb2f963bf2013-11-23 07:17:56 +00003515 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516}
3517
3518/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 * e1000_change_mtu - Change the Maximum Transfer Unit
3520 * @netdev: network interface device structure
3521 * @new_mtu: new value for maximum frame size
3522 *
3523 * Returns 0 on success, negative on failure
3524 **/
Joe Perches64798842008-07-11 15:17:02 -07003525static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003527 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07003528 struct e1000_hw *hw = &adapter->hw;
Jarod Wilson91c527a2016-10-17 15:54:05 -04003529 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003530
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003531 /* Adapter-specific max frame size limits. */
Joe Perches1dc32912008-07-11 15:17:08 -07003532 switch (hw->mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003533 case e1000_undefined ... e1000_82542_rev2_1:
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +00003534 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07003535 e_err(probe, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003536 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003537 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003538 break;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003539 default:
3540 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3541 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003542 }
3543
Jesse Brandeburg3d6114e2009-09-25 12:19:02 +00003544 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
3545 msleep(1);
3546 /* e1000_down has a dependency on max_frame_size */
3547 hw->max_frame_size = max_frame;
Sabrina Dubroca08e83312015-02-26 05:35:41 +00003548 if (netif_running(netdev)) {
3549 /* prevent buffers from being reallocated */
3550 adapter->alloc_rx_buf = e1000_alloc_dummy_rx_buffers;
Jesse Brandeburg3d6114e2009-09-25 12:19:02 +00003551 e1000_down(adapter);
Sabrina Dubroca08e83312015-02-26 05:35:41 +00003552 }
Jesse Brandeburg3d6114e2009-09-25 12:19:02 +00003553
David S. Miller87f50322006-07-31 22:39:40 -07003554 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003555 * means we reserve 2 more, this pushes us to allocate from the next
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003556 * larger slab size.
3557 * i.e. RXBUFFER_2048 --> size-4096 slab
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003558 * however with the new *_jumbo_rx* routines, jumbo receives will use
3559 * fragmented skbs
3560 */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003561
Jesse Brandeburg99261462010-01-22 22:56:16 +00003562 if (max_frame <= E1000_RXBUFFER_2048)
Auke Kok9e2feac2006-04-14 19:05:18 -07003563 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003564 else
3565#if (PAGE_SIZE >= E1000_RXBUFFER_16384)
Auke Kok9e2feac2006-04-14 19:05:18 -07003566 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003567#elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3568 adapter->rx_buffer_len = PAGE_SIZE;
3569#endif
Auke Kok9e2feac2006-04-14 19:05:18 -07003570
3571 /* adjust allocation if LPE protects us, and we aren't using SBP */
Joe Perches1dc32912008-07-11 15:17:08 -07003572 if (!hw->tbi_compatibility_on &&
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +00003573 ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
Auke Kok9e2feac2006-04-14 19:05:18 -07003574 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3575 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003576
Emil Tantilov675ad472010-04-27 14:02:58 +00003577 pr_info("%s changing MTU from %d to %d\n",
3578 netdev->name, netdev->mtu, new_mtu);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003579 netdev->mtu = new_mtu;
3580
Auke Kok2db10a02006-06-27 09:06:28 -07003581 if (netif_running(netdev))
Jesse Brandeburg3d6114e2009-09-25 12:19:02 +00003582 e1000_up(adapter);
3583 else
3584 e1000_reset(adapter);
3585
3586 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 return 0;
3589}
3590
3591/**
3592 * e1000_update_stats - Update the board statistics counters
3593 * @adapter: board private structure
3594 **/
Joe Perches64798842008-07-11 15:17:02 -07003595void e1000_update_stats(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596{
Ajit Khaparde5fe31de2009-10-07 02:42:23 +00003597 struct net_device *netdev = adapter->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003599 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07003601 u16 phy_tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602
3603#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3604
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003605 /* Prevent stats update while adapter is being reset, or if the pci
Linas Vepstas282f33c2006-06-08 22:19:44 -07003606 * connection is down.
3607 */
Auke Kok90267292006-06-08 09:30:24 -07003608 if (adapter->link_speed == 0)
3609 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003610 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003611 return;
Auke Kok90267292006-06-08 09:30:24 -07003612
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 spin_lock_irqsave(&adapter->stats_lock, flags);
3614
Masatake YAMATO828d0552007-10-20 03:06:37 +02003615 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616 * called from the interrupt context, so they must only
3617 * be written while holding adapter->stats_lock
3618 */
3619
Joe Perches1dc32912008-07-11 15:17:08 -07003620 adapter->stats.crcerrs += er32(CRCERRS);
3621 adapter->stats.gprc += er32(GPRC);
3622 adapter->stats.gorcl += er32(GORCL);
3623 adapter->stats.gorch += er32(GORCH);
3624 adapter->stats.bprc += er32(BPRC);
3625 adapter->stats.mprc += er32(MPRC);
3626 adapter->stats.roc += er32(ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003627
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003628 adapter->stats.prc64 += er32(PRC64);
3629 adapter->stats.prc127 += er32(PRC127);
3630 adapter->stats.prc255 += er32(PRC255);
3631 adapter->stats.prc511 += er32(PRC511);
3632 adapter->stats.prc1023 += er32(PRC1023);
3633 adapter->stats.prc1522 += er32(PRC1522);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634
Joe Perches1dc32912008-07-11 15:17:08 -07003635 adapter->stats.symerrs += er32(SYMERRS);
3636 adapter->stats.mpc += er32(MPC);
3637 adapter->stats.scc += er32(SCC);
3638 adapter->stats.ecol += er32(ECOL);
3639 adapter->stats.mcc += er32(MCC);
3640 adapter->stats.latecol += er32(LATECOL);
3641 adapter->stats.dc += er32(DC);
3642 adapter->stats.sec += er32(SEC);
3643 adapter->stats.rlec += er32(RLEC);
3644 adapter->stats.xonrxc += er32(XONRXC);
3645 adapter->stats.xontxc += er32(XONTXC);
3646 adapter->stats.xoffrxc += er32(XOFFRXC);
3647 adapter->stats.xofftxc += er32(XOFFTXC);
3648 adapter->stats.fcruc += er32(FCRUC);
3649 adapter->stats.gptc += er32(GPTC);
3650 adapter->stats.gotcl += er32(GOTCL);
3651 adapter->stats.gotch += er32(GOTCH);
3652 adapter->stats.rnbc += er32(RNBC);
3653 adapter->stats.ruc += er32(RUC);
3654 adapter->stats.rfc += er32(RFC);
3655 adapter->stats.rjc += er32(RJC);
3656 adapter->stats.torl += er32(TORL);
3657 adapter->stats.torh += er32(TORH);
3658 adapter->stats.totl += er32(TOTL);
3659 adapter->stats.toth += er32(TOTH);
3660 adapter->stats.tpr += er32(TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003661
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003662 adapter->stats.ptc64 += er32(PTC64);
3663 adapter->stats.ptc127 += er32(PTC127);
3664 adapter->stats.ptc255 += er32(PTC255);
3665 adapter->stats.ptc511 += er32(PTC511);
3666 adapter->stats.ptc1023 += er32(PTC1023);
3667 adapter->stats.ptc1522 += er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003668
Joe Perches1dc32912008-07-11 15:17:08 -07003669 adapter->stats.mptc += er32(MPTC);
3670 adapter->stats.bptc += er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671
3672 /* used for adaptive IFS */
3673
Joe Perches1dc32912008-07-11 15:17:08 -07003674 hw->tx_packet_delta = er32(TPT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 adapter->stats.tpt += hw->tx_packet_delta;
Joe Perches1dc32912008-07-11 15:17:08 -07003676 hw->collision_delta = er32(COLC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677 adapter->stats.colc += hw->collision_delta;
3678
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003679 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07003680 adapter->stats.algnerrc += er32(ALGNERRC);
3681 adapter->stats.rxerrc += er32(RXERRC);
3682 adapter->stats.tncrs += er32(TNCRS);
3683 adapter->stats.cexterr += er32(CEXTERR);
3684 adapter->stats.tsctc += er32(TSCTC);
3685 adapter->stats.tsctfc += er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 }
3687
3688 /* Fill out the OS statistics structure */
Ajit Khaparde5fe31de2009-10-07 02:42:23 +00003689 netdev->stats.multicast = adapter->stats.mprc;
3690 netdev->stats.collisions = adapter->stats.colc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691
3692 /* Rx Errors */
3693
Jeff Kirsher87041632006-03-02 18:21:24 -08003694 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003695 * our own version based on RUC and ROC
3696 */
Ajit Khaparde5fe31de2009-10-07 02:42:23 +00003697 netdev->stats.rx_errors = adapter->stats.rxerrc +
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003699 adapter->stats.ruc + adapter->stats.roc +
3700 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003701 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
Ajit Khaparde5fe31de2009-10-07 02:42:23 +00003702 netdev->stats.rx_length_errors = adapter->stats.rlerrc;
3703 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3704 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3705 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706
3707 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003708 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde5fe31de2009-10-07 02:42:23 +00003709 netdev->stats.tx_errors = adapter->stats.txerrc;
3710 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3711 netdev->stats.tx_window_errors = adapter->stats.latecol;
3712 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Joe Perches1dc32912008-07-11 15:17:08 -07003713 if (hw->bad_tx_carr_stats_fd &&
Jeff Garzik167fb282006-12-15 10:41:15 -05003714 adapter->link_duplex == FULL_DUPLEX) {
Ajit Khaparde5fe31de2009-10-07 02:42:23 +00003715 netdev->stats.tx_carrier_errors = 0;
Jeff Garzik167fb282006-12-15 10:41:15 -05003716 adapter->stats.tncrs = 0;
3717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718
3719 /* Tx Dropped needs to be maintained elsewhere */
3720
3721 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003722 if (hw->media_type == e1000_media_type_copper) {
3723 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3725 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3726 adapter->phy_stats.idle_errors += phy_tmp;
3727 }
3728
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003729 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 (hw->phy_type == e1000_phy_m88) &&
3731 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3732 adapter->phy_stats.receive_errors += phy_tmp;
3733 }
3734
Jeff Garzik15e376b2006-12-15 11:16:33 -05003735 /* Management Stats */
Joe Perches1dc32912008-07-11 15:17:08 -07003736 if (hw->has_smbus) {
3737 adapter->stats.mgptc += er32(MGTPTC);
3738 adapter->stats.mgprc += er32(MGTPRC);
3739 adapter->stats.mgpdc += er32(MGTPDC);
Jeff Garzik15e376b2006-12-15 11:16:33 -05003740 }
3741
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3743}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003744
3745/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 * e1000_intr - Interrupt Handler
3747 * @irq: interrupt number
3748 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 **/
Joe Perches64798842008-07-11 15:17:02 -07003750static irqreturn_t e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751{
3752 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003753 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003755 u32 icr = er32(ICR);
Francois Romieuc3570ac2008-07-11 15:17:38 -07003756
Jesse Brandeburg4c11b8a2011-01-13 07:48:13 +00003757 if (unlikely((!icr)))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003758 return IRQ_NONE; /* Not our interrupt */
3759
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003760 /* we might have caused the interrupt, but the above
Jesse Brandeburg4c11b8a2011-01-13 07:48:13 +00003761 * read cleared it, and just in case the driver is
3762 * down there is nothing to do so return handled
3763 */
3764 if (unlikely(test_bit(__E1000_DOWN, &adapter->flags)))
3765 return IRQ_HANDLED;
3766
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003767 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 hw->get_link_status = 1;
Auke Kok1314bbf2006-09-27 12:54:02 -07003769 /* guard against interrupt when we're going down */
3770 if (!test_bit(__E1000_DOWN, &adapter->flags))
Jesse Brandeburga4010af2011-10-05 07:24:41 +00003771 schedule_delayed_work(&adapter->watchdog_task, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 }
3773
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003774 /* disable interrupts, without the synchronize_irq bit */
3775 ew32(IMC, ~0);
3776 E1000_WRITE_FLUSH();
3777
Ben Hutchings288379f2009-01-19 16:43:59 -08003778 if (likely(napi_schedule_prep(&adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003779 adapter->total_tx_bytes = 0;
3780 adapter->total_tx_packets = 0;
3781 adapter->total_rx_bytes = 0;
3782 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08003783 __napi_schedule(&adapter->napi);
Jesse Brandeburga6c42322009-03-25 21:59:22 +00003784 } else {
Auke Kok90fb5132006-11-01 08:47:30 -08003785 /* this really should not happen! if it does it is basically a
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003786 * bug, but not a hard error, so enable ints and continue
3787 */
Jesse Brandeburga6c42322009-03-25 21:59:22 +00003788 if (!test_bit(__E1000_DOWN, &adapter->flags))
3789 e1000_irq_enable(adapter);
3790 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 return IRQ_HANDLED;
3793}
3794
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795/**
3796 * e1000_clean - NAPI Rx polling callback
3797 * @adapter: board private structure
3798 **/
Joe Perches64798842008-07-11 15:17:02 -07003799static int e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003801 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
3802 napi);
Jesse Brandeburg650b5a52009-09-25 12:19:23 +00003803 int tx_clean_complete = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003804
Jesse Brandeburg650b5a52009-09-25 12:19:23 +00003805 tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003806
Jesse Brandeburg650b5a52009-09-25 12:19:23 +00003807 adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003808
Jesse Brandeburg650b5a52009-09-25 12:19:23 +00003809 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003810 work_done = budget;
3811
David S. Miller53e52c72008-01-07 21:06:12 -08003812 /* If budget not fully consumed, exit the polling mode */
3813 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003814 if (likely(adapter->itr_setting & 3))
3815 e1000_set_itr(adapter);
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003816 napi_complete_done(napi, work_done);
Jesse Brandeburga6c42322009-03-25 21:59:22 +00003817 if (!test_bit(__E1000_DOWN, &adapter->flags))
3818 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 }
3820
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003821 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822}
3823
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824/**
3825 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3826 * @adapter: board private structure
3827 **/
Joe Perches64798842008-07-11 15:17:02 -07003828static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3829 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830{
Joe Perches1dc32912008-07-11 15:17:08 -07003831 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 struct net_device *netdev = adapter->netdev;
3833 struct e1000_tx_desc *tx_desc, *eop_desc;
Florian Westphal580f3212014-09-03 13:34:31 +00003834 struct e1000_tx_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003836 unsigned int count = 0;
Janusz Wolaka48954c2015-09-17 23:34:29 +02003837 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Otto Estuardo Solares Cabrera2f66fd32012-08-24 08:04:58 +00003838 unsigned int bytes_compl = 0, pkts_compl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839
3840 i = tx_ring->next_to_clean;
3841 eop = tx_ring->buffer_info[i].next_to_watch;
3842 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3843
Alexander Duyckccfb3422009-03-25 21:59:04 +00003844 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3845 (count < tx_ring->count)) {
Jesse Brandeburg843f4262009-04-16 16:59:47 +00003846 bool cleaned = false;
Alexander Duyck837a1db2015-04-07 16:55:27 -07003847 dma_rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburg843f4262009-04-16 16:59:47 +00003848 for ( ; !cleaned; count++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 tx_desc = E1000_TX_DESC(*tx_ring, i);
3850 buffer_info = &tx_ring->buffer_info[i];
3851 cleaned = (i == eop);
3852
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003853 if (cleaned) {
Dean Nelson31c15a22011-08-25 14:39:24 +00003854 total_tx_packets += buffer_info->segs;
3855 total_tx_bytes += buffer_info->bytecount;
Otto Estuardo Solares Cabrera2f66fd32012-08-24 08:04:58 +00003856 if (buffer_info->skb) {
3857 bytes_compl += buffer_info->skb->len;
3858 pkts_compl++;
3859 }
3860
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003861 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05003862 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003863 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864
Janusz Wolaka48954c2015-09-17 23:34:29 +02003865 if (unlikely(++i == tx_ring->count))
3866 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003868
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 eop = tx_ring->buffer_info[i].next_to_watch;
3870 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3871 }
3872
Dmitriy Vyukov9eab46b2015-09-08 10:52:44 +02003873 /* Synchronize with E1000_DESC_UNUSED called from e1000_xmit_frame,
3874 * which will reuse the cleaned buffers.
3875 */
3876 smp_store_release(&tx_ring->next_to_clean, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877
Otto Estuardo Solares Cabrera2f66fd32012-08-24 08:04:58 +00003878 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
3879
Auke Kok77b2aad2006-04-14 19:05:25 -07003880#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg843f4262009-04-16 16:59:47 +00003881 if (unlikely(count && netif_carrier_ok(netdev) &&
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003882 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3883 /* Make sure that anybody stopping the queue after this
3884 * sees the new next_to_clean.
3885 */
3886 smp_mb();
Jesse Brandeburgcdd75492009-09-25 12:18:07 +00003887
3888 if (netif_queue_stopped(netdev) &&
3889 !(test_bit(__E1000_DOWN, &adapter->flags))) {
Auke Kok77b2aad2006-04-14 19:05:25 -07003890 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003891 ++adapter->restart_queue;
3892 }
Auke Kok77b2aad2006-04-14 19:05:25 -07003893 }
Malli Chilakala26483452005-04-28 19:44:46 -07003894
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003895 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003896 /* Detect a transmit hang in hardware, this serializes the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003897 * check with the clearing of time_stamp and movement of i
3898 */
Joe Perchesc3033b02008-03-21 11:06:25 -07003899 adapter->detect_tx_hung = false;
Jesse Brandeburgcdd75492009-09-25 12:18:07 +00003900 if (tx_ring->buffer_info[eop].time_stamp &&
3901 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003902 (adapter->tx_timeout_factor * HZ)) &&
Joe Perches8e95a202009-12-03 07:58:21 +00003903 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003904
3905 /* detected Tx unit hang */
Emil Tantilovfeb8f472010-07-26 23:37:21 -07003906 e_err(drv, "Detected Tx Unit Hang\n"
Emil Tantilov675ad472010-04-27 14:02:58 +00003907 " Tx Queue <%lu>\n"
3908 " TDH <%x>\n"
3909 " TDT <%x>\n"
3910 " next_to_use <%x>\n"
3911 " next_to_clean <%x>\n"
3912 "buffer_info[next_to_clean]\n"
3913 " time_stamp <%lx>\n"
3914 " next_to_watch <%x>\n"
3915 " jiffies <%lx>\n"
3916 " next_to_watch.status <%x>\n",
Hong Zhiguo49a45a02013-10-22 18:32:56 +00003917 (unsigned long)(tx_ring - adapter->tx_ring),
Joe Perches1dc32912008-07-11 15:17:08 -07003918 readl(hw->hw_addr + tx_ring->tdh),
3919 readl(hw->hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003920 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003921 tx_ring->next_to_clean,
Jesse Brandeburgcdd75492009-09-25 12:18:07 +00003922 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003923 eop,
3924 jiffies,
3925 eop_desc->upper.fields.status);
Tushar Daveb04e36b2012-01-27 09:00:46 +00003926 e1000_dump(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003930 adapter->total_tx_bytes += total_tx_bytes;
3931 adapter->total_tx_packets += total_tx_packets;
Ajit Khaparde5fe31de2009-10-07 02:42:23 +00003932 netdev->stats.tx_bytes += total_tx_bytes;
3933 netdev->stats.tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00003934 return count < tx_ring->count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935}
3936
3937/**
3938 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003939 * @adapter: board private structure
3940 * @status_err: receive descriptor status and error fields
3941 * @csum: receive descriptor csum field
3942 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 **/
Joe Perches64798842008-07-11 15:17:02 -07003944static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3945 u32 csum, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946{
Joe Perches1dc32912008-07-11 15:17:08 -07003947 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003948 u16 status = (u16)status_err;
3949 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -07003950
3951 skb_checksum_none_assert(skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003952
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 /* 82543 or newer only */
Janusz Wolaka48954c2015-09-17 23:34:29 +02003954 if (unlikely(hw->mac_type < e1000_82543))
3955 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 /* Ignore Checksum bit is set */
Janusz Wolaka48954c2015-09-17 23:34:29 +02003957 if (unlikely(status & E1000_RXD_STAT_IXSM))
3958 return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003959 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003960 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003961 /* let the stack verify checksum errors */
3962 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 return;
3964 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003965 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003966 if (!(status & E1000_RXD_STAT_TCPCS))
3967 return;
3968
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003969 /* It must be a TCP or UDP packet with a valid checksum */
3970 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 /* TCP checksum is good */
3972 skb->ip_summed = CHECKSUM_UNNECESSARY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003974 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975}
3976
3977/**
Florian Westphal13809602014-09-03 13:34:36 +00003978 * e1000_consume_page - helper function for jumbo Rx path
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003979 **/
Florian Westphal93f0afe2014-09-03 13:34:26 +00003980static void e1000_consume_page(struct e1000_rx_buffer *bi, struct sk_buff *skb,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003981 u16 length)
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003982{
Florian Westphal13809602014-09-03 13:34:36 +00003983 bi->rxbuf.page = NULL;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003984 skb->len += length;
3985 skb->data_len += length;
Eric Dumazeted64b3c2011-10-13 07:53:42 +00003986 skb->truesize += PAGE_SIZE;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003987}
3988
3989/**
3990 * e1000_receive_skb - helper function to handle rx indications
3991 * @adapter: board private structure
3992 * @status: descriptor status field as written by hardware
3993 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
3994 * @skb: pointer to sk_buff to be indicated to stack
3995 */
3996static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
3997 __le16 vlan, struct sk_buff *skb)
3998{
Jesse Brandeburg6a08d192010-09-22 18:23:05 +00003999 skb->protocol = eth_type_trans(skb, adapter->netdev);
4000
Jiri Pirko5622e402011-07-21 03:26:31 +00004001 if (status & E1000_RXD_STAT_VP) {
4002 u16 vid = le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
4003
Patrick McHardy86a9bad2013-04-19 02:04:30 +00004004 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Jiri Pirko5622e402011-07-21 03:26:31 +00004005 }
4006 napi_gro_receive(&adapter->napi, skb);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004007}
4008
4009/**
Florian Westphal4f0aeb12014-09-03 13:34:10 +00004010 * e1000_tbi_adjust_stats
4011 * @hw: Struct containing variables accessed by shared code
4012 * @frame_len: The length of the frame in question
4013 * @mac_addr: The Ethernet destination address of the frame in question
4014 *
4015 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4016 */
4017static void e1000_tbi_adjust_stats(struct e1000_hw *hw,
4018 struct e1000_hw_stats *stats,
4019 u32 frame_len, const u8 *mac_addr)
4020{
4021 u64 carry_bit;
4022
4023 /* First adjust the frame length. */
4024 frame_len--;
4025 /* We need to adjust the statistics counters, since the hardware
4026 * counters overcount this packet as a CRC error and undercount
4027 * the packet as a good packet
4028 */
4029 /* This packet should not be counted as a CRC error. */
4030 stats->crcerrs--;
4031 /* This packet does count as a Good Packet Received. */
4032 stats->gprc++;
4033
4034 /* Adjust the Good Octets received counters */
4035 carry_bit = 0x80000000 & stats->gorcl;
4036 stats->gorcl += frame_len;
4037 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4038 * Received Count) was one before the addition,
4039 * AND it is zero after, then we lost the carry out,
4040 * need to add one to Gorch (Good Octets Received Count High).
4041 * This could be simplified if all environments supported
4042 * 64-bit integers.
4043 */
4044 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4045 stats->gorch++;
4046 /* Is this a broadcast or multicast? Check broadcast first,
4047 * since the test for a multicast frame will test positive on
4048 * a broadcast frame.
4049 */
4050 if (is_broadcast_ether_addr(mac_addr))
4051 stats->bprc++;
4052 else if (is_multicast_ether_addr(mac_addr))
4053 stats->mprc++;
4054
4055 if (frame_len == hw->max_frame_size) {
4056 /* In this case, the hardware has overcounted the number of
4057 * oversize frames.
4058 */
4059 if (stats->roc > 0)
4060 stats->roc--;
4061 }
4062
4063 /* Adjust the bin counters when the extra byte put the frame in the
4064 * wrong bin. Remember that the frame_len was adjusted above.
4065 */
4066 if (frame_len == 64) {
4067 stats->prc64++;
4068 stats->prc127--;
4069 } else if (frame_len == 127) {
4070 stats->prc127++;
4071 stats->prc255--;
4072 } else if (frame_len == 255) {
4073 stats->prc255++;
4074 stats->prc511--;
4075 } else if (frame_len == 511) {
4076 stats->prc511++;
4077 stats->prc1023--;
4078 } else if (frame_len == 1023) {
4079 stats->prc1023++;
4080 stats->prc1522--;
4081 } else if (frame_len == 1522) {
4082 stats->prc1522++;
4083 }
4084}
4085
Florian Westphal20371102014-09-03 13:34:15 +00004086static bool e1000_tbi_should_accept(struct e1000_adapter *adapter,
4087 u8 status, u8 errors,
4088 u32 length, const u8 *data)
4089{
4090 struct e1000_hw *hw = &adapter->hw;
4091 u8 last_byte = *(data + length - 1);
4092
4093 if (TBI_ACCEPT(hw, status, errors, length, last_byte)) {
4094 unsigned long irq_flags;
4095
4096 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
4097 e1000_tbi_adjust_stats(hw, &adapter->stats, length, data);
4098 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
4099
4100 return true;
4101 }
4102
4103 return false;
4104}
4105
Florian Westphal2b294b12014-09-03 13:34:21 +00004106static struct sk_buff *e1000_alloc_rx_skb(struct e1000_adapter *adapter,
4107 unsigned int bufsz)
4108{
Alexander Duyck67fd8932014-12-09 19:40:56 -08004109 struct sk_buff *skb = napi_alloc_skb(&adapter->napi, bufsz);
Florian Westphal2b294b12014-09-03 13:34:21 +00004110
4111 if (unlikely(!skb))
4112 adapter->alloc_rx_buff_failed++;
4113 return skb;
4114}
4115
Florian Westphal4f0aeb12014-09-03 13:34:10 +00004116/**
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004117 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
4118 * @adapter: board private structure
4119 * @rx_ring: ring to clean
4120 * @work_done: amount of napi work completed this call
4121 * @work_to_do: max amount of work allowed for this call to do
4122 *
4123 * the return value indicates whether actual cleaning was done, there
4124 * is no guarantee that everything was cleaned
4125 */
4126static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
4127 struct e1000_rx_ring *rx_ring,
4128 int *work_done, int work_to_do)
4129{
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004130 struct net_device *netdev = adapter->netdev;
4131 struct pci_dev *pdev = adapter->pdev;
4132 struct e1000_rx_desc *rx_desc, *next_rxd;
Florian Westphal93f0afe2014-09-03 13:34:26 +00004133 struct e1000_rx_buffer *buffer_info, *next_buffer;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004134 u32 length;
4135 unsigned int i;
4136 int cleaned_count = 0;
4137 bool cleaned = false;
Janusz Wolaka48954c2015-09-17 23:34:29 +02004138 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004139
4140 i = rx_ring->next_to_clean;
4141 rx_desc = E1000_RX_DESC(*rx_ring, i);
4142 buffer_info = &rx_ring->buffer_info[i];
4143
4144 while (rx_desc->status & E1000_RXD_STAT_DD) {
4145 struct sk_buff *skb;
4146 u8 status;
4147
4148 if (*work_done >= work_to_do)
4149 break;
4150 (*work_done)++;
Alexander Duyck837a1db2015-04-07 16:55:27 -07004151 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004152
4153 status = rx_desc->status;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004154
Janusz Wolaka48954c2015-09-17 23:34:29 +02004155 if (++i == rx_ring->count)
4156 i = 0;
4157
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004158 next_rxd = E1000_RX_DESC(*rx_ring, i);
4159 prefetch(next_rxd);
4160
4161 next_buffer = &rx_ring->buffer_info[i];
4162
4163 cleaned = true;
4164 cleaned_count++;
Nick Nunleyb16f53b2010-04-27 13:08:45 +00004165 dma_unmap_page(&pdev->dev, buffer_info->dma,
Florian Westphal93f0afe2014-09-03 13:34:26 +00004166 adapter->rx_buffer_len, DMA_FROM_DEVICE);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004167 buffer_info->dma = 0;
4168
4169 length = le16_to_cpu(rx_desc->length);
4170
4171 /* errors is only valid for DD + EOP descriptors */
4172 if (unlikely((status & E1000_RXD_STAT_EOP) &&
4173 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
Florian Westphal13809602014-09-03 13:34:36 +00004174 u8 *mapped = page_address(buffer_info->rxbuf.page);
Sebastian Andrzej Siewiora3060852012-05-11 16:30:46 +00004175
Florian Westphal20371102014-09-03 13:34:15 +00004176 if (e1000_tbi_should_accept(adapter, status,
4177 rx_desc->errors,
4178 length, mapped)) {
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004179 length--;
Florian Westphal20371102014-09-03 13:34:15 +00004180 } else if (netdev->features & NETIF_F_RXALL) {
4181 goto process_skb;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004182 } else {
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004183 /* an error means any chain goes out the window
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004184 * too
4185 */
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004186 if (rx_ring->rx_skb_top)
4187 dev_kfree_skb(rx_ring->rx_skb_top);
4188 rx_ring->rx_skb_top = NULL;
4189 goto next_desc;
4190 }
4191 }
4192
4193#define rxtop rx_ring->rx_skb_top
Ben Greeare825b732012-04-04 06:01:29 +00004194process_skb:
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004195 if (!(status & E1000_RXD_STAT_EOP)) {
4196 /* this descriptor is only the beginning (or middle) */
4197 if (!rxtop) {
4198 /* this is the beginning of a chain */
Florian Westphalde591c72014-09-03 13:34:42 +00004199 rxtop = napi_get_frags(&adapter->napi);
Florian Westphal13809602014-09-03 13:34:36 +00004200 if (!rxtop)
4201 break;
4202
4203 skb_fill_page_desc(rxtop, 0,
4204 buffer_info->rxbuf.page,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004205 0, length);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004206 } else {
4207 /* this is the middle of a chain */
4208 skb_fill_page_desc(rxtop,
4209 skb_shinfo(rxtop)->nr_frags,
Florian Westphal13809602014-09-03 13:34:36 +00004210 buffer_info->rxbuf.page, 0, length);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004211 }
4212 e1000_consume_page(buffer_info, rxtop, length);
4213 goto next_desc;
4214 } else {
4215 if (rxtop) {
4216 /* end of the chain */
4217 skb_fill_page_desc(rxtop,
4218 skb_shinfo(rxtop)->nr_frags,
Florian Westphal13809602014-09-03 13:34:36 +00004219 buffer_info->rxbuf.page, 0, length);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004220 skb = rxtop;
4221 rxtop = NULL;
4222 e1000_consume_page(buffer_info, skb, length);
4223 } else {
Florian Westphal13809602014-09-03 13:34:36 +00004224 struct page *p;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004225 /* no chain, got EOP, this buf is the packet
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004226 * copybreak to save the put_page/alloc_page
4227 */
Florian Westphal13809602014-09-03 13:34:36 +00004228 p = buffer_info->rxbuf.page;
Florian Westphalde591c72014-09-03 13:34:42 +00004229 if (length <= copybreak) {
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004230 u8 *vaddr;
Florian Westphal13809602014-09-03 13:34:36 +00004231
Florian Westphalde591c72014-09-03 13:34:42 +00004232 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4233 length -= 4;
4234 skb = e1000_alloc_rx_skb(adapter,
4235 length);
4236 if (!skb)
4237 break;
4238
Florian Westphal13809602014-09-03 13:34:36 +00004239 vaddr = kmap_atomic(p);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004240 memcpy(skb_tail_pointer(skb), vaddr,
4241 length);
Cong Wang46790262011-11-25 23:14:23 +08004242 kunmap_atomic(vaddr);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004243 /* re-use the page, so don't erase
Florian Westphal13809602014-09-03 13:34:36 +00004244 * buffer_info->rxbuf.page
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004245 */
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004246 skb_put(skb, length);
Florian Westphalde591c72014-09-03 13:34:42 +00004247 e1000_rx_checksum(adapter,
4248 status | rx_desc->errors << 24,
4249 le16_to_cpu(rx_desc->csum), skb);
4250
4251 total_rx_bytes += skb->len;
4252 total_rx_packets++;
4253
4254 e1000_receive_skb(adapter, status,
4255 rx_desc->special, skb);
4256 goto next_desc;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004257 } else {
Florian Westphalde591c72014-09-03 13:34:42 +00004258 skb = napi_get_frags(&adapter->napi);
4259 if (!skb) {
4260 adapter->alloc_rx_buff_failed++;
4261 break;
4262 }
Florian Westphal13809602014-09-03 13:34:36 +00004263 skb_fill_page_desc(skb, 0, p, 0,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004264 length);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004265 e1000_consume_page(buffer_info, skb,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004266 length);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004267 }
4268 }
4269 }
4270
4271 /* Receive Checksum Offload XXX recompute due to CRC strip? */
4272 e1000_rx_checksum(adapter,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004273 (u32)(status) |
4274 ((u32)(rx_desc->errors) << 24),
4275 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004276
Ben Greearb0d15622012-02-11 15:40:11 +00004277 total_rx_bytes += (skb->len - 4); /* don't count FCS */
4278 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4279 pskb_trim(skb, skb->len - 4);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004280 total_rx_packets++;
4281
Florian Westphalde591c72014-09-03 13:34:42 +00004282 if (status & E1000_RXD_STAT_VP) {
4283 __le16 vlan = rx_desc->special;
4284 u16 vid = le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
4285
4286 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004287 }
4288
Florian Westphalde591c72014-09-03 13:34:42 +00004289 napi_gro_frags(&adapter->napi);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004290
4291next_desc:
4292 rx_desc->status = 0;
4293
4294 /* return some buffers to hardware, one at a time is too slow */
4295 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4296 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4297 cleaned_count = 0;
4298 }
4299
4300 /* use prefetched values */
4301 rx_desc = next_rxd;
4302 buffer_info = next_buffer;
4303 }
4304 rx_ring->next_to_clean = i;
4305
4306 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4307 if (cleaned_count)
4308 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4309
4310 adapter->total_rx_packets += total_rx_packets;
4311 adapter->total_rx_bytes += total_rx_bytes;
Ajit Khaparde5fe31de2009-10-07 02:42:23 +00004312 netdev->stats.rx_bytes += total_rx_bytes;
4313 netdev->stats.rx_packets += total_rx_packets;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004314 return cleaned;
4315}
4316
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004317/* this should improve performance for small packets with large amounts
Joe Perches57bf6ee2010-05-13 15:26:17 +00004318 * of reassembly being done in the stack
4319 */
Florian Westphal2b294b12014-09-03 13:34:21 +00004320static struct sk_buff *e1000_copybreak(struct e1000_adapter *adapter,
Florian Westphal93f0afe2014-09-03 13:34:26 +00004321 struct e1000_rx_buffer *buffer_info,
Florian Westphal2b294b12014-09-03 13:34:21 +00004322 u32 length, const void *data)
Joe Perches57bf6ee2010-05-13 15:26:17 +00004323{
Florian Westphal2b294b12014-09-03 13:34:21 +00004324 struct sk_buff *skb;
Joe Perches57bf6ee2010-05-13 15:26:17 +00004325
4326 if (length > copybreak)
Florian Westphal2b294b12014-09-03 13:34:21 +00004327 return NULL;
Joe Perches57bf6ee2010-05-13 15:26:17 +00004328
Florian Westphal2b294b12014-09-03 13:34:21 +00004329 skb = e1000_alloc_rx_skb(adapter, length);
4330 if (!skb)
4331 return NULL;
Joe Perches57bf6ee2010-05-13 15:26:17 +00004332
Florian Westphal2b294b12014-09-03 13:34:21 +00004333 dma_sync_single_for_cpu(&adapter->pdev->dev, buffer_info->dma,
4334 length, DMA_FROM_DEVICE);
4335
Johannes Berg59ae1d12017-06-16 14:29:20 +02004336 skb_put_data(skb, data, length);
Florian Westphal2b294b12014-09-03 13:34:21 +00004337
4338 return skb;
Joe Perches57bf6ee2010-05-13 15:26:17 +00004339}
4340
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004341/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004342 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 * @adapter: board private structure
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004344 * @rx_ring: ring to clean
4345 * @work_done: amount of napi work completed this call
4346 * @work_to_do: max amount of work allowed for this call to do
4347 */
Joe Perches64798842008-07-11 15:17:02 -07004348static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4349 struct e1000_rx_ring *rx_ring,
4350 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 struct net_device *netdev = adapter->netdev;
4353 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004354 struct e1000_rx_desc *rx_desc, *next_rxd;
Florian Westphal93f0afe2014-09-03 13:34:26 +00004355 struct e1000_rx_buffer *buffer_info, *next_buffer;
Joe Perches406874a2008-04-03 10:06:32 -07004356 u32 length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004358 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004359 bool cleaned = false;
Janusz Wolaka48954c2015-09-17 23:34:29 +02004360 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361
4362 i = rx_ring->next_to_clean;
4363 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004364 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004366 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004367 struct sk_buff *skb;
Florian Westphal13809602014-09-03 13:34:36 +00004368 u8 *data;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004369 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004370
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004371 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 break;
4373 (*work_done)++;
Alexander Duyck837a1db2015-04-07 16:55:27 -07004374 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
Francois Romieuc3570ac2008-07-11 15:17:38 -07004375
Jeff Kirshera292ca62006-01-12 16:51:30 -08004376 status = rx_desc->status;
Florian Westphal2b294b12014-09-03 13:34:21 +00004377 length = le16_to_cpu(rx_desc->length);
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004378
Florian Westphal13809602014-09-03 13:34:36 +00004379 data = buffer_info->rxbuf.data;
4380 prefetch(data);
4381 skb = e1000_copybreak(adapter, buffer_info, length, data);
Florian Westphal2b294b12014-09-03 13:34:21 +00004382 if (!skb) {
Florian Westphal13809602014-09-03 13:34:36 +00004383 unsigned int frag_len = e1000_frag_len(adapter);
4384
4385 skb = build_skb(data - E1000_HEADROOM, frag_len);
4386 if (!skb) {
4387 adapter->alloc_rx_buff_failed++;
4388 break;
4389 }
4390
4391 skb_reserve(skb, E1000_HEADROOM);
Florian Westphal2b294b12014-09-03 13:34:21 +00004392 dma_unmap_single(&pdev->dev, buffer_info->dma,
Florian Westphal93f0afe2014-09-03 13:34:26 +00004393 adapter->rx_buffer_len,
4394 DMA_FROM_DEVICE);
Florian Westphal2b294b12014-09-03 13:34:21 +00004395 buffer_info->dma = 0;
Florian Westphal13809602014-09-03 13:34:36 +00004396 buffer_info->rxbuf.data = NULL;
Florian Westphal2b294b12014-09-03 13:34:21 +00004397 }
Jeff Kirsher30320be2006-03-02 18:21:57 -08004398
Janusz Wolaka48954c2015-09-17 23:34:29 +02004399 if (++i == rx_ring->count)
4400 i = 0;
4401
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004402 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004403 prefetch(next_rxd);
4404
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004405 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004406
Joe Perchesc3033b02008-03-21 11:06:25 -07004407 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004408 cleaned_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409
Neil Hormanea30e112009-06-02 01:29:58 -07004410 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburg40a14de2010-01-19 14:15:38 +00004411 * packet, if thats the case we need to toss it. In fact, we
4412 * to toss every packet with the EOP bit clear and the next
4413 * frame that _does_ have the EOP bit set, as it is by
4414 * definition only a frame fragment
4415 */
4416 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
4417 adapter->discarding = true;
4418
4419 if (adapter->discarding) {
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004420 /* All receives must fit into a single buffer */
Florian Westphal20371102014-09-03 13:34:15 +00004421 netdev_dbg(netdev, "Receive packet consumed multiple buffers\n");
Florian Westphal2b294b12014-09-03 13:34:21 +00004422 dev_kfree_skb(skb);
Jesse Brandeburg40a14de2010-01-19 14:15:38 +00004423 if (status & E1000_RXD_STAT_EOP)
4424 adapter->discarding = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 goto next_desc;
4426 }
4427
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004428 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Florian Westphal20371102014-09-03 13:34:15 +00004429 if (e1000_tbi_should_accept(adapter, status,
4430 rx_desc->errors,
Florian Westphal13809602014-09-03 13:34:36 +00004431 length, data)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432 length--;
Florian Westphal20371102014-09-03 13:34:15 +00004433 } else if (netdev->features & NETIF_F_RXALL) {
4434 goto process_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 } else {
Florian Westphal2b294b12014-09-03 13:34:21 +00004436 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 goto next_desc;
4438 }
Auke Kok1cb58212006-04-18 12:31:04 -07004439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440
Ben Greeare825b732012-04-04 06:01:29 +00004441process_skb:
Ben Greearb0d15622012-02-11 15:40:11 +00004442 total_rx_bytes += (length - 4); /* don't count FCS */
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004443 total_rx_packets++;
4444
Ben Greearb0d15622012-02-11 15:40:11 +00004445 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4446 /* adjust length to remove Ethernet CRC, this must be
4447 * done after the TBI_ACCEPT workaround above
4448 */
4449 length -= 4;
4450
Florian Westphal13809602014-09-03 13:34:36 +00004451 if (buffer_info->rxbuf.data == NULL)
Florian Westphal2b294b12014-09-03 13:34:21 +00004452 skb_put(skb, length);
4453 else /* copybreak skb */
4454 skb_trim(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455
4456 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004457 e1000_rx_checksum(adapter,
Joe Perches406874a2008-04-03 10:06:32 -07004458 (u32)(status) |
4459 ((u32)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004460 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004461
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004462 e1000_receive_skb(adapter, status, rx_desc->special, skb);
Francois Romieuc3570ac2008-07-11 15:17:38 -07004463
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464next_desc:
4465 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004467 /* return some buffers to hardware, one at a time is too slow */
4468 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4469 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4470 cleaned_count = 0;
4471 }
4472
Jeff Kirsher30320be2006-03-02 18:21:57 -08004473 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004474 rx_desc = next_rxd;
4475 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004478
4479 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4480 if (cleaned_count)
4481 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004483 adapter->total_rx_packets += total_rx_packets;
4484 adapter->total_rx_bytes += total_rx_bytes;
Ajit Khaparde5fe31de2009-10-07 02:42:23 +00004485 netdev->stats.rx_bytes += total_rx_bytes;
4486 netdev->stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 return cleaned;
4488}
4489
4490/**
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004491 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4492 * @adapter: address of board private structure
4493 * @rx_ring: pointer to receive ring structure
4494 * @cleaned_count: number of buffers to allocate this pass
4495 **/
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004496static void
4497e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004498 struct e1000_rx_ring *rx_ring, int cleaned_count)
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004499{
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004500 struct pci_dev *pdev = adapter->pdev;
4501 struct e1000_rx_desc *rx_desc;
Florian Westphal93f0afe2014-09-03 13:34:26 +00004502 struct e1000_rx_buffer *buffer_info;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004503 unsigned int i;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004504
4505 i = rx_ring->next_to_use;
4506 buffer_info = &rx_ring->buffer_info[i];
4507
4508 while (cleaned_count--) {
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004509 /* allocate a new page if necessary */
Florian Westphal13809602014-09-03 13:34:36 +00004510 if (!buffer_info->rxbuf.page) {
4511 buffer_info->rxbuf.page = alloc_page(GFP_ATOMIC);
4512 if (unlikely(!buffer_info->rxbuf.page)) {
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004513 adapter->alloc_rx_buff_failed++;
4514 break;
4515 }
4516 }
4517
Anton Blanchardb5abb022010-02-19 17:54:53 +00004518 if (!buffer_info->dma) {
Nick Nunleyb16f53b2010-04-27 13:08:45 +00004519 buffer_info->dma = dma_map_page(&pdev->dev,
Florian Westphal13809602014-09-03 13:34:36 +00004520 buffer_info->rxbuf.page, 0,
4521 adapter->rx_buffer_len,
Nick Nunleyb16f53b2010-04-27 13:08:45 +00004522 DMA_FROM_DEVICE);
4523 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Florian Westphal13809602014-09-03 13:34:36 +00004524 put_page(buffer_info->rxbuf.page);
4525 buffer_info->rxbuf.page = NULL;
Anton Blanchardb5abb022010-02-19 17:54:53 +00004526 buffer_info->dma = 0;
4527 adapter->alloc_rx_buff_failed++;
Florian Westphal13809602014-09-03 13:34:36 +00004528 break;
Anton Blanchardb5abb022010-02-19 17:54:53 +00004529 }
4530 }
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004531
4532 rx_desc = E1000_RX_DESC(*rx_ring, i);
4533 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4534
4535 if (unlikely(++i == rx_ring->count))
4536 i = 0;
4537 buffer_info = &rx_ring->buffer_info[i];
4538 }
4539
4540 if (likely(rx_ring->next_to_use != i)) {
4541 rx_ring->next_to_use = i;
4542 if (unlikely(i-- == 0))
4543 i = (rx_ring->count - 1);
4544
4545 /* Force memory writes to complete before letting h/w
4546 * know there are new descriptors to fetch. (Only
4547 * applicable for weak-ordered memory model archs,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004548 * such as IA-64).
4549 */
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004550 wmb();
4551 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4552 }
4553}
4554
4555/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004556 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 * @adapter: address of board private structure
4558 **/
Joe Perches64798842008-07-11 15:17:02 -07004559static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4560 struct e1000_rx_ring *rx_ring,
4561 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562{
Joe Perches1dc32912008-07-11 15:17:08 -07004563 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564 struct pci_dev *pdev = adapter->pdev;
4565 struct e1000_rx_desc *rx_desc;
Florian Westphal93f0afe2014-09-03 13:34:26 +00004566 struct e1000_rx_buffer *buffer_info;
Malli Chilakala26483452005-04-28 19:44:46 -07004567 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +00004568 unsigned int bufsz = adapter->rx_buffer_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569
4570 i = rx_ring->next_to_use;
4571 buffer_info = &rx_ring->buffer_info[i];
4572
Jeff Kirshera292ca62006-01-12 16:51:30 -08004573 while (cleaned_count--) {
Florian Westphal13809602014-09-03 13:34:36 +00004574 void *data;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004575
Florian Westphal13809602014-09-03 13:34:36 +00004576 if (buffer_info->rxbuf.data)
4577 goto skip;
4578
4579 data = e1000_alloc_frag(adapter);
4580 if (!data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004582 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583 break;
4584 }
4585
Malli Chilakala26483452005-04-28 19:44:46 -07004586 /* Fix for errata 23, can't cross 64kB boundary */
Florian Westphal13809602014-09-03 13:34:36 +00004587 if (!e1000_check_64k_bound(adapter, data, bufsz)) {
4588 void *olddata = data;
Emil Tantilovfeb8f472010-07-26 23:37:21 -07004589 e_err(rx_err, "skb align check failed: %u bytes at "
Florian Westphal13809602014-09-03 13:34:36 +00004590 "%p\n", bufsz, data);
Malli Chilakala26483452005-04-28 19:44:46 -07004591 /* Try again, without freeing the previous */
Florian Westphal13809602014-09-03 13:34:36 +00004592 data = e1000_alloc_frag(adapter);
Malli Chilakala26483452005-04-28 19:44:46 -07004593 /* Failed allocation, critical failure */
Florian Westphal13809602014-09-03 13:34:36 +00004594 if (!data) {
Alexander Duyck6bf93ba2015-05-06 21:12:20 -07004595 skb_free_frag(olddata);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004596 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 break;
4598 }
Malli Chilakala26483452005-04-28 19:44:46 -07004599
Florian Westphal13809602014-09-03 13:34:36 +00004600 if (!e1000_check_64k_bound(adapter, data, bufsz)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 /* give up */
Alexander Duyck6bf93ba2015-05-06 21:12:20 -07004602 skb_free_frag(data);
4603 skb_free_frag(olddata);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004604 adapter->alloc_rx_buff_failed++;
Florian Westphal13809602014-09-03 13:34:36 +00004605 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004607
4608 /* Use new allocation */
Alexander Duyck6bf93ba2015-05-06 21:12:20 -07004609 skb_free_frag(olddata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 }
Nick Nunleyb16f53b2010-04-27 13:08:45 +00004611 buffer_info->dma = dma_map_single(&pdev->dev,
Florian Westphal13809602014-09-03 13:34:36 +00004612 data,
Florian Westphal93f0afe2014-09-03 13:34:26 +00004613 adapter->rx_buffer_len,
Nick Nunleyb16f53b2010-04-27 13:08:45 +00004614 DMA_FROM_DEVICE);
4615 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Alexander Duyck6bf93ba2015-05-06 21:12:20 -07004616 skb_free_frag(data);
Anton Blanchardb5abb022010-02-19 17:54:53 +00004617 buffer_info->dma = 0;
4618 adapter->alloc_rx_buff_failed++;
Florian Westphal13809602014-09-03 13:34:36 +00004619 break;
Anton Blanchardb5abb022010-02-19 17:54:53 +00004620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004622 /* XXX if it was allocated cleanly it will never map to a
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004623 * boundary crossing
4624 */
4625
Malli Chilakala26483452005-04-28 19:44:46 -07004626 /* Fix for errata 23, can't cross 64kB boundary */
4627 if (!e1000_check_64k_bound(adapter,
4628 (void *)(unsigned long)buffer_info->dma,
4629 adapter->rx_buffer_len)) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07004630 e_err(rx_err, "dma align check failed: %u bytes at "
4631 "%p\n", adapter->rx_buffer_len,
Emil Tantilov675ad472010-04-27 14:02:58 +00004632 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633
Nick Nunleyb16f53b2010-04-27 13:08:45 +00004634 dma_unmap_single(&pdev->dev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635 adapter->rx_buffer_len,
Nick Nunleyb16f53b2010-04-27 13:08:45 +00004636 DMA_FROM_DEVICE);
Florian Westphal13809602014-09-03 13:34:36 +00004637
Alexander Duyck6bf93ba2015-05-06 21:12:20 -07004638 skb_free_frag(data);
Florian Westphal13809602014-09-03 13:34:36 +00004639 buffer_info->rxbuf.data = NULL;
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00004640 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004642 adapter->alloc_rx_buff_failed++;
Florian Westphal13809602014-09-03 13:34:36 +00004643 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 }
Florian Westphal13809602014-09-03 13:34:36 +00004645 buffer_info->rxbuf.data = data;
4646 skip:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 rx_desc = E1000_RX_DESC(*rx_ring, i);
4648 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4649
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004650 if (unlikely(++i == rx_ring->count))
4651 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 buffer_info = &rx_ring->buffer_info[i];
4653 }
4654
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004655 if (likely(rx_ring->next_to_use != i)) {
4656 rx_ring->next_to_use = i;
4657 if (unlikely(i-- == 0))
4658 i = (rx_ring->count - 1);
4659
4660 /* Force memory writes to complete before letting h/w
4661 * know there are new descriptors to fetch. (Only
4662 * applicable for weak-ordered memory model archs,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004663 * such as IA-64).
4664 */
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004665 wmb();
Joe Perches1dc32912008-07-11 15:17:08 -07004666 writel(i, hw->hw_addr + rx_ring->rdt);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668}
4669
4670/**
4671 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4672 * @adapter:
4673 **/
Joe Perches64798842008-07-11 15:17:02 -07004674static void e1000_smartspeed(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675{
Joe Perches1dc32912008-07-11 15:17:08 -07004676 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004677 u16 phy_status;
4678 u16 phy_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679
Joe Perches1dc32912008-07-11 15:17:08 -07004680 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4681 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 return;
4683
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004684 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 /* If Master/Slave config fault is asserted twice,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004686 * we assume back-to-back
4687 */
Joe Perches1dc32912008-07-11 15:17:08 -07004688 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
Janusz Wolaka48954c2015-09-17 23:34:29 +02004689 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
4690 return;
Joe Perches1dc32912008-07-11 15:17:08 -07004691 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
Janusz Wolaka48954c2015-09-17 23:34:29 +02004692 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
4693 return;
Joe Perches1dc32912008-07-11 15:17:08 -07004694 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004695 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696 phy_ctrl &= ~CR_1000T_MS_ENABLE;
Joe Perches1dc32912008-07-11 15:17:08 -07004697 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 phy_ctrl);
4699 adapter->smartspeed++;
Joe Perches1dc32912008-07-11 15:17:08 -07004700 if (!e1000_phy_setup_autoneg(hw) &&
4701 !e1000_read_phy_reg(hw, PHY_CTRL,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004702 &phy_ctrl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4704 MII_CR_RESTART_AUTO_NEG);
Joe Perches1dc32912008-07-11 15:17:08 -07004705 e1000_write_phy_reg(hw, PHY_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 phy_ctrl);
4707 }
4708 }
4709 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004710 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 /* If still no link, perhaps using 2/3 pair cable */
Joe Perches1dc32912008-07-11 15:17:08 -07004712 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 phy_ctrl |= CR_1000T_MS_ENABLE;
Joe Perches1dc32912008-07-11 15:17:08 -07004714 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4715 if (!e1000_phy_setup_autoneg(hw) &&
4716 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4718 MII_CR_RESTART_AUTO_NEG);
Joe Perches1dc32912008-07-11 15:17:08 -07004719 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 }
4721 }
4722 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004723 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 adapter->smartspeed = 0;
4725}
4726
4727/**
4728 * e1000_ioctl -
4729 * @netdev:
4730 * @ifreq:
4731 * @cmd:
4732 **/
Joe Perches64798842008-07-11 15:17:02 -07004733static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734{
4735 switch (cmd) {
4736 case SIOCGMIIPHY:
4737 case SIOCGMIIREG:
4738 case SIOCSMIIREG:
4739 return e1000_mii_ioctl(netdev, ifr, cmd);
4740 default:
4741 return -EOPNOTSUPP;
4742 }
4743}
4744
4745/**
4746 * e1000_mii_ioctl -
4747 * @netdev:
4748 * @ifreq:
4749 * @cmd:
4750 **/
Joe Perches64798842008-07-11 15:17:02 -07004751static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4752 int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004754 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004755 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756 struct mii_ioctl_data *data = if_mii(ifr);
4757 int retval;
Joe Perches406874a2008-04-03 10:06:32 -07004758 u16 mii_reg;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004759 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760
Joe Perches1dc32912008-07-11 15:17:08 -07004761 if (hw->media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 return -EOPNOTSUPP;
4763
4764 switch (cmd) {
4765 case SIOCGMIIPHY:
Joe Perches1dc32912008-07-11 15:17:08 -07004766 data->phy_id = hw->phy_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 break;
4768 case SIOCGMIIREG:
Malli Chilakala97876fc2005-06-17 17:40:19 -07004769 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004770 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004771 &data->val_out)) {
4772 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004774 }
4775 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776 break;
4777 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004778 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779 return -EFAULT;
4780 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004781 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004782 if (e1000_write_phy_reg(hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004783 mii_reg)) {
4784 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004786 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004787 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004788 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 switch (data->reg_num) {
4790 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004791 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004793 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Joe Perches1dc32912008-07-11 15:17:08 -07004794 hw->autoneg = 1;
4795 hw->autoneg_advertised = 0x2F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796 } else {
David Decotigny14ad2512011-04-27 18:32:43 +00004797 u32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 if (mii_reg & 0x40)
David Decotigny14ad2512011-04-27 18:32:43 +00004799 speed = SPEED_1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 else if (mii_reg & 0x2000)
David Decotigny14ad2512011-04-27 18:32:43 +00004801 speed = SPEED_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 else
David Decotigny14ad2512011-04-27 18:32:43 +00004803 speed = SPEED_10;
4804 retval = e1000_set_spd_dplx(
4805 adapter, speed,
4806 ((mii_reg & 0x100)
4807 ? DUPLEX_FULL :
4808 DUPLEX_HALF));
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004809 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 return retval;
4811 }
Auke Kok2db10a02006-06-27 09:06:28 -07004812 if (netif_running(adapter->netdev))
4813 e1000_reinit_locked(adapter);
4814 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 e1000_reset(adapter);
4816 break;
4817 case M88E1000_PHY_SPEC_CTRL:
4818 case M88E1000_EXT_PHY_SPEC_CTRL:
Joe Perches1dc32912008-07-11 15:17:08 -07004819 if (e1000_phy_reset(hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 return -EIO;
4821 break;
4822 }
4823 } else {
4824 switch (data->reg_num) {
4825 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004826 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004828 if (netif_running(adapter->netdev))
4829 e1000_reinit_locked(adapter);
4830 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 e1000_reset(adapter);
4832 break;
4833 }
4834 }
4835 break;
4836 default:
4837 return -EOPNOTSUPP;
4838 }
4839 return E1000_SUCCESS;
4840}
4841
Joe Perches64798842008-07-11 15:17:02 -07004842void e1000_pci_set_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843{
4844 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004845 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004847 if (ret_val)
Emil Tantilovfeb8f472010-07-26 23:37:21 -07004848 e_err(probe, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849}
4850
Joe Perches64798842008-07-11 15:17:02 -07004851void e1000_pci_clear_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852{
4853 struct e1000_adapter *adapter = hw->back;
4854
4855 pci_clear_mwi(adapter->pdev);
4856}
4857
Joe Perches64798842008-07-11 15:17:02 -07004858int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
Peter Oruba007755e2007-09-28 22:42:06 -07004859{
4860 struct e1000_adapter *adapter = hw->back;
4861 return pcix_get_mmrbc(adapter->pdev);
4862}
4863
Joe Perches64798842008-07-11 15:17:02 -07004864void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
Peter Oruba007755e2007-09-28 22:42:06 -07004865{
4866 struct e1000_adapter *adapter = hw->back;
4867 pcix_set_mmrbc(adapter->pdev, mmrbc);
4868}
4869
Joe Perches64798842008-07-11 15:17:02 -07004870void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871{
4872 outl(value, port);
4873}
4874
Jiri Pirko5622e402011-07-21 03:26:31 +00004875static bool e1000_vlan_used(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876{
Jiri Pirko5622e402011-07-21 03:26:31 +00004877 u16 vid;
4878
4879 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
4880 return true;
4881 return false;
4882}
4883
Jiri Pirko52f55092012-03-20 18:10:01 +00004884static void __e1000_vlan_mode(struct e1000_adapter *adapter,
4885 netdev_features_t features)
4886{
4887 struct e1000_hw *hw = &adapter->hw;
4888 u32 ctrl;
4889
4890 ctrl = er32(CTRL);
Patrick McHardyf6469682013-04-19 02:04:27 +00004891 if (features & NETIF_F_HW_VLAN_CTAG_RX) {
Jiri Pirko52f55092012-03-20 18:10:01 +00004892 /* enable VLAN tag insert/strip */
4893 ctrl |= E1000_CTRL_VME;
4894 } else {
4895 /* disable VLAN tag insert/strip */
4896 ctrl &= ~E1000_CTRL_VME;
4897 }
4898 ew32(CTRL, ctrl);
4899}
Jiri Pirko5622e402011-07-21 03:26:31 +00004900static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
4901 bool filter_on)
4902{
Joe Perches1dc32912008-07-11 15:17:08 -07004903 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko5622e402011-07-21 03:26:31 +00004904 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004906 if (!test_bit(__E1000_DOWN, &adapter->flags))
4907 e1000_irq_disable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908
Jiri Pirko52f55092012-03-20 18:10:01 +00004909 __e1000_vlan_mode(adapter, adapter->netdev->features);
Jiri Pirko5622e402011-07-21 03:26:31 +00004910 if (filter_on) {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004911 /* enable VLAN receive filtering */
4912 rctl = er32(RCTL);
4913 rctl &= ~E1000_RCTL_CFIEN;
Jiri Pirko5622e402011-07-21 03:26:31 +00004914 if (!(adapter->netdev->flags & IFF_PROMISC))
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004915 rctl |= E1000_RCTL_VFE;
4916 ew32(RCTL, rctl);
4917 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 } else {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004919 /* disable VLAN receive filtering */
4920 rctl = er32(RCTL);
4921 rctl &= ~E1000_RCTL_VFE;
4922 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 }
4924
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004925 if (!test_bit(__E1000_DOWN, &adapter->flags))
4926 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927}
4928
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004929static void e1000_vlan_mode(struct net_device *netdev,
Jiri Pirko52f55092012-03-20 18:10:01 +00004930 netdev_features_t features)
Jiri Pirko5622e402011-07-21 03:26:31 +00004931{
4932 struct e1000_adapter *adapter = netdev_priv(netdev);
Jiri Pirko5622e402011-07-21 03:26:31 +00004933
4934 if (!test_bit(__E1000_DOWN, &adapter->flags))
4935 e1000_irq_disable(adapter);
4936
Jiri Pirko52f55092012-03-20 18:10:01 +00004937 __e1000_vlan_mode(adapter, features);
Jiri Pirko5622e402011-07-21 03:26:31 +00004938
4939 if (!test_bit(__E1000_DOWN, &adapter->flags))
4940 e1000_irq_enable(adapter);
4941}
4942
Patrick McHardy80d5c362013-04-19 02:04:28 +00004943static int e1000_vlan_rx_add_vid(struct net_device *netdev,
4944 __be16 proto, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004946 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004947 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004948 u32 vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004949
Joe Perches1dc32912008-07-11 15:17:08 -07004950 if ((hw->mng_cookie.status &
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004951 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4952 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05004953 return 0;
Jiri Pirko5622e402011-07-21 03:26:31 +00004954
4955 if (!e1000_vlan_used(adapter))
4956 e1000_vlan_filter_on_off(adapter, true);
4957
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 /* add VID to filter table */
4959 index = (vid >> 5) & 0x7F;
Joe Perches1dc32912008-07-11 15:17:08 -07004960 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961 vfta |= (1 << (vid & 0x1F));
Joe Perches1dc32912008-07-11 15:17:08 -07004962 e1000_write_vfta(hw, index, vfta);
Jiri Pirko5622e402011-07-21 03:26:31 +00004963
4964 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004965
4966 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967}
4968
Patrick McHardy80d5c362013-04-19 02:04:28 +00004969static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
4970 __be16 proto, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004972 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004973 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004974 u32 vfta, index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004976 if (!test_bit(__E1000_DOWN, &adapter->flags))
4977 e1000_irq_disable(adapter);
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004978 if (!test_bit(__E1000_DOWN, &adapter->flags))
4979 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980
4981 /* remove VID from filter table */
4982 index = (vid >> 5) & 0x7F;
Joe Perches1dc32912008-07-11 15:17:08 -07004983 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 vfta &= ~(1 << (vid & 0x1F));
Joe Perches1dc32912008-07-11 15:17:08 -07004985 e1000_write_vfta(hw, index, vfta);
Jiri Pirko5622e402011-07-21 03:26:31 +00004986
4987 clear_bit(vid, adapter->active_vlans);
4988
4989 if (!e1000_vlan_used(adapter))
4990 e1000_vlan_filter_on_off(adapter, false);
Jiri Pirko8e586132011-12-08 19:52:37 -05004991
4992 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993}
4994
Joe Perches64798842008-07-11 15:17:02 -07004995static void e1000_restore_vlan(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996{
Jiri Pirko5622e402011-07-21 03:26:31 +00004997 u16 vid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998
Jiri Pirko5622e402011-07-21 03:26:31 +00004999 if (!e1000_vlan_used(adapter))
5000 return;
5001
5002 e1000_vlan_filter_on_off(adapter, true);
5003 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00005004 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005}
5006
David Decotigny14ad2512011-04-27 18:32:43 +00005007int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008{
Joe Perches1dc32912008-07-11 15:17:08 -07005009 struct e1000_hw *hw = &adapter->hw;
5010
5011 hw->autoneg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012
David Decotigny14ad2512011-04-27 18:32:43 +00005013 /* Make sure dplx is at most 1 bit and lsb of speed is not set
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005014 * for the switch() below to work
5015 */
David Decotigny14ad2512011-04-27 18:32:43 +00005016 if ((spd & 1) || (dplx & ~1))
5017 goto err_inval;
5018
Malli Chilakala69213682005-06-17 17:44:20 -07005019 /* Fiber NICs only allow 1000 gbps Full duplex */
Joe Perches1dc32912008-07-11 15:17:08 -07005020 if ((hw->media_type == e1000_media_type_fiber) &&
David Decotigny14ad2512011-04-27 18:32:43 +00005021 spd != SPEED_1000 &&
5022 dplx != DUPLEX_FULL)
5023 goto err_inval;
Malli Chilakala69213682005-06-17 17:44:20 -07005024
David Decotigny14ad2512011-04-27 18:32:43 +00005025 switch (spd + dplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026 case SPEED_10 + DUPLEX_HALF:
Joe Perches1dc32912008-07-11 15:17:08 -07005027 hw->forced_speed_duplex = e1000_10_half;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 break;
5029 case SPEED_10 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07005030 hw->forced_speed_duplex = e1000_10_full;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 break;
5032 case SPEED_100 + DUPLEX_HALF:
Joe Perches1dc32912008-07-11 15:17:08 -07005033 hw->forced_speed_duplex = e1000_100_half;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 break;
5035 case SPEED_100 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07005036 hw->forced_speed_duplex = e1000_100_full;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037 break;
5038 case SPEED_1000 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07005039 hw->autoneg = 1;
5040 hw->autoneg_advertised = ADVERTISE_1000_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041 break;
5042 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5043 default:
David Decotigny14ad2512011-04-27 18:32:43 +00005044 goto err_inval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045 }
Jesse Brandeburgc819bbd52012-07-26 02:31:09 +00005046
5047 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
5048 hw->mdix = AUTO_ALL_MODES;
5049
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +00005051
5052err_inval:
5053 e_err(probe, "Unsupported Speed/Duplex configuration\n");
5054 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055}
5056
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005057static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058{
5059 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005060 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005061 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07005062 u32 ctrl, ctrl_ext, rctl, status;
5063 u32 wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07005064#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08005065 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07005066#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067
5068 netif_device_detach(netdev);
5069
Auke Kok2db10a02006-06-27 09:06:28 -07005070 if (netif_running(netdev)) {
yzhu16a7d64e2013-11-23 07:07:40 +00005071 int count = E1000_CHECK_RESET_COUNT;
5072
5073 while (test_bit(__E1000_RESETTING, &adapter->flags) && count--)
5074 usleep_range(10000, 20000);
5075
Auke Kok2db10a02006-06-27 09:06:28 -07005076 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07005078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005080#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005081 retval = pci_save_state(pdev);
Jesse Brandeburg3a3847e2012-01-04 20:23:33 +00005082 if (retval)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005083 return retval;
5084#endif
5085
Joe Perches1dc32912008-07-11 15:17:08 -07005086 status = er32(STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005087 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 wufc &= ~E1000_WUFC_LNKC;
5089
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005090 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005092 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093
Dean Nelsonb8681792012-01-19 17:47:24 +00005094 rctl = er32(RCTL);
5095
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096 /* turn on all-multi mode if wake on multicast is enabled */
Dean Nelsonb8681792012-01-19 17:47:24 +00005097 if (wufc & E1000_WUFC_MC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098 rctl |= E1000_RCTL_MPE;
Dean Nelsonb8681792012-01-19 17:47:24 +00005099
5100 /* enable receives in the hardware */
5101 ew32(RCTL, rctl | E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102
Joe Perches1dc32912008-07-11 15:17:08 -07005103 if (hw->mac_type >= e1000_82540) {
5104 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105 /* advertise wake from D3Cold */
5106 #define E1000_CTRL_ADVD3WUC 0x00100000
5107 /* phy power management enable */
5108 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5109 ctrl |= E1000_CTRL_ADVD3WUC |
5110 E1000_CTRL_EN_PHY_PWR_MGMT;
Joe Perches1dc32912008-07-11 15:17:08 -07005111 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 }
5113
Joe Perches1dc32912008-07-11 15:17:08 -07005114 if (hw->media_type == e1000_media_type_fiber ||
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005115 hw->media_type == e1000_media_type_internal_serdes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 /* keep the laser running in D3 */
Joe Perches1dc32912008-07-11 15:17:08 -07005117 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07005119 ew32(CTRL_EXT, ctrl_ext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 }
5121
Joe Perches1dc32912008-07-11 15:17:08 -07005122 ew32(WUC, E1000_WUC_PME_EN);
5123 ew32(WUFC, wufc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07005125 ew32(WUC, 0);
5126 ew32(WUFC, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 }
5128
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005129 e1000_release_manageability(adapter);
5130
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005131 *enable_wake = !!wufc;
5132
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005133 /* make sure adapter isn't asleep if manageability is enabled */
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005134 if (adapter->en_mng_pt)
5135 *enable_wake = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136
Auke Kokedd106f2006-11-06 08:57:12 -08005137 if (netif_running(netdev))
5138 e1000_free_irq(adapter);
5139
Tushar Dave0b76aae2017-12-06 02:26:29 +05305140 if (!test_and_set_bit(__E1000_DISABLED, &adapter->flags))
5141 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005142
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 return 0;
5144}
5145
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005146#ifdef CONFIG_PM
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005147static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5148{
5149 int retval;
5150 bool wake;
5151
5152 retval = __e1000_shutdown(pdev, &wake);
5153 if (retval)
5154 return retval;
5155
5156 if (wake) {
5157 pci_prepare_to_sleep(pdev);
5158 } else {
5159 pci_wake_from_d3(pdev, false);
5160 pci_set_power_state(pdev, PCI_D3hot);
5161 }
5162
5163 return 0;
5164}
5165
Joe Perches64798842008-07-11 15:17:02 -07005166static int e1000_resume(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167{
5168 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005169 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005170 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07005171 u32 err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172
Auke Kokd0e027d2006-04-14 19:04:40 -07005173 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005174 pci_restore_state(pdev);
Nick Nunleydbb5aae2010-02-03 14:49:48 +00005175 pci_save_state(pdev);
Taku Izumi81250292008-07-11 15:17:44 -07005176
5177 if (adapter->need_ioport)
5178 err = pci_enable_device(pdev);
5179 else
5180 err = pci_enable_device_mem(pdev);
Joe Perchesc7be73b2008-07-11 15:17:28 -07005181 if (err) {
Emil Tantilov675ad472010-04-27 14:02:58 +00005182 pr_err("Cannot enable PCI device from suspend\n");
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005183 return err;
5184 }
Tushar Dave0b76aae2017-12-06 02:26:29 +05305185
5186 /* flush memory to make sure state is correct */
5187 smp_mb__before_atomic();
5188 clear_bit(__E1000_DISABLED, &adapter->flags);
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005189 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190
Auke Kokd0e027d2006-04-14 19:04:40 -07005191 pci_enable_wake(pdev, PCI_D3hot, 0);
5192 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193
Joe Perchesc7be73b2008-07-11 15:17:28 -07005194 if (netif_running(netdev)) {
5195 err = e1000_request_irq(adapter);
5196 if (err)
5197 return err;
5198 }
Auke Kokedd106f2006-11-06 08:57:12 -08005199
5200 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201 e1000_reset(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07005202 ew32(WUS, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005204 e1000_init_manageability(adapter);
5205
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005206 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 e1000_up(adapter);
5208
5209 netif_device_attach(netdev);
5210
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211 return 0;
5212}
5213#endif
Auke Kokc653e632006-05-23 13:35:57 -07005214
5215static void e1000_shutdown(struct pci_dev *pdev)
5216{
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005217 bool wake;
5218
5219 __e1000_shutdown(pdev, &wake);
5220
5221 if (system_state == SYSTEM_POWER_OFF) {
5222 pci_wake_from_d3(pdev, wake);
5223 pci_set_power_state(pdev, PCI_D3hot);
5224 }
Auke Kokc653e632006-05-23 13:35:57 -07005225}
5226
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227#ifdef CONFIG_NET_POLL_CONTROLLER
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005228/* Polling 'interrupt' - used by things like netconsole to send skbs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005229 * without having to re-enable interrupts. It's not called while
5230 * the interrupt routine is executing.
5231 */
Joe Perches64798842008-07-11 15:17:02 -07005232static void e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005234 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005235
WANG Cong31119122016-12-10 14:22:42 -08005236 if (disable_hardirq(adapter->pdev->irq))
5237 e1000_intr(adapter->pdev->irq, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238 enable_irq(adapter->pdev->irq);
5239}
5240#endif
5241
Auke Kok90267292006-06-08 09:30:24 -07005242/**
5243 * e1000_io_error_detected - called when PCI error is detected
5244 * @pdev: Pointer to PCI device
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005245 * @state: The current pci connection state
Auke Kok90267292006-06-08 09:30:24 -07005246 *
5247 * This function is called after a PCI bus error affecting
5248 * this device has been detected.
5249 */
Joe Perches64798842008-07-11 15:17:02 -07005250static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5251 pci_channel_state_t state)
Auke Kok90267292006-06-08 09:30:24 -07005252{
5253 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen4cf16532008-11-12 23:38:14 -08005254 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok90267292006-06-08 09:30:24 -07005255
5256 netif_device_detach(netdev);
5257
Andre Detscheab63302009-06-30 12:46:13 +00005258 if (state == pci_channel_io_perm_failure)
5259 return PCI_ERS_RESULT_DISCONNECT;
5260
Auke Kok90267292006-06-08 09:30:24 -07005261 if (netif_running(netdev))
5262 e1000_down(adapter);
Tushar Dave0b76aae2017-12-06 02:26:29 +05305263
5264 if (!test_and_set_bit(__E1000_DISABLED, &adapter->flags))
5265 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005266
5267 /* Request a slot slot reset. */
5268 return PCI_ERS_RESULT_NEED_RESET;
5269}
5270
5271/**
5272 * e1000_io_slot_reset - called after the pci bus has been reset.
5273 * @pdev: Pointer to PCI device
5274 *
5275 * Restart the card from scratch, as if from a cold-boot. Implementation
5276 * resembles the first-half of the e1000_resume routine.
5277 */
5278static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5279{
5280 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen4cf16532008-11-12 23:38:14 -08005281 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005282 struct e1000_hw *hw = &adapter->hw;
Taku Izumi81250292008-07-11 15:17:44 -07005283 int err;
Auke Kok90267292006-06-08 09:30:24 -07005284
Taku Izumi81250292008-07-11 15:17:44 -07005285 if (adapter->need_ioport)
5286 err = pci_enable_device(pdev);
5287 else
5288 err = pci_enable_device_mem(pdev);
5289 if (err) {
Emil Tantilov675ad472010-04-27 14:02:58 +00005290 pr_err("Cannot re-enable PCI device after reset.\n");
Auke Kok90267292006-06-08 09:30:24 -07005291 return PCI_ERS_RESULT_DISCONNECT;
5292 }
Tushar Dave0b76aae2017-12-06 02:26:29 +05305293
5294 /* flush memory to make sure state is correct */
5295 smp_mb__before_atomic();
5296 clear_bit(__E1000_DISABLED, &adapter->flags);
Auke Kok90267292006-06-08 09:30:24 -07005297 pci_set_master(pdev);
5298
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005299 pci_enable_wake(pdev, PCI_D3hot, 0);
5300 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005301
Auke Kok90267292006-06-08 09:30:24 -07005302 e1000_reset(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07005303 ew32(WUS, ~0);
Auke Kok90267292006-06-08 09:30:24 -07005304
5305 return PCI_ERS_RESULT_RECOVERED;
5306}
5307
5308/**
5309 * e1000_io_resume - called when traffic can start flowing again.
5310 * @pdev: Pointer to PCI device
5311 *
5312 * This callback is called when the error recovery driver tells us that
5313 * its OK to resume normal operation. Implementation resembles the
5314 * second-half of the e1000_resume routine.
5315 */
5316static void e1000_io_resume(struct pci_dev *pdev)
5317{
5318 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen4cf16532008-11-12 23:38:14 -08005319 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005320
5321 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005322
5323 if (netif_running(netdev)) {
5324 if (e1000_up(adapter)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00005325 pr_info("can't bring device back up after reset\n");
Auke Kok90267292006-06-08 09:30:24 -07005326 return;
5327 }
5328 }
5329
5330 netif_device_attach(netdev);
Auke Kok90267292006-06-08 09:30:24 -07005331}
5332
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333/* e1000_main.c */