1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/module.h>
32 #include <linux/types.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/vmalloc.h>
36 #include <linux/pagemap.h>
37 #include <linux/delay.h>
38 #include <linux/netdevice.h>
39 #include <linux/interrupt.h>
40 #include <linux/tcp.h>
41 #include <linux/ipv6.h>
42 #include <linux/slab.h>
43 #include <net/checksum.h>
44 #include <net/ip6_checksum.h>
45 #include <linux/mii.h>
46 #include <linux/ethtool.h>
47 #include <linux/if_vlan.h>
48 #include <linux/cpu.h>
49 #include <linux/smp.h>
50 #include <linux/pm_qos.h>
51 #include <linux/pm_runtime.h>
52 #include <linux/aer.h>
53 #include <linux/prefetch.h>
57 #define DRV_EXTRAVERSION "-k"
59 #define DRV_VERSION "1.10.6" DRV_EXTRAVERSION
60 char e1000e_driver_name[] = "e1000e";
61 const char e1000e_driver_version[] = DRV_VERSION;
63 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
64 static int debug = -1;
65 module_param(debug, int, 0);
66 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
68 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
70 static const struct e1000_info *e1000_info_tbl[] = {
71 [board_82571] = &e1000_82571_info,
72 [board_82572] = &e1000_82572_info,
73 [board_82573] = &e1000_82573_info,
74 [board_82574] = &e1000_82574_info,
75 [board_82583] = &e1000_82583_info,
76 [board_80003es2lan] = &e1000_es2_info,
77 [board_ich8lan] = &e1000_ich8_info,
78 [board_ich9lan] = &e1000_ich9_info,
79 [board_ich10lan] = &e1000_ich10_info,
80 [board_pchlan] = &e1000_pch_info,
81 [board_pch2lan] = &e1000_pch2_info,
84 struct e1000_reg_info {
89 #define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
90 #define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
91 #define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
92 #define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
93 #define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
95 #define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
96 #define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
97 #define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
98 #define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
99 #define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
101 static const struct e1000_reg_info e1000_reg_info_tbl[] = {
103 /* General Registers */
104 {E1000_CTRL, "CTRL"},
105 {E1000_STATUS, "STATUS"},
106 {E1000_CTRL_EXT, "CTRL_EXT"},
108 /* Interrupt Registers */
112 {E1000_RCTL, "RCTL"},
113 {E1000_RDLEN(0), "RDLEN"},
114 {E1000_RDH(0), "RDH"},
115 {E1000_RDT(0), "RDT"},
116 {E1000_RDTR, "RDTR"},
117 {E1000_RXDCTL(0), "RXDCTL"},
119 {E1000_RDBAL(0), "RDBAL"},
120 {E1000_RDBAH(0), "RDBAH"},
121 {E1000_RDFH, "RDFH"},
122 {E1000_RDFT, "RDFT"},
123 {E1000_RDFHS, "RDFHS"},
124 {E1000_RDFTS, "RDFTS"},
125 {E1000_RDFPC, "RDFPC"},
128 {E1000_TCTL, "TCTL"},
129 {E1000_TDBAL(0), "TDBAL"},
130 {E1000_TDBAH(0), "TDBAH"},
131 {E1000_TDLEN(0), "TDLEN"},
132 {E1000_TDH(0), "TDH"},
133 {E1000_TDT(0), "TDT"},
134 {E1000_TIDV, "TIDV"},
135 {E1000_TXDCTL(0), "TXDCTL"},
136 {E1000_TADV, "TADV"},
137 {E1000_TARC(0), "TARC"},
138 {E1000_TDFH, "TDFH"},
139 {E1000_TDFT, "TDFT"},
140 {E1000_TDFHS, "TDFHS"},
141 {E1000_TDFTS, "TDFTS"},
142 {E1000_TDFPC, "TDFPC"},
144 /* List Terminator */
149 * e1000_regdump - register printout routine
151 static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
157 switch (reginfo->ofs) {
158 case E1000_RXDCTL(0):
159 for (n = 0; n < 2; n++)
160 regs[n] = __er32(hw, E1000_RXDCTL(n));
162 case E1000_TXDCTL(0):
163 for (n = 0; n < 2; n++)
164 regs[n] = __er32(hw, E1000_TXDCTL(n));
167 for (n = 0; n < 2; n++)
168 regs[n] = __er32(hw, E1000_TARC(n));
171 pr_info("%-15s %08x\n",
172 reginfo->name, __er32(hw, reginfo->ofs));
176 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
177 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
181 * e1000e_dump - Print registers, Tx-ring and Rx-ring
183 static void e1000e_dump(struct e1000_adapter *adapter)
185 struct net_device *netdev = adapter->netdev;
186 struct e1000_hw *hw = &adapter->hw;
187 struct e1000_reg_info *reginfo;
188 struct e1000_ring *tx_ring = adapter->tx_ring;
189 struct e1000_tx_desc *tx_desc;
194 struct e1000_buffer *buffer_info;
195 struct e1000_ring *rx_ring = adapter->rx_ring;
196 union e1000_rx_desc_packet_split *rx_desc_ps;
197 union e1000_rx_desc_extended *rx_desc;
207 if (!netif_msg_hw(adapter))
210 /* Print netdevice Info */
212 dev_info(&adapter->pdev->dev, "Net device Info\n");
213 pr_info("Device Name state trans_start last_rx\n");
214 pr_info("%-15s %016lX %016lX %016lX\n",
215 netdev->name, netdev->state, netdev->trans_start,
219 /* Print Registers */
220 dev_info(&adapter->pdev->dev, "Register Dump\n");
221 pr_info(" Register Name Value\n");
222 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
223 reginfo->name; reginfo++) {
224 e1000_regdump(hw, reginfo);
227 /* Print Tx Ring Summary */
228 if (!netdev || !netif_running(netdev))
231 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
232 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
233 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
234 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
235 0, tx_ring->next_to_use, tx_ring->next_to_clean,
236 (unsigned long long)buffer_info->dma,
238 buffer_info->next_to_watch,
239 (unsigned long long)buffer_info->time_stamp);
242 if (!netif_msg_tx_done(adapter))
243 goto rx_ring_summary;
245 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
247 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
249 * Legacy Transmit Descriptor
250 * +--------------------------------------------------------------+
251 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
252 * +--------------------------------------------------------------+
253 * 8 | Special | CSS | Status | CMD | CSO | Length |
254 * +--------------------------------------------------------------+
255 * 63 48 47 36 35 32 31 24 23 16 15 0
257 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
258 * 63 48 47 40 39 32 31 16 15 8 7 0
259 * +----------------------------------------------------------------+
260 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
261 * +----------------------------------------------------------------+
262 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
263 * +----------------------------------------------------------------+
264 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
266 * Extended Data Descriptor (DTYP=0x1)
267 * +----------------------------------------------------------------+
268 * 0 | Buffer Address [63:0] |
269 * +----------------------------------------------------------------+
270 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
271 * +----------------------------------------------------------------+
272 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
274 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
275 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
276 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
277 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
278 const char *next_desc;
279 tx_desc = E1000_TX_DESC(*tx_ring, i);
280 buffer_info = &tx_ring->buffer_info[i];
281 u0 = (struct my_u0 *)tx_desc;
282 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
283 next_desc = " NTC/U";
284 else if (i == tx_ring->next_to_use)
286 else if (i == tx_ring->next_to_clean)
290 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
291 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
292 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
294 (unsigned long long)le64_to_cpu(u0->a),
295 (unsigned long long)le64_to_cpu(u0->b),
296 (unsigned long long)buffer_info->dma,
297 buffer_info->length, buffer_info->next_to_watch,
298 (unsigned long long)buffer_info->time_stamp,
299 buffer_info->skb, next_desc);
301 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
302 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
303 16, 1, phys_to_virt(buffer_info->dma),
304 buffer_info->length, true);
307 /* Print Rx Ring Summary */
309 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
310 pr_info("Queue [NTU] [NTC]\n");
311 pr_info(" %5d %5X %5X\n",
312 0, rx_ring->next_to_use, rx_ring->next_to_clean);
315 if (!netif_msg_rx_status(adapter))
318 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
319 switch (adapter->rx_ps_pages) {
323 /* [Extended] Packet Split Receive Descriptor Format
325 * +-----------------------------------------------------+
326 * 0 | Buffer Address 0 [63:0] |
327 * +-----------------------------------------------------+
328 * 8 | Buffer Address 1 [63:0] |
329 * +-----------------------------------------------------+
330 * 16 | Buffer Address 2 [63:0] |
331 * +-----------------------------------------------------+
332 * 24 | Buffer Address 3 [63:0] |
333 * +-----------------------------------------------------+
335 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");
336 /* [Extended] Receive Descriptor (Write-Back) Format
338 * 63 48 47 32 31 13 12 8 7 4 3 0
339 * +------------------------------------------------------+
340 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
341 * | Checksum | Ident | | Queue | | Type |
342 * +------------------------------------------------------+
343 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
344 * +------------------------------------------------------+
345 * 63 48 47 32 31 20 19 0
347 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
348 for (i = 0; i < rx_ring->count; i++) {
349 const char *next_desc;
350 buffer_info = &rx_ring->buffer_info[i];
351 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
352 u1 = (struct my_u1 *)rx_desc_ps;
354 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
356 if (i == rx_ring->next_to_use)
358 else if (i == rx_ring->next_to_clean)
363 if (staterr & E1000_RXD_STAT_DD) {
364 /* Descriptor Done */
365 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
367 (unsigned long long)le64_to_cpu(u1->a),
368 (unsigned long long)le64_to_cpu(u1->b),
369 (unsigned long long)le64_to_cpu(u1->c),
370 (unsigned long long)le64_to_cpu(u1->d),
371 buffer_info->skb, next_desc);
373 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
375 (unsigned long long)le64_to_cpu(u1->a),
376 (unsigned long long)le64_to_cpu(u1->b),
377 (unsigned long long)le64_to_cpu(u1->c),
378 (unsigned long long)le64_to_cpu(u1->d),
379 (unsigned long long)buffer_info->dma,
380 buffer_info->skb, next_desc);
382 if (netif_msg_pktdata(adapter))
383 print_hex_dump(KERN_INFO, "",
384 DUMP_PREFIX_ADDRESS, 16, 1,
385 phys_to_virt(buffer_info->dma),
386 adapter->rx_ps_bsize0, true);
392 /* Extended Receive Descriptor (Read) Format
394 * +-----------------------------------------------------+
395 * 0 | Buffer Address [63:0] |
396 * +-----------------------------------------------------+
398 * +-----------------------------------------------------+
400 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
401 /* Extended Receive Descriptor (Write-Back) Format
403 * 63 48 47 32 31 24 23 4 3 0
404 * +------------------------------------------------------+
406 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
407 * | Packet | IP | | | Type |
408 * | Checksum | Ident | | | |
409 * +------------------------------------------------------+
410 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
411 * +------------------------------------------------------+
412 * 63 48 47 32 31 20 19 0
414 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
416 for (i = 0; i < rx_ring->count; i++) {
417 const char *next_desc;
419 buffer_info = &rx_ring->buffer_info[i];
420 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
421 u1 = (struct my_u1 *)rx_desc;
422 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
424 if (i == rx_ring->next_to_use)
426 else if (i == rx_ring->next_to_clean)
431 if (staterr & E1000_RXD_STAT_DD) {
432 /* Descriptor Done */
433 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
435 (unsigned long long)le64_to_cpu(u1->a),
436 (unsigned long long)le64_to_cpu(u1->b),
437 buffer_info->skb, next_desc);
439 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
441 (unsigned long long)le64_to_cpu(u1->a),
442 (unsigned long long)le64_to_cpu(u1->b),
443 (unsigned long long)buffer_info->dma,
444 buffer_info->skb, next_desc);
446 if (netif_msg_pktdata(adapter))
447 print_hex_dump(KERN_INFO, "",
448 DUMP_PREFIX_ADDRESS, 16,
452 adapter->rx_buffer_len,
460 * e1000_desc_unused - calculate if we have unused descriptors
462 static int e1000_desc_unused(struct e1000_ring *ring)
464 if (ring->next_to_clean > ring->next_to_use)
465 return ring->next_to_clean - ring->next_to_use - 1;
467 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
471 * e1000_receive_skb - helper function to handle Rx indications
472 * @adapter: board private structure
473 * @status: descriptor status field as written by hardware
474 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
475 * @skb: pointer to sk_buff to be indicated to stack
477 static void e1000_receive_skb(struct e1000_adapter *adapter,
478 struct net_device *netdev, struct sk_buff *skb,
479 u8 status, __le16 vlan)
481 u16 tag = le16_to_cpu(vlan);
482 skb->protocol = eth_type_trans(skb, netdev);
484 if (status & E1000_RXD_STAT_VP)
485 __vlan_hwaccel_put_tag(skb, tag);
487 napi_gro_receive(&adapter->napi, skb);
491 * e1000_rx_checksum - Receive Checksum Offload
492 * @adapter: board private structure
493 * @status_err: receive descriptor status and error fields
494 * @csum: receive descriptor csum field
495 * @sk_buff: socket buffer with received data
497 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
498 __le16 csum, struct sk_buff *skb)
500 u16 status = (u16)status_err;
501 u8 errors = (u8)(status_err >> 24);
503 skb_checksum_none_assert(skb);
505 /* Rx checksum disabled */
506 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
509 /* Ignore Checksum bit is set */
510 if (status & E1000_RXD_STAT_IXSM)
513 /* TCP/UDP checksum error bit is set */
514 if (errors & E1000_RXD_ERR_TCPE) {
515 /* let the stack verify checksum errors */
516 adapter->hw_csum_err++;
520 /* TCP/UDP Checksum has not been calculated */
521 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
524 /* It must be a TCP or UDP packet with a valid checksum */
525 if (status & E1000_RXD_STAT_TCPCS) {
526 /* TCP checksum is good */
527 skb->ip_summed = CHECKSUM_UNNECESSARY;
530 * IP fragment with UDP payload
531 * Hardware complements the payload checksum, so we undo it
532 * and then put the value in host order for further stack use.
534 __sum16 sum = (__force __sum16)swab16((__force u16)csum);
535 skb->csum = csum_unfold(~sum);
536 skb->ip_summed = CHECKSUM_COMPLETE;
538 adapter->hw_csum_good++;
542 * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa()
543 * @hw: pointer to the HW structure
544 * @tail: address of tail descriptor register
545 * @i: value to write to tail descriptor register
547 * When updating the tail register, the ME could be accessing Host CSR
548 * registers at the same time. Normally, this is handled in h/w by an
549 * arbiter but on some parts there is a bug that acknowledges Host accesses
550 * later than it should which could result in the descriptor register to
551 * have an incorrect value. Workaround this by checking the FWSM register
552 * which has bit 24 set while ME is accessing Host CSR registers, wait
553 * if it is set and try again a number of times.
555 static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, void __iomem *tail,
560 while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) &&
561 (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI))
566 if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail)))
567 return E1000_ERR_SWFW_SYNC;
572 static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
574 struct e1000_adapter *adapter = rx_ring->adapter;
575 struct e1000_hw *hw = &adapter->hw;
577 if (e1000e_update_tail_wa(hw, rx_ring->tail, i)) {
578 u32 rctl = er32(RCTL);
579 ew32(RCTL, rctl & ~E1000_RCTL_EN);
580 e_err("ME firmware caused invalid RDT - resetting\n");
581 schedule_work(&adapter->reset_task);
585 static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
587 struct e1000_adapter *adapter = tx_ring->adapter;
588 struct e1000_hw *hw = &adapter->hw;
590 if (e1000e_update_tail_wa(hw, tx_ring->tail, i)) {
591 u32 tctl = er32(TCTL);
592 ew32(TCTL, tctl & ~E1000_TCTL_EN);
593 e_err("ME firmware caused invalid TDT - resetting\n");
594 schedule_work(&adapter->reset_task);
599 * e1000_alloc_rx_buffers - Replace used receive buffers
600 * @rx_ring: Rx descriptor ring
602 static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
603 int cleaned_count, gfp_t gfp)
605 struct e1000_adapter *adapter = rx_ring->adapter;
606 struct net_device *netdev = adapter->netdev;
607 struct pci_dev *pdev = adapter->pdev;
608 union e1000_rx_desc_extended *rx_desc;
609 struct e1000_buffer *buffer_info;
612 unsigned int bufsz = adapter->rx_buffer_len;
614 i = rx_ring->next_to_use;
615 buffer_info = &rx_ring->buffer_info[i];
617 while (cleaned_count--) {
618 skb = buffer_info->skb;
624 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
626 /* Better luck next round */
627 adapter->alloc_rx_buff_failed++;
631 buffer_info->skb = skb;
633 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
634 adapter->rx_buffer_len,
636 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
637 dev_err(&pdev->dev, "Rx DMA map failed\n");
638 adapter->rx_dma_failed++;
642 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
643 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
645 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
647 * Force memory writes to complete before letting h/w
648 * know there are new descriptors to fetch. (Only
649 * applicable for weak-ordered memory model archs,
653 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
654 e1000e_update_rdt_wa(rx_ring, i);
656 writel(i, rx_ring->tail);
659 if (i == rx_ring->count)
661 buffer_info = &rx_ring->buffer_info[i];
664 rx_ring->next_to_use = i;
668 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
669 * @rx_ring: Rx descriptor ring
671 static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
672 int cleaned_count, gfp_t gfp)
674 struct e1000_adapter *adapter = rx_ring->adapter;
675 struct net_device *netdev = adapter->netdev;
676 struct pci_dev *pdev = adapter->pdev;
677 union e1000_rx_desc_packet_split *rx_desc;
678 struct e1000_buffer *buffer_info;
679 struct e1000_ps_page *ps_page;
683 i = rx_ring->next_to_use;
684 buffer_info = &rx_ring->buffer_info[i];
686 while (cleaned_count--) {
687 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
689 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
690 ps_page = &buffer_info->ps_pages[j];
691 if (j >= adapter->rx_ps_pages) {
692 /* all unused desc entries get hw null ptr */
693 rx_desc->read.buffer_addr[j + 1] =
697 if (!ps_page->page) {
698 ps_page->page = alloc_page(gfp);
699 if (!ps_page->page) {
700 adapter->alloc_rx_buff_failed++;
703 ps_page->dma = dma_map_page(&pdev->dev,
707 if (dma_mapping_error(&pdev->dev,
709 dev_err(&adapter->pdev->dev,
710 "Rx DMA page map failed\n");
711 adapter->rx_dma_failed++;
716 * Refresh the desc even if buffer_addrs
717 * didn't change because each write-back
720 rx_desc->read.buffer_addr[j + 1] =
721 cpu_to_le64(ps_page->dma);
724 skb = __netdev_alloc_skb_ip_align(netdev,
725 adapter->rx_ps_bsize0,
729 adapter->alloc_rx_buff_failed++;
733 buffer_info->skb = skb;
734 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
735 adapter->rx_ps_bsize0,
737 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
738 dev_err(&pdev->dev, "Rx DMA map failed\n");
739 adapter->rx_dma_failed++;
741 dev_kfree_skb_any(skb);
742 buffer_info->skb = NULL;
746 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
748 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
750 * Force memory writes to complete before letting h/w
751 * know there are new descriptors to fetch. (Only
752 * applicable for weak-ordered memory model archs,
756 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
757 e1000e_update_rdt_wa(rx_ring, i << 1);
759 writel(i << 1, rx_ring->tail);
763 if (i == rx_ring->count)
765 buffer_info = &rx_ring->buffer_info[i];
769 rx_ring->next_to_use = i;
773 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
774 * @rx_ring: Rx descriptor ring
775 * @cleaned_count: number of buffers to allocate this pass
778 static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
779 int cleaned_count, gfp_t gfp)
781 struct e1000_adapter *adapter = rx_ring->adapter;
782 struct net_device *netdev = adapter->netdev;
783 struct pci_dev *pdev = adapter->pdev;
784 union e1000_rx_desc_extended *rx_desc;
785 struct e1000_buffer *buffer_info;
788 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
790 i = rx_ring->next_to_use;
791 buffer_info = &rx_ring->buffer_info[i];
793 while (cleaned_count--) {
794 skb = buffer_info->skb;
800 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
801 if (unlikely(!skb)) {
802 /* Better luck next round */
803 adapter->alloc_rx_buff_failed++;
807 buffer_info->skb = skb;
809 /* allocate a new page if necessary */
810 if (!buffer_info->page) {
811 buffer_info->page = alloc_page(gfp);
812 if (unlikely(!buffer_info->page)) {
813 adapter->alloc_rx_buff_failed++;
818 if (!buffer_info->dma)
819 buffer_info->dma = dma_map_page(&pdev->dev,
820 buffer_info->page, 0,
824 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
825 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
827 if (unlikely(++i == rx_ring->count))
829 buffer_info = &rx_ring->buffer_info[i];
832 if (likely(rx_ring->next_to_use != i)) {
833 rx_ring->next_to_use = i;
834 if (unlikely(i-- == 0))
835 i = (rx_ring->count - 1);
837 /* Force memory writes to complete before letting h/w
838 * know there are new descriptors to fetch. (Only
839 * applicable for weak-ordered memory model archs,
842 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
843 e1000e_update_rdt_wa(rx_ring, i);
845 writel(i, rx_ring->tail);
849 static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
852 if (netdev->features & NETIF_F_RXHASH)
853 skb->rxhash = le32_to_cpu(rss);
857 * e1000_clean_rx_irq - Send received data up the network stack
858 * @rx_ring: Rx descriptor ring
860 * the return value indicates whether actual cleaning was done, there
861 * is no guarantee that everything was cleaned
863 static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
866 struct e1000_adapter *adapter = rx_ring->adapter;
867 struct net_device *netdev = adapter->netdev;
868 struct pci_dev *pdev = adapter->pdev;
869 struct e1000_hw *hw = &adapter->hw;
870 union e1000_rx_desc_extended *rx_desc, *next_rxd;
871 struct e1000_buffer *buffer_info, *next_buffer;
874 int cleaned_count = 0;
875 bool cleaned = false;
876 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
878 i = rx_ring->next_to_clean;
879 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
880 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
881 buffer_info = &rx_ring->buffer_info[i];
883 while (staterr & E1000_RXD_STAT_DD) {
886 if (*work_done >= work_to_do)
889 rmb(); /* read descriptor and rx_buffer_info after status DD */
891 skb = buffer_info->skb;
892 buffer_info->skb = NULL;
894 prefetch(skb->data - NET_IP_ALIGN);
897 if (i == rx_ring->count)
899 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
902 next_buffer = &rx_ring->buffer_info[i];
906 dma_unmap_single(&pdev->dev,
908 adapter->rx_buffer_len,
910 buffer_info->dma = 0;
912 length = le16_to_cpu(rx_desc->wb.upper.length);
915 * !EOP means multiple descriptors were used to store a single
916 * packet, if that's the case we need to toss it. In fact, we
917 * need to toss every packet with the EOP bit clear and the
918 * next frame that _does_ have the EOP bit set, as it is by
919 * definition only a frame fragment
921 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
922 adapter->flags2 |= FLAG2_IS_DISCARDING;
924 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
925 /* All receives must fit into a single buffer */
926 e_dbg("Receive packet consumed multiple buffers\n");
928 buffer_info->skb = skb;
929 if (staterr & E1000_RXD_STAT_EOP)
930 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
934 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
935 !(netdev->features & NETIF_F_RXALL))) {
937 buffer_info->skb = skb;
941 /* adjust length to remove Ethernet CRC */
942 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
943 /* If configured to store CRC, don't subtract FCS,
944 * but keep the FCS bytes out of the total_rx_bytes
947 if (netdev->features & NETIF_F_RXFCS)
953 total_rx_bytes += length;
957 * code added for copybreak, this should improve
958 * performance for small packets with large amounts
959 * of reassembly being done in the stack
961 if (length < copybreak) {
962 struct sk_buff *new_skb =
963 netdev_alloc_skb_ip_align(netdev, length);
965 skb_copy_to_linear_data_offset(new_skb,
971 /* save the skb in buffer_info as good */
972 buffer_info->skb = skb;
975 /* else just continue with the old one */
977 /* end copybreak code */
978 skb_put(skb, length);
980 /* Receive Checksum Offload */
981 e1000_rx_checksum(adapter, staterr,
982 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
984 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
986 e1000_receive_skb(adapter, netdev, skb, staterr,
987 rx_desc->wb.upper.vlan);
990 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
992 /* return some buffers to hardware, one at a time is too slow */
993 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
994 adapter->alloc_rx_buf(rx_ring, cleaned_count,
999 /* use prefetched values */
1001 buffer_info = next_buffer;
1003 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1005 rx_ring->next_to_clean = i;
1007 cleaned_count = e1000_desc_unused(rx_ring);
1009 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1011 adapter->total_rx_bytes += total_rx_bytes;
1012 adapter->total_rx_packets += total_rx_packets;
1016 static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1017 struct e1000_buffer *buffer_info)
1019 struct e1000_adapter *adapter = tx_ring->adapter;
1021 if (buffer_info->dma) {
1022 if (buffer_info->mapped_as_page)
1023 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1024 buffer_info->length, DMA_TO_DEVICE);
1026 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1027 buffer_info->length, DMA_TO_DEVICE);
1028 buffer_info->dma = 0;
1030 if (buffer_info->skb) {
1031 dev_kfree_skb_any(buffer_info->skb);
1032 buffer_info->skb = NULL;
1034 buffer_info->time_stamp = 0;
1037 static void e1000_print_hw_hang(struct work_struct *work)
1039 struct e1000_adapter *adapter = container_of(work,
1040 struct e1000_adapter,
1042 struct net_device *netdev = adapter->netdev;
1043 struct e1000_ring *tx_ring = adapter->tx_ring;
1044 unsigned int i = tx_ring->next_to_clean;
1045 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1046 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
1047 struct e1000_hw *hw = &adapter->hw;
1048 u16 phy_status, phy_1000t_status, phy_ext_status;
1051 if (test_bit(__E1000_DOWN, &adapter->state))
1054 if (!adapter->tx_hang_recheck &&
1055 (adapter->flags2 & FLAG2_DMA_BURST)) {
1057 * May be block on write-back, flush and detect again
1058 * flush pending descriptor writebacks to memory
1060 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1061 /* execute the writes immediately */
1064 * Due to rare timing issues, write to TIDV again to ensure
1065 * the write is successful
1067 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1068 /* execute the writes immediately */
1070 adapter->tx_hang_recheck = true;
1073 /* Real hang detected */
1074 adapter->tx_hang_recheck = false;
1075 netif_stop_queue(netdev);
1077 e1e_rphy(hw, PHY_STATUS, &phy_status);
1078 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1079 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1081 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1083 /* detected Hardware unit hang */
1084 e_err("Detected Hardware Unit Hang:\n"
1087 " next_to_use <%x>\n"
1088 " next_to_clean <%x>\n"
1089 "buffer_info[next_to_clean]:\n"
1090 " time_stamp <%lx>\n"
1091 " next_to_watch <%x>\n"
1093 " next_to_watch.status <%x>\n"
1096 "PHY 1000BASE-T Status <%x>\n"
1097 "PHY Extended Status <%x>\n"
1098 "PCI Status <%x>\n",
1099 readl(tx_ring->head),
1100 readl(tx_ring->tail),
1101 tx_ring->next_to_use,
1102 tx_ring->next_to_clean,
1103 tx_ring->buffer_info[eop].time_stamp,
1106 eop_desc->upper.fields.status,
1115 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1116 * @tx_ring: Tx descriptor ring
1118 * the return value indicates whether actual cleaning was done, there
1119 * is no guarantee that everything was cleaned
1121 static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
1123 struct e1000_adapter *adapter = tx_ring->adapter;
1124 struct net_device *netdev = adapter->netdev;
1125 struct e1000_hw *hw = &adapter->hw;
1126 struct e1000_tx_desc *tx_desc, *eop_desc;
1127 struct e1000_buffer *buffer_info;
1128 unsigned int i, eop;
1129 unsigned int count = 0;
1130 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1131 unsigned int bytes_compl = 0, pkts_compl = 0;
1133 i = tx_ring->next_to_clean;
1134 eop = tx_ring->buffer_info[i].next_to_watch;
1135 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1137 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1138 (count < tx_ring->count)) {
1139 bool cleaned = false;
1140 rmb(); /* read buffer_info after eop_desc */
1141 for (; !cleaned; count++) {
1142 tx_desc = E1000_TX_DESC(*tx_ring, i);
1143 buffer_info = &tx_ring->buffer_info[i];
1144 cleaned = (i == eop);
1147 total_tx_packets += buffer_info->segs;
1148 total_tx_bytes += buffer_info->bytecount;
1149 if (buffer_info->skb) {
1150 bytes_compl += buffer_info->skb->len;
1155 e1000_put_txbuf(tx_ring, buffer_info);
1156 tx_desc->upper.data = 0;
1159 if (i == tx_ring->count)
1163 if (i == tx_ring->next_to_use)
1165 eop = tx_ring->buffer_info[i].next_to_watch;
1166 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1169 tx_ring->next_to_clean = i;
1171 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1173 #define TX_WAKE_THRESHOLD 32
1174 if (count && netif_carrier_ok(netdev) &&
1175 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
1176 /* Make sure that anybody stopping the queue after this
1177 * sees the new next_to_clean.
1181 if (netif_queue_stopped(netdev) &&
1182 !(test_bit(__E1000_DOWN, &adapter->state))) {
1183 netif_wake_queue(netdev);
1184 ++adapter->restart_queue;
1188 if (adapter->detect_tx_hung) {
1190 * Detect a transmit hang in hardware, this serializes the
1191 * check with the clearing of time_stamp and movement of i
1193 adapter->detect_tx_hung = false;
1194 if (tx_ring->buffer_info[i].time_stamp &&
1195 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
1196 + (adapter->tx_timeout_factor * HZ)) &&
1197 !(er32(STATUS) & E1000_STATUS_TXOFF))
1198 schedule_work(&adapter->print_hang_task);
1200 adapter->tx_hang_recheck = false;
1202 adapter->total_tx_bytes += total_tx_bytes;
1203 adapter->total_tx_packets += total_tx_packets;
1204 return count < tx_ring->count;
1208 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1209 * @rx_ring: Rx descriptor ring
1211 * the return value indicates whether actual cleaning was done, there
1212 * is no guarantee that everything was cleaned
1214 static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1217 struct e1000_adapter *adapter = rx_ring->adapter;
1218 struct e1000_hw *hw = &adapter->hw;
1219 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1220 struct net_device *netdev = adapter->netdev;
1221 struct pci_dev *pdev = adapter->pdev;
1222 struct e1000_buffer *buffer_info, *next_buffer;
1223 struct e1000_ps_page *ps_page;
1224 struct sk_buff *skb;
1226 u32 length, staterr;
1227 int cleaned_count = 0;
1228 bool cleaned = false;
1229 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1231 i = rx_ring->next_to_clean;
1232 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1233 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1234 buffer_info = &rx_ring->buffer_info[i];
1236 while (staterr & E1000_RXD_STAT_DD) {
1237 if (*work_done >= work_to_do)
1240 skb = buffer_info->skb;
1241 rmb(); /* read descriptor and rx_buffer_info after status DD */
1243 /* in the packet split case this is header only */
1244 prefetch(skb->data - NET_IP_ALIGN);
1247 if (i == rx_ring->count)
1249 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1252 next_buffer = &rx_ring->buffer_info[i];
1256 dma_unmap_single(&pdev->dev, buffer_info->dma,
1257 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
1258 buffer_info->dma = 0;
1260 /* see !EOP comment in other Rx routine */
1261 if (!(staterr & E1000_RXD_STAT_EOP))
1262 adapter->flags2 |= FLAG2_IS_DISCARDING;
1264 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
1265 e_dbg("Packet Split buffers didn't pick up the full packet\n");
1266 dev_kfree_skb_irq(skb);
1267 if (staterr & E1000_RXD_STAT_EOP)
1268 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1272 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1273 !(netdev->features & NETIF_F_RXALL))) {
1274 dev_kfree_skb_irq(skb);
1278 length = le16_to_cpu(rx_desc->wb.middle.length0);
1281 e_dbg("Last part of the packet spanning multiple descriptors\n");
1282 dev_kfree_skb_irq(skb);
1287 skb_put(skb, length);
1291 * this looks ugly, but it seems compiler issues make
1292 * it more efficient than reusing j
1294 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1297 * page alloc/put takes too long and effects small
1298 * packet throughput, so unsplit small packets and
1299 * save the alloc/put only valid in softirq (napi)
1300 * context to call kmap_*
1302 if (l1 && (l1 <= copybreak) &&
1303 ((length + l1) <= adapter->rx_ps_bsize0)) {
1306 ps_page = &buffer_info->ps_pages[0];
1309 * there is no documentation about how to call
1310 * kmap_atomic, so we can't hold the mapping
1313 dma_sync_single_for_cpu(&pdev->dev,
1317 vaddr = kmap_atomic(ps_page->page);
1318 memcpy(skb_tail_pointer(skb), vaddr, l1);
1319 kunmap_atomic(vaddr);
1320 dma_sync_single_for_device(&pdev->dev,
1325 /* remove the CRC */
1326 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1327 if (!(netdev->features & NETIF_F_RXFCS))
1336 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1337 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1341 ps_page = &buffer_info->ps_pages[j];
1342 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1345 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1346 ps_page->page = NULL;
1348 skb->data_len += length;
1349 skb->truesize += PAGE_SIZE;
1352 /* strip the ethernet crc, problem is we're using pages now so
1353 * this whole operation can get a little cpu intensive
1355 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1356 if (!(netdev->features & NETIF_F_RXFCS))
1357 pskb_trim(skb, skb->len - 4);
1361 total_rx_bytes += skb->len;
1364 e1000_rx_checksum(adapter, staterr,
1365 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1367 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1369 if (rx_desc->wb.upper.header_status &
1370 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1371 adapter->rx_hdr_split++;
1373 e1000_receive_skb(adapter, netdev, skb,
1374 staterr, rx_desc->wb.middle.vlan);
1377 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1378 buffer_info->skb = NULL;
1380 /* return some buffers to hardware, one at a time is too slow */
1381 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1382 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1387 /* use prefetched values */
1389 buffer_info = next_buffer;
1391 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1393 rx_ring->next_to_clean = i;
1395 cleaned_count = e1000_desc_unused(rx_ring);
1397 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1399 adapter->total_rx_bytes += total_rx_bytes;
1400 adapter->total_rx_packets += total_rx_packets;
1405 * e1000_consume_page - helper function
1407 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1412 skb->data_len += length;
1413 skb->truesize += PAGE_SIZE;
1417 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1418 * @adapter: board private structure
1420 * the return value indicates whether actual cleaning was done, there
1421 * is no guarantee that everything was cleaned
1423 static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1426 struct e1000_adapter *adapter = rx_ring->adapter;
1427 struct net_device *netdev = adapter->netdev;
1428 struct pci_dev *pdev = adapter->pdev;
1429 union e1000_rx_desc_extended *rx_desc, *next_rxd;
1430 struct e1000_buffer *buffer_info, *next_buffer;
1431 u32 length, staterr;
1433 int cleaned_count = 0;
1434 bool cleaned = false;
1435 unsigned int total_rx_bytes=0, total_rx_packets=0;
1437 i = rx_ring->next_to_clean;
1438 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1439 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1440 buffer_info = &rx_ring->buffer_info[i];
1442 while (staterr & E1000_RXD_STAT_DD) {
1443 struct sk_buff *skb;
1445 if (*work_done >= work_to_do)
1448 rmb(); /* read descriptor and rx_buffer_info after status DD */
1450 skb = buffer_info->skb;
1451 buffer_info->skb = NULL;
1454 if (i == rx_ring->count)
1456 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
1459 next_buffer = &rx_ring->buffer_info[i];
1463 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1465 buffer_info->dma = 0;
1467 length = le16_to_cpu(rx_desc->wb.upper.length);
1469 /* errors is only valid for DD + EOP descriptors */
1470 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1471 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1472 !(netdev->features & NETIF_F_RXALL)))) {
1473 /* recycle both page and skb */
1474 buffer_info->skb = skb;
1475 /* an error means any chain goes out the window too */
1476 if (rx_ring->rx_skb_top)
1477 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1478 rx_ring->rx_skb_top = NULL;
1482 #define rxtop (rx_ring->rx_skb_top)
1483 if (!(staterr & E1000_RXD_STAT_EOP)) {
1484 /* this descriptor is only the beginning (or middle) */
1486 /* this is the beginning of a chain */
1488 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1491 /* this is the middle of a chain */
1492 skb_fill_page_desc(rxtop,
1493 skb_shinfo(rxtop)->nr_frags,
1494 buffer_info->page, 0, length);
1495 /* re-use the skb, only consumed the page */
1496 buffer_info->skb = skb;
1498 e1000_consume_page(buffer_info, rxtop, length);
1502 /* end of the chain */
1503 skb_fill_page_desc(rxtop,
1504 skb_shinfo(rxtop)->nr_frags,
1505 buffer_info->page, 0, length);
1506 /* re-use the current skb, we only consumed the
1508 buffer_info->skb = skb;
1511 e1000_consume_page(buffer_info, skb, length);
1513 /* no chain, got EOP, this buf is the packet
1514 * copybreak to save the put_page/alloc_page */
1515 if (length <= copybreak &&
1516 skb_tailroom(skb) >= length) {
1518 vaddr = kmap_atomic(buffer_info->page);
1519 memcpy(skb_tail_pointer(skb), vaddr,
1521 kunmap_atomic(vaddr);
1522 /* re-use the page, so don't erase
1523 * buffer_info->page */
1524 skb_put(skb, length);
1526 skb_fill_page_desc(skb, 0,
1527 buffer_info->page, 0,
1529 e1000_consume_page(buffer_info, skb,
1535 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1536 e1000_rx_checksum(adapter, staterr,
1537 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1539 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1541 /* probably a little skewed due to removing CRC */
1542 total_rx_bytes += skb->len;
1545 /* eth type trans needs skb->data to point to something */
1546 if (!pskb_may_pull(skb, ETH_HLEN)) {
1547 e_err("pskb_may_pull failed.\n");
1548 dev_kfree_skb_irq(skb);
1552 e1000_receive_skb(adapter, netdev, skb, staterr,
1553 rx_desc->wb.upper.vlan);
1556 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
1558 /* return some buffers to hardware, one at a time is too slow */
1559 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1560 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1565 /* use prefetched values */
1567 buffer_info = next_buffer;
1569 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1571 rx_ring->next_to_clean = i;
1573 cleaned_count = e1000_desc_unused(rx_ring);
1575 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1577 adapter->total_rx_bytes += total_rx_bytes;
1578 adapter->total_rx_packets += total_rx_packets;
1583 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1584 * @rx_ring: Rx descriptor ring
1586 static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
1588 struct e1000_adapter *adapter = rx_ring->adapter;
1589 struct e1000_buffer *buffer_info;
1590 struct e1000_ps_page *ps_page;
1591 struct pci_dev *pdev = adapter->pdev;
1594 /* Free all the Rx ring sk_buffs */
1595 for (i = 0; i < rx_ring->count; i++) {
1596 buffer_info = &rx_ring->buffer_info[i];
1597 if (buffer_info->dma) {
1598 if (adapter->clean_rx == e1000_clean_rx_irq)
1599 dma_unmap_single(&pdev->dev, buffer_info->dma,
1600 adapter->rx_buffer_len,
1602 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1603 dma_unmap_page(&pdev->dev, buffer_info->dma,
1606 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1607 dma_unmap_single(&pdev->dev, buffer_info->dma,
1608 adapter->rx_ps_bsize0,
1610 buffer_info->dma = 0;
1613 if (buffer_info->page) {
1614 put_page(buffer_info->page);
1615 buffer_info->page = NULL;
1618 if (buffer_info->skb) {
1619 dev_kfree_skb(buffer_info->skb);
1620 buffer_info->skb = NULL;
1623 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1624 ps_page = &buffer_info->ps_pages[j];
1627 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1630 put_page(ps_page->page);
1631 ps_page->page = NULL;
1635 /* there also may be some cached data from a chained receive */
1636 if (rx_ring->rx_skb_top) {
1637 dev_kfree_skb(rx_ring->rx_skb_top);
1638 rx_ring->rx_skb_top = NULL;
1641 /* Zero out the descriptor ring */
1642 memset(rx_ring->desc, 0, rx_ring->size);
1644 rx_ring->next_to_clean = 0;
1645 rx_ring->next_to_use = 0;
1646 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1648 writel(0, rx_ring->head);
1649 writel(0, rx_ring->tail);
1652 static void e1000e_downshift_workaround(struct work_struct *work)
1654 struct e1000_adapter *adapter = container_of(work,
1655 struct e1000_adapter, downshift_task);
1657 if (test_bit(__E1000_DOWN, &adapter->state))
1660 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1664 * e1000_intr_msi - Interrupt Handler
1665 * @irq: interrupt number
1666 * @data: pointer to a network interface device structure
1668 static irqreturn_t e1000_intr_msi(int irq, void *data)
1670 struct net_device *netdev = data;
1671 struct e1000_adapter *adapter = netdev_priv(netdev);
1672 struct e1000_hw *hw = &adapter->hw;
1673 u32 icr = er32(ICR);
1676 * read ICR disables interrupts using IAM
1679 if (icr & E1000_ICR_LSC) {
1680 hw->mac.get_link_status = true;
1682 * ICH8 workaround-- Call gig speed drop workaround on cable
1683 * disconnect (LSC) before accessing any PHY registers
1685 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1686 (!(er32(STATUS) & E1000_STATUS_LU)))
1687 schedule_work(&adapter->downshift_task);
1690 * 80003ES2LAN workaround-- For packet buffer work-around on
1691 * link down event; disable receives here in the ISR and reset
1692 * adapter in watchdog
1694 if (netif_carrier_ok(netdev) &&
1695 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1696 /* disable receives */
1697 u32 rctl = er32(RCTL);
1698 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1699 adapter->flags |= FLAG_RX_RESTART_NOW;
1701 /* guard against interrupt when we're going down */
1702 if (!test_bit(__E1000_DOWN, &adapter->state))
1703 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1706 if (napi_schedule_prep(&adapter->napi)) {
1707 adapter->total_tx_bytes = 0;
1708 adapter->total_tx_packets = 0;
1709 adapter->total_rx_bytes = 0;
1710 adapter->total_rx_packets = 0;
1711 __napi_schedule(&adapter->napi);
1718 * e1000_intr - Interrupt Handler
1719 * @irq: interrupt number
1720 * @data: pointer to a network interface device structure
1722 static irqreturn_t e1000_intr(int irq, void *data)
1724 struct net_device *netdev = data;
1725 struct e1000_adapter *adapter = netdev_priv(netdev);
1726 struct e1000_hw *hw = &adapter->hw;
1727 u32 rctl, icr = er32(ICR);
1729 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
1730 return IRQ_NONE; /* Not our interrupt */
1733 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1734 * not set, then the adapter didn't send an interrupt
1736 if (!(icr & E1000_ICR_INT_ASSERTED))
1740 * Interrupt Auto-Mask...upon reading ICR,
1741 * interrupts are masked. No need for the
1745 if (icr & E1000_ICR_LSC) {
1746 hw->mac.get_link_status = true;
1748 * ICH8 workaround-- Call gig speed drop workaround on cable
1749 * disconnect (LSC) before accessing any PHY registers
1751 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1752 (!(er32(STATUS) & E1000_STATUS_LU)))
1753 schedule_work(&adapter->downshift_task);
1756 * 80003ES2LAN workaround--
1757 * For packet buffer work-around on link down event;
1758 * disable receives here in the ISR and
1759 * reset adapter in watchdog
1761 if (netif_carrier_ok(netdev) &&
1762 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1763 /* disable receives */
1765 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1766 adapter->flags |= FLAG_RX_RESTART_NOW;
1768 /* guard against interrupt when we're going down */
1769 if (!test_bit(__E1000_DOWN, &adapter->state))
1770 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1773 if (napi_schedule_prep(&adapter->napi)) {
1774 adapter->total_tx_bytes = 0;
1775 adapter->total_tx_packets = 0;
1776 adapter->total_rx_bytes = 0;
1777 adapter->total_rx_packets = 0;
1778 __napi_schedule(&adapter->napi);
1784 static irqreturn_t e1000_msix_other(int irq, void *data)
1786 struct net_device *netdev = data;
1787 struct e1000_adapter *adapter = netdev_priv(netdev);
1788 struct e1000_hw *hw = &adapter->hw;
1789 u32 icr = er32(ICR);
1791 if (!(icr & E1000_ICR_INT_ASSERTED)) {
1792 if (!test_bit(__E1000_DOWN, &adapter->state))
1793 ew32(IMS, E1000_IMS_OTHER);
1797 if (icr & adapter->eiac_mask)
1798 ew32(ICS, (icr & adapter->eiac_mask));
1800 if (icr & E1000_ICR_OTHER) {
1801 if (!(icr & E1000_ICR_LSC))
1802 goto no_link_interrupt;
1803 hw->mac.get_link_status = true;
1804 /* guard against interrupt when we're going down */
1805 if (!test_bit(__E1000_DOWN, &adapter->state))
1806 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1810 if (!test_bit(__E1000_DOWN, &adapter->state))
1811 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
1817 static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1819 struct net_device *netdev = data;
1820 struct e1000_adapter *adapter = netdev_priv(netdev);
1821 struct e1000_hw *hw = &adapter->hw;
1822 struct e1000_ring *tx_ring = adapter->tx_ring;
1825 adapter->total_tx_bytes = 0;
1826 adapter->total_tx_packets = 0;
1828 if (!e1000_clean_tx_irq(tx_ring))
1829 /* Ring was not completely cleaned, so fire another interrupt */
1830 ew32(ICS, tx_ring->ims_val);
1835 static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1837 struct net_device *netdev = data;
1838 struct e1000_adapter *adapter = netdev_priv(netdev);
1839 struct e1000_ring *rx_ring = adapter->rx_ring;
1841 /* Write the ITR value calculated at the end of the
1842 * previous interrupt.
1844 if (rx_ring->set_itr) {
1845 writel(1000000000 / (rx_ring->itr_val * 256),
1846 rx_ring->itr_register);
1847 rx_ring->set_itr = 0;
1850 if (napi_schedule_prep(&adapter->napi)) {
1851 adapter->total_rx_bytes = 0;
1852 adapter->total_rx_packets = 0;
1853 __napi_schedule(&adapter->napi);
1859 * e1000_configure_msix - Configure MSI-X hardware
1861 * e1000_configure_msix sets up the hardware to properly
1862 * generate MSI-X interrupts.
1864 static void e1000_configure_msix(struct e1000_adapter *adapter)
1866 struct e1000_hw *hw = &adapter->hw;
1867 struct e1000_ring *rx_ring = adapter->rx_ring;
1868 struct e1000_ring *tx_ring = adapter->tx_ring;
1870 u32 ctrl_ext, ivar = 0;
1872 adapter->eiac_mask = 0;
1874 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1875 if (hw->mac.type == e1000_82574) {
1876 u32 rfctl = er32(RFCTL);
1877 rfctl |= E1000_RFCTL_ACK_DIS;
1881 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1882 /* Configure Rx vector */
1883 rx_ring->ims_val = E1000_IMS_RXQ0;
1884 adapter->eiac_mask |= rx_ring->ims_val;
1885 if (rx_ring->itr_val)
1886 writel(1000000000 / (rx_ring->itr_val * 256),
1887 rx_ring->itr_register);
1889 writel(1, rx_ring->itr_register);
1890 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1892 /* Configure Tx vector */
1893 tx_ring->ims_val = E1000_IMS_TXQ0;
1895 if (tx_ring->itr_val)
1896 writel(1000000000 / (tx_ring->itr_val * 256),
1897 tx_ring->itr_register);
1899 writel(1, tx_ring->itr_register);
1900 adapter->eiac_mask |= tx_ring->ims_val;
1901 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1903 /* set vector for Other Causes, e.g. link changes */
1905 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1906 if (rx_ring->itr_val)
1907 writel(1000000000 / (rx_ring->itr_val * 256),
1908 hw->hw_addr + E1000_EITR_82574(vector));
1910 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1912 /* Cause Tx interrupts on every write back */
1917 /* enable MSI-X PBA support */
1918 ctrl_ext = er32(CTRL_EXT);
1919 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1921 /* Auto-Mask Other interrupts upon ICR read */
1922 #define E1000_EIAC_MASK_82574 0x01F00000
1923 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1924 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1925 ew32(CTRL_EXT, ctrl_ext);
1929 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1931 if (adapter->msix_entries) {
1932 pci_disable_msix(adapter->pdev);
1933 kfree(adapter->msix_entries);
1934 adapter->msix_entries = NULL;
1935 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1936 pci_disable_msi(adapter->pdev);
1937 adapter->flags &= ~FLAG_MSI_ENABLED;
1942 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1944 * Attempt to configure interrupts using the best available
1945 * capabilities of the hardware and kernel.
1947 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1952 switch (adapter->int_mode) {
1953 case E1000E_INT_MODE_MSIX:
1954 if (adapter->flags & FLAG_HAS_MSIX) {
1955 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1956 adapter->msix_entries = kcalloc(adapter->num_vectors,
1957 sizeof(struct msix_entry),
1959 if (adapter->msix_entries) {
1960 for (i = 0; i < adapter->num_vectors; i++)
1961 adapter->msix_entries[i].entry = i;
1963 err = pci_enable_msix(adapter->pdev,
1964 adapter->msix_entries,
1965 adapter->num_vectors);
1969 /* MSI-X failed, so fall through and try MSI */
1970 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
1971 e1000e_reset_interrupt_capability(adapter);
1973 adapter->int_mode = E1000E_INT_MODE_MSI;
1975 case E1000E_INT_MODE_MSI:
1976 if (!pci_enable_msi(adapter->pdev)) {
1977 adapter->flags |= FLAG_MSI_ENABLED;
1979 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1980 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
1983 case E1000E_INT_MODE_LEGACY:
1984 /* Don't do anything; this is the system default */
1988 /* store the number of vectors being used */
1989 adapter->num_vectors = 1;
1993 * e1000_request_msix - Initialize MSI-X interrupts
1995 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1998 static int e1000_request_msix(struct e1000_adapter *adapter)
2000 struct net_device *netdev = adapter->netdev;
2001 int err = 0, vector = 0;
2003 if (strlen(netdev->name) < (IFNAMSIZ - 5))
2004 snprintf(adapter->rx_ring->name,
2005 sizeof(adapter->rx_ring->name) - 1,
2006 "%s-rx-0", netdev->name);
2008 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2009 err = request_irq(adapter->msix_entries[vector].vector,
2010 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
2014 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2015 E1000_EITR_82574(vector);
2016 adapter->rx_ring->itr_val = adapter->itr;
2019 if (strlen(netdev->name) < (IFNAMSIZ - 5))
2020 snprintf(adapter->tx_ring->name,
2021 sizeof(adapter->tx_ring->name) - 1,
2022 "%s-tx-0", netdev->name);
2024 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2025 err = request_irq(adapter->msix_entries[vector].vector,
2026 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
2030 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2031 E1000_EITR_82574(vector);
2032 adapter->tx_ring->itr_val = adapter->itr;
2035 err = request_irq(adapter->msix_entries[vector].vector,
2036 e1000_msix_other, 0, netdev->name, netdev);
2040 e1000_configure_msix(adapter);
2046 * e1000_request_irq - initialize interrupts
2048 * Attempts to configure interrupts using the best available
2049 * capabilities of the hardware and kernel.
2051 static int e1000_request_irq(struct e1000_adapter *adapter)
2053 struct net_device *netdev = adapter->netdev;
2056 if (adapter->msix_entries) {
2057 err = e1000_request_msix(adapter);
2060 /* fall back to MSI */
2061 e1000e_reset_interrupt_capability(adapter);
2062 adapter->int_mode = E1000E_INT_MODE_MSI;
2063 e1000e_set_interrupt_capability(adapter);
2065 if (adapter->flags & FLAG_MSI_ENABLED) {
2066 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
2067 netdev->name, netdev);
2071 /* fall back to legacy interrupt */
2072 e1000e_reset_interrupt_capability(adapter);
2073 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2076 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
2077 netdev->name, netdev);
2079 e_err("Unable to allocate interrupt, Error: %d\n", err);
2084 static void e1000_free_irq(struct e1000_adapter *adapter)
2086 struct net_device *netdev = adapter->netdev;
2088 if (adapter->msix_entries) {
2091 free_irq(adapter->msix_entries[vector].vector, netdev);
2094 free_irq(adapter->msix_entries[vector].vector, netdev);
2097 /* Other Causes interrupt vector */
2098 free_irq(adapter->msix_entries[vector].vector, netdev);
2102 free_irq(adapter->pdev->irq, netdev);
2106 * e1000_irq_disable - Mask off interrupt generation on the NIC
2108 static void e1000_irq_disable(struct e1000_adapter *adapter)
2110 struct e1000_hw *hw = &adapter->hw;
2113 if (adapter->msix_entries)
2114 ew32(EIAC_82574, 0);
2117 if (adapter->msix_entries) {
2119 for (i = 0; i < adapter->num_vectors; i++)
2120 synchronize_irq(adapter->msix_entries[i].vector);
2122 synchronize_irq(adapter->pdev->irq);
2127 * e1000_irq_enable - Enable default interrupt generation settings
2129 static void e1000_irq_enable(struct e1000_adapter *adapter)
2131 struct e1000_hw *hw = &adapter->hw;
2133 if (adapter->msix_entries) {
2134 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2135 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2137 ew32(IMS, IMS_ENABLE_MASK);
2143 * e1000e_get_hw_control - get control of the h/w from f/w
2144 * @adapter: address of board private structure
2146 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2147 * For ASF and Pass Through versions of f/w this means that
2148 * the driver is loaded. For AMT version (only with 82573)
2149 * of the f/w this means that the network i/f is open.
2151 void e1000e_get_hw_control(struct e1000_adapter *adapter)
2153 struct e1000_hw *hw = &adapter->hw;
2157 /* Let firmware know the driver has taken over */
2158 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2160 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2161 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2162 ctrl_ext = er32(CTRL_EXT);
2163 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2168 * e1000e_release_hw_control - release control of the h/w to f/w
2169 * @adapter: address of board private structure
2171 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2172 * For ASF and Pass Through versions of f/w this means that the
2173 * driver is no longer loaded. For AMT version (only with 82573) i
2174 * of the f/w this means that the network i/f is closed.
2177 void e1000e_release_hw_control(struct e1000_adapter *adapter)
2179 struct e1000_hw *hw = &adapter->hw;
2183 /* Let firmware taken over control of h/w */
2184 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2186 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2187 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2188 ctrl_ext = er32(CTRL_EXT);
2189 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2194 * @e1000_alloc_ring - allocate memory for a ring structure
2196 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2197 struct e1000_ring *ring)
2199 struct pci_dev *pdev = adapter->pdev;
2201 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2210 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2211 * @tx_ring: Tx descriptor ring
2213 * Return 0 on success, negative on failure
2215 int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
2217 struct e1000_adapter *adapter = tx_ring->adapter;
2218 int err = -ENOMEM, size;
2220 size = sizeof(struct e1000_buffer) * tx_ring->count;
2221 tx_ring->buffer_info = vzalloc(size);
2222 if (!tx_ring->buffer_info)
2225 /* round up to nearest 4K */
2226 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2227 tx_ring->size = ALIGN(tx_ring->size, 4096);
2229 err = e1000_alloc_ring_dma(adapter, tx_ring);
2233 tx_ring->next_to_use = 0;
2234 tx_ring->next_to_clean = 0;
2238 vfree(tx_ring->buffer_info);
2239 e_err("Unable to allocate memory for the transmit descriptor ring\n");
2244 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2245 * @rx_ring: Rx descriptor ring
2247 * Returns 0 on success, negative on failure
2249 int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
2251 struct e1000_adapter *adapter = rx_ring->adapter;
2252 struct e1000_buffer *buffer_info;
2253 int i, size, desc_len, err = -ENOMEM;
2255 size = sizeof(struct e1000_buffer) * rx_ring->count;
2256 rx_ring->buffer_info = vzalloc(size);
2257 if (!rx_ring->buffer_info)
2260 for (i = 0; i < rx_ring->count; i++) {
2261 buffer_info = &rx_ring->buffer_info[i];
2262 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2263 sizeof(struct e1000_ps_page),
2265 if (!buffer_info->ps_pages)
2269 desc_len = sizeof(union e1000_rx_desc_packet_split);
2271 /* Round up to nearest 4K */
2272 rx_ring->size = rx_ring->count * desc_len;
2273 rx_ring->size = ALIGN(rx_ring->size, 4096);
2275 err = e1000_alloc_ring_dma(adapter, rx_ring);
2279 rx_ring->next_to_clean = 0;
2280 rx_ring->next_to_use = 0;
2281 rx_ring->rx_skb_top = NULL;
2286 for (i = 0; i < rx_ring->count; i++) {
2287 buffer_info = &rx_ring->buffer_info[i];
2288 kfree(buffer_info->ps_pages);
2291 vfree(rx_ring->buffer_info);
2292 e_err("Unable to allocate memory for the receive descriptor ring\n");
2297 * e1000_clean_tx_ring - Free Tx Buffers
2298 * @tx_ring: Tx descriptor ring
2300 static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
2302 struct e1000_adapter *adapter = tx_ring->adapter;
2303 struct e1000_buffer *buffer_info;
2307 for (i = 0; i < tx_ring->count; i++) {
2308 buffer_info = &tx_ring->buffer_info[i];
2309 e1000_put_txbuf(tx_ring, buffer_info);
2312 netdev_reset_queue(adapter->netdev);
2313 size = sizeof(struct e1000_buffer) * tx_ring->count;
2314 memset(tx_ring->buffer_info, 0, size);
2316 memset(tx_ring->desc, 0, tx_ring->size);
2318 tx_ring->next_to_use = 0;
2319 tx_ring->next_to_clean = 0;
2321 writel(0, tx_ring->head);
2322 writel(0, tx_ring->tail);
2326 * e1000e_free_tx_resources - Free Tx Resources per Queue
2327 * @tx_ring: Tx descriptor ring
2329 * Free all transmit software resources
2331 void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
2333 struct e1000_adapter *adapter = tx_ring->adapter;
2334 struct pci_dev *pdev = adapter->pdev;
2336 e1000_clean_tx_ring(tx_ring);
2338 vfree(tx_ring->buffer_info);
2339 tx_ring->buffer_info = NULL;
2341 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2343 tx_ring->desc = NULL;
2347 * e1000e_free_rx_resources - Free Rx Resources
2348 * @rx_ring: Rx descriptor ring
2350 * Free all receive software resources
2352 void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
2354 struct e1000_adapter *adapter = rx_ring->adapter;
2355 struct pci_dev *pdev = adapter->pdev;
2358 e1000_clean_rx_ring(rx_ring);
2360 for (i = 0; i < rx_ring->count; i++)
2361 kfree(rx_ring->buffer_info[i].ps_pages);
2363 vfree(rx_ring->buffer_info);
2364 rx_ring->buffer_info = NULL;
2366 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2368 rx_ring->desc = NULL;
2372 * e1000_update_itr - update the dynamic ITR value based on statistics
2373 * @adapter: pointer to adapter
2374 * @itr_setting: current adapter->itr
2375 * @packets: the number of packets during this measurement interval
2376 * @bytes: the number of bytes during this measurement interval
2378 * Stores a new ITR value based on packets and byte
2379 * counts during the last interrupt. The advantage of per interrupt
2380 * computation is faster updates and more accurate ITR for the current
2381 * traffic pattern. Constants in this function were computed
2382 * based on theoretical maximum wire speed and thresholds were set based
2383 * on testing data as well as attempting to minimize response time
2384 * while increasing bulk throughput. This functionality is controlled
2385 * by the InterruptThrottleRate module parameter.
2387 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2388 u16 itr_setting, int packets,
2391 unsigned int retval = itr_setting;
2396 switch (itr_setting) {
2397 case lowest_latency:
2398 /* handle TSO and jumbo frames */
2399 if (bytes/packets > 8000)
2400 retval = bulk_latency;
2401 else if ((packets < 5) && (bytes > 512))
2402 retval = low_latency;
2404 case low_latency: /* 50 usec aka 20000 ints/s */
2405 if (bytes > 10000) {
2406 /* this if handles the TSO accounting */
2407 if (bytes/packets > 8000)
2408 retval = bulk_latency;
2409 else if ((packets < 10) || ((bytes/packets) > 1200))
2410 retval = bulk_latency;
2411 else if ((packets > 35))
2412 retval = lowest_latency;
2413 } else if (bytes/packets > 2000) {
2414 retval = bulk_latency;
2415 } else if (packets <= 2 && bytes < 512) {
2416 retval = lowest_latency;
2419 case bulk_latency: /* 250 usec aka 4000 ints/s */
2420 if (bytes > 25000) {
2422 retval = low_latency;
2423 } else if (bytes < 6000) {
2424 retval = low_latency;
2432 static void e1000_set_itr(struct e1000_adapter *adapter)
2434 struct e1000_hw *hw = &adapter->hw;
2436 u32 new_itr = adapter->itr;
2438 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2439 if (adapter->link_speed != SPEED_1000) {
2445 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2450 adapter->tx_itr = e1000_update_itr(adapter,
2452 adapter->total_tx_packets,
2453 adapter->total_tx_bytes);
2454 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2455 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2456 adapter->tx_itr = low_latency;
2458 adapter->rx_itr = e1000_update_itr(adapter,
2460 adapter->total_rx_packets,
2461 adapter->total_rx_bytes);
2462 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2463 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2464 adapter->rx_itr = low_latency;
2466 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2468 switch (current_itr) {
2469 /* counts and packets in update_itr are dependent on these numbers */
2470 case lowest_latency:
2474 new_itr = 20000; /* aka hwitr = ~200 */
2484 if (new_itr != adapter->itr) {
2486 * this attempts to bias the interrupt rate towards Bulk
2487 * by adding intermediate steps when interrupt rate is
2490 new_itr = new_itr > adapter->itr ?
2491 min(adapter->itr + (new_itr >> 2), new_itr) :
2493 adapter->itr = new_itr;
2494 adapter->rx_ring->itr_val = new_itr;
2495 if (adapter->msix_entries)
2496 adapter->rx_ring->set_itr = 1;
2499 ew32(ITR, 1000000000 / (new_itr * 256));
2506 * e1000_alloc_queues - Allocate memory for all rings
2507 * @adapter: board private structure to initialize
2509 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2511 int size = sizeof(struct e1000_ring);
2513 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
2514 if (!adapter->tx_ring)
2516 adapter->tx_ring->count = adapter->tx_ring_count;
2517 adapter->tx_ring->adapter = adapter;
2519 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
2520 if (!adapter->rx_ring)
2522 adapter->rx_ring->count = adapter->rx_ring_count;
2523 adapter->rx_ring->adapter = adapter;
2527 e_err("Unable to allocate memory for queues\n");
2528 kfree(adapter->rx_ring);
2529 kfree(adapter->tx_ring);
2534 * e1000e_poll - NAPI Rx polling callback
2535 * @napi: struct associated with this polling callback
2536 * @weight: number of packets driver is allowed to process this poll
2538 static int e1000e_poll(struct napi_struct *napi, int weight)
2540 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2542 struct e1000_hw *hw = &adapter->hw;
2543 struct net_device *poll_dev = adapter->netdev;
2544 int tx_cleaned = 1, work_done = 0;
2546 adapter = netdev_priv(poll_dev);
2548 if (!adapter->msix_entries ||
2549 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2550 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
2552 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
2557 /* If weight not fully consumed, exit the polling mode */
2558 if (work_done < weight) {
2559 if (adapter->itr_setting & 3)
2560 e1000_set_itr(adapter);
2561 napi_complete(napi);
2562 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2563 if (adapter->msix_entries)
2564 ew32(IMS, adapter->rx_ring->ims_val);
2566 e1000_irq_enable(adapter);
2573 static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2575 struct e1000_adapter *adapter = netdev_priv(netdev);
2576 struct e1000_hw *hw = &adapter->hw;
2579 /* don't update vlan cookie if already programmed */
2580 if ((adapter->hw.mng_cookie.status &
2581 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2582 (vid == adapter->mng_vlan_id))
2585 /* add VID to filter table */
2586 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2587 index = (vid >> 5) & 0x7F;
2588 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2589 vfta |= (1 << (vid & 0x1F));
2590 hw->mac.ops.write_vfta(hw, index, vfta);
2593 set_bit(vid, adapter->active_vlans);
2598 static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2600 struct e1000_adapter *adapter = netdev_priv(netdev);
2601 struct e1000_hw *hw = &adapter->hw;
2604 if ((adapter->hw.mng_cookie.status &
2605 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2606 (vid == adapter->mng_vlan_id)) {
2607 /* release control to f/w */
2608 e1000e_release_hw_control(adapter);
2612 /* remove VID from filter table */
2613 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2614 index = (vid >> 5) & 0x7F;
2615 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2616 vfta &= ~(1 << (vid & 0x1F));
2617 hw->mac.ops.write_vfta(hw, index, vfta);
2620 clear_bit(vid, adapter->active_vlans);
2626 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2627 * @adapter: board private structure to initialize
2629 static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2631 struct net_device *netdev = adapter->netdev;
2632 struct e1000_hw *hw = &adapter->hw;
2635 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2636 /* disable VLAN receive filtering */
2638 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2641 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2642 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2643 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2649 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2650 * @adapter: board private structure to initialize
2652 static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2654 struct e1000_hw *hw = &adapter->hw;
2657 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2658 /* enable VLAN receive filtering */
2660 rctl |= E1000_RCTL_VFE;
2661 rctl &= ~E1000_RCTL_CFIEN;
2667 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2668 * @adapter: board private structure to initialize
2670 static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2672 struct e1000_hw *hw = &adapter->hw;
2675 /* disable VLAN tag insert/strip */
2677 ctrl &= ~E1000_CTRL_VME;
2682 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2683 * @adapter: board private structure to initialize
2685 static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2687 struct e1000_hw *hw = &adapter->hw;
2690 /* enable VLAN tag insert/strip */
2692 ctrl |= E1000_CTRL_VME;
2696 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2698 struct net_device *netdev = adapter->netdev;
2699 u16 vid = adapter->hw.mng_cookie.vlan_id;
2700 u16 old_vid = adapter->mng_vlan_id;
2702 if (adapter->hw.mng_cookie.status &
2703 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2704 e1000_vlan_rx_add_vid(netdev, vid);
2705 adapter->mng_vlan_id = vid;
2708 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2709 e1000_vlan_rx_kill_vid(netdev, old_vid);
2712 static void e1000_restore_vlan(struct e1000_adapter *adapter)
2716 e1000_vlan_rx_add_vid(adapter->netdev, 0);
2718 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
2719 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2722 static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
2724 struct e1000_hw *hw = &adapter->hw;
2725 u32 manc, manc2h, mdef, i, j;
2727 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2733 * enable receiving management packets to the host. this will probably
2734 * generate destination unreachable messages from the host OS, but
2735 * the packets will be handled on SMBUS
2737 manc |= E1000_MANC_EN_MNG2HOST;
2738 manc2h = er32(MANC2H);
2740 switch (hw->mac.type) {
2742 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2747 * Check if IPMI pass-through decision filter already exists;
2750 for (i = 0, j = 0; i < 8; i++) {
2751 mdef = er32(MDEF(i));
2753 /* Ignore filters with anything other than IPMI ports */
2754 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2757 /* Enable this decision filter in MANC2H */
2764 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2767 /* Create new decision filter in an empty filter */
2768 for (i = 0, j = 0; i < 8; i++)
2769 if (er32(MDEF(i)) == 0) {
2770 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2771 E1000_MDEF_PORT_664));
2778 e_warn("Unable to create IPMI pass-through filter\n");
2782 ew32(MANC2H, manc2h);
2787 * e1000_configure_tx - Configure Transmit Unit after Reset
2788 * @adapter: board private structure
2790 * Configure the Tx unit of the MAC after a reset.
2792 static void e1000_configure_tx(struct e1000_adapter *adapter)
2794 struct e1000_hw *hw = &adapter->hw;
2795 struct e1000_ring *tx_ring = adapter->tx_ring;
2799 /* Setup the HW Tx Head and Tail descriptor pointers */
2800 tdba = tx_ring->dma;
2801 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2802 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2803 ew32(TDBAH(0), (tdba >> 32));
2804 ew32(TDLEN(0), tdlen);
2807 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2808 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
2810 /* Set the Tx Interrupt Delay register */
2811 ew32(TIDV, adapter->tx_int_delay);
2812 /* Tx irq moderation */
2813 ew32(TADV, adapter->tx_abs_int_delay);
2815 if (adapter->flags2 & FLAG2_DMA_BURST) {
2816 u32 txdctl = er32(TXDCTL(0));
2817 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2818 E1000_TXDCTL_WTHRESH);
2820 * set up some performance related parameters to encourage the
2821 * hardware to use the bus more efficiently in bursts, depends
2822 * on the tx_int_delay to be enabled,
2823 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2824 * hthresh = 1 ==> prefetch when one or more available
2825 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2826 * BEWARE: this seems to work but should be considered first if
2827 * there are Tx hangs or other Tx related bugs
2829 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2830 ew32(TXDCTL(0), txdctl);
2832 /* erratum work around: set txdctl the same for both queues */
2833 ew32(TXDCTL(1), er32(TXDCTL(0)));
2835 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
2836 tarc = er32(TARC(0));
2838 * set the speed mode bit, we'll clear it if we're not at
2839 * gigabit link later
2841 #define SPEED_MODE_BIT (1 << 21)
2842 tarc |= SPEED_MODE_BIT;
2843 ew32(TARC(0), tarc);
2846 /* errata: program both queues to unweighted RR */
2847 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
2848 tarc = er32(TARC(0));
2850 ew32(TARC(0), tarc);
2851 tarc = er32(TARC(1));
2853 ew32(TARC(1), tarc);
2856 /* Setup Transmit Descriptor Settings for eop descriptor */
2857 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2859 /* only set IDE if we are delaying interrupts using the timers */
2860 if (adapter->tx_int_delay)
2861 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2863 /* enable Report Status bit */
2864 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2866 hw->mac.ops.config_collision_dist(hw);
2870 * e1000_setup_rctl - configure the receive control registers
2871 * @adapter: Board private structure
2873 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2874 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2875 static void e1000_setup_rctl(struct e1000_adapter *adapter)
2877 struct e1000_hw *hw = &adapter->hw;
2881 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2882 if (hw->mac.type == e1000_pch2lan) {
2885 if (adapter->netdev->mtu > ETH_DATA_LEN)
2886 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2888 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
2891 e_dbg("failed to enable jumbo frame workaround mode\n");
2894 /* Program MC offset vector base */
2896 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2897 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2898 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2899 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2901 /* Do not Store bad packets */
2902 rctl &= ~E1000_RCTL_SBP;
2904 /* Enable Long Packet receive */
2905 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2906 rctl &= ~E1000_RCTL_LPE;
2908 rctl |= E1000_RCTL_LPE;
2910 /* Some systems expect that the CRC is included in SMBUS traffic. The
2911 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2912 * host memory when this is enabled
2914 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2915 rctl |= E1000_RCTL_SECRC;
2917 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2918 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2921 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2923 phy_data |= (1 << 2);
2924 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2926 e1e_rphy(hw, 22, &phy_data);
2928 phy_data |= (1 << 14);
2929 e1e_wphy(hw, 0x10, 0x2823);
2930 e1e_wphy(hw, 0x11, 0x0003);
2931 e1e_wphy(hw, 22, phy_data);
2934 /* Setup buffer sizes */
2935 rctl &= ~E1000_RCTL_SZ_4096;
2936 rctl |= E1000_RCTL_BSEX;
2937 switch (adapter->rx_buffer_len) {
2940 rctl |= E1000_RCTL_SZ_2048;
2941 rctl &= ~E1000_RCTL_BSEX;
2944 rctl |= E1000_RCTL_SZ_4096;
2947 rctl |= E1000_RCTL_SZ_8192;
2950 rctl |= E1000_RCTL_SZ_16384;
2954 /* Enable Extended Status in all Receive Descriptors */
2955 rfctl = er32(RFCTL);
2956 rfctl |= E1000_RFCTL_EXTEN;
2959 * 82571 and greater support packet-split where the protocol
2960 * header is placed in skb->data and the packet data is
2961 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2962 * In the case of a non-split, skb->data is linearly filled,
2963 * followed by the page buffers. Therefore, skb->data is
2964 * sized to hold the largest protocol header.
2966 * allocations using alloc_page take too long for regular MTU
2967 * so only enable packet split for jumbo frames
2969 * Using pages when the page size is greater than 16k wastes
2970 * a lot of memory, since we allocate 3 pages at all times
2973 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2974 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
2975 adapter->rx_ps_pages = pages;
2977 adapter->rx_ps_pages = 0;
2979 if (adapter->rx_ps_pages) {
2983 * disable packet split support for IPv6 extension headers,
2984 * because some malformed IPv6 headers can hang the Rx
2986 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2987 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2989 /* Enable Packet split descriptors */
2990 rctl |= E1000_RCTL_DTYP_PS;
2992 psrctl |= adapter->rx_ps_bsize0 >>
2993 E1000_PSRCTL_BSIZE0_SHIFT;
2995 switch (adapter->rx_ps_pages) {
2997 psrctl |= PAGE_SIZE <<
2998 E1000_PSRCTL_BSIZE3_SHIFT;
3000 psrctl |= PAGE_SIZE <<
3001 E1000_PSRCTL_BSIZE2_SHIFT;
3003 psrctl |= PAGE_SIZE >>
3004 E1000_PSRCTL_BSIZE1_SHIFT;
3008 ew32(PSRCTL, psrctl);
3011 /* This is useful for sniffing bad packets. */
3012 if (adapter->netdev->features & NETIF_F_RXALL) {
3013 /* UPE and MPE will be handled by normal PROMISC logic
3014 * in e1000e_set_rx_mode */
3015 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3016 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3017 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3019 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3020 E1000_RCTL_DPF | /* Allow filtered pause */
3021 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3022 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3023 * and that breaks VLANs.
3029 /* just started the receive unit, no need to restart */
3030 adapter->flags &= ~FLAG_RX_RESTART_NOW;
3034 * e1000_configure_rx - Configure Receive Unit after Reset
3035 * @adapter: board private structure
3037 * Configure the Rx unit of the MAC after a reset.
3039 static void e1000_configure_rx(struct e1000_adapter *adapter)
3041 struct e1000_hw *hw = &adapter->hw;
3042 struct e1000_ring *rx_ring = adapter->rx_ring;
3044 u32 rdlen, rctl, rxcsum, ctrl_ext;
3046 if (adapter->rx_ps_pages) {
3047 /* this is a 32 byte descriptor */
3048 rdlen = rx_ring->count *
3049 sizeof(union e1000_rx_desc_packet_split);
3050 adapter->clean_rx = e1000_clean_rx_irq_ps;
3051 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
3052 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
3053 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3054 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3055 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
3057 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3058 adapter->clean_rx = e1000_clean_rx_irq;
3059 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3062 /* disable receives while setting up the descriptors */
3064 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3065 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3067 usleep_range(10000, 20000);
3069 if (adapter->flags2 & FLAG2_DMA_BURST) {
3071 * set the writeback threshold (only takes effect if the RDTR
3072 * is set). set GRAN=1 and write back up to 0x4 worth, and
3073 * enable prefetching of 0x20 Rx descriptors
3079 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3080 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3083 * override the delay timers for enabling bursting, only if
3084 * the value was not set by the user via module options
3086 if (adapter->rx_int_delay == DEFAULT_RDTR)
3087 adapter->rx_int_delay = BURST_RDTR;
3088 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3089 adapter->rx_abs_int_delay = BURST_RADV;
3092 /* set the Receive Delay Timer Register */
3093 ew32(RDTR, adapter->rx_int_delay);
3095 /* irq moderation */
3096 ew32(RADV, adapter->rx_abs_int_delay);
3097 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
3098 ew32(ITR, 1000000000 / (adapter->itr * 256));
3100 ctrl_ext = er32(CTRL_EXT);
3101 /* Auto-Mask interrupts upon ICR access */
3102 ctrl_ext |= E1000_CTRL_EXT_IAME;
3103 ew32(IAM, 0xffffffff);
3104 ew32(CTRL_EXT, ctrl_ext);
3108 * Setup the HW Rx Head and Tail Descriptor Pointers and
3109 * the Base and Length of the Rx Descriptor Ring
3111 rdba = rx_ring->dma;
3112 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3113 ew32(RDBAH(0), (rdba >> 32));
3114 ew32(RDLEN(0), rdlen);
3117 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3118 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
3120 /* Enable Receive Checksum Offload for TCP and UDP */
3121 rxcsum = er32(RXCSUM);
3122 if (adapter->netdev->features & NETIF_F_RXCSUM) {
3123 rxcsum |= E1000_RXCSUM_TUOFL;
3126 * IPv4 payload checksum for UDP fragments must be
3127 * used in conjunction with packet-split.
3129 if (adapter->rx_ps_pages)
3130 rxcsum |= E1000_RXCSUM_IPPCSE;
3132 rxcsum &= ~E1000_RXCSUM_TUOFL;
3133 /* no need to clear IPPCSE as it defaults to 0 */
3135 ew32(RXCSUM, rxcsum);
3137 if (adapter->hw.mac.type == e1000_pch2lan) {
3139 * With jumbo frames, excessive C-state transition
3140 * latencies result in dropped transactions.
3142 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3143 u32 rxdctl = er32(RXDCTL(0));
3144 ew32(RXDCTL(0), rxdctl | 0x3);
3145 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
3147 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3148 PM_QOS_DEFAULT_VALUE);
3152 /* Enable Receives */
3157 * e1000e_write_mc_addr_list - write multicast addresses to MTA
3158 * @netdev: network interface device structure
3160 * Writes multicast address list to the MTA hash table.
3161 * Returns: -ENOMEM on failure
3162 * 0 on no addresses written
3163 * X on writing X addresses to MTA
3165 static int e1000e_write_mc_addr_list(struct net_device *netdev)
3167 struct e1000_adapter *adapter = netdev_priv(netdev);
3168 struct e1000_hw *hw = &adapter->hw;
3169 struct netdev_hw_addr *ha;
3173 if (netdev_mc_empty(netdev)) {
3174 /* nothing to program, so clear mc list */
3175 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3179 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3183 /* update_mc_addr_list expects a packed array of only addresses. */
3185 netdev_for_each_mc_addr(ha, netdev)
3186 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3188 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3191 return netdev_mc_count(netdev);
3195 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3196 * @netdev: network interface device structure
3198 * Writes unicast address list to the RAR table.
3199 * Returns: -ENOMEM on failure/insufficient address space
3200 * 0 on no addresses written
3201 * X on writing X addresses to the RAR table
3203 static int e1000e_write_uc_addr_list(struct net_device *netdev)
3205 struct e1000_adapter *adapter = netdev_priv(netdev);
3206 struct e1000_hw *hw = &adapter->hw;
3207 unsigned int rar_entries = hw->mac.rar_entry_count;
3210 /* save a rar entry for our hardware address */
3213 /* save a rar entry for the LAA workaround */
3214 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3217 /* return ENOMEM indicating insufficient memory for addresses */
3218 if (netdev_uc_count(netdev) > rar_entries)
3221 if (!netdev_uc_empty(netdev) && rar_entries) {
3222 struct netdev_hw_addr *ha;
3225 * write the addresses in reverse order to avoid write
3228 netdev_for_each_uc_addr(ha, netdev) {
3231 e1000e_rar_set(hw, ha->addr, rar_entries--);
3236 /* zero out the remaining RAR entries not used above */
3237 for (; rar_entries > 0; rar_entries--) {
3238 ew32(RAH(rar_entries), 0);
3239 ew32(RAL(rar_entries), 0);
3247 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3248 * @netdev: network interface device structure
3250 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3251 * address list or the network interface flags are updated. This routine is
3252 * responsible for configuring the hardware for proper unicast, multicast,
3253 * promiscuous mode, and all-multi behavior.
3255 static void e1000e_set_rx_mode(struct net_device *netdev)
3257 struct e1000_adapter *adapter = netdev_priv(netdev);
3258 struct e1000_hw *hw = &adapter->hw;
3261 /* Check for Promiscuous and All Multicast modes */
3264 /* clear the affected bits */
3265 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3267 if (netdev->flags & IFF_PROMISC) {
3268 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
3269 /* Do not hardware filter VLANs in promisc mode */
3270 e1000e_vlan_filter_disable(adapter);
3274 if (netdev->flags & IFF_ALLMULTI) {
3275 rctl |= E1000_RCTL_MPE;
3278 * Write addresses to the MTA, if the attempt fails
3279 * then we should just turn on promiscuous mode so
3280 * that we can at least receive multicast traffic
3282 count = e1000e_write_mc_addr_list(netdev);
3284 rctl |= E1000_RCTL_MPE;
3286 e1000e_vlan_filter_enable(adapter);
3288 * Write addresses to available RAR registers, if there is not
3289 * sufficient space to store all the addresses then enable
3290 * unicast promiscuous mode
3292 count = e1000e_write_uc_addr_list(netdev);
3294 rctl |= E1000_RCTL_UPE;
3299 if (netdev->features & NETIF_F_HW_VLAN_RX)
3300 e1000e_vlan_strip_enable(adapter);
3302 e1000e_vlan_strip_disable(adapter);
3305 static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3307 struct e1000_hw *hw = &adapter->hw;
3310 static const u32 rsskey[10] = {
3311 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3312 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3315 /* Fill out hash function seed */
3316 for (i = 0; i < 10; i++)
3317 ew32(RSSRK(i), rsskey[i]);
3319 /* Direct all traffic to queue 0 */
3320 for (i = 0; i < 32; i++)
3324 * Disable raw packet checksumming so that RSS hash is placed in
3325 * descriptor on writeback.
3327 rxcsum = er32(RXCSUM);
3328 rxcsum |= E1000_RXCSUM_PCSD;
3330 ew32(RXCSUM, rxcsum);
3332 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3333 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3334 E1000_MRQC_RSS_FIELD_IPV6 |
3335 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3336 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3342 * e1000_configure - configure the hardware for Rx and Tx
3343 * @adapter: private board structure
3345 static void e1000_configure(struct e1000_adapter *adapter)
3347 struct e1000_ring *rx_ring = adapter->rx_ring;
3349 e1000e_set_rx_mode(adapter->netdev);
3351 e1000_restore_vlan(adapter);
3352 e1000_init_manageability_pt(adapter);
3354 e1000_configure_tx(adapter);
3356 if (adapter->netdev->features & NETIF_F_RXHASH)
3357 e1000e_setup_rss_hash(adapter);
3358 e1000_setup_rctl(adapter);
3359 e1000_configure_rx(adapter);
3360 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
3364 * e1000e_power_up_phy - restore link in case the phy was powered down
3365 * @adapter: address of board private structure
3367 * The phy may be powered down to save power and turn off link when the
3368 * driver is unloaded and wake on lan is not enabled (among others)
3369 * *** this routine MUST be followed by a call to e1000e_reset ***
3371 void e1000e_power_up_phy(struct e1000_adapter *adapter)
3373 if (adapter->hw.phy.ops.power_up)
3374 adapter->hw.phy.ops.power_up(&adapter->hw);
3376 adapter->hw.mac.ops.setup_link(&adapter->hw);
3380 * e1000_power_down_phy - Power down the PHY
3382 * Power down the PHY so no link is implied when interface is down.
3383 * The PHY cannot be powered down if management or WoL is active.
3385 static void e1000_power_down_phy(struct e1000_adapter *adapter)
3387 /* WoL is enabled */
3391 if (adapter->hw.phy.ops.power_down)
3392 adapter->hw.phy.ops.power_down(&adapter->hw);
3396 * e1000e_reset - bring the hardware into a known good state
3398 * This function boots the hardware and enables some settings that
3399 * require a configuration cycle of the hardware - those cannot be
3400 * set/changed during runtime. After reset the device needs to be
3401 * properly configured for Rx, Tx etc.
3403 void e1000e_reset(struct e1000_adapter *adapter)
3405 struct e1000_mac_info *mac = &adapter->hw.mac;
3406 struct e1000_fc_info *fc = &adapter->hw.fc;
3407 struct e1000_hw *hw = &adapter->hw;
3408 u32 tx_space, min_tx_space, min_rx_space;
3409 u32 pba = adapter->pba;
3412 /* reset Packet Buffer Allocation to default */
3415 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
3417 * To maintain wire speed transmits, the Tx FIFO should be
3418 * large enough to accommodate two full transmit packets,
3419 * rounded up to the next 1KB and expressed in KB. Likewise,
3420 * the Rx FIFO should be large enough to accommodate at least
3421 * one full receive packet and is similarly rounded up and
3425 /* upper 16 bits has Tx packet buffer allocation size in KB */
3426 tx_space = pba >> 16;
3427 /* lower 16 bits has Rx packet buffer allocation size in KB */
3430 * the Tx fifo also stores 16 bytes of information about the Tx
3431 * but don't include ethernet FCS because hardware appends it
3433 min_tx_space = (adapter->max_frame_size +
3434 sizeof(struct e1000_tx_desc) -
3436 min_tx_space = ALIGN(min_tx_space, 1024);
3437 min_tx_space >>= 10;
3438 /* software strips receive CRC, so leave room for it */
3439 min_rx_space = adapter->max_frame_size;
3440 min_rx_space = ALIGN(min_rx_space, 1024);
3441 min_rx_space >>= 10;
3444 * If current Tx allocation is less than the min Tx FIFO size,
3445 * and the min Tx FIFO size is less than the current Rx FIFO
3446 * allocation, take space away from current Rx allocation
3448 if ((tx_space < min_tx_space) &&
3449 ((min_tx_space - tx_space) < pba)) {
3450 pba -= min_tx_space - tx_space;
3453 * if short on Rx space, Rx wins and must trump Tx
3454 * adjustment or use Early Receive if available
3456 if (pba < min_rx_space)
3464 * flow control settings
3466 * The high water mark must be low enough to fit one full frame
3467 * (or the size used for early receive) above it in the Rx FIFO.
3468 * Set it to the lower of:
3469 * - 90% of the Rx FIFO size, and
3470 * - the full Rx FIFO size minus one full frame
3472 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3473 fc->pause_time = 0xFFFF;
3475 fc->pause_time = E1000_FC_PAUSE_TIME;
3476 fc->send_xon = true;
3477 fc->current_mode = fc->requested_mode;
3479 switch (hw->mac.type) {
3481 case e1000_ich10lan:
3482 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3485 fc->high_water = 0x2800;
3486 fc->low_water = fc->high_water - 8;
3491 hwm = min(((pba << 10) * 9 / 10),
3492 ((pba << 10) - adapter->max_frame_size));
3494 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3495 fc->low_water = fc->high_water - 8;
3499 * Workaround PCH LOM adapter hangs with certain network
3500 * loads. If hangs persist, try disabling Tx flow control.
3502 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3503 fc->high_water = 0x3500;
3504 fc->low_water = 0x1500;
3506 fc->high_water = 0x5000;
3507 fc->low_water = 0x3000;
3509 fc->refresh_time = 0x1000;
3512 fc->high_water = 0x05C20;
3513 fc->low_water = 0x05048;
3514 fc->pause_time = 0x0650;
3515 fc->refresh_time = 0x0400;
3516 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3524 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3525 * fit in receive buffer.
3527 if (adapter->itr_setting & 0x3) {
3528 if ((adapter->max_frame_size * 2) > (pba << 10)) {
3529 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3530 dev_info(&adapter->pdev->dev,
3531 "Interrupt Throttle Rate turned off\n");
3532 adapter->flags2 |= FLAG2_DISABLE_AIM;
3535 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3536 dev_info(&adapter->pdev->dev,
3537 "Interrupt Throttle Rate turned on\n");
3538 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3539 adapter->itr = 20000;
3540 ew32(ITR, 1000000000 / (adapter->itr * 256));
3544 /* Allow time for pending master requests to run */
3545 mac->ops.reset_hw(hw);
3548 * For parts with AMT enabled, let the firmware know
3549 * that the network interface is in control
3551 if (adapter->flags & FLAG_HAS_AMT)
3552 e1000e_get_hw_control(adapter);
3556 if (mac->ops.init_hw(hw))
3557 e_err("Hardware Error\n");
3559 e1000_update_mng_vlan(adapter);
3561 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3562 ew32(VET, ETH_P_8021Q);
3564 e1000e_reset_adaptive(hw);
3566 if (!netif_running(adapter->netdev) &&
3567 !test_bit(__E1000_TESTING, &adapter->state)) {
3568 e1000_power_down_phy(adapter);
3572 e1000_get_phy_info(hw);
3574 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3575 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
3578 * speed up time to link by disabling smart power down, ignore
3579 * the return value of this function because there is nothing
3580 * different we would do if it failed
3582 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3583 phy_data &= ~IGP02E1000_PM_SPD;
3584 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3588 int e1000e_up(struct e1000_adapter *adapter)
3590 struct e1000_hw *hw = &adapter->hw;
3592 /* hardware has been reset, we need to reload some things */
3593 e1000_configure(adapter);
3595 clear_bit(__E1000_DOWN, &adapter->state);
3597 if (adapter->msix_entries)
3598 e1000_configure_msix(adapter);
3599 e1000_irq_enable(adapter);
3601 netif_start_queue(adapter->netdev);
3603 /* fire a link change interrupt to start the watchdog */
3604 if (adapter->msix_entries)
3605 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3607 ew32(ICS, E1000_ICS_LSC);
3612 static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3614 struct e1000_hw *hw = &adapter->hw;
3616 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3619 /* flush pending descriptor writebacks to memory */
3620 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3621 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3623 /* execute the writes immediately */
3627 * due to rare timing issues, write to TIDV/RDTR again to ensure the
3628 * write is successful
3630 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3631 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3633 /* execute the writes immediately */
3637 static void e1000e_update_stats(struct e1000_adapter *adapter);
3639 void e1000e_down(struct e1000_adapter *adapter)
3641 struct net_device *netdev = adapter->netdev;
3642 struct e1000_hw *hw = &adapter->hw;
3646 * signal that we're down so the interrupt handler does not
3647 * reschedule our watchdog timer
3649 set_bit(__E1000_DOWN, &adapter->state);
3651 /* disable receives in the hardware */
3653 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3654 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3655 /* flush and sleep below */
3657 netif_stop_queue(netdev);
3659 /* disable transmits in the hardware */
3661 tctl &= ~E1000_TCTL_EN;
3664 /* flush both disables and wait for them to finish */
3666 usleep_range(10000, 20000);
3668 e1000_irq_disable(adapter);
3670 del_timer_sync(&adapter->watchdog_timer);
3671 del_timer_sync(&adapter->phy_info_timer);
3673 netif_carrier_off(netdev);
3675 spin_lock(&adapter->stats64_lock);
3676 e1000e_update_stats(adapter);
3677 spin_unlock(&adapter->stats64_lock);
3679 e1000e_flush_descriptors(adapter);
3680 e1000_clean_tx_ring(adapter->tx_ring);
3681 e1000_clean_rx_ring(adapter->rx_ring);
3683 adapter->link_speed = 0;
3684 adapter->link_duplex = 0;
3686 if (!pci_channel_offline(adapter->pdev))
3687 e1000e_reset(adapter);
3690 * TODO: for power management, we could drop the link and
3691 * pci_disable_device here.
3695 void e1000e_reinit_locked(struct e1000_adapter *adapter)
3698 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3699 usleep_range(1000, 2000);
3700 e1000e_down(adapter);
3702 clear_bit(__E1000_RESETTING, &adapter->state);
3706 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3707 * @adapter: board private structure to initialize
3709 * e1000_sw_init initializes the Adapter private data structure.
3710 * Fields are initialized based on PCI device information and
3711 * OS network device settings (MTU size).
3713 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3715 struct net_device *netdev = adapter->netdev;
3717 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3718 adapter->rx_ps_bsize0 = 128;
3719 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3720 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
3721 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3722 adapter->rx_ring_count = E1000_DEFAULT_RXD;
3724 spin_lock_init(&adapter->stats64_lock);
3726 e1000e_set_interrupt_capability(adapter);
3728 if (e1000_alloc_queues(adapter))
3731 /* Explicitly disable IRQ since the NIC can be in any state. */
3732 e1000_irq_disable(adapter);
3734 set_bit(__E1000_DOWN, &adapter->state);
3739 * e1000_intr_msi_test - Interrupt Handler
3740 * @irq: interrupt number
3741 * @data: pointer to a network interface device structure
3743 static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3745 struct net_device *netdev = data;
3746 struct e1000_adapter *adapter = netdev_priv(netdev);
3747 struct e1000_hw *hw = &adapter->hw;
3748 u32 icr = er32(ICR);
3750 e_dbg("icr is %08X\n", icr);
3751 if (icr & E1000_ICR_RXSEQ) {
3752 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3760 * e1000_test_msi_interrupt - Returns 0 for successful test
3761 * @adapter: board private struct
3763 * code flow taken from tg3.c
3765 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3767 struct net_device *netdev = adapter->netdev;
3768 struct e1000_hw *hw = &adapter->hw;
3771 /* poll_enable hasn't been called yet, so don't need disable */
3772 /* clear any pending events */
3775 /* free the real vector and request a test handler */
3776 e1000_free_irq(adapter);
3777 e1000e_reset_interrupt_capability(adapter);
3779 /* Assume that the test fails, if it succeeds then the test
3780 * MSI irq handler will unset this flag */
3781 adapter->flags |= FLAG_MSI_TEST_FAILED;
3783 err = pci_enable_msi(adapter->pdev);
3785 goto msi_test_failed;
3787 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
3788 netdev->name, netdev);
3790 pci_disable_msi(adapter->pdev);
3791 goto msi_test_failed;
3796 e1000_irq_enable(adapter);
3798 /* fire an unusual interrupt on the test handler */
3799 ew32(ICS, E1000_ICS_RXSEQ);
3803 e1000_irq_disable(adapter);
3807 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
3808 adapter->int_mode = E1000E_INT_MODE_LEGACY;
3809 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3811 e_dbg("MSI interrupt test succeeded!\n");
3814 free_irq(adapter->pdev->irq, netdev);
3815 pci_disable_msi(adapter->pdev);
3818 e1000e_set_interrupt_capability(adapter);
3819 return e1000_request_irq(adapter);
3823 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3824 * @adapter: board private struct
3826 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3828 static int e1000_test_msi(struct e1000_adapter *adapter)
3833 if (!(adapter->flags & FLAG_MSI_ENABLED))
3836 /* disable SERR in case the MSI write causes a master abort */
3837 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3838 if (pci_cmd & PCI_COMMAND_SERR)
3839 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3840 pci_cmd & ~PCI_COMMAND_SERR);
3842 err = e1000_test_msi_interrupt(adapter);
3844 /* re-enable SERR */
3845 if (pci_cmd & PCI_COMMAND_SERR) {
3846 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3847 pci_cmd |= PCI_COMMAND_SERR;
3848 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3855 * e1000_open - Called when a network interface is made active
3856 * @netdev: network interface device structure
3858 * Returns 0 on success, negative value on failure
3860 * The open entry point is called when a network interface is made
3861 * active by the system (IFF_UP). At this point all resources needed
3862 * for transmit and receive operations are allocated, the interrupt
3863 * handler is registered with the OS, the watchdog timer is started,
3864 * and the stack is notified that the interface is ready.
3866 static int e1000_open(struct net_device *netdev)
3868 struct e1000_adapter *adapter = netdev_priv(netdev);
3869 struct e1000_hw *hw = &adapter->hw;
3870 struct pci_dev *pdev = adapter->pdev;
3873 /* disallow open during test */
3874 if (test_bit(__E1000_TESTING, &adapter->state))
3877 pm_runtime_get_sync(&pdev->dev);
3879 netif_carrier_off(netdev);
3881 /* allocate transmit descriptors */
3882 err = e1000e_setup_tx_resources(adapter->tx_ring);
3886 /* allocate receive descriptors */
3887 err = e1000e_setup_rx_resources(adapter->rx_ring);
3892 * If AMT is enabled, let the firmware know that the network
3893 * interface is now open and reset the part to a known state.
3895 if (adapter->flags & FLAG_HAS_AMT) {
3896 e1000e_get_hw_control(adapter);
3897 e1000e_reset(adapter);
3900 e1000e_power_up_phy(adapter);
3902 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3903 if ((adapter->hw.mng_cookie.status &
3904 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3905 e1000_update_mng_vlan(adapter);
3907 /* DMA latency requirement to workaround jumbo issue */
3908 if (adapter->hw.mac.type == e1000_pch2lan)
3909 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3910 PM_QOS_CPU_DMA_LATENCY,
3911 PM_QOS_DEFAULT_VALUE);
3914 * before we allocate an interrupt, we must be ready to handle it.
3915 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3916 * as soon as we call pci_request_irq, so we have to setup our
3917 * clean_rx handler before we do so.
3919 e1000_configure(adapter);
3921 err = e1000_request_irq(adapter);
3926 * Work around PCIe errata with MSI interrupts causing some chipsets to
3927 * ignore e1000e MSI messages, which means we need to test our MSI
3930 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
3931 err = e1000_test_msi(adapter);
3933 e_err("Interrupt allocation failed\n");
3938 /* From here on the code is the same as e1000e_up() */
3939 clear_bit(__E1000_DOWN, &adapter->state);
3941 napi_enable(&adapter->napi);
3943 e1000_irq_enable(adapter);
3945 adapter->tx_hang_recheck = false;
3946 netif_start_queue(netdev);
3948 adapter->idle_check = true;
3949 pm_runtime_put(&pdev->dev);
3951 /* fire a link status change interrupt to start the watchdog */
3952 if (adapter->msix_entries)
3953 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3955 ew32(ICS, E1000_ICS_LSC);
3960 e1000e_release_hw_control(adapter);
3961 e1000_power_down_phy(adapter);
3962 e1000e_free_rx_resources(adapter->rx_ring);
3964 e1000e_free_tx_resources(adapter->tx_ring);
3966 e1000e_reset(adapter);
3967 pm_runtime_put_sync(&pdev->dev);
3973 * e1000_close - Disables a network interface
3974 * @netdev: network interface device structure
3976 * Returns 0, this is not allowed to fail
3978 * The close entry point is called when an interface is de-activated
3979 * by the OS. The hardware is still under the drivers control, but
3980 * needs to be disabled. A global MAC reset is issued to stop the
3981 * hardware, and all transmit and receive resources are freed.
3983 static int e1000_close(struct net_device *netdev)
3985 struct e1000_adapter *adapter = netdev_priv(netdev);
3986 struct pci_dev *pdev = adapter->pdev;
3987 int count = E1000_CHECK_RESET_COUNT;
3989 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
3990 usleep_range(10000, 20000);
3992 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3994 pm_runtime_get_sync(&pdev->dev);
3996 napi_disable(&adapter->napi);
3998 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3999 e1000e_down(adapter);
4000 e1000_free_irq(adapter);
4002 e1000_power_down_phy(adapter);
4004 e1000e_free_tx_resources(adapter->tx_ring);
4005 e1000e_free_rx_resources(adapter->rx_ring);
4008 * kill manageability vlan ID if supported, but not if a vlan with
4009 * the same ID is registered on the host OS (let 8021q kill it)
4011 if (adapter->hw.mng_cookie.status &
4012 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
4013 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4016 * If AMT is enabled, let the firmware know that the network
4017 * interface is now closed
4019 if ((adapter->flags & FLAG_HAS_AMT) &&
4020 !test_bit(__E1000_TESTING, &adapter->state))
4021 e1000e_release_hw_control(adapter);
4023 if (adapter->hw.mac.type == e1000_pch2lan)
4024 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
4026 pm_runtime_put_sync(&pdev->dev);
4031 * e1000_set_mac - Change the Ethernet Address of the NIC
4032 * @netdev: network interface device structure
4033 * @p: pointer to an address structure
4035 * Returns 0 on success, negative on failure
4037 static int e1000_set_mac(struct net_device *netdev, void *p)
4039 struct e1000_adapter *adapter = netdev_priv(netdev);
4040 struct sockaddr *addr = p;
4042 if (!is_valid_ether_addr(addr->sa_data))
4043 return -EADDRNOTAVAIL;
4045 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4046 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4048 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
4050 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4051 /* activate the work around */
4052 e1000e_set_laa_state_82571(&adapter->hw, 1);
4055 * Hold a copy of the LAA in RAR[14] This is done so that
4056 * between the time RAR[0] gets clobbered and the time it
4057 * gets fixed (in e1000_watchdog), the actual LAA is in one
4058 * of the RARs and no incoming packets directed to this port
4059 * are dropped. Eventually the LAA will be in RAR[0] and
4062 e1000e_rar_set(&adapter->hw,
4063 adapter->hw.mac.addr,
4064 adapter->hw.mac.rar_entry_count - 1);
4071 * e1000e_update_phy_task - work thread to update phy
4072 * @work: pointer to our work struct
4074 * this worker thread exists because we must acquire a
4075 * semaphore to read the phy, which we could msleep while
4076 * waiting for it, and we can't msleep in a timer.
4078 static void e1000e_update_phy_task(struct work_struct *work)
4080 struct e1000_adapter *adapter = container_of(work,
4081 struct e1000_adapter, update_phy_task);
4083 if (test_bit(__E1000_DOWN, &adapter->state))
4086 e1000_get_phy_info(&adapter->hw);
4090 * Need to wait a few seconds after link up to get diagnostic information from
4093 static void e1000_update_phy_info(unsigned long data)
4095 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4097 if (test_bit(__E1000_DOWN, &adapter->state))
4100 schedule_work(&adapter->update_phy_task);
4104 * e1000e_update_phy_stats - Update the PHY statistics counters
4105 * @adapter: board private structure
4107 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
4109 static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4111 struct e1000_hw *hw = &adapter->hw;
4115 ret_val = hw->phy.ops.acquire(hw);
4120 * A page set is expensive so check if already on desired page.
4121 * If not, set to the page with the PHY status registers.
4124 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4128 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4129 ret_val = hw->phy.ops.set_page(hw,
4130 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4135 /* Single Collision Count */
4136 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4137 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4139 adapter->stats.scc += phy_data;
4141 /* Excessive Collision Count */
4142 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4143 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4145 adapter->stats.ecol += phy_data;
4147 /* Multiple Collision Count */
4148 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4149 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4151 adapter->stats.mcc += phy_data;
4153 /* Late Collision Count */
4154 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4155 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4157 adapter->stats.latecol += phy_data;
4159 /* Collision Count - also used for adaptive IFS */
4160 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4161 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4163 hw->mac.collision_delta = phy_data;
4166 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4167 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4169 adapter->stats.dc += phy_data;
4171 /* Transmit with no CRS */
4172 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4173 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4175 adapter->stats.tncrs += phy_data;
4178 hw->phy.ops.release(hw);
4182 * e1000e_update_stats - Update the board statistics counters
4183 * @adapter: board private structure
4185 static void e1000e_update_stats(struct e1000_adapter *adapter)
4187 struct net_device *netdev = adapter->netdev;
4188 struct e1000_hw *hw = &adapter->hw;
4189 struct pci_dev *pdev = adapter->pdev;
4192 * Prevent stats update while adapter is being reset, or if the pci
4193 * connection is down.
4195 if (adapter->link_speed == 0)
4197 if (pci_channel_offline(pdev))
4200 adapter->stats.crcerrs += er32(CRCERRS);
4201 adapter->stats.gprc += er32(GPRC);
4202 adapter->stats.gorc += er32(GORCL);
4203 er32(GORCH); /* Clear gorc */
4204 adapter->stats.bprc += er32(BPRC);
4205 adapter->stats.mprc += er32(MPRC);
4206 adapter->stats.roc += er32(ROC);
4208 adapter->stats.mpc += er32(MPC);
4210 /* Half-duplex statistics */
4211 if (adapter->link_duplex == HALF_DUPLEX) {
4212 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4213 e1000e_update_phy_stats(adapter);
4215 adapter->stats.scc += er32(SCC);
4216 adapter->stats.ecol += er32(ECOL);
4217 adapter->stats.mcc += er32(MCC);
4218 adapter->stats.latecol += er32(LATECOL);
4219 adapter->stats.dc += er32(DC);
4221 hw->mac.collision_delta = er32(COLC);
4223 if ((hw->mac.type != e1000_82574) &&
4224 (hw->mac.type != e1000_82583))
4225 adapter->stats.tncrs += er32(TNCRS);
4227 adapter->stats.colc += hw->mac.collision_delta;
4230 adapter->stats.xonrxc += er32(XONRXC);
4231 adapter->stats.xontxc += er32(XONTXC);
4232 adapter->stats.xoffrxc += er32(XOFFRXC);
4233 adapter->stats.xofftxc += er32(XOFFTXC);
4234 adapter->stats.gptc += er32(GPTC);
4235 adapter->stats.gotc += er32(GOTCL);
4236 er32(GOTCH); /* Clear gotc */
4237 adapter->stats.rnbc += er32(RNBC);
4238 adapter->stats.ruc += er32(RUC);
4240 adapter->stats.mptc += er32(MPTC);
4241 adapter->stats.bptc += er32(BPTC);
4243 /* used for adaptive IFS */
4245 hw->mac.tx_packet_delta = er32(TPT);
4246 adapter->stats.tpt += hw->mac.tx_packet_delta;
4248 adapter->stats.algnerrc += er32(ALGNERRC);
4249 adapter->stats.rxerrc += er32(RXERRC);
4250 adapter->stats.cexterr += er32(CEXTERR);
4251 adapter->stats.tsctc += er32(TSCTC);
4252 adapter->stats.tsctfc += er32(TSCTFC);
4254 /* Fill out the OS statistics structure */
4255 netdev->stats.multicast = adapter->stats.mprc;
4256 netdev->stats.collisions = adapter->stats.colc;
4261 * RLEC on some newer hardware can be incorrect so build
4262 * our own version based on RUC and ROC
4264 netdev->stats.rx_errors = adapter->stats.rxerrc +
4265 adapter->stats.crcerrs + adapter->stats.algnerrc +
4266 adapter->stats.ruc + adapter->stats.roc +
4267 adapter->stats.cexterr;
4268 netdev->stats.rx_length_errors = adapter->stats.ruc +
4270 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4271 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4272 netdev->stats.rx_missed_errors = adapter->stats.mpc;
4275 netdev->stats.tx_errors = adapter->stats.ecol +
4276 adapter->stats.latecol;
4277 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4278 netdev->stats.tx_window_errors = adapter->stats.latecol;
4279 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
4281 /* Tx Dropped needs to be maintained elsewhere */
4283 /* Management Stats */
4284 adapter->stats.mgptc += er32(MGTPTC);
4285 adapter->stats.mgprc += er32(MGTPRC);
4286 adapter->stats.mgpdc += er32(MGTPDC);
4290 * e1000_phy_read_status - Update the PHY register status snapshot
4291 * @adapter: board private structure
4293 static void e1000_phy_read_status(struct e1000_adapter *adapter)
4295 struct e1000_hw *hw = &adapter->hw;
4296 struct e1000_phy_regs *phy = &adapter->phy_regs;
4298 if ((er32(STATUS) & E1000_STATUS_LU) &&
4299 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
4302 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4303 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4304 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4305 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4306 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4307 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4308 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4309 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4311 e_warn("Error reading PHY register\n");
4314 * Do not read PHY registers if link is not up
4315 * Set values to typical power-on defaults
4317 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4318 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4319 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4321 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4322 ADVERTISE_ALL | ADVERTISE_CSMA);
4324 phy->expansion = EXPANSION_ENABLENPAGE;
4325 phy->ctrl1000 = ADVERTISE_1000FULL;
4327 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4331 static void e1000_print_link_info(struct e1000_adapter *adapter)
4333 struct e1000_hw *hw = &adapter->hw;
4334 u32 ctrl = er32(CTRL);
4336 /* Link status message must follow this format for user tools */
4337 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4338 adapter->netdev->name,
4339 adapter->link_speed,
4340 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4341 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4342 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4343 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
4346 static bool e1000e_has_link(struct e1000_adapter *adapter)
4348 struct e1000_hw *hw = &adapter->hw;
4349 bool link_active = false;
4353 * get_link_status is set on LSC (link status) interrupt or
4354 * Rx sequence error interrupt. get_link_status will stay
4355 * false until the check_for_link establishes link
4356 * for copper adapters ONLY
4358 switch (hw->phy.media_type) {
4359 case e1000_media_type_copper:
4360 if (hw->mac.get_link_status) {
4361 ret_val = hw->mac.ops.check_for_link(hw);
4362 link_active = !hw->mac.get_link_status;
4367 case e1000_media_type_fiber:
4368 ret_val = hw->mac.ops.check_for_link(hw);
4369 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4371 case e1000_media_type_internal_serdes:
4372 ret_val = hw->mac.ops.check_for_link(hw);
4373 link_active = adapter->hw.mac.serdes_has_link;
4376 case e1000_media_type_unknown:
4380 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4381 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4382 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
4383 e_info("Gigabit has been disabled, downgrading speed\n");
4389 static void e1000e_enable_receives(struct e1000_adapter *adapter)
4391 /* make sure the receive unit is started */
4392 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4393 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4394 struct e1000_hw *hw = &adapter->hw;
4395 u32 rctl = er32(RCTL);
4396 ew32(RCTL, rctl | E1000_RCTL_EN);
4397 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4401 static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4403 struct e1000_hw *hw = &adapter->hw;
4406 * With 82574 controllers, PHY needs to be checked periodically
4407 * for hung state and reset, if two calls return true
4409 if (e1000_check_phy_82574(hw))
4410 adapter->phy_hang_count++;
4412 adapter->phy_hang_count = 0;
4414 if (adapter->phy_hang_count > 1) {
4415 adapter->phy_hang_count = 0;
4416 schedule_work(&adapter->reset_task);
4421 * e1000_watchdog - Timer Call-back
4422 * @data: pointer to adapter cast into an unsigned long
4424 static void e1000_watchdog(unsigned long data)
4426 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4428 /* Do the rest outside of interrupt context */
4429 schedule_work(&adapter->watchdog_task);
4431 /* TODO: make this use queue_delayed_work() */
4434 static void e1000_watchdog_task(struct work_struct *work)
4436 struct e1000_adapter *adapter = container_of(work,
4437 struct e1000_adapter, watchdog_task);
4438 struct net_device *netdev = adapter->netdev;
4439 struct e1000_mac_info *mac = &adapter->hw.mac;
4440 struct e1000_phy_info *phy = &adapter->hw.phy;
4441 struct e1000_ring *tx_ring = adapter->tx_ring;
4442 struct e1000_hw *hw = &adapter->hw;
4445 if (test_bit(__E1000_DOWN, &adapter->state))
4448 link = e1000e_has_link(adapter);
4449 if ((netif_carrier_ok(netdev)) && link) {
4450 /* Cancel scheduled suspend requests. */
4451 pm_runtime_resume(netdev->dev.parent);
4453 e1000e_enable_receives(adapter);
4457 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4458 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4459 e1000_update_mng_vlan(adapter);
4462 if (!netif_carrier_ok(netdev)) {
4465 /* Cancel scheduled suspend requests. */
4466 pm_runtime_resume(netdev->dev.parent);
4468 /* update snapshot of PHY registers on LSC */
4469 e1000_phy_read_status(adapter);
4470 mac->ops.get_link_up_info(&adapter->hw,
4471 &adapter->link_speed,
4472 &adapter->link_duplex);
4473 e1000_print_link_info(adapter);
4475 * On supported PHYs, check for duplex mismatch only
4476 * if link has autonegotiated at 10/100 half
4478 if ((hw->phy.type == e1000_phy_igp_3 ||
4479 hw->phy.type == e1000_phy_bm) &&
4480 (hw->mac.autoneg == true) &&
4481 (adapter->link_speed == SPEED_10 ||
4482 adapter->link_speed == SPEED_100) &&
4483 (adapter->link_duplex == HALF_DUPLEX)) {
4486 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4488 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4489 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
4492 /* adjust timeout factor according to speed/duplex */
4493 adapter->tx_timeout_factor = 1;
4494 switch (adapter->link_speed) {
4497 adapter->tx_timeout_factor = 16;
4501 adapter->tx_timeout_factor = 10;
4506 * workaround: re-program speed mode bit after
4509 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4512 tarc0 = er32(TARC(0));
4513 tarc0 &= ~SPEED_MODE_BIT;
4514 ew32(TARC(0), tarc0);
4518 * disable TSO for pcie and 10/100 speeds, to avoid
4519 * some hardware issues
4521 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4522 switch (adapter->link_speed) {
4525 e_info("10/100 speed: disabling TSO\n");
4526 netdev->features &= ~NETIF_F_TSO;
4527 netdev->features &= ~NETIF_F_TSO6;
4530 netdev->features |= NETIF_F_TSO;
4531 netdev->features |= NETIF_F_TSO6;
4540 * enable transmits in the hardware, need to do this
4541 * after setting TARC(0)
4544 tctl |= E1000_TCTL_EN;
4548 * Perform any post-link-up configuration before
4549 * reporting link up.
4551 if (phy->ops.cfg_on_link_up)
4552 phy->ops.cfg_on_link_up(hw);
4554 netif_carrier_on(netdev);
4556 if (!test_bit(__E1000_DOWN, &adapter->state))
4557 mod_timer(&adapter->phy_info_timer,
4558 round_jiffies(jiffies + 2 * HZ));
4561 if (netif_carrier_ok(netdev)) {
4562 adapter->link_speed = 0;
4563 adapter->link_duplex = 0;
4564 /* Link status message must follow this format */
4565 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4566 adapter->netdev->name);
4567 netif_carrier_off(netdev);
4568 if (!test_bit(__E1000_DOWN, &adapter->state))
4569 mod_timer(&adapter->phy_info_timer,
4570 round_jiffies(jiffies + 2 * HZ));
4572 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4573 schedule_work(&adapter->reset_task);
4575 pm_schedule_suspend(netdev->dev.parent,
4581 spin_lock(&adapter->stats64_lock);
4582 e1000e_update_stats(adapter);
4584 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4585 adapter->tpt_old = adapter->stats.tpt;
4586 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4587 adapter->colc_old = adapter->stats.colc;
4589 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4590 adapter->gorc_old = adapter->stats.gorc;
4591 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4592 adapter->gotc_old = adapter->stats.gotc;
4593 spin_unlock(&adapter->stats64_lock);
4595 e1000e_update_adaptive(&adapter->hw);
4597 if (!netif_carrier_ok(netdev) &&
4598 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4600 * We've lost link, so the controller stops DMA,
4601 * but we've got queued Tx work that's never going
4602 * to get done, so reset controller to flush Tx.
4603 * (Do the reset outside of interrupt context).
4605 schedule_work(&adapter->reset_task);
4606 /* return immediately since reset is imminent */
4610 /* Simple mode for Interrupt Throttle Rate (ITR) */
4611 if (adapter->itr_setting == 4) {
4613 * Symmetric Tx/Rx gets a reduced ITR=2000;
4614 * Total asymmetrical Tx or Rx gets ITR=8000;
4615 * everyone else is between 2000-8000.
4617 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4618 u32 dif = (adapter->gotc > adapter->gorc ?
4619 adapter->gotc - adapter->gorc :
4620 adapter->gorc - adapter->gotc) / 10000;
4621 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4623 ew32(ITR, 1000000000 / (itr * 256));
4626 /* Cause software interrupt to ensure Rx ring is cleaned */
4627 if (adapter->msix_entries)
4628 ew32(ICS, adapter->rx_ring->ims_val);
4630 ew32(ICS, E1000_ICS_RXDMT0);
4632 /* flush pending descriptors to memory before detecting Tx hang */
4633 e1000e_flush_descriptors(adapter);
4635 /* Force detection of hung controller every watchdog period */
4636 adapter->detect_tx_hung = true;
4639 * With 82571 controllers, LAA may be overwritten due to controller
4640 * reset from the other port. Set the appropriate LAA in RAR[0]
4642 if (e1000e_get_laa_state_82571(hw))
4643 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4645 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4646 e1000e_check_82574_phy_workaround(adapter);
4648 /* Reset the timer */
4649 if (!test_bit(__E1000_DOWN, &adapter->state))
4650 mod_timer(&adapter->watchdog_timer,
4651 round_jiffies(jiffies + 2 * HZ));
4654 #define E1000_TX_FLAGS_CSUM 0x00000001
4655 #define E1000_TX_FLAGS_VLAN 0x00000002
4656 #define E1000_TX_FLAGS_TSO 0x00000004
4657 #define E1000_TX_FLAGS_IPV4 0x00000008
4658 #define E1000_TX_FLAGS_NO_FCS 0x00000010
4659 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4660 #define E1000_TX_FLAGS_VLAN_SHIFT 16
4662 static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
4664 struct e1000_context_desc *context_desc;
4665 struct e1000_buffer *buffer_info;
4668 u16 ipcse = 0, tucse, mss;
4669 u8 ipcss, ipcso, tucss, tucso, hdr_len;
4671 if (!skb_is_gso(skb))
4674 if (skb_header_cloned(skb)) {
4675 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4681 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4682 mss = skb_shinfo(skb)->gso_size;
4683 if (skb->protocol == htons(ETH_P_IP)) {
4684 struct iphdr *iph = ip_hdr(skb);
4687 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4689 cmd_length = E1000_TXD_CMD_IP;
4690 ipcse = skb_transport_offset(skb) - 1;
4691 } else if (skb_is_gso_v6(skb)) {
4692 ipv6_hdr(skb)->payload_len = 0;
4693 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4694 &ipv6_hdr(skb)->daddr,
4698 ipcss = skb_network_offset(skb);
4699 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4700 tucss = skb_transport_offset(skb);
4701 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4704 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4705 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4707 i = tx_ring->next_to_use;
4708 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4709 buffer_info = &tx_ring->buffer_info[i];
4711 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4712 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4713 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4714 context_desc->upper_setup.tcp_fields.tucss = tucss;
4715 context_desc->upper_setup.tcp_fields.tucso = tucso;
4716 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4717 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4718 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4719 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4721 buffer_info->time_stamp = jiffies;
4722 buffer_info->next_to_watch = i;
4725 if (i == tx_ring->count)
4727 tx_ring->next_to_use = i;
4732 static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
4734 struct e1000_adapter *adapter = tx_ring->adapter;
4735 struct e1000_context_desc *context_desc;
4736 struct e1000_buffer *buffer_info;
4739 u32 cmd_len = E1000_TXD_CMD_DEXT;
4742 if (skb->ip_summed != CHECKSUM_PARTIAL)
4745 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4746 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4748 protocol = skb->protocol;
4751 case cpu_to_be16(ETH_P_IP):
4752 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4753 cmd_len |= E1000_TXD_CMD_TCP;
4755 case cpu_to_be16(ETH_P_IPV6):
4756 /* XXX not handling all IPV6 headers */
4757 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4758 cmd_len |= E1000_TXD_CMD_TCP;
4761 if (unlikely(net_ratelimit()))
4762 e_warn("checksum_partial proto=%x!\n",
4763 be16_to_cpu(protocol));
4767 css = skb_checksum_start_offset(skb);
4769 i = tx_ring->next_to_use;
4770 buffer_info = &tx_ring->buffer_info[i];
4771 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4773 context_desc->lower_setup.ip_config = 0;
4774 context_desc->upper_setup.tcp_fields.tucss = css;
4775 context_desc->upper_setup.tcp_fields.tucso =
4776 css + skb->csum_offset;
4777 context_desc->upper_setup.tcp_fields.tucse = 0;
4778 context_desc->tcp_seg_setup.data = 0;
4779 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4781 buffer_info->time_stamp = jiffies;
4782 buffer_info->next_to_watch = i;
4785 if (i == tx_ring->count)
4787 tx_ring->next_to_use = i;
4792 #define E1000_MAX_PER_TXD 8192
4793 #define E1000_MAX_TXD_PWR 12
4795 static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
4796 unsigned int first, unsigned int max_per_txd,
4797 unsigned int nr_frags, unsigned int mss)
4799 struct e1000_adapter *adapter = tx_ring->adapter;
4800 struct pci_dev *pdev = adapter->pdev;
4801 struct e1000_buffer *buffer_info;
4802 unsigned int len = skb_headlen(skb);
4803 unsigned int offset = 0, size, count = 0, i;
4804 unsigned int f, bytecount, segs;
4806 i = tx_ring->next_to_use;
4809 buffer_info = &tx_ring->buffer_info[i];
4810 size = min(len, max_per_txd);
4812 buffer_info->length = size;
4813 buffer_info->time_stamp = jiffies;
4814 buffer_info->next_to_watch = i;
4815 buffer_info->dma = dma_map_single(&pdev->dev,
4817 size, DMA_TO_DEVICE);
4818 buffer_info->mapped_as_page = false;
4819 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4828 if (i == tx_ring->count)
4833 for (f = 0; f < nr_frags; f++) {
4834 const struct skb_frag_struct *frag;
4836 frag = &skb_shinfo(skb)->frags[f];
4837 len = skb_frag_size(frag);
4842 if (i == tx_ring->count)
4845 buffer_info = &tx_ring->buffer_info[i];
4846 size = min(len, max_per_txd);
4848 buffer_info->length = size;
4849 buffer_info->time_stamp = jiffies;
4850 buffer_info->next_to_watch = i;
4851 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4852 offset, size, DMA_TO_DEVICE);
4853 buffer_info->mapped_as_page = true;
4854 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4863 segs = skb_shinfo(skb)->gso_segs ? : 1;
4864 /* multiply data chunks by size of headers */
4865 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4867 tx_ring->buffer_info[i].skb = skb;
4868 tx_ring->buffer_info[i].segs = segs;
4869 tx_ring->buffer_info[i].bytecount = bytecount;
4870 tx_ring->buffer_info[first].next_to_watch = i;
4875 dev_err(&pdev->dev, "Tx DMA map failed\n");
4876 buffer_info->dma = 0;
4882 i += tx_ring->count;
4884 buffer_info = &tx_ring->buffer_info[i];
4885 e1000_put_txbuf(tx_ring, buffer_info);
4891 static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
4893 struct e1000_adapter *adapter = tx_ring->adapter;
4894 struct e1000_tx_desc *tx_desc = NULL;
4895 struct e1000_buffer *buffer_info;
4896 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4899 if (tx_flags & E1000_TX_FLAGS_TSO) {
4900 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4902 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4904 if (tx_flags & E1000_TX_FLAGS_IPV4)
4905 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4908 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4909 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4910 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4913 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4914 txd_lower |= E1000_TXD_CMD_VLE;
4915 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4918 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4919 txd_lower &= ~(E1000_TXD_CMD_IFCS);
4921 i = tx_ring->next_to_use;
4924 buffer_info = &tx_ring->buffer_info[i];
4925 tx_desc = E1000_TX_DESC(*tx_ring, i);
4926 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4927 tx_desc->lower.data =
4928 cpu_to_le32(txd_lower | buffer_info->length);
4929 tx_desc->upper.data = cpu_to_le32(txd_upper);
4932 if (i == tx_ring->count)
4934 } while (--count > 0);
4936 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4938 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
4939 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4940 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
4943 * Force memory writes to complete before letting h/w
4944 * know there are new descriptors to fetch. (Only
4945 * applicable for weak-ordered memory model archs,
4950 tx_ring->next_to_use = i;
4952 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4953 e1000e_update_tdt_wa(tx_ring, i);
4955 writel(i, tx_ring->tail);
4958 * we need this if more than one processor can write to our tail
4959 * at a time, it synchronizes IO on IA64/Altix systems
4964 #define MINIMUM_DHCP_PACKET_SIZE 282
4965 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4966 struct sk_buff *skb)
4968 struct e1000_hw *hw = &adapter->hw;
4971 if (vlan_tx_tag_present(skb)) {
4972 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4973 (adapter->hw.mng_cookie.status &
4974 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4978 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4981 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4985 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4988 if (ip->protocol != IPPROTO_UDP)
4991 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4992 if (ntohs(udp->dest) != 67)
4995 offset = (u8 *)udp + 8 - skb->data;
4996 length = skb->len - offset;
4997 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5003 static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
5005 struct e1000_adapter *adapter = tx_ring->adapter;
5007 netif_stop_queue(adapter->netdev);
5009 * Herbert's original patch had:
5010 * smp_mb__after_netif_stop_queue();
5011 * but since that doesn't exist yet, just open code it.
5016 * We need to check again in a case another CPU has just
5017 * made room available.
5019 if (e1000_desc_unused(tx_ring) < size)
5023 netif_start_queue(adapter->netdev);
5024 ++adapter->restart_queue;
5028 static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
5030 if (e1000_desc_unused(tx_ring) >= size)
5032 return __e1000_maybe_stop_tx(tx_ring, size);
5035 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1)
5036 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5037 struct net_device *netdev)
5039 struct e1000_adapter *adapter = netdev_priv(netdev);
5040 struct e1000_ring *tx_ring = adapter->tx_ring;
5042 unsigned int max_per_txd = E1000_MAX_PER_TXD;
5043 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
5044 unsigned int tx_flags = 0;
5045 unsigned int len = skb_headlen(skb);
5046 unsigned int nr_frags;
5052 if (test_bit(__E1000_DOWN, &adapter->state)) {
5053 dev_kfree_skb_any(skb);
5054 return NETDEV_TX_OK;
5057 if (skb->len <= 0) {
5058 dev_kfree_skb_any(skb);
5059 return NETDEV_TX_OK;
5062 mss = skb_shinfo(skb)->gso_size;
5064 * The controller does a simple calculation to
5065 * make sure there is enough room in the FIFO before
5066 * initiating the DMA for each buffer. The calc is:
5067 * 4 = ceil(buffer len/mss). To make sure we don't
5068 * overrun the FIFO, adjust the max buffer len if mss
5073 max_per_txd = min(mss << 2, max_per_txd);
5074 max_txd_pwr = fls(max_per_txd) - 1;
5077 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
5078 * points to just header, pull a few bytes of payload from
5079 * frags into skb->data
5081 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5083 * we do this workaround for ES2LAN, but it is un-necessary,
5084 * avoiding it could save a lot of cycles
5086 if (skb->data_len && (hdr_len == len)) {
5087 unsigned int pull_size;
5089 pull_size = min_t(unsigned int, 4, skb->data_len);
5090 if (!__pskb_pull_tail(skb, pull_size)) {
5091 e_err("__pskb_pull_tail failed.\n");
5092 dev_kfree_skb_any(skb);
5093 return NETDEV_TX_OK;
5095 len = skb_headlen(skb);
5099 /* reserve a descriptor for the offload context */
5100 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5104 count += TXD_USE_COUNT(len, max_txd_pwr);
5106 nr_frags = skb_shinfo(skb)->nr_frags;
5107 for (f = 0; f < nr_frags; f++)
5108 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5111 if (adapter->hw.mac.tx_pkt_filtering)
5112 e1000_transfer_dhcp_info(adapter, skb);
5115 * need: count + 2 desc gap to keep tail from touching
5116 * head, otherwise try next time
5118 if (e1000_maybe_stop_tx(tx_ring, count + 2))
5119 return NETDEV_TX_BUSY;
5121 if (vlan_tx_tag_present(skb)) {
5122 tx_flags |= E1000_TX_FLAGS_VLAN;
5123 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5126 first = tx_ring->next_to_use;
5128 tso = e1000_tso(tx_ring, skb);
5130 dev_kfree_skb_any(skb);
5131 return NETDEV_TX_OK;
5135 tx_flags |= E1000_TX_FLAGS_TSO;
5136 else if (e1000_tx_csum(tx_ring, skb))
5137 tx_flags |= E1000_TX_FLAGS_CSUM;
5140 * Old method was to assume IPv4 packet by default if TSO was enabled.
5141 * 82571 hardware supports TSO capabilities for IPv6 as well...
5142 * no longer assume, we must.
5144 if (skb->protocol == htons(ETH_P_IP))
5145 tx_flags |= E1000_TX_FLAGS_IPV4;
5147 if (unlikely(skb->no_fcs))
5148 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5150 /* if count is 0 then mapping error has occurred */
5151 count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss);
5153 netdev_sent_queue(netdev, skb->len);
5154 e1000_tx_queue(tx_ring, tx_flags, count);
5155 /* Make sure there is space in the ring for the next send. */
5156 e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2);
5159 dev_kfree_skb_any(skb);
5160 tx_ring->buffer_info[first].time_stamp = 0;
5161 tx_ring->next_to_use = first;
5164 return NETDEV_TX_OK;
5168 * e1000_tx_timeout - Respond to a Tx Hang
5169 * @netdev: network interface device structure
5171 static void e1000_tx_timeout(struct net_device *netdev)
5173 struct e1000_adapter *adapter = netdev_priv(netdev);
5175 /* Do the reset outside of interrupt context */
5176 adapter->tx_timeout_count++;
5177 schedule_work(&adapter->reset_task);
5180 static void e1000_reset_task(struct work_struct *work)
5182 struct e1000_adapter *adapter;
5183 adapter = container_of(work, struct e1000_adapter, reset_task);
5185 /* don't run the task if already down */
5186 if (test_bit(__E1000_DOWN, &adapter->state))
5189 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5190 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5191 e1000e_dump(adapter);
5192 e_err("Reset adapter\n");
5194 e1000e_reinit_locked(adapter);
5198 * e1000_get_stats64 - Get System Network Statistics
5199 * @netdev: network interface device structure
5200 * @stats: rtnl_link_stats64 pointer
5202 * Returns the address of the device statistics structure.
5204 struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5205 struct rtnl_link_stats64 *stats)
5207 struct e1000_adapter *adapter = netdev_priv(netdev);
5209 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5210 spin_lock(&adapter->stats64_lock);
5211 e1000e_update_stats(adapter);
5212 /* Fill out the OS statistics structure */
5213 stats->rx_bytes = adapter->stats.gorc;
5214 stats->rx_packets = adapter->stats.gprc;
5215 stats->tx_bytes = adapter->stats.gotc;
5216 stats->tx_packets = adapter->stats.gptc;
5217 stats->multicast = adapter->stats.mprc;
5218 stats->collisions = adapter->stats.colc;
5223 * RLEC on some newer hardware can be incorrect so build
5224 * our own version based on RUC and ROC
5226 stats->rx_errors = adapter->stats.rxerrc +
5227 adapter->stats.crcerrs + adapter->stats.algnerrc +
5228 adapter->stats.ruc + adapter->stats.roc +
5229 adapter->stats.cexterr;
5230 stats->rx_length_errors = adapter->stats.ruc +
5232 stats->rx_crc_errors = adapter->stats.crcerrs;
5233 stats->rx_frame_errors = adapter->stats.algnerrc;
5234 stats->rx_missed_errors = adapter->stats.mpc;
5237 stats->tx_errors = adapter->stats.ecol +
5238 adapter->stats.latecol;
5239 stats->tx_aborted_errors = adapter->stats.ecol;
5240 stats->tx_window_errors = adapter->stats.latecol;
5241 stats->tx_carrier_errors = adapter->stats.tncrs;
5243 /* Tx Dropped needs to be maintained elsewhere */
5245 spin_unlock(&adapter->stats64_lock);
5250 * e1000_change_mtu - Change the Maximum Transfer Unit
5251 * @netdev: network interface device structure
5252 * @new_mtu: new value for maximum frame size
5254 * Returns 0 on success, negative on failure
5256 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5258 struct e1000_adapter *adapter = netdev_priv(netdev);
5259 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5261 /* Jumbo frame support */
5262 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
5263 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5264 e_err("Jumbo Frames not supported.\n");
5269 * IP payload checksum (enabled with jumbos/packet-split when
5270 * Rx checksum is enabled) and generation of RSS hash is
5271 * mutually exclusive in the hardware.
5273 if ((netdev->features & NETIF_F_RXCSUM) &&
5274 (netdev->features & NETIF_F_RXHASH)) {
5275 e_err("Jumbo frames cannot be enabled when both receive checksum offload and receive hashing are enabled. Disable one of the receive offload features before enabling jumbos.\n");
5280 /* Supported frame sizes */
5281 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5282 (max_frame > adapter->max_hw_frame_size)) {
5283 e_err("Unsupported MTU setting\n");
5287 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5288 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5289 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5290 (new_mtu > ETH_DATA_LEN)) {
5291 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
5295 /* 82573 Errata 17 */
5296 if (((adapter->hw.mac.type == e1000_82573) ||
5297 (adapter->hw.mac.type == e1000_82574)) &&
5298 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5299 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5300 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5303 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
5304 usleep_range(1000, 2000);
5305 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
5306 adapter->max_frame_size = max_frame;
5307 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5308 netdev->mtu = new_mtu;
5309 if (netif_running(netdev))
5310 e1000e_down(adapter);
5313 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
5314 * means we reserve 2 more, this pushes us to allocate from the next
5316 * i.e. RXBUFFER_2048 --> size-4096 slab
5317 * However with the new *_jumbo_rx* routines, jumbo receives will use
5321 if (max_frame <= 2048)
5322 adapter->rx_buffer_len = 2048;
5324 adapter->rx_buffer_len = 4096;
5326 /* adjust allocation if LPE protects us, and we aren't using SBP */
5327 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5328 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5329 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
5332 if (netif_running(netdev))
5335 e1000e_reset(adapter);
5337 clear_bit(__E1000_RESETTING, &adapter->state);
5342 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5345 struct e1000_adapter *adapter = netdev_priv(netdev);
5346 struct mii_ioctl_data *data = if_mii(ifr);
5348 if (adapter->hw.phy.media_type != e1000_media_type_copper)
5353 data->phy_id = adapter->hw.phy.addr;
5356 e1000_phy_read_status(adapter);
5358 switch (data->reg_num & 0x1F) {
5360 data->val_out = adapter->phy_regs.bmcr;
5363 data->val_out = adapter->phy_regs.bmsr;
5366 data->val_out = (adapter->hw.phy.id >> 16);
5369 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5372 data->val_out = adapter->phy_regs.advertise;
5375 data->val_out = adapter->phy_regs.lpa;
5378 data->val_out = adapter->phy_regs.expansion;
5381 data->val_out = adapter->phy_regs.ctrl1000;
5384 data->val_out = adapter->phy_regs.stat1000;
5387 data->val_out = adapter->phy_regs.estatus;
5400 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5406 return e1000_mii_ioctl(netdev, ifr, cmd);
5412 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5414 struct e1000_hw *hw = &adapter->hw;
5416 u16 phy_reg, wuc_enable;
5419 /* copy MAC RARs to PHY RARs */
5420 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
5422 retval = hw->phy.ops.acquire(hw);
5424 e_err("Could not acquire PHY\n");
5428 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5429 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5433 /* copy MAC MTA to PHY MTA - only needed for pchlan */
5434 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5435 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5436 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5437 (u16)(mac_reg & 0xFFFF));
5438 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5439 (u16)((mac_reg >> 16) & 0xFFFF));
5442 /* configure PHY Rx Control register */
5443 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
5444 mac_reg = er32(RCTL);
5445 if (mac_reg & E1000_RCTL_UPE)
5446 phy_reg |= BM_RCTL_UPE;
5447 if (mac_reg & E1000_RCTL_MPE)
5448 phy_reg |= BM_RCTL_MPE;
5449 phy_reg &= ~(BM_RCTL_MO_MASK);
5450 if (mac_reg & E1000_RCTL_MO_3)
5451 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5452 << BM_RCTL_MO_SHIFT);
5453 if (mac_reg & E1000_RCTL_BAM)
5454 phy_reg |= BM_RCTL_BAM;
5455 if (mac_reg & E1000_RCTL_PMCF)
5456 phy_reg |= BM_RCTL_PMCF;
5457 mac_reg = er32(CTRL);
5458 if (mac_reg & E1000_CTRL_RFCE)
5459 phy_reg |= BM_RCTL_RFCE;
5460 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
5462 /* enable PHY wakeup in MAC register */
5464 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5466 /* configure and enable PHY wakeup in PHY registers */
5467 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5468 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5470 /* activate PHY wakeup */
5471 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5472 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5474 e_err("Could not set PHY Host Wakeup bit\n");
5476 hw->phy.ops.release(hw);
5481 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5484 struct net_device *netdev = pci_get_drvdata(pdev);
5485 struct e1000_adapter *adapter = netdev_priv(netdev);
5486 struct e1000_hw *hw = &adapter->hw;
5487 u32 ctrl, ctrl_ext, rctl, status;
5488 /* Runtime suspend should only enable wakeup for link changes */
5489 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
5492 netif_device_detach(netdev);
5494 if (netif_running(netdev)) {
5495 int count = E1000_CHECK_RESET_COUNT;
5497 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5498 usleep_range(10000, 20000);
5500 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5501 e1000e_down(adapter);
5502 e1000_free_irq(adapter);
5504 e1000e_reset_interrupt_capability(adapter);
5506 retval = pci_save_state(pdev);
5510 status = er32(STATUS);
5511 if (status & E1000_STATUS_LU)
5512 wufc &= ~E1000_WUFC_LNKC;
5515 e1000_setup_rctl(adapter);
5516 e1000e_set_rx_mode(netdev);
5518 /* turn on all-multi mode if wake on multicast is enabled */
5519 if (wufc & E1000_WUFC_MC) {
5521 rctl |= E1000_RCTL_MPE;
5526 /* advertise wake from D3Cold */
5527 #define E1000_CTRL_ADVD3WUC 0x00100000
5528 /* phy power management enable */
5529 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5530 ctrl |= E1000_CTRL_ADVD3WUC;
5531 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5532 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
5535 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5536 adapter->hw.phy.media_type ==
5537 e1000_media_type_internal_serdes) {
5538 /* keep the laser running in D3 */
5539 ctrl_ext = er32(CTRL_EXT);
5540 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
5541 ew32(CTRL_EXT, ctrl_ext);
5544 if (adapter->flags & FLAG_IS_ICH)
5545 e1000_suspend_workarounds_ich8lan(&adapter->hw);
5547 /* Allow time for pending master requests to run */
5548 e1000e_disable_pcie_master(&adapter->hw);
5550 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5551 /* enable wakeup by the PHY */
5552 retval = e1000_init_phy_wakeup(adapter, wufc);
5556 /* enable wakeup by the MAC */
5558 ew32(WUC, E1000_WUC_PME_EN);
5565 *enable_wake = !!wufc;
5567 /* make sure adapter isn't asleep if manageability is enabled */
5568 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5569 (hw->mac.ops.check_mng_mode(hw)))
5570 *enable_wake = true;
5572 if (adapter->hw.phy.type == e1000_phy_igp_3)
5573 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5576 * Release control of h/w to f/w. If f/w is AMT enabled, this
5577 * would have already happened in close and is redundant.
5579 e1000e_release_hw_control(adapter);
5581 pci_disable_device(pdev);
5586 static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5588 if (sleep && wake) {
5589 pci_prepare_to_sleep(pdev);
5593 pci_wake_from_d3(pdev, wake);
5594 pci_set_power_state(pdev, PCI_D3hot);
5597 static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5600 struct net_device *netdev = pci_get_drvdata(pdev);
5601 struct e1000_adapter *adapter = netdev_priv(netdev);
5604 * The pci-e switch on some quad port adapters will report a
5605 * correctable error when the MAC transitions from D0 to D3. To
5606 * prevent this we need to mask off the correctable errors on the
5607 * downstream port of the pci-e switch.
5609 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5610 struct pci_dev *us_dev = pdev->bus->self;
5611 int pos = pci_pcie_cap(us_dev);
5614 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5615 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5616 (devctl & ~PCI_EXP_DEVCTL_CERE));
5618 e1000_power_off(pdev, sleep, wake);
5620 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5622 e1000_power_off(pdev, sleep, wake);
5626 #ifdef CONFIG_PCIEASPM
5627 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5629 pci_disable_link_state_locked(pdev, state);
5632 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5638 * Both device and parent should have the same ASPM setting.
5639 * Disable ASPM in downstream component first and then upstream.
5641 pos = pci_pcie_cap(pdev);
5642 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16);
5644 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5646 if (!pdev->bus->self)
5649 pos = pci_pcie_cap(pdev->bus->self);
5650 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16);
5652 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5655 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5657 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5658 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5659 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5661 __e1000e_disable_aspm(pdev, state);
5665 static bool e1000e_pm_ready(struct e1000_adapter *adapter)
5667 return !!adapter->tx_ring->buffer_info;
5670 static int __e1000_resume(struct pci_dev *pdev)
5672 struct net_device *netdev = pci_get_drvdata(pdev);
5673 struct e1000_adapter *adapter = netdev_priv(netdev);
5674 struct e1000_hw *hw = &adapter->hw;
5675 u16 aspm_disable_flag = 0;
5678 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5679 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5680 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5681 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5682 if (aspm_disable_flag)
5683 e1000e_disable_aspm(pdev, aspm_disable_flag);
5685 pci_set_power_state(pdev, PCI_D0);
5686 pci_restore_state(pdev);
5687 pci_save_state(pdev);
5689 e1000e_set_interrupt_capability(adapter);
5690 if (netif_running(netdev)) {
5691 err = e1000_request_irq(adapter);
5696 if (hw->mac.type == e1000_pch2lan)
5697 e1000_resume_workarounds_pchlan(&adapter->hw);
5699 e1000e_power_up_phy(adapter);
5701 /* report the system wakeup cause from S3/S4 */
5702 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5705 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5707 e_info("PHY Wakeup cause - %s\n",
5708 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5709 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5710 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5711 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5712 phy_data & E1000_WUS_LNKC ?
5713 "Link Status Change" : "other");
5715 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5717 u32 wus = er32(WUS);
5719 e_info("MAC Wakeup cause - %s\n",
5720 wus & E1000_WUS_EX ? "Unicast Packet" :
5721 wus & E1000_WUS_MC ? "Multicast Packet" :
5722 wus & E1000_WUS_BC ? "Broadcast Packet" :
5723 wus & E1000_WUS_MAG ? "Magic Packet" :
5724 wus & E1000_WUS_LNKC ? "Link Status Change" :
5730 e1000e_reset(adapter);
5732 e1000_init_manageability_pt(adapter);
5734 if (netif_running(netdev))
5737 netif_device_attach(netdev);
5740 * If the controller has AMT, do not set DRV_LOAD until the interface
5741 * is up. For all other cases, let the f/w know that the h/w is now
5742 * under the control of the driver.
5744 if (!(adapter->flags & FLAG_HAS_AMT))
5745 e1000e_get_hw_control(adapter);
5750 #ifdef CONFIG_PM_SLEEP
5751 static int e1000_suspend(struct device *dev)
5753 struct pci_dev *pdev = to_pci_dev(dev);
5757 retval = __e1000_shutdown(pdev, &wake, false);
5759 e1000_complete_shutdown(pdev, true, wake);
5764 static int e1000_resume(struct device *dev)
5766 struct pci_dev *pdev = to_pci_dev(dev);
5767 struct net_device *netdev = pci_get_drvdata(pdev);
5768 struct e1000_adapter *adapter = netdev_priv(netdev);
5770 if (e1000e_pm_ready(adapter))
5771 adapter->idle_check = true;
5773 return __e1000_resume(pdev);
5775 #endif /* CONFIG_PM_SLEEP */
5777 #ifdef CONFIG_PM_RUNTIME
5778 static int e1000_runtime_suspend(struct device *dev)
5780 struct pci_dev *pdev = to_pci_dev(dev);
5781 struct net_device *netdev = pci_get_drvdata(pdev);
5782 struct e1000_adapter *adapter = netdev_priv(netdev);
5784 if (e1000e_pm_ready(adapter)) {
5787 __e1000_shutdown(pdev, &wake, true);
5793 static int e1000_idle(struct device *dev)
5795 struct pci_dev *pdev = to_pci_dev(dev);
5796 struct net_device *netdev = pci_get_drvdata(pdev);
5797 struct e1000_adapter *adapter = netdev_priv(netdev);
5799 if (!e1000e_pm_ready(adapter))
5802 if (adapter->idle_check) {
5803 adapter->idle_check = false;
5804 if (!e1000e_has_link(adapter))
5805 pm_schedule_suspend(dev, MSEC_PER_SEC);
5811 static int e1000_runtime_resume(struct device *dev)
5813 struct pci_dev *pdev = to_pci_dev(dev);
5814 struct net_device *netdev = pci_get_drvdata(pdev);
5815 struct e1000_adapter *adapter = netdev_priv(netdev);
5817 if (!e1000e_pm_ready(adapter))
5820 adapter->idle_check = !dev->power.runtime_auto;
5821 return __e1000_resume(pdev);
5823 #endif /* CONFIG_PM_RUNTIME */
5824 #endif /* CONFIG_PM */
5826 static void e1000_shutdown(struct pci_dev *pdev)
5830 __e1000_shutdown(pdev, &wake, false);
5832 if (system_state == SYSTEM_POWER_OFF)
5833 e1000_complete_shutdown(pdev, false, wake);
5836 #ifdef CONFIG_NET_POLL_CONTROLLER
5838 static irqreturn_t e1000_intr_msix(int irq, void *data)
5840 struct net_device *netdev = data;
5841 struct e1000_adapter *adapter = netdev_priv(netdev);
5843 if (adapter->msix_entries) {
5844 int vector, msix_irq;
5847 msix_irq = adapter->msix_entries[vector].vector;
5848 disable_irq(msix_irq);
5849 e1000_intr_msix_rx(msix_irq, netdev);
5850 enable_irq(msix_irq);
5853 msix_irq = adapter->msix_entries[vector].vector;
5854 disable_irq(msix_irq);
5855 e1000_intr_msix_tx(msix_irq, netdev);
5856 enable_irq(msix_irq);
5859 msix_irq = adapter->msix_entries[vector].vector;
5860 disable_irq(msix_irq);
5861 e1000_msix_other(msix_irq, netdev);
5862 enable_irq(msix_irq);
5869 * Polling 'interrupt' - used by things like netconsole to send skbs
5870 * without having to re-enable interrupts. It's not called while
5871 * the interrupt routine is executing.
5873 static void e1000_netpoll(struct net_device *netdev)
5875 struct e1000_adapter *adapter = netdev_priv(netdev);
5877 switch (adapter->int_mode) {
5878 case E1000E_INT_MODE_MSIX:
5879 e1000_intr_msix(adapter->pdev->irq, netdev);
5881 case E1000E_INT_MODE_MSI:
5882 disable_irq(adapter->pdev->irq);
5883 e1000_intr_msi(adapter->pdev->irq, netdev);
5884 enable_irq(adapter->pdev->irq);
5886 default: /* E1000E_INT_MODE_LEGACY */
5887 disable_irq(adapter->pdev->irq);
5888 e1000_intr(adapter->pdev->irq, netdev);
5889 enable_irq(adapter->pdev->irq);
5896 * e1000_io_error_detected - called when PCI error is detected
5897 * @pdev: Pointer to PCI device
5898 * @state: The current pci connection state
5900 * This function is called after a PCI bus error affecting
5901 * this device has been detected.
5903 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5904 pci_channel_state_t state)
5906 struct net_device *netdev = pci_get_drvdata(pdev);
5907 struct e1000_adapter *adapter = netdev_priv(netdev);
5909 netif_device_detach(netdev);
5911 if (state == pci_channel_io_perm_failure)
5912 return PCI_ERS_RESULT_DISCONNECT;
5914 if (netif_running(netdev))
5915 e1000e_down(adapter);
5916 pci_disable_device(pdev);
5918 /* Request a slot slot reset. */
5919 return PCI_ERS_RESULT_NEED_RESET;
5923 * e1000_io_slot_reset - called after the pci bus has been reset.
5924 * @pdev: Pointer to PCI device
5926 * Restart the card from scratch, as if from a cold-boot. Implementation
5927 * resembles the first-half of the e1000_resume routine.
5929 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5931 struct net_device *netdev = pci_get_drvdata(pdev);
5932 struct e1000_adapter *adapter = netdev_priv(netdev);
5933 struct e1000_hw *hw = &adapter->hw;
5934 u16 aspm_disable_flag = 0;
5936 pci_ers_result_t result;
5938 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5939 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5940 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5941 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5942 if (aspm_disable_flag)
5943 e1000e_disable_aspm(pdev, aspm_disable_flag);
5945 err = pci_enable_device_mem(pdev);
5948 "Cannot re-enable PCI device after reset.\n");
5949 result = PCI_ERS_RESULT_DISCONNECT;
5951 pci_set_master(pdev);
5952 pdev->state_saved = true;
5953 pci_restore_state(pdev);
5955 pci_enable_wake(pdev, PCI_D3hot, 0);
5956 pci_enable_wake(pdev, PCI_D3cold, 0);
5958 e1000e_reset(adapter);
5960 result = PCI_ERS_RESULT_RECOVERED;
5963 pci_cleanup_aer_uncorrect_error_status(pdev);
5969 * e1000_io_resume - called when traffic can start flowing again.
5970 * @pdev: Pointer to PCI device
5972 * This callback is called when the error recovery driver tells us that
5973 * its OK to resume normal operation. Implementation resembles the
5974 * second-half of the e1000_resume routine.
5976 static void e1000_io_resume(struct pci_dev *pdev)
5978 struct net_device *netdev = pci_get_drvdata(pdev);
5979 struct e1000_adapter *adapter = netdev_priv(netdev);
5981 e1000_init_manageability_pt(adapter);
5983 if (netif_running(netdev)) {
5984 if (e1000e_up(adapter)) {
5986 "can't bring device back up after reset\n");
5991 netif_device_attach(netdev);
5994 * If the controller has AMT, do not set DRV_LOAD until the interface
5995 * is up. For all other cases, let the f/w know that the h/w is now
5996 * under the control of the driver.
5998 if (!(adapter->flags & FLAG_HAS_AMT))
5999 e1000e_get_hw_control(adapter);
6003 static void e1000_print_device_info(struct e1000_adapter *adapter)
6005 struct e1000_hw *hw = &adapter->hw;
6006 struct net_device *netdev = adapter->netdev;
6008 u8 pba_str[E1000_PBANUM_LENGTH];
6010 /* print bus type/speed/width info */
6011 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
6013 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
6017 e_info("Intel(R) PRO/%s Network Connection\n",
6018 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
6019 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6020 E1000_PBANUM_LENGTH);
6022 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
6023 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6024 hw->mac.type, hw->phy.type, pba_str);
6027 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6029 struct e1000_hw *hw = &adapter->hw;
6033 if (hw->mac.type != e1000_82573)
6036 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
6038 if (!ret_val && (!(buf & (1 << 0)))) {
6039 /* Deep Smart Power Down (DSPD) */
6040 dev_warn(&adapter->pdev->dev,
6041 "Warning: detected DSPD enabled in EEPROM\n");
6045 static int e1000_set_features(struct net_device *netdev,
6046 netdev_features_t features)
6048 struct e1000_adapter *adapter = netdev_priv(netdev);
6049 netdev_features_t changed = features ^ netdev->features;
6051 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6052 adapter->flags |= FLAG_TSO_FORCE;
6054 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
6055 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6060 * IP payload checksum (enabled with jumbos/packet-split when Rx
6061 * checksum is enabled) and generation of RSS hash is mutually
6062 * exclusive in the hardware.
6064 if (adapter->rx_ps_pages &&
6065 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
6066 e_err("Enabling both receive checksum offload and receive hashing is not possible with jumbo frames. Disable jumbos or enable only one of the receive offload features.\n");
6070 if (changed & NETIF_F_RXFCS) {
6071 if (features & NETIF_F_RXFCS) {
6072 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6074 /* We need to take it back to defaults, which might mean
6075 * stripping is still disabled at the adapter level.
6077 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6078 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6080 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6084 netdev->features = features;
6086 if (netif_running(netdev))
6087 e1000e_reinit_locked(adapter);
6089 e1000e_reset(adapter);
6094 static const struct net_device_ops e1000e_netdev_ops = {
6095 .ndo_open = e1000_open,
6096 .ndo_stop = e1000_close,
6097 .ndo_start_xmit = e1000_xmit_frame,
6098 .ndo_get_stats64 = e1000e_get_stats64,
6099 .ndo_set_rx_mode = e1000e_set_rx_mode,
6100 .ndo_set_mac_address = e1000_set_mac,
6101 .ndo_change_mtu = e1000_change_mtu,
6102 .ndo_do_ioctl = e1000_ioctl,
6103 .ndo_tx_timeout = e1000_tx_timeout,
6104 .ndo_validate_addr = eth_validate_addr,
6106 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6107 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6108 #ifdef CONFIG_NET_POLL_CONTROLLER
6109 .ndo_poll_controller = e1000_netpoll,
6111 .ndo_set_features = e1000_set_features,
6115 * e1000_probe - Device Initialization Routine
6116 * @pdev: PCI device information struct
6117 * @ent: entry in e1000_pci_tbl
6119 * Returns 0 on success, negative on failure
6121 * e1000_probe initializes an adapter identified by a pci_dev structure.
6122 * The OS initialization, configuring of the adapter private structure,
6123 * and a hardware reset occur.
6125 static int __devinit e1000_probe(struct pci_dev *pdev,
6126 const struct pci_device_id *ent)
6128 struct net_device *netdev;
6129 struct e1000_adapter *adapter;
6130 struct e1000_hw *hw;
6131 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
6132 resource_size_t mmio_start, mmio_len;
6133 resource_size_t flash_start, flash_len;
6134 static int cards_found;
6135 u16 aspm_disable_flag = 0;
6136 int i, err, pci_using_dac;
6137 u16 eeprom_data = 0;
6138 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6140 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6141 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6142 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
6143 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6144 if (aspm_disable_flag)
6145 e1000e_disable_aspm(pdev, aspm_disable_flag);
6147 err = pci_enable_device_mem(pdev);
6152 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
6154 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
6158 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
6160 err = dma_set_coherent_mask(&pdev->dev,
6163 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
6169 err = pci_request_selected_regions_exclusive(pdev,
6170 pci_select_bars(pdev, IORESOURCE_MEM),
6171 e1000e_driver_name);
6175 /* AER (Advanced Error Reporting) hooks */
6176 pci_enable_pcie_error_reporting(pdev);
6178 pci_set_master(pdev);
6179 /* PCI config space info */
6180 err = pci_save_state(pdev);
6182 goto err_alloc_etherdev;
6185 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6187 goto err_alloc_etherdev;
6189 SET_NETDEV_DEV(netdev, &pdev->dev);
6191 netdev->irq = pdev->irq;
6193 pci_set_drvdata(pdev, netdev);
6194 adapter = netdev_priv(netdev);
6196 adapter->netdev = netdev;
6197 adapter->pdev = pdev;
6199 adapter->pba = ei->pba;
6200 adapter->flags = ei->flags;
6201 adapter->flags2 = ei->flags2;
6202 adapter->hw.adapter = adapter;
6203 adapter->hw.mac.type = ei->mac;
6204 adapter->max_hw_frame_size = ei->max_hw_frame_size;
6205 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
6207 mmio_start = pci_resource_start(pdev, 0);
6208 mmio_len = pci_resource_len(pdev, 0);
6211 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6212 if (!adapter->hw.hw_addr)
6215 if ((adapter->flags & FLAG_HAS_FLASH) &&
6216 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6217 flash_start = pci_resource_start(pdev, 1);
6218 flash_len = pci_resource_len(pdev, 1);
6219 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6220 if (!adapter->hw.flash_address)
6224 /* construct the net_device struct */
6225 netdev->netdev_ops = &e1000e_netdev_ops;
6226 e1000e_set_ethtool_ops(netdev);
6227 netdev->watchdog_timeo = 5 * HZ;
6228 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
6229 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
6231 netdev->mem_start = mmio_start;
6232 netdev->mem_end = mmio_start + mmio_len;
6234 adapter->bd_number = cards_found++;
6236 e1000e_check_options(adapter);
6238 /* setup adapter struct */
6239 err = e1000_sw_init(adapter);
6243 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6244 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6245 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6247 err = ei->get_variants(adapter);
6251 if ((adapter->flags & FLAG_IS_ICH) &&
6252 (adapter->flags & FLAG_READ_ONLY_NVM))
6253 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6255 hw->mac.ops.get_bus_info(&adapter->hw);
6257 adapter->hw.phy.autoneg_wait_to_complete = 0;
6259 /* Copper options */
6260 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
6261 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6262 adapter->hw.phy.disable_polarity_correction = 0;
6263 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6266 if (hw->phy.ops.check_reset_block(hw))
6267 e_info("PHY reset is blocked due to SOL/IDER session.\n");
6269 /* Set initial default active device features */
6270 netdev->features = (NETIF_F_SG |
6271 NETIF_F_HW_VLAN_RX |
6272 NETIF_F_HW_VLAN_TX |
6279 /* Set user-changeable features (subset of all device features) */
6280 netdev->hw_features = netdev->features;
6281 netdev->hw_features |= NETIF_F_RXFCS;
6282 netdev->priv_flags |= IFF_SUPP_NOFCS;
6283 netdev->hw_features |= NETIF_F_RXALL;
6285 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6286 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6288 netdev->vlan_features |= (NETIF_F_SG |
6293 netdev->priv_flags |= IFF_UNICAST_FLT;
6295 if (pci_using_dac) {
6296 netdev->features |= NETIF_F_HIGHDMA;
6297 netdev->vlan_features |= NETIF_F_HIGHDMA;
6300 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6301 adapter->flags |= FLAG_MNG_PT_ENABLED;
6304 * before reading the NVM, reset the controller to
6305 * put the device in a known good starting state
6307 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6310 * systems with ASPM and others may see the checksum fail on the first
6311 * attempt. Let's give it a few tries
6314 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6317 e_err("The NVM Checksum Is Not Valid\n");
6323 e1000_eeprom_checks(adapter);
6325 /* copy the MAC address */
6326 if (e1000e_read_mac_addr(&adapter->hw))
6327 e_err("NVM Read Error while reading MAC address\n");
6329 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6330 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6332 if (!is_valid_ether_addr(netdev->perm_addr)) {
6333 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
6338 init_timer(&adapter->watchdog_timer);
6339 adapter->watchdog_timer.function = e1000_watchdog;
6340 adapter->watchdog_timer.data = (unsigned long) adapter;
6342 init_timer(&adapter->phy_info_timer);
6343 adapter->phy_info_timer.function = e1000_update_phy_info;
6344 adapter->phy_info_timer.data = (unsigned long) adapter;
6346 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6347 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
6348 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6349 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
6350 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
6352 /* Initialize link parameters. User can change them with ethtool */
6353 adapter->hw.mac.autoneg = 1;
6354 adapter->fc_autoneg = true;
6355 adapter->hw.fc.requested_mode = e1000_fc_default;
6356 adapter->hw.fc.current_mode = e1000_fc_default;
6357 adapter->hw.phy.autoneg_advertised = 0x2f;
6359 /* ring size defaults */
6360 adapter->rx_ring->count = 256;
6361 adapter->tx_ring->count = 256;
6364 * Initial Wake on LAN setting - If APM wake is enabled in
6365 * the EEPROM, enable the ACPI Magic Packet filter
6367 if (adapter->flags & FLAG_APME_IN_WUC) {
6368 /* APME bit in EEPROM is mapped to WUC.APME */
6369 eeprom_data = er32(WUC);
6370 eeprom_apme_mask = E1000_WUC_APME;
6371 if ((hw->mac.type > e1000_ich10lan) &&
6372 (eeprom_data & E1000_WUC_PHY_WAKE))
6373 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
6374 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6375 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6376 (adapter->hw.bus.func == 1))
6377 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6380 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6384 /* fetch WoL from EEPROM */
6385 if (eeprom_data & eeprom_apme_mask)
6386 adapter->eeprom_wol |= E1000_WUFC_MAG;
6389 * now that we have the eeprom settings, apply the special cases
6390 * where the eeprom may be wrong or the board simply won't support
6391 * wake on lan on a particular port
6393 if (!(adapter->flags & FLAG_HAS_WOL))
6394 adapter->eeprom_wol = 0;
6396 /* initialize the wol settings based on the eeprom settings */
6397 adapter->wol = adapter->eeprom_wol;
6398 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
6400 /* save off EEPROM version number */
6401 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6403 /* reset the hardware with the new settings */
6404 e1000e_reset(adapter);
6407 * If the controller has AMT, do not set DRV_LOAD until the interface
6408 * is up. For all other cases, let the f/w know that the h/w is now
6409 * under the control of the driver.
6411 if (!(adapter->flags & FLAG_HAS_AMT))
6412 e1000e_get_hw_control(adapter);
6414 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
6415 err = register_netdev(netdev);
6419 /* carrier off reporting is important to ethtool even BEFORE open */
6420 netif_carrier_off(netdev);
6422 e1000_print_device_info(adapter);
6424 if (pci_dev_run_wake(pdev))
6425 pm_runtime_put_noidle(&pdev->dev);
6430 if (!(adapter->flags & FLAG_HAS_AMT))
6431 e1000e_release_hw_control(adapter);
6433 if (!hw->phy.ops.check_reset_block(hw))
6434 e1000_phy_hw_reset(&adapter->hw);
6436 kfree(adapter->tx_ring);
6437 kfree(adapter->rx_ring);
6439 if (adapter->hw.flash_address)
6440 iounmap(adapter->hw.flash_address);
6441 e1000e_reset_interrupt_capability(adapter);
6443 iounmap(adapter->hw.hw_addr);
6445 free_netdev(netdev);
6447 pci_release_selected_regions(pdev,
6448 pci_select_bars(pdev, IORESOURCE_MEM));
6451 pci_disable_device(pdev);
6456 * e1000_remove - Device Removal Routine
6457 * @pdev: PCI device information struct
6459 * e1000_remove is called by the PCI subsystem to alert the driver
6460 * that it should release a PCI device. The could be caused by a
6461 * Hot-Plug event, or because the driver is going to be removed from
6464 static void __devexit e1000_remove(struct pci_dev *pdev)
6466 struct net_device *netdev = pci_get_drvdata(pdev);
6467 struct e1000_adapter *adapter = netdev_priv(netdev);
6468 bool down = test_bit(__E1000_DOWN, &adapter->state);
6471 * The timers may be rescheduled, so explicitly disable them
6472 * from being rescheduled.
6475 set_bit(__E1000_DOWN, &adapter->state);
6476 del_timer_sync(&adapter->watchdog_timer);
6477 del_timer_sync(&adapter->phy_info_timer);
6479 cancel_work_sync(&adapter->reset_task);
6480 cancel_work_sync(&adapter->watchdog_task);
6481 cancel_work_sync(&adapter->downshift_task);
6482 cancel_work_sync(&adapter->update_phy_task);
6483 cancel_work_sync(&adapter->print_hang_task);
6485 if (!(netdev->flags & IFF_UP))
6486 e1000_power_down_phy(adapter);
6488 /* Don't lie to e1000_close() down the road. */
6490 clear_bit(__E1000_DOWN, &adapter->state);
6491 unregister_netdev(netdev);
6493 if (pci_dev_run_wake(pdev))
6494 pm_runtime_get_noresume(&pdev->dev);
6497 * Release control of h/w to f/w. If f/w is AMT enabled, this
6498 * would have already happened in close and is redundant.
6500 e1000e_release_hw_control(adapter);
6502 e1000e_reset_interrupt_capability(adapter);
6503 kfree(adapter->tx_ring);
6504 kfree(adapter->rx_ring);
6506 iounmap(adapter->hw.hw_addr);
6507 if (adapter->hw.flash_address)
6508 iounmap(adapter->hw.flash_address);
6509 pci_release_selected_regions(pdev,
6510 pci_select_bars(pdev, IORESOURCE_MEM));
6512 free_netdev(netdev);
6515 pci_disable_pcie_error_reporting(pdev);
6517 pci_disable_device(pdev);
6520 /* PCI Error Recovery (ERS) */
6521 static struct pci_error_handlers e1000_err_handler = {
6522 .error_detected = e1000_io_error_detected,
6523 .slot_reset = e1000_io_slot_reset,
6524 .resume = e1000_io_resume,
6527 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
6528 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6529 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6530 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6531 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6532 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6533 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
6534 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6535 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6536 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
6538 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6539 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6540 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6541 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
6543 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6544 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6545 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
6547 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
6548 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
6549 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
6551 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6552 board_80003es2lan },
6553 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6554 board_80003es2lan },
6555 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6556 board_80003es2lan },
6557 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6558 board_80003es2lan },
6560 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6561 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6562 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6563 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6564 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6565 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6566 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
6567 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
6569 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6570 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6571 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6572 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6573 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
6574 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
6575 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6576 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6577 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6579 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6580 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6581 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
6583 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6584 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
6585 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
6587 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6588 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6589 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6590 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6592 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6593 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6595 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
6597 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6600 static const struct dev_pm_ops e1000_pm_ops = {
6601 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6602 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6603 e1000_runtime_resume, e1000_idle)
6607 /* PCI Device API Driver */
6608 static struct pci_driver e1000_driver = {
6609 .name = e1000e_driver_name,
6610 .id_table = e1000_pci_tbl,
6611 .probe = e1000_probe,
6612 .remove = __devexit_p(e1000_remove),
6615 .pm = &e1000_pm_ops,
6618 .shutdown = e1000_shutdown,
6619 .err_handler = &e1000_err_handler
6623 * e1000_init_module - Driver Registration Routine
6625 * e1000_init_module is the first routine called when the driver is
6626 * loaded. All it does is register with the PCI subsystem.
6628 static int __init e1000_init_module(void)
6631 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6632 e1000e_driver_version);
6633 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
6634 ret = pci_register_driver(&e1000_driver);
6638 module_init(e1000_init_module);
6641 * e1000_exit_module - Driver Exit Cleanup Routine
6643 * e1000_exit_module is called just before the driver is removed
6646 static void __exit e1000_exit_module(void)
6648 pci_unregister_driver(&e1000_driver);
6650 module_exit(e1000_exit_module);
6653 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6654 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6655 MODULE_LICENSE("GPL");
6656 MODULE_VERSION(DRV_VERSION);