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
, KM_SKB_DATA_SOFTIRQ
);
1281 memcpy(skb_tail_pointer(skb
), vaddr
, l1
);
1282 kunmap_atomic(vaddr
, KM_SKB_DATA_SOFTIRQ
);
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 KM_SKB_DATA_SOFTIRQ
);
1475 memcpy(skb_tail_pointer(skb
), vaddr
,
1477 kunmap_atomic(vaddr
,
1478 KM_SKB_DATA_SOFTIRQ
);
1479 /* re-use the page, so don't erase
1480 * buffer_info->page */
1481 skb_put(skb
, length
);
1483 skb_fill_page_desc(skb
, 0,
1484 buffer_info
->page
, 0,
1486 e1000_consume_page(buffer_info
, skb
,
1492 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1493 e1000_rx_checksum(adapter
, staterr
,
1494 le16_to_cpu(rx_desc
->wb
.lower
.hi_dword
.
1495 csum_ip
.csum
), skb
);
1497 /* probably a little skewed due to removing CRC */
1498 total_rx_bytes
+= skb
->len
;
1501 /* eth type trans needs skb->data to point to something */
1502 if (!pskb_may_pull(skb
, ETH_HLEN
)) {
1503 e_err("pskb_may_pull failed.\n");
1504 dev_kfree_skb_irq(skb
);
1508 e1000_receive_skb(adapter
, netdev
, skb
, staterr
,
1509 rx_desc
->wb
.upper
.vlan
);
1512 rx_desc
->wb
.upper
.status_error
&= cpu_to_le32(~0xFF);
1514 /* return some buffers to hardware, one at a time is too slow */
1515 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
1516 adapter
->alloc_rx_buf(adapter
, cleaned_count
,
1521 /* use prefetched values */
1523 buffer_info
= next_buffer
;
1525 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1527 rx_ring
->next_to_clean
= i
;
1529 cleaned_count
= e1000_desc_unused(rx_ring
);
1531 adapter
->alloc_rx_buf(adapter
, cleaned_count
, GFP_ATOMIC
);
1533 adapter
->total_rx_bytes
+= total_rx_bytes
;
1534 adapter
->total_rx_packets
+= total_rx_packets
;
1539 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1540 * @adapter: board private structure
1542 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
)
1544 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1545 struct e1000_buffer
*buffer_info
;
1546 struct e1000_ps_page
*ps_page
;
1547 struct pci_dev
*pdev
= adapter
->pdev
;
1550 /* Free all the Rx ring sk_buffs */
1551 for (i
= 0; i
< rx_ring
->count
; i
++) {
1552 buffer_info
= &rx_ring
->buffer_info
[i
];
1553 if (buffer_info
->dma
) {
1554 if (adapter
->clean_rx
== e1000_clean_rx_irq
)
1555 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
1556 adapter
->rx_buffer_len
,
1558 else if (adapter
->clean_rx
== e1000_clean_jumbo_rx_irq
)
1559 dma_unmap_page(&pdev
->dev
, buffer_info
->dma
,
1562 else if (adapter
->clean_rx
== e1000_clean_rx_irq_ps
)
1563 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
1564 adapter
->rx_ps_bsize0
,
1566 buffer_info
->dma
= 0;
1569 if (buffer_info
->page
) {
1570 put_page(buffer_info
->page
);
1571 buffer_info
->page
= NULL
;
1574 if (buffer_info
->skb
) {
1575 dev_kfree_skb(buffer_info
->skb
);
1576 buffer_info
->skb
= NULL
;
1579 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
1580 ps_page
= &buffer_info
->ps_pages
[j
];
1583 dma_unmap_page(&pdev
->dev
, ps_page
->dma
, PAGE_SIZE
,
1586 put_page(ps_page
->page
);
1587 ps_page
->page
= NULL
;
1591 /* there also may be some cached data from a chained receive */
1592 if (rx_ring
->rx_skb_top
) {
1593 dev_kfree_skb(rx_ring
->rx_skb_top
);
1594 rx_ring
->rx_skb_top
= NULL
;
1597 /* Zero out the descriptor ring */
1598 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1600 rx_ring
->next_to_clean
= 0;
1601 rx_ring
->next_to_use
= 0;
1602 adapter
->flags2
&= ~FLAG2_IS_DISCARDING
;
1604 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1605 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1608 static void e1000e_downshift_workaround(struct work_struct
*work
)
1610 struct e1000_adapter
*adapter
= container_of(work
,
1611 struct e1000_adapter
, downshift_task
);
1613 if (test_bit(__E1000_DOWN
, &adapter
->state
))
1616 e1000e_gig_downshift_workaround_ich8lan(&adapter
->hw
);
1620 * e1000_intr_msi - Interrupt Handler
1621 * @irq: interrupt number
1622 * @data: pointer to a network interface device structure
1624 static irqreturn_t
e1000_intr_msi(int irq
, void *data
)
1626 struct net_device
*netdev
= data
;
1627 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1628 struct e1000_hw
*hw
= &adapter
->hw
;
1629 u32 icr
= er32(ICR
);
1632 * read ICR disables interrupts using IAM
1635 if (icr
& E1000_ICR_LSC
) {
1636 hw
->mac
.get_link_status
= 1;
1638 * ICH8 workaround-- Call gig speed drop workaround on cable
1639 * disconnect (LSC) before accessing any PHY registers
1641 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
1642 (!(er32(STATUS
) & E1000_STATUS_LU
)))
1643 schedule_work(&adapter
->downshift_task
);
1646 * 80003ES2LAN workaround-- For packet buffer work-around on
1647 * link down event; disable receives here in the ISR and reset
1648 * adapter in watchdog
1650 if (netif_carrier_ok(netdev
) &&
1651 adapter
->flags
& FLAG_RX_NEEDS_RESTART
) {
1652 /* disable receives */
1653 u32 rctl
= er32(RCTL
);
1654 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1655 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
1657 /* guard against interrupt when we're going down */
1658 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1659 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1662 if (napi_schedule_prep(&adapter
->napi
)) {
1663 adapter
->total_tx_bytes
= 0;
1664 adapter
->total_tx_packets
= 0;
1665 adapter
->total_rx_bytes
= 0;
1666 adapter
->total_rx_packets
= 0;
1667 __napi_schedule(&adapter
->napi
);
1674 * e1000_intr - Interrupt Handler
1675 * @irq: interrupt number
1676 * @data: pointer to a network interface device structure
1678 static irqreturn_t
e1000_intr(int irq
, void *data
)
1680 struct net_device
*netdev
= data
;
1681 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1682 struct e1000_hw
*hw
= &adapter
->hw
;
1683 u32 rctl
, icr
= er32(ICR
);
1685 if (!icr
|| test_bit(__E1000_DOWN
, &adapter
->state
))
1686 return IRQ_NONE
; /* Not our interrupt */
1689 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1690 * not set, then the adapter didn't send an interrupt
1692 if (!(icr
& E1000_ICR_INT_ASSERTED
))
1696 * Interrupt Auto-Mask...upon reading ICR,
1697 * interrupts are masked. No need for the
1701 if (icr
& E1000_ICR_LSC
) {
1702 hw
->mac
.get_link_status
= 1;
1704 * ICH8 workaround-- Call gig speed drop workaround on cable
1705 * disconnect (LSC) before accessing any PHY registers
1707 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
1708 (!(er32(STATUS
) & E1000_STATUS_LU
)))
1709 schedule_work(&adapter
->downshift_task
);
1712 * 80003ES2LAN workaround--
1713 * For packet buffer work-around on link down event;
1714 * disable receives here in the ISR and
1715 * reset adapter in watchdog
1717 if (netif_carrier_ok(netdev
) &&
1718 (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)) {
1719 /* disable receives */
1721 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1722 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
1724 /* guard against interrupt when we're going down */
1725 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1726 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1729 if (napi_schedule_prep(&adapter
->napi
)) {
1730 adapter
->total_tx_bytes
= 0;
1731 adapter
->total_tx_packets
= 0;
1732 adapter
->total_rx_bytes
= 0;
1733 adapter
->total_rx_packets
= 0;
1734 __napi_schedule(&adapter
->napi
);
1740 static irqreturn_t
e1000_msix_other(int irq
, void *data
)
1742 struct net_device
*netdev
= data
;
1743 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1744 struct e1000_hw
*hw
= &adapter
->hw
;
1745 u32 icr
= er32(ICR
);
1747 if (!(icr
& E1000_ICR_INT_ASSERTED
)) {
1748 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1749 ew32(IMS
, E1000_IMS_OTHER
);
1753 if (icr
& adapter
->eiac_mask
)
1754 ew32(ICS
, (icr
& adapter
->eiac_mask
));
1756 if (icr
& E1000_ICR_OTHER
) {
1757 if (!(icr
& E1000_ICR_LSC
))
1758 goto no_link_interrupt
;
1759 hw
->mac
.get_link_status
= 1;
1760 /* guard against interrupt when we're going down */
1761 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1762 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1766 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1767 ew32(IMS
, E1000_IMS_LSC
| E1000_IMS_OTHER
);
1773 static irqreturn_t
e1000_intr_msix_tx(int irq
, void *data
)
1775 struct net_device
*netdev
= data
;
1776 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1777 struct e1000_hw
*hw
= &adapter
->hw
;
1778 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1781 adapter
->total_tx_bytes
= 0;
1782 adapter
->total_tx_packets
= 0;
1784 if (!e1000_clean_tx_irq(adapter
))
1785 /* Ring was not completely cleaned, so fire another interrupt */
1786 ew32(ICS
, tx_ring
->ims_val
);
1791 static irqreturn_t
e1000_intr_msix_rx(int irq
, void *data
)
1793 struct net_device
*netdev
= data
;
1794 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1796 /* Write the ITR value calculated at the end of the
1797 * previous interrupt.
1799 if (adapter
->rx_ring
->set_itr
) {
1800 writel(1000000000 / (adapter
->rx_ring
->itr_val
* 256),
1801 adapter
->hw
.hw_addr
+ adapter
->rx_ring
->itr_register
);
1802 adapter
->rx_ring
->set_itr
= 0;
1805 if (napi_schedule_prep(&adapter
->napi
)) {
1806 adapter
->total_rx_bytes
= 0;
1807 adapter
->total_rx_packets
= 0;
1808 __napi_schedule(&adapter
->napi
);
1814 * e1000_configure_msix - Configure MSI-X hardware
1816 * e1000_configure_msix sets up the hardware to properly
1817 * generate MSI-X interrupts.
1819 static void e1000_configure_msix(struct e1000_adapter
*adapter
)
1821 struct e1000_hw
*hw
= &adapter
->hw
;
1822 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1823 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1825 u32 ctrl_ext
, ivar
= 0;
1827 adapter
->eiac_mask
= 0;
1829 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1830 if (hw
->mac
.type
== e1000_82574
) {
1831 u32 rfctl
= er32(RFCTL
);
1832 rfctl
|= E1000_RFCTL_ACK_DIS
;
1836 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1837 /* Configure Rx vector */
1838 rx_ring
->ims_val
= E1000_IMS_RXQ0
;
1839 adapter
->eiac_mask
|= rx_ring
->ims_val
;
1840 if (rx_ring
->itr_val
)
1841 writel(1000000000 / (rx_ring
->itr_val
* 256),
1842 hw
->hw_addr
+ rx_ring
->itr_register
);
1844 writel(1, hw
->hw_addr
+ rx_ring
->itr_register
);
1845 ivar
= E1000_IVAR_INT_ALLOC_VALID
| vector
;
1847 /* Configure Tx vector */
1848 tx_ring
->ims_val
= E1000_IMS_TXQ0
;
1850 if (tx_ring
->itr_val
)
1851 writel(1000000000 / (tx_ring
->itr_val
* 256),
1852 hw
->hw_addr
+ tx_ring
->itr_register
);
1854 writel(1, hw
->hw_addr
+ tx_ring
->itr_register
);
1855 adapter
->eiac_mask
|= tx_ring
->ims_val
;
1856 ivar
|= ((E1000_IVAR_INT_ALLOC_VALID
| vector
) << 8);
1858 /* set vector for Other Causes, e.g. link changes */
1860 ivar
|= ((E1000_IVAR_INT_ALLOC_VALID
| vector
) << 16);
1861 if (rx_ring
->itr_val
)
1862 writel(1000000000 / (rx_ring
->itr_val
* 256),
1863 hw
->hw_addr
+ E1000_EITR_82574(vector
));
1865 writel(1, hw
->hw_addr
+ E1000_EITR_82574(vector
));
1867 /* Cause Tx interrupts on every write back */
1872 /* enable MSI-X PBA support */
1873 ctrl_ext
= er32(CTRL_EXT
);
1874 ctrl_ext
|= E1000_CTRL_EXT_PBA_CLR
;
1876 /* Auto-Mask Other interrupts upon ICR read */
1877 #define E1000_EIAC_MASK_82574 0x01F00000
1878 ew32(IAM
, ~E1000_EIAC_MASK_82574
| E1000_IMS_OTHER
);
1879 ctrl_ext
|= E1000_CTRL_EXT_EIAME
;
1880 ew32(CTRL_EXT
, ctrl_ext
);
1884 void e1000e_reset_interrupt_capability(struct e1000_adapter
*adapter
)
1886 if (adapter
->msix_entries
) {
1887 pci_disable_msix(adapter
->pdev
);
1888 kfree(adapter
->msix_entries
);
1889 adapter
->msix_entries
= NULL
;
1890 } else if (adapter
->flags
& FLAG_MSI_ENABLED
) {
1891 pci_disable_msi(adapter
->pdev
);
1892 adapter
->flags
&= ~FLAG_MSI_ENABLED
;
1897 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1899 * Attempt to configure interrupts using the best available
1900 * capabilities of the hardware and kernel.
1902 void e1000e_set_interrupt_capability(struct e1000_adapter
*adapter
)
1907 switch (adapter
->int_mode
) {
1908 case E1000E_INT_MODE_MSIX
:
1909 if (adapter
->flags
& FLAG_HAS_MSIX
) {
1910 adapter
->num_vectors
= 3; /* RxQ0, TxQ0 and other */
1911 adapter
->msix_entries
= kcalloc(adapter
->num_vectors
,
1912 sizeof(struct msix_entry
),
1914 if (adapter
->msix_entries
) {
1915 for (i
= 0; i
< adapter
->num_vectors
; i
++)
1916 adapter
->msix_entries
[i
].entry
= i
;
1918 err
= pci_enable_msix(adapter
->pdev
,
1919 adapter
->msix_entries
,
1920 adapter
->num_vectors
);
1924 /* MSI-X failed, so fall through and try MSI */
1925 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
1926 e1000e_reset_interrupt_capability(adapter
);
1928 adapter
->int_mode
= E1000E_INT_MODE_MSI
;
1930 case E1000E_INT_MODE_MSI
:
1931 if (!pci_enable_msi(adapter
->pdev
)) {
1932 adapter
->flags
|= FLAG_MSI_ENABLED
;
1934 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
1935 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
1938 case E1000E_INT_MODE_LEGACY
:
1939 /* Don't do anything; this is the system default */
1943 /* store the number of vectors being used */
1944 adapter
->num_vectors
= 1;
1948 * e1000_request_msix - Initialize MSI-X interrupts
1950 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1953 static int e1000_request_msix(struct e1000_adapter
*adapter
)
1955 struct net_device
*netdev
= adapter
->netdev
;
1956 int err
= 0, vector
= 0;
1958 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
1959 snprintf(adapter
->rx_ring
->name
,
1960 sizeof(adapter
->rx_ring
->name
) - 1,
1961 "%s-rx-0", netdev
->name
);
1963 memcpy(adapter
->rx_ring
->name
, netdev
->name
, IFNAMSIZ
);
1964 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1965 e1000_intr_msix_rx
, 0, adapter
->rx_ring
->name
,
1969 adapter
->rx_ring
->itr_register
= E1000_EITR_82574(vector
);
1970 adapter
->rx_ring
->itr_val
= adapter
->itr
;
1973 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
1974 snprintf(adapter
->tx_ring
->name
,
1975 sizeof(adapter
->tx_ring
->name
) - 1,
1976 "%s-tx-0", netdev
->name
);
1978 memcpy(adapter
->tx_ring
->name
, netdev
->name
, IFNAMSIZ
);
1979 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1980 e1000_intr_msix_tx
, 0, adapter
->tx_ring
->name
,
1984 adapter
->tx_ring
->itr_register
= E1000_EITR_82574(vector
);
1985 adapter
->tx_ring
->itr_val
= adapter
->itr
;
1988 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1989 e1000_msix_other
, 0, netdev
->name
, netdev
);
1993 e1000_configure_msix(adapter
);
2000 * e1000_request_irq - initialize interrupts
2002 * Attempts to configure interrupts using the best available
2003 * capabilities of the hardware and kernel.
2005 static int e1000_request_irq(struct e1000_adapter
*adapter
)
2007 struct net_device
*netdev
= adapter
->netdev
;
2010 if (adapter
->msix_entries
) {
2011 err
= e1000_request_msix(adapter
);
2014 /* fall back to MSI */
2015 e1000e_reset_interrupt_capability(adapter
);
2016 adapter
->int_mode
= E1000E_INT_MODE_MSI
;
2017 e1000e_set_interrupt_capability(adapter
);
2019 if (adapter
->flags
& FLAG_MSI_ENABLED
) {
2020 err
= request_irq(adapter
->pdev
->irq
, e1000_intr_msi
, 0,
2021 netdev
->name
, netdev
);
2025 /* fall back to legacy interrupt */
2026 e1000e_reset_interrupt_capability(adapter
);
2027 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
2030 err
= request_irq(adapter
->pdev
->irq
, e1000_intr
, IRQF_SHARED
,
2031 netdev
->name
, netdev
);
2033 e_err("Unable to allocate interrupt, Error: %d\n", err
);
2038 static void e1000_free_irq(struct e1000_adapter
*adapter
)
2040 struct net_device
*netdev
= adapter
->netdev
;
2042 if (adapter
->msix_entries
) {
2045 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
2048 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
2051 /* Other Causes interrupt vector */
2052 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
2056 free_irq(adapter
->pdev
->irq
, netdev
);
2060 * e1000_irq_disable - Mask off interrupt generation on the NIC
2062 static void e1000_irq_disable(struct e1000_adapter
*adapter
)
2064 struct e1000_hw
*hw
= &adapter
->hw
;
2067 if (adapter
->msix_entries
)
2068 ew32(EIAC_82574
, 0);
2071 if (adapter
->msix_entries
) {
2073 for (i
= 0; i
< adapter
->num_vectors
; i
++)
2074 synchronize_irq(adapter
->msix_entries
[i
].vector
);
2076 synchronize_irq(adapter
->pdev
->irq
);
2081 * e1000_irq_enable - Enable default interrupt generation settings
2083 static void e1000_irq_enable(struct e1000_adapter
*adapter
)
2085 struct e1000_hw
*hw
= &adapter
->hw
;
2087 if (adapter
->msix_entries
) {
2088 ew32(EIAC_82574
, adapter
->eiac_mask
& E1000_EIAC_MASK_82574
);
2089 ew32(IMS
, adapter
->eiac_mask
| E1000_IMS_OTHER
| E1000_IMS_LSC
);
2091 ew32(IMS
, IMS_ENABLE_MASK
);
2097 * e1000e_get_hw_control - get control of the h/w from f/w
2098 * @adapter: address of board private structure
2100 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2101 * For ASF and Pass Through versions of f/w this means that
2102 * the driver is loaded. For AMT version (only with 82573)
2103 * of the f/w this means that the network i/f is open.
2105 void e1000e_get_hw_control(struct e1000_adapter
*adapter
)
2107 struct e1000_hw
*hw
= &adapter
->hw
;
2111 /* Let firmware know the driver has taken over */
2112 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
2114 ew32(SWSM
, swsm
| E1000_SWSM_DRV_LOAD
);
2115 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
2116 ctrl_ext
= er32(CTRL_EXT
);
2117 ew32(CTRL_EXT
, ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
2122 * e1000e_release_hw_control - release control of the h/w to f/w
2123 * @adapter: address of board private structure
2125 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2126 * For ASF and Pass Through versions of f/w this means that the
2127 * driver is no longer loaded. For AMT version (only with 82573) i
2128 * of the f/w this means that the network i/f is closed.
2131 void e1000e_release_hw_control(struct e1000_adapter
*adapter
)
2133 struct e1000_hw
*hw
= &adapter
->hw
;
2137 /* Let firmware taken over control of h/w */
2138 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
2140 ew32(SWSM
, swsm
& ~E1000_SWSM_DRV_LOAD
);
2141 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
2142 ctrl_ext
= er32(CTRL_EXT
);
2143 ew32(CTRL_EXT
, ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
2148 * @e1000_alloc_ring - allocate memory for a ring structure
2150 static int e1000_alloc_ring_dma(struct e1000_adapter
*adapter
,
2151 struct e1000_ring
*ring
)
2153 struct pci_dev
*pdev
= adapter
->pdev
;
2155 ring
->desc
= dma_alloc_coherent(&pdev
->dev
, ring
->size
, &ring
->dma
,
2164 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2165 * @adapter: board private structure
2167 * Return 0 on success, negative on failure
2169 int e1000e_setup_tx_resources(struct e1000_adapter
*adapter
)
2171 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2172 int err
= -ENOMEM
, size
;
2174 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
2175 tx_ring
->buffer_info
= vzalloc(size
);
2176 if (!tx_ring
->buffer_info
)
2179 /* round up to nearest 4K */
2180 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
2181 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
2183 err
= e1000_alloc_ring_dma(adapter
, tx_ring
);
2187 tx_ring
->next_to_use
= 0;
2188 tx_ring
->next_to_clean
= 0;
2192 vfree(tx_ring
->buffer_info
);
2193 e_err("Unable to allocate memory for the transmit descriptor ring\n");
2198 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2199 * @adapter: board private structure
2201 * Returns 0 on success, negative on failure
2203 int e1000e_setup_rx_resources(struct e1000_adapter
*adapter
)
2205 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
2206 struct e1000_buffer
*buffer_info
;
2207 int i
, size
, desc_len
, err
= -ENOMEM
;
2209 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2210 rx_ring
->buffer_info
= vzalloc(size
);
2211 if (!rx_ring
->buffer_info
)
2214 for (i
= 0; i
< rx_ring
->count
; i
++) {
2215 buffer_info
= &rx_ring
->buffer_info
[i
];
2216 buffer_info
->ps_pages
= kcalloc(PS_PAGE_BUFFERS
,
2217 sizeof(struct e1000_ps_page
),
2219 if (!buffer_info
->ps_pages
)
2223 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
2225 /* Round up to nearest 4K */
2226 rx_ring
->size
= rx_ring
->count
* desc_len
;
2227 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
2229 err
= e1000_alloc_ring_dma(adapter
, rx_ring
);
2233 rx_ring
->next_to_clean
= 0;
2234 rx_ring
->next_to_use
= 0;
2235 rx_ring
->rx_skb_top
= NULL
;
2240 for (i
= 0; i
< rx_ring
->count
; i
++) {
2241 buffer_info
= &rx_ring
->buffer_info
[i
];
2242 kfree(buffer_info
->ps_pages
);
2245 vfree(rx_ring
->buffer_info
);
2246 e_err("Unable to allocate memory for the receive descriptor ring\n");
2251 * e1000_clean_tx_ring - Free Tx Buffers
2252 * @adapter: board private structure
2254 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
)
2256 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2257 struct e1000_buffer
*buffer_info
;
2261 for (i
= 0; i
< tx_ring
->count
; i
++) {
2262 buffer_info
= &tx_ring
->buffer_info
[i
];
2263 e1000_put_txbuf(adapter
, buffer_info
);
2266 netdev_reset_queue(adapter
->netdev
);
2267 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
2268 memset(tx_ring
->buffer_info
, 0, size
);
2270 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2272 tx_ring
->next_to_use
= 0;
2273 tx_ring
->next_to_clean
= 0;
2275 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
2276 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
2280 * e1000e_free_tx_resources - Free Tx Resources per Queue
2281 * @adapter: board private structure
2283 * Free all transmit software resources
2285 void e1000e_free_tx_resources(struct e1000_adapter
*adapter
)
2287 struct pci_dev
*pdev
= adapter
->pdev
;
2288 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2290 e1000_clean_tx_ring(adapter
);
2292 vfree(tx_ring
->buffer_info
);
2293 tx_ring
->buffer_info
= NULL
;
2295 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
2297 tx_ring
->desc
= NULL
;
2301 * e1000e_free_rx_resources - Free Rx Resources
2302 * @adapter: board private structure
2304 * Free all receive software resources
2307 void e1000e_free_rx_resources(struct e1000_adapter
*adapter
)
2309 struct pci_dev
*pdev
= adapter
->pdev
;
2310 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
2313 e1000_clean_rx_ring(adapter
);
2315 for (i
= 0; i
< rx_ring
->count
; i
++)
2316 kfree(rx_ring
->buffer_info
[i
].ps_pages
);
2318 vfree(rx_ring
->buffer_info
);
2319 rx_ring
->buffer_info
= NULL
;
2321 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
2323 rx_ring
->desc
= NULL
;
2327 * e1000_update_itr - update the dynamic ITR value based on statistics
2328 * @adapter: pointer to adapter
2329 * @itr_setting: current adapter->itr
2330 * @packets: the number of packets during this measurement interval
2331 * @bytes: the number of bytes during this measurement interval
2333 * Stores a new ITR value based on packets and byte
2334 * counts during the last interrupt. The advantage of per interrupt
2335 * computation is faster updates and more accurate ITR for the current
2336 * traffic pattern. Constants in this function were computed
2337 * based on theoretical maximum wire speed and thresholds were set based
2338 * on testing data as well as attempting to minimize response time
2339 * while increasing bulk throughput. This functionality is controlled
2340 * by the InterruptThrottleRate module parameter.
2342 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
2343 u16 itr_setting
, int packets
,
2346 unsigned int retval
= itr_setting
;
2349 goto update_itr_done
;
2351 switch (itr_setting
) {
2352 case lowest_latency
:
2353 /* handle TSO and jumbo frames */
2354 if (bytes
/packets
> 8000)
2355 retval
= bulk_latency
;
2356 else if ((packets
< 5) && (bytes
> 512))
2357 retval
= low_latency
;
2359 case low_latency
: /* 50 usec aka 20000 ints/s */
2360 if (bytes
> 10000) {
2361 /* this if handles the TSO accounting */
2362 if (bytes
/packets
> 8000)
2363 retval
= bulk_latency
;
2364 else if ((packets
< 10) || ((bytes
/packets
) > 1200))
2365 retval
= bulk_latency
;
2366 else if ((packets
> 35))
2367 retval
= lowest_latency
;
2368 } else if (bytes
/packets
> 2000) {
2369 retval
= bulk_latency
;
2370 } else if (packets
<= 2 && bytes
< 512) {
2371 retval
= lowest_latency
;
2374 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2375 if (bytes
> 25000) {
2377 retval
= low_latency
;
2378 } else if (bytes
< 6000) {
2379 retval
= low_latency
;
2388 static void e1000_set_itr(struct e1000_adapter
*adapter
)
2390 struct e1000_hw
*hw
= &adapter
->hw
;
2392 u32 new_itr
= adapter
->itr
;
2394 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2395 if (adapter
->link_speed
!= SPEED_1000
) {
2401 if (adapter
->flags2
& FLAG2_DISABLE_AIM
) {
2406 adapter
->tx_itr
= e1000_update_itr(adapter
,
2408 adapter
->total_tx_packets
,
2409 adapter
->total_tx_bytes
);
2410 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2411 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
2412 adapter
->tx_itr
= low_latency
;
2414 adapter
->rx_itr
= e1000_update_itr(adapter
,
2416 adapter
->total_rx_packets
,
2417 adapter
->total_rx_bytes
);
2418 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2419 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
2420 adapter
->rx_itr
= low_latency
;
2422 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2424 switch (current_itr
) {
2425 /* counts and packets in update_itr are dependent on these numbers */
2426 case lowest_latency
:
2430 new_itr
= 20000; /* aka hwitr = ~200 */
2440 if (new_itr
!= adapter
->itr
) {
2442 * this attempts to bias the interrupt rate towards Bulk
2443 * by adding intermediate steps when interrupt rate is
2446 new_itr
= new_itr
> adapter
->itr
?
2447 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2449 adapter
->itr
= new_itr
;
2450 adapter
->rx_ring
->itr_val
= new_itr
;
2451 if (adapter
->msix_entries
)
2452 adapter
->rx_ring
->set_itr
= 1;
2455 ew32(ITR
, 1000000000 / (new_itr
* 256));
2462 * e1000_alloc_queues - Allocate memory for all rings
2463 * @adapter: board private structure to initialize
2465 static int __devinit
e1000_alloc_queues(struct e1000_adapter
*adapter
)
2467 adapter
->tx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
2468 if (!adapter
->tx_ring
)
2471 adapter
->rx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
2472 if (!adapter
->rx_ring
)
2477 e_err("Unable to allocate memory for queues\n");
2478 kfree(adapter
->rx_ring
);
2479 kfree(adapter
->tx_ring
);
2484 * e1000_clean - NAPI Rx polling callback
2485 * @napi: struct associated with this polling callback
2486 * @budget: amount of packets driver is allowed to process this poll
2488 static int e1000_clean(struct napi_struct
*napi
, int budget
)
2490 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
, napi
);
2491 struct e1000_hw
*hw
= &adapter
->hw
;
2492 struct net_device
*poll_dev
= adapter
->netdev
;
2493 int tx_cleaned
= 1, work_done
= 0;
2495 adapter
= netdev_priv(poll_dev
);
2497 if (adapter
->msix_entries
&&
2498 !(adapter
->rx_ring
->ims_val
& adapter
->tx_ring
->ims_val
))
2501 tx_cleaned
= e1000_clean_tx_irq(adapter
);
2504 adapter
->clean_rx(adapter
, &work_done
, budget
);
2509 /* If budget not fully consumed, exit the polling mode */
2510 if (work_done
< budget
) {
2511 if (adapter
->itr_setting
& 3)
2512 e1000_set_itr(adapter
);
2513 napi_complete(napi
);
2514 if (!test_bit(__E1000_DOWN
, &adapter
->state
)) {
2515 if (adapter
->msix_entries
)
2516 ew32(IMS
, adapter
->rx_ring
->ims_val
);
2518 e1000_irq_enable(adapter
);
2525 static int e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
2527 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2528 struct e1000_hw
*hw
= &adapter
->hw
;
2531 /* don't update vlan cookie if already programmed */
2532 if ((adapter
->hw
.mng_cookie
.status
&
2533 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
2534 (vid
== adapter
->mng_vlan_id
))
2537 /* add VID to filter table */
2538 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2539 index
= (vid
>> 5) & 0x7F;
2540 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
2541 vfta
|= (1 << (vid
& 0x1F));
2542 hw
->mac
.ops
.write_vfta(hw
, index
, vfta
);
2545 set_bit(vid
, adapter
->active_vlans
);
2550 static int e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
2552 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2553 struct e1000_hw
*hw
= &adapter
->hw
;
2556 if ((adapter
->hw
.mng_cookie
.status
&
2557 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
2558 (vid
== adapter
->mng_vlan_id
)) {
2559 /* release control to f/w */
2560 e1000e_release_hw_control(adapter
);
2564 /* remove VID from filter table */
2565 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2566 index
= (vid
>> 5) & 0x7F;
2567 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
2568 vfta
&= ~(1 << (vid
& 0x1F));
2569 hw
->mac
.ops
.write_vfta(hw
, index
, vfta
);
2572 clear_bit(vid
, adapter
->active_vlans
);
2578 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2579 * @adapter: board private structure to initialize
2581 static void e1000e_vlan_filter_disable(struct e1000_adapter
*adapter
)
2583 struct net_device
*netdev
= adapter
->netdev
;
2584 struct e1000_hw
*hw
= &adapter
->hw
;
2587 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2588 /* disable VLAN receive filtering */
2590 rctl
&= ~(E1000_RCTL_VFE
| E1000_RCTL_CFIEN
);
2593 if (adapter
->mng_vlan_id
!= (u16
)E1000_MNG_VLAN_NONE
) {
2594 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
2595 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
2601 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2602 * @adapter: board private structure to initialize
2604 static void e1000e_vlan_filter_enable(struct e1000_adapter
*adapter
)
2606 struct e1000_hw
*hw
= &adapter
->hw
;
2609 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2610 /* enable VLAN receive filtering */
2612 rctl
|= E1000_RCTL_VFE
;
2613 rctl
&= ~E1000_RCTL_CFIEN
;
2619 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2620 * @adapter: board private structure to initialize
2622 static void e1000e_vlan_strip_disable(struct e1000_adapter
*adapter
)
2624 struct e1000_hw
*hw
= &adapter
->hw
;
2627 /* disable VLAN tag insert/strip */
2629 ctrl
&= ~E1000_CTRL_VME
;
2634 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2635 * @adapter: board private structure to initialize
2637 static void e1000e_vlan_strip_enable(struct e1000_adapter
*adapter
)
2639 struct e1000_hw
*hw
= &adapter
->hw
;
2642 /* enable VLAN tag insert/strip */
2644 ctrl
|= E1000_CTRL_VME
;
2648 static void e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
2650 struct net_device
*netdev
= adapter
->netdev
;
2651 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
2652 u16 old_vid
= adapter
->mng_vlan_id
;
2654 if (adapter
->hw
.mng_cookie
.status
&
2655 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) {
2656 e1000_vlan_rx_add_vid(netdev
, vid
);
2657 adapter
->mng_vlan_id
= vid
;
2660 if ((old_vid
!= (u16
)E1000_MNG_VLAN_NONE
) && (vid
!= old_vid
))
2661 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
2664 static void e1000_restore_vlan(struct e1000_adapter
*adapter
)
2668 e1000_vlan_rx_add_vid(adapter
->netdev
, 0);
2670 for_each_set_bit(vid
, adapter
->active_vlans
, VLAN_N_VID
)
2671 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
2674 static void e1000_init_manageability_pt(struct e1000_adapter
*adapter
)
2676 struct e1000_hw
*hw
= &adapter
->hw
;
2677 u32 manc
, manc2h
, mdef
, i
, j
;
2679 if (!(adapter
->flags
& FLAG_MNG_PT_ENABLED
))
2685 * enable receiving management packets to the host. this will probably
2686 * generate destination unreachable messages from the host OS, but
2687 * the packets will be handled on SMBUS
2689 manc
|= E1000_MANC_EN_MNG2HOST
;
2690 manc2h
= er32(MANC2H
);
2692 switch (hw
->mac
.type
) {
2694 manc2h
|= (E1000_MANC2H_PORT_623
| E1000_MANC2H_PORT_664
);
2699 * Check if IPMI pass-through decision filter already exists;
2702 for (i
= 0, j
= 0; i
< 8; i
++) {
2703 mdef
= er32(MDEF(i
));
2705 /* Ignore filters with anything other than IPMI ports */
2706 if (mdef
& ~(E1000_MDEF_PORT_623
| E1000_MDEF_PORT_664
))
2709 /* Enable this decision filter in MANC2H */
2716 if (j
== (E1000_MDEF_PORT_623
| E1000_MDEF_PORT_664
))
2719 /* Create new decision filter in an empty filter */
2720 for (i
= 0, j
= 0; i
< 8; i
++)
2721 if (er32(MDEF(i
)) == 0) {
2722 ew32(MDEF(i
), (E1000_MDEF_PORT_623
|
2723 E1000_MDEF_PORT_664
));
2730 e_warn("Unable to create IPMI pass-through filter\n");
2734 ew32(MANC2H
, manc2h
);
2739 * e1000_configure_tx - Configure Transmit Unit after Reset
2740 * @adapter: board private structure
2742 * Configure the Tx unit of the MAC after a reset.
2744 static void e1000_configure_tx(struct e1000_adapter
*adapter
)
2746 struct e1000_hw
*hw
= &adapter
->hw
;
2747 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2749 u32 tdlen
, tctl
, tipg
, tarc
;
2752 /* Setup the HW Tx Head and Tail descriptor pointers */
2753 tdba
= tx_ring
->dma
;
2754 tdlen
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
2755 ew32(TDBAL
, (tdba
& DMA_BIT_MASK(32)));
2756 ew32(TDBAH
, (tdba
>> 32));
2760 tx_ring
->head
= E1000_TDH
;
2761 tx_ring
->tail
= E1000_TDT
;
2763 /* Set the default values for the Tx Inter Packet Gap timer */
2764 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
; /* 8 */
2765 ipgr1
= DEFAULT_82543_TIPG_IPGR1
; /* 8 */
2766 ipgr2
= DEFAULT_82543_TIPG_IPGR2
; /* 6 */
2768 if (adapter
->flags
& FLAG_TIPG_MEDIUM_FOR_80003ESLAN
)
2769 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
; /* 7 */
2771 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
2772 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
2775 /* Set the Tx Interrupt Delay register */
2776 ew32(TIDV
, adapter
->tx_int_delay
);
2777 /* Tx irq moderation */
2778 ew32(TADV
, adapter
->tx_abs_int_delay
);
2780 if (adapter
->flags2
& FLAG2_DMA_BURST
) {
2781 u32 txdctl
= er32(TXDCTL(0));
2782 txdctl
&= ~(E1000_TXDCTL_PTHRESH
| E1000_TXDCTL_HTHRESH
|
2783 E1000_TXDCTL_WTHRESH
);
2785 * set up some performance related parameters to encourage the
2786 * hardware to use the bus more efficiently in bursts, depends
2787 * on the tx_int_delay to be enabled,
2788 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2789 * hthresh = 1 ==> prefetch when one or more available
2790 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2791 * BEWARE: this seems to work but should be considered first if
2792 * there are Tx hangs or other Tx related bugs
2794 txdctl
|= E1000_TXDCTL_DMA_BURST_ENABLE
;
2795 ew32(TXDCTL(0), txdctl
);
2796 /* erratum work around: set txdctl the same for both queues */
2797 ew32(TXDCTL(1), txdctl
);
2800 /* Program the Transmit Control Register */
2802 tctl
&= ~E1000_TCTL_CT
;
2803 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
2804 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
2806 if (adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) {
2807 tarc
= er32(TARC(0));
2809 * set the speed mode bit, we'll clear it if we're not at
2810 * gigabit link later
2812 #define SPEED_MODE_BIT (1 << 21)
2813 tarc
|= SPEED_MODE_BIT
;
2814 ew32(TARC(0), tarc
);
2817 /* errata: program both queues to unweighted RR */
2818 if (adapter
->flags
& FLAG_TARC_SET_BIT_ZERO
) {
2819 tarc
= er32(TARC(0));
2821 ew32(TARC(0), tarc
);
2822 tarc
= er32(TARC(1));
2824 ew32(TARC(1), tarc
);
2827 /* Setup Transmit Descriptor Settings for eop descriptor */
2828 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
2830 /* only set IDE if we are delaying interrupts using the timers */
2831 if (adapter
->tx_int_delay
)
2832 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
2834 /* enable Report Status bit */
2835 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
2839 e1000e_config_collision_dist(hw
);
2843 * e1000_setup_rctl - configure the receive control registers
2844 * @adapter: Board private structure
2846 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2847 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2848 static void e1000_setup_rctl(struct e1000_adapter
*adapter
)
2850 struct e1000_hw
*hw
= &adapter
->hw
;
2854 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2855 if (hw
->mac
.type
== e1000_pch2lan
) {
2858 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
)
2859 ret_val
= e1000_lv_jumbo_workaround_ich8lan(hw
, true);
2861 ret_val
= e1000_lv_jumbo_workaround_ich8lan(hw
, false);
2864 e_dbg("failed to enable jumbo frame workaround mode\n");
2867 /* Program MC offset vector base */
2869 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
2870 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
2871 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
2872 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
2874 /* Do not Store bad packets */
2875 rctl
&= ~E1000_RCTL_SBP
;
2877 /* Enable Long Packet receive */
2878 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
2879 rctl
&= ~E1000_RCTL_LPE
;
2881 rctl
|= E1000_RCTL_LPE
;
2883 /* Some systems expect that the CRC is included in SMBUS traffic. The
2884 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2885 * host memory when this is enabled
2887 if (adapter
->flags2
& FLAG2_CRC_STRIPPING
)
2888 rctl
|= E1000_RCTL_SECRC
;
2890 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2891 if ((hw
->phy
.type
== e1000_phy_82577
) && (rctl
& E1000_RCTL_LPE
)) {
2894 e1e_rphy(hw
, PHY_REG(770, 26), &phy_data
);
2896 phy_data
|= (1 << 2);
2897 e1e_wphy(hw
, PHY_REG(770, 26), phy_data
);
2899 e1e_rphy(hw
, 22, &phy_data
);
2901 phy_data
|= (1 << 14);
2902 e1e_wphy(hw
, 0x10, 0x2823);
2903 e1e_wphy(hw
, 0x11, 0x0003);
2904 e1e_wphy(hw
, 22, phy_data
);
2907 /* Setup buffer sizes */
2908 rctl
&= ~E1000_RCTL_SZ_4096
;
2909 rctl
|= E1000_RCTL_BSEX
;
2910 switch (adapter
->rx_buffer_len
) {
2913 rctl
|= E1000_RCTL_SZ_2048
;
2914 rctl
&= ~E1000_RCTL_BSEX
;
2917 rctl
|= E1000_RCTL_SZ_4096
;
2920 rctl
|= E1000_RCTL_SZ_8192
;
2923 rctl
|= E1000_RCTL_SZ_16384
;
2927 /* Enable Extended Status in all Receive Descriptors */
2928 rfctl
= er32(RFCTL
);
2929 rfctl
|= E1000_RFCTL_EXTEN
;
2932 * 82571 and greater support packet-split where the protocol
2933 * header is placed in skb->data and the packet data is
2934 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2935 * In the case of a non-split, skb->data is linearly filled,
2936 * followed by the page buffers. Therefore, skb->data is
2937 * sized to hold the largest protocol header.
2939 * allocations using alloc_page take too long for regular MTU
2940 * so only enable packet split for jumbo frames
2942 * Using pages when the page size is greater than 16k wastes
2943 * a lot of memory, since we allocate 3 pages at all times
2946 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
2947 if (!(adapter
->flags
& FLAG_HAS_ERT
) && (pages
<= 3) &&
2948 (PAGE_SIZE
<= 16384) && (rctl
& E1000_RCTL_LPE
))
2949 adapter
->rx_ps_pages
= pages
;
2951 adapter
->rx_ps_pages
= 0;
2953 if (adapter
->rx_ps_pages
) {
2957 * disable packet split support for IPv6 extension headers,
2958 * because some malformed IPv6 headers can hang the Rx
2960 rfctl
|= (E1000_RFCTL_IPV6_EX_DIS
|
2961 E1000_RFCTL_NEW_IPV6_EXT_DIS
);
2963 /* Enable Packet split descriptors */
2964 rctl
|= E1000_RCTL_DTYP_PS
;
2966 psrctl
|= adapter
->rx_ps_bsize0
>>
2967 E1000_PSRCTL_BSIZE0_SHIFT
;
2969 switch (adapter
->rx_ps_pages
) {
2971 psrctl
|= PAGE_SIZE
<<
2972 E1000_PSRCTL_BSIZE3_SHIFT
;
2974 psrctl
|= PAGE_SIZE
<<
2975 E1000_PSRCTL_BSIZE2_SHIFT
;
2977 psrctl
|= PAGE_SIZE
>>
2978 E1000_PSRCTL_BSIZE1_SHIFT
;
2982 ew32(PSRCTL
, psrctl
);
2987 /* just started the receive unit, no need to restart */
2988 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
2992 * e1000_configure_rx - Configure Receive Unit after Reset
2993 * @adapter: board private structure
2995 * Configure the Rx unit of the MAC after a reset.
2997 static void e1000_configure_rx(struct e1000_adapter
*adapter
)
2999 struct e1000_hw
*hw
= &adapter
->hw
;
3000 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
3002 u32 rdlen
, rctl
, rxcsum
, ctrl_ext
;
3004 if (adapter
->rx_ps_pages
) {
3005 /* this is a 32 byte descriptor */
3006 rdlen
= rx_ring
->count
*
3007 sizeof(union e1000_rx_desc_packet_split
);
3008 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
3009 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
3010 } else if (adapter
->netdev
->mtu
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
3011 rdlen
= rx_ring
->count
* sizeof(union e1000_rx_desc_extended
);
3012 adapter
->clean_rx
= e1000_clean_jumbo_rx_irq
;
3013 adapter
->alloc_rx_buf
= e1000_alloc_jumbo_rx_buffers
;
3015 rdlen
= rx_ring
->count
* sizeof(union e1000_rx_desc_extended
);
3016 adapter
->clean_rx
= e1000_clean_rx_irq
;
3017 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
3020 /* disable receives while setting up the descriptors */
3022 if (!(adapter
->flags2
& FLAG2_NO_DISABLE_RX
))
3023 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
3025 usleep_range(10000, 20000);
3027 if (adapter
->flags2
& FLAG2_DMA_BURST
) {
3029 * set the writeback threshold (only takes effect if the RDTR
3030 * is set). set GRAN=1 and write back up to 0x4 worth, and
3031 * enable prefetching of 0x20 Rx descriptors
3037 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE
);
3038 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE
);
3041 * override the delay timers for enabling bursting, only if
3042 * the value was not set by the user via module options
3044 if (adapter
->rx_int_delay
== DEFAULT_RDTR
)
3045 adapter
->rx_int_delay
= BURST_RDTR
;
3046 if (adapter
->rx_abs_int_delay
== DEFAULT_RADV
)
3047 adapter
->rx_abs_int_delay
= BURST_RADV
;
3050 /* set the Receive Delay Timer Register */
3051 ew32(RDTR
, adapter
->rx_int_delay
);
3053 /* irq moderation */
3054 ew32(RADV
, adapter
->rx_abs_int_delay
);
3055 if ((adapter
->itr_setting
!= 0) && (adapter
->itr
!= 0))
3056 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
3058 ctrl_ext
= er32(CTRL_EXT
);
3059 /* Auto-Mask interrupts upon ICR access */
3060 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
3061 ew32(IAM
, 0xffffffff);
3062 ew32(CTRL_EXT
, ctrl_ext
);
3066 * Setup the HW Rx Head and Tail Descriptor Pointers and
3067 * the Base and Length of the Rx Descriptor Ring
3069 rdba
= rx_ring
->dma
;
3070 ew32(RDBAL
, (rdba
& DMA_BIT_MASK(32)));
3071 ew32(RDBAH
, (rdba
>> 32));
3075 rx_ring
->head
= E1000_RDH
;
3076 rx_ring
->tail
= E1000_RDT
;
3078 /* Enable Receive Checksum Offload for TCP and UDP */
3079 rxcsum
= er32(RXCSUM
);
3080 if (adapter
->netdev
->features
& NETIF_F_RXCSUM
) {
3081 rxcsum
|= E1000_RXCSUM_TUOFL
;
3084 * IPv4 payload checksum for UDP fragments must be
3085 * used in conjunction with packet-split.
3087 if (adapter
->rx_ps_pages
)
3088 rxcsum
|= E1000_RXCSUM_IPPCSE
;
3090 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
3091 /* no need to clear IPPCSE as it defaults to 0 */
3093 ew32(RXCSUM
, rxcsum
);
3096 * Enable early receives on supported devices, only takes effect when
3097 * packet size is equal or larger than the specified value (in 8 byte
3098 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
3100 if ((adapter
->flags
& FLAG_HAS_ERT
) ||
3101 (adapter
->hw
.mac
.type
== e1000_pch2lan
)) {
3102 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
3103 u32 rxdctl
= er32(RXDCTL(0));
3104 ew32(RXDCTL(0), rxdctl
| 0x3);
3105 if (adapter
->flags
& FLAG_HAS_ERT
)
3106 ew32(ERT
, E1000_ERT_2048
| (1 << 13));
3108 * With jumbo frames and early-receive enabled,
3109 * excessive C-state transition latencies result in
3110 * dropped transactions.
3112 pm_qos_update_request(&adapter
->netdev
->pm_qos_req
, 55);
3114 pm_qos_update_request(&adapter
->netdev
->pm_qos_req
,
3115 PM_QOS_DEFAULT_VALUE
);
3119 /* Enable Receives */
3124 * e1000e_write_mc_addr_list - write multicast addresses to MTA
3125 * @netdev: network interface device structure
3127 * Writes multicast address list to the MTA hash table.
3128 * Returns: -ENOMEM on failure
3129 * 0 on no addresses written
3130 * X on writing X addresses to MTA
3132 static int e1000e_write_mc_addr_list(struct net_device
*netdev
)
3134 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3135 struct e1000_hw
*hw
= &adapter
->hw
;
3136 struct netdev_hw_addr
*ha
;
3140 if (netdev_mc_empty(netdev
)) {
3141 /* nothing to program, so clear mc list */
3142 hw
->mac
.ops
.update_mc_addr_list(hw
, NULL
, 0);
3146 mta_list
= kzalloc(netdev_mc_count(netdev
) * ETH_ALEN
, GFP_ATOMIC
);
3150 /* update_mc_addr_list expects a packed array of only addresses. */
3152 netdev_for_each_mc_addr(ha
, netdev
)
3153 memcpy(mta_list
+ (i
++ * ETH_ALEN
), ha
->addr
, ETH_ALEN
);
3155 hw
->mac
.ops
.update_mc_addr_list(hw
, mta_list
, i
);
3158 return netdev_mc_count(netdev
);
3162 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3163 * @netdev: network interface device structure
3165 * Writes unicast address list to the RAR table.
3166 * Returns: -ENOMEM on failure/insufficient address space
3167 * 0 on no addresses written
3168 * X on writing X addresses to the RAR table
3170 static int e1000e_write_uc_addr_list(struct net_device
*netdev
)
3172 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3173 struct e1000_hw
*hw
= &adapter
->hw
;
3174 unsigned int rar_entries
= hw
->mac
.rar_entry_count
;
3177 /* save a rar entry for our hardware address */
3180 /* save a rar entry for the LAA workaround */
3181 if (adapter
->flags
& FLAG_RESET_OVERWRITES_LAA
)
3184 /* return ENOMEM indicating insufficient memory for addresses */
3185 if (netdev_uc_count(netdev
) > rar_entries
)
3188 if (!netdev_uc_empty(netdev
) && rar_entries
) {
3189 struct netdev_hw_addr
*ha
;
3192 * write the addresses in reverse order to avoid write
3195 netdev_for_each_uc_addr(ha
, netdev
) {
3198 e1000e_rar_set(hw
, ha
->addr
, rar_entries
--);
3203 /* zero out the remaining RAR entries not used above */
3204 for (; rar_entries
> 0; rar_entries
--) {
3205 ew32(RAH(rar_entries
), 0);
3206 ew32(RAL(rar_entries
), 0);
3214 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3215 * @netdev: network interface device structure
3217 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3218 * address list or the network interface flags are updated. This routine is
3219 * responsible for configuring the hardware for proper unicast, multicast,
3220 * promiscuous mode, and all-multi behavior.
3222 static void e1000e_set_rx_mode(struct net_device
*netdev
)
3224 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3225 struct e1000_hw
*hw
= &adapter
->hw
;
3228 /* Check for Promiscuous and All Multicast modes */
3231 /* clear the affected bits */
3232 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
3234 if (netdev
->flags
& IFF_PROMISC
) {
3235 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
3236 /* Do not hardware filter VLANs in promisc mode */
3237 e1000e_vlan_filter_disable(adapter
);
3240 if (netdev
->flags
& IFF_ALLMULTI
) {
3241 rctl
|= E1000_RCTL_MPE
;
3244 * Write addresses to the MTA, if the attempt fails
3245 * then we should just turn on promiscuous mode so
3246 * that we can at least receive multicast traffic
3248 count
= e1000e_write_mc_addr_list(netdev
);
3250 rctl
|= E1000_RCTL_MPE
;
3252 e1000e_vlan_filter_enable(adapter
);
3254 * Write addresses to available RAR registers, if there is not
3255 * sufficient space to store all the addresses then enable
3256 * unicast promiscuous mode
3258 count
= e1000e_write_uc_addr_list(netdev
);
3260 rctl
|= E1000_RCTL_UPE
;
3265 if (netdev
->features
& NETIF_F_HW_VLAN_RX
)
3266 e1000e_vlan_strip_enable(adapter
);
3268 e1000e_vlan_strip_disable(adapter
);
3272 * e1000_configure - configure the hardware for Rx and Tx
3273 * @adapter: private board structure
3275 static void e1000_configure(struct e1000_adapter
*adapter
)
3277 e1000e_set_rx_mode(adapter
->netdev
);
3279 e1000_restore_vlan(adapter
);
3280 e1000_init_manageability_pt(adapter
);
3282 e1000_configure_tx(adapter
);
3283 e1000_setup_rctl(adapter
);
3284 e1000_configure_rx(adapter
);
3285 adapter
->alloc_rx_buf(adapter
, e1000_desc_unused(adapter
->rx_ring
),
3290 * e1000e_power_up_phy - restore link in case the phy was powered down
3291 * @adapter: address of board private structure
3293 * The phy may be powered down to save power and turn off link when the
3294 * driver is unloaded and wake on lan is not enabled (among others)
3295 * *** this routine MUST be followed by a call to e1000e_reset ***
3297 void e1000e_power_up_phy(struct e1000_adapter
*adapter
)
3299 if (adapter
->hw
.phy
.ops
.power_up
)
3300 adapter
->hw
.phy
.ops
.power_up(&adapter
->hw
);
3302 adapter
->hw
.mac
.ops
.setup_link(&adapter
->hw
);
3306 * e1000_power_down_phy - Power down the PHY
3308 * Power down the PHY so no link is implied when interface is down.
3309 * The PHY cannot be powered down if management or WoL is active.
3311 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
3313 /* WoL is enabled */
3317 if (adapter
->hw
.phy
.ops
.power_down
)
3318 adapter
->hw
.phy
.ops
.power_down(&adapter
->hw
);
3322 * e1000e_reset - bring the hardware into a known good state
3324 * This function boots the hardware and enables some settings that
3325 * require a configuration cycle of the hardware - those cannot be
3326 * set/changed during runtime. After reset the device needs to be
3327 * properly configured for Rx, Tx etc.
3329 void e1000e_reset(struct e1000_adapter
*adapter
)
3331 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
3332 struct e1000_fc_info
*fc
= &adapter
->hw
.fc
;
3333 struct e1000_hw
*hw
= &adapter
->hw
;
3334 u32 tx_space
, min_tx_space
, min_rx_space
;
3335 u32 pba
= adapter
->pba
;
3338 /* reset Packet Buffer Allocation to default */
3341 if (adapter
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
3343 * To maintain wire speed transmits, the Tx FIFO should be
3344 * large enough to accommodate two full transmit packets,
3345 * rounded up to the next 1KB and expressed in KB. Likewise,
3346 * the Rx FIFO should be large enough to accommodate at least
3347 * one full receive packet and is similarly rounded up and
3351 /* upper 16 bits has Tx packet buffer allocation size in KB */
3352 tx_space
= pba
>> 16;
3353 /* lower 16 bits has Rx packet buffer allocation size in KB */
3356 * the Tx fifo also stores 16 bytes of information about the Tx
3357 * but don't include ethernet FCS because hardware appends it
3359 min_tx_space
= (adapter
->max_frame_size
+
3360 sizeof(struct e1000_tx_desc
) -
3362 min_tx_space
= ALIGN(min_tx_space
, 1024);
3363 min_tx_space
>>= 10;
3364 /* software strips receive CRC, so leave room for it */
3365 min_rx_space
= adapter
->max_frame_size
;
3366 min_rx_space
= ALIGN(min_rx_space
, 1024);
3367 min_rx_space
>>= 10;
3370 * If current Tx allocation is less than the min Tx FIFO size,
3371 * and the min Tx FIFO size is less than the current Rx FIFO
3372 * allocation, take space away from current Rx allocation
3374 if ((tx_space
< min_tx_space
) &&
3375 ((min_tx_space
- tx_space
) < pba
)) {
3376 pba
-= min_tx_space
- tx_space
;
3379 * if short on Rx space, Rx wins and must trump Tx
3380 * adjustment or use Early Receive if available
3382 if ((pba
< min_rx_space
) &&
3383 (!(adapter
->flags
& FLAG_HAS_ERT
)))
3384 /* ERT enabled in e1000_configure_rx */
3392 * flow control settings
3394 * The high water mark must be low enough to fit one full frame
3395 * (or the size used for early receive) above it in the Rx FIFO.
3396 * Set it to the lower of:
3397 * - 90% of the Rx FIFO size, and
3398 * - the full Rx FIFO size minus the early receive size (for parts
3399 * with ERT support assuming ERT set to E1000_ERT_2048), or
3400 * - the full Rx FIFO size minus one full frame
3402 if (adapter
->flags
& FLAG_DISABLE_FC_PAUSE_TIME
)
3403 fc
->pause_time
= 0xFFFF;
3405 fc
->pause_time
= E1000_FC_PAUSE_TIME
;
3407 fc
->current_mode
= fc
->requested_mode
;
3409 switch (hw
->mac
.type
) {
3411 if ((adapter
->flags
& FLAG_HAS_ERT
) &&
3412 (adapter
->netdev
->mtu
> ETH_DATA_LEN
))
3413 hwm
= min(((pba
<< 10) * 9 / 10),
3414 ((pba
<< 10) - (E1000_ERT_2048
<< 3)));
3416 hwm
= min(((pba
<< 10) * 9 / 10),
3417 ((pba
<< 10) - adapter
->max_frame_size
));
3419 fc
->high_water
= hwm
& E1000_FCRTH_RTH
; /* 8-byte granularity */
3420 fc
->low_water
= fc
->high_water
- 8;
3424 * Workaround PCH LOM adapter hangs with certain network
3425 * loads. If hangs persist, try disabling Tx flow control.
3427 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
3428 fc
->high_water
= 0x3500;
3429 fc
->low_water
= 0x1500;
3431 fc
->high_water
= 0x5000;
3432 fc
->low_water
= 0x3000;
3434 fc
->refresh_time
= 0x1000;
3437 fc
->high_water
= 0x05C20;
3438 fc
->low_water
= 0x05048;
3439 fc
->pause_time
= 0x0650;
3440 fc
->refresh_time
= 0x0400;
3441 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
3449 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3450 * fit in receive buffer and early-receive not supported.
3452 if (adapter
->itr_setting
& 0x3) {
3453 if (((adapter
->max_frame_size
* 2) > (pba
<< 10)) &&
3454 !(adapter
->flags
& FLAG_HAS_ERT
)) {
3455 if (!(adapter
->flags2
& FLAG2_DISABLE_AIM
)) {
3456 dev_info(&adapter
->pdev
->dev
,
3457 "Interrupt Throttle Rate turned off\n");
3458 adapter
->flags2
|= FLAG2_DISABLE_AIM
;
3461 } else if (adapter
->flags2
& FLAG2_DISABLE_AIM
) {
3462 dev_info(&adapter
->pdev
->dev
,
3463 "Interrupt Throttle Rate turned on\n");
3464 adapter
->flags2
&= ~FLAG2_DISABLE_AIM
;
3465 adapter
->itr
= 20000;
3466 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
3470 /* Allow time for pending master requests to run */
3471 mac
->ops
.reset_hw(hw
);
3474 * For parts with AMT enabled, let the firmware know
3475 * that the network interface is in control
3477 if (adapter
->flags
& FLAG_HAS_AMT
)
3478 e1000e_get_hw_control(adapter
);
3482 if (mac
->ops
.init_hw(hw
))
3483 e_err("Hardware Error\n");
3485 e1000_update_mng_vlan(adapter
);
3487 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3488 ew32(VET
, ETH_P_8021Q
);
3490 e1000e_reset_adaptive(hw
);
3492 if (!netif_running(adapter
->netdev
) &&
3493 !test_bit(__E1000_TESTING
, &adapter
->state
)) {
3494 e1000_power_down_phy(adapter
);
3498 e1000_get_phy_info(hw
);
3500 if ((adapter
->flags
& FLAG_HAS_SMART_POWER_DOWN
) &&
3501 !(adapter
->flags
& FLAG_SMART_POWER_DOWN
)) {
3504 * speed up time to link by disabling smart power down, ignore
3505 * the return value of this function because there is nothing
3506 * different we would do if it failed
3508 e1e_rphy(hw
, IGP02E1000_PHY_POWER_MGMT
, &phy_data
);
3509 phy_data
&= ~IGP02E1000_PM_SPD
;
3510 e1e_wphy(hw
, IGP02E1000_PHY_POWER_MGMT
, phy_data
);
3514 int e1000e_up(struct e1000_adapter
*adapter
)
3516 struct e1000_hw
*hw
= &adapter
->hw
;
3518 /* hardware has been reset, we need to reload some things */
3519 e1000_configure(adapter
);
3521 clear_bit(__E1000_DOWN
, &adapter
->state
);
3523 if (adapter
->msix_entries
)
3524 e1000_configure_msix(adapter
);
3525 e1000_irq_enable(adapter
);
3527 netif_start_queue(adapter
->netdev
);
3529 /* fire a link change interrupt to start the watchdog */
3530 if (adapter
->msix_entries
)
3531 ew32(ICS
, E1000_ICS_LSC
| E1000_ICR_OTHER
);
3533 ew32(ICS
, E1000_ICS_LSC
);
3538 static void e1000e_flush_descriptors(struct e1000_adapter
*adapter
)
3540 struct e1000_hw
*hw
= &adapter
->hw
;
3542 if (!(adapter
->flags2
& FLAG2_DMA_BURST
))
3545 /* flush pending descriptor writebacks to memory */
3546 ew32(TIDV
, adapter
->tx_int_delay
| E1000_TIDV_FPD
);
3547 ew32(RDTR
, adapter
->rx_int_delay
| E1000_RDTR_FPD
);
3549 /* execute the writes immediately */
3553 static void e1000e_update_stats(struct e1000_adapter
*adapter
);
3555 void e1000e_down(struct e1000_adapter
*adapter
)
3557 struct net_device
*netdev
= adapter
->netdev
;
3558 struct e1000_hw
*hw
= &adapter
->hw
;
3562 * signal that we're down so the interrupt handler does not
3563 * reschedule our watchdog timer
3565 set_bit(__E1000_DOWN
, &adapter
->state
);
3567 /* disable receives in the hardware */
3569 if (!(adapter
->flags2
& FLAG2_NO_DISABLE_RX
))
3570 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
3571 /* flush and sleep below */
3573 netif_stop_queue(netdev
);
3575 /* disable transmits in the hardware */
3577 tctl
&= ~E1000_TCTL_EN
;
3580 /* flush both disables and wait for them to finish */
3582 usleep_range(10000, 20000);
3584 e1000_irq_disable(adapter
);
3586 del_timer_sync(&adapter
->watchdog_timer
);
3587 del_timer_sync(&adapter
->phy_info_timer
);
3589 netif_carrier_off(netdev
);
3591 spin_lock(&adapter
->stats64_lock
);
3592 e1000e_update_stats(adapter
);
3593 spin_unlock(&adapter
->stats64_lock
);
3595 e1000e_flush_descriptors(adapter
);
3596 e1000_clean_tx_ring(adapter
);
3597 e1000_clean_rx_ring(adapter
);
3599 adapter
->link_speed
= 0;
3600 adapter
->link_duplex
= 0;
3602 if (!pci_channel_offline(adapter
->pdev
))
3603 e1000e_reset(adapter
);
3606 * TODO: for power management, we could drop the link and
3607 * pci_disable_device here.
3611 void e1000e_reinit_locked(struct e1000_adapter
*adapter
)
3614 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
3615 usleep_range(1000, 2000);
3616 e1000e_down(adapter
);
3618 clear_bit(__E1000_RESETTING
, &adapter
->state
);
3622 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3623 * @adapter: board private structure to initialize
3625 * e1000_sw_init initializes the Adapter private data structure.
3626 * Fields are initialized based on PCI device information and
3627 * OS network device settings (MTU size).
3629 static int __devinit
e1000_sw_init(struct e1000_adapter
*adapter
)
3631 struct net_device
*netdev
= adapter
->netdev
;
3633 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
;
3634 adapter
->rx_ps_bsize0
= 128;
3635 adapter
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3636 adapter
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
3638 spin_lock_init(&adapter
->stats64_lock
);
3640 e1000e_set_interrupt_capability(adapter
);
3642 if (e1000_alloc_queues(adapter
))
3645 /* Explicitly disable IRQ since the NIC can be in any state. */
3646 e1000_irq_disable(adapter
);
3648 set_bit(__E1000_DOWN
, &adapter
->state
);
3653 * e1000_intr_msi_test - Interrupt Handler
3654 * @irq: interrupt number
3655 * @data: pointer to a network interface device structure
3657 static irqreturn_t
e1000_intr_msi_test(int irq
, void *data
)
3659 struct net_device
*netdev
= data
;
3660 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3661 struct e1000_hw
*hw
= &adapter
->hw
;
3662 u32 icr
= er32(ICR
);
3664 e_dbg("icr is %08X\n", icr
);
3665 if (icr
& E1000_ICR_RXSEQ
) {
3666 adapter
->flags
&= ~FLAG_MSI_TEST_FAILED
;
3674 * e1000_test_msi_interrupt - Returns 0 for successful test
3675 * @adapter: board private struct
3677 * code flow taken from tg3.c
3679 static int e1000_test_msi_interrupt(struct e1000_adapter
*adapter
)
3681 struct net_device
*netdev
= adapter
->netdev
;
3682 struct e1000_hw
*hw
= &adapter
->hw
;
3685 /* poll_enable hasn't been called yet, so don't need disable */
3686 /* clear any pending events */
3689 /* free the real vector and request a test handler */
3690 e1000_free_irq(adapter
);
3691 e1000e_reset_interrupt_capability(adapter
);
3693 /* Assume that the test fails, if it succeeds then the test
3694 * MSI irq handler will unset this flag */
3695 adapter
->flags
|= FLAG_MSI_TEST_FAILED
;
3697 err
= pci_enable_msi(adapter
->pdev
);
3699 goto msi_test_failed
;
3701 err
= request_irq(adapter
->pdev
->irq
, e1000_intr_msi_test
, 0,
3702 netdev
->name
, netdev
);
3704 pci_disable_msi(adapter
->pdev
);
3705 goto msi_test_failed
;
3710 e1000_irq_enable(adapter
);
3712 /* fire an unusual interrupt on the test handler */
3713 ew32(ICS
, E1000_ICS_RXSEQ
);
3717 e1000_irq_disable(adapter
);
3721 if (adapter
->flags
& FLAG_MSI_TEST_FAILED
) {
3722 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
3723 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3725 e_dbg("MSI interrupt test succeeded!\n");
3727 free_irq(adapter
->pdev
->irq
, netdev
);
3728 pci_disable_msi(adapter
->pdev
);
3731 e1000e_set_interrupt_capability(adapter
);
3732 return e1000_request_irq(adapter
);
3736 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3737 * @adapter: board private struct
3739 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3741 static int e1000_test_msi(struct e1000_adapter
*adapter
)
3746 if (!(adapter
->flags
& FLAG_MSI_ENABLED
))
3749 /* disable SERR in case the MSI write causes a master abort */
3750 pci_read_config_word(adapter
->pdev
, PCI_COMMAND
, &pci_cmd
);
3751 if (pci_cmd
& PCI_COMMAND_SERR
)
3752 pci_write_config_word(adapter
->pdev
, PCI_COMMAND
,
3753 pci_cmd
& ~PCI_COMMAND_SERR
);
3755 err
= e1000_test_msi_interrupt(adapter
);
3757 /* re-enable SERR */
3758 if (pci_cmd
& PCI_COMMAND_SERR
) {
3759 pci_read_config_word(adapter
->pdev
, PCI_COMMAND
, &pci_cmd
);
3760 pci_cmd
|= PCI_COMMAND_SERR
;
3761 pci_write_config_word(adapter
->pdev
, PCI_COMMAND
, pci_cmd
);
3768 * e1000_open - Called when a network interface is made active
3769 * @netdev: network interface device structure
3771 * Returns 0 on success, negative value on failure
3773 * The open entry point is called when a network interface is made
3774 * active by the system (IFF_UP). At this point all resources needed
3775 * for transmit and receive operations are allocated, the interrupt
3776 * handler is registered with the OS, the watchdog timer is started,
3777 * and the stack is notified that the interface is ready.
3779 static int e1000_open(struct net_device
*netdev
)
3781 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3782 struct e1000_hw
*hw
= &adapter
->hw
;
3783 struct pci_dev
*pdev
= adapter
->pdev
;
3786 /* disallow open during test */
3787 if (test_bit(__E1000_TESTING
, &adapter
->state
))
3790 pm_runtime_get_sync(&pdev
->dev
);
3792 netif_carrier_off(netdev
);
3794 /* allocate transmit descriptors */
3795 err
= e1000e_setup_tx_resources(adapter
);
3799 /* allocate receive descriptors */
3800 err
= e1000e_setup_rx_resources(adapter
);
3805 * If AMT is enabled, let the firmware know that the network
3806 * interface is now open and reset the part to a known state.
3808 if (adapter
->flags
& FLAG_HAS_AMT
) {
3809 e1000e_get_hw_control(adapter
);
3810 e1000e_reset(adapter
);
3813 e1000e_power_up_phy(adapter
);
3815 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
3816 if ((adapter
->hw
.mng_cookie
.status
&
3817 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
))
3818 e1000_update_mng_vlan(adapter
);
3820 /* DMA latency requirement to workaround early-receive/jumbo issue */
3821 if ((adapter
->flags
& FLAG_HAS_ERT
) ||
3822 (adapter
->hw
.mac
.type
== e1000_pch2lan
))
3823 pm_qos_add_request(&adapter
->netdev
->pm_qos_req
,
3824 PM_QOS_CPU_DMA_LATENCY
,
3825 PM_QOS_DEFAULT_VALUE
);
3828 * before we allocate an interrupt, we must be ready to handle it.
3829 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3830 * as soon as we call pci_request_irq, so we have to setup our
3831 * clean_rx handler before we do so.
3833 e1000_configure(adapter
);
3835 err
= e1000_request_irq(adapter
);
3840 * Work around PCIe errata with MSI interrupts causing some chipsets to
3841 * ignore e1000e MSI messages, which means we need to test our MSI
3844 if (adapter
->int_mode
!= E1000E_INT_MODE_LEGACY
) {
3845 err
= e1000_test_msi(adapter
);
3847 e_err("Interrupt allocation failed\n");
3852 /* From here on the code is the same as e1000e_up() */
3853 clear_bit(__E1000_DOWN
, &adapter
->state
);
3855 napi_enable(&adapter
->napi
);
3857 e1000_irq_enable(adapter
);
3859 adapter
->tx_hang_recheck
= false;
3860 netif_start_queue(netdev
);
3862 adapter
->idle_check
= true;
3863 pm_runtime_put(&pdev
->dev
);
3865 /* fire a link status change interrupt to start the watchdog */
3866 if (adapter
->msix_entries
)
3867 ew32(ICS
, E1000_ICS_LSC
| E1000_ICR_OTHER
);
3869 ew32(ICS
, E1000_ICS_LSC
);
3874 e1000e_release_hw_control(adapter
);
3875 e1000_power_down_phy(adapter
);
3876 e1000e_free_rx_resources(adapter
);
3878 e1000e_free_tx_resources(adapter
);
3880 e1000e_reset(adapter
);
3881 pm_runtime_put_sync(&pdev
->dev
);
3887 * e1000_close - Disables a network interface
3888 * @netdev: network interface device structure
3890 * Returns 0, this is not allowed to fail
3892 * The close entry point is called when an interface is de-activated
3893 * by the OS. The hardware is still under the drivers control, but
3894 * needs to be disabled. A global MAC reset is issued to stop the
3895 * hardware, and all transmit and receive resources are freed.
3897 static int e1000_close(struct net_device
*netdev
)
3899 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3900 struct pci_dev
*pdev
= adapter
->pdev
;
3902 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
3904 pm_runtime_get_sync(&pdev
->dev
);
3906 napi_disable(&adapter
->napi
);
3908 if (!test_bit(__E1000_DOWN
, &adapter
->state
)) {
3909 e1000e_down(adapter
);
3910 e1000_free_irq(adapter
);
3912 e1000_power_down_phy(adapter
);
3914 e1000e_free_tx_resources(adapter
);
3915 e1000e_free_rx_resources(adapter
);
3918 * kill manageability vlan ID if supported, but not if a vlan with
3919 * the same ID is registered on the host OS (let 8021q kill it)
3921 if (adapter
->hw
.mng_cookie
.status
&
3922 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
)
3923 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
3926 * If AMT is enabled, let the firmware know that the network
3927 * interface is now closed
3929 if ((adapter
->flags
& FLAG_HAS_AMT
) &&
3930 !test_bit(__E1000_TESTING
, &adapter
->state
))
3931 e1000e_release_hw_control(adapter
);
3933 if ((adapter
->flags
& FLAG_HAS_ERT
) ||
3934 (adapter
->hw
.mac
.type
== e1000_pch2lan
))
3935 pm_qos_remove_request(&adapter
->netdev
->pm_qos_req
);
3937 pm_runtime_put_sync(&pdev
->dev
);
3942 * e1000_set_mac - Change the Ethernet Address of the NIC
3943 * @netdev: network interface device structure
3944 * @p: pointer to an address structure
3946 * Returns 0 on success, negative on failure
3948 static int e1000_set_mac(struct net_device
*netdev
, void *p
)
3950 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3951 struct sockaddr
*addr
= p
;
3953 if (!is_valid_ether_addr(addr
->sa_data
))
3954 return -EADDRNOTAVAIL
;
3956 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
3957 memcpy(adapter
->hw
.mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
3959 e1000e_rar_set(&adapter
->hw
, adapter
->hw
.mac
.addr
, 0);
3961 if (adapter
->flags
& FLAG_RESET_OVERWRITES_LAA
) {
3962 /* activate the work around */
3963 e1000e_set_laa_state_82571(&adapter
->hw
, 1);
3966 * Hold a copy of the LAA in RAR[14] This is done so that
3967 * between the time RAR[0] gets clobbered and the time it
3968 * gets fixed (in e1000_watchdog), the actual LAA is in one
3969 * of the RARs and no incoming packets directed to this port
3970 * are dropped. Eventually the LAA will be in RAR[0] and
3973 e1000e_rar_set(&adapter
->hw
,
3974 adapter
->hw
.mac
.addr
,
3975 adapter
->hw
.mac
.rar_entry_count
- 1);
3982 * e1000e_update_phy_task - work thread to update phy
3983 * @work: pointer to our work struct
3985 * this worker thread exists because we must acquire a
3986 * semaphore to read the phy, which we could msleep while
3987 * waiting for it, and we can't msleep in a timer.
3989 static void e1000e_update_phy_task(struct work_struct
*work
)
3991 struct e1000_adapter
*adapter
= container_of(work
,
3992 struct e1000_adapter
, update_phy_task
);
3994 if (test_bit(__E1000_DOWN
, &adapter
->state
))
3997 e1000_get_phy_info(&adapter
->hw
);
4001 * Need to wait a few seconds after link up to get diagnostic information from
4004 static void e1000_update_phy_info(unsigned long data
)
4006 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
4008 if (test_bit(__E1000_DOWN
, &adapter
->state
))
4011 schedule_work(&adapter
->update_phy_task
);
4015 * e1000e_update_phy_stats - Update the PHY statistics counters
4016 * @adapter: board private structure
4018 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
4020 static void e1000e_update_phy_stats(struct e1000_adapter
*adapter
)
4022 struct e1000_hw
*hw
= &adapter
->hw
;
4026 ret_val
= hw
->phy
.ops
.acquire(hw
);
4031 * A page set is expensive so check if already on desired page.
4032 * If not, set to the page with the PHY status registers.
4035 ret_val
= e1000e_read_phy_reg_mdic(hw
, IGP01E1000_PHY_PAGE_SELECT
,
4039 if (phy_data
!= (HV_STATS_PAGE
<< IGP_PAGE_SHIFT
)) {
4040 ret_val
= hw
->phy
.ops
.set_page(hw
,
4041 HV_STATS_PAGE
<< IGP_PAGE_SHIFT
);
4046 /* Single Collision Count */
4047 hw
->phy
.ops
.read_reg_page(hw
, HV_SCC_UPPER
, &phy_data
);
4048 ret_val
= hw
->phy
.ops
.read_reg_page(hw
, HV_SCC_LOWER
, &phy_data
);
4050 adapter
->stats
.scc
+= phy_data
;
4052 /* Excessive Collision Count */
4053 hw
->phy
.ops
.read_reg_page(hw
, HV_ECOL_UPPER
, &phy_data
);
4054 ret_val
= hw
->phy
.ops
.read_reg_page(hw
, HV_ECOL_LOWER
, &phy_data
);
4056 adapter
->stats
.ecol
+= phy_data
;
4058 /* Multiple Collision Count */
4059 hw
->phy
.ops
.read_reg_page(hw
, HV_MCC_UPPER
, &phy_data
);
4060 ret_val
= hw
->phy
.ops
.read_reg_page(hw
, HV_MCC_LOWER
, &phy_data
);
4062 adapter
->stats
.mcc
+= phy_data
;
4064 /* Late Collision Count */
4065 hw
->phy
.ops
.read_reg_page(hw
, HV_LATECOL_UPPER
, &phy_data
);
4066 ret_val
= hw
->phy
.ops
.read_reg_page(hw
, HV_LATECOL_LOWER
, &phy_data
);
4068 adapter
->stats
.latecol
+= phy_data
;
4070 /* Collision Count - also used for adaptive IFS */
4071 hw
->phy
.ops
.read_reg_page(hw
, HV_COLC_UPPER
, &phy_data
);
4072 ret_val
= hw
->phy
.ops
.read_reg_page(hw
, HV_COLC_LOWER
, &phy_data
);
4074 hw
->mac
.collision_delta
= phy_data
;
4077 hw
->phy
.ops
.read_reg_page(hw
, HV_DC_UPPER
, &phy_data
);
4078 ret_val
= hw
->phy
.ops
.read_reg_page(hw
, HV_DC_LOWER
, &phy_data
);
4080 adapter
->stats
.dc
+= phy_data
;
4082 /* Transmit with no CRS */
4083 hw
->phy
.ops
.read_reg_page(hw
, HV_TNCRS_UPPER
, &phy_data
);
4084 ret_val
= hw
->phy
.ops
.read_reg_page(hw
, HV_TNCRS_LOWER
, &phy_data
);
4086 adapter
->stats
.tncrs
+= phy_data
;
4089 hw
->phy
.ops
.release(hw
);
4093 * e1000e_update_stats - Update the board statistics counters
4094 * @adapter: board private structure
4096 static void e1000e_update_stats(struct e1000_adapter
*adapter
)
4098 struct net_device
*netdev
= adapter
->netdev
;
4099 struct e1000_hw
*hw
= &adapter
->hw
;
4100 struct pci_dev
*pdev
= adapter
->pdev
;
4103 * Prevent stats update while adapter is being reset, or if the pci
4104 * connection is down.
4106 if (adapter
->link_speed
== 0)
4108 if (pci_channel_offline(pdev
))
4111 adapter
->stats
.crcerrs
+= er32(CRCERRS
);
4112 adapter
->stats
.gprc
+= er32(GPRC
);
4113 adapter
->stats
.gorc
+= er32(GORCL
);
4114 er32(GORCH
); /* Clear gorc */
4115 adapter
->stats
.bprc
+= er32(BPRC
);
4116 adapter
->stats
.mprc
+= er32(MPRC
);
4117 adapter
->stats
.roc
+= er32(ROC
);
4119 adapter
->stats
.mpc
+= er32(MPC
);
4121 /* Half-duplex statistics */
4122 if (adapter
->link_duplex
== HALF_DUPLEX
) {
4123 if (adapter
->flags2
& FLAG2_HAS_PHY_STATS
) {
4124 e1000e_update_phy_stats(adapter
);
4126 adapter
->stats
.scc
+= er32(SCC
);
4127 adapter
->stats
.ecol
+= er32(ECOL
);
4128 adapter
->stats
.mcc
+= er32(MCC
);
4129 adapter
->stats
.latecol
+= er32(LATECOL
);
4130 adapter
->stats
.dc
+= er32(DC
);
4132 hw
->mac
.collision_delta
= er32(COLC
);
4134 if ((hw
->mac
.type
!= e1000_82574
) &&
4135 (hw
->mac
.type
!= e1000_82583
))
4136 adapter
->stats
.tncrs
+= er32(TNCRS
);
4138 adapter
->stats
.colc
+= hw
->mac
.collision_delta
;
4141 adapter
->stats
.xonrxc
+= er32(XONRXC
);
4142 adapter
->stats
.xontxc
+= er32(XONTXC
);
4143 adapter
->stats
.xoffrxc
+= er32(XOFFRXC
);
4144 adapter
->stats
.xofftxc
+= er32(XOFFTXC
);
4145 adapter
->stats
.gptc
+= er32(GPTC
);
4146 adapter
->stats
.gotc
+= er32(GOTCL
);
4147 er32(GOTCH
); /* Clear gotc */
4148 adapter
->stats
.rnbc
+= er32(RNBC
);
4149 adapter
->stats
.ruc
+= er32(RUC
);
4151 adapter
->stats
.mptc
+= er32(MPTC
);
4152 adapter
->stats
.bptc
+= er32(BPTC
);
4154 /* used for adaptive IFS */
4156 hw
->mac
.tx_packet_delta
= er32(TPT
);
4157 adapter
->stats
.tpt
+= hw
->mac
.tx_packet_delta
;
4159 adapter
->stats
.algnerrc
+= er32(ALGNERRC
);
4160 adapter
->stats
.rxerrc
+= er32(RXERRC
);
4161 adapter
->stats
.cexterr
+= er32(CEXTERR
);
4162 adapter
->stats
.tsctc
+= er32(TSCTC
);
4163 adapter
->stats
.tsctfc
+= er32(TSCTFC
);
4165 /* Fill out the OS statistics structure */
4166 netdev
->stats
.multicast
= adapter
->stats
.mprc
;
4167 netdev
->stats
.collisions
= adapter
->stats
.colc
;
4172 * RLEC on some newer hardware can be incorrect so build
4173 * our own version based on RUC and ROC
4175 netdev
->stats
.rx_errors
= adapter
->stats
.rxerrc
+
4176 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
4177 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
4178 adapter
->stats
.cexterr
;
4179 netdev
->stats
.rx_length_errors
= adapter
->stats
.ruc
+
4181 netdev
->stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
4182 netdev
->stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
4183 netdev
->stats
.rx_missed_errors
= adapter
->stats
.mpc
;
4186 netdev
->stats
.tx_errors
= adapter
->stats
.ecol
+
4187 adapter
->stats
.latecol
;
4188 netdev
->stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
4189 netdev
->stats
.tx_window_errors
= adapter
->stats
.latecol
;
4190 netdev
->stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
4192 /* Tx Dropped needs to be maintained elsewhere */
4194 /* Management Stats */
4195 adapter
->stats
.mgptc
+= er32(MGTPTC
);
4196 adapter
->stats
.mgprc
+= er32(MGTPRC
);
4197 adapter
->stats
.mgpdc
+= er32(MGTPDC
);
4201 * e1000_phy_read_status - Update the PHY register status snapshot
4202 * @adapter: board private structure
4204 static void e1000_phy_read_status(struct e1000_adapter
*adapter
)
4206 struct e1000_hw
*hw
= &adapter
->hw
;
4207 struct e1000_phy_regs
*phy
= &adapter
->phy_regs
;
4209 if ((er32(STATUS
) & E1000_STATUS_LU
) &&
4210 (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
)) {
4213 ret_val
= e1e_rphy(hw
, PHY_CONTROL
, &phy
->bmcr
);
4214 ret_val
|= e1e_rphy(hw
, PHY_STATUS
, &phy
->bmsr
);
4215 ret_val
|= e1e_rphy(hw
, PHY_AUTONEG_ADV
, &phy
->advertise
);
4216 ret_val
|= e1e_rphy(hw
, PHY_LP_ABILITY
, &phy
->lpa
);
4217 ret_val
|= e1e_rphy(hw
, PHY_AUTONEG_EXP
, &phy
->expansion
);
4218 ret_val
|= e1e_rphy(hw
, PHY_1000T_CTRL
, &phy
->ctrl1000
);
4219 ret_val
|= e1e_rphy(hw
, PHY_1000T_STATUS
, &phy
->stat1000
);
4220 ret_val
|= e1e_rphy(hw
, PHY_EXT_STATUS
, &phy
->estatus
);
4222 e_warn("Error reading PHY register\n");
4225 * Do not read PHY registers if link is not up
4226 * Set values to typical power-on defaults
4228 phy
->bmcr
= (BMCR_SPEED1000
| BMCR_ANENABLE
| BMCR_FULLDPLX
);
4229 phy
->bmsr
= (BMSR_100FULL
| BMSR_100HALF
| BMSR_10FULL
|
4230 BMSR_10HALF
| BMSR_ESTATEN
| BMSR_ANEGCAPABLE
|
4232 phy
->advertise
= (ADVERTISE_PAUSE_ASYM
| ADVERTISE_PAUSE_CAP
|
4233 ADVERTISE_ALL
| ADVERTISE_CSMA
);
4235 phy
->expansion
= EXPANSION_ENABLENPAGE
;
4236 phy
->ctrl1000
= ADVERTISE_1000FULL
;
4238 phy
->estatus
= (ESTATUS_1000_TFULL
| ESTATUS_1000_THALF
);
4242 static void e1000_print_link_info(struct e1000_adapter
*adapter
)
4244 struct e1000_hw
*hw
= &adapter
->hw
;
4245 u32 ctrl
= er32(CTRL
);
4247 /* Link status message must follow this format for user tools */
4248 printk(KERN_INFO
"e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4249 adapter
->netdev
->name
,
4250 adapter
->link_speed
,
4251 adapter
->link_duplex
== FULL_DUPLEX
? "Full" : "Half",
4252 (ctrl
& E1000_CTRL_TFCE
) && (ctrl
& E1000_CTRL_RFCE
) ? "Rx/Tx" :
4253 (ctrl
& E1000_CTRL_RFCE
) ? "Rx" :
4254 (ctrl
& E1000_CTRL_TFCE
) ? "Tx" : "None");
4257 static bool e1000e_has_link(struct e1000_adapter
*adapter
)
4259 struct e1000_hw
*hw
= &adapter
->hw
;
4260 bool link_active
= false;
4264 * get_link_status is set on LSC (link status) interrupt or
4265 * Rx sequence error interrupt. get_link_status will stay
4266 * false until the check_for_link establishes link
4267 * for copper adapters ONLY
4269 switch (hw
->phy
.media_type
) {
4270 case e1000_media_type_copper
:
4271 if (hw
->mac
.get_link_status
) {
4272 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
4273 link_active
= !hw
->mac
.get_link_status
;
4278 case e1000_media_type_fiber
:
4279 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
4280 link_active
= !!(er32(STATUS
) & E1000_STATUS_LU
);
4282 case e1000_media_type_internal_serdes
:
4283 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
4284 link_active
= adapter
->hw
.mac
.serdes_has_link
;
4287 case e1000_media_type_unknown
:
4291 if ((ret_val
== E1000_ERR_PHY
) && (hw
->phy
.type
== e1000_phy_igp_3
) &&
4292 (er32(CTRL
) & E1000_PHY_CTRL_GBE_DISABLE
)) {
4293 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
4294 e_info("Gigabit has been disabled, downgrading speed\n");
4300 static void e1000e_enable_receives(struct e1000_adapter
*adapter
)
4302 /* make sure the receive unit is started */
4303 if ((adapter
->flags
& FLAG_RX_NEEDS_RESTART
) &&
4304 (adapter
->flags
& FLAG_RX_RESTART_NOW
)) {
4305 struct e1000_hw
*hw
= &adapter
->hw
;
4306 u32 rctl
= er32(RCTL
);
4307 ew32(RCTL
, rctl
| E1000_RCTL_EN
);
4308 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
4312 static void e1000e_check_82574_phy_workaround(struct e1000_adapter
*adapter
)
4314 struct e1000_hw
*hw
= &adapter
->hw
;
4317 * With 82574 controllers, PHY needs to be checked periodically
4318 * for hung state and reset, if two calls return true
4320 if (e1000_check_phy_82574(hw
))
4321 adapter
->phy_hang_count
++;
4323 adapter
->phy_hang_count
= 0;
4325 if (adapter
->phy_hang_count
> 1) {
4326 adapter
->phy_hang_count
= 0;
4327 schedule_work(&adapter
->reset_task
);
4332 * e1000_watchdog - Timer Call-back
4333 * @data: pointer to adapter cast into an unsigned long
4335 static void e1000_watchdog(unsigned long data
)
4337 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
4339 /* Do the rest outside of interrupt context */
4340 schedule_work(&adapter
->watchdog_task
);
4342 /* TODO: make this use queue_delayed_work() */
4345 static void e1000_watchdog_task(struct work_struct
*work
)
4347 struct e1000_adapter
*adapter
= container_of(work
,
4348 struct e1000_adapter
, watchdog_task
);
4349 struct net_device
*netdev
= adapter
->netdev
;
4350 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
4351 struct e1000_phy_info
*phy
= &adapter
->hw
.phy
;
4352 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4353 struct e1000_hw
*hw
= &adapter
->hw
;
4356 if (test_bit(__E1000_DOWN
, &adapter
->state
))
4359 link
= e1000e_has_link(adapter
);
4360 if ((netif_carrier_ok(netdev
)) && link
) {
4361 /* Cancel scheduled suspend requests. */
4362 pm_runtime_resume(netdev
->dev
.parent
);
4364 e1000e_enable_receives(adapter
);
4368 if ((e1000e_enable_tx_pkt_filtering(hw
)) &&
4369 (adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
))
4370 e1000_update_mng_vlan(adapter
);
4373 if (!netif_carrier_ok(netdev
)) {
4376 /* Cancel scheduled suspend requests. */
4377 pm_runtime_resume(netdev
->dev
.parent
);
4379 /* update snapshot of PHY registers on LSC */
4380 e1000_phy_read_status(adapter
);
4381 mac
->ops
.get_link_up_info(&adapter
->hw
,
4382 &adapter
->link_speed
,
4383 &adapter
->link_duplex
);
4384 e1000_print_link_info(adapter
);
4386 * On supported PHYs, check for duplex mismatch only
4387 * if link has autonegotiated at 10/100 half
4389 if ((hw
->phy
.type
== e1000_phy_igp_3
||
4390 hw
->phy
.type
== e1000_phy_bm
) &&
4391 (hw
->mac
.autoneg
== true) &&
4392 (adapter
->link_speed
== SPEED_10
||
4393 adapter
->link_speed
== SPEED_100
) &&
4394 (adapter
->link_duplex
== HALF_DUPLEX
)) {
4397 e1e_rphy(hw
, PHY_AUTONEG_EXP
, &autoneg_exp
);
4399 if (!(autoneg_exp
& NWAY_ER_LP_NWAY_CAPS
))
4400 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
4403 /* adjust timeout factor according to speed/duplex */
4404 adapter
->tx_timeout_factor
= 1;
4405 switch (adapter
->link_speed
) {
4408 adapter
->tx_timeout_factor
= 16;
4412 adapter
->tx_timeout_factor
= 10;
4417 * workaround: re-program speed mode bit after
4420 if ((adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) &&
4423 tarc0
= er32(TARC(0));
4424 tarc0
&= ~SPEED_MODE_BIT
;
4425 ew32(TARC(0), tarc0
);
4429 * disable TSO for pcie and 10/100 speeds, to avoid
4430 * some hardware issues
4432 if (!(adapter
->flags
& FLAG_TSO_FORCE
)) {
4433 switch (adapter
->link_speed
) {
4436 e_info("10/100 speed: disabling TSO\n");
4437 netdev
->features
&= ~NETIF_F_TSO
;
4438 netdev
->features
&= ~NETIF_F_TSO6
;
4441 netdev
->features
|= NETIF_F_TSO
;
4442 netdev
->features
|= NETIF_F_TSO6
;
4451 * enable transmits in the hardware, need to do this
4452 * after setting TARC(0)
4455 tctl
|= E1000_TCTL_EN
;
4459 * Perform any post-link-up configuration before
4460 * reporting link up.
4462 if (phy
->ops
.cfg_on_link_up
)
4463 phy
->ops
.cfg_on_link_up(hw
);
4465 netif_carrier_on(netdev
);
4467 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
4468 mod_timer(&adapter
->phy_info_timer
,
4469 round_jiffies(jiffies
+ 2 * HZ
));
4472 if (netif_carrier_ok(netdev
)) {
4473 adapter
->link_speed
= 0;
4474 adapter
->link_duplex
= 0;
4475 /* Link status message must follow this format */
4476 printk(KERN_INFO
"e1000e: %s NIC Link is Down\n",
4477 adapter
->netdev
->name
);
4478 netif_carrier_off(netdev
);
4479 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
4480 mod_timer(&adapter
->phy_info_timer
,
4481 round_jiffies(jiffies
+ 2 * HZ
));
4483 if (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)
4484 schedule_work(&adapter
->reset_task
);
4486 pm_schedule_suspend(netdev
->dev
.parent
,
4492 spin_lock(&adapter
->stats64_lock
);
4493 e1000e_update_stats(adapter
);
4495 mac
->tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
4496 adapter
->tpt_old
= adapter
->stats
.tpt
;
4497 mac
->collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
4498 adapter
->colc_old
= adapter
->stats
.colc
;
4500 adapter
->gorc
= adapter
->stats
.gorc
- adapter
->gorc_old
;
4501 adapter
->gorc_old
= adapter
->stats
.gorc
;
4502 adapter
->gotc
= adapter
->stats
.gotc
- adapter
->gotc_old
;
4503 adapter
->gotc_old
= adapter
->stats
.gotc
;
4504 spin_unlock(&adapter
->stats64_lock
);
4506 e1000e_update_adaptive(&adapter
->hw
);
4508 if (!netif_carrier_ok(netdev
) &&
4509 (e1000_desc_unused(tx_ring
) + 1 < tx_ring
->count
)) {
4511 * We've lost link, so the controller stops DMA,
4512 * but we've got queued Tx work that's never going
4513 * to get done, so reset controller to flush Tx.
4514 * (Do the reset outside of interrupt context).
4516 schedule_work(&adapter
->reset_task
);
4517 /* return immediately since reset is imminent */
4521 /* Simple mode for Interrupt Throttle Rate (ITR) */
4522 if (adapter
->itr_setting
== 4) {
4524 * Symmetric Tx/Rx gets a reduced ITR=2000;
4525 * Total asymmetrical Tx or Rx gets ITR=8000;
4526 * everyone else is between 2000-8000.
4528 u32 goc
= (adapter
->gotc
+ adapter
->gorc
) / 10000;
4529 u32 dif
= (adapter
->gotc
> adapter
->gorc
?
4530 adapter
->gotc
- adapter
->gorc
:
4531 adapter
->gorc
- adapter
->gotc
) / 10000;
4532 u32 itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
4534 ew32(ITR
, 1000000000 / (itr
* 256));
4537 /* Cause software interrupt to ensure Rx ring is cleaned */
4538 if (adapter
->msix_entries
)
4539 ew32(ICS
, adapter
->rx_ring
->ims_val
);
4541 ew32(ICS
, E1000_ICS_RXDMT0
);
4543 /* flush pending descriptors to memory before detecting Tx hang */
4544 e1000e_flush_descriptors(adapter
);
4546 /* Force detection of hung controller every watchdog period */
4547 adapter
->detect_tx_hung
= true;
4550 * With 82571 controllers, LAA may be overwritten due to controller
4551 * reset from the other port. Set the appropriate LAA in RAR[0]
4553 if (e1000e_get_laa_state_82571(hw
))
4554 e1000e_rar_set(hw
, adapter
->hw
.mac
.addr
, 0);
4556 if (adapter
->flags2
& FLAG2_CHECK_PHY_HANG
)
4557 e1000e_check_82574_phy_workaround(adapter
);
4559 /* Reset the timer */
4560 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
4561 mod_timer(&adapter
->watchdog_timer
,
4562 round_jiffies(jiffies
+ 2 * HZ
));
4565 #define E1000_TX_FLAGS_CSUM 0x00000001
4566 #define E1000_TX_FLAGS_VLAN 0x00000002
4567 #define E1000_TX_FLAGS_TSO 0x00000004
4568 #define E1000_TX_FLAGS_IPV4 0x00000008
4569 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4570 #define E1000_TX_FLAGS_VLAN_SHIFT 16
4572 static int e1000_tso(struct e1000_adapter
*adapter
,
4573 struct sk_buff
*skb
)
4575 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4576 struct e1000_context_desc
*context_desc
;
4577 struct e1000_buffer
*buffer_info
;
4580 u16 ipcse
= 0, tucse
, mss
;
4581 u8 ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
4583 if (!skb_is_gso(skb
))
4586 if (skb_header_cloned(skb
)) {
4587 int err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
4593 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
4594 mss
= skb_shinfo(skb
)->gso_size
;
4595 if (skb
->protocol
== htons(ETH_P_IP
)) {
4596 struct iphdr
*iph
= ip_hdr(skb
);
4599 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
4601 cmd_length
= E1000_TXD_CMD_IP
;
4602 ipcse
= skb_transport_offset(skb
) - 1;
4603 } else if (skb_is_gso_v6(skb
)) {
4604 ipv6_hdr(skb
)->payload_len
= 0;
4605 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
4606 &ipv6_hdr(skb
)->daddr
,
4610 ipcss
= skb_network_offset(skb
);
4611 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
4612 tucss
= skb_transport_offset(skb
);
4613 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
4616 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
4617 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
4619 i
= tx_ring
->next_to_use
;
4620 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
4621 buffer_info
= &tx_ring
->buffer_info
[i
];
4623 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
4624 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
4625 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
4626 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
4627 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
4628 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
4629 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
4630 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
4631 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
4633 buffer_info
->time_stamp
= jiffies
;
4634 buffer_info
->next_to_watch
= i
;
4637 if (i
== tx_ring
->count
)
4639 tx_ring
->next_to_use
= i
;
4644 static bool e1000_tx_csum(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
4646 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4647 struct e1000_context_desc
*context_desc
;
4648 struct e1000_buffer
*buffer_info
;
4651 u32 cmd_len
= E1000_TXD_CMD_DEXT
;
4654 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
4657 if (skb
->protocol
== cpu_to_be16(ETH_P_8021Q
))
4658 protocol
= vlan_eth_hdr(skb
)->h_vlan_encapsulated_proto
;
4660 protocol
= skb
->protocol
;
4663 case cpu_to_be16(ETH_P_IP
):
4664 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
4665 cmd_len
|= E1000_TXD_CMD_TCP
;
4667 case cpu_to_be16(ETH_P_IPV6
):
4668 /* XXX not handling all IPV6 headers */
4669 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
4670 cmd_len
|= E1000_TXD_CMD_TCP
;
4673 if (unlikely(net_ratelimit()))
4674 e_warn("checksum_partial proto=%x!\n",
4675 be16_to_cpu(protocol
));
4679 css
= skb_checksum_start_offset(skb
);
4681 i
= tx_ring
->next_to_use
;
4682 buffer_info
= &tx_ring
->buffer_info
[i
];
4683 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
4685 context_desc
->lower_setup
.ip_config
= 0;
4686 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
4687 context_desc
->upper_setup
.tcp_fields
.tucso
=
4688 css
+ skb
->csum_offset
;
4689 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
4690 context_desc
->tcp_seg_setup
.data
= 0;
4691 context_desc
->cmd_and_length
= cpu_to_le32(cmd_len
);
4693 buffer_info
->time_stamp
= jiffies
;
4694 buffer_info
->next_to_watch
= i
;
4697 if (i
== tx_ring
->count
)
4699 tx_ring
->next_to_use
= i
;
4704 #define E1000_MAX_PER_TXD 8192
4705 #define E1000_MAX_TXD_PWR 12
4707 static int e1000_tx_map(struct e1000_adapter
*adapter
,
4708 struct sk_buff
*skb
, unsigned int first
,
4709 unsigned int max_per_txd
, unsigned int nr_frags
,
4712 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4713 struct pci_dev
*pdev
= adapter
->pdev
;
4714 struct e1000_buffer
*buffer_info
;
4715 unsigned int len
= skb_headlen(skb
);
4716 unsigned int offset
= 0, size
, count
= 0, i
;
4717 unsigned int f
, bytecount
, segs
;
4719 i
= tx_ring
->next_to_use
;
4722 buffer_info
= &tx_ring
->buffer_info
[i
];
4723 size
= min(len
, max_per_txd
);
4725 buffer_info
->length
= size
;
4726 buffer_info
->time_stamp
= jiffies
;
4727 buffer_info
->next_to_watch
= i
;
4728 buffer_info
->dma
= dma_map_single(&pdev
->dev
,
4730 size
, DMA_TO_DEVICE
);
4731 buffer_info
->mapped_as_page
= false;
4732 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
))
4741 if (i
== tx_ring
->count
)
4746 for (f
= 0; f
< nr_frags
; f
++) {
4747 const struct skb_frag_struct
*frag
;
4749 frag
= &skb_shinfo(skb
)->frags
[f
];
4750 len
= skb_frag_size(frag
);
4755 if (i
== tx_ring
->count
)
4758 buffer_info
= &tx_ring
->buffer_info
[i
];
4759 size
= min(len
, max_per_txd
);
4761 buffer_info
->length
= size
;
4762 buffer_info
->time_stamp
= jiffies
;
4763 buffer_info
->next_to_watch
= i
;
4764 buffer_info
->dma
= skb_frag_dma_map(&pdev
->dev
, frag
,
4765 offset
, size
, DMA_TO_DEVICE
);
4766 buffer_info
->mapped_as_page
= true;
4767 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
))
4776 segs
= skb_shinfo(skb
)->gso_segs
? : 1;
4777 /* multiply data chunks by size of headers */
4778 bytecount
= ((segs
- 1) * skb_headlen(skb
)) + skb
->len
;
4780 tx_ring
->buffer_info
[i
].skb
= skb
;
4781 tx_ring
->buffer_info
[i
].segs
= segs
;
4782 tx_ring
->buffer_info
[i
].bytecount
= bytecount
;
4783 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
4788 dev_err(&pdev
->dev
, "Tx DMA map failed\n");
4789 buffer_info
->dma
= 0;
4795 i
+= tx_ring
->count
;
4797 buffer_info
= &tx_ring
->buffer_info
[i
];
4798 e1000_put_txbuf(adapter
, buffer_info
);
4804 static void e1000_tx_queue(struct e1000_adapter
*adapter
,
4805 int tx_flags
, int count
)
4807 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4808 struct e1000_tx_desc
*tx_desc
= NULL
;
4809 struct e1000_buffer
*buffer_info
;
4810 u32 txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
4813 if (tx_flags
& E1000_TX_FLAGS_TSO
) {
4814 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
4816 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
4818 if (tx_flags
& E1000_TX_FLAGS_IPV4
)
4819 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
4822 if (tx_flags
& E1000_TX_FLAGS_CSUM
) {
4823 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
4824 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
4827 if (tx_flags
& E1000_TX_FLAGS_VLAN
) {
4828 txd_lower
|= E1000_TXD_CMD_VLE
;
4829 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
4832 i
= tx_ring
->next_to_use
;
4835 buffer_info
= &tx_ring
->buffer_info
[i
];
4836 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
4837 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4838 tx_desc
->lower
.data
=
4839 cpu_to_le32(txd_lower
| buffer_info
->length
);
4840 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
4843 if (i
== tx_ring
->count
)
4845 } while (--count
> 0);
4847 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
4850 * Force memory writes to complete before letting h/w
4851 * know there are new descriptors to fetch. (Only
4852 * applicable for weak-ordered memory model archs,
4857 tx_ring
->next_to_use
= i
;
4859 if (adapter
->flags2
& FLAG2_PCIM2PCI_ARBITER_WA
)
4860 e1000e_update_tdt_wa(adapter
, i
);
4862 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
4865 * we need this if more than one processor can write to our tail
4866 * at a time, it synchronizes IO on IA64/Altix systems
4871 #define MINIMUM_DHCP_PACKET_SIZE 282
4872 static int e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
,
4873 struct sk_buff
*skb
)
4875 struct e1000_hw
*hw
= &adapter
->hw
;
4878 if (vlan_tx_tag_present(skb
)) {
4879 if (!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
4880 (adapter
->hw
.mng_cookie
.status
&
4881 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
)))
4885 if (skb
->len
<= MINIMUM_DHCP_PACKET_SIZE
)
4888 if (((struct ethhdr
*) skb
->data
)->h_proto
!= htons(ETH_P_IP
))
4892 const struct iphdr
*ip
= (struct iphdr
*)((u8
*)skb
->data
+14);
4895 if (ip
->protocol
!= IPPROTO_UDP
)
4898 udp
= (struct udphdr
*)((u8
*)ip
+ (ip
->ihl
<< 2));
4899 if (ntohs(udp
->dest
) != 67)
4902 offset
= (u8
*)udp
+ 8 - skb
->data
;
4903 length
= skb
->len
- offset
;
4904 return e1000e_mng_write_dhcp_info(hw
, (u8
*)udp
+ 8, length
);
4910 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
4912 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4914 netif_stop_queue(netdev
);
4916 * Herbert's original patch had:
4917 * smp_mb__after_netif_stop_queue();
4918 * but since that doesn't exist yet, just open code it.
4923 * We need to check again in a case another CPU has just
4924 * made room available.
4926 if (e1000_desc_unused(adapter
->tx_ring
) < size
)
4930 netif_start_queue(netdev
);
4931 ++adapter
->restart_queue
;
4935 static int e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
4937 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4939 if (e1000_desc_unused(adapter
->tx_ring
) >= size
)
4941 return __e1000_maybe_stop_tx(netdev
, size
);
4944 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4945 static netdev_tx_t
e1000_xmit_frame(struct sk_buff
*skb
,
4946 struct net_device
*netdev
)
4948 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4949 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4951 unsigned int max_per_txd
= E1000_MAX_PER_TXD
;
4952 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
4953 unsigned int tx_flags
= 0;
4954 unsigned int len
= skb_headlen(skb
);
4955 unsigned int nr_frags
;
4961 if (test_bit(__E1000_DOWN
, &adapter
->state
)) {
4962 dev_kfree_skb_any(skb
);
4963 return NETDEV_TX_OK
;
4966 if (skb
->len
<= 0) {
4967 dev_kfree_skb_any(skb
);
4968 return NETDEV_TX_OK
;
4971 mss
= skb_shinfo(skb
)->gso_size
;
4973 * The controller does a simple calculation to
4974 * make sure there is enough room in the FIFO before
4975 * initiating the DMA for each buffer. The calc is:
4976 * 4 = ceil(buffer len/mss). To make sure we don't
4977 * overrun the FIFO, adjust the max buffer len if mss
4982 max_per_txd
= min(mss
<< 2, max_per_txd
);
4983 max_txd_pwr
= fls(max_per_txd
) - 1;
4986 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4987 * points to just header, pull a few bytes of payload from
4988 * frags into skb->data
4990 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
4992 * we do this workaround for ES2LAN, but it is un-necessary,
4993 * avoiding it could save a lot of cycles
4995 if (skb
->data_len
&& (hdr_len
== len
)) {
4996 unsigned int pull_size
;
4998 pull_size
= min((unsigned int)4, skb
->data_len
);
4999 if (!__pskb_pull_tail(skb
, pull_size
)) {
5000 e_err("__pskb_pull_tail failed.\n");
5001 dev_kfree_skb_any(skb
);
5002 return NETDEV_TX_OK
;
5004 len
= skb_headlen(skb
);
5008 /* reserve a descriptor for the offload context */
5009 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
5013 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
5015 nr_frags
= skb_shinfo(skb
)->nr_frags
;
5016 for (f
= 0; f
< nr_frags
; f
++)
5017 count
+= TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb
)->frags
[f
]),
5020 if (adapter
->hw
.mac
.tx_pkt_filtering
)
5021 e1000_transfer_dhcp_info(adapter
, skb
);
5024 * need: count + 2 desc gap to keep tail from touching
5025 * head, otherwise try next time
5027 if (e1000_maybe_stop_tx(netdev
, count
+ 2))
5028 return NETDEV_TX_BUSY
;
5030 if (vlan_tx_tag_present(skb
)) {
5031 tx_flags
|= E1000_TX_FLAGS_VLAN
;
5032 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
5035 first
= tx_ring
->next_to_use
;
5037 tso
= e1000_tso(adapter
, skb
);
5039 dev_kfree_skb_any(skb
);
5040 return NETDEV_TX_OK
;
5044 tx_flags
|= E1000_TX_FLAGS_TSO
;
5045 else if (e1000_tx_csum(adapter
, skb
))
5046 tx_flags
|= E1000_TX_FLAGS_CSUM
;
5049 * Old method was to assume IPv4 packet by default if TSO was enabled.
5050 * 82571 hardware supports TSO capabilities for IPv6 as well...
5051 * no longer assume, we must.
5053 if (skb
->protocol
== htons(ETH_P_IP
))
5054 tx_flags
|= E1000_TX_FLAGS_IPV4
;
5056 /* if count is 0 then mapping error has occurred */
5057 count
= e1000_tx_map(adapter
, skb
, first
, max_per_txd
, nr_frags
, mss
);
5059 netdev_sent_queue(netdev
, skb
->len
);
5060 e1000_tx_queue(adapter
, tx_flags
, count
);
5061 /* Make sure there is space in the ring for the next send. */
5062 e1000_maybe_stop_tx(netdev
, MAX_SKB_FRAGS
+ 2);
5065 dev_kfree_skb_any(skb
);
5066 tx_ring
->buffer_info
[first
].time_stamp
= 0;
5067 tx_ring
->next_to_use
= first
;
5070 return NETDEV_TX_OK
;
5074 * e1000_tx_timeout - Respond to a Tx Hang
5075 * @netdev: network interface device structure
5077 static void e1000_tx_timeout(struct net_device
*netdev
)
5079 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5081 /* Do the reset outside of interrupt context */
5082 adapter
->tx_timeout_count
++;
5083 schedule_work(&adapter
->reset_task
);
5086 static void e1000_reset_task(struct work_struct
*work
)
5088 struct e1000_adapter
*adapter
;
5089 adapter
= container_of(work
, struct e1000_adapter
, reset_task
);
5091 /* don't run the task if already down */
5092 if (test_bit(__E1000_DOWN
, &adapter
->state
))
5095 if (!((adapter
->flags
& FLAG_RX_NEEDS_RESTART
) &&
5096 (adapter
->flags
& FLAG_RX_RESTART_NOW
))) {
5097 e1000e_dump(adapter
);
5098 e_err("Reset adapter\n");
5100 e1000e_reinit_locked(adapter
);
5104 * e1000_get_stats64 - Get System Network Statistics
5105 * @netdev: network interface device structure
5106 * @stats: rtnl_link_stats64 pointer
5108 * Returns the address of the device statistics structure.
5110 struct rtnl_link_stats64
*e1000e_get_stats64(struct net_device
*netdev
,
5111 struct rtnl_link_stats64
*stats
)
5113 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5115 memset(stats
, 0, sizeof(struct rtnl_link_stats64
));
5116 spin_lock(&adapter
->stats64_lock
);
5117 e1000e_update_stats(adapter
);
5118 /* Fill out the OS statistics structure */
5119 stats
->rx_bytes
= adapter
->stats
.gorc
;
5120 stats
->rx_packets
= adapter
->stats
.gprc
;
5121 stats
->tx_bytes
= adapter
->stats
.gotc
;
5122 stats
->tx_packets
= adapter
->stats
.gptc
;
5123 stats
->multicast
= adapter
->stats
.mprc
;
5124 stats
->collisions
= adapter
->stats
.colc
;
5129 * RLEC on some newer hardware can be incorrect so build
5130 * our own version based on RUC and ROC
5132 stats
->rx_errors
= adapter
->stats
.rxerrc
+
5133 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
5134 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
5135 adapter
->stats
.cexterr
;
5136 stats
->rx_length_errors
= adapter
->stats
.ruc
+
5138 stats
->rx_crc_errors
= adapter
->stats
.crcerrs
;
5139 stats
->rx_frame_errors
= adapter
->stats
.algnerrc
;
5140 stats
->rx_missed_errors
= adapter
->stats
.mpc
;
5143 stats
->tx_errors
= adapter
->stats
.ecol
+
5144 adapter
->stats
.latecol
;
5145 stats
->tx_aborted_errors
= adapter
->stats
.ecol
;
5146 stats
->tx_window_errors
= adapter
->stats
.latecol
;
5147 stats
->tx_carrier_errors
= adapter
->stats
.tncrs
;
5149 /* Tx Dropped needs to be maintained elsewhere */
5151 spin_unlock(&adapter
->stats64_lock
);
5156 * e1000_change_mtu - Change the Maximum Transfer Unit
5157 * @netdev: network interface device structure
5158 * @new_mtu: new value for maximum frame size
5160 * Returns 0 on success, negative on failure
5162 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
5164 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5165 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5167 /* Jumbo frame support */
5168 if ((max_frame
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) &&
5169 !(adapter
->flags
& FLAG_HAS_JUMBO_FRAMES
)) {
5170 e_err("Jumbo Frames not supported.\n");
5174 /* Supported frame sizes */
5175 if ((new_mtu
< ETH_ZLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
) ||
5176 (max_frame
> adapter
->max_hw_frame_size
)) {
5177 e_err("Unsupported MTU setting\n");
5181 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5182 if ((adapter
->hw
.mac
.type
== e1000_pch2lan
) &&
5183 !(adapter
->flags2
& FLAG2_CRC_STRIPPING
) &&
5184 (new_mtu
> ETH_DATA_LEN
)) {
5185 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
5189 /* 82573 Errata 17 */
5190 if (((adapter
->hw
.mac
.type
== e1000_82573
) ||
5191 (adapter
->hw
.mac
.type
== e1000_82574
)) &&
5192 (max_frame
> ETH_FRAME_LEN
+ ETH_FCS_LEN
)) {
5193 adapter
->flags2
|= FLAG2_DISABLE_ASPM_L1
;
5194 e1000e_disable_aspm(adapter
->pdev
, PCIE_LINK_STATE_L1
);
5197 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
5198 usleep_range(1000, 2000);
5199 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
5200 adapter
->max_frame_size
= max_frame
;
5201 e_info("changing MTU from %d to %d\n", netdev
->mtu
, new_mtu
);
5202 netdev
->mtu
= new_mtu
;
5203 if (netif_running(netdev
))
5204 e1000e_down(adapter
);
5207 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
5208 * means we reserve 2 more, this pushes us to allocate from the next
5210 * i.e. RXBUFFER_2048 --> size-4096 slab
5211 * However with the new *_jumbo_rx* routines, jumbo receives will use
5215 if (max_frame
<= 2048)
5216 adapter
->rx_buffer_len
= 2048;
5218 adapter
->rx_buffer_len
= 4096;
5220 /* adjust allocation if LPE protects us, and we aren't using SBP */
5221 if ((max_frame
== ETH_FRAME_LEN
+ ETH_FCS_LEN
) ||
5222 (max_frame
== ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
))
5223 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
5226 if (netif_running(netdev
))
5229 e1000e_reset(adapter
);
5231 clear_bit(__E1000_RESETTING
, &adapter
->state
);
5236 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
5239 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5240 struct mii_ioctl_data
*data
= if_mii(ifr
);
5242 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
5247 data
->phy_id
= adapter
->hw
.phy
.addr
;
5250 e1000_phy_read_status(adapter
);
5252 switch (data
->reg_num
& 0x1F) {
5254 data
->val_out
= adapter
->phy_regs
.bmcr
;
5257 data
->val_out
= adapter
->phy_regs
.bmsr
;
5260 data
->val_out
= (adapter
->hw
.phy
.id
>> 16);
5263 data
->val_out
= (adapter
->hw
.phy
.id
& 0xFFFF);
5266 data
->val_out
= adapter
->phy_regs
.advertise
;
5269 data
->val_out
= adapter
->phy_regs
.lpa
;
5272 data
->val_out
= adapter
->phy_regs
.expansion
;
5275 data
->val_out
= adapter
->phy_regs
.ctrl1000
;
5278 data
->val_out
= adapter
->phy_regs
.stat1000
;
5281 data
->val_out
= adapter
->phy_regs
.estatus
;
5294 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
5300 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
5306 static int e1000_init_phy_wakeup(struct e1000_adapter
*adapter
, u32 wufc
)
5308 struct e1000_hw
*hw
= &adapter
->hw
;
5310 u16 phy_reg
, wuc_enable
;
5313 /* copy MAC RARs to PHY RARs */
5314 e1000_copy_rx_addrs_to_phy_ich8lan(hw
);
5316 retval
= hw
->phy
.ops
.acquire(hw
);
5318 e_err("Could not acquire PHY\n");
5322 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5323 retval
= e1000_enable_phy_wakeup_reg_access_bm(hw
, &wuc_enable
);
5327 /* copy MAC MTA to PHY MTA - only needed for pchlan */
5328 for (i
= 0; i
< adapter
->hw
.mac
.mta_reg_count
; i
++) {
5329 mac_reg
= E1000_READ_REG_ARRAY(hw
, E1000_MTA
, i
);
5330 hw
->phy
.ops
.write_reg_page(hw
, BM_MTA(i
),
5331 (u16
)(mac_reg
& 0xFFFF));
5332 hw
->phy
.ops
.write_reg_page(hw
, BM_MTA(i
) + 1,
5333 (u16
)((mac_reg
>> 16) & 0xFFFF));
5336 /* configure PHY Rx Control register */
5337 hw
->phy
.ops
.read_reg_page(&adapter
->hw
, BM_RCTL
, &phy_reg
);
5338 mac_reg
= er32(RCTL
);
5339 if (mac_reg
& E1000_RCTL_UPE
)
5340 phy_reg
|= BM_RCTL_UPE
;
5341 if (mac_reg
& E1000_RCTL_MPE
)
5342 phy_reg
|= BM_RCTL_MPE
;
5343 phy_reg
&= ~(BM_RCTL_MO_MASK
);
5344 if (mac_reg
& E1000_RCTL_MO_3
)
5345 phy_reg
|= (((mac_reg
& E1000_RCTL_MO_3
) >> E1000_RCTL_MO_SHIFT
)
5346 << BM_RCTL_MO_SHIFT
);
5347 if (mac_reg
& E1000_RCTL_BAM
)
5348 phy_reg
|= BM_RCTL_BAM
;
5349 if (mac_reg
& E1000_RCTL_PMCF
)
5350 phy_reg
|= BM_RCTL_PMCF
;
5351 mac_reg
= er32(CTRL
);
5352 if (mac_reg
& E1000_CTRL_RFCE
)
5353 phy_reg
|= BM_RCTL_RFCE
;
5354 hw
->phy
.ops
.write_reg_page(&adapter
->hw
, BM_RCTL
, phy_reg
);
5356 /* enable PHY wakeup in MAC register */
5358 ew32(WUC
, E1000_WUC_PHY_WAKE
| E1000_WUC_PME_EN
);
5360 /* configure and enable PHY wakeup in PHY registers */
5361 hw
->phy
.ops
.write_reg_page(&adapter
->hw
, BM_WUFC
, wufc
);
5362 hw
->phy
.ops
.write_reg_page(&adapter
->hw
, BM_WUC
, E1000_WUC_PME_EN
);
5364 /* activate PHY wakeup */
5365 wuc_enable
|= BM_WUC_ENABLE_BIT
| BM_WUC_HOST_WU_BIT
;
5366 retval
= e1000_disable_phy_wakeup_reg_access_bm(hw
, &wuc_enable
);
5368 e_err("Could not set PHY Host Wakeup bit\n");
5370 hw
->phy
.ops
.release(hw
);
5375 static int __e1000_shutdown(struct pci_dev
*pdev
, bool *enable_wake
,
5378 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5379 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5380 struct e1000_hw
*hw
= &adapter
->hw
;
5381 u32 ctrl
, ctrl_ext
, rctl
, status
;
5382 /* Runtime suspend should only enable wakeup for link changes */
5383 u32 wufc
= runtime
? E1000_WUFC_LNKC
: adapter
->wol
;
5386 netif_device_detach(netdev
);
5388 if (netif_running(netdev
)) {
5389 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
5390 e1000e_down(adapter
);
5391 e1000_free_irq(adapter
);
5393 e1000e_reset_interrupt_capability(adapter
);
5395 retval
= pci_save_state(pdev
);
5399 status
= er32(STATUS
);
5400 if (status
& E1000_STATUS_LU
)
5401 wufc
&= ~E1000_WUFC_LNKC
;
5404 e1000_setup_rctl(adapter
);
5405 e1000e_set_rx_mode(netdev
);
5407 /* turn on all-multi mode if wake on multicast is enabled */
5408 if (wufc
& E1000_WUFC_MC
) {
5410 rctl
|= E1000_RCTL_MPE
;
5415 /* advertise wake from D3Cold */
5416 #define E1000_CTRL_ADVD3WUC 0x00100000
5417 /* phy power management enable */
5418 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5419 ctrl
|= E1000_CTRL_ADVD3WUC
;
5420 if (!(adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
))
5421 ctrl
|= E1000_CTRL_EN_PHY_PWR_MGMT
;
5424 if (adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
||
5425 adapter
->hw
.phy
.media_type
==
5426 e1000_media_type_internal_serdes
) {
5427 /* keep the laser running in D3 */
5428 ctrl_ext
= er32(CTRL_EXT
);
5429 ctrl_ext
|= E1000_CTRL_EXT_SDP3_DATA
;
5430 ew32(CTRL_EXT
, ctrl_ext
);
5433 if (adapter
->flags
& FLAG_IS_ICH
)
5434 e1000_suspend_workarounds_ich8lan(&adapter
->hw
);
5436 /* Allow time for pending master requests to run */
5437 e1000e_disable_pcie_master(&adapter
->hw
);
5439 if (adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
) {
5440 /* enable wakeup by the PHY */
5441 retval
= e1000_init_phy_wakeup(adapter
, wufc
);
5445 /* enable wakeup by the MAC */
5447 ew32(WUC
, E1000_WUC_PME_EN
);
5454 *enable_wake
= !!wufc
;
5456 /* make sure adapter isn't asleep if manageability is enabled */
5457 if ((adapter
->flags
& FLAG_MNG_PT_ENABLED
) ||
5458 (hw
->mac
.ops
.check_mng_mode(hw
)))
5459 *enable_wake
= true;
5461 if (adapter
->hw
.phy
.type
== e1000_phy_igp_3
)
5462 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter
->hw
);
5465 * Release control of h/w to f/w. If f/w is AMT enabled, this
5466 * would have already happened in close and is redundant.
5468 e1000e_release_hw_control(adapter
);
5470 pci_disable_device(pdev
);
5475 static void e1000_power_off(struct pci_dev
*pdev
, bool sleep
, bool wake
)
5477 if (sleep
&& wake
) {
5478 pci_prepare_to_sleep(pdev
);
5482 pci_wake_from_d3(pdev
, wake
);
5483 pci_set_power_state(pdev
, PCI_D3hot
);
5486 static void e1000_complete_shutdown(struct pci_dev
*pdev
, bool sleep
,
5489 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5490 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5493 * The pci-e switch on some quad port adapters will report a
5494 * correctable error when the MAC transitions from D0 to D3. To
5495 * prevent this we need to mask off the correctable errors on the
5496 * downstream port of the pci-e switch.
5498 if (adapter
->flags
& FLAG_IS_QUAD_PORT
) {
5499 struct pci_dev
*us_dev
= pdev
->bus
->self
;
5500 int pos
= pci_pcie_cap(us_dev
);
5503 pci_read_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
, &devctl
);
5504 pci_write_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
,
5505 (devctl
& ~PCI_EXP_DEVCTL_CERE
));
5507 e1000_power_off(pdev
, sleep
, wake
);
5509 pci_write_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
, devctl
);
5511 e1000_power_off(pdev
, sleep
, wake
);
5515 #ifdef CONFIG_PCIEASPM
5516 static void __e1000e_disable_aspm(struct pci_dev
*pdev
, u16 state
)
5518 pci_disable_link_state_locked(pdev
, state
);
5521 static void __e1000e_disable_aspm(struct pci_dev
*pdev
, u16 state
)
5527 * Both device and parent should have the same ASPM setting.
5528 * Disable ASPM in downstream component first and then upstream.
5530 pos
= pci_pcie_cap(pdev
);
5531 pci_read_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, ®16
);
5533 pci_write_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, reg16
);
5535 if (!pdev
->bus
->self
)
5538 pos
= pci_pcie_cap(pdev
->bus
->self
);
5539 pci_read_config_word(pdev
->bus
->self
, pos
+ PCI_EXP_LNKCTL
, ®16
);
5541 pci_write_config_word(pdev
->bus
->self
, pos
+ PCI_EXP_LNKCTL
, reg16
);
5544 static void e1000e_disable_aspm(struct pci_dev
*pdev
, u16 state
)
5546 dev_info(&pdev
->dev
, "Disabling ASPM %s %s\n",
5547 (state
& PCIE_LINK_STATE_L0S
) ? "L0s" : "",
5548 (state
& PCIE_LINK_STATE_L1
) ? "L1" : "");
5550 __e1000e_disable_aspm(pdev
, state
);
5554 static bool e1000e_pm_ready(struct e1000_adapter
*adapter
)
5556 return !!adapter
->tx_ring
->buffer_info
;
5559 static int __e1000_resume(struct pci_dev
*pdev
)
5561 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5562 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5563 struct e1000_hw
*hw
= &adapter
->hw
;
5564 u16 aspm_disable_flag
= 0;
5567 if (adapter
->flags2
& FLAG2_DISABLE_ASPM_L0S
)
5568 aspm_disable_flag
= PCIE_LINK_STATE_L0S
;
5569 if (adapter
->flags2
& FLAG2_DISABLE_ASPM_L1
)
5570 aspm_disable_flag
|= PCIE_LINK_STATE_L1
;
5571 if (aspm_disable_flag
)
5572 e1000e_disable_aspm(pdev
, aspm_disable_flag
);
5574 pci_set_power_state(pdev
, PCI_D0
);
5575 pci_restore_state(pdev
);
5576 pci_save_state(pdev
);
5578 e1000e_set_interrupt_capability(adapter
);
5579 if (netif_running(netdev
)) {
5580 err
= e1000_request_irq(adapter
);
5585 if (hw
->mac
.type
== e1000_pch2lan
)
5586 e1000_resume_workarounds_pchlan(&adapter
->hw
);
5588 e1000e_power_up_phy(adapter
);
5590 /* report the system wakeup cause from S3/S4 */
5591 if (adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
) {
5594 e1e_rphy(&adapter
->hw
, BM_WUS
, &phy_data
);
5596 e_info("PHY Wakeup cause - %s\n",
5597 phy_data
& E1000_WUS_EX
? "Unicast Packet" :
5598 phy_data
& E1000_WUS_MC
? "Multicast Packet" :
5599 phy_data
& E1000_WUS_BC
? "Broadcast Packet" :
5600 phy_data
& E1000_WUS_MAG
? "Magic Packet" :
5601 phy_data
& E1000_WUS_LNKC
?
5602 "Link Status Change" : "other");
5604 e1e_wphy(&adapter
->hw
, BM_WUS
, ~0);
5606 u32 wus
= er32(WUS
);
5608 e_info("MAC Wakeup cause - %s\n",
5609 wus
& E1000_WUS_EX
? "Unicast Packet" :
5610 wus
& E1000_WUS_MC
? "Multicast Packet" :
5611 wus
& E1000_WUS_BC
? "Broadcast Packet" :
5612 wus
& E1000_WUS_MAG
? "Magic Packet" :
5613 wus
& E1000_WUS_LNKC
? "Link Status Change" :
5619 e1000e_reset(adapter
);
5621 e1000_init_manageability_pt(adapter
);
5623 if (netif_running(netdev
))
5626 netif_device_attach(netdev
);
5629 * If the controller has AMT, do not set DRV_LOAD until the interface
5630 * is up. For all other cases, let the f/w know that the h/w is now
5631 * under the control of the driver.
5633 if (!(adapter
->flags
& FLAG_HAS_AMT
))
5634 e1000e_get_hw_control(adapter
);
5639 #ifdef CONFIG_PM_SLEEP
5640 static int e1000_suspend(struct device
*dev
)
5642 struct pci_dev
*pdev
= to_pci_dev(dev
);
5646 retval
= __e1000_shutdown(pdev
, &wake
, false);
5648 e1000_complete_shutdown(pdev
, true, wake
);
5653 static int e1000_resume(struct device
*dev
)
5655 struct pci_dev
*pdev
= to_pci_dev(dev
);
5656 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5657 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5659 if (e1000e_pm_ready(adapter
))
5660 adapter
->idle_check
= true;
5662 return __e1000_resume(pdev
);
5664 #endif /* CONFIG_PM_SLEEP */
5666 #ifdef CONFIG_PM_RUNTIME
5667 static int e1000_runtime_suspend(struct device
*dev
)
5669 struct pci_dev
*pdev
= to_pci_dev(dev
);
5670 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5671 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5673 if (e1000e_pm_ready(adapter
)) {
5676 __e1000_shutdown(pdev
, &wake
, true);
5682 static int e1000_idle(struct device
*dev
)
5684 struct pci_dev
*pdev
= to_pci_dev(dev
);
5685 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5686 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5688 if (!e1000e_pm_ready(adapter
))
5691 if (adapter
->idle_check
) {
5692 adapter
->idle_check
= false;
5693 if (!e1000e_has_link(adapter
))
5694 pm_schedule_suspend(dev
, MSEC_PER_SEC
);
5700 static int e1000_runtime_resume(struct device
*dev
)
5702 struct pci_dev
*pdev
= to_pci_dev(dev
);
5703 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5704 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5706 if (!e1000e_pm_ready(adapter
))
5709 adapter
->idle_check
= !dev
->power
.runtime_auto
;
5710 return __e1000_resume(pdev
);
5712 #endif /* CONFIG_PM_RUNTIME */
5713 #endif /* CONFIG_PM */
5715 static void e1000_shutdown(struct pci_dev
*pdev
)
5719 __e1000_shutdown(pdev
, &wake
, false);
5721 if (system_state
== SYSTEM_POWER_OFF
)
5722 e1000_complete_shutdown(pdev
, false, wake
);
5725 #ifdef CONFIG_NET_POLL_CONTROLLER
5727 static irqreturn_t
e1000_intr_msix(int irq
, void *data
)
5729 struct net_device
*netdev
= data
;
5730 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5732 if (adapter
->msix_entries
) {
5733 int vector
, msix_irq
;
5736 msix_irq
= adapter
->msix_entries
[vector
].vector
;
5737 disable_irq(msix_irq
);
5738 e1000_intr_msix_rx(msix_irq
, netdev
);
5739 enable_irq(msix_irq
);
5742 msix_irq
= adapter
->msix_entries
[vector
].vector
;
5743 disable_irq(msix_irq
);
5744 e1000_intr_msix_tx(msix_irq
, netdev
);
5745 enable_irq(msix_irq
);
5748 msix_irq
= adapter
->msix_entries
[vector
].vector
;
5749 disable_irq(msix_irq
);
5750 e1000_msix_other(msix_irq
, netdev
);
5751 enable_irq(msix_irq
);
5758 * Polling 'interrupt' - used by things like netconsole to send skbs
5759 * without having to re-enable interrupts. It's not called while
5760 * the interrupt routine is executing.
5762 static void e1000_netpoll(struct net_device
*netdev
)
5764 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5766 switch (adapter
->int_mode
) {
5767 case E1000E_INT_MODE_MSIX
:
5768 e1000_intr_msix(adapter
->pdev
->irq
, netdev
);
5770 case E1000E_INT_MODE_MSI
:
5771 disable_irq(adapter
->pdev
->irq
);
5772 e1000_intr_msi(adapter
->pdev
->irq
, netdev
);
5773 enable_irq(adapter
->pdev
->irq
);
5775 default: /* E1000E_INT_MODE_LEGACY */
5776 disable_irq(adapter
->pdev
->irq
);
5777 e1000_intr(adapter
->pdev
->irq
, netdev
);
5778 enable_irq(adapter
->pdev
->irq
);
5785 * e1000_io_error_detected - called when PCI error is detected
5786 * @pdev: Pointer to PCI device
5787 * @state: The current pci connection state
5789 * This function is called after a PCI bus error affecting
5790 * this device has been detected.
5792 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
5793 pci_channel_state_t state
)
5795 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5796 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5798 netif_device_detach(netdev
);
5800 if (state
== pci_channel_io_perm_failure
)
5801 return PCI_ERS_RESULT_DISCONNECT
;
5803 if (netif_running(netdev
))
5804 e1000e_down(adapter
);
5805 pci_disable_device(pdev
);
5807 /* Request a slot slot reset. */
5808 return PCI_ERS_RESULT_NEED_RESET
;
5812 * e1000_io_slot_reset - called after the pci bus has been reset.
5813 * @pdev: Pointer to PCI device
5815 * Restart the card from scratch, as if from a cold-boot. Implementation
5816 * resembles the first-half of the e1000_resume routine.
5818 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
5820 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5821 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5822 struct e1000_hw
*hw
= &adapter
->hw
;
5823 u16 aspm_disable_flag
= 0;
5825 pci_ers_result_t result
;
5827 if (adapter
->flags2
& FLAG2_DISABLE_ASPM_L0S
)
5828 aspm_disable_flag
= PCIE_LINK_STATE_L0S
;
5829 if (adapter
->flags2
& FLAG2_DISABLE_ASPM_L1
)
5830 aspm_disable_flag
|= PCIE_LINK_STATE_L1
;
5831 if (aspm_disable_flag
)
5832 e1000e_disable_aspm(pdev
, aspm_disable_flag
);
5834 err
= pci_enable_device_mem(pdev
);
5837 "Cannot re-enable PCI device after reset.\n");
5838 result
= PCI_ERS_RESULT_DISCONNECT
;
5840 pci_set_master(pdev
);
5841 pdev
->state_saved
= true;
5842 pci_restore_state(pdev
);
5844 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5845 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5847 e1000e_reset(adapter
);
5849 result
= PCI_ERS_RESULT_RECOVERED
;
5852 pci_cleanup_aer_uncorrect_error_status(pdev
);
5858 * e1000_io_resume - called when traffic can start flowing again.
5859 * @pdev: Pointer to PCI device
5861 * This callback is called when the error recovery driver tells us that
5862 * its OK to resume normal operation. Implementation resembles the
5863 * second-half of the e1000_resume routine.
5865 static void e1000_io_resume(struct pci_dev
*pdev
)
5867 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5868 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5870 e1000_init_manageability_pt(adapter
);
5872 if (netif_running(netdev
)) {
5873 if (e1000e_up(adapter
)) {
5875 "can't bring device back up after reset\n");
5880 netif_device_attach(netdev
);
5883 * If the controller has AMT, do not set DRV_LOAD until the interface
5884 * is up. For all other cases, let the f/w know that the h/w is now
5885 * under the control of the driver.
5887 if (!(adapter
->flags
& FLAG_HAS_AMT
))
5888 e1000e_get_hw_control(adapter
);
5892 static void e1000_print_device_info(struct e1000_adapter
*adapter
)
5894 struct e1000_hw
*hw
= &adapter
->hw
;
5895 struct net_device
*netdev
= adapter
->netdev
;
5897 u8 pba_str
[E1000_PBANUM_LENGTH
];
5899 /* print bus type/speed/width info */
5900 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
5902 ((hw
->bus
.width
== e1000_bus_width_pcie_x4
) ? "Width x4" :
5906 e_info("Intel(R) PRO/%s Network Connection\n",
5907 (hw
->phy
.type
== e1000_phy_ife
) ? "10/100" : "1000");
5908 ret_val
= e1000_read_pba_string_generic(hw
, pba_str
,
5909 E1000_PBANUM_LENGTH
);
5911 strncpy((char *)pba_str
, "Unknown", sizeof(pba_str
) - 1);
5912 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5913 hw
->mac
.type
, hw
->phy
.type
, pba_str
);
5916 static void e1000_eeprom_checks(struct e1000_adapter
*adapter
)
5918 struct e1000_hw
*hw
= &adapter
->hw
;
5922 if (hw
->mac
.type
!= e1000_82573
)
5925 ret_val
= e1000_read_nvm(hw
, NVM_INIT_CONTROL2_REG
, 1, &buf
);
5926 if (!ret_val
&& (!(le16_to_cpu(buf
) & (1 << 0)))) {
5927 /* Deep Smart Power Down (DSPD) */
5928 dev_warn(&adapter
->pdev
->dev
,
5929 "Warning: detected DSPD enabled in EEPROM\n");
5933 static int e1000_set_features(struct net_device
*netdev
,
5934 netdev_features_t features
)
5936 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5937 netdev_features_t changed
= features
^ netdev
->features
;
5939 if (changed
& (NETIF_F_TSO
| NETIF_F_TSO6
))
5940 adapter
->flags
|= FLAG_TSO_FORCE
;
5942 if (!(changed
& (NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_TX
|
5946 if (netif_running(netdev
))
5947 e1000e_reinit_locked(adapter
);
5949 e1000e_reset(adapter
);
5954 static const struct net_device_ops e1000e_netdev_ops
= {
5955 .ndo_open
= e1000_open
,
5956 .ndo_stop
= e1000_close
,
5957 .ndo_start_xmit
= e1000_xmit_frame
,
5958 .ndo_get_stats64
= e1000e_get_stats64
,
5959 .ndo_set_rx_mode
= e1000e_set_rx_mode
,
5960 .ndo_set_mac_address
= e1000_set_mac
,
5961 .ndo_change_mtu
= e1000_change_mtu
,
5962 .ndo_do_ioctl
= e1000_ioctl
,
5963 .ndo_tx_timeout
= e1000_tx_timeout
,
5964 .ndo_validate_addr
= eth_validate_addr
,
5966 .ndo_vlan_rx_add_vid
= e1000_vlan_rx_add_vid
,
5967 .ndo_vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
,
5968 #ifdef CONFIG_NET_POLL_CONTROLLER
5969 .ndo_poll_controller
= e1000_netpoll
,
5971 .ndo_set_features
= e1000_set_features
,
5975 * e1000_probe - Device Initialization Routine
5976 * @pdev: PCI device information struct
5977 * @ent: entry in e1000_pci_tbl
5979 * Returns 0 on success, negative on failure
5981 * e1000_probe initializes an adapter identified by a pci_dev structure.
5982 * The OS initialization, configuring of the adapter private structure,
5983 * and a hardware reset occur.
5985 static int __devinit
e1000_probe(struct pci_dev
*pdev
,
5986 const struct pci_device_id
*ent
)
5988 struct net_device
*netdev
;
5989 struct e1000_adapter
*adapter
;
5990 struct e1000_hw
*hw
;
5991 const struct e1000_info
*ei
= e1000_info_tbl
[ent
->driver_data
];
5992 resource_size_t mmio_start
, mmio_len
;
5993 resource_size_t flash_start
, flash_len
;
5995 static int cards_found
;
5996 u16 aspm_disable_flag
= 0;
5997 int i
, err
, pci_using_dac
;
5998 u16 eeprom_data
= 0;
5999 u16 eeprom_apme_mask
= E1000_EEPROM_APME
;
6001 if (ei
->flags2
& FLAG2_DISABLE_ASPM_L0S
)
6002 aspm_disable_flag
= PCIE_LINK_STATE_L0S
;
6003 if (ei
->flags2
& FLAG2_DISABLE_ASPM_L1
)
6004 aspm_disable_flag
|= PCIE_LINK_STATE_L1
;
6005 if (aspm_disable_flag
)
6006 e1000e_disable_aspm(pdev
, aspm_disable_flag
);
6008 err
= pci_enable_device_mem(pdev
);
6013 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64));
6015 err
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64));
6019 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
6021 err
= dma_set_coherent_mask(&pdev
->dev
,
6024 dev_err(&pdev
->dev
, "No usable DMA configuration, aborting\n");
6030 err
= pci_request_selected_regions_exclusive(pdev
,
6031 pci_select_bars(pdev
, IORESOURCE_MEM
),
6032 e1000e_driver_name
);
6036 /* AER (Advanced Error Reporting) hooks */
6037 pci_enable_pcie_error_reporting(pdev
);
6039 pci_set_master(pdev
);
6040 /* PCI config space info */
6041 err
= pci_save_state(pdev
);
6043 goto err_alloc_etherdev
;
6046 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
6048 goto err_alloc_etherdev
;
6050 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
6052 netdev
->irq
= pdev
->irq
;
6054 pci_set_drvdata(pdev
, netdev
);
6055 adapter
= netdev_priv(netdev
);
6057 adapter
->netdev
= netdev
;
6058 adapter
->pdev
= pdev
;
6060 adapter
->pba
= ei
->pba
;
6061 adapter
->flags
= ei
->flags
;
6062 adapter
->flags2
= ei
->flags2
;
6063 adapter
->hw
.adapter
= adapter
;
6064 adapter
->hw
.mac
.type
= ei
->mac
;
6065 adapter
->max_hw_frame_size
= ei
->max_hw_frame_size
;
6066 adapter
->msg_enable
= (1 << NETIF_MSG_DRV
| NETIF_MSG_PROBE
) - 1;
6068 mmio_start
= pci_resource_start(pdev
, 0);
6069 mmio_len
= pci_resource_len(pdev
, 0);
6072 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
6073 if (!adapter
->hw
.hw_addr
)
6076 if ((adapter
->flags
& FLAG_HAS_FLASH
) &&
6077 (pci_resource_flags(pdev
, 1) & IORESOURCE_MEM
)) {
6078 flash_start
= pci_resource_start(pdev
, 1);
6079 flash_len
= pci_resource_len(pdev
, 1);
6080 adapter
->hw
.flash_address
= ioremap(flash_start
, flash_len
);
6081 if (!adapter
->hw
.flash_address
)
6085 /* construct the net_device struct */
6086 netdev
->netdev_ops
= &e1000e_netdev_ops
;
6087 e1000e_set_ethtool_ops(netdev
);
6088 netdev
->watchdog_timeo
= 5 * HZ
;
6089 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
6090 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
6092 netdev
->mem_start
= mmio_start
;
6093 netdev
->mem_end
= mmio_start
+ mmio_len
;
6095 adapter
->bd_number
= cards_found
++;
6097 e1000e_check_options(adapter
);
6099 /* setup adapter struct */
6100 err
= e1000_sw_init(adapter
);
6104 memcpy(&hw
->mac
.ops
, ei
->mac_ops
, sizeof(hw
->mac
.ops
));
6105 memcpy(&hw
->nvm
.ops
, ei
->nvm_ops
, sizeof(hw
->nvm
.ops
));
6106 memcpy(&hw
->phy
.ops
, ei
->phy_ops
, sizeof(hw
->phy
.ops
));
6108 err
= ei
->get_variants(adapter
);
6112 if ((adapter
->flags
& FLAG_IS_ICH
) &&
6113 (adapter
->flags
& FLAG_READ_ONLY_NVM
))
6114 e1000e_write_protect_nvm_ich8lan(&adapter
->hw
);
6116 hw
->mac
.ops
.get_bus_info(&adapter
->hw
);
6118 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
6120 /* Copper options */
6121 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
) {
6122 adapter
->hw
.phy
.mdix
= AUTO_ALL_MODES
;
6123 adapter
->hw
.phy
.disable_polarity_correction
= 0;
6124 adapter
->hw
.phy
.ms_type
= e1000_ms_hw_default
;
6127 if (e1000_check_reset_block(&adapter
->hw
))
6128 e_info("PHY reset is blocked due to SOL/IDER session.\n");
6130 /* Set initial default active device features */
6131 netdev
->features
= (NETIF_F_SG
|
6132 NETIF_F_HW_VLAN_RX
|
6133 NETIF_F_HW_VLAN_TX
|
6139 /* Set user-changeable features (subset of all device features) */
6140 netdev
->hw_features
= netdev
->features
;
6142 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
)
6143 netdev
->features
|= NETIF_F_HW_VLAN_FILTER
;
6145 netdev
->vlan_features
|= (NETIF_F_SG
|
6150 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
6152 if (pci_using_dac
) {
6153 netdev
->features
|= NETIF_F_HIGHDMA
;
6154 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
6157 if (e1000e_enable_mng_pass_thru(&adapter
->hw
))
6158 adapter
->flags
|= FLAG_MNG_PT_ENABLED
;
6161 * before reading the NVM, reset the controller to
6162 * put the device in a known good starting state
6164 adapter
->hw
.mac
.ops
.reset_hw(&adapter
->hw
);
6167 * systems with ASPM and others may see the checksum fail on the first
6168 * attempt. Let's give it a few tries
6171 if (e1000_validate_nvm_checksum(&adapter
->hw
) >= 0)
6174 e_err("The NVM Checksum Is Not Valid\n");
6180 e1000_eeprom_checks(adapter
);
6182 /* copy the MAC address */
6183 if (e1000e_read_mac_addr(&adapter
->hw
))
6184 e_err("NVM Read Error while reading MAC address\n");
6186 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
6187 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
6189 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
6190 e_err("Invalid MAC Address: %pM\n", netdev
->perm_addr
);
6195 init_timer(&adapter
->watchdog_timer
);
6196 adapter
->watchdog_timer
.function
= e1000_watchdog
;
6197 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
6199 init_timer(&adapter
->phy_info_timer
);
6200 adapter
->phy_info_timer
.function
= e1000_update_phy_info
;
6201 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
6203 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
6204 INIT_WORK(&adapter
->watchdog_task
, e1000_watchdog_task
);
6205 INIT_WORK(&adapter
->downshift_task
, e1000e_downshift_workaround
);
6206 INIT_WORK(&adapter
->update_phy_task
, e1000e_update_phy_task
);
6207 INIT_WORK(&adapter
->print_hang_task
, e1000_print_hw_hang
);
6209 /* Initialize link parameters. User can change them with ethtool */
6210 adapter
->hw
.mac
.autoneg
= 1;
6211 adapter
->fc_autoneg
= true;
6212 adapter
->hw
.fc
.requested_mode
= e1000_fc_default
;
6213 adapter
->hw
.fc
.current_mode
= e1000_fc_default
;
6214 adapter
->hw
.phy
.autoneg_advertised
= 0x2f;
6216 /* ring size defaults */
6217 adapter
->rx_ring
->count
= 256;
6218 adapter
->tx_ring
->count
= 256;
6221 * Initial Wake on LAN setting - If APM wake is enabled in
6222 * the EEPROM, enable the ACPI Magic Packet filter
6224 if (adapter
->flags
& FLAG_APME_IN_WUC
) {
6225 /* APME bit in EEPROM is mapped to WUC.APME */
6226 eeprom_data
= er32(WUC
);
6227 eeprom_apme_mask
= E1000_WUC_APME
;
6228 if ((hw
->mac
.type
> e1000_ich10lan
) &&
6229 (eeprom_data
& E1000_WUC_PHY_WAKE
))
6230 adapter
->flags2
|= FLAG2_HAS_PHY_WAKEUP
;
6231 } else if (adapter
->flags
& FLAG_APME_IN_CTRL3
) {
6232 if (adapter
->flags
& FLAG_APME_CHECK_PORT_B
&&
6233 (adapter
->hw
.bus
.func
== 1))
6234 e1000_read_nvm(&adapter
->hw
,
6235 NVM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
6237 e1000_read_nvm(&adapter
->hw
,
6238 NVM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
6241 /* fetch WoL from EEPROM */
6242 if (eeprom_data
& eeprom_apme_mask
)
6243 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
6246 * now that we have the eeprom settings, apply the special cases
6247 * where the eeprom may be wrong or the board simply won't support
6248 * wake on lan on a particular port
6250 if (!(adapter
->flags
& FLAG_HAS_WOL
))
6251 adapter
->eeprom_wol
= 0;
6253 /* initialize the wol settings based on the eeprom settings */
6254 adapter
->wol
= adapter
->eeprom_wol
;
6255 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
6257 /* save off EEPROM version number */
6258 e1000_read_nvm(&adapter
->hw
, 5, 1, &adapter
->eeprom_vers
);
6260 /* reset the hardware with the new settings */
6261 e1000e_reset(adapter
);
6264 * If the controller has AMT, do not set DRV_LOAD until the interface
6265 * is up. For all other cases, let the f/w know that the h/w is now
6266 * under the control of the driver.
6268 if (!(adapter
->flags
& FLAG_HAS_AMT
))
6269 e1000e_get_hw_control(adapter
);
6271 strncpy(netdev
->name
, "eth%d", sizeof(netdev
->name
) - 1);
6272 err
= register_netdev(netdev
);
6276 /* carrier off reporting is important to ethtool even BEFORE open */
6277 netif_carrier_off(netdev
);
6279 e1000_print_device_info(adapter
);
6281 if (pci_dev_run_wake(pdev
))
6282 pm_runtime_put_noidle(&pdev
->dev
);
6287 if (!(adapter
->flags
& FLAG_HAS_AMT
))
6288 e1000e_release_hw_control(adapter
);
6290 if (!e1000_check_reset_block(&adapter
->hw
))
6291 e1000_phy_hw_reset(&adapter
->hw
);
6293 kfree(adapter
->tx_ring
);
6294 kfree(adapter
->rx_ring
);
6296 if (adapter
->hw
.flash_address
)
6297 iounmap(adapter
->hw
.flash_address
);
6298 e1000e_reset_interrupt_capability(adapter
);
6300 iounmap(adapter
->hw
.hw_addr
);
6302 free_netdev(netdev
);
6304 pci_release_selected_regions(pdev
,
6305 pci_select_bars(pdev
, IORESOURCE_MEM
));
6308 pci_disable_device(pdev
);
6313 * e1000_remove - Device Removal Routine
6314 * @pdev: PCI device information struct
6316 * e1000_remove is called by the PCI subsystem to alert the driver
6317 * that it should release a PCI device. The could be caused by a
6318 * Hot-Plug event, or because the driver is going to be removed from
6321 static void __devexit
e1000_remove(struct pci_dev
*pdev
)
6323 struct net_device
*netdev
= pci_get_drvdata(pdev
);
6324 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
6325 bool down
= test_bit(__E1000_DOWN
, &adapter
->state
);
6328 * The timers may be rescheduled, so explicitly disable them
6329 * from being rescheduled.
6332 set_bit(__E1000_DOWN
, &adapter
->state
);
6333 del_timer_sync(&adapter
->watchdog_timer
);
6334 del_timer_sync(&adapter
->phy_info_timer
);
6336 cancel_work_sync(&adapter
->reset_task
);
6337 cancel_work_sync(&adapter
->watchdog_task
);
6338 cancel_work_sync(&adapter
->downshift_task
);
6339 cancel_work_sync(&adapter
->update_phy_task
);
6340 cancel_work_sync(&adapter
->print_hang_task
);
6342 if (!(netdev
->flags
& IFF_UP
))
6343 e1000_power_down_phy(adapter
);
6345 /* Don't lie to e1000_close() down the road. */
6347 clear_bit(__E1000_DOWN
, &adapter
->state
);
6348 unregister_netdev(netdev
);
6350 if (pci_dev_run_wake(pdev
))
6351 pm_runtime_get_noresume(&pdev
->dev
);
6354 * Release control of h/w to f/w. If f/w is AMT enabled, this
6355 * would have already happened in close and is redundant.
6357 e1000e_release_hw_control(adapter
);
6359 e1000e_reset_interrupt_capability(adapter
);
6360 kfree(adapter
->tx_ring
);
6361 kfree(adapter
->rx_ring
);
6363 iounmap(adapter
->hw
.hw_addr
);
6364 if (adapter
->hw
.flash_address
)
6365 iounmap(adapter
->hw
.flash_address
);
6366 pci_release_selected_regions(pdev
,
6367 pci_select_bars(pdev
, IORESOURCE_MEM
));
6369 free_netdev(netdev
);
6372 pci_disable_pcie_error_reporting(pdev
);
6374 pci_disable_device(pdev
);
6377 /* PCI Error Recovery (ERS) */
6378 static struct pci_error_handlers e1000_err_handler
= {
6379 .error_detected
= e1000_io_error_detected
,
6380 .slot_reset
= e1000_io_slot_reset
,
6381 .resume
= e1000_io_resume
,
6384 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl
) = {
6385 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_COPPER
), board_82571
},
6386 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_FIBER
), board_82571
},
6387 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER
), board_82571
},
6388 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER_LP
), board_82571
},
6389 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_FIBER
), board_82571
},
6390 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES
), board_82571
},
6391 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_DUAL
), board_82571
},
6392 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_QUAD
), board_82571
},
6393 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571PT_QUAD_COPPER
), board_82571
},
6395 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI
), board_82572
},
6396 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_COPPER
), board_82572
},
6397 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_FIBER
), board_82572
},
6398 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_SERDES
), board_82572
},
6400 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E
), board_82573
},
6401 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E_IAMT
), board_82573
},
6402 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573L
), board_82573
},
6404 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82574L
), board_82574
},
6405 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82574LA
), board_82574
},
6406 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82583V
), board_82583
},
6408 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_DPT
),
6409 board_80003es2lan
},
6410 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_SPT
),
6411 board_80003es2lan
},
6412 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_DPT
),
6413 board_80003es2lan
},
6414 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_SPT
),
6415 board_80003es2lan
},
6417 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE
), board_ich8lan
},
6418 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_G
), board_ich8lan
},
6419 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_GT
), board_ich8lan
},
6420 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_AMT
), board_ich8lan
},
6421 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_C
), board_ich8lan
},
6422 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M
), board_ich8lan
},
6423 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M_AMT
), board_ich8lan
},
6424 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_82567V_3
), board_ich8lan
},
6426 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE
), board_ich9lan
},
6427 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_G
), board_ich9lan
},
6428 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_GT
), board_ich9lan
},
6429 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_AMT
), board_ich9lan
},
6430 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_C
), board_ich9lan
},
6431 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_BM
), board_ich9lan
},
6432 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M
), board_ich9lan
},
6433 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M_AMT
), board_ich9lan
},
6434 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M_V
), board_ich9lan
},
6436 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_LM
), board_ich9lan
},
6437 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_LF
), board_ich9lan
},
6438 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_V
), board_ich9lan
},
6440 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_LM
), board_ich10lan
},
6441 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_LF
), board_ich10lan
},
6442 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_V
), board_ich10lan
},
6444 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_M_HV_LM
), board_pchlan
},
6445 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_M_HV_LC
), board_pchlan
},
6446 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_D_HV_DM
), board_pchlan
},
6447 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_D_HV_DC
), board_pchlan
},
6449 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH2_LV_LM
), board_pch2lan
},
6450 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH2_LV_V
), board_pch2lan
},
6452 { } /* terminate list */
6454 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
6457 static const struct dev_pm_ops e1000_pm_ops
= {
6458 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend
, e1000_resume
)
6459 SET_RUNTIME_PM_OPS(e1000_runtime_suspend
,
6460 e1000_runtime_resume
, e1000_idle
)
6464 /* PCI Device API Driver */
6465 static struct pci_driver e1000_driver
= {
6466 .name
= e1000e_driver_name
,
6467 .id_table
= e1000_pci_tbl
,
6468 .probe
= e1000_probe
,
6469 .remove
= __devexit_p(e1000_remove
),
6471 .driver
.pm
= &e1000_pm_ops
,
6473 .shutdown
= e1000_shutdown
,
6474 .err_handler
= &e1000_err_handler
6478 * e1000_init_module - Driver Registration Routine
6480 * e1000_init_module is the first routine called when the driver is
6481 * loaded. All it does is register with the PCI subsystem.
6483 static int __init
e1000_init_module(void)
6486 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6487 e1000e_driver_version
);
6488 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
6489 ret
= pci_register_driver(&e1000_driver
);
6493 module_init(e1000_init_module
);
6496 * e1000_exit_module - Driver Exit Cleanup Routine
6498 * e1000_exit_module is called just before the driver is removed
6501 static void __exit
e1000_exit_module(void)
6503 pci_unregister_driver(&e1000_driver
);
6505 module_exit(e1000_exit_module
);
6508 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6509 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6510 MODULE_LICENSE("GPL");
6511 MODULE_VERSION(DRV_VERSION
);