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>
28 #include <linux/suspend.h>
32 char e1000e_driver_name[] = "e1000e";
34 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
35 static int debug = -1;
36 module_param(debug, int, 0);
37 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
39 static const struct e1000_info *e1000_info_tbl[] = {
40 [board_82571] = &e1000_82571_info,
41 [board_82572] = &e1000_82572_info,
42 [board_82573] = &e1000_82573_info,
43 [board_82574] = &e1000_82574_info,
44 [board_82583] = &e1000_82583_info,
45 [board_80003es2lan] = &e1000_es2_info,
46 [board_ich8lan] = &e1000_ich8_info,
47 [board_ich9lan] = &e1000_ich9_info,
48 [board_ich10lan] = &e1000_ich10_info,
49 [board_pchlan] = &e1000_pch_info,
50 [board_pch2lan] = &e1000_pch2_info,
51 [board_pch_lpt] = &e1000_pch_lpt_info,
52 [board_pch_spt] = &e1000_pch_spt_info,
53 [board_pch_cnp] = &e1000_pch_cnp_info,
56 struct e1000_reg_info {
61 static const struct e1000_reg_info e1000_reg_info_tbl[] = {
62 /* General Registers */
64 {E1000_STATUS, "STATUS"},
65 {E1000_CTRL_EXT, "CTRL_EXT"},
67 /* Interrupt Registers */
72 {E1000_RDLEN(0), "RDLEN"},
73 {E1000_RDH(0), "RDH"},
74 {E1000_RDT(0), "RDT"},
76 {E1000_RXDCTL(0), "RXDCTL"},
78 {E1000_RDBAL(0), "RDBAL"},
79 {E1000_RDBAH(0), "RDBAH"},
82 {E1000_RDFHS, "RDFHS"},
83 {E1000_RDFTS, "RDFTS"},
84 {E1000_RDFPC, "RDFPC"},
88 {E1000_TDBAL(0), "TDBAL"},
89 {E1000_TDBAH(0), "TDBAH"},
90 {E1000_TDLEN(0), "TDLEN"},
91 {E1000_TDH(0), "TDH"},
92 {E1000_TDT(0), "TDT"},
94 {E1000_TXDCTL(0), "TXDCTL"},
96 {E1000_TARC(0), "TARC"},
99 {E1000_TDFHS, "TDFHS"},
100 {E1000_TDFTS, "TDFTS"},
101 {E1000_TDFPC, "TDFPC"},
103 /* List Terminator */
108 * __ew32_prepare - prepare to write to MAC CSR register on certain parts
109 * @hw: pointer to the HW structure
111 * When updating the MAC CSR registers, the Manageability Engine (ME) could
112 * be accessing the registers at the same time. Normally, this is handled in
113 * h/w by an arbiter but on some parts there is a bug that acknowledges Host
114 * accesses later than it should which could result in the register to have
115 * an incorrect value. Workaround this by checking the FWSM register which
116 * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set
117 * and try again a number of times.
119 static void __ew32_prepare(struct e1000_hw *hw)
121 s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;
123 while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
127 void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val)
129 if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
132 writel(val, hw->hw_addr + reg);
136 * e1000_regdump - register printout routine
137 * @hw: pointer to the HW structure
138 * @reginfo: pointer to the register info table
140 static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
146 switch (reginfo->ofs) {
147 case E1000_RXDCTL(0):
148 for (n = 0; n < 2; n++)
149 regs[n] = __er32(hw, E1000_RXDCTL(n));
151 case E1000_TXDCTL(0):
152 for (n = 0; n < 2; n++)
153 regs[n] = __er32(hw, E1000_TXDCTL(n));
156 for (n = 0; n < 2; n++)
157 regs[n] = __er32(hw, E1000_TARC(n));
160 pr_info("%-15s %08x\n",
161 reginfo->name, __er32(hw, reginfo->ofs));
165 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
166 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
169 static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
170 struct e1000_buffer *bi)
173 struct e1000_ps_page *ps_page;
175 for (i = 0; i < adapter->rx_ps_pages; i++) {
176 ps_page = &bi->ps_pages[i];
179 pr_info("packet dump for ps_page %d:\n", i);
180 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
181 16, 1, page_address(ps_page->page),
188 * e1000e_dump - Print registers, Tx-ring and Rx-ring
189 * @adapter: board private structure
191 static void e1000e_dump(struct e1000_adapter *adapter)
193 struct net_device *netdev = adapter->netdev;
194 struct e1000_hw *hw = &adapter->hw;
195 struct e1000_reg_info *reginfo;
196 struct e1000_ring *tx_ring = adapter->tx_ring;
197 struct e1000_tx_desc *tx_desc;
202 struct e1000_buffer *buffer_info;
203 struct e1000_ring *rx_ring = adapter->rx_ring;
204 union e1000_rx_desc_packet_split *rx_desc_ps;
205 union e1000_rx_desc_extended *rx_desc;
215 if (!netif_msg_hw(adapter))
218 /* Print netdevice Info */
220 dev_info(&adapter->pdev->dev, "Net device Info\n");
221 pr_info("Device Name state trans_start\n");
222 pr_info("%-15s %016lX %016lX\n", netdev->name,
223 netdev->state, dev_trans_start(netdev));
226 /* Print Registers */
227 dev_info(&adapter->pdev->dev, "Register Dump\n");
228 pr_info(" Register Name Value\n");
229 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
230 reginfo->name; reginfo++) {
231 e1000_regdump(hw, reginfo);
234 /* Print Tx Ring Summary */
235 if (!netdev || !netif_running(netdev))
238 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
239 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
240 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
241 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
242 0, tx_ring->next_to_use, tx_ring->next_to_clean,
243 (unsigned long long)buffer_info->dma,
245 buffer_info->next_to_watch,
246 (unsigned long long)buffer_info->time_stamp);
249 if (!netif_msg_tx_done(adapter))
250 goto rx_ring_summary;
252 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
254 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
256 * Legacy Transmit Descriptor
257 * +--------------------------------------------------------------+
258 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
259 * +--------------------------------------------------------------+
260 * 8 | Special | CSS | Status | CMD | CSO | Length |
261 * +--------------------------------------------------------------+
262 * 63 48 47 36 35 32 31 24 23 16 15 0
264 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
265 * 63 48 47 40 39 32 31 16 15 8 7 0
266 * +----------------------------------------------------------------+
267 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
268 * +----------------------------------------------------------------+
269 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
270 * +----------------------------------------------------------------+
271 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
273 * Extended Data Descriptor (DTYP=0x1)
274 * +----------------------------------------------------------------+
275 * 0 | Buffer Address [63:0] |
276 * +----------------------------------------------------------------+
277 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
278 * +----------------------------------------------------------------+
279 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
281 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
282 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
283 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
284 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
285 const char *next_desc;
286 tx_desc = E1000_TX_DESC(*tx_ring, i);
287 buffer_info = &tx_ring->buffer_info[i];
288 u0 = (struct my_u0 *)tx_desc;
289 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
290 next_desc = " NTC/U";
291 else if (i == tx_ring->next_to_use)
293 else if (i == tx_ring->next_to_clean)
297 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
298 (!(le64_to_cpu(u0->b) & BIT(29)) ? 'l' :
299 ((le64_to_cpu(u0->b) & BIT(20)) ? 'd' : 'c')),
301 (unsigned long long)le64_to_cpu(u0->a),
302 (unsigned long long)le64_to_cpu(u0->b),
303 (unsigned long long)buffer_info->dma,
304 buffer_info->length, buffer_info->next_to_watch,
305 (unsigned long long)buffer_info->time_stamp,
306 buffer_info->skb, next_desc);
308 if (netif_msg_pktdata(adapter) && buffer_info->skb)
309 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
310 16, 1, buffer_info->skb->data,
311 buffer_info->skb->len, true);
314 /* Print Rx Ring Summary */
316 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
317 pr_info("Queue [NTU] [NTC]\n");
318 pr_info(" %5d %5X %5X\n",
319 0, rx_ring->next_to_use, rx_ring->next_to_clean);
322 if (!netif_msg_rx_status(adapter))
325 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
326 switch (adapter->rx_ps_pages) {
330 /* [Extended] Packet Split Receive Descriptor Format
332 * +-----------------------------------------------------+
333 * 0 | Buffer Address 0 [63:0] |
334 * +-----------------------------------------------------+
335 * 8 | Buffer Address 1 [63:0] |
336 * +-----------------------------------------------------+
337 * 16 | Buffer Address 2 [63:0] |
338 * +-----------------------------------------------------+
339 * 24 | Buffer Address 3 [63:0] |
340 * +-----------------------------------------------------+
342 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");
343 /* [Extended] Receive Descriptor (Write-Back) Format
345 * 63 48 47 32 31 13 12 8 7 4 3 0
346 * +------------------------------------------------------+
347 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
348 * | Checksum | Ident | | Queue | | Type |
349 * +------------------------------------------------------+
350 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
351 * +------------------------------------------------------+
352 * 63 48 47 32 31 20 19 0
354 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
355 for (i = 0; i < rx_ring->count; i++) {
356 const char *next_desc;
357 buffer_info = &rx_ring->buffer_info[i];
358 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
359 u1 = (struct my_u1 *)rx_desc_ps;
361 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
363 if (i == rx_ring->next_to_use)
365 else if (i == rx_ring->next_to_clean)
370 if (staterr & E1000_RXD_STAT_DD) {
371 /* Descriptor Done */
372 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
374 (unsigned long long)le64_to_cpu(u1->a),
375 (unsigned long long)le64_to_cpu(u1->b),
376 (unsigned long long)le64_to_cpu(u1->c),
377 (unsigned long long)le64_to_cpu(u1->d),
378 buffer_info->skb, next_desc);
380 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
382 (unsigned long long)le64_to_cpu(u1->a),
383 (unsigned long long)le64_to_cpu(u1->b),
384 (unsigned long long)le64_to_cpu(u1->c),
385 (unsigned long long)le64_to_cpu(u1->d),
386 (unsigned long long)buffer_info->dma,
387 buffer_info->skb, next_desc);
389 if (netif_msg_pktdata(adapter))
390 e1000e_dump_ps_pages(adapter,
397 /* Extended Receive Descriptor (Read) Format
399 * +-----------------------------------------------------+
400 * 0 | Buffer Address [63:0] |
401 * +-----------------------------------------------------+
403 * +-----------------------------------------------------+
405 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
406 /* Extended Receive Descriptor (Write-Back) Format
408 * 63 48 47 32 31 24 23 4 3 0
409 * +------------------------------------------------------+
411 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
412 * | Packet | IP | | | Type |
413 * | Checksum | Ident | | | |
414 * +------------------------------------------------------+
415 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
416 * +------------------------------------------------------+
417 * 63 48 47 32 31 20 19 0
419 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
421 for (i = 0; i < rx_ring->count; i++) {
422 const char *next_desc;
424 buffer_info = &rx_ring->buffer_info[i];
425 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
426 u1 = (struct my_u1 *)rx_desc;
427 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
429 if (i == rx_ring->next_to_use)
431 else if (i == rx_ring->next_to_clean)
436 if (staterr & E1000_RXD_STAT_DD) {
437 /* Descriptor Done */
438 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
440 (unsigned long long)le64_to_cpu(u1->a),
441 (unsigned long long)le64_to_cpu(u1->b),
442 buffer_info->skb, next_desc);
444 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
446 (unsigned long long)le64_to_cpu(u1->a),
447 (unsigned long long)le64_to_cpu(u1->b),
448 (unsigned long long)buffer_info->dma,
449 buffer_info->skb, next_desc);
451 if (netif_msg_pktdata(adapter) &&
453 print_hex_dump(KERN_INFO, "",
454 DUMP_PREFIX_ADDRESS, 16,
456 buffer_info->skb->data,
457 adapter->rx_buffer_len,
465 * e1000_desc_unused - calculate if we have unused descriptors
466 * @ring: pointer to ring struct to perform calculation on
468 static int e1000_desc_unused(struct e1000_ring *ring)
470 if (ring->next_to_clean > ring->next_to_use)
471 return ring->next_to_clean - ring->next_to_use - 1;
473 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
477 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
478 * @adapter: board private structure
479 * @hwtstamps: time stamp structure to update
480 * @systim: unsigned 64bit system time value.
482 * Convert the system time value stored in the RX/TXSTMP registers into a
483 * hwtstamp which can be used by the upper level time stamping functions.
485 * The 'systim_lock' spinlock is used to protect the consistency of the
486 * system time value. This is needed because reading the 64 bit time
487 * value involves reading two 32 bit registers. The first read latches the
490 static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
491 struct skb_shared_hwtstamps *hwtstamps,
497 spin_lock_irqsave(&adapter->systim_lock, flags);
498 ns = timecounter_cyc2time(&adapter->tc, systim);
499 spin_unlock_irqrestore(&adapter->systim_lock, flags);
501 memset(hwtstamps, 0, sizeof(*hwtstamps));
502 hwtstamps->hwtstamp = ns_to_ktime(ns);
506 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
507 * @adapter: board private structure
508 * @status: descriptor extended error and status field
509 * @skb: particular skb to include time stamp
511 * If the time stamp is valid, convert it into the timecounter ns value
512 * and store that result into the shhwtstamps structure which is passed
513 * up the network stack.
515 static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
518 struct e1000_hw *hw = &adapter->hw;
521 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
522 !(status & E1000_RXDEXT_STATERR_TST) ||
523 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
526 /* The Rx time stamp registers contain the time stamp. No other
527 * received packet will be time stamped until the Rx time stamp
528 * registers are read. Because only one packet can be time stamped
529 * at a time, the register values must belong to this packet and
530 * therefore none of the other additional attributes need to be
533 rxstmp = (u64)er32(RXSTMPL);
534 rxstmp |= (u64)er32(RXSTMPH) << 32;
535 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
537 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
541 * e1000_receive_skb - helper function to handle Rx indications
542 * @adapter: board private structure
543 * @netdev: pointer to netdev struct
544 * @staterr: descriptor extended error and status field as written by hardware
545 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
546 * @skb: pointer to sk_buff to be indicated to stack
548 static void e1000_receive_skb(struct e1000_adapter *adapter,
549 struct net_device *netdev, struct sk_buff *skb,
550 u32 staterr, __le16 vlan)
552 u16 tag = le16_to_cpu(vlan);
554 e1000e_rx_hwtstamp(adapter, staterr, skb);
556 skb->protocol = eth_type_trans(skb, netdev);
558 if (staterr & E1000_RXD_STAT_VP)
559 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
561 napi_gro_receive(&adapter->napi, skb);
565 * e1000_rx_checksum - Receive Checksum Offload
566 * @adapter: board private structure
567 * @status_err: receive descriptor status and error fields
568 * @skb: socket buffer with received data
570 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
573 u16 status = (u16)status_err;
574 u8 errors = (u8)(status_err >> 24);
576 skb_checksum_none_assert(skb);
578 /* Rx checksum disabled */
579 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
582 /* Ignore Checksum bit is set */
583 if (status & E1000_RXD_STAT_IXSM)
586 /* TCP/UDP checksum error bit or IP checksum error bit is set */
587 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
588 /* let the stack verify checksum errors */
589 adapter->hw_csum_err++;
593 /* TCP/UDP Checksum has not been calculated */
594 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
597 /* It must be a TCP or UDP packet with a valid checksum */
598 skb->ip_summed = CHECKSUM_UNNECESSARY;
599 adapter->hw_csum_good++;
602 static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
604 struct e1000_adapter *adapter = rx_ring->adapter;
605 struct e1000_hw *hw = &adapter->hw;
608 writel(i, rx_ring->tail);
610 if (unlikely(i != readl(rx_ring->tail))) {
611 u32 rctl = er32(RCTL);
613 ew32(RCTL, rctl & ~E1000_RCTL_EN);
614 e_err("ME firmware caused invalid RDT - resetting\n");
615 schedule_work(&adapter->reset_task);
619 static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
621 struct e1000_adapter *adapter = tx_ring->adapter;
622 struct e1000_hw *hw = &adapter->hw;
625 writel(i, tx_ring->tail);
627 if (unlikely(i != readl(tx_ring->tail))) {
628 u32 tctl = er32(TCTL);
630 ew32(TCTL, tctl & ~E1000_TCTL_EN);
631 e_err("ME firmware caused invalid TDT - resetting\n");
632 schedule_work(&adapter->reset_task);
637 * e1000_alloc_rx_buffers - Replace used receive buffers
638 * @rx_ring: Rx descriptor ring
639 * @cleaned_count: number to reallocate
640 * @gfp: flags for allocation
642 static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
643 int cleaned_count, gfp_t gfp)
645 struct e1000_adapter *adapter = rx_ring->adapter;
646 struct net_device *netdev = adapter->netdev;
647 struct pci_dev *pdev = adapter->pdev;
648 union e1000_rx_desc_extended *rx_desc;
649 struct e1000_buffer *buffer_info;
652 unsigned int bufsz = adapter->rx_buffer_len;
654 i = rx_ring->next_to_use;
655 buffer_info = &rx_ring->buffer_info[i];
657 while (cleaned_count--) {
658 skb = buffer_info->skb;
664 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
666 /* Better luck next round */
667 adapter->alloc_rx_buff_failed++;
671 buffer_info->skb = skb;
673 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
674 adapter->rx_buffer_len,
676 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
677 dev_err(&pdev->dev, "Rx DMA map failed\n");
678 adapter->rx_dma_failed++;
682 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
683 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
685 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
686 /* Force memory writes to complete before letting h/w
687 * know there are new descriptors to fetch. (Only
688 * applicable for weak-ordered memory model archs,
692 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
693 e1000e_update_rdt_wa(rx_ring, i);
695 writel(i, rx_ring->tail);
698 if (i == rx_ring->count)
700 buffer_info = &rx_ring->buffer_info[i];
703 rx_ring->next_to_use = i;
707 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
708 * @rx_ring: Rx descriptor ring
709 * @cleaned_count: number to reallocate
710 * @gfp: flags for allocation
712 static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
713 int cleaned_count, gfp_t gfp)
715 struct e1000_adapter *adapter = rx_ring->adapter;
716 struct net_device *netdev = adapter->netdev;
717 struct pci_dev *pdev = adapter->pdev;
718 union e1000_rx_desc_packet_split *rx_desc;
719 struct e1000_buffer *buffer_info;
720 struct e1000_ps_page *ps_page;
724 i = rx_ring->next_to_use;
725 buffer_info = &rx_ring->buffer_info[i];
727 while (cleaned_count--) {
728 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
730 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
731 ps_page = &buffer_info->ps_pages[j];
732 if (j >= adapter->rx_ps_pages) {
733 /* all unused desc entries get hw null ptr */
734 rx_desc->read.buffer_addr[j + 1] =
738 if (!ps_page->page) {
739 ps_page->page = alloc_page(gfp);
740 if (!ps_page->page) {
741 adapter->alloc_rx_buff_failed++;
744 ps_page->dma = dma_map_page(&pdev->dev,
748 if (dma_mapping_error(&pdev->dev,
750 dev_err(&adapter->pdev->dev,
751 "Rx DMA page map failed\n");
752 adapter->rx_dma_failed++;
756 /* Refresh the desc even if buffer_addrs
757 * didn't change because each write-back
760 rx_desc->read.buffer_addr[j + 1] =
761 cpu_to_le64(ps_page->dma);
764 skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
768 adapter->alloc_rx_buff_failed++;
772 buffer_info->skb = skb;
773 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
774 adapter->rx_ps_bsize0,
776 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
777 dev_err(&pdev->dev, "Rx DMA map failed\n");
778 adapter->rx_dma_failed++;
780 dev_kfree_skb_any(skb);
781 buffer_info->skb = NULL;
785 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
787 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
788 /* Force memory writes to complete before letting h/w
789 * know there are new descriptors to fetch. (Only
790 * applicable for weak-ordered memory model archs,
794 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
795 e1000e_update_rdt_wa(rx_ring, i << 1);
797 writel(i << 1, rx_ring->tail);
801 if (i == rx_ring->count)
803 buffer_info = &rx_ring->buffer_info[i];
807 rx_ring->next_to_use = i;
811 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
812 * @rx_ring: Rx descriptor ring
813 * @cleaned_count: number of buffers to allocate this pass
814 * @gfp: flags for allocation
817 static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
818 int cleaned_count, gfp_t gfp)
820 struct e1000_adapter *adapter = rx_ring->adapter;
821 struct net_device *netdev = adapter->netdev;
822 struct pci_dev *pdev = adapter->pdev;
823 union e1000_rx_desc_extended *rx_desc;
824 struct e1000_buffer *buffer_info;
827 unsigned int bufsz = 256 - 16; /* for skb_reserve */
829 i = rx_ring->next_to_use;
830 buffer_info = &rx_ring->buffer_info[i];
832 while (cleaned_count--) {
833 skb = buffer_info->skb;
839 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
840 if (unlikely(!skb)) {
841 /* Better luck next round */
842 adapter->alloc_rx_buff_failed++;
846 buffer_info->skb = skb;
848 /* allocate a new page if necessary */
849 if (!buffer_info->page) {
850 buffer_info->page = alloc_page(gfp);
851 if (unlikely(!buffer_info->page)) {
852 adapter->alloc_rx_buff_failed++;
857 if (!buffer_info->dma) {
858 buffer_info->dma = dma_map_page(&pdev->dev,
859 buffer_info->page, 0,
862 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
863 adapter->alloc_rx_buff_failed++;
868 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
869 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
871 if (unlikely(++i == rx_ring->count))
873 buffer_info = &rx_ring->buffer_info[i];
876 if (likely(rx_ring->next_to_use != i)) {
877 rx_ring->next_to_use = i;
878 if (unlikely(i-- == 0))
879 i = (rx_ring->count - 1);
881 /* Force memory writes to complete before letting h/w
882 * know there are new descriptors to fetch. (Only
883 * applicable for weak-ordered memory model archs,
887 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
888 e1000e_update_rdt_wa(rx_ring, i);
890 writel(i, rx_ring->tail);
894 static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
897 if (netdev->features & NETIF_F_RXHASH)
898 skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3);
902 * e1000_clean_rx_irq - Send received data up the network stack
903 * @rx_ring: Rx descriptor ring
904 * @work_done: output parameter for indicating completed work
905 * @work_to_do: how many packets we can clean
907 * the return value indicates whether actual cleaning was done, there
908 * is no guarantee that everything was cleaned
910 static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
913 struct e1000_adapter *adapter = rx_ring->adapter;
914 struct net_device *netdev = adapter->netdev;
915 struct pci_dev *pdev = adapter->pdev;
916 struct e1000_hw *hw = &adapter->hw;
917 union e1000_rx_desc_extended *rx_desc, *next_rxd;
918 struct e1000_buffer *buffer_info, *next_buffer;
921 int cleaned_count = 0;
922 bool cleaned = false;
923 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
925 i = rx_ring->next_to_clean;
926 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
927 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
928 buffer_info = &rx_ring->buffer_info[i];
930 while (staterr & E1000_RXD_STAT_DD) {
933 if (*work_done >= work_to_do)
936 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
938 skb = buffer_info->skb;
939 buffer_info->skb = NULL;
941 prefetch(skb->data - NET_IP_ALIGN);
944 if (i == rx_ring->count)
946 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
949 next_buffer = &rx_ring->buffer_info[i];
953 dma_unmap_single(&pdev->dev, buffer_info->dma,
954 adapter->rx_buffer_len, DMA_FROM_DEVICE);
955 buffer_info->dma = 0;
957 length = le16_to_cpu(rx_desc->wb.upper.length);
959 /* !EOP means multiple descriptors were used to store a single
960 * packet, if that's the case we need to toss it. In fact, we
961 * need to toss every packet with the EOP bit clear and the
962 * next frame that _does_ have the EOP bit set, as it is by
963 * definition only a frame fragment
965 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
966 adapter->flags2 |= FLAG2_IS_DISCARDING;
968 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
969 /* All receives must fit into a single buffer */
970 e_dbg("Receive packet consumed multiple buffers\n");
972 buffer_info->skb = skb;
973 if (staterr & E1000_RXD_STAT_EOP)
974 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
978 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
979 !(netdev->features & NETIF_F_RXALL))) {
981 buffer_info->skb = skb;
985 /* adjust length to remove Ethernet CRC */
986 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
987 /* If configured to store CRC, don't subtract FCS,
988 * but keep the FCS bytes out of the total_rx_bytes
991 if (netdev->features & NETIF_F_RXFCS)
997 total_rx_bytes += length;
1000 /* code added for copybreak, this should improve
1001 * performance for small packets with large amounts
1002 * of reassembly being done in the stack
1004 if (length < copybreak) {
1005 struct sk_buff *new_skb =
1006 napi_alloc_skb(&adapter->napi, length);
1008 skb_copy_to_linear_data_offset(new_skb,
1014 /* save the skb in buffer_info as good */
1015 buffer_info->skb = skb;
1018 /* else just continue with the old one */
1020 /* end copybreak code */
1021 skb_put(skb, length);
1023 /* Receive Checksum Offload */
1024 e1000_rx_checksum(adapter, staterr, skb);
1026 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1028 e1000_receive_skb(adapter, netdev, skb, staterr,
1029 rx_desc->wb.upper.vlan);
1032 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
1034 /* return some buffers to hardware, one at a time is too slow */
1035 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1036 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1041 /* use prefetched values */
1043 buffer_info = next_buffer;
1045 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1047 rx_ring->next_to_clean = i;
1049 cleaned_count = e1000_desc_unused(rx_ring);
1051 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1053 adapter->total_rx_bytes += total_rx_bytes;
1054 adapter->total_rx_packets += total_rx_packets;
1058 static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1059 struct e1000_buffer *buffer_info,
1062 struct e1000_adapter *adapter = tx_ring->adapter;
1064 if (buffer_info->dma) {
1065 if (buffer_info->mapped_as_page)
1066 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1067 buffer_info->length, DMA_TO_DEVICE);
1069 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1070 buffer_info->length, DMA_TO_DEVICE);
1071 buffer_info->dma = 0;
1073 if (buffer_info->skb) {
1075 dev_kfree_skb_any(buffer_info->skb);
1077 dev_consume_skb_any(buffer_info->skb);
1078 buffer_info->skb = NULL;
1080 buffer_info->time_stamp = 0;
1083 static void e1000_print_hw_hang(struct work_struct *work)
1085 struct e1000_adapter *adapter = container_of(work,
1086 struct e1000_adapter,
1088 struct net_device *netdev = adapter->netdev;
1089 struct e1000_ring *tx_ring = adapter->tx_ring;
1090 unsigned int i = tx_ring->next_to_clean;
1091 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1092 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
1093 struct e1000_hw *hw = &adapter->hw;
1094 u16 phy_status, phy_1000t_status, phy_ext_status;
1097 if (test_bit(__E1000_DOWN, &adapter->state))
1100 if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
1101 /* May be block on write-back, flush and detect again
1102 * flush pending descriptor writebacks to memory
1104 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1105 /* execute the writes immediately */
1107 /* Due to rare timing issues, write to TIDV again to ensure
1108 * the write is successful
1110 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1111 /* execute the writes immediately */
1113 adapter->tx_hang_recheck = true;
1116 adapter->tx_hang_recheck = false;
1118 if (er32(TDH(0)) == er32(TDT(0))) {
1119 e_dbg("false hang detected, ignoring\n");
1123 /* Real hang detected */
1124 netif_stop_queue(netdev);
1126 e1e_rphy(hw, MII_BMSR, &phy_status);
1127 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1128 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
1130 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1132 /* detected Hardware unit hang */
1133 e_err("Detected Hardware Unit Hang:\n"
1136 " next_to_use <%x>\n"
1137 " next_to_clean <%x>\n"
1138 "buffer_info[next_to_clean]:\n"
1139 " time_stamp <%lx>\n"
1140 " next_to_watch <%x>\n"
1142 " next_to_watch.status <%x>\n"
1145 "PHY 1000BASE-T Status <%x>\n"
1146 "PHY Extended Status <%x>\n"
1147 "PCI Status <%x>\n",
1148 readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
1149 tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
1150 eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
1151 phy_status, phy_1000t_status, phy_ext_status, pci_status);
1153 e1000e_dump(adapter);
1155 /* Suggest workaround for known h/w issue */
1156 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1157 e_err("Try turning off Tx pause (flow control) via ethtool\n");
1161 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1162 * @work: pointer to work struct
1164 * This work function polls the TSYNCTXCTL valid bit to determine when a
1165 * timestamp has been taken for the current stored skb. The timestamp must
1166 * be for this skb because only one such packet is allowed in the queue.
1168 static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1170 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1172 struct e1000_hw *hw = &adapter->hw;
1174 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
1175 struct sk_buff *skb = adapter->tx_hwtstamp_skb;
1176 struct skb_shared_hwtstamps shhwtstamps;
1179 txstmp = er32(TXSTMPL);
1180 txstmp |= (u64)er32(TXSTMPH) << 32;
1182 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1184 /* Clear the global tx_hwtstamp_skb pointer and force writes
1185 * prior to notifying the stack of a Tx timestamp.
1187 adapter->tx_hwtstamp_skb = NULL;
1188 wmb(); /* force write prior to skb_tstamp_tx */
1190 skb_tstamp_tx(skb, &shhwtstamps);
1191 dev_consume_skb_any(skb);
1192 } else if (time_after(jiffies, adapter->tx_hwtstamp_start
1193 + adapter->tx_timeout_factor * HZ)) {
1194 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1195 adapter->tx_hwtstamp_skb = NULL;
1196 adapter->tx_hwtstamp_timeouts++;
1197 e_warn("clearing Tx timestamp hang\n");
1199 /* reschedule to check later */
1200 schedule_work(&adapter->tx_hwtstamp_work);
1205 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1206 * @tx_ring: Tx descriptor ring
1208 * the return value indicates whether actual cleaning was done, there
1209 * is no guarantee that everything was cleaned
1211 static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
1213 struct e1000_adapter *adapter = tx_ring->adapter;
1214 struct net_device *netdev = adapter->netdev;
1215 struct e1000_hw *hw = &adapter->hw;
1216 struct e1000_tx_desc *tx_desc, *eop_desc;
1217 struct e1000_buffer *buffer_info;
1218 unsigned int i, eop;
1219 unsigned int count = 0;
1220 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1221 unsigned int bytes_compl = 0, pkts_compl = 0;
1223 i = tx_ring->next_to_clean;
1224 eop = tx_ring->buffer_info[i].next_to_watch;
1225 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1227 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1228 (count < tx_ring->count)) {
1229 bool cleaned = false;
1231 dma_rmb(); /* read buffer_info after eop_desc */
1232 for (; !cleaned; count++) {
1233 tx_desc = E1000_TX_DESC(*tx_ring, i);
1234 buffer_info = &tx_ring->buffer_info[i];
1235 cleaned = (i == eop);
1238 total_tx_packets += buffer_info->segs;
1239 total_tx_bytes += buffer_info->bytecount;
1240 if (buffer_info->skb) {
1241 bytes_compl += buffer_info->skb->len;
1246 e1000_put_txbuf(tx_ring, buffer_info, false);
1247 tx_desc->upper.data = 0;
1250 if (i == tx_ring->count)
1254 if (i == tx_ring->next_to_use)
1256 eop = tx_ring->buffer_info[i].next_to_watch;
1257 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1260 tx_ring->next_to_clean = i;
1262 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1264 #define TX_WAKE_THRESHOLD 32
1265 if (count && netif_carrier_ok(netdev) &&
1266 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
1267 /* Make sure that anybody stopping the queue after this
1268 * sees the new next_to_clean.
1272 if (netif_queue_stopped(netdev) &&
1273 !(test_bit(__E1000_DOWN, &adapter->state))) {
1274 netif_wake_queue(netdev);
1275 ++adapter->restart_queue;
1279 if (adapter->detect_tx_hung) {
1280 /* Detect a transmit hang in hardware, this serializes the
1281 * check with the clearing of time_stamp and movement of i
1283 adapter->detect_tx_hung = false;
1284 if (tx_ring->buffer_info[i].time_stamp &&
1285 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
1286 + (adapter->tx_timeout_factor * HZ)) &&
1287 !(er32(STATUS) & E1000_STATUS_TXOFF))
1288 schedule_work(&adapter->print_hang_task);
1290 adapter->tx_hang_recheck = false;
1292 adapter->total_tx_bytes += total_tx_bytes;
1293 adapter->total_tx_packets += total_tx_packets;
1294 return count < tx_ring->count;
1298 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1299 * @rx_ring: Rx descriptor ring
1300 * @work_done: output parameter for indicating completed work
1301 * @work_to_do: how many packets we can clean
1303 * the return value indicates whether actual cleaning was done, there
1304 * is no guarantee that everything was cleaned
1306 static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1309 struct e1000_adapter *adapter = rx_ring->adapter;
1310 struct e1000_hw *hw = &adapter->hw;
1311 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1312 struct net_device *netdev = adapter->netdev;
1313 struct pci_dev *pdev = adapter->pdev;
1314 struct e1000_buffer *buffer_info, *next_buffer;
1315 struct e1000_ps_page *ps_page;
1316 struct sk_buff *skb;
1318 u32 length, staterr;
1319 int cleaned_count = 0;
1320 bool cleaned = false;
1321 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1323 i = rx_ring->next_to_clean;
1324 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1325 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1326 buffer_info = &rx_ring->buffer_info[i];
1328 while (staterr & E1000_RXD_STAT_DD) {
1329 if (*work_done >= work_to_do)
1332 skb = buffer_info->skb;
1333 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
1335 /* in the packet split case this is header only */
1336 prefetch(skb->data - NET_IP_ALIGN);
1339 if (i == rx_ring->count)
1341 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1344 next_buffer = &rx_ring->buffer_info[i];
1348 dma_unmap_single(&pdev->dev, buffer_info->dma,
1349 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
1350 buffer_info->dma = 0;
1352 /* see !EOP comment in other Rx routine */
1353 if (!(staterr & E1000_RXD_STAT_EOP))
1354 adapter->flags2 |= FLAG2_IS_DISCARDING;
1356 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
1357 e_dbg("Packet Split buffers didn't pick up the full packet\n");
1358 dev_kfree_skb_irq(skb);
1359 if (staterr & E1000_RXD_STAT_EOP)
1360 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1364 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1365 !(netdev->features & NETIF_F_RXALL))) {
1366 dev_kfree_skb_irq(skb);
1370 length = le16_to_cpu(rx_desc->wb.middle.length0);
1373 e_dbg("Last part of the packet spanning multiple descriptors\n");
1374 dev_kfree_skb_irq(skb);
1379 skb_put(skb, length);
1382 /* this looks ugly, but it seems compiler issues make
1383 * it more efficient than reusing j
1385 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1387 /* page alloc/put takes too long and effects small
1388 * packet throughput, so unsplit small packets and
1389 * save the alloc/put only valid in softirq (napi)
1390 * context to call kmap_*
1392 if (l1 && (l1 <= copybreak) &&
1393 ((length + l1) <= adapter->rx_ps_bsize0)) {
1396 ps_page = &buffer_info->ps_pages[0];
1398 /* there is no documentation about how to call
1399 * kmap_atomic, so we can't hold the mapping
1402 dma_sync_single_for_cpu(&pdev->dev,
1406 vaddr = kmap_atomic(ps_page->page);
1407 memcpy(skb_tail_pointer(skb), vaddr, l1);
1408 kunmap_atomic(vaddr);
1409 dma_sync_single_for_device(&pdev->dev,
1414 /* remove the CRC */
1415 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1416 if (!(netdev->features & NETIF_F_RXFCS))
1425 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1426 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1430 ps_page = &buffer_info->ps_pages[j];
1431 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1434 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1435 ps_page->page = NULL;
1437 skb->data_len += length;
1438 skb->truesize += PAGE_SIZE;
1441 /* strip the ethernet crc, problem is we're using pages now so
1442 * this whole operation can get a little cpu intensive
1444 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1445 if (!(netdev->features & NETIF_F_RXFCS))
1446 pskb_trim(skb, skb->len - 4);
1450 total_rx_bytes += skb->len;
1453 e1000_rx_checksum(adapter, staterr, skb);
1455 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1457 if (rx_desc->wb.upper.header_status &
1458 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1459 adapter->rx_hdr_split++;
1461 e1000_receive_skb(adapter, netdev, skb, staterr,
1462 rx_desc->wb.middle.vlan);
1465 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1466 buffer_info->skb = NULL;
1468 /* return some buffers to hardware, one at a time is too slow */
1469 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1470 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1475 /* use prefetched values */
1477 buffer_info = next_buffer;
1479 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1481 rx_ring->next_to_clean = i;
1483 cleaned_count = e1000_desc_unused(rx_ring);
1485 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1487 adapter->total_rx_bytes += total_rx_bytes;
1488 adapter->total_rx_packets += total_rx_packets;
1492 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1497 skb->data_len += length;
1498 skb->truesize += PAGE_SIZE;
1502 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1503 * @rx_ring: Rx descriptor ring
1504 * @work_done: output parameter for indicating completed work
1505 * @work_to_do: how many packets we can clean
1507 * the return value indicates whether actual cleaning was done, there
1508 * is no guarantee that everything was cleaned
1510 static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1513 struct e1000_adapter *adapter = rx_ring->adapter;
1514 struct net_device *netdev = adapter->netdev;
1515 struct pci_dev *pdev = adapter->pdev;
1516 union e1000_rx_desc_extended *rx_desc, *next_rxd;
1517 struct e1000_buffer *buffer_info, *next_buffer;
1518 u32 length, staterr;
1520 int cleaned_count = 0;
1521 bool cleaned = false;
1522 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1523 struct skb_shared_info *shinfo;
1525 i = rx_ring->next_to_clean;
1526 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1527 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1528 buffer_info = &rx_ring->buffer_info[i];
1530 while (staterr & E1000_RXD_STAT_DD) {
1531 struct sk_buff *skb;
1533 if (*work_done >= work_to_do)
1536 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
1538 skb = buffer_info->skb;
1539 buffer_info->skb = NULL;
1542 if (i == rx_ring->count)
1544 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
1547 next_buffer = &rx_ring->buffer_info[i];
1551 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1553 buffer_info->dma = 0;
1555 length = le16_to_cpu(rx_desc->wb.upper.length);
1557 /* errors is only valid for DD + EOP descriptors */
1558 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1559 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1560 !(netdev->features & NETIF_F_RXALL)))) {
1561 /* recycle both page and skb */
1562 buffer_info->skb = skb;
1563 /* an error means any chain goes out the window too */
1564 if (rx_ring->rx_skb_top)
1565 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1566 rx_ring->rx_skb_top = NULL;
1569 #define rxtop (rx_ring->rx_skb_top)
1570 if (!(staterr & E1000_RXD_STAT_EOP)) {
1571 /* this descriptor is only the beginning (or middle) */
1573 /* this is the beginning of a chain */
1575 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1578 /* this is the middle of a chain */
1579 shinfo = skb_shinfo(rxtop);
1580 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1581 buffer_info->page, 0,
1583 /* re-use the skb, only consumed the page */
1584 buffer_info->skb = skb;
1586 e1000_consume_page(buffer_info, rxtop, length);
1590 /* end of the chain */
1591 shinfo = skb_shinfo(rxtop);
1592 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1593 buffer_info->page, 0,
1595 /* re-use the current skb, we only consumed the
1598 buffer_info->skb = skb;
1601 e1000_consume_page(buffer_info, skb, length);
1603 /* no chain, got EOP, this buf is the packet
1604 * copybreak to save the put_page/alloc_page
1606 if (length <= copybreak &&
1607 skb_tailroom(skb) >= length) {
1609 vaddr = kmap_atomic(buffer_info->page);
1610 memcpy(skb_tail_pointer(skb), vaddr,
1612 kunmap_atomic(vaddr);
1613 /* re-use the page, so don't erase
1616 skb_put(skb, length);
1618 skb_fill_page_desc(skb, 0,
1619 buffer_info->page, 0,
1621 e1000_consume_page(buffer_info, skb,
1627 /* Receive Checksum Offload */
1628 e1000_rx_checksum(adapter, staterr, skb);
1630 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1632 /* probably a little skewed due to removing CRC */
1633 total_rx_bytes += skb->len;
1636 /* eth type trans needs skb->data to point to something */
1637 if (!pskb_may_pull(skb, ETH_HLEN)) {
1638 e_err("pskb_may_pull failed.\n");
1639 dev_kfree_skb_irq(skb);
1643 e1000_receive_skb(adapter, netdev, skb, staterr,
1644 rx_desc->wb.upper.vlan);
1647 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
1649 /* return some buffers to hardware, one at a time is too slow */
1650 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1651 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1656 /* use prefetched values */
1658 buffer_info = next_buffer;
1660 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1662 rx_ring->next_to_clean = i;
1664 cleaned_count = e1000_desc_unused(rx_ring);
1666 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1668 adapter->total_rx_bytes += total_rx_bytes;
1669 adapter->total_rx_packets += total_rx_packets;
1674 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1675 * @rx_ring: Rx descriptor ring
1677 static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
1679 struct e1000_adapter *adapter = rx_ring->adapter;
1680 struct e1000_buffer *buffer_info;
1681 struct e1000_ps_page *ps_page;
1682 struct pci_dev *pdev = adapter->pdev;
1685 /* Free all the Rx ring sk_buffs */
1686 for (i = 0; i < rx_ring->count; i++) {
1687 buffer_info = &rx_ring->buffer_info[i];
1688 if (buffer_info->dma) {
1689 if (adapter->clean_rx == e1000_clean_rx_irq)
1690 dma_unmap_single(&pdev->dev, buffer_info->dma,
1691 adapter->rx_buffer_len,
1693 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1694 dma_unmap_page(&pdev->dev, buffer_info->dma,
1695 PAGE_SIZE, DMA_FROM_DEVICE);
1696 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1697 dma_unmap_single(&pdev->dev, buffer_info->dma,
1698 adapter->rx_ps_bsize0,
1700 buffer_info->dma = 0;
1703 if (buffer_info->page) {
1704 put_page(buffer_info->page);
1705 buffer_info->page = NULL;
1708 if (buffer_info->skb) {
1709 dev_kfree_skb(buffer_info->skb);
1710 buffer_info->skb = NULL;
1713 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1714 ps_page = &buffer_info->ps_pages[j];
1717 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1720 put_page(ps_page->page);
1721 ps_page->page = NULL;
1725 /* there also may be some cached data from a chained receive */
1726 if (rx_ring->rx_skb_top) {
1727 dev_kfree_skb(rx_ring->rx_skb_top);
1728 rx_ring->rx_skb_top = NULL;
1731 /* Zero out the descriptor ring */
1732 memset(rx_ring->desc, 0, rx_ring->size);
1734 rx_ring->next_to_clean = 0;
1735 rx_ring->next_to_use = 0;
1736 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1739 static void e1000e_downshift_workaround(struct work_struct *work)
1741 struct e1000_adapter *adapter = container_of(work,
1742 struct e1000_adapter,
1745 if (test_bit(__E1000_DOWN, &adapter->state))
1748 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1752 * e1000_intr_msi - Interrupt Handler
1753 * @irq: interrupt number
1754 * @data: pointer to a network interface device structure
1756 static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
1758 struct net_device *netdev = data;
1759 struct e1000_adapter *adapter = netdev_priv(netdev);
1760 struct e1000_hw *hw = &adapter->hw;
1761 u32 icr = er32(ICR);
1763 /* read ICR disables interrupts using IAM */
1764 if (icr & E1000_ICR_LSC) {
1765 hw->mac.get_link_status = true;
1766 /* ICH8 workaround-- Call gig speed drop workaround on cable
1767 * disconnect (LSC) before accessing any PHY registers
1769 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1770 (!(er32(STATUS) & E1000_STATUS_LU)))
1771 schedule_work(&adapter->downshift_task);
1773 /* 80003ES2LAN workaround-- For packet buffer work-around on
1774 * link down event; disable receives here in the ISR and reset
1775 * adapter in watchdog
1777 if (netif_carrier_ok(netdev) &&
1778 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1779 /* disable receives */
1780 u32 rctl = er32(RCTL);
1782 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1783 adapter->flags |= FLAG_RESTART_NOW;
1785 /* guard against interrupt when we're going down */
1786 if (!test_bit(__E1000_DOWN, &adapter->state))
1787 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1790 /* Reset on uncorrectable ECC error */
1791 if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
1792 u32 pbeccsts = er32(PBECCSTS);
1794 adapter->corr_errors +=
1795 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1796 adapter->uncorr_errors +=
1797 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1798 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1800 /* Do the reset outside of interrupt context */
1801 schedule_work(&adapter->reset_task);
1803 /* return immediately since reset is imminent */
1807 if (napi_schedule_prep(&adapter->napi)) {
1808 adapter->total_tx_bytes = 0;
1809 adapter->total_tx_packets = 0;
1810 adapter->total_rx_bytes = 0;
1811 adapter->total_rx_packets = 0;
1812 __napi_schedule(&adapter->napi);
1819 * e1000_intr - Interrupt Handler
1820 * @irq: interrupt number
1821 * @data: pointer to a network interface device structure
1823 static irqreturn_t e1000_intr(int __always_unused irq, void *data)
1825 struct net_device *netdev = data;
1826 struct e1000_adapter *adapter = netdev_priv(netdev);
1827 struct e1000_hw *hw = &adapter->hw;
1828 u32 rctl, icr = er32(ICR);
1830 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
1831 return IRQ_NONE; /* Not our interrupt */
1833 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1834 * not set, then the adapter didn't send an interrupt
1836 if (!(icr & E1000_ICR_INT_ASSERTED))
1839 /* Interrupt Auto-Mask...upon reading ICR,
1840 * interrupts are masked. No need for the
1844 if (icr & E1000_ICR_LSC) {
1845 hw->mac.get_link_status = true;
1846 /* ICH8 workaround-- Call gig speed drop workaround on cable
1847 * disconnect (LSC) before accessing any PHY registers
1849 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1850 (!(er32(STATUS) & E1000_STATUS_LU)))
1851 schedule_work(&adapter->downshift_task);
1853 /* 80003ES2LAN workaround--
1854 * For packet buffer work-around on link down event;
1855 * disable receives here in the ISR and
1856 * reset adapter in watchdog
1858 if (netif_carrier_ok(netdev) &&
1859 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1860 /* disable receives */
1862 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1863 adapter->flags |= FLAG_RESTART_NOW;
1865 /* guard against interrupt when we're going down */
1866 if (!test_bit(__E1000_DOWN, &adapter->state))
1867 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1870 /* Reset on uncorrectable ECC error */
1871 if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
1872 u32 pbeccsts = er32(PBECCSTS);
1874 adapter->corr_errors +=
1875 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1876 adapter->uncorr_errors +=
1877 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1878 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1880 /* Do the reset outside of interrupt context */
1881 schedule_work(&adapter->reset_task);
1883 /* return immediately since reset is imminent */
1887 if (napi_schedule_prep(&adapter->napi)) {
1888 adapter->total_tx_bytes = 0;
1889 adapter->total_tx_packets = 0;
1890 adapter->total_rx_bytes = 0;
1891 adapter->total_rx_packets = 0;
1892 __napi_schedule(&adapter->napi);
1898 static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
1900 struct net_device *netdev = data;
1901 struct e1000_adapter *adapter = netdev_priv(netdev);
1902 struct e1000_hw *hw = &adapter->hw;
1903 u32 icr = er32(ICR);
1905 if (icr & adapter->eiac_mask)
1906 ew32(ICS, (icr & adapter->eiac_mask));
1908 if (icr & E1000_ICR_LSC) {
1909 hw->mac.get_link_status = true;
1910 /* guard against interrupt when we're going down */
1911 if (!test_bit(__E1000_DOWN, &adapter->state))
1912 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1915 if (!test_bit(__E1000_DOWN, &adapter->state))
1916 ew32(IMS, E1000_IMS_OTHER | IMS_OTHER_MASK);
1921 static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
1923 struct net_device *netdev = data;
1924 struct e1000_adapter *adapter = netdev_priv(netdev);
1925 struct e1000_hw *hw = &adapter->hw;
1926 struct e1000_ring *tx_ring = adapter->tx_ring;
1928 adapter->total_tx_bytes = 0;
1929 adapter->total_tx_packets = 0;
1931 if (!e1000_clean_tx_irq(tx_ring))
1932 /* Ring was not completely cleaned, so fire another interrupt */
1933 ew32(ICS, tx_ring->ims_val);
1935 if (!test_bit(__E1000_DOWN, &adapter->state))
1936 ew32(IMS, adapter->tx_ring->ims_val);
1941 static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
1943 struct net_device *netdev = data;
1944 struct e1000_adapter *adapter = netdev_priv(netdev);
1945 struct e1000_ring *rx_ring = adapter->rx_ring;
1947 /* Write the ITR value calculated at the end of the
1948 * previous interrupt.
1950 if (rx_ring->set_itr) {
1951 u32 itr = rx_ring->itr_val ?
1952 1000000000 / (rx_ring->itr_val * 256) : 0;
1954 writel(itr, rx_ring->itr_register);
1955 rx_ring->set_itr = 0;
1958 if (napi_schedule_prep(&adapter->napi)) {
1959 adapter->total_rx_bytes = 0;
1960 adapter->total_rx_packets = 0;
1961 __napi_schedule(&adapter->napi);
1967 * e1000_configure_msix - Configure MSI-X hardware
1968 * @adapter: board private structure
1970 * e1000_configure_msix sets up the hardware to properly
1971 * generate MSI-X interrupts.
1973 static void e1000_configure_msix(struct e1000_adapter *adapter)
1975 struct e1000_hw *hw = &adapter->hw;
1976 struct e1000_ring *rx_ring = adapter->rx_ring;
1977 struct e1000_ring *tx_ring = adapter->tx_ring;
1979 u32 ctrl_ext, ivar = 0;
1981 adapter->eiac_mask = 0;
1983 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1984 if (hw->mac.type == e1000_82574) {
1985 u32 rfctl = er32(RFCTL);
1987 rfctl |= E1000_RFCTL_ACK_DIS;
1991 /* Configure Rx vector */
1992 rx_ring->ims_val = E1000_IMS_RXQ0;
1993 adapter->eiac_mask |= rx_ring->ims_val;
1994 if (rx_ring->itr_val)
1995 writel(1000000000 / (rx_ring->itr_val * 256),
1996 rx_ring->itr_register);
1998 writel(1, rx_ring->itr_register);
1999 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
2001 /* Configure Tx vector */
2002 tx_ring->ims_val = E1000_IMS_TXQ0;
2004 if (tx_ring->itr_val)
2005 writel(1000000000 / (tx_ring->itr_val * 256),
2006 tx_ring->itr_register);
2008 writel(1, tx_ring->itr_register);
2009 adapter->eiac_mask |= tx_ring->ims_val;
2010 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
2012 /* set vector for Other Causes, e.g. link changes */
2014 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
2015 if (rx_ring->itr_val)
2016 writel(1000000000 / (rx_ring->itr_val * 256),
2017 hw->hw_addr + E1000_EITR_82574(vector));
2019 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2021 /* Cause Tx interrupts on every write back */
2026 /* enable MSI-X PBA support */
2027 ctrl_ext = er32(CTRL_EXT) & ~E1000_CTRL_EXT_IAME;
2028 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR | E1000_CTRL_EXT_EIAME;
2029 ew32(CTRL_EXT, ctrl_ext);
2033 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2035 if (adapter->msix_entries) {
2036 pci_disable_msix(adapter->pdev);
2037 kfree(adapter->msix_entries);
2038 adapter->msix_entries = NULL;
2039 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2040 pci_disable_msi(adapter->pdev);
2041 adapter->flags &= ~FLAG_MSI_ENABLED;
2046 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2047 * @adapter: board private structure
2049 * Attempt to configure interrupts using the best available
2050 * capabilities of the hardware and kernel.
2052 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2057 switch (adapter->int_mode) {
2058 case E1000E_INT_MODE_MSIX:
2059 if (adapter->flags & FLAG_HAS_MSIX) {
2060 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2061 adapter->msix_entries = kcalloc(adapter->num_vectors,
2065 if (adapter->msix_entries) {
2066 struct e1000_adapter *a = adapter;
2068 for (i = 0; i < adapter->num_vectors; i++)
2069 adapter->msix_entries[i].entry = i;
2071 err = pci_enable_msix_range(a->pdev,
2078 /* MSI-X failed, so fall through and try MSI */
2079 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
2080 e1000e_reset_interrupt_capability(adapter);
2082 adapter->int_mode = E1000E_INT_MODE_MSI;
2084 case E1000E_INT_MODE_MSI:
2085 if (!pci_enable_msi(adapter->pdev)) {
2086 adapter->flags |= FLAG_MSI_ENABLED;
2088 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2089 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
2092 case E1000E_INT_MODE_LEGACY:
2093 /* Don't do anything; this is the system default */
2097 /* store the number of vectors being used */
2098 adapter->num_vectors = 1;
2102 * e1000_request_msix - Initialize MSI-X interrupts
2103 * @adapter: board private structure
2105 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2108 static int e1000_request_msix(struct e1000_adapter *adapter)
2110 struct net_device *netdev = adapter->netdev;
2111 int err = 0, vector = 0;
2113 if (strlen(netdev->name) < (IFNAMSIZ - 5))
2114 snprintf(adapter->rx_ring->name,
2115 sizeof(adapter->rx_ring->name) - 1,
2116 "%.14s-rx-0", netdev->name);
2118 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2119 err = request_irq(adapter->msix_entries[vector].vector,
2120 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
2124 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2125 E1000_EITR_82574(vector);
2126 adapter->rx_ring->itr_val = adapter->itr;
2129 if (strlen(netdev->name) < (IFNAMSIZ - 5))
2130 snprintf(adapter->tx_ring->name,
2131 sizeof(adapter->tx_ring->name) - 1,
2132 "%.14s-tx-0", netdev->name);
2134 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2135 err = request_irq(adapter->msix_entries[vector].vector,
2136 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
2140 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2141 E1000_EITR_82574(vector);
2142 adapter->tx_ring->itr_val = adapter->itr;
2145 err = request_irq(adapter->msix_entries[vector].vector,
2146 e1000_msix_other, 0, netdev->name, netdev);
2150 e1000_configure_msix(adapter);
2156 * e1000_request_irq - initialize interrupts
2157 * @adapter: board private structure
2159 * Attempts to configure interrupts using the best available
2160 * capabilities of the hardware and kernel.
2162 static int e1000_request_irq(struct e1000_adapter *adapter)
2164 struct net_device *netdev = adapter->netdev;
2167 if (adapter->msix_entries) {
2168 err = e1000_request_msix(adapter);
2171 /* fall back to MSI */
2172 e1000e_reset_interrupt_capability(adapter);
2173 adapter->int_mode = E1000E_INT_MODE_MSI;
2174 e1000e_set_interrupt_capability(adapter);
2176 if (adapter->flags & FLAG_MSI_ENABLED) {
2177 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
2178 netdev->name, netdev);
2182 /* fall back to legacy interrupt */
2183 e1000e_reset_interrupt_capability(adapter);
2184 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2187 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
2188 netdev->name, netdev);
2190 e_err("Unable to allocate interrupt, Error: %d\n", err);
2195 static void e1000_free_irq(struct e1000_adapter *adapter)
2197 struct net_device *netdev = adapter->netdev;
2199 if (adapter->msix_entries) {
2202 free_irq(adapter->msix_entries[vector].vector, netdev);
2205 free_irq(adapter->msix_entries[vector].vector, netdev);
2208 /* Other Causes interrupt vector */
2209 free_irq(adapter->msix_entries[vector].vector, netdev);
2213 free_irq(adapter->pdev->irq, netdev);
2217 * e1000_irq_disable - Mask off interrupt generation on the NIC
2218 * @adapter: board private structure
2220 static void e1000_irq_disable(struct e1000_adapter *adapter)
2222 struct e1000_hw *hw = &adapter->hw;
2225 if (adapter->msix_entries)
2226 ew32(EIAC_82574, 0);
2229 if (adapter->msix_entries) {
2232 for (i = 0; i < adapter->num_vectors; i++)
2233 synchronize_irq(adapter->msix_entries[i].vector);
2235 synchronize_irq(adapter->pdev->irq);
2240 * e1000_irq_enable - Enable default interrupt generation settings
2241 * @adapter: board private structure
2243 static void e1000_irq_enable(struct e1000_adapter *adapter)
2245 struct e1000_hw *hw = &adapter->hw;
2247 if (adapter->msix_entries) {
2248 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2249 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER |
2251 } else if (hw->mac.type >= e1000_pch_lpt) {
2252 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
2254 ew32(IMS, IMS_ENABLE_MASK);
2260 * e1000e_get_hw_control - get control of the h/w from f/w
2261 * @adapter: address of board private structure
2263 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2264 * For ASF and Pass Through versions of f/w this means that
2265 * the driver is loaded. For AMT version (only with 82573)
2266 * of the f/w this means that the network i/f is open.
2268 void e1000e_get_hw_control(struct e1000_adapter *adapter)
2270 struct e1000_hw *hw = &adapter->hw;
2274 /* Let firmware know the driver has taken over */
2275 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2277 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2278 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2279 ctrl_ext = er32(CTRL_EXT);
2280 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2285 * e1000e_release_hw_control - release control of the h/w to f/w
2286 * @adapter: address of board private structure
2288 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2289 * For ASF and Pass Through versions of f/w this means that the
2290 * driver is no longer loaded. For AMT version (only with 82573) i
2291 * of the f/w this means that the network i/f is closed.
2294 void e1000e_release_hw_control(struct e1000_adapter *adapter)
2296 struct e1000_hw *hw = &adapter->hw;
2300 /* Let firmware taken over control of h/w */
2301 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2303 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2304 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2305 ctrl_ext = er32(CTRL_EXT);
2306 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2311 * e1000_alloc_ring_dma - allocate memory for a ring structure
2312 * @adapter: board private structure
2313 * @ring: ring struct for which to allocate dma
2315 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2316 struct e1000_ring *ring)
2318 struct pci_dev *pdev = adapter->pdev;
2320 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2329 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2330 * @tx_ring: Tx descriptor ring
2332 * Return 0 on success, negative on failure
2334 int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
2336 struct e1000_adapter *adapter = tx_ring->adapter;
2337 int err = -ENOMEM, size;
2339 size = sizeof(struct e1000_buffer) * tx_ring->count;
2340 tx_ring->buffer_info = vzalloc(size);
2341 if (!tx_ring->buffer_info)
2344 /* round up to nearest 4K */
2345 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2346 tx_ring->size = ALIGN(tx_ring->size, 4096);
2348 err = e1000_alloc_ring_dma(adapter, tx_ring);
2352 tx_ring->next_to_use = 0;
2353 tx_ring->next_to_clean = 0;
2357 vfree(tx_ring->buffer_info);
2358 e_err("Unable to allocate memory for the transmit descriptor ring\n");
2363 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2364 * @rx_ring: Rx descriptor ring
2366 * Returns 0 on success, negative on failure
2368 int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
2370 struct e1000_adapter *adapter = rx_ring->adapter;
2371 struct e1000_buffer *buffer_info;
2372 int i, size, desc_len, err = -ENOMEM;
2374 size = sizeof(struct e1000_buffer) * rx_ring->count;
2375 rx_ring->buffer_info = vzalloc(size);
2376 if (!rx_ring->buffer_info)
2379 for (i = 0; i < rx_ring->count; i++) {
2380 buffer_info = &rx_ring->buffer_info[i];
2381 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2382 sizeof(struct e1000_ps_page),
2384 if (!buffer_info->ps_pages)
2388 desc_len = sizeof(union e1000_rx_desc_packet_split);
2390 /* Round up to nearest 4K */
2391 rx_ring->size = rx_ring->count * desc_len;
2392 rx_ring->size = ALIGN(rx_ring->size, 4096);
2394 err = e1000_alloc_ring_dma(adapter, rx_ring);
2398 rx_ring->next_to_clean = 0;
2399 rx_ring->next_to_use = 0;
2400 rx_ring->rx_skb_top = NULL;
2405 for (i = 0; i < rx_ring->count; i++) {
2406 buffer_info = &rx_ring->buffer_info[i];
2407 kfree(buffer_info->ps_pages);
2410 vfree(rx_ring->buffer_info);
2411 e_err("Unable to allocate memory for the receive descriptor ring\n");
2416 * e1000_clean_tx_ring - Free Tx Buffers
2417 * @tx_ring: Tx descriptor ring
2419 static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
2421 struct e1000_adapter *adapter = tx_ring->adapter;
2422 struct e1000_buffer *buffer_info;
2426 for (i = 0; i < tx_ring->count; i++) {
2427 buffer_info = &tx_ring->buffer_info[i];
2428 e1000_put_txbuf(tx_ring, buffer_info, false);
2431 netdev_reset_queue(adapter->netdev);
2432 size = sizeof(struct e1000_buffer) * tx_ring->count;
2433 memset(tx_ring->buffer_info, 0, size);
2435 memset(tx_ring->desc, 0, tx_ring->size);
2437 tx_ring->next_to_use = 0;
2438 tx_ring->next_to_clean = 0;
2442 * e1000e_free_tx_resources - Free Tx Resources per Queue
2443 * @tx_ring: Tx descriptor ring
2445 * Free all transmit software resources
2447 void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
2449 struct e1000_adapter *adapter = tx_ring->adapter;
2450 struct pci_dev *pdev = adapter->pdev;
2452 e1000_clean_tx_ring(tx_ring);
2454 vfree(tx_ring->buffer_info);
2455 tx_ring->buffer_info = NULL;
2457 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2459 tx_ring->desc = NULL;
2463 * e1000e_free_rx_resources - Free Rx Resources
2464 * @rx_ring: Rx descriptor ring
2466 * Free all receive software resources
2468 void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
2470 struct e1000_adapter *adapter = rx_ring->adapter;
2471 struct pci_dev *pdev = adapter->pdev;
2474 e1000_clean_rx_ring(rx_ring);
2476 for (i = 0; i < rx_ring->count; i++)
2477 kfree(rx_ring->buffer_info[i].ps_pages);
2479 vfree(rx_ring->buffer_info);
2480 rx_ring->buffer_info = NULL;
2482 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2484 rx_ring->desc = NULL;
2488 * e1000_update_itr - update the dynamic ITR value based on statistics
2489 * @itr_setting: current adapter->itr
2490 * @packets: the number of packets during this measurement interval
2491 * @bytes: the number of bytes during this measurement interval
2493 * Stores a new ITR value based on packets and byte
2494 * counts during the last interrupt. The advantage of per interrupt
2495 * computation is faster updates and more accurate ITR for the current
2496 * traffic pattern. Constants in this function were computed
2497 * based on theoretical maximum wire speed and thresholds were set based
2498 * on testing data as well as attempting to minimize response time
2499 * while increasing bulk throughput. This functionality is controlled
2500 * by the InterruptThrottleRate module parameter.
2502 static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
2504 unsigned int retval = itr_setting;
2509 switch (itr_setting) {
2510 case lowest_latency:
2511 /* handle TSO and jumbo frames */
2512 if (bytes / packets > 8000)
2513 retval = bulk_latency;
2514 else if ((packets < 5) && (bytes > 512))
2515 retval = low_latency;
2517 case low_latency: /* 50 usec aka 20000 ints/s */
2518 if (bytes > 10000) {
2519 /* this if handles the TSO accounting */
2520 if (bytes / packets > 8000)
2521 retval = bulk_latency;
2522 else if ((packets < 10) || ((bytes / packets) > 1200))
2523 retval = bulk_latency;
2524 else if ((packets > 35))
2525 retval = lowest_latency;
2526 } else if (bytes / packets > 2000) {
2527 retval = bulk_latency;
2528 } else if (packets <= 2 && bytes < 512) {
2529 retval = lowest_latency;
2532 case bulk_latency: /* 250 usec aka 4000 ints/s */
2533 if (bytes > 25000) {
2535 retval = low_latency;
2536 } else if (bytes < 6000) {
2537 retval = low_latency;
2545 static void e1000_set_itr(struct e1000_adapter *adapter)
2548 u32 new_itr = adapter->itr;
2550 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2551 if (adapter->link_speed != SPEED_1000) {
2557 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2562 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2563 adapter->total_tx_packets,
2564 adapter->total_tx_bytes);
2565 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2566 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2567 adapter->tx_itr = low_latency;
2569 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2570 adapter->total_rx_packets,
2571 adapter->total_rx_bytes);
2572 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2573 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2574 adapter->rx_itr = low_latency;
2576 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2578 /* counts and packets in update_itr are dependent on these numbers */
2579 switch (current_itr) {
2580 case lowest_latency:
2584 new_itr = 20000; /* aka hwitr = ~200 */
2594 if (new_itr != adapter->itr) {
2595 /* this attempts to bias the interrupt rate towards Bulk
2596 * by adding intermediate steps when interrupt rate is
2599 new_itr = new_itr > adapter->itr ?
2600 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
2601 adapter->itr = new_itr;
2602 adapter->rx_ring->itr_val = new_itr;
2603 if (adapter->msix_entries)
2604 adapter->rx_ring->set_itr = 1;
2606 e1000e_write_itr(adapter, new_itr);
2611 * e1000e_write_itr - write the ITR value to the appropriate registers
2612 * @adapter: address of board private structure
2613 * @itr: new ITR value to program
2615 * e1000e_write_itr determines if the adapter is in MSI-X mode
2616 * and, if so, writes the EITR registers with the ITR value.
2617 * Otherwise, it writes the ITR value into the ITR register.
2619 void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2621 struct e1000_hw *hw = &adapter->hw;
2622 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2624 if (adapter->msix_entries) {
2627 for (vector = 0; vector < adapter->num_vectors; vector++)
2628 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2635 * e1000_alloc_queues - Allocate memory for all rings
2636 * @adapter: board private structure to initialize
2638 static int e1000_alloc_queues(struct e1000_adapter *adapter)
2640 int size = sizeof(struct e1000_ring);
2642 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
2643 if (!adapter->tx_ring)
2645 adapter->tx_ring->count = adapter->tx_ring_count;
2646 adapter->tx_ring->adapter = adapter;
2648 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
2649 if (!adapter->rx_ring)
2651 adapter->rx_ring->count = adapter->rx_ring_count;
2652 adapter->rx_ring->adapter = adapter;
2656 e_err("Unable to allocate memory for queues\n");
2657 kfree(adapter->rx_ring);
2658 kfree(adapter->tx_ring);
2663 * e1000e_poll - NAPI Rx polling callback
2664 * @napi: struct associated with this polling callback
2665 * @budget: number of packets driver is allowed to process this poll
2667 static int e1000e_poll(struct napi_struct *napi, int budget)
2669 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2671 struct e1000_hw *hw = &adapter->hw;
2672 struct net_device *poll_dev = adapter->netdev;
2673 int tx_cleaned = 1, work_done = 0;
2675 adapter = netdev_priv(poll_dev);
2677 if (!adapter->msix_entries ||
2678 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2679 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
2681 adapter->clean_rx(adapter->rx_ring, &work_done, budget);
2683 if (!tx_cleaned || work_done == budget)
2686 /* Exit the polling mode, but don't re-enable interrupts if stack might
2687 * poll us due to busy-polling
2689 if (likely(napi_complete_done(napi, work_done))) {
2690 if (adapter->itr_setting & 3)
2691 e1000_set_itr(adapter);
2692 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2693 if (adapter->msix_entries)
2694 ew32(IMS, adapter->rx_ring->ims_val);
2696 e1000_irq_enable(adapter);
2703 static int e1000_vlan_rx_add_vid(struct net_device *netdev,
2704 __always_unused __be16 proto, u16 vid)
2706 struct e1000_adapter *adapter = netdev_priv(netdev);
2707 struct e1000_hw *hw = &adapter->hw;
2710 /* don't update vlan cookie if already programmed */
2711 if ((adapter->hw.mng_cookie.status &
2712 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2713 (vid == adapter->mng_vlan_id))
2716 /* add VID to filter table */
2717 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2718 index = (vid >> 5) & 0x7F;
2719 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2720 vfta |= BIT((vid & 0x1F));
2721 hw->mac.ops.write_vfta(hw, index, vfta);
2724 set_bit(vid, adapter->active_vlans);
2729 static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
2730 __always_unused __be16 proto, u16 vid)
2732 struct e1000_adapter *adapter = netdev_priv(netdev);
2733 struct e1000_hw *hw = &adapter->hw;
2736 if ((adapter->hw.mng_cookie.status &
2737 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2738 (vid == adapter->mng_vlan_id)) {
2739 /* release control to f/w */
2740 e1000e_release_hw_control(adapter);
2744 /* remove VID from filter table */
2745 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2746 index = (vid >> 5) & 0x7F;
2747 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2748 vfta &= ~BIT((vid & 0x1F));
2749 hw->mac.ops.write_vfta(hw, index, vfta);
2752 clear_bit(vid, adapter->active_vlans);
2758 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2759 * @adapter: board private structure to initialize
2761 static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2763 struct net_device *netdev = adapter->netdev;
2764 struct e1000_hw *hw = &adapter->hw;
2767 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2768 /* disable VLAN receive filtering */
2770 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2773 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2774 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
2775 adapter->mng_vlan_id);
2776 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2782 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2783 * @adapter: board private structure to initialize
2785 static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2787 struct e1000_hw *hw = &adapter->hw;
2790 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2791 /* enable VLAN receive filtering */
2793 rctl |= E1000_RCTL_VFE;
2794 rctl &= ~E1000_RCTL_CFIEN;
2800 * e1000e_vlan_strip_disable - helper to disable HW VLAN stripping
2801 * @adapter: board private structure to initialize
2803 static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2805 struct e1000_hw *hw = &adapter->hw;
2808 /* disable VLAN tag insert/strip */
2810 ctrl &= ~E1000_CTRL_VME;
2815 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2816 * @adapter: board private structure to initialize
2818 static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2820 struct e1000_hw *hw = &adapter->hw;
2823 /* enable VLAN tag insert/strip */
2825 ctrl |= E1000_CTRL_VME;
2829 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2831 struct net_device *netdev = adapter->netdev;
2832 u16 vid = adapter->hw.mng_cookie.vlan_id;
2833 u16 old_vid = adapter->mng_vlan_id;
2835 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2836 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
2837 adapter->mng_vlan_id = vid;
2840 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2841 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
2844 static void e1000_restore_vlan(struct e1000_adapter *adapter)
2848 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
2850 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
2851 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
2854 static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
2856 struct e1000_hw *hw = &adapter->hw;
2857 u32 manc, manc2h, mdef, i, j;
2859 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2864 /* enable receiving management packets to the host. this will probably
2865 * generate destination unreachable messages from the host OS, but
2866 * the packets will be handled on SMBUS
2868 manc |= E1000_MANC_EN_MNG2HOST;
2869 manc2h = er32(MANC2H);
2871 switch (hw->mac.type) {
2873 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2877 /* Check if IPMI pass-through decision filter already exists;
2880 for (i = 0, j = 0; i < 8; i++) {
2881 mdef = er32(MDEF(i));
2883 /* Ignore filters with anything other than IPMI ports */
2884 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2887 /* Enable this decision filter in MANC2H */
2894 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2897 /* Create new decision filter in an empty filter */
2898 for (i = 0, j = 0; i < 8; i++)
2899 if (er32(MDEF(i)) == 0) {
2900 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2901 E1000_MDEF_PORT_664));
2908 e_warn("Unable to create IPMI pass-through filter\n");
2912 ew32(MANC2H, manc2h);
2917 * e1000_configure_tx - Configure Transmit Unit after Reset
2918 * @adapter: board private structure
2920 * Configure the Tx unit of the MAC after a reset.
2922 static void e1000_configure_tx(struct e1000_adapter *adapter)
2924 struct e1000_hw *hw = &adapter->hw;
2925 struct e1000_ring *tx_ring = adapter->tx_ring;
2927 u32 tdlen, tctl, tarc;
2929 /* Setup the HW Tx Head and Tail descriptor pointers */
2930 tdba = tx_ring->dma;
2931 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2932 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2933 ew32(TDBAH(0), (tdba >> 32));
2934 ew32(TDLEN(0), tdlen);
2937 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2938 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
2940 writel(0, tx_ring->head);
2941 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2942 e1000e_update_tdt_wa(tx_ring, 0);
2944 writel(0, tx_ring->tail);
2946 /* Set the Tx Interrupt Delay register */
2947 ew32(TIDV, adapter->tx_int_delay);
2948 /* Tx irq moderation */
2949 ew32(TADV, adapter->tx_abs_int_delay);
2951 if (adapter->flags2 & FLAG2_DMA_BURST) {
2952 u32 txdctl = er32(TXDCTL(0));
2954 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2955 E1000_TXDCTL_WTHRESH);
2956 /* set up some performance related parameters to encourage the
2957 * hardware to use the bus more efficiently in bursts, depends
2958 * on the tx_int_delay to be enabled,
2959 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
2960 * hthresh = 1 ==> prefetch when one or more available
2961 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2962 * BEWARE: this seems to work but should be considered first if
2963 * there are Tx hangs or other Tx related bugs
2965 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2966 ew32(TXDCTL(0), txdctl);
2968 /* erratum work around: set txdctl the same for both queues */
2969 ew32(TXDCTL(1), er32(TXDCTL(0)));
2971 /* Program the Transmit Control Register */
2973 tctl &= ~E1000_TCTL_CT;
2974 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2975 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2977 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
2978 tarc = er32(TARC(0));
2979 /* set the speed mode bit, we'll clear it if we're not at
2980 * gigabit link later
2982 #define SPEED_MODE_BIT BIT(21)
2983 tarc |= SPEED_MODE_BIT;
2984 ew32(TARC(0), tarc);
2987 /* errata: program both queues to unweighted RR */
2988 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
2989 tarc = er32(TARC(0));
2991 ew32(TARC(0), tarc);
2992 tarc = er32(TARC(1));
2994 ew32(TARC(1), tarc);
2997 /* Setup Transmit Descriptor Settings for eop descriptor */
2998 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
3000 /* only set IDE if we are delaying interrupts using the timers */
3001 if (adapter->tx_int_delay)
3002 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
3004 /* enable Report Status bit */
3005 adapter->txd_cmd |= E1000_TXD_CMD_RS;
3009 hw->mac.ops.config_collision_dist(hw);
3011 /* SPT and KBL Si errata workaround to avoid data corruption */
3012 if (hw->mac.type == e1000_pch_spt) {
3015 reg_val = er32(IOSFPC);
3016 reg_val |= E1000_RCTL_RDMTS_HEX;
3017 ew32(IOSFPC, reg_val);
3019 reg_val = er32(TARC(0));
3020 /* SPT and KBL Si errata workaround to avoid Tx hang.
3021 * Dropping the number of outstanding requests from
3022 * 3 to 2 in order to avoid a buffer overrun.
3024 reg_val &= ~E1000_TARC0_CB_MULTIQ_3_REQ;
3025 reg_val |= E1000_TARC0_CB_MULTIQ_2_REQ;
3026 ew32(TARC(0), reg_val);
3030 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
3031 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
3034 * e1000_setup_rctl - configure the receive control registers
3035 * @adapter: Board private structure
3037 static void e1000_setup_rctl(struct e1000_adapter *adapter)
3039 struct e1000_hw *hw = &adapter->hw;
3043 /* Workaround Si errata on PCHx - configure jumbo frame flow.
3044 * If jumbo frames not set, program related MAC/PHY registers
3047 if (hw->mac.type >= e1000_pch2lan) {
3050 if (adapter->netdev->mtu > ETH_DATA_LEN)
3051 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
3053 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
3056 e_dbg("failed to enable|disable jumbo frame workaround mode\n");
3059 /* Program MC offset vector base */
3061 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3062 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
3063 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3064 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3066 /* Do not Store bad packets */
3067 rctl &= ~E1000_RCTL_SBP;
3069 /* Enable Long Packet receive */
3070 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3071 rctl &= ~E1000_RCTL_LPE;
3073 rctl |= E1000_RCTL_LPE;
3075 /* Some systems expect that the CRC is included in SMBUS traffic. The
3076 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3077 * host memory when this is enabled
3079 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3080 rctl |= E1000_RCTL_SECRC;
3082 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3083 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3086 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3089 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3091 e1e_rphy(hw, 22, &phy_data);
3093 phy_data |= BIT(14);
3094 e1e_wphy(hw, 0x10, 0x2823);
3095 e1e_wphy(hw, 0x11, 0x0003);
3096 e1e_wphy(hw, 22, phy_data);
3099 /* Setup buffer sizes */
3100 rctl &= ~E1000_RCTL_SZ_4096;
3101 rctl |= E1000_RCTL_BSEX;
3102 switch (adapter->rx_buffer_len) {
3105 rctl |= E1000_RCTL_SZ_2048;
3106 rctl &= ~E1000_RCTL_BSEX;
3109 rctl |= E1000_RCTL_SZ_4096;
3112 rctl |= E1000_RCTL_SZ_8192;
3115 rctl |= E1000_RCTL_SZ_16384;
3119 /* Enable Extended Status in all Receive Descriptors */
3120 rfctl = er32(RFCTL);
3121 rfctl |= E1000_RFCTL_EXTEN;
3124 /* 82571 and greater support packet-split where the protocol
3125 * header is placed in skb->data and the packet data is
3126 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3127 * In the case of a non-split, skb->data is linearly filled,
3128 * followed by the page buffers. Therefore, skb->data is
3129 * sized to hold the largest protocol header.
3131 * allocations using alloc_page take too long for regular MTU
3132 * so only enable packet split for jumbo frames
3134 * Using pages when the page size is greater than 16k wastes
3135 * a lot of memory, since we allocate 3 pages at all times
3138 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
3139 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
3140 adapter->rx_ps_pages = pages;
3142 adapter->rx_ps_pages = 0;
3144 if (adapter->rx_ps_pages) {
3147 /* Enable Packet split descriptors */
3148 rctl |= E1000_RCTL_DTYP_PS;
3150 psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
3152 switch (adapter->rx_ps_pages) {
3154 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
3157 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
3160 psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
3164 ew32(PSRCTL, psrctl);
3167 /* This is useful for sniffing bad packets. */
3168 if (adapter->netdev->features & NETIF_F_RXALL) {
3169 /* UPE and MPE will be handled by normal PROMISC logic
3170 * in e1000e_set_rx_mode
3172 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3173 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3174 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3176 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3177 E1000_RCTL_DPF | /* Allow filtered pause */
3178 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3179 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3180 * and that breaks VLANs.
3185 /* just started the receive unit, no need to restart */
3186 adapter->flags &= ~FLAG_RESTART_NOW;
3190 * e1000_configure_rx - Configure Receive Unit after Reset
3191 * @adapter: board private structure
3193 * Configure the Rx unit of the MAC after a reset.
3195 static void e1000_configure_rx(struct e1000_adapter *adapter)
3197 struct e1000_hw *hw = &adapter->hw;
3198 struct e1000_ring *rx_ring = adapter->rx_ring;
3200 u32 rdlen, rctl, rxcsum, ctrl_ext;
3202 if (adapter->rx_ps_pages) {
3203 /* this is a 32 byte descriptor */
3204 rdlen = rx_ring->count *
3205 sizeof(union e1000_rx_desc_packet_split);
3206 adapter->clean_rx = e1000_clean_rx_irq_ps;
3207 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
3208 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
3209 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3210 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3211 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
3213 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3214 adapter->clean_rx = e1000_clean_rx_irq;
3215 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3218 /* disable receives while setting up the descriptors */
3220 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3221 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3223 usleep_range(10000, 11000);
3225 if (adapter->flags2 & FLAG2_DMA_BURST) {
3226 /* set the writeback threshold (only takes effect if the RDTR
3227 * is set). set GRAN=1 and write back up to 0x4 worth, and
3228 * enable prefetching of 0x20 Rx descriptors
3234 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3235 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3238 /* set the Receive Delay Timer Register */
3239 ew32(RDTR, adapter->rx_int_delay);
3241 /* irq moderation */
3242 ew32(RADV, adapter->rx_abs_int_delay);
3243 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
3244 e1000e_write_itr(adapter, adapter->itr);
3246 ctrl_ext = er32(CTRL_EXT);
3247 /* Auto-Mask interrupts upon ICR access */
3248 ctrl_ext |= E1000_CTRL_EXT_IAME;
3249 ew32(IAM, 0xffffffff);
3250 ew32(CTRL_EXT, ctrl_ext);
3253 /* Setup the HW Rx Head and Tail Descriptor Pointers and
3254 * the Base and Length of the Rx Descriptor Ring
3256 rdba = rx_ring->dma;
3257 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3258 ew32(RDBAH(0), (rdba >> 32));
3259 ew32(RDLEN(0), rdlen);
3262 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3263 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
3265 writel(0, rx_ring->head);
3266 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
3267 e1000e_update_rdt_wa(rx_ring, 0);
3269 writel(0, rx_ring->tail);
3271 /* Enable Receive Checksum Offload for TCP and UDP */
3272 rxcsum = er32(RXCSUM);
3273 if (adapter->netdev->features & NETIF_F_RXCSUM)
3274 rxcsum |= E1000_RXCSUM_TUOFL;
3276 rxcsum &= ~E1000_RXCSUM_TUOFL;
3277 ew32(RXCSUM, rxcsum);
3279 /* With jumbo frames, excessive C-state transition latencies result
3280 * in dropped transactions.
3282 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3284 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3285 adapter->max_frame_size) * 8 / 1000;
3287 if (adapter->flags & FLAG_IS_ICH) {
3288 u32 rxdctl = er32(RXDCTL(0));
3290 ew32(RXDCTL(0), rxdctl | 0x3 | BIT(8));
3293 dev_info(&adapter->pdev->dev,
3294 "Some CPU C-states have been disabled in order to enable jumbo frames\n");
3295 cpu_latency_qos_update_request(&adapter->pm_qos_req, lat);
3297 cpu_latency_qos_update_request(&adapter->pm_qos_req,
3298 PM_QOS_DEFAULT_VALUE);
3301 /* Enable Receives */
3306 * e1000e_write_mc_addr_list - write multicast addresses to MTA
3307 * @netdev: network interface device structure
3309 * Writes multicast address list to the MTA hash table.
3310 * Returns: -ENOMEM on failure
3311 * 0 on no addresses written
3312 * X on writing X addresses to MTA
3314 static int e1000e_write_mc_addr_list(struct net_device *netdev)
3316 struct e1000_adapter *adapter = netdev_priv(netdev);
3317 struct e1000_hw *hw = &adapter->hw;
3318 struct netdev_hw_addr *ha;
3322 if (netdev_mc_empty(netdev)) {
3323 /* nothing to program, so clear mc list */
3324 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3328 mta_list = kcalloc(netdev_mc_count(netdev), ETH_ALEN, GFP_ATOMIC);
3332 /* update_mc_addr_list expects a packed array of only addresses. */
3334 netdev_for_each_mc_addr(ha, netdev)
3335 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3337 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3340 return netdev_mc_count(netdev);
3344 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3345 * @netdev: network interface device structure
3347 * Writes unicast address list to the RAR table.
3348 * Returns: -ENOMEM on failure/insufficient address space
3349 * 0 on no addresses written
3350 * X on writing X addresses to the RAR table
3352 static int e1000e_write_uc_addr_list(struct net_device *netdev)
3354 struct e1000_adapter *adapter = netdev_priv(netdev);
3355 struct e1000_hw *hw = &adapter->hw;
3356 unsigned int rar_entries;
3359 rar_entries = hw->mac.ops.rar_get_count(hw);
3361 /* save a rar entry for our hardware address */
3364 /* save a rar entry for the LAA workaround */
3365 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3368 /* return ENOMEM indicating insufficient memory for addresses */
3369 if (netdev_uc_count(netdev) > rar_entries)
3372 if (!netdev_uc_empty(netdev) && rar_entries) {
3373 struct netdev_hw_addr *ha;
3375 /* write the addresses in reverse order to avoid write
3378 netdev_for_each_uc_addr(ha, netdev) {
3383 ret_val = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
3390 /* zero out the remaining RAR entries not used above */
3391 for (; rar_entries > 0; rar_entries--) {
3392 ew32(RAH(rar_entries), 0);
3393 ew32(RAL(rar_entries), 0);
3401 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3402 * @netdev: network interface device structure
3404 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3405 * address list or the network interface flags are updated. This routine is
3406 * responsible for configuring the hardware for proper unicast, multicast,
3407 * promiscuous mode, and all-multi behavior.
3409 static void e1000e_set_rx_mode(struct net_device *netdev)
3411 struct e1000_adapter *adapter = netdev_priv(netdev);
3412 struct e1000_hw *hw = &adapter->hw;
3415 if (pm_runtime_suspended(netdev->dev.parent))
3418 /* Check for Promiscuous and All Multicast modes */
3421 /* clear the affected bits */
3422 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3424 if (netdev->flags & IFF_PROMISC) {
3425 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
3426 /* Do not hardware filter VLANs in promisc mode */
3427 e1000e_vlan_filter_disable(adapter);
3431 if (netdev->flags & IFF_ALLMULTI) {
3432 rctl |= E1000_RCTL_MPE;
3434 /* Write addresses to the MTA, if the attempt fails
3435 * then we should just turn on promiscuous mode so
3436 * that we can at least receive multicast traffic
3438 count = e1000e_write_mc_addr_list(netdev);
3440 rctl |= E1000_RCTL_MPE;
3442 e1000e_vlan_filter_enable(adapter);
3443 /* Write addresses to available RAR registers, if there is not
3444 * sufficient space to store all the addresses then enable
3445 * unicast promiscuous mode
3447 count = e1000e_write_uc_addr_list(netdev);
3449 rctl |= E1000_RCTL_UPE;
3454 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
3455 e1000e_vlan_strip_enable(adapter);
3457 e1000e_vlan_strip_disable(adapter);
3460 static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3462 struct e1000_hw *hw = &adapter->hw;
3467 netdev_rss_key_fill(rss_key, sizeof(rss_key));
3468 for (i = 0; i < 10; i++)
3469 ew32(RSSRK(i), rss_key[i]);
3471 /* Direct all traffic to queue 0 */
3472 for (i = 0; i < 32; i++)
3475 /* Disable raw packet checksumming so that RSS hash is placed in
3476 * descriptor on writeback.
3478 rxcsum = er32(RXCSUM);
3479 rxcsum |= E1000_RXCSUM_PCSD;
3481 ew32(RXCSUM, rxcsum);
3483 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3484 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3485 E1000_MRQC_RSS_FIELD_IPV6 |
3486 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3487 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3493 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3494 * @adapter: board private structure
3495 * @timinca: pointer to returned time increment attributes
3497 * Get attributes for incrementing the System Time Register SYSTIML/H at
3498 * the default base frequency, and set the cyclecounter shift value.
3500 s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
3502 struct e1000_hw *hw = &adapter->hw;
3503 u32 incvalue, incperiod, shift;
3505 /* Make sure clock is enabled on I217/I218/I219 before checking
3508 if ((hw->mac.type >= e1000_pch_lpt) &&
3509 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3510 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3511 u32 fextnvm7 = er32(FEXTNVM7);
3513 if (!(fextnvm7 & BIT(0))) {
3514 ew32(FEXTNVM7, fextnvm7 | BIT(0));
3519 switch (hw->mac.type) {
3521 /* Stable 96MHz frequency */
3522 incperiod = INCPERIOD_96MHZ;
3523 incvalue = INCVALUE_96MHZ;
3524 shift = INCVALUE_SHIFT_96MHZ;
3525 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
3528 if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
3529 /* Stable 96MHz frequency */
3530 incperiod = INCPERIOD_96MHZ;
3531 incvalue = INCVALUE_96MHZ;
3532 shift = INCVALUE_SHIFT_96MHZ;
3533 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
3535 /* Stable 25MHz frequency */
3536 incperiod = INCPERIOD_25MHZ;
3537 incvalue = INCVALUE_25MHZ;
3538 shift = INCVALUE_SHIFT_25MHZ;
3539 adapter->cc.shift = shift;
3543 /* Stable 24MHz frequency */
3544 incperiod = INCPERIOD_24MHZ;
3545 incvalue = INCVALUE_24MHZ;
3546 shift = INCVALUE_SHIFT_24MHZ;
3547 adapter->cc.shift = shift;
3554 if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
3555 /* Stable 24MHz frequency */
3556 incperiod = INCPERIOD_24MHZ;
3557 incvalue = INCVALUE_24MHZ;
3558 shift = INCVALUE_SHIFT_24MHZ;
3559 adapter->cc.shift = shift;
3561 /* Stable 38400KHz frequency */
3562 incperiod = INCPERIOD_38400KHZ;
3563 incvalue = INCVALUE_38400KHZ;
3564 shift = INCVALUE_SHIFT_38400KHZ;
3565 adapter->cc.shift = shift;
3570 /* Stable 25MHz frequency */
3571 incperiod = INCPERIOD_25MHZ;
3572 incvalue = INCVALUE_25MHZ;
3573 shift = INCVALUE_SHIFT_25MHZ;
3574 adapter->cc.shift = shift;
3580 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3581 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3587 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3588 * @adapter: board private structure
3589 * @config: timestamp configuration
3591 * Outgoing time stamping can be enabled and disabled. Play nice and
3592 * disable it when requested, although it shouldn't cause any overhead
3593 * when no packet needs it. At most one packet in the queue may be
3594 * marked for time stamping, otherwise it would be impossible to tell
3595 * for sure to which packet the hardware time stamp belongs.
3597 * Incoming time stamping has to be configured via the hardware filters.
3598 * Not all combinations are supported, in particular event type has to be
3599 * specified. Matching the kind of event packet is not supported, with the
3600 * exception of "all V2 events regardless of level 2 or 4".
3602 static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
3603 struct hwtstamp_config *config)
3605 struct e1000_hw *hw = &adapter->hw;
3606 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3607 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
3614 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3617 /* flags reserved for future extensions - must be zero */
3621 switch (config->tx_type) {
3622 case HWTSTAMP_TX_OFF:
3625 case HWTSTAMP_TX_ON:
3631 switch (config->rx_filter) {
3632 case HWTSTAMP_FILTER_NONE:
3635 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3636 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3637 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3640 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3641 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3642 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3645 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3646 /* Also time stamps V2 L2 Path Delay Request/Response */
3647 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3648 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3651 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3652 /* Also time stamps V2 L2 Path Delay Request/Response. */
3653 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3654 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3657 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3658 /* Hardware cannot filter just V2 L4 Sync messages */
3660 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3661 /* Also time stamps V2 Path Delay Request/Response. */
3662 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3663 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3667 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3668 /* Hardware cannot filter just V2 L4 Delay Request messages */
3670 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3671 /* Also time stamps V2 Path Delay Request/Response. */
3672 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3673 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3677 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3678 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3679 /* Hardware cannot filter just V2 L4 or L2 Event messages */
3681 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3682 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3683 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3687 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3688 /* For V1, the hardware can only filter Sync messages or
3689 * Delay Request messages but not both so fall-through to
3690 * time stamp all packets.
3693 case HWTSTAMP_FILTER_NTP_ALL:
3694 case HWTSTAMP_FILTER_ALL:
3697 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3698 config->rx_filter = HWTSTAMP_FILTER_ALL;
3704 adapter->hwtstamp_config = *config;
3706 /* enable/disable Tx h/w time stamping */
3707 regval = er32(TSYNCTXCTL);
3708 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3709 regval |= tsync_tx_ctl;
3710 ew32(TSYNCTXCTL, regval);
3711 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3712 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3713 e_err("Timesync Tx Control register not set as expected\n");
3717 /* enable/disable Rx h/w time stamping */
3718 regval = er32(TSYNCRXCTL);
3719 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3720 regval |= tsync_rx_ctl;
3721 ew32(TSYNCRXCTL, regval);
3722 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3723 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3724 (regval & (E1000_TSYNCRXCTL_ENABLED |
3725 E1000_TSYNCRXCTL_TYPE_MASK))) {
3726 e_err("Timesync Rx Control register not set as expected\n");
3730 /* L2: define ethertype filter for time stamped packets */
3732 rxmtrl |= ETH_P_1588;
3734 /* define which PTP packets get time stamped */
3735 ew32(RXMTRL, rxmtrl);
3737 /* Filter by destination port */
3739 rxudp = PTP_EV_PORT;
3740 cpu_to_be16s(&rxudp);
3746 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
3754 * e1000_configure - configure the hardware for Rx and Tx
3755 * @adapter: private board structure
3757 static void e1000_configure(struct e1000_adapter *adapter)
3759 struct e1000_ring *rx_ring = adapter->rx_ring;
3761 e1000e_set_rx_mode(adapter->netdev);
3763 e1000_restore_vlan(adapter);
3764 e1000_init_manageability_pt(adapter);
3766 e1000_configure_tx(adapter);
3768 if (adapter->netdev->features & NETIF_F_RXHASH)
3769 e1000e_setup_rss_hash(adapter);
3770 e1000_setup_rctl(adapter);
3771 e1000_configure_rx(adapter);
3772 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
3776 * e1000e_power_up_phy - restore link in case the phy was powered down
3777 * @adapter: address of board private structure
3779 * The phy may be powered down to save power and turn off link when the
3780 * driver is unloaded and wake on lan is not enabled (among others)
3781 * *** this routine MUST be followed by a call to e1000e_reset ***
3783 void e1000e_power_up_phy(struct e1000_adapter *adapter)
3785 if (adapter->hw.phy.ops.power_up)
3786 adapter->hw.phy.ops.power_up(&adapter->hw);
3788 adapter->hw.mac.ops.setup_link(&adapter->hw);
3792 * e1000_power_down_phy - Power down the PHY
3793 * @adapter: board private structure
3795 * Power down the PHY so no link is implied when interface is down.
3796 * The PHY cannot be powered down if management or WoL is active.
3798 static void e1000_power_down_phy(struct e1000_adapter *adapter)
3800 if (adapter->hw.phy.ops.power_down)
3801 adapter->hw.phy.ops.power_down(&adapter->hw);
3805 * e1000_flush_tx_ring - remove all descriptors from the tx_ring
3806 * @adapter: board private structure
3808 * We want to clear all pending descriptors from the TX ring.
3809 * zeroing happens when the HW reads the regs. We assign the ring itself as
3810 * the data of the next descriptor. We don't care about the data we are about
3813 static void e1000_flush_tx_ring(struct e1000_adapter *adapter)
3815 struct e1000_hw *hw = &adapter->hw;
3816 struct e1000_ring *tx_ring = adapter->tx_ring;
3817 struct e1000_tx_desc *tx_desc = NULL;
3818 u32 tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS;
3822 ew32(TCTL, tctl | E1000_TCTL_EN);
3824 BUG_ON(tdt != tx_ring->next_to_use);
3825 tx_desc = E1000_TX_DESC(*tx_ring, tx_ring->next_to_use);
3826 tx_desc->buffer_addr = cpu_to_le64(tx_ring->dma);
3828 tx_desc->lower.data = cpu_to_le32(txd_lower | size);
3829 tx_desc->upper.data = 0;
3830 /* flush descriptors to memory before notifying the HW */
3832 tx_ring->next_to_use++;
3833 if (tx_ring->next_to_use == tx_ring->count)
3834 tx_ring->next_to_use = 0;
3835 ew32(TDT(0), tx_ring->next_to_use);
3836 usleep_range(200, 250);
3840 * e1000_flush_rx_ring - remove all descriptors from the rx_ring
3841 * @adapter: board private structure
3843 * Mark all descriptors in the RX ring as consumed and disable the rx ring
3845 static void e1000_flush_rx_ring(struct e1000_adapter *adapter)
3848 struct e1000_hw *hw = &adapter->hw;
3851 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3853 usleep_range(100, 150);
3855 rxdctl = er32(RXDCTL(0));
3856 /* zero the lower 14 bits (prefetch and host thresholds) */
3857 rxdctl &= 0xffffc000;
3859 /* update thresholds: prefetch threshold to 31, host threshold to 1
3860 * and make sure the granularity is "descriptors" and not "cache lines"
3862 rxdctl |= (0x1F | BIT(8) | E1000_RXDCTL_THRESH_UNIT_DESC);
3864 ew32(RXDCTL(0), rxdctl);
3865 /* momentarily enable the RX ring for the changes to take effect */
3866 ew32(RCTL, rctl | E1000_RCTL_EN);
3868 usleep_range(100, 150);
3869 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3873 * e1000_flush_desc_rings - remove all descriptors from the descriptor rings
3874 * @adapter: board private structure
3876 * In i219, the descriptor rings must be emptied before resetting the HW
3877 * or before changing the device state to D3 during runtime (runtime PM).
3879 * Failure to do this will cause the HW to enter a unit hang state which can
3880 * only be released by PCI reset on the device
3884 static void e1000_flush_desc_rings(struct e1000_adapter *adapter)
3887 u32 fext_nvm11, tdlen;
3888 struct e1000_hw *hw = &adapter->hw;
3890 /* First, disable MULR fix in FEXTNVM11 */
3891 fext_nvm11 = er32(FEXTNVM11);
3892 fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
3893 ew32(FEXTNVM11, fext_nvm11);
3894 /* do nothing if we're not in faulty state, or if the queue is empty */
3895 tdlen = er32(TDLEN(0));
3896 pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
3898 if (!(hang_state & FLUSH_DESC_REQUIRED) || !tdlen)
3900 e1000_flush_tx_ring(adapter);
3901 /* recheck, maybe the fault is caused by the rx ring */
3902 pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
3904 if (hang_state & FLUSH_DESC_REQUIRED)
3905 e1000_flush_rx_ring(adapter);
3909 * e1000e_systim_reset - reset the timesync registers after a hardware reset
3910 * @adapter: board private structure
3912 * When the MAC is reset, all hardware bits for timesync will be reset to the
3913 * default values. This function will restore the settings last in place.
3914 * Since the clock SYSTIME registers are reset, we will simply restore the
3915 * cyclecounter to the kernel real clock time.
3917 static void e1000e_systim_reset(struct e1000_adapter *adapter)
3919 struct ptp_clock_info *info = &adapter->ptp_clock_info;
3920 struct e1000_hw *hw = &adapter->hw;
3921 unsigned long flags;
3925 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3928 if (info->adjfreq) {
3929 /* restore the previous ptp frequency delta */
3930 ret_val = info->adjfreq(info, adapter->ptp_delta);
3932 /* set the default base frequency if no adjustment possible */
3933 ret_val = e1000e_get_base_timinca(adapter, &timinca);
3935 ew32(TIMINCA, timinca);
3939 dev_warn(&adapter->pdev->dev,
3940 "Failed to restore TIMINCA clock rate delta: %d\n",
3945 /* reset the systim ns time counter */
3946 spin_lock_irqsave(&adapter->systim_lock, flags);
3947 timecounter_init(&adapter->tc, &adapter->cc,
3948 ktime_to_ns(ktime_get_real()));
3949 spin_unlock_irqrestore(&adapter->systim_lock, flags);
3951 /* restore the previous hwtstamp configuration settings */
3952 e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
3956 * e1000e_reset - bring the hardware into a known good state
3957 * @adapter: board private structure
3959 * This function boots the hardware and enables some settings that
3960 * require a configuration cycle of the hardware - those cannot be
3961 * set/changed during runtime. After reset the device needs to be
3962 * properly configured for Rx, Tx etc.
3964 void e1000e_reset(struct e1000_adapter *adapter)
3966 struct e1000_mac_info *mac = &adapter->hw.mac;
3967 struct e1000_fc_info *fc = &adapter->hw.fc;
3968 struct e1000_hw *hw = &adapter->hw;
3969 u32 tx_space, min_tx_space, min_rx_space;
3970 u32 pba = adapter->pba;
3973 /* reset Packet Buffer Allocation to default */
3976 if (adapter->max_frame_size > (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) {
3977 /* To maintain wire speed transmits, the Tx FIFO should be
3978 * large enough to accommodate two full transmit packets,
3979 * rounded up to the next 1KB and expressed in KB. Likewise,
3980 * the Rx FIFO should be large enough to accommodate at least
3981 * one full receive packet and is similarly rounded up and
3985 /* upper 16 bits has Tx packet buffer allocation size in KB */
3986 tx_space = pba >> 16;
3987 /* lower 16 bits has Rx packet buffer allocation size in KB */
3989 /* the Tx fifo also stores 16 bytes of information about the Tx
3990 * but don't include ethernet FCS because hardware appends it
3992 min_tx_space = (adapter->max_frame_size +
3993 sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
3994 min_tx_space = ALIGN(min_tx_space, 1024);
3995 min_tx_space >>= 10;
3996 /* software strips receive CRC, so leave room for it */
3997 min_rx_space = adapter->max_frame_size;
3998 min_rx_space = ALIGN(min_rx_space, 1024);
3999 min_rx_space >>= 10;
4001 /* If current Tx allocation is less than the min Tx FIFO size,
4002 * and the min Tx FIFO size is less than the current Rx FIFO
4003 * allocation, take space away from current Rx allocation
4005 if ((tx_space < min_tx_space) &&
4006 ((min_tx_space - tx_space) < pba)) {
4007 pba -= min_tx_space - tx_space;
4009 /* if short on Rx space, Rx wins and must trump Tx
4012 if (pba < min_rx_space)
4019 /* flow control settings
4021 * The high water mark must be low enough to fit one full frame
4022 * (or the size used for early receive) above it in the Rx FIFO.
4023 * Set it to the lower of:
4024 * - 90% of the Rx FIFO size, and
4025 * - the full Rx FIFO size minus one full frame
4027 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
4028 fc->pause_time = 0xFFFF;
4030 fc->pause_time = E1000_FC_PAUSE_TIME;
4031 fc->send_xon = true;
4032 fc->current_mode = fc->requested_mode;
4034 switch (hw->mac.type) {
4036 case e1000_ich10lan:
4037 if (adapter->netdev->mtu > ETH_DATA_LEN) {
4040 fc->high_water = 0x2800;
4041 fc->low_water = fc->high_water - 8;
4046 hwm = min(((pba << 10) * 9 / 10),
4047 ((pba << 10) - adapter->max_frame_size));
4049 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
4050 fc->low_water = fc->high_water - 8;
4053 /* Workaround PCH LOM adapter hangs with certain network
4054 * loads. If hangs persist, try disabling Tx flow control.
4056 if (adapter->netdev->mtu > ETH_DATA_LEN) {
4057 fc->high_water = 0x3500;
4058 fc->low_water = 0x1500;
4060 fc->high_water = 0x5000;
4061 fc->low_water = 0x3000;
4063 fc->refresh_time = 0x1000;
4073 fc->refresh_time = 0xFFFF;
4074 fc->pause_time = 0xFFFF;
4076 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
4077 fc->high_water = 0x05C20;
4078 fc->low_water = 0x05048;
4084 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
4085 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
4089 /* Alignment of Tx data is on an arbitrary byte boundary with the
4090 * maximum size per Tx descriptor limited only to the transmit
4091 * allocation of the packet buffer minus 96 bytes with an upper
4092 * limit of 24KB due to receive synchronization limitations.
4094 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
4097 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
4098 * fit in receive buffer.
4100 if (adapter->itr_setting & 0x3) {
4101 if ((adapter->max_frame_size * 2) > (pba << 10)) {
4102 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
4103 dev_info(&adapter->pdev->dev,
4104 "Interrupt Throttle Rate off\n");
4105 adapter->flags2 |= FLAG2_DISABLE_AIM;
4106 e1000e_write_itr(adapter, 0);
4108 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
4109 dev_info(&adapter->pdev->dev,
4110 "Interrupt Throttle Rate on\n");
4111 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
4112 adapter->itr = 20000;
4113 e1000e_write_itr(adapter, adapter->itr);
4117 if (hw->mac.type >= e1000_pch_spt)
4118 e1000_flush_desc_rings(adapter);
4119 /* Allow time for pending master requests to run */
4120 mac->ops.reset_hw(hw);
4122 /* For parts with AMT enabled, let the firmware know
4123 * that the network interface is in control
4125 if (adapter->flags & FLAG_HAS_AMT)
4126 e1000e_get_hw_control(adapter);
4130 if (mac->ops.init_hw(hw))
4131 e_err("Hardware Error\n");
4133 e1000_update_mng_vlan(adapter);
4135 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
4136 ew32(VET, ETH_P_8021Q);
4138 e1000e_reset_adaptive(hw);
4140 /* restore systim and hwtstamp settings */
4141 e1000e_systim_reset(adapter);
4143 /* Set EEE advertisement as appropriate */
4144 if (adapter->flags2 & FLAG2_HAS_EEE) {
4148 switch (hw->phy.type) {
4149 case e1000_phy_82579:
4150 adv_addr = I82579_EEE_ADVERTISEMENT;
4152 case e1000_phy_i217:
4153 adv_addr = I217_EEE_ADVERTISEMENT;
4156 dev_err(&adapter->pdev->dev,
4157 "Invalid PHY type setting EEE advertisement\n");
4161 ret_val = hw->phy.ops.acquire(hw);
4163 dev_err(&adapter->pdev->dev,
4164 "EEE advertisement - unable to acquire PHY\n");
4168 e1000_write_emi_reg_locked(hw, adv_addr,
4169 hw->dev_spec.ich8lan.eee_disable ?
4170 0 : adapter->eee_advert);
4172 hw->phy.ops.release(hw);
4175 if (!netif_running(adapter->netdev) &&
4176 !test_bit(__E1000_TESTING, &adapter->state))
4177 e1000_power_down_phy(adapter);
4179 e1000_get_phy_info(hw);
4181 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
4182 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
4184 /* speed up time to link by disabling smart power down, ignore
4185 * the return value of this function because there is nothing
4186 * different we would do if it failed
4188 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
4189 phy_data &= ~IGP02E1000_PM_SPD;
4190 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
4192 if (hw->mac.type >= e1000_pch_spt && adapter->int_mode == 0) {
4195 /* Fextnvm7 @ 0xe4[2] = 1 */
4196 reg = er32(FEXTNVM7);
4197 reg |= E1000_FEXTNVM7_SIDE_CLK_UNGATE;
4198 ew32(FEXTNVM7, reg);
4199 /* Fextnvm9 @ 0x5bb4[13:12] = 11 */
4200 reg = er32(FEXTNVM9);
4201 reg |= E1000_FEXTNVM9_IOSFSB_CLKGATE_DIS |
4202 E1000_FEXTNVM9_IOSFSB_CLKREQ_DIS;
4203 ew32(FEXTNVM9, reg);
4209 * e1000e_trigger_lsc - trigger an LSC interrupt
4212 * Fire a link status change interrupt to start the watchdog.
4214 static void e1000e_trigger_lsc(struct e1000_adapter *adapter)
4216 struct e1000_hw *hw = &adapter->hw;
4218 if (adapter->msix_entries)
4219 ew32(ICS, E1000_ICS_LSC | E1000_ICS_OTHER);
4221 ew32(ICS, E1000_ICS_LSC);
4224 void e1000e_up(struct e1000_adapter *adapter)
4226 /* hardware has been reset, we need to reload some things */
4227 e1000_configure(adapter);
4229 clear_bit(__E1000_DOWN, &adapter->state);
4231 if (adapter->msix_entries)
4232 e1000_configure_msix(adapter);
4233 e1000_irq_enable(adapter);
4235 /* Tx queue started by watchdog timer when link is up */
4237 e1000e_trigger_lsc(adapter);
4240 static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
4242 struct e1000_hw *hw = &adapter->hw;
4244 if (!(adapter->flags2 & FLAG2_DMA_BURST))
4247 /* flush pending descriptor writebacks to memory */
4248 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4249 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4251 /* execute the writes immediately */
4254 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
4255 * write is successful
4257 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4258 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4260 /* execute the writes immediately */
4264 static void e1000e_update_stats(struct e1000_adapter *adapter);
4267 * e1000e_down - quiesce the device and optionally reset the hardware
4268 * @adapter: board private structure
4269 * @reset: boolean flag to reset the hardware or not
4271 void e1000e_down(struct e1000_adapter *adapter, bool reset)
4273 struct net_device *netdev = adapter->netdev;
4274 struct e1000_hw *hw = &adapter->hw;
4277 /* signal that we're down so the interrupt handler does not
4278 * reschedule our watchdog timer
4280 set_bit(__E1000_DOWN, &adapter->state);
4282 netif_carrier_off(netdev);
4284 /* disable receives in the hardware */
4286 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
4287 ew32(RCTL, rctl & ~E1000_RCTL_EN);
4288 /* flush and sleep below */
4290 netif_stop_queue(netdev);
4292 /* disable transmits in the hardware */
4294 tctl &= ~E1000_TCTL_EN;
4297 /* flush both disables and wait for them to finish */
4299 usleep_range(10000, 11000);
4301 e1000_irq_disable(adapter);
4303 napi_synchronize(&adapter->napi);
4305 del_timer_sync(&adapter->watchdog_timer);
4306 del_timer_sync(&adapter->phy_info_timer);
4308 spin_lock(&adapter->stats64_lock);
4309 e1000e_update_stats(adapter);
4310 spin_unlock(&adapter->stats64_lock);
4312 e1000e_flush_descriptors(adapter);
4314 adapter->link_speed = 0;
4315 adapter->link_duplex = 0;
4317 /* Disable Si errata workaround on PCHx for jumbo frame flow */
4318 if ((hw->mac.type >= e1000_pch2lan) &&
4319 (adapter->netdev->mtu > ETH_DATA_LEN) &&
4320 e1000_lv_jumbo_workaround_ich8lan(hw, false))
4321 e_dbg("failed to disable jumbo frame workaround mode\n");
4323 if (!pci_channel_offline(adapter->pdev)) {
4325 e1000e_reset(adapter);
4326 else if (hw->mac.type >= e1000_pch_spt)
4327 e1000_flush_desc_rings(adapter);
4329 e1000_clean_tx_ring(adapter->tx_ring);
4330 e1000_clean_rx_ring(adapter->rx_ring);
4333 void e1000e_reinit_locked(struct e1000_adapter *adapter)
4336 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4337 usleep_range(1000, 1100);
4338 e1000e_down(adapter, true);
4340 clear_bit(__E1000_RESETTING, &adapter->state);
4344 * e1000e_sanitize_systim - sanitize raw cycle counter reads
4345 * @hw: pointer to the HW structure
4346 * @systim: PHC time value read, sanitized and returned
4347 * @sts: structure to hold system time before and after reading SYSTIML,
4350 * Errata for 82574/82583 possible bad bits read from SYSTIMH/L:
4351 * check to see that the time is incrementing at a reasonable
4352 * rate and is a multiple of incvalue.
4354 static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim,
4355 struct ptp_system_timestamp *sts)
4357 u64 time_delta, rem, temp;
4362 incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
4363 for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
4364 /* latch SYSTIMH on read of SYSTIML */
4365 ptp_read_system_prets(sts);
4366 systim_next = (u64)er32(SYSTIML);
4367 ptp_read_system_postts(sts);
4368 systim_next |= (u64)er32(SYSTIMH) << 32;
4370 time_delta = systim_next - systim;
4372 /* VMWare users have seen incvalue of zero, don't div / 0 */
4373 rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0);
4375 systim = systim_next;
4377 if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0))
4385 * e1000e_read_systim - read SYSTIM register
4386 * @adapter: board private structure
4387 * @sts: structure which will contain system time before and after reading
4388 * SYSTIML, may be NULL
4390 u64 e1000e_read_systim(struct e1000_adapter *adapter,
4391 struct ptp_system_timestamp *sts)
4393 struct e1000_hw *hw = &adapter->hw;
4394 u32 systimel, systimel_2, systimeh;
4396 /* SYSTIMH latching upon SYSTIML read does not work well.
4397 * This means that if SYSTIML overflows after we read it but before
4398 * we read SYSTIMH, the value of SYSTIMH has been incremented and we
4399 * will experience a huge non linear increment in the systime value
4400 * to fix that we test for overflow and if true, we re-read systime.
4402 ptp_read_system_prets(sts);
4403 systimel = er32(SYSTIML);
4404 ptp_read_system_postts(sts);
4405 systimeh = er32(SYSTIMH);
4406 /* Is systimel is so large that overflow is possible? */
4407 if (systimel >= (u32)0xffffffff - E1000_TIMINCA_INCVALUE_MASK) {
4408 ptp_read_system_prets(sts);
4409 systimel_2 = er32(SYSTIML);
4410 ptp_read_system_postts(sts);
4411 if (systimel > systimel_2) {
4412 /* There was an overflow, read again SYSTIMH, and use
4415 systimeh = er32(SYSTIMH);
4416 systimel = systimel_2;
4419 systim = (u64)systimel;
4420 systim |= (u64)systimeh << 32;
4422 if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW)
4423 systim = e1000e_sanitize_systim(hw, systim, sts);
4429 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4430 * @cc: cyclecounter structure
4432 static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc)
4434 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4437 return e1000e_read_systim(adapter, NULL);
4441 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4442 * @adapter: board private structure to initialize
4444 * e1000_sw_init initializes the Adapter private data structure.
4445 * Fields are initialized based on PCI device information and
4446 * OS network device settings (MTU size).
4448 static int e1000_sw_init(struct e1000_adapter *adapter)
4450 struct net_device *netdev = adapter->netdev;
4452 adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
4453 adapter->rx_ps_bsize0 = 128;
4454 adapter->max_frame_size = netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
4455 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
4456 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4457 adapter->rx_ring_count = E1000_DEFAULT_RXD;
4459 spin_lock_init(&adapter->stats64_lock);
4461 e1000e_set_interrupt_capability(adapter);
4463 if (e1000_alloc_queues(adapter))
4466 /* Setup hardware time stamping cyclecounter */
4467 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4468 adapter->cc.read = e1000e_cyclecounter_read;
4469 adapter->cc.mask = CYCLECOUNTER_MASK(64);
4470 adapter->cc.mult = 1;
4471 /* cc.shift set in e1000e_get_base_tininca() */
4473 spin_lock_init(&adapter->systim_lock);
4474 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4477 /* Explicitly disable IRQ since the NIC can be in any state. */
4478 e1000_irq_disable(adapter);
4480 set_bit(__E1000_DOWN, &adapter->state);
4485 * e1000_intr_msi_test - Interrupt Handler
4486 * @irq: interrupt number
4487 * @data: pointer to a network interface device structure
4489 static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
4491 struct net_device *netdev = data;
4492 struct e1000_adapter *adapter = netdev_priv(netdev);
4493 struct e1000_hw *hw = &adapter->hw;
4494 u32 icr = er32(ICR);
4496 e_dbg("icr is %08X\n", icr);
4497 if (icr & E1000_ICR_RXSEQ) {
4498 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
4499 /* Force memory writes to complete before acknowledging the
4500 * interrupt is handled.
4509 * e1000_test_msi_interrupt - Returns 0 for successful test
4510 * @adapter: board private struct
4512 * code flow taken from tg3.c
4514 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4516 struct net_device *netdev = adapter->netdev;
4517 struct e1000_hw *hw = &adapter->hw;
4520 /* poll_enable hasn't been called yet, so don't need disable */
4521 /* clear any pending events */
4524 /* free the real vector and request a test handler */
4525 e1000_free_irq(adapter);
4526 e1000e_reset_interrupt_capability(adapter);
4528 /* Assume that the test fails, if it succeeds then the test
4529 * MSI irq handler will unset this flag
4531 adapter->flags |= FLAG_MSI_TEST_FAILED;
4533 err = pci_enable_msi(adapter->pdev);
4535 goto msi_test_failed;
4537 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
4538 netdev->name, netdev);
4540 pci_disable_msi(adapter->pdev);
4541 goto msi_test_failed;
4544 /* Force memory writes to complete before enabling and firing an
4549 e1000_irq_enable(adapter);
4551 /* fire an unusual interrupt on the test handler */
4552 ew32(ICS, E1000_ICS_RXSEQ);
4556 e1000_irq_disable(adapter);
4558 rmb(); /* read flags after interrupt has been fired */
4560 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
4561 adapter->int_mode = E1000E_INT_MODE_LEGACY;
4562 e_info("MSI interrupt test failed, using legacy interrupt.\n");
4564 e_dbg("MSI interrupt test succeeded!\n");
4567 free_irq(adapter->pdev->irq, netdev);
4568 pci_disable_msi(adapter->pdev);
4571 e1000e_set_interrupt_capability(adapter);
4572 return e1000_request_irq(adapter);
4576 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4577 * @adapter: board private struct
4579 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4581 static int e1000_test_msi(struct e1000_adapter *adapter)
4586 if (!(adapter->flags & FLAG_MSI_ENABLED))
4589 /* disable SERR in case the MSI write causes a master abort */
4590 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4591 if (pci_cmd & PCI_COMMAND_SERR)
4592 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4593 pci_cmd & ~PCI_COMMAND_SERR);
4595 err = e1000_test_msi_interrupt(adapter);
4597 /* re-enable SERR */
4598 if (pci_cmd & PCI_COMMAND_SERR) {
4599 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4600 pci_cmd |= PCI_COMMAND_SERR;
4601 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4608 * e1000e_open - Called when a network interface is made active
4609 * @netdev: network interface device structure
4611 * Returns 0 on success, negative value on failure
4613 * The open entry point is called when a network interface is made
4614 * active by the system (IFF_UP). At this point all resources needed
4615 * for transmit and receive operations are allocated, the interrupt
4616 * handler is registered with the OS, the watchdog timer is started,
4617 * and the stack is notified that the interface is ready.
4619 int e1000e_open(struct net_device *netdev)
4621 struct e1000_adapter *adapter = netdev_priv(netdev);
4622 struct e1000_hw *hw = &adapter->hw;
4623 struct pci_dev *pdev = adapter->pdev;
4626 /* disallow open during test */
4627 if (test_bit(__E1000_TESTING, &adapter->state))
4630 pm_runtime_get_sync(&pdev->dev);
4632 netif_carrier_off(netdev);
4633 netif_stop_queue(netdev);
4635 /* allocate transmit descriptors */
4636 err = e1000e_setup_tx_resources(adapter->tx_ring);
4640 /* allocate receive descriptors */
4641 err = e1000e_setup_rx_resources(adapter->rx_ring);
4645 /* If AMT is enabled, let the firmware know that the network
4646 * interface is now open and reset the part to a known state.
4648 if (adapter->flags & FLAG_HAS_AMT) {
4649 e1000e_get_hw_control(adapter);
4650 e1000e_reset(adapter);
4653 e1000e_power_up_phy(adapter);
4655 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4656 if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4657 e1000_update_mng_vlan(adapter);
4659 /* DMA latency requirement to workaround jumbo issue */
4660 cpu_latency_qos_add_request(&adapter->pm_qos_req, PM_QOS_DEFAULT_VALUE);
4662 /* before we allocate an interrupt, we must be ready to handle it.
4663 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4664 * as soon as we call pci_request_irq, so we have to setup our
4665 * clean_rx handler before we do so.
4667 e1000_configure(adapter);
4669 err = e1000_request_irq(adapter);
4673 /* Work around PCIe errata with MSI interrupts causing some chipsets to
4674 * ignore e1000e MSI messages, which means we need to test our MSI
4677 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
4678 err = e1000_test_msi(adapter);
4680 e_err("Interrupt allocation failed\n");
4685 /* From here on the code is the same as e1000e_up() */
4686 clear_bit(__E1000_DOWN, &adapter->state);
4688 napi_enable(&adapter->napi);
4690 e1000_irq_enable(adapter);
4692 adapter->tx_hang_recheck = false;
4694 hw->mac.get_link_status = true;
4695 pm_runtime_put(&pdev->dev);
4697 e1000e_trigger_lsc(adapter);
4702 cpu_latency_qos_remove_request(&adapter->pm_qos_req);
4703 e1000e_release_hw_control(adapter);
4704 e1000_power_down_phy(adapter);
4705 e1000e_free_rx_resources(adapter->rx_ring);
4707 e1000e_free_tx_resources(adapter->tx_ring);
4709 e1000e_reset(adapter);
4710 pm_runtime_put_sync(&pdev->dev);
4716 * e1000e_close - Disables a network interface
4717 * @netdev: network interface device structure
4719 * Returns 0, this is not allowed to fail
4721 * The close entry point is called when an interface is de-activated
4722 * by the OS. The hardware is still under the drivers control, but
4723 * needs to be disabled. A global MAC reset is issued to stop the
4724 * hardware, and all transmit and receive resources are freed.
4726 int e1000e_close(struct net_device *netdev)
4728 struct e1000_adapter *adapter = netdev_priv(netdev);
4729 struct pci_dev *pdev = adapter->pdev;
4730 int count = E1000_CHECK_RESET_COUNT;
4732 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4733 usleep_range(10000, 11000);
4735 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
4737 pm_runtime_get_sync(&pdev->dev);
4739 if (netif_device_present(netdev)) {
4740 e1000e_down(adapter, true);
4741 e1000_free_irq(adapter);
4743 /* Link status message must follow this format */
4744 netdev_info(netdev, "NIC Link is Down\n");
4747 napi_disable(&adapter->napi);
4749 e1000e_free_tx_resources(adapter->tx_ring);
4750 e1000e_free_rx_resources(adapter->rx_ring);
4752 /* kill manageability vlan ID if supported, but not if a vlan with
4753 * the same ID is registered on the host OS (let 8021q kill it)
4755 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
4756 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
4757 adapter->mng_vlan_id);
4759 /* If AMT is enabled, let the firmware know that the network
4760 * interface is now closed
4762 if ((adapter->flags & FLAG_HAS_AMT) &&
4763 !test_bit(__E1000_TESTING, &adapter->state))
4764 e1000e_release_hw_control(adapter);
4766 cpu_latency_qos_remove_request(&adapter->pm_qos_req);
4768 pm_runtime_put_sync(&pdev->dev);
4774 * e1000_set_mac - Change the Ethernet Address of the NIC
4775 * @netdev: network interface device structure
4776 * @p: pointer to an address structure
4778 * Returns 0 on success, negative on failure
4780 static int e1000_set_mac(struct net_device *netdev, void *p)
4782 struct e1000_adapter *adapter = netdev_priv(netdev);
4783 struct e1000_hw *hw = &adapter->hw;
4784 struct sockaddr *addr = p;
4786 if (!is_valid_ether_addr(addr->sa_data))
4787 return -EADDRNOTAVAIL;
4789 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4790 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4792 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
4794 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4795 /* activate the work around */
4796 e1000e_set_laa_state_82571(&adapter->hw, 1);
4798 /* Hold a copy of the LAA in RAR[14] This is done so that
4799 * between the time RAR[0] gets clobbered and the time it
4800 * gets fixed (in e1000_watchdog), the actual LAA is in one
4801 * of the RARs and no incoming packets directed to this port
4802 * are dropped. Eventually the LAA will be in RAR[0] and
4805 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4806 adapter->hw.mac.rar_entry_count - 1);
4813 * e1000e_update_phy_task - work thread to update phy
4814 * @work: pointer to our work struct
4816 * this worker thread exists because we must acquire a
4817 * semaphore to read the phy, which we could msleep while
4818 * waiting for it, and we can't msleep in a timer.
4820 static void e1000e_update_phy_task(struct work_struct *work)
4822 struct e1000_adapter *adapter = container_of(work,
4823 struct e1000_adapter,
4825 struct e1000_hw *hw = &adapter->hw;
4827 if (test_bit(__E1000_DOWN, &adapter->state))
4830 e1000_get_phy_info(hw);
4832 /* Enable EEE on 82579 after link up */
4833 if (hw->phy.type >= e1000_phy_82579)
4834 e1000_set_eee_pchlan(hw);
4838 * e1000_update_phy_info - timre call-back to update PHY info
4839 * @t: pointer to timer_list containing private info adapter
4841 * Need to wait a few seconds after link up to get diagnostic information from
4844 static void e1000_update_phy_info(struct timer_list *t)
4846 struct e1000_adapter *adapter = from_timer(adapter, t, phy_info_timer);
4848 if (test_bit(__E1000_DOWN, &adapter->state))
4851 schedule_work(&adapter->update_phy_task);
4855 * e1000e_update_phy_stats - Update the PHY statistics counters
4856 * @adapter: board private structure
4858 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
4860 static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4862 struct e1000_hw *hw = &adapter->hw;
4866 ret_val = hw->phy.ops.acquire(hw);
4870 /* A page set is expensive so check if already on desired page.
4871 * If not, set to the page with the PHY status registers.
4874 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4878 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4879 ret_val = hw->phy.ops.set_page(hw,
4880 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4885 /* Single Collision Count */
4886 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4887 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4889 adapter->stats.scc += phy_data;
4891 /* Excessive Collision Count */
4892 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4893 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4895 adapter->stats.ecol += phy_data;
4897 /* Multiple Collision Count */
4898 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4899 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4901 adapter->stats.mcc += phy_data;
4903 /* Late Collision Count */
4904 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4905 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4907 adapter->stats.latecol += phy_data;
4909 /* Collision Count - also used for adaptive IFS */
4910 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4911 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4913 hw->mac.collision_delta = phy_data;
4916 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4917 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4919 adapter->stats.dc += phy_data;
4921 /* Transmit with no CRS */
4922 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4923 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4925 adapter->stats.tncrs += phy_data;
4928 hw->phy.ops.release(hw);
4932 * e1000e_update_stats - Update the board statistics counters
4933 * @adapter: board private structure
4935 static void e1000e_update_stats(struct e1000_adapter *adapter)
4937 struct net_device *netdev = adapter->netdev;
4938 struct e1000_hw *hw = &adapter->hw;
4939 struct pci_dev *pdev = adapter->pdev;
4941 /* Prevent stats update while adapter is being reset, or if the pci
4942 * connection is down.
4944 if (adapter->link_speed == 0)
4946 if (pci_channel_offline(pdev))
4949 adapter->stats.crcerrs += er32(CRCERRS);
4950 adapter->stats.gprc += er32(GPRC);
4951 adapter->stats.gorc += er32(GORCL);
4952 er32(GORCH); /* Clear gorc */
4953 adapter->stats.bprc += er32(BPRC);
4954 adapter->stats.mprc += er32(MPRC);
4955 adapter->stats.roc += er32(ROC);
4957 adapter->stats.mpc += er32(MPC);
4959 /* Half-duplex statistics */
4960 if (adapter->link_duplex == HALF_DUPLEX) {
4961 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4962 e1000e_update_phy_stats(adapter);
4964 adapter->stats.scc += er32(SCC);
4965 adapter->stats.ecol += er32(ECOL);
4966 adapter->stats.mcc += er32(MCC);
4967 adapter->stats.latecol += er32(LATECOL);
4968 adapter->stats.dc += er32(DC);
4970 hw->mac.collision_delta = er32(COLC);
4972 if ((hw->mac.type != e1000_82574) &&
4973 (hw->mac.type != e1000_82583))
4974 adapter->stats.tncrs += er32(TNCRS);
4976 adapter->stats.colc += hw->mac.collision_delta;
4979 adapter->stats.xonrxc += er32(XONRXC);
4980 adapter->stats.xontxc += er32(XONTXC);
4981 adapter->stats.xoffrxc += er32(XOFFRXC);
4982 adapter->stats.xofftxc += er32(XOFFTXC);
4983 adapter->stats.gptc += er32(GPTC);
4984 adapter->stats.gotc += er32(GOTCL);
4985 er32(GOTCH); /* Clear gotc */
4986 adapter->stats.rnbc += er32(RNBC);
4987 adapter->stats.ruc += er32(RUC);
4989 adapter->stats.mptc += er32(MPTC);
4990 adapter->stats.bptc += er32(BPTC);
4992 /* used for adaptive IFS */
4994 hw->mac.tx_packet_delta = er32(TPT);
4995 adapter->stats.tpt += hw->mac.tx_packet_delta;
4997 adapter->stats.algnerrc += er32(ALGNERRC);
4998 adapter->stats.rxerrc += er32(RXERRC);
4999 adapter->stats.cexterr += er32(CEXTERR);
5000 adapter->stats.tsctc += er32(TSCTC);
5001 adapter->stats.tsctfc += er32(TSCTFC);
5003 /* Fill out the OS statistics structure */
5004 netdev->stats.multicast = adapter->stats.mprc;
5005 netdev->stats.collisions = adapter->stats.colc;
5009 /* RLEC on some newer hardware can be incorrect so build
5010 * our own version based on RUC and ROC
5012 netdev->stats.rx_errors = adapter->stats.rxerrc +
5013 adapter->stats.crcerrs + adapter->stats.algnerrc +
5014 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
5015 netdev->stats.rx_length_errors = adapter->stats.ruc +
5017 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
5018 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
5019 netdev->stats.rx_missed_errors = adapter->stats.mpc;
5022 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
5023 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
5024 netdev->stats.tx_window_errors = adapter->stats.latecol;
5025 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
5027 /* Tx Dropped needs to be maintained elsewhere */
5029 /* Management Stats */
5030 adapter->stats.mgptc += er32(MGTPTC);
5031 adapter->stats.mgprc += er32(MGTPRC);
5032 adapter->stats.mgpdc += er32(MGTPDC);
5034 /* Correctable ECC Errors */
5035 if (hw->mac.type >= e1000_pch_lpt) {
5036 u32 pbeccsts = er32(PBECCSTS);
5038 adapter->corr_errors +=
5039 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
5040 adapter->uncorr_errors +=
5041 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
5042 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
5047 * e1000_phy_read_status - Update the PHY register status snapshot
5048 * @adapter: board private structure
5050 static void e1000_phy_read_status(struct e1000_adapter *adapter)
5052 struct e1000_hw *hw = &adapter->hw;
5053 struct e1000_phy_regs *phy = &adapter->phy_regs;
5055 if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
5056 (er32(STATUS) & E1000_STATUS_LU) &&
5057 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
5060 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
5061 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
5062 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
5063 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
5064 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
5065 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
5066 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
5067 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
5069 e_warn("Error reading PHY register\n");
5071 /* Do not read PHY registers if link is not up
5072 * Set values to typical power-on defaults
5074 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
5075 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
5076 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
5078 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
5079 ADVERTISE_ALL | ADVERTISE_CSMA);
5081 phy->expansion = EXPANSION_ENABLENPAGE;
5082 phy->ctrl1000 = ADVERTISE_1000FULL;
5084 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
5088 static void e1000_print_link_info(struct e1000_adapter *adapter)
5090 struct e1000_hw *hw = &adapter->hw;
5091 u32 ctrl = er32(CTRL);
5093 /* Link status message must follow this format for user tools */
5094 netdev_info(adapter->netdev,
5095 "NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
5096 adapter->link_speed,
5097 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
5098 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
5099 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
5100 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
5103 static bool e1000e_has_link(struct e1000_adapter *adapter)
5105 struct e1000_hw *hw = &adapter->hw;
5106 bool link_active = false;
5109 /* get_link_status is set on LSC (link status) interrupt or
5110 * Rx sequence error interrupt. get_link_status will stay
5111 * true until the check_for_link establishes link
5112 * for copper adapters ONLY
5114 switch (hw->phy.media_type) {
5115 case e1000_media_type_copper:
5116 if (hw->mac.get_link_status) {
5117 ret_val = hw->mac.ops.check_for_link(hw);
5118 link_active = !hw->mac.get_link_status;
5123 case e1000_media_type_fiber:
5124 ret_val = hw->mac.ops.check_for_link(hw);
5125 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
5127 case e1000_media_type_internal_serdes:
5128 ret_val = hw->mac.ops.check_for_link(hw);
5129 link_active = hw->mac.serdes_has_link;
5132 case e1000_media_type_unknown:
5136 if ((ret_val == -E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
5137 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
5138 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
5139 e_info("Gigabit has been disabled, downgrading speed\n");
5145 static void e1000e_enable_receives(struct e1000_adapter *adapter)
5147 /* make sure the receive unit is started */
5148 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5149 (adapter->flags & FLAG_RESTART_NOW)) {
5150 struct e1000_hw *hw = &adapter->hw;
5151 u32 rctl = er32(RCTL);
5153 ew32(RCTL, rctl | E1000_RCTL_EN);
5154 adapter->flags &= ~FLAG_RESTART_NOW;
5158 static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
5160 struct e1000_hw *hw = &adapter->hw;
5162 /* With 82574 controllers, PHY needs to be checked periodically
5163 * for hung state and reset, if two calls return true
5165 if (e1000_check_phy_82574(hw))
5166 adapter->phy_hang_count++;
5168 adapter->phy_hang_count = 0;
5170 if (adapter->phy_hang_count > 1) {
5171 adapter->phy_hang_count = 0;
5172 e_dbg("PHY appears hung - resetting\n");
5173 schedule_work(&adapter->reset_task);
5178 * e1000_watchdog - Timer Call-back
5179 * @t: pointer to timer_list containing private info adapter
5181 static void e1000_watchdog(struct timer_list *t)
5183 struct e1000_adapter *adapter = from_timer(adapter, t, watchdog_timer);
5185 /* Do the rest outside of interrupt context */
5186 schedule_work(&adapter->watchdog_task);
5188 /* TODO: make this use queue_delayed_work() */
5191 static void e1000_watchdog_task(struct work_struct *work)
5193 struct e1000_adapter *adapter = container_of(work,
5194 struct e1000_adapter,
5196 struct net_device *netdev = adapter->netdev;
5197 struct e1000_mac_info *mac = &adapter->hw.mac;
5198 struct e1000_phy_info *phy = &adapter->hw.phy;
5199 struct e1000_ring *tx_ring = adapter->tx_ring;
5200 u32 dmoff_exit_timeout = 100, tries = 0;
5201 struct e1000_hw *hw = &adapter->hw;
5202 u32 link, tctl, pcim_state;
5204 if (test_bit(__E1000_DOWN, &adapter->state))
5207 link = e1000e_has_link(adapter);
5208 if ((netif_carrier_ok(netdev)) && link) {
5209 /* Cancel scheduled suspend requests. */
5210 pm_runtime_resume(netdev->dev.parent);
5212 e1000e_enable_receives(adapter);
5216 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
5217 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
5218 e1000_update_mng_vlan(adapter);
5221 if (!netif_carrier_ok(netdev)) {
5224 /* Cancel scheduled suspend requests. */
5225 pm_runtime_resume(netdev->dev.parent);
5227 /* Checking if MAC is in DMoff state*/
5228 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
5229 pcim_state = er32(STATUS);
5230 while (pcim_state & E1000_STATUS_PCIM_STATE) {
5231 if (tries++ == dmoff_exit_timeout) {
5232 e_dbg("Error in exiting dmoff\n");
5235 usleep_range(10000, 20000);
5236 pcim_state = er32(STATUS);
5238 /* Checking if MAC exited DMoff state */
5239 if (!(pcim_state & E1000_STATUS_PCIM_STATE))
5240 e1000_phy_hw_reset(&adapter->hw);
5244 /* update snapshot of PHY registers on LSC */
5245 e1000_phy_read_status(adapter);
5246 mac->ops.get_link_up_info(&adapter->hw,
5247 &adapter->link_speed,
5248 &adapter->link_duplex);
5249 e1000_print_link_info(adapter);
5251 /* check if SmartSpeed worked */
5252 e1000e_check_downshift(hw);
5253 if (phy->speed_downgraded)
5255 "Link Speed was downgraded by SmartSpeed\n");
5257 /* On supported PHYs, check for duplex mismatch only
5258 * if link has autonegotiated at 10/100 half
5260 if ((hw->phy.type == e1000_phy_igp_3 ||
5261 hw->phy.type == e1000_phy_bm) &&
5263 (adapter->link_speed == SPEED_10 ||
5264 adapter->link_speed == SPEED_100) &&
5265 (adapter->link_duplex == HALF_DUPLEX)) {
5268 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
5270 if (!(autoneg_exp & EXPANSION_NWAY))
5271 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
5274 /* adjust timeout factor according to speed/duplex */
5275 adapter->tx_timeout_factor = 1;
5276 switch (adapter->link_speed) {
5279 adapter->tx_timeout_factor = 16;
5283 adapter->tx_timeout_factor = 10;
5287 /* workaround: re-program speed mode bit after
5290 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
5294 tarc0 = er32(TARC(0));
5295 tarc0 &= ~SPEED_MODE_BIT;
5296 ew32(TARC(0), tarc0);
5299 /* disable TSO for pcie and 10/100 speeds, to avoid
5300 * some hardware issues
5302 if (!(adapter->flags & FLAG_TSO_FORCE)) {
5303 switch (adapter->link_speed) {
5306 e_info("10/100 speed: disabling TSO\n");
5307 netdev->features &= ~NETIF_F_TSO;
5308 netdev->features &= ~NETIF_F_TSO6;
5311 netdev->features |= NETIF_F_TSO;
5312 netdev->features |= NETIF_F_TSO6;
5318 if (hw->mac.type == e1000_pch_spt) {
5319 netdev->features &= ~NETIF_F_TSO;
5320 netdev->features &= ~NETIF_F_TSO6;
5324 /* enable transmits in the hardware, need to do this
5325 * after setting TARC(0)
5328 tctl |= E1000_TCTL_EN;
5331 /* Perform any post-link-up configuration before
5332 * reporting link up.
5334 if (phy->ops.cfg_on_link_up)
5335 phy->ops.cfg_on_link_up(hw);
5337 netif_wake_queue(netdev);
5338 netif_carrier_on(netdev);
5340 if (!test_bit(__E1000_DOWN, &adapter->state))
5341 mod_timer(&adapter->phy_info_timer,
5342 round_jiffies(jiffies + 2 * HZ));
5345 if (netif_carrier_ok(netdev)) {
5346 adapter->link_speed = 0;
5347 adapter->link_duplex = 0;
5348 /* Link status message must follow this format */
5349 netdev_info(netdev, "NIC Link is Down\n");
5350 netif_carrier_off(netdev);
5351 netif_stop_queue(netdev);
5352 if (!test_bit(__E1000_DOWN, &adapter->state))
5353 mod_timer(&adapter->phy_info_timer,
5354 round_jiffies(jiffies + 2 * HZ));
5356 /* 8000ES2LAN requires a Rx packet buffer work-around
5357 * on link down event; reset the controller to flush
5358 * the Rx packet buffer.
5360 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
5361 adapter->flags |= FLAG_RESTART_NOW;
5363 pm_schedule_suspend(netdev->dev.parent,
5369 spin_lock(&adapter->stats64_lock);
5370 e1000e_update_stats(adapter);
5372 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
5373 adapter->tpt_old = adapter->stats.tpt;
5374 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
5375 adapter->colc_old = adapter->stats.colc;
5377 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
5378 adapter->gorc_old = adapter->stats.gorc;
5379 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
5380 adapter->gotc_old = adapter->stats.gotc;
5381 spin_unlock(&adapter->stats64_lock);
5383 /* If the link is lost the controller stops DMA, but
5384 * if there is queued Tx work it cannot be done. So
5385 * reset the controller to flush the Tx packet buffers.
5387 if (!netif_carrier_ok(netdev) &&
5388 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
5389 adapter->flags |= FLAG_RESTART_NOW;
5391 /* If reset is necessary, do it outside of interrupt context. */
5392 if (adapter->flags & FLAG_RESTART_NOW) {
5393 schedule_work(&adapter->reset_task);
5394 /* return immediately since reset is imminent */
5398 e1000e_update_adaptive(&adapter->hw);
5400 /* Simple mode for Interrupt Throttle Rate (ITR) */
5401 if (adapter->itr_setting == 4) {
5402 /* Symmetric Tx/Rx gets a reduced ITR=2000;
5403 * Total asymmetrical Tx or Rx gets ITR=8000;
5404 * everyone else is between 2000-8000.
5406 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
5407 u32 dif = (adapter->gotc > adapter->gorc ?
5408 adapter->gotc - adapter->gorc :
5409 adapter->gorc - adapter->gotc) / 10000;
5410 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
5412 e1000e_write_itr(adapter, itr);
5415 /* Cause software interrupt to ensure Rx ring is cleaned */
5416 if (adapter->msix_entries)
5417 ew32(ICS, adapter->rx_ring->ims_val);
5419 ew32(ICS, E1000_ICS_RXDMT0);
5421 /* flush pending descriptors to memory before detecting Tx hang */
5422 e1000e_flush_descriptors(adapter);
5424 /* Force detection of hung controller every watchdog period */
5425 adapter->detect_tx_hung = true;
5427 /* With 82571 controllers, LAA may be overwritten due to controller
5428 * reset from the other port. Set the appropriate LAA in RAR[0]
5430 if (e1000e_get_laa_state_82571(hw))
5431 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
5433 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5434 e1000e_check_82574_phy_workaround(adapter);
5436 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5437 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5438 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5439 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5441 adapter->rx_hwtstamp_cleared++;
5443 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5447 /* Reset the timer */
5448 if (!test_bit(__E1000_DOWN, &adapter->state))
5449 mod_timer(&adapter->watchdog_timer,
5450 round_jiffies(jiffies + 2 * HZ));
5453 #define E1000_TX_FLAGS_CSUM 0x00000001
5454 #define E1000_TX_FLAGS_VLAN 0x00000002
5455 #define E1000_TX_FLAGS_TSO 0x00000004
5456 #define E1000_TX_FLAGS_IPV4 0x00000008
5457 #define E1000_TX_FLAGS_NO_FCS 0x00000010
5458 #define E1000_TX_FLAGS_HWTSTAMP 0x00000020
5459 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5460 #define E1000_TX_FLAGS_VLAN_SHIFT 16
5462 static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb,
5465 struct e1000_context_desc *context_desc;
5466 struct e1000_buffer *buffer_info;
5470 u8 ipcss, ipcso, tucss, tucso, hdr_len;
5473 if (!skb_is_gso(skb))
5476 err = skb_cow_head(skb, 0);
5480 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5481 mss = skb_shinfo(skb)->gso_size;
5482 if (protocol == htons(ETH_P_IP)) {
5483 struct iphdr *iph = ip_hdr(skb);
5486 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
5488 cmd_length = E1000_TXD_CMD_IP;
5489 ipcse = skb_transport_offset(skb) - 1;
5490 } else if (skb_is_gso_v6(skb)) {
5491 tcp_v6_gso_csum_prep(skb);
5494 ipcss = skb_network_offset(skb);
5495 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5496 tucss = skb_transport_offset(skb);
5497 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
5499 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
5500 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
5502 i = tx_ring->next_to_use;
5503 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5504 buffer_info = &tx_ring->buffer_info[i];
5506 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5507 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5508 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5509 context_desc->upper_setup.tcp_fields.tucss = tucss;
5510 context_desc->upper_setup.tcp_fields.tucso = tucso;
5511 context_desc->upper_setup.tcp_fields.tucse = 0;
5512 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5513 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5514 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5516 buffer_info->time_stamp = jiffies;
5517 buffer_info->next_to_watch = i;
5520 if (i == tx_ring->count)
5522 tx_ring->next_to_use = i;
5527 static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb,
5530 struct e1000_adapter *adapter = tx_ring->adapter;
5531 struct e1000_context_desc *context_desc;
5532 struct e1000_buffer *buffer_info;
5535 u32 cmd_len = E1000_TXD_CMD_DEXT;
5537 if (skb->ip_summed != CHECKSUM_PARTIAL)
5541 case cpu_to_be16(ETH_P_IP):
5542 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5543 cmd_len |= E1000_TXD_CMD_TCP;
5545 case cpu_to_be16(ETH_P_IPV6):
5546 /* XXX not handling all IPV6 headers */
5547 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5548 cmd_len |= E1000_TXD_CMD_TCP;
5551 if (unlikely(net_ratelimit()))
5552 e_warn("checksum_partial proto=%x!\n",
5553 be16_to_cpu(protocol));
5557 css = skb_checksum_start_offset(skb);
5559 i = tx_ring->next_to_use;
5560 buffer_info = &tx_ring->buffer_info[i];
5561 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5563 context_desc->lower_setup.ip_config = 0;
5564 context_desc->upper_setup.tcp_fields.tucss = css;
5565 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
5566 context_desc->upper_setup.tcp_fields.tucse = 0;
5567 context_desc->tcp_seg_setup.data = 0;
5568 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5570 buffer_info->time_stamp = jiffies;
5571 buffer_info->next_to_watch = i;
5574 if (i == tx_ring->count)
5576 tx_ring->next_to_use = i;
5581 static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5582 unsigned int first, unsigned int max_per_txd,
5583 unsigned int nr_frags)
5585 struct e1000_adapter *adapter = tx_ring->adapter;
5586 struct pci_dev *pdev = adapter->pdev;
5587 struct e1000_buffer *buffer_info;
5588 unsigned int len = skb_headlen(skb);
5589 unsigned int offset = 0, size, count = 0, i;
5590 unsigned int f, bytecount, segs;
5592 i = tx_ring->next_to_use;
5595 buffer_info = &tx_ring->buffer_info[i];
5596 size = min(len, max_per_txd);
5598 buffer_info->length = size;
5599 buffer_info->time_stamp = jiffies;
5600 buffer_info->next_to_watch = i;
5601 buffer_info->dma = dma_map_single(&pdev->dev,
5603 size, DMA_TO_DEVICE);
5604 buffer_info->mapped_as_page = false;
5605 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
5614 if (i == tx_ring->count)
5619 for (f = 0; f < nr_frags; f++) {
5620 const skb_frag_t *frag = &skb_shinfo(skb)->frags[f];
5622 len = skb_frag_size(frag);
5627 if (i == tx_ring->count)
5630 buffer_info = &tx_ring->buffer_info[i];
5631 size = min(len, max_per_txd);
5633 buffer_info->length = size;
5634 buffer_info->time_stamp = jiffies;
5635 buffer_info->next_to_watch = i;
5636 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
5639 buffer_info->mapped_as_page = true;
5640 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
5649 segs = skb_shinfo(skb)->gso_segs ? : 1;
5650 /* multiply data chunks by size of headers */
5651 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5653 tx_ring->buffer_info[i].skb = skb;
5654 tx_ring->buffer_info[i].segs = segs;
5655 tx_ring->buffer_info[i].bytecount = bytecount;
5656 tx_ring->buffer_info[first].next_to_watch = i;
5661 dev_err(&pdev->dev, "Tx DMA map failed\n");
5662 buffer_info->dma = 0;
5668 i += tx_ring->count;
5670 buffer_info = &tx_ring->buffer_info[i];
5671 e1000_put_txbuf(tx_ring, buffer_info, true);
5677 static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
5679 struct e1000_adapter *adapter = tx_ring->adapter;
5680 struct e1000_tx_desc *tx_desc = NULL;
5681 struct e1000_buffer *buffer_info;
5682 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5685 if (tx_flags & E1000_TX_FLAGS_TSO) {
5686 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
5688 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5690 if (tx_flags & E1000_TX_FLAGS_IPV4)
5691 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5694 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5695 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5696 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5699 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5700 txd_lower |= E1000_TXD_CMD_VLE;
5701 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5704 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5705 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5707 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5708 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5709 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5712 i = tx_ring->next_to_use;
5715 buffer_info = &tx_ring->buffer_info[i];
5716 tx_desc = E1000_TX_DESC(*tx_ring, i);
5717 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
5718 tx_desc->lower.data = cpu_to_le32(txd_lower |
5719 buffer_info->length);
5720 tx_desc->upper.data = cpu_to_le32(txd_upper);
5723 if (i == tx_ring->count)
5725 } while (--count > 0);
5727 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5729 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5730 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5731 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5733 /* Force memory writes to complete before letting h/w
5734 * know there are new descriptors to fetch. (Only
5735 * applicable for weak-ordered memory model archs,
5740 tx_ring->next_to_use = i;
5743 #define MINIMUM_DHCP_PACKET_SIZE 282
5744 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5745 struct sk_buff *skb)
5747 struct e1000_hw *hw = &adapter->hw;
5750 if (skb_vlan_tag_present(skb) &&
5751 !((skb_vlan_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5752 (adapter->hw.mng_cookie.status &
5753 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5756 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5759 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
5763 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
5766 if (ip->protocol != IPPROTO_UDP)
5769 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5770 if (ntohs(udp->dest) != 67)
5773 offset = (u8 *)udp + 8 - skb->data;
5774 length = skb->len - offset;
5775 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5781 static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
5783 struct e1000_adapter *adapter = tx_ring->adapter;
5785 netif_stop_queue(adapter->netdev);
5786 /* Herbert's original patch had:
5787 * smp_mb__after_netif_stop_queue();
5788 * but since that doesn't exist yet, just open code it.
5792 /* We need to check again in a case another CPU has just
5793 * made room available.
5795 if (e1000_desc_unused(tx_ring) < size)
5799 netif_start_queue(adapter->netdev);
5800 ++adapter->restart_queue;
5804 static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
5806 BUG_ON(size > tx_ring->count);
5808 if (e1000_desc_unused(tx_ring) >= size)
5810 return __e1000_maybe_stop_tx(tx_ring, size);
5813 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5814 struct net_device *netdev)
5816 struct e1000_adapter *adapter = netdev_priv(netdev);
5817 struct e1000_ring *tx_ring = adapter->tx_ring;
5819 unsigned int tx_flags = 0;
5820 unsigned int len = skb_headlen(skb);
5821 unsigned int nr_frags;
5826 __be16 protocol = vlan_get_protocol(skb);
5828 if (test_bit(__E1000_DOWN, &adapter->state)) {
5829 dev_kfree_skb_any(skb);
5830 return NETDEV_TX_OK;
5833 if (skb->len <= 0) {
5834 dev_kfree_skb_any(skb);
5835 return NETDEV_TX_OK;
5838 /* The minimum packet size with TCTL.PSP set is 17 bytes so
5839 * pad skb in order to meet this minimum size requirement
5841 if (skb_put_padto(skb, 17))
5842 return NETDEV_TX_OK;
5844 mss = skb_shinfo(skb)->gso_size;
5848 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
5849 * points to just header, pull a few bytes of payload from
5850 * frags into skb->data
5852 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5853 /* we do this workaround for ES2LAN, but it is un-necessary,
5854 * avoiding it could save a lot of cycles
5856 if (skb->data_len && (hdr_len == len)) {
5857 unsigned int pull_size;
5859 pull_size = min_t(unsigned int, 4, skb->data_len);
5860 if (!__pskb_pull_tail(skb, pull_size)) {
5861 e_err("__pskb_pull_tail failed.\n");
5862 dev_kfree_skb_any(skb);
5863 return NETDEV_TX_OK;
5865 len = skb_headlen(skb);
5869 /* reserve a descriptor for the offload context */
5870 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5874 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
5876 nr_frags = skb_shinfo(skb)->nr_frags;
5877 for (f = 0; f < nr_frags; f++)
5878 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5879 adapter->tx_fifo_limit);
5881 if (adapter->hw.mac.tx_pkt_filtering)
5882 e1000_transfer_dhcp_info(adapter, skb);
5884 /* need: count + 2 desc gap to keep tail from touching
5885 * head, otherwise try next time
5887 if (e1000_maybe_stop_tx(tx_ring, count + 2))
5888 return NETDEV_TX_BUSY;
5890 if (skb_vlan_tag_present(skb)) {
5891 tx_flags |= E1000_TX_FLAGS_VLAN;
5892 tx_flags |= (skb_vlan_tag_get(skb) <<
5893 E1000_TX_FLAGS_VLAN_SHIFT);
5896 first = tx_ring->next_to_use;
5898 tso = e1000_tso(tx_ring, skb, protocol);
5900 dev_kfree_skb_any(skb);
5901 return NETDEV_TX_OK;
5905 tx_flags |= E1000_TX_FLAGS_TSO;
5906 else if (e1000_tx_csum(tx_ring, skb, protocol))
5907 tx_flags |= E1000_TX_FLAGS_CSUM;
5909 /* Old method was to assume IPv4 packet by default if TSO was enabled.
5910 * 82571 hardware supports TSO capabilities for IPv6 as well...
5911 * no longer assume, we must.
5913 if (protocol == htons(ETH_P_IP))
5914 tx_flags |= E1000_TX_FLAGS_IPV4;
5916 if (unlikely(skb->no_fcs))
5917 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5919 /* if count is 0 then mapping error has occurred */
5920 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5923 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5924 (adapter->flags & FLAG_HAS_HW_TIMESTAMP)) {
5925 if (!adapter->tx_hwtstamp_skb) {
5926 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5927 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5928 adapter->tx_hwtstamp_skb = skb_get(skb);
5929 adapter->tx_hwtstamp_start = jiffies;
5930 schedule_work(&adapter->tx_hwtstamp_work);
5932 adapter->tx_hwtstamp_skipped++;
5936 skb_tx_timestamp(skb);
5938 netdev_sent_queue(netdev, skb->len);
5939 e1000_tx_queue(tx_ring, tx_flags, count);
5940 /* Make sure there is space in the ring for the next send. */
5941 e1000_maybe_stop_tx(tx_ring,
5943 DIV_ROUND_UP(PAGE_SIZE,
5944 adapter->tx_fifo_limit) + 2));
5946 if (!netdev_xmit_more() ||
5947 netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) {
5948 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
5949 e1000e_update_tdt_wa(tx_ring,
5950 tx_ring->next_to_use);
5952 writel(tx_ring->next_to_use, tx_ring->tail);
5955 dev_kfree_skb_any(skb);
5956 tx_ring->buffer_info[first].time_stamp = 0;
5957 tx_ring->next_to_use = first;
5960 return NETDEV_TX_OK;
5964 * e1000_tx_timeout - Respond to a Tx Hang
5965 * @netdev: network interface device structure
5966 * @txqueue: index of the hung queue (unused)
5968 static void e1000_tx_timeout(struct net_device *netdev, unsigned int __always_unused txqueue)
5970 struct e1000_adapter *adapter = netdev_priv(netdev);
5972 /* Do the reset outside of interrupt context */
5973 adapter->tx_timeout_count++;
5974 schedule_work(&adapter->reset_task);
5977 static void e1000_reset_task(struct work_struct *work)
5979 struct e1000_adapter *adapter;
5980 adapter = container_of(work, struct e1000_adapter, reset_task);
5983 /* don't run the task if already down */
5984 if (test_bit(__E1000_DOWN, &adapter->state)) {
5989 if (!(adapter->flags & FLAG_RESTART_NOW)) {
5990 e1000e_dump(adapter);
5991 e_err("Reset adapter unexpectedly\n");
5993 e1000e_reinit_locked(adapter);
5998 * e1000e_get_stats64 - Get System Network Statistics
5999 * @netdev: network interface device structure
6000 * @stats: rtnl_link_stats64 pointer
6002 * Returns the address of the device statistics structure.
6004 void e1000e_get_stats64(struct net_device *netdev,
6005 struct rtnl_link_stats64 *stats)
6007 struct e1000_adapter *adapter = netdev_priv(netdev);
6009 spin_lock(&adapter->stats64_lock);
6010 e1000e_update_stats(adapter);
6011 /* Fill out the OS statistics structure */
6012 stats->rx_bytes = adapter->stats.gorc;
6013 stats->rx_packets = adapter->stats.gprc;
6014 stats->tx_bytes = adapter->stats.gotc;
6015 stats->tx_packets = adapter->stats.gptc;
6016 stats->multicast = adapter->stats.mprc;
6017 stats->collisions = adapter->stats.colc;
6021 /* RLEC on some newer hardware can be incorrect so build
6022 * our own version based on RUC and ROC
6024 stats->rx_errors = adapter->stats.rxerrc +
6025 adapter->stats.crcerrs + adapter->stats.algnerrc +
6026 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
6027 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
6028 stats->rx_crc_errors = adapter->stats.crcerrs;
6029 stats->rx_frame_errors = adapter->stats.algnerrc;
6030 stats->rx_missed_errors = adapter->stats.mpc;
6033 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
6034 stats->tx_aborted_errors = adapter->stats.ecol;
6035 stats->tx_window_errors = adapter->stats.latecol;
6036 stats->tx_carrier_errors = adapter->stats.tncrs;
6038 /* Tx Dropped needs to be maintained elsewhere */
6040 spin_unlock(&adapter->stats64_lock);
6044 * e1000_change_mtu - Change the Maximum Transfer Unit
6045 * @netdev: network interface device structure
6046 * @new_mtu: new value for maximum frame size
6048 * Returns 0 on success, negative on failure
6050 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
6052 struct e1000_adapter *adapter = netdev_priv(netdev);
6053 int max_frame = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
6055 /* Jumbo frame support */
6056 if ((new_mtu > ETH_DATA_LEN) &&
6057 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
6058 e_err("Jumbo Frames not supported.\n");
6062 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
6063 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
6064 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
6065 (new_mtu > ETH_DATA_LEN)) {
6066 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
6070 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
6071 usleep_range(1000, 1100);
6072 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
6073 adapter->max_frame_size = max_frame;
6074 netdev_dbg(netdev, "changing MTU from %d to %d\n",
6075 netdev->mtu, new_mtu);
6076 netdev->mtu = new_mtu;
6078 pm_runtime_get_sync(netdev->dev.parent);
6080 if (netif_running(netdev))
6081 e1000e_down(adapter, true);
6083 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
6084 * means we reserve 2 more, this pushes us to allocate from the next
6086 * i.e. RXBUFFER_2048 --> size-4096 slab
6087 * However with the new *_jumbo_rx* routines, jumbo receives will use
6091 if (max_frame <= 2048)
6092 adapter->rx_buffer_len = 2048;
6094 adapter->rx_buffer_len = 4096;
6096 /* adjust allocation if LPE protects us, and we aren't using SBP */
6097 if (max_frame <= (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN))
6098 adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
6100 if (netif_running(netdev))
6103 e1000e_reset(adapter);
6105 pm_runtime_put_sync(netdev->dev.parent);
6107 clear_bit(__E1000_RESETTING, &adapter->state);
6112 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
6115 struct e1000_adapter *adapter = netdev_priv(netdev);
6116 struct mii_ioctl_data *data = if_mii(ifr);
6118 if (adapter->hw.phy.media_type != e1000_media_type_copper)
6123 data->phy_id = adapter->hw.phy.addr;
6126 e1000_phy_read_status(adapter);
6128 switch (data->reg_num & 0x1F) {
6130 data->val_out = adapter->phy_regs.bmcr;
6133 data->val_out = adapter->phy_regs.bmsr;
6136 data->val_out = (adapter->hw.phy.id >> 16);
6139 data->val_out = (adapter->hw.phy.id & 0xFFFF);
6142 data->val_out = adapter->phy_regs.advertise;
6145 data->val_out = adapter->phy_regs.lpa;
6148 data->val_out = adapter->phy_regs.expansion;
6151 data->val_out = adapter->phy_regs.ctrl1000;
6154 data->val_out = adapter->phy_regs.stat1000;
6157 data->val_out = adapter->phy_regs.estatus;
6171 * e1000e_hwtstamp_set - control hardware time stamping
6172 * @netdev: network interface device structure
6173 * @ifr: interface request
6175 * Outgoing time stamping can be enabled and disabled. Play nice and
6176 * disable it when requested, although it shouldn't cause any overhead
6177 * when no packet needs it. At most one packet in the queue may be
6178 * marked for time stamping, otherwise it would be impossible to tell
6179 * for sure to which packet the hardware time stamp belongs.
6181 * Incoming time stamping has to be configured via the hardware filters.
6182 * Not all combinations are supported, in particular event type has to be
6183 * specified. Matching the kind of event packet is not supported, with the
6184 * exception of "all V2 events regardless of level 2 or 4".
6186 static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
6188 struct e1000_adapter *adapter = netdev_priv(netdev);
6189 struct hwtstamp_config config;
6192 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
6195 ret_val = e1000e_config_hwtstamp(adapter, &config);
6199 switch (config.rx_filter) {
6200 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6201 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6202 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6203 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6204 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6205 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
6206 /* With V2 type filters which specify a Sync or Delay Request,
6207 * Path Delay Request/Response messages are also time stamped
6208 * by hardware so notify the caller the requested packets plus
6209 * some others are time stamped.
6211 config.rx_filter = HWTSTAMP_FILTER_SOME;
6217 return copy_to_user(ifr->ifr_data, &config,
6218 sizeof(config)) ? -EFAULT : 0;
6221 static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
6223 struct e1000_adapter *adapter = netdev_priv(netdev);
6225 return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
6226 sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
6229 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6235 return e1000_mii_ioctl(netdev, ifr, cmd);
6237 return e1000e_hwtstamp_set(netdev, ifr);
6239 return e1000e_hwtstamp_get(netdev, ifr);
6245 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
6247 struct e1000_hw *hw = &adapter->hw;
6248 u32 i, mac_reg, wuc;
6249 u16 phy_reg, wuc_enable;
6252 /* copy MAC RARs to PHY RARs */
6253 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
6255 retval = hw->phy.ops.acquire(hw);
6257 e_err("Could not acquire PHY\n");
6261 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
6262 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
6266 /* copy MAC MTA to PHY MTA - only needed for pchlan */
6267 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
6268 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
6269 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
6270 (u16)(mac_reg & 0xFFFF));
6271 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
6272 (u16)((mac_reg >> 16) & 0xFFFF));
6275 /* configure PHY Rx Control register */
6276 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
6277 mac_reg = er32(RCTL);
6278 if (mac_reg & E1000_RCTL_UPE)
6279 phy_reg |= BM_RCTL_UPE;
6280 if (mac_reg & E1000_RCTL_MPE)
6281 phy_reg |= BM_RCTL_MPE;
6282 phy_reg &= ~(BM_RCTL_MO_MASK);
6283 if (mac_reg & E1000_RCTL_MO_3)
6284 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
6285 << BM_RCTL_MO_SHIFT);
6286 if (mac_reg & E1000_RCTL_BAM)
6287 phy_reg |= BM_RCTL_BAM;
6288 if (mac_reg & E1000_RCTL_PMCF)
6289 phy_reg |= BM_RCTL_PMCF;
6290 mac_reg = er32(CTRL);
6291 if (mac_reg & E1000_CTRL_RFCE)
6292 phy_reg |= BM_RCTL_RFCE;
6293 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
6295 wuc = E1000_WUC_PME_EN;
6296 if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
6297 wuc |= E1000_WUC_APME;
6299 /* enable PHY wakeup in MAC register */
6301 ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
6302 E1000_WUC_PME_STATUS | wuc));
6304 /* configure and enable PHY wakeup in PHY registers */
6305 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
6306 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
6308 /* activate PHY wakeup */
6309 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
6310 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
6312 e_err("Could not set PHY Host Wakeup bit\n");
6314 hw->phy.ops.release(hw);
6319 static void e1000e_flush_lpic(struct pci_dev *pdev)
6321 struct net_device *netdev = pci_get_drvdata(pdev);
6322 struct e1000_adapter *adapter = netdev_priv(netdev);
6323 struct e1000_hw *hw = &adapter->hw;
6326 pm_runtime_get_sync(netdev->dev.parent);
6328 ret_val = hw->phy.ops.acquire(hw);
6332 pr_info("EEE TX LPI TIMER: %08X\n",
6333 er32(LPIC) >> E1000_LPIC_LPIET_SHIFT);
6335 hw->phy.ops.release(hw);
6338 pm_runtime_put_sync(netdev->dev.parent);
6341 /* S0ix implementation */
6342 static void e1000e_s0ix_entry_flow(struct e1000_adapter *adapter)
6344 struct e1000_hw *hw = &adapter->hw;
6348 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
6349 /* Request ME configure the device for S0ix */
6350 mac_data = er32(H2ME);
6351 mac_data |= E1000_H2ME_START_DPG;
6352 mac_data &= ~E1000_H2ME_EXIT_DPG;
6353 ew32(H2ME, mac_data);
6355 /* Request driver configure the device to S0ix */
6356 /* Disable the periodic inband message,
6357 * don't request PCIe clock in K1 page770_17[10:9] = 10b
6359 e1e_rphy(hw, HV_PM_CTRL, &phy_data);
6360 phy_data &= ~HV_PM_CTRL_K1_CLK_REQ;
6361 phy_data |= BIT(10);
6362 e1e_wphy(hw, HV_PM_CTRL, phy_data);
6364 /* Make sure we don't exit K1 every time a new packet arrives
6365 * 772_29[5] = 1 CS_Mode_Stay_In_K1
6367 e1e_rphy(hw, I217_CGFREG, &phy_data);
6369 e1e_wphy(hw, I217_CGFREG, phy_data);
6371 /* Change the MAC/PHY interface to SMBus
6372 * Force the SMBus in PHY page769_23[0] = 1
6373 * Force the SMBus in MAC CTRL_EXT[11] = 1
6375 e1e_rphy(hw, CV_SMB_CTRL, &phy_data);
6376 phy_data |= CV_SMB_CTRL_FORCE_SMBUS;
6377 e1e_wphy(hw, CV_SMB_CTRL, phy_data);
6378 mac_data = er32(CTRL_EXT);
6379 mac_data |= E1000_CTRL_EXT_FORCE_SMBUS;
6380 ew32(CTRL_EXT, mac_data);
6382 /* DFT control: PHY bit: page769_20[0] = 1
6383 * page769_20[7] - PHY PLL stop
6384 * page769_20[8] - PHY go to the electrical idle
6385 * page769_20[9] - PHY serdes disable
6386 * Gate PPW via EXTCNF_CTRL - set 0x0F00[7] = 1
6388 e1e_rphy(hw, I82579_DFT_CTRL, &phy_data);
6393 e1e_wphy(hw, I82579_DFT_CTRL, phy_data);
6395 mac_data = er32(EXTCNF_CTRL);
6396 mac_data |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
6397 ew32(EXTCNF_CTRL, mac_data);
6399 /* Enable the Dynamic Power Gating in the MAC */
6400 mac_data = er32(FEXTNVM7);
6401 mac_data |= BIT(22);
6402 ew32(FEXTNVM7, mac_data);
6404 /* Disable disconnected cable conditioning for Power Gating */
6405 mac_data = er32(DPGFR);
6407 ew32(DPGFR, mac_data);
6409 /* Don't wake from dynamic Power Gating with clock request */
6410 mac_data = er32(FEXTNVM12);
6411 mac_data |= BIT(12);
6412 ew32(FEXTNVM12, mac_data);
6414 /* Ungate PGCB clock */
6415 mac_data = er32(FEXTNVM9);
6416 mac_data &= ~BIT(28);
6417 ew32(FEXTNVM9, mac_data);
6419 /* Enable K1 off to enable mPHY Power Gating */
6420 mac_data = er32(FEXTNVM6);
6421 mac_data |= BIT(31);
6422 ew32(FEXTNVM6, mac_data);
6424 /* Enable mPHY power gating for any link and speed */
6425 mac_data = er32(FEXTNVM8);
6427 ew32(FEXTNVM8, mac_data);
6429 /* Enable the Dynamic Clock Gating in the DMA and MAC */
6430 mac_data = er32(CTRL_EXT);
6431 mac_data |= E1000_CTRL_EXT_DMA_DYN_CLK_EN;
6432 ew32(CTRL_EXT, mac_data);
6434 /* No MAC DPG gating SLP_S0 in modern standby
6435 * Switch the logic of the lanphypc to use PMC counter
6437 mac_data = er32(FEXTNVM5);
6439 ew32(FEXTNVM5, mac_data);
6442 /* Disable the time synchronization clock */
6443 mac_data = er32(FEXTNVM7);
6444 mac_data |= BIT(31);
6445 mac_data &= ~BIT(0);
6446 ew32(FEXTNVM7, mac_data);
6448 /* Dynamic Power Gating Enable */
6449 mac_data = er32(CTRL_EXT);
6451 ew32(CTRL_EXT, mac_data);
6453 /* Check MAC Tx/Rx packet buffer pointers.
6454 * Reset MAC Tx/Rx packet buffer pointers to suppress any
6455 * pending traffic indication that would prevent power gating.
6457 mac_data = er32(TDFH);
6460 mac_data = er32(TDFT);
6463 mac_data = er32(TDFHS);
6466 mac_data = er32(TDFTS);
6469 mac_data = er32(TDFPC);
6472 mac_data = er32(RDFH);
6475 mac_data = er32(RDFT);
6478 mac_data = er32(RDFHS);
6481 mac_data = er32(RDFTS);
6484 mac_data = er32(RDFPC);
6489 static void e1000e_s0ix_exit_flow(struct e1000_adapter *adapter)
6491 struct e1000_hw *hw = &adapter->hw;
6492 bool firmware_bug = false;
6497 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
6498 /* Request ME unconfigure the device from S0ix */
6499 mac_data = er32(H2ME);
6500 mac_data &= ~E1000_H2ME_START_DPG;
6501 mac_data |= E1000_H2ME_EXIT_DPG;
6502 ew32(H2ME, mac_data);
6504 /* Poll up to 2.5 seconds for ME to unconfigure DPG.
6505 * If this takes more than 1 second, show a warning indicating a
6508 while (!(er32(EXFWSM) & E1000_EXFWSM_DPG_EXIT_DONE)) {
6509 if (i > 100 && !firmware_bug)
6510 firmware_bug = true;
6513 e_dbg("Timeout (firmware bug): %d msec\n",
6518 usleep_range(10000, 11000);
6521 e_warn("DPG_EXIT_DONE took %d msec. This is a firmware bug\n",
6524 e_dbg("DPG_EXIT_DONE cleared after %d msec\n", i * 10);
6526 /* Request driver unconfigure the device from S0ix */
6528 /* Disable the Dynamic Power Gating in the MAC */
6529 mac_data = er32(FEXTNVM7);
6530 mac_data &= 0xFFBFFFFF;
6531 ew32(FEXTNVM7, mac_data);
6533 /* Disable mPHY power gating for any link and speed */
6534 mac_data = er32(FEXTNVM8);
6535 mac_data &= ~BIT(9);
6536 ew32(FEXTNVM8, mac_data);
6538 /* Disable K1 off */
6539 mac_data = er32(FEXTNVM6);
6540 mac_data &= ~BIT(31);
6541 ew32(FEXTNVM6, mac_data);
6543 /* Disable Ungate PGCB clock */
6544 mac_data = er32(FEXTNVM9);
6545 mac_data |= BIT(28);
6546 ew32(FEXTNVM9, mac_data);
6548 /* Cancel not waking from dynamic
6549 * Power Gating with clock request
6551 mac_data = er32(FEXTNVM12);
6552 mac_data &= ~BIT(12);
6553 ew32(FEXTNVM12, mac_data);
6555 /* Cancel disable disconnected cable conditioning
6558 mac_data = er32(DPGFR);
6559 mac_data &= ~BIT(2);
6560 ew32(DPGFR, mac_data);
6562 /* Disable the Dynamic Clock Gating in the DMA and MAC */
6563 mac_data = er32(CTRL_EXT);
6564 mac_data &= 0xFFF7FFFF;
6565 ew32(CTRL_EXT, mac_data);
6567 /* Revert the lanphypc logic to use the internal Gbe counter
6568 * and not the PMC counter
6570 mac_data = er32(FEXTNVM5);
6571 mac_data &= 0xFFFFFF7F;
6572 ew32(FEXTNVM5, mac_data);
6574 /* Enable the periodic inband message,
6575 * Request PCIe clock in K1 page770_17[10:9] =01b
6577 e1e_rphy(hw, HV_PM_CTRL, &phy_data);
6579 phy_data |= HV_PM_CTRL_K1_CLK_REQ;
6580 e1e_wphy(hw, HV_PM_CTRL, phy_data);
6582 /* Return back configuration
6583 * 772_29[5] = 0 CS_Mode_Stay_In_K1
6585 e1e_rphy(hw, I217_CGFREG, &phy_data);
6587 e1e_wphy(hw, I217_CGFREG, phy_data);
6589 /* Change the MAC/PHY interface to Kumeran
6590 * Unforce the SMBus in PHY page769_23[0] = 0
6591 * Unforce the SMBus in MAC CTRL_EXT[11] = 0
6593 e1e_rphy(hw, CV_SMB_CTRL, &phy_data);
6594 phy_data &= ~CV_SMB_CTRL_FORCE_SMBUS;
6595 e1e_wphy(hw, CV_SMB_CTRL, phy_data);
6596 mac_data = er32(CTRL_EXT);
6597 mac_data &= ~E1000_CTRL_EXT_FORCE_SMBUS;
6598 ew32(CTRL_EXT, mac_data);
6601 /* Disable Dynamic Power Gating */
6602 mac_data = er32(CTRL_EXT);
6603 mac_data &= 0xFFFFFFF7;
6604 ew32(CTRL_EXT, mac_data);
6606 /* Enable the time synchronization clock */
6607 mac_data = er32(FEXTNVM7);
6608 mac_data &= ~BIT(31);
6610 ew32(FEXTNVM7, mac_data);
6613 static int e1000e_pm_freeze(struct device *dev)
6615 struct net_device *netdev = dev_get_drvdata(dev);
6616 struct e1000_adapter *adapter = netdev_priv(netdev);
6621 present = netif_device_present(netdev);
6622 netif_device_detach(netdev);
6624 if (present && netif_running(netdev)) {
6625 int count = E1000_CHECK_RESET_COUNT;
6627 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
6628 usleep_range(10000, 11000);
6630 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
6632 /* Quiesce the device without resetting the hardware */
6633 e1000e_down(adapter, false);
6634 e1000_free_irq(adapter);
6638 e1000e_reset_interrupt_capability(adapter);
6640 /* Allow time for pending master requests to run */
6641 e1000e_disable_pcie_master(&adapter->hw);
6646 static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
6648 struct net_device *netdev = pci_get_drvdata(pdev);
6649 struct e1000_adapter *adapter = netdev_priv(netdev);
6650 struct e1000_hw *hw = &adapter->hw;
6651 u32 ctrl, ctrl_ext, rctl, status, wufc;
6654 /* Runtime suspend should only enable wakeup for link changes */
6656 wufc = E1000_WUFC_LNKC;
6657 else if (device_may_wakeup(&pdev->dev))
6658 wufc = adapter->wol;
6662 status = er32(STATUS);
6663 if (status & E1000_STATUS_LU)
6664 wufc &= ~E1000_WUFC_LNKC;
6667 e1000_setup_rctl(adapter);
6668 e1000e_set_rx_mode(netdev);
6670 /* turn on all-multi mode if wake on multicast is enabled */
6671 if (wufc & E1000_WUFC_MC) {
6673 rctl |= E1000_RCTL_MPE;
6678 ctrl |= E1000_CTRL_ADVD3WUC;
6679 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
6680 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
6683 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
6684 adapter->hw.phy.media_type ==
6685 e1000_media_type_internal_serdes) {
6686 /* keep the laser running in D3 */
6687 ctrl_ext = er32(CTRL_EXT);
6688 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
6689 ew32(CTRL_EXT, ctrl_ext);
6693 e1000e_power_up_phy(adapter);
6695 if (adapter->flags & FLAG_IS_ICH)
6696 e1000_suspend_workarounds_ich8lan(&adapter->hw);
6698 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6699 /* enable wakeup by the PHY */
6700 retval = e1000_init_phy_wakeup(adapter, wufc);
6704 /* enable wakeup by the MAC */
6706 ew32(WUC, E1000_WUC_PME_EN);
6712 e1000_power_down_phy(adapter);
6715 if (adapter->hw.phy.type == e1000_phy_igp_3) {
6716 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
6717 } else if (hw->mac.type >= e1000_pch_lpt) {
6718 if (wufc && !(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
6719 /* ULP does not support wake from unicast, multicast
6722 retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
6728 /* Ensure that the appropriate bits are set in LPI_CTRL
6731 if ((hw->phy.type >= e1000_phy_i217) &&
6732 adapter->eee_advert && hw->dev_spec.ich8lan.eee_lp_ability) {
6735 retval = hw->phy.ops.acquire(hw);
6737 retval = e1e_rphy_locked(hw, I82579_LPI_CTRL,
6740 if (adapter->eee_advert &
6741 hw->dev_spec.ich8lan.eee_lp_ability &
6742 I82579_EEE_100_SUPPORTED)
6743 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
6744 if (adapter->eee_advert &
6745 hw->dev_spec.ich8lan.eee_lp_ability &
6746 I82579_EEE_1000_SUPPORTED)
6747 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
6749 retval = e1e_wphy_locked(hw, I82579_LPI_CTRL,
6753 hw->phy.ops.release(hw);
6756 /* Release control of h/w to f/w. If f/w is AMT enabled, this
6757 * would have already happened in close and is redundant.
6759 e1000e_release_hw_control(adapter);
6761 pci_clear_master(pdev);
6763 /* The pci-e switch on some quad port adapters will report a
6764 * correctable error when the MAC transitions from D0 to D3. To
6765 * prevent this we need to mask off the correctable errors on the
6766 * downstream port of the pci-e switch.
6768 * We don't have the associated upstream bridge while assigning
6769 * the PCI device into guest. For example, the KVM on power is
6772 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6773 struct pci_dev *us_dev = pdev->bus->self;
6779 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6780 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6781 (devctl & ~PCI_EXP_DEVCTL_CERE));
6783 pci_save_state(pdev);
6784 pci_prepare_to_sleep(pdev);
6786 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
6793 * __e1000e_disable_aspm - Disable ASPM states
6794 * @pdev: pointer to PCI device struct
6795 * @state: bit-mask of ASPM states to disable
6796 * @locked: indication if this context holds pci_bus_sem locked.
6798 * Some devices *must* have certain ASPM states disabled per hardware errata.
6800 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state, int locked)
6802 struct pci_dev *parent = pdev->bus->self;
6803 u16 aspm_dis_mask = 0;
6804 u16 pdev_aspmc, parent_aspmc;
6807 case PCIE_LINK_STATE_L0S:
6808 case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
6809 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
6810 fallthrough; /* can't have L1 without L0s */
6811 case PCIE_LINK_STATE_L1:
6812 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
6818 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6819 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6822 pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
6824 parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6827 /* Nothing to do if the ASPM states to be disabled already are */
6828 if (!(pdev_aspmc & aspm_dis_mask) &&
6829 (!parent || !(parent_aspmc & aspm_dis_mask)))
6832 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6833 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
6835 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
6838 #ifdef CONFIG_PCIEASPM
6840 pci_disable_link_state_locked(pdev, state);
6842 pci_disable_link_state(pdev, state);
6844 /* Double-check ASPM control. If not disabled by the above, the
6845 * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
6846 * not enabled); override by writing PCI config space directly.
6848 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6849 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6851 if (!(aspm_dis_mask & pdev_aspmc))
6855 /* Both device and parent should have the same ASPM setting.
6856 * Disable ASPM in downstream component first and then upstream.
6858 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
6861 pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
6866 * e1000e_disable_aspm - Disable ASPM states.
6867 * @pdev: pointer to PCI device struct
6868 * @state: bit-mask of ASPM states to disable
6870 * This function acquires the pci_bus_sem!
6871 * Some devices *must* have certain ASPM states disabled per hardware errata.
6873 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6875 __e1000e_disable_aspm(pdev, state, 0);
6879 * e1000e_disable_aspm_locked - Disable ASPM states.
6880 * @pdev: pointer to PCI device struct
6881 * @state: bit-mask of ASPM states to disable
6883 * This function must be called with pci_bus_sem acquired!
6884 * Some devices *must* have certain ASPM states disabled per hardware errata.
6886 static void e1000e_disable_aspm_locked(struct pci_dev *pdev, u16 state)
6888 __e1000e_disable_aspm(pdev, state, 1);
6891 static int e1000e_pm_thaw(struct device *dev)
6893 struct net_device *netdev = dev_get_drvdata(dev);
6894 struct e1000_adapter *adapter = netdev_priv(netdev);
6897 e1000e_set_interrupt_capability(adapter);
6900 if (netif_running(netdev)) {
6901 rc = e1000_request_irq(adapter);
6908 netif_device_attach(netdev);
6915 static int __e1000_resume(struct pci_dev *pdev)
6917 struct net_device *netdev = pci_get_drvdata(pdev);
6918 struct e1000_adapter *adapter = netdev_priv(netdev);
6919 struct e1000_hw *hw = &adapter->hw;
6920 u16 aspm_disable_flag = 0;
6922 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6923 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6924 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6925 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6926 if (aspm_disable_flag)
6927 e1000e_disable_aspm(pdev, aspm_disable_flag);
6929 pci_set_master(pdev);
6931 if (hw->mac.type >= e1000_pch2lan)
6932 e1000_resume_workarounds_pchlan(&adapter->hw);
6934 e1000e_power_up_phy(adapter);
6936 /* report the system wakeup cause from S3/S4 */
6937 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6940 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6942 e_info("PHY Wakeup cause - %s\n",
6943 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6944 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6945 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6946 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6947 phy_data & E1000_WUS_LNKC ?
6948 "Link Status Change" : "other");
6950 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6952 u32 wus = er32(WUS);
6955 e_info("MAC Wakeup cause - %s\n",
6956 wus & E1000_WUS_EX ? "Unicast Packet" :
6957 wus & E1000_WUS_MC ? "Multicast Packet" :
6958 wus & E1000_WUS_BC ? "Broadcast Packet" :
6959 wus & E1000_WUS_MAG ? "Magic Packet" :
6960 wus & E1000_WUS_LNKC ? "Link Status Change" :
6966 e1000e_reset(adapter);
6968 e1000_init_manageability_pt(adapter);
6970 /* If the controller has AMT, do not set DRV_LOAD until the interface
6971 * is up. For all other cases, let the f/w know that the h/w is now
6972 * under the control of the driver.
6974 if (!(adapter->flags & FLAG_HAS_AMT))
6975 e1000e_get_hw_control(adapter);
6980 static __maybe_unused int e1000e_pm_prepare(struct device *dev)
6982 return pm_runtime_suspended(dev) &&
6983 pm_suspend_via_firmware();
6986 static __maybe_unused int e1000e_pm_suspend(struct device *dev)
6988 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
6989 struct e1000_adapter *adapter = netdev_priv(netdev);
6990 struct pci_dev *pdev = to_pci_dev(dev);
6993 e1000e_flush_lpic(pdev);
6995 e1000e_pm_freeze(dev);
6997 rc = __e1000_shutdown(pdev, false);
6999 e1000e_pm_thaw(dev);
7001 /* Introduce S0ix implementation */
7002 if (adapter->flags2 & FLAG2_ENABLE_S0IX_FLOWS)
7003 e1000e_s0ix_entry_flow(adapter);
7009 static __maybe_unused int e1000e_pm_resume(struct device *dev)
7011 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
7012 struct e1000_adapter *adapter = netdev_priv(netdev);
7013 struct pci_dev *pdev = to_pci_dev(dev);
7016 /* Introduce S0ix implementation */
7017 if (adapter->flags2 & FLAG2_ENABLE_S0IX_FLOWS)
7018 e1000e_s0ix_exit_flow(adapter);
7020 rc = __e1000_resume(pdev);
7024 return e1000e_pm_thaw(dev);
7027 static __maybe_unused int e1000e_pm_runtime_idle(struct device *dev)
7029 struct net_device *netdev = dev_get_drvdata(dev);
7030 struct e1000_adapter *adapter = netdev_priv(netdev);
7033 eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability;
7035 if (!e1000e_has_link(adapter)) {
7036 adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp;
7037 pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
7043 static __maybe_unused int e1000e_pm_runtime_resume(struct device *dev)
7045 struct pci_dev *pdev = to_pci_dev(dev);
7046 struct net_device *netdev = pci_get_drvdata(pdev);
7047 struct e1000_adapter *adapter = netdev_priv(netdev);
7050 rc = __e1000_resume(pdev);
7054 if (netdev->flags & IFF_UP)
7060 static __maybe_unused int e1000e_pm_runtime_suspend(struct device *dev)
7062 struct pci_dev *pdev = to_pci_dev(dev);
7063 struct net_device *netdev = pci_get_drvdata(pdev);
7064 struct e1000_adapter *adapter = netdev_priv(netdev);
7066 if (netdev->flags & IFF_UP) {
7067 int count = E1000_CHECK_RESET_COUNT;
7069 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
7070 usleep_range(10000, 11000);
7072 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
7074 /* Down the device without resetting the hardware */
7075 e1000e_down(adapter, false);
7078 if (__e1000_shutdown(pdev, true)) {
7079 e1000e_pm_runtime_resume(dev);
7086 static void e1000_shutdown(struct pci_dev *pdev)
7088 e1000e_flush_lpic(pdev);
7090 e1000e_pm_freeze(&pdev->dev);
7092 __e1000_shutdown(pdev, false);
7095 #ifdef CONFIG_NET_POLL_CONTROLLER
7097 static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
7099 struct net_device *netdev = data;
7100 struct e1000_adapter *adapter = netdev_priv(netdev);
7102 if (adapter->msix_entries) {
7103 int vector, msix_irq;
7106 msix_irq = adapter->msix_entries[vector].vector;
7107 if (disable_hardirq(msix_irq))
7108 e1000_intr_msix_rx(msix_irq, netdev);
7109 enable_irq(msix_irq);
7112 msix_irq = adapter->msix_entries[vector].vector;
7113 if (disable_hardirq(msix_irq))
7114 e1000_intr_msix_tx(msix_irq, netdev);
7115 enable_irq(msix_irq);
7118 msix_irq = adapter->msix_entries[vector].vector;
7119 if (disable_hardirq(msix_irq))
7120 e1000_msix_other(msix_irq, netdev);
7121 enable_irq(msix_irq);
7129 * @netdev: network interface device structure
7131 * Polling 'interrupt' - used by things like netconsole to send skbs
7132 * without having to re-enable interrupts. It's not called while
7133 * the interrupt routine is executing.
7135 static void e1000_netpoll(struct net_device *netdev)
7137 struct e1000_adapter *adapter = netdev_priv(netdev);
7139 switch (adapter->int_mode) {
7140 case E1000E_INT_MODE_MSIX:
7141 e1000_intr_msix(adapter->pdev->irq, netdev);
7143 case E1000E_INT_MODE_MSI:
7144 if (disable_hardirq(adapter->pdev->irq))
7145 e1000_intr_msi(adapter->pdev->irq, netdev);
7146 enable_irq(adapter->pdev->irq);
7148 default: /* E1000E_INT_MODE_LEGACY */
7149 if (disable_hardirq(adapter->pdev->irq))
7150 e1000_intr(adapter->pdev->irq, netdev);
7151 enable_irq(adapter->pdev->irq);
7158 * e1000_io_error_detected - called when PCI error is detected
7159 * @pdev: Pointer to PCI device
7160 * @state: The current pci connection state
7162 * This function is called after a PCI bus error affecting
7163 * this device has been detected.
7165 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
7166 pci_channel_state_t state)
7168 e1000e_pm_freeze(&pdev->dev);
7170 if (state == pci_channel_io_perm_failure)
7171 return PCI_ERS_RESULT_DISCONNECT;
7173 pci_disable_device(pdev);
7175 /* Request a slot reset. */
7176 return PCI_ERS_RESULT_NEED_RESET;
7180 * e1000_io_slot_reset - called after the pci bus has been reset.
7181 * @pdev: Pointer to PCI device
7183 * Restart the card from scratch, as if from a cold-boot. Implementation
7184 * resembles the first-half of the e1000e_pm_resume routine.
7186 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
7188 struct net_device *netdev = pci_get_drvdata(pdev);
7189 struct e1000_adapter *adapter = netdev_priv(netdev);
7190 struct e1000_hw *hw = &adapter->hw;
7191 u16 aspm_disable_flag = 0;
7193 pci_ers_result_t result;
7195 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
7196 aspm_disable_flag = PCIE_LINK_STATE_L0S;
7197 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
7198 aspm_disable_flag |= PCIE_LINK_STATE_L1;
7199 if (aspm_disable_flag)
7200 e1000e_disable_aspm_locked(pdev, aspm_disable_flag);
7202 err = pci_enable_device_mem(pdev);
7205 "Cannot re-enable PCI device after reset.\n");
7206 result = PCI_ERS_RESULT_DISCONNECT;
7208 pdev->state_saved = true;
7209 pci_restore_state(pdev);
7210 pci_set_master(pdev);
7212 pci_enable_wake(pdev, PCI_D3hot, 0);
7213 pci_enable_wake(pdev, PCI_D3cold, 0);
7215 e1000e_reset(adapter);
7217 result = PCI_ERS_RESULT_RECOVERED;
7224 * e1000_io_resume - called when traffic can start flowing again.
7225 * @pdev: Pointer to PCI device
7227 * This callback is called when the error recovery driver tells us that
7228 * its OK to resume normal operation. Implementation resembles the
7229 * second-half of the e1000e_pm_resume routine.
7231 static void e1000_io_resume(struct pci_dev *pdev)
7233 struct net_device *netdev = pci_get_drvdata(pdev);
7234 struct e1000_adapter *adapter = netdev_priv(netdev);
7236 e1000_init_manageability_pt(adapter);
7238 e1000e_pm_thaw(&pdev->dev);
7240 /* If the controller has AMT, do not set DRV_LOAD until the interface
7241 * is up. For all other cases, let the f/w know that the h/w is now
7242 * under the control of the driver.
7244 if (!(adapter->flags & FLAG_HAS_AMT))
7245 e1000e_get_hw_control(adapter);
7248 static void e1000_print_device_info(struct e1000_adapter *adapter)
7250 struct e1000_hw *hw = &adapter->hw;
7251 struct net_device *netdev = adapter->netdev;
7253 u8 pba_str[E1000_PBANUM_LENGTH];
7255 /* print bus type/speed/width info */
7256 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
7258 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
7262 e_info("Intel(R) PRO/%s Network Connection\n",
7263 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
7264 ret_val = e1000_read_pba_string_generic(hw, pba_str,
7265 E1000_PBANUM_LENGTH);
7267 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
7268 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
7269 hw->mac.type, hw->phy.type, pba_str);
7272 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
7274 struct e1000_hw *hw = &adapter->hw;
7278 if (hw->mac.type != e1000_82573)
7281 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
7283 if (!ret_val && (!(buf & BIT(0)))) {
7284 /* Deep Smart Power Down (DSPD) */
7285 dev_warn(&adapter->pdev->dev,
7286 "Warning: detected DSPD enabled in EEPROM\n");
7290 static netdev_features_t e1000_fix_features(struct net_device *netdev,
7291 netdev_features_t features)
7293 struct e1000_adapter *adapter = netdev_priv(netdev);
7294 struct e1000_hw *hw = &adapter->hw;
7296 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
7297 if ((hw->mac.type >= e1000_pch2lan) && (netdev->mtu > ETH_DATA_LEN))
7298 features &= ~NETIF_F_RXFCS;
7300 /* Since there is no support for separate Rx/Tx vlan accel
7301 * enable/disable make sure Tx flag is always in same state as Rx.
7303 if (features & NETIF_F_HW_VLAN_CTAG_RX)
7304 features |= NETIF_F_HW_VLAN_CTAG_TX;
7306 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
7311 static int e1000_set_features(struct net_device *netdev,
7312 netdev_features_t features)
7314 struct e1000_adapter *adapter = netdev_priv(netdev);
7315 netdev_features_t changed = features ^ netdev->features;
7317 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
7318 adapter->flags |= FLAG_TSO_FORCE;
7320 if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
7321 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
7325 if (changed & NETIF_F_RXFCS) {
7326 if (features & NETIF_F_RXFCS) {
7327 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
7329 /* We need to take it back to defaults, which might mean
7330 * stripping is still disabled at the adapter level.
7332 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
7333 adapter->flags2 |= FLAG2_CRC_STRIPPING;
7335 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
7339 netdev->features = features;
7341 if (netif_running(netdev))
7342 e1000e_reinit_locked(adapter);
7344 e1000e_reset(adapter);
7349 static const struct net_device_ops e1000e_netdev_ops = {
7350 .ndo_open = e1000e_open,
7351 .ndo_stop = e1000e_close,
7352 .ndo_start_xmit = e1000_xmit_frame,
7353 .ndo_get_stats64 = e1000e_get_stats64,
7354 .ndo_set_rx_mode = e1000e_set_rx_mode,
7355 .ndo_set_mac_address = e1000_set_mac,
7356 .ndo_change_mtu = e1000_change_mtu,
7357 .ndo_eth_ioctl = e1000_ioctl,
7358 .ndo_tx_timeout = e1000_tx_timeout,
7359 .ndo_validate_addr = eth_validate_addr,
7361 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
7362 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
7363 #ifdef CONFIG_NET_POLL_CONTROLLER
7364 .ndo_poll_controller = e1000_netpoll,
7366 .ndo_set_features = e1000_set_features,
7367 .ndo_fix_features = e1000_fix_features,
7368 .ndo_features_check = passthru_features_check,
7372 * e1000_probe - Device Initialization Routine
7373 * @pdev: PCI device information struct
7374 * @ent: entry in e1000_pci_tbl
7376 * Returns 0 on success, negative on failure
7378 * e1000_probe initializes an adapter identified by a pci_dev structure.
7379 * The OS initialization, configuring of the adapter private structure,
7380 * and a hardware reset occur.
7382 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7384 struct net_device *netdev;
7385 struct e1000_adapter *adapter;
7386 struct e1000_hw *hw;
7387 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
7388 resource_size_t mmio_start, mmio_len;
7389 resource_size_t flash_start, flash_len;
7390 static int cards_found;
7391 u16 aspm_disable_flag = 0;
7392 int bars, i, err, pci_using_dac;
7393 u16 eeprom_data = 0;
7394 u16 eeprom_apme_mask = E1000_EEPROM_APME;
7397 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
7398 aspm_disable_flag = PCIE_LINK_STATE_L0S;
7399 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
7400 aspm_disable_flag |= PCIE_LINK_STATE_L1;
7401 if (aspm_disable_flag)
7402 e1000e_disable_aspm(pdev, aspm_disable_flag);
7404 err = pci_enable_device_mem(pdev);
7409 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
7413 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
7416 "No usable DMA configuration, aborting\n");
7421 bars = pci_select_bars(pdev, IORESOURCE_MEM);
7422 err = pci_request_selected_regions_exclusive(pdev, bars,
7423 e1000e_driver_name);
7427 /* AER (Advanced Error Reporting) hooks */
7428 pci_enable_pcie_error_reporting(pdev);
7430 pci_set_master(pdev);
7431 /* PCI config space info */
7432 err = pci_save_state(pdev);
7434 goto err_alloc_etherdev;
7437 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
7439 goto err_alloc_etherdev;
7441 SET_NETDEV_DEV(netdev, &pdev->dev);
7443 netdev->irq = pdev->irq;
7445 pci_set_drvdata(pdev, netdev);
7446 adapter = netdev_priv(netdev);
7448 adapter->netdev = netdev;
7449 adapter->pdev = pdev;
7451 adapter->pba = ei->pba;
7452 adapter->flags = ei->flags;
7453 adapter->flags2 = ei->flags2;
7454 adapter->hw.adapter = adapter;
7455 adapter->hw.mac.type = ei->mac;
7456 adapter->max_hw_frame_size = ei->max_hw_frame_size;
7457 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
7459 mmio_start = pci_resource_start(pdev, 0);
7460 mmio_len = pci_resource_len(pdev, 0);
7463 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
7464 if (!adapter->hw.hw_addr)
7467 if ((adapter->flags & FLAG_HAS_FLASH) &&
7468 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM) &&
7469 (hw->mac.type < e1000_pch_spt)) {
7470 flash_start = pci_resource_start(pdev, 1);
7471 flash_len = pci_resource_len(pdev, 1);
7472 adapter->hw.flash_address = ioremap(flash_start, flash_len);
7473 if (!adapter->hw.flash_address)
7477 /* Set default EEE advertisement */
7478 if (adapter->flags2 & FLAG2_HAS_EEE)
7479 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
7481 /* construct the net_device struct */
7482 netdev->netdev_ops = &e1000e_netdev_ops;
7483 e1000e_set_ethtool_ops(netdev);
7484 netdev->watchdog_timeo = 5 * HZ;
7485 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
7486 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
7488 netdev->mem_start = mmio_start;
7489 netdev->mem_end = mmio_start + mmio_len;
7491 adapter->bd_number = cards_found++;
7493 e1000e_check_options(adapter);
7495 /* setup adapter struct */
7496 err = e1000_sw_init(adapter);
7500 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
7501 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
7502 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
7504 err = ei->get_variants(adapter);
7508 if ((adapter->flags & FLAG_IS_ICH) &&
7509 (adapter->flags & FLAG_READ_ONLY_NVM) &&
7510 (hw->mac.type < e1000_pch_spt))
7511 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
7513 hw->mac.ops.get_bus_info(&adapter->hw);
7515 adapter->hw.phy.autoneg_wait_to_complete = 0;
7517 /* Copper options */
7518 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
7519 adapter->hw.phy.mdix = AUTO_ALL_MODES;
7520 adapter->hw.phy.disable_polarity_correction = 0;
7521 adapter->hw.phy.ms_type = e1000_ms_hw_default;
7524 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
7525 dev_info(&pdev->dev,
7526 "PHY reset is blocked due to SOL/IDER session.\n");
7528 /* Set initial default active device features */
7529 netdev->features = (NETIF_F_SG |
7530 NETIF_F_HW_VLAN_CTAG_RX |
7531 NETIF_F_HW_VLAN_CTAG_TX |
7538 /* Set user-changeable features (subset of all device features) */
7539 netdev->hw_features = netdev->features;
7540 netdev->hw_features |= NETIF_F_RXFCS;
7541 netdev->priv_flags |= IFF_SUPP_NOFCS;
7542 netdev->hw_features |= NETIF_F_RXALL;
7544 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
7545 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
7547 netdev->vlan_features |= (NETIF_F_SG |
7552 netdev->priv_flags |= IFF_UNICAST_FLT;
7554 if (pci_using_dac) {
7555 netdev->features |= NETIF_F_HIGHDMA;
7556 netdev->vlan_features |= NETIF_F_HIGHDMA;
7559 /* MTU range: 68 - max_hw_frame_size */
7560 netdev->min_mtu = ETH_MIN_MTU;
7561 netdev->max_mtu = adapter->max_hw_frame_size -
7562 (VLAN_ETH_HLEN + ETH_FCS_LEN);
7564 if (e1000e_enable_mng_pass_thru(&adapter->hw))
7565 adapter->flags |= FLAG_MNG_PT_ENABLED;
7567 /* before reading the NVM, reset the controller to
7568 * put the device in a known good starting state
7570 adapter->hw.mac.ops.reset_hw(&adapter->hw);
7572 /* systems with ASPM and others may see the checksum fail on the first
7573 * attempt. Let's give it a few tries
7576 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
7579 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
7585 e1000_eeprom_checks(adapter);
7587 /* copy the MAC address */
7588 if (e1000e_read_mac_addr(&adapter->hw))
7590 "NVM Read Error while reading MAC address\n");
7592 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
7594 if (!is_valid_ether_addr(netdev->dev_addr)) {
7595 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
7601 timer_setup(&adapter->watchdog_timer, e1000_watchdog, 0);
7602 timer_setup(&adapter->phy_info_timer, e1000_update_phy_info, 0);
7604 INIT_WORK(&adapter->reset_task, e1000_reset_task);
7605 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
7606 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
7607 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
7608 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
7610 /* Initialize link parameters. User can change them with ethtool */
7611 adapter->hw.mac.autoneg = 1;
7612 adapter->fc_autoneg = true;
7613 adapter->hw.fc.requested_mode = e1000_fc_default;
7614 adapter->hw.fc.current_mode = e1000_fc_default;
7615 adapter->hw.phy.autoneg_advertised = 0x2f;
7617 /* Initial Wake on LAN setting - If APM wake is enabled in
7618 * the EEPROM, enable the ACPI Magic Packet filter
7620 if (adapter->flags & FLAG_APME_IN_WUC) {
7621 /* APME bit in EEPROM is mapped to WUC.APME */
7622 eeprom_data = er32(WUC);
7623 eeprom_apme_mask = E1000_WUC_APME;
7624 if ((hw->mac.type > e1000_ich10lan) &&
7625 (eeprom_data & E1000_WUC_PHY_WAKE))
7626 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
7627 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
7628 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
7629 (adapter->hw.bus.func == 1))
7630 ret_val = e1000_read_nvm(&adapter->hw,
7631 NVM_INIT_CONTROL3_PORT_B,
7634 ret_val = e1000_read_nvm(&adapter->hw,
7635 NVM_INIT_CONTROL3_PORT_A,
7639 /* fetch WoL from EEPROM */
7641 e_dbg("NVM read error getting WoL initial values: %d\n", ret_val);
7642 else if (eeprom_data & eeprom_apme_mask)
7643 adapter->eeprom_wol |= E1000_WUFC_MAG;
7645 /* now that we have the eeprom settings, apply the special cases
7646 * where the eeprom may be wrong or the board simply won't support
7647 * wake on lan on a particular port
7649 if (!(adapter->flags & FLAG_HAS_WOL))
7650 adapter->eeprom_wol = 0;
7652 /* initialize the wol settings based on the eeprom settings */
7653 adapter->wol = adapter->eeprom_wol;
7655 /* make sure adapter isn't asleep if manageability is enabled */
7656 if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
7657 (hw->mac.ops.check_mng_mode(hw)))
7658 device_wakeup_enable(&pdev->dev);
7660 /* save off EEPROM version number */
7661 ret_val = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
7664 e_dbg("NVM read error getting EEPROM version: %d\n", ret_val);
7665 adapter->eeprom_vers = 0;
7668 /* init PTP hardware clock */
7669 e1000e_ptp_init(adapter);
7671 /* reset the hardware with the new settings */
7672 e1000e_reset(adapter);
7674 /* If the controller has AMT, do not set DRV_LOAD until the interface
7675 * is up. For all other cases, let the f/w know that the h/w is now
7676 * under the control of the driver.
7678 if (!(adapter->flags & FLAG_HAS_AMT))
7679 e1000e_get_hw_control(adapter);
7681 if (hw->mac.type >= e1000_pch_cnp)
7682 adapter->flags2 |= FLAG2_ENABLE_S0IX_FLOWS;
7684 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
7685 err = register_netdev(netdev);
7689 /* carrier off reporting is important to ethtool even BEFORE open */
7690 netif_carrier_off(netdev);
7692 e1000_print_device_info(adapter);
7694 dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_SMART_PREPARE);
7696 if (pci_dev_run_wake(pdev) && hw->mac.type != e1000_pch_cnp)
7697 pm_runtime_put_noidle(&pdev->dev);
7702 if (!(adapter->flags & FLAG_HAS_AMT))
7703 e1000e_release_hw_control(adapter);
7705 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
7706 e1000_phy_hw_reset(&adapter->hw);
7708 kfree(adapter->tx_ring);
7709 kfree(adapter->rx_ring);
7711 if ((adapter->hw.flash_address) && (hw->mac.type < e1000_pch_spt))
7712 iounmap(adapter->hw.flash_address);
7713 e1000e_reset_interrupt_capability(adapter);
7715 iounmap(adapter->hw.hw_addr);
7717 free_netdev(netdev);
7719 pci_disable_pcie_error_reporting(pdev);
7720 pci_release_mem_regions(pdev);
7723 pci_disable_device(pdev);
7728 * e1000_remove - Device Removal Routine
7729 * @pdev: PCI device information struct
7731 * e1000_remove is called by the PCI subsystem to alert the driver
7732 * that it should release a PCI device. This could be caused by a
7733 * Hot-Plug event, or because the driver is going to be removed from
7736 static void e1000_remove(struct pci_dev *pdev)
7738 struct net_device *netdev = pci_get_drvdata(pdev);
7739 struct e1000_adapter *adapter = netdev_priv(netdev);
7741 e1000e_ptp_remove(adapter);
7743 /* The timers may be rescheduled, so explicitly disable them
7744 * from being rescheduled.
7746 set_bit(__E1000_DOWN, &adapter->state);
7747 del_timer_sync(&adapter->watchdog_timer);
7748 del_timer_sync(&adapter->phy_info_timer);
7750 cancel_work_sync(&adapter->reset_task);
7751 cancel_work_sync(&adapter->watchdog_task);
7752 cancel_work_sync(&adapter->downshift_task);
7753 cancel_work_sync(&adapter->update_phy_task);
7754 cancel_work_sync(&adapter->print_hang_task);
7756 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
7757 cancel_work_sync(&adapter->tx_hwtstamp_work);
7758 if (adapter->tx_hwtstamp_skb) {
7759 dev_consume_skb_any(adapter->tx_hwtstamp_skb);
7760 adapter->tx_hwtstamp_skb = NULL;
7764 unregister_netdev(netdev);
7766 if (pci_dev_run_wake(pdev))
7767 pm_runtime_get_noresume(&pdev->dev);
7769 /* Release control of h/w to f/w. If f/w is AMT enabled, this
7770 * would have already happened in close and is redundant.
7772 e1000e_release_hw_control(adapter);
7774 e1000e_reset_interrupt_capability(adapter);
7775 kfree(adapter->tx_ring);
7776 kfree(adapter->rx_ring);
7778 iounmap(adapter->hw.hw_addr);
7779 if ((adapter->hw.flash_address) &&
7780 (adapter->hw.mac.type < e1000_pch_spt))
7781 iounmap(adapter->hw.flash_address);
7782 pci_release_mem_regions(pdev);
7784 free_netdev(netdev);
7787 pci_disable_pcie_error_reporting(pdev);
7789 pci_disable_device(pdev);
7792 /* PCI Error Recovery (ERS) */
7793 static const struct pci_error_handlers e1000_err_handler = {
7794 .error_detected = e1000_io_error_detected,
7795 .slot_reset = e1000_io_slot_reset,
7796 .resume = e1000_io_resume,
7799 static const struct pci_device_id e1000_pci_tbl[] = {
7800 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
7801 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
7802 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
7803 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
7805 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
7806 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
7807 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
7808 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
7809 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
7811 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
7812 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
7813 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
7814 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
7816 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
7817 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
7818 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
7820 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
7821 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
7822 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
7824 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
7825 board_80003es2lan },
7826 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
7827 board_80003es2lan },
7828 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
7829 board_80003es2lan },
7830 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
7831 board_80003es2lan },
7833 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
7834 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
7835 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
7836 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
7837 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
7838 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
7839 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
7840 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
7842 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
7843 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
7844 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
7845 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
7846 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
7847 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
7848 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
7849 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
7850 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
7852 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
7853 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
7854 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
7856 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
7857 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
7858 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
7860 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
7861 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
7862 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
7863 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
7865 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
7866 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7868 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7869 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
7870 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7871 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
7872 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
7873 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
7874 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
7875 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
7876 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM), board_pch_spt },
7877 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V), board_pch_spt },
7878 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM2), board_pch_spt },
7879 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V2), board_pch_spt },
7880 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LBG_I219_LM3), board_pch_spt },
7881 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM4), board_pch_spt },
7882 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V4), board_pch_spt },
7883 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM5), board_pch_spt },
7884 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V5), board_pch_spt },
7885 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM6), board_pch_cnp },
7886 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V6), board_pch_cnp },
7887 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM7), board_pch_cnp },
7888 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V7), board_pch_cnp },
7889 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM8), board_pch_cnp },
7890 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V8), board_pch_cnp },
7891 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM9), board_pch_cnp },
7892 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V9), board_pch_cnp },
7893 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM10), board_pch_cnp },
7894 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V10), board_pch_cnp },
7895 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM11), board_pch_cnp },
7896 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V11), board_pch_cnp },
7897 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM12), board_pch_spt },
7898 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V12), board_pch_spt },
7899 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM13), board_pch_cnp },
7900 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V13), board_pch_cnp },
7901 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM14), board_pch_cnp },
7902 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V14), board_pch_cnp },
7903 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM15), board_pch_cnp },
7904 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V15), board_pch_cnp },
7905 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_RPL_I219_LM23), board_pch_cnp },
7906 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_RPL_I219_V23), board_pch_cnp },
7907 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM16), board_pch_cnp },
7908 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V16), board_pch_cnp },
7909 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM17), board_pch_cnp },
7910 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V17), board_pch_cnp },
7911 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_RPL_I219_LM22), board_pch_cnp },
7912 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_RPL_I219_V22), board_pch_cnp },
7913 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_LM18), board_pch_cnp },
7914 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_V18), board_pch_cnp },
7915 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_LM19), board_pch_cnp },
7916 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_V19), board_pch_cnp },
7917 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LNP_I219_LM20), board_pch_cnp },
7918 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LNP_I219_V20), board_pch_cnp },
7919 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LNP_I219_LM21), board_pch_cnp },
7920 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LNP_I219_V21), board_pch_cnp },
7922 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
7924 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7926 static const struct dev_pm_ops e1000_pm_ops = {
7927 #ifdef CONFIG_PM_SLEEP
7928 .prepare = e1000e_pm_prepare,
7929 .suspend = e1000e_pm_suspend,
7930 .resume = e1000e_pm_resume,
7931 .freeze = e1000e_pm_freeze,
7932 .thaw = e1000e_pm_thaw,
7933 .poweroff = e1000e_pm_suspend,
7934 .restore = e1000e_pm_resume,
7936 SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
7937 e1000e_pm_runtime_idle)
7940 /* PCI Device API Driver */
7941 static struct pci_driver e1000_driver = {
7942 .name = e1000e_driver_name,
7943 .id_table = e1000_pci_tbl,
7944 .probe = e1000_probe,
7945 .remove = e1000_remove,
7947 .pm = &e1000_pm_ops,
7949 .shutdown = e1000_shutdown,
7950 .err_handler = &e1000_err_handler
7954 * e1000_init_module - Driver Registration Routine
7956 * e1000_init_module is the first routine called when the driver is
7957 * loaded. All it does is register with the PCI subsystem.
7959 static int __init e1000_init_module(void)
7961 pr_info("Intel(R) PRO/1000 Network Driver\n");
7962 pr_info("Copyright(c) 1999 - 2015 Intel Corporation.\n");
7964 return pci_register_driver(&e1000_driver);
7966 module_init(e1000_init_module);
7969 * e1000_exit_module - Driver Exit Cleanup Routine
7971 * e1000_exit_module is called just before the driver is removed
7974 static void __exit e1000_exit_module(void)
7976 pci_unregister_driver(&e1000_driver);
7978 module_exit(e1000_exit_module);
7981 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7982 MODULE_LICENSE("GPL v2");