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>
49 #define DRV_VERSION "0.2.0"
50 char e1000e_driver_name
[] = "e1000e";
51 const char e1000e_driver_version
[] = DRV_VERSION
;
53 static const struct e1000_info
*e1000_info_tbl
[] = {
54 [board_82571
] = &e1000_82571_info
,
55 [board_82572
] = &e1000_82572_info
,
56 [board_82573
] = &e1000_82573_info
,
57 [board_80003es2lan
] = &e1000_es2_info
,
58 [board_ich8lan
] = &e1000_ich8_info
,
59 [board_ich9lan
] = &e1000_ich9_info
,
64 * e1000_get_hw_dev_name - return device name string
65 * used by hardware layer to print debugging information
67 char *e1000e_get_hw_dev_name(struct e1000_hw
*hw
)
69 return hw
->adapter
->netdev
->name
;
74 * e1000_desc_unused - calculate if we have unused descriptors
76 static int e1000_desc_unused(struct e1000_ring
*ring
)
78 if (ring
->next_to_clean
> ring
->next_to_use
)
79 return ring
->next_to_clean
- ring
->next_to_use
- 1;
81 return ring
->count
+ ring
->next_to_clean
- ring
->next_to_use
- 1;
85 * e1000_receive_skb - helper function to handle Rx indications
86 * @adapter: board private structure
87 * @status: descriptor status field as written by hardware
88 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
89 * @skb: pointer to sk_buff to be indicated to stack
91 static void e1000_receive_skb(struct e1000_adapter
*adapter
,
92 struct net_device
*netdev
,
94 u8 status
, __le16 vlan
)
96 skb
->protocol
= eth_type_trans(skb
, netdev
);
98 if (adapter
->vlgrp
&& (status
& E1000_RXD_STAT_VP
))
99 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
101 E1000_RXD_SPC_VLAN_MASK
);
103 netif_receive_skb(skb
);
105 netdev
->last_rx
= jiffies
;
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(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(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(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_clean_rx_irq - Send received data up the network stack; legacy
345 * @adapter: board private structure
347 * the return value indicates whether actual cleaning was done, there
348 * is no guarantee that everything was cleaned
350 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
351 int *work_done
, int work_to_do
)
353 struct net_device
*netdev
= adapter
->netdev
;
354 struct pci_dev
*pdev
= adapter
->pdev
;
355 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
356 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
357 struct e1000_buffer
*buffer_info
, *next_buffer
;
360 int cleaned_count
= 0;
362 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
364 i
= rx_ring
->next_to_clean
;
365 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
366 buffer_info
= &rx_ring
->buffer_info
[i
];
368 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
372 if (*work_done
>= work_to_do
)
376 status
= rx_desc
->status
;
377 skb
= buffer_info
->skb
;
378 buffer_info
->skb
= NULL
;
380 prefetch(skb
->data
- NET_IP_ALIGN
);
383 if (i
== rx_ring
->count
)
385 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
388 next_buffer
= &rx_ring
->buffer_info
[i
];
392 pci_unmap_single(pdev
,
394 adapter
->rx_buffer_len
,
396 buffer_info
->dma
= 0;
398 length
= le16_to_cpu(rx_desc
->length
);
400 /* !EOP means multiple descriptors were used to store a single
401 * packet, also make sure the frame isn't just CRC only */
402 if (!(status
& E1000_RXD_STAT_EOP
) || (length
<= 4)) {
403 /* All receives must fit into a single buffer */
404 ndev_dbg(netdev
, "%s: Receive packet consumed "
405 "multiple buffers\n", netdev
->name
);
407 buffer_info
->skb
= skb
;
411 if (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
) {
413 buffer_info
->skb
= skb
;
417 total_rx_bytes
+= length
;
421 * code added for copybreak, this should improve
422 * performance for small packets with large amounts
423 * of reassembly being done in the stack
425 if (length
< copybreak
) {
426 struct sk_buff
*new_skb
=
427 netdev_alloc_skb(netdev
, length
+ NET_IP_ALIGN
);
429 skb_reserve(new_skb
, NET_IP_ALIGN
);
430 memcpy(new_skb
->data
- NET_IP_ALIGN
,
431 skb
->data
- NET_IP_ALIGN
,
432 length
+ NET_IP_ALIGN
);
433 /* save the skb in buffer_info as good */
434 buffer_info
->skb
= skb
;
437 /* else just continue with the old one */
439 /* end copybreak code */
440 skb_put(skb
, length
);
442 /* Receive Checksum Offload */
443 e1000_rx_checksum(adapter
,
445 ((u32
)(rx_desc
->errors
) << 24),
446 le16_to_cpu(rx_desc
->csum
), skb
);
448 e1000_receive_skb(adapter
, netdev
, skb
,status
,rx_desc
->special
);
453 /* return some buffers to hardware, one at a time is too slow */
454 if (cleaned_count
>= E1000_RX_BUFFER_WRITE
) {
455 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
459 /* use prefetched values */
461 buffer_info
= next_buffer
;
463 rx_ring
->next_to_clean
= i
;
465 cleaned_count
= e1000_desc_unused(rx_ring
);
467 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
469 adapter
->total_rx_packets
+= total_rx_packets
;
470 adapter
->total_rx_bytes
+= total_rx_bytes
;
471 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
472 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
476 static void e1000_put_txbuf(struct e1000_adapter
*adapter
,
477 struct e1000_buffer
*buffer_info
)
479 if (buffer_info
->dma
) {
480 pci_unmap_page(adapter
->pdev
, buffer_info
->dma
,
481 buffer_info
->length
, PCI_DMA_TODEVICE
);
482 buffer_info
->dma
= 0;
484 if (buffer_info
->skb
) {
485 dev_kfree_skb_any(buffer_info
->skb
);
486 buffer_info
->skb
= NULL
;
490 static void e1000_print_tx_hang(struct e1000_adapter
*adapter
)
492 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
493 unsigned int i
= tx_ring
->next_to_clean
;
494 unsigned int eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
495 struct e1000_tx_desc
*eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
496 struct net_device
*netdev
= adapter
->netdev
;
498 /* detected Tx unit hang */
500 "Detected Tx Unit Hang:\n"
503 " next_to_use <%x>\n"
504 " next_to_clean <%x>\n"
505 "buffer_info[next_to_clean]:\n"
506 " time_stamp <%lx>\n"
507 " next_to_watch <%x>\n"
509 " next_to_watch.status <%x>\n",
510 readl(adapter
->hw
.hw_addr
+ tx_ring
->head
),
511 readl(adapter
->hw
.hw_addr
+ tx_ring
->tail
),
512 tx_ring
->next_to_use
,
513 tx_ring
->next_to_clean
,
514 tx_ring
->buffer_info
[eop
].time_stamp
,
517 eop_desc
->upper
.fields
.status
);
521 * e1000_clean_tx_irq - Reclaim resources after transmit completes
522 * @adapter: board private structure
524 * the return value indicates whether actual cleaning was done, there
525 * is no guarantee that everything was cleaned
527 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
)
529 struct net_device
*netdev
= adapter
->netdev
;
530 struct e1000_hw
*hw
= &adapter
->hw
;
531 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
532 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
533 struct e1000_buffer
*buffer_info
;
535 unsigned int count
= 0;
537 unsigned int total_tx_bytes
= 0, total_tx_packets
= 0;
539 i
= tx_ring
->next_to_clean
;
540 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
541 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
543 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
544 for (cleaned
= 0; !cleaned
; ) {
545 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
546 buffer_info
= &tx_ring
->buffer_info
[i
];
547 cleaned
= (i
== eop
);
550 struct sk_buff
*skb
= buffer_info
->skb
;
551 unsigned int segs
, bytecount
;
552 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
553 /* multiply data chunks by size of headers */
554 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
556 total_tx_packets
+= segs
;
557 total_tx_bytes
+= bytecount
;
560 e1000_put_txbuf(adapter
, buffer_info
);
561 tx_desc
->upper
.data
= 0;
564 if (i
== tx_ring
->count
)
568 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
569 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
570 #define E1000_TX_WEIGHT 64
571 /* weight of a sort for tx, to avoid endless transmit cleanup */
572 if (count
++ == E1000_TX_WEIGHT
)
576 tx_ring
->next_to_clean
= i
;
578 #define TX_WAKE_THRESHOLD 32
579 if (cleaned
&& netif_carrier_ok(netdev
) &&
580 e1000_desc_unused(tx_ring
) >= TX_WAKE_THRESHOLD
) {
581 /* Make sure that anybody stopping the queue after this
582 * sees the new next_to_clean.
586 if (netif_queue_stopped(netdev
) &&
587 !(test_bit(__E1000_DOWN
, &adapter
->state
))) {
588 netif_wake_queue(netdev
);
589 ++adapter
->restart_queue
;
593 if (adapter
->detect_tx_hung
) {
595 * Detect a transmit hang in hardware, this serializes the
596 * check with the clearing of time_stamp and movement of i
598 adapter
->detect_tx_hung
= 0;
599 if (tx_ring
->buffer_info
[eop
].dma
&&
600 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
601 + (adapter
->tx_timeout_factor
* HZ
))
602 && !(er32(STATUS
) & E1000_STATUS_TXOFF
)) {
603 e1000_print_tx_hang(adapter
);
604 netif_stop_queue(netdev
);
607 adapter
->total_tx_bytes
+= total_tx_bytes
;
608 adapter
->total_tx_packets
+= total_tx_packets
;
609 adapter
->net_stats
.tx_packets
+= total_tx_packets
;
610 adapter
->net_stats
.tx_bytes
+= total_tx_bytes
;
615 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
616 * @adapter: board private structure
618 * the return value indicates whether actual cleaning was done, there
619 * is no guarantee that everything was cleaned
621 static bool e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
622 int *work_done
, int work_to_do
)
624 union e1000_rx_desc_packet_split
*rx_desc
, *next_rxd
;
625 struct net_device
*netdev
= adapter
->netdev
;
626 struct pci_dev
*pdev
= adapter
->pdev
;
627 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
628 struct e1000_buffer
*buffer_info
, *next_buffer
;
629 struct e1000_ps_page
*ps_page
;
633 int cleaned_count
= 0;
635 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
637 i
= rx_ring
->next_to_clean
;
638 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
639 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
640 buffer_info
= &rx_ring
->buffer_info
[i
];
642 while (staterr
& E1000_RXD_STAT_DD
) {
643 if (*work_done
>= work_to_do
)
646 skb
= buffer_info
->skb
;
648 /* in the packet split case this is header only */
649 prefetch(skb
->data
- NET_IP_ALIGN
);
652 if (i
== rx_ring
->count
)
654 next_rxd
= E1000_RX_DESC_PS(*rx_ring
, i
);
657 next_buffer
= &rx_ring
->buffer_info
[i
];
661 pci_unmap_single(pdev
, buffer_info
->dma
,
662 adapter
->rx_ps_bsize0
,
664 buffer_info
->dma
= 0;
666 if (!(staterr
& E1000_RXD_STAT_EOP
)) {
667 ndev_dbg(netdev
, "%s: Packet Split buffers didn't pick "
668 "up the full packet\n", netdev
->name
);
669 dev_kfree_skb_irq(skb
);
673 if (staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
) {
674 dev_kfree_skb_irq(skb
);
678 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
681 ndev_dbg(netdev
, "%s: Last part of the packet spanning"
682 " multiple descriptors\n", netdev
->name
);
683 dev_kfree_skb_irq(skb
);
688 skb_put(skb
, length
);
692 * this looks ugly, but it seems compiler issues make it
693 * more efficient than reusing j
695 int l1
= le16_to_cpu(rx_desc
->wb
.upper
.length
[0]);
698 * page alloc/put takes too long and effects small packet
699 * throughput, so unsplit small packets and save the alloc/put
700 * only valid in softirq (napi) context to call kmap_*
702 if (l1
&& (l1
<= copybreak
) &&
703 ((length
+ l1
) <= adapter
->rx_ps_bsize0
)) {
706 ps_page
= &buffer_info
->ps_pages
[0];
709 * there is no documentation about how to call
710 * kmap_atomic, so we can't hold the mapping
713 pci_dma_sync_single_for_cpu(pdev
, ps_page
->dma
,
714 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
715 vaddr
= kmap_atomic(ps_page
->page
, KM_SKB_DATA_SOFTIRQ
);
716 memcpy(skb_tail_pointer(skb
), vaddr
, l1
);
717 kunmap_atomic(vaddr
, KM_SKB_DATA_SOFTIRQ
);
718 pci_dma_sync_single_for_device(pdev
, ps_page
->dma
,
719 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
726 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
727 length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
]);
731 ps_page
= &buffer_info
->ps_pages
[j
];
732 pci_unmap_page(pdev
, ps_page
->dma
, PAGE_SIZE
,
735 skb_fill_page_desc(skb
, j
, ps_page
->page
, 0, length
);
736 ps_page
->page
= NULL
;
738 skb
->data_len
+= length
;
739 skb
->truesize
+= length
;
743 total_rx_bytes
+= skb
->len
;
746 e1000_rx_checksum(adapter
, staterr
, le16_to_cpu(
747 rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
), skb
);
749 if (rx_desc
->wb
.upper
.header_status
&
750 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP
))
751 adapter
->rx_hdr_split
++;
753 e1000_receive_skb(adapter
, netdev
, skb
,
754 staterr
, rx_desc
->wb
.middle
.vlan
);
757 rx_desc
->wb
.middle
.status_error
&= cpu_to_le32(~0xFF);
758 buffer_info
->skb
= NULL
;
760 /* return some buffers to hardware, one at a time is too slow */
761 if (cleaned_count
>= E1000_RX_BUFFER_WRITE
) {
762 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
766 /* use prefetched values */
768 buffer_info
= next_buffer
;
770 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
772 rx_ring
->next_to_clean
= i
;
774 cleaned_count
= e1000_desc_unused(rx_ring
);
776 adapter
->alloc_rx_buf(adapter
, cleaned_count
);
778 adapter
->total_rx_packets
+= total_rx_packets
;
779 adapter
->total_rx_bytes
+= total_rx_bytes
;
780 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
781 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
786 * e1000_clean_rx_ring - Free Rx Buffers per Queue
787 * @adapter: board private structure
789 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
)
791 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
792 struct e1000_buffer
*buffer_info
;
793 struct e1000_ps_page
*ps_page
;
794 struct pci_dev
*pdev
= adapter
->pdev
;
797 /* Free all the Rx ring sk_buffs */
798 for (i
= 0; i
< rx_ring
->count
; i
++) {
799 buffer_info
= &rx_ring
->buffer_info
[i
];
800 if (buffer_info
->dma
) {
801 if (adapter
->clean_rx
== e1000_clean_rx_irq
)
802 pci_unmap_single(pdev
, buffer_info
->dma
,
803 adapter
->rx_buffer_len
,
805 else if (adapter
->clean_rx
== e1000_clean_rx_irq_ps
)
806 pci_unmap_single(pdev
, buffer_info
->dma
,
807 adapter
->rx_ps_bsize0
,
809 buffer_info
->dma
= 0;
812 if (buffer_info
->skb
) {
813 dev_kfree_skb(buffer_info
->skb
);
814 buffer_info
->skb
= NULL
;
817 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
818 ps_page
= &buffer_info
->ps_pages
[j
];
821 pci_unmap_page(pdev
, ps_page
->dma
, PAGE_SIZE
,
824 put_page(ps_page
->page
);
825 ps_page
->page
= NULL
;
829 /* there also may be some cached data from a chained receive */
830 if (rx_ring
->rx_skb_top
) {
831 dev_kfree_skb(rx_ring
->rx_skb_top
);
832 rx_ring
->rx_skb_top
= NULL
;
835 /* Zero out the descriptor ring */
836 memset(rx_ring
->desc
, 0, rx_ring
->size
);
838 rx_ring
->next_to_clean
= 0;
839 rx_ring
->next_to_use
= 0;
841 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
842 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
846 * e1000_intr_msi - Interrupt Handler
847 * @irq: interrupt number
848 * @data: pointer to a network interface device structure
850 static irqreturn_t
e1000_intr_msi(int irq
, void *data
)
852 struct net_device
*netdev
= data
;
853 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
854 struct e1000_hw
*hw
= &adapter
->hw
;
858 * read ICR disables interrupts using IAM
861 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
862 hw
->mac
.get_link_status
= 1;
864 * ICH8 workaround-- Call gig speed drop workaround on cable
865 * disconnect (LSC) before accessing any PHY registers
867 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
868 (!(er32(STATUS
) & E1000_STATUS_LU
)))
869 e1000e_gig_downshift_workaround_ich8lan(hw
);
872 * 80003ES2LAN workaround-- For packet buffer work-around on
873 * link down event; disable receives here in the ISR and reset
874 * adapter in watchdog
876 if (netif_carrier_ok(netdev
) &&
877 adapter
->flags
& FLAG_RX_NEEDS_RESTART
) {
878 /* disable receives */
879 u32 rctl
= er32(RCTL
);
880 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
881 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
883 /* guard against interrupt when we're going down */
884 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
885 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
888 if (netif_rx_schedule_prep(netdev
, &adapter
->napi
)) {
889 adapter
->total_tx_bytes
= 0;
890 adapter
->total_tx_packets
= 0;
891 adapter
->total_rx_bytes
= 0;
892 adapter
->total_rx_packets
= 0;
893 __netif_rx_schedule(netdev
, &adapter
->napi
);
900 * e1000_intr - Interrupt Handler
901 * @irq: interrupt number
902 * @data: pointer to a network interface device structure
904 static irqreturn_t
e1000_intr(int irq
, void *data
)
906 struct net_device
*netdev
= data
;
907 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
908 struct e1000_hw
*hw
= &adapter
->hw
;
910 u32 rctl
, icr
= er32(ICR
);
912 return IRQ_NONE
; /* Not our interrupt */
915 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
916 * not set, then the adapter didn't send an interrupt
918 if (!(icr
& E1000_ICR_INT_ASSERTED
))
922 * Interrupt Auto-Mask...upon reading ICR,
923 * interrupts are masked. No need for the
927 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
928 hw
->mac
.get_link_status
= 1;
930 * ICH8 workaround-- Call gig speed drop workaround on cable
931 * disconnect (LSC) before accessing any PHY registers
933 if ((adapter
->flags
& FLAG_LSC_GIG_SPEED_DROP
) &&
934 (!(er32(STATUS
) & E1000_STATUS_LU
)))
935 e1000e_gig_downshift_workaround_ich8lan(hw
);
938 * 80003ES2LAN workaround--
939 * For packet buffer work-around on link down event;
940 * disable receives here in the ISR and
941 * reset adapter in watchdog
943 if (netif_carrier_ok(netdev
) &&
944 (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)) {
945 /* disable receives */
947 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
948 adapter
->flags
|= FLAG_RX_RESTART_NOW
;
950 /* guard against interrupt when we're going down */
951 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
952 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
955 if (netif_rx_schedule_prep(netdev
, &adapter
->napi
)) {
956 adapter
->total_tx_bytes
= 0;
957 adapter
->total_tx_packets
= 0;
958 adapter
->total_rx_bytes
= 0;
959 adapter
->total_rx_packets
= 0;
960 __netif_rx_schedule(netdev
, &adapter
->napi
);
966 static int e1000_request_irq(struct e1000_adapter
*adapter
)
968 struct net_device
*netdev
= adapter
->netdev
;
969 irq_handler_t handler
= e1000_intr
;
970 int irq_flags
= IRQF_SHARED
;
973 if (!pci_enable_msi(adapter
->pdev
)) {
974 adapter
->flags
|= FLAG_MSI_ENABLED
;
975 handler
= e1000_intr_msi
;
979 err
= request_irq(adapter
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
983 "Unable to allocate %s interrupt (return: %d)\n",
984 adapter
->flags
& FLAG_MSI_ENABLED
? "MSI":"INTx",
986 if (adapter
->flags
& FLAG_MSI_ENABLED
)
987 pci_disable_msi(adapter
->pdev
);
993 static void e1000_free_irq(struct e1000_adapter
*adapter
)
995 struct net_device
*netdev
= adapter
->netdev
;
997 free_irq(adapter
->pdev
->irq
, netdev
);
998 if (adapter
->flags
& FLAG_MSI_ENABLED
) {
999 pci_disable_msi(adapter
->pdev
);
1000 adapter
->flags
&= ~FLAG_MSI_ENABLED
;
1005 * e1000_irq_disable - Mask off interrupt generation on the NIC
1007 static void e1000_irq_disable(struct e1000_adapter
*adapter
)
1009 struct e1000_hw
*hw
= &adapter
->hw
;
1013 synchronize_irq(adapter
->pdev
->irq
);
1017 * e1000_irq_enable - Enable default interrupt generation settings
1019 static void e1000_irq_enable(struct e1000_adapter
*adapter
)
1021 struct e1000_hw
*hw
= &adapter
->hw
;
1023 ew32(IMS
, IMS_ENABLE_MASK
);
1028 * e1000_get_hw_control - get control of the h/w from f/w
1029 * @adapter: address of board private structure
1031 * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1032 * For ASF and Pass Through versions of f/w this means that
1033 * the driver is loaded. For AMT version (only with 82573)
1034 * of the f/w this means that the network i/f is open.
1036 static void e1000_get_hw_control(struct e1000_adapter
*adapter
)
1038 struct e1000_hw
*hw
= &adapter
->hw
;
1042 /* Let firmware know the driver has taken over */
1043 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
1045 ew32(SWSM
, swsm
| E1000_SWSM_DRV_LOAD
);
1046 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
1047 ctrl_ext
= er32(CTRL_EXT
);
1048 ew32(CTRL_EXT
, ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
1053 * e1000_release_hw_control - release control of the h/w to f/w
1054 * @adapter: address of board private structure
1056 * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1057 * For ASF and Pass Through versions of f/w this means that the
1058 * driver is no longer loaded. For AMT version (only with 82573) i
1059 * of the f/w this means that the network i/f is closed.
1062 static void e1000_release_hw_control(struct e1000_adapter
*adapter
)
1064 struct e1000_hw
*hw
= &adapter
->hw
;
1068 /* Let firmware taken over control of h/w */
1069 if (adapter
->flags
& FLAG_HAS_SWSM_ON_LOAD
) {
1071 ew32(SWSM
, swsm
& ~E1000_SWSM_DRV_LOAD
);
1072 } else if (adapter
->flags
& FLAG_HAS_CTRLEXT_ON_LOAD
) {
1073 ctrl_ext
= er32(CTRL_EXT
);
1074 ew32(CTRL_EXT
, ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
1079 * @e1000_alloc_ring - allocate memory for a ring structure
1081 static int e1000_alloc_ring_dma(struct e1000_adapter
*adapter
,
1082 struct e1000_ring
*ring
)
1084 struct pci_dev
*pdev
= adapter
->pdev
;
1086 ring
->desc
= dma_alloc_coherent(&pdev
->dev
, ring
->size
, &ring
->dma
,
1095 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1096 * @adapter: board private structure
1098 * Return 0 on success, negative on failure
1100 int e1000e_setup_tx_resources(struct e1000_adapter
*adapter
)
1102 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1103 int err
= -ENOMEM
, size
;
1105 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1106 tx_ring
->buffer_info
= vmalloc(size
);
1107 if (!tx_ring
->buffer_info
)
1109 memset(tx_ring
->buffer_info
, 0, size
);
1111 /* round up to nearest 4K */
1112 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1113 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1115 err
= e1000_alloc_ring_dma(adapter
, tx_ring
);
1119 tx_ring
->next_to_use
= 0;
1120 tx_ring
->next_to_clean
= 0;
1121 spin_lock_init(&adapter
->tx_queue_lock
);
1125 vfree(tx_ring
->buffer_info
);
1126 ndev_err(adapter
->netdev
,
1127 "Unable to allocate memory for the transmit descriptor ring\n");
1132 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1133 * @adapter: board private structure
1135 * Returns 0 on success, negative on failure
1137 int e1000e_setup_rx_resources(struct e1000_adapter
*adapter
)
1139 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1140 struct e1000_buffer
*buffer_info
;
1141 int i
, size
, desc_len
, err
= -ENOMEM
;
1143 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
1144 rx_ring
->buffer_info
= vmalloc(size
);
1145 if (!rx_ring
->buffer_info
)
1147 memset(rx_ring
->buffer_info
, 0, size
);
1149 for (i
= 0; i
< rx_ring
->count
; i
++) {
1150 buffer_info
= &rx_ring
->buffer_info
[i
];
1151 buffer_info
->ps_pages
= kcalloc(PS_PAGE_BUFFERS
,
1152 sizeof(struct e1000_ps_page
),
1154 if (!buffer_info
->ps_pages
)
1158 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1160 /* Round up to nearest 4K */
1161 rx_ring
->size
= rx_ring
->count
* desc_len
;
1162 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
1164 err
= e1000_alloc_ring_dma(adapter
, rx_ring
);
1168 rx_ring
->next_to_clean
= 0;
1169 rx_ring
->next_to_use
= 0;
1170 rx_ring
->rx_skb_top
= NULL
;
1175 for (i
= 0; i
< rx_ring
->count
; i
++) {
1176 buffer_info
= &rx_ring
->buffer_info
[i
];
1177 kfree(buffer_info
->ps_pages
);
1180 vfree(rx_ring
->buffer_info
);
1181 ndev_err(adapter
->netdev
,
1182 "Unable to allocate memory for the transmit descriptor ring\n");
1187 * e1000_clean_tx_ring - Free Tx Buffers
1188 * @adapter: board private structure
1190 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
)
1192 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1193 struct e1000_buffer
*buffer_info
;
1197 for (i
= 0; i
< tx_ring
->count
; i
++) {
1198 buffer_info
= &tx_ring
->buffer_info
[i
];
1199 e1000_put_txbuf(adapter
, buffer_info
);
1202 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1203 memset(tx_ring
->buffer_info
, 0, size
);
1205 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1207 tx_ring
->next_to_use
= 0;
1208 tx_ring
->next_to_clean
= 0;
1210 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1211 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1215 * e1000e_free_tx_resources - Free Tx Resources per Queue
1216 * @adapter: board private structure
1218 * Free all transmit software resources
1220 void e1000e_free_tx_resources(struct e1000_adapter
*adapter
)
1222 struct pci_dev
*pdev
= adapter
->pdev
;
1223 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1225 e1000_clean_tx_ring(adapter
);
1227 vfree(tx_ring
->buffer_info
);
1228 tx_ring
->buffer_info
= NULL
;
1230 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1232 tx_ring
->desc
= NULL
;
1236 * e1000e_free_rx_resources - Free Rx Resources
1237 * @adapter: board private structure
1239 * Free all receive software resources
1242 void e1000e_free_rx_resources(struct e1000_adapter
*adapter
)
1244 struct pci_dev
*pdev
= adapter
->pdev
;
1245 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1248 e1000_clean_rx_ring(adapter
);
1250 for (i
= 0; i
< rx_ring
->count
; i
++) {
1251 kfree(rx_ring
->buffer_info
[i
].ps_pages
);
1254 vfree(rx_ring
->buffer_info
);
1255 rx_ring
->buffer_info
= NULL
;
1257 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
1259 rx_ring
->desc
= NULL
;
1263 * e1000_update_itr - update the dynamic ITR value based on statistics
1264 * @adapter: pointer to adapter
1265 * @itr_setting: current adapter->itr
1266 * @packets: the number of packets during this measurement interval
1267 * @bytes: the number of bytes during this measurement interval
1269 * Stores a new ITR value based on packets and byte
1270 * counts during the last interrupt. The advantage of per interrupt
1271 * computation is faster updates and more accurate ITR for the current
1272 * traffic pattern. Constants in this function were computed
1273 * based on theoretical maximum wire speed and thresholds were set based
1274 * on testing data as well as attempting to minimize response time
1275 * while increasing bulk throughput.
1276 * this functionality is controlled by the InterruptThrottleRate module
1277 * parameter (see e1000_param.c)
1279 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
1280 u16 itr_setting
, int packets
,
1283 unsigned int retval
= itr_setting
;
1286 goto update_itr_done
;
1288 switch (itr_setting
) {
1289 case lowest_latency
:
1290 /* handle TSO and jumbo frames */
1291 if (bytes
/packets
> 8000)
1292 retval
= bulk_latency
;
1293 else if ((packets
< 5) && (bytes
> 512)) {
1294 retval
= low_latency
;
1297 case low_latency
: /* 50 usec aka 20000 ints/s */
1298 if (bytes
> 10000) {
1299 /* this if handles the TSO accounting */
1300 if (bytes
/packets
> 8000) {
1301 retval
= bulk_latency
;
1302 } else if ((packets
< 10) || ((bytes
/packets
) > 1200)) {
1303 retval
= bulk_latency
;
1304 } else if ((packets
> 35)) {
1305 retval
= lowest_latency
;
1307 } else if (bytes
/packets
> 2000) {
1308 retval
= bulk_latency
;
1309 } else if (packets
<= 2 && bytes
< 512) {
1310 retval
= lowest_latency
;
1313 case bulk_latency
: /* 250 usec aka 4000 ints/s */
1314 if (bytes
> 25000) {
1316 retval
= low_latency
;
1318 } else if (bytes
< 6000) {
1319 retval
= low_latency
;
1328 static void e1000_set_itr(struct e1000_adapter
*adapter
)
1330 struct e1000_hw
*hw
= &adapter
->hw
;
1332 u32 new_itr
= adapter
->itr
;
1334 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1335 if (adapter
->link_speed
!= SPEED_1000
) {
1341 adapter
->tx_itr
= e1000_update_itr(adapter
,
1343 adapter
->total_tx_packets
,
1344 adapter
->total_tx_bytes
);
1345 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1346 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
1347 adapter
->tx_itr
= low_latency
;
1349 adapter
->rx_itr
= e1000_update_itr(adapter
,
1351 adapter
->total_rx_packets
,
1352 adapter
->total_rx_bytes
);
1353 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1354 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
1355 adapter
->rx_itr
= low_latency
;
1357 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
1359 switch (current_itr
) {
1360 /* counts and packets in update_itr are dependent on these numbers */
1361 case lowest_latency
:
1365 new_itr
= 20000; /* aka hwitr = ~200 */
1375 if (new_itr
!= adapter
->itr
) {
1377 * this attempts to bias the interrupt rate towards Bulk
1378 * by adding intermediate steps when interrupt rate is
1381 new_itr
= new_itr
> adapter
->itr
?
1382 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
1384 adapter
->itr
= new_itr
;
1385 ew32(ITR
, 1000000000 / (new_itr
* 256));
1390 * e1000_clean - NAPI Rx polling callback
1391 * @napi: struct associated with this polling callback
1392 * @budget: amount of packets driver is allowed to process this poll
1394 static int e1000_clean(struct napi_struct
*napi
, int budget
)
1396 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
, napi
);
1397 struct net_device
*poll_dev
= adapter
->netdev
;
1398 int tx_cleaned
= 0, work_done
= 0;
1400 /* Must NOT use netdev_priv macro here. */
1401 adapter
= poll_dev
->priv
;
1404 * e1000_clean is called per-cpu. This lock protects
1405 * tx_ring from being cleaned by multiple cpus
1406 * simultaneously. A failure obtaining the lock means
1407 * tx_ring is currently being cleaned anyway.
1409 if (spin_trylock(&adapter
->tx_queue_lock
)) {
1410 tx_cleaned
= e1000_clean_tx_irq(adapter
);
1411 spin_unlock(&adapter
->tx_queue_lock
);
1414 adapter
->clean_rx(adapter
, &work_done
, budget
);
1419 /* If budget not fully consumed, exit the polling mode */
1420 if (work_done
< budget
) {
1421 if (adapter
->itr_setting
& 3)
1422 e1000_set_itr(adapter
);
1423 netif_rx_complete(poll_dev
, napi
);
1424 e1000_irq_enable(adapter
);
1430 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
1432 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1433 struct e1000_hw
*hw
= &adapter
->hw
;
1436 /* don't update vlan cookie if already programmed */
1437 if ((adapter
->hw
.mng_cookie
.status
&
1438 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
1439 (vid
== adapter
->mng_vlan_id
))
1441 /* add VID to filter table */
1442 index
= (vid
>> 5) & 0x7F;
1443 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
1444 vfta
|= (1 << (vid
& 0x1F));
1445 e1000e_write_vfta(hw
, index
, vfta
);
1448 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
1450 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1451 struct e1000_hw
*hw
= &adapter
->hw
;
1454 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1455 e1000_irq_disable(adapter
);
1456 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
1458 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1459 e1000_irq_enable(adapter
);
1461 if ((adapter
->hw
.mng_cookie
.status
&
1462 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
1463 (vid
== adapter
->mng_vlan_id
)) {
1464 /* release control to f/w */
1465 e1000_release_hw_control(adapter
);
1469 /* remove VID from filter table */
1470 index
= (vid
>> 5) & 0x7F;
1471 vfta
= E1000_READ_REG_ARRAY(hw
, E1000_VFTA
, index
);
1472 vfta
&= ~(1 << (vid
& 0x1F));
1473 e1000e_write_vfta(hw
, index
, vfta
);
1476 static void e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
1478 struct net_device
*netdev
= adapter
->netdev
;
1479 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
1480 u16 old_vid
= adapter
->mng_vlan_id
;
1482 if (!adapter
->vlgrp
)
1485 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
1486 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1487 if (adapter
->hw
.mng_cookie
.status
&
1488 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) {
1489 e1000_vlan_rx_add_vid(netdev
, vid
);
1490 adapter
->mng_vlan_id
= vid
;
1493 if ((old_vid
!= (u16
)E1000_MNG_VLAN_NONE
) &&
1495 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
1496 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
1498 adapter
->mng_vlan_id
= vid
;
1503 static void e1000_vlan_rx_register(struct net_device
*netdev
,
1504 struct vlan_group
*grp
)
1506 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1507 struct e1000_hw
*hw
= &adapter
->hw
;
1510 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1511 e1000_irq_disable(adapter
);
1512 adapter
->vlgrp
= grp
;
1515 /* enable VLAN tag insert/strip */
1517 ctrl
|= E1000_CTRL_VME
;
1520 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
1521 /* enable VLAN receive filtering */
1523 rctl
|= E1000_RCTL_VFE
;
1524 rctl
&= ~E1000_RCTL_CFIEN
;
1526 e1000_update_mng_vlan(adapter
);
1529 /* disable VLAN tag insert/strip */
1531 ctrl
&= ~E1000_CTRL_VME
;
1534 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
) {
1535 /* disable VLAN filtering */
1537 rctl
&= ~E1000_RCTL_VFE
;
1539 if (adapter
->mng_vlan_id
!=
1540 (u16
)E1000_MNG_VLAN_NONE
) {
1541 e1000_vlan_rx_kill_vid(netdev
,
1542 adapter
->mng_vlan_id
);
1543 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1548 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
1549 e1000_irq_enable(adapter
);
1552 static void e1000_restore_vlan(struct e1000_adapter
*adapter
)
1556 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
1558 if (!adapter
->vlgrp
)
1561 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
1562 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
1564 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
1568 static void e1000_init_manageability(struct e1000_adapter
*adapter
)
1570 struct e1000_hw
*hw
= &adapter
->hw
;
1573 if (!(adapter
->flags
& FLAG_MNG_PT_ENABLED
))
1579 * enable receiving management packets to the host. this will probably
1580 * generate destination unreachable messages from the host OS, but
1581 * the packets will be handled on SMBUS
1583 manc
|= E1000_MANC_EN_MNG2HOST
;
1584 manc2h
= er32(MANC2H
);
1585 #define E1000_MNG2HOST_PORT_623 (1 << 5)
1586 #define E1000_MNG2HOST_PORT_664 (1 << 6)
1587 manc2h
|= E1000_MNG2HOST_PORT_623
;
1588 manc2h
|= E1000_MNG2HOST_PORT_664
;
1589 ew32(MANC2H
, manc2h
);
1594 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1595 * @adapter: board private structure
1597 * Configure the Tx unit of the MAC after a reset.
1599 static void e1000_configure_tx(struct e1000_adapter
*adapter
)
1601 struct e1000_hw
*hw
= &adapter
->hw
;
1602 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
1604 u32 tdlen
, tctl
, tipg
, tarc
;
1607 /* Setup the HW Tx Head and Tail descriptor pointers */
1608 tdba
= tx_ring
->dma
;
1609 tdlen
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1610 ew32(TDBAL
, (tdba
& DMA_32BIT_MASK
));
1611 ew32(TDBAH
, (tdba
>> 32));
1615 tx_ring
->head
= E1000_TDH
;
1616 tx_ring
->tail
= E1000_TDT
;
1618 /* Set the default values for the Tx Inter Packet Gap timer */
1619 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
; /* 8 */
1620 ipgr1
= DEFAULT_82543_TIPG_IPGR1
; /* 8 */
1621 ipgr2
= DEFAULT_82543_TIPG_IPGR2
; /* 6 */
1623 if (adapter
->flags
& FLAG_TIPG_MEDIUM_FOR_80003ESLAN
)
1624 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
; /* 7 */
1626 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1627 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1630 /* Set the Tx Interrupt Delay register */
1631 ew32(TIDV
, adapter
->tx_int_delay
);
1632 /* Tx irq moderation */
1633 ew32(TADV
, adapter
->tx_abs_int_delay
);
1635 /* Program the Transmit Control Register */
1637 tctl
&= ~E1000_TCTL_CT
;
1638 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1639 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1641 if (adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) {
1644 * set the speed mode bit, we'll clear it if we're not at
1645 * gigabit link later
1647 #define SPEED_MODE_BIT (1 << 21)
1648 tarc
|= SPEED_MODE_BIT
;
1652 /* errata: program both queues to unweighted RR */
1653 if (adapter
->flags
& FLAG_TARC_SET_BIT_ZERO
) {
1662 e1000e_config_collision_dist(hw
);
1664 /* Setup Transmit Descriptor Settings for eop descriptor */
1665 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
1667 /* only set IDE if we are delaying interrupts using the timers */
1668 if (adapter
->tx_int_delay
)
1669 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
1671 /* enable Report Status bit */
1672 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1676 adapter
->tx_queue_len
= adapter
->netdev
->tx_queue_len
;
1680 * e1000_setup_rctl - configure the receive control registers
1681 * @adapter: Board private structure
1683 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1684 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1685 static void e1000_setup_rctl(struct e1000_adapter
*adapter
)
1687 struct e1000_hw
*hw
= &adapter
->hw
;
1692 /* Program MC offset vector base */
1694 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1695 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1696 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1697 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1699 /* Do not Store bad packets */
1700 rctl
&= ~E1000_RCTL_SBP
;
1702 /* Enable Long Packet receive */
1703 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1704 rctl
&= ~E1000_RCTL_LPE
;
1706 rctl
|= E1000_RCTL_LPE
;
1708 /* Enable hardware CRC frame stripping */
1709 rctl
|= E1000_RCTL_SECRC
;
1711 /* Setup buffer sizes */
1712 rctl
&= ~E1000_RCTL_SZ_4096
;
1713 rctl
|= E1000_RCTL_BSEX
;
1714 switch (adapter
->rx_buffer_len
) {
1716 rctl
|= E1000_RCTL_SZ_256
;
1717 rctl
&= ~E1000_RCTL_BSEX
;
1720 rctl
|= E1000_RCTL_SZ_512
;
1721 rctl
&= ~E1000_RCTL_BSEX
;
1724 rctl
|= E1000_RCTL_SZ_1024
;
1725 rctl
&= ~E1000_RCTL_BSEX
;
1729 rctl
|= E1000_RCTL_SZ_2048
;
1730 rctl
&= ~E1000_RCTL_BSEX
;
1733 rctl
|= E1000_RCTL_SZ_4096
;
1736 rctl
|= E1000_RCTL_SZ_8192
;
1739 rctl
|= E1000_RCTL_SZ_16384
;
1744 * 82571 and greater support packet-split where the protocol
1745 * header is placed in skb->data and the packet data is
1746 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1747 * In the case of a non-split, skb->data is linearly filled,
1748 * followed by the page buffers. Therefore, skb->data is
1749 * sized to hold the largest protocol header.
1751 * allocations using alloc_page take too long for regular MTU
1752 * so only enable packet split for jumbo frames
1754 * Using pages when the page size is greater than 16k wastes
1755 * a lot of memory, since we allocate 3 pages at all times
1758 adapter
->rx_ps_pages
= 0;
1759 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
1760 if ((pages
<= 3) && (PAGE_SIZE
<= 16384) && (rctl
& E1000_RCTL_LPE
))
1761 adapter
->rx_ps_pages
= pages
;
1763 if (adapter
->rx_ps_pages
) {
1764 /* Configure extra packet-split registers */
1765 rfctl
= er32(RFCTL
);
1766 rfctl
|= E1000_RFCTL_EXTEN
;
1768 * disable packet split support for IPv6 extension headers,
1769 * because some malformed IPv6 headers can hang the Rx
1771 rfctl
|= (E1000_RFCTL_IPV6_EX_DIS
|
1772 E1000_RFCTL_NEW_IPV6_EXT_DIS
);
1776 /* Enable Packet split descriptors */
1777 rctl
|= E1000_RCTL_DTYP_PS
;
1779 psrctl
|= adapter
->rx_ps_bsize0
>>
1780 E1000_PSRCTL_BSIZE0_SHIFT
;
1782 switch (adapter
->rx_ps_pages
) {
1784 psrctl
|= PAGE_SIZE
<<
1785 E1000_PSRCTL_BSIZE3_SHIFT
;
1787 psrctl
|= PAGE_SIZE
<<
1788 E1000_PSRCTL_BSIZE2_SHIFT
;
1790 psrctl
|= PAGE_SIZE
>>
1791 E1000_PSRCTL_BSIZE1_SHIFT
;
1795 ew32(PSRCTL
, psrctl
);
1799 /* just started the receive unit, no need to restart */
1800 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
1804 * e1000_configure_rx - Configure Receive Unit after Reset
1805 * @adapter: board private structure
1807 * Configure the Rx unit of the MAC after a reset.
1809 static void e1000_configure_rx(struct e1000_adapter
*adapter
)
1811 struct e1000_hw
*hw
= &adapter
->hw
;
1812 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
1814 u32 rdlen
, rctl
, rxcsum
, ctrl_ext
;
1816 if (adapter
->rx_ps_pages
) {
1817 /* this is a 32 byte descriptor */
1818 rdlen
= rx_ring
->count
*
1819 sizeof(union e1000_rx_desc_packet_split
);
1820 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
1821 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
1823 rdlen
= rx_ring
->count
*
1824 sizeof(struct e1000_rx_desc
);
1825 adapter
->clean_rx
= e1000_clean_rx_irq
;
1826 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1829 /* disable receives while setting up the descriptors */
1831 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1835 /* set the Receive Delay Timer Register */
1836 ew32(RDTR
, adapter
->rx_int_delay
);
1838 /* irq moderation */
1839 ew32(RADV
, adapter
->rx_abs_int_delay
);
1840 if (adapter
->itr_setting
!= 0)
1841 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
1843 ctrl_ext
= er32(CTRL_EXT
);
1844 /* Reset delay timers after every interrupt */
1845 ctrl_ext
|= E1000_CTRL_EXT_INT_TIMER_CLR
;
1846 /* Auto-Mask interrupts upon ICR access */
1847 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
1848 ew32(IAM
, 0xffffffff);
1849 ew32(CTRL_EXT
, ctrl_ext
);
1853 * Setup the HW Rx Head and Tail Descriptor Pointers and
1854 * the Base and Length of the Rx Descriptor Ring
1856 rdba
= rx_ring
->dma
;
1857 ew32(RDBAL
, (rdba
& DMA_32BIT_MASK
));
1858 ew32(RDBAH
, (rdba
>> 32));
1862 rx_ring
->head
= E1000_RDH
;
1863 rx_ring
->tail
= E1000_RDT
;
1865 /* Enable Receive Checksum Offload for TCP and UDP */
1866 rxcsum
= er32(RXCSUM
);
1867 if (adapter
->flags
& FLAG_RX_CSUM_ENABLED
) {
1868 rxcsum
|= E1000_RXCSUM_TUOFL
;
1871 * IPv4 payload checksum for UDP fragments must be
1872 * used in conjunction with packet-split.
1874 if (adapter
->rx_ps_pages
)
1875 rxcsum
|= E1000_RXCSUM_IPPCSE
;
1877 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1878 /* no need to clear IPPCSE as it defaults to 0 */
1880 ew32(RXCSUM
, rxcsum
);
1883 * Enable early receives on supported devices, only takes effect when
1884 * packet size is equal or larger than the specified value (in 8 byte
1885 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
1887 if ((adapter
->flags
& FLAG_HAS_ERT
) &&
1888 (adapter
->netdev
->mtu
> ETH_DATA_LEN
))
1889 ew32(ERT
, E1000_ERT_2048
);
1891 /* Enable Receives */
1896 * e1000_update_mc_addr_list - Update Multicast addresses
1897 * @hw: pointer to the HW structure
1898 * @mc_addr_list: array of multicast addresses to program
1899 * @mc_addr_count: number of multicast addresses to program
1900 * @rar_used_count: the first RAR register free to program
1901 * @rar_count: total number of supported Receive Address Registers
1903 * Updates the Receive Address Registers and Multicast Table Array.
1904 * The caller must have a packed mc_addr_list of multicast addresses.
1905 * The parameter rar_count will usually be hw->mac.rar_entry_count
1906 * unless there are workarounds that change this. Currently no func pointer
1907 * exists and all implementations are handled in the generic version of this
1910 static void e1000_update_mc_addr_list(struct e1000_hw
*hw
, u8
*mc_addr_list
,
1911 u32 mc_addr_count
, u32 rar_used_count
,
1914 hw
->mac
.ops
.update_mc_addr_list(hw
, mc_addr_list
, mc_addr_count
,
1915 rar_used_count
, rar_count
);
1919 * e1000_set_multi - Multicast and Promiscuous mode set
1920 * @netdev: network interface device structure
1922 * The set_multi entry point is called whenever the multicast address
1923 * list or the network interface flags are updated. This routine is
1924 * responsible for configuring the hardware for proper multicast,
1925 * promiscuous mode, and all-multi behavior.
1927 static void e1000_set_multi(struct net_device
*netdev
)
1929 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1930 struct e1000_hw
*hw
= &adapter
->hw
;
1931 struct e1000_mac_info
*mac
= &hw
->mac
;
1932 struct dev_mc_list
*mc_ptr
;
1937 /* Check for Promiscuous and All Multicast modes */
1941 if (netdev
->flags
& IFF_PROMISC
) {
1942 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
1943 } else if (netdev
->flags
& IFF_ALLMULTI
) {
1944 rctl
|= E1000_RCTL_MPE
;
1945 rctl
&= ~E1000_RCTL_UPE
;
1947 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
1952 if (netdev
->mc_count
) {
1953 mta_list
= kmalloc(netdev
->mc_count
* 6, GFP_ATOMIC
);
1957 /* prepare a packed array of only addresses. */
1958 mc_ptr
= netdev
->mc_list
;
1960 for (i
= 0; i
< netdev
->mc_count
; i
++) {
1963 memcpy(mta_list
+ (i
*ETH_ALEN
), mc_ptr
->dmi_addr
,
1965 mc_ptr
= mc_ptr
->next
;
1968 e1000_update_mc_addr_list(hw
, mta_list
, i
, 1,
1969 mac
->rar_entry_count
);
1973 * if we're called from probe, we might not have
1974 * anything to do here, so clear out the list
1976 e1000_update_mc_addr_list(hw
, NULL
, 0, 1, mac
->rar_entry_count
);
1981 * e1000_configure - configure the hardware for Rx and Tx
1982 * @adapter: private board structure
1984 static void e1000_configure(struct e1000_adapter
*adapter
)
1986 e1000_set_multi(adapter
->netdev
);
1988 e1000_restore_vlan(adapter
);
1989 e1000_init_manageability(adapter
);
1991 e1000_configure_tx(adapter
);
1992 e1000_setup_rctl(adapter
);
1993 e1000_configure_rx(adapter
);
1994 adapter
->alloc_rx_buf(adapter
, e1000_desc_unused(adapter
->rx_ring
));
1998 * e1000e_power_up_phy - restore link in case the phy was powered down
1999 * @adapter: address of board private structure
2001 * The phy may be powered down to save power and turn off link when the
2002 * driver is unloaded and wake on lan is not enabled (among others)
2003 * *** this routine MUST be followed by a call to e1000e_reset ***
2005 void e1000e_power_up_phy(struct e1000_adapter
*adapter
)
2009 /* Just clear the power down bit to wake the phy back up */
2010 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
) {
2012 * According to the manual, the phy will retain its
2013 * settings across a power-down/up cycle
2015 e1e_rphy(&adapter
->hw
, PHY_CONTROL
, &mii_reg
);
2016 mii_reg
&= ~MII_CR_POWER_DOWN
;
2017 e1e_wphy(&adapter
->hw
, PHY_CONTROL
, mii_reg
);
2020 adapter
->hw
.mac
.ops
.setup_link(&adapter
->hw
);
2024 * e1000_power_down_phy - Power down the PHY
2026 * Power down the PHY so no link is implied when interface is down
2027 * The PHY cannot be powered down is management or WoL is active
2029 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
2031 struct e1000_hw
*hw
= &adapter
->hw
;
2034 /* WoL is enabled */
2038 /* non-copper PHY? */
2039 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
2042 /* reset is blocked because of a SoL/IDER session */
2043 if (e1000e_check_mng_mode(hw
) || e1000_check_reset_block(hw
))
2046 /* manageability (AMT) is enabled */
2047 if (er32(MANC
) & E1000_MANC_SMBUS_EN
)
2050 /* power down the PHY */
2051 e1e_rphy(hw
, PHY_CONTROL
, &mii_reg
);
2052 mii_reg
|= MII_CR_POWER_DOWN
;
2053 e1e_wphy(hw
, PHY_CONTROL
, mii_reg
);
2058 * e1000e_reset - bring the hardware into a known good state
2060 * This function boots the hardware and enables some settings that
2061 * require a configuration cycle of the hardware - those cannot be
2062 * set/changed during runtime. After reset the device needs to be
2063 * properly configured for Rx, Tx etc.
2065 void e1000e_reset(struct e1000_adapter
*adapter
)
2067 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
2068 struct e1000_fc_info
*fc
= &adapter
->hw
.fc
;
2069 struct e1000_hw
*hw
= &adapter
->hw
;
2070 u32 tx_space
, min_tx_space
, min_rx_space
;
2071 u32 pba
= adapter
->pba
;
2074 /* reset Packet Buffer Allocation to default */
2077 if (adapter
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
2079 * To maintain wire speed transmits, the Tx FIFO should be
2080 * large enough to accommodate two full transmit packets,
2081 * rounded up to the next 1KB and expressed in KB. Likewise,
2082 * the Rx FIFO should be large enough to accommodate at least
2083 * one full receive packet and is similarly rounded up and
2087 /* upper 16 bits has Tx packet buffer allocation size in KB */
2088 tx_space
= pba
>> 16;
2089 /* lower 16 bits has Rx packet buffer allocation size in KB */
2092 * the Tx fifo also stores 16 bytes of information about the tx
2093 * but don't include ethernet FCS because hardware appends it
2095 min_tx_space
= (adapter
->max_frame_size
+
2096 sizeof(struct e1000_tx_desc
) -
2098 min_tx_space
= ALIGN(min_tx_space
, 1024);
2099 min_tx_space
>>= 10;
2100 /* software strips receive CRC, so leave room for it */
2101 min_rx_space
= adapter
->max_frame_size
;
2102 min_rx_space
= ALIGN(min_rx_space
, 1024);
2103 min_rx_space
>>= 10;
2106 * If current Tx allocation is less than the min Tx FIFO size,
2107 * and the min Tx FIFO size is less than the current Rx FIFO
2108 * allocation, take space away from current Rx allocation
2110 if ((tx_space
< min_tx_space
) &&
2111 ((min_tx_space
- tx_space
) < pba
)) {
2112 pba
-= min_tx_space
- tx_space
;
2115 * if short on Rx space, Rx wins and must trump tx
2116 * adjustment or use Early Receive if available
2118 if ((pba
< min_rx_space
) &&
2119 (!(adapter
->flags
& FLAG_HAS_ERT
)))
2120 /* ERT enabled in e1000_configure_rx */
2129 * flow control settings
2131 * The high water mark must be low enough to fit one full frame
2132 * (or the size used for early receive) above it in the Rx FIFO.
2133 * Set it to the lower of:
2134 * - 90% of the Rx FIFO size, and
2135 * - the full Rx FIFO size minus the early receive size (for parts
2136 * with ERT support assuming ERT set to E1000_ERT_2048), or
2137 * - the full Rx FIFO size minus one full frame
2139 if (adapter
->flags
& FLAG_HAS_ERT
)
2140 hwm
= min(((pba
<< 10) * 9 / 10),
2141 ((pba
<< 10) - (E1000_ERT_2048
<< 3)));
2143 hwm
= min(((pba
<< 10) * 9 / 10),
2144 ((pba
<< 10) - adapter
->max_frame_size
));
2146 fc
->high_water
= hwm
& 0xFFF8; /* 8-byte granularity */
2147 fc
->low_water
= fc
->high_water
- 8;
2149 if (adapter
->flags
& FLAG_DISABLE_FC_PAUSE_TIME
)
2150 fc
->pause_time
= 0xFFFF;
2152 fc
->pause_time
= E1000_FC_PAUSE_TIME
;
2154 fc
->type
= fc
->original_type
;
2156 /* Allow time for pending master requests to run */
2157 mac
->ops
.reset_hw(hw
);
2160 if (mac
->ops
.init_hw(hw
))
2161 ndev_err(adapter
->netdev
, "Hardware Error\n");
2163 e1000_update_mng_vlan(adapter
);
2165 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2166 ew32(VET
, ETH_P_8021Q
);
2168 e1000e_reset_adaptive(hw
);
2169 e1000_get_phy_info(hw
);
2171 if (!(adapter
->flags
& FLAG_SMART_POWER_DOWN
)) {
2174 * speed up time to link by disabling smart power down, ignore
2175 * the return value of this function because there is nothing
2176 * different we would do if it failed
2178 e1e_rphy(hw
, IGP02E1000_PHY_POWER_MGMT
, &phy_data
);
2179 phy_data
&= ~IGP02E1000_PM_SPD
;
2180 e1e_wphy(hw
, IGP02E1000_PHY_POWER_MGMT
, phy_data
);
2184 int e1000e_up(struct e1000_adapter
*adapter
)
2186 struct e1000_hw
*hw
= &adapter
->hw
;
2188 /* hardware has been reset, we need to reload some things */
2189 e1000_configure(adapter
);
2191 clear_bit(__E1000_DOWN
, &adapter
->state
);
2193 napi_enable(&adapter
->napi
);
2194 e1000_irq_enable(adapter
);
2196 /* fire a link change interrupt to start the watchdog */
2197 ew32(ICS
, E1000_ICS_LSC
);
2201 void e1000e_down(struct e1000_adapter
*adapter
)
2203 struct net_device
*netdev
= adapter
->netdev
;
2204 struct e1000_hw
*hw
= &adapter
->hw
;
2208 * signal that we're down so the interrupt handler does not
2209 * reschedule our watchdog timer
2211 set_bit(__E1000_DOWN
, &adapter
->state
);
2213 /* disable receives in the hardware */
2215 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
2216 /* flush and sleep below */
2218 netif_stop_queue(netdev
);
2220 /* disable transmits in the hardware */
2222 tctl
&= ~E1000_TCTL_EN
;
2224 /* flush both disables and wait for them to finish */
2228 napi_disable(&adapter
->napi
);
2229 e1000_irq_disable(adapter
);
2231 del_timer_sync(&adapter
->watchdog_timer
);
2232 del_timer_sync(&adapter
->phy_info_timer
);
2234 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2235 netif_carrier_off(netdev
);
2236 adapter
->link_speed
= 0;
2237 adapter
->link_duplex
= 0;
2239 e1000e_reset(adapter
);
2240 e1000_clean_tx_ring(adapter
);
2241 e1000_clean_rx_ring(adapter
);
2244 * TODO: for power management, we could drop the link and
2245 * pci_disable_device here.
2249 void e1000e_reinit_locked(struct e1000_adapter
*adapter
)
2252 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
2254 e1000e_down(adapter
);
2256 clear_bit(__E1000_RESETTING
, &adapter
->state
);
2260 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2261 * @adapter: board private structure to initialize
2263 * e1000_sw_init initializes the Adapter private data structure.
2264 * Fields are initialized based on PCI device information and
2265 * OS network device settings (MTU size).
2267 static int __devinit
e1000_sw_init(struct e1000_adapter
*adapter
)
2269 struct net_device
*netdev
= adapter
->netdev
;
2271 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
;
2272 adapter
->rx_ps_bsize0
= 128;
2273 adapter
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2274 adapter
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
2276 adapter
->tx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
2277 if (!adapter
->tx_ring
)
2280 adapter
->rx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
2281 if (!adapter
->rx_ring
)
2284 spin_lock_init(&adapter
->tx_queue_lock
);
2286 /* Explicitly disable IRQ since the NIC can be in any state. */
2287 e1000_irq_disable(adapter
);
2289 spin_lock_init(&adapter
->stats_lock
);
2291 set_bit(__E1000_DOWN
, &adapter
->state
);
2295 ndev_err(netdev
, "Unable to allocate memory for queues\n");
2296 kfree(adapter
->rx_ring
);
2297 kfree(adapter
->tx_ring
);
2302 * e1000_open - Called when a network interface is made active
2303 * @netdev: network interface device structure
2305 * Returns 0 on success, negative value on failure
2307 * The open entry point is called when a network interface is made
2308 * active by the system (IFF_UP). At this point all resources needed
2309 * for transmit and receive operations are allocated, the interrupt
2310 * handler is registered with the OS, the watchdog timer is started,
2311 * and the stack is notified that the interface is ready.
2313 static int e1000_open(struct net_device
*netdev
)
2315 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2316 struct e1000_hw
*hw
= &adapter
->hw
;
2319 /* disallow open during test */
2320 if (test_bit(__E1000_TESTING
, &adapter
->state
))
2323 /* allocate transmit descriptors */
2324 err
= e1000e_setup_tx_resources(adapter
);
2328 /* allocate receive descriptors */
2329 err
= e1000e_setup_rx_resources(adapter
);
2333 e1000e_power_up_phy(adapter
);
2335 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
2336 if ((adapter
->hw
.mng_cookie
.status
&
2337 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
))
2338 e1000_update_mng_vlan(adapter
);
2341 * If AMT is enabled, let the firmware know that the network
2342 * interface is now open
2344 if ((adapter
->flags
& FLAG_HAS_AMT
) &&
2345 e1000e_check_mng_mode(&adapter
->hw
))
2346 e1000_get_hw_control(adapter
);
2349 * before we allocate an interrupt, we must be ready to handle it.
2350 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
2351 * as soon as we call pci_request_irq, so we have to setup our
2352 * clean_rx handler before we do so.
2354 e1000_configure(adapter
);
2356 err
= e1000_request_irq(adapter
);
2360 /* From here on the code is the same as e1000e_up() */
2361 clear_bit(__E1000_DOWN
, &adapter
->state
);
2363 napi_enable(&adapter
->napi
);
2365 e1000_irq_enable(adapter
);
2367 /* fire a link status change interrupt to start the watchdog */
2368 ew32(ICS
, E1000_ICS_LSC
);
2373 e1000_release_hw_control(adapter
);
2374 e1000_power_down_phy(adapter
);
2375 e1000e_free_rx_resources(adapter
);
2377 e1000e_free_tx_resources(adapter
);
2379 e1000e_reset(adapter
);
2385 * e1000_close - Disables a network interface
2386 * @netdev: network interface device structure
2388 * Returns 0, this is not allowed to fail
2390 * The close entry point is called when an interface is de-activated
2391 * by the OS. The hardware is still under the drivers control, but
2392 * needs to be disabled. A global MAC reset is issued to stop the
2393 * hardware, and all transmit and receive resources are freed.
2395 static int e1000_close(struct net_device
*netdev
)
2397 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2399 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
2400 e1000e_down(adapter
);
2401 e1000_power_down_phy(adapter
);
2402 e1000_free_irq(adapter
);
2404 e1000e_free_tx_resources(adapter
);
2405 e1000e_free_rx_resources(adapter
);
2408 * kill manageability vlan ID if supported, but not if a vlan with
2409 * the same ID is registered on the host OS (let 8021q kill it)
2411 if ((adapter
->hw
.mng_cookie
.status
&
2412 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
2414 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
)))
2415 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
2418 * If AMT is enabled, let the firmware know that the network
2419 * interface is now closed
2421 if ((adapter
->flags
& FLAG_HAS_AMT
) &&
2422 e1000e_check_mng_mode(&adapter
->hw
))
2423 e1000_release_hw_control(adapter
);
2428 * e1000_set_mac - Change the Ethernet Address of the NIC
2429 * @netdev: network interface device structure
2430 * @p: pointer to an address structure
2432 * Returns 0 on success, negative on failure
2434 static int e1000_set_mac(struct net_device
*netdev
, void *p
)
2436 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2437 struct sockaddr
*addr
= p
;
2439 if (!is_valid_ether_addr(addr
->sa_data
))
2440 return -EADDRNOTAVAIL
;
2442 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2443 memcpy(adapter
->hw
.mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
2445 e1000e_rar_set(&adapter
->hw
, adapter
->hw
.mac
.addr
, 0);
2447 if (adapter
->flags
& FLAG_RESET_OVERWRITES_LAA
) {
2448 /* activate the work around */
2449 e1000e_set_laa_state_82571(&adapter
->hw
, 1);
2452 * Hold a copy of the LAA in RAR[14] This is done so that
2453 * between the time RAR[0] gets clobbered and the time it
2454 * gets fixed (in e1000_watchdog), the actual LAA is in one
2455 * of the RARs and no incoming packets directed to this port
2456 * are dropped. Eventually the LAA will be in RAR[0] and
2459 e1000e_rar_set(&adapter
->hw
,
2460 adapter
->hw
.mac
.addr
,
2461 adapter
->hw
.mac
.rar_entry_count
- 1);
2468 * Need to wait a few seconds after link up to get diagnostic information from
2471 static void e1000_update_phy_info(unsigned long data
)
2473 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2474 e1000_get_phy_info(&adapter
->hw
);
2478 * e1000e_update_stats - Update the board statistics counters
2479 * @adapter: board private structure
2481 void e1000e_update_stats(struct e1000_adapter
*adapter
)
2483 struct e1000_hw
*hw
= &adapter
->hw
;
2484 struct pci_dev
*pdev
= adapter
->pdev
;
2485 unsigned long irq_flags
;
2488 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2491 * Prevent stats update while adapter is being reset, or if the pci
2492 * connection is down.
2494 if (adapter
->link_speed
== 0)
2496 if (pci_channel_offline(pdev
))
2499 spin_lock_irqsave(&adapter
->stats_lock
, irq_flags
);
2502 * these counters are modified from e1000_adjust_tbi_stats,
2503 * called from the interrupt context, so they must only
2504 * be written while holding adapter->stats_lock
2507 adapter
->stats
.crcerrs
+= er32(CRCERRS
);
2508 adapter
->stats
.gprc
+= er32(GPRC
);
2509 adapter
->stats
.gorcl
+= er32(GORCL
);
2510 adapter
->stats
.gorch
+= er32(GORCH
);
2511 adapter
->stats
.bprc
+= er32(BPRC
);
2512 adapter
->stats
.mprc
+= er32(MPRC
);
2513 adapter
->stats
.roc
+= er32(ROC
);
2515 if (adapter
->flags
& FLAG_HAS_STATS_PTC_PRC
) {
2516 adapter
->stats
.prc64
+= er32(PRC64
);
2517 adapter
->stats
.prc127
+= er32(PRC127
);
2518 adapter
->stats
.prc255
+= er32(PRC255
);
2519 adapter
->stats
.prc511
+= er32(PRC511
);
2520 adapter
->stats
.prc1023
+= er32(PRC1023
);
2521 adapter
->stats
.prc1522
+= er32(PRC1522
);
2522 adapter
->stats
.symerrs
+= er32(SYMERRS
);
2523 adapter
->stats
.sec
+= er32(SEC
);
2526 adapter
->stats
.mpc
+= er32(MPC
);
2527 adapter
->stats
.scc
+= er32(SCC
);
2528 adapter
->stats
.ecol
+= er32(ECOL
);
2529 adapter
->stats
.mcc
+= er32(MCC
);
2530 adapter
->stats
.latecol
+= er32(LATECOL
);
2531 adapter
->stats
.dc
+= er32(DC
);
2532 adapter
->stats
.rlec
+= er32(RLEC
);
2533 adapter
->stats
.xonrxc
+= er32(XONRXC
);
2534 adapter
->stats
.xontxc
+= er32(XONTXC
);
2535 adapter
->stats
.xoffrxc
+= er32(XOFFRXC
);
2536 adapter
->stats
.xofftxc
+= er32(XOFFTXC
);
2537 adapter
->stats
.fcruc
+= er32(FCRUC
);
2538 adapter
->stats
.gptc
+= er32(GPTC
);
2539 adapter
->stats
.gotcl
+= er32(GOTCL
);
2540 adapter
->stats
.gotch
+= er32(GOTCH
);
2541 adapter
->stats
.rnbc
+= er32(RNBC
);
2542 adapter
->stats
.ruc
+= er32(RUC
);
2543 adapter
->stats
.rfc
+= er32(RFC
);
2544 adapter
->stats
.rjc
+= er32(RJC
);
2545 adapter
->stats
.torl
+= er32(TORL
);
2546 adapter
->stats
.torh
+= er32(TORH
);
2547 adapter
->stats
.totl
+= er32(TOTL
);
2548 adapter
->stats
.toth
+= er32(TOTH
);
2549 adapter
->stats
.tpr
+= er32(TPR
);
2551 if (adapter
->flags
& FLAG_HAS_STATS_PTC_PRC
) {
2552 adapter
->stats
.ptc64
+= er32(PTC64
);
2553 adapter
->stats
.ptc127
+= er32(PTC127
);
2554 adapter
->stats
.ptc255
+= er32(PTC255
);
2555 adapter
->stats
.ptc511
+= er32(PTC511
);
2556 adapter
->stats
.ptc1023
+= er32(PTC1023
);
2557 adapter
->stats
.ptc1522
+= er32(PTC1522
);
2560 adapter
->stats
.mptc
+= er32(MPTC
);
2561 adapter
->stats
.bptc
+= er32(BPTC
);
2563 /* used for adaptive IFS */
2565 hw
->mac
.tx_packet_delta
= er32(TPT
);
2566 adapter
->stats
.tpt
+= hw
->mac
.tx_packet_delta
;
2567 hw
->mac
.collision_delta
= er32(COLC
);
2568 adapter
->stats
.colc
+= hw
->mac
.collision_delta
;
2570 adapter
->stats
.algnerrc
+= er32(ALGNERRC
);
2571 adapter
->stats
.rxerrc
+= er32(RXERRC
);
2572 adapter
->stats
.tncrs
+= er32(TNCRS
);
2573 adapter
->stats
.cexterr
+= er32(CEXTERR
);
2574 adapter
->stats
.tsctc
+= er32(TSCTC
);
2575 adapter
->stats
.tsctfc
+= er32(TSCTFC
);
2577 adapter
->stats
.iac
+= er32(IAC
);
2579 if (adapter
->flags
& FLAG_HAS_STATS_ICR_ICT
) {
2580 adapter
->stats
.icrxoc
+= er32(ICRXOC
);
2581 adapter
->stats
.icrxptc
+= er32(ICRXPTC
);
2582 adapter
->stats
.icrxatc
+= er32(ICRXATC
);
2583 adapter
->stats
.ictxptc
+= er32(ICTXPTC
);
2584 adapter
->stats
.ictxatc
+= er32(ICTXATC
);
2585 adapter
->stats
.ictxqec
+= er32(ICTXQEC
);
2586 adapter
->stats
.ictxqmtc
+= er32(ICTXQMTC
);
2587 adapter
->stats
.icrxdmtc
+= er32(ICRXDMTC
);
2590 /* Fill out the OS statistics structure */
2591 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
2592 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
2597 * RLEC on some newer hardware can be incorrect so build
2598 * our own version based on RUC and ROC
2600 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
2601 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
2602 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
2603 adapter
->stats
.cexterr
;
2604 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.ruc
+
2606 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
2607 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
2608 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
2611 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
2612 adapter
->stats
.latecol
;
2613 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
2614 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
2615 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
2617 /* Tx Dropped needs to be maintained elsewhere */
2620 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
2621 if ((adapter
->link_speed
== SPEED_1000
) &&
2622 (!e1e_rphy(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
2623 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
2624 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
2628 /* Management Stats */
2629 adapter
->stats
.mgptc
+= er32(MGTPTC
);
2630 adapter
->stats
.mgprc
+= er32(MGTPRC
);
2631 adapter
->stats
.mgpdc
+= er32(MGTPDC
);
2633 spin_unlock_irqrestore(&adapter
->stats_lock
, irq_flags
);
2636 static void e1000_print_link_info(struct e1000_adapter
*adapter
)
2638 struct e1000_hw
*hw
= &adapter
->hw
;
2639 struct net_device
*netdev
= adapter
->netdev
;
2640 u32 ctrl
= er32(CTRL
);
2643 "Link is Up %d Mbps %s, Flow Control: %s\n",
2644 adapter
->link_speed
,
2645 (adapter
->link_duplex
== FULL_DUPLEX
) ?
2646 "Full Duplex" : "Half Duplex",
2647 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
& E1000_CTRL_RFCE
)) ?
2649 ((ctrl
& E1000_CTRL_RFCE
) ? "RX" :
2650 ((ctrl
& E1000_CTRL_TFCE
) ? "TX" : "None" )));
2653 static bool e1000_has_link(struct e1000_adapter
*adapter
)
2655 struct e1000_hw
*hw
= &adapter
->hw
;
2656 bool link_active
= 0;
2660 * get_link_status is set on LSC (link status) interrupt or
2661 * Rx sequence error interrupt. get_link_status will stay
2662 * false until the check_for_link establishes link
2663 * for copper adapters ONLY
2665 switch (hw
->phy
.media_type
) {
2666 case e1000_media_type_copper
:
2667 if (hw
->mac
.get_link_status
) {
2668 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
2669 link_active
= !hw
->mac
.get_link_status
;
2674 case e1000_media_type_fiber
:
2675 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
2676 link_active
= !!(er32(STATUS
) & E1000_STATUS_LU
);
2678 case e1000_media_type_internal_serdes
:
2679 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
2680 link_active
= adapter
->hw
.mac
.serdes_has_link
;
2683 case e1000_media_type_unknown
:
2687 if ((ret_val
== E1000_ERR_PHY
) && (hw
->phy
.type
== e1000_phy_igp_3
) &&
2688 (er32(CTRL
) & E1000_PHY_CTRL_GBE_DISABLE
)) {
2689 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
2690 ndev_info(adapter
->netdev
,
2691 "Gigabit has been disabled, downgrading speed\n");
2697 static void e1000e_enable_receives(struct e1000_adapter
*adapter
)
2699 /* make sure the receive unit is started */
2700 if ((adapter
->flags
& FLAG_RX_NEEDS_RESTART
) &&
2701 (adapter
->flags
& FLAG_RX_RESTART_NOW
)) {
2702 struct e1000_hw
*hw
= &adapter
->hw
;
2703 u32 rctl
= er32(RCTL
);
2704 ew32(RCTL
, rctl
| E1000_RCTL_EN
);
2705 adapter
->flags
&= ~FLAG_RX_RESTART_NOW
;
2710 * e1000_watchdog - Timer Call-back
2711 * @data: pointer to adapter cast into an unsigned long
2713 static void e1000_watchdog(unsigned long data
)
2715 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2717 /* Do the rest outside of interrupt context */
2718 schedule_work(&adapter
->watchdog_task
);
2720 /* TODO: make this use queue_delayed_work() */
2723 static void e1000_watchdog_task(struct work_struct
*work
)
2725 struct e1000_adapter
*adapter
= container_of(work
,
2726 struct e1000_adapter
, watchdog_task
);
2727 struct net_device
*netdev
= adapter
->netdev
;
2728 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
2729 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2730 struct e1000_hw
*hw
= &adapter
->hw
;
2734 link
= e1000_has_link(adapter
);
2735 if ((netif_carrier_ok(netdev
)) && link
) {
2736 e1000e_enable_receives(adapter
);
2740 if ((e1000e_enable_tx_pkt_filtering(hw
)) &&
2741 (adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
))
2742 e1000_update_mng_vlan(adapter
);
2745 if (!netif_carrier_ok(netdev
)) {
2747 /* update snapshot of PHY registers on LSC */
2748 mac
->ops
.get_link_up_info(&adapter
->hw
,
2749 &adapter
->link_speed
,
2750 &adapter
->link_duplex
);
2751 e1000_print_link_info(adapter
);
2753 * tweak tx_queue_len according to speed/duplex
2754 * and adjust the timeout factor
2756 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2757 adapter
->tx_timeout_factor
= 1;
2758 switch (adapter
->link_speed
) {
2761 netdev
->tx_queue_len
= 10;
2762 adapter
->tx_timeout_factor
= 14;
2766 netdev
->tx_queue_len
= 100;
2767 /* maybe add some timeout factor ? */
2772 * workaround: re-program speed mode bit after
2775 if ((adapter
->flags
& FLAG_TARC_SPEED_MODE_BIT
) &&
2778 tarc0
= er32(TARC0
);
2779 tarc0
&= ~SPEED_MODE_BIT
;
2784 * disable TSO for pcie and 10/100 speeds, to avoid
2785 * some hardware issues
2787 if (!(adapter
->flags
& FLAG_TSO_FORCE
)) {
2788 switch (adapter
->link_speed
) {
2792 "10/100 speed: disabling TSO\n");
2793 netdev
->features
&= ~NETIF_F_TSO
;
2794 netdev
->features
&= ~NETIF_F_TSO6
;
2797 netdev
->features
|= NETIF_F_TSO
;
2798 netdev
->features
|= NETIF_F_TSO6
;
2807 * enable transmits in the hardware, need to do this
2808 * after setting TARC(0)
2811 tctl
|= E1000_TCTL_EN
;
2814 netif_carrier_on(netdev
);
2815 netif_wake_queue(netdev
);
2817 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2818 mod_timer(&adapter
->phy_info_timer
,
2819 round_jiffies(jiffies
+ 2 * HZ
));
2822 if (netif_carrier_ok(netdev
)) {
2823 adapter
->link_speed
= 0;
2824 adapter
->link_duplex
= 0;
2825 ndev_info(netdev
, "Link is Down\n");
2826 netif_carrier_off(netdev
);
2827 netif_stop_queue(netdev
);
2828 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2829 mod_timer(&adapter
->phy_info_timer
,
2830 round_jiffies(jiffies
+ 2 * HZ
));
2832 if (adapter
->flags
& FLAG_RX_NEEDS_RESTART
)
2833 schedule_work(&adapter
->reset_task
);
2838 e1000e_update_stats(adapter
);
2840 mac
->tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2841 adapter
->tpt_old
= adapter
->stats
.tpt
;
2842 mac
->collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2843 adapter
->colc_old
= adapter
->stats
.colc
;
2845 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2846 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2847 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2848 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2850 e1000e_update_adaptive(&adapter
->hw
);
2852 if (!netif_carrier_ok(netdev
)) {
2853 tx_pending
= (e1000_desc_unused(tx_ring
) + 1 <
2857 * We've lost link, so the controller stops DMA,
2858 * but we've got queued Tx work that's never going
2859 * to get done, so reset controller to flush Tx.
2860 * (Do the reset outside of interrupt context).
2862 adapter
->tx_timeout_count
++;
2863 schedule_work(&adapter
->reset_task
);
2867 /* Cause software interrupt to ensure Rx ring is cleaned */
2868 ew32(ICS
, E1000_ICS_RXDMT0
);
2870 /* Force detection of hung controller every watchdog period */
2871 adapter
->detect_tx_hung
= 1;
2874 * With 82571 controllers, LAA may be overwritten due to controller
2875 * reset from the other port. Set the appropriate LAA in RAR[0]
2877 if (e1000e_get_laa_state_82571(hw
))
2878 e1000e_rar_set(hw
, adapter
->hw
.mac
.addr
, 0);
2880 /* Reset the timer */
2881 if (!test_bit(__E1000_DOWN
, &adapter
->state
))
2882 mod_timer(&adapter
->watchdog_timer
,
2883 round_jiffies(jiffies
+ 2 * HZ
));
2886 #define E1000_TX_FLAGS_CSUM 0x00000001
2887 #define E1000_TX_FLAGS_VLAN 0x00000002
2888 #define E1000_TX_FLAGS_TSO 0x00000004
2889 #define E1000_TX_FLAGS_IPV4 0x00000008
2890 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2891 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2893 static int e1000_tso(struct e1000_adapter
*adapter
,
2894 struct sk_buff
*skb
)
2896 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2897 struct e1000_context_desc
*context_desc
;
2898 struct e1000_buffer
*buffer_info
;
2901 u16 ipcse
= 0, tucse
, mss
;
2902 u8 ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2905 if (skb_is_gso(skb
)) {
2906 if (skb_header_cloned(skb
)) {
2907 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2912 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2913 mss
= skb_shinfo(skb
)->gso_size
;
2914 if (skb
->protocol
== htons(ETH_P_IP
)) {
2915 struct iphdr
*iph
= ip_hdr(skb
);
2918 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2922 cmd_length
= E1000_TXD_CMD_IP
;
2923 ipcse
= skb_transport_offset(skb
) - 1;
2924 } else if (skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
) {
2925 ipv6_hdr(skb
)->payload_len
= 0;
2926 tcp_hdr(skb
)->check
=
2927 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2928 &ipv6_hdr(skb
)->daddr
,
2932 ipcss
= skb_network_offset(skb
);
2933 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
2934 tucss
= skb_transport_offset(skb
);
2935 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
2938 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2939 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2941 i
= tx_ring
->next_to_use
;
2942 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2943 buffer_info
= &tx_ring
->buffer_info
[i
];
2945 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2946 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2947 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2948 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2949 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2950 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2951 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2952 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2953 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2955 buffer_info
->time_stamp
= jiffies
;
2956 buffer_info
->next_to_watch
= i
;
2959 if (i
== tx_ring
->count
)
2961 tx_ring
->next_to_use
= i
;
2969 static bool e1000_tx_csum(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2971 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
2972 struct e1000_context_desc
*context_desc
;
2973 struct e1000_buffer
*buffer_info
;
2977 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2978 css
= skb_transport_offset(skb
);
2980 i
= tx_ring
->next_to_use
;
2981 buffer_info
= &tx_ring
->buffer_info
[i
];
2982 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2984 context_desc
->lower_setup
.ip_config
= 0;
2985 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2986 context_desc
->upper_setup
.tcp_fields
.tucso
=
2987 css
+ skb
->csum_offset
;
2988 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2989 context_desc
->tcp_seg_setup
.data
= 0;
2990 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
2992 buffer_info
->time_stamp
= jiffies
;
2993 buffer_info
->next_to_watch
= i
;
2996 if (i
== tx_ring
->count
)
2998 tx_ring
->next_to_use
= i
;
3006 #define E1000_MAX_PER_TXD 8192
3007 #define E1000_MAX_TXD_PWR 12
3009 static int e1000_tx_map(struct e1000_adapter
*adapter
,
3010 struct sk_buff
*skb
, unsigned int first
,
3011 unsigned int max_per_txd
, unsigned int nr_frags
,
3014 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3015 struct e1000_buffer
*buffer_info
;
3016 unsigned int len
= skb
->len
- skb
->data_len
;
3017 unsigned int offset
= 0, size
, count
= 0, i
;
3020 i
= tx_ring
->next_to_use
;
3023 buffer_info
= &tx_ring
->buffer_info
[i
];
3024 size
= min(len
, max_per_txd
);
3026 /* Workaround for premature desc write-backs
3027 * in TSO mode. Append 4-byte sentinel desc */
3028 if (mss
&& !nr_frags
&& size
== len
&& size
> 8)
3031 buffer_info
->length
= size
;
3032 /* set time_stamp *before* dma to help avoid a possible race */
3033 buffer_info
->time_stamp
= jiffies
;
3035 pci_map_single(adapter
->pdev
,
3039 if (pci_dma_mapping_error(buffer_info
->dma
)) {
3040 dev_err(&adapter
->pdev
->dev
, "TX DMA map failed\n");
3041 adapter
->tx_dma_failed
++;
3044 buffer_info
->next_to_watch
= i
;
3050 if (i
== tx_ring
->count
)
3054 for (f
= 0; f
< nr_frags
; f
++) {
3055 struct skb_frag_struct
*frag
;
3057 frag
= &skb_shinfo(skb
)->frags
[f
];
3059 offset
= frag
->page_offset
;
3062 buffer_info
= &tx_ring
->buffer_info
[i
];
3063 size
= min(len
, max_per_txd
);
3064 /* Workaround for premature desc write-backs
3065 * in TSO mode. Append 4-byte sentinel desc */
3066 if (mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8)
3069 buffer_info
->length
= size
;
3070 buffer_info
->time_stamp
= jiffies
;
3072 pci_map_page(adapter
->pdev
,
3077 if (pci_dma_mapping_error(buffer_info
->dma
)) {
3078 dev_err(&adapter
->pdev
->dev
,
3079 "TX DMA page map failed\n");
3080 adapter
->tx_dma_failed
++;
3084 buffer_info
->next_to_watch
= i
;
3091 if (i
== tx_ring
->count
)
3097 i
= tx_ring
->count
- 1;
3101 tx_ring
->buffer_info
[i
].skb
= skb
;
3102 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
3107 static void e1000_tx_queue(struct e1000_adapter
*adapter
,
3108 int tx_flags
, int count
)
3110 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3111 struct e1000_tx_desc
*tx_desc
= NULL
;
3112 struct e1000_buffer
*buffer_info
;
3113 u32 txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
3116 if (tx_flags
& E1000_TX_FLAGS_TSO
) {
3117 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
3119 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3121 if (tx_flags
& E1000_TX_FLAGS_IPV4
)
3122 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
3125 if (tx_flags
& E1000_TX_FLAGS_CSUM
) {
3126 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
3127 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3130 if (tx_flags
& E1000_TX_FLAGS_VLAN
) {
3131 txd_lower
|= E1000_TXD_CMD_VLE
;
3132 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
3135 i
= tx_ring
->next_to_use
;
3138 buffer_info
= &tx_ring
->buffer_info
[i
];
3139 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3140 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3141 tx_desc
->lower
.data
=
3142 cpu_to_le32(txd_lower
| buffer_info
->length
);
3143 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
3146 if (i
== tx_ring
->count
)
3150 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
3153 * Force memory writes to complete before letting h/w
3154 * know there are new descriptors to fetch. (Only
3155 * applicable for weak-ordered memory model archs,
3160 tx_ring
->next_to_use
= i
;
3161 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3163 * we need this if more than one processor can write to our tail
3164 * at a time, it synchronizes IO on IA64/Altix systems
3169 #define MINIMUM_DHCP_PACKET_SIZE 282
3170 static int e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
,
3171 struct sk_buff
*skb
)
3173 struct e1000_hw
*hw
= &adapter
->hw
;
3176 if (vlan_tx_tag_present(skb
)) {
3177 if (!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
)
3178 && (adapter
->hw
.mng_cookie
.status
&
3179 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
)))
3183 if (skb
->len
<= MINIMUM_DHCP_PACKET_SIZE
)
3186 if (((struct ethhdr
*) skb
->data
)->h_proto
!= htons(ETH_P_IP
))
3190 const struct iphdr
*ip
= (struct iphdr
*)((u8
*)skb
->data
+14);
3193 if (ip
->protocol
!= IPPROTO_UDP
)
3196 udp
= (struct udphdr
*)((u8
*)ip
+ (ip
->ihl
<< 2));
3197 if (ntohs(udp
->dest
) != 67)
3200 offset
= (u8
*)udp
+ 8 - skb
->data
;
3201 length
= skb
->len
- offset
;
3202 return e1000e_mng_write_dhcp_info(hw
, (u8
*)udp
+ 8, length
);
3208 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
3210 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3212 netif_stop_queue(netdev
);
3214 * Herbert's original patch had:
3215 * smp_mb__after_netif_stop_queue();
3216 * but since that doesn't exist yet, just open code it.
3221 * We need to check again in a case another CPU has just
3222 * made room available.
3224 if (e1000_desc_unused(adapter
->tx_ring
) < size
)
3228 netif_start_queue(netdev
);
3229 ++adapter
->restart_queue
;
3233 static int e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
3235 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3237 if (e1000_desc_unused(adapter
->tx_ring
) >= size
)
3239 return __e1000_maybe_stop_tx(netdev
, size
);
3242 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3243 static int e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
3245 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3246 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
3248 unsigned int max_per_txd
= E1000_MAX_PER_TXD
;
3249 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
3250 unsigned int tx_flags
= 0;
3251 unsigned int len
= skb
->len
- skb
->data_len
;
3252 unsigned long irq_flags
;
3253 unsigned int nr_frags
;
3259 if (test_bit(__E1000_DOWN
, &adapter
->state
)) {
3260 dev_kfree_skb_any(skb
);
3261 return NETDEV_TX_OK
;
3264 if (skb
->len
<= 0) {
3265 dev_kfree_skb_any(skb
);
3266 return NETDEV_TX_OK
;
3269 mss
= skb_shinfo(skb
)->gso_size
;
3271 * The controller does a simple calculation to
3272 * make sure there is enough room in the FIFO before
3273 * initiating the DMA for each buffer. The calc is:
3274 * 4 = ceil(buffer len/mss). To make sure we don't
3275 * overrun the FIFO, adjust the max buffer len if mss
3280 max_per_txd
= min(mss
<< 2, max_per_txd
);
3281 max_txd_pwr
= fls(max_per_txd
) - 1;
3284 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
3285 * points to just header, pull a few bytes of payload from
3286 * frags into skb->data
3288 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
3290 * we do this workaround for ES2LAN, but it is un-necessary,
3291 * avoiding it could save a lot of cycles
3293 if (skb
->data_len
&& (hdr_len
== len
)) {
3294 unsigned int pull_size
;
3296 pull_size
= min((unsigned int)4, skb
->data_len
);
3297 if (!__pskb_pull_tail(skb
, pull_size
)) {
3299 "__pskb_pull_tail failed.\n");
3300 dev_kfree_skb_any(skb
);
3301 return NETDEV_TX_OK
;
3303 len
= skb
->len
- skb
->data_len
;
3307 /* reserve a descriptor for the offload context */
3308 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3312 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
3314 nr_frags
= skb_shinfo(skb
)->nr_frags
;
3315 for (f
= 0; f
< nr_frags
; f
++)
3316 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
3319 if (adapter
->hw
.mac
.tx_pkt_filtering
)
3320 e1000_transfer_dhcp_info(adapter
, skb
);
3322 if (!spin_trylock_irqsave(&adapter
->tx_queue_lock
, irq_flags
))
3323 /* Collision - tell upper layer to requeue */
3324 return NETDEV_TX_LOCKED
;
3327 * need: count + 2 desc gap to keep tail from touching
3328 * head, otherwise try next time
3330 if (e1000_maybe_stop_tx(netdev
, count
+ 2)) {
3331 spin_unlock_irqrestore(&adapter
->tx_queue_lock
, irq_flags
);
3332 return NETDEV_TX_BUSY
;
3335 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
3336 tx_flags
|= E1000_TX_FLAGS_VLAN
;
3337 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
3340 first
= tx_ring
->next_to_use
;
3342 tso
= e1000_tso(adapter
, skb
);
3344 dev_kfree_skb_any(skb
);
3345 spin_unlock_irqrestore(&adapter
->tx_queue_lock
, irq_flags
);
3346 return NETDEV_TX_OK
;
3350 tx_flags
|= E1000_TX_FLAGS_TSO
;
3351 else if (e1000_tx_csum(adapter
, skb
))
3352 tx_flags
|= E1000_TX_FLAGS_CSUM
;
3355 * Old method was to assume IPv4 packet by default if TSO was enabled.
3356 * 82571 hardware supports TSO capabilities for IPv6 as well...
3357 * no longer assume, we must.
3359 if (skb
->protocol
== htons(ETH_P_IP
))
3360 tx_flags
|= E1000_TX_FLAGS_IPV4
;
3362 count
= e1000_tx_map(adapter
, skb
, first
, max_per_txd
, nr_frags
, mss
);
3364 /* handle pci_map_single() error in e1000_tx_map */
3365 dev_kfree_skb_any(skb
);
3366 spin_unlock_irqrestore(&adapter
->tx_queue_lock
, irq_flags
);
3367 return NETDEV_TX_OK
;
3370 e1000_tx_queue(adapter
, tx_flags
, count
);
3372 netdev
->trans_start
= jiffies
;
3374 /* Make sure there is space in the ring for the next send. */
3375 e1000_maybe_stop_tx(netdev
, MAX_SKB_FRAGS
+ 2);
3377 spin_unlock_irqrestore(&adapter
->tx_queue_lock
, irq_flags
);
3378 return NETDEV_TX_OK
;
3382 * e1000_tx_timeout - Respond to a Tx Hang
3383 * @netdev: network interface device structure
3385 static void e1000_tx_timeout(struct net_device
*netdev
)
3387 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3389 /* Do the reset outside of interrupt context */
3390 adapter
->tx_timeout_count
++;
3391 schedule_work(&adapter
->reset_task
);
3394 static void e1000_reset_task(struct work_struct
*work
)
3396 struct e1000_adapter
*adapter
;
3397 adapter
= container_of(work
, struct e1000_adapter
, reset_task
);
3399 e1000e_reinit_locked(adapter
);
3403 * e1000_get_stats - Get System Network Statistics
3404 * @netdev: network interface device structure
3406 * Returns the address of the device statistics structure.
3407 * The statistics are actually updated from the timer callback.
3409 static struct net_device_stats
*e1000_get_stats(struct net_device
*netdev
)
3411 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3413 /* only return the current stats */
3414 return &adapter
->net_stats
;
3418 * e1000_change_mtu - Change the Maximum Transfer Unit
3419 * @netdev: network interface device structure
3420 * @new_mtu: new value for maximum frame size
3422 * Returns 0 on success, negative on failure
3424 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3426 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3427 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3429 if ((max_frame
< ETH_ZLEN
+ ETH_FCS_LEN
) ||
3430 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3431 ndev_err(netdev
, "Invalid MTU setting\n");
3435 /* Jumbo frame size limits */
3436 if (max_frame
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
3437 if (!(adapter
->flags
& FLAG_HAS_JUMBO_FRAMES
)) {
3438 ndev_err(netdev
, "Jumbo Frames not supported.\n");
3441 if (adapter
->hw
.phy
.type
== e1000_phy_ife
) {
3442 ndev_err(netdev
, "Jumbo Frames not supported.\n");
3447 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3448 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3449 ndev_err(netdev
, "MTU > 9216 not supported.\n");
3453 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
3455 /* e1000e_down has a dependency on max_frame_size */
3456 adapter
->max_frame_size
= max_frame
;
3457 if (netif_running(netdev
))
3458 e1000e_down(adapter
);
3461 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3462 * means we reserve 2 more, this pushes us to allocate from the next
3464 * i.e. RXBUFFER_2048 --> size-4096 slab
3467 if (max_frame
<= 256)
3468 adapter
->rx_buffer_len
= 256;
3469 else if (max_frame
<= 512)
3470 adapter
->rx_buffer_len
= 512;
3471 else if (max_frame
<= 1024)
3472 adapter
->rx_buffer_len
= 1024;
3473 else if (max_frame
<= 2048)
3474 adapter
->rx_buffer_len
= 2048;
3476 adapter
->rx_buffer_len
= 4096;
3478 /* adjust allocation if LPE protects us, and we aren't using SBP */
3479 if ((max_frame
== ETH_FRAME_LEN
+ ETH_FCS_LEN
) ||
3480 (max_frame
== ETH_FRAME_LEN
+ VLAN_HLEN
+ ETH_FCS_LEN
))
3481 adapter
->rx_buffer_len
= ETH_FRAME_LEN
+ VLAN_HLEN
3484 ndev_info(netdev
, "changing MTU from %d to %d\n",
3485 netdev
->mtu
, new_mtu
);
3486 netdev
->mtu
= new_mtu
;
3488 if (netif_running(netdev
))
3491 e1000e_reset(adapter
);
3493 clear_bit(__E1000_RESETTING
, &adapter
->state
);
3498 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
3501 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3502 struct mii_ioctl_data
*data
= if_mii(ifr
);
3503 unsigned long irq_flags
;
3505 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
3510 data
->phy_id
= adapter
->hw
.phy
.addr
;
3513 if (!capable(CAP_NET_ADMIN
))
3515 spin_lock_irqsave(&adapter
->stats_lock
, irq_flags
);
3516 if (e1e_rphy(&adapter
->hw
, data
->reg_num
& 0x1F,
3518 spin_unlock_irqrestore(&adapter
->stats_lock
, irq_flags
);
3521 spin_unlock_irqrestore(&adapter
->stats_lock
, irq_flags
);
3530 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
3536 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
3542 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3544 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3545 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3546 struct e1000_hw
*hw
= &adapter
->hw
;
3547 u32 ctrl
, ctrl_ext
, rctl
, status
;
3548 u32 wufc
= adapter
->wol
;
3551 netif_device_detach(netdev
);
3553 if (netif_running(netdev
)) {
3554 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->state
));
3555 e1000e_down(adapter
);
3556 e1000_free_irq(adapter
);
3559 retval
= pci_save_state(pdev
);
3563 status
= er32(STATUS
);
3564 if (status
& E1000_STATUS_LU
)
3565 wufc
&= ~E1000_WUFC_LNKC
;
3568 e1000_setup_rctl(adapter
);
3569 e1000_set_multi(netdev
);
3571 /* turn on all-multi mode if wake on multicast is enabled */
3572 if (wufc
& E1000_WUFC_MC
) {
3574 rctl
|= E1000_RCTL_MPE
;
3579 /* advertise wake from D3Cold */
3580 #define E1000_CTRL_ADVD3WUC 0x00100000
3581 /* phy power management enable */
3582 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3583 ctrl
|= E1000_CTRL_ADVD3WUC
|
3584 E1000_CTRL_EN_PHY_PWR_MGMT
;
3587 if (adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
||
3588 adapter
->hw
.phy
.media_type
==
3589 e1000_media_type_internal_serdes
) {
3590 /* keep the laser running in D3 */
3591 ctrl_ext
= er32(CTRL_EXT
);
3592 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
3593 ew32(CTRL_EXT
, ctrl_ext
);
3596 /* Allow time for pending master requests to run */
3597 e1000e_disable_pcie_master(&adapter
->hw
);
3599 ew32(WUC
, E1000_WUC_PME_EN
);
3601 pci_enable_wake(pdev
, PCI_D3hot
, 1);
3602 pci_enable_wake(pdev
, PCI_D3cold
, 1);
3606 pci_enable_wake(pdev
, PCI_D3hot
, 0);
3607 pci_enable_wake(pdev
, PCI_D3cold
, 0);
3610 /* make sure adapter isn't asleep if manageability is enabled */
3611 if (adapter
->flags
& FLAG_MNG_PT_ENABLED
) {
3612 pci_enable_wake(pdev
, PCI_D3hot
, 1);
3613 pci_enable_wake(pdev
, PCI_D3cold
, 1);
3616 if (adapter
->hw
.phy
.type
== e1000_phy_igp_3
)
3617 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter
->hw
);
3620 * Release control of h/w to f/w. If f/w is AMT enabled, this
3621 * would have already happened in close and is redundant.
3623 e1000_release_hw_control(adapter
);
3625 pci_disable_device(pdev
);
3627 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
3632 static void e1000e_disable_l1aspm(struct pci_dev
*pdev
)
3638 * 82573 workaround - disable L1 ASPM on mobile chipsets
3640 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
3641 * resulting in lost data or garbage information on the pci-e link
3642 * level. This could result in (false) bad EEPROM checksum errors,
3643 * long ping times (up to 2s) or even a system freeze/hang.
3645 * Unfortunately this feature saves about 1W power consumption when
3648 pos
= pci_find_capability(pdev
, PCI_CAP_ID_EXP
);
3649 pci_read_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, &val
);
3651 dev_warn(&pdev
->dev
, "Disabling L1 ASPM\n");
3653 pci_write_config_word(pdev
, pos
+ PCI_EXP_LNKCTL
, val
);
3658 static int e1000_resume(struct pci_dev
*pdev
)
3660 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3661 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3662 struct e1000_hw
*hw
= &adapter
->hw
;
3665 pci_set_power_state(pdev
, PCI_D0
);
3666 pci_restore_state(pdev
);
3667 e1000e_disable_l1aspm(pdev
);
3668 err
= pci_enable_device(pdev
);
3671 "Cannot enable PCI device from suspend\n");
3675 pci_set_master(pdev
);
3677 pci_enable_wake(pdev
, PCI_D3hot
, 0);
3678 pci_enable_wake(pdev
, PCI_D3cold
, 0);
3680 if (netif_running(netdev
)) {
3681 err
= e1000_request_irq(adapter
);
3686 e1000e_power_up_phy(adapter
);
3687 e1000e_reset(adapter
);
3690 e1000_init_manageability(adapter
);
3692 if (netif_running(netdev
))
3695 netif_device_attach(netdev
);
3698 * If the controller has AMT, do not set DRV_LOAD until the interface
3699 * is up. For all other cases, let the f/w know that the h/w is now
3700 * under the control of the driver.
3702 if (!(adapter
->flags
& FLAG_HAS_AMT
) || !e1000e_check_mng_mode(&adapter
->hw
))
3703 e1000_get_hw_control(adapter
);
3709 static void e1000_shutdown(struct pci_dev
*pdev
)
3711 e1000_suspend(pdev
, PMSG_SUSPEND
);
3714 #ifdef CONFIG_NET_POLL_CONTROLLER
3716 * Polling 'interrupt' - used by things like netconsole to send skbs
3717 * without having to re-enable interrupts. It's not called while
3718 * the interrupt routine is executing.
3720 static void e1000_netpoll(struct net_device
*netdev
)
3722 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3724 disable_irq(adapter
->pdev
->irq
);
3725 e1000_intr(adapter
->pdev
->irq
, netdev
);
3727 e1000_clean_tx_irq(adapter
);
3729 enable_irq(adapter
->pdev
->irq
);
3734 * e1000_io_error_detected - called when PCI error is detected
3735 * @pdev: Pointer to PCI device
3736 * @state: The current pci connection state
3738 * This function is called after a PCI bus error affecting
3739 * this device has been detected.
3741 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
3742 pci_channel_state_t state
)
3744 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3745 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3747 netif_device_detach(netdev
);
3749 if (netif_running(netdev
))
3750 e1000e_down(adapter
);
3751 pci_disable_device(pdev
);
3753 /* Request a slot slot reset. */
3754 return PCI_ERS_RESULT_NEED_RESET
;
3758 * e1000_io_slot_reset - called after the pci bus has been reset.
3759 * @pdev: Pointer to PCI device
3761 * Restart the card from scratch, as if from a cold-boot. Implementation
3762 * resembles the first-half of the e1000_resume routine.
3764 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
3766 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3767 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3768 struct e1000_hw
*hw
= &adapter
->hw
;
3770 e1000e_disable_l1aspm(pdev
);
3771 if (pci_enable_device(pdev
)) {
3773 "Cannot re-enable PCI device after reset.\n");
3774 return PCI_ERS_RESULT_DISCONNECT
;
3776 pci_set_master(pdev
);
3778 pci_enable_wake(pdev
, PCI_D3hot
, 0);
3779 pci_enable_wake(pdev
, PCI_D3cold
, 0);
3781 e1000e_reset(adapter
);
3784 return PCI_ERS_RESULT_RECOVERED
;
3788 * e1000_io_resume - called when traffic can start flowing again.
3789 * @pdev: Pointer to PCI device
3791 * This callback is called when the error recovery driver tells us that
3792 * its OK to resume normal operation. Implementation resembles the
3793 * second-half of the e1000_resume routine.
3795 static void e1000_io_resume(struct pci_dev
*pdev
)
3797 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3798 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3800 e1000_init_manageability(adapter
);
3802 if (netif_running(netdev
)) {
3803 if (e1000e_up(adapter
)) {
3805 "can't bring device back up after reset\n");
3810 netif_device_attach(netdev
);
3813 * If the controller has AMT, do not set DRV_LOAD until the interface
3814 * is up. For all other cases, let the f/w know that the h/w is now
3815 * under the control of the driver.
3817 if (!(adapter
->flags
& FLAG_HAS_AMT
) ||
3818 !e1000e_check_mng_mode(&adapter
->hw
))
3819 e1000_get_hw_control(adapter
);
3823 static void e1000_print_device_info(struct e1000_adapter
*adapter
)
3825 struct e1000_hw
*hw
= &adapter
->hw
;
3826 struct net_device
*netdev
= adapter
->netdev
;
3829 /* print bus type/speed/width info */
3830 ndev_info(netdev
, "(PCI Express:2.5GB/s:%s) "
3831 "%02x:%02x:%02x:%02x:%02x:%02x\n",
3833 ((hw
->bus
.width
== e1000_bus_width_pcie_x4
) ? "Width x4" :
3836 netdev
->dev_addr
[0], netdev
->dev_addr
[1],
3837 netdev
->dev_addr
[2], netdev
->dev_addr
[3],
3838 netdev
->dev_addr
[4], netdev
->dev_addr
[5]);
3839 ndev_info(netdev
, "Intel(R) PRO/%s Network Connection\n",
3840 (hw
->phy
.type
== e1000_phy_ife
)
3841 ? "10/100" : "1000");
3842 e1000e_read_part_num(hw
, &part_num
);
3843 ndev_info(netdev
, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
3844 hw
->mac
.type
, hw
->phy
.type
,
3845 (part_num
>> 8), (part_num
& 0xff));
3849 * e1000_probe - Device Initialization Routine
3850 * @pdev: PCI device information struct
3851 * @ent: entry in e1000_pci_tbl
3853 * Returns 0 on success, negative on failure
3855 * e1000_probe initializes an adapter identified by a pci_dev structure.
3856 * The OS initialization, configuring of the adapter private structure,
3857 * and a hardware reset occur.
3859 static int __devinit
e1000_probe(struct pci_dev
*pdev
,
3860 const struct pci_device_id
*ent
)
3862 struct net_device
*netdev
;
3863 struct e1000_adapter
*adapter
;
3864 struct e1000_hw
*hw
;
3865 const struct e1000_info
*ei
= e1000_info_tbl
[ent
->driver_data
];
3866 unsigned long mmio_start
, mmio_len
;
3867 unsigned long flash_start
, flash_len
;
3869 static int cards_found
;
3870 int i
, err
, pci_using_dac
;
3871 u16 eeprom_data
= 0;
3872 u16 eeprom_apme_mask
= E1000_EEPROM_APME
;
3874 e1000e_disable_l1aspm(pdev
);
3875 err
= pci_enable_device(pdev
);
3880 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
3882 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
3886 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
3888 err
= pci_set_consistent_dma_mask(pdev
,
3891 dev_err(&pdev
->dev
, "No usable DMA "
3892 "configuration, aborting\n");
3898 err
= pci_request_regions(pdev
, e1000e_driver_name
);
3902 pci_set_master(pdev
);
3905 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
3907 goto err_alloc_etherdev
;
3909 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3911 pci_set_drvdata(pdev
, netdev
);
3912 adapter
= netdev_priv(netdev
);
3914 adapter
->netdev
= netdev
;
3915 adapter
->pdev
= pdev
;
3917 adapter
->pba
= ei
->pba
;
3918 adapter
->flags
= ei
->flags
;
3919 adapter
->hw
.adapter
= adapter
;
3920 adapter
->hw
.mac
.type
= ei
->mac
;
3921 adapter
->msg_enable
= (1 << NETIF_MSG_DRV
| NETIF_MSG_PROBE
) - 1;
3923 mmio_start
= pci_resource_start(pdev
, 0);
3924 mmio_len
= pci_resource_len(pdev
, 0);
3927 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
3928 if (!adapter
->hw
.hw_addr
)
3931 if ((adapter
->flags
& FLAG_HAS_FLASH
) &&
3932 (pci_resource_flags(pdev
, 1) & IORESOURCE_MEM
)) {
3933 flash_start
= pci_resource_start(pdev
, 1);
3934 flash_len
= pci_resource_len(pdev
, 1);
3935 adapter
->hw
.flash_address
= ioremap(flash_start
, flash_len
);
3936 if (!adapter
->hw
.flash_address
)
3940 /* construct the net_device struct */
3941 netdev
->open
= &e1000_open
;
3942 netdev
->stop
= &e1000_close
;
3943 netdev
->hard_start_xmit
= &e1000_xmit_frame
;
3944 netdev
->get_stats
= &e1000_get_stats
;
3945 netdev
->set_multicast_list
= &e1000_set_multi
;
3946 netdev
->set_mac_address
= &e1000_set_mac
;
3947 netdev
->change_mtu
= &e1000_change_mtu
;
3948 netdev
->do_ioctl
= &e1000_ioctl
;
3949 e1000e_set_ethtool_ops(netdev
);
3950 netdev
->tx_timeout
= &e1000_tx_timeout
;
3951 netdev
->watchdog_timeo
= 5 * HZ
;
3952 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
3953 netdev
->vlan_rx_register
= e1000_vlan_rx_register
;
3954 netdev
->vlan_rx_add_vid
= e1000_vlan_rx_add_vid
;
3955 netdev
->vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
;
3956 #ifdef CONFIG_NET_POLL_CONTROLLER
3957 netdev
->poll_controller
= e1000_netpoll
;
3959 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
3961 netdev
->mem_start
= mmio_start
;
3962 netdev
->mem_end
= mmio_start
+ mmio_len
;
3964 adapter
->bd_number
= cards_found
++;
3966 /* setup adapter struct */
3967 err
= e1000_sw_init(adapter
);
3973 memcpy(&hw
->mac
.ops
, ei
->mac_ops
, sizeof(hw
->mac
.ops
));
3974 memcpy(&hw
->nvm
.ops
, ei
->nvm_ops
, sizeof(hw
->nvm
.ops
));
3975 memcpy(&hw
->phy
.ops
, ei
->phy_ops
, sizeof(hw
->phy
.ops
));
3977 err
= ei
->get_invariants(adapter
);
3981 hw
->mac
.ops
.get_bus_info(&adapter
->hw
);
3983 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
3985 /* Copper options */
3986 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
) {
3987 adapter
->hw
.phy
.mdix
= AUTO_ALL_MODES
;
3988 adapter
->hw
.phy
.disable_polarity_correction
= 0;
3989 adapter
->hw
.phy
.ms_type
= e1000_ms_hw_default
;
3992 if (e1000_check_reset_block(&adapter
->hw
))
3994 "PHY reset is blocked due to SOL/IDER session.\n");
3996 netdev
->features
= NETIF_F_SG
|
3998 NETIF_F_HW_VLAN_TX
|
4001 if (adapter
->flags
& FLAG_HAS_HW_VLAN_FILTER
)
4002 netdev
->features
|= NETIF_F_HW_VLAN_FILTER
;
4004 netdev
->features
|= NETIF_F_TSO
;
4005 netdev
->features
|= NETIF_F_TSO6
;
4008 netdev
->features
|= NETIF_F_HIGHDMA
;
4011 * We should not be using LLTX anymore, but we are still Tx faster with
4014 netdev
->features
|= NETIF_F_LLTX
;
4016 if (e1000e_enable_mng_pass_thru(&adapter
->hw
))
4017 adapter
->flags
|= FLAG_MNG_PT_ENABLED
;
4020 * before reading the NVM, reset the controller to
4021 * put the device in a known good starting state
4023 adapter
->hw
.mac
.ops
.reset_hw(&adapter
->hw
);
4026 * systems with ASPM and others may see the checksum fail on the first
4027 * attempt. Let's give it a few tries
4030 if (e1000_validate_nvm_checksum(&adapter
->hw
) >= 0)
4033 ndev_err(netdev
, "The NVM Checksum Is Not Valid\n");
4039 /* copy the MAC address out of the NVM */
4040 if (e1000e_read_mac_addr(&adapter
->hw
))
4041 ndev_err(netdev
, "NVM Read Error while reading MAC address\n");
4043 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
4044 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
4046 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
4047 ndev_err(netdev
, "Invalid MAC Address: "
4048 "%02x:%02x:%02x:%02x:%02x:%02x\n",
4049 netdev
->perm_addr
[0], netdev
->perm_addr
[1],
4050 netdev
->perm_addr
[2], netdev
->perm_addr
[3],
4051 netdev
->perm_addr
[4], netdev
->perm_addr
[5]);
4056 init_timer(&adapter
->watchdog_timer
);
4057 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
4058 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
4060 init_timer(&adapter
->phy_info_timer
);
4061 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
4062 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
4064 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
4065 INIT_WORK(&adapter
->watchdog_task
, e1000_watchdog_task
);
4067 e1000e_check_options(adapter
);
4069 /* Initialize link parameters. User can change them with ethtool */
4070 adapter
->hw
.mac
.autoneg
= 1;
4071 adapter
->fc_autoneg
= 1;
4072 adapter
->hw
.fc
.original_type
= e1000_fc_default
;
4073 adapter
->hw
.fc
.type
= e1000_fc_default
;
4074 adapter
->hw
.phy
.autoneg_advertised
= 0x2f;
4076 /* ring size defaults */
4077 adapter
->rx_ring
->count
= 256;
4078 adapter
->tx_ring
->count
= 256;
4081 * Initial Wake on LAN setting - If APM wake is enabled in
4082 * the EEPROM, enable the ACPI Magic Packet filter
4084 if (adapter
->flags
& FLAG_APME_IN_WUC
) {
4085 /* APME bit in EEPROM is mapped to WUC.APME */
4086 eeprom_data
= er32(WUC
);
4087 eeprom_apme_mask
= E1000_WUC_APME
;
4088 } else if (adapter
->flags
& FLAG_APME_IN_CTRL3
) {
4089 if (adapter
->flags
& FLAG_APME_CHECK_PORT_B
&&
4090 (adapter
->hw
.bus
.func
== 1))
4091 e1000_read_nvm(&adapter
->hw
,
4092 NVM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
4094 e1000_read_nvm(&adapter
->hw
,
4095 NVM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
4098 /* fetch WoL from EEPROM */
4099 if (eeprom_data
& eeprom_apme_mask
)
4100 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
4103 * now that we have the eeprom settings, apply the special cases
4104 * where the eeprom may be wrong or the board simply won't support
4105 * wake on lan on a particular port
4107 if (!(adapter
->flags
& FLAG_HAS_WOL
))
4108 adapter
->eeprom_wol
= 0;
4110 /* initialize the wol settings based on the eeprom settings */
4111 adapter
->wol
= adapter
->eeprom_wol
;
4113 /* reset the hardware with the new settings */
4114 e1000e_reset(adapter
);
4117 * If the controller has AMT, do not set DRV_LOAD until the interface
4118 * is up. For all other cases, let the f/w know that the h/w is now
4119 * under the control of the driver.
4121 if (!(adapter
->flags
& FLAG_HAS_AMT
) ||
4122 !e1000e_check_mng_mode(&adapter
->hw
))
4123 e1000_get_hw_control(adapter
);
4125 /* tell the stack to leave us alone until e1000_open() is called */
4126 netif_carrier_off(netdev
);
4127 netif_stop_queue(netdev
);
4129 strcpy(netdev
->name
, "eth%d");
4130 err
= register_netdev(netdev
);
4134 e1000_print_device_info(adapter
);
4140 e1000_release_hw_control(adapter
);
4142 if (!e1000_check_reset_block(&adapter
->hw
))
4143 e1000_phy_hw_reset(&adapter
->hw
);
4145 if (adapter
->hw
.flash_address
)
4146 iounmap(adapter
->hw
.flash_address
);
4149 kfree(adapter
->tx_ring
);
4150 kfree(adapter
->rx_ring
);
4152 iounmap(adapter
->hw
.hw_addr
);
4154 free_netdev(netdev
);
4156 pci_release_regions(pdev
);
4159 pci_disable_device(pdev
);
4164 * e1000_remove - Device Removal Routine
4165 * @pdev: PCI device information struct
4167 * e1000_remove is called by the PCI subsystem to alert the driver
4168 * that it should release a PCI device. The could be caused by a
4169 * Hot-Plug event, or because the driver is going to be removed from
4172 static void __devexit
e1000_remove(struct pci_dev
*pdev
)
4174 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4175 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4178 * flush_scheduled work may reschedule our watchdog task, so
4179 * explicitly disable watchdog tasks from being rescheduled
4181 set_bit(__E1000_DOWN
, &adapter
->state
);
4182 del_timer_sync(&adapter
->watchdog_timer
);
4183 del_timer_sync(&adapter
->phy_info_timer
);
4185 flush_scheduled_work();
4188 * Release control of h/w to f/w. If f/w is AMT enabled, this
4189 * would have already happened in close and is redundant.
4191 e1000_release_hw_control(adapter
);
4193 unregister_netdev(netdev
);
4195 if (!e1000_check_reset_block(&adapter
->hw
))
4196 e1000_phy_hw_reset(&adapter
->hw
);
4198 kfree(adapter
->tx_ring
);
4199 kfree(adapter
->rx_ring
);
4201 iounmap(adapter
->hw
.hw_addr
);
4202 if (adapter
->hw
.flash_address
)
4203 iounmap(adapter
->hw
.flash_address
);
4204 pci_release_regions(pdev
);
4206 free_netdev(netdev
);
4208 pci_disable_device(pdev
);
4211 /* PCI Error Recovery (ERS) */
4212 static struct pci_error_handlers e1000_err_handler
= {
4213 .error_detected
= e1000_io_error_detected
,
4214 .slot_reset
= e1000_io_slot_reset
,
4215 .resume
= e1000_io_resume
,
4218 static struct pci_device_id e1000_pci_tbl
[] = {
4219 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_COPPER
), board_82571
},
4220 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_FIBER
), board_82571
},
4221 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER
), board_82571
},
4222 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_COPPER_LP
), board_82571
},
4223 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_QUAD_FIBER
), board_82571
},
4224 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES
), board_82571
},
4225 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_DUAL
), board_82571
},
4226 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571EB_SERDES_QUAD
), board_82571
},
4227 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82571PT_QUAD_COPPER
), board_82571
},
4229 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI
), board_82572
},
4230 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_COPPER
), board_82572
},
4231 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_FIBER
), board_82572
},
4232 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82572EI_SERDES
), board_82572
},
4234 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E
), board_82573
},
4235 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573E_IAMT
), board_82573
},
4236 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82573L
), board_82573
},
4238 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_DPT
),
4239 board_80003es2lan
},
4240 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_COPPER_SPT
),
4241 board_80003es2lan
},
4242 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_DPT
),
4243 board_80003es2lan
},
4244 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_80003ES2LAN_SERDES_SPT
),
4245 board_80003es2lan
},
4247 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE
), board_ich8lan
},
4248 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_G
), board_ich8lan
},
4249 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IFE_GT
), board_ich8lan
},
4250 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_AMT
), board_ich8lan
},
4251 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_C
), board_ich8lan
},
4252 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M
), board_ich8lan
},
4253 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH8_IGP_M_AMT
), board_ich8lan
},
4255 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE
), board_ich9lan
},
4256 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_G
), board_ich9lan
},
4257 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IFE_GT
), board_ich9lan
},
4258 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_AMT
), board_ich9lan
},
4259 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_ICH9_IGP_C
), board_ich9lan
},
4261 { } /* terminate list */
4263 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
4265 /* PCI Device API Driver */
4266 static struct pci_driver e1000_driver
= {
4267 .name
= e1000e_driver_name
,
4268 .id_table
= e1000_pci_tbl
,
4269 .probe
= e1000_probe
,
4270 .remove
= __devexit_p(e1000_remove
),
4272 /* Power Management Hooks */
4273 .suspend
= e1000_suspend
,
4274 .resume
= e1000_resume
,
4276 .shutdown
= e1000_shutdown
,
4277 .err_handler
= &e1000_err_handler
4281 * e1000_init_module - Driver Registration Routine
4283 * e1000_init_module is the first routine called when the driver is
4284 * loaded. All it does is register with the PCI subsystem.
4286 static int __init
e1000_init_module(void)
4289 printk(KERN_INFO
"%s: Intel(R) PRO/1000 Network Driver - %s\n",
4290 e1000e_driver_name
, e1000e_driver_version
);
4291 printk(KERN_INFO
"%s: Copyright (c) 1999-2008 Intel Corporation.\n",
4292 e1000e_driver_name
);
4293 ret
= pci_register_driver(&e1000_driver
);
4297 module_init(e1000_init_module
);
4300 * e1000_exit_module - Driver Exit Cleanup Routine
4302 * e1000_exit_module is called just before the driver is removed
4305 static void __exit
e1000_exit_module(void)
4307 pci_unregister_driver(&e1000_driver
);
4309 module_exit(e1000_exit_module
);
4312 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
4313 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
4314 MODULE_LICENSE("GPL");
4315 MODULE_VERSION(DRV_VERSION
);