blob: e2ad3f38c75c4b77c552e60907b0323430fb5e69 [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 - 2018 Intel Corporation. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003
Bruce Allan8544b9f2010-03-24 12:55:30 +00004#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
5
Auke Kokbc7f75f2007-09-17 12:30:59 -07006#include <linux/module.h>
7#include <linux/types.h>
8#include <linux/init.h>
9#include <linux/pci.h>
10#include <linux/vmalloc.h>
11#include <linux/pagemap.h>
12#include <linux/delay.h>
13#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000014#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070015#include <linux/tcp.h>
16#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070018#include <net/checksum.h>
19#include <net/ip6_checksum.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070020#include <linux/ethtool.h>
21#include <linux/if_vlan.h>
22#include <linux/cpu.h>
23#include <linux/smp.h>
Linus Torvalds7e0bb712011-10-25 15:18:39 +020024#include <linux/pm_qos.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000025#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000026#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040027#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070028
29#include "e1000.h"
30
Bruce Allanb3ccf262011-05-19 01:53:41 +000031#define DRV_EXTRAVERSION "-k"
Bruce Allanc14c6432010-06-16 13:28:34 +000032
Raanan Avargild2d7d4e2015-07-19 16:33:21 +030033#define DRV_VERSION "3.2.6" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070034char e1000e_driver_name[] = "e1000e";
35const char e1000e_driver_version[] = DRV_VERSION;
36
stephen hemmingerb3f4d592012-03-13 06:04:20 +000037#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
38static int debug = -1;
39module_param(debug, int, 0);
40MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
41
Auke Kokbc7f75f2007-09-17 12:30:59 -070042static const struct e1000_info *e1000_info_tbl[] = {
43 [board_82571] = &e1000_82571_info,
44 [board_82572] = &e1000_82572_info,
45 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070046 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000047 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070048 [board_80003es2lan] = &e1000_es2_info,
49 [board_ich8lan] = &e1000_ich8_info,
50 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070051 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000052 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000053 [board_pch2lan] = &e1000_pch2_info,
Bruce Allan2fbe4522012-04-19 03:21:47 +000054 [board_pch_lpt] = &e1000_pch_lpt_info,
David Ertman79849eb2015-02-10 09:10:43 +000055 [board_pch_spt] = &e1000_pch_spt_info,
Sasha Neftin3a3173b2017-04-06 10:26:32 +030056 [board_pch_cnp] = &e1000_pch_cnp_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070057};
58
Taku Izumi84f4ee92010-04-27 14:39:08 +000059struct e1000_reg_info {
60 u32 ofs;
61 char *name;
62};
63
Taku Izumi84f4ee92010-04-27 14:39:08 +000064static const struct e1000_reg_info e1000_reg_info_tbl[] = {
Taku Izumi84f4ee92010-04-27 14:39:08 +000065 /* General Registers */
66 {E1000_CTRL, "CTRL"},
67 {E1000_STATUS, "STATUS"},
68 {E1000_CTRL_EXT, "CTRL_EXT"},
69
70 /* Interrupt Registers */
71 {E1000_ICR, "ICR"},
72
Bruce Allanaf667a22010-12-31 06:10:01 +000073 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +000074 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +000075 {E1000_RDLEN(0), "RDLEN"},
76 {E1000_RDH(0), "RDH"},
77 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000078 {E1000_RDTR, "RDTR"},
79 {E1000_RXDCTL(0), "RXDCTL"},
80 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +000081 {E1000_RDBAL(0), "RDBAL"},
82 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000083 {E1000_RDFH, "RDFH"},
84 {E1000_RDFT, "RDFT"},
85 {E1000_RDFHS, "RDFHS"},
86 {E1000_RDFTS, "RDFTS"},
87 {E1000_RDFPC, "RDFPC"},
88
Bruce Allanaf667a22010-12-31 06:10:01 +000089 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +000090 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +000091 {E1000_TDBAL(0), "TDBAL"},
92 {E1000_TDBAH(0), "TDBAH"},
93 {E1000_TDLEN(0), "TDLEN"},
94 {E1000_TDH(0), "TDH"},
95 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000096 {E1000_TIDV, "TIDV"},
97 {E1000_TXDCTL(0), "TXDCTL"},
98 {E1000_TADV, "TADV"},
99 {E1000_TARC(0), "TARC"},
100 {E1000_TDFH, "TDFH"},
101 {E1000_TDFT, "TDFT"},
102 {E1000_TDFHS, "TDFHS"},
103 {E1000_TDFTS, "TDFTS"},
104 {E1000_TDFPC, "TDFPC"},
105
106 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000107 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000108};
109
Vitaly Lifshitse086ba22020-05-07 20:14:06 +0300110struct e1000e_me_supported {
111 u16 device_id; /* supported device ID */
112};
113
114static const struct e1000e_me_supported me_supported[] = {
115 {E1000_DEV_ID_PCH_LPT_I217_LM},
116 {E1000_DEV_ID_PCH_LPTLP_I218_LM},
117 {E1000_DEV_ID_PCH_I218_LM2},
118 {E1000_DEV_ID_PCH_I218_LM3},
119 {E1000_DEV_ID_PCH_SPT_I219_LM},
120 {E1000_DEV_ID_PCH_SPT_I219_LM2},
121 {E1000_DEV_ID_PCH_LBG_I219_LM3},
122 {E1000_DEV_ID_PCH_SPT_I219_LM4},
123 {E1000_DEV_ID_PCH_SPT_I219_LM5},
124 {E1000_DEV_ID_PCH_CNP_I219_LM6},
125 {E1000_DEV_ID_PCH_CNP_I219_LM7},
126 {E1000_DEV_ID_PCH_ICP_I219_LM8},
127 {E1000_DEV_ID_PCH_ICP_I219_LM9},
128 {E1000_DEV_ID_PCH_CMP_I219_LM10},
129 {E1000_DEV_ID_PCH_CMP_I219_LM11},
130 {E1000_DEV_ID_PCH_CMP_I219_LM12},
131 {E1000_DEV_ID_PCH_TGP_I219_LM13},
132 {E1000_DEV_ID_PCH_TGP_I219_LM14},
133 {E1000_DEV_ID_PCH_TGP_I219_LM15},
134 {0}
135};
136
137static bool e1000e_check_me(u16 device_id)
138{
139 struct e1000e_me_supported *id;
140
141 for (id = (struct e1000e_me_supported *)me_supported;
142 id->device_id; id++)
143 if (device_id == id->device_id)
144 return true;
145
146 return false;
147}
148
Bruce Allane921eb12012-11-28 09:28:37 +0000149/**
Andi Kleenc6f31482014-05-20 08:22:45 +0000150 * __ew32_prepare - prepare to write to MAC CSR register on certain parts
151 * @hw: pointer to the HW structure
152 *
153 * When updating the MAC CSR registers, the Manageability Engine (ME) could
154 * be accessing the registers at the same time. Normally, this is handled in
155 * h/w by an arbiter but on some parts there is a bug that acknowledges Host
156 * accesses later than it should which could result in the register to have
157 * an incorrect value. Workaround this by checking the FWSM register which
158 * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set
159 * and try again a number of times.
160 **/
Punit Agrawald601afc2020-05-15 13:31:27 +0900161static void __ew32_prepare(struct e1000_hw *hw)
Andi Kleenc6f31482014-05-20 08:22:45 +0000162{
163 s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;
164
165 while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
166 udelay(50);
Andi Kleenc6f31482014-05-20 08:22:45 +0000167}
168
169void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val)
170{
171 if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
172 __ew32_prepare(hw);
173
174 writel(val, hw->hw_addr + reg);
175}
176
177/**
Taku Izumi84f4ee92010-04-27 14:39:08 +0000178 * e1000_regdump - register printout routine
Bruce Allane921eb12012-11-28 09:28:37 +0000179 * @hw: pointer to the HW structure
180 * @reginfo: pointer to the register info table
181 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000182static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
183{
184 int n = 0;
185 char rname[16];
186 u32 regs[8];
187
188 switch (reginfo->ofs) {
189 case E1000_RXDCTL(0):
190 for (n = 0; n < 2; n++)
191 regs[n] = __er32(hw, E1000_RXDCTL(n));
192 break;
193 case E1000_TXDCTL(0):
194 for (n = 0; n < 2; n++)
195 regs[n] = __er32(hw, E1000_TXDCTL(n));
196 break;
197 case E1000_TARC(0):
198 for (n = 0; n < 2; n++)
199 regs[n] = __er32(hw, E1000_TARC(n));
200 break;
201 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000202 pr_info("%-15s %08x\n",
203 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000204 return;
205 }
206
207 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000208 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000209}
210
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000211static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
212 struct e1000_buffer *bi)
213{
214 int i;
215 struct e1000_ps_page *ps_page;
216
217 for (i = 0; i < adapter->rx_ps_pages; i++) {
218 ps_page = &bi->ps_pages[i];
219
220 if (ps_page->page) {
221 pr_info("packet dump for ps_page %d:\n", i);
222 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
223 16, 1, page_address(ps_page->page),
224 PAGE_SIZE, true);
225 }
226 }
227}
228
Bruce Allane921eb12012-11-28 09:28:37 +0000229/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000230 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Bruce Allane921eb12012-11-28 09:28:37 +0000231 * @adapter: board private structure
232 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000233static void e1000e_dump(struct e1000_adapter *adapter)
234{
235 struct net_device *netdev = adapter->netdev;
236 struct e1000_hw *hw = &adapter->hw;
237 struct e1000_reg_info *reginfo;
238 struct e1000_ring *tx_ring = adapter->tx_ring;
239 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000240 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000241 __le64 a;
242 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000243 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000244 struct e1000_buffer *buffer_info;
245 struct e1000_ring *rx_ring = adapter->rx_ring;
246 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000247 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000248 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000249 __le64 a;
250 __le64 b;
251 __le64 c;
252 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000253 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000254 u32 staterr;
255 int i = 0;
256
257 if (!netif_msg_hw(adapter))
258 return;
259
260 /* Print netdevice Info */
261 if (netdev) {
262 dev_info(&adapter->pdev->dev, "Net device Info\n");
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100263 pr_info("Device Name state trans_start\n");
264 pr_info("%-15s %016lX %016lX\n", netdev->name,
265 netdev->state, dev_trans_start(netdev));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000266 }
267
268 /* Print Registers */
269 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000270 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000271 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
272 reginfo->name; reginfo++) {
273 e1000_regdump(hw, reginfo);
274 }
275
Bruce Allanaf667a22010-12-31 06:10:01 +0000276 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000277 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000278 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000279
Bruce Allanaf667a22010-12-31 06:10:01 +0000280 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000281 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000282 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000283 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
284 0, tx_ring->next_to_use, tx_ring->next_to_clean,
285 (unsigned long long)buffer_info->dma,
286 buffer_info->length,
287 buffer_info->next_to_watch,
288 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000289
Bruce Allanaf667a22010-12-31 06:10:01 +0000290 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000291 if (!netif_msg_tx_done(adapter))
292 goto rx_ring_summary;
293
Bruce Allanaf667a22010-12-31 06:10:01 +0000294 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000295
296 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
297 *
298 * Legacy Transmit Descriptor
299 * +--------------------------------------------------------------+
300 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
301 * +--------------------------------------------------------------+
302 * 8 | Special | CSS | Status | CMD | CSO | Length |
303 * +--------------------------------------------------------------+
304 * 63 48 47 36 35 32 31 24 23 16 15 0
305 *
306 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
307 * 63 48 47 40 39 32 31 16 15 8 7 0
308 * +----------------------------------------------------------------+
309 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
310 * +----------------------------------------------------------------+
311 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
312 * +----------------------------------------------------------------+
313 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
314 *
315 * Extended Data Descriptor (DTYP=0x1)
316 * +----------------------------------------------------------------+
317 * 0 | Buffer Address [63:0] |
318 * +----------------------------------------------------------------+
319 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
320 * +----------------------------------------------------------------+
321 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
322 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000323 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
324 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
325 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000326 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000327 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000328 tx_desc = E1000_TX_DESC(*tx_ring, i);
329 buffer_info = &tx_ring->buffer_info[i];
330 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000331 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000332 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000333 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000334 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000335 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000336 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000337 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000338 next_desc = "";
339 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
Jacob Keller18dd2392016-04-13 16:08:32 -0700340 (!(le64_to_cpu(u0->b) & BIT(29)) ? 'l' :
341 ((le64_to_cpu(u0->b) & BIT(20)) ? 'd' : 'c')),
Jeff Kirsheref456f82011-11-03 11:40:28 +0000342 i,
343 (unsigned long long)le64_to_cpu(u0->a),
344 (unsigned long long)le64_to_cpu(u0->b),
345 (unsigned long long)buffer_info->dma,
346 buffer_info->length, buffer_info->next_to_watch,
347 (unsigned long long)buffer_info->time_stamp,
348 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000349
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000350 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumi84f4ee92010-04-27 14:39:08 +0000351 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000352 16, 1, buffer_info->skb->data,
353 buffer_info->skb->len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000354 }
355
Bruce Allanaf667a22010-12-31 06:10:01 +0000356 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000357rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000358 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000359 pr_info("Queue [NTU] [NTC]\n");
360 pr_info(" %5d %5X %5X\n",
361 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000362
Bruce Allanaf667a22010-12-31 06:10:01 +0000363 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000364 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000365 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000366
Bruce Allanaf667a22010-12-31 06:10:01 +0000367 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000368 switch (adapter->rx_ps_pages) {
369 case 1:
370 case 2:
371 case 3:
372 /* [Extended] Packet Split Receive Descriptor Format
373 *
374 * +-----------------------------------------------------+
375 * 0 | Buffer Address 0 [63:0] |
376 * +-----------------------------------------------------+
377 * 8 | Buffer Address 1 [63:0] |
378 * +-----------------------------------------------------+
379 * 16 | Buffer Address 2 [63:0] |
380 * +-----------------------------------------------------+
381 * 24 | Buffer Address 3 [63:0] |
382 * +-----------------------------------------------------+
383 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000384 pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000385 /* [Extended] Receive Descriptor (Write-Back) Format
386 *
387 * 63 48 47 32 31 13 12 8 7 4 3 0
388 * +------------------------------------------------------+
389 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
390 * | Checksum | Ident | | Queue | | Type |
391 * +------------------------------------------------------+
392 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
393 * +------------------------------------------------------+
394 * 63 48 47 32 31 20 19 0
395 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000396 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000397 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000398 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000399 buffer_info = &rx_ring->buffer_info[i];
400 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
401 u1 = (struct my_u1 *)rx_desc_ps;
402 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000403 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000404
405 if (i == rx_ring->next_to_use)
406 next_desc = " NTU";
407 else if (i == rx_ring->next_to_clean)
408 next_desc = " NTC";
409 else
410 next_desc = "";
411
Taku Izumi84f4ee92010-04-27 14:39:08 +0000412 if (staterr & E1000_RXD_STAT_DD) {
413 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000414 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
415 "RWB", i,
416 (unsigned long long)le64_to_cpu(u1->a),
417 (unsigned long long)le64_to_cpu(u1->b),
418 (unsigned long long)le64_to_cpu(u1->c),
419 (unsigned long long)le64_to_cpu(u1->d),
420 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000421 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000422 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
423 "R ", i,
424 (unsigned long long)le64_to_cpu(u1->a),
425 (unsigned long long)le64_to_cpu(u1->b),
426 (unsigned long long)le64_to_cpu(u1->c),
427 (unsigned long long)le64_to_cpu(u1->d),
428 (unsigned long long)buffer_info->dma,
429 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000430
431 if (netif_msg_pktdata(adapter))
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000432 e1000e_dump_ps_pages(adapter,
433 buffer_info);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000434 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000435 }
436 break;
437 default:
438 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000439 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000440 *
Bruce Allan5f450212011-07-22 06:21:46 +0000441 * +-----------------------------------------------------+
442 * 0 | Buffer Address [63:0] |
443 * +-----------------------------------------------------+
444 * 8 | Reserved |
445 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000446 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000447 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000448 /* Extended Receive Descriptor (Write-Back) Format
449 *
450 * 63 48 47 32 31 24 23 4 3 0
451 * +------------------------------------------------------+
452 * | RSS Hash | | | |
453 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
454 * | Packet | IP | | | Type |
455 * | Checksum | Ident | | | |
456 * +------------------------------------------------------+
457 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
458 * +------------------------------------------------------+
459 * 63 48 47 32 31 20 19 0
460 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000461 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000462
463 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000464 const char *next_desc;
465
Taku Izumi84f4ee92010-04-27 14:39:08 +0000466 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000467 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
468 u1 = (struct my_u1 *)rx_desc;
469 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000470
471 if (i == rx_ring->next_to_use)
472 next_desc = " NTU";
473 else if (i == rx_ring->next_to_clean)
474 next_desc = " NTC";
475 else
476 next_desc = "";
477
Bruce Allan5f450212011-07-22 06:21:46 +0000478 if (staterr & E1000_RXD_STAT_DD) {
479 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000480 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
481 "RWB", i,
482 (unsigned long long)le64_to_cpu(u1->a),
483 (unsigned long long)le64_to_cpu(u1->b),
484 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000485 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000486 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
487 "R ", i,
488 (unsigned long long)le64_to_cpu(u1->a),
489 (unsigned long long)le64_to_cpu(u1->b),
490 (unsigned long long)buffer_info->dma,
491 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000492
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000493 if (netif_msg_pktdata(adapter) &&
494 buffer_info->skb)
Bruce Allan5f450212011-07-22 06:21:46 +0000495 print_hex_dump(KERN_INFO, "",
496 DUMP_PREFIX_ADDRESS, 16,
497 1,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000498 buffer_info->skb->data,
Bruce Allan5f450212011-07-22 06:21:46 +0000499 adapter->rx_buffer_len,
500 true);
501 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000502 }
503 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000504}
505
Auke Kokbc7f75f2007-09-17 12:30:59 -0700506/**
507 * e1000_desc_unused - calculate if we have unused descriptors
508 **/
509static int e1000_desc_unused(struct e1000_ring *ring)
510{
511 if (ring->next_to_clean > ring->next_to_use)
512 return ring->next_to_clean - ring->next_to_use - 1;
513
514 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
515}
516
517/**
Bruce Allanb67e1912012-12-27 08:32:33 +0000518 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
519 * @adapter: board private structure
520 * @hwtstamps: time stamp structure to update
521 * @systim: unsigned 64bit system time value.
522 *
523 * Convert the system time value stored in the RX/TXSTMP registers into a
524 * hwtstamp which can be used by the upper level time stamping functions.
525 *
526 * The 'systim_lock' spinlock is used to protect the consistency of the
527 * system time value. This is needed because reading the 64 bit time
528 * value involves reading two 32 bit registers. The first read latches the
529 * value.
530 **/
531static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
532 struct skb_shared_hwtstamps *hwtstamps,
533 u64 systim)
534{
535 u64 ns;
536 unsigned long flags;
537
538 spin_lock_irqsave(&adapter->systim_lock, flags);
539 ns = timecounter_cyc2time(&adapter->tc, systim);
540 spin_unlock_irqrestore(&adapter->systim_lock, flags);
541
542 memset(hwtstamps, 0, sizeof(*hwtstamps));
543 hwtstamps->hwtstamp = ns_to_ktime(ns);
544}
545
546/**
547 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
548 * @adapter: board private structure
549 * @status: descriptor extended error and status field
550 * @skb: particular skb to include time stamp
551 *
552 * If the time stamp is valid, convert it into the timecounter ns value
553 * and store that result into the shhwtstamps structure which is passed
554 * up the network stack.
555 **/
556static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
557 struct sk_buff *skb)
558{
559 struct e1000_hw *hw = &adapter->hw;
560 u64 rxstmp;
561
562 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
563 !(status & E1000_RXDEXT_STATERR_TST) ||
564 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
565 return;
566
567 /* The Rx time stamp registers contain the time stamp. No other
568 * received packet will be time stamped until the Rx time stamp
569 * registers are read. Because only one packet can be time stamped
570 * at a time, the register values must belong to this packet and
571 * therefore none of the other additional attributes need to be
572 * compared.
573 */
574 rxstmp = (u64)er32(RXSTMPL);
575 rxstmp |= (u64)er32(RXSTMPH) << 32;
576 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
577
578 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
579}
580
581/**
Bruce Allanad680762008-03-28 09:15:03 -0700582 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700583 * @adapter: board private structure
Bruce Allanb67e1912012-12-27 08:32:33 +0000584 * @staterr: descriptor extended error and status field as written by hardware
Auke Kokbc7f75f2007-09-17 12:30:59 -0700585 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
586 * @skb: pointer to sk_buff to be indicated to stack
587 **/
588static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000589 struct net_device *netdev, struct sk_buff *skb,
Bruce Allanb67e1912012-12-27 08:32:33 +0000590 u32 staterr, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700591{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000592 u16 tag = le16_to_cpu(vlan);
Bruce Allanb67e1912012-12-27 08:32:33 +0000593
594 e1000e_rx_hwtstamp(adapter, staterr, skb);
595
Auke Kokbc7f75f2007-09-17 12:30:59 -0700596 skb->protocol = eth_type_trans(skb, netdev);
597
Bruce Allanb67e1912012-12-27 08:32:33 +0000598 if (staterr & E1000_RXD_STAT_VP)
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000599 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000600
601 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602}
603
604/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000605 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000606 * @adapter: board private structure
607 * @status_err: receive descriptor status and error fields
608 * @csum: receive descriptor csum field
609 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700610 **/
611static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allan2e1706f2012-06-30 20:02:42 +0000612 struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613{
614 u16 status = (u16)status_err;
615 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700616
617 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700618
Bruce Allanafd12932012-01-05 00:34:05 +0000619 /* Rx checksum disabled */
620 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
621 return;
622
Auke Kokbc7f75f2007-09-17 12:30:59 -0700623 /* Ignore Checksum bit is set */
624 if (status & E1000_RXD_STAT_IXSM)
625 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000626
Bruce Allan2e1706f2012-06-30 20:02:42 +0000627 /* TCP/UDP checksum error bit or IP checksum error bit is set */
628 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700629 /* let the stack verify checksum errors */
630 adapter->hw_csum_err++;
631 return;
632 }
633
634 /* TCP/UDP Checksum has not been calculated */
635 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
636 return;
637
638 /* It must be a TCP or UDP packet with a valid checksum */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000639 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640 adapter->hw_csum_good++;
641}
642
Bruce Allan55aa6982011-12-16 00:45:45 +0000643static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700644{
Bruce Allan55aa6982011-12-16 00:45:45 +0000645 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700646 struct e1000_hw *hw = &adapter->hw;
647
Punit Agrawald601afc2020-05-15 13:31:27 +0900648 __ew32_prepare(hw);
Bruce Allanbdc125f2012-03-20 03:47:52 +0000649 writel(i, rx_ring->tail);
650
Punit Agrawald601afc2020-05-15 13:31:27 +0900651 if (unlikely(i != readl(rx_ring->tail))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700652 u32 rctl = er32(RCTL);
David Ertman6cf08d12014-04-05 06:07:00 +0000653
David S. Miller823dcd22011-08-20 10:39:12 -0700654 ew32(RCTL, rctl & ~E1000_RCTL_EN);
655 e_err("ME firmware caused invalid RDT - resetting\n");
656 schedule_work(&adapter->reset_task);
657 }
658}
659
Bruce Allan55aa6982011-12-16 00:45:45 +0000660static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700661{
Bruce Allan55aa6982011-12-16 00:45:45 +0000662 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700663 struct e1000_hw *hw = &adapter->hw;
664
Punit Agrawald601afc2020-05-15 13:31:27 +0900665 __ew32_prepare(hw);
Bruce Allanbdc125f2012-03-20 03:47:52 +0000666 writel(i, tx_ring->tail);
667
Punit Agrawald601afc2020-05-15 13:31:27 +0900668 if (unlikely(i != readl(tx_ring->tail))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700669 u32 tctl = er32(TCTL);
David Ertman6cf08d12014-04-05 06:07:00 +0000670
David S. Miller823dcd22011-08-20 10:39:12 -0700671 ew32(TCTL, tctl & ~E1000_TCTL_EN);
672 e_err("ME firmware caused invalid TDT - resetting\n");
673 schedule_work(&adapter->reset_task);
674 }
675}
676
677/**
Bruce Allan5f450212011-07-22 06:21:46 +0000678 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000679 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700680 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000681static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000682 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700683{
Bruce Allan55aa6982011-12-16 00:45:45 +0000684 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700685 struct net_device *netdev = adapter->netdev;
686 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000687 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700688 struct e1000_buffer *buffer_info;
689 struct sk_buff *skb;
690 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000691 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700692
693 i = rx_ring->next_to_use;
694 buffer_info = &rx_ring->buffer_info[i];
695
696 while (cleaned_count--) {
697 skb = buffer_info->skb;
698 if (skb) {
699 skb_trim(skb, 0);
700 goto map_skb;
701 }
702
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000703 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700704 if (!skb) {
705 /* Better luck next round */
706 adapter->alloc_rx_buff_failed++;
707 break;
708 }
709
Auke Kokbc7f75f2007-09-17 12:30:59 -0700710 buffer_info->skb = skb;
711map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000712 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700713 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000714 DMA_FROM_DEVICE);
715 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000716 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700717 adapter->rx_dma_failed++;
718 break;
719 }
720
Bruce Allan5f450212011-07-22 06:21:46 +0000721 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
722 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700723
Tom Herbert50849d72010-05-05 14:02:49 +0000724 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000725 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000726 * know there are new descriptors to fetch. (Only
727 * applicable for weak-ordered memory model archs,
728 * such as IA-64).
729 */
730 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700731 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000732 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700733 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000734 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000735 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700736 i++;
737 if (i == rx_ring->count)
738 i = 0;
739 buffer_info = &rx_ring->buffer_info[i];
740 }
741
Tom Herbert50849d72010-05-05 14:02:49 +0000742 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700743}
744
745/**
746 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000747 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700748 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000749static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000750 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700751{
Bruce Allan55aa6982011-12-16 00:45:45 +0000752 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700753 struct net_device *netdev = adapter->netdev;
754 struct pci_dev *pdev = adapter->pdev;
755 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700756 struct e1000_buffer *buffer_info;
757 struct e1000_ps_page *ps_page;
758 struct sk_buff *skb;
759 unsigned int i, j;
760
761 i = rx_ring->next_to_use;
762 buffer_info = &rx_ring->buffer_info[i];
763
764 while (cleaned_count--) {
765 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
766
767 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700768 ps_page = &buffer_info->ps_pages[j];
769 if (j >= adapter->rx_ps_pages) {
770 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000771 rx_desc->read.buffer_addr[j + 1] =
772 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700773 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700774 }
Auke Kok47f44e42007-10-25 13:57:44 -0700775 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000776 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700777 if (!ps_page->page) {
778 adapter->alloc_rx_buff_failed++;
779 goto no_buffers;
780 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000781 ps_page->dma = dma_map_page(&pdev->dev,
782 ps_page->page,
783 0, PAGE_SIZE,
784 DMA_FROM_DEVICE);
785 if (dma_mapping_error(&pdev->dev,
786 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700787 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000788 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700789 adapter->rx_dma_failed++;
790 goto no_buffers;
791 }
792 }
Bruce Allane921eb12012-11-28 09:28:37 +0000793 /* Refresh the desc even if buffer_addrs
Auke Kok47f44e42007-10-25 13:57:44 -0700794 * didn't change because each write-back
795 * erases this info.
796 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000797 rx_desc->read.buffer_addr[j + 1] =
798 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700799 }
800
Bruce Allane5fe2542013-02-20 04:06:27 +0000801 skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000802 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700803
804 if (!skb) {
805 adapter->alloc_rx_buff_failed++;
806 break;
807 }
808
Auke Kokbc7f75f2007-09-17 12:30:59 -0700809 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000810 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700811 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000812 DMA_FROM_DEVICE);
813 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000814 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700815 adapter->rx_dma_failed++;
816 /* cleanup skb */
817 dev_kfree_skb_any(skb);
818 buffer_info->skb = NULL;
819 break;
820 }
821
822 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
823
Tom Herbert50849d72010-05-05 14:02:49 +0000824 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000825 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000826 * know there are new descriptors to fetch. (Only
827 * applicable for weak-ordered memory model archs,
828 * such as IA-64).
829 */
830 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700831 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000832 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700833 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000834 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000835 }
836
Auke Kokbc7f75f2007-09-17 12:30:59 -0700837 i++;
838 if (i == rx_ring->count)
839 i = 0;
840 buffer_info = &rx_ring->buffer_info[i];
841 }
842
843no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000844 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700845}
846
847/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700848 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000849 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700850 * @cleaned_count: number of buffers to allocate this pass
851 **/
852
Bruce Allan55aa6982011-12-16 00:45:45 +0000853static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000854 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700855{
Bruce Allan55aa6982011-12-16 00:45:45 +0000856 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700857 struct net_device *netdev = adapter->netdev;
858 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000859 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700860 struct e1000_buffer *buffer_info;
861 struct sk_buff *skb;
862 unsigned int i;
Bruce Allan2a2293b2012-12-05 06:26:35 +0000863 unsigned int bufsz = 256 - 16; /* for skb_reserve */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700864
865 i = rx_ring->next_to_use;
866 buffer_info = &rx_ring->buffer_info[i];
867
868 while (cleaned_count--) {
869 skb = buffer_info->skb;
870 if (skb) {
871 skb_trim(skb, 0);
872 goto check_page;
873 }
874
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000875 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700876 if (unlikely(!skb)) {
877 /* Better luck next round */
878 adapter->alloc_rx_buff_failed++;
879 break;
880 }
881
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700882 buffer_info->skb = skb;
883check_page:
884 /* allocate a new page if necessary */
885 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000886 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700887 if (unlikely(!buffer_info->page)) {
888 adapter->alloc_rx_buff_failed++;
889 break;
890 }
891 }
892
Christoph Paasch37287fae2013-03-20 08:59:46 +0000893 if (!buffer_info->dma) {
Nick Nunley0be3f552010-04-27 13:09:05 +0000894 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allanf0ff4392013-02-20 04:05:39 +0000895 buffer_info->page, 0,
896 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000897 DMA_FROM_DEVICE);
Christoph Paasch37287fae2013-03-20 08:59:46 +0000898 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
899 adapter->alloc_rx_buff_failed++;
900 break;
901 }
902 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700903
Bruce Allan5f450212011-07-22 06:21:46 +0000904 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
905 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700906
907 if (unlikely(++i == rx_ring->count))
908 i = 0;
909 buffer_info = &rx_ring->buffer_info[i];
910 }
911
912 if (likely(rx_ring->next_to_use != i)) {
913 rx_ring->next_to_use = i;
914 if (unlikely(i-- == 0))
915 i = (rx_ring->count - 1);
916
917 /* Force memory writes to complete before letting h/w
918 * know there are new descriptors to fetch. (Only
919 * applicable for weak-ordered memory model archs,
Bruce Allane921eb12012-11-28 09:28:37 +0000920 * such as IA-64).
921 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700922 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700923 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000924 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700925 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000926 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700927 }
928}
929
Bruce Allan70495a52012-01-11 01:26:50 +0000930static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
931 struct sk_buff *skb)
932{
933 if (netdev->features & NETIF_F_RXHASH)
Tom Herberte25909b2013-12-18 16:46:48 +0000934 skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3);
Bruce Allan70495a52012-01-11 01:26:50 +0000935}
936
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700937/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000938 * e1000_clean_rx_irq - Send received data up the network stack
939 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700940 *
941 * the return value indicates whether actual cleaning was done, there
942 * is no guarantee that everything was cleaned
943 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000944static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
945 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700946{
Bruce Allan55aa6982011-12-16 00:45:45 +0000947 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700948 struct net_device *netdev = adapter->netdev;
949 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000950 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000951 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000953 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700954 unsigned int i;
955 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000956 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
958
959 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000960 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
961 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700962 buffer_info = &rx_ring->buffer_info[i];
963
Bruce Allan5f450212011-07-22 06:21:46 +0000964 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700965 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700966
967 if (*work_done >= work_to_do)
968 break;
969 (*work_done)++;
Alexander Duyck837a1db2015-04-07 16:55:27 -0700970 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700971
Auke Kokbc7f75f2007-09-17 12:30:59 -0700972 skb = buffer_info->skb;
973 buffer_info->skb = NULL;
974
975 prefetch(skb->data - NET_IP_ALIGN);
976
977 i++;
978 if (i == rx_ring->count)
979 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000980 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700981 prefetch(next_rxd);
982
983 next_buffer = &rx_ring->buffer_info[i];
984
Rusty Russell3db1cd52011-12-19 13:56:45 +0000985 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700986 cleaned_count++;
Bruce Allane5fe2542013-02-20 04:06:27 +0000987 dma_unmap_single(&pdev->dev, buffer_info->dma,
988 adapter->rx_buffer_len, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700989 buffer_info->dma = 0;
990
Bruce Allan5f450212011-07-22 06:21:46 +0000991 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700992
Bruce Allane921eb12012-11-28 09:28:37 +0000993 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000994 * packet, if that's the case we need to toss it. In fact, we
995 * need to toss every packet with the EOP bit clear and the
996 * next frame that _does_ have the EOP bit set, as it is by
997 * definition only a frame fragment
998 */
Bruce Allan5f450212011-07-22 06:21:46 +0000999 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001000 adapter->flags2 |= FLAG2_IS_DISCARDING;
1001
1002 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001004 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005 /* recycle */
1006 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +00001007 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001008 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001009 goto next_desc;
1010 }
1011
Ben Greearcf955e62012-02-11 15:39:51 +00001012 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1013 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014 /* recycle */
1015 buffer_info->skb = skb;
1016 goto next_desc;
1017 }
1018
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001019 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +00001020 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1021 /* If configured to store CRC, don't subtract FCS,
1022 * but keep the FCS bytes out of the total_rx_bytes
1023 * counter
1024 */
1025 if (netdev->features & NETIF_F_RXFCS)
1026 total_rx_bytes -= 4;
1027 else
1028 length -= 4;
1029 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001030
Auke Kokbc7f75f2007-09-17 12:30:59 -07001031 total_rx_bytes += length;
1032 total_rx_packets++;
1033
Bruce Allane921eb12012-11-28 09:28:37 +00001034 /* code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -07001036 * of reassembly being done in the stack
1037 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001038 if (length < copybreak) {
1039 struct sk_buff *new_skb =
Alexander Duyck67fd8932014-12-09 19:40:56 -08001040 napi_alloc_skb(&adapter->napi, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001041 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -07001042 skb_copy_to_linear_data_offset(new_skb,
1043 -NET_IP_ALIGN,
1044 (skb->data -
1045 NET_IP_ALIGN),
1046 (length +
1047 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001048 /* save the skb in buffer_info as good */
1049 buffer_info->skb = skb;
1050 skb = new_skb;
1051 }
1052 /* else just continue with the old one */
1053 }
1054 /* end copybreak code */
1055 skb_put(skb, length);
1056
1057 /* Receive Checksum Offload */
Bruce Allan2e1706f2012-06-30 20:02:42 +00001058 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001059
Bruce Allan70495a52012-01-11 01:26:50 +00001060 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1061
Bruce Allan5f450212011-07-22 06:21:46 +00001062 e1000_receive_skb(adapter, netdev, skb, staterr,
1063 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001064
1065next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001066 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001067
1068 /* return some buffers to hardware, one at a time is too slow */
1069 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001070 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001071 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001072 cleaned_count = 0;
1073 }
1074
1075 /* use prefetched values */
1076 rx_desc = next_rxd;
1077 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001078
1079 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001080 }
1081 rx_ring->next_to_clean = i;
1082
1083 cleaned_count = e1000_desc_unused(rx_ring);
1084 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001085 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001086
Auke Kokbc7f75f2007-09-17 12:30:59 -07001087 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001088 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001089 return cleaned;
1090}
1091
Bruce Allan55aa6982011-12-16 00:45:45 +00001092static void e1000_put_txbuf(struct e1000_ring *tx_ring,
Florian Fainelli377b6272017-08-25 18:14:24 -07001093 struct e1000_buffer *buffer_info,
1094 bool drop)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095{
Bruce Allan55aa6982011-12-16 00:45:45 +00001096 struct e1000_adapter *adapter = tx_ring->adapter;
1097
Alexander Duyck03b13202009-12-02 16:45:31 +00001098 if (buffer_info->dma) {
1099 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001100 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1101 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001102 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001103 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1104 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001105 buffer_info->dma = 0;
1106 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001107 if (buffer_info->skb) {
Florian Fainelli377b6272017-08-25 18:14:24 -07001108 if (drop)
1109 dev_kfree_skb_any(buffer_info->skb);
1110 else
1111 dev_consume_skb_any(buffer_info->skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001112 buffer_info->skb = NULL;
1113 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001114 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115}
1116
Bruce Allan41cec6f2009-11-20 23:28:56 +00001117static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001118{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001119 struct e1000_adapter *adapter = container_of(work,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001120 struct e1000_adapter,
1121 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001122 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001123 struct e1000_ring *tx_ring = adapter->tx_ring;
1124 unsigned int i = tx_ring->next_to_clean;
1125 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1126 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001127 struct e1000_hw *hw = &adapter->hw;
1128 u16 phy_status, phy_1000t_status, phy_ext_status;
1129 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001130
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001131 if (test_bit(__E1000_DOWN, &adapter->state))
1132 return;
1133
Bruce Allane5fe2542013-02-20 04:06:27 +00001134 if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001135 /* May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001136 * flush pending descriptor writebacks to memory
1137 */
1138 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1139 /* execute the writes immediately */
1140 e1e_flush();
Bruce Allane921eb12012-11-28 09:28:37 +00001141 /* Due to rare timing issues, write to TIDV again to ensure
Matthew Vickbf030852012-03-16 09:03:00 +00001142 * the write is successful
1143 */
1144 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1145 /* execute the writes immediately */
1146 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001147 adapter->tx_hang_recheck = true;
1148 return;
1149 }
Jeff Kirsher09357b02011-11-18 14:25:00 +00001150 adapter->tx_hang_recheck = false;
David Ertmand9554e92014-01-08 01:07:55 +00001151
1152 if (er32(TDH(0)) == er32(TDT(0))) {
1153 e_dbg("false hang detected, ignoring\n");
1154 return;
1155 }
1156
1157 /* Real hang detected */
Jeff Kirsher09357b02011-11-18 14:25:00 +00001158 netif_stop_queue(netdev);
1159
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001160 e1e_rphy(hw, MII_BMSR, &phy_status);
1161 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1162 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001163
1164 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1165
1166 /* detected Hardware unit hang */
1167 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001168 " TDH <%x>\n"
1169 " TDT <%x>\n"
1170 " next_to_use <%x>\n"
1171 " next_to_clean <%x>\n"
1172 "buffer_info[next_to_clean]:\n"
1173 " time_stamp <%lx>\n"
1174 " next_to_watch <%x>\n"
1175 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001176 " next_to_watch.status <%x>\n"
1177 "MAC Status <%x>\n"
1178 "PHY Status <%x>\n"
1179 "PHY 1000BASE-T Status <%x>\n"
1180 "PHY Extended Status <%x>\n"
1181 "PCI Status <%x>\n",
Bruce Allane5fe2542013-02-20 04:06:27 +00001182 readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
1183 tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
1184 eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
1185 phy_status, phy_1000t_status, phy_ext_status, pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001186
David Ertmand9554e92014-01-08 01:07:55 +00001187 e1000e_dump(adapter);
1188
Bruce Allan7c0427e2012-03-20 03:48:08 +00001189 /* Suggest workaround for known h/w issue */
1190 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1191 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192}
1193
1194/**
Bruce Allanb67e1912012-12-27 08:32:33 +00001195 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1196 * @work: pointer to work struct
1197 *
1198 * This work function polls the TSYNCTXCTL valid bit to determine when a
1199 * timestamp has been taken for the current stored skb. The timestamp must
1200 * be for this skb because only one such packet is allowed in the queue.
1201 */
1202static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1203{
1204 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1205 tx_hwtstamp_work);
1206 struct e1000_hw *hw = &adapter->hw;
1207
Bruce Allanb67e1912012-12-27 08:32:33 +00001208 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
Jacob Keller50128632017-05-03 10:28:50 -07001209 struct sk_buff *skb = adapter->tx_hwtstamp_skb;
Bruce Allanb67e1912012-12-27 08:32:33 +00001210 struct skb_shared_hwtstamps shhwtstamps;
1211 u64 txstmp;
1212
1213 txstmp = er32(TXSTMPL);
1214 txstmp |= (u64)er32(TXSTMPH) << 32;
1215
1216 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1217
Jacob Keller50128632017-05-03 10:28:50 -07001218 /* Clear the global tx_hwtstamp_skb pointer and force writes
1219 * prior to notifying the stack of a Tx timestamp.
1220 */
Bruce Allanb67e1912012-12-27 08:32:33 +00001221 adapter->tx_hwtstamp_skb = NULL;
Jacob Keller50128632017-05-03 10:28:50 -07001222 wmb(); /* force write prior to skb_tstamp_tx */
1223
1224 skb_tstamp_tx(skb, &shhwtstamps);
Florian Fainelli377b6272017-08-25 18:14:24 -07001225 dev_consume_skb_any(skb);
Jakub Kicinski59c871c2014-03-15 14:55:00 +00001226 } else if (time_after(jiffies, adapter->tx_hwtstamp_start
1227 + adapter->tx_timeout_factor * HZ)) {
1228 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1229 adapter->tx_hwtstamp_skb = NULL;
1230 adapter->tx_hwtstamp_timeouts++;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +00001231 e_warn("clearing Tx timestamp hang\n");
Bruce Allanb67e1912012-12-27 08:32:33 +00001232 } else {
1233 /* reschedule to check later */
1234 schedule_work(&adapter->tx_hwtstamp_work);
1235 }
1236}
1237
1238/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001239 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001240 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001241 *
1242 * the return value indicates whether actual cleaning was done, there
1243 * is no guarantee that everything was cleaned
1244 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001245static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001246{
Bruce Allan55aa6982011-12-16 00:45:45 +00001247 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001248 struct net_device *netdev = adapter->netdev;
1249 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 struct e1000_tx_desc *tx_desc, *eop_desc;
1251 struct e1000_buffer *buffer_info;
1252 unsigned int i, eop;
1253 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001254 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001255 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001256
1257 i = tx_ring->next_to_clean;
1258 eop = tx_ring->buffer_info[i].next_to_watch;
1259 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1260
Alexander Duyck12d04a32009-03-25 22:05:03 +00001261 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1262 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001263 bool cleaned = false;
David Ertman6cf08d12014-04-05 06:07:00 +00001264
Alexander Duyck837a1db2015-04-07 16:55:27 -07001265 dma_rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001266 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001267 tx_desc = E1000_TX_DESC(*tx_ring, i);
1268 buffer_info = &tx_ring->buffer_info[i];
1269 cleaned = (i == eop);
1270
1271 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001272 total_tx_packets += buffer_info->segs;
1273 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001274 if (buffer_info->skb) {
1275 bytes_compl += buffer_info->skb->len;
1276 pkts_compl++;
1277 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001278 }
1279
Florian Fainelli377b6272017-08-25 18:14:24 -07001280 e1000_put_txbuf(tx_ring, buffer_info, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001281 tx_desc->upper.data = 0;
1282
1283 i++;
1284 if (i == tx_ring->count)
1285 i = 0;
1286 }
1287
Terry Loftindac87612010-04-09 10:29:49 +00001288 if (i == tx_ring->next_to_use)
1289 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001290 eop = tx_ring->buffer_info[i].next_to_watch;
1291 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001292 }
1293
1294 tx_ring->next_to_clean = i;
1295
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001296 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1297
Auke Kokbc7f75f2007-09-17 12:30:59 -07001298#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001299 if (count && netif_carrier_ok(netdev) &&
1300 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001301 /* Make sure that anybody stopping the queue after this
1302 * sees the new next_to_clean.
1303 */
1304 smp_mb();
1305
1306 if (netif_queue_stopped(netdev) &&
1307 !(test_bit(__E1000_DOWN, &adapter->state))) {
1308 netif_wake_queue(netdev);
1309 ++adapter->restart_queue;
1310 }
1311 }
1312
1313 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001314 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001315 * check with the clearing of time_stamp and movement of i
1316 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001317 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001318 if (tx_ring->buffer_info[i].time_stamp &&
1319 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001320 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001321 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001322 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001323 else
1324 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001325 }
1326 adapter->total_tx_bytes += total_tx_bytes;
1327 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001328 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001329}
1330
1331/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001332 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001333 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001334 *
1335 * the return value indicates whether actual cleaning was done, there
1336 * is no guarantee that everything was cleaned
1337 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001338static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1339 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001340{
Bruce Allan55aa6982011-12-16 00:45:45 +00001341 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001342 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001343 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1344 struct net_device *netdev = adapter->netdev;
1345 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001346 struct e1000_buffer *buffer_info, *next_buffer;
1347 struct e1000_ps_page *ps_page;
1348 struct sk_buff *skb;
1349 unsigned int i, j;
1350 u32 length, staterr;
1351 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001352 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001353 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1354
1355 i = rx_ring->next_to_clean;
1356 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1357 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1358 buffer_info = &rx_ring->buffer_info[i];
1359
1360 while (staterr & E1000_RXD_STAT_DD) {
1361 if (*work_done >= work_to_do)
1362 break;
1363 (*work_done)++;
1364 skb = buffer_info->skb;
Alexander Duyck837a1db2015-04-07 16:55:27 -07001365 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001366
1367 /* in the packet split case this is header only */
1368 prefetch(skb->data - NET_IP_ALIGN);
1369
1370 i++;
1371 if (i == rx_ring->count)
1372 i = 0;
1373 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1374 prefetch(next_rxd);
1375
1376 next_buffer = &rx_ring->buffer_info[i];
1377
Rusty Russell3db1cd52011-12-19 13:56:45 +00001378 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001379 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001380 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001381 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001382 buffer_info->dma = 0;
1383
Bruce Allanaf667a22010-12-31 06:10:01 +00001384 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001385 if (!(staterr & E1000_RXD_STAT_EOP))
1386 adapter->flags2 |= FLAG2_IS_DISCARDING;
1387
1388 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001389 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001390 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001391 if (staterr & E1000_RXD_STAT_EOP)
1392 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001393 goto next_desc;
1394 }
1395
Ben Greearcf955e62012-02-11 15:39:51 +00001396 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1397 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001398 dev_kfree_skb_irq(skb);
1399 goto next_desc;
1400 }
1401
1402 length = le16_to_cpu(rx_desc->wb.middle.length0);
1403
1404 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001405 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001406 dev_kfree_skb_irq(skb);
1407 goto next_desc;
1408 }
1409
1410 /* Good Receive */
1411 skb_put(skb, length);
1412
1413 {
Bruce Allane921eb12012-11-28 09:28:37 +00001414 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001415 * it more efficient than reusing j
1416 */
1417 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001418
Bruce Allane921eb12012-11-28 09:28:37 +00001419 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001420 * packet throughput, so unsplit small packets and
1421 * save the alloc/put only valid in softirq (napi)
1422 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001423 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001424 if (l1 && (l1 <= copybreak) &&
1425 ((length + l1) <= adapter->rx_ps_bsize0)) {
1426 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001427
Bruce Allan0e15df42012-01-31 06:37:11 +00001428 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001429
Bruce Allane921eb12012-11-28 09:28:37 +00001430 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001431 * kmap_atomic, so we can't hold the mapping
1432 * very long
1433 */
1434 dma_sync_single_for_cpu(&pdev->dev,
1435 ps_page->dma,
1436 PAGE_SIZE,
1437 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001438 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001439 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001440 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001441 dma_sync_single_for_device(&pdev->dev,
1442 ps_page->dma,
1443 PAGE_SIZE,
1444 DMA_FROM_DEVICE);
1445
1446 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001447 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1448 if (!(netdev->features & NETIF_F_RXFCS))
1449 l1 -= 4;
1450 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001451
1452 skb_put(skb, l1);
1453 goto copydone;
Bruce Allane80bd1d2013-05-01 01:19:46 +00001454 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001455 }
1456
1457 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1458 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1459 if (!length)
1460 break;
1461
Auke Kok47f44e42007-10-25 13:57:44 -07001462 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001463 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1464 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001465 ps_page->dma = 0;
1466 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1467 ps_page->page = NULL;
1468 skb->len += length;
1469 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001470 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001471 }
1472
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001473 /* strip the ethernet crc, problem is we're using pages now so
1474 * this whole operation can get a little cpu intensive
1475 */
Ben Greear01840392012-02-11 15:39:25 +00001476 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1477 if (!(netdev->features & NETIF_F_RXFCS))
1478 pskb_trim(skb, skb->len - 4);
1479 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001480
Auke Kokbc7f75f2007-09-17 12:30:59 -07001481copydone:
1482 total_rx_bytes += skb->len;
1483 total_rx_packets++;
1484
Bruce Allan2e1706f2012-06-30 20:02:42 +00001485 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001486
Bruce Allan70495a52012-01-11 01:26:50 +00001487 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1488
Auke Kokbc7f75f2007-09-17 12:30:59 -07001489 if (rx_desc->wb.upper.header_status &
Bruce Allan17e813e2013-02-20 04:06:01 +00001490 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001491 adapter->rx_hdr_split++;
1492
Bruce Allanb67e1912012-12-27 08:32:33 +00001493 e1000_receive_skb(adapter, netdev, skb, staterr,
1494 rx_desc->wb.middle.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001495
1496next_desc:
1497 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1498 buffer_info->skb = NULL;
1499
1500 /* return some buffers to hardware, one at a time is too slow */
1501 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001502 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001503 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001504 cleaned_count = 0;
1505 }
1506
1507 /* use prefetched values */
1508 rx_desc = next_rxd;
1509 buffer_info = next_buffer;
1510
1511 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1512 }
1513 rx_ring->next_to_clean = i;
1514
1515 cleaned_count = e1000_desc_unused(rx_ring);
1516 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001517 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001518
Auke Kokbc7f75f2007-09-17 12:30:59 -07001519 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001520 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001521 return cleaned;
1522}
1523
1524/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001525 * e1000_consume_page - helper function
1526 **/
1527static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
Bruce Allan66501f52013-02-20 04:05:55 +00001528 u16 length)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001529{
1530 bi->page = NULL;
1531 skb->len += length;
1532 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001533 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001534}
1535
1536/**
1537 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1538 * @adapter: board private structure
1539 *
1540 * the return value indicates whether actual cleaning was done, there
1541 * is no guarantee that everything was cleaned
1542 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001543static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1544 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001545{
Bruce Allan55aa6982011-12-16 00:45:45 +00001546 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001547 struct net_device *netdev = adapter->netdev;
1548 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001549 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001550 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001551 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001552 unsigned int i;
1553 int cleaned_count = 0;
1554 bool cleaned = false;
Bruce Allan362e20c2013-02-20 04:05:45 +00001555 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001556 struct skb_shared_info *shinfo;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001557
1558 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001559 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1560 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001561 buffer_info = &rx_ring->buffer_info[i];
1562
Bruce Allan5f450212011-07-22 06:21:46 +00001563 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001564 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001565
1566 if (*work_done >= work_to_do)
1567 break;
1568 (*work_done)++;
Alexander Duyck837a1db2015-04-07 16:55:27 -07001569 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001570
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001571 skb = buffer_info->skb;
1572 buffer_info->skb = NULL;
1573
1574 ++i;
1575 if (i == rx_ring->count)
1576 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001577 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001578 prefetch(next_rxd);
1579
1580 next_buffer = &rx_ring->buffer_info[i];
1581
1582 cleaned = true;
1583 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001584 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1585 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001586 buffer_info->dma = 0;
1587
Bruce Allan5f450212011-07-22 06:21:46 +00001588 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001589
1590 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001591 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001592 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1593 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001594 /* recycle both page and skb */
1595 buffer_info->skb = skb;
1596 /* an error means any chain goes out the window too */
1597 if (rx_ring->rx_skb_top)
1598 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1599 rx_ring->rx_skb_top = NULL;
1600 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001601 }
Bruce Allanf0f1a172010-12-11 05:53:32 +00001602#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001603 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001604 /* this descriptor is only the beginning (or middle) */
1605 if (!rxtop) {
1606 /* this is the beginning of a chain */
1607 rxtop = skb;
1608 skb_fill_page_desc(rxtop, 0, buffer_info->page,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001609 0, length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001610 } else {
1611 /* this is the middle of a chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001612 shinfo = skb_shinfo(rxtop);
1613 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1614 buffer_info->page, 0,
1615 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001616 /* re-use the skb, only consumed the page */
1617 buffer_info->skb = skb;
1618 }
1619 e1000_consume_page(buffer_info, rxtop, length);
1620 goto next_desc;
1621 } else {
1622 if (rxtop) {
1623 /* end of the chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001624 shinfo = skb_shinfo(rxtop);
1625 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1626 buffer_info->page, 0,
1627 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001628 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001629 * page
1630 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001631 buffer_info->skb = skb;
1632 skb = rxtop;
1633 rxtop = NULL;
1634 e1000_consume_page(buffer_info, skb, length);
1635 } else {
1636 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001637 * copybreak to save the put_page/alloc_page
1638 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001639 if (length <= copybreak &&
1640 skb_tailroom(skb) >= length) {
1641 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001642 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001643 memcpy(skb_tail_pointer(skb), vaddr,
1644 length);
Cong Wang46790262011-11-25 23:14:23 +08001645 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001646 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001647 * buffer_info->page
1648 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001649 skb_put(skb, length);
1650 } else {
1651 skb_fill_page_desc(skb, 0,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001652 buffer_info->page, 0,
1653 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001654 e1000_consume_page(buffer_info, skb,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001655 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001656 }
1657 }
1658 }
1659
Bruce Allan2e1706f2012-06-30 20:02:42 +00001660 /* Receive Checksum Offload */
1661 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001662
Bruce Allan70495a52012-01-11 01:26:50 +00001663 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1664
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001665 /* probably a little skewed due to removing CRC */
1666 total_rx_bytes += skb->len;
1667 total_rx_packets++;
1668
1669 /* eth type trans needs skb->data to point to something */
1670 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001671 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001672 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001673 goto next_desc;
1674 }
1675
Bruce Allan5f450212011-07-22 06:21:46 +00001676 e1000_receive_skb(adapter, netdev, skb, staterr,
1677 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001678
1679next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001680 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001681
1682 /* return some buffers to hardware, one at a time is too slow */
1683 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001684 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001685 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001686 cleaned_count = 0;
1687 }
1688
1689 /* use prefetched values */
1690 rx_desc = next_rxd;
1691 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001692
1693 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001694 }
1695 rx_ring->next_to_clean = i;
1696
1697 cleaned_count = e1000_desc_unused(rx_ring);
1698 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001699 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001700
1701 adapter->total_rx_bytes += total_rx_bytes;
1702 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001703 return cleaned;
1704}
1705
1706/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001708 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001709 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001710static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001711{
Bruce Allan55aa6982011-12-16 00:45:45 +00001712 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001713 struct e1000_buffer *buffer_info;
1714 struct e1000_ps_page *ps_page;
1715 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001716 unsigned int i, j;
1717
1718 /* Free all the Rx ring sk_buffs */
1719 for (i = 0; i < rx_ring->count; i++) {
1720 buffer_info = &rx_ring->buffer_info[i];
1721 if (buffer_info->dma) {
1722 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001723 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001724 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001725 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001726 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001727 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001728 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001729 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001730 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001731 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001732 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001733 buffer_info->dma = 0;
1734 }
1735
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001736 if (buffer_info->page) {
1737 put_page(buffer_info->page);
1738 buffer_info->page = NULL;
1739 }
1740
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741 if (buffer_info->skb) {
1742 dev_kfree_skb(buffer_info->skb);
1743 buffer_info->skb = NULL;
1744 }
1745
1746 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001747 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001748 if (!ps_page->page)
1749 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001750 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1751 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001752 ps_page->dma = 0;
1753 put_page(ps_page->page);
1754 ps_page->page = NULL;
1755 }
1756 }
1757
1758 /* there also may be some cached data from a chained receive */
1759 if (rx_ring->rx_skb_top) {
1760 dev_kfree_skb(rx_ring->rx_skb_top);
1761 rx_ring->rx_skb_top = NULL;
1762 }
1763
Auke Kokbc7f75f2007-09-17 12:30:59 -07001764 /* Zero out the descriptor ring */
1765 memset(rx_ring->desc, 0, rx_ring->size);
1766
1767 rx_ring->next_to_clean = 0;
1768 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001769 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001770}
1771
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001772static void e1000e_downshift_workaround(struct work_struct *work)
1773{
1774 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00001775 struct e1000_adapter,
1776 downshift_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001777
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001778 if (test_bit(__E1000_DOWN, &adapter->state))
1779 return;
1780
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001781 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1782}
1783
Auke Kokbc7f75f2007-09-17 12:30:59 -07001784/**
1785 * e1000_intr_msi - Interrupt Handler
1786 * @irq: interrupt number
1787 * @data: pointer to a network interface device structure
1788 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001789static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001790{
1791 struct net_device *netdev = data;
1792 struct e1000_adapter *adapter = netdev_priv(netdev);
1793 struct e1000_hw *hw = &adapter->hw;
1794 u32 icr = er32(ICR);
1795
Bruce Allane921eb12012-11-28 09:28:37 +00001796 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001797 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001798 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001799 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001800 * disconnect (LSC) before accessing any PHY registers
1801 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001802 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1803 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001804 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001805
Bruce Allane921eb12012-11-28 09:28:37 +00001806 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001807 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001808 * adapter in watchdog
1809 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001810 if (netif_carrier_ok(netdev) &&
1811 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1812 /* disable receives */
1813 u32 rctl = er32(RCTL);
David Ertman6cf08d12014-04-05 06:07:00 +00001814
Auke Kokbc7f75f2007-09-17 12:30:59 -07001815 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001816 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001817 }
1818 /* guard against interrupt when we're going down */
1819 if (!test_bit(__E1000_DOWN, &adapter->state))
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08001820 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001821 }
1822
Bruce Allan94fb8482013-01-23 09:00:03 +00001823 /* Reset on uncorrectable ECC error */
Sasha Neftinc8744f42017-04-06 10:26:47 +03001824 if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
Bruce Allan94fb8482013-01-23 09:00:03 +00001825 u32 pbeccsts = er32(PBECCSTS);
1826
1827 adapter->corr_errors +=
1828 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1829 adapter->uncorr_errors +=
1830 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1831 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1832
1833 /* Do the reset outside of interrupt context */
1834 schedule_work(&adapter->reset_task);
1835
1836 /* return immediately since reset is imminent */
1837 return IRQ_HANDLED;
1838 }
1839
Ben Hutchings288379f2009-01-19 16:43:59 -08001840 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001841 adapter->total_tx_bytes = 0;
1842 adapter->total_tx_packets = 0;
1843 adapter->total_rx_bytes = 0;
1844 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001845 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001846 }
1847
1848 return IRQ_HANDLED;
1849}
1850
1851/**
1852 * e1000_intr - Interrupt Handler
1853 * @irq: interrupt number
1854 * @data: pointer to a network interface device structure
1855 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001856static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001857{
1858 struct net_device *netdev = data;
1859 struct e1000_adapter *adapter = netdev_priv(netdev);
1860 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001861 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001862
Bruce Allana68ea772009-11-20 23:23:16 +00001863 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Bruce Allane80bd1d2013-05-01 01:19:46 +00001864 return IRQ_NONE; /* Not our interrupt */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001865
Bruce Allane921eb12012-11-28 09:28:37 +00001866 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001867 * not set, then the adapter didn't send an interrupt
1868 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001869 if (!(icr & E1000_ICR_INT_ASSERTED))
1870 return IRQ_NONE;
1871
Bruce Allane921eb12012-11-28 09:28:37 +00001872 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001873 * interrupts are masked. No need for the
1874 * IMC write
1875 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001876
dave graham573cca82009-02-10 12:52:05 +00001877 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001878 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001879 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001880 * disconnect (LSC) before accessing any PHY registers
1881 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001882 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1883 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001884 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001885
Bruce Allane921eb12012-11-28 09:28:37 +00001886 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001887 * For packet buffer work-around on link down event;
1888 * disable receives here in the ISR and
1889 * reset adapter in watchdog
1890 */
1891 if (netif_carrier_ok(netdev) &&
1892 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1893 /* disable receives */
1894 rctl = er32(RCTL);
1895 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001896 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001897 }
1898 /* guard against interrupt when we're going down */
1899 if (!test_bit(__E1000_DOWN, &adapter->state))
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08001900 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001901 }
1902
Bruce Allan94fb8482013-01-23 09:00:03 +00001903 /* Reset on uncorrectable ECC error */
Sasha Neftinc8744f42017-04-06 10:26:47 +03001904 if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
Bruce Allan94fb8482013-01-23 09:00:03 +00001905 u32 pbeccsts = er32(PBECCSTS);
1906
1907 adapter->corr_errors +=
1908 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1909 adapter->uncorr_errors +=
1910 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1911 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1912
1913 /* Do the reset outside of interrupt context */
1914 schedule_work(&adapter->reset_task);
1915
1916 /* return immediately since reset is imminent */
1917 return IRQ_HANDLED;
1918 }
1919
Ben Hutchings288379f2009-01-19 16:43:59 -08001920 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001921 adapter->total_tx_bytes = 0;
1922 adapter->total_tx_packets = 0;
1923 adapter->total_rx_bytes = 0;
1924 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001925 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001926 }
1927
1928 return IRQ_HANDLED;
1929}
1930
Bruce Allan8bb62862013-01-16 08:46:49 +00001931static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001932{
1933 struct net_device *netdev = data;
1934 struct e1000_adapter *adapter = netdev_priv(netdev);
1935 struct e1000_hw *hw = &adapter->hw;
Benjamin Poirier116f4a62018-02-08 15:47:14 +09001936 u32 icr = er32(ICR);
Benjamin Poirier745d0bd2018-01-31 16:26:27 +09001937
Benjamin Poirier361a9542018-02-08 15:47:13 +09001938 if (icr & adapter->eiac_mask)
1939 ew32(ICS, (icr & adapter->eiac_mask));
1940
Benjamin Poirier4aea7a5c2017-07-21 11:36:27 -07001941 if (icr & E1000_ICR_LSC) {
Benjamin Poirier4aea7a5c2017-07-21 11:36:27 -07001942 hw->mac.get_link_status = true;
1943 /* guard against interrupt when we're going down */
1944 if (!test_bit(__E1000_DOWN, &adapter->state))
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08001945 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Benjamin Poirier4aea7a5c2017-07-21 11:36:27 -07001946 }
1947
Benjamin Poirier1f0ea192018-02-08 15:47:12 +09001948 if (!test_bit(__E1000_DOWN, &adapter->state))
Benjamin Poirier116f4a62018-02-08 15:47:14 +09001949 ew32(IMS, E1000_IMS_OTHER | IMS_OTHER_MASK);
Bruce Allan4662e822008-08-26 18:37:06 -07001950
Bruce Allan4662e822008-08-26 18:37:06 -07001951 return IRQ_HANDLED;
1952}
1953
Bruce Allan8bb62862013-01-16 08:46:49 +00001954static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001955{
1956 struct net_device *netdev = data;
1957 struct e1000_adapter *adapter = netdev_priv(netdev);
1958 struct e1000_hw *hw = &adapter->hw;
1959 struct e1000_ring *tx_ring = adapter->tx_ring;
1960
Bruce Allan4662e822008-08-26 18:37:06 -07001961 adapter->total_tx_bytes = 0;
1962 adapter->total_tx_packets = 0;
1963
Bruce Allan55aa6982011-12-16 00:45:45 +00001964 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001965 /* Ring was not completely cleaned, so fire another interrupt */
1966 ew32(ICS, tx_ring->ims_val);
1967
Benjamin Poirier0a8047a2015-11-09 15:50:21 -08001968 if (!test_bit(__E1000_DOWN, &adapter->state))
1969 ew32(IMS, adapter->tx_ring->ims_val);
1970
Bruce Allan4662e822008-08-26 18:37:06 -07001971 return IRQ_HANDLED;
1972}
1973
Bruce Allan8bb62862013-01-16 08:46:49 +00001974static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001975{
1976 struct net_device *netdev = data;
1977 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001978 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001979
1980 /* Write the ITR value calculated at the end of the
1981 * previous interrupt.
1982 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001983 if (rx_ring->set_itr) {
Dmitry Fleytmanb77ac462015-10-13 12:48:18 +03001984 u32 itr = rx_ring->itr_val ?
1985 1000000000 / (rx_ring->itr_val * 256) : 0;
1986
1987 writel(itr, rx_ring->itr_register);
Bruce Allan55aa6982011-12-16 00:45:45 +00001988 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001989 }
1990
Ben Hutchings288379f2009-01-19 16:43:59 -08001991 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001992 adapter->total_rx_bytes = 0;
1993 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001994 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001995 }
1996 return IRQ_HANDLED;
1997}
1998
1999/**
2000 * e1000_configure_msix - Configure MSI-X hardware
2001 *
2002 * e1000_configure_msix sets up the hardware to properly
2003 * generate MSI-X interrupts.
2004 **/
2005static void e1000_configure_msix(struct e1000_adapter *adapter)
2006{
2007 struct e1000_hw *hw = &adapter->hw;
2008 struct e1000_ring *rx_ring = adapter->rx_ring;
2009 struct e1000_ring *tx_ring = adapter->tx_ring;
2010 int vector = 0;
2011 u32 ctrl_ext, ivar = 0;
2012
2013 adapter->eiac_mask = 0;
2014
2015 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
2016 if (hw->mac.type == e1000_82574) {
2017 u32 rfctl = er32(RFCTL);
David Ertman6cf08d12014-04-05 06:07:00 +00002018
Bruce Allan4662e822008-08-26 18:37:06 -07002019 rfctl |= E1000_RFCTL_ACK_DIS;
2020 ew32(RFCTL, rfctl);
2021 }
2022
Bruce Allan4662e822008-08-26 18:37:06 -07002023 /* Configure Rx vector */
2024 rx_ring->ims_val = E1000_IMS_RXQ0;
2025 adapter->eiac_mask |= rx_ring->ims_val;
2026 if (rx_ring->itr_val)
2027 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00002028 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002029 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00002030 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002031 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
2032
2033 /* Configure Tx vector */
2034 tx_ring->ims_val = E1000_IMS_TXQ0;
2035 vector++;
2036 if (tx_ring->itr_val)
2037 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00002038 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002039 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00002040 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002041 adapter->eiac_mask |= tx_ring->ims_val;
2042 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
2043
2044 /* set vector for Other Causes, e.g. link changes */
2045 vector++;
2046 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
2047 if (rx_ring->itr_val)
2048 writel(1000000000 / (rx_ring->itr_val * 256),
2049 hw->hw_addr + E1000_EITR_82574(vector));
2050 else
2051 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2052
2053 /* Cause Tx interrupts on every write back */
Jacob Keller18dd2392016-04-13 16:08:32 -07002054 ivar |= BIT(31);
Bruce Allan4662e822008-08-26 18:37:06 -07002055
2056 ew32(IVAR, ivar);
2057
2058 /* enable MSI-X PBA support */
Benjamin Poirier0a8047a2015-11-09 15:50:21 -08002059 ctrl_ext = er32(CTRL_EXT) & ~E1000_CTRL_EXT_IAME;
2060 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR | E1000_CTRL_EXT_EIAME;
Bruce Allan4662e822008-08-26 18:37:06 -07002061 ew32(CTRL_EXT, ctrl_ext);
2062 e1e_flush();
2063}
2064
2065void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2066{
2067 if (adapter->msix_entries) {
2068 pci_disable_msix(adapter->pdev);
2069 kfree(adapter->msix_entries);
2070 adapter->msix_entries = NULL;
2071 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2072 pci_disable_msi(adapter->pdev);
2073 adapter->flags &= ~FLAG_MSI_ENABLED;
2074 }
Bruce Allan4662e822008-08-26 18:37:06 -07002075}
2076
2077/**
2078 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2079 *
2080 * Attempt to configure interrupts using the best available
2081 * capabilities of the hardware and kernel.
2082 **/
2083void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2084{
2085 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002086 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002087
2088 switch (adapter->int_mode) {
2089 case E1000E_INT_MODE_MSIX:
2090 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002091 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2092 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan17e813e2013-02-20 04:06:01 +00002093 sizeof(struct
2094 msix_entry),
2095 GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002096 if (adapter->msix_entries) {
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002097 struct e1000_adapter *a = adapter;
2098
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002099 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002100 adapter->msix_entries[i].entry = i;
2101
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002102 err = pci_enable_msix_range(a->pdev,
2103 a->msix_entries,
2104 a->num_vectors,
2105 a->num_vectors);
2106 if (err > 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002107 return;
2108 }
2109 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002110 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002111 e1000e_reset_interrupt_capability(adapter);
2112 }
2113 adapter->int_mode = E1000E_INT_MODE_MSI;
2114 /* Fall through */
2115 case E1000E_INT_MODE_MSI:
2116 if (!pci_enable_msi(adapter->pdev)) {
2117 adapter->flags |= FLAG_MSI_ENABLED;
2118 } else {
2119 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002120 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002121 }
2122 /* Fall through */
2123 case E1000E_INT_MODE_LEGACY:
2124 /* Don't do anything; this is the system default */
2125 break;
2126 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002127
2128 /* store the number of vectors being used */
2129 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002130}
2131
2132/**
2133 * e1000_request_msix - Initialize MSI-X interrupts
2134 *
2135 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2136 * kernel.
2137 **/
2138static int e1000_request_msix(struct e1000_adapter *adapter)
2139{
2140 struct net_device *netdev = adapter->netdev;
2141 int err = 0, vector = 0;
2142
2143 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002144 snprintf(adapter->rx_ring->name,
2145 sizeof(adapter->rx_ring->name) - 1,
Florian Fainelli135e7242019-02-21 20:09:28 -08002146 "%.14s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002147 else
2148 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2149 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002150 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002151 netdev);
2152 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002153 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002154 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2155 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002156 adapter->rx_ring->itr_val = adapter->itr;
2157 vector++;
2158
2159 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002160 snprintf(adapter->tx_ring->name,
2161 sizeof(adapter->tx_ring->name) - 1,
Florian Fainelli135e7242019-02-21 20:09:28 -08002162 "%.14s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002163 else
2164 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2165 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002166 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002167 netdev);
2168 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002169 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002170 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2171 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002172 adapter->tx_ring->itr_val = adapter->itr;
2173 vector++;
2174
2175 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002176 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002177 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002178 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002179
2180 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002181
Bruce Allan4662e822008-08-26 18:37:06 -07002182 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002183}
2184
Bruce Allanf8d59f72008-08-08 18:36:11 -07002185/**
2186 * e1000_request_irq - initialize interrupts
2187 *
2188 * Attempts to configure interrupts using the best available
2189 * capabilities of the hardware and kernel.
2190 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002191static int e1000_request_irq(struct e1000_adapter *adapter)
2192{
2193 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002194 int err;
2195
Bruce Allan4662e822008-08-26 18:37:06 -07002196 if (adapter->msix_entries) {
2197 err = e1000_request_msix(adapter);
2198 if (!err)
2199 return err;
2200 /* fall back to MSI */
2201 e1000e_reset_interrupt_capability(adapter);
2202 adapter->int_mode = E1000E_INT_MODE_MSI;
2203 e1000e_set_interrupt_capability(adapter);
2204 }
2205 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002206 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002207 netdev->name, netdev);
2208 if (!err)
2209 return err;
2210
2211 /* fall back to legacy interrupt */
2212 e1000e_reset_interrupt_capability(adapter);
2213 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002214 }
2215
Joe Perchesa0607fd2009-11-18 23:29:17 -08002216 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002217 netdev->name, netdev);
2218 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002219 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002220
2221 return err;
2222}
2223
2224static void e1000_free_irq(struct e1000_adapter *adapter)
2225{
2226 struct net_device *netdev = adapter->netdev;
2227
Bruce Allan4662e822008-08-26 18:37:06 -07002228 if (adapter->msix_entries) {
2229 int vector = 0;
2230
2231 free_irq(adapter->msix_entries[vector].vector, netdev);
2232 vector++;
2233
2234 free_irq(adapter->msix_entries[vector].vector, netdev);
2235 vector++;
2236
2237 /* Other Causes interrupt vector */
2238 free_irq(adapter->msix_entries[vector].vector, netdev);
2239 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002240 }
Bruce Allan4662e822008-08-26 18:37:06 -07002241
2242 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002243}
2244
2245/**
2246 * e1000_irq_disable - Mask off interrupt generation on the NIC
2247 **/
2248static void e1000_irq_disable(struct e1000_adapter *adapter)
2249{
2250 struct e1000_hw *hw = &adapter->hw;
2251
Auke Kokbc7f75f2007-09-17 12:30:59 -07002252 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002253 if (adapter->msix_entries)
2254 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002255 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002256
2257 if (adapter->msix_entries) {
2258 int i;
David Ertman6cf08d12014-04-05 06:07:00 +00002259
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002260 for (i = 0; i < adapter->num_vectors; i++)
2261 synchronize_irq(adapter->msix_entries[i].vector);
2262 } else {
2263 synchronize_irq(adapter->pdev->irq);
2264 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002265}
2266
2267/**
2268 * e1000_irq_enable - Enable default interrupt generation settings
2269 **/
2270static void e1000_irq_enable(struct e1000_adapter *adapter)
2271{
2272 struct e1000_hw *hw = &adapter->hw;
2273
Bruce Allan4662e822008-08-26 18:37:06 -07002274 if (adapter->msix_entries) {
2275 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
Benjamin Poirier116f4a62018-02-08 15:47:14 +09002276 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER |
2277 IMS_OTHER_MASK);
Sasha Neftinc8744f42017-04-06 10:26:47 +03002278 } else if (hw->mac.type >= e1000_pch_lpt) {
Bruce Allan94fb8482013-01-23 09:00:03 +00002279 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002280 } else {
2281 ew32(IMS, IMS_ENABLE_MASK);
2282 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002283 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002284}
2285
2286/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002287 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288 * @adapter: address of board private structure
2289 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002290 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002291 * For ASF and Pass Through versions of f/w this means that
2292 * the driver is loaded. For AMT version (only with 82573)
2293 * of the f/w this means that the network i/f is open.
2294 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002295void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002296{
2297 struct e1000_hw *hw = &adapter->hw;
2298 u32 ctrl_ext;
2299 u32 swsm;
2300
2301 /* Let firmware know the driver has taken over */
2302 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2303 swsm = er32(SWSM);
2304 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2305 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2306 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002307 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002308 }
2309}
2310
2311/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002312 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002313 * @adapter: address of board private structure
2314 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002315 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002316 * For ASF and Pass Through versions of f/w this means that the
2317 * driver is no longer loaded. For AMT version (only with 82573) i
2318 * of the f/w this means that the network i/f is closed.
2319 *
2320 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002321void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002322{
2323 struct e1000_hw *hw = &adapter->hw;
2324 u32 ctrl_ext;
2325 u32 swsm;
2326
2327 /* Let firmware taken over control of h/w */
2328 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2329 swsm = er32(SWSM);
2330 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2331 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2332 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002333 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334 }
2335}
2336
Auke Kokbc7f75f2007-09-17 12:30:59 -07002337/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002338 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002339 **/
2340static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2341 struct e1000_ring *ring)
2342{
2343 struct pci_dev *pdev = adapter->pdev;
2344
Luis Chamberlain750afb02019-01-04 09:23:09 +01002345 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2346 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002347 if (!ring->desc)
2348 return -ENOMEM;
2349
2350 return 0;
2351}
2352
2353/**
2354 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002355 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356 *
2357 * Return 0 on success, negative on failure
2358 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002359int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002360{
Bruce Allan55aa6982011-12-16 00:45:45 +00002361 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002362 int err = -ENOMEM, size;
2363
2364 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002365 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366 if (!tx_ring->buffer_info)
2367 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002368
2369 /* round up to nearest 4K */
2370 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2371 tx_ring->size = ALIGN(tx_ring->size, 4096);
2372
2373 err = e1000_alloc_ring_dma(adapter, tx_ring);
2374 if (err)
2375 goto err;
2376
2377 tx_ring->next_to_use = 0;
2378 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002379
2380 return 0;
2381err:
2382 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002383 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384 return err;
2385}
2386
2387/**
2388 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002389 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002390 *
2391 * Returns 0 on success, negative on failure
2392 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002393int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002394{
Bruce Allan55aa6982011-12-16 00:45:45 +00002395 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002396 struct e1000_buffer *buffer_info;
2397 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398
2399 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002400 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002401 if (!rx_ring->buffer_info)
2402 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002403
Auke Kok47f44e42007-10-25 13:57:44 -07002404 for (i = 0; i < rx_ring->count; i++) {
2405 buffer_info = &rx_ring->buffer_info[i];
2406 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2407 sizeof(struct e1000_ps_page),
2408 GFP_KERNEL);
2409 if (!buffer_info->ps_pages)
2410 goto err_pages;
2411 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002412
2413 desc_len = sizeof(union e1000_rx_desc_packet_split);
2414
2415 /* Round up to nearest 4K */
2416 rx_ring->size = rx_ring->count * desc_len;
2417 rx_ring->size = ALIGN(rx_ring->size, 4096);
2418
2419 err = e1000_alloc_ring_dma(adapter, rx_ring);
2420 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002421 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002422
2423 rx_ring->next_to_clean = 0;
2424 rx_ring->next_to_use = 0;
2425 rx_ring->rx_skb_top = NULL;
2426
2427 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002428
2429err_pages:
2430 for (i = 0; i < rx_ring->count; i++) {
2431 buffer_info = &rx_ring->buffer_info[i];
2432 kfree(buffer_info->ps_pages);
2433 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434err:
2435 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002436 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437 return err;
2438}
2439
2440/**
2441 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002442 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002443 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002444static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002445{
Bruce Allan55aa6982011-12-16 00:45:45 +00002446 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002447 struct e1000_buffer *buffer_info;
2448 unsigned long size;
2449 unsigned int i;
2450
2451 for (i = 0; i < tx_ring->count; i++) {
2452 buffer_info = &tx_ring->buffer_info[i];
Florian Fainelli377b6272017-08-25 18:14:24 -07002453 e1000_put_txbuf(tx_ring, buffer_info, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 }
2455
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002456 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002457 size = sizeof(struct e1000_buffer) * tx_ring->count;
2458 memset(tx_ring->buffer_info, 0, size);
2459
2460 memset(tx_ring->desc, 0, tx_ring->size);
2461
2462 tx_ring->next_to_use = 0;
2463 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002464}
2465
2466/**
2467 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002468 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002469 *
2470 * Free all transmit software resources
2471 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002472void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002473{
Bruce Allan55aa6982011-12-16 00:45:45 +00002474 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002475 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002476
Bruce Allan55aa6982011-12-16 00:45:45 +00002477 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002478
2479 vfree(tx_ring->buffer_info);
2480 tx_ring->buffer_info = NULL;
2481
2482 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2483 tx_ring->dma);
2484 tx_ring->desc = NULL;
2485}
2486
2487/**
2488 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002489 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002490 *
2491 * Free all receive software resources
2492 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002493void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002494{
Bruce Allan55aa6982011-12-16 00:45:45 +00002495 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002496 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002497 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002498
Bruce Allan55aa6982011-12-16 00:45:45 +00002499 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002501 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002502 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002503
Auke Kokbc7f75f2007-09-17 12:30:59 -07002504 vfree(rx_ring->buffer_info);
2505 rx_ring->buffer_info = NULL;
2506
Auke Kokbc7f75f2007-09-17 12:30:59 -07002507 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2508 rx_ring->dma);
2509 rx_ring->desc = NULL;
2510}
2511
2512/**
2513 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002514 * @adapter: pointer to adapter
2515 * @itr_setting: current adapter->itr
2516 * @packets: the number of packets during this measurement interval
2517 * @bytes: the number of bytes during this measurement interval
2518 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002519 * Stores a new ITR value based on packets and byte
2520 * counts during the last interrupt. The advantage of per interrupt
2521 * computation is faster updates and more accurate ITR for the current
2522 * traffic pattern. Constants in this function were computed
2523 * based on theoretical maximum wire speed and thresholds were set based
2524 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002525 * while increasing bulk throughput. This functionality is controlled
2526 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002528static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002529{
2530 unsigned int retval = itr_setting;
2531
2532 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002533 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002534
2535 switch (itr_setting) {
2536 case lowest_latency:
2537 /* handle TSO and jumbo frames */
Bruce Allan362e20c2013-02-20 04:05:45 +00002538 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002539 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002540 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002541 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002542 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002543 case low_latency: /* 50 usec aka 20000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002544 if (bytes > 10000) {
2545 /* this if handles the TSO accounting */
Bruce Allan362e20c2013-02-20 04:05:45 +00002546 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002547 retval = bulk_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002548 else if ((packets < 10) || ((bytes / packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002549 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002550 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002551 retval = lowest_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002552 } else if (bytes / packets > 2000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002553 retval = bulk_latency;
2554 } else if (packets <= 2 && bytes < 512) {
2555 retval = lowest_latency;
2556 }
2557 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002558 case bulk_latency: /* 250 usec aka 4000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002559 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002560 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002561 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002562 } else if (bytes < 6000) {
2563 retval = low_latency;
2564 }
2565 break;
2566 }
2567
Auke Kokbc7f75f2007-09-17 12:30:59 -07002568 return retval;
2569}
2570
2571static void e1000_set_itr(struct e1000_adapter *adapter)
2572{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002573 u16 current_itr;
2574 u32 new_itr = adapter->itr;
2575
2576 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2577 if (adapter->link_speed != SPEED_1000) {
2578 current_itr = 0;
2579 new_itr = 4000;
2580 goto set_itr_now;
2581 }
2582
Bruce Allan828bac82010-09-29 21:39:37 +00002583 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2584 new_itr = 0;
2585 goto set_itr_now;
2586 }
2587
Bruce Allan8bb62862013-01-16 08:46:49 +00002588 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2589 adapter->total_tx_packets,
2590 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002591 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2592 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2593 adapter->tx_itr = low_latency;
2594
Bruce Allan8bb62862013-01-16 08:46:49 +00002595 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2596 adapter->total_rx_packets,
2597 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002598 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2599 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2600 adapter->rx_itr = low_latency;
2601
2602 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2603
Auke Kokbc7f75f2007-09-17 12:30:59 -07002604 /* counts and packets in update_itr are dependent on these numbers */
Bruce Allan33550ce2013-02-20 04:06:16 +00002605 switch (current_itr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002606 case lowest_latency:
2607 new_itr = 70000;
2608 break;
2609 case low_latency:
Bruce Allane80bd1d2013-05-01 01:19:46 +00002610 new_itr = 20000; /* aka hwitr = ~200 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611 break;
2612 case bulk_latency:
2613 new_itr = 4000;
2614 break;
2615 default:
2616 break;
2617 }
2618
2619set_itr_now:
2620 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002621 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002622 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002623 * increasing
2624 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002625 new_itr = new_itr > adapter->itr ?
Bruce Allanf0ff4392013-02-20 04:05:39 +00002626 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002627 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002628 adapter->rx_ring->itr_val = new_itr;
2629 if (adapter->msix_entries)
2630 adapter->rx_ring->set_itr = 1;
2631 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002632 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002633 }
2634}
2635
2636/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002637 * e1000e_write_itr - write the ITR value to the appropriate registers
2638 * @adapter: address of board private structure
2639 * @itr: new ITR value to program
2640 *
2641 * e1000e_write_itr determines if the adapter is in MSI-X mode
2642 * and, if so, writes the EITR registers with the ITR value.
2643 * Otherwise, it writes the ITR value into the ITR register.
2644 **/
2645void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2646{
2647 struct e1000_hw *hw = &adapter->hw;
2648 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2649
2650 if (adapter->msix_entries) {
2651 int vector;
2652
2653 for (vector = 0; vector < adapter->num_vectors; vector++)
2654 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2655 } else {
2656 ew32(ITR, new_itr);
2657 }
2658}
2659
2660/**
Bruce Allan4662e822008-08-26 18:37:06 -07002661 * e1000_alloc_queues - Allocate memory for all rings
2662 * @adapter: board private structure to initialize
2663 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002664static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002665{
Bruce Allan55aa6982011-12-16 00:45:45 +00002666 int size = sizeof(struct e1000_ring);
2667
2668 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002669 if (!adapter->tx_ring)
2670 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002671 adapter->tx_ring->count = adapter->tx_ring_count;
2672 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002673
Bruce Allan55aa6982011-12-16 00:45:45 +00002674 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002675 if (!adapter->rx_ring)
2676 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002677 adapter->rx_ring->count = adapter->rx_ring_count;
2678 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002679
2680 return 0;
2681err:
2682 e_err("Unable to allocate memory for queues\n");
2683 kfree(adapter->rx_ring);
2684 kfree(adapter->tx_ring);
2685 return -ENOMEM;
2686}
2687
2688/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002689 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002690 * @napi: struct associated with this polling callback
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002691 * @budget: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002692 **/
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002693static int e1000e_poll(struct napi_struct *napi, int budget)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002695 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2696 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002697 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002698 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002699 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002700
Wang Chen4cf16532008-11-12 23:38:14 -08002701 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002702
Bruce Allanc58c8a72012-03-20 03:48:19 +00002703 if (!adapter->msix_entries ||
2704 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2705 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002706
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002707 adapter->clean_rx(adapter->rx_ring, &work_done, budget);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002708
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002709 if (!tx_cleaned || work_done == budget)
2710 return budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002711
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002712 /* Exit the polling mode, but don't re-enable interrupts if stack might
2713 * poll us due to busy-polling
2714 */
2715 if (likely(napi_complete_done(napi, work_done))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002716 if (adapter->itr_setting & 3)
2717 e1000_set_itr(adapter);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002718 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2719 if (adapter->msix_entries)
Benjamin Poirier1f0ea192018-02-08 15:47:12 +09002720 ew32(IMS, adapter->rx_ring->ims_val);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002721 else
2722 e1000_irq_enable(adapter);
2723 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002724 }
2725
2726 return work_done;
2727}
2728
Patrick McHardy80d5c362013-04-19 02:04:28 +00002729static int e1000_vlan_rx_add_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002730 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002731{
2732 struct e1000_adapter *adapter = netdev_priv(netdev);
2733 struct e1000_hw *hw = &adapter->hw;
2734 u32 vfta, index;
2735
2736 /* don't update vlan cookie if already programmed */
2737 if ((adapter->hw.mng_cookie.status &
2738 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2739 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002740 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002741
Auke Kokbc7f75f2007-09-17 12:30:59 -07002742 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002743 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2744 index = (vid >> 5) & 0x7F;
2745 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
Jacob Keller18dd2392016-04-13 16:08:32 -07002746 vfta |= BIT((vid & 0x1F));
Bruce Allancaaddaf2009-12-01 15:46:43 +00002747 hw->mac.ops.write_vfta(hw, index, vfta);
2748 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002749
2750 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002751
2752 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002753}
2754
Patrick McHardy80d5c362013-04-19 02:04:28 +00002755static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002756 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002757{
2758 struct e1000_adapter *adapter = netdev_priv(netdev);
2759 struct e1000_hw *hw = &adapter->hw;
2760 u32 vfta, index;
2761
Auke Kokbc7f75f2007-09-17 12:30:59 -07002762 if ((adapter->hw.mng_cookie.status &
2763 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2764 (vid == adapter->mng_vlan_id)) {
2765 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002766 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002767 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002768 }
2769
2770 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002771 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2772 index = (vid >> 5) & 0x7F;
2773 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
Jacob Keller18dd2392016-04-13 16:08:32 -07002774 vfta &= ~BIT((vid & 0x1F));
Bruce Allancaaddaf2009-12-01 15:46:43 +00002775 hw->mac.ops.write_vfta(hw, index, vfta);
2776 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002777
2778 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002779
2780 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002781}
2782
2783/**
2784 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2785 * @adapter: board private structure to initialize
2786 **/
2787static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2788{
2789 struct net_device *netdev = adapter->netdev;
2790 struct e1000_hw *hw = &adapter->hw;
2791 u32 rctl;
2792
2793 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2794 /* disable VLAN receive filtering */
2795 rctl = er32(RCTL);
2796 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2797 ew32(RCTL, rctl);
2798
2799 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002800 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
2801 adapter->mng_vlan_id);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002802 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2803 }
2804 }
2805}
2806
2807/**
2808 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2809 * @adapter: board private structure to initialize
2810 **/
2811static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2812{
2813 struct e1000_hw *hw = &adapter->hw;
2814 u32 rctl;
2815
2816 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2817 /* enable VLAN receive filtering */
2818 rctl = er32(RCTL);
2819 rctl |= E1000_RCTL_VFE;
2820 rctl &= ~E1000_RCTL_CFIEN;
2821 ew32(RCTL, rctl);
2822 }
2823}
2824
2825/**
Jarod Wilson889ad452016-06-28 20:41:31 -07002826 * e1000e_vlan_strip_disable - helper to disable HW VLAN stripping
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002827 * @adapter: board private structure to initialize
2828 **/
2829static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2830{
2831 struct e1000_hw *hw = &adapter->hw;
2832 u32 ctrl;
2833
2834 /* disable VLAN tag insert/strip */
2835 ctrl = er32(CTRL);
2836 ctrl &= ~E1000_CTRL_VME;
2837 ew32(CTRL, ctrl);
2838}
2839
2840/**
2841 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2842 * @adapter: board private structure to initialize
2843 **/
2844static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2845{
2846 struct e1000_hw *hw = &adapter->hw;
2847 u32 ctrl;
2848
2849 /* enable VLAN tag insert/strip */
2850 ctrl = er32(CTRL);
2851 ctrl |= E1000_CTRL_VME;
2852 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002853}
2854
2855static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2856{
2857 struct net_device *netdev = adapter->netdev;
2858 u16 vid = adapter->hw.mng_cookie.vlan_id;
2859 u16 old_vid = adapter->mng_vlan_id;
2860
Bruce Allane5fe2542013-02-20 04:06:27 +00002861 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002862 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002863 adapter->mng_vlan_id = vid;
2864 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002865
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002866 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
Patrick McHardy80d5c362013-04-19 02:04:28 +00002867 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002868}
2869
2870static void e1000_restore_vlan(struct e1000_adapter *adapter)
2871{
2872 u16 vid;
2873
Patrick McHardy80d5c362013-04-19 02:04:28 +00002874 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002875
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002876 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00002877 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002878}
2879
Bruce Allancd791612010-05-10 14:59:51 +00002880static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002881{
2882 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002883 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002884
2885 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2886 return;
2887
2888 manc = er32(MANC);
2889
Bruce Allane921eb12012-11-28 09:28:37 +00002890 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002891 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002892 * the packets will be handled on SMBUS
2893 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002894 manc |= E1000_MANC_EN_MNG2HOST;
2895 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002896
2897 switch (hw->mac.type) {
2898 default:
2899 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2900 break;
2901 case e1000_82574:
2902 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002903 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002904 * if so, enable it.
2905 */
2906 for (i = 0, j = 0; i < 8; i++) {
2907 mdef = er32(MDEF(i));
2908
2909 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002910 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002911 continue;
2912
2913 /* Enable this decision filter in MANC2H */
2914 if (mdef)
Jacob Keller18dd2392016-04-13 16:08:32 -07002915 manc2h |= BIT(i);
Bruce Allancd791612010-05-10 14:59:51 +00002916
2917 j |= mdef;
2918 }
2919
2920 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2921 break;
2922
2923 /* Create new decision filter in an empty filter */
2924 for (i = 0, j = 0; i < 8; i++)
2925 if (er32(MDEF(i)) == 0) {
2926 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2927 E1000_MDEF_PORT_664));
Jacob Keller18dd2392016-04-13 16:08:32 -07002928 manc2h |= BIT(1);
Bruce Allancd791612010-05-10 14:59:51 +00002929 j++;
2930 break;
2931 }
2932
2933 if (!j)
2934 e_warn("Unable to create IPMI pass-through filter\n");
2935 break;
2936 }
2937
Auke Kokbc7f75f2007-09-17 12:30:59 -07002938 ew32(MANC2H, manc2h);
2939 ew32(MANC, manc);
2940}
2941
2942/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002943 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002944 * @adapter: board private structure
2945 *
2946 * Configure the Tx unit of the MAC after a reset.
2947 **/
2948static void e1000_configure_tx(struct e1000_adapter *adapter)
2949{
2950 struct e1000_hw *hw = &adapter->hw;
2951 struct e1000_ring *tx_ring = adapter->tx_ring;
2952 u64 tdba;
David Ertmane7e834a2014-01-13 23:19:27 +00002953 u32 tdlen, tctl, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002954
2955 /* Setup the HW Tx Head and Tail descriptor pointers */
2956 tdba = tx_ring->dma;
2957 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002958 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2959 ew32(TDBAH(0), (tdba >> 32));
2960 ew32(TDLEN(0), tdlen);
2961 ew32(TDH(0), 0);
2962 ew32(TDT(0), 0);
2963 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2964 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002965
Jia-Ju Bai0845d452015-08-05 18:16:10 +08002966 writel(0, tx_ring->head);
2967 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2968 e1000e_update_tdt_wa(tx_ring, 0);
2969 else
2970 writel(0, tx_ring->tail);
2971
Auke Kokbc7f75f2007-09-17 12:30:59 -07002972 /* Set the Tx Interrupt Delay register */
2973 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002974 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002975 ew32(TADV, adapter->tx_abs_int_delay);
2976
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002977 if (adapter->flags2 & FLAG2_DMA_BURST) {
2978 u32 txdctl = er32(TXDCTL(0));
David Ertman6cf08d12014-04-05 06:07:00 +00002979
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002980 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2981 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002982 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002983 * hardware to use the bus more efficiently in bursts, depends
2984 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002985 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002986 * hthresh = 1 ==> prefetch when one or more available
2987 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2988 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002989 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002990 */
2991 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2992 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002993 }
Bruce Allan56032be2011-12-16 00:46:01 +00002994 /* erratum work around: set txdctl the same for both queues */
2995 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002996
David Ertmane7e834a2014-01-13 23:19:27 +00002997 /* Program the Transmit Control Register */
2998 tctl = er32(TCTL);
2999 tctl &= ~E1000_TCTL_CT;
3000 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
3001 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
3002
Auke Kokbc7f75f2007-09-17 12:30:59 -07003003 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003004 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00003005 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07003006 * gigabit link later
3007 */
Jacob Keller18dd2392016-04-13 16:08:32 -07003008#define SPEED_MODE_BIT BIT(21)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003009 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003010 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003011 }
3012
3013 /* errata: program both queues to unweighted RR */
3014 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003015 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003016 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003017 ew32(TARC(0), tarc);
3018 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003019 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003020 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003021 }
3022
Auke Kokbc7f75f2007-09-17 12:30:59 -07003023 /* Setup Transmit Descriptor Settings for eop descriptor */
3024 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
3025
3026 /* only set IDE if we are delaying interrupts using the timers */
3027 if (adapter->tx_int_delay)
3028 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
3029
3030 /* enable Report Status bit */
3031 adapter->txd_cmd |= E1000_TXD_CMD_RS;
3032
David Ertmane7e834a2014-01-13 23:19:27 +00003033 ew32(TCTL, tctl);
3034
Bruce Allan57cde762012-02-22 09:02:58 +00003035 hw->mac.ops.config_collision_dist(hw);
David Ertman79849eb2015-02-10 09:10:43 +00003036
Sasha Neftinb10effb2017-08-06 16:49:18 +03003037 /* SPT and KBL Si errata workaround to avoid data corruption */
3038 if (hw->mac.type == e1000_pch_spt) {
David Ertman79849eb2015-02-10 09:10:43 +00003039 u32 reg_val;
3040
3041 reg_val = er32(IOSFPC);
3042 reg_val |= E1000_RCTL_RDMTS_HEX;
3043 ew32(IOSFPC, reg_val);
3044
3045 reg_val = er32(TARC(0));
Sasha Neftinc0f4b162017-11-06 08:31:59 +02003046 /* SPT and KBL Si errata workaround to avoid Tx hang.
3047 * Dropping the number of outstanding requests from
3048 * 3 to 2 in order to avoid a buffer overrun.
3049 */
3050 reg_val &= ~E1000_TARC0_CB_MULTIQ_3_REQ;
3051 reg_val |= E1000_TARC0_CB_MULTIQ_2_REQ;
David Ertman79849eb2015-02-10 09:10:43 +00003052 ew32(TARC(0), reg_val);
3053 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003054}
3055
3056/**
3057 * e1000_setup_rctl - configure the receive control registers
3058 * @adapter: Board private structure
3059 **/
3060#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
3061 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
3062static void e1000_setup_rctl(struct e1000_adapter *adapter)
3063{
3064 struct e1000_hw *hw = &adapter->hw;
3065 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003066 u32 pages = 0;
3067
David Ertmanb20a7742014-03-25 04:27:55 +00003068 /* Workaround Si errata on PCHx - configure jumbo frame flow.
3069 * If jumbo frames not set, program related MAC/PHY registers
3070 * to h/w defaults
3071 */
3072 if (hw->mac.type >= e1000_pch2lan) {
3073 s32 ret_val;
3074
3075 if (adapter->netdev->mtu > ETH_DATA_LEN)
3076 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
3077 else
3078 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
3079
3080 if (ret_val)
3081 e_dbg("failed to enable|disable jumbo frame workaround mode\n");
3082 }
Bruce Allana1ce6472010-09-22 17:16:40 +00003083
Auke Kokbc7f75f2007-09-17 12:30:59 -07003084 /* Program MC offset vector base */
3085 rctl = er32(RCTL);
3086 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3087 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
Bruce Allanf0ff4392013-02-20 04:05:39 +00003088 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3089 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003090
3091 /* Do not Store bad packets */
3092 rctl &= ~E1000_RCTL_SBP;
3093
3094 /* Enable Long Packet receive */
3095 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3096 rctl &= ~E1000_RCTL_LPE;
3097 else
3098 rctl |= E1000_RCTL_LPE;
3099
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003100 /* Some systems expect that the CRC is included in SMBUS traffic. The
3101 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3102 * host memory when this is enabled
3103 */
3104 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3105 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003106
Bruce Allana4f58f52009-06-02 11:29:18 +00003107 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3108 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3109 u16 phy_data;
3110
3111 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3112 phy_data &= 0xfff8;
Jacob Keller18dd2392016-04-13 16:08:32 -07003113 phy_data |= BIT(2);
Bruce Allana4f58f52009-06-02 11:29:18 +00003114 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3115
3116 e1e_rphy(hw, 22, &phy_data);
3117 phy_data &= 0x0fff;
Jacob Keller18dd2392016-04-13 16:08:32 -07003118 phy_data |= BIT(14);
Bruce Allana4f58f52009-06-02 11:29:18 +00003119 e1e_wphy(hw, 0x10, 0x2823);
3120 e1e_wphy(hw, 0x11, 0x0003);
3121 e1e_wphy(hw, 22, phy_data);
3122 }
3123
Auke Kokbc7f75f2007-09-17 12:30:59 -07003124 /* Setup buffer sizes */
3125 rctl &= ~E1000_RCTL_SZ_4096;
3126 rctl |= E1000_RCTL_BSEX;
3127 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128 case 2048:
3129 default:
3130 rctl |= E1000_RCTL_SZ_2048;
3131 rctl &= ~E1000_RCTL_BSEX;
3132 break;
3133 case 4096:
3134 rctl |= E1000_RCTL_SZ_4096;
3135 break;
3136 case 8192:
3137 rctl |= E1000_RCTL_SZ_8192;
3138 break;
3139 case 16384:
3140 rctl |= E1000_RCTL_SZ_16384;
3141 break;
3142 }
3143
Bruce Allan5f450212011-07-22 06:21:46 +00003144 /* Enable Extended Status in all Receive Descriptors */
3145 rfctl = er32(RFCTL);
3146 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003147 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003148
Bruce Allane921eb12012-11-28 09:28:37 +00003149 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003150 * header is placed in skb->data and the packet data is
3151 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3152 * In the case of a non-split, skb->data is linearly filled,
3153 * followed by the page buffers. Therefore, skb->data is
3154 * sized to hold the largest protocol header.
3155 *
3156 * allocations using alloc_page take too long for regular MTU
3157 * so only enable packet split for jumbo frames
3158 *
3159 * Using pages when the page size is greater than 16k wastes
3160 * a lot of memory, since we allocate 3 pages at all times
3161 * per packet.
3162 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003163 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003164 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003165 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003166 else
3167 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003168
3169 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003170 u32 psrctl = 0;
3171
Auke Kok140a7482007-10-25 13:57:58 -07003172 /* Enable Packet split descriptors */
3173 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003174
Bruce Allane5fe2542013-02-20 04:06:27 +00003175 psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003176
3177 switch (adapter->rx_ps_pages) {
3178 case 3:
Bruce Allane5fe2542013-02-20 04:06:27 +00003179 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
3180 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003181 case 2:
Bruce Allane5fe2542013-02-20 04:06:27 +00003182 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
3183 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003184 case 1:
Bruce Allane5fe2542013-02-20 04:06:27 +00003185 psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003186 break;
3187 }
3188
3189 ew32(PSRCTL, psrctl);
3190 }
3191
Ben Greearcf955e62012-02-11 15:39:51 +00003192 /* This is useful for sniffing bad packets. */
3193 if (adapter->netdev->features & NETIF_F_RXALL) {
3194 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003195 * in e1000e_set_rx_mode
3196 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00003197 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3198 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3199 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
Ben Greearcf955e62012-02-11 15:39:51 +00003200
Bruce Allane80bd1d2013-05-01 01:19:46 +00003201 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3202 E1000_RCTL_DPF | /* Allow filtered pause */
3203 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
Ben Greearcf955e62012-02-11 15:39:51 +00003204 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3205 * and that breaks VLANs.
3206 */
3207 }
3208
Auke Kokbc7f75f2007-09-17 12:30:59 -07003209 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003210 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003211 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003212}
3213
3214/**
3215 * e1000_configure_rx - Configure Receive Unit after Reset
3216 * @adapter: board private structure
3217 *
3218 * Configure the Rx unit of the MAC after a reset.
3219 **/
3220static void e1000_configure_rx(struct e1000_adapter *adapter)
3221{
3222 struct e1000_hw *hw = &adapter->hw;
3223 struct e1000_ring *rx_ring = adapter->rx_ring;
3224 u64 rdba;
3225 u32 rdlen, rctl, rxcsum, ctrl_ext;
3226
3227 if (adapter->rx_ps_pages) {
3228 /* this is a 32 byte descriptor */
3229 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003230 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003231 adapter->clean_rx = e1000_clean_rx_irq_ps;
3232 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003233 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003234 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003235 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3236 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003237 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003238 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003239 adapter->clean_rx = e1000_clean_rx_irq;
3240 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3241 }
3242
3243 /* disable receives while setting up the descriptors */
3244 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003245 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3246 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003247 e1e_flush();
Arjan van de Venab6973a2019-06-14 17:29:35 -07003248 usleep_range(10000, 11000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003249
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003250 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003251 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003252 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003253 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003254 * granularity = 01
3255 * wthresh = 04,
3256 * hthresh = 04,
3257 * pthresh = 0x20
3258 */
3259 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3260 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003261 }
3262
Auke Kokbc7f75f2007-09-17 12:30:59 -07003263 /* set the Receive Delay Timer Register */
3264 ew32(RDTR, adapter->rx_int_delay);
3265
3266 /* irq moderation */
3267 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003268 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003269 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003270
3271 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003272 /* Auto-Mask interrupts upon ICR access */
3273 ctrl_ext |= E1000_CTRL_EXT_IAME;
3274 ew32(IAM, 0xffffffff);
3275 ew32(CTRL_EXT, ctrl_ext);
3276 e1e_flush();
3277
Bruce Allane921eb12012-11-28 09:28:37 +00003278 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003279 * the Base and Length of the Rx Descriptor Ring
3280 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003281 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003282 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3283 ew32(RDBAH(0), (rdba >> 32));
3284 ew32(RDLEN(0), rdlen);
3285 ew32(RDH(0), 0);
3286 ew32(RDT(0), 0);
3287 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3288 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003289
Jia-Ju Bai0845d452015-08-05 18:16:10 +08003290 writel(0, rx_ring->head);
3291 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
3292 e1000e_update_rdt_wa(rx_ring, 0);
3293 else
3294 writel(0, rx_ring->tail);
3295
Auke Kokbc7f75f2007-09-17 12:30:59 -07003296 /* Enable Receive Checksum Offload for TCP and UDP */
3297 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003298 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003299 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003300 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003301 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003302 ew32(RXCSUM, rxcsum);
3303
Bruce Allan3e35d992013-01-12 07:25:22 +00003304 /* With jumbo frames, excessive C-state transition latencies result
3305 * in dropped transactions.
3306 */
3307 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3308 u32 lat =
3309 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3310 adapter->max_frame_size) * 8 / 1000;
3311
3312 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003313 u32 rxdctl = er32(RXDCTL(0));
David Ertman6cf08d12014-04-05 06:07:00 +00003314
Matt Turnerb701cac2017-11-07 14:13:30 -08003315 ew32(RXDCTL(0), rxdctl | 0x3 | BIT(8));
Bruce Allan53ec5492009-11-20 23:27:40 +00003316 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003317
Matt Turner8299b002017-11-14 15:51:33 -08003318 dev_info(&adapter->pdev->dev,
3319 "Some CPU C-states have been disabled in order to enable jumbo frames\n");
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01003320 cpu_latency_qos_update_request(&adapter->pm_qos_req, lat);
Bruce Allan3e35d992013-01-12 07:25:22 +00003321 } else {
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01003322 cpu_latency_qos_update_request(&adapter->pm_qos_req,
3323 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003324 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325
3326 /* Enable Receives */
3327 ew32(RCTL, rctl);
3328}
3329
3330/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003331 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003332 * @netdev: network interface device structure
3333 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003334 * Writes multicast address list to the MTA hash table.
3335 * Returns: -ENOMEM on failure
3336 * 0 on no addresses written
3337 * X on writing X addresses to MTA
3338 */
3339static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003340{
3341 struct e1000_adapter *adapter = netdev_priv(netdev);
3342 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003343 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003344 u8 *mta_list;
3345 int i;
3346
3347 if (netdev_mc_empty(netdev)) {
3348 /* nothing to program, so clear mc list */
3349 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3350 return 0;
3351 }
3352
Kees Cook6396bb22018-06-12 14:03:40 -07003353 mta_list = kcalloc(netdev_mc_count(netdev), ETH_ALEN, GFP_ATOMIC);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003354 if (!mta_list)
3355 return -ENOMEM;
3356
3357 /* update_mc_addr_list expects a packed array of only addresses. */
3358 i = 0;
3359 netdev_for_each_mc_addr(ha, netdev)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003360 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003361
3362 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3363 kfree(mta_list);
3364
3365 return netdev_mc_count(netdev);
3366}
3367
3368/**
3369 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3370 * @netdev: network interface device structure
3371 *
3372 * Writes unicast address list to the RAR table.
3373 * Returns: -ENOMEM on failure/insufficient address space
3374 * 0 on no addresses written
3375 * X on writing X addresses to the RAR table
3376 **/
3377static int e1000e_write_uc_addr_list(struct net_device *netdev)
3378{
3379 struct e1000_adapter *adapter = netdev_priv(netdev);
3380 struct e1000_hw *hw = &adapter->hw;
David Ertmanb3e5bf12014-05-06 03:50:17 +00003381 unsigned int rar_entries;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003382 int count = 0;
3383
David Ertmanb3e5bf12014-05-06 03:50:17 +00003384 rar_entries = hw->mac.ops.rar_get_count(hw);
3385
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003386 /* save a rar entry for our hardware address */
3387 rar_entries--;
3388
3389 /* save a rar entry for the LAA workaround */
3390 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3391 rar_entries--;
3392
3393 /* return ENOMEM indicating insufficient memory for addresses */
3394 if (netdev_uc_count(netdev) > rar_entries)
3395 return -ENOMEM;
3396
3397 if (!netdev_uc_empty(netdev) && rar_entries) {
3398 struct netdev_hw_addr *ha;
3399
Bruce Allane921eb12012-11-28 09:28:37 +00003400 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003401 * combining
3402 */
3403 netdev_for_each_uc_addr(ha, netdev) {
Brian Walsh847042a2016-04-12 23:22:30 -04003404 int ret_val;
David Ertmanb3e5bf12014-05-06 03:50:17 +00003405
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003406 if (!rar_entries)
3407 break;
Brian Walsh847042a2016-04-12 23:22:30 -04003408 ret_val = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
3409 if (ret_val < 0)
David Ertmanb3e5bf12014-05-06 03:50:17 +00003410 return -ENOMEM;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003411 count++;
3412 }
3413 }
3414
3415 /* zero out the remaining RAR entries not used above */
3416 for (; rar_entries > 0; rar_entries--) {
3417 ew32(RAH(rar_entries), 0);
3418 ew32(RAL(rar_entries), 0);
3419 }
3420 e1e_flush();
3421
3422 return count;
3423}
3424
3425/**
3426 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3427 * @netdev: network interface device structure
3428 *
3429 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3430 * address list or the network interface flags are updated. This routine is
3431 * responsible for configuring the hardware for proper unicast, multicast,
3432 * promiscuous mode, and all-multi behavior.
3433 **/
3434static void e1000e_set_rx_mode(struct net_device *netdev)
3435{
3436 struct e1000_adapter *adapter = netdev_priv(netdev);
3437 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003438 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003439
David Ertman63eb48f2014-02-14 07:16:46 +00003440 if (pm_runtime_suspended(netdev->dev.parent))
3441 return;
3442
Auke Kokbc7f75f2007-09-17 12:30:59 -07003443 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003444 rctl = er32(RCTL);
3445
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003446 /* clear the affected bits */
3447 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3448
Auke Kokbc7f75f2007-09-17 12:30:59 -07003449 if (netdev->flags & IFF_PROMISC) {
3450 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003451 /* Do not hardware filter VLANs in promisc mode */
3452 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003453 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003454 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003455
Patrick McHardy746b9f02008-07-16 20:15:45 -07003456 if (netdev->flags & IFF_ALLMULTI) {
3457 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003458 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003459 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003460 * then we should just turn on promiscuous mode so
3461 * that we can at least receive multicast traffic
3462 */
3463 count = e1000e_write_mc_addr_list(netdev);
3464 if (count < 0)
3465 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003466 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003467 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003468 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003469 * sufficient space to store all the addresses then enable
3470 * unicast promiscuous mode
3471 */
3472 count = e1000e_write_uc_addr_list(netdev);
3473 if (count < 0)
3474 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003475 }
3476
3477 ew32(RCTL, rctl);
3478
Jarod Wilson83808642016-06-09 19:50:13 -04003479 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003480 e1000e_vlan_strip_enable(adapter);
3481 else
3482 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003483}
3484
Bruce Allan70495a52012-01-11 01:26:50 +00003485static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3486{
3487 struct e1000_hw *hw = &adapter->hw;
3488 u32 mrqc, rxcsum;
Eric Dumazet5c8d19d2014-11-16 06:23:11 -08003489 u32 rss_key[10];
Bruce Allan70495a52012-01-11 01:26:50 +00003490 int i;
Bruce Allan70495a52012-01-11 01:26:50 +00003491
Eric Dumazet5c8d19d2014-11-16 06:23:11 -08003492 netdev_rss_key_fill(rss_key, sizeof(rss_key));
Bruce Allan70495a52012-01-11 01:26:50 +00003493 for (i = 0; i < 10; i++)
Eric Dumazet5c8d19d2014-11-16 06:23:11 -08003494 ew32(RSSRK(i), rss_key[i]);
Bruce Allan70495a52012-01-11 01:26:50 +00003495
3496 /* Direct all traffic to queue 0 */
3497 for (i = 0; i < 32; i++)
3498 ew32(RETA(i), 0);
3499
Bruce Allane921eb12012-11-28 09:28:37 +00003500 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003501 * descriptor on writeback.
3502 */
3503 rxcsum = er32(RXCSUM);
3504 rxcsum |= E1000_RXCSUM_PCSD;
3505
3506 ew32(RXCSUM, rxcsum);
3507
3508 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3509 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3510 E1000_MRQC_RSS_FIELD_IPV6 |
3511 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3512 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3513
3514 ew32(MRQC, mrqc);
3515}
3516
Auke Kokbc7f75f2007-09-17 12:30:59 -07003517/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003518 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3519 * @adapter: board private structure
3520 * @timinca: pointer to returned time increment attributes
3521 *
3522 * Get attributes for incrementing the System Time Register SYSTIML/H at
3523 * the default base frequency, and set the cyclecounter shift value.
3524 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003525s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003526{
3527 struct e1000_hw *hw = &adapter->hw;
3528 u32 incvalue, incperiod, shift;
3529
David Ertman79849eb2015-02-10 09:10:43 +00003530 /* Make sure clock is enabled on I217/I218/I219 before checking
3531 * the frequency
3532 */
Sasha Neftinc8744f42017-04-06 10:26:47 +03003533 if ((hw->mac.type >= e1000_pch_lpt) &&
Bruce Allanb67e1912012-12-27 08:32:33 +00003534 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3535 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3536 u32 fextnvm7 = er32(FEXTNVM7);
3537
Jacob Keller18dd2392016-04-13 16:08:32 -07003538 if (!(fextnvm7 & BIT(0))) {
3539 ew32(FEXTNVM7, fextnvm7 | BIT(0));
Bruce Allanb67e1912012-12-27 08:32:33 +00003540 e1e_flush();
3541 }
3542 }
3543
3544 switch (hw->mac.type) {
3545 case e1000_pch2lan:
Bernd Faust5313eec2017-02-16 19:42:07 +01003546 /* Stable 96MHz frequency */
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003547 incperiod = INCPERIOD_96MHZ;
3548 incvalue = INCVALUE_96MHZ;
3549 shift = INCVALUE_SHIFT_96MHZ;
3550 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
Bernd Faust5313eec2017-02-16 19:42:07 +01003551 break;
Bruce Allanb67e1912012-12-27 08:32:33 +00003552 case e1000_pch_lpt:
Yanir Lubetkin83129b32015-06-02 17:05:45 +03003553 if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
Bruce Allanb67e1912012-12-27 08:32:33 +00003554 /* Stable 96MHz frequency */
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003555 incperiod = INCPERIOD_96MHZ;
3556 incvalue = INCVALUE_96MHZ;
3557 shift = INCVALUE_SHIFT_96MHZ;
3558 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
Yanir Lubetkin83129b32015-06-02 17:05:45 +03003559 } else {
3560 /* Stable 25MHz frequency */
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003561 incperiod = INCPERIOD_25MHZ;
3562 incvalue = INCVALUE_25MHZ;
3563 shift = INCVALUE_SHIFT_25MHZ;
Yanir Lubetkin83129b32015-06-02 17:05:45 +03003564 adapter->cc.shift = shift;
3565 }
3566 break;
3567 case e1000_pch_spt:
Benjamin Poirierfff200c2018-05-10 16:28:35 +09003568 /* Stable 24MHz frequency */
3569 incperiod = INCPERIOD_24MHZ;
3570 incvalue = INCVALUE_24MHZ;
3571 shift = INCVALUE_SHIFT_24MHZ;
3572 adapter->cc.shift = shift;
3573 break;
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003574 case e1000_pch_cnp:
Sasha Neftinfb776f52019-10-16 11:08:38 +03003575 case e1000_pch_tgp:
Sasha Neftin59e46682020-01-19 13:57:13 +02003576 case e1000_pch_adp:
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003577 if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
3578 /* Stable 24MHz frequency */
3579 incperiod = INCPERIOD_24MHZ;
3580 incvalue = INCVALUE_24MHZ;
3581 shift = INCVALUE_SHIFT_24MHZ;
3582 adapter->cc.shift = shift;
3583 } else {
3584 /* Stable 38400KHz frequency */
3585 incperiod = INCPERIOD_38400KHZ;
3586 incvalue = INCVALUE_38400KHZ;
3587 shift = INCVALUE_SHIFT_38400KHZ;
3588 adapter->cc.shift = shift;
3589 }
3590 break;
Bruce Allanb67e1912012-12-27 08:32:33 +00003591 case e1000_82574:
3592 case e1000_82583:
3593 /* Stable 25MHz frequency */
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003594 incperiod = INCPERIOD_25MHZ;
3595 incvalue = INCVALUE_25MHZ;
3596 shift = INCVALUE_SHIFT_25MHZ;
Bruce Allanb67e1912012-12-27 08:32:33 +00003597 adapter->cc.shift = shift;
3598 break;
3599 default:
3600 return -EINVAL;
3601 }
3602
3603 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3604 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3605
3606 return 0;
3607}
3608
3609/**
3610 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3611 * @adapter: board private structure
3612 *
3613 * Outgoing time stamping can be enabled and disabled. Play nice and
3614 * disable it when requested, although it shouldn't cause any overhead
3615 * when no packet needs it. At most one packet in the queue may be
3616 * marked for time stamping, otherwise it would be impossible to tell
3617 * for sure to which packet the hardware time stamp belongs.
3618 *
3619 * Incoming time stamping has to be configured via the hardware filters.
3620 * Not all combinations are supported, in particular event type has to be
3621 * specified. Matching the kind of event packet is not supported, with the
3622 * exception of "all V2 events regardless of level 2 or 4".
3623 **/
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003624static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
3625 struct hwtstamp_config *config)
Bruce Allanb67e1912012-12-27 08:32:33 +00003626{
3627 struct e1000_hw *hw = &adapter->hw;
Bruce Allanb67e1912012-12-27 08:32:33 +00003628 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3629 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003630 u32 rxmtrl = 0;
3631 u16 rxudp = 0;
3632 bool is_l4 = false;
3633 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003634 u32 regval;
Bruce Allanb67e1912012-12-27 08:32:33 +00003635
3636 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3637 return -EINVAL;
3638
3639 /* flags reserved for future extensions - must be zero */
3640 if (config->flags)
3641 return -EINVAL;
3642
3643 switch (config->tx_type) {
3644 case HWTSTAMP_TX_OFF:
3645 tsync_tx_ctl = 0;
3646 break;
3647 case HWTSTAMP_TX_ON:
3648 break;
3649 default:
3650 return -ERANGE;
3651 }
3652
3653 switch (config->rx_filter) {
3654 case HWTSTAMP_FILTER_NONE:
3655 tsync_rx_ctl = 0;
3656 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003657 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3658 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3659 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3660 is_l4 = true;
3661 break;
3662 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3663 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3664 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3665 is_l4 = true;
3666 break;
3667 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3668 /* Also time stamps V2 L2 Path Delay Request/Response */
3669 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3670 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3671 is_l2 = true;
3672 break;
3673 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3674 /* Also time stamps V2 L2 Path Delay Request/Response. */
3675 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3676 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3677 is_l2 = true;
3678 break;
3679 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3680 /* Hardware cannot filter just V2 L4 Sync messages;
3681 * fall-through to V2 (both L2 and L4) Sync.
3682 */
3683 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3684 /* Also time stamps V2 Path Delay Request/Response. */
3685 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3686 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3687 is_l2 = true;
3688 is_l4 = true;
3689 break;
3690 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3691 /* Hardware cannot filter just V2 L4 Delay Request messages;
3692 * fall-through to V2 (both L2 and L4) Delay Request.
3693 */
3694 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3695 /* Also time stamps V2 Path Delay Request/Response. */
3696 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3697 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3698 is_l2 = true;
3699 is_l4 = true;
3700 break;
3701 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3702 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3703 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3704 * fall-through to all V2 (both L2 and L4) Events.
3705 */
3706 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3707 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3708 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3709 is_l2 = true;
3710 is_l4 = true;
3711 break;
3712 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3713 /* For V1, the hardware can only filter Sync messages or
3714 * Delay Request messages but not both so fall-through to
3715 * time stamp all packets.
3716 */
Miroslav Lichvare3412572017-05-19 17:52:36 +02003717 case HWTSTAMP_FILTER_NTP_ALL:
Bruce Allanb67e1912012-12-27 08:32:33 +00003718 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003719 is_l2 = true;
3720 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003721 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3722 config->rx_filter = HWTSTAMP_FILTER_ALL;
3723 break;
3724 default:
3725 return -ERANGE;
3726 }
3727
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003728 adapter->hwtstamp_config = *config;
3729
Bruce Allanb67e1912012-12-27 08:32:33 +00003730 /* enable/disable Tx h/w time stamping */
3731 regval = er32(TSYNCTXCTL);
3732 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3733 regval |= tsync_tx_ctl;
3734 ew32(TSYNCTXCTL, regval);
3735 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3736 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3737 e_err("Timesync Tx Control register not set as expected\n");
3738 return -EAGAIN;
3739 }
3740
3741 /* enable/disable Rx h/w time stamping */
3742 regval = er32(TSYNCRXCTL);
3743 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3744 regval |= tsync_rx_ctl;
3745 ew32(TSYNCRXCTL, regval);
3746 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3747 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3748 (regval & (E1000_TSYNCRXCTL_ENABLED |
3749 E1000_TSYNCRXCTL_TYPE_MASK))) {
3750 e_err("Timesync Rx Control register not set as expected\n");
3751 return -EAGAIN;
3752 }
3753
Bruce Alland89777b2013-01-19 01:09:58 +00003754 /* L2: define ethertype filter for time stamped packets */
3755 if (is_l2)
3756 rxmtrl |= ETH_P_1588;
3757
3758 /* define which PTP packets get time stamped */
3759 ew32(RXMTRL, rxmtrl);
3760
3761 /* Filter by destination port */
3762 if (is_l4) {
3763 rxudp = PTP_EV_PORT;
3764 cpu_to_be16s(&rxudp);
3765 }
3766 ew32(RXUDP, rxudp);
3767
3768 e1e_flush();
3769
Bruce Allanb67e1912012-12-27 08:32:33 +00003770 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003771 er32(RXSTMPH);
3772 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003773
Bruce Allanb67e1912012-12-27 08:32:33 +00003774 return 0;
3775}
3776
3777/**
Bruce Allanad680762008-03-28 09:15:03 -07003778 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003779 * @adapter: private board structure
3780 **/
3781static void e1000_configure(struct e1000_adapter *adapter)
3782{
Bruce Allan55aa6982011-12-16 00:45:45 +00003783 struct e1000_ring *rx_ring = adapter->rx_ring;
3784
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003785 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003786
3787 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003788 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003789
3790 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003791
3792 if (adapter->netdev->features & NETIF_F_RXHASH)
3793 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003794 e1000_setup_rctl(adapter);
3795 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003796 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003797}
3798
3799/**
3800 * e1000e_power_up_phy - restore link in case the phy was powered down
3801 * @adapter: address of board private structure
3802 *
3803 * The phy may be powered down to save power and turn off link when the
3804 * driver is unloaded and wake on lan is not enabled (among others)
3805 * *** this routine MUST be followed by a call to e1000e_reset ***
3806 **/
3807void e1000e_power_up_phy(struct e1000_adapter *adapter)
3808{
Bruce Allan17f208d2009-12-01 15:47:22 +00003809 if (adapter->hw.phy.ops.power_up)
3810 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003811
3812 adapter->hw.mac.ops.setup_link(&adapter->hw);
3813}
3814
3815/**
3816 * e1000_power_down_phy - Power down the PHY
3817 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003818 * Power down the PHY so no link is implied when interface is down.
3819 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003820 */
3821static void e1000_power_down_phy(struct e1000_adapter *adapter)
3822{
Bruce Allan17f208d2009-12-01 15:47:22 +00003823 if (adapter->hw.phy.ops.power_down)
3824 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003825}
3826
3827/**
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003828 * e1000_flush_tx_ring - remove all descriptors from the tx_ring
3829 *
3830 * We want to clear all pending descriptors from the TX ring.
3831 * zeroing happens when the HW reads the regs. We assign the ring itself as
3832 * the data of the next descriptor. We don't care about the data we are about
3833 * to reset the HW.
3834 */
3835static void e1000_flush_tx_ring(struct e1000_adapter *adapter)
3836{
3837 struct e1000_hw *hw = &adapter->hw;
3838 struct e1000_ring *tx_ring = adapter->tx_ring;
3839 struct e1000_tx_desc *tx_desc = NULL;
3840 u32 tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS;
3841 u16 size = 512;
3842
3843 tctl = er32(TCTL);
3844 ew32(TCTL, tctl | E1000_TCTL_EN);
3845 tdt = er32(TDT(0));
3846 BUG_ON(tdt != tx_ring->next_to_use);
3847 tx_desc = E1000_TX_DESC(*tx_ring, tx_ring->next_to_use);
Ben Dooks (Codethink)99fe61b2019-12-18 09:53:08 +00003848 tx_desc->buffer_addr = cpu_to_le64(tx_ring->dma);
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003849
3850 tx_desc->lower.data = cpu_to_le32(txd_lower | size);
3851 tx_desc->upper.data = 0;
3852 /* flush descriptors to memory before notifying the HW */
3853 wmb();
3854 tx_ring->next_to_use++;
3855 if (tx_ring->next_to_use == tx_ring->count)
3856 tx_ring->next_to_use = 0;
3857 ew32(TDT(0), tx_ring->next_to_use);
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003858 usleep_range(200, 250);
3859}
3860
3861/**
3862 * e1000_flush_rx_ring - remove all descriptors from the rx_ring
3863 *
3864 * Mark all descriptors in the RX ring as consumed and disable the rx ring
3865 */
3866static void e1000_flush_rx_ring(struct e1000_adapter *adapter)
3867{
3868 u32 rctl, rxdctl;
3869 struct e1000_hw *hw = &adapter->hw;
3870
3871 rctl = er32(RCTL);
3872 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3873 e1e_flush();
3874 usleep_range(100, 150);
3875
3876 rxdctl = er32(RXDCTL(0));
3877 /* zero the lower 14 bits (prefetch and host thresholds) */
3878 rxdctl &= 0xffffc000;
3879
3880 /* update thresholds: prefetch threshold to 31, host threshold to 1
3881 * and make sure the granularity is "descriptors" and not "cache lines"
3882 */
Jacob Keller18dd2392016-04-13 16:08:32 -07003883 rxdctl |= (0x1F | BIT(8) | E1000_RXDCTL_THRESH_UNIT_DESC);
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003884
3885 ew32(RXDCTL(0), rxdctl);
3886 /* momentarily enable the RX ring for the changes to take effect */
3887 ew32(RCTL, rctl | E1000_RCTL_EN);
3888 e1e_flush();
3889 usleep_range(100, 150);
3890 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3891}
3892
3893/**
3894 * e1000_flush_desc_rings - remove all descriptors from the descriptor rings
3895 *
3896 * In i219, the descriptor rings must be emptied before resetting the HW
3897 * or before changing the device state to D3 during runtime (runtime PM).
3898 *
3899 * Failure to do this will cause the HW to enter a unit hang state which can
3900 * only be released by PCI reset on the device
3901 *
3902 */
3903
3904static void e1000_flush_desc_rings(struct e1000_adapter *adapter)
3905{
Yanir Lubetkinff9174292015-06-02 17:05:38 +03003906 u16 hang_state;
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003907 u32 fext_nvm11, tdlen;
3908 struct e1000_hw *hw = &adapter->hw;
3909
3910 /* First, disable MULR fix in FEXTNVM11 */
3911 fext_nvm11 = er32(FEXTNVM11);
3912 fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
3913 ew32(FEXTNVM11, fext_nvm11);
3914 /* do nothing if we're not in faulty state, or if the queue is empty */
3915 tdlen = er32(TDLEN(0));
Yanir Lubetkinff9174292015-06-02 17:05:38 +03003916 pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
3917 &hang_state);
3918 if (!(hang_state & FLUSH_DESC_REQUIRED) || !tdlen)
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003919 return;
3920 e1000_flush_tx_ring(adapter);
3921 /* recheck, maybe the fault is caused by the rx ring */
Yanir Lubetkinff9174292015-06-02 17:05:38 +03003922 pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
3923 &hang_state);
3924 if (hang_state & FLUSH_DESC_REQUIRED)
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003925 e1000_flush_rx_ring(adapter);
3926}
3927
3928/**
Jacob Kelleraa524b62016-04-20 11:36:42 -07003929 * e1000e_systim_reset - reset the timesync registers after a hardware reset
3930 * @adapter: board private structure
3931 *
3932 * When the MAC is reset, all hardware bits for timesync will be reset to the
3933 * default values. This function will restore the settings last in place.
3934 * Since the clock SYSTIME registers are reset, we will simply restore the
3935 * cyclecounter to the kernel real clock time.
3936 **/
3937static void e1000e_systim_reset(struct e1000_adapter *adapter)
3938{
3939 struct ptp_clock_info *info = &adapter->ptp_clock_info;
3940 struct e1000_hw *hw = &adapter->hw;
3941 unsigned long flags;
3942 u32 timinca;
3943 s32 ret_val;
3944
3945 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3946 return;
3947
3948 if (info->adjfreq) {
3949 /* restore the previous ptp frequency delta */
3950 ret_val = info->adjfreq(info, adapter->ptp_delta);
3951 } else {
3952 /* set the default base frequency if no adjustment possible */
3953 ret_val = e1000e_get_base_timinca(adapter, &timinca);
3954 if (!ret_val)
3955 ew32(TIMINCA, timinca);
3956 }
3957
3958 if (ret_val) {
3959 dev_warn(&adapter->pdev->dev,
3960 "Failed to restore TIMINCA clock rate delta: %d\n",
3961 ret_val);
3962 return;
3963 }
3964
3965 /* reset the systim ns time counter */
3966 spin_lock_irqsave(&adapter->systim_lock, flags);
3967 timecounter_init(&adapter->tc, &adapter->cc,
3968 ktime_to_ns(ktime_get_real()));
3969 spin_unlock_irqrestore(&adapter->systim_lock, flags);
3970
3971 /* restore the previous hwtstamp configuration settings */
3972 e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
3973}
3974
3975/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003976 * e1000e_reset - bring the hardware into a known good state
3977 *
3978 * This function boots the hardware and enables some settings that
3979 * require a configuration cycle of the hardware - those cannot be
3980 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003981 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003982 */
3983void e1000e_reset(struct e1000_adapter *adapter)
3984{
3985 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003986 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003987 struct e1000_hw *hw = &adapter->hw;
3988 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003989 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003990 u16 hwm;
3991
Bruce Allanad680762008-03-28 09:15:03 -07003992 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003993 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003994
Alexander Duyck8084b862015-05-02 00:52:00 -07003995 if (adapter->max_frame_size > (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003996 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003997 * large enough to accommodate two full transmit packets,
3998 * rounded up to the next 1KB and expressed in KB. Likewise,
3999 * the Rx FIFO should be large enough to accommodate at least
4000 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07004001 * expressed in KB.
4002 */
Auke Kokdf762462007-10-25 13:57:53 -07004003 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004004 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07004005 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004006 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07004007 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00004008 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07004009 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004010 */
4011 min_tx_space = (adapter->max_frame_size +
Bruce Allane5fe2542013-02-20 04:06:27 +00004012 sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004013 min_tx_space = ALIGN(min_tx_space, 1024);
4014 min_tx_space >>= 10;
4015 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004016 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004017 min_rx_space = ALIGN(min_rx_space, 1024);
4018 min_rx_space >>= 10;
4019
Bruce Allane921eb12012-11-28 09:28:37 +00004020 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004021 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07004022 * allocation, take space away from current Rx allocation
4023 */
Auke Kokdf762462007-10-25 13:57:53 -07004024 if ((tx_space < min_tx_space) &&
4025 ((min_tx_space - tx_space) < pba)) {
4026 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004027
Bruce Allane921eb12012-11-28 09:28:37 +00004028 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00004029 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07004030 */
Bruce Allan79d4e902011-12-16 00:46:27 +00004031 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07004032 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004033 }
Auke Kokdf762462007-10-25 13:57:53 -07004034
4035 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004036 }
4037
Bruce Allane921eb12012-11-28 09:28:37 +00004038 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07004039 *
Bruce Allan38eb3942009-11-19 12:34:20 +00004040 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07004041 * (or the size used for early receive) above it in the Rx FIFO.
4042 * Set it to the lower of:
4043 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00004044 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07004045 */
Bruce Alland3738bb2010-06-16 13:27:28 +00004046 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
4047 fc->pause_time = 0xFFFF;
4048 else
4049 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00004050 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00004051 fc->current_mode = fc->requested_mode;
4052
4053 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00004054 case e1000_ich9lan:
4055 case e1000_ich10lan:
4056 if (adapter->netdev->mtu > ETH_DATA_LEN) {
4057 pba = 14;
4058 ew32(PBA, pba);
4059 fc->high_water = 0x2800;
4060 fc->low_water = fc->high_water - 8;
4061 break;
4062 }
4063 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00004064 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00004065 hwm = min(((pba << 10) * 9 / 10),
4066 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00004067
Bruce Allane80bd1d2013-05-01 01:19:46 +00004068 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
Bruce Alland3738bb2010-06-16 13:27:28 +00004069 fc->low_water = fc->high_water - 8;
4070 break;
4071 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00004072 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00004073 * loads. If hangs persist, try disabling Tx flow control.
4074 */
4075 if (adapter->netdev->mtu > ETH_DATA_LEN) {
4076 fc->high_water = 0x3500;
Bruce Allane80bd1d2013-05-01 01:19:46 +00004077 fc->low_water = 0x1500;
Bruce Allan38eb3942009-11-19 12:34:20 +00004078 } else {
4079 fc->high_water = 0x5000;
Bruce Allane80bd1d2013-05-01 01:19:46 +00004080 fc->low_water = 0x3000;
Bruce Allan38eb3942009-11-19 12:34:20 +00004081 }
Bruce Allana3055952010-05-10 15:02:12 +00004082 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00004083 break;
4084 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00004085 case e1000_pch_lpt:
David Ertman79849eb2015-02-10 09:10:43 +00004086 case e1000_pch_spt:
Sasha Neftinc8744f42017-04-06 10:26:47 +03004087 case e1000_pch_cnp:
Sasha Neftinfb776f52019-10-16 11:08:38 +03004088 /* fall-through */
4089 case e1000_pch_tgp:
Sasha Neftin59e46682020-01-19 13:57:13 +02004090 case e1000_pch_adp:
Miguel Bernal Marinf74dc882017-03-27 16:01:56 -06004091 fc->refresh_time = 0xFFFF;
4092 fc->pause_time = 0xFFFF;
Bruce Allan347b5202012-12-08 00:35:35 +00004093
4094 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
4095 fc->high_water = 0x05C20;
4096 fc->low_water = 0x05048;
Bruce Allan347b5202012-12-08 00:35:35 +00004097 break;
Bruce Allan828bac82010-09-29 21:39:37 +00004098 }
Bruce Allan347b5202012-12-08 00:35:35 +00004099
Bruce Allance345e02013-06-21 09:07:07 +00004100 pba = 14;
4101 ew32(PBA, pba);
Bruce Allan347b5202012-12-08 00:35:35 +00004102 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
4103 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00004104 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00004105 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004106
Bruce Allane921eb12012-11-28 09:28:37 +00004107 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00004108 * maximum size per Tx descriptor limited only to the transmit
4109 * allocation of the packet buffer minus 96 bytes with an upper
4110 * limit of 24KB due to receive synchronization limitations.
4111 */
4112 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
4113 24 << 10);
4114
Bruce Allane921eb12012-11-28 09:28:37 +00004115 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00004116 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00004117 */
4118 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00004119 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00004120 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
4121 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00004122 "Interrupt Throttle Rate off\n");
Bruce Allan828bac82010-09-29 21:39:37 +00004123 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00004124 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00004125 }
4126 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
4127 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00004128 "Interrupt Throttle Rate on\n");
Bruce Allan828bac82010-09-29 21:39:37 +00004129 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
4130 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00004131 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00004132 }
4133 }
4134
Sasha Neftinc8744f42017-04-06 10:26:47 +03004135 if (hw->mac.type >= e1000_pch_spt)
Yanir Lubetkin0ffc5642015-04-22 04:15:01 +03004136 e1000_flush_desc_rings(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004137 /* Allow time for pending master requests to run */
4138 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004139
Bruce Allane921eb12012-11-28 09:28:37 +00004140 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004141 * that the network interface is in control
4142 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004143 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004144 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004145
Auke Kokbc7f75f2007-09-17 12:30:59 -07004146 ew32(WUC, 0);
4147
4148 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004149 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004150
4151 e1000_update_mng_vlan(adapter);
4152
4153 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
4154 ew32(VET, ETH_P_8021Q);
4155
4156 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004157
Jacob Kelleraa524b62016-04-20 11:36:42 -07004158 /* restore systim and hwtstamp settings */
4159 e1000e_systim_reset(adapter);
Bruce Allanb67e1912012-12-27 08:32:33 +00004160
Bruce Alland495bcb2013-03-20 07:23:11 +00004161 /* Set EEE advertisement as appropriate */
4162 if (adapter->flags2 & FLAG2_HAS_EEE) {
4163 s32 ret_val;
4164 u16 adv_addr;
4165
4166 switch (hw->phy.type) {
4167 case e1000_phy_82579:
4168 adv_addr = I82579_EEE_ADVERTISEMENT;
4169 break;
4170 case e1000_phy_i217:
4171 adv_addr = I217_EEE_ADVERTISEMENT;
4172 break;
4173 default:
4174 dev_err(&adapter->pdev->dev,
4175 "Invalid PHY type setting EEE advertisement\n");
4176 return;
4177 }
4178
4179 ret_val = hw->phy.ops.acquire(hw);
4180 if (ret_val) {
4181 dev_err(&adapter->pdev->dev,
4182 "EEE advertisement - unable to acquire PHY\n");
4183 return;
4184 }
4185
4186 e1000_write_emi_reg_locked(hw, adv_addr,
4187 hw->dev_spec.ich8lan.eee_disable ?
4188 0 : adapter->eee_advert);
4189
4190 hw->phy.ops.release(hw);
4191 }
4192
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004193 if (!netif_running(adapter->netdev) &&
David Ertman28002092014-02-14 07:16:41 +00004194 !test_bit(__E1000_TESTING, &adapter->state))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004195 e1000_power_down_phy(adapter);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004196
Auke Kokbc7f75f2007-09-17 12:30:59 -07004197 e1000_get_phy_info(hw);
4198
Bruce Allan918d7192009-06-02 11:28:20 +00004199 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
4200 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004201 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00004202 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07004203 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07004204 * different we would do if it failed
4205 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004206 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
4207 phy_data &= ~IGP02E1000_PM_SPD;
4208 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
4209 }
Sasha Neftinc8744f42017-04-06 10:26:47 +03004210 if (hw->mac.type >= e1000_pch_spt && adapter->int_mode == 0) {
Yanir Lubetkinec945cf2015-06-02 17:05:42 +03004211 u32 reg;
4212
4213 /* Fextnvm7 @ 0xe4[2] = 1 */
4214 reg = er32(FEXTNVM7);
4215 reg |= E1000_FEXTNVM7_SIDE_CLK_UNGATE;
4216 ew32(FEXTNVM7, reg);
4217 /* Fextnvm9 @ 0x5bb4[13:12] = 11 */
4218 reg = er32(FEXTNVM9);
4219 reg |= E1000_FEXTNVM9_IOSFSB_CLKGATE_DIS |
4220 E1000_FEXTNVM9_IOSFSB_CLKREQ_DIS;
4221 ew32(FEXTNVM9, reg);
4222 }
4223
Auke Kokbc7f75f2007-09-17 12:30:59 -07004224}
4225
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004226/**
4227 * e1000e_trigger_lsc - trigger an LSC interrupt
4228 * @adapter:
4229 *
4230 * Fire a link status change interrupt to start the watchdog.
4231 **/
4232static void e1000e_trigger_lsc(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004233{
4234 struct e1000_hw *hw = &adapter->hw;
4235
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004236 if (adapter->msix_entries)
Benjamin Poirier4aea7a5c2017-07-21 11:36:27 -07004237 ew32(ICS, E1000_ICS_LSC | E1000_ICS_OTHER);
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004238 else
4239 ew32(ICS, E1000_ICS_LSC);
4240}
4241
4242void e1000e_up(struct e1000_adapter *adapter)
4243{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004244 /* hardware has been reset, we need to reload some things */
4245 e1000_configure(adapter);
4246
4247 clear_bit(__E1000_DOWN, &adapter->state);
4248
Bruce Allan4662e822008-08-26 18:37:06 -07004249 if (adapter->msix_entries)
4250 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004251 e1000_irq_enable(adapter);
4252
Konstantin Khlebnikovd17ba0f2019-04-17 11:13:20 +03004253 /* Tx queue started by watchdog timer when link is up */
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004254
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004255 e1000e_trigger_lsc(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004256}
4257
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004258static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
4259{
4260 struct e1000_hw *hw = &adapter->hw;
4261
4262 if (!(adapter->flags2 & FLAG2_DMA_BURST))
4263 return;
4264
4265 /* flush pending descriptor writebacks to memory */
4266 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4267 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4268
4269 /* execute the writes immediately */
4270 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00004271
Bruce Allane921eb12012-11-28 09:28:37 +00004272 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00004273 * write is successful
4274 */
4275 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4276 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4277
4278 /* execute the writes immediately */
4279 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004280}
4281
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004282static void e1000e_update_stats(struct e1000_adapter *adapter);
4283
David Ertman28002092014-02-14 07:16:41 +00004284/**
4285 * e1000e_down - quiesce the device and optionally reset the hardware
4286 * @adapter: board private structure
4287 * @reset: boolean flag to reset the hardware or not
4288 */
4289void e1000e_down(struct e1000_adapter *adapter, bool reset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004290{
4291 struct net_device *netdev = adapter->netdev;
4292 struct e1000_hw *hw = &adapter->hw;
4293 u32 tctl, rctl;
4294
Bruce Allane921eb12012-11-28 09:28:37 +00004295 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07004296 * reschedule our watchdog timer
4297 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004298 set_bit(__E1000_DOWN, &adapter->state);
4299
Eliezer Tamira60a1322015-03-20 17:41:52 -07004300 netif_carrier_off(netdev);
4301
Auke Kokbc7f75f2007-09-17 12:30:59 -07004302 /* disable receives in the hardware */
4303 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07004304 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
4305 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004306 /* flush and sleep below */
4307
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004308 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004309
4310 /* disable transmits in the hardware */
4311 tctl = er32(TCTL);
4312 tctl &= ~E1000_TCTL_EN;
4313 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004314
Auke Kokbc7f75f2007-09-17 12:30:59 -07004315 /* flush both disables and wait for them to finish */
4316 e1e_flush();
Arjan van de Venab6973a2019-06-14 17:29:35 -07004317 usleep_range(10000, 11000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004318
Auke Kokbc7f75f2007-09-17 12:30:59 -07004319 e1000_irq_disable(adapter);
4320
Bruce Allana3b87a42013-04-20 05:37:29 +00004321 napi_synchronize(&adapter->napi);
4322
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08004323 del_timer_sync(&adapter->watchdog_timer);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004324 del_timer_sync(&adapter->phy_info_timer);
4325
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004326 spin_lock(&adapter->stats64_lock);
4327 e1000e_update_stats(adapter);
4328 spin_unlock(&adapter->stats64_lock);
4329
Bruce Allan400484f2011-05-13 07:20:03 +00004330 e1000e_flush_descriptors(adapter);
Bruce Allan400484f2011-05-13 07:20:03 +00004331
Auke Kokbc7f75f2007-09-17 12:30:59 -07004332 adapter->link_speed = 0;
4333 adapter->link_duplex = 0;
4334
Bruce Allanda1e20462013-06-21 09:07:02 +00004335 /* Disable Si errata workaround on PCHx for jumbo frame flow */
4336 if ((hw->mac.type >= e1000_pch2lan) &&
4337 (adapter->netdev->mtu > ETH_DATA_LEN) &&
4338 e1000_lv_jumbo_workaround_ich8lan(hw, false))
4339 e_dbg("failed to disable jumbo frame workaround mode\n");
4340
Yanir Lubetkin0ffc5642015-04-22 04:15:01 +03004341 if (!pci_channel_offline(adapter->pdev)) {
4342 if (reset)
4343 e1000e_reset(adapter);
Sasha Neftinc8744f42017-04-06 10:26:47 +03004344 else if (hw->mac.type >= e1000_pch_spt)
Yanir Lubetkin0ffc5642015-04-22 04:15:01 +03004345 e1000_flush_desc_rings(adapter);
4346 }
4347 e1000_clean_tx_ring(adapter->tx_ring);
4348 e1000_clean_rx_ring(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004349}
4350
4351void e1000e_reinit_locked(struct e1000_adapter *adapter)
4352{
4353 might_sleep();
4354 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Arjan van de Venab6973a2019-06-14 17:29:35 -07004355 usleep_range(1000, 1100);
David Ertman28002092014-02-14 07:16:41 +00004356 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004357 e1000e_up(adapter);
4358 clear_bit(__E1000_RESETTING, &adapter->state);
4359}
4360
4361/**
Jarod Wilson0be5b962016-07-26 14:25:34 -04004362 * e1000e_sanitize_systim - sanitize raw cycle counter reads
4363 * @hw: pointer to the HW structure
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004364 * @systim: PHC time value read, sanitized and returned
4365 * @sts: structure to hold system time before and after reading SYSTIML,
4366 * may be NULL
Jarod Wilson0be5b962016-07-26 14:25:34 -04004367 *
4368 * Errata for 82574/82583 possible bad bits read from SYSTIMH/L:
4369 * check to see that the time is incrementing at a reasonable
4370 * rate and is a multiple of incvalue.
4371 **/
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004372static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim,
4373 struct ptp_system_timestamp *sts)
Jarod Wilson0be5b962016-07-26 14:25:34 -04004374{
4375 u64 time_delta, rem, temp;
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004376 u64 systim_next;
Jarod Wilson0be5b962016-07-26 14:25:34 -04004377 u32 incvalue;
4378 int i;
4379
4380 incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
4381 for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
4382 /* latch SYSTIMH on read of SYSTIML */
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004383 ptp_read_system_prets(sts);
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004384 systim_next = (u64)er32(SYSTIML);
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004385 ptp_read_system_postts(sts);
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004386 systim_next |= (u64)er32(SYSTIMH) << 32;
Jarod Wilson0be5b962016-07-26 14:25:34 -04004387
4388 time_delta = systim_next - systim;
4389 temp = time_delta;
4390 /* VMWare users have seen incvalue of zero, don't div / 0 */
4391 rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0);
4392
4393 systim = systim_next;
4394
4395 if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0))
4396 break;
4397 }
4398
4399 return systim;
4400}
4401
4402/**
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004403 * e1000e_read_systim - read SYSTIM register
4404 * @adapter: board private structure
4405 * @sts: structure which will contain system time before and after reading
4406 * SYSTIML, may be NULL
Bruce Allanb67e1912012-12-27 08:32:33 +00004407 **/
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004408u64 e1000e_read_systim(struct e1000_adapter *adapter,
4409 struct ptp_system_timestamp *sts)
Bruce Allanb67e1912012-12-27 08:32:33 +00004410{
Bruce Allanb67e1912012-12-27 08:32:33 +00004411 struct e1000_hw *hw = &adapter->hw;
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004412 u32 systimel, systimel_2, systimeh;
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004413 u64 systim;
Raanan Avargil37b129102015-07-19 16:33:20 +03004414 /* SYSTIMH latching upon SYSTIML read does not work well.
4415 * This means that if SYSTIML overflows after we read it but before
4416 * we read SYSTIMH, the value of SYSTIMH has been incremented and we
4417 * will experience a huge non linear increment in the systime value
4418 * to fix that we test for overflow and if true, we re-read systime.
Yanir Lubetkin83129b32015-06-02 17:05:45 +03004419 */
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004420 ptp_read_system_prets(sts);
Denys Vlasenkoab507c92016-04-20 17:45:56 +02004421 systimel = er32(SYSTIML);
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004422 ptp_read_system_postts(sts);
Raanan Avargil37b129102015-07-19 16:33:20 +03004423 systimeh = er32(SYSTIMH);
Denys Vlasenkoab507c92016-04-20 17:45:56 +02004424 /* Is systimel is so large that overflow is possible? */
4425 if (systimel >= (u32)0xffffffff - E1000_TIMINCA_INCVALUE_MASK) {
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004426 ptp_read_system_prets(sts);
4427 systimel_2 = er32(SYSTIML);
4428 ptp_read_system_postts(sts);
Denys Vlasenkoab507c92016-04-20 17:45:56 +02004429 if (systimel > systimel_2) {
4430 /* There was an overflow, read again SYSTIMH, and use
4431 * systimel_2
4432 */
4433 systimeh = er32(SYSTIMH);
4434 systimel = systimel_2;
4435 }
Raanan Avargil37b129102015-07-19 16:33:20 +03004436 }
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004437 systim = (u64)systimel;
4438 systim |= (u64)systimeh << 32;
Bruce Allanb67e1912012-12-27 08:32:33 +00004439
Jarod Wilson0be5b962016-07-26 14:25:34 -04004440 if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW)
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004441 systim = e1000e_sanitize_systim(hw, systim, sts);
Todd Fujinaka5e7ff972014-05-03 06:41:37 +00004442
Bruce Allanb67e1912012-12-27 08:32:33 +00004443 return systim;
4444}
4445
4446/**
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004447 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4448 * @cc: cyclecounter structure
4449 **/
4450static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc)
4451{
4452 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4453 cc);
4454
4455 return e1000e_read_systim(adapter, NULL);
4456}
4457
4458/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004459 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4460 * @adapter: board private structure to initialize
4461 *
4462 * e1000_sw_init initializes the Adapter private data structure.
4463 * Fields are initialized based on PCI device information and
4464 * OS network device settings (MTU size).
4465 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004466static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004467{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004468 struct net_device *netdev = adapter->netdev;
4469
Alexander Duyck8084b862015-05-02 00:52:00 -07004470 adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004471 adapter->rx_ps_bsize0 = 128;
Alexander Duyck8084b862015-05-02 00:52:00 -07004472 adapter->max_frame_size = netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004473 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004474 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4475 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004476
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004477 spin_lock_init(&adapter->stats64_lock);
4478
Bruce Allan4662e822008-08-26 18:37:06 -07004479 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004480
Bruce Allan4662e822008-08-26 18:37:06 -07004481 if (e1000_alloc_queues(adapter))
4482 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004483
Bruce Allanb67e1912012-12-27 08:32:33 +00004484 /* Setup hardware time stamping cyclecounter */
4485 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4486 adapter->cc.read = e1000e_cyclecounter_read;
Richard Cochran4d045b42015-01-02 20:22:05 +01004487 adapter->cc.mask = CYCLECOUNTER_MASK(64);
Bruce Allanb67e1912012-12-27 08:32:33 +00004488 adapter->cc.mult = 1;
4489 /* cc.shift set in e1000e_get_base_tininca() */
4490
4491 spin_lock_init(&adapter->systim_lock);
4492 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4493 }
4494
Auke Kokbc7f75f2007-09-17 12:30:59 -07004495 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004496 e1000_irq_disable(adapter);
4497
Auke Kokbc7f75f2007-09-17 12:30:59 -07004498 set_bit(__E1000_DOWN, &adapter->state);
4499 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004500}
4501
4502/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004503 * e1000_intr_msi_test - Interrupt Handler
4504 * @irq: interrupt number
4505 * @data: pointer to a network interface device structure
4506 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004507static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004508{
4509 struct net_device *netdev = data;
4510 struct e1000_adapter *adapter = netdev_priv(netdev);
4511 struct e1000_hw *hw = &adapter->hw;
4512 u32 icr = er32(ICR);
4513
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004514 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004515 if (icr & E1000_ICR_RXSEQ) {
4516 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004517 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004518 * interrupt is handled.
4519 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004520 wmb();
4521 }
4522
4523 return IRQ_HANDLED;
4524}
4525
4526/**
4527 * e1000_test_msi_interrupt - Returns 0 for successful test
4528 * @adapter: board private struct
4529 *
4530 * code flow taken from tg3.c
4531 **/
4532static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4533{
4534 struct net_device *netdev = adapter->netdev;
4535 struct e1000_hw *hw = &adapter->hw;
4536 int err;
4537
4538 /* poll_enable hasn't been called yet, so don't need disable */
4539 /* clear any pending events */
4540 er32(ICR);
4541
4542 /* free the real vector and request a test handler */
4543 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004544 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004545
4546 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004547 * MSI irq handler will unset this flag
4548 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004549 adapter->flags |= FLAG_MSI_TEST_FAILED;
4550
4551 err = pci_enable_msi(adapter->pdev);
4552 if (err)
4553 goto msi_test_failed;
4554
Joe Perchesa0607fd2009-11-18 23:29:17 -08004555 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004556 netdev->name, netdev);
4557 if (err) {
4558 pci_disable_msi(adapter->pdev);
4559 goto msi_test_failed;
4560 }
4561
Bruce Allane921eb12012-11-28 09:28:37 +00004562 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004563 * interrupt.
4564 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004565 wmb();
4566
4567 e1000_irq_enable(adapter);
4568
4569 /* fire an unusual interrupt on the test handler */
4570 ew32(ICS, E1000_ICS_RXSEQ);
4571 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004572 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004573
4574 e1000_irq_disable(adapter);
4575
Bruce Allanbc763292012-08-17 06:18:07 +00004576 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004577
4578 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004579 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004580 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004581 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004582 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004583 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004584
4585 free_irq(adapter->pdev->irq, netdev);
4586 pci_disable_msi(adapter->pdev);
4587
Bruce Allanf8d59f72008-08-08 18:36:11 -07004588msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004589 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004590 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004591}
4592
4593/**
4594 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4595 * @adapter: board private struct
4596 *
4597 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4598 **/
4599static int e1000_test_msi(struct e1000_adapter *adapter)
4600{
4601 int err;
4602 u16 pci_cmd;
4603
4604 if (!(adapter->flags & FLAG_MSI_ENABLED))
4605 return 0;
4606
4607 /* disable SERR in case the MSI write causes a master abort */
4608 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004609 if (pci_cmd & PCI_COMMAND_SERR)
4610 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4611 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004612
4613 err = e1000_test_msi_interrupt(adapter);
4614
Dean Nelson36f24072010-06-29 18:12:05 +00004615 /* re-enable SERR */
4616 if (pci_cmd & PCI_COMMAND_SERR) {
4617 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4618 pci_cmd |= PCI_COMMAND_SERR;
4619 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4620 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004621
Bruce Allanf8d59f72008-08-08 18:36:11 -07004622 return err;
4623}
4624
4625/**
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01004626 * e1000e_open - Called when a network interface is made active
Auke Kokbc7f75f2007-09-17 12:30:59 -07004627 * @netdev: network interface device structure
4628 *
4629 * Returns 0 on success, negative value on failure
4630 *
4631 * The open entry point is called when a network interface is made
4632 * active by the system (IFF_UP). At this point all resources needed
4633 * for transmit and receive operations are allocated, the interrupt
4634 * handler is registered with the OS, the watchdog timer is started,
4635 * and the stack is notified that the interface is ready.
4636 **/
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01004637int e1000e_open(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004638{
4639 struct e1000_adapter *adapter = netdev_priv(netdev);
4640 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004641 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004642 int err;
4643
4644 /* disallow open during test */
4645 if (test_bit(__E1000_TESTING, &adapter->state))
4646 return -EBUSY;
4647
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004648 pm_runtime_get_sync(&pdev->dev);
4649
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004650 netif_carrier_off(netdev);
Konstantin Khlebnikovd17ba0f2019-04-17 11:13:20 +03004651 netif_stop_queue(netdev);
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004652
Auke Kokbc7f75f2007-09-17 12:30:59 -07004653 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004654 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004655 if (err)
4656 goto err_setup_tx;
4657
4658 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004659 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004660 if (err)
4661 goto err_setup_rx;
4662
Bruce Allane921eb12012-11-28 09:28:37 +00004663 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004664 * interface is now open and reset the part to a known state.
4665 */
4666 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004667 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004668 e1000e_reset(adapter);
4669 }
4670
Auke Kokbc7f75f2007-09-17 12:30:59 -07004671 e1000e_power_up_phy(adapter);
4672
4673 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Bruce Allane5fe2542013-02-20 04:06:27 +00004674 if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004675 e1000_update_mng_vlan(adapter);
4676
Bruce Allan79d4e902011-12-16 00:46:27 +00004677 /* DMA latency requirement to workaround jumbo issue */
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01004678 cpu_latency_qos_add_request(&adapter->pm_qos_req, PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004679
Bruce Allane921eb12012-11-28 09:28:37 +00004680 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004681 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4682 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004683 * clean_rx handler before we do so.
4684 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004685 e1000_configure(adapter);
4686
4687 err = e1000_request_irq(adapter);
4688 if (err)
4689 goto err_req_irq;
4690
Bruce Allane921eb12012-11-28 09:28:37 +00004691 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004692 * ignore e1000e MSI messages, which means we need to test our MSI
4693 * interrupt now
4694 */
Bruce Allan4662e822008-08-26 18:37:06 -07004695 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004696 err = e1000_test_msi(adapter);
4697 if (err) {
4698 e_err("Interrupt allocation failed\n");
4699 goto err_req_irq;
4700 }
4701 }
4702
Auke Kokbc7f75f2007-09-17 12:30:59 -07004703 /* From here on the code is the same as e1000e_up() */
4704 clear_bit(__E1000_DOWN, &adapter->state);
4705
4706 napi_enable(&adapter->napi);
4707
4708 e1000_irq_enable(adapter);
4709
Jeff Kirsher09357b02011-11-18 14:25:00 +00004710 adapter->tx_hang_recheck = false;
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004711
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00004712 hw->mac.get_link_status = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004713 pm_runtime_put(&pdev->dev);
4714
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004715 e1000e_trigger_lsc(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004716
4717 return 0;
4718
4719err_req_irq:
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01004720 cpu_latency_qos_remove_request(&adapter->pm_qos_req);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004721 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004722 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004723 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004724err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004725 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004726err_setup_tx:
4727 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004728 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004729
4730 return err;
4731}
4732
4733/**
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01004734 * e1000e_close - Disables a network interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004735 * @netdev: network interface device structure
4736 *
4737 * Returns 0, this is not allowed to fail
4738 *
4739 * The close entry point is called when an interface is de-activated
4740 * by the OS. The hardware is still under the drivers control, but
4741 * needs to be disabled. A global MAC reset is issued to stop the
4742 * hardware, and all transmit and receive resources are freed.
4743 **/
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01004744int e1000e_close(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004745{
4746 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004747 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004748 int count = E1000_CHECK_RESET_COUNT;
4749
4750 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
Arjan van de Venab6973a2019-06-14 17:29:35 -07004751 usleep_range(10000, 11000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004752
4753 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004754
4755 pm_runtime_get_sync(&pdev->dev);
4756
Alexander Duycka7023812019-10-11 08:34:52 -07004757 if (netif_device_present(netdev)) {
David Ertman28002092014-02-14 07:16:41 +00004758 e1000e_down(adapter, true);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004759 e1000_free_irq(adapter);
David Ertman63eb48f2014-02-14 07:16:46 +00004760
4761 /* Link status message must follow this format */
Alexander Duyckc557a4b2019-10-31 09:58:51 -07004762 netdev_info(netdev, "NIC Link is Down\n");
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004763 }
Bruce Allana3b87a42013-04-20 05:37:29 +00004764
4765 napi_disable(&adapter->napi);
4766
Bruce Allan55aa6982011-12-16 00:45:45 +00004767 e1000e_free_tx_resources(adapter->tx_ring);
4768 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004769
Bruce Allane921eb12012-11-28 09:28:37 +00004770 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004771 * the same ID is registered on the host OS (let 8021q kill it)
4772 */
Bruce Allane5fe2542013-02-20 04:06:27 +00004773 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004774 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
4775 adapter->mng_vlan_id);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004776
Bruce Allane921eb12012-11-28 09:28:37 +00004777 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004778 * interface is now closed
4779 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004780 if ((adapter->flags & FLAG_HAS_AMT) &&
4781 !test_bit(__E1000_TESTING, &adapter->state))
4782 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004783
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01004784 cpu_latency_qos_remove_request(&adapter->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004785
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004786 pm_runtime_put_sync(&pdev->dev);
4787
Auke Kokbc7f75f2007-09-17 12:30:59 -07004788 return 0;
4789}
Bruce Allanfc830b72013-02-20 04:06:11 +00004790
Auke Kokbc7f75f2007-09-17 12:30:59 -07004791/**
4792 * e1000_set_mac - Change the Ethernet Address of the NIC
4793 * @netdev: network interface device structure
4794 * @p: pointer to an address structure
4795 *
4796 * Returns 0 on success, negative on failure
4797 **/
4798static int e1000_set_mac(struct net_device *netdev, void *p)
4799{
4800 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004801 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004802 struct sockaddr *addr = p;
4803
4804 if (!is_valid_ether_addr(addr->sa_data))
4805 return -EADDRNOTAVAIL;
4806
4807 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4808 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4809
Bruce Allan69e1e012012-04-14 03:28:50 +00004810 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004811
4812 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4813 /* activate the work around */
4814 e1000e_set_laa_state_82571(&adapter->hw, 1);
4815
Bruce Allane921eb12012-11-28 09:28:37 +00004816 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004817 * between the time RAR[0] gets clobbered and the time it
4818 * gets fixed (in e1000_watchdog), the actual LAA is in one
4819 * of the RARs and no incoming packets directed to this port
4820 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004821 * RAR[14]
4822 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004823 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4824 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004825 }
4826
4827 return 0;
4828}
4829
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004830/**
4831 * e1000e_update_phy_task - work thread to update phy
4832 * @work: pointer to our work struct
4833 *
4834 * this worker thread exists because we must acquire a
4835 * semaphore to read the phy, which we could msleep while
4836 * waiting for it, and we can't msleep in a timer.
4837 **/
4838static void e1000e_update_phy_task(struct work_struct *work)
4839{
4840 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004841 struct e1000_adapter,
4842 update_phy_task);
David Ertmana03206e2014-01-24 23:07:48 +00004843 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004844
4845 if (test_bit(__E1000_DOWN, &adapter->state))
4846 return;
4847
David Ertmana03206e2014-01-24 23:07:48 +00004848 e1000_get_phy_info(hw);
4849
4850 /* Enable EEE on 82579 after link up */
David Ertman50844bb2014-05-13 00:06:26 +00004851 if (hw->phy.type >= e1000_phy_82579)
David Ertmana03206e2014-01-24 23:07:48 +00004852 e1000_set_eee_pchlan(hw);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004853}
4854
Bruce Allane921eb12012-11-28 09:28:37 +00004855/**
4856 * e1000_update_phy_info - timre call-back to update PHY info
4857 * @data: pointer to adapter cast into an unsigned long
4858 *
Bruce Allanad680762008-03-28 09:15:03 -07004859 * Need to wait a few seconds after link up to get diagnostic information from
4860 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004861 **/
Kees Cook26566ea2017-10-16 17:29:35 -07004862static void e1000_update_phy_info(struct timer_list *t)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004863{
Kees Cook26566ea2017-10-16 17:29:35 -07004864 struct e1000_adapter *adapter = from_timer(adapter, t, phy_info_timer);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004865
4866 if (test_bit(__E1000_DOWN, &adapter->state))
4867 return;
4868
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004869 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004870}
4871
4872/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004873 * e1000e_update_phy_stats - Update the PHY statistics counters
4874 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004875 *
4876 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004877 **/
4878static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4879{
4880 struct e1000_hw *hw = &adapter->hw;
4881 s32 ret_val;
4882 u16 phy_data;
4883
4884 ret_val = hw->phy.ops.acquire(hw);
4885 if (ret_val)
4886 return;
4887
Bruce Allane921eb12012-11-28 09:28:37 +00004888 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004889 * If not, set to the page with the PHY status registers.
4890 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004891 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004892 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4893 &phy_data);
4894 if (ret_val)
4895 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004896 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4897 ret_val = hw->phy.ops.set_page(hw,
4898 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004899 if (ret_val)
4900 goto release;
4901 }
4902
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004903 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004904 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4905 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004906 if (!ret_val)
4907 adapter->stats.scc += phy_data;
4908
4909 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004910 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4911 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004912 if (!ret_val)
4913 adapter->stats.ecol += phy_data;
4914
4915 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004916 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4917 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004918 if (!ret_val)
4919 adapter->stats.mcc += phy_data;
4920
4921 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004922 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4923 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004924 if (!ret_val)
4925 adapter->stats.latecol += phy_data;
4926
4927 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004928 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4929 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004930 if (!ret_val)
4931 hw->mac.collision_delta = phy_data;
4932
4933 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004934 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4935 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004936 if (!ret_val)
4937 adapter->stats.dc += phy_data;
4938
4939 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004940 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4941 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004942 if (!ret_val)
4943 adapter->stats.tncrs += phy_data;
4944
4945release:
4946 hw->phy.ops.release(hw);
4947}
4948
4949/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004950 * e1000e_update_stats - Update the board statistics counters
4951 * @adapter: board private structure
4952 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004953static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004954{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004955 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004956 struct e1000_hw *hw = &adapter->hw;
4957 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004958
Bruce Allane921eb12012-11-28 09:28:37 +00004959 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004960 * connection is down.
4961 */
4962 if (adapter->link_speed == 0)
4963 return;
4964 if (pci_channel_offline(pdev))
4965 return;
4966
Auke Kokbc7f75f2007-09-17 12:30:59 -07004967 adapter->stats.crcerrs += er32(CRCERRS);
4968 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004969 adapter->stats.gorc += er32(GORCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00004970 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004971 adapter->stats.bprc += er32(BPRC);
4972 adapter->stats.mprc += er32(MPRC);
4973 adapter->stats.roc += er32(ROC);
4974
Auke Kokbc7f75f2007-09-17 12:30:59 -07004975 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004976
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004977 /* Half-duplex statistics */
4978 if (adapter->link_duplex == HALF_DUPLEX) {
4979 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4980 e1000e_update_phy_stats(adapter);
4981 } else {
4982 adapter->stats.scc += er32(SCC);
4983 adapter->stats.ecol += er32(ECOL);
4984 adapter->stats.mcc += er32(MCC);
4985 adapter->stats.latecol += er32(LATECOL);
4986 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004987
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004988 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004989
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004990 if ((hw->mac.type != e1000_82574) &&
4991 (hw->mac.type != e1000_82583))
4992 adapter->stats.tncrs += er32(TNCRS);
4993 }
4994 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004995 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004996
Auke Kokbc7f75f2007-09-17 12:30:59 -07004997 adapter->stats.xonrxc += er32(XONRXC);
4998 adapter->stats.xontxc += er32(XONTXC);
4999 adapter->stats.xoffrxc += er32(XOFFRXC);
5000 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005001 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07005002 adapter->stats.gotc += er32(GOTCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00005003 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005004 adapter->stats.rnbc += er32(RNBC);
5005 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005006
5007 adapter->stats.mptc += er32(MPTC);
5008 adapter->stats.bptc += er32(BPTC);
5009
5010 /* used for adaptive IFS */
5011
5012 hw->mac.tx_packet_delta = er32(TPT);
5013 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005014
5015 adapter->stats.algnerrc += er32(ALGNERRC);
5016 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005017 adapter->stats.cexterr += er32(CEXTERR);
5018 adapter->stats.tsctc += er32(TSCTC);
5019 adapter->stats.tsctfc += er32(TSCTFC);
5020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005021 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00005022 netdev->stats.multicast = adapter->stats.mprc;
5023 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005024
5025 /* Rx Errors */
5026
Bruce Allane921eb12012-11-28 09:28:37 +00005027 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07005028 * our own version based on RUC and ROC
5029 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00005030 netdev->stats.rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005031 adapter->stats.crcerrs + adapter->stats.algnerrc +
5032 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00005033 netdev->stats.rx_length_errors = adapter->stats.ruc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005034 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00005035 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
5036 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
5037 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005038
5039 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00005040 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00005041 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
5042 netdev->stats.tx_window_errors = adapter->stats.latecol;
5043 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005044
5045 /* Tx Dropped needs to be maintained elsewhere */
5046
Auke Kokbc7f75f2007-09-17 12:30:59 -07005047 /* Management Stats */
5048 adapter->stats.mgptc += er32(MGTPTC);
5049 adapter->stats.mgprc += er32(MGTPRC);
5050 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00005051
5052 /* Correctable ECC Errors */
Sasha Neftinc8744f42017-04-06 10:26:47 +03005053 if (hw->mac.type >= e1000_pch_lpt) {
Bruce Allan94fb8482013-01-23 09:00:03 +00005054 u32 pbeccsts = er32(PBECCSTS);
David Ertman6cf08d12014-04-05 06:07:00 +00005055
Bruce Allan94fb8482013-01-23 09:00:03 +00005056 adapter->corr_errors +=
5057 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
5058 adapter->uncorr_errors +=
5059 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
5060 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
5061 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005062}
5063
Bruce Allan7c257692008-04-23 11:09:00 -07005064/**
5065 * e1000_phy_read_status - Update the PHY register status snapshot
5066 * @adapter: board private structure
5067 **/
5068static void e1000_phy_read_status(struct e1000_adapter *adapter)
5069{
5070 struct e1000_hw *hw = &adapter->hw;
5071 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07005072
Bruce Allan97390ab2013-06-29 07:42:25 +00005073 if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
5074 (er32(STATUS) & E1000_STATUS_LU) &&
Bruce Allan7c257692008-04-23 11:09:00 -07005075 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005076 int ret_val;
5077
Bruce Allanc2ade1a2013-01-16 08:54:35 +00005078 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
5079 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
5080 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
5081 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
5082 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
5083 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
5084 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
5085 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07005086 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005087 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07005088 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00005089 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07005090 * Set values to typical power-on defaults
5091 */
5092 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
5093 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
5094 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
5095 BMSR_ERCAP);
5096 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
5097 ADVERTISE_ALL | ADVERTISE_CSMA);
5098 phy->lpa = 0;
5099 phy->expansion = EXPANSION_ENABLENPAGE;
5100 phy->ctrl1000 = ADVERTISE_1000FULL;
5101 phy->stat1000 = 0;
5102 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
5103 }
Bruce Allan7c257692008-04-23 11:09:00 -07005104}
5105
Auke Kokbc7f75f2007-09-17 12:30:59 -07005106static void e1000_print_link_info(struct e1000_adapter *adapter)
5107{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005108 struct e1000_hw *hw = &adapter->hw;
5109 u32 ctrl = er32(CTRL);
5110
Bruce Allan8f12fe82008-11-21 16:54:43 -08005111 /* Link status message must follow this format for user tools */
Alexander Duyckc557a4b2019-10-31 09:58:51 -07005112 netdev_info(adapter->netdev,
5113 "NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
5114 adapter->link_speed,
5115 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
5116 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
5117 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
5118 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005119}
5120
Bruce Allan0c6bdb32010-06-17 18:58:43 +00005121static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005122{
5123 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00005124 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005125 s32 ret_val = 0;
5126
Bruce Allane921eb12012-11-28 09:28:37 +00005127 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005128 * Rx sequence error interrupt. get_link_status will stay
Benjamin Poirier65a29da2017-07-21 11:36:24 -07005129 * true until the check_for_link establishes link
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005130 * for copper adapters ONLY
5131 */
5132 switch (hw->phy.media_type) {
5133 case e1000_media_type_copper:
5134 if (hw->mac.get_link_status) {
5135 ret_val = hw->mac.ops.check_for_link(hw);
Benjamin Poirier3016e0a2018-03-06 10:55:52 +09005136 link_active = !hw->mac.get_link_status;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005137 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00005138 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005139 }
5140 break;
5141 case e1000_media_type_fiber:
5142 ret_val = hw->mac.ops.check_for_link(hw);
5143 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
5144 break;
5145 case e1000_media_type_internal_serdes:
5146 ret_val = hw->mac.ops.check_for_link(hw);
Benjamin Poirier65a29da2017-07-21 11:36:24 -07005147 link_active = hw->mac.serdes_has_link;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005148 break;
5149 default:
5150 case e1000_media_type_unknown:
5151 break;
5152 }
5153
Benjamin Poirierd3509f82017-07-21 11:36:25 -07005154 if ((ret_val == -E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005155 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
5156 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005157 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005158 }
5159
5160 return link_active;
5161}
5162
5163static void e1000e_enable_receives(struct e1000_adapter *adapter)
5164{
5165 /* make sure the receive unit is started */
5166 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00005167 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005168 struct e1000_hw *hw = &adapter->hw;
5169 u32 rctl = er32(RCTL);
David Ertman6cf08d12014-04-05 06:07:00 +00005170
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005171 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00005172 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005173 }
5174}
5175
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005176static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
5177{
5178 struct e1000_hw *hw = &adapter->hw;
5179
Bruce Allane921eb12012-11-28 09:28:37 +00005180 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005181 * for hung state and reset, if two calls return true
5182 */
5183 if (e1000_check_phy_82574(hw))
5184 adapter->phy_hang_count++;
5185 else
5186 adapter->phy_hang_count = 0;
5187
5188 if (adapter->phy_hang_count > 1) {
5189 adapter->phy_hang_count = 0;
David Ertmand9554e92014-01-08 01:07:55 +00005190 e_dbg("PHY appears hung - resetting\n");
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005191 schedule_work(&adapter->reset_task);
5192 }
5193}
5194
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08005195/**
5196 * e1000_watchdog - Timer Call-back
5197 * @data: pointer to adapter cast into an unsigned long
5198 **/
5199static void e1000_watchdog(struct timer_list *t)
5200{
5201 struct e1000_adapter *adapter = from_timer(adapter, t, watchdog_timer);
5202
5203 /* Do the rest outside of interrupt context */
5204 schedule_work(&adapter->watchdog_task);
5205
5206 /* TODO: make this use queue_delayed_work() */
5207}
5208
Auke Kokbc7f75f2007-09-17 12:30:59 -07005209static void e1000_watchdog_task(struct work_struct *work)
5210{
5211 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00005212 struct e1000_adapter,
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08005213 watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005214 struct net_device *netdev = adapter->netdev;
5215 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08005216 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005217 struct e1000_ring *tx_ring = adapter->tx_ring;
Vitaly Lifshitsdef4ec62019-06-25 17:39:11 +03005218 u32 dmoff_exit_timeout = 100, tries = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005219 struct e1000_hw *hw = &adapter->hw;
Vitaly Lifshitsdef4ec62019-06-25 17:39:11 +03005220 u32 link, tctl, pcim_state;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005221
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005222 if (test_bit(__E1000_DOWN, &adapter->state))
5223 return;
5224
David S. Millerb405e8d2010-02-04 22:31:41 -08005225 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005226 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005227 /* Cancel scheduled suspend requests. */
5228 pm_runtime_resume(netdev->dev.parent);
5229
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005230 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005231 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005232 }
5233
5234 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
5235 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
5236 e1000_update_mng_vlan(adapter);
5237
Auke Kokbc7f75f2007-09-17 12:30:59 -07005238 if (link) {
5239 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00005240 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005241
5242 /* Cancel scheduled suspend requests. */
5243 pm_runtime_resume(netdev->dev.parent);
5244
Vitaly Lifshitsdef4ec62019-06-25 17:39:11 +03005245 /* Checking if MAC is in DMoff state*/
5246 pcim_state = er32(STATUS);
5247 while (pcim_state & E1000_STATUS_PCIM_STATE) {
5248 if (tries++ == dmoff_exit_timeout) {
5249 e_dbg("Error in exiting dmoff\n");
5250 break;
5251 }
5252 usleep_range(10000, 20000);
5253 pcim_state = er32(STATUS);
5254
5255 /* Checking if MAC exited DMoff state */
5256 if (!(pcim_state & E1000_STATUS_PCIM_STATE))
5257 e1000_phy_hw_reset(&adapter->hw);
5258 }
5259
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005260 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07005261 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005262 mac->ops.get_link_up_info(&adapter->hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00005263 &adapter->link_speed,
5264 &adapter->link_duplex);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005265 e1000_print_link_info(adapter);
Koki Sanagie792cd92013-02-03 14:03:55 +00005266
5267 /* check if SmartSpeed worked */
5268 e1000e_check_downshift(hw);
5269 if (phy->speed_downgraded)
5270 netdev_warn(netdev,
5271 "Link Speed was downgraded by SmartSpeed\n");
5272
Bruce Allane921eb12012-11-28 09:28:37 +00005273 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07005274 * if link has autonegotiated at 10/100 half
5275 */
5276 if ((hw->phy.type == e1000_phy_igp_3 ||
5277 hw->phy.type == e1000_phy_bm) &&
David Ertman138953b2013-08-30 05:45:25 +00005278 hw->mac.autoneg &&
Bruce Allanf4187b52008-08-26 18:36:50 -07005279 (adapter->link_speed == SPEED_10 ||
5280 adapter->link_speed == SPEED_100) &&
5281 (adapter->link_duplex == HALF_DUPLEX)) {
5282 u16 autoneg_exp;
5283
Bruce Allanc2ade1a2013-01-16 08:54:35 +00005284 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07005285
Bruce Allanc2ade1a2013-01-16 08:54:35 +00005286 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00005287 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07005288 }
5289
Emil Tantilovf49c57e2010-03-24 12:55:02 +00005290 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005291 adapter->tx_timeout_factor = 1;
5292 switch (adapter->link_speed) {
5293 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00005294 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07005295 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005296 break;
5297 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00005298 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00005299 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005300 break;
5301 }
5302
Bruce Allane921eb12012-11-28 09:28:37 +00005303 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07005304 * link-up event
5305 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005306 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
5307 !txb2b) {
5308 u32 tarc0;
David Ertman6cf08d12014-04-05 06:07:00 +00005309
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07005310 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005311 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07005312 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005313 }
5314
Bruce Allane921eb12012-11-28 09:28:37 +00005315 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07005316 * some hardware issues
5317 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005318 if (!(adapter->flags & FLAG_TSO_FORCE)) {
5319 switch (adapter->link_speed) {
5320 case SPEED_10:
5321 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005322 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005323 netdev->features &= ~NETIF_F_TSO;
5324 netdev->features &= ~NETIF_F_TSO6;
5325 break;
5326 case SPEED_1000:
5327 netdev->features |= NETIF_F_TSO;
5328 netdev->features |= NETIF_F_TSO6;
5329 break;
5330 default:
5331 /* oops */
5332 break;
5333 }
Kai-Heng Fengf2980102020-05-07 22:21:07 +08005334 if (hw->mac.type == e1000_pch_spt) {
5335 netdev->features &= ~NETIF_F_TSO;
5336 netdev->features &= ~NETIF_F_TSO6;
5337 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005338 }
5339
Bruce Allane921eb12012-11-28 09:28:37 +00005340 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07005341 * after setting TARC(0)
5342 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005343 tctl = er32(TCTL);
5344 tctl |= E1000_TCTL_EN;
5345 ew32(TCTL, tctl);
5346
Bruce Allane921eb12012-11-28 09:28:37 +00005347 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08005348 * reporting link up.
5349 */
5350 if (phy->ops.cfg_on_link_up)
5351 phy->ops.cfg_on_link_up(hw);
5352
Konstantin Khlebnikovd17ba0f2019-04-17 11:13:20 +03005353 netif_wake_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005354 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005355
5356 if (!test_bit(__E1000_DOWN, &adapter->state))
5357 mod_timer(&adapter->phy_info_timer,
5358 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005359 }
5360 } else {
5361 if (netif_carrier_ok(netdev)) {
5362 adapter->link_speed = 0;
5363 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08005364 /* Link status message must follow this format */
Alexander Duyckc557a4b2019-10-31 09:58:51 -07005365 netdev_info(netdev, "NIC Link is Down\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005366 netif_carrier_off(netdev);
Konstantin Khlebnikovd17ba0f2019-04-17 11:13:20 +03005367 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005368 if (!test_bit(__E1000_DOWN, &adapter->state))
5369 mod_timer(&adapter->phy_info_timer,
5370 round_jiffies(jiffies + 2 * HZ));
5371
David Ertmand9554e92014-01-08 01:07:55 +00005372 /* 8000ES2LAN requires a Rx packet buffer work-around
5373 * on link down event; reset the controller to flush
5374 * the Rx packet buffer.
Bruce Allan12d43f72012-12-05 06:26:14 +00005375 */
Konstantin Khlebnikovcaff4222019-04-17 11:13:16 +03005376 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
Bruce Allan12d43f72012-12-05 06:26:14 +00005377 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005378 else
5379 pm_schedule_suspend(netdev->dev.parent,
Bruce Allan17e813e2013-02-20 04:06:01 +00005380 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005381 }
5382 }
5383
5384link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005385 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005386 e1000e_update_stats(adapter);
5387
5388 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
5389 adapter->tpt_old = adapter->stats.tpt;
5390 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
5391 adapter->colc_old = adapter->stats.colc;
5392
Bruce Allan7c257692008-04-23 11:09:00 -07005393 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
5394 adapter->gorc_old = adapter->stats.gorc;
5395 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
5396 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00005397 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005398
Konstantin Khlebnikovcaff4222019-04-17 11:13:16 +03005399 /* If the link is lost the controller stops DMA, but
5400 * if there is queued Tx work it cannot be done. So
5401 * reset the controller to flush the Tx packet buffers.
5402 */
5403 if (!netif_carrier_ok(netdev) &&
5404 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
5405 adapter->flags |= FLAG_RESTART_NOW;
5406
David Ertmand9554e92014-01-08 01:07:55 +00005407 /* If reset is necessary, do it outside of interrupt context. */
Bruce Allan12d43f72012-12-05 06:26:14 +00005408 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00005409 schedule_work(&adapter->reset_task);
5410 /* return immediately since reset is imminent */
5411 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005412 }
5413
Bruce Allan12d43f72012-12-05 06:26:14 +00005414 e1000e_update_adaptive(&adapter->hw);
5415
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005416 /* Simple mode for Interrupt Throttle Rate (ITR) */
5417 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00005418 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005419 * Total asymmetrical Tx or Rx gets ITR=8000;
5420 * everyone else is between 2000-8000.
5421 */
5422 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
5423 u32 dif = (adapter->gotc > adapter->gorc ?
Bruce Allan17e813e2013-02-20 04:06:01 +00005424 adapter->gotc - adapter->gorc :
5425 adapter->gorc - adapter->gotc) / 10000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005426 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
5427
Matthew Vick22a4cca2012-07-12 00:02:42 +00005428 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005429 }
5430
Bruce Allanad680762008-03-28 09:15:03 -07005431 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07005432 if (adapter->msix_entries)
5433 ew32(ICS, adapter->rx_ring->ims_val);
5434 else
5435 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005436
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00005437 /* flush pending descriptors to memory before detecting Tx hang */
5438 e1000e_flush_descriptors(adapter);
5439
Auke Kokbc7f75f2007-09-17 12:30:59 -07005440 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005441 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005442
Bruce Allane921eb12012-11-28 09:28:37 +00005443 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005444 * reset from the other port. Set the appropriate LAA in RAR[0]
5445 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005446 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005447 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005448
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005449 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5450 e1000e_check_82574_phy_workaround(adapter);
5451
Bruce Allanb67e1912012-12-27 08:32:33 +00005452 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5453 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5454 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5455 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5456 er32(RXSTMPH);
5457 adapter->rx_hwtstamp_cleared++;
5458 } else {
5459 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5460 }
5461 }
5462
Auke Kokbc7f75f2007-09-17 12:30:59 -07005463 /* Reset the timer */
5464 if (!test_bit(__E1000_DOWN, &adapter->state))
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08005465 mod_timer(&adapter->watchdog_timer,
5466 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005467}
5468
5469#define E1000_TX_FLAGS_CSUM 0x00000001
5470#define E1000_TX_FLAGS_VLAN 0x00000002
5471#define E1000_TX_FLAGS_TSO 0x00000004
5472#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005473#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005474#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005475#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5476#define E1000_TX_FLAGS_VLAN_SHIFT 16
5477
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005478static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb,
5479 __be16 protocol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005480{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005481 struct e1000_context_desc *context_desc;
5482 struct e1000_buffer *buffer_info;
5483 unsigned int i;
5484 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005485 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005486 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Francois Romieubcf1f572014-03-30 03:14:43 +00005487 int err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005488
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005489 if (!skb_is_gso(skb))
5490 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005491
Francois Romieubcf1f572014-03-30 03:14:43 +00005492 err = skb_cow_head(skb, 0);
5493 if (err < 0)
5494 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005495
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005496 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5497 mss = skb_shinfo(skb)->gso_size;
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005498 if (protocol == htons(ETH_P_IP)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005499 struct iphdr *iph = ip_hdr(skb);
5500 iph->tot_len = 0;
5501 iph->check = 0;
5502 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005503 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005504 cmd_length = E1000_TXD_CMD_IP;
5505 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005506 } else if (skb_is_gso_v6(skb)) {
Heiner Kallweit2b316fbc2020-02-18 21:05:02 +01005507 tcp_v6_gso_csum_prep(skb);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005508 ipcse = 0;
5509 }
5510 ipcss = skb_network_offset(skb);
5511 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5512 tucss = skb_transport_offset(skb);
5513 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005514
5515 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005516 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005517
5518 i = tx_ring->next_to_use;
5519 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5520 buffer_info = &tx_ring->buffer_info[i];
5521
Bruce Allane80bd1d2013-05-01 01:19:46 +00005522 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5523 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5524 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005525 context_desc->upper_setup.tcp_fields.tucss = tucss;
5526 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005527 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allane80bd1d2013-05-01 01:19:46 +00005528 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005529 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5530 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5531
5532 buffer_info->time_stamp = jiffies;
5533 buffer_info->next_to_watch = i;
5534
5535 i++;
5536 if (i == tx_ring->count)
5537 i = 0;
5538 tx_ring->next_to_use = i;
5539
5540 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005541}
5542
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005543static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb,
5544 __be16 protocol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005545{
Bruce Allan55aa6982011-12-16 00:45:45 +00005546 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005547 struct e1000_context_desc *context_desc;
5548 struct e1000_buffer *buffer_info;
5549 unsigned int i;
5550 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005551 u32 cmd_len = E1000_TXD_CMD_DEXT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005552
Dave Grahamaf807c82008-10-09 14:28:58 -07005553 if (skb->ip_summed != CHECKSUM_PARTIAL)
David Ertman3992c8e2014-04-05 03:36:15 +00005554 return false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005555
Arthur Jones3f518392009-03-20 15:56:35 -07005556 switch (protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08005557 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005558 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5559 cmd_len |= E1000_TXD_CMD_TCP;
5560 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08005561 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005562 /* XXX not handling all IPV6 headers */
5563 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5564 cmd_len |= E1000_TXD_CMD_TCP;
5565 break;
5566 default:
5567 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005568 e_warn("checksum_partial proto=%x!\n",
5569 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005570 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005571 }
5572
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005573 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005574
5575 i = tx_ring->next_to_use;
5576 buffer_info = &tx_ring->buffer_info[i];
5577 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5578
5579 context_desc->lower_setup.ip_config = 0;
5580 context_desc->upper_setup.tcp_fields.tucss = css;
Bruce Allanf0ff4392013-02-20 04:05:39 +00005581 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Dave Grahamaf807c82008-10-09 14:28:58 -07005582 context_desc->upper_setup.tcp_fields.tucse = 0;
5583 context_desc->tcp_seg_setup.data = 0;
5584 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5585
5586 buffer_info->time_stamp = jiffies;
5587 buffer_info->next_to_watch = i;
5588
5589 i++;
5590 if (i == tx_ring->count)
5591 i = 0;
5592 tx_ring->next_to_use = i;
5593
David Ertman3992c8e2014-04-05 03:36:15 +00005594 return true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005595}
5596
Bruce Allan55aa6982011-12-16 00:45:45 +00005597static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5598 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005599 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005600{
Bruce Allan55aa6982011-12-16 00:45:45 +00005601 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005602 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005603 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005604 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005605 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005606 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005607
5608 i = tx_ring->next_to_use;
5609
5610 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005611 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005612 size = min(len, max_per_txd);
5613
Auke Kokbc7f75f2007-09-17 12:30:59 -07005614 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005615 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005616 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005617 buffer_info->dma = dma_map_single(&pdev->dev,
5618 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005619 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005620 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005621 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005622 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005623
5624 len -= size;
5625 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005626 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005627
5628 if (len) {
5629 i++;
5630 if (i == tx_ring->count)
5631 i = 0;
5632 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005633 }
5634
5635 for (f = 0; f < nr_frags; f++) {
Matthew Wilcox (Oracle)d7840972019-07-22 20:08:25 -07005636 const skb_frag_t *frag = &skb_shinfo(skb)->frags[f];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005637
Eric Dumazet9e903e02011-10-18 21:00:24 +00005638 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005639 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005640
5641 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005642 i++;
5643 if (i == tx_ring->count)
5644 i = 0;
5645
Auke Kokbc7f75f2007-09-17 12:30:59 -07005646 buffer_info = &tx_ring->buffer_info[i];
5647 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005648
5649 buffer_info->length = size;
5650 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005651 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005652 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
Bruce Allan17e813e2013-02-20 04:06:01 +00005653 offset, size,
5654 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005655 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005656 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005657 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005658
5659 len -= size;
5660 offset += size;
5661 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005662 }
5663 }
5664
Bruce Allanaf667a22010-12-31 06:10:01 +00005665 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005666 /* multiply data chunks by size of headers */
5667 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5668
Auke Kokbc7f75f2007-09-17 12:30:59 -07005669 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005670 tx_ring->buffer_info[i].segs = segs;
5671 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005672 tx_ring->buffer_info[first].next_to_watch = i;
5673
5674 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005675
5676dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005677 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005678 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005679 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005680 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005681
5682 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005683 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005684 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005685 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005686 buffer_info = &tx_ring->buffer_info[i];
Florian Fainelli377b6272017-08-25 18:14:24 -07005687 e1000_put_txbuf(tx_ring, buffer_info, true);
Alexander Duyck03b13202009-12-02 16:45:31 +00005688 }
5689
5690 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005691}
5692
Bruce Allan55aa6982011-12-16 00:45:45 +00005693static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005694{
Bruce Allan55aa6982011-12-16 00:45:45 +00005695 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005696 struct e1000_tx_desc *tx_desc = NULL;
5697 struct e1000_buffer *buffer_info;
5698 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5699 unsigned int i;
5700
5701 if (tx_flags & E1000_TX_FLAGS_TSO) {
5702 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005703 E1000_TXD_CMD_TSE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005704 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5705
5706 if (tx_flags & E1000_TX_FLAGS_IPV4)
5707 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5708 }
5709
5710 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5711 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5712 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5713 }
5714
5715 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5716 txd_lower |= E1000_TXD_CMD_VLE;
5717 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5718 }
5719
Ben Greear943146d2012-02-11 15:39:40 +00005720 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5721 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5722
Bruce Allanb67e1912012-12-27 08:32:33 +00005723 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5724 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5725 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5726 }
5727
Auke Kokbc7f75f2007-09-17 12:30:59 -07005728 i = tx_ring->next_to_use;
5729
Bruce Allan36b973d2010-11-24 07:42:43 +00005730 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005731 buffer_info = &tx_ring->buffer_info[i];
5732 tx_desc = E1000_TX_DESC(*tx_ring, i);
5733 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allanf0ff4392013-02-20 04:05:39 +00005734 tx_desc->lower.data = cpu_to_le32(txd_lower |
5735 buffer_info->length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005736 tx_desc->upper.data = cpu_to_le32(txd_upper);
5737
5738 i++;
5739 if (i == tx_ring->count)
5740 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005741 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005742
5743 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5744
Ben Greear943146d2012-02-11 15:39:40 +00005745 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5746 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5747 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5748
Bruce Allane921eb12012-11-28 09:28:37 +00005749 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005750 * know there are new descriptors to fetch. (Only
5751 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005752 * such as IA-64).
5753 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005754 wmb();
5755
5756 tx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005757}
5758
5759#define MINIMUM_DHCP_PACKET_SIZE 282
5760static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5761 struct sk_buff *skb)
5762{
Bruce Allane80bd1d2013-05-01 01:19:46 +00005763 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005764 u16 length, offset;
5765
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01005766 if (skb_vlan_tag_present(skb) &&
5767 !((skb_vlan_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Bruce Alland60923c2012-12-05 06:26:56 +00005768 (adapter->hw.mng_cookie.status &
5769 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5770 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005771
5772 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5773 return 0;
5774
Bruce Allan53aa82d2013-02-20 04:06:06 +00005775 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005776 return 0;
5777
5778 {
Bruce Allan362e20c2013-02-20 04:05:45 +00005779 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005780 struct udphdr *udp;
5781
5782 if (ip->protocol != IPPROTO_UDP)
5783 return 0;
5784
5785 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5786 if (ntohs(udp->dest) != 67)
5787 return 0;
5788
5789 offset = (u8 *)udp + 8 - skb->data;
5790 length = skb->len - offset;
5791 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5792 }
5793
5794 return 0;
5795}
5796
Bruce Allan55aa6982011-12-16 00:45:45 +00005797static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005798{
Bruce Allan55aa6982011-12-16 00:45:45 +00005799 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005800
Bruce Allan55aa6982011-12-16 00:45:45 +00005801 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005802 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005803 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005804 * but since that doesn't exist yet, just open code it.
5805 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005806 smp_mb();
5807
Bruce Allane921eb12012-11-28 09:28:37 +00005808 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005809 * made room available.
5810 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005811 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005812 return -EBUSY;
5813
5814 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005815 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005816 ++adapter->restart_queue;
5817 return 0;
5818}
5819
Bruce Allan55aa6982011-12-16 00:45:45 +00005820static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005821{
Bruce Alland821a4c2012-08-24 20:38:11 +00005822 BUG_ON(size > tx_ring->count);
5823
Bruce Allan55aa6982011-12-16 00:45:45 +00005824 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005825 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005826 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005827}
5828
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005829static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5830 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005831{
5832 struct e1000_adapter *adapter = netdev_priv(netdev);
5833 struct e1000_ring *tx_ring = adapter->tx_ring;
5834 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005835 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005836 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005837 unsigned int nr_frags;
5838 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005839 int count = 0;
5840 int tso;
5841 unsigned int f;
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005842 __be16 protocol = vlan_get_protocol(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005843
5844 if (test_bit(__E1000_DOWN, &adapter->state)) {
5845 dev_kfree_skb_any(skb);
5846 return NETDEV_TX_OK;
5847 }
5848
5849 if (skb->len <= 0) {
5850 dev_kfree_skb_any(skb);
5851 return NETDEV_TX_OK;
5852 }
5853
Bruce Allane921eb12012-11-28 09:28:37 +00005854 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005855 * pad skb in order to meet this minimum size requirement
5856 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08005857 if (skb_put_padto(skb, 17))
5858 return NETDEV_TX_OK;
Tushar Dave6e97c172012-09-14 02:21:37 +00005859
Auke Kokbc7f75f2007-09-17 12:30:59 -07005860 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005861 if (mss) {
5862 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005863
Bruce Allane921eb12012-11-28 09:28:37 +00005864 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005865 * points to just header, pull a few bytes of payload from
5866 * frags into skb->data
5867 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005868 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005869 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005870 * avoiding it could save a lot of cycles
5871 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005872 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005873 unsigned int pull_size;
5874
Bruce Allana2a5b322012-01-31 06:37:17 +00005875 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005876 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005877 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005878 dev_kfree_skb_any(skb);
5879 return NETDEV_TX_OK;
5880 }
Eric Dumazete743d312010-04-14 15:59:40 -07005881 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005882 }
5883 }
5884
5885 /* reserve a descriptor for the offload context */
5886 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5887 count++;
5888 count++;
5889
Bruce Alland821a4c2012-08-24 20:38:11 +00005890 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005891
5892 nr_frags = skb_shinfo(skb)->nr_frags;
5893 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005894 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5895 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005896
5897 if (adapter->hw.mac.tx_pkt_filtering)
5898 e1000_transfer_dhcp_info(adapter, skb);
5899
Bruce Allane921eb12012-11-28 09:28:37 +00005900 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005901 * head, otherwise try next time
5902 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005903 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005904 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005905
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01005906 if (skb_vlan_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005907 tx_flags |= E1000_TX_FLAGS_VLAN;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01005908 tx_flags |= (skb_vlan_tag_get(skb) <<
5909 E1000_TX_FLAGS_VLAN_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005910 }
5911
5912 first = tx_ring->next_to_use;
5913
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005914 tso = e1000_tso(tx_ring, skb, protocol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005915 if (tso < 0) {
5916 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005917 return NETDEV_TX_OK;
5918 }
5919
5920 if (tso)
5921 tx_flags |= E1000_TX_FLAGS_TSO;
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005922 else if (e1000_tx_csum(tx_ring, skb, protocol))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005923 tx_flags |= E1000_TX_FLAGS_CSUM;
5924
Bruce Allane921eb12012-11-28 09:28:37 +00005925 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005926 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005927 * no longer assume, we must.
5928 */
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005929 if (protocol == htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005930 tx_flags |= E1000_TX_FLAGS_IPV4;
5931
Ben Greear943146d2012-02-11 15:39:40 +00005932 if (unlikely(skb->no_fcs))
5933 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5934
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005935 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005936 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5937 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005938 if (count) {
Mathias Koehrer69308952014-08-07 18:51:53 +00005939 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
Jacob Kellercff57142017-05-03 10:28:57 -07005940 (adapter->flags & FLAG_HAS_HW_TIMESTAMP)) {
5941 if (!adapter->tx_hwtstamp_skb) {
5942 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5943 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5944 adapter->tx_hwtstamp_skb = skb_get(skb);
5945 adapter->tx_hwtstamp_start = jiffies;
5946 schedule_work(&adapter->tx_hwtstamp_work);
5947 } else {
5948 adapter->tx_hwtstamp_skipped++;
5949 }
Bruce Allanb67e1912012-12-27 08:32:33 +00005950 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005951
Miroslav Lichvar74abc9b12017-05-19 17:52:41 +02005952 skb_tx_timestamp(skb);
5953
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005954 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005955 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005956 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005957 e1000_maybe_stop_tx(tx_ring,
5958 (MAX_SKB_FRAGS *
5959 DIV_ROUND_UP(PAGE_SIZE,
5960 adapter->tx_fifo_limit) + 2));
Florian Westphal472f31f2015-01-09 09:26:14 +00005961
Florian Westphal6b16f9e2019-04-01 16:42:14 +02005962 if (!netdev_xmit_more() ||
Florian Westphal472f31f2015-01-09 09:26:14 +00005963 netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) {
5964 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
5965 e1000e_update_tdt_wa(tx_ring,
5966 tx_ring->next_to_use);
5967 else
5968 writel(tx_ring->next_to_use, tx_ring->tail);
Florian Westphal472f31f2015-01-09 09:26:14 +00005969 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005970 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005971 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005972 tx_ring->buffer_info[first].time_stamp = 0;
5973 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005974 }
5975
Auke Kokbc7f75f2007-09-17 12:30:59 -07005976 return NETDEV_TX_OK;
5977}
5978
5979/**
5980 * e1000_tx_timeout - Respond to a Tx Hang
5981 * @netdev: network interface device structure
5982 **/
Michael S. Tsirkin0290bd22019-12-10 09:23:51 -05005983static void e1000_tx_timeout(struct net_device *netdev, unsigned int txqueue)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005984{
5985 struct e1000_adapter *adapter = netdev_priv(netdev);
5986
5987 /* Do the reset outside of interrupt context */
5988 adapter->tx_timeout_count++;
5989 schedule_work(&adapter->reset_task);
5990}
5991
5992static void e1000_reset_task(struct work_struct *work)
5993{
5994 struct e1000_adapter *adapter;
5995 adapter = container_of(work, struct e1000_adapter, reset_task);
5996
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005997 /* don't run the task if already down */
5998 if (test_bit(__E1000_DOWN, &adapter->state))
5999 return;
6000
Bruce Allan12d43f72012-12-05 06:26:14 +00006001 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00006002 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00006003 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00006004 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006005 e1000e_reinit_locked(adapter);
6006}
6007
6008/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006009 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07006010 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006011 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07006012 *
6013 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07006014 **/
stephen hemmingerbc1f4472017-01-06 19:12:52 -08006015void e1000e_get_stats64(struct net_device *netdev,
6016 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006017{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006018 struct e1000_adapter *adapter = netdev_priv(netdev);
6019
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006020 spin_lock(&adapter->stats64_lock);
6021 e1000e_update_stats(adapter);
6022 /* Fill out the OS statistics structure */
6023 stats->rx_bytes = adapter->stats.gorc;
6024 stats->rx_packets = adapter->stats.gprc;
6025 stats->tx_bytes = adapter->stats.gotc;
6026 stats->tx_packets = adapter->stats.gptc;
6027 stats->multicast = adapter->stats.mprc;
6028 stats->collisions = adapter->stats.colc;
6029
6030 /* Rx Errors */
6031
Bruce Allane921eb12012-11-28 09:28:37 +00006032 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006033 * our own version based on RUC and ROC
6034 */
6035 stats->rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00006036 adapter->stats.crcerrs + adapter->stats.algnerrc +
6037 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
6038 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006039 stats->rx_crc_errors = adapter->stats.crcerrs;
6040 stats->rx_frame_errors = adapter->stats.algnerrc;
6041 stats->rx_missed_errors = adapter->stats.mpc;
6042
6043 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00006044 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006045 stats->tx_aborted_errors = adapter->stats.ecol;
6046 stats->tx_window_errors = adapter->stats.latecol;
6047 stats->tx_carrier_errors = adapter->stats.tncrs;
6048
6049 /* Tx Dropped needs to be maintained elsewhere */
6050
6051 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006052}
6053
6054/**
6055 * e1000_change_mtu - Change the Maximum Transfer Unit
6056 * @netdev: network interface device structure
6057 * @new_mtu: new value for maximum frame size
6058 *
6059 * Returns 0 on success, negative on failure
6060 **/
6061static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
6062{
6063 struct e1000_adapter *adapter = netdev_priv(netdev);
Alexander Duyck8084b862015-05-02 00:52:00 -07006064 int max_frame = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006065
Bruce Allan2adc55c2009-06-02 11:28:58 +00006066 /* Jumbo frame support */
Jarod Wilson91c527a2016-10-17 15:54:05 -04006067 if ((new_mtu > ETH_DATA_LEN) &&
Bruce Allan2e1706f2012-06-30 20:02:42 +00006068 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
6069 e_err("Jumbo Frames not supported.\n");
6070 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006071 }
6072
Bruce Allan2fbe4522012-04-19 03:21:47 +00006073 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
6074 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00006075 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
6076 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00006077 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00006078 return -EINVAL;
6079 }
6080
Auke Kokbc7f75f2007-09-17 12:30:59 -07006081 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Arjan van de Venab6973a2019-06-14 17:29:35 -07006082 usleep_range(1000, 1100);
Bruce Allan610c9922009-11-19 12:35:45 +00006083 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006084 adapter->max_frame_size = max_frame;
Florian Fainelli12299132019-11-07 14:35:36 -08006085 netdev_dbg(netdev, "changing MTU from %d to %d\n",
6086 netdev->mtu, new_mtu);
Bruce Allan610c9922009-11-19 12:35:45 +00006087 netdev->mtu = new_mtu;
David Ertman63eb48f2014-02-14 07:16:46 +00006088
6089 pm_runtime_get_sync(netdev->dev.parent);
6090
Auke Kokbc7f75f2007-09-17 12:30:59 -07006091 if (netif_running(netdev))
David Ertman28002092014-02-14 07:16:41 +00006092 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006093
Bruce Allane921eb12012-11-28 09:28:37 +00006094 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07006095 * means we reserve 2 more, this pushes us to allocate from the next
6096 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07006097 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006098 * However with the new *_jumbo_rx* routines, jumbo receives will use
6099 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07006100 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006101
Jesse Brandeburg99261462010-01-22 22:56:16 +00006102 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006103 adapter->rx_buffer_len = 2048;
6104 else
6105 adapter->rx_buffer_len = 4096;
6106
6107 /* adjust allocation if LPE protects us, and we aren't using SBP */
Alexander Duyck8084b862015-05-02 00:52:00 -07006108 if (max_frame <= (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN))
6109 adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006110
Auke Kokbc7f75f2007-09-17 12:30:59 -07006111 if (netif_running(netdev))
6112 e1000e_up(adapter);
6113 else
6114 e1000e_reset(adapter);
6115
David Ertman63eb48f2014-02-14 07:16:46 +00006116 pm_runtime_put_sync(netdev->dev.parent);
6117
Auke Kokbc7f75f2007-09-17 12:30:59 -07006118 clear_bit(__E1000_RESETTING, &adapter->state);
6119
6120 return 0;
6121}
6122
6123static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
6124 int cmd)
6125{
6126 struct e1000_adapter *adapter = netdev_priv(netdev);
6127 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006128
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006129 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006130 return -EOPNOTSUPP;
6131
6132 switch (cmd) {
6133 case SIOCGMIIPHY:
6134 data->phy_id = adapter->hw.phy.addr;
6135 break;
6136 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00006137 e1000_phy_read_status(adapter);
6138
Bruce Allan7c257692008-04-23 11:09:00 -07006139 switch (data->reg_num & 0x1F) {
6140 case MII_BMCR:
6141 data->val_out = adapter->phy_regs.bmcr;
6142 break;
6143 case MII_BMSR:
6144 data->val_out = adapter->phy_regs.bmsr;
6145 break;
6146 case MII_PHYSID1:
6147 data->val_out = (adapter->hw.phy.id >> 16);
6148 break;
6149 case MII_PHYSID2:
6150 data->val_out = (adapter->hw.phy.id & 0xFFFF);
6151 break;
6152 case MII_ADVERTISE:
6153 data->val_out = adapter->phy_regs.advertise;
6154 break;
6155 case MII_LPA:
6156 data->val_out = adapter->phy_regs.lpa;
6157 break;
6158 case MII_EXPANSION:
6159 data->val_out = adapter->phy_regs.expansion;
6160 break;
6161 case MII_CTRL1000:
6162 data->val_out = adapter->phy_regs.ctrl1000;
6163 break;
6164 case MII_STAT1000:
6165 data->val_out = adapter->phy_regs.stat1000;
6166 break;
6167 case MII_ESTATUS:
6168 data->val_out = adapter->phy_regs.estatus;
6169 break;
6170 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006171 return -EIO;
6172 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006173 break;
6174 case SIOCSMIIREG:
6175 default:
6176 return -EOPNOTSUPP;
6177 }
6178 return 0;
6179}
6180
Bruce Allanb67e1912012-12-27 08:32:33 +00006181/**
6182 * e1000e_hwtstamp_ioctl - control hardware time stamping
6183 * @netdev: network interface device structure
6184 * @ifreq: interface request
6185 *
6186 * Outgoing time stamping can be enabled and disabled. Play nice and
6187 * disable it when requested, although it shouldn't cause any overhead
6188 * when no packet needs it. At most one packet in the queue may be
6189 * marked for time stamping, otherwise it would be impossible to tell
6190 * for sure to which packet the hardware time stamp belongs.
6191 *
6192 * Incoming time stamping has to be configured via the hardware filters.
6193 * Not all combinations are supported, in particular event type has to be
6194 * specified. Matching the kind of event packet is not supported, with the
6195 * exception of "all V2 events regardless of level 2 or 4".
6196 **/
Ben Hutchings4e8cff62013-11-18 23:07:16 +00006197static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
Bruce Allanb67e1912012-12-27 08:32:33 +00006198{
6199 struct e1000_adapter *adapter = netdev_priv(netdev);
6200 struct hwtstamp_config config;
6201 int ret_val;
6202
6203 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
6204 return -EFAULT;
6205
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00006206 ret_val = e1000e_config_hwtstamp(adapter, &config);
Bruce Allanb67e1912012-12-27 08:32:33 +00006207 if (ret_val)
6208 return ret_val;
6209
Bruce Alland89777b2013-01-19 01:09:58 +00006210 switch (config.rx_filter) {
6211 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6212 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6213 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6214 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6215 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6216 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
6217 /* With V2 type filters which specify a Sync or Delay Request,
6218 * Path Delay Request/Response messages are also time stamped
6219 * by hardware so notify the caller the requested packets plus
6220 * some others are time stamped.
6221 */
6222 config.rx_filter = HWTSTAMP_FILTER_SOME;
6223 break;
6224 default:
6225 break;
6226 }
6227
Bruce Allanb67e1912012-12-27 08:32:33 +00006228 return copy_to_user(ifr->ifr_data, &config,
6229 sizeof(config)) ? -EFAULT : 0;
6230}
6231
Ben Hutchings4e8cff62013-11-18 23:07:16 +00006232static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
6233{
6234 struct e1000_adapter *adapter = netdev_priv(netdev);
6235
6236 return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
6237 sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
6238}
6239
Auke Kokbc7f75f2007-09-17 12:30:59 -07006240static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6241{
6242 switch (cmd) {
6243 case SIOCGMIIPHY:
6244 case SIOCGMIIREG:
6245 case SIOCSMIIREG:
6246 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00006247 case SIOCSHWTSTAMP:
Ben Hutchings4e8cff62013-11-18 23:07:16 +00006248 return e1000e_hwtstamp_set(netdev, ifr);
6249 case SIOCGHWTSTAMP:
6250 return e1000e_hwtstamp_get(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006251 default:
6252 return -EOPNOTSUPP;
6253 }
6254}
6255
Bruce Allana4f58f52009-06-02 11:29:18 +00006256static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
6257{
6258 struct e1000_hw *hw = &adapter->hw;
David Ertman74f350e2014-02-22 03:15:17 +00006259 u32 i, mac_reg, wuc;
Bruce Allan2b6b1682011-05-13 07:20:09 +00006260 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00006261 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00006262
6263 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00006264 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00006265
Bruce Allan2b6b1682011-05-13 07:20:09 +00006266 retval = hw->phy.ops.acquire(hw);
6267 if (retval) {
6268 e_err("Could not acquire PHY\n");
6269 return retval;
6270 }
6271
6272 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
6273 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
6274 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00006275 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00006276
6277 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00006278 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
6279 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00006280 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
6281 (u16)(mac_reg & 0xFFFF));
6282 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
6283 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00006284 }
6285
6286 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00006287 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00006288 mac_reg = er32(RCTL);
6289 if (mac_reg & E1000_RCTL_UPE)
6290 phy_reg |= BM_RCTL_UPE;
6291 if (mac_reg & E1000_RCTL_MPE)
6292 phy_reg |= BM_RCTL_MPE;
6293 phy_reg &= ~(BM_RCTL_MO_MASK);
6294 if (mac_reg & E1000_RCTL_MO_3)
6295 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
Bruce Allan17e813e2013-02-20 04:06:01 +00006296 << BM_RCTL_MO_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00006297 if (mac_reg & E1000_RCTL_BAM)
6298 phy_reg |= BM_RCTL_BAM;
6299 if (mac_reg & E1000_RCTL_PMCF)
6300 phy_reg |= BM_RCTL_PMCF;
6301 mac_reg = er32(CTRL);
6302 if (mac_reg & E1000_CTRL_RFCE)
6303 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00006304 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00006305
David Ertman74f350e2014-02-22 03:15:17 +00006306 wuc = E1000_WUC_PME_EN;
6307 if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
6308 wuc |= E1000_WUC_APME;
6309
Bruce Allana4f58f52009-06-02 11:29:18 +00006310 /* enable PHY wakeup in MAC register */
6311 ew32(WUFC, wufc);
David Ertman74f350e2014-02-22 03:15:17 +00006312 ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
6313 E1000_WUC_PME_STATUS | wuc));
Bruce Allana4f58f52009-06-02 11:29:18 +00006314
6315 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00006316 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
David Ertman74f350e2014-02-22 03:15:17 +00006317 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
Bruce Allana4f58f52009-06-02 11:29:18 +00006318
6319 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00006320 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
6321 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00006322 if (retval)
6323 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00006324release:
Bruce Allan94d81862009-11-20 23:25:26 +00006325 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00006326
6327 return retval;
6328}
6329
David Ertman2a7e19a2014-07-11 06:21:31 +00006330static void e1000e_flush_lpic(struct pci_dev *pdev)
6331{
6332 struct net_device *netdev = pci_get_drvdata(pdev);
6333 struct e1000_adapter *adapter = netdev_priv(netdev);
6334 struct e1000_hw *hw = &adapter->hw;
6335 u32 ret_val;
6336
6337 pm_runtime_get_sync(netdev->dev.parent);
6338
6339 ret_val = hw->phy.ops.acquire(hw);
6340 if (ret_val)
6341 goto fl_out;
6342
6343 pr_info("EEE TX LPI TIMER: %08X\n",
6344 er32(LPIC) >> E1000_LPIC_LPIET_SHIFT);
6345
6346 hw->phy.ops.release(hw);
6347
6348fl_out:
6349 pm_runtime_put_sync(netdev->dev.parent);
6350}
6351
Sasha Neftin203bddf2019-10-23 18:09:17 +03006352#ifdef CONFIG_PM_SLEEP
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006353/* S0ix implementation */
6354static void e1000e_s0ix_entry_flow(struct e1000_adapter *adapter)
6355{
6356 struct e1000_hw *hw = &adapter->hw;
6357 u32 mac_data;
6358 u16 phy_data;
6359
6360 /* Disable the periodic inband message,
6361 * don't request PCIe clock in K1 page770_17[10:9] = 10b
6362 */
6363 e1e_rphy(hw, HV_PM_CTRL, &phy_data);
6364 phy_data &= ~HV_PM_CTRL_K1_CLK_REQ;
6365 phy_data |= BIT(10);
6366 e1e_wphy(hw, HV_PM_CTRL, phy_data);
6367
6368 /* Make sure we don't exit K1 every time a new packet arrives
6369 * 772_29[5] = 1 CS_Mode_Stay_In_K1
6370 */
6371 e1e_rphy(hw, I217_CGFREG, &phy_data);
6372 phy_data |= BIT(5);
6373 e1e_wphy(hw, I217_CGFREG, phy_data);
6374
6375 /* Change the MAC/PHY interface to SMBus
6376 * Force the SMBus in PHY page769_23[0] = 1
6377 * Force the SMBus in MAC CTRL_EXT[11] = 1
6378 */
6379 e1e_rphy(hw, CV_SMB_CTRL, &phy_data);
6380 phy_data |= CV_SMB_CTRL_FORCE_SMBUS;
6381 e1e_wphy(hw, CV_SMB_CTRL, phy_data);
6382 mac_data = er32(CTRL_EXT);
6383 mac_data |= E1000_CTRL_EXT_FORCE_SMBUS;
6384 ew32(CTRL_EXT, mac_data);
6385
6386 /* DFT control: PHY bit: page769_20[0] = 1
6387 * Gate PPW via EXTCNF_CTRL - set 0x0F00[7] = 1
6388 */
6389 e1e_rphy(hw, I82579_DFT_CTRL, &phy_data);
6390 phy_data |= BIT(0);
6391 e1e_wphy(hw, I82579_DFT_CTRL, phy_data);
6392
6393 mac_data = er32(EXTCNF_CTRL);
6394 mac_data |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
6395 ew32(EXTCNF_CTRL, mac_data);
6396
6397 /* Check MAC Tx/Rx packet buffer pointers.
6398 * Reset MAC Tx/Rx packet buffer pointers to suppress any
6399 * pending traffic indication that would prevent power gating.
6400 */
6401 mac_data = er32(TDFH);
6402 if (mac_data)
6403 ew32(TDFH, 0);
6404 mac_data = er32(TDFT);
6405 if (mac_data)
6406 ew32(TDFT, 0);
6407 mac_data = er32(TDFHS);
6408 if (mac_data)
6409 ew32(TDFHS, 0);
6410 mac_data = er32(TDFTS);
6411 if (mac_data)
6412 ew32(TDFTS, 0);
6413 mac_data = er32(TDFPC);
6414 if (mac_data)
6415 ew32(TDFPC, 0);
6416 mac_data = er32(RDFH);
6417 if (mac_data)
6418 ew32(RDFH, 0);
6419 mac_data = er32(RDFT);
6420 if (mac_data)
6421 ew32(RDFT, 0);
6422 mac_data = er32(RDFHS);
6423 if (mac_data)
6424 ew32(RDFHS, 0);
6425 mac_data = er32(RDFTS);
6426 if (mac_data)
6427 ew32(RDFTS, 0);
6428 mac_data = er32(RDFPC);
6429 if (mac_data)
6430 ew32(RDFPC, 0);
6431
6432 /* Enable the Dynamic Power Gating in the MAC */
6433 mac_data = er32(FEXTNVM7);
6434 mac_data |= BIT(22);
6435 ew32(FEXTNVM7, mac_data);
6436
6437 /* Disable the time synchronization clock */
6438 mac_data = er32(FEXTNVM7);
6439 mac_data |= BIT(31);
6440 mac_data &= ~BIT(0);
6441 ew32(FEXTNVM7, mac_data);
6442
6443 /* Dynamic Power Gating Enable */
6444 mac_data = er32(CTRL_EXT);
6445 mac_data |= BIT(3);
6446 ew32(CTRL_EXT, mac_data);
6447
Vitaly Lifshits632fbd52020-03-12 13:57:07 +02006448 /* Disable disconnected cable conditioning for Power Gating */
6449 mac_data = er32(DPGFR);
6450 mac_data |= BIT(2);
6451 ew32(DPGFR, mac_data);
6452
6453 /* Don't wake from dynamic Power Gating with clock request */
6454 mac_data = er32(FEXTNVM12);
6455 mac_data |= BIT(12);
6456 ew32(FEXTNVM12, mac_data);
6457
6458 /* Ungate PGCB clock */
6459 mac_data = er32(FEXTNVM9);
6460 mac_data |= BIT(28);
6461 ew32(FEXTNVM9, mac_data);
6462
6463 /* Enable K1 off to enable mPHY Power Gating */
6464 mac_data = er32(FEXTNVM6);
6465 mac_data |= BIT(31);
6466 ew32(FEXTNVM12, mac_data);
6467
6468 /* Enable mPHY power gating for any link and speed */
6469 mac_data = er32(FEXTNVM8);
6470 mac_data |= BIT(9);
6471 ew32(FEXTNVM8, mac_data);
6472
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006473 /* Enable the Dynamic Clock Gating in the DMA and MAC */
6474 mac_data = er32(CTRL_EXT);
6475 mac_data |= E1000_CTRL_EXT_DMA_DYN_CLK_EN;
6476 ew32(CTRL_EXT, mac_data);
6477
6478 /* No MAC DPG gating SLP_S0 in modern standby
6479 * Switch the logic of the lanphypc to use PMC counter
6480 */
6481 mac_data = er32(FEXTNVM5);
6482 mac_data |= BIT(7);
6483 ew32(FEXTNVM5, mac_data);
6484}
6485
6486static void e1000e_s0ix_exit_flow(struct e1000_adapter *adapter)
6487{
6488 struct e1000_hw *hw = &adapter->hw;
6489 u32 mac_data;
6490 u16 phy_data;
6491
6492 /* Disable the Dynamic Power Gating in the MAC */
6493 mac_data = er32(FEXTNVM7);
6494 mac_data &= 0xFFBFFFFF;
6495 ew32(FEXTNVM7, mac_data);
6496
6497 /* Enable the time synchronization clock */
6498 mac_data = er32(FEXTNVM7);
6499 mac_data |= BIT(0);
6500 ew32(FEXTNVM7, mac_data);
6501
Vitaly Lifshits632fbd52020-03-12 13:57:07 +02006502 /* Disable mPHY power gating for any link and speed */
6503 mac_data = er32(FEXTNVM8);
6504 mac_data &= ~BIT(9);
6505 ew32(FEXTNVM8, mac_data);
6506
6507 /* Disable K1 off */
6508 mac_data = er32(FEXTNVM6);
6509 mac_data &= ~BIT(31);
6510 ew32(FEXTNVM12, mac_data);
6511
6512 /* Disable Ungate PGCB clock */
6513 mac_data = er32(FEXTNVM9);
6514 mac_data &= ~BIT(28);
6515 ew32(FEXTNVM9, mac_data);
6516
6517 /* Cancel not waking from dynamic
6518 * Power Gating with clock request
6519 */
6520 mac_data = er32(FEXTNVM12);
6521 mac_data &= ~BIT(12);
6522 ew32(FEXTNVM12, mac_data);
6523
6524 /* Cancel disable disconnected cable conditioning
6525 * for Power Gating
6526 */
6527 mac_data = er32(DPGFR);
6528 mac_data &= ~BIT(2);
6529 ew32(DPGFR, mac_data);
6530
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006531 /* Disable Dynamic Power Gating */
6532 mac_data = er32(CTRL_EXT);
6533 mac_data &= 0xFFFFFFF7;
6534 ew32(CTRL_EXT, mac_data);
6535
6536 /* Disable the Dynamic Clock Gating in the DMA and MAC */
6537 mac_data = er32(CTRL_EXT);
6538 mac_data &= 0xFFF7FFFF;
6539 ew32(CTRL_EXT, mac_data);
6540
6541 /* Revert the lanphypc logic to use the internal Gbe counter
6542 * and not the PMC counter
6543 */
6544 mac_data = er32(FEXTNVM5);
6545 mac_data &= 0xFFFFFF7F;
6546 ew32(FEXTNVM5, mac_data);
6547
6548 /* Enable the periodic inband message,
6549 * Request PCIe clock in K1 page770_17[10:9] =01b
6550 */
6551 e1e_rphy(hw, HV_PM_CTRL, &phy_data);
6552 phy_data &= 0xFBFF;
6553 phy_data |= HV_PM_CTRL_K1_CLK_REQ;
6554 e1e_wphy(hw, HV_PM_CTRL, phy_data);
6555
6556 /* Return back configuration
6557 * 772_29[5] = 0 CS_Mode_Stay_In_K1
6558 */
6559 e1e_rphy(hw, I217_CGFREG, &phy_data);
6560 phy_data &= 0xFFDF;
6561 e1e_wphy(hw, I217_CGFREG, phy_data);
6562
6563 /* Change the MAC/PHY interface to Kumeran
6564 * Unforce the SMBus in PHY page769_23[0] = 0
6565 * Unforce the SMBus in MAC CTRL_EXT[11] = 0
6566 */
6567 e1e_rphy(hw, CV_SMB_CTRL, &phy_data);
6568 phy_data &= ~CV_SMB_CTRL_FORCE_SMBUS;
6569 e1e_wphy(hw, CV_SMB_CTRL, phy_data);
6570 mac_data = er32(CTRL_EXT);
6571 mac_data &= ~E1000_CTRL_EXT_FORCE_SMBUS;
6572 ew32(CTRL_EXT, mac_data);
6573}
Sasha Neftin203bddf2019-10-23 18:09:17 +03006574#endif /* CONFIG_PM_SLEEP */
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006575
David Ertman28002092014-02-14 07:16:41 +00006576static int e1000e_pm_freeze(struct device *dev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006577{
Chuhong Yuanee2e80c2019-07-23 22:15:13 +08006578 struct net_device *netdev = dev_get_drvdata(dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006579 struct e1000_adapter *adapter = netdev_priv(netdev);
Alexander Duycka7023812019-10-11 08:34:52 -07006580 bool present;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006581
Alexander Duycka7023812019-10-11 08:34:52 -07006582 rtnl_lock();
6583
6584 present = netif_device_present(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006585 netif_device_detach(netdev);
6586
Alexander Duycka7023812019-10-11 08:34:52 -07006587 if (present && netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00006588 int count = E1000_CHECK_RESET_COUNT;
6589
6590 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
Arjan van de Venab6973a2019-06-14 17:29:35 -07006591 usleep_range(10000, 11000);
Bruce Allanbb9e44d2012-03-21 00:39:12 +00006592
Auke Kokbc7f75f2007-09-17 12:30:59 -07006593 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
David Ertman28002092014-02-14 07:16:41 +00006594
6595 /* Quiesce the device without resetting the hardware */
6596 e1000e_down(adapter, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006597 e1000_free_irq(adapter);
6598 }
Alexander Duycka7023812019-10-11 08:34:52 -07006599 rtnl_unlock();
6600
Jeff Kirsher9f47a482017-03-23 20:47:15 -07006601 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006602
David Ertman28002092014-02-14 07:16:41 +00006603 /* Allow time for pending master requests to run */
6604 e1000e_disable_pcie_master(&adapter->hw);
6605
6606 return 0;
6607}
6608
6609static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
6610{
6611 struct net_device *netdev = pci_get_drvdata(pdev);
6612 struct e1000_adapter *adapter = netdev_priv(netdev);
6613 struct e1000_hw *hw = &adapter->hw;
Chen Yu6bf6be12020-05-22 01:59:00 +08006614 u32 ctrl, ctrl_ext, rctl, status, wufc;
David Ertman28002092014-02-14 07:16:41 +00006615 int retval = 0;
6616
Chen Yu6bf6be12020-05-22 01:59:00 +08006617 /* Runtime suspend should only enable wakeup for link changes */
6618 if (runtime)
6619 wufc = E1000_WUFC_LNKC;
6620 else if (device_may_wakeup(&pdev->dev))
6621 wufc = adapter->wol;
6622 else
6623 wufc = 0;
6624
Auke Kokbc7f75f2007-09-17 12:30:59 -07006625 status = er32(STATUS);
6626 if (status & E1000_STATUS_LU)
6627 wufc &= ~E1000_WUFC_LNKC;
6628
6629 if (wufc) {
6630 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006631 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006632
6633 /* turn on all-multi mode if wake on multicast is enabled */
6634 if (wufc & E1000_WUFC_MC) {
6635 rctl = er32(RCTL);
6636 rctl |= E1000_RCTL_MPE;
6637 ew32(RCTL, rctl);
6638 }
6639
6640 ctrl = er32(CTRL);
Bruce Allana4f58f52009-06-02 11:29:18 +00006641 ctrl |= E1000_CTRL_ADVD3WUC;
6642 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
6643 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006644 ew32(CTRL, ctrl);
6645
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006646 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
6647 adapter->hw.phy.media_type ==
6648 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006649 /* keep the laser running in D3 */
6650 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00006651 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006652 ew32(CTRL_EXT, ctrl_ext);
6653 }
6654
David Ertman63eb48f2014-02-14 07:16:46 +00006655 if (!runtime)
6656 e1000e_power_up_phy(adapter);
6657
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006658 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00006659 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006660
Bruce Allan82776a42009-08-14 14:35:33 +00006661 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00006662 /* enable wakeup by the PHY */
6663 retval = e1000_init_phy_wakeup(adapter, wufc);
6664 if (retval)
6665 return retval;
6666 } else {
6667 /* enable wakeup by the MAC */
6668 ew32(WUFC, wufc);
6669 ew32(WUC, E1000_WUC_PME_EN);
6670 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006671 } else {
6672 ew32(WUC, 0);
6673 ew32(WUFC, 0);
David Ertman28002092014-02-14 07:16:41 +00006674
6675 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006676 }
6677
David Ertman74f350e2014-02-22 03:15:17 +00006678 if (adapter->hw.phy.type == e1000_phy_igp_3) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006679 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
Sasha Neftinc8744f42017-04-06 10:26:47 +03006680 } else if (hw->mac.type >= e1000_pch_lpt) {
Chen Yu6bf6be12020-05-22 01:59:00 +08006681 if (wufc && !(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
David Ertman74f350e2014-02-22 03:15:17 +00006682 /* ULP does not support wake from unicast, multicast
6683 * or broadcast.
6684 */
6685 retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
6686
6687 if (retval)
6688 return retval;
6689 }
6690
Raanan Avargilf5ac7442015-07-06 16:48:00 +03006691 /* Ensure that the appropriate bits are set in LPI_CTRL
6692 * for EEE in Sx
6693 */
6694 if ((hw->phy.type >= e1000_phy_i217) &&
6695 adapter->eee_advert && hw->dev_spec.ich8lan.eee_lp_ability) {
6696 u16 lpi_ctrl = 0;
6697
6698 retval = hw->phy.ops.acquire(hw);
6699 if (!retval) {
6700 retval = e1e_rphy_locked(hw, I82579_LPI_CTRL,
6701 &lpi_ctrl);
6702 if (!retval) {
6703 if (adapter->eee_advert &
6704 hw->dev_spec.ich8lan.eee_lp_ability &
6705 I82579_EEE_100_SUPPORTED)
6706 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
6707 if (adapter->eee_advert &
6708 hw->dev_spec.ich8lan.eee_lp_ability &
6709 I82579_EEE_1000_SUPPORTED)
6710 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
6711
6712 retval = e1e_wphy_locked(hw, I82579_LPI_CTRL,
6713 lpi_ctrl);
6714 }
6715 }
6716 hw->phy.ops.release(hw);
6717 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006718
Bruce Allane921eb12012-11-28 09:28:37 +00006719 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006720 * would have already happened in close and is redundant.
6721 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006722 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006723
Dean Nelson24b41c92013-06-13 03:55:44 +00006724 pci_clear_master(pdev);
6725
Bruce Allane921eb12012-11-28 09:28:37 +00006726 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006727 * correctable error when the MAC transitions from D0 to D3. To
6728 * prevent this we need to mask off the correctable errors on the
6729 * downstream port of the pci-e switch.
Li Zhange8c254c2013-08-13 18:42:58 +00006730 *
6731 * We don't have the associated upstream bridge while assigning
6732 * the PCI device into guest. For example, the KVM on power is
6733 * one of the cases.
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006734 */
6735 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6736 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006737 u16 devctl;
6738
Li Zhange8c254c2013-08-13 18:42:58 +00006739 if (!us_dev)
6740 return 0;
6741
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006742 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6743 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6744 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006745
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006746 pci_save_state(pdev);
6747 pci_prepare_to_sleep(pdev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006748
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006749 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006750 }
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006751
6752 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006753}
6754
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006755/**
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006756 * __e1000e_disable_aspm - Disable ASPM states
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006757 * @pdev: pointer to PCI device struct
6758 * @state: bit-mask of ASPM states to disable
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006759 * @locked: indication if this context holds pci_bus_sem locked.
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006760 *
6761 * Some devices *must* have certain ASPM states disabled per hardware errata.
6762 **/
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006763static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state, int locked)
Bruce Allan6f461f62010-04-27 03:33:04 +00006764{
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006765 struct pci_dev *parent = pdev->bus->self;
6766 u16 aspm_dis_mask = 0;
6767 u16 pdev_aspmc, parent_aspmc;
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006768
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006769 switch (state) {
6770 case PCIE_LINK_STATE_L0S:
6771 case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
6772 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
6773 /* fall-through - can't have L1 without L0s */
6774 case PCIE_LINK_STATE_L1:
6775 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
6776 break;
6777 default:
6778 return;
6779 }
6780
6781 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6782 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6783
6784 if (parent) {
6785 pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
6786 &parent_aspmc);
6787 parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6788 }
6789
6790 /* Nothing to do if the ASPM states to be disabled already are */
6791 if (!(pdev_aspmc & aspm_dis_mask) &&
6792 (!parent || !(parent_aspmc & aspm_dis_mask)))
6793 return;
6794
6795 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6796 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
6797 "L0s" : "",
6798 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
6799 "L1" : "");
6800
6801#ifdef CONFIG_PCIEASPM
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006802 if (locked)
6803 pci_disable_link_state_locked(pdev, state);
6804 else
6805 pci_disable_link_state(pdev, state);
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006806
6807 /* Double-check ASPM control. If not disabled by the above, the
6808 * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
6809 * not enabled); override by writing PCI config space directly.
6810 */
6811 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6812 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6813
6814 if (!(aspm_dis_mask & pdev_aspmc))
6815 return;
6816#endif
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006817
Bruce Allane921eb12012-11-28 09:28:37 +00006818 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006819 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006820 */
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006821 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
Bruce Allan6f461f62010-04-27 03:33:04 +00006822
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006823 if (parent)
6824 pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
6825 aspm_dis_mask);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006826}
6827
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006828/**
6829 * e1000e_disable_aspm - Disable ASPM states.
6830 * @pdev: pointer to PCI device struct
6831 * @state: bit-mask of ASPM states to disable
6832 *
6833 * This function acquires the pci_bus_sem!
6834 * Some devices *must* have certain ASPM states disabled per hardware errata.
6835 **/
6836static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6837{
6838 __e1000e_disable_aspm(pdev, state, 0);
6839}
6840
6841/**
6842 * e1000e_disable_aspm_locked Disable ASPM states.
6843 * @pdev: pointer to PCI device struct
6844 * @state: bit-mask of ASPM states to disable
6845 *
6846 * This function must be called with pci_bus_sem acquired!
6847 * Some devices *must* have certain ASPM states disabled per hardware errata.
6848 **/
6849static void e1000e_disable_aspm_locked(struct pci_dev *pdev, u16 state)
6850{
6851 __e1000e_disable_aspm(pdev, state, 1);
6852}
6853
Alexander Duycka7023812019-10-11 08:34:52 -07006854static int e1000e_pm_thaw(struct device *dev)
6855{
6856 struct net_device *netdev = dev_get_drvdata(dev);
6857 struct e1000_adapter *adapter = netdev_priv(netdev);
6858 int rc = 0;
6859
6860 e1000e_set_interrupt_capability(adapter);
6861
6862 rtnl_lock();
6863 if (netif_running(netdev)) {
6864 rc = e1000_request_irq(adapter);
6865 if (rc)
6866 goto err_irq;
6867
6868 e1000e_up(adapter);
6869 }
6870
6871 netif_device_attach(netdev);
6872err_irq:
6873 rtnl_unlock();
6874
6875 return rc;
6876}
6877
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006878#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006879static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006880{
6881 struct net_device *netdev = pci_get_drvdata(pdev);
6882 struct e1000_adapter *adapter = netdev_priv(netdev);
6883 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006884 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006885
Bruce Allan78cd29d2011-03-24 03:09:03 +00006886 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6887 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6888 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6889 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6890 if (aspm_disable_flag)
Raanan Avargil2758f9e2015-07-06 17:57:36 +03006891 e1000e_disable_aspm(pdev, aspm_disable_flag);
Bruce Allan78cd29d2011-03-24 03:09:03 +00006892
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006893 pci_set_master(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006894
Bruce Allan2fbe4522012-04-19 03:21:47 +00006895 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006896 e1000_resume_workarounds_pchlan(&adapter->hw);
6897
Auke Kokbc7f75f2007-09-17 12:30:59 -07006898 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006899
6900 /* report the system wakeup cause from S3/S4 */
6901 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6902 u16 phy_data;
6903
6904 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6905 if (phy_data) {
6906 e_info("PHY Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006907 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6908 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6909 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6910 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6911 phy_data & E1000_WUS_LNKC ?
6912 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006913 }
6914 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6915 } else {
6916 u32 wus = er32(WUS);
David Ertman6cf08d12014-04-05 06:07:00 +00006917
Bruce Allana4f58f52009-06-02 11:29:18 +00006918 if (wus) {
6919 e_info("MAC Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006920 wus & E1000_WUS_EX ? "Unicast Packet" :
6921 wus & E1000_WUS_MC ? "Multicast Packet" :
6922 wus & E1000_WUS_BC ? "Broadcast Packet" :
6923 wus & E1000_WUS_MAG ? "Magic Packet" :
6924 wus & E1000_WUS_LNKC ? "Link Status Change" :
6925 "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006926 }
6927 ew32(WUS, ~0);
6928 }
6929
Auke Kokbc7f75f2007-09-17 12:30:59 -07006930 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006931
Bruce Allancd791612010-05-10 14:59:51 +00006932 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006933
Bruce Allane921eb12012-11-28 09:28:37 +00006934 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006935 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006936 * under the control of the driver.
6937 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006938 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006939 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006940
6941 return 0;
6942}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006943
Hiroaki SHIMODA3e7986f2014-04-15 08:20:19 +00006944#ifdef CONFIG_PM_SLEEP
David Ertman28002092014-02-14 07:16:41 +00006945static int e1000e_pm_suspend(struct device *dev)
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006946{
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006947 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
6948 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006949 struct pci_dev *pdev = to_pci_dev(dev);
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006950 struct e1000_hw *hw = &adapter->hw;
Chris Wilson833521e2017-05-31 18:50:43 +03006951 int rc;
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006952
David Ertman2a7e19a2014-07-11 06:21:31 +00006953 e1000e_flush_lpic(pdev);
6954
David Ertman28002092014-02-14 07:16:41 +00006955 e1000e_pm_freeze(dev);
6956
Chris Wilson833521e2017-05-31 18:50:43 +03006957 rc = __e1000_shutdown(pdev, false);
6958 if (rc)
6959 e1000e_pm_thaw(dev);
6960
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006961 /* Introduce S0ix implementation */
Vitaly Lifshitse086ba22020-05-07 20:14:06 +03006962 if (hw->mac.type >= e1000_pch_cnp &&
6963 !e1000e_check_me(hw->adapter->pdev->device))
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006964 e1000e_s0ix_entry_flow(adapter);
6965
Chris Wilson833521e2017-05-31 18:50:43 +03006966 return rc;
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006967}
6968
David Ertman28002092014-02-14 07:16:41 +00006969static int e1000e_pm_resume(struct device *dev)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006970{
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006971 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
6972 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006973 struct pci_dev *pdev = to_pci_dev(dev);
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006974 struct e1000_hw *hw = &adapter->hw;
David Ertman28002092014-02-14 07:16:41 +00006975 int rc;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006976
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006977 /* Introduce S0ix implementation */
Vitaly Lifshitse086ba22020-05-07 20:14:06 +03006978 if (hw->mac.type >= e1000_pch_cnp &&
6979 !e1000e_check_me(hw->adapter->pdev->device))
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006980 e1000e_s0ix_exit_flow(adapter);
6981
David Ertman28002092014-02-14 07:16:41 +00006982 rc = __e1000_resume(pdev);
6983 if (rc)
6984 return rc;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006985
David Ertman28002092014-02-14 07:16:41 +00006986 return e1000e_pm_thaw(dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006987}
Mika Westerberg38a529b2014-01-16 14:39:39 +02006988#endif /* CONFIG_PM_SLEEP */
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006989
David Ertman63eb48f2014-02-14 07:16:46 +00006990static int e1000e_pm_runtime_idle(struct device *dev)
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006991{
Chuhong Yuanee2e80c2019-07-23 22:15:13 +08006992 struct net_device *netdev = dev_get_drvdata(dev);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006993 struct e1000_adapter *adapter = netdev_priv(netdev);
David Ertman2116bc252014-07-11 06:21:23 +00006994 u16 eee_lp;
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006995
David Ertman2116bc252014-07-11 06:21:23 +00006996 eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability;
6997
6998 if (!e1000e_has_link(adapter)) {
6999 adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp;
David Ertman63eb48f2014-02-14 07:16:46 +00007000 pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
David Ertman2116bc252014-07-11 06:21:23 +00007001 }
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007002
7003 return -EBUSY;
7004}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007005
David Ertman63eb48f2014-02-14 07:16:46 +00007006static int e1000e_pm_runtime_resume(struct device *dev)
7007{
7008 struct pci_dev *pdev = to_pci_dev(dev);
7009 struct net_device *netdev = pci_get_drvdata(pdev);
7010 struct e1000_adapter *adapter = netdev_priv(netdev);
7011 int rc;
7012
7013 rc = __e1000_resume(pdev);
7014 if (rc)
7015 return rc;
7016
7017 if (netdev->flags & IFF_UP)
Alexander Duyck386164d2015-10-27 16:59:31 -07007018 e1000e_up(adapter);
David Ertman63eb48f2014-02-14 07:16:46 +00007019
7020 return rc;
7021}
7022
7023static int e1000e_pm_runtime_suspend(struct device *dev)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007024{
7025 struct pci_dev *pdev = to_pci_dev(dev);
7026 struct net_device *netdev = pci_get_drvdata(pdev);
7027 struct e1000_adapter *adapter = netdev_priv(netdev);
7028
David Ertman63eb48f2014-02-14 07:16:46 +00007029 if (netdev->flags & IFF_UP) {
7030 int count = E1000_CHECK_RESET_COUNT;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007031
David Ertman63eb48f2014-02-14 07:16:46 +00007032 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
Arjan van de Venab6973a2019-06-14 17:29:35 -07007033 usleep_range(10000, 11000);
David Ertman63eb48f2014-02-14 07:16:46 +00007034
7035 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
7036
7037 /* Down the device without resetting the hardware */
7038 e1000e_down(adapter, false);
7039 }
7040
7041 if (__e1000_shutdown(pdev, true)) {
7042 e1000e_pm_runtime_resume(dev);
7043 return -EBUSY;
7044 }
7045
7046 return 0;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007047}
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007048#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007049
7050static void e1000_shutdown(struct pci_dev *pdev)
7051{
David Ertman2a7e19a2014-07-11 06:21:31 +00007052 e1000e_flush_lpic(pdev);
7053
David Ertman28002092014-02-14 07:16:41 +00007054 e1000e_pm_freeze(&pdev->dev);
7055
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00007056 __e1000_shutdown(pdev, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007057}
7058
7059#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08007060
Bruce Allan8bb62862013-01-16 08:46:49 +00007061static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08007062{
7063 struct net_device *netdev = data;
7064 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007065
7066 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00007067 int vector, msix_irq;
7068
Dongdong Deng147b2c82010-11-16 19:50:15 -08007069 vector = 0;
7070 msix_irq = adapter->msix_entries[vector].vector;
Konstantin Khlebnikovfd8e5972017-05-19 10:18:49 +03007071 if (disable_hardirq(msix_irq))
7072 e1000_intr_msix_rx(msix_irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007073 enable_irq(msix_irq);
7074
7075 vector++;
7076 msix_irq = adapter->msix_entries[vector].vector;
Konstantin Khlebnikovfd8e5972017-05-19 10:18:49 +03007077 if (disable_hardirq(msix_irq))
7078 e1000_intr_msix_tx(msix_irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007079 enable_irq(msix_irq);
7080
7081 vector++;
7082 msix_irq = adapter->msix_entries[vector].vector;
Konstantin Khlebnikovfd8e5972017-05-19 10:18:49 +03007083 if (disable_hardirq(msix_irq))
7084 e1000_msix_other(msix_irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007085 enable_irq(msix_irq);
7086 }
7087
7088 return IRQ_HANDLED;
7089}
7090
Bruce Allane921eb12012-11-28 09:28:37 +00007091/**
7092 * e1000_netpoll
7093 * @netdev: network interface device structure
7094 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07007095 * Polling 'interrupt' - used by things like netconsole to send skbs
7096 * without having to re-enable interrupts. It's not called while
7097 * the interrupt routine is executing.
7098 */
7099static void e1000_netpoll(struct net_device *netdev)
7100{
7101 struct e1000_adapter *adapter = netdev_priv(netdev);
7102
Dongdong Deng147b2c82010-11-16 19:50:15 -08007103 switch (adapter->int_mode) {
7104 case E1000E_INT_MODE_MSIX:
7105 e1000_intr_msix(adapter->pdev->irq, netdev);
7106 break;
7107 case E1000E_INT_MODE_MSI:
WANG Cong31119122016-12-10 14:22:42 -08007108 if (disable_hardirq(adapter->pdev->irq))
7109 e1000_intr_msi(adapter->pdev->irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007110 enable_irq(adapter->pdev->irq);
7111 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00007112 default: /* E1000E_INT_MODE_LEGACY */
WANG Cong31119122016-12-10 14:22:42 -08007113 if (disable_hardirq(adapter->pdev->irq))
7114 e1000_intr(adapter->pdev->irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007115 enable_irq(adapter->pdev->irq);
7116 break;
7117 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07007118}
7119#endif
7120
7121/**
7122 * e1000_io_error_detected - called when PCI error is detected
7123 * @pdev: Pointer to PCI device
7124 * @state: The current pci connection state
7125 *
7126 * This function is called after a PCI bus error affecting
7127 * this device has been detected.
7128 */
7129static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
7130 pci_channel_state_t state)
7131{
Alexander Duycka7023812019-10-11 08:34:52 -07007132 e1000e_pm_freeze(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007133
Mike Masonc93b5a72009-06-30 12:45:53 +00007134 if (state == pci_channel_io_perm_failure)
7135 return PCI_ERS_RESULT_DISCONNECT;
7136
Auke Kokbc7f75f2007-09-17 12:30:59 -07007137 pci_disable_device(pdev);
7138
7139 /* Request a slot slot reset. */
7140 return PCI_ERS_RESULT_NEED_RESET;
7141}
7142
7143/**
7144 * e1000_io_slot_reset - called after the pci bus has been reset.
7145 * @pdev: Pointer to PCI device
7146 *
7147 * Restart the card from scratch, as if from a cold-boot. Implementation
David Ertman28002092014-02-14 07:16:41 +00007148 * resembles the first-half of the e1000e_pm_resume routine.
Auke Kokbc7f75f2007-09-17 12:30:59 -07007149 */
7150static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
7151{
7152 struct net_device *netdev = pci_get_drvdata(pdev);
7153 struct e1000_adapter *adapter = netdev_priv(netdev);
7154 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00007155 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09007156 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007157 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007158
Bruce Allan78cd29d2011-03-24 03:09:03 +00007159 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
7160 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00007161 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00007162 aspm_disable_flag |= PCIE_LINK_STATE_L1;
7163 if (aspm_disable_flag)
Raanan Avargil2758f9e2015-07-06 17:57:36 +03007164 e1000e_disable_aspm_locked(pdev, aspm_disable_flag);
Bruce Allan78cd29d2011-03-24 03:09:03 +00007165
Bruce Allanf0f422e2008-08-04 17:21:53 -07007166 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09007167 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007168 dev_err(&pdev->dev,
7169 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007170 result = PCI_ERS_RESULT_DISCONNECT;
7171 } else {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007172 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007173 pci_restore_state(pdev);
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00007174 pci_set_master(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007175
7176 pci_enable_wake(pdev, PCI_D3hot, 0);
7177 pci_enable_wake(pdev, PCI_D3cold, 0);
7178
7179 e1000e_reset(adapter);
7180 ew32(WUS, ~0);
7181 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007182 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07007183
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007184 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007185}
7186
7187/**
7188 * e1000_io_resume - called when traffic can start flowing again.
7189 * @pdev: Pointer to PCI device
7190 *
7191 * This callback is called when the error recovery driver tells us that
7192 * its OK to resume normal operation. Implementation resembles the
David Ertman28002092014-02-14 07:16:41 +00007193 * second-half of the e1000e_pm_resume routine.
Auke Kokbc7f75f2007-09-17 12:30:59 -07007194 */
7195static void e1000_io_resume(struct pci_dev *pdev)
7196{
7197 struct net_device *netdev = pci_get_drvdata(pdev);
7198 struct e1000_adapter *adapter = netdev_priv(netdev);
7199
Bruce Allancd791612010-05-10 14:59:51 +00007200 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007201
Alexander Duycka7023812019-10-11 08:34:52 -07007202 e1000e_pm_thaw(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007203
Bruce Allane921eb12012-11-28 09:28:37 +00007204 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07007205 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07007206 * under the control of the driver.
7207 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007208 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00007209 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007210}
7211
7212static void e1000_print_device_info(struct e1000_adapter *adapter)
7213{
7214 struct e1000_hw *hw = &adapter->hw;
7215 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00007216 u32 ret_val;
7217 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07007218
7219 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00007220 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07007221 /* bus width */
7222 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
Bruce Allanf0ff4392013-02-20 04:05:39 +00007223 "Width x1"),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07007224 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07007225 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07007226 e_info("Intel(R) PRO/%s Network Connection\n",
7227 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00007228 ret_val = e1000_read_pba_string_generic(hw, pba_str,
7229 E1000_PBANUM_LENGTH);
7230 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00007231 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00007232 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
7233 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007234}
7235
Auke Kok10aa4c02008-08-04 17:21:20 -07007236static void e1000_eeprom_checks(struct e1000_adapter *adapter)
7237{
7238 struct e1000_hw *hw = &adapter->hw;
7239 int ret_val;
7240 u16 buf = 0;
7241
7242 if (hw->mac.type != e1000_82573)
7243 return;
7244
7245 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00007246 le16_to_cpus(&buf);
Jacob Keller18dd2392016-04-13 16:08:32 -07007247 if (!ret_val && (!(buf & BIT(0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07007248 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07007249 dev_warn(&adapter->pdev->dev,
7250 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07007251 }
Auke Kok10aa4c02008-08-04 17:21:20 -07007252}
7253
Alexander Duyck55e7fe52015-05-02 01:09:59 -07007254static netdev_features_t e1000_fix_features(struct net_device *netdev,
7255 netdev_features_t features)
7256{
7257 struct e1000_adapter *adapter = netdev_priv(netdev);
7258 struct e1000_hw *hw = &adapter->hw;
7259
7260 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
7261 if ((hw->mac.type >= e1000_pch2lan) && (netdev->mtu > ETH_DATA_LEN))
7262 features &= ~NETIF_F_RXFCS;
7263
Jarod Wilson83808642016-06-09 19:50:13 -04007264 /* Since there is no support for separate Rx/Tx vlan accel
7265 * enable/disable make sure Tx flag is always in same state as Rx.
7266 */
7267 if (features & NETIF_F_HW_VLAN_CTAG_RX)
7268 features |= NETIF_F_HW_VLAN_CTAG_TX;
7269 else
7270 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
7271
Alexander Duyck55e7fe52015-05-02 01:09:59 -07007272 return features;
7273}
7274
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007275static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00007276 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00007277{
7278 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007279 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00007280
7281 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
7282 adapter->flags |= FLAG_TSO_FORCE;
7283
Patrick McHardyf6469682013-04-19 02:04:27 +00007284 if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00007285 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
7286 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00007287 return 0;
7288
Ben Greear01840392012-02-11 15:39:25 +00007289 if (changed & NETIF_F_RXFCS) {
7290 if (features & NETIF_F_RXFCS) {
7291 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
7292 } else {
7293 /* We need to take it back to defaults, which might mean
7294 * stripping is still disabled at the adapter level.
7295 */
7296 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
7297 adapter->flags2 |= FLAG2_CRC_STRIPPING;
7298 else
7299 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
7300 }
7301 }
7302
Bruce Allan70495a52012-01-11 01:26:50 +00007303 netdev->features = features;
7304
Bruce Allandc221292011-08-19 03:23:48 +00007305 if (netif_running(netdev))
7306 e1000e_reinit_locked(adapter);
7307 else
7308 e1000e_reset(adapter);
7309
Serhey Popovychb0ddfe22018-03-29 17:51:36 +03007310 return 1;
Bruce Allandc221292011-08-19 03:23:48 +00007311}
7312
Stephen Hemminger651c2462008-11-19 21:57:48 -08007313static const struct net_device_ops e1000e_netdev_ops = {
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01007314 .ndo_open = e1000e_open,
7315 .ndo_stop = e1000e_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007316 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00007317 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00007318 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08007319 .ndo_set_mac_address = e1000_set_mac,
7320 .ndo_change_mtu = e1000_change_mtu,
7321 .ndo_do_ioctl = e1000_ioctl,
7322 .ndo_tx_timeout = e1000_tx_timeout,
7323 .ndo_validate_addr = eth_validate_addr,
7324
Stephen Hemminger651c2462008-11-19 21:57:48 -08007325 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
7326 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
7327#ifdef CONFIG_NET_POLL_CONTROLLER
7328 .ndo_poll_controller = e1000_netpoll,
7329#endif
Bruce Allandc221292011-08-19 03:23:48 +00007330 .ndo_set_features = e1000_set_features,
Alexander Duyck55e7fe52015-05-02 01:09:59 -07007331 .ndo_fix_features = e1000_fix_features,
Toshiaki Makitaf2701b12015-08-06 17:57:29 +09007332 .ndo_features_check = passthru_features_check,
Stephen Hemminger651c2462008-11-19 21:57:48 -08007333};
7334
Auke Kokbc7f75f2007-09-17 12:30:59 -07007335/**
7336 * e1000_probe - Device Initialization Routine
7337 * @pdev: PCI device information struct
7338 * @ent: entry in e1000_pci_tbl
7339 *
7340 * Returns 0 on success, negative on failure
7341 *
7342 * e1000_probe initializes an adapter identified by a pci_dev structure.
7343 * The OS initialization, configuring of the adapter private structure,
7344 * and a hardware reset occur.
7345 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00007346static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07007347{
7348 struct net_device *netdev;
7349 struct e1000_adapter *adapter;
7350 struct e1000_hw *hw;
7351 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05007352 resource_size_t mmio_start, mmio_len;
7353 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007354 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00007355 u16 aspm_disable_flag = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00007356 int bars, i, err, pci_using_dac;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007357 u16 eeprom_data = 0;
7358 u16 eeprom_apme_mask = E1000_EEPROM_APME;
Brian Walsh847042a2016-04-12 23:22:30 -04007359 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007360
Bruce Allan78cd29d2011-03-24 03:09:03 +00007361 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
7362 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00007363 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00007364 aspm_disable_flag |= PCIE_LINK_STATE_L1;
7365 if (aspm_disable_flag)
7366 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09007367
Bruce Allanf0f422e2008-08-04 17:21:53 -07007368 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007369 if (err)
7370 return err;
7371
7372 pci_using_dac = 0;
Russell King718a39e2013-06-10 12:22:30 +01007373 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07007374 if (!err) {
Russell King718a39e2013-06-10 12:22:30 +01007375 pci_using_dac = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007376 } else {
Russell King718a39e2013-06-10 12:22:30 +01007377 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07007378 if (err) {
Russell King718a39e2013-06-10 12:22:30 +01007379 dev_err(&pdev->dev,
7380 "No usable DMA configuration, aborting\n");
7381 goto err_dma;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007382 }
7383 }
7384
Bruce Allan17e813e2013-02-20 04:06:01 +00007385 bars = pci_select_bars(pdev, IORESOURCE_MEM);
7386 err = pci_request_selected_regions_exclusive(pdev, bars,
7387 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007388 if (err)
7389 goto err_pci_reg;
7390
Xiaotian Feng68eac462009-08-14 14:35:52 +00007391 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07007392 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00007393
Auke Kokbc7f75f2007-09-17 12:30:59 -07007394 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08007395 /* PCI config space info */
7396 err = pci_save_state(pdev);
7397 if (err)
7398 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007399
7400 err = -ENOMEM;
7401 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
7402 if (!netdev)
7403 goto err_alloc_etherdev;
7404
Auke Kokbc7f75f2007-09-17 12:30:59 -07007405 SET_NETDEV_DEV(netdev, &pdev->dev);
7406
Tom Herbertf85e4df2010-05-05 14:03:32 +00007407 netdev->irq = pdev->irq;
7408
Auke Kokbc7f75f2007-09-17 12:30:59 -07007409 pci_set_drvdata(pdev, netdev);
7410 adapter = netdev_priv(netdev);
7411 hw = &adapter->hw;
7412 adapter->netdev = netdev;
7413 adapter->pdev = pdev;
7414 adapter->ei = ei;
7415 adapter->pba = ei->pba;
7416 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00007417 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007418 adapter->hw.adapter = adapter;
7419 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00007420 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007421 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007422
7423 mmio_start = pci_resource_start(pdev, 0);
7424 mmio_len = pci_resource_len(pdev, 0);
7425
7426 err = -EIO;
7427 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
7428 if (!adapter->hw.hw_addr)
7429 goto err_ioremap;
7430
7431 if ((adapter->flags & FLAG_HAS_FLASH) &&
Yanir Lubetkin1103a632015-02-28 10:10:06 +00007432 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM) &&
7433 (hw->mac.type < e1000_pch_spt)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007434 flash_start = pci_resource_start(pdev, 1);
7435 flash_len = pci_resource_len(pdev, 1);
7436 adapter->hw.flash_address = ioremap(flash_start, flash_len);
7437 if (!adapter->hw.flash_address)
7438 goto err_flashmap;
7439 }
7440
Bruce Alland495bcb2013-03-20 07:23:11 +00007441 /* Set default EEE advertisement */
7442 if (adapter->flags2 & FLAG2_HAS_EEE)
7443 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
7444
Auke Kokbc7f75f2007-09-17 12:30:59 -07007445 /* construct the net_device struct */
Bruce Allane80bd1d2013-05-01 01:19:46 +00007446 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007447 e1000e_set_ethtool_ops(netdev);
Bruce Allane80bd1d2013-05-01 01:19:46 +00007448 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00007449 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00007450 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07007451
7452 netdev->mem_start = mmio_start;
7453 netdev->mem_end = mmio_start + mmio_len;
7454
7455 adapter->bd_number = cards_found++;
7456
Bruce Allan4662e822008-08-26 18:37:06 -07007457 e1000e_check_options(adapter);
7458
Auke Kokbc7f75f2007-09-17 12:30:59 -07007459 /* setup adapter struct */
7460 err = e1000_sw_init(adapter);
7461 if (err)
7462 goto err_sw_init;
7463
Auke Kokbc7f75f2007-09-17 12:30:59 -07007464 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
7465 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
7466 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
7467
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07007468 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007469 if (err)
7470 goto err_hw_init;
7471
Bruce Allan4a770352008-10-01 17:18:35 -07007472 if ((adapter->flags & FLAG_IS_ICH) &&
Yanir Lubetkin152c0a92015-03-20 17:41:53 -07007473 (adapter->flags & FLAG_READ_ONLY_NVM) &&
7474 (hw->mac.type < e1000_pch_spt))
Bruce Allan4a770352008-10-01 17:18:35 -07007475 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
7476
Auke Kokbc7f75f2007-09-17 12:30:59 -07007477 hw->mac.ops.get_bus_info(&adapter->hw);
7478
Jeff Kirsher318a94d2008-03-28 09:15:16 -07007479 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007480
7481 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07007482 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007483 adapter->hw.phy.mdix = AUTO_ALL_MODES;
7484 adapter->hw.phy.disable_polarity_correction = 0;
7485 adapter->hw.phy.ms_type = e1000_ms_hw_default;
7486 }
7487
Bruce Allan470a5422012-05-26 06:08:48 +00007488 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00007489 dev_info(&pdev->dev,
7490 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007491
Bruce Allandc221292011-08-19 03:23:48 +00007492 /* Set initial default active device features */
7493 netdev->features = (NETIF_F_SG |
Patrick McHardyf6469682013-04-19 02:04:27 +00007494 NETIF_F_HW_VLAN_CTAG_RX |
7495 NETIF_F_HW_VLAN_CTAG_TX |
Bruce Allandc221292011-08-19 03:23:48 +00007496 NETIF_F_TSO |
7497 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00007498 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00007499 NETIF_F_RXCSUM |
7500 NETIF_F_HW_CSUM);
7501
7502 /* Set user-changeable features (subset of all device features) */
7503 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00007504 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00007505 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00007506 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007507
7508 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardyf6469682013-04-19 02:04:27 +00007509 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007510
Bruce Allandc221292011-08-19 03:23:48 +00007511 netdev->vlan_features |= (NETIF_F_SG |
7512 NETIF_F_TSO |
7513 NETIF_F_TSO6 |
7514 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07007515
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00007516 netdev->priv_flags |= IFF_UNICAST_FLT;
7517
Yi Zou7b872a52010-09-22 17:57:58 +00007518 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007519 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007520 netdev->vlan_features |= NETIF_F_HIGHDMA;
7521 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07007522
Jarod Wilson91c527a2016-10-17 15:54:05 -04007523 /* MTU range: 68 - max_hw_frame_size */
7524 netdev->min_mtu = ETH_MIN_MTU;
7525 netdev->max_mtu = adapter->max_hw_frame_size -
7526 (VLAN_ETH_HLEN + ETH_FCS_LEN);
7527
Auke Kokbc7f75f2007-09-17 12:30:59 -07007528 if (e1000e_enable_mng_pass_thru(&adapter->hw))
7529 adapter->flags |= FLAG_MNG_PT_ENABLED;
7530
Bruce Allane921eb12012-11-28 09:28:37 +00007531 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07007532 * put the device in a known good starting state
7533 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007534 adapter->hw.mac.ops.reset_hw(&adapter->hw);
7535
Bruce Allane921eb12012-11-28 09:28:37 +00007536 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07007537 * attempt. Let's give it a few tries
7538 */
7539 for (i = 0;; i++) {
7540 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
7541 break;
7542 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00007543 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007544 err = -EIO;
7545 goto err_eeprom;
7546 }
7547 }
7548
Auke Kok10aa4c02008-08-04 17:21:20 -07007549 e1000_eeprom_checks(adapter);
7550
Bruce Allan608f8a02010-01-13 02:04:58 +00007551 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007552 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00007553 dev_err(&pdev->dev,
7554 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007555
7556 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007557
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00007558 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00007559 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00007560 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007561 err = -EIO;
7562 goto err_eeprom;
7563 }
7564
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08007565 timer_setup(&adapter->watchdog_timer, e1000_watchdog, 0);
Kees Cook26566ea2017-10-16 17:29:35 -07007566 timer_setup(&adapter->phy_info_timer, e1000_update_phy_info, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007567
7568 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08007569 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07007570 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
7571 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00007572 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007573
Auke Kokbc7f75f2007-09-17 12:30:59 -07007574 /* Initialize link parameters. User can change them with ethtool */
7575 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00007576 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08007577 adapter->hw.fc.requested_mode = e1000_fc_default;
7578 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007579 adapter->hw.phy.autoneg_advertised = 0x2f;
7580
Bruce Allane921eb12012-11-28 09:28:37 +00007581 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07007582 * the EEPROM, enable the ACPI Magic Packet filter
7583 */
7584 if (adapter->flags & FLAG_APME_IN_WUC) {
7585 /* APME bit in EEPROM is mapped to WUC.APME */
7586 eeprom_data = er32(WUC);
7587 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00007588 if ((hw->mac.type > e1000_ich10lan) &&
7589 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00007590 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007591 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
7592 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
7593 (adapter->hw.bus.func == 1))
Brian Walsh847042a2016-04-12 23:22:30 -04007594 ret_val = e1000_read_nvm(&adapter->hw,
David Ertman491a04d2014-07-09 16:07:42 +00007595 NVM_INIT_CONTROL3_PORT_B,
7596 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007597 else
Brian Walsh847042a2016-04-12 23:22:30 -04007598 ret_val = e1000_read_nvm(&adapter->hw,
David Ertman491a04d2014-07-09 16:07:42 +00007599 NVM_INIT_CONTROL3_PORT_A,
7600 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007601 }
7602
7603 /* fetch WoL from EEPROM */
Brian Walsh847042a2016-04-12 23:22:30 -04007604 if (ret_val)
7605 e_dbg("NVM read error getting WoL initial values: %d\n", ret_val);
David Ertman491a04d2014-07-09 16:07:42 +00007606 else if (eeprom_data & eeprom_apme_mask)
Auke Kokbc7f75f2007-09-17 12:30:59 -07007607 adapter->eeprom_wol |= E1000_WUFC_MAG;
7608
Bruce Allane921eb12012-11-28 09:28:37 +00007609 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07007610 * where the eeprom may be wrong or the board simply won't support
7611 * wake on lan on a particular port
7612 */
7613 if (!(adapter->flags & FLAG_HAS_WOL))
7614 adapter->eeprom_wol = 0;
7615
7616 /* initialize the wol settings based on the eeprom settings */
7617 adapter->wol = adapter->eeprom_wol;
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00007618
7619 /* make sure adapter isn't asleep if manageability is enabled */
7620 if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
7621 (hw->mac.ops.check_mng_mode(hw)))
7622 device_wakeup_enable(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007623
Bruce Allan84527592008-11-21 17:00:22 -08007624 /* save off EEPROM version number */
Brian Walsh847042a2016-04-12 23:22:30 -04007625 ret_val = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
David Ertman491a04d2014-07-09 16:07:42 +00007626
Brian Walsh847042a2016-04-12 23:22:30 -04007627 if (ret_val) {
7628 e_dbg("NVM read error getting EEPROM version: %d\n", ret_val);
David Ertman491a04d2014-07-09 16:07:42 +00007629 adapter->eeprom_vers = 0;
7630 }
Bruce Allan84527592008-11-21 17:00:22 -08007631
Jacob Kelleraa524b62016-04-20 11:36:42 -07007632 /* init PTP hardware clock */
7633 e1000e_ptp_init(adapter);
7634
Auke Kokbc7f75f2007-09-17 12:30:59 -07007635 /* reset the hardware with the new settings */
7636 e1000e_reset(adapter);
7637
Bruce Allane921eb12012-11-28 09:28:37 +00007638 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07007639 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07007640 * under the control of the driver.
7641 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007642 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00007643 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007644
Bruce Allanf2315bf2011-12-16 00:46:59 +00007645 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07007646 err = register_netdev(netdev);
7647 if (err)
7648 goto err_register;
7649
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00007650 /* carrier off reporting is important to ethtool even BEFORE open */
7651 netif_carrier_off(netdev);
7652
Auke Kokbc7f75f2007-09-17 12:30:59 -07007653 e1000_print_device_info(adapter);
7654
Rafael J. Wysockie0751552020-04-18 18:53:01 +02007655 dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE);
Kai-Heng Feng59f58702018-12-11 15:59:37 +08007656
Kai-Heng Feng459d69c2019-02-03 01:40:16 +08007657 if (pci_dev_run_wake(pdev) && hw->mac.type < e1000_pch_cnp)
Alan Sternf3ec4f82010-06-08 15:23:51 -04007658 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007659
Auke Kokbc7f75f2007-09-17 12:30:59 -07007660 return 0;
7661
7662err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007663 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00007664 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007665err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00007666 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07007667 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007668err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07007669 kfree(adapter->tx_ring);
7670 kfree(adapter->rx_ring);
7671err_sw_init:
Yanir Lubetkin1103a632015-02-28 10:10:06 +00007672 if ((adapter->hw.flash_address) && (hw->mac.type < e1000_pch_spt))
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007673 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00007674 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007675err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07007676 iounmap(adapter->hw.hw_addr);
7677err_ioremap:
7678 free_netdev(netdev);
7679err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02007680 pci_release_mem_regions(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007681err_pci_reg:
7682err_dma:
7683 pci_disable_device(pdev);
7684 return err;
7685}
7686
7687/**
7688 * e1000_remove - Device Removal Routine
7689 * @pdev: PCI device information struct
7690 *
7691 * e1000_remove is called by the PCI subsystem to alert the driver
7692 * that it should release a PCI device. The could be caused by a
7693 * Hot-Plug event, or because the driver is going to be removed from
7694 * memory.
7695 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007696static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07007697{
7698 struct net_device *netdev = pci_get_drvdata(pdev);
7699 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007700
Bruce Alland89777b2013-01-19 01:09:58 +00007701 e1000e_ptp_remove(adapter);
7702
Bruce Allane921eb12012-11-28 09:28:37 +00007703 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01007704 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07007705 */
Alexander Duyckdaee5592019-10-11 08:34:59 -07007706 set_bit(__E1000_DOWN, &adapter->state);
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08007707 del_timer_sync(&adapter->watchdog_timer);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007708 del_timer_sync(&adapter->phy_info_timer);
7709
Bruce Allan41cec6f2009-11-20 23:28:56 +00007710 cancel_work_sync(&adapter->reset_task);
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08007711 cancel_work_sync(&adapter->watchdog_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00007712 cancel_work_sync(&adapter->downshift_task);
7713 cancel_work_sync(&adapter->update_phy_task);
7714 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007715
Bruce Allanb67e1912012-12-27 08:32:33 +00007716 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
7717 cancel_work_sync(&adapter->tx_hwtstamp_work);
7718 if (adapter->tx_hwtstamp_skb) {
Florian Fainelli377b6272017-08-25 18:14:24 -07007719 dev_consume_skb_any(adapter->tx_hwtstamp_skb);
Bruce Allanb67e1912012-12-27 08:32:33 +00007720 adapter->tx_hwtstamp_skb = NULL;
7721 }
7722 }
7723
Bruce Allan17f208d2009-12-01 15:47:22 +00007724 unregister_netdev(netdev);
7725
Alan Sternf3ec4f82010-06-08 15:23:51 -04007726 if (pci_dev_run_wake(pdev))
7727 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007728
Bruce Allane921eb12012-11-28 09:28:37 +00007729 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07007730 * would have already happened in close and is redundant.
7731 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00007732 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007733
Bruce Allan4662e822008-08-26 18:37:06 -07007734 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007735 kfree(adapter->tx_ring);
7736 kfree(adapter->rx_ring);
7737
7738 iounmap(adapter->hw.hw_addr);
Yanir Lubetkin1103a632015-02-28 10:10:06 +00007739 if ((adapter->hw.flash_address) &&
7740 (adapter->hw.mac.type < e1000_pch_spt))
Auke Kokbc7f75f2007-09-17 12:30:59 -07007741 iounmap(adapter->hw.flash_address);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02007742 pci_release_mem_regions(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007743
7744 free_netdev(netdev);
7745
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007746 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07007747 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007748
Auke Kokbc7f75f2007-09-17 12:30:59 -07007749 pci_disable_device(pdev);
7750}
7751
7752/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007753static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007754 .error_detected = e1000_io_error_detected,
7755 .slot_reset = e1000_io_slot_reset,
7756 .resume = e1000_io_resume,
7757};
7758
David Ertman0e8e8422014-04-08 22:10:31 +00007759static const struct pci_device_id e1000_pci_tbl[] = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007760 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
7761 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
7762 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
Bruce Allanc29c3ba2013-02-20 04:05:50 +00007763 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
7764 board_82571 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007765 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
7766 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07007767 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
7768 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
7769 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07007770
Auke Kokbc7f75f2007-09-17 12:30:59 -07007771 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
7772 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
7773 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
7774 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07007775
Auke Kokbc7f75f2007-09-17 12:30:59 -07007776 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
7777 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
7778 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07007779
Bruce Allan4662e822008-08-26 18:37:06 -07007780 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07007781 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00007782 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07007783
Auke Kokbc7f75f2007-09-17 12:30:59 -07007784 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
7785 board_80003es2lan },
7786 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
7787 board_80003es2lan },
7788 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
7789 board_80003es2lan },
7790 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
7791 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07007792
Auke Kokbc7f75f2007-09-17 12:30:59 -07007793 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
7794 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
7795 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
7796 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
7797 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
7798 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
7799 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00007800 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07007801
Auke Kokbc7f75f2007-09-17 12:30:59 -07007802 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
7803 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
7804 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
7805 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
7806 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07007807 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07007808 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
7809 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
7810 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
7811
7812 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
7813 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
7814 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007815
Bruce Allanf4187b52008-08-26 18:36:50 -07007816 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
7817 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00007818 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07007819
Bruce Allana4f58f52009-06-02 11:29:18 +00007820 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
7821 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
7822 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
7823 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
7824
Bruce Alland3738bb2010-06-16 13:27:28 +00007825 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
7826 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7827
Bruce Allan2fbe4522012-04-19 03:21:47 +00007828 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7829 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00007830 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7831 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan91a3d822013-06-29 01:15:16 +00007832 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
7833 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
7834 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
7835 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
David Ertman79849eb2015-02-10 09:10:43 +00007836 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM), board_pch_spt },
7837 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V), board_pch_spt },
7838 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM2), board_pch_spt },
7839 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V2), board_pch_spt },
Raanan Avargilf3ed9352015-10-20 17:13:01 +03007840 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LBG_I219_LM3), board_pch_spt },
Raanan Avargil9cd34b32015-12-22 15:35:05 +02007841 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM4), board_pch_spt },
7842 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V4), board_pch_spt },
7843 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM5), board_pch_spt },
7844 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V5), board_pch_spt },
Sasha Neftin3a3173b2017-04-06 10:26:32 +03007845 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM6), board_pch_cnp },
7846 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V6), board_pch_cnp },
7847 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM7), board_pch_cnp },
7848 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V7), board_pch_cnp },
Sasha Neftin48f76b682017-07-17 15:13:39 -07007849 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM8), board_pch_cnp },
7850 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V8), board_pch_cnp },
7851 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM9), board_pch_cnp },
7852 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V9), board_pch_cnp },
Sasha Neftin914ee9c2019-10-10 13:15:39 +03007853 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM10), board_pch_cnp },
7854 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V10), board_pch_cnp },
7855 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM11), board_pch_cnp },
7856 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V11), board_pch_cnp },
7857 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM12), board_pch_spt },
7858 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V12), board_pch_spt },
Sasha Neftinfb776f52019-10-16 11:08:38 +03007859 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM13), board_pch_cnp },
7860 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V13), board_pch_cnp },
7861 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM14), board_pch_cnp },
7862 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V14), board_pch_cnp },
7863 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM15), board_pch_cnp },
Vitaly Lifshits56321222020-01-21 15:46:28 -08007864 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V15), board_pch_cnp },
Sasha Neftin59e46682020-01-19 13:57:13 +02007865 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM16), board_pch_cnp },
7866 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V16), board_pch_cnp },
7867 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM17), board_pch_cnp },
7868 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V17), board_pch_cnp },
Bruce Allan2fbe4522012-04-19 03:21:47 +00007869
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007870 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007871};
7872MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7873
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007874static const struct dev_pm_ops e1000_pm_ops = {
Kevin Hao72f72dc2014-03-18 00:26:49 -07007875#ifdef CONFIG_PM_SLEEP
David Ertman28002092014-02-14 07:16:41 +00007876 .suspend = e1000e_pm_suspend,
7877 .resume = e1000e_pm_resume,
7878 .freeze = e1000e_pm_freeze,
7879 .thaw = e1000e_pm_thaw,
7880 .poweroff = e1000e_pm_suspend,
7881 .restore = e1000e_pm_resume,
Kevin Hao72f72dc2014-03-18 00:26:49 -07007882#endif
David Ertman63eb48f2014-02-14 07:16:46 +00007883 SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
7884 e1000e_pm_runtime_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007885};
7886
Auke Kokbc7f75f2007-09-17 12:30:59 -07007887/* PCI Device API Driver */
7888static struct pci_driver e1000_driver = {
7889 .name = e1000e_driver_name,
7890 .id_table = e1000_pci_tbl,
7891 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007892 .remove = e1000_remove,
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007893 .driver = {
7894 .pm = &e1000_pm_ops,
7895 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007896 .shutdown = e1000_shutdown,
7897 .err_handler = &e1000_err_handler
7898};
7899
7900/**
7901 * e1000_init_module - Driver Registration Routine
7902 *
7903 * e1000_init_module is the first routine called when the driver is
7904 * loaded. All it does is register with the PCI subsystem.
7905 **/
7906static int __init e1000_init_module(void)
7907{
Bruce Allan8544b9f2010-03-24 12:55:30 +00007908 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7909 e1000e_driver_version);
Yanir Lubetkin529498c2015-06-02 17:05:50 +03007910 pr_info("Copyright(c) 1999 - 2015 Intel Corporation.\n");
Bruce Allan53ec5492009-11-20 23:27:40 +00007911
Jean Sacren5a5e8892015-09-19 05:08:42 -06007912 return pci_register_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007913}
7914module_init(e1000_init_module);
7915
7916/**
7917 * e1000_exit_module - Driver Exit Cleanup Routine
7918 *
7919 * e1000_exit_module is called just before the driver is removed
7920 * from memory.
7921 **/
7922static void __exit e1000_exit_module(void)
7923{
7924 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007925}
7926module_exit(e1000_exit_module);
7927
Auke Kokbc7f75f2007-09-17 12:30:59 -07007928MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7929MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
Jesse Brandeburg98674eb2018-09-14 17:37:57 -07007930MODULE_LICENSE("GPL v2");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007931MODULE_VERSION(DRV_VERSION);
7932
Bruce Allan06c24b92012-02-23 03:13:13 +00007933/* netdev.c */