1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 #include <linux/module.h>
7 #include <linux/types.h>
8 #include <linux/init.h>
10 #include <linux/vmalloc.h>
11 #include <linux/pagemap.h>
12 #include <linux/delay.h>
13 #include <linux/netdevice.h>
14 #include <linux/interrupt.h>
15 #include <linux/tcp.h>
16 #include <linux/ipv6.h>
17 #include <linux/slab.h>
18 #include <net/checksum.h>
19 #include <net/ip6_checksum.h>
20 #include <linux/ethtool.h>
21 #include <linux/if_vlan.h>
22 #include <linux/cpu.h>
23 #include <linux/smp.h>
24 #include <linux/pm_qos.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/aer.h>
27 #include <linux/prefetch.h>
31 char e1000e_driver_name[] = "e1000e";
33 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
34 static int debug = -1;
35 module_param(debug, int, 0);
36 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
38 static const struct e1000_info *e1000_info_tbl[] = {
39 [board_82571] = &e1000_82571_info,
40 [board_82572] = &e1000_82572_info,
41 [board_82573] = &e1000_82573_info,
42 [board_82574] = &e1000_82574_info,
43 [board_82583] = &e1000_82583_info,
44 [board_80003es2lan] = &e1000_es2_info,
45 [board_ich8lan] = &e1000_ich8_info,
46 [board_ich9lan] = &e1000_ich9_info,
47 [board_ich10lan] = &e1000_ich10_info,
48 [board_pchlan] = &e1000_pch_info,
49 [board_pch2lan] = &e1000_pch2_info,
50 [board_pch_lpt] = &e1000_pch_lpt_info,
51 [board_pch_spt] = &e1000_pch_spt_info,
52 [board_pch_cnp] = &e1000_pch_cnp_info,
55 struct e1000_reg_info {
60 static const struct e1000_reg_info e1000_reg_info_tbl[] = {
61 /* General Registers */
63 {E1000_STATUS, "STATUS"},
64 {E1000_CTRL_EXT, "CTRL_EXT"},
66 /* Interrupt Registers */
71 {E1000_RDLEN(0), "RDLEN"},
72 {E1000_RDH(0), "RDH"},
73 {E1000_RDT(0), "RDT"},
75 {E1000_RXDCTL(0), "RXDCTL"},
77 {E1000_RDBAL(0), "RDBAL"},
78 {E1000_RDBAH(0), "RDBAH"},
81 {E1000_RDFHS, "RDFHS"},
82 {E1000_RDFTS, "RDFTS"},
83 {E1000_RDFPC, "RDFPC"},
87 {E1000_TDBAL(0), "TDBAL"},
88 {E1000_TDBAH(0), "TDBAH"},
89 {E1000_TDLEN(0), "TDLEN"},
90 {E1000_TDH(0), "TDH"},
91 {E1000_TDT(0), "TDT"},
93 {E1000_TXDCTL(0), "TXDCTL"},
95 {E1000_TARC(0), "TARC"},
98 {E1000_TDFHS, "TDFHS"},
99 {E1000_TDFTS, "TDFTS"},
100 {E1000_TDFPC, "TDFPC"},
102 /* List Terminator */
106 struct e1000e_me_supported {
107 u16 device_id; /* supported device ID */
110 static const struct e1000e_me_supported me_supported[] = {
111 {E1000_DEV_ID_PCH_LPT_I217_LM},
112 {E1000_DEV_ID_PCH_LPTLP_I218_LM},
113 {E1000_DEV_ID_PCH_I218_LM2},
114 {E1000_DEV_ID_PCH_I218_LM3},
115 {E1000_DEV_ID_PCH_SPT_I219_LM},
116 {E1000_DEV_ID_PCH_SPT_I219_LM2},
117 {E1000_DEV_ID_PCH_LBG_I219_LM3},
118 {E1000_DEV_ID_PCH_SPT_I219_LM4},
119 {E1000_DEV_ID_PCH_SPT_I219_LM5},
120 {E1000_DEV_ID_PCH_CNP_I219_LM6},
121 {E1000_DEV_ID_PCH_CNP_I219_LM7},
122 {E1000_DEV_ID_PCH_ICP_I219_LM8},
123 {E1000_DEV_ID_PCH_ICP_I219_LM9},
124 {E1000_DEV_ID_PCH_CMP_I219_LM10},
125 {E1000_DEV_ID_PCH_CMP_I219_LM11},
126 {E1000_DEV_ID_PCH_CMP_I219_LM12},
127 {E1000_DEV_ID_PCH_TGP_I219_LM13},
128 {E1000_DEV_ID_PCH_TGP_I219_LM14},
129 {E1000_DEV_ID_PCH_TGP_I219_LM15},
133 static bool e1000e_check_me(u16 device_id)
135 struct e1000e_me_supported *id;
137 for (id = (struct e1000e_me_supported *)me_supported;
139 if (device_id == id->device_id)
146 * __ew32_prepare - prepare to write to MAC CSR register on certain parts
147 * @hw: pointer to the HW structure
149 * When updating the MAC CSR registers, the Manageability Engine (ME) could
150 * be accessing the registers at the same time. Normally, this is handled in
151 * h/w by an arbiter but on some parts there is a bug that acknowledges Host
152 * accesses later than it should which could result in the register to have
153 * an incorrect value. Workaround this by checking the FWSM register which
154 * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set
155 * and try again a number of times.
157 static void __ew32_prepare(struct e1000_hw *hw)
159 s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;
161 while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
165 void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val)
167 if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
170 writel(val, hw->hw_addr + reg);
174 * e1000_regdump - register printout routine
175 * @hw: pointer to the HW structure
176 * @reginfo: pointer to the register info table
178 static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
184 switch (reginfo->ofs) {
185 case E1000_RXDCTL(0):
186 for (n = 0; n < 2; n++)
187 regs[n] = __er32(hw, E1000_RXDCTL(n));
189 case E1000_TXDCTL(0):
190 for (n = 0; n < 2; n++)
191 regs[n] = __er32(hw, E1000_TXDCTL(n));
194 for (n = 0; n < 2; n++)
195 regs[n] = __er32(hw, E1000_TARC(n));
198 pr_info("%-15s %08x\n",
199 reginfo->name, __er32(hw, reginfo->ofs));
203 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
204 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
207 static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
208 struct e1000_buffer *bi)
211 struct e1000_ps_page *ps_page;
213 for (i = 0; i < adapter->rx_ps_pages; i++) {
214 ps_page = &bi->ps_pages[i];
217 pr_info("packet dump for ps_page %d:\n", i);
218 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
219 16, 1, page_address(ps_page->page),
226 * e1000e_dump - Print registers, Tx-ring and Rx-ring
227 * @adapter: board private structure
229 static void e1000e_dump(struct e1000_adapter *adapter)
231 struct net_device *netdev = adapter->netdev;
232 struct e1000_hw *hw = &adapter->hw;
233 struct e1000_reg_info *reginfo;
234 struct e1000_ring *tx_ring = adapter->tx_ring;
235 struct e1000_tx_desc *tx_desc;
240 struct e1000_buffer *buffer_info;
241 struct e1000_ring *rx_ring = adapter->rx_ring;
242 union e1000_rx_desc_packet_split *rx_desc_ps;
243 union e1000_rx_desc_extended *rx_desc;
253 if (!netif_msg_hw(adapter))
256 /* Print netdevice Info */
258 dev_info(&adapter->pdev->dev, "Net device Info\n");
259 pr_info("Device Name state trans_start\n");
260 pr_info("%-15s %016lX %016lX\n", netdev->name,
261 netdev->state, dev_trans_start(netdev));
264 /* Print Registers */
265 dev_info(&adapter->pdev->dev, "Register Dump\n");
266 pr_info(" Register Name Value\n");
267 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
268 reginfo->name; reginfo++) {
269 e1000_regdump(hw, reginfo);
272 /* Print Tx Ring Summary */
273 if (!netdev || !netif_running(netdev))
276 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
277 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
278 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
279 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
280 0, tx_ring->next_to_use, tx_ring->next_to_clean,
281 (unsigned long long)buffer_info->dma,
283 buffer_info->next_to_watch,
284 (unsigned long long)buffer_info->time_stamp);
287 if (!netif_msg_tx_done(adapter))
288 goto rx_ring_summary;
290 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
292 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
294 * Legacy Transmit Descriptor
295 * +--------------------------------------------------------------+
296 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
297 * +--------------------------------------------------------------+
298 * 8 | Special | CSS | Status | CMD | CSO | Length |
299 * +--------------------------------------------------------------+
300 * 63 48 47 36 35 32 31 24 23 16 15 0
302 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
303 * 63 48 47 40 39 32 31 16 15 8 7 0
304 * +----------------------------------------------------------------+
305 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
306 * +----------------------------------------------------------------+
307 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
308 * +----------------------------------------------------------------+
309 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
311 * Extended Data Descriptor (DTYP=0x1)
312 * +----------------------------------------------------------------+
313 * 0 | Buffer Address [63:0] |
314 * +----------------------------------------------------------------+
315 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
316 * +----------------------------------------------------------------+
317 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
319 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
320 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
321 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
322 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
323 const char *next_desc;
324 tx_desc = E1000_TX_DESC(*tx_ring, i);
325 buffer_info = &tx_ring->buffer_info[i];
326 u0 = (struct my_u0 *)tx_desc;
327 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
328 next_desc = " NTC/U";
329 else if (i == tx_ring->next_to_use)
331 else if (i == tx_ring->next_to_clean)
335 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
336 (!(le64_to_cpu(u0->b) & BIT(29)) ? 'l' :
337 ((le64_to_cpu(u0->b) & BIT(20)) ? 'd' : 'c')),
339 (unsigned long long)le64_to_cpu(u0->a),
340 (unsigned long long)le64_to_cpu(u0->b),
341 (unsigned long long)buffer_info->dma,
342 buffer_info->length, buffer_info->next_to_watch,
343 (unsigned long long)buffer_info->time_stamp,
344 buffer_info->skb, next_desc);
346 if (netif_msg_pktdata(adapter) && buffer_info->skb)
347 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
348 16, 1, buffer_info->skb->data,
349 buffer_info->skb->len, true);
352 /* Print Rx Ring Summary */
354 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
355 pr_info("Queue [NTU] [NTC]\n");
356 pr_info(" %5d %5X %5X\n",
357 0, rx_ring->next_to_use, rx_ring->next_to_clean);
360 if (!netif_msg_rx_status(adapter))
363 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
364 switch (adapter->rx_ps_pages) {
368 /* [Extended] Packet Split Receive Descriptor Format
370 * +-----------------------------------------------------+
371 * 0 | Buffer Address 0 [63:0] |
372 * +-----------------------------------------------------+
373 * 8 | Buffer Address 1 [63:0] |
374 * +-----------------------------------------------------+
375 * 16 | Buffer Address 2 [63:0] |
376 * +-----------------------------------------------------+
377 * 24 | Buffer Address 3 [63:0] |
378 * +-----------------------------------------------------+
380 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");
381 /* [Extended] Receive Descriptor (Write-Back) Format
383 * 63 48 47 32 31 13 12 8 7 4 3 0
384 * +------------------------------------------------------+
385 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
386 * | Checksum | Ident | | Queue | | Type |
387 * +------------------------------------------------------+
388 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
389 * +------------------------------------------------------+
390 * 63 48 47 32 31 20 19 0
392 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
393 for (i = 0; i < rx_ring->count; i++) {
394 const char *next_desc;
395 buffer_info = &rx_ring->buffer_info[i];
396 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
397 u1 = (struct my_u1 *)rx_desc_ps;
399 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
401 if (i == rx_ring->next_to_use)
403 else if (i == rx_ring->next_to_clean)
408 if (staterr & E1000_RXD_STAT_DD) {
409 /* Descriptor Done */
410 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
412 (unsigned long long)le64_to_cpu(u1->a),
413 (unsigned long long)le64_to_cpu(u1->b),
414 (unsigned long long)le64_to_cpu(u1->c),
415 (unsigned long long)le64_to_cpu(u1->d),
416 buffer_info->skb, next_desc);
418 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
420 (unsigned long long)le64_to_cpu(u1->a),
421 (unsigned long long)le64_to_cpu(u1->b),
422 (unsigned long long)le64_to_cpu(u1->c),
423 (unsigned long long)le64_to_cpu(u1->d),
424 (unsigned long long)buffer_info->dma,
425 buffer_info->skb, next_desc);
427 if (netif_msg_pktdata(adapter))
428 e1000e_dump_ps_pages(adapter,
435 /* Extended Receive Descriptor (Read) Format
437 * +-----------------------------------------------------+
438 * 0 | Buffer Address [63:0] |
439 * +-----------------------------------------------------+
441 * +-----------------------------------------------------+
443 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
444 /* Extended Receive Descriptor (Write-Back) Format
446 * 63 48 47 32 31 24 23 4 3 0
447 * +------------------------------------------------------+
449 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
450 * | Packet | IP | | | Type |
451 * | Checksum | Ident | | | |
452 * +------------------------------------------------------+
453 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
454 * +------------------------------------------------------+
455 * 63 48 47 32 31 20 19 0
457 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
459 for (i = 0; i < rx_ring->count; i++) {
460 const char *next_desc;
462 buffer_info = &rx_ring->buffer_info[i];
463 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
464 u1 = (struct my_u1 *)rx_desc;
465 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
467 if (i == rx_ring->next_to_use)
469 else if (i == rx_ring->next_to_clean)
474 if (staterr & E1000_RXD_STAT_DD) {
475 /* Descriptor Done */
476 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
478 (unsigned long long)le64_to_cpu(u1->a),
479 (unsigned long long)le64_to_cpu(u1->b),
480 buffer_info->skb, next_desc);
482 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
484 (unsigned long long)le64_to_cpu(u1->a),
485 (unsigned long long)le64_to_cpu(u1->b),
486 (unsigned long long)buffer_info->dma,
487 buffer_info->skb, next_desc);
489 if (netif_msg_pktdata(adapter) &&
491 print_hex_dump(KERN_INFO, "",
492 DUMP_PREFIX_ADDRESS, 16,
494 buffer_info->skb->data,
495 adapter->rx_buffer_len,
503 * e1000_desc_unused - calculate if we have unused descriptors
504 * @ring: pointer to ring struct to perform calculation on
506 static int e1000_desc_unused(struct e1000_ring *ring)
508 if (ring->next_to_clean > ring->next_to_use)
509 return ring->next_to_clean - ring->next_to_use - 1;
511 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
515 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
516 * @adapter: board private structure
517 * @hwtstamps: time stamp structure to update
518 * @systim: unsigned 64bit system time value.
520 * Convert the system time value stored in the RX/TXSTMP registers into a
521 * hwtstamp which can be used by the upper level time stamping functions.
523 * The 'systim_lock' spinlock is used to protect the consistency of the
524 * system time value. This is needed because reading the 64 bit time
525 * value involves reading two 32 bit registers. The first read latches the
528 static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
529 struct skb_shared_hwtstamps *hwtstamps,
535 spin_lock_irqsave(&adapter->systim_lock, flags);
536 ns = timecounter_cyc2time(&adapter->tc, systim);
537 spin_unlock_irqrestore(&adapter->systim_lock, flags);
539 memset(hwtstamps, 0, sizeof(*hwtstamps));
540 hwtstamps->hwtstamp = ns_to_ktime(ns);
544 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
545 * @adapter: board private structure
546 * @status: descriptor extended error and status field
547 * @skb: particular skb to include time stamp
549 * If the time stamp is valid, convert it into the timecounter ns value
550 * and store that result into the shhwtstamps structure which is passed
551 * up the network stack.
553 static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
556 struct e1000_hw *hw = &adapter->hw;
559 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
560 !(status & E1000_RXDEXT_STATERR_TST) ||
561 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
564 /* The Rx time stamp registers contain the time stamp. No other
565 * received packet will be time stamped until the Rx time stamp
566 * registers are read. Because only one packet can be time stamped
567 * at a time, the register values must belong to this packet and
568 * therefore none of the other additional attributes need to be
571 rxstmp = (u64)er32(RXSTMPL);
572 rxstmp |= (u64)er32(RXSTMPH) << 32;
573 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
575 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
579 * e1000_receive_skb - helper function to handle Rx indications
580 * @adapter: board private structure
581 * @netdev: pointer to netdev struct
582 * @staterr: descriptor extended error and status field as written by hardware
583 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
584 * @skb: pointer to sk_buff to be indicated to stack
586 static void e1000_receive_skb(struct e1000_adapter *adapter,
587 struct net_device *netdev, struct sk_buff *skb,
588 u32 staterr, __le16 vlan)
590 u16 tag = le16_to_cpu(vlan);
592 e1000e_rx_hwtstamp(adapter, staterr, skb);
594 skb->protocol = eth_type_trans(skb, netdev);
596 if (staterr & E1000_RXD_STAT_VP)
597 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
599 napi_gro_receive(&adapter->napi, skb);
603 * e1000_rx_checksum - Receive Checksum Offload
604 * @adapter: board private structure
605 * @status_err: receive descriptor status and error fields
606 * @skb: socket buffer with received data
608 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
611 u16 status = (u16)status_err;
612 u8 errors = (u8)(status_err >> 24);
614 skb_checksum_none_assert(skb);
616 /* Rx checksum disabled */
617 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
620 /* Ignore Checksum bit is set */
621 if (status & E1000_RXD_STAT_IXSM)
624 /* TCP/UDP checksum error bit or IP checksum error bit is set */
625 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
626 /* let the stack verify checksum errors */
627 adapter->hw_csum_err++;
631 /* TCP/UDP Checksum has not been calculated */
632 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
635 /* It must be a TCP or UDP packet with a valid checksum */
636 skb->ip_summed = CHECKSUM_UNNECESSARY;
637 adapter->hw_csum_good++;
640 static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
642 struct e1000_adapter *adapter = rx_ring->adapter;
643 struct e1000_hw *hw = &adapter->hw;
646 writel(i, rx_ring->tail);
648 if (unlikely(i != readl(rx_ring->tail))) {
649 u32 rctl = er32(RCTL);
651 ew32(RCTL, rctl & ~E1000_RCTL_EN);
652 e_err("ME firmware caused invalid RDT - resetting\n");
653 schedule_work(&adapter->reset_task);
657 static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
659 struct e1000_adapter *adapter = tx_ring->adapter;
660 struct e1000_hw *hw = &adapter->hw;
663 writel(i, tx_ring->tail);
665 if (unlikely(i != readl(tx_ring->tail))) {
666 u32 tctl = er32(TCTL);
668 ew32(TCTL, tctl & ~E1000_TCTL_EN);
669 e_err("ME firmware caused invalid TDT - resetting\n");
670 schedule_work(&adapter->reset_task);
675 * e1000_alloc_rx_buffers - Replace used receive buffers
676 * @rx_ring: Rx descriptor ring
677 * @cleaned_count: number to reallocate
678 * @gfp: flags for allocation
680 static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
681 int cleaned_count, gfp_t gfp)
683 struct e1000_adapter *adapter = rx_ring->adapter;
684 struct net_device *netdev = adapter->netdev;
685 struct pci_dev *pdev = adapter->pdev;
686 union e1000_rx_desc_extended *rx_desc;
687 struct e1000_buffer *buffer_info;
690 unsigned int bufsz = adapter->rx_buffer_len;
692 i = rx_ring->next_to_use;
693 buffer_info = &rx_ring->buffer_info[i];
695 while (cleaned_count--) {
696 skb = buffer_info->skb;
702 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
704 /* Better luck next round */
705 adapter->alloc_rx_buff_failed++;
709 buffer_info->skb = skb;
711 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
712 adapter->rx_buffer_len,
714 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
715 dev_err(&pdev->dev, "Rx DMA map failed\n");
716 adapter->rx_dma_failed++;
720 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
721 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
723 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
724 /* Force memory writes to complete before letting h/w
725 * know there are new descriptors to fetch. (Only
726 * applicable for weak-ordered memory model archs,
730 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
731 e1000e_update_rdt_wa(rx_ring, i);
733 writel(i, rx_ring->tail);
736 if (i == rx_ring->count)
738 buffer_info = &rx_ring->buffer_info[i];
741 rx_ring->next_to_use = i;
745 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
746 * @rx_ring: Rx descriptor ring
747 * @cleaned_count: number to reallocate
748 * @gfp: flags for allocation
750 static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
751 int cleaned_count, gfp_t gfp)
753 struct e1000_adapter *adapter = rx_ring->adapter;
754 struct net_device *netdev = adapter->netdev;
755 struct pci_dev *pdev = adapter->pdev;
756 union e1000_rx_desc_packet_split *rx_desc;
757 struct e1000_buffer *buffer_info;
758 struct e1000_ps_page *ps_page;
762 i = rx_ring->next_to_use;
763 buffer_info = &rx_ring->buffer_info[i];
765 while (cleaned_count--) {
766 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
768 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
769 ps_page = &buffer_info->ps_pages[j];
770 if (j >= adapter->rx_ps_pages) {
771 /* all unused desc entries get hw null ptr */
772 rx_desc->read.buffer_addr[j + 1] =
776 if (!ps_page->page) {
777 ps_page->page = alloc_page(gfp);
778 if (!ps_page->page) {
779 adapter->alloc_rx_buff_failed++;
782 ps_page->dma = dma_map_page(&pdev->dev,
786 if (dma_mapping_error(&pdev->dev,
788 dev_err(&adapter->pdev->dev,
789 "Rx DMA page map failed\n");
790 adapter->rx_dma_failed++;
794 /* Refresh the desc even if buffer_addrs
795 * didn't change because each write-back
798 rx_desc->read.buffer_addr[j + 1] =
799 cpu_to_le64(ps_page->dma);
802 skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
806 adapter->alloc_rx_buff_failed++;
810 buffer_info->skb = skb;
811 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
812 adapter->rx_ps_bsize0,
814 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
815 dev_err(&pdev->dev, "Rx DMA map failed\n");
816 adapter->rx_dma_failed++;
818 dev_kfree_skb_any(skb);
819 buffer_info->skb = NULL;
823 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
825 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
826 /* Force memory writes to complete before letting h/w
827 * know there are new descriptors to fetch. (Only
828 * applicable for weak-ordered memory model archs,
832 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
833 e1000e_update_rdt_wa(rx_ring, i << 1);
835 writel(i << 1, rx_ring->tail);
839 if (i == rx_ring->count)
841 buffer_info = &rx_ring->buffer_info[i];
845 rx_ring->next_to_use = i;
849 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
850 * @rx_ring: Rx descriptor ring
851 * @cleaned_count: number of buffers to allocate this pass
852 * @gfp: flags for allocation
855 static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
856 int cleaned_count, gfp_t gfp)
858 struct e1000_adapter *adapter = rx_ring->adapter;
859 struct net_device *netdev = adapter->netdev;
860 struct pci_dev *pdev = adapter->pdev;
861 union e1000_rx_desc_extended *rx_desc;
862 struct e1000_buffer *buffer_info;
865 unsigned int bufsz = 256 - 16; /* for skb_reserve */
867 i = rx_ring->next_to_use;
868 buffer_info = &rx_ring->buffer_info[i];
870 while (cleaned_count--) {
871 skb = buffer_info->skb;
877 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
878 if (unlikely(!skb)) {
879 /* Better luck next round */
880 adapter->alloc_rx_buff_failed++;
884 buffer_info->skb = skb;
886 /* allocate a new page if necessary */
887 if (!buffer_info->page) {
888 buffer_info->page = alloc_page(gfp);
889 if (unlikely(!buffer_info->page)) {
890 adapter->alloc_rx_buff_failed++;
895 if (!buffer_info->dma) {
896 buffer_info->dma = dma_map_page(&pdev->dev,
897 buffer_info->page, 0,
900 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
901 adapter->alloc_rx_buff_failed++;
906 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
907 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
909 if (unlikely(++i == rx_ring->count))
911 buffer_info = &rx_ring->buffer_info[i];
914 if (likely(rx_ring->next_to_use != i)) {
915 rx_ring->next_to_use = i;
916 if (unlikely(i-- == 0))
917 i = (rx_ring->count - 1);
919 /* Force memory writes to complete before letting h/w
920 * know there are new descriptors to fetch. (Only
921 * applicable for weak-ordered memory model archs,
925 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
926 e1000e_update_rdt_wa(rx_ring, i);
928 writel(i, rx_ring->tail);
932 static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
935 if (netdev->features & NETIF_F_RXHASH)
936 skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3);
940 * e1000_clean_rx_irq - Send received data up the network stack
941 * @rx_ring: Rx descriptor ring
942 * @work_done: output parameter for indicating completed work
943 * @work_to_do: how many packets we can clean
945 * the return value indicates whether actual cleaning was done, there
946 * is no guarantee that everything was cleaned
948 static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
951 struct e1000_adapter *adapter = rx_ring->adapter;
952 struct net_device *netdev = adapter->netdev;
953 struct pci_dev *pdev = adapter->pdev;
954 struct e1000_hw *hw = &adapter->hw;
955 union e1000_rx_desc_extended *rx_desc, *next_rxd;
956 struct e1000_buffer *buffer_info, *next_buffer;
959 int cleaned_count = 0;
960 bool cleaned = false;
961 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
963 i = rx_ring->next_to_clean;
964 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
965 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
966 buffer_info = &rx_ring->buffer_info[i];
968 while (staterr & E1000_RXD_STAT_DD) {
971 if (*work_done >= work_to_do)
974 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
976 skb = buffer_info->skb;
977 buffer_info->skb = NULL;
979 prefetch(skb->data - NET_IP_ALIGN);
982 if (i == rx_ring->count)
984 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
987 next_buffer = &rx_ring->buffer_info[i];
991 dma_unmap_single(&pdev->dev, buffer_info->dma,
992 adapter->rx_buffer_len, DMA_FROM_DEVICE);
993 buffer_info->dma = 0;
995 length = le16_to_cpu(rx_desc->wb.upper.length);
997 /* !EOP means multiple descriptors were used to store a single
998 * packet, if that's the case we need to toss it. In fact, we
999 * need to toss every packet with the EOP bit clear and the
1000 * next frame that _does_ have the EOP bit set, as it is by
1001 * definition only a frame fragment
1003 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
1004 adapter->flags2 |= FLAG2_IS_DISCARDING;
1006 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
1007 /* All receives must fit into a single buffer */
1008 e_dbg("Receive packet consumed multiple buffers\n");
1010 buffer_info->skb = skb;
1011 if (staterr & E1000_RXD_STAT_EOP)
1012 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1016 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1017 !(netdev->features & NETIF_F_RXALL))) {
1019 buffer_info->skb = skb;
1023 /* adjust length to remove Ethernet CRC */
1024 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1025 /* If configured to store CRC, don't subtract FCS,
1026 * but keep the FCS bytes out of the total_rx_bytes
1029 if (netdev->features & NETIF_F_RXFCS)
1030 total_rx_bytes -= 4;
1035 total_rx_bytes += length;
1038 /* code added for copybreak, this should improve
1039 * performance for small packets with large amounts
1040 * of reassembly being done in the stack
1042 if (length < copybreak) {
1043 struct sk_buff *new_skb =
1044 napi_alloc_skb(&adapter->napi, length);
1046 skb_copy_to_linear_data_offset(new_skb,
1052 /* save the skb in buffer_info as good */
1053 buffer_info->skb = skb;
1056 /* else just continue with the old one */
1058 /* end copybreak code */
1059 skb_put(skb, length);
1061 /* Receive Checksum Offload */
1062 e1000_rx_checksum(adapter, staterr, skb);
1064 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1066 e1000_receive_skb(adapter, netdev, skb, staterr,
1067 rx_desc->wb.upper.vlan);
1070 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
1072 /* return some buffers to hardware, one at a time is too slow */
1073 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1074 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1079 /* use prefetched values */
1081 buffer_info = next_buffer;
1083 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1085 rx_ring->next_to_clean = i;
1087 cleaned_count = e1000_desc_unused(rx_ring);
1089 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1091 adapter->total_rx_bytes += total_rx_bytes;
1092 adapter->total_rx_packets += total_rx_packets;
1096 static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1097 struct e1000_buffer *buffer_info,
1100 struct e1000_adapter *adapter = tx_ring->adapter;
1102 if (buffer_info->dma) {
1103 if (buffer_info->mapped_as_page)
1104 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1105 buffer_info->length, DMA_TO_DEVICE);
1107 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1108 buffer_info->length, DMA_TO_DEVICE);
1109 buffer_info->dma = 0;
1111 if (buffer_info->skb) {
1113 dev_kfree_skb_any(buffer_info->skb);
1115 dev_consume_skb_any(buffer_info->skb);
1116 buffer_info->skb = NULL;
1118 buffer_info->time_stamp = 0;
1121 static void e1000_print_hw_hang(struct work_struct *work)
1123 struct e1000_adapter *adapter = container_of(work,
1124 struct e1000_adapter,
1126 struct net_device *netdev = adapter->netdev;
1127 struct e1000_ring *tx_ring = adapter->tx_ring;
1128 unsigned int i = tx_ring->next_to_clean;
1129 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1130 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
1131 struct e1000_hw *hw = &adapter->hw;
1132 u16 phy_status, phy_1000t_status, phy_ext_status;
1135 if (test_bit(__E1000_DOWN, &adapter->state))
1138 if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
1139 /* May be block on write-back, flush and detect again
1140 * flush pending descriptor writebacks to memory
1142 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1143 /* execute the writes immediately */
1145 /* Due to rare timing issues, write to TIDV again to ensure
1146 * the write is successful
1148 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1149 /* execute the writes immediately */
1151 adapter->tx_hang_recheck = true;
1154 adapter->tx_hang_recheck = false;
1156 if (er32(TDH(0)) == er32(TDT(0))) {
1157 e_dbg("false hang detected, ignoring\n");
1161 /* Real hang detected */
1162 netif_stop_queue(netdev);
1164 e1e_rphy(hw, MII_BMSR, &phy_status);
1165 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1166 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
1168 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1170 /* detected Hardware unit hang */
1171 e_err("Detected Hardware Unit Hang:\n"
1174 " next_to_use <%x>\n"
1175 " next_to_clean <%x>\n"
1176 "buffer_info[next_to_clean]:\n"
1177 " time_stamp <%lx>\n"
1178 " next_to_watch <%x>\n"
1180 " next_to_watch.status <%x>\n"
1183 "PHY 1000BASE-T Status <%x>\n"
1184 "PHY Extended Status <%x>\n"
1185 "PCI Status <%x>\n",
1186 readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
1187 tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
1188 eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
1189 phy_status, phy_1000t_status, phy_ext_status, pci_status);
1191 e1000e_dump(adapter);
1193 /* Suggest workaround for known h/w issue */
1194 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1195 e_err("Try turning off Tx pause (flow control) via ethtool\n");
1199 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1200 * @work: pointer to work struct
1202 * This work function polls the TSYNCTXCTL valid bit to determine when a
1203 * timestamp has been taken for the current stored skb. The timestamp must
1204 * be for this skb because only one such packet is allowed in the queue.
1206 static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1208 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1210 struct e1000_hw *hw = &adapter->hw;
1212 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
1213 struct sk_buff *skb = adapter->tx_hwtstamp_skb;
1214 struct skb_shared_hwtstamps shhwtstamps;
1217 txstmp = er32(TXSTMPL);
1218 txstmp |= (u64)er32(TXSTMPH) << 32;
1220 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1222 /* Clear the global tx_hwtstamp_skb pointer and force writes
1223 * prior to notifying the stack of a Tx timestamp.
1225 adapter->tx_hwtstamp_skb = NULL;
1226 wmb(); /* force write prior to skb_tstamp_tx */
1228 skb_tstamp_tx(skb, &shhwtstamps);
1229 dev_consume_skb_any(skb);
1230 } else if (time_after(jiffies, adapter->tx_hwtstamp_start
1231 + adapter->tx_timeout_factor * HZ)) {
1232 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1233 adapter->tx_hwtstamp_skb = NULL;
1234 adapter->tx_hwtstamp_timeouts++;
1235 e_warn("clearing Tx timestamp hang\n");
1237 /* reschedule to check later */
1238 schedule_work(&adapter->tx_hwtstamp_work);
1243 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1244 * @tx_ring: Tx descriptor ring
1246 * the return value indicates whether actual cleaning was done, there
1247 * is no guarantee that everything was cleaned
1249 static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
1251 struct e1000_adapter *adapter = tx_ring->adapter;
1252 struct net_device *netdev = adapter->netdev;
1253 struct e1000_hw *hw = &adapter->hw;
1254 struct e1000_tx_desc *tx_desc, *eop_desc;
1255 struct e1000_buffer *buffer_info;
1256 unsigned int i, eop;
1257 unsigned int count = 0;
1258 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1259 unsigned int bytes_compl = 0, pkts_compl = 0;
1261 i = tx_ring->next_to_clean;
1262 eop = tx_ring->buffer_info[i].next_to_watch;
1263 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1265 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1266 (count < tx_ring->count)) {
1267 bool cleaned = false;
1269 dma_rmb(); /* read buffer_info after eop_desc */
1270 for (; !cleaned; count++) {
1271 tx_desc = E1000_TX_DESC(*tx_ring, i);
1272 buffer_info = &tx_ring->buffer_info[i];
1273 cleaned = (i == eop);
1276 total_tx_packets += buffer_info->segs;
1277 total_tx_bytes += buffer_info->bytecount;
1278 if (buffer_info->skb) {
1279 bytes_compl += buffer_info->skb->len;
1284 e1000_put_txbuf(tx_ring, buffer_info, false);
1285 tx_desc->upper.data = 0;
1288 if (i == tx_ring->count)
1292 if (i == tx_ring->next_to_use)
1294 eop = tx_ring->buffer_info[i].next_to_watch;
1295 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1298 tx_ring->next_to_clean = i;
1300 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1302 #define TX_WAKE_THRESHOLD 32
1303 if (count && netif_carrier_ok(netdev) &&
1304 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
1305 /* Make sure that anybody stopping the queue after this
1306 * sees the new next_to_clean.
1310 if (netif_queue_stopped(netdev) &&
1311 !(test_bit(__E1000_DOWN, &adapter->state))) {
1312 netif_wake_queue(netdev);
1313 ++adapter->restart_queue;
1317 if (adapter->detect_tx_hung) {
1318 /* Detect a transmit hang in hardware, this serializes the
1319 * check with the clearing of time_stamp and movement of i
1321 adapter->detect_tx_hung = false;
1322 if (tx_ring->buffer_info[i].time_stamp &&
1323 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
1324 + (adapter->tx_timeout_factor * HZ)) &&
1325 !(er32(STATUS) & E1000_STATUS_TXOFF))
1326 schedule_work(&adapter->print_hang_task);
1328 adapter->tx_hang_recheck = false;
1330 adapter->total_tx_bytes += total_tx_bytes;
1331 adapter->total_tx_packets += total_tx_packets;
1332 return count < tx_ring->count;
1336 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1337 * @rx_ring: Rx descriptor ring
1338 * @work_done: output parameter for indicating completed work
1339 * @work_to_do: how many packets we can clean
1341 * the return value indicates whether actual cleaning was done, there
1342 * is no guarantee that everything was cleaned
1344 static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1347 struct e1000_adapter *adapter = rx_ring->adapter;
1348 struct e1000_hw *hw = &adapter->hw;
1349 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1350 struct net_device *netdev = adapter->netdev;
1351 struct pci_dev *pdev = adapter->pdev;
1352 struct e1000_buffer *buffer_info, *next_buffer;
1353 struct e1000_ps_page *ps_page;
1354 struct sk_buff *skb;
1356 u32 length, staterr;
1357 int cleaned_count = 0;
1358 bool cleaned = false;
1359 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1361 i = rx_ring->next_to_clean;
1362 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1363 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1364 buffer_info = &rx_ring->buffer_info[i];
1366 while (staterr & E1000_RXD_STAT_DD) {
1367 if (*work_done >= work_to_do)
1370 skb = buffer_info->skb;
1371 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
1373 /* in the packet split case this is header only */
1374 prefetch(skb->data - NET_IP_ALIGN);
1377 if (i == rx_ring->count)
1379 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1382 next_buffer = &rx_ring->buffer_info[i];
1386 dma_unmap_single(&pdev->dev, buffer_info->dma,
1387 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
1388 buffer_info->dma = 0;
1390 /* see !EOP comment in other Rx routine */
1391 if (!(staterr & E1000_RXD_STAT_EOP))
1392 adapter->flags2 |= FLAG2_IS_DISCARDING;
1394 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
1395 e_dbg("Packet Split buffers didn't pick up the full packet\n");
1396 dev_kfree_skb_irq(skb);
1397 if (staterr & E1000_RXD_STAT_EOP)
1398 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1402 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1403 !(netdev->features & NETIF_F_RXALL))) {
1404 dev_kfree_skb_irq(skb);
1408 length = le16_to_cpu(rx_desc->wb.middle.length0);
1411 e_dbg("Last part of the packet spanning multiple descriptors\n");
1412 dev_kfree_skb_irq(skb);
1417 skb_put(skb, length);
1420 /* this looks ugly, but it seems compiler issues make
1421 * it more efficient than reusing j
1423 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1425 /* page alloc/put takes too long and effects small
1426 * packet throughput, so unsplit small packets and
1427 * save the alloc/put only valid in softirq (napi)
1428 * context to call kmap_*
1430 if (l1 && (l1 <= copybreak) &&
1431 ((length + l1) <= adapter->rx_ps_bsize0)) {
1434 ps_page = &buffer_info->ps_pages[0];
1436 /* there is no documentation about how to call
1437 * kmap_atomic, so we can't hold the mapping
1440 dma_sync_single_for_cpu(&pdev->dev,
1444 vaddr = kmap_atomic(ps_page->page);
1445 memcpy(skb_tail_pointer(skb), vaddr, l1);
1446 kunmap_atomic(vaddr);
1447 dma_sync_single_for_device(&pdev->dev,
1452 /* remove the CRC */
1453 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1454 if (!(netdev->features & NETIF_F_RXFCS))
1463 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1464 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1468 ps_page = &buffer_info->ps_pages[j];
1469 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1472 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1473 ps_page->page = NULL;
1475 skb->data_len += length;
1476 skb->truesize += PAGE_SIZE;
1479 /* strip the ethernet crc, problem is we're using pages now so
1480 * this whole operation can get a little cpu intensive
1482 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1483 if (!(netdev->features & NETIF_F_RXFCS))
1484 pskb_trim(skb, skb->len - 4);
1488 total_rx_bytes += skb->len;
1491 e1000_rx_checksum(adapter, staterr, skb);
1493 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1495 if (rx_desc->wb.upper.header_status &
1496 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1497 adapter->rx_hdr_split++;
1499 e1000_receive_skb(adapter, netdev, skb, staterr,
1500 rx_desc->wb.middle.vlan);
1503 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1504 buffer_info->skb = NULL;
1506 /* return some buffers to hardware, one at a time is too slow */
1507 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1508 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1513 /* use prefetched values */
1515 buffer_info = next_buffer;
1517 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1519 rx_ring->next_to_clean = i;
1521 cleaned_count = e1000_desc_unused(rx_ring);
1523 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1525 adapter->total_rx_bytes += total_rx_bytes;
1526 adapter->total_rx_packets += total_rx_packets;
1530 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1535 skb->data_len += length;
1536 skb->truesize += PAGE_SIZE;
1540 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1541 * @rx_ring: Rx descriptor ring
1542 * @work_done: output parameter for indicating completed work
1543 * @work_to_do: how many packets we can clean
1545 * the return value indicates whether actual cleaning was done, there
1546 * is no guarantee that everything was cleaned
1548 static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1551 struct e1000_adapter *adapter = rx_ring->adapter;
1552 struct net_device *netdev = adapter->netdev;
1553 struct pci_dev *pdev = adapter->pdev;
1554 union e1000_rx_desc_extended *rx_desc, *next_rxd;
1555 struct e1000_buffer *buffer_info, *next_buffer;
1556 u32 length, staterr;
1558 int cleaned_count = 0;
1559 bool cleaned = false;
1560 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1561 struct skb_shared_info *shinfo;
1563 i = rx_ring->next_to_clean;
1564 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1565 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1566 buffer_info = &rx_ring->buffer_info[i];
1568 while (staterr & E1000_RXD_STAT_DD) {
1569 struct sk_buff *skb;
1571 if (*work_done >= work_to_do)
1574 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
1576 skb = buffer_info->skb;
1577 buffer_info->skb = NULL;
1580 if (i == rx_ring->count)
1582 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
1585 next_buffer = &rx_ring->buffer_info[i];
1589 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1591 buffer_info->dma = 0;
1593 length = le16_to_cpu(rx_desc->wb.upper.length);
1595 /* errors is only valid for DD + EOP descriptors */
1596 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1597 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1598 !(netdev->features & NETIF_F_RXALL)))) {
1599 /* recycle both page and skb */
1600 buffer_info->skb = skb;
1601 /* an error means any chain goes out the window too */
1602 if (rx_ring->rx_skb_top)
1603 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1604 rx_ring->rx_skb_top = NULL;
1607 #define rxtop (rx_ring->rx_skb_top)
1608 if (!(staterr & E1000_RXD_STAT_EOP)) {
1609 /* this descriptor is only the beginning (or middle) */
1611 /* this is the beginning of a chain */
1613 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1616 /* this is the middle of a chain */
1617 shinfo = skb_shinfo(rxtop);
1618 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1619 buffer_info->page, 0,
1621 /* re-use the skb, only consumed the page */
1622 buffer_info->skb = skb;
1624 e1000_consume_page(buffer_info, rxtop, length);
1628 /* end of the chain */
1629 shinfo = skb_shinfo(rxtop);
1630 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1631 buffer_info->page, 0,
1633 /* re-use the current skb, we only consumed the
1636 buffer_info->skb = skb;
1639 e1000_consume_page(buffer_info, skb, length);
1641 /* no chain, got EOP, this buf is the packet
1642 * copybreak to save the put_page/alloc_page
1644 if (length <= copybreak &&
1645 skb_tailroom(skb) >= length) {
1647 vaddr = kmap_atomic(buffer_info->page);
1648 memcpy(skb_tail_pointer(skb), vaddr,
1650 kunmap_atomic(vaddr);
1651 /* re-use the page, so don't erase
1654 skb_put(skb, length);
1656 skb_fill_page_desc(skb, 0,
1657 buffer_info->page, 0,
1659 e1000_consume_page(buffer_info, skb,
1665 /* Receive Checksum Offload */
1666 e1000_rx_checksum(adapter, staterr, skb);
1668 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1670 /* probably a little skewed due to removing CRC */
1671 total_rx_bytes += skb->len;
1674 /* eth type trans needs skb->data to point to something */
1675 if (!pskb_may_pull(skb, ETH_HLEN)) {
1676 e_err("pskb_may_pull failed.\n");
1677 dev_kfree_skb_irq(skb);
1681 e1000_receive_skb(adapter, netdev, skb, staterr,
1682 rx_desc->wb.upper.vlan);
1685 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
1687 /* return some buffers to hardware, one at a time is too slow */
1688 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1689 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1694 /* use prefetched values */
1696 buffer_info = next_buffer;
1698 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1700 rx_ring->next_to_clean = i;
1702 cleaned_count = e1000_desc_unused(rx_ring);
1704 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1706 adapter->total_rx_bytes += total_rx_bytes;
1707 adapter->total_rx_packets += total_rx_packets;
1712 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1713 * @rx_ring: Rx descriptor ring
1715 static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
1717 struct e1000_adapter *adapter = rx_ring->adapter;
1718 struct e1000_buffer *buffer_info;
1719 struct e1000_ps_page *ps_page;
1720 struct pci_dev *pdev = adapter->pdev;
1723 /* Free all the Rx ring sk_buffs */
1724 for (i = 0; i < rx_ring->count; i++) {
1725 buffer_info = &rx_ring->buffer_info[i];
1726 if (buffer_info->dma) {
1727 if (adapter->clean_rx == e1000_clean_rx_irq)
1728 dma_unmap_single(&pdev->dev, buffer_info->dma,
1729 adapter->rx_buffer_len,
1731 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1732 dma_unmap_page(&pdev->dev, buffer_info->dma,
1733 PAGE_SIZE, DMA_FROM_DEVICE);
1734 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1735 dma_unmap_single(&pdev->dev, buffer_info->dma,
1736 adapter->rx_ps_bsize0,
1738 buffer_info->dma = 0;
1741 if (buffer_info->page) {
1742 put_page(buffer_info->page);
1743 buffer_info->page = NULL;
1746 if (buffer_info->skb) {
1747 dev_kfree_skb(buffer_info->skb);
1748 buffer_info->skb = NULL;
1751 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1752 ps_page = &buffer_info->ps_pages[j];
1755 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1758 put_page(ps_page->page);
1759 ps_page->page = NULL;
1763 /* there also may be some cached data from a chained receive */
1764 if (rx_ring->rx_skb_top) {
1765 dev_kfree_skb(rx_ring->rx_skb_top);
1766 rx_ring->rx_skb_top = NULL;
1769 /* Zero out the descriptor ring */
1770 memset(rx_ring->desc, 0, rx_ring->size);
1772 rx_ring->next_to_clean = 0;
1773 rx_ring->next_to_use = 0;
1774 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1777 static void e1000e_downshift_workaround(struct work_struct *work)
1779 struct e1000_adapter *adapter = container_of(work,
1780 struct e1000_adapter,
1783 if (test_bit(__E1000_DOWN, &adapter->state))
1786 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1790 * e1000_intr_msi - Interrupt Handler
1791 * @irq: interrupt number
1792 * @data: pointer to a network interface device structure
1794 static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
1796 struct net_device *netdev = data;
1797 struct e1000_adapter *adapter = netdev_priv(netdev);
1798 struct e1000_hw *hw = &adapter->hw;
1799 u32 icr = er32(ICR);
1801 /* read ICR disables interrupts using IAM */
1802 if (icr & E1000_ICR_LSC) {
1803 hw->mac.get_link_status = true;
1804 /* ICH8 workaround-- Call gig speed drop workaround on cable
1805 * disconnect (LSC) before accessing any PHY registers
1807 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1808 (!(er32(STATUS) & E1000_STATUS_LU)))
1809 schedule_work(&adapter->downshift_task);
1811 /* 80003ES2LAN workaround-- For packet buffer work-around on
1812 * link down event; disable receives here in the ISR and reset
1813 * adapter in watchdog
1815 if (netif_carrier_ok(netdev) &&
1816 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1817 /* disable receives */
1818 u32 rctl = er32(RCTL);
1820 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1821 adapter->flags |= FLAG_RESTART_NOW;
1823 /* guard against interrupt when we're going down */
1824 if (!test_bit(__E1000_DOWN, &adapter->state))
1825 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1828 /* Reset on uncorrectable ECC error */
1829 if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
1830 u32 pbeccsts = er32(PBECCSTS);
1832 adapter->corr_errors +=
1833 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1834 adapter->uncorr_errors +=
1835 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1836 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1838 /* Do the reset outside of interrupt context */
1839 schedule_work(&adapter->reset_task);
1841 /* return immediately since reset is imminent */
1845 if (napi_schedule_prep(&adapter->napi)) {
1846 adapter->total_tx_bytes = 0;
1847 adapter->total_tx_packets = 0;
1848 adapter->total_rx_bytes = 0;
1849 adapter->total_rx_packets = 0;
1850 __napi_schedule(&adapter->napi);
1857 * e1000_intr - Interrupt Handler
1858 * @irq: interrupt number
1859 * @data: pointer to a network interface device structure
1861 static irqreturn_t e1000_intr(int __always_unused irq, void *data)
1863 struct net_device *netdev = data;
1864 struct e1000_adapter *adapter = netdev_priv(netdev);
1865 struct e1000_hw *hw = &adapter->hw;
1866 u32 rctl, icr = er32(ICR);
1868 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
1869 return IRQ_NONE; /* Not our interrupt */
1871 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1872 * not set, then the adapter didn't send an interrupt
1874 if (!(icr & E1000_ICR_INT_ASSERTED))
1877 /* Interrupt Auto-Mask...upon reading ICR,
1878 * interrupts are masked. No need for the
1882 if (icr & E1000_ICR_LSC) {
1883 hw->mac.get_link_status = true;
1884 /* ICH8 workaround-- Call gig speed drop workaround on cable
1885 * disconnect (LSC) before accessing any PHY registers
1887 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1888 (!(er32(STATUS) & E1000_STATUS_LU)))
1889 schedule_work(&adapter->downshift_task);
1891 /* 80003ES2LAN workaround--
1892 * For packet buffer work-around on link down event;
1893 * disable receives here in the ISR and
1894 * reset adapter in watchdog
1896 if (netif_carrier_ok(netdev) &&
1897 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1898 /* disable receives */
1900 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1901 adapter->flags |= FLAG_RESTART_NOW;
1903 /* guard against interrupt when we're going down */
1904 if (!test_bit(__E1000_DOWN, &adapter->state))
1905 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1908 /* Reset on uncorrectable ECC error */
1909 if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
1910 u32 pbeccsts = er32(PBECCSTS);
1912 adapter->corr_errors +=
1913 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1914 adapter->uncorr_errors +=
1915 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1916 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1918 /* Do the reset outside of interrupt context */
1919 schedule_work(&adapter->reset_task);
1921 /* return immediately since reset is imminent */
1925 if (napi_schedule_prep(&adapter->napi)) {
1926 adapter->total_tx_bytes = 0;
1927 adapter->total_tx_packets = 0;
1928 adapter->total_rx_bytes = 0;
1929 adapter->total_rx_packets = 0;
1930 __napi_schedule(&adapter->napi);
1936 static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
1938 struct net_device *netdev = data;
1939 struct e1000_adapter *adapter = netdev_priv(netdev);
1940 struct e1000_hw *hw = &adapter->hw;
1941 u32 icr = er32(ICR);
1943 if (icr & adapter->eiac_mask)
1944 ew32(ICS, (icr & adapter->eiac_mask));
1946 if (icr & E1000_ICR_LSC) {
1947 hw->mac.get_link_status = true;
1948 /* guard against interrupt when we're going down */
1949 if (!test_bit(__E1000_DOWN, &adapter->state))
1950 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1953 if (!test_bit(__E1000_DOWN, &adapter->state))
1954 ew32(IMS, E1000_IMS_OTHER | IMS_OTHER_MASK);
1959 static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
1961 struct net_device *netdev = data;
1962 struct e1000_adapter *adapter = netdev_priv(netdev);
1963 struct e1000_hw *hw = &adapter->hw;
1964 struct e1000_ring *tx_ring = adapter->tx_ring;
1966 adapter->total_tx_bytes = 0;
1967 adapter->total_tx_packets = 0;
1969 if (!e1000_clean_tx_irq(tx_ring))
1970 /* Ring was not completely cleaned, so fire another interrupt */
1971 ew32(ICS, tx_ring->ims_val);
1973 if (!test_bit(__E1000_DOWN, &adapter->state))
1974 ew32(IMS, adapter->tx_ring->ims_val);
1979 static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
1981 struct net_device *netdev = data;
1982 struct e1000_adapter *adapter = netdev_priv(netdev);
1983 struct e1000_ring *rx_ring = adapter->rx_ring;
1985 /* Write the ITR value calculated at the end of the
1986 * previous interrupt.
1988 if (rx_ring->set_itr) {
1989 u32 itr = rx_ring->itr_val ?
1990 1000000000 / (rx_ring->itr_val * 256) : 0;
1992 writel(itr, rx_ring->itr_register);
1993 rx_ring->set_itr = 0;
1996 if (napi_schedule_prep(&adapter->napi)) {
1997 adapter->total_rx_bytes = 0;
1998 adapter->total_rx_packets = 0;
1999 __napi_schedule(&adapter->napi);
2005 * e1000_configure_msix - Configure MSI-X hardware
2006 * @adapter: board private structure
2008 * e1000_configure_msix sets up the hardware to properly
2009 * generate MSI-X interrupts.
2011 static void e1000_configure_msix(struct e1000_adapter *adapter)
2013 struct e1000_hw *hw = &adapter->hw;
2014 struct e1000_ring *rx_ring = adapter->rx_ring;
2015 struct e1000_ring *tx_ring = adapter->tx_ring;
2017 u32 ctrl_ext, ivar = 0;
2019 adapter->eiac_mask = 0;
2021 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
2022 if (hw->mac.type == e1000_82574) {
2023 u32 rfctl = er32(RFCTL);
2025 rfctl |= E1000_RFCTL_ACK_DIS;
2029 /* Configure Rx vector */
2030 rx_ring->ims_val = E1000_IMS_RXQ0;
2031 adapter->eiac_mask |= rx_ring->ims_val;
2032 if (rx_ring->itr_val)
2033 writel(1000000000 / (rx_ring->itr_val * 256),
2034 rx_ring->itr_register);
2036 writel(1, rx_ring->itr_register);
2037 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
2039 /* Configure Tx vector */
2040 tx_ring->ims_val = E1000_IMS_TXQ0;
2042 if (tx_ring->itr_val)
2043 writel(1000000000 / (tx_ring->itr_val * 256),
2044 tx_ring->itr_register);
2046 writel(1, tx_ring->itr_register);
2047 adapter->eiac_mask |= tx_ring->ims_val;
2048 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
2050 /* set vector for Other Causes, e.g. link changes */
2052 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
2053 if (rx_ring->itr_val)
2054 writel(1000000000 / (rx_ring->itr_val * 256),
2055 hw->hw_addr + E1000_EITR_82574(vector));
2057 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2059 /* Cause Tx interrupts on every write back */
2064 /* enable MSI-X PBA support */
2065 ctrl_ext = er32(CTRL_EXT) & ~E1000_CTRL_EXT_IAME;
2066 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR | E1000_CTRL_EXT_EIAME;
2067 ew32(CTRL_EXT, ctrl_ext);
2071 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2073 if (adapter->msix_entries) {
2074 pci_disable_msix(adapter->pdev);
2075 kfree(adapter->msix_entries);
2076 adapter->msix_entries = NULL;
2077 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2078 pci_disable_msi(adapter->pdev);
2079 adapter->flags &= ~FLAG_MSI_ENABLED;
2084 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2085 * @adapter: board private structure
2087 * Attempt to configure interrupts using the best available
2088 * capabilities of the hardware and kernel.
2090 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2095 switch (adapter->int_mode) {
2096 case E1000E_INT_MODE_MSIX:
2097 if (adapter->flags & FLAG_HAS_MSIX) {
2098 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2099 adapter->msix_entries = kcalloc(adapter->num_vectors,
2103 if (adapter->msix_entries) {
2104 struct e1000_adapter *a = adapter;
2106 for (i = 0; i < adapter->num_vectors; i++)
2107 adapter->msix_entries[i].entry = i;
2109 err = pci_enable_msix_range(a->pdev,
2116 /* MSI-X failed, so fall through and try MSI */
2117 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
2118 e1000e_reset_interrupt_capability(adapter);
2120 adapter->int_mode = E1000E_INT_MODE_MSI;
2122 case E1000E_INT_MODE_MSI:
2123 if (!pci_enable_msi(adapter->pdev)) {
2124 adapter->flags |= FLAG_MSI_ENABLED;
2126 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2127 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
2130 case E1000E_INT_MODE_LEGACY:
2131 /* Don't do anything; this is the system default */
2135 /* store the number of vectors being used */
2136 adapter->num_vectors = 1;
2140 * e1000_request_msix - Initialize MSI-X interrupts
2141 * @adapter: board private structure
2143 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2146 static int e1000_request_msix(struct e1000_adapter *adapter)
2148 struct net_device *netdev = adapter->netdev;
2149 int err = 0, vector = 0;
2151 if (strlen(netdev->name) < (IFNAMSIZ - 5))
2152 snprintf(adapter->rx_ring->name,
2153 sizeof(adapter->rx_ring->name) - 1,
2154 "%.14s-rx-0", netdev->name);
2156 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2157 err = request_irq(adapter->msix_entries[vector].vector,
2158 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
2162 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2163 E1000_EITR_82574(vector);
2164 adapter->rx_ring->itr_val = adapter->itr;
2167 if (strlen(netdev->name) < (IFNAMSIZ - 5))
2168 snprintf(adapter->tx_ring->name,
2169 sizeof(adapter->tx_ring->name) - 1,
2170 "%.14s-tx-0", netdev->name);
2172 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2173 err = request_irq(adapter->msix_entries[vector].vector,
2174 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
2178 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2179 E1000_EITR_82574(vector);
2180 adapter->tx_ring->itr_val = adapter->itr;
2183 err = request_irq(adapter->msix_entries[vector].vector,
2184 e1000_msix_other, 0, netdev->name, netdev);
2188 e1000_configure_msix(adapter);
2194 * e1000_request_irq - initialize interrupts
2195 * @adapter: board private structure
2197 * Attempts to configure interrupts using the best available
2198 * capabilities of the hardware and kernel.
2200 static int e1000_request_irq(struct e1000_adapter *adapter)
2202 struct net_device *netdev = adapter->netdev;
2205 if (adapter->msix_entries) {
2206 err = e1000_request_msix(adapter);
2209 /* fall back to MSI */
2210 e1000e_reset_interrupt_capability(adapter);
2211 adapter->int_mode = E1000E_INT_MODE_MSI;
2212 e1000e_set_interrupt_capability(adapter);
2214 if (adapter->flags & FLAG_MSI_ENABLED) {
2215 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
2216 netdev->name, netdev);
2220 /* fall back to legacy interrupt */
2221 e1000e_reset_interrupt_capability(adapter);
2222 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2225 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
2226 netdev->name, netdev);
2228 e_err("Unable to allocate interrupt, Error: %d\n", err);
2233 static void e1000_free_irq(struct e1000_adapter *adapter)
2235 struct net_device *netdev = adapter->netdev;
2237 if (adapter->msix_entries) {
2240 free_irq(adapter->msix_entries[vector].vector, netdev);
2243 free_irq(adapter->msix_entries[vector].vector, netdev);
2246 /* Other Causes interrupt vector */
2247 free_irq(adapter->msix_entries[vector].vector, netdev);
2251 free_irq(adapter->pdev->irq, netdev);
2255 * e1000_irq_disable - Mask off interrupt generation on the NIC
2256 * @adapter: board private structure
2258 static void e1000_irq_disable(struct e1000_adapter *adapter)
2260 struct e1000_hw *hw = &adapter->hw;
2263 if (adapter->msix_entries)
2264 ew32(EIAC_82574, 0);
2267 if (adapter->msix_entries) {
2270 for (i = 0; i < adapter->num_vectors; i++)
2271 synchronize_irq(adapter->msix_entries[i].vector);
2273 synchronize_irq(adapter->pdev->irq);
2278 * e1000_irq_enable - Enable default interrupt generation settings
2279 * @adapter: board private structure
2281 static void e1000_irq_enable(struct e1000_adapter *adapter)
2283 struct e1000_hw *hw = &adapter->hw;
2285 if (adapter->msix_entries) {
2286 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2287 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER |
2289 } else if (hw->mac.type >= e1000_pch_lpt) {
2290 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
2292 ew32(IMS, IMS_ENABLE_MASK);
2298 * e1000e_get_hw_control - get control of the h/w from f/w
2299 * @adapter: address of board private structure
2301 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2302 * For ASF and Pass Through versions of f/w this means that
2303 * the driver is loaded. For AMT version (only with 82573)
2304 * of the f/w this means that the network i/f is open.
2306 void e1000e_get_hw_control(struct e1000_adapter *adapter)
2308 struct e1000_hw *hw = &adapter->hw;
2312 /* Let firmware know the driver has taken over */
2313 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2315 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2316 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2317 ctrl_ext = er32(CTRL_EXT);
2318 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2323 * e1000e_release_hw_control - release control of the h/w to f/w
2324 * @adapter: address of board private structure
2326 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2327 * For ASF and Pass Through versions of f/w this means that the
2328 * driver is no longer loaded. For AMT version (only with 82573) i
2329 * of the f/w this means that the network i/f is closed.
2332 void e1000e_release_hw_control(struct e1000_adapter *adapter)
2334 struct e1000_hw *hw = &adapter->hw;
2338 /* Let firmware taken over control of h/w */
2339 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2341 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2342 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2343 ctrl_ext = er32(CTRL_EXT);
2344 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2349 * e1000_alloc_ring_dma - allocate memory for a ring structure
2350 * @adapter: board private structure
2351 * @ring: ring struct for which to allocate dma
2353 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2354 struct e1000_ring *ring)
2356 struct pci_dev *pdev = adapter->pdev;
2358 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2367 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2368 * @tx_ring: Tx descriptor ring
2370 * Return 0 on success, negative on failure
2372 int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
2374 struct e1000_adapter *adapter = tx_ring->adapter;
2375 int err = -ENOMEM, size;
2377 size = sizeof(struct e1000_buffer) * tx_ring->count;
2378 tx_ring->buffer_info = vzalloc(size);
2379 if (!tx_ring->buffer_info)
2382 /* round up to nearest 4K */
2383 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2384 tx_ring->size = ALIGN(tx_ring->size, 4096);
2386 err = e1000_alloc_ring_dma(adapter, tx_ring);
2390 tx_ring->next_to_use = 0;
2391 tx_ring->next_to_clean = 0;
2395 vfree(tx_ring->buffer_info);
2396 e_err("Unable to allocate memory for the transmit descriptor ring\n");
2401 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2402 * @rx_ring: Rx descriptor ring
2404 * Returns 0 on success, negative on failure
2406 int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
2408 struct e1000_adapter *adapter = rx_ring->adapter;
2409 struct e1000_buffer *buffer_info;
2410 int i, size, desc_len, err = -ENOMEM;
2412 size = sizeof(struct e1000_buffer) * rx_ring->count;
2413 rx_ring->buffer_info = vzalloc(size);
2414 if (!rx_ring->buffer_info)
2417 for (i = 0; i < rx_ring->count; i++) {
2418 buffer_info = &rx_ring->buffer_info[i];
2419 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2420 sizeof(struct e1000_ps_page),
2422 if (!buffer_info->ps_pages)
2426 desc_len = sizeof(union e1000_rx_desc_packet_split);
2428 /* Round up to nearest 4K */
2429 rx_ring->size = rx_ring->count * desc_len;
2430 rx_ring->size = ALIGN(rx_ring->size, 4096);
2432 err = e1000_alloc_ring_dma(adapter, rx_ring);
2436 rx_ring->next_to_clean = 0;
2437 rx_ring->next_to_use = 0;
2438 rx_ring->rx_skb_top = NULL;
2443 for (i = 0; i < rx_ring->count; i++) {
2444 buffer_info = &rx_ring->buffer_info[i];
2445 kfree(buffer_info->ps_pages);
2448 vfree(rx_ring->buffer_info);
2449 e_err("Unable to allocate memory for the receive descriptor ring\n");
2454 * e1000_clean_tx_ring - Free Tx Buffers
2455 * @tx_ring: Tx descriptor ring
2457 static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
2459 struct e1000_adapter *adapter = tx_ring->adapter;
2460 struct e1000_buffer *buffer_info;
2464 for (i = 0; i < tx_ring->count; i++) {
2465 buffer_info = &tx_ring->buffer_info[i];
2466 e1000_put_txbuf(tx_ring, buffer_info, false);
2469 netdev_reset_queue(adapter->netdev);
2470 size = sizeof(struct e1000_buffer) * tx_ring->count;
2471 memset(tx_ring->buffer_info, 0, size);
2473 memset(tx_ring->desc, 0, tx_ring->size);
2475 tx_ring->next_to_use = 0;
2476 tx_ring->next_to_clean = 0;
2480 * e1000e_free_tx_resources - Free Tx Resources per Queue
2481 * @tx_ring: Tx descriptor ring
2483 * Free all transmit software resources
2485 void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
2487 struct e1000_adapter *adapter = tx_ring->adapter;
2488 struct pci_dev *pdev = adapter->pdev;
2490 e1000_clean_tx_ring(tx_ring);
2492 vfree(tx_ring->buffer_info);
2493 tx_ring->buffer_info = NULL;
2495 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2497 tx_ring->desc = NULL;
2501 * e1000e_free_rx_resources - Free Rx Resources
2502 * @rx_ring: Rx descriptor ring
2504 * Free all receive software resources
2506 void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
2508 struct e1000_adapter *adapter = rx_ring->adapter;
2509 struct pci_dev *pdev = adapter->pdev;
2512 e1000_clean_rx_ring(rx_ring);
2514 for (i = 0; i < rx_ring->count; i++)
2515 kfree(rx_ring->buffer_info[i].ps_pages);
2517 vfree(rx_ring->buffer_info);
2518 rx_ring->buffer_info = NULL;
2520 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2522 rx_ring->desc = NULL;
2526 * e1000_update_itr - update the dynamic ITR value based on statistics
2527 * @itr_setting: current adapter->itr
2528 * @packets: the number of packets during this measurement interval
2529 * @bytes: the number of bytes during this measurement interval
2531 * Stores a new ITR value based on packets and byte
2532 * counts during the last interrupt. The advantage of per interrupt
2533 * computation is faster updates and more accurate ITR for the current
2534 * traffic pattern. Constants in this function were computed
2535 * based on theoretical maximum wire speed and thresholds were set based
2536 * on testing data as well as attempting to minimize response time
2537 * while increasing bulk throughput. This functionality is controlled
2538 * by the InterruptThrottleRate module parameter.
2540 static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
2542 unsigned int retval = itr_setting;
2547 switch (itr_setting) {
2548 case lowest_latency:
2549 /* handle TSO and jumbo frames */
2550 if (bytes / packets > 8000)
2551 retval = bulk_latency;
2552 else if ((packets < 5) && (bytes > 512))
2553 retval = low_latency;
2555 case low_latency: /* 50 usec aka 20000 ints/s */
2556 if (bytes > 10000) {
2557 /* this if handles the TSO accounting */
2558 if (bytes / packets > 8000)
2559 retval = bulk_latency;
2560 else if ((packets < 10) || ((bytes / packets) > 1200))
2561 retval = bulk_latency;
2562 else if ((packets > 35))
2563 retval = lowest_latency;
2564 } else if (bytes / packets > 2000) {
2565 retval = bulk_latency;
2566 } else if (packets <= 2 && bytes < 512) {
2567 retval = lowest_latency;
2570 case bulk_latency: /* 250 usec aka 4000 ints/s */
2571 if (bytes > 25000) {
2573 retval = low_latency;
2574 } else if (bytes < 6000) {
2575 retval = low_latency;
2583 static void e1000_set_itr(struct e1000_adapter *adapter)
2586 u32 new_itr = adapter->itr;
2588 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2589 if (adapter->link_speed != SPEED_1000) {
2595 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2600 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2601 adapter->total_tx_packets,
2602 adapter->total_tx_bytes);
2603 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2604 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2605 adapter->tx_itr = low_latency;
2607 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2608 adapter->total_rx_packets,
2609 adapter->total_rx_bytes);
2610 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2611 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2612 adapter->rx_itr = low_latency;
2614 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2616 /* counts and packets in update_itr are dependent on these numbers */
2617 switch (current_itr) {
2618 case lowest_latency:
2622 new_itr = 20000; /* aka hwitr = ~200 */
2632 if (new_itr != adapter->itr) {
2633 /* this attempts to bias the interrupt rate towards Bulk
2634 * by adding intermediate steps when interrupt rate is
2637 new_itr = new_itr > adapter->itr ?
2638 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
2639 adapter->itr = new_itr;
2640 adapter->rx_ring->itr_val = new_itr;
2641 if (adapter->msix_entries)
2642 adapter->rx_ring->set_itr = 1;
2644 e1000e_write_itr(adapter, new_itr);
2649 * e1000e_write_itr - write the ITR value to the appropriate registers
2650 * @adapter: address of board private structure
2651 * @itr: new ITR value to program
2653 * e1000e_write_itr determines if the adapter is in MSI-X mode
2654 * and, if so, writes the EITR registers with the ITR value.
2655 * Otherwise, it writes the ITR value into the ITR register.
2657 void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2659 struct e1000_hw *hw = &adapter->hw;
2660 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2662 if (adapter->msix_entries) {
2665 for (vector = 0; vector < adapter->num_vectors; vector++)
2666 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2673 * e1000_alloc_queues - Allocate memory for all rings
2674 * @adapter: board private structure to initialize
2676 static int e1000_alloc_queues(struct e1000_adapter *adapter)
2678 int size = sizeof(struct e1000_ring);
2680 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
2681 if (!adapter->tx_ring)
2683 adapter->tx_ring->count = adapter->tx_ring_count;
2684 adapter->tx_ring->adapter = adapter;
2686 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
2687 if (!adapter->rx_ring)
2689 adapter->rx_ring->count = adapter->rx_ring_count;
2690 adapter->rx_ring->adapter = adapter;
2694 e_err("Unable to allocate memory for queues\n");
2695 kfree(adapter->rx_ring);
2696 kfree(adapter->tx_ring);
2701 * e1000e_poll - NAPI Rx polling callback
2702 * @napi: struct associated with this polling callback
2703 * @budget: number of packets driver is allowed to process this poll
2705 static int e1000e_poll(struct napi_struct *napi, int budget)
2707 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2709 struct e1000_hw *hw = &adapter->hw;
2710 struct net_device *poll_dev = adapter->netdev;
2711 int tx_cleaned = 1, work_done = 0;
2713 adapter = netdev_priv(poll_dev);
2715 if (!adapter->msix_entries ||
2716 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2717 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
2719 adapter->clean_rx(adapter->rx_ring, &work_done, budget);
2721 if (!tx_cleaned || work_done == budget)
2724 /* Exit the polling mode, but don't re-enable interrupts if stack might
2725 * poll us due to busy-polling
2727 if (likely(napi_complete_done(napi, work_done))) {
2728 if (adapter->itr_setting & 3)
2729 e1000_set_itr(adapter);
2730 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2731 if (adapter->msix_entries)
2732 ew32(IMS, adapter->rx_ring->ims_val);
2734 e1000_irq_enable(adapter);
2741 static int e1000_vlan_rx_add_vid(struct net_device *netdev,
2742 __always_unused __be16 proto, u16 vid)
2744 struct e1000_adapter *adapter = netdev_priv(netdev);
2745 struct e1000_hw *hw = &adapter->hw;
2748 /* don't update vlan cookie if already programmed */
2749 if ((adapter->hw.mng_cookie.status &
2750 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2751 (vid == adapter->mng_vlan_id))
2754 /* add VID to filter table */
2755 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2756 index = (vid >> 5) & 0x7F;
2757 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2758 vfta |= BIT((vid & 0x1F));
2759 hw->mac.ops.write_vfta(hw, index, vfta);
2762 set_bit(vid, adapter->active_vlans);
2767 static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
2768 __always_unused __be16 proto, u16 vid)
2770 struct e1000_adapter *adapter = netdev_priv(netdev);
2771 struct e1000_hw *hw = &adapter->hw;
2774 if ((adapter->hw.mng_cookie.status &
2775 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2776 (vid == adapter->mng_vlan_id)) {
2777 /* release control to f/w */
2778 e1000e_release_hw_control(adapter);
2782 /* remove VID from filter table */
2783 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2784 index = (vid >> 5) & 0x7F;
2785 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2786 vfta &= ~BIT((vid & 0x1F));
2787 hw->mac.ops.write_vfta(hw, index, vfta);
2790 clear_bit(vid, adapter->active_vlans);
2796 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2797 * @adapter: board private structure to initialize
2799 static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2801 struct net_device *netdev = adapter->netdev;
2802 struct e1000_hw *hw = &adapter->hw;
2805 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2806 /* disable VLAN receive filtering */
2808 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2811 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2812 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
2813 adapter->mng_vlan_id);
2814 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2820 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2821 * @adapter: board private structure to initialize
2823 static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2825 struct e1000_hw *hw = &adapter->hw;
2828 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2829 /* enable VLAN receive filtering */
2831 rctl |= E1000_RCTL_VFE;
2832 rctl &= ~E1000_RCTL_CFIEN;
2838 * e1000e_vlan_strip_disable - helper to disable HW VLAN stripping
2839 * @adapter: board private structure to initialize
2841 static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2843 struct e1000_hw *hw = &adapter->hw;
2846 /* disable VLAN tag insert/strip */
2848 ctrl &= ~E1000_CTRL_VME;
2853 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2854 * @adapter: board private structure to initialize
2856 static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2858 struct e1000_hw *hw = &adapter->hw;
2861 /* enable VLAN tag insert/strip */
2863 ctrl |= E1000_CTRL_VME;
2867 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2869 struct net_device *netdev = adapter->netdev;
2870 u16 vid = adapter->hw.mng_cookie.vlan_id;
2871 u16 old_vid = adapter->mng_vlan_id;
2873 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2874 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
2875 adapter->mng_vlan_id = vid;
2878 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2879 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
2882 static void e1000_restore_vlan(struct e1000_adapter *adapter)
2886 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
2888 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
2889 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
2892 static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
2894 struct e1000_hw *hw = &adapter->hw;
2895 u32 manc, manc2h, mdef, i, j;
2897 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2902 /* enable receiving management packets to the host. this will probably
2903 * generate destination unreachable messages from the host OS, but
2904 * the packets will be handled on SMBUS
2906 manc |= E1000_MANC_EN_MNG2HOST;
2907 manc2h = er32(MANC2H);
2909 switch (hw->mac.type) {
2911 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2915 /* Check if IPMI pass-through decision filter already exists;
2918 for (i = 0, j = 0; i < 8; i++) {
2919 mdef = er32(MDEF(i));
2921 /* Ignore filters with anything other than IPMI ports */
2922 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2925 /* Enable this decision filter in MANC2H */
2932 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2935 /* Create new decision filter in an empty filter */
2936 for (i = 0, j = 0; i < 8; i++)
2937 if (er32(MDEF(i)) == 0) {
2938 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2939 E1000_MDEF_PORT_664));
2946 e_warn("Unable to create IPMI pass-through filter\n");
2950 ew32(MANC2H, manc2h);
2955 * e1000_configure_tx - Configure Transmit Unit after Reset
2956 * @adapter: board private structure
2958 * Configure the Tx unit of the MAC after a reset.
2960 static void e1000_configure_tx(struct e1000_adapter *adapter)
2962 struct e1000_hw *hw = &adapter->hw;
2963 struct e1000_ring *tx_ring = adapter->tx_ring;
2965 u32 tdlen, tctl, tarc;
2967 /* Setup the HW Tx Head and Tail descriptor pointers */
2968 tdba = tx_ring->dma;
2969 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2970 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2971 ew32(TDBAH(0), (tdba >> 32));
2972 ew32(TDLEN(0), tdlen);
2975 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2976 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
2978 writel(0, tx_ring->head);
2979 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2980 e1000e_update_tdt_wa(tx_ring, 0);
2982 writel(0, tx_ring->tail);
2984 /* Set the Tx Interrupt Delay register */
2985 ew32(TIDV, adapter->tx_int_delay);
2986 /* Tx irq moderation */
2987 ew32(TADV, adapter->tx_abs_int_delay);
2989 if (adapter->flags2 & FLAG2_DMA_BURST) {
2990 u32 txdctl = er32(TXDCTL(0));
2992 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2993 E1000_TXDCTL_WTHRESH);
2994 /* set up some performance related parameters to encourage the
2995 * hardware to use the bus more efficiently in bursts, depends
2996 * on the tx_int_delay to be enabled,
2997 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
2998 * hthresh = 1 ==> prefetch when one or more available
2999 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
3000 * BEWARE: this seems to work but should be considered first if
3001 * there are Tx hangs or other Tx related bugs
3003 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
3004 ew32(TXDCTL(0), txdctl);
3006 /* erratum work around: set txdctl the same for both queues */
3007 ew32(TXDCTL(1), er32(TXDCTL(0)));
3009 /* Program the Transmit Control Register */
3011 tctl &= ~E1000_TCTL_CT;
3012 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
3013 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
3015 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
3016 tarc = er32(TARC(0));
3017 /* set the speed mode bit, we'll clear it if we're not at
3018 * gigabit link later
3020 #define SPEED_MODE_BIT BIT(21)
3021 tarc |= SPEED_MODE_BIT;
3022 ew32(TARC(0), tarc);
3025 /* errata: program both queues to unweighted RR */
3026 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
3027 tarc = er32(TARC(0));
3029 ew32(TARC(0), tarc);
3030 tarc = er32(TARC(1));
3032 ew32(TARC(1), tarc);
3035 /* Setup Transmit Descriptor Settings for eop descriptor */
3036 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
3038 /* only set IDE if we are delaying interrupts using the timers */
3039 if (adapter->tx_int_delay)
3040 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
3042 /* enable Report Status bit */
3043 adapter->txd_cmd |= E1000_TXD_CMD_RS;
3047 hw->mac.ops.config_collision_dist(hw);
3049 /* SPT and KBL Si errata workaround to avoid data corruption */
3050 if (hw->mac.type == e1000_pch_spt) {
3053 reg_val = er32(IOSFPC);
3054 reg_val |= E1000_RCTL_RDMTS_HEX;
3055 ew32(IOSFPC, reg_val);
3057 reg_val = er32(TARC(0));
3058 /* SPT and KBL Si errata workaround to avoid Tx hang.
3059 * Dropping the number of outstanding requests from
3060 * 3 to 2 in order to avoid a buffer overrun.
3062 reg_val &= ~E1000_TARC0_CB_MULTIQ_3_REQ;
3063 reg_val |= E1000_TARC0_CB_MULTIQ_2_REQ;
3064 ew32(TARC(0), reg_val);
3068 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
3069 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
3072 * e1000_setup_rctl - configure the receive control registers
3073 * @adapter: Board private structure
3075 static void e1000_setup_rctl(struct e1000_adapter *adapter)
3077 struct e1000_hw *hw = &adapter->hw;
3081 /* Workaround Si errata on PCHx - configure jumbo frame flow.
3082 * If jumbo frames not set, program related MAC/PHY registers
3085 if (hw->mac.type >= e1000_pch2lan) {
3088 if (adapter->netdev->mtu > ETH_DATA_LEN)
3089 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
3091 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
3094 e_dbg("failed to enable|disable jumbo frame workaround mode\n");
3097 /* Program MC offset vector base */
3099 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3100 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
3101 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3102 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3104 /* Do not Store bad packets */
3105 rctl &= ~E1000_RCTL_SBP;
3107 /* Enable Long Packet receive */
3108 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3109 rctl &= ~E1000_RCTL_LPE;
3111 rctl |= E1000_RCTL_LPE;
3113 /* Some systems expect that the CRC is included in SMBUS traffic. The
3114 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3115 * host memory when this is enabled
3117 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3118 rctl |= E1000_RCTL_SECRC;
3120 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3121 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3124 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3127 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3129 e1e_rphy(hw, 22, &phy_data);
3131 phy_data |= BIT(14);
3132 e1e_wphy(hw, 0x10, 0x2823);
3133 e1e_wphy(hw, 0x11, 0x0003);
3134 e1e_wphy(hw, 22, phy_data);
3137 /* Setup buffer sizes */
3138 rctl &= ~E1000_RCTL_SZ_4096;
3139 rctl |= E1000_RCTL_BSEX;
3140 switch (adapter->rx_buffer_len) {
3143 rctl |= E1000_RCTL_SZ_2048;
3144 rctl &= ~E1000_RCTL_BSEX;
3147 rctl |= E1000_RCTL_SZ_4096;
3150 rctl |= E1000_RCTL_SZ_8192;
3153 rctl |= E1000_RCTL_SZ_16384;
3157 /* Enable Extended Status in all Receive Descriptors */
3158 rfctl = er32(RFCTL);
3159 rfctl |= E1000_RFCTL_EXTEN;
3162 /* 82571 and greater support packet-split where the protocol
3163 * header is placed in skb->data and the packet data is
3164 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3165 * In the case of a non-split, skb->data is linearly filled,
3166 * followed by the page buffers. Therefore, skb->data is
3167 * sized to hold the largest protocol header.
3169 * allocations using alloc_page take too long for regular MTU
3170 * so only enable packet split for jumbo frames
3172 * Using pages when the page size is greater than 16k wastes
3173 * a lot of memory, since we allocate 3 pages at all times
3176 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
3177 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
3178 adapter->rx_ps_pages = pages;
3180 adapter->rx_ps_pages = 0;
3182 if (adapter->rx_ps_pages) {
3185 /* Enable Packet split descriptors */
3186 rctl |= E1000_RCTL_DTYP_PS;
3188 psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
3190 switch (adapter->rx_ps_pages) {
3192 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
3195 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
3198 psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
3202 ew32(PSRCTL, psrctl);
3205 /* This is useful for sniffing bad packets. */
3206 if (adapter->netdev->features & NETIF_F_RXALL) {
3207 /* UPE and MPE will be handled by normal PROMISC logic
3208 * in e1000e_set_rx_mode
3210 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3211 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3212 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3214 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3215 E1000_RCTL_DPF | /* Allow filtered pause */
3216 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3217 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3218 * and that breaks VLANs.
3223 /* just started the receive unit, no need to restart */
3224 adapter->flags &= ~FLAG_RESTART_NOW;
3228 * e1000_configure_rx - Configure Receive Unit after Reset
3229 * @adapter: board private structure
3231 * Configure the Rx unit of the MAC after a reset.
3233 static void e1000_configure_rx(struct e1000_adapter *adapter)
3235 struct e1000_hw *hw = &adapter->hw;
3236 struct e1000_ring *rx_ring = adapter->rx_ring;
3238 u32 rdlen, rctl, rxcsum, ctrl_ext;
3240 if (adapter->rx_ps_pages) {
3241 /* this is a 32 byte descriptor */
3242 rdlen = rx_ring->count *
3243 sizeof(union e1000_rx_desc_packet_split);
3244 adapter->clean_rx = e1000_clean_rx_irq_ps;
3245 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
3246 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
3247 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3248 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3249 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
3251 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3252 adapter->clean_rx = e1000_clean_rx_irq;
3253 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3256 /* disable receives while setting up the descriptors */
3258 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3259 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3261 usleep_range(10000, 11000);
3263 if (adapter->flags2 & FLAG2_DMA_BURST) {
3264 /* set the writeback threshold (only takes effect if the RDTR
3265 * is set). set GRAN=1 and write back up to 0x4 worth, and
3266 * enable prefetching of 0x20 Rx descriptors
3272 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3273 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3276 /* set the Receive Delay Timer Register */
3277 ew32(RDTR, adapter->rx_int_delay);
3279 /* irq moderation */
3280 ew32(RADV, adapter->rx_abs_int_delay);
3281 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
3282 e1000e_write_itr(adapter, adapter->itr);
3284 ctrl_ext = er32(CTRL_EXT);
3285 /* Auto-Mask interrupts upon ICR access */
3286 ctrl_ext |= E1000_CTRL_EXT_IAME;
3287 ew32(IAM, 0xffffffff);
3288 ew32(CTRL_EXT, ctrl_ext);
3291 /* Setup the HW Rx Head and Tail Descriptor Pointers and
3292 * the Base and Length of the Rx Descriptor Ring
3294 rdba = rx_ring->dma;
3295 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3296 ew32(RDBAH(0), (rdba >> 32));
3297 ew32(RDLEN(0), rdlen);
3300 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3301 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
3303 writel(0, rx_ring->head);
3304 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
3305 e1000e_update_rdt_wa(rx_ring, 0);
3307 writel(0, rx_ring->tail);
3309 /* Enable Receive Checksum Offload for TCP and UDP */
3310 rxcsum = er32(RXCSUM);
3311 if (adapter->netdev->features & NETIF_F_RXCSUM)
3312 rxcsum |= E1000_RXCSUM_TUOFL;
3314 rxcsum &= ~E1000_RXCSUM_TUOFL;
3315 ew32(RXCSUM, rxcsum);
3317 /* With jumbo frames, excessive C-state transition latencies result
3318 * in dropped transactions.
3320 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3322 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3323 adapter->max_frame_size) * 8 / 1000;
3325 if (adapter->flags & FLAG_IS_ICH) {
3326 u32 rxdctl = er32(RXDCTL(0));
3328 ew32(RXDCTL(0), rxdctl | 0x3 | BIT(8));
3331 dev_info(&adapter->pdev->dev,
3332 "Some CPU C-states have been disabled in order to enable jumbo frames\n");
3333 cpu_latency_qos_update_request(&adapter->pm_qos_req, lat);
3335 cpu_latency_qos_update_request(&adapter->pm_qos_req,
3336 PM_QOS_DEFAULT_VALUE);
3339 /* Enable Receives */
3344 * e1000e_write_mc_addr_list - write multicast addresses to MTA
3345 * @netdev: network interface device structure
3347 * Writes multicast address list to the MTA hash table.
3348 * Returns: -ENOMEM on failure
3349 * 0 on no addresses written
3350 * X on writing X addresses to MTA
3352 static int e1000e_write_mc_addr_list(struct net_device *netdev)
3354 struct e1000_adapter *adapter = netdev_priv(netdev);
3355 struct e1000_hw *hw = &adapter->hw;
3356 struct netdev_hw_addr *ha;
3360 if (netdev_mc_empty(netdev)) {
3361 /* nothing to program, so clear mc list */
3362 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3366 mta_list = kcalloc(netdev_mc_count(netdev), ETH_ALEN, GFP_ATOMIC);
3370 /* update_mc_addr_list expects a packed array of only addresses. */
3372 netdev_for_each_mc_addr(ha, netdev)
3373 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3375 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3378 return netdev_mc_count(netdev);
3382 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3383 * @netdev: network interface device structure
3385 * Writes unicast address list to the RAR table.
3386 * Returns: -ENOMEM on failure/insufficient address space
3387 * 0 on no addresses written
3388 * X on writing X addresses to the RAR table
3390 static int e1000e_write_uc_addr_list(struct net_device *netdev)
3392 struct e1000_adapter *adapter = netdev_priv(netdev);
3393 struct e1000_hw *hw = &adapter->hw;
3394 unsigned int rar_entries;
3397 rar_entries = hw->mac.ops.rar_get_count(hw);
3399 /* save a rar entry for our hardware address */
3402 /* save a rar entry for the LAA workaround */
3403 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3406 /* return ENOMEM indicating insufficient memory for addresses */
3407 if (netdev_uc_count(netdev) > rar_entries)
3410 if (!netdev_uc_empty(netdev) && rar_entries) {
3411 struct netdev_hw_addr *ha;
3413 /* write the addresses in reverse order to avoid write
3416 netdev_for_each_uc_addr(ha, netdev) {
3421 ret_val = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
3428 /* zero out the remaining RAR entries not used above */
3429 for (; rar_entries > 0; rar_entries--) {
3430 ew32(RAH(rar_entries), 0);
3431 ew32(RAL(rar_entries), 0);
3439 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3440 * @netdev: network interface device structure
3442 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3443 * address list or the network interface flags are updated. This routine is
3444 * responsible for configuring the hardware for proper unicast, multicast,
3445 * promiscuous mode, and all-multi behavior.
3447 static void e1000e_set_rx_mode(struct net_device *netdev)
3449 struct e1000_adapter *adapter = netdev_priv(netdev);
3450 struct e1000_hw *hw = &adapter->hw;
3453 if (pm_runtime_suspended(netdev->dev.parent))
3456 /* Check for Promiscuous and All Multicast modes */
3459 /* clear the affected bits */
3460 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3462 if (netdev->flags & IFF_PROMISC) {
3463 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
3464 /* Do not hardware filter VLANs in promisc mode */
3465 e1000e_vlan_filter_disable(adapter);
3469 if (netdev->flags & IFF_ALLMULTI) {
3470 rctl |= E1000_RCTL_MPE;
3472 /* Write addresses to the MTA, if the attempt fails
3473 * then we should just turn on promiscuous mode so
3474 * that we can at least receive multicast traffic
3476 count = e1000e_write_mc_addr_list(netdev);
3478 rctl |= E1000_RCTL_MPE;
3480 e1000e_vlan_filter_enable(adapter);
3481 /* Write addresses to available RAR registers, if there is not
3482 * sufficient space to store all the addresses then enable
3483 * unicast promiscuous mode
3485 count = e1000e_write_uc_addr_list(netdev);
3487 rctl |= E1000_RCTL_UPE;
3492 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
3493 e1000e_vlan_strip_enable(adapter);
3495 e1000e_vlan_strip_disable(adapter);
3498 static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3500 struct e1000_hw *hw = &adapter->hw;
3505 netdev_rss_key_fill(rss_key, sizeof(rss_key));
3506 for (i = 0; i < 10; i++)
3507 ew32(RSSRK(i), rss_key[i]);
3509 /* Direct all traffic to queue 0 */
3510 for (i = 0; i < 32; i++)
3513 /* Disable raw packet checksumming so that RSS hash is placed in
3514 * descriptor on writeback.
3516 rxcsum = er32(RXCSUM);
3517 rxcsum |= E1000_RXCSUM_PCSD;
3519 ew32(RXCSUM, rxcsum);
3521 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3522 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3523 E1000_MRQC_RSS_FIELD_IPV6 |
3524 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3525 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3531 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3532 * @adapter: board private structure
3533 * @timinca: pointer to returned time increment attributes
3535 * Get attributes for incrementing the System Time Register SYSTIML/H at
3536 * the default base frequency, and set the cyclecounter shift value.
3538 s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
3540 struct e1000_hw *hw = &adapter->hw;
3541 u32 incvalue, incperiod, shift;
3543 /* Make sure clock is enabled on I217/I218/I219 before checking
3546 if ((hw->mac.type >= e1000_pch_lpt) &&
3547 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3548 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3549 u32 fextnvm7 = er32(FEXTNVM7);
3551 if (!(fextnvm7 & BIT(0))) {
3552 ew32(FEXTNVM7, fextnvm7 | BIT(0));
3557 switch (hw->mac.type) {
3559 /* Stable 96MHz frequency */
3560 incperiod = INCPERIOD_96MHZ;
3561 incvalue = INCVALUE_96MHZ;
3562 shift = INCVALUE_SHIFT_96MHZ;
3563 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
3566 if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
3567 /* Stable 96MHz frequency */
3568 incperiod = INCPERIOD_96MHZ;
3569 incvalue = INCVALUE_96MHZ;
3570 shift = INCVALUE_SHIFT_96MHZ;
3571 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
3573 /* Stable 25MHz frequency */
3574 incperiod = INCPERIOD_25MHZ;
3575 incvalue = INCVALUE_25MHZ;
3576 shift = INCVALUE_SHIFT_25MHZ;
3577 adapter->cc.shift = shift;
3581 /* Stable 24MHz frequency */
3582 incperiod = INCPERIOD_24MHZ;
3583 incvalue = INCVALUE_24MHZ;
3584 shift = INCVALUE_SHIFT_24MHZ;
3585 adapter->cc.shift = shift;
3591 if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
3592 /* Stable 24MHz frequency */
3593 incperiod = INCPERIOD_24MHZ;
3594 incvalue = INCVALUE_24MHZ;
3595 shift = INCVALUE_SHIFT_24MHZ;
3596 adapter->cc.shift = shift;
3598 /* Stable 38400KHz frequency */
3599 incperiod = INCPERIOD_38400KHZ;
3600 incvalue = INCVALUE_38400KHZ;
3601 shift = INCVALUE_SHIFT_38400KHZ;
3602 adapter->cc.shift = shift;
3607 /* Stable 25MHz frequency */
3608 incperiod = INCPERIOD_25MHZ;
3609 incvalue = INCVALUE_25MHZ;
3610 shift = INCVALUE_SHIFT_25MHZ;
3611 adapter->cc.shift = shift;
3617 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3618 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3624 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3625 * @adapter: board private structure
3626 * @config: timestamp configuration
3628 * Outgoing time stamping can be enabled and disabled. Play nice and
3629 * disable it when requested, although it shouldn't cause any overhead
3630 * when no packet needs it. At most one packet in the queue may be
3631 * marked for time stamping, otherwise it would be impossible to tell
3632 * for sure to which packet the hardware time stamp belongs.
3634 * Incoming time stamping has to be configured via the hardware filters.
3635 * Not all combinations are supported, in particular event type has to be
3636 * specified. Matching the kind of event packet is not supported, with the
3637 * exception of "all V2 events regardless of level 2 or 4".
3639 static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
3640 struct hwtstamp_config *config)
3642 struct e1000_hw *hw = &adapter->hw;
3643 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3644 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
3651 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3654 /* flags reserved for future extensions - must be zero */
3658 switch (config->tx_type) {
3659 case HWTSTAMP_TX_OFF:
3662 case HWTSTAMP_TX_ON:
3668 switch (config->rx_filter) {
3669 case HWTSTAMP_FILTER_NONE:
3672 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3673 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3674 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3677 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3678 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3679 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3682 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3683 /* Also time stamps V2 L2 Path Delay Request/Response */
3684 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3685 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3688 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3689 /* Also time stamps V2 L2 Path Delay Request/Response. */
3690 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3691 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3694 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3695 /* Hardware cannot filter just V2 L4 Sync messages */
3697 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3698 /* Also time stamps V2 Path Delay Request/Response. */
3699 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3700 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3704 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3705 /* Hardware cannot filter just V2 L4 Delay Request messages */
3707 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3708 /* Also time stamps V2 Path Delay Request/Response. */
3709 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3710 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3714 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3715 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3716 /* Hardware cannot filter just V2 L4 or L2 Event messages */
3718 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3719 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3720 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3724 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3725 /* For V1, the hardware can only filter Sync messages or
3726 * Delay Request messages but not both so fall-through to
3727 * time stamp all packets.
3730 case HWTSTAMP_FILTER_NTP_ALL:
3731 case HWTSTAMP_FILTER_ALL:
3734 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3735 config->rx_filter = HWTSTAMP_FILTER_ALL;
3741 adapter->hwtstamp_config = *config;
3743 /* enable/disable Tx h/w time stamping */
3744 regval = er32(TSYNCTXCTL);
3745 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3746 regval |= tsync_tx_ctl;
3747 ew32(TSYNCTXCTL, regval);
3748 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3749 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3750 e_err("Timesync Tx Control register not set as expected\n");
3754 /* enable/disable Rx h/w time stamping */
3755 regval = er32(TSYNCRXCTL);
3756 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3757 regval |= tsync_rx_ctl;
3758 ew32(TSYNCRXCTL, regval);
3759 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3760 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3761 (regval & (E1000_TSYNCRXCTL_ENABLED |
3762 E1000_TSYNCRXCTL_TYPE_MASK))) {
3763 e_err("Timesync Rx Control register not set as expected\n");
3767 /* L2: define ethertype filter for time stamped packets */
3769 rxmtrl |= ETH_P_1588;
3771 /* define which PTP packets get time stamped */
3772 ew32(RXMTRL, rxmtrl);
3774 /* Filter by destination port */
3776 rxudp = PTP_EV_PORT;
3777 cpu_to_be16s(&rxudp);
3783 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
3791 * e1000_configure - configure the hardware for Rx and Tx
3792 * @adapter: private board structure
3794 static void e1000_configure(struct e1000_adapter *adapter)
3796 struct e1000_ring *rx_ring = adapter->rx_ring;
3798 e1000e_set_rx_mode(adapter->netdev);
3800 e1000_restore_vlan(adapter);
3801 e1000_init_manageability_pt(adapter);
3803 e1000_configure_tx(adapter);
3805 if (adapter->netdev->features & NETIF_F_RXHASH)
3806 e1000e_setup_rss_hash(adapter);
3807 e1000_setup_rctl(adapter);
3808 e1000_configure_rx(adapter);
3809 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
3813 * e1000e_power_up_phy - restore link in case the phy was powered down
3814 * @adapter: address of board private structure
3816 * The phy may be powered down to save power and turn off link when the
3817 * driver is unloaded and wake on lan is not enabled (among others)
3818 * *** this routine MUST be followed by a call to e1000e_reset ***
3820 void e1000e_power_up_phy(struct e1000_adapter *adapter)
3822 if (adapter->hw.phy.ops.power_up)
3823 adapter->hw.phy.ops.power_up(&adapter->hw);
3825 adapter->hw.mac.ops.setup_link(&adapter->hw);
3829 * e1000_power_down_phy - Power down the PHY
3830 * @adapter: board private structure
3832 * Power down the PHY so no link is implied when interface is down.
3833 * The PHY cannot be powered down if management or WoL is active.
3835 static void e1000_power_down_phy(struct e1000_adapter *adapter)
3837 if (adapter->hw.phy.ops.power_down)
3838 adapter->hw.phy.ops.power_down(&adapter->hw);
3842 * e1000_flush_tx_ring - remove all descriptors from the tx_ring
3843 * @adapter: board private structure
3845 * We want to clear all pending descriptors from the TX ring.
3846 * zeroing happens when the HW reads the regs. We assign the ring itself as
3847 * the data of the next descriptor. We don't care about the data we are about
3850 static void e1000_flush_tx_ring(struct e1000_adapter *adapter)
3852 struct e1000_hw *hw = &adapter->hw;
3853 struct e1000_ring *tx_ring = adapter->tx_ring;
3854 struct e1000_tx_desc *tx_desc = NULL;
3855 u32 tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS;
3859 ew32(TCTL, tctl | E1000_TCTL_EN);
3861 BUG_ON(tdt != tx_ring->next_to_use);
3862 tx_desc = E1000_TX_DESC(*tx_ring, tx_ring->next_to_use);
3863 tx_desc->buffer_addr = cpu_to_le64(tx_ring->dma);
3865 tx_desc->lower.data = cpu_to_le32(txd_lower | size);
3866 tx_desc->upper.data = 0;
3867 /* flush descriptors to memory before notifying the HW */
3869 tx_ring->next_to_use++;
3870 if (tx_ring->next_to_use == tx_ring->count)
3871 tx_ring->next_to_use = 0;
3872 ew32(TDT(0), tx_ring->next_to_use);
3873 usleep_range(200, 250);
3877 * e1000_flush_rx_ring - remove all descriptors from the rx_ring
3878 * @adapter: board private structure
3880 * Mark all descriptors in the RX ring as consumed and disable the rx ring
3882 static void e1000_flush_rx_ring(struct e1000_adapter *adapter)
3885 struct e1000_hw *hw = &adapter->hw;
3888 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3890 usleep_range(100, 150);
3892 rxdctl = er32(RXDCTL(0));
3893 /* zero the lower 14 bits (prefetch and host thresholds) */
3894 rxdctl &= 0xffffc000;
3896 /* update thresholds: prefetch threshold to 31, host threshold to 1
3897 * and make sure the granularity is "descriptors" and not "cache lines"
3899 rxdctl |= (0x1F | BIT(8) | E1000_RXDCTL_THRESH_UNIT_DESC);
3901 ew32(RXDCTL(0), rxdctl);
3902 /* momentarily enable the RX ring for the changes to take effect */
3903 ew32(RCTL, rctl | E1000_RCTL_EN);
3905 usleep_range(100, 150);
3906 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3910 * e1000_flush_desc_rings - remove all descriptors from the descriptor rings
3911 * @adapter: board private structure
3913 * In i219, the descriptor rings must be emptied before resetting the HW
3914 * or before changing the device state to D3 during runtime (runtime PM).
3916 * Failure to do this will cause the HW to enter a unit hang state which can
3917 * only be released by PCI reset on the device
3921 static void e1000_flush_desc_rings(struct e1000_adapter *adapter)
3924 u32 fext_nvm11, tdlen;
3925 struct e1000_hw *hw = &adapter->hw;
3927 /* First, disable MULR fix in FEXTNVM11 */
3928 fext_nvm11 = er32(FEXTNVM11);
3929 fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
3930 ew32(FEXTNVM11, fext_nvm11);
3931 /* do nothing if we're not in faulty state, or if the queue is empty */
3932 tdlen = er32(TDLEN(0));
3933 pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
3935 if (!(hang_state & FLUSH_DESC_REQUIRED) || !tdlen)
3937 e1000_flush_tx_ring(adapter);
3938 /* recheck, maybe the fault is caused by the rx ring */
3939 pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
3941 if (hang_state & FLUSH_DESC_REQUIRED)
3942 e1000_flush_rx_ring(adapter);
3946 * e1000e_systim_reset - reset the timesync registers after a hardware reset
3947 * @adapter: board private structure
3949 * When the MAC is reset, all hardware bits for timesync will be reset to the
3950 * default values. This function will restore the settings last in place.
3951 * Since the clock SYSTIME registers are reset, we will simply restore the
3952 * cyclecounter to the kernel real clock time.
3954 static void e1000e_systim_reset(struct e1000_adapter *adapter)
3956 struct ptp_clock_info *info = &adapter->ptp_clock_info;
3957 struct e1000_hw *hw = &adapter->hw;
3958 unsigned long flags;
3962 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3965 if (info->adjfreq) {
3966 /* restore the previous ptp frequency delta */
3967 ret_val = info->adjfreq(info, adapter->ptp_delta);
3969 /* set the default base frequency if no adjustment possible */
3970 ret_val = e1000e_get_base_timinca(adapter, &timinca);
3972 ew32(TIMINCA, timinca);
3976 dev_warn(&adapter->pdev->dev,
3977 "Failed to restore TIMINCA clock rate delta: %d\n",
3982 /* reset the systim ns time counter */
3983 spin_lock_irqsave(&adapter->systim_lock, flags);
3984 timecounter_init(&adapter->tc, &adapter->cc,
3985 ktime_to_ns(ktime_get_real()));
3986 spin_unlock_irqrestore(&adapter->systim_lock, flags);
3988 /* restore the previous hwtstamp configuration settings */
3989 e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
3993 * e1000e_reset - bring the hardware into a known good state
3994 * @adapter: board private structure
3996 * This function boots the hardware and enables some settings that
3997 * require a configuration cycle of the hardware - those cannot be
3998 * set/changed during runtime. After reset the device needs to be
3999 * properly configured for Rx, Tx etc.
4001 void e1000e_reset(struct e1000_adapter *adapter)
4003 struct e1000_mac_info *mac = &adapter->hw.mac;
4004 struct e1000_fc_info *fc = &adapter->hw.fc;
4005 struct e1000_hw *hw = &adapter->hw;
4006 u32 tx_space, min_tx_space, min_rx_space;
4007 u32 pba = adapter->pba;
4010 /* reset Packet Buffer Allocation to default */
4013 if (adapter->max_frame_size > (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) {
4014 /* To maintain wire speed transmits, the Tx FIFO should be
4015 * large enough to accommodate two full transmit packets,
4016 * rounded up to the next 1KB and expressed in KB. Likewise,
4017 * the Rx FIFO should be large enough to accommodate at least
4018 * one full receive packet and is similarly rounded up and
4022 /* upper 16 bits has Tx packet buffer allocation size in KB */
4023 tx_space = pba >> 16;
4024 /* lower 16 bits has Rx packet buffer allocation size in KB */
4026 /* the Tx fifo also stores 16 bytes of information about the Tx
4027 * but don't include ethernet FCS because hardware appends it
4029 min_tx_space = (adapter->max_frame_size +
4030 sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
4031 min_tx_space = ALIGN(min_tx_space, 1024);
4032 min_tx_space >>= 10;
4033 /* software strips receive CRC, so leave room for it */
4034 min_rx_space = adapter->max_frame_size;
4035 min_rx_space = ALIGN(min_rx_space, 1024);
4036 min_rx_space >>= 10;
4038 /* If current Tx allocation is less than the min Tx FIFO size,
4039 * and the min Tx FIFO size is less than the current Rx FIFO
4040 * allocation, take space away from current Rx allocation
4042 if ((tx_space < min_tx_space) &&
4043 ((min_tx_space - tx_space) < pba)) {
4044 pba -= min_tx_space - tx_space;
4046 /* if short on Rx space, Rx wins and must trump Tx
4049 if (pba < min_rx_space)
4056 /* flow control settings
4058 * The high water mark must be low enough to fit one full frame
4059 * (or the size used for early receive) above it in the Rx FIFO.
4060 * Set it to the lower of:
4061 * - 90% of the Rx FIFO size, and
4062 * - the full Rx FIFO size minus one full frame
4064 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
4065 fc->pause_time = 0xFFFF;
4067 fc->pause_time = E1000_FC_PAUSE_TIME;
4068 fc->send_xon = true;
4069 fc->current_mode = fc->requested_mode;
4071 switch (hw->mac.type) {
4073 case e1000_ich10lan:
4074 if (adapter->netdev->mtu > ETH_DATA_LEN) {
4077 fc->high_water = 0x2800;
4078 fc->low_water = fc->high_water - 8;
4083 hwm = min(((pba << 10) * 9 / 10),
4084 ((pba << 10) - adapter->max_frame_size));
4086 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
4087 fc->low_water = fc->high_water - 8;
4090 /* Workaround PCH LOM adapter hangs with certain network
4091 * loads. If hangs persist, try disabling Tx flow control.
4093 if (adapter->netdev->mtu > ETH_DATA_LEN) {
4094 fc->high_water = 0x3500;
4095 fc->low_water = 0x1500;
4097 fc->high_water = 0x5000;
4098 fc->low_water = 0x3000;
4100 fc->refresh_time = 0x1000;
4109 fc->refresh_time = 0xFFFF;
4110 fc->pause_time = 0xFFFF;
4112 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
4113 fc->high_water = 0x05C20;
4114 fc->low_water = 0x05048;
4120 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
4121 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
4125 /* Alignment of Tx data is on an arbitrary byte boundary with the
4126 * maximum size per Tx descriptor limited only to the transmit
4127 * allocation of the packet buffer minus 96 bytes with an upper
4128 * limit of 24KB due to receive synchronization limitations.
4130 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
4133 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
4134 * fit in receive buffer.
4136 if (adapter->itr_setting & 0x3) {
4137 if ((adapter->max_frame_size * 2) > (pba << 10)) {
4138 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
4139 dev_info(&adapter->pdev->dev,
4140 "Interrupt Throttle Rate off\n");
4141 adapter->flags2 |= FLAG2_DISABLE_AIM;
4142 e1000e_write_itr(adapter, 0);
4144 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
4145 dev_info(&adapter->pdev->dev,
4146 "Interrupt Throttle Rate on\n");
4147 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
4148 adapter->itr = 20000;
4149 e1000e_write_itr(adapter, adapter->itr);
4153 if (hw->mac.type >= e1000_pch_spt)
4154 e1000_flush_desc_rings(adapter);
4155 /* Allow time for pending master requests to run */
4156 mac->ops.reset_hw(hw);
4158 /* For parts with AMT enabled, let the firmware know
4159 * that the network interface is in control
4161 if (adapter->flags & FLAG_HAS_AMT)
4162 e1000e_get_hw_control(adapter);
4166 if (mac->ops.init_hw(hw))
4167 e_err("Hardware Error\n");
4169 e1000_update_mng_vlan(adapter);
4171 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
4172 ew32(VET, ETH_P_8021Q);
4174 e1000e_reset_adaptive(hw);
4176 /* restore systim and hwtstamp settings */
4177 e1000e_systim_reset(adapter);
4179 /* Set EEE advertisement as appropriate */
4180 if (adapter->flags2 & FLAG2_HAS_EEE) {
4184 switch (hw->phy.type) {
4185 case e1000_phy_82579:
4186 adv_addr = I82579_EEE_ADVERTISEMENT;
4188 case e1000_phy_i217:
4189 adv_addr = I217_EEE_ADVERTISEMENT;
4192 dev_err(&adapter->pdev->dev,
4193 "Invalid PHY type setting EEE advertisement\n");
4197 ret_val = hw->phy.ops.acquire(hw);
4199 dev_err(&adapter->pdev->dev,
4200 "EEE advertisement - unable to acquire PHY\n");
4204 e1000_write_emi_reg_locked(hw, adv_addr,
4205 hw->dev_spec.ich8lan.eee_disable ?
4206 0 : adapter->eee_advert);
4208 hw->phy.ops.release(hw);
4211 if (!netif_running(adapter->netdev) &&
4212 !test_bit(__E1000_TESTING, &adapter->state))
4213 e1000_power_down_phy(adapter);
4215 e1000_get_phy_info(hw);
4217 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
4218 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
4220 /* speed up time to link by disabling smart power down, ignore
4221 * the return value of this function because there is nothing
4222 * different we would do if it failed
4224 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
4225 phy_data &= ~IGP02E1000_PM_SPD;
4226 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
4228 if (hw->mac.type >= e1000_pch_spt && adapter->int_mode == 0) {
4231 /* Fextnvm7 @ 0xe4[2] = 1 */
4232 reg = er32(FEXTNVM7);
4233 reg |= E1000_FEXTNVM7_SIDE_CLK_UNGATE;
4234 ew32(FEXTNVM7, reg);
4235 /* Fextnvm9 @ 0x5bb4[13:12] = 11 */
4236 reg = er32(FEXTNVM9);
4237 reg |= E1000_FEXTNVM9_IOSFSB_CLKGATE_DIS |
4238 E1000_FEXTNVM9_IOSFSB_CLKREQ_DIS;
4239 ew32(FEXTNVM9, reg);
4245 * e1000e_trigger_lsc - trigger an LSC interrupt
4248 * Fire a link status change interrupt to start the watchdog.
4250 static void e1000e_trigger_lsc(struct e1000_adapter *adapter)
4252 struct e1000_hw *hw = &adapter->hw;
4254 if (adapter->msix_entries)
4255 ew32(ICS, E1000_ICS_LSC | E1000_ICS_OTHER);
4257 ew32(ICS, E1000_ICS_LSC);
4260 void e1000e_up(struct e1000_adapter *adapter)
4262 /* hardware has been reset, we need to reload some things */
4263 e1000_configure(adapter);
4265 clear_bit(__E1000_DOWN, &adapter->state);
4267 if (adapter->msix_entries)
4268 e1000_configure_msix(adapter);
4269 e1000_irq_enable(adapter);
4271 /* Tx queue started by watchdog timer when link is up */
4273 e1000e_trigger_lsc(adapter);
4276 static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
4278 struct e1000_hw *hw = &adapter->hw;
4280 if (!(adapter->flags2 & FLAG2_DMA_BURST))
4283 /* flush pending descriptor writebacks to memory */
4284 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4285 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4287 /* execute the writes immediately */
4290 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
4291 * write is successful
4293 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4294 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4296 /* execute the writes immediately */
4300 static void e1000e_update_stats(struct e1000_adapter *adapter);
4303 * e1000e_down - quiesce the device and optionally reset the hardware
4304 * @adapter: board private structure
4305 * @reset: boolean flag to reset the hardware or not
4307 void e1000e_down(struct e1000_adapter *adapter, bool reset)
4309 struct net_device *netdev = adapter->netdev;
4310 struct e1000_hw *hw = &adapter->hw;
4313 /* signal that we're down so the interrupt handler does not
4314 * reschedule our watchdog timer
4316 set_bit(__E1000_DOWN, &adapter->state);
4318 netif_carrier_off(netdev);
4320 /* disable receives in the hardware */
4322 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
4323 ew32(RCTL, rctl & ~E1000_RCTL_EN);
4324 /* flush and sleep below */
4326 netif_stop_queue(netdev);
4328 /* disable transmits in the hardware */
4330 tctl &= ~E1000_TCTL_EN;
4333 /* flush both disables and wait for them to finish */
4335 usleep_range(10000, 11000);
4337 e1000_irq_disable(adapter);
4339 napi_synchronize(&adapter->napi);
4341 del_timer_sync(&adapter->watchdog_timer);
4342 del_timer_sync(&adapter->phy_info_timer);
4344 spin_lock(&adapter->stats64_lock);
4345 e1000e_update_stats(adapter);
4346 spin_unlock(&adapter->stats64_lock);
4348 e1000e_flush_descriptors(adapter);
4350 adapter->link_speed = 0;
4351 adapter->link_duplex = 0;
4353 /* Disable Si errata workaround on PCHx for jumbo frame flow */
4354 if ((hw->mac.type >= e1000_pch2lan) &&
4355 (adapter->netdev->mtu > ETH_DATA_LEN) &&
4356 e1000_lv_jumbo_workaround_ich8lan(hw, false))
4357 e_dbg("failed to disable jumbo frame workaround mode\n");
4359 if (!pci_channel_offline(adapter->pdev)) {
4361 e1000e_reset(adapter);
4362 else if (hw->mac.type >= e1000_pch_spt)
4363 e1000_flush_desc_rings(adapter);
4365 e1000_clean_tx_ring(adapter->tx_ring);
4366 e1000_clean_rx_ring(adapter->rx_ring);
4369 void e1000e_reinit_locked(struct e1000_adapter *adapter)
4372 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4373 usleep_range(1000, 1100);
4374 e1000e_down(adapter, true);
4376 clear_bit(__E1000_RESETTING, &adapter->state);
4380 * e1000e_sanitize_systim - sanitize raw cycle counter reads
4381 * @hw: pointer to the HW structure
4382 * @systim: PHC time value read, sanitized and returned
4383 * @sts: structure to hold system time before and after reading SYSTIML,
4386 * Errata for 82574/82583 possible bad bits read from SYSTIMH/L:
4387 * check to see that the time is incrementing at a reasonable
4388 * rate and is a multiple of incvalue.
4390 static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim,
4391 struct ptp_system_timestamp *sts)
4393 u64 time_delta, rem, temp;
4398 incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
4399 for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
4400 /* latch SYSTIMH on read of SYSTIML */
4401 ptp_read_system_prets(sts);
4402 systim_next = (u64)er32(SYSTIML);
4403 ptp_read_system_postts(sts);
4404 systim_next |= (u64)er32(SYSTIMH) << 32;
4406 time_delta = systim_next - systim;
4408 /* VMWare users have seen incvalue of zero, don't div / 0 */
4409 rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0);
4411 systim = systim_next;
4413 if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0))
4421 * e1000e_read_systim - read SYSTIM register
4422 * @adapter: board private structure
4423 * @sts: structure which will contain system time before and after reading
4424 * SYSTIML, may be NULL
4426 u64 e1000e_read_systim(struct e1000_adapter *adapter,
4427 struct ptp_system_timestamp *sts)
4429 struct e1000_hw *hw = &adapter->hw;
4430 u32 systimel, systimel_2, systimeh;
4432 /* SYSTIMH latching upon SYSTIML read does not work well.
4433 * This means that if SYSTIML overflows after we read it but before
4434 * we read SYSTIMH, the value of SYSTIMH has been incremented and we
4435 * will experience a huge non linear increment in the systime value
4436 * to fix that we test for overflow and if true, we re-read systime.
4438 ptp_read_system_prets(sts);
4439 systimel = er32(SYSTIML);
4440 ptp_read_system_postts(sts);
4441 systimeh = er32(SYSTIMH);
4442 /* Is systimel is so large that overflow is possible? */
4443 if (systimel >= (u32)0xffffffff - E1000_TIMINCA_INCVALUE_MASK) {
4444 ptp_read_system_prets(sts);
4445 systimel_2 = er32(SYSTIML);
4446 ptp_read_system_postts(sts);
4447 if (systimel > systimel_2) {
4448 /* There was an overflow, read again SYSTIMH, and use
4451 systimeh = er32(SYSTIMH);
4452 systimel = systimel_2;
4455 systim = (u64)systimel;
4456 systim |= (u64)systimeh << 32;
4458 if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW)
4459 systim = e1000e_sanitize_systim(hw, systim, sts);
4465 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4466 * @cc: cyclecounter structure
4468 static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc)
4470 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4473 return e1000e_read_systim(adapter, NULL);
4477 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4478 * @adapter: board private structure to initialize
4480 * e1000_sw_init initializes the Adapter private data structure.
4481 * Fields are initialized based on PCI device information and
4482 * OS network device settings (MTU size).
4484 static int e1000_sw_init(struct e1000_adapter *adapter)
4486 struct net_device *netdev = adapter->netdev;
4488 adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
4489 adapter->rx_ps_bsize0 = 128;
4490 adapter->max_frame_size = netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
4491 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
4492 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4493 adapter->rx_ring_count = E1000_DEFAULT_RXD;
4495 spin_lock_init(&adapter->stats64_lock);
4497 e1000e_set_interrupt_capability(adapter);
4499 if (e1000_alloc_queues(adapter))
4502 /* Setup hardware time stamping cyclecounter */
4503 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4504 adapter->cc.read = e1000e_cyclecounter_read;
4505 adapter->cc.mask = CYCLECOUNTER_MASK(64);
4506 adapter->cc.mult = 1;
4507 /* cc.shift set in e1000e_get_base_tininca() */
4509 spin_lock_init(&adapter->systim_lock);
4510 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4513 /* Explicitly disable IRQ since the NIC can be in any state. */
4514 e1000_irq_disable(adapter);
4516 set_bit(__E1000_DOWN, &adapter->state);
4521 * e1000_intr_msi_test - Interrupt Handler
4522 * @irq: interrupt number
4523 * @data: pointer to a network interface device structure
4525 static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
4527 struct net_device *netdev = data;
4528 struct e1000_adapter *adapter = netdev_priv(netdev);
4529 struct e1000_hw *hw = &adapter->hw;
4530 u32 icr = er32(ICR);
4532 e_dbg("icr is %08X\n", icr);
4533 if (icr & E1000_ICR_RXSEQ) {
4534 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
4535 /* Force memory writes to complete before acknowledging the
4536 * interrupt is handled.
4545 * e1000_test_msi_interrupt - Returns 0 for successful test
4546 * @adapter: board private struct
4548 * code flow taken from tg3.c
4550 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4552 struct net_device *netdev = adapter->netdev;
4553 struct e1000_hw *hw = &adapter->hw;
4556 /* poll_enable hasn't been called yet, so don't need disable */
4557 /* clear any pending events */
4560 /* free the real vector and request a test handler */
4561 e1000_free_irq(adapter);
4562 e1000e_reset_interrupt_capability(adapter);
4564 /* Assume that the test fails, if it succeeds then the test
4565 * MSI irq handler will unset this flag
4567 adapter->flags |= FLAG_MSI_TEST_FAILED;
4569 err = pci_enable_msi(adapter->pdev);
4571 goto msi_test_failed;
4573 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
4574 netdev->name, netdev);
4576 pci_disable_msi(adapter->pdev);
4577 goto msi_test_failed;
4580 /* Force memory writes to complete before enabling and firing an
4585 e1000_irq_enable(adapter);
4587 /* fire an unusual interrupt on the test handler */
4588 ew32(ICS, E1000_ICS_RXSEQ);
4592 e1000_irq_disable(adapter);
4594 rmb(); /* read flags after interrupt has been fired */
4596 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
4597 adapter->int_mode = E1000E_INT_MODE_LEGACY;
4598 e_info("MSI interrupt test failed, using legacy interrupt.\n");
4600 e_dbg("MSI interrupt test succeeded!\n");
4603 free_irq(adapter->pdev->irq, netdev);
4604 pci_disable_msi(adapter->pdev);
4607 e1000e_set_interrupt_capability(adapter);
4608 return e1000_request_irq(adapter);
4612 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4613 * @adapter: board private struct
4615 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4617 static int e1000_test_msi(struct e1000_adapter *adapter)
4622 if (!(adapter->flags & FLAG_MSI_ENABLED))
4625 /* disable SERR in case the MSI write causes a master abort */
4626 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4627 if (pci_cmd & PCI_COMMAND_SERR)
4628 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4629 pci_cmd & ~PCI_COMMAND_SERR);
4631 err = e1000_test_msi_interrupt(adapter);
4633 /* re-enable SERR */
4634 if (pci_cmd & PCI_COMMAND_SERR) {
4635 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4636 pci_cmd |= PCI_COMMAND_SERR;
4637 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4644 * e1000e_open - Called when a network interface is made active
4645 * @netdev: network interface device structure
4647 * Returns 0 on success, negative value on failure
4649 * The open entry point is called when a network interface is made
4650 * active by the system (IFF_UP). At this point all resources needed
4651 * for transmit and receive operations are allocated, the interrupt
4652 * handler is registered with the OS, the watchdog timer is started,
4653 * and the stack is notified that the interface is ready.
4655 int e1000e_open(struct net_device *netdev)
4657 struct e1000_adapter *adapter = netdev_priv(netdev);
4658 struct e1000_hw *hw = &adapter->hw;
4659 struct pci_dev *pdev = adapter->pdev;
4662 /* disallow open during test */
4663 if (test_bit(__E1000_TESTING, &adapter->state))
4666 pm_runtime_get_sync(&pdev->dev);
4668 netif_carrier_off(netdev);
4669 netif_stop_queue(netdev);
4671 /* allocate transmit descriptors */
4672 err = e1000e_setup_tx_resources(adapter->tx_ring);
4676 /* allocate receive descriptors */
4677 err = e1000e_setup_rx_resources(adapter->rx_ring);
4681 /* If AMT is enabled, let the firmware know that the network
4682 * interface is now open and reset the part to a known state.
4684 if (adapter->flags & FLAG_HAS_AMT) {
4685 e1000e_get_hw_control(adapter);
4686 e1000e_reset(adapter);
4689 e1000e_power_up_phy(adapter);
4691 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4692 if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4693 e1000_update_mng_vlan(adapter);
4695 /* DMA latency requirement to workaround jumbo issue */
4696 cpu_latency_qos_add_request(&adapter->pm_qos_req, PM_QOS_DEFAULT_VALUE);
4698 /* before we allocate an interrupt, we must be ready to handle it.
4699 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4700 * as soon as we call pci_request_irq, so we have to setup our
4701 * clean_rx handler before we do so.
4703 e1000_configure(adapter);
4705 err = e1000_request_irq(adapter);
4709 /* Work around PCIe errata with MSI interrupts causing some chipsets to
4710 * ignore e1000e MSI messages, which means we need to test our MSI
4713 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
4714 err = e1000_test_msi(adapter);
4716 e_err("Interrupt allocation failed\n");
4721 /* From here on the code is the same as e1000e_up() */
4722 clear_bit(__E1000_DOWN, &adapter->state);
4724 napi_enable(&adapter->napi);
4726 e1000_irq_enable(adapter);
4728 adapter->tx_hang_recheck = false;
4730 hw->mac.get_link_status = true;
4731 pm_runtime_put(&pdev->dev);
4733 e1000e_trigger_lsc(adapter);
4738 cpu_latency_qos_remove_request(&adapter->pm_qos_req);
4739 e1000e_release_hw_control(adapter);
4740 e1000_power_down_phy(adapter);
4741 e1000e_free_rx_resources(adapter->rx_ring);
4743 e1000e_free_tx_resources(adapter->tx_ring);
4745 e1000e_reset(adapter);
4746 pm_runtime_put_sync(&pdev->dev);
4752 * e1000e_close - Disables a network interface
4753 * @netdev: network interface device structure
4755 * Returns 0, this is not allowed to fail
4757 * The close entry point is called when an interface is de-activated
4758 * by the OS. The hardware is still under the drivers control, but
4759 * needs to be disabled. A global MAC reset is issued to stop the
4760 * hardware, and all transmit and receive resources are freed.
4762 int e1000e_close(struct net_device *netdev)
4764 struct e1000_adapter *adapter = netdev_priv(netdev);
4765 struct pci_dev *pdev = adapter->pdev;
4766 int count = E1000_CHECK_RESET_COUNT;
4768 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4769 usleep_range(10000, 11000);
4771 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
4773 pm_runtime_get_sync(&pdev->dev);
4775 if (netif_device_present(netdev)) {
4776 e1000e_down(adapter, true);
4777 e1000_free_irq(adapter);
4779 /* Link status message must follow this format */
4780 netdev_info(netdev, "NIC Link is Down\n");
4783 napi_disable(&adapter->napi);
4785 e1000e_free_tx_resources(adapter->tx_ring);
4786 e1000e_free_rx_resources(adapter->rx_ring);
4788 /* kill manageability vlan ID if supported, but not if a vlan with
4789 * the same ID is registered on the host OS (let 8021q kill it)
4791 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
4792 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
4793 adapter->mng_vlan_id);
4795 /* If AMT is enabled, let the firmware know that the network
4796 * interface is now closed
4798 if ((adapter->flags & FLAG_HAS_AMT) &&
4799 !test_bit(__E1000_TESTING, &adapter->state))
4800 e1000e_release_hw_control(adapter);
4802 cpu_latency_qos_remove_request(&adapter->pm_qos_req);
4804 pm_runtime_put_sync(&pdev->dev);
4810 * e1000_set_mac - Change the Ethernet Address of the NIC
4811 * @netdev: network interface device structure
4812 * @p: pointer to an address structure
4814 * Returns 0 on success, negative on failure
4816 static int e1000_set_mac(struct net_device *netdev, void *p)
4818 struct e1000_adapter *adapter = netdev_priv(netdev);
4819 struct e1000_hw *hw = &adapter->hw;
4820 struct sockaddr *addr = p;
4822 if (!is_valid_ether_addr(addr->sa_data))
4823 return -EADDRNOTAVAIL;
4825 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4826 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4828 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
4830 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4831 /* activate the work around */
4832 e1000e_set_laa_state_82571(&adapter->hw, 1);
4834 /* Hold a copy of the LAA in RAR[14] This is done so that
4835 * between the time RAR[0] gets clobbered and the time it
4836 * gets fixed (in e1000_watchdog), the actual LAA is in one
4837 * of the RARs and no incoming packets directed to this port
4838 * are dropped. Eventually the LAA will be in RAR[0] and
4841 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4842 adapter->hw.mac.rar_entry_count - 1);
4849 * e1000e_update_phy_task - work thread to update phy
4850 * @work: pointer to our work struct
4852 * this worker thread exists because we must acquire a
4853 * semaphore to read the phy, which we could msleep while
4854 * waiting for it, and we can't msleep in a timer.
4856 static void e1000e_update_phy_task(struct work_struct *work)
4858 struct e1000_adapter *adapter = container_of(work,
4859 struct e1000_adapter,
4861 struct e1000_hw *hw = &adapter->hw;
4863 if (test_bit(__E1000_DOWN, &adapter->state))
4866 e1000_get_phy_info(hw);
4868 /* Enable EEE on 82579 after link up */
4869 if (hw->phy.type >= e1000_phy_82579)
4870 e1000_set_eee_pchlan(hw);
4874 * e1000_update_phy_info - timre call-back to update PHY info
4875 * @t: pointer to timer_list containing private info adapter
4877 * Need to wait a few seconds after link up to get diagnostic information from
4880 static void e1000_update_phy_info(struct timer_list *t)
4882 struct e1000_adapter *adapter = from_timer(adapter, t, phy_info_timer);
4884 if (test_bit(__E1000_DOWN, &adapter->state))
4887 schedule_work(&adapter->update_phy_task);
4891 * e1000e_update_phy_stats - Update the PHY statistics counters
4892 * @adapter: board private structure
4894 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
4896 static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4898 struct e1000_hw *hw = &adapter->hw;
4902 ret_val = hw->phy.ops.acquire(hw);
4906 /* A page set is expensive so check if already on desired page.
4907 * If not, set to the page with the PHY status registers.
4910 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4914 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4915 ret_val = hw->phy.ops.set_page(hw,
4916 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4921 /* Single Collision Count */
4922 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4923 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4925 adapter->stats.scc += phy_data;
4927 /* Excessive Collision Count */
4928 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4929 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4931 adapter->stats.ecol += phy_data;
4933 /* Multiple Collision Count */
4934 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4935 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4937 adapter->stats.mcc += phy_data;
4939 /* Late Collision Count */
4940 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4941 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4943 adapter->stats.latecol += phy_data;
4945 /* Collision Count - also used for adaptive IFS */
4946 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4947 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4949 hw->mac.collision_delta = phy_data;
4952 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4953 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4955 adapter->stats.dc += phy_data;
4957 /* Transmit with no CRS */
4958 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4959 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4961 adapter->stats.tncrs += phy_data;
4964 hw->phy.ops.release(hw);
4968 * e1000e_update_stats - Update the board statistics counters
4969 * @adapter: board private structure
4971 static void e1000e_update_stats(struct e1000_adapter *adapter)
4973 struct net_device *netdev = adapter->netdev;
4974 struct e1000_hw *hw = &adapter->hw;
4975 struct pci_dev *pdev = adapter->pdev;
4977 /* Prevent stats update while adapter is being reset, or if the pci
4978 * connection is down.
4980 if (adapter->link_speed == 0)
4982 if (pci_channel_offline(pdev))
4985 adapter->stats.crcerrs += er32(CRCERRS);
4986 adapter->stats.gprc += er32(GPRC);
4987 adapter->stats.gorc += er32(GORCL);
4988 er32(GORCH); /* Clear gorc */
4989 adapter->stats.bprc += er32(BPRC);
4990 adapter->stats.mprc += er32(MPRC);
4991 adapter->stats.roc += er32(ROC);
4993 adapter->stats.mpc += er32(MPC);
4995 /* Half-duplex statistics */
4996 if (adapter->link_duplex == HALF_DUPLEX) {
4997 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4998 e1000e_update_phy_stats(adapter);
5000 adapter->stats.scc += er32(SCC);
5001 adapter->stats.ecol += er32(ECOL);
5002 adapter->stats.mcc += er32(MCC);
5003 adapter->stats.latecol += er32(LATECOL);
5004 adapter->stats.dc += er32(DC);
5006 hw->mac.collision_delta = er32(COLC);
5008 if ((hw->mac.type != e1000_82574) &&
5009 (hw->mac.type != e1000_82583))
5010 adapter->stats.tncrs += er32(TNCRS);
5012 adapter->stats.colc += hw->mac.collision_delta;
5015 adapter->stats.xonrxc += er32(XONRXC);
5016 adapter->stats.xontxc += er32(XONTXC);
5017 adapter->stats.xoffrxc += er32(XOFFRXC);
5018 adapter->stats.xofftxc += er32(XOFFTXC);
5019 adapter->stats.gptc += er32(GPTC);
5020 adapter->stats.gotc += er32(GOTCL);
5021 er32(GOTCH); /* Clear gotc */
5022 adapter->stats.rnbc += er32(RNBC);
5023 adapter->stats.ruc += er32(RUC);
5025 adapter->stats.mptc += er32(MPTC);
5026 adapter->stats.bptc += er32(BPTC);
5028 /* used for adaptive IFS */
5030 hw->mac.tx_packet_delta = er32(TPT);
5031 adapter->stats.tpt += hw->mac.tx_packet_delta;
5033 adapter->stats.algnerrc += er32(ALGNERRC);
5034 adapter->stats.rxerrc += er32(RXERRC);
5035 adapter->stats.cexterr += er32(CEXTERR);
5036 adapter->stats.tsctc += er32(TSCTC);
5037 adapter->stats.tsctfc += er32(TSCTFC);
5039 /* Fill out the OS statistics structure */
5040 netdev->stats.multicast = adapter->stats.mprc;
5041 netdev->stats.collisions = adapter->stats.colc;
5045 /* RLEC on some newer hardware can be incorrect so build
5046 * our own version based on RUC and ROC
5048 netdev->stats.rx_errors = adapter->stats.rxerrc +
5049 adapter->stats.crcerrs + adapter->stats.algnerrc +
5050 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
5051 netdev->stats.rx_length_errors = adapter->stats.ruc +
5053 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
5054 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
5055 netdev->stats.rx_missed_errors = adapter->stats.mpc;
5058 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
5059 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
5060 netdev->stats.tx_window_errors = adapter->stats.latecol;
5061 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
5063 /* Tx Dropped needs to be maintained elsewhere */
5065 /* Management Stats */
5066 adapter->stats.mgptc += er32(MGTPTC);
5067 adapter->stats.mgprc += er32(MGTPRC);
5068 adapter->stats.mgpdc += er32(MGTPDC);
5070 /* Correctable ECC Errors */
5071 if (hw->mac.type >= e1000_pch_lpt) {
5072 u32 pbeccsts = er32(PBECCSTS);
5074 adapter->corr_errors +=
5075 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
5076 adapter->uncorr_errors +=
5077 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
5078 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
5083 * e1000_phy_read_status - Update the PHY register status snapshot
5084 * @adapter: board private structure
5086 static void e1000_phy_read_status(struct e1000_adapter *adapter)
5088 struct e1000_hw *hw = &adapter->hw;
5089 struct e1000_phy_regs *phy = &adapter->phy_regs;
5091 if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
5092 (er32(STATUS) & E1000_STATUS_LU) &&
5093 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
5096 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
5097 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
5098 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
5099 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
5100 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
5101 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
5102 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
5103 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
5105 e_warn("Error reading PHY register\n");
5107 /* Do not read PHY registers if link is not up
5108 * Set values to typical power-on defaults
5110 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
5111 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
5112 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
5114 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
5115 ADVERTISE_ALL | ADVERTISE_CSMA);
5117 phy->expansion = EXPANSION_ENABLENPAGE;
5118 phy->ctrl1000 = ADVERTISE_1000FULL;
5120 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
5124 static void e1000_print_link_info(struct e1000_adapter *adapter)
5126 struct e1000_hw *hw = &adapter->hw;
5127 u32 ctrl = er32(CTRL);
5129 /* Link status message must follow this format for user tools */
5130 netdev_info(adapter->netdev,
5131 "NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
5132 adapter->link_speed,
5133 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
5134 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
5135 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
5136 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
5139 static bool e1000e_has_link(struct e1000_adapter *adapter)
5141 struct e1000_hw *hw = &adapter->hw;
5142 bool link_active = false;
5145 /* get_link_status is set on LSC (link status) interrupt or
5146 * Rx sequence error interrupt. get_link_status will stay
5147 * true until the check_for_link establishes link
5148 * for copper adapters ONLY
5150 switch (hw->phy.media_type) {
5151 case e1000_media_type_copper:
5152 if (hw->mac.get_link_status) {
5153 ret_val = hw->mac.ops.check_for_link(hw);
5154 link_active = !hw->mac.get_link_status;
5159 case e1000_media_type_fiber:
5160 ret_val = hw->mac.ops.check_for_link(hw);
5161 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
5163 case e1000_media_type_internal_serdes:
5164 ret_val = hw->mac.ops.check_for_link(hw);
5165 link_active = hw->mac.serdes_has_link;
5168 case e1000_media_type_unknown:
5172 if ((ret_val == -E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
5173 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
5174 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
5175 e_info("Gigabit has been disabled, downgrading speed\n");
5181 static void e1000e_enable_receives(struct e1000_adapter *adapter)
5183 /* make sure the receive unit is started */
5184 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5185 (adapter->flags & FLAG_RESTART_NOW)) {
5186 struct e1000_hw *hw = &adapter->hw;
5187 u32 rctl = er32(RCTL);
5189 ew32(RCTL, rctl | E1000_RCTL_EN);
5190 adapter->flags &= ~FLAG_RESTART_NOW;
5194 static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
5196 struct e1000_hw *hw = &adapter->hw;
5198 /* With 82574 controllers, PHY needs to be checked periodically
5199 * for hung state and reset, if two calls return true
5201 if (e1000_check_phy_82574(hw))
5202 adapter->phy_hang_count++;
5204 adapter->phy_hang_count = 0;
5206 if (adapter->phy_hang_count > 1) {
5207 adapter->phy_hang_count = 0;
5208 e_dbg("PHY appears hung - resetting\n");
5209 schedule_work(&adapter->reset_task);
5214 * e1000_watchdog - Timer Call-back
5215 * @t: pointer to timer_list containing private info adapter
5217 static void e1000_watchdog(struct timer_list *t)
5219 struct e1000_adapter *adapter = from_timer(adapter, t, watchdog_timer);
5221 /* Do the rest outside of interrupt context */
5222 schedule_work(&adapter->watchdog_task);
5224 /* TODO: make this use queue_delayed_work() */
5227 static void e1000_watchdog_task(struct work_struct *work)
5229 struct e1000_adapter *adapter = container_of(work,
5230 struct e1000_adapter,
5232 struct net_device *netdev = adapter->netdev;
5233 struct e1000_mac_info *mac = &adapter->hw.mac;
5234 struct e1000_phy_info *phy = &adapter->hw.phy;
5235 struct e1000_ring *tx_ring = adapter->tx_ring;
5236 u32 dmoff_exit_timeout = 100, tries = 0;
5237 struct e1000_hw *hw = &adapter->hw;
5238 u32 link, tctl, pcim_state;
5240 if (test_bit(__E1000_DOWN, &adapter->state))
5243 link = e1000e_has_link(adapter);
5244 if ((netif_carrier_ok(netdev)) && link) {
5245 /* Cancel scheduled suspend requests. */
5246 pm_runtime_resume(netdev->dev.parent);
5248 e1000e_enable_receives(adapter);
5252 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
5253 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
5254 e1000_update_mng_vlan(adapter);
5257 if (!netif_carrier_ok(netdev)) {
5260 /* Cancel scheduled suspend requests. */
5261 pm_runtime_resume(netdev->dev.parent);
5263 /* Checking if MAC is in DMoff state*/
5264 pcim_state = er32(STATUS);
5265 while (pcim_state & E1000_STATUS_PCIM_STATE) {
5266 if (tries++ == dmoff_exit_timeout) {
5267 e_dbg("Error in exiting dmoff\n");
5270 usleep_range(10000, 20000);
5271 pcim_state = er32(STATUS);
5273 /* Checking if MAC exited DMoff state */
5274 if (!(pcim_state & E1000_STATUS_PCIM_STATE))
5275 e1000_phy_hw_reset(&adapter->hw);
5278 /* update snapshot of PHY registers on LSC */
5279 e1000_phy_read_status(adapter);
5280 mac->ops.get_link_up_info(&adapter->hw,
5281 &adapter->link_speed,
5282 &adapter->link_duplex);
5283 e1000_print_link_info(adapter);
5285 /* check if SmartSpeed worked */
5286 e1000e_check_downshift(hw);
5287 if (phy->speed_downgraded)
5289 "Link Speed was downgraded by SmartSpeed\n");
5291 /* On supported PHYs, check for duplex mismatch only
5292 * if link has autonegotiated at 10/100 half
5294 if ((hw->phy.type == e1000_phy_igp_3 ||
5295 hw->phy.type == e1000_phy_bm) &&
5297 (adapter->link_speed == SPEED_10 ||
5298 adapter->link_speed == SPEED_100) &&
5299 (adapter->link_duplex == HALF_DUPLEX)) {
5302 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
5304 if (!(autoneg_exp & EXPANSION_NWAY))
5305 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
5308 /* adjust timeout factor according to speed/duplex */
5309 adapter->tx_timeout_factor = 1;
5310 switch (adapter->link_speed) {
5313 adapter->tx_timeout_factor = 16;
5317 adapter->tx_timeout_factor = 10;
5321 /* workaround: re-program speed mode bit after
5324 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
5328 tarc0 = er32(TARC(0));
5329 tarc0 &= ~SPEED_MODE_BIT;
5330 ew32(TARC(0), tarc0);
5333 /* disable TSO for pcie and 10/100 speeds, to avoid
5334 * some hardware issues
5336 if (!(adapter->flags & FLAG_TSO_FORCE)) {
5337 switch (adapter->link_speed) {
5340 e_info("10/100 speed: disabling TSO\n");
5341 netdev->features &= ~NETIF_F_TSO;
5342 netdev->features &= ~NETIF_F_TSO6;
5345 netdev->features |= NETIF_F_TSO;
5346 netdev->features |= NETIF_F_TSO6;
5352 if (hw->mac.type == e1000_pch_spt) {
5353 netdev->features &= ~NETIF_F_TSO;
5354 netdev->features &= ~NETIF_F_TSO6;
5358 /* enable transmits in the hardware, need to do this
5359 * after setting TARC(0)
5362 tctl |= E1000_TCTL_EN;
5365 /* Perform any post-link-up configuration before
5366 * reporting link up.
5368 if (phy->ops.cfg_on_link_up)
5369 phy->ops.cfg_on_link_up(hw);
5371 netif_wake_queue(netdev);
5372 netif_carrier_on(netdev);
5374 if (!test_bit(__E1000_DOWN, &adapter->state))
5375 mod_timer(&adapter->phy_info_timer,
5376 round_jiffies(jiffies + 2 * HZ));
5379 if (netif_carrier_ok(netdev)) {
5380 adapter->link_speed = 0;
5381 adapter->link_duplex = 0;
5382 /* Link status message must follow this format */
5383 netdev_info(netdev, "NIC Link is Down\n");
5384 netif_carrier_off(netdev);
5385 netif_stop_queue(netdev);
5386 if (!test_bit(__E1000_DOWN, &adapter->state))
5387 mod_timer(&adapter->phy_info_timer,
5388 round_jiffies(jiffies + 2 * HZ));
5390 /* 8000ES2LAN requires a Rx packet buffer work-around
5391 * on link down event; reset the controller to flush
5392 * the Rx packet buffer.
5394 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
5395 adapter->flags |= FLAG_RESTART_NOW;
5397 pm_schedule_suspend(netdev->dev.parent,
5403 spin_lock(&adapter->stats64_lock);
5404 e1000e_update_stats(adapter);
5406 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
5407 adapter->tpt_old = adapter->stats.tpt;
5408 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
5409 adapter->colc_old = adapter->stats.colc;
5411 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
5412 adapter->gorc_old = adapter->stats.gorc;
5413 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
5414 adapter->gotc_old = adapter->stats.gotc;
5415 spin_unlock(&adapter->stats64_lock);
5417 /* If the link is lost the controller stops DMA, but
5418 * if there is queued Tx work it cannot be done. So
5419 * reset the controller to flush the Tx packet buffers.
5421 if (!netif_carrier_ok(netdev) &&
5422 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
5423 adapter->flags |= FLAG_RESTART_NOW;
5425 /* If reset is necessary, do it outside of interrupt context. */
5426 if (adapter->flags & FLAG_RESTART_NOW) {
5427 schedule_work(&adapter->reset_task);
5428 /* return immediately since reset is imminent */
5432 e1000e_update_adaptive(&adapter->hw);
5434 /* Simple mode for Interrupt Throttle Rate (ITR) */
5435 if (adapter->itr_setting == 4) {
5436 /* Symmetric Tx/Rx gets a reduced ITR=2000;
5437 * Total asymmetrical Tx or Rx gets ITR=8000;
5438 * everyone else is between 2000-8000.
5440 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
5441 u32 dif = (adapter->gotc > adapter->gorc ?
5442 adapter->gotc - adapter->gorc :
5443 adapter->gorc - adapter->gotc) / 10000;
5444 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
5446 e1000e_write_itr(adapter, itr);
5449 /* Cause software interrupt to ensure Rx ring is cleaned */
5450 if (adapter->msix_entries)
5451 ew32(ICS, adapter->rx_ring->ims_val);
5453 ew32(ICS, E1000_ICS_RXDMT0);
5455 /* flush pending descriptors to memory before detecting Tx hang */
5456 e1000e_flush_descriptors(adapter);
5458 /* Force detection of hung controller every watchdog period */
5459 adapter->detect_tx_hung = true;
5461 /* With 82571 controllers, LAA may be overwritten due to controller
5462 * reset from the other port. Set the appropriate LAA in RAR[0]
5464 if (e1000e_get_laa_state_82571(hw))
5465 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
5467 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5468 e1000e_check_82574_phy_workaround(adapter);
5470 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5471 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5472 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5473 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5475 adapter->rx_hwtstamp_cleared++;
5477 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5481 /* Reset the timer */
5482 if (!test_bit(__E1000_DOWN, &adapter->state))
5483 mod_timer(&adapter->watchdog_timer,
5484 round_jiffies(jiffies + 2 * HZ));
5487 #define E1000_TX_FLAGS_CSUM 0x00000001
5488 #define E1000_TX_FLAGS_VLAN 0x00000002
5489 #define E1000_TX_FLAGS_TSO 0x00000004
5490 #define E1000_TX_FLAGS_IPV4 0x00000008
5491 #define E1000_TX_FLAGS_NO_FCS 0x00000010
5492 #define E1000_TX_FLAGS_HWTSTAMP 0x00000020
5493 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5494 #define E1000_TX_FLAGS_VLAN_SHIFT 16
5496 static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb,
5499 struct e1000_context_desc *context_desc;
5500 struct e1000_buffer *buffer_info;
5504 u8 ipcss, ipcso, tucss, tucso, hdr_len;
5507 if (!skb_is_gso(skb))
5510 err = skb_cow_head(skb, 0);
5514 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5515 mss = skb_shinfo(skb)->gso_size;
5516 if (protocol == htons(ETH_P_IP)) {
5517 struct iphdr *iph = ip_hdr(skb);
5520 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
5522 cmd_length = E1000_TXD_CMD_IP;
5523 ipcse = skb_transport_offset(skb) - 1;
5524 } else if (skb_is_gso_v6(skb)) {
5525 tcp_v6_gso_csum_prep(skb);
5528 ipcss = skb_network_offset(skb);
5529 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5530 tucss = skb_transport_offset(skb);
5531 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
5533 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
5534 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
5536 i = tx_ring->next_to_use;
5537 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5538 buffer_info = &tx_ring->buffer_info[i];
5540 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5541 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5542 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5543 context_desc->upper_setup.tcp_fields.tucss = tucss;
5544 context_desc->upper_setup.tcp_fields.tucso = tucso;
5545 context_desc->upper_setup.tcp_fields.tucse = 0;
5546 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5547 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5548 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5550 buffer_info->time_stamp = jiffies;
5551 buffer_info->next_to_watch = i;
5554 if (i == tx_ring->count)
5556 tx_ring->next_to_use = i;
5561 static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb,
5564 struct e1000_adapter *adapter = tx_ring->adapter;
5565 struct e1000_context_desc *context_desc;
5566 struct e1000_buffer *buffer_info;
5569 u32 cmd_len = E1000_TXD_CMD_DEXT;
5571 if (skb->ip_summed != CHECKSUM_PARTIAL)
5575 case cpu_to_be16(ETH_P_IP):
5576 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5577 cmd_len |= E1000_TXD_CMD_TCP;
5579 case cpu_to_be16(ETH_P_IPV6):
5580 /* XXX not handling all IPV6 headers */
5581 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5582 cmd_len |= E1000_TXD_CMD_TCP;
5585 if (unlikely(net_ratelimit()))
5586 e_warn("checksum_partial proto=%x!\n",
5587 be16_to_cpu(protocol));
5591 css = skb_checksum_start_offset(skb);
5593 i = tx_ring->next_to_use;
5594 buffer_info = &tx_ring->buffer_info[i];
5595 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5597 context_desc->lower_setup.ip_config = 0;
5598 context_desc->upper_setup.tcp_fields.tucss = css;
5599 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
5600 context_desc->upper_setup.tcp_fields.tucse = 0;
5601 context_desc->tcp_seg_setup.data = 0;
5602 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5604 buffer_info->time_stamp = jiffies;
5605 buffer_info->next_to_watch = i;
5608 if (i == tx_ring->count)
5610 tx_ring->next_to_use = i;
5615 static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5616 unsigned int first, unsigned int max_per_txd,
5617 unsigned int nr_frags)
5619 struct e1000_adapter *adapter = tx_ring->adapter;
5620 struct pci_dev *pdev = adapter->pdev;
5621 struct e1000_buffer *buffer_info;
5622 unsigned int len = skb_headlen(skb);
5623 unsigned int offset = 0, size, count = 0, i;
5624 unsigned int f, bytecount, segs;
5626 i = tx_ring->next_to_use;
5629 buffer_info = &tx_ring->buffer_info[i];
5630 size = min(len, max_per_txd);
5632 buffer_info->length = size;
5633 buffer_info->time_stamp = jiffies;
5634 buffer_info->next_to_watch = i;
5635 buffer_info->dma = dma_map_single(&pdev->dev,
5637 size, DMA_TO_DEVICE);
5638 buffer_info->mapped_as_page = false;
5639 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
5648 if (i == tx_ring->count)
5653 for (f = 0; f < nr_frags; f++) {
5654 const skb_frag_t *frag = &skb_shinfo(skb)->frags[f];
5656 len = skb_frag_size(frag);
5661 if (i == tx_ring->count)
5664 buffer_info = &tx_ring->buffer_info[i];
5665 size = min(len, max_per_txd);
5667 buffer_info->length = size;
5668 buffer_info->time_stamp = jiffies;
5669 buffer_info->next_to_watch = i;
5670 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
5673 buffer_info->mapped_as_page = true;
5674 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
5683 segs = skb_shinfo(skb)->gso_segs ? : 1;
5684 /* multiply data chunks by size of headers */
5685 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5687 tx_ring->buffer_info[i].skb = skb;
5688 tx_ring->buffer_info[i].segs = segs;
5689 tx_ring->buffer_info[i].bytecount = bytecount;
5690 tx_ring->buffer_info[first].next_to_watch = i;
5695 dev_err(&pdev->dev, "Tx DMA map failed\n");
5696 buffer_info->dma = 0;
5702 i += tx_ring->count;
5704 buffer_info = &tx_ring->buffer_info[i];
5705 e1000_put_txbuf(tx_ring, buffer_info, true);
5711 static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
5713 struct e1000_adapter *adapter = tx_ring->adapter;
5714 struct e1000_tx_desc *tx_desc = NULL;
5715 struct e1000_buffer *buffer_info;
5716 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5719 if (tx_flags & E1000_TX_FLAGS_TSO) {
5720 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
5722 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5724 if (tx_flags & E1000_TX_FLAGS_IPV4)
5725 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5728 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5729 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5730 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5733 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5734 txd_lower |= E1000_TXD_CMD_VLE;
5735 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5738 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5739 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5741 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5742 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5743 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5746 i = tx_ring->next_to_use;
5749 buffer_info = &tx_ring->buffer_info[i];
5750 tx_desc = E1000_TX_DESC(*tx_ring, i);
5751 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
5752 tx_desc->lower.data = cpu_to_le32(txd_lower |
5753 buffer_info->length);
5754 tx_desc->upper.data = cpu_to_le32(txd_upper);
5757 if (i == tx_ring->count)
5759 } while (--count > 0);
5761 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5763 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5764 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5765 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5767 /* Force memory writes to complete before letting h/w
5768 * know there are new descriptors to fetch. (Only
5769 * applicable for weak-ordered memory model archs,
5774 tx_ring->next_to_use = i;
5777 #define MINIMUM_DHCP_PACKET_SIZE 282
5778 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5779 struct sk_buff *skb)
5781 struct e1000_hw *hw = &adapter->hw;
5784 if (skb_vlan_tag_present(skb) &&
5785 !((skb_vlan_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5786 (adapter->hw.mng_cookie.status &
5787 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5790 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5793 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
5797 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
5800 if (ip->protocol != IPPROTO_UDP)
5803 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5804 if (ntohs(udp->dest) != 67)
5807 offset = (u8 *)udp + 8 - skb->data;
5808 length = skb->len - offset;
5809 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5815 static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
5817 struct e1000_adapter *adapter = tx_ring->adapter;
5819 netif_stop_queue(adapter->netdev);
5820 /* Herbert's original patch had:
5821 * smp_mb__after_netif_stop_queue();
5822 * but since that doesn't exist yet, just open code it.
5826 /* We need to check again in a case another CPU has just
5827 * made room available.
5829 if (e1000_desc_unused(tx_ring) < size)
5833 netif_start_queue(adapter->netdev);
5834 ++adapter->restart_queue;
5838 static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
5840 BUG_ON(size > tx_ring->count);
5842 if (e1000_desc_unused(tx_ring) >= size)
5844 return __e1000_maybe_stop_tx(tx_ring, size);
5847 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5848 struct net_device *netdev)
5850 struct e1000_adapter *adapter = netdev_priv(netdev);
5851 struct e1000_ring *tx_ring = adapter->tx_ring;
5853 unsigned int tx_flags = 0;
5854 unsigned int len = skb_headlen(skb);
5855 unsigned int nr_frags;
5860 __be16 protocol = vlan_get_protocol(skb);
5862 if (test_bit(__E1000_DOWN, &adapter->state)) {
5863 dev_kfree_skb_any(skb);
5864 return NETDEV_TX_OK;
5867 if (skb->len <= 0) {
5868 dev_kfree_skb_any(skb);
5869 return NETDEV_TX_OK;
5872 /* The minimum packet size with TCTL.PSP set is 17 bytes so
5873 * pad skb in order to meet this minimum size requirement
5875 if (skb_put_padto(skb, 17))
5876 return NETDEV_TX_OK;
5878 mss = skb_shinfo(skb)->gso_size;
5882 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
5883 * points to just header, pull a few bytes of payload from
5884 * frags into skb->data
5886 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5887 /* we do this workaround for ES2LAN, but it is un-necessary,
5888 * avoiding it could save a lot of cycles
5890 if (skb->data_len && (hdr_len == len)) {
5891 unsigned int pull_size;
5893 pull_size = min_t(unsigned int, 4, skb->data_len);
5894 if (!__pskb_pull_tail(skb, pull_size)) {
5895 e_err("__pskb_pull_tail failed.\n");
5896 dev_kfree_skb_any(skb);
5897 return NETDEV_TX_OK;
5899 len = skb_headlen(skb);
5903 /* reserve a descriptor for the offload context */
5904 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5908 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
5910 nr_frags = skb_shinfo(skb)->nr_frags;
5911 for (f = 0; f < nr_frags; f++)
5912 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5913 adapter->tx_fifo_limit);
5915 if (adapter->hw.mac.tx_pkt_filtering)
5916 e1000_transfer_dhcp_info(adapter, skb);
5918 /* need: count + 2 desc gap to keep tail from touching
5919 * head, otherwise try next time
5921 if (e1000_maybe_stop_tx(tx_ring, count + 2))
5922 return NETDEV_TX_BUSY;
5924 if (skb_vlan_tag_present(skb)) {
5925 tx_flags |= E1000_TX_FLAGS_VLAN;
5926 tx_flags |= (skb_vlan_tag_get(skb) <<
5927 E1000_TX_FLAGS_VLAN_SHIFT);
5930 first = tx_ring->next_to_use;
5932 tso = e1000_tso(tx_ring, skb, protocol);
5934 dev_kfree_skb_any(skb);
5935 return NETDEV_TX_OK;
5939 tx_flags |= E1000_TX_FLAGS_TSO;
5940 else if (e1000_tx_csum(tx_ring, skb, protocol))
5941 tx_flags |= E1000_TX_FLAGS_CSUM;
5943 /* Old method was to assume IPv4 packet by default if TSO was enabled.
5944 * 82571 hardware supports TSO capabilities for IPv6 as well...
5945 * no longer assume, we must.
5947 if (protocol == htons(ETH_P_IP))
5948 tx_flags |= E1000_TX_FLAGS_IPV4;
5950 if (unlikely(skb->no_fcs))
5951 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5953 /* if count is 0 then mapping error has occurred */
5954 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5957 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5958 (adapter->flags & FLAG_HAS_HW_TIMESTAMP)) {
5959 if (!adapter->tx_hwtstamp_skb) {
5960 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5961 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5962 adapter->tx_hwtstamp_skb = skb_get(skb);
5963 adapter->tx_hwtstamp_start = jiffies;
5964 schedule_work(&adapter->tx_hwtstamp_work);
5966 adapter->tx_hwtstamp_skipped++;
5970 skb_tx_timestamp(skb);
5972 netdev_sent_queue(netdev, skb->len);
5973 e1000_tx_queue(tx_ring, tx_flags, count);
5974 /* Make sure there is space in the ring for the next send. */
5975 e1000_maybe_stop_tx(tx_ring,
5977 DIV_ROUND_UP(PAGE_SIZE,
5978 adapter->tx_fifo_limit) + 2));
5980 if (!netdev_xmit_more() ||
5981 netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) {
5982 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
5983 e1000e_update_tdt_wa(tx_ring,
5984 tx_ring->next_to_use);
5986 writel(tx_ring->next_to_use, tx_ring->tail);
5989 dev_kfree_skb_any(skb);
5990 tx_ring->buffer_info[first].time_stamp = 0;
5991 tx_ring->next_to_use = first;
5994 return NETDEV_TX_OK;
5998 * e1000_tx_timeout - Respond to a Tx Hang
5999 * @netdev: network interface device structure
6000 * @txqueue: index of the hung queue (unused)
6002 static void e1000_tx_timeout(struct net_device *netdev, unsigned int __always_unused txqueue)
6004 struct e1000_adapter *adapter = netdev_priv(netdev);
6006 /* Do the reset outside of interrupt context */
6007 adapter->tx_timeout_count++;
6008 schedule_work(&adapter->reset_task);
6011 static void e1000_reset_task(struct work_struct *work)
6013 struct e1000_adapter *adapter;
6014 adapter = container_of(work, struct e1000_adapter, reset_task);
6016 /* don't run the task if already down */
6017 if (test_bit(__E1000_DOWN, &adapter->state))
6020 if (!(adapter->flags & FLAG_RESTART_NOW)) {
6021 e1000e_dump(adapter);
6022 e_err("Reset adapter unexpectedly\n");
6024 e1000e_reinit_locked(adapter);
6028 * e1000_get_stats64 - Get System Network Statistics
6029 * @netdev: network interface device structure
6030 * @stats: rtnl_link_stats64 pointer
6032 * Returns the address of the device statistics structure.
6034 void e1000e_get_stats64(struct net_device *netdev,
6035 struct rtnl_link_stats64 *stats)
6037 struct e1000_adapter *adapter = netdev_priv(netdev);
6039 spin_lock(&adapter->stats64_lock);
6040 e1000e_update_stats(adapter);
6041 /* Fill out the OS statistics structure */
6042 stats->rx_bytes = adapter->stats.gorc;
6043 stats->rx_packets = adapter->stats.gprc;
6044 stats->tx_bytes = adapter->stats.gotc;
6045 stats->tx_packets = adapter->stats.gptc;
6046 stats->multicast = adapter->stats.mprc;
6047 stats->collisions = adapter->stats.colc;
6051 /* RLEC on some newer hardware can be incorrect so build
6052 * our own version based on RUC and ROC
6054 stats->rx_errors = adapter->stats.rxerrc +
6055 adapter->stats.crcerrs + adapter->stats.algnerrc +
6056 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
6057 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
6058 stats->rx_crc_errors = adapter->stats.crcerrs;
6059 stats->rx_frame_errors = adapter->stats.algnerrc;
6060 stats->rx_missed_errors = adapter->stats.mpc;
6063 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
6064 stats->tx_aborted_errors = adapter->stats.ecol;
6065 stats->tx_window_errors = adapter->stats.latecol;
6066 stats->tx_carrier_errors = adapter->stats.tncrs;
6068 /* Tx Dropped needs to be maintained elsewhere */
6070 spin_unlock(&adapter->stats64_lock);
6074 * e1000_change_mtu - Change the Maximum Transfer Unit
6075 * @netdev: network interface device structure
6076 * @new_mtu: new value for maximum frame size
6078 * Returns 0 on success, negative on failure
6080 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
6082 struct e1000_adapter *adapter = netdev_priv(netdev);
6083 int max_frame = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
6085 /* Jumbo frame support */
6086 if ((new_mtu > ETH_DATA_LEN) &&
6087 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
6088 e_err("Jumbo Frames not supported.\n");
6092 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
6093 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
6094 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
6095 (new_mtu > ETH_DATA_LEN)) {
6096 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
6100 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
6101 usleep_range(1000, 1100);
6102 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
6103 adapter->max_frame_size = max_frame;
6104 netdev_dbg(netdev, "changing MTU from %d to %d\n",
6105 netdev->mtu, new_mtu);
6106 netdev->mtu = new_mtu;
6108 pm_runtime_get_sync(netdev->dev.parent);
6110 if (netif_running(netdev))
6111 e1000e_down(adapter, true);
6113 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
6114 * means we reserve 2 more, this pushes us to allocate from the next
6116 * i.e. RXBUFFER_2048 --> size-4096 slab
6117 * However with the new *_jumbo_rx* routines, jumbo receives will use
6121 if (max_frame <= 2048)
6122 adapter->rx_buffer_len = 2048;
6124 adapter->rx_buffer_len = 4096;
6126 /* adjust allocation if LPE protects us, and we aren't using SBP */
6127 if (max_frame <= (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN))
6128 adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
6130 if (netif_running(netdev))
6133 e1000e_reset(adapter);
6135 pm_runtime_put_sync(netdev->dev.parent);
6137 clear_bit(__E1000_RESETTING, &adapter->state);
6142 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
6145 struct e1000_adapter *adapter = netdev_priv(netdev);
6146 struct mii_ioctl_data *data = if_mii(ifr);
6148 if (adapter->hw.phy.media_type != e1000_media_type_copper)
6153 data->phy_id = adapter->hw.phy.addr;
6156 e1000_phy_read_status(adapter);
6158 switch (data->reg_num & 0x1F) {
6160 data->val_out = adapter->phy_regs.bmcr;
6163 data->val_out = adapter->phy_regs.bmsr;
6166 data->val_out = (adapter->hw.phy.id >> 16);
6169 data->val_out = (adapter->hw.phy.id & 0xFFFF);
6172 data->val_out = adapter->phy_regs.advertise;
6175 data->val_out = adapter->phy_regs.lpa;
6178 data->val_out = adapter->phy_regs.expansion;
6181 data->val_out = adapter->phy_regs.ctrl1000;
6184 data->val_out = adapter->phy_regs.stat1000;
6187 data->val_out = adapter->phy_regs.estatus;
6201 * e1000e_hwtstamp_ioctl - control hardware time stamping
6202 * @netdev: network interface device structure
6203 * @ifr: interface request
6205 * Outgoing time stamping can be enabled and disabled. Play nice and
6206 * disable it when requested, although it shouldn't cause any overhead
6207 * when no packet needs it. At most one packet in the queue may be
6208 * marked for time stamping, otherwise it would be impossible to tell
6209 * for sure to which packet the hardware time stamp belongs.
6211 * Incoming time stamping has to be configured via the hardware filters.
6212 * Not all combinations are supported, in particular event type has to be
6213 * specified. Matching the kind of event packet is not supported, with the
6214 * exception of "all V2 events regardless of level 2 or 4".
6216 static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
6218 struct e1000_adapter *adapter = netdev_priv(netdev);
6219 struct hwtstamp_config config;
6222 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
6225 ret_val = e1000e_config_hwtstamp(adapter, &config);
6229 switch (config.rx_filter) {
6230 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6231 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6232 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6233 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6234 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6235 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
6236 /* With V2 type filters which specify a Sync or Delay Request,
6237 * Path Delay Request/Response messages are also time stamped
6238 * by hardware so notify the caller the requested packets plus
6239 * some others are time stamped.
6241 config.rx_filter = HWTSTAMP_FILTER_SOME;
6247 return copy_to_user(ifr->ifr_data, &config,
6248 sizeof(config)) ? -EFAULT : 0;
6251 static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
6253 struct e1000_adapter *adapter = netdev_priv(netdev);
6255 return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
6256 sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
6259 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6265 return e1000_mii_ioctl(netdev, ifr, cmd);
6267 return e1000e_hwtstamp_set(netdev, ifr);
6269 return e1000e_hwtstamp_get(netdev, ifr);
6275 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
6277 struct e1000_hw *hw = &adapter->hw;
6278 u32 i, mac_reg, wuc;
6279 u16 phy_reg, wuc_enable;
6282 /* copy MAC RARs to PHY RARs */
6283 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
6285 retval = hw->phy.ops.acquire(hw);
6287 e_err("Could not acquire PHY\n");
6291 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
6292 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
6296 /* copy MAC MTA to PHY MTA - only needed for pchlan */
6297 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
6298 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
6299 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
6300 (u16)(mac_reg & 0xFFFF));
6301 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
6302 (u16)((mac_reg >> 16) & 0xFFFF));
6305 /* configure PHY Rx Control register */
6306 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
6307 mac_reg = er32(RCTL);
6308 if (mac_reg & E1000_RCTL_UPE)
6309 phy_reg |= BM_RCTL_UPE;
6310 if (mac_reg & E1000_RCTL_MPE)
6311 phy_reg |= BM_RCTL_MPE;
6312 phy_reg &= ~(BM_RCTL_MO_MASK);
6313 if (mac_reg & E1000_RCTL_MO_3)
6314 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
6315 << BM_RCTL_MO_SHIFT);
6316 if (mac_reg & E1000_RCTL_BAM)
6317 phy_reg |= BM_RCTL_BAM;
6318 if (mac_reg & E1000_RCTL_PMCF)
6319 phy_reg |= BM_RCTL_PMCF;
6320 mac_reg = er32(CTRL);
6321 if (mac_reg & E1000_CTRL_RFCE)
6322 phy_reg |= BM_RCTL_RFCE;
6323 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
6325 wuc = E1000_WUC_PME_EN;
6326 if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
6327 wuc |= E1000_WUC_APME;
6329 /* enable PHY wakeup in MAC register */
6331 ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
6332 E1000_WUC_PME_STATUS | wuc));
6334 /* configure and enable PHY wakeup in PHY registers */
6335 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
6336 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
6338 /* activate PHY wakeup */
6339 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
6340 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
6342 e_err("Could not set PHY Host Wakeup bit\n");
6344 hw->phy.ops.release(hw);
6349 static void e1000e_flush_lpic(struct pci_dev *pdev)
6351 struct net_device *netdev = pci_get_drvdata(pdev);
6352 struct e1000_adapter *adapter = netdev_priv(netdev);
6353 struct e1000_hw *hw = &adapter->hw;
6356 pm_runtime_get_sync(netdev->dev.parent);
6358 ret_val = hw->phy.ops.acquire(hw);
6362 pr_info("EEE TX LPI TIMER: %08X\n",
6363 er32(LPIC) >> E1000_LPIC_LPIET_SHIFT);
6365 hw->phy.ops.release(hw);
6368 pm_runtime_put_sync(netdev->dev.parent);
6371 /* S0ix implementation */
6372 static void e1000e_s0ix_entry_flow(struct e1000_adapter *adapter)
6374 struct e1000_hw *hw = &adapter->hw;
6378 /* Disable the periodic inband message,
6379 * don't request PCIe clock in K1 page770_17[10:9] = 10b
6381 e1e_rphy(hw, HV_PM_CTRL, &phy_data);
6382 phy_data &= ~HV_PM_CTRL_K1_CLK_REQ;
6383 phy_data |= BIT(10);
6384 e1e_wphy(hw, HV_PM_CTRL, phy_data);
6386 /* Make sure we don't exit K1 every time a new packet arrives
6387 * 772_29[5] = 1 CS_Mode_Stay_In_K1
6389 e1e_rphy(hw, I217_CGFREG, &phy_data);
6391 e1e_wphy(hw, I217_CGFREG, phy_data);
6393 /* Change the MAC/PHY interface to SMBus
6394 * Force the SMBus in PHY page769_23[0] = 1
6395 * Force the SMBus in MAC CTRL_EXT[11] = 1
6397 e1e_rphy(hw, CV_SMB_CTRL, &phy_data);
6398 phy_data |= CV_SMB_CTRL_FORCE_SMBUS;
6399 e1e_wphy(hw, CV_SMB_CTRL, phy_data);
6400 mac_data = er32(CTRL_EXT);
6401 mac_data |= E1000_CTRL_EXT_FORCE_SMBUS;
6402 ew32(CTRL_EXT, mac_data);
6404 /* DFT control: PHY bit: page769_20[0] = 1
6405 * Gate PPW via EXTCNF_CTRL - set 0x0F00[7] = 1
6407 e1e_rphy(hw, I82579_DFT_CTRL, &phy_data);
6409 e1e_wphy(hw, I82579_DFT_CTRL, phy_data);
6411 mac_data = er32(EXTCNF_CTRL);
6412 mac_data |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
6413 ew32(EXTCNF_CTRL, mac_data);
6415 /* Check MAC Tx/Rx packet buffer pointers.
6416 * Reset MAC Tx/Rx packet buffer pointers to suppress any
6417 * pending traffic indication that would prevent power gating.
6419 mac_data = er32(TDFH);
6422 mac_data = er32(TDFT);
6425 mac_data = er32(TDFHS);
6428 mac_data = er32(TDFTS);
6431 mac_data = er32(TDFPC);
6434 mac_data = er32(RDFH);
6437 mac_data = er32(RDFT);
6440 mac_data = er32(RDFHS);
6443 mac_data = er32(RDFTS);
6446 mac_data = er32(RDFPC);
6450 /* Enable the Dynamic Power Gating in the MAC */
6451 mac_data = er32(FEXTNVM7);
6452 mac_data |= BIT(22);
6453 ew32(FEXTNVM7, mac_data);
6455 /* Disable the time synchronization clock */
6456 mac_data = er32(FEXTNVM7);
6457 mac_data |= BIT(31);
6458 mac_data &= ~BIT(0);
6459 ew32(FEXTNVM7, mac_data);
6461 /* Dynamic Power Gating Enable */
6462 mac_data = er32(CTRL_EXT);
6464 ew32(CTRL_EXT, mac_data);
6466 /* Disable disconnected cable conditioning for Power Gating */
6467 mac_data = er32(DPGFR);
6469 ew32(DPGFR, mac_data);
6471 /* Don't wake from dynamic Power Gating with clock request */
6472 mac_data = er32(FEXTNVM12);
6473 mac_data |= BIT(12);
6474 ew32(FEXTNVM12, mac_data);
6476 /* Ungate PGCB clock */
6477 mac_data = er32(FEXTNVM9);
6478 mac_data &= ~BIT(28);
6479 ew32(FEXTNVM9, mac_data);
6481 /* Enable K1 off to enable mPHY Power Gating */
6482 mac_data = er32(FEXTNVM6);
6483 mac_data |= BIT(31);
6484 ew32(FEXTNVM6, mac_data);
6486 /* Enable mPHY power gating for any link and speed */
6487 mac_data = er32(FEXTNVM8);
6489 ew32(FEXTNVM8, mac_data);
6491 /* Enable the Dynamic Clock Gating in the DMA and MAC */
6492 mac_data = er32(CTRL_EXT);
6493 mac_data |= E1000_CTRL_EXT_DMA_DYN_CLK_EN;
6494 ew32(CTRL_EXT, mac_data);
6496 /* No MAC DPG gating SLP_S0 in modern standby
6497 * Switch the logic of the lanphypc to use PMC counter
6499 mac_data = er32(FEXTNVM5);
6501 ew32(FEXTNVM5, mac_data);
6504 static void e1000e_s0ix_exit_flow(struct e1000_adapter *adapter)
6506 struct e1000_hw *hw = &adapter->hw;
6510 /* Disable the Dynamic Power Gating in the MAC */
6511 mac_data = er32(FEXTNVM7);
6512 mac_data &= 0xFFBFFFFF;
6513 ew32(FEXTNVM7, mac_data);
6515 /* Enable the time synchronization clock */
6516 mac_data = er32(FEXTNVM7);
6518 ew32(FEXTNVM7, mac_data);
6520 /* Disable mPHY power gating for any link and speed */
6521 mac_data = er32(FEXTNVM8);
6522 mac_data &= ~BIT(9);
6523 ew32(FEXTNVM8, mac_data);
6525 /* Disable K1 off */
6526 mac_data = er32(FEXTNVM6);
6527 mac_data &= ~BIT(31);
6528 ew32(FEXTNVM6, mac_data);
6530 /* Disable Ungate PGCB clock */
6531 mac_data = er32(FEXTNVM9);
6532 mac_data |= BIT(28);
6533 ew32(FEXTNVM9, mac_data);
6535 /* Cancel not waking from dynamic
6536 * Power Gating with clock request
6538 mac_data = er32(FEXTNVM12);
6539 mac_data &= ~BIT(12);
6540 ew32(FEXTNVM12, mac_data);
6542 /* Cancel disable disconnected cable conditioning
6545 mac_data = er32(DPGFR);
6546 mac_data &= ~BIT(2);
6547 ew32(DPGFR, mac_data);
6549 /* Disable Dynamic Power Gating */
6550 mac_data = er32(CTRL_EXT);
6551 mac_data &= 0xFFFFFFF7;
6552 ew32(CTRL_EXT, mac_data);
6554 /* Disable the Dynamic Clock Gating in the DMA and MAC */
6555 mac_data = er32(CTRL_EXT);
6556 mac_data &= 0xFFF7FFFF;
6557 ew32(CTRL_EXT, mac_data);
6559 /* Revert the lanphypc logic to use the internal Gbe counter
6560 * and not the PMC counter
6562 mac_data = er32(FEXTNVM5);
6563 mac_data &= 0xFFFFFF7F;
6564 ew32(FEXTNVM5, mac_data);
6566 /* Enable the periodic inband message,
6567 * Request PCIe clock in K1 page770_17[10:9] =01b
6569 e1e_rphy(hw, HV_PM_CTRL, &phy_data);
6571 phy_data |= HV_PM_CTRL_K1_CLK_REQ;
6572 e1e_wphy(hw, HV_PM_CTRL, phy_data);
6574 /* Return back configuration
6575 * 772_29[5] = 0 CS_Mode_Stay_In_K1
6577 e1e_rphy(hw, I217_CGFREG, &phy_data);
6579 e1e_wphy(hw, I217_CGFREG, phy_data);
6581 /* Change the MAC/PHY interface to Kumeran
6582 * Unforce the SMBus in PHY page769_23[0] = 0
6583 * Unforce the SMBus in MAC CTRL_EXT[11] = 0
6585 e1e_rphy(hw, CV_SMB_CTRL, &phy_data);
6586 phy_data &= ~CV_SMB_CTRL_FORCE_SMBUS;
6587 e1e_wphy(hw, CV_SMB_CTRL, phy_data);
6588 mac_data = er32(CTRL_EXT);
6589 mac_data &= ~E1000_CTRL_EXT_FORCE_SMBUS;
6590 ew32(CTRL_EXT, mac_data);
6593 static int e1000e_pm_freeze(struct device *dev)
6595 struct net_device *netdev = dev_get_drvdata(dev);
6596 struct e1000_adapter *adapter = netdev_priv(netdev);
6601 present = netif_device_present(netdev);
6602 netif_device_detach(netdev);
6604 if (present && netif_running(netdev)) {
6605 int count = E1000_CHECK_RESET_COUNT;
6607 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
6608 usleep_range(10000, 11000);
6610 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
6612 /* Quiesce the device without resetting the hardware */
6613 e1000e_down(adapter, false);
6614 e1000_free_irq(adapter);
6618 e1000e_reset_interrupt_capability(adapter);
6620 /* Allow time for pending master requests to run */
6621 e1000e_disable_pcie_master(&adapter->hw);
6626 static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
6628 struct net_device *netdev = pci_get_drvdata(pdev);
6629 struct e1000_adapter *adapter = netdev_priv(netdev);
6630 struct e1000_hw *hw = &adapter->hw;
6631 u32 ctrl, ctrl_ext, rctl, status, wufc;
6634 /* Runtime suspend should only enable wakeup for link changes */
6636 wufc = E1000_WUFC_LNKC;
6637 else if (device_may_wakeup(&pdev->dev))
6638 wufc = adapter->wol;
6642 status = er32(STATUS);
6643 if (status & E1000_STATUS_LU)
6644 wufc &= ~E1000_WUFC_LNKC;
6647 e1000_setup_rctl(adapter);
6648 e1000e_set_rx_mode(netdev);
6650 /* turn on all-multi mode if wake on multicast is enabled */
6651 if (wufc & E1000_WUFC_MC) {
6653 rctl |= E1000_RCTL_MPE;
6658 ctrl |= E1000_CTRL_ADVD3WUC;
6659 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
6660 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
6663 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
6664 adapter->hw.phy.media_type ==
6665 e1000_media_type_internal_serdes) {
6666 /* keep the laser running in D3 */
6667 ctrl_ext = er32(CTRL_EXT);
6668 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
6669 ew32(CTRL_EXT, ctrl_ext);
6673 e1000e_power_up_phy(adapter);
6675 if (adapter->flags & FLAG_IS_ICH)
6676 e1000_suspend_workarounds_ich8lan(&adapter->hw);
6678 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6679 /* enable wakeup by the PHY */
6680 retval = e1000_init_phy_wakeup(adapter, wufc);
6684 /* enable wakeup by the MAC */
6686 ew32(WUC, E1000_WUC_PME_EN);
6692 e1000_power_down_phy(adapter);
6695 if (adapter->hw.phy.type == e1000_phy_igp_3) {
6696 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
6697 } else if (hw->mac.type >= e1000_pch_lpt) {
6698 if (wufc && !(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
6699 /* ULP does not support wake from unicast, multicast
6702 retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
6708 /* Ensure that the appropriate bits are set in LPI_CTRL
6711 if ((hw->phy.type >= e1000_phy_i217) &&
6712 adapter->eee_advert && hw->dev_spec.ich8lan.eee_lp_ability) {
6715 retval = hw->phy.ops.acquire(hw);
6717 retval = e1e_rphy_locked(hw, I82579_LPI_CTRL,
6720 if (adapter->eee_advert &
6721 hw->dev_spec.ich8lan.eee_lp_ability &
6722 I82579_EEE_100_SUPPORTED)
6723 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
6724 if (adapter->eee_advert &
6725 hw->dev_spec.ich8lan.eee_lp_ability &
6726 I82579_EEE_1000_SUPPORTED)
6727 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
6729 retval = e1e_wphy_locked(hw, I82579_LPI_CTRL,
6733 hw->phy.ops.release(hw);
6736 /* Release control of h/w to f/w. If f/w is AMT enabled, this
6737 * would have already happened in close and is redundant.
6739 e1000e_release_hw_control(adapter);
6741 pci_clear_master(pdev);
6743 /* The pci-e switch on some quad port adapters will report a
6744 * correctable error when the MAC transitions from D0 to D3. To
6745 * prevent this we need to mask off the correctable errors on the
6746 * downstream port of the pci-e switch.
6748 * We don't have the associated upstream bridge while assigning
6749 * the PCI device into guest. For example, the KVM on power is
6752 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6753 struct pci_dev *us_dev = pdev->bus->self;
6759 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6760 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6761 (devctl & ~PCI_EXP_DEVCTL_CERE));
6763 pci_save_state(pdev);
6764 pci_prepare_to_sleep(pdev);
6766 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
6773 * __e1000e_disable_aspm - Disable ASPM states
6774 * @pdev: pointer to PCI device struct
6775 * @state: bit-mask of ASPM states to disable
6776 * @locked: indication if this context holds pci_bus_sem locked.
6778 * Some devices *must* have certain ASPM states disabled per hardware errata.
6780 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state, int locked)
6782 struct pci_dev *parent = pdev->bus->self;
6783 u16 aspm_dis_mask = 0;
6784 u16 pdev_aspmc, parent_aspmc;
6787 case PCIE_LINK_STATE_L0S:
6788 case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
6789 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
6790 fallthrough; /* can't have L1 without L0s */
6791 case PCIE_LINK_STATE_L1:
6792 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
6798 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6799 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6802 pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
6804 parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6807 /* Nothing to do if the ASPM states to be disabled already are */
6808 if (!(pdev_aspmc & aspm_dis_mask) &&
6809 (!parent || !(parent_aspmc & aspm_dis_mask)))
6812 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6813 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
6815 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
6818 #ifdef CONFIG_PCIEASPM
6820 pci_disable_link_state_locked(pdev, state);
6822 pci_disable_link_state(pdev, state);
6824 /* Double-check ASPM control. If not disabled by the above, the
6825 * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
6826 * not enabled); override by writing PCI config space directly.
6828 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6829 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6831 if (!(aspm_dis_mask & pdev_aspmc))
6835 /* Both device and parent should have the same ASPM setting.
6836 * Disable ASPM in downstream component first and then upstream.
6838 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
6841 pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
6846 * e1000e_disable_aspm - Disable ASPM states.
6847 * @pdev: pointer to PCI device struct
6848 * @state: bit-mask of ASPM states to disable
6850 * This function acquires the pci_bus_sem!
6851 * Some devices *must* have certain ASPM states disabled per hardware errata.
6853 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6855 __e1000e_disable_aspm(pdev, state, 0);
6859 * e1000e_disable_aspm_locked Disable ASPM states.
6860 * @pdev: pointer to PCI device struct
6861 * @state: bit-mask of ASPM states to disable
6863 * This function must be called with pci_bus_sem acquired!
6864 * Some devices *must* have certain ASPM states disabled per hardware errata.
6866 static void e1000e_disable_aspm_locked(struct pci_dev *pdev, u16 state)
6868 __e1000e_disable_aspm(pdev, state, 1);
6871 static int e1000e_pm_thaw(struct device *dev)
6873 struct net_device *netdev = dev_get_drvdata(dev);
6874 struct e1000_adapter *adapter = netdev_priv(netdev);
6877 e1000e_set_interrupt_capability(adapter);
6880 if (netif_running(netdev)) {
6881 rc = e1000_request_irq(adapter);
6888 netif_device_attach(netdev);
6895 static int __e1000_resume(struct pci_dev *pdev)
6897 struct net_device *netdev = pci_get_drvdata(pdev);
6898 struct e1000_adapter *adapter = netdev_priv(netdev);
6899 struct e1000_hw *hw = &adapter->hw;
6900 u16 aspm_disable_flag = 0;
6902 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6903 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6904 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6905 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6906 if (aspm_disable_flag)
6907 e1000e_disable_aspm(pdev, aspm_disable_flag);
6909 pci_set_master(pdev);
6911 if (hw->mac.type >= e1000_pch2lan)
6912 e1000_resume_workarounds_pchlan(&adapter->hw);
6914 e1000e_power_up_phy(adapter);
6916 /* report the system wakeup cause from S3/S4 */
6917 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6920 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6922 e_info("PHY Wakeup cause - %s\n",
6923 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6924 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6925 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6926 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6927 phy_data & E1000_WUS_LNKC ?
6928 "Link Status Change" : "other");
6930 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6932 u32 wus = er32(WUS);
6935 e_info("MAC Wakeup cause - %s\n",
6936 wus & E1000_WUS_EX ? "Unicast Packet" :
6937 wus & E1000_WUS_MC ? "Multicast Packet" :
6938 wus & E1000_WUS_BC ? "Broadcast Packet" :
6939 wus & E1000_WUS_MAG ? "Magic Packet" :
6940 wus & E1000_WUS_LNKC ? "Link Status Change" :
6946 e1000e_reset(adapter);
6948 e1000_init_manageability_pt(adapter);
6950 /* If the controller has AMT, do not set DRV_LOAD until the interface
6951 * is up. For all other cases, let the f/w know that the h/w is now
6952 * under the control of the driver.
6954 if (!(adapter->flags & FLAG_HAS_AMT))
6955 e1000e_get_hw_control(adapter);
6960 static __maybe_unused int e1000e_pm_suspend(struct device *dev)
6962 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
6963 struct e1000_adapter *adapter = netdev_priv(netdev);
6964 struct pci_dev *pdev = to_pci_dev(dev);
6965 struct e1000_hw *hw = &adapter->hw;
6968 e1000e_flush_lpic(pdev);
6970 e1000e_pm_freeze(dev);
6972 rc = __e1000_shutdown(pdev, false);
6974 e1000e_pm_thaw(dev);
6976 /* Introduce S0ix implementation */
6977 if (hw->mac.type >= e1000_pch_cnp &&
6978 !e1000e_check_me(hw->adapter->pdev->device))
6979 e1000e_s0ix_entry_flow(adapter);
6984 static __maybe_unused int e1000e_pm_resume(struct device *dev)
6986 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
6987 struct e1000_adapter *adapter = netdev_priv(netdev);
6988 struct pci_dev *pdev = to_pci_dev(dev);
6989 struct e1000_hw *hw = &adapter->hw;
6992 /* Introduce S0ix implementation */
6993 if (hw->mac.type >= e1000_pch_cnp &&
6994 !e1000e_check_me(hw->adapter->pdev->device))
6995 e1000e_s0ix_exit_flow(adapter);
6997 rc = __e1000_resume(pdev);
7001 return e1000e_pm_thaw(dev);
7004 static __maybe_unused int e1000e_pm_runtime_idle(struct device *dev)
7006 struct net_device *netdev = dev_get_drvdata(dev);
7007 struct e1000_adapter *adapter = netdev_priv(netdev);
7010 eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability;
7012 if (!e1000e_has_link(adapter)) {
7013 adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp;
7014 pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
7020 static __maybe_unused int e1000e_pm_runtime_resume(struct device *dev)
7022 struct pci_dev *pdev = to_pci_dev(dev);
7023 struct net_device *netdev = pci_get_drvdata(pdev);
7024 struct e1000_adapter *adapter = netdev_priv(netdev);
7027 rc = __e1000_resume(pdev);
7031 if (netdev->flags & IFF_UP)
7037 static __maybe_unused int e1000e_pm_runtime_suspend(struct device *dev)
7039 struct pci_dev *pdev = to_pci_dev(dev);
7040 struct net_device *netdev = pci_get_drvdata(pdev);
7041 struct e1000_adapter *adapter = netdev_priv(netdev);
7043 if (netdev->flags & IFF_UP) {
7044 int count = E1000_CHECK_RESET_COUNT;
7046 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
7047 usleep_range(10000, 11000);
7049 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
7051 /* Down the device without resetting the hardware */
7052 e1000e_down(adapter, false);
7055 if (__e1000_shutdown(pdev, true)) {
7056 e1000e_pm_runtime_resume(dev);
7063 static void e1000_shutdown(struct pci_dev *pdev)
7065 e1000e_flush_lpic(pdev);
7067 e1000e_pm_freeze(&pdev->dev);
7069 __e1000_shutdown(pdev, false);
7072 #ifdef CONFIG_NET_POLL_CONTROLLER
7074 static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
7076 struct net_device *netdev = data;
7077 struct e1000_adapter *adapter = netdev_priv(netdev);
7079 if (adapter->msix_entries) {
7080 int vector, msix_irq;
7083 msix_irq = adapter->msix_entries[vector].vector;
7084 if (disable_hardirq(msix_irq))
7085 e1000_intr_msix_rx(msix_irq, netdev);
7086 enable_irq(msix_irq);
7089 msix_irq = adapter->msix_entries[vector].vector;
7090 if (disable_hardirq(msix_irq))
7091 e1000_intr_msix_tx(msix_irq, netdev);
7092 enable_irq(msix_irq);
7095 msix_irq = adapter->msix_entries[vector].vector;
7096 if (disable_hardirq(msix_irq))
7097 e1000_msix_other(msix_irq, netdev);
7098 enable_irq(msix_irq);
7106 * @netdev: network interface device structure
7108 * Polling 'interrupt' - used by things like netconsole to send skbs
7109 * without having to re-enable interrupts. It's not called while
7110 * the interrupt routine is executing.
7112 static void e1000_netpoll(struct net_device *netdev)
7114 struct e1000_adapter *adapter = netdev_priv(netdev);
7116 switch (adapter->int_mode) {
7117 case E1000E_INT_MODE_MSIX:
7118 e1000_intr_msix(adapter->pdev->irq, netdev);
7120 case E1000E_INT_MODE_MSI:
7121 if (disable_hardirq(adapter->pdev->irq))
7122 e1000_intr_msi(adapter->pdev->irq, netdev);
7123 enable_irq(adapter->pdev->irq);
7125 default: /* E1000E_INT_MODE_LEGACY */
7126 if (disable_hardirq(adapter->pdev->irq))
7127 e1000_intr(adapter->pdev->irq, netdev);
7128 enable_irq(adapter->pdev->irq);
7135 * e1000_io_error_detected - called when PCI error is detected
7136 * @pdev: Pointer to PCI device
7137 * @state: The current pci connection state
7139 * This function is called after a PCI bus error affecting
7140 * this device has been detected.
7142 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
7143 pci_channel_state_t state)
7145 e1000e_pm_freeze(&pdev->dev);
7147 if (state == pci_channel_io_perm_failure)
7148 return PCI_ERS_RESULT_DISCONNECT;
7150 pci_disable_device(pdev);
7152 /* Request a slot slot reset. */
7153 return PCI_ERS_RESULT_NEED_RESET;
7157 * e1000_io_slot_reset - called after the pci bus has been reset.
7158 * @pdev: Pointer to PCI device
7160 * Restart the card from scratch, as if from a cold-boot. Implementation
7161 * resembles the first-half of the e1000e_pm_resume routine.
7163 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
7165 struct net_device *netdev = pci_get_drvdata(pdev);
7166 struct e1000_adapter *adapter = netdev_priv(netdev);
7167 struct e1000_hw *hw = &adapter->hw;
7168 u16 aspm_disable_flag = 0;
7170 pci_ers_result_t result;
7172 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
7173 aspm_disable_flag = PCIE_LINK_STATE_L0S;
7174 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
7175 aspm_disable_flag |= PCIE_LINK_STATE_L1;
7176 if (aspm_disable_flag)
7177 e1000e_disable_aspm_locked(pdev, aspm_disable_flag);
7179 err = pci_enable_device_mem(pdev);
7182 "Cannot re-enable PCI device after reset.\n");
7183 result = PCI_ERS_RESULT_DISCONNECT;
7185 pdev->state_saved = true;
7186 pci_restore_state(pdev);
7187 pci_set_master(pdev);
7189 pci_enable_wake(pdev, PCI_D3hot, 0);
7190 pci_enable_wake(pdev, PCI_D3cold, 0);
7192 e1000e_reset(adapter);
7194 result = PCI_ERS_RESULT_RECOVERED;
7201 * e1000_io_resume - called when traffic can start flowing again.
7202 * @pdev: Pointer to PCI device
7204 * This callback is called when the error recovery driver tells us that
7205 * its OK to resume normal operation. Implementation resembles the
7206 * second-half of the e1000e_pm_resume routine.
7208 static void e1000_io_resume(struct pci_dev *pdev)
7210 struct net_device *netdev = pci_get_drvdata(pdev);
7211 struct e1000_adapter *adapter = netdev_priv(netdev);
7213 e1000_init_manageability_pt(adapter);
7215 e1000e_pm_thaw(&pdev->dev);
7217 /* If the controller has AMT, do not set DRV_LOAD until the interface
7218 * is up. For all other cases, let the f/w know that the h/w is now
7219 * under the control of the driver.
7221 if (!(adapter->flags & FLAG_HAS_AMT))
7222 e1000e_get_hw_control(adapter);
7225 static void e1000_print_device_info(struct e1000_adapter *adapter)
7227 struct e1000_hw *hw = &adapter->hw;
7228 struct net_device *netdev = adapter->netdev;
7230 u8 pba_str[E1000_PBANUM_LENGTH];
7232 /* print bus type/speed/width info */
7233 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
7235 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
7239 e_info("Intel(R) PRO/%s Network Connection\n",
7240 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
7241 ret_val = e1000_read_pba_string_generic(hw, pba_str,
7242 E1000_PBANUM_LENGTH);
7244 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
7245 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
7246 hw->mac.type, hw->phy.type, pba_str);
7249 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
7251 struct e1000_hw *hw = &adapter->hw;
7255 if (hw->mac.type != e1000_82573)
7258 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
7260 if (!ret_val && (!(buf & BIT(0)))) {
7261 /* Deep Smart Power Down (DSPD) */
7262 dev_warn(&adapter->pdev->dev,
7263 "Warning: detected DSPD enabled in EEPROM\n");
7267 static netdev_features_t e1000_fix_features(struct net_device *netdev,
7268 netdev_features_t features)
7270 struct e1000_adapter *adapter = netdev_priv(netdev);
7271 struct e1000_hw *hw = &adapter->hw;
7273 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
7274 if ((hw->mac.type >= e1000_pch2lan) && (netdev->mtu > ETH_DATA_LEN))
7275 features &= ~NETIF_F_RXFCS;
7277 /* Since there is no support for separate Rx/Tx vlan accel
7278 * enable/disable make sure Tx flag is always in same state as Rx.
7280 if (features & NETIF_F_HW_VLAN_CTAG_RX)
7281 features |= NETIF_F_HW_VLAN_CTAG_TX;
7283 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
7288 static int e1000_set_features(struct net_device *netdev,
7289 netdev_features_t features)
7291 struct e1000_adapter *adapter = netdev_priv(netdev);
7292 netdev_features_t changed = features ^ netdev->features;
7294 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
7295 adapter->flags |= FLAG_TSO_FORCE;
7297 if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
7298 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
7302 if (changed & NETIF_F_RXFCS) {
7303 if (features & NETIF_F_RXFCS) {
7304 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
7306 /* We need to take it back to defaults, which might mean
7307 * stripping is still disabled at the adapter level.
7309 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
7310 adapter->flags2 |= FLAG2_CRC_STRIPPING;
7312 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
7316 netdev->features = features;
7318 if (netif_running(netdev))
7319 e1000e_reinit_locked(adapter);
7321 e1000e_reset(adapter);
7326 static const struct net_device_ops e1000e_netdev_ops = {
7327 .ndo_open = e1000e_open,
7328 .ndo_stop = e1000e_close,
7329 .ndo_start_xmit = e1000_xmit_frame,
7330 .ndo_get_stats64 = e1000e_get_stats64,
7331 .ndo_set_rx_mode = e1000e_set_rx_mode,
7332 .ndo_set_mac_address = e1000_set_mac,
7333 .ndo_change_mtu = e1000_change_mtu,
7334 .ndo_do_ioctl = e1000_ioctl,
7335 .ndo_tx_timeout = e1000_tx_timeout,
7336 .ndo_validate_addr = eth_validate_addr,
7338 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
7339 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
7340 #ifdef CONFIG_NET_POLL_CONTROLLER
7341 .ndo_poll_controller = e1000_netpoll,
7343 .ndo_set_features = e1000_set_features,
7344 .ndo_fix_features = e1000_fix_features,
7345 .ndo_features_check = passthru_features_check,
7349 * e1000_probe - Device Initialization Routine
7350 * @pdev: PCI device information struct
7351 * @ent: entry in e1000_pci_tbl
7353 * Returns 0 on success, negative on failure
7355 * e1000_probe initializes an adapter identified by a pci_dev structure.
7356 * The OS initialization, configuring of the adapter private structure,
7357 * and a hardware reset occur.
7359 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7361 struct net_device *netdev;
7362 struct e1000_adapter *adapter;
7363 struct e1000_hw *hw;
7364 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
7365 resource_size_t mmio_start, mmio_len;
7366 resource_size_t flash_start, flash_len;
7367 static int cards_found;
7368 u16 aspm_disable_flag = 0;
7369 int bars, i, err, pci_using_dac;
7370 u16 eeprom_data = 0;
7371 u16 eeprom_apme_mask = E1000_EEPROM_APME;
7374 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
7375 aspm_disable_flag = PCIE_LINK_STATE_L0S;
7376 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
7377 aspm_disable_flag |= PCIE_LINK_STATE_L1;
7378 if (aspm_disable_flag)
7379 e1000e_disable_aspm(pdev, aspm_disable_flag);
7381 err = pci_enable_device_mem(pdev);
7386 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
7390 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
7393 "No usable DMA configuration, aborting\n");
7398 bars = pci_select_bars(pdev, IORESOURCE_MEM);
7399 err = pci_request_selected_regions_exclusive(pdev, bars,
7400 e1000e_driver_name);
7404 /* AER (Advanced Error Reporting) hooks */
7405 pci_enable_pcie_error_reporting(pdev);
7407 pci_set_master(pdev);
7408 /* PCI config space info */
7409 err = pci_save_state(pdev);
7411 goto err_alloc_etherdev;
7414 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
7416 goto err_alloc_etherdev;
7418 SET_NETDEV_DEV(netdev, &pdev->dev);
7420 netdev->irq = pdev->irq;
7422 pci_set_drvdata(pdev, netdev);
7423 adapter = netdev_priv(netdev);
7425 adapter->netdev = netdev;
7426 adapter->pdev = pdev;
7428 adapter->pba = ei->pba;
7429 adapter->flags = ei->flags;
7430 adapter->flags2 = ei->flags2;
7431 adapter->hw.adapter = adapter;
7432 adapter->hw.mac.type = ei->mac;
7433 adapter->max_hw_frame_size = ei->max_hw_frame_size;
7434 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
7436 mmio_start = pci_resource_start(pdev, 0);
7437 mmio_len = pci_resource_len(pdev, 0);
7440 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
7441 if (!adapter->hw.hw_addr)
7444 if ((adapter->flags & FLAG_HAS_FLASH) &&
7445 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM) &&
7446 (hw->mac.type < e1000_pch_spt)) {
7447 flash_start = pci_resource_start(pdev, 1);
7448 flash_len = pci_resource_len(pdev, 1);
7449 adapter->hw.flash_address = ioremap(flash_start, flash_len);
7450 if (!adapter->hw.flash_address)
7454 /* Set default EEE advertisement */
7455 if (adapter->flags2 & FLAG2_HAS_EEE)
7456 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
7458 /* construct the net_device struct */
7459 netdev->netdev_ops = &e1000e_netdev_ops;
7460 e1000e_set_ethtool_ops(netdev);
7461 netdev->watchdog_timeo = 5 * HZ;
7462 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
7463 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
7465 netdev->mem_start = mmio_start;
7466 netdev->mem_end = mmio_start + mmio_len;
7468 adapter->bd_number = cards_found++;
7470 e1000e_check_options(adapter);
7472 /* setup adapter struct */
7473 err = e1000_sw_init(adapter);
7477 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
7478 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
7479 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
7481 err = ei->get_variants(adapter);
7485 if ((adapter->flags & FLAG_IS_ICH) &&
7486 (adapter->flags & FLAG_READ_ONLY_NVM) &&
7487 (hw->mac.type < e1000_pch_spt))
7488 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
7490 hw->mac.ops.get_bus_info(&adapter->hw);
7492 adapter->hw.phy.autoneg_wait_to_complete = 0;
7494 /* Copper options */
7495 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
7496 adapter->hw.phy.mdix = AUTO_ALL_MODES;
7497 adapter->hw.phy.disable_polarity_correction = 0;
7498 adapter->hw.phy.ms_type = e1000_ms_hw_default;
7501 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
7502 dev_info(&pdev->dev,
7503 "PHY reset is blocked due to SOL/IDER session.\n");
7505 /* Set initial default active device features */
7506 netdev->features = (NETIF_F_SG |
7507 NETIF_F_HW_VLAN_CTAG_RX |
7508 NETIF_F_HW_VLAN_CTAG_TX |
7515 /* Set user-changeable features (subset of all device features) */
7516 netdev->hw_features = netdev->features;
7517 netdev->hw_features |= NETIF_F_RXFCS;
7518 netdev->priv_flags |= IFF_SUPP_NOFCS;
7519 netdev->hw_features |= NETIF_F_RXALL;
7521 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
7522 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
7524 netdev->vlan_features |= (NETIF_F_SG |
7529 netdev->priv_flags |= IFF_UNICAST_FLT;
7531 if (pci_using_dac) {
7532 netdev->features |= NETIF_F_HIGHDMA;
7533 netdev->vlan_features |= NETIF_F_HIGHDMA;
7536 /* MTU range: 68 - max_hw_frame_size */
7537 netdev->min_mtu = ETH_MIN_MTU;
7538 netdev->max_mtu = adapter->max_hw_frame_size -
7539 (VLAN_ETH_HLEN + ETH_FCS_LEN);
7541 if (e1000e_enable_mng_pass_thru(&adapter->hw))
7542 adapter->flags |= FLAG_MNG_PT_ENABLED;
7544 /* before reading the NVM, reset the controller to
7545 * put the device in a known good starting state
7547 adapter->hw.mac.ops.reset_hw(&adapter->hw);
7549 /* systems with ASPM and others may see the checksum fail on the first
7550 * attempt. Let's give it a few tries
7553 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
7556 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
7562 e1000_eeprom_checks(adapter);
7564 /* copy the MAC address */
7565 if (e1000e_read_mac_addr(&adapter->hw))
7567 "NVM Read Error while reading MAC address\n");
7569 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
7571 if (!is_valid_ether_addr(netdev->dev_addr)) {
7572 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
7578 timer_setup(&adapter->watchdog_timer, e1000_watchdog, 0);
7579 timer_setup(&adapter->phy_info_timer, e1000_update_phy_info, 0);
7581 INIT_WORK(&adapter->reset_task, e1000_reset_task);
7582 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
7583 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
7584 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
7585 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
7587 /* Initialize link parameters. User can change them with ethtool */
7588 adapter->hw.mac.autoneg = 1;
7589 adapter->fc_autoneg = true;
7590 adapter->hw.fc.requested_mode = e1000_fc_default;
7591 adapter->hw.fc.current_mode = e1000_fc_default;
7592 adapter->hw.phy.autoneg_advertised = 0x2f;
7594 /* Initial Wake on LAN setting - If APM wake is enabled in
7595 * the EEPROM, enable the ACPI Magic Packet filter
7597 if (adapter->flags & FLAG_APME_IN_WUC) {
7598 /* APME bit in EEPROM is mapped to WUC.APME */
7599 eeprom_data = er32(WUC);
7600 eeprom_apme_mask = E1000_WUC_APME;
7601 if ((hw->mac.type > e1000_ich10lan) &&
7602 (eeprom_data & E1000_WUC_PHY_WAKE))
7603 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
7604 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
7605 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
7606 (adapter->hw.bus.func == 1))
7607 ret_val = e1000_read_nvm(&adapter->hw,
7608 NVM_INIT_CONTROL3_PORT_B,
7611 ret_val = e1000_read_nvm(&adapter->hw,
7612 NVM_INIT_CONTROL3_PORT_A,
7616 /* fetch WoL from EEPROM */
7618 e_dbg("NVM read error getting WoL initial values: %d\n", ret_val);
7619 else if (eeprom_data & eeprom_apme_mask)
7620 adapter->eeprom_wol |= E1000_WUFC_MAG;
7622 /* now that we have the eeprom settings, apply the special cases
7623 * where the eeprom may be wrong or the board simply won't support
7624 * wake on lan on a particular port
7626 if (!(adapter->flags & FLAG_HAS_WOL))
7627 adapter->eeprom_wol = 0;
7629 /* initialize the wol settings based on the eeprom settings */
7630 adapter->wol = adapter->eeprom_wol;
7632 /* make sure adapter isn't asleep if manageability is enabled */
7633 if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
7634 (hw->mac.ops.check_mng_mode(hw)))
7635 device_wakeup_enable(&pdev->dev);
7637 /* save off EEPROM version number */
7638 ret_val = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
7641 e_dbg("NVM read error getting EEPROM version: %d\n", ret_val);
7642 adapter->eeprom_vers = 0;
7645 /* init PTP hardware clock */
7646 e1000e_ptp_init(adapter);
7648 /* reset the hardware with the new settings */
7649 e1000e_reset(adapter);
7651 /* If the controller has AMT, do not set DRV_LOAD until the interface
7652 * is up. For all other cases, let the f/w know that the h/w is now
7653 * under the control of the driver.
7655 if (!(adapter->flags & FLAG_HAS_AMT))
7656 e1000e_get_hw_control(adapter);
7658 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
7659 err = register_netdev(netdev);
7663 /* carrier off reporting is important to ethtool even BEFORE open */
7664 netif_carrier_off(netdev);
7666 e1000_print_device_info(adapter);
7668 dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE);
7670 if (pci_dev_run_wake(pdev) && hw->mac.type < e1000_pch_cnp)
7671 pm_runtime_put_noidle(&pdev->dev);
7676 if (!(adapter->flags & FLAG_HAS_AMT))
7677 e1000e_release_hw_control(adapter);
7679 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
7680 e1000_phy_hw_reset(&adapter->hw);
7682 kfree(adapter->tx_ring);
7683 kfree(adapter->rx_ring);
7685 if ((adapter->hw.flash_address) && (hw->mac.type < e1000_pch_spt))
7686 iounmap(adapter->hw.flash_address);
7687 e1000e_reset_interrupt_capability(adapter);
7689 iounmap(adapter->hw.hw_addr);
7691 free_netdev(netdev);
7693 pci_release_mem_regions(pdev);
7696 pci_disable_device(pdev);
7701 * e1000_remove - Device Removal Routine
7702 * @pdev: PCI device information struct
7704 * e1000_remove is called by the PCI subsystem to alert the driver
7705 * that it should release a PCI device. The could be caused by a
7706 * Hot-Plug event, or because the driver is going to be removed from
7709 static void e1000_remove(struct pci_dev *pdev)
7711 struct net_device *netdev = pci_get_drvdata(pdev);
7712 struct e1000_adapter *adapter = netdev_priv(netdev);
7714 e1000e_ptp_remove(adapter);
7716 /* The timers may be rescheduled, so explicitly disable them
7717 * from being rescheduled.
7719 set_bit(__E1000_DOWN, &adapter->state);
7720 del_timer_sync(&adapter->watchdog_timer);
7721 del_timer_sync(&adapter->phy_info_timer);
7723 cancel_work_sync(&adapter->reset_task);
7724 cancel_work_sync(&adapter->watchdog_task);
7725 cancel_work_sync(&adapter->downshift_task);
7726 cancel_work_sync(&adapter->update_phy_task);
7727 cancel_work_sync(&adapter->print_hang_task);
7729 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
7730 cancel_work_sync(&adapter->tx_hwtstamp_work);
7731 if (adapter->tx_hwtstamp_skb) {
7732 dev_consume_skb_any(adapter->tx_hwtstamp_skb);
7733 adapter->tx_hwtstamp_skb = NULL;
7737 unregister_netdev(netdev);
7739 if (pci_dev_run_wake(pdev))
7740 pm_runtime_get_noresume(&pdev->dev);
7742 /* Release control of h/w to f/w. If f/w is AMT enabled, this
7743 * would have already happened in close and is redundant.
7745 e1000e_release_hw_control(adapter);
7747 e1000e_reset_interrupt_capability(adapter);
7748 kfree(adapter->tx_ring);
7749 kfree(adapter->rx_ring);
7751 iounmap(adapter->hw.hw_addr);
7752 if ((adapter->hw.flash_address) &&
7753 (adapter->hw.mac.type < e1000_pch_spt))
7754 iounmap(adapter->hw.flash_address);
7755 pci_release_mem_regions(pdev);
7757 free_netdev(netdev);
7760 pci_disable_pcie_error_reporting(pdev);
7762 pci_disable_device(pdev);
7765 /* PCI Error Recovery (ERS) */
7766 static const struct pci_error_handlers e1000_err_handler = {
7767 .error_detected = e1000_io_error_detected,
7768 .slot_reset = e1000_io_slot_reset,
7769 .resume = e1000_io_resume,
7772 static const struct pci_device_id e1000_pci_tbl[] = {
7773 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
7774 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
7775 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
7776 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
7778 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
7779 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
7780 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
7781 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
7782 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
7784 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
7785 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
7786 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
7787 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
7789 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
7790 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
7791 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
7793 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
7794 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
7795 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
7797 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
7798 board_80003es2lan },
7799 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
7800 board_80003es2lan },
7801 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
7802 board_80003es2lan },
7803 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
7804 board_80003es2lan },
7806 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
7807 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
7808 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
7809 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
7810 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
7811 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
7812 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
7813 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
7815 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
7816 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
7817 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
7818 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
7819 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
7820 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
7821 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
7822 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
7823 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
7825 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
7826 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
7827 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
7829 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
7830 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
7831 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
7833 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
7834 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
7835 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
7836 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
7838 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
7839 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7841 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7842 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
7843 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7844 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
7845 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
7846 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
7847 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
7848 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
7849 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM), board_pch_spt },
7850 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V), board_pch_spt },
7851 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM2), board_pch_spt },
7852 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V2), board_pch_spt },
7853 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LBG_I219_LM3), board_pch_spt },
7854 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM4), board_pch_spt },
7855 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V4), board_pch_spt },
7856 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM5), board_pch_spt },
7857 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V5), board_pch_spt },
7858 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM6), board_pch_cnp },
7859 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V6), board_pch_cnp },
7860 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM7), board_pch_cnp },
7861 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V7), board_pch_cnp },
7862 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM8), board_pch_cnp },
7863 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V8), board_pch_cnp },
7864 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM9), board_pch_cnp },
7865 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V9), board_pch_cnp },
7866 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM10), board_pch_cnp },
7867 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V10), board_pch_cnp },
7868 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM11), board_pch_cnp },
7869 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V11), board_pch_cnp },
7870 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM12), board_pch_spt },
7871 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V12), board_pch_spt },
7872 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM13), board_pch_cnp },
7873 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V13), board_pch_cnp },
7874 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM14), board_pch_cnp },
7875 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V14), board_pch_cnp },
7876 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM15), board_pch_cnp },
7877 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V15), board_pch_cnp },
7878 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM16), board_pch_cnp },
7879 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V16), board_pch_cnp },
7880 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM17), board_pch_cnp },
7881 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V17), board_pch_cnp },
7882 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_LM18), board_pch_cnp },
7883 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_V18), board_pch_cnp },
7884 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_LM19), board_pch_cnp },
7885 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_V19), board_pch_cnp },
7887 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
7889 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7891 static const struct dev_pm_ops e1000_pm_ops = {
7892 #ifdef CONFIG_PM_SLEEP
7893 .suspend = e1000e_pm_suspend,
7894 .resume = e1000e_pm_resume,
7895 .freeze = e1000e_pm_freeze,
7896 .thaw = e1000e_pm_thaw,
7897 .poweroff = e1000e_pm_suspend,
7898 .restore = e1000e_pm_resume,
7900 SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
7901 e1000e_pm_runtime_idle)
7904 /* PCI Device API Driver */
7905 static struct pci_driver e1000_driver = {
7906 .name = e1000e_driver_name,
7907 .id_table = e1000_pci_tbl,
7908 .probe = e1000_probe,
7909 .remove = e1000_remove,
7911 .pm = &e1000_pm_ops,
7913 .shutdown = e1000_shutdown,
7914 .err_handler = &e1000_err_handler
7918 * e1000_init_module - Driver Registration Routine
7920 * e1000_init_module is the first routine called when the driver is
7921 * loaded. All it does is register with the PCI subsystem.
7923 static int __init e1000_init_module(void)
7925 pr_info("Intel(R) PRO/1000 Network Driver\n");
7926 pr_info("Copyright(c) 1999 - 2015 Intel Corporation.\n");
7928 return pci_register_driver(&e1000_driver);
7930 module_init(e1000_init_module);
7933 * e1000_exit_module - Driver Exit Cleanup Routine
7935 * e1000_exit_module is called just before the driver is removed
7938 static void __exit e1000_exit_module(void)
7940 pci_unregister_driver(&e1000_driver);
7942 module_exit(e1000_exit_module);
7944 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7945 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7946 MODULE_LICENSE("GPL v2");