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/tcp.h>
40 #include <linux/ipv6.h>
41 #include <linux/slab.h>
42 #include <net/checksum.h>
43 #include <net/ip6_checksum.h>
44 #include <linux/mii.h>
45 #include <linux/ethtool.h>
46 #include <linux/if_vlan.h>
47 #include <linux/cpu.h>
48 #include <linux/smp.h>
49 #include <linux/pm_qos_params.h>
50 #include <linux/pm_runtime.h>
51 #include <linux/aer.h>
52 #include <linux/prefetch.h>
56 #define DRV_EXTRAVERSION "-k2"
58 #define DRV_VERSION "1.3.10" DRV_EXTRAVERSION
59 char e1000e_driver_name
[] = "e1000e";
60 const char e1000e_driver_version
[] = DRV_VERSION
;
62 static void e1000e_disable_aspm(struct pci_dev
*pdev
, u16 state
);
64 static const struct e1000_info
*e1000_info_tbl
[] = {
65 [board_82571
] = &e1000_82571_info
,
66 [board_82572
] = &e1000_82572_info
,
67 [board_82573
] = &e1000_82573_info
,
68 [board_82574
] = &e1000_82574_info
,
69 [board_82583
] = &e1000_82583_info
,
70 [board_80003es2lan
] = &e1000_es2_info
,
71 [board_ich8lan
] = &e1000_ich8_info
,
72 [board_ich9lan
] = &e1000_ich9_info
,
73 [board_ich10lan
] = &e1000_ich10_info
,
74 [board_pchlan
] = &e1000_pch_info
,
75 [board_pch2lan
] = &e1000_pch2_info
,
78 struct e1000_reg_info
{
83 #define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
84 #define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
85 #define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
86 #define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
87 #define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
89 #define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
90 #define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
91 #define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
92 #define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
93 #define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
95 static const struct e1000_reg_info e1000_reg_info_tbl
[] = {
97 /* General Registers */
99 {E1000_STATUS
, "STATUS"},
100 {E1000_CTRL_EXT
, "CTRL_EXT"},
102 /* Interrupt Registers */
106 {E1000_RCTL
, "RCTL"},
107 {E1000_RDLEN
, "RDLEN"},
110 {E1000_RDTR
, "RDTR"},
111 {E1000_RXDCTL(0), "RXDCTL"},
113 {E1000_RDBAL
, "RDBAL"},
114 {E1000_RDBAH
, "RDBAH"},
115 {E1000_RDFH
, "RDFH"},
116 {E1000_RDFT
, "RDFT"},
117 {E1000_RDFHS
, "RDFHS"},
118 {E1000_RDFTS
, "RDFTS"},
119 {E1000_RDFPC
, "RDFPC"},
122 {E1000_TCTL
, "TCTL"},
123 {E1000_TDBAL
, "TDBAL"},
124 {E1000_TDBAH
, "TDBAH"},
125 {E1000_TDLEN
, "TDLEN"},
128 {E1000_TIDV
, "TIDV"},
129 {E1000_TXDCTL(0), "TXDCTL"},
130 {E1000_TADV
, "TADV"},
131 {E1000_TARC(0), "TARC"},
132 {E1000_TDFH
, "TDFH"},
133 {E1000_TDFT
, "TDFT"},
134 {E1000_TDFHS
, "TDFHS"},
135 {E1000_TDFTS
, "TDFTS"},
136 {E1000_TDFPC
, "TDFPC"},
138 /* List Terminator */
143 * e1000_regdump - register printout routine
145 static void e1000_regdump(struct e1000_hw
*hw
, struct e1000_reg_info
*reginfo
)
151 switch (reginfo
->ofs
) {
152 case E1000_RXDCTL(0):
153 for (n
= 0; n
< 2; n
++)
154 regs
[n
] = __er32(hw
, E1000_RXDCTL(n
));
156 case E1000_TXDCTL(0):
157 for (n
= 0; n
< 2; n
++)
158 regs
[n
] = __er32(hw
, E1000_TXDCTL(n
));
161 for (n
= 0; n
< 2; n
++)
162 regs
[n
] = __er32(hw
, E1000_TARC(n
));
165 printk(KERN_INFO
"%-15s %08x\n",
166 reginfo
->name
, __er32(hw
, reginfo
->ofs
));
170 snprintf(rname
, 16, "%s%s", reginfo
->name
, "[0-1]");
171 printk(KERN_INFO
"%-15s ", rname
);
172 for (n
= 0; n
< 2; n
++)
173 printk(KERN_CONT
"%08x ", regs
[n
]);
174 printk(KERN_CONT
"\n");
178 * e1000e_dump - Print registers, Tx-ring and Rx-ring
180 static void e1000e_dump(struct e1000_adapter
*adapter
)
182 struct net_device
*netdev
= adapter
->netdev
;
183 struct e1000_hw
*hw
= &adapter
->hw
;
184 struct e1000_reg_info
*reginfo
;
185 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
186 struct e1000_tx_desc
*tx_desc
;
191 struct e1000_buffer
*buffer_info
;
192 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
193 union e1000_rx_desc_packet_split
*rx_desc_ps
;
194 struct e1000_rx_desc
*rx_desc
;
204 if (!netif_msg_hw(adapter
))
207 /* Print netdevice Info */
209 dev_info(&adapter
->pdev
->dev
, "Net device Info\n");
210 printk(KERN_INFO
"Device Name state "
211 "trans_start last_rx\n");
212 printk(KERN_INFO
"%-15s %016lX %016lX %016lX\n",
213 netdev
->name
, netdev
->state
, netdev
->trans_start
,
217 /* Print Registers */
218 dev_info(&adapter
->pdev
->dev
, "Register Dump\n");
219 printk(KERN_INFO
" Register Name Value\n");
220 for (reginfo
= (struct e1000_reg_info
*)e1000_reg_info_tbl
;
221 reginfo
->name
; reginfo
++) {
222 e1000_regdump(hw
, reginfo
);
225 /* Print Tx Ring Summary */
226 if (!netdev
|| !netif_running(netdev
))
229 dev_info(&adapter
->pdev
->dev
, "Tx Ring Summary\n");
230 printk(KERN_INFO
"Queue [NTU] [NTC] [bi(ntc)->dma ]"
231 " leng ntw timestamp\n");
232 buffer_info
= &tx_ring
->buffer_info
[tx_ring
->next_to_clean
];
233 printk(KERN_INFO
" %5d %5X %5X %016llX %04X %3X %016llX\n",
234 0, tx_ring
->next_to_use
, tx_ring
->next_to_clean
,
235 (unsigned long long)buffer_info
->dma
,
237 buffer_info
->next_to_watch
,
238 (unsigned long long)buffer_info
->time_stamp
);
241 if (!netif_msg_tx_done(adapter
))
242 goto rx_ring_summary
;
244 dev_info(&adapter
->pdev
->dev
, "Tx Ring Dump\n");
246 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
248 * Legacy Transmit Descriptor
249 * +--------------------------------------------------------------+
250 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
251 * +--------------------------------------------------------------+
252 * 8 | Special | CSS | Status | CMD | CSO | Length |
253 * +--------------------------------------------------------------+
254 * 63 48 47 36 35 32 31 24 23 16 15 0
256 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
257 * 63 48 47 40 39 32 31 16 15 8 7 0
258 * +----------------------------------------------------------------+
259 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
260 * +----------------------------------------------------------------+
261 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
262 * +----------------------------------------------------------------+
263 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
265 * Extended Data Descriptor (DTYP=0x1)
266 * +----------------------------------------------------------------+
267 * 0 | Buffer Address [63:0] |
268 * +----------------------------------------------------------------+
269 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
270 * +----------------------------------------------------------------+
271 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
273 printk(KERN_INFO
"Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]"
274 " [bi->dma ] leng ntw timestamp bi->skb "
275 "<-- Legacy format\n");
276 printk(KERN_INFO
"Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]"
277 " [bi->dma ] leng ntw timestamp bi->skb "
278 "<-- Ext Context format\n");
279 printk(KERN_INFO
"Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]"
280 " [bi->dma ] leng ntw timestamp bi->skb "
281 "<-- Ext Data format\n");
282 for (i
= 0; tx_ring
->desc
&& (i
< tx_ring
->count
); i
++) {
283 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
284 buffer_info
= &tx_ring
->buffer_info
[i
];
285 u0
= (struct my_u0
*)tx_desc
;
286 printk(KERN_INFO
"T%c[0x%03X] %016llX %016llX %016llX "
287 "%04X %3X %016llX %p",
288 (!(le64_to_cpu(u0
->b
) & (1 << 29)) ? 'l' :
289 ((le64_to_cpu(u0
->b
) & (1 << 20)) ? 'd' : 'c')), i
,
290 (unsigned long long)le64_to_cpu(u0
->a
),
291 (unsigned long long)le64_to_cpu(u0
->b
),
292 (unsigned long long)buffer_info
->dma
,
293 buffer_info
->length
, buffer_info
->next_to_watch
,
294 (unsigned long long)buffer_info
->time_stamp
,
296 if (i
== tx_ring
->next_to_use
&& i
== tx_ring
->next_to_clean
)
297 printk(KERN_CONT
" NTC/U\n");
298 else if (i
== tx_ring
->next_to_use
)
299 printk(KERN_CONT
" NTU\n");
300 else if (i
== tx_ring
->next_to_clean
)
301 printk(KERN_CONT
" NTC\n");
303 printk(KERN_CONT
"\n");
305 if (netif_msg_pktdata(adapter
) && buffer_info
->dma
!= 0)
306 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_ADDRESS
,
307 16, 1, phys_to_virt(buffer_info
->dma
),
308 buffer_info
->length
, true);
311 /* Print Rx Ring Summary */
313 dev_info(&adapter
->pdev
->dev
, "Rx Ring Summary\n");
314 printk(KERN_INFO
"Queue [NTU] [NTC]\n");
315 printk(KERN_INFO
" %5d %5X %5X\n", 0,
316 rx_ring
->next_to_use
, rx_ring
->next_to_clean
);
319 if (!netif_msg_rx_status(adapter
))
322 dev_info(&adapter
->pdev
->dev
, "Rx Ring Dump\n");
323 switch (adapter
->rx_ps_pages
) {
327 /* [Extended] Packet Split Receive Descriptor Format
329 * +-----------------------------------------------------+
330 * 0 | Buffer Address 0 [63:0] |
331 * +-----------------------------------------------------+
332 * 8 | Buffer Address 1 [63:0] |
333 * +-----------------------------------------------------+
334 * 16 | Buffer Address 2 [63:0] |
335 * +-----------------------------------------------------+
336 * 24 | Buffer Address 3 [63:0] |
337 * +-----------------------------------------------------+
339 printk(KERN_INFO
"R [desc] [buffer 0 63:0 ] "
341 "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] "
342 "[bi->skb] <-- Ext Pkt Split format\n");
343 /* [Extended] Receive Descriptor (Write-Back) Format
345 * 63 48 47 32 31 13 12 8 7 4 3 0
346 * +------------------------------------------------------+
347 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
348 * | Checksum | Ident | | Queue | | Type |
349 * +------------------------------------------------------+
350 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
351 * +------------------------------------------------------+
352 * 63 48 47 32 31 20 19 0
354 printk(KERN_INFO
"RWB[desc] [ck ipid mrqhsh] "
356 "[ l3 l2 l1 hs] [reserved ] ---------------- "
357 "[bi->skb] <-- Ext Rx Write-Back format\n");
358 for (i
= 0; i
< rx_ring
->count
; i
++) {
359 buffer_info
= &rx_ring
->buffer_info
[i
];
360 rx_desc_ps
= E1000_RX_DESC_PS(*rx_ring
, i
);
361 u1
= (struct my_u1
*)rx_desc_ps
;
363 le32_to_cpu(rx_desc_ps
->wb
.middle
.status_error
);
364 if (staterr
& E1000_RXD_STAT_DD
) {
365 /* Descriptor Done */
366 printk(KERN_INFO
"RWB[0x%03X] %016llX "
367 "%016llX %016llX %016llX "
368 "---------------- %p", i
,
369 (unsigned long long)le64_to_cpu(u1
->a
),
370 (unsigned long long)le64_to_cpu(u1
->b
),
371 (unsigned long long)le64_to_cpu(u1
->c
),
372 (unsigned long long)le64_to_cpu(u1
->d
),
375 printk(KERN_INFO
"R [0x%03X] %016llX "
376 "%016llX %016llX %016llX %016llX %p", i
,
377 (unsigned long long)le64_to_cpu(u1
->a
),
378 (unsigned long long)le64_to_cpu(u1
->b
),
379 (unsigned long long)le64_to_cpu(u1
->c
),
380 (unsigned long long)le64_to_cpu(u1
->d
),
381 (unsigned long long)buffer_info
->dma
,
384 if (netif_msg_pktdata(adapter
))
385 print_hex_dump(KERN_INFO
, "",
386 DUMP_PREFIX_ADDRESS
, 16, 1,
387 phys_to_virt(buffer_info
->dma
),
388 adapter
->rx_ps_bsize0
, true);
391 if (i
== rx_ring
->next_to_use
)
392 printk(KERN_CONT
" NTU\n");
393 else if (i
== rx_ring
->next_to_clean
)
394 printk(KERN_CONT
" NTC\n");
396 printk(KERN_CONT
"\n");
401 /* Legacy Receive Descriptor Format
403 * +-----------------------------------------------------+
404 * | Buffer Address [63:0] |
405 * +-----------------------------------------------------+
406 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
407 * +-----------------------------------------------------+
408 * 63 48 47 40 39 32 31 16 15 0
410 printk(KERN_INFO
"Rl[desc] [address 63:0 ] "
411 "[vl er S cks ln] [bi->dma ] [bi->skb] "
412 "<-- Legacy format\n");
413 for (i
= 0; rx_ring
->desc
&& (i
< rx_ring
->count
); i
++) {
414 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
415 buffer_info
= &rx_ring
->buffer_info
[i
];
416 u0
= (struct my_u0
*)rx_desc
;
417 printk(KERN_INFO
"Rl[0x%03X] %016llX %016llX "
419 (unsigned long long)le64_to_cpu(u0
->a
),
420 (unsigned long long)le64_to_cpu(u0
->b
),
421 (unsigned long long)buffer_info
->dma
,
423 if (i
== rx_ring
->next_to_use
)
424 printk(KERN_CONT
" NTU\n");
425 else if (i
== rx_ring
->next_to_clean
)
426 printk(KERN_CONT
" NTC\n");
428 printk(KERN_CONT
"\n");
430 if (netif_msg_pktdata(adapter
))
431 print_hex_dump(KERN_INFO
, "",
434 phys_to_virt(buffer_info
->dma
),
435 adapter
->rx_buffer_len
, true);
444 * e1000_desc_unused - calculate if we have unused descriptors
446 static int e1000_desc_unused(struct e1000_ring
*ring
)
448 if (ring
->next_to_clean
> ring
->next_to_use
)
449 return ring
->next_to_clean
- ring
->next_to_use
- 1;
451 return ring
->count
+ ring
->next_to_clean
- ring
->next_to_use
- 1;
455 * e1000_receive_skb - helper function to handle Rx indications
456 * @adapter: board private structure
457 * @status: descriptor status field as written by hardware
458 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
459 * @skb: pointer to sk_buff to be indicated to stack
461 static void e1000_receive_skb(struct e1000_adapter
*adapter
,
462 struct net_device
*netdev
, struct sk_buff
*skb
,
463 u8 status
, __le16 vlan
)
465 u16 tag
= le16_to_cpu(vlan
);
466 skb
->protocol
= eth_type_trans(skb
, netdev
);
468 if (status
& E1000_RXD_STAT_VP
)
469 __vlan_hwaccel_put_tag(skb
, tag
);
471 napi_gro_receive(&adapter
->napi
, skb
);
475 * e1000_rx_checksum - Receive Checksum Offload
476 * @adapter: board private structure
477 * @status_err: receive descriptor status and error fields
478 * @csum: receive descriptor csum field
479 * @sk_buff: socket buffer with received data
481 static void e1000_rx_checksum(struct e1000_adapter
*adapter
, u32 status_err
,
482 u32 csum
, struct sk_buff
*skb
)
484 u16 status
= (u16
)status_err
;
485 u8 errors
= (u8
)(status_err
>> 24);
487 skb_checksum_none_assert(skb
);
489 /* Ignore Checksum bit is set */
490 if (status
& E1000_RXD_STAT_IXSM
)
492 /* TCP/UDP checksum error bit is set */
493 if (errors
& E1000_RXD_ERR_TCPE
) {
494 /* let the stack verify checksum errors */
495 adapter
->hw_csum_err
++;
499 /* TCP/UDP Checksum has not been calculated */
500 if (!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
503 /* It must be a TCP or UDP packet with a valid checksum */
504 if (status
& E1000_RXD_STAT_TCPCS
) {
505 /* TCP checksum is good */
506 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
509 * IP fragment with UDP payload
510 * Hardware complements the payload checksum, so we undo it
511 * and then put the value in host order for further stack use.
513 __sum16 sum
= (__force __sum16
)htons(csum
);
514 skb
->csum
= csum_unfold(~sum
);
515 skb
->ip_summed
= CHECKSUM_COMPLETE
;
517 adapter
->hw_csum_good
++;
521 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
522 * @adapter: address of board private structure
524 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
527 struct net_device
*netdev
= adapter
->netdev
;
528 struct pci_dev
*pdev
= adapter
->pdev
;
529 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
530 struct e1000_rx_desc
*rx_desc
;
531 struct e1000_buffer
*buffer_info
;
534 unsigned int bufsz
= adapter
->rx_buffer_len
;
536 i
= rx_ring
->next_to_use
;
537 buffer_info
= &rx_ring
->buffer_info
[i
];
539 while (cleaned_count
--) {
540 skb
= buffer_info
->skb
;
546 skb
= netdev_alloc_skb_ip_align(netdev
, bufsz
);
548 /* Better luck next round */
549 adapter
->alloc_rx_buff_failed
++;
553 buffer_info
->skb
= skb
;
555 buffer_info
->dma
= dma_map_single(&pdev
->dev
, skb
->data
,
556 adapter
->rx_buffer_len
,
558 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
)) {
559 dev_err(&pdev
->dev
, "Rx DMA map failed\n");
560 adapter
->rx_dma_failed
++;
564 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
565 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
567 if (unlikely(!(i
& (E1000_RX_BUFFER_WRITE
- 1)))) {
569 * Force memory writes to complete before letting h/w
570 * know there are new descriptors to fetch. (Only
571 * applicable for weak-ordered memory model archs,
575 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
578 if (i
== rx_ring
->count
)
580 buffer_info
= &rx_ring
->buffer_info
[i
];
583 rx_ring
->next_to_use
= i
;
587 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
588 * @adapter: address of board private structure
590 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
593 struct net_device
*netdev
= adapter
->netdev
;
594 struct pci_dev
*pdev
= adapter
->pdev
;
595 union e1000_rx_desc_packet_split
*rx_desc
;
596 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
597 struct e1000_buffer
*buffer_info
;
598 struct e1000_ps_page
*ps_page
;
602 i
= rx_ring
->next_to_use
;
603 buffer_info
= &rx_ring
->buffer_info
[i
];
605 while (cleaned_count
--) {
606 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
608 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
609 ps_page
= &buffer_info
->ps_pages
[j
];
610 if (j
>= adapter
->rx_ps_pages
) {
611 /* all unused desc entries get hw null ptr */
612 rx_desc
->read
.buffer_addr
[j
+ 1] =
616 if (!ps_page
->page
) {
617 ps_page
->page
= alloc_page(GFP_ATOMIC
);
618 if (!ps_page
->page
) {
619 adapter
->alloc_rx_buff_failed
++;
622 ps_page
->dma
= dma_map_page(&pdev
->dev
,
626 if (dma_mapping_error(&pdev
->dev
,
628 dev_err(&adapter
->pdev
->dev
,
629 "Rx DMA page map failed\n");
630 adapter
->rx_dma_failed
++;
635 * Refresh the desc even if buffer_addrs
636 * didn't change because each write-back
639 rx_desc
->read
.buffer_addr
[j
+ 1] =
640 cpu_to_le64(ps_page
->dma
);
643 skb
= netdev_alloc_skb_ip_align(netdev
,
644 adapter
->rx_ps_bsize0
);
647 adapter
->alloc_rx_buff_failed
++;
651 buffer_info
->skb
= skb
;
652 buffer_info
->dma
= dma_map_single(&pdev
->dev
, skb
->data
,
653 adapter
->rx_ps_bsize0
,
655 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
)) {
656 dev_err(&pdev
->dev
, "Rx DMA map failed\n");
657 adapter
->rx_dma_failed
++;
659 dev_kfree_skb_any(skb
);
660 buffer_info
->skb
= NULL
;
664 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
666 if (unlikely(!(i
& (E1000_RX_BUFFER_WRITE
- 1)))) {
668 * Force memory writes to complete before letting h/w
669 * know there are new descriptors to fetch. (Only
670 * applicable for weak-ordered memory model archs,
674 writel(i
<< 1, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
678 if (i
== rx_ring
->count
)
680 buffer_info
= &rx_ring
->buffer_info
[i
];
684 rx_ring
->next_to_use
= i
;
688 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
689 * @adapter: address of board private structure
690 * @cleaned_count: number of buffers to allocate this pass
693 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter
*adapter
,
696 struct net_device
*netdev
= adapter
->netdev
;
697 struct pci_dev
*pdev
= adapter
->pdev
;
698 struct e1000_rx_desc
*rx_desc
;
699 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
700 struct e1000_buffer
*buffer_info
;
703 unsigned int bufsz
= 256 - 16 /* for skb_reserve */;
705 i
= rx_ring
->next_to_use
;
706 buffer_info
= &rx_ring
->buffer_info
[i
];
708 while (cleaned_count
--) {
709 skb
= buffer_info
->skb
;
715 skb
= netdev_alloc_skb_ip_align(netdev
, bufsz
);
716 if (unlikely(!skb
)) {
717 /* Better luck next round */
718 adapter
->alloc_rx_buff_failed
++;
722 buffer_info
->skb
= skb
;
724 /* allocate a new page if necessary */
725 if (!buffer_info
->page
) {
726 buffer_info
->page
= alloc_page(GFP_ATOMIC
);
727 if (unlikely(!buffer_info
->page
)) {
728 adapter
->alloc_rx_buff_failed
++;
733 if (!buffer_info
->dma
)
734 buffer_info
->dma
= dma_map_page(&pdev
->dev
,
735 buffer_info
->page
, 0,
739 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
740 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
742 if (unlikely(++i
== rx_ring
->count
))
744 buffer_info
= &rx_ring
->buffer_info
[i
];
747 if (likely(rx_ring
->next_to_use
!= i
)) {
748 rx_ring
->next_to_use
= i
;
749 if (unlikely(i
-- == 0))
750 i
= (rx_ring
->count
- 1);
752 /* Force memory writes to complete before letting h/w
753 * know there are new descriptors to fetch. (Only
754 * applicable for weak-ordered memory model archs,
757 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
762 * e1000_clean_rx_irq - Send received data up the network stack; legacy
763 * @adapter: board private structure
765 * the return value indicates whether actual cleaning was done, there
766 * is no guarantee that everything was cleaned
768 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
769 int *work_done
, int work_to_do
)
771 struct net_device
*netdev
= adapter
->netdev
;
772 struct pci_dev
*pdev
= adapter
->pdev
;
773 struct e1000_hw
*hw
= &adapter
->hw
;
774 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
775 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
776 struct e1000_buffer
*buffer_info
, *next_buffer
;
779 int cleaned_count
= 0;
781 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
783 i
= rx_ring
->next_to_clean
;
784 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
785 buffer_info
= &rx_ring
->buffer_info
[i
];
787 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
791 if (*work_done
>= work_to_do
)
794 rmb(); /* read descriptor and rx_buffer_info after status DD */
796 status
= rx_desc
->status
;
797 skb
= buffer_info
->skb
;
798 buffer_info
->skb
= NULL
;
800 prefetch(skb
->data
- NET_IP_ALIGN
);
803 if (i
== rx_ring
->count
)
805 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
808 next_buffer
= &rx_ring
->buffer_info
[i
];
812 dma_unmap_single(&pdev
->dev
,
814 adapter
->rx_buffer_len
,
816 buffer_info
->dma
= 0;
818 length
= le16_to_cpu(rx_desc
->length
);
821 * !EOP means multiple descriptors were used to store a single
822 * packet, if that's the case we need to toss it. In fact, we
823 * need to toss every packet with the EOP bit clear and the
824 * next frame that _does_ have the EOP bit set, as it is by
825 * definition only a frame fragment
827 if (unlikely(!(status
& E1000_RXD_STAT_EOP
)))
828 adapter
->flags2
|= FLAG2_IS_DISCARDING
;
830 if (adapter
->flags2
& FLAG2_IS_DISCARDING
) {
831 /* All receives must fit into a single buffer */
832 e_dbg("Receive packet consumed multiple buffers\n");
834 buffer_info
->skb
= skb
;
835 if (status
& E1000_RXD_STAT_EOP
)
836 adapter
->flags2
&= ~FLAG2_IS_DISCARDING
;
840 if (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
) {
842 buffer_info
->skb
= skb
;
846 /* adjust length to remove Ethernet CRC */
847 if (!(adapter
->flags2
& FLAG2_CRC_STRIPPING
))
850 total_rx_bytes
+= length
;
854 * code added for copybreak, this should improve
855 * performance for small packets with large amounts
856 * of reassembly being done in the stack
858 if (length
< copybreak
) {
859 struct sk_buff
*new_skb
=
860 netdev_alloc_skb_ip_align(netdev
, length
);
862 skb_copy_to_linear_data_offset(new_skb
,
868 /* save the skb in buffer_info as good */
869 buffer_info
->skb
= skb
;
872 /* else just continue with the old one */
874 /* end copybreak code */
875 skb_put(skb
, length
);
877 /* Receive Checksum Offload */
878 e1000_rx_checksum(adapter
,
880 ((u32
)(rx_desc
->errors
) << 24),
881 le16_to_cpu(rx_desc
->csum
), skb
);
883 e1000_receive_skb(adapter
, netdev
, skb
,status
,rx_desc
->special
);
888 /* return some buffers to hardware, one at a time is too slow */
889 if (cleaned_count
>= E1000_RX_BUFFER_WRITE
) {
890 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
894 /* use prefetched values */
896 buffer_info
= next_buffer
;
898 rx_ring
->next_to_clean
= i
;
900 cleaned_count
= e1000_desc_unused(rx_ring
);
902 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
904 adapter
->total_rx_bytes
+= total_rx_bytes
;
905 adapter
->total_rx_packets
+= total_rx_packets
;
909 static void e1000_put_txbuf(struct e1000_adapter
*adapter
,
910 struct e1000_buffer
*buffer_info
)
912 if (buffer_info
->dma
) {
913 if (buffer_info
->mapped_as_page
)
914 dma_unmap_page(&adapter
->pdev
->dev
, buffer_info
->dma
,
915 buffer_info
->length
, DMA_TO_DEVICE
);
917 dma_unmap_single(&adapter
->pdev
->dev
, buffer_info
->dma
,
918 buffer_info
->length
, DMA_TO_DEVICE
);
919 buffer_info
->dma
= 0;
921 if (buffer_info
->skb
) {
922 dev_kfree_skb_any(buffer_info
->skb
);
923 buffer_info
->skb
= NULL
;
925 buffer_info
->time_stamp
= 0;
928 static void e1000_print_hw_hang(struct work_struct
*work
)
930 struct e1000_adapter
*adapter
= container_of(work
,
931 struct e1000_adapter
,
933 struct net_device
*netdev
= adapter
->netdev
;
934 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
935 unsigned int i
= tx_ring
->next_to_clean
;
936 unsigned int eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
937 struct e1000_tx_desc
*eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
938 struct e1000_hw
*hw
= &adapter
->hw
;
939 u16 phy_status
, phy_1000t_status
, phy_ext_status
;
942 if (test_bit(__E1000_DOWN
, &adapter
->state
))
945 if (!adapter
->tx_hang_recheck
&&
946 (adapter
->flags2
& FLAG2_DMA_BURST
)) {
947 /* May be block on write-back, flush and detect again
948 * flush pending descriptor writebacks to memory
950 ew32(TIDV
, adapter
->tx_int_delay
| E1000_TIDV_FPD
);
951 /* execute the writes immediately */
953 adapter
->tx_hang_recheck
= true;
956 /* Real hang detected */
957 adapter
->tx_hang_recheck
= false;
958 netif_stop_queue(netdev
);
960 e1e_rphy(hw
, PHY_STATUS
, &phy_status
);
961 e1e_rphy(hw
, PHY_1000T_STATUS
, &phy_1000t_status
);
962 e1e_rphy(hw
, PHY_EXT_STATUS
, &phy_ext_status
);
964 pci_read_config_word(adapter
->pdev
, PCI_STATUS
, &pci_status
);
966 /* detected Hardware unit hang */
967 e_err("Detected Hardware Unit Hang:\n"
970 " next_to_use <%x>\n"
971 " next_to_clean <%x>\n"
972 "buffer_info[next_to_clean]:\n"
973 " time_stamp <%lx>\n"
974 " next_to_watch <%x>\n"
976 " next_to_watch.status <%x>\n"
979 "PHY 1000BASE-T Status <%x>\n"
980 "PHY Extended Status <%x>\n"
982 readl(adapter
->hw
.hw_addr
+ tx_ring
->head
),
983 readl(adapter
->hw
.hw_addr
+ tx_ring
->tail
),
984 tx_ring
->next_to_use
,
985 tx_ring
->next_to_clean
,
986 tx_ring
->buffer_info
[eop
].time_stamp
,
989 eop_desc
->upper
.fields
.status
,
998 * e1000_clean_tx_irq - Reclaim resources after transmit completes
999 * @adapter: board private structure
1001 * the return value indicates whether actual cleaning was done, there
1002 * is no guarantee that everything was cleaned
1004 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
)
1006 struct net_device
*netdev
= adapter
->netdev
;
1007 struct e1000_hw
*hw
= &adapter
->hw
;
1008 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1009 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
1010 struct e1000_buffer
*buffer_info
;
1011 unsigned int i
, eop
;
1012 unsigned int count
= 0;
1013 unsigned int total_tx_bytes
= 0, total_tx_packets
= 0;
1015 i
= tx_ring
->next_to_clean
;
1016 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
1017 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
1019 while ((eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) &&
1020 (count
< tx_ring
->count
)) {
1021 bool cleaned
= false;
1022 rmb(); /* read buffer_info after eop_desc */
1023 for (; !cleaned
; count
++) {
1024 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
1025 buffer_info
= &tx_ring
->buffer_info
[i
];
1026 cleaned
= (i
== eop
);
1029 total_tx_packets
+= buffer_info
->segs
;
1030 total_tx_bytes
+= buffer_info
->bytecount
;
1033 e1000_put_txbuf(adapter
, buffer_info
);
1034 tx_desc
->upper
.data
= 0;
1037 if (i
== tx_ring
->count
)
1041 if (i
== tx_ring
->next_to_use
)
1043 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
1044 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
1047 tx_ring
->next_to_clean
= i
;
1049 #define TX_WAKE_THRESHOLD 32
1050 if (count
&& netif_carrier_ok(netdev
) &&
1051 e1000_desc_unused(tx_ring
) >= TX_WAKE_THRESHOLD
) {
1052 /* Make sure that anybody stopping the queue after this
1053 * sees the new next_to_clean.
1057 if (netif_queue_stopped(netdev
) &&
1058 !(test_bit(__E1000_DOWN
, &adapter
->state
))) {
1059 netif_wake_queue(netdev
);
1060 ++adapter
->restart_queue
;
1064 if (adapter
->detect_tx_hung
) {
1066 * Detect a transmit hang in hardware, this serializes the
1067 * check with the clearing of time_stamp and movement of i
1069 adapter
->detect_tx_hung
= 0;
1070 if (tx_ring
->buffer_info
[i
].time_stamp
&&
1071 time_after(jiffies
, tx_ring
->buffer_info
[i
].time_stamp
1072 + (adapter
->tx_timeout_factor
* HZ
)) &&
1073 !(er32(STATUS
) & E1000_STATUS_TXOFF
))
1074 schedule_work(&adapter
->print_hang_task
);
1076 adapter
->tx_hang_recheck
= false;
1078 adapter
->total_tx_bytes
+= total_tx_bytes
;
1079 adapter
->total_tx_packets
+= total_tx_packets
;
1080 return count
< tx_ring
->count
;
1084 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1085 * @adapter: board private structure
1087 * the return value indicates whether actual cleaning was done, there
1088 * is no guarantee that everything was cleaned
1090 static bool e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
1091 int *work_done
, int work_to_do
)
1093 struct e1000_hw
*hw
= &adapter
->hw
;
1094 union e1000_rx_desc_packet_split
*rx_desc
, *next_rxd
;
1095 struct net_device
*netdev
= adapter
->netdev
;
1096 struct pci_dev
*pdev
= adapter
->pdev
;
1097 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1098 struct e1000_buffer
*buffer_info
, *next_buffer
;
1099 struct e1000_ps_page
*ps_page
;
1100 struct sk_buff
*skb
;
1102 u32 length
, staterr
;
1103 int cleaned_count
= 0;
1105 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
1107 i
= rx_ring
->next_to_clean
;
1108 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
1109 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
1110 buffer_info
= &rx_ring
->buffer_info
[i
];
1112 while (staterr
& E1000_RXD_STAT_DD
) {
1113 if (*work_done
>= work_to_do
)
1116 skb
= buffer_info
->skb
;
1117 rmb(); /* read descriptor and rx_buffer_info after status DD */
1119 /* in the packet split case this is header only */
1120 prefetch(skb
->data
- NET_IP_ALIGN
);
1123 if (i
== rx_ring
->count
)
1125 next_rxd
= E1000_RX_DESC_PS(*rx_ring
, i
);
1128 next_buffer
= &rx_ring
->buffer_info
[i
];
1132 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
1133 adapter
->rx_ps_bsize0
, DMA_FROM_DEVICE
);
1134 buffer_info
->dma
= 0;
1136 /* see !EOP comment in other Rx routine */
1137 if (!(staterr
& E1000_RXD_STAT_EOP
))
1138 adapter
->flags2
|= FLAG2_IS_DISCARDING
;
1140 if (adapter
->flags2
& FLAG2_IS_DISCARDING
) {
1141 e_dbg("Packet Split buffers didn't pick up the full "
1143 dev_kfree_skb_irq(skb
);
1144 if (staterr
& E1000_RXD_STAT_EOP
)
1145 adapter
->flags2
&= ~FLAG2_IS_DISCARDING
;
1149 if (staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
) {
1150 dev_kfree_skb_irq(skb
);
1154 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
1157 e_dbg("Last part of the packet spanning multiple "
1159 dev_kfree_skb_irq(skb
);
1164 skb_put(skb
, length
);
1168 * this looks ugly, but it seems compiler issues make it
1169 * more efficient than reusing j
1171 int l1
= le16_to_cpu(rx_desc
->wb
.upper
.length
[0]);
1174 * page alloc/put takes too long and effects small packet
1175 * throughput, so unsplit small packets and save the alloc/put
1176 * only valid in softirq (napi) context to call kmap_*
1178 if (l1
&& (l1
<= copybreak
) &&
1179 ((length
+ l1
) <= adapter
->rx_ps_bsize0
)) {
1182 ps_page
= &buffer_info
->ps_pages
[0];
1185 * there is no documentation about how to call
1186 * kmap_atomic, so we can't hold the mapping
1189 dma_sync_single_for_cpu(&pdev
->dev
, ps_page
->dma
,
1190 PAGE_SIZE
, DMA_FROM_DEVICE
);
1191 vaddr
= kmap_atomic(ps_page
->page
, KM_SKB_DATA_SOFTIRQ
);
1192 memcpy(skb_tail_pointer(skb
), vaddr
, l1
);
1193 kunmap_atomic(vaddr
, KM_SKB_DATA_SOFTIRQ
);
1194 dma_sync_single_for_device(&pdev
->dev
, ps_page
->dma
,
1195 PAGE_SIZE
, DMA_FROM_DEVICE
);
1197 /* remove the CRC */
1198 if (!(adapter
->flags2
& FLAG2_CRC_STRIPPING
))
1206 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
1207 length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
]);
1211 ps_page
= &buffer_info
->ps_pages
[j
];
1212 dma_unmap_page(&pdev
->dev
, ps_page
->dma
, PAGE_SIZE
,
1215 skb_fill_page_desc(skb
, j
, ps_page
->page
, 0, length
);
1216 ps_page
->page
= NULL
;
1218 skb
->data_len
+= length
;
1219 skb
->truesize
+= length
;
1222 /* strip the ethernet crc, problem is we're using pages now so
1223 * this whole operation can get a little cpu intensive
1225 if (!(adapter
->flags2
& FLAG2_CRC_STRIPPING
))
1226 pskb_trim(skb
, skb
->len
- 4);
1229 total_rx_bytes
+= skb
->len
;
1232 e1000_rx_checksum(adapter
, staterr
, le16_to_cpu(
1233 rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
), skb
);
1235 if (rx_desc
->wb
.upper
.header_status
&
1236 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP
))
1237 adapter
->rx_hdr_split
++;
1239 e1000_receive_skb(adapter
, netdev
, skb
,
1240 staterr
, rx_desc
->wb
.middle
.vlan
);
1243 rx_desc
->wb
.middle
.status_error
&= cpu_to_le32(~0xFF);
1244 buffer_info
->skb
= NULL
;
1246 /* return some buffers to hardware, one at a time is too slow */
1247 if (cleaned_count
>= E1000_RX_BUFFER_WRITE
) {
1248 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
1252 /* use prefetched values */
1254 buffer_info
= next_buffer
;
1256 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
1258 rx_ring
->next_to_clean
= i
;
1260 cleaned_count
= e1000_desc_unused(rx_ring
);
1262 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
1264 adapter
->total_rx_bytes
+= total_rx_bytes
;
1265 adapter
->total_rx_packets
+= total_rx_packets
;
1270 * e1000_consume_page - helper function
1272 static void e1000_consume_page(struct e1000_buffer
*bi
, struct sk_buff
*skb
,
1277 skb
->data_len
+= length
;
1278 skb
->truesize
+= length
;
1282 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1283 * @adapter: board private structure
1285 * the return value indicates whether actual cleaning was done, there
1286 * is no guarantee that everything was cleaned
1289 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter
*adapter
,
1290 int *work_done
, int work_to_do
)
1292 struct net_device
*netdev
= adapter
->netdev
;
1293 struct pci_dev
*pdev
= adapter
->pdev
;
1294 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1295 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
1296 struct e1000_buffer
*buffer_info
, *next_buffer
;
1299 int cleaned_count
= 0;
1300 bool cleaned
= false;
1301 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
1303 i
= rx_ring
->next_to_clean
;
1304 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
1305 buffer_info
= &rx_ring
->buffer_info
[i
];
1307 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
1308 struct sk_buff
*skb
;
1311 if (*work_done
>= work_to_do
)
1314 rmb(); /* read descriptor and rx_buffer_info after status DD */
1316 status
= rx_desc
->status
;
1317 skb
= buffer_info
->skb
;
1318 buffer_info
->skb
= NULL
;
1321 if (i
== rx_ring
->count
)
1323 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
1326 next_buffer
= &rx_ring
->buffer_info
[i
];
1330 dma_unmap_page(&pdev
->dev
, buffer_info
->dma
, PAGE_SIZE
,
1332 buffer_info
->dma
= 0;
1334 length
= le16_to_cpu(rx_desc
->length
);
1336 /* errors is only valid for DD + EOP descriptors */
1337 if (unlikely((status
& E1000_RXD_STAT_EOP
) &&
1338 (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
))) {
1339 /* recycle both page and skb */
1340 buffer_info
->skb
= skb
;
1341 /* an error means any chain goes out the window
1343 if (rx_ring
->rx_skb_top
)
1344 dev_kfree_skb_irq(rx_ring
->rx_skb_top
);
1345 rx_ring
->rx_skb_top
= NULL
;
1349 #define rxtop (rx_ring->rx_skb_top)
1350 if (!(status
& E1000_RXD_STAT_EOP
)) {
1351 /* this descriptor is only the beginning (or middle) */
1353 /* this is the beginning of a chain */
1355 skb_fill_page_desc(rxtop
, 0, buffer_info
->page
,
1358 /* this is the middle of a chain */
1359 skb_fill_page_desc(rxtop
,
1360 skb_shinfo(rxtop
)->nr_frags
,
1361 buffer_info
->page
, 0, length
);
1362 /* re-use the skb, only consumed the page */
1363 buffer_info
->skb
= skb
;
1365 e1000_consume_page(buffer_info
, rxtop
, length
);
1369 /* end of the chain */
1370 skb_fill_page_desc(rxtop
,
1371 skb_shinfo(rxtop
)->nr_frags
,
1372 buffer_info
->page
, 0, length
);
1373 /* re-use the current skb, we only consumed the
1375 buffer_info
->skb
= skb
;
1378 e1000_consume_page(buffer_info
, skb
, length
);
1380 /* no chain, got EOP, this buf is the packet
1381 * copybreak to save the put_page/alloc_page */
1382 if (length
<= copybreak
&&
1383 skb_tailroom(skb
) >= length
) {
1385 vaddr
= kmap_atomic(buffer_info
->page
,
1386 KM_SKB_DATA_SOFTIRQ
);
1387 memcpy(skb_tail_pointer(skb
), vaddr
,
1389 kunmap_atomic(vaddr
,
1390 KM_SKB_DATA_SOFTIRQ
);
1391 /* re-use the page, so don't erase
1392 * buffer_info->page */
1393 skb_put(skb
, length
);
1395 skb_fill_page_desc(skb
, 0,
1396 buffer_info
->page
, 0,
1398 e1000_consume_page(buffer_info
, skb
,
1404 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1405 e1000_rx_checksum(adapter
,
1407 ((u32
)(rx_desc
->errors
) << 24),
1408 le16_to_cpu(rx_desc
->csum
), skb
);
1410 /* probably a little skewed due to removing CRC */
1411 total_rx_bytes
+= skb
->len
;
1414 /* eth type trans needs skb->data to point to something */
1415 if (!pskb_may_pull(skb
, ETH_HLEN
)) {
1416 e_err("pskb_may_pull failed.\n");
1417 dev_kfree_skb_irq(skb
);
1421 e1000_receive_skb(adapter
, netdev
, skb
, status
,
1425 rx_desc
->status
= 0;
1427 /* return some buffers to hardware, one at a time is too slow */
1428 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
1429 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
1433 /* use prefetched values */
1435 buffer_info
= next_buffer
;
1437 rx_ring
->next_to_clean
= i
;
1439 cleaned_count
= e1000_desc_unused(rx_ring
);
1441 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
1443 adapter
->total_rx_bytes
+= total_rx_bytes
;
1444 adapter
->total_rx_packets
+= total_rx_packets
;
1449 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1450 * @adapter: board private structure
1452 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
)
1454 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1455 struct e1000_buffer
*buffer_info
;
1456 struct e1000_ps_page
*ps_page
;
1457 struct pci_dev
*pdev
= adapter
->pdev
;
1460 /* Free all the Rx ring sk_buffs */
1461 for (i
= 0; i
< rx_ring
->count
; i
++) {
1462 buffer_info
= &rx_ring
->buffer_info
[i
];
1463 if (buffer_info
->dma
) {
1464 if (adapter
->clean_rx
== e1000_clean_rx_irq
)
1465 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
1466 adapter
->rx_buffer_len
,
1468 else if (adapter
->clean_rx
== e1000_clean_jumbo_rx_irq
)
1469 dma_unmap_page(&pdev
->dev
, buffer_info
->dma
,
1472 else if (adapter
->clean_rx
== e1000_clean_rx_irq_ps
)
1473 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
1474 adapter
->rx_ps_bsize0
,
1476 buffer_info
->dma
= 0;
1479 if (buffer_info
->page
) {
1480 put_page(buffer_info
->page
);
1481 buffer_info
->page
= NULL
;
1484 if (buffer_info
->skb
) {
1485 dev_kfree_skb(buffer_info
->skb
);
1486 buffer_info
->skb
= NULL
;
1489 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
1490 ps_page
= &buffer_info
->ps_pages
[j
];
1493 dma_unmap_page(&pdev
->dev
, ps_page
->dma
, PAGE_SIZE
,
1496 put_page(ps_page
->page
);
1497 ps_page
->page
= NULL
;
1501 /* there also may be some cached data from a chained receive */
1502 if (rx_ring
->rx_skb_top
) {
1503 dev_kfree_skb(rx_ring
->rx_skb_top
);
1504 rx_ring
->rx_skb_top
= NULL
;
1507 /* Zero out the descriptor ring */
1508 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1510 rx_ring
->next_to_clean
= 0;
1511 rx_ring
->next_to_use
= 0;
1512 adapter
->flags2
&= ~FLAG2_IS_DISCARDING
;
1514 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1515 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1518 static void e1000e_downshift_workaround(struct work_struct
*work
)
1520 struct e1000_adapter
*adapter
= container_of(work
,
1521 struct e1000_adapter
, downshift_task
);
1523 if (test_bit(__E1000_DOWN
, &adapter
->state
))
1526 e1000e_gig_downshift_workaround_ich8lan(&adapter
->hw
);
1530 * e1000_intr_msi - Interrupt Handler
1531 * @irq: interrupt number
1532 * @data: pointer to a network interface device structure
1534 static irqreturn_t
e1000_intr_msi(int irq
, void *data
)
1536 struct net_device
*netdev
= data
;
1537 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1538 struct e1000_hw
*hw
= &adapter
->hw
;
1539 u32 icr
= er32(ICR
);
1542 * read ICR disables interrupts using IAM
1545 if (icr
& E1000_ICR_LSC
) {
1546 hw
->mac
.get_link_status
= 1;
1548 * ICH8 workaround-- Call gig speed drop workaround on cable
1549 * disconnect (LSC) before accessing any PHY registers
1551 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
1552 (!(er32(STATUS
) & E1000_STATUS_LU
)))
1553 schedule_work(&adapter
->downshift_task
);
1556 * 80003ES2LAN workaround-- For packet buffer work-around on
1557 * link down event; disable receives here in the ISR and reset
1558 * adapter in watchdog
1560 if (netif_carrier_ok(netdev
) &&
1561 adapter
->flags
& FLAG_RX_NEEDS_RESTART
) {
1562 /* disable receives */
1563 u32 rctl
= er32(RCTL
);
1564 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1565 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
1567 /* guard against interrupt when we're going down */
1568 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1569 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1572 if (napi_schedule_prep(&adapter
->napi
)) {
1573 adapter
->total_tx_bytes
= 0;
1574 adapter
->total_tx_packets
= 0;
1575 adapter
->total_rx_bytes
= 0;
1576 adapter
->total_rx_packets
= 0;
1577 __napi_schedule(&adapter
->napi
);
1584 * e1000_intr - Interrupt Handler
1585 * @irq: interrupt number
1586 * @data: pointer to a network interface device structure
1588 static irqreturn_t
e1000_intr(int irq
, void *data
)
1590 struct net_device
*netdev
= data
;
1591 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1592 struct e1000_hw
*hw
= &adapter
->hw
;
1593 u32 rctl
, icr
= er32(ICR
);
1595 if (!icr
|| test_bit(__E1000_DOWN
, &adapter
->state
))
1596 return IRQ_NONE
; /* Not our interrupt */
1599 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1600 * not set, then the adapter didn't send an interrupt
1602 if (!(icr
& E1000_ICR_INT_ASSERTED
))
1606 * Interrupt Auto-Mask...upon reading ICR,
1607 * interrupts are masked. No need for the
1611 if (icr
& E1000_ICR_LSC
) {
1612 hw
->mac
.get_link_status
= 1;
1614 * ICH8 workaround-- Call gig speed drop workaround on cable
1615 * disconnect (LSC) before accessing any PHY registers
1617 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
1618 (!(er32(STATUS
) & E1000_STATUS_LU
)))
1619 schedule_work(&adapter
->downshift_task
);
1622 * 80003ES2LAN workaround--
1623 * For packet buffer work-around on link down event;
1624 * disable receives here in the ISR and
1625 * reset adapter in watchdog
1627 if (netif_carrier_ok(netdev
) &&
1628 (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)) {
1629 /* disable receives */
1631 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1632 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
1634 /* guard against interrupt when we're going down */
1635 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1636 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1639 if (napi_schedule_prep(&adapter
->napi
)) {
1640 adapter
->total_tx_bytes
= 0;
1641 adapter
->total_tx_packets
= 0;
1642 adapter
->total_rx_bytes
= 0;
1643 adapter
->total_rx_packets
= 0;
1644 __napi_schedule(&adapter
->napi
);
1650 static irqreturn_t
e1000_msix_other(int irq
, void *data
)
1652 struct net_device
*netdev
= data
;
1653 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1654 struct e1000_hw
*hw
= &adapter
->hw
;
1655 u32 icr
= er32(ICR
);
1657 if (!(icr
& E1000_ICR_INT_ASSERTED
)) {
1658 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1659 ew32(IMS
, E1000_IMS_OTHER
);
1663 if (icr
& adapter
->eiac_mask
)
1664 ew32(ICS
, (icr
& adapter
->eiac_mask
));
1666 if (icr
& E1000_ICR_OTHER
) {
1667 if (!(icr
& E1000_ICR_LSC
))
1668 goto no_link_interrupt
;
1669 hw
->mac
.get_link_status
= 1;
1670 /* guard against interrupt when we're going down */
1671 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1672 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1676 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1677 ew32(IMS
, E1000_IMS_LSC
| E1000_IMS_OTHER
);
1683 static irqreturn_t
e1000_intr_msix_tx(int irq
, void *data
)
1685 struct net_device
*netdev
= data
;
1686 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1687 struct e1000_hw
*hw
= &adapter
->hw
;
1688 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1691 adapter
->total_tx_bytes
= 0;
1692 adapter
->total_tx_packets
= 0;
1694 if (!e1000_clean_tx_irq(adapter
))
1695 /* Ring was not completely cleaned, so fire another interrupt */
1696 ew32(ICS
, tx_ring
->ims_val
);
1701 static irqreturn_t
e1000_intr_msix_rx(int irq
, void *data
)
1703 struct net_device
*netdev
= data
;
1704 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1706 /* Write the ITR value calculated at the end of the
1707 * previous interrupt.
1709 if (adapter
->rx_ring
->set_itr
) {
1710 writel(1000000000 / (adapter
->rx_ring
->itr_val
* 256),
1711 adapter
->hw
.hw_addr
+ adapter
->rx_ring
->itr_register
);
1712 adapter
->rx_ring
->set_itr
= 0;
1715 if (napi_schedule_prep(&adapter
->napi
)) {
1716 adapter
->total_rx_bytes
= 0;
1717 adapter
->total_rx_packets
= 0;
1718 __napi_schedule(&adapter
->napi
);
1724 * e1000_configure_msix - Configure MSI-X hardware
1726 * e1000_configure_msix sets up the hardware to properly
1727 * generate MSI-X interrupts.
1729 static void e1000_configure_msix(struct e1000_adapter
*adapter
)
1731 struct e1000_hw
*hw
= &adapter
->hw
;
1732 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1733 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1735 u32 ctrl_ext
, ivar
= 0;
1737 adapter
->eiac_mask
= 0;
1739 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1740 if (hw
->mac
.type
== e1000_82574
) {
1741 u32 rfctl
= er32(RFCTL
);
1742 rfctl
|= E1000_RFCTL_ACK_DIS
;
1746 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1747 /* Configure Rx vector */
1748 rx_ring
->ims_val
= E1000_IMS_RXQ0
;
1749 adapter
->eiac_mask
|= rx_ring
->ims_val
;
1750 if (rx_ring
->itr_val
)
1751 writel(1000000000 / (rx_ring
->itr_val
* 256),
1752 hw
->hw_addr
+ rx_ring
->itr_register
);
1754 writel(1, hw
->hw_addr
+ rx_ring
->itr_register
);
1755 ivar
= E1000_IVAR_INT_ALLOC_VALID
| vector
;
1757 /* Configure Tx vector */
1758 tx_ring
->ims_val
= E1000_IMS_TXQ0
;
1760 if (tx_ring
->itr_val
)
1761 writel(1000000000 / (tx_ring
->itr_val
* 256),
1762 hw
->hw_addr
+ tx_ring
->itr_register
);
1764 writel(1, hw
->hw_addr
+ tx_ring
->itr_register
);
1765 adapter
->eiac_mask
|= tx_ring
->ims_val
;
1766 ivar
|= ((E1000_IVAR_INT_ALLOC_VALID
| vector
) << 8);
1768 /* set vector for Other Causes, e.g. link changes */
1770 ivar
|= ((E1000_IVAR_INT_ALLOC_VALID
| vector
) << 16);
1771 if (rx_ring
->itr_val
)
1772 writel(1000000000 / (rx_ring
->itr_val
* 256),
1773 hw
->hw_addr
+ E1000_EITR_82574(vector
));
1775 writel(1, hw
->hw_addr
+ E1000_EITR_82574(vector
));
1777 /* Cause Tx interrupts on every write back */
1782 /* enable MSI-X PBA support */
1783 ctrl_ext
= er32(CTRL_EXT
);
1784 ctrl_ext
|= E1000_CTRL_EXT_PBA_CLR
;
1786 /* Auto-Mask Other interrupts upon ICR read */
1787 #define E1000_EIAC_MASK_82574 0x01F00000
1788 ew32(IAM
, ~E1000_EIAC_MASK_82574
| E1000_IMS_OTHER
);
1789 ctrl_ext
|= E1000_CTRL_EXT_EIAME
;
1790 ew32(CTRL_EXT
, ctrl_ext
);
1794 void e1000e_reset_interrupt_capability(struct e1000_adapter
*adapter
)
1796 if (adapter
->msix_entries
) {
1797 pci_disable_msix(adapter
->pdev
);
1798 kfree(adapter
->msix_entries
);
1799 adapter
->msix_entries
= NULL
;
1800 } else if (adapter
->flags
& FLAG_MSI_ENABLED
) {
1801 pci_disable_msi(adapter
->pdev
);
1802 adapter
->flags
&= ~FLAG_MSI_ENABLED
;
1807 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1809 * Attempt to configure interrupts using the best available
1810 * capabilities of the hardware and kernel.
1812 void e1000e_set_interrupt_capability(struct e1000_adapter
*adapter
)
1817 switch (adapter
->int_mode
) {
1818 case E1000E_INT_MODE_MSIX
:
1819 if (adapter
->flags
& FLAG_HAS_MSIX
) {
1820 adapter
->num_vectors
= 3; /* RxQ0, TxQ0 and other */
1821 adapter
->msix_entries
= kcalloc(adapter
->num_vectors
,
1822 sizeof(struct msix_entry
),
1824 if (adapter
->msix_entries
) {
1825 for (i
= 0; i
< adapter
->num_vectors
; i
++)
1826 adapter
->msix_entries
[i
].entry
= i
;
1828 err
= pci_enable_msix(adapter
->pdev
,
1829 adapter
->msix_entries
,
1830 adapter
->num_vectors
);
1834 /* MSI-X failed, so fall through and try MSI */
1835 e_err("Failed to initialize MSI-X interrupts. "
1836 "Falling back to MSI interrupts.\n");
1837 e1000e_reset_interrupt_capability(adapter
);
1839 adapter
->int_mode
= E1000E_INT_MODE_MSI
;
1841 case E1000E_INT_MODE_MSI
:
1842 if (!pci_enable_msi(adapter
->pdev
)) {
1843 adapter
->flags
|= FLAG_MSI_ENABLED
;
1845 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
1846 e_err("Failed to initialize MSI interrupts. Falling "
1847 "back to legacy interrupts.\n");
1850 case E1000E_INT_MODE_LEGACY
:
1851 /* Don't do anything; this is the system default */
1855 /* store the number of vectors being used */
1856 adapter
->num_vectors
= 1;
1860 * e1000_request_msix - Initialize MSI-X interrupts
1862 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1865 static int e1000_request_msix(struct e1000_adapter
*adapter
)
1867 struct net_device
*netdev
= adapter
->netdev
;
1868 int err
= 0, vector
= 0;
1870 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
1871 snprintf(adapter
->rx_ring
->name
,
1872 sizeof(adapter
->rx_ring
->name
) - 1,
1873 "%s-rx-0", netdev
->name
);
1875 memcpy(adapter
->rx_ring
->name
, netdev
->name
, IFNAMSIZ
);
1876 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1877 e1000_intr_msix_rx
, 0, adapter
->rx_ring
->name
,
1881 adapter
->rx_ring
->itr_register
= E1000_EITR_82574(vector
);
1882 adapter
->rx_ring
->itr_val
= adapter
->itr
;
1885 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
1886 snprintf(adapter
->tx_ring
->name
,
1887 sizeof(adapter
->tx_ring
->name
) - 1,
1888 "%s-tx-0", netdev
->name
);
1890 memcpy(adapter
->tx_ring
->name
, netdev
->name
, IFNAMSIZ
);
1891 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1892 e1000_intr_msix_tx
, 0, adapter
->tx_ring
->name
,
1896 adapter
->tx_ring
->itr_register
= E1000_EITR_82574(vector
);
1897 adapter
->tx_ring
->itr_val
= adapter
->itr
;
1900 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1901 e1000_msix_other
, 0, netdev
->name
, netdev
);
1905 e1000_configure_msix(adapter
);
1912 * e1000_request_irq - initialize interrupts
1914 * Attempts to configure interrupts using the best available
1915 * capabilities of the hardware and kernel.
1917 static int e1000_request_irq(struct e1000_adapter
*adapter
)
1919 struct net_device
*netdev
= adapter
->netdev
;
1922 if (adapter
->msix_entries
) {
1923 err
= e1000_request_msix(adapter
);
1926 /* fall back to MSI */
1927 e1000e_reset_interrupt_capability(adapter
);
1928 adapter
->int_mode
= E1000E_INT_MODE_MSI
;
1929 e1000e_set_interrupt_capability(adapter
);
1931 if (adapter
->flags
& FLAG_MSI_ENABLED
) {
1932 err
= request_irq(adapter
->pdev
->irq
, e1000_intr_msi
, 0,
1933 netdev
->name
, netdev
);
1937 /* fall back to legacy interrupt */
1938 e1000e_reset_interrupt_capability(adapter
);
1939 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
1942 err
= request_irq(adapter
->pdev
->irq
, e1000_intr
, IRQF_SHARED
,
1943 netdev
->name
, netdev
);
1945 e_err("Unable to allocate interrupt, Error: %d\n", err
);
1950 static void e1000_free_irq(struct e1000_adapter
*adapter
)
1952 struct net_device
*netdev
= adapter
->netdev
;
1954 if (adapter
->msix_entries
) {
1957 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
1960 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
1963 /* Other Causes interrupt vector */
1964 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
1968 free_irq(adapter
->pdev
->irq
, netdev
);
1972 * e1000_irq_disable - Mask off interrupt generation on the NIC
1974 static void e1000_irq_disable(struct e1000_adapter
*adapter
)
1976 struct e1000_hw
*hw
= &adapter
->hw
;
1979 if (adapter
->msix_entries
)
1980 ew32(EIAC_82574
, 0);
1983 if (adapter
->msix_entries
) {
1985 for (i
= 0; i
< adapter
->num_vectors
; i
++)
1986 synchronize_irq(adapter
->msix_entries
[i
].vector
);
1988 synchronize_irq(adapter
->pdev
->irq
);
1993 * e1000_irq_enable - Enable default interrupt generation settings
1995 static void e1000_irq_enable(struct e1000_adapter
*adapter
)
1997 struct e1000_hw
*hw
= &adapter
->hw
;
1999 if (adapter
->msix_entries
) {
2000 ew32(EIAC_82574
, adapter
->eiac_mask
& E1000_EIAC_MASK_82574
);
2001 ew32(IMS
, adapter
->eiac_mask
| E1000_IMS_OTHER
| E1000_IMS_LSC
);
2003 ew32(IMS
, IMS_ENABLE_MASK
);
2009 * e1000e_get_hw_control - get control of the h/w from f/w
2010 * @adapter: address of board private structure
2012 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2013 * For ASF and Pass Through versions of f/w this means that
2014 * the driver is loaded. For AMT version (only with 82573)
2015 * of the f/w this means that the network i/f is open.
2017 void e1000e_get_hw_control(struct e1000_adapter
*adapter
)
2019 struct e1000_hw
*hw
= &adapter
->hw
;
2023 /* Let firmware know the driver has taken over */
2024 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
2026 ew32(SWSM
, swsm
| E1000_SWSM_DRV_LOAD
);
2027 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
2028 ctrl_ext
= er32(CTRL_EXT
);
2029 ew32(CTRL_EXT
, ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
2034 * e1000e_release_hw_control - release control of the h/w to f/w
2035 * @adapter: address of board private structure
2037 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2038 * For ASF and Pass Through versions of f/w this means that the
2039 * driver is no longer loaded. For AMT version (only with 82573) i
2040 * of the f/w this means that the network i/f is closed.
2043 void e1000e_release_hw_control(struct e1000_adapter
*adapter
)
2045 struct e1000_hw
*hw
= &adapter
->hw
;
2049 /* Let firmware taken over control of h/w */
2050 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
2052 ew32(SWSM
, swsm
& ~E1000_SWSM_DRV_LOAD
);
2053 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
2054 ctrl_ext
= er32(CTRL_EXT
);
2055 ew32(CTRL_EXT
, ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
2060 * @e1000_alloc_ring - allocate memory for a ring structure
2062 static int e1000_alloc_ring_dma(struct e1000_adapter
*adapter
,
2063 struct e1000_ring
*ring
)
2065 struct pci_dev
*pdev
= adapter
->pdev
;
2067 ring
->desc
= dma_alloc_coherent(&pdev
->dev
, ring
->size
, &ring
->dma
,
2076 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2077 * @adapter: board private structure
2079 * Return 0 on success, negative on failure
2081 int e1000e_setup_tx_resources(struct e1000_adapter
*adapter
)
2083 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2084 int err
= -ENOMEM
, size
;
2086 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
2087 tx_ring
->buffer_info
= vzalloc(size
);
2088 if (!tx_ring
->buffer_info
)
2091 /* round up to nearest 4K */
2092 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
2093 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
2095 err
= e1000_alloc_ring_dma(adapter
, tx_ring
);
2099 tx_ring
->next_to_use
= 0;
2100 tx_ring
->next_to_clean
= 0;
2104 vfree(tx_ring
->buffer_info
);
2105 e_err("Unable to allocate memory for the transmit descriptor ring\n");
2110 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2111 * @adapter: board private structure
2113 * Returns 0 on success, negative on failure
2115 int e1000e_setup_rx_resources(struct e1000_adapter
*adapter
)
2117 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
2118 struct e1000_buffer
*buffer_info
;
2119 int i
, size
, desc_len
, err
= -ENOMEM
;
2121 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2122 rx_ring
->buffer_info
= vzalloc(size
);
2123 if (!rx_ring
->buffer_info
)
2126 for (i
= 0; i
< rx_ring
->count
; i
++) {
2127 buffer_info
= &rx_ring
->buffer_info
[i
];
2128 buffer_info
->ps_pages
= kcalloc(PS_PAGE_BUFFERS
,
2129 sizeof(struct e1000_ps_page
),
2131 if (!buffer_info
->ps_pages
)
2135 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
2137 /* Round up to nearest 4K */
2138 rx_ring
->size
= rx_ring
->count
* desc_len
;
2139 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
2141 err
= e1000_alloc_ring_dma(adapter
, rx_ring
);
2145 rx_ring
->next_to_clean
= 0;
2146 rx_ring
->next_to_use
= 0;
2147 rx_ring
->rx_skb_top
= NULL
;
2152 for (i
= 0; i
< rx_ring
->count
; i
++) {
2153 buffer_info
= &rx_ring
->buffer_info
[i
];
2154 kfree(buffer_info
->ps_pages
);
2157 vfree(rx_ring
->buffer_info
);
2158 e_err("Unable to allocate memory for the receive descriptor ring\n");
2163 * e1000_clean_tx_ring - Free Tx Buffers
2164 * @adapter: board private structure
2166 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
)
2168 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2169 struct e1000_buffer
*buffer_info
;
2173 for (i
= 0; i
< tx_ring
->count
; i
++) {
2174 buffer_info
= &tx_ring
->buffer_info
[i
];
2175 e1000_put_txbuf(adapter
, buffer_info
);
2178 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
2179 memset(tx_ring
->buffer_info
, 0, size
);
2181 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2183 tx_ring
->next_to_use
= 0;
2184 tx_ring
->next_to_clean
= 0;
2186 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
2187 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
2191 * e1000e_free_tx_resources - Free Tx Resources per Queue
2192 * @adapter: board private structure
2194 * Free all transmit software resources
2196 void e1000e_free_tx_resources(struct e1000_adapter
*adapter
)
2198 struct pci_dev
*pdev
= adapter
->pdev
;
2199 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2201 e1000_clean_tx_ring(adapter
);
2203 vfree(tx_ring
->buffer_info
);
2204 tx_ring
->buffer_info
= NULL
;
2206 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
2208 tx_ring
->desc
= NULL
;
2212 * e1000e_free_rx_resources - Free Rx Resources
2213 * @adapter: board private structure
2215 * Free all receive software resources
2218 void e1000e_free_rx_resources(struct e1000_adapter
*adapter
)
2220 struct pci_dev
*pdev
= adapter
->pdev
;
2221 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
2224 e1000_clean_rx_ring(adapter
);
2226 for (i
= 0; i
< rx_ring
->count
; i
++)
2227 kfree(rx_ring
->buffer_info
[i
].ps_pages
);
2229 vfree(rx_ring
->buffer_info
);
2230 rx_ring
->buffer_info
= NULL
;
2232 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
2234 rx_ring
->desc
= NULL
;
2238 * e1000_update_itr - update the dynamic ITR value based on statistics
2239 * @adapter: pointer to adapter
2240 * @itr_setting: current adapter->itr
2241 * @packets: the number of packets during this measurement interval
2242 * @bytes: the number of bytes during this measurement interval
2244 * Stores a new ITR value based on packets and byte
2245 * counts during the last interrupt. The advantage of per interrupt
2246 * computation is faster updates and more accurate ITR for the current
2247 * traffic pattern. Constants in this function were computed
2248 * based on theoretical maximum wire speed and thresholds were set based
2249 * on testing data as well as attempting to minimize response time
2250 * while increasing bulk throughput. This functionality is controlled
2251 * by the InterruptThrottleRate module parameter.
2253 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
2254 u16 itr_setting
, int packets
,
2257 unsigned int retval
= itr_setting
;
2260 goto update_itr_done
;
2262 switch (itr_setting
) {
2263 case lowest_latency
:
2264 /* handle TSO and jumbo frames */
2265 if (bytes
/packets
> 8000)
2266 retval
= bulk_latency
;
2267 else if ((packets
< 5) && (bytes
> 512))
2268 retval
= low_latency
;
2270 case low_latency
: /* 50 usec aka 20000 ints/s */
2271 if (bytes
> 10000) {
2272 /* this if handles the TSO accounting */
2273 if (bytes
/packets
> 8000)
2274 retval
= bulk_latency
;
2275 else if ((packets
< 10) || ((bytes
/packets
) > 1200))
2276 retval
= bulk_latency
;
2277 else if ((packets
> 35))
2278 retval
= lowest_latency
;
2279 } else if (bytes
/packets
> 2000) {
2280 retval
= bulk_latency
;
2281 } else if (packets
<= 2 && bytes
< 512) {
2282 retval
= lowest_latency
;
2285 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2286 if (bytes
> 25000) {
2288 retval
= low_latency
;
2289 } else if (bytes
< 6000) {
2290 retval
= low_latency
;
2299 static void e1000_set_itr(struct e1000_adapter
*adapter
)
2301 struct e1000_hw
*hw
= &adapter
->hw
;
2303 u32 new_itr
= adapter
->itr
;
2305 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2306 if (adapter
->link_speed
!= SPEED_1000
) {
2312 if (adapter
->flags2
& FLAG2_DISABLE_AIM
) {
2317 adapter
->tx_itr
= e1000_update_itr(adapter
,
2319 adapter
->total_tx_packets
,
2320 adapter
->total_tx_bytes
);
2321 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2322 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
2323 adapter
->tx_itr
= low_latency
;
2325 adapter
->rx_itr
= e1000_update_itr(adapter
,
2327 adapter
->total_rx_packets
,
2328 adapter
->total_rx_bytes
);
2329 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2330 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
2331 adapter
->rx_itr
= low_latency
;
2333 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2335 switch (current_itr
) {
2336 /* counts and packets in update_itr are dependent on these numbers */
2337 case lowest_latency
:
2341 new_itr
= 20000; /* aka hwitr = ~200 */
2351 if (new_itr
!= adapter
->itr
) {
2353 * this attempts to bias the interrupt rate towards Bulk
2354 * by adding intermediate steps when interrupt rate is
2357 new_itr
= new_itr
> adapter
->itr
?
2358 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2360 adapter
->itr
= new_itr
;
2361 adapter
->rx_ring
->itr_val
= new_itr
;
2362 if (adapter
->msix_entries
)
2363 adapter
->rx_ring
->set_itr
= 1;
2366 ew32(ITR
, 1000000000 / (new_itr
* 256));
2373 * e1000_alloc_queues - Allocate memory for all rings
2374 * @adapter: board private structure to initialize
2376 static int __devinit
e1000_alloc_queues(struct e1000_adapter
*adapter
)
2378 adapter
->tx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
2379 if (!adapter
->tx_ring
)
2382 adapter
->rx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
2383 if (!adapter
->rx_ring
)
2388 e_err("Unable to allocate memory for queues\n");
2389 kfree(adapter
->rx_ring
);
2390 kfree(adapter
->tx_ring
);
2395 * e1000_clean - NAPI Rx polling callback
2396 * @napi: struct associated with this polling callback
2397 * @budget: amount of packets driver is allowed to process this poll
2399 static int e1000_clean(struct napi_struct
*napi
, int budget
)
2401 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
, napi
);
2402 struct e1000_hw
*hw
= &adapter
->hw
;
2403 struct net_device
*poll_dev
= adapter
->netdev
;
2404 int tx_cleaned
= 1, work_done
= 0;
2406 adapter
= netdev_priv(poll_dev
);
2408 if (adapter
->msix_entries
&&
2409 !(adapter
->rx_ring
->ims_val
& adapter
->tx_ring
->ims_val
))
2412 tx_cleaned
= e1000_clean_tx_irq(adapter
);
2415 adapter
->clean_rx(adapter
, &work_done
, budget
);
2420 /* If budget not fully consumed, exit the polling mode */
2421 if (work_done
< budget
) {
2422 if (adapter
->itr_setting
& 3)
2423 e1000_set_itr(adapter
);
2424 napi_complete(napi
);
2425 if (!test_bit(__E1000_DOWN
, &adapter
->state
)) {
2426 if (adapter
->msix_entries
)
2427 ew32(IMS
, adapter
->rx_ring
->ims_val
);
2429 e1000_irq_enable(adapter
);
2436 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
2438 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2439 struct e1000_hw
*hw
= &adapter
->hw
;
2442 /* don't update vlan cookie if already programmed */
2443 if ((adapter
->hw
.mng_cookie
.status
&
2444 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
2445 (vid
== adapter
->mng_vlan_id
))
2448 /* add VID to filter table */
2449 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2450 index
= (vid
>> 5) & 0x7F;
2451 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
2452 vfta
|= (1 << (vid
& 0x1F));
2453 hw
->mac
.ops
.write_vfta(hw
, index
, vfta
);
2456 set_bit(vid
, adapter
->active_vlans
);
2459 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
2461 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2462 struct e1000_hw
*hw
= &adapter
->hw
;
2465 if ((adapter
->hw
.mng_cookie
.status
&
2466 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
2467 (vid
== adapter
->mng_vlan_id
)) {
2468 /* release control to f/w */
2469 e1000e_release_hw_control(adapter
);
2473 /* remove VID from filter table */
2474 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2475 index
= (vid
>> 5) & 0x7F;
2476 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
2477 vfta
&= ~(1 << (vid
& 0x1F));
2478 hw
->mac
.ops
.write_vfta(hw
, index
, vfta
);
2481 clear_bit(vid
, adapter
->active_vlans
);
2485 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2486 * @adapter: board private structure to initialize
2488 static void e1000e_vlan_filter_disable(struct e1000_adapter
*adapter
)
2490 struct net_device
*netdev
= adapter
->netdev
;
2491 struct e1000_hw
*hw
= &adapter
->hw
;
2494 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2495 /* disable VLAN receive filtering */
2497 rctl
&= ~(E1000_RCTL_VFE
| E1000_RCTL_CFIEN
);
2500 if (adapter
->mng_vlan_id
!= (u16
)E1000_MNG_VLAN_NONE
) {
2501 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
2502 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
2508 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2509 * @adapter: board private structure to initialize
2511 static void e1000e_vlan_filter_enable(struct e1000_adapter
*adapter
)
2513 struct e1000_hw
*hw
= &adapter
->hw
;
2516 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2517 /* enable VLAN receive filtering */
2519 rctl
|= E1000_RCTL_VFE
;
2520 rctl
&= ~E1000_RCTL_CFIEN
;
2526 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2527 * @adapter: board private structure to initialize
2529 static void e1000e_vlan_strip_disable(struct e1000_adapter
*adapter
)
2531 struct e1000_hw
*hw
= &adapter
->hw
;
2534 /* disable VLAN tag insert/strip */
2536 ctrl
&= ~E1000_CTRL_VME
;
2541 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2542 * @adapter: board private structure to initialize
2544 static void e1000e_vlan_strip_enable(struct e1000_adapter
*adapter
)
2546 struct e1000_hw
*hw
= &adapter
->hw
;
2549 /* enable VLAN tag insert/strip */
2551 ctrl
|= E1000_CTRL_VME
;
2555 static void e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
2557 struct net_device
*netdev
= adapter
->netdev
;
2558 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
2559 u16 old_vid
= adapter
->mng_vlan_id
;
2561 if (adapter
->hw
.mng_cookie
.status
&
2562 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) {
2563 e1000_vlan_rx_add_vid(netdev
, vid
);
2564 adapter
->mng_vlan_id
= vid
;
2567 if ((old_vid
!= (u16
)E1000_MNG_VLAN_NONE
) && (vid
!= old_vid
))
2568 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
2571 static void e1000_restore_vlan(struct e1000_adapter
*adapter
)
2575 e1000_vlan_rx_add_vid(adapter
->netdev
, 0);
2577 for_each_set_bit(vid
, adapter
->active_vlans
, VLAN_N_VID
)
2578 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
2581 static void e1000_init_manageability_pt(struct e1000_adapter
*adapter
)
2583 struct e1000_hw
*hw
= &adapter
->hw
;
2584 u32 manc
, manc2h
, mdef
, i
, j
;
2586 if (!(adapter
->flags
& FLAG_MNG_PT_ENABLED
))
2592 * enable receiving management packets to the host. this will probably
2593 * generate destination unreachable messages from the host OS, but
2594 * the packets will be handled on SMBUS
2596 manc
|= E1000_MANC_EN_MNG2HOST
;
2597 manc2h
= er32(MANC2H
);
2599 switch (hw
->mac
.type
) {
2601 manc2h
|= (E1000_MANC2H_PORT_623
| E1000_MANC2H_PORT_664
);
2606 * Check if IPMI pass-through decision filter already exists;
2609 for (i
= 0, j
= 0; i
< 8; i
++) {
2610 mdef
= er32(MDEF(i
));
2612 /* Ignore filters with anything other than IPMI ports */
2613 if (mdef
& ~(E1000_MDEF_PORT_623
| E1000_MDEF_PORT_664
))
2616 /* Enable this decision filter in MANC2H */
2623 if (j
== (E1000_MDEF_PORT_623
| E1000_MDEF_PORT_664
))
2626 /* Create new decision filter in an empty filter */
2627 for (i
= 0, j
= 0; i
< 8; i
++)
2628 if (er32(MDEF(i
)) == 0) {
2629 ew32(MDEF(i
), (E1000_MDEF_PORT_623
|
2630 E1000_MDEF_PORT_664
));
2637 e_warn("Unable to create IPMI pass-through filter\n");
2641 ew32(MANC2H
, manc2h
);
2646 * e1000_configure_tx - Configure Transmit Unit after Reset
2647 * @adapter: board private structure
2649 * Configure the Tx unit of the MAC after a reset.
2651 static void e1000_configure_tx(struct e1000_adapter
*adapter
)
2653 struct e1000_hw
*hw
= &adapter
->hw
;
2654 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2656 u32 tdlen
, tctl
, tipg
, tarc
;
2659 /* Setup the HW Tx Head and Tail descriptor pointers */
2660 tdba
= tx_ring
->dma
;
2661 tdlen
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
2662 ew32(TDBAL
, (tdba
& DMA_BIT_MASK(32)));
2663 ew32(TDBAH
, (tdba
>> 32));
2667 tx_ring
->head
= E1000_TDH
;
2668 tx_ring
->tail
= E1000_TDT
;
2670 /* Set the default values for the Tx Inter Packet Gap timer */
2671 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
; /* 8 */
2672 ipgr1
= DEFAULT_82543_TIPG_IPGR1
; /* 8 */
2673 ipgr2
= DEFAULT_82543_TIPG_IPGR2
; /* 6 */
2675 if (adapter
->flags
& FLAG_TIPG_MEDIUM_FOR_80003ESLAN
)
2676 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
; /* 7 */
2678 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
2679 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
2682 /* Set the Tx Interrupt Delay register */
2683 ew32(TIDV
, adapter
->tx_int_delay
);
2684 /* Tx irq moderation */
2685 ew32(TADV
, adapter
->tx_abs_int_delay
);
2687 if (adapter
->flags2
& FLAG2_DMA_BURST
) {
2688 u32 txdctl
= er32(TXDCTL(0));
2689 txdctl
&= ~(E1000_TXDCTL_PTHRESH
| E1000_TXDCTL_HTHRESH
|
2690 E1000_TXDCTL_WTHRESH
);
2692 * set up some performance related parameters to encourage the
2693 * hardware to use the bus more efficiently in bursts, depends
2694 * on the tx_int_delay to be enabled,
2695 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2696 * hthresh = 1 ==> prefetch when one or more available
2697 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2698 * BEWARE: this seems to work but should be considered first if
2699 * there are Tx hangs or other Tx related bugs
2701 txdctl
|= E1000_TXDCTL_DMA_BURST_ENABLE
;
2702 ew32(TXDCTL(0), txdctl
);
2703 /* erratum work around: set txdctl the same for both queues */
2704 ew32(TXDCTL(1), txdctl
);
2707 /* Program the Transmit Control Register */
2709 tctl
&= ~E1000_TCTL_CT
;
2710 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
2711 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
2713 if (adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) {
2714 tarc
= er32(TARC(0));
2716 * set the speed mode bit, we'll clear it if we're not at
2717 * gigabit link later
2719 #define SPEED_MODE_BIT (1 << 21)
2720 tarc
|= SPEED_MODE_BIT
;
2721 ew32(TARC(0), tarc
);
2724 /* errata: program both queues to unweighted RR */
2725 if (adapter
->flags
& FLAG_TARC_SET_BIT_ZERO
) {
2726 tarc
= er32(TARC(0));
2728 ew32(TARC(0), tarc
);
2729 tarc
= er32(TARC(1));
2731 ew32(TARC(1), tarc
);
2734 /* Setup Transmit Descriptor Settings for eop descriptor */
2735 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
2737 /* only set IDE if we are delaying interrupts using the timers */
2738 if (adapter
->tx_int_delay
)
2739 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
2741 /* enable Report Status bit */
2742 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
2746 e1000e_config_collision_dist(hw
);
2750 * e1000_setup_rctl - configure the receive control registers
2751 * @adapter: Board private structure
2753 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2754 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2755 static void e1000_setup_rctl(struct e1000_adapter
*adapter
)
2757 struct e1000_hw
*hw
= &adapter
->hw
;
2761 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2762 if (hw
->mac
.type
== e1000_pch2lan
) {
2765 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
)
2766 ret_val
= e1000_lv_jumbo_workaround_ich8lan(hw
, true);
2768 ret_val
= e1000_lv_jumbo_workaround_ich8lan(hw
, false);
2771 e_dbg("failed to enable jumbo frame workaround mode\n");
2774 /* Program MC offset vector base */
2776 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
2777 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
2778 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
2779 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
2781 /* Do not Store bad packets */
2782 rctl
&= ~E1000_RCTL_SBP
;
2784 /* Enable Long Packet receive */
2785 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
2786 rctl
&= ~E1000_RCTL_LPE
;
2788 rctl
|= E1000_RCTL_LPE
;
2790 /* Some systems expect that the CRC is included in SMBUS traffic. The
2791 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2792 * host memory when this is enabled
2794 if (adapter
->flags2
& FLAG2_CRC_STRIPPING
)
2795 rctl
|= E1000_RCTL_SECRC
;
2797 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2798 if ((hw
->phy
.type
== e1000_phy_82577
) && (rctl
& E1000_RCTL_LPE
)) {
2801 e1e_rphy(hw
, PHY_REG(770, 26), &phy_data
);
2803 phy_data
|= (1 << 2);
2804 e1e_wphy(hw
, PHY_REG(770, 26), phy_data
);
2806 e1e_rphy(hw
, 22, &phy_data
);
2808 phy_data
|= (1 << 14);
2809 e1e_wphy(hw
, 0x10, 0x2823);
2810 e1e_wphy(hw
, 0x11, 0x0003);
2811 e1e_wphy(hw
, 22, phy_data
);
2814 /* Setup buffer sizes */
2815 rctl
&= ~E1000_RCTL_SZ_4096
;
2816 rctl
|= E1000_RCTL_BSEX
;
2817 switch (adapter
->rx_buffer_len
) {
2820 rctl
|= E1000_RCTL_SZ_2048
;
2821 rctl
&= ~E1000_RCTL_BSEX
;
2824 rctl
|= E1000_RCTL_SZ_4096
;
2827 rctl
|= E1000_RCTL_SZ_8192
;
2830 rctl
|= E1000_RCTL_SZ_16384
;
2835 * 82571 and greater support packet-split where the protocol
2836 * header is placed in skb->data and the packet data is
2837 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2838 * In the case of a non-split, skb->data is linearly filled,
2839 * followed by the page buffers. Therefore, skb->data is
2840 * sized to hold the largest protocol header.
2842 * allocations using alloc_page take too long for regular MTU
2843 * so only enable packet split for jumbo frames
2845 * Using pages when the page size is greater than 16k wastes
2846 * a lot of memory, since we allocate 3 pages at all times
2849 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
2850 if (!(adapter
->flags
& FLAG_HAS_ERT
) && (pages
<= 3) &&
2851 (PAGE_SIZE
<= 16384) && (rctl
& E1000_RCTL_LPE
))
2852 adapter
->rx_ps_pages
= pages
;
2854 adapter
->rx_ps_pages
= 0;
2856 if (adapter
->rx_ps_pages
) {
2859 /* Configure extra packet-split registers */
2860 rfctl
= er32(RFCTL
);
2861 rfctl
|= E1000_RFCTL_EXTEN
;
2863 * disable packet split support for IPv6 extension headers,
2864 * because some malformed IPv6 headers can hang the Rx
2866 rfctl
|= (E1000_RFCTL_IPV6_EX_DIS
|
2867 E1000_RFCTL_NEW_IPV6_EXT_DIS
);
2871 /* Enable Packet split descriptors */
2872 rctl
|= E1000_RCTL_DTYP_PS
;
2874 psrctl
|= adapter
->rx_ps_bsize0
>>
2875 E1000_PSRCTL_BSIZE0_SHIFT
;
2877 switch (adapter
->rx_ps_pages
) {
2879 psrctl
|= PAGE_SIZE
<<
2880 E1000_PSRCTL_BSIZE3_SHIFT
;
2882 psrctl
|= PAGE_SIZE
<<
2883 E1000_PSRCTL_BSIZE2_SHIFT
;
2885 psrctl
|= PAGE_SIZE
>>
2886 E1000_PSRCTL_BSIZE1_SHIFT
;
2890 ew32(PSRCTL
, psrctl
);
2894 /* just started the receive unit, no need to restart */
2895 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
2899 * e1000_configure_rx - Configure Receive Unit after Reset
2900 * @adapter: board private structure
2902 * Configure the Rx unit of the MAC after a reset.
2904 static void e1000_configure_rx(struct e1000_adapter
*adapter
)
2906 struct e1000_hw
*hw
= &adapter
->hw
;
2907 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
2909 u32 rdlen
, rctl
, rxcsum
, ctrl_ext
;
2911 if (adapter
->rx_ps_pages
) {
2912 /* this is a 32 byte descriptor */
2913 rdlen
= rx_ring
->count
*
2914 sizeof(union e1000_rx_desc_packet_split
);
2915 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
2916 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
2917 } else if (adapter
->netdev
->mtu
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
2918 rdlen
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
2919 adapter
->clean_rx
= e1000_clean_jumbo_rx_irq
;
2920 adapter
->alloc_rx_buf
= e1000_alloc_jumbo_rx_buffers
;
2922 rdlen
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
2923 adapter
->clean_rx
= e1000_clean_rx_irq
;
2924 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
2927 /* disable receives while setting up the descriptors */
2929 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
2931 usleep_range(10000, 20000);
2933 if (adapter
->flags2
& FLAG2_DMA_BURST
) {
2935 * set the writeback threshold (only takes effect if the RDTR
2936 * is set). set GRAN=1 and write back up to 0x4 worth, and
2937 * enable prefetching of 0x20 Rx descriptors
2943 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE
);
2944 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE
);
2947 * override the delay timers for enabling bursting, only if
2948 * the value was not set by the user via module options
2950 if (adapter
->rx_int_delay
== DEFAULT_RDTR
)
2951 adapter
->rx_int_delay
= BURST_RDTR
;
2952 if (adapter
->rx_abs_int_delay
== DEFAULT_RADV
)
2953 adapter
->rx_abs_int_delay
= BURST_RADV
;
2956 /* set the Receive Delay Timer Register */
2957 ew32(RDTR
, adapter
->rx_int_delay
);
2959 /* irq moderation */
2960 ew32(RADV
, adapter
->rx_abs_int_delay
);
2961 if ((adapter
->itr_setting
!= 0) && (adapter
->itr
!= 0))
2962 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
2964 ctrl_ext
= er32(CTRL_EXT
);
2965 /* Auto-Mask interrupts upon ICR access */
2966 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
2967 ew32(IAM
, 0xffffffff);
2968 ew32(CTRL_EXT
, ctrl_ext
);
2972 * Setup the HW Rx Head and Tail Descriptor Pointers and
2973 * the Base and Length of the Rx Descriptor Ring
2975 rdba
= rx_ring
->dma
;
2976 ew32(RDBAL
, (rdba
& DMA_BIT_MASK(32)));
2977 ew32(RDBAH
, (rdba
>> 32));
2981 rx_ring
->head
= E1000_RDH
;
2982 rx_ring
->tail
= E1000_RDT
;
2984 /* Enable Receive Checksum Offload for TCP and UDP */
2985 rxcsum
= er32(RXCSUM
);
2986 if (adapter
->flags
& FLAG_RX_CSUM_ENABLED
) {
2987 rxcsum
|= E1000_RXCSUM_TUOFL
;
2990 * IPv4 payload checksum for UDP fragments must be
2991 * used in conjunction with packet-split.
2993 if (adapter
->rx_ps_pages
)
2994 rxcsum
|= E1000_RXCSUM_IPPCSE
;
2996 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
2997 /* no need to clear IPPCSE as it defaults to 0 */
2999 ew32(RXCSUM
, rxcsum
);
3002 * Enable early receives on supported devices, only takes effect when
3003 * packet size is equal or larger than the specified value (in 8 byte
3004 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
3006 if ((adapter
->flags
& FLAG_HAS_ERT
) ||
3007 (adapter
->hw
.mac
.type
== e1000_pch2lan
)) {
3008 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
3009 u32 rxdctl
= er32(RXDCTL(0));
3010 ew32(RXDCTL(0), rxdctl
| 0x3);
3011 if (adapter
->flags
& FLAG_HAS_ERT
)
3012 ew32(ERT
, E1000_ERT_2048
| (1 << 13));
3014 * With jumbo frames and early-receive enabled,
3015 * excessive C-state transition latencies result in
3016 * dropped transactions.
3018 pm_qos_update_request(&adapter
->netdev
->pm_qos_req
, 55);
3020 pm_qos_update_request(&adapter
->netdev
->pm_qos_req
,
3021 PM_QOS_DEFAULT_VALUE
);
3025 /* Enable Receives */
3030 * e1000_update_mc_addr_list - Update Multicast addresses
3031 * @hw: pointer to the HW structure
3032 * @mc_addr_list: array of multicast addresses to program
3033 * @mc_addr_count: number of multicast addresses to program
3035 * Updates the Multicast Table Array.
3036 * The caller must have a packed mc_addr_list of multicast addresses.
3038 static void e1000_update_mc_addr_list(struct e1000_hw
*hw
, u8
*mc_addr_list
,
3041 hw
->mac
.ops
.update_mc_addr_list(hw
, mc_addr_list
, mc_addr_count
);
3045 * e1000_set_multi - Multicast and Promiscuous mode set
3046 * @netdev: network interface device structure
3048 * The set_multi entry point is called whenever the multicast address
3049 * list or the network interface flags are updated. This routine is
3050 * responsible for configuring the hardware for proper multicast,
3051 * promiscuous mode, and all-multi behavior.
3053 static void e1000_set_multi(struct net_device
*netdev
)
3055 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3056 struct e1000_hw
*hw
= &adapter
->hw
;
3057 struct netdev_hw_addr
*ha
;
3061 /* Check for Promiscuous and All Multicast modes */
3065 if (netdev
->flags
& IFF_PROMISC
) {
3066 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
3067 rctl
&= ~E1000_RCTL_VFE
;
3068 /* Do not hardware filter VLANs in promisc mode */
3069 e1000e_vlan_filter_disable(adapter
);
3071 if (netdev
->flags
& IFF_ALLMULTI
) {
3072 rctl
|= E1000_RCTL_MPE
;
3073 rctl
&= ~E1000_RCTL_UPE
;
3075 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
3077 e1000e_vlan_filter_enable(adapter
);
3082 if (!netdev_mc_empty(netdev
)) {
3085 mta_list
= kmalloc(netdev_mc_count(netdev
) * 6, GFP_ATOMIC
);
3089 /* prepare a packed array of only addresses. */
3090 netdev_for_each_mc_addr(ha
, netdev
)
3091 memcpy(mta_list
+ (i
++ * ETH_ALEN
), ha
->addr
, ETH_ALEN
);
3093 e1000_update_mc_addr_list(hw
, mta_list
, i
);
3097 * if we're called from probe, we might not have
3098 * anything to do here, so clear out the list
3100 e1000_update_mc_addr_list(hw
, NULL
, 0);
3103 if (netdev
->features
& NETIF_F_HW_VLAN_RX
)
3104 e1000e_vlan_strip_enable(adapter
);
3106 e1000e_vlan_strip_disable(adapter
);
3110 * e1000_configure - configure the hardware for Rx and Tx
3111 * @adapter: private board structure
3113 static void e1000_configure(struct e1000_adapter
*adapter
)
3115 e1000_set_multi(adapter
->netdev
);
3117 e1000_restore_vlan(adapter
);
3118 e1000_init_manageability_pt(adapter
);
3120 e1000_configure_tx(adapter
);
3121 e1000_setup_rctl(adapter
);
3122 e1000_configure_rx(adapter
);
3123 adapter
->alloc_rx_buf(adapter
, e1000_desc_unused(adapter
->rx_ring
));
3127 * e1000e_power_up_phy - restore link in case the phy was powered down
3128 * @adapter: address of board private structure
3130 * The phy may be powered down to save power and turn off link when the
3131 * driver is unloaded and wake on lan is not enabled (among others)
3132 * *** this routine MUST be followed by a call to e1000e_reset ***
3134 void e1000e_power_up_phy(struct e1000_adapter
*adapter
)
3136 if (adapter
->hw
.phy
.ops
.power_up
)
3137 adapter
->hw
.phy
.ops
.power_up(&adapter
->hw
);
3139 adapter
->hw
.mac
.ops
.setup_link(&adapter
->hw
);
3143 * e1000_power_down_phy - Power down the PHY
3145 * Power down the PHY so no link is implied when interface is down.
3146 * The PHY cannot be powered down if management or WoL is active.
3148 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
3150 /* WoL is enabled */
3154 if (adapter
->hw
.phy
.ops
.power_down
)
3155 adapter
->hw
.phy
.ops
.power_down(&adapter
->hw
);
3159 * e1000e_reset - bring the hardware into a known good state
3161 * This function boots the hardware and enables some settings that
3162 * require a configuration cycle of the hardware - those cannot be
3163 * set/changed during runtime. After reset the device needs to be
3164 * properly configured for Rx, Tx etc.
3166 void e1000e_reset(struct e1000_adapter
*adapter
)
3168 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
3169 struct e1000_fc_info
*fc
= &adapter
->hw
.fc
;
3170 struct e1000_hw
*hw
= &adapter
->hw
;
3171 u32 tx_space
, min_tx_space
, min_rx_space
;
3172 u32 pba
= adapter
->pba
;
3175 /* reset Packet Buffer Allocation to default */
3178 if (adapter
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
3180 * To maintain wire speed transmits, the Tx FIFO should be
3181 * large enough to accommodate two full transmit packets,
3182 * rounded up to the next 1KB and expressed in KB. Likewise,
3183 * the Rx FIFO should be large enough to accommodate at least
3184 * one full receive packet and is similarly rounded up and
3188 /* upper 16 bits has Tx packet buffer allocation size in KB */
3189 tx_space
= pba
>> 16;
3190 /* lower 16 bits has Rx packet buffer allocation size in KB */
3193 * the Tx fifo also stores 16 bytes of information about the Tx
3194 * but don't include ethernet FCS because hardware appends it
3196 min_tx_space
= (adapter
->max_frame_size
+
3197 sizeof(struct e1000_tx_desc
) -
3199 min_tx_space
= ALIGN(min_tx_space
, 1024);
3200 min_tx_space
>>= 10;
3201 /* software strips receive CRC, so leave room for it */
3202 min_rx_space
= adapter
->max_frame_size
;
3203 min_rx_space
= ALIGN(min_rx_space
, 1024);
3204 min_rx_space
>>= 10;
3207 * If current Tx allocation is less than the min Tx FIFO size,
3208 * and the min Tx FIFO size is less than the current Rx FIFO
3209 * allocation, take space away from current Rx allocation
3211 if ((tx_space
< min_tx_space
) &&
3212 ((min_tx_space
- tx_space
) < pba
)) {
3213 pba
-= min_tx_space
- tx_space
;
3216 * if short on Rx space, Rx wins and must trump Tx
3217 * adjustment or use Early Receive if available
3219 if ((pba
< min_rx_space
) &&
3220 (!(adapter
->flags
& FLAG_HAS_ERT
)))
3221 /* ERT enabled in e1000_configure_rx */
3229 * flow control settings
3231 * The high water mark must be low enough to fit one full frame
3232 * (or the size used for early receive) above it in the Rx FIFO.
3233 * Set it to the lower of:
3234 * - 90% of the Rx FIFO size, and
3235 * - the full Rx FIFO size minus the early receive size (for parts
3236 * with ERT support assuming ERT set to E1000_ERT_2048), or
3237 * - the full Rx FIFO size minus one full frame
3239 if (adapter
->flags
& FLAG_DISABLE_FC_PAUSE_TIME
)
3240 fc
->pause_time
= 0xFFFF;
3242 fc
->pause_time
= E1000_FC_PAUSE_TIME
;
3244 fc
->current_mode
= fc
->requested_mode
;
3246 switch (hw
->mac
.type
) {
3248 if ((adapter
->flags
& FLAG_HAS_ERT
) &&
3249 (adapter
->netdev
->mtu
> ETH_DATA_LEN
))
3250 hwm
= min(((pba
<< 10) * 9 / 10),
3251 ((pba
<< 10) - (E1000_ERT_2048
<< 3)));
3253 hwm
= min(((pba
<< 10) * 9 / 10),
3254 ((pba
<< 10) - adapter
->max_frame_size
));
3256 fc
->high_water
= hwm
& E1000_FCRTH_RTH
; /* 8-byte granularity */
3257 fc
->low_water
= fc
->high_water
- 8;
3261 * Workaround PCH LOM adapter hangs with certain network
3262 * loads. If hangs persist, try disabling Tx flow control.
3264 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
3265 fc
->high_water
= 0x3500;
3266 fc
->low_water
= 0x1500;
3268 fc
->high_water
= 0x5000;
3269 fc
->low_water
= 0x3000;
3271 fc
->refresh_time
= 0x1000;
3274 fc
->high_water
= 0x05C20;
3275 fc
->low_water
= 0x05048;
3276 fc
->pause_time
= 0x0650;
3277 fc
->refresh_time
= 0x0400;
3278 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
3286 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3287 * fit in receive buffer and early-receive not supported.
3289 if (adapter
->itr_setting
& 0x3) {
3290 if (((adapter
->max_frame_size
* 2) > (pba
<< 10)) &&
3291 !(adapter
->flags
& FLAG_HAS_ERT
)) {
3292 if (!(adapter
->flags2
& FLAG2_DISABLE_AIM
)) {
3293 dev_info(&adapter
->pdev
->dev
,
3294 "Interrupt Throttle Rate turned off\n");
3295 adapter
->flags2
|= FLAG2_DISABLE_AIM
;
3298 } else if (adapter
->flags2
& FLAG2_DISABLE_AIM
) {
3299 dev_info(&adapter
->pdev
->dev
,
3300 "Interrupt Throttle Rate turned on\n");
3301 adapter
->flags2
&= ~FLAG2_DISABLE_AIM
;
3302 adapter
->itr
= 20000;
3303 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
3307 /* Allow time for pending master requests to run */
3308 mac
->ops
.reset_hw(hw
);
3311 * For parts with AMT enabled, let the firmware know
3312 * that the network interface is in control
3314 if (adapter
->flags
& FLAG_HAS_AMT
)
3315 e1000e_get_hw_control(adapter
);
3319 if (mac
->ops
.init_hw(hw
))
3320 e_err("Hardware Error\n");
3322 e1000_update_mng_vlan(adapter
);
3324 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3325 ew32(VET
, ETH_P_8021Q
);
3327 e1000e_reset_adaptive(hw
);
3329 if (!netif_running(adapter
->netdev
) &&
3330 !test_bit(__E1000_TESTING
, &adapter
->state
)) {
3331 e1000_power_down_phy(adapter
);
3335 e1000_get_phy_info(hw
);
3337 if ((adapter
->flags
& FLAG_HAS_SMART_POWER_DOWN
) &&
3338 !(adapter
->flags
& FLAG_SMART_POWER_DOWN
)) {
3341 * speed up time to link by disabling smart power down, ignore
3342 * the return value of this function because there is nothing
3343 * different we would do if it failed
3345 e1e_rphy(hw
, IGP02E1000_PHY_POWER_MGMT
, &phy_data
);
3346 phy_data
&= ~IGP02E1000_PM_SPD
;
3347 e1e_wphy(hw
, IGP02E1000_PHY_POWER_MGMT
, phy_data
);
3351 int e1000e_up(struct e1000_adapter
*adapter
)
3353 struct e1000_hw
*hw
= &adapter
->hw
;
3355 /* hardware has been reset, we need to reload some things */
3356 e1000_configure(adapter
);
3358 clear_bit(__E1000_DOWN
, &adapter
->state
);
3360 napi_enable(&adapter
->napi
);
3361 if (adapter
->msix_entries
)
3362 e1000_configure_msix(adapter
);
3363 e1000_irq_enable(adapter
);
3365 netif_wake_queue(adapter
->netdev
);
3367 /* fire a link change interrupt to start the watchdog */
3368 if (adapter
->msix_entries
)
3369 ew32(ICS
, E1000_ICS_LSC
| E1000_ICR_OTHER
);
3371 ew32(ICS
, E1000_ICS_LSC
);
3376 static void e1000e_flush_descriptors(struct e1000_adapter
*adapter
)
3378 struct e1000_hw
*hw
= &adapter
->hw
;
3380 if (!(adapter
->flags2
& FLAG2_DMA_BURST
))
3383 /* flush pending descriptor writebacks to memory */
3384 ew32(TIDV
, adapter
->tx_int_delay
| E1000_TIDV_FPD
);
3385 ew32(RDTR
, adapter
->rx_int_delay
| E1000_RDTR_FPD
);
3387 /* execute the writes immediately */
3391 static void e1000e_update_stats(struct e1000_adapter
*adapter
);
3393 void e1000e_down(struct e1000_adapter
*adapter
)
3395 struct net_device
*netdev
= adapter
->netdev
;
3396 struct e1000_hw
*hw
= &adapter
->hw
;
3400 * signal that we're down so the interrupt handler does not
3401 * reschedule our watchdog timer
3403 set_bit(__E1000_DOWN
, &adapter
->state
);
3405 /* disable receives in the hardware */
3407 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
3408 /* flush and sleep below */
3410 netif_stop_queue(netdev
);
3412 /* disable transmits in the hardware */
3414 tctl
&= ~E1000_TCTL_EN
;
3416 /* flush both disables and wait for them to finish */
3418 usleep_range(10000, 20000);
3420 napi_disable(&adapter
->napi
);
3421 e1000_irq_disable(adapter
);
3423 del_timer_sync(&adapter
->watchdog_timer
);
3424 del_timer_sync(&adapter
->phy_info_timer
);
3426 netif_carrier_off(netdev
);
3428 spin_lock(&adapter
->stats64_lock
);
3429 e1000e_update_stats(adapter
);
3430 spin_unlock(&adapter
->stats64_lock
);
3432 adapter
->link_speed
= 0;
3433 adapter
->link_duplex
= 0;
3435 if (!pci_channel_offline(adapter
->pdev
))
3436 e1000e_reset(adapter
);
3438 e1000e_flush_descriptors(adapter
);
3440 e1000_clean_tx_ring(adapter
);
3441 e1000_clean_rx_ring(adapter
);
3444 * TODO: for power management, we could drop the link and
3445 * pci_disable_device here.
3449 void e1000e_reinit_locked(struct e1000_adapter
*adapter
)
3452 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
3453 usleep_range(1000, 2000);
3454 e1000e_down(adapter
);
3456 clear_bit(__E1000_RESETTING
, &adapter
->state
);
3460 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3461 * @adapter: board private structure to initialize
3463 * e1000_sw_init initializes the Adapter private data structure.
3464 * Fields are initialized based on PCI device information and
3465 * OS network device settings (MTU size).
3467 static int __devinit
e1000_sw_init(struct e1000_adapter
*adapter
)
3469 struct net_device
*netdev
= adapter
->netdev
;
3471 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
;
3472 adapter
->rx_ps_bsize0
= 128;
3473 adapter
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3474 adapter
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
3476 spin_lock_init(&adapter
->stats64_lock
);
3478 e1000e_set_interrupt_capability(adapter
);
3480 if (e1000_alloc_queues(adapter
))
3483 /* Explicitly disable IRQ since the NIC can be in any state. */
3484 e1000_irq_disable(adapter
);
3486 set_bit(__E1000_DOWN
, &adapter
->state
);
3491 * e1000_intr_msi_test - Interrupt Handler
3492 * @irq: interrupt number
3493 * @data: pointer to a network interface device structure
3495 static irqreturn_t
e1000_intr_msi_test(int irq
, void *data
)
3497 struct net_device
*netdev
= data
;
3498 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3499 struct e1000_hw
*hw
= &adapter
->hw
;
3500 u32 icr
= er32(ICR
);
3502 e_dbg("icr is %08X\n", icr
);
3503 if (icr
& E1000_ICR_RXSEQ
) {
3504 adapter
->flags
&= ~FLAG_MSI_TEST_FAILED
;
3512 * e1000_test_msi_interrupt - Returns 0 for successful test
3513 * @adapter: board private struct
3515 * code flow taken from tg3.c
3517 static int e1000_test_msi_interrupt(struct e1000_adapter
*adapter
)
3519 struct net_device
*netdev
= adapter
->netdev
;
3520 struct e1000_hw
*hw
= &adapter
->hw
;
3523 /* poll_enable hasn't been called yet, so don't need disable */
3524 /* clear any pending events */
3527 /* free the real vector and request a test handler */
3528 e1000_free_irq(adapter
);
3529 e1000e_reset_interrupt_capability(adapter
);
3531 /* Assume that the test fails, if it succeeds then the test
3532 * MSI irq handler will unset this flag */
3533 adapter
->flags
|= FLAG_MSI_TEST_FAILED
;
3535 err
= pci_enable_msi(adapter
->pdev
);
3537 goto msi_test_failed
;
3539 err
= request_irq(adapter
->pdev
->irq
, e1000_intr_msi_test
, 0,
3540 netdev
->name
, netdev
);
3542 pci_disable_msi(adapter
->pdev
);
3543 goto msi_test_failed
;
3548 e1000_irq_enable(adapter
);
3550 /* fire an unusual interrupt on the test handler */
3551 ew32(ICS
, E1000_ICS_RXSEQ
);
3555 e1000_irq_disable(adapter
);
3559 if (adapter
->flags
& FLAG_MSI_TEST_FAILED
) {
3560 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
3561 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3563 e_dbg("MSI interrupt test succeeded!\n");
3565 free_irq(adapter
->pdev
->irq
, netdev
);
3566 pci_disable_msi(adapter
->pdev
);
3569 e1000e_set_interrupt_capability(adapter
);
3570 return e1000_request_irq(adapter
);
3574 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3575 * @adapter: board private struct
3577 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3579 static int e1000_test_msi(struct e1000_adapter
*adapter
)
3584 if (!(adapter
->flags
& FLAG_MSI_ENABLED
))
3587 /* disable SERR in case the MSI write causes a master abort */
3588 pci_read_config_word(adapter
->pdev
, PCI_COMMAND
, &pci_cmd
);
3589 if (pci_cmd
& PCI_COMMAND_SERR
)
3590 pci_write_config_word(adapter
->pdev
, PCI_COMMAND
,
3591 pci_cmd
& ~PCI_COMMAND_SERR
);
3593 err
= e1000_test_msi_interrupt(adapter
);
3595 /* re-enable SERR */
3596 if (pci_cmd
& PCI_COMMAND_SERR
) {
3597 pci_read_config_word(adapter
->pdev
, PCI_COMMAND
, &pci_cmd
);
3598 pci_cmd
|= PCI_COMMAND_SERR
;
3599 pci_write_config_word(adapter
->pdev
, PCI_COMMAND
, pci_cmd
);
3606 * e1000_open - Called when a network interface is made active
3607 * @netdev: network interface device structure
3609 * Returns 0 on success, negative value on failure
3611 * The open entry point is called when a network interface is made
3612 * active by the system (IFF_UP). At this point all resources needed
3613 * for transmit and receive operations are allocated, the interrupt
3614 * handler is registered with the OS, the watchdog timer is started,
3615 * and the stack is notified that the interface is ready.
3617 static int e1000_open(struct net_device
*netdev
)
3619 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3620 struct e1000_hw
*hw
= &adapter
->hw
;
3621 struct pci_dev
*pdev
= adapter
->pdev
;
3624 /* disallow open during test */
3625 if (test_bit(__E1000_TESTING
, &adapter
->state
))
3628 pm_runtime_get_sync(&pdev
->dev
);
3630 netif_carrier_off(netdev
);
3632 /* allocate transmit descriptors */
3633 err
= e1000e_setup_tx_resources(adapter
);
3637 /* allocate receive descriptors */
3638 err
= e1000e_setup_rx_resources(adapter
);
3643 * If AMT is enabled, let the firmware know that the network
3644 * interface is now open and reset the part to a known state.
3646 if (adapter
->flags
& FLAG_HAS_AMT
) {
3647 e1000e_get_hw_control(adapter
);
3648 e1000e_reset(adapter
);
3651 e1000e_power_up_phy(adapter
);
3653 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
3654 if ((adapter
->hw
.mng_cookie
.status
&
3655 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
))
3656 e1000_update_mng_vlan(adapter
);
3658 /* DMA latency requirement to workaround early-receive/jumbo issue */
3659 if ((adapter
->flags
& FLAG_HAS_ERT
) ||
3660 (adapter
->hw
.mac
.type
== e1000_pch2lan
))
3661 pm_qos_add_request(&adapter
->netdev
->pm_qos_req
,
3662 PM_QOS_CPU_DMA_LATENCY
,
3663 PM_QOS_DEFAULT_VALUE
);
3666 * before we allocate an interrupt, we must be ready to handle it.
3667 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3668 * as soon as we call pci_request_irq, so we have to setup our
3669 * clean_rx handler before we do so.
3671 e1000_configure(adapter
);
3673 err
= e1000_request_irq(adapter
);
3678 * Work around PCIe errata with MSI interrupts causing some chipsets to
3679 * ignore e1000e MSI messages, which means we need to test our MSI
3682 if (adapter
->int_mode
!= E1000E_INT_MODE_LEGACY
) {
3683 err
= e1000_test_msi(adapter
);
3685 e_err("Interrupt allocation failed\n");
3690 /* From here on the code is the same as e1000e_up() */
3691 clear_bit(__E1000_DOWN
, &adapter
->state
);
3693 napi_enable(&adapter
->napi
);
3695 e1000_irq_enable(adapter
);
3697 adapter
->tx_hang_recheck
= false;
3698 netif_start_queue(netdev
);
3700 adapter
->idle_check
= true;
3701 pm_runtime_put(&pdev
->dev
);
3703 /* fire a link status change interrupt to start the watchdog */
3704 if (adapter
->msix_entries
)
3705 ew32(ICS
, E1000_ICS_LSC
| E1000_ICR_OTHER
);
3707 ew32(ICS
, E1000_ICS_LSC
);
3712 e1000e_release_hw_control(adapter
);
3713 e1000_power_down_phy(adapter
);
3714 e1000e_free_rx_resources(adapter
);
3716 e1000e_free_tx_resources(adapter
);
3718 e1000e_reset(adapter
);
3719 pm_runtime_put_sync(&pdev
->dev
);
3725 * e1000_close - Disables a network interface
3726 * @netdev: network interface device structure
3728 * Returns 0, this is not allowed to fail
3730 * The close entry point is called when an interface is de-activated
3731 * by the OS. The hardware is still under the drivers control, but
3732 * needs to be disabled. A global MAC reset is issued to stop the
3733 * hardware, and all transmit and receive resources are freed.
3735 static int e1000_close(struct net_device
*netdev
)
3737 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3738 struct pci_dev
*pdev
= adapter
->pdev
;
3740 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
3742 pm_runtime_get_sync(&pdev
->dev
);
3744 if (!test_bit(__E1000_DOWN
, &adapter
->state
)) {
3745 e1000e_down(adapter
);
3746 e1000_free_irq(adapter
);
3748 e1000_power_down_phy(adapter
);
3750 e1000e_free_tx_resources(adapter
);
3751 e1000e_free_rx_resources(adapter
);
3754 * kill manageability vlan ID if supported, but not if a vlan with
3755 * the same ID is registered on the host OS (let 8021q kill it)
3757 if (adapter
->hw
.mng_cookie
.status
&
3758 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
)
3759 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
3762 * If AMT is enabled, let the firmware know that the network
3763 * interface is now closed
3765 if ((adapter
->flags
& FLAG_HAS_AMT
) &&
3766 !test_bit(__E1000_TESTING
, &adapter
->state
))
3767 e1000e_release_hw_control(adapter
);
3769 if ((adapter
->flags
& FLAG_HAS_ERT
) ||
3770 (adapter
->hw
.mac
.type
== e1000_pch2lan
))
3771 pm_qos_remove_request(&adapter
->netdev
->pm_qos_req
);
3773 pm_runtime_put_sync(&pdev
->dev
);
3778 * e1000_set_mac - Change the Ethernet Address of the NIC
3779 * @netdev: network interface device structure
3780 * @p: pointer to an address structure
3782 * Returns 0 on success, negative on failure
3784 static int e1000_set_mac(struct net_device
*netdev
, void *p
)
3786 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3787 struct sockaddr
*addr
= p
;
3789 if (!is_valid_ether_addr(addr
->sa_data
))
3790 return -EADDRNOTAVAIL
;
3792 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
3793 memcpy(adapter
->hw
.mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
3795 e1000e_rar_set(&adapter
->hw
, adapter
->hw
.mac
.addr
, 0);
3797 if (adapter
->flags
& FLAG_RESET_OVERWRITES_LAA
) {
3798 /* activate the work around */
3799 e1000e_set_laa_state_82571(&adapter
->hw
, 1);
3802 * Hold a copy of the LAA in RAR[14] This is done so that
3803 * between the time RAR[0] gets clobbered and the time it
3804 * gets fixed (in e1000_watchdog), the actual LAA is in one
3805 * of the RARs and no incoming packets directed to this port
3806 * are dropped. Eventually the LAA will be in RAR[0] and
3809 e1000e_rar_set(&adapter
->hw
,
3810 adapter
->hw
.mac
.addr
,
3811 adapter
->hw
.mac
.rar_entry_count
- 1);
3818 * e1000e_update_phy_task - work thread to update phy
3819 * @work: pointer to our work struct
3821 * this worker thread exists because we must acquire a
3822 * semaphore to read the phy, which we could msleep while
3823 * waiting for it, and we can't msleep in a timer.
3825 static void e1000e_update_phy_task(struct work_struct
*work
)
3827 struct e1000_adapter
*adapter
= container_of(work
,
3828 struct e1000_adapter
, update_phy_task
);
3830 if (test_bit(__E1000_DOWN
, &adapter
->state
))
3833 e1000_get_phy_info(&adapter
->hw
);
3837 * Need to wait a few seconds after link up to get diagnostic information from
3840 static void e1000_update_phy_info(unsigned long data
)
3842 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
3844 if (test_bit(__E1000_DOWN
, &adapter
->state
))
3847 schedule_work(&adapter
->update_phy_task
);
3851 * e1000e_update_phy_stats - Update the PHY statistics counters
3852 * @adapter: board private structure
3854 static void e1000e_update_phy_stats(struct e1000_adapter
*adapter
)
3856 struct e1000_hw
*hw
= &adapter
->hw
;
3860 ret_val
= hw
->phy
.ops
.acquire(hw
);
3866 #define HV_PHY_STATS_PAGE 778
3868 * A page set is expensive so check if already on desired page.
3869 * If not, set to the page with the PHY status registers.
3871 ret_val
= e1000e_read_phy_reg_mdic(hw
, IGP01E1000_PHY_PAGE_SELECT
,
3875 if (phy_data
!= (HV_PHY_STATS_PAGE
<< IGP_PAGE_SHIFT
)) {
3876 ret_val
= e1000e_write_phy_reg_mdic(hw
,
3877 IGP01E1000_PHY_PAGE_SELECT
,
3878 (HV_PHY_STATS_PAGE
<<
3884 /* Read/clear the upper 16-bit registers and read/accumulate lower */
3886 /* Single Collision Count */
3887 e1000e_read_phy_reg_mdic(hw
, HV_SCC_UPPER
& MAX_PHY_REG_ADDRESS
,
3889 ret_val
= e1000e_read_phy_reg_mdic(hw
,
3890 HV_SCC_LOWER
& MAX_PHY_REG_ADDRESS
,
3893 adapter
->stats
.scc
+= phy_data
;
3895 /* Excessive Collision Count */
3896 e1000e_read_phy_reg_mdic(hw
, HV_ECOL_UPPER
& MAX_PHY_REG_ADDRESS
,
3898 ret_val
= e1000e_read_phy_reg_mdic(hw
,
3899 HV_ECOL_LOWER
& MAX_PHY_REG_ADDRESS
,
3902 adapter
->stats
.ecol
+= phy_data
;
3904 /* Multiple Collision Count */
3905 e1000e_read_phy_reg_mdic(hw
, HV_MCC_UPPER
& MAX_PHY_REG_ADDRESS
,
3907 ret_val
= e1000e_read_phy_reg_mdic(hw
,
3908 HV_MCC_LOWER
& MAX_PHY_REG_ADDRESS
,
3911 adapter
->stats
.mcc
+= phy_data
;
3913 /* Late Collision Count */
3914 e1000e_read_phy_reg_mdic(hw
, HV_LATECOL_UPPER
& MAX_PHY_REG_ADDRESS
,
3916 ret_val
= e1000e_read_phy_reg_mdic(hw
,
3918 MAX_PHY_REG_ADDRESS
,
3921 adapter
->stats
.latecol
+= phy_data
;
3923 /* Collision Count - also used for adaptive IFS */
3924 e1000e_read_phy_reg_mdic(hw
, HV_COLC_UPPER
& MAX_PHY_REG_ADDRESS
,
3926 ret_val
= e1000e_read_phy_reg_mdic(hw
,
3927 HV_COLC_LOWER
& MAX_PHY_REG_ADDRESS
,
3930 hw
->mac
.collision_delta
= phy_data
;
3933 e1000e_read_phy_reg_mdic(hw
, HV_DC_UPPER
& MAX_PHY_REG_ADDRESS
,
3935 ret_val
= e1000e_read_phy_reg_mdic(hw
,
3936 HV_DC_LOWER
& MAX_PHY_REG_ADDRESS
,
3939 adapter
->stats
.dc
+= phy_data
;
3941 /* Transmit with no CRS */
3942 e1000e_read_phy_reg_mdic(hw
, HV_TNCRS_UPPER
& MAX_PHY_REG_ADDRESS
,
3944 ret_val
= e1000e_read_phy_reg_mdic(hw
,
3945 HV_TNCRS_LOWER
& MAX_PHY_REG_ADDRESS
,
3948 adapter
->stats
.tncrs
+= phy_data
;
3951 hw
->phy
.ops
.release(hw
);
3955 * e1000e_update_stats - Update the board statistics counters
3956 * @adapter: board private structure
3958 static void e1000e_update_stats(struct e1000_adapter
*adapter
)
3960 struct net_device
*netdev
= adapter
->netdev
;
3961 struct e1000_hw
*hw
= &adapter
->hw
;
3962 struct pci_dev
*pdev
= adapter
->pdev
;
3965 * Prevent stats update while adapter is being reset, or if the pci
3966 * connection is down.
3968 if (adapter
->link_speed
== 0)
3970 if (pci_channel_offline(pdev
))
3973 adapter
->stats
.crcerrs
+= er32(CRCERRS
);
3974 adapter
->stats
.gprc
+= er32(GPRC
);
3975 adapter
->stats
.gorc
+= er32(GORCL
);
3976 er32(GORCH
); /* Clear gorc */
3977 adapter
->stats
.bprc
+= er32(BPRC
);
3978 adapter
->stats
.mprc
+= er32(MPRC
);
3979 adapter
->stats
.roc
+= er32(ROC
);
3981 adapter
->stats
.mpc
+= er32(MPC
);
3983 /* Half-duplex statistics */
3984 if (adapter
->link_duplex
== HALF_DUPLEX
) {
3985 if (adapter
->flags2
& FLAG2_HAS_PHY_STATS
) {
3986 e1000e_update_phy_stats(adapter
);
3988 adapter
->stats
.scc
+= er32(SCC
);
3989 adapter
->stats
.ecol
+= er32(ECOL
);
3990 adapter
->stats
.mcc
+= er32(MCC
);
3991 adapter
->stats
.latecol
+= er32(LATECOL
);
3992 adapter
->stats
.dc
+= er32(DC
);
3994 hw
->mac
.collision_delta
= er32(COLC
);
3996 if ((hw
->mac
.type
!= e1000_82574
) &&
3997 (hw
->mac
.type
!= e1000_82583
))
3998 adapter
->stats
.tncrs
+= er32(TNCRS
);
4000 adapter
->stats
.colc
+= hw
->mac
.collision_delta
;
4003 adapter
->stats
.xonrxc
+= er32(XONRXC
);
4004 adapter
->stats
.xontxc
+= er32(XONTXC
);
4005 adapter
->stats
.xoffrxc
+= er32(XOFFRXC
);
4006 adapter
->stats
.xofftxc
+= er32(XOFFTXC
);
4007 adapter
->stats
.gptc
+= er32(GPTC
);
4008 adapter
->stats
.gotc
+= er32(GOTCL
);
4009 er32(GOTCH
); /* Clear gotc */
4010 adapter
->stats
.rnbc
+= er32(RNBC
);
4011 adapter
->stats
.ruc
+= er32(RUC
);
4013 adapter
->stats
.mptc
+= er32(MPTC
);
4014 adapter
->stats
.bptc
+= er32(BPTC
);
4016 /* used for adaptive IFS */
4018 hw
->mac
.tx_packet_delta
= er32(TPT
);
4019 adapter
->stats
.tpt
+= hw
->mac
.tx_packet_delta
;
4021 adapter
->stats
.algnerrc
+= er32(ALGNERRC
);
4022 adapter
->stats
.rxerrc
+= er32(RXERRC
);
4023 adapter
->stats
.cexterr
+= er32(CEXTERR
);
4024 adapter
->stats
.tsctc
+= er32(TSCTC
);
4025 adapter
->stats
.tsctfc
+= er32(TSCTFC
);
4027 /* Fill out the OS statistics structure */
4028 netdev
->stats
.multicast
= adapter
->stats
.mprc
;
4029 netdev
->stats
.collisions
= adapter
->stats
.colc
;
4034 * RLEC on some newer hardware can be incorrect so build
4035 * our own version based on RUC and ROC
4037 netdev
->stats
.rx_errors
= adapter
->stats
.rxerrc
+
4038 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
4039 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
4040 adapter
->stats
.cexterr
;
4041 netdev
->stats
.rx_length_errors
= adapter
->stats
.ruc
+
4043 netdev
->stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
4044 netdev
->stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
4045 netdev
->stats
.rx_missed_errors
= adapter
->stats
.mpc
;
4048 netdev
->stats
.tx_errors
= adapter
->stats
.ecol
+
4049 adapter
->stats
.latecol
;
4050 netdev
->stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
4051 netdev
->stats
.tx_window_errors
= adapter
->stats
.latecol
;
4052 netdev
->stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
4054 /* Tx Dropped needs to be maintained elsewhere */
4056 /* Management Stats */
4057 adapter
->stats
.mgptc
+= er32(MGTPTC
);
4058 adapter
->stats
.mgprc
+= er32(MGTPRC
);
4059 adapter
->stats
.mgpdc
+= er32(MGTPDC
);
4063 * e1000_phy_read_status - Update the PHY register status snapshot
4064 * @adapter: board private structure
4066 static void e1000_phy_read_status(struct e1000_adapter
*adapter
)
4068 struct e1000_hw
*hw
= &adapter
->hw
;
4069 struct e1000_phy_regs
*phy
= &adapter
->phy_regs
;
4071 if ((er32(STATUS
) & E1000_STATUS_LU
) &&
4072 (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
)) {
4075 ret_val
= e1e_rphy(hw
, PHY_CONTROL
, &phy
->bmcr
);
4076 ret_val
|= e1e_rphy(hw
, PHY_STATUS
, &phy
->bmsr
);
4077 ret_val
|= e1e_rphy(hw
, PHY_AUTONEG_ADV
, &phy
->advertise
);
4078 ret_val
|= e1e_rphy(hw
, PHY_LP_ABILITY
, &phy
->lpa
);
4079 ret_val
|= e1e_rphy(hw
, PHY_AUTONEG_EXP
, &phy
->expansion
);
4080 ret_val
|= e1e_rphy(hw
, PHY_1000T_CTRL
, &phy
->ctrl1000
);
4081 ret_val
|= e1e_rphy(hw
, PHY_1000T_STATUS
, &phy
->stat1000
);
4082 ret_val
|= e1e_rphy(hw
, PHY_EXT_STATUS
, &phy
->estatus
);
4084 e_warn("Error reading PHY register\n");
4087 * Do not read PHY registers if link is not up
4088 * Set values to typical power-on defaults
4090 phy
->bmcr
= (BMCR_SPEED1000
| BMCR_ANENABLE
| BMCR_FULLDPLX
);
4091 phy
->bmsr
= (BMSR_100FULL
| BMSR_100HALF
| BMSR_10FULL
|
4092 BMSR_10HALF
| BMSR_ESTATEN
| BMSR_ANEGCAPABLE
|
4094 phy
->advertise
= (ADVERTISE_PAUSE_ASYM
| ADVERTISE_PAUSE_CAP
|
4095 ADVERTISE_ALL
| ADVERTISE_CSMA
);
4097 phy
->expansion
= EXPANSION_ENABLENPAGE
;
4098 phy
->ctrl1000
= ADVERTISE_1000FULL
;
4100 phy
->estatus
= (ESTATUS_1000_TFULL
| ESTATUS_1000_THALF
);
4104 static void e1000_print_link_info(struct e1000_adapter
*adapter
)
4106 struct e1000_hw
*hw
= &adapter
->hw
;
4107 u32 ctrl
= er32(CTRL
);
4109 /* Link status message must follow this format for user tools */
4110 printk(KERN_INFO
"e1000e: %s NIC Link is Up %d Mbps %s, "
4111 "Flow Control: %s\n",
4112 adapter
->netdev
->name
,
4113 adapter
->link_speed
,
4114 (adapter
->link_duplex
== FULL_DUPLEX
) ?
4115 "Full Duplex" : "Half Duplex",
4116 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
& E1000_CTRL_RFCE
)) ?
4118 ((ctrl
& E1000_CTRL_RFCE
) ? "Rx" :
4119 ((ctrl
& E1000_CTRL_TFCE
) ? "Tx" : "None")));
4122 static bool e1000e_has_link(struct e1000_adapter
*adapter
)
4124 struct e1000_hw
*hw
= &adapter
->hw
;
4125 bool link_active
= 0;
4129 * get_link_status is set on LSC (link status) interrupt or
4130 * Rx sequence error interrupt. get_link_status will stay
4131 * false until the check_for_link establishes link
4132 * for copper adapters ONLY
4134 switch (hw
->phy
.media_type
) {
4135 case e1000_media_type_copper
:
4136 if (hw
->mac
.get_link_status
) {
4137 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
4138 link_active
= !hw
->mac
.get_link_status
;
4143 case e1000_media_type_fiber
:
4144 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
4145 link_active
= !!(er32(STATUS
) & E1000_STATUS_LU
);
4147 case e1000_media_type_internal_serdes
:
4148 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
4149 link_active
= adapter
->hw
.mac
.serdes_has_link
;
4152 case e1000_media_type_unknown
:
4156 if ((ret_val
== E1000_ERR_PHY
) && (hw
->phy
.type
== e1000_phy_igp_3
) &&
4157 (er32(CTRL
) & E1000_PHY_CTRL_GBE_DISABLE
)) {
4158 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
4159 e_info("Gigabit has been disabled, downgrading speed\n");
4165 static void e1000e_enable_receives(struct e1000_adapter
*adapter
)
4167 /* make sure the receive unit is started */
4168 if ((adapter
->flags
& FLAG_RX_NEEDS_RESTART
) &&
4169 (adapter
->flags
& FLAG_RX_RESTART_NOW
)) {
4170 struct e1000_hw
*hw
= &adapter
->hw
;
4171 u32 rctl
= er32(RCTL
);
4172 ew32(RCTL
, rctl
| E1000_RCTL_EN
);
4173 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
4177 static void e1000e_check_82574_phy_workaround(struct e1000_adapter
*adapter
)
4179 struct e1000_hw
*hw
= &adapter
->hw
;
4182 * With 82574 controllers, PHY needs to be checked periodically
4183 * for hung state and reset, if two calls return true
4185 if (e1000_check_phy_82574(hw
))
4186 adapter
->phy_hang_count
++;
4188 adapter
->phy_hang_count
= 0;
4190 if (adapter
->phy_hang_count
> 1) {
4191 adapter
->phy_hang_count
= 0;
4192 schedule_work(&adapter
->reset_task
);
4197 * e1000_watchdog - Timer Call-back
4198 * @data: pointer to adapter cast into an unsigned long
4200 static void e1000_watchdog(unsigned long data
)
4202 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
4204 /* Do the rest outside of interrupt context */
4205 schedule_work(&adapter
->watchdog_task
);
4207 /* TODO: make this use queue_delayed_work() */
4210 static void e1000_watchdog_task(struct work_struct
*work
)
4212 struct e1000_adapter
*adapter
= container_of(work
,
4213 struct e1000_adapter
, watchdog_task
);
4214 struct net_device
*netdev
= adapter
->netdev
;
4215 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
4216 struct e1000_phy_info
*phy
= &adapter
->hw
.phy
;
4217 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4218 struct e1000_hw
*hw
= &adapter
->hw
;
4221 if (test_bit(__E1000_DOWN
, &adapter
->state
))
4224 link
= e1000e_has_link(adapter
);
4225 if ((netif_carrier_ok(netdev
)) && link
) {
4226 /* Cancel scheduled suspend requests. */
4227 pm_runtime_resume(netdev
->dev
.parent
);
4229 e1000e_enable_receives(adapter
);
4233 if ((e1000e_enable_tx_pkt_filtering(hw
)) &&
4234 (adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
))
4235 e1000_update_mng_vlan(adapter
);
4238 if (!netif_carrier_ok(netdev
)) {
4241 /* Cancel scheduled suspend requests. */
4242 pm_runtime_resume(netdev
->dev
.parent
);
4244 /* update snapshot of PHY registers on LSC */
4245 e1000_phy_read_status(adapter
);
4246 mac
->ops
.get_link_up_info(&adapter
->hw
,
4247 &adapter
->link_speed
,
4248 &adapter
->link_duplex
);
4249 e1000_print_link_info(adapter
);
4251 * On supported PHYs, check for duplex mismatch only
4252 * if link has autonegotiated at 10/100 half
4254 if ((hw
->phy
.type
== e1000_phy_igp_3
||
4255 hw
->phy
.type
== e1000_phy_bm
) &&
4256 (hw
->mac
.autoneg
== true) &&
4257 (adapter
->link_speed
== SPEED_10
||
4258 adapter
->link_speed
== SPEED_100
) &&
4259 (adapter
->link_duplex
== HALF_DUPLEX
)) {
4262 e1e_rphy(hw
, PHY_AUTONEG_EXP
, &autoneg_exp
);
4264 if (!(autoneg_exp
& NWAY_ER_LP_NWAY_CAPS
))
4265 e_info("Autonegotiated half duplex but"
4266 " link partner cannot autoneg. "
4267 " Try forcing full duplex if "
4268 "link gets many collisions.\n");
4271 /* adjust timeout factor according to speed/duplex */
4272 adapter
->tx_timeout_factor
= 1;
4273 switch (adapter
->link_speed
) {
4276 adapter
->tx_timeout_factor
= 16;
4280 adapter
->tx_timeout_factor
= 10;
4285 * workaround: re-program speed mode bit after
4288 if ((adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) &&
4291 tarc0
= er32(TARC(0));
4292 tarc0
&= ~SPEED_MODE_BIT
;
4293 ew32(TARC(0), tarc0
);
4297 * disable TSO for pcie and 10/100 speeds, to avoid
4298 * some hardware issues
4300 if (!(adapter
->flags
& FLAG_TSO_FORCE
)) {
4301 switch (adapter
->link_speed
) {
4304 e_info("10/100 speed: disabling TSO\n");
4305 netdev
->features
&= ~NETIF_F_TSO
;
4306 netdev
->features
&= ~NETIF_F_TSO6
;
4309 netdev
->features
|= NETIF_F_TSO
;
4310 netdev
->features
|= NETIF_F_TSO6
;
4319 * enable transmits in the hardware, need to do this
4320 * after setting TARC(0)
4323 tctl
|= E1000_TCTL_EN
;
4327 * Perform any post-link-up configuration before
4328 * reporting link up.
4330 if (phy
->ops
.cfg_on_link_up
)
4331 phy
->ops
.cfg_on_link_up(hw
);
4333 netif_carrier_on(netdev
);
4335 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
4336 mod_timer(&adapter
->phy_info_timer
,
4337 round_jiffies(jiffies
+ 2 * HZ
));
4340 if (netif_carrier_ok(netdev
)) {
4341 adapter
->link_speed
= 0;
4342 adapter
->link_duplex
= 0;
4343 /* Link status message must follow this format */
4344 printk(KERN_INFO
"e1000e: %s NIC Link is Down\n",
4345 adapter
->netdev
->name
);
4346 netif_carrier_off(netdev
);
4347 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
4348 mod_timer(&adapter
->phy_info_timer
,
4349 round_jiffies(jiffies
+ 2 * HZ
));
4351 if (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)
4352 schedule_work(&adapter
->reset_task
);
4354 pm_schedule_suspend(netdev
->dev
.parent
,
4360 spin_lock(&adapter
->stats64_lock
);
4361 e1000e_update_stats(adapter
);
4363 mac
->tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
4364 adapter
->tpt_old
= adapter
->stats
.tpt
;
4365 mac
->collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
4366 adapter
->colc_old
= adapter
->stats
.colc
;
4368 adapter
->gorc
= adapter
->stats
.gorc
- adapter
->gorc_old
;
4369 adapter
->gorc_old
= adapter
->stats
.gorc
;
4370 adapter
->gotc
= adapter
->stats
.gotc
- adapter
->gotc_old
;
4371 adapter
->gotc_old
= adapter
->stats
.gotc
;
4372 spin_unlock(&adapter
->stats64_lock
);
4374 e1000e_update_adaptive(&adapter
->hw
);
4376 if (!netif_carrier_ok(netdev
) &&
4377 (e1000_desc_unused(tx_ring
) + 1 < tx_ring
->count
)) {
4379 * We've lost link, so the controller stops DMA,
4380 * but we've got queued Tx work that's never going
4381 * to get done, so reset controller to flush Tx.
4382 * (Do the reset outside of interrupt context).
4384 schedule_work(&adapter
->reset_task
);
4385 /* return immediately since reset is imminent */
4389 /* Simple mode for Interrupt Throttle Rate (ITR) */
4390 if (adapter
->itr_setting
== 4) {
4392 * Symmetric Tx/Rx gets a reduced ITR=2000;
4393 * Total asymmetrical Tx or Rx gets ITR=8000;
4394 * everyone else is between 2000-8000.
4396 u32 goc
= (adapter
->gotc
+ adapter
->gorc
) / 10000;
4397 u32 dif
= (adapter
->gotc
> adapter
->gorc
?
4398 adapter
->gotc
- adapter
->gorc
:
4399 adapter
->gorc
- adapter
->gotc
) / 10000;
4400 u32 itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
4402 ew32(ITR
, 1000000000 / (itr
* 256));
4405 /* Cause software interrupt to ensure Rx ring is cleaned */
4406 if (adapter
->msix_entries
)
4407 ew32(ICS
, adapter
->rx_ring
->ims_val
);
4409 ew32(ICS
, E1000_ICS_RXDMT0
);
4411 /* flush pending descriptors to memory before detecting Tx hang */
4412 e1000e_flush_descriptors(adapter
);
4414 /* Force detection of hung controller every watchdog period */
4415 adapter
->detect_tx_hung
= 1;
4418 * With 82571 controllers, LAA may be overwritten due to controller
4419 * reset from the other port. Set the appropriate LAA in RAR[0]
4421 if (e1000e_get_laa_state_82571(hw
))
4422 e1000e_rar_set(hw
, adapter
->hw
.mac
.addr
, 0);
4424 if (adapter
->flags2
& FLAG2_CHECK_PHY_HANG
)
4425 e1000e_check_82574_phy_workaround(adapter
);
4427 /* Reset the timer */
4428 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
4429 mod_timer(&adapter
->watchdog_timer
,
4430 round_jiffies(jiffies
+ 2 * HZ
));
4433 #define E1000_TX_FLAGS_CSUM 0x00000001
4434 #define E1000_TX_FLAGS_VLAN 0x00000002
4435 #define E1000_TX_FLAGS_TSO 0x00000004
4436 #define E1000_TX_FLAGS_IPV4 0x00000008
4437 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4438 #define E1000_TX_FLAGS_VLAN_SHIFT 16
4440 static int e1000_tso(struct e1000_adapter
*adapter
,
4441 struct sk_buff
*skb
)
4443 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4444 struct e1000_context_desc
*context_desc
;
4445 struct e1000_buffer
*buffer_info
;
4448 u16 ipcse
= 0, tucse
, mss
;
4449 u8 ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
4451 if (!skb_is_gso(skb
))
4454 if (skb_header_cloned(skb
)) {
4455 int err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
4461 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
4462 mss
= skb_shinfo(skb
)->gso_size
;
4463 if (skb
->protocol
== htons(ETH_P_IP
)) {
4464 struct iphdr
*iph
= ip_hdr(skb
);
4467 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
4469 cmd_length
= E1000_TXD_CMD_IP
;
4470 ipcse
= skb_transport_offset(skb
) - 1;
4471 } else if (skb_is_gso_v6(skb
)) {
4472 ipv6_hdr(skb
)->payload_len
= 0;
4473 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
4474 &ipv6_hdr(skb
)->daddr
,
4478 ipcss
= skb_network_offset(skb
);
4479 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
4480 tucss
= skb_transport_offset(skb
);
4481 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
4484 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
4485 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
4487 i
= tx_ring
->next_to_use
;
4488 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
4489 buffer_info
= &tx_ring
->buffer_info
[i
];
4491 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
4492 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
4493 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
4494 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
4495 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
4496 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
4497 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
4498 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
4499 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
4501 buffer_info
->time_stamp
= jiffies
;
4502 buffer_info
->next_to_watch
= i
;
4505 if (i
== tx_ring
->count
)
4507 tx_ring
->next_to_use
= i
;
4512 static bool e1000_tx_csum(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
4514 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4515 struct e1000_context_desc
*context_desc
;
4516 struct e1000_buffer
*buffer_info
;
4519 u32 cmd_len
= E1000_TXD_CMD_DEXT
;
4522 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
4525 if (skb
->protocol
== cpu_to_be16(ETH_P_8021Q
))
4526 protocol
= vlan_eth_hdr(skb
)->h_vlan_encapsulated_proto
;
4528 protocol
= skb
->protocol
;
4531 case cpu_to_be16(ETH_P_IP
):
4532 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
4533 cmd_len
|= E1000_TXD_CMD_TCP
;
4535 case cpu_to_be16(ETH_P_IPV6
):
4536 /* XXX not handling all IPV6 headers */
4537 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
4538 cmd_len
|= E1000_TXD_CMD_TCP
;
4541 if (unlikely(net_ratelimit()))
4542 e_warn("checksum_partial proto=%x!\n",
4543 be16_to_cpu(protocol
));
4547 css
= skb_checksum_start_offset(skb
);
4549 i
= tx_ring
->next_to_use
;
4550 buffer_info
= &tx_ring
->buffer_info
[i
];
4551 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
4553 context_desc
->lower_setup
.ip_config
= 0;
4554 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
4555 context_desc
->upper_setup
.tcp_fields
.tucso
=
4556 css
+ skb
->csum_offset
;
4557 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
4558 context_desc
->tcp_seg_setup
.data
= 0;
4559 context_desc
->cmd_and_length
= cpu_to_le32(cmd_len
);
4561 buffer_info
->time_stamp
= jiffies
;
4562 buffer_info
->next_to_watch
= i
;
4565 if (i
== tx_ring
->count
)
4567 tx_ring
->next_to_use
= i
;
4572 #define E1000_MAX_PER_TXD 8192
4573 #define E1000_MAX_TXD_PWR 12
4575 static int e1000_tx_map(struct e1000_adapter
*adapter
,
4576 struct sk_buff
*skb
, unsigned int first
,
4577 unsigned int max_per_txd
, unsigned int nr_frags
,
4580 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4581 struct pci_dev
*pdev
= adapter
->pdev
;
4582 struct e1000_buffer
*buffer_info
;
4583 unsigned int len
= skb_headlen(skb
);
4584 unsigned int offset
= 0, size
, count
= 0, i
;
4585 unsigned int f
, bytecount
, segs
;
4587 i
= tx_ring
->next_to_use
;
4590 buffer_info
= &tx_ring
->buffer_info
[i
];
4591 size
= min(len
, max_per_txd
);
4593 buffer_info
->length
= size
;
4594 buffer_info
->time_stamp
= jiffies
;
4595 buffer_info
->next_to_watch
= i
;
4596 buffer_info
->dma
= dma_map_single(&pdev
->dev
,
4598 size
, DMA_TO_DEVICE
);
4599 buffer_info
->mapped_as_page
= false;
4600 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
))
4609 if (i
== tx_ring
->count
)
4614 for (f
= 0; f
< nr_frags
; f
++) {
4615 struct skb_frag_struct
*frag
;
4617 frag
= &skb_shinfo(skb
)->frags
[f
];
4619 offset
= frag
->page_offset
;
4623 if (i
== tx_ring
->count
)
4626 buffer_info
= &tx_ring
->buffer_info
[i
];
4627 size
= min(len
, max_per_txd
);
4629 buffer_info
->length
= size
;
4630 buffer_info
->time_stamp
= jiffies
;
4631 buffer_info
->next_to_watch
= i
;
4632 buffer_info
->dma
= dma_map_page(&pdev
->dev
, frag
->page
,
4635 buffer_info
->mapped_as_page
= true;
4636 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
))
4645 segs
= skb_shinfo(skb
)->gso_segs
? : 1;
4646 /* multiply data chunks by size of headers */
4647 bytecount
= ((segs
- 1) * skb_headlen(skb
)) + skb
->len
;
4649 tx_ring
->buffer_info
[i
].skb
= skb
;
4650 tx_ring
->buffer_info
[i
].segs
= segs
;
4651 tx_ring
->buffer_info
[i
].bytecount
= bytecount
;
4652 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
4657 dev_err(&pdev
->dev
, "Tx DMA map failed\n");
4658 buffer_info
->dma
= 0;
4664 i
+= tx_ring
->count
;
4666 buffer_info
= &tx_ring
->buffer_info
[i
];
4667 e1000_put_txbuf(adapter
, buffer_info
);
4673 static void e1000_tx_queue(struct e1000_adapter
*adapter
,
4674 int tx_flags
, int count
)
4676 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4677 struct e1000_tx_desc
*tx_desc
= NULL
;
4678 struct e1000_buffer
*buffer_info
;
4679 u32 txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
4682 if (tx_flags
& E1000_TX_FLAGS_TSO
) {
4683 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
4685 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
4687 if (tx_flags
& E1000_TX_FLAGS_IPV4
)
4688 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
4691 if (tx_flags
& E1000_TX_FLAGS_CSUM
) {
4692 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
4693 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
4696 if (tx_flags
& E1000_TX_FLAGS_VLAN
) {
4697 txd_lower
|= E1000_TXD_CMD_VLE
;
4698 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
4701 i
= tx_ring
->next_to_use
;
4704 buffer_info
= &tx_ring
->buffer_info
[i
];
4705 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
4706 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4707 tx_desc
->lower
.data
=
4708 cpu_to_le32(txd_lower
| buffer_info
->length
);
4709 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
4712 if (i
== tx_ring
->count
)
4714 } while (--count
> 0);
4716 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
4719 * Force memory writes to complete before letting h/w
4720 * know there are new descriptors to fetch. (Only
4721 * applicable for weak-ordered memory model archs,
4726 tx_ring
->next_to_use
= i
;
4727 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
4729 * we need this if more than one processor can write to our tail
4730 * at a time, it synchronizes IO on IA64/Altix systems
4735 #define MINIMUM_DHCP_PACKET_SIZE 282
4736 static int e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
,
4737 struct sk_buff
*skb
)
4739 struct e1000_hw
*hw
= &adapter
->hw
;
4742 if (vlan_tx_tag_present(skb
)) {
4743 if (!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
4744 (adapter
->hw
.mng_cookie
.status
&
4745 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
)))
4749 if (skb
->len
<= MINIMUM_DHCP_PACKET_SIZE
)
4752 if (((struct ethhdr
*) skb
->data
)->h_proto
!= htons(ETH_P_IP
))
4756 const struct iphdr
*ip
= (struct iphdr
*)((u8
*)skb
->data
+14);
4759 if (ip
->protocol
!= IPPROTO_UDP
)
4762 udp
= (struct udphdr
*)((u8
*)ip
+ (ip
->ihl
<< 2));
4763 if (ntohs(udp
->dest
) != 67)
4766 offset
= (u8
*)udp
+ 8 - skb
->data
;
4767 length
= skb
->len
- offset
;
4768 return e1000e_mng_write_dhcp_info(hw
, (u8
*)udp
+ 8, length
);
4774 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
4776 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4778 netif_stop_queue(netdev
);
4780 * Herbert's original patch had:
4781 * smp_mb__after_netif_stop_queue();
4782 * but since that doesn't exist yet, just open code it.
4787 * We need to check again in a case another CPU has just
4788 * made room available.
4790 if (e1000_desc_unused(adapter
->tx_ring
) < size
)
4794 netif_start_queue(netdev
);
4795 ++adapter
->restart_queue
;
4799 static int e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
4801 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4803 if (e1000_desc_unused(adapter
->tx_ring
) >= size
)
4805 return __e1000_maybe_stop_tx(netdev
, size
);
4808 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4809 static netdev_tx_t
e1000_xmit_frame(struct sk_buff
*skb
,
4810 struct net_device
*netdev
)
4812 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4813 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4815 unsigned int max_per_txd
= E1000_MAX_PER_TXD
;
4816 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
4817 unsigned int tx_flags
= 0;
4818 unsigned int len
= skb_headlen(skb
);
4819 unsigned int nr_frags
;
4825 if (test_bit(__E1000_DOWN
, &adapter
->state
)) {
4826 dev_kfree_skb_any(skb
);
4827 return NETDEV_TX_OK
;
4830 if (skb
->len
<= 0) {
4831 dev_kfree_skb_any(skb
);
4832 return NETDEV_TX_OK
;
4835 mss
= skb_shinfo(skb
)->gso_size
;
4837 * The controller does a simple calculation to
4838 * make sure there is enough room in the FIFO before
4839 * initiating the DMA for each buffer. The calc is:
4840 * 4 = ceil(buffer len/mss). To make sure we don't
4841 * overrun the FIFO, adjust the max buffer len if mss
4846 max_per_txd
= min(mss
<< 2, max_per_txd
);
4847 max_txd_pwr
= fls(max_per_txd
) - 1;
4850 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4851 * points to just header, pull a few bytes of payload from
4852 * frags into skb->data
4854 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
4856 * we do this workaround for ES2LAN, but it is un-necessary,
4857 * avoiding it could save a lot of cycles
4859 if (skb
->data_len
&& (hdr_len
== len
)) {
4860 unsigned int pull_size
;
4862 pull_size
= min((unsigned int)4, skb
->data_len
);
4863 if (!__pskb_pull_tail(skb
, pull_size
)) {
4864 e_err("__pskb_pull_tail failed.\n");
4865 dev_kfree_skb_any(skb
);
4866 return NETDEV_TX_OK
;
4868 len
= skb_headlen(skb
);
4872 /* reserve a descriptor for the offload context */
4873 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
4877 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
4879 nr_frags
= skb_shinfo(skb
)->nr_frags
;
4880 for (f
= 0; f
< nr_frags
; f
++)
4881 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
4884 if (adapter
->hw
.mac
.tx_pkt_filtering
)
4885 e1000_transfer_dhcp_info(adapter
, skb
);
4888 * need: count + 2 desc gap to keep tail from touching
4889 * head, otherwise try next time
4891 if (e1000_maybe_stop_tx(netdev
, count
+ 2))
4892 return NETDEV_TX_BUSY
;
4894 if (vlan_tx_tag_present(skb
)) {
4895 tx_flags
|= E1000_TX_FLAGS_VLAN
;
4896 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
4899 first
= tx_ring
->next_to_use
;
4901 tso
= e1000_tso(adapter
, skb
);
4903 dev_kfree_skb_any(skb
);
4904 return NETDEV_TX_OK
;
4908 tx_flags
|= E1000_TX_FLAGS_TSO
;
4909 else if (e1000_tx_csum(adapter
, skb
))
4910 tx_flags
|= E1000_TX_FLAGS_CSUM
;
4913 * Old method was to assume IPv4 packet by default if TSO was enabled.
4914 * 82571 hardware supports TSO capabilities for IPv6 as well...
4915 * no longer assume, we must.
4917 if (skb
->protocol
== htons(ETH_P_IP
))
4918 tx_flags
|= E1000_TX_FLAGS_IPV4
;
4920 /* if count is 0 then mapping error has occurred */
4921 count
= e1000_tx_map(adapter
, skb
, first
, max_per_txd
, nr_frags
, mss
);
4923 e1000_tx_queue(adapter
, tx_flags
, count
);
4924 /* Make sure there is space in the ring for the next send. */
4925 e1000_maybe_stop_tx(netdev
, MAX_SKB_FRAGS
+ 2);
4928 dev_kfree_skb_any(skb
);
4929 tx_ring
->buffer_info
[first
].time_stamp
= 0;
4930 tx_ring
->next_to_use
= first
;
4933 return NETDEV_TX_OK
;
4937 * e1000_tx_timeout - Respond to a Tx Hang
4938 * @netdev: network interface device structure
4940 static void e1000_tx_timeout(struct net_device
*netdev
)
4942 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4944 /* Do the reset outside of interrupt context */
4945 adapter
->tx_timeout_count
++;
4946 schedule_work(&adapter
->reset_task
);
4949 static void e1000_reset_task(struct work_struct
*work
)
4951 struct e1000_adapter
*adapter
;
4952 adapter
= container_of(work
, struct e1000_adapter
, reset_task
);
4954 /* don't run the task if already down */
4955 if (test_bit(__E1000_DOWN
, &adapter
->state
))
4958 if (!((adapter
->flags
& FLAG_RX_NEEDS_RESTART
) &&
4959 (adapter
->flags
& FLAG_RX_RESTART_NOW
))) {
4960 e1000e_dump(adapter
);
4961 e_err("Reset adapter\n");
4963 e1000e_reinit_locked(adapter
);
4967 * e1000_get_stats64 - Get System Network Statistics
4968 * @netdev: network interface device structure
4969 * @stats: rtnl_link_stats64 pointer
4971 * Returns the address of the device statistics structure.
4973 struct rtnl_link_stats64
*e1000e_get_stats64(struct net_device
*netdev
,
4974 struct rtnl_link_stats64
*stats
)
4976 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4978 memset(stats
, 0, sizeof(struct rtnl_link_stats64
));
4979 spin_lock(&adapter
->stats64_lock
);
4980 e1000e_update_stats(adapter
);
4981 /* Fill out the OS statistics structure */
4982 stats
->rx_bytes
= adapter
->stats
.gorc
;
4983 stats
->rx_packets
= adapter
->stats
.gprc
;
4984 stats
->tx_bytes
= adapter
->stats
.gotc
;
4985 stats
->tx_packets
= adapter
->stats
.gptc
;
4986 stats
->multicast
= adapter
->stats
.mprc
;
4987 stats
->collisions
= adapter
->stats
.colc
;
4992 * RLEC on some newer hardware can be incorrect so build
4993 * our own version based on RUC and ROC
4995 stats
->rx_errors
= adapter
->stats
.rxerrc
+
4996 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
4997 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
4998 adapter
->stats
.cexterr
;
4999 stats
->rx_length_errors
= adapter
->stats
.ruc
+
5001 stats
->rx_crc_errors
= adapter
->stats
.crcerrs
;
5002 stats
->rx_frame_errors
= adapter
->stats
.algnerrc
;
5003 stats
->rx_missed_errors
= adapter
->stats
.mpc
;
5006 stats
->tx_errors
= adapter
->stats
.ecol
+
5007 adapter
->stats
.latecol
;
5008 stats
->tx_aborted_errors
= adapter
->stats
.ecol
;
5009 stats
->tx_window_errors
= adapter
->stats
.latecol
;
5010 stats
->tx_carrier_errors
= adapter
->stats
.tncrs
;
5012 /* Tx Dropped needs to be maintained elsewhere */
5014 spin_unlock(&adapter
->stats64_lock
);
5019 * e1000_change_mtu - Change the Maximum Transfer Unit
5020 * @netdev: network interface device structure
5021 * @new_mtu: new value for maximum frame size
5023 * Returns 0 on success, negative on failure
5025 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
5027 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5028 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5030 /* Jumbo frame support */
5031 if ((max_frame
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) &&
5032 !(adapter
->flags
& FLAG_HAS_JUMBO_FRAMES
)) {
5033 e_err("Jumbo Frames not supported.\n");
5037 /* Supported frame sizes */
5038 if ((new_mtu
< ETH_ZLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
) ||
5039 (max_frame
> adapter
->max_hw_frame_size
)) {
5040 e_err("Unsupported MTU setting\n");
5044 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5045 if ((adapter
->hw
.mac
.type
== e1000_pch2lan
) &&
5046 !(adapter
->flags2
& FLAG2_CRC_STRIPPING
) &&
5047 (new_mtu
> ETH_DATA_LEN
)) {
5048 e_err("Jumbo Frames not supported on 82579 when CRC "
5049 "stripping is disabled.\n");
5053 /* 82573 Errata 17 */
5054 if (((adapter
->hw
.mac
.type
== e1000_82573
) ||
5055 (adapter
->hw
.mac
.type
== e1000_82574
)) &&
5056 (max_frame
> ETH_FRAME_LEN
+ ETH_FCS_LEN
)) {
5057 adapter
->flags2
|= FLAG2_DISABLE_ASPM_L1
;
5058 e1000e_disable_aspm(adapter
->pdev
, PCIE_LINK_STATE_L1
);
5061 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
5062 usleep_range(1000, 2000);
5063 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
5064 adapter
->max_frame_size
= max_frame
;
5065 e_info("changing MTU from %d to %d\n", netdev
->mtu
, new_mtu
);
5066 netdev
->mtu
= new_mtu
;
5067 if (netif_running(netdev
))
5068 e1000e_down(adapter
);
5071 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
5072 * means we reserve 2 more, this pushes us to allocate from the next
5074 * i.e. RXBUFFER_2048 --> size-4096 slab
5075 * However with the new *_jumbo_rx* routines, jumbo receives will use
5079 if (max_frame
<= 2048)
5080 adapter
->rx_buffer_len
= 2048;
5082 adapter
->rx_buffer_len
= 4096;
5084 /* adjust allocation if LPE protects us, and we aren't using SBP */
5085 if ((max_frame
== ETH_FRAME_LEN
+ ETH_FCS_LEN
) ||
5086 (max_frame
== ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
))
5087 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
5090 if (netif_running(netdev
))
5093 e1000e_reset(adapter
);
5095 clear_bit(__E1000_RESETTING
, &adapter
->state
);
5100 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
5103 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5104 struct mii_ioctl_data
*data
= if_mii(ifr
);
5106 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
5111 data
->phy_id
= adapter
->hw
.phy
.addr
;
5114 e1000_phy_read_status(adapter
);
5116 switch (data
->reg_num
& 0x1F) {
5118 data
->val_out
= adapter
->phy_regs
.bmcr
;
5121 data
->val_out
= adapter
->phy_regs
.bmsr
;
5124 data
->val_out
= (adapter
->hw
.phy
.id
>> 16);
5127 data
->val_out
= (adapter
->hw
.phy
.id
& 0xFFFF);
5130 data
->val_out
= adapter
->phy_regs
.advertise
;
5133 data
->val_out
= adapter
->phy_regs
.lpa
;
5136 data
->val_out
= adapter
->phy_regs
.expansion
;
5139 data
->val_out
= adapter
->phy_regs
.ctrl1000
;
5142 data
->val_out
= adapter
->phy_regs
.stat1000
;
5145 data
->val_out
= adapter
->phy_regs
.estatus
;
5158 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
5164 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
5170 static int e1000_init_phy_wakeup(struct e1000_adapter
*adapter
, u32 wufc
)
5172 struct e1000_hw
*hw
= &adapter
->hw
;
5177 /* copy MAC RARs to PHY RARs */
5178 e1000_copy_rx_addrs_to_phy_ich8lan(hw
);
5180 /* copy MAC MTA to PHY MTA */
5181 for (i
= 0; i
< adapter
->hw
.mac
.mta_reg_count
; i
++) {
5182 mac_reg
= E1000_READ_REG_ARRAY(hw
, E1000_MTA
, i
);
5183 e1e_wphy(hw
, BM_MTA(i
), (u16
)(mac_reg
& 0xFFFF));
5184 e1e_wphy(hw
, BM_MTA(i
) + 1, (u16
)((mac_reg
>> 16) & 0xFFFF));
5187 /* configure PHY Rx Control register */
5188 e1e_rphy(&adapter
->hw
, BM_RCTL
, &phy_reg
);
5189 mac_reg
= er32(RCTL
);
5190 if (mac_reg
& E1000_RCTL_UPE
)
5191 phy_reg
|= BM_RCTL_UPE
;
5192 if (mac_reg
& E1000_RCTL_MPE
)
5193 phy_reg
|= BM_RCTL_MPE
;
5194 phy_reg
&= ~(BM_RCTL_MO_MASK
);
5195 if (mac_reg
& E1000_RCTL_MO_3
)
5196 phy_reg
|= (((mac_reg
& E1000_RCTL_MO_3
) >> E1000_RCTL_MO_SHIFT
)
5197 << BM_RCTL_MO_SHIFT
);
5198 if (mac_reg
& E1000_RCTL_BAM
)
5199 phy_reg
|= BM_RCTL_BAM
;
5200 if (mac_reg
& E1000_RCTL_PMCF
)
5201 phy_reg
|= BM_RCTL_PMCF
;
5202 mac_reg
= er32(CTRL
);
5203 if (mac_reg
& E1000_CTRL_RFCE
)
5204 phy_reg
|= BM_RCTL_RFCE
;
5205 e1e_wphy(&adapter
->hw
, BM_RCTL
, phy_reg
);
5207 /* enable PHY wakeup in MAC register */
5209 ew32(WUC
, E1000_WUC_PHY_WAKE
| E1000_WUC_PME_EN
);
5211 /* configure and enable PHY wakeup in PHY registers */
5212 e1e_wphy(&adapter
->hw
, BM_WUFC
, wufc
);
5213 e1e_wphy(&adapter
->hw
, BM_WUC
, E1000_WUC_PME_EN
);
5215 /* activate PHY wakeup */
5216 retval
= hw
->phy
.ops
.acquire(hw
);
5218 e_err("Could not acquire PHY\n");
5221 e1000e_write_phy_reg_mdic(hw
, IGP01E1000_PHY_PAGE_SELECT
,
5222 (BM_WUC_ENABLE_PAGE
<< IGP_PAGE_SHIFT
));
5223 retval
= e1000e_read_phy_reg_mdic(hw
, BM_WUC_ENABLE_REG
, &phy_reg
);
5225 e_err("Could not read PHY page 769\n");
5228 phy_reg
|= BM_WUC_ENABLE_BIT
| BM_WUC_HOST_WU_BIT
;
5229 retval
= e1000e_write_phy_reg_mdic(hw
, BM_WUC_ENABLE_REG
, phy_reg
);
5231 e_err("Could not set PHY Host Wakeup bit\n");
5233 hw
->phy
.ops
.release(hw
);
5238 static int __e1000_shutdown(struct pci_dev
*pdev
, bool *enable_wake
,
5241 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5242 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5243 struct e1000_hw
*hw
= &adapter
->hw
;
5244 u32 ctrl
, ctrl_ext
, rctl
, status
;
5245 /* Runtime suspend should only enable wakeup for link changes */
5246 u32 wufc
= runtime
? E1000_WUFC_LNKC
: adapter
->wol
;
5249 netif_device_detach(netdev
);
5251 if (netif_running(netdev
)) {
5252 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
5253 e1000e_down(adapter
);
5254 e1000_free_irq(adapter
);
5256 e1000e_reset_interrupt_capability(adapter
);
5258 retval
= pci_save_state(pdev
);
5262 status
= er32(STATUS
);
5263 if (status
& E1000_STATUS_LU
)
5264 wufc
&= ~E1000_WUFC_LNKC
;
5267 e1000_setup_rctl(adapter
);
5268 e1000_set_multi(netdev
);
5270 /* turn on all-multi mode if wake on multicast is enabled */
5271 if (wufc
& E1000_WUFC_MC
) {
5273 rctl
|= E1000_RCTL_MPE
;
5278 /* advertise wake from D3Cold */
5279 #define E1000_CTRL_ADVD3WUC 0x00100000
5280 /* phy power management enable */
5281 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5282 ctrl
|= E1000_CTRL_ADVD3WUC
;
5283 if (!(adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
))
5284 ctrl
|= E1000_CTRL_EN_PHY_PWR_MGMT
;
5287 if (adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
||
5288 adapter
->hw
.phy
.media_type
==
5289 e1000_media_type_internal_serdes
) {
5290 /* keep the laser running in D3 */
5291 ctrl_ext
= er32(CTRL_EXT
);
5292 ctrl_ext
|= E1000_CTRL_EXT_SDP3_DATA
;
5293 ew32(CTRL_EXT
, ctrl_ext
);
5296 if (adapter
->flags
& FLAG_IS_ICH
)
5297 e1000e_disable_gig_wol_ich8lan(&adapter
->hw
);
5299 /* Allow time for pending master requests to run */
5300 e1000e_disable_pcie_master(&adapter
->hw
);
5302 if (adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
) {
5303 /* enable wakeup by the PHY */
5304 retval
= e1000_init_phy_wakeup(adapter
, wufc
);
5308 /* enable wakeup by the MAC */
5310 ew32(WUC
, E1000_WUC_PME_EN
);
5317 *enable_wake
= !!wufc
;
5319 /* make sure adapter isn't asleep if manageability is enabled */
5320 if ((adapter
->flags
& FLAG_MNG_PT_ENABLED
) ||
5321 (hw
->mac
.ops
.check_mng_mode(hw
)))
5322 *enable_wake
= true;
5324 if (adapter
->hw
.phy
.type
== e1000_phy_igp_3
)
5325 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter
->hw
);
5328 * Release control of h/w to f/w. If f/w is AMT enabled, this
5329 * would have already happened in close and is redundant.
5331 e1000e_release_hw_control(adapter
);
5333 pci_disable_device(pdev
);
5338 static void e1000_power_off(struct pci_dev
*pdev
, bool sleep
, bool wake
)
5340 if (sleep
&& wake
) {
5341 pci_prepare_to_sleep(pdev
);
5345 pci_wake_from_d3(pdev
, wake
);
5346 pci_set_power_state(pdev
, PCI_D3hot
);
5349 static void e1000_complete_shutdown(struct pci_dev
*pdev
, bool sleep
,
5352 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5353 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5356 * The pci-e switch on some quad port adapters will report a
5357 * correctable error when the MAC transitions from D0 to D3. To
5358 * prevent this we need to mask off the correctable errors on the
5359 * downstream port of the pci-e switch.
5361 if (adapter
->flags
& FLAG_IS_QUAD_PORT
) {
5362 struct pci_dev
*us_dev
= pdev
->bus
->self
;
5363 int pos
= pci_find_capability(us_dev
, PCI_CAP_ID_EXP
);
5366 pci_read_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
, &devctl
);
5367 pci_write_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
,
5368 (devctl
& ~PCI_EXP_DEVCTL_CERE
));
5370 e1000_power_off(pdev
, sleep
, wake
);
5372 pci_write_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
, devctl
);
5374 e1000_power_off(pdev
, sleep
, wake
);
5378 #ifdef CONFIG_PCIEASPM
5379 static void __e1000e_disable_aspm(struct pci_dev
*pdev
, u16 state
)
5381 pci_disable_link_state_locked(pdev
, state
);
5384 static void __e1000e_disable_aspm(struct pci_dev
*pdev
, u16 state
)
5390 * Both device and parent should have the same ASPM setting.
5391 * Disable ASPM in downstream component first and then upstream.
5393 pos
= pci_pcie_cap(pdev
);
5394 pci_read_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, ®16
);
5396 pci_write_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, reg16
);
5398 if (!pdev
->bus
->self
)
5401 pos
= pci_pcie_cap(pdev
->bus
->self
);
5402 pci_read_config_word(pdev
->bus
->self
, pos
+ PCI_EXP_LNKCTL
, ®16
);
5404 pci_write_config_word(pdev
->bus
->self
, pos
+ PCI_EXP_LNKCTL
, reg16
);
5407 static void e1000e_disable_aspm(struct pci_dev
*pdev
, u16 state
)
5409 dev_info(&pdev
->dev
, "Disabling ASPM %s %s\n",
5410 (state
& PCIE_LINK_STATE_L0S
) ? "L0s" : "",
5411 (state
& PCIE_LINK_STATE_L1
) ? "L1" : "");
5413 __e1000e_disable_aspm(pdev
, state
);
5417 static bool e1000e_pm_ready(struct e1000_adapter
*adapter
)
5419 return !!adapter
->tx_ring
->buffer_info
;
5422 static int __e1000_resume(struct pci_dev
*pdev
)
5424 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5425 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5426 struct e1000_hw
*hw
= &adapter
->hw
;
5427 u16 aspm_disable_flag
= 0;
5430 if (adapter
->flags2
& FLAG2_DISABLE_ASPM_L0S
)
5431 aspm_disable_flag
= PCIE_LINK_STATE_L0S
;
5432 if (adapter
->flags2
& FLAG2_DISABLE_ASPM_L1
)
5433 aspm_disable_flag
|= PCIE_LINK_STATE_L1
;
5434 if (aspm_disable_flag
)
5435 e1000e_disable_aspm(pdev
, aspm_disable_flag
);
5437 pci_set_power_state(pdev
, PCI_D0
);
5438 pci_restore_state(pdev
);
5439 pci_save_state(pdev
);
5441 e1000e_set_interrupt_capability(adapter
);
5442 if (netif_running(netdev
)) {
5443 err
= e1000_request_irq(adapter
);
5448 e1000e_power_up_phy(adapter
);
5450 /* report the system wakeup cause from S3/S4 */
5451 if (adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
) {
5454 e1e_rphy(&adapter
->hw
, BM_WUS
, &phy_data
);
5456 e_info("PHY Wakeup cause - %s\n",
5457 phy_data
& E1000_WUS_EX
? "Unicast Packet" :
5458 phy_data
& E1000_WUS_MC
? "Multicast Packet" :
5459 phy_data
& E1000_WUS_BC
? "Broadcast Packet" :
5460 phy_data
& E1000_WUS_MAG
? "Magic Packet" :
5461 phy_data
& E1000_WUS_LNKC
? "Link Status "
5462 " Change" : "other");
5464 e1e_wphy(&adapter
->hw
, BM_WUS
, ~0);
5466 u32 wus
= er32(WUS
);
5468 e_info("MAC Wakeup cause - %s\n",
5469 wus
& E1000_WUS_EX
? "Unicast Packet" :
5470 wus
& E1000_WUS_MC
? "Multicast Packet" :
5471 wus
& E1000_WUS_BC
? "Broadcast Packet" :
5472 wus
& E1000_WUS_MAG
? "Magic Packet" :
5473 wus
& E1000_WUS_LNKC
? "Link Status Change" :
5479 e1000e_reset(adapter
);
5481 e1000_init_manageability_pt(adapter
);
5483 if (netif_running(netdev
))
5486 netif_device_attach(netdev
);
5489 * If the controller has AMT, do not set DRV_LOAD until the interface
5490 * is up. For all other cases, let the f/w know that the h/w is now
5491 * under the control of the driver.
5493 if (!(adapter
->flags
& FLAG_HAS_AMT
))
5494 e1000e_get_hw_control(adapter
);
5499 #ifdef CONFIG_PM_SLEEP
5500 static int e1000_suspend(struct device
*dev
)
5502 struct pci_dev
*pdev
= to_pci_dev(dev
);
5506 retval
= __e1000_shutdown(pdev
, &wake
, false);
5508 e1000_complete_shutdown(pdev
, true, wake
);
5513 static int e1000_resume(struct device
*dev
)
5515 struct pci_dev
*pdev
= to_pci_dev(dev
);
5516 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5517 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5519 if (e1000e_pm_ready(adapter
))
5520 adapter
->idle_check
= true;
5522 return __e1000_resume(pdev
);
5524 #endif /* CONFIG_PM_SLEEP */
5526 #ifdef CONFIG_PM_RUNTIME
5527 static int e1000_runtime_suspend(struct device
*dev
)
5529 struct pci_dev
*pdev
= to_pci_dev(dev
);
5530 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5531 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5533 if (e1000e_pm_ready(adapter
)) {
5536 __e1000_shutdown(pdev
, &wake
, true);
5542 static int e1000_idle(struct device
*dev
)
5544 struct pci_dev
*pdev
= to_pci_dev(dev
);
5545 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5546 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5548 if (!e1000e_pm_ready(adapter
))
5551 if (adapter
->idle_check
) {
5552 adapter
->idle_check
= false;
5553 if (!e1000e_has_link(adapter
))
5554 pm_schedule_suspend(dev
, MSEC_PER_SEC
);
5560 static int e1000_runtime_resume(struct device
*dev
)
5562 struct pci_dev
*pdev
= to_pci_dev(dev
);
5563 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5564 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5566 if (!e1000e_pm_ready(adapter
))
5569 adapter
->idle_check
= !dev
->power
.runtime_auto
;
5570 return __e1000_resume(pdev
);
5572 #endif /* CONFIG_PM_RUNTIME */
5573 #endif /* CONFIG_PM */
5575 static void e1000_shutdown(struct pci_dev
*pdev
)
5579 __e1000_shutdown(pdev
, &wake
, false);
5581 if (system_state
== SYSTEM_POWER_OFF
)
5582 e1000_complete_shutdown(pdev
, false, wake
);
5585 #ifdef CONFIG_NET_POLL_CONTROLLER
5587 static irqreturn_t
e1000_intr_msix(int irq
, void *data
)
5589 struct net_device
*netdev
= data
;
5590 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5592 if (adapter
->msix_entries
) {
5593 int vector
, msix_irq
;
5596 msix_irq
= adapter
->msix_entries
[vector
].vector
;
5597 disable_irq(msix_irq
);
5598 e1000_intr_msix_rx(msix_irq
, netdev
);
5599 enable_irq(msix_irq
);
5602 msix_irq
= adapter
->msix_entries
[vector
].vector
;
5603 disable_irq(msix_irq
);
5604 e1000_intr_msix_tx(msix_irq
, netdev
);
5605 enable_irq(msix_irq
);
5608 msix_irq
= adapter
->msix_entries
[vector
].vector
;
5609 disable_irq(msix_irq
);
5610 e1000_msix_other(msix_irq
, netdev
);
5611 enable_irq(msix_irq
);
5618 * Polling 'interrupt' - used by things like netconsole to send skbs
5619 * without having to re-enable interrupts. It's not called while
5620 * the interrupt routine is executing.
5622 static void e1000_netpoll(struct net_device
*netdev
)
5624 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5626 switch (adapter
->int_mode
) {
5627 case E1000E_INT_MODE_MSIX
:
5628 e1000_intr_msix(adapter
->pdev
->irq
, netdev
);
5630 case E1000E_INT_MODE_MSI
:
5631 disable_irq(adapter
->pdev
->irq
);
5632 e1000_intr_msi(adapter
->pdev
->irq
, netdev
);
5633 enable_irq(adapter
->pdev
->irq
);
5635 default: /* E1000E_INT_MODE_LEGACY */
5636 disable_irq(adapter
->pdev
->irq
);
5637 e1000_intr(adapter
->pdev
->irq
, netdev
);
5638 enable_irq(adapter
->pdev
->irq
);
5645 * e1000_io_error_detected - called when PCI error is detected
5646 * @pdev: Pointer to PCI device
5647 * @state: The current pci connection state
5649 * This function is called after a PCI bus error affecting
5650 * this device has been detected.
5652 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
5653 pci_channel_state_t state
)
5655 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5656 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5658 netif_device_detach(netdev
);
5660 if (state
== pci_channel_io_perm_failure
)
5661 return PCI_ERS_RESULT_DISCONNECT
;
5663 if (netif_running(netdev
))
5664 e1000e_down(adapter
);
5665 pci_disable_device(pdev
);
5667 /* Request a slot slot reset. */
5668 return PCI_ERS_RESULT_NEED_RESET
;
5672 * e1000_io_slot_reset - called after the pci bus has been reset.
5673 * @pdev: Pointer to PCI device
5675 * Restart the card from scratch, as if from a cold-boot. Implementation
5676 * resembles the first-half of the e1000_resume routine.
5678 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
5680 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5681 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5682 struct e1000_hw
*hw
= &adapter
->hw
;
5683 u16 aspm_disable_flag
= 0;
5685 pci_ers_result_t result
;
5687 if (adapter
->flags2
& FLAG2_DISABLE_ASPM_L0S
)
5688 aspm_disable_flag
= PCIE_LINK_STATE_L0S
;
5689 if (adapter
->flags2
& FLAG2_DISABLE_ASPM_L1
)
5690 aspm_disable_flag
|= PCIE_LINK_STATE_L1
;
5691 if (aspm_disable_flag
)
5692 e1000e_disable_aspm(pdev
, aspm_disable_flag
);
5694 err
= pci_enable_device_mem(pdev
);
5697 "Cannot re-enable PCI device after reset.\n");
5698 result
= PCI_ERS_RESULT_DISCONNECT
;
5700 pci_set_master(pdev
);
5701 pdev
->state_saved
= true;
5702 pci_restore_state(pdev
);
5704 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5705 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5707 e1000e_reset(adapter
);
5709 result
= PCI_ERS_RESULT_RECOVERED
;
5712 pci_cleanup_aer_uncorrect_error_status(pdev
);
5718 * e1000_io_resume - called when traffic can start flowing again.
5719 * @pdev: Pointer to PCI device
5721 * This callback is called when the error recovery driver tells us that
5722 * its OK to resume normal operation. Implementation resembles the
5723 * second-half of the e1000_resume routine.
5725 static void e1000_io_resume(struct pci_dev
*pdev
)
5727 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5728 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5730 e1000_init_manageability_pt(adapter
);
5732 if (netif_running(netdev
)) {
5733 if (e1000e_up(adapter
)) {
5735 "can't bring device back up after reset\n");
5740 netif_device_attach(netdev
);
5743 * If the controller has AMT, do not set DRV_LOAD until the interface
5744 * is up. For all other cases, let the f/w know that the h/w is now
5745 * under the control of the driver.
5747 if (!(adapter
->flags
& FLAG_HAS_AMT
))
5748 e1000e_get_hw_control(adapter
);
5752 static void e1000_print_device_info(struct e1000_adapter
*adapter
)
5754 struct e1000_hw
*hw
= &adapter
->hw
;
5755 struct net_device
*netdev
= adapter
->netdev
;
5757 u8 pba_str
[E1000_PBANUM_LENGTH
];
5759 /* print bus type/speed/width info */
5760 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
5762 ((hw
->bus
.width
== e1000_bus_width_pcie_x4
) ? "Width x4" :
5766 e_info("Intel(R) PRO/%s Network Connection\n",
5767 (hw
->phy
.type
== e1000_phy_ife
) ? "10/100" : "1000");
5768 ret_val
= e1000_read_pba_string_generic(hw
, pba_str
,
5769 E1000_PBANUM_LENGTH
);
5771 strncpy((char *)pba_str
, "Unknown", sizeof(pba_str
) - 1);
5772 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5773 hw
->mac
.type
, hw
->phy
.type
, pba_str
);
5776 static void e1000_eeprom_checks(struct e1000_adapter
*adapter
)
5778 struct e1000_hw
*hw
= &adapter
->hw
;
5782 if (hw
->mac
.type
!= e1000_82573
)
5785 ret_val
= e1000_read_nvm(hw
, NVM_INIT_CONTROL2_REG
, 1, &buf
);
5786 if (!ret_val
&& (!(le16_to_cpu(buf
) & (1 << 0)))) {
5787 /* Deep Smart Power Down (DSPD) */
5788 dev_warn(&adapter
->pdev
->dev
,
5789 "Warning: detected DSPD enabled in EEPROM\n");
5793 static const struct net_device_ops e1000e_netdev_ops
= {
5794 .ndo_open
= e1000_open
,
5795 .ndo_stop
= e1000_close
,
5796 .ndo_start_xmit
= e1000_xmit_frame
,
5797 .ndo_get_stats64
= e1000e_get_stats64
,
5798 .ndo_set_multicast_list
= e1000_set_multi
,
5799 .ndo_set_mac_address
= e1000_set_mac
,
5800 .ndo_change_mtu
= e1000_change_mtu
,
5801 .ndo_do_ioctl
= e1000_ioctl
,
5802 .ndo_tx_timeout
= e1000_tx_timeout
,
5803 .ndo_validate_addr
= eth_validate_addr
,
5805 .ndo_vlan_rx_add_vid
= e1000_vlan_rx_add_vid
,
5806 .ndo_vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
,
5807 #ifdef CONFIG_NET_POLL_CONTROLLER
5808 .ndo_poll_controller
= e1000_netpoll
,
5813 * e1000_probe - Device Initialization Routine
5814 * @pdev: PCI device information struct
5815 * @ent: entry in e1000_pci_tbl
5817 * Returns 0 on success, negative on failure
5819 * e1000_probe initializes an adapter identified by a pci_dev structure.
5820 * The OS initialization, configuring of the adapter private structure,
5821 * and a hardware reset occur.
5823 static int __devinit
e1000_probe(struct pci_dev
*pdev
,
5824 const struct pci_device_id
*ent
)
5826 struct net_device
*netdev
;
5827 struct e1000_adapter
*adapter
;
5828 struct e1000_hw
*hw
;
5829 const struct e1000_info
*ei
= e1000_info_tbl
[ent
->driver_data
];
5830 resource_size_t mmio_start
, mmio_len
;
5831 resource_size_t flash_start
, flash_len
;
5833 static int cards_found
;
5834 u16 aspm_disable_flag
= 0;
5835 int i
, err
, pci_using_dac
;
5836 u16 eeprom_data
= 0;
5837 u16 eeprom_apme_mask
= E1000_EEPROM_APME
;
5839 if (ei
->flags2
& FLAG2_DISABLE_ASPM_L0S
)
5840 aspm_disable_flag
= PCIE_LINK_STATE_L0S
;
5841 if (ei
->flags2
& FLAG2_DISABLE_ASPM_L1
)
5842 aspm_disable_flag
|= PCIE_LINK_STATE_L1
;
5843 if (aspm_disable_flag
)
5844 e1000e_disable_aspm(pdev
, aspm_disable_flag
);
5846 err
= pci_enable_device_mem(pdev
);
5851 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64));
5853 err
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64));
5857 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
5859 err
= dma_set_coherent_mask(&pdev
->dev
,
5862 dev_err(&pdev
->dev
, "No usable DMA "
5863 "configuration, aborting\n");
5869 err
= pci_request_selected_regions_exclusive(pdev
,
5870 pci_select_bars(pdev
, IORESOURCE_MEM
),
5871 e1000e_driver_name
);
5875 /* AER (Advanced Error Reporting) hooks */
5876 pci_enable_pcie_error_reporting(pdev
);
5878 pci_set_master(pdev
);
5879 /* PCI config space info */
5880 err
= pci_save_state(pdev
);
5882 goto err_alloc_etherdev
;
5885 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
5887 goto err_alloc_etherdev
;
5889 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
5891 netdev
->irq
= pdev
->irq
;
5893 pci_set_drvdata(pdev
, netdev
);
5894 adapter
= netdev_priv(netdev
);
5896 adapter
->netdev
= netdev
;
5897 adapter
->pdev
= pdev
;
5899 adapter
->pba
= ei
->pba
;
5900 adapter
->flags
= ei
->flags
;
5901 adapter
->flags2
= ei
->flags2
;
5902 adapter
->hw
.adapter
= adapter
;
5903 adapter
->hw
.mac
.type
= ei
->mac
;
5904 adapter
->max_hw_frame_size
= ei
->max_hw_frame_size
;
5905 adapter
->msg_enable
= (1 << NETIF_MSG_DRV
| NETIF_MSG_PROBE
) - 1;
5907 mmio_start
= pci_resource_start(pdev
, 0);
5908 mmio_len
= pci_resource_len(pdev
, 0);
5911 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
5912 if (!adapter
->hw
.hw_addr
)
5915 if ((adapter
->flags
& FLAG_HAS_FLASH
) &&
5916 (pci_resource_flags(pdev
, 1) & IORESOURCE_MEM
)) {
5917 flash_start
= pci_resource_start(pdev
, 1);
5918 flash_len
= pci_resource_len(pdev
, 1);
5919 adapter
->hw
.flash_address
= ioremap(flash_start
, flash_len
);
5920 if (!adapter
->hw
.flash_address
)
5924 /* construct the net_device struct */
5925 netdev
->netdev_ops
= &e1000e_netdev_ops
;
5926 e1000e_set_ethtool_ops(netdev
);
5927 netdev
->watchdog_timeo
= 5 * HZ
;
5928 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
5929 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
5931 netdev
->mem_start
= mmio_start
;
5932 netdev
->mem_end
= mmio_start
+ mmio_len
;
5934 adapter
->bd_number
= cards_found
++;
5936 e1000e_check_options(adapter
);
5938 /* setup adapter struct */
5939 err
= e1000_sw_init(adapter
);
5943 memcpy(&hw
->mac
.ops
, ei
->mac_ops
, sizeof(hw
->mac
.ops
));
5944 memcpy(&hw
->nvm
.ops
, ei
->nvm_ops
, sizeof(hw
->nvm
.ops
));
5945 memcpy(&hw
->phy
.ops
, ei
->phy_ops
, sizeof(hw
->phy
.ops
));
5947 err
= ei
->get_variants(adapter
);
5951 if ((adapter
->flags
& FLAG_IS_ICH
) &&
5952 (adapter
->flags
& FLAG_READ_ONLY_NVM
))
5953 e1000e_write_protect_nvm_ich8lan(&adapter
->hw
);
5955 hw
->mac
.ops
.get_bus_info(&adapter
->hw
);
5957 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
5959 /* Copper options */
5960 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
) {
5961 adapter
->hw
.phy
.mdix
= AUTO_ALL_MODES
;
5962 adapter
->hw
.phy
.disable_polarity_correction
= 0;
5963 adapter
->hw
.phy
.ms_type
= e1000_ms_hw_default
;
5966 if (e1000_check_reset_block(&adapter
->hw
))
5967 e_info("PHY reset is blocked due to SOL/IDER session.\n");
5969 netdev
->features
= NETIF_F_SG
|
5971 NETIF_F_HW_VLAN_TX
|
5974 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
)
5975 netdev
->features
|= NETIF_F_HW_VLAN_FILTER
;
5977 netdev
->features
|= NETIF_F_TSO
;
5978 netdev
->features
|= NETIF_F_TSO6
;
5980 netdev
->vlan_features
|= NETIF_F_TSO
;
5981 netdev
->vlan_features
|= NETIF_F_TSO6
;
5982 netdev
->vlan_features
|= NETIF_F_HW_CSUM
;
5983 netdev
->vlan_features
|= NETIF_F_SG
;
5985 if (pci_using_dac
) {
5986 netdev
->features
|= NETIF_F_HIGHDMA
;
5987 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
5990 if (e1000e_enable_mng_pass_thru(&adapter
->hw
))
5991 adapter
->flags
|= FLAG_MNG_PT_ENABLED
;
5994 * before reading the NVM, reset the controller to
5995 * put the device in a known good starting state
5997 adapter
->hw
.mac
.ops
.reset_hw(&adapter
->hw
);
6000 * systems with ASPM and others may see the checksum fail on the first
6001 * attempt. Let's give it a few tries
6004 if (e1000_validate_nvm_checksum(&adapter
->hw
) >= 0)
6007 e_err("The NVM Checksum Is Not Valid\n");
6013 e1000_eeprom_checks(adapter
);
6015 /* copy the MAC address */
6016 if (e1000e_read_mac_addr(&adapter
->hw
))
6017 e_err("NVM Read Error while reading MAC address\n");
6019 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
6020 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
6022 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
6023 e_err("Invalid MAC Address: %pM\n", netdev
->perm_addr
);
6028 init_timer(&adapter
->watchdog_timer
);
6029 adapter
->watchdog_timer
.function
= e1000_watchdog
;
6030 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
6032 init_timer(&adapter
->phy_info_timer
);
6033 adapter
->phy_info_timer
.function
= e1000_update_phy_info
;
6034 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
6036 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
6037 INIT_WORK(&adapter
->watchdog_task
, e1000_watchdog_task
);
6038 INIT_WORK(&adapter
->downshift_task
, e1000e_downshift_workaround
);
6039 INIT_WORK(&adapter
->update_phy_task
, e1000e_update_phy_task
);
6040 INIT_WORK(&adapter
->print_hang_task
, e1000_print_hw_hang
);
6042 /* Initialize link parameters. User can change them with ethtool */
6043 adapter
->hw
.mac
.autoneg
= 1;
6044 adapter
->fc_autoneg
= 1;
6045 adapter
->hw
.fc
.requested_mode
= e1000_fc_default
;
6046 adapter
->hw
.fc
.current_mode
= e1000_fc_default
;
6047 adapter
->hw
.phy
.autoneg_advertised
= 0x2f;
6049 /* ring size defaults */
6050 adapter
->rx_ring
->count
= 256;
6051 adapter
->tx_ring
->count
= 256;
6054 * Initial Wake on LAN setting - If APM wake is enabled in
6055 * the EEPROM, enable the ACPI Magic Packet filter
6057 if (adapter
->flags
& FLAG_APME_IN_WUC
) {
6058 /* APME bit in EEPROM is mapped to WUC.APME */
6059 eeprom_data
= er32(WUC
);
6060 eeprom_apme_mask
= E1000_WUC_APME
;
6061 if ((hw
->mac
.type
> e1000_ich10lan
) &&
6062 (eeprom_data
& E1000_WUC_PHY_WAKE
))
6063 adapter
->flags2
|= FLAG2_HAS_PHY_WAKEUP
;
6064 } else if (adapter
->flags
& FLAG_APME_IN_CTRL3
) {
6065 if (adapter
->flags
& FLAG_APME_CHECK_PORT_B
&&
6066 (adapter
->hw
.bus
.func
== 1))
6067 e1000_read_nvm(&adapter
->hw
,
6068 NVM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
6070 e1000_read_nvm(&adapter
->hw
,
6071 NVM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
6074 /* fetch WoL from EEPROM */
6075 if (eeprom_data
& eeprom_apme_mask
)
6076 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
6079 * now that we have the eeprom settings, apply the special cases
6080 * where the eeprom may be wrong or the board simply won't support
6081 * wake on lan on a particular port
6083 if (!(adapter
->flags
& FLAG_HAS_WOL
))
6084 adapter
->eeprom_wol
= 0;
6086 /* initialize the wol settings based on the eeprom settings */
6087 adapter
->wol
= adapter
->eeprom_wol
;
6088 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
6090 /* save off EEPROM version number */
6091 e1000_read_nvm(&adapter
->hw
, 5, 1, &adapter
->eeprom_vers
);
6093 /* reset the hardware with the new settings */
6094 e1000e_reset(adapter
);
6097 * If the controller has AMT, do not set DRV_LOAD until the interface
6098 * is up. For all other cases, let the f/w know that the h/w is now
6099 * under the control of the driver.
6101 if (!(adapter
->flags
& FLAG_HAS_AMT
))
6102 e1000e_get_hw_control(adapter
);
6104 strncpy(netdev
->name
, "eth%d", sizeof(netdev
->name
) - 1);
6105 err
= register_netdev(netdev
);
6109 /* carrier off reporting is important to ethtool even BEFORE open */
6110 netif_carrier_off(netdev
);
6112 e1000_print_device_info(adapter
);
6114 if (pci_dev_run_wake(pdev
))
6115 pm_runtime_put_noidle(&pdev
->dev
);
6120 if (!(adapter
->flags
& FLAG_HAS_AMT
))
6121 e1000e_release_hw_control(adapter
);
6123 if (!e1000_check_reset_block(&adapter
->hw
))
6124 e1000_phy_hw_reset(&adapter
->hw
);
6126 kfree(adapter
->tx_ring
);
6127 kfree(adapter
->rx_ring
);
6129 if (adapter
->hw
.flash_address
)
6130 iounmap(adapter
->hw
.flash_address
);
6131 e1000e_reset_interrupt_capability(adapter
);
6133 iounmap(adapter
->hw
.hw_addr
);
6135 free_netdev(netdev
);
6137 pci_release_selected_regions(pdev
,
6138 pci_select_bars(pdev
, IORESOURCE_MEM
));
6141 pci_disable_device(pdev
);
6146 * e1000_remove - Device Removal Routine
6147 * @pdev: PCI device information struct
6149 * e1000_remove is called by the PCI subsystem to alert the driver
6150 * that it should release a PCI device. The could be caused by a
6151 * Hot-Plug event, or because the driver is going to be removed from
6154 static void __devexit
e1000_remove(struct pci_dev
*pdev
)
6156 struct net_device
*netdev
= pci_get_drvdata(pdev
);
6157 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
6158 bool down
= test_bit(__E1000_DOWN
, &adapter
->state
);
6161 * The timers may be rescheduled, so explicitly disable them
6162 * from being rescheduled.
6165 set_bit(__E1000_DOWN
, &adapter
->state
);
6166 del_timer_sync(&adapter
->watchdog_timer
);
6167 del_timer_sync(&adapter
->phy_info_timer
);
6169 cancel_work_sync(&adapter
->reset_task
);
6170 cancel_work_sync(&adapter
->watchdog_task
);
6171 cancel_work_sync(&adapter
->downshift_task
);
6172 cancel_work_sync(&adapter
->update_phy_task
);
6173 cancel_work_sync(&adapter
->print_hang_task
);
6175 if (!(netdev
->flags
& IFF_UP
))
6176 e1000_power_down_phy(adapter
);
6178 /* Don't lie to e1000_close() down the road. */
6180 clear_bit(__E1000_DOWN
, &adapter
->state
);
6181 unregister_netdev(netdev
);
6183 if (pci_dev_run_wake(pdev
))
6184 pm_runtime_get_noresume(&pdev
->dev
);
6187 * Release control of h/w to f/w. If f/w is AMT enabled, this
6188 * would have already happened in close and is redundant.
6190 e1000e_release_hw_control(adapter
);
6192 e1000e_reset_interrupt_capability(adapter
);
6193 kfree(adapter
->tx_ring
);
6194 kfree(adapter
->rx_ring
);
6196 iounmap(adapter
->hw
.hw_addr
);
6197 if (adapter
->hw
.flash_address
)
6198 iounmap(adapter
->hw
.flash_address
);
6199 pci_release_selected_regions(pdev
,
6200 pci_select_bars(pdev
, IORESOURCE_MEM
));
6202 free_netdev(netdev
);
6205 pci_disable_pcie_error_reporting(pdev
);
6207 pci_disable_device(pdev
);
6210 /* PCI Error Recovery (ERS) */
6211 static struct pci_error_handlers e1000_err_handler
= {
6212 .error_detected
= e1000_io_error_detected
,
6213 .slot_reset
= e1000_io_slot_reset
,
6214 .resume
= e1000_io_resume
,
6217 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl
) = {
6218 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_COPPER
), board_82571
},
6219 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_FIBER
), board_82571
},
6220 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER
), board_82571
},
6221 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER_LP
), board_82571
},
6222 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_FIBER
), board_82571
},
6223 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES
), board_82571
},
6224 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_DUAL
), board_82571
},
6225 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_QUAD
), board_82571
},
6226 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571PT_QUAD_COPPER
), board_82571
},
6228 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI
), board_82572
},
6229 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_COPPER
), board_82572
},
6230 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_FIBER
), board_82572
},
6231 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_SERDES
), board_82572
},
6233 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E
), board_82573
},
6234 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E_IAMT
), board_82573
},
6235 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573L
), board_82573
},
6237 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82574L
), board_82574
},
6238 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82574LA
), board_82574
},
6239 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82583V
), board_82583
},
6241 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_DPT
),
6242 board_80003es2lan
},
6243 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_SPT
),
6244 board_80003es2lan
},
6245 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_DPT
),
6246 board_80003es2lan
},
6247 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_SPT
),
6248 board_80003es2lan
},
6250 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE
), board_ich8lan
},
6251 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_G
), board_ich8lan
},
6252 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_GT
), board_ich8lan
},
6253 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_AMT
), board_ich8lan
},
6254 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_C
), board_ich8lan
},
6255 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M
), board_ich8lan
},
6256 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M_AMT
), board_ich8lan
},
6257 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_82567V_3
), board_ich8lan
},
6259 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE
), board_ich9lan
},
6260 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_G
), board_ich9lan
},
6261 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_GT
), board_ich9lan
},
6262 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_AMT
), board_ich9lan
},
6263 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_C
), board_ich9lan
},
6264 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_BM
), board_ich9lan
},
6265 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M
), board_ich9lan
},
6266 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M_AMT
), board_ich9lan
},
6267 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M_V
), board_ich9lan
},
6269 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_LM
), board_ich9lan
},
6270 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_LF
), board_ich9lan
},
6271 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_V
), board_ich9lan
},
6273 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_LM
), board_ich10lan
},
6274 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_LF
), board_ich10lan
},
6275 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_V
), board_ich10lan
},
6277 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_M_HV_LM
), board_pchlan
},
6278 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_M_HV_LC
), board_pchlan
},
6279 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_D_HV_DM
), board_pchlan
},
6280 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_D_HV_DC
), board_pchlan
},
6282 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH2_LV_LM
), board_pch2lan
},
6283 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH2_LV_V
), board_pch2lan
},
6285 { } /* terminate list */
6287 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
6290 static const struct dev_pm_ops e1000_pm_ops
= {
6291 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend
, e1000_resume
)
6292 SET_RUNTIME_PM_OPS(e1000_runtime_suspend
,
6293 e1000_runtime_resume
, e1000_idle
)
6297 /* PCI Device API Driver */
6298 static struct pci_driver e1000_driver
= {
6299 .name
= e1000e_driver_name
,
6300 .id_table
= e1000_pci_tbl
,
6301 .probe
= e1000_probe
,
6302 .remove
= __devexit_p(e1000_remove
),
6304 .driver
.pm
= &e1000_pm_ops
,
6306 .shutdown
= e1000_shutdown
,
6307 .err_handler
= &e1000_err_handler
6311 * e1000_init_module - Driver Registration Routine
6313 * e1000_init_module is the first routine called when the driver is
6314 * loaded. All it does is register with the PCI subsystem.
6316 static int __init
e1000_init_module(void)
6319 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6320 e1000e_driver_version
);
6321 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
6322 ret
= pci_register_driver(&e1000_driver
);
6326 module_init(e1000_init_module
);
6329 * e1000_exit_module - Driver Exit Cleanup Routine
6331 * e1000_exit_module is called just before the driver is removed
6334 static void __exit
e1000_exit_module(void)
6336 pci_unregister_driver(&e1000_driver
);
6338 module_exit(e1000_exit_module
);
6341 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6342 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6343 MODULE_LICENSE("GPL");
6344 MODULE_VERSION(DRV_VERSION
);