blob: a42aeb555f343400721993e95f6a7d31397f3649 [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>
Chen Yuccf8b942020-12-01 09:21:50 +080028#include <linux/suspend.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070029
30#include "e1000.h"
31
Auke Kokbc7f75f2007-09-17 12:30:59 -070032char e1000e_driver_name[] = "e1000e";
Auke Kokbc7f75f2007-09-17 12:30:59 -070033
stephen hemmingerb3f4d592012-03-13 06:04:20 +000034#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
35static int debug = -1;
36module_param(debug, int, 0);
37MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
38
Auke Kokbc7f75f2007-09-17 12:30:59 -070039static const struct e1000_info *e1000_info_tbl[] = {
40 [board_82571] = &e1000_82571_info,
41 [board_82572] = &e1000_82572_info,
42 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070043 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000044 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070045 [board_80003es2lan] = &e1000_es2_info,
46 [board_ich8lan] = &e1000_ich8_info,
47 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070048 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000049 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000050 [board_pch2lan] = &e1000_pch2_info,
Bruce Allan2fbe4522012-04-19 03:21:47 +000051 [board_pch_lpt] = &e1000_pch_lpt_info,
David Ertman79849eb2015-02-10 09:10:43 +000052 [board_pch_spt] = &e1000_pch_spt_info,
Sasha Neftin3a3173b2017-04-06 10:26:32 +030053 [board_pch_cnp] = &e1000_pch_cnp_info,
Sasha Neftin280db5d2021-09-22 09:54:49 +030054 [board_pch_tgp] = &e1000_pch_tgp_info,
Sasha Neftin68defd52021-12-07 13:23:06 +020055 [board_pch_adp] = &e1000_pch_adp_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070056};
57
Taku Izumi84f4ee92010-04-27 14:39:08 +000058struct e1000_reg_info {
59 u32 ofs;
60 char *name;
61};
62
Taku Izumi84f4ee92010-04-27 14:39:08 +000063static const struct e1000_reg_info e1000_reg_info_tbl[] = {
Taku Izumi84f4ee92010-04-27 14:39:08 +000064 /* General Registers */
65 {E1000_CTRL, "CTRL"},
66 {E1000_STATUS, "STATUS"},
67 {E1000_CTRL_EXT, "CTRL_EXT"},
68
69 /* Interrupt Registers */
70 {E1000_ICR, "ICR"},
71
Bruce Allanaf667a22010-12-31 06:10:01 +000072 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +000073 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +000074 {E1000_RDLEN(0), "RDLEN"},
75 {E1000_RDH(0), "RDH"},
76 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000077 {E1000_RDTR, "RDTR"},
78 {E1000_RXDCTL(0), "RXDCTL"},
79 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +000080 {E1000_RDBAL(0), "RDBAL"},
81 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000082 {E1000_RDFH, "RDFH"},
83 {E1000_RDFT, "RDFT"},
84 {E1000_RDFHS, "RDFHS"},
85 {E1000_RDFTS, "RDFTS"},
86 {E1000_RDFPC, "RDFPC"},
87
Bruce Allanaf667a22010-12-31 06:10:01 +000088 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +000089 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +000090 {E1000_TDBAL(0), "TDBAL"},
91 {E1000_TDBAH(0), "TDBAH"},
92 {E1000_TDLEN(0), "TDLEN"},
93 {E1000_TDH(0), "TDH"},
94 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000095 {E1000_TIDV, "TIDV"},
96 {E1000_TXDCTL(0), "TXDCTL"},
97 {E1000_TADV, "TADV"},
98 {E1000_TARC(0), "TARC"},
99 {E1000_TDFH, "TDFH"},
100 {E1000_TDFT, "TDFT"},
101 {E1000_TDFHS, "TDFHS"},
102 {E1000_TDFTS, "TDFTS"},
103 {E1000_TDFPC, "TDFPC"},
104
105 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000106 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000107};
108
Bruce Allane921eb12012-11-28 09:28:37 +0000109/**
Andi Kleenc6f31482014-05-20 08:22:45 +0000110 * __ew32_prepare - prepare to write to MAC CSR register on certain parts
111 * @hw: pointer to the HW structure
112 *
113 * When updating the MAC CSR registers, the Manageability Engine (ME) could
114 * be accessing the registers at the same time. Normally, this is handled in
115 * h/w by an arbiter but on some parts there is a bug that acknowledges Host
116 * accesses later than it should which could result in the register to have
117 * an incorrect value. Workaround this by checking the FWSM register which
118 * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set
119 * and try again a number of times.
120 **/
Punit Agrawald601afc2020-05-15 13:31:27 +0900121static void __ew32_prepare(struct e1000_hw *hw)
Andi Kleenc6f31482014-05-20 08:22:45 +0000122{
123 s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;
124
125 while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
126 udelay(50);
Andi Kleenc6f31482014-05-20 08:22:45 +0000127}
128
129void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val)
130{
131 if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
132 __ew32_prepare(hw);
133
134 writel(val, hw->hw_addr + reg);
135}
136
137/**
Taku Izumi84f4ee92010-04-27 14:39:08 +0000138 * e1000_regdump - register printout routine
Bruce Allane921eb12012-11-28 09:28:37 +0000139 * @hw: pointer to the HW structure
140 * @reginfo: pointer to the register info table
141 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000142static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
143{
144 int n = 0;
145 char rname[16];
146 u32 regs[8];
147
148 switch (reginfo->ofs) {
149 case E1000_RXDCTL(0):
150 for (n = 0; n < 2; n++)
151 regs[n] = __er32(hw, E1000_RXDCTL(n));
152 break;
153 case E1000_TXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_TXDCTL(n));
156 break;
157 case E1000_TARC(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TARC(n));
160 break;
161 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000162 pr_info("%-15s %08x\n",
163 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000164 return;
165 }
166
167 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000168 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000169}
170
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000171static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
172 struct e1000_buffer *bi)
173{
174 int i;
175 struct e1000_ps_page *ps_page;
176
177 for (i = 0; i < adapter->rx_ps_pages; i++) {
178 ps_page = &bi->ps_pages[i];
179
180 if (ps_page->page) {
181 pr_info("packet dump for ps_page %d:\n", i);
182 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
183 16, 1, page_address(ps_page->page),
184 PAGE_SIZE, true);
185 }
186 }
187}
188
Bruce Allane921eb12012-11-28 09:28:37 +0000189/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000190 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Bruce Allane921eb12012-11-28 09:28:37 +0000191 * @adapter: board private structure
192 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000193static void e1000e_dump(struct e1000_adapter *adapter)
194{
195 struct net_device *netdev = adapter->netdev;
196 struct e1000_hw *hw = &adapter->hw;
197 struct e1000_reg_info *reginfo;
198 struct e1000_ring *tx_ring = adapter->tx_ring;
199 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000200 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000201 __le64 a;
202 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000203 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000204 struct e1000_buffer *buffer_info;
205 struct e1000_ring *rx_ring = adapter->rx_ring;
206 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000207 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000208 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000209 __le64 a;
210 __le64 b;
211 __le64 c;
212 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000213 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000214 u32 staterr;
215 int i = 0;
216
217 if (!netif_msg_hw(adapter))
218 return;
219
220 /* Print netdevice Info */
221 if (netdev) {
222 dev_info(&adapter->pdev->dev, "Net device Info\n");
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100223 pr_info("Device Name state trans_start\n");
224 pr_info("%-15s %016lX %016lX\n", netdev->name,
225 netdev->state, dev_trans_start(netdev));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000226 }
227
228 /* Print Registers */
229 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000230 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000231 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
232 reginfo->name; reginfo++) {
233 e1000_regdump(hw, reginfo);
234 }
235
Bruce Allanaf667a22010-12-31 06:10:01 +0000236 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000237 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000238 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000239
Bruce Allanaf667a22010-12-31 06:10:01 +0000240 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000241 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000242 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000243 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
244 0, tx_ring->next_to_use, tx_ring->next_to_clean,
245 (unsigned long long)buffer_info->dma,
246 buffer_info->length,
247 buffer_info->next_to_watch,
248 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000249
Bruce Allanaf667a22010-12-31 06:10:01 +0000250 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000251 if (!netif_msg_tx_done(adapter))
252 goto rx_ring_summary;
253
Bruce Allanaf667a22010-12-31 06:10:01 +0000254 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000255
256 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
257 *
258 * Legacy Transmit Descriptor
259 * +--------------------------------------------------------------+
260 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
261 * +--------------------------------------------------------------+
262 * 8 | Special | CSS | Status | CMD | CSO | Length |
263 * +--------------------------------------------------------------+
264 * 63 48 47 36 35 32 31 24 23 16 15 0
265 *
266 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
267 * 63 48 47 40 39 32 31 16 15 8 7 0
268 * +----------------------------------------------------------------+
269 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
270 * +----------------------------------------------------------------+
271 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
272 * +----------------------------------------------------------------+
273 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
274 *
275 * Extended Data Descriptor (DTYP=0x1)
276 * +----------------------------------------------------------------+
277 * 0 | Buffer Address [63:0] |
278 * +----------------------------------------------------------------+
279 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
280 * +----------------------------------------------------------------+
281 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
282 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000283 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
284 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
285 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 +0000286 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000287 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000288 tx_desc = E1000_TX_DESC(*tx_ring, i);
289 buffer_info = &tx_ring->buffer_info[i];
290 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000291 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000292 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000293 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000294 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000295 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000296 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000297 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000298 next_desc = "";
299 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
Jacob Keller18dd2392016-04-13 16:08:32 -0700300 (!(le64_to_cpu(u0->b) & BIT(29)) ? 'l' :
301 ((le64_to_cpu(u0->b) & BIT(20)) ? 'd' : 'c')),
Jeff Kirsheref456f82011-11-03 11:40:28 +0000302 i,
303 (unsigned long long)le64_to_cpu(u0->a),
304 (unsigned long long)le64_to_cpu(u0->b),
305 (unsigned long long)buffer_info->dma,
306 buffer_info->length, buffer_info->next_to_watch,
307 (unsigned long long)buffer_info->time_stamp,
308 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000309
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000310 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumi84f4ee92010-04-27 14:39:08 +0000311 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000312 16, 1, buffer_info->skb->data,
313 buffer_info->skb->len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000314 }
315
Bruce Allanaf667a22010-12-31 06:10:01 +0000316 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000317rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000318 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000319 pr_info("Queue [NTU] [NTC]\n");
320 pr_info(" %5d %5X %5X\n",
321 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000322
Bruce Allanaf667a22010-12-31 06:10:01 +0000323 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000324 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000325 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000326
Bruce Allanaf667a22010-12-31 06:10:01 +0000327 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000328 switch (adapter->rx_ps_pages) {
329 case 1:
330 case 2:
331 case 3:
332 /* [Extended] Packet Split Receive Descriptor Format
333 *
334 * +-----------------------------------------------------+
335 * 0 | Buffer Address 0 [63:0] |
336 * +-----------------------------------------------------+
337 * 8 | Buffer Address 1 [63:0] |
338 * +-----------------------------------------------------+
339 * 16 | Buffer Address 2 [63:0] |
340 * +-----------------------------------------------------+
341 * 24 | Buffer Address 3 [63:0] |
342 * +-----------------------------------------------------+
343 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000344 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 +0000345 /* [Extended] Receive Descriptor (Write-Back) Format
346 *
347 * 63 48 47 32 31 13 12 8 7 4 3 0
348 * +------------------------------------------------------+
349 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
350 * | Checksum | Ident | | Queue | | Type |
351 * +------------------------------------------------------+
352 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
353 * +------------------------------------------------------+
354 * 63 48 47 32 31 20 19 0
355 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000356 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 +0000357 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000358 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000359 buffer_info = &rx_ring->buffer_info[i];
360 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
361 u1 = (struct my_u1 *)rx_desc_ps;
362 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000363 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000364
365 if (i == rx_ring->next_to_use)
366 next_desc = " NTU";
367 else if (i == rx_ring->next_to_clean)
368 next_desc = " NTC";
369 else
370 next_desc = "";
371
Taku Izumi84f4ee92010-04-27 14:39:08 +0000372 if (staterr & E1000_RXD_STAT_DD) {
373 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000374 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
375 "RWB", i,
376 (unsigned long long)le64_to_cpu(u1->a),
377 (unsigned long long)le64_to_cpu(u1->b),
378 (unsigned long long)le64_to_cpu(u1->c),
379 (unsigned long long)le64_to_cpu(u1->d),
380 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000381 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000382 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
383 "R ", i,
384 (unsigned long long)le64_to_cpu(u1->a),
385 (unsigned long long)le64_to_cpu(u1->b),
386 (unsigned long long)le64_to_cpu(u1->c),
387 (unsigned long long)le64_to_cpu(u1->d),
388 (unsigned long long)buffer_info->dma,
389 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000390
391 if (netif_msg_pktdata(adapter))
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000392 e1000e_dump_ps_pages(adapter,
393 buffer_info);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000394 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000395 }
396 break;
397 default:
398 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000399 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000400 *
Bruce Allan5f450212011-07-22 06:21:46 +0000401 * +-----------------------------------------------------+
402 * 0 | Buffer Address [63:0] |
403 * +-----------------------------------------------------+
404 * 8 | Reserved |
405 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000406 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000407 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 +0000408 /* Extended Receive Descriptor (Write-Back) Format
409 *
410 * 63 48 47 32 31 24 23 4 3 0
411 * +------------------------------------------------------+
412 * | RSS Hash | | | |
413 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
414 * | Packet | IP | | | Type |
415 * | Checksum | Ident | | | |
416 * +------------------------------------------------------+
417 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
418 * +------------------------------------------------------+
419 * 63 48 47 32 31 20 19 0
420 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000421 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 +0000422
423 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000424 const char *next_desc;
425
Taku Izumi84f4ee92010-04-27 14:39:08 +0000426 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000427 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
428 u1 = (struct my_u1 *)rx_desc;
429 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000430
431 if (i == rx_ring->next_to_use)
432 next_desc = " NTU";
433 else if (i == rx_ring->next_to_clean)
434 next_desc = " NTC";
435 else
436 next_desc = "";
437
Bruce Allan5f450212011-07-22 06:21:46 +0000438 if (staterr & E1000_RXD_STAT_DD) {
439 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000440 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
441 "RWB", i,
442 (unsigned long long)le64_to_cpu(u1->a),
443 (unsigned long long)le64_to_cpu(u1->b),
444 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000445 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000446 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
447 "R ", i,
448 (unsigned long long)le64_to_cpu(u1->a),
449 (unsigned long long)le64_to_cpu(u1->b),
450 (unsigned long long)buffer_info->dma,
451 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000452
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000453 if (netif_msg_pktdata(adapter) &&
454 buffer_info->skb)
Bruce Allan5f450212011-07-22 06:21:46 +0000455 print_hex_dump(KERN_INFO, "",
456 DUMP_PREFIX_ADDRESS, 16,
457 1,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000458 buffer_info->skb->data,
Bruce Allan5f450212011-07-22 06:21:46 +0000459 adapter->rx_buffer_len,
460 true);
461 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000462 }
463 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000464}
465
Auke Kokbc7f75f2007-09-17 12:30:59 -0700466/**
467 * e1000_desc_unused - calculate if we have unused descriptors
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -0700468 * @ring: pointer to ring struct to perform calculation on
Auke Kokbc7f75f2007-09-17 12:30:59 -0700469 **/
470static int e1000_desc_unused(struct e1000_ring *ring)
471{
472 if (ring->next_to_clean > ring->next_to_use)
473 return ring->next_to_clean - ring->next_to_use - 1;
474
475 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
476}
477
478/**
Bruce Allanb67e1912012-12-27 08:32:33 +0000479 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
480 * @adapter: board private structure
481 * @hwtstamps: time stamp structure to update
482 * @systim: unsigned 64bit system time value.
483 *
484 * Convert the system time value stored in the RX/TXSTMP registers into a
485 * hwtstamp which can be used by the upper level time stamping functions.
486 *
487 * The 'systim_lock' spinlock is used to protect the consistency of the
488 * system time value. This is needed because reading the 64 bit time
489 * value involves reading two 32 bit registers. The first read latches the
490 * value.
491 **/
492static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
493 struct skb_shared_hwtstamps *hwtstamps,
494 u64 systim)
495{
496 u64 ns;
497 unsigned long flags;
498
499 spin_lock_irqsave(&adapter->systim_lock, flags);
500 ns = timecounter_cyc2time(&adapter->tc, systim);
501 spin_unlock_irqrestore(&adapter->systim_lock, flags);
502
503 memset(hwtstamps, 0, sizeof(*hwtstamps));
504 hwtstamps->hwtstamp = ns_to_ktime(ns);
505}
506
507/**
508 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
509 * @adapter: board private structure
510 * @status: descriptor extended error and status field
511 * @skb: particular skb to include time stamp
512 *
513 * If the time stamp is valid, convert it into the timecounter ns value
514 * and store that result into the shhwtstamps structure which is passed
515 * up the network stack.
516 **/
517static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
518 struct sk_buff *skb)
519{
520 struct e1000_hw *hw = &adapter->hw;
521 u64 rxstmp;
522
523 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
524 !(status & E1000_RXDEXT_STATERR_TST) ||
525 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
526 return;
527
528 /* The Rx time stamp registers contain the time stamp. No other
529 * received packet will be time stamped until the Rx time stamp
530 * registers are read. Because only one packet can be time stamped
531 * at a time, the register values must belong to this packet and
532 * therefore none of the other additional attributes need to be
533 * compared.
534 */
535 rxstmp = (u64)er32(RXSTMPL);
536 rxstmp |= (u64)er32(RXSTMPH) << 32;
537 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
538
539 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
540}
541
542/**
Bruce Allanad680762008-03-28 09:15:03 -0700543 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700544 * @adapter: board private structure
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -0700545 * @netdev: pointer to netdev struct
Bruce Allanb67e1912012-12-27 08:32:33 +0000546 * @staterr: descriptor extended error and status field as written by hardware
Auke Kokbc7f75f2007-09-17 12:30:59 -0700547 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
548 * @skb: pointer to sk_buff to be indicated to stack
549 **/
550static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000551 struct net_device *netdev, struct sk_buff *skb,
Bruce Allanb67e1912012-12-27 08:32:33 +0000552 u32 staterr, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700553{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000554 u16 tag = le16_to_cpu(vlan);
Bruce Allanb67e1912012-12-27 08:32:33 +0000555
556 e1000e_rx_hwtstamp(adapter, staterr, skb);
557
Auke Kokbc7f75f2007-09-17 12:30:59 -0700558 skb->protocol = eth_type_trans(skb, netdev);
559
Bruce Allanb67e1912012-12-27 08:32:33 +0000560 if (staterr & E1000_RXD_STAT_VP)
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000561 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000562
563 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700564}
565
566/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000567 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000568 * @adapter: board private structure
569 * @status_err: receive descriptor status and error fields
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -0700570 * @skb: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700571 **/
572static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allan2e1706f2012-06-30 20:02:42 +0000573 struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700574{
575 u16 status = (u16)status_err;
576 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700577
578 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700579
Bruce Allanafd12932012-01-05 00:34:05 +0000580 /* Rx checksum disabled */
581 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
582 return;
583
Auke Kokbc7f75f2007-09-17 12:30:59 -0700584 /* Ignore Checksum bit is set */
585 if (status & E1000_RXD_STAT_IXSM)
586 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000587
Bruce Allan2e1706f2012-06-30 20:02:42 +0000588 /* TCP/UDP checksum error bit or IP checksum error bit is set */
589 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700590 /* let the stack verify checksum errors */
591 adapter->hw_csum_err++;
592 return;
593 }
594
595 /* TCP/UDP Checksum has not been calculated */
596 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
597 return;
598
599 /* It must be a TCP or UDP packet with a valid checksum */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000600 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700601 adapter->hw_csum_good++;
602}
603
Bruce Allan55aa6982011-12-16 00:45:45 +0000604static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700605{
Bruce Allan55aa6982011-12-16 00:45:45 +0000606 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700607 struct e1000_hw *hw = &adapter->hw;
608
Punit Agrawald601afc2020-05-15 13:31:27 +0900609 __ew32_prepare(hw);
Bruce Allanbdc125f2012-03-20 03:47:52 +0000610 writel(i, rx_ring->tail);
611
Punit Agrawald601afc2020-05-15 13:31:27 +0900612 if (unlikely(i != readl(rx_ring->tail))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700613 u32 rctl = er32(RCTL);
David Ertman6cf08d12014-04-05 06:07:00 +0000614
David S. Miller823dcd22011-08-20 10:39:12 -0700615 ew32(RCTL, rctl & ~E1000_RCTL_EN);
616 e_err("ME firmware caused invalid RDT - resetting\n");
617 schedule_work(&adapter->reset_task);
618 }
619}
620
Bruce Allan55aa6982011-12-16 00:45:45 +0000621static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700622{
Bruce Allan55aa6982011-12-16 00:45:45 +0000623 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700624 struct e1000_hw *hw = &adapter->hw;
625
Punit Agrawald601afc2020-05-15 13:31:27 +0900626 __ew32_prepare(hw);
Bruce Allanbdc125f2012-03-20 03:47:52 +0000627 writel(i, tx_ring->tail);
628
Punit Agrawald601afc2020-05-15 13:31:27 +0900629 if (unlikely(i != readl(tx_ring->tail))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700630 u32 tctl = er32(TCTL);
David Ertman6cf08d12014-04-05 06:07:00 +0000631
David S. Miller823dcd22011-08-20 10:39:12 -0700632 ew32(TCTL, tctl & ~E1000_TCTL_EN);
633 e_err("ME firmware caused invalid TDT - resetting\n");
634 schedule_work(&adapter->reset_task);
635 }
636}
637
638/**
Bruce Allan5f450212011-07-22 06:21:46 +0000639 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000640 * @rx_ring: Rx descriptor ring
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -0700641 * @cleaned_count: number to reallocate
642 * @gfp: flags for allocation
Auke Kokbc7f75f2007-09-17 12:30:59 -0700643 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000644static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000645 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700646{
Bruce Allan55aa6982011-12-16 00:45:45 +0000647 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648 struct net_device *netdev = adapter->netdev;
649 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000650 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700651 struct e1000_buffer *buffer_info;
652 struct sk_buff *skb;
653 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000654 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700655
656 i = rx_ring->next_to_use;
657 buffer_info = &rx_ring->buffer_info[i];
658
659 while (cleaned_count--) {
660 skb = buffer_info->skb;
661 if (skb) {
662 skb_trim(skb, 0);
663 goto map_skb;
664 }
665
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000666 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700667 if (!skb) {
668 /* Better luck next round */
669 adapter->alloc_rx_buff_failed++;
670 break;
671 }
672
Auke Kokbc7f75f2007-09-17 12:30:59 -0700673 buffer_info->skb = skb;
674map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000675 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700676 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000677 DMA_FROM_DEVICE);
678 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000679 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700680 adapter->rx_dma_failed++;
681 break;
682 }
683
Bruce Allan5f450212011-07-22 06:21:46 +0000684 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
685 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700686
Tom Herbert50849d72010-05-05 14:02:49 +0000687 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000688 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000689 * know there are new descriptors to fetch. (Only
690 * applicable for weak-ordered memory model archs,
691 * such as IA-64).
692 */
693 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700694 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000695 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700696 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000697 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000698 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700699 i++;
700 if (i == rx_ring->count)
701 i = 0;
702 buffer_info = &rx_ring->buffer_info[i];
703 }
704
Tom Herbert50849d72010-05-05 14:02:49 +0000705 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700706}
707
708/**
709 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000710 * @rx_ring: Rx descriptor ring
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -0700711 * @cleaned_count: number to reallocate
712 * @gfp: flags for allocation
Auke Kokbc7f75f2007-09-17 12:30:59 -0700713 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000714static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000715 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700716{
Bruce Allan55aa6982011-12-16 00:45:45 +0000717 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700718 struct net_device *netdev = adapter->netdev;
719 struct pci_dev *pdev = adapter->pdev;
720 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700721 struct e1000_buffer *buffer_info;
722 struct e1000_ps_page *ps_page;
723 struct sk_buff *skb;
724 unsigned int i, j;
725
726 i = rx_ring->next_to_use;
727 buffer_info = &rx_ring->buffer_info[i];
728
729 while (cleaned_count--) {
730 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
731
732 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700733 ps_page = &buffer_info->ps_pages[j];
734 if (j >= adapter->rx_ps_pages) {
735 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000736 rx_desc->read.buffer_addr[j + 1] =
737 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700738 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700739 }
Auke Kok47f44e42007-10-25 13:57:44 -0700740 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000741 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700742 if (!ps_page->page) {
743 adapter->alloc_rx_buff_failed++;
744 goto no_buffers;
745 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000746 ps_page->dma = dma_map_page(&pdev->dev,
747 ps_page->page,
748 0, PAGE_SIZE,
749 DMA_FROM_DEVICE);
750 if (dma_mapping_error(&pdev->dev,
751 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700752 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000753 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700754 adapter->rx_dma_failed++;
755 goto no_buffers;
756 }
757 }
Bruce Allane921eb12012-11-28 09:28:37 +0000758 /* Refresh the desc even if buffer_addrs
Auke Kok47f44e42007-10-25 13:57:44 -0700759 * didn't change because each write-back
760 * erases this info.
761 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000762 rx_desc->read.buffer_addr[j + 1] =
763 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700764 }
765
Bruce Allane5fe2542013-02-20 04:06:27 +0000766 skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000767 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700768
769 if (!skb) {
770 adapter->alloc_rx_buff_failed++;
771 break;
772 }
773
Auke Kokbc7f75f2007-09-17 12:30:59 -0700774 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000775 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700776 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000777 DMA_FROM_DEVICE);
778 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000779 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700780 adapter->rx_dma_failed++;
781 /* cleanup skb */
782 dev_kfree_skb_any(skb);
783 buffer_info->skb = NULL;
784 break;
785 }
786
787 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
788
Tom Herbert50849d72010-05-05 14:02:49 +0000789 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000790 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000791 * know there are new descriptors to fetch. (Only
792 * applicable for weak-ordered memory model archs,
793 * such as IA-64).
794 */
795 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700796 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000797 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700798 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000799 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000800 }
801
Auke Kokbc7f75f2007-09-17 12:30:59 -0700802 i++;
803 if (i == rx_ring->count)
804 i = 0;
805 buffer_info = &rx_ring->buffer_info[i];
806 }
807
808no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000809 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810}
811
812/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700813 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000814 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700815 * @cleaned_count: number of buffers to allocate this pass
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -0700816 * @gfp: flags for allocation
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700817 **/
818
Bruce Allan55aa6982011-12-16 00:45:45 +0000819static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000820 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700821{
Bruce Allan55aa6982011-12-16 00:45:45 +0000822 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700823 struct net_device *netdev = adapter->netdev;
824 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000825 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700826 struct e1000_buffer *buffer_info;
827 struct sk_buff *skb;
828 unsigned int i;
Bruce Allan2a2293b2012-12-05 06:26:35 +0000829 unsigned int bufsz = 256 - 16; /* for skb_reserve */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700830
831 i = rx_ring->next_to_use;
832 buffer_info = &rx_ring->buffer_info[i];
833
834 while (cleaned_count--) {
835 skb = buffer_info->skb;
836 if (skb) {
837 skb_trim(skb, 0);
838 goto check_page;
839 }
840
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000841 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700842 if (unlikely(!skb)) {
843 /* Better luck next round */
844 adapter->alloc_rx_buff_failed++;
845 break;
846 }
847
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700848 buffer_info->skb = skb;
849check_page:
850 /* allocate a new page if necessary */
851 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000852 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700853 if (unlikely(!buffer_info->page)) {
854 adapter->alloc_rx_buff_failed++;
855 break;
856 }
857 }
858
Christoph Paasch37287fae2013-03-20 08:59:46 +0000859 if (!buffer_info->dma) {
Nick Nunley0be3f552010-04-27 13:09:05 +0000860 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allanf0ff4392013-02-20 04:05:39 +0000861 buffer_info->page, 0,
862 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000863 DMA_FROM_DEVICE);
Christoph Paasch37287fae2013-03-20 08:59:46 +0000864 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
865 adapter->alloc_rx_buff_failed++;
866 break;
867 }
868 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700869
Bruce Allan5f450212011-07-22 06:21:46 +0000870 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
871 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700872
873 if (unlikely(++i == rx_ring->count))
874 i = 0;
875 buffer_info = &rx_ring->buffer_info[i];
876 }
877
878 if (likely(rx_ring->next_to_use != i)) {
879 rx_ring->next_to_use = i;
880 if (unlikely(i-- == 0))
881 i = (rx_ring->count - 1);
882
883 /* Force memory writes to complete before letting h/w
884 * know there are new descriptors to fetch. (Only
885 * applicable for weak-ordered memory model archs,
Bruce Allane921eb12012-11-28 09:28:37 +0000886 * such as IA-64).
887 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700888 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700889 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000890 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700891 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000892 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700893 }
894}
895
Bruce Allan70495a52012-01-11 01:26:50 +0000896static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
897 struct sk_buff *skb)
898{
899 if (netdev->features & NETIF_F_RXHASH)
Tom Herberte25909b2013-12-18 16:46:48 +0000900 skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3);
Bruce Allan70495a52012-01-11 01:26:50 +0000901}
902
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700903/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000904 * e1000_clean_rx_irq - Send received data up the network stack
905 * @rx_ring: Rx descriptor ring
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -0700906 * @work_done: output parameter for indicating completed work
907 * @work_to_do: how many packets we can clean
Auke Kokbc7f75f2007-09-17 12:30:59 -0700908 *
909 * the return value indicates whether actual cleaning was done, there
910 * is no guarantee that everything was cleaned
911 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000912static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
913 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700914{
Bruce Allan55aa6982011-12-16 00:45:45 +0000915 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700916 struct net_device *netdev = adapter->netdev;
917 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000918 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000919 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700920 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000921 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700922 unsigned int i;
923 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000924 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700925 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
926
927 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000928 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
929 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700930 buffer_info = &rx_ring->buffer_info[i];
931
Bruce Allan5f450212011-07-22 06:21:46 +0000932 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700934
935 if (*work_done >= work_to_do)
936 break;
937 (*work_done)++;
Alexander Duyck837a1db2015-04-07 16:55:27 -0700938 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939
Auke Kokbc7f75f2007-09-17 12:30:59 -0700940 skb = buffer_info->skb;
941 buffer_info->skb = NULL;
942
943 prefetch(skb->data - NET_IP_ALIGN);
944
945 i++;
946 if (i == rx_ring->count)
947 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000948 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700949 prefetch(next_rxd);
950
951 next_buffer = &rx_ring->buffer_info[i];
952
Rusty Russell3db1cd52011-12-19 13:56:45 +0000953 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700954 cleaned_count++;
Bruce Allane5fe2542013-02-20 04:06:27 +0000955 dma_unmap_single(&pdev->dev, buffer_info->dma,
956 adapter->rx_buffer_len, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957 buffer_info->dma = 0;
958
Bruce Allan5f450212011-07-22 06:21:46 +0000959 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700960
Bruce Allane921eb12012-11-28 09:28:37 +0000961 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000962 * packet, if that's the case we need to toss it. In fact, we
963 * need to toss every packet with the EOP bit clear and the
964 * next frame that _does_ have the EOP bit set, as it is by
965 * definition only a frame fragment
966 */
Bruce Allan5f450212011-07-22 06:21:46 +0000967 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000968 adapter->flags2 |= FLAG2_IS_DISCARDING;
969
970 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700971 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000972 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973 /* recycle */
974 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000975 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000976 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700977 goto next_desc;
978 }
979
Ben Greearcf955e62012-02-11 15:39:51 +0000980 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
981 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 /* recycle */
983 buffer_info->skb = skb;
984 goto next_desc;
985 }
986
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000987 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000988 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
989 /* If configured to store CRC, don't subtract FCS,
990 * but keep the FCS bytes out of the total_rx_bytes
991 * counter
992 */
993 if (netdev->features & NETIF_F_RXFCS)
994 total_rx_bytes -= 4;
995 else
996 length -= 4;
997 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000998
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999 total_rx_bytes += length;
1000 total_rx_packets++;
1001
Bruce Allane921eb12012-11-28 09:28:37 +00001002 /* code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -07001004 * of reassembly being done in the stack
1005 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001006 if (length < copybreak) {
1007 struct sk_buff *new_skb =
Alexander Duyck67fd8932014-12-09 19:40:56 -08001008 napi_alloc_skb(&adapter->napi, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001009 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -07001010 skb_copy_to_linear_data_offset(new_skb,
1011 -NET_IP_ALIGN,
1012 (skb->data -
1013 NET_IP_ALIGN),
1014 (length +
1015 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001016 /* save the skb in buffer_info as good */
1017 buffer_info->skb = skb;
1018 skb = new_skb;
1019 }
1020 /* else just continue with the old one */
1021 }
1022 /* end copybreak code */
1023 skb_put(skb, length);
1024
1025 /* Receive Checksum Offload */
Bruce Allan2e1706f2012-06-30 20:02:42 +00001026 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027
Bruce Allan70495a52012-01-11 01:26:50 +00001028 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1029
Bruce Allan5f450212011-07-22 06:21:46 +00001030 e1000_receive_skb(adapter, netdev, skb, staterr,
1031 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001032
1033next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001034 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035
1036 /* return some buffers to hardware, one at a time is too slow */
1037 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001038 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001039 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040 cleaned_count = 0;
1041 }
1042
1043 /* use prefetched values */
1044 rx_desc = next_rxd;
1045 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001046
1047 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001048 }
1049 rx_ring->next_to_clean = i;
1050
1051 cleaned_count = e1000_desc_unused(rx_ring);
1052 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001053 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001054
Auke Kokbc7f75f2007-09-17 12:30:59 -07001055 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001056 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001057 return cleaned;
1058}
1059
Bruce Allan55aa6982011-12-16 00:45:45 +00001060static void e1000_put_txbuf(struct e1000_ring *tx_ring,
Florian Fainelli377b6272017-08-25 18:14:24 -07001061 struct e1000_buffer *buffer_info,
1062 bool drop)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001063{
Bruce Allan55aa6982011-12-16 00:45:45 +00001064 struct e1000_adapter *adapter = tx_ring->adapter;
1065
Alexander Duyck03b13202009-12-02 16:45:31 +00001066 if (buffer_info->dma) {
1067 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001068 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1069 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001070 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001071 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1072 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001073 buffer_info->dma = 0;
1074 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001075 if (buffer_info->skb) {
Florian Fainelli377b6272017-08-25 18:14:24 -07001076 if (drop)
1077 dev_kfree_skb_any(buffer_info->skb);
1078 else
1079 dev_consume_skb_any(buffer_info->skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001080 buffer_info->skb = NULL;
1081 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001082 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001083}
1084
Bruce Allan41cec6f2009-11-20 23:28:56 +00001085static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001086{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001087 struct e1000_adapter *adapter = container_of(work,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001088 struct e1000_adapter,
1089 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001090 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001091 struct e1000_ring *tx_ring = adapter->tx_ring;
1092 unsigned int i = tx_ring->next_to_clean;
1093 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1094 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001095 struct e1000_hw *hw = &adapter->hw;
1096 u16 phy_status, phy_1000t_status, phy_ext_status;
1097 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001098
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001099 if (test_bit(__E1000_DOWN, &adapter->state))
1100 return;
1101
Bruce Allane5fe2542013-02-20 04:06:27 +00001102 if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001103 /* May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001104 * flush pending descriptor writebacks to memory
1105 */
1106 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1107 /* execute the writes immediately */
1108 e1e_flush();
Bruce Allane921eb12012-11-28 09:28:37 +00001109 /* Due to rare timing issues, write to TIDV again to ensure
Matthew Vickbf030852012-03-16 09:03:00 +00001110 * the write is successful
1111 */
1112 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1113 /* execute the writes immediately */
1114 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001115 adapter->tx_hang_recheck = true;
1116 return;
1117 }
Jeff Kirsher09357b02011-11-18 14:25:00 +00001118 adapter->tx_hang_recheck = false;
David Ertmand9554e92014-01-08 01:07:55 +00001119
1120 if (er32(TDH(0)) == er32(TDT(0))) {
1121 e_dbg("false hang detected, ignoring\n");
1122 return;
1123 }
1124
1125 /* Real hang detected */
Jeff Kirsher09357b02011-11-18 14:25:00 +00001126 netif_stop_queue(netdev);
1127
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001128 e1e_rphy(hw, MII_BMSR, &phy_status);
1129 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1130 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001131
1132 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1133
1134 /* detected Hardware unit hang */
1135 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001136 " TDH <%x>\n"
1137 " TDT <%x>\n"
1138 " next_to_use <%x>\n"
1139 " next_to_clean <%x>\n"
1140 "buffer_info[next_to_clean]:\n"
1141 " time_stamp <%lx>\n"
1142 " next_to_watch <%x>\n"
1143 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001144 " next_to_watch.status <%x>\n"
1145 "MAC Status <%x>\n"
1146 "PHY Status <%x>\n"
1147 "PHY 1000BASE-T Status <%x>\n"
1148 "PHY Extended Status <%x>\n"
1149 "PCI Status <%x>\n",
Bruce Allane5fe2542013-02-20 04:06:27 +00001150 readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
1151 tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
1152 eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
1153 phy_status, phy_1000t_status, phy_ext_status, pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001154
David Ertmand9554e92014-01-08 01:07:55 +00001155 e1000e_dump(adapter);
1156
Bruce Allan7c0427e2012-03-20 03:48:08 +00001157 /* Suggest workaround for known h/w issue */
1158 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1159 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160}
1161
1162/**
Bruce Allanb67e1912012-12-27 08:32:33 +00001163 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1164 * @work: pointer to work struct
1165 *
1166 * This work function polls the TSYNCTXCTL valid bit to determine when a
1167 * timestamp has been taken for the current stored skb. The timestamp must
1168 * be for this skb because only one such packet is allowed in the queue.
1169 */
1170static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1171{
1172 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1173 tx_hwtstamp_work);
1174 struct e1000_hw *hw = &adapter->hw;
1175
Bruce Allanb67e1912012-12-27 08:32:33 +00001176 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
Jacob Keller50128632017-05-03 10:28:50 -07001177 struct sk_buff *skb = adapter->tx_hwtstamp_skb;
Bruce Allanb67e1912012-12-27 08:32:33 +00001178 struct skb_shared_hwtstamps shhwtstamps;
1179 u64 txstmp;
1180
1181 txstmp = er32(TXSTMPL);
1182 txstmp |= (u64)er32(TXSTMPH) << 32;
1183
1184 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1185
Jacob Keller50128632017-05-03 10:28:50 -07001186 /* Clear the global tx_hwtstamp_skb pointer and force writes
1187 * prior to notifying the stack of a Tx timestamp.
1188 */
Bruce Allanb67e1912012-12-27 08:32:33 +00001189 adapter->tx_hwtstamp_skb = NULL;
Jacob Keller50128632017-05-03 10:28:50 -07001190 wmb(); /* force write prior to skb_tstamp_tx */
1191
1192 skb_tstamp_tx(skb, &shhwtstamps);
Florian Fainelli377b6272017-08-25 18:14:24 -07001193 dev_consume_skb_any(skb);
Jakub Kicinski59c871c2014-03-15 14:55:00 +00001194 } else if (time_after(jiffies, adapter->tx_hwtstamp_start
1195 + adapter->tx_timeout_factor * HZ)) {
1196 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1197 adapter->tx_hwtstamp_skb = NULL;
1198 adapter->tx_hwtstamp_timeouts++;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +00001199 e_warn("clearing Tx timestamp hang\n");
Bruce Allanb67e1912012-12-27 08:32:33 +00001200 } else {
1201 /* reschedule to check later */
1202 schedule_work(&adapter->tx_hwtstamp_work);
1203 }
1204}
1205
1206/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001207 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001208 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209 *
1210 * the return value indicates whether actual cleaning was done, there
1211 * is no guarantee that everything was cleaned
1212 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001213static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001214{
Bruce Allan55aa6982011-12-16 00:45:45 +00001215 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001216 struct net_device *netdev = adapter->netdev;
1217 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001218 struct e1000_tx_desc *tx_desc, *eop_desc;
1219 struct e1000_buffer *buffer_info;
1220 unsigned int i, eop;
1221 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001222 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001223 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001224
1225 i = tx_ring->next_to_clean;
1226 eop = tx_ring->buffer_info[i].next_to_watch;
1227 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1228
Alexander Duyck12d04a32009-03-25 22:05:03 +00001229 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1230 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001231 bool cleaned = false;
David Ertman6cf08d12014-04-05 06:07:00 +00001232
Alexander Duyck837a1db2015-04-07 16:55:27 -07001233 dma_rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001234 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001235 tx_desc = E1000_TX_DESC(*tx_ring, i);
1236 buffer_info = &tx_ring->buffer_info[i];
1237 cleaned = (i == eop);
1238
1239 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001240 total_tx_packets += buffer_info->segs;
1241 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001242 if (buffer_info->skb) {
1243 bytes_compl += buffer_info->skb->len;
1244 pkts_compl++;
1245 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001246 }
1247
Florian Fainelli377b6272017-08-25 18:14:24 -07001248 e1000_put_txbuf(tx_ring, buffer_info, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249 tx_desc->upper.data = 0;
1250
1251 i++;
1252 if (i == tx_ring->count)
1253 i = 0;
1254 }
1255
Terry Loftindac87612010-04-09 10:29:49 +00001256 if (i == tx_ring->next_to_use)
1257 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001258 eop = tx_ring->buffer_info[i].next_to_watch;
1259 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260 }
1261
1262 tx_ring->next_to_clean = i;
1263
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001264 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1265
Auke Kokbc7f75f2007-09-17 12:30:59 -07001266#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001267 if (count && netif_carrier_ok(netdev) &&
1268 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001269 /* Make sure that anybody stopping the queue after this
1270 * sees the new next_to_clean.
1271 */
1272 smp_mb();
1273
1274 if (netif_queue_stopped(netdev) &&
1275 !(test_bit(__E1000_DOWN, &adapter->state))) {
1276 netif_wake_queue(netdev);
1277 ++adapter->restart_queue;
1278 }
1279 }
1280
1281 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001282 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001283 * check with the clearing of time_stamp and movement of i
1284 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001285 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001286 if (tx_ring->buffer_info[i].time_stamp &&
1287 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001288 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001289 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001290 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001291 else
1292 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001293 }
1294 adapter->total_tx_bytes += total_tx_bytes;
1295 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001296 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001297}
1298
1299/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001300 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001301 * @rx_ring: Rx descriptor ring
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07001302 * @work_done: output parameter for indicating completed work
1303 * @work_to_do: how many packets we can clean
Auke Kokbc7f75f2007-09-17 12:30:59 -07001304 *
1305 * the return value indicates whether actual cleaning was done, there
1306 * is no guarantee that everything was cleaned
1307 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001308static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1309 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001310{
Bruce Allan55aa6982011-12-16 00:45:45 +00001311 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001312 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001313 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1314 struct net_device *netdev = adapter->netdev;
1315 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001316 struct e1000_buffer *buffer_info, *next_buffer;
1317 struct e1000_ps_page *ps_page;
1318 struct sk_buff *skb;
1319 unsigned int i, j;
1320 u32 length, staterr;
1321 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001322 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001323 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1324
1325 i = rx_ring->next_to_clean;
1326 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1327 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1328 buffer_info = &rx_ring->buffer_info[i];
1329
1330 while (staterr & E1000_RXD_STAT_DD) {
1331 if (*work_done >= work_to_do)
1332 break;
1333 (*work_done)++;
1334 skb = buffer_info->skb;
Alexander Duyck837a1db2015-04-07 16:55:27 -07001335 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336
1337 /* in the packet split case this is header only */
1338 prefetch(skb->data - NET_IP_ALIGN);
1339
1340 i++;
1341 if (i == rx_ring->count)
1342 i = 0;
1343 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1344 prefetch(next_rxd);
1345
1346 next_buffer = &rx_ring->buffer_info[i];
1347
Rusty Russell3db1cd52011-12-19 13:56:45 +00001348 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001349 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001350 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001351 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001352 buffer_info->dma = 0;
1353
Bruce Allanaf667a22010-12-31 06:10:01 +00001354 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001355 if (!(staterr & E1000_RXD_STAT_EOP))
1356 adapter->flags2 |= FLAG2_IS_DISCARDING;
1357
1358 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001359 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001360 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001361 if (staterr & E1000_RXD_STAT_EOP)
1362 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001363 goto next_desc;
1364 }
1365
Ben Greearcf955e62012-02-11 15:39:51 +00001366 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1367 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001368 dev_kfree_skb_irq(skb);
1369 goto next_desc;
1370 }
1371
1372 length = le16_to_cpu(rx_desc->wb.middle.length0);
1373
1374 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001375 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001376 dev_kfree_skb_irq(skb);
1377 goto next_desc;
1378 }
1379
1380 /* Good Receive */
1381 skb_put(skb, length);
1382
1383 {
Bruce Allane921eb12012-11-28 09:28:37 +00001384 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001385 * it more efficient than reusing j
1386 */
1387 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001388
Bruce Allane921eb12012-11-28 09:28:37 +00001389 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001390 * packet throughput, so unsplit small packets and
1391 * save the alloc/put only valid in softirq (napi)
1392 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001393 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001394 if (l1 && (l1 <= copybreak) &&
1395 ((length + l1) <= adapter->rx_ps_bsize0)) {
1396 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001397
Bruce Allan0e15df42012-01-31 06:37:11 +00001398 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001399
Bruce Allane921eb12012-11-28 09:28:37 +00001400 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001401 * kmap_atomic, so we can't hold the mapping
1402 * very long
1403 */
1404 dma_sync_single_for_cpu(&pdev->dev,
1405 ps_page->dma,
1406 PAGE_SIZE,
1407 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001408 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001409 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001410 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001411 dma_sync_single_for_device(&pdev->dev,
1412 ps_page->dma,
1413 PAGE_SIZE,
1414 DMA_FROM_DEVICE);
1415
1416 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001417 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1418 if (!(netdev->features & NETIF_F_RXFCS))
1419 l1 -= 4;
1420 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001421
1422 skb_put(skb, l1);
1423 goto copydone;
Bruce Allane80bd1d2013-05-01 01:19:46 +00001424 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001425 }
1426
1427 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1428 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1429 if (!length)
1430 break;
1431
Auke Kok47f44e42007-10-25 13:57:44 -07001432 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001433 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1434 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001435 ps_page->dma = 0;
1436 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1437 ps_page->page = NULL;
1438 skb->len += length;
1439 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001440 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001441 }
1442
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001443 /* strip the ethernet crc, problem is we're using pages now so
1444 * this whole operation can get a little cpu intensive
1445 */
Ben Greear01840392012-02-11 15:39:25 +00001446 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1447 if (!(netdev->features & NETIF_F_RXFCS))
1448 pskb_trim(skb, skb->len - 4);
1449 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001450
Auke Kokbc7f75f2007-09-17 12:30:59 -07001451copydone:
1452 total_rx_bytes += skb->len;
1453 total_rx_packets++;
1454
Bruce Allan2e1706f2012-06-30 20:02:42 +00001455 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001456
Bruce Allan70495a52012-01-11 01:26:50 +00001457 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1458
Auke Kokbc7f75f2007-09-17 12:30:59 -07001459 if (rx_desc->wb.upper.header_status &
Bruce Allan17e813e2013-02-20 04:06:01 +00001460 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461 adapter->rx_hdr_split++;
1462
Bruce Allanb67e1912012-12-27 08:32:33 +00001463 e1000_receive_skb(adapter, netdev, skb, staterr,
1464 rx_desc->wb.middle.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001465
1466next_desc:
1467 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1468 buffer_info->skb = NULL;
1469
1470 /* return some buffers to hardware, one at a time is too slow */
1471 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001472 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001473 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001474 cleaned_count = 0;
1475 }
1476
1477 /* use prefetched values */
1478 rx_desc = next_rxd;
1479 buffer_info = next_buffer;
1480
1481 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1482 }
1483 rx_ring->next_to_clean = i;
1484
1485 cleaned_count = e1000_desc_unused(rx_ring);
1486 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001487 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001488
Auke Kokbc7f75f2007-09-17 12:30:59 -07001489 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001490 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001491 return cleaned;
1492}
1493
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001494static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
Bruce Allan66501f52013-02-20 04:05:55 +00001495 u16 length)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001496{
1497 bi->page = NULL;
1498 skb->len += length;
1499 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001500 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001501}
1502
1503/**
1504 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07001505 * @rx_ring: Rx descriptor ring
1506 * @work_done: output parameter for indicating completed work
1507 * @work_to_do: how many packets we can clean
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001508 *
1509 * the return value indicates whether actual cleaning was done, there
1510 * is no guarantee that everything was cleaned
1511 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001512static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1513 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001514{
Bruce Allan55aa6982011-12-16 00:45:45 +00001515 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001516 struct net_device *netdev = adapter->netdev;
1517 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001518 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001519 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001520 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001521 unsigned int i;
1522 int cleaned_count = 0;
1523 bool cleaned = false;
Bruce Allan362e20c2013-02-20 04:05:45 +00001524 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001525 struct skb_shared_info *shinfo;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001526
1527 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001528 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1529 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001530 buffer_info = &rx_ring->buffer_info[i];
1531
Bruce Allan5f450212011-07-22 06:21:46 +00001532 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001533 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001534
1535 if (*work_done >= work_to_do)
1536 break;
1537 (*work_done)++;
Alexander Duyck837a1db2015-04-07 16:55:27 -07001538 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001539
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001540 skb = buffer_info->skb;
1541 buffer_info->skb = NULL;
1542
1543 ++i;
1544 if (i == rx_ring->count)
1545 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001546 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001547 prefetch(next_rxd);
1548
1549 next_buffer = &rx_ring->buffer_info[i];
1550
1551 cleaned = true;
1552 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001553 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1554 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001555 buffer_info->dma = 0;
1556
Bruce Allan5f450212011-07-22 06:21:46 +00001557 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001558
1559 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001560 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001561 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1562 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001563 /* recycle both page and skb */
1564 buffer_info->skb = skb;
1565 /* an error means any chain goes out the window too */
1566 if (rx_ring->rx_skb_top)
1567 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1568 rx_ring->rx_skb_top = NULL;
1569 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001570 }
Bruce Allanf0f1a172010-12-11 05:53:32 +00001571#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001572 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001573 /* this descriptor is only the beginning (or middle) */
1574 if (!rxtop) {
1575 /* this is the beginning of a chain */
1576 rxtop = skb;
1577 skb_fill_page_desc(rxtop, 0, buffer_info->page,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001578 0, length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001579 } else {
1580 /* this is the middle of a chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001581 shinfo = skb_shinfo(rxtop);
1582 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1583 buffer_info->page, 0,
1584 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001585 /* re-use the skb, only consumed the page */
1586 buffer_info->skb = skb;
1587 }
1588 e1000_consume_page(buffer_info, rxtop, length);
1589 goto next_desc;
1590 } else {
1591 if (rxtop) {
1592 /* end of the chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001593 shinfo = skb_shinfo(rxtop);
1594 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1595 buffer_info->page, 0,
1596 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001597 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001598 * page
1599 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001600 buffer_info->skb = skb;
1601 skb = rxtop;
1602 rxtop = NULL;
1603 e1000_consume_page(buffer_info, skb, length);
1604 } else {
1605 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001606 * copybreak to save the put_page/alloc_page
1607 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001608 if (length <= copybreak &&
1609 skb_tailroom(skb) >= length) {
1610 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001611 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001612 memcpy(skb_tail_pointer(skb), vaddr,
1613 length);
Cong Wang46790262011-11-25 23:14:23 +08001614 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001615 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001616 * buffer_info->page
1617 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001618 skb_put(skb, length);
1619 } else {
1620 skb_fill_page_desc(skb, 0,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001621 buffer_info->page, 0,
1622 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001623 e1000_consume_page(buffer_info, skb,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001624 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001625 }
1626 }
1627 }
1628
Bruce Allan2e1706f2012-06-30 20:02:42 +00001629 /* Receive Checksum Offload */
1630 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001631
Bruce Allan70495a52012-01-11 01:26:50 +00001632 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1633
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001634 /* probably a little skewed due to removing CRC */
1635 total_rx_bytes += skb->len;
1636 total_rx_packets++;
1637
1638 /* eth type trans needs skb->data to point to something */
1639 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001640 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001641 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001642 goto next_desc;
1643 }
1644
Bruce Allan5f450212011-07-22 06:21:46 +00001645 e1000_receive_skb(adapter, netdev, skb, staterr,
1646 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001647
1648next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001649 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001650
1651 /* return some buffers to hardware, one at a time is too slow */
1652 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001653 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001654 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001655 cleaned_count = 0;
1656 }
1657
1658 /* use prefetched values */
1659 rx_desc = next_rxd;
1660 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001661
1662 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001663 }
1664 rx_ring->next_to_clean = i;
1665
1666 cleaned_count = e1000_desc_unused(rx_ring);
1667 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001668 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001669
1670 adapter->total_rx_bytes += total_rx_bytes;
1671 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001672 return cleaned;
1673}
1674
1675/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001676 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001677 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001679static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001680{
Bruce Allan55aa6982011-12-16 00:45:45 +00001681 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001682 struct e1000_buffer *buffer_info;
1683 struct e1000_ps_page *ps_page;
1684 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001685 unsigned int i, j;
1686
1687 /* Free all the Rx ring sk_buffs */
1688 for (i = 0; i < rx_ring->count; i++) {
1689 buffer_info = &rx_ring->buffer_info[i];
1690 if (buffer_info->dma) {
1691 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001692 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001693 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001694 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001695 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001696 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001697 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001698 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001699 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001700 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001701 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001702 buffer_info->dma = 0;
1703 }
1704
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001705 if (buffer_info->page) {
1706 put_page(buffer_info->page);
1707 buffer_info->page = NULL;
1708 }
1709
Auke Kokbc7f75f2007-09-17 12:30:59 -07001710 if (buffer_info->skb) {
1711 dev_kfree_skb(buffer_info->skb);
1712 buffer_info->skb = NULL;
1713 }
1714
1715 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001716 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717 if (!ps_page->page)
1718 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001719 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1720 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721 ps_page->dma = 0;
1722 put_page(ps_page->page);
1723 ps_page->page = NULL;
1724 }
1725 }
1726
1727 /* there also may be some cached data from a chained receive */
1728 if (rx_ring->rx_skb_top) {
1729 dev_kfree_skb(rx_ring->rx_skb_top);
1730 rx_ring->rx_skb_top = NULL;
1731 }
1732
Auke Kokbc7f75f2007-09-17 12:30:59 -07001733 /* Zero out the descriptor ring */
1734 memset(rx_ring->desc, 0, rx_ring->size);
1735
1736 rx_ring->next_to_clean = 0;
1737 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001738 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001739}
1740
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001741static void e1000e_downshift_workaround(struct work_struct *work)
1742{
1743 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00001744 struct e1000_adapter,
1745 downshift_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001746
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001747 if (test_bit(__E1000_DOWN, &adapter->state))
1748 return;
1749
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001750 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1751}
1752
Auke Kokbc7f75f2007-09-17 12:30:59 -07001753/**
1754 * e1000_intr_msi - Interrupt Handler
1755 * @irq: interrupt number
1756 * @data: pointer to a network interface device structure
1757 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001758static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001759{
1760 struct net_device *netdev = data;
1761 struct e1000_adapter *adapter = netdev_priv(netdev);
1762 struct e1000_hw *hw = &adapter->hw;
1763 u32 icr = er32(ICR);
1764
Bruce Allane921eb12012-11-28 09:28:37 +00001765 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001766 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001767 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001768 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001769 * disconnect (LSC) before accessing any PHY registers
1770 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001771 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1772 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001773 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001774
Bruce Allane921eb12012-11-28 09:28:37 +00001775 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001776 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001777 * adapter in watchdog
1778 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001779 if (netif_carrier_ok(netdev) &&
1780 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1781 /* disable receives */
1782 u32 rctl = er32(RCTL);
David Ertman6cf08d12014-04-05 06:07:00 +00001783
Auke Kokbc7f75f2007-09-17 12:30:59 -07001784 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001785 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001786 }
1787 /* guard against interrupt when we're going down */
1788 if (!test_bit(__E1000_DOWN, &adapter->state))
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08001789 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001790 }
1791
Bruce Allan94fb8482013-01-23 09:00:03 +00001792 /* Reset on uncorrectable ECC error */
Sasha Neftinc8744f42017-04-06 10:26:47 +03001793 if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
Bruce Allan94fb8482013-01-23 09:00:03 +00001794 u32 pbeccsts = er32(PBECCSTS);
1795
1796 adapter->corr_errors +=
1797 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1798 adapter->uncorr_errors +=
1799 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1800 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1801
1802 /* Do the reset outside of interrupt context */
1803 schedule_work(&adapter->reset_task);
1804
1805 /* return immediately since reset is imminent */
1806 return IRQ_HANDLED;
1807 }
1808
Ben Hutchings288379f2009-01-19 16:43:59 -08001809 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001810 adapter->total_tx_bytes = 0;
1811 adapter->total_tx_packets = 0;
1812 adapter->total_rx_bytes = 0;
1813 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001814 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001815 }
1816
1817 return IRQ_HANDLED;
1818}
1819
1820/**
1821 * e1000_intr - Interrupt Handler
1822 * @irq: interrupt number
1823 * @data: pointer to a network interface device structure
1824 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001825static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001826{
1827 struct net_device *netdev = data;
1828 struct e1000_adapter *adapter = netdev_priv(netdev);
1829 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001830 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001831
Bruce Allana68ea772009-11-20 23:23:16 +00001832 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Bruce Allane80bd1d2013-05-01 01:19:46 +00001833 return IRQ_NONE; /* Not our interrupt */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834
Bruce Allane921eb12012-11-28 09:28:37 +00001835 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001836 * not set, then the adapter didn't send an interrupt
1837 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001838 if (!(icr & E1000_ICR_INT_ASSERTED))
1839 return IRQ_NONE;
1840
Bruce Allane921eb12012-11-28 09:28:37 +00001841 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001842 * interrupts are masked. No need for the
1843 * IMC write
1844 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001845
dave graham573cca82009-02-10 12:52:05 +00001846 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001847 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001848 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001849 * disconnect (LSC) before accessing any PHY registers
1850 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001851 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1852 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001853 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001854
Bruce Allane921eb12012-11-28 09:28:37 +00001855 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856 * For packet buffer work-around on link down event;
1857 * disable receives here in the ISR and
1858 * reset adapter in watchdog
1859 */
1860 if (netif_carrier_ok(netdev) &&
1861 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1862 /* disable receives */
1863 rctl = er32(RCTL);
1864 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001865 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001866 }
1867 /* guard against interrupt when we're going down */
1868 if (!test_bit(__E1000_DOWN, &adapter->state))
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08001869 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001870 }
1871
Bruce Allan94fb8482013-01-23 09:00:03 +00001872 /* Reset on uncorrectable ECC error */
Sasha Neftinc8744f42017-04-06 10:26:47 +03001873 if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
Bruce Allan94fb8482013-01-23 09:00:03 +00001874 u32 pbeccsts = er32(PBECCSTS);
1875
1876 adapter->corr_errors +=
1877 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1878 adapter->uncorr_errors +=
1879 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1880 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1881
1882 /* Do the reset outside of interrupt context */
1883 schedule_work(&adapter->reset_task);
1884
1885 /* return immediately since reset is imminent */
1886 return IRQ_HANDLED;
1887 }
1888
Ben Hutchings288379f2009-01-19 16:43:59 -08001889 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001890 adapter->total_tx_bytes = 0;
1891 adapter->total_tx_packets = 0;
1892 adapter->total_rx_bytes = 0;
1893 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001894 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001895 }
1896
1897 return IRQ_HANDLED;
1898}
1899
Bruce Allan8bb62862013-01-16 08:46:49 +00001900static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001901{
1902 struct net_device *netdev = data;
1903 struct e1000_adapter *adapter = netdev_priv(netdev);
1904 struct e1000_hw *hw = &adapter->hw;
Benjamin Poirier116f4a62018-02-08 15:47:14 +09001905 u32 icr = er32(ICR);
Benjamin Poirier745d0bd2018-01-31 16:26:27 +09001906
Benjamin Poirier361a9542018-02-08 15:47:13 +09001907 if (icr & adapter->eiac_mask)
1908 ew32(ICS, (icr & adapter->eiac_mask));
1909
Benjamin Poirier4aea7a5c2017-07-21 11:36:27 -07001910 if (icr & E1000_ICR_LSC) {
Benjamin Poirier4aea7a5c2017-07-21 11:36:27 -07001911 hw->mac.get_link_status = true;
1912 /* guard against interrupt when we're going down */
1913 if (!test_bit(__E1000_DOWN, &adapter->state))
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08001914 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Benjamin Poirier4aea7a5c2017-07-21 11:36:27 -07001915 }
1916
Benjamin Poirier1f0ea192018-02-08 15:47:12 +09001917 if (!test_bit(__E1000_DOWN, &adapter->state))
Benjamin Poirier116f4a62018-02-08 15:47:14 +09001918 ew32(IMS, E1000_IMS_OTHER | IMS_OTHER_MASK);
Bruce Allan4662e822008-08-26 18:37:06 -07001919
Bruce Allan4662e822008-08-26 18:37:06 -07001920 return IRQ_HANDLED;
1921}
1922
Bruce Allan8bb62862013-01-16 08:46:49 +00001923static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001924{
1925 struct net_device *netdev = data;
1926 struct e1000_adapter *adapter = netdev_priv(netdev);
1927 struct e1000_hw *hw = &adapter->hw;
1928 struct e1000_ring *tx_ring = adapter->tx_ring;
1929
Bruce Allan4662e822008-08-26 18:37:06 -07001930 adapter->total_tx_bytes = 0;
1931 adapter->total_tx_packets = 0;
1932
Bruce Allan55aa6982011-12-16 00:45:45 +00001933 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001934 /* Ring was not completely cleaned, so fire another interrupt */
1935 ew32(ICS, tx_ring->ims_val);
1936
Benjamin Poirier0a8047a2015-11-09 15:50:21 -08001937 if (!test_bit(__E1000_DOWN, &adapter->state))
1938 ew32(IMS, adapter->tx_ring->ims_val);
1939
Bruce Allan4662e822008-08-26 18:37:06 -07001940 return IRQ_HANDLED;
1941}
1942
Bruce Allan8bb62862013-01-16 08:46:49 +00001943static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001944{
1945 struct net_device *netdev = data;
1946 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001947 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001948
1949 /* Write the ITR value calculated at the end of the
1950 * previous interrupt.
1951 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001952 if (rx_ring->set_itr) {
Dmitry Fleytmanb77ac462015-10-13 12:48:18 +03001953 u32 itr = rx_ring->itr_val ?
1954 1000000000 / (rx_ring->itr_val * 256) : 0;
1955
1956 writel(itr, rx_ring->itr_register);
Bruce Allan55aa6982011-12-16 00:45:45 +00001957 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001958 }
1959
Ben Hutchings288379f2009-01-19 16:43:59 -08001960 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001961 adapter->total_rx_bytes = 0;
1962 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001963 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001964 }
1965 return IRQ_HANDLED;
1966}
1967
1968/**
1969 * e1000_configure_msix - Configure MSI-X hardware
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07001970 * @adapter: board private structure
Bruce Allan4662e822008-08-26 18:37:06 -07001971 *
1972 * e1000_configure_msix sets up the hardware to properly
1973 * generate MSI-X interrupts.
1974 **/
1975static void e1000_configure_msix(struct e1000_adapter *adapter)
1976{
1977 struct e1000_hw *hw = &adapter->hw;
1978 struct e1000_ring *rx_ring = adapter->rx_ring;
1979 struct e1000_ring *tx_ring = adapter->tx_ring;
1980 int vector = 0;
1981 u32 ctrl_ext, ivar = 0;
1982
1983 adapter->eiac_mask = 0;
1984
1985 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1986 if (hw->mac.type == e1000_82574) {
1987 u32 rfctl = er32(RFCTL);
David Ertman6cf08d12014-04-05 06:07:00 +00001988
Bruce Allan4662e822008-08-26 18:37:06 -07001989 rfctl |= E1000_RFCTL_ACK_DIS;
1990 ew32(RFCTL, rfctl);
1991 }
1992
Bruce Allan4662e822008-08-26 18:37:06 -07001993 /* Configure Rx vector */
1994 rx_ring->ims_val = E1000_IMS_RXQ0;
1995 adapter->eiac_mask |= rx_ring->ims_val;
1996 if (rx_ring->itr_val)
1997 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001998 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001999 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00002000 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002001 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
2002
2003 /* Configure Tx vector */
2004 tx_ring->ims_val = E1000_IMS_TXQ0;
2005 vector++;
2006 if (tx_ring->itr_val)
2007 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00002008 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002009 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00002010 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002011 adapter->eiac_mask |= tx_ring->ims_val;
2012 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
2013
2014 /* set vector for Other Causes, e.g. link changes */
2015 vector++;
2016 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
2017 if (rx_ring->itr_val)
2018 writel(1000000000 / (rx_ring->itr_val * 256),
2019 hw->hw_addr + E1000_EITR_82574(vector));
2020 else
2021 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2022
2023 /* Cause Tx interrupts on every write back */
Jacob Keller18dd2392016-04-13 16:08:32 -07002024 ivar |= BIT(31);
Bruce Allan4662e822008-08-26 18:37:06 -07002025
2026 ew32(IVAR, ivar);
2027
2028 /* enable MSI-X PBA support */
Benjamin Poirier0a8047a2015-11-09 15:50:21 -08002029 ctrl_ext = er32(CTRL_EXT) & ~E1000_CTRL_EXT_IAME;
2030 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR | E1000_CTRL_EXT_EIAME;
Bruce Allan4662e822008-08-26 18:37:06 -07002031 ew32(CTRL_EXT, ctrl_ext);
2032 e1e_flush();
2033}
2034
2035void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2036{
2037 if (adapter->msix_entries) {
2038 pci_disable_msix(adapter->pdev);
2039 kfree(adapter->msix_entries);
2040 adapter->msix_entries = NULL;
2041 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2042 pci_disable_msi(adapter->pdev);
2043 adapter->flags &= ~FLAG_MSI_ENABLED;
2044 }
Bruce Allan4662e822008-08-26 18:37:06 -07002045}
2046
2047/**
2048 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07002049 * @adapter: board private structure
Bruce Allan4662e822008-08-26 18:37:06 -07002050 *
2051 * Attempt to configure interrupts using the best available
2052 * capabilities of the hardware and kernel.
2053 **/
2054void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2055{
2056 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002057 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002058
2059 switch (adapter->int_mode) {
2060 case E1000E_INT_MODE_MSIX:
2061 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002062 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2063 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan17e813e2013-02-20 04:06:01 +00002064 sizeof(struct
2065 msix_entry),
2066 GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002067 if (adapter->msix_entries) {
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002068 struct e1000_adapter *a = adapter;
2069
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002070 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002071 adapter->msix_entries[i].entry = i;
2072
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002073 err = pci_enable_msix_range(a->pdev,
2074 a->msix_entries,
2075 a->num_vectors,
2076 a->num_vectors);
2077 if (err > 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002078 return;
2079 }
2080 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002081 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002082 e1000e_reset_interrupt_capability(adapter);
2083 }
2084 adapter->int_mode = E1000E_INT_MODE_MSI;
Jeff Kirsher5463fce62020-06-03 20:07:26 -07002085 fallthrough;
Bruce Allan4662e822008-08-26 18:37:06 -07002086 case E1000E_INT_MODE_MSI:
2087 if (!pci_enable_msi(adapter->pdev)) {
2088 adapter->flags |= FLAG_MSI_ENABLED;
2089 } else {
2090 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002091 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002092 }
Jeff Kirsher5463fce62020-06-03 20:07:26 -07002093 fallthrough;
Bruce Allan4662e822008-08-26 18:37:06 -07002094 case E1000E_INT_MODE_LEGACY:
2095 /* Don't do anything; this is the system default */
2096 break;
2097 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002098
2099 /* store the number of vectors being used */
2100 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002101}
2102
2103/**
2104 * e1000_request_msix - Initialize MSI-X interrupts
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07002105 * @adapter: board private structure
Bruce Allan4662e822008-08-26 18:37:06 -07002106 *
2107 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2108 * kernel.
2109 **/
2110static int e1000_request_msix(struct e1000_adapter *adapter)
2111{
2112 struct net_device *netdev = adapter->netdev;
2113 int err = 0, vector = 0;
2114
2115 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002116 snprintf(adapter->rx_ring->name,
2117 sizeof(adapter->rx_ring->name) - 1,
Florian Fainelli135e7242019-02-21 20:09:28 -08002118 "%.14s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002119 else
2120 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2121 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002122 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002123 netdev);
2124 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002125 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002126 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2127 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002128 adapter->rx_ring->itr_val = adapter->itr;
2129 vector++;
2130
2131 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002132 snprintf(adapter->tx_ring->name,
2133 sizeof(adapter->tx_ring->name) - 1,
Florian Fainelli135e7242019-02-21 20:09:28 -08002134 "%.14s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002135 else
2136 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2137 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002138 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002139 netdev);
2140 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002141 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002142 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2143 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002144 adapter->tx_ring->itr_val = adapter->itr;
2145 vector++;
2146
2147 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002148 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002149 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002150 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002151
2152 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002153
Bruce Allan4662e822008-08-26 18:37:06 -07002154 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002155}
2156
Bruce Allanf8d59f72008-08-08 18:36:11 -07002157/**
2158 * e1000_request_irq - initialize interrupts
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07002159 * @adapter: board private structure
Bruce Allanf8d59f72008-08-08 18:36:11 -07002160 *
2161 * Attempts to configure interrupts using the best available
2162 * capabilities of the hardware and kernel.
2163 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002164static int e1000_request_irq(struct e1000_adapter *adapter)
2165{
2166 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002167 int err;
2168
Bruce Allan4662e822008-08-26 18:37:06 -07002169 if (adapter->msix_entries) {
2170 err = e1000_request_msix(adapter);
2171 if (!err)
2172 return err;
2173 /* fall back to MSI */
2174 e1000e_reset_interrupt_capability(adapter);
2175 adapter->int_mode = E1000E_INT_MODE_MSI;
2176 e1000e_set_interrupt_capability(adapter);
2177 }
2178 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002179 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002180 netdev->name, netdev);
2181 if (!err)
2182 return err;
2183
2184 /* fall back to legacy interrupt */
2185 e1000e_reset_interrupt_capability(adapter);
2186 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002187 }
2188
Joe Perchesa0607fd2009-11-18 23:29:17 -08002189 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002190 netdev->name, netdev);
2191 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002192 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002193
2194 return err;
2195}
2196
2197static void e1000_free_irq(struct e1000_adapter *adapter)
2198{
2199 struct net_device *netdev = adapter->netdev;
2200
Bruce Allan4662e822008-08-26 18:37:06 -07002201 if (adapter->msix_entries) {
2202 int vector = 0;
2203
2204 free_irq(adapter->msix_entries[vector].vector, netdev);
2205 vector++;
2206
2207 free_irq(adapter->msix_entries[vector].vector, netdev);
2208 vector++;
2209
2210 /* Other Causes interrupt vector */
2211 free_irq(adapter->msix_entries[vector].vector, netdev);
2212 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002213 }
Bruce Allan4662e822008-08-26 18:37:06 -07002214
2215 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002216}
2217
2218/**
2219 * e1000_irq_disable - Mask off interrupt generation on the NIC
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07002220 * @adapter: board private structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002221 **/
2222static void e1000_irq_disable(struct e1000_adapter *adapter)
2223{
2224 struct e1000_hw *hw = &adapter->hw;
2225
Auke Kokbc7f75f2007-09-17 12:30:59 -07002226 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002227 if (adapter->msix_entries)
2228 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002230
2231 if (adapter->msix_entries) {
2232 int i;
David Ertman6cf08d12014-04-05 06:07:00 +00002233
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002234 for (i = 0; i < adapter->num_vectors; i++)
2235 synchronize_irq(adapter->msix_entries[i].vector);
2236 } else {
2237 synchronize_irq(adapter->pdev->irq);
2238 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002239}
2240
2241/**
2242 * e1000_irq_enable - Enable default interrupt generation settings
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07002243 * @adapter: board private structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244 **/
2245static void e1000_irq_enable(struct e1000_adapter *adapter)
2246{
2247 struct e1000_hw *hw = &adapter->hw;
2248
Bruce Allan4662e822008-08-26 18:37:06 -07002249 if (adapter->msix_entries) {
2250 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
Benjamin Poirier116f4a62018-02-08 15:47:14 +09002251 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER |
2252 IMS_OTHER_MASK);
Sasha Neftinc8744f42017-04-06 10:26:47 +03002253 } else if (hw->mac.type >= e1000_pch_lpt) {
Bruce Allan94fb8482013-01-23 09:00:03 +00002254 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002255 } else {
2256 ew32(IMS, IMS_ENABLE_MASK);
2257 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002258 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259}
2260
2261/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002262 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002263 * @adapter: address of board private structure
2264 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002265 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002266 * For ASF and Pass Through versions of f/w this means that
2267 * the driver is loaded. For AMT version (only with 82573)
2268 * of the f/w this means that the network i/f is open.
2269 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002270void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002271{
2272 struct e1000_hw *hw = &adapter->hw;
2273 u32 ctrl_ext;
2274 u32 swsm;
2275
2276 /* Let firmware know the driver has taken over */
2277 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2278 swsm = er32(SWSM);
2279 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2280 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2281 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002282 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002283 }
2284}
2285
2286/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002287 * e1000e_release_hw_control - release control of the h/w to 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_release_hw_control resets {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 the
2292 * driver is no longer loaded. For AMT version (only with 82573) i
2293 * of the f/w this means that the network i/f is closed.
2294 *
2295 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002296void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002297{
2298 struct e1000_hw *hw = &adapter->hw;
2299 u32 ctrl_ext;
2300 u32 swsm;
2301
2302 /* Let firmware taken over control of h/w */
2303 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2304 swsm = er32(SWSM);
2305 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2306 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2307 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002308 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002309 }
2310}
2311
Auke Kokbc7f75f2007-09-17 12:30:59 -07002312/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002313 * e1000_alloc_ring_dma - allocate memory for a ring structure
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07002314 * @adapter: board private structure
2315 * @ring: ring struct for which to allocate dma
Auke Kokbc7f75f2007-09-17 12:30:59 -07002316 **/
2317static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2318 struct e1000_ring *ring)
2319{
2320 struct pci_dev *pdev = adapter->pdev;
2321
Luis Chamberlain750afb02019-01-04 09:23:09 +01002322 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2323 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324 if (!ring->desc)
2325 return -ENOMEM;
2326
2327 return 0;
2328}
2329
2330/**
2331 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002332 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333 *
2334 * Return 0 on success, negative on failure
2335 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002336int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002337{
Bruce Allan55aa6982011-12-16 00:45:45 +00002338 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002339 int err = -ENOMEM, size;
2340
2341 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002342 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002343 if (!tx_ring->buffer_info)
2344 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002345
2346 /* round up to nearest 4K */
2347 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2348 tx_ring->size = ALIGN(tx_ring->size, 4096);
2349
2350 err = e1000_alloc_ring_dma(adapter, tx_ring);
2351 if (err)
2352 goto err;
2353
2354 tx_ring->next_to_use = 0;
2355 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356
2357 return 0;
2358err:
2359 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002360 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002361 return err;
2362}
2363
2364/**
2365 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002366 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002367 *
2368 * Returns 0 on success, negative on failure
2369 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002370int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002371{
Bruce Allan55aa6982011-12-16 00:45:45 +00002372 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002373 struct e1000_buffer *buffer_info;
2374 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002375
2376 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002377 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378 if (!rx_ring->buffer_info)
2379 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002380
Auke Kok47f44e42007-10-25 13:57:44 -07002381 for (i = 0; i < rx_ring->count; i++) {
2382 buffer_info = &rx_ring->buffer_info[i];
2383 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2384 sizeof(struct e1000_ps_page),
2385 GFP_KERNEL);
2386 if (!buffer_info->ps_pages)
2387 goto err_pages;
2388 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389
2390 desc_len = sizeof(union e1000_rx_desc_packet_split);
2391
2392 /* Round up to nearest 4K */
2393 rx_ring->size = rx_ring->count * desc_len;
2394 rx_ring->size = ALIGN(rx_ring->size, 4096);
2395
2396 err = e1000_alloc_ring_dma(adapter, rx_ring);
2397 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002398 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002399
2400 rx_ring->next_to_clean = 0;
2401 rx_ring->next_to_use = 0;
2402 rx_ring->rx_skb_top = NULL;
2403
2404 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002405
2406err_pages:
2407 for (i = 0; i < rx_ring->count; i++) {
2408 buffer_info = &rx_ring->buffer_info[i];
2409 kfree(buffer_info->ps_pages);
2410 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002411err:
2412 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002413 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002414 return err;
2415}
2416
2417/**
2418 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002419 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002420 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002421static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002422{
Bruce Allan55aa6982011-12-16 00:45:45 +00002423 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002424 struct e1000_buffer *buffer_info;
2425 unsigned long size;
2426 unsigned int i;
2427
2428 for (i = 0; i < tx_ring->count; i++) {
2429 buffer_info = &tx_ring->buffer_info[i];
Florian Fainelli377b6272017-08-25 18:14:24 -07002430 e1000_put_txbuf(tx_ring, buffer_info, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002431 }
2432
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002433 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434 size = sizeof(struct e1000_buffer) * tx_ring->count;
2435 memset(tx_ring->buffer_info, 0, size);
2436
2437 memset(tx_ring->desc, 0, tx_ring->size);
2438
2439 tx_ring->next_to_use = 0;
2440 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002441}
2442
2443/**
2444 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002445 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446 *
2447 * Free all transmit software resources
2448 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002449void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002450{
Bruce Allan55aa6982011-12-16 00:45:45 +00002451 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002452 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002453
Bruce Allan55aa6982011-12-16 00:45:45 +00002454 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002455
2456 vfree(tx_ring->buffer_info);
2457 tx_ring->buffer_info = NULL;
2458
2459 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2460 tx_ring->dma);
2461 tx_ring->desc = NULL;
2462}
2463
2464/**
2465 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002466 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002467 *
2468 * Free all receive software resources
2469 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002470void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002471{
Bruce Allan55aa6982011-12-16 00:45:45 +00002472 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002473 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002474 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002475
Bruce Allan55aa6982011-12-16 00:45:45 +00002476 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002477
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002478 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002479 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002480
Auke Kokbc7f75f2007-09-17 12:30:59 -07002481 vfree(rx_ring->buffer_info);
2482 rx_ring->buffer_info = NULL;
2483
Auke Kokbc7f75f2007-09-17 12:30:59 -07002484 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2485 rx_ring->dma);
2486 rx_ring->desc = NULL;
2487}
2488
2489/**
2490 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002491 * @itr_setting: current adapter->itr
2492 * @packets: the number of packets during this measurement interval
2493 * @bytes: the number of bytes during this measurement interval
2494 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002495 * Stores a new ITR value based on packets and byte
2496 * counts during the last interrupt. The advantage of per interrupt
2497 * computation is faster updates and more accurate ITR for the current
2498 * traffic pattern. Constants in this function were computed
2499 * based on theoretical maximum wire speed and thresholds were set based
2500 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002501 * while increasing bulk throughput. This functionality is controlled
2502 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002503 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002504static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002505{
2506 unsigned int retval = itr_setting;
2507
2508 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002509 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510
2511 switch (itr_setting) {
2512 case lowest_latency:
2513 /* handle TSO and jumbo frames */
Bruce Allan362e20c2013-02-20 04:05:45 +00002514 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002515 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002516 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002517 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002518 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002519 case low_latency: /* 50 usec aka 20000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520 if (bytes > 10000) {
2521 /* this if handles the TSO accounting */
Bruce Allan362e20c2013-02-20 04:05:45 +00002522 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002523 retval = bulk_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002524 else if ((packets < 10) || ((bytes / packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002525 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002526 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527 retval = lowest_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002528 } else if (bytes / packets > 2000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002529 retval = bulk_latency;
2530 } else if (packets <= 2 && bytes < 512) {
2531 retval = lowest_latency;
2532 }
2533 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002534 case bulk_latency: /* 250 usec aka 4000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002535 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002536 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002537 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002538 } else if (bytes < 6000) {
2539 retval = low_latency;
2540 }
2541 break;
2542 }
2543
Auke Kokbc7f75f2007-09-17 12:30:59 -07002544 return retval;
2545}
2546
2547static void e1000_set_itr(struct e1000_adapter *adapter)
2548{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002549 u16 current_itr;
2550 u32 new_itr = adapter->itr;
2551
2552 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2553 if (adapter->link_speed != SPEED_1000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002554 new_itr = 4000;
2555 goto set_itr_now;
2556 }
2557
Bruce Allan828bac82010-09-29 21:39:37 +00002558 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2559 new_itr = 0;
2560 goto set_itr_now;
2561 }
2562
Bruce Allan8bb62862013-01-16 08:46:49 +00002563 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2564 adapter->total_tx_packets,
2565 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2567 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2568 adapter->tx_itr = low_latency;
2569
Bruce Allan8bb62862013-01-16 08:46:49 +00002570 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2571 adapter->total_rx_packets,
2572 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002573 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2574 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2575 adapter->rx_itr = low_latency;
2576
2577 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2578
Auke Kokbc7f75f2007-09-17 12:30:59 -07002579 /* counts and packets in update_itr are dependent on these numbers */
Bruce Allan33550ce2013-02-20 04:06:16 +00002580 switch (current_itr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002581 case lowest_latency:
2582 new_itr = 70000;
2583 break;
2584 case low_latency:
Bruce Allane80bd1d2013-05-01 01:19:46 +00002585 new_itr = 20000; /* aka hwitr = ~200 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002586 break;
2587 case bulk_latency:
2588 new_itr = 4000;
2589 break;
2590 default:
2591 break;
2592 }
2593
2594set_itr_now:
2595 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002596 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002597 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002598 * increasing
2599 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002600 new_itr = new_itr > adapter->itr ?
Bruce Allanf0ff4392013-02-20 04:05:39 +00002601 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002602 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002603 adapter->rx_ring->itr_val = new_itr;
2604 if (adapter->msix_entries)
2605 adapter->rx_ring->set_itr = 1;
2606 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002607 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002608 }
2609}
2610
2611/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002612 * e1000e_write_itr - write the ITR value to the appropriate registers
2613 * @adapter: address of board private structure
2614 * @itr: new ITR value to program
2615 *
2616 * e1000e_write_itr determines if the adapter is in MSI-X mode
2617 * and, if so, writes the EITR registers with the ITR value.
2618 * Otherwise, it writes the ITR value into the ITR register.
2619 **/
2620void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2621{
2622 struct e1000_hw *hw = &adapter->hw;
2623 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2624
2625 if (adapter->msix_entries) {
2626 int vector;
2627
2628 for (vector = 0; vector < adapter->num_vectors; vector++)
2629 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2630 } else {
2631 ew32(ITR, new_itr);
2632 }
2633}
2634
2635/**
Bruce Allan4662e822008-08-26 18:37:06 -07002636 * e1000_alloc_queues - Allocate memory for all rings
2637 * @adapter: board private structure to initialize
2638 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002639static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002640{
Bruce Allan55aa6982011-12-16 00:45:45 +00002641 int size = sizeof(struct e1000_ring);
2642
2643 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002644 if (!adapter->tx_ring)
2645 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002646 adapter->tx_ring->count = adapter->tx_ring_count;
2647 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002648
Bruce Allan55aa6982011-12-16 00:45:45 +00002649 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002650 if (!adapter->rx_ring)
2651 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002652 adapter->rx_ring->count = adapter->rx_ring_count;
2653 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002654
2655 return 0;
2656err:
2657 e_err("Unable to allocate memory for queues\n");
2658 kfree(adapter->rx_ring);
2659 kfree(adapter->tx_ring);
2660 return -ENOMEM;
2661}
2662
2663/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002664 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002665 * @napi: struct associated with this polling callback
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002666 * @budget: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002667 **/
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002668static int e1000e_poll(struct napi_struct *napi, int budget)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002669{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002670 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2671 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002672 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002673 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002674 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002675
Wang Chen4cf16532008-11-12 23:38:14 -08002676 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002677
Bruce Allanc58c8a72012-03-20 03:48:19 +00002678 if (!adapter->msix_entries ||
2679 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2680 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002681
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002682 adapter->clean_rx(adapter->rx_ring, &work_done, budget);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002683
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002684 if (!tx_cleaned || work_done == budget)
2685 return budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002686
Jesse Brandeburg0bcd9522018-11-08 14:55:32 -08002687 /* Exit the polling mode, but don't re-enable interrupts if stack might
2688 * poll us due to busy-polling
2689 */
2690 if (likely(napi_complete_done(napi, work_done))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002691 if (adapter->itr_setting & 3)
2692 e1000_set_itr(adapter);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002693 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2694 if (adapter->msix_entries)
Benjamin Poirier1f0ea192018-02-08 15:47:12 +09002695 ew32(IMS, adapter->rx_ring->ims_val);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002696 else
2697 e1000_irq_enable(adapter);
2698 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002699 }
2700
2701 return work_done;
2702}
2703
Patrick McHardy80d5c362013-04-19 02:04:28 +00002704static int e1000_vlan_rx_add_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002705 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002706{
2707 struct e1000_adapter *adapter = netdev_priv(netdev);
2708 struct e1000_hw *hw = &adapter->hw;
2709 u32 vfta, index;
2710
2711 /* don't update vlan cookie if already programmed */
2712 if ((adapter->hw.mng_cookie.status &
2713 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2714 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002715 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002716
Auke Kokbc7f75f2007-09-17 12:30:59 -07002717 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002718 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2719 index = (vid >> 5) & 0x7F;
2720 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
Jacob Keller18dd2392016-04-13 16:08:32 -07002721 vfta |= BIT((vid & 0x1F));
Bruce Allancaaddaf2009-12-01 15:46:43 +00002722 hw->mac.ops.write_vfta(hw, index, vfta);
2723 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002724
2725 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002726
2727 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002728}
2729
Patrick McHardy80d5c362013-04-19 02:04:28 +00002730static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002731 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002732{
2733 struct e1000_adapter *adapter = netdev_priv(netdev);
2734 struct e1000_hw *hw = &adapter->hw;
2735 u32 vfta, index;
2736
Auke Kokbc7f75f2007-09-17 12:30:59 -07002737 if ((adapter->hw.mng_cookie.status &
2738 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2739 (vid == adapter->mng_vlan_id)) {
2740 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002741 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002742 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002743 }
2744
2745 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002746 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2747 index = (vid >> 5) & 0x7F;
2748 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
Jacob Keller18dd2392016-04-13 16:08:32 -07002749 vfta &= ~BIT((vid & 0x1F));
Bruce Allancaaddaf2009-12-01 15:46:43 +00002750 hw->mac.ops.write_vfta(hw, index, vfta);
2751 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002752
2753 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002754
2755 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002756}
2757
2758/**
2759 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2760 * @adapter: board private structure to initialize
2761 **/
2762static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2763{
2764 struct net_device *netdev = adapter->netdev;
2765 struct e1000_hw *hw = &adapter->hw;
2766 u32 rctl;
2767
2768 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2769 /* disable VLAN receive filtering */
2770 rctl = er32(RCTL);
2771 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2772 ew32(RCTL, rctl);
2773
2774 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002775 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
2776 adapter->mng_vlan_id);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002777 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2778 }
2779 }
2780}
2781
2782/**
2783 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2784 * @adapter: board private structure to initialize
2785 **/
2786static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2787{
2788 struct e1000_hw *hw = &adapter->hw;
2789 u32 rctl;
2790
2791 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2792 /* enable VLAN receive filtering */
2793 rctl = er32(RCTL);
2794 rctl |= E1000_RCTL_VFE;
2795 rctl &= ~E1000_RCTL_CFIEN;
2796 ew32(RCTL, rctl);
2797 }
2798}
2799
2800/**
Jarod Wilson889ad452016-06-28 20:41:31 -07002801 * e1000e_vlan_strip_disable - helper to disable HW VLAN stripping
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002802 * @adapter: board private structure to initialize
2803 **/
2804static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2805{
2806 struct e1000_hw *hw = &adapter->hw;
2807 u32 ctrl;
2808
2809 /* disable VLAN tag insert/strip */
2810 ctrl = er32(CTRL);
2811 ctrl &= ~E1000_CTRL_VME;
2812 ew32(CTRL, ctrl);
2813}
2814
2815/**
2816 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2817 * @adapter: board private structure to initialize
2818 **/
2819static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2820{
2821 struct e1000_hw *hw = &adapter->hw;
2822 u32 ctrl;
2823
2824 /* enable VLAN tag insert/strip */
2825 ctrl = er32(CTRL);
2826 ctrl |= E1000_CTRL_VME;
2827 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002828}
2829
2830static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2831{
2832 struct net_device *netdev = adapter->netdev;
2833 u16 vid = adapter->hw.mng_cookie.vlan_id;
2834 u16 old_vid = adapter->mng_vlan_id;
2835
Bruce Allane5fe2542013-02-20 04:06:27 +00002836 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002837 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838 adapter->mng_vlan_id = vid;
2839 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002840
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002841 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
Patrick McHardy80d5c362013-04-19 02:04:28 +00002842 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002843}
2844
2845static void e1000_restore_vlan(struct e1000_adapter *adapter)
2846{
2847 u16 vid;
2848
Patrick McHardy80d5c362013-04-19 02:04:28 +00002849 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002850
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002851 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00002852 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002853}
2854
Bruce Allancd791612010-05-10 14:59:51 +00002855static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002856{
2857 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002858 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002859
2860 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2861 return;
2862
2863 manc = er32(MANC);
2864
Bruce Allane921eb12012-11-28 09:28:37 +00002865 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002866 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002867 * the packets will be handled on SMBUS
2868 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002869 manc |= E1000_MANC_EN_MNG2HOST;
2870 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002871
2872 switch (hw->mac.type) {
2873 default:
2874 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2875 break;
2876 case e1000_82574:
2877 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002878 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002879 * if so, enable it.
2880 */
2881 for (i = 0, j = 0; i < 8; i++) {
2882 mdef = er32(MDEF(i));
2883
2884 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002885 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002886 continue;
2887
2888 /* Enable this decision filter in MANC2H */
2889 if (mdef)
Jacob Keller18dd2392016-04-13 16:08:32 -07002890 manc2h |= BIT(i);
Bruce Allancd791612010-05-10 14:59:51 +00002891
2892 j |= mdef;
2893 }
2894
2895 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2896 break;
2897
2898 /* Create new decision filter in an empty filter */
2899 for (i = 0, j = 0; i < 8; i++)
2900 if (er32(MDEF(i)) == 0) {
2901 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2902 E1000_MDEF_PORT_664));
Jacob Keller18dd2392016-04-13 16:08:32 -07002903 manc2h |= BIT(1);
Bruce Allancd791612010-05-10 14:59:51 +00002904 j++;
2905 break;
2906 }
2907
2908 if (!j)
2909 e_warn("Unable to create IPMI pass-through filter\n");
2910 break;
2911 }
2912
Auke Kokbc7f75f2007-09-17 12:30:59 -07002913 ew32(MANC2H, manc2h);
2914 ew32(MANC, manc);
2915}
2916
2917/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002918 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002919 * @adapter: board private structure
2920 *
2921 * Configure the Tx unit of the MAC after a reset.
2922 **/
2923static void e1000_configure_tx(struct e1000_adapter *adapter)
2924{
2925 struct e1000_hw *hw = &adapter->hw;
2926 struct e1000_ring *tx_ring = adapter->tx_ring;
2927 u64 tdba;
David Ertmane7e834a2014-01-13 23:19:27 +00002928 u32 tdlen, tctl, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002929
2930 /* Setup the HW Tx Head and Tail descriptor pointers */
2931 tdba = tx_ring->dma;
2932 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002933 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2934 ew32(TDBAH(0), (tdba >> 32));
2935 ew32(TDLEN(0), tdlen);
2936 ew32(TDH(0), 0);
2937 ew32(TDT(0), 0);
2938 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2939 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002940
Jia-Ju Bai0845d452015-08-05 18:16:10 +08002941 writel(0, tx_ring->head);
2942 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2943 e1000e_update_tdt_wa(tx_ring, 0);
2944 else
2945 writel(0, tx_ring->tail);
2946
Auke Kokbc7f75f2007-09-17 12:30:59 -07002947 /* Set the Tx Interrupt Delay register */
2948 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002949 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002950 ew32(TADV, adapter->tx_abs_int_delay);
2951
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002952 if (adapter->flags2 & FLAG2_DMA_BURST) {
2953 u32 txdctl = er32(TXDCTL(0));
David Ertman6cf08d12014-04-05 06:07:00 +00002954
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002955 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2956 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002957 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002958 * hardware to use the bus more efficiently in bursts, depends
2959 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002960 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002961 * hthresh = 1 ==> prefetch when one or more available
2962 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2963 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002964 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002965 */
2966 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2967 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002968 }
Bruce Allan56032be2011-12-16 00:46:01 +00002969 /* erratum work around: set txdctl the same for both queues */
2970 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002971
David Ertmane7e834a2014-01-13 23:19:27 +00002972 /* Program the Transmit Control Register */
2973 tctl = er32(TCTL);
2974 tctl &= ~E1000_TCTL_CT;
2975 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2976 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2977
Auke Kokbc7f75f2007-09-17 12:30:59 -07002978 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002979 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002980 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002981 * gigabit link later
2982 */
Jacob Keller18dd2392016-04-13 16:08:32 -07002983#define SPEED_MODE_BIT BIT(21)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002984 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002985 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002986 }
2987
2988 /* errata: program both queues to unweighted RR */
2989 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002990 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002991 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002992 ew32(TARC(0), tarc);
2993 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002994 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002995 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002996 }
2997
Auke Kokbc7f75f2007-09-17 12:30:59 -07002998 /* Setup Transmit Descriptor Settings for eop descriptor */
2999 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
3000
3001 /* only set IDE if we are delaying interrupts using the timers */
3002 if (adapter->tx_int_delay)
3003 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
3004
3005 /* enable Report Status bit */
3006 adapter->txd_cmd |= E1000_TXD_CMD_RS;
3007
David Ertmane7e834a2014-01-13 23:19:27 +00003008 ew32(TCTL, tctl);
3009
Bruce Allan57cde762012-02-22 09:02:58 +00003010 hw->mac.ops.config_collision_dist(hw);
David Ertman79849eb2015-02-10 09:10:43 +00003011
Sasha Neftinb10effb2017-08-06 16:49:18 +03003012 /* SPT and KBL Si errata workaround to avoid data corruption */
3013 if (hw->mac.type == e1000_pch_spt) {
David Ertman79849eb2015-02-10 09:10:43 +00003014 u32 reg_val;
3015
3016 reg_val = er32(IOSFPC);
3017 reg_val |= E1000_RCTL_RDMTS_HEX;
3018 ew32(IOSFPC, reg_val);
3019
3020 reg_val = er32(TARC(0));
Sasha Neftinc0f4b162017-11-06 08:31:59 +02003021 /* SPT and KBL Si errata workaround to avoid Tx hang.
3022 * Dropping the number of outstanding requests from
3023 * 3 to 2 in order to avoid a buffer overrun.
3024 */
3025 reg_val &= ~E1000_TARC0_CB_MULTIQ_3_REQ;
3026 reg_val |= E1000_TARC0_CB_MULTIQ_2_REQ;
David Ertman79849eb2015-02-10 09:10:43 +00003027 ew32(TARC(0), reg_val);
3028 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003029}
3030
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07003031#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
3032 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
3033
Auke Kokbc7f75f2007-09-17 12:30:59 -07003034/**
3035 * e1000_setup_rctl - configure the receive control registers
3036 * @adapter: Board private structure
3037 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07003038static void e1000_setup_rctl(struct e1000_adapter *adapter)
3039{
3040 struct e1000_hw *hw = &adapter->hw;
3041 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003042 u32 pages = 0;
3043
David Ertmanb20a7742014-03-25 04:27:55 +00003044 /* Workaround Si errata on PCHx - configure jumbo frame flow.
3045 * If jumbo frames not set, program related MAC/PHY registers
3046 * to h/w defaults
3047 */
3048 if (hw->mac.type >= e1000_pch2lan) {
3049 s32 ret_val;
3050
3051 if (adapter->netdev->mtu > ETH_DATA_LEN)
3052 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
3053 else
3054 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
3055
3056 if (ret_val)
3057 e_dbg("failed to enable|disable jumbo frame workaround mode\n");
3058 }
Bruce Allana1ce6472010-09-22 17:16:40 +00003059
Auke Kokbc7f75f2007-09-17 12:30:59 -07003060 /* Program MC offset vector base */
3061 rctl = er32(RCTL);
3062 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3063 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
Bruce Allanf0ff4392013-02-20 04:05:39 +00003064 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3065 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003066
3067 /* Do not Store bad packets */
3068 rctl &= ~E1000_RCTL_SBP;
3069
3070 /* Enable Long Packet receive */
3071 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3072 rctl &= ~E1000_RCTL_LPE;
3073 else
3074 rctl |= E1000_RCTL_LPE;
3075
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003076 /* Some systems expect that the CRC is included in SMBUS traffic. The
3077 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3078 * host memory when this is enabled
3079 */
3080 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3081 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003082
Bruce Allana4f58f52009-06-02 11:29:18 +00003083 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3084 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3085 u16 phy_data;
3086
3087 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3088 phy_data &= 0xfff8;
Jacob Keller18dd2392016-04-13 16:08:32 -07003089 phy_data |= BIT(2);
Bruce Allana4f58f52009-06-02 11:29:18 +00003090 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3091
3092 e1e_rphy(hw, 22, &phy_data);
3093 phy_data &= 0x0fff;
Jacob Keller18dd2392016-04-13 16:08:32 -07003094 phy_data |= BIT(14);
Bruce Allana4f58f52009-06-02 11:29:18 +00003095 e1e_wphy(hw, 0x10, 0x2823);
3096 e1e_wphy(hw, 0x11, 0x0003);
3097 e1e_wphy(hw, 22, phy_data);
3098 }
3099
Auke Kokbc7f75f2007-09-17 12:30:59 -07003100 /* Setup buffer sizes */
3101 rctl &= ~E1000_RCTL_SZ_4096;
3102 rctl |= E1000_RCTL_BSEX;
3103 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003104 case 2048:
3105 default:
3106 rctl |= E1000_RCTL_SZ_2048;
3107 rctl &= ~E1000_RCTL_BSEX;
3108 break;
3109 case 4096:
3110 rctl |= E1000_RCTL_SZ_4096;
3111 break;
3112 case 8192:
3113 rctl |= E1000_RCTL_SZ_8192;
3114 break;
3115 case 16384:
3116 rctl |= E1000_RCTL_SZ_16384;
3117 break;
3118 }
3119
Bruce Allan5f450212011-07-22 06:21:46 +00003120 /* Enable Extended Status in all Receive Descriptors */
3121 rfctl = er32(RFCTL);
3122 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003123 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003124
Bruce Allane921eb12012-11-28 09:28:37 +00003125 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003126 * header is placed in skb->data and the packet data is
3127 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3128 * In the case of a non-split, skb->data is linearly filled,
3129 * followed by the page buffers. Therefore, skb->data is
3130 * sized to hold the largest protocol header.
3131 *
3132 * allocations using alloc_page take too long for regular MTU
3133 * so only enable packet split for jumbo frames
3134 *
3135 * Using pages when the page size is greater than 16k wastes
3136 * a lot of memory, since we allocate 3 pages at all times
3137 * per packet.
3138 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003139 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003140 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003141 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003142 else
3143 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003144
3145 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003146 u32 psrctl = 0;
3147
Auke Kok140a7482007-10-25 13:57:58 -07003148 /* Enable Packet split descriptors */
3149 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003150
Bruce Allane5fe2542013-02-20 04:06:27 +00003151 psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003152
3153 switch (adapter->rx_ps_pages) {
3154 case 3:
Bruce Allane5fe2542013-02-20 04:06:27 +00003155 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
Jeff Kirsher5463fce62020-06-03 20:07:26 -07003156 fallthrough;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003157 case 2:
Bruce Allane5fe2542013-02-20 04:06:27 +00003158 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
Jeff Kirsher5463fce62020-06-03 20:07:26 -07003159 fallthrough;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003160 case 1:
Bruce Allane5fe2542013-02-20 04:06:27 +00003161 psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003162 break;
3163 }
3164
3165 ew32(PSRCTL, psrctl);
3166 }
3167
Ben Greearcf955e62012-02-11 15:39:51 +00003168 /* This is useful for sniffing bad packets. */
3169 if (adapter->netdev->features & NETIF_F_RXALL) {
3170 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003171 * in e1000e_set_rx_mode
3172 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00003173 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3174 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3175 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
Ben Greearcf955e62012-02-11 15:39:51 +00003176
Bruce Allane80bd1d2013-05-01 01:19:46 +00003177 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3178 E1000_RCTL_DPF | /* Allow filtered pause */
3179 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
Ben Greearcf955e62012-02-11 15:39:51 +00003180 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3181 * and that breaks VLANs.
3182 */
3183 }
3184
Auke Kokbc7f75f2007-09-17 12:30:59 -07003185 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003186 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003187 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003188}
3189
3190/**
3191 * e1000_configure_rx - Configure Receive Unit after Reset
3192 * @adapter: board private structure
3193 *
3194 * Configure the Rx unit of the MAC after a reset.
3195 **/
3196static void e1000_configure_rx(struct e1000_adapter *adapter)
3197{
3198 struct e1000_hw *hw = &adapter->hw;
3199 struct e1000_ring *rx_ring = adapter->rx_ring;
3200 u64 rdba;
3201 u32 rdlen, rctl, rxcsum, ctrl_ext;
3202
3203 if (adapter->rx_ps_pages) {
3204 /* this is a 32 byte descriptor */
3205 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003206 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003207 adapter->clean_rx = e1000_clean_rx_irq_ps;
3208 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003209 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003210 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003211 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3212 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003213 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003214 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003215 adapter->clean_rx = e1000_clean_rx_irq;
3216 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3217 }
3218
3219 /* disable receives while setting up the descriptors */
3220 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003221 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3222 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003223 e1e_flush();
Arjan van de Venab6973a2019-06-14 17:29:35 -07003224 usleep_range(10000, 11000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003225
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003226 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003227 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003228 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003229 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003230 * granularity = 01
3231 * wthresh = 04,
3232 * hthresh = 04,
3233 * pthresh = 0x20
3234 */
3235 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3236 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003237 }
3238
Auke Kokbc7f75f2007-09-17 12:30:59 -07003239 /* set the Receive Delay Timer Register */
3240 ew32(RDTR, adapter->rx_int_delay);
3241
3242 /* irq moderation */
3243 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003244 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003245 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003246
3247 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003248 /* Auto-Mask interrupts upon ICR access */
3249 ctrl_ext |= E1000_CTRL_EXT_IAME;
3250 ew32(IAM, 0xffffffff);
3251 ew32(CTRL_EXT, ctrl_ext);
3252 e1e_flush();
3253
Bruce Allane921eb12012-11-28 09:28:37 +00003254 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003255 * the Base and Length of the Rx Descriptor Ring
3256 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003257 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003258 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3259 ew32(RDBAH(0), (rdba >> 32));
3260 ew32(RDLEN(0), rdlen);
3261 ew32(RDH(0), 0);
3262 ew32(RDT(0), 0);
3263 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3264 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003265
Jia-Ju Bai0845d452015-08-05 18:16:10 +08003266 writel(0, rx_ring->head);
3267 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
3268 e1000e_update_rdt_wa(rx_ring, 0);
3269 else
3270 writel(0, rx_ring->tail);
3271
Auke Kokbc7f75f2007-09-17 12:30:59 -07003272 /* Enable Receive Checksum Offload for TCP and UDP */
3273 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003274 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003275 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003276 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003277 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003278 ew32(RXCSUM, rxcsum);
3279
Bruce Allan3e35d992013-01-12 07:25:22 +00003280 /* With jumbo frames, excessive C-state transition latencies result
3281 * in dropped transactions.
3282 */
3283 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3284 u32 lat =
3285 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3286 adapter->max_frame_size) * 8 / 1000;
3287
3288 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003289 u32 rxdctl = er32(RXDCTL(0));
David Ertman6cf08d12014-04-05 06:07:00 +00003290
Matt Turnerb701cac2017-11-07 14:13:30 -08003291 ew32(RXDCTL(0), rxdctl | 0x3 | BIT(8));
Bruce Allan53ec5492009-11-20 23:27:40 +00003292 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003293
Matt Turner8299b002017-11-14 15:51:33 -08003294 dev_info(&adapter->pdev->dev,
3295 "Some CPU C-states have been disabled in order to enable jumbo frames\n");
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01003296 cpu_latency_qos_update_request(&adapter->pm_qos_req, lat);
Bruce Allan3e35d992013-01-12 07:25:22 +00003297 } else {
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01003298 cpu_latency_qos_update_request(&adapter->pm_qos_req,
3299 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003300 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003301
3302 /* Enable Receives */
3303 ew32(RCTL, rctl);
3304}
3305
3306/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003307 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003308 * @netdev: network interface device structure
3309 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003310 * Writes multicast address list to the MTA hash table.
3311 * Returns: -ENOMEM on failure
3312 * 0 on no addresses written
3313 * X on writing X addresses to MTA
3314 */
3315static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003316{
3317 struct e1000_adapter *adapter = netdev_priv(netdev);
3318 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003319 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003320 u8 *mta_list;
3321 int i;
3322
3323 if (netdev_mc_empty(netdev)) {
3324 /* nothing to program, so clear mc list */
3325 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3326 return 0;
3327 }
3328
Kees Cook6396bb22018-06-12 14:03:40 -07003329 mta_list = kcalloc(netdev_mc_count(netdev), ETH_ALEN, GFP_ATOMIC);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003330 if (!mta_list)
3331 return -ENOMEM;
3332
3333 /* update_mc_addr_list expects a packed array of only addresses. */
3334 i = 0;
3335 netdev_for_each_mc_addr(ha, netdev)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003336 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003337
3338 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3339 kfree(mta_list);
3340
3341 return netdev_mc_count(netdev);
3342}
3343
3344/**
3345 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3346 * @netdev: network interface device structure
3347 *
3348 * Writes unicast address list to the RAR table.
3349 * Returns: -ENOMEM on failure/insufficient address space
3350 * 0 on no addresses written
3351 * X on writing X addresses to the RAR table
3352 **/
3353static int e1000e_write_uc_addr_list(struct net_device *netdev)
3354{
3355 struct e1000_adapter *adapter = netdev_priv(netdev);
3356 struct e1000_hw *hw = &adapter->hw;
David Ertmanb3e5bf12014-05-06 03:50:17 +00003357 unsigned int rar_entries;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003358 int count = 0;
3359
David Ertmanb3e5bf12014-05-06 03:50:17 +00003360 rar_entries = hw->mac.ops.rar_get_count(hw);
3361
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003362 /* save a rar entry for our hardware address */
3363 rar_entries--;
3364
3365 /* save a rar entry for the LAA workaround */
3366 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3367 rar_entries--;
3368
3369 /* return ENOMEM indicating insufficient memory for addresses */
3370 if (netdev_uc_count(netdev) > rar_entries)
3371 return -ENOMEM;
3372
3373 if (!netdev_uc_empty(netdev) && rar_entries) {
3374 struct netdev_hw_addr *ha;
3375
Bruce Allane921eb12012-11-28 09:28:37 +00003376 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003377 * combining
3378 */
3379 netdev_for_each_uc_addr(ha, netdev) {
Brian Walsh847042a2016-04-12 23:22:30 -04003380 int ret_val;
David Ertmanb3e5bf12014-05-06 03:50:17 +00003381
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003382 if (!rar_entries)
3383 break;
Brian Walsh847042a2016-04-12 23:22:30 -04003384 ret_val = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
3385 if (ret_val < 0)
David Ertmanb3e5bf12014-05-06 03:50:17 +00003386 return -ENOMEM;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003387 count++;
3388 }
3389 }
3390
3391 /* zero out the remaining RAR entries not used above */
3392 for (; rar_entries > 0; rar_entries--) {
3393 ew32(RAH(rar_entries), 0);
3394 ew32(RAL(rar_entries), 0);
3395 }
3396 e1e_flush();
3397
3398 return count;
3399}
3400
3401/**
3402 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3403 * @netdev: network interface device structure
3404 *
3405 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3406 * address list or the network interface flags are updated. This routine is
3407 * responsible for configuring the hardware for proper unicast, multicast,
3408 * promiscuous mode, and all-multi behavior.
3409 **/
3410static void e1000e_set_rx_mode(struct net_device *netdev)
3411{
3412 struct e1000_adapter *adapter = netdev_priv(netdev);
3413 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003414 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003415
David Ertman63eb48f2014-02-14 07:16:46 +00003416 if (pm_runtime_suspended(netdev->dev.parent))
3417 return;
3418
Auke Kokbc7f75f2007-09-17 12:30:59 -07003419 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003420 rctl = er32(RCTL);
3421
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003422 /* clear the affected bits */
3423 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3424
Auke Kokbc7f75f2007-09-17 12:30:59 -07003425 if (netdev->flags & IFF_PROMISC) {
3426 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003427 /* Do not hardware filter VLANs in promisc mode */
3428 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003429 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003430 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003431
Patrick McHardy746b9f02008-07-16 20:15:45 -07003432 if (netdev->flags & IFF_ALLMULTI) {
3433 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003434 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003435 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003436 * then we should just turn on promiscuous mode so
3437 * that we can at least receive multicast traffic
3438 */
3439 count = e1000e_write_mc_addr_list(netdev);
3440 if (count < 0)
3441 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003442 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003443 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003444 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003445 * sufficient space to store all the addresses then enable
3446 * unicast promiscuous mode
3447 */
3448 count = e1000e_write_uc_addr_list(netdev);
3449 if (count < 0)
3450 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003451 }
3452
3453 ew32(RCTL, rctl);
3454
Jarod Wilson83808642016-06-09 19:50:13 -04003455 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003456 e1000e_vlan_strip_enable(adapter);
3457 else
3458 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003459}
3460
Bruce Allan70495a52012-01-11 01:26:50 +00003461static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3462{
3463 struct e1000_hw *hw = &adapter->hw;
3464 u32 mrqc, rxcsum;
Eric Dumazet5c8d19d2014-11-16 06:23:11 -08003465 u32 rss_key[10];
Bruce Allan70495a52012-01-11 01:26:50 +00003466 int i;
Bruce Allan70495a52012-01-11 01:26:50 +00003467
Eric Dumazet5c8d19d2014-11-16 06:23:11 -08003468 netdev_rss_key_fill(rss_key, sizeof(rss_key));
Bruce Allan70495a52012-01-11 01:26:50 +00003469 for (i = 0; i < 10; i++)
Eric Dumazet5c8d19d2014-11-16 06:23:11 -08003470 ew32(RSSRK(i), rss_key[i]);
Bruce Allan70495a52012-01-11 01:26:50 +00003471
3472 /* Direct all traffic to queue 0 */
3473 for (i = 0; i < 32; i++)
3474 ew32(RETA(i), 0);
3475
Bruce Allane921eb12012-11-28 09:28:37 +00003476 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003477 * descriptor on writeback.
3478 */
3479 rxcsum = er32(RXCSUM);
3480 rxcsum |= E1000_RXCSUM_PCSD;
3481
3482 ew32(RXCSUM, rxcsum);
3483
3484 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3485 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3486 E1000_MRQC_RSS_FIELD_IPV6 |
3487 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3488 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3489
3490 ew32(MRQC, mrqc);
3491}
3492
Auke Kokbc7f75f2007-09-17 12:30:59 -07003493/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003494 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3495 * @adapter: board private structure
3496 * @timinca: pointer to returned time increment attributes
3497 *
3498 * Get attributes for incrementing the System Time Register SYSTIML/H at
3499 * the default base frequency, and set the cyclecounter shift value.
3500 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003501s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003502{
3503 struct e1000_hw *hw = &adapter->hw;
3504 u32 incvalue, incperiod, shift;
3505
David Ertman79849eb2015-02-10 09:10:43 +00003506 /* Make sure clock is enabled on I217/I218/I219 before checking
3507 * the frequency
3508 */
Sasha Neftinc8744f42017-04-06 10:26:47 +03003509 if ((hw->mac.type >= e1000_pch_lpt) &&
Bruce Allanb67e1912012-12-27 08:32:33 +00003510 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3511 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3512 u32 fextnvm7 = er32(FEXTNVM7);
3513
Jacob Keller18dd2392016-04-13 16:08:32 -07003514 if (!(fextnvm7 & BIT(0))) {
3515 ew32(FEXTNVM7, fextnvm7 | BIT(0));
Bruce Allanb67e1912012-12-27 08:32:33 +00003516 e1e_flush();
3517 }
3518 }
3519
3520 switch (hw->mac.type) {
3521 case e1000_pch2lan:
Bernd Faust5313eec2017-02-16 19:42:07 +01003522 /* Stable 96MHz frequency */
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003523 incperiod = INCPERIOD_96MHZ;
3524 incvalue = INCVALUE_96MHZ;
3525 shift = INCVALUE_SHIFT_96MHZ;
3526 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
Bernd Faust5313eec2017-02-16 19:42:07 +01003527 break;
Bruce Allanb67e1912012-12-27 08:32:33 +00003528 case e1000_pch_lpt:
Yanir Lubetkin83129b32015-06-02 17:05:45 +03003529 if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
Bruce Allanb67e1912012-12-27 08:32:33 +00003530 /* Stable 96MHz frequency */
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003531 incperiod = INCPERIOD_96MHZ;
3532 incvalue = INCVALUE_96MHZ;
3533 shift = INCVALUE_SHIFT_96MHZ;
3534 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
Yanir Lubetkin83129b32015-06-02 17:05:45 +03003535 } else {
3536 /* Stable 25MHz frequency */
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003537 incperiod = INCPERIOD_25MHZ;
3538 incvalue = INCVALUE_25MHZ;
3539 shift = INCVALUE_SHIFT_25MHZ;
Yanir Lubetkin83129b32015-06-02 17:05:45 +03003540 adapter->cc.shift = shift;
3541 }
3542 break;
3543 case e1000_pch_spt:
Benjamin Poirierfff200c2018-05-10 16:28:35 +09003544 /* Stable 24MHz frequency */
3545 incperiod = INCPERIOD_24MHZ;
3546 incvalue = INCVALUE_24MHZ;
3547 shift = INCVALUE_SHIFT_24MHZ;
3548 adapter->cc.shift = shift;
3549 break;
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003550 case e1000_pch_cnp:
Sasha Neftinfb776f52019-10-16 11:08:38 +03003551 case e1000_pch_tgp:
Sasha Neftin59e46682020-01-19 13:57:13 +02003552 case e1000_pch_adp:
Sasha Neftincc23f4f2020-08-13 11:34:06 +03003553 case e1000_pch_mtp:
Sasha Neftin820b8ff2021-03-04 09:38:13 +02003554 case e1000_pch_lnp:
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003555 if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
3556 /* Stable 24MHz frequency */
3557 incperiod = INCPERIOD_24MHZ;
3558 incvalue = INCVALUE_24MHZ;
3559 shift = INCVALUE_SHIFT_24MHZ;
3560 adapter->cc.shift = shift;
3561 } else {
3562 /* Stable 38400KHz frequency */
3563 incperiod = INCPERIOD_38400KHZ;
3564 incvalue = INCVALUE_38400KHZ;
3565 shift = INCVALUE_SHIFT_38400KHZ;
3566 adapter->cc.shift = shift;
3567 }
3568 break;
Bruce Allanb67e1912012-12-27 08:32:33 +00003569 case e1000_82574:
3570 case e1000_82583:
3571 /* Stable 25MHz frequency */
Sasha Neftin68fe1d52017-04-06 10:27:03 +03003572 incperiod = INCPERIOD_25MHZ;
3573 incvalue = INCVALUE_25MHZ;
3574 shift = INCVALUE_SHIFT_25MHZ;
Bruce Allanb67e1912012-12-27 08:32:33 +00003575 adapter->cc.shift = shift;
3576 break;
3577 default:
3578 return -EINVAL;
3579 }
3580
3581 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3582 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3583
3584 return 0;
3585}
3586
3587/**
3588 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3589 * @adapter: board private structure
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07003590 * @config: timestamp configuration
Bruce Allanb67e1912012-12-27 08:32:33 +00003591 *
3592 * Outgoing time stamping can be enabled and disabled. Play nice and
3593 * disable it when requested, although it shouldn't cause any overhead
3594 * when no packet needs it. At most one packet in the queue may be
3595 * marked for time stamping, otherwise it would be impossible to tell
3596 * for sure to which packet the hardware time stamp belongs.
3597 *
3598 * Incoming time stamping has to be configured via the hardware filters.
3599 * Not all combinations are supported, in particular event type has to be
3600 * specified. Matching the kind of event packet is not supported, with the
3601 * exception of "all V2 events regardless of level 2 or 4".
3602 **/
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003603static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
3604 struct hwtstamp_config *config)
Bruce Allanb67e1912012-12-27 08:32:33 +00003605{
3606 struct e1000_hw *hw = &adapter->hw;
Bruce Allanb67e1912012-12-27 08:32:33 +00003607 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3608 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003609 u32 rxmtrl = 0;
3610 u16 rxudp = 0;
3611 bool is_l4 = false;
3612 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003613 u32 regval;
Bruce Allanb67e1912012-12-27 08:32:33 +00003614
3615 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3616 return -EINVAL;
3617
Bruce Allanb67e1912012-12-27 08:32:33 +00003618 switch (config->tx_type) {
3619 case HWTSTAMP_TX_OFF:
3620 tsync_tx_ctl = 0;
3621 break;
3622 case HWTSTAMP_TX_ON:
3623 break;
3624 default:
3625 return -ERANGE;
3626 }
3627
3628 switch (config->rx_filter) {
3629 case HWTSTAMP_FILTER_NONE:
3630 tsync_rx_ctl = 0;
3631 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003632 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3633 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3634 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3635 is_l4 = true;
3636 break;
3637 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3638 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3639 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3640 is_l4 = true;
3641 break;
3642 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3643 /* Also time stamps V2 L2 Path Delay Request/Response */
3644 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3645 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3646 is_l2 = true;
3647 break;
3648 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3649 /* Also time stamps V2 L2 Path Delay Request/Response. */
3650 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3651 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3652 is_l2 = true;
3653 break;
3654 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
Jeff Kirsher5463fce62020-06-03 20:07:26 -07003655 /* Hardware cannot filter just V2 L4 Sync messages */
3656 fallthrough;
Bruce Alland89777b2013-01-19 01:09:58 +00003657 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3658 /* Also time stamps V2 Path Delay Request/Response. */
3659 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3660 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3661 is_l2 = true;
3662 is_l4 = true;
3663 break;
3664 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
Jeff Kirsher5463fce62020-06-03 20:07:26 -07003665 /* Hardware cannot filter just V2 L4 Delay Request messages */
3666 fallthrough;
Bruce Alland89777b2013-01-19 01:09:58 +00003667 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3668 /* Also time stamps V2 Path Delay Request/Response. */
3669 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3670 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3671 is_l2 = true;
3672 is_l4 = true;
3673 break;
3674 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3675 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
Jeff Kirsher5463fce62020-06-03 20:07:26 -07003676 /* Hardware cannot filter just V2 L4 or L2 Event messages */
3677 fallthrough;
Bruce Alland89777b2013-01-19 01:09:58 +00003678 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3679 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3680 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3681 is_l2 = true;
3682 is_l4 = true;
3683 break;
3684 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3685 /* For V1, the hardware can only filter Sync messages or
3686 * Delay Request messages but not both so fall-through to
3687 * time stamp all packets.
3688 */
Jeff Kirsher5463fce62020-06-03 20:07:26 -07003689 fallthrough;
Miroslav Lichvare3412572017-05-19 17:52:36 +02003690 case HWTSTAMP_FILTER_NTP_ALL:
Bruce Allanb67e1912012-12-27 08:32:33 +00003691 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003692 is_l2 = true;
3693 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003694 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3695 config->rx_filter = HWTSTAMP_FILTER_ALL;
3696 break;
3697 default:
3698 return -ERANGE;
3699 }
3700
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003701 adapter->hwtstamp_config = *config;
3702
Bruce Allanb67e1912012-12-27 08:32:33 +00003703 /* enable/disable Tx h/w time stamping */
3704 regval = er32(TSYNCTXCTL);
3705 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3706 regval |= tsync_tx_ctl;
3707 ew32(TSYNCTXCTL, regval);
3708 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3709 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3710 e_err("Timesync Tx Control register not set as expected\n");
3711 return -EAGAIN;
3712 }
3713
3714 /* enable/disable Rx h/w time stamping */
3715 regval = er32(TSYNCRXCTL);
3716 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3717 regval |= tsync_rx_ctl;
3718 ew32(TSYNCRXCTL, regval);
3719 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3720 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3721 (regval & (E1000_TSYNCRXCTL_ENABLED |
3722 E1000_TSYNCRXCTL_TYPE_MASK))) {
3723 e_err("Timesync Rx Control register not set as expected\n");
3724 return -EAGAIN;
3725 }
3726
Bruce Alland89777b2013-01-19 01:09:58 +00003727 /* L2: define ethertype filter for time stamped packets */
3728 if (is_l2)
3729 rxmtrl |= ETH_P_1588;
3730
3731 /* define which PTP packets get time stamped */
3732 ew32(RXMTRL, rxmtrl);
3733
3734 /* Filter by destination port */
3735 if (is_l4) {
3736 rxudp = PTP_EV_PORT;
3737 cpu_to_be16s(&rxudp);
3738 }
3739 ew32(RXUDP, rxudp);
3740
3741 e1e_flush();
3742
Bruce Allanb67e1912012-12-27 08:32:33 +00003743 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003744 er32(RXSTMPH);
3745 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003746
Bruce Allanb67e1912012-12-27 08:32:33 +00003747 return 0;
3748}
3749
3750/**
Bruce Allanad680762008-03-28 09:15:03 -07003751 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003752 * @adapter: private board structure
3753 **/
3754static void e1000_configure(struct e1000_adapter *adapter)
3755{
Bruce Allan55aa6982011-12-16 00:45:45 +00003756 struct e1000_ring *rx_ring = adapter->rx_ring;
3757
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003758 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759
3760 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003761 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003762
3763 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003764
3765 if (adapter->netdev->features & NETIF_F_RXHASH)
3766 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003767 e1000_setup_rctl(adapter);
3768 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003769 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003770}
3771
3772/**
3773 * e1000e_power_up_phy - restore link in case the phy was powered down
3774 * @adapter: address of board private structure
3775 *
3776 * The phy may be powered down to save power and turn off link when the
3777 * driver is unloaded and wake on lan is not enabled (among others)
3778 * *** this routine MUST be followed by a call to e1000e_reset ***
3779 **/
3780void e1000e_power_up_phy(struct e1000_adapter *adapter)
3781{
Bruce Allan17f208d2009-12-01 15:47:22 +00003782 if (adapter->hw.phy.ops.power_up)
3783 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003784
3785 adapter->hw.mac.ops.setup_link(&adapter->hw);
3786}
3787
3788/**
3789 * e1000_power_down_phy - Power down the PHY
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07003790 * @adapter: board private structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07003791 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003792 * Power down the PHY so no link is implied when interface is down.
3793 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003794 */
3795static void e1000_power_down_phy(struct e1000_adapter *adapter)
3796{
Bruce Allan17f208d2009-12-01 15:47:22 +00003797 if (adapter->hw.phy.ops.power_down)
3798 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003799}
3800
3801/**
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003802 * e1000_flush_tx_ring - remove all descriptors from the tx_ring
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07003803 * @adapter: board private structure
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003804 *
3805 * We want to clear all pending descriptors from the TX ring.
3806 * zeroing happens when the HW reads the regs. We assign the ring itself as
3807 * the data of the next descriptor. We don't care about the data we are about
3808 * to reset the HW.
3809 */
3810static void e1000_flush_tx_ring(struct e1000_adapter *adapter)
3811{
3812 struct e1000_hw *hw = &adapter->hw;
3813 struct e1000_ring *tx_ring = adapter->tx_ring;
3814 struct e1000_tx_desc *tx_desc = NULL;
3815 u32 tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS;
3816 u16 size = 512;
3817
3818 tctl = er32(TCTL);
3819 ew32(TCTL, tctl | E1000_TCTL_EN);
3820 tdt = er32(TDT(0));
3821 BUG_ON(tdt != tx_ring->next_to_use);
3822 tx_desc = E1000_TX_DESC(*tx_ring, tx_ring->next_to_use);
Ben Dooks (Codethink)99fe61b2019-12-18 09:53:08 +00003823 tx_desc->buffer_addr = cpu_to_le64(tx_ring->dma);
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003824
3825 tx_desc->lower.data = cpu_to_le32(txd_lower | size);
3826 tx_desc->upper.data = 0;
3827 /* flush descriptors to memory before notifying the HW */
3828 wmb();
3829 tx_ring->next_to_use++;
3830 if (tx_ring->next_to_use == tx_ring->count)
3831 tx_ring->next_to_use = 0;
3832 ew32(TDT(0), tx_ring->next_to_use);
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003833 usleep_range(200, 250);
3834}
3835
3836/**
3837 * e1000_flush_rx_ring - remove all descriptors from the rx_ring
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07003838 * @adapter: board private structure
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003839 *
3840 * Mark all descriptors in the RX ring as consumed and disable the rx ring
3841 */
3842static void e1000_flush_rx_ring(struct e1000_adapter *adapter)
3843{
3844 u32 rctl, rxdctl;
3845 struct e1000_hw *hw = &adapter->hw;
3846
3847 rctl = er32(RCTL);
3848 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3849 e1e_flush();
3850 usleep_range(100, 150);
3851
3852 rxdctl = er32(RXDCTL(0));
3853 /* zero the lower 14 bits (prefetch and host thresholds) */
3854 rxdctl &= 0xffffc000;
3855
3856 /* update thresholds: prefetch threshold to 31, host threshold to 1
3857 * and make sure the granularity is "descriptors" and not "cache lines"
3858 */
Jacob Keller18dd2392016-04-13 16:08:32 -07003859 rxdctl |= (0x1F | BIT(8) | E1000_RXDCTL_THRESH_UNIT_DESC);
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003860
3861 ew32(RXDCTL(0), rxdctl);
3862 /* momentarily enable the RX ring for the changes to take effect */
3863 ew32(RCTL, rctl | E1000_RCTL_EN);
3864 e1e_flush();
3865 usleep_range(100, 150);
3866 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3867}
3868
3869/**
3870 * e1000_flush_desc_rings - remove all descriptors from the descriptor rings
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07003871 * @adapter: board private structure
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003872 *
3873 * In i219, the descriptor rings must be emptied before resetting the HW
3874 * or before changing the device state to D3 during runtime (runtime PM).
3875 *
3876 * Failure to do this will cause the HW to enter a unit hang state which can
3877 * only be released by PCI reset on the device
3878 *
3879 */
3880
3881static void e1000_flush_desc_rings(struct e1000_adapter *adapter)
3882{
Yanir Lubetkinff9174292015-06-02 17:05:38 +03003883 u16 hang_state;
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003884 u32 fext_nvm11, tdlen;
3885 struct e1000_hw *hw = &adapter->hw;
3886
3887 /* First, disable MULR fix in FEXTNVM11 */
3888 fext_nvm11 = er32(FEXTNVM11);
3889 fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
3890 ew32(FEXTNVM11, fext_nvm11);
3891 /* do nothing if we're not in faulty state, or if the queue is empty */
3892 tdlen = er32(TDLEN(0));
Yanir Lubetkinff9174292015-06-02 17:05:38 +03003893 pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
3894 &hang_state);
3895 if (!(hang_state & FLUSH_DESC_REQUIRED) || !tdlen)
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003896 return;
3897 e1000_flush_tx_ring(adapter);
3898 /* recheck, maybe the fault is caused by the rx ring */
Yanir Lubetkinff9174292015-06-02 17:05:38 +03003899 pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
3900 &hang_state);
3901 if (hang_state & FLUSH_DESC_REQUIRED)
Yanir Lubetkinad851fb2015-04-14 02:20:21 +03003902 e1000_flush_rx_ring(adapter);
3903}
3904
3905/**
Jacob Kelleraa524b62016-04-20 11:36:42 -07003906 * e1000e_systim_reset - reset the timesync registers after a hardware reset
3907 * @adapter: board private structure
3908 *
3909 * When the MAC is reset, all hardware bits for timesync will be reset to the
3910 * default values. This function will restore the settings last in place.
3911 * Since the clock SYSTIME registers are reset, we will simply restore the
3912 * cyclecounter to the kernel real clock time.
3913 **/
3914static void e1000e_systim_reset(struct e1000_adapter *adapter)
3915{
3916 struct ptp_clock_info *info = &adapter->ptp_clock_info;
3917 struct e1000_hw *hw = &adapter->hw;
3918 unsigned long flags;
3919 u32 timinca;
3920 s32 ret_val;
3921
3922 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3923 return;
3924
3925 if (info->adjfreq) {
3926 /* restore the previous ptp frequency delta */
3927 ret_val = info->adjfreq(info, adapter->ptp_delta);
3928 } else {
3929 /* set the default base frequency if no adjustment possible */
3930 ret_val = e1000e_get_base_timinca(adapter, &timinca);
3931 if (!ret_val)
3932 ew32(TIMINCA, timinca);
3933 }
3934
3935 if (ret_val) {
3936 dev_warn(&adapter->pdev->dev,
3937 "Failed to restore TIMINCA clock rate delta: %d\n",
3938 ret_val);
3939 return;
3940 }
3941
3942 /* reset the systim ns time counter */
3943 spin_lock_irqsave(&adapter->systim_lock, flags);
3944 timecounter_init(&adapter->tc, &adapter->cc,
3945 ktime_to_ns(ktime_get_real()));
3946 spin_unlock_irqrestore(&adapter->systim_lock, flags);
3947
3948 /* restore the previous hwtstamp configuration settings */
3949 e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
3950}
3951
3952/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003953 * e1000e_reset - bring the hardware into a known good state
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07003954 * @adapter: board private structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07003955 *
3956 * This function boots the hardware and enables some settings that
3957 * require a configuration cycle of the hardware - those cannot be
3958 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003959 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003960 */
3961void e1000e_reset(struct e1000_adapter *adapter)
3962{
3963 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003964 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003965 struct e1000_hw *hw = &adapter->hw;
3966 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003967 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003968 u16 hwm;
3969
Bruce Allanad680762008-03-28 09:15:03 -07003970 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003971 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003972
Alexander Duyck8084b862015-05-02 00:52:00 -07003973 if (adapter->max_frame_size > (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003974 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003975 * large enough to accommodate two full transmit packets,
3976 * rounded up to the next 1KB and expressed in KB. Likewise,
3977 * the Rx FIFO should be large enough to accommodate at least
3978 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003979 * expressed in KB.
3980 */
Auke Kokdf762462007-10-25 13:57:53 -07003981 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003982 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003983 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003984 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003985 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003986 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003987 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003988 */
3989 min_tx_space = (adapter->max_frame_size +
Bruce Allane5fe2542013-02-20 04:06:27 +00003990 sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003991 min_tx_space = ALIGN(min_tx_space, 1024);
3992 min_tx_space >>= 10;
3993 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003994 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003995 min_rx_space = ALIGN(min_rx_space, 1024);
3996 min_rx_space >>= 10;
3997
Bruce Allane921eb12012-11-28 09:28:37 +00003998 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003999 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07004000 * allocation, take space away from current Rx allocation
4001 */
Auke Kokdf762462007-10-25 13:57:53 -07004002 if ((tx_space < min_tx_space) &&
4003 ((min_tx_space - tx_space) < pba)) {
4004 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004005
Bruce Allane921eb12012-11-28 09:28:37 +00004006 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00004007 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07004008 */
Bruce Allan79d4e902011-12-16 00:46:27 +00004009 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07004010 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004011 }
Auke Kokdf762462007-10-25 13:57:53 -07004012
4013 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004014 }
4015
Bruce Allane921eb12012-11-28 09:28:37 +00004016 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07004017 *
Bruce Allan38eb3942009-11-19 12:34:20 +00004018 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07004019 * (or the size used for early receive) above it in the Rx FIFO.
4020 * Set it to the lower of:
4021 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00004022 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07004023 */
Bruce Alland3738bb2010-06-16 13:27:28 +00004024 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
4025 fc->pause_time = 0xFFFF;
4026 else
4027 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00004028 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00004029 fc->current_mode = fc->requested_mode;
4030
4031 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00004032 case e1000_ich9lan:
4033 case e1000_ich10lan:
4034 if (adapter->netdev->mtu > ETH_DATA_LEN) {
4035 pba = 14;
4036 ew32(PBA, pba);
4037 fc->high_water = 0x2800;
4038 fc->low_water = fc->high_water - 8;
4039 break;
4040 }
Jeff Kirsher5463fce62020-06-03 20:07:26 -07004041 fallthrough;
Bruce Alland3738bb2010-06-16 13:27:28 +00004042 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00004043 hwm = min(((pba << 10) * 9 / 10),
4044 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00004045
Bruce Allane80bd1d2013-05-01 01:19:46 +00004046 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
Bruce Alland3738bb2010-06-16 13:27:28 +00004047 fc->low_water = fc->high_water - 8;
4048 break;
4049 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00004050 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00004051 * loads. If hangs persist, try disabling Tx flow control.
4052 */
4053 if (adapter->netdev->mtu > ETH_DATA_LEN) {
4054 fc->high_water = 0x3500;
Bruce Allane80bd1d2013-05-01 01:19:46 +00004055 fc->low_water = 0x1500;
Bruce Allan38eb3942009-11-19 12:34:20 +00004056 } else {
4057 fc->high_water = 0x5000;
Bruce Allane80bd1d2013-05-01 01:19:46 +00004058 fc->low_water = 0x3000;
Bruce Allan38eb3942009-11-19 12:34:20 +00004059 }
Bruce Allana3055952010-05-10 15:02:12 +00004060 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00004061 break;
4062 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00004063 case e1000_pch_lpt:
David Ertman79849eb2015-02-10 09:10:43 +00004064 case e1000_pch_spt:
Sasha Neftinc8744f42017-04-06 10:26:47 +03004065 case e1000_pch_cnp:
Sasha Neftinfb776f52019-10-16 11:08:38 +03004066 case e1000_pch_tgp:
Sasha Neftin59e46682020-01-19 13:57:13 +02004067 case e1000_pch_adp:
Sasha Neftincc23f4f2020-08-13 11:34:06 +03004068 case e1000_pch_mtp:
Sasha Neftin820b8ff2021-03-04 09:38:13 +02004069 case e1000_pch_lnp:
Miguel Bernal Marinf74dc882017-03-27 16:01:56 -06004070 fc->refresh_time = 0xFFFF;
4071 fc->pause_time = 0xFFFF;
Bruce Allan347b5202012-12-08 00:35:35 +00004072
4073 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
4074 fc->high_water = 0x05C20;
4075 fc->low_water = 0x05048;
Bruce Allan347b5202012-12-08 00:35:35 +00004076 break;
Bruce Allan828bac82010-09-29 21:39:37 +00004077 }
Bruce Allan347b5202012-12-08 00:35:35 +00004078
Bruce Allance345e02013-06-21 09:07:07 +00004079 pba = 14;
4080 ew32(PBA, pba);
Bruce Allan347b5202012-12-08 00:35:35 +00004081 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
4082 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00004083 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00004084 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004085
Bruce Allane921eb12012-11-28 09:28:37 +00004086 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00004087 * maximum size per Tx descriptor limited only to the transmit
4088 * allocation of the packet buffer minus 96 bytes with an upper
4089 * limit of 24KB due to receive synchronization limitations.
4090 */
4091 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
4092 24 << 10);
4093
Bruce Allane921eb12012-11-28 09:28:37 +00004094 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00004095 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00004096 */
4097 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00004098 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00004099 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
4100 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00004101 "Interrupt Throttle Rate off\n");
Bruce Allan828bac82010-09-29 21:39:37 +00004102 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00004103 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00004104 }
4105 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
4106 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00004107 "Interrupt Throttle Rate on\n");
Bruce Allan828bac82010-09-29 21:39:37 +00004108 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
4109 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00004110 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00004111 }
4112 }
4113
Sasha Neftinc8744f42017-04-06 10:26:47 +03004114 if (hw->mac.type >= e1000_pch_spt)
Yanir Lubetkin0ffc5642015-04-22 04:15:01 +03004115 e1000_flush_desc_rings(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004116 /* Allow time for pending master requests to run */
4117 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004118
Bruce Allane921eb12012-11-28 09:28:37 +00004119 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004120 * that the network interface is in control
4121 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004122 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004123 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004124
Auke Kokbc7f75f2007-09-17 12:30:59 -07004125 ew32(WUC, 0);
4126
4127 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004128 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004129
4130 e1000_update_mng_vlan(adapter);
4131
4132 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
4133 ew32(VET, ETH_P_8021Q);
4134
4135 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004136
Jacob Kelleraa524b62016-04-20 11:36:42 -07004137 /* restore systim and hwtstamp settings */
4138 e1000e_systim_reset(adapter);
Bruce Allanb67e1912012-12-27 08:32:33 +00004139
Bruce Alland495bcb2013-03-20 07:23:11 +00004140 /* Set EEE advertisement as appropriate */
4141 if (adapter->flags2 & FLAG2_HAS_EEE) {
4142 s32 ret_val;
4143 u16 adv_addr;
4144
4145 switch (hw->phy.type) {
4146 case e1000_phy_82579:
4147 adv_addr = I82579_EEE_ADVERTISEMENT;
4148 break;
4149 case e1000_phy_i217:
4150 adv_addr = I217_EEE_ADVERTISEMENT;
4151 break;
4152 default:
4153 dev_err(&adapter->pdev->dev,
4154 "Invalid PHY type setting EEE advertisement\n");
4155 return;
4156 }
4157
4158 ret_val = hw->phy.ops.acquire(hw);
4159 if (ret_val) {
4160 dev_err(&adapter->pdev->dev,
4161 "EEE advertisement - unable to acquire PHY\n");
4162 return;
4163 }
4164
4165 e1000_write_emi_reg_locked(hw, adv_addr,
4166 hw->dev_spec.ich8lan.eee_disable ?
4167 0 : adapter->eee_advert);
4168
4169 hw->phy.ops.release(hw);
4170 }
4171
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004172 if (!netif_running(adapter->netdev) &&
David Ertman28002092014-02-14 07:16:41 +00004173 !test_bit(__E1000_TESTING, &adapter->state))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004174 e1000_power_down_phy(adapter);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004175
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176 e1000_get_phy_info(hw);
4177
Bruce Allan918d7192009-06-02 11:28:20 +00004178 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
4179 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004180 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00004181 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07004182 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07004183 * different we would do if it failed
4184 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004185 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
4186 phy_data &= ~IGP02E1000_PM_SPD;
4187 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
4188 }
Sasha Neftinc8744f42017-04-06 10:26:47 +03004189 if (hw->mac.type >= e1000_pch_spt && adapter->int_mode == 0) {
Yanir Lubetkinec945cf2015-06-02 17:05:42 +03004190 u32 reg;
4191
4192 /* Fextnvm7 @ 0xe4[2] = 1 */
4193 reg = er32(FEXTNVM7);
4194 reg |= E1000_FEXTNVM7_SIDE_CLK_UNGATE;
4195 ew32(FEXTNVM7, reg);
4196 /* Fextnvm9 @ 0x5bb4[13:12] = 11 */
4197 reg = er32(FEXTNVM9);
4198 reg |= E1000_FEXTNVM9_IOSFSB_CLKGATE_DIS |
4199 E1000_FEXTNVM9_IOSFSB_CLKREQ_DIS;
4200 ew32(FEXTNVM9, reg);
4201 }
4202
Auke Kokbc7f75f2007-09-17 12:30:59 -07004203}
4204
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004205/**
4206 * e1000e_trigger_lsc - trigger an LSC interrupt
4207 * @adapter:
4208 *
4209 * Fire a link status change interrupt to start the watchdog.
4210 **/
4211static void e1000e_trigger_lsc(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004212{
4213 struct e1000_hw *hw = &adapter->hw;
4214
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004215 if (adapter->msix_entries)
Benjamin Poirier4aea7a5c2017-07-21 11:36:27 -07004216 ew32(ICS, E1000_ICS_LSC | E1000_ICS_OTHER);
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004217 else
4218 ew32(ICS, E1000_ICS_LSC);
4219}
4220
4221void e1000e_up(struct e1000_adapter *adapter)
4222{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004223 /* hardware has been reset, we need to reload some things */
4224 e1000_configure(adapter);
4225
4226 clear_bit(__E1000_DOWN, &adapter->state);
4227
Bruce Allan4662e822008-08-26 18:37:06 -07004228 if (adapter->msix_entries)
4229 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004230 e1000_irq_enable(adapter);
4231
Konstantin Khlebnikovd17ba0f2019-04-17 11:13:20 +03004232 /* Tx queue started by watchdog timer when link is up */
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004233
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004234 e1000e_trigger_lsc(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004235}
4236
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004237static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
4238{
4239 struct e1000_hw *hw = &adapter->hw;
4240
4241 if (!(adapter->flags2 & FLAG2_DMA_BURST))
4242 return;
4243
4244 /* flush pending descriptor writebacks to memory */
4245 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4246 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4247
4248 /* execute the writes immediately */
4249 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00004250
Bruce Allane921eb12012-11-28 09:28:37 +00004251 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00004252 * write is successful
4253 */
4254 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4255 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4256
4257 /* execute the writes immediately */
4258 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004259}
4260
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004261static void e1000e_update_stats(struct e1000_adapter *adapter);
4262
David Ertman28002092014-02-14 07:16:41 +00004263/**
4264 * e1000e_down - quiesce the device and optionally reset the hardware
4265 * @adapter: board private structure
4266 * @reset: boolean flag to reset the hardware or not
4267 */
4268void e1000e_down(struct e1000_adapter *adapter, bool reset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004269{
4270 struct net_device *netdev = adapter->netdev;
4271 struct e1000_hw *hw = &adapter->hw;
4272 u32 tctl, rctl;
4273
Bruce Allane921eb12012-11-28 09:28:37 +00004274 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07004275 * reschedule our watchdog timer
4276 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004277 set_bit(__E1000_DOWN, &adapter->state);
4278
Eliezer Tamira60a1322015-03-20 17:41:52 -07004279 netif_carrier_off(netdev);
4280
Auke Kokbc7f75f2007-09-17 12:30:59 -07004281 /* disable receives in the hardware */
4282 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07004283 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
4284 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004285 /* flush and sleep below */
4286
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004287 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004288
4289 /* disable transmits in the hardware */
4290 tctl = er32(TCTL);
4291 tctl &= ~E1000_TCTL_EN;
4292 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004293
Auke Kokbc7f75f2007-09-17 12:30:59 -07004294 /* flush both disables and wait for them to finish */
4295 e1e_flush();
Arjan van de Venab6973a2019-06-14 17:29:35 -07004296 usleep_range(10000, 11000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004297
Auke Kokbc7f75f2007-09-17 12:30:59 -07004298 e1000_irq_disable(adapter);
4299
Bruce Allana3b87a42013-04-20 05:37:29 +00004300 napi_synchronize(&adapter->napi);
4301
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08004302 del_timer_sync(&adapter->watchdog_timer);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004303 del_timer_sync(&adapter->phy_info_timer);
4304
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004305 spin_lock(&adapter->stats64_lock);
4306 e1000e_update_stats(adapter);
4307 spin_unlock(&adapter->stats64_lock);
4308
Bruce Allan400484f2011-05-13 07:20:03 +00004309 e1000e_flush_descriptors(adapter);
Bruce Allan400484f2011-05-13 07:20:03 +00004310
Auke Kokbc7f75f2007-09-17 12:30:59 -07004311 adapter->link_speed = 0;
4312 adapter->link_duplex = 0;
4313
Bruce Allanda1e20462013-06-21 09:07:02 +00004314 /* Disable Si errata workaround on PCHx for jumbo frame flow */
4315 if ((hw->mac.type >= e1000_pch2lan) &&
4316 (adapter->netdev->mtu > ETH_DATA_LEN) &&
4317 e1000_lv_jumbo_workaround_ich8lan(hw, false))
4318 e_dbg("failed to disable jumbo frame workaround mode\n");
4319
Yanir Lubetkin0ffc5642015-04-22 04:15:01 +03004320 if (!pci_channel_offline(adapter->pdev)) {
4321 if (reset)
4322 e1000e_reset(adapter);
Sasha Neftinc8744f42017-04-06 10:26:47 +03004323 else if (hw->mac.type >= e1000_pch_spt)
Yanir Lubetkin0ffc5642015-04-22 04:15:01 +03004324 e1000_flush_desc_rings(adapter);
4325 }
4326 e1000_clean_tx_ring(adapter->tx_ring);
4327 e1000_clean_rx_ring(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004328}
4329
4330void e1000e_reinit_locked(struct e1000_adapter *adapter)
4331{
4332 might_sleep();
4333 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Arjan van de Venab6973a2019-06-14 17:29:35 -07004334 usleep_range(1000, 1100);
David Ertman28002092014-02-14 07:16:41 +00004335 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004336 e1000e_up(adapter);
4337 clear_bit(__E1000_RESETTING, &adapter->state);
4338}
4339
4340/**
Jarod Wilson0be5b962016-07-26 14:25:34 -04004341 * e1000e_sanitize_systim - sanitize raw cycle counter reads
4342 * @hw: pointer to the HW structure
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004343 * @systim: PHC time value read, sanitized and returned
4344 * @sts: structure to hold system time before and after reading SYSTIML,
4345 * may be NULL
Jarod Wilson0be5b962016-07-26 14:25:34 -04004346 *
4347 * Errata for 82574/82583 possible bad bits read from SYSTIMH/L:
4348 * check to see that the time is incrementing at a reasonable
4349 * rate and is a multiple of incvalue.
4350 **/
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004351static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim,
4352 struct ptp_system_timestamp *sts)
Jarod Wilson0be5b962016-07-26 14:25:34 -04004353{
4354 u64 time_delta, rem, temp;
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004355 u64 systim_next;
Jarod Wilson0be5b962016-07-26 14:25:34 -04004356 u32 incvalue;
4357 int i;
4358
4359 incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
4360 for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
4361 /* latch SYSTIMH on read of SYSTIML */
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004362 ptp_read_system_prets(sts);
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004363 systim_next = (u64)er32(SYSTIML);
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004364 ptp_read_system_postts(sts);
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004365 systim_next |= (u64)er32(SYSTIMH) << 32;
Jarod Wilson0be5b962016-07-26 14:25:34 -04004366
4367 time_delta = systim_next - systim;
4368 temp = time_delta;
4369 /* VMWare users have seen incvalue of zero, don't div / 0 */
4370 rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0);
4371
4372 systim = systim_next;
4373
4374 if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0))
4375 break;
4376 }
4377
4378 return systim;
4379}
4380
4381/**
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004382 * e1000e_read_systim - read SYSTIM register
4383 * @adapter: board private structure
4384 * @sts: structure which will contain system time before and after reading
4385 * SYSTIML, may be NULL
Bruce Allanb67e1912012-12-27 08:32:33 +00004386 **/
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004387u64 e1000e_read_systim(struct e1000_adapter *adapter,
4388 struct ptp_system_timestamp *sts)
Bruce Allanb67e1912012-12-27 08:32:33 +00004389{
Bruce Allanb67e1912012-12-27 08:32:33 +00004390 struct e1000_hw *hw = &adapter->hw;
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004391 u32 systimel, systimel_2, systimeh;
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004392 u64 systim;
Raanan Avargil37b129102015-07-19 16:33:20 +03004393 /* SYSTIMH latching upon SYSTIML read does not work well.
4394 * This means that if SYSTIML overflows after we read it but before
4395 * we read SYSTIMH, the value of SYSTIMH has been incremented and we
4396 * will experience a huge non linear increment in the systime value
4397 * to fix that we test for overflow and if true, we re-read systime.
Yanir Lubetkin83129b32015-06-02 17:05:45 +03004398 */
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004399 ptp_read_system_prets(sts);
Denys Vlasenkoab507c92016-04-20 17:45:56 +02004400 systimel = er32(SYSTIML);
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004401 ptp_read_system_postts(sts);
Raanan Avargil37b129102015-07-19 16:33:20 +03004402 systimeh = er32(SYSTIMH);
Denys Vlasenkoab507c92016-04-20 17:45:56 +02004403 /* Is systimel is so large that overflow is possible? */
4404 if (systimel >= (u32)0xffffffff - E1000_TIMINCA_INCVALUE_MASK) {
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004405 ptp_read_system_prets(sts);
4406 systimel_2 = er32(SYSTIML);
4407 ptp_read_system_postts(sts);
Denys Vlasenkoab507c92016-04-20 17:45:56 +02004408 if (systimel > systimel_2) {
4409 /* There was an overflow, read again SYSTIMH, and use
4410 * systimel_2
4411 */
4412 systimeh = er32(SYSTIMH);
4413 systimel = systimel_2;
4414 }
Raanan Avargil37b129102015-07-19 16:33:20 +03004415 }
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +01004416 systim = (u64)systimel;
4417 systim |= (u64)systimeh << 32;
Bruce Allanb67e1912012-12-27 08:32:33 +00004418
Jarod Wilson0be5b962016-07-26 14:25:34 -04004419 if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW)
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004420 systim = e1000e_sanitize_systim(hw, systim, sts);
Todd Fujinaka5e7ff972014-05-03 06:41:37 +00004421
Bruce Allanb67e1912012-12-27 08:32:33 +00004422 return systim;
4423}
4424
4425/**
Miroslav Lichvar98942d72018-11-09 11:14:46 +01004426 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4427 * @cc: cyclecounter structure
4428 **/
4429static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc)
4430{
4431 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4432 cc);
4433
4434 return e1000e_read_systim(adapter, NULL);
4435}
4436
4437/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004438 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4439 * @adapter: board private structure to initialize
4440 *
4441 * e1000_sw_init initializes the Adapter private data structure.
4442 * Fields are initialized based on PCI device information and
4443 * OS network device settings (MTU size).
4444 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004445static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004446{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004447 struct net_device *netdev = adapter->netdev;
4448
Alexander Duyck8084b862015-05-02 00:52:00 -07004449 adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004450 adapter->rx_ps_bsize0 = 128;
Alexander Duyck8084b862015-05-02 00:52:00 -07004451 adapter->max_frame_size = netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004452 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004453 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4454 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004455
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004456 spin_lock_init(&adapter->stats64_lock);
4457
Bruce Allan4662e822008-08-26 18:37:06 -07004458 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004459
Bruce Allan4662e822008-08-26 18:37:06 -07004460 if (e1000_alloc_queues(adapter))
4461 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004462
Bruce Allanb67e1912012-12-27 08:32:33 +00004463 /* Setup hardware time stamping cyclecounter */
4464 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4465 adapter->cc.read = e1000e_cyclecounter_read;
Richard Cochran4d045b42015-01-02 20:22:05 +01004466 adapter->cc.mask = CYCLECOUNTER_MASK(64);
Bruce Allanb67e1912012-12-27 08:32:33 +00004467 adapter->cc.mult = 1;
4468 /* cc.shift set in e1000e_get_base_tininca() */
4469
4470 spin_lock_init(&adapter->systim_lock);
4471 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4472 }
4473
Auke Kokbc7f75f2007-09-17 12:30:59 -07004474 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004475 e1000_irq_disable(adapter);
4476
Auke Kokbc7f75f2007-09-17 12:30:59 -07004477 set_bit(__E1000_DOWN, &adapter->state);
4478 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004479}
4480
4481/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004482 * e1000_intr_msi_test - Interrupt Handler
4483 * @irq: interrupt number
4484 * @data: pointer to a network interface device structure
4485 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004486static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004487{
4488 struct net_device *netdev = data;
4489 struct e1000_adapter *adapter = netdev_priv(netdev);
4490 struct e1000_hw *hw = &adapter->hw;
4491 u32 icr = er32(ICR);
4492
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004493 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004494 if (icr & E1000_ICR_RXSEQ) {
4495 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004496 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004497 * interrupt is handled.
4498 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004499 wmb();
4500 }
4501
4502 return IRQ_HANDLED;
4503}
4504
4505/**
4506 * e1000_test_msi_interrupt - Returns 0 for successful test
4507 * @adapter: board private struct
4508 *
4509 * code flow taken from tg3.c
4510 **/
4511static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4512{
4513 struct net_device *netdev = adapter->netdev;
4514 struct e1000_hw *hw = &adapter->hw;
4515 int err;
4516
4517 /* poll_enable hasn't been called yet, so don't need disable */
4518 /* clear any pending events */
4519 er32(ICR);
4520
4521 /* free the real vector and request a test handler */
4522 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004523 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004524
4525 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004526 * MSI irq handler will unset this flag
4527 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004528 adapter->flags |= FLAG_MSI_TEST_FAILED;
4529
4530 err = pci_enable_msi(adapter->pdev);
4531 if (err)
4532 goto msi_test_failed;
4533
Joe Perchesa0607fd2009-11-18 23:29:17 -08004534 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004535 netdev->name, netdev);
4536 if (err) {
4537 pci_disable_msi(adapter->pdev);
4538 goto msi_test_failed;
4539 }
4540
Bruce Allane921eb12012-11-28 09:28:37 +00004541 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004542 * interrupt.
4543 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004544 wmb();
4545
4546 e1000_irq_enable(adapter);
4547
4548 /* fire an unusual interrupt on the test handler */
4549 ew32(ICS, E1000_ICS_RXSEQ);
4550 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004551 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004552
4553 e1000_irq_disable(adapter);
4554
Bruce Allanbc763292012-08-17 06:18:07 +00004555 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004556
4557 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004558 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004559 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004560 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004561 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004562 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004563
4564 free_irq(adapter->pdev->irq, netdev);
4565 pci_disable_msi(adapter->pdev);
4566
Bruce Allanf8d59f72008-08-08 18:36:11 -07004567msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004568 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004569 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004570}
4571
4572/**
4573 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4574 * @adapter: board private struct
4575 *
4576 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4577 **/
4578static int e1000_test_msi(struct e1000_adapter *adapter)
4579{
4580 int err;
4581 u16 pci_cmd;
4582
4583 if (!(adapter->flags & FLAG_MSI_ENABLED))
4584 return 0;
4585
4586 /* disable SERR in case the MSI write causes a master abort */
4587 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004588 if (pci_cmd & PCI_COMMAND_SERR)
4589 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4590 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004591
4592 err = e1000_test_msi_interrupt(adapter);
4593
Dean Nelson36f24072010-06-29 18:12:05 +00004594 /* re-enable SERR */
4595 if (pci_cmd & PCI_COMMAND_SERR) {
4596 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4597 pci_cmd |= PCI_COMMAND_SERR;
4598 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4599 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004600
Bruce Allanf8d59f72008-08-08 18:36:11 -07004601 return err;
4602}
4603
4604/**
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01004605 * e1000e_open - Called when a network interface is made active
Auke Kokbc7f75f2007-09-17 12:30:59 -07004606 * @netdev: network interface device structure
4607 *
4608 * Returns 0 on success, negative value on failure
4609 *
4610 * The open entry point is called when a network interface is made
4611 * active by the system (IFF_UP). At this point all resources needed
4612 * for transmit and receive operations are allocated, the interrupt
4613 * handler is registered with the OS, the watchdog timer is started,
4614 * and the stack is notified that the interface is ready.
4615 **/
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01004616int e1000e_open(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004617{
4618 struct e1000_adapter *adapter = netdev_priv(netdev);
4619 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004620 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004621 int err;
4622
4623 /* disallow open during test */
4624 if (test_bit(__E1000_TESTING, &adapter->state))
4625 return -EBUSY;
4626
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004627 pm_runtime_get_sync(&pdev->dev);
4628
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004629 netif_carrier_off(netdev);
Konstantin Khlebnikovd17ba0f2019-04-17 11:13:20 +03004630 netif_stop_queue(netdev);
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004631
Auke Kokbc7f75f2007-09-17 12:30:59 -07004632 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004633 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004634 if (err)
4635 goto err_setup_tx;
4636
4637 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004638 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004639 if (err)
4640 goto err_setup_rx;
4641
Bruce Allane921eb12012-11-28 09:28:37 +00004642 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004643 * interface is now open and reset the part to a known state.
4644 */
4645 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004646 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004647 e1000e_reset(adapter);
4648 }
4649
Auke Kokbc7f75f2007-09-17 12:30:59 -07004650 e1000e_power_up_phy(adapter);
4651
4652 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Bruce Allane5fe2542013-02-20 04:06:27 +00004653 if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004654 e1000_update_mng_vlan(adapter);
4655
Bruce Allan79d4e902011-12-16 00:46:27 +00004656 /* DMA latency requirement to workaround jumbo issue */
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01004657 cpu_latency_qos_add_request(&adapter->pm_qos_req, PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004658
Bruce Allane921eb12012-11-28 09:28:37 +00004659 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004660 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4661 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004662 * clean_rx handler before we do so.
4663 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004664 e1000_configure(adapter);
4665
4666 err = e1000_request_irq(adapter);
4667 if (err)
4668 goto err_req_irq;
4669
Bruce Allane921eb12012-11-28 09:28:37 +00004670 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004671 * ignore e1000e MSI messages, which means we need to test our MSI
4672 * interrupt now
4673 */
Bruce Allan4662e822008-08-26 18:37:06 -07004674 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004675 err = e1000_test_msi(adapter);
4676 if (err) {
4677 e_err("Interrupt allocation failed\n");
4678 goto err_req_irq;
4679 }
4680 }
4681
Auke Kokbc7f75f2007-09-17 12:30:59 -07004682 /* From here on the code is the same as e1000e_up() */
4683 clear_bit(__E1000_DOWN, &adapter->state);
4684
4685 napi_enable(&adapter->napi);
4686
4687 e1000_irq_enable(adapter);
4688
Jeff Kirsher09357b02011-11-18 14:25:00 +00004689 adapter->tx_hang_recheck = false;
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004690
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00004691 hw->mac.get_link_status = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004692 pm_runtime_put(&pdev->dev);
4693
Benjamin Poiriera61cfe42015-11-09 15:50:20 -08004694 e1000e_trigger_lsc(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004695
4696 return 0;
4697
4698err_req_irq:
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01004699 cpu_latency_qos_remove_request(&adapter->pm_qos_req);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004700 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004701 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004702 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004703err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004704 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004705err_setup_tx:
4706 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004707 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004708
4709 return err;
4710}
4711
4712/**
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01004713 * e1000e_close - Disables a network interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004714 * @netdev: network interface device structure
4715 *
4716 * Returns 0, this is not allowed to fail
4717 *
4718 * The close entry point is called when an interface is de-activated
4719 * by the OS. The hardware is still under the drivers control, but
4720 * needs to be disabled. A global MAC reset is issued to stop the
4721 * hardware, and all transmit and receive resources are freed.
4722 **/
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01004723int e1000e_close(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004724{
4725 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004726 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004727 int count = E1000_CHECK_RESET_COUNT;
4728
4729 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
Arjan van de Venab6973a2019-06-14 17:29:35 -07004730 usleep_range(10000, 11000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004731
4732 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004733
4734 pm_runtime_get_sync(&pdev->dev);
4735
Alexander Duycka7023812019-10-11 08:34:52 -07004736 if (netif_device_present(netdev)) {
David Ertman28002092014-02-14 07:16:41 +00004737 e1000e_down(adapter, true);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004738 e1000_free_irq(adapter);
David Ertman63eb48f2014-02-14 07:16:46 +00004739
4740 /* Link status message must follow this format */
Alexander Duyckc557a4b2019-10-31 09:58:51 -07004741 netdev_info(netdev, "NIC Link is Down\n");
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004742 }
Bruce Allana3b87a42013-04-20 05:37:29 +00004743
4744 napi_disable(&adapter->napi);
4745
Bruce Allan55aa6982011-12-16 00:45:45 +00004746 e1000e_free_tx_resources(adapter->tx_ring);
4747 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004748
Bruce Allane921eb12012-11-28 09:28:37 +00004749 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004750 * the same ID is registered on the host OS (let 8021q kill it)
4751 */
Bruce Allane5fe2542013-02-20 04:06:27 +00004752 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004753 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
4754 adapter->mng_vlan_id);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004755
Bruce Allane921eb12012-11-28 09:28:37 +00004756 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004757 * interface is now closed
4758 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004759 if ((adapter->flags & FLAG_HAS_AMT) &&
4760 !test_bit(__E1000_TESTING, &adapter->state))
4761 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004762
Rafael J. Wysocki81e95ad2020-02-12 00:24:36 +01004763 cpu_latency_qos_remove_request(&adapter->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004764
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004765 pm_runtime_put_sync(&pdev->dev);
4766
Auke Kokbc7f75f2007-09-17 12:30:59 -07004767 return 0;
4768}
Bruce Allanfc830b72013-02-20 04:06:11 +00004769
Auke Kokbc7f75f2007-09-17 12:30:59 -07004770/**
4771 * e1000_set_mac - Change the Ethernet Address of the NIC
4772 * @netdev: network interface device structure
4773 * @p: pointer to an address structure
4774 *
4775 * Returns 0 on success, negative on failure
4776 **/
4777static int e1000_set_mac(struct net_device *netdev, void *p)
4778{
4779 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004780 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004781 struct sockaddr *addr = p;
4782
4783 if (!is_valid_ether_addr(addr->sa_data))
4784 return -EADDRNOTAVAIL;
4785
Jakub Kicinskia05e4c02021-10-04 09:05:21 -07004786 eth_hw_addr_set(netdev, addr->sa_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004787 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4788
Bruce Allan69e1e012012-04-14 03:28:50 +00004789 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004790
4791 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4792 /* activate the work around */
4793 e1000e_set_laa_state_82571(&adapter->hw, 1);
4794
Bruce Allane921eb12012-11-28 09:28:37 +00004795 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004796 * between the time RAR[0] gets clobbered and the time it
4797 * gets fixed (in e1000_watchdog), the actual LAA is in one
4798 * of the RARs and no incoming packets directed to this port
4799 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004800 * RAR[14]
4801 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004802 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4803 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004804 }
4805
4806 return 0;
4807}
4808
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004809/**
4810 * e1000e_update_phy_task - work thread to update phy
4811 * @work: pointer to our work struct
4812 *
4813 * this worker thread exists because we must acquire a
4814 * semaphore to read the phy, which we could msleep while
4815 * waiting for it, and we can't msleep in a timer.
4816 **/
4817static void e1000e_update_phy_task(struct work_struct *work)
4818{
4819 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004820 struct e1000_adapter,
4821 update_phy_task);
David Ertmana03206e2014-01-24 23:07:48 +00004822 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004823
4824 if (test_bit(__E1000_DOWN, &adapter->state))
4825 return;
4826
David Ertmana03206e2014-01-24 23:07:48 +00004827 e1000_get_phy_info(hw);
4828
4829 /* Enable EEE on 82579 after link up */
David Ertman50844bb2014-05-13 00:06:26 +00004830 if (hw->phy.type >= e1000_phy_82579)
David Ertmana03206e2014-01-24 23:07:48 +00004831 e1000_set_eee_pchlan(hw);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004832}
4833
Bruce Allane921eb12012-11-28 09:28:37 +00004834/**
4835 * e1000_update_phy_info - timre call-back to update PHY info
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07004836 * @t: pointer to timer_list containing private info adapter
Bruce Allane921eb12012-11-28 09:28:37 +00004837 *
Bruce Allanad680762008-03-28 09:15:03 -07004838 * Need to wait a few seconds after link up to get diagnostic information from
4839 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004840 **/
Kees Cook26566ea2017-10-16 17:29:35 -07004841static void e1000_update_phy_info(struct timer_list *t)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004842{
Kees Cook26566ea2017-10-16 17:29:35 -07004843 struct e1000_adapter *adapter = from_timer(adapter, t, phy_info_timer);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004844
4845 if (test_bit(__E1000_DOWN, &adapter->state))
4846 return;
4847
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004848 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004849}
4850
4851/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004852 * e1000e_update_phy_stats - Update the PHY statistics counters
4853 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004854 *
4855 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004856 **/
4857static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4858{
4859 struct e1000_hw *hw = &adapter->hw;
4860 s32 ret_val;
4861 u16 phy_data;
4862
4863 ret_val = hw->phy.ops.acquire(hw);
4864 if (ret_val)
4865 return;
4866
Bruce Allane921eb12012-11-28 09:28:37 +00004867 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004868 * If not, set to the page with the PHY status registers.
4869 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004870 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004871 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4872 &phy_data);
4873 if (ret_val)
4874 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004875 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4876 ret_val = hw->phy.ops.set_page(hw,
4877 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004878 if (ret_val)
4879 goto release;
4880 }
4881
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004882 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004883 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4884 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004885 if (!ret_val)
4886 adapter->stats.scc += phy_data;
4887
4888 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004889 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4890 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004891 if (!ret_val)
4892 adapter->stats.ecol += phy_data;
4893
4894 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004895 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4896 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004897 if (!ret_val)
4898 adapter->stats.mcc += phy_data;
4899
4900 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004901 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4902 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004903 if (!ret_val)
4904 adapter->stats.latecol += phy_data;
4905
4906 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004907 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4908 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004909 if (!ret_val)
4910 hw->mac.collision_delta = phy_data;
4911
4912 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004913 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4914 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004915 if (!ret_val)
4916 adapter->stats.dc += phy_data;
4917
4918 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004919 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4920 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004921 if (!ret_val)
4922 adapter->stats.tncrs += phy_data;
4923
4924release:
4925 hw->phy.ops.release(hw);
4926}
4927
4928/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004929 * e1000e_update_stats - Update the board statistics counters
4930 * @adapter: board private structure
4931 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004932static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004933{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004934 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004935 struct e1000_hw *hw = &adapter->hw;
4936 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004937
Bruce Allane921eb12012-11-28 09:28:37 +00004938 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004939 * connection is down.
4940 */
4941 if (adapter->link_speed == 0)
4942 return;
4943 if (pci_channel_offline(pdev))
4944 return;
4945
Auke Kokbc7f75f2007-09-17 12:30:59 -07004946 adapter->stats.crcerrs += er32(CRCERRS);
4947 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004948 adapter->stats.gorc += er32(GORCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00004949 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004950 adapter->stats.bprc += er32(BPRC);
4951 adapter->stats.mprc += er32(MPRC);
4952 adapter->stats.roc += er32(ROC);
4953
Auke Kokbc7f75f2007-09-17 12:30:59 -07004954 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004955
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004956 /* Half-duplex statistics */
4957 if (adapter->link_duplex == HALF_DUPLEX) {
4958 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4959 e1000e_update_phy_stats(adapter);
4960 } else {
4961 adapter->stats.scc += er32(SCC);
4962 adapter->stats.ecol += er32(ECOL);
4963 adapter->stats.mcc += er32(MCC);
4964 adapter->stats.latecol += er32(LATECOL);
4965 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004966
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004967 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004968
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004969 if ((hw->mac.type != e1000_82574) &&
4970 (hw->mac.type != e1000_82583))
4971 adapter->stats.tncrs += er32(TNCRS);
4972 }
4973 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004974 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004975
Auke Kokbc7f75f2007-09-17 12:30:59 -07004976 adapter->stats.xonrxc += er32(XONRXC);
4977 adapter->stats.xontxc += er32(XONTXC);
4978 adapter->stats.xoffrxc += er32(XOFFRXC);
4979 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004980 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004981 adapter->stats.gotc += er32(GOTCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00004982 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004983 adapter->stats.rnbc += er32(RNBC);
4984 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004985
4986 adapter->stats.mptc += er32(MPTC);
4987 adapter->stats.bptc += er32(BPTC);
4988
4989 /* used for adaptive IFS */
4990
4991 hw->mac.tx_packet_delta = er32(TPT);
4992 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004993
4994 adapter->stats.algnerrc += er32(ALGNERRC);
4995 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004996 adapter->stats.cexterr += er32(CEXTERR);
4997 adapter->stats.tsctc += er32(TSCTC);
4998 adapter->stats.tsctfc += er32(TSCTFC);
4999
Auke Kokbc7f75f2007-09-17 12:30:59 -07005000 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00005001 netdev->stats.multicast = adapter->stats.mprc;
5002 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005003
5004 /* Rx Errors */
5005
Bruce Allane921eb12012-11-28 09:28:37 +00005006 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07005007 * our own version based on RUC and ROC
5008 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00005009 netdev->stats.rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005010 adapter->stats.crcerrs + adapter->stats.algnerrc +
5011 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00005012 netdev->stats.rx_length_errors = adapter->stats.ruc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005013 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00005014 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
5015 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
5016 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005017
5018 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00005019 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00005020 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
5021 netdev->stats.tx_window_errors = adapter->stats.latecol;
5022 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005023
5024 /* Tx Dropped needs to be maintained elsewhere */
5025
Auke Kokbc7f75f2007-09-17 12:30:59 -07005026 /* Management Stats */
5027 adapter->stats.mgptc += er32(MGTPTC);
5028 adapter->stats.mgprc += er32(MGTPRC);
5029 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00005030
5031 /* Correctable ECC Errors */
Sasha Neftinc8744f42017-04-06 10:26:47 +03005032 if (hw->mac.type >= e1000_pch_lpt) {
Bruce Allan94fb8482013-01-23 09:00:03 +00005033 u32 pbeccsts = er32(PBECCSTS);
David Ertman6cf08d12014-04-05 06:07:00 +00005034
Bruce Allan94fb8482013-01-23 09:00:03 +00005035 adapter->corr_errors +=
5036 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
5037 adapter->uncorr_errors +=
5038 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
5039 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
5040 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005041}
5042
Bruce Allan7c257692008-04-23 11:09:00 -07005043/**
5044 * e1000_phy_read_status - Update the PHY register status snapshot
5045 * @adapter: board private structure
5046 **/
5047static void e1000_phy_read_status(struct e1000_adapter *adapter)
5048{
5049 struct e1000_hw *hw = &adapter->hw;
5050 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07005051
Bruce Allan97390ab2013-06-29 07:42:25 +00005052 if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
5053 (er32(STATUS) & E1000_STATUS_LU) &&
Bruce Allan7c257692008-04-23 11:09:00 -07005054 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005055 int ret_val;
5056
Bruce Allanc2ade1a2013-01-16 08:54:35 +00005057 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
5058 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
5059 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
5060 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
5061 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
5062 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
5063 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
5064 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07005065 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005066 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07005067 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00005068 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07005069 * Set values to typical power-on defaults
5070 */
5071 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
5072 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
5073 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
5074 BMSR_ERCAP);
5075 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
5076 ADVERTISE_ALL | ADVERTISE_CSMA);
5077 phy->lpa = 0;
5078 phy->expansion = EXPANSION_ENABLENPAGE;
5079 phy->ctrl1000 = ADVERTISE_1000FULL;
5080 phy->stat1000 = 0;
5081 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
5082 }
Bruce Allan7c257692008-04-23 11:09:00 -07005083}
5084
Auke Kokbc7f75f2007-09-17 12:30:59 -07005085static void e1000_print_link_info(struct e1000_adapter *adapter)
5086{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005087 struct e1000_hw *hw = &adapter->hw;
5088 u32 ctrl = er32(CTRL);
5089
Bruce Allan8f12fe82008-11-21 16:54:43 -08005090 /* Link status message must follow this format for user tools */
Alexander Duyckc557a4b2019-10-31 09:58:51 -07005091 netdev_info(adapter->netdev,
5092 "NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
5093 adapter->link_speed,
5094 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
5095 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
5096 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
5097 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005098}
5099
Bruce Allan0c6bdb32010-06-17 18:58:43 +00005100static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005101{
5102 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00005103 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005104 s32 ret_val = 0;
5105
Bruce Allane921eb12012-11-28 09:28:37 +00005106 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005107 * Rx sequence error interrupt. get_link_status will stay
Benjamin Poirier65a29da2017-07-21 11:36:24 -07005108 * true until the check_for_link establishes link
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005109 * for copper adapters ONLY
5110 */
5111 switch (hw->phy.media_type) {
5112 case e1000_media_type_copper:
5113 if (hw->mac.get_link_status) {
5114 ret_val = hw->mac.ops.check_for_link(hw);
Benjamin Poirier3016e0a2018-03-06 10:55:52 +09005115 link_active = !hw->mac.get_link_status;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005116 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00005117 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005118 }
5119 break;
5120 case e1000_media_type_fiber:
5121 ret_val = hw->mac.ops.check_for_link(hw);
5122 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
5123 break;
5124 case e1000_media_type_internal_serdes:
5125 ret_val = hw->mac.ops.check_for_link(hw);
Benjamin Poirier65a29da2017-07-21 11:36:24 -07005126 link_active = hw->mac.serdes_has_link;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005127 break;
5128 default:
5129 case e1000_media_type_unknown:
5130 break;
5131 }
5132
Benjamin Poirierd3509f82017-07-21 11:36:25 -07005133 if ((ret_val == -E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005134 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
5135 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005136 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005137 }
5138
5139 return link_active;
5140}
5141
5142static void e1000e_enable_receives(struct e1000_adapter *adapter)
5143{
5144 /* make sure the receive unit is started */
5145 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00005146 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005147 struct e1000_hw *hw = &adapter->hw;
5148 u32 rctl = er32(RCTL);
David Ertman6cf08d12014-04-05 06:07:00 +00005149
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005150 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00005151 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005152 }
5153}
5154
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005155static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
5156{
5157 struct e1000_hw *hw = &adapter->hw;
5158
Bruce Allane921eb12012-11-28 09:28:37 +00005159 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005160 * for hung state and reset, if two calls return true
5161 */
5162 if (e1000_check_phy_82574(hw))
5163 adapter->phy_hang_count++;
5164 else
5165 adapter->phy_hang_count = 0;
5166
5167 if (adapter->phy_hang_count > 1) {
5168 adapter->phy_hang_count = 0;
David Ertmand9554e92014-01-08 01:07:55 +00005169 e_dbg("PHY appears hung - resetting\n");
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005170 schedule_work(&adapter->reset_task);
5171 }
5172}
5173
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08005174/**
5175 * e1000_watchdog - Timer Call-back
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07005176 * @t: pointer to timer_list containing private info adapter
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08005177 **/
5178static void e1000_watchdog(struct timer_list *t)
5179{
5180 struct e1000_adapter *adapter = from_timer(adapter, t, watchdog_timer);
5181
5182 /* Do the rest outside of interrupt context */
5183 schedule_work(&adapter->watchdog_task);
5184
5185 /* TODO: make this use queue_delayed_work() */
5186}
5187
Auke Kokbc7f75f2007-09-17 12:30:59 -07005188static void e1000_watchdog_task(struct work_struct *work)
5189{
5190 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00005191 struct e1000_adapter,
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08005192 watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005193 struct net_device *netdev = adapter->netdev;
5194 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08005195 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005196 struct e1000_ring *tx_ring = adapter->tx_ring;
Vitaly Lifshitsdef4ec62019-06-25 17:39:11 +03005197 u32 dmoff_exit_timeout = 100, tries = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005198 struct e1000_hw *hw = &adapter->hw;
Vitaly Lifshitsdef4ec62019-06-25 17:39:11 +03005199 u32 link, tctl, pcim_state;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005200
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005201 if (test_bit(__E1000_DOWN, &adapter->state))
5202 return;
5203
David S. Millerb405e8d2010-02-04 22:31:41 -08005204 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005205 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005206 /* Cancel scheduled suspend requests. */
5207 pm_runtime_resume(netdev->dev.parent);
5208
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005209 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005210 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005211 }
5212
5213 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
5214 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
5215 e1000_update_mng_vlan(adapter);
5216
Auke Kokbc7f75f2007-09-17 12:30:59 -07005217 if (link) {
5218 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00005219 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005220
5221 /* Cancel scheduled suspend requests. */
5222 pm_runtime_resume(netdev->dev.parent);
5223
Vitaly Lifshitsdef4ec62019-06-25 17:39:11 +03005224 /* Checking if MAC is in DMoff state*/
Sasha Neftin2e7256f2021-06-24 12:02:48 -07005225 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
Vitaly Lifshitsdef4ec62019-06-25 17:39:11 +03005226 pcim_state = er32(STATUS);
Sasha Neftin2e7256f2021-06-24 12:02:48 -07005227 while (pcim_state & E1000_STATUS_PCIM_STATE) {
5228 if (tries++ == dmoff_exit_timeout) {
5229 e_dbg("Error in exiting dmoff\n");
5230 break;
5231 }
5232 usleep_range(10000, 20000);
5233 pcim_state = er32(STATUS);
Vitaly Lifshitsdef4ec62019-06-25 17:39:11 +03005234
Sasha Neftin2e7256f2021-06-24 12:02:48 -07005235 /* Checking if MAC exited DMoff state */
5236 if (!(pcim_state & E1000_STATUS_PCIM_STATE))
5237 e1000_phy_hw_reset(&adapter->hw);
5238 }
Vitaly Lifshitsdef4ec62019-06-25 17:39:11 +03005239 }
5240
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005241 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07005242 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005243 mac->ops.get_link_up_info(&adapter->hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00005244 &adapter->link_speed,
5245 &adapter->link_duplex);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005246 e1000_print_link_info(adapter);
Koki Sanagie792cd92013-02-03 14:03:55 +00005247
5248 /* check if SmartSpeed worked */
5249 e1000e_check_downshift(hw);
5250 if (phy->speed_downgraded)
5251 netdev_warn(netdev,
5252 "Link Speed was downgraded by SmartSpeed\n");
5253
Bruce Allane921eb12012-11-28 09:28:37 +00005254 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07005255 * if link has autonegotiated at 10/100 half
5256 */
5257 if ((hw->phy.type == e1000_phy_igp_3 ||
5258 hw->phy.type == e1000_phy_bm) &&
David Ertman138953b2013-08-30 05:45:25 +00005259 hw->mac.autoneg &&
Bruce Allanf4187b52008-08-26 18:36:50 -07005260 (adapter->link_speed == SPEED_10 ||
5261 adapter->link_speed == SPEED_100) &&
5262 (adapter->link_duplex == HALF_DUPLEX)) {
5263 u16 autoneg_exp;
5264
Bruce Allanc2ade1a2013-01-16 08:54:35 +00005265 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07005266
Bruce Allanc2ade1a2013-01-16 08:54:35 +00005267 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00005268 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 -07005269 }
5270
Emil Tantilovf49c57e2010-03-24 12:55:02 +00005271 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005272 adapter->tx_timeout_factor = 1;
5273 switch (adapter->link_speed) {
5274 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00005275 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07005276 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005277 break;
5278 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00005279 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00005280 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005281 break;
5282 }
5283
Bruce Allane921eb12012-11-28 09:28:37 +00005284 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07005285 * link-up event
5286 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005287 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
5288 !txb2b) {
5289 u32 tarc0;
David Ertman6cf08d12014-04-05 06:07:00 +00005290
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07005291 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005292 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07005293 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005294 }
5295
Bruce Allane921eb12012-11-28 09:28:37 +00005296 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07005297 * some hardware issues
5298 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005299 if (!(adapter->flags & FLAG_TSO_FORCE)) {
5300 switch (adapter->link_speed) {
5301 case SPEED_10:
5302 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005303 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005304 netdev->features &= ~NETIF_F_TSO;
5305 netdev->features &= ~NETIF_F_TSO6;
5306 break;
5307 case SPEED_1000:
5308 netdev->features |= NETIF_F_TSO;
5309 netdev->features |= NETIF_F_TSO6;
5310 break;
5311 default:
5312 /* oops */
5313 break;
5314 }
Kai-Heng Fengf2980102020-05-07 22:21:07 +08005315 if (hw->mac.type == e1000_pch_spt) {
5316 netdev->features &= ~NETIF_F_TSO;
5317 netdev->features &= ~NETIF_F_TSO6;
5318 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005319 }
5320
Bruce Allane921eb12012-11-28 09:28:37 +00005321 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07005322 * after setting TARC(0)
5323 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005324 tctl = er32(TCTL);
5325 tctl |= E1000_TCTL_EN;
5326 ew32(TCTL, tctl);
5327
Bruce Allane921eb12012-11-28 09:28:37 +00005328 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08005329 * reporting link up.
5330 */
5331 if (phy->ops.cfg_on_link_up)
5332 phy->ops.cfg_on_link_up(hw);
5333
Konstantin Khlebnikovd17ba0f2019-04-17 11:13:20 +03005334 netif_wake_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005335 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005336
5337 if (!test_bit(__E1000_DOWN, &adapter->state))
5338 mod_timer(&adapter->phy_info_timer,
5339 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005340 }
5341 } else {
5342 if (netif_carrier_ok(netdev)) {
5343 adapter->link_speed = 0;
5344 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08005345 /* Link status message must follow this format */
Alexander Duyckc557a4b2019-10-31 09:58:51 -07005346 netdev_info(netdev, "NIC Link is Down\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005347 netif_carrier_off(netdev);
Konstantin Khlebnikovd17ba0f2019-04-17 11:13:20 +03005348 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005349 if (!test_bit(__E1000_DOWN, &adapter->state))
5350 mod_timer(&adapter->phy_info_timer,
5351 round_jiffies(jiffies + 2 * HZ));
5352
David Ertmand9554e92014-01-08 01:07:55 +00005353 /* 8000ES2LAN requires a Rx packet buffer work-around
5354 * on link down event; reset the controller to flush
5355 * the Rx packet buffer.
Bruce Allan12d43f72012-12-05 06:26:14 +00005356 */
Konstantin Khlebnikovcaff4222019-04-17 11:13:16 +03005357 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
Bruce Allan12d43f72012-12-05 06:26:14 +00005358 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005359 else
5360 pm_schedule_suspend(netdev->dev.parent,
Bruce Allan17e813e2013-02-20 04:06:01 +00005361 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005362 }
5363 }
5364
5365link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005366 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005367 e1000e_update_stats(adapter);
5368
5369 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
5370 adapter->tpt_old = adapter->stats.tpt;
5371 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
5372 adapter->colc_old = adapter->stats.colc;
5373
Bruce Allan7c257692008-04-23 11:09:00 -07005374 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
5375 adapter->gorc_old = adapter->stats.gorc;
5376 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
5377 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00005378 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005379
Konstantin Khlebnikovcaff4222019-04-17 11:13:16 +03005380 /* If the link is lost the controller stops DMA, but
5381 * if there is queued Tx work it cannot be done. So
5382 * reset the controller to flush the Tx packet buffers.
5383 */
5384 if (!netif_carrier_ok(netdev) &&
5385 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
5386 adapter->flags |= FLAG_RESTART_NOW;
5387
David Ertmand9554e92014-01-08 01:07:55 +00005388 /* If reset is necessary, do it outside of interrupt context. */
Bruce Allan12d43f72012-12-05 06:26:14 +00005389 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00005390 schedule_work(&adapter->reset_task);
5391 /* return immediately since reset is imminent */
5392 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005393 }
5394
Bruce Allan12d43f72012-12-05 06:26:14 +00005395 e1000e_update_adaptive(&adapter->hw);
5396
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005397 /* Simple mode for Interrupt Throttle Rate (ITR) */
5398 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00005399 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005400 * Total asymmetrical Tx or Rx gets ITR=8000;
5401 * everyone else is between 2000-8000.
5402 */
5403 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
5404 u32 dif = (adapter->gotc > adapter->gorc ?
Bruce Allan17e813e2013-02-20 04:06:01 +00005405 adapter->gotc - adapter->gorc :
5406 adapter->gorc - adapter->gotc) / 10000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005407 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
5408
Matthew Vick22a4cca2012-07-12 00:02:42 +00005409 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005410 }
5411
Bruce Allanad680762008-03-28 09:15:03 -07005412 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07005413 if (adapter->msix_entries)
5414 ew32(ICS, adapter->rx_ring->ims_val);
5415 else
5416 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005417
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00005418 /* flush pending descriptors to memory before detecting Tx hang */
5419 e1000e_flush_descriptors(adapter);
5420
Auke Kokbc7f75f2007-09-17 12:30:59 -07005421 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005422 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005423
Bruce Allane921eb12012-11-28 09:28:37 +00005424 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005425 * reset from the other port. Set the appropriate LAA in RAR[0]
5426 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005427 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005428 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005429
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005430 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5431 e1000e_check_82574_phy_workaround(adapter);
5432
Bruce Allanb67e1912012-12-27 08:32:33 +00005433 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5434 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5435 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5436 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5437 er32(RXSTMPH);
5438 adapter->rx_hwtstamp_cleared++;
5439 } else {
5440 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5441 }
5442 }
5443
Auke Kokbc7f75f2007-09-17 12:30:59 -07005444 /* Reset the timer */
5445 if (!test_bit(__E1000_DOWN, &adapter->state))
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08005446 mod_timer(&adapter->watchdog_timer,
5447 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005448}
5449
5450#define E1000_TX_FLAGS_CSUM 0x00000001
5451#define E1000_TX_FLAGS_VLAN 0x00000002
5452#define E1000_TX_FLAGS_TSO 0x00000004
5453#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005454#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005455#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005456#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5457#define E1000_TX_FLAGS_VLAN_SHIFT 16
5458
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005459static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb,
5460 __be16 protocol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005461{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005462 struct e1000_context_desc *context_desc;
5463 struct e1000_buffer *buffer_info;
5464 unsigned int i;
5465 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005466 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005467 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Francois Romieubcf1f572014-03-30 03:14:43 +00005468 int err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005469
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005470 if (!skb_is_gso(skb))
5471 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005472
Francois Romieubcf1f572014-03-30 03:14:43 +00005473 err = skb_cow_head(skb, 0);
5474 if (err < 0)
5475 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005476
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005477 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5478 mss = skb_shinfo(skb)->gso_size;
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005479 if (protocol == htons(ETH_P_IP)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005480 struct iphdr *iph = ip_hdr(skb);
5481 iph->tot_len = 0;
5482 iph->check = 0;
5483 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005484 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005485 cmd_length = E1000_TXD_CMD_IP;
5486 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005487 } else if (skb_is_gso_v6(skb)) {
Heiner Kallweit2b316fbc2020-02-18 21:05:02 +01005488 tcp_v6_gso_csum_prep(skb);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005489 ipcse = 0;
5490 }
5491 ipcss = skb_network_offset(skb);
5492 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5493 tucss = skb_transport_offset(skb);
5494 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005495
5496 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005497 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005498
5499 i = tx_ring->next_to_use;
5500 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5501 buffer_info = &tx_ring->buffer_info[i];
5502
Bruce Allane80bd1d2013-05-01 01:19:46 +00005503 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5504 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5505 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005506 context_desc->upper_setup.tcp_fields.tucss = tucss;
5507 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005508 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allane80bd1d2013-05-01 01:19:46 +00005509 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005510 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5511 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5512
5513 buffer_info->time_stamp = jiffies;
5514 buffer_info->next_to_watch = i;
5515
5516 i++;
5517 if (i == tx_ring->count)
5518 i = 0;
5519 tx_ring->next_to_use = i;
5520
5521 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005522}
5523
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005524static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb,
5525 __be16 protocol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005526{
Bruce Allan55aa6982011-12-16 00:45:45 +00005527 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005528 struct e1000_context_desc *context_desc;
5529 struct e1000_buffer *buffer_info;
5530 unsigned int i;
5531 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005532 u32 cmd_len = E1000_TXD_CMD_DEXT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005533
Dave Grahamaf807c82008-10-09 14:28:58 -07005534 if (skb->ip_summed != CHECKSUM_PARTIAL)
David Ertman3992c8e2014-04-05 03:36:15 +00005535 return false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005536
Arthur Jones3f518392009-03-20 15:56:35 -07005537 switch (protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08005538 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005539 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5540 cmd_len |= E1000_TXD_CMD_TCP;
5541 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08005542 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005543 /* XXX not handling all IPV6 headers */
5544 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5545 cmd_len |= E1000_TXD_CMD_TCP;
5546 break;
5547 default:
5548 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005549 e_warn("checksum_partial proto=%x!\n",
5550 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005551 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005552 }
5553
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005554 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005555
5556 i = tx_ring->next_to_use;
5557 buffer_info = &tx_ring->buffer_info[i];
5558 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5559
5560 context_desc->lower_setup.ip_config = 0;
5561 context_desc->upper_setup.tcp_fields.tucss = css;
Bruce Allanf0ff4392013-02-20 04:05:39 +00005562 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Dave Grahamaf807c82008-10-09 14:28:58 -07005563 context_desc->upper_setup.tcp_fields.tucse = 0;
5564 context_desc->tcp_seg_setup.data = 0;
5565 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5566
5567 buffer_info->time_stamp = jiffies;
5568 buffer_info->next_to_watch = i;
5569
5570 i++;
5571 if (i == tx_ring->count)
5572 i = 0;
5573 tx_ring->next_to_use = i;
5574
David Ertman3992c8e2014-04-05 03:36:15 +00005575 return true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005576}
5577
Bruce Allan55aa6982011-12-16 00:45:45 +00005578static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5579 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005580 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005581{
Bruce Allan55aa6982011-12-16 00:45:45 +00005582 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005583 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005584 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005585 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005586 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005587 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005588
5589 i = tx_ring->next_to_use;
5590
5591 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005592 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005593 size = min(len, max_per_txd);
5594
Auke Kokbc7f75f2007-09-17 12:30:59 -07005595 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005596 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005597 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005598 buffer_info->dma = dma_map_single(&pdev->dev,
5599 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005600 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005601 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005602 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005603 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005604
5605 len -= size;
5606 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005607 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005608
5609 if (len) {
5610 i++;
5611 if (i == tx_ring->count)
5612 i = 0;
5613 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005614 }
5615
5616 for (f = 0; f < nr_frags; f++) {
Matthew Wilcox (Oracle)d7840972019-07-22 20:08:25 -07005617 const skb_frag_t *frag = &skb_shinfo(skb)->frags[f];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005618
Eric Dumazet9e903e02011-10-18 21:00:24 +00005619 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005620 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005621
5622 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005623 i++;
5624 if (i == tx_ring->count)
5625 i = 0;
5626
Auke Kokbc7f75f2007-09-17 12:30:59 -07005627 buffer_info = &tx_ring->buffer_info[i];
5628 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005629
5630 buffer_info->length = size;
5631 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005632 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005633 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
Bruce Allan17e813e2013-02-20 04:06:01 +00005634 offset, size,
5635 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005636 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005637 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005638 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005639
5640 len -= size;
5641 offset += size;
5642 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005643 }
5644 }
5645
Bruce Allanaf667a22010-12-31 06:10:01 +00005646 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005647 /* multiply data chunks by size of headers */
5648 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5649
Auke Kokbc7f75f2007-09-17 12:30:59 -07005650 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005651 tx_ring->buffer_info[i].segs = segs;
5652 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005653 tx_ring->buffer_info[first].next_to_watch = i;
5654
5655 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005656
5657dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005658 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005659 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005660 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005661 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005662
5663 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005664 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005665 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005666 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005667 buffer_info = &tx_ring->buffer_info[i];
Florian Fainelli377b6272017-08-25 18:14:24 -07005668 e1000_put_txbuf(tx_ring, buffer_info, true);
Alexander Duyck03b13202009-12-02 16:45:31 +00005669 }
5670
5671 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005672}
5673
Bruce Allan55aa6982011-12-16 00:45:45 +00005674static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005675{
Bruce Allan55aa6982011-12-16 00:45:45 +00005676 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005677 struct e1000_tx_desc *tx_desc = NULL;
5678 struct e1000_buffer *buffer_info;
5679 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5680 unsigned int i;
5681
5682 if (tx_flags & E1000_TX_FLAGS_TSO) {
5683 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005684 E1000_TXD_CMD_TSE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005685 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5686
5687 if (tx_flags & E1000_TX_FLAGS_IPV4)
5688 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5689 }
5690
5691 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5692 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5693 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5694 }
5695
5696 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5697 txd_lower |= E1000_TXD_CMD_VLE;
5698 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5699 }
5700
Ben Greear943146d2012-02-11 15:39:40 +00005701 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5702 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5703
Bruce Allanb67e1912012-12-27 08:32:33 +00005704 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5705 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5706 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5707 }
5708
Auke Kokbc7f75f2007-09-17 12:30:59 -07005709 i = tx_ring->next_to_use;
5710
Bruce Allan36b973d2010-11-24 07:42:43 +00005711 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005712 buffer_info = &tx_ring->buffer_info[i];
5713 tx_desc = E1000_TX_DESC(*tx_ring, i);
5714 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allanf0ff4392013-02-20 04:05:39 +00005715 tx_desc->lower.data = cpu_to_le32(txd_lower |
5716 buffer_info->length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005717 tx_desc->upper.data = cpu_to_le32(txd_upper);
5718
5719 i++;
5720 if (i == tx_ring->count)
5721 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005722 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005723
5724 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5725
Ben Greear943146d2012-02-11 15:39:40 +00005726 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5727 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5728 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5729
Bruce Allane921eb12012-11-28 09:28:37 +00005730 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005731 * know there are new descriptors to fetch. (Only
5732 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005733 * such as IA-64).
5734 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005735 wmb();
5736
5737 tx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005738}
5739
5740#define MINIMUM_DHCP_PACKET_SIZE 282
5741static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5742 struct sk_buff *skb)
5743{
Bruce Allane80bd1d2013-05-01 01:19:46 +00005744 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005745 u16 length, offset;
5746
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01005747 if (skb_vlan_tag_present(skb) &&
5748 !((skb_vlan_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Bruce Alland60923c2012-12-05 06:26:56 +00005749 (adapter->hw.mng_cookie.status &
5750 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5751 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005752
5753 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5754 return 0;
5755
Bruce Allan53aa82d2013-02-20 04:06:06 +00005756 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005757 return 0;
5758
5759 {
Bruce Allan362e20c2013-02-20 04:05:45 +00005760 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005761 struct udphdr *udp;
5762
5763 if (ip->protocol != IPPROTO_UDP)
5764 return 0;
5765
5766 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5767 if (ntohs(udp->dest) != 67)
5768 return 0;
5769
5770 offset = (u8 *)udp + 8 - skb->data;
5771 length = skb->len - offset;
5772 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5773 }
5774
5775 return 0;
5776}
5777
Bruce Allan55aa6982011-12-16 00:45:45 +00005778static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005779{
Bruce Allan55aa6982011-12-16 00:45:45 +00005780 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005781
Bruce Allan55aa6982011-12-16 00:45:45 +00005782 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005783 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005784 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005785 * but since that doesn't exist yet, just open code it.
5786 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005787 smp_mb();
5788
Bruce Allane921eb12012-11-28 09:28:37 +00005789 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005790 * made room available.
5791 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005792 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005793 return -EBUSY;
5794
5795 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005796 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005797 ++adapter->restart_queue;
5798 return 0;
5799}
5800
Bruce Allan55aa6982011-12-16 00:45:45 +00005801static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005802{
Bruce Alland821a4c2012-08-24 20:38:11 +00005803 BUG_ON(size > tx_ring->count);
5804
Bruce Allan55aa6982011-12-16 00:45:45 +00005805 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005806 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005807 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005808}
5809
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005810static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5811 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005812{
5813 struct e1000_adapter *adapter = netdev_priv(netdev);
5814 struct e1000_ring *tx_ring = adapter->tx_ring;
5815 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005816 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005817 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005818 unsigned int nr_frags;
5819 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005820 int count = 0;
5821 int tso;
5822 unsigned int f;
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005823 __be16 protocol = vlan_get_protocol(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005824
5825 if (test_bit(__E1000_DOWN, &adapter->state)) {
5826 dev_kfree_skb_any(skb);
5827 return NETDEV_TX_OK;
5828 }
5829
5830 if (skb->len <= 0) {
5831 dev_kfree_skb_any(skb);
5832 return NETDEV_TX_OK;
5833 }
5834
Bruce Allane921eb12012-11-28 09:28:37 +00005835 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005836 * pad skb in order to meet this minimum size requirement
5837 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08005838 if (skb_put_padto(skb, 17))
5839 return NETDEV_TX_OK;
Tushar Dave6e97c172012-09-14 02:21:37 +00005840
Auke Kokbc7f75f2007-09-17 12:30:59 -07005841 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005842 if (mss) {
5843 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005844
Bruce Allane921eb12012-11-28 09:28:37 +00005845 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005846 * points to just header, pull a few bytes of payload from
5847 * frags into skb->data
5848 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005849 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005850 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005851 * avoiding it could save a lot of cycles
5852 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005853 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005854 unsigned int pull_size;
5855
Bruce Allana2a5b322012-01-31 06:37:17 +00005856 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005857 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005858 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005859 dev_kfree_skb_any(skb);
5860 return NETDEV_TX_OK;
5861 }
Eric Dumazete743d312010-04-14 15:59:40 -07005862 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005863 }
5864 }
5865
5866 /* reserve a descriptor for the offload context */
5867 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5868 count++;
5869 count++;
5870
Bruce Alland821a4c2012-08-24 20:38:11 +00005871 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005872
5873 nr_frags = skb_shinfo(skb)->nr_frags;
5874 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005875 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5876 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005877
5878 if (adapter->hw.mac.tx_pkt_filtering)
5879 e1000_transfer_dhcp_info(adapter, skb);
5880
Bruce Allane921eb12012-11-28 09:28:37 +00005881 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005882 * head, otherwise try next time
5883 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005884 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005885 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005886
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01005887 if (skb_vlan_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005888 tx_flags |= E1000_TX_FLAGS_VLAN;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01005889 tx_flags |= (skb_vlan_tag_get(skb) <<
5890 E1000_TX_FLAGS_VLAN_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005891 }
5892
5893 first = tx_ring->next_to_use;
5894
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005895 tso = e1000_tso(tx_ring, skb, protocol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005896 if (tso < 0) {
5897 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005898 return NETDEV_TX_OK;
5899 }
5900
5901 if (tso)
5902 tx_flags |= E1000_TX_FLAGS_TSO;
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005903 else if (e1000_tx_csum(tx_ring, skb, protocol))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005904 tx_flags |= E1000_TX_FLAGS_CSUM;
5905
Bruce Allane921eb12012-11-28 09:28:37 +00005906 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005907 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005908 * no longer assume, we must.
5909 */
Vlad Yasevich47ccd1e2014-08-25 10:34:48 -04005910 if (protocol == htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005911 tx_flags |= E1000_TX_FLAGS_IPV4;
5912
Ben Greear943146d2012-02-11 15:39:40 +00005913 if (unlikely(skb->no_fcs))
5914 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5915
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005916 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005917 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5918 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005919 if (count) {
Mathias Koehrer69308952014-08-07 18:51:53 +00005920 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
Jacob Kellercff57142017-05-03 10:28:57 -07005921 (adapter->flags & FLAG_HAS_HW_TIMESTAMP)) {
5922 if (!adapter->tx_hwtstamp_skb) {
5923 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5924 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5925 adapter->tx_hwtstamp_skb = skb_get(skb);
5926 adapter->tx_hwtstamp_start = jiffies;
5927 schedule_work(&adapter->tx_hwtstamp_work);
5928 } else {
5929 adapter->tx_hwtstamp_skipped++;
5930 }
Bruce Allanb67e1912012-12-27 08:32:33 +00005931 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005932
Miroslav Lichvar74abc9b12017-05-19 17:52:41 +02005933 skb_tx_timestamp(skb);
5934
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005935 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005936 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005937 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005938 e1000_maybe_stop_tx(tx_ring,
5939 (MAX_SKB_FRAGS *
5940 DIV_ROUND_UP(PAGE_SIZE,
5941 adapter->tx_fifo_limit) + 2));
Florian Westphal472f31f2015-01-09 09:26:14 +00005942
Florian Westphal6b16f9e2019-04-01 16:42:14 +02005943 if (!netdev_xmit_more() ||
Florian Westphal472f31f2015-01-09 09:26:14 +00005944 netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) {
5945 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
5946 e1000e_update_tdt_wa(tx_ring,
5947 tx_ring->next_to_use);
5948 else
5949 writel(tx_ring->next_to_use, tx_ring->tail);
Florian Westphal472f31f2015-01-09 09:26:14 +00005950 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005951 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005952 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005953 tx_ring->buffer_info[first].time_stamp = 0;
5954 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955 }
5956
Auke Kokbc7f75f2007-09-17 12:30:59 -07005957 return NETDEV_TX_OK;
5958}
5959
5960/**
5961 * e1000_tx_timeout - Respond to a Tx Hang
5962 * @netdev: network interface device structure
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07005963 * @txqueue: index of the hung queue (unused)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005964 **/
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07005965static void e1000_tx_timeout(struct net_device *netdev, unsigned int __always_unused txqueue)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005966{
5967 struct e1000_adapter *adapter = netdev_priv(netdev);
5968
5969 /* Do the reset outside of interrupt context */
5970 adapter->tx_timeout_count++;
5971 schedule_work(&adapter->reset_task);
5972}
5973
5974static void e1000_reset_task(struct work_struct *work)
5975{
5976 struct e1000_adapter *adapter;
5977 adapter = container_of(work, struct e1000_adapter, reset_task);
5978
Vitaly Lifshits21f857f2020-10-21 14:59:37 +03005979 rtnl_lock();
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005980 /* don't run the task if already down */
Vitaly Lifshits21f857f2020-10-21 14:59:37 +03005981 if (test_bit(__E1000_DOWN, &adapter->state)) {
5982 rtnl_unlock();
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005983 return;
Vitaly Lifshits21f857f2020-10-21 14:59:37 +03005984 }
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005985
Bruce Allan12d43f72012-12-05 06:26:14 +00005986 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005987 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005988 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005989 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005990 e1000e_reinit_locked(adapter);
Vitaly Lifshits21f857f2020-10-21 14:59:37 +03005991 rtnl_unlock();
Auke Kokbc7f75f2007-09-17 12:30:59 -07005992}
5993
5994/**
Sasha Neftin39da2ca2021-03-14 15:59:20 +02005995 * e1000e_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005996 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005997 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005998 *
5999 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07006000 **/
stephen hemmingerbc1f4472017-01-06 19:12:52 -08006001void e1000e_get_stats64(struct net_device *netdev,
6002 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006003{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006004 struct e1000_adapter *adapter = netdev_priv(netdev);
6005
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006006 spin_lock(&adapter->stats64_lock);
6007 e1000e_update_stats(adapter);
6008 /* Fill out the OS statistics structure */
6009 stats->rx_bytes = adapter->stats.gorc;
6010 stats->rx_packets = adapter->stats.gprc;
6011 stats->tx_bytes = adapter->stats.gotc;
6012 stats->tx_packets = adapter->stats.gptc;
6013 stats->multicast = adapter->stats.mprc;
6014 stats->collisions = adapter->stats.colc;
6015
6016 /* Rx Errors */
6017
Bruce Allane921eb12012-11-28 09:28:37 +00006018 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006019 * our own version based on RUC and ROC
6020 */
6021 stats->rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00006022 adapter->stats.crcerrs + adapter->stats.algnerrc +
6023 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
6024 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006025 stats->rx_crc_errors = adapter->stats.crcerrs;
6026 stats->rx_frame_errors = adapter->stats.algnerrc;
6027 stats->rx_missed_errors = adapter->stats.mpc;
6028
6029 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00006030 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006031 stats->tx_aborted_errors = adapter->stats.ecol;
6032 stats->tx_window_errors = adapter->stats.latecol;
6033 stats->tx_carrier_errors = adapter->stats.tncrs;
6034
6035 /* Tx Dropped needs to be maintained elsewhere */
6036
6037 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006038}
6039
6040/**
6041 * e1000_change_mtu - Change the Maximum Transfer Unit
6042 * @netdev: network interface device structure
6043 * @new_mtu: new value for maximum frame size
6044 *
6045 * Returns 0 on success, negative on failure
6046 **/
6047static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
6048{
6049 struct e1000_adapter *adapter = netdev_priv(netdev);
Alexander Duyck8084b862015-05-02 00:52:00 -07006050 int max_frame = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006051
Bruce Allan2adc55c2009-06-02 11:28:58 +00006052 /* Jumbo frame support */
Jarod Wilson91c527a2016-10-17 15:54:05 -04006053 if ((new_mtu > ETH_DATA_LEN) &&
Bruce Allan2e1706f2012-06-30 20:02:42 +00006054 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
6055 e_err("Jumbo Frames not supported.\n");
6056 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006057 }
6058
Bruce Allan2fbe4522012-04-19 03:21:47 +00006059 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
6060 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00006061 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
6062 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00006063 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00006064 return -EINVAL;
6065 }
6066
Auke Kokbc7f75f2007-09-17 12:30:59 -07006067 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Arjan van de Venab6973a2019-06-14 17:29:35 -07006068 usleep_range(1000, 1100);
Bruce Allan610c9922009-11-19 12:35:45 +00006069 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006070 adapter->max_frame_size = max_frame;
Florian Fainelli12299132019-11-07 14:35:36 -08006071 netdev_dbg(netdev, "changing MTU from %d to %d\n",
6072 netdev->mtu, new_mtu);
Bruce Allan610c9922009-11-19 12:35:45 +00006073 netdev->mtu = new_mtu;
David Ertman63eb48f2014-02-14 07:16:46 +00006074
6075 pm_runtime_get_sync(netdev->dev.parent);
6076
Auke Kokbc7f75f2007-09-17 12:30:59 -07006077 if (netif_running(netdev))
David Ertman28002092014-02-14 07:16:41 +00006078 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006079
Bruce Allane921eb12012-11-28 09:28:37 +00006080 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07006081 * means we reserve 2 more, this pushes us to allocate from the next
6082 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07006083 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006084 * However with the new *_jumbo_rx* routines, jumbo receives will use
6085 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07006086 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006087
Jesse Brandeburg99261462010-01-22 22:56:16 +00006088 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006089 adapter->rx_buffer_len = 2048;
6090 else
6091 adapter->rx_buffer_len = 4096;
6092
6093 /* adjust allocation if LPE protects us, and we aren't using SBP */
Alexander Duyck8084b862015-05-02 00:52:00 -07006094 if (max_frame <= (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN))
6095 adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006096
Auke Kokbc7f75f2007-09-17 12:30:59 -07006097 if (netif_running(netdev))
6098 e1000e_up(adapter);
6099 else
6100 e1000e_reset(adapter);
6101
David Ertman63eb48f2014-02-14 07:16:46 +00006102 pm_runtime_put_sync(netdev->dev.parent);
6103
Auke Kokbc7f75f2007-09-17 12:30:59 -07006104 clear_bit(__E1000_RESETTING, &adapter->state);
6105
6106 return 0;
6107}
6108
6109static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
6110 int cmd)
6111{
6112 struct e1000_adapter *adapter = netdev_priv(netdev);
6113 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006114
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006115 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006116 return -EOPNOTSUPP;
6117
6118 switch (cmd) {
6119 case SIOCGMIIPHY:
6120 data->phy_id = adapter->hw.phy.addr;
6121 break;
6122 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00006123 e1000_phy_read_status(adapter);
6124
Bruce Allan7c257692008-04-23 11:09:00 -07006125 switch (data->reg_num & 0x1F) {
6126 case MII_BMCR:
6127 data->val_out = adapter->phy_regs.bmcr;
6128 break;
6129 case MII_BMSR:
6130 data->val_out = adapter->phy_regs.bmsr;
6131 break;
6132 case MII_PHYSID1:
6133 data->val_out = (adapter->hw.phy.id >> 16);
6134 break;
6135 case MII_PHYSID2:
6136 data->val_out = (adapter->hw.phy.id & 0xFFFF);
6137 break;
6138 case MII_ADVERTISE:
6139 data->val_out = adapter->phy_regs.advertise;
6140 break;
6141 case MII_LPA:
6142 data->val_out = adapter->phy_regs.lpa;
6143 break;
6144 case MII_EXPANSION:
6145 data->val_out = adapter->phy_regs.expansion;
6146 break;
6147 case MII_CTRL1000:
6148 data->val_out = adapter->phy_regs.ctrl1000;
6149 break;
6150 case MII_STAT1000:
6151 data->val_out = adapter->phy_regs.stat1000;
6152 break;
6153 case MII_ESTATUS:
6154 data->val_out = adapter->phy_regs.estatus;
6155 break;
6156 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006157 return -EIO;
6158 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006159 break;
6160 case SIOCSMIIREG:
6161 default:
6162 return -EOPNOTSUPP;
6163 }
6164 return 0;
6165}
6166
Bruce Allanb67e1912012-12-27 08:32:33 +00006167/**
Sasha Neftin39da2ca2021-03-14 15:59:20 +02006168 * e1000e_hwtstamp_set - control hardware time stamping
Bruce Allanb67e1912012-12-27 08:32:33 +00006169 * @netdev: network interface device structure
Jesse Brandeburgb50f7bc2020-09-25 15:24:37 -07006170 * @ifr: interface request
Bruce Allanb67e1912012-12-27 08:32:33 +00006171 *
6172 * Outgoing time stamping can be enabled and disabled. Play nice and
6173 * disable it when requested, although it shouldn't cause any overhead
6174 * when no packet needs it. At most one packet in the queue may be
6175 * marked for time stamping, otherwise it would be impossible to tell
6176 * for sure to which packet the hardware time stamp belongs.
6177 *
6178 * Incoming time stamping has to be configured via the hardware filters.
6179 * Not all combinations are supported, in particular event type has to be
6180 * specified. Matching the kind of event packet is not supported, with the
6181 * exception of "all V2 events regardless of level 2 or 4".
6182 **/
Ben Hutchings4e8cff62013-11-18 23:07:16 +00006183static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
Bruce Allanb67e1912012-12-27 08:32:33 +00006184{
6185 struct e1000_adapter *adapter = netdev_priv(netdev);
6186 struct hwtstamp_config config;
6187 int ret_val;
6188
6189 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
6190 return -EFAULT;
6191
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00006192 ret_val = e1000e_config_hwtstamp(adapter, &config);
Bruce Allanb67e1912012-12-27 08:32:33 +00006193 if (ret_val)
6194 return ret_val;
6195
Bruce Alland89777b2013-01-19 01:09:58 +00006196 switch (config.rx_filter) {
6197 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6198 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6199 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6200 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6201 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6202 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
6203 /* With V2 type filters which specify a Sync or Delay Request,
6204 * Path Delay Request/Response messages are also time stamped
6205 * by hardware so notify the caller the requested packets plus
6206 * some others are time stamped.
6207 */
6208 config.rx_filter = HWTSTAMP_FILTER_SOME;
6209 break;
6210 default:
6211 break;
6212 }
6213
Bruce Allanb67e1912012-12-27 08:32:33 +00006214 return copy_to_user(ifr->ifr_data, &config,
6215 sizeof(config)) ? -EFAULT : 0;
6216}
6217
Ben Hutchings4e8cff62013-11-18 23:07:16 +00006218static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
6219{
6220 struct e1000_adapter *adapter = netdev_priv(netdev);
6221
6222 return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
6223 sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
6224}
6225
Auke Kokbc7f75f2007-09-17 12:30:59 -07006226static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6227{
6228 switch (cmd) {
6229 case SIOCGMIIPHY:
6230 case SIOCGMIIREG:
6231 case SIOCSMIIREG:
6232 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00006233 case SIOCSHWTSTAMP:
Ben Hutchings4e8cff62013-11-18 23:07:16 +00006234 return e1000e_hwtstamp_set(netdev, ifr);
6235 case SIOCGHWTSTAMP:
6236 return e1000e_hwtstamp_get(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006237 default:
6238 return -EOPNOTSUPP;
6239 }
6240}
6241
Bruce Allana4f58f52009-06-02 11:29:18 +00006242static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
6243{
6244 struct e1000_hw *hw = &adapter->hw;
David Ertman74f350e2014-02-22 03:15:17 +00006245 u32 i, mac_reg, wuc;
Bruce Allan2b6b1682011-05-13 07:20:09 +00006246 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00006247 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00006248
6249 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00006250 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00006251
Bruce Allan2b6b1682011-05-13 07:20:09 +00006252 retval = hw->phy.ops.acquire(hw);
6253 if (retval) {
6254 e_err("Could not acquire PHY\n");
6255 return retval;
6256 }
6257
6258 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
6259 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
6260 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00006261 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00006262
6263 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00006264 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
6265 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00006266 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
6267 (u16)(mac_reg & 0xFFFF));
6268 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
6269 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00006270 }
6271
6272 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00006273 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00006274 mac_reg = er32(RCTL);
6275 if (mac_reg & E1000_RCTL_UPE)
6276 phy_reg |= BM_RCTL_UPE;
6277 if (mac_reg & E1000_RCTL_MPE)
6278 phy_reg |= BM_RCTL_MPE;
6279 phy_reg &= ~(BM_RCTL_MO_MASK);
6280 if (mac_reg & E1000_RCTL_MO_3)
6281 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
Bruce Allan17e813e2013-02-20 04:06:01 +00006282 << BM_RCTL_MO_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00006283 if (mac_reg & E1000_RCTL_BAM)
6284 phy_reg |= BM_RCTL_BAM;
6285 if (mac_reg & E1000_RCTL_PMCF)
6286 phy_reg |= BM_RCTL_PMCF;
6287 mac_reg = er32(CTRL);
6288 if (mac_reg & E1000_CTRL_RFCE)
6289 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00006290 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00006291
David Ertman74f350e2014-02-22 03:15:17 +00006292 wuc = E1000_WUC_PME_EN;
6293 if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
6294 wuc |= E1000_WUC_APME;
6295
Bruce Allana4f58f52009-06-02 11:29:18 +00006296 /* enable PHY wakeup in MAC register */
6297 ew32(WUFC, wufc);
David Ertman74f350e2014-02-22 03:15:17 +00006298 ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
6299 E1000_WUC_PME_STATUS | wuc));
Bruce Allana4f58f52009-06-02 11:29:18 +00006300
6301 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00006302 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
David Ertman74f350e2014-02-22 03:15:17 +00006303 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
Bruce Allana4f58f52009-06-02 11:29:18 +00006304
6305 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00006306 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
6307 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00006308 if (retval)
6309 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00006310release:
Bruce Allan94d81862009-11-20 23:25:26 +00006311 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00006312
6313 return retval;
6314}
6315
David Ertman2a7e19a2014-07-11 06:21:31 +00006316static void e1000e_flush_lpic(struct pci_dev *pdev)
6317{
6318 struct net_device *netdev = pci_get_drvdata(pdev);
6319 struct e1000_adapter *adapter = netdev_priv(netdev);
6320 struct e1000_hw *hw = &adapter->hw;
6321 u32 ret_val;
6322
6323 pm_runtime_get_sync(netdev->dev.parent);
6324
6325 ret_val = hw->phy.ops.acquire(hw);
6326 if (ret_val)
6327 goto fl_out;
6328
6329 pr_info("EEE TX LPI TIMER: %08X\n",
6330 er32(LPIC) >> E1000_LPIC_LPIET_SHIFT);
6331
6332 hw->phy.ops.release(hw);
6333
6334fl_out:
6335 pm_runtime_put_sync(netdev->dev.parent);
6336}
6337
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006338/* S0ix implementation */
6339static void e1000e_s0ix_entry_flow(struct e1000_adapter *adapter)
6340{
6341 struct e1000_hw *hw = &adapter->hw;
6342 u32 mac_data;
6343 u16 phy_data;
6344
Sasha Neftincad014b2021-12-07 13:23:42 +02006345 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID &&
6346 hw->mac.type >= e1000_pch_adp) {
Sasha Neftin3e55d232021-06-24 11:18:27 +03006347 /* Request ME configure the device for S0ix */
6348 mac_data = er32(H2ME);
6349 mac_data |= E1000_H2ME_START_DPG;
6350 mac_data &= ~E1000_H2ME_EXIT_DPG;
6351 ew32(H2ME, mac_data);
6352 } else {
6353 /* Request driver configure the device to S0ix */
6354 /* Disable the periodic inband message,
6355 * don't request PCIe clock in K1 page770_17[10:9] = 10b
6356 */
6357 e1e_rphy(hw, HV_PM_CTRL, &phy_data);
6358 phy_data &= ~HV_PM_CTRL_K1_CLK_REQ;
6359 phy_data |= BIT(10);
6360 e1e_wphy(hw, HV_PM_CTRL, phy_data);
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006361
Sasha Neftin3e55d232021-06-24 11:18:27 +03006362 /* Make sure we don't exit K1 every time a new packet arrives
6363 * 772_29[5] = 1 CS_Mode_Stay_In_K1
6364 */
6365 e1e_rphy(hw, I217_CGFREG, &phy_data);
6366 phy_data |= BIT(5);
6367 e1e_wphy(hw, I217_CGFREG, phy_data);
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006368
Sasha Neftin3e55d232021-06-24 11:18:27 +03006369 /* Change the MAC/PHY interface to SMBus
6370 * Force the SMBus in PHY page769_23[0] = 1
6371 * Force the SMBus in MAC CTRL_EXT[11] = 1
6372 */
6373 e1e_rphy(hw, CV_SMB_CTRL, &phy_data);
6374 phy_data |= CV_SMB_CTRL_FORCE_SMBUS;
6375 e1e_wphy(hw, CV_SMB_CTRL, phy_data);
6376 mac_data = er32(CTRL_EXT);
6377 mac_data |= E1000_CTRL_EXT_FORCE_SMBUS;
6378 ew32(CTRL_EXT, mac_data);
6379
6380 /* DFT control: PHY bit: page769_20[0] = 1
Sasha Neftin3ad3e282021-06-24 11:19:08 +03006381 * page769_20[7] - PHY PLL stop
6382 * page769_20[8] - PHY go to the electrical idle
6383 * page769_20[9] - PHY serdes disable
Sasha Neftin3e55d232021-06-24 11:18:27 +03006384 * Gate PPW via EXTCNF_CTRL - set 0x0F00[7] = 1
6385 */
6386 e1e_rphy(hw, I82579_DFT_CTRL, &phy_data);
6387 phy_data |= BIT(0);
Sasha Neftin3ad3e282021-06-24 11:19:08 +03006388 phy_data |= BIT(7);
6389 phy_data |= BIT(8);
6390 phy_data |= BIT(9);
Sasha Neftin3e55d232021-06-24 11:18:27 +03006391 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 /* Enable the Dynamic Power Gating in the MAC */
6398 mac_data = er32(FEXTNVM7);
6399 mac_data |= BIT(22);
6400 ew32(FEXTNVM7, mac_data);
6401
6402 /* Disable disconnected cable conditioning for Power Gating */
6403 mac_data = er32(DPGFR);
6404 mac_data |= BIT(2);
6405 ew32(DPGFR, mac_data);
6406
6407 /* Don't wake from dynamic Power Gating with clock request */
6408 mac_data = er32(FEXTNVM12);
6409 mac_data |= BIT(12);
6410 ew32(FEXTNVM12, mac_data);
6411
6412 /* Ungate PGCB clock */
6413 mac_data = er32(FEXTNVM9);
6414 mac_data &= ~BIT(28);
6415 ew32(FEXTNVM9, mac_data);
6416
6417 /* Enable K1 off to enable mPHY Power Gating */
6418 mac_data = er32(FEXTNVM6);
6419 mac_data |= BIT(31);
6420 ew32(FEXTNVM6, mac_data);
6421
6422 /* Enable mPHY power gating for any link and speed */
6423 mac_data = er32(FEXTNVM8);
6424 mac_data |= BIT(9);
6425 ew32(FEXTNVM8, mac_data);
6426
6427 /* Enable the Dynamic Clock Gating in the DMA and MAC */
6428 mac_data = er32(CTRL_EXT);
6429 mac_data |= E1000_CTRL_EXT_DMA_DYN_CLK_EN;
6430 ew32(CTRL_EXT, mac_data);
6431
6432 /* No MAC DPG gating SLP_S0 in modern standby
6433 * Switch the logic of the lanphypc to use PMC counter
6434 */
6435 mac_data = er32(FEXTNVM5);
6436 mac_data |= BIT(7);
6437 ew32(FEXTNVM5, mac_data);
6438 }
6439
6440 /* Disable the time synchronization clock */
6441 mac_data = er32(FEXTNVM7);
6442 mac_data |= BIT(31);
6443 mac_data &= ~BIT(0);
6444 ew32(FEXTNVM7, mac_data);
6445
6446 /* Dynamic Power Gating Enable */
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006447 mac_data = er32(CTRL_EXT);
Sasha Neftin3e55d232021-06-24 11:18:27 +03006448 mac_data |= BIT(3);
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006449 ew32(CTRL_EXT, mac_data);
6450
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006451 /* Check MAC Tx/Rx packet buffer pointers.
6452 * Reset MAC Tx/Rx packet buffer pointers to suppress any
6453 * pending traffic indication that would prevent power gating.
6454 */
6455 mac_data = er32(TDFH);
6456 if (mac_data)
6457 ew32(TDFH, 0);
6458 mac_data = er32(TDFT);
6459 if (mac_data)
6460 ew32(TDFT, 0);
6461 mac_data = er32(TDFHS);
6462 if (mac_data)
6463 ew32(TDFHS, 0);
6464 mac_data = er32(TDFTS);
6465 if (mac_data)
6466 ew32(TDFTS, 0);
6467 mac_data = er32(TDFPC);
6468 if (mac_data)
6469 ew32(TDFPC, 0);
6470 mac_data = er32(RDFH);
6471 if (mac_data)
6472 ew32(RDFH, 0);
6473 mac_data = er32(RDFT);
6474 if (mac_data)
6475 ew32(RDFT, 0);
6476 mac_data = er32(RDFHS);
6477 if (mac_data)
6478 ew32(RDFHS, 0);
6479 mac_data = er32(RDFTS);
6480 if (mac_data)
6481 ew32(RDFTS, 0);
6482 mac_data = er32(RDFPC);
6483 if (mac_data)
6484 ew32(RDFPC, 0);
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006485}
6486
6487static void e1000e_s0ix_exit_flow(struct e1000_adapter *adapter)
6488{
6489 struct e1000_hw *hw = &adapter->hw;
Sasha Neftinef407b82021-06-24 11:18:46 +03006490 bool firmware_bug = false;
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006491 u32 mac_data;
6492 u16 phy_data;
Sasha Neftinef407b82021-06-24 11:18:46 +03006493 u32 i = 0;
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006494
Sasha Neftincad014b2021-12-07 13:23:42 +02006495 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID &&
6496 hw->mac.type >= e1000_pch_adp) {
Sasha Neftin3e55d232021-06-24 11:18:27 +03006497 /* Request ME unconfigure the device from S0ix */
6498 mac_data = er32(H2ME);
6499 mac_data &= ~E1000_H2ME_START_DPG;
6500 mac_data |= E1000_H2ME_EXIT_DPG;
6501 ew32(H2ME, mac_data);
Sasha Neftinef407b82021-06-24 11:18:46 +03006502
6503 /* Poll up to 2.5 seconds for ME to unconfigure DPG.
6504 * If this takes more than 1 second, show a warning indicating a
6505 * firmware bug
6506 */
6507 while (!(er32(EXFWSM) & E1000_EXFWSM_DPG_EXIT_DONE)) {
6508 if (i > 100 && !firmware_bug)
6509 firmware_bug = true;
6510
6511 if (i++ == 250) {
6512 e_dbg("Timeout (firmware bug): %d msec\n",
6513 i * 10);
6514 break;
6515 }
6516
6517 usleep_range(10000, 11000);
6518 }
6519 if (firmware_bug)
6520 e_warn("DPG_EXIT_DONE took %d msec. This is a firmware bug\n",
6521 i * 10);
6522 else
6523 e_dbg("DPG_EXIT_DONE cleared after %d msec\n", i * 10);
Sasha Neftin3e55d232021-06-24 11:18:27 +03006524 } else {
6525 /* Request driver unconfigure the device from S0ix */
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006526
Sasha Neftin3e55d232021-06-24 11:18:27 +03006527 /* Disable the Dynamic Power Gating in the MAC */
6528 mac_data = er32(FEXTNVM7);
6529 mac_data &= 0xFFBFFFFF;
6530 ew32(FEXTNVM7, mac_data);
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006531
Sasha Neftin3e55d232021-06-24 11:18:27 +03006532 /* Disable mPHY power gating for any link and speed */
6533 mac_data = er32(FEXTNVM8);
6534 mac_data &= ~BIT(9);
6535 ew32(FEXTNVM8, mac_data);
Vitaly Lifshits632fbd52020-03-12 13:57:07 +02006536
Sasha Neftin3e55d232021-06-24 11:18:27 +03006537 /* Disable K1 off */
6538 mac_data = er32(FEXTNVM6);
6539 mac_data &= ~BIT(31);
6540 ew32(FEXTNVM6, mac_data);
Vitaly Lifshits632fbd52020-03-12 13:57:07 +02006541
Sasha Neftin3e55d232021-06-24 11:18:27 +03006542 /* Disable Ungate PGCB clock */
6543 mac_data = er32(FEXTNVM9);
6544 mac_data |= BIT(28);
6545 ew32(FEXTNVM9, mac_data);
Vitaly Lifshits632fbd52020-03-12 13:57:07 +02006546
Sasha Neftin3e55d232021-06-24 11:18:27 +03006547 /* Cancel not waking from dynamic
6548 * Power Gating with clock request
6549 */
6550 mac_data = er32(FEXTNVM12);
6551 mac_data &= ~BIT(12);
6552 ew32(FEXTNVM12, mac_data);
Vitaly Lifshits632fbd52020-03-12 13:57:07 +02006553
Sasha Neftin3e55d232021-06-24 11:18:27 +03006554 /* Cancel disable disconnected cable conditioning
6555 * for Power Gating
6556 */
6557 mac_data = er32(DPGFR);
6558 mac_data &= ~BIT(2);
6559 ew32(DPGFR, mac_data);
6560
6561 /* Disable the Dynamic Clock Gating in the DMA and MAC */
6562 mac_data = er32(CTRL_EXT);
6563 mac_data &= 0xFFF7FFFF;
6564 ew32(CTRL_EXT, mac_data);
6565
6566 /* Revert the lanphypc logic to use the internal Gbe counter
6567 * and not the PMC counter
6568 */
6569 mac_data = er32(FEXTNVM5);
6570 mac_data &= 0xFFFFFF7F;
6571 ew32(FEXTNVM5, mac_data);
6572
6573 /* Enable the periodic inband message,
6574 * Request PCIe clock in K1 page770_17[10:9] =01b
6575 */
6576 e1e_rphy(hw, HV_PM_CTRL, &phy_data);
6577 phy_data &= 0xFBFF;
6578 phy_data |= HV_PM_CTRL_K1_CLK_REQ;
6579 e1e_wphy(hw, HV_PM_CTRL, phy_data);
6580
6581 /* Return back configuration
6582 * 772_29[5] = 0 CS_Mode_Stay_In_K1
6583 */
6584 e1e_rphy(hw, I217_CGFREG, &phy_data);
6585 phy_data &= 0xFFDF;
6586 e1e_wphy(hw, I217_CGFREG, phy_data);
6587
6588 /* Change the MAC/PHY interface to Kumeran
6589 * Unforce the SMBus in PHY page769_23[0] = 0
6590 * Unforce the SMBus in MAC CTRL_EXT[11] = 0
6591 */
6592 e1e_rphy(hw, CV_SMB_CTRL, &phy_data);
6593 phy_data &= ~CV_SMB_CTRL_FORCE_SMBUS;
6594 e1e_wphy(hw, CV_SMB_CTRL, phy_data);
6595 mac_data = er32(CTRL_EXT);
6596 mac_data &= ~E1000_CTRL_EXT_FORCE_SMBUS;
6597 ew32(CTRL_EXT, mac_data);
6598 }
Vitaly Lifshits632fbd52020-03-12 13:57:07 +02006599
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006600 /* Disable Dynamic Power Gating */
6601 mac_data = er32(CTRL_EXT);
6602 mac_data &= 0xFFFFFFF7;
6603 ew32(CTRL_EXT, mac_data);
6604
Sasha Neftin3e55d232021-06-24 11:18:27 +03006605 /* Enable the time synchronization clock */
6606 mac_data = er32(FEXTNVM7);
6607 mac_data &= ~BIT(31);
6608 mac_data |= BIT(0);
6609 ew32(FEXTNVM7, mac_data);
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006610}
6611
David Ertman28002092014-02-14 07:16:41 +00006612static int e1000e_pm_freeze(struct device *dev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006613{
Chuhong Yuanee2e80c2019-07-23 22:15:13 +08006614 struct net_device *netdev = dev_get_drvdata(dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006615 struct e1000_adapter *adapter = netdev_priv(netdev);
Alexander Duycka7023812019-10-11 08:34:52 -07006616 bool present;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006617
Alexander Duycka7023812019-10-11 08:34:52 -07006618 rtnl_lock();
6619
6620 present = netif_device_present(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006621 netif_device_detach(netdev);
6622
Alexander Duycka7023812019-10-11 08:34:52 -07006623 if (present && netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00006624 int count = E1000_CHECK_RESET_COUNT;
6625
6626 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
Arjan van de Venab6973a2019-06-14 17:29:35 -07006627 usleep_range(10000, 11000);
Bruce Allanbb9e44d2012-03-21 00:39:12 +00006628
Auke Kokbc7f75f2007-09-17 12:30:59 -07006629 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
David Ertman28002092014-02-14 07:16:41 +00006630
6631 /* Quiesce the device without resetting the hardware */
6632 e1000e_down(adapter, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006633 e1000_free_irq(adapter);
6634 }
Alexander Duycka7023812019-10-11 08:34:52 -07006635 rtnl_unlock();
6636
Jeff Kirsher9f47a482017-03-23 20:47:15 -07006637 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006638
David Ertman28002092014-02-14 07:16:41 +00006639 /* Allow time for pending master requests to run */
6640 e1000e_disable_pcie_master(&adapter->hw);
6641
6642 return 0;
6643}
6644
6645static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
6646{
6647 struct net_device *netdev = pci_get_drvdata(pdev);
6648 struct e1000_adapter *adapter = netdev_priv(netdev);
6649 struct e1000_hw *hw = &adapter->hw;
Chen Yu6bf6be12020-05-22 01:59:00 +08006650 u32 ctrl, ctrl_ext, rctl, status, wufc;
David Ertman28002092014-02-14 07:16:41 +00006651 int retval = 0;
6652
Chen Yu6bf6be12020-05-22 01:59:00 +08006653 /* Runtime suspend should only enable wakeup for link changes */
6654 if (runtime)
6655 wufc = E1000_WUFC_LNKC;
6656 else if (device_may_wakeup(&pdev->dev))
6657 wufc = adapter->wol;
6658 else
6659 wufc = 0;
6660
Auke Kokbc7f75f2007-09-17 12:30:59 -07006661 status = er32(STATUS);
6662 if (status & E1000_STATUS_LU)
6663 wufc &= ~E1000_WUFC_LNKC;
6664
6665 if (wufc) {
6666 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006667 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006668
6669 /* turn on all-multi mode if wake on multicast is enabled */
6670 if (wufc & E1000_WUFC_MC) {
6671 rctl = er32(RCTL);
6672 rctl |= E1000_RCTL_MPE;
6673 ew32(RCTL, rctl);
6674 }
6675
6676 ctrl = er32(CTRL);
Bruce Allana4f58f52009-06-02 11:29:18 +00006677 ctrl |= E1000_CTRL_ADVD3WUC;
6678 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
6679 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006680 ew32(CTRL, ctrl);
6681
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006682 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
6683 adapter->hw.phy.media_type ==
6684 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006685 /* keep the laser running in D3 */
6686 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00006687 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006688 ew32(CTRL_EXT, ctrl_ext);
6689 }
6690
David Ertman63eb48f2014-02-14 07:16:46 +00006691 if (!runtime)
6692 e1000e_power_up_phy(adapter);
6693
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006694 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00006695 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006696
Bruce Allan82776a42009-08-14 14:35:33 +00006697 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00006698 /* enable wakeup by the PHY */
6699 retval = e1000_init_phy_wakeup(adapter, wufc);
6700 if (retval)
6701 return retval;
6702 } else {
6703 /* enable wakeup by the MAC */
6704 ew32(WUFC, wufc);
6705 ew32(WUC, E1000_WUC_PME_EN);
6706 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006707 } else {
6708 ew32(WUC, 0);
6709 ew32(WUFC, 0);
David Ertman28002092014-02-14 07:16:41 +00006710
6711 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006712 }
6713
David Ertman74f350e2014-02-22 03:15:17 +00006714 if (adapter->hw.phy.type == e1000_phy_igp_3) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006715 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
Sasha Neftinc8744f42017-04-06 10:26:47 +03006716 } else if (hw->mac.type >= e1000_pch_lpt) {
Chen Yu6bf6be12020-05-22 01:59:00 +08006717 if (wufc && !(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
David Ertman74f350e2014-02-22 03:15:17 +00006718 /* ULP does not support wake from unicast, multicast
6719 * or broadcast.
6720 */
6721 retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
6722
6723 if (retval)
6724 return retval;
6725 }
6726
Raanan Avargilf5ac7442015-07-06 16:48:00 +03006727 /* Ensure that the appropriate bits are set in LPI_CTRL
6728 * for EEE in Sx
6729 */
6730 if ((hw->phy.type >= e1000_phy_i217) &&
6731 adapter->eee_advert && hw->dev_spec.ich8lan.eee_lp_ability) {
6732 u16 lpi_ctrl = 0;
6733
6734 retval = hw->phy.ops.acquire(hw);
6735 if (!retval) {
6736 retval = e1e_rphy_locked(hw, I82579_LPI_CTRL,
6737 &lpi_ctrl);
6738 if (!retval) {
6739 if (adapter->eee_advert &
6740 hw->dev_spec.ich8lan.eee_lp_ability &
6741 I82579_EEE_100_SUPPORTED)
6742 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
6743 if (adapter->eee_advert &
6744 hw->dev_spec.ich8lan.eee_lp_ability &
6745 I82579_EEE_1000_SUPPORTED)
6746 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
6747
6748 retval = e1e_wphy_locked(hw, I82579_LPI_CTRL,
6749 lpi_ctrl);
6750 }
6751 }
6752 hw->phy.ops.release(hw);
6753 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006754
Bruce Allane921eb12012-11-28 09:28:37 +00006755 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006756 * would have already happened in close and is redundant.
6757 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006758 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006759
Dean Nelson24b41c92013-06-13 03:55:44 +00006760 pci_clear_master(pdev);
6761
Bruce Allane921eb12012-11-28 09:28:37 +00006762 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006763 * correctable error when the MAC transitions from D0 to D3. To
6764 * prevent this we need to mask off the correctable errors on the
6765 * downstream port of the pci-e switch.
Li Zhange8c254c2013-08-13 18:42:58 +00006766 *
6767 * We don't have the associated upstream bridge while assigning
6768 * the PCI device into guest. For example, the KVM on power is
6769 * one of the cases.
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006770 */
6771 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6772 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006773 u16 devctl;
6774
Li Zhange8c254c2013-08-13 18:42:58 +00006775 if (!us_dev)
6776 return 0;
6777
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006778 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6779 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6780 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006781
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006782 pci_save_state(pdev);
6783 pci_prepare_to_sleep(pdev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006784
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006785 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006786 }
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006787
6788 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006789}
6790
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006791/**
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006792 * __e1000e_disable_aspm - Disable ASPM states
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006793 * @pdev: pointer to PCI device struct
6794 * @state: bit-mask of ASPM states to disable
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006795 * @locked: indication if this context holds pci_bus_sem locked.
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006796 *
6797 * Some devices *must* have certain ASPM states disabled per hardware errata.
6798 **/
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006799static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state, int locked)
Bruce Allan6f461f62010-04-27 03:33:04 +00006800{
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006801 struct pci_dev *parent = pdev->bus->self;
6802 u16 aspm_dis_mask = 0;
6803 u16 pdev_aspmc, parent_aspmc;
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006804
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006805 switch (state) {
6806 case PCIE_LINK_STATE_L0S:
6807 case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
6808 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
Jeff Kirsher5463fce62020-06-03 20:07:26 -07006809 fallthrough; /* can't have L1 without L0s */
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006810 case PCIE_LINK_STATE_L1:
6811 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
6812 break;
6813 default:
6814 return;
6815 }
6816
6817 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6818 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6819
6820 if (parent) {
6821 pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
6822 &parent_aspmc);
6823 parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6824 }
6825
6826 /* Nothing to do if the ASPM states to be disabled already are */
6827 if (!(pdev_aspmc & aspm_dis_mask) &&
6828 (!parent || !(parent_aspmc & aspm_dis_mask)))
6829 return;
6830
6831 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6832 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
6833 "L0s" : "",
6834 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
6835 "L1" : "");
6836
6837#ifdef CONFIG_PCIEASPM
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006838 if (locked)
6839 pci_disable_link_state_locked(pdev, state);
6840 else
6841 pci_disable_link_state(pdev, state);
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006842
6843 /* Double-check ASPM control. If not disabled by the above, the
6844 * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
6845 * not enabled); override by writing PCI config space directly.
6846 */
6847 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6848 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6849
6850 if (!(aspm_dis_mask & pdev_aspmc))
6851 return;
6852#endif
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006853
Bruce Allane921eb12012-11-28 09:28:37 +00006854 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006855 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006856 */
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006857 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
Bruce Allan6f461f62010-04-27 03:33:04 +00006858
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006859 if (parent)
6860 pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
6861 aspm_dis_mask);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006862}
6863
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006864/**
6865 * e1000e_disable_aspm - Disable ASPM states.
6866 * @pdev: pointer to PCI device struct
6867 * @state: bit-mask of ASPM states to disable
6868 *
6869 * This function acquires the pci_bus_sem!
6870 * Some devices *must* have certain ASPM states disabled per hardware errata.
6871 **/
6872static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6873{
6874 __e1000e_disable_aspm(pdev, state, 0);
6875}
6876
6877/**
Sasha Neftin39da2ca2021-03-14 15:59:20 +02006878 * e1000e_disable_aspm_locked - Disable ASPM states.
Yanir Lubetkinbeb0a152015-06-10 01:15:05 +03006879 * @pdev: pointer to PCI device struct
6880 * @state: bit-mask of ASPM states to disable
6881 *
6882 * This function must be called with pci_bus_sem acquired!
6883 * Some devices *must* have certain ASPM states disabled per hardware errata.
6884 **/
6885static void e1000e_disable_aspm_locked(struct pci_dev *pdev, u16 state)
6886{
6887 __e1000e_disable_aspm(pdev, state, 1);
6888}
6889
Alexander Duycka7023812019-10-11 08:34:52 -07006890static int e1000e_pm_thaw(struct device *dev)
6891{
6892 struct net_device *netdev = dev_get_drvdata(dev);
6893 struct e1000_adapter *adapter = netdev_priv(netdev);
6894 int rc = 0;
6895
6896 e1000e_set_interrupt_capability(adapter);
6897
6898 rtnl_lock();
6899 if (netif_running(netdev)) {
6900 rc = e1000_request_irq(adapter);
6901 if (rc)
6902 goto err_irq;
6903
6904 e1000e_up(adapter);
6905 }
6906
6907 netif_device_attach(netdev);
6908err_irq:
6909 rtnl_unlock();
6910
6911 return rc;
6912}
6913
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006914static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006915{
6916 struct net_device *netdev = pci_get_drvdata(pdev);
6917 struct e1000_adapter *adapter = netdev_priv(netdev);
6918 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006919 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006920
Bruce Allan78cd29d2011-03-24 03:09:03 +00006921 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6922 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6923 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6924 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6925 if (aspm_disable_flag)
Raanan Avargil2758f9e2015-07-06 17:57:36 +03006926 e1000e_disable_aspm(pdev, aspm_disable_flag);
Bruce Allan78cd29d2011-03-24 03:09:03 +00006927
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006928 pci_set_master(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006929
Bruce Allan2fbe4522012-04-19 03:21:47 +00006930 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006931 e1000_resume_workarounds_pchlan(&adapter->hw);
6932
Auke Kokbc7f75f2007-09-17 12:30:59 -07006933 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006934
6935 /* report the system wakeup cause from S3/S4 */
6936 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6937 u16 phy_data;
6938
6939 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6940 if (phy_data) {
6941 e_info("PHY Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006942 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6943 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6944 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6945 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6946 phy_data & E1000_WUS_LNKC ?
6947 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006948 }
6949 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6950 } else {
6951 u32 wus = er32(WUS);
David Ertman6cf08d12014-04-05 06:07:00 +00006952
Bruce Allana4f58f52009-06-02 11:29:18 +00006953 if (wus) {
6954 e_info("MAC Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006955 wus & E1000_WUS_EX ? "Unicast Packet" :
6956 wus & E1000_WUS_MC ? "Multicast Packet" :
6957 wus & E1000_WUS_BC ? "Broadcast Packet" :
6958 wus & E1000_WUS_MAG ? "Magic Packet" :
6959 wus & E1000_WUS_LNKC ? "Link Status Change" :
6960 "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006961 }
6962 ew32(WUS, ~0);
6963 }
6964
Auke Kokbc7f75f2007-09-17 12:30:59 -07006965 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006966
Bruce Allancd791612010-05-10 14:59:51 +00006967 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006968
Bruce Allane921eb12012-11-28 09:28:37 +00006969 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006970 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006971 * under the control of the driver.
6972 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006973 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006974 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006975
6976 return 0;
6977}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006978
Wei Yongjunf2d75b12021-03-17 14:52:34 +00006979static __maybe_unused int e1000e_pm_prepare(struct device *dev)
Chen Yuccf8b942020-12-01 09:21:50 +08006980{
6981 return pm_runtime_suspended(dev) &&
6982 pm_suspend_via_firmware();
6983}
6984
Arnd Bergmann880e6262020-05-27 15:47:00 +02006985static __maybe_unused int e1000e_pm_suspend(struct device *dev)
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006986{
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03006987 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
6988 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006989 struct pci_dev *pdev = to_pci_dev(dev);
Chris Wilson833521e2017-05-31 18:50:43 +03006990 int rc;
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006991
David Ertman2a7e19a2014-07-11 06:21:31 +00006992 e1000e_flush_lpic(pdev);
6993
David Ertman28002092014-02-14 07:16:41 +00006994 e1000e_pm_freeze(dev);
6995
Chris Wilson833521e2017-05-31 18:50:43 +03006996 rc = __e1000_shutdown(pdev, false);
Mario Limonciello808e0d82020-12-14 13:29:32 -06006997 if (rc) {
Chris Wilson833521e2017-05-31 18:50:43 +03006998 e1000e_pm_thaw(dev);
Mario Limonciello808e0d82020-12-14 13:29:32 -06006999 } else {
7000 /* Introduce S0ix implementation */
Mario Limonciello3c98cbf2020-12-14 13:29:35 -06007001 if (adapter->flags2 & FLAG2_ENABLE_S0IX_FLOWS)
Mario Limonciello808e0d82020-12-14 13:29:32 -06007002 e1000e_s0ix_entry_flow(adapter);
7003 }
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03007004
Chris Wilson833521e2017-05-31 18:50:43 +03007005 return rc;
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007006}
7007
Arnd Bergmann880e6262020-05-27 15:47:00 +02007008static __maybe_unused int e1000e_pm_resume(struct device *dev)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007009{
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03007010 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
7011 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007012 struct pci_dev *pdev = to_pci_dev(dev);
David Ertman28002092014-02-14 07:16:41 +00007013 int rc;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007014
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03007015 /* Introduce S0ix implementation */
Mario Limonciello3c98cbf2020-12-14 13:29:35 -06007016 if (adapter->flags2 & FLAG2_ENABLE_S0IX_FLOWS)
Sasha Neftinf15bb6d2019-09-16 09:52:40 +03007017 e1000e_s0ix_exit_flow(adapter);
7018
David Ertman28002092014-02-14 07:16:41 +00007019 rc = __e1000_resume(pdev);
7020 if (rc)
7021 return rc;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007022
David Ertman28002092014-02-14 07:16:41 +00007023 return e1000e_pm_thaw(dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007024}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007025
Arnd Bergmann880e6262020-05-27 15:47:00 +02007026static __maybe_unused int e1000e_pm_runtime_idle(struct device *dev)
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007027{
Chuhong Yuanee2e80c2019-07-23 22:15:13 +08007028 struct net_device *netdev = dev_get_drvdata(dev);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007029 struct e1000_adapter *adapter = netdev_priv(netdev);
David Ertman2116bc252014-07-11 06:21:23 +00007030 u16 eee_lp;
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007031
David Ertman2116bc252014-07-11 06:21:23 +00007032 eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability;
7033
7034 if (!e1000e_has_link(adapter)) {
7035 adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp;
David Ertman63eb48f2014-02-14 07:16:46 +00007036 pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
David Ertman2116bc252014-07-11 06:21:23 +00007037 }
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007038
7039 return -EBUSY;
7040}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007041
Arnd Bergmann880e6262020-05-27 15:47:00 +02007042static __maybe_unused int e1000e_pm_runtime_resume(struct device *dev)
David Ertman63eb48f2014-02-14 07:16:46 +00007043{
7044 struct pci_dev *pdev = to_pci_dev(dev);
7045 struct net_device *netdev = pci_get_drvdata(pdev);
7046 struct e1000_adapter *adapter = netdev_priv(netdev);
7047 int rc;
7048
7049 rc = __e1000_resume(pdev);
7050 if (rc)
7051 return rc;
7052
7053 if (netdev->flags & IFF_UP)
Alexander Duyck386164d2015-10-27 16:59:31 -07007054 e1000e_up(adapter);
David Ertman63eb48f2014-02-14 07:16:46 +00007055
7056 return rc;
7057}
7058
Arnd Bergmann880e6262020-05-27 15:47:00 +02007059static __maybe_unused int e1000e_pm_runtime_suspend(struct device *dev)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007060{
7061 struct pci_dev *pdev = to_pci_dev(dev);
7062 struct net_device *netdev = pci_get_drvdata(pdev);
7063 struct e1000_adapter *adapter = netdev_priv(netdev);
7064
David Ertman63eb48f2014-02-14 07:16:46 +00007065 if (netdev->flags & IFF_UP) {
7066 int count = E1000_CHECK_RESET_COUNT;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007067
David Ertman63eb48f2014-02-14 07:16:46 +00007068 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
Arjan van de Venab6973a2019-06-14 17:29:35 -07007069 usleep_range(10000, 11000);
David Ertman63eb48f2014-02-14 07:16:46 +00007070
7071 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
7072
7073 /* Down the device without resetting the hardware */
7074 e1000e_down(adapter, false);
7075 }
7076
7077 if (__e1000_shutdown(pdev, true)) {
7078 e1000e_pm_runtime_resume(dev);
7079 return -EBUSY;
7080 }
7081
7082 return 0;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007083}
Auke Kokbc7f75f2007-09-17 12:30:59 -07007084
7085static void e1000_shutdown(struct pci_dev *pdev)
7086{
David Ertman2a7e19a2014-07-11 06:21:31 +00007087 e1000e_flush_lpic(pdev);
7088
David Ertman28002092014-02-14 07:16:41 +00007089 e1000e_pm_freeze(&pdev->dev);
7090
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00007091 __e1000_shutdown(pdev, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007092}
7093
7094#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08007095
Bruce Allan8bb62862013-01-16 08:46:49 +00007096static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08007097{
7098 struct net_device *netdev = data;
7099 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007100
7101 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00007102 int vector, msix_irq;
7103
Dongdong Deng147b2c82010-11-16 19:50:15 -08007104 vector = 0;
7105 msix_irq = adapter->msix_entries[vector].vector;
Konstantin Khlebnikovfd8e5972017-05-19 10:18:49 +03007106 if (disable_hardirq(msix_irq))
7107 e1000_intr_msix_rx(msix_irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007108 enable_irq(msix_irq);
7109
7110 vector++;
7111 msix_irq = adapter->msix_entries[vector].vector;
Konstantin Khlebnikovfd8e5972017-05-19 10:18:49 +03007112 if (disable_hardirq(msix_irq))
7113 e1000_intr_msix_tx(msix_irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007114 enable_irq(msix_irq);
7115
7116 vector++;
7117 msix_irq = adapter->msix_entries[vector].vector;
Konstantin Khlebnikovfd8e5972017-05-19 10:18:49 +03007118 if (disable_hardirq(msix_irq))
7119 e1000_msix_other(msix_irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007120 enable_irq(msix_irq);
7121 }
7122
7123 return IRQ_HANDLED;
7124}
7125
Bruce Allane921eb12012-11-28 09:28:37 +00007126/**
7127 * e1000_netpoll
7128 * @netdev: network interface device structure
7129 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07007130 * Polling 'interrupt' - used by things like netconsole to send skbs
7131 * without having to re-enable interrupts. It's not called while
7132 * the interrupt routine is executing.
7133 */
7134static void e1000_netpoll(struct net_device *netdev)
7135{
7136 struct e1000_adapter *adapter = netdev_priv(netdev);
7137
Dongdong Deng147b2c82010-11-16 19:50:15 -08007138 switch (adapter->int_mode) {
7139 case E1000E_INT_MODE_MSIX:
7140 e1000_intr_msix(adapter->pdev->irq, netdev);
7141 break;
7142 case E1000E_INT_MODE_MSI:
WANG Cong31119122016-12-10 14:22:42 -08007143 if (disable_hardirq(adapter->pdev->irq))
7144 e1000_intr_msi(adapter->pdev->irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007145 enable_irq(adapter->pdev->irq);
7146 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00007147 default: /* E1000E_INT_MODE_LEGACY */
WANG Cong31119122016-12-10 14:22:42 -08007148 if (disable_hardirq(adapter->pdev->irq))
7149 e1000_intr(adapter->pdev->irq, netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08007150 enable_irq(adapter->pdev->irq);
7151 break;
7152 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07007153}
7154#endif
7155
7156/**
7157 * e1000_io_error_detected - called when PCI error is detected
7158 * @pdev: Pointer to PCI device
7159 * @state: The current pci connection state
7160 *
7161 * This function is called after a PCI bus error affecting
7162 * this device has been detected.
7163 */
7164static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
7165 pci_channel_state_t state)
7166{
Alexander Duycka7023812019-10-11 08:34:52 -07007167 e1000e_pm_freeze(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007168
Mike Masonc93b5a72009-06-30 12:45:53 +00007169 if (state == pci_channel_io_perm_failure)
7170 return PCI_ERS_RESULT_DISCONNECT;
7171
Auke Kokbc7f75f2007-09-17 12:30:59 -07007172 pci_disable_device(pdev);
7173
Hao Chen800b74a2021-05-19 14:14:44 +08007174 /* Request a slot reset. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007175 return PCI_ERS_RESULT_NEED_RESET;
7176}
7177
7178/**
7179 * e1000_io_slot_reset - called after the pci bus has been reset.
7180 * @pdev: Pointer to PCI device
7181 *
7182 * Restart the card from scratch, as if from a cold-boot. Implementation
David Ertman28002092014-02-14 07:16:41 +00007183 * resembles the first-half of the e1000e_pm_resume routine.
Auke Kokbc7f75f2007-09-17 12:30:59 -07007184 */
7185static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
7186{
7187 struct net_device *netdev = pci_get_drvdata(pdev);
7188 struct e1000_adapter *adapter = netdev_priv(netdev);
7189 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00007190 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09007191 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007192 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007193
Bruce Allan78cd29d2011-03-24 03:09:03 +00007194 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
7195 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00007196 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00007197 aspm_disable_flag |= PCIE_LINK_STATE_L1;
7198 if (aspm_disable_flag)
Raanan Avargil2758f9e2015-07-06 17:57:36 +03007199 e1000e_disable_aspm_locked(pdev, aspm_disable_flag);
Bruce Allan78cd29d2011-03-24 03:09:03 +00007200
Bruce Allanf0f422e2008-08-04 17:21:53 -07007201 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09007202 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007203 dev_err(&pdev->dev,
7204 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007205 result = PCI_ERS_RESULT_DISCONNECT;
7206 } else {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007207 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007208 pci_restore_state(pdev);
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00007209 pci_set_master(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007210
7211 pci_enable_wake(pdev, PCI_D3hot, 0);
7212 pci_enable_wake(pdev, PCI_D3cold, 0);
7213
7214 e1000e_reset(adapter);
7215 ew32(WUS, ~0);
7216 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007217 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07007218
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007219 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007220}
7221
7222/**
7223 * e1000_io_resume - called when traffic can start flowing again.
7224 * @pdev: Pointer to PCI device
7225 *
7226 * This callback is called when the error recovery driver tells us that
7227 * its OK to resume normal operation. Implementation resembles the
David Ertman28002092014-02-14 07:16:41 +00007228 * second-half of the e1000e_pm_resume routine.
Auke Kokbc7f75f2007-09-17 12:30:59 -07007229 */
7230static void e1000_io_resume(struct pci_dev *pdev)
7231{
7232 struct net_device *netdev = pci_get_drvdata(pdev);
7233 struct e1000_adapter *adapter = netdev_priv(netdev);
7234
Bruce Allancd791612010-05-10 14:59:51 +00007235 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007236
Alexander Duycka7023812019-10-11 08:34:52 -07007237 e1000e_pm_thaw(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007238
Bruce Allane921eb12012-11-28 09:28:37 +00007239 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07007240 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07007241 * under the control of the driver.
7242 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007243 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00007244 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007245}
7246
7247static void e1000_print_device_info(struct e1000_adapter *adapter)
7248{
7249 struct e1000_hw *hw = &adapter->hw;
7250 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00007251 u32 ret_val;
7252 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07007253
7254 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00007255 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07007256 /* bus width */
7257 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
Bruce Allanf0ff4392013-02-20 04:05:39 +00007258 "Width x1"),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07007259 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07007260 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07007261 e_info("Intel(R) PRO/%s Network Connection\n",
7262 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00007263 ret_val = e1000_read_pba_string_generic(hw, pba_str,
7264 E1000_PBANUM_LENGTH);
7265 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00007266 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00007267 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
7268 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007269}
7270
Auke Kok10aa4c02008-08-04 17:21:20 -07007271static void e1000_eeprom_checks(struct e1000_adapter *adapter)
7272{
7273 struct e1000_hw *hw = &adapter->hw;
7274 int ret_val;
7275 u16 buf = 0;
7276
7277 if (hw->mac.type != e1000_82573)
7278 return;
7279
7280 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00007281 le16_to_cpus(&buf);
Jacob Keller18dd2392016-04-13 16:08:32 -07007282 if (!ret_val && (!(buf & BIT(0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07007283 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07007284 dev_warn(&adapter->pdev->dev,
7285 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07007286 }
Auke Kok10aa4c02008-08-04 17:21:20 -07007287}
7288
Alexander Duyck55e7fe52015-05-02 01:09:59 -07007289static netdev_features_t e1000_fix_features(struct net_device *netdev,
7290 netdev_features_t features)
7291{
7292 struct e1000_adapter *adapter = netdev_priv(netdev);
7293 struct e1000_hw *hw = &adapter->hw;
7294
7295 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
7296 if ((hw->mac.type >= e1000_pch2lan) && (netdev->mtu > ETH_DATA_LEN))
7297 features &= ~NETIF_F_RXFCS;
7298
Jarod Wilson83808642016-06-09 19:50:13 -04007299 /* Since there is no support for separate Rx/Tx vlan accel
7300 * enable/disable make sure Tx flag is always in same state as Rx.
7301 */
7302 if (features & NETIF_F_HW_VLAN_CTAG_RX)
7303 features |= NETIF_F_HW_VLAN_CTAG_TX;
7304 else
7305 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
7306
Alexander Duyck55e7fe52015-05-02 01:09:59 -07007307 return features;
7308}
7309
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007310static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00007311 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00007312{
7313 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007314 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00007315
7316 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
7317 adapter->flags |= FLAG_TSO_FORCE;
7318
Patrick McHardyf6469682013-04-19 02:04:27 +00007319 if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00007320 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
7321 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00007322 return 0;
7323
Ben Greear01840392012-02-11 15:39:25 +00007324 if (changed & NETIF_F_RXFCS) {
7325 if (features & NETIF_F_RXFCS) {
7326 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
7327 } else {
7328 /* We need to take it back to defaults, which might mean
7329 * stripping is still disabled at the adapter level.
7330 */
7331 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
7332 adapter->flags2 |= FLAG2_CRC_STRIPPING;
7333 else
7334 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
7335 }
7336 }
7337
Bruce Allan70495a52012-01-11 01:26:50 +00007338 netdev->features = features;
7339
Bruce Allandc221292011-08-19 03:23:48 +00007340 if (netif_running(netdev))
7341 e1000e_reinit_locked(adapter);
7342 else
7343 e1000e_reset(adapter);
7344
Serhey Popovychb0ddfe22018-03-29 17:51:36 +03007345 return 1;
Bruce Allandc221292011-08-19 03:23:48 +00007346}
7347
Stephen Hemminger651c2462008-11-19 21:57:48 -08007348static const struct net_device_ops e1000e_netdev_ops = {
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01007349 .ndo_open = e1000e_open,
7350 .ndo_stop = e1000e_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007351 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00007352 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00007353 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08007354 .ndo_set_mac_address = e1000_set_mac,
7355 .ndo_change_mtu = e1000_change_mtu,
Arnd Bergmanna7605372021-07-27 15:45:13 +02007356 .ndo_eth_ioctl = e1000_ioctl,
Stephen Hemminger651c2462008-11-19 21:57:48 -08007357 .ndo_tx_timeout = e1000_tx_timeout,
7358 .ndo_validate_addr = eth_validate_addr,
7359
Stephen Hemminger651c2462008-11-19 21:57:48 -08007360 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
7361 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
7362#ifdef CONFIG_NET_POLL_CONTROLLER
7363 .ndo_poll_controller = e1000_netpoll,
7364#endif
Bruce Allandc221292011-08-19 03:23:48 +00007365 .ndo_set_features = e1000_set_features,
Alexander Duyck55e7fe52015-05-02 01:09:59 -07007366 .ndo_fix_features = e1000_fix_features,
Toshiaki Makitaf2701b12015-08-06 17:57:29 +09007367 .ndo_features_check = passthru_features_check,
Stephen Hemminger651c2462008-11-19 21:57:48 -08007368};
7369
Auke Kokbc7f75f2007-09-17 12:30:59 -07007370/**
7371 * e1000_probe - Device Initialization Routine
7372 * @pdev: PCI device information struct
7373 * @ent: entry in e1000_pci_tbl
7374 *
7375 * Returns 0 on success, negative on failure
7376 *
7377 * e1000_probe initializes an adapter identified by a pci_dev structure.
7378 * The OS initialization, configuring of the adapter private structure,
7379 * and a hardware reset occur.
7380 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00007381static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07007382{
7383 struct net_device *netdev;
7384 struct e1000_adapter *adapter;
7385 struct e1000_hw *hw;
7386 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05007387 resource_size_t mmio_start, mmio_len;
7388 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007389 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00007390 u16 aspm_disable_flag = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00007391 int bars, i, err, pci_using_dac;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007392 u16 eeprom_data = 0;
7393 u16 eeprom_apme_mask = E1000_EEPROM_APME;
Brian Walsh847042a2016-04-12 23:22:30 -04007394 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007395
Bruce Allan78cd29d2011-03-24 03:09:03 +00007396 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
7397 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00007398 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00007399 aspm_disable_flag |= PCIE_LINK_STATE_L1;
7400 if (aspm_disable_flag)
7401 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09007402
Bruce Allanf0f422e2008-08-04 17:21:53 -07007403 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007404 if (err)
7405 return err;
7406
7407 pci_using_dac = 0;
Russell King718a39e2013-06-10 12:22:30 +01007408 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07007409 if (!err) {
Russell King718a39e2013-06-10 12:22:30 +01007410 pci_using_dac = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007411 } else {
Russell King718a39e2013-06-10 12:22:30 +01007412 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07007413 if (err) {
Russell King718a39e2013-06-10 12:22:30 +01007414 dev_err(&pdev->dev,
7415 "No usable DMA configuration, aborting\n");
7416 goto err_dma;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007417 }
7418 }
7419
Bruce Allan17e813e2013-02-20 04:06:01 +00007420 bars = pci_select_bars(pdev, IORESOURCE_MEM);
7421 err = pci_request_selected_regions_exclusive(pdev, bars,
7422 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007423 if (err)
7424 goto err_pci_reg;
7425
Xiaotian Feng68eac462009-08-14 14:35:52 +00007426 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07007427 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00007428
Auke Kokbc7f75f2007-09-17 12:30:59 -07007429 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08007430 /* PCI config space info */
7431 err = pci_save_state(pdev);
7432 if (err)
7433 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007434
7435 err = -ENOMEM;
7436 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
7437 if (!netdev)
7438 goto err_alloc_etherdev;
7439
Auke Kokbc7f75f2007-09-17 12:30:59 -07007440 SET_NETDEV_DEV(netdev, &pdev->dev);
7441
Tom Herbertf85e4df2010-05-05 14:03:32 +00007442 netdev->irq = pdev->irq;
7443
Auke Kokbc7f75f2007-09-17 12:30:59 -07007444 pci_set_drvdata(pdev, netdev);
7445 adapter = netdev_priv(netdev);
7446 hw = &adapter->hw;
7447 adapter->netdev = netdev;
7448 adapter->pdev = pdev;
7449 adapter->ei = ei;
7450 adapter->pba = ei->pba;
7451 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00007452 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007453 adapter->hw.adapter = adapter;
7454 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00007455 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007456 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007457
7458 mmio_start = pci_resource_start(pdev, 0);
7459 mmio_len = pci_resource_len(pdev, 0);
7460
7461 err = -EIO;
7462 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
7463 if (!adapter->hw.hw_addr)
7464 goto err_ioremap;
7465
7466 if ((adapter->flags & FLAG_HAS_FLASH) &&
Yanir Lubetkin1103a632015-02-28 10:10:06 +00007467 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM) &&
7468 (hw->mac.type < e1000_pch_spt)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007469 flash_start = pci_resource_start(pdev, 1);
7470 flash_len = pci_resource_len(pdev, 1);
7471 adapter->hw.flash_address = ioremap(flash_start, flash_len);
7472 if (!adapter->hw.flash_address)
7473 goto err_flashmap;
7474 }
7475
Bruce Alland495bcb2013-03-20 07:23:11 +00007476 /* Set default EEE advertisement */
7477 if (adapter->flags2 & FLAG2_HAS_EEE)
7478 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
7479
Auke Kokbc7f75f2007-09-17 12:30:59 -07007480 /* construct the net_device struct */
Bruce Allane80bd1d2013-05-01 01:19:46 +00007481 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007482 e1000e_set_ethtool_ops(netdev);
Bruce Allane80bd1d2013-05-01 01:19:46 +00007483 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00007484 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00007485 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07007486
7487 netdev->mem_start = mmio_start;
7488 netdev->mem_end = mmio_start + mmio_len;
7489
7490 adapter->bd_number = cards_found++;
7491
Bruce Allan4662e822008-08-26 18:37:06 -07007492 e1000e_check_options(adapter);
7493
Auke Kokbc7f75f2007-09-17 12:30:59 -07007494 /* setup adapter struct */
7495 err = e1000_sw_init(adapter);
7496 if (err)
7497 goto err_sw_init;
7498
Auke Kokbc7f75f2007-09-17 12:30:59 -07007499 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
7500 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
7501 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
7502
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07007503 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007504 if (err)
7505 goto err_hw_init;
7506
Bruce Allan4a770352008-10-01 17:18:35 -07007507 if ((adapter->flags & FLAG_IS_ICH) &&
Yanir Lubetkin152c0a92015-03-20 17:41:53 -07007508 (adapter->flags & FLAG_READ_ONLY_NVM) &&
7509 (hw->mac.type < e1000_pch_spt))
Bruce Allan4a770352008-10-01 17:18:35 -07007510 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
7511
Auke Kokbc7f75f2007-09-17 12:30:59 -07007512 hw->mac.ops.get_bus_info(&adapter->hw);
7513
Jeff Kirsher318a94d2008-03-28 09:15:16 -07007514 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007515
7516 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07007517 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007518 adapter->hw.phy.mdix = AUTO_ALL_MODES;
7519 adapter->hw.phy.disable_polarity_correction = 0;
7520 adapter->hw.phy.ms_type = e1000_ms_hw_default;
7521 }
7522
Bruce Allan470a5422012-05-26 06:08:48 +00007523 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00007524 dev_info(&pdev->dev,
7525 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007526
Bruce Allandc221292011-08-19 03:23:48 +00007527 /* Set initial default active device features */
7528 netdev->features = (NETIF_F_SG |
Patrick McHardyf6469682013-04-19 02:04:27 +00007529 NETIF_F_HW_VLAN_CTAG_RX |
7530 NETIF_F_HW_VLAN_CTAG_TX |
Bruce Allandc221292011-08-19 03:23:48 +00007531 NETIF_F_TSO |
7532 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00007533 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00007534 NETIF_F_RXCSUM |
7535 NETIF_F_HW_CSUM);
7536
7537 /* Set user-changeable features (subset of all device features) */
7538 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00007539 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00007540 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00007541 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007542
7543 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardyf6469682013-04-19 02:04:27 +00007544 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007545
Bruce Allandc221292011-08-19 03:23:48 +00007546 netdev->vlan_features |= (NETIF_F_SG |
7547 NETIF_F_TSO |
7548 NETIF_F_TSO6 |
7549 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07007550
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00007551 netdev->priv_flags |= IFF_UNICAST_FLT;
7552
Yi Zou7b872a52010-09-22 17:57:58 +00007553 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007554 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007555 netdev->vlan_features |= NETIF_F_HIGHDMA;
7556 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07007557
Jarod Wilson91c527a2016-10-17 15:54:05 -04007558 /* MTU range: 68 - max_hw_frame_size */
7559 netdev->min_mtu = ETH_MIN_MTU;
7560 netdev->max_mtu = adapter->max_hw_frame_size -
7561 (VLAN_ETH_HLEN + ETH_FCS_LEN);
7562
Auke Kokbc7f75f2007-09-17 12:30:59 -07007563 if (e1000e_enable_mng_pass_thru(&adapter->hw))
7564 adapter->flags |= FLAG_MNG_PT_ENABLED;
7565
Bruce Allane921eb12012-11-28 09:28:37 +00007566 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07007567 * put the device in a known good starting state
7568 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007569 adapter->hw.mac.ops.reset_hw(&adapter->hw);
7570
Bruce Allane921eb12012-11-28 09:28:37 +00007571 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07007572 * attempt. Let's give it a few tries
7573 */
7574 for (i = 0;; i++) {
7575 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
7576 break;
7577 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00007578 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007579 err = -EIO;
7580 goto err_eeprom;
7581 }
7582 }
7583
Auke Kok10aa4c02008-08-04 17:21:20 -07007584 e1000_eeprom_checks(adapter);
7585
Bruce Allan608f8a02010-01-13 02:04:58 +00007586 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007587 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00007588 dev_err(&pdev->dev,
7589 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007590
Jakub Kicinskia05e4c02021-10-04 09:05:21 -07007591 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007592
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00007593 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00007594 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00007595 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007596 err = -EIO;
7597 goto err_eeprom;
7598 }
7599
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08007600 timer_setup(&adapter->watchdog_timer, e1000_watchdog, 0);
Kees Cook26566ea2017-10-16 17:29:35 -07007601 timer_setup(&adapter->phy_info_timer, e1000_update_phy_info, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007602
7603 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08007604 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07007605 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
7606 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00007607 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007608
Auke Kokbc7f75f2007-09-17 12:30:59 -07007609 /* Initialize link parameters. User can change them with ethtool */
7610 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00007611 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08007612 adapter->hw.fc.requested_mode = e1000_fc_default;
7613 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007614 adapter->hw.phy.autoneg_advertised = 0x2f;
7615
Bruce Allane921eb12012-11-28 09:28:37 +00007616 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07007617 * the EEPROM, enable the ACPI Magic Packet filter
7618 */
7619 if (adapter->flags & FLAG_APME_IN_WUC) {
7620 /* APME bit in EEPROM is mapped to WUC.APME */
7621 eeprom_data = er32(WUC);
7622 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00007623 if ((hw->mac.type > e1000_ich10lan) &&
7624 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00007625 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07007626 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
7627 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
7628 (adapter->hw.bus.func == 1))
Brian Walsh847042a2016-04-12 23:22:30 -04007629 ret_val = e1000_read_nvm(&adapter->hw,
David Ertman491a04d2014-07-09 16:07:42 +00007630 NVM_INIT_CONTROL3_PORT_B,
7631 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007632 else
Brian Walsh847042a2016-04-12 23:22:30 -04007633 ret_val = e1000_read_nvm(&adapter->hw,
David Ertman491a04d2014-07-09 16:07:42 +00007634 NVM_INIT_CONTROL3_PORT_A,
7635 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007636 }
7637
7638 /* fetch WoL from EEPROM */
Brian Walsh847042a2016-04-12 23:22:30 -04007639 if (ret_val)
7640 e_dbg("NVM read error getting WoL initial values: %d\n", ret_val);
David Ertman491a04d2014-07-09 16:07:42 +00007641 else if (eeprom_data & eeprom_apme_mask)
Auke Kokbc7f75f2007-09-17 12:30:59 -07007642 adapter->eeprom_wol |= E1000_WUFC_MAG;
7643
Bruce Allane921eb12012-11-28 09:28:37 +00007644 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07007645 * where the eeprom may be wrong or the board simply won't support
7646 * wake on lan on a particular port
7647 */
7648 if (!(adapter->flags & FLAG_HAS_WOL))
7649 adapter->eeprom_wol = 0;
7650
7651 /* initialize the wol settings based on the eeprom settings */
7652 adapter->wol = adapter->eeprom_wol;
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00007653
7654 /* make sure adapter isn't asleep if manageability is enabled */
7655 if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
7656 (hw->mac.ops.check_mng_mode(hw)))
7657 device_wakeup_enable(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007658
Bruce Allan84527592008-11-21 17:00:22 -08007659 /* save off EEPROM version number */
Brian Walsh847042a2016-04-12 23:22:30 -04007660 ret_val = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
David Ertman491a04d2014-07-09 16:07:42 +00007661
Brian Walsh847042a2016-04-12 23:22:30 -04007662 if (ret_val) {
7663 e_dbg("NVM read error getting EEPROM version: %d\n", ret_val);
David Ertman491a04d2014-07-09 16:07:42 +00007664 adapter->eeprom_vers = 0;
7665 }
Bruce Allan84527592008-11-21 17:00:22 -08007666
Jacob Kelleraa524b62016-04-20 11:36:42 -07007667 /* init PTP hardware clock */
7668 e1000e_ptp_init(adapter);
7669
Auke Kokbc7f75f2007-09-17 12:30:59 -07007670 /* reset the hardware with the new settings */
7671 e1000e_reset(adapter);
7672
Bruce Allane921eb12012-11-28 09:28:37 +00007673 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07007674 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07007675 * under the control of the driver.
7676 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007677 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00007678 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007679
Mario Limonciello3c98cbf2020-12-14 13:29:35 -06007680 if (hw->mac.type >= e1000_pch_cnp)
7681 adapter->flags2 |= FLAG2_ENABLE_S0IX_FLOWS;
7682
Bruce Allanf2315bf2011-12-16 00:46:59 +00007683 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07007684 err = register_netdev(netdev);
7685 if (err)
7686 goto err_register;
7687
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00007688 /* carrier off reporting is important to ethtool even BEFORE open */
7689 netif_carrier_off(netdev);
7690
Auke Kokbc7f75f2007-09-17 12:30:59 -07007691 e1000_print_device_info(adapter);
7692
Chen Yuccf8b942020-12-01 09:21:50 +08007693 dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_SMART_PREPARE);
Kai-Heng Feng59f58702018-12-11 15:59:37 +08007694
Chen Yu33353692020-12-01 09:22:09 +08007695 if (pci_dev_run_wake(pdev) && hw->mac.type != e1000_pch_cnp)
Alan Sternf3ec4f82010-06-08 15:23:51 -04007696 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007697
Auke Kokbc7f75f2007-09-17 12:30:59 -07007698 return 0;
7699
7700err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007701 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00007702 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007703err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00007704 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07007705 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007706err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07007707 kfree(adapter->tx_ring);
7708 kfree(adapter->rx_ring);
7709err_sw_init:
Yanir Lubetkin1103a632015-02-28 10:10:06 +00007710 if ((adapter->hw.flash_address) && (hw->mac.type < e1000_pch_spt))
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007711 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00007712 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07007713err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07007714 iounmap(adapter->hw.hw_addr);
7715err_ioremap:
7716 free_netdev(netdev);
7717err_alloc_etherdev:
Christophe JAILLET45890752021-06-16 07:05:53 +02007718 pci_disable_pcie_error_reporting(pdev);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02007719 pci_release_mem_regions(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007720err_pci_reg:
7721err_dma:
7722 pci_disable_device(pdev);
7723 return err;
7724}
7725
7726/**
7727 * e1000_remove - Device Removal Routine
7728 * @pdev: PCI device information struct
7729 *
7730 * e1000_remove is called by the PCI subsystem to alert the driver
Tree Daviese0bc64d2021-06-24 05:06:01 -07007731 * that it should release a PCI device. This could be caused by a
Auke Kokbc7f75f2007-09-17 12:30:59 -07007732 * Hot-Plug event, or because the driver is going to be removed from
7733 * memory.
7734 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007735static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07007736{
7737 struct net_device *netdev = pci_get_drvdata(pdev);
7738 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007739
Bruce Alland89777b2013-01-19 01:09:58 +00007740 e1000e_ptp_remove(adapter);
7741
Bruce Allane921eb12012-11-28 09:28:37 +00007742 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01007743 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07007744 */
Alexander Duyckdaee5592019-10-11 08:34:59 -07007745 set_bit(__E1000_DOWN, &adapter->state);
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08007746 del_timer_sync(&adapter->watchdog_timer);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007747 del_timer_sync(&adapter->phy_info_timer);
7748
Bruce Allan41cec6f2009-11-20 23:28:56 +00007749 cancel_work_sync(&adapter->reset_task);
Jeff Kirsherd5ad7a62020-01-04 23:29:22 -08007750 cancel_work_sync(&adapter->watchdog_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00007751 cancel_work_sync(&adapter->downshift_task);
7752 cancel_work_sync(&adapter->update_phy_task);
7753 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007754
Bruce Allanb67e1912012-12-27 08:32:33 +00007755 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
7756 cancel_work_sync(&adapter->tx_hwtstamp_work);
7757 if (adapter->tx_hwtstamp_skb) {
Florian Fainelli377b6272017-08-25 18:14:24 -07007758 dev_consume_skb_any(adapter->tx_hwtstamp_skb);
Bruce Allanb67e1912012-12-27 08:32:33 +00007759 adapter->tx_hwtstamp_skb = NULL;
7760 }
7761 }
7762
Bruce Allan17f208d2009-12-01 15:47:22 +00007763 unregister_netdev(netdev);
7764
Alan Sternf3ec4f82010-06-08 15:23:51 -04007765 if (pci_dev_run_wake(pdev))
7766 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007767
Bruce Allane921eb12012-11-28 09:28:37 +00007768 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07007769 * would have already happened in close and is redundant.
7770 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00007771 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007772
Bruce Allan4662e822008-08-26 18:37:06 -07007773 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007774 kfree(adapter->tx_ring);
7775 kfree(adapter->rx_ring);
7776
7777 iounmap(adapter->hw.hw_addr);
Yanir Lubetkin1103a632015-02-28 10:10:06 +00007778 if ((adapter->hw.flash_address) &&
7779 (adapter->hw.mac.type < e1000_pch_spt))
Auke Kokbc7f75f2007-09-17 12:30:59 -07007780 iounmap(adapter->hw.flash_address);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02007781 pci_release_mem_regions(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007782
7783 free_netdev(netdev);
7784
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007785 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07007786 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007787
Auke Kokbc7f75f2007-09-17 12:30:59 -07007788 pci_disable_device(pdev);
7789}
7790
7791/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007792static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007793 .error_detected = e1000_io_error_detected,
7794 .slot_reset = e1000_io_slot_reset,
7795 .resume = e1000_io_resume,
7796};
7797
David Ertman0e8e8422014-04-08 22:10:31 +00007798static const struct pci_device_id e1000_pci_tbl[] = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007799 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
7800 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
7801 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
Bruce Allanc29c3ba2013-02-20 04:05:50 +00007802 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
7803 board_82571 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007804 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
7805 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07007806 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
7807 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
7808 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07007809
Auke Kokbc7f75f2007-09-17 12:30:59 -07007810 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
7811 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
7812 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
7813 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07007814
Auke Kokbc7f75f2007-09-17 12:30:59 -07007815 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
7816 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
7817 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07007818
Bruce Allan4662e822008-08-26 18:37:06 -07007819 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07007820 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00007821 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07007822
Auke Kokbc7f75f2007-09-17 12:30:59 -07007823 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
7824 board_80003es2lan },
7825 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
7826 board_80003es2lan },
7827 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
7828 board_80003es2lan },
7829 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
7830 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07007831
Auke Kokbc7f75f2007-09-17 12:30:59 -07007832 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
7833 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
7834 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
7835 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
7836 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
7837 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
7838 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00007839 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07007840
Auke Kokbc7f75f2007-09-17 12:30:59 -07007841 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
7842 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
7843 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
7844 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
7845 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07007846 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07007847 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
7848 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
7849 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
7850
7851 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
7852 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
7853 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007854
Bruce Allanf4187b52008-08-26 18:36:50 -07007855 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
7856 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00007857 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07007858
Bruce Allana4f58f52009-06-02 11:29:18 +00007859 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
7860 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
7861 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
7862 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
7863
Bruce Alland3738bb2010-06-16 13:27:28 +00007864 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
7865 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7866
Bruce Allan2fbe4522012-04-19 03:21:47 +00007867 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7868 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00007869 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7870 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan91a3d822013-06-29 01:15:16 +00007871 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
7872 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
7873 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
7874 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
David Ertman79849eb2015-02-10 09:10:43 +00007875 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM), board_pch_spt },
7876 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V), board_pch_spt },
7877 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM2), board_pch_spt },
7878 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V2), board_pch_spt },
Raanan Avargilf3ed9352015-10-20 17:13:01 +03007879 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LBG_I219_LM3), board_pch_spt },
Raanan Avargil9cd34b32015-12-22 15:35:05 +02007880 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM4), board_pch_spt },
7881 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V4), board_pch_spt },
7882 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM5), board_pch_spt },
7883 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V5), board_pch_spt },
Sasha Neftin3a3173b2017-04-06 10:26:32 +03007884 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM6), board_pch_cnp },
7885 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V6), board_pch_cnp },
7886 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM7), board_pch_cnp },
7887 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V7), board_pch_cnp },
Sasha Neftin48f76b682017-07-17 15:13:39 -07007888 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM8), board_pch_cnp },
7889 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V8), board_pch_cnp },
7890 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM9), board_pch_cnp },
7891 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V9), board_pch_cnp },
Sasha Neftin914ee9c2019-10-10 13:15:39 +03007892 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM10), board_pch_cnp },
7893 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V10), board_pch_cnp },
7894 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM11), board_pch_cnp },
7895 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V11), board_pch_cnp },
7896 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM12), board_pch_spt },
7897 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V12), board_pch_spt },
Sasha Neftin280db5d2021-09-22 09:54:49 +03007898 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM13), board_pch_tgp },
7899 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V13), board_pch_tgp },
7900 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM14), board_pch_tgp },
7901 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V14), board_pch_tgp },
7902 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM15), board_pch_tgp },
7903 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V15), board_pch_tgp },
Sasha Neftin68defd52021-12-07 13:23:06 +02007904 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_RPL_I219_LM23), board_pch_adp },
7905 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_RPL_I219_V23), board_pch_adp },
7906 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM16), board_pch_adp },
7907 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V16), board_pch_adp },
7908 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM17), board_pch_adp },
7909 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V17), board_pch_adp },
7910 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_RPL_I219_LM22), board_pch_adp },
7911 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_RPL_I219_V22), board_pch_adp },
7912 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_LM18), board_pch_adp },
7913 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_V18), board_pch_adp },
7914 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_LM19), board_pch_adp },
7915 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_V19), board_pch_adp },
7916 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LNP_I219_LM20), board_pch_adp },
7917 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LNP_I219_V20), board_pch_adp },
7918 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LNP_I219_LM21), board_pch_adp },
7919 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LNP_I219_V21), board_pch_adp },
Bruce Allan2fbe4522012-04-19 03:21:47 +00007920
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007921 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007922};
7923MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7924
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007925static const struct dev_pm_ops e1000_pm_ops = {
Kevin Hao72f72dc2014-03-18 00:26:49 -07007926#ifdef CONFIG_PM_SLEEP
Chen Yuccf8b942020-12-01 09:21:50 +08007927 .prepare = e1000e_pm_prepare,
David Ertman28002092014-02-14 07:16:41 +00007928 .suspend = e1000e_pm_suspend,
7929 .resume = e1000e_pm_resume,
7930 .freeze = e1000e_pm_freeze,
7931 .thaw = e1000e_pm_thaw,
7932 .poweroff = e1000e_pm_suspend,
7933 .restore = e1000e_pm_resume,
Kevin Hao72f72dc2014-03-18 00:26:49 -07007934#endif
David Ertman63eb48f2014-02-14 07:16:46 +00007935 SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
7936 e1000e_pm_runtime_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007937};
7938
Auke Kokbc7f75f2007-09-17 12:30:59 -07007939/* PCI Device API Driver */
7940static struct pci_driver e1000_driver = {
7941 .name = e1000e_driver_name,
7942 .id_table = e1000_pci_tbl,
7943 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007944 .remove = e1000_remove,
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007945 .driver = {
7946 .pm = &e1000_pm_ops,
7947 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007948 .shutdown = e1000_shutdown,
7949 .err_handler = &e1000_err_handler
7950};
7951
7952/**
7953 * e1000_init_module - Driver Registration Routine
7954 *
7955 * e1000_init_module is the first routine called when the driver is
7956 * loaded. All it does is register with the PCI subsystem.
7957 **/
7958static int __init e1000_init_module(void)
7959{
Jeff Kirsher34a2a3b82020-05-29 00:18:33 -07007960 pr_info("Intel(R) PRO/1000 Network Driver\n");
Yanir Lubetkin529498c2015-06-02 17:05:50 +03007961 pr_info("Copyright(c) 1999 - 2015 Intel Corporation.\n");
Bruce Allan53ec5492009-11-20 23:27:40 +00007962
Jean Sacren5a5e8892015-09-19 05:08:42 -06007963 return pci_register_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007964}
7965module_init(e1000_init_module);
7966
7967/**
7968 * e1000_exit_module - Driver Exit Cleanup Routine
7969 *
7970 * e1000_exit_module is called just before the driver is removed
7971 * from memory.
7972 **/
7973static void __exit e1000_exit_module(void)
7974{
7975 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007976}
7977module_exit(e1000_exit_module);
7978
Auke Kokbc7f75f2007-09-17 12:30:59 -07007979MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7980MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
Jesse Brandeburg98674eb2018-09-14 17:37:57 -07007981MODULE_LICENSE("GPL v2");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007982
Bruce Allan06c24b92012-02-23 03:13:13 +00007983/* netdev.c */