1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2011 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.5.1" DRV_EXTRAVERSION
60 char e1000e_driver_name[] = "e1000e";
61 const char e1000e_driver_version[] = DRV_VERSION;
63 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
65 static const struct e1000_info *e1000_info_tbl[] = {
66 [board_82571] = &e1000_82571_info,
67 [board_82572] = &e1000_82572_info,
68 [board_82573] = &e1000_82573_info,
69 [board_82574] = &e1000_82574_info,
70 [board_82583] = &e1000_82583_info,
71 [board_80003es2lan] = &e1000_es2_info,
72 [board_ich8lan] = &e1000_ich8_info,
73 [board_ich9lan] = &e1000_ich9_info,
74 [board_ich10lan] = &e1000_ich10_info,
75 [board_pchlan] = &e1000_pch_info,
76 [board_pch2lan] = &e1000_pch2_info,
79 struct e1000_reg_info {
84 #define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
85 #define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
86 #define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
87 #define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
88 #define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
90 #define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
91 #define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
92 #define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
93 #define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
94 #define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
96 static const struct e1000_reg_info e1000_reg_info_tbl[] = {
98 /* General Registers */
100 {E1000_STATUS, "STATUS"},
101 {E1000_CTRL_EXT, "CTRL_EXT"},
103 /* Interrupt Registers */
107 {E1000_RCTL, "RCTL"},
108 {E1000_RDLEN, "RDLEN"},
111 {E1000_RDTR, "RDTR"},
112 {E1000_RXDCTL(0), "RXDCTL"},
114 {E1000_RDBAL, "RDBAL"},
115 {E1000_RDBAH, "RDBAH"},
116 {E1000_RDFH, "RDFH"},
117 {E1000_RDFT, "RDFT"},
118 {E1000_RDFHS, "RDFHS"},
119 {E1000_RDFTS, "RDFTS"},
120 {E1000_RDFPC, "RDFPC"},
123 {E1000_TCTL, "TCTL"},
124 {E1000_TDBAL, "TDBAL"},
125 {E1000_TDBAH, "TDBAH"},
126 {E1000_TDLEN, "TDLEN"},
129 {E1000_TIDV, "TIDV"},
130 {E1000_TXDCTL(0), "TXDCTL"},
131 {E1000_TADV, "TADV"},
132 {E1000_TARC(0), "TARC"},
133 {E1000_TDFH, "TDFH"},
134 {E1000_TDFT, "TDFT"},
135 {E1000_TDFHS, "TDFHS"},
136 {E1000_TDFTS, "TDFTS"},
137 {E1000_TDFPC, "TDFPC"},
139 /* List Terminator */
144 * e1000_regdump - register printout routine
146 static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
152 switch (reginfo->ofs) {
153 case E1000_RXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_RXDCTL(n));
157 case E1000_TXDCTL(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TXDCTL(n));
162 for (n = 0; n < 2; n++)
163 regs[n] = __er32(hw, E1000_TARC(n));
166 pr_info("%-15s %08x\n",
167 reginfo->name, __er32(hw, reginfo->ofs));
171 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
172 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
176 * e1000e_dump - Print registers, Tx-ring and Rx-ring
178 static void e1000e_dump(struct e1000_adapter *adapter)
180 struct net_device *netdev = adapter->netdev;
181 struct e1000_hw *hw = &adapter->hw;
182 struct e1000_reg_info *reginfo;
183 struct e1000_ring *tx_ring = adapter->tx_ring;
184 struct e1000_tx_desc *tx_desc;
189 struct e1000_buffer *buffer_info;
190 struct e1000_ring *rx_ring = adapter->rx_ring;
191 union e1000_rx_desc_packet_split *rx_desc_ps;
192 union e1000_rx_desc_extended *rx_desc;
202 if (!netif_msg_hw(adapter))
205 /* Print netdevice Info */
207 dev_info(&adapter->pdev->dev, "Net device Info\n");
208 pr_info("Device Name state trans_start last_rx\n");
209 pr_info("%-15s %016lX %016lX %016lX\n",
210 netdev->name, netdev->state, netdev->trans_start,
214 /* Print Registers */
215 dev_info(&adapter->pdev->dev, "Register Dump\n");
216 pr_info(" Register Name Value\n");
217 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
218 reginfo->name; reginfo++) {
219 e1000_regdump(hw, reginfo);
222 /* Print Tx Ring Summary */
223 if (!netdev || !netif_running(netdev))
226 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
227 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
228 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
229 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
230 0, tx_ring->next_to_use, tx_ring->next_to_clean,
231 (unsigned long long)buffer_info->dma,
233 buffer_info->next_to_watch,
234 (unsigned long long)buffer_info->time_stamp);
237 if (!netif_msg_tx_done(adapter))
238 goto rx_ring_summary;
240 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
242 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
244 * Legacy Transmit Descriptor
245 * +--------------------------------------------------------------+
246 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
247 * +--------------------------------------------------------------+
248 * 8 | Special | CSS | Status | CMD | CSO | Length |
249 * +--------------------------------------------------------------+
250 * 63 48 47 36 35 32 31 24 23 16 15 0
252 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
253 * 63 48 47 40 39 32 31 16 15 8 7 0
254 * +----------------------------------------------------------------+
255 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
256 * +----------------------------------------------------------------+
257 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
258 * +----------------------------------------------------------------+
259 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
261 * Extended Data Descriptor (DTYP=0x1)
262 * +----------------------------------------------------------------+
263 * 0 | Buffer Address [63:0] |
264 * +----------------------------------------------------------------+
265 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
266 * +----------------------------------------------------------------+
267 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
269 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
270 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
271 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
272 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
273 const char *next_desc;
274 tx_desc = E1000_TX_DESC(*tx_ring, i);
275 buffer_info = &tx_ring->buffer_info[i];
276 u0 = (struct my_u0 *)tx_desc;
277 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
278 next_desc = " NTC/U";
279 else if (i == tx_ring->next_to_use)
281 else if (i == tx_ring->next_to_clean)
285 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
286 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
287 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
289 (unsigned long long)le64_to_cpu(u0->a),
290 (unsigned long long)le64_to_cpu(u0->b),
291 (unsigned long long)buffer_info->dma,
292 buffer_info->length, buffer_info->next_to_watch,
293 (unsigned long long)buffer_info->time_stamp,
294 buffer_info->skb, next_desc);
296 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
297 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
298 16, 1, phys_to_virt(buffer_info->dma),
299 buffer_info->length, true);
302 /* Print Rx Ring Summary */
304 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
305 pr_info("Queue [NTU] [NTC]\n");
306 pr_info(" %5d %5X %5X\n",
307 0, rx_ring->next_to_use, rx_ring->next_to_clean);
310 if (!netif_msg_rx_status(adapter))
313 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
314 switch (adapter->rx_ps_pages) {
318 /* [Extended] Packet Split Receive Descriptor Format
320 * +-----------------------------------------------------+
321 * 0 | Buffer Address 0 [63:0] |
322 * +-----------------------------------------------------+
323 * 8 | Buffer Address 1 [63:0] |
324 * +-----------------------------------------------------+
325 * 16 | Buffer Address 2 [63:0] |
326 * +-----------------------------------------------------+
327 * 24 | Buffer Address 3 [63:0] |
328 * +-----------------------------------------------------+
330 pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
331 /* [Extended] Receive Descriptor (Write-Back) Format
333 * 63 48 47 32 31 13 12 8 7 4 3 0
334 * +------------------------------------------------------+
335 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
336 * | Checksum | Ident | | Queue | | Type |
337 * +------------------------------------------------------+
338 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
339 * +------------------------------------------------------+
340 * 63 48 47 32 31 20 19 0
342 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
343 for (i = 0; i < rx_ring->count; i++) {
344 const char *next_desc;
345 buffer_info = &rx_ring->buffer_info[i];
346 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
347 u1 = (struct my_u1 *)rx_desc_ps;
349 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
351 if (i == rx_ring->next_to_use)
353 else if (i == rx_ring->next_to_clean)
358 if (staterr & E1000_RXD_STAT_DD) {
359 /* Descriptor Done */
360 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
362 (unsigned long long)le64_to_cpu(u1->a),
363 (unsigned long long)le64_to_cpu(u1->b),
364 (unsigned long long)le64_to_cpu(u1->c),
365 (unsigned long long)le64_to_cpu(u1->d),
366 buffer_info->skb, next_desc);
368 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
370 (unsigned long long)le64_to_cpu(u1->a),
371 (unsigned long long)le64_to_cpu(u1->b),
372 (unsigned long long)le64_to_cpu(u1->c),
373 (unsigned long long)le64_to_cpu(u1->d),
374 (unsigned long long)buffer_info->dma,
375 buffer_info->skb, next_desc);
377 if (netif_msg_pktdata(adapter))
378 print_hex_dump(KERN_INFO, "",
379 DUMP_PREFIX_ADDRESS, 16, 1,
380 phys_to_virt(buffer_info->dma),
381 adapter->rx_ps_bsize0, true);
387 /* Extended Receive Descriptor (Read) Format
389 * +-----------------------------------------------------+
390 * 0 | Buffer Address [63:0] |
391 * +-----------------------------------------------------+
393 * +-----------------------------------------------------+
395 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
396 /* Extended Receive Descriptor (Write-Back) Format
398 * 63 48 47 32 31 24 23 4 3 0
399 * +------------------------------------------------------+
401 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
402 * | Packet | IP | | | Type |
403 * | Checksum | Ident | | | |
404 * +------------------------------------------------------+
405 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
406 * +------------------------------------------------------+
407 * 63 48 47 32 31 20 19 0
409 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
411 for (i = 0; i < rx_ring->count; i++) {
412 const char *next_desc;
414 buffer_info = &rx_ring->buffer_info[i];
415 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
416 u1 = (struct my_u1 *)rx_desc;
417 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
419 if (i == rx_ring->next_to_use)
421 else if (i == rx_ring->next_to_clean)
426 if (staterr & E1000_RXD_STAT_DD) {
427 /* Descriptor Done */
428 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
430 (unsigned long long)le64_to_cpu(u1->a),
431 (unsigned long long)le64_to_cpu(u1->b),
432 buffer_info->skb, next_desc);
434 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
436 (unsigned long long)le64_to_cpu(u1->a),
437 (unsigned long long)le64_to_cpu(u1->b),
438 (unsigned long long)buffer_info->dma,
439 buffer_info->skb, next_desc);
441 if (netif_msg_pktdata(adapter))
442 print_hex_dump(KERN_INFO, "",
443 DUMP_PREFIX_ADDRESS, 16,
447 adapter->rx_buffer_len,
458 * e1000_desc_unused - calculate if we have unused descriptors
460 static int e1000_desc_unused(struct e1000_ring *ring)
462 if (ring->next_to_clean > ring->next_to_use)
463 return ring->next_to_clean - ring->next_to_use - 1;
465 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
469 * e1000_receive_skb - helper function to handle Rx indications
470 * @adapter: board private structure
471 * @status: descriptor status field as written by hardware
472 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
473 * @skb: pointer to sk_buff to be indicated to stack
475 static void e1000_receive_skb(struct e1000_adapter *adapter,
476 struct net_device *netdev, struct sk_buff *skb,
477 u8 status, __le16 vlan)
479 u16 tag = le16_to_cpu(vlan);
480 skb->protocol = eth_type_trans(skb, netdev);
482 if (status & E1000_RXD_STAT_VP)
483 __vlan_hwaccel_put_tag(skb, tag);
485 napi_gro_receive(&adapter->napi, skb);
489 * e1000_rx_checksum - Receive Checksum Offload
490 * @adapter: board private structure
491 * @status_err: receive descriptor status and error fields
492 * @csum: receive descriptor csum field
493 * @sk_buff: socket buffer with received data
495 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
496 u32 csum, struct sk_buff *skb)
498 u16 status = (u16)status_err;
499 u8 errors = (u8)(status_err >> 24);
501 skb_checksum_none_assert(skb);
503 /* Ignore Checksum bit is set */
504 if (status & E1000_RXD_STAT_IXSM)
506 /* TCP/UDP checksum error bit is set */
507 if (errors & E1000_RXD_ERR_TCPE) {
508 /* let the stack verify checksum errors */
509 adapter->hw_csum_err++;
513 /* TCP/UDP Checksum has not been calculated */
514 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
517 /* It must be a TCP or UDP packet with a valid checksum */
518 if (status & E1000_RXD_STAT_TCPCS) {
519 /* TCP checksum is good */
520 skb->ip_summed = CHECKSUM_UNNECESSARY;
523 * IP fragment with UDP payload
524 * Hardware complements the payload checksum, so we undo it
525 * and then put the value in host order for further stack use.
527 __sum16 sum = (__force __sum16)htons(csum);
528 skb->csum = csum_unfold(~sum);
529 skb->ip_summed = CHECKSUM_COMPLETE;
531 adapter->hw_csum_good++;
535 * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa()
536 * @hw: pointer to the HW structure
537 * @tail: address of tail descriptor register
538 * @i: value to write to tail descriptor register
540 * When updating the tail register, the ME could be accessing Host CSR
541 * registers at the same time. Normally, this is handled in h/w by an
542 * arbiter but on some parts there is a bug that acknowledges Host accesses
543 * later than it should which could result in the descriptor register to
544 * have an incorrect value. Workaround this by checking the FWSM register
545 * which has bit 24 set while ME is accessing Host CSR registers, wait
546 * if it is set and try again a number of times.
548 static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, u8 __iomem * tail,
553 while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) &&
554 (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI))
559 if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail)))
560 return E1000_ERR_SWFW_SYNC;
565 static void e1000e_update_rdt_wa(struct e1000_adapter *adapter, unsigned int i)
567 u8 __iomem *tail = (adapter->hw.hw_addr + adapter->rx_ring->tail);
568 struct e1000_hw *hw = &adapter->hw;
570 if (e1000e_update_tail_wa(hw, tail, i)) {
571 u32 rctl = er32(RCTL);
572 ew32(RCTL, rctl & ~E1000_RCTL_EN);
573 e_err("ME firmware caused invalid RDT - resetting\n");
574 schedule_work(&adapter->reset_task);
578 static void e1000e_update_tdt_wa(struct e1000_adapter *adapter, unsigned int i)
580 u8 __iomem *tail = (adapter->hw.hw_addr + adapter->tx_ring->tail);
581 struct e1000_hw *hw = &adapter->hw;
583 if (e1000e_update_tail_wa(hw, tail, i)) {
584 u32 tctl = er32(TCTL);
585 ew32(TCTL, tctl & ~E1000_TCTL_EN);
586 e_err("ME firmware caused invalid TDT - resetting\n");
587 schedule_work(&adapter->reset_task);
592 * e1000_alloc_rx_buffers - Replace used receive buffers
593 * @adapter: address of board private structure
595 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
596 int cleaned_count, gfp_t gfp)
598 struct net_device *netdev = adapter->netdev;
599 struct pci_dev *pdev = adapter->pdev;
600 struct e1000_ring *rx_ring = adapter->rx_ring;
601 union e1000_rx_desc_extended *rx_desc;
602 struct e1000_buffer *buffer_info;
605 unsigned int bufsz = adapter->rx_buffer_len;
607 i = rx_ring->next_to_use;
608 buffer_info = &rx_ring->buffer_info[i];
610 while (cleaned_count--) {
611 skb = buffer_info->skb;
617 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
619 /* Better luck next round */
620 adapter->alloc_rx_buff_failed++;
624 buffer_info->skb = skb;
626 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
627 adapter->rx_buffer_len,
629 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
630 dev_err(&pdev->dev, "Rx DMA map failed\n");
631 adapter->rx_dma_failed++;
635 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
636 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
638 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
640 * Force memory writes to complete before letting h/w
641 * know there are new descriptors to fetch. (Only
642 * applicable for weak-ordered memory model archs,
646 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
647 e1000e_update_rdt_wa(adapter, i);
649 writel(i, adapter->hw.hw_addr + rx_ring->tail);
652 if (i == rx_ring->count)
654 buffer_info = &rx_ring->buffer_info[i];
657 rx_ring->next_to_use = i;
661 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
662 * @adapter: address of board private structure
664 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
665 int cleaned_count, gfp_t gfp)
667 struct net_device *netdev = adapter->netdev;
668 struct pci_dev *pdev = adapter->pdev;
669 union e1000_rx_desc_packet_split *rx_desc;
670 struct e1000_ring *rx_ring = adapter->rx_ring;
671 struct e1000_buffer *buffer_info;
672 struct e1000_ps_page *ps_page;
676 i = rx_ring->next_to_use;
677 buffer_info = &rx_ring->buffer_info[i];
679 while (cleaned_count--) {
680 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
682 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
683 ps_page = &buffer_info->ps_pages[j];
684 if (j >= adapter->rx_ps_pages) {
685 /* all unused desc entries get hw null ptr */
686 rx_desc->read.buffer_addr[j + 1] =
690 if (!ps_page->page) {
691 ps_page->page = alloc_page(gfp);
692 if (!ps_page->page) {
693 adapter->alloc_rx_buff_failed++;
696 ps_page->dma = dma_map_page(&pdev->dev,
700 if (dma_mapping_error(&pdev->dev,
702 dev_err(&adapter->pdev->dev,
703 "Rx DMA page map failed\n");
704 adapter->rx_dma_failed++;
709 * Refresh the desc even if buffer_addrs
710 * didn't change because each write-back
713 rx_desc->read.buffer_addr[j + 1] =
714 cpu_to_le64(ps_page->dma);
717 skb = __netdev_alloc_skb_ip_align(netdev,
718 adapter->rx_ps_bsize0,
722 adapter->alloc_rx_buff_failed++;
726 buffer_info->skb = skb;
727 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
728 adapter->rx_ps_bsize0,
730 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
731 dev_err(&pdev->dev, "Rx DMA map failed\n");
732 adapter->rx_dma_failed++;
734 dev_kfree_skb_any(skb);
735 buffer_info->skb = NULL;
739 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
741 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
743 * Force memory writes to complete before letting h/w
744 * know there are new descriptors to fetch. (Only
745 * applicable for weak-ordered memory model archs,
749 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
750 e1000e_update_rdt_wa(adapter, i << 1);
753 adapter->hw.hw_addr + rx_ring->tail);
757 if (i == rx_ring->count)
759 buffer_info = &rx_ring->buffer_info[i];
763 rx_ring->next_to_use = i;
767 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
768 * @adapter: address of board private structure
769 * @cleaned_count: number of buffers to allocate this pass
772 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
773 int cleaned_count, gfp_t gfp)
775 struct net_device *netdev = adapter->netdev;
776 struct pci_dev *pdev = adapter->pdev;
777 union e1000_rx_desc_extended *rx_desc;
778 struct e1000_ring *rx_ring = adapter->rx_ring;
779 struct e1000_buffer *buffer_info;
782 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
784 i = rx_ring->next_to_use;
785 buffer_info = &rx_ring->buffer_info[i];
787 while (cleaned_count--) {
788 skb = buffer_info->skb;
794 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
795 if (unlikely(!skb)) {
796 /* Better luck next round */
797 adapter->alloc_rx_buff_failed++;
801 buffer_info->skb = skb;
803 /* allocate a new page if necessary */
804 if (!buffer_info->page) {
805 buffer_info->page = alloc_page(gfp);
806 if (unlikely(!buffer_info->page)) {
807 adapter->alloc_rx_buff_failed++;
812 if (!buffer_info->dma)
813 buffer_info->dma = dma_map_page(&pdev->dev,
814 buffer_info->page, 0,
818 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
819 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
821 if (unlikely(++i == rx_ring->count))
823 buffer_info = &rx_ring->buffer_info[i];
826 if (likely(rx_ring->next_to_use != i)) {
827 rx_ring->next_to_use = i;
828 if (unlikely(i-- == 0))
829 i = (rx_ring->count - 1);
831 /* Force memory writes to complete before letting h/w
832 * know there are new descriptors to fetch. (Only
833 * applicable for weak-ordered memory model archs,
836 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
837 e1000e_update_rdt_wa(adapter, i);
839 writel(i, adapter->hw.hw_addr + rx_ring->tail);
844 * e1000_clean_rx_irq - Send received data up the network stack; legacy
845 * @adapter: board private structure
847 * the return value indicates whether actual cleaning was done, there
848 * is no guarantee that everything was cleaned
850 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
851 int *work_done, int work_to_do)
853 struct net_device *netdev = adapter->netdev;
854 struct pci_dev *pdev = adapter->pdev;
855 struct e1000_hw *hw = &adapter->hw;
856 struct e1000_ring *rx_ring = adapter->rx_ring;
857 union e1000_rx_desc_extended *rx_desc, *next_rxd;
858 struct e1000_buffer *buffer_info, *next_buffer;
861 int cleaned_count = 0;
862 bool cleaned = false;
863 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
865 i = rx_ring->next_to_clean;
866 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
867 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
868 buffer_info = &rx_ring->buffer_info[i];
870 while (staterr & E1000_RXD_STAT_DD) {
873 if (*work_done >= work_to_do)
876 rmb(); /* read descriptor and rx_buffer_info after status DD */
878 skb = buffer_info->skb;
879 buffer_info->skb = NULL;
881 prefetch(skb->data - NET_IP_ALIGN);
884 if (i == rx_ring->count)
886 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
889 next_buffer = &rx_ring->buffer_info[i];
893 dma_unmap_single(&pdev->dev,
895 adapter->rx_buffer_len,
897 buffer_info->dma = 0;
899 length = le16_to_cpu(rx_desc->wb.upper.length);
902 * !EOP means multiple descriptors were used to store a single
903 * packet, if that's the case we need to toss it. In fact, we
904 * need to toss every packet with the EOP bit clear and the
905 * next frame that _does_ have the EOP bit set, as it is by
906 * definition only a frame fragment
908 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
909 adapter->flags2 |= FLAG2_IS_DISCARDING;
911 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
912 /* All receives must fit into a single buffer */
913 e_dbg("Receive packet consumed multiple buffers\n");
915 buffer_info->skb = skb;
916 if (staterr & E1000_RXD_STAT_EOP)
917 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
921 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
923 buffer_info->skb = skb;
927 /* adjust length to remove Ethernet CRC */
928 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
931 total_rx_bytes += length;
935 * code added for copybreak, this should improve
936 * performance for small packets with large amounts
937 * of reassembly being done in the stack
939 if (length < copybreak) {
940 struct sk_buff *new_skb =
941 netdev_alloc_skb_ip_align(netdev, length);
943 skb_copy_to_linear_data_offset(new_skb,
949 /* save the skb in buffer_info as good */
950 buffer_info->skb = skb;
953 /* else just continue with the old one */
955 /* end copybreak code */
956 skb_put(skb, length);
958 /* Receive Checksum Offload */
959 e1000_rx_checksum(adapter, staterr,
960 le16_to_cpu(rx_desc->wb.lower.hi_dword.
963 e1000_receive_skb(adapter, netdev, skb, staterr,
964 rx_desc->wb.upper.vlan);
967 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
969 /* return some buffers to hardware, one at a time is too slow */
970 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
971 adapter->alloc_rx_buf(adapter, cleaned_count,
976 /* use prefetched values */
978 buffer_info = next_buffer;
980 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
982 rx_ring->next_to_clean = i;
984 cleaned_count = e1000_desc_unused(rx_ring);
986 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
988 adapter->total_rx_bytes += total_rx_bytes;
989 adapter->total_rx_packets += total_rx_packets;
993 static void e1000_put_txbuf(struct e1000_adapter *adapter,
994 struct e1000_buffer *buffer_info)
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)) {
1031 /* May be block on write-back, flush and detect again
1032 * flush pending descriptor writebacks to memory
1034 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1035 /* execute the writes immediately */
1037 adapter->tx_hang_recheck = true;
1040 /* Real hang detected */
1041 adapter->tx_hang_recheck = false;
1042 netif_stop_queue(netdev);
1044 e1e_rphy(hw, PHY_STATUS, &phy_status);
1045 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1046 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1048 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1050 /* detected Hardware unit hang */
1051 e_err("Detected Hardware Unit Hang:\n"
1054 " next_to_use <%x>\n"
1055 " next_to_clean <%x>\n"
1056 "buffer_info[next_to_clean]:\n"
1057 " time_stamp <%lx>\n"
1058 " next_to_watch <%x>\n"
1060 " next_to_watch.status <%x>\n"
1063 "PHY 1000BASE-T Status <%x>\n"
1064 "PHY Extended Status <%x>\n"
1065 "PCI Status <%x>\n",
1066 readl(adapter->hw.hw_addr + tx_ring->head),
1067 readl(adapter->hw.hw_addr + tx_ring->tail),
1068 tx_ring->next_to_use,
1069 tx_ring->next_to_clean,
1070 tx_ring->buffer_info[eop].time_stamp,
1073 eop_desc->upper.fields.status,
1082 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1083 * @adapter: board private structure
1085 * the return value indicates whether actual cleaning was done, there
1086 * is no guarantee that everything was cleaned
1088 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
1090 struct net_device *netdev = adapter->netdev;
1091 struct e1000_hw *hw = &adapter->hw;
1092 struct e1000_ring *tx_ring = adapter->tx_ring;
1093 struct e1000_tx_desc *tx_desc, *eop_desc;
1094 struct e1000_buffer *buffer_info;
1095 unsigned int i, eop;
1096 unsigned int count = 0;
1097 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1098 unsigned int bytes_compl = 0, pkts_compl = 0;
1100 i = tx_ring->next_to_clean;
1101 eop = tx_ring->buffer_info[i].next_to_watch;
1102 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1104 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1105 (count < tx_ring->count)) {
1106 bool cleaned = false;
1107 rmb(); /* read buffer_info after eop_desc */
1108 for (; !cleaned; count++) {
1109 tx_desc = E1000_TX_DESC(*tx_ring, i);
1110 buffer_info = &tx_ring->buffer_info[i];
1111 cleaned = (i == eop);
1114 total_tx_packets += buffer_info->segs;
1115 total_tx_bytes += buffer_info->bytecount;
1116 if (buffer_info->skb) {
1117 bytes_compl += buffer_info->skb->len;
1122 e1000_put_txbuf(adapter, buffer_info);
1123 tx_desc->upper.data = 0;
1126 if (i == tx_ring->count)
1130 if (i == tx_ring->next_to_use)
1132 eop = tx_ring->buffer_info[i].next_to_watch;
1133 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1136 tx_ring->next_to_clean = i;
1138 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1140 #define TX_WAKE_THRESHOLD 32
1141 if (count && netif_carrier_ok(netdev) &&
1142 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
1143 /* Make sure that anybody stopping the queue after this
1144 * sees the new next_to_clean.
1148 if (netif_queue_stopped(netdev) &&
1149 !(test_bit(__E1000_DOWN, &adapter->state))) {
1150 netif_wake_queue(netdev);
1151 ++adapter->restart_queue;
1155 if (adapter->detect_tx_hung) {
1157 * Detect a transmit hang in hardware, this serializes the
1158 * check with the clearing of time_stamp and movement of i
1160 adapter->detect_tx_hung = false;
1161 if (tx_ring->buffer_info[i].time_stamp &&
1162 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
1163 + (adapter->tx_timeout_factor * HZ)) &&
1164 !(er32(STATUS) & E1000_STATUS_TXOFF))
1165 schedule_work(&adapter->print_hang_task);
1167 adapter->tx_hang_recheck = false;
1169 adapter->total_tx_bytes += total_tx_bytes;
1170 adapter->total_tx_packets += total_tx_packets;
1171 return count < tx_ring->count;
1175 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1176 * @adapter: board private structure
1178 * the return value indicates whether actual cleaning was done, there
1179 * is no guarantee that everything was cleaned
1181 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1182 int *work_done, int work_to_do)
1184 struct e1000_hw *hw = &adapter->hw;
1185 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1186 struct net_device *netdev = adapter->netdev;
1187 struct pci_dev *pdev = adapter->pdev;
1188 struct e1000_ring *rx_ring = adapter->rx_ring;
1189 struct e1000_buffer *buffer_info, *next_buffer;
1190 struct e1000_ps_page *ps_page;
1191 struct sk_buff *skb;
1193 u32 length, staterr;
1194 int cleaned_count = 0;
1195 bool cleaned = false;
1196 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1198 i = rx_ring->next_to_clean;
1199 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1200 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1201 buffer_info = &rx_ring->buffer_info[i];
1203 while (staterr & E1000_RXD_STAT_DD) {
1204 if (*work_done >= work_to_do)
1207 skb = buffer_info->skb;
1208 rmb(); /* read descriptor and rx_buffer_info after status DD */
1210 /* in the packet split case this is header only */
1211 prefetch(skb->data - NET_IP_ALIGN);
1214 if (i == rx_ring->count)
1216 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1219 next_buffer = &rx_ring->buffer_info[i];
1223 dma_unmap_single(&pdev->dev, buffer_info->dma,
1224 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
1225 buffer_info->dma = 0;
1227 /* see !EOP comment in other Rx routine */
1228 if (!(staterr & E1000_RXD_STAT_EOP))
1229 adapter->flags2 |= FLAG2_IS_DISCARDING;
1231 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
1232 e_dbg("Packet Split buffers didn't pick up the full packet\n");
1233 dev_kfree_skb_irq(skb);
1234 if (staterr & E1000_RXD_STAT_EOP)
1235 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1239 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1240 dev_kfree_skb_irq(skb);
1244 length = le16_to_cpu(rx_desc->wb.middle.length0);
1247 e_dbg("Last part of the packet spanning multiple descriptors\n");
1248 dev_kfree_skb_irq(skb);
1253 skb_put(skb, length);
1257 * this looks ugly, but it seems compiler issues make it
1258 * more efficient than reusing j
1260 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1263 * page alloc/put takes too long and effects small packet
1264 * throughput, so unsplit small packets and save the alloc/put
1265 * only valid in softirq (napi) context to call kmap_*
1267 if (l1 && (l1 <= copybreak) &&
1268 ((length + l1) <= adapter->rx_ps_bsize0)) {
1271 ps_page = &buffer_info->ps_pages[0];
1274 * there is no documentation about how to call
1275 * kmap_atomic, so we can't hold the mapping
1278 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1279 PAGE_SIZE, DMA_FROM_DEVICE);
1280 vaddr = kmap_atomic(ps_page->page);
1281 memcpy(skb_tail_pointer(skb), vaddr, l1);
1282 kunmap_atomic(vaddr);
1283 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1284 PAGE_SIZE, DMA_FROM_DEVICE);
1286 /* remove the CRC */
1287 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1295 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1296 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1300 ps_page = &buffer_info->ps_pages[j];
1301 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1304 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1305 ps_page->page = NULL;
1307 skb->data_len += length;
1308 skb->truesize += PAGE_SIZE;
1311 /* strip the ethernet crc, problem is we're using pages now so
1312 * this whole operation can get a little cpu intensive
1314 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1315 pskb_trim(skb, skb->len - 4);
1318 total_rx_bytes += skb->len;
1321 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1322 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1324 if (rx_desc->wb.upper.header_status &
1325 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1326 adapter->rx_hdr_split++;
1328 e1000_receive_skb(adapter, netdev, skb,
1329 staterr, rx_desc->wb.middle.vlan);
1332 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1333 buffer_info->skb = NULL;
1335 /* return some buffers to hardware, one at a time is too slow */
1336 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1337 adapter->alloc_rx_buf(adapter, cleaned_count,
1342 /* use prefetched values */
1344 buffer_info = next_buffer;
1346 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1348 rx_ring->next_to_clean = i;
1350 cleaned_count = e1000_desc_unused(rx_ring);
1352 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
1354 adapter->total_rx_bytes += total_rx_bytes;
1355 adapter->total_rx_packets += total_rx_packets;
1360 * e1000_consume_page - helper function
1362 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1367 skb->data_len += length;
1368 skb->truesize += PAGE_SIZE;
1372 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1373 * @adapter: board private structure
1375 * the return value indicates whether actual cleaning was done, there
1376 * is no guarantee that everything was cleaned
1379 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1380 int *work_done, int work_to_do)
1382 struct net_device *netdev = adapter->netdev;
1383 struct pci_dev *pdev = adapter->pdev;
1384 struct e1000_ring *rx_ring = adapter->rx_ring;
1385 union e1000_rx_desc_extended *rx_desc, *next_rxd;
1386 struct e1000_buffer *buffer_info, *next_buffer;
1387 u32 length, staterr;
1389 int cleaned_count = 0;
1390 bool cleaned = false;
1391 unsigned int total_rx_bytes=0, total_rx_packets=0;
1393 i = rx_ring->next_to_clean;
1394 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1395 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1396 buffer_info = &rx_ring->buffer_info[i];
1398 while (staterr & E1000_RXD_STAT_DD) {
1399 struct sk_buff *skb;
1401 if (*work_done >= work_to_do)
1404 rmb(); /* read descriptor and rx_buffer_info after status DD */
1406 skb = buffer_info->skb;
1407 buffer_info->skb = NULL;
1410 if (i == rx_ring->count)
1412 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
1415 next_buffer = &rx_ring->buffer_info[i];
1419 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1421 buffer_info->dma = 0;
1423 length = le16_to_cpu(rx_desc->wb.upper.length);
1425 /* errors is only valid for DD + EOP descriptors */
1426 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1427 (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
1428 /* recycle both page and skb */
1429 buffer_info->skb = skb;
1430 /* an error means any chain goes out the window too */
1431 if (rx_ring->rx_skb_top)
1432 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1433 rx_ring->rx_skb_top = NULL;
1437 #define rxtop (rx_ring->rx_skb_top)
1438 if (!(staterr & E1000_RXD_STAT_EOP)) {
1439 /* this descriptor is only the beginning (or middle) */
1441 /* this is the beginning of a chain */
1443 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1446 /* this is the middle of a chain */
1447 skb_fill_page_desc(rxtop,
1448 skb_shinfo(rxtop)->nr_frags,
1449 buffer_info->page, 0, length);
1450 /* re-use the skb, only consumed the page */
1451 buffer_info->skb = skb;
1453 e1000_consume_page(buffer_info, rxtop, length);
1457 /* end of the chain */
1458 skb_fill_page_desc(rxtop,
1459 skb_shinfo(rxtop)->nr_frags,
1460 buffer_info->page, 0, length);
1461 /* re-use the current skb, we only consumed the
1463 buffer_info->skb = skb;
1466 e1000_consume_page(buffer_info, skb, length);
1468 /* no chain, got EOP, this buf is the packet
1469 * copybreak to save the put_page/alloc_page */
1470 if (length <= copybreak &&
1471 skb_tailroom(skb) >= length) {
1473 vaddr = kmap_atomic(buffer_info->page);
1474 memcpy(skb_tail_pointer(skb), vaddr,
1476 kunmap_atomic(vaddr);
1477 /* re-use the page, so don't erase
1478 * buffer_info->page */
1479 skb_put(skb, length);
1481 skb_fill_page_desc(skb, 0,
1482 buffer_info->page, 0,
1484 e1000_consume_page(buffer_info, skb,
1490 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1491 e1000_rx_checksum(adapter, staterr,
1492 le16_to_cpu(rx_desc->wb.lower.hi_dword.
1493 csum_ip.csum), skb);
1495 /* probably a little skewed due to removing CRC */
1496 total_rx_bytes += skb->len;
1499 /* eth type trans needs skb->data to point to something */
1500 if (!pskb_may_pull(skb, ETH_HLEN)) {
1501 e_err("pskb_may_pull failed.\n");
1502 dev_kfree_skb_irq(skb);
1506 e1000_receive_skb(adapter, netdev, skb, staterr,
1507 rx_desc->wb.upper.vlan);
1510 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
1512 /* return some buffers to hardware, one at a time is too slow */
1513 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1514 adapter->alloc_rx_buf(adapter, cleaned_count,
1519 /* use prefetched values */
1521 buffer_info = next_buffer;
1523 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1525 rx_ring->next_to_clean = i;
1527 cleaned_count = e1000_desc_unused(rx_ring);
1529 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
1531 adapter->total_rx_bytes += total_rx_bytes;
1532 adapter->total_rx_packets += total_rx_packets;
1537 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1538 * @adapter: board private structure
1540 static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1542 struct e1000_ring *rx_ring = adapter->rx_ring;
1543 struct e1000_buffer *buffer_info;
1544 struct e1000_ps_page *ps_page;
1545 struct pci_dev *pdev = adapter->pdev;
1548 /* Free all the Rx ring sk_buffs */
1549 for (i = 0; i < rx_ring->count; i++) {
1550 buffer_info = &rx_ring->buffer_info[i];
1551 if (buffer_info->dma) {
1552 if (adapter->clean_rx == e1000_clean_rx_irq)
1553 dma_unmap_single(&pdev->dev, buffer_info->dma,
1554 adapter->rx_buffer_len,
1556 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1557 dma_unmap_page(&pdev->dev, buffer_info->dma,
1560 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1561 dma_unmap_single(&pdev->dev, buffer_info->dma,
1562 adapter->rx_ps_bsize0,
1564 buffer_info->dma = 0;
1567 if (buffer_info->page) {
1568 put_page(buffer_info->page);
1569 buffer_info->page = NULL;
1572 if (buffer_info->skb) {
1573 dev_kfree_skb(buffer_info->skb);
1574 buffer_info->skb = NULL;
1577 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1578 ps_page = &buffer_info->ps_pages[j];
1581 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1584 put_page(ps_page->page);
1585 ps_page->page = NULL;
1589 /* there also may be some cached data from a chained receive */
1590 if (rx_ring->rx_skb_top) {
1591 dev_kfree_skb(rx_ring->rx_skb_top);
1592 rx_ring->rx_skb_top = NULL;
1595 /* Zero out the descriptor ring */
1596 memset(rx_ring->desc, 0, rx_ring->size);
1598 rx_ring->next_to_clean = 0;
1599 rx_ring->next_to_use = 0;
1600 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1602 writel(0, adapter->hw.hw_addr + rx_ring->head);
1603 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1606 static void e1000e_downshift_workaround(struct work_struct *work)
1608 struct e1000_adapter *adapter = container_of(work,
1609 struct e1000_adapter, downshift_task);
1611 if (test_bit(__E1000_DOWN, &adapter->state))
1614 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1618 * e1000_intr_msi - Interrupt Handler
1619 * @irq: interrupt number
1620 * @data: pointer to a network interface device structure
1622 static irqreturn_t e1000_intr_msi(int irq, void *data)
1624 struct net_device *netdev = data;
1625 struct e1000_adapter *adapter = netdev_priv(netdev);
1626 struct e1000_hw *hw = &adapter->hw;
1627 u32 icr = er32(ICR);
1630 * read ICR disables interrupts using IAM
1633 if (icr & E1000_ICR_LSC) {
1634 hw->mac.get_link_status = 1;
1636 * ICH8 workaround-- Call gig speed drop workaround on cable
1637 * disconnect (LSC) before accessing any PHY registers
1639 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1640 (!(er32(STATUS) & E1000_STATUS_LU)))
1641 schedule_work(&adapter->downshift_task);
1644 * 80003ES2LAN workaround-- For packet buffer work-around on
1645 * link down event; disable receives here in the ISR and reset
1646 * adapter in watchdog
1648 if (netif_carrier_ok(netdev) &&
1649 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1650 /* disable receives */
1651 u32 rctl = er32(RCTL);
1652 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1653 adapter->flags |= FLAG_RX_RESTART_NOW;
1655 /* guard against interrupt when we're going down */
1656 if (!test_bit(__E1000_DOWN, &adapter->state))
1657 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1660 if (napi_schedule_prep(&adapter->napi)) {
1661 adapter->total_tx_bytes = 0;
1662 adapter->total_tx_packets = 0;
1663 adapter->total_rx_bytes = 0;
1664 adapter->total_rx_packets = 0;
1665 __napi_schedule(&adapter->napi);
1672 * e1000_intr - Interrupt Handler
1673 * @irq: interrupt number
1674 * @data: pointer to a network interface device structure
1676 static irqreturn_t e1000_intr(int irq, void *data)
1678 struct net_device *netdev = data;
1679 struct e1000_adapter *adapter = netdev_priv(netdev);
1680 struct e1000_hw *hw = &adapter->hw;
1681 u32 rctl, icr = er32(ICR);
1683 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
1684 return IRQ_NONE; /* Not our interrupt */
1687 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1688 * not set, then the adapter didn't send an interrupt
1690 if (!(icr & E1000_ICR_INT_ASSERTED))
1694 * Interrupt Auto-Mask...upon reading ICR,
1695 * interrupts are masked. No need for the
1699 if (icr & E1000_ICR_LSC) {
1700 hw->mac.get_link_status = 1;
1702 * ICH8 workaround-- Call gig speed drop workaround on cable
1703 * disconnect (LSC) before accessing any PHY registers
1705 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1706 (!(er32(STATUS) & E1000_STATUS_LU)))
1707 schedule_work(&adapter->downshift_task);
1710 * 80003ES2LAN workaround--
1711 * For packet buffer work-around on link down event;
1712 * disable receives here in the ISR and
1713 * reset adapter in watchdog
1715 if (netif_carrier_ok(netdev) &&
1716 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1717 /* disable receives */
1719 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1720 adapter->flags |= FLAG_RX_RESTART_NOW;
1722 /* guard against interrupt when we're going down */
1723 if (!test_bit(__E1000_DOWN, &adapter->state))
1724 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1727 if (napi_schedule_prep(&adapter->napi)) {
1728 adapter->total_tx_bytes = 0;
1729 adapter->total_tx_packets = 0;
1730 adapter->total_rx_bytes = 0;
1731 adapter->total_rx_packets = 0;
1732 __napi_schedule(&adapter->napi);
1738 static irqreturn_t e1000_msix_other(int irq, void *data)
1740 struct net_device *netdev = data;
1741 struct e1000_adapter *adapter = netdev_priv(netdev);
1742 struct e1000_hw *hw = &adapter->hw;
1743 u32 icr = er32(ICR);
1745 if (!(icr & E1000_ICR_INT_ASSERTED)) {
1746 if (!test_bit(__E1000_DOWN, &adapter->state))
1747 ew32(IMS, E1000_IMS_OTHER);
1751 if (icr & adapter->eiac_mask)
1752 ew32(ICS, (icr & adapter->eiac_mask));
1754 if (icr & E1000_ICR_OTHER) {
1755 if (!(icr & E1000_ICR_LSC))
1756 goto no_link_interrupt;
1757 hw->mac.get_link_status = 1;
1758 /* guard against interrupt when we're going down */
1759 if (!test_bit(__E1000_DOWN, &adapter->state))
1760 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1764 if (!test_bit(__E1000_DOWN, &adapter->state))
1765 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
1771 static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1773 struct net_device *netdev = data;
1774 struct e1000_adapter *adapter = netdev_priv(netdev);
1775 struct e1000_hw *hw = &adapter->hw;
1776 struct e1000_ring *tx_ring = adapter->tx_ring;
1779 adapter->total_tx_bytes = 0;
1780 adapter->total_tx_packets = 0;
1782 if (!e1000_clean_tx_irq(adapter))
1783 /* Ring was not completely cleaned, so fire another interrupt */
1784 ew32(ICS, tx_ring->ims_val);
1789 static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1791 struct net_device *netdev = data;
1792 struct e1000_adapter *adapter = netdev_priv(netdev);
1794 /* Write the ITR value calculated at the end of the
1795 * previous interrupt.
1797 if (adapter->rx_ring->set_itr) {
1798 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1799 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1800 adapter->rx_ring->set_itr = 0;
1803 if (napi_schedule_prep(&adapter->napi)) {
1804 adapter->total_rx_bytes = 0;
1805 adapter->total_rx_packets = 0;
1806 __napi_schedule(&adapter->napi);
1812 * e1000_configure_msix - Configure MSI-X hardware
1814 * e1000_configure_msix sets up the hardware to properly
1815 * generate MSI-X interrupts.
1817 static void e1000_configure_msix(struct e1000_adapter *adapter)
1819 struct e1000_hw *hw = &adapter->hw;
1820 struct e1000_ring *rx_ring = adapter->rx_ring;
1821 struct e1000_ring *tx_ring = adapter->tx_ring;
1823 u32 ctrl_ext, ivar = 0;
1825 adapter->eiac_mask = 0;
1827 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1828 if (hw->mac.type == e1000_82574) {
1829 u32 rfctl = er32(RFCTL);
1830 rfctl |= E1000_RFCTL_ACK_DIS;
1834 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1835 /* Configure Rx vector */
1836 rx_ring->ims_val = E1000_IMS_RXQ0;
1837 adapter->eiac_mask |= rx_ring->ims_val;
1838 if (rx_ring->itr_val)
1839 writel(1000000000 / (rx_ring->itr_val * 256),
1840 hw->hw_addr + rx_ring->itr_register);
1842 writel(1, hw->hw_addr + rx_ring->itr_register);
1843 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1845 /* Configure Tx vector */
1846 tx_ring->ims_val = E1000_IMS_TXQ0;
1848 if (tx_ring->itr_val)
1849 writel(1000000000 / (tx_ring->itr_val * 256),
1850 hw->hw_addr + tx_ring->itr_register);
1852 writel(1, hw->hw_addr + tx_ring->itr_register);
1853 adapter->eiac_mask |= tx_ring->ims_val;
1854 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1856 /* set vector for Other Causes, e.g. link changes */
1858 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1859 if (rx_ring->itr_val)
1860 writel(1000000000 / (rx_ring->itr_val * 256),
1861 hw->hw_addr + E1000_EITR_82574(vector));
1863 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1865 /* Cause Tx interrupts on every write back */
1870 /* enable MSI-X PBA support */
1871 ctrl_ext = er32(CTRL_EXT);
1872 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1874 /* Auto-Mask Other interrupts upon ICR read */
1875 #define E1000_EIAC_MASK_82574 0x01F00000
1876 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1877 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1878 ew32(CTRL_EXT, ctrl_ext);
1882 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1884 if (adapter->msix_entries) {
1885 pci_disable_msix(adapter->pdev);
1886 kfree(adapter->msix_entries);
1887 adapter->msix_entries = NULL;
1888 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1889 pci_disable_msi(adapter->pdev);
1890 adapter->flags &= ~FLAG_MSI_ENABLED;
1895 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1897 * Attempt to configure interrupts using the best available
1898 * capabilities of the hardware and kernel.
1900 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1905 switch (adapter->int_mode) {
1906 case E1000E_INT_MODE_MSIX:
1907 if (adapter->flags & FLAG_HAS_MSIX) {
1908 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1909 adapter->msix_entries = kcalloc(adapter->num_vectors,
1910 sizeof(struct msix_entry),
1912 if (adapter->msix_entries) {
1913 for (i = 0; i < adapter->num_vectors; i++)
1914 adapter->msix_entries[i].entry = i;
1916 err = pci_enable_msix(adapter->pdev,
1917 adapter->msix_entries,
1918 adapter->num_vectors);
1922 /* MSI-X failed, so fall through and try MSI */
1923 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
1924 e1000e_reset_interrupt_capability(adapter);
1926 adapter->int_mode = E1000E_INT_MODE_MSI;
1928 case E1000E_INT_MODE_MSI:
1929 if (!pci_enable_msi(adapter->pdev)) {
1930 adapter->flags |= FLAG_MSI_ENABLED;
1932 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1933 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
1936 case E1000E_INT_MODE_LEGACY:
1937 /* Don't do anything; this is the system default */
1941 /* store the number of vectors being used */
1942 adapter->num_vectors = 1;
1946 * e1000_request_msix - Initialize MSI-X interrupts
1948 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1951 static int e1000_request_msix(struct e1000_adapter *adapter)
1953 struct net_device *netdev = adapter->netdev;
1954 int err = 0, vector = 0;
1956 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1957 snprintf(adapter->rx_ring->name,
1958 sizeof(adapter->rx_ring->name) - 1,
1959 "%s-rx-0", netdev->name);
1961 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1962 err = request_irq(adapter->msix_entries[vector].vector,
1963 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
1967 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1968 adapter->rx_ring->itr_val = adapter->itr;
1971 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1972 snprintf(adapter->tx_ring->name,
1973 sizeof(adapter->tx_ring->name) - 1,
1974 "%s-tx-0", netdev->name);
1976 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1977 err = request_irq(adapter->msix_entries[vector].vector,
1978 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
1982 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1983 adapter->tx_ring->itr_val = adapter->itr;
1986 err = request_irq(adapter->msix_entries[vector].vector,
1987 e1000_msix_other, 0, netdev->name, netdev);
1991 e1000_configure_msix(adapter);
1998 * e1000_request_irq - initialize interrupts
2000 * Attempts to configure interrupts using the best available
2001 * capabilities of the hardware and kernel.
2003 static int e1000_request_irq(struct e1000_adapter *adapter)
2005 struct net_device *netdev = adapter->netdev;
2008 if (adapter->msix_entries) {
2009 err = e1000_request_msix(adapter);
2012 /* fall back to MSI */
2013 e1000e_reset_interrupt_capability(adapter);
2014 adapter->int_mode = E1000E_INT_MODE_MSI;
2015 e1000e_set_interrupt_capability(adapter);
2017 if (adapter->flags & FLAG_MSI_ENABLED) {
2018 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
2019 netdev->name, netdev);
2023 /* fall back to legacy interrupt */
2024 e1000e_reset_interrupt_capability(adapter);
2025 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2028 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
2029 netdev->name, netdev);
2031 e_err("Unable to allocate interrupt, Error: %d\n", err);
2036 static void e1000_free_irq(struct e1000_adapter *adapter)
2038 struct net_device *netdev = adapter->netdev;
2040 if (adapter->msix_entries) {
2043 free_irq(adapter->msix_entries[vector].vector, netdev);
2046 free_irq(adapter->msix_entries[vector].vector, netdev);
2049 /* Other Causes interrupt vector */
2050 free_irq(adapter->msix_entries[vector].vector, netdev);
2054 free_irq(adapter->pdev->irq, netdev);
2058 * e1000_irq_disable - Mask off interrupt generation on the NIC
2060 static void e1000_irq_disable(struct e1000_adapter *adapter)
2062 struct e1000_hw *hw = &adapter->hw;
2065 if (adapter->msix_entries)
2066 ew32(EIAC_82574, 0);
2069 if (adapter->msix_entries) {
2071 for (i = 0; i < adapter->num_vectors; i++)
2072 synchronize_irq(adapter->msix_entries[i].vector);
2074 synchronize_irq(adapter->pdev->irq);
2079 * e1000_irq_enable - Enable default interrupt generation settings
2081 static void e1000_irq_enable(struct e1000_adapter *adapter)
2083 struct e1000_hw *hw = &adapter->hw;
2085 if (adapter->msix_entries) {
2086 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2087 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2089 ew32(IMS, IMS_ENABLE_MASK);
2095 * e1000e_get_hw_control - get control of the h/w from f/w
2096 * @adapter: address of board private structure
2098 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2099 * For ASF and Pass Through versions of f/w this means that
2100 * the driver is loaded. For AMT version (only with 82573)
2101 * of the f/w this means that the network i/f is open.
2103 void e1000e_get_hw_control(struct e1000_adapter *adapter)
2105 struct e1000_hw *hw = &adapter->hw;
2109 /* Let firmware know the driver has taken over */
2110 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2112 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2113 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2114 ctrl_ext = er32(CTRL_EXT);
2115 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2120 * e1000e_release_hw_control - release control of the h/w to f/w
2121 * @adapter: address of board private structure
2123 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2124 * For ASF and Pass Through versions of f/w this means that the
2125 * driver is no longer loaded. For AMT version (only with 82573) i
2126 * of the f/w this means that the network i/f is closed.
2129 void e1000e_release_hw_control(struct e1000_adapter *adapter)
2131 struct e1000_hw *hw = &adapter->hw;
2135 /* Let firmware taken over control of h/w */
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 * @e1000_alloc_ring - allocate memory for a ring structure
2148 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2149 struct e1000_ring *ring)
2151 struct pci_dev *pdev = adapter->pdev;
2153 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2162 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2163 * @adapter: board private structure
2165 * Return 0 on success, negative on failure
2167 int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2169 struct e1000_ring *tx_ring = adapter->tx_ring;
2170 int err = -ENOMEM, size;
2172 size = sizeof(struct e1000_buffer) * tx_ring->count;
2173 tx_ring->buffer_info = vzalloc(size);
2174 if (!tx_ring->buffer_info)
2177 /* round up to nearest 4K */
2178 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2179 tx_ring->size = ALIGN(tx_ring->size, 4096);
2181 err = e1000_alloc_ring_dma(adapter, tx_ring);
2185 tx_ring->next_to_use = 0;
2186 tx_ring->next_to_clean = 0;
2190 vfree(tx_ring->buffer_info);
2191 e_err("Unable to allocate memory for the transmit descriptor ring\n");
2196 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2197 * @adapter: board private structure
2199 * Returns 0 on success, negative on failure
2201 int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2203 struct e1000_ring *rx_ring = adapter->rx_ring;
2204 struct e1000_buffer *buffer_info;
2205 int i, size, desc_len, err = -ENOMEM;
2207 size = sizeof(struct e1000_buffer) * rx_ring->count;
2208 rx_ring->buffer_info = vzalloc(size);
2209 if (!rx_ring->buffer_info)
2212 for (i = 0; i < rx_ring->count; i++) {
2213 buffer_info = &rx_ring->buffer_info[i];
2214 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2215 sizeof(struct e1000_ps_page),
2217 if (!buffer_info->ps_pages)
2221 desc_len = sizeof(union e1000_rx_desc_packet_split);
2223 /* Round up to nearest 4K */
2224 rx_ring->size = rx_ring->count * desc_len;
2225 rx_ring->size = ALIGN(rx_ring->size, 4096);
2227 err = e1000_alloc_ring_dma(adapter, rx_ring);
2231 rx_ring->next_to_clean = 0;
2232 rx_ring->next_to_use = 0;
2233 rx_ring->rx_skb_top = NULL;
2238 for (i = 0; i < rx_ring->count; i++) {
2239 buffer_info = &rx_ring->buffer_info[i];
2240 kfree(buffer_info->ps_pages);
2243 vfree(rx_ring->buffer_info);
2244 e_err("Unable to allocate memory for the receive descriptor ring\n");
2249 * e1000_clean_tx_ring - Free Tx Buffers
2250 * @adapter: board private structure
2252 static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2254 struct e1000_ring *tx_ring = adapter->tx_ring;
2255 struct e1000_buffer *buffer_info;
2259 for (i = 0; i < tx_ring->count; i++) {
2260 buffer_info = &tx_ring->buffer_info[i];
2261 e1000_put_txbuf(adapter, buffer_info);
2264 netdev_reset_queue(adapter->netdev);
2265 size = sizeof(struct e1000_buffer) * tx_ring->count;
2266 memset(tx_ring->buffer_info, 0, size);
2268 memset(tx_ring->desc, 0, tx_ring->size);
2270 tx_ring->next_to_use = 0;
2271 tx_ring->next_to_clean = 0;
2273 writel(0, adapter->hw.hw_addr + tx_ring->head);
2274 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2278 * e1000e_free_tx_resources - Free Tx Resources per Queue
2279 * @adapter: board private structure
2281 * Free all transmit software resources
2283 void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2285 struct pci_dev *pdev = adapter->pdev;
2286 struct e1000_ring *tx_ring = adapter->tx_ring;
2288 e1000_clean_tx_ring(adapter);
2290 vfree(tx_ring->buffer_info);
2291 tx_ring->buffer_info = NULL;
2293 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2295 tx_ring->desc = NULL;
2299 * e1000e_free_rx_resources - Free Rx Resources
2300 * @adapter: board private structure
2302 * Free all receive software resources
2305 void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2307 struct pci_dev *pdev = adapter->pdev;
2308 struct e1000_ring *rx_ring = adapter->rx_ring;
2311 e1000_clean_rx_ring(adapter);
2313 for (i = 0; i < rx_ring->count; i++)
2314 kfree(rx_ring->buffer_info[i].ps_pages);
2316 vfree(rx_ring->buffer_info);
2317 rx_ring->buffer_info = NULL;
2319 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2321 rx_ring->desc = NULL;
2325 * e1000_update_itr - update the dynamic ITR value based on statistics
2326 * @adapter: pointer to adapter
2327 * @itr_setting: current adapter->itr
2328 * @packets: the number of packets during this measurement interval
2329 * @bytes: the number of bytes during this measurement interval
2331 * Stores a new ITR value based on packets and byte
2332 * counts during the last interrupt. The advantage of per interrupt
2333 * computation is faster updates and more accurate ITR for the current
2334 * traffic pattern. Constants in this function were computed
2335 * based on theoretical maximum wire speed and thresholds were set based
2336 * on testing data as well as attempting to minimize response time
2337 * while increasing bulk throughput. This functionality is controlled
2338 * by the InterruptThrottleRate module parameter.
2340 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2341 u16 itr_setting, int packets,
2344 unsigned int retval = itr_setting;
2347 goto update_itr_done;
2349 switch (itr_setting) {
2350 case lowest_latency:
2351 /* handle TSO and jumbo frames */
2352 if (bytes/packets > 8000)
2353 retval = bulk_latency;
2354 else if ((packets < 5) && (bytes > 512))
2355 retval = low_latency;
2357 case low_latency: /* 50 usec aka 20000 ints/s */
2358 if (bytes > 10000) {
2359 /* this if handles the TSO accounting */
2360 if (bytes/packets > 8000)
2361 retval = bulk_latency;
2362 else if ((packets < 10) || ((bytes/packets) > 1200))
2363 retval = bulk_latency;
2364 else if ((packets > 35))
2365 retval = lowest_latency;
2366 } else if (bytes/packets > 2000) {
2367 retval = bulk_latency;
2368 } else if (packets <= 2 && bytes < 512) {
2369 retval = lowest_latency;
2372 case bulk_latency: /* 250 usec aka 4000 ints/s */
2373 if (bytes > 25000) {
2375 retval = low_latency;
2376 } else if (bytes < 6000) {
2377 retval = low_latency;
2386 static void e1000_set_itr(struct e1000_adapter *adapter)
2388 struct e1000_hw *hw = &adapter->hw;
2390 u32 new_itr = adapter->itr;
2392 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2393 if (adapter->link_speed != SPEED_1000) {
2399 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2404 adapter->tx_itr = e1000_update_itr(adapter,
2406 adapter->total_tx_packets,
2407 adapter->total_tx_bytes);
2408 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2409 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2410 adapter->tx_itr = low_latency;
2412 adapter->rx_itr = e1000_update_itr(adapter,
2414 adapter->total_rx_packets,
2415 adapter->total_rx_bytes);
2416 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2417 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2418 adapter->rx_itr = low_latency;
2420 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2422 switch (current_itr) {
2423 /* counts and packets in update_itr are dependent on these numbers */
2424 case lowest_latency:
2428 new_itr = 20000; /* aka hwitr = ~200 */
2438 if (new_itr != adapter->itr) {
2440 * this attempts to bias the interrupt rate towards Bulk
2441 * by adding intermediate steps when interrupt rate is
2444 new_itr = new_itr > adapter->itr ?
2445 min(adapter->itr + (new_itr >> 2), new_itr) :
2447 adapter->itr = new_itr;
2448 adapter->rx_ring->itr_val = new_itr;
2449 if (adapter->msix_entries)
2450 adapter->rx_ring->set_itr = 1;
2453 ew32(ITR, 1000000000 / (new_itr * 256));
2460 * e1000_alloc_queues - Allocate memory for all rings
2461 * @adapter: board private structure to initialize
2463 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2465 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2466 if (!adapter->tx_ring)
2469 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2470 if (!adapter->rx_ring)
2475 e_err("Unable to allocate memory for queues\n");
2476 kfree(adapter->rx_ring);
2477 kfree(adapter->tx_ring);
2482 * e1000_clean - NAPI Rx polling callback
2483 * @napi: struct associated with this polling callback
2484 * @budget: amount of packets driver is allowed to process this poll
2486 static int e1000_clean(struct napi_struct *napi, int budget)
2488 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
2489 struct e1000_hw *hw = &adapter->hw;
2490 struct net_device *poll_dev = adapter->netdev;
2491 int tx_cleaned = 1, work_done = 0;
2493 adapter = netdev_priv(poll_dev);
2495 if (adapter->msix_entries &&
2496 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2499 tx_cleaned = e1000_clean_tx_irq(adapter);
2502 adapter->clean_rx(adapter, &work_done, budget);
2507 /* If budget not fully consumed, exit the polling mode */
2508 if (work_done < budget) {
2509 if (adapter->itr_setting & 3)
2510 e1000_set_itr(adapter);
2511 napi_complete(napi);
2512 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2513 if (adapter->msix_entries)
2514 ew32(IMS, adapter->rx_ring->ims_val);
2516 e1000_irq_enable(adapter);
2523 static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2525 struct e1000_adapter *adapter = netdev_priv(netdev);
2526 struct e1000_hw *hw = &adapter->hw;
2529 /* don't update vlan cookie if already programmed */
2530 if ((adapter->hw.mng_cookie.status &
2531 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2532 (vid == adapter->mng_vlan_id))
2535 /* add VID to filter table */
2536 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2537 index = (vid >> 5) & 0x7F;
2538 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2539 vfta |= (1 << (vid & 0x1F));
2540 hw->mac.ops.write_vfta(hw, index, vfta);
2543 set_bit(vid, adapter->active_vlans);
2548 static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2550 struct e1000_adapter *adapter = netdev_priv(netdev);
2551 struct e1000_hw *hw = &adapter->hw;
2554 if ((adapter->hw.mng_cookie.status &
2555 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2556 (vid == adapter->mng_vlan_id)) {
2557 /* release control to f/w */
2558 e1000e_release_hw_control(adapter);
2562 /* remove VID from filter table */
2563 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2564 index = (vid >> 5) & 0x7F;
2565 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2566 vfta &= ~(1 << (vid & 0x1F));
2567 hw->mac.ops.write_vfta(hw, index, vfta);
2570 clear_bit(vid, adapter->active_vlans);
2576 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2577 * @adapter: board private structure to initialize
2579 static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2581 struct net_device *netdev = adapter->netdev;
2582 struct e1000_hw *hw = &adapter->hw;
2585 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2586 /* disable VLAN receive filtering */
2588 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2591 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2592 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2593 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2599 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2600 * @adapter: board private structure to initialize
2602 static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2604 struct e1000_hw *hw = &adapter->hw;
2607 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2608 /* enable VLAN receive filtering */
2610 rctl |= E1000_RCTL_VFE;
2611 rctl &= ~E1000_RCTL_CFIEN;
2617 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2618 * @adapter: board private structure to initialize
2620 static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2622 struct e1000_hw *hw = &adapter->hw;
2625 /* disable VLAN tag insert/strip */
2627 ctrl &= ~E1000_CTRL_VME;
2632 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2633 * @adapter: board private structure to initialize
2635 static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2637 struct e1000_hw *hw = &adapter->hw;
2640 /* enable VLAN tag insert/strip */
2642 ctrl |= E1000_CTRL_VME;
2646 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2648 struct net_device *netdev = adapter->netdev;
2649 u16 vid = adapter->hw.mng_cookie.vlan_id;
2650 u16 old_vid = adapter->mng_vlan_id;
2652 if (adapter->hw.mng_cookie.status &
2653 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2654 e1000_vlan_rx_add_vid(netdev, vid);
2655 adapter->mng_vlan_id = vid;
2658 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2659 e1000_vlan_rx_kill_vid(netdev, old_vid);
2662 static void e1000_restore_vlan(struct e1000_adapter *adapter)
2666 e1000_vlan_rx_add_vid(adapter->netdev, 0);
2668 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
2669 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2672 static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
2674 struct e1000_hw *hw = &adapter->hw;
2675 u32 manc, manc2h, mdef, i, j;
2677 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2683 * enable receiving management packets to the host. this will probably
2684 * generate destination unreachable messages from the host OS, but
2685 * the packets will be handled on SMBUS
2687 manc |= E1000_MANC_EN_MNG2HOST;
2688 manc2h = er32(MANC2H);
2690 switch (hw->mac.type) {
2692 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2697 * Check if IPMI pass-through decision filter already exists;
2700 for (i = 0, j = 0; i < 8; i++) {
2701 mdef = er32(MDEF(i));
2703 /* Ignore filters with anything other than IPMI ports */
2704 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2707 /* Enable this decision filter in MANC2H */
2714 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2717 /* Create new decision filter in an empty filter */
2718 for (i = 0, j = 0; i < 8; i++)
2719 if (er32(MDEF(i)) == 0) {
2720 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2721 E1000_MDEF_PORT_664));
2728 e_warn("Unable to create IPMI pass-through filter\n");
2732 ew32(MANC2H, manc2h);
2737 * e1000_configure_tx - Configure Transmit Unit after Reset
2738 * @adapter: board private structure
2740 * Configure the Tx unit of the MAC after a reset.
2742 static void e1000_configure_tx(struct e1000_adapter *adapter)
2744 struct e1000_hw *hw = &adapter->hw;
2745 struct e1000_ring *tx_ring = adapter->tx_ring;
2747 u32 tdlen, tctl, tipg, tarc;
2750 /* Setup the HW Tx Head and Tail descriptor pointers */
2751 tdba = tx_ring->dma;
2752 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2753 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
2754 ew32(TDBAH, (tdba >> 32));
2758 tx_ring->head = E1000_TDH;
2759 tx_ring->tail = E1000_TDT;
2761 /* Set the default values for the Tx Inter Packet Gap timer */
2762 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2763 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2764 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2766 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2767 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2769 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2770 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2773 /* Set the Tx Interrupt Delay register */
2774 ew32(TIDV, adapter->tx_int_delay);
2775 /* Tx irq moderation */
2776 ew32(TADV, adapter->tx_abs_int_delay);
2778 if (adapter->flags2 & FLAG2_DMA_BURST) {
2779 u32 txdctl = er32(TXDCTL(0));
2780 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2781 E1000_TXDCTL_WTHRESH);
2783 * set up some performance related parameters to encourage the
2784 * hardware to use the bus more efficiently in bursts, depends
2785 * on the tx_int_delay to be enabled,
2786 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2787 * hthresh = 1 ==> prefetch when one or more available
2788 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2789 * BEWARE: this seems to work but should be considered first if
2790 * there are Tx hangs or other Tx related bugs
2792 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2793 ew32(TXDCTL(0), txdctl);
2794 /* erratum work around: set txdctl the same for both queues */
2795 ew32(TXDCTL(1), txdctl);
2798 /* Program the Transmit Control Register */
2800 tctl &= ~E1000_TCTL_CT;
2801 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2802 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2804 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
2805 tarc = er32(TARC(0));
2807 * set the speed mode bit, we'll clear it if we're not at
2808 * gigabit link later
2810 #define SPEED_MODE_BIT (1 << 21)
2811 tarc |= SPEED_MODE_BIT;
2812 ew32(TARC(0), tarc);
2815 /* errata: program both queues to unweighted RR */
2816 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
2817 tarc = er32(TARC(0));
2819 ew32(TARC(0), tarc);
2820 tarc = er32(TARC(1));
2822 ew32(TARC(1), tarc);
2825 /* Setup Transmit Descriptor Settings for eop descriptor */
2826 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2828 /* only set IDE if we are delaying interrupts using the timers */
2829 if (adapter->tx_int_delay)
2830 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2832 /* enable Report Status bit */
2833 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2837 e1000e_config_collision_dist(hw);
2841 * e1000_setup_rctl - configure the receive control registers
2842 * @adapter: Board private structure
2844 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2845 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2846 static void e1000_setup_rctl(struct e1000_adapter *adapter)
2848 struct e1000_hw *hw = &adapter->hw;
2852 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2853 if (hw->mac.type == e1000_pch2lan) {
2856 if (adapter->netdev->mtu > ETH_DATA_LEN)
2857 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2859 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
2862 e_dbg("failed to enable jumbo frame workaround mode\n");
2865 /* Program MC offset vector base */
2867 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2868 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2869 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2870 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2872 /* Do not Store bad packets */
2873 rctl &= ~E1000_RCTL_SBP;
2875 /* Enable Long Packet receive */
2876 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2877 rctl &= ~E1000_RCTL_LPE;
2879 rctl |= E1000_RCTL_LPE;
2881 /* Some systems expect that the CRC is included in SMBUS traffic. The
2882 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2883 * host memory when this is enabled
2885 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2886 rctl |= E1000_RCTL_SECRC;
2888 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2889 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2892 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2894 phy_data |= (1 << 2);
2895 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2897 e1e_rphy(hw, 22, &phy_data);
2899 phy_data |= (1 << 14);
2900 e1e_wphy(hw, 0x10, 0x2823);
2901 e1e_wphy(hw, 0x11, 0x0003);
2902 e1e_wphy(hw, 22, phy_data);
2905 /* Setup buffer sizes */
2906 rctl &= ~E1000_RCTL_SZ_4096;
2907 rctl |= E1000_RCTL_BSEX;
2908 switch (adapter->rx_buffer_len) {
2911 rctl |= E1000_RCTL_SZ_2048;
2912 rctl &= ~E1000_RCTL_BSEX;
2915 rctl |= E1000_RCTL_SZ_4096;
2918 rctl |= E1000_RCTL_SZ_8192;
2921 rctl |= E1000_RCTL_SZ_16384;
2925 /* Enable Extended Status in all Receive Descriptors */
2926 rfctl = er32(RFCTL);
2927 rfctl |= E1000_RFCTL_EXTEN;
2930 * 82571 and greater support packet-split where the protocol
2931 * header is placed in skb->data and the packet data is
2932 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2933 * In the case of a non-split, skb->data is linearly filled,
2934 * followed by the page buffers. Therefore, skb->data is
2935 * sized to hold the largest protocol header.
2937 * allocations using alloc_page take too long for regular MTU
2938 * so only enable packet split for jumbo frames
2940 * Using pages when the page size is greater than 16k wastes
2941 * a lot of memory, since we allocate 3 pages at all times
2944 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2945 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
2946 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
2947 adapter->rx_ps_pages = pages;
2949 adapter->rx_ps_pages = 0;
2951 if (adapter->rx_ps_pages) {
2955 * disable packet split support for IPv6 extension headers,
2956 * because some malformed IPv6 headers can hang the Rx
2958 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2959 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2961 /* Enable Packet split descriptors */
2962 rctl |= E1000_RCTL_DTYP_PS;
2964 psrctl |= adapter->rx_ps_bsize0 >>
2965 E1000_PSRCTL_BSIZE0_SHIFT;
2967 switch (adapter->rx_ps_pages) {
2969 psrctl |= PAGE_SIZE <<
2970 E1000_PSRCTL_BSIZE3_SHIFT;
2972 psrctl |= PAGE_SIZE <<
2973 E1000_PSRCTL_BSIZE2_SHIFT;
2975 psrctl |= PAGE_SIZE >>
2976 E1000_PSRCTL_BSIZE1_SHIFT;
2980 ew32(PSRCTL, psrctl);
2985 /* just started the receive unit, no need to restart */
2986 adapter->flags &= ~FLAG_RX_RESTART_NOW;
2990 * e1000_configure_rx - Configure Receive Unit after Reset
2991 * @adapter: board private structure
2993 * Configure the Rx unit of the MAC after a reset.
2995 static void e1000_configure_rx(struct e1000_adapter *adapter)
2997 struct e1000_hw *hw = &adapter->hw;
2998 struct e1000_ring *rx_ring = adapter->rx_ring;
3000 u32 rdlen, rctl, rxcsum, ctrl_ext;
3002 if (adapter->rx_ps_pages) {
3003 /* this is a 32 byte descriptor */
3004 rdlen = rx_ring->count *
3005 sizeof(union e1000_rx_desc_packet_split);
3006 adapter->clean_rx = e1000_clean_rx_irq_ps;
3007 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
3008 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
3009 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3010 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3011 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
3013 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3014 adapter->clean_rx = e1000_clean_rx_irq;
3015 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3018 /* disable receives while setting up the descriptors */
3020 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3021 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3023 usleep_range(10000, 20000);
3025 if (adapter->flags2 & FLAG2_DMA_BURST) {
3027 * set the writeback threshold (only takes effect if the RDTR
3028 * is set). set GRAN=1 and write back up to 0x4 worth, and
3029 * enable prefetching of 0x20 Rx descriptors
3035 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3036 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3039 * override the delay timers for enabling bursting, only if
3040 * the value was not set by the user via module options
3042 if (adapter->rx_int_delay == DEFAULT_RDTR)
3043 adapter->rx_int_delay = BURST_RDTR;
3044 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3045 adapter->rx_abs_int_delay = BURST_RADV;
3048 /* set the Receive Delay Timer Register */
3049 ew32(RDTR, adapter->rx_int_delay);
3051 /* irq moderation */
3052 ew32(RADV, adapter->rx_abs_int_delay);
3053 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
3054 ew32(ITR, 1000000000 / (adapter->itr * 256));
3056 ctrl_ext = er32(CTRL_EXT);
3057 /* Auto-Mask interrupts upon ICR access */
3058 ctrl_ext |= E1000_CTRL_EXT_IAME;
3059 ew32(IAM, 0xffffffff);
3060 ew32(CTRL_EXT, ctrl_ext);
3064 * Setup the HW Rx Head and Tail Descriptor Pointers and
3065 * the Base and Length of the Rx Descriptor Ring
3067 rdba = rx_ring->dma;
3068 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
3069 ew32(RDBAH, (rdba >> 32));
3073 rx_ring->head = E1000_RDH;
3074 rx_ring->tail = E1000_RDT;
3076 /* Enable Receive Checksum Offload for TCP and UDP */
3077 rxcsum = er32(RXCSUM);
3078 if (adapter->netdev->features & NETIF_F_RXCSUM) {
3079 rxcsum |= E1000_RXCSUM_TUOFL;
3082 * IPv4 payload checksum for UDP fragments must be
3083 * used in conjunction with packet-split.
3085 if (adapter->rx_ps_pages)
3086 rxcsum |= E1000_RXCSUM_IPPCSE;
3088 rxcsum &= ~E1000_RXCSUM_TUOFL;
3089 /* no need to clear IPPCSE as it defaults to 0 */
3091 ew32(RXCSUM, rxcsum);
3094 * Enable early receives on supported devices, only takes effect when
3095 * packet size is equal or larger than the specified value (in 8 byte
3096 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
3098 if ((adapter->flags & FLAG_HAS_ERT) ||
3099 (adapter->hw.mac.type == e1000_pch2lan)) {
3100 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3101 u32 rxdctl = er32(RXDCTL(0));
3102 ew32(RXDCTL(0), rxdctl | 0x3);
3103 if (adapter->flags & FLAG_HAS_ERT)
3104 ew32(ERT, E1000_ERT_2048 | (1 << 13));
3106 * With jumbo frames and early-receive enabled,
3107 * excessive C-state transition latencies result in
3108 * dropped transactions.
3110 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
3112 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3113 PM_QOS_DEFAULT_VALUE);
3117 /* Enable Receives */
3122 * e1000e_write_mc_addr_list - write multicast addresses to MTA
3123 * @netdev: network interface device structure
3125 * Writes multicast address list to the MTA hash table.
3126 * Returns: -ENOMEM on failure
3127 * 0 on no addresses written
3128 * X on writing X addresses to MTA
3130 static int e1000e_write_mc_addr_list(struct net_device *netdev)
3132 struct e1000_adapter *adapter = netdev_priv(netdev);
3133 struct e1000_hw *hw = &adapter->hw;
3134 struct netdev_hw_addr *ha;
3138 if (netdev_mc_empty(netdev)) {
3139 /* nothing to program, so clear mc list */
3140 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3144 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3148 /* update_mc_addr_list expects a packed array of only addresses. */
3150 netdev_for_each_mc_addr(ha, netdev)
3151 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3153 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3156 return netdev_mc_count(netdev);
3160 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3161 * @netdev: network interface device structure
3163 * Writes unicast address list to the RAR table.
3164 * Returns: -ENOMEM on failure/insufficient address space
3165 * 0 on no addresses written
3166 * X on writing X addresses to the RAR table
3168 static int e1000e_write_uc_addr_list(struct net_device *netdev)
3170 struct e1000_adapter *adapter = netdev_priv(netdev);
3171 struct e1000_hw *hw = &adapter->hw;
3172 unsigned int rar_entries = hw->mac.rar_entry_count;
3175 /* save a rar entry for our hardware address */
3178 /* save a rar entry for the LAA workaround */
3179 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3182 /* return ENOMEM indicating insufficient memory for addresses */
3183 if (netdev_uc_count(netdev) > rar_entries)
3186 if (!netdev_uc_empty(netdev) && rar_entries) {
3187 struct netdev_hw_addr *ha;
3190 * write the addresses in reverse order to avoid write
3193 netdev_for_each_uc_addr(ha, netdev) {
3196 e1000e_rar_set(hw, ha->addr, rar_entries--);
3201 /* zero out the remaining RAR entries not used above */
3202 for (; rar_entries > 0; rar_entries--) {
3203 ew32(RAH(rar_entries), 0);
3204 ew32(RAL(rar_entries), 0);
3212 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3213 * @netdev: network interface device structure
3215 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3216 * address list or the network interface flags are updated. This routine is
3217 * responsible for configuring the hardware for proper unicast, multicast,
3218 * promiscuous mode, and all-multi behavior.
3220 static void e1000e_set_rx_mode(struct net_device *netdev)
3222 struct e1000_adapter *adapter = netdev_priv(netdev);
3223 struct e1000_hw *hw = &adapter->hw;
3226 /* Check for Promiscuous and All Multicast modes */
3229 /* clear the affected bits */
3230 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3232 if (netdev->flags & IFF_PROMISC) {
3233 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
3234 /* Do not hardware filter VLANs in promisc mode */
3235 e1000e_vlan_filter_disable(adapter);
3238 if (netdev->flags & IFF_ALLMULTI) {
3239 rctl |= E1000_RCTL_MPE;
3242 * Write addresses to the MTA, if the attempt fails
3243 * then we should just turn on promiscuous mode so
3244 * that we can at least receive multicast traffic
3246 count = e1000e_write_mc_addr_list(netdev);
3248 rctl |= E1000_RCTL_MPE;
3250 e1000e_vlan_filter_enable(adapter);
3252 * Write addresses to available RAR registers, if there is not
3253 * sufficient space to store all the addresses then enable
3254 * unicast promiscuous mode
3256 count = e1000e_write_uc_addr_list(netdev);
3258 rctl |= E1000_RCTL_UPE;
3263 if (netdev->features & NETIF_F_HW_VLAN_RX)
3264 e1000e_vlan_strip_enable(adapter);
3266 e1000e_vlan_strip_disable(adapter);
3270 * e1000_configure - configure the hardware for Rx and Tx
3271 * @adapter: private board structure
3273 static void e1000_configure(struct e1000_adapter *adapter)
3275 e1000e_set_rx_mode(adapter->netdev);
3277 e1000_restore_vlan(adapter);
3278 e1000_init_manageability_pt(adapter);
3280 e1000_configure_tx(adapter);
3281 e1000_setup_rctl(adapter);
3282 e1000_configure_rx(adapter);
3283 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring),
3288 * e1000e_power_up_phy - restore link in case the phy was powered down
3289 * @adapter: address of board private structure
3291 * The phy may be powered down to save power and turn off link when the
3292 * driver is unloaded and wake on lan is not enabled (among others)
3293 * *** this routine MUST be followed by a call to e1000e_reset ***
3295 void e1000e_power_up_phy(struct e1000_adapter *adapter)
3297 if (adapter->hw.phy.ops.power_up)
3298 adapter->hw.phy.ops.power_up(&adapter->hw);
3300 adapter->hw.mac.ops.setup_link(&adapter->hw);
3304 * e1000_power_down_phy - Power down the PHY
3306 * Power down the PHY so no link is implied when interface is down.
3307 * The PHY cannot be powered down if management or WoL is active.
3309 static void e1000_power_down_phy(struct e1000_adapter *adapter)
3311 /* WoL is enabled */
3315 if (adapter->hw.phy.ops.power_down)
3316 adapter->hw.phy.ops.power_down(&adapter->hw);
3320 * e1000e_reset - bring the hardware into a known good state
3322 * This function boots the hardware and enables some settings that
3323 * require a configuration cycle of the hardware - those cannot be
3324 * set/changed during runtime. After reset the device needs to be
3325 * properly configured for Rx, Tx etc.
3327 void e1000e_reset(struct e1000_adapter *adapter)
3329 struct e1000_mac_info *mac = &adapter->hw.mac;
3330 struct e1000_fc_info *fc = &adapter->hw.fc;
3331 struct e1000_hw *hw = &adapter->hw;
3332 u32 tx_space, min_tx_space, min_rx_space;
3333 u32 pba = adapter->pba;
3336 /* reset Packet Buffer Allocation to default */
3339 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
3341 * To maintain wire speed transmits, the Tx FIFO should be
3342 * large enough to accommodate two full transmit packets,
3343 * rounded up to the next 1KB and expressed in KB. Likewise,
3344 * the Rx FIFO should be large enough to accommodate at least
3345 * one full receive packet and is similarly rounded up and
3349 /* upper 16 bits has Tx packet buffer allocation size in KB */
3350 tx_space = pba >> 16;
3351 /* lower 16 bits has Rx packet buffer allocation size in KB */
3354 * the Tx fifo also stores 16 bytes of information about the Tx
3355 * but don't include ethernet FCS because hardware appends it
3357 min_tx_space = (adapter->max_frame_size +
3358 sizeof(struct e1000_tx_desc) -
3360 min_tx_space = ALIGN(min_tx_space, 1024);
3361 min_tx_space >>= 10;
3362 /* software strips receive CRC, so leave room for it */
3363 min_rx_space = adapter->max_frame_size;
3364 min_rx_space = ALIGN(min_rx_space, 1024);
3365 min_rx_space >>= 10;
3368 * If current Tx allocation is less than the min Tx FIFO size,
3369 * and the min Tx FIFO size is less than the current Rx FIFO
3370 * allocation, take space away from current Rx allocation
3372 if ((tx_space < min_tx_space) &&
3373 ((min_tx_space - tx_space) < pba)) {
3374 pba -= min_tx_space - tx_space;
3377 * if short on Rx space, Rx wins and must trump Tx
3378 * adjustment or use Early Receive if available
3380 if ((pba < min_rx_space) &&
3381 (!(adapter->flags & FLAG_HAS_ERT)))
3382 /* ERT enabled in e1000_configure_rx */
3390 * flow control settings
3392 * The high water mark must be low enough to fit one full frame
3393 * (or the size used for early receive) above it in the Rx FIFO.
3394 * Set it to the lower of:
3395 * - 90% of the Rx FIFO size, and
3396 * - the full Rx FIFO size minus the early receive size (for parts
3397 * with ERT support assuming ERT set to E1000_ERT_2048), or
3398 * - the full Rx FIFO size minus one full frame
3400 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3401 fc->pause_time = 0xFFFF;
3403 fc->pause_time = E1000_FC_PAUSE_TIME;
3405 fc->current_mode = fc->requested_mode;
3407 switch (hw->mac.type) {
3409 if ((adapter->flags & FLAG_HAS_ERT) &&
3410 (adapter->netdev->mtu > ETH_DATA_LEN))
3411 hwm = min(((pba << 10) * 9 / 10),
3412 ((pba << 10) - (E1000_ERT_2048 << 3)));
3414 hwm = min(((pba << 10) * 9 / 10),
3415 ((pba << 10) - adapter->max_frame_size));
3417 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3418 fc->low_water = fc->high_water - 8;
3422 * Workaround PCH LOM adapter hangs with certain network
3423 * loads. If hangs persist, try disabling Tx flow control.
3425 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3426 fc->high_water = 0x3500;
3427 fc->low_water = 0x1500;
3429 fc->high_water = 0x5000;
3430 fc->low_water = 0x3000;
3432 fc->refresh_time = 0x1000;
3435 fc->high_water = 0x05C20;
3436 fc->low_water = 0x05048;
3437 fc->pause_time = 0x0650;
3438 fc->refresh_time = 0x0400;
3439 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3447 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3448 * fit in receive buffer and early-receive not supported.
3450 if (adapter->itr_setting & 0x3) {
3451 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3452 !(adapter->flags & FLAG_HAS_ERT)) {
3453 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3454 dev_info(&adapter->pdev->dev,
3455 "Interrupt Throttle Rate turned off\n");
3456 adapter->flags2 |= FLAG2_DISABLE_AIM;
3459 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3460 dev_info(&adapter->pdev->dev,
3461 "Interrupt Throttle Rate turned on\n");
3462 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3463 adapter->itr = 20000;
3464 ew32(ITR, 1000000000 / (adapter->itr * 256));
3468 /* Allow time for pending master requests to run */
3469 mac->ops.reset_hw(hw);
3472 * For parts with AMT enabled, let the firmware know
3473 * that the network interface is in control
3475 if (adapter->flags & FLAG_HAS_AMT)
3476 e1000e_get_hw_control(adapter);
3480 if (mac->ops.init_hw(hw))
3481 e_err("Hardware Error\n");
3483 e1000_update_mng_vlan(adapter);
3485 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3486 ew32(VET, ETH_P_8021Q);
3488 e1000e_reset_adaptive(hw);
3490 if (!netif_running(adapter->netdev) &&
3491 !test_bit(__E1000_TESTING, &adapter->state)) {
3492 e1000_power_down_phy(adapter);
3496 e1000_get_phy_info(hw);
3498 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3499 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
3502 * speed up time to link by disabling smart power down, ignore
3503 * the return value of this function because there is nothing
3504 * different we would do if it failed
3506 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3507 phy_data &= ~IGP02E1000_PM_SPD;
3508 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3512 int e1000e_up(struct e1000_adapter *adapter)
3514 struct e1000_hw *hw = &adapter->hw;
3516 /* hardware has been reset, we need to reload some things */
3517 e1000_configure(adapter);
3519 clear_bit(__E1000_DOWN, &adapter->state);
3521 if (adapter->msix_entries)
3522 e1000_configure_msix(adapter);
3523 e1000_irq_enable(adapter);
3525 netif_start_queue(adapter->netdev);
3527 /* fire a link change interrupt to start the watchdog */
3528 if (adapter->msix_entries)
3529 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3531 ew32(ICS, E1000_ICS_LSC);
3536 static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3538 struct e1000_hw *hw = &adapter->hw;
3540 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3543 /* flush pending descriptor writebacks to memory */
3544 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3545 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3547 /* execute the writes immediately */
3551 static void e1000e_update_stats(struct e1000_adapter *adapter);
3553 void e1000e_down(struct e1000_adapter *adapter)
3555 struct net_device *netdev = adapter->netdev;
3556 struct e1000_hw *hw = &adapter->hw;
3560 * signal that we're down so the interrupt handler does not
3561 * reschedule our watchdog timer
3563 set_bit(__E1000_DOWN, &adapter->state);
3565 /* disable receives in the hardware */
3567 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3568 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3569 /* flush and sleep below */
3571 netif_stop_queue(netdev);
3573 /* disable transmits in the hardware */
3575 tctl &= ~E1000_TCTL_EN;
3578 /* flush both disables and wait for them to finish */
3580 usleep_range(10000, 20000);
3582 e1000_irq_disable(adapter);
3584 del_timer_sync(&adapter->watchdog_timer);
3585 del_timer_sync(&adapter->phy_info_timer);
3587 netif_carrier_off(netdev);
3589 spin_lock(&adapter->stats64_lock);
3590 e1000e_update_stats(adapter);
3591 spin_unlock(&adapter->stats64_lock);
3593 e1000e_flush_descriptors(adapter);
3594 e1000_clean_tx_ring(adapter);
3595 e1000_clean_rx_ring(adapter);
3597 adapter->link_speed = 0;
3598 adapter->link_duplex = 0;
3600 if (!pci_channel_offline(adapter->pdev))
3601 e1000e_reset(adapter);
3604 * TODO: for power management, we could drop the link and
3605 * pci_disable_device here.
3609 void e1000e_reinit_locked(struct e1000_adapter *adapter)
3612 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3613 usleep_range(1000, 2000);
3614 e1000e_down(adapter);
3616 clear_bit(__E1000_RESETTING, &adapter->state);
3620 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3621 * @adapter: board private structure to initialize
3623 * e1000_sw_init initializes the Adapter private data structure.
3624 * Fields are initialized based on PCI device information and
3625 * OS network device settings (MTU size).
3627 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3629 struct net_device *netdev = adapter->netdev;
3631 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3632 adapter->rx_ps_bsize0 = 128;
3633 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3634 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
3636 spin_lock_init(&adapter->stats64_lock);
3638 e1000e_set_interrupt_capability(adapter);
3640 if (e1000_alloc_queues(adapter))
3643 /* Explicitly disable IRQ since the NIC can be in any state. */
3644 e1000_irq_disable(adapter);
3646 set_bit(__E1000_DOWN, &adapter->state);
3651 * e1000_intr_msi_test - Interrupt Handler
3652 * @irq: interrupt number
3653 * @data: pointer to a network interface device structure
3655 static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3657 struct net_device *netdev = data;
3658 struct e1000_adapter *adapter = netdev_priv(netdev);
3659 struct e1000_hw *hw = &adapter->hw;
3660 u32 icr = er32(ICR);
3662 e_dbg("icr is %08X\n", icr);
3663 if (icr & E1000_ICR_RXSEQ) {
3664 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3672 * e1000_test_msi_interrupt - Returns 0 for successful test
3673 * @adapter: board private struct
3675 * code flow taken from tg3.c
3677 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3679 struct net_device *netdev = adapter->netdev;
3680 struct e1000_hw *hw = &adapter->hw;
3683 /* poll_enable hasn't been called yet, so don't need disable */
3684 /* clear any pending events */
3687 /* free the real vector and request a test handler */
3688 e1000_free_irq(adapter);
3689 e1000e_reset_interrupt_capability(adapter);
3691 /* Assume that the test fails, if it succeeds then the test
3692 * MSI irq handler will unset this flag */
3693 adapter->flags |= FLAG_MSI_TEST_FAILED;
3695 err = pci_enable_msi(adapter->pdev);
3697 goto msi_test_failed;
3699 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
3700 netdev->name, netdev);
3702 pci_disable_msi(adapter->pdev);
3703 goto msi_test_failed;
3708 e1000_irq_enable(adapter);
3710 /* fire an unusual interrupt on the test handler */
3711 ew32(ICS, E1000_ICS_RXSEQ);
3715 e1000_irq_disable(adapter);
3719 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
3720 adapter->int_mode = E1000E_INT_MODE_LEGACY;
3721 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3723 e_dbg("MSI interrupt test succeeded!\n");
3725 free_irq(adapter->pdev->irq, netdev);
3726 pci_disable_msi(adapter->pdev);
3729 e1000e_set_interrupt_capability(adapter);
3730 return e1000_request_irq(adapter);
3734 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3735 * @adapter: board private struct
3737 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3739 static int e1000_test_msi(struct e1000_adapter *adapter)
3744 if (!(adapter->flags & FLAG_MSI_ENABLED))
3747 /* disable SERR in case the MSI write causes a master abort */
3748 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3749 if (pci_cmd & PCI_COMMAND_SERR)
3750 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3751 pci_cmd & ~PCI_COMMAND_SERR);
3753 err = e1000_test_msi_interrupt(adapter);
3755 /* re-enable SERR */
3756 if (pci_cmd & PCI_COMMAND_SERR) {
3757 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3758 pci_cmd |= PCI_COMMAND_SERR;
3759 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3766 * e1000_open - Called when a network interface is made active
3767 * @netdev: network interface device structure
3769 * Returns 0 on success, negative value on failure
3771 * The open entry point is called when a network interface is made
3772 * active by the system (IFF_UP). At this point all resources needed
3773 * for transmit and receive operations are allocated, the interrupt
3774 * handler is registered with the OS, the watchdog timer is started,
3775 * and the stack is notified that the interface is ready.
3777 static int e1000_open(struct net_device *netdev)
3779 struct e1000_adapter *adapter = netdev_priv(netdev);
3780 struct e1000_hw *hw = &adapter->hw;
3781 struct pci_dev *pdev = adapter->pdev;
3784 /* disallow open during test */
3785 if (test_bit(__E1000_TESTING, &adapter->state))
3788 pm_runtime_get_sync(&pdev->dev);
3790 netif_carrier_off(netdev);
3792 /* allocate transmit descriptors */
3793 err = e1000e_setup_tx_resources(adapter);
3797 /* allocate receive descriptors */
3798 err = e1000e_setup_rx_resources(adapter);
3803 * If AMT is enabled, let the firmware know that the network
3804 * interface is now open and reset the part to a known state.
3806 if (adapter->flags & FLAG_HAS_AMT) {
3807 e1000e_get_hw_control(adapter);
3808 e1000e_reset(adapter);
3811 e1000e_power_up_phy(adapter);
3813 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3814 if ((adapter->hw.mng_cookie.status &
3815 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3816 e1000_update_mng_vlan(adapter);
3818 /* DMA latency requirement to workaround early-receive/jumbo issue */
3819 if ((adapter->flags & FLAG_HAS_ERT) ||
3820 (adapter->hw.mac.type == e1000_pch2lan))
3821 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3822 PM_QOS_CPU_DMA_LATENCY,
3823 PM_QOS_DEFAULT_VALUE);
3826 * before we allocate an interrupt, we must be ready to handle it.
3827 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3828 * as soon as we call pci_request_irq, so we have to setup our
3829 * clean_rx handler before we do so.
3831 e1000_configure(adapter);
3833 err = e1000_request_irq(adapter);
3838 * Work around PCIe errata with MSI interrupts causing some chipsets to
3839 * ignore e1000e MSI messages, which means we need to test our MSI
3842 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
3843 err = e1000_test_msi(adapter);
3845 e_err("Interrupt allocation failed\n");
3850 /* From here on the code is the same as e1000e_up() */
3851 clear_bit(__E1000_DOWN, &adapter->state);
3853 napi_enable(&adapter->napi);
3855 e1000_irq_enable(adapter);
3857 adapter->tx_hang_recheck = false;
3858 netif_start_queue(netdev);
3860 adapter->idle_check = true;
3861 pm_runtime_put(&pdev->dev);
3863 /* fire a link status change interrupt to start the watchdog */
3864 if (adapter->msix_entries)
3865 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3867 ew32(ICS, E1000_ICS_LSC);
3872 e1000e_release_hw_control(adapter);
3873 e1000_power_down_phy(adapter);
3874 e1000e_free_rx_resources(adapter);
3876 e1000e_free_tx_resources(adapter);
3878 e1000e_reset(adapter);
3879 pm_runtime_put_sync(&pdev->dev);
3885 * e1000_close - Disables a network interface
3886 * @netdev: network interface device structure
3888 * Returns 0, this is not allowed to fail
3890 * The close entry point is called when an interface is de-activated
3891 * by the OS. The hardware is still under the drivers control, but
3892 * needs to be disabled. A global MAC reset is issued to stop the
3893 * hardware, and all transmit and receive resources are freed.
3895 static int e1000_close(struct net_device *netdev)
3897 struct e1000_adapter *adapter = netdev_priv(netdev);
3898 struct pci_dev *pdev = adapter->pdev;
3900 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3902 pm_runtime_get_sync(&pdev->dev);
3904 napi_disable(&adapter->napi);
3906 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3907 e1000e_down(adapter);
3908 e1000_free_irq(adapter);
3910 e1000_power_down_phy(adapter);
3912 e1000e_free_tx_resources(adapter);
3913 e1000e_free_rx_resources(adapter);
3916 * kill manageability vlan ID if supported, but not if a vlan with
3917 * the same ID is registered on the host OS (let 8021q kill it)
3919 if (adapter->hw.mng_cookie.status &
3920 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
3921 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3924 * If AMT is enabled, let the firmware know that the network
3925 * interface is now closed
3927 if ((adapter->flags & FLAG_HAS_AMT) &&
3928 !test_bit(__E1000_TESTING, &adapter->state))
3929 e1000e_release_hw_control(adapter);
3931 if ((adapter->flags & FLAG_HAS_ERT) ||
3932 (adapter->hw.mac.type == e1000_pch2lan))
3933 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
3935 pm_runtime_put_sync(&pdev->dev);
3940 * e1000_set_mac - Change the Ethernet Address of the NIC
3941 * @netdev: network interface device structure
3942 * @p: pointer to an address structure
3944 * Returns 0 on success, negative on failure
3946 static int e1000_set_mac(struct net_device *netdev, void *p)
3948 struct e1000_adapter *adapter = netdev_priv(netdev);
3949 struct sockaddr *addr = p;
3951 if (!is_valid_ether_addr(addr->sa_data))
3952 return -EADDRNOTAVAIL;
3954 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3955 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3957 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3959 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3960 /* activate the work around */
3961 e1000e_set_laa_state_82571(&adapter->hw, 1);
3964 * Hold a copy of the LAA in RAR[14] This is done so that
3965 * between the time RAR[0] gets clobbered and the time it
3966 * gets fixed (in e1000_watchdog), the actual LAA is in one
3967 * of the RARs and no incoming packets directed to this port
3968 * are dropped. Eventually the LAA will be in RAR[0] and
3971 e1000e_rar_set(&adapter->hw,
3972 adapter->hw.mac.addr,
3973 adapter->hw.mac.rar_entry_count - 1);
3980 * e1000e_update_phy_task - work thread to update phy
3981 * @work: pointer to our work struct
3983 * this worker thread exists because we must acquire a
3984 * semaphore to read the phy, which we could msleep while
3985 * waiting for it, and we can't msleep in a timer.
3987 static void e1000e_update_phy_task(struct work_struct *work)
3989 struct e1000_adapter *adapter = container_of(work,
3990 struct e1000_adapter, update_phy_task);
3992 if (test_bit(__E1000_DOWN, &adapter->state))
3995 e1000_get_phy_info(&adapter->hw);
3999 * Need to wait a few seconds after link up to get diagnostic information from
4002 static void e1000_update_phy_info(unsigned long data)
4004 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4006 if (test_bit(__E1000_DOWN, &adapter->state))
4009 schedule_work(&adapter->update_phy_task);
4013 * e1000e_update_phy_stats - Update the PHY statistics counters
4014 * @adapter: board private structure
4016 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
4018 static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4020 struct e1000_hw *hw = &adapter->hw;
4024 ret_val = hw->phy.ops.acquire(hw);
4029 * A page set is expensive so check if already on desired page.
4030 * If not, set to the page with the PHY status registers.
4033 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4037 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4038 ret_val = hw->phy.ops.set_page(hw,
4039 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4044 /* Single Collision Count */
4045 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4046 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4048 adapter->stats.scc += phy_data;
4050 /* Excessive Collision Count */
4051 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4052 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4054 adapter->stats.ecol += phy_data;
4056 /* Multiple Collision Count */
4057 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4058 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4060 adapter->stats.mcc += phy_data;
4062 /* Late Collision Count */
4063 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4064 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4066 adapter->stats.latecol += phy_data;
4068 /* Collision Count - also used for adaptive IFS */
4069 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4070 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4072 hw->mac.collision_delta = phy_data;
4075 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4076 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4078 adapter->stats.dc += phy_data;
4080 /* Transmit with no CRS */
4081 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4082 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4084 adapter->stats.tncrs += phy_data;
4087 hw->phy.ops.release(hw);
4091 * e1000e_update_stats - Update the board statistics counters
4092 * @adapter: board private structure
4094 static void e1000e_update_stats(struct e1000_adapter *adapter)
4096 struct net_device *netdev = adapter->netdev;
4097 struct e1000_hw *hw = &adapter->hw;
4098 struct pci_dev *pdev = adapter->pdev;
4101 * Prevent stats update while adapter is being reset, or if the pci
4102 * connection is down.
4104 if (adapter->link_speed == 0)
4106 if (pci_channel_offline(pdev))
4109 adapter->stats.crcerrs += er32(CRCERRS);
4110 adapter->stats.gprc += er32(GPRC);
4111 adapter->stats.gorc += er32(GORCL);
4112 er32(GORCH); /* Clear gorc */
4113 adapter->stats.bprc += er32(BPRC);
4114 adapter->stats.mprc += er32(MPRC);
4115 adapter->stats.roc += er32(ROC);
4117 adapter->stats.mpc += er32(MPC);
4119 /* Half-duplex statistics */
4120 if (adapter->link_duplex == HALF_DUPLEX) {
4121 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4122 e1000e_update_phy_stats(adapter);
4124 adapter->stats.scc += er32(SCC);
4125 adapter->stats.ecol += er32(ECOL);
4126 adapter->stats.mcc += er32(MCC);
4127 adapter->stats.latecol += er32(LATECOL);
4128 adapter->stats.dc += er32(DC);
4130 hw->mac.collision_delta = er32(COLC);
4132 if ((hw->mac.type != e1000_82574) &&
4133 (hw->mac.type != e1000_82583))
4134 adapter->stats.tncrs += er32(TNCRS);
4136 adapter->stats.colc += hw->mac.collision_delta;
4139 adapter->stats.xonrxc += er32(XONRXC);
4140 adapter->stats.xontxc += er32(XONTXC);
4141 adapter->stats.xoffrxc += er32(XOFFRXC);
4142 adapter->stats.xofftxc += er32(XOFFTXC);
4143 adapter->stats.gptc += er32(GPTC);
4144 adapter->stats.gotc += er32(GOTCL);
4145 er32(GOTCH); /* Clear gotc */
4146 adapter->stats.rnbc += er32(RNBC);
4147 adapter->stats.ruc += er32(RUC);
4149 adapter->stats.mptc += er32(MPTC);
4150 adapter->stats.bptc += er32(BPTC);
4152 /* used for adaptive IFS */
4154 hw->mac.tx_packet_delta = er32(TPT);
4155 adapter->stats.tpt += hw->mac.tx_packet_delta;
4157 adapter->stats.algnerrc += er32(ALGNERRC);
4158 adapter->stats.rxerrc += er32(RXERRC);
4159 adapter->stats.cexterr += er32(CEXTERR);
4160 adapter->stats.tsctc += er32(TSCTC);
4161 adapter->stats.tsctfc += er32(TSCTFC);
4163 /* Fill out the OS statistics structure */
4164 netdev->stats.multicast = adapter->stats.mprc;
4165 netdev->stats.collisions = adapter->stats.colc;
4170 * RLEC on some newer hardware can be incorrect so build
4171 * our own version based on RUC and ROC
4173 netdev->stats.rx_errors = adapter->stats.rxerrc +
4174 adapter->stats.crcerrs + adapter->stats.algnerrc +
4175 adapter->stats.ruc + adapter->stats.roc +
4176 adapter->stats.cexterr;
4177 netdev->stats.rx_length_errors = adapter->stats.ruc +
4179 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4180 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4181 netdev->stats.rx_missed_errors = adapter->stats.mpc;
4184 netdev->stats.tx_errors = adapter->stats.ecol +
4185 adapter->stats.latecol;
4186 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4187 netdev->stats.tx_window_errors = adapter->stats.latecol;
4188 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
4190 /* Tx Dropped needs to be maintained elsewhere */
4192 /* Management Stats */
4193 adapter->stats.mgptc += er32(MGTPTC);
4194 adapter->stats.mgprc += er32(MGTPRC);
4195 adapter->stats.mgpdc += er32(MGTPDC);
4199 * e1000_phy_read_status - Update the PHY register status snapshot
4200 * @adapter: board private structure
4202 static void e1000_phy_read_status(struct e1000_adapter *adapter)
4204 struct e1000_hw *hw = &adapter->hw;
4205 struct e1000_phy_regs *phy = &adapter->phy_regs;
4207 if ((er32(STATUS) & E1000_STATUS_LU) &&
4208 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
4211 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4212 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4213 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4214 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4215 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4216 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4217 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4218 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4220 e_warn("Error reading PHY register\n");
4223 * Do not read PHY registers if link is not up
4224 * Set values to typical power-on defaults
4226 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4227 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4228 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4230 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4231 ADVERTISE_ALL | ADVERTISE_CSMA);
4233 phy->expansion = EXPANSION_ENABLENPAGE;
4234 phy->ctrl1000 = ADVERTISE_1000FULL;
4236 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4240 static void e1000_print_link_info(struct e1000_adapter *adapter)
4242 struct e1000_hw *hw = &adapter->hw;
4243 u32 ctrl = er32(CTRL);
4245 /* Link status message must follow this format for user tools */
4246 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4247 adapter->netdev->name,
4248 adapter->link_speed,
4249 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4250 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4251 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4252 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
4255 static bool e1000e_has_link(struct e1000_adapter *adapter)
4257 struct e1000_hw *hw = &adapter->hw;
4258 bool link_active = false;
4262 * get_link_status is set on LSC (link status) interrupt or
4263 * Rx sequence error interrupt. get_link_status will stay
4264 * false until the check_for_link establishes link
4265 * for copper adapters ONLY
4267 switch (hw->phy.media_type) {
4268 case e1000_media_type_copper:
4269 if (hw->mac.get_link_status) {
4270 ret_val = hw->mac.ops.check_for_link(hw);
4271 link_active = !hw->mac.get_link_status;
4276 case e1000_media_type_fiber:
4277 ret_val = hw->mac.ops.check_for_link(hw);
4278 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4280 case e1000_media_type_internal_serdes:
4281 ret_val = hw->mac.ops.check_for_link(hw);
4282 link_active = adapter->hw.mac.serdes_has_link;
4285 case e1000_media_type_unknown:
4289 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4290 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4291 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
4292 e_info("Gigabit has been disabled, downgrading speed\n");
4298 static void e1000e_enable_receives(struct e1000_adapter *adapter)
4300 /* make sure the receive unit is started */
4301 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4302 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4303 struct e1000_hw *hw = &adapter->hw;
4304 u32 rctl = er32(RCTL);
4305 ew32(RCTL, rctl | E1000_RCTL_EN);
4306 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4310 static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4312 struct e1000_hw *hw = &adapter->hw;
4315 * With 82574 controllers, PHY needs to be checked periodically
4316 * for hung state and reset, if two calls return true
4318 if (e1000_check_phy_82574(hw))
4319 adapter->phy_hang_count++;
4321 adapter->phy_hang_count = 0;
4323 if (adapter->phy_hang_count > 1) {
4324 adapter->phy_hang_count = 0;
4325 schedule_work(&adapter->reset_task);
4330 * e1000_watchdog - Timer Call-back
4331 * @data: pointer to adapter cast into an unsigned long
4333 static void e1000_watchdog(unsigned long data)
4335 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4337 /* Do the rest outside of interrupt context */
4338 schedule_work(&adapter->watchdog_task);
4340 /* TODO: make this use queue_delayed_work() */
4343 static void e1000_watchdog_task(struct work_struct *work)
4345 struct e1000_adapter *adapter = container_of(work,
4346 struct e1000_adapter, watchdog_task);
4347 struct net_device *netdev = adapter->netdev;
4348 struct e1000_mac_info *mac = &adapter->hw.mac;
4349 struct e1000_phy_info *phy = &adapter->hw.phy;
4350 struct e1000_ring *tx_ring = adapter->tx_ring;
4351 struct e1000_hw *hw = &adapter->hw;
4354 if (test_bit(__E1000_DOWN, &adapter->state))
4357 link = e1000e_has_link(adapter);
4358 if ((netif_carrier_ok(netdev)) && link) {
4359 /* Cancel scheduled suspend requests. */
4360 pm_runtime_resume(netdev->dev.parent);
4362 e1000e_enable_receives(adapter);
4366 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4367 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4368 e1000_update_mng_vlan(adapter);
4371 if (!netif_carrier_ok(netdev)) {
4374 /* Cancel scheduled suspend requests. */
4375 pm_runtime_resume(netdev->dev.parent);
4377 /* update snapshot of PHY registers on LSC */
4378 e1000_phy_read_status(adapter);
4379 mac->ops.get_link_up_info(&adapter->hw,
4380 &adapter->link_speed,
4381 &adapter->link_duplex);
4382 e1000_print_link_info(adapter);
4384 * On supported PHYs, check for duplex mismatch only
4385 * if link has autonegotiated at 10/100 half
4387 if ((hw->phy.type == e1000_phy_igp_3 ||
4388 hw->phy.type == e1000_phy_bm) &&
4389 (hw->mac.autoneg == true) &&
4390 (adapter->link_speed == SPEED_10 ||
4391 adapter->link_speed == SPEED_100) &&
4392 (adapter->link_duplex == HALF_DUPLEX)) {
4395 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4397 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4398 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
4401 /* adjust timeout factor according to speed/duplex */
4402 adapter->tx_timeout_factor = 1;
4403 switch (adapter->link_speed) {
4406 adapter->tx_timeout_factor = 16;
4410 adapter->tx_timeout_factor = 10;
4415 * workaround: re-program speed mode bit after
4418 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4421 tarc0 = er32(TARC(0));
4422 tarc0 &= ~SPEED_MODE_BIT;
4423 ew32(TARC(0), tarc0);
4427 * disable TSO for pcie and 10/100 speeds, to avoid
4428 * some hardware issues
4430 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4431 switch (adapter->link_speed) {
4434 e_info("10/100 speed: disabling TSO\n");
4435 netdev->features &= ~NETIF_F_TSO;
4436 netdev->features &= ~NETIF_F_TSO6;
4439 netdev->features |= NETIF_F_TSO;
4440 netdev->features |= NETIF_F_TSO6;
4449 * enable transmits in the hardware, need to do this
4450 * after setting TARC(0)
4453 tctl |= E1000_TCTL_EN;
4457 * Perform any post-link-up configuration before
4458 * reporting link up.
4460 if (phy->ops.cfg_on_link_up)
4461 phy->ops.cfg_on_link_up(hw);
4463 netif_carrier_on(netdev);
4465 if (!test_bit(__E1000_DOWN, &adapter->state))
4466 mod_timer(&adapter->phy_info_timer,
4467 round_jiffies(jiffies + 2 * HZ));
4470 if (netif_carrier_ok(netdev)) {
4471 adapter->link_speed = 0;
4472 adapter->link_duplex = 0;
4473 /* Link status message must follow this format */
4474 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4475 adapter->netdev->name);
4476 netif_carrier_off(netdev);
4477 if (!test_bit(__E1000_DOWN, &adapter->state))
4478 mod_timer(&adapter->phy_info_timer,
4479 round_jiffies(jiffies + 2 * HZ));
4481 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4482 schedule_work(&adapter->reset_task);
4484 pm_schedule_suspend(netdev->dev.parent,
4490 spin_lock(&adapter->stats64_lock);
4491 e1000e_update_stats(adapter);
4493 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4494 adapter->tpt_old = adapter->stats.tpt;
4495 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4496 adapter->colc_old = adapter->stats.colc;
4498 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4499 adapter->gorc_old = adapter->stats.gorc;
4500 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4501 adapter->gotc_old = adapter->stats.gotc;
4502 spin_unlock(&adapter->stats64_lock);
4504 e1000e_update_adaptive(&adapter->hw);
4506 if (!netif_carrier_ok(netdev) &&
4507 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4509 * We've lost link, so the controller stops DMA,
4510 * but we've got queued Tx work that's never going
4511 * to get done, so reset controller to flush Tx.
4512 * (Do the reset outside of interrupt context).
4514 schedule_work(&adapter->reset_task);
4515 /* return immediately since reset is imminent */
4519 /* Simple mode for Interrupt Throttle Rate (ITR) */
4520 if (adapter->itr_setting == 4) {
4522 * Symmetric Tx/Rx gets a reduced ITR=2000;
4523 * Total asymmetrical Tx or Rx gets ITR=8000;
4524 * everyone else is between 2000-8000.
4526 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4527 u32 dif = (adapter->gotc > adapter->gorc ?
4528 adapter->gotc - adapter->gorc :
4529 adapter->gorc - adapter->gotc) / 10000;
4530 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4532 ew32(ITR, 1000000000 / (itr * 256));
4535 /* Cause software interrupt to ensure Rx ring is cleaned */
4536 if (adapter->msix_entries)
4537 ew32(ICS, adapter->rx_ring->ims_val);
4539 ew32(ICS, E1000_ICS_RXDMT0);
4541 /* flush pending descriptors to memory before detecting Tx hang */
4542 e1000e_flush_descriptors(adapter);
4544 /* Force detection of hung controller every watchdog period */
4545 adapter->detect_tx_hung = true;
4548 * With 82571 controllers, LAA may be overwritten due to controller
4549 * reset from the other port. Set the appropriate LAA in RAR[0]
4551 if (e1000e_get_laa_state_82571(hw))
4552 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4554 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4555 e1000e_check_82574_phy_workaround(adapter);
4557 /* Reset the timer */
4558 if (!test_bit(__E1000_DOWN, &adapter->state))
4559 mod_timer(&adapter->watchdog_timer,
4560 round_jiffies(jiffies + 2 * HZ));
4563 #define E1000_TX_FLAGS_CSUM 0x00000001
4564 #define E1000_TX_FLAGS_VLAN 0x00000002
4565 #define E1000_TX_FLAGS_TSO 0x00000004
4566 #define E1000_TX_FLAGS_IPV4 0x00000008
4567 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4568 #define E1000_TX_FLAGS_VLAN_SHIFT 16
4570 static int e1000_tso(struct e1000_adapter *adapter,
4571 struct sk_buff *skb)
4573 struct e1000_ring *tx_ring = adapter->tx_ring;
4574 struct e1000_context_desc *context_desc;
4575 struct e1000_buffer *buffer_info;
4578 u16 ipcse = 0, tucse, mss;
4579 u8 ipcss, ipcso, tucss, tucso, hdr_len;
4581 if (!skb_is_gso(skb))
4584 if (skb_header_cloned(skb)) {
4585 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4591 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4592 mss = skb_shinfo(skb)->gso_size;
4593 if (skb->protocol == htons(ETH_P_IP)) {
4594 struct iphdr *iph = ip_hdr(skb);
4597 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4599 cmd_length = E1000_TXD_CMD_IP;
4600 ipcse = skb_transport_offset(skb) - 1;
4601 } else if (skb_is_gso_v6(skb)) {
4602 ipv6_hdr(skb)->payload_len = 0;
4603 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4604 &ipv6_hdr(skb)->daddr,
4608 ipcss = skb_network_offset(skb);
4609 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4610 tucss = skb_transport_offset(skb);
4611 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4614 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4615 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4617 i = tx_ring->next_to_use;
4618 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4619 buffer_info = &tx_ring->buffer_info[i];
4621 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4622 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4623 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4624 context_desc->upper_setup.tcp_fields.tucss = tucss;
4625 context_desc->upper_setup.tcp_fields.tucso = tucso;
4626 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4627 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4628 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4629 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4631 buffer_info->time_stamp = jiffies;
4632 buffer_info->next_to_watch = i;
4635 if (i == tx_ring->count)
4637 tx_ring->next_to_use = i;
4642 static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4644 struct e1000_ring *tx_ring = adapter->tx_ring;
4645 struct e1000_context_desc *context_desc;
4646 struct e1000_buffer *buffer_info;
4649 u32 cmd_len = E1000_TXD_CMD_DEXT;
4652 if (skb->ip_summed != CHECKSUM_PARTIAL)
4655 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4656 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4658 protocol = skb->protocol;
4661 case cpu_to_be16(ETH_P_IP):
4662 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4663 cmd_len |= E1000_TXD_CMD_TCP;
4665 case cpu_to_be16(ETH_P_IPV6):
4666 /* XXX not handling all IPV6 headers */
4667 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4668 cmd_len |= E1000_TXD_CMD_TCP;
4671 if (unlikely(net_ratelimit()))
4672 e_warn("checksum_partial proto=%x!\n",
4673 be16_to_cpu(protocol));
4677 css = skb_checksum_start_offset(skb);
4679 i = tx_ring->next_to_use;
4680 buffer_info = &tx_ring->buffer_info[i];
4681 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4683 context_desc->lower_setup.ip_config = 0;
4684 context_desc->upper_setup.tcp_fields.tucss = css;
4685 context_desc->upper_setup.tcp_fields.tucso =
4686 css + skb->csum_offset;
4687 context_desc->upper_setup.tcp_fields.tucse = 0;
4688 context_desc->tcp_seg_setup.data = 0;
4689 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4691 buffer_info->time_stamp = jiffies;
4692 buffer_info->next_to_watch = i;
4695 if (i == tx_ring->count)
4697 tx_ring->next_to_use = i;
4702 #define E1000_MAX_PER_TXD 8192
4703 #define E1000_MAX_TXD_PWR 12
4705 static int e1000_tx_map(struct e1000_adapter *adapter,
4706 struct sk_buff *skb, unsigned int first,
4707 unsigned int max_per_txd, unsigned int nr_frags,
4710 struct e1000_ring *tx_ring = adapter->tx_ring;
4711 struct pci_dev *pdev = adapter->pdev;
4712 struct e1000_buffer *buffer_info;
4713 unsigned int len = skb_headlen(skb);
4714 unsigned int offset = 0, size, count = 0, i;
4715 unsigned int f, bytecount, segs;
4717 i = tx_ring->next_to_use;
4720 buffer_info = &tx_ring->buffer_info[i];
4721 size = min(len, max_per_txd);
4723 buffer_info->length = size;
4724 buffer_info->time_stamp = jiffies;
4725 buffer_info->next_to_watch = i;
4726 buffer_info->dma = dma_map_single(&pdev->dev,
4728 size, DMA_TO_DEVICE);
4729 buffer_info->mapped_as_page = false;
4730 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4739 if (i == tx_ring->count)
4744 for (f = 0; f < nr_frags; f++) {
4745 const struct skb_frag_struct *frag;
4747 frag = &skb_shinfo(skb)->frags[f];
4748 len = skb_frag_size(frag);
4753 if (i == tx_ring->count)
4756 buffer_info = &tx_ring->buffer_info[i];
4757 size = min(len, max_per_txd);
4759 buffer_info->length = size;
4760 buffer_info->time_stamp = jiffies;
4761 buffer_info->next_to_watch = i;
4762 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4763 offset, size, DMA_TO_DEVICE);
4764 buffer_info->mapped_as_page = true;
4765 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4774 segs = skb_shinfo(skb)->gso_segs ? : 1;
4775 /* multiply data chunks by size of headers */
4776 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4778 tx_ring->buffer_info[i].skb = skb;
4779 tx_ring->buffer_info[i].segs = segs;
4780 tx_ring->buffer_info[i].bytecount = bytecount;
4781 tx_ring->buffer_info[first].next_to_watch = i;
4786 dev_err(&pdev->dev, "Tx DMA map failed\n");
4787 buffer_info->dma = 0;
4793 i += tx_ring->count;
4795 buffer_info = &tx_ring->buffer_info[i];
4796 e1000_put_txbuf(adapter, buffer_info);
4802 static void e1000_tx_queue(struct e1000_adapter *adapter,
4803 int tx_flags, int count)
4805 struct e1000_ring *tx_ring = adapter->tx_ring;
4806 struct e1000_tx_desc *tx_desc = NULL;
4807 struct e1000_buffer *buffer_info;
4808 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4811 if (tx_flags & E1000_TX_FLAGS_TSO) {
4812 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4814 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4816 if (tx_flags & E1000_TX_FLAGS_IPV4)
4817 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4820 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4821 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4822 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4825 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4826 txd_lower |= E1000_TXD_CMD_VLE;
4827 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4830 i = tx_ring->next_to_use;
4833 buffer_info = &tx_ring->buffer_info[i];
4834 tx_desc = E1000_TX_DESC(*tx_ring, i);
4835 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4836 tx_desc->lower.data =
4837 cpu_to_le32(txd_lower | buffer_info->length);
4838 tx_desc->upper.data = cpu_to_le32(txd_upper);
4841 if (i == tx_ring->count)
4843 } while (--count > 0);
4845 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4848 * Force memory writes to complete before letting h/w
4849 * know there are new descriptors to fetch. (Only
4850 * applicable for weak-ordered memory model archs,
4855 tx_ring->next_to_use = i;
4857 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4858 e1000e_update_tdt_wa(adapter, i);
4860 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4863 * we need this if more than one processor can write to our tail
4864 * at a time, it synchronizes IO on IA64/Altix systems
4869 #define MINIMUM_DHCP_PACKET_SIZE 282
4870 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4871 struct sk_buff *skb)
4873 struct e1000_hw *hw = &adapter->hw;
4876 if (vlan_tx_tag_present(skb)) {
4877 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4878 (adapter->hw.mng_cookie.status &
4879 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4883 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4886 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4890 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4893 if (ip->protocol != IPPROTO_UDP)
4896 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4897 if (ntohs(udp->dest) != 67)
4900 offset = (u8 *)udp + 8 - skb->data;
4901 length = skb->len - offset;
4902 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4908 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4910 struct e1000_adapter *adapter = netdev_priv(netdev);
4912 netif_stop_queue(netdev);
4914 * Herbert's original patch had:
4915 * smp_mb__after_netif_stop_queue();
4916 * but since that doesn't exist yet, just open code it.
4921 * We need to check again in a case another CPU has just
4922 * made room available.
4924 if (e1000_desc_unused(adapter->tx_ring) < size)
4928 netif_start_queue(netdev);
4929 ++adapter->restart_queue;
4933 static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4935 struct e1000_adapter *adapter = netdev_priv(netdev);
4937 if (e1000_desc_unused(adapter->tx_ring) >= size)
4939 return __e1000_maybe_stop_tx(netdev, size);
4942 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4943 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4944 struct net_device *netdev)
4946 struct e1000_adapter *adapter = netdev_priv(netdev);
4947 struct e1000_ring *tx_ring = adapter->tx_ring;
4949 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4950 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4951 unsigned int tx_flags = 0;
4952 unsigned int len = skb_headlen(skb);
4953 unsigned int nr_frags;
4959 if (test_bit(__E1000_DOWN, &adapter->state)) {
4960 dev_kfree_skb_any(skb);
4961 return NETDEV_TX_OK;
4964 if (skb->len <= 0) {
4965 dev_kfree_skb_any(skb);
4966 return NETDEV_TX_OK;
4969 mss = skb_shinfo(skb)->gso_size;
4971 * The controller does a simple calculation to
4972 * make sure there is enough room in the FIFO before
4973 * initiating the DMA for each buffer. The calc is:
4974 * 4 = ceil(buffer len/mss). To make sure we don't
4975 * overrun the FIFO, adjust the max buffer len if mss
4980 max_per_txd = min(mss << 2, max_per_txd);
4981 max_txd_pwr = fls(max_per_txd) - 1;
4984 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4985 * points to just header, pull a few bytes of payload from
4986 * frags into skb->data
4988 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4990 * we do this workaround for ES2LAN, but it is un-necessary,
4991 * avoiding it could save a lot of cycles
4993 if (skb->data_len && (hdr_len == len)) {
4994 unsigned int pull_size;
4996 pull_size = min((unsigned int)4, skb->data_len);
4997 if (!__pskb_pull_tail(skb, pull_size)) {
4998 e_err("__pskb_pull_tail failed.\n");
4999 dev_kfree_skb_any(skb);
5000 return NETDEV_TX_OK;
5002 len = skb_headlen(skb);
5006 /* reserve a descriptor for the offload context */
5007 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5011 count += TXD_USE_COUNT(len, max_txd_pwr);
5013 nr_frags = skb_shinfo(skb)->nr_frags;
5014 for (f = 0; f < nr_frags; f++)
5015 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5018 if (adapter->hw.mac.tx_pkt_filtering)
5019 e1000_transfer_dhcp_info(adapter, skb);
5022 * need: count + 2 desc gap to keep tail from touching
5023 * head, otherwise try next time
5025 if (e1000_maybe_stop_tx(netdev, count + 2))
5026 return NETDEV_TX_BUSY;
5028 if (vlan_tx_tag_present(skb)) {
5029 tx_flags |= E1000_TX_FLAGS_VLAN;
5030 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5033 first = tx_ring->next_to_use;
5035 tso = e1000_tso(adapter, skb);
5037 dev_kfree_skb_any(skb);
5038 return NETDEV_TX_OK;
5042 tx_flags |= E1000_TX_FLAGS_TSO;
5043 else if (e1000_tx_csum(adapter, skb))
5044 tx_flags |= E1000_TX_FLAGS_CSUM;
5047 * Old method was to assume IPv4 packet by default if TSO was enabled.
5048 * 82571 hardware supports TSO capabilities for IPv6 as well...
5049 * no longer assume, we must.
5051 if (skb->protocol == htons(ETH_P_IP))
5052 tx_flags |= E1000_TX_FLAGS_IPV4;
5054 /* if count is 0 then mapping error has occurred */
5055 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
5057 netdev_sent_queue(netdev, skb->len);
5058 e1000_tx_queue(adapter, tx_flags, count);
5059 /* Make sure there is space in the ring for the next send. */
5060 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
5063 dev_kfree_skb_any(skb);
5064 tx_ring->buffer_info[first].time_stamp = 0;
5065 tx_ring->next_to_use = first;
5068 return NETDEV_TX_OK;
5072 * e1000_tx_timeout - Respond to a Tx Hang
5073 * @netdev: network interface device structure
5075 static void e1000_tx_timeout(struct net_device *netdev)
5077 struct e1000_adapter *adapter = netdev_priv(netdev);
5079 /* Do the reset outside of interrupt context */
5080 adapter->tx_timeout_count++;
5081 schedule_work(&adapter->reset_task);
5084 static void e1000_reset_task(struct work_struct *work)
5086 struct e1000_adapter *adapter;
5087 adapter = container_of(work, struct e1000_adapter, reset_task);
5089 /* don't run the task if already down */
5090 if (test_bit(__E1000_DOWN, &adapter->state))
5093 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5094 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5095 e1000e_dump(adapter);
5096 e_err("Reset adapter\n");
5098 e1000e_reinit_locked(adapter);
5102 * e1000_get_stats64 - Get System Network Statistics
5103 * @netdev: network interface device structure
5104 * @stats: rtnl_link_stats64 pointer
5106 * Returns the address of the device statistics structure.
5108 struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5109 struct rtnl_link_stats64 *stats)
5111 struct e1000_adapter *adapter = netdev_priv(netdev);
5113 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5114 spin_lock(&adapter->stats64_lock);
5115 e1000e_update_stats(adapter);
5116 /* Fill out the OS statistics structure */
5117 stats->rx_bytes = adapter->stats.gorc;
5118 stats->rx_packets = adapter->stats.gprc;
5119 stats->tx_bytes = adapter->stats.gotc;
5120 stats->tx_packets = adapter->stats.gptc;
5121 stats->multicast = adapter->stats.mprc;
5122 stats->collisions = adapter->stats.colc;
5127 * RLEC on some newer hardware can be incorrect so build
5128 * our own version based on RUC and ROC
5130 stats->rx_errors = adapter->stats.rxerrc +
5131 adapter->stats.crcerrs + adapter->stats.algnerrc +
5132 adapter->stats.ruc + adapter->stats.roc +
5133 adapter->stats.cexterr;
5134 stats->rx_length_errors = adapter->stats.ruc +
5136 stats->rx_crc_errors = adapter->stats.crcerrs;
5137 stats->rx_frame_errors = adapter->stats.algnerrc;
5138 stats->rx_missed_errors = adapter->stats.mpc;
5141 stats->tx_errors = adapter->stats.ecol +
5142 adapter->stats.latecol;
5143 stats->tx_aborted_errors = adapter->stats.ecol;
5144 stats->tx_window_errors = adapter->stats.latecol;
5145 stats->tx_carrier_errors = adapter->stats.tncrs;
5147 /* Tx Dropped needs to be maintained elsewhere */
5149 spin_unlock(&adapter->stats64_lock);
5154 * e1000_change_mtu - Change the Maximum Transfer Unit
5155 * @netdev: network interface device structure
5156 * @new_mtu: new value for maximum frame size
5158 * Returns 0 on success, negative on failure
5160 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5162 struct e1000_adapter *adapter = netdev_priv(netdev);
5163 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5165 /* Jumbo frame support */
5166 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5167 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5168 e_err("Jumbo Frames not supported.\n");
5172 /* Supported frame sizes */
5173 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5174 (max_frame > adapter->max_hw_frame_size)) {
5175 e_err("Unsupported MTU setting\n");
5179 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5180 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5181 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5182 (new_mtu > ETH_DATA_LEN)) {
5183 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
5187 /* 82573 Errata 17 */
5188 if (((adapter->hw.mac.type == e1000_82573) ||
5189 (adapter->hw.mac.type == e1000_82574)) &&
5190 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5191 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5192 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5195 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
5196 usleep_range(1000, 2000);
5197 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
5198 adapter->max_frame_size = max_frame;
5199 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5200 netdev->mtu = new_mtu;
5201 if (netif_running(netdev))
5202 e1000e_down(adapter);
5205 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
5206 * means we reserve 2 more, this pushes us to allocate from the next
5208 * i.e. RXBUFFER_2048 --> size-4096 slab
5209 * However with the new *_jumbo_rx* routines, jumbo receives will use
5213 if (max_frame <= 2048)
5214 adapter->rx_buffer_len = 2048;
5216 adapter->rx_buffer_len = 4096;
5218 /* adjust allocation if LPE protects us, and we aren't using SBP */
5219 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5220 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5221 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
5224 if (netif_running(netdev))
5227 e1000e_reset(adapter);
5229 clear_bit(__E1000_RESETTING, &adapter->state);
5234 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5237 struct e1000_adapter *adapter = netdev_priv(netdev);
5238 struct mii_ioctl_data *data = if_mii(ifr);
5240 if (adapter->hw.phy.media_type != e1000_media_type_copper)
5245 data->phy_id = adapter->hw.phy.addr;
5248 e1000_phy_read_status(adapter);
5250 switch (data->reg_num & 0x1F) {
5252 data->val_out = adapter->phy_regs.bmcr;
5255 data->val_out = adapter->phy_regs.bmsr;
5258 data->val_out = (adapter->hw.phy.id >> 16);
5261 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5264 data->val_out = adapter->phy_regs.advertise;
5267 data->val_out = adapter->phy_regs.lpa;
5270 data->val_out = adapter->phy_regs.expansion;
5273 data->val_out = adapter->phy_regs.ctrl1000;
5276 data->val_out = adapter->phy_regs.stat1000;
5279 data->val_out = adapter->phy_regs.estatus;
5292 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5298 return e1000_mii_ioctl(netdev, ifr, cmd);
5304 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5306 struct e1000_hw *hw = &adapter->hw;
5308 u16 phy_reg, wuc_enable;
5311 /* copy MAC RARs to PHY RARs */
5312 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
5314 retval = hw->phy.ops.acquire(hw);
5316 e_err("Could not acquire PHY\n");
5320 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5321 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5325 /* copy MAC MTA to PHY MTA - only needed for pchlan */
5326 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5327 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5328 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5329 (u16)(mac_reg & 0xFFFF));
5330 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5331 (u16)((mac_reg >> 16) & 0xFFFF));
5334 /* configure PHY Rx Control register */
5335 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
5336 mac_reg = er32(RCTL);
5337 if (mac_reg & E1000_RCTL_UPE)
5338 phy_reg |= BM_RCTL_UPE;
5339 if (mac_reg & E1000_RCTL_MPE)
5340 phy_reg |= BM_RCTL_MPE;
5341 phy_reg &= ~(BM_RCTL_MO_MASK);
5342 if (mac_reg & E1000_RCTL_MO_3)
5343 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5344 << BM_RCTL_MO_SHIFT);
5345 if (mac_reg & E1000_RCTL_BAM)
5346 phy_reg |= BM_RCTL_BAM;
5347 if (mac_reg & E1000_RCTL_PMCF)
5348 phy_reg |= BM_RCTL_PMCF;
5349 mac_reg = er32(CTRL);
5350 if (mac_reg & E1000_CTRL_RFCE)
5351 phy_reg |= BM_RCTL_RFCE;
5352 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
5354 /* enable PHY wakeup in MAC register */
5356 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5358 /* configure and enable PHY wakeup in PHY registers */
5359 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5360 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5362 /* activate PHY wakeup */
5363 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5364 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5366 e_err("Could not set PHY Host Wakeup bit\n");
5368 hw->phy.ops.release(hw);
5373 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5376 struct net_device *netdev = pci_get_drvdata(pdev);
5377 struct e1000_adapter *adapter = netdev_priv(netdev);
5378 struct e1000_hw *hw = &adapter->hw;
5379 u32 ctrl, ctrl_ext, rctl, status;
5380 /* Runtime suspend should only enable wakeup for link changes */
5381 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
5384 netif_device_detach(netdev);
5386 if (netif_running(netdev)) {
5387 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5388 e1000e_down(adapter);
5389 e1000_free_irq(adapter);
5391 e1000e_reset_interrupt_capability(adapter);
5393 retval = pci_save_state(pdev);
5397 status = er32(STATUS);
5398 if (status & E1000_STATUS_LU)
5399 wufc &= ~E1000_WUFC_LNKC;
5402 e1000_setup_rctl(adapter);
5403 e1000e_set_rx_mode(netdev);
5405 /* turn on all-multi mode if wake on multicast is enabled */
5406 if (wufc & E1000_WUFC_MC) {
5408 rctl |= E1000_RCTL_MPE;
5413 /* advertise wake from D3Cold */
5414 #define E1000_CTRL_ADVD3WUC 0x00100000
5415 /* phy power management enable */
5416 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5417 ctrl |= E1000_CTRL_ADVD3WUC;
5418 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5419 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
5422 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5423 adapter->hw.phy.media_type ==
5424 e1000_media_type_internal_serdes) {
5425 /* keep the laser running in D3 */
5426 ctrl_ext = er32(CTRL_EXT);
5427 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
5428 ew32(CTRL_EXT, ctrl_ext);
5431 if (adapter->flags & FLAG_IS_ICH)
5432 e1000_suspend_workarounds_ich8lan(&adapter->hw);
5434 /* Allow time for pending master requests to run */
5435 e1000e_disable_pcie_master(&adapter->hw);
5437 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5438 /* enable wakeup by the PHY */
5439 retval = e1000_init_phy_wakeup(adapter, wufc);
5443 /* enable wakeup by the MAC */
5445 ew32(WUC, E1000_WUC_PME_EN);
5452 *enable_wake = !!wufc;
5454 /* make sure adapter isn't asleep if manageability is enabled */
5455 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5456 (hw->mac.ops.check_mng_mode(hw)))
5457 *enable_wake = true;
5459 if (adapter->hw.phy.type == e1000_phy_igp_3)
5460 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5463 * Release control of h/w to f/w. If f/w is AMT enabled, this
5464 * would have already happened in close and is redundant.
5466 e1000e_release_hw_control(adapter);
5468 pci_disable_device(pdev);
5473 static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5475 if (sleep && wake) {
5476 pci_prepare_to_sleep(pdev);
5480 pci_wake_from_d3(pdev, wake);
5481 pci_set_power_state(pdev, PCI_D3hot);
5484 static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5487 struct net_device *netdev = pci_get_drvdata(pdev);
5488 struct e1000_adapter *adapter = netdev_priv(netdev);
5491 * The pci-e switch on some quad port adapters will report a
5492 * correctable error when the MAC transitions from D0 to D3. To
5493 * prevent this we need to mask off the correctable errors on the
5494 * downstream port of the pci-e switch.
5496 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5497 struct pci_dev *us_dev = pdev->bus->self;
5498 int pos = pci_pcie_cap(us_dev);
5501 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5502 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5503 (devctl & ~PCI_EXP_DEVCTL_CERE));
5505 e1000_power_off(pdev, sleep, wake);
5507 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5509 e1000_power_off(pdev, sleep, wake);
5513 #ifdef CONFIG_PCIEASPM
5514 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5516 pci_disable_link_state_locked(pdev, state);
5519 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5525 * Both device and parent should have the same ASPM setting.
5526 * Disable ASPM in downstream component first and then upstream.
5528 pos = pci_pcie_cap(pdev);
5529 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16);
5531 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5533 if (!pdev->bus->self)
5536 pos = pci_pcie_cap(pdev->bus->self);
5537 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16);
5539 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5542 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5544 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5545 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5546 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5548 __e1000e_disable_aspm(pdev, state);
5552 static bool e1000e_pm_ready(struct e1000_adapter *adapter)
5554 return !!adapter->tx_ring->buffer_info;
5557 static int __e1000_resume(struct pci_dev *pdev)
5559 struct net_device *netdev = pci_get_drvdata(pdev);
5560 struct e1000_adapter *adapter = netdev_priv(netdev);
5561 struct e1000_hw *hw = &adapter->hw;
5562 u16 aspm_disable_flag = 0;
5565 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5566 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5567 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5568 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5569 if (aspm_disable_flag)
5570 e1000e_disable_aspm(pdev, aspm_disable_flag);
5572 pci_set_power_state(pdev, PCI_D0);
5573 pci_restore_state(pdev);
5574 pci_save_state(pdev);
5576 e1000e_set_interrupt_capability(adapter);
5577 if (netif_running(netdev)) {
5578 err = e1000_request_irq(adapter);
5583 if (hw->mac.type == e1000_pch2lan)
5584 e1000_resume_workarounds_pchlan(&adapter->hw);
5586 e1000e_power_up_phy(adapter);
5588 /* report the system wakeup cause from S3/S4 */
5589 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5592 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5594 e_info("PHY Wakeup cause - %s\n",
5595 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5596 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5597 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5598 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5599 phy_data & E1000_WUS_LNKC ?
5600 "Link Status Change" : "other");
5602 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5604 u32 wus = er32(WUS);
5606 e_info("MAC Wakeup cause - %s\n",
5607 wus & E1000_WUS_EX ? "Unicast Packet" :
5608 wus & E1000_WUS_MC ? "Multicast Packet" :
5609 wus & E1000_WUS_BC ? "Broadcast Packet" :
5610 wus & E1000_WUS_MAG ? "Magic Packet" :
5611 wus & E1000_WUS_LNKC ? "Link Status Change" :
5617 e1000e_reset(adapter);
5619 e1000_init_manageability_pt(adapter);
5621 if (netif_running(netdev))
5624 netif_device_attach(netdev);
5627 * If the controller has AMT, do not set DRV_LOAD until the interface
5628 * is up. For all other cases, let the f/w know that the h/w is now
5629 * under the control of the driver.
5631 if (!(adapter->flags & FLAG_HAS_AMT))
5632 e1000e_get_hw_control(adapter);
5637 #ifdef CONFIG_PM_SLEEP
5638 static int e1000_suspend(struct device *dev)
5640 struct pci_dev *pdev = to_pci_dev(dev);
5644 retval = __e1000_shutdown(pdev, &wake, false);
5646 e1000_complete_shutdown(pdev, true, wake);
5651 static int e1000_resume(struct device *dev)
5653 struct pci_dev *pdev = to_pci_dev(dev);
5654 struct net_device *netdev = pci_get_drvdata(pdev);
5655 struct e1000_adapter *adapter = netdev_priv(netdev);
5657 if (e1000e_pm_ready(adapter))
5658 adapter->idle_check = true;
5660 return __e1000_resume(pdev);
5662 #endif /* CONFIG_PM_SLEEP */
5664 #ifdef CONFIG_PM_RUNTIME
5665 static int e1000_runtime_suspend(struct device *dev)
5667 struct pci_dev *pdev = to_pci_dev(dev);
5668 struct net_device *netdev = pci_get_drvdata(pdev);
5669 struct e1000_adapter *adapter = netdev_priv(netdev);
5671 if (e1000e_pm_ready(adapter)) {
5674 __e1000_shutdown(pdev, &wake, true);
5680 static int e1000_idle(struct device *dev)
5682 struct pci_dev *pdev = to_pci_dev(dev);
5683 struct net_device *netdev = pci_get_drvdata(pdev);
5684 struct e1000_adapter *adapter = netdev_priv(netdev);
5686 if (!e1000e_pm_ready(adapter))
5689 if (adapter->idle_check) {
5690 adapter->idle_check = false;
5691 if (!e1000e_has_link(adapter))
5692 pm_schedule_suspend(dev, MSEC_PER_SEC);
5698 static int e1000_runtime_resume(struct device *dev)
5700 struct pci_dev *pdev = to_pci_dev(dev);
5701 struct net_device *netdev = pci_get_drvdata(pdev);
5702 struct e1000_adapter *adapter = netdev_priv(netdev);
5704 if (!e1000e_pm_ready(adapter))
5707 adapter->idle_check = !dev->power.runtime_auto;
5708 return __e1000_resume(pdev);
5710 #endif /* CONFIG_PM_RUNTIME */
5711 #endif /* CONFIG_PM */
5713 static void e1000_shutdown(struct pci_dev *pdev)
5717 __e1000_shutdown(pdev, &wake, false);
5719 if (system_state == SYSTEM_POWER_OFF)
5720 e1000_complete_shutdown(pdev, false, wake);
5723 #ifdef CONFIG_NET_POLL_CONTROLLER
5725 static irqreturn_t e1000_intr_msix(int irq, void *data)
5727 struct net_device *netdev = data;
5728 struct e1000_adapter *adapter = netdev_priv(netdev);
5730 if (adapter->msix_entries) {
5731 int vector, msix_irq;
5734 msix_irq = adapter->msix_entries[vector].vector;
5735 disable_irq(msix_irq);
5736 e1000_intr_msix_rx(msix_irq, netdev);
5737 enable_irq(msix_irq);
5740 msix_irq = adapter->msix_entries[vector].vector;
5741 disable_irq(msix_irq);
5742 e1000_intr_msix_tx(msix_irq, netdev);
5743 enable_irq(msix_irq);
5746 msix_irq = adapter->msix_entries[vector].vector;
5747 disable_irq(msix_irq);
5748 e1000_msix_other(msix_irq, netdev);
5749 enable_irq(msix_irq);
5756 * Polling 'interrupt' - used by things like netconsole to send skbs
5757 * without having to re-enable interrupts. It's not called while
5758 * the interrupt routine is executing.
5760 static void e1000_netpoll(struct net_device *netdev)
5762 struct e1000_adapter *adapter = netdev_priv(netdev);
5764 switch (adapter->int_mode) {
5765 case E1000E_INT_MODE_MSIX:
5766 e1000_intr_msix(adapter->pdev->irq, netdev);
5768 case E1000E_INT_MODE_MSI:
5769 disable_irq(adapter->pdev->irq);
5770 e1000_intr_msi(adapter->pdev->irq, netdev);
5771 enable_irq(adapter->pdev->irq);
5773 default: /* E1000E_INT_MODE_LEGACY */
5774 disable_irq(adapter->pdev->irq);
5775 e1000_intr(adapter->pdev->irq, netdev);
5776 enable_irq(adapter->pdev->irq);
5783 * e1000_io_error_detected - called when PCI error is detected
5784 * @pdev: Pointer to PCI device
5785 * @state: The current pci connection state
5787 * This function is called after a PCI bus error affecting
5788 * this device has been detected.
5790 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5791 pci_channel_state_t state)
5793 struct net_device *netdev = pci_get_drvdata(pdev);
5794 struct e1000_adapter *adapter = netdev_priv(netdev);
5796 netif_device_detach(netdev);
5798 if (state == pci_channel_io_perm_failure)
5799 return PCI_ERS_RESULT_DISCONNECT;
5801 if (netif_running(netdev))
5802 e1000e_down(adapter);
5803 pci_disable_device(pdev);
5805 /* Request a slot slot reset. */
5806 return PCI_ERS_RESULT_NEED_RESET;
5810 * e1000_io_slot_reset - called after the pci bus has been reset.
5811 * @pdev: Pointer to PCI device
5813 * Restart the card from scratch, as if from a cold-boot. Implementation
5814 * resembles the first-half of the e1000_resume routine.
5816 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5818 struct net_device *netdev = pci_get_drvdata(pdev);
5819 struct e1000_adapter *adapter = netdev_priv(netdev);
5820 struct e1000_hw *hw = &adapter->hw;
5821 u16 aspm_disable_flag = 0;
5823 pci_ers_result_t result;
5825 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5826 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5827 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5828 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5829 if (aspm_disable_flag)
5830 e1000e_disable_aspm(pdev, aspm_disable_flag);
5832 err = pci_enable_device_mem(pdev);
5835 "Cannot re-enable PCI device after reset.\n");
5836 result = PCI_ERS_RESULT_DISCONNECT;
5838 pci_set_master(pdev);
5839 pdev->state_saved = true;
5840 pci_restore_state(pdev);
5842 pci_enable_wake(pdev, PCI_D3hot, 0);
5843 pci_enable_wake(pdev, PCI_D3cold, 0);
5845 e1000e_reset(adapter);
5847 result = PCI_ERS_RESULT_RECOVERED;
5850 pci_cleanup_aer_uncorrect_error_status(pdev);
5856 * e1000_io_resume - called when traffic can start flowing again.
5857 * @pdev: Pointer to PCI device
5859 * This callback is called when the error recovery driver tells us that
5860 * its OK to resume normal operation. Implementation resembles the
5861 * second-half of the e1000_resume routine.
5863 static void e1000_io_resume(struct pci_dev *pdev)
5865 struct net_device *netdev = pci_get_drvdata(pdev);
5866 struct e1000_adapter *adapter = netdev_priv(netdev);
5868 e1000_init_manageability_pt(adapter);
5870 if (netif_running(netdev)) {
5871 if (e1000e_up(adapter)) {
5873 "can't bring device back up after reset\n");
5878 netif_device_attach(netdev);
5881 * If the controller has AMT, do not set DRV_LOAD until the interface
5882 * is up. For all other cases, let the f/w know that the h/w is now
5883 * under the control of the driver.
5885 if (!(adapter->flags & FLAG_HAS_AMT))
5886 e1000e_get_hw_control(adapter);
5890 static void e1000_print_device_info(struct e1000_adapter *adapter)
5892 struct e1000_hw *hw = &adapter->hw;
5893 struct net_device *netdev = adapter->netdev;
5895 u8 pba_str[E1000_PBANUM_LENGTH];
5897 /* print bus type/speed/width info */
5898 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
5900 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5904 e_info("Intel(R) PRO/%s Network Connection\n",
5905 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
5906 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5907 E1000_PBANUM_LENGTH);
5909 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
5910 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5911 hw->mac.type, hw->phy.type, pba_str);
5914 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5916 struct e1000_hw *hw = &adapter->hw;
5920 if (hw->mac.type != e1000_82573)
5923 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
5924 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
5925 /* Deep Smart Power Down (DSPD) */
5926 dev_warn(&adapter->pdev->dev,
5927 "Warning: detected DSPD enabled in EEPROM\n");
5931 static int e1000_set_features(struct net_device *netdev,
5932 netdev_features_t features)
5934 struct e1000_adapter *adapter = netdev_priv(netdev);
5935 netdev_features_t changed = features ^ netdev->features;
5937 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5938 adapter->flags |= FLAG_TSO_FORCE;
5940 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
5944 if (netif_running(netdev))
5945 e1000e_reinit_locked(adapter);
5947 e1000e_reset(adapter);
5952 static const struct net_device_ops e1000e_netdev_ops = {
5953 .ndo_open = e1000_open,
5954 .ndo_stop = e1000_close,
5955 .ndo_start_xmit = e1000_xmit_frame,
5956 .ndo_get_stats64 = e1000e_get_stats64,
5957 .ndo_set_rx_mode = e1000e_set_rx_mode,
5958 .ndo_set_mac_address = e1000_set_mac,
5959 .ndo_change_mtu = e1000_change_mtu,
5960 .ndo_do_ioctl = e1000_ioctl,
5961 .ndo_tx_timeout = e1000_tx_timeout,
5962 .ndo_validate_addr = eth_validate_addr,
5964 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5965 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5966 #ifdef CONFIG_NET_POLL_CONTROLLER
5967 .ndo_poll_controller = e1000_netpoll,
5969 .ndo_set_features = e1000_set_features,
5973 * e1000_probe - Device Initialization Routine
5974 * @pdev: PCI device information struct
5975 * @ent: entry in e1000_pci_tbl
5977 * Returns 0 on success, negative on failure
5979 * e1000_probe initializes an adapter identified by a pci_dev structure.
5980 * The OS initialization, configuring of the adapter private structure,
5981 * and a hardware reset occur.
5983 static int __devinit e1000_probe(struct pci_dev *pdev,
5984 const struct pci_device_id *ent)
5986 struct net_device *netdev;
5987 struct e1000_adapter *adapter;
5988 struct e1000_hw *hw;
5989 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
5990 resource_size_t mmio_start, mmio_len;
5991 resource_size_t flash_start, flash_len;
5993 static int cards_found;
5994 u16 aspm_disable_flag = 0;
5995 int i, err, pci_using_dac;
5996 u16 eeprom_data = 0;
5997 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5999 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6000 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6001 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
6002 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6003 if (aspm_disable_flag)
6004 e1000e_disable_aspm(pdev, aspm_disable_flag);
6006 err = pci_enable_device_mem(pdev);
6011 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
6013 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
6017 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
6019 err = dma_set_coherent_mask(&pdev->dev,
6022 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
6028 err = pci_request_selected_regions_exclusive(pdev,
6029 pci_select_bars(pdev, IORESOURCE_MEM),
6030 e1000e_driver_name);
6034 /* AER (Advanced Error Reporting) hooks */
6035 pci_enable_pcie_error_reporting(pdev);
6037 pci_set_master(pdev);
6038 /* PCI config space info */
6039 err = pci_save_state(pdev);
6041 goto err_alloc_etherdev;
6044 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6046 goto err_alloc_etherdev;
6048 SET_NETDEV_DEV(netdev, &pdev->dev);
6050 netdev->irq = pdev->irq;
6052 pci_set_drvdata(pdev, netdev);
6053 adapter = netdev_priv(netdev);
6055 adapter->netdev = netdev;
6056 adapter->pdev = pdev;
6058 adapter->pba = ei->pba;
6059 adapter->flags = ei->flags;
6060 adapter->flags2 = ei->flags2;
6061 adapter->hw.adapter = adapter;
6062 adapter->hw.mac.type = ei->mac;
6063 adapter->max_hw_frame_size = ei->max_hw_frame_size;
6064 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6066 mmio_start = pci_resource_start(pdev, 0);
6067 mmio_len = pci_resource_len(pdev, 0);
6070 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6071 if (!adapter->hw.hw_addr)
6074 if ((adapter->flags & FLAG_HAS_FLASH) &&
6075 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6076 flash_start = pci_resource_start(pdev, 1);
6077 flash_len = pci_resource_len(pdev, 1);
6078 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6079 if (!adapter->hw.flash_address)
6083 /* construct the net_device struct */
6084 netdev->netdev_ops = &e1000e_netdev_ops;
6085 e1000e_set_ethtool_ops(netdev);
6086 netdev->watchdog_timeo = 5 * HZ;
6087 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
6088 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
6090 netdev->mem_start = mmio_start;
6091 netdev->mem_end = mmio_start + mmio_len;
6093 adapter->bd_number = cards_found++;
6095 e1000e_check_options(adapter);
6097 /* setup adapter struct */
6098 err = e1000_sw_init(adapter);
6102 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6103 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6104 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6106 err = ei->get_variants(adapter);
6110 if ((adapter->flags & FLAG_IS_ICH) &&
6111 (adapter->flags & FLAG_READ_ONLY_NVM))
6112 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6114 hw->mac.ops.get_bus_info(&adapter->hw);
6116 adapter->hw.phy.autoneg_wait_to_complete = 0;
6118 /* Copper options */
6119 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
6120 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6121 adapter->hw.phy.disable_polarity_correction = 0;
6122 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6125 if (e1000_check_reset_block(&adapter->hw))
6126 e_info("PHY reset is blocked due to SOL/IDER session.\n");
6128 /* Set initial default active device features */
6129 netdev->features = (NETIF_F_SG |
6130 NETIF_F_HW_VLAN_RX |
6131 NETIF_F_HW_VLAN_TX |
6137 /* Set user-changeable features (subset of all device features) */
6138 netdev->hw_features = netdev->features;
6140 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6141 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6143 netdev->vlan_features |= (NETIF_F_SG |
6148 netdev->priv_flags |= IFF_UNICAST_FLT;
6150 if (pci_using_dac) {
6151 netdev->features |= NETIF_F_HIGHDMA;
6152 netdev->vlan_features |= NETIF_F_HIGHDMA;
6155 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6156 adapter->flags |= FLAG_MNG_PT_ENABLED;
6159 * before reading the NVM, reset the controller to
6160 * put the device in a known good starting state
6162 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6165 * systems with ASPM and others may see the checksum fail on the first
6166 * attempt. Let's give it a few tries
6169 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6172 e_err("The NVM Checksum Is Not Valid\n");
6178 e1000_eeprom_checks(adapter);
6180 /* copy the MAC address */
6181 if (e1000e_read_mac_addr(&adapter->hw))
6182 e_err("NVM Read Error while reading MAC address\n");
6184 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6185 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6187 if (!is_valid_ether_addr(netdev->perm_addr)) {
6188 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
6193 init_timer(&adapter->watchdog_timer);
6194 adapter->watchdog_timer.function = e1000_watchdog;
6195 adapter->watchdog_timer.data = (unsigned long) adapter;
6197 init_timer(&adapter->phy_info_timer);
6198 adapter->phy_info_timer.function = e1000_update_phy_info;
6199 adapter->phy_info_timer.data = (unsigned long) adapter;
6201 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6202 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
6203 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6204 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
6205 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
6207 /* Initialize link parameters. User can change them with ethtool */
6208 adapter->hw.mac.autoneg = 1;
6209 adapter->fc_autoneg = true;
6210 adapter->hw.fc.requested_mode = e1000_fc_default;
6211 adapter->hw.fc.current_mode = e1000_fc_default;
6212 adapter->hw.phy.autoneg_advertised = 0x2f;
6214 /* ring size defaults */
6215 adapter->rx_ring->count = 256;
6216 adapter->tx_ring->count = 256;
6219 * Initial Wake on LAN setting - If APM wake is enabled in
6220 * the EEPROM, enable the ACPI Magic Packet filter
6222 if (adapter->flags & FLAG_APME_IN_WUC) {
6223 /* APME bit in EEPROM is mapped to WUC.APME */
6224 eeprom_data = er32(WUC);
6225 eeprom_apme_mask = E1000_WUC_APME;
6226 if ((hw->mac.type > e1000_ich10lan) &&
6227 (eeprom_data & E1000_WUC_PHY_WAKE))
6228 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
6229 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6230 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6231 (adapter->hw.bus.func == 1))
6232 e1000_read_nvm(&adapter->hw,
6233 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6235 e1000_read_nvm(&adapter->hw,
6236 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6239 /* fetch WoL from EEPROM */
6240 if (eeprom_data & eeprom_apme_mask)
6241 adapter->eeprom_wol |= E1000_WUFC_MAG;
6244 * now that we have the eeprom settings, apply the special cases
6245 * where the eeprom may be wrong or the board simply won't support
6246 * wake on lan on a particular port
6248 if (!(adapter->flags & FLAG_HAS_WOL))
6249 adapter->eeprom_wol = 0;
6251 /* initialize the wol settings based on the eeprom settings */
6252 adapter->wol = adapter->eeprom_wol;
6253 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
6255 /* save off EEPROM version number */
6256 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6258 /* reset the hardware with the new settings */
6259 e1000e_reset(adapter);
6262 * If the controller has AMT, do not set DRV_LOAD until the interface
6263 * is up. For all other cases, let the f/w know that the h/w is now
6264 * under the control of the driver.
6266 if (!(adapter->flags & FLAG_HAS_AMT))
6267 e1000e_get_hw_control(adapter);
6269 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
6270 err = register_netdev(netdev);
6274 /* carrier off reporting is important to ethtool even BEFORE open */
6275 netif_carrier_off(netdev);
6277 e1000_print_device_info(adapter);
6279 if (pci_dev_run_wake(pdev))
6280 pm_runtime_put_noidle(&pdev->dev);
6285 if (!(adapter->flags & FLAG_HAS_AMT))
6286 e1000e_release_hw_control(adapter);
6288 if (!e1000_check_reset_block(&adapter->hw))
6289 e1000_phy_hw_reset(&adapter->hw);
6291 kfree(adapter->tx_ring);
6292 kfree(adapter->rx_ring);
6294 if (adapter->hw.flash_address)
6295 iounmap(adapter->hw.flash_address);
6296 e1000e_reset_interrupt_capability(adapter);
6298 iounmap(adapter->hw.hw_addr);
6300 free_netdev(netdev);
6302 pci_release_selected_regions(pdev,
6303 pci_select_bars(pdev, IORESOURCE_MEM));
6306 pci_disable_device(pdev);
6311 * e1000_remove - Device Removal Routine
6312 * @pdev: PCI device information struct
6314 * e1000_remove is called by the PCI subsystem to alert the driver
6315 * that it should release a PCI device. The could be caused by a
6316 * Hot-Plug event, or because the driver is going to be removed from
6319 static void __devexit e1000_remove(struct pci_dev *pdev)
6321 struct net_device *netdev = pci_get_drvdata(pdev);
6322 struct e1000_adapter *adapter = netdev_priv(netdev);
6323 bool down = test_bit(__E1000_DOWN, &adapter->state);
6326 * The timers may be rescheduled, so explicitly disable them
6327 * from being rescheduled.
6330 set_bit(__E1000_DOWN, &adapter->state);
6331 del_timer_sync(&adapter->watchdog_timer);
6332 del_timer_sync(&adapter->phy_info_timer);
6334 cancel_work_sync(&adapter->reset_task);
6335 cancel_work_sync(&adapter->watchdog_task);
6336 cancel_work_sync(&adapter->downshift_task);
6337 cancel_work_sync(&adapter->update_phy_task);
6338 cancel_work_sync(&adapter->print_hang_task);
6340 if (!(netdev->flags & IFF_UP))
6341 e1000_power_down_phy(adapter);
6343 /* Don't lie to e1000_close() down the road. */
6345 clear_bit(__E1000_DOWN, &adapter->state);
6346 unregister_netdev(netdev);
6348 if (pci_dev_run_wake(pdev))
6349 pm_runtime_get_noresume(&pdev->dev);
6352 * Release control of h/w to f/w. If f/w is AMT enabled, this
6353 * would have already happened in close and is redundant.
6355 e1000e_release_hw_control(adapter);
6357 e1000e_reset_interrupt_capability(adapter);
6358 kfree(adapter->tx_ring);
6359 kfree(adapter->rx_ring);
6361 iounmap(adapter->hw.hw_addr);
6362 if (adapter->hw.flash_address)
6363 iounmap(adapter->hw.flash_address);
6364 pci_release_selected_regions(pdev,
6365 pci_select_bars(pdev, IORESOURCE_MEM));
6367 free_netdev(netdev);
6370 pci_disable_pcie_error_reporting(pdev);
6372 pci_disable_device(pdev);
6375 /* PCI Error Recovery (ERS) */
6376 static struct pci_error_handlers e1000_err_handler = {
6377 .error_detected = e1000_io_error_detected,
6378 .slot_reset = e1000_io_slot_reset,
6379 .resume = e1000_io_resume,
6382 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
6383 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6384 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6385 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6386 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6387 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6388 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
6389 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6390 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6391 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
6393 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6394 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6395 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6396 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
6398 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6399 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6400 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
6402 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
6403 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
6404 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
6406 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6407 board_80003es2lan },
6408 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6409 board_80003es2lan },
6410 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6411 board_80003es2lan },
6412 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6413 board_80003es2lan },
6415 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6416 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6417 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6418 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6419 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6420 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6421 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
6422 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
6424 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6425 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6426 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6427 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6428 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
6429 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
6430 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6431 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6432 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6434 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6435 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6436 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
6438 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6439 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
6440 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
6442 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6443 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6444 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6445 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6447 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6448 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6450 { } /* terminate list */
6452 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6455 static const struct dev_pm_ops e1000_pm_ops = {
6456 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6457 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6458 e1000_runtime_resume, e1000_idle)
6462 /* PCI Device API Driver */
6463 static struct pci_driver e1000_driver = {
6464 .name = e1000e_driver_name,
6465 .id_table = e1000_pci_tbl,
6466 .probe = e1000_probe,
6467 .remove = __devexit_p(e1000_remove),
6469 .driver.pm = &e1000_pm_ops,
6471 .shutdown = e1000_shutdown,
6472 .err_handler = &e1000_err_handler
6476 * e1000_init_module - Driver Registration Routine
6478 * e1000_init_module is the first routine called when the driver is
6479 * loaded. All it does is register with the PCI subsystem.
6481 static int __init e1000_init_module(void)
6484 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6485 e1000e_driver_version);
6486 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
6487 ret = pci_register_driver(&e1000_driver);
6491 module_init(e1000_init_module);
6494 * e1000_exit_module - Driver Exit Cleanup Routine
6496 * e1000_exit_module is called just before the driver is removed
6499 static void __exit e1000_exit_module(void)
6501 pci_unregister_driver(&e1000_driver);
6503 module_exit(e1000_exit_module);
6506 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6507 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6508 MODULE_LICENSE("GPL");
6509 MODULE_VERSION(DRV_VERSION);