1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/module.h>
32 #include <linux/types.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/vmalloc.h>
36 #include <linux/pagemap.h>
37 #include <linux/delay.h>
38 #include <linux/netdevice.h>
39 #include <linux/interrupt.h>
40 #include <linux/tcp.h>
41 #include <linux/ipv6.h>
42 #include <linux/slab.h>
43 #include <net/checksum.h>
44 #include <net/ip6_checksum.h>
45 #include <linux/mii.h>
46 #include <linux/ethtool.h>
47 #include <linux/if_vlan.h>
48 #include <linux/cpu.h>
49 #include <linux/smp.h>
50 #include <linux/pm_qos.h>
51 #include <linux/pm_runtime.h>
52 #include <linux/aer.h>
53 #include <linux/prefetch.h>
57 #define DRV_EXTRAVERSION "-k"
59 #define DRV_VERSION "1.10.6" DRV_EXTRAVERSION
60 char e1000e_driver_name[] = "e1000e";
61 const char e1000e_driver_version[] = DRV_VERSION;
63 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
64 static int debug = -1;
65 module_param(debug, int, 0);
66 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
68 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
70 static const struct e1000_info *e1000_info_tbl[] = {
71 [board_82571] = &e1000_82571_info,
72 [board_82572] = &e1000_82572_info,
73 [board_82573] = &e1000_82573_info,
74 [board_82574] = &e1000_82574_info,
75 [board_82583] = &e1000_82583_info,
76 [board_80003es2lan] = &e1000_es2_info,
77 [board_ich8lan] = &e1000_ich8_info,
78 [board_ich9lan] = &e1000_ich9_info,
79 [board_ich10lan] = &e1000_ich10_info,
80 [board_pchlan] = &e1000_pch_info,
81 [board_pch2lan] = &e1000_pch2_info,
84 struct e1000_reg_info {
89 #define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
90 #define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
91 #define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
92 #define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
93 #define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
95 #define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
96 #define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
97 #define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
98 #define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
99 #define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
101 static const struct e1000_reg_info e1000_reg_info_tbl[] = {
103 /* General Registers */
104 {E1000_CTRL, "CTRL"},
105 {E1000_STATUS, "STATUS"},
106 {E1000_CTRL_EXT, "CTRL_EXT"},
108 /* Interrupt Registers */
112 {E1000_RCTL, "RCTL"},
113 {E1000_RDLEN(0), "RDLEN"},
114 {E1000_RDH(0), "RDH"},
115 {E1000_RDT(0), "RDT"},
116 {E1000_RDTR, "RDTR"},
117 {E1000_RXDCTL(0), "RXDCTL"},
119 {E1000_RDBAL(0), "RDBAL"},
120 {E1000_RDBAH(0), "RDBAH"},
121 {E1000_RDFH, "RDFH"},
122 {E1000_RDFT, "RDFT"},
123 {E1000_RDFHS, "RDFHS"},
124 {E1000_RDFTS, "RDFTS"},
125 {E1000_RDFPC, "RDFPC"},
128 {E1000_TCTL, "TCTL"},
129 {E1000_TDBAL(0), "TDBAL"},
130 {E1000_TDBAH(0), "TDBAH"},
131 {E1000_TDLEN(0), "TDLEN"},
132 {E1000_TDH(0), "TDH"},
133 {E1000_TDT(0), "TDT"},
134 {E1000_TIDV, "TIDV"},
135 {E1000_TXDCTL(0), "TXDCTL"},
136 {E1000_TADV, "TADV"},
137 {E1000_TARC(0), "TARC"},
138 {E1000_TDFH, "TDFH"},
139 {E1000_TDFT, "TDFT"},
140 {E1000_TDFHS, "TDFHS"},
141 {E1000_TDFTS, "TDFTS"},
142 {E1000_TDFPC, "TDFPC"},
144 /* List Terminator */
149 * e1000_regdump - register printout routine
151 static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
157 switch (reginfo->ofs) {
158 case E1000_RXDCTL(0):
159 for (n = 0; n < 2; n++)
160 regs[n] = __er32(hw, E1000_RXDCTL(n));
162 case E1000_TXDCTL(0):
163 for (n = 0; n < 2; n++)
164 regs[n] = __er32(hw, E1000_TXDCTL(n));
167 for (n = 0; n < 2; n++)
168 regs[n] = __er32(hw, E1000_TARC(n));
171 pr_info("%-15s %08x\n",
172 reginfo->name, __er32(hw, reginfo->ofs));
176 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
177 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
181 * e1000e_dump - Print registers, Tx-ring and Rx-ring
183 static void e1000e_dump(struct e1000_adapter *adapter)
185 struct net_device *netdev = adapter->netdev;
186 struct e1000_hw *hw = &adapter->hw;
187 struct e1000_reg_info *reginfo;
188 struct e1000_ring *tx_ring = adapter->tx_ring;
189 struct e1000_tx_desc *tx_desc;
194 struct e1000_buffer *buffer_info;
195 struct e1000_ring *rx_ring = adapter->rx_ring;
196 union e1000_rx_desc_packet_split *rx_desc_ps;
197 union e1000_rx_desc_extended *rx_desc;
207 if (!netif_msg_hw(adapter))
210 /* Print netdevice Info */
212 dev_info(&adapter->pdev->dev, "Net device Info\n");
213 pr_info("Device Name state trans_start last_rx\n");
214 pr_info("%-15s %016lX %016lX %016lX\n",
215 netdev->name, netdev->state, netdev->trans_start,
219 /* Print Registers */
220 dev_info(&adapter->pdev->dev, "Register Dump\n");
221 pr_info(" Register Name Value\n");
222 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
223 reginfo->name; reginfo++) {
224 e1000_regdump(hw, reginfo);
227 /* Print Tx Ring Summary */
228 if (!netdev || !netif_running(netdev))
231 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
232 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
233 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
234 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
235 0, tx_ring->next_to_use, tx_ring->next_to_clean,
236 (unsigned long long)buffer_info->dma,
238 buffer_info->next_to_watch,
239 (unsigned long long)buffer_info->time_stamp);
242 if (!netif_msg_tx_done(adapter))
243 goto rx_ring_summary;
245 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
247 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
249 * Legacy Transmit Descriptor
250 * +--------------------------------------------------------------+
251 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
252 * +--------------------------------------------------------------+
253 * 8 | Special | CSS | Status | CMD | CSO | Length |
254 * +--------------------------------------------------------------+
255 * 63 48 47 36 35 32 31 24 23 16 15 0
257 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
258 * 63 48 47 40 39 32 31 16 15 8 7 0
259 * +----------------------------------------------------------------+
260 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
261 * +----------------------------------------------------------------+
262 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
263 * +----------------------------------------------------------------+
264 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
266 * Extended Data Descriptor (DTYP=0x1)
267 * +----------------------------------------------------------------+
268 * 0 | Buffer Address [63:0] |
269 * +----------------------------------------------------------------+
270 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
271 * +----------------------------------------------------------------+
272 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
274 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
275 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
276 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
277 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
278 const char *next_desc;
279 tx_desc = E1000_TX_DESC(*tx_ring, i);
280 buffer_info = &tx_ring->buffer_info[i];
281 u0 = (struct my_u0 *)tx_desc;
282 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
283 next_desc = " NTC/U";
284 else if (i == tx_ring->next_to_use)
286 else if (i == tx_ring->next_to_clean)
290 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
291 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
292 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
294 (unsigned long long)le64_to_cpu(u0->a),
295 (unsigned long long)le64_to_cpu(u0->b),
296 (unsigned long long)buffer_info->dma,
297 buffer_info->length, buffer_info->next_to_watch,
298 (unsigned long long)buffer_info->time_stamp,
299 buffer_info->skb, next_desc);
301 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
302 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
303 16, 1, phys_to_virt(buffer_info->dma),
304 buffer_info->length, true);
307 /* Print Rx Ring Summary */
309 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
310 pr_info("Queue [NTU] [NTC]\n");
311 pr_info(" %5d %5X %5X\n",
312 0, rx_ring->next_to_use, rx_ring->next_to_clean);
315 if (!netif_msg_rx_status(adapter))
318 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
319 switch (adapter->rx_ps_pages) {
323 /* [Extended] Packet Split Receive Descriptor Format
325 * +-----------------------------------------------------+
326 * 0 | Buffer Address 0 [63:0] |
327 * +-----------------------------------------------------+
328 * 8 | Buffer Address 1 [63:0] |
329 * +-----------------------------------------------------+
330 * 16 | Buffer Address 2 [63:0] |
331 * +-----------------------------------------------------+
332 * 24 | Buffer Address 3 [63:0] |
333 * +-----------------------------------------------------+
335 pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
336 /* [Extended] Receive Descriptor (Write-Back) Format
338 * 63 48 47 32 31 13 12 8 7 4 3 0
339 * +------------------------------------------------------+
340 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
341 * | Checksum | Ident | | Queue | | Type |
342 * +------------------------------------------------------+
343 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
344 * +------------------------------------------------------+
345 * 63 48 47 32 31 20 19 0
347 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
348 for (i = 0; i < rx_ring->count; i++) {
349 const char *next_desc;
350 buffer_info = &rx_ring->buffer_info[i];
351 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
352 u1 = (struct my_u1 *)rx_desc_ps;
354 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
356 if (i == rx_ring->next_to_use)
358 else if (i == rx_ring->next_to_clean)
363 if (staterr & E1000_RXD_STAT_DD) {
364 /* Descriptor Done */
365 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
367 (unsigned long long)le64_to_cpu(u1->a),
368 (unsigned long long)le64_to_cpu(u1->b),
369 (unsigned long long)le64_to_cpu(u1->c),
370 (unsigned long long)le64_to_cpu(u1->d),
371 buffer_info->skb, next_desc);
373 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
375 (unsigned long long)le64_to_cpu(u1->a),
376 (unsigned long long)le64_to_cpu(u1->b),
377 (unsigned long long)le64_to_cpu(u1->c),
378 (unsigned long long)le64_to_cpu(u1->d),
379 (unsigned long long)buffer_info->dma,
380 buffer_info->skb, next_desc);
382 if (netif_msg_pktdata(adapter))
383 print_hex_dump(KERN_INFO, "",
384 DUMP_PREFIX_ADDRESS, 16, 1,
385 phys_to_virt(buffer_info->dma),
386 adapter->rx_ps_bsize0, true);
392 /* Extended Receive Descriptor (Read) Format
394 * +-----------------------------------------------------+
395 * 0 | Buffer Address [63:0] |
396 * +-----------------------------------------------------+
398 * +-----------------------------------------------------+
400 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
401 /* Extended Receive Descriptor (Write-Back) Format
403 * 63 48 47 32 31 24 23 4 3 0
404 * +------------------------------------------------------+
406 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
407 * | Packet | IP | | | Type |
408 * | Checksum | Ident | | | |
409 * +------------------------------------------------------+
410 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
411 * +------------------------------------------------------+
412 * 63 48 47 32 31 20 19 0
414 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
416 for (i = 0; i < rx_ring->count; i++) {
417 const char *next_desc;
419 buffer_info = &rx_ring->buffer_info[i];
420 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
421 u1 = (struct my_u1 *)rx_desc;
422 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
424 if (i == rx_ring->next_to_use)
426 else if (i == rx_ring->next_to_clean)
431 if (staterr & E1000_RXD_STAT_DD) {
432 /* Descriptor Done */
433 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
435 (unsigned long long)le64_to_cpu(u1->a),
436 (unsigned long long)le64_to_cpu(u1->b),
437 buffer_info->skb, next_desc);
439 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
441 (unsigned long long)le64_to_cpu(u1->a),
442 (unsigned long long)le64_to_cpu(u1->b),
443 (unsigned long long)buffer_info->dma,
444 buffer_info->skb, next_desc);
446 if (netif_msg_pktdata(adapter))
447 print_hex_dump(KERN_INFO, "",
448 DUMP_PREFIX_ADDRESS, 16,
452 adapter->rx_buffer_len,
460 * e1000_desc_unused - calculate if we have unused descriptors
462 static int e1000_desc_unused(struct e1000_ring *ring)
464 if (ring->next_to_clean > ring->next_to_use)
465 return ring->next_to_clean - ring->next_to_use - 1;
467 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
471 * e1000_receive_skb - helper function to handle Rx indications
472 * @adapter: board private structure
473 * @status: descriptor status field as written by hardware
474 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
475 * @skb: pointer to sk_buff to be indicated to stack
477 static void e1000_receive_skb(struct e1000_adapter *adapter,
478 struct net_device *netdev, struct sk_buff *skb,
479 u8 status, __le16 vlan)
481 u16 tag = le16_to_cpu(vlan);
482 skb->protocol = eth_type_trans(skb, netdev);
484 if (status & E1000_RXD_STAT_VP)
485 __vlan_hwaccel_put_tag(skb, tag);
487 napi_gro_receive(&adapter->napi, skb);
491 * e1000_rx_checksum - Receive Checksum Offload
492 * @adapter: board private structure
493 * @status_err: receive descriptor status and error fields
494 * @csum: receive descriptor csum field
495 * @sk_buff: socket buffer with received data
497 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
498 __le16 csum, struct sk_buff *skb)
500 u16 status = (u16)status_err;
501 u8 errors = (u8)(status_err >> 24);
503 skb_checksum_none_assert(skb);
505 /* Rx checksum disabled */
506 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
509 /* Ignore Checksum bit is set */
510 if (status & E1000_RXD_STAT_IXSM)
513 /* TCP/UDP checksum error bit is set */
514 if (errors & E1000_RXD_ERR_TCPE) {
515 /* let the stack verify checksum errors */
516 adapter->hw_csum_err++;
520 /* TCP/UDP Checksum has not been calculated */
521 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
524 /* It must be a TCP or UDP packet with a valid checksum */
525 if (status & E1000_RXD_STAT_TCPCS) {
526 /* TCP checksum is good */
527 skb->ip_summed = CHECKSUM_UNNECESSARY;
530 * IP fragment with UDP payload
531 * Hardware complements the payload checksum, so we undo it
532 * and then put the value in host order for further stack use.
534 __sum16 sum = (__force __sum16)swab16((__force u16)csum);
535 skb->csum = csum_unfold(~sum);
536 skb->ip_summed = CHECKSUM_COMPLETE;
538 adapter->hw_csum_good++;
541 static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
543 struct e1000_adapter *adapter = rx_ring->adapter;
544 struct e1000_hw *hw = &adapter->hw;
545 s32 ret_val = __ew32_prepare(hw);
547 writel(i, rx_ring->tail);
549 if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
550 u32 rctl = er32(RCTL);
551 ew32(RCTL, rctl & ~E1000_RCTL_EN);
552 e_err("ME firmware caused invalid RDT - resetting\n");
553 schedule_work(&adapter->reset_task);
557 static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
559 struct e1000_adapter *adapter = tx_ring->adapter;
560 struct e1000_hw *hw = &adapter->hw;
561 s32 ret_val = __ew32_prepare(hw);
563 writel(i, tx_ring->tail);
565 if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
566 u32 tctl = er32(TCTL);
567 ew32(TCTL, tctl & ~E1000_TCTL_EN);
568 e_err("ME firmware caused invalid TDT - resetting\n");
569 schedule_work(&adapter->reset_task);
574 * e1000_alloc_rx_buffers - Replace used receive buffers
575 * @rx_ring: Rx descriptor ring
577 static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
578 int cleaned_count, gfp_t gfp)
580 struct e1000_adapter *adapter = rx_ring->adapter;
581 struct net_device *netdev = adapter->netdev;
582 struct pci_dev *pdev = adapter->pdev;
583 union e1000_rx_desc_extended *rx_desc;
584 struct e1000_buffer *buffer_info;
587 unsigned int bufsz = adapter->rx_buffer_len;
589 i = rx_ring->next_to_use;
590 buffer_info = &rx_ring->buffer_info[i];
592 while (cleaned_count--) {
593 skb = buffer_info->skb;
599 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
601 /* Better luck next round */
602 adapter->alloc_rx_buff_failed++;
606 buffer_info->skb = skb;
608 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
609 adapter->rx_buffer_len,
611 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
612 dev_err(&pdev->dev, "Rx DMA map failed\n");
613 adapter->rx_dma_failed++;
617 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
618 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
620 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
622 * Force memory writes to complete before letting h/w
623 * know there are new descriptors to fetch. (Only
624 * applicable for weak-ordered memory model archs,
628 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
629 e1000e_update_rdt_wa(rx_ring, i);
631 writel(i, rx_ring->tail);
634 if (i == rx_ring->count)
636 buffer_info = &rx_ring->buffer_info[i];
639 rx_ring->next_to_use = i;
643 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
644 * @rx_ring: Rx descriptor ring
646 static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
647 int cleaned_count, gfp_t gfp)
649 struct e1000_adapter *adapter = rx_ring->adapter;
650 struct net_device *netdev = adapter->netdev;
651 struct pci_dev *pdev = adapter->pdev;
652 union e1000_rx_desc_packet_split *rx_desc;
653 struct e1000_buffer *buffer_info;
654 struct e1000_ps_page *ps_page;
658 i = rx_ring->next_to_use;
659 buffer_info = &rx_ring->buffer_info[i];
661 while (cleaned_count--) {
662 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
664 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
665 ps_page = &buffer_info->ps_pages[j];
666 if (j >= adapter->rx_ps_pages) {
667 /* all unused desc entries get hw null ptr */
668 rx_desc->read.buffer_addr[j + 1] =
672 if (!ps_page->page) {
673 ps_page->page = alloc_page(gfp);
674 if (!ps_page->page) {
675 adapter->alloc_rx_buff_failed++;
678 ps_page->dma = dma_map_page(&pdev->dev,
682 if (dma_mapping_error(&pdev->dev,
684 dev_err(&adapter->pdev->dev,
685 "Rx DMA page map failed\n");
686 adapter->rx_dma_failed++;
691 * Refresh the desc even if buffer_addrs
692 * didn't change because each write-back
695 rx_desc->read.buffer_addr[j + 1] =
696 cpu_to_le64(ps_page->dma);
699 skb = __netdev_alloc_skb_ip_align(netdev,
700 adapter->rx_ps_bsize0,
704 adapter->alloc_rx_buff_failed++;
708 buffer_info->skb = skb;
709 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
710 adapter->rx_ps_bsize0,
712 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
713 dev_err(&pdev->dev, "Rx DMA map failed\n");
714 adapter->rx_dma_failed++;
716 dev_kfree_skb_any(skb);
717 buffer_info->skb = NULL;
721 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
723 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
725 * Force memory writes to complete before letting h/w
726 * know there are new descriptors to fetch. (Only
727 * applicable for weak-ordered memory model archs,
731 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
732 e1000e_update_rdt_wa(rx_ring, i << 1);
734 writel(i << 1, rx_ring->tail);
738 if (i == rx_ring->count)
740 buffer_info = &rx_ring->buffer_info[i];
744 rx_ring->next_to_use = i;
748 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
749 * @rx_ring: Rx descriptor ring
750 * @cleaned_count: number of buffers to allocate this pass
753 static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
754 int cleaned_count, gfp_t gfp)
756 struct e1000_adapter *adapter = rx_ring->adapter;
757 struct net_device *netdev = adapter->netdev;
758 struct pci_dev *pdev = adapter->pdev;
759 union e1000_rx_desc_extended *rx_desc;
760 struct e1000_buffer *buffer_info;
763 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
765 i = rx_ring->next_to_use;
766 buffer_info = &rx_ring->buffer_info[i];
768 while (cleaned_count--) {
769 skb = buffer_info->skb;
775 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
776 if (unlikely(!skb)) {
777 /* Better luck next round */
778 adapter->alloc_rx_buff_failed++;
782 buffer_info->skb = skb;
784 /* allocate a new page if necessary */
785 if (!buffer_info->page) {
786 buffer_info->page = alloc_page(gfp);
787 if (unlikely(!buffer_info->page)) {
788 adapter->alloc_rx_buff_failed++;
793 if (!buffer_info->dma)
794 buffer_info->dma = dma_map_page(&pdev->dev,
795 buffer_info->page, 0,
799 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
800 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
802 if (unlikely(++i == rx_ring->count))
804 buffer_info = &rx_ring->buffer_info[i];
807 if (likely(rx_ring->next_to_use != i)) {
808 rx_ring->next_to_use = i;
809 if (unlikely(i-- == 0))
810 i = (rx_ring->count - 1);
812 /* Force memory writes to complete before letting h/w
813 * know there are new descriptors to fetch. (Only
814 * applicable for weak-ordered memory model archs,
817 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
818 e1000e_update_rdt_wa(rx_ring, i);
820 writel(i, rx_ring->tail);
824 static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
827 if (netdev->features & NETIF_F_RXHASH)
828 skb->rxhash = le32_to_cpu(rss);
832 * e1000_clean_rx_irq - Send received data up the network stack
833 * @rx_ring: Rx descriptor ring
835 * the return value indicates whether actual cleaning was done, there
836 * is no guarantee that everything was cleaned
838 static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
841 struct e1000_adapter *adapter = rx_ring->adapter;
842 struct net_device *netdev = adapter->netdev;
843 struct pci_dev *pdev = adapter->pdev;
844 struct e1000_hw *hw = &adapter->hw;
845 union e1000_rx_desc_extended *rx_desc, *next_rxd;
846 struct e1000_buffer *buffer_info, *next_buffer;
849 int cleaned_count = 0;
850 bool cleaned = false;
851 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
853 i = rx_ring->next_to_clean;
854 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
855 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
856 buffer_info = &rx_ring->buffer_info[i];
858 while (staterr & E1000_RXD_STAT_DD) {
861 if (*work_done >= work_to_do)
864 rmb(); /* read descriptor and rx_buffer_info after status DD */
866 skb = buffer_info->skb;
867 buffer_info->skb = NULL;
869 prefetch(skb->data - NET_IP_ALIGN);
872 if (i == rx_ring->count)
874 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
877 next_buffer = &rx_ring->buffer_info[i];
881 dma_unmap_single(&pdev->dev,
883 adapter->rx_buffer_len,
885 buffer_info->dma = 0;
887 length = le16_to_cpu(rx_desc->wb.upper.length);
890 * !EOP means multiple descriptors were used to store a single
891 * packet, if that's the case we need to toss it. In fact, we
892 * need to toss every packet with the EOP bit clear and the
893 * next frame that _does_ have the EOP bit set, as it is by
894 * definition only a frame fragment
896 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
897 adapter->flags2 |= FLAG2_IS_DISCARDING;
899 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
900 /* All receives must fit into a single buffer */
901 e_dbg("Receive packet consumed multiple buffers\n");
903 buffer_info->skb = skb;
904 if (staterr & E1000_RXD_STAT_EOP)
905 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
909 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
910 !(netdev->features & NETIF_F_RXALL))) {
912 buffer_info->skb = skb;
916 /* adjust length to remove Ethernet CRC */
917 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
918 /* If configured to store CRC, don't subtract FCS,
919 * but keep the FCS bytes out of the total_rx_bytes
922 if (netdev->features & NETIF_F_RXFCS)
928 total_rx_bytes += length;
932 * code added for copybreak, this should improve
933 * performance for small packets with large amounts
934 * of reassembly being done in the stack
936 if (length < copybreak) {
937 struct sk_buff *new_skb =
938 netdev_alloc_skb_ip_align(netdev, length);
940 skb_copy_to_linear_data_offset(new_skb,
946 /* save the skb in buffer_info as good */
947 buffer_info->skb = skb;
950 /* else just continue with the old one */
952 /* end copybreak code */
953 skb_put(skb, length);
955 /* Receive Checksum Offload */
956 e1000_rx_checksum(adapter, staterr,
957 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
959 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
961 e1000_receive_skb(adapter, netdev, skb, staterr,
962 rx_desc->wb.upper.vlan);
965 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
967 /* return some buffers to hardware, one at a time is too slow */
968 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
969 adapter->alloc_rx_buf(rx_ring, cleaned_count,
974 /* use prefetched values */
976 buffer_info = next_buffer;
978 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
980 rx_ring->next_to_clean = i;
982 cleaned_count = e1000_desc_unused(rx_ring);
984 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
986 adapter->total_rx_bytes += total_rx_bytes;
987 adapter->total_rx_packets += total_rx_packets;
991 static void e1000_put_txbuf(struct e1000_ring *tx_ring,
992 struct e1000_buffer *buffer_info)
994 struct e1000_adapter *adapter = tx_ring->adapter;
996 if (buffer_info->dma) {
997 if (buffer_info->mapped_as_page)
998 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
999 buffer_info->length, DMA_TO_DEVICE);
1001 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1002 buffer_info->length, DMA_TO_DEVICE);
1003 buffer_info->dma = 0;
1005 if (buffer_info->skb) {
1006 dev_kfree_skb_any(buffer_info->skb);
1007 buffer_info->skb = NULL;
1009 buffer_info->time_stamp = 0;
1012 static void e1000_print_hw_hang(struct work_struct *work)
1014 struct e1000_adapter *adapter = container_of(work,
1015 struct e1000_adapter,
1017 struct net_device *netdev = adapter->netdev;
1018 struct e1000_ring *tx_ring = adapter->tx_ring;
1019 unsigned int i = tx_ring->next_to_clean;
1020 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1021 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
1022 struct e1000_hw *hw = &adapter->hw;
1023 u16 phy_status, phy_1000t_status, phy_ext_status;
1026 if (test_bit(__E1000_DOWN, &adapter->state))
1029 if (!adapter->tx_hang_recheck &&
1030 (adapter->flags2 & FLAG2_DMA_BURST)) {
1032 * May be block on write-back, flush and detect again
1033 * flush pending descriptor writebacks to memory
1035 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1036 /* execute the writes immediately */
1039 * Due to rare timing issues, write to TIDV again to ensure
1040 * the write is successful
1042 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1043 /* execute the writes immediately */
1045 adapter->tx_hang_recheck = true;
1048 /* Real hang detected */
1049 adapter->tx_hang_recheck = false;
1050 netif_stop_queue(netdev);
1052 e1e_rphy(hw, PHY_STATUS, &phy_status);
1053 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1054 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1056 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1058 /* detected Hardware unit hang */
1059 e_err("Detected Hardware Unit Hang:\n"
1062 " next_to_use <%x>\n"
1063 " next_to_clean <%x>\n"
1064 "buffer_info[next_to_clean]:\n"
1065 " time_stamp <%lx>\n"
1066 " next_to_watch <%x>\n"
1068 " next_to_watch.status <%x>\n"
1071 "PHY 1000BASE-T Status <%x>\n"
1072 "PHY Extended Status <%x>\n"
1073 "PCI Status <%x>\n",
1074 readl(tx_ring->head),
1075 readl(tx_ring->tail),
1076 tx_ring->next_to_use,
1077 tx_ring->next_to_clean,
1078 tx_ring->buffer_info[eop].time_stamp,
1081 eop_desc->upper.fields.status,
1090 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1091 * @tx_ring: Tx descriptor ring
1093 * the return value indicates whether actual cleaning was done, there
1094 * is no guarantee that everything was cleaned
1096 static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
1098 struct e1000_adapter *adapter = tx_ring->adapter;
1099 struct net_device *netdev = adapter->netdev;
1100 struct e1000_hw *hw = &adapter->hw;
1101 struct e1000_tx_desc *tx_desc, *eop_desc;
1102 struct e1000_buffer *buffer_info;
1103 unsigned int i, eop;
1104 unsigned int count = 0;
1105 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1106 unsigned int bytes_compl = 0, pkts_compl = 0;
1108 i = tx_ring->next_to_clean;
1109 eop = tx_ring->buffer_info[i].next_to_watch;
1110 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1112 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1113 (count < tx_ring->count)) {
1114 bool cleaned = false;
1115 rmb(); /* read buffer_info after eop_desc */
1116 for (; !cleaned; count++) {
1117 tx_desc = E1000_TX_DESC(*tx_ring, i);
1118 buffer_info = &tx_ring->buffer_info[i];
1119 cleaned = (i == eop);
1122 total_tx_packets += buffer_info->segs;
1123 total_tx_bytes += buffer_info->bytecount;
1124 if (buffer_info->skb) {
1125 bytes_compl += buffer_info->skb->len;
1130 e1000_put_txbuf(tx_ring, buffer_info);
1131 tx_desc->upper.data = 0;
1134 if (i == tx_ring->count)
1138 if (i == tx_ring->next_to_use)
1140 eop = tx_ring->buffer_info[i].next_to_watch;
1141 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1144 tx_ring->next_to_clean = i;
1146 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1148 #define TX_WAKE_THRESHOLD 32
1149 if (count && netif_carrier_ok(netdev) &&
1150 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
1151 /* Make sure that anybody stopping the queue after this
1152 * sees the new next_to_clean.
1156 if (netif_queue_stopped(netdev) &&
1157 !(test_bit(__E1000_DOWN, &adapter->state))) {
1158 netif_wake_queue(netdev);
1159 ++adapter->restart_queue;
1163 if (adapter->detect_tx_hung) {
1165 * Detect a transmit hang in hardware, this serializes the
1166 * check with the clearing of time_stamp and movement of i
1168 adapter->detect_tx_hung = false;
1169 if (tx_ring->buffer_info[i].time_stamp &&
1170 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
1171 + (adapter->tx_timeout_factor * HZ)) &&
1172 !(er32(STATUS) & E1000_STATUS_TXOFF))
1173 schedule_work(&adapter->print_hang_task);
1175 adapter->tx_hang_recheck = false;
1177 adapter->total_tx_bytes += total_tx_bytes;
1178 adapter->total_tx_packets += total_tx_packets;
1179 return count < tx_ring->count;
1183 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1184 * @rx_ring: Rx descriptor ring
1186 * the return value indicates whether actual cleaning was done, there
1187 * is no guarantee that everything was cleaned
1189 static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1192 struct e1000_adapter *adapter = rx_ring->adapter;
1193 struct e1000_hw *hw = &adapter->hw;
1194 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1195 struct net_device *netdev = adapter->netdev;
1196 struct pci_dev *pdev = adapter->pdev;
1197 struct e1000_buffer *buffer_info, *next_buffer;
1198 struct e1000_ps_page *ps_page;
1199 struct sk_buff *skb;
1201 u32 length, staterr;
1202 int cleaned_count = 0;
1203 bool cleaned = false;
1204 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1206 i = rx_ring->next_to_clean;
1207 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1208 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1209 buffer_info = &rx_ring->buffer_info[i];
1211 while (staterr & E1000_RXD_STAT_DD) {
1212 if (*work_done >= work_to_do)
1215 skb = buffer_info->skb;
1216 rmb(); /* read descriptor and rx_buffer_info after status DD */
1218 /* in the packet split case this is header only */
1219 prefetch(skb->data - NET_IP_ALIGN);
1222 if (i == rx_ring->count)
1224 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1227 next_buffer = &rx_ring->buffer_info[i];
1231 dma_unmap_single(&pdev->dev, buffer_info->dma,
1232 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
1233 buffer_info->dma = 0;
1235 /* see !EOP comment in other Rx routine */
1236 if (!(staterr & E1000_RXD_STAT_EOP))
1237 adapter->flags2 |= FLAG2_IS_DISCARDING;
1239 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
1240 e_dbg("Packet Split buffers didn't pick up the full packet\n");
1241 dev_kfree_skb_irq(skb);
1242 if (staterr & E1000_RXD_STAT_EOP)
1243 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1247 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1248 !(netdev->features & NETIF_F_RXALL))) {
1249 dev_kfree_skb_irq(skb);
1253 length = le16_to_cpu(rx_desc->wb.middle.length0);
1256 e_dbg("Last part of the packet spanning multiple descriptors\n");
1257 dev_kfree_skb_irq(skb);
1262 skb_put(skb, length);
1266 * this looks ugly, but it seems compiler issues make
1267 * it more efficient than reusing j
1269 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1272 * page alloc/put takes too long and effects small
1273 * packet throughput, so unsplit small packets and
1274 * save the alloc/put only valid in softirq (napi)
1275 * context to call kmap_*
1277 if (l1 && (l1 <= copybreak) &&
1278 ((length + l1) <= adapter->rx_ps_bsize0)) {
1281 ps_page = &buffer_info->ps_pages[0];
1284 * there is no documentation about how to call
1285 * kmap_atomic, so we can't hold the mapping
1288 dma_sync_single_for_cpu(&pdev->dev,
1292 vaddr = kmap_atomic(ps_page->page);
1293 memcpy(skb_tail_pointer(skb), vaddr, l1);
1294 kunmap_atomic(vaddr);
1295 dma_sync_single_for_device(&pdev->dev,
1300 /* remove the CRC */
1301 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1302 if (!(netdev->features & NETIF_F_RXFCS))
1311 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1312 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1316 ps_page = &buffer_info->ps_pages[j];
1317 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1320 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1321 ps_page->page = NULL;
1323 skb->data_len += length;
1324 skb->truesize += PAGE_SIZE;
1327 /* strip the ethernet crc, problem is we're using pages now so
1328 * this whole operation can get a little cpu intensive
1330 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1331 if (!(netdev->features & NETIF_F_RXFCS))
1332 pskb_trim(skb, skb->len - 4);
1336 total_rx_bytes += skb->len;
1339 e1000_rx_checksum(adapter, staterr,
1340 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1342 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1344 if (rx_desc->wb.upper.header_status &
1345 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1346 adapter->rx_hdr_split++;
1348 e1000_receive_skb(adapter, netdev, skb,
1349 staterr, rx_desc->wb.middle.vlan);
1352 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1353 buffer_info->skb = NULL;
1355 /* return some buffers to hardware, one at a time is too slow */
1356 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1357 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1362 /* use prefetched values */
1364 buffer_info = next_buffer;
1366 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1368 rx_ring->next_to_clean = i;
1370 cleaned_count = e1000_desc_unused(rx_ring);
1372 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1374 adapter->total_rx_bytes += total_rx_bytes;
1375 adapter->total_rx_packets += total_rx_packets;
1380 * e1000_consume_page - helper function
1382 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1387 skb->data_len += length;
1388 skb->truesize += PAGE_SIZE;
1392 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1393 * @adapter: board private structure
1395 * the return value indicates whether actual cleaning was done, there
1396 * is no guarantee that everything was cleaned
1398 static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1401 struct e1000_adapter *adapter = rx_ring->adapter;
1402 struct net_device *netdev = adapter->netdev;
1403 struct pci_dev *pdev = adapter->pdev;
1404 union e1000_rx_desc_extended *rx_desc, *next_rxd;
1405 struct e1000_buffer *buffer_info, *next_buffer;
1406 u32 length, staterr;
1408 int cleaned_count = 0;
1409 bool cleaned = false;
1410 unsigned int total_rx_bytes=0, total_rx_packets=0;
1412 i = rx_ring->next_to_clean;
1413 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1414 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1415 buffer_info = &rx_ring->buffer_info[i];
1417 while (staterr & E1000_RXD_STAT_DD) {
1418 struct sk_buff *skb;
1420 if (*work_done >= work_to_do)
1423 rmb(); /* read descriptor and rx_buffer_info after status DD */
1425 skb = buffer_info->skb;
1426 buffer_info->skb = NULL;
1429 if (i == rx_ring->count)
1431 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
1434 next_buffer = &rx_ring->buffer_info[i];
1438 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1440 buffer_info->dma = 0;
1442 length = le16_to_cpu(rx_desc->wb.upper.length);
1444 /* errors is only valid for DD + EOP descriptors */
1445 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1446 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1447 !(netdev->features & NETIF_F_RXALL)))) {
1448 /* recycle both page and skb */
1449 buffer_info->skb = skb;
1450 /* an error means any chain goes out the window too */
1451 if (rx_ring->rx_skb_top)
1452 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1453 rx_ring->rx_skb_top = NULL;
1457 #define rxtop (rx_ring->rx_skb_top)
1458 if (!(staterr & E1000_RXD_STAT_EOP)) {
1459 /* this descriptor is only the beginning (or middle) */
1461 /* this is the beginning of a chain */
1463 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1466 /* this is the middle of a chain */
1467 skb_fill_page_desc(rxtop,
1468 skb_shinfo(rxtop)->nr_frags,
1469 buffer_info->page, 0, length);
1470 /* re-use the skb, only consumed the page */
1471 buffer_info->skb = skb;
1473 e1000_consume_page(buffer_info, rxtop, length);
1477 /* end of the chain */
1478 skb_fill_page_desc(rxtop,
1479 skb_shinfo(rxtop)->nr_frags,
1480 buffer_info->page, 0, length);
1481 /* re-use the current skb, we only consumed the
1483 buffer_info->skb = skb;
1486 e1000_consume_page(buffer_info, skb, length);
1488 /* no chain, got EOP, this buf is the packet
1489 * copybreak to save the put_page/alloc_page */
1490 if (length <= copybreak &&
1491 skb_tailroom(skb) >= length) {
1493 vaddr = kmap_atomic(buffer_info->page);
1494 memcpy(skb_tail_pointer(skb), vaddr,
1496 kunmap_atomic(vaddr);
1497 /* re-use the page, so don't erase
1498 * buffer_info->page */
1499 skb_put(skb, length);
1501 skb_fill_page_desc(skb, 0,
1502 buffer_info->page, 0,
1504 e1000_consume_page(buffer_info, skb,
1510 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1511 e1000_rx_checksum(adapter, staterr,
1512 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1514 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1516 /* probably a little skewed due to removing CRC */
1517 total_rx_bytes += skb->len;
1520 /* eth type trans needs skb->data to point to something */
1521 if (!pskb_may_pull(skb, ETH_HLEN)) {
1522 e_err("pskb_may_pull failed.\n");
1523 dev_kfree_skb_irq(skb);
1527 e1000_receive_skb(adapter, netdev, skb, staterr,
1528 rx_desc->wb.upper.vlan);
1531 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
1533 /* return some buffers to hardware, one at a time is too slow */
1534 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1535 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1540 /* use prefetched values */
1542 buffer_info = next_buffer;
1544 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1546 rx_ring->next_to_clean = i;
1548 cleaned_count = e1000_desc_unused(rx_ring);
1550 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1552 adapter->total_rx_bytes += total_rx_bytes;
1553 adapter->total_rx_packets += total_rx_packets;
1558 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1559 * @rx_ring: Rx descriptor ring
1561 static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
1563 struct e1000_adapter *adapter = rx_ring->adapter;
1564 struct e1000_buffer *buffer_info;
1565 struct e1000_ps_page *ps_page;
1566 struct pci_dev *pdev = adapter->pdev;
1569 /* Free all the Rx ring sk_buffs */
1570 for (i = 0; i < rx_ring->count; i++) {
1571 buffer_info = &rx_ring->buffer_info[i];
1572 if (buffer_info->dma) {
1573 if (adapter->clean_rx == e1000_clean_rx_irq)
1574 dma_unmap_single(&pdev->dev, buffer_info->dma,
1575 adapter->rx_buffer_len,
1577 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1578 dma_unmap_page(&pdev->dev, buffer_info->dma,
1581 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1582 dma_unmap_single(&pdev->dev, buffer_info->dma,
1583 adapter->rx_ps_bsize0,
1585 buffer_info->dma = 0;
1588 if (buffer_info->page) {
1589 put_page(buffer_info->page);
1590 buffer_info->page = NULL;
1593 if (buffer_info->skb) {
1594 dev_kfree_skb(buffer_info->skb);
1595 buffer_info->skb = NULL;
1598 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1599 ps_page = &buffer_info->ps_pages[j];
1602 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1605 put_page(ps_page->page);
1606 ps_page->page = NULL;
1610 /* there also may be some cached data from a chained receive */
1611 if (rx_ring->rx_skb_top) {
1612 dev_kfree_skb(rx_ring->rx_skb_top);
1613 rx_ring->rx_skb_top = NULL;
1616 /* Zero out the descriptor ring */
1617 memset(rx_ring->desc, 0, rx_ring->size);
1619 rx_ring->next_to_clean = 0;
1620 rx_ring->next_to_use = 0;
1621 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1623 writel(0, rx_ring->head);
1624 if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
1625 e1000e_update_rdt_wa(rx_ring, 0);
1627 writel(0, rx_ring->tail);
1630 static void e1000e_downshift_workaround(struct work_struct *work)
1632 struct e1000_adapter *adapter = container_of(work,
1633 struct e1000_adapter, downshift_task);
1635 if (test_bit(__E1000_DOWN, &adapter->state))
1638 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1642 * e1000_intr_msi - Interrupt Handler
1643 * @irq: interrupt number
1644 * @data: pointer to a network interface device structure
1646 static irqreturn_t e1000_intr_msi(int irq, void *data)
1648 struct net_device *netdev = data;
1649 struct e1000_adapter *adapter = netdev_priv(netdev);
1650 struct e1000_hw *hw = &adapter->hw;
1651 u32 icr = er32(ICR);
1654 * read ICR disables interrupts using IAM
1657 if (icr & E1000_ICR_LSC) {
1658 hw->mac.get_link_status = true;
1660 * ICH8 workaround-- Call gig speed drop workaround on cable
1661 * disconnect (LSC) before accessing any PHY registers
1663 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1664 (!(er32(STATUS) & E1000_STATUS_LU)))
1665 schedule_work(&adapter->downshift_task);
1668 * 80003ES2LAN workaround-- For packet buffer work-around on
1669 * link down event; disable receives here in the ISR and reset
1670 * adapter in watchdog
1672 if (netif_carrier_ok(netdev) &&
1673 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1674 /* disable receives */
1675 u32 rctl = er32(RCTL);
1676 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1677 adapter->flags |= FLAG_RX_RESTART_NOW;
1679 /* guard against interrupt when we're going down */
1680 if (!test_bit(__E1000_DOWN, &adapter->state))
1681 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1684 if (napi_schedule_prep(&adapter->napi)) {
1685 adapter->total_tx_bytes = 0;
1686 adapter->total_tx_packets = 0;
1687 adapter->total_rx_bytes = 0;
1688 adapter->total_rx_packets = 0;
1689 __napi_schedule(&adapter->napi);
1696 * e1000_intr - Interrupt Handler
1697 * @irq: interrupt number
1698 * @data: pointer to a network interface device structure
1700 static irqreturn_t e1000_intr(int irq, void *data)
1702 struct net_device *netdev = data;
1703 struct e1000_adapter *adapter = netdev_priv(netdev);
1704 struct e1000_hw *hw = &adapter->hw;
1705 u32 rctl, icr = er32(ICR);
1707 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
1708 return IRQ_NONE; /* Not our interrupt */
1711 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1712 * not set, then the adapter didn't send an interrupt
1714 if (!(icr & E1000_ICR_INT_ASSERTED))
1718 * Interrupt Auto-Mask...upon reading ICR,
1719 * interrupts are masked. No need for the
1723 if (icr & E1000_ICR_LSC) {
1724 hw->mac.get_link_status = true;
1726 * ICH8 workaround-- Call gig speed drop workaround on cable
1727 * disconnect (LSC) before accessing any PHY registers
1729 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1730 (!(er32(STATUS) & E1000_STATUS_LU)))
1731 schedule_work(&adapter->downshift_task);
1734 * 80003ES2LAN workaround--
1735 * For packet buffer work-around on link down event;
1736 * disable receives here in the ISR and
1737 * reset adapter in watchdog
1739 if (netif_carrier_ok(netdev) &&
1740 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1741 /* disable receives */
1743 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1744 adapter->flags |= FLAG_RX_RESTART_NOW;
1746 /* guard against interrupt when we're going down */
1747 if (!test_bit(__E1000_DOWN, &adapter->state))
1748 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1751 if (napi_schedule_prep(&adapter->napi)) {
1752 adapter->total_tx_bytes = 0;
1753 adapter->total_tx_packets = 0;
1754 adapter->total_rx_bytes = 0;
1755 adapter->total_rx_packets = 0;
1756 __napi_schedule(&adapter->napi);
1762 static irqreturn_t e1000_msix_other(int irq, void *data)
1764 struct net_device *netdev = data;
1765 struct e1000_adapter *adapter = netdev_priv(netdev);
1766 struct e1000_hw *hw = &adapter->hw;
1767 u32 icr = er32(ICR);
1769 if (!(icr & E1000_ICR_INT_ASSERTED)) {
1770 if (!test_bit(__E1000_DOWN, &adapter->state))
1771 ew32(IMS, E1000_IMS_OTHER);
1775 if (icr & adapter->eiac_mask)
1776 ew32(ICS, (icr & adapter->eiac_mask));
1778 if (icr & E1000_ICR_OTHER) {
1779 if (!(icr & E1000_ICR_LSC))
1780 goto no_link_interrupt;
1781 hw->mac.get_link_status = true;
1782 /* guard against interrupt when we're going down */
1783 if (!test_bit(__E1000_DOWN, &adapter->state))
1784 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1788 if (!test_bit(__E1000_DOWN, &adapter->state))
1789 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
1795 static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1797 struct net_device *netdev = data;
1798 struct e1000_adapter *adapter = netdev_priv(netdev);
1799 struct e1000_hw *hw = &adapter->hw;
1800 struct e1000_ring *tx_ring = adapter->tx_ring;
1803 adapter->total_tx_bytes = 0;
1804 adapter->total_tx_packets = 0;
1806 if (!e1000_clean_tx_irq(tx_ring))
1807 /* Ring was not completely cleaned, so fire another interrupt */
1808 ew32(ICS, tx_ring->ims_val);
1813 static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1815 struct net_device *netdev = data;
1816 struct e1000_adapter *adapter = netdev_priv(netdev);
1817 struct e1000_ring *rx_ring = adapter->rx_ring;
1819 /* Write the ITR value calculated at the end of the
1820 * previous interrupt.
1822 if (rx_ring->set_itr) {
1823 writel(1000000000 / (rx_ring->itr_val * 256),
1824 rx_ring->itr_register);
1825 rx_ring->set_itr = 0;
1828 if (napi_schedule_prep(&adapter->napi)) {
1829 adapter->total_rx_bytes = 0;
1830 adapter->total_rx_packets = 0;
1831 __napi_schedule(&adapter->napi);
1837 * e1000_configure_msix - Configure MSI-X hardware
1839 * e1000_configure_msix sets up the hardware to properly
1840 * generate MSI-X interrupts.
1842 static void e1000_configure_msix(struct e1000_adapter *adapter)
1844 struct e1000_hw *hw = &adapter->hw;
1845 struct e1000_ring *rx_ring = adapter->rx_ring;
1846 struct e1000_ring *tx_ring = adapter->tx_ring;
1848 u32 ctrl_ext, ivar = 0;
1850 adapter->eiac_mask = 0;
1852 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1853 if (hw->mac.type == e1000_82574) {
1854 u32 rfctl = er32(RFCTL);
1855 rfctl |= E1000_RFCTL_ACK_DIS;
1859 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1860 /* Configure Rx vector */
1861 rx_ring->ims_val = E1000_IMS_RXQ0;
1862 adapter->eiac_mask |= rx_ring->ims_val;
1863 if (rx_ring->itr_val)
1864 writel(1000000000 / (rx_ring->itr_val * 256),
1865 rx_ring->itr_register);
1867 writel(1, rx_ring->itr_register);
1868 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1870 /* Configure Tx vector */
1871 tx_ring->ims_val = E1000_IMS_TXQ0;
1873 if (tx_ring->itr_val)
1874 writel(1000000000 / (tx_ring->itr_val * 256),
1875 tx_ring->itr_register);
1877 writel(1, tx_ring->itr_register);
1878 adapter->eiac_mask |= tx_ring->ims_val;
1879 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1881 /* set vector for Other Causes, e.g. link changes */
1883 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1884 if (rx_ring->itr_val)
1885 writel(1000000000 / (rx_ring->itr_val * 256),
1886 hw->hw_addr + E1000_EITR_82574(vector));
1888 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1890 /* Cause Tx interrupts on every write back */
1895 /* enable MSI-X PBA support */
1896 ctrl_ext = er32(CTRL_EXT);
1897 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1899 /* Auto-Mask Other interrupts upon ICR read */
1900 #define E1000_EIAC_MASK_82574 0x01F00000
1901 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1902 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1903 ew32(CTRL_EXT, ctrl_ext);
1907 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1909 if (adapter->msix_entries) {
1910 pci_disable_msix(adapter->pdev);
1911 kfree(adapter->msix_entries);
1912 adapter->msix_entries = NULL;
1913 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1914 pci_disable_msi(adapter->pdev);
1915 adapter->flags &= ~FLAG_MSI_ENABLED;
1920 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1922 * Attempt to configure interrupts using the best available
1923 * capabilities of the hardware and kernel.
1925 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1930 switch (adapter->int_mode) {
1931 case E1000E_INT_MODE_MSIX:
1932 if (adapter->flags & FLAG_HAS_MSIX) {
1933 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1934 adapter->msix_entries = kcalloc(adapter->num_vectors,
1935 sizeof(struct msix_entry),
1937 if (adapter->msix_entries) {
1938 for (i = 0; i < adapter->num_vectors; i++)
1939 adapter->msix_entries[i].entry = i;
1941 err = pci_enable_msix(adapter->pdev,
1942 adapter->msix_entries,
1943 adapter->num_vectors);
1947 /* MSI-X failed, so fall through and try MSI */
1948 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
1949 e1000e_reset_interrupt_capability(adapter);
1951 adapter->int_mode = E1000E_INT_MODE_MSI;
1953 case E1000E_INT_MODE_MSI:
1954 if (!pci_enable_msi(adapter->pdev)) {
1955 adapter->flags |= FLAG_MSI_ENABLED;
1957 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1958 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
1961 case E1000E_INT_MODE_LEGACY:
1962 /* Don't do anything; this is the system default */
1966 /* store the number of vectors being used */
1967 adapter->num_vectors = 1;
1971 * e1000_request_msix - Initialize MSI-X interrupts
1973 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1976 static int e1000_request_msix(struct e1000_adapter *adapter)
1978 struct net_device *netdev = adapter->netdev;
1979 int err = 0, vector = 0;
1981 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1982 snprintf(adapter->rx_ring->name,
1983 sizeof(adapter->rx_ring->name) - 1,
1984 "%s-rx-0", netdev->name);
1986 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1987 err = request_irq(adapter->msix_entries[vector].vector,
1988 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
1992 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
1993 E1000_EITR_82574(vector);
1994 adapter->rx_ring->itr_val = adapter->itr;
1997 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1998 snprintf(adapter->tx_ring->name,
1999 sizeof(adapter->tx_ring->name) - 1,
2000 "%s-tx-0", netdev->name);
2002 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2003 err = request_irq(adapter->msix_entries[vector].vector,
2004 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
2008 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2009 E1000_EITR_82574(vector);
2010 adapter->tx_ring->itr_val = adapter->itr;
2013 err = request_irq(adapter->msix_entries[vector].vector,
2014 e1000_msix_other, 0, netdev->name, netdev);
2018 e1000_configure_msix(adapter);
2024 * e1000_request_irq - initialize interrupts
2026 * Attempts to configure interrupts using the best available
2027 * capabilities of the hardware and kernel.
2029 static int e1000_request_irq(struct e1000_adapter *adapter)
2031 struct net_device *netdev = adapter->netdev;
2034 if (adapter->msix_entries) {
2035 err = e1000_request_msix(adapter);
2038 /* fall back to MSI */
2039 e1000e_reset_interrupt_capability(adapter);
2040 adapter->int_mode = E1000E_INT_MODE_MSI;
2041 e1000e_set_interrupt_capability(adapter);
2043 if (adapter->flags & FLAG_MSI_ENABLED) {
2044 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
2045 netdev->name, netdev);
2049 /* fall back to legacy interrupt */
2050 e1000e_reset_interrupt_capability(adapter);
2051 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2054 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
2055 netdev->name, netdev);
2057 e_err("Unable to allocate interrupt, Error: %d\n", err);
2062 static void e1000_free_irq(struct e1000_adapter *adapter)
2064 struct net_device *netdev = adapter->netdev;
2066 if (adapter->msix_entries) {
2069 free_irq(adapter->msix_entries[vector].vector, netdev);
2072 free_irq(adapter->msix_entries[vector].vector, netdev);
2075 /* Other Causes interrupt vector */
2076 free_irq(adapter->msix_entries[vector].vector, netdev);
2080 free_irq(adapter->pdev->irq, netdev);
2084 * e1000_irq_disable - Mask off interrupt generation on the NIC
2086 static void e1000_irq_disable(struct e1000_adapter *adapter)
2088 struct e1000_hw *hw = &adapter->hw;
2091 if (adapter->msix_entries)
2092 ew32(EIAC_82574, 0);
2095 if (adapter->msix_entries) {
2097 for (i = 0; i < adapter->num_vectors; i++)
2098 synchronize_irq(adapter->msix_entries[i].vector);
2100 synchronize_irq(adapter->pdev->irq);
2105 * e1000_irq_enable - Enable default interrupt generation settings
2107 static void e1000_irq_enable(struct e1000_adapter *adapter)
2109 struct e1000_hw *hw = &adapter->hw;
2111 if (adapter->msix_entries) {
2112 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2113 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2115 ew32(IMS, IMS_ENABLE_MASK);
2121 * e1000e_get_hw_control - get control of the h/w from f/w
2122 * @adapter: address of board private structure
2124 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2125 * For ASF and Pass Through versions of f/w this means that
2126 * the driver is loaded. For AMT version (only with 82573)
2127 * of the f/w this means that the network i/f is open.
2129 void e1000e_get_hw_control(struct e1000_adapter *adapter)
2131 struct e1000_hw *hw = &adapter->hw;
2135 /* Let firmware know the driver has taken over */
2136 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2138 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2139 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2140 ctrl_ext = er32(CTRL_EXT);
2141 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2146 * e1000e_release_hw_control - release control of the h/w to f/w
2147 * @adapter: address of board private structure
2149 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2150 * For ASF and Pass Through versions of f/w this means that the
2151 * driver is no longer loaded. For AMT version (only with 82573) i
2152 * of the f/w this means that the network i/f is closed.
2155 void e1000e_release_hw_control(struct e1000_adapter *adapter)
2157 struct e1000_hw *hw = &adapter->hw;
2161 /* Let firmware taken over control of h/w */
2162 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2164 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2165 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2166 ctrl_ext = er32(CTRL_EXT);
2167 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2172 * @e1000_alloc_ring - allocate memory for a ring structure
2174 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2175 struct e1000_ring *ring)
2177 struct pci_dev *pdev = adapter->pdev;
2179 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2188 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2189 * @tx_ring: Tx descriptor ring
2191 * Return 0 on success, negative on failure
2193 int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
2195 struct e1000_adapter *adapter = tx_ring->adapter;
2196 int err = -ENOMEM, size;
2198 size = sizeof(struct e1000_buffer) * tx_ring->count;
2199 tx_ring->buffer_info = vzalloc(size);
2200 if (!tx_ring->buffer_info)
2203 /* round up to nearest 4K */
2204 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2205 tx_ring->size = ALIGN(tx_ring->size, 4096);
2207 err = e1000_alloc_ring_dma(adapter, tx_ring);
2211 tx_ring->next_to_use = 0;
2212 tx_ring->next_to_clean = 0;
2216 vfree(tx_ring->buffer_info);
2217 e_err("Unable to allocate memory for the transmit descriptor ring\n");
2222 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2223 * @rx_ring: Rx descriptor ring
2225 * Returns 0 on success, negative on failure
2227 int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
2229 struct e1000_adapter *adapter = rx_ring->adapter;
2230 struct e1000_buffer *buffer_info;
2231 int i, size, desc_len, err = -ENOMEM;
2233 size = sizeof(struct e1000_buffer) * rx_ring->count;
2234 rx_ring->buffer_info = vzalloc(size);
2235 if (!rx_ring->buffer_info)
2238 for (i = 0; i < rx_ring->count; i++) {
2239 buffer_info = &rx_ring->buffer_info[i];
2240 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2241 sizeof(struct e1000_ps_page),
2243 if (!buffer_info->ps_pages)
2247 desc_len = sizeof(union e1000_rx_desc_packet_split);
2249 /* Round up to nearest 4K */
2250 rx_ring->size = rx_ring->count * desc_len;
2251 rx_ring->size = ALIGN(rx_ring->size, 4096);
2253 err = e1000_alloc_ring_dma(adapter, rx_ring);
2257 rx_ring->next_to_clean = 0;
2258 rx_ring->next_to_use = 0;
2259 rx_ring->rx_skb_top = NULL;
2264 for (i = 0; i < rx_ring->count; i++) {
2265 buffer_info = &rx_ring->buffer_info[i];
2266 kfree(buffer_info->ps_pages);
2269 vfree(rx_ring->buffer_info);
2270 e_err("Unable to allocate memory for the receive descriptor ring\n");
2275 * e1000_clean_tx_ring - Free Tx Buffers
2276 * @tx_ring: Tx descriptor ring
2278 static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
2280 struct e1000_adapter *adapter = tx_ring->adapter;
2281 struct e1000_buffer *buffer_info;
2285 for (i = 0; i < tx_ring->count; i++) {
2286 buffer_info = &tx_ring->buffer_info[i];
2287 e1000_put_txbuf(tx_ring, buffer_info);
2290 netdev_reset_queue(adapter->netdev);
2291 size = sizeof(struct e1000_buffer) * tx_ring->count;
2292 memset(tx_ring->buffer_info, 0, size);
2294 memset(tx_ring->desc, 0, tx_ring->size);
2296 tx_ring->next_to_use = 0;
2297 tx_ring->next_to_clean = 0;
2299 writel(0, tx_ring->head);
2300 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2301 e1000e_update_tdt_wa(tx_ring, 0);
2303 writel(0, tx_ring->tail);
2307 * e1000e_free_tx_resources - Free Tx Resources per Queue
2308 * @tx_ring: Tx descriptor ring
2310 * Free all transmit software resources
2312 void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
2314 struct e1000_adapter *adapter = tx_ring->adapter;
2315 struct pci_dev *pdev = adapter->pdev;
2317 e1000_clean_tx_ring(tx_ring);
2319 vfree(tx_ring->buffer_info);
2320 tx_ring->buffer_info = NULL;
2322 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2324 tx_ring->desc = NULL;
2328 * e1000e_free_rx_resources - Free Rx Resources
2329 * @rx_ring: Rx descriptor ring
2331 * Free all receive software resources
2333 void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
2335 struct e1000_adapter *adapter = rx_ring->adapter;
2336 struct pci_dev *pdev = adapter->pdev;
2339 e1000_clean_rx_ring(rx_ring);
2341 for (i = 0; i < rx_ring->count; i++)
2342 kfree(rx_ring->buffer_info[i].ps_pages);
2344 vfree(rx_ring->buffer_info);
2345 rx_ring->buffer_info = NULL;
2347 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2349 rx_ring->desc = NULL;
2353 * e1000_update_itr - update the dynamic ITR value based on statistics
2354 * @adapter: pointer to adapter
2355 * @itr_setting: current adapter->itr
2356 * @packets: the number of packets during this measurement interval
2357 * @bytes: the number of bytes during this measurement interval
2359 * Stores a new ITR value based on packets and byte
2360 * counts during the last interrupt. The advantage of per interrupt
2361 * computation is faster updates and more accurate ITR for the current
2362 * traffic pattern. Constants in this function were computed
2363 * based on theoretical maximum wire speed and thresholds were set based
2364 * on testing data as well as attempting to minimize response time
2365 * while increasing bulk throughput. This functionality is controlled
2366 * by the InterruptThrottleRate module parameter.
2368 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2369 u16 itr_setting, int packets,
2372 unsigned int retval = itr_setting;
2377 switch (itr_setting) {
2378 case lowest_latency:
2379 /* handle TSO and jumbo frames */
2380 if (bytes/packets > 8000)
2381 retval = bulk_latency;
2382 else if ((packets < 5) && (bytes > 512))
2383 retval = low_latency;
2385 case low_latency: /* 50 usec aka 20000 ints/s */
2386 if (bytes > 10000) {
2387 /* this if handles the TSO accounting */
2388 if (bytes/packets > 8000)
2389 retval = bulk_latency;
2390 else if ((packets < 10) || ((bytes/packets) > 1200))
2391 retval = bulk_latency;
2392 else if ((packets > 35))
2393 retval = lowest_latency;
2394 } else if (bytes/packets > 2000) {
2395 retval = bulk_latency;
2396 } else if (packets <= 2 && bytes < 512) {
2397 retval = lowest_latency;
2400 case bulk_latency: /* 250 usec aka 4000 ints/s */
2401 if (bytes > 25000) {
2403 retval = low_latency;
2404 } else if (bytes < 6000) {
2405 retval = low_latency;
2413 static void e1000_set_itr(struct e1000_adapter *adapter)
2415 struct e1000_hw *hw = &adapter->hw;
2417 u32 new_itr = adapter->itr;
2419 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2420 if (adapter->link_speed != SPEED_1000) {
2426 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2431 adapter->tx_itr = e1000_update_itr(adapter,
2433 adapter->total_tx_packets,
2434 adapter->total_tx_bytes);
2435 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2436 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2437 adapter->tx_itr = low_latency;
2439 adapter->rx_itr = e1000_update_itr(adapter,
2441 adapter->total_rx_packets,
2442 adapter->total_rx_bytes);
2443 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2444 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2445 adapter->rx_itr = low_latency;
2447 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2449 switch (current_itr) {
2450 /* counts and packets in update_itr are dependent on these numbers */
2451 case lowest_latency:
2455 new_itr = 20000; /* aka hwitr = ~200 */
2465 if (new_itr != adapter->itr) {
2467 * this attempts to bias the interrupt rate towards Bulk
2468 * by adding intermediate steps when interrupt rate is
2471 new_itr = new_itr > adapter->itr ?
2472 min(adapter->itr + (new_itr >> 2), new_itr) :
2474 adapter->itr = new_itr;
2475 adapter->rx_ring->itr_val = new_itr;
2476 if (adapter->msix_entries)
2477 adapter->rx_ring->set_itr = 1;
2480 ew32(ITR, 1000000000 / (new_itr * 256));
2487 * e1000_alloc_queues - Allocate memory for all rings
2488 * @adapter: board private structure to initialize
2490 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2492 int size = sizeof(struct e1000_ring);
2494 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
2495 if (!adapter->tx_ring)
2497 adapter->tx_ring->count = adapter->tx_ring_count;
2498 adapter->tx_ring->adapter = adapter;
2500 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
2501 if (!adapter->rx_ring)
2503 adapter->rx_ring->count = adapter->rx_ring_count;
2504 adapter->rx_ring->adapter = adapter;
2508 e_err("Unable to allocate memory for queues\n");
2509 kfree(adapter->rx_ring);
2510 kfree(adapter->tx_ring);
2515 * e1000e_poll - NAPI Rx polling callback
2516 * @napi: struct associated with this polling callback
2517 * @weight: number of packets driver is allowed to process this poll
2519 static int e1000e_poll(struct napi_struct *napi, int weight)
2521 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2523 struct e1000_hw *hw = &adapter->hw;
2524 struct net_device *poll_dev = adapter->netdev;
2525 int tx_cleaned = 1, work_done = 0;
2527 adapter = netdev_priv(poll_dev);
2529 if (!adapter->msix_entries ||
2530 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2531 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
2533 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
2538 /* If weight not fully consumed, exit the polling mode */
2539 if (work_done < weight) {
2540 if (adapter->itr_setting & 3)
2541 e1000_set_itr(adapter);
2542 napi_complete(napi);
2543 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2544 if (adapter->msix_entries)
2545 ew32(IMS, adapter->rx_ring->ims_val);
2547 e1000_irq_enable(adapter);
2554 static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2556 struct e1000_adapter *adapter = netdev_priv(netdev);
2557 struct e1000_hw *hw = &adapter->hw;
2560 /* don't update vlan cookie if already programmed */
2561 if ((adapter->hw.mng_cookie.status &
2562 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2563 (vid == adapter->mng_vlan_id))
2566 /* add VID to filter table */
2567 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2568 index = (vid >> 5) & 0x7F;
2569 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2570 vfta |= (1 << (vid & 0x1F));
2571 hw->mac.ops.write_vfta(hw, index, vfta);
2574 set_bit(vid, adapter->active_vlans);
2579 static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2581 struct e1000_adapter *adapter = netdev_priv(netdev);
2582 struct e1000_hw *hw = &adapter->hw;
2585 if ((adapter->hw.mng_cookie.status &
2586 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2587 (vid == adapter->mng_vlan_id)) {
2588 /* release control to f/w */
2589 e1000e_release_hw_control(adapter);
2593 /* remove VID from filter table */
2594 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2595 index = (vid >> 5) & 0x7F;
2596 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2597 vfta &= ~(1 << (vid & 0x1F));
2598 hw->mac.ops.write_vfta(hw, index, vfta);
2601 clear_bit(vid, adapter->active_vlans);
2607 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2608 * @adapter: board private structure to initialize
2610 static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2612 struct net_device *netdev = adapter->netdev;
2613 struct e1000_hw *hw = &adapter->hw;
2616 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2617 /* disable VLAN receive filtering */
2619 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2622 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2623 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2624 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2630 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2631 * @adapter: board private structure to initialize
2633 static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2635 struct e1000_hw *hw = &adapter->hw;
2638 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2639 /* enable VLAN receive filtering */
2641 rctl |= E1000_RCTL_VFE;
2642 rctl &= ~E1000_RCTL_CFIEN;
2648 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2649 * @adapter: board private structure to initialize
2651 static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2653 struct e1000_hw *hw = &adapter->hw;
2656 /* disable VLAN tag insert/strip */
2658 ctrl &= ~E1000_CTRL_VME;
2663 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2664 * @adapter: board private structure to initialize
2666 static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2668 struct e1000_hw *hw = &adapter->hw;
2671 /* enable VLAN tag insert/strip */
2673 ctrl |= E1000_CTRL_VME;
2677 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2679 struct net_device *netdev = adapter->netdev;
2680 u16 vid = adapter->hw.mng_cookie.vlan_id;
2681 u16 old_vid = adapter->mng_vlan_id;
2683 if (adapter->hw.mng_cookie.status &
2684 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2685 e1000_vlan_rx_add_vid(netdev, vid);
2686 adapter->mng_vlan_id = vid;
2689 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2690 e1000_vlan_rx_kill_vid(netdev, old_vid);
2693 static void e1000_restore_vlan(struct e1000_adapter *adapter)
2697 e1000_vlan_rx_add_vid(adapter->netdev, 0);
2699 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
2700 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2703 static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
2705 struct e1000_hw *hw = &adapter->hw;
2706 u32 manc, manc2h, mdef, i, j;
2708 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2714 * enable receiving management packets to the host. this will probably
2715 * generate destination unreachable messages from the host OS, but
2716 * the packets will be handled on SMBUS
2718 manc |= E1000_MANC_EN_MNG2HOST;
2719 manc2h = er32(MANC2H);
2721 switch (hw->mac.type) {
2723 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2728 * Check if IPMI pass-through decision filter already exists;
2731 for (i = 0, j = 0; i < 8; i++) {
2732 mdef = er32(MDEF(i));
2734 /* Ignore filters with anything other than IPMI ports */
2735 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2738 /* Enable this decision filter in MANC2H */
2745 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2748 /* Create new decision filter in an empty filter */
2749 for (i = 0, j = 0; i < 8; i++)
2750 if (er32(MDEF(i)) == 0) {
2751 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2752 E1000_MDEF_PORT_664));
2759 e_warn("Unable to create IPMI pass-through filter\n");
2763 ew32(MANC2H, manc2h);
2768 * e1000_configure_tx - Configure Transmit Unit after Reset
2769 * @adapter: board private structure
2771 * Configure the Tx unit of the MAC after a reset.
2773 static void e1000_configure_tx(struct e1000_adapter *adapter)
2775 struct e1000_hw *hw = &adapter->hw;
2776 struct e1000_ring *tx_ring = adapter->tx_ring;
2780 /* Setup the HW Tx Head and Tail descriptor pointers */
2781 tdba = tx_ring->dma;
2782 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2783 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2784 ew32(TDBAH(0), (tdba >> 32));
2785 ew32(TDLEN(0), tdlen);
2788 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2789 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
2791 /* Set the Tx Interrupt Delay register */
2792 ew32(TIDV, adapter->tx_int_delay);
2793 /* Tx irq moderation */
2794 ew32(TADV, adapter->tx_abs_int_delay);
2796 if (adapter->flags2 & FLAG2_DMA_BURST) {
2797 u32 txdctl = er32(TXDCTL(0));
2798 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2799 E1000_TXDCTL_WTHRESH);
2801 * set up some performance related parameters to encourage the
2802 * hardware to use the bus more efficiently in bursts, depends
2803 * on the tx_int_delay to be enabled,
2804 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2805 * hthresh = 1 ==> prefetch when one or more available
2806 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2807 * BEWARE: this seems to work but should be considered first if
2808 * there are Tx hangs or other Tx related bugs
2810 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2811 ew32(TXDCTL(0), txdctl);
2813 /* erratum work around: set txdctl the same for both queues */
2814 ew32(TXDCTL(1), er32(TXDCTL(0)));
2816 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
2817 tarc = er32(TARC(0));
2819 * set the speed mode bit, we'll clear it if we're not at
2820 * gigabit link later
2822 #define SPEED_MODE_BIT (1 << 21)
2823 tarc |= SPEED_MODE_BIT;
2824 ew32(TARC(0), tarc);
2827 /* errata: program both queues to unweighted RR */
2828 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
2829 tarc = er32(TARC(0));
2831 ew32(TARC(0), tarc);
2832 tarc = er32(TARC(1));
2834 ew32(TARC(1), tarc);
2837 /* Setup Transmit Descriptor Settings for eop descriptor */
2838 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2840 /* only set IDE if we are delaying interrupts using the timers */
2841 if (adapter->tx_int_delay)
2842 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2844 /* enable Report Status bit */
2845 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2847 hw->mac.ops.config_collision_dist(hw);
2851 * e1000_setup_rctl - configure the receive control registers
2852 * @adapter: Board private structure
2854 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2855 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2856 static void e1000_setup_rctl(struct e1000_adapter *adapter)
2858 struct e1000_hw *hw = &adapter->hw;
2862 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2863 if (hw->mac.type == e1000_pch2lan) {
2866 if (adapter->netdev->mtu > ETH_DATA_LEN)
2867 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2869 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
2872 e_dbg("failed to enable jumbo frame workaround mode\n");
2875 /* Program MC offset vector base */
2877 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2878 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2879 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2880 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2882 /* Do not Store bad packets */
2883 rctl &= ~E1000_RCTL_SBP;
2885 /* Enable Long Packet receive */
2886 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2887 rctl &= ~E1000_RCTL_LPE;
2889 rctl |= E1000_RCTL_LPE;
2891 /* Some systems expect that the CRC is included in SMBUS traffic. The
2892 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2893 * host memory when this is enabled
2895 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2896 rctl |= E1000_RCTL_SECRC;
2898 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2899 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2902 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2904 phy_data |= (1 << 2);
2905 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2907 e1e_rphy(hw, 22, &phy_data);
2909 phy_data |= (1 << 14);
2910 e1e_wphy(hw, 0x10, 0x2823);
2911 e1e_wphy(hw, 0x11, 0x0003);
2912 e1e_wphy(hw, 22, phy_data);
2915 /* Setup buffer sizes */
2916 rctl &= ~E1000_RCTL_SZ_4096;
2917 rctl |= E1000_RCTL_BSEX;
2918 switch (adapter->rx_buffer_len) {
2921 rctl |= E1000_RCTL_SZ_2048;
2922 rctl &= ~E1000_RCTL_BSEX;
2925 rctl |= E1000_RCTL_SZ_4096;
2928 rctl |= E1000_RCTL_SZ_8192;
2931 rctl |= E1000_RCTL_SZ_16384;
2935 /* Enable Extended Status in all Receive Descriptors */
2936 rfctl = er32(RFCTL);
2937 rfctl |= E1000_RFCTL_EXTEN;
2940 * 82571 and greater support packet-split where the protocol
2941 * header is placed in skb->data and the packet data is
2942 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2943 * In the case of a non-split, skb->data is linearly filled,
2944 * followed by the page buffers. Therefore, skb->data is
2945 * sized to hold the largest protocol header.
2947 * allocations using alloc_page take too long for regular MTU
2948 * so only enable packet split for jumbo frames
2950 * Using pages when the page size is greater than 16k wastes
2951 * a lot of memory, since we allocate 3 pages at all times
2954 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2955 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
2956 adapter->rx_ps_pages = pages;
2958 adapter->rx_ps_pages = 0;
2960 if (adapter->rx_ps_pages) {
2964 * disable packet split support for IPv6 extension headers,
2965 * because some malformed IPv6 headers can hang the Rx
2967 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2968 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2970 /* Enable Packet split descriptors */
2971 rctl |= E1000_RCTL_DTYP_PS;
2973 psrctl |= adapter->rx_ps_bsize0 >>
2974 E1000_PSRCTL_BSIZE0_SHIFT;
2976 switch (adapter->rx_ps_pages) {
2978 psrctl |= PAGE_SIZE <<
2979 E1000_PSRCTL_BSIZE3_SHIFT;
2981 psrctl |= PAGE_SIZE <<
2982 E1000_PSRCTL_BSIZE2_SHIFT;
2984 psrctl |= PAGE_SIZE >>
2985 E1000_PSRCTL_BSIZE1_SHIFT;
2989 ew32(PSRCTL, psrctl);
2992 /* This is useful for sniffing bad packets. */
2993 if (adapter->netdev->features & NETIF_F_RXALL) {
2994 /* UPE and MPE will be handled by normal PROMISC logic
2995 * in e1000e_set_rx_mode */
2996 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
2997 E1000_RCTL_BAM | /* RX All Bcast Pkts */
2998 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3000 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3001 E1000_RCTL_DPF | /* Allow filtered pause */
3002 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3003 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3004 * and that breaks VLANs.
3010 /* just started the receive unit, no need to restart */
3011 adapter->flags &= ~FLAG_RX_RESTART_NOW;
3015 * e1000_configure_rx - Configure Receive Unit after Reset
3016 * @adapter: board private structure
3018 * Configure the Rx unit of the MAC after a reset.
3020 static void e1000_configure_rx(struct e1000_adapter *adapter)
3022 struct e1000_hw *hw = &adapter->hw;
3023 struct e1000_ring *rx_ring = adapter->rx_ring;
3025 u32 rdlen, rctl, rxcsum, ctrl_ext;
3027 if (adapter->rx_ps_pages) {
3028 /* this is a 32 byte descriptor */
3029 rdlen = rx_ring->count *
3030 sizeof(union e1000_rx_desc_packet_split);
3031 adapter->clean_rx = e1000_clean_rx_irq_ps;
3032 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
3033 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
3034 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3035 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3036 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
3038 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3039 adapter->clean_rx = e1000_clean_rx_irq;
3040 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3043 /* disable receives while setting up the descriptors */
3045 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3046 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3048 usleep_range(10000, 20000);
3050 if (adapter->flags2 & FLAG2_DMA_BURST) {
3052 * set the writeback threshold (only takes effect if the RDTR
3053 * is set). set GRAN=1 and write back up to 0x4 worth, and
3054 * enable prefetching of 0x20 Rx descriptors
3060 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3061 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3064 * override the delay timers for enabling bursting, only if
3065 * the value was not set by the user via module options
3067 if (adapter->rx_int_delay == DEFAULT_RDTR)
3068 adapter->rx_int_delay = BURST_RDTR;
3069 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3070 adapter->rx_abs_int_delay = BURST_RADV;
3073 /* set the Receive Delay Timer Register */
3074 ew32(RDTR, adapter->rx_int_delay);
3076 /* irq moderation */
3077 ew32(RADV, adapter->rx_abs_int_delay);
3078 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
3079 ew32(ITR, 1000000000 / (adapter->itr * 256));
3081 ctrl_ext = er32(CTRL_EXT);
3082 /* Auto-Mask interrupts upon ICR access */
3083 ctrl_ext |= E1000_CTRL_EXT_IAME;
3084 ew32(IAM, 0xffffffff);
3085 ew32(CTRL_EXT, ctrl_ext);
3089 * Setup the HW Rx Head and Tail Descriptor Pointers and
3090 * the Base and Length of the Rx Descriptor Ring
3092 rdba = rx_ring->dma;
3093 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3094 ew32(RDBAH(0), (rdba >> 32));
3095 ew32(RDLEN(0), rdlen);
3098 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3099 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
3101 /* Enable Receive Checksum Offload for TCP and UDP */
3102 rxcsum = er32(RXCSUM);
3103 if (adapter->netdev->features & NETIF_F_RXCSUM) {
3104 rxcsum |= E1000_RXCSUM_TUOFL;
3107 * IPv4 payload checksum for UDP fragments must be
3108 * used in conjunction with packet-split.
3110 if (adapter->rx_ps_pages)
3111 rxcsum |= E1000_RXCSUM_IPPCSE;
3113 rxcsum &= ~E1000_RXCSUM_TUOFL;
3114 /* no need to clear IPPCSE as it defaults to 0 */
3116 ew32(RXCSUM, rxcsum);
3118 if (adapter->hw.mac.type == e1000_pch2lan) {
3120 * With jumbo frames, excessive C-state transition
3121 * latencies result in dropped transactions.
3123 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3124 u32 rxdctl = er32(RXDCTL(0));
3125 ew32(RXDCTL(0), rxdctl | 0x3);
3126 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
3128 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3129 PM_QOS_DEFAULT_VALUE);
3133 /* Enable Receives */
3138 * e1000e_write_mc_addr_list - write multicast addresses to MTA
3139 * @netdev: network interface device structure
3141 * Writes multicast address list to the MTA hash table.
3142 * Returns: -ENOMEM on failure
3143 * 0 on no addresses written
3144 * X on writing X addresses to MTA
3146 static int e1000e_write_mc_addr_list(struct net_device *netdev)
3148 struct e1000_adapter *adapter = netdev_priv(netdev);
3149 struct e1000_hw *hw = &adapter->hw;
3150 struct netdev_hw_addr *ha;
3154 if (netdev_mc_empty(netdev)) {
3155 /* nothing to program, so clear mc list */
3156 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3160 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3164 /* update_mc_addr_list expects a packed array of only addresses. */
3166 netdev_for_each_mc_addr(ha, netdev)
3167 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3169 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3172 return netdev_mc_count(netdev);
3176 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3177 * @netdev: network interface device structure
3179 * Writes unicast address list to the RAR table.
3180 * Returns: -ENOMEM on failure/insufficient address space
3181 * 0 on no addresses written
3182 * X on writing X addresses to the RAR table
3184 static int e1000e_write_uc_addr_list(struct net_device *netdev)
3186 struct e1000_adapter *adapter = netdev_priv(netdev);
3187 struct e1000_hw *hw = &adapter->hw;
3188 unsigned int rar_entries = hw->mac.rar_entry_count;
3191 /* save a rar entry for our hardware address */
3194 /* save a rar entry for the LAA workaround */
3195 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3198 /* return ENOMEM indicating insufficient memory for addresses */
3199 if (netdev_uc_count(netdev) > rar_entries)
3202 if (!netdev_uc_empty(netdev) && rar_entries) {
3203 struct netdev_hw_addr *ha;
3206 * write the addresses in reverse order to avoid write
3209 netdev_for_each_uc_addr(ha, netdev) {
3212 e1000e_rar_set(hw, ha->addr, rar_entries--);
3217 /* zero out the remaining RAR entries not used above */
3218 for (; rar_entries > 0; rar_entries--) {
3219 ew32(RAH(rar_entries), 0);
3220 ew32(RAL(rar_entries), 0);
3228 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3229 * @netdev: network interface device structure
3231 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3232 * address list or the network interface flags are updated. This routine is
3233 * responsible for configuring the hardware for proper unicast, multicast,
3234 * promiscuous mode, and all-multi behavior.
3236 static void e1000e_set_rx_mode(struct net_device *netdev)
3238 struct e1000_adapter *adapter = netdev_priv(netdev);
3239 struct e1000_hw *hw = &adapter->hw;
3242 /* Check for Promiscuous and All Multicast modes */
3245 /* clear the affected bits */
3246 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3248 if (netdev->flags & IFF_PROMISC) {
3249 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
3250 /* Do not hardware filter VLANs in promisc mode */
3251 e1000e_vlan_filter_disable(adapter);
3255 if (netdev->flags & IFF_ALLMULTI) {
3256 rctl |= E1000_RCTL_MPE;
3259 * Write addresses to the MTA, if the attempt fails
3260 * then we should just turn on promiscuous mode so
3261 * that we can at least receive multicast traffic
3263 count = e1000e_write_mc_addr_list(netdev);
3265 rctl |= E1000_RCTL_MPE;
3267 e1000e_vlan_filter_enable(adapter);
3269 * Write addresses to available RAR registers, if there is not
3270 * sufficient space to store all the addresses then enable
3271 * unicast promiscuous mode
3273 count = e1000e_write_uc_addr_list(netdev);
3275 rctl |= E1000_RCTL_UPE;
3280 if (netdev->features & NETIF_F_HW_VLAN_RX)
3281 e1000e_vlan_strip_enable(adapter);
3283 e1000e_vlan_strip_disable(adapter);
3286 static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3288 struct e1000_hw *hw = &adapter->hw;
3291 static const u32 rsskey[10] = {
3292 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3293 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3296 /* Fill out hash function seed */
3297 for (i = 0; i < 10; i++)
3298 ew32(RSSRK(i), rsskey[i]);
3300 /* Direct all traffic to queue 0 */
3301 for (i = 0; i < 32; i++)
3305 * Disable raw packet checksumming so that RSS hash is placed in
3306 * descriptor on writeback.
3308 rxcsum = er32(RXCSUM);
3309 rxcsum |= E1000_RXCSUM_PCSD;
3311 ew32(RXCSUM, rxcsum);
3313 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3314 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3315 E1000_MRQC_RSS_FIELD_IPV6 |
3316 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3317 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3323 * e1000_configure - configure the hardware for Rx and Tx
3324 * @adapter: private board structure
3326 static void e1000_configure(struct e1000_adapter *adapter)
3328 struct e1000_ring *rx_ring = adapter->rx_ring;
3330 e1000e_set_rx_mode(adapter->netdev);
3332 e1000_restore_vlan(adapter);
3333 e1000_init_manageability_pt(adapter);
3335 e1000_configure_tx(adapter);
3337 if (adapter->netdev->features & NETIF_F_RXHASH)
3338 e1000e_setup_rss_hash(adapter);
3339 e1000_setup_rctl(adapter);
3340 e1000_configure_rx(adapter);
3341 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
3345 * e1000e_power_up_phy - restore link in case the phy was powered down
3346 * @adapter: address of board private structure
3348 * The phy may be powered down to save power and turn off link when the
3349 * driver is unloaded and wake on lan is not enabled (among others)
3350 * *** this routine MUST be followed by a call to e1000e_reset ***
3352 void e1000e_power_up_phy(struct e1000_adapter *adapter)
3354 if (adapter->hw.phy.ops.power_up)
3355 adapter->hw.phy.ops.power_up(&adapter->hw);
3357 adapter->hw.mac.ops.setup_link(&adapter->hw);
3361 * e1000_power_down_phy - Power down the PHY
3363 * Power down the PHY so no link is implied when interface is down.
3364 * The PHY cannot be powered down if management or WoL is active.
3366 static void e1000_power_down_phy(struct e1000_adapter *adapter)
3368 /* WoL is enabled */
3372 if (adapter->hw.phy.ops.power_down)
3373 adapter->hw.phy.ops.power_down(&adapter->hw);
3377 * e1000e_reset - bring the hardware into a known good state
3379 * This function boots the hardware and enables some settings that
3380 * require a configuration cycle of the hardware - those cannot be
3381 * set/changed during runtime. After reset the device needs to be
3382 * properly configured for Rx, Tx etc.
3384 void e1000e_reset(struct e1000_adapter *adapter)
3386 struct e1000_mac_info *mac = &adapter->hw.mac;
3387 struct e1000_fc_info *fc = &adapter->hw.fc;
3388 struct e1000_hw *hw = &adapter->hw;
3389 u32 tx_space, min_tx_space, min_rx_space;
3390 u32 pba = adapter->pba;
3393 /* reset Packet Buffer Allocation to default */
3396 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
3398 * To maintain wire speed transmits, the Tx FIFO should be
3399 * large enough to accommodate two full transmit packets,
3400 * rounded up to the next 1KB and expressed in KB. Likewise,
3401 * the Rx FIFO should be large enough to accommodate at least
3402 * one full receive packet and is similarly rounded up and
3406 /* upper 16 bits has Tx packet buffer allocation size in KB */
3407 tx_space = pba >> 16;
3408 /* lower 16 bits has Rx packet buffer allocation size in KB */
3411 * the Tx fifo also stores 16 bytes of information about the Tx
3412 * but don't include ethernet FCS because hardware appends it
3414 min_tx_space = (adapter->max_frame_size +
3415 sizeof(struct e1000_tx_desc) -
3417 min_tx_space = ALIGN(min_tx_space, 1024);
3418 min_tx_space >>= 10;
3419 /* software strips receive CRC, so leave room for it */
3420 min_rx_space = adapter->max_frame_size;
3421 min_rx_space = ALIGN(min_rx_space, 1024);
3422 min_rx_space >>= 10;
3425 * If current Tx allocation is less than the min Tx FIFO size,
3426 * and the min Tx FIFO size is less than the current Rx FIFO
3427 * allocation, take space away from current Rx allocation
3429 if ((tx_space < min_tx_space) &&
3430 ((min_tx_space - tx_space) < pba)) {
3431 pba -= min_tx_space - tx_space;
3434 * if short on Rx space, Rx wins and must trump Tx
3435 * adjustment or use Early Receive if available
3437 if (pba < min_rx_space)
3445 * flow control settings
3447 * The high water mark must be low enough to fit one full frame
3448 * (or the size used for early receive) above it in the Rx FIFO.
3449 * Set it to the lower of:
3450 * - 90% of the Rx FIFO size, and
3451 * - the full Rx FIFO size minus one full frame
3453 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3454 fc->pause_time = 0xFFFF;
3456 fc->pause_time = E1000_FC_PAUSE_TIME;
3457 fc->send_xon = true;
3458 fc->current_mode = fc->requested_mode;
3460 switch (hw->mac.type) {
3462 case e1000_ich10lan:
3463 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3466 fc->high_water = 0x2800;
3467 fc->low_water = fc->high_water - 8;
3472 hwm = min(((pba << 10) * 9 / 10),
3473 ((pba << 10) - adapter->max_frame_size));
3475 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3476 fc->low_water = fc->high_water - 8;
3480 * Workaround PCH LOM adapter hangs with certain network
3481 * loads. If hangs persist, try disabling Tx flow control.
3483 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3484 fc->high_water = 0x3500;
3485 fc->low_water = 0x1500;
3487 fc->high_water = 0x5000;
3488 fc->low_water = 0x3000;
3490 fc->refresh_time = 0x1000;
3493 fc->high_water = 0x05C20;
3494 fc->low_water = 0x05048;
3495 fc->pause_time = 0x0650;
3496 fc->refresh_time = 0x0400;
3497 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3505 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3506 * fit in receive buffer.
3508 if (adapter->itr_setting & 0x3) {
3509 if ((adapter->max_frame_size * 2) > (pba << 10)) {
3510 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3511 dev_info(&adapter->pdev->dev,
3512 "Interrupt Throttle Rate turned off\n");
3513 adapter->flags2 |= FLAG2_DISABLE_AIM;
3516 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3517 dev_info(&adapter->pdev->dev,
3518 "Interrupt Throttle Rate turned on\n");
3519 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3520 adapter->itr = 20000;
3521 ew32(ITR, 1000000000 / (adapter->itr * 256));
3525 /* Allow time for pending master requests to run */
3526 mac->ops.reset_hw(hw);
3529 * For parts with AMT enabled, let the firmware know
3530 * that the network interface is in control
3532 if (adapter->flags & FLAG_HAS_AMT)
3533 e1000e_get_hw_control(adapter);
3537 if (mac->ops.init_hw(hw))
3538 e_err("Hardware Error\n");
3540 e1000_update_mng_vlan(adapter);
3542 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3543 ew32(VET, ETH_P_8021Q);
3545 e1000e_reset_adaptive(hw);
3547 if (!netif_running(adapter->netdev) &&
3548 !test_bit(__E1000_TESTING, &adapter->state)) {
3549 e1000_power_down_phy(adapter);
3553 e1000_get_phy_info(hw);
3555 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3556 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
3559 * speed up time to link by disabling smart power down, ignore
3560 * the return value of this function because there is nothing
3561 * different we would do if it failed
3563 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3564 phy_data &= ~IGP02E1000_PM_SPD;
3565 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3569 int e1000e_up(struct e1000_adapter *adapter)
3571 struct e1000_hw *hw = &adapter->hw;
3573 /* hardware has been reset, we need to reload some things */
3574 e1000_configure(adapter);
3576 clear_bit(__E1000_DOWN, &adapter->state);
3578 if (adapter->msix_entries)
3579 e1000_configure_msix(adapter);
3580 e1000_irq_enable(adapter);
3582 netif_start_queue(adapter->netdev);
3584 /* fire a link change interrupt to start the watchdog */
3585 if (adapter->msix_entries)
3586 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3588 ew32(ICS, E1000_ICS_LSC);
3593 static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3595 struct e1000_hw *hw = &adapter->hw;
3597 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3600 /* flush pending descriptor writebacks to memory */
3601 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3602 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3604 /* execute the writes immediately */
3608 * due to rare timing issues, write to TIDV/RDTR again to ensure the
3609 * write is successful
3611 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3612 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3614 /* execute the writes immediately */
3618 static void e1000e_update_stats(struct e1000_adapter *adapter);
3620 void e1000e_down(struct e1000_adapter *adapter)
3622 struct net_device *netdev = adapter->netdev;
3623 struct e1000_hw *hw = &adapter->hw;
3627 * signal that we're down so the interrupt handler does not
3628 * reschedule our watchdog timer
3630 set_bit(__E1000_DOWN, &adapter->state);
3632 /* disable receives in the hardware */
3634 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3635 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3636 /* flush and sleep below */
3638 netif_stop_queue(netdev);
3640 /* disable transmits in the hardware */
3642 tctl &= ~E1000_TCTL_EN;
3645 /* flush both disables and wait for them to finish */
3647 usleep_range(10000, 20000);
3649 e1000_irq_disable(adapter);
3651 del_timer_sync(&adapter->watchdog_timer);
3652 del_timer_sync(&adapter->phy_info_timer);
3654 netif_carrier_off(netdev);
3656 spin_lock(&adapter->stats64_lock);
3657 e1000e_update_stats(adapter);
3658 spin_unlock(&adapter->stats64_lock);
3660 e1000e_flush_descriptors(adapter);
3661 e1000_clean_tx_ring(adapter->tx_ring);
3662 e1000_clean_rx_ring(adapter->rx_ring);
3664 adapter->link_speed = 0;
3665 adapter->link_duplex = 0;
3667 if (!pci_channel_offline(adapter->pdev))
3668 e1000e_reset(adapter);
3671 * TODO: for power management, we could drop the link and
3672 * pci_disable_device here.
3676 void e1000e_reinit_locked(struct e1000_adapter *adapter)
3679 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3680 usleep_range(1000, 2000);
3681 e1000e_down(adapter);
3683 clear_bit(__E1000_RESETTING, &adapter->state);
3687 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3688 * @adapter: board private structure to initialize
3690 * e1000_sw_init initializes the Adapter private data structure.
3691 * Fields are initialized based on PCI device information and
3692 * OS network device settings (MTU size).
3694 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3696 struct net_device *netdev = adapter->netdev;
3698 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3699 adapter->rx_ps_bsize0 = 128;
3700 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3701 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
3702 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3703 adapter->rx_ring_count = E1000_DEFAULT_RXD;
3705 spin_lock_init(&adapter->stats64_lock);
3707 e1000e_set_interrupt_capability(adapter);
3709 if (e1000_alloc_queues(adapter))
3712 /* Explicitly disable IRQ since the NIC can be in any state. */
3713 e1000_irq_disable(adapter);
3715 set_bit(__E1000_DOWN, &adapter->state);
3720 * e1000_intr_msi_test - Interrupt Handler
3721 * @irq: interrupt number
3722 * @data: pointer to a network interface device structure
3724 static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3726 struct net_device *netdev = data;
3727 struct e1000_adapter *adapter = netdev_priv(netdev);
3728 struct e1000_hw *hw = &adapter->hw;
3729 u32 icr = er32(ICR);
3731 e_dbg("icr is %08X\n", icr);
3732 if (icr & E1000_ICR_RXSEQ) {
3733 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3741 * e1000_test_msi_interrupt - Returns 0 for successful test
3742 * @adapter: board private struct
3744 * code flow taken from tg3.c
3746 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3748 struct net_device *netdev = adapter->netdev;
3749 struct e1000_hw *hw = &adapter->hw;
3752 /* poll_enable hasn't been called yet, so don't need disable */
3753 /* clear any pending events */
3756 /* free the real vector and request a test handler */
3757 e1000_free_irq(adapter);
3758 e1000e_reset_interrupt_capability(adapter);
3760 /* Assume that the test fails, if it succeeds then the test
3761 * MSI irq handler will unset this flag */
3762 adapter->flags |= FLAG_MSI_TEST_FAILED;
3764 err = pci_enable_msi(adapter->pdev);
3766 goto msi_test_failed;
3768 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
3769 netdev->name, netdev);
3771 pci_disable_msi(adapter->pdev);
3772 goto msi_test_failed;
3777 e1000_irq_enable(adapter);
3779 /* fire an unusual interrupt on the test handler */
3780 ew32(ICS, E1000_ICS_RXSEQ);
3784 e1000_irq_disable(adapter);
3788 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
3789 adapter->int_mode = E1000E_INT_MODE_LEGACY;
3790 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3792 e_dbg("MSI interrupt test succeeded!\n");
3795 free_irq(adapter->pdev->irq, netdev);
3796 pci_disable_msi(adapter->pdev);
3799 e1000e_set_interrupt_capability(adapter);
3800 return e1000_request_irq(adapter);
3804 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3805 * @adapter: board private struct
3807 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3809 static int e1000_test_msi(struct e1000_adapter *adapter)
3814 if (!(adapter->flags & FLAG_MSI_ENABLED))
3817 /* disable SERR in case the MSI write causes a master abort */
3818 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3819 if (pci_cmd & PCI_COMMAND_SERR)
3820 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3821 pci_cmd & ~PCI_COMMAND_SERR);
3823 err = e1000_test_msi_interrupt(adapter);
3825 /* re-enable SERR */
3826 if (pci_cmd & PCI_COMMAND_SERR) {
3827 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3828 pci_cmd |= PCI_COMMAND_SERR;
3829 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3836 * e1000_open - Called when a network interface is made active
3837 * @netdev: network interface device structure
3839 * Returns 0 on success, negative value on failure
3841 * The open entry point is called when a network interface is made
3842 * active by the system (IFF_UP). At this point all resources needed
3843 * for transmit and receive operations are allocated, the interrupt
3844 * handler is registered with the OS, the watchdog timer is started,
3845 * and the stack is notified that the interface is ready.
3847 static int e1000_open(struct net_device *netdev)
3849 struct e1000_adapter *adapter = netdev_priv(netdev);
3850 struct e1000_hw *hw = &adapter->hw;
3851 struct pci_dev *pdev = adapter->pdev;
3854 /* disallow open during test */
3855 if (test_bit(__E1000_TESTING, &adapter->state))
3858 pm_runtime_get_sync(&pdev->dev);
3860 netif_carrier_off(netdev);
3862 /* allocate transmit descriptors */
3863 err = e1000e_setup_tx_resources(adapter->tx_ring);
3867 /* allocate receive descriptors */
3868 err = e1000e_setup_rx_resources(adapter->rx_ring);
3873 * If AMT is enabled, let the firmware know that the network
3874 * interface is now open and reset the part to a known state.
3876 if (adapter->flags & FLAG_HAS_AMT) {
3877 e1000e_get_hw_control(adapter);
3878 e1000e_reset(adapter);
3881 e1000e_power_up_phy(adapter);
3883 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3884 if ((adapter->hw.mng_cookie.status &
3885 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3886 e1000_update_mng_vlan(adapter);
3888 /* DMA latency requirement to workaround jumbo issue */
3889 if (adapter->hw.mac.type == e1000_pch2lan)
3890 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3891 PM_QOS_CPU_DMA_LATENCY,
3892 PM_QOS_DEFAULT_VALUE);
3895 * before we allocate an interrupt, we must be ready to handle it.
3896 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3897 * as soon as we call pci_request_irq, so we have to setup our
3898 * clean_rx handler before we do so.
3900 e1000_configure(adapter);
3902 err = e1000_request_irq(adapter);
3907 * Work around PCIe errata with MSI interrupts causing some chipsets to
3908 * ignore e1000e MSI messages, which means we need to test our MSI
3911 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
3912 err = e1000_test_msi(adapter);
3914 e_err("Interrupt allocation failed\n");
3919 /* From here on the code is the same as e1000e_up() */
3920 clear_bit(__E1000_DOWN, &adapter->state);
3922 napi_enable(&adapter->napi);
3924 e1000_irq_enable(adapter);
3926 adapter->tx_hang_recheck = false;
3927 netif_start_queue(netdev);
3929 adapter->idle_check = true;
3930 pm_runtime_put(&pdev->dev);
3932 /* fire a link status change interrupt to start the watchdog */
3933 if (adapter->msix_entries)
3934 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3936 ew32(ICS, E1000_ICS_LSC);
3941 e1000e_release_hw_control(adapter);
3942 e1000_power_down_phy(adapter);
3943 e1000e_free_rx_resources(adapter->rx_ring);
3945 e1000e_free_tx_resources(adapter->tx_ring);
3947 e1000e_reset(adapter);
3948 pm_runtime_put_sync(&pdev->dev);
3954 * e1000_close - Disables a network interface
3955 * @netdev: network interface device structure
3957 * Returns 0, this is not allowed to fail
3959 * The close entry point is called when an interface is de-activated
3960 * by the OS. The hardware is still under the drivers control, but
3961 * needs to be disabled. A global MAC reset is issued to stop the
3962 * hardware, and all transmit and receive resources are freed.
3964 static int e1000_close(struct net_device *netdev)
3966 struct e1000_adapter *adapter = netdev_priv(netdev);
3967 struct pci_dev *pdev = adapter->pdev;
3968 int count = E1000_CHECK_RESET_COUNT;
3970 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
3971 usleep_range(10000, 20000);
3973 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3975 pm_runtime_get_sync(&pdev->dev);
3977 napi_disable(&adapter->napi);
3979 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3980 e1000e_down(adapter);
3981 e1000_free_irq(adapter);
3983 e1000_power_down_phy(adapter);
3985 e1000e_free_tx_resources(adapter->tx_ring);
3986 e1000e_free_rx_resources(adapter->rx_ring);
3989 * kill manageability vlan ID if supported, but not if a vlan with
3990 * the same ID is registered on the host OS (let 8021q kill it)
3992 if (adapter->hw.mng_cookie.status &
3993 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
3994 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3997 * If AMT is enabled, let the firmware know that the network
3998 * interface is now closed
4000 if ((adapter->flags & FLAG_HAS_AMT) &&
4001 !test_bit(__E1000_TESTING, &adapter->state))
4002 e1000e_release_hw_control(adapter);
4004 if (adapter->hw.mac.type == e1000_pch2lan)
4005 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
4007 pm_runtime_put_sync(&pdev->dev);
4012 * e1000_set_mac - Change the Ethernet Address of the NIC
4013 * @netdev: network interface device structure
4014 * @p: pointer to an address structure
4016 * Returns 0 on success, negative on failure
4018 static int e1000_set_mac(struct net_device *netdev, void *p)
4020 struct e1000_adapter *adapter = netdev_priv(netdev);
4021 struct sockaddr *addr = p;
4023 if (!is_valid_ether_addr(addr->sa_data))
4024 return -EADDRNOTAVAIL;
4026 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4027 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4029 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
4031 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4032 /* activate the work around */
4033 e1000e_set_laa_state_82571(&adapter->hw, 1);
4036 * Hold a copy of the LAA in RAR[14] This is done so that
4037 * between the time RAR[0] gets clobbered and the time it
4038 * gets fixed (in e1000_watchdog), the actual LAA is in one
4039 * of the RARs and no incoming packets directed to this port
4040 * are dropped. Eventually the LAA will be in RAR[0] and
4043 e1000e_rar_set(&adapter->hw,
4044 adapter->hw.mac.addr,
4045 adapter->hw.mac.rar_entry_count - 1);
4052 * e1000e_update_phy_task - work thread to update phy
4053 * @work: pointer to our work struct
4055 * this worker thread exists because we must acquire a
4056 * semaphore to read the phy, which we could msleep while
4057 * waiting for it, and we can't msleep in a timer.
4059 static void e1000e_update_phy_task(struct work_struct *work)
4061 struct e1000_adapter *adapter = container_of(work,
4062 struct e1000_adapter, update_phy_task);
4064 if (test_bit(__E1000_DOWN, &adapter->state))
4067 e1000_get_phy_info(&adapter->hw);
4071 * Need to wait a few seconds after link up to get diagnostic information from
4074 static void e1000_update_phy_info(unsigned long data)
4076 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4078 if (test_bit(__E1000_DOWN, &adapter->state))
4081 schedule_work(&adapter->update_phy_task);
4085 * e1000e_update_phy_stats - Update the PHY statistics counters
4086 * @adapter: board private structure
4088 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
4090 static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4092 struct e1000_hw *hw = &adapter->hw;
4096 ret_val = hw->phy.ops.acquire(hw);
4101 * A page set is expensive so check if already on desired page.
4102 * If not, set to the page with the PHY status registers.
4105 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4109 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4110 ret_val = hw->phy.ops.set_page(hw,
4111 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4116 /* Single Collision Count */
4117 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4118 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4120 adapter->stats.scc += phy_data;
4122 /* Excessive Collision Count */
4123 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4124 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4126 adapter->stats.ecol += phy_data;
4128 /* Multiple Collision Count */
4129 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4130 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4132 adapter->stats.mcc += phy_data;
4134 /* Late Collision Count */
4135 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4136 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4138 adapter->stats.latecol += phy_data;
4140 /* Collision Count - also used for adaptive IFS */
4141 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4142 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4144 hw->mac.collision_delta = phy_data;
4147 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4148 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4150 adapter->stats.dc += phy_data;
4152 /* Transmit with no CRS */
4153 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4154 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4156 adapter->stats.tncrs += phy_data;
4159 hw->phy.ops.release(hw);
4163 * e1000e_update_stats - Update the board statistics counters
4164 * @adapter: board private structure
4166 static void e1000e_update_stats(struct e1000_adapter *adapter)
4168 struct net_device *netdev = adapter->netdev;
4169 struct e1000_hw *hw = &adapter->hw;
4170 struct pci_dev *pdev = adapter->pdev;
4173 * Prevent stats update while adapter is being reset, or if the pci
4174 * connection is down.
4176 if (adapter->link_speed == 0)
4178 if (pci_channel_offline(pdev))
4181 adapter->stats.crcerrs += er32(CRCERRS);
4182 adapter->stats.gprc += er32(GPRC);
4183 adapter->stats.gorc += er32(GORCL);
4184 er32(GORCH); /* Clear gorc */
4185 adapter->stats.bprc += er32(BPRC);
4186 adapter->stats.mprc += er32(MPRC);
4187 adapter->stats.roc += er32(ROC);
4189 adapter->stats.mpc += er32(MPC);
4191 /* Half-duplex statistics */
4192 if (adapter->link_duplex == HALF_DUPLEX) {
4193 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4194 e1000e_update_phy_stats(adapter);
4196 adapter->stats.scc += er32(SCC);
4197 adapter->stats.ecol += er32(ECOL);
4198 adapter->stats.mcc += er32(MCC);
4199 adapter->stats.latecol += er32(LATECOL);
4200 adapter->stats.dc += er32(DC);
4202 hw->mac.collision_delta = er32(COLC);
4204 if ((hw->mac.type != e1000_82574) &&
4205 (hw->mac.type != e1000_82583))
4206 adapter->stats.tncrs += er32(TNCRS);
4208 adapter->stats.colc += hw->mac.collision_delta;
4211 adapter->stats.xonrxc += er32(XONRXC);
4212 adapter->stats.xontxc += er32(XONTXC);
4213 adapter->stats.xoffrxc += er32(XOFFRXC);
4214 adapter->stats.xofftxc += er32(XOFFTXC);
4215 adapter->stats.gptc += er32(GPTC);
4216 adapter->stats.gotc += er32(GOTCL);
4217 er32(GOTCH); /* Clear gotc */
4218 adapter->stats.rnbc += er32(RNBC);
4219 adapter->stats.ruc += er32(RUC);
4221 adapter->stats.mptc += er32(MPTC);
4222 adapter->stats.bptc += er32(BPTC);
4224 /* used for adaptive IFS */
4226 hw->mac.tx_packet_delta = er32(TPT);
4227 adapter->stats.tpt += hw->mac.tx_packet_delta;
4229 adapter->stats.algnerrc += er32(ALGNERRC);
4230 adapter->stats.rxerrc += er32(RXERRC);
4231 adapter->stats.cexterr += er32(CEXTERR);
4232 adapter->stats.tsctc += er32(TSCTC);
4233 adapter->stats.tsctfc += er32(TSCTFC);
4235 /* Fill out the OS statistics structure */
4236 netdev->stats.multicast = adapter->stats.mprc;
4237 netdev->stats.collisions = adapter->stats.colc;
4242 * RLEC on some newer hardware can be incorrect so build
4243 * our own version based on RUC and ROC
4245 netdev->stats.rx_errors = adapter->stats.rxerrc +
4246 adapter->stats.crcerrs + adapter->stats.algnerrc +
4247 adapter->stats.ruc + adapter->stats.roc +
4248 adapter->stats.cexterr;
4249 netdev->stats.rx_length_errors = adapter->stats.ruc +
4251 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4252 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4253 netdev->stats.rx_missed_errors = adapter->stats.mpc;
4256 netdev->stats.tx_errors = adapter->stats.ecol +
4257 adapter->stats.latecol;
4258 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4259 netdev->stats.tx_window_errors = adapter->stats.latecol;
4260 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
4262 /* Tx Dropped needs to be maintained elsewhere */
4264 /* Management Stats */
4265 adapter->stats.mgptc += er32(MGTPTC);
4266 adapter->stats.mgprc += er32(MGTPRC);
4267 adapter->stats.mgpdc += er32(MGTPDC);
4271 * e1000_phy_read_status - Update the PHY register status snapshot
4272 * @adapter: board private structure
4274 static void e1000_phy_read_status(struct e1000_adapter *adapter)
4276 struct e1000_hw *hw = &adapter->hw;
4277 struct e1000_phy_regs *phy = &adapter->phy_regs;
4279 if ((er32(STATUS) & E1000_STATUS_LU) &&
4280 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
4283 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4284 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4285 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4286 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4287 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4288 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4289 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4290 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4292 e_warn("Error reading PHY register\n");
4295 * Do not read PHY registers if link is not up
4296 * Set values to typical power-on defaults
4298 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4299 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4300 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4302 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4303 ADVERTISE_ALL | ADVERTISE_CSMA);
4305 phy->expansion = EXPANSION_ENABLENPAGE;
4306 phy->ctrl1000 = ADVERTISE_1000FULL;
4308 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4312 static void e1000_print_link_info(struct e1000_adapter *adapter)
4314 struct e1000_hw *hw = &adapter->hw;
4315 u32 ctrl = er32(CTRL);
4317 /* Link status message must follow this format for user tools */
4318 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4319 adapter->netdev->name,
4320 adapter->link_speed,
4321 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4322 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4323 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4324 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
4327 static bool e1000e_has_link(struct e1000_adapter *adapter)
4329 struct e1000_hw *hw = &adapter->hw;
4330 bool link_active = false;
4334 * get_link_status is set on LSC (link status) interrupt or
4335 * Rx sequence error interrupt. get_link_status will stay
4336 * false until the check_for_link establishes link
4337 * for copper adapters ONLY
4339 switch (hw->phy.media_type) {
4340 case e1000_media_type_copper:
4341 if (hw->mac.get_link_status) {
4342 ret_val = hw->mac.ops.check_for_link(hw);
4343 link_active = !hw->mac.get_link_status;
4348 case e1000_media_type_fiber:
4349 ret_val = hw->mac.ops.check_for_link(hw);
4350 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4352 case e1000_media_type_internal_serdes:
4353 ret_val = hw->mac.ops.check_for_link(hw);
4354 link_active = adapter->hw.mac.serdes_has_link;
4357 case e1000_media_type_unknown:
4361 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4362 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4363 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
4364 e_info("Gigabit has been disabled, downgrading speed\n");
4370 static void e1000e_enable_receives(struct e1000_adapter *adapter)
4372 /* make sure the receive unit is started */
4373 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4374 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4375 struct e1000_hw *hw = &adapter->hw;
4376 u32 rctl = er32(RCTL);
4377 ew32(RCTL, rctl | E1000_RCTL_EN);
4378 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4382 static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4384 struct e1000_hw *hw = &adapter->hw;
4387 * With 82574 controllers, PHY needs to be checked periodically
4388 * for hung state and reset, if two calls return true
4390 if (e1000_check_phy_82574(hw))
4391 adapter->phy_hang_count++;
4393 adapter->phy_hang_count = 0;
4395 if (adapter->phy_hang_count > 1) {
4396 adapter->phy_hang_count = 0;
4397 schedule_work(&adapter->reset_task);
4402 * e1000_watchdog - Timer Call-back
4403 * @data: pointer to adapter cast into an unsigned long
4405 static void e1000_watchdog(unsigned long data)
4407 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4409 /* Do the rest outside of interrupt context */
4410 schedule_work(&adapter->watchdog_task);
4412 /* TODO: make this use queue_delayed_work() */
4415 static void e1000_watchdog_task(struct work_struct *work)
4417 struct e1000_adapter *adapter = container_of(work,
4418 struct e1000_adapter, watchdog_task);
4419 struct net_device *netdev = adapter->netdev;
4420 struct e1000_mac_info *mac = &adapter->hw.mac;
4421 struct e1000_phy_info *phy = &adapter->hw.phy;
4422 struct e1000_ring *tx_ring = adapter->tx_ring;
4423 struct e1000_hw *hw = &adapter->hw;
4426 if (test_bit(__E1000_DOWN, &adapter->state))
4429 link = e1000e_has_link(adapter);
4430 if ((netif_carrier_ok(netdev)) && link) {
4431 /* Cancel scheduled suspend requests. */
4432 pm_runtime_resume(netdev->dev.parent);
4434 e1000e_enable_receives(adapter);
4438 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4439 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4440 e1000_update_mng_vlan(adapter);
4443 if (!netif_carrier_ok(netdev)) {
4446 /* Cancel scheduled suspend requests. */
4447 pm_runtime_resume(netdev->dev.parent);
4449 /* update snapshot of PHY registers on LSC */
4450 e1000_phy_read_status(adapter);
4451 mac->ops.get_link_up_info(&adapter->hw,
4452 &adapter->link_speed,
4453 &adapter->link_duplex);
4454 e1000_print_link_info(adapter);
4456 * On supported PHYs, check for duplex mismatch only
4457 * if link has autonegotiated at 10/100 half
4459 if ((hw->phy.type == e1000_phy_igp_3 ||
4460 hw->phy.type == e1000_phy_bm) &&
4461 (hw->mac.autoneg == true) &&
4462 (adapter->link_speed == SPEED_10 ||
4463 adapter->link_speed == SPEED_100) &&
4464 (adapter->link_duplex == HALF_DUPLEX)) {
4467 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4469 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4470 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
4473 /* adjust timeout factor according to speed/duplex */
4474 adapter->tx_timeout_factor = 1;
4475 switch (adapter->link_speed) {
4478 adapter->tx_timeout_factor = 16;
4482 adapter->tx_timeout_factor = 10;
4487 * workaround: re-program speed mode bit after
4490 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4493 tarc0 = er32(TARC(0));
4494 tarc0 &= ~SPEED_MODE_BIT;
4495 ew32(TARC(0), tarc0);
4499 * disable TSO for pcie and 10/100 speeds, to avoid
4500 * some hardware issues
4502 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4503 switch (adapter->link_speed) {
4506 e_info("10/100 speed: disabling TSO\n");
4507 netdev->features &= ~NETIF_F_TSO;
4508 netdev->features &= ~NETIF_F_TSO6;
4511 netdev->features |= NETIF_F_TSO;
4512 netdev->features |= NETIF_F_TSO6;
4521 * enable transmits in the hardware, need to do this
4522 * after setting TARC(0)
4525 tctl |= E1000_TCTL_EN;
4529 * Perform any post-link-up configuration before
4530 * reporting link up.
4532 if (phy->ops.cfg_on_link_up)
4533 phy->ops.cfg_on_link_up(hw);
4535 netif_carrier_on(netdev);
4537 if (!test_bit(__E1000_DOWN, &adapter->state))
4538 mod_timer(&adapter->phy_info_timer,
4539 round_jiffies(jiffies + 2 * HZ));
4542 if (netif_carrier_ok(netdev)) {
4543 adapter->link_speed = 0;
4544 adapter->link_duplex = 0;
4545 /* Link status message must follow this format */
4546 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4547 adapter->netdev->name);
4548 netif_carrier_off(netdev);
4549 if (!test_bit(__E1000_DOWN, &adapter->state))
4550 mod_timer(&adapter->phy_info_timer,
4551 round_jiffies(jiffies + 2 * HZ));
4553 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4554 schedule_work(&adapter->reset_task);
4556 pm_schedule_suspend(netdev->dev.parent,
4562 spin_lock(&adapter->stats64_lock);
4563 e1000e_update_stats(adapter);
4565 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4566 adapter->tpt_old = adapter->stats.tpt;
4567 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4568 adapter->colc_old = adapter->stats.colc;
4570 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4571 adapter->gorc_old = adapter->stats.gorc;
4572 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4573 adapter->gotc_old = adapter->stats.gotc;
4574 spin_unlock(&adapter->stats64_lock);
4576 e1000e_update_adaptive(&adapter->hw);
4578 if (!netif_carrier_ok(netdev) &&
4579 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4581 * We've lost link, so the controller stops DMA,
4582 * but we've got queued Tx work that's never going
4583 * to get done, so reset controller to flush Tx.
4584 * (Do the reset outside of interrupt context).
4586 schedule_work(&adapter->reset_task);
4587 /* return immediately since reset is imminent */
4591 /* Simple mode for Interrupt Throttle Rate (ITR) */
4592 if (adapter->itr_setting == 4) {
4594 * Symmetric Tx/Rx gets a reduced ITR=2000;
4595 * Total asymmetrical Tx or Rx gets ITR=8000;
4596 * everyone else is between 2000-8000.
4598 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4599 u32 dif = (adapter->gotc > adapter->gorc ?
4600 adapter->gotc - adapter->gorc :
4601 adapter->gorc - adapter->gotc) / 10000;
4602 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4604 ew32(ITR, 1000000000 / (itr * 256));
4607 /* Cause software interrupt to ensure Rx ring is cleaned */
4608 if (adapter->msix_entries)
4609 ew32(ICS, adapter->rx_ring->ims_val);
4611 ew32(ICS, E1000_ICS_RXDMT0);
4613 /* flush pending descriptors to memory before detecting Tx hang */
4614 e1000e_flush_descriptors(adapter);
4616 /* Force detection of hung controller every watchdog period */
4617 adapter->detect_tx_hung = true;
4620 * With 82571 controllers, LAA may be overwritten due to controller
4621 * reset from the other port. Set the appropriate LAA in RAR[0]
4623 if (e1000e_get_laa_state_82571(hw))
4624 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4626 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4627 e1000e_check_82574_phy_workaround(adapter);
4629 /* Reset the timer */
4630 if (!test_bit(__E1000_DOWN, &adapter->state))
4631 mod_timer(&adapter->watchdog_timer,
4632 round_jiffies(jiffies + 2 * HZ));
4635 #define E1000_TX_FLAGS_CSUM 0x00000001
4636 #define E1000_TX_FLAGS_VLAN 0x00000002
4637 #define E1000_TX_FLAGS_TSO 0x00000004
4638 #define E1000_TX_FLAGS_IPV4 0x00000008
4639 #define E1000_TX_FLAGS_NO_FCS 0x00000010
4640 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4641 #define E1000_TX_FLAGS_VLAN_SHIFT 16
4643 static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
4645 struct e1000_context_desc *context_desc;
4646 struct e1000_buffer *buffer_info;
4649 u16 ipcse = 0, tucse, mss;
4650 u8 ipcss, ipcso, tucss, tucso, hdr_len;
4652 if (!skb_is_gso(skb))
4655 if (skb_header_cloned(skb)) {
4656 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4662 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4663 mss = skb_shinfo(skb)->gso_size;
4664 if (skb->protocol == htons(ETH_P_IP)) {
4665 struct iphdr *iph = ip_hdr(skb);
4668 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4670 cmd_length = E1000_TXD_CMD_IP;
4671 ipcse = skb_transport_offset(skb) - 1;
4672 } else if (skb_is_gso_v6(skb)) {
4673 ipv6_hdr(skb)->payload_len = 0;
4674 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4675 &ipv6_hdr(skb)->daddr,
4679 ipcss = skb_network_offset(skb);
4680 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4681 tucss = skb_transport_offset(skb);
4682 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4685 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4686 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4688 i = tx_ring->next_to_use;
4689 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4690 buffer_info = &tx_ring->buffer_info[i];
4692 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4693 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4694 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4695 context_desc->upper_setup.tcp_fields.tucss = tucss;
4696 context_desc->upper_setup.tcp_fields.tucso = tucso;
4697 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4698 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4699 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4700 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4702 buffer_info->time_stamp = jiffies;
4703 buffer_info->next_to_watch = i;
4706 if (i == tx_ring->count)
4708 tx_ring->next_to_use = i;
4713 static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
4715 struct e1000_adapter *adapter = tx_ring->adapter;
4716 struct e1000_context_desc *context_desc;
4717 struct e1000_buffer *buffer_info;
4720 u32 cmd_len = E1000_TXD_CMD_DEXT;
4723 if (skb->ip_summed != CHECKSUM_PARTIAL)
4726 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4727 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4729 protocol = skb->protocol;
4732 case cpu_to_be16(ETH_P_IP):
4733 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4734 cmd_len |= E1000_TXD_CMD_TCP;
4736 case cpu_to_be16(ETH_P_IPV6):
4737 /* XXX not handling all IPV6 headers */
4738 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4739 cmd_len |= E1000_TXD_CMD_TCP;
4742 if (unlikely(net_ratelimit()))
4743 e_warn("checksum_partial proto=%x!\n",
4744 be16_to_cpu(protocol));
4748 css = skb_checksum_start_offset(skb);
4750 i = tx_ring->next_to_use;
4751 buffer_info = &tx_ring->buffer_info[i];
4752 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4754 context_desc->lower_setup.ip_config = 0;
4755 context_desc->upper_setup.tcp_fields.tucss = css;
4756 context_desc->upper_setup.tcp_fields.tucso =
4757 css + skb->csum_offset;
4758 context_desc->upper_setup.tcp_fields.tucse = 0;
4759 context_desc->tcp_seg_setup.data = 0;
4760 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4762 buffer_info->time_stamp = jiffies;
4763 buffer_info->next_to_watch = i;
4766 if (i == tx_ring->count)
4768 tx_ring->next_to_use = i;
4773 #define E1000_MAX_PER_TXD 8192
4774 #define E1000_MAX_TXD_PWR 12
4776 static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
4777 unsigned int first, unsigned int max_per_txd,
4778 unsigned int nr_frags, unsigned int mss)
4780 struct e1000_adapter *adapter = tx_ring->adapter;
4781 struct pci_dev *pdev = adapter->pdev;
4782 struct e1000_buffer *buffer_info;
4783 unsigned int len = skb_headlen(skb);
4784 unsigned int offset = 0, size, count = 0, i;
4785 unsigned int f, bytecount, segs;
4787 i = tx_ring->next_to_use;
4790 buffer_info = &tx_ring->buffer_info[i];
4791 size = min(len, max_per_txd);
4793 buffer_info->length = size;
4794 buffer_info->time_stamp = jiffies;
4795 buffer_info->next_to_watch = i;
4796 buffer_info->dma = dma_map_single(&pdev->dev,
4798 size, DMA_TO_DEVICE);
4799 buffer_info->mapped_as_page = false;
4800 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4809 if (i == tx_ring->count)
4814 for (f = 0; f < nr_frags; f++) {
4815 const struct skb_frag_struct *frag;
4817 frag = &skb_shinfo(skb)->frags[f];
4818 len = skb_frag_size(frag);
4823 if (i == tx_ring->count)
4826 buffer_info = &tx_ring->buffer_info[i];
4827 size = min(len, max_per_txd);
4829 buffer_info->length = size;
4830 buffer_info->time_stamp = jiffies;
4831 buffer_info->next_to_watch = i;
4832 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4833 offset, size, DMA_TO_DEVICE);
4834 buffer_info->mapped_as_page = true;
4835 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4844 segs = skb_shinfo(skb)->gso_segs ? : 1;
4845 /* multiply data chunks by size of headers */
4846 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4848 tx_ring->buffer_info[i].skb = skb;
4849 tx_ring->buffer_info[i].segs = segs;
4850 tx_ring->buffer_info[i].bytecount = bytecount;
4851 tx_ring->buffer_info[first].next_to_watch = i;
4856 dev_err(&pdev->dev, "Tx DMA map failed\n");
4857 buffer_info->dma = 0;
4863 i += tx_ring->count;
4865 buffer_info = &tx_ring->buffer_info[i];
4866 e1000_put_txbuf(tx_ring, buffer_info);
4872 static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
4874 struct e1000_adapter *adapter = tx_ring->adapter;
4875 struct e1000_tx_desc *tx_desc = NULL;
4876 struct e1000_buffer *buffer_info;
4877 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4880 if (tx_flags & E1000_TX_FLAGS_TSO) {
4881 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4883 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4885 if (tx_flags & E1000_TX_FLAGS_IPV4)
4886 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4889 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4890 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4891 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4894 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4895 txd_lower |= E1000_TXD_CMD_VLE;
4896 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4899 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4900 txd_lower &= ~(E1000_TXD_CMD_IFCS);
4902 i = tx_ring->next_to_use;
4905 buffer_info = &tx_ring->buffer_info[i];
4906 tx_desc = E1000_TX_DESC(*tx_ring, i);
4907 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4908 tx_desc->lower.data =
4909 cpu_to_le32(txd_lower | buffer_info->length);
4910 tx_desc->upper.data = cpu_to_le32(txd_upper);
4913 if (i == tx_ring->count)
4915 } while (--count > 0);
4917 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4919 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
4920 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4921 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
4924 * Force memory writes to complete before letting h/w
4925 * know there are new descriptors to fetch. (Only
4926 * applicable for weak-ordered memory model archs,
4931 tx_ring->next_to_use = i;
4933 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4934 e1000e_update_tdt_wa(tx_ring, i);
4936 writel(i, tx_ring->tail);
4939 * we need this if more than one processor can write to our tail
4940 * at a time, it synchronizes IO on IA64/Altix systems
4945 #define MINIMUM_DHCP_PACKET_SIZE 282
4946 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4947 struct sk_buff *skb)
4949 struct e1000_hw *hw = &adapter->hw;
4952 if (vlan_tx_tag_present(skb)) {
4953 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4954 (adapter->hw.mng_cookie.status &
4955 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4959 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4962 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4966 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4969 if (ip->protocol != IPPROTO_UDP)
4972 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4973 if (ntohs(udp->dest) != 67)
4976 offset = (u8 *)udp + 8 - skb->data;
4977 length = skb->len - offset;
4978 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4984 static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
4986 struct e1000_adapter *adapter = tx_ring->adapter;
4988 netif_stop_queue(adapter->netdev);
4990 * Herbert's original patch had:
4991 * smp_mb__after_netif_stop_queue();
4992 * but since that doesn't exist yet, just open code it.
4997 * We need to check again in a case another CPU has just
4998 * made room available.
5000 if (e1000_desc_unused(tx_ring) < size)
5004 netif_start_queue(adapter->netdev);
5005 ++adapter->restart_queue;
5009 static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
5011 if (e1000_desc_unused(tx_ring) >= size)
5013 return __e1000_maybe_stop_tx(tx_ring, size);
5016 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1)
5017 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5018 struct net_device *netdev)
5020 struct e1000_adapter *adapter = netdev_priv(netdev);
5021 struct e1000_ring *tx_ring = adapter->tx_ring;
5023 unsigned int max_per_txd = E1000_MAX_PER_TXD;
5024 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
5025 unsigned int tx_flags = 0;
5026 unsigned int len = skb_headlen(skb);
5027 unsigned int nr_frags;
5033 if (test_bit(__E1000_DOWN, &adapter->state)) {
5034 dev_kfree_skb_any(skb);
5035 return NETDEV_TX_OK;
5038 if (skb->len <= 0) {
5039 dev_kfree_skb_any(skb);
5040 return NETDEV_TX_OK;
5043 mss = skb_shinfo(skb)->gso_size;
5045 * The controller does a simple calculation to
5046 * make sure there is enough room in the FIFO before
5047 * initiating the DMA for each buffer. The calc is:
5048 * 4 = ceil(buffer len/mss). To make sure we don't
5049 * overrun the FIFO, adjust the max buffer len if mss
5054 max_per_txd = min(mss << 2, max_per_txd);
5055 max_txd_pwr = fls(max_per_txd) - 1;
5058 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
5059 * points to just header, pull a few bytes of payload from
5060 * frags into skb->data
5062 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5064 * we do this workaround for ES2LAN, but it is un-necessary,
5065 * avoiding it could save a lot of cycles
5067 if (skb->data_len && (hdr_len == len)) {
5068 unsigned int pull_size;
5070 pull_size = min_t(unsigned int, 4, skb->data_len);
5071 if (!__pskb_pull_tail(skb, pull_size)) {
5072 e_err("__pskb_pull_tail failed.\n");
5073 dev_kfree_skb_any(skb);
5074 return NETDEV_TX_OK;
5076 len = skb_headlen(skb);
5080 /* reserve a descriptor for the offload context */
5081 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5085 count += TXD_USE_COUNT(len, max_txd_pwr);
5087 nr_frags = skb_shinfo(skb)->nr_frags;
5088 for (f = 0; f < nr_frags; f++)
5089 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5092 if (adapter->hw.mac.tx_pkt_filtering)
5093 e1000_transfer_dhcp_info(adapter, skb);
5096 * need: count + 2 desc gap to keep tail from touching
5097 * head, otherwise try next time
5099 if (e1000_maybe_stop_tx(tx_ring, count + 2))
5100 return NETDEV_TX_BUSY;
5102 if (vlan_tx_tag_present(skb)) {
5103 tx_flags |= E1000_TX_FLAGS_VLAN;
5104 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5107 first = tx_ring->next_to_use;
5109 tso = e1000_tso(tx_ring, skb);
5111 dev_kfree_skb_any(skb);
5112 return NETDEV_TX_OK;
5116 tx_flags |= E1000_TX_FLAGS_TSO;
5117 else if (e1000_tx_csum(tx_ring, skb))
5118 tx_flags |= E1000_TX_FLAGS_CSUM;
5121 * Old method was to assume IPv4 packet by default if TSO was enabled.
5122 * 82571 hardware supports TSO capabilities for IPv6 as well...
5123 * no longer assume, we must.
5125 if (skb->protocol == htons(ETH_P_IP))
5126 tx_flags |= E1000_TX_FLAGS_IPV4;
5128 if (unlikely(skb->no_fcs))
5129 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5131 /* if count is 0 then mapping error has occurred */
5132 count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss);
5134 skb_tx_timestamp(skb);
5136 netdev_sent_queue(netdev, skb->len);
5137 e1000_tx_queue(tx_ring, tx_flags, count);
5138 /* Make sure there is space in the ring for the next send. */
5139 e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2);
5142 dev_kfree_skb_any(skb);
5143 tx_ring->buffer_info[first].time_stamp = 0;
5144 tx_ring->next_to_use = first;
5147 return NETDEV_TX_OK;
5151 * e1000_tx_timeout - Respond to a Tx Hang
5152 * @netdev: network interface device structure
5154 static void e1000_tx_timeout(struct net_device *netdev)
5156 struct e1000_adapter *adapter = netdev_priv(netdev);
5158 /* Do the reset outside of interrupt context */
5159 adapter->tx_timeout_count++;
5160 schedule_work(&adapter->reset_task);
5163 static void e1000_reset_task(struct work_struct *work)
5165 struct e1000_adapter *adapter;
5166 adapter = container_of(work, struct e1000_adapter, reset_task);
5168 /* don't run the task if already down */
5169 if (test_bit(__E1000_DOWN, &adapter->state))
5172 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5173 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5174 e1000e_dump(adapter);
5175 e_err("Reset adapter\n");
5177 e1000e_reinit_locked(adapter);
5181 * e1000_get_stats64 - Get System Network Statistics
5182 * @netdev: network interface device structure
5183 * @stats: rtnl_link_stats64 pointer
5185 * Returns the address of the device statistics structure.
5187 struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5188 struct rtnl_link_stats64 *stats)
5190 struct e1000_adapter *adapter = netdev_priv(netdev);
5192 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5193 spin_lock(&adapter->stats64_lock);
5194 e1000e_update_stats(adapter);
5195 /* Fill out the OS statistics structure */
5196 stats->rx_bytes = adapter->stats.gorc;
5197 stats->rx_packets = adapter->stats.gprc;
5198 stats->tx_bytes = adapter->stats.gotc;
5199 stats->tx_packets = adapter->stats.gptc;
5200 stats->multicast = adapter->stats.mprc;
5201 stats->collisions = adapter->stats.colc;
5206 * RLEC on some newer hardware can be incorrect so build
5207 * our own version based on RUC and ROC
5209 stats->rx_errors = adapter->stats.rxerrc +
5210 adapter->stats.crcerrs + adapter->stats.algnerrc +
5211 adapter->stats.ruc + adapter->stats.roc +
5212 adapter->stats.cexterr;
5213 stats->rx_length_errors = adapter->stats.ruc +
5215 stats->rx_crc_errors = adapter->stats.crcerrs;
5216 stats->rx_frame_errors = adapter->stats.algnerrc;
5217 stats->rx_missed_errors = adapter->stats.mpc;
5220 stats->tx_errors = adapter->stats.ecol +
5221 adapter->stats.latecol;
5222 stats->tx_aborted_errors = adapter->stats.ecol;
5223 stats->tx_window_errors = adapter->stats.latecol;
5224 stats->tx_carrier_errors = adapter->stats.tncrs;
5226 /* Tx Dropped needs to be maintained elsewhere */
5228 spin_unlock(&adapter->stats64_lock);
5233 * e1000_change_mtu - Change the Maximum Transfer Unit
5234 * @netdev: network interface device structure
5235 * @new_mtu: new value for maximum frame size
5237 * Returns 0 on success, negative on failure
5239 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5241 struct e1000_adapter *adapter = netdev_priv(netdev);
5242 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5244 /* Jumbo frame support */
5245 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
5246 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5247 e_err("Jumbo Frames not supported.\n");
5252 * IP payload checksum (enabled with jumbos/packet-split when
5253 * Rx checksum is enabled) and generation of RSS hash is
5254 * mutually exclusive in the hardware.
5256 if ((netdev->features & NETIF_F_RXCSUM) &&
5257 (netdev->features & NETIF_F_RXHASH)) {
5258 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");
5263 /* Supported frame sizes */
5264 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5265 (max_frame > adapter->max_hw_frame_size)) {
5266 e_err("Unsupported MTU setting\n");
5270 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5271 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5272 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5273 (new_mtu > ETH_DATA_LEN)) {
5274 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
5278 /* 82573 Errata 17 */
5279 if (((adapter->hw.mac.type == e1000_82573) ||
5280 (adapter->hw.mac.type == e1000_82574)) &&
5281 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5282 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5283 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5286 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
5287 usleep_range(1000, 2000);
5288 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
5289 adapter->max_frame_size = max_frame;
5290 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5291 netdev->mtu = new_mtu;
5292 if (netif_running(netdev))
5293 e1000e_down(adapter);
5296 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
5297 * means we reserve 2 more, this pushes us to allocate from the next
5299 * i.e. RXBUFFER_2048 --> size-4096 slab
5300 * However with the new *_jumbo_rx* routines, jumbo receives will use
5304 if (max_frame <= 2048)
5305 adapter->rx_buffer_len = 2048;
5307 adapter->rx_buffer_len = 4096;
5309 /* adjust allocation if LPE protects us, and we aren't using SBP */
5310 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5311 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5312 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
5315 if (netif_running(netdev))
5318 e1000e_reset(adapter);
5320 clear_bit(__E1000_RESETTING, &adapter->state);
5325 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5328 struct e1000_adapter *adapter = netdev_priv(netdev);
5329 struct mii_ioctl_data *data = if_mii(ifr);
5331 if (adapter->hw.phy.media_type != e1000_media_type_copper)
5336 data->phy_id = adapter->hw.phy.addr;
5339 e1000_phy_read_status(adapter);
5341 switch (data->reg_num & 0x1F) {
5343 data->val_out = adapter->phy_regs.bmcr;
5346 data->val_out = adapter->phy_regs.bmsr;
5349 data->val_out = (adapter->hw.phy.id >> 16);
5352 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5355 data->val_out = adapter->phy_regs.advertise;
5358 data->val_out = adapter->phy_regs.lpa;
5361 data->val_out = adapter->phy_regs.expansion;
5364 data->val_out = adapter->phy_regs.ctrl1000;
5367 data->val_out = adapter->phy_regs.stat1000;
5370 data->val_out = adapter->phy_regs.estatus;
5383 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5389 return e1000_mii_ioctl(netdev, ifr, cmd);
5395 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5397 struct e1000_hw *hw = &adapter->hw;
5399 u16 phy_reg, wuc_enable;
5402 /* copy MAC RARs to PHY RARs */
5403 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
5405 retval = hw->phy.ops.acquire(hw);
5407 e_err("Could not acquire PHY\n");
5411 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5412 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5416 /* copy MAC MTA to PHY MTA - only needed for pchlan */
5417 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5418 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5419 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5420 (u16)(mac_reg & 0xFFFF));
5421 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5422 (u16)((mac_reg >> 16) & 0xFFFF));
5425 /* configure PHY Rx Control register */
5426 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
5427 mac_reg = er32(RCTL);
5428 if (mac_reg & E1000_RCTL_UPE)
5429 phy_reg |= BM_RCTL_UPE;
5430 if (mac_reg & E1000_RCTL_MPE)
5431 phy_reg |= BM_RCTL_MPE;
5432 phy_reg &= ~(BM_RCTL_MO_MASK);
5433 if (mac_reg & E1000_RCTL_MO_3)
5434 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5435 << BM_RCTL_MO_SHIFT);
5436 if (mac_reg & E1000_RCTL_BAM)
5437 phy_reg |= BM_RCTL_BAM;
5438 if (mac_reg & E1000_RCTL_PMCF)
5439 phy_reg |= BM_RCTL_PMCF;
5440 mac_reg = er32(CTRL);
5441 if (mac_reg & E1000_CTRL_RFCE)
5442 phy_reg |= BM_RCTL_RFCE;
5443 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
5445 /* enable PHY wakeup in MAC register */
5447 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5449 /* configure and enable PHY wakeup in PHY registers */
5450 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5451 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5453 /* activate PHY wakeup */
5454 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5455 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5457 e_err("Could not set PHY Host Wakeup bit\n");
5459 hw->phy.ops.release(hw);
5464 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5467 struct net_device *netdev = pci_get_drvdata(pdev);
5468 struct e1000_adapter *adapter = netdev_priv(netdev);
5469 struct e1000_hw *hw = &adapter->hw;
5470 u32 ctrl, ctrl_ext, rctl, status;
5471 /* Runtime suspend should only enable wakeup for link changes */
5472 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
5475 netif_device_detach(netdev);
5477 if (netif_running(netdev)) {
5478 int count = E1000_CHECK_RESET_COUNT;
5480 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5481 usleep_range(10000, 20000);
5483 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5484 e1000e_down(adapter);
5485 e1000_free_irq(adapter);
5487 e1000e_reset_interrupt_capability(adapter);
5489 retval = pci_save_state(pdev);
5493 status = er32(STATUS);
5494 if (status & E1000_STATUS_LU)
5495 wufc &= ~E1000_WUFC_LNKC;
5498 e1000_setup_rctl(adapter);
5499 e1000e_set_rx_mode(netdev);
5501 /* turn on all-multi mode if wake on multicast is enabled */
5502 if (wufc & E1000_WUFC_MC) {
5504 rctl |= E1000_RCTL_MPE;
5509 /* advertise wake from D3Cold */
5510 #define E1000_CTRL_ADVD3WUC 0x00100000
5511 /* phy power management enable */
5512 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5513 ctrl |= E1000_CTRL_ADVD3WUC;
5514 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5515 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
5518 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5519 adapter->hw.phy.media_type ==
5520 e1000_media_type_internal_serdes) {
5521 /* keep the laser running in D3 */
5522 ctrl_ext = er32(CTRL_EXT);
5523 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
5524 ew32(CTRL_EXT, ctrl_ext);
5527 if (adapter->flags & FLAG_IS_ICH)
5528 e1000_suspend_workarounds_ich8lan(&adapter->hw);
5530 /* Allow time for pending master requests to run */
5531 e1000e_disable_pcie_master(&adapter->hw);
5533 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5534 /* enable wakeup by the PHY */
5535 retval = e1000_init_phy_wakeup(adapter, wufc);
5539 /* enable wakeup by the MAC */
5541 ew32(WUC, E1000_WUC_PME_EN);
5548 *enable_wake = !!wufc;
5550 /* make sure adapter isn't asleep if manageability is enabled */
5551 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5552 (hw->mac.ops.check_mng_mode(hw)))
5553 *enable_wake = true;
5555 if (adapter->hw.phy.type == e1000_phy_igp_3)
5556 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5559 * Release control of h/w to f/w. If f/w is AMT enabled, this
5560 * would have already happened in close and is redundant.
5562 e1000e_release_hw_control(adapter);
5564 pci_disable_device(pdev);
5569 static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5571 if (sleep && wake) {
5572 pci_prepare_to_sleep(pdev);
5576 pci_wake_from_d3(pdev, wake);
5577 pci_set_power_state(pdev, PCI_D3hot);
5580 static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5583 struct net_device *netdev = pci_get_drvdata(pdev);
5584 struct e1000_adapter *adapter = netdev_priv(netdev);
5587 * The pci-e switch on some quad port adapters will report a
5588 * correctable error when the MAC transitions from D0 to D3. To
5589 * prevent this we need to mask off the correctable errors on the
5590 * downstream port of the pci-e switch.
5592 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5593 struct pci_dev *us_dev = pdev->bus->self;
5594 int pos = pci_pcie_cap(us_dev);
5597 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5598 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5599 (devctl & ~PCI_EXP_DEVCTL_CERE));
5601 e1000_power_off(pdev, sleep, wake);
5603 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5605 e1000_power_off(pdev, sleep, wake);
5609 #ifdef CONFIG_PCIEASPM
5610 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5612 pci_disable_link_state_locked(pdev, state);
5615 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5621 * Both device and parent should have the same ASPM setting.
5622 * Disable ASPM in downstream component first and then upstream.
5624 pos = pci_pcie_cap(pdev);
5625 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16);
5627 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5629 if (!pdev->bus->self)
5632 pos = pci_pcie_cap(pdev->bus->self);
5633 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16);
5635 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5638 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5640 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5641 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5642 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5644 __e1000e_disable_aspm(pdev, state);
5648 static bool e1000e_pm_ready(struct e1000_adapter *adapter)
5650 return !!adapter->tx_ring->buffer_info;
5653 static int __e1000_resume(struct pci_dev *pdev)
5655 struct net_device *netdev = pci_get_drvdata(pdev);
5656 struct e1000_adapter *adapter = netdev_priv(netdev);
5657 struct e1000_hw *hw = &adapter->hw;
5658 u16 aspm_disable_flag = 0;
5661 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5662 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5663 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5664 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5665 if (aspm_disable_flag)
5666 e1000e_disable_aspm(pdev, aspm_disable_flag);
5668 pci_set_power_state(pdev, PCI_D0);
5669 pci_restore_state(pdev);
5670 pci_save_state(pdev);
5672 e1000e_set_interrupt_capability(adapter);
5673 if (netif_running(netdev)) {
5674 err = e1000_request_irq(adapter);
5679 if (hw->mac.type == e1000_pch2lan)
5680 e1000_resume_workarounds_pchlan(&adapter->hw);
5682 e1000e_power_up_phy(adapter);
5684 /* report the system wakeup cause from S3/S4 */
5685 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5688 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5690 e_info("PHY Wakeup cause - %s\n",
5691 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5692 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5693 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5694 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5695 phy_data & E1000_WUS_LNKC ?
5696 "Link Status Change" : "other");
5698 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5700 u32 wus = er32(WUS);
5702 e_info("MAC Wakeup cause - %s\n",
5703 wus & E1000_WUS_EX ? "Unicast Packet" :
5704 wus & E1000_WUS_MC ? "Multicast Packet" :
5705 wus & E1000_WUS_BC ? "Broadcast Packet" :
5706 wus & E1000_WUS_MAG ? "Magic Packet" :
5707 wus & E1000_WUS_LNKC ? "Link Status Change" :
5713 e1000e_reset(adapter);
5715 e1000_init_manageability_pt(adapter);
5717 if (netif_running(netdev))
5720 netif_device_attach(netdev);
5723 * If the controller has AMT, do not set DRV_LOAD until the interface
5724 * is up. For all other cases, let the f/w know that the h/w is now
5725 * under the control of the driver.
5727 if (!(adapter->flags & FLAG_HAS_AMT))
5728 e1000e_get_hw_control(adapter);
5733 #ifdef CONFIG_PM_SLEEP
5734 static int e1000_suspend(struct device *dev)
5736 struct pci_dev *pdev = to_pci_dev(dev);
5740 retval = __e1000_shutdown(pdev, &wake, false);
5742 e1000_complete_shutdown(pdev, true, wake);
5747 static int e1000_resume(struct device *dev)
5749 struct pci_dev *pdev = to_pci_dev(dev);
5750 struct net_device *netdev = pci_get_drvdata(pdev);
5751 struct e1000_adapter *adapter = netdev_priv(netdev);
5753 if (e1000e_pm_ready(adapter))
5754 adapter->idle_check = true;
5756 return __e1000_resume(pdev);
5758 #endif /* CONFIG_PM_SLEEP */
5760 #ifdef CONFIG_PM_RUNTIME
5761 static int e1000_runtime_suspend(struct device *dev)
5763 struct pci_dev *pdev = to_pci_dev(dev);
5764 struct net_device *netdev = pci_get_drvdata(pdev);
5765 struct e1000_adapter *adapter = netdev_priv(netdev);
5767 if (e1000e_pm_ready(adapter)) {
5770 __e1000_shutdown(pdev, &wake, true);
5776 static int e1000_idle(struct device *dev)
5778 struct pci_dev *pdev = to_pci_dev(dev);
5779 struct net_device *netdev = pci_get_drvdata(pdev);
5780 struct e1000_adapter *adapter = netdev_priv(netdev);
5782 if (!e1000e_pm_ready(adapter))
5785 if (adapter->idle_check) {
5786 adapter->idle_check = false;
5787 if (!e1000e_has_link(adapter))
5788 pm_schedule_suspend(dev, MSEC_PER_SEC);
5794 static int e1000_runtime_resume(struct device *dev)
5796 struct pci_dev *pdev = to_pci_dev(dev);
5797 struct net_device *netdev = pci_get_drvdata(pdev);
5798 struct e1000_adapter *adapter = netdev_priv(netdev);
5800 if (!e1000e_pm_ready(adapter))
5803 adapter->idle_check = !dev->power.runtime_auto;
5804 return __e1000_resume(pdev);
5806 #endif /* CONFIG_PM_RUNTIME */
5807 #endif /* CONFIG_PM */
5809 static void e1000_shutdown(struct pci_dev *pdev)
5813 __e1000_shutdown(pdev, &wake, false);
5815 if (system_state == SYSTEM_POWER_OFF)
5816 e1000_complete_shutdown(pdev, false, wake);
5819 #ifdef CONFIG_NET_POLL_CONTROLLER
5821 static irqreturn_t e1000_intr_msix(int irq, void *data)
5823 struct net_device *netdev = data;
5824 struct e1000_adapter *adapter = netdev_priv(netdev);
5826 if (adapter->msix_entries) {
5827 int vector, msix_irq;
5830 msix_irq = adapter->msix_entries[vector].vector;
5831 disable_irq(msix_irq);
5832 e1000_intr_msix_rx(msix_irq, netdev);
5833 enable_irq(msix_irq);
5836 msix_irq = adapter->msix_entries[vector].vector;
5837 disable_irq(msix_irq);
5838 e1000_intr_msix_tx(msix_irq, netdev);
5839 enable_irq(msix_irq);
5842 msix_irq = adapter->msix_entries[vector].vector;
5843 disable_irq(msix_irq);
5844 e1000_msix_other(msix_irq, netdev);
5845 enable_irq(msix_irq);
5852 * Polling 'interrupt' - used by things like netconsole to send skbs
5853 * without having to re-enable interrupts. It's not called while
5854 * the interrupt routine is executing.
5856 static void e1000_netpoll(struct net_device *netdev)
5858 struct e1000_adapter *adapter = netdev_priv(netdev);
5860 switch (adapter->int_mode) {
5861 case E1000E_INT_MODE_MSIX:
5862 e1000_intr_msix(adapter->pdev->irq, netdev);
5864 case E1000E_INT_MODE_MSI:
5865 disable_irq(adapter->pdev->irq);
5866 e1000_intr_msi(adapter->pdev->irq, netdev);
5867 enable_irq(adapter->pdev->irq);
5869 default: /* E1000E_INT_MODE_LEGACY */
5870 disable_irq(adapter->pdev->irq);
5871 e1000_intr(adapter->pdev->irq, netdev);
5872 enable_irq(adapter->pdev->irq);
5879 * e1000_io_error_detected - called when PCI error is detected
5880 * @pdev: Pointer to PCI device
5881 * @state: The current pci connection state
5883 * This function is called after a PCI bus error affecting
5884 * this device has been detected.
5886 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5887 pci_channel_state_t state)
5889 struct net_device *netdev = pci_get_drvdata(pdev);
5890 struct e1000_adapter *adapter = netdev_priv(netdev);
5892 netif_device_detach(netdev);
5894 if (state == pci_channel_io_perm_failure)
5895 return PCI_ERS_RESULT_DISCONNECT;
5897 if (netif_running(netdev))
5898 e1000e_down(adapter);
5899 pci_disable_device(pdev);
5901 /* Request a slot slot reset. */
5902 return PCI_ERS_RESULT_NEED_RESET;
5906 * e1000_io_slot_reset - called after the pci bus has been reset.
5907 * @pdev: Pointer to PCI device
5909 * Restart the card from scratch, as if from a cold-boot. Implementation
5910 * resembles the first-half of the e1000_resume routine.
5912 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5914 struct net_device *netdev = pci_get_drvdata(pdev);
5915 struct e1000_adapter *adapter = netdev_priv(netdev);
5916 struct e1000_hw *hw = &adapter->hw;
5917 u16 aspm_disable_flag = 0;
5919 pci_ers_result_t result;
5921 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5922 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5923 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5924 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5925 if (aspm_disable_flag)
5926 e1000e_disable_aspm(pdev, aspm_disable_flag);
5928 err = pci_enable_device_mem(pdev);
5931 "Cannot re-enable PCI device after reset.\n");
5932 result = PCI_ERS_RESULT_DISCONNECT;
5934 pci_set_master(pdev);
5935 pdev->state_saved = true;
5936 pci_restore_state(pdev);
5938 pci_enable_wake(pdev, PCI_D3hot, 0);
5939 pci_enable_wake(pdev, PCI_D3cold, 0);
5941 e1000e_reset(adapter);
5943 result = PCI_ERS_RESULT_RECOVERED;
5946 pci_cleanup_aer_uncorrect_error_status(pdev);
5952 * e1000_io_resume - called when traffic can start flowing again.
5953 * @pdev: Pointer to PCI device
5955 * This callback is called when the error recovery driver tells us that
5956 * its OK to resume normal operation. Implementation resembles the
5957 * second-half of the e1000_resume routine.
5959 static void e1000_io_resume(struct pci_dev *pdev)
5961 struct net_device *netdev = pci_get_drvdata(pdev);
5962 struct e1000_adapter *adapter = netdev_priv(netdev);
5964 e1000_init_manageability_pt(adapter);
5966 if (netif_running(netdev)) {
5967 if (e1000e_up(adapter)) {
5969 "can't bring device back up after reset\n");
5974 netif_device_attach(netdev);
5977 * If the controller has AMT, do not set DRV_LOAD until the interface
5978 * is up. For all other cases, let the f/w know that the h/w is now
5979 * under the control of the driver.
5981 if (!(adapter->flags & FLAG_HAS_AMT))
5982 e1000e_get_hw_control(adapter);
5986 static void e1000_print_device_info(struct e1000_adapter *adapter)
5988 struct e1000_hw *hw = &adapter->hw;
5989 struct net_device *netdev = adapter->netdev;
5991 u8 pba_str[E1000_PBANUM_LENGTH];
5993 /* print bus type/speed/width info */
5994 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
5996 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
6000 e_info("Intel(R) PRO/%s Network Connection\n",
6001 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
6002 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6003 E1000_PBANUM_LENGTH);
6005 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
6006 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6007 hw->mac.type, hw->phy.type, pba_str);
6010 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6012 struct e1000_hw *hw = &adapter->hw;
6016 if (hw->mac.type != e1000_82573)
6019 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
6021 if (!ret_val && (!(buf & (1 << 0)))) {
6022 /* Deep Smart Power Down (DSPD) */
6023 dev_warn(&adapter->pdev->dev,
6024 "Warning: detected DSPD enabled in EEPROM\n");
6028 static int e1000_set_features(struct net_device *netdev,
6029 netdev_features_t features)
6031 struct e1000_adapter *adapter = netdev_priv(netdev);
6032 netdev_features_t changed = features ^ netdev->features;
6034 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6035 adapter->flags |= FLAG_TSO_FORCE;
6037 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
6038 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6043 * IP payload checksum (enabled with jumbos/packet-split when Rx
6044 * checksum is enabled) and generation of RSS hash is mutually
6045 * exclusive in the hardware.
6047 if (adapter->rx_ps_pages &&
6048 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
6049 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");
6053 if (changed & NETIF_F_RXFCS) {
6054 if (features & NETIF_F_RXFCS) {
6055 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6057 /* We need to take it back to defaults, which might mean
6058 * stripping is still disabled at the adapter level.
6060 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6061 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6063 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6067 netdev->features = features;
6069 if (netif_running(netdev))
6070 e1000e_reinit_locked(adapter);
6072 e1000e_reset(adapter);
6077 static const struct net_device_ops e1000e_netdev_ops = {
6078 .ndo_open = e1000_open,
6079 .ndo_stop = e1000_close,
6080 .ndo_start_xmit = e1000_xmit_frame,
6081 .ndo_get_stats64 = e1000e_get_stats64,
6082 .ndo_set_rx_mode = e1000e_set_rx_mode,
6083 .ndo_set_mac_address = e1000_set_mac,
6084 .ndo_change_mtu = e1000_change_mtu,
6085 .ndo_do_ioctl = e1000_ioctl,
6086 .ndo_tx_timeout = e1000_tx_timeout,
6087 .ndo_validate_addr = eth_validate_addr,
6089 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6090 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6091 #ifdef CONFIG_NET_POLL_CONTROLLER
6092 .ndo_poll_controller = e1000_netpoll,
6094 .ndo_set_features = e1000_set_features,
6098 * e1000_probe - Device Initialization Routine
6099 * @pdev: PCI device information struct
6100 * @ent: entry in e1000_pci_tbl
6102 * Returns 0 on success, negative on failure
6104 * e1000_probe initializes an adapter identified by a pci_dev structure.
6105 * The OS initialization, configuring of the adapter private structure,
6106 * and a hardware reset occur.
6108 static int __devinit e1000_probe(struct pci_dev *pdev,
6109 const struct pci_device_id *ent)
6111 struct net_device *netdev;
6112 struct e1000_adapter *adapter;
6113 struct e1000_hw *hw;
6114 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
6115 resource_size_t mmio_start, mmio_len;
6116 resource_size_t flash_start, flash_len;
6117 static int cards_found;
6118 u16 aspm_disable_flag = 0;
6119 int i, err, pci_using_dac;
6120 u16 eeprom_data = 0;
6121 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6123 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6124 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6125 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
6126 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6127 if (aspm_disable_flag)
6128 e1000e_disable_aspm(pdev, aspm_disable_flag);
6130 err = pci_enable_device_mem(pdev);
6135 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
6137 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
6141 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
6143 err = dma_set_coherent_mask(&pdev->dev,
6146 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
6152 err = pci_request_selected_regions_exclusive(pdev,
6153 pci_select_bars(pdev, IORESOURCE_MEM),
6154 e1000e_driver_name);
6158 /* AER (Advanced Error Reporting) hooks */
6159 pci_enable_pcie_error_reporting(pdev);
6161 pci_set_master(pdev);
6162 /* PCI config space info */
6163 err = pci_save_state(pdev);
6165 goto err_alloc_etherdev;
6168 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6170 goto err_alloc_etherdev;
6172 SET_NETDEV_DEV(netdev, &pdev->dev);
6174 netdev->irq = pdev->irq;
6176 pci_set_drvdata(pdev, netdev);
6177 adapter = netdev_priv(netdev);
6179 adapter->netdev = netdev;
6180 adapter->pdev = pdev;
6182 adapter->pba = ei->pba;
6183 adapter->flags = ei->flags;
6184 adapter->flags2 = ei->flags2;
6185 adapter->hw.adapter = adapter;
6186 adapter->hw.mac.type = ei->mac;
6187 adapter->max_hw_frame_size = ei->max_hw_frame_size;
6188 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
6190 mmio_start = pci_resource_start(pdev, 0);
6191 mmio_len = pci_resource_len(pdev, 0);
6194 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6195 if (!adapter->hw.hw_addr)
6198 if ((adapter->flags & FLAG_HAS_FLASH) &&
6199 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6200 flash_start = pci_resource_start(pdev, 1);
6201 flash_len = pci_resource_len(pdev, 1);
6202 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6203 if (!adapter->hw.flash_address)
6207 /* construct the net_device struct */
6208 netdev->netdev_ops = &e1000e_netdev_ops;
6209 e1000e_set_ethtool_ops(netdev);
6210 netdev->watchdog_timeo = 5 * HZ;
6211 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
6212 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
6214 netdev->mem_start = mmio_start;
6215 netdev->mem_end = mmio_start + mmio_len;
6217 adapter->bd_number = cards_found++;
6219 e1000e_check_options(adapter);
6221 /* setup adapter struct */
6222 err = e1000_sw_init(adapter);
6226 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6227 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6228 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6230 err = ei->get_variants(adapter);
6234 if ((adapter->flags & FLAG_IS_ICH) &&
6235 (adapter->flags & FLAG_READ_ONLY_NVM))
6236 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6238 hw->mac.ops.get_bus_info(&adapter->hw);
6240 adapter->hw.phy.autoneg_wait_to_complete = 0;
6242 /* Copper options */
6243 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
6244 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6245 adapter->hw.phy.disable_polarity_correction = 0;
6246 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6249 if (hw->phy.ops.check_reset_block(hw))
6250 e_info("PHY reset is blocked due to SOL/IDER session.\n");
6252 /* Set initial default active device features */
6253 netdev->features = (NETIF_F_SG |
6254 NETIF_F_HW_VLAN_RX |
6255 NETIF_F_HW_VLAN_TX |
6262 /* Set user-changeable features (subset of all device features) */
6263 netdev->hw_features = netdev->features;
6264 netdev->hw_features |= NETIF_F_RXFCS;
6265 netdev->priv_flags |= IFF_SUPP_NOFCS;
6266 netdev->hw_features |= NETIF_F_RXALL;
6268 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6269 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6271 netdev->vlan_features |= (NETIF_F_SG |
6276 netdev->priv_flags |= IFF_UNICAST_FLT;
6278 if (pci_using_dac) {
6279 netdev->features |= NETIF_F_HIGHDMA;
6280 netdev->vlan_features |= NETIF_F_HIGHDMA;
6283 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6284 adapter->flags |= FLAG_MNG_PT_ENABLED;
6287 * before reading the NVM, reset the controller to
6288 * put the device in a known good starting state
6290 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6293 * systems with ASPM and others may see the checksum fail on the first
6294 * attempt. Let's give it a few tries
6297 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6300 e_err("The NVM Checksum Is Not Valid\n");
6306 e1000_eeprom_checks(adapter);
6308 /* copy the MAC address */
6309 if (e1000e_read_mac_addr(&adapter->hw))
6310 e_err("NVM Read Error while reading MAC address\n");
6312 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6313 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6315 if (!is_valid_ether_addr(netdev->perm_addr)) {
6316 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
6321 init_timer(&adapter->watchdog_timer);
6322 adapter->watchdog_timer.function = e1000_watchdog;
6323 adapter->watchdog_timer.data = (unsigned long) adapter;
6325 init_timer(&adapter->phy_info_timer);
6326 adapter->phy_info_timer.function = e1000_update_phy_info;
6327 adapter->phy_info_timer.data = (unsigned long) adapter;
6329 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6330 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
6331 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6332 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
6333 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
6335 /* Initialize link parameters. User can change them with ethtool */
6336 adapter->hw.mac.autoneg = 1;
6337 adapter->fc_autoneg = true;
6338 adapter->hw.fc.requested_mode = e1000_fc_default;
6339 adapter->hw.fc.current_mode = e1000_fc_default;
6340 adapter->hw.phy.autoneg_advertised = 0x2f;
6342 /* ring size defaults */
6343 adapter->rx_ring->count = 256;
6344 adapter->tx_ring->count = 256;
6347 * Initial Wake on LAN setting - If APM wake is enabled in
6348 * the EEPROM, enable the ACPI Magic Packet filter
6350 if (adapter->flags & FLAG_APME_IN_WUC) {
6351 /* APME bit in EEPROM is mapped to WUC.APME */
6352 eeprom_data = er32(WUC);
6353 eeprom_apme_mask = E1000_WUC_APME;
6354 if ((hw->mac.type > e1000_ich10lan) &&
6355 (eeprom_data & E1000_WUC_PHY_WAKE))
6356 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
6357 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6358 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6359 (adapter->hw.bus.func == 1))
6360 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6363 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6367 /* fetch WoL from EEPROM */
6368 if (eeprom_data & eeprom_apme_mask)
6369 adapter->eeprom_wol |= E1000_WUFC_MAG;
6372 * now that we have the eeprom settings, apply the special cases
6373 * where the eeprom may be wrong or the board simply won't support
6374 * wake on lan on a particular port
6376 if (!(adapter->flags & FLAG_HAS_WOL))
6377 adapter->eeprom_wol = 0;
6379 /* initialize the wol settings based on the eeprom settings */
6380 adapter->wol = adapter->eeprom_wol;
6381 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
6383 /* save off EEPROM version number */
6384 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6386 /* reset the hardware with the new settings */
6387 e1000e_reset(adapter);
6390 * If the controller has AMT, do not set DRV_LOAD until the interface
6391 * is up. For all other cases, let the f/w know that the h/w is now
6392 * under the control of the driver.
6394 if (!(adapter->flags & FLAG_HAS_AMT))
6395 e1000e_get_hw_control(adapter);
6397 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
6398 err = register_netdev(netdev);
6402 /* carrier off reporting is important to ethtool even BEFORE open */
6403 netif_carrier_off(netdev);
6405 e1000_print_device_info(adapter);
6407 if (pci_dev_run_wake(pdev))
6408 pm_runtime_put_noidle(&pdev->dev);
6413 if (!(adapter->flags & FLAG_HAS_AMT))
6414 e1000e_release_hw_control(adapter);
6416 if (!hw->phy.ops.check_reset_block(hw))
6417 e1000_phy_hw_reset(&adapter->hw);
6419 kfree(adapter->tx_ring);
6420 kfree(adapter->rx_ring);
6422 if (adapter->hw.flash_address)
6423 iounmap(adapter->hw.flash_address);
6424 e1000e_reset_interrupt_capability(adapter);
6426 iounmap(adapter->hw.hw_addr);
6428 free_netdev(netdev);
6430 pci_release_selected_regions(pdev,
6431 pci_select_bars(pdev, IORESOURCE_MEM));
6434 pci_disable_device(pdev);
6439 * e1000_remove - Device Removal Routine
6440 * @pdev: PCI device information struct
6442 * e1000_remove is called by the PCI subsystem to alert the driver
6443 * that it should release a PCI device. The could be caused by a
6444 * Hot-Plug event, or because the driver is going to be removed from
6447 static void __devexit e1000_remove(struct pci_dev *pdev)
6449 struct net_device *netdev = pci_get_drvdata(pdev);
6450 struct e1000_adapter *adapter = netdev_priv(netdev);
6451 bool down = test_bit(__E1000_DOWN, &adapter->state);
6454 * The timers may be rescheduled, so explicitly disable them
6455 * from being rescheduled.
6458 set_bit(__E1000_DOWN, &adapter->state);
6459 del_timer_sync(&adapter->watchdog_timer);
6460 del_timer_sync(&adapter->phy_info_timer);
6462 cancel_work_sync(&adapter->reset_task);
6463 cancel_work_sync(&adapter->watchdog_task);
6464 cancel_work_sync(&adapter->downshift_task);
6465 cancel_work_sync(&adapter->update_phy_task);
6466 cancel_work_sync(&adapter->print_hang_task);
6468 if (!(netdev->flags & IFF_UP))
6469 e1000_power_down_phy(adapter);
6471 /* Don't lie to e1000_close() down the road. */
6473 clear_bit(__E1000_DOWN, &adapter->state);
6474 unregister_netdev(netdev);
6476 if (pci_dev_run_wake(pdev))
6477 pm_runtime_get_noresume(&pdev->dev);
6480 * Release control of h/w to f/w. If f/w is AMT enabled, this
6481 * would have already happened in close and is redundant.
6483 e1000e_release_hw_control(adapter);
6485 e1000e_reset_interrupt_capability(adapter);
6486 kfree(adapter->tx_ring);
6487 kfree(adapter->rx_ring);
6489 iounmap(adapter->hw.hw_addr);
6490 if (adapter->hw.flash_address)
6491 iounmap(adapter->hw.flash_address);
6492 pci_release_selected_regions(pdev,
6493 pci_select_bars(pdev, IORESOURCE_MEM));
6495 free_netdev(netdev);
6498 pci_disable_pcie_error_reporting(pdev);
6500 pci_disable_device(pdev);
6503 /* PCI Error Recovery (ERS) */
6504 static struct pci_error_handlers e1000_err_handler = {
6505 .error_detected = e1000_io_error_detected,
6506 .slot_reset = e1000_io_slot_reset,
6507 .resume = e1000_io_resume,
6510 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
6511 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6512 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6513 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6514 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6515 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6516 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
6517 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6518 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6519 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
6521 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6522 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6523 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6524 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
6526 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6527 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6528 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
6530 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
6531 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
6532 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
6534 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6535 board_80003es2lan },
6536 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6537 board_80003es2lan },
6538 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6539 board_80003es2lan },
6540 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6541 board_80003es2lan },
6543 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6544 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6545 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6546 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6547 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6548 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6549 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
6550 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
6552 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6553 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6554 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6555 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6556 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
6557 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
6558 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6559 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6560 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6562 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6563 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6564 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
6566 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6567 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
6568 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
6570 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6571 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6572 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6573 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6575 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6576 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6578 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
6580 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6583 static const struct dev_pm_ops e1000_pm_ops = {
6584 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6585 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6586 e1000_runtime_resume, e1000_idle)
6590 /* PCI Device API Driver */
6591 static struct pci_driver e1000_driver = {
6592 .name = e1000e_driver_name,
6593 .id_table = e1000_pci_tbl,
6594 .probe = e1000_probe,
6595 .remove = __devexit_p(e1000_remove),
6598 .pm = &e1000_pm_ops,
6601 .shutdown = e1000_shutdown,
6602 .err_handler = &e1000_err_handler
6606 * e1000_init_module - Driver Registration Routine
6608 * e1000_init_module is the first routine called when the driver is
6609 * loaded. All it does is register with the PCI subsystem.
6611 static int __init e1000_init_module(void)
6614 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6615 e1000e_driver_version);
6616 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
6617 ret = pci_register_driver(&e1000_driver);
6621 module_init(e1000_init_module);
6624 * e1000_exit_module - Driver Exit Cleanup Routine
6626 * e1000_exit_module is called just before the driver is removed
6629 static void __exit e1000_exit_module(void)
6631 pci_unregister_driver(&e1000_driver);
6633 module_exit(e1000_exit_module);
6636 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6637 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6638 MODULE_LICENSE("GPL");
6639 MODULE_VERSION(DRV_VERSION);