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>
50 #define DRV_VERSION "0.3.3.3-k6"
51 char e1000e_driver_name
[] = "e1000e";
52 const char e1000e_driver_version
[] = DRV_VERSION
;
54 static const struct e1000_info
*e1000_info_tbl
[] = {
55 [board_82571
] = &e1000_82571_info
,
56 [board_82572
] = &e1000_82572_info
,
57 [board_82573
] = &e1000_82573_info
,
58 [board_82574
] = &e1000_82574_info
,
59 [board_80003es2lan
] = &e1000_es2_info
,
60 [board_ich8lan
] = &e1000_ich8_info
,
61 [board_ich9lan
] = &e1000_ich9_info
,
62 [board_ich10lan
] = &e1000_ich10_info
,
67 * e1000_get_hw_dev_name - return device name string
68 * used by hardware layer to print debugging information
70 char *e1000e_get_hw_dev_name(struct e1000_hw
*hw
)
72 return hw
->adapter
->netdev
->name
;
77 * e1000_desc_unused - calculate if we have unused descriptors
79 static int e1000_desc_unused(struct e1000_ring
*ring
)
81 if (ring
->next_to_clean
> ring
->next_to_use
)
82 return ring
->next_to_clean
- ring
->next_to_use
- 1;
84 return ring
->count
+ ring
->next_to_clean
- ring
->next_to_use
- 1;
88 * e1000_receive_skb - helper function to handle Rx indications
89 * @adapter: board private structure
90 * @status: descriptor status field as written by hardware
91 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
92 * @skb: pointer to sk_buff to be indicated to stack
94 static void e1000_receive_skb(struct e1000_adapter
*adapter
,
95 struct net_device
*netdev
,
97 u8 status
, __le16 vlan
)
99 skb
->protocol
= eth_type_trans(skb
, netdev
);
101 if (adapter
->vlgrp
&& (status
& E1000_RXD_STAT_VP
))
102 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
105 netif_receive_skb(skb
);
109 * e1000_rx_checksum - Receive Checksum Offload for 82543
110 * @adapter: board private structure
111 * @status_err: receive descriptor status and error fields
112 * @csum: receive descriptor csum field
113 * @sk_buff: socket buffer with received data
115 static void e1000_rx_checksum(struct e1000_adapter
*adapter
, u32 status_err
,
116 u32 csum
, struct sk_buff
*skb
)
118 u16 status
= (u16
)status_err
;
119 u8 errors
= (u8
)(status_err
>> 24);
120 skb
->ip_summed
= CHECKSUM_NONE
;
122 /* Ignore Checksum bit is set */
123 if (status
& E1000_RXD_STAT_IXSM
)
125 /* TCP/UDP checksum error bit is set */
126 if (errors
& E1000_RXD_ERR_TCPE
) {
127 /* let the stack verify checksum errors */
128 adapter
->hw_csum_err
++;
132 /* TCP/UDP Checksum has not been calculated */
133 if (!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
136 /* It must be a TCP or UDP packet with a valid checksum */
137 if (status
& E1000_RXD_STAT_TCPCS
) {
138 /* TCP checksum is good */
139 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
142 * IP fragment with UDP payload
143 * Hardware complements the payload checksum, so we undo it
144 * and then put the value in host order for further stack use.
146 __sum16 sum
= (__force __sum16
)htons(csum
);
147 skb
->csum
= csum_unfold(~sum
);
148 skb
->ip_summed
= CHECKSUM_COMPLETE
;
150 adapter
->hw_csum_good
++;
154 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
155 * @adapter: address of board private structure
157 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
160 struct net_device
*netdev
= adapter
->netdev
;
161 struct pci_dev
*pdev
= adapter
->pdev
;
162 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
163 struct e1000_rx_desc
*rx_desc
;
164 struct e1000_buffer
*buffer_info
;
167 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
169 i
= rx_ring
->next_to_use
;
170 buffer_info
= &rx_ring
->buffer_info
[i
];
172 while (cleaned_count
--) {
173 skb
= buffer_info
->skb
;
179 skb
= netdev_alloc_skb(netdev
, bufsz
);
181 /* Better luck next round */
182 adapter
->alloc_rx_buff_failed
++;
187 * Make buffer alignment 2 beyond a 16 byte boundary
188 * this will result in a 16 byte aligned IP header after
189 * the 14 byte MAC header is removed
191 skb_reserve(skb
, NET_IP_ALIGN
);
193 buffer_info
->skb
= skb
;
195 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
196 adapter
->rx_buffer_len
,
198 if (pci_dma_mapping_error(pdev
, buffer_info
->dma
)) {
199 dev_err(&pdev
->dev
, "RX DMA map failed\n");
200 adapter
->rx_dma_failed
++;
204 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
205 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
208 if (i
== rx_ring
->count
)
210 buffer_info
= &rx_ring
->buffer_info
[i
];
213 if (rx_ring
->next_to_use
!= i
) {
214 rx_ring
->next_to_use
= i
;
216 i
= (rx_ring
->count
- 1);
219 * Force memory writes to complete before letting h/w
220 * know there are new descriptors to fetch. (Only
221 * applicable for weak-ordered memory model archs,
225 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
230 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
231 * @adapter: address of board private structure
233 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
236 struct net_device
*netdev
= adapter
->netdev
;
237 struct pci_dev
*pdev
= adapter
->pdev
;
238 union e1000_rx_desc_packet_split
*rx_desc
;
239 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
240 struct e1000_buffer
*buffer_info
;
241 struct e1000_ps_page
*ps_page
;
245 i
= rx_ring
->next_to_use
;
246 buffer_info
= &rx_ring
->buffer_info
[i
];
248 while (cleaned_count
--) {
249 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
251 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
252 ps_page
= &buffer_info
->ps_pages
[j
];
253 if (j
>= adapter
->rx_ps_pages
) {
254 /* all unused desc entries get hw null ptr */
255 rx_desc
->read
.buffer_addr
[j
+1] = ~cpu_to_le64(0);
258 if (!ps_page
->page
) {
259 ps_page
->page
= alloc_page(GFP_ATOMIC
);
260 if (!ps_page
->page
) {
261 adapter
->alloc_rx_buff_failed
++;
264 ps_page
->dma
= pci_map_page(pdev
,
268 if (pci_dma_mapping_error(pdev
, ps_page
->dma
)) {
269 dev_err(&adapter
->pdev
->dev
,
270 "RX DMA page map failed\n");
271 adapter
->rx_dma_failed
++;
276 * Refresh the desc even if buffer_addrs
277 * didn't change because each write-back
280 rx_desc
->read
.buffer_addr
[j
+1] =
281 cpu_to_le64(ps_page
->dma
);
284 skb
= netdev_alloc_skb(netdev
,
285 adapter
->rx_ps_bsize0
+ NET_IP_ALIGN
);
288 adapter
->alloc_rx_buff_failed
++;
293 * Make buffer alignment 2 beyond a 16 byte boundary
294 * this will result in a 16 byte aligned IP header after
295 * the 14 byte MAC header is removed
297 skb_reserve(skb
, NET_IP_ALIGN
);
299 buffer_info
->skb
= skb
;
300 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
301 adapter
->rx_ps_bsize0
,
303 if (pci_dma_mapping_error(pdev
, buffer_info
->dma
)) {
304 dev_err(&pdev
->dev
, "RX DMA map failed\n");
305 adapter
->rx_dma_failed
++;
307 dev_kfree_skb_any(skb
);
308 buffer_info
->skb
= NULL
;
312 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
315 if (i
== rx_ring
->count
)
317 buffer_info
= &rx_ring
->buffer_info
[i
];
321 if (rx_ring
->next_to_use
!= i
) {
322 rx_ring
->next_to_use
= i
;
325 i
= (rx_ring
->count
- 1);
328 * Force memory writes to complete before letting h/w
329 * know there are new descriptors to fetch. (Only
330 * applicable for weak-ordered memory model archs,
335 * Hardware increments by 16 bytes, but packet split
336 * descriptors are 32 bytes...so we increment tail
339 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
344 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
345 * @adapter: address of board private structure
346 * @rx_ring: pointer to receive ring structure
347 * @cleaned_count: number of buffers to allocate this pass
350 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter
*adapter
,
353 struct net_device
*netdev
= adapter
->netdev
;
354 struct pci_dev
*pdev
= adapter
->pdev
;
355 struct e1000_rx_desc
*rx_desc
;
356 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
357 struct e1000_buffer
*buffer_info
;
360 unsigned int bufsz
= 256 -
361 16 /* for skb_reserve */ -
364 i
= rx_ring
->next_to_use
;
365 buffer_info
= &rx_ring
->buffer_info
[i
];
367 while (cleaned_count
--) {
368 skb
= buffer_info
->skb
;
374 skb
= netdev_alloc_skb(netdev
, bufsz
);
375 if (unlikely(!skb
)) {
376 /* Better luck next round */
377 adapter
->alloc_rx_buff_failed
++;
381 /* Make buffer alignment 2 beyond a 16 byte boundary
382 * this will result in a 16 byte aligned IP header after
383 * the 14 byte MAC header is removed
385 skb_reserve(skb
, NET_IP_ALIGN
);
387 buffer_info
->skb
= skb
;
389 /* allocate a new page if necessary */
390 if (!buffer_info
->page
) {
391 buffer_info
->page
= alloc_page(GFP_ATOMIC
);
392 if (unlikely(!buffer_info
->page
)) {
393 adapter
->alloc_rx_buff_failed
++;
398 if (!buffer_info
->dma
)
399 buffer_info
->dma
= pci_map_page(pdev
,
400 buffer_info
->page
, 0,
404 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
405 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
407 if (unlikely(++i
== rx_ring
->count
))
409 buffer_info
= &rx_ring
->buffer_info
[i
];
412 if (likely(rx_ring
->next_to_use
!= i
)) {
413 rx_ring
->next_to_use
= i
;
414 if (unlikely(i
-- == 0))
415 i
= (rx_ring
->count
- 1);
417 /* Force memory writes to complete before letting h/w
418 * know there are new descriptors to fetch. (Only
419 * applicable for weak-ordered memory model archs,
422 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
427 * e1000_clean_rx_irq - Send received data up the network stack; legacy
428 * @adapter: board private structure
430 * the return value indicates whether actual cleaning was done, there
431 * is no guarantee that everything was cleaned
433 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
434 int *work_done
, int work_to_do
)
436 struct net_device
*netdev
= adapter
->netdev
;
437 struct pci_dev
*pdev
= adapter
->pdev
;
438 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
439 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
440 struct e1000_buffer
*buffer_info
, *next_buffer
;
443 int cleaned_count
= 0;
445 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
447 i
= rx_ring
->next_to_clean
;
448 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
449 buffer_info
= &rx_ring
->buffer_info
[i
];
451 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
455 if (*work_done
>= work_to_do
)
459 status
= rx_desc
->status
;
460 skb
= buffer_info
->skb
;
461 buffer_info
->skb
= NULL
;
463 prefetch(skb
->data
- NET_IP_ALIGN
);
466 if (i
== rx_ring
->count
)
468 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
471 next_buffer
= &rx_ring
->buffer_info
[i
];
475 pci_unmap_single(pdev
,
477 adapter
->rx_buffer_len
,
479 buffer_info
->dma
= 0;
481 length
= le16_to_cpu(rx_desc
->length
);
483 /* !EOP means multiple descriptors were used to store a single
484 * packet, also make sure the frame isn't just CRC only */
485 if (!(status
& E1000_RXD_STAT_EOP
) || (length
<= 4)) {
486 /* All receives must fit into a single buffer */
487 e_dbg("%s: Receive packet consumed multiple buffers\n",
490 buffer_info
->skb
= skb
;
494 if (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
) {
496 buffer_info
->skb
= skb
;
500 /* adjust length to remove Ethernet CRC */
501 if (!(adapter
->flags2
& FLAG2_CRC_STRIPPING
))
504 total_rx_bytes
+= length
;
508 * code added for copybreak, this should improve
509 * performance for small packets with large amounts
510 * of reassembly being done in the stack
512 if (length
< copybreak
) {
513 struct sk_buff
*new_skb
=
514 netdev_alloc_skb(netdev
, length
+ NET_IP_ALIGN
);
516 skb_reserve(new_skb
, NET_IP_ALIGN
);
517 skb_copy_to_linear_data_offset(new_skb
,
523 /* save the skb in buffer_info as good */
524 buffer_info
->skb
= skb
;
527 /* else just continue with the old one */
529 /* end copybreak code */
530 skb_put(skb
, length
);
532 /* Receive Checksum Offload */
533 e1000_rx_checksum(adapter
,
535 ((u32
)(rx_desc
->errors
) << 24),
536 le16_to_cpu(rx_desc
->csum
), skb
);
538 e1000_receive_skb(adapter
, netdev
, skb
,status
,rx_desc
->special
);
543 /* return some buffers to hardware, one at a time is too slow */
544 if (cleaned_count
>= E1000_RX_BUFFER_WRITE
) {
545 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
549 /* use prefetched values */
551 buffer_info
= next_buffer
;
553 rx_ring
->next_to_clean
= i
;
555 cleaned_count
= e1000_desc_unused(rx_ring
);
557 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
559 adapter
->total_rx_bytes
+= total_rx_bytes
;
560 adapter
->total_rx_packets
+= total_rx_packets
;
561 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
562 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
566 static void e1000_put_txbuf(struct e1000_adapter
*adapter
,
567 struct e1000_buffer
*buffer_info
)
569 if (buffer_info
->dma
) {
570 pci_unmap_page(adapter
->pdev
, buffer_info
->dma
,
571 buffer_info
->length
, PCI_DMA_TODEVICE
);
572 buffer_info
->dma
= 0;
574 if (buffer_info
->skb
) {
575 dev_kfree_skb_any(buffer_info
->skb
);
576 buffer_info
->skb
= NULL
;
580 static void e1000_print_tx_hang(struct e1000_adapter
*adapter
)
582 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
583 unsigned int i
= tx_ring
->next_to_clean
;
584 unsigned int eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
585 struct e1000_tx_desc
*eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
587 /* detected Tx unit hang */
588 e_err("Detected Tx Unit Hang:\n"
591 " next_to_use <%x>\n"
592 " next_to_clean <%x>\n"
593 "buffer_info[next_to_clean]:\n"
594 " time_stamp <%lx>\n"
595 " next_to_watch <%x>\n"
597 " next_to_watch.status <%x>\n",
598 readl(adapter
->hw
.hw_addr
+ tx_ring
->head
),
599 readl(adapter
->hw
.hw_addr
+ tx_ring
->tail
),
600 tx_ring
->next_to_use
,
601 tx_ring
->next_to_clean
,
602 tx_ring
->buffer_info
[eop
].time_stamp
,
605 eop_desc
->upper
.fields
.status
);
609 * e1000_clean_tx_irq - Reclaim resources after transmit completes
610 * @adapter: board private structure
612 * the return value indicates whether actual cleaning was done, there
613 * is no guarantee that everything was cleaned
615 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
)
617 struct net_device
*netdev
= adapter
->netdev
;
618 struct e1000_hw
*hw
= &adapter
->hw
;
619 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
620 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
621 struct e1000_buffer
*buffer_info
;
623 unsigned int count
= 0;
625 unsigned int total_tx_bytes
= 0, total_tx_packets
= 0;
627 i
= tx_ring
->next_to_clean
;
628 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
629 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
631 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
632 for (cleaned
= 0; !cleaned
; ) {
633 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
634 buffer_info
= &tx_ring
->buffer_info
[i
];
635 cleaned
= (i
== eop
);
638 struct sk_buff
*skb
= buffer_info
->skb
;
639 unsigned int segs
, bytecount
;
640 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
641 /* multiply data chunks by size of headers */
642 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
644 total_tx_packets
+= segs
;
645 total_tx_bytes
+= bytecount
;
648 e1000_put_txbuf(adapter
, buffer_info
);
649 tx_desc
->upper
.data
= 0;
652 if (i
== tx_ring
->count
)
656 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
657 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
658 #define E1000_TX_WEIGHT 64
659 /* weight of a sort for tx, to avoid endless transmit cleanup */
660 if (count
++ == E1000_TX_WEIGHT
)
664 tx_ring
->next_to_clean
= i
;
666 #define TX_WAKE_THRESHOLD 32
667 if (cleaned
&& netif_carrier_ok(netdev
) &&
668 e1000_desc_unused(tx_ring
) >= TX_WAKE_THRESHOLD
) {
669 /* Make sure that anybody stopping the queue after this
670 * sees the new next_to_clean.
674 if (netif_queue_stopped(netdev
) &&
675 !(test_bit(__E1000_DOWN
, &adapter
->state
))) {
676 netif_wake_queue(netdev
);
677 ++adapter
->restart_queue
;
681 if (adapter
->detect_tx_hung
) {
683 * Detect a transmit hang in hardware, this serializes the
684 * check with the clearing of time_stamp and movement of i
686 adapter
->detect_tx_hung
= 0;
687 if (tx_ring
->buffer_info
[eop
].dma
&&
688 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
689 + (adapter
->tx_timeout_factor
* HZ
))
690 && !(er32(STATUS
) & E1000_STATUS_TXOFF
)) {
691 e1000_print_tx_hang(adapter
);
692 netif_stop_queue(netdev
);
695 adapter
->total_tx_bytes
+= total_tx_bytes
;
696 adapter
->total_tx_packets
+= total_tx_packets
;
697 adapter
->net_stats
.tx_bytes
+= total_tx_bytes
;
698 adapter
->net_stats
.tx_packets
+= total_tx_packets
;
703 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
704 * @adapter: board private structure
706 * the return value indicates whether actual cleaning was done, there
707 * is no guarantee that everything was cleaned
709 static bool e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
710 int *work_done
, int work_to_do
)
712 union e1000_rx_desc_packet_split
*rx_desc
, *next_rxd
;
713 struct net_device
*netdev
= adapter
->netdev
;
714 struct pci_dev
*pdev
= adapter
->pdev
;
715 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
716 struct e1000_buffer
*buffer_info
, *next_buffer
;
717 struct e1000_ps_page
*ps_page
;
721 int cleaned_count
= 0;
723 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
725 i
= rx_ring
->next_to_clean
;
726 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
727 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
728 buffer_info
= &rx_ring
->buffer_info
[i
];
730 while (staterr
& E1000_RXD_STAT_DD
) {
731 if (*work_done
>= work_to_do
)
734 skb
= buffer_info
->skb
;
736 /* in the packet split case this is header only */
737 prefetch(skb
->data
- NET_IP_ALIGN
);
740 if (i
== rx_ring
->count
)
742 next_rxd
= E1000_RX_DESC_PS(*rx_ring
, i
);
745 next_buffer
= &rx_ring
->buffer_info
[i
];
749 pci_unmap_single(pdev
, buffer_info
->dma
,
750 adapter
->rx_ps_bsize0
,
752 buffer_info
->dma
= 0;
754 if (!(staterr
& E1000_RXD_STAT_EOP
)) {
755 e_dbg("%s: Packet Split buffers didn't pick up the "
756 "full packet\n", netdev
->name
);
757 dev_kfree_skb_irq(skb
);
761 if (staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
) {
762 dev_kfree_skb_irq(skb
);
766 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
769 e_dbg("%s: Last part of the packet spanning multiple "
770 "descriptors\n", netdev
->name
);
771 dev_kfree_skb_irq(skb
);
776 skb_put(skb
, length
);
780 * this looks ugly, but it seems compiler issues make it
781 * more efficient than reusing j
783 int l1
= le16_to_cpu(rx_desc
->wb
.upper
.length
[0]);
786 * page alloc/put takes too long and effects small packet
787 * throughput, so unsplit small packets and save the alloc/put
788 * only valid in softirq (napi) context to call kmap_*
790 if (l1
&& (l1
<= copybreak
) &&
791 ((length
+ l1
) <= adapter
->rx_ps_bsize0
)) {
794 ps_page
= &buffer_info
->ps_pages
[0];
797 * there is no documentation about how to call
798 * kmap_atomic, so we can't hold the mapping
801 pci_dma_sync_single_for_cpu(pdev
, ps_page
->dma
,
802 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
803 vaddr
= kmap_atomic(ps_page
->page
, KM_SKB_DATA_SOFTIRQ
);
804 memcpy(skb_tail_pointer(skb
), vaddr
, l1
);
805 kunmap_atomic(vaddr
, KM_SKB_DATA_SOFTIRQ
);
806 pci_dma_sync_single_for_device(pdev
, ps_page
->dma
,
807 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
810 if (!(adapter
->flags2
& FLAG2_CRC_STRIPPING
))
818 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
819 length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
]);
823 ps_page
= &buffer_info
->ps_pages
[j
];
824 pci_unmap_page(pdev
, ps_page
->dma
, PAGE_SIZE
,
827 skb_fill_page_desc(skb
, j
, ps_page
->page
, 0, length
);
828 ps_page
->page
= NULL
;
830 skb
->data_len
+= length
;
831 skb
->truesize
+= length
;
834 /* strip the ethernet crc, problem is we're using pages now so
835 * this whole operation can get a little cpu intensive
837 if (!(adapter
->flags2
& FLAG2_CRC_STRIPPING
))
838 pskb_trim(skb
, skb
->len
- 4);
841 total_rx_bytes
+= skb
->len
;
844 e1000_rx_checksum(adapter
, staterr
, le16_to_cpu(
845 rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
), skb
);
847 if (rx_desc
->wb
.upper
.header_status
&
848 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP
))
849 adapter
->rx_hdr_split
++;
851 e1000_receive_skb(adapter
, netdev
, skb
,
852 staterr
, rx_desc
->wb
.middle
.vlan
);
855 rx_desc
->wb
.middle
.status_error
&= cpu_to_le32(~0xFF);
856 buffer_info
->skb
= NULL
;
858 /* return some buffers to hardware, one at a time is too slow */
859 if (cleaned_count
>= E1000_RX_BUFFER_WRITE
) {
860 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
864 /* use prefetched values */
866 buffer_info
= next_buffer
;
868 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
870 rx_ring
->next_to_clean
= i
;
872 cleaned_count
= e1000_desc_unused(rx_ring
);
874 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
876 adapter
->total_rx_bytes
+= total_rx_bytes
;
877 adapter
->total_rx_packets
+= total_rx_packets
;
878 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
879 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
884 * e1000_consume_page - helper function
886 static void e1000_consume_page(struct e1000_buffer
*bi
, struct sk_buff
*skb
,
891 skb
->data_len
+= length
;
892 skb
->truesize
+= length
;
896 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
897 * @adapter: board private structure
899 * the return value indicates whether actual cleaning was done, there
900 * is no guarantee that everything was cleaned
903 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter
*adapter
,
904 int *work_done
, int work_to_do
)
906 struct net_device
*netdev
= adapter
->netdev
;
907 struct pci_dev
*pdev
= adapter
->pdev
;
908 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
909 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
910 struct e1000_buffer
*buffer_info
, *next_buffer
;
913 int cleaned_count
= 0;
914 bool cleaned
= false;
915 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
917 i
= rx_ring
->next_to_clean
;
918 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
919 buffer_info
= &rx_ring
->buffer_info
[i
];
921 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
925 if (*work_done
>= work_to_do
)
929 status
= rx_desc
->status
;
930 skb
= buffer_info
->skb
;
931 buffer_info
->skb
= NULL
;
934 if (i
== rx_ring
->count
)
936 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
939 next_buffer
= &rx_ring
->buffer_info
[i
];
943 pci_unmap_page(pdev
, buffer_info
->dma
, PAGE_SIZE
,
945 buffer_info
->dma
= 0;
947 length
= le16_to_cpu(rx_desc
->length
);
949 /* errors is only valid for DD + EOP descriptors */
950 if (unlikely((status
& E1000_RXD_STAT_EOP
) &&
951 (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
))) {
952 /* recycle both page and skb */
953 buffer_info
->skb
= skb
;
954 /* an error means any chain goes out the window
956 if (rx_ring
->rx_skb_top
)
957 dev_kfree_skb(rx_ring
->rx_skb_top
);
958 rx_ring
->rx_skb_top
= NULL
;
962 #define rxtop rx_ring->rx_skb_top
963 if (!(status
& E1000_RXD_STAT_EOP
)) {
964 /* this descriptor is only the beginning (or middle) */
966 /* this is the beginning of a chain */
968 skb_fill_page_desc(rxtop
, 0, buffer_info
->page
,
971 /* this is the middle of a chain */
972 skb_fill_page_desc(rxtop
,
973 skb_shinfo(rxtop
)->nr_frags
,
974 buffer_info
->page
, 0, length
);
975 /* re-use the skb, only consumed the page */
976 buffer_info
->skb
= skb
;
978 e1000_consume_page(buffer_info
, rxtop
, length
);
982 /* end of the chain */
983 skb_fill_page_desc(rxtop
,
984 skb_shinfo(rxtop
)->nr_frags
,
985 buffer_info
->page
, 0, length
);
986 /* re-use the current skb, we only consumed the
988 buffer_info
->skb
= skb
;
991 e1000_consume_page(buffer_info
, skb
, length
);
993 /* no chain, got EOP, this buf is the packet
994 * copybreak to save the put_page/alloc_page */
995 if (length
<= copybreak
&&
996 skb_tailroom(skb
) >= length
) {
998 vaddr
= kmap_atomic(buffer_info
->page
,
999 KM_SKB_DATA_SOFTIRQ
);
1000 memcpy(skb_tail_pointer(skb
), vaddr
,
1002 kunmap_atomic(vaddr
,
1003 KM_SKB_DATA_SOFTIRQ
);
1004 /* re-use the page, so don't erase
1005 * buffer_info->page */
1006 skb_put(skb
, length
);
1008 skb_fill_page_desc(skb
, 0,
1009 buffer_info
->page
, 0,
1011 e1000_consume_page(buffer_info
, skb
,
1017 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1018 e1000_rx_checksum(adapter
,
1020 ((u32
)(rx_desc
->errors
) << 24),
1021 le16_to_cpu(rx_desc
->csum
), skb
);
1023 /* probably a little skewed due to removing CRC */
1024 total_rx_bytes
+= skb
->len
;
1027 /* eth type trans needs skb->data to point to something */
1028 if (!pskb_may_pull(skb
, ETH_HLEN
)) {
1029 e_err("pskb_may_pull failed.\n");
1034 e1000_receive_skb(adapter
, netdev
, skb
, status
,
1038 rx_desc
->status
= 0;
1040 /* return some buffers to hardware, one at a time is too slow */
1041 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
1042 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
1046 /* use prefetched values */
1048 buffer_info
= next_buffer
;
1050 rx_ring
->next_to_clean
= i
;
1052 cleaned_count
= e1000_desc_unused(rx_ring
);
1054 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
1056 adapter
->total_rx_bytes
+= total_rx_bytes
;
1057 adapter
->total_rx_packets
+= total_rx_packets
;
1058 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
1059 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
1064 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1065 * @adapter: board private structure
1067 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
)
1069 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1070 struct e1000_buffer
*buffer_info
;
1071 struct e1000_ps_page
*ps_page
;
1072 struct pci_dev
*pdev
= adapter
->pdev
;
1075 /* Free all the Rx ring sk_buffs */
1076 for (i
= 0; i
< rx_ring
->count
; i
++) {
1077 buffer_info
= &rx_ring
->buffer_info
[i
];
1078 if (buffer_info
->dma
) {
1079 if (adapter
->clean_rx
== e1000_clean_rx_irq
)
1080 pci_unmap_single(pdev
, buffer_info
->dma
,
1081 adapter
->rx_buffer_len
,
1082 PCI_DMA_FROMDEVICE
);
1083 else if (adapter
->clean_rx
== e1000_clean_jumbo_rx_irq
)
1084 pci_unmap_page(pdev
, buffer_info
->dma
,
1086 PCI_DMA_FROMDEVICE
);
1087 else if (adapter
->clean_rx
== e1000_clean_rx_irq_ps
)
1088 pci_unmap_single(pdev
, buffer_info
->dma
,
1089 adapter
->rx_ps_bsize0
,
1090 PCI_DMA_FROMDEVICE
);
1091 buffer_info
->dma
= 0;
1094 if (buffer_info
->page
) {
1095 put_page(buffer_info
->page
);
1096 buffer_info
->page
= NULL
;
1099 if (buffer_info
->skb
) {
1100 dev_kfree_skb(buffer_info
->skb
);
1101 buffer_info
->skb
= NULL
;
1104 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
1105 ps_page
= &buffer_info
->ps_pages
[j
];
1108 pci_unmap_page(pdev
, ps_page
->dma
, PAGE_SIZE
,
1109 PCI_DMA_FROMDEVICE
);
1111 put_page(ps_page
->page
);
1112 ps_page
->page
= NULL
;
1116 /* there also may be some cached data from a chained receive */
1117 if (rx_ring
->rx_skb_top
) {
1118 dev_kfree_skb(rx_ring
->rx_skb_top
);
1119 rx_ring
->rx_skb_top
= NULL
;
1122 /* Zero out the descriptor ring */
1123 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1125 rx_ring
->next_to_clean
= 0;
1126 rx_ring
->next_to_use
= 0;
1128 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1129 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1132 static void e1000e_downshift_workaround(struct work_struct
*work
)
1134 struct e1000_adapter
*adapter
= container_of(work
,
1135 struct e1000_adapter
, downshift_task
);
1137 e1000e_gig_downshift_workaround_ich8lan(&adapter
->hw
);
1141 * e1000_intr_msi - Interrupt Handler
1142 * @irq: interrupt number
1143 * @data: pointer to a network interface device structure
1145 static irqreturn_t
e1000_intr_msi(int irq
, void *data
)
1147 struct net_device
*netdev
= data
;
1148 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1149 struct e1000_hw
*hw
= &adapter
->hw
;
1150 u32 icr
= er32(ICR
);
1153 * read ICR disables interrupts using IAM
1156 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
1157 hw
->mac
.get_link_status
= 1;
1159 * ICH8 workaround-- Call gig speed drop workaround on cable
1160 * disconnect (LSC) before accessing any PHY registers
1162 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
1163 (!(er32(STATUS
) & E1000_STATUS_LU
)))
1164 schedule_work(&adapter
->downshift_task
);
1167 * 80003ES2LAN workaround-- For packet buffer work-around on
1168 * link down event; disable receives here in the ISR and reset
1169 * adapter in watchdog
1171 if (netif_carrier_ok(netdev
) &&
1172 adapter
->flags
& FLAG_RX_NEEDS_RESTART
) {
1173 /* disable receives */
1174 u32 rctl
= er32(RCTL
);
1175 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1176 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
1178 /* guard against interrupt when we're going down */
1179 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1180 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1183 if (netif_rx_schedule_prep(netdev
, &adapter
->napi
)) {
1184 adapter
->total_tx_bytes
= 0;
1185 adapter
->total_tx_packets
= 0;
1186 adapter
->total_rx_bytes
= 0;
1187 adapter
->total_rx_packets
= 0;
1188 __netif_rx_schedule(netdev
, &adapter
->napi
);
1195 * e1000_intr - Interrupt Handler
1196 * @irq: interrupt number
1197 * @data: pointer to a network interface device structure
1199 static irqreturn_t
e1000_intr(int irq
, void *data
)
1201 struct net_device
*netdev
= data
;
1202 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1203 struct e1000_hw
*hw
= &adapter
->hw
;
1204 u32 rctl
, icr
= er32(ICR
);
1207 return IRQ_NONE
; /* Not our interrupt */
1210 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1211 * not set, then the adapter didn't send an interrupt
1213 if (!(icr
& E1000_ICR_INT_ASSERTED
))
1217 * Interrupt Auto-Mask...upon reading ICR,
1218 * interrupts are masked. No need for the
1222 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
1223 hw
->mac
.get_link_status
= 1;
1225 * ICH8 workaround-- Call gig speed drop workaround on cable
1226 * disconnect (LSC) before accessing any PHY registers
1228 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
1229 (!(er32(STATUS
) & E1000_STATUS_LU
)))
1230 schedule_work(&adapter
->downshift_task
);
1233 * 80003ES2LAN workaround--
1234 * For packet buffer work-around on link down event;
1235 * disable receives here in the ISR and
1236 * reset adapter in watchdog
1238 if (netif_carrier_ok(netdev
) &&
1239 (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)) {
1240 /* disable receives */
1242 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1243 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
1245 /* guard against interrupt when we're going down */
1246 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1247 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1250 if (netif_rx_schedule_prep(netdev
, &adapter
->napi
)) {
1251 adapter
->total_tx_bytes
= 0;
1252 adapter
->total_tx_packets
= 0;
1253 adapter
->total_rx_bytes
= 0;
1254 adapter
->total_rx_packets
= 0;
1255 __netif_rx_schedule(netdev
, &adapter
->napi
);
1261 static irqreturn_t
e1000_msix_other(int irq
, void *data
)
1263 struct net_device
*netdev
= data
;
1264 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1265 struct e1000_hw
*hw
= &adapter
->hw
;
1266 u32 icr
= er32(ICR
);
1268 if (!(icr
& E1000_ICR_INT_ASSERTED
)) {
1269 ew32(IMS
, E1000_IMS_OTHER
);
1273 if (icr
& adapter
->eiac_mask
)
1274 ew32(ICS
, (icr
& adapter
->eiac_mask
));
1276 if (icr
& E1000_ICR_OTHER
) {
1277 if (!(icr
& E1000_ICR_LSC
))
1278 goto no_link_interrupt
;
1279 hw
->mac
.get_link_status
= 1;
1280 /* guard against interrupt when we're going down */
1281 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1282 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
1286 ew32(IMS
, E1000_IMS_LSC
| E1000_IMS_OTHER
);
1292 static irqreturn_t
e1000_intr_msix_tx(int irq
, void *data
)
1294 struct net_device
*netdev
= data
;
1295 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1296 struct e1000_hw
*hw
= &adapter
->hw
;
1297 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1300 adapter
->total_tx_bytes
= 0;
1301 adapter
->total_tx_packets
= 0;
1303 if (!e1000_clean_tx_irq(adapter
))
1304 /* Ring was not completely cleaned, so fire another interrupt */
1305 ew32(ICS
, tx_ring
->ims_val
);
1310 static irqreturn_t
e1000_intr_msix_rx(int irq
, void *data
)
1312 struct net_device
*netdev
= data
;
1313 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1315 /* Write the ITR value calculated at the end of the
1316 * previous interrupt.
1318 if (adapter
->rx_ring
->set_itr
) {
1319 writel(1000000000 / (adapter
->rx_ring
->itr_val
* 256),
1320 adapter
->hw
.hw_addr
+ adapter
->rx_ring
->itr_register
);
1321 adapter
->rx_ring
->set_itr
= 0;
1324 if (netif_rx_schedule_prep(netdev
, &adapter
->napi
)) {
1325 adapter
->total_rx_bytes
= 0;
1326 adapter
->total_rx_packets
= 0;
1327 __netif_rx_schedule(netdev
, &adapter
->napi
);
1333 * e1000_configure_msix - Configure MSI-X hardware
1335 * e1000_configure_msix sets up the hardware to properly
1336 * generate MSI-X interrupts.
1338 static void e1000_configure_msix(struct e1000_adapter
*adapter
)
1340 struct e1000_hw
*hw
= &adapter
->hw
;
1341 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1342 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1344 u32 ctrl_ext
, ivar
= 0;
1346 adapter
->eiac_mask
= 0;
1348 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1349 if (hw
->mac
.type
== e1000_82574
) {
1350 u32 rfctl
= er32(RFCTL
);
1351 rfctl
|= E1000_RFCTL_ACK_DIS
;
1355 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1356 /* Configure Rx vector */
1357 rx_ring
->ims_val
= E1000_IMS_RXQ0
;
1358 adapter
->eiac_mask
|= rx_ring
->ims_val
;
1359 if (rx_ring
->itr_val
)
1360 writel(1000000000 / (rx_ring
->itr_val
* 256),
1361 hw
->hw_addr
+ rx_ring
->itr_register
);
1363 writel(1, hw
->hw_addr
+ rx_ring
->itr_register
);
1364 ivar
= E1000_IVAR_INT_ALLOC_VALID
| vector
;
1366 /* Configure Tx vector */
1367 tx_ring
->ims_val
= E1000_IMS_TXQ0
;
1369 if (tx_ring
->itr_val
)
1370 writel(1000000000 / (tx_ring
->itr_val
* 256),
1371 hw
->hw_addr
+ tx_ring
->itr_register
);
1373 writel(1, hw
->hw_addr
+ tx_ring
->itr_register
);
1374 adapter
->eiac_mask
|= tx_ring
->ims_val
;
1375 ivar
|= ((E1000_IVAR_INT_ALLOC_VALID
| vector
) << 8);
1377 /* set vector for Other Causes, e.g. link changes */
1379 ivar
|= ((E1000_IVAR_INT_ALLOC_VALID
| vector
) << 16);
1380 if (rx_ring
->itr_val
)
1381 writel(1000000000 / (rx_ring
->itr_val
* 256),
1382 hw
->hw_addr
+ E1000_EITR_82574(vector
));
1384 writel(1, hw
->hw_addr
+ E1000_EITR_82574(vector
));
1386 /* Cause Tx interrupts on every write back */
1391 /* enable MSI-X PBA support */
1392 ctrl_ext
= er32(CTRL_EXT
);
1393 ctrl_ext
|= E1000_CTRL_EXT_PBA_CLR
;
1395 /* Auto-Mask Other interrupts upon ICR read */
1396 #define E1000_EIAC_MASK_82574 0x01F00000
1397 ew32(IAM
, ~E1000_EIAC_MASK_82574
| E1000_IMS_OTHER
);
1398 ctrl_ext
|= E1000_CTRL_EXT_EIAME
;
1399 ew32(CTRL_EXT
, ctrl_ext
);
1403 void e1000e_reset_interrupt_capability(struct e1000_adapter
*adapter
)
1405 if (adapter
->msix_entries
) {
1406 pci_disable_msix(adapter
->pdev
);
1407 kfree(adapter
->msix_entries
);
1408 adapter
->msix_entries
= NULL
;
1409 } else if (adapter
->flags
& FLAG_MSI_ENABLED
) {
1410 pci_disable_msi(adapter
->pdev
);
1411 adapter
->flags
&= ~FLAG_MSI_ENABLED
;
1418 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1420 * Attempt to configure interrupts using the best available
1421 * capabilities of the hardware and kernel.
1423 void e1000e_set_interrupt_capability(struct e1000_adapter
*adapter
)
1429 switch (adapter
->int_mode
) {
1430 case E1000E_INT_MODE_MSIX
:
1431 if (adapter
->flags
& FLAG_HAS_MSIX
) {
1432 numvecs
= 3; /* RxQ0, TxQ0 and other */
1433 adapter
->msix_entries
= kcalloc(numvecs
,
1434 sizeof(struct msix_entry
),
1436 if (adapter
->msix_entries
) {
1437 for (i
= 0; i
< numvecs
; i
++)
1438 adapter
->msix_entries
[i
].entry
= i
;
1440 err
= pci_enable_msix(adapter
->pdev
,
1441 adapter
->msix_entries
,
1446 /* MSI-X failed, so fall through and try MSI */
1447 e_err("Failed to initialize MSI-X interrupts. "
1448 "Falling back to MSI interrupts.\n");
1449 e1000e_reset_interrupt_capability(adapter
);
1451 adapter
->int_mode
= E1000E_INT_MODE_MSI
;
1453 case E1000E_INT_MODE_MSI
:
1454 if (!pci_enable_msi(adapter
->pdev
)) {
1455 adapter
->flags
|= FLAG_MSI_ENABLED
;
1457 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
1458 e_err("Failed to initialize MSI interrupts. Falling "
1459 "back to legacy interrupts.\n");
1462 case E1000E_INT_MODE_LEGACY
:
1463 /* Don't do anything; this is the system default */
1471 * e1000_request_msix - Initialize MSI-X interrupts
1473 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1476 static int e1000_request_msix(struct e1000_adapter
*adapter
)
1478 struct net_device
*netdev
= adapter
->netdev
;
1479 int err
= 0, vector
= 0;
1481 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
1482 sprintf(adapter
->rx_ring
->name
, "%s-rx0", netdev
->name
);
1484 memcpy(adapter
->rx_ring
->name
, netdev
->name
, IFNAMSIZ
);
1485 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1486 &e1000_intr_msix_rx
, 0, adapter
->rx_ring
->name
,
1490 adapter
->rx_ring
->itr_register
= E1000_EITR_82574(vector
);
1491 adapter
->rx_ring
->itr_val
= adapter
->itr
;
1494 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
1495 sprintf(adapter
->tx_ring
->name
, "%s-tx0", netdev
->name
);
1497 memcpy(adapter
->tx_ring
->name
, netdev
->name
, IFNAMSIZ
);
1498 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1499 &e1000_intr_msix_tx
, 0, adapter
->tx_ring
->name
,
1503 adapter
->tx_ring
->itr_register
= E1000_EITR_82574(vector
);
1504 adapter
->tx_ring
->itr_val
= adapter
->itr
;
1507 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1508 &e1000_msix_other
, 0, netdev
->name
, netdev
);
1512 e1000_configure_msix(adapter
);
1519 * e1000_request_irq - initialize interrupts
1521 * Attempts to configure interrupts using the best available
1522 * capabilities of the hardware and kernel.
1524 static int e1000_request_irq(struct e1000_adapter
*adapter
)
1526 struct net_device
*netdev
= adapter
->netdev
;
1529 if (adapter
->msix_entries
) {
1530 err
= e1000_request_msix(adapter
);
1533 /* fall back to MSI */
1534 e1000e_reset_interrupt_capability(adapter
);
1535 adapter
->int_mode
= E1000E_INT_MODE_MSI
;
1536 e1000e_set_interrupt_capability(adapter
);
1538 if (adapter
->flags
& FLAG_MSI_ENABLED
) {
1539 err
= request_irq(adapter
->pdev
->irq
, &e1000_intr_msi
, 0,
1540 netdev
->name
, netdev
);
1544 /* fall back to legacy interrupt */
1545 e1000e_reset_interrupt_capability(adapter
);
1546 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
1549 err
= request_irq(adapter
->pdev
->irq
, &e1000_intr
, IRQF_SHARED
,
1550 netdev
->name
, netdev
);
1552 e_err("Unable to allocate interrupt, Error: %d\n", err
);
1557 static void e1000_free_irq(struct e1000_adapter
*adapter
)
1559 struct net_device
*netdev
= adapter
->netdev
;
1561 if (adapter
->msix_entries
) {
1564 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
1567 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
1570 /* Other Causes interrupt vector */
1571 free_irq(adapter
->msix_entries
[vector
].vector
, netdev
);
1575 free_irq(adapter
->pdev
->irq
, netdev
);
1579 * e1000_irq_disable - Mask off interrupt generation on the NIC
1581 static void e1000_irq_disable(struct e1000_adapter
*adapter
)
1583 struct e1000_hw
*hw
= &adapter
->hw
;
1586 if (adapter
->msix_entries
)
1587 ew32(EIAC_82574
, 0);
1589 synchronize_irq(adapter
->pdev
->irq
);
1593 * e1000_irq_enable - Enable default interrupt generation settings
1595 static void e1000_irq_enable(struct e1000_adapter
*adapter
)
1597 struct e1000_hw
*hw
= &adapter
->hw
;
1599 if (adapter
->msix_entries
) {
1600 ew32(EIAC_82574
, adapter
->eiac_mask
& E1000_EIAC_MASK_82574
);
1601 ew32(IMS
, adapter
->eiac_mask
| E1000_IMS_OTHER
| E1000_IMS_LSC
);
1603 ew32(IMS
, IMS_ENABLE_MASK
);
1609 * e1000_get_hw_control - get control of the h/w from f/w
1610 * @adapter: address of board private structure
1612 * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1613 * For ASF and Pass Through versions of f/w this means that
1614 * the driver is loaded. For AMT version (only with 82573)
1615 * of the f/w this means that the network i/f is open.
1617 static void e1000_get_hw_control(struct e1000_adapter
*adapter
)
1619 struct e1000_hw
*hw
= &adapter
->hw
;
1623 /* Let firmware know the driver has taken over */
1624 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
1626 ew32(SWSM
, swsm
| E1000_SWSM_DRV_LOAD
);
1627 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
1628 ctrl_ext
= er32(CTRL_EXT
);
1629 ew32(CTRL_EXT
, ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
1634 * e1000_release_hw_control - release control of the h/w to f/w
1635 * @adapter: address of board private structure
1637 * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1638 * For ASF and Pass Through versions of f/w this means that the
1639 * driver is no longer loaded. For AMT version (only with 82573) i
1640 * of the f/w this means that the network i/f is closed.
1643 static void e1000_release_hw_control(struct e1000_adapter
*adapter
)
1645 struct e1000_hw
*hw
= &adapter
->hw
;
1649 /* Let firmware taken over control of h/w */
1650 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
1652 ew32(SWSM
, swsm
& ~E1000_SWSM_DRV_LOAD
);
1653 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
1654 ctrl_ext
= er32(CTRL_EXT
);
1655 ew32(CTRL_EXT
, ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
1660 * @e1000_alloc_ring - allocate memory for a ring structure
1662 static int e1000_alloc_ring_dma(struct e1000_adapter
*adapter
,
1663 struct e1000_ring
*ring
)
1665 struct pci_dev
*pdev
= adapter
->pdev
;
1667 ring
->desc
= dma_alloc_coherent(&pdev
->dev
, ring
->size
, &ring
->dma
,
1676 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1677 * @adapter: board private structure
1679 * Return 0 on success, negative on failure
1681 int e1000e_setup_tx_resources(struct e1000_adapter
*adapter
)
1683 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1684 int err
= -ENOMEM
, size
;
1686 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1687 tx_ring
->buffer_info
= vmalloc(size
);
1688 if (!tx_ring
->buffer_info
)
1690 memset(tx_ring
->buffer_info
, 0, size
);
1692 /* round up to nearest 4K */
1693 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1694 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1696 err
= e1000_alloc_ring_dma(adapter
, tx_ring
);
1700 tx_ring
->next_to_use
= 0;
1701 tx_ring
->next_to_clean
= 0;
1702 spin_lock_init(&adapter
->tx_queue_lock
);
1706 vfree(tx_ring
->buffer_info
);
1707 e_err("Unable to allocate memory for the transmit descriptor ring\n");
1712 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1713 * @adapter: board private structure
1715 * Returns 0 on success, negative on failure
1717 int e1000e_setup_rx_resources(struct e1000_adapter
*adapter
)
1719 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1720 struct e1000_buffer
*buffer_info
;
1721 int i
, size
, desc_len
, err
= -ENOMEM
;
1723 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
1724 rx_ring
->buffer_info
= vmalloc(size
);
1725 if (!rx_ring
->buffer_info
)
1727 memset(rx_ring
->buffer_info
, 0, size
);
1729 for (i
= 0; i
< rx_ring
->count
; i
++) {
1730 buffer_info
= &rx_ring
->buffer_info
[i
];
1731 buffer_info
->ps_pages
= kcalloc(PS_PAGE_BUFFERS
,
1732 sizeof(struct e1000_ps_page
),
1734 if (!buffer_info
->ps_pages
)
1738 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1740 /* Round up to nearest 4K */
1741 rx_ring
->size
= rx_ring
->count
* desc_len
;
1742 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
1744 err
= e1000_alloc_ring_dma(adapter
, rx_ring
);
1748 rx_ring
->next_to_clean
= 0;
1749 rx_ring
->next_to_use
= 0;
1750 rx_ring
->rx_skb_top
= NULL
;
1755 for (i
= 0; i
< rx_ring
->count
; i
++) {
1756 buffer_info
= &rx_ring
->buffer_info
[i
];
1757 kfree(buffer_info
->ps_pages
);
1760 vfree(rx_ring
->buffer_info
);
1761 e_err("Unable to allocate memory for the transmit descriptor ring\n");
1766 * e1000_clean_tx_ring - Free Tx Buffers
1767 * @adapter: board private structure
1769 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
)
1771 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1772 struct e1000_buffer
*buffer_info
;
1776 for (i
= 0; i
< tx_ring
->count
; i
++) {
1777 buffer_info
= &tx_ring
->buffer_info
[i
];
1778 e1000_put_txbuf(adapter
, buffer_info
);
1781 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1782 memset(tx_ring
->buffer_info
, 0, size
);
1784 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1786 tx_ring
->next_to_use
= 0;
1787 tx_ring
->next_to_clean
= 0;
1789 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1790 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1794 * e1000e_free_tx_resources - Free Tx Resources per Queue
1795 * @adapter: board private structure
1797 * Free all transmit software resources
1799 void e1000e_free_tx_resources(struct e1000_adapter
*adapter
)
1801 struct pci_dev
*pdev
= adapter
->pdev
;
1802 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1804 e1000_clean_tx_ring(adapter
);
1806 vfree(tx_ring
->buffer_info
);
1807 tx_ring
->buffer_info
= NULL
;
1809 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1811 tx_ring
->desc
= NULL
;
1815 * e1000e_free_rx_resources - Free Rx Resources
1816 * @adapter: board private structure
1818 * Free all receive software resources
1821 void e1000e_free_rx_resources(struct e1000_adapter
*adapter
)
1823 struct pci_dev
*pdev
= adapter
->pdev
;
1824 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1827 e1000_clean_rx_ring(adapter
);
1829 for (i
= 0; i
< rx_ring
->count
; i
++) {
1830 kfree(rx_ring
->buffer_info
[i
].ps_pages
);
1833 vfree(rx_ring
->buffer_info
);
1834 rx_ring
->buffer_info
= NULL
;
1836 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
1838 rx_ring
->desc
= NULL
;
1842 * e1000_update_itr - update the dynamic ITR value based on statistics
1843 * @adapter: pointer to adapter
1844 * @itr_setting: current adapter->itr
1845 * @packets: the number of packets during this measurement interval
1846 * @bytes: the number of bytes during this measurement interval
1848 * Stores a new ITR value based on packets and byte
1849 * counts during the last interrupt. The advantage of per interrupt
1850 * computation is faster updates and more accurate ITR for the current
1851 * traffic pattern. Constants in this function were computed
1852 * based on theoretical maximum wire speed and thresholds were set based
1853 * on testing data as well as attempting to minimize response time
1854 * while increasing bulk throughput. This functionality is controlled
1855 * by the InterruptThrottleRate module parameter.
1857 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
1858 u16 itr_setting
, int packets
,
1861 unsigned int retval
= itr_setting
;
1864 goto update_itr_done
;
1866 switch (itr_setting
) {
1867 case lowest_latency
:
1868 /* handle TSO and jumbo frames */
1869 if (bytes
/packets
> 8000)
1870 retval
= bulk_latency
;
1871 else if ((packets
< 5) && (bytes
> 512)) {
1872 retval
= low_latency
;
1875 case low_latency
: /* 50 usec aka 20000 ints/s */
1876 if (bytes
> 10000) {
1877 /* this if handles the TSO accounting */
1878 if (bytes
/packets
> 8000) {
1879 retval
= bulk_latency
;
1880 } else if ((packets
< 10) || ((bytes
/packets
) > 1200)) {
1881 retval
= bulk_latency
;
1882 } else if ((packets
> 35)) {
1883 retval
= lowest_latency
;
1885 } else if (bytes
/packets
> 2000) {
1886 retval
= bulk_latency
;
1887 } else if (packets
<= 2 && bytes
< 512) {
1888 retval
= lowest_latency
;
1891 case bulk_latency
: /* 250 usec aka 4000 ints/s */
1892 if (bytes
> 25000) {
1894 retval
= low_latency
;
1896 } else if (bytes
< 6000) {
1897 retval
= low_latency
;
1906 static void e1000_set_itr(struct e1000_adapter
*adapter
)
1908 struct e1000_hw
*hw
= &adapter
->hw
;
1910 u32 new_itr
= adapter
->itr
;
1912 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1913 if (adapter
->link_speed
!= SPEED_1000
) {
1919 adapter
->tx_itr
= e1000_update_itr(adapter
,
1921 adapter
->total_tx_packets
,
1922 adapter
->total_tx_bytes
);
1923 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1924 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
1925 adapter
->tx_itr
= low_latency
;
1927 adapter
->rx_itr
= e1000_update_itr(adapter
,
1929 adapter
->total_rx_packets
,
1930 adapter
->total_rx_bytes
);
1931 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1932 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
1933 adapter
->rx_itr
= low_latency
;
1935 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
1937 switch (current_itr
) {
1938 /* counts and packets in update_itr are dependent on these numbers */
1939 case lowest_latency
:
1943 new_itr
= 20000; /* aka hwitr = ~200 */
1953 if (new_itr
!= adapter
->itr
) {
1955 * this attempts to bias the interrupt rate towards Bulk
1956 * by adding intermediate steps when interrupt rate is
1959 new_itr
= new_itr
> adapter
->itr
?
1960 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
1962 adapter
->itr
= new_itr
;
1963 adapter
->rx_ring
->itr_val
= new_itr
;
1964 if (adapter
->msix_entries
)
1965 adapter
->rx_ring
->set_itr
= 1;
1967 ew32(ITR
, 1000000000 / (new_itr
* 256));
1972 * e1000_alloc_queues - Allocate memory for all rings
1973 * @adapter: board private structure to initialize
1975 static int __devinit
e1000_alloc_queues(struct e1000_adapter
*adapter
)
1977 adapter
->tx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
1978 if (!adapter
->tx_ring
)
1981 adapter
->rx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
1982 if (!adapter
->rx_ring
)
1987 e_err("Unable to allocate memory for queues\n");
1988 kfree(adapter
->rx_ring
);
1989 kfree(adapter
->tx_ring
);
1994 * e1000_clean - NAPI Rx polling callback
1995 * @napi: struct associated with this polling callback
1996 * @budget: amount of packets driver is allowed to process this poll
1998 static int e1000_clean(struct napi_struct
*napi
, int budget
)
2000 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
, napi
);
2001 struct e1000_hw
*hw
= &adapter
->hw
;
2002 struct net_device
*poll_dev
= adapter
->netdev
;
2003 int tx_cleaned
= 0, work_done
= 0;
2005 adapter
= netdev_priv(poll_dev
);
2007 if (adapter
->msix_entries
&&
2008 !(adapter
->rx_ring
->ims_val
& adapter
->tx_ring
->ims_val
))
2012 * e1000_clean is called per-cpu. This lock protects
2013 * tx_ring from being cleaned by multiple cpus
2014 * simultaneously. A failure obtaining the lock means
2015 * tx_ring is currently being cleaned anyway.
2017 if (spin_trylock(&adapter
->tx_queue_lock
)) {
2018 tx_cleaned
= e1000_clean_tx_irq(adapter
);
2019 spin_unlock(&adapter
->tx_queue_lock
);
2023 adapter
->clean_rx(adapter
, &work_done
, budget
);
2028 /* If budget not fully consumed, exit the polling mode */
2029 if (work_done
< budget
) {
2030 if (adapter
->itr_setting
& 3)
2031 e1000_set_itr(adapter
);
2032 netif_rx_complete(poll_dev
, napi
);
2033 if (adapter
->msix_entries
)
2034 ew32(IMS
, adapter
->rx_ring
->ims_val
);
2036 e1000_irq_enable(adapter
);
2042 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
2044 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2045 struct e1000_hw
*hw
= &adapter
->hw
;
2048 /* don't update vlan cookie if already programmed */
2049 if ((adapter
->hw
.mng_cookie
.status
&
2050 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
2051 (vid
== adapter
->mng_vlan_id
))
2053 /* add VID to filter table */
2054 index
= (vid
>> 5) & 0x7F;
2055 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
2056 vfta
|= (1 << (vid
& 0x1F));
2057 e1000e_write_vfta(hw
, index
, vfta
);
2060 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
2062 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2063 struct e1000_hw
*hw
= &adapter
->hw
;
2066 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2067 e1000_irq_disable(adapter
);
2068 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
2070 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2071 e1000_irq_enable(adapter
);
2073 if ((adapter
->hw
.mng_cookie
.status
&
2074 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
2075 (vid
== adapter
->mng_vlan_id
)) {
2076 /* release control to f/w */
2077 e1000_release_hw_control(adapter
);
2081 /* remove VID from filter table */
2082 index
= (vid
>> 5) & 0x7F;
2083 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
2084 vfta
&= ~(1 << (vid
& 0x1F));
2085 e1000e_write_vfta(hw
, index
, vfta
);
2088 static void e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
2090 struct net_device
*netdev
= adapter
->netdev
;
2091 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
2092 u16 old_vid
= adapter
->mng_vlan_id
;
2094 if (!adapter
->vlgrp
)
2097 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
2098 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
2099 if (adapter
->hw
.mng_cookie
.status
&
2100 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) {
2101 e1000_vlan_rx_add_vid(netdev
, vid
);
2102 adapter
->mng_vlan_id
= vid
;
2105 if ((old_vid
!= (u16
)E1000_MNG_VLAN_NONE
) &&
2107 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
2108 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
2110 adapter
->mng_vlan_id
= vid
;
2115 static void e1000_vlan_rx_register(struct net_device
*netdev
,
2116 struct vlan_group
*grp
)
2118 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2119 struct e1000_hw
*hw
= &adapter
->hw
;
2122 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2123 e1000_irq_disable(adapter
);
2124 adapter
->vlgrp
= grp
;
2127 /* enable VLAN tag insert/strip */
2129 ctrl
|= E1000_CTRL_VME
;
2132 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2133 /* enable VLAN receive filtering */
2135 rctl
&= ~E1000_RCTL_CFIEN
;
2137 e1000_update_mng_vlan(adapter
);
2140 /* disable VLAN tag insert/strip */
2142 ctrl
&= ~E1000_CTRL_VME
;
2145 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
2146 if (adapter
->mng_vlan_id
!=
2147 (u16
)E1000_MNG_VLAN_NONE
) {
2148 e1000_vlan_rx_kill_vid(netdev
,
2149 adapter
->mng_vlan_id
);
2150 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
2155 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2156 e1000_irq_enable(adapter
);
2159 static void e1000_restore_vlan(struct e1000_adapter
*adapter
)
2163 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
2165 if (!adapter
->vlgrp
)
2168 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
2169 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
2171 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
2175 static void e1000_init_manageability(struct e1000_adapter
*adapter
)
2177 struct e1000_hw
*hw
= &adapter
->hw
;
2180 if (!(adapter
->flags
& FLAG_MNG_PT_ENABLED
))
2186 * enable receiving management packets to the host. this will probably
2187 * generate destination unreachable messages from the host OS, but
2188 * the packets will be handled on SMBUS
2190 manc
|= E1000_MANC_EN_MNG2HOST
;
2191 manc2h
= er32(MANC2H
);
2192 #define E1000_MNG2HOST_PORT_623 (1 << 5)
2193 #define E1000_MNG2HOST_PORT_664 (1 << 6)
2194 manc2h
|= E1000_MNG2HOST_PORT_623
;
2195 manc2h
|= E1000_MNG2HOST_PORT_664
;
2196 ew32(MANC2H
, manc2h
);
2201 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2202 * @adapter: board private structure
2204 * Configure the Tx unit of the MAC after a reset.
2206 static void e1000_configure_tx(struct e1000_adapter
*adapter
)
2208 struct e1000_hw
*hw
= &adapter
->hw
;
2209 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2211 u32 tdlen
, tctl
, tipg
, tarc
;
2214 /* Setup the HW Tx Head and Tail descriptor pointers */
2215 tdba
= tx_ring
->dma
;
2216 tdlen
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
2217 ew32(TDBAL
, (tdba
& DMA_32BIT_MASK
));
2218 ew32(TDBAH
, (tdba
>> 32));
2222 tx_ring
->head
= E1000_TDH
;
2223 tx_ring
->tail
= E1000_TDT
;
2225 /* Set the default values for the Tx Inter Packet Gap timer */
2226 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
; /* 8 */
2227 ipgr1
= DEFAULT_82543_TIPG_IPGR1
; /* 8 */
2228 ipgr2
= DEFAULT_82543_TIPG_IPGR2
; /* 6 */
2230 if (adapter
->flags
& FLAG_TIPG_MEDIUM_FOR_80003ESLAN
)
2231 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
; /* 7 */
2233 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
2234 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
2237 /* Set the Tx Interrupt Delay register */
2238 ew32(TIDV
, adapter
->tx_int_delay
);
2239 /* Tx irq moderation */
2240 ew32(TADV
, adapter
->tx_abs_int_delay
);
2242 /* Program the Transmit Control Register */
2244 tctl
&= ~E1000_TCTL_CT
;
2245 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
2246 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
2248 if (adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) {
2249 tarc
= er32(TARC(0));
2251 * set the speed mode bit, we'll clear it if we're not at
2252 * gigabit link later
2254 #define SPEED_MODE_BIT (1 << 21)
2255 tarc
|= SPEED_MODE_BIT
;
2256 ew32(TARC(0), tarc
);
2259 /* errata: program both queues to unweighted RR */
2260 if (adapter
->flags
& FLAG_TARC_SET_BIT_ZERO
) {
2261 tarc
= er32(TARC(0));
2263 ew32(TARC(0), tarc
);
2264 tarc
= er32(TARC(1));
2266 ew32(TARC(1), tarc
);
2269 e1000e_config_collision_dist(hw
);
2271 /* Setup Transmit Descriptor Settings for eop descriptor */
2272 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
2274 /* only set IDE if we are delaying interrupts using the timers */
2275 if (adapter
->tx_int_delay
)
2276 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
2278 /* enable Report Status bit */
2279 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
2283 adapter
->tx_queue_len
= adapter
->netdev
->tx_queue_len
;
2287 * e1000_setup_rctl - configure the receive control registers
2288 * @adapter: Board private structure
2290 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2291 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2292 static void e1000_setup_rctl(struct e1000_adapter
*adapter
)
2294 struct e1000_hw
*hw
= &adapter
->hw
;
2299 /* Program MC offset vector base */
2301 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
2302 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
2303 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
2304 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
2306 /* Do not Store bad packets */
2307 rctl
&= ~E1000_RCTL_SBP
;
2309 /* Enable Long Packet receive */
2310 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
2311 rctl
&= ~E1000_RCTL_LPE
;
2313 rctl
|= E1000_RCTL_LPE
;
2315 /* Some systems expect that the CRC is included in SMBUS traffic. The
2316 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2317 * host memory when this is enabled
2319 if (adapter
->flags2
& FLAG2_CRC_STRIPPING
)
2320 rctl
|= E1000_RCTL_SECRC
;
2322 /* Setup buffer sizes */
2323 rctl
&= ~E1000_RCTL_SZ_4096
;
2324 rctl
|= E1000_RCTL_BSEX
;
2325 switch (adapter
->rx_buffer_len
) {
2327 rctl
|= E1000_RCTL_SZ_256
;
2328 rctl
&= ~E1000_RCTL_BSEX
;
2331 rctl
|= E1000_RCTL_SZ_512
;
2332 rctl
&= ~E1000_RCTL_BSEX
;
2335 rctl
|= E1000_RCTL_SZ_1024
;
2336 rctl
&= ~E1000_RCTL_BSEX
;
2340 rctl
|= E1000_RCTL_SZ_2048
;
2341 rctl
&= ~E1000_RCTL_BSEX
;
2344 rctl
|= E1000_RCTL_SZ_4096
;
2347 rctl
|= E1000_RCTL_SZ_8192
;
2350 rctl
|= E1000_RCTL_SZ_16384
;
2355 * 82571 and greater support packet-split where the protocol
2356 * header is placed in skb->data and the packet data is
2357 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2358 * In the case of a non-split, skb->data is linearly filled,
2359 * followed by the page buffers. Therefore, skb->data is
2360 * sized to hold the largest protocol header.
2362 * allocations using alloc_page take too long for regular MTU
2363 * so only enable packet split for jumbo frames
2365 * Using pages when the page size is greater than 16k wastes
2366 * a lot of memory, since we allocate 3 pages at all times
2369 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
2370 if (!(adapter
->flags
& FLAG_IS_ICH
) && (pages
<= 3) &&
2371 (PAGE_SIZE
<= 16384) && (rctl
& E1000_RCTL_LPE
))
2372 adapter
->rx_ps_pages
= pages
;
2374 adapter
->rx_ps_pages
= 0;
2376 if (adapter
->rx_ps_pages
) {
2377 /* Configure extra packet-split registers */
2378 rfctl
= er32(RFCTL
);
2379 rfctl
|= E1000_RFCTL_EXTEN
;
2381 * disable packet split support for IPv6 extension headers,
2382 * because some malformed IPv6 headers can hang the Rx
2384 rfctl
|= (E1000_RFCTL_IPV6_EX_DIS
|
2385 E1000_RFCTL_NEW_IPV6_EXT_DIS
);
2389 /* Enable Packet split descriptors */
2390 rctl
|= E1000_RCTL_DTYP_PS
;
2392 psrctl
|= adapter
->rx_ps_bsize0
>>
2393 E1000_PSRCTL_BSIZE0_SHIFT
;
2395 switch (adapter
->rx_ps_pages
) {
2397 psrctl
|= PAGE_SIZE
<<
2398 E1000_PSRCTL_BSIZE3_SHIFT
;
2400 psrctl
|= PAGE_SIZE
<<
2401 E1000_PSRCTL_BSIZE2_SHIFT
;
2403 psrctl
|= PAGE_SIZE
>>
2404 E1000_PSRCTL_BSIZE1_SHIFT
;
2408 ew32(PSRCTL
, psrctl
);
2412 /* just started the receive unit, no need to restart */
2413 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
2417 * e1000_configure_rx - Configure Receive Unit after Reset
2418 * @adapter: board private structure
2420 * Configure the Rx unit of the MAC after a reset.
2422 static void e1000_configure_rx(struct e1000_adapter
*adapter
)
2424 struct e1000_hw
*hw
= &adapter
->hw
;
2425 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
2427 u32 rdlen
, rctl
, rxcsum
, ctrl_ext
;
2429 if (adapter
->rx_ps_pages
) {
2430 /* this is a 32 byte descriptor */
2431 rdlen
= rx_ring
->count
*
2432 sizeof(union e1000_rx_desc_packet_split
);
2433 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
2434 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
2435 } else if (adapter
->netdev
->mtu
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
2436 rdlen
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
2437 adapter
->clean_rx
= e1000_clean_jumbo_rx_irq
;
2438 adapter
->alloc_rx_buf
= e1000_alloc_jumbo_rx_buffers
;
2440 rdlen
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
2441 adapter
->clean_rx
= e1000_clean_rx_irq
;
2442 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
2445 /* disable receives while setting up the descriptors */
2447 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
2451 /* set the Receive Delay Timer Register */
2452 ew32(RDTR
, adapter
->rx_int_delay
);
2454 /* irq moderation */
2455 ew32(RADV
, adapter
->rx_abs_int_delay
);
2456 if (adapter
->itr_setting
!= 0)
2457 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
2459 ctrl_ext
= er32(CTRL_EXT
);
2460 /* Reset delay timers after every interrupt */
2461 ctrl_ext
|= E1000_CTRL_EXT_INT_TIMER_CLR
;
2462 /* Auto-Mask interrupts upon ICR access */
2463 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
2464 ew32(IAM
, 0xffffffff);
2465 ew32(CTRL_EXT
, ctrl_ext
);
2469 * Setup the HW Rx Head and Tail Descriptor Pointers and
2470 * the Base and Length of the Rx Descriptor Ring
2472 rdba
= rx_ring
->dma
;
2473 ew32(RDBAL
, (rdba
& DMA_32BIT_MASK
));
2474 ew32(RDBAH
, (rdba
>> 32));
2478 rx_ring
->head
= E1000_RDH
;
2479 rx_ring
->tail
= E1000_RDT
;
2481 /* Enable Receive Checksum Offload for TCP and UDP */
2482 rxcsum
= er32(RXCSUM
);
2483 if (adapter
->flags
& FLAG_RX_CSUM_ENABLED
) {
2484 rxcsum
|= E1000_RXCSUM_TUOFL
;
2487 * IPv4 payload checksum for UDP fragments must be
2488 * used in conjunction with packet-split.
2490 if (adapter
->rx_ps_pages
)
2491 rxcsum
|= E1000_RXCSUM_IPPCSE
;
2493 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
2494 /* no need to clear IPPCSE as it defaults to 0 */
2496 ew32(RXCSUM
, rxcsum
);
2499 * Enable early receives on supported devices, only takes effect when
2500 * packet size is equal or larger than the specified value (in 8 byte
2501 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2503 if ((adapter
->flags
& FLAG_HAS_ERT
) &&
2504 (adapter
->netdev
->mtu
> ETH_DATA_LEN
)) {
2505 u32 rxdctl
= er32(RXDCTL(0));
2506 ew32(RXDCTL(0), rxdctl
| 0x3);
2507 ew32(ERT
, E1000_ERT_2048
| (1 << 13));
2509 * With jumbo frames and early-receive enabled, excessive
2510 * C4->C2 latencies result in dropped transactions.
2512 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY
,
2513 e1000e_driver_name
, 55);
2515 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY
,
2517 PM_QOS_DEFAULT_VALUE
);
2520 /* Enable Receives */
2525 * e1000_update_mc_addr_list - Update Multicast addresses
2526 * @hw: pointer to the HW structure
2527 * @mc_addr_list: array of multicast addresses to program
2528 * @mc_addr_count: number of multicast addresses to program
2529 * @rar_used_count: the first RAR register free to program
2530 * @rar_count: total number of supported Receive Address Registers
2532 * Updates the Receive Address Registers and Multicast Table Array.
2533 * The caller must have a packed mc_addr_list of multicast addresses.
2534 * The parameter rar_count will usually be hw->mac.rar_entry_count
2535 * unless there are workarounds that change this. Currently no func pointer
2536 * exists and all implementations are handled in the generic version of this
2539 static void e1000_update_mc_addr_list(struct e1000_hw
*hw
, u8
*mc_addr_list
,
2540 u32 mc_addr_count
, u32 rar_used_count
,
2543 hw
->mac
.ops
.update_mc_addr_list(hw
, mc_addr_list
, mc_addr_count
,
2544 rar_used_count
, rar_count
);
2548 * e1000_set_multi - Multicast and Promiscuous mode set
2549 * @netdev: network interface device structure
2551 * The set_multi entry point is called whenever the multicast address
2552 * list or the network interface flags are updated. This routine is
2553 * responsible for configuring the hardware for proper multicast,
2554 * promiscuous mode, and all-multi behavior.
2556 static void e1000_set_multi(struct net_device
*netdev
)
2558 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2559 struct e1000_hw
*hw
= &adapter
->hw
;
2560 struct e1000_mac_info
*mac
= &hw
->mac
;
2561 struct dev_mc_list
*mc_ptr
;
2566 /* Check for Promiscuous and All Multicast modes */
2570 if (netdev
->flags
& IFF_PROMISC
) {
2571 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2572 rctl
&= ~E1000_RCTL_VFE
;
2574 if (netdev
->flags
& IFF_ALLMULTI
) {
2575 rctl
|= E1000_RCTL_MPE
;
2576 rctl
&= ~E1000_RCTL_UPE
;
2578 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2580 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
)
2581 rctl
|= E1000_RCTL_VFE
;
2586 if (netdev
->mc_count
) {
2587 mta_list
= kmalloc(netdev
->mc_count
* 6, GFP_ATOMIC
);
2591 /* prepare a packed array of only addresses. */
2592 mc_ptr
= netdev
->mc_list
;
2594 for (i
= 0; i
< netdev
->mc_count
; i
++) {
2597 memcpy(mta_list
+ (i
*ETH_ALEN
), mc_ptr
->dmi_addr
,
2599 mc_ptr
= mc_ptr
->next
;
2602 e1000_update_mc_addr_list(hw
, mta_list
, i
, 1,
2603 mac
->rar_entry_count
);
2607 * if we're called from probe, we might not have
2608 * anything to do here, so clear out the list
2610 e1000_update_mc_addr_list(hw
, NULL
, 0, 1, mac
->rar_entry_count
);
2615 * e1000_configure - configure the hardware for Rx and Tx
2616 * @adapter: private board structure
2618 static void e1000_configure(struct e1000_adapter
*adapter
)
2620 e1000_set_multi(adapter
->netdev
);
2622 e1000_restore_vlan(adapter
);
2623 e1000_init_manageability(adapter
);
2625 e1000_configure_tx(adapter
);
2626 e1000_setup_rctl(adapter
);
2627 e1000_configure_rx(adapter
);
2628 adapter
->alloc_rx_buf(adapter
, e1000_desc_unused(adapter
->rx_ring
));
2632 * e1000e_power_up_phy - restore link in case the phy was powered down
2633 * @adapter: address of board private structure
2635 * The phy may be powered down to save power and turn off link when the
2636 * driver is unloaded and wake on lan is not enabled (among others)
2637 * *** this routine MUST be followed by a call to e1000e_reset ***
2639 void e1000e_power_up_phy(struct e1000_adapter
*adapter
)
2643 /* Just clear the power down bit to wake the phy back up */
2644 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
) {
2646 * According to the manual, the phy will retain its
2647 * settings across a power-down/up cycle
2649 e1e_rphy(&adapter
->hw
, PHY_CONTROL
, &mii_reg
);
2650 mii_reg
&= ~MII_CR_POWER_DOWN
;
2651 e1e_wphy(&adapter
->hw
, PHY_CONTROL
, mii_reg
);
2654 adapter
->hw
.mac
.ops
.setup_link(&adapter
->hw
);
2658 * e1000_power_down_phy - Power down the PHY
2660 * Power down the PHY so no link is implied when interface is down
2661 * The PHY cannot be powered down is management or WoL is active
2663 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
2665 struct e1000_hw
*hw
= &adapter
->hw
;
2668 /* WoL is enabled */
2672 /* non-copper PHY? */
2673 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
2676 /* reset is blocked because of a SoL/IDER session */
2677 if (e1000e_check_mng_mode(hw
) || e1000_check_reset_block(hw
))
2680 /* manageability (AMT) is enabled */
2681 if (er32(MANC
) & E1000_MANC_SMBUS_EN
)
2684 /* power down the PHY */
2685 e1e_rphy(hw
, PHY_CONTROL
, &mii_reg
);
2686 mii_reg
|= MII_CR_POWER_DOWN
;
2687 e1e_wphy(hw
, PHY_CONTROL
, mii_reg
);
2692 * e1000e_reset - bring the hardware into a known good state
2694 * This function boots the hardware and enables some settings that
2695 * require a configuration cycle of the hardware - those cannot be
2696 * set/changed during runtime. After reset the device needs to be
2697 * properly configured for Rx, Tx etc.
2699 void e1000e_reset(struct e1000_adapter
*adapter
)
2701 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
2702 struct e1000_fc_info
*fc
= &adapter
->hw
.fc
;
2703 struct e1000_hw
*hw
= &adapter
->hw
;
2704 u32 tx_space
, min_tx_space
, min_rx_space
;
2705 u32 pba
= adapter
->pba
;
2708 /* reset Packet Buffer Allocation to default */
2711 if (adapter
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
2713 * To maintain wire speed transmits, the Tx FIFO should be
2714 * large enough to accommodate two full transmit packets,
2715 * rounded up to the next 1KB and expressed in KB. Likewise,
2716 * the Rx FIFO should be large enough to accommodate at least
2717 * one full receive packet and is similarly rounded up and
2721 /* upper 16 bits has Tx packet buffer allocation size in KB */
2722 tx_space
= pba
>> 16;
2723 /* lower 16 bits has Rx packet buffer allocation size in KB */
2726 * the Tx fifo also stores 16 bytes of information about the tx
2727 * but don't include ethernet FCS because hardware appends it
2729 min_tx_space
= (adapter
->max_frame_size
+
2730 sizeof(struct e1000_tx_desc
) -
2732 min_tx_space
= ALIGN(min_tx_space
, 1024);
2733 min_tx_space
>>= 10;
2734 /* software strips receive CRC, so leave room for it */
2735 min_rx_space
= adapter
->max_frame_size
;
2736 min_rx_space
= ALIGN(min_rx_space
, 1024);
2737 min_rx_space
>>= 10;
2740 * If current Tx allocation is less than the min Tx FIFO size,
2741 * and the min Tx FIFO size is less than the current Rx FIFO
2742 * allocation, take space away from current Rx allocation
2744 if ((tx_space
< min_tx_space
) &&
2745 ((min_tx_space
- tx_space
) < pba
)) {
2746 pba
-= min_tx_space
- tx_space
;
2749 * if short on Rx space, Rx wins and must trump tx
2750 * adjustment or use Early Receive if available
2752 if ((pba
< min_rx_space
) &&
2753 (!(adapter
->flags
& FLAG_HAS_ERT
)))
2754 /* ERT enabled in e1000_configure_rx */
2763 * flow control settings
2765 * The high water mark must be low enough to fit one full frame
2766 * (or the size used for early receive) above it in the Rx FIFO.
2767 * Set it to the lower of:
2768 * - 90% of the Rx FIFO size, and
2769 * - the full Rx FIFO size minus the early receive size (for parts
2770 * with ERT support assuming ERT set to E1000_ERT_2048), or
2771 * - the full Rx FIFO size minus one full frame
2773 if (adapter
->flags
& FLAG_HAS_ERT
)
2774 hwm
= min(((pba
<< 10) * 9 / 10),
2775 ((pba
<< 10) - (E1000_ERT_2048
<< 3)));
2777 hwm
= min(((pba
<< 10) * 9 / 10),
2778 ((pba
<< 10) - adapter
->max_frame_size
));
2780 fc
->high_water
= hwm
& 0xFFF8; /* 8-byte granularity */
2781 fc
->low_water
= fc
->high_water
- 8;
2783 if (adapter
->flags
& FLAG_DISABLE_FC_PAUSE_TIME
)
2784 fc
->pause_time
= 0xFFFF;
2786 fc
->pause_time
= E1000_FC_PAUSE_TIME
;
2788 fc
->type
= fc
->original_type
;
2790 /* Allow time for pending master requests to run */
2791 mac
->ops
.reset_hw(hw
);
2794 * For parts with AMT enabled, let the firmware know
2795 * that the network interface is in control
2797 if (adapter
->flags
& FLAG_HAS_AMT
)
2798 e1000_get_hw_control(adapter
);
2802 if (mac
->ops
.init_hw(hw
))
2803 e_err("Hardware Error\n");
2805 e1000_update_mng_vlan(adapter
);
2807 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2808 ew32(VET
, ETH_P_8021Q
);
2810 e1000e_reset_adaptive(hw
);
2811 e1000_get_phy_info(hw
);
2813 if (!(adapter
->flags
& FLAG_SMART_POWER_DOWN
)) {
2816 * speed up time to link by disabling smart power down, ignore
2817 * the return value of this function because there is nothing
2818 * different we would do if it failed
2820 e1e_rphy(hw
, IGP02E1000_PHY_POWER_MGMT
, &phy_data
);
2821 phy_data
&= ~IGP02E1000_PM_SPD
;
2822 e1e_wphy(hw
, IGP02E1000_PHY_POWER_MGMT
, phy_data
);
2826 int e1000e_up(struct e1000_adapter
*adapter
)
2828 struct e1000_hw
*hw
= &adapter
->hw
;
2830 /* hardware has been reset, we need to reload some things */
2831 e1000_configure(adapter
);
2833 clear_bit(__E1000_DOWN
, &adapter
->state
);
2835 napi_enable(&adapter
->napi
);
2836 if (adapter
->msix_entries
)
2837 e1000_configure_msix(adapter
);
2838 e1000_irq_enable(adapter
);
2840 /* fire a link change interrupt to start the watchdog */
2841 ew32(ICS
, E1000_ICS_LSC
);
2845 void e1000e_down(struct e1000_adapter
*adapter
)
2847 struct net_device
*netdev
= adapter
->netdev
;
2848 struct e1000_hw
*hw
= &adapter
->hw
;
2852 * signal that we're down so the interrupt handler does not
2853 * reschedule our watchdog timer
2855 set_bit(__E1000_DOWN
, &adapter
->state
);
2857 /* disable receives in the hardware */
2859 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
2860 /* flush and sleep below */
2862 netif_tx_stop_all_queues(netdev
);
2864 /* disable transmits in the hardware */
2866 tctl
&= ~E1000_TCTL_EN
;
2868 /* flush both disables and wait for them to finish */
2872 napi_disable(&adapter
->napi
);
2873 e1000_irq_disable(adapter
);
2875 del_timer_sync(&adapter
->watchdog_timer
);
2876 del_timer_sync(&adapter
->phy_info_timer
);
2878 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2879 netif_carrier_off(netdev
);
2880 adapter
->link_speed
= 0;
2881 adapter
->link_duplex
= 0;
2883 if (!pci_channel_offline(adapter
->pdev
))
2884 e1000e_reset(adapter
);
2885 e1000_clean_tx_ring(adapter
);
2886 e1000_clean_rx_ring(adapter
);
2889 * TODO: for power management, we could drop the link and
2890 * pci_disable_device here.
2894 void e1000e_reinit_locked(struct e1000_adapter
*adapter
)
2897 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
2899 e1000e_down(adapter
);
2901 clear_bit(__E1000_RESETTING
, &adapter
->state
);
2905 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2906 * @adapter: board private structure to initialize
2908 * e1000_sw_init initializes the Adapter private data structure.
2909 * Fields are initialized based on PCI device information and
2910 * OS network device settings (MTU size).
2912 static int __devinit
e1000_sw_init(struct e1000_adapter
*adapter
)
2914 struct net_device
*netdev
= adapter
->netdev
;
2916 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
;
2917 adapter
->rx_ps_bsize0
= 128;
2918 adapter
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2919 adapter
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
2921 e1000e_set_interrupt_capability(adapter
);
2923 if (e1000_alloc_queues(adapter
))
2926 spin_lock_init(&adapter
->tx_queue_lock
);
2928 /* Explicitly disable IRQ since the NIC can be in any state. */
2929 e1000_irq_disable(adapter
);
2931 set_bit(__E1000_DOWN
, &adapter
->state
);
2936 * e1000_intr_msi_test - Interrupt Handler
2937 * @irq: interrupt number
2938 * @data: pointer to a network interface device structure
2940 static irqreturn_t
e1000_intr_msi_test(int irq
, void *data
)
2942 struct net_device
*netdev
= data
;
2943 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2944 struct e1000_hw
*hw
= &adapter
->hw
;
2945 u32 icr
= er32(ICR
);
2947 e_dbg("%s: icr is %08X\n", netdev
->name
, icr
);
2948 if (icr
& E1000_ICR_RXSEQ
) {
2949 adapter
->flags
&= ~FLAG_MSI_TEST_FAILED
;
2957 * e1000_test_msi_interrupt - Returns 0 for successful test
2958 * @adapter: board private struct
2960 * code flow taken from tg3.c
2962 static int e1000_test_msi_interrupt(struct e1000_adapter
*adapter
)
2964 struct net_device
*netdev
= adapter
->netdev
;
2965 struct e1000_hw
*hw
= &adapter
->hw
;
2968 /* poll_enable hasn't been called yet, so don't need disable */
2969 /* clear any pending events */
2972 /* free the real vector and request a test handler */
2973 e1000_free_irq(adapter
);
2974 e1000e_reset_interrupt_capability(adapter
);
2976 /* Assume that the test fails, if it succeeds then the test
2977 * MSI irq handler will unset this flag */
2978 adapter
->flags
|= FLAG_MSI_TEST_FAILED
;
2980 err
= pci_enable_msi(adapter
->pdev
);
2982 goto msi_test_failed
;
2984 err
= request_irq(adapter
->pdev
->irq
, &e1000_intr_msi_test
, 0,
2985 netdev
->name
, netdev
);
2987 pci_disable_msi(adapter
->pdev
);
2988 goto msi_test_failed
;
2993 e1000_irq_enable(adapter
);
2995 /* fire an unusual interrupt on the test handler */
2996 ew32(ICS
, E1000_ICS_RXSEQ
);
3000 e1000_irq_disable(adapter
);
3004 if (adapter
->flags
& FLAG_MSI_TEST_FAILED
) {
3005 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
3007 e_info("MSI interrupt test failed!\n");
3010 free_irq(adapter
->pdev
->irq
, netdev
);
3011 pci_disable_msi(adapter
->pdev
);
3014 goto msi_test_failed
;
3016 /* okay so the test worked, restore settings */
3017 e_dbg("%s: MSI interrupt test succeeded!\n", netdev
->name
);
3019 e1000e_set_interrupt_capability(adapter
);
3020 e1000_request_irq(adapter
);
3025 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3026 * @adapter: board private struct
3028 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3030 static int e1000_test_msi(struct e1000_adapter
*adapter
)
3035 if (!(adapter
->flags
& FLAG_MSI_ENABLED
))
3038 /* disable SERR in case the MSI write causes a master abort */
3039 pci_read_config_word(adapter
->pdev
, PCI_COMMAND
, &pci_cmd
);
3040 pci_write_config_word(adapter
->pdev
, PCI_COMMAND
,
3041 pci_cmd
& ~PCI_COMMAND_SERR
);
3043 err
= e1000_test_msi_interrupt(adapter
);
3045 /* restore previous setting of command word */
3046 pci_write_config_word(adapter
->pdev
, PCI_COMMAND
, pci_cmd
);
3052 /* EIO means MSI test failed */
3056 /* back to INTx mode */
3057 e_warn("MSI interrupt test failed, using legacy interrupt.\n");
3059 e1000_free_irq(adapter
);
3061 err
= e1000_request_irq(adapter
);
3067 * e1000_open - Called when a network interface is made active
3068 * @netdev: network interface device structure
3070 * Returns 0 on success, negative value on failure
3072 * The open entry point is called when a network interface is made
3073 * active by the system (IFF_UP). At this point all resources needed
3074 * for transmit and receive operations are allocated, the interrupt
3075 * handler is registered with the OS, the watchdog timer is started,
3076 * and the stack is notified that the interface is ready.
3078 static int e1000_open(struct net_device
*netdev
)
3080 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3081 struct e1000_hw
*hw
= &adapter
->hw
;
3084 /* disallow open during test */
3085 if (test_bit(__E1000_TESTING
, &adapter
->state
))
3088 /* allocate transmit descriptors */
3089 err
= e1000e_setup_tx_resources(adapter
);
3093 /* allocate receive descriptors */
3094 err
= e1000e_setup_rx_resources(adapter
);
3098 e1000e_power_up_phy(adapter
);
3100 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
3101 if ((adapter
->hw
.mng_cookie
.status
&
3102 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
))
3103 e1000_update_mng_vlan(adapter
);
3106 * If AMT is enabled, let the firmware know that the network
3107 * interface is now open
3109 if (adapter
->flags
& FLAG_HAS_AMT
)
3110 e1000_get_hw_control(adapter
);
3113 * before we allocate an interrupt, we must be ready to handle it.
3114 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3115 * as soon as we call pci_request_irq, so we have to setup our
3116 * clean_rx handler before we do so.
3118 e1000_configure(adapter
);
3120 err
= e1000_request_irq(adapter
);
3125 * Work around PCIe errata with MSI interrupts causing some chipsets to
3126 * ignore e1000e MSI messages, which means we need to test our MSI
3129 if (adapter
->int_mode
!= E1000E_INT_MODE_LEGACY
) {
3130 err
= e1000_test_msi(adapter
);
3132 e_err("Interrupt allocation failed\n");
3137 /* From here on the code is the same as e1000e_up() */
3138 clear_bit(__E1000_DOWN
, &adapter
->state
);
3140 napi_enable(&adapter
->napi
);
3142 e1000_irq_enable(adapter
);
3144 netif_tx_start_all_queues(netdev
);
3146 /* fire a link status change interrupt to start the watchdog */
3147 ew32(ICS
, E1000_ICS_LSC
);
3152 e1000_release_hw_control(adapter
);
3153 e1000_power_down_phy(adapter
);
3154 e1000e_free_rx_resources(adapter
);
3156 e1000e_free_tx_resources(adapter
);
3158 e1000e_reset(adapter
);
3164 * e1000_close - Disables a network interface
3165 * @netdev: network interface device structure
3167 * Returns 0, this is not allowed to fail
3169 * The close entry point is called when an interface is de-activated
3170 * by the OS. The hardware is still under the drivers control, but
3171 * needs to be disabled. A global MAC reset is issued to stop the
3172 * hardware, and all transmit and receive resources are freed.
3174 static int e1000_close(struct net_device
*netdev
)
3176 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3178 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
3179 e1000e_down(adapter
);
3180 e1000_power_down_phy(adapter
);
3181 e1000_free_irq(adapter
);
3183 e1000e_free_tx_resources(adapter
);
3184 e1000e_free_rx_resources(adapter
);
3187 * kill manageability vlan ID if supported, but not if a vlan with
3188 * the same ID is registered on the host OS (let 8021q kill it)
3190 if ((adapter
->hw
.mng_cookie
.status
&
3191 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
3193 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
)))
3194 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
3197 * If AMT is enabled, let the firmware know that the network
3198 * interface is now closed
3200 if (adapter
->flags
& FLAG_HAS_AMT
)
3201 e1000_release_hw_control(adapter
);
3206 * e1000_set_mac - Change the Ethernet Address of the NIC
3207 * @netdev: network interface device structure
3208 * @p: pointer to an address structure
3210 * Returns 0 on success, negative on failure
3212 static int e1000_set_mac(struct net_device
*netdev
, void *p
)
3214 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3215 struct sockaddr
*addr
= p
;
3217 if (!is_valid_ether_addr(addr
->sa_data
))
3218 return -EADDRNOTAVAIL
;
3220 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
3221 memcpy(adapter
->hw
.mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
3223 e1000e_rar_set(&adapter
->hw
, adapter
->hw
.mac
.addr
, 0);
3225 if (adapter
->flags
& FLAG_RESET_OVERWRITES_LAA
) {
3226 /* activate the work around */
3227 e1000e_set_laa_state_82571(&adapter
->hw
, 1);
3230 * Hold a copy of the LAA in RAR[14] This is done so that
3231 * between the time RAR[0] gets clobbered and the time it
3232 * gets fixed (in e1000_watchdog), the actual LAA is in one
3233 * of the RARs and no incoming packets directed to this port
3234 * are dropped. Eventually the LAA will be in RAR[0] and
3237 e1000e_rar_set(&adapter
->hw
,
3238 adapter
->hw
.mac
.addr
,
3239 adapter
->hw
.mac
.rar_entry_count
- 1);
3246 * e1000e_update_phy_task - work thread to update phy
3247 * @work: pointer to our work struct
3249 * this worker thread exists because we must acquire a
3250 * semaphore to read the phy, which we could msleep while
3251 * waiting for it, and we can't msleep in a timer.
3253 static void e1000e_update_phy_task(struct work_struct
*work
)
3255 struct e1000_adapter
*adapter
= container_of(work
,
3256 struct e1000_adapter
, update_phy_task
);
3257 e1000_get_phy_info(&adapter
->hw
);
3261 * Need to wait a few seconds after link up to get diagnostic information from
3264 static void e1000_update_phy_info(unsigned long data
)
3266 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
3267 schedule_work(&adapter
->update_phy_task
);
3271 * e1000e_update_stats - Update the board statistics counters
3272 * @adapter: board private structure
3274 void e1000e_update_stats(struct e1000_adapter
*adapter
)
3276 struct e1000_hw
*hw
= &adapter
->hw
;
3277 struct pci_dev
*pdev
= adapter
->pdev
;
3280 * Prevent stats update while adapter is being reset, or if the pci
3281 * connection is down.
3283 if (adapter
->link_speed
== 0)
3285 if (pci_channel_offline(pdev
))
3288 adapter
->stats
.crcerrs
+= er32(CRCERRS
);
3289 adapter
->stats
.gprc
+= er32(GPRC
);
3290 adapter
->stats
.gorc
+= er32(GORCL
);
3291 er32(GORCH
); /* Clear gorc */
3292 adapter
->stats
.bprc
+= er32(BPRC
);
3293 adapter
->stats
.mprc
+= er32(MPRC
);
3294 adapter
->stats
.roc
+= er32(ROC
);
3296 adapter
->stats
.mpc
+= er32(MPC
);
3297 adapter
->stats
.scc
+= er32(SCC
);
3298 adapter
->stats
.ecol
+= er32(ECOL
);
3299 adapter
->stats
.mcc
+= er32(MCC
);
3300 adapter
->stats
.latecol
+= er32(LATECOL
);
3301 adapter
->stats
.dc
+= er32(DC
);
3302 adapter
->stats
.xonrxc
+= er32(XONRXC
);
3303 adapter
->stats
.xontxc
+= er32(XONTXC
);
3304 adapter
->stats
.xoffrxc
+= er32(XOFFRXC
);
3305 adapter
->stats
.xofftxc
+= er32(XOFFTXC
);
3306 adapter
->stats
.gptc
+= er32(GPTC
);
3307 adapter
->stats
.gotc
+= er32(GOTCL
);
3308 er32(GOTCH
); /* Clear gotc */
3309 adapter
->stats
.rnbc
+= er32(RNBC
);
3310 adapter
->stats
.ruc
+= er32(RUC
);
3312 adapter
->stats
.mptc
+= er32(MPTC
);
3313 adapter
->stats
.bptc
+= er32(BPTC
);
3315 /* used for adaptive IFS */
3317 hw
->mac
.tx_packet_delta
= er32(TPT
);
3318 adapter
->stats
.tpt
+= hw
->mac
.tx_packet_delta
;
3319 hw
->mac
.collision_delta
= er32(COLC
);
3320 adapter
->stats
.colc
+= hw
->mac
.collision_delta
;
3322 adapter
->stats
.algnerrc
+= er32(ALGNERRC
);
3323 adapter
->stats
.rxerrc
+= er32(RXERRC
);
3324 if (hw
->mac
.type
!= e1000_82574
)
3325 adapter
->stats
.tncrs
+= er32(TNCRS
);
3326 adapter
->stats
.cexterr
+= er32(CEXTERR
);
3327 adapter
->stats
.tsctc
+= er32(TSCTC
);
3328 adapter
->stats
.tsctfc
+= er32(TSCTFC
);
3330 /* Fill out the OS statistics structure */
3331 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3332 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3337 * RLEC on some newer hardware can be incorrect so build
3338 * our own version based on RUC and ROC
3340 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3341 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3342 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3343 adapter
->stats
.cexterr
;
3344 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.ruc
+
3346 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3347 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3348 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3351 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3352 adapter
->stats
.latecol
;
3353 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3354 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3355 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3357 /* Tx Dropped needs to be maintained elsewhere */
3359 /* Management Stats */
3360 adapter
->stats
.mgptc
+= er32(MGTPTC
);
3361 adapter
->stats
.mgprc
+= er32(MGTPRC
);
3362 adapter
->stats
.mgpdc
+= er32(MGTPDC
);
3366 * e1000_phy_read_status - Update the PHY register status snapshot
3367 * @adapter: board private structure
3369 static void e1000_phy_read_status(struct e1000_adapter
*adapter
)
3371 struct e1000_hw
*hw
= &adapter
->hw
;
3372 struct e1000_phy_regs
*phy
= &adapter
->phy_regs
;
3375 if ((er32(STATUS
) & E1000_STATUS_LU
) &&
3376 (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
)) {
3377 ret_val
= e1e_rphy(hw
, PHY_CONTROL
, &phy
->bmcr
);
3378 ret_val
|= e1e_rphy(hw
, PHY_STATUS
, &phy
->bmsr
);
3379 ret_val
|= e1e_rphy(hw
, PHY_AUTONEG_ADV
, &phy
->advertise
);
3380 ret_val
|= e1e_rphy(hw
, PHY_LP_ABILITY
, &phy
->lpa
);
3381 ret_val
|= e1e_rphy(hw
, PHY_AUTONEG_EXP
, &phy
->expansion
);
3382 ret_val
|= e1e_rphy(hw
, PHY_1000T_CTRL
, &phy
->ctrl1000
);
3383 ret_val
|= e1e_rphy(hw
, PHY_1000T_STATUS
, &phy
->stat1000
);
3384 ret_val
|= e1e_rphy(hw
, PHY_EXT_STATUS
, &phy
->estatus
);
3386 e_warn("Error reading PHY register\n");
3389 * Do not read PHY registers if link is not up
3390 * Set values to typical power-on defaults
3392 phy
->bmcr
= (BMCR_SPEED1000
| BMCR_ANENABLE
| BMCR_FULLDPLX
);
3393 phy
->bmsr
= (BMSR_100FULL
| BMSR_100HALF
| BMSR_10FULL
|
3394 BMSR_10HALF
| BMSR_ESTATEN
| BMSR_ANEGCAPABLE
|
3396 phy
->advertise
= (ADVERTISE_PAUSE_ASYM
| ADVERTISE_PAUSE_CAP
|
3397 ADVERTISE_ALL
| ADVERTISE_CSMA
);
3399 phy
->expansion
= EXPANSION_ENABLENPAGE
;
3400 phy
->ctrl1000
= ADVERTISE_1000FULL
;
3402 phy
->estatus
= (ESTATUS_1000_TFULL
| ESTATUS_1000_THALF
);
3406 static void e1000_print_link_info(struct e1000_adapter
*adapter
)
3408 struct e1000_hw
*hw
= &adapter
->hw
;
3409 u32 ctrl
= er32(CTRL
);
3411 e_info("Link is Up %d Mbps %s, Flow Control: %s\n",
3412 adapter
->link_speed
,
3413 (adapter
->link_duplex
== FULL_DUPLEX
) ?
3414 "Full Duplex" : "Half Duplex",
3415 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
& E1000_CTRL_RFCE
)) ?
3417 ((ctrl
& E1000_CTRL_RFCE
) ? "RX" :
3418 ((ctrl
& E1000_CTRL_TFCE
) ? "TX" : "None" )));
3421 static bool e1000_has_link(struct e1000_adapter
*adapter
)
3423 struct e1000_hw
*hw
= &adapter
->hw
;
3424 bool link_active
= 0;
3428 * get_link_status is set on LSC (link status) interrupt or
3429 * Rx sequence error interrupt. get_link_status will stay
3430 * false until the check_for_link establishes link
3431 * for copper adapters ONLY
3433 switch (hw
->phy
.media_type
) {
3434 case e1000_media_type_copper
:
3435 if (hw
->mac
.get_link_status
) {
3436 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
3437 link_active
= !hw
->mac
.get_link_status
;
3442 case e1000_media_type_fiber
:
3443 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
3444 link_active
= !!(er32(STATUS
) & E1000_STATUS_LU
);
3446 case e1000_media_type_internal_serdes
:
3447 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
3448 link_active
= adapter
->hw
.mac
.serdes_has_link
;
3451 case e1000_media_type_unknown
:
3455 if ((ret_val
== E1000_ERR_PHY
) && (hw
->phy
.type
== e1000_phy_igp_3
) &&
3456 (er32(CTRL
) & E1000_PHY_CTRL_GBE_DISABLE
)) {
3457 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
3458 e_info("Gigabit has been disabled, downgrading speed\n");
3464 static void e1000e_enable_receives(struct e1000_adapter
*adapter
)
3466 /* make sure the receive unit is started */
3467 if ((adapter
->flags
& FLAG_RX_NEEDS_RESTART
) &&
3468 (adapter
->flags
& FLAG_RX_RESTART_NOW
)) {
3469 struct e1000_hw
*hw
= &adapter
->hw
;
3470 u32 rctl
= er32(RCTL
);
3471 ew32(RCTL
, rctl
| E1000_RCTL_EN
);
3472 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
3477 * e1000_watchdog - Timer Call-back
3478 * @data: pointer to adapter cast into an unsigned long
3480 static void e1000_watchdog(unsigned long data
)
3482 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
3484 /* Do the rest outside of interrupt context */
3485 schedule_work(&adapter
->watchdog_task
);
3487 /* TODO: make this use queue_delayed_work() */
3490 static void e1000_watchdog_task(struct work_struct
*work
)
3492 struct e1000_adapter
*adapter
= container_of(work
,
3493 struct e1000_adapter
, watchdog_task
);
3494 struct net_device
*netdev
= adapter
->netdev
;
3495 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
3496 struct e1000_phy_info
*phy
= &adapter
->hw
.phy
;
3497 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3498 struct e1000_hw
*hw
= &adapter
->hw
;
3502 link
= e1000_has_link(adapter
);
3503 if ((netif_carrier_ok(netdev
)) && link
) {
3504 e1000e_enable_receives(adapter
);
3508 if ((e1000e_enable_tx_pkt_filtering(hw
)) &&
3509 (adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
))
3510 e1000_update_mng_vlan(adapter
);
3513 if (!netif_carrier_ok(netdev
)) {
3515 /* update snapshot of PHY registers on LSC */
3516 e1000_phy_read_status(adapter
);
3517 mac
->ops
.get_link_up_info(&adapter
->hw
,
3518 &adapter
->link_speed
,
3519 &adapter
->link_duplex
);
3520 e1000_print_link_info(adapter
);
3522 * On supported PHYs, check for duplex mismatch only
3523 * if link has autonegotiated at 10/100 half
3525 if ((hw
->phy
.type
== e1000_phy_igp_3
||
3526 hw
->phy
.type
== e1000_phy_bm
) &&
3527 (hw
->mac
.autoneg
== true) &&
3528 (adapter
->link_speed
== SPEED_10
||
3529 adapter
->link_speed
== SPEED_100
) &&
3530 (adapter
->link_duplex
== HALF_DUPLEX
)) {
3533 e1e_rphy(hw
, PHY_AUTONEG_EXP
, &autoneg_exp
);
3535 if (!(autoneg_exp
& NWAY_ER_LP_NWAY_CAPS
))
3536 e_info("Autonegotiated half duplex but"
3537 " link partner cannot autoneg. "
3538 " Try forcing full duplex if "
3539 "link gets many collisions.\n");
3543 * tweak tx_queue_len according to speed/duplex
3544 * and adjust the timeout factor
3546 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
3547 adapter
->tx_timeout_factor
= 1;
3548 switch (adapter
->link_speed
) {
3551 netdev
->tx_queue_len
= 10;
3552 adapter
->tx_timeout_factor
= 16;
3556 netdev
->tx_queue_len
= 100;
3557 /* maybe add some timeout factor ? */
3562 * workaround: re-program speed mode bit after
3565 if ((adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) &&
3568 tarc0
= er32(TARC(0));
3569 tarc0
&= ~SPEED_MODE_BIT
;
3570 ew32(TARC(0), tarc0
);
3574 * disable TSO for pcie and 10/100 speeds, to avoid
3575 * some hardware issues
3577 if (!(adapter
->flags
& FLAG_TSO_FORCE
)) {
3578 switch (adapter
->link_speed
) {
3581 e_info("10/100 speed: disabling TSO\n");
3582 netdev
->features
&= ~NETIF_F_TSO
;
3583 netdev
->features
&= ~NETIF_F_TSO6
;
3586 netdev
->features
|= NETIF_F_TSO
;
3587 netdev
->features
|= NETIF_F_TSO6
;
3596 * enable transmits in the hardware, need to do this
3597 * after setting TARC(0)
3600 tctl
|= E1000_TCTL_EN
;
3604 * Perform any post-link-up configuration before
3605 * reporting link up.
3607 if (phy
->ops
.cfg_on_link_up
)
3608 phy
->ops
.cfg_on_link_up(hw
);
3610 netif_carrier_on(netdev
);
3611 netif_tx_wake_all_queues(netdev
);
3613 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
3614 mod_timer(&adapter
->phy_info_timer
,
3615 round_jiffies(jiffies
+ 2 * HZ
));
3618 if (netif_carrier_ok(netdev
)) {
3619 adapter
->link_speed
= 0;
3620 adapter
->link_duplex
= 0;
3621 e_info("Link is Down\n");
3622 netif_carrier_off(netdev
);
3623 netif_tx_stop_all_queues(netdev
);
3624 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
3625 mod_timer(&adapter
->phy_info_timer
,
3626 round_jiffies(jiffies
+ 2 * HZ
));
3628 if (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)
3629 schedule_work(&adapter
->reset_task
);
3634 e1000e_update_stats(adapter
);
3636 mac
->tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
3637 adapter
->tpt_old
= adapter
->stats
.tpt
;
3638 mac
->collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
3639 adapter
->colc_old
= adapter
->stats
.colc
;
3641 adapter
->gorc
= adapter
->stats
.gorc
- adapter
->gorc_old
;
3642 adapter
->gorc_old
= adapter
->stats
.gorc
;
3643 adapter
->gotc
= adapter
->stats
.gotc
- adapter
->gotc_old
;
3644 adapter
->gotc_old
= adapter
->stats
.gotc
;
3646 e1000e_update_adaptive(&adapter
->hw
);
3648 if (!netif_carrier_ok(netdev
)) {
3649 tx_pending
= (e1000_desc_unused(tx_ring
) + 1 <
3653 * We've lost link, so the controller stops DMA,
3654 * but we've got queued Tx work that's never going
3655 * to get done, so reset controller to flush Tx.
3656 * (Do the reset outside of interrupt context).
3658 adapter
->tx_timeout_count
++;
3659 schedule_work(&adapter
->reset_task
);
3663 /* Cause software interrupt to ensure Rx ring is cleaned */
3664 if (adapter
->msix_entries
)
3665 ew32(ICS
, adapter
->rx_ring
->ims_val
);
3667 ew32(ICS
, E1000_ICS_RXDMT0
);
3669 /* Force detection of hung controller every watchdog period */
3670 adapter
->detect_tx_hung
= 1;
3673 * With 82571 controllers, LAA may be overwritten due to controller
3674 * reset from the other port. Set the appropriate LAA in RAR[0]
3676 if (e1000e_get_laa_state_82571(hw
))
3677 e1000e_rar_set(hw
, adapter
->hw
.mac
.addr
, 0);
3679 /* Reset the timer */
3680 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
3681 mod_timer(&adapter
->watchdog_timer
,
3682 round_jiffies(jiffies
+ 2 * HZ
));
3685 #define E1000_TX_FLAGS_CSUM 0x00000001
3686 #define E1000_TX_FLAGS_VLAN 0x00000002
3687 #define E1000_TX_FLAGS_TSO 0x00000004
3688 #define E1000_TX_FLAGS_IPV4 0x00000008
3689 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
3690 #define E1000_TX_FLAGS_VLAN_SHIFT 16
3692 static int e1000_tso(struct e1000_adapter
*adapter
,
3693 struct sk_buff
*skb
)
3695 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3696 struct e1000_context_desc
*context_desc
;
3697 struct e1000_buffer
*buffer_info
;
3700 u16 ipcse
= 0, tucse
, mss
;
3701 u8 ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
3704 if (skb_is_gso(skb
)) {
3705 if (skb_header_cloned(skb
)) {
3706 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
3711 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
3712 mss
= skb_shinfo(skb
)->gso_size
;
3713 if (skb
->protocol
== htons(ETH_P_IP
)) {
3714 struct iphdr
*iph
= ip_hdr(skb
);
3717 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
3721 cmd_length
= E1000_TXD_CMD_IP
;
3722 ipcse
= skb_transport_offset(skb
) - 1;
3723 } else if (skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
) {
3724 ipv6_hdr(skb
)->payload_len
= 0;
3725 tcp_hdr(skb
)->check
=
3726 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
3727 &ipv6_hdr(skb
)->daddr
,
3731 ipcss
= skb_network_offset(skb
);
3732 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
3733 tucss
= skb_transport_offset(skb
);
3734 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
3737 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
3738 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
3740 i
= tx_ring
->next_to_use
;
3741 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
3742 buffer_info
= &tx_ring
->buffer_info
[i
];
3744 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
3745 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
3746 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
3747 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
3748 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
3749 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
3750 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
3751 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
3752 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
3754 buffer_info
->time_stamp
= jiffies
;
3755 buffer_info
->next_to_watch
= i
;
3758 if (i
== tx_ring
->count
)
3760 tx_ring
->next_to_use
= i
;
3768 static bool e1000_tx_csum(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
3770 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3771 struct e1000_context_desc
*context_desc
;
3772 struct e1000_buffer
*buffer_info
;
3775 u32 cmd_len
= E1000_TXD_CMD_DEXT
;
3777 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
3780 switch (skb
->protocol
) {
3781 case __constant_htons(ETH_P_IP
):
3782 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
3783 cmd_len
|= E1000_TXD_CMD_TCP
;
3785 case __constant_htons(ETH_P_IPV6
):
3786 /* XXX not handling all IPV6 headers */
3787 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
3788 cmd_len
|= E1000_TXD_CMD_TCP
;
3791 if (unlikely(net_ratelimit()))
3792 e_warn("checksum_partial proto=%x!\n", skb
->protocol
);
3796 css
= skb_transport_offset(skb
);
3798 i
= tx_ring
->next_to_use
;
3799 buffer_info
= &tx_ring
->buffer_info
[i
];
3800 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
3802 context_desc
->lower_setup
.ip_config
= 0;
3803 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
3804 context_desc
->upper_setup
.tcp_fields
.tucso
=
3805 css
+ skb
->csum_offset
;
3806 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
3807 context_desc
->tcp_seg_setup
.data
= 0;
3808 context_desc
->cmd_and_length
= cpu_to_le32(cmd_len
);
3810 buffer_info
->time_stamp
= jiffies
;
3811 buffer_info
->next_to_watch
= i
;
3814 if (i
== tx_ring
->count
)
3816 tx_ring
->next_to_use
= i
;
3821 #define E1000_MAX_PER_TXD 8192
3822 #define E1000_MAX_TXD_PWR 12
3824 static int e1000_tx_map(struct e1000_adapter
*adapter
,
3825 struct sk_buff
*skb
, unsigned int first
,
3826 unsigned int max_per_txd
, unsigned int nr_frags
,
3829 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3830 struct e1000_buffer
*buffer_info
;
3831 unsigned int len
= skb
->len
- skb
->data_len
;
3832 unsigned int offset
= 0, size
, count
= 0, i
;
3835 i
= tx_ring
->next_to_use
;
3838 buffer_info
= &tx_ring
->buffer_info
[i
];
3839 size
= min(len
, max_per_txd
);
3841 /* Workaround for premature desc write-backs
3842 * in TSO mode. Append 4-byte sentinel desc */
3843 if (mss
&& !nr_frags
&& size
== len
&& size
> 8)
3846 buffer_info
->length
= size
;
3847 /* set time_stamp *before* dma to help avoid a possible race */
3848 buffer_info
->time_stamp
= jiffies
;
3850 pci_map_single(adapter
->pdev
,
3854 if (pci_dma_mapping_error(adapter
->pdev
, buffer_info
->dma
)) {
3855 dev_err(&adapter
->pdev
->dev
, "TX DMA map failed\n");
3856 adapter
->tx_dma_failed
++;
3859 buffer_info
->next_to_watch
= i
;
3865 if (i
== tx_ring
->count
)
3869 for (f
= 0; f
< nr_frags
; f
++) {
3870 struct skb_frag_struct
*frag
;
3872 frag
= &skb_shinfo(skb
)->frags
[f
];
3874 offset
= frag
->page_offset
;
3877 buffer_info
= &tx_ring
->buffer_info
[i
];
3878 size
= min(len
, max_per_txd
);
3879 /* Workaround for premature desc write-backs
3880 * in TSO mode. Append 4-byte sentinel desc */
3881 if (mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8)
3884 buffer_info
->length
= size
;
3885 buffer_info
->time_stamp
= jiffies
;
3887 pci_map_page(adapter
->pdev
,
3892 if (pci_dma_mapping_error(adapter
->pdev
,
3893 buffer_info
->dma
)) {
3894 dev_err(&adapter
->pdev
->dev
,
3895 "TX DMA page map failed\n");
3896 adapter
->tx_dma_failed
++;
3900 buffer_info
->next_to_watch
= i
;
3907 if (i
== tx_ring
->count
)
3913 i
= tx_ring
->count
- 1;
3917 tx_ring
->buffer_info
[i
].skb
= skb
;
3918 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
3923 static void e1000_tx_queue(struct e1000_adapter
*adapter
,
3924 int tx_flags
, int count
)
3926 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3927 struct e1000_tx_desc
*tx_desc
= NULL
;
3928 struct e1000_buffer
*buffer_info
;
3929 u32 txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
3932 if (tx_flags
& E1000_TX_FLAGS_TSO
) {
3933 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
3935 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3937 if (tx_flags
& E1000_TX_FLAGS_IPV4
)
3938 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
3941 if (tx_flags
& E1000_TX_FLAGS_CSUM
) {
3942 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
3943 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3946 if (tx_flags
& E1000_TX_FLAGS_VLAN
) {
3947 txd_lower
|= E1000_TXD_CMD_VLE
;
3948 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
3951 i
= tx_ring
->next_to_use
;
3954 buffer_info
= &tx_ring
->buffer_info
[i
];
3955 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3956 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3957 tx_desc
->lower
.data
=
3958 cpu_to_le32(txd_lower
| buffer_info
->length
);
3959 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
3962 if (i
== tx_ring
->count
)
3966 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
3969 * Force memory writes to complete before letting h/w
3970 * know there are new descriptors to fetch. (Only
3971 * applicable for weak-ordered memory model archs,
3976 tx_ring
->next_to_use
= i
;
3977 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3979 * we need this if more than one processor can write to our tail
3980 * at a time, it synchronizes IO on IA64/Altix systems
3985 #define MINIMUM_DHCP_PACKET_SIZE 282
3986 static int e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
,
3987 struct sk_buff
*skb
)
3989 struct e1000_hw
*hw
= &adapter
->hw
;
3992 if (vlan_tx_tag_present(skb
)) {
3993 if (!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
)
3994 && (adapter
->hw
.mng_cookie
.status
&
3995 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
)))
3999 if (skb
->len
<= MINIMUM_DHCP_PACKET_SIZE
)
4002 if (((struct ethhdr
*) skb
->data
)->h_proto
!= htons(ETH_P_IP
))
4006 const struct iphdr
*ip
= (struct iphdr
*)((u8
*)skb
->data
+14);
4009 if (ip
->protocol
!= IPPROTO_UDP
)
4012 udp
= (struct udphdr
*)((u8
*)ip
+ (ip
->ihl
<< 2));
4013 if (ntohs(udp
->dest
) != 67)
4016 offset
= (u8
*)udp
+ 8 - skb
->data
;
4017 length
= skb
->len
- offset
;
4018 return e1000e_mng_write_dhcp_info(hw
, (u8
*)udp
+ 8, length
);
4024 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
4026 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4028 netif_stop_queue(netdev
);
4030 * Herbert's original patch had:
4031 * smp_mb__after_netif_stop_queue();
4032 * but since that doesn't exist yet, just open code it.
4037 * We need to check again in a case another CPU has just
4038 * made room available.
4040 if (e1000_desc_unused(adapter
->tx_ring
) < size
)
4044 netif_start_queue(netdev
);
4045 ++adapter
->restart_queue
;
4049 static int e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
4051 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4053 if (e1000_desc_unused(adapter
->tx_ring
) >= size
)
4055 return __e1000_maybe_stop_tx(netdev
, size
);
4058 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4059 static int e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
4061 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4062 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
4064 unsigned int max_per_txd
= E1000_MAX_PER_TXD
;
4065 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
4066 unsigned int tx_flags
= 0;
4067 unsigned int len
= skb
->len
- skb
->data_len
;
4068 unsigned long irq_flags
;
4069 unsigned int nr_frags
;
4075 if (test_bit(__E1000_DOWN
, &adapter
->state
)) {
4076 dev_kfree_skb_any(skb
);
4077 return NETDEV_TX_OK
;
4080 if (skb
->len
<= 0) {
4081 dev_kfree_skb_any(skb
);
4082 return NETDEV_TX_OK
;
4085 mss
= skb_shinfo(skb
)->gso_size
;
4087 * The controller does a simple calculation to
4088 * make sure there is enough room in the FIFO before
4089 * initiating the DMA for each buffer. The calc is:
4090 * 4 = ceil(buffer len/mss). To make sure we don't
4091 * overrun the FIFO, adjust the max buffer len if mss
4096 max_per_txd
= min(mss
<< 2, max_per_txd
);
4097 max_txd_pwr
= fls(max_per_txd
) - 1;
4100 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4101 * points to just header, pull a few bytes of payload from
4102 * frags into skb->data
4104 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
4106 * we do this workaround for ES2LAN, but it is un-necessary,
4107 * avoiding it could save a lot of cycles
4109 if (skb
->data_len
&& (hdr_len
== len
)) {
4110 unsigned int pull_size
;
4112 pull_size
= min((unsigned int)4, skb
->data_len
);
4113 if (!__pskb_pull_tail(skb
, pull_size
)) {
4114 e_err("__pskb_pull_tail failed.\n");
4115 dev_kfree_skb_any(skb
);
4116 return NETDEV_TX_OK
;
4118 len
= skb
->len
- skb
->data_len
;
4122 /* reserve a descriptor for the offload context */
4123 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
4127 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
4129 nr_frags
= skb_shinfo(skb
)->nr_frags
;
4130 for (f
= 0; f
< nr_frags
; f
++)
4131 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
4134 if (adapter
->hw
.mac
.tx_pkt_filtering
)
4135 e1000_transfer_dhcp_info(adapter
, skb
);
4137 if (!spin_trylock_irqsave(&adapter
->tx_queue_lock
, irq_flags
))
4138 /* Collision - tell upper layer to requeue */
4139 return NETDEV_TX_LOCKED
;
4142 * need: count + 2 desc gap to keep tail from touching
4143 * head, otherwise try next time
4145 if (e1000_maybe_stop_tx(netdev
, count
+ 2)) {
4146 spin_unlock_irqrestore(&adapter
->tx_queue_lock
, irq_flags
);
4147 return NETDEV_TX_BUSY
;
4150 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
4151 tx_flags
|= E1000_TX_FLAGS_VLAN
;
4152 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
4155 first
= tx_ring
->next_to_use
;
4157 tso
= e1000_tso(adapter
, skb
);
4159 dev_kfree_skb_any(skb
);
4160 spin_unlock_irqrestore(&adapter
->tx_queue_lock
, irq_flags
);
4161 return NETDEV_TX_OK
;
4165 tx_flags
|= E1000_TX_FLAGS_TSO
;
4166 else if (e1000_tx_csum(adapter
, skb
))
4167 tx_flags
|= E1000_TX_FLAGS_CSUM
;
4170 * Old method was to assume IPv4 packet by default if TSO was enabled.
4171 * 82571 hardware supports TSO capabilities for IPv6 as well...
4172 * no longer assume, we must.
4174 if (skb
->protocol
== htons(ETH_P_IP
))
4175 tx_flags
|= E1000_TX_FLAGS_IPV4
;
4177 count
= e1000_tx_map(adapter
, skb
, first
, max_per_txd
, nr_frags
, mss
);
4179 /* handle pci_map_single() error in e1000_tx_map */
4180 dev_kfree_skb_any(skb
);
4181 spin_unlock_irqrestore(&adapter
->tx_queue_lock
, irq_flags
);
4182 return NETDEV_TX_OK
;
4185 e1000_tx_queue(adapter
, tx_flags
, count
);
4187 netdev
->trans_start
= jiffies
;
4189 /* Make sure there is space in the ring for the next send. */
4190 e1000_maybe_stop_tx(netdev
, MAX_SKB_FRAGS
+ 2);
4192 spin_unlock_irqrestore(&adapter
->tx_queue_lock
, irq_flags
);
4193 return NETDEV_TX_OK
;
4197 * e1000_tx_timeout - Respond to a Tx Hang
4198 * @netdev: network interface device structure
4200 static void e1000_tx_timeout(struct net_device
*netdev
)
4202 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4204 /* Do the reset outside of interrupt context */
4205 adapter
->tx_timeout_count
++;
4206 schedule_work(&adapter
->reset_task
);
4209 static void e1000_reset_task(struct work_struct
*work
)
4211 struct e1000_adapter
*adapter
;
4212 adapter
= container_of(work
, struct e1000_adapter
, reset_task
);
4214 e1000e_reinit_locked(adapter
);
4218 * e1000_get_stats - Get System Network Statistics
4219 * @netdev: network interface device structure
4221 * Returns the address of the device statistics structure.
4222 * The statistics are actually updated from the timer callback.
4224 static struct net_device_stats
*e1000_get_stats(struct net_device
*netdev
)
4226 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4228 /* only return the current stats */
4229 return &adapter
->net_stats
;
4233 * e1000_change_mtu - Change the Maximum Transfer Unit
4234 * @netdev: network interface device structure
4235 * @new_mtu: new value for maximum frame size
4237 * Returns 0 on success, negative on failure
4239 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
4241 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4242 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4244 if ((new_mtu
< ETH_ZLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
) ||
4245 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
4246 e_err("Invalid MTU setting\n");
4250 /* Jumbo frame size limits */
4251 if (max_frame
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
4252 if (!(adapter
->flags
& FLAG_HAS_JUMBO_FRAMES
)) {
4253 e_err("Jumbo Frames not supported.\n");
4256 if (adapter
->hw
.phy
.type
== e1000_phy_ife
) {
4257 e_err("Jumbo Frames not supported.\n");
4262 #define MAX_STD_JUMBO_FRAME_SIZE 9234
4263 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
4264 e_err("MTU > 9216 not supported.\n");
4268 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
4270 /* e1000e_down has a dependency on max_frame_size */
4271 adapter
->max_frame_size
= max_frame
;
4272 if (netif_running(netdev
))
4273 e1000e_down(adapter
);
4276 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
4277 * means we reserve 2 more, this pushes us to allocate from the next
4279 * i.e. RXBUFFER_2048 --> size-4096 slab
4280 * However with the new *_jumbo_rx* routines, jumbo receives will use
4284 if (max_frame
<= 256)
4285 adapter
->rx_buffer_len
= 256;
4286 else if (max_frame
<= 512)
4287 adapter
->rx_buffer_len
= 512;
4288 else if (max_frame
<= 1024)
4289 adapter
->rx_buffer_len
= 1024;
4290 else if (max_frame
<= 2048)
4291 adapter
->rx_buffer_len
= 2048;
4293 adapter
->rx_buffer_len
= 4096;
4295 /* adjust allocation if LPE protects us, and we aren't using SBP */
4296 if ((max_frame
== ETH_FRAME_LEN
+ ETH_FCS_LEN
) ||
4297 (max_frame
== ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
))
4298 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
4301 e_info("changing MTU from %d to %d\n", netdev
->mtu
, new_mtu
);
4302 netdev
->mtu
= new_mtu
;
4304 if (netif_running(netdev
))
4307 e1000e_reset(adapter
);
4309 clear_bit(__E1000_RESETTING
, &adapter
->state
);
4314 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
4317 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4318 struct mii_ioctl_data
*data
= if_mii(ifr
);
4320 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
4325 data
->phy_id
= adapter
->hw
.phy
.addr
;
4328 if (!capable(CAP_NET_ADMIN
))
4330 switch (data
->reg_num
& 0x1F) {
4332 data
->val_out
= adapter
->phy_regs
.bmcr
;
4335 data
->val_out
= adapter
->phy_regs
.bmsr
;
4338 data
->val_out
= (adapter
->hw
.phy
.id
>> 16);
4341 data
->val_out
= (adapter
->hw
.phy
.id
& 0xFFFF);
4344 data
->val_out
= adapter
->phy_regs
.advertise
;
4347 data
->val_out
= adapter
->phy_regs
.lpa
;
4350 data
->val_out
= adapter
->phy_regs
.expansion
;
4353 data
->val_out
= adapter
->phy_regs
.ctrl1000
;
4356 data
->val_out
= adapter
->phy_regs
.stat1000
;
4359 data
->val_out
= adapter
->phy_regs
.estatus
;
4372 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4378 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4384 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4386 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4387 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4388 struct e1000_hw
*hw
= &adapter
->hw
;
4389 u32 ctrl
, ctrl_ext
, rctl
, status
;
4390 u32 wufc
= adapter
->wol
;
4393 netif_device_detach(netdev
);
4395 if (netif_running(netdev
)) {
4396 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
4397 e1000e_down(adapter
);
4398 e1000_free_irq(adapter
);
4400 e1000e_reset_interrupt_capability(adapter
);
4402 retval
= pci_save_state(pdev
);
4406 status
= er32(STATUS
);
4407 if (status
& E1000_STATUS_LU
)
4408 wufc
&= ~E1000_WUFC_LNKC
;
4411 e1000_setup_rctl(adapter
);
4412 e1000_set_multi(netdev
);
4414 /* turn on all-multi mode if wake on multicast is enabled */
4415 if (wufc
& E1000_WUFC_MC
) {
4417 rctl
|= E1000_RCTL_MPE
;
4422 /* advertise wake from D3Cold */
4423 #define E1000_CTRL_ADVD3WUC 0x00100000
4424 /* phy power management enable */
4425 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4426 ctrl
|= E1000_CTRL_ADVD3WUC
|
4427 E1000_CTRL_EN_PHY_PWR_MGMT
;
4430 if (adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
||
4431 adapter
->hw
.phy
.media_type
==
4432 e1000_media_type_internal_serdes
) {
4433 /* keep the laser running in D3 */
4434 ctrl_ext
= er32(CTRL_EXT
);
4435 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
4436 ew32(CTRL_EXT
, ctrl_ext
);
4439 if (adapter
->flags
& FLAG_IS_ICH
)
4440 e1000e_disable_gig_wol_ich8lan(&adapter
->hw
);
4442 /* Allow time for pending master requests to run */
4443 e1000e_disable_pcie_master(&adapter
->hw
);
4445 ew32(WUC
, E1000_WUC_PME_EN
);
4447 pci_enable_wake(pdev
, PCI_D3hot
, 1);
4448 pci_enable_wake(pdev
, PCI_D3cold
, 1);
4452 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4453 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4456 /* make sure adapter isn't asleep if manageability is enabled */
4457 if (adapter
->flags
& FLAG_MNG_PT_ENABLED
) {
4458 pci_enable_wake(pdev
, PCI_D3hot
, 1);
4459 pci_enable_wake(pdev
, PCI_D3cold
, 1);
4462 if (adapter
->hw
.phy
.type
== e1000_phy_igp_3
)
4463 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter
->hw
);
4466 * Release control of h/w to f/w. If f/w is AMT enabled, this
4467 * would have already happened in close and is redundant.
4469 e1000_release_hw_control(adapter
);
4471 pci_disable_device(pdev
);
4474 * The pci-e switch on some quad port adapters will report a
4475 * correctable error when the MAC transitions from D0 to D3. To
4476 * prevent this we need to mask off the correctable errors on the
4477 * downstream port of the pci-e switch.
4479 if (adapter
->flags
& FLAG_IS_QUAD_PORT
) {
4480 struct pci_dev
*us_dev
= pdev
->bus
->self
;
4481 int pos
= pci_find_capability(us_dev
, PCI_CAP_ID_EXP
);
4484 pci_read_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
, &devctl
);
4485 pci_write_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
,
4486 (devctl
& ~PCI_EXP_DEVCTL_CERE
));
4488 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4490 pci_write_config_word(us_dev
, pos
+ PCI_EXP_DEVCTL
, devctl
);
4492 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4498 static void e1000e_disable_l1aspm(struct pci_dev
*pdev
)
4504 * 82573 workaround - disable L1 ASPM on mobile chipsets
4506 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
4507 * resulting in lost data or garbage information on the pci-e link
4508 * level. This could result in (false) bad EEPROM checksum errors,
4509 * long ping times (up to 2s) or even a system freeze/hang.
4511 * Unfortunately this feature saves about 1W power consumption when
4514 pos
= pci_find_capability(pdev
, PCI_CAP_ID_EXP
);
4515 pci_read_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, &val
);
4517 dev_warn(&pdev
->dev
, "Disabling L1 ASPM\n");
4519 pci_write_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, val
);
4524 static int e1000_resume(struct pci_dev
*pdev
)
4526 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4527 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4528 struct e1000_hw
*hw
= &adapter
->hw
;
4531 pci_set_power_state(pdev
, PCI_D0
);
4532 pci_restore_state(pdev
);
4533 e1000e_disable_l1aspm(pdev
);
4535 err
= pci_enable_device_mem(pdev
);
4538 "Cannot enable PCI device from suspend\n");
4542 pci_set_master(pdev
);
4544 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4545 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4547 e1000e_set_interrupt_capability(adapter
);
4548 if (netif_running(netdev
)) {
4549 err
= e1000_request_irq(adapter
);
4554 e1000e_power_up_phy(adapter
);
4555 e1000e_reset(adapter
);
4558 e1000_init_manageability(adapter
);
4560 if (netif_running(netdev
))
4563 netif_device_attach(netdev
);
4566 * If the controller has AMT, do not set DRV_LOAD until the interface
4567 * is up. For all other cases, let the f/w know that the h/w is now
4568 * under the control of the driver.
4570 if (!(adapter
->flags
& FLAG_HAS_AMT
))
4571 e1000_get_hw_control(adapter
);
4577 static void e1000_shutdown(struct pci_dev
*pdev
)
4579 e1000_suspend(pdev
, PMSG_SUSPEND
);
4582 #ifdef CONFIG_NET_POLL_CONTROLLER
4584 * Polling 'interrupt' - used by things like netconsole to send skbs
4585 * without having to re-enable interrupts. It's not called while
4586 * the interrupt routine is executing.
4588 static void e1000_netpoll(struct net_device
*netdev
)
4590 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4592 disable_irq(adapter
->pdev
->irq
);
4593 e1000_intr(adapter
->pdev
->irq
, netdev
);
4595 enable_irq(adapter
->pdev
->irq
);
4600 * e1000_io_error_detected - called when PCI error is detected
4601 * @pdev: Pointer to PCI device
4602 * @state: The current pci connection state
4604 * This function is called after a PCI bus error affecting
4605 * this device has been detected.
4607 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
4608 pci_channel_state_t state
)
4610 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4611 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4613 netif_device_detach(netdev
);
4615 if (netif_running(netdev
))
4616 e1000e_down(adapter
);
4617 pci_disable_device(pdev
);
4619 /* Request a slot slot reset. */
4620 return PCI_ERS_RESULT_NEED_RESET
;
4624 * e1000_io_slot_reset - called after the pci bus has been reset.
4625 * @pdev: Pointer to PCI device
4627 * Restart the card from scratch, as if from a cold-boot. Implementation
4628 * resembles the first-half of the e1000_resume routine.
4630 static pci_ers_result_t
e1000_io_slot_reset(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 e1000e_disable_l1aspm(pdev
);
4638 err
= pci_enable_device_mem(pdev
);
4641 "Cannot re-enable PCI device after reset.\n");
4642 return PCI_ERS_RESULT_DISCONNECT
;
4644 pci_set_master(pdev
);
4645 pci_restore_state(pdev
);
4647 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4648 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4650 e1000e_reset(adapter
);
4653 return PCI_ERS_RESULT_RECOVERED
;
4657 * e1000_io_resume - called when traffic can start flowing again.
4658 * @pdev: Pointer to PCI device
4660 * This callback is called when the error recovery driver tells us that
4661 * its OK to resume normal operation. Implementation resembles the
4662 * second-half of the e1000_resume routine.
4664 static void e1000_io_resume(struct pci_dev
*pdev
)
4666 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4667 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4669 e1000_init_manageability(adapter
);
4671 if (netif_running(netdev
)) {
4672 if (e1000e_up(adapter
)) {
4674 "can't bring device back up after reset\n");
4679 netif_device_attach(netdev
);
4682 * If the controller has AMT, do not set DRV_LOAD until the interface
4683 * is up. For all other cases, let the f/w know that the h/w is now
4684 * under the control of the driver.
4686 if (!(adapter
->flags
& FLAG_HAS_AMT
))
4687 e1000_get_hw_control(adapter
);
4691 static void e1000_print_device_info(struct e1000_adapter
*adapter
)
4693 struct e1000_hw
*hw
= &adapter
->hw
;
4694 struct net_device
*netdev
= adapter
->netdev
;
4697 /* print bus type/speed/width info */
4698 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
4700 ((hw
->bus
.width
== e1000_bus_width_pcie_x4
) ? "Width x4" :
4704 e_info("Intel(R) PRO/%s Network Connection\n",
4705 (hw
->phy
.type
== e1000_phy_ife
) ? "10/100" : "1000");
4706 e1000e_read_pba_num(hw
, &pba_num
);
4707 e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4708 hw
->mac
.type
, hw
->phy
.type
, (pba_num
>> 8), (pba_num
& 0xff));
4711 static void e1000_eeprom_checks(struct e1000_adapter
*adapter
)
4713 struct e1000_hw
*hw
= &adapter
->hw
;
4717 if (hw
->mac
.type
!= e1000_82573
)
4720 ret_val
= e1000_read_nvm(hw
, NVM_INIT_CONTROL2_REG
, 1, &buf
);
4721 if (!(le16_to_cpu(buf
) & (1 << 0))) {
4722 /* Deep Smart Power Down (DSPD) */
4723 dev_warn(&adapter
->pdev
->dev
,
4724 "Warning: detected DSPD enabled in EEPROM\n");
4727 ret_val
= e1000_read_nvm(hw
, NVM_INIT_3GIO_3
, 1, &buf
);
4728 if (le16_to_cpu(buf
) & (3 << 2)) {
4730 dev_warn(&adapter
->pdev
->dev
,
4731 "Warning: detected ASPM enabled in EEPROM\n");
4735 static const struct net_device_ops e1000e_netdev_ops
= {
4736 .ndo_open
= e1000_open
,
4737 .ndo_stop
= e1000_close
,
4738 .ndo_start_xmit
= e1000_xmit_frame
,
4739 .ndo_get_stats
= e1000_get_stats
,
4740 .ndo_set_multicast_list
= e1000_set_multi
,
4741 .ndo_set_mac_address
= e1000_set_mac
,
4742 .ndo_change_mtu
= e1000_change_mtu
,
4743 .ndo_do_ioctl
= e1000_ioctl
,
4744 .ndo_tx_timeout
= e1000_tx_timeout
,
4745 .ndo_validate_addr
= eth_validate_addr
,
4747 .ndo_vlan_rx_register
= e1000_vlan_rx_register
,
4748 .ndo_vlan_rx_add_vid
= e1000_vlan_rx_add_vid
,
4749 .ndo_vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
,
4750 #ifdef CONFIG_NET_POLL_CONTROLLER
4751 .ndo_poll_controller
= e1000_netpoll
,
4756 * e1000_probe - Device Initialization Routine
4757 * @pdev: PCI device information struct
4758 * @ent: entry in e1000_pci_tbl
4760 * Returns 0 on success, negative on failure
4762 * e1000_probe initializes an adapter identified by a pci_dev structure.
4763 * The OS initialization, configuring of the adapter private structure,
4764 * and a hardware reset occur.
4766 static int __devinit
e1000_probe(struct pci_dev
*pdev
,
4767 const struct pci_device_id
*ent
)
4769 struct net_device
*netdev
;
4770 struct e1000_adapter
*adapter
;
4771 struct e1000_hw
*hw
;
4772 const struct e1000_info
*ei
= e1000_info_tbl
[ent
->driver_data
];
4773 resource_size_t mmio_start
, mmio_len
;
4774 resource_size_t flash_start
, flash_len
;
4776 static int cards_found
;
4777 int i
, err
, pci_using_dac
;
4778 u16 eeprom_data
= 0;
4779 u16 eeprom_apme_mask
= E1000_EEPROM_APME
;
4781 e1000e_disable_l1aspm(pdev
);
4783 err
= pci_enable_device_mem(pdev
);
4788 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
4790 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
4794 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
4796 err
= pci_set_consistent_dma_mask(pdev
,
4799 dev_err(&pdev
->dev
, "No usable DMA "
4800 "configuration, aborting\n");
4806 err
= pci_request_selected_regions(pdev
,
4807 pci_select_bars(pdev
, IORESOURCE_MEM
),
4808 e1000e_driver_name
);
4812 pci_set_master(pdev
);
4813 /* PCI config space info */
4814 err
= pci_save_state(pdev
);
4816 goto err_alloc_etherdev
;
4819 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
4821 goto err_alloc_etherdev
;
4823 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
4825 pci_set_drvdata(pdev
, netdev
);
4826 adapter
= netdev_priv(netdev
);
4828 adapter
->netdev
= netdev
;
4829 adapter
->pdev
= pdev
;
4831 adapter
->pba
= ei
->pba
;
4832 adapter
->flags
= ei
->flags
;
4833 adapter
->flags2
= ei
->flags2
;
4834 adapter
->hw
.adapter
= adapter
;
4835 adapter
->hw
.mac
.type
= ei
->mac
;
4836 adapter
->msg_enable
= (1 << NETIF_MSG_DRV
| NETIF_MSG_PROBE
) - 1;
4838 mmio_start
= pci_resource_start(pdev
, 0);
4839 mmio_len
= pci_resource_len(pdev
, 0);
4842 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
4843 if (!adapter
->hw
.hw_addr
)
4846 if ((adapter
->flags
& FLAG_HAS_FLASH
) &&
4847 (pci_resource_flags(pdev
, 1) & IORESOURCE_MEM
)) {
4848 flash_start
= pci_resource_start(pdev
, 1);
4849 flash_len
= pci_resource_len(pdev
, 1);
4850 adapter
->hw
.flash_address
= ioremap(flash_start
, flash_len
);
4851 if (!adapter
->hw
.flash_address
)
4855 /* construct the net_device struct */
4856 netdev
->netdev_ops
= &e1000e_netdev_ops
;
4857 e1000e_set_ethtool_ops(netdev
);
4858 netdev
->watchdog_timeo
= 5 * HZ
;
4859 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
4860 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
4862 netdev
->mem_start
= mmio_start
;
4863 netdev
->mem_end
= mmio_start
+ mmio_len
;
4865 adapter
->bd_number
= cards_found
++;
4867 e1000e_check_options(adapter
);
4869 /* setup adapter struct */
4870 err
= e1000_sw_init(adapter
);
4876 memcpy(&hw
->mac
.ops
, ei
->mac_ops
, sizeof(hw
->mac
.ops
));
4877 memcpy(&hw
->nvm
.ops
, ei
->nvm_ops
, sizeof(hw
->nvm
.ops
));
4878 memcpy(&hw
->phy
.ops
, ei
->phy_ops
, sizeof(hw
->phy
.ops
));
4880 err
= ei
->get_variants(adapter
);
4884 if ((adapter
->flags
& FLAG_IS_ICH
) &&
4885 (adapter
->flags
& FLAG_READ_ONLY_NVM
))
4886 e1000e_write_protect_nvm_ich8lan(&adapter
->hw
);
4888 hw
->mac
.ops
.get_bus_info(&adapter
->hw
);
4890 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
4892 /* Copper options */
4893 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
) {
4894 adapter
->hw
.phy
.mdix
= AUTO_ALL_MODES
;
4895 adapter
->hw
.phy
.disable_polarity_correction
= 0;
4896 adapter
->hw
.phy
.ms_type
= e1000_ms_hw_default
;
4899 if (e1000_check_reset_block(&adapter
->hw
))
4900 e_info("PHY reset is blocked due to SOL/IDER session.\n");
4902 netdev
->features
= NETIF_F_SG
|
4904 NETIF_F_HW_VLAN_TX
|
4907 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
)
4908 netdev
->features
|= NETIF_F_HW_VLAN_FILTER
;
4910 netdev
->features
|= NETIF_F_TSO
;
4911 netdev
->features
|= NETIF_F_TSO6
;
4913 netdev
->vlan_features
|= NETIF_F_TSO
;
4914 netdev
->vlan_features
|= NETIF_F_TSO6
;
4915 netdev
->vlan_features
|= NETIF_F_HW_CSUM
;
4916 netdev
->vlan_features
|= NETIF_F_SG
;
4919 netdev
->features
|= NETIF_F_HIGHDMA
;
4922 * We should not be using LLTX anymore, but we are still Tx faster with
4925 netdev
->features
|= NETIF_F_LLTX
;
4927 if (e1000e_enable_mng_pass_thru(&adapter
->hw
))
4928 adapter
->flags
|= FLAG_MNG_PT_ENABLED
;
4931 * before reading the NVM, reset the controller to
4932 * put the device in a known good starting state
4934 adapter
->hw
.mac
.ops
.reset_hw(&adapter
->hw
);
4937 * systems with ASPM and others may see the checksum fail on the first
4938 * attempt. Let's give it a few tries
4941 if (e1000_validate_nvm_checksum(&adapter
->hw
) >= 0)
4944 e_err("The NVM Checksum Is Not Valid\n");
4950 e1000_eeprom_checks(adapter
);
4952 /* copy the MAC address out of the NVM */
4953 if (e1000e_read_mac_addr(&adapter
->hw
))
4954 e_err("NVM Read Error while reading MAC address\n");
4956 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
4957 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
4959 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
4960 e_err("Invalid MAC Address: %pM\n", netdev
->perm_addr
);
4965 init_timer(&adapter
->watchdog_timer
);
4966 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
4967 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
4969 init_timer(&adapter
->phy_info_timer
);
4970 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
4971 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
4973 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
4974 INIT_WORK(&adapter
->watchdog_task
, e1000_watchdog_task
);
4975 INIT_WORK(&adapter
->downshift_task
, e1000e_downshift_workaround
);
4976 INIT_WORK(&adapter
->update_phy_task
, e1000e_update_phy_task
);
4978 /* Initialize link parameters. User can change them with ethtool */
4979 adapter
->hw
.mac
.autoneg
= 1;
4980 adapter
->fc_autoneg
= 1;
4981 adapter
->hw
.fc
.original_type
= e1000_fc_default
;
4982 adapter
->hw
.fc
.type
= e1000_fc_default
;
4983 adapter
->hw
.phy
.autoneg_advertised
= 0x2f;
4985 /* ring size defaults */
4986 adapter
->rx_ring
->count
= 256;
4987 adapter
->tx_ring
->count
= 256;
4990 * Initial Wake on LAN setting - If APM wake is enabled in
4991 * the EEPROM, enable the ACPI Magic Packet filter
4993 if (adapter
->flags
& FLAG_APME_IN_WUC
) {
4994 /* APME bit in EEPROM is mapped to WUC.APME */
4995 eeprom_data
= er32(WUC
);
4996 eeprom_apme_mask
= E1000_WUC_APME
;
4997 } else if (adapter
->flags
& FLAG_APME_IN_CTRL3
) {
4998 if (adapter
->flags
& FLAG_APME_CHECK_PORT_B
&&
4999 (adapter
->hw
.bus
.func
== 1))
5000 e1000_read_nvm(&adapter
->hw
,
5001 NVM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
5003 e1000_read_nvm(&adapter
->hw
,
5004 NVM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
5007 /* fetch WoL from EEPROM */
5008 if (eeprom_data
& eeprom_apme_mask
)
5009 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
5012 * now that we have the eeprom settings, apply the special cases
5013 * where the eeprom may be wrong or the board simply won't support
5014 * wake on lan on a particular port
5016 if (!(adapter
->flags
& FLAG_HAS_WOL
))
5017 adapter
->eeprom_wol
= 0;
5019 /* initialize the wol settings based on the eeprom settings */
5020 adapter
->wol
= adapter
->eeprom_wol
;
5021 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
5023 /* reset the hardware with the new settings */
5024 e1000e_reset(adapter
);
5027 * If the controller has AMT, do not set DRV_LOAD until the interface
5028 * is up. For all other cases, let the f/w know that the h/w is now
5029 * under the control of the driver.
5031 if (!(adapter
->flags
& FLAG_HAS_AMT
))
5032 e1000_get_hw_control(adapter
);
5034 /* tell the stack to leave us alone until e1000_open() is called */
5035 netif_carrier_off(netdev
);
5036 netif_tx_stop_all_queues(netdev
);
5038 strcpy(netdev
->name
, "eth%d");
5039 err
= register_netdev(netdev
);
5043 e1000_print_device_info(adapter
);
5048 if (!(adapter
->flags
& FLAG_HAS_AMT
))
5049 e1000_release_hw_control(adapter
);
5051 if (!e1000_check_reset_block(&adapter
->hw
))
5052 e1000_phy_hw_reset(&adapter
->hw
);
5055 kfree(adapter
->tx_ring
);
5056 kfree(adapter
->rx_ring
);
5058 if (adapter
->hw
.flash_address
)
5059 iounmap(adapter
->hw
.flash_address
);
5060 e1000e_reset_interrupt_capability(adapter
);
5062 iounmap(adapter
->hw
.hw_addr
);
5064 free_netdev(netdev
);
5066 pci_release_selected_regions(pdev
,
5067 pci_select_bars(pdev
, IORESOURCE_MEM
));
5070 pci_disable_device(pdev
);
5075 * e1000_remove - Device Removal Routine
5076 * @pdev: PCI device information struct
5078 * e1000_remove is called by the PCI subsystem to alert the driver
5079 * that it should release a PCI device. The could be caused by a
5080 * Hot-Plug event, or because the driver is going to be removed from
5083 static void __devexit
e1000_remove(struct pci_dev
*pdev
)
5085 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5086 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5089 * flush_scheduled work may reschedule our watchdog task, so
5090 * explicitly disable watchdog tasks from being rescheduled
5092 set_bit(__E1000_DOWN
, &adapter
->state
);
5093 del_timer_sync(&adapter
->watchdog_timer
);
5094 del_timer_sync(&adapter
->phy_info_timer
);
5096 flush_scheduled_work();
5099 * Release control of h/w to f/w. If f/w is AMT enabled, this
5100 * would have already happened in close and is redundant.
5102 e1000_release_hw_control(adapter
);
5104 unregister_netdev(netdev
);
5106 if (!e1000_check_reset_block(&adapter
->hw
))
5107 e1000_phy_hw_reset(&adapter
->hw
);
5109 e1000e_reset_interrupt_capability(adapter
);
5110 kfree(adapter
->tx_ring
);
5111 kfree(adapter
->rx_ring
);
5113 iounmap(adapter
->hw
.hw_addr
);
5114 if (adapter
->hw
.flash_address
)
5115 iounmap(adapter
->hw
.flash_address
);
5116 pci_release_selected_regions(pdev
,
5117 pci_select_bars(pdev
, IORESOURCE_MEM
));
5119 free_netdev(netdev
);
5121 pci_disable_device(pdev
);
5124 /* PCI Error Recovery (ERS) */
5125 static struct pci_error_handlers e1000_err_handler
= {
5126 .error_detected
= e1000_io_error_detected
,
5127 .slot_reset
= e1000_io_slot_reset
,
5128 .resume
= e1000_io_resume
,
5131 static struct pci_device_id e1000_pci_tbl
[] = {
5132 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_COPPER
), board_82571
},
5133 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_FIBER
), board_82571
},
5134 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER
), board_82571
},
5135 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER_LP
), board_82571
},
5136 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_FIBER
), board_82571
},
5137 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES
), board_82571
},
5138 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_DUAL
), board_82571
},
5139 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_QUAD
), board_82571
},
5140 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571PT_QUAD_COPPER
), board_82571
},
5142 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI
), board_82572
},
5143 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_COPPER
), board_82572
},
5144 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_FIBER
), board_82572
},
5145 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_SERDES
), board_82572
},
5147 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E
), board_82573
},
5148 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E_IAMT
), board_82573
},
5149 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573L
), board_82573
},
5151 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82574L
), board_82574
},
5153 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_DPT
),
5154 board_80003es2lan
},
5155 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_SPT
),
5156 board_80003es2lan
},
5157 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_DPT
),
5158 board_80003es2lan
},
5159 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_SPT
),
5160 board_80003es2lan
},
5162 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE
), board_ich8lan
},
5163 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_G
), board_ich8lan
},
5164 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_GT
), board_ich8lan
},
5165 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_AMT
), board_ich8lan
},
5166 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_C
), board_ich8lan
},
5167 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M
), board_ich8lan
},
5168 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M_AMT
), board_ich8lan
},
5170 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE
), board_ich9lan
},
5171 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_G
), board_ich9lan
},
5172 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_GT
), board_ich9lan
},
5173 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_AMT
), board_ich9lan
},
5174 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_C
), board_ich9lan
},
5175 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_BM
), board_ich9lan
},
5176 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M
), board_ich9lan
},
5177 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M_AMT
), board_ich9lan
},
5178 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_M_V
), board_ich9lan
},
5180 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_LM
), board_ich9lan
},
5181 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_LF
), board_ich9lan
},
5182 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_R_BM_V
), board_ich9lan
},
5184 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_LM
), board_ich10lan
},
5185 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH10_D_BM_LF
), board_ich10lan
},
5187 { } /* terminate list */
5189 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
5191 /* PCI Device API Driver */
5192 static struct pci_driver e1000_driver
= {
5193 .name
= e1000e_driver_name
,
5194 .id_table
= e1000_pci_tbl
,
5195 .probe
= e1000_probe
,
5196 .remove
= __devexit_p(e1000_remove
),
5198 /* Power Management Hooks */
5199 .suspend
= e1000_suspend
,
5200 .resume
= e1000_resume
,
5202 .shutdown
= e1000_shutdown
,
5203 .err_handler
= &e1000_err_handler
5207 * e1000_init_module - Driver Registration Routine
5209 * e1000_init_module is the first routine called when the driver is
5210 * loaded. All it does is register with the PCI subsystem.
5212 static int __init
e1000_init_module(void)
5215 printk(KERN_INFO
"%s: Intel(R) PRO/1000 Network Driver - %s\n",
5216 e1000e_driver_name
, e1000e_driver_version
);
5217 printk(KERN_INFO
"%s: Copyright (c) 1999-2008 Intel Corporation.\n",
5218 e1000e_driver_name
);
5219 ret
= pci_register_driver(&e1000_driver
);
5220 pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY
, e1000e_driver_name
,
5221 PM_QOS_DEFAULT_VALUE
);
5225 module_init(e1000_init_module
);
5228 * e1000_exit_module - Driver Exit Cleanup Routine
5230 * e1000_exit_module is called just before the driver is removed
5233 static void __exit
e1000_exit_module(void)
5235 pci_unregister_driver(&e1000_driver
);
5236 pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY
, e1000e_driver_name
);
5238 module_exit(e1000_exit_module
);
5241 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
5242 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
5243 MODULE_LICENSE("GPL");
5244 MODULE_VERSION(DRV_VERSION
);