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.9.5" DRV_EXTRAVERSION
60 char e1000e_driver_name[] = "e1000e";
61 const char e1000e_driver_version[] = DRV_VERSION;
63 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
65 static const struct e1000_info *e1000_info_tbl[] = {
66 [board_82571] = &e1000_82571_info,
67 [board_82572] = &e1000_82572_info,
68 [board_82573] = &e1000_82573_info,
69 [board_82574] = &e1000_82574_info,
70 [board_82583] = &e1000_82583_info,
71 [board_80003es2lan] = &e1000_es2_info,
72 [board_ich8lan] = &e1000_ich8_info,
73 [board_ich9lan] = &e1000_ich9_info,
74 [board_ich10lan] = &e1000_ich10_info,
75 [board_pchlan] = &e1000_pch_info,
76 [board_pch2lan] = &e1000_pch2_info,
79 struct e1000_reg_info {
84 #define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
85 #define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
86 #define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
87 #define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
88 #define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
90 #define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
91 #define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
92 #define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
93 #define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
94 #define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
96 static const struct e1000_reg_info e1000_reg_info_tbl[] = {
98 /* General Registers */
100 {E1000_STATUS, "STATUS"},
101 {E1000_CTRL_EXT, "CTRL_EXT"},
103 /* Interrupt Registers */
107 {E1000_RCTL, "RCTL"},
108 {E1000_RDLEN, "RDLEN"},
111 {E1000_RDTR, "RDTR"},
112 {E1000_RXDCTL(0), "RXDCTL"},
114 {E1000_RDBAL, "RDBAL"},
115 {E1000_RDBAH, "RDBAH"},
116 {E1000_RDFH, "RDFH"},
117 {E1000_RDFT, "RDFT"},
118 {E1000_RDFHS, "RDFHS"},
119 {E1000_RDFTS, "RDFTS"},
120 {E1000_RDFPC, "RDFPC"},
123 {E1000_TCTL, "TCTL"},
124 {E1000_TDBAL, "TDBAL"},
125 {E1000_TDBAH, "TDBAH"},
126 {E1000_TDLEN, "TDLEN"},
129 {E1000_TIDV, "TIDV"},
130 {E1000_TXDCTL(0), "TXDCTL"},
131 {E1000_TADV, "TADV"},
132 {E1000_TARC(0), "TARC"},
133 {E1000_TDFH, "TDFH"},
134 {E1000_TDFT, "TDFT"},
135 {E1000_TDFHS, "TDFHS"},
136 {E1000_TDFTS, "TDFTS"},
137 {E1000_TDFPC, "TDFPC"},
139 /* List Terminator */
144 * e1000_regdump - register printout routine
146 static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
152 switch (reginfo->ofs) {
153 case E1000_RXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_RXDCTL(n));
157 case E1000_TXDCTL(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TXDCTL(n));
162 for (n = 0; n < 2; n++)
163 regs[n] = __er32(hw, E1000_TARC(n));
166 pr_info("%-15s %08x\n",
167 reginfo->name, __er32(hw, reginfo->ofs));
171 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
172 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
176 * e1000e_dump - Print registers, Tx-ring and Rx-ring
178 static void e1000e_dump(struct e1000_adapter *adapter)
180 struct net_device *netdev = adapter->netdev;
181 struct e1000_hw *hw = &adapter->hw;
182 struct e1000_reg_info *reginfo;
183 struct e1000_ring *tx_ring = adapter->tx_ring;
184 struct e1000_tx_desc *tx_desc;
189 struct e1000_buffer *buffer_info;
190 struct e1000_ring *rx_ring = adapter->rx_ring;
191 union e1000_rx_desc_packet_split *rx_desc_ps;
192 union e1000_rx_desc_extended *rx_desc;
202 if (!netif_msg_hw(adapter))
205 /* Print netdevice Info */
207 dev_info(&adapter->pdev->dev, "Net device Info\n");
208 pr_info("Device Name state trans_start last_rx\n");
209 pr_info("%-15s %016lX %016lX %016lX\n",
210 netdev->name, netdev->state, netdev->trans_start,
214 /* Print Registers */
215 dev_info(&adapter->pdev->dev, "Register Dump\n");
216 pr_info(" Register Name Value\n");
217 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
218 reginfo->name; reginfo++) {
219 e1000_regdump(hw, reginfo);
222 /* Print Tx Ring Summary */
223 if (!netdev || !netif_running(netdev))
226 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
227 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
228 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
229 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
230 0, tx_ring->next_to_use, tx_ring->next_to_clean,
231 (unsigned long long)buffer_info->dma,
233 buffer_info->next_to_watch,
234 (unsigned long long)buffer_info->time_stamp);
237 if (!netif_msg_tx_done(adapter))
238 goto rx_ring_summary;
240 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
242 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
244 * Legacy Transmit Descriptor
245 * +--------------------------------------------------------------+
246 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
247 * +--------------------------------------------------------------+
248 * 8 | Special | CSS | Status | CMD | CSO | Length |
249 * +--------------------------------------------------------------+
250 * 63 48 47 36 35 32 31 24 23 16 15 0
252 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
253 * 63 48 47 40 39 32 31 16 15 8 7 0
254 * +----------------------------------------------------------------+
255 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
256 * +----------------------------------------------------------------+
257 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
258 * +----------------------------------------------------------------+
259 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
261 * Extended Data Descriptor (DTYP=0x1)
262 * +----------------------------------------------------------------+
263 * 0 | Buffer Address [63:0] |
264 * +----------------------------------------------------------------+
265 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
266 * +----------------------------------------------------------------+
267 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
269 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
270 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
271 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
272 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
273 const char *next_desc;
274 tx_desc = E1000_TX_DESC(*tx_ring, i);
275 buffer_info = &tx_ring->buffer_info[i];
276 u0 = (struct my_u0 *)tx_desc;
277 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
278 next_desc = " NTC/U";
279 else if (i == tx_ring->next_to_use)
281 else if (i == tx_ring->next_to_clean)
285 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
286 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
287 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
289 (unsigned long long)le64_to_cpu(u0->a),
290 (unsigned long long)le64_to_cpu(u0->b),
291 (unsigned long long)buffer_info->dma,
292 buffer_info->length, buffer_info->next_to_watch,
293 (unsigned long long)buffer_info->time_stamp,
294 buffer_info->skb, next_desc);
296 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
297 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
298 16, 1, phys_to_virt(buffer_info->dma),
299 buffer_info->length, true);
302 /* Print Rx Ring Summary */
304 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
305 pr_info("Queue [NTU] [NTC]\n");
306 pr_info(" %5d %5X %5X\n",
307 0, rx_ring->next_to_use, rx_ring->next_to_clean);
310 if (!netif_msg_rx_status(adapter))
313 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
314 switch (adapter->rx_ps_pages) {
318 /* [Extended] Packet Split Receive Descriptor Format
320 * +-----------------------------------------------------+
321 * 0 | Buffer Address 0 [63:0] |
322 * +-----------------------------------------------------+
323 * 8 | Buffer Address 1 [63:0] |
324 * +-----------------------------------------------------+
325 * 16 | Buffer Address 2 [63:0] |
326 * +-----------------------------------------------------+
327 * 24 | Buffer Address 3 [63:0] |
328 * +-----------------------------------------------------+
330 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");
331 /* [Extended] Receive Descriptor (Write-Back) Format
333 * 63 48 47 32 31 13 12 8 7 4 3 0
334 * +------------------------------------------------------+
335 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
336 * | Checksum | Ident | | Queue | | Type |
337 * +------------------------------------------------------+
338 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
339 * +------------------------------------------------------+
340 * 63 48 47 32 31 20 19 0
342 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
343 for (i = 0; i < rx_ring->count; i++) {
344 const char *next_desc;
345 buffer_info = &rx_ring->buffer_info[i];
346 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
347 u1 = (struct my_u1 *)rx_desc_ps;
349 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
351 if (i == rx_ring->next_to_use)
353 else if (i == rx_ring->next_to_clean)
358 if (staterr & E1000_RXD_STAT_DD) {
359 /* Descriptor Done */
360 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
362 (unsigned long long)le64_to_cpu(u1->a),
363 (unsigned long long)le64_to_cpu(u1->b),
364 (unsigned long long)le64_to_cpu(u1->c),
365 (unsigned long long)le64_to_cpu(u1->d),
366 buffer_info->skb, next_desc);
368 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
370 (unsigned long long)le64_to_cpu(u1->a),
371 (unsigned long long)le64_to_cpu(u1->b),
372 (unsigned long long)le64_to_cpu(u1->c),
373 (unsigned long long)le64_to_cpu(u1->d),
374 (unsigned long long)buffer_info->dma,
375 buffer_info->skb, next_desc);
377 if (netif_msg_pktdata(adapter))
378 print_hex_dump(KERN_INFO, "",
379 DUMP_PREFIX_ADDRESS, 16, 1,
380 phys_to_virt(buffer_info->dma),
381 adapter->rx_ps_bsize0, true);
387 /* Extended Receive Descriptor (Read) Format
389 * +-----------------------------------------------------+
390 * 0 | Buffer Address [63:0] |
391 * +-----------------------------------------------------+
393 * +-----------------------------------------------------+
395 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
396 /* Extended Receive Descriptor (Write-Back) Format
398 * 63 48 47 32 31 24 23 4 3 0
399 * +------------------------------------------------------+
401 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
402 * | Packet | IP | | | Type |
403 * | Checksum | Ident | | | |
404 * +------------------------------------------------------+
405 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
406 * +------------------------------------------------------+
407 * 63 48 47 32 31 20 19 0
409 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
411 for (i = 0; i < rx_ring->count; i++) {
412 const char *next_desc;
414 buffer_info = &rx_ring->buffer_info[i];
415 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
416 u1 = (struct my_u1 *)rx_desc;
417 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
419 if (i == rx_ring->next_to_use)
421 else if (i == rx_ring->next_to_clean)
426 if (staterr & E1000_RXD_STAT_DD) {
427 /* Descriptor Done */
428 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
430 (unsigned long long)le64_to_cpu(u1->a),
431 (unsigned long long)le64_to_cpu(u1->b),
432 buffer_info->skb, next_desc);
434 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
436 (unsigned long long)le64_to_cpu(u1->a),
437 (unsigned long long)le64_to_cpu(u1->b),
438 (unsigned long long)buffer_info->dma,
439 buffer_info->skb, next_desc);
441 if (netif_msg_pktdata(adapter))
442 print_hex_dump(KERN_INFO, "",
443 DUMP_PREFIX_ADDRESS, 16,
447 adapter->rx_buffer_len,
455 * e1000_desc_unused - calculate if we have unused descriptors
457 static int e1000_desc_unused(struct e1000_ring *ring)
459 if (ring->next_to_clean > ring->next_to_use)
460 return ring->next_to_clean - ring->next_to_use - 1;
462 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
466 * e1000_receive_skb - helper function to handle Rx indications
467 * @adapter: board private structure
468 * @status: descriptor status field as written by hardware
469 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
470 * @skb: pointer to sk_buff to be indicated to stack
472 static void e1000_receive_skb(struct e1000_adapter *adapter,
473 struct net_device *netdev, struct sk_buff *skb,
474 u8 status, __le16 vlan)
476 u16 tag = le16_to_cpu(vlan);
477 skb->protocol = eth_type_trans(skb, netdev);
479 if (status & E1000_RXD_STAT_VP)
480 __vlan_hwaccel_put_tag(skb, tag);
482 napi_gro_receive(&adapter->napi, skb);
486 * e1000_rx_checksum - Receive Checksum Offload
487 * @adapter: board private structure
488 * @status_err: receive descriptor status and error fields
489 * @csum: receive descriptor csum field
490 * @sk_buff: socket buffer with received data
492 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
493 __le16 csum, struct sk_buff *skb)
495 u16 status = (u16)status_err;
496 u8 errors = (u8)(status_err >> 24);
498 skb_checksum_none_assert(skb);
500 /* Rx checksum disabled */
501 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
504 /* Ignore Checksum bit is set */
505 if (status & E1000_RXD_STAT_IXSM)
508 /* TCP/UDP checksum error bit is set */
509 if (errors & E1000_RXD_ERR_TCPE) {
510 /* let the stack verify checksum errors */
511 adapter->hw_csum_err++;
515 /* TCP/UDP Checksum has not been calculated */
516 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
519 /* It must be a TCP or UDP packet with a valid checksum */
520 if (status & E1000_RXD_STAT_TCPCS) {
521 /* TCP checksum is good */
522 skb->ip_summed = CHECKSUM_UNNECESSARY;
525 * IP fragment with UDP payload
526 * Hardware complements the payload checksum, so we undo it
527 * and then put the value in host order for further stack use.
529 __sum16 sum = (__force __sum16)swab16((__force u16)csum);
530 skb->csum = csum_unfold(~sum);
531 skb->ip_summed = CHECKSUM_COMPLETE;
533 adapter->hw_csum_good++;
537 * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa()
538 * @hw: pointer to the HW structure
539 * @tail: address of tail descriptor register
540 * @i: value to write to tail descriptor register
542 * When updating the tail register, the ME could be accessing Host CSR
543 * registers at the same time. Normally, this is handled in h/w by an
544 * arbiter but on some parts there is a bug that acknowledges Host accesses
545 * later than it should which could result in the descriptor register to
546 * have an incorrect value. Workaround this by checking the FWSM register
547 * which has bit 24 set while ME is accessing Host CSR registers, wait
548 * if it is set and try again a number of times.
550 static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, void __iomem *tail,
555 while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) &&
556 (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI))
561 if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail)))
562 return E1000_ERR_SWFW_SYNC;
567 static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
569 struct e1000_adapter *adapter = rx_ring->adapter;
570 struct e1000_hw *hw = &adapter->hw;
572 if (e1000e_update_tail_wa(hw, rx_ring->tail, i)) {
573 u32 rctl = er32(RCTL);
574 ew32(RCTL, rctl & ~E1000_RCTL_EN);
575 e_err("ME firmware caused invalid RDT - resetting\n");
576 schedule_work(&adapter->reset_task);
580 static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
582 struct e1000_adapter *adapter = tx_ring->adapter;
583 struct e1000_hw *hw = &adapter->hw;
585 if (e1000e_update_tail_wa(hw, tx_ring->tail, i)) {
586 u32 tctl = er32(TCTL);
587 ew32(TCTL, tctl & ~E1000_TCTL_EN);
588 e_err("ME firmware caused invalid TDT - resetting\n");
589 schedule_work(&adapter->reset_task);
594 * e1000_alloc_rx_buffers - Replace used receive buffers
595 * @rx_ring: Rx descriptor ring
597 static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
598 int cleaned_count, gfp_t gfp)
600 struct e1000_adapter *adapter = rx_ring->adapter;
601 struct net_device *netdev = adapter->netdev;
602 struct pci_dev *pdev = adapter->pdev;
603 union e1000_rx_desc_extended *rx_desc;
604 struct e1000_buffer *buffer_info;
607 unsigned int bufsz = adapter->rx_buffer_len;
609 i = rx_ring->next_to_use;
610 buffer_info = &rx_ring->buffer_info[i];
612 while (cleaned_count--) {
613 skb = buffer_info->skb;
619 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
621 /* Better luck next round */
622 adapter->alloc_rx_buff_failed++;
626 buffer_info->skb = skb;
628 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
629 adapter->rx_buffer_len,
631 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
632 dev_err(&pdev->dev, "Rx DMA map failed\n");
633 adapter->rx_dma_failed++;
637 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
638 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
640 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
642 * Force memory writes to complete before letting h/w
643 * know there are new descriptors to fetch. (Only
644 * applicable for weak-ordered memory model archs,
648 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
649 e1000e_update_rdt_wa(rx_ring, i);
651 writel(i, rx_ring->tail);
654 if (i == rx_ring->count)
656 buffer_info = &rx_ring->buffer_info[i];
659 rx_ring->next_to_use = i;
663 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
664 * @rx_ring: Rx descriptor ring
666 static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
667 int cleaned_count, gfp_t gfp)
669 struct e1000_adapter *adapter = rx_ring->adapter;
670 struct net_device *netdev = adapter->netdev;
671 struct pci_dev *pdev = adapter->pdev;
672 union e1000_rx_desc_packet_split *rx_desc;
673 struct e1000_buffer *buffer_info;
674 struct e1000_ps_page *ps_page;
678 i = rx_ring->next_to_use;
679 buffer_info = &rx_ring->buffer_info[i];
681 while (cleaned_count--) {
682 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
684 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
685 ps_page = &buffer_info->ps_pages[j];
686 if (j >= adapter->rx_ps_pages) {
687 /* all unused desc entries get hw null ptr */
688 rx_desc->read.buffer_addr[j + 1] =
692 if (!ps_page->page) {
693 ps_page->page = alloc_page(gfp);
694 if (!ps_page->page) {
695 adapter->alloc_rx_buff_failed++;
698 ps_page->dma = dma_map_page(&pdev->dev,
702 if (dma_mapping_error(&pdev->dev,
704 dev_err(&adapter->pdev->dev,
705 "Rx DMA page map failed\n");
706 adapter->rx_dma_failed++;
711 * Refresh the desc even if buffer_addrs
712 * didn't change because each write-back
715 rx_desc->read.buffer_addr[j + 1] =
716 cpu_to_le64(ps_page->dma);
719 skb = __netdev_alloc_skb_ip_align(netdev,
720 adapter->rx_ps_bsize0,
724 adapter->alloc_rx_buff_failed++;
728 buffer_info->skb = skb;
729 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
730 adapter->rx_ps_bsize0,
732 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
733 dev_err(&pdev->dev, "Rx DMA map failed\n");
734 adapter->rx_dma_failed++;
736 dev_kfree_skb_any(skb);
737 buffer_info->skb = NULL;
741 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
743 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
745 * Force memory writes to complete before letting h/w
746 * know there are new descriptors to fetch. (Only
747 * applicable for weak-ordered memory model archs,
751 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
752 e1000e_update_rdt_wa(rx_ring, i << 1);
754 writel(i << 1, rx_ring->tail);
758 if (i == rx_ring->count)
760 buffer_info = &rx_ring->buffer_info[i];
764 rx_ring->next_to_use = i;
768 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
769 * @rx_ring: Rx descriptor ring
770 * @cleaned_count: number of buffers to allocate this pass
773 static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
774 int cleaned_count, gfp_t gfp)
776 struct e1000_adapter *adapter = rx_ring->adapter;
777 struct net_device *netdev = adapter->netdev;
778 struct pci_dev *pdev = adapter->pdev;
779 union e1000_rx_desc_extended *rx_desc;
780 struct e1000_buffer *buffer_info;
783 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
785 i = rx_ring->next_to_use;
786 buffer_info = &rx_ring->buffer_info[i];
788 while (cleaned_count--) {
789 skb = buffer_info->skb;
795 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
796 if (unlikely(!skb)) {
797 /* Better luck next round */
798 adapter->alloc_rx_buff_failed++;
802 buffer_info->skb = skb;
804 /* allocate a new page if necessary */
805 if (!buffer_info->page) {
806 buffer_info->page = alloc_page(gfp);
807 if (unlikely(!buffer_info->page)) {
808 adapter->alloc_rx_buff_failed++;
813 if (!buffer_info->dma)
814 buffer_info->dma = dma_map_page(&pdev->dev,
815 buffer_info->page, 0,
819 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
820 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
822 if (unlikely(++i == rx_ring->count))
824 buffer_info = &rx_ring->buffer_info[i];
827 if (likely(rx_ring->next_to_use != i)) {
828 rx_ring->next_to_use = i;
829 if (unlikely(i-- == 0))
830 i = (rx_ring->count - 1);
832 /* Force memory writes to complete before letting h/w
833 * know there are new descriptors to fetch. (Only
834 * applicable for weak-ordered memory model archs,
837 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
838 e1000e_update_rdt_wa(rx_ring, i);
840 writel(i, rx_ring->tail);
844 static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
847 if (netdev->features & NETIF_F_RXHASH)
848 skb->rxhash = le32_to_cpu(rss);
852 * e1000_clean_rx_irq - Send received data up the network stack
853 * @rx_ring: Rx descriptor ring
855 * the return value indicates whether actual cleaning was done, there
856 * is no guarantee that everything was cleaned
858 static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
861 struct e1000_adapter *adapter = rx_ring->adapter;
862 struct net_device *netdev = adapter->netdev;
863 struct pci_dev *pdev = adapter->pdev;
864 struct e1000_hw *hw = &adapter->hw;
865 union e1000_rx_desc_extended *rx_desc, *next_rxd;
866 struct e1000_buffer *buffer_info, *next_buffer;
869 int cleaned_count = 0;
870 bool cleaned = false;
871 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
873 i = rx_ring->next_to_clean;
874 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
875 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
876 buffer_info = &rx_ring->buffer_info[i];
878 while (staterr & E1000_RXD_STAT_DD) {
881 if (*work_done >= work_to_do)
884 rmb(); /* read descriptor and rx_buffer_info after status DD */
886 skb = buffer_info->skb;
887 buffer_info->skb = NULL;
889 prefetch(skb->data - NET_IP_ALIGN);
892 if (i == rx_ring->count)
894 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
897 next_buffer = &rx_ring->buffer_info[i];
901 dma_unmap_single(&pdev->dev,
903 adapter->rx_buffer_len,
905 buffer_info->dma = 0;
907 length = le16_to_cpu(rx_desc->wb.upper.length);
910 * !EOP means multiple descriptors were used to store a single
911 * packet, if that's the case we need to toss it. In fact, we
912 * need to toss every packet with the EOP bit clear and the
913 * next frame that _does_ have the EOP bit set, as it is by
914 * definition only a frame fragment
916 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
917 adapter->flags2 |= FLAG2_IS_DISCARDING;
919 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
920 /* All receives must fit into a single buffer */
921 e_dbg("Receive packet consumed multiple buffers\n");
923 buffer_info->skb = skb;
924 if (staterr & E1000_RXD_STAT_EOP)
925 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
929 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
930 !(netdev->features & NETIF_F_RXALL))) {
932 buffer_info->skb = skb;
936 /* adjust length to remove Ethernet CRC */
937 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
938 /* If configured to store CRC, don't subtract FCS,
939 * but keep the FCS bytes out of the total_rx_bytes
942 if (netdev->features & NETIF_F_RXFCS)
948 total_rx_bytes += length;
952 * code added for copybreak, this should improve
953 * performance for small packets with large amounts
954 * of reassembly being done in the stack
956 if (length < copybreak) {
957 struct sk_buff *new_skb =
958 netdev_alloc_skb_ip_align(netdev, length);
960 skb_copy_to_linear_data_offset(new_skb,
966 /* save the skb in buffer_info as good */
967 buffer_info->skb = skb;
970 /* else just continue with the old one */
972 /* end copybreak code */
973 skb_put(skb, length);
975 /* Receive Checksum Offload */
976 e1000_rx_checksum(adapter, staterr,
977 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
979 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
981 e1000_receive_skb(adapter, netdev, skb, staterr,
982 rx_desc->wb.upper.vlan);
985 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
987 /* return some buffers to hardware, one at a time is too slow */
988 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
989 adapter->alloc_rx_buf(rx_ring, cleaned_count,
994 /* use prefetched values */
996 buffer_info = next_buffer;
998 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1000 rx_ring->next_to_clean = i;
1002 cleaned_count = e1000_desc_unused(rx_ring);
1004 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1006 adapter->total_rx_bytes += total_rx_bytes;
1007 adapter->total_rx_packets += total_rx_packets;
1011 static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1012 struct e1000_buffer *buffer_info)
1014 struct e1000_adapter *adapter = tx_ring->adapter;
1016 if (buffer_info->dma) {
1017 if (buffer_info->mapped_as_page)
1018 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1019 buffer_info->length, DMA_TO_DEVICE);
1021 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1022 buffer_info->length, DMA_TO_DEVICE);
1023 buffer_info->dma = 0;
1025 if (buffer_info->skb) {
1026 dev_kfree_skb_any(buffer_info->skb);
1027 buffer_info->skb = NULL;
1029 buffer_info->time_stamp = 0;
1032 static void e1000_print_hw_hang(struct work_struct *work)
1034 struct e1000_adapter *adapter = container_of(work,
1035 struct e1000_adapter,
1037 struct net_device *netdev = adapter->netdev;
1038 struct e1000_ring *tx_ring = adapter->tx_ring;
1039 unsigned int i = tx_ring->next_to_clean;
1040 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1041 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
1042 struct e1000_hw *hw = &adapter->hw;
1043 u16 phy_status, phy_1000t_status, phy_ext_status;
1046 if (test_bit(__E1000_DOWN, &adapter->state))
1049 if (!adapter->tx_hang_recheck &&
1050 (adapter->flags2 & FLAG2_DMA_BURST)) {
1051 /* May be block on write-back, flush and detect again
1052 * flush pending descriptor writebacks to memory
1054 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1055 /* execute the writes immediately */
1057 adapter->tx_hang_recheck = true;
1060 /* Real hang detected */
1061 adapter->tx_hang_recheck = false;
1062 netif_stop_queue(netdev);
1064 e1e_rphy(hw, PHY_STATUS, &phy_status);
1065 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1066 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1068 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1070 /* detected Hardware unit hang */
1071 e_err("Detected Hardware Unit Hang:\n"
1074 " next_to_use <%x>\n"
1075 " next_to_clean <%x>\n"
1076 "buffer_info[next_to_clean]:\n"
1077 " time_stamp <%lx>\n"
1078 " next_to_watch <%x>\n"
1080 " next_to_watch.status <%x>\n"
1083 "PHY 1000BASE-T Status <%x>\n"
1084 "PHY Extended Status <%x>\n"
1085 "PCI Status <%x>\n",
1086 readl(tx_ring->head),
1087 readl(tx_ring->tail),
1088 tx_ring->next_to_use,
1089 tx_ring->next_to_clean,
1090 tx_ring->buffer_info[eop].time_stamp,
1093 eop_desc->upper.fields.status,
1102 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1103 * @tx_ring: Tx descriptor ring
1105 * the return value indicates whether actual cleaning was done, there
1106 * is no guarantee that everything was cleaned
1108 static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
1110 struct e1000_adapter *adapter = tx_ring->adapter;
1111 struct net_device *netdev = adapter->netdev;
1112 struct e1000_hw *hw = &adapter->hw;
1113 struct e1000_tx_desc *tx_desc, *eop_desc;
1114 struct e1000_buffer *buffer_info;
1115 unsigned int i, eop;
1116 unsigned int count = 0;
1117 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1118 unsigned int bytes_compl = 0, pkts_compl = 0;
1120 i = tx_ring->next_to_clean;
1121 eop = tx_ring->buffer_info[i].next_to_watch;
1122 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1124 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1125 (count < tx_ring->count)) {
1126 bool cleaned = false;
1127 rmb(); /* read buffer_info after eop_desc */
1128 for (; !cleaned; count++) {
1129 tx_desc = E1000_TX_DESC(*tx_ring, i);
1130 buffer_info = &tx_ring->buffer_info[i];
1131 cleaned = (i == eop);
1134 total_tx_packets += buffer_info->segs;
1135 total_tx_bytes += buffer_info->bytecount;
1136 if (buffer_info->skb) {
1137 bytes_compl += buffer_info->skb->len;
1142 e1000_put_txbuf(tx_ring, buffer_info);
1143 tx_desc->upper.data = 0;
1146 if (i == tx_ring->count)
1150 if (i == tx_ring->next_to_use)
1152 eop = tx_ring->buffer_info[i].next_to_watch;
1153 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1156 tx_ring->next_to_clean = i;
1158 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1160 #define TX_WAKE_THRESHOLD 32
1161 if (count && netif_carrier_ok(netdev) &&
1162 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
1163 /* Make sure that anybody stopping the queue after this
1164 * sees the new next_to_clean.
1168 if (netif_queue_stopped(netdev) &&
1169 !(test_bit(__E1000_DOWN, &adapter->state))) {
1170 netif_wake_queue(netdev);
1171 ++adapter->restart_queue;
1175 if (adapter->detect_tx_hung) {
1177 * Detect a transmit hang in hardware, this serializes the
1178 * check with the clearing of time_stamp and movement of i
1180 adapter->detect_tx_hung = false;
1181 if (tx_ring->buffer_info[i].time_stamp &&
1182 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
1183 + (adapter->tx_timeout_factor * HZ)) &&
1184 !(er32(STATUS) & E1000_STATUS_TXOFF))
1185 schedule_work(&adapter->print_hang_task);
1187 adapter->tx_hang_recheck = false;
1189 adapter->total_tx_bytes += total_tx_bytes;
1190 adapter->total_tx_packets += total_tx_packets;
1191 return count < tx_ring->count;
1195 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1196 * @rx_ring: Rx descriptor ring
1198 * the return value indicates whether actual cleaning was done, there
1199 * is no guarantee that everything was cleaned
1201 static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1204 struct e1000_adapter *adapter = rx_ring->adapter;
1205 struct e1000_hw *hw = &adapter->hw;
1206 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1207 struct net_device *netdev = adapter->netdev;
1208 struct pci_dev *pdev = adapter->pdev;
1209 struct e1000_buffer *buffer_info, *next_buffer;
1210 struct e1000_ps_page *ps_page;
1211 struct sk_buff *skb;
1213 u32 length, staterr;
1214 int cleaned_count = 0;
1215 bool cleaned = false;
1216 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1218 i = rx_ring->next_to_clean;
1219 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1220 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1221 buffer_info = &rx_ring->buffer_info[i];
1223 while (staterr & E1000_RXD_STAT_DD) {
1224 if (*work_done >= work_to_do)
1227 skb = buffer_info->skb;
1228 rmb(); /* read descriptor and rx_buffer_info after status DD */
1230 /* in the packet split case this is header only */
1231 prefetch(skb->data - NET_IP_ALIGN);
1234 if (i == rx_ring->count)
1236 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1239 next_buffer = &rx_ring->buffer_info[i];
1243 dma_unmap_single(&pdev->dev, buffer_info->dma,
1244 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
1245 buffer_info->dma = 0;
1247 /* see !EOP comment in other Rx routine */
1248 if (!(staterr & E1000_RXD_STAT_EOP))
1249 adapter->flags2 |= FLAG2_IS_DISCARDING;
1251 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
1252 e_dbg("Packet Split buffers didn't pick up the full packet\n");
1253 dev_kfree_skb_irq(skb);
1254 if (staterr & E1000_RXD_STAT_EOP)
1255 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1259 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1260 !(netdev->features & NETIF_F_RXALL))) {
1261 dev_kfree_skb_irq(skb);
1265 length = le16_to_cpu(rx_desc->wb.middle.length0);
1268 e_dbg("Last part of the packet spanning multiple descriptors\n");
1269 dev_kfree_skb_irq(skb);
1274 skb_put(skb, length);
1278 * this looks ugly, but it seems compiler issues make
1279 * it more efficient than reusing j
1281 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1284 * page alloc/put takes too long and effects small
1285 * packet throughput, so unsplit small packets and
1286 * save the alloc/put only valid in softirq (napi)
1287 * context to call kmap_*
1289 if (l1 && (l1 <= copybreak) &&
1290 ((length + l1) <= adapter->rx_ps_bsize0)) {
1293 ps_page = &buffer_info->ps_pages[0];
1296 * there is no documentation about how to call
1297 * kmap_atomic, so we can't hold the mapping
1300 dma_sync_single_for_cpu(&pdev->dev,
1304 vaddr = kmap_atomic(ps_page->page,
1305 KM_SKB_DATA_SOFTIRQ);
1306 memcpy(skb_tail_pointer(skb), vaddr, l1);
1307 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
1308 dma_sync_single_for_device(&pdev->dev,
1313 /* remove the CRC */
1314 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1315 if (!(netdev->features & NETIF_F_RXFCS))
1324 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1325 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1329 ps_page = &buffer_info->ps_pages[j];
1330 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1333 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1334 ps_page->page = NULL;
1336 skb->data_len += length;
1337 skb->truesize += PAGE_SIZE;
1340 /* strip the ethernet crc, problem is we're using pages now so
1341 * this whole operation can get a little cpu intensive
1343 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1344 if (!(netdev->features & NETIF_F_RXFCS))
1345 pskb_trim(skb, skb->len - 4);
1349 total_rx_bytes += skb->len;
1352 e1000_rx_checksum(adapter, staterr,
1353 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1355 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1357 if (rx_desc->wb.upper.header_status &
1358 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1359 adapter->rx_hdr_split++;
1361 e1000_receive_skb(adapter, netdev, skb,
1362 staterr, rx_desc->wb.middle.vlan);
1365 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1366 buffer_info->skb = NULL;
1368 /* return some buffers to hardware, one at a time is too slow */
1369 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1370 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1375 /* use prefetched values */
1377 buffer_info = next_buffer;
1379 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1381 rx_ring->next_to_clean = i;
1383 cleaned_count = e1000_desc_unused(rx_ring);
1385 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1387 adapter->total_rx_bytes += total_rx_bytes;
1388 adapter->total_rx_packets += total_rx_packets;
1393 * e1000_consume_page - helper function
1395 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1400 skb->data_len += length;
1401 skb->truesize += PAGE_SIZE;
1405 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1406 * @adapter: board private structure
1408 * the return value indicates whether actual cleaning was done, there
1409 * is no guarantee that everything was cleaned
1411 static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1414 struct e1000_adapter *adapter = rx_ring->adapter;
1415 struct net_device *netdev = adapter->netdev;
1416 struct pci_dev *pdev = adapter->pdev;
1417 union e1000_rx_desc_extended *rx_desc, *next_rxd;
1418 struct e1000_buffer *buffer_info, *next_buffer;
1419 u32 length, staterr;
1421 int cleaned_count = 0;
1422 bool cleaned = false;
1423 unsigned int total_rx_bytes=0, total_rx_packets=0;
1425 i = rx_ring->next_to_clean;
1426 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1427 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1428 buffer_info = &rx_ring->buffer_info[i];
1430 while (staterr & E1000_RXD_STAT_DD) {
1431 struct sk_buff *skb;
1433 if (*work_done >= work_to_do)
1436 rmb(); /* read descriptor and rx_buffer_info after status DD */
1438 skb = buffer_info->skb;
1439 buffer_info->skb = NULL;
1442 if (i == rx_ring->count)
1444 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
1447 next_buffer = &rx_ring->buffer_info[i];
1451 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1453 buffer_info->dma = 0;
1455 length = le16_to_cpu(rx_desc->wb.upper.length);
1457 /* errors is only valid for DD + EOP descriptors */
1458 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1459 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1460 !(netdev->features & NETIF_F_RXALL)))) {
1461 /* recycle both page and skb */
1462 buffer_info->skb = skb;
1463 /* an error means any chain goes out the window too */
1464 if (rx_ring->rx_skb_top)
1465 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1466 rx_ring->rx_skb_top = NULL;
1470 #define rxtop (rx_ring->rx_skb_top)
1471 if (!(staterr & E1000_RXD_STAT_EOP)) {
1472 /* this descriptor is only the beginning (or middle) */
1474 /* this is the beginning of a chain */
1476 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1479 /* this is the middle of a chain */
1480 skb_fill_page_desc(rxtop,
1481 skb_shinfo(rxtop)->nr_frags,
1482 buffer_info->page, 0, length);
1483 /* re-use the skb, only consumed the page */
1484 buffer_info->skb = skb;
1486 e1000_consume_page(buffer_info, rxtop, length);
1490 /* end of the chain */
1491 skb_fill_page_desc(rxtop,
1492 skb_shinfo(rxtop)->nr_frags,
1493 buffer_info->page, 0, length);
1494 /* re-use the current skb, we only consumed the
1496 buffer_info->skb = skb;
1499 e1000_consume_page(buffer_info, skb, length);
1501 /* no chain, got EOP, this buf is the packet
1502 * copybreak to save the put_page/alloc_page */
1503 if (length <= copybreak &&
1504 skb_tailroom(skb) >= length) {
1506 vaddr = kmap_atomic(buffer_info->page,
1507 KM_SKB_DATA_SOFTIRQ);
1508 memcpy(skb_tail_pointer(skb), vaddr,
1510 kunmap_atomic(vaddr,
1511 KM_SKB_DATA_SOFTIRQ);
1512 /* re-use the page, so don't erase
1513 * buffer_info->page */
1514 skb_put(skb, length);
1516 skb_fill_page_desc(skb, 0,
1517 buffer_info->page, 0,
1519 e1000_consume_page(buffer_info, skb,
1525 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1526 e1000_rx_checksum(adapter, staterr,
1527 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1529 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1531 /* probably a little skewed due to removing CRC */
1532 total_rx_bytes += skb->len;
1535 /* eth type trans needs skb->data to point to something */
1536 if (!pskb_may_pull(skb, ETH_HLEN)) {
1537 e_err("pskb_may_pull failed.\n");
1538 dev_kfree_skb_irq(skb);
1542 e1000_receive_skb(adapter, netdev, skb, staterr,
1543 rx_desc->wb.upper.vlan);
1546 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
1548 /* return some buffers to hardware, one at a time is too slow */
1549 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1550 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1555 /* use prefetched values */
1557 buffer_info = next_buffer;
1559 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1561 rx_ring->next_to_clean = i;
1563 cleaned_count = e1000_desc_unused(rx_ring);
1565 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1567 adapter->total_rx_bytes += total_rx_bytes;
1568 adapter->total_rx_packets += total_rx_packets;
1573 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1574 * @rx_ring: Rx descriptor ring
1576 static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
1578 struct e1000_adapter *adapter = rx_ring->adapter;
1579 struct e1000_buffer *buffer_info;
1580 struct e1000_ps_page *ps_page;
1581 struct pci_dev *pdev = adapter->pdev;
1584 /* Free all the Rx ring sk_buffs */
1585 for (i = 0; i < rx_ring->count; i++) {
1586 buffer_info = &rx_ring->buffer_info[i];
1587 if (buffer_info->dma) {
1588 if (adapter->clean_rx == e1000_clean_rx_irq)
1589 dma_unmap_single(&pdev->dev, buffer_info->dma,
1590 adapter->rx_buffer_len,
1592 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1593 dma_unmap_page(&pdev->dev, buffer_info->dma,
1596 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1597 dma_unmap_single(&pdev->dev, buffer_info->dma,
1598 adapter->rx_ps_bsize0,
1600 buffer_info->dma = 0;
1603 if (buffer_info->page) {
1604 put_page(buffer_info->page);
1605 buffer_info->page = NULL;
1608 if (buffer_info->skb) {
1609 dev_kfree_skb(buffer_info->skb);
1610 buffer_info->skb = NULL;
1613 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1614 ps_page = &buffer_info->ps_pages[j];
1617 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1620 put_page(ps_page->page);
1621 ps_page->page = NULL;
1625 /* there also may be some cached data from a chained receive */
1626 if (rx_ring->rx_skb_top) {
1627 dev_kfree_skb(rx_ring->rx_skb_top);
1628 rx_ring->rx_skb_top = NULL;
1631 /* Zero out the descriptor ring */
1632 memset(rx_ring->desc, 0, rx_ring->size);
1634 rx_ring->next_to_clean = 0;
1635 rx_ring->next_to_use = 0;
1636 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1638 writel(0, rx_ring->head);
1639 writel(0, rx_ring->tail);
1642 static void e1000e_downshift_workaround(struct work_struct *work)
1644 struct e1000_adapter *adapter = container_of(work,
1645 struct e1000_adapter, downshift_task);
1647 if (test_bit(__E1000_DOWN, &adapter->state))
1650 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1654 * e1000_intr_msi - Interrupt Handler
1655 * @irq: interrupt number
1656 * @data: pointer to a network interface device structure
1658 static irqreturn_t e1000_intr_msi(int irq, void *data)
1660 struct net_device *netdev = data;
1661 struct e1000_adapter *adapter = netdev_priv(netdev);
1662 struct e1000_hw *hw = &adapter->hw;
1663 u32 icr = er32(ICR);
1666 * read ICR disables interrupts using IAM
1669 if (icr & E1000_ICR_LSC) {
1670 hw->mac.get_link_status = true;
1672 * ICH8 workaround-- Call gig speed drop workaround on cable
1673 * disconnect (LSC) before accessing any PHY registers
1675 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1676 (!(er32(STATUS) & E1000_STATUS_LU)))
1677 schedule_work(&adapter->downshift_task);
1680 * 80003ES2LAN workaround-- For packet buffer work-around on
1681 * link down event; disable receives here in the ISR and reset
1682 * adapter in watchdog
1684 if (netif_carrier_ok(netdev) &&
1685 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1686 /* disable receives */
1687 u32 rctl = er32(RCTL);
1688 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1689 adapter->flags |= FLAG_RX_RESTART_NOW;
1691 /* guard against interrupt when we're going down */
1692 if (!test_bit(__E1000_DOWN, &adapter->state))
1693 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1696 if (napi_schedule_prep(&adapter->napi)) {
1697 adapter->total_tx_bytes = 0;
1698 adapter->total_tx_packets = 0;
1699 adapter->total_rx_bytes = 0;
1700 adapter->total_rx_packets = 0;
1701 __napi_schedule(&adapter->napi);
1708 * e1000_intr - Interrupt Handler
1709 * @irq: interrupt number
1710 * @data: pointer to a network interface device structure
1712 static irqreturn_t e1000_intr(int irq, void *data)
1714 struct net_device *netdev = data;
1715 struct e1000_adapter *adapter = netdev_priv(netdev);
1716 struct e1000_hw *hw = &adapter->hw;
1717 u32 rctl, icr = er32(ICR);
1719 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
1720 return IRQ_NONE; /* Not our interrupt */
1723 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1724 * not set, then the adapter didn't send an interrupt
1726 if (!(icr & E1000_ICR_INT_ASSERTED))
1730 * Interrupt Auto-Mask...upon reading ICR,
1731 * interrupts are masked. No need for the
1735 if (icr & E1000_ICR_LSC) {
1736 hw->mac.get_link_status = true;
1738 * ICH8 workaround-- Call gig speed drop workaround on cable
1739 * disconnect (LSC) before accessing any PHY registers
1741 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1742 (!(er32(STATUS) & E1000_STATUS_LU)))
1743 schedule_work(&adapter->downshift_task);
1746 * 80003ES2LAN workaround--
1747 * For packet buffer work-around on link down event;
1748 * disable receives here in the ISR and
1749 * reset adapter in watchdog
1751 if (netif_carrier_ok(netdev) &&
1752 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1753 /* disable receives */
1755 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1756 adapter->flags |= FLAG_RX_RESTART_NOW;
1758 /* guard against interrupt when we're going down */
1759 if (!test_bit(__E1000_DOWN, &adapter->state))
1760 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1763 if (napi_schedule_prep(&adapter->napi)) {
1764 adapter->total_tx_bytes = 0;
1765 adapter->total_tx_packets = 0;
1766 adapter->total_rx_bytes = 0;
1767 adapter->total_rx_packets = 0;
1768 __napi_schedule(&adapter->napi);
1774 static irqreturn_t e1000_msix_other(int irq, void *data)
1776 struct net_device *netdev = data;
1777 struct e1000_adapter *adapter = netdev_priv(netdev);
1778 struct e1000_hw *hw = &adapter->hw;
1779 u32 icr = er32(ICR);
1781 if (!(icr & E1000_ICR_INT_ASSERTED)) {
1782 if (!test_bit(__E1000_DOWN, &adapter->state))
1783 ew32(IMS, E1000_IMS_OTHER);
1787 if (icr & adapter->eiac_mask)
1788 ew32(ICS, (icr & adapter->eiac_mask));
1790 if (icr & E1000_ICR_OTHER) {
1791 if (!(icr & E1000_ICR_LSC))
1792 goto no_link_interrupt;
1793 hw->mac.get_link_status = true;
1794 /* guard against interrupt when we're going down */
1795 if (!test_bit(__E1000_DOWN, &adapter->state))
1796 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1800 if (!test_bit(__E1000_DOWN, &adapter->state))
1801 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
1807 static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1809 struct net_device *netdev = data;
1810 struct e1000_adapter *adapter = netdev_priv(netdev);
1811 struct e1000_hw *hw = &adapter->hw;
1812 struct e1000_ring *tx_ring = adapter->tx_ring;
1815 adapter->total_tx_bytes = 0;
1816 adapter->total_tx_packets = 0;
1818 if (!e1000_clean_tx_irq(tx_ring))
1819 /* Ring was not completely cleaned, so fire another interrupt */
1820 ew32(ICS, tx_ring->ims_val);
1825 static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1827 struct net_device *netdev = data;
1828 struct e1000_adapter *adapter = netdev_priv(netdev);
1829 struct e1000_ring *rx_ring = adapter->rx_ring;
1831 /* Write the ITR value calculated at the end of the
1832 * previous interrupt.
1834 if (rx_ring->set_itr) {
1835 writel(1000000000 / (rx_ring->itr_val * 256),
1836 rx_ring->itr_register);
1837 rx_ring->set_itr = 0;
1840 if (napi_schedule_prep(&adapter->napi)) {
1841 adapter->total_rx_bytes = 0;
1842 adapter->total_rx_packets = 0;
1843 __napi_schedule(&adapter->napi);
1849 * e1000_configure_msix - Configure MSI-X hardware
1851 * e1000_configure_msix sets up the hardware to properly
1852 * generate MSI-X interrupts.
1854 static void e1000_configure_msix(struct e1000_adapter *adapter)
1856 struct e1000_hw *hw = &adapter->hw;
1857 struct e1000_ring *rx_ring = adapter->rx_ring;
1858 struct e1000_ring *tx_ring = adapter->tx_ring;
1860 u32 ctrl_ext, ivar = 0;
1862 adapter->eiac_mask = 0;
1864 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1865 if (hw->mac.type == e1000_82574) {
1866 u32 rfctl = er32(RFCTL);
1867 rfctl |= E1000_RFCTL_ACK_DIS;
1871 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1872 /* Configure Rx vector */
1873 rx_ring->ims_val = E1000_IMS_RXQ0;
1874 adapter->eiac_mask |= rx_ring->ims_val;
1875 if (rx_ring->itr_val)
1876 writel(1000000000 / (rx_ring->itr_val * 256),
1877 rx_ring->itr_register);
1879 writel(1, rx_ring->itr_register);
1880 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1882 /* Configure Tx vector */
1883 tx_ring->ims_val = E1000_IMS_TXQ0;
1885 if (tx_ring->itr_val)
1886 writel(1000000000 / (tx_ring->itr_val * 256),
1887 tx_ring->itr_register);
1889 writel(1, tx_ring->itr_register);
1890 adapter->eiac_mask |= tx_ring->ims_val;
1891 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1893 /* set vector for Other Causes, e.g. link changes */
1895 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1896 if (rx_ring->itr_val)
1897 writel(1000000000 / (rx_ring->itr_val * 256),
1898 hw->hw_addr + E1000_EITR_82574(vector));
1900 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1902 /* Cause Tx interrupts on every write back */
1907 /* enable MSI-X PBA support */
1908 ctrl_ext = er32(CTRL_EXT);
1909 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1911 /* Auto-Mask Other interrupts upon ICR read */
1912 #define E1000_EIAC_MASK_82574 0x01F00000
1913 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1914 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1915 ew32(CTRL_EXT, ctrl_ext);
1919 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1921 if (adapter->msix_entries) {
1922 pci_disable_msix(adapter->pdev);
1923 kfree(adapter->msix_entries);
1924 adapter->msix_entries = NULL;
1925 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1926 pci_disable_msi(adapter->pdev);
1927 adapter->flags &= ~FLAG_MSI_ENABLED;
1932 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1934 * Attempt to configure interrupts using the best available
1935 * capabilities of the hardware and kernel.
1937 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1942 switch (adapter->int_mode) {
1943 case E1000E_INT_MODE_MSIX:
1944 if (adapter->flags & FLAG_HAS_MSIX) {
1945 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1946 adapter->msix_entries = kcalloc(adapter->num_vectors,
1947 sizeof(struct msix_entry),
1949 if (adapter->msix_entries) {
1950 for (i = 0; i < adapter->num_vectors; i++)
1951 adapter->msix_entries[i].entry = i;
1953 err = pci_enable_msix(adapter->pdev,
1954 adapter->msix_entries,
1955 adapter->num_vectors);
1959 /* MSI-X failed, so fall through and try MSI */
1960 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
1961 e1000e_reset_interrupt_capability(adapter);
1963 adapter->int_mode = E1000E_INT_MODE_MSI;
1965 case E1000E_INT_MODE_MSI:
1966 if (!pci_enable_msi(adapter->pdev)) {
1967 adapter->flags |= FLAG_MSI_ENABLED;
1969 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1970 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
1973 case E1000E_INT_MODE_LEGACY:
1974 /* Don't do anything; this is the system default */
1978 /* store the number of vectors being used */
1979 adapter->num_vectors = 1;
1983 * e1000_request_msix - Initialize MSI-X interrupts
1985 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1988 static int e1000_request_msix(struct e1000_adapter *adapter)
1990 struct net_device *netdev = adapter->netdev;
1991 int err = 0, vector = 0;
1993 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1994 snprintf(adapter->rx_ring->name,
1995 sizeof(adapter->rx_ring->name) - 1,
1996 "%s-rx-0", netdev->name);
1998 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1999 err = request_irq(adapter->msix_entries[vector].vector,
2000 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
2004 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2005 E1000_EITR_82574(vector);
2006 adapter->rx_ring->itr_val = adapter->itr;
2009 if (strlen(netdev->name) < (IFNAMSIZ - 5))
2010 snprintf(adapter->tx_ring->name,
2011 sizeof(adapter->tx_ring->name) - 1,
2012 "%s-tx-0", netdev->name);
2014 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2015 err = request_irq(adapter->msix_entries[vector].vector,
2016 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
2020 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2021 E1000_EITR_82574(vector);
2022 adapter->tx_ring->itr_val = adapter->itr;
2025 err = request_irq(adapter->msix_entries[vector].vector,
2026 e1000_msix_other, 0, netdev->name, netdev);
2030 e1000_configure_msix(adapter);
2036 * e1000_request_irq - initialize interrupts
2038 * Attempts to configure interrupts using the best available
2039 * capabilities of the hardware and kernel.
2041 static int e1000_request_irq(struct e1000_adapter *adapter)
2043 struct net_device *netdev = adapter->netdev;
2046 if (adapter->msix_entries) {
2047 err = e1000_request_msix(adapter);
2050 /* fall back to MSI */
2051 e1000e_reset_interrupt_capability(adapter);
2052 adapter->int_mode = E1000E_INT_MODE_MSI;
2053 e1000e_set_interrupt_capability(adapter);
2055 if (adapter->flags & FLAG_MSI_ENABLED) {
2056 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
2057 netdev->name, netdev);
2061 /* fall back to legacy interrupt */
2062 e1000e_reset_interrupt_capability(adapter);
2063 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2066 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
2067 netdev->name, netdev);
2069 e_err("Unable to allocate interrupt, Error: %d\n", err);
2074 static void e1000_free_irq(struct e1000_adapter *adapter)
2076 struct net_device *netdev = adapter->netdev;
2078 if (adapter->msix_entries) {
2081 free_irq(adapter->msix_entries[vector].vector, netdev);
2084 free_irq(adapter->msix_entries[vector].vector, netdev);
2087 /* Other Causes interrupt vector */
2088 free_irq(adapter->msix_entries[vector].vector, netdev);
2092 free_irq(adapter->pdev->irq, netdev);
2096 * e1000_irq_disable - Mask off interrupt generation on the NIC
2098 static void e1000_irq_disable(struct e1000_adapter *adapter)
2100 struct e1000_hw *hw = &adapter->hw;
2103 if (adapter->msix_entries)
2104 ew32(EIAC_82574, 0);
2107 if (adapter->msix_entries) {
2109 for (i = 0; i < adapter->num_vectors; i++)
2110 synchronize_irq(adapter->msix_entries[i].vector);
2112 synchronize_irq(adapter->pdev->irq);
2117 * e1000_irq_enable - Enable default interrupt generation settings
2119 static void e1000_irq_enable(struct e1000_adapter *adapter)
2121 struct e1000_hw *hw = &adapter->hw;
2123 if (adapter->msix_entries) {
2124 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2125 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2127 ew32(IMS, IMS_ENABLE_MASK);
2133 * e1000e_get_hw_control - get control of the h/w from f/w
2134 * @adapter: address of board private structure
2136 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2137 * For ASF and Pass Through versions of f/w this means that
2138 * the driver is loaded. For AMT version (only with 82573)
2139 * of the f/w this means that the network i/f is open.
2141 void e1000e_get_hw_control(struct e1000_adapter *adapter)
2143 struct e1000_hw *hw = &adapter->hw;
2147 /* Let firmware know the driver has taken over */
2148 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2150 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2151 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2152 ctrl_ext = er32(CTRL_EXT);
2153 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2158 * e1000e_release_hw_control - release control of the h/w to f/w
2159 * @adapter: address of board private structure
2161 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2162 * For ASF and Pass Through versions of f/w this means that the
2163 * driver is no longer loaded. For AMT version (only with 82573) i
2164 * of the f/w this means that the network i/f is closed.
2167 void e1000e_release_hw_control(struct e1000_adapter *adapter)
2169 struct e1000_hw *hw = &adapter->hw;
2173 /* Let firmware taken over control of h/w */
2174 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2176 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2177 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2178 ctrl_ext = er32(CTRL_EXT);
2179 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2184 * @e1000_alloc_ring - allocate memory for a ring structure
2186 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2187 struct e1000_ring *ring)
2189 struct pci_dev *pdev = adapter->pdev;
2191 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2200 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2201 * @tx_ring: Tx descriptor ring
2203 * Return 0 on success, negative on failure
2205 int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
2207 struct e1000_adapter *adapter = tx_ring->adapter;
2208 int err = -ENOMEM, size;
2210 size = sizeof(struct e1000_buffer) * tx_ring->count;
2211 tx_ring->buffer_info = vzalloc(size);
2212 if (!tx_ring->buffer_info)
2215 /* round up to nearest 4K */
2216 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2217 tx_ring->size = ALIGN(tx_ring->size, 4096);
2219 err = e1000_alloc_ring_dma(adapter, tx_ring);
2223 tx_ring->next_to_use = 0;
2224 tx_ring->next_to_clean = 0;
2228 vfree(tx_ring->buffer_info);
2229 e_err("Unable to allocate memory for the transmit descriptor ring\n");
2234 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2235 * @rx_ring: Rx descriptor ring
2237 * Returns 0 on success, negative on failure
2239 int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
2241 struct e1000_adapter *adapter = rx_ring->adapter;
2242 struct e1000_buffer *buffer_info;
2243 int i, size, desc_len, err = -ENOMEM;
2245 size = sizeof(struct e1000_buffer) * rx_ring->count;
2246 rx_ring->buffer_info = vzalloc(size);
2247 if (!rx_ring->buffer_info)
2250 for (i = 0; i < rx_ring->count; i++) {
2251 buffer_info = &rx_ring->buffer_info[i];
2252 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2253 sizeof(struct e1000_ps_page),
2255 if (!buffer_info->ps_pages)
2259 desc_len = sizeof(union e1000_rx_desc_packet_split);
2261 /* Round up to nearest 4K */
2262 rx_ring->size = rx_ring->count * desc_len;
2263 rx_ring->size = ALIGN(rx_ring->size, 4096);
2265 err = e1000_alloc_ring_dma(adapter, rx_ring);
2269 rx_ring->next_to_clean = 0;
2270 rx_ring->next_to_use = 0;
2271 rx_ring->rx_skb_top = NULL;
2276 for (i = 0; i < rx_ring->count; i++) {
2277 buffer_info = &rx_ring->buffer_info[i];
2278 kfree(buffer_info->ps_pages);
2281 vfree(rx_ring->buffer_info);
2282 e_err("Unable to allocate memory for the receive descriptor ring\n");
2287 * e1000_clean_tx_ring - Free Tx Buffers
2288 * @tx_ring: Tx descriptor ring
2290 static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
2292 struct e1000_adapter *adapter = tx_ring->adapter;
2293 struct e1000_buffer *buffer_info;
2297 for (i = 0; i < tx_ring->count; i++) {
2298 buffer_info = &tx_ring->buffer_info[i];
2299 e1000_put_txbuf(tx_ring, buffer_info);
2302 netdev_reset_queue(adapter->netdev);
2303 size = sizeof(struct e1000_buffer) * tx_ring->count;
2304 memset(tx_ring->buffer_info, 0, size);
2306 memset(tx_ring->desc, 0, tx_ring->size);
2308 tx_ring->next_to_use = 0;
2309 tx_ring->next_to_clean = 0;
2311 writel(0, tx_ring->head);
2312 writel(0, tx_ring->tail);
2316 * e1000e_free_tx_resources - Free Tx Resources per Queue
2317 * @tx_ring: Tx descriptor ring
2319 * Free all transmit software resources
2321 void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
2323 struct e1000_adapter *adapter = tx_ring->adapter;
2324 struct pci_dev *pdev = adapter->pdev;
2326 e1000_clean_tx_ring(tx_ring);
2328 vfree(tx_ring->buffer_info);
2329 tx_ring->buffer_info = NULL;
2331 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2333 tx_ring->desc = NULL;
2337 * e1000e_free_rx_resources - Free Rx Resources
2338 * @rx_ring: Rx descriptor ring
2340 * Free all receive software resources
2342 void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
2344 struct e1000_adapter *adapter = rx_ring->adapter;
2345 struct pci_dev *pdev = adapter->pdev;
2348 e1000_clean_rx_ring(rx_ring);
2350 for (i = 0; i < rx_ring->count; i++)
2351 kfree(rx_ring->buffer_info[i].ps_pages);
2353 vfree(rx_ring->buffer_info);
2354 rx_ring->buffer_info = NULL;
2356 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2358 rx_ring->desc = NULL;
2362 * e1000_update_itr - update the dynamic ITR value based on statistics
2363 * @adapter: pointer to adapter
2364 * @itr_setting: current adapter->itr
2365 * @packets: the number of packets during this measurement interval
2366 * @bytes: the number of bytes during this measurement interval
2368 * Stores a new ITR value based on packets and byte
2369 * counts during the last interrupt. The advantage of per interrupt
2370 * computation is faster updates and more accurate ITR for the current
2371 * traffic pattern. Constants in this function were computed
2372 * based on theoretical maximum wire speed and thresholds were set based
2373 * on testing data as well as attempting to minimize response time
2374 * while increasing bulk throughput. This functionality is controlled
2375 * by the InterruptThrottleRate module parameter.
2377 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2378 u16 itr_setting, int packets,
2381 unsigned int retval = itr_setting;
2386 switch (itr_setting) {
2387 case lowest_latency:
2388 /* handle TSO and jumbo frames */
2389 if (bytes/packets > 8000)
2390 retval = bulk_latency;
2391 else if ((packets < 5) && (bytes > 512))
2392 retval = low_latency;
2394 case low_latency: /* 50 usec aka 20000 ints/s */
2395 if (bytes > 10000) {
2396 /* this if handles the TSO accounting */
2397 if (bytes/packets > 8000)
2398 retval = bulk_latency;
2399 else if ((packets < 10) || ((bytes/packets) > 1200))
2400 retval = bulk_latency;
2401 else if ((packets > 35))
2402 retval = lowest_latency;
2403 } else if (bytes/packets > 2000) {
2404 retval = bulk_latency;
2405 } else if (packets <= 2 && bytes < 512) {
2406 retval = lowest_latency;
2409 case bulk_latency: /* 250 usec aka 4000 ints/s */
2410 if (bytes > 25000) {
2412 retval = low_latency;
2413 } else if (bytes < 6000) {
2414 retval = low_latency;
2422 static void e1000_set_itr(struct e1000_adapter *adapter)
2424 struct e1000_hw *hw = &adapter->hw;
2426 u32 new_itr = adapter->itr;
2428 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2429 if (adapter->link_speed != SPEED_1000) {
2435 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2440 adapter->tx_itr = e1000_update_itr(adapter,
2442 adapter->total_tx_packets,
2443 adapter->total_tx_bytes);
2444 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2445 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2446 adapter->tx_itr = low_latency;
2448 adapter->rx_itr = e1000_update_itr(adapter,
2450 adapter->total_rx_packets,
2451 adapter->total_rx_bytes);
2452 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2453 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2454 adapter->rx_itr = low_latency;
2456 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2458 switch (current_itr) {
2459 /* counts and packets in update_itr are dependent on these numbers */
2460 case lowest_latency:
2464 new_itr = 20000; /* aka hwitr = ~200 */
2474 if (new_itr != adapter->itr) {
2476 * this attempts to bias the interrupt rate towards Bulk
2477 * by adding intermediate steps when interrupt rate is
2480 new_itr = new_itr > adapter->itr ?
2481 min(adapter->itr + (new_itr >> 2), new_itr) :
2483 adapter->itr = new_itr;
2484 adapter->rx_ring->itr_val = new_itr;
2485 if (adapter->msix_entries)
2486 adapter->rx_ring->set_itr = 1;
2489 ew32(ITR, 1000000000 / (new_itr * 256));
2496 * e1000_alloc_queues - Allocate memory for all rings
2497 * @adapter: board private structure to initialize
2499 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2501 int size = sizeof(struct e1000_ring);
2503 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
2504 if (!adapter->tx_ring)
2506 adapter->tx_ring->count = adapter->tx_ring_count;
2507 adapter->tx_ring->adapter = adapter;
2509 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
2510 if (!adapter->rx_ring)
2512 adapter->rx_ring->count = adapter->rx_ring_count;
2513 adapter->rx_ring->adapter = adapter;
2517 e_err("Unable to allocate memory for queues\n");
2518 kfree(adapter->rx_ring);
2519 kfree(adapter->tx_ring);
2524 * e1000_clean - NAPI Rx polling callback
2525 * @napi: struct associated with this polling callback
2526 * @budget: amount of packets driver is allowed to process this poll
2528 static int e1000_clean(struct napi_struct *napi, int budget)
2530 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
2531 struct e1000_hw *hw = &adapter->hw;
2532 struct net_device *poll_dev = adapter->netdev;
2533 int tx_cleaned = 1, work_done = 0;
2535 adapter = netdev_priv(poll_dev);
2537 if (adapter->msix_entries &&
2538 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2541 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
2544 adapter->clean_rx(adapter->rx_ring, &work_done, budget);
2549 /* If budget not fully consumed, exit the polling mode */
2550 if (work_done < budget) {
2551 if (adapter->itr_setting & 3)
2552 e1000_set_itr(adapter);
2553 napi_complete(napi);
2554 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2555 if (adapter->msix_entries)
2556 ew32(IMS, adapter->rx_ring->ims_val);
2558 e1000_irq_enable(adapter);
2565 static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2567 struct e1000_adapter *adapter = netdev_priv(netdev);
2568 struct e1000_hw *hw = &adapter->hw;
2571 /* don't update vlan cookie if already programmed */
2572 if ((adapter->hw.mng_cookie.status &
2573 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2574 (vid == adapter->mng_vlan_id))
2577 /* add VID to filter table */
2578 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2579 index = (vid >> 5) & 0x7F;
2580 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2581 vfta |= (1 << (vid & 0x1F));
2582 hw->mac.ops.write_vfta(hw, index, vfta);
2585 set_bit(vid, adapter->active_vlans);
2590 static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2592 struct e1000_adapter *adapter = netdev_priv(netdev);
2593 struct e1000_hw *hw = &adapter->hw;
2596 if ((adapter->hw.mng_cookie.status &
2597 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2598 (vid == adapter->mng_vlan_id)) {
2599 /* release control to f/w */
2600 e1000e_release_hw_control(adapter);
2604 /* remove VID from filter table */
2605 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2606 index = (vid >> 5) & 0x7F;
2607 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2608 vfta &= ~(1 << (vid & 0x1F));
2609 hw->mac.ops.write_vfta(hw, index, vfta);
2612 clear_bit(vid, adapter->active_vlans);
2618 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2619 * @adapter: board private structure to initialize
2621 static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2623 struct net_device *netdev = adapter->netdev;
2624 struct e1000_hw *hw = &adapter->hw;
2627 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2628 /* disable VLAN receive filtering */
2630 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2633 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2634 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2635 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2641 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2642 * @adapter: board private structure to initialize
2644 static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2646 struct e1000_hw *hw = &adapter->hw;
2649 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2650 /* enable VLAN receive filtering */
2652 rctl |= E1000_RCTL_VFE;
2653 rctl &= ~E1000_RCTL_CFIEN;
2659 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2660 * @adapter: board private structure to initialize
2662 static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2664 struct e1000_hw *hw = &adapter->hw;
2667 /* disable VLAN tag insert/strip */
2669 ctrl &= ~E1000_CTRL_VME;
2674 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2675 * @adapter: board private structure to initialize
2677 static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2679 struct e1000_hw *hw = &adapter->hw;
2682 /* enable VLAN tag insert/strip */
2684 ctrl |= E1000_CTRL_VME;
2688 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2690 struct net_device *netdev = adapter->netdev;
2691 u16 vid = adapter->hw.mng_cookie.vlan_id;
2692 u16 old_vid = adapter->mng_vlan_id;
2694 if (adapter->hw.mng_cookie.status &
2695 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2696 e1000_vlan_rx_add_vid(netdev, vid);
2697 adapter->mng_vlan_id = vid;
2700 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2701 e1000_vlan_rx_kill_vid(netdev, old_vid);
2704 static void e1000_restore_vlan(struct e1000_adapter *adapter)
2708 e1000_vlan_rx_add_vid(adapter->netdev, 0);
2710 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
2711 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2714 static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
2716 struct e1000_hw *hw = &adapter->hw;
2717 u32 manc, manc2h, mdef, i, j;
2719 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2725 * enable receiving management packets to the host. this will probably
2726 * generate destination unreachable messages from the host OS, but
2727 * the packets will be handled on SMBUS
2729 manc |= E1000_MANC_EN_MNG2HOST;
2730 manc2h = er32(MANC2H);
2732 switch (hw->mac.type) {
2734 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2739 * Check if IPMI pass-through decision filter already exists;
2742 for (i = 0, j = 0; i < 8; i++) {
2743 mdef = er32(MDEF(i));
2745 /* Ignore filters with anything other than IPMI ports */
2746 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2749 /* Enable this decision filter in MANC2H */
2756 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2759 /* Create new decision filter in an empty filter */
2760 for (i = 0, j = 0; i < 8; i++)
2761 if (er32(MDEF(i)) == 0) {
2762 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2763 E1000_MDEF_PORT_664));
2770 e_warn("Unable to create IPMI pass-through filter\n");
2774 ew32(MANC2H, manc2h);
2779 * e1000_configure_tx - Configure Transmit Unit after Reset
2780 * @adapter: board private structure
2782 * Configure the Tx unit of the MAC after a reset.
2784 static void e1000_configure_tx(struct e1000_adapter *adapter)
2786 struct e1000_hw *hw = &adapter->hw;
2787 struct e1000_ring *tx_ring = adapter->tx_ring;
2791 /* Setup the HW Tx Head and Tail descriptor pointers */
2792 tdba = tx_ring->dma;
2793 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2794 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
2795 ew32(TDBAH, (tdba >> 32));
2799 tx_ring->head = adapter->hw.hw_addr + E1000_TDH;
2800 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT;
2802 /* Set the Tx Interrupt Delay register */
2803 ew32(TIDV, adapter->tx_int_delay);
2804 /* Tx irq moderation */
2805 ew32(TADV, adapter->tx_abs_int_delay);
2807 if (adapter->flags2 & FLAG2_DMA_BURST) {
2808 u32 txdctl = er32(TXDCTL(0));
2809 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2810 E1000_TXDCTL_WTHRESH);
2812 * set up some performance related parameters to encourage the
2813 * hardware to use the bus more efficiently in bursts, depends
2814 * on the tx_int_delay to be enabled,
2815 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2816 * hthresh = 1 ==> prefetch when one or more available
2817 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2818 * BEWARE: this seems to work but should be considered first if
2819 * there are Tx hangs or other Tx related bugs
2821 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2822 ew32(TXDCTL(0), txdctl);
2824 /* erratum work around: set txdctl the same for both queues */
2825 ew32(TXDCTL(1), er32(TXDCTL(0)));
2827 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
2828 tarc = er32(TARC(0));
2830 * set the speed mode bit, we'll clear it if we're not at
2831 * gigabit link later
2833 #define SPEED_MODE_BIT (1 << 21)
2834 tarc |= SPEED_MODE_BIT;
2835 ew32(TARC(0), tarc);
2838 /* errata: program both queues to unweighted RR */
2839 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
2840 tarc = er32(TARC(0));
2842 ew32(TARC(0), tarc);
2843 tarc = er32(TARC(1));
2845 ew32(TARC(1), tarc);
2848 /* Setup Transmit Descriptor Settings for eop descriptor */
2849 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2851 /* only set IDE if we are delaying interrupts using the timers */
2852 if (adapter->tx_int_delay)
2853 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2855 /* enable Report Status bit */
2856 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2858 hw->mac.ops.config_collision_dist(hw);
2862 * e1000_setup_rctl - configure the receive control registers
2863 * @adapter: Board private structure
2865 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2866 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2867 static void e1000_setup_rctl(struct e1000_adapter *adapter)
2869 struct e1000_hw *hw = &adapter->hw;
2873 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2874 if (hw->mac.type == e1000_pch2lan) {
2877 if (adapter->netdev->mtu > ETH_DATA_LEN)
2878 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2880 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
2883 e_dbg("failed to enable jumbo frame workaround mode\n");
2886 /* Program MC offset vector base */
2888 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2889 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2890 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2891 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2893 /* Do not Store bad packets */
2894 rctl &= ~E1000_RCTL_SBP;
2896 /* Enable Long Packet receive */
2897 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2898 rctl &= ~E1000_RCTL_LPE;
2900 rctl |= E1000_RCTL_LPE;
2902 /* Some systems expect that the CRC is included in SMBUS traffic. The
2903 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2904 * host memory when this is enabled
2906 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2907 rctl |= E1000_RCTL_SECRC;
2909 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2910 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2913 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2915 phy_data |= (1 << 2);
2916 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2918 e1e_rphy(hw, 22, &phy_data);
2920 phy_data |= (1 << 14);
2921 e1e_wphy(hw, 0x10, 0x2823);
2922 e1e_wphy(hw, 0x11, 0x0003);
2923 e1e_wphy(hw, 22, phy_data);
2926 /* Setup buffer sizes */
2927 rctl &= ~E1000_RCTL_SZ_4096;
2928 rctl |= E1000_RCTL_BSEX;
2929 switch (adapter->rx_buffer_len) {
2932 rctl |= E1000_RCTL_SZ_2048;
2933 rctl &= ~E1000_RCTL_BSEX;
2936 rctl |= E1000_RCTL_SZ_4096;
2939 rctl |= E1000_RCTL_SZ_8192;
2942 rctl |= E1000_RCTL_SZ_16384;
2946 /* Enable Extended Status in all Receive Descriptors */
2947 rfctl = er32(RFCTL);
2948 rfctl |= E1000_RFCTL_EXTEN;
2951 * 82571 and greater support packet-split where the protocol
2952 * header is placed in skb->data and the packet data is
2953 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2954 * In the case of a non-split, skb->data is linearly filled,
2955 * followed by the page buffers. Therefore, skb->data is
2956 * sized to hold the largest protocol header.
2958 * allocations using alloc_page take too long for regular MTU
2959 * so only enable packet split for jumbo frames
2961 * Using pages when the page size is greater than 16k wastes
2962 * a lot of memory, since we allocate 3 pages at all times
2965 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2966 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
2967 adapter->rx_ps_pages = pages;
2969 adapter->rx_ps_pages = 0;
2971 if (adapter->rx_ps_pages) {
2975 * disable packet split support for IPv6 extension headers,
2976 * because some malformed IPv6 headers can hang the Rx
2978 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2979 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2981 /* Enable Packet split descriptors */
2982 rctl |= E1000_RCTL_DTYP_PS;
2984 psrctl |= adapter->rx_ps_bsize0 >>
2985 E1000_PSRCTL_BSIZE0_SHIFT;
2987 switch (adapter->rx_ps_pages) {
2989 psrctl |= PAGE_SIZE <<
2990 E1000_PSRCTL_BSIZE3_SHIFT;
2992 psrctl |= PAGE_SIZE <<
2993 E1000_PSRCTL_BSIZE2_SHIFT;
2995 psrctl |= PAGE_SIZE >>
2996 E1000_PSRCTL_BSIZE1_SHIFT;
3000 ew32(PSRCTL, psrctl);
3003 /* This is useful for sniffing bad packets. */
3004 if (adapter->netdev->features & NETIF_F_RXALL) {
3005 /* UPE and MPE will be handled by normal PROMISC logic
3006 * in e1000e_set_rx_mode */
3007 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3008 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3009 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3011 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3012 E1000_RCTL_DPF | /* Allow filtered pause */
3013 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3014 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3015 * and that breaks VLANs.
3021 /* just started the receive unit, no need to restart */
3022 adapter->flags &= ~FLAG_RX_RESTART_NOW;
3026 * e1000_configure_rx - Configure Receive Unit after Reset
3027 * @adapter: board private structure
3029 * Configure the Rx unit of the MAC after a reset.
3031 static void e1000_configure_rx(struct e1000_adapter *adapter)
3033 struct e1000_hw *hw = &adapter->hw;
3034 struct e1000_ring *rx_ring = adapter->rx_ring;
3036 u32 rdlen, rctl, rxcsum, ctrl_ext;
3038 if (adapter->rx_ps_pages) {
3039 /* this is a 32 byte descriptor */
3040 rdlen = rx_ring->count *
3041 sizeof(union e1000_rx_desc_packet_split);
3042 adapter->clean_rx = e1000_clean_rx_irq_ps;
3043 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
3044 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
3045 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3046 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3047 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
3049 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3050 adapter->clean_rx = e1000_clean_rx_irq;
3051 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3054 /* disable receives while setting up the descriptors */
3056 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3057 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3059 usleep_range(10000, 20000);
3061 if (adapter->flags2 & FLAG2_DMA_BURST) {
3063 * set the writeback threshold (only takes effect if the RDTR
3064 * is set). set GRAN=1 and write back up to 0x4 worth, and
3065 * enable prefetching of 0x20 Rx descriptors
3071 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3072 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3075 * override the delay timers for enabling bursting, only if
3076 * the value was not set by the user via module options
3078 if (adapter->rx_int_delay == DEFAULT_RDTR)
3079 adapter->rx_int_delay = BURST_RDTR;
3080 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3081 adapter->rx_abs_int_delay = BURST_RADV;
3084 /* set the Receive Delay Timer Register */
3085 ew32(RDTR, adapter->rx_int_delay);
3087 /* irq moderation */
3088 ew32(RADV, adapter->rx_abs_int_delay);
3089 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
3090 ew32(ITR, 1000000000 / (adapter->itr * 256));
3092 ctrl_ext = er32(CTRL_EXT);
3093 /* Auto-Mask interrupts upon ICR access */
3094 ctrl_ext |= E1000_CTRL_EXT_IAME;
3095 ew32(IAM, 0xffffffff);
3096 ew32(CTRL_EXT, ctrl_ext);
3100 * Setup the HW Rx Head and Tail Descriptor Pointers and
3101 * the Base and Length of the Rx Descriptor Ring
3103 rdba = rx_ring->dma;
3104 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
3105 ew32(RDBAH, (rdba >> 32));
3109 rx_ring->head = adapter->hw.hw_addr + E1000_RDH;
3110 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT;
3112 /* Enable Receive Checksum Offload for TCP and UDP */
3113 rxcsum = er32(RXCSUM);
3114 if (adapter->netdev->features & NETIF_F_RXCSUM) {
3115 rxcsum |= E1000_RXCSUM_TUOFL;
3118 * IPv4 payload checksum for UDP fragments must be
3119 * used in conjunction with packet-split.
3121 if (adapter->rx_ps_pages)
3122 rxcsum |= E1000_RXCSUM_IPPCSE;
3124 rxcsum &= ~E1000_RXCSUM_TUOFL;
3125 /* no need to clear IPPCSE as it defaults to 0 */
3127 ew32(RXCSUM, rxcsum);
3129 if (adapter->hw.mac.type == e1000_pch2lan) {
3131 * With jumbo frames, excessive C-state transition
3132 * latencies result in dropped transactions.
3134 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3135 u32 rxdctl = er32(RXDCTL(0));
3136 ew32(RXDCTL(0), rxdctl | 0x3);
3137 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
3139 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3140 PM_QOS_DEFAULT_VALUE);
3144 /* Enable Receives */
3149 * e1000e_write_mc_addr_list - write multicast addresses to MTA
3150 * @netdev: network interface device structure
3152 * Writes multicast address list to the MTA hash table.
3153 * Returns: -ENOMEM on failure
3154 * 0 on no addresses written
3155 * X on writing X addresses to MTA
3157 static int e1000e_write_mc_addr_list(struct net_device *netdev)
3159 struct e1000_adapter *adapter = netdev_priv(netdev);
3160 struct e1000_hw *hw = &adapter->hw;
3161 struct netdev_hw_addr *ha;
3165 if (netdev_mc_empty(netdev)) {
3166 /* nothing to program, so clear mc list */
3167 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3171 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3175 /* update_mc_addr_list expects a packed array of only addresses. */
3177 netdev_for_each_mc_addr(ha, netdev)
3178 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3180 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3183 return netdev_mc_count(netdev);
3187 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3188 * @netdev: network interface device structure
3190 * Writes unicast address list to the RAR table.
3191 * Returns: -ENOMEM on failure/insufficient address space
3192 * 0 on no addresses written
3193 * X on writing X addresses to the RAR table
3195 static int e1000e_write_uc_addr_list(struct net_device *netdev)
3197 struct e1000_adapter *adapter = netdev_priv(netdev);
3198 struct e1000_hw *hw = &adapter->hw;
3199 unsigned int rar_entries = hw->mac.rar_entry_count;
3202 /* save a rar entry for our hardware address */
3205 /* save a rar entry for the LAA workaround */
3206 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3209 /* return ENOMEM indicating insufficient memory for addresses */
3210 if (netdev_uc_count(netdev) > rar_entries)
3213 if (!netdev_uc_empty(netdev) && rar_entries) {
3214 struct netdev_hw_addr *ha;
3217 * write the addresses in reverse order to avoid write
3220 netdev_for_each_uc_addr(ha, netdev) {
3223 e1000e_rar_set(hw, ha->addr, rar_entries--);
3228 /* zero out the remaining RAR entries not used above */
3229 for (; rar_entries > 0; rar_entries--) {
3230 ew32(RAH(rar_entries), 0);
3231 ew32(RAL(rar_entries), 0);
3239 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3240 * @netdev: network interface device structure
3242 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3243 * address list or the network interface flags are updated. This routine is
3244 * responsible for configuring the hardware for proper unicast, multicast,
3245 * promiscuous mode, and all-multi behavior.
3247 static void e1000e_set_rx_mode(struct net_device *netdev)
3249 struct e1000_adapter *adapter = netdev_priv(netdev);
3250 struct e1000_hw *hw = &adapter->hw;
3253 /* Check for Promiscuous and All Multicast modes */
3256 /* clear the affected bits */
3257 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3259 if (netdev->flags & IFF_PROMISC) {
3260 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
3261 /* Do not hardware filter VLANs in promisc mode */
3262 e1000e_vlan_filter_disable(adapter);
3266 if (netdev->flags & IFF_ALLMULTI) {
3267 rctl |= E1000_RCTL_MPE;
3270 * Write addresses to the MTA, if the attempt fails
3271 * then we should just turn on promiscuous mode so
3272 * that we can at least receive multicast traffic
3274 count = e1000e_write_mc_addr_list(netdev);
3276 rctl |= E1000_RCTL_MPE;
3278 e1000e_vlan_filter_enable(adapter);
3280 * Write addresses to available RAR registers, if there is not
3281 * sufficient space to store all the addresses then enable
3282 * unicast promiscuous mode
3284 count = e1000e_write_uc_addr_list(netdev);
3286 rctl |= E1000_RCTL_UPE;
3291 if (netdev->features & NETIF_F_HW_VLAN_RX)
3292 e1000e_vlan_strip_enable(adapter);
3294 e1000e_vlan_strip_disable(adapter);
3297 static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3299 struct e1000_hw *hw = &adapter->hw;
3302 static const u32 rsskey[10] = {
3303 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3304 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3307 /* Fill out hash function seed */
3308 for (i = 0; i < 10; i++)
3309 ew32(RSSRK(i), rsskey[i]);
3311 /* Direct all traffic to queue 0 */
3312 for (i = 0; i < 32; i++)
3316 * Disable raw packet checksumming so that RSS hash is placed in
3317 * descriptor on writeback.
3319 rxcsum = er32(RXCSUM);
3320 rxcsum |= E1000_RXCSUM_PCSD;
3322 ew32(RXCSUM, rxcsum);
3324 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3325 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3326 E1000_MRQC_RSS_FIELD_IPV6 |
3327 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3328 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3334 * e1000_configure - configure the hardware for Rx and Tx
3335 * @adapter: private board structure
3337 static void e1000_configure(struct e1000_adapter *adapter)
3339 struct e1000_ring *rx_ring = adapter->rx_ring;
3341 e1000e_set_rx_mode(adapter->netdev);
3343 e1000_restore_vlan(adapter);
3344 e1000_init_manageability_pt(adapter);
3346 e1000_configure_tx(adapter);
3348 if (adapter->netdev->features & NETIF_F_RXHASH)
3349 e1000e_setup_rss_hash(adapter);
3350 e1000_setup_rctl(adapter);
3351 e1000_configure_rx(adapter);
3352 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
3356 * e1000e_power_up_phy - restore link in case the phy was powered down
3357 * @adapter: address of board private structure
3359 * The phy may be powered down to save power and turn off link when the
3360 * driver is unloaded and wake on lan is not enabled (among others)
3361 * *** this routine MUST be followed by a call to e1000e_reset ***
3363 void e1000e_power_up_phy(struct e1000_adapter *adapter)
3365 if (adapter->hw.phy.ops.power_up)
3366 adapter->hw.phy.ops.power_up(&adapter->hw);
3368 adapter->hw.mac.ops.setup_link(&adapter->hw);
3372 * e1000_power_down_phy - Power down the PHY
3374 * Power down the PHY so no link is implied when interface is down.
3375 * The PHY cannot be powered down if management or WoL is active.
3377 static void e1000_power_down_phy(struct e1000_adapter *adapter)
3379 /* WoL is enabled */
3383 if (adapter->hw.phy.ops.power_down)
3384 adapter->hw.phy.ops.power_down(&adapter->hw);
3388 * e1000e_reset - bring the hardware into a known good state
3390 * This function boots the hardware and enables some settings that
3391 * require a configuration cycle of the hardware - those cannot be
3392 * set/changed during runtime. After reset the device needs to be
3393 * properly configured for Rx, Tx etc.
3395 void e1000e_reset(struct e1000_adapter *adapter)
3397 struct e1000_mac_info *mac = &adapter->hw.mac;
3398 struct e1000_fc_info *fc = &adapter->hw.fc;
3399 struct e1000_hw *hw = &adapter->hw;
3400 u32 tx_space, min_tx_space, min_rx_space;
3401 u32 pba = adapter->pba;
3404 /* reset Packet Buffer Allocation to default */
3407 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
3409 * To maintain wire speed transmits, the Tx FIFO should be
3410 * large enough to accommodate two full transmit packets,
3411 * rounded up to the next 1KB and expressed in KB. Likewise,
3412 * the Rx FIFO should be large enough to accommodate at least
3413 * one full receive packet and is similarly rounded up and
3417 /* upper 16 bits has Tx packet buffer allocation size in KB */
3418 tx_space = pba >> 16;
3419 /* lower 16 bits has Rx packet buffer allocation size in KB */
3422 * the Tx fifo also stores 16 bytes of information about the Tx
3423 * but don't include ethernet FCS because hardware appends it
3425 min_tx_space = (adapter->max_frame_size +
3426 sizeof(struct e1000_tx_desc) -
3428 min_tx_space = ALIGN(min_tx_space, 1024);
3429 min_tx_space >>= 10;
3430 /* software strips receive CRC, so leave room for it */
3431 min_rx_space = adapter->max_frame_size;
3432 min_rx_space = ALIGN(min_rx_space, 1024);
3433 min_rx_space >>= 10;
3436 * If current Tx allocation is less than the min Tx FIFO size,
3437 * and the min Tx FIFO size is less than the current Rx FIFO
3438 * allocation, take space away from current Rx allocation
3440 if ((tx_space < min_tx_space) &&
3441 ((min_tx_space - tx_space) < pba)) {
3442 pba -= min_tx_space - tx_space;
3445 * if short on Rx space, Rx wins and must trump Tx
3446 * adjustment or use Early Receive if available
3448 if (pba < min_rx_space)
3456 * flow control settings
3458 * The high water mark must be low enough to fit one full frame
3459 * (or the size used for early receive) above it in the Rx FIFO.
3460 * Set it to the lower of:
3461 * - 90% of the Rx FIFO size, and
3462 * - the full Rx FIFO size minus one full frame
3464 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3465 fc->pause_time = 0xFFFF;
3467 fc->pause_time = E1000_FC_PAUSE_TIME;
3468 fc->send_xon = true;
3469 fc->current_mode = fc->requested_mode;
3471 switch (hw->mac.type) {
3473 case e1000_ich10lan:
3474 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3477 fc->high_water = 0x2800;
3478 fc->low_water = fc->high_water - 8;
3483 hwm = min(((pba << 10) * 9 / 10),
3484 ((pba << 10) - adapter->max_frame_size));
3486 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3487 fc->low_water = fc->high_water - 8;
3491 * Workaround PCH LOM adapter hangs with certain network
3492 * loads. If hangs persist, try disabling Tx flow control.
3494 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3495 fc->high_water = 0x3500;
3496 fc->low_water = 0x1500;
3498 fc->high_water = 0x5000;
3499 fc->low_water = 0x3000;
3501 fc->refresh_time = 0x1000;
3504 fc->high_water = 0x05C20;
3505 fc->low_water = 0x05048;
3506 fc->pause_time = 0x0650;
3507 fc->refresh_time = 0x0400;
3508 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3516 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3517 * fit in receive buffer.
3519 if (adapter->itr_setting & 0x3) {
3520 if ((adapter->max_frame_size * 2) > (pba << 10)) {
3521 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3522 dev_info(&adapter->pdev->dev,
3523 "Interrupt Throttle Rate turned off\n");
3524 adapter->flags2 |= FLAG2_DISABLE_AIM;
3527 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3528 dev_info(&adapter->pdev->dev,
3529 "Interrupt Throttle Rate turned on\n");
3530 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3531 adapter->itr = 20000;
3532 ew32(ITR, 1000000000 / (adapter->itr * 256));
3536 /* Allow time for pending master requests to run */
3537 mac->ops.reset_hw(hw);
3540 * For parts with AMT enabled, let the firmware know
3541 * that the network interface is in control
3543 if (adapter->flags & FLAG_HAS_AMT)
3544 e1000e_get_hw_control(adapter);
3548 if (mac->ops.init_hw(hw))
3549 e_err("Hardware Error\n");
3551 e1000_update_mng_vlan(adapter);
3553 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3554 ew32(VET, ETH_P_8021Q);
3556 e1000e_reset_adaptive(hw);
3558 if (!netif_running(adapter->netdev) &&
3559 !test_bit(__E1000_TESTING, &adapter->state)) {
3560 e1000_power_down_phy(adapter);
3564 e1000_get_phy_info(hw);
3566 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3567 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
3570 * speed up time to link by disabling smart power down, ignore
3571 * the return value of this function because there is nothing
3572 * different we would do if it failed
3574 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3575 phy_data &= ~IGP02E1000_PM_SPD;
3576 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3580 int e1000e_up(struct e1000_adapter *adapter)
3582 struct e1000_hw *hw = &adapter->hw;
3584 /* hardware has been reset, we need to reload some things */
3585 e1000_configure(adapter);
3587 clear_bit(__E1000_DOWN, &adapter->state);
3589 if (adapter->msix_entries)
3590 e1000_configure_msix(adapter);
3591 e1000_irq_enable(adapter);
3593 netif_start_queue(adapter->netdev);
3595 /* fire a link change interrupt to start the watchdog */
3596 if (adapter->msix_entries)
3597 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3599 ew32(ICS, E1000_ICS_LSC);
3604 static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3606 struct e1000_hw *hw = &adapter->hw;
3608 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3611 /* flush pending descriptor writebacks to memory */
3612 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3613 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3615 /* execute the writes immediately */
3619 static void e1000e_update_stats(struct e1000_adapter *adapter);
3621 void e1000e_down(struct e1000_adapter *adapter)
3623 struct net_device *netdev = adapter->netdev;
3624 struct e1000_hw *hw = &adapter->hw;
3628 * signal that we're down so the interrupt handler does not
3629 * reschedule our watchdog timer
3631 set_bit(__E1000_DOWN, &adapter->state);
3633 /* disable receives in the hardware */
3635 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3636 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3637 /* flush and sleep below */
3639 netif_stop_queue(netdev);
3641 /* disable transmits in the hardware */
3643 tctl &= ~E1000_TCTL_EN;
3646 /* flush both disables and wait for them to finish */
3648 usleep_range(10000, 20000);
3650 e1000_irq_disable(adapter);
3652 del_timer_sync(&adapter->watchdog_timer);
3653 del_timer_sync(&adapter->phy_info_timer);
3655 netif_carrier_off(netdev);
3657 spin_lock(&adapter->stats64_lock);
3658 e1000e_update_stats(adapter);
3659 spin_unlock(&adapter->stats64_lock);
3661 e1000e_flush_descriptors(adapter);
3662 e1000_clean_tx_ring(adapter->tx_ring);
3663 e1000_clean_rx_ring(adapter->rx_ring);
3665 adapter->link_speed = 0;
3666 adapter->link_duplex = 0;
3668 if (!pci_channel_offline(adapter->pdev))
3669 e1000e_reset(adapter);
3672 * TODO: for power management, we could drop the link and
3673 * pci_disable_device here.
3677 void e1000e_reinit_locked(struct e1000_adapter *adapter)
3680 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3681 usleep_range(1000, 2000);
3682 e1000e_down(adapter);
3684 clear_bit(__E1000_RESETTING, &adapter->state);
3688 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3689 * @adapter: board private structure to initialize
3691 * e1000_sw_init initializes the Adapter private data structure.
3692 * Fields are initialized based on PCI device information and
3693 * OS network device settings (MTU size).
3695 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3697 struct net_device *netdev = adapter->netdev;
3699 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3700 adapter->rx_ps_bsize0 = 128;
3701 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3702 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
3703 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3704 adapter->rx_ring_count = E1000_DEFAULT_RXD;
3706 spin_lock_init(&adapter->stats64_lock);
3708 e1000e_set_interrupt_capability(adapter);
3710 if (e1000_alloc_queues(adapter))
3713 /* Explicitly disable IRQ since the NIC can be in any state. */
3714 e1000_irq_disable(adapter);
3716 set_bit(__E1000_DOWN, &adapter->state);
3721 * e1000_intr_msi_test - Interrupt Handler
3722 * @irq: interrupt number
3723 * @data: pointer to a network interface device structure
3725 static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3727 struct net_device *netdev = data;
3728 struct e1000_adapter *adapter = netdev_priv(netdev);
3729 struct e1000_hw *hw = &adapter->hw;
3730 u32 icr = er32(ICR);
3732 e_dbg("icr is %08X\n", icr);
3733 if (icr & E1000_ICR_RXSEQ) {
3734 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3742 * e1000_test_msi_interrupt - Returns 0 for successful test
3743 * @adapter: board private struct
3745 * code flow taken from tg3.c
3747 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3749 struct net_device *netdev = adapter->netdev;
3750 struct e1000_hw *hw = &adapter->hw;
3753 /* poll_enable hasn't been called yet, so don't need disable */
3754 /* clear any pending events */
3757 /* free the real vector and request a test handler */
3758 e1000_free_irq(adapter);
3759 e1000e_reset_interrupt_capability(adapter);
3761 /* Assume that the test fails, if it succeeds then the test
3762 * MSI irq handler will unset this flag */
3763 adapter->flags |= FLAG_MSI_TEST_FAILED;
3765 err = pci_enable_msi(adapter->pdev);
3767 goto msi_test_failed;
3769 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
3770 netdev->name, netdev);
3772 pci_disable_msi(adapter->pdev);
3773 goto msi_test_failed;
3778 e1000_irq_enable(adapter);
3780 /* fire an unusual interrupt on the test handler */
3781 ew32(ICS, E1000_ICS_RXSEQ);
3785 e1000_irq_disable(adapter);
3789 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
3790 adapter->int_mode = E1000E_INT_MODE_LEGACY;
3791 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3793 e_dbg("MSI interrupt test succeeded!\n");
3796 free_irq(adapter->pdev->irq, netdev);
3797 pci_disable_msi(adapter->pdev);
3800 e1000e_set_interrupt_capability(adapter);
3801 return e1000_request_irq(adapter);
3805 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3806 * @adapter: board private struct
3808 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3810 static int e1000_test_msi(struct e1000_adapter *adapter)
3815 if (!(adapter->flags & FLAG_MSI_ENABLED))
3818 /* disable SERR in case the MSI write causes a master abort */
3819 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3820 if (pci_cmd & PCI_COMMAND_SERR)
3821 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3822 pci_cmd & ~PCI_COMMAND_SERR);
3824 err = e1000_test_msi_interrupt(adapter);
3826 /* re-enable SERR */
3827 if (pci_cmd & PCI_COMMAND_SERR) {
3828 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3829 pci_cmd |= PCI_COMMAND_SERR;
3830 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3837 * e1000_open - Called when a network interface is made active
3838 * @netdev: network interface device structure
3840 * Returns 0 on success, negative value on failure
3842 * The open entry point is called when a network interface is made
3843 * active by the system (IFF_UP). At this point all resources needed
3844 * for transmit and receive operations are allocated, the interrupt
3845 * handler is registered with the OS, the watchdog timer is started,
3846 * and the stack is notified that the interface is ready.
3848 static int e1000_open(struct net_device *netdev)
3850 struct e1000_adapter *adapter = netdev_priv(netdev);
3851 struct e1000_hw *hw = &adapter->hw;
3852 struct pci_dev *pdev = adapter->pdev;
3855 /* disallow open during test */
3856 if (test_bit(__E1000_TESTING, &adapter->state))
3859 pm_runtime_get_sync(&pdev->dev);
3861 netif_carrier_off(netdev);
3863 /* allocate transmit descriptors */
3864 err = e1000e_setup_tx_resources(adapter->tx_ring);
3868 /* allocate receive descriptors */
3869 err = e1000e_setup_rx_resources(adapter->rx_ring);
3874 * If AMT is enabled, let the firmware know that the network
3875 * interface is now open and reset the part to a known state.
3877 if (adapter->flags & FLAG_HAS_AMT) {
3878 e1000e_get_hw_control(adapter);
3879 e1000e_reset(adapter);
3882 e1000e_power_up_phy(adapter);
3884 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3885 if ((adapter->hw.mng_cookie.status &
3886 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3887 e1000_update_mng_vlan(adapter);
3889 /* DMA latency requirement to workaround jumbo issue */
3890 if (adapter->hw.mac.type == e1000_pch2lan)
3891 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3892 PM_QOS_CPU_DMA_LATENCY,
3893 PM_QOS_DEFAULT_VALUE);
3896 * before we allocate an interrupt, we must be ready to handle it.
3897 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3898 * as soon as we call pci_request_irq, so we have to setup our
3899 * clean_rx handler before we do so.
3901 e1000_configure(adapter);
3903 err = e1000_request_irq(adapter);
3908 * Work around PCIe errata with MSI interrupts causing some chipsets to
3909 * ignore e1000e MSI messages, which means we need to test our MSI
3912 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
3913 err = e1000_test_msi(adapter);
3915 e_err("Interrupt allocation failed\n");
3920 /* From here on the code is the same as e1000e_up() */
3921 clear_bit(__E1000_DOWN, &adapter->state);
3923 napi_enable(&adapter->napi);
3925 e1000_irq_enable(adapter);
3927 adapter->tx_hang_recheck = false;
3928 netif_start_queue(netdev);
3930 adapter->idle_check = true;
3931 pm_runtime_put(&pdev->dev);
3933 /* fire a link status change interrupt to start the watchdog */
3934 if (adapter->msix_entries)
3935 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3937 ew32(ICS, E1000_ICS_LSC);
3942 e1000e_release_hw_control(adapter);
3943 e1000_power_down_phy(adapter);
3944 e1000e_free_rx_resources(adapter->rx_ring);
3946 e1000e_free_tx_resources(adapter->tx_ring);
3948 e1000e_reset(adapter);
3949 pm_runtime_put_sync(&pdev->dev);
3955 * e1000_close - Disables a network interface
3956 * @netdev: network interface device structure
3958 * Returns 0, this is not allowed to fail
3960 * The close entry point is called when an interface is de-activated
3961 * by the OS. The hardware is still under the drivers control, but
3962 * needs to be disabled. A global MAC reset is issued to stop the
3963 * hardware, and all transmit and receive resources are freed.
3965 static int e1000_close(struct net_device *netdev)
3967 struct e1000_adapter *adapter = netdev_priv(netdev);
3968 struct pci_dev *pdev = adapter->pdev;
3970 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3972 pm_runtime_get_sync(&pdev->dev);
3974 napi_disable(&adapter->napi);
3976 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3977 e1000e_down(adapter);
3978 e1000_free_irq(adapter);
3980 e1000_power_down_phy(adapter);
3982 e1000e_free_tx_resources(adapter->tx_ring);
3983 e1000e_free_rx_resources(adapter->rx_ring);
3986 * kill manageability vlan ID if supported, but not if a vlan with
3987 * the same ID is registered on the host OS (let 8021q kill it)
3989 if (adapter->hw.mng_cookie.status &
3990 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
3991 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3994 * If AMT is enabled, let the firmware know that the network
3995 * interface is now closed
3997 if ((adapter->flags & FLAG_HAS_AMT) &&
3998 !test_bit(__E1000_TESTING, &adapter->state))
3999 e1000e_release_hw_control(adapter);
4001 if (adapter->hw.mac.type == e1000_pch2lan)
4002 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
4004 pm_runtime_put_sync(&pdev->dev);
4009 * e1000_set_mac - Change the Ethernet Address of the NIC
4010 * @netdev: network interface device structure
4011 * @p: pointer to an address structure
4013 * Returns 0 on success, negative on failure
4015 static int e1000_set_mac(struct net_device *netdev, void *p)
4017 struct e1000_adapter *adapter = netdev_priv(netdev);
4018 struct sockaddr *addr = p;
4020 if (!is_valid_ether_addr(addr->sa_data))
4021 return -EADDRNOTAVAIL;
4023 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4024 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4026 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
4028 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4029 /* activate the work around */
4030 e1000e_set_laa_state_82571(&adapter->hw, 1);
4033 * Hold a copy of the LAA in RAR[14] This is done so that
4034 * between the time RAR[0] gets clobbered and the time it
4035 * gets fixed (in e1000_watchdog), the actual LAA is in one
4036 * of the RARs and no incoming packets directed to this port
4037 * are dropped. Eventually the LAA will be in RAR[0] and
4040 e1000e_rar_set(&adapter->hw,
4041 adapter->hw.mac.addr,
4042 adapter->hw.mac.rar_entry_count - 1);
4049 * e1000e_update_phy_task - work thread to update phy
4050 * @work: pointer to our work struct
4052 * this worker thread exists because we must acquire a
4053 * semaphore to read the phy, which we could msleep while
4054 * waiting for it, and we can't msleep in a timer.
4056 static void e1000e_update_phy_task(struct work_struct *work)
4058 struct e1000_adapter *adapter = container_of(work,
4059 struct e1000_adapter, update_phy_task);
4061 if (test_bit(__E1000_DOWN, &adapter->state))
4064 e1000_get_phy_info(&adapter->hw);
4068 * Need to wait a few seconds after link up to get diagnostic information from
4071 static void e1000_update_phy_info(unsigned long data)
4073 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4075 if (test_bit(__E1000_DOWN, &adapter->state))
4078 schedule_work(&adapter->update_phy_task);
4082 * e1000e_update_phy_stats - Update the PHY statistics counters
4083 * @adapter: board private structure
4085 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
4087 static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4089 struct e1000_hw *hw = &adapter->hw;
4093 ret_val = hw->phy.ops.acquire(hw);
4098 * A page set is expensive so check if already on desired page.
4099 * If not, set to the page with the PHY status registers.
4102 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4106 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4107 ret_val = hw->phy.ops.set_page(hw,
4108 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4113 /* Single Collision Count */
4114 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4115 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4117 adapter->stats.scc += phy_data;
4119 /* Excessive Collision Count */
4120 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4121 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4123 adapter->stats.ecol += phy_data;
4125 /* Multiple Collision Count */
4126 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4127 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4129 adapter->stats.mcc += phy_data;
4131 /* Late Collision Count */
4132 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4133 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4135 adapter->stats.latecol += phy_data;
4137 /* Collision Count - also used for adaptive IFS */
4138 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4139 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4141 hw->mac.collision_delta = phy_data;
4144 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4145 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4147 adapter->stats.dc += phy_data;
4149 /* Transmit with no CRS */
4150 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4151 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4153 adapter->stats.tncrs += phy_data;
4156 hw->phy.ops.release(hw);
4160 * e1000e_update_stats - Update the board statistics counters
4161 * @adapter: board private structure
4163 static void e1000e_update_stats(struct e1000_adapter *adapter)
4165 struct net_device *netdev = adapter->netdev;
4166 struct e1000_hw *hw = &adapter->hw;
4167 struct pci_dev *pdev = adapter->pdev;
4170 * Prevent stats update while adapter is being reset, or if the pci
4171 * connection is down.
4173 if (adapter->link_speed == 0)
4175 if (pci_channel_offline(pdev))
4178 adapter->stats.crcerrs += er32(CRCERRS);
4179 adapter->stats.gprc += er32(GPRC);
4180 adapter->stats.gorc += er32(GORCL);
4181 er32(GORCH); /* Clear gorc */
4182 adapter->stats.bprc += er32(BPRC);
4183 adapter->stats.mprc += er32(MPRC);
4184 adapter->stats.roc += er32(ROC);
4186 adapter->stats.mpc += er32(MPC);
4188 /* Half-duplex statistics */
4189 if (adapter->link_duplex == HALF_DUPLEX) {
4190 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4191 e1000e_update_phy_stats(adapter);
4193 adapter->stats.scc += er32(SCC);
4194 adapter->stats.ecol += er32(ECOL);
4195 adapter->stats.mcc += er32(MCC);
4196 adapter->stats.latecol += er32(LATECOL);
4197 adapter->stats.dc += er32(DC);
4199 hw->mac.collision_delta = er32(COLC);
4201 if ((hw->mac.type != e1000_82574) &&
4202 (hw->mac.type != e1000_82583))
4203 adapter->stats.tncrs += er32(TNCRS);
4205 adapter->stats.colc += hw->mac.collision_delta;
4208 adapter->stats.xonrxc += er32(XONRXC);
4209 adapter->stats.xontxc += er32(XONTXC);
4210 adapter->stats.xoffrxc += er32(XOFFRXC);
4211 adapter->stats.xofftxc += er32(XOFFTXC);
4212 adapter->stats.gptc += er32(GPTC);
4213 adapter->stats.gotc += er32(GOTCL);
4214 er32(GOTCH); /* Clear gotc */
4215 adapter->stats.rnbc += er32(RNBC);
4216 adapter->stats.ruc += er32(RUC);
4218 adapter->stats.mptc += er32(MPTC);
4219 adapter->stats.bptc += er32(BPTC);
4221 /* used for adaptive IFS */
4223 hw->mac.tx_packet_delta = er32(TPT);
4224 adapter->stats.tpt += hw->mac.tx_packet_delta;
4226 adapter->stats.algnerrc += er32(ALGNERRC);
4227 adapter->stats.rxerrc += er32(RXERRC);
4228 adapter->stats.cexterr += er32(CEXTERR);
4229 adapter->stats.tsctc += er32(TSCTC);
4230 adapter->stats.tsctfc += er32(TSCTFC);
4232 /* Fill out the OS statistics structure */
4233 netdev->stats.multicast = adapter->stats.mprc;
4234 netdev->stats.collisions = adapter->stats.colc;
4239 * RLEC on some newer hardware can be incorrect so build
4240 * our own version based on RUC and ROC
4242 netdev->stats.rx_errors = adapter->stats.rxerrc +
4243 adapter->stats.crcerrs + adapter->stats.algnerrc +
4244 adapter->stats.ruc + adapter->stats.roc +
4245 adapter->stats.cexterr;
4246 netdev->stats.rx_length_errors = adapter->stats.ruc +
4248 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4249 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4250 netdev->stats.rx_missed_errors = adapter->stats.mpc;
4253 netdev->stats.tx_errors = adapter->stats.ecol +
4254 adapter->stats.latecol;
4255 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4256 netdev->stats.tx_window_errors = adapter->stats.latecol;
4257 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
4259 /* Tx Dropped needs to be maintained elsewhere */
4261 /* Management Stats */
4262 adapter->stats.mgptc += er32(MGTPTC);
4263 adapter->stats.mgprc += er32(MGTPRC);
4264 adapter->stats.mgpdc += er32(MGTPDC);
4268 * e1000_phy_read_status - Update the PHY register status snapshot
4269 * @adapter: board private structure
4271 static void e1000_phy_read_status(struct e1000_adapter *adapter)
4273 struct e1000_hw *hw = &adapter->hw;
4274 struct e1000_phy_regs *phy = &adapter->phy_regs;
4276 if ((er32(STATUS) & E1000_STATUS_LU) &&
4277 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
4280 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4281 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4282 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4283 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4284 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4285 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4286 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4287 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4289 e_warn("Error reading PHY register\n");
4292 * Do not read PHY registers if link is not up
4293 * Set values to typical power-on defaults
4295 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4296 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4297 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4299 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4300 ADVERTISE_ALL | ADVERTISE_CSMA);
4302 phy->expansion = EXPANSION_ENABLENPAGE;
4303 phy->ctrl1000 = ADVERTISE_1000FULL;
4305 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4309 static void e1000_print_link_info(struct e1000_adapter *adapter)
4311 struct e1000_hw *hw = &adapter->hw;
4312 u32 ctrl = er32(CTRL);
4314 /* Link status message must follow this format for user tools */
4315 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4316 adapter->netdev->name,
4317 adapter->link_speed,
4318 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4319 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4320 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4321 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
4324 static bool e1000e_has_link(struct e1000_adapter *adapter)
4326 struct e1000_hw *hw = &adapter->hw;
4327 bool link_active = false;
4331 * get_link_status is set on LSC (link status) interrupt or
4332 * Rx sequence error interrupt. get_link_status will stay
4333 * false until the check_for_link establishes link
4334 * for copper adapters ONLY
4336 switch (hw->phy.media_type) {
4337 case e1000_media_type_copper:
4338 if (hw->mac.get_link_status) {
4339 ret_val = hw->mac.ops.check_for_link(hw);
4340 link_active = !hw->mac.get_link_status;
4345 case e1000_media_type_fiber:
4346 ret_val = hw->mac.ops.check_for_link(hw);
4347 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4349 case e1000_media_type_internal_serdes:
4350 ret_val = hw->mac.ops.check_for_link(hw);
4351 link_active = adapter->hw.mac.serdes_has_link;
4354 case e1000_media_type_unknown:
4358 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4359 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4360 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
4361 e_info("Gigabit has been disabled, downgrading speed\n");
4367 static void e1000e_enable_receives(struct e1000_adapter *adapter)
4369 /* make sure the receive unit is started */
4370 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4371 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4372 struct e1000_hw *hw = &adapter->hw;
4373 u32 rctl = er32(RCTL);
4374 ew32(RCTL, rctl | E1000_RCTL_EN);
4375 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4379 static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4381 struct e1000_hw *hw = &adapter->hw;
4384 * With 82574 controllers, PHY needs to be checked periodically
4385 * for hung state and reset, if two calls return true
4387 if (e1000_check_phy_82574(hw))
4388 adapter->phy_hang_count++;
4390 adapter->phy_hang_count = 0;
4392 if (adapter->phy_hang_count > 1) {
4393 adapter->phy_hang_count = 0;
4394 schedule_work(&adapter->reset_task);
4399 * e1000_watchdog - Timer Call-back
4400 * @data: pointer to adapter cast into an unsigned long
4402 static void e1000_watchdog(unsigned long data)
4404 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4406 /* Do the rest outside of interrupt context */
4407 schedule_work(&adapter->watchdog_task);
4409 /* TODO: make this use queue_delayed_work() */
4412 static void e1000_watchdog_task(struct work_struct *work)
4414 struct e1000_adapter *adapter = container_of(work,
4415 struct e1000_adapter, watchdog_task);
4416 struct net_device *netdev = adapter->netdev;
4417 struct e1000_mac_info *mac = &adapter->hw.mac;
4418 struct e1000_phy_info *phy = &adapter->hw.phy;
4419 struct e1000_ring *tx_ring = adapter->tx_ring;
4420 struct e1000_hw *hw = &adapter->hw;
4423 if (test_bit(__E1000_DOWN, &adapter->state))
4426 link = e1000e_has_link(adapter);
4427 if ((netif_carrier_ok(netdev)) && link) {
4428 /* Cancel scheduled suspend requests. */
4429 pm_runtime_resume(netdev->dev.parent);
4431 e1000e_enable_receives(adapter);
4435 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4436 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4437 e1000_update_mng_vlan(adapter);
4440 if (!netif_carrier_ok(netdev)) {
4443 /* Cancel scheduled suspend requests. */
4444 pm_runtime_resume(netdev->dev.parent);
4446 /* update snapshot of PHY registers on LSC */
4447 e1000_phy_read_status(adapter);
4448 mac->ops.get_link_up_info(&adapter->hw,
4449 &adapter->link_speed,
4450 &adapter->link_duplex);
4451 e1000_print_link_info(adapter);
4453 * On supported PHYs, check for duplex mismatch only
4454 * if link has autonegotiated at 10/100 half
4456 if ((hw->phy.type == e1000_phy_igp_3 ||
4457 hw->phy.type == e1000_phy_bm) &&
4458 (hw->mac.autoneg == true) &&
4459 (adapter->link_speed == SPEED_10 ||
4460 adapter->link_speed == SPEED_100) &&
4461 (adapter->link_duplex == HALF_DUPLEX)) {
4464 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4466 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4467 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
4470 /* adjust timeout factor according to speed/duplex */
4471 adapter->tx_timeout_factor = 1;
4472 switch (adapter->link_speed) {
4475 adapter->tx_timeout_factor = 16;
4479 adapter->tx_timeout_factor = 10;
4484 * workaround: re-program speed mode bit after
4487 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4490 tarc0 = er32(TARC(0));
4491 tarc0 &= ~SPEED_MODE_BIT;
4492 ew32(TARC(0), tarc0);
4496 * disable TSO for pcie and 10/100 speeds, to avoid
4497 * some hardware issues
4499 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4500 switch (adapter->link_speed) {
4503 e_info("10/100 speed: disabling TSO\n");
4504 netdev->features &= ~NETIF_F_TSO;
4505 netdev->features &= ~NETIF_F_TSO6;
4508 netdev->features |= NETIF_F_TSO;
4509 netdev->features |= NETIF_F_TSO6;
4518 * enable transmits in the hardware, need to do this
4519 * after setting TARC(0)
4522 tctl |= E1000_TCTL_EN;
4526 * Perform any post-link-up configuration before
4527 * reporting link up.
4529 if (phy->ops.cfg_on_link_up)
4530 phy->ops.cfg_on_link_up(hw);
4532 netif_carrier_on(netdev);
4534 if (!test_bit(__E1000_DOWN, &adapter->state))
4535 mod_timer(&adapter->phy_info_timer,
4536 round_jiffies(jiffies + 2 * HZ));
4539 if (netif_carrier_ok(netdev)) {
4540 adapter->link_speed = 0;
4541 adapter->link_duplex = 0;
4542 /* Link status message must follow this format */
4543 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4544 adapter->netdev->name);
4545 netif_carrier_off(netdev);
4546 if (!test_bit(__E1000_DOWN, &adapter->state))
4547 mod_timer(&adapter->phy_info_timer,
4548 round_jiffies(jiffies + 2 * HZ));
4550 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4551 schedule_work(&adapter->reset_task);
4553 pm_schedule_suspend(netdev->dev.parent,
4559 spin_lock(&adapter->stats64_lock);
4560 e1000e_update_stats(adapter);
4562 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4563 adapter->tpt_old = adapter->stats.tpt;
4564 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4565 adapter->colc_old = adapter->stats.colc;
4567 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4568 adapter->gorc_old = adapter->stats.gorc;
4569 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4570 adapter->gotc_old = adapter->stats.gotc;
4571 spin_unlock(&adapter->stats64_lock);
4573 e1000e_update_adaptive(&adapter->hw);
4575 if (!netif_carrier_ok(netdev) &&
4576 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4578 * We've lost link, so the controller stops DMA,
4579 * but we've got queued Tx work that's never going
4580 * to get done, so reset controller to flush Tx.
4581 * (Do the reset outside of interrupt context).
4583 schedule_work(&adapter->reset_task);
4584 /* return immediately since reset is imminent */
4588 /* Simple mode for Interrupt Throttle Rate (ITR) */
4589 if (adapter->itr_setting == 4) {
4591 * Symmetric Tx/Rx gets a reduced ITR=2000;
4592 * Total asymmetrical Tx or Rx gets ITR=8000;
4593 * everyone else is between 2000-8000.
4595 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4596 u32 dif = (adapter->gotc > adapter->gorc ?
4597 adapter->gotc - adapter->gorc :
4598 adapter->gorc - adapter->gotc) / 10000;
4599 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4601 ew32(ITR, 1000000000 / (itr * 256));
4604 /* Cause software interrupt to ensure Rx ring is cleaned */
4605 if (adapter->msix_entries)
4606 ew32(ICS, adapter->rx_ring->ims_val);
4608 ew32(ICS, E1000_ICS_RXDMT0);
4610 /* flush pending descriptors to memory before detecting Tx hang */
4611 e1000e_flush_descriptors(adapter);
4613 /* Force detection of hung controller every watchdog period */
4614 adapter->detect_tx_hung = true;
4617 * With 82571 controllers, LAA may be overwritten due to controller
4618 * reset from the other port. Set the appropriate LAA in RAR[0]
4620 if (e1000e_get_laa_state_82571(hw))
4621 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4623 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4624 e1000e_check_82574_phy_workaround(adapter);
4626 /* Reset the timer */
4627 if (!test_bit(__E1000_DOWN, &adapter->state))
4628 mod_timer(&adapter->watchdog_timer,
4629 round_jiffies(jiffies + 2 * HZ));
4632 #define E1000_TX_FLAGS_CSUM 0x00000001
4633 #define E1000_TX_FLAGS_VLAN 0x00000002
4634 #define E1000_TX_FLAGS_TSO 0x00000004
4635 #define E1000_TX_FLAGS_IPV4 0x00000008
4636 #define E1000_TX_FLAGS_NO_FCS 0x00000010
4637 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4638 #define E1000_TX_FLAGS_VLAN_SHIFT 16
4640 static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
4642 struct e1000_context_desc *context_desc;
4643 struct e1000_buffer *buffer_info;
4646 u16 ipcse = 0, tucse, mss;
4647 u8 ipcss, ipcso, tucss, tucso, hdr_len;
4649 if (!skb_is_gso(skb))
4652 if (skb_header_cloned(skb)) {
4653 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4659 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4660 mss = skb_shinfo(skb)->gso_size;
4661 if (skb->protocol == htons(ETH_P_IP)) {
4662 struct iphdr *iph = ip_hdr(skb);
4665 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4667 cmd_length = E1000_TXD_CMD_IP;
4668 ipcse = skb_transport_offset(skb) - 1;
4669 } else if (skb_is_gso_v6(skb)) {
4670 ipv6_hdr(skb)->payload_len = 0;
4671 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4672 &ipv6_hdr(skb)->daddr,
4676 ipcss = skb_network_offset(skb);
4677 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4678 tucss = skb_transport_offset(skb);
4679 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4682 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4683 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4685 i = tx_ring->next_to_use;
4686 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4687 buffer_info = &tx_ring->buffer_info[i];
4689 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4690 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4691 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4692 context_desc->upper_setup.tcp_fields.tucss = tucss;
4693 context_desc->upper_setup.tcp_fields.tucso = tucso;
4694 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4695 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4696 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4697 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4699 buffer_info->time_stamp = jiffies;
4700 buffer_info->next_to_watch = i;
4703 if (i == tx_ring->count)
4705 tx_ring->next_to_use = i;
4710 static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
4712 struct e1000_adapter *adapter = tx_ring->adapter;
4713 struct e1000_context_desc *context_desc;
4714 struct e1000_buffer *buffer_info;
4717 u32 cmd_len = E1000_TXD_CMD_DEXT;
4720 if (skb->ip_summed != CHECKSUM_PARTIAL)
4723 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4724 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4726 protocol = skb->protocol;
4729 case cpu_to_be16(ETH_P_IP):
4730 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4731 cmd_len |= E1000_TXD_CMD_TCP;
4733 case cpu_to_be16(ETH_P_IPV6):
4734 /* XXX not handling all IPV6 headers */
4735 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4736 cmd_len |= E1000_TXD_CMD_TCP;
4739 if (unlikely(net_ratelimit()))
4740 e_warn("checksum_partial proto=%x!\n",
4741 be16_to_cpu(protocol));
4745 css = skb_checksum_start_offset(skb);
4747 i = tx_ring->next_to_use;
4748 buffer_info = &tx_ring->buffer_info[i];
4749 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4751 context_desc->lower_setup.ip_config = 0;
4752 context_desc->upper_setup.tcp_fields.tucss = css;
4753 context_desc->upper_setup.tcp_fields.tucso =
4754 css + skb->csum_offset;
4755 context_desc->upper_setup.tcp_fields.tucse = 0;
4756 context_desc->tcp_seg_setup.data = 0;
4757 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4759 buffer_info->time_stamp = jiffies;
4760 buffer_info->next_to_watch = i;
4763 if (i == tx_ring->count)
4765 tx_ring->next_to_use = i;
4770 #define E1000_MAX_PER_TXD 8192
4771 #define E1000_MAX_TXD_PWR 12
4773 static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
4774 unsigned int first, unsigned int max_per_txd,
4775 unsigned int nr_frags, unsigned int mss)
4777 struct e1000_adapter *adapter = tx_ring->adapter;
4778 struct pci_dev *pdev = adapter->pdev;
4779 struct e1000_buffer *buffer_info;
4780 unsigned int len = skb_headlen(skb);
4781 unsigned int offset = 0, size, count = 0, i;
4782 unsigned int f, bytecount, segs;
4784 i = tx_ring->next_to_use;
4787 buffer_info = &tx_ring->buffer_info[i];
4788 size = min(len, max_per_txd);
4790 buffer_info->length = size;
4791 buffer_info->time_stamp = jiffies;
4792 buffer_info->next_to_watch = i;
4793 buffer_info->dma = dma_map_single(&pdev->dev,
4795 size, DMA_TO_DEVICE);
4796 buffer_info->mapped_as_page = false;
4797 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4806 if (i == tx_ring->count)
4811 for (f = 0; f < nr_frags; f++) {
4812 const struct skb_frag_struct *frag;
4814 frag = &skb_shinfo(skb)->frags[f];
4815 len = skb_frag_size(frag);
4820 if (i == tx_ring->count)
4823 buffer_info = &tx_ring->buffer_info[i];
4824 size = min(len, max_per_txd);
4826 buffer_info->length = size;
4827 buffer_info->time_stamp = jiffies;
4828 buffer_info->next_to_watch = i;
4829 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4830 offset, size, DMA_TO_DEVICE);
4831 buffer_info->mapped_as_page = true;
4832 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4841 segs = skb_shinfo(skb)->gso_segs ? : 1;
4842 /* multiply data chunks by size of headers */
4843 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4845 tx_ring->buffer_info[i].skb = skb;
4846 tx_ring->buffer_info[i].segs = segs;
4847 tx_ring->buffer_info[i].bytecount = bytecount;
4848 tx_ring->buffer_info[first].next_to_watch = i;
4853 dev_err(&pdev->dev, "Tx DMA map failed\n");
4854 buffer_info->dma = 0;
4860 i += tx_ring->count;
4862 buffer_info = &tx_ring->buffer_info[i];
4863 e1000_put_txbuf(tx_ring, buffer_info);
4869 static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
4871 struct e1000_adapter *adapter = tx_ring->adapter;
4872 struct e1000_tx_desc *tx_desc = NULL;
4873 struct e1000_buffer *buffer_info;
4874 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4877 if (tx_flags & E1000_TX_FLAGS_TSO) {
4878 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4880 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4882 if (tx_flags & E1000_TX_FLAGS_IPV4)
4883 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4886 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4887 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4888 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4891 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4892 txd_lower |= E1000_TXD_CMD_VLE;
4893 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4896 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4897 txd_lower &= ~(E1000_TXD_CMD_IFCS);
4899 i = tx_ring->next_to_use;
4902 buffer_info = &tx_ring->buffer_info[i];
4903 tx_desc = E1000_TX_DESC(*tx_ring, i);
4904 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4905 tx_desc->lower.data =
4906 cpu_to_le32(txd_lower | buffer_info->length);
4907 tx_desc->upper.data = cpu_to_le32(txd_upper);
4910 if (i == tx_ring->count)
4912 } while (--count > 0);
4914 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4916 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
4917 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4918 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
4921 * Force memory writes to complete before letting h/w
4922 * know there are new descriptors to fetch. (Only
4923 * applicable for weak-ordered memory model archs,
4928 tx_ring->next_to_use = i;
4930 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4931 e1000e_update_tdt_wa(tx_ring, i);
4933 writel(i, tx_ring->tail);
4936 * we need this if more than one processor can write to our tail
4937 * at a time, it synchronizes IO on IA64/Altix systems
4942 #define MINIMUM_DHCP_PACKET_SIZE 282
4943 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4944 struct sk_buff *skb)
4946 struct e1000_hw *hw = &adapter->hw;
4949 if (vlan_tx_tag_present(skb)) {
4950 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4951 (adapter->hw.mng_cookie.status &
4952 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4956 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4959 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4963 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4966 if (ip->protocol != IPPROTO_UDP)
4969 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4970 if (ntohs(udp->dest) != 67)
4973 offset = (u8 *)udp + 8 - skb->data;
4974 length = skb->len - offset;
4975 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4981 static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
4983 struct e1000_adapter *adapter = tx_ring->adapter;
4985 netif_stop_queue(adapter->netdev);
4987 * Herbert's original patch had:
4988 * smp_mb__after_netif_stop_queue();
4989 * but since that doesn't exist yet, just open code it.
4994 * We need to check again in a case another CPU has just
4995 * made room available.
4997 if (e1000_desc_unused(tx_ring) < size)
5001 netif_start_queue(adapter->netdev);
5002 ++adapter->restart_queue;
5006 static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
5008 if (e1000_desc_unused(tx_ring) >= size)
5010 return __e1000_maybe_stop_tx(tx_ring, size);
5013 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1)
5014 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5015 struct net_device *netdev)
5017 struct e1000_adapter *adapter = netdev_priv(netdev);
5018 struct e1000_ring *tx_ring = adapter->tx_ring;
5020 unsigned int max_per_txd = E1000_MAX_PER_TXD;
5021 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
5022 unsigned int tx_flags = 0;
5023 unsigned int len = skb_headlen(skb);
5024 unsigned int nr_frags;
5030 if (test_bit(__E1000_DOWN, &adapter->state)) {
5031 dev_kfree_skb_any(skb);
5032 return NETDEV_TX_OK;
5035 if (skb->len <= 0) {
5036 dev_kfree_skb_any(skb);
5037 return NETDEV_TX_OK;
5040 mss = skb_shinfo(skb)->gso_size;
5042 * The controller does a simple calculation to
5043 * make sure there is enough room in the FIFO before
5044 * initiating the DMA for each buffer. The calc is:
5045 * 4 = ceil(buffer len/mss). To make sure we don't
5046 * overrun the FIFO, adjust the max buffer len if mss
5051 max_per_txd = min(mss << 2, max_per_txd);
5052 max_txd_pwr = fls(max_per_txd) - 1;
5055 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
5056 * points to just header, pull a few bytes of payload from
5057 * frags into skb->data
5059 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5061 * we do this workaround for ES2LAN, but it is un-necessary,
5062 * avoiding it could save a lot of cycles
5064 if (skb->data_len && (hdr_len == len)) {
5065 unsigned int pull_size;
5067 pull_size = min_t(unsigned int, 4, skb->data_len);
5068 if (!__pskb_pull_tail(skb, pull_size)) {
5069 e_err("__pskb_pull_tail failed.\n");
5070 dev_kfree_skb_any(skb);
5071 return NETDEV_TX_OK;
5073 len = skb_headlen(skb);
5077 /* reserve a descriptor for the offload context */
5078 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5082 count += TXD_USE_COUNT(len, max_txd_pwr);
5084 nr_frags = skb_shinfo(skb)->nr_frags;
5085 for (f = 0; f < nr_frags; f++)
5086 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5089 if (adapter->hw.mac.tx_pkt_filtering)
5090 e1000_transfer_dhcp_info(adapter, skb);
5093 * need: count + 2 desc gap to keep tail from touching
5094 * head, otherwise try next time
5096 if (e1000_maybe_stop_tx(tx_ring, count + 2))
5097 return NETDEV_TX_BUSY;
5099 if (vlan_tx_tag_present(skb)) {
5100 tx_flags |= E1000_TX_FLAGS_VLAN;
5101 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5104 first = tx_ring->next_to_use;
5106 tso = e1000_tso(tx_ring, skb);
5108 dev_kfree_skb_any(skb);
5109 return NETDEV_TX_OK;
5113 tx_flags |= E1000_TX_FLAGS_TSO;
5114 else if (e1000_tx_csum(tx_ring, skb))
5115 tx_flags |= E1000_TX_FLAGS_CSUM;
5118 * Old method was to assume IPv4 packet by default if TSO was enabled.
5119 * 82571 hardware supports TSO capabilities for IPv6 as well...
5120 * no longer assume, we must.
5122 if (skb->protocol == htons(ETH_P_IP))
5123 tx_flags |= E1000_TX_FLAGS_IPV4;
5125 if (unlikely(skb->no_fcs))
5126 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5128 /* if count is 0 then mapping error has occurred */
5129 count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss);
5131 netdev_sent_queue(netdev, skb->len);
5132 e1000_tx_queue(tx_ring, tx_flags, count);
5133 /* Make sure there is space in the ring for the next send. */
5134 e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2);
5137 dev_kfree_skb_any(skb);
5138 tx_ring->buffer_info[first].time_stamp = 0;
5139 tx_ring->next_to_use = first;
5142 return NETDEV_TX_OK;
5146 * e1000_tx_timeout - Respond to a Tx Hang
5147 * @netdev: network interface device structure
5149 static void e1000_tx_timeout(struct net_device *netdev)
5151 struct e1000_adapter *adapter = netdev_priv(netdev);
5153 /* Do the reset outside of interrupt context */
5154 adapter->tx_timeout_count++;
5155 schedule_work(&adapter->reset_task);
5158 static void e1000_reset_task(struct work_struct *work)
5160 struct e1000_adapter *adapter;
5161 adapter = container_of(work, struct e1000_adapter, reset_task);
5163 /* don't run the task if already down */
5164 if (test_bit(__E1000_DOWN, &adapter->state))
5167 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5168 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5169 e1000e_dump(adapter);
5170 e_err("Reset adapter\n");
5172 e1000e_reinit_locked(adapter);
5176 * e1000_get_stats64 - Get System Network Statistics
5177 * @netdev: network interface device structure
5178 * @stats: rtnl_link_stats64 pointer
5180 * Returns the address of the device statistics structure.
5182 struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5183 struct rtnl_link_stats64 *stats)
5185 struct e1000_adapter *adapter = netdev_priv(netdev);
5187 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5188 spin_lock(&adapter->stats64_lock);
5189 e1000e_update_stats(adapter);
5190 /* Fill out the OS statistics structure */
5191 stats->rx_bytes = adapter->stats.gorc;
5192 stats->rx_packets = adapter->stats.gprc;
5193 stats->tx_bytes = adapter->stats.gotc;
5194 stats->tx_packets = adapter->stats.gptc;
5195 stats->multicast = adapter->stats.mprc;
5196 stats->collisions = adapter->stats.colc;
5201 * RLEC on some newer hardware can be incorrect so build
5202 * our own version based on RUC and ROC
5204 stats->rx_errors = adapter->stats.rxerrc +
5205 adapter->stats.crcerrs + adapter->stats.algnerrc +
5206 adapter->stats.ruc + adapter->stats.roc +
5207 adapter->stats.cexterr;
5208 stats->rx_length_errors = adapter->stats.ruc +
5210 stats->rx_crc_errors = adapter->stats.crcerrs;
5211 stats->rx_frame_errors = adapter->stats.algnerrc;
5212 stats->rx_missed_errors = adapter->stats.mpc;
5215 stats->tx_errors = adapter->stats.ecol +
5216 adapter->stats.latecol;
5217 stats->tx_aborted_errors = adapter->stats.ecol;
5218 stats->tx_window_errors = adapter->stats.latecol;
5219 stats->tx_carrier_errors = adapter->stats.tncrs;
5221 /* Tx Dropped needs to be maintained elsewhere */
5223 spin_unlock(&adapter->stats64_lock);
5228 * e1000_change_mtu - Change the Maximum Transfer Unit
5229 * @netdev: network interface device structure
5230 * @new_mtu: new value for maximum frame size
5232 * Returns 0 on success, negative on failure
5234 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5236 struct e1000_adapter *adapter = netdev_priv(netdev);
5237 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5239 /* Jumbo frame support */
5240 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
5241 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5242 e_err("Jumbo Frames not supported.\n");
5247 * IP payload checksum (enabled with jumbos/packet-split when
5248 * Rx checksum is enabled) and generation of RSS hash is
5249 * mutually exclusive in the hardware.
5251 if ((netdev->features & NETIF_F_RXCSUM) &&
5252 (netdev->features & NETIF_F_RXHASH)) {
5253 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");
5258 /* Supported frame sizes */
5259 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5260 (max_frame > adapter->max_hw_frame_size)) {
5261 e_err("Unsupported MTU setting\n");
5265 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5266 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5267 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5268 (new_mtu > ETH_DATA_LEN)) {
5269 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
5273 /* 82573 Errata 17 */
5274 if (((adapter->hw.mac.type == e1000_82573) ||
5275 (adapter->hw.mac.type == e1000_82574)) &&
5276 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5277 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5278 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5281 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
5282 usleep_range(1000, 2000);
5283 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
5284 adapter->max_frame_size = max_frame;
5285 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5286 netdev->mtu = new_mtu;
5287 if (netif_running(netdev))
5288 e1000e_down(adapter);
5291 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
5292 * means we reserve 2 more, this pushes us to allocate from the next
5294 * i.e. RXBUFFER_2048 --> size-4096 slab
5295 * However with the new *_jumbo_rx* routines, jumbo receives will use
5299 if (max_frame <= 2048)
5300 adapter->rx_buffer_len = 2048;
5302 adapter->rx_buffer_len = 4096;
5304 /* adjust allocation if LPE protects us, and we aren't using SBP */
5305 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5306 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5307 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
5310 if (netif_running(netdev))
5313 e1000e_reset(adapter);
5315 clear_bit(__E1000_RESETTING, &adapter->state);
5320 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5323 struct e1000_adapter *adapter = netdev_priv(netdev);
5324 struct mii_ioctl_data *data = if_mii(ifr);
5326 if (adapter->hw.phy.media_type != e1000_media_type_copper)
5331 data->phy_id = adapter->hw.phy.addr;
5334 e1000_phy_read_status(adapter);
5336 switch (data->reg_num & 0x1F) {
5338 data->val_out = adapter->phy_regs.bmcr;
5341 data->val_out = adapter->phy_regs.bmsr;
5344 data->val_out = (adapter->hw.phy.id >> 16);
5347 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5350 data->val_out = adapter->phy_regs.advertise;
5353 data->val_out = adapter->phy_regs.lpa;
5356 data->val_out = adapter->phy_regs.expansion;
5359 data->val_out = adapter->phy_regs.ctrl1000;
5362 data->val_out = adapter->phy_regs.stat1000;
5365 data->val_out = adapter->phy_regs.estatus;
5378 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5384 return e1000_mii_ioctl(netdev, ifr, cmd);
5390 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5392 struct e1000_hw *hw = &adapter->hw;
5394 u16 phy_reg, wuc_enable;
5397 /* copy MAC RARs to PHY RARs */
5398 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
5400 retval = hw->phy.ops.acquire(hw);
5402 e_err("Could not acquire PHY\n");
5406 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5407 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5411 /* copy MAC MTA to PHY MTA - only needed for pchlan */
5412 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5413 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5414 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5415 (u16)(mac_reg & 0xFFFF));
5416 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5417 (u16)((mac_reg >> 16) & 0xFFFF));
5420 /* configure PHY Rx Control register */
5421 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
5422 mac_reg = er32(RCTL);
5423 if (mac_reg & E1000_RCTL_UPE)
5424 phy_reg |= BM_RCTL_UPE;
5425 if (mac_reg & E1000_RCTL_MPE)
5426 phy_reg |= BM_RCTL_MPE;
5427 phy_reg &= ~(BM_RCTL_MO_MASK);
5428 if (mac_reg & E1000_RCTL_MO_3)
5429 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5430 << BM_RCTL_MO_SHIFT);
5431 if (mac_reg & E1000_RCTL_BAM)
5432 phy_reg |= BM_RCTL_BAM;
5433 if (mac_reg & E1000_RCTL_PMCF)
5434 phy_reg |= BM_RCTL_PMCF;
5435 mac_reg = er32(CTRL);
5436 if (mac_reg & E1000_CTRL_RFCE)
5437 phy_reg |= BM_RCTL_RFCE;
5438 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
5440 /* enable PHY wakeup in MAC register */
5442 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5444 /* configure and enable PHY wakeup in PHY registers */
5445 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5446 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5448 /* activate PHY wakeup */
5449 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5450 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5452 e_err("Could not set PHY Host Wakeup bit\n");
5454 hw->phy.ops.release(hw);
5459 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5462 struct net_device *netdev = pci_get_drvdata(pdev);
5463 struct e1000_adapter *adapter = netdev_priv(netdev);
5464 struct e1000_hw *hw = &adapter->hw;
5465 u32 ctrl, ctrl_ext, rctl, status;
5466 /* Runtime suspend should only enable wakeup for link changes */
5467 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
5470 netif_device_detach(netdev);
5472 if (netif_running(netdev)) {
5473 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5474 e1000e_down(adapter);
5475 e1000_free_irq(adapter);
5477 e1000e_reset_interrupt_capability(adapter);
5479 retval = pci_save_state(pdev);
5483 status = er32(STATUS);
5484 if (status & E1000_STATUS_LU)
5485 wufc &= ~E1000_WUFC_LNKC;
5488 e1000_setup_rctl(adapter);
5489 e1000e_set_rx_mode(netdev);
5491 /* turn on all-multi mode if wake on multicast is enabled */
5492 if (wufc & E1000_WUFC_MC) {
5494 rctl |= E1000_RCTL_MPE;
5499 /* advertise wake from D3Cold */
5500 #define E1000_CTRL_ADVD3WUC 0x00100000
5501 /* phy power management enable */
5502 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5503 ctrl |= E1000_CTRL_ADVD3WUC;
5504 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5505 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
5508 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5509 adapter->hw.phy.media_type ==
5510 e1000_media_type_internal_serdes) {
5511 /* keep the laser running in D3 */
5512 ctrl_ext = er32(CTRL_EXT);
5513 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
5514 ew32(CTRL_EXT, ctrl_ext);
5517 if (adapter->flags & FLAG_IS_ICH)
5518 e1000_suspend_workarounds_ich8lan(&adapter->hw);
5520 /* Allow time for pending master requests to run */
5521 e1000e_disable_pcie_master(&adapter->hw);
5523 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5524 /* enable wakeup by the PHY */
5525 retval = e1000_init_phy_wakeup(adapter, wufc);
5529 /* enable wakeup by the MAC */
5531 ew32(WUC, E1000_WUC_PME_EN);
5538 *enable_wake = !!wufc;
5540 /* make sure adapter isn't asleep if manageability is enabled */
5541 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5542 (hw->mac.ops.check_mng_mode(hw)))
5543 *enable_wake = true;
5545 if (adapter->hw.phy.type == e1000_phy_igp_3)
5546 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5549 * Release control of h/w to f/w. If f/w is AMT enabled, this
5550 * would have already happened in close and is redundant.
5552 e1000e_release_hw_control(adapter);
5554 pci_disable_device(pdev);
5559 static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5561 if (sleep && wake) {
5562 pci_prepare_to_sleep(pdev);
5566 pci_wake_from_d3(pdev, wake);
5567 pci_set_power_state(pdev, PCI_D3hot);
5570 static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5573 struct net_device *netdev = pci_get_drvdata(pdev);
5574 struct e1000_adapter *adapter = netdev_priv(netdev);
5577 * The pci-e switch on some quad port adapters will report a
5578 * correctable error when the MAC transitions from D0 to D3. To
5579 * prevent this we need to mask off the correctable errors on the
5580 * downstream port of the pci-e switch.
5582 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5583 struct pci_dev *us_dev = pdev->bus->self;
5584 int pos = pci_pcie_cap(us_dev);
5587 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5588 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5589 (devctl & ~PCI_EXP_DEVCTL_CERE));
5591 e1000_power_off(pdev, sleep, wake);
5593 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5595 e1000_power_off(pdev, sleep, wake);
5599 #ifdef CONFIG_PCIEASPM
5600 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5602 pci_disable_link_state_locked(pdev, state);
5605 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5611 * Both device and parent should have the same ASPM setting.
5612 * Disable ASPM in downstream component first and then upstream.
5614 pos = pci_pcie_cap(pdev);
5615 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16);
5617 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5619 if (!pdev->bus->self)
5622 pos = pci_pcie_cap(pdev->bus->self);
5623 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16);
5625 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5628 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5630 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5631 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5632 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5634 __e1000e_disable_aspm(pdev, state);
5638 static bool e1000e_pm_ready(struct e1000_adapter *adapter)
5640 return !!adapter->tx_ring->buffer_info;
5643 static int __e1000_resume(struct pci_dev *pdev)
5645 struct net_device *netdev = pci_get_drvdata(pdev);
5646 struct e1000_adapter *adapter = netdev_priv(netdev);
5647 struct e1000_hw *hw = &adapter->hw;
5648 u16 aspm_disable_flag = 0;
5651 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5652 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5653 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5654 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5655 if (aspm_disable_flag)
5656 e1000e_disable_aspm(pdev, aspm_disable_flag);
5658 pci_set_power_state(pdev, PCI_D0);
5659 pci_restore_state(pdev);
5660 pci_save_state(pdev);
5662 e1000e_set_interrupt_capability(adapter);
5663 if (netif_running(netdev)) {
5664 err = e1000_request_irq(adapter);
5669 if (hw->mac.type == e1000_pch2lan)
5670 e1000_resume_workarounds_pchlan(&adapter->hw);
5672 e1000e_power_up_phy(adapter);
5674 /* report the system wakeup cause from S3/S4 */
5675 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5678 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5680 e_info("PHY Wakeup cause - %s\n",
5681 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5682 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5683 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5684 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5685 phy_data & E1000_WUS_LNKC ?
5686 "Link Status Change" : "other");
5688 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5690 u32 wus = er32(WUS);
5692 e_info("MAC Wakeup cause - %s\n",
5693 wus & E1000_WUS_EX ? "Unicast Packet" :
5694 wus & E1000_WUS_MC ? "Multicast Packet" :
5695 wus & E1000_WUS_BC ? "Broadcast Packet" :
5696 wus & E1000_WUS_MAG ? "Magic Packet" :
5697 wus & E1000_WUS_LNKC ? "Link Status Change" :
5703 e1000e_reset(adapter);
5705 e1000_init_manageability_pt(adapter);
5707 if (netif_running(netdev))
5710 netif_device_attach(netdev);
5713 * If the controller has AMT, do not set DRV_LOAD until the interface
5714 * is up. For all other cases, let the f/w know that the h/w is now
5715 * under the control of the driver.
5717 if (!(adapter->flags & FLAG_HAS_AMT))
5718 e1000e_get_hw_control(adapter);
5723 #ifdef CONFIG_PM_SLEEP
5724 static int e1000_suspend(struct device *dev)
5726 struct pci_dev *pdev = to_pci_dev(dev);
5730 retval = __e1000_shutdown(pdev, &wake, false);
5732 e1000_complete_shutdown(pdev, true, wake);
5737 static int e1000_resume(struct device *dev)
5739 struct pci_dev *pdev = to_pci_dev(dev);
5740 struct net_device *netdev = pci_get_drvdata(pdev);
5741 struct e1000_adapter *adapter = netdev_priv(netdev);
5743 if (e1000e_pm_ready(adapter))
5744 adapter->idle_check = true;
5746 return __e1000_resume(pdev);
5748 #endif /* CONFIG_PM_SLEEP */
5750 #ifdef CONFIG_PM_RUNTIME
5751 static int e1000_runtime_suspend(struct device *dev)
5753 struct pci_dev *pdev = to_pci_dev(dev);
5754 struct net_device *netdev = pci_get_drvdata(pdev);
5755 struct e1000_adapter *adapter = netdev_priv(netdev);
5757 if (e1000e_pm_ready(adapter)) {
5760 __e1000_shutdown(pdev, &wake, true);
5766 static int e1000_idle(struct device *dev)
5768 struct pci_dev *pdev = to_pci_dev(dev);
5769 struct net_device *netdev = pci_get_drvdata(pdev);
5770 struct e1000_adapter *adapter = netdev_priv(netdev);
5772 if (!e1000e_pm_ready(adapter))
5775 if (adapter->idle_check) {
5776 adapter->idle_check = false;
5777 if (!e1000e_has_link(adapter))
5778 pm_schedule_suspend(dev, MSEC_PER_SEC);
5784 static int e1000_runtime_resume(struct device *dev)
5786 struct pci_dev *pdev = to_pci_dev(dev);
5787 struct net_device *netdev = pci_get_drvdata(pdev);
5788 struct e1000_adapter *adapter = netdev_priv(netdev);
5790 if (!e1000e_pm_ready(adapter))
5793 adapter->idle_check = !dev->power.runtime_auto;
5794 return __e1000_resume(pdev);
5796 #endif /* CONFIG_PM_RUNTIME */
5797 #endif /* CONFIG_PM */
5799 static void e1000_shutdown(struct pci_dev *pdev)
5803 __e1000_shutdown(pdev, &wake, false);
5805 if (system_state == SYSTEM_POWER_OFF)
5806 e1000_complete_shutdown(pdev, false, wake);
5809 #ifdef CONFIG_NET_POLL_CONTROLLER
5811 static irqreturn_t e1000_intr_msix(int irq, void *data)
5813 struct net_device *netdev = data;
5814 struct e1000_adapter *adapter = netdev_priv(netdev);
5816 if (adapter->msix_entries) {
5817 int vector, msix_irq;
5820 msix_irq = adapter->msix_entries[vector].vector;
5821 disable_irq(msix_irq);
5822 e1000_intr_msix_rx(msix_irq, netdev);
5823 enable_irq(msix_irq);
5826 msix_irq = adapter->msix_entries[vector].vector;
5827 disable_irq(msix_irq);
5828 e1000_intr_msix_tx(msix_irq, netdev);
5829 enable_irq(msix_irq);
5832 msix_irq = adapter->msix_entries[vector].vector;
5833 disable_irq(msix_irq);
5834 e1000_msix_other(msix_irq, netdev);
5835 enable_irq(msix_irq);
5842 * Polling 'interrupt' - used by things like netconsole to send skbs
5843 * without having to re-enable interrupts. It's not called while
5844 * the interrupt routine is executing.
5846 static void e1000_netpoll(struct net_device *netdev)
5848 struct e1000_adapter *adapter = netdev_priv(netdev);
5850 switch (adapter->int_mode) {
5851 case E1000E_INT_MODE_MSIX:
5852 e1000_intr_msix(adapter->pdev->irq, netdev);
5854 case E1000E_INT_MODE_MSI:
5855 disable_irq(adapter->pdev->irq);
5856 e1000_intr_msi(adapter->pdev->irq, netdev);
5857 enable_irq(adapter->pdev->irq);
5859 default: /* E1000E_INT_MODE_LEGACY */
5860 disable_irq(adapter->pdev->irq);
5861 e1000_intr(adapter->pdev->irq, netdev);
5862 enable_irq(adapter->pdev->irq);
5869 * e1000_io_error_detected - called when PCI error is detected
5870 * @pdev: Pointer to PCI device
5871 * @state: The current pci connection state
5873 * This function is called after a PCI bus error affecting
5874 * this device has been detected.
5876 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5877 pci_channel_state_t state)
5879 struct net_device *netdev = pci_get_drvdata(pdev);
5880 struct e1000_adapter *adapter = netdev_priv(netdev);
5882 netif_device_detach(netdev);
5884 if (state == pci_channel_io_perm_failure)
5885 return PCI_ERS_RESULT_DISCONNECT;
5887 if (netif_running(netdev))
5888 e1000e_down(adapter);
5889 pci_disable_device(pdev);
5891 /* Request a slot slot reset. */
5892 return PCI_ERS_RESULT_NEED_RESET;
5896 * e1000_io_slot_reset - called after the pci bus has been reset.
5897 * @pdev: Pointer to PCI device
5899 * Restart the card from scratch, as if from a cold-boot. Implementation
5900 * resembles the first-half of the e1000_resume routine.
5902 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5904 struct net_device *netdev = pci_get_drvdata(pdev);
5905 struct e1000_adapter *adapter = netdev_priv(netdev);
5906 struct e1000_hw *hw = &adapter->hw;
5907 u16 aspm_disable_flag = 0;
5909 pci_ers_result_t result;
5911 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5912 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5913 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5914 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5915 if (aspm_disable_flag)
5916 e1000e_disable_aspm(pdev, aspm_disable_flag);
5918 err = pci_enable_device_mem(pdev);
5921 "Cannot re-enable PCI device after reset.\n");
5922 result = PCI_ERS_RESULT_DISCONNECT;
5924 pci_set_master(pdev);
5925 pdev->state_saved = true;
5926 pci_restore_state(pdev);
5928 pci_enable_wake(pdev, PCI_D3hot, 0);
5929 pci_enable_wake(pdev, PCI_D3cold, 0);
5931 e1000e_reset(adapter);
5933 result = PCI_ERS_RESULT_RECOVERED;
5936 pci_cleanup_aer_uncorrect_error_status(pdev);
5942 * e1000_io_resume - called when traffic can start flowing again.
5943 * @pdev: Pointer to PCI device
5945 * This callback is called when the error recovery driver tells us that
5946 * its OK to resume normal operation. Implementation resembles the
5947 * second-half of the e1000_resume routine.
5949 static void e1000_io_resume(struct pci_dev *pdev)
5951 struct net_device *netdev = pci_get_drvdata(pdev);
5952 struct e1000_adapter *adapter = netdev_priv(netdev);
5954 e1000_init_manageability_pt(adapter);
5956 if (netif_running(netdev)) {
5957 if (e1000e_up(adapter)) {
5959 "can't bring device back up after reset\n");
5964 netif_device_attach(netdev);
5967 * If the controller has AMT, do not set DRV_LOAD until the interface
5968 * is up. For all other cases, let the f/w know that the h/w is now
5969 * under the control of the driver.
5971 if (!(adapter->flags & FLAG_HAS_AMT))
5972 e1000e_get_hw_control(adapter);
5976 static void e1000_print_device_info(struct e1000_adapter *adapter)
5978 struct e1000_hw *hw = &adapter->hw;
5979 struct net_device *netdev = adapter->netdev;
5981 u8 pba_str[E1000_PBANUM_LENGTH];
5983 /* print bus type/speed/width info */
5984 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
5986 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5990 e_info("Intel(R) PRO/%s Network Connection\n",
5991 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
5992 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5993 E1000_PBANUM_LENGTH);
5995 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
5996 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5997 hw->mac.type, hw->phy.type, pba_str);
6000 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6002 struct e1000_hw *hw = &adapter->hw;
6006 if (hw->mac.type != e1000_82573)
6009 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
6011 if (!ret_val && (!(buf & (1 << 0)))) {
6012 /* Deep Smart Power Down (DSPD) */
6013 dev_warn(&adapter->pdev->dev,
6014 "Warning: detected DSPD enabled in EEPROM\n");
6018 static int e1000_set_features(struct net_device *netdev,
6019 netdev_features_t features)
6021 struct e1000_adapter *adapter = netdev_priv(netdev);
6022 netdev_features_t changed = features ^ netdev->features;
6024 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6025 adapter->flags |= FLAG_TSO_FORCE;
6027 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
6028 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6033 * IP payload checksum (enabled with jumbos/packet-split when Rx
6034 * checksum is enabled) and generation of RSS hash is mutually
6035 * exclusive in the hardware.
6037 if (adapter->rx_ps_pages &&
6038 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
6039 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");
6043 if (changed & NETIF_F_RXFCS) {
6044 if (features & NETIF_F_RXFCS) {
6045 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6047 /* We need to take it back to defaults, which might mean
6048 * stripping is still disabled at the adapter level.
6050 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6051 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6053 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6057 netdev->features = features;
6059 if (netif_running(netdev))
6060 e1000e_reinit_locked(adapter);
6062 e1000e_reset(adapter);
6067 static const struct net_device_ops e1000e_netdev_ops = {
6068 .ndo_open = e1000_open,
6069 .ndo_stop = e1000_close,
6070 .ndo_start_xmit = e1000_xmit_frame,
6071 .ndo_get_stats64 = e1000e_get_stats64,
6072 .ndo_set_rx_mode = e1000e_set_rx_mode,
6073 .ndo_set_mac_address = e1000_set_mac,
6074 .ndo_change_mtu = e1000_change_mtu,
6075 .ndo_do_ioctl = e1000_ioctl,
6076 .ndo_tx_timeout = e1000_tx_timeout,
6077 .ndo_validate_addr = eth_validate_addr,
6079 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6080 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6081 #ifdef CONFIG_NET_POLL_CONTROLLER
6082 .ndo_poll_controller = e1000_netpoll,
6084 .ndo_set_features = e1000_set_features,
6088 * e1000_probe - Device Initialization Routine
6089 * @pdev: PCI device information struct
6090 * @ent: entry in e1000_pci_tbl
6092 * Returns 0 on success, negative on failure
6094 * e1000_probe initializes an adapter identified by a pci_dev structure.
6095 * The OS initialization, configuring of the adapter private structure,
6096 * and a hardware reset occur.
6098 static int __devinit e1000_probe(struct pci_dev *pdev,
6099 const struct pci_device_id *ent)
6101 struct net_device *netdev;
6102 struct e1000_adapter *adapter;
6103 struct e1000_hw *hw;
6104 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
6105 resource_size_t mmio_start, mmio_len;
6106 resource_size_t flash_start, flash_len;
6107 static int cards_found;
6108 u16 aspm_disable_flag = 0;
6109 int i, err, pci_using_dac;
6110 u16 eeprom_data = 0;
6111 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6113 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6114 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6115 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
6116 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6117 if (aspm_disable_flag)
6118 e1000e_disable_aspm(pdev, aspm_disable_flag);
6120 err = pci_enable_device_mem(pdev);
6125 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
6127 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
6131 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
6133 err = dma_set_coherent_mask(&pdev->dev,
6136 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
6142 err = pci_request_selected_regions_exclusive(pdev,
6143 pci_select_bars(pdev, IORESOURCE_MEM),
6144 e1000e_driver_name);
6148 /* AER (Advanced Error Reporting) hooks */
6149 pci_enable_pcie_error_reporting(pdev);
6151 pci_set_master(pdev);
6152 /* PCI config space info */
6153 err = pci_save_state(pdev);
6155 goto err_alloc_etherdev;
6158 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6160 goto err_alloc_etherdev;
6162 SET_NETDEV_DEV(netdev, &pdev->dev);
6164 netdev->irq = pdev->irq;
6166 pci_set_drvdata(pdev, netdev);
6167 adapter = netdev_priv(netdev);
6169 adapter->netdev = netdev;
6170 adapter->pdev = pdev;
6172 adapter->pba = ei->pba;
6173 adapter->flags = ei->flags;
6174 adapter->flags2 = ei->flags2;
6175 adapter->hw.adapter = adapter;
6176 adapter->hw.mac.type = ei->mac;
6177 adapter->max_hw_frame_size = ei->max_hw_frame_size;
6178 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6180 mmio_start = pci_resource_start(pdev, 0);
6181 mmio_len = pci_resource_len(pdev, 0);
6184 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6185 if (!adapter->hw.hw_addr)
6188 if ((adapter->flags & FLAG_HAS_FLASH) &&
6189 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6190 flash_start = pci_resource_start(pdev, 1);
6191 flash_len = pci_resource_len(pdev, 1);
6192 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6193 if (!adapter->hw.flash_address)
6197 /* construct the net_device struct */
6198 netdev->netdev_ops = &e1000e_netdev_ops;
6199 e1000e_set_ethtool_ops(netdev);
6200 netdev->watchdog_timeo = 5 * HZ;
6201 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
6202 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
6204 netdev->mem_start = mmio_start;
6205 netdev->mem_end = mmio_start + mmio_len;
6207 adapter->bd_number = cards_found++;
6209 e1000e_check_options(adapter);
6211 /* setup adapter struct */
6212 err = e1000_sw_init(adapter);
6216 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6217 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6218 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6220 err = ei->get_variants(adapter);
6224 if ((adapter->flags & FLAG_IS_ICH) &&
6225 (adapter->flags & FLAG_READ_ONLY_NVM))
6226 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6228 hw->mac.ops.get_bus_info(&adapter->hw);
6230 adapter->hw.phy.autoneg_wait_to_complete = 0;
6232 /* Copper options */
6233 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
6234 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6235 adapter->hw.phy.disable_polarity_correction = 0;
6236 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6239 if (hw->phy.ops.check_reset_block(hw))
6240 e_info("PHY reset is blocked due to SOL/IDER session.\n");
6242 /* Set initial default active device features */
6243 netdev->features = (NETIF_F_SG |
6244 NETIF_F_HW_VLAN_RX |
6245 NETIF_F_HW_VLAN_TX |
6252 /* Set user-changeable features (subset of all device features) */
6253 netdev->hw_features = netdev->features;
6254 netdev->hw_features |= NETIF_F_RXFCS;
6255 netdev->priv_flags |= IFF_SUPP_NOFCS;
6256 netdev->hw_features |= NETIF_F_RXALL;
6258 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6259 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6261 netdev->vlan_features |= (NETIF_F_SG |
6266 netdev->priv_flags |= IFF_UNICAST_FLT;
6268 if (pci_using_dac) {
6269 netdev->features |= NETIF_F_HIGHDMA;
6270 netdev->vlan_features |= NETIF_F_HIGHDMA;
6273 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6274 adapter->flags |= FLAG_MNG_PT_ENABLED;
6277 * before reading the NVM, reset the controller to
6278 * put the device in a known good starting state
6280 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6283 * systems with ASPM and others may see the checksum fail on the first
6284 * attempt. Let's give it a few tries
6287 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6290 e_err("The NVM Checksum Is Not Valid\n");
6296 e1000_eeprom_checks(adapter);
6298 /* copy the MAC address */
6299 if (e1000e_read_mac_addr(&adapter->hw))
6300 e_err("NVM Read Error while reading MAC address\n");
6302 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6303 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6305 if (!is_valid_ether_addr(netdev->perm_addr)) {
6306 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
6311 init_timer(&adapter->watchdog_timer);
6312 adapter->watchdog_timer.function = e1000_watchdog;
6313 adapter->watchdog_timer.data = (unsigned long) adapter;
6315 init_timer(&adapter->phy_info_timer);
6316 adapter->phy_info_timer.function = e1000_update_phy_info;
6317 adapter->phy_info_timer.data = (unsigned long) adapter;
6319 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6320 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
6321 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6322 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
6323 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
6325 /* Initialize link parameters. User can change them with ethtool */
6326 adapter->hw.mac.autoneg = 1;
6327 adapter->fc_autoneg = true;
6328 adapter->hw.fc.requested_mode = e1000_fc_default;
6329 adapter->hw.fc.current_mode = e1000_fc_default;
6330 adapter->hw.phy.autoneg_advertised = 0x2f;
6332 /* ring size defaults */
6333 adapter->rx_ring->count = 256;
6334 adapter->tx_ring->count = 256;
6337 * Initial Wake on LAN setting - If APM wake is enabled in
6338 * the EEPROM, enable the ACPI Magic Packet filter
6340 if (adapter->flags & FLAG_APME_IN_WUC) {
6341 /* APME bit in EEPROM is mapped to WUC.APME */
6342 eeprom_data = er32(WUC);
6343 eeprom_apme_mask = E1000_WUC_APME;
6344 if ((hw->mac.type > e1000_ich10lan) &&
6345 (eeprom_data & E1000_WUC_PHY_WAKE))
6346 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
6347 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6348 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6349 (adapter->hw.bus.func == 1))
6350 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6353 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6357 /* fetch WoL from EEPROM */
6358 if (eeprom_data & eeprom_apme_mask)
6359 adapter->eeprom_wol |= E1000_WUFC_MAG;
6362 * now that we have the eeprom settings, apply the special cases
6363 * where the eeprom may be wrong or the board simply won't support
6364 * wake on lan on a particular port
6366 if (!(adapter->flags & FLAG_HAS_WOL))
6367 adapter->eeprom_wol = 0;
6369 /* initialize the wol settings based on the eeprom settings */
6370 adapter->wol = adapter->eeprom_wol;
6371 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
6373 /* save off EEPROM version number */
6374 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6376 /* reset the hardware with the new settings */
6377 e1000e_reset(adapter);
6380 * If the controller has AMT, do not set DRV_LOAD until the interface
6381 * is up. For all other cases, let the f/w know that the h/w is now
6382 * under the control of the driver.
6384 if (!(adapter->flags & FLAG_HAS_AMT))
6385 e1000e_get_hw_control(adapter);
6387 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
6388 err = register_netdev(netdev);
6392 /* carrier off reporting is important to ethtool even BEFORE open */
6393 netif_carrier_off(netdev);
6395 e1000_print_device_info(adapter);
6397 if (pci_dev_run_wake(pdev))
6398 pm_runtime_put_noidle(&pdev->dev);
6403 if (!(adapter->flags & FLAG_HAS_AMT))
6404 e1000e_release_hw_control(adapter);
6406 if (!hw->phy.ops.check_reset_block(hw))
6407 e1000_phy_hw_reset(&adapter->hw);
6409 kfree(adapter->tx_ring);
6410 kfree(adapter->rx_ring);
6412 if (adapter->hw.flash_address)
6413 iounmap(adapter->hw.flash_address);
6414 e1000e_reset_interrupt_capability(adapter);
6416 iounmap(adapter->hw.hw_addr);
6418 free_netdev(netdev);
6420 pci_release_selected_regions(pdev,
6421 pci_select_bars(pdev, IORESOURCE_MEM));
6424 pci_disable_device(pdev);
6429 * e1000_remove - Device Removal Routine
6430 * @pdev: PCI device information struct
6432 * e1000_remove is called by the PCI subsystem to alert the driver
6433 * that it should release a PCI device. The could be caused by a
6434 * Hot-Plug event, or because the driver is going to be removed from
6437 static void __devexit e1000_remove(struct pci_dev *pdev)
6439 struct net_device *netdev = pci_get_drvdata(pdev);
6440 struct e1000_adapter *adapter = netdev_priv(netdev);
6441 bool down = test_bit(__E1000_DOWN, &adapter->state);
6444 * The timers may be rescheduled, so explicitly disable them
6445 * from being rescheduled.
6448 set_bit(__E1000_DOWN, &adapter->state);
6449 del_timer_sync(&adapter->watchdog_timer);
6450 del_timer_sync(&adapter->phy_info_timer);
6452 cancel_work_sync(&adapter->reset_task);
6453 cancel_work_sync(&adapter->watchdog_task);
6454 cancel_work_sync(&adapter->downshift_task);
6455 cancel_work_sync(&adapter->update_phy_task);
6456 cancel_work_sync(&adapter->print_hang_task);
6458 if (!(netdev->flags & IFF_UP))
6459 e1000_power_down_phy(adapter);
6461 /* Don't lie to e1000_close() down the road. */
6463 clear_bit(__E1000_DOWN, &adapter->state);
6464 unregister_netdev(netdev);
6466 if (pci_dev_run_wake(pdev))
6467 pm_runtime_get_noresume(&pdev->dev);
6470 * Release control of h/w to f/w. If f/w is AMT enabled, this
6471 * would have already happened in close and is redundant.
6473 e1000e_release_hw_control(adapter);
6475 e1000e_reset_interrupt_capability(adapter);
6476 kfree(adapter->tx_ring);
6477 kfree(adapter->rx_ring);
6479 iounmap(adapter->hw.hw_addr);
6480 if (adapter->hw.flash_address)
6481 iounmap(adapter->hw.flash_address);
6482 pci_release_selected_regions(pdev,
6483 pci_select_bars(pdev, IORESOURCE_MEM));
6485 free_netdev(netdev);
6488 pci_disable_pcie_error_reporting(pdev);
6490 pci_disable_device(pdev);
6493 /* PCI Error Recovery (ERS) */
6494 static struct pci_error_handlers e1000_err_handler = {
6495 .error_detected = e1000_io_error_detected,
6496 .slot_reset = e1000_io_slot_reset,
6497 .resume = e1000_io_resume,
6500 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
6501 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6502 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6503 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6504 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6505 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6506 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
6507 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6508 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6509 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
6511 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6512 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6513 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6514 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
6516 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6517 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6518 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
6520 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
6521 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
6522 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
6524 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6525 board_80003es2lan },
6526 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6527 board_80003es2lan },
6528 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6529 board_80003es2lan },
6530 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6531 board_80003es2lan },
6533 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6534 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6535 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6536 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6537 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6538 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6539 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
6540 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
6542 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6543 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6544 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6545 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6546 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
6547 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
6548 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6549 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6550 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6552 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6553 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6554 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
6556 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6557 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
6558 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
6560 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6561 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6562 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6563 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6565 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6566 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6568 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
6570 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6573 static const struct dev_pm_ops e1000_pm_ops = {
6574 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6575 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6576 e1000_runtime_resume, e1000_idle)
6580 /* PCI Device API Driver */
6581 static struct pci_driver e1000_driver = {
6582 .name = e1000e_driver_name,
6583 .id_table = e1000_pci_tbl,
6584 .probe = e1000_probe,
6585 .remove = __devexit_p(e1000_remove),
6588 .pm = &e1000_pm_ops,
6591 .shutdown = e1000_shutdown,
6592 .err_handler = &e1000_err_handler
6596 * e1000_init_module - Driver Registration Routine
6598 * e1000_init_module is the first routine called when the driver is
6599 * loaded. All it does is register with the PCI subsystem.
6601 static int __init e1000_init_module(void)
6604 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6605 e1000e_driver_version);
6606 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
6607 ret = pci_register_driver(&e1000_driver);
6611 module_init(e1000_init_module);
6614 * e1000_exit_module - Driver Exit Cleanup Routine
6616 * e1000_exit_module is called just before the driver is removed
6619 static void __exit e1000_exit_module(void)
6621 pci_unregister_driver(&e1000_driver);
6623 module_exit(e1000_exit_module);
6626 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6627 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6628 MODULE_LICENSE("GPL");
6629 MODULE_VERSION(DRV_VERSION);