1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2008 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 #include <linux/module.h>
30 #include <linux/types.h>
31 #include <linux/init.h>
32 #include <linux/pci.h>
33 #include <linux/vmalloc.h>
34 #include <linux/pagemap.h>
35 #include <linux/delay.h>
36 #include <linux/netdevice.h>
37 #include <linux/tcp.h>
38 #include <linux/ipv6.h>
39 #include <net/checksum.h>
40 #include <net/ip6_checksum.h>
41 #include <linux/mii.h>
42 #include <linux/ethtool.h>
43 #include <linux/if_vlan.h>
44 #include <linux/cpu.h>
45 #include <linux/smp.h>
46 #include <linux/pm_qos_params.h>
47 #include <linux/aer.h>
51 #define DRV_VERSION "1.0.2-k2"
52 char e1000e_driver_name
[] = "e1000e";
53 const char e1000e_driver_version
[] = DRV_VERSION
;
55 static const struct e1000_info
*e1000_info_tbl
[] = {
56 [board_82571
] = &e1000_82571_info
,
57 [board_82572
] = &e1000_82572_info
,
58 [board_82573
] = &e1000_82573_info
,
59 [board_82574
] = &e1000_82574_info
,
60 [board_82583
] = &e1000_82583_info
,
61 [board_80003es2lan
] = &e1000_es2_info
,
62 [board_ich8lan
] = &e1000_ich8_info
,
63 [board_ich9lan
] = &e1000_ich9_info
,
64 [board_ich10lan
] = &e1000_ich10_info
,
65 [board_pchlan
] = &e1000_pch_info
,
70 * e1000_get_hw_dev_name - return device name string
71 * used by hardware layer to print debugging information
73 char *e1000e_get_hw_dev_name(struct e1000_hw
*hw
)
75 return hw
->adapter
->netdev
->name
;
80 * e1000_desc_unused - calculate if we have unused descriptors
82 static int e1000_desc_unused(struct e1000_ring
*ring
)
84 if (ring
->next_to_clean
> ring
->next_to_use
)
85 return ring
->next_to_clean
- ring
->next_to_use
- 1;
87 return ring
->count
+ ring
->next_to_clean
- ring
->next_to_use
- 1;
91 * e1000_receive_skb - helper function to handle Rx indications
92 * @adapter: board private structure
93 * @status: descriptor status field as written by hardware
94 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
95 * @skb: pointer to sk_buff to be indicated to stack
97 static void e1000_receive_skb(struct e1000_adapter
*adapter
,
98 struct net_device
*netdev
,
100 u8 status
, __le16 vlan
)
102 skb
->protocol
= eth_type_trans(skb
, netdev
);
104 if (adapter
->vlgrp
&& (status
& E1000_RXD_STAT_VP
))
105 vlan_gro_receive(&adapter
->napi
, adapter
->vlgrp
,
106 le16_to_cpu(vlan
), skb
);
108 napi_gro_receive(&adapter
->napi
, skb
);
112 * e1000_rx_checksum - Receive Checksum Offload for 82543
113 * @adapter: board private structure
114 * @status_err: receive descriptor status and error fields
115 * @csum: receive descriptor csum field
116 * @sk_buff: socket buffer with received data
118 static void e1000_rx_checksum(struct e1000_adapter
*adapter
, u32 status_err
,
119 u32 csum
, struct sk_buff
*skb
)
121 u16 status
= (u16
)status_err
;
122 u8 errors
= (u8
)(status_err
>> 24);
123 skb
->ip_summed
= CHECKSUM_NONE
;
125 /* Ignore Checksum bit is set */
126 if (status
& E1000_RXD_STAT_IXSM
)
128 /* TCP/UDP checksum error bit is set */
129 if (errors
& E1000_RXD_ERR_TCPE
) {
130 /* let the stack verify checksum errors */
131 adapter
->hw_csum_err
++;
135 /* TCP/UDP Checksum has not been calculated */
136 if (!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
139 /* It must be a TCP or UDP packet with a valid checksum */
140 if (status
& E1000_RXD_STAT_TCPCS
) {
141 /* TCP checksum is good */
142 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
145 * IP fragment with UDP payload
146 * Hardware complements the payload checksum, so we undo it
147 * and then put the value in host order for further stack use.
149 __sum16 sum
= (__force __sum16
)htons(csum
);
150 skb
->csum
= csum_unfold(~sum
);
151 skb
->ip_summed
= CHECKSUM_COMPLETE
;
153 adapter
->hw_csum_good
++;
157 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
158 * @adapter: address of board private structure
160 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
163 struct net_device
*netdev
= adapter
->netdev
;
164 struct pci_dev
*pdev
= adapter
->pdev
;
165 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
166 struct e1000_rx_desc
*rx_desc
;
167 struct e1000_buffer
*buffer_info
;
170 unsigned int bufsz
= adapter
->rx_buffer_len
;
172 i
= rx_ring
->next_to_use
;
173 buffer_info
= &rx_ring
->buffer_info
[i
];
175 while (cleaned_count
--) {
176 skb
= buffer_info
->skb
;
182 skb
= netdev_alloc_skb_ip_align(netdev
, bufsz
);
184 /* Better luck next round */
185 adapter
->alloc_rx_buff_failed
++;
189 buffer_info
->skb
= skb
;
191 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
192 adapter
->rx_buffer_len
,
194 if (pci_dma_mapping_error(pdev
, buffer_info
->dma
)) {
195 dev_err(&pdev
->dev
, "RX DMA map failed\n");
196 adapter
->rx_dma_failed
++;
200 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
201 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
204 if (i
== rx_ring
->count
)
206 buffer_info
= &rx_ring
->buffer_info
[i
];
209 if (rx_ring
->next_to_use
!= i
) {
210 rx_ring
->next_to_use
= i
;
212 i
= (rx_ring
->count
- 1);
215 * Force memory writes to complete before letting h/w
216 * know there are new descriptors to fetch. (Only
217 * applicable for weak-ordered memory model archs,
221 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
226 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
227 * @adapter: address of board private structure
229 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
232 struct net_device
*netdev
= adapter
->netdev
;
233 struct pci_dev
*pdev
= adapter
->pdev
;
234 union e1000_rx_desc_packet_split
*rx_desc
;
235 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
236 struct e1000_buffer
*buffer_info
;
237 struct e1000_ps_page
*ps_page
;
241 i
= rx_ring
->next_to_use
;
242 buffer_info
= &rx_ring
->buffer_info
[i
];
244 while (cleaned_count
--) {
245 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
247 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
248 ps_page
= &buffer_info
->ps_pages
[j
];
249 if (j
>= adapter
->rx_ps_pages
) {
250 /* all unused desc entries get hw null ptr */
251 rx_desc
->read
.buffer_addr
[j
+1] = ~cpu_to_le64(0);
254 if (!ps_page
->page
) {
255 ps_page
->page
= alloc_page(GFP_ATOMIC
);
256 if (!ps_page
->page
) {
257 adapter
->alloc_rx_buff_failed
++;
260 ps_page
->dma
= pci_map_page(pdev
,
264 if (pci_dma_mapping_error(pdev
, ps_page
->dma
)) {
265 dev_err(&adapter
->pdev
->dev
,
266 "RX DMA page map failed\n");
267 adapter
->rx_dma_failed
++;
272 * Refresh the desc even if buffer_addrs
273 * didn't change because each write-back
276 rx_desc
->read
.buffer_addr
[j
+1] =
277 cpu_to_le64(ps_page
->dma
);
280 skb
= netdev_alloc_skb_ip_align(netdev
,
281 adapter
->rx_ps_bsize0
);
284 adapter
->alloc_rx_buff_failed
++;
288 buffer_info
->skb
= skb
;
289 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
290 adapter
->rx_ps_bsize0
,
292 if (pci_dma_mapping_error(pdev
, buffer_info
->dma
)) {
293 dev_err(&pdev
->dev
, "RX DMA map failed\n");
294 adapter
->rx_dma_failed
++;
296 dev_kfree_skb_any(skb
);
297 buffer_info
->skb
= NULL
;
301 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
304 if (i
== rx_ring
->count
)
306 buffer_info
= &rx_ring
->buffer_info
[i
];
310 if (rx_ring
->next_to_use
!= i
) {
311 rx_ring
->next_to_use
= i
;
314 i
= (rx_ring
->count
- 1);
317 * Force memory writes to complete before letting h/w
318 * know there are new descriptors to fetch. (Only
319 * applicable for weak-ordered memory model archs,
324 * Hardware increments by 16 bytes, but packet split
325 * descriptors are 32 bytes...so we increment tail
328 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
333 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
334 * @adapter: address of board private structure
335 * @cleaned_count: number of buffers to allocate this pass
338 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter
*adapter
,
341 struct net_device
*netdev
= adapter
->netdev
;
342 struct pci_dev
*pdev
= adapter
->pdev
;
343 struct e1000_rx_desc
*rx_desc
;
344 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
345 struct e1000_buffer
*buffer_info
;
348 unsigned int bufsz
= 256 - 16 /* for skb_reserve */;
350 i
= rx_ring
->next_to_use
;
351 buffer_info
= &rx_ring
->buffer_info
[i
];
353 while (cleaned_count
--) {
354 skb
= buffer_info
->skb
;
360 skb
= netdev_alloc_skb_ip_align(netdev
, bufsz
);
361 if (unlikely(!skb
)) {
362 /* Better luck next round */
363 adapter
->alloc_rx_buff_failed
++;
367 buffer_info
->skb
= skb
;
369 /* allocate a new page if necessary */
370 if (!buffer_info
->page
) {
371 buffer_info
->page
= alloc_page(GFP_ATOMIC
);
372 if (unlikely(!buffer_info
->page
)) {
373 adapter
->alloc_rx_buff_failed
++;
378 if (!buffer_info
->dma
)
379 buffer_info
->dma
= pci_map_page(pdev
,
380 buffer_info
->page
, 0,
384 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
385 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
387 if (unlikely(++i
== rx_ring
->count
))
389 buffer_info
= &rx_ring
->buffer_info
[i
];
392 if (likely(rx_ring
->next_to_use
!= i
)) {
393 rx_ring
->next_to_use
= i
;
394 if (unlikely(i
-- == 0))
395 i
= (rx_ring
->count
- 1);
397 /* Force memory writes to complete before letting h/w
398 * know there are new descriptors to fetch. (Only
399 * applicable for weak-ordered memory model archs,
402 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
407 * e1000_clean_rx_irq - Send received data up the network stack; legacy
408 * @adapter: board private structure
410 * the return value indicates whether actual cleaning was done, there
411 * is no guarantee that everything was cleaned
413 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
414 int *work_done
, int work_to_do
)
416 struct net_device
*netdev
= adapter
->netdev
;
417 struct pci_dev
*pdev
= adapter
->pdev
;
418 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
419 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
420 struct e1000_buffer
*buffer_info
, *next_buffer
;
423 int cleaned_count
= 0;
425 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
427 i
= rx_ring
->next_to_clean
;
428 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
429 buffer_info
= &rx_ring
->buffer_info
[i
];
431 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
435 if (*work_done
>= work_to_do
)
439 status
= rx_desc
->status
;
440 skb
= buffer_info
->skb
;
441 buffer_info
->skb
= NULL
;
443 prefetch(skb
->data
- NET_IP_ALIGN
);
446 if (i
== rx_ring
->count
)
448 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
451 next_buffer
= &rx_ring
->buffer_info
[i
];
455 pci_unmap_single(pdev
,
457 adapter
->rx_buffer_len
,
459 buffer_info
->dma
= 0;
461 length
= le16_to_cpu(rx_desc
->length
);
463 /* !EOP means multiple descriptors were used to store a single
464 * packet, also make sure the frame isn't just CRC only */
465 if (!(status
& E1000_RXD_STAT_EOP
) || (length
<= 4)) {
466 /* All receives must fit into a single buffer */
467 e_dbg("%s: Receive packet consumed multiple buffers\n",
470 buffer_info
->skb
= skb
;
474 if (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
) {
476 buffer_info
->skb
= skb
;
480 /* adjust length to remove Ethernet CRC */
481 if (!(adapter
->flags2
& FLAG2_CRC_STRIPPING
))
484 total_rx_bytes
+= length
;
488 * code added for copybreak, this should improve
489 * performance for small packets with large amounts
490 * of reassembly being done in the stack
492 if (length
< copybreak
) {
493 struct sk_buff
*new_skb
=
494 netdev_alloc_skb_ip_align(netdev
, length
);
496 skb_copy_to_linear_data_offset(new_skb
,
502 /* save the skb in buffer_info as good */
503 buffer_info
->skb
= skb
;
506 /* else just continue with the old one */
508 /* end copybreak code */
509 skb_put(skb
, length
);
511 /* Receive Checksum Offload */
512 e1000_rx_checksum(adapter
,
514 ((u32
)(rx_desc
->errors
) << 24),
515 le16_to_cpu(rx_desc
->csum
), skb
);
517 e1000_receive_skb(adapter
, netdev
, skb
,status
,rx_desc
->special
);
522 /* return some buffers to hardware, one at a time is too slow */
523 if (cleaned_count
>= E1000_RX_BUFFER_WRITE
) {
524 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
528 /* use prefetched values */
530 buffer_info
= next_buffer
;
532 rx_ring
->next_to_clean
= i
;
534 cleaned_count
= e1000_desc_unused(rx_ring
);
536 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
538 adapter
->total_rx_bytes
+= total_rx_bytes
;
539 adapter
->total_rx_packets
+= total_rx_packets
;
540 netdev
->stats
.rx_bytes
+= total_rx_bytes
;
541 netdev
->stats
.rx_packets
+= total_rx_packets
;
545 static void e1000_put_txbuf(struct e1000_adapter
*adapter
,
546 struct e1000_buffer
*buffer_info
)
548 buffer_info
->dma
= 0;
549 if (buffer_info
->skb
) {
550 skb_dma_unmap(&adapter
->pdev
->dev
, buffer_info
->skb
,
552 dev_kfree_skb_any(buffer_info
->skb
);
553 buffer_info
->skb
= NULL
;
555 buffer_info
->time_stamp
= 0;
558 static void e1000_print_tx_hang(struct e1000_adapter
*adapter
)
560 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
561 unsigned int i
= tx_ring
->next_to_clean
;
562 unsigned int eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
563 struct e1000_tx_desc
*eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
565 /* detected Tx unit hang */
566 e_err("Detected Tx Unit Hang:\n"
569 " next_to_use <%x>\n"
570 " next_to_clean <%x>\n"
571 "buffer_info[next_to_clean]:\n"
572 " time_stamp <%lx>\n"
573 " next_to_watch <%x>\n"
575 " next_to_watch.status <%x>\n",
576 readl(adapter
->hw
.hw_addr
+ tx_ring
->head
),
577 readl(adapter
->hw
.hw_addr
+ tx_ring
->tail
),
578 tx_ring
->next_to_use
,
579 tx_ring
->next_to_clean
,
580 tx_ring
->buffer_info
[eop
].time_stamp
,
583 eop_desc
->upper
.fields
.status
);
587 * e1000_clean_tx_irq - Reclaim resources after transmit completes
588 * @adapter: board private structure
590 * the return value indicates whether actual cleaning was done, there
591 * is no guarantee that everything was cleaned
593 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
)
595 struct net_device
*netdev
= adapter
->netdev
;
596 struct e1000_hw
*hw
= &adapter
->hw
;
597 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
598 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
599 struct e1000_buffer
*buffer_info
;
601 unsigned int count
= 0;
602 unsigned int total_tx_bytes
= 0, total_tx_packets
= 0;
604 i
= tx_ring
->next_to_clean
;
605 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
606 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
608 while ((eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) &&
609 (count
< tx_ring
->count
)) {
610 bool cleaned
= false;
611 for (; !cleaned
; count
++) {
612 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
613 buffer_info
= &tx_ring
->buffer_info
[i
];
614 cleaned
= (i
== eop
);
617 struct sk_buff
*skb
= buffer_info
->skb
;
618 unsigned int segs
, bytecount
;
619 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
620 /* multiply data chunks by size of headers */
621 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
623 total_tx_packets
+= segs
;
624 total_tx_bytes
+= bytecount
;
627 e1000_put_txbuf(adapter
, buffer_info
);
628 tx_desc
->upper
.data
= 0;
631 if (i
== tx_ring
->count
)
635 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
636 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
639 tx_ring
->next_to_clean
= i
;
641 #define TX_WAKE_THRESHOLD 32
642 if (count
&& netif_carrier_ok(netdev
) &&
643 e1000_desc_unused(tx_ring
) >= TX_WAKE_THRESHOLD
) {
644 /* Make sure that anybody stopping the queue after this
645 * sees the new next_to_clean.
649 if (netif_queue_stopped(netdev
) &&
650 !(test_bit(__E1000_DOWN
, &adapter
->state
))) {
651 netif_wake_queue(netdev
);
652 ++adapter
->restart_queue
;
656 if (adapter
->detect_tx_hung
) {
657 /* Detect a transmit hang in hardware, this serializes the
658 * check with the clearing of time_stamp and movement of i */
659 adapter
->detect_tx_hung
= 0;
660 if (tx_ring
->buffer_info
[i
].time_stamp
&&
661 time_after(jiffies
, tx_ring
->buffer_info
[i
].time_stamp
662 + (adapter
->tx_timeout_factor
* HZ
))
663 && !(er32(STATUS
) & E1000_STATUS_TXOFF
)) {
664 e1000_print_tx_hang(adapter
);
665 netif_stop_queue(netdev
);
668 adapter
->total_tx_bytes
+= total_tx_bytes
;
669 adapter
->total_tx_packets
+= total_tx_packets
;
670 netdev
->stats
.tx_bytes
+= total_tx_bytes
;
671 netdev
->stats
.tx_packets
+= total_tx_packets
;
672 return (count
< tx_ring
->count
);
676 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
677 * @adapter: board private structure
679 * the return value indicates whether actual cleaning was done, there
680 * is no guarantee that everything was cleaned
682 static bool e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
683 int *work_done
, int work_to_do
)
685 union e1000_rx_desc_packet_split
*rx_desc
, *next_rxd
;
686 struct net_device
*netdev
= adapter
->netdev
;
687 struct pci_dev
*pdev
= adapter
->pdev
;
688 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
689 struct e1000_buffer
*buffer_info
, *next_buffer
;
690 struct e1000_ps_page
*ps_page
;
694 int cleaned_count
= 0;
696 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
698 i
= rx_ring
->next_to_clean
;
699 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
700 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
701 buffer_info
= &rx_ring
->buffer_info
[i
];
703 while (staterr
& E1000_RXD_STAT_DD
) {
704 if (*work_done
>= work_to_do
)
707 skb
= buffer_info
->skb
;
709 /* in the packet split case this is header only */
710 prefetch(skb
->data
- NET_IP_ALIGN
);
713 if (i
== rx_ring
->count
)
715 next_rxd
= E1000_RX_DESC_PS(*rx_ring
, i
);
718 next_buffer
= &rx_ring
->buffer_info
[i
];
722 pci_unmap_single(pdev
, buffer_info
->dma
,
723 adapter
->rx_ps_bsize0
,
725 buffer_info
->dma
= 0;
727 if (!(staterr
& E1000_RXD_STAT_EOP
)) {
728 e_dbg("%s: Packet Split buffers didn't pick up the "
729 "full packet\n", netdev
->name
);
730 dev_kfree_skb_irq(skb
);
734 if (staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
) {
735 dev_kfree_skb_irq(skb
);
739 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
742 e_dbg("%s: Last part of the packet spanning multiple "
743 "descriptors\n", netdev
->name
);
744 dev_kfree_skb_irq(skb
);
749 skb_put(skb
, length
);
753 * this looks ugly, but it seems compiler issues make it
754 * more efficient than reusing j
756 int l1
= le16_to_cpu(rx_desc
->wb
.upper
.length
[0]);
759 * page alloc/put takes too long and effects small packet
760 * throughput, so unsplit small packets and save the alloc/put
761 * only valid in softirq (napi) context to call kmap_*
763 if (l1
&& (l1
<= copybreak
) &&
764 ((length
+ l1
) <= adapter
->rx_ps_bsize0
)) {
767 ps_page
= &buffer_info
->ps_pages
[0];
770 * there is no documentation about how to call
771 * kmap_atomic, so we can't hold the mapping
774 pci_dma_sync_single_for_cpu(pdev
, ps_page
->dma
,
775 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
776 vaddr
= kmap_atomic(ps_page
->page
, KM_SKB_DATA_SOFTIRQ
);
777 memcpy(skb_tail_pointer(skb
), vaddr
, l1
);
778 kunmap_atomic(vaddr
, KM_SKB_DATA_SOFTIRQ
);
779 pci_dma_sync_single_for_device(pdev
, ps_page
->dma
,
780 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
783 if (!(adapter
->flags2
& FLAG2_CRC_STRIPPING
))
791 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
792 length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
]);
796 ps_page
= &buffer_info
->ps_pages
[j
];
797 pci_unmap_page(pdev
, ps_page
->dma
, PAGE_SIZE
,
800 skb_fill_page_desc(skb
, j
, ps_page
->page
, 0, length
);
801 ps_page
->page
= NULL
;
803 skb
->data_len
+= length
;
804 skb
->truesize
+= length
;
807 /* strip the ethernet crc, problem is we're using pages now so
808 * this whole operation can get a little cpu intensive
810 if (!(adapter
->flags2
& FLAG2_CRC_STRIPPING
))
811 pskb_trim(skb
, skb
->len
- 4);
814 total_rx_bytes
+= skb
->len
;
817 e1000_rx_checksum(adapter
, staterr
, le16_to_cpu(
818 rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
), skb
);
820 if (rx_desc
->wb
.upper
.header_status
&
821 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP
))
822 adapter
->rx_hdr_split
++;
824 e1000_receive_skb(adapter
, netdev
, skb
,
825 staterr
, rx_desc
->wb
.middle
.vlan
);
828 rx_desc
->wb
.middle
.status_error
&= cpu_to_le32(~0xFF);
829 buffer_info
->skb
= NULL
;
831 /* return some buffers to hardware, one at a time is too slow */
832 if (cleaned_count
>= E1000_RX_BUFFER_WRITE
) {
833 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
837 /* use prefetched values */
839 buffer_info
= next_buffer
;
841 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
843 rx_ring
->next_to_clean
= i
;
845 cleaned_count
= e1000_desc_unused(rx_ring
);
847 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
849 adapter
->total_rx_bytes
+= total_rx_bytes
;
850 adapter
->total_rx_packets
+= total_rx_packets
;
851 netdev
->stats
.rx_bytes
+= total_rx_bytes
;
852 netdev
->stats
.rx_packets
+= total_rx_packets
;
857 * e1000_consume_page - helper function
859 static void e1000_consume_page(struct e1000_buffer
*bi
, struct sk_buff
*skb
,
864 skb
->data_len
+= length
;
865 skb
->truesize
+= length
;
869 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
870 * @adapter: board private structure
872 * the return value indicates whether actual cleaning was done, there
873 * is no guarantee that everything was cleaned
876 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter
*adapter
,
877 int *work_done
, int work_to_do
)
879 struct net_device
*netdev
= adapter
->netdev
;
880 struct pci_dev
*pdev
= adapter
->pdev
;
881 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
882 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
883 struct e1000_buffer
*buffer_info
, *next_buffer
;
886 int cleaned_count
= 0;
887 bool cleaned
= false;
888 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
890 i
= rx_ring
->next_to_clean
;
891 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
892 buffer_info
= &rx_ring
->buffer_info
[i
];
894 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
898 if (*work_done
>= work_to_do
)
902 status
= rx_desc
->status
;
903 skb
= buffer_info
->skb
;
904 buffer_info
->skb
= NULL
;
907 if (i
== rx_ring
->count
)
909 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
912 next_buffer
= &rx_ring
->buffer_info
[i
];
916 pci_unmap_page(pdev
, buffer_info
->dma
, PAGE_SIZE
,
918 buffer_info
->dma
= 0;
920 length
= le16_to_cpu(rx_desc
->length
);
922 /* errors is only valid for DD + EOP descriptors */
923 if (unlikely((status
& E1000_RXD_STAT_EOP
) &&
924 (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
))) {
925 /* recycle both page and skb */
926 buffer_info
->skb
= skb
;
927 /* an error means any chain goes out the window
929 if (rx_ring
->rx_skb_top
)
930 dev_kfree_skb(rx_ring
->rx_skb_top
);
931 rx_ring
->rx_skb_top
= NULL
;
935 #define rxtop rx_ring->rx_skb_top
936 if (!(status
& E1000_RXD_STAT_EOP
)) {
937 /* this descriptor is only the beginning (or middle) */
939 /* this is the beginning of a chain */
941 skb_fill_page_desc(rxtop
, 0, buffer_info
->page
,
944 /* this is the middle of a chain */
945 skb_fill_page_desc(rxtop
,
946 skb_shinfo(rxtop
)->nr_frags
,
947 buffer_info
->page
, 0, length
);
948 /* re-use the skb, only consumed the page */
949 buffer_info
->skb
= skb
;
951 e1000_consume_page(buffer_info
, rxtop
, length
);
955 /* end of the chain */
956 skb_fill_page_desc(rxtop
,
957 skb_shinfo(rxtop
)->nr_frags
,
958 buffer_info
->page
, 0, length
);
959 /* re-use the current skb, we only consumed the
961 buffer_info
->skb
= skb
;
964 e1000_consume_page(buffer_info
, skb
, length
);
966 /* no chain, got EOP, this buf is the packet
967 * copybreak to save the put_page/alloc_page */
968 if (length
<= copybreak
&&
969 skb_tailroom(skb
) >= length
) {
971 vaddr
= kmap_atomic(buffer_info
->page
,
972 KM_SKB_DATA_SOFTIRQ
);
973 memcpy(skb_tail_pointer(skb
), vaddr
,
976 KM_SKB_DATA_SOFTIRQ
);
977 /* re-use the page, so don't erase
978 * buffer_info->page */
979 skb_put(skb
, length
);
981 skb_fill_page_desc(skb
, 0,
982 buffer_info
->page
, 0,
984 e1000_consume_page(buffer_info
, skb
,
990 /* Receive Checksum Offload XXX recompute due to CRC strip? */
991 e1000_rx_checksum(adapter
,
993 ((u32
)(rx_desc
->errors
) << 24),
994 le16_to_cpu(rx_desc
->csum
), skb
);
996 /* probably a little skewed due to removing CRC */
997 total_rx_bytes
+= skb
->len
;
1000 /* eth type trans needs skb->data to point to something */
1001 if (!pskb_may_pull(skb
, ETH_HLEN
)) {
1002 e_err("pskb_may_pull failed.\n");
1007 e1000_receive_skb(adapter
, netdev
, skb
, status
,
1011 rx_desc
->status
= 0;
1013 /* return some buffers to hardware, one at a time is too slow */
1014 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
1015 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
1019 /* use prefetched values */
1021 buffer_info
= next_buffer
;
1023 rx_ring
->next_to_clean
= i
;
1025 cleaned_count
= e1000_desc_unused(rx_ring
);
1027 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
1029 adapter
->total_rx_bytes
+= total_rx_bytes
;
1030 adapter
->total_rx_packets
+= total_rx_packets
;
1031 netdev
->stats
.rx_bytes
+= total_rx_bytes
;
1032 netdev
->stats
.rx_packets
+= total_rx_packets
;
1037 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1038 * @adapter: board private structure
1040 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
)
1042 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1043 struct e1000_buffer
*buffer_info
;
1044 struct e1000_ps_page
*ps_page
;
1045 struct pci_dev
*pdev
= adapter
->pdev
;
1048 /* Free all the Rx ring sk_buffs */
1049 for (i
= 0; i
< rx_ring
->count
; i
++) {
1050 buffer_info
= &rx_ring
->buffer_info
[i
];
1051 if (buffer_info
->dma
) {
1052 if (adapter
->clean_rx
== e1000_clean_rx_irq
)
1053 pci_unmap_single(pdev
, buffer_info
->dma
,
1054 adapter
->rx_buffer_len
,
1055 PCI_DMA_FROMDEVICE
);
1056 else if (adapter
->clean_rx
== e1000_clean_jumbo_rx_irq
)
1057 pci_unmap_page(pdev
, buffer_info
->dma
,
1059 PCI_DMA_FROMDEVICE
);
1060 else if (adapter
->clean_rx
== e1000_clean_rx_irq_ps
)
1061 pci_unmap_single(pdev
, buffer_info
->dma
,
1062 adapter
->rx_ps_bsize0
,
1063 PCI_DMA_FROMDEVICE
);
1064 buffer_info
->dma
= 0;
1067 if (buffer_info
->page
) {
1068 put_page(buffer_info
->page
);
1069 buffer_info
->page
= NULL
;
1072 if (buffer_info
->skb
) {
1073 dev_kfree_skb(buffer_info
->skb
);
1074 buffer_info
->skb
= NULL
;
1077 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
1078 ps_page
= &buffer_info
->ps_pages
[j
];
1081 pci_unmap_page(pdev
, ps_page
->dma
, PAGE_SIZE
,
1082 PCI_DMA_FROMDEVICE
);
1084 put_page(ps_page
->page
);
1085 ps_page
->page
= NULL
;
1089 /* there also may be some cached data from a chained receive */
1090 if (rx_ring
->rx_skb_top
) {
1091 dev_kfree_skb(rx_ring
->rx_skb_top
);
1092 rx_ring
->rx_skb_top
= NULL
;
1095 /* Zero out the descriptor ring */
1096 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1098 rx_ring
->next_to_clean
= 0;
1099 rx_ring
->next_to_use
= 0;
1101 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1102 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1105 static void e1000e_downshift_workaround(struct work_struct
*work
)
1107 struct e1000_adapter
*adapter
= container_of(work
,
1108 struct e1000_adapter
, downshift_task
);
1110 e1000e_gig_downshift_workaround_ich8lan(&adapter
->hw
);
1114 * e1000_intr_msi - Interrupt Handler
1115 * @irq: interrupt number
1116 * @data: pointer to a network interface device structure
1118 static irqreturn_t
e1000_intr_msi(int irq
, void *data
)
1120 struct net_device
*netdev
= data
;
1121 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1122 struct e1000_hw
*hw
= &adapter
->hw
;
1123 u32 icr
= er32(ICR
);
1126 * read ICR disables interrupts using IAM
1129 if (icr
& E1000_ICR_LSC
) {
1130 hw
->mac
.get_link_status
= 1;
1132 * ICH8 workaround-- Call gig speed drop workaround on cable
1133 * disconnect (LSC) before accessing any PHY registers
1135 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
1136 (!(er32(STATUS
) & E1000_STATUS_LU
)))
1137 schedule_work(&adapter
->downshift_task
);
1140 * 80003ES2LAN workaround-- For packet buffer work-around on
1141 * link down event; disable receives here in the ISR and reset
1142 * adapter in watchdog
1144 if (netif_carrier_ok(netdev
) &&
1145 adapter
->flags
& FLAG_RX_NEEDS_RESTART
) {
1146 /* disable receives */
1147 u32 rctl
= er32(RCTL
);
1148 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1149 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
1151 /* guard against interrupt when we're going down */
1152 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1153 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1156 if (napi_schedule_prep(&adapter
->napi
)) {
1157 adapter
->total_tx_bytes
= 0;
1158 adapter
->total_tx_packets
= 0;
1159 adapter
->total_rx_bytes
= 0;
1160 adapter
->total_rx_packets
= 0;
1161 __napi_schedule(&adapter
->napi
);
1168 * e1000_intr - Interrupt Handler
1169 * @irq: interrupt number
1170 * @data: pointer to a network interface device structure
1172 static irqreturn_t
e1000_intr(int irq
, void *data
)
1174 struct net_device
*netdev
= data
;
1175 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1176 struct e1000_hw
*hw
= &adapter
->hw
;
1177 u32 rctl
, icr
= er32(ICR
);
1180 return IRQ_NONE
; /* Not our interrupt */
1183 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1184 * not set, then the adapter didn't send an interrupt
1186 if (!(icr
& E1000_ICR_INT_ASSERTED
))
1190 * Interrupt Auto-Mask...upon reading ICR,
1191 * interrupts are masked. No need for the
1195 if (icr
& E1000_ICR_LSC
) {
1196 hw
->mac
.get_link_status
= 1;
1198 * ICH8 workaround-- Call gig speed drop workaround on cable
1199 * disconnect (LSC) before accessing any PHY registers
1201 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
1202 (!(er32(STATUS
) & E1000_STATUS_LU
)))
1203 schedule_work(&adapter
->downshift_task
);
1206 * 80003ES2LAN workaround--
1207 * For packet buffer work-around on link down event;
1208 * disable receives here in the ISR and
1209 * reset adapter in watchdog
1211 if (netif_carrier_ok(netdev
) &&
1212 (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)) {
1213 /* disable receives */
1215 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1216 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
1218 /* guard against interrupt when we're going down */
1219 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1220 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1223 if (napi_schedule_prep(&adapter
->napi
)) {
1224 adapter
->total_tx_bytes
= 0;
1225 adapter
->total_tx_packets
= 0;
1226 adapter
->total_rx_bytes
= 0;
1227 adapter
->total_rx_packets
= 0;
1228 __napi_schedule(&adapter
->napi
);
1234 static irqreturn_t
e1000_msix_other(int irq
, void *data
)
1236 struct net_device
*netdev
= data
;
1237 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1238 struct e1000_hw
*hw
= &adapter
->hw
;
1239 u32 icr
= er32(ICR
);
1241 if (!(icr
& E1000_ICR_INT_ASSERTED
)) {
1242 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1243 ew32(IMS
, E1000_IMS_OTHER
);
1247 if (icr
& adapter
->eiac_mask
)
1248 ew32(ICS
, (icr
& adapter
->eiac_mask
));
1250 if (icr
& E1000_ICR_OTHER
) {
1251 if (!(icr
& E1000_ICR_LSC
))
1252 goto no_link_interrupt
;
1253 hw
->mac
.get_link_status
= 1;
1254 /* guard against interrupt when we're going down */
1255 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1256 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1260 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1261 ew32(IMS
, E1000_IMS_LSC
| E1000_IMS_OTHER
);
1267 static irqreturn_t
e1000_intr_msix_tx(int irq
, void *data
)
1269 struct net_device
*netdev
= data
;
1270 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1271 struct e1000_hw
*hw
= &adapter
->hw
;
1272 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1275 adapter
->total_tx_bytes
= 0;
1276 adapter
->total_tx_packets
= 0;
1278 if (!e1000_clean_tx_irq(adapter
))
1279 /* Ring was not completely cleaned, so fire another interrupt */
1280 ew32(ICS
, tx_ring
->ims_val
);
1285 static irqreturn_t
e1000_intr_msix_rx(int irq
, void *data
)
1287 struct net_device
*netdev
= data
;
1288 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1290 /* Write the ITR value calculated at the end of the
1291 * previous interrupt.
1293 if (adapter
->rx_ring
->set_itr
) {
1294 writel(1000000000 / (adapter
->rx_ring
->itr_val
* 256),
1295 adapter
->hw
.hw_addr
+ adapter
->rx_ring
->itr_register
);
1296 adapter
->rx_ring
->set_itr
= 0;
1299 if (napi_schedule_prep(&adapter
->napi
)) {
1300 adapter
->total_rx_bytes
= 0;
1301 adapter
->total_rx_packets
= 0;
1302 __napi_schedule(&adapter
->napi
);
1308 * e1000_configure_msix - Configure MSI-X hardware
1310 * e1000_configure_msix sets up the hardware to properly
1311 * generate MSI-X interrupts.
1313 static void e1000_configure_msix(struct e1000_adapter
*adapter
)
1315 struct e1000_hw
*hw
= &adapter
->hw
;
1316 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1317 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1319 u32 ctrl_ext
, ivar
= 0;
1321 adapter
->eiac_mask
= 0;
1323 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1324 if (hw
->mac
.type
== e1000_82574
) {
1325 u32 rfctl
= er32(RFCTL
);
1326 rfctl
|= E1000_RFCTL_ACK_DIS
;
1330 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1331 /* Configure Rx vector */
1332 rx_ring
->ims_val
= E1000_IMS_RXQ0
;
1333 adapter
->eiac_mask
|= rx_ring
->ims_val
;
1334 if (rx_ring
->itr_val
)
1335 writel(1000000000 / (rx_ring
->itr_val
* 256),
1336 hw
->hw_addr
+ rx_ring
->itr_register
);
1338 writel(1, hw
->hw_addr
+ rx_ring
->itr_register
);
1339 ivar
= E1000_IVAR_INT_ALLOC_VALID
| vector
;
1341 /* Configure Tx vector */
1342 tx_ring
->ims_val
= E1000_IMS_TXQ0
;
1344 if (tx_ring
->itr_val
)
1345 writel(1000000000 / (tx_ring
->itr_val
* 256),
1346 hw
->hw_addr
+ tx_ring
->itr_register
);
1348 writel(1, hw
->hw_addr
+ tx_ring
->itr_register
);
1349 adapter
->eiac_mask
|= tx_ring
->ims_val
;
1350 ivar
|= ((E1000_IVAR_INT_ALLOC_VALID
| vector
) << 8);
1352 /* set vector for Other Causes, e.g. link changes */
1354 ivar
|= ((E1000_IVAR_INT_ALLOC_VALID
| vector
) << 16);
1355 if (rx_ring
->itr_val
)
1356 writel(1000000000 / (rx_ring
->itr_val
* 256),
1357 hw
->hw_addr
+ E1000_EITR_82574(vector
));
1359 writel(1, hw
->hw_addr
+ E1000_EITR_82574(vector
));
1361 /* Cause Tx interrupts on every write back */
1366 /* enable MSI-X PBA support */
1367 ctrl_ext
= er32(CTRL_EXT
);
1368 ctrl_ext
|= E1000_CTRL_EXT_PBA_CLR
;
1370 /* Auto-Mask Other interrupts upon ICR read */
1371 #define E1000_EIAC_MASK_82574 0x01F00000
1372 ew32(IAM
, ~E1000_EIAC_MASK_82574
| E1000_IMS_OTHER
);
1373 ctrl_ext
|= E1000_CTRL_EXT_EIAME
;
1374 ew32(CTRL_EXT
, ctrl_ext
);
1378 void e1000e_reset_interrupt_capability(struct e1000_adapter
*adapter
)
1380 if (adapter
->msix_entries
) {
1381 pci_disable_msix(adapter
->pdev
);
1382 kfree(adapter
->msix_entries
);
1383 adapter
->msix_entries
= NULL
;
1384 } else if (adapter
->flags
& FLAG_MSI_ENABLED
) {
1385 pci_disable_msi(adapter
->pdev
);
1386 adapter
->flags
&= ~FLAG_MSI_ENABLED
;
1393 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1395 * Attempt to configure interrupts using the best available
1396 * capabilities of the hardware and kernel.
1398 void e1000e_set_interrupt_capability(struct e1000_adapter
*adapter
)
1404 switch (adapter
->int_mode
) {
1405 case E1000E_INT_MODE_MSIX
:
1406 if (adapter
->flags
& FLAG_HAS_MSIX
) {
1407 numvecs
= 3; /* RxQ0, TxQ0 and other */
1408 adapter
->msix_entries
= kcalloc(numvecs
,
1409 sizeof(struct msix_entry
),
1411 if (adapter
->msix_entries
) {
1412 for (i
= 0; i
< numvecs
; i
++)
1413 adapter
->msix_entries
[i
].entry
= i
;
1415 err
= pci_enable_msix(adapter
->pdev
,
1416 adapter
->msix_entries
,
1421 /* MSI-X failed, so fall through and try MSI */
1422 e_err("Failed to initialize MSI-X interrupts. "
1423 "Falling back to MSI interrupts.\n");
1424 e1000e_reset_interrupt_capability(adapter
);
1426 adapter
->int_mode
= E1000E_INT_MODE_MSI
;
1428 case E1000E_INT_MODE_MSI
:
1429 if (!pci_enable_msi(adapter
->pdev
)) {
1430 adapter
->flags
|= FLAG_MSI_ENABLED
;
1432 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
1433 e_err("Failed to initialize MSI interrupts. Falling "
1434 "back to legacy interrupts.\n");
1437 case E1000E_INT_MODE_LEGACY
:
1438 /* Don't do anything; this is the system default */
1446 * e1000_request_msix - Initialize MSI-X interrupts
1448 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1451 static int e1000_request_msix(struct e1000_adapter
*adapter
)
1453 struct net_device
*netdev
= adapter
->netdev
;
1454 int err
= 0, vector
= 0;
1456 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
1457 sprintf(adapter
->rx_ring
->name
, "%s-rx-0", netdev
->name
);
1459 memcpy(adapter
->rx_ring
->name
, netdev
->name
, IFNAMSIZ
);
1460 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1461 e1000_intr_msix_rx
, 0, adapter
->rx_ring
->name
,
1465 adapter
->rx_ring
->itr_register
= E1000_EITR_82574(vector
);
1466 adapter
->rx_ring
->itr_val
= adapter
->itr
;
1469 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
1470 sprintf(adapter
->tx_ring
->name
, "%s-tx-0", netdev
->name
);
1472 memcpy(adapter
->tx_ring
->name
, netdev
->name
, IFNAMSIZ
);
1473 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1474 e1000_intr_msix_tx
, 0, adapter
->tx_ring
->name
,
1478 adapter
->tx_ring
->itr_register
= E1000_EITR_82574(vector
);
1479 adapter
->tx_ring
->itr_val
= adapter
->itr
;
1482 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1483 e1000_msix_other
, 0, netdev
->name
, netdev
);
1487 e1000_configure_msix(adapter
);
1494 * e1000_request_irq - initialize interrupts
1496 * Attempts to configure interrupts using the best available
1497 * capabilities of the hardware and kernel.
1499 static int e1000_request_irq(struct e1000_adapter
*adapter
)
1501 struct net_device
*netdev
= adapter
->netdev
;
1504 if (adapter
->msix_entries
) {
1505 err
= e1000_request_msix(adapter
);
1508 /* fall back to MSI */
1509 e1000e_reset_interrupt_capability(adapter
);
1510 adapter
->int_mode
= E1000E_INT_MODE_MSI
;
1511 e1000e_set_interrupt_capability(adapter
);
1513 if (adapter
->flags
& FLAG_MSI_ENABLED
) {
1514 err
= request_irq(adapter
->pdev
->irq
, e1000_intr_msi
, 0,
1515 netdev
->name
, netdev
);
1519 /* fall back to legacy interrupt */
1520 e1000e_reset_interrupt_capability(adapter
);
1521 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
1524 err
= request_irq(adapter
->pdev
->irq
, e1000_intr
, IRQF_SHARED
,
1525 netdev
->name
, netdev
);
1527 e_err("Unable to allocate interrupt, Error: %d\n", err
);
1532 static void e1000_free_irq(struct e1000_adapter
*adapter
)
1534 struct net_device
*netdev
= adapter
->netdev
;
1536 if (adapter
->msix_entries
) {
1539 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
1542 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
1545 /* Other Causes interrupt vector */
1546 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
1550 free_irq(adapter
->pdev
->irq
, netdev
);
1554 * e1000_irq_disable - Mask off interrupt generation on the NIC
1556 static void e1000_irq_disable(struct e1000_adapter
*adapter
)
1558 struct e1000_hw
*hw
= &adapter
->hw
;
1561 if (adapter
->msix_entries
)
1562 ew32(EIAC_82574
, 0);
1564 synchronize_irq(adapter
->pdev
->irq
);
1568 * e1000_irq_enable - Enable default interrupt generation settings
1570 static void e1000_irq_enable(struct e1000_adapter
*adapter
)
1572 struct e1000_hw
*hw
= &adapter
->hw
;
1574 if (adapter
->msix_entries
) {
1575 ew32(EIAC_82574
, adapter
->eiac_mask
& E1000_EIAC_MASK_82574
);
1576 ew32(IMS
, adapter
->eiac_mask
| E1000_IMS_OTHER
| E1000_IMS_LSC
);
1578 ew32(IMS
, IMS_ENABLE_MASK
);
1584 * e1000_get_hw_control - get control of the h/w from f/w
1585 * @adapter: address of board private structure
1587 * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1588 * For ASF and Pass Through versions of f/w this means that
1589 * the driver is loaded. For AMT version (only with 82573)
1590 * of the f/w this means that the network i/f is open.
1592 static void e1000_get_hw_control(struct e1000_adapter
*adapter
)
1594 struct e1000_hw
*hw
= &adapter
->hw
;
1598 /* Let firmware know the driver has taken over */
1599 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
1601 ew32(SWSM
, swsm
| E1000_SWSM_DRV_LOAD
);
1602 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
1603 ctrl_ext
= er32(CTRL_EXT
);
1604 ew32(CTRL_EXT
, ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
1609 * e1000_release_hw_control - release control of the h/w to f/w
1610 * @adapter: address of board private structure
1612 * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1613 * For ASF and Pass Through versions of f/w this means that the
1614 * driver is no longer loaded. For AMT version (only with 82573) i
1615 * of the f/w this means that the network i/f is closed.
1618 static void e1000_release_hw_control(struct e1000_adapter
*adapter
)
1620 struct e1000_hw
*hw
= &adapter
->hw
;
1624 /* Let firmware taken over control of h/w */
1625 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
1627 ew32(SWSM
, swsm
& ~E1000_SWSM_DRV_LOAD
);
1628 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
1629 ctrl_ext
= er32(CTRL_EXT
);
1630 ew32(CTRL_EXT
, ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
1635 * @e1000_alloc_ring - allocate memory for a ring structure
1637 static int e1000_alloc_ring_dma(struct e1000_adapter
*adapter
,
1638 struct e1000_ring
*ring
)
1640 struct pci_dev
*pdev
= adapter
->pdev
;
1642 ring
->desc
= dma_alloc_coherent(&pdev
->dev
, ring
->size
, &ring
->dma
,
1651 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1652 * @adapter: board private structure
1654 * Return 0 on success, negative on failure
1656 int e1000e_setup_tx_resources(struct e1000_adapter
*adapter
)
1658 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1659 int err
= -ENOMEM
, size
;
1661 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1662 tx_ring
->buffer_info
= vmalloc(size
);
1663 if (!tx_ring
->buffer_info
)
1665 memset(tx_ring
->buffer_info
, 0, size
);
1667 /* round up to nearest 4K */
1668 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1669 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1671 err
= e1000_alloc_ring_dma(adapter
, tx_ring
);
1675 tx_ring
->next_to_use
= 0;
1676 tx_ring
->next_to_clean
= 0;
1680 vfree(tx_ring
->buffer_info
);
1681 e_err("Unable to allocate memory for the transmit descriptor ring\n");
1686 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1687 * @adapter: board private structure
1689 * Returns 0 on success, negative on failure
1691 int e1000e_setup_rx_resources(struct e1000_adapter
*adapter
)
1693 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1694 struct e1000_buffer
*buffer_info
;
1695 int i
, size
, desc_len
, err
= -ENOMEM
;
1697 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
1698 rx_ring
->buffer_info
= vmalloc(size
);
1699 if (!rx_ring
->buffer_info
)
1701 memset(rx_ring
->buffer_info
, 0, size
);
1703 for (i
= 0; i
< rx_ring
->count
; i
++) {
1704 buffer_info
= &rx_ring
->buffer_info
[i
];
1705 buffer_info
->ps_pages
= kcalloc(PS_PAGE_BUFFERS
,
1706 sizeof(struct e1000_ps_page
),
1708 if (!buffer_info
->ps_pages
)
1712 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1714 /* Round up to nearest 4K */
1715 rx_ring
->size
= rx_ring
->count
* desc_len
;
1716 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
1718 err
= e1000_alloc_ring_dma(adapter
, rx_ring
);
1722 rx_ring
->next_to_clean
= 0;
1723 rx_ring
->next_to_use
= 0;
1724 rx_ring
->rx_skb_top
= NULL
;
1729 for (i
= 0; i
< rx_ring
->count
; i
++) {
1730 buffer_info
= &rx_ring
->buffer_info
[i
];
1731 kfree(buffer_info
->ps_pages
);
1734 vfree(rx_ring
->buffer_info
);
1735 e_err("Unable to allocate memory for the transmit descriptor ring\n");
1740 * e1000_clean_tx_ring - Free Tx Buffers
1741 * @adapter: board private structure
1743 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
)
1745 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1746 struct e1000_buffer
*buffer_info
;
1750 for (i
= 0; i
< tx_ring
->count
; i
++) {
1751 buffer_info
= &tx_ring
->buffer_info
[i
];
1752 e1000_put_txbuf(adapter
, buffer_info
);
1755 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1756 memset(tx_ring
->buffer_info
, 0, size
);
1758 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1760 tx_ring
->next_to_use
= 0;
1761 tx_ring
->next_to_clean
= 0;
1763 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1764 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1768 * e1000e_free_tx_resources - Free Tx Resources per Queue
1769 * @adapter: board private structure
1771 * Free all transmit software resources
1773 void e1000e_free_tx_resources(struct e1000_adapter
*adapter
)
1775 struct pci_dev
*pdev
= adapter
->pdev
;
1776 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1778 e1000_clean_tx_ring(adapter
);
1780 vfree(tx_ring
->buffer_info
);
1781 tx_ring
->buffer_info
= NULL
;
1783 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1785 tx_ring
->desc
= NULL
;
1789 * e1000e_free_rx_resources - Free Rx Resources
1790 * @adapter: board private structure
1792 * Free all receive software resources
1795 void e1000e_free_rx_resources(struct e1000_adapter
*adapter
)
1797 struct pci_dev
*pdev
= adapter
->pdev
;
1798 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1801 e1000_clean_rx_ring(adapter
);
1803 for (i
= 0; i
< rx_ring
->count
; i
++) {
1804 kfree(rx_ring
->buffer_info
[i
].ps_pages
);
1807 vfree(rx_ring
->buffer_info
);
1808 rx_ring
->buffer_info
= NULL
;
1810 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
1812 rx_ring
->desc
= NULL
;
1816 * e1000_update_itr - update the dynamic ITR value based on statistics
1817 * @adapter: pointer to adapter
1818 * @itr_setting: current adapter->itr
1819 * @packets: the number of packets during this measurement interval
1820 * @bytes: the number of bytes during this measurement interval
1822 * Stores a new ITR value based on packets and byte
1823 * counts during the last interrupt. The advantage of per interrupt
1824 * computation is faster updates and more accurate ITR for the current
1825 * traffic pattern. Constants in this function were computed
1826 * based on theoretical maximum wire speed and thresholds were set based
1827 * on testing data as well as attempting to minimize response time
1828 * while increasing bulk throughput. This functionality is controlled
1829 * by the InterruptThrottleRate module parameter.
1831 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
1832 u16 itr_setting
, int packets
,
1835 unsigned int retval
= itr_setting
;
1838 goto update_itr_done
;
1840 switch (itr_setting
) {
1841 case lowest_latency
:
1842 /* handle TSO and jumbo frames */
1843 if (bytes
/packets
> 8000)
1844 retval
= bulk_latency
;
1845 else if ((packets
< 5) && (bytes
> 512)) {
1846 retval
= low_latency
;
1849 case low_latency
: /* 50 usec aka 20000 ints/s */
1850 if (bytes
> 10000) {
1851 /* this if handles the TSO accounting */
1852 if (bytes
/packets
> 8000) {
1853 retval
= bulk_latency
;
1854 } else if ((packets
< 10) || ((bytes
/packets
) > 1200)) {
1855 retval
= bulk_latency
;
1856 } else if ((packets
> 35)) {
1857 retval
= lowest_latency
;
1859 } else if (bytes
/packets
> 2000) {
1860 retval
= bulk_latency
;
1861 } else if (packets
<= 2 && bytes
< 512) {
1862 retval
= lowest_latency
;
1865 case bulk_latency
: /* 250 usec aka 4000 ints/s */
1866 if (bytes
> 25000) {
1868 retval
= low_latency
;
1870 } else if (bytes
< 6000) {
1871 retval
= low_latency
;
1880 static void e1000_set_itr(struct e1000_adapter
*adapter
)
1882 struct e1000_hw
*hw
= &adapter
->hw
;
1884 u32 new_itr
= adapter
->itr
;
1886 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1887 if (adapter
->link_speed
!= SPEED_1000
) {
1893 adapter
->tx_itr
= e1000_update_itr(adapter
,
1895 adapter
->total_tx_packets
,
1896 adapter
->total_tx_bytes
);
1897 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1898 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
1899 adapter
->tx_itr
= low_latency
;
1901 adapter
->rx_itr
= e1000_update_itr(adapter
,
1903 adapter
->total_rx_packets
,
1904 adapter
->total_rx_bytes
);
1905 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1906 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
1907 adapter
->rx_itr
= low_latency
;
1909 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
1911 switch (current_itr
) {
1912 /* counts and packets in update_itr are dependent on these numbers */
1913 case lowest_latency
:
1917 new_itr
= 20000; /* aka hwitr = ~200 */
1927 if (new_itr
!= adapter
->itr
) {
1929 * this attempts to bias the interrupt rate towards Bulk
1930 * by adding intermediate steps when interrupt rate is
1933 new_itr
= new_itr
> adapter
->itr
?
1934 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
1936 adapter
->itr
= new_itr
;
1937 adapter
->rx_ring
->itr_val
= new_itr
;
1938 if (adapter
->msix_entries
)
1939 adapter
->rx_ring
->set_itr
= 1;
1941 ew32(ITR
, 1000000000 / (new_itr
* 256));
1946 * e1000_alloc_queues - Allocate memory for all rings
1947 * @adapter: board private structure to initialize
1949 static int __devinit
e1000_alloc_queues(struct e1000_adapter
*adapter
)
1951 adapter
->tx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
1952 if (!adapter
->tx_ring
)
1955 adapter
->rx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
1956 if (!adapter
->rx_ring
)
1961 e_err("Unable to allocate memory for queues\n");
1962 kfree(adapter
->rx_ring
);
1963 kfree(adapter
->tx_ring
);
1968 * e1000_clean - NAPI Rx polling callback
1969 * @napi: struct associated with this polling callback
1970 * @budget: amount of packets driver is allowed to process this poll
1972 static int e1000_clean(struct napi_struct
*napi
, int budget
)
1974 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
, napi
);
1975 struct e1000_hw
*hw
= &adapter
->hw
;
1976 struct net_device
*poll_dev
= adapter
->netdev
;
1977 int tx_cleaned
= 1, work_done
= 0;
1979 adapter
= netdev_priv(poll_dev
);
1981 if (adapter
->msix_entries
&&
1982 !(adapter
->rx_ring
->ims_val
& adapter
->tx_ring
->ims_val
))
1985 tx_cleaned
= e1000_clean_tx_irq(adapter
);
1988 adapter
->clean_rx(adapter
, &work_done
, budget
);
1993 /* If budget not fully consumed, exit the polling mode */
1994 if (work_done
< budget
) {
1995 if (adapter
->itr_setting
& 3)
1996 e1000_set_itr(adapter
);
1997 napi_complete(napi
);
1998 if (!test_bit(__E1000_DOWN
, &adapter
->state
)) {
1999 if (adapter
->msix_entries
)
2000 ew32(IMS
, adapter
->rx_ring
->ims_val
);
2002 e1000_irq_enable(adapter
);
2009 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
2011 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2012 struct e1000_hw
*hw
= &adapter
->hw
;
2015 /* don't update vlan cookie if already programmed */
2016 if ((adapter
->hw
.mng_cookie
.status
&
2017 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
2018 (vid
== adapter
->mng_vlan_id
))
2020 /* add VID to filter table */
2021 index
= (vid
>> 5) & 0x7F;
2022 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
2023 vfta
|= (1 << (vid
& 0x1F));
2024 e1000e_write_vfta(hw
, index
, vfta
);
2027 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
2029 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2030 struct e1000_hw
*hw
= &adapter
->hw
;
2033 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2034 e1000_irq_disable(adapter
);
2035 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
2037 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2038 e1000_irq_enable(adapter
);
2040 if ((adapter
->hw
.mng_cookie
.status
&
2041 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
2042 (vid
== adapter
->mng_vlan_id
)) {
2043 /* release control to f/w */
2044 e1000_release_hw_control(adapter
);
2048 /* remove VID from filter table */
2049 index
= (vid
>> 5) & 0x7F;
2050 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
2051 vfta
&= ~(1 << (vid
& 0x1F));
2052 e1000e_write_vfta(hw
, index
, vfta
);
2055 static void e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
2057 struct net_device
*netdev
= adapter
->netdev
;
2058 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
2059 u16 old_vid
= adapter
->mng_vlan_id
;
2061 if (!adapter
->vlgrp
)
2064 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
2065 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
2066 if (adapter
->hw
.mng_cookie
.status
&
2067 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) {
2068 e1000_vlan_rx_add_vid(netdev
, vid
);
2069 adapter
->mng_vlan_id
= vid
;
2072 if ((old_vid
!= (u16
)E1000_MNG_VLAN_NONE
) &&
2074 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
2075 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
2077 adapter
->mng_vlan_id
= vid
;
2082 static void e1000_vlan_rx_register(struct net_device
*netdev
,
2083 struct vlan_group
*grp
)
2085 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2086 struct e1000_hw
*hw
= &adapter
->hw
;
2089 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2090 e1000_irq_disable(adapter
);
2091 adapter
->vlgrp
= grp
;
2094 /* enable VLAN tag insert/strip */
2096 ctrl
|= E1000_CTRL_VME
;
2099 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2100 /* enable VLAN receive filtering */
2102 rctl
&= ~E1000_RCTL_CFIEN
;
2104 e1000_update_mng_vlan(adapter
);
2107 /* disable VLAN tag insert/strip */
2109 ctrl
&= ~E1000_CTRL_VME
;
2112 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2113 if (adapter
->mng_vlan_id
!=
2114 (u16
)E1000_MNG_VLAN_NONE
) {
2115 e1000_vlan_rx_kill_vid(netdev
,
2116 adapter
->mng_vlan_id
);
2117 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
2122 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2123 e1000_irq_enable(adapter
);
2126 static void e1000_restore_vlan(struct e1000_adapter
*adapter
)
2130 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
2132 if (!adapter
->vlgrp
)
2135 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
2136 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
2138 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
2142 static void e1000_init_manageability(struct e1000_adapter
*adapter
)
2144 struct e1000_hw
*hw
= &adapter
->hw
;
2147 if (!(adapter
->flags
& FLAG_MNG_PT_ENABLED
))
2153 * enable receiving management packets to the host. this will probably
2154 * generate destination unreachable messages from the host OS, but
2155 * the packets will be handled on SMBUS
2157 manc
|= E1000_MANC_EN_MNG2HOST
;
2158 manc2h
= er32(MANC2H
);
2159 #define E1000_MNG2HOST_PORT_623 (1 << 5)
2160 #define E1000_MNG2HOST_PORT_664 (1 << 6)
2161 manc2h
|= E1000_MNG2HOST_PORT_623
;
2162 manc2h
|= E1000_MNG2HOST_PORT_664
;
2163 ew32(MANC2H
, manc2h
);
2168 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2169 * @adapter: board private structure
2171 * Configure the Tx unit of the MAC after a reset.
2173 static void e1000_configure_tx(struct e1000_adapter
*adapter
)
2175 struct e1000_hw
*hw
= &adapter
->hw
;
2176 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2178 u32 tdlen
, tctl
, tipg
, tarc
;
2181 /* Setup the HW Tx Head and Tail descriptor pointers */
2182 tdba
= tx_ring
->dma
;
2183 tdlen
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
2184 ew32(TDBAL
, (tdba
& DMA_BIT_MASK(32)));
2185 ew32(TDBAH
, (tdba
>> 32));
2189 tx_ring
->head
= E1000_TDH
;
2190 tx_ring
->tail
= E1000_TDT
;
2192 /* Set the default values for the Tx Inter Packet Gap timer */
2193 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
; /* 8 */
2194 ipgr1
= DEFAULT_82543_TIPG_IPGR1
; /* 8 */
2195 ipgr2
= DEFAULT_82543_TIPG_IPGR2
; /* 6 */
2197 if (adapter
->flags
& FLAG_TIPG_MEDIUM_FOR_80003ESLAN
)
2198 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
; /* 7 */
2200 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
2201 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
2204 /* Set the Tx Interrupt Delay register */
2205 ew32(TIDV
, adapter
->tx_int_delay
);
2206 /* Tx irq moderation */
2207 ew32(TADV
, adapter
->tx_abs_int_delay
);
2209 /* Program the Transmit Control Register */
2211 tctl
&= ~E1000_TCTL_CT
;
2212 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
2213 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
2215 if (adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) {
2216 tarc
= er32(TARC(0));
2218 * set the speed mode bit, we'll clear it if we're not at
2219 * gigabit link later
2221 #define SPEED_MODE_BIT (1 << 21)
2222 tarc
|= SPEED_MODE_BIT
;
2223 ew32(TARC(0), tarc
);
2226 /* errata: program both queues to unweighted RR */
2227 if (adapter
->flags
& FLAG_TARC_SET_BIT_ZERO
) {
2228 tarc
= er32(TARC(0));
2230 ew32(TARC(0), tarc
);
2231 tarc
= er32(TARC(1));
2233 ew32(TARC(1), tarc
);
2236 /* Setup Transmit Descriptor Settings for eop descriptor */
2237 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
2239 /* only set IDE if we are delaying interrupts using the timers */
2240 if (adapter
->tx_int_delay
)
2241 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
2243 /* enable Report Status bit */
2244 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
2248 e1000e_config_collision_dist(hw
);
2250 adapter
->tx_queue_len
= adapter
->netdev
->tx_queue_len
;
2254 * e1000_setup_rctl - configure the receive control registers
2255 * @adapter: Board private structure
2257 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2258 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2259 static void e1000_setup_rctl(struct e1000_adapter
*adapter
)
2261 struct e1000_hw
*hw
= &adapter
->hw
;
2266 /* Program MC offset vector base */
2268 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
2269 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
2270 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
2271 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
2273 /* Do not Store bad packets */
2274 rctl
&= ~E1000_RCTL_SBP
;
2276 /* Enable Long Packet receive */
2277 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
2278 rctl
&= ~E1000_RCTL_LPE
;
2280 rctl
|= E1000_RCTL_LPE
;
2282 /* Some systems expect that the CRC is included in SMBUS traffic. The
2283 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2284 * host memory when this is enabled
2286 if (adapter
->flags2
& FLAG2_CRC_STRIPPING
)
2287 rctl
|= E1000_RCTL_SECRC
;
2289 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2290 if ((hw
->phy
.type
== e1000_phy_82577
) && (rctl
& E1000_RCTL_LPE
)) {
2293 e1e_rphy(hw
, PHY_REG(770, 26), &phy_data
);
2295 phy_data
|= (1 << 2);
2296 e1e_wphy(hw
, PHY_REG(770, 26), phy_data
);
2298 e1e_rphy(hw
, 22, &phy_data
);
2300 phy_data
|= (1 << 14);
2301 e1e_wphy(hw
, 0x10, 0x2823);
2302 e1e_wphy(hw
, 0x11, 0x0003);
2303 e1e_wphy(hw
, 22, phy_data
);
2306 /* Setup buffer sizes */
2307 rctl
&= ~E1000_RCTL_SZ_4096
;
2308 rctl
|= E1000_RCTL_BSEX
;
2309 switch (adapter
->rx_buffer_len
) {
2311 rctl
|= E1000_RCTL_SZ_256
;
2312 rctl
&= ~E1000_RCTL_BSEX
;
2315 rctl
|= E1000_RCTL_SZ_512
;
2316 rctl
&= ~E1000_RCTL_BSEX
;
2319 rctl
|= E1000_RCTL_SZ_1024
;
2320 rctl
&= ~E1000_RCTL_BSEX
;
2324 rctl
|= E1000_RCTL_SZ_2048
;
2325 rctl
&= ~E1000_RCTL_BSEX
;
2328 rctl
|= E1000_RCTL_SZ_4096
;
2331 rctl
|= E1000_RCTL_SZ_8192
;
2334 rctl
|= E1000_RCTL_SZ_16384
;
2339 * 82571 and greater support packet-split where the protocol
2340 * header is placed in skb->data and the packet data is
2341 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2342 * In the case of a non-split, skb->data is linearly filled,
2343 * followed by the page buffers. Therefore, skb->data is
2344 * sized to hold the largest protocol header.
2346 * allocations using alloc_page take too long for regular MTU
2347 * so only enable packet split for jumbo frames
2349 * Using pages when the page size is greater than 16k wastes
2350 * a lot of memory, since we allocate 3 pages at all times
2353 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
2354 if (!(adapter
->flags
& FLAG_IS_ICH
) && (pages
<= 3) &&
2355 (PAGE_SIZE
<= 16384) && (rctl
& E1000_RCTL_LPE
))
2356 adapter
->rx_ps_pages
= pages
;
2358 adapter
->rx_ps_pages
= 0;
2360 if (adapter
->rx_ps_pages
) {
2361 /* Configure extra packet-split registers */
2362 rfctl
= er32(RFCTL
);
2363 rfctl
|= E1000_RFCTL_EXTEN
;
2365 * disable packet split support for IPv6 extension headers,
2366 * because some malformed IPv6 headers can hang the Rx
2368 rfctl
|= (E1000_RFCTL_IPV6_EX_DIS
|
2369 E1000_RFCTL_NEW_IPV6_EXT_DIS
);
2373 /* Enable Packet split descriptors */
2374 rctl
|= E1000_RCTL_DTYP_PS
;
2376 psrctl
|= adapter
->rx_ps_bsize0
>>
2377 E1000_PSRCTL_BSIZE0_SHIFT
;
2379 switch (adapter
->rx_ps_pages
) {
2381 psrctl
|= PAGE_SIZE
<<
2382 E1000_PSRCTL_BSIZE3_SHIFT
;
2384 psrctl
|= PAGE_SIZE
<<
2385 E1000_PSRCTL_BSIZE2_SHIFT
;
2387 psrctl
|= PAGE_SIZE
>>
2388 E1000_PSRCTL_BSIZE1_SHIFT
;
2392 ew32(PSRCTL
, psrctl
);
2396 /* just started the receive unit, no need to restart */
2397 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
2401 * e1000_configure_rx - Configure Receive Unit after Reset
2402 * @adapter: board private structure
2404 * Configure the Rx unit of the MAC after a reset.
2406 static void e1000_configure_rx(struct e1000_adapter
*adapter
)
2408 struct e1000_hw
*hw
= &adapter
->hw
;
2409 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
2411 u32 rdlen
, rctl
, rxcsum
, ctrl_ext
;
2413 if (adapter
->rx_ps_pages
) {
2414 /* this is a 32 byte descriptor */
2415 rdlen
= rx_ring
->count
*
2416 sizeof(union e1000_rx_desc_packet_split
);
2417 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
2418 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
2419 } else if (adapter
->netdev
->mtu
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
2420 rdlen
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
2421 adapter
->clean_rx
= e1000_clean_jumbo_rx_irq
;
2422 adapter
->alloc_rx_buf
= e1000_alloc_jumbo_rx_buffers
;
2424 rdlen
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
2425 adapter
->clean_rx
= e1000_clean_rx_irq
;
2426 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
2429 /* disable receives while setting up the descriptors */
2431 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
2435 /* set the Receive Delay Timer Register */
2436 ew32(RDTR
, adapter
->rx_int_delay
);
2438 /* irq moderation */
2439 ew32(RADV
, adapter
->rx_abs_int_delay
);
2440 if (adapter
->itr_setting
!= 0)
2441 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
2443 ctrl_ext
= er32(CTRL_EXT
);
2444 /* Reset delay timers after every interrupt */
2445 ctrl_ext
|= E1000_CTRL_EXT_INT_TIMER_CLR
;
2446 /* Auto-Mask interrupts upon ICR access */
2447 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
2448 ew32(IAM
, 0xffffffff);
2449 ew32(CTRL_EXT
, ctrl_ext
);
2453 * Setup the HW Rx Head and Tail Descriptor Pointers and
2454 * the Base and Length of the Rx Descriptor Ring
2456 rdba
= rx_ring
->dma
;
2457 ew32(RDBAL
, (rdba
& DMA_BIT_MASK(32)));
2458 ew32(RDBAH
, (rdba
>> 32));
2462 rx_ring
->head
= E1000_RDH
;
2463 rx_ring
->tail
= E1000_RDT
;
2465 /* Enable Receive Checksum Offload for TCP and UDP */
2466 rxcsum
= er32(RXCSUM
);
2467 if (adapter
->flags
& FLAG_RX_CSUM_ENABLED
) {
2468 rxcsum
|= E1000_RXCSUM_TUOFL
;
2471 * IPv4 payload checksum for UDP fragments must be
2472 * used in conjunction with packet-split.
2474 if (adapter
->rx_ps_pages
)
2475 rxcsum
|= E1000_RXCSUM_IPPCSE
;
2477 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
2478 /* no need to clear IPPCSE as it defaults to 0 */
2480 ew32(RXCSUM
, rxcsum
);
2483 * Enable early receives on supported devices, only takes effect when
2484 * packet size is equal or larger than the specified value (in 8 byte
2485 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2487 if ((adapter
->flags
& FLAG_HAS_ERT
) &&
2488 (adapter
->netdev
->mtu
> ETH_DATA_LEN
)) {
2489 u32 rxdctl
= er32(RXDCTL(0));
2490 ew32(RXDCTL(0), rxdctl
| 0x3);
2491 ew32(ERT
, E1000_ERT_2048
| (1 << 13));
2493 * With jumbo frames and early-receive enabled, excessive
2494 * C4->C2 latencies result in dropped transactions.
2496 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY
,
2497 e1000e_driver_name
, 55);
2499 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY
,
2501 PM_QOS_DEFAULT_VALUE
);
2504 /* Enable Receives */
2509 * e1000_update_mc_addr_list - Update Multicast addresses
2510 * @hw: pointer to the HW structure
2511 * @mc_addr_list: array of multicast addresses to program
2512 * @mc_addr_count: number of multicast addresses to program
2513 * @rar_used_count: the first RAR register free to program
2514 * @rar_count: total number of supported Receive Address Registers
2516 * Updates the Receive Address Registers and Multicast Table Array.
2517 * The caller must have a packed mc_addr_list of multicast addresses.
2518 * The parameter rar_count will usually be hw->mac.rar_entry_count
2519 * unless there are workarounds that change this. Currently no func pointer
2520 * exists and all implementations are handled in the generic version of this
2523 static void e1000_update_mc_addr_list(struct e1000_hw
*hw
, u8
*mc_addr_list
,
2524 u32 mc_addr_count
, u32 rar_used_count
,
2527 hw
->mac
.ops
.update_mc_addr_list(hw
, mc_addr_list
, mc_addr_count
,
2528 rar_used_count
, rar_count
);
2532 * e1000_set_multi - Multicast and Promiscuous mode set
2533 * @netdev: network interface device structure
2535 * The set_multi entry point is called whenever the multicast address
2536 * list or the network interface flags are updated. This routine is
2537 * responsible for configuring the hardware for proper multicast,
2538 * promiscuous mode, and all-multi behavior.
2540 static void e1000_set_multi(struct net_device
*netdev
)
2542 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2543 struct e1000_hw
*hw
= &adapter
->hw
;
2544 struct e1000_mac_info
*mac
= &hw
->mac
;
2545 struct dev_mc_list
*mc_ptr
;
2550 /* Check for Promiscuous and All Multicast modes */
2554 if (netdev
->flags
& IFF_PROMISC
) {
2555 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2556 rctl
&= ~E1000_RCTL_VFE
;
2558 if (netdev
->flags
& IFF_ALLMULTI
) {
2559 rctl
|= E1000_RCTL_MPE
;
2560 rctl
&= ~E1000_RCTL_UPE
;
2562 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2564 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
)
2565 rctl
|= E1000_RCTL_VFE
;
2570 if (netdev
->mc_count
) {
2571 mta_list
= kmalloc(netdev
->mc_count
* 6, GFP_ATOMIC
);
2575 /* prepare a packed array of only addresses. */
2576 mc_ptr
= netdev
->mc_list
;
2578 for (i
= 0; i
< netdev
->mc_count
; i
++) {
2581 memcpy(mta_list
+ (i
*ETH_ALEN
), mc_ptr
->dmi_addr
,
2583 mc_ptr
= mc_ptr
->next
;
2586 e1000_update_mc_addr_list(hw
, mta_list
, i
, 1,
2587 mac
->rar_entry_count
);
2591 * if we're called from probe, we might not have
2592 * anything to do here, so clear out the list
2594 e1000_update_mc_addr_list(hw
, NULL
, 0, 1, mac
->rar_entry_count
);
2599 * e1000_configure - configure the hardware for Rx and Tx
2600 * @adapter: private board structure
2602 static void e1000_configure(struct e1000_adapter
*adapter
)
2604 e1000_set_multi(adapter
->netdev
);
2606 e1000_restore_vlan(adapter
);
2607 e1000_init_manageability(adapter
);
2609 e1000_configure_tx(adapter
);
2610 e1000_setup_rctl(adapter
);
2611 e1000_configure_rx(adapter
);
2612 adapter
->alloc_rx_buf(adapter
, e1000_desc_unused(adapter
->rx_ring
));
2616 * e1000e_power_up_phy - restore link in case the phy was powered down
2617 * @adapter: address of board private structure
2619 * The phy may be powered down to save power and turn off link when the
2620 * driver is unloaded and wake on lan is not enabled (among others)
2621 * *** this routine MUST be followed by a call to e1000e_reset ***
2623 void e1000e_power_up_phy(struct e1000_adapter
*adapter
)
2627 /* Just clear the power down bit to wake the phy back up */
2628 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
) {
2630 * According to the manual, the phy will retain its
2631 * settings across a power-down/up cycle
2633 e1e_rphy(&adapter
->hw
, PHY_CONTROL
, &mii_reg
);
2634 mii_reg
&= ~MII_CR_POWER_DOWN
;
2635 e1e_wphy(&adapter
->hw
, PHY_CONTROL
, mii_reg
);
2638 adapter
->hw
.mac
.ops
.setup_link(&adapter
->hw
);
2642 * e1000_power_down_phy - Power down the PHY
2644 * Power down the PHY so no link is implied when interface is down
2645 * The PHY cannot be powered down is management or WoL is active
2647 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
2649 struct e1000_hw
*hw
= &adapter
->hw
;
2652 /* WoL is enabled */
2656 /* non-copper PHY? */
2657 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
2660 /* reset is blocked because of a SoL/IDER session */
2661 if (e1000e_check_mng_mode(hw
) || e1000_check_reset_block(hw
))
2664 /* manageability (AMT) is enabled */
2665 if (er32(MANC
) & E1000_MANC_SMBUS_EN
)
2668 /* power down the PHY */
2669 e1e_rphy(hw
, PHY_CONTROL
, &mii_reg
);
2670 mii_reg
|= MII_CR_POWER_DOWN
;
2671 e1e_wphy(hw
, PHY_CONTROL
, mii_reg
);
2676 * e1000e_reset - bring the hardware into a known good state
2678 * This function boots the hardware and enables some settings that
2679 * require a configuration cycle of the hardware - those cannot be
2680 * set/changed during runtime. After reset the device needs to be
2681 * properly configured for Rx, Tx etc.
2683 void e1000e_reset(struct e1000_adapter
*adapter
)
2685 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
2686 struct e1000_fc_info
*fc
= &adapter
->hw
.fc
;
2687 struct e1000_hw
*hw
= &adapter
->hw
;
2688 u32 tx_space
, min_tx_space
, min_rx_space
;
2689 u32 pba
= adapter
->pba
;
2692 /* reset Packet Buffer Allocation to default */
2695 if (adapter
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
2697 * To maintain wire speed transmits, the Tx FIFO should be
2698 * large enough to accommodate two full transmit packets,
2699 * rounded up to the next 1KB and expressed in KB. Likewise,
2700 * the Rx FIFO should be large enough to accommodate at least
2701 * one full receive packet and is similarly rounded up and
2705 /* upper 16 bits has Tx packet buffer allocation size in KB */
2706 tx_space
= pba
>> 16;
2707 /* lower 16 bits has Rx packet buffer allocation size in KB */
2710 * the Tx fifo also stores 16 bytes of information about the tx
2711 * but don't include ethernet FCS because hardware appends it
2713 min_tx_space
= (adapter
->max_frame_size
+
2714 sizeof(struct e1000_tx_desc
) -
2716 min_tx_space
= ALIGN(min_tx_space
, 1024);
2717 min_tx_space
>>= 10;
2718 /* software strips receive CRC, so leave room for it */
2719 min_rx_space
= adapter
->max_frame_size
;
2720 min_rx_space
= ALIGN(min_rx_space
, 1024);
2721 min_rx_space
>>= 10;
2724 * If current Tx allocation is less than the min Tx FIFO size,
2725 * and the min Tx FIFO size is less than the current Rx FIFO
2726 * allocation, take space away from current Rx allocation
2728 if ((tx_space
< min_tx_space
) &&
2729 ((min_tx_space
- tx_space
) < pba
)) {
2730 pba
-= min_tx_space
- tx_space
;
2733 * if short on Rx space, Rx wins and must trump tx
2734 * adjustment or use Early Receive if available
2736 if ((pba
< min_rx_space
) &&
2737 (!(adapter
->flags
& FLAG_HAS_ERT
)))
2738 /* ERT enabled in e1000_configure_rx */
2747 * flow control settings
2749 * The high water mark must be low enough to fit two full frame
2750 * (or the size used for early receive) above it in the Rx FIFO.
2751 * Set it to the lower of:
2752 * - 90% of the Rx FIFO size, and
2753 * - the full Rx FIFO size minus the early receive size (for parts
2754 * with ERT support assuming ERT set to E1000_ERT_2048), or
2755 * - the full Rx FIFO size minus two full frames
2757 if ((adapter
->flags
& FLAG_HAS_ERT
) &&
2758 (adapter
->netdev
->mtu
> ETH_DATA_LEN
))
2759 hwm
= min(((pba
<< 10) * 9 / 10),
2760 ((pba
<< 10) - (E1000_ERT_2048
<< 3)));
2762 hwm
= min(((pba
<< 10) * 9 / 10),
2763 ((pba
<< 10) - (2 * adapter
->max_frame_size
)));
2765 fc
->high_water
= hwm
& E1000_FCRTH_RTH
; /* 8-byte granularity */
2766 fc
->low_water
= (fc
->high_water
- (2 * adapter
->max_frame_size
));
2767 fc
->low_water
&= E1000_FCRTL_RTL
; /* 8-byte granularity */
2769 if (adapter
->flags
& FLAG_DISABLE_FC_PAUSE_TIME
)
2770 fc
->pause_time
= 0xFFFF;
2772 fc
->pause_time
= E1000_FC_PAUSE_TIME
;
2774 fc
->current_mode
= fc
->requested_mode
;
2776 /* Allow time for pending master requests to run */
2777 mac
->ops
.reset_hw(hw
);
2780 * For parts with AMT enabled, let the firmware know
2781 * that the network interface is in control
2783 if (adapter
->flags
& FLAG_HAS_AMT
)
2784 e1000_get_hw_control(adapter
);
2787 if (adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
)
2788 e1e_wphy(&adapter
->hw
, BM_WUC
, 0);
2790 if (mac
->ops
.init_hw(hw
))
2791 e_err("Hardware Error\n");
2793 e1000_update_mng_vlan(adapter
);
2795 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2796 ew32(VET
, ETH_P_8021Q
);
2798 e1000e_reset_adaptive(hw
);
2799 e1000_get_phy_info(hw
);
2801 if ((adapter
->flags
& FLAG_HAS_SMART_POWER_DOWN
) &&
2802 !(adapter
->flags
& FLAG_SMART_POWER_DOWN
)) {
2805 * speed up time to link by disabling smart power down, ignore
2806 * the return value of this function because there is nothing
2807 * different we would do if it failed
2809 e1e_rphy(hw
, IGP02E1000_PHY_POWER_MGMT
, &phy_data
);
2810 phy_data
&= ~IGP02E1000_PM_SPD
;
2811 e1e_wphy(hw
, IGP02E1000_PHY_POWER_MGMT
, phy_data
);
2815 int e1000e_up(struct e1000_adapter
*adapter
)
2817 struct e1000_hw
*hw
= &adapter
->hw
;
2819 /* hardware has been reset, we need to reload some things */
2820 e1000_configure(adapter
);
2822 clear_bit(__E1000_DOWN
, &adapter
->state
);
2824 napi_enable(&adapter
->napi
);
2825 if (adapter
->msix_entries
)
2826 e1000_configure_msix(adapter
);
2827 e1000_irq_enable(adapter
);
2829 netif_wake_queue(adapter
->netdev
);
2831 /* fire a link change interrupt to start the watchdog */
2832 ew32(ICS
, E1000_ICS_LSC
);
2836 void e1000e_down(struct e1000_adapter
*adapter
)
2838 struct net_device
*netdev
= adapter
->netdev
;
2839 struct e1000_hw
*hw
= &adapter
->hw
;
2843 * signal that we're down so the interrupt handler does not
2844 * reschedule our watchdog timer
2846 set_bit(__E1000_DOWN
, &adapter
->state
);
2848 /* disable receives in the hardware */
2850 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
2851 /* flush and sleep below */
2853 netif_stop_queue(netdev
);
2855 /* disable transmits in the hardware */
2857 tctl
&= ~E1000_TCTL_EN
;
2859 /* flush both disables and wait for them to finish */
2863 napi_disable(&adapter
->napi
);
2864 e1000_irq_disable(adapter
);
2866 del_timer_sync(&adapter
->watchdog_timer
);
2867 del_timer_sync(&adapter
->phy_info_timer
);
2869 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2870 netif_carrier_off(netdev
);
2871 adapter
->link_speed
= 0;
2872 adapter
->link_duplex
= 0;
2874 if (!pci_channel_offline(adapter
->pdev
))
2875 e1000e_reset(adapter
);
2876 e1000_clean_tx_ring(adapter
);
2877 e1000_clean_rx_ring(adapter
);
2880 * TODO: for power management, we could drop the link and
2881 * pci_disable_device here.
2885 void e1000e_reinit_locked(struct e1000_adapter
*adapter
)
2888 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
2890 e1000e_down(adapter
);
2892 clear_bit(__E1000_RESETTING
, &adapter
->state
);
2896 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2897 * @adapter: board private structure to initialize
2899 * e1000_sw_init initializes the Adapter private data structure.
2900 * Fields are initialized based on PCI device information and
2901 * OS network device settings (MTU size).
2903 static int __devinit
e1000_sw_init(struct e1000_adapter
*adapter
)
2905 struct net_device
*netdev
= adapter
->netdev
;
2907 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
;
2908 adapter
->rx_ps_bsize0
= 128;
2909 adapter
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2910 adapter
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
2912 e1000e_set_interrupt_capability(adapter
);
2914 if (e1000_alloc_queues(adapter
))
2917 /* Explicitly disable IRQ since the NIC can be in any state. */
2918 e1000_irq_disable(adapter
);
2920 set_bit(__E1000_DOWN
, &adapter
->state
);
2925 * e1000_intr_msi_test - Interrupt Handler
2926 * @irq: interrupt number
2927 * @data: pointer to a network interface device structure
2929 static irqreturn_t
e1000_intr_msi_test(int irq
, void *data
)
2931 struct net_device
*netdev
= data
;
2932 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2933 struct e1000_hw
*hw
= &adapter
->hw
;
2934 u32 icr
= er32(ICR
);
2936 e_dbg("%s: icr is %08X\n", netdev
->name
, icr
);
2937 if (icr
& E1000_ICR_RXSEQ
) {
2938 adapter
->flags
&= ~FLAG_MSI_TEST_FAILED
;
2946 * e1000_test_msi_interrupt - Returns 0 for successful test
2947 * @adapter: board private struct
2949 * code flow taken from tg3.c
2951 static int e1000_test_msi_interrupt(struct e1000_adapter
*adapter
)
2953 struct net_device
*netdev
= adapter
->netdev
;
2954 struct e1000_hw
*hw
= &adapter
->hw
;
2957 /* poll_enable hasn't been called yet, so don't need disable */
2958 /* clear any pending events */
2961 /* free the real vector and request a test handler */
2962 e1000_free_irq(adapter
);
2963 e1000e_reset_interrupt_capability(adapter
);
2965 /* Assume that the test fails, if it succeeds then the test
2966 * MSI irq handler will unset this flag */
2967 adapter
->flags
|= FLAG_MSI_TEST_FAILED
;
2969 err
= pci_enable_msi(adapter
->pdev
);
2971 goto msi_test_failed
;
2973 err
= request_irq(adapter
->pdev
->irq
, e1000_intr_msi_test
, 0,
2974 netdev
->name
, netdev
);
2976 pci_disable_msi(adapter
->pdev
);
2977 goto msi_test_failed
;
2982 e1000_irq_enable(adapter
);
2984 /* fire an unusual interrupt on the test handler */
2985 ew32(ICS
, E1000_ICS_RXSEQ
);
2989 e1000_irq_disable(adapter
);
2993 if (adapter
->flags
& FLAG_MSI_TEST_FAILED
) {
2994 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
2996 e_info("MSI interrupt test failed!\n");
2999 free_irq(adapter
->pdev
->irq
, netdev
);
3000 pci_disable_msi(adapter
->pdev
);
3003 goto msi_test_failed
;
3005 /* okay so the test worked, restore settings */
3006 e_dbg("%s: MSI interrupt test succeeded!\n", netdev
->name
);
3008 e1000e_set_interrupt_capability(adapter
);
3009 e1000_request_irq(adapter
);
3014 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3015 * @adapter: board private struct
3017 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3019 static int e1000_test_msi(struct e1000_adapter
*adapter
)
3024 if (!(adapter
->flags
& FLAG_MSI_ENABLED
))
3027 /* disable SERR in case the MSI write causes a master abort */
3028 pci_read_config_word(adapter
->pdev
, PCI_COMMAND
, &pci_cmd
);
3029 pci_write_config_word(adapter
->pdev
, PCI_COMMAND
,
3030 pci_cmd
& ~PCI_COMMAND_SERR
);
3032 err
= e1000_test_msi_interrupt(adapter
);
3034 /* restore previous setting of command word */
3035 pci_write_config_word(adapter
->pdev
, PCI_COMMAND
, pci_cmd
);
3041 /* EIO means MSI test failed */
3045 /* back to INTx mode */
3046 e_warn("MSI interrupt test failed, using legacy interrupt.\n");
3048 e1000_free_irq(adapter
);
3050 err
= e1000_request_irq(adapter
);
3056 * e1000_open - Called when a network interface is made active
3057 * @netdev: network interface device structure
3059 * Returns 0 on success, negative value on failure
3061 * The open entry point is called when a network interface is made
3062 * active by the system (IFF_UP). At this point all resources needed
3063 * for transmit and receive operations are allocated, the interrupt
3064 * handler is registered with the OS, the watchdog timer is started,
3065 * and the stack is notified that the interface is ready.
3067 static int e1000_open(struct net_device
*netdev
)
3069 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3070 struct e1000_hw
*hw
= &adapter
->hw
;
3073 /* disallow open during test */
3074 if (test_bit(__E1000_TESTING
, &adapter
->state
))
3077 netif_carrier_off(netdev
);
3079 /* allocate transmit descriptors */
3080 err
= e1000e_setup_tx_resources(adapter
);
3084 /* allocate receive descriptors */
3085 err
= e1000e_setup_rx_resources(adapter
);
3089 e1000e_power_up_phy(adapter
);
3091 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
3092 if ((adapter
->hw
.mng_cookie
.status
&
3093 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
))
3094 e1000_update_mng_vlan(adapter
);
3097 * If AMT is enabled, let the firmware know that the network
3098 * interface is now open
3100 if (adapter
->flags
& FLAG_HAS_AMT
)
3101 e1000_get_hw_control(adapter
);
3104 * before we allocate an interrupt, we must be ready to handle it.
3105 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3106 * as soon as we call pci_request_irq, so we have to setup our
3107 * clean_rx handler before we do so.
3109 e1000_configure(adapter
);
3111 err
= e1000_request_irq(adapter
);
3116 * Work around PCIe errata with MSI interrupts causing some chipsets to
3117 * ignore e1000e MSI messages, which means we need to test our MSI
3120 if (adapter
->int_mode
!= E1000E_INT_MODE_LEGACY
) {
3121 err
= e1000_test_msi(adapter
);
3123 e_err("Interrupt allocation failed\n");
3128 /* From here on the code is the same as e1000e_up() */
3129 clear_bit(__E1000_DOWN
, &adapter
->state
);
3131 napi_enable(&adapter
->napi
);
3133 e1000_irq_enable(adapter
);
3135 netif_start_queue(netdev
);
3137 /* fire a link status change interrupt to start the watchdog */
3138 ew32(ICS
, E1000_ICS_LSC
);
3143 e1000_release_hw_control(adapter
);
3144 e1000_power_down_phy(adapter
);
3145 e1000e_free_rx_resources(adapter
);
3147 e1000e_free_tx_resources(adapter
);
3149 e1000e_reset(adapter
);
3155 * e1000_close - Disables a network interface
3156 * @netdev: network interface device structure
3158 * Returns 0, this is not allowed to fail
3160 * The close entry point is called when an interface is de-activated
3161 * by the OS. The hardware is still under the drivers control, but
3162 * needs to be disabled. A global MAC reset is issued to stop the
3163 * hardware, and all transmit and receive resources are freed.
3165 static int e1000_close(struct net_device
*netdev
)
3167 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3169 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
3170 e1000e_down(adapter
);
3171 e1000_power_down_phy(adapter
);
3172 e1000_free_irq(adapter
);
3174 e1000e_free_tx_resources(adapter
);
3175 e1000e_free_rx_resources(adapter
);
3178 * kill manageability vlan ID if supported, but not if a vlan with
3179 * the same ID is registered on the host OS (let 8021q kill it)
3181 if ((adapter
->hw
.mng_cookie
.status
&
3182 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
3184 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
)))
3185 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
3188 * If AMT is enabled, let the firmware know that the network
3189 * interface is now closed
3191 if (adapter
->flags
& FLAG_HAS_AMT
)
3192 e1000_release_hw_control(adapter
);
3197 * e1000_set_mac - Change the Ethernet Address of the NIC
3198 * @netdev: network interface device structure
3199 * @p: pointer to an address structure
3201 * Returns 0 on success, negative on failure
3203 static int e1000_set_mac(struct net_device
*netdev
, void *p
)
3205 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3206 struct sockaddr
*addr
= p
;
3208 if (!is_valid_ether_addr(addr
->sa_data
))
3209 return -EADDRNOTAVAIL
;
3211 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
3212 memcpy(adapter
->hw
.mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
3214 e1000e_rar_set(&adapter
->hw
, adapter
->hw
.mac
.addr
, 0);
3216 if (adapter
->flags
& FLAG_RESET_OVERWRITES_LAA
) {
3217 /* activate the work around */
3218 e1000e_set_laa_state_82571(&adapter
->hw
, 1);
3221 * Hold a copy of the LAA in RAR[14] This is done so that
3222 * between the time RAR[0] gets clobbered and the time it
3223 * gets fixed (in e1000_watchdog), the actual LAA is in one
3224 * of the RARs and no incoming packets directed to this port
3225 * are dropped. Eventually the LAA will be in RAR[0] and
3228 e1000e_rar_set(&adapter
->hw
,
3229 adapter
->hw
.mac
.addr
,
3230 adapter
->hw
.mac
.rar_entry_count
- 1);
3237 * e1000e_update_phy_task - work thread to update phy
3238 * @work: pointer to our work struct
3240 * this worker thread exists because we must acquire a
3241 * semaphore to read the phy, which we could msleep while
3242 * waiting for it, and we can't msleep in a timer.
3244 static void e1000e_update_phy_task(struct work_struct
*work
)
3246 struct e1000_adapter
*adapter
= container_of(work
,
3247 struct e1000_adapter
, update_phy_task
);
3248 e1000_get_phy_info(&adapter
->hw
);
3252 * Need to wait a few seconds after link up to get diagnostic information from
3255 static void e1000_update_phy_info(unsigned long data
)
3257 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
3258 schedule_work(&adapter
->update_phy_task
);
3262 * e1000e_update_stats - Update the board statistics counters
3263 * @adapter: board private structure
3265 void e1000e_update_stats(struct e1000_adapter
*adapter
)
3267 struct net_device
*netdev
= adapter
->netdev
;
3268 struct e1000_hw
*hw
= &adapter
->hw
;
3269 struct pci_dev
*pdev
= adapter
->pdev
;
3273 * Prevent stats update while adapter is being reset, or if the pci
3274 * connection is down.
3276 if (adapter
->link_speed
== 0)
3278 if (pci_channel_offline(pdev
))
3281 adapter
->stats
.crcerrs
+= er32(CRCERRS
);
3282 adapter
->stats
.gprc
+= er32(GPRC
);
3283 adapter
->stats
.gorc
+= er32(GORCL
);
3284 er32(GORCH
); /* Clear gorc */
3285 adapter
->stats
.bprc
+= er32(BPRC
);
3286 adapter
->stats
.mprc
+= er32(MPRC
);
3287 adapter
->stats
.roc
+= er32(ROC
);
3289 adapter
->stats
.mpc
+= er32(MPC
);
3290 if ((hw
->phy
.type
== e1000_phy_82578
) ||
3291 (hw
->phy
.type
== e1000_phy_82577
)) {
3292 e1e_rphy(hw
, HV_SCC_UPPER
, &phy_data
);
3293 e1e_rphy(hw
, HV_SCC_LOWER
, &phy_data
);
3294 adapter
->stats
.scc
+= phy_data
;
3296 e1e_rphy(hw
, HV_ECOL_UPPER
, &phy_data
);
3297 e1e_rphy(hw
, HV_ECOL_LOWER
, &phy_data
);
3298 adapter
->stats
.ecol
+= phy_data
;
3300 e1e_rphy(hw
, HV_MCC_UPPER
, &phy_data
);
3301 e1e_rphy(hw
, HV_MCC_LOWER
, &phy_data
);
3302 adapter
->stats
.mcc
+= phy_data
;
3304 e1e_rphy(hw
, HV_LATECOL_UPPER
, &phy_data
);
3305 e1e_rphy(hw
, HV_LATECOL_LOWER
, &phy_data
);
3306 adapter
->stats
.latecol
+= phy_data
;
3308 e1e_rphy(hw
, HV_DC_UPPER
, &phy_data
);
3309 e1e_rphy(hw
, HV_DC_LOWER
, &phy_data
);
3310 adapter
->stats
.dc
+= phy_data
;
3312 adapter
->stats
.scc
+= er32(SCC
);
3313 adapter
->stats
.ecol
+= er32(ECOL
);
3314 adapter
->stats
.mcc
+= er32(MCC
);
3315 adapter
->stats
.latecol
+= er32(LATECOL
);
3316 adapter
->stats
.dc
+= er32(DC
);
3318 adapter
->stats
.xonrxc
+= er32(XONRXC
);
3319 adapter
->stats
.xontxc
+= er32(XONTXC
);
3320 adapter
->stats
.xoffrxc
+= er32(XOFFRXC
);
3321 adapter
->stats
.xofftxc
+= er32(XOFFTXC
);
3322 adapter
->stats
.gptc
+= er32(GPTC
);
3323 adapter
->stats
.gotc
+= er32(GOTCL
);
3324 er32(GOTCH
); /* Clear gotc */
3325 adapter
->stats
.rnbc
+= er32(RNBC
);
3326 adapter
->stats
.ruc
+= er32(RUC
);
3328 adapter
->stats
.mptc
+= er32(MPTC
);
3329 adapter
->stats
.bptc
+= er32(BPTC
);
3331 /* used for adaptive IFS */
3333 hw
->mac
.tx_packet_delta
= er32(TPT
);
3334 adapter
->stats
.tpt
+= hw
->mac
.tx_packet_delta
;
3335 if ((hw
->phy
.type
== e1000_phy_82578
) ||
3336 (hw
->phy
.type
== e1000_phy_82577
)) {
3337 e1e_rphy(hw
, HV_COLC_UPPER
, &phy_data
);
3338 e1e_rphy(hw
, HV_COLC_LOWER
, &phy_data
);
3339 hw
->mac
.collision_delta
= phy_data
;
3341 hw
->mac
.collision_delta
= er32(COLC
);
3343 adapter
->stats
.colc
+= hw
->mac
.collision_delta
;
3345 adapter
->stats
.algnerrc
+= er32(ALGNERRC
);
3346 adapter
->stats
.rxerrc
+= er32(RXERRC
);
3347 if ((hw
->phy
.type
== e1000_phy_82578
) ||
3348 (hw
->phy
.type
== e1000_phy_82577
)) {
3349 e1e_rphy(hw
, HV_TNCRS_UPPER
, &phy_data
);
3350 e1e_rphy(hw
, HV_TNCRS_LOWER
, &phy_data
);
3351 adapter
->stats
.tncrs
+= phy_data
;
3353 if ((hw
->mac
.type
!= e1000_82574
) &&
3354 (hw
->mac
.type
!= e1000_82583
))
3355 adapter
->stats
.tncrs
+= er32(TNCRS
);
3357 adapter
->stats
.cexterr
+= er32(CEXTERR
);
3358 adapter
->stats
.tsctc
+= er32(TSCTC
);
3359 adapter
->stats
.tsctfc
+= er32(TSCTFC
);
3361 /* Fill out the OS statistics structure */
3362 netdev
->stats
.multicast
= adapter
->stats
.mprc
;
3363 netdev
->stats
.collisions
= adapter
->stats
.colc
;
3368 * RLEC on some newer hardware can be incorrect so build
3369 * our own version based on RUC and ROC
3371 netdev
->stats
.rx_errors
= adapter
->stats
.rxerrc
+
3372 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3373 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3374 adapter
->stats
.cexterr
;
3375 netdev
->stats
.rx_length_errors
= adapter
->stats
.ruc
+
3377 netdev
->stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3378 netdev
->stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3379 netdev
->stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3382 netdev
->stats
.tx_errors
= adapter
->stats
.ecol
+
3383 adapter
->stats
.latecol
;
3384 netdev
->stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3385 netdev
->stats
.tx_window_errors
= adapter
->stats
.latecol
;
3386 netdev
->stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3388 /* Tx Dropped needs to be maintained elsewhere */
3390 /* Management Stats */
3391 adapter
->stats
.mgptc
+= er32(MGTPTC
);
3392 adapter
->stats
.mgprc
+= er32(MGTPRC
);
3393 adapter
->stats
.mgpdc
+= er32(MGTPDC
);
3397 * e1000_phy_read_status - Update the PHY register status snapshot
3398 * @adapter: board private structure
3400 static void e1000_phy_read_status(struct e1000_adapter
*adapter
)
3402 struct e1000_hw
*hw
= &adapter
->hw
;
3403 struct e1000_phy_regs
*phy
= &adapter
->phy_regs
;
3406 if ((er32(STATUS
) & E1000_STATUS_LU
) &&
3407 (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
)) {
3408 ret_val
= e1e_rphy(hw
, PHY_CONTROL
, &phy
->bmcr
);
3409 ret_val
|= e1e_rphy(hw
, PHY_STATUS
, &phy
->bmsr
);
3410 ret_val
|= e1e_rphy(hw
, PHY_AUTONEG_ADV
, &phy
->advertise
);
3411 ret_val
|= e1e_rphy(hw
, PHY_LP_ABILITY
, &phy
->lpa
);
3412 ret_val
|= e1e_rphy(hw
, PHY_AUTONEG_EXP
, &phy
->expansion
);
3413 ret_val
|= e1e_rphy(hw
, PHY_1000T_CTRL
, &phy
->ctrl1000
);
3414 ret_val
|= e1e_rphy(hw
, PHY_1000T_STATUS
, &phy
->stat1000
);
3415 ret_val
|= e1e_rphy(hw
, PHY_EXT_STATUS
, &phy
->estatus
);
3417 e_warn("Error reading PHY register\n");
3420 * Do not read PHY registers if link is not up
3421 * Set values to typical power-on defaults
3423 phy
->bmcr
= (BMCR_SPEED1000
| BMCR_ANENABLE
| BMCR_FULLDPLX
);
3424 phy
->bmsr
= (BMSR_100FULL
| BMSR_100HALF
| BMSR_10FULL
|
3425 BMSR_10HALF
| BMSR_ESTATEN
| BMSR_ANEGCAPABLE
|
3427 phy
->advertise
= (ADVERTISE_PAUSE_ASYM
| ADVERTISE_PAUSE_CAP
|
3428 ADVERTISE_ALL
| ADVERTISE_CSMA
);
3430 phy
->expansion
= EXPANSION_ENABLENPAGE
;
3431 phy
->ctrl1000
= ADVERTISE_1000FULL
;
3433 phy
->estatus
= (ESTATUS_1000_TFULL
| ESTATUS_1000_THALF
);
3437 static void e1000_print_link_info(struct e1000_adapter
*adapter
)
3439 struct e1000_hw
*hw
= &adapter
->hw
;
3440 u32 ctrl
= er32(CTRL
);
3442 /* Link status message must follow this format for user tools */
3443 printk(KERN_INFO
"e1000e: %s NIC Link is Up %d Mbps %s, "
3444 "Flow Control: %s\n",
3445 adapter
->netdev
->name
,
3446 adapter
->link_speed
,
3447 (adapter
->link_duplex
== FULL_DUPLEX
) ?
3448 "Full Duplex" : "Half Duplex",
3449 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
& E1000_CTRL_RFCE
)) ?
3451 ((ctrl
& E1000_CTRL_RFCE
) ? "RX" :
3452 ((ctrl
& E1000_CTRL_TFCE
) ? "TX" : "None" )));
3455 bool e1000_has_link(struct e1000_adapter
*adapter
)
3457 struct e1000_hw
*hw
= &adapter
->hw
;
3458 bool link_active
= 0;
3462 * get_link_status is set on LSC (link status) interrupt or
3463 * Rx sequence error interrupt. get_link_status will stay
3464 * false until the check_for_link establishes link
3465 * for copper adapters ONLY
3467 switch (hw
->phy
.media_type
) {
3468 case e1000_media_type_copper
:
3469 if (hw
->mac
.get_link_status
) {
3470 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
3471 link_active
= !hw
->mac
.get_link_status
;
3476 case e1000_media_type_fiber
:
3477 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
3478 link_active
= !!(er32(STATUS
) & E1000_STATUS_LU
);
3480 case e1000_media_type_internal_serdes
:
3481 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
3482 link_active
= adapter
->hw
.mac
.serdes_has_link
;
3485 case e1000_media_type_unknown
:
3489 if ((ret_val
== E1000_ERR_PHY
) && (hw
->phy
.type
== e1000_phy_igp_3
) &&
3490 (er32(CTRL
) & E1000_PHY_CTRL_GBE_DISABLE
)) {
3491 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
3492 e_info("Gigabit has been disabled, downgrading speed\n");
3498 static void e1000e_enable_receives(struct e1000_adapter
*adapter
)
3500 /* make sure the receive unit is started */
3501 if ((adapter
->flags
& FLAG_RX_NEEDS_RESTART
) &&
3502 (adapter
->flags
& FLAG_RX_RESTART_NOW
)) {
3503 struct e1000_hw
*hw
= &adapter
->hw
;
3504 u32 rctl
= er32(RCTL
);
3505 ew32(RCTL
, rctl
| E1000_RCTL_EN
);
3506 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
3511 * e1000_watchdog - Timer Call-back
3512 * @data: pointer to adapter cast into an unsigned long
3514 static void e1000_watchdog(unsigned long data
)
3516 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
3518 /* Do the rest outside of interrupt context */
3519 schedule_work(&adapter
->watchdog_task
);
3521 /* TODO: make this use queue_delayed_work() */
3524 static void e1000_watchdog_task(struct work_struct
*work
)
3526 struct e1000_adapter
*adapter
= container_of(work
,
3527 struct e1000_adapter
, watchdog_task
);
3528 struct net_device
*netdev
= adapter
->netdev
;
3529 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
3530 struct e1000_phy_info
*phy
= &adapter
->hw
.phy
;
3531 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3532 struct e1000_hw
*hw
= &adapter
->hw
;
3536 link
= e1000_has_link(adapter
);
3537 if ((netif_carrier_ok(netdev
)) && link
) {
3538 e1000e_enable_receives(adapter
);
3542 if ((e1000e_enable_tx_pkt_filtering(hw
)) &&
3543 (adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
))
3544 e1000_update_mng_vlan(adapter
);
3547 if (!netif_carrier_ok(netdev
)) {
3549 /* update snapshot of PHY registers on LSC */
3550 e1000_phy_read_status(adapter
);
3551 mac
->ops
.get_link_up_info(&adapter
->hw
,
3552 &adapter
->link_speed
,
3553 &adapter
->link_duplex
);
3554 e1000_print_link_info(adapter
);
3556 * On supported PHYs, check for duplex mismatch only
3557 * if link has autonegotiated at 10/100 half
3559 if ((hw
->phy
.type
== e1000_phy_igp_3
||
3560 hw
->phy
.type
== e1000_phy_bm
) &&
3561 (hw
->mac
.autoneg
== true) &&
3562 (adapter
->link_speed
== SPEED_10
||
3563 adapter
->link_speed
== SPEED_100
) &&
3564 (adapter
->link_duplex
== HALF_DUPLEX
)) {
3567 e1e_rphy(hw
, PHY_AUTONEG_EXP
, &autoneg_exp
);
3569 if (!(autoneg_exp
& NWAY_ER_LP_NWAY_CAPS
))
3570 e_info("Autonegotiated half duplex but"
3571 " link partner cannot autoneg. "
3572 " Try forcing full duplex if "
3573 "link gets many collisions.\n");
3577 * tweak tx_queue_len according to speed/duplex
3578 * and adjust the timeout factor
3580 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
3581 adapter
->tx_timeout_factor
= 1;
3582 switch (adapter
->link_speed
) {
3585 netdev
->tx_queue_len
= 10;
3586 adapter
->tx_timeout_factor
= 16;
3590 netdev
->tx_queue_len
= 100;
3591 /* maybe add some timeout factor ? */
3596 * workaround: re-program speed mode bit after
3599 if ((adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) &&
3602 tarc0
= er32(TARC(0));
3603 tarc0
&= ~SPEED_MODE_BIT
;
3604 ew32(TARC(0), tarc0
);
3608 * disable TSO for pcie and 10/100 speeds, to avoid
3609 * some hardware issues
3611 if (!(adapter
->flags
& FLAG_TSO_FORCE
)) {
3612 switch (adapter
->link_speed
) {
3615 e_info("10/100 speed: disabling TSO\n");
3616 netdev
->features
&= ~NETIF_F_TSO
;
3617 netdev
->features
&= ~NETIF_F_TSO6
;
3620 netdev
->features
|= NETIF_F_TSO
;
3621 netdev
->features
|= NETIF_F_TSO6
;
3630 * enable transmits in the hardware, need to do this
3631 * after setting TARC(0)
3634 tctl
|= E1000_TCTL_EN
;
3638 * Perform any post-link-up configuration before
3639 * reporting link up.
3641 if (phy
->ops
.cfg_on_link_up
)
3642 phy
->ops
.cfg_on_link_up(hw
);
3644 netif_carrier_on(netdev
);
3646 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
3647 mod_timer(&adapter
->phy_info_timer
,
3648 round_jiffies(jiffies
+ 2 * HZ
));
3651 if (netif_carrier_ok(netdev
)) {
3652 adapter
->link_speed
= 0;
3653 adapter
->link_duplex
= 0;
3654 /* Link status message must follow this format */
3655 printk(KERN_INFO
"e1000e: %s NIC Link is Down\n",
3656 adapter
->netdev
->name
);
3657 netif_carrier_off(netdev
);
3658 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
3659 mod_timer(&adapter
->phy_info_timer
,
3660 round_jiffies(jiffies
+ 2 * HZ
));
3662 if (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)
3663 schedule_work(&adapter
->reset_task
);
3668 e1000e_update_stats(adapter
);
3670 mac
->tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
3671 adapter
->tpt_old
= adapter
->stats
.tpt
;
3672 mac
->collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
3673 adapter
->colc_old
= adapter
->stats
.colc
;
3675 adapter
->gorc
= adapter
->stats
.gorc
- adapter
->gorc_old
;
3676 adapter
->gorc_old
= adapter
->stats
.gorc
;
3677 adapter
->gotc
= adapter
->stats
.gotc
- adapter
->gotc_old
;
3678 adapter
->gotc_old
= adapter
->stats
.gotc
;
3680 e1000e_update_adaptive(&adapter
->hw
);
3682 if (!netif_carrier_ok(netdev
)) {
3683 tx_pending
= (e1000_desc_unused(tx_ring
) + 1 <
3687 * We've lost link, so the controller stops DMA,
3688 * but we've got queued Tx work that's never going
3689 * to get done, so reset controller to flush Tx.
3690 * (Do the reset outside of interrupt context).
3692 adapter
->tx_timeout_count
++;
3693 schedule_work(&adapter
->reset_task
);
3694 /* return immediately since reset is imminent */
3699 /* Cause software interrupt to ensure Rx ring is cleaned */
3700 if (adapter
->msix_entries
)
3701 ew32(ICS
, adapter
->rx_ring
->ims_val
);
3703 ew32(ICS
, E1000_ICS_RXDMT0
);
3705 /* Force detection of hung controller every watchdog period */
3706 adapter
->detect_tx_hung
= 1;
3709 * With 82571 controllers, LAA may be overwritten due to controller
3710 * reset from the other port. Set the appropriate LAA in RAR[0]
3712 if (e1000e_get_laa_state_82571(hw
))
3713 e1000e_rar_set(hw
, adapter
->hw
.mac
.addr
, 0);
3715 /* Reset the timer */
3716 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
3717 mod_timer(&adapter
->watchdog_timer
,
3718 round_jiffies(jiffies
+ 2 * HZ
));
3721 #define E1000_TX_FLAGS_CSUM 0x00000001
3722 #define E1000_TX_FLAGS_VLAN 0x00000002
3723 #define E1000_TX_FLAGS_TSO 0x00000004
3724 #define E1000_TX_FLAGS_IPV4 0x00000008
3725 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
3726 #define E1000_TX_FLAGS_VLAN_SHIFT 16
3728 static int e1000_tso(struct e1000_adapter
*adapter
,
3729 struct sk_buff
*skb
)
3731 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3732 struct e1000_context_desc
*context_desc
;
3733 struct e1000_buffer
*buffer_info
;
3736 u16 ipcse
= 0, tucse
, mss
;
3737 u8 ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
3740 if (skb_is_gso(skb
)) {
3741 if (skb_header_cloned(skb
)) {
3742 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
3747 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
3748 mss
= skb_shinfo(skb
)->gso_size
;
3749 if (skb
->protocol
== htons(ETH_P_IP
)) {
3750 struct iphdr
*iph
= ip_hdr(skb
);
3753 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
3757 cmd_length
= E1000_TXD_CMD_IP
;
3758 ipcse
= skb_transport_offset(skb
) - 1;
3759 } else if (skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
) {
3760 ipv6_hdr(skb
)->payload_len
= 0;
3761 tcp_hdr(skb
)->check
=
3762 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
3763 &ipv6_hdr(skb
)->daddr
,
3767 ipcss
= skb_network_offset(skb
);
3768 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
3769 tucss
= skb_transport_offset(skb
);
3770 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
3773 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
3774 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
3776 i
= tx_ring
->next_to_use
;
3777 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
3778 buffer_info
= &tx_ring
->buffer_info
[i
];
3780 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
3781 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
3782 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
3783 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
3784 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
3785 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
3786 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
3787 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
3788 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
3790 buffer_info
->time_stamp
= jiffies
;
3791 buffer_info
->next_to_watch
= i
;
3794 if (i
== tx_ring
->count
)
3796 tx_ring
->next_to_use
= i
;
3804 static bool e1000_tx_csum(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
3806 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3807 struct e1000_context_desc
*context_desc
;
3808 struct e1000_buffer
*buffer_info
;
3811 u32 cmd_len
= E1000_TXD_CMD_DEXT
;
3814 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
3817 if (skb
->protocol
== cpu_to_be16(ETH_P_8021Q
))
3818 protocol
= vlan_eth_hdr(skb
)->h_vlan_encapsulated_proto
;
3820 protocol
= skb
->protocol
;
3823 case cpu_to_be16(ETH_P_IP
):
3824 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
3825 cmd_len
|= E1000_TXD_CMD_TCP
;
3827 case cpu_to_be16(ETH_P_IPV6
):
3828 /* XXX not handling all IPV6 headers */
3829 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
3830 cmd_len
|= E1000_TXD_CMD_TCP
;
3833 if (unlikely(net_ratelimit()))
3834 e_warn("checksum_partial proto=%x!\n",
3835 be16_to_cpu(protocol
));
3839 css
= skb_transport_offset(skb
);
3841 i
= tx_ring
->next_to_use
;
3842 buffer_info
= &tx_ring
->buffer_info
[i
];
3843 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
3845 context_desc
->lower_setup
.ip_config
= 0;
3846 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
3847 context_desc
->upper_setup
.tcp_fields
.tucso
=
3848 css
+ skb
->csum_offset
;
3849 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
3850 context_desc
->tcp_seg_setup
.data
= 0;
3851 context_desc
->cmd_and_length
= cpu_to_le32(cmd_len
);
3853 buffer_info
->time_stamp
= jiffies
;
3854 buffer_info
->next_to_watch
= i
;
3857 if (i
== tx_ring
->count
)
3859 tx_ring
->next_to_use
= i
;
3864 #define E1000_MAX_PER_TXD 8192
3865 #define E1000_MAX_TXD_PWR 12
3867 static int e1000_tx_map(struct e1000_adapter
*adapter
,
3868 struct sk_buff
*skb
, unsigned int first
,
3869 unsigned int max_per_txd
, unsigned int nr_frags
,
3872 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3873 struct e1000_buffer
*buffer_info
;
3874 unsigned int len
= skb_headlen(skb
);
3875 unsigned int offset
, size
, count
= 0, i
;
3879 i
= tx_ring
->next_to_use
;
3881 if (skb_dma_map(&adapter
->pdev
->dev
, skb
, DMA_TO_DEVICE
)) {
3882 dev_err(&adapter
->pdev
->dev
, "TX DMA map failed\n");
3883 adapter
->tx_dma_failed
++;
3887 map
= skb_shinfo(skb
)->dma_maps
;
3891 buffer_info
= &tx_ring
->buffer_info
[i
];
3892 size
= min(len
, max_per_txd
);
3894 buffer_info
->length
= size
;
3895 buffer_info
->time_stamp
= jiffies
;
3896 buffer_info
->next_to_watch
= i
;
3897 buffer_info
->dma
= skb_shinfo(skb
)->dma_head
+ offset
;
3905 if (i
== tx_ring
->count
)
3910 for (f
= 0; f
< nr_frags
; f
++) {
3911 struct skb_frag_struct
*frag
;
3913 frag
= &skb_shinfo(skb
)->frags
[f
];
3919 if (i
== tx_ring
->count
)
3922 buffer_info
= &tx_ring
->buffer_info
[i
];
3923 size
= min(len
, max_per_txd
);
3925 buffer_info
->length
= size
;
3926 buffer_info
->time_stamp
= jiffies
;
3927 buffer_info
->next_to_watch
= i
;
3928 buffer_info
->dma
= map
[f
] + offset
;
3936 tx_ring
->buffer_info
[i
].skb
= skb
;
3937 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
3942 static void e1000_tx_queue(struct e1000_adapter
*adapter
,
3943 int tx_flags
, int count
)
3945 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3946 struct e1000_tx_desc
*tx_desc
= NULL
;
3947 struct e1000_buffer
*buffer_info
;
3948 u32 txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
3951 if (tx_flags
& E1000_TX_FLAGS_TSO
) {
3952 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
3954 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3956 if (tx_flags
& E1000_TX_FLAGS_IPV4
)
3957 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
3960 if (tx_flags
& E1000_TX_FLAGS_CSUM
) {
3961 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
3962 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3965 if (tx_flags
& E1000_TX_FLAGS_VLAN
) {
3966 txd_lower
|= E1000_TXD_CMD_VLE
;
3967 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
3970 i
= tx_ring
->next_to_use
;
3973 buffer_info
= &tx_ring
->buffer_info
[i
];
3974 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3975 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3976 tx_desc
->lower
.data
=
3977 cpu_to_le32(txd_lower
| buffer_info
->length
);
3978 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
3981 if (i
== tx_ring
->count
)
3985 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
3988 * Force memory writes to complete before letting h/w
3989 * know there are new descriptors to fetch. (Only
3990 * applicable for weak-ordered memory model archs,
3995 tx_ring
->next_to_use
= i
;
3996 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3998 * we need this if more than one processor can write to our tail
3999 * at a time, it synchronizes IO on IA64/Altix systems
4004 #define MINIMUM_DHCP_PACKET_SIZE 282
4005 static int e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
,
4006 struct sk_buff
*skb
)
4008 struct e1000_hw
*hw
= &adapter
->hw
;
4011 if (vlan_tx_tag_present(skb
)) {
4012 if (!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
)
4013 && (adapter
->hw
.mng_cookie
.status
&
4014 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
)))
4018 if (skb
->len
<= MINIMUM_DHCP_PACKET_SIZE
)
4021 if (((struct ethhdr
*) skb
->data
)->h_proto
!= htons(ETH_P_IP
))
4025 const struct iphdr
*ip
= (struct iphdr
*)((u8
*)skb
->data
+14);
4028 if (ip
->protocol
!= IPPROTO_UDP
)
4031 udp
= (struct udphdr
*)((u8
*)ip
+ (ip
->ihl
<< 2));
4032 if (ntohs(udp
->dest
) != 67)
4035 offset
= (u8
*)udp
+ 8 - skb
->data
;
4036 length
= skb
->len
- offset
;
4037 return e1000e_mng_write_dhcp_info(hw
, (u8
*)udp
+ 8, length
);
4043 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
4045 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4047 netif_stop_queue(netdev
);
4049 * Herbert's original patch had:
4050 * smp_mb__after_netif_stop_queue();
4051 * but since that doesn't exist yet, just open code it.
4056 * We need to check again in a case another CPU has just
4057 * made room available.
4059 if (e1000_desc_unused(adapter
->tx_ring
) < size
)
4063 netif_start_queue(netdev
);
4064 ++adapter
->restart_queue
;
4068 static int e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
4070 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4072 if (e1000_desc_unused(adapter
->tx_ring
) >= size
)
4074 return __e1000_maybe_stop_tx(netdev
, size
);
4077 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4078 static netdev_tx_t
e1000_xmit_frame(struct sk_buff
*skb
,
4079 struct net_device
*netdev
)
4081 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4082 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4084 unsigned int max_per_txd
= E1000_MAX_PER_TXD
;
4085 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
4086 unsigned int tx_flags
= 0;
4087 unsigned int len
= skb
->len
- skb
->data_len
;
4088 unsigned int nr_frags
;
4094 if (test_bit(__E1000_DOWN
, &adapter
->state
)) {
4095 dev_kfree_skb_any(skb
);
4096 return NETDEV_TX_OK
;
4099 if (skb
->len
<= 0) {
4100 dev_kfree_skb_any(skb
);
4101 return NETDEV_TX_OK
;
4104 mss
= skb_shinfo(skb
)->gso_size
;
4106 * The controller does a simple calculation to
4107 * make sure there is enough room in the FIFO before
4108 * initiating the DMA for each buffer. The calc is:
4109 * 4 = ceil(buffer len/mss). To make sure we don't
4110 * overrun the FIFO, adjust the max buffer len if mss
4115 max_per_txd
= min(mss
<< 2, max_per_txd
);
4116 max_txd_pwr
= fls(max_per_txd
) - 1;
4119 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4120 * points to just header, pull a few bytes of payload from
4121 * frags into skb->data
4123 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
4125 * we do this workaround for ES2LAN, but it is un-necessary,
4126 * avoiding it could save a lot of cycles
4128 if (skb
->data_len
&& (hdr_len
== len
)) {
4129 unsigned int pull_size
;
4131 pull_size
= min((unsigned int)4, skb
->data_len
);
4132 if (!__pskb_pull_tail(skb
, pull_size
)) {
4133 e_err("__pskb_pull_tail failed.\n");
4134 dev_kfree_skb_any(skb
);
4135 return NETDEV_TX_OK
;
4137 len
= skb
->len
- skb
->data_len
;
4141 /* reserve a descriptor for the offload context */
4142 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
4146 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
4148 nr_frags
= skb_shinfo(skb
)->nr_frags
;
4149 for (f
= 0; f
< nr_frags
; f
++)
4150 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
4153 if (adapter
->hw
.mac
.tx_pkt_filtering
)
4154 e1000_transfer_dhcp_info(adapter
, skb
);
4157 * need: count + 2 desc gap to keep tail from touching
4158 * head, otherwise try next time
4160 if (e1000_maybe_stop_tx(netdev
, count
+ 2))
4161 return NETDEV_TX_BUSY
;
4163 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
4164 tx_flags
|= E1000_TX_FLAGS_VLAN
;
4165 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
4168 first
= tx_ring
->next_to_use
;
4170 tso
= e1000_tso(adapter
, skb
);
4172 dev_kfree_skb_any(skb
);
4173 return NETDEV_TX_OK
;
4177 tx_flags
|= E1000_TX_FLAGS_TSO
;
4178 else if (e1000_tx_csum(adapter
, skb
))
4179 tx_flags
|= E1000_TX_FLAGS_CSUM
;
4182 * Old method was to assume IPv4 packet by default if TSO was enabled.
4183 * 82571 hardware supports TSO capabilities for IPv6 as well...
4184 * no longer assume, we must.
4186 if (skb
->protocol
== htons(ETH_P_IP
))
4187 tx_flags
|= E1000_TX_FLAGS_IPV4
;
4189 /* if count is 0 then mapping error has occured */
4190 count
= e1000_tx_map(adapter
, skb
, first
, max_per_txd
, nr_frags
, mss
);
4192 e1000_tx_queue(adapter
, tx_flags
, count
);
4193 /* Make sure there is space in the ring for the next send. */
4194 e1000_maybe_stop_tx(netdev
, MAX_SKB_FRAGS
+ 2);
4197 dev_kfree_skb_any(skb
);
4198 tx_ring
->buffer_info
[first
].time_stamp
= 0;
4199 tx_ring
->next_to_use
= first
;
4202 return NETDEV_TX_OK
;
4206 * e1000_tx_timeout - Respond to a Tx Hang
4207 * @netdev: network interface device structure
4209 static void e1000_tx_timeout(struct net_device
*netdev
)
4211 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4213 /* Do the reset outside of interrupt context */
4214 adapter
->tx_timeout_count
++;
4215 schedule_work(&adapter
->reset_task
);
4218 static void e1000_reset_task(struct work_struct
*work
)
4220 struct e1000_adapter
*adapter
;
4221 adapter
= container_of(work
, struct e1000_adapter
, reset_task
);
4223 e1000e_reinit_locked(adapter
);
4227 * e1000_get_stats - Get System Network Statistics
4228 * @netdev: network interface device structure
4230 * Returns the address of the device statistics structure.
4231 * The statistics are actually updated from the timer callback.
4233 static struct net_device_stats
*e1000_get_stats(struct net_device
*netdev
)
4235 /* only return the current stats */
4236 return &netdev
->stats
;
4240 * e1000_change_mtu - Change the Maximum Transfer Unit
4241 * @netdev: network interface device structure
4242 * @new_mtu: new value for maximum frame size
4244 * Returns 0 on success, negative on failure
4246 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
4248 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4249 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4251 /* Jumbo frame support */
4252 if ((max_frame
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) &&
4253 !(adapter
->flags
& FLAG_HAS_JUMBO_FRAMES
)) {
4254 e_err("Jumbo Frames not supported.\n");
4258 /* Supported frame sizes */
4259 if ((new_mtu
< ETH_ZLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
) ||
4260 (max_frame
> adapter
->max_hw_frame_size
)) {
4261 e_err("Unsupported MTU setting\n");
4265 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
4267 /* e1000e_down has a dependency on max_frame_size */
4268 adapter
->max_frame_size
= max_frame
;
4269 if (netif_running(netdev
))
4270 e1000e_down(adapter
);
4273 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
4274 * means we reserve 2 more, this pushes us to allocate from the next
4276 * i.e. RXBUFFER_2048 --> size-4096 slab
4277 * However with the new *_jumbo_rx* routines, jumbo receives will use
4281 if (max_frame
<= 256)
4282 adapter
->rx_buffer_len
= 256;
4283 else if (max_frame
<= 512)
4284 adapter
->rx_buffer_len
= 512;
4285 else if (max_frame
<= 1024)
4286 adapter
->rx_buffer_len
= 1024;
4287 else if (max_frame
<= 2048)
4288 adapter
->rx_buffer_len
= 2048;
4290 adapter
->rx_buffer_len
= 4096;
4292 /* adjust allocation if LPE protects us, and we aren't using SBP */
4293 if ((max_frame
== ETH_FRAME_LEN
+ ETH_FCS_LEN
) ||
4294 (max_frame
== ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
))
4295 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
4298 e_info("changing MTU from %d to %d\n", netdev
->mtu
, new_mtu
);
4299 netdev
->mtu
= new_mtu
;
4301 if (netif_running(netdev
))
4304 e1000e_reset(adapter
);
4306 clear_bit(__E1000_RESETTING
, &adapter
->state
);
4311 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
4314 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4315 struct mii_ioctl_data
*data
= if_mii(ifr
);
4317 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
4322 data
->phy_id
= adapter
->hw
.phy
.addr
;
4325 switch (data
->reg_num
& 0x1F) {
4327 data
->val_out
= adapter
->phy_regs
.bmcr
;
4330 data
->val_out
= adapter
->phy_regs
.bmsr
;
4333 data
->val_out
= (adapter
->hw
.phy
.id
>> 16);
4336 data
->val_out
= (adapter
->hw
.phy
.id
& 0xFFFF);
4339 data
->val_out
= adapter
->phy_regs
.advertise
;
4342 data
->val_out
= adapter
->phy_regs
.lpa
;
4345 data
->val_out
= adapter
->phy_regs
.expansion
;
4348 data
->val_out
= adapter
->phy_regs
.ctrl1000
;
4351 data
->val_out
= adapter
->phy_regs
.stat1000
;
4354 data
->val_out
= adapter
->phy_regs
.estatus
;
4367 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4373 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4379 static int e1000_init_phy_wakeup(struct e1000_adapter
*adapter
, u32 wufc
)
4381 struct e1000_hw
*hw
= &adapter
->hw
;
4386 /* copy MAC RARs to PHY RARs */
4387 for (i
= 0; i
< adapter
->hw
.mac
.rar_entry_count
; i
++) {
4388 mac_reg
= er32(RAL(i
));
4389 e1e_wphy(hw
, BM_RAR_L(i
), (u16
)(mac_reg
& 0xFFFF));
4390 e1e_wphy(hw
, BM_RAR_M(i
), (u16
)((mac_reg
>> 16) & 0xFFFF));
4391 mac_reg
= er32(RAH(i
));
4392 e1e_wphy(hw
, BM_RAR_H(i
), (u16
)(mac_reg
& 0xFFFF));
4393 e1e_wphy(hw
, BM_RAR_CTRL(i
), (u16
)((mac_reg
>> 16) & 0xFFFF));
4396 /* copy MAC MTA to PHY MTA */
4397 for (i
= 0; i
< adapter
->hw
.mac
.mta_reg_count
; i
++) {
4398 mac_reg
= E1000_READ_REG_ARRAY(hw
, E1000_MTA
, i
);
4399 e1e_wphy(hw
, BM_MTA(i
), (u16
)(mac_reg
& 0xFFFF));
4400 e1e_wphy(hw
, BM_MTA(i
) + 1, (u16
)((mac_reg
>> 16) & 0xFFFF));
4403 /* configure PHY Rx Control register */
4404 e1e_rphy(&adapter
->hw
, BM_RCTL
, &phy_reg
);
4405 mac_reg
= er32(RCTL
);
4406 if (mac_reg
& E1000_RCTL_UPE
)
4407 phy_reg
|= BM_RCTL_UPE
;
4408 if (mac_reg
& E1000_RCTL_MPE
)
4409 phy_reg
|= BM_RCTL_MPE
;
4410 phy_reg
&= ~(BM_RCTL_MO_MASK
);
4411 if (mac_reg
& E1000_RCTL_MO_3
)
4412 phy_reg
|= (((mac_reg
& E1000_RCTL_MO_3
) >> E1000_RCTL_MO_SHIFT
)
4413 << BM_RCTL_MO_SHIFT
);
4414 if (mac_reg
& E1000_RCTL_BAM
)
4415 phy_reg
|= BM_RCTL_BAM
;
4416 if (mac_reg
& E1000_RCTL_PMCF
)
4417 phy_reg
|= BM_RCTL_PMCF
;
4418 mac_reg
= er32(CTRL
);
4419 if (mac_reg
& E1000_CTRL_RFCE
)
4420 phy_reg
|= BM_RCTL_RFCE
;
4421 e1e_wphy(&adapter
->hw
, BM_RCTL
, phy_reg
);
4423 /* enable PHY wakeup in MAC register */
4425 ew32(WUC
, E1000_WUC_PHY_WAKE
| E1000_WUC_PME_EN
);
4427 /* configure and enable PHY wakeup in PHY registers */
4428 e1e_wphy(&adapter
->hw
, BM_WUFC
, wufc
);
4429 e1e_wphy(&adapter
->hw
, BM_WUC
, E1000_WUC_PME_EN
);
4431 /* activate PHY wakeup */
4432 retval
= hw
->phy
.ops
.acquire_phy(hw
);
4434 e_err("Could not acquire PHY\n");
4437 e1000e_write_phy_reg_mdic(hw
, IGP01E1000_PHY_PAGE_SELECT
,
4438 (BM_WUC_ENABLE_PAGE
<< IGP_PAGE_SHIFT
));
4439 retval
= e1000e_read_phy_reg_mdic(hw
, BM_WUC_ENABLE_REG
, &phy_reg
);
4441 e_err("Could not read PHY page 769\n");
4444 phy_reg
|= BM_WUC_ENABLE_BIT
| BM_WUC_HOST_WU_BIT
;
4445 retval
= e1000e_write_phy_reg_mdic(hw
, BM_WUC_ENABLE_REG
, phy_reg
);
4447 e_err("Could not set PHY Host Wakeup bit\n");
4449 hw
->phy
.ops
.release_phy(hw
);
4454 static int __e1000_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
4456 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4457 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4458 struct e1000_hw
*hw
= &adapter
->hw
;
4459 u32 ctrl
, ctrl_ext
, rctl
, status
;
4460 u32 wufc
= adapter
->wol
;
4463 netif_device_detach(netdev
);
4465 if (netif_running(netdev
)) {
4466 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
4467 e1000e_down(adapter
);
4468 e1000_free_irq(adapter
);
4470 e1000e_reset_interrupt_capability(adapter
);
4472 retval
= pci_save_state(pdev
);
4476 status
= er32(STATUS
);
4477 if (status
& E1000_STATUS_LU
)
4478 wufc
&= ~E1000_WUFC_LNKC
;
4481 e1000_setup_rctl(adapter
);
4482 e1000_set_multi(netdev
);
4484 /* turn on all-multi mode if wake on multicast is enabled */
4485 if (wufc
& E1000_WUFC_MC
) {
4487 rctl
|= E1000_RCTL_MPE
;
4492 /* advertise wake from D3Cold */
4493 #define E1000_CTRL_ADVD3WUC 0x00100000
4494 /* phy power management enable */
4495 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4496 ctrl
|= E1000_CTRL_ADVD3WUC
;
4497 if (!(adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
))
4498 ctrl
|= E1000_CTRL_EN_PHY_PWR_MGMT
;
4501 if (adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
||
4502 adapter
->hw
.phy
.media_type
==
4503 e1000_media_type_internal_serdes
) {
4504 /* keep the laser running in D3 */
4505 ctrl_ext
= er32(CTRL_EXT
);
4506 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
4507 ew32(CTRL_EXT
, ctrl_ext
);
4510 if (adapter
->flags
& FLAG_IS_ICH
)
4511 e1000e_disable_gig_wol_ich8lan(&adapter
->hw
);
4513 /* Allow time for pending master requests to run */
4514 e1000e_disable_pcie_master(&adapter
->hw
);
4516 if (adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
) {
4517 /* enable wakeup by the PHY */
4518 retval
= e1000_init_phy_wakeup(adapter
, wufc
);
4522 /* enable wakeup by the MAC */
4524 ew32(WUC
, E1000_WUC_PME_EN
);
4531 *enable_wake
= !!wufc
;
4533 /* make sure adapter isn't asleep if manageability is enabled */
4534 if ((adapter
->flags
& FLAG_MNG_PT_ENABLED
) ||
4535 (hw
->mac
.ops
.check_mng_mode(hw
)))
4536 *enable_wake
= true;
4538 if (adapter
->hw
.phy
.type
== e1000_phy_igp_3
)
4539 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter
->hw
);
4542 * Release control of h/w to f/w. If f/w is AMT enabled, this
4543 * would have already happened in close and is redundant.
4545 e1000_release_hw_control(adapter
);
4547 pci_disable_device(pdev
);
4552 static void e1000_power_off(struct pci_dev
*pdev
, bool sleep
, bool wake
)
4554 if (sleep
&& wake
) {
4555 pci_prepare_to_sleep(pdev
);
4559 pci_wake_from_d3(pdev
, wake
);
4560 pci_set_power_state(pdev
, PCI_D3hot
);
4563 static void e1000_complete_shutdown(struct pci_dev
*pdev
, bool sleep
,
4566 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4567 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4570 * The pci-e switch on some quad port adapters will report a
4571 * correctable error when the MAC transitions from D0 to D3. To
4572 * prevent this we need to mask off the correctable errors on the
4573 * downstream port of the pci-e switch.
4575 if (adapter
->flags
& FLAG_IS_QUAD_PORT
) {
4576 struct pci_dev
*us_dev
= pdev
->bus
->self
;
4577 int pos
= pci_find_capability(us_dev
, PCI_CAP_ID_EXP
);
4580 pci_read_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
, &devctl
);
4581 pci_write_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
,
4582 (devctl
& ~PCI_EXP_DEVCTL_CERE
));
4584 e1000_power_off(pdev
, sleep
, wake
);
4586 pci_write_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
, devctl
);
4588 e1000_power_off(pdev
, sleep
, wake
);
4592 static void e1000e_disable_l1aspm(struct pci_dev
*pdev
)
4598 * 82573 workaround - disable L1 ASPM on mobile chipsets
4600 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
4601 * resulting in lost data or garbage information on the pci-e link
4602 * level. This could result in (false) bad EEPROM checksum errors,
4603 * long ping times (up to 2s) or even a system freeze/hang.
4605 * Unfortunately this feature saves about 1W power consumption when
4608 pos
= pci_find_capability(pdev
, PCI_CAP_ID_EXP
);
4609 pci_read_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, &val
);
4611 dev_warn(&pdev
->dev
, "Disabling L1 ASPM\n");
4613 pci_write_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, val
);
4618 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4623 retval
= __e1000_shutdown(pdev
, &wake
);
4625 e1000_complete_shutdown(pdev
, true, wake
);
4630 static int e1000_resume(struct pci_dev
*pdev
)
4632 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4633 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4634 struct e1000_hw
*hw
= &adapter
->hw
;
4637 pci_set_power_state(pdev
, PCI_D0
);
4638 pci_restore_state(pdev
);
4639 e1000e_disable_l1aspm(pdev
);
4641 err
= pci_enable_device_mem(pdev
);
4644 "Cannot enable PCI device from suspend\n");
4648 pci_set_master(pdev
);
4650 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4651 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4653 e1000e_set_interrupt_capability(adapter
);
4654 if (netif_running(netdev
)) {
4655 err
= e1000_request_irq(adapter
);
4660 e1000e_power_up_phy(adapter
);
4662 /* report the system wakeup cause from S3/S4 */
4663 if (adapter
->flags2
& FLAG2_HAS_PHY_WAKEUP
) {
4666 e1e_rphy(&adapter
->hw
, BM_WUS
, &phy_data
);
4668 e_info("PHY Wakeup cause - %s\n",
4669 phy_data
& E1000_WUS_EX
? "Unicast Packet" :
4670 phy_data
& E1000_WUS_MC
? "Multicast Packet" :
4671 phy_data
& E1000_WUS_BC
? "Broadcast Packet" :
4672 phy_data
& E1000_WUS_MAG
? "Magic Packet" :
4673 phy_data
& E1000_WUS_LNKC
? "Link Status "
4674 " Change" : "other");
4676 e1e_wphy(&adapter
->hw
, BM_WUS
, ~0);
4678 u32 wus
= er32(WUS
);
4680 e_info("MAC Wakeup cause - %s\n",
4681 wus
& E1000_WUS_EX
? "Unicast Packet" :
4682 wus
& E1000_WUS_MC
? "Multicast Packet" :
4683 wus
& E1000_WUS_BC
? "Broadcast Packet" :
4684 wus
& E1000_WUS_MAG
? "Magic Packet" :
4685 wus
& E1000_WUS_LNKC
? "Link Status Change" :
4691 e1000e_reset(adapter
);
4693 e1000_init_manageability(adapter
);
4695 if (netif_running(netdev
))
4698 netif_device_attach(netdev
);
4701 * If the controller has AMT, do not set DRV_LOAD until the interface
4702 * is up. For all other cases, let the f/w know that the h/w is now
4703 * under the control of the driver.
4705 if (!(adapter
->flags
& FLAG_HAS_AMT
))
4706 e1000_get_hw_control(adapter
);
4712 static void e1000_shutdown(struct pci_dev
*pdev
)
4716 __e1000_shutdown(pdev
, &wake
);
4718 if (system_state
== SYSTEM_POWER_OFF
)
4719 e1000_complete_shutdown(pdev
, false, wake
);
4722 #ifdef CONFIG_NET_POLL_CONTROLLER
4724 * Polling 'interrupt' - used by things like netconsole to send skbs
4725 * without having to re-enable interrupts. It's not called while
4726 * the interrupt routine is executing.
4728 static void e1000_netpoll(struct net_device
*netdev
)
4730 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4732 disable_irq(adapter
->pdev
->irq
);
4733 e1000_intr(adapter
->pdev
->irq
, netdev
);
4735 enable_irq(adapter
->pdev
->irq
);
4740 * e1000_io_error_detected - called when PCI error is detected
4741 * @pdev: Pointer to PCI device
4742 * @state: The current pci connection state
4744 * This function is called after a PCI bus error affecting
4745 * this device has been detected.
4747 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
4748 pci_channel_state_t state
)
4750 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4751 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4753 netif_device_detach(netdev
);
4755 if (state
== pci_channel_io_perm_failure
)
4756 return PCI_ERS_RESULT_DISCONNECT
;
4758 if (netif_running(netdev
))
4759 e1000e_down(adapter
);
4760 pci_disable_device(pdev
);
4762 /* Request a slot slot reset. */
4763 return PCI_ERS_RESULT_NEED_RESET
;
4767 * e1000_io_slot_reset - called after the pci bus has been reset.
4768 * @pdev: Pointer to PCI device
4770 * Restart the card from scratch, as if from a cold-boot. Implementation
4771 * resembles the first-half of the e1000_resume routine.
4773 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
4775 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4776 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4777 struct e1000_hw
*hw
= &adapter
->hw
;
4779 pci_ers_result_t result
;
4781 e1000e_disable_l1aspm(pdev
);
4782 err
= pci_enable_device_mem(pdev
);
4785 "Cannot re-enable PCI device after reset.\n");
4786 result
= PCI_ERS_RESULT_DISCONNECT
;
4788 pci_set_master(pdev
);
4789 pci_restore_state(pdev
);
4791 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4792 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4794 e1000e_reset(adapter
);
4796 result
= PCI_ERS_RESULT_RECOVERED
;
4799 pci_cleanup_aer_uncorrect_error_status(pdev
);
4805 * e1000_io_resume - called when traffic can start flowing again.
4806 * @pdev: Pointer to PCI device
4808 * This callback is called when the error recovery driver tells us that
4809 * its OK to resume normal operation. Implementation resembles the
4810 * second-half of the e1000_resume routine.
4812 static void e1000_io_resume(struct pci_dev
*pdev
)
4814 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4815 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4817 e1000_init_manageability(adapter
);
4819 if (netif_running(netdev
)) {
4820 if (e1000e_up(adapter
)) {
4822 "can't bring device back up after reset\n");
4827 netif_device_attach(netdev
);
4830 * If the controller has AMT, do not set DRV_LOAD until the interface
4831 * is up. For all other cases, let the f/w know that the h/w is now
4832 * under the control of the driver.
4834 if (!(adapter
->flags
& FLAG_HAS_AMT
))
4835 e1000_get_hw_control(adapter
);
4839 static void e1000_print_device_info(struct e1000_adapter
*adapter
)
4841 struct e1000_hw
*hw
= &adapter
->hw
;
4842 struct net_device
*netdev
= adapter
->netdev
;
4845 /* print bus type/speed/width info */
4846 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
4848 ((hw
->bus
.width
== e1000_bus_width_pcie_x4
) ? "Width x4" :
4852 e_info("Intel(R) PRO/%s Network Connection\n",
4853 (hw
->phy
.type
== e1000_phy_ife
) ? "10/100" : "1000");
4854 e1000e_read_pba_num(hw
, &pba_num
);
4855 e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4856 hw
->mac
.type
, hw
->phy
.type
, (pba_num
>> 8), (pba_num
& 0xff));
4859 static void e1000_eeprom_checks(struct e1000_adapter
*adapter
)
4861 struct e1000_hw
*hw
= &adapter
->hw
;
4865 if (hw
->mac
.type
!= e1000_82573
)
4868 ret_val
= e1000_read_nvm(hw
, NVM_INIT_CONTROL2_REG
, 1, &buf
);
4869 if (!ret_val
&& (!(le16_to_cpu(buf
) & (1 << 0)))) {
4870 /* Deep Smart Power Down (DSPD) */
4871 dev_warn(&adapter
->pdev
->dev
,
4872 "Warning: detected DSPD enabled in EEPROM\n");
4875 ret_val
= e1000_read_nvm(hw
, NVM_INIT_3GIO_3
, 1, &buf
);
4876 if (!ret_val
&& (le16_to_cpu(buf
) & (3 << 2))) {
4878 dev_warn(&adapter
->pdev
->dev
,
4879 "Warning: detected ASPM enabled in EEPROM\n");
4883 static const struct net_device_ops e1000e_netdev_ops
= {
4884 .ndo_open
= e1000_open
,
4885 .ndo_stop
= e1000_close
,
4886 .ndo_start_xmit
= e1000_xmit_frame
,
4887 .ndo_get_stats
= e1000_get_stats
,
4888 .ndo_set_multicast_list
= e1000_set_multi
,
4889 .ndo_set_mac_address
= e1000_set_mac
,
4890 .ndo_change_mtu
= e1000_change_mtu
,
4891 .ndo_do_ioctl
= e1000_ioctl
,
4892 .ndo_tx_timeout
= e1000_tx_timeout
,
4893 .ndo_validate_addr
= eth_validate_addr
,
4895 .ndo_vlan_rx_register
= e1000_vlan_rx_register
,
4896 .ndo_vlan_rx_add_vid
= e1000_vlan_rx_add_vid
,
4897 .ndo_vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
,
4898 #ifdef CONFIG_NET_POLL_CONTROLLER
4899 .ndo_poll_controller
= e1000_netpoll
,
4904 * e1000_probe - Device Initialization Routine
4905 * @pdev: PCI device information struct
4906 * @ent: entry in e1000_pci_tbl
4908 * Returns 0 on success, negative on failure
4910 * e1000_probe initializes an adapter identified by a pci_dev structure.
4911 * The OS initialization, configuring of the adapter private structure,
4912 * and a hardware reset occur.
4914 static int __devinit
e1000_probe(struct pci_dev
*pdev
,
4915 const struct pci_device_id
*ent
)
4917 struct net_device
*netdev
;
4918 struct e1000_adapter
*adapter
;
4919 struct e1000_hw
*hw
;
4920 const struct e1000_info
*ei
= e1000_info_tbl
[ent
->driver_data
];
4921 resource_size_t mmio_start
, mmio_len
;
4922 resource_size_t flash_start
, flash_len
;
4924 static int cards_found
;
4925 int i
, err
, pci_using_dac
;
4926 u16 eeprom_data
= 0;
4927 u16 eeprom_apme_mask
= E1000_EEPROM_APME
;
4929 e1000e_disable_l1aspm(pdev
);
4931 err
= pci_enable_device_mem(pdev
);
4936 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
4938 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64));
4942 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
4944 err
= pci_set_consistent_dma_mask(pdev
,
4947 dev_err(&pdev
->dev
, "No usable DMA "
4948 "configuration, aborting\n");
4954 err
= pci_request_selected_regions_exclusive(pdev
,
4955 pci_select_bars(pdev
, IORESOURCE_MEM
),
4956 e1000e_driver_name
);
4960 /* AER (Advanced Error Reporting) hooks */
4961 pci_enable_pcie_error_reporting(pdev
);
4963 pci_set_master(pdev
);
4964 /* PCI config space info */
4965 err
= pci_save_state(pdev
);
4967 goto err_alloc_etherdev
;
4970 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
4972 goto err_alloc_etherdev
;
4974 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
4976 pci_set_drvdata(pdev
, netdev
);
4977 adapter
= netdev_priv(netdev
);
4979 adapter
->netdev
= netdev
;
4980 adapter
->pdev
= pdev
;
4982 adapter
->pba
= ei
->pba
;
4983 adapter
->flags
= ei
->flags
;
4984 adapter
->flags2
= ei
->flags2
;
4985 adapter
->hw
.adapter
= adapter
;
4986 adapter
->hw
.mac
.type
= ei
->mac
;
4987 adapter
->max_hw_frame_size
= ei
->max_hw_frame_size
;
4988 adapter
->msg_enable
= (1 << NETIF_MSG_DRV
| NETIF_MSG_PROBE
) - 1;
4990 mmio_start
= pci_resource_start(pdev
, 0);
4991 mmio_len
= pci_resource_len(pdev
, 0);
4994 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
4995 if (!adapter
->hw
.hw_addr
)
4998 if ((adapter
->flags
& FLAG_HAS_FLASH
) &&
4999 (pci_resource_flags(pdev
, 1) & IORESOURCE_MEM
)) {
5000 flash_start
= pci_resource_start(pdev
, 1);
5001 flash_len
= pci_resource_len(pdev
, 1);
5002 adapter
->hw
.flash_address
= ioremap(flash_start
, flash_len
);
5003 if (!adapter
->hw
.flash_address
)
5007 /* construct the net_device struct */
5008 netdev
->netdev_ops
= &e1000e_netdev_ops
;
5009 e1000e_set_ethtool_ops(netdev
);
5010 netdev
->watchdog_timeo
= 5 * HZ
;
5011 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
5012 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
5014 netdev
->mem_start
= mmio_start
;
5015 netdev
->mem_end
= mmio_start
+ mmio_len
;
5017 adapter
->bd_number
= cards_found
++;
5019 e1000e_check_options(adapter
);
5021 /* setup adapter struct */
5022 err
= e1000_sw_init(adapter
);
5028 memcpy(&hw
->mac
.ops
, ei
->mac_ops
, sizeof(hw
->mac
.ops
));
5029 memcpy(&hw
->nvm
.ops
, ei
->nvm_ops
, sizeof(hw
->nvm
.ops
));
5030 memcpy(&hw
->phy
.ops
, ei
->phy_ops
, sizeof(hw
->phy
.ops
));
5032 err
= ei
->get_variants(adapter
);
5036 if ((adapter
->flags
& FLAG_IS_ICH
) &&
5037 (adapter
->flags
& FLAG_READ_ONLY_NVM
))
5038 e1000e_write_protect_nvm_ich8lan(&adapter
->hw
);
5040 hw
->mac
.ops
.get_bus_info(&adapter
->hw
);
5042 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
5044 /* Copper options */
5045 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
) {
5046 adapter
->hw
.phy
.mdix
= AUTO_ALL_MODES
;
5047 adapter
->hw
.phy
.disable_polarity_correction
= 0;
5048 adapter
->hw
.phy
.ms_type
= e1000_ms_hw_default
;
5051 if (e1000_check_reset_block(&adapter
->hw
))
5052 e_info("PHY reset is blocked due to SOL/IDER session.\n");
5054 netdev
->features
= NETIF_F_SG
|
5056 NETIF_F_HW_VLAN_TX
|
5059 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
)
5060 netdev
->features
|= NETIF_F_HW_VLAN_FILTER
;
5062 netdev
->features
|= NETIF_F_TSO
;
5063 netdev
->features
|= NETIF_F_TSO6
;
5065 netdev
->vlan_features
|= NETIF_F_TSO
;
5066 netdev
->vlan_features
|= NETIF_F_TSO6
;
5067 netdev
->vlan_features
|= NETIF_F_HW_CSUM
;
5068 netdev
->vlan_features
|= NETIF_F_SG
;
5071 netdev
->features
|= NETIF_F_HIGHDMA
;
5073 if (e1000e_enable_mng_pass_thru(&adapter
->hw
))
5074 adapter
->flags
|= FLAG_MNG_PT_ENABLED
;
5077 * before reading the NVM, reset the controller to
5078 * put the device in a known good starting state
5080 adapter
->hw
.mac
.ops
.reset_hw(&adapter
->hw
);
5083 * systems with ASPM and others may see the checksum fail on the first
5084 * attempt. Let's give it a few tries
5087 if (e1000_validate_nvm_checksum(&adapter
->hw
) >= 0)
5090 e_err("The NVM Checksum Is Not Valid\n");
5096 e1000_eeprom_checks(adapter
);
5098 /* copy the MAC address out of the NVM */
5099 if (e1000e_read_mac_addr(&adapter
->hw
))
5100 e_err("NVM Read Error while reading MAC address\n");
5102 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
5103 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
5105 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
5106 e_err("Invalid MAC Address: %pM\n", netdev
->perm_addr
);
5111 init_timer(&adapter
->watchdog_timer
);
5112 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
5113 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
5115 init_timer(&adapter
->phy_info_timer
);
5116 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
5117 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
5119 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
5120 INIT_WORK(&adapter
->watchdog_task
, e1000_watchdog_task
);
5121 INIT_WORK(&adapter
->downshift_task
, e1000e_downshift_workaround
);
5122 INIT_WORK(&adapter
->update_phy_task
, e1000e_update_phy_task
);
5124 /* Initialize link parameters. User can change them with ethtool */
5125 adapter
->hw
.mac
.autoneg
= 1;
5126 adapter
->fc_autoneg
= 1;
5127 adapter
->hw
.fc
.requested_mode
= e1000_fc_default
;
5128 adapter
->hw
.fc
.current_mode
= e1000_fc_default
;
5129 adapter
->hw
.phy
.autoneg_advertised
= 0x2f;
5131 /* ring size defaults */
5132 adapter
->rx_ring
->count
= 256;
5133 adapter
->tx_ring
->count
= 256;
5136 * Initial Wake on LAN setting - If APM wake is enabled in
5137 * the EEPROM, enable the ACPI Magic Packet filter
5139 if (adapter
->flags
& FLAG_APME_IN_WUC
) {
5140 /* APME bit in EEPROM is mapped to WUC.APME */
5141 eeprom_data
= er32(WUC
);
5142 eeprom_apme_mask
= E1000_WUC_APME
;
5143 if (eeprom_data
& E1000_WUC_PHY_WAKE
)
5144 adapter
->flags2
|= FLAG2_HAS_PHY_WAKEUP
;
5145 } else if (adapter
->flags
& FLAG_APME_IN_CTRL3
) {
5146 if (adapter
->flags
& FLAG_APME_CHECK_PORT_B
&&
5147 (adapter
->hw
.bus
.func
== 1))
5148 e1000_read_nvm(&adapter
->hw
,
5149 NVM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
5151 e1000_read_nvm(&adapter
->hw
,
5152 NVM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
5155 /* fetch WoL from EEPROM */
5156 if (eeprom_data
& eeprom_apme_mask
)
5157 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
5160 * now that we have the eeprom settings, apply the special cases
5161 * where the eeprom may be wrong or the board simply won't support
5162 * wake on lan on a particular port
5164 if (!(adapter
->flags
& FLAG_HAS_WOL
))
5165 adapter
->eeprom_wol
= 0;
5167 /* initialize the wol settings based on the eeprom settings */
5168 adapter
->wol
= adapter
->eeprom_wol
;
5169 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
5171 /* save off EEPROM version number */
5172 e1000_read_nvm(&adapter
->hw
, 5, 1, &adapter
->eeprom_vers
);
5174 /* reset the hardware with the new settings */
5175 e1000e_reset(adapter
);
5178 * If the controller has AMT, do not set DRV_LOAD until the interface
5179 * is up. For all other cases, let the f/w know that the h/w is now
5180 * under the control of the driver.
5182 if (!(adapter
->flags
& FLAG_HAS_AMT
))
5183 e1000_get_hw_control(adapter
);
5185 strcpy(netdev
->name
, "eth%d");
5186 err
= register_netdev(netdev
);
5190 /* carrier off reporting is important to ethtool even BEFORE open */
5191 netif_carrier_off(netdev
);
5193 e1000_print_device_info(adapter
);
5198 if (!(adapter
->flags
& FLAG_HAS_AMT
))
5199 e1000_release_hw_control(adapter
);
5201 if (!e1000_check_reset_block(&adapter
->hw
))
5202 e1000_phy_hw_reset(&adapter
->hw
);
5205 kfree(adapter
->tx_ring
);
5206 kfree(adapter
->rx_ring
);
5208 if (adapter
->hw
.flash_address
)
5209 iounmap(adapter
->hw
.flash_address
);
5210 e1000e_reset_interrupt_capability(adapter
);
5212 iounmap(adapter
->hw
.hw_addr
);
5214 free_netdev(netdev
);
5216 pci_release_selected_regions(pdev
,
5217 pci_select_bars(pdev
, IORESOURCE_MEM
));
5220 pci_disable_device(pdev
);
5225 * e1000_remove - Device Removal Routine
5226 * @pdev: PCI device information struct
5228 * e1000_remove is called by the PCI subsystem to alert the driver
5229 * that it should release a PCI device. The could be caused by a
5230 * Hot-Plug event, or because the driver is going to be removed from
5233 static void __devexit
e1000_remove(struct pci_dev
*pdev
)
5235 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5236 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5239 * flush_scheduled work may reschedule our watchdog task, so
5240 * explicitly disable watchdog tasks from being rescheduled
5242 set_bit(__E1000_DOWN
, &adapter
->state
);
5243 del_timer_sync(&adapter
->watchdog_timer
);
5244 del_timer_sync(&adapter
->phy_info_timer
);
5246 flush_scheduled_work();
5249 * Release control of h/w to f/w. If f/w is AMT enabled, this
5250 * would have already happened in close and is redundant.
5252 e1000_release_hw_control(adapter
);
5254 unregister_netdev(netdev
);
5256 if (!e1000_check_reset_block(&adapter
->hw
))
5257 e1000_phy_hw_reset(&adapter
->hw
);
5259 e1000e_reset_interrupt_capability(adapter
);
5260 kfree(adapter
->tx_ring
);
5261 kfree(adapter
->rx_ring
);
5263 iounmap(adapter
->hw
.hw_addr
);
5264 if (adapter
->hw
.flash_address
)
5265 iounmap(adapter
->hw
.flash_address
);
5266 pci_release_selected_regions(pdev
,
5267 pci_select_bars(pdev
, IORESOURCE_MEM
));
5269 free_netdev(netdev
);
5272 pci_disable_pcie_error_reporting(pdev
);
5274 pci_disable_device(pdev
);
5277 /* PCI Error Recovery (ERS) */
5278 static struct pci_error_handlers e1000_err_handler
= {
5279 .error_detected
= e1000_io_error_detected
,
5280 .slot_reset
= e1000_io_slot_reset
,
5281 .resume
= e1000_io_resume
,
5284 static struct pci_device_id e1000_pci_tbl
[] = {
5285 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_COPPER
), board_82571
},
5286 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_FIBER
), board_82571
},
5287 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER
), board_82571
},
5288 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER_LP
), board_82571
},
5289 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_FIBER
), board_82571
},
5290 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES
), board_82571
},
5291 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_DUAL
), board_82571
},
5292 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_QUAD
), board_82571
},
5293 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571PT_QUAD_COPPER
), board_82571
},
5295 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI
), board_82572
},
5296 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_COPPER
), board_82572
},
5297 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_FIBER
), board_82572
},
5298 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_SERDES
), board_82572
},
5300 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E
), board_82573
},
5301 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E_IAMT
), board_82573
},
5302 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573L
), board_82573
},
5304 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82574L
), board_82574
},
5305 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82574LA
), board_82574
},
5306 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82583V
), board_82583
},
5308 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_DPT
),
5309 board_80003es2lan
},
5310 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_SPT
),
5311 board_80003es2lan
},
5312 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_DPT
),
5313 board_80003es2lan
},
5314 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_SPT
),
5315 board_80003es2lan
},
5317 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE
), board_ich8lan
},
5318 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_G
), board_ich8lan
},
5319 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_GT
), board_ich8lan
},
5320 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_AMT
), board_ich8lan
},
5321 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_C
), board_ich8lan
},
5322 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M
), board_ich8lan
},
5323 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M_AMT
), board_ich8lan
},
5325 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE
), board_ich9lan
},
5326 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_G
), board_ich9lan
},
5327 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_GT
), board_ich9lan
},
5328 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_AMT
), board_ich9lan
},
5329 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_C
), board_ich9lan
},
5330 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_BM
), board_ich9lan
},
5331 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M
), board_ich9lan
},
5332 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M_AMT
), board_ich9lan
},
5333 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M_V
), board_ich9lan
},
5335 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_LM
), board_ich9lan
},
5336 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_LF
), board_ich9lan
},
5337 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_V
), board_ich9lan
},
5339 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_LM
), board_ich10lan
},
5340 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_LF
), board_ich10lan
},
5342 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_M_HV_LM
), board_pchlan
},
5343 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_M_HV_LC
), board_pchlan
},
5344 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_D_HV_DM
), board_pchlan
},
5345 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_PCH_D_HV_DC
), board_pchlan
},
5347 { } /* terminate list */
5349 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
5351 /* PCI Device API Driver */
5352 static struct pci_driver e1000_driver
= {
5353 .name
= e1000e_driver_name
,
5354 .id_table
= e1000_pci_tbl
,
5355 .probe
= e1000_probe
,
5356 .remove
= __devexit_p(e1000_remove
),
5358 /* Power Management Hooks */
5359 .suspend
= e1000_suspend
,
5360 .resume
= e1000_resume
,
5362 .shutdown
= e1000_shutdown
,
5363 .err_handler
= &e1000_err_handler
5367 * e1000_init_module - Driver Registration Routine
5369 * e1000_init_module is the first routine called when the driver is
5370 * loaded. All it does is register with the PCI subsystem.
5372 static int __init
e1000_init_module(void)
5375 printk(KERN_INFO
"%s: Intel(R) PRO/1000 Network Driver - %s\n",
5376 e1000e_driver_name
, e1000e_driver_version
);
5377 printk(KERN_INFO
"%s: Copyright (c) 1999-2008 Intel Corporation.\n",
5378 e1000e_driver_name
);
5379 ret
= pci_register_driver(&e1000_driver
);
5380 pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY
, e1000e_driver_name
,
5381 PM_QOS_DEFAULT_VALUE
);
5385 module_init(e1000_init_module
);
5388 * e1000_exit_module - Driver Exit Cleanup Routine
5390 * e1000_exit_module is called just before the driver is removed
5393 static void __exit
e1000_exit_module(void)
5395 pci_unregister_driver(&e1000_driver
);
5396 pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY
, e1000e_driver_name
);
5398 module_exit(e1000_exit_module
);
5401 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
5402 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
5403 MODULE_LICENSE("GPL");
5404 MODULE_VERSION(DRV_VERSION
);