1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2007 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,
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;
141 /* IP fragment with UDP payload */
142 /* Hardware complements the payload checksum, so we undo it
143 * and then put the value in host order for further stack use.
145 csum = ntohl(csum ^ 0xFFFF);
147 skb->ip_summed = CHECKSUM_COMPLETE;
149 adapter->hw_csum_good++;
153 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
154 * @adapter: address of board private structure
156 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
159 struct net_device *netdev = adapter->netdev;
160 struct pci_dev *pdev = adapter->pdev;
161 struct e1000_ring *rx_ring = adapter->rx_ring;
162 struct e1000_rx_desc *rx_desc;
163 struct e1000_buffer *buffer_info;
166 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
168 i = rx_ring->next_to_use;
169 buffer_info = &rx_ring->buffer_info[i];
171 while (cleaned_count--) {
172 skb = buffer_info->skb;
178 skb = netdev_alloc_skb(netdev, bufsz);
180 /* Better luck next round */
181 adapter->alloc_rx_buff_failed++;
185 /* Make buffer alignment 2 beyond a 16 byte boundary
186 * this will result in a 16 byte aligned IP header after
187 * the 14 byte MAC header is removed
189 skb_reserve(skb, NET_IP_ALIGN);
191 buffer_info->skb = skb;
193 buffer_info->dma = pci_map_single(pdev, skb->data,
194 adapter->rx_buffer_len,
196 if (pci_dma_mapping_error(buffer_info->dma)) {
197 dev_err(&pdev->dev, "RX DMA map failed\n");
198 adapter->rx_dma_failed++;
202 rx_desc = E1000_RX_DESC(*rx_ring, i);
203 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
206 if (i == rx_ring->count)
208 buffer_info = &rx_ring->buffer_info[i];
211 if (rx_ring->next_to_use != i) {
212 rx_ring->next_to_use = i;
214 i = (rx_ring->count - 1);
216 /* Force memory writes to complete before letting h/w
217 * know there are new descriptors to fetch. (Only
218 * applicable for weak-ordered memory model archs,
221 writel(i, adapter->hw.hw_addr + rx_ring->tail);
226 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
227 * @adapter: address of board private structure
229 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
232 struct net_device *netdev = adapter->netdev;
233 struct pci_dev *pdev = adapter->pdev;
234 union e1000_rx_desc_packet_split *rx_desc;
235 struct e1000_ring *rx_ring = adapter->rx_ring;
236 struct e1000_buffer *buffer_info;
237 struct e1000_ps_page *ps_page;
241 i = rx_ring->next_to_use;
242 buffer_info = &rx_ring->buffer_info[i];
244 while (cleaned_count--) {
245 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
247 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
248 ps_page = &buffer_info->ps_pages[j];
249 if (j >= adapter->rx_ps_pages) {
250 /* all unused desc entries get hw null ptr */
251 rx_desc->read.buffer_addr[j+1] = ~0;
254 if (!ps_page->page) {
255 ps_page->page = alloc_page(GFP_ATOMIC);
256 if (!ps_page->page) {
257 adapter->alloc_rx_buff_failed++;
260 ps_page->dma = pci_map_page(pdev,
264 if (pci_dma_mapping_error(ps_page->dma)) {
265 dev_err(&adapter->pdev->dev,
266 "RX DMA page map failed\n");
267 adapter->rx_dma_failed++;
272 * Refresh the desc even if buffer_addrs
273 * didn't change because each write-back
276 rx_desc->read.buffer_addr[j+1] =
277 cpu_to_le64(ps_page->dma);
280 skb = netdev_alloc_skb(netdev,
281 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
284 adapter->alloc_rx_buff_failed++;
288 /* Make buffer alignment 2 beyond a 16 byte boundary
289 * this will result in a 16 byte aligned IP header after
290 * the 14 byte MAC header is removed
292 skb_reserve(skb, NET_IP_ALIGN);
294 buffer_info->skb = skb;
295 buffer_info->dma = pci_map_single(pdev, skb->data,
296 adapter->rx_ps_bsize0,
298 if (pci_dma_mapping_error(buffer_info->dma)) {
299 dev_err(&pdev->dev, "RX DMA map failed\n");
300 adapter->rx_dma_failed++;
302 dev_kfree_skb_any(skb);
303 buffer_info->skb = NULL;
307 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
310 if (i == rx_ring->count)
312 buffer_info = &rx_ring->buffer_info[i];
316 if (rx_ring->next_to_use != i) {
317 rx_ring->next_to_use = i;
320 i = (rx_ring->count - 1);
322 /* Force memory writes to complete before letting h/w
323 * know there are new descriptors to fetch. (Only
324 * applicable for weak-ordered memory model archs,
327 /* Hardware increments by 16 bytes, but packet split
328 * descriptors are 32 bytes...so we increment tail
331 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
336 * e1000_alloc_rx_buffers_jumbo - Replace used jumbo receive buffers
338 * @adapter: address of board private structure
339 * @cleaned_count: number of buffers to allocate this pass
341 static void e1000_alloc_rx_buffers_jumbo(struct e1000_adapter *adapter,
344 struct net_device *netdev = adapter->netdev;
345 struct pci_dev *pdev = adapter->pdev;
346 struct e1000_ring *rx_ring = adapter->rx_ring;
347 struct e1000_rx_desc *rx_desc;
348 struct e1000_buffer *buffer_info;
351 unsigned int bufsz = 256 -
352 16 /*for skb_reserve */ -
355 i = rx_ring->next_to_use;
356 buffer_info = &rx_ring->buffer_info[i];
358 while (cleaned_count--) {
359 skb = buffer_info->skb;
365 skb = netdev_alloc_skb(netdev, bufsz);
367 /* Better luck next round */
368 adapter->alloc_rx_buff_failed++;
372 /* Make buffer alignment 2 beyond a 16 byte boundary
373 * this will result in a 16 byte aligned IP header after
374 * the 14 byte MAC header is removed
376 skb_reserve(skb, NET_IP_ALIGN);
378 buffer_info->skb = skb;
380 /* allocate a new page if necessary */
381 if (!buffer_info->page) {
382 buffer_info->page = alloc_page(GFP_ATOMIC);
383 if (!buffer_info->page) {
384 adapter->alloc_rx_buff_failed++;
389 if (!buffer_info->dma)
390 buffer_info->dma = pci_map_page(pdev,
391 buffer_info->page, 0,
394 if (pci_dma_mapping_error(buffer_info->dma)) {
395 dev_err(&adapter->pdev->dev, "RX DMA page map failed\n");
396 adapter->rx_dma_failed++;
400 rx_desc = E1000_RX_DESC(*rx_ring, i);
401 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
404 if (i == rx_ring->count)
406 buffer_info = &rx_ring->buffer_info[i];
409 if (rx_ring->next_to_use != i) {
410 rx_ring->next_to_use = i;
412 i = (rx_ring->count - 1);
414 /* Force memory writes to complete before letting h/w
415 * know there are new descriptors to fetch. (Only
416 * applicable for weak-ordered memory model archs,
419 writel(i, adapter->hw.hw_addr + rx_ring->tail);
424 * e1000_clean_rx_irq - Send received data up the network stack; legacy
425 * @adapter: board private structure
427 * the return value indicates whether actual cleaning was done, there
428 * is no guarantee that everything was cleaned
430 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
431 int *work_done, int work_to_do)
433 struct net_device *netdev = adapter->netdev;
434 struct pci_dev *pdev = adapter->pdev;
435 struct e1000_ring *rx_ring = adapter->rx_ring;
436 struct e1000_rx_desc *rx_desc, *next_rxd;
437 struct e1000_buffer *buffer_info, *next_buffer;
440 int cleaned_count = 0;
442 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
444 i = rx_ring->next_to_clean;
445 rx_desc = E1000_RX_DESC(*rx_ring, i);
446 buffer_info = &rx_ring->buffer_info[i];
448 while (rx_desc->status & E1000_RXD_STAT_DD) {
452 if (*work_done >= work_to_do)
456 status = rx_desc->status;
457 skb = buffer_info->skb;
458 buffer_info->skb = NULL;
460 prefetch(skb->data - NET_IP_ALIGN);
463 if (i == rx_ring->count)
465 next_rxd = E1000_RX_DESC(*rx_ring, i);
468 next_buffer = &rx_ring->buffer_info[i];
472 pci_unmap_single(pdev,
474 adapter->rx_buffer_len,
476 buffer_info->dma = 0;
478 length = le16_to_cpu(rx_desc->length);
480 /* !EOP means multiple descriptors were used to store a single
481 * packet, also make sure the frame isn't just CRC only */
482 if (!(status & E1000_RXD_STAT_EOP) || (length <= 4)) {
483 /* All receives must fit into a single buffer */
484 ndev_dbg(netdev, "%s: Receive packet consumed "
485 "multiple buffers\n", netdev->name);
487 buffer_info->skb = skb;
491 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
493 buffer_info->skb = skb;
497 total_rx_bytes += length;
500 /* code added for copybreak, this should improve
501 * performance for small packets with large amounts
502 * of reassembly being done in the stack */
503 if (length < copybreak) {
504 struct sk_buff *new_skb =
505 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
507 skb_reserve(new_skb, NET_IP_ALIGN);
508 memcpy(new_skb->data - NET_IP_ALIGN,
509 skb->data - NET_IP_ALIGN,
510 length + NET_IP_ALIGN);
511 /* save the skb in buffer_info as good */
512 buffer_info->skb = skb;
515 /* else just continue with the old one */
517 /* end copybreak code */
518 skb_put(skb, length);
520 /* Receive Checksum Offload */
521 e1000_rx_checksum(adapter,
523 ((u32)(rx_desc->errors) << 24),
524 le16_to_cpu(rx_desc->csum), skb);
526 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
531 /* return some buffers to hardware, one at a time is too slow */
532 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
533 adapter->alloc_rx_buf(adapter, cleaned_count);
537 /* use prefetched values */
539 buffer_info = next_buffer;
541 rx_ring->next_to_clean = i;
543 cleaned_count = e1000_desc_unused(rx_ring);
545 adapter->alloc_rx_buf(adapter, cleaned_count);
547 adapter->total_rx_packets += total_rx_packets;
548 adapter->total_rx_bytes += total_rx_bytes;
552 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
557 skb->data_len += length;
558 skb->truesize += length;
561 static void e1000_put_txbuf(struct e1000_adapter *adapter,
562 struct e1000_buffer *buffer_info)
564 if (buffer_info->dma) {
565 pci_unmap_page(adapter->pdev, buffer_info->dma,
566 buffer_info->length, PCI_DMA_TODEVICE);
567 buffer_info->dma = 0;
569 if (buffer_info->skb) {
570 dev_kfree_skb_any(buffer_info->skb);
571 buffer_info->skb = NULL;
575 static void e1000_print_tx_hang(struct e1000_adapter *adapter)
577 struct e1000_ring *tx_ring = adapter->tx_ring;
578 unsigned int i = tx_ring->next_to_clean;
579 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
580 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
581 struct net_device *netdev = adapter->netdev;
583 /* detected Tx unit hang */
585 "Detected Tx Unit Hang:\n"
588 " next_to_use <%x>\n"
589 " next_to_clean <%x>\n"
590 "buffer_info[next_to_clean]:\n"
591 " time_stamp <%lx>\n"
592 " next_to_watch <%x>\n"
594 " next_to_watch.status <%x>\n",
595 readl(adapter->hw.hw_addr + tx_ring->head),
596 readl(adapter->hw.hw_addr + tx_ring->tail),
597 tx_ring->next_to_use,
598 tx_ring->next_to_clean,
599 tx_ring->buffer_info[eop].time_stamp,
602 eop_desc->upper.fields.status);
606 * e1000_clean_tx_irq - Reclaim resources after transmit completes
607 * @adapter: board private structure
609 * the return value indicates whether actual cleaning was done, there
610 * is no guarantee that everything was cleaned
612 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
614 struct net_device *netdev = adapter->netdev;
615 struct e1000_hw *hw = &adapter->hw;
616 struct e1000_ring *tx_ring = adapter->tx_ring;
617 struct e1000_tx_desc *tx_desc, *eop_desc;
618 struct e1000_buffer *buffer_info;
620 unsigned int count = 0;
622 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
624 i = tx_ring->next_to_clean;
625 eop = tx_ring->buffer_info[i].next_to_watch;
626 eop_desc = E1000_TX_DESC(*tx_ring, eop);
628 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
629 for (cleaned = 0; !cleaned; ) {
630 tx_desc = E1000_TX_DESC(*tx_ring, i);
631 buffer_info = &tx_ring->buffer_info[i];
632 cleaned = (i == eop);
635 struct sk_buff *skb = buffer_info->skb;
636 unsigned int segs, bytecount;
637 segs = skb_shinfo(skb)->gso_segs ?: 1;
638 /* multiply data chunks by size of headers */
639 bytecount = ((segs - 1) * skb_headlen(skb)) +
641 total_tx_packets += segs;
642 total_tx_bytes += bytecount;
645 e1000_put_txbuf(adapter, buffer_info);
646 tx_desc->upper.data = 0;
649 if (i == tx_ring->count)
653 eop = tx_ring->buffer_info[i].next_to_watch;
654 eop_desc = E1000_TX_DESC(*tx_ring, eop);
655 #define E1000_TX_WEIGHT 64
656 /* weight of a sort for tx, to avoid endless transmit cleanup */
657 if (count++ == E1000_TX_WEIGHT)
661 tx_ring->next_to_clean = i;
663 #define TX_WAKE_THRESHOLD 32
664 if (cleaned && netif_carrier_ok(netdev) &&
665 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
666 /* Make sure that anybody stopping the queue after this
667 * sees the new next_to_clean.
671 if (netif_queue_stopped(netdev) &&
672 !(test_bit(__E1000_DOWN, &adapter->state))) {
673 netif_wake_queue(netdev);
674 ++adapter->restart_queue;
678 if (adapter->detect_tx_hung) {
679 /* Detect a transmit hang in hardware, this serializes the
680 * check with the clearing of time_stamp and movement of i */
681 adapter->detect_tx_hung = 0;
682 if (tx_ring->buffer_info[eop].dma &&
683 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp
684 + (adapter->tx_timeout_factor * HZ))
686 E1000_STATUS_TXOFF)) {
687 e1000_print_tx_hang(adapter);
688 netif_stop_queue(netdev);
691 adapter->total_tx_bytes += total_tx_bytes;
692 adapter->total_tx_packets += total_tx_packets;
697 * e1000_clean_rx_irq_jumbo - Send received data up the network stack; legacy
698 * @adapter: board private structure
700 * the return value indicates whether actual cleaning was done, there
701 * is no guarantee that everything was cleaned
703 static bool e1000_clean_rx_irq_jumbo(struct e1000_adapter *adapter,
704 int *work_done, int work_to_do)
706 struct net_device *netdev = adapter->netdev;
707 struct pci_dev *pdev = adapter->pdev;
708 struct e1000_ring *rx_ring = adapter->rx_ring;
709 struct e1000_rx_desc *rx_desc, *next_rxd;
710 struct e1000_buffer *buffer_info, *next_buffer;
713 int cleaned_count = 0;
715 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
717 i = rx_ring->next_to_clean;
718 rx_desc = E1000_RX_DESC(*rx_ring, i);
719 buffer_info = &rx_ring->buffer_info[i];
721 while (rx_desc->status & E1000_RXD_STAT_DD) {
725 if (*work_done >= work_to_do)
729 status = rx_desc->status;
730 skb = buffer_info->skb;
731 buffer_info->skb = NULL;
734 if (i == rx_ring->count)
736 next_rxd = E1000_RX_DESC(*rx_ring, i);
739 next_buffer = &rx_ring->buffer_info[i];
747 buffer_info->dma = 0;
749 length = le16_to_cpu(rx_desc->length);
751 /* errors is only valid for DD + EOP descriptors */
752 if ((status & E1000_RXD_STAT_EOP) &&
753 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
754 /* recycle both page and skb */
755 buffer_info->skb = skb;
756 /* an error means any chain goes out the window too */
757 if (rx_ring->rx_skb_top)
758 dev_kfree_skb(rx_ring->rx_skb_top);
759 rx_ring->rx_skb_top = NULL;
763 #define rxtop rx_ring->rx_skb_top
764 if (!(status & E1000_RXD_STAT_EOP)) {
765 /* this descriptor is only the beginning (or middle) */
767 /* this is the beginning of a chain */
769 skb_fill_page_desc(rxtop, 0, buffer_info->page,
772 /* this is the middle of a chain */
773 skb_fill_page_desc(rxtop,
774 skb_shinfo(rxtop)->nr_frags,
775 buffer_info->page, 0,
777 /* re-use the skb, only consumed the page */
778 buffer_info->skb = skb;
780 e1000_consume_page(buffer_info, rxtop, length);
784 /* end of the chain */
785 skb_fill_page_desc(rxtop,
786 skb_shinfo(rxtop)->nr_frags,
787 buffer_info->page, 0, length);
788 /* re-use the current skb, we only consumed the
790 buffer_info->skb = skb;
793 e1000_consume_page(buffer_info, skb, length);
795 /* no chain, got EOP, this buf is the packet
796 * copybreak to save the put_page/alloc_page */
797 if (length <= copybreak &&
798 skb_tailroom(skb) >= length) {
800 vaddr = kmap_atomic(buffer_info->page,
801 KM_SKB_DATA_SOFTIRQ);
802 memcpy(skb_tail_pointer(skb),
805 KM_SKB_DATA_SOFTIRQ);
806 /* re-use the page, so don't erase
807 * buffer_info->page */
808 skb_put(skb, length);
810 skb_fill_page_desc(skb, 0,
811 buffer_info->page, 0,
813 e1000_consume_page(buffer_info, skb,
819 /* Receive Checksum Offload XXX recompute due to CRC strip? */
820 e1000_rx_checksum(adapter,
822 ((u32)(rx_desc->errors) << 24),
823 le16_to_cpu(rx_desc->csum), skb);
825 pskb_trim(skb, skb->len - 4);
827 /* probably a little skewed due to removing CRC */
828 total_rx_bytes += skb->len;
831 /* eth type trans needs skb->data to point to something */
832 if (!pskb_may_pull(skb, ETH_HLEN)) {
833 ndev_err(netdev, "__pskb_pull_tail failed.\n");
838 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
843 /* return some buffers to hardware, one at a time is too slow */
844 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
845 adapter->alloc_rx_buf(adapter, cleaned_count);
849 /* use prefetched values */
851 buffer_info = next_buffer;
853 rx_ring->next_to_clean = i;
855 cleaned_count = e1000_desc_unused(rx_ring);
857 adapter->alloc_rx_buf(adapter, cleaned_count);
859 adapter->total_rx_packets += total_rx_packets;
860 adapter->total_rx_bytes += total_rx_bytes;
865 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
866 * @adapter: board private structure
868 * the return value indicates whether actual cleaning was done, there
869 * is no guarantee that everything was cleaned
871 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
872 int *work_done, int work_to_do)
874 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
875 struct net_device *netdev = adapter->netdev;
876 struct pci_dev *pdev = adapter->pdev;
877 struct e1000_ring *rx_ring = adapter->rx_ring;
878 struct e1000_buffer *buffer_info, *next_buffer;
879 struct e1000_ps_page *ps_page;
883 int cleaned_count = 0;
885 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
887 i = rx_ring->next_to_clean;
888 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
889 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
890 buffer_info = &rx_ring->buffer_info[i];
892 while (staterr & E1000_RXD_STAT_DD) {
893 if (*work_done >= work_to_do)
896 skb = buffer_info->skb;
898 /* in the packet split case this is header only */
899 prefetch(skb->data - NET_IP_ALIGN);
902 if (i == rx_ring->count)
904 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
907 next_buffer = &rx_ring->buffer_info[i];
911 pci_unmap_single(pdev, buffer_info->dma,
912 adapter->rx_ps_bsize0,
914 buffer_info->dma = 0;
916 if (!(staterr & E1000_RXD_STAT_EOP)) {
917 ndev_dbg(netdev, "%s: Packet Split buffers didn't pick "
918 "up the full packet\n", netdev->name);
919 dev_kfree_skb_irq(skb);
923 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
924 dev_kfree_skb_irq(skb);
928 length = le16_to_cpu(rx_desc->wb.middle.length0);
931 ndev_dbg(netdev, "%s: Last part of the packet spanning"
932 " multiple descriptors\n", netdev->name);
933 dev_kfree_skb_irq(skb);
938 skb_put(skb, length);
941 /* this looks ugly, but it seems compiler issues make it
942 more efficient than reusing j */
943 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
945 /* page alloc/put takes too long and effects small packet
946 * throughput, so unsplit small packets and save the alloc/put*/
947 if (l1 && (l1 <= copybreak) &&
948 ((length + l1) <= adapter->rx_ps_bsize0)) {
951 ps_page = &buffer_info->ps_pages[0];
953 /* there is no documentation about how to call
954 * kmap_atomic, so we can't hold the mapping
956 pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
957 PAGE_SIZE, PCI_DMA_FROMDEVICE);
958 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
959 memcpy(skb_tail_pointer(skb), vaddr, l1);
960 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
961 pci_dma_sync_single_for_device(pdev, ps_page->dma,
962 PAGE_SIZE, PCI_DMA_FROMDEVICE);
969 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
970 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
974 ps_page = &buffer_info->ps_pages[j];
975 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
978 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
979 ps_page->page = NULL;
981 skb->data_len += length;
982 skb->truesize += length;
986 total_rx_bytes += skb->len;
989 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
990 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
992 if (rx_desc->wb.upper.header_status &
993 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
994 adapter->rx_hdr_split++;
996 e1000_receive_skb(adapter, netdev, skb,
997 staterr, rx_desc->wb.middle.vlan);
1000 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1001 buffer_info->skb = NULL;
1003 /* return some buffers to hardware, one at a time is too slow */
1004 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1005 adapter->alloc_rx_buf(adapter, cleaned_count);
1009 /* use prefetched values */
1011 buffer_info = next_buffer;
1013 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1015 rx_ring->next_to_clean = i;
1017 cleaned_count = e1000_desc_unused(rx_ring);
1019 adapter->alloc_rx_buf(adapter, cleaned_count);
1021 adapter->total_rx_packets += total_rx_packets;
1022 adapter->total_rx_bytes += total_rx_bytes;
1027 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1028 * @adapter: board private structure
1030 static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1032 struct e1000_ring *rx_ring = adapter->rx_ring;
1033 struct e1000_buffer *buffer_info;
1034 struct e1000_ps_page *ps_page;
1035 struct pci_dev *pdev = adapter->pdev;
1038 /* Free all the Rx ring sk_buffs */
1039 for (i = 0; i < rx_ring->count; i++) {
1040 buffer_info = &rx_ring->buffer_info[i];
1041 if (buffer_info->dma) {
1042 if (adapter->clean_rx == e1000_clean_rx_irq)
1043 pci_unmap_single(pdev, buffer_info->dma,
1044 adapter->rx_buffer_len,
1045 PCI_DMA_FROMDEVICE);
1046 else if (adapter->clean_rx == e1000_clean_rx_irq_jumbo)
1047 pci_unmap_page(pdev, buffer_info->dma,
1048 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1049 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1050 pci_unmap_single(pdev, buffer_info->dma,
1051 adapter->rx_ps_bsize0,
1052 PCI_DMA_FROMDEVICE);
1053 buffer_info->dma = 0;
1056 if (buffer_info->page) {
1057 put_page(buffer_info->page);
1058 buffer_info->page = NULL;
1061 if (buffer_info->skb) {
1062 dev_kfree_skb(buffer_info->skb);
1063 buffer_info->skb = NULL;
1066 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1067 ps_page = &buffer_info->ps_pages[j];
1070 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
1071 PCI_DMA_FROMDEVICE);
1073 put_page(ps_page->page);
1074 ps_page->page = NULL;
1078 /* there also may be some cached data from a chained receive */
1079 if (rx_ring->rx_skb_top) {
1080 dev_kfree_skb(rx_ring->rx_skb_top);
1081 rx_ring->rx_skb_top = NULL;
1084 /* Zero out the descriptor ring */
1085 memset(rx_ring->desc, 0, rx_ring->size);
1087 rx_ring->next_to_clean = 0;
1088 rx_ring->next_to_use = 0;
1090 writel(0, adapter->hw.hw_addr + rx_ring->head);
1091 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1095 * e1000_intr_msi - Interrupt Handler
1096 * @irq: interrupt number
1097 * @data: pointer to a network interface device structure
1099 static irqreturn_t e1000_intr_msi(int irq, void *data)
1101 struct net_device *netdev = data;
1102 struct e1000_adapter *adapter = netdev_priv(netdev);
1103 struct e1000_hw *hw = &adapter->hw;
1104 u32 icr = er32(ICR);
1106 /* read ICR disables interrupts using IAM, so keep up with our
1107 * enable/disable accounting */
1108 atomic_inc(&adapter->irq_sem);
1110 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
1111 hw->mac.get_link_status = 1;
1112 /* ICH8 workaround-- Call gig speed drop workaround on cable
1113 * disconnect (LSC) before accessing any PHY registers */
1114 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1115 (!(er32(STATUS) & E1000_STATUS_LU)))
1116 e1000e_gig_downshift_workaround_ich8lan(hw);
1118 /* 80003ES2LAN workaround-- For packet buffer work-around on
1119 * link down event; disable receives here in the ISR and reset
1120 * adapter in watchdog */
1121 if (netif_carrier_ok(netdev) &&
1122 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1123 /* disable receives */
1124 u32 rctl = er32(RCTL);
1125 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1127 /* guard against interrupt when we're going down */
1128 if (!test_bit(__E1000_DOWN, &adapter->state))
1129 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1132 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1133 adapter->total_tx_bytes = 0;
1134 adapter->total_tx_packets = 0;
1135 adapter->total_rx_bytes = 0;
1136 adapter->total_rx_packets = 0;
1137 __netif_rx_schedule(netdev, &adapter->napi);
1139 atomic_dec(&adapter->irq_sem);
1146 * e1000_intr - Interrupt Handler
1147 * @irq: interrupt number
1148 * @data: pointer to a network interface device structure
1150 static irqreturn_t e1000_intr(int irq, void *data)
1152 struct net_device *netdev = data;
1153 struct e1000_adapter *adapter = netdev_priv(netdev);
1154 struct e1000_hw *hw = &adapter->hw;
1156 u32 rctl, icr = er32(ICR);
1158 return IRQ_NONE; /* Not our interrupt */
1160 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1161 * not set, then the adapter didn't send an interrupt */
1162 if (!(icr & E1000_ICR_INT_ASSERTED))
1165 /* Interrupt Auto-Mask...upon reading ICR,
1166 * interrupts are masked. No need for the
1167 * IMC write, but it does mean we should
1168 * account for it ASAP. */
1169 atomic_inc(&adapter->irq_sem);
1171 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
1172 hw->mac.get_link_status = 1;
1173 /* ICH8 workaround-- Call gig speed drop workaround on cable
1174 * disconnect (LSC) before accessing any PHY registers */
1175 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1176 (!(er32(STATUS) & E1000_STATUS_LU)))
1177 e1000e_gig_downshift_workaround_ich8lan(hw);
1179 /* 80003ES2LAN workaround--
1180 * For packet buffer work-around on link down event;
1181 * disable receives here in the ISR and
1182 * reset adapter in watchdog
1184 if (netif_carrier_ok(netdev) &&
1185 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1186 /* disable receives */
1188 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1190 /* guard against interrupt when we're going down */
1191 if (!test_bit(__E1000_DOWN, &adapter->state))
1192 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1195 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1196 adapter->total_tx_bytes = 0;
1197 adapter->total_tx_packets = 0;
1198 adapter->total_rx_bytes = 0;
1199 adapter->total_rx_packets = 0;
1200 __netif_rx_schedule(netdev, &adapter->napi);
1202 atomic_dec(&adapter->irq_sem);
1208 static int e1000_request_irq(struct e1000_adapter *adapter)
1210 struct net_device *netdev = adapter->netdev;
1211 void (*handler) = &e1000_intr;
1212 int irq_flags = IRQF_SHARED;
1215 err = pci_enable_msi(adapter->pdev);
1218 "Unable to allocate MSI interrupt Error: %d\n", err);
1220 adapter->flags |= FLAG_MSI_ENABLED;
1221 handler = &e1000_intr_msi;
1225 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
1228 if (adapter->flags & FLAG_MSI_ENABLED)
1229 pci_disable_msi(adapter->pdev);
1231 "Unable to allocate interrupt Error: %d\n", err);
1237 static void e1000_free_irq(struct e1000_adapter *adapter)
1239 struct net_device *netdev = adapter->netdev;
1241 free_irq(adapter->pdev->irq, netdev);
1242 if (adapter->flags & FLAG_MSI_ENABLED) {
1243 pci_disable_msi(adapter->pdev);
1244 adapter->flags &= ~FLAG_MSI_ENABLED;
1249 * e1000_irq_disable - Mask off interrupt generation on the NIC
1251 static void e1000_irq_disable(struct e1000_adapter *adapter)
1253 struct e1000_hw *hw = &adapter->hw;
1255 atomic_inc(&adapter->irq_sem);
1258 synchronize_irq(adapter->pdev->irq);
1262 * e1000_irq_enable - Enable default interrupt generation settings
1264 static void e1000_irq_enable(struct e1000_adapter *adapter)
1266 struct e1000_hw *hw = &adapter->hw;
1268 if (atomic_dec_and_test(&adapter->irq_sem)) {
1269 ew32(IMS, IMS_ENABLE_MASK);
1275 * e1000_get_hw_control - get control of the h/w from f/w
1276 * @adapter: address of board private structure
1278 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
1279 * For ASF and Pass Through versions of f/w this means that
1280 * the driver is loaded. For AMT version (only with 82573)
1281 * of the f/w this means that the network i/f is open.
1283 static void e1000_get_hw_control(struct e1000_adapter *adapter)
1285 struct e1000_hw *hw = &adapter->hw;
1289 /* Let firmware know the driver has taken over */
1290 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1292 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1293 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1294 ctrl_ext = er32(CTRL_EXT);
1296 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1301 * e1000_release_hw_control - release control of the h/w to f/w
1302 * @adapter: address of board private structure
1304 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
1305 * For ASF and Pass Through versions of f/w this means that the
1306 * driver is no longer loaded. For AMT version (only with 82573) i
1307 * of the f/w this means that the network i/f is closed.
1310 static void e1000_release_hw_control(struct e1000_adapter *adapter)
1312 struct e1000_hw *hw = &adapter->hw;
1316 /* Let firmware taken over control of h/w */
1317 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1319 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1320 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1321 ctrl_ext = er32(CTRL_EXT);
1323 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1327 static void e1000_release_manageability(struct e1000_adapter *adapter)
1329 if (adapter->flags & FLAG_MNG_PT_ENABLED) {
1330 struct e1000_hw *hw = &adapter->hw;
1332 u32 manc = er32(MANC);
1334 /* re-enable hardware interception of ARP */
1335 manc |= E1000_MANC_ARP_EN;
1336 manc &= ~E1000_MANC_EN_MNG2HOST;
1338 /* don't explicitly have to mess with MANC2H since
1339 * MANC has an enable disable that gates MANC2H */
1345 * @e1000_alloc_ring - allocate memory for a ring structure
1347 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
1348 struct e1000_ring *ring)
1350 struct pci_dev *pdev = adapter->pdev;
1352 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
1361 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1362 * @adapter: board private structure
1364 * Return 0 on success, negative on failure
1366 int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
1368 struct e1000_ring *tx_ring = adapter->tx_ring;
1369 int err = -ENOMEM, size;
1371 size = sizeof(struct e1000_buffer) * tx_ring->count;
1372 tx_ring->buffer_info = vmalloc(size);
1373 if (!tx_ring->buffer_info)
1375 memset(tx_ring->buffer_info, 0, size);
1377 /* round up to nearest 4K */
1378 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1379 tx_ring->size = ALIGN(tx_ring->size, 4096);
1381 err = e1000_alloc_ring_dma(adapter, tx_ring);
1385 tx_ring->next_to_use = 0;
1386 tx_ring->next_to_clean = 0;
1387 spin_lock_init(&adapter->tx_queue_lock);
1391 vfree(tx_ring->buffer_info);
1392 ndev_err(adapter->netdev,
1393 "Unable to allocate memory for the transmit descriptor ring\n");
1398 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1399 * @adapter: board private structure
1401 * Returns 0 on success, negative on failure
1403 int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
1405 struct e1000_ring *rx_ring = adapter->rx_ring;
1406 struct e1000_buffer *buffer_info;
1407 int i, size, desc_len, err = -ENOMEM;
1409 size = sizeof(struct e1000_buffer) * rx_ring->count;
1410 rx_ring->buffer_info = vmalloc(size);
1411 if (!rx_ring->buffer_info)
1413 memset(rx_ring->buffer_info, 0, size);
1415 for (i = 0; i < rx_ring->count; i++) {
1416 buffer_info = &rx_ring->buffer_info[i];
1417 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
1418 sizeof(struct e1000_ps_page),
1420 if (!buffer_info->ps_pages)
1424 desc_len = sizeof(union e1000_rx_desc_packet_split);
1426 /* Round up to nearest 4K */
1427 rx_ring->size = rx_ring->count * desc_len;
1428 rx_ring->size = ALIGN(rx_ring->size, 4096);
1430 err = e1000_alloc_ring_dma(adapter, rx_ring);
1434 rx_ring->next_to_clean = 0;
1435 rx_ring->next_to_use = 0;
1436 rx_ring->rx_skb_top = NULL;
1441 for (i = 0; i < rx_ring->count; i++) {
1442 buffer_info = &rx_ring->buffer_info[i];
1443 kfree(buffer_info->ps_pages);
1446 vfree(rx_ring->buffer_info);
1447 ndev_err(adapter->netdev,
1448 "Unable to allocate memory for the transmit descriptor ring\n");
1453 * e1000_clean_tx_ring - Free Tx Buffers
1454 * @adapter: board private structure
1456 static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
1458 struct e1000_ring *tx_ring = adapter->tx_ring;
1459 struct e1000_buffer *buffer_info;
1463 for (i = 0; i < tx_ring->count; i++) {
1464 buffer_info = &tx_ring->buffer_info[i];
1465 e1000_put_txbuf(adapter, buffer_info);
1468 size = sizeof(struct e1000_buffer) * tx_ring->count;
1469 memset(tx_ring->buffer_info, 0, size);
1471 memset(tx_ring->desc, 0, tx_ring->size);
1473 tx_ring->next_to_use = 0;
1474 tx_ring->next_to_clean = 0;
1476 writel(0, adapter->hw.hw_addr + tx_ring->head);
1477 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1481 * e1000e_free_tx_resources - Free Tx Resources per Queue
1482 * @adapter: board private structure
1484 * Free all transmit software resources
1486 void e1000e_free_tx_resources(struct e1000_adapter *adapter)
1488 struct pci_dev *pdev = adapter->pdev;
1489 struct e1000_ring *tx_ring = adapter->tx_ring;
1491 e1000_clean_tx_ring(adapter);
1493 vfree(tx_ring->buffer_info);
1494 tx_ring->buffer_info = NULL;
1496 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1498 tx_ring->desc = NULL;
1502 * e1000e_free_rx_resources - Free Rx Resources
1503 * @adapter: board private structure
1505 * Free all receive software resources
1508 void e1000e_free_rx_resources(struct e1000_adapter *adapter)
1510 struct pci_dev *pdev = adapter->pdev;
1511 struct e1000_ring *rx_ring = adapter->rx_ring;
1514 e1000_clean_rx_ring(adapter);
1516 for (i = 0; i < rx_ring->count; i++) {
1517 kfree(rx_ring->buffer_info[i].ps_pages);
1520 vfree(rx_ring->buffer_info);
1521 rx_ring->buffer_info = NULL;
1523 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1525 rx_ring->desc = NULL;
1529 * e1000_update_itr - update the dynamic ITR value based on statistics
1530 * Stores a new ITR value based on packets and byte
1531 * counts during the last interrupt. The advantage of per interrupt
1532 * computation is faster updates and more accurate ITR for the current
1533 * traffic pattern. Constants in this function were computed
1534 * based on theoretical maximum wire speed and thresholds were set based
1535 * on testing data as well as attempting to minimize response time
1536 * while increasing bulk throughput.
1537 * this functionality is controlled by the InterruptThrottleRate module
1538 * parameter (see e1000_param.c)
1539 * @adapter: pointer to adapter
1540 * @itr_setting: current adapter->itr
1541 * @packets: the number of packets during this measurement interval
1542 * @bytes: the number of bytes during this measurement interval
1544 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
1545 u16 itr_setting, int packets,
1548 unsigned int retval = itr_setting;
1551 goto update_itr_done;
1553 switch (itr_setting) {
1554 case lowest_latency:
1555 /* handle TSO and jumbo frames */
1556 if (bytes/packets > 8000)
1557 retval = bulk_latency;
1558 else if ((packets < 5) && (bytes > 512)) {
1559 retval = low_latency;
1562 case low_latency: /* 50 usec aka 20000 ints/s */
1563 if (bytes > 10000) {
1564 /* this if handles the TSO accounting */
1565 if (bytes/packets > 8000) {
1566 retval = bulk_latency;
1567 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
1568 retval = bulk_latency;
1569 } else if ((packets > 35)) {
1570 retval = lowest_latency;
1572 } else if (bytes/packets > 2000) {
1573 retval = bulk_latency;
1574 } else if (packets <= 2 && bytes < 512) {
1575 retval = lowest_latency;
1578 case bulk_latency: /* 250 usec aka 4000 ints/s */
1579 if (bytes > 25000) {
1581 retval = low_latency;
1583 } else if (bytes < 6000) {
1584 retval = low_latency;
1593 static void e1000_set_itr(struct e1000_adapter *adapter)
1595 struct e1000_hw *hw = &adapter->hw;
1597 u32 new_itr = adapter->itr;
1599 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1600 if (adapter->link_speed != SPEED_1000) {
1606 adapter->tx_itr = e1000_update_itr(adapter,
1608 adapter->total_tx_packets,
1609 adapter->total_tx_bytes);
1610 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1611 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
1612 adapter->tx_itr = low_latency;
1614 adapter->rx_itr = e1000_update_itr(adapter,
1616 adapter->total_rx_packets,
1617 adapter->total_rx_bytes);
1618 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1619 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
1620 adapter->rx_itr = low_latency;
1622 current_itr = max(adapter->rx_itr, adapter->tx_itr);
1624 switch (current_itr) {
1625 /* counts and packets in update_itr are dependent on these numbers */
1626 case lowest_latency:
1630 new_itr = 20000; /* aka hwitr = ~200 */
1640 if (new_itr != adapter->itr) {
1641 /* this attempts to bias the interrupt rate towards Bulk
1642 * by adding intermediate steps when interrupt rate is
1644 new_itr = new_itr > adapter->itr ?
1645 min(adapter->itr + (new_itr >> 2), new_itr) :
1647 adapter->itr = new_itr;
1648 ew32(ITR, 1000000000 / (new_itr * 256));
1653 * e1000_clean - NAPI Rx polling callback
1654 * @adapter: board private structure
1656 static int e1000_clean(struct napi_struct *napi, int budget)
1658 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
1659 struct net_device *poll_dev = adapter->netdev;
1660 int tx_cleaned = 0, work_done = 0;
1662 /* Must NOT use netdev_priv macro here. */
1663 adapter = poll_dev->priv;
1665 /* Keep link state information with original netdev */
1666 if (!netif_carrier_ok(poll_dev))
1669 /* e1000_clean is called per-cpu. This lock protects
1670 * tx_ring from being cleaned by multiple cpus
1671 * simultaneously. A failure obtaining the lock means
1672 * tx_ring is currently being cleaned anyway. */
1673 if (spin_trylock(&adapter->tx_queue_lock)) {
1674 tx_cleaned = e1000_clean_tx_irq(adapter);
1675 spin_unlock(&adapter->tx_queue_lock);
1678 adapter->clean_rx(adapter, &work_done, budget);
1680 /* If no Tx and not enough Rx work done, exit the polling mode */
1681 if ((!tx_cleaned && (work_done < budget)) ||
1682 !netif_running(poll_dev)) {
1684 if (adapter->itr_setting & 3)
1685 e1000_set_itr(adapter);
1686 netif_rx_complete(poll_dev, napi);
1687 e1000_irq_enable(adapter);
1693 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1695 struct e1000_adapter *adapter = netdev_priv(netdev);
1696 struct e1000_hw *hw = &adapter->hw;
1699 /* don't update vlan cookie if already programmed */
1700 if ((adapter->hw.mng_cookie.status &
1701 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
1702 (vid == adapter->mng_vlan_id))
1704 /* add VID to filter table */
1705 index = (vid >> 5) & 0x7F;
1706 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
1707 vfta |= (1 << (vid & 0x1F));
1708 e1000e_write_vfta(hw, index, vfta);
1711 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1713 struct e1000_adapter *adapter = netdev_priv(netdev);
1714 struct e1000_hw *hw = &adapter->hw;
1717 e1000_irq_disable(adapter);
1718 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1719 e1000_irq_enable(adapter);
1721 if ((adapter->hw.mng_cookie.status &
1722 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
1723 (vid == adapter->mng_vlan_id)) {
1724 /* release control to f/w */
1725 e1000_release_hw_control(adapter);
1729 /* remove VID from filter table */
1730 index = (vid >> 5) & 0x7F;
1731 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
1732 vfta &= ~(1 << (vid & 0x1F));
1733 e1000e_write_vfta(hw, index, vfta);
1736 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
1738 struct net_device *netdev = adapter->netdev;
1739 u16 vid = adapter->hw.mng_cookie.vlan_id;
1740 u16 old_vid = adapter->mng_vlan_id;
1742 if (!adapter->vlgrp)
1745 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
1746 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1747 if (adapter->hw.mng_cookie.status &
1748 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1749 e1000_vlan_rx_add_vid(netdev, vid);
1750 adapter->mng_vlan_id = vid;
1753 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
1755 !vlan_group_get_device(adapter->vlgrp, old_vid))
1756 e1000_vlan_rx_kill_vid(netdev, old_vid);
1758 adapter->mng_vlan_id = vid;
1763 static void e1000_vlan_rx_register(struct net_device *netdev,
1764 struct vlan_group *grp)
1766 struct e1000_adapter *adapter = netdev_priv(netdev);
1767 struct e1000_hw *hw = &adapter->hw;
1770 e1000_irq_disable(adapter);
1771 adapter->vlgrp = grp;
1774 /* enable VLAN tag insert/strip */
1776 ctrl |= E1000_CTRL_VME;
1779 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
1780 /* enable VLAN receive filtering */
1782 rctl |= E1000_RCTL_VFE;
1783 rctl &= ~E1000_RCTL_CFIEN;
1785 e1000_update_mng_vlan(adapter);
1788 /* disable VLAN tag insert/strip */
1790 ctrl &= ~E1000_CTRL_VME;
1793 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
1794 /* disable VLAN filtering */
1796 rctl &= ~E1000_RCTL_VFE;
1798 if (adapter->mng_vlan_id !=
1799 (u16)E1000_MNG_VLAN_NONE) {
1800 e1000_vlan_rx_kill_vid(netdev,
1801 adapter->mng_vlan_id);
1802 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1807 e1000_irq_enable(adapter);
1810 static void e1000_restore_vlan(struct e1000_adapter *adapter)
1814 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1816 if (!adapter->vlgrp)
1819 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1820 if (!vlan_group_get_device(adapter->vlgrp, vid))
1822 e1000_vlan_rx_add_vid(adapter->netdev, vid);
1826 static void e1000_init_manageability(struct e1000_adapter *adapter)
1828 struct e1000_hw *hw = &adapter->hw;
1831 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
1836 /* disable hardware interception of ARP */
1837 manc &= ~(E1000_MANC_ARP_EN);
1839 /* enable receiving management packets to the host. this will probably
1840 * generate destination unreachable messages from the host OS, but
1841 * the packets will be handled on SMBUS */
1842 manc |= E1000_MANC_EN_MNG2HOST;
1843 manc2h = er32(MANC2H);
1844 #define E1000_MNG2HOST_PORT_623 (1 << 5)
1845 #define E1000_MNG2HOST_PORT_664 (1 << 6)
1846 manc2h |= E1000_MNG2HOST_PORT_623;
1847 manc2h |= E1000_MNG2HOST_PORT_664;
1848 ew32(MANC2H, manc2h);
1853 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1854 * @adapter: board private structure
1856 * Configure the Tx unit of the MAC after a reset.
1858 static void e1000_configure_tx(struct e1000_adapter *adapter)
1860 struct e1000_hw *hw = &adapter->hw;
1861 struct e1000_ring *tx_ring = adapter->tx_ring;
1863 u32 tdlen, tctl, tipg, tarc;
1866 /* Setup the HW Tx Head and Tail descriptor pointers */
1867 tdba = tx_ring->dma;
1868 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
1869 ew32(TDBAL, (tdba & DMA_32BIT_MASK));
1870 ew32(TDBAH, (tdba >> 32));
1874 tx_ring->head = E1000_TDH;
1875 tx_ring->tail = E1000_TDT;
1877 /* Set the default values for the Tx Inter Packet Gap timer */
1878 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
1879 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
1880 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
1882 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
1883 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
1885 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1886 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1889 /* Set the Tx Interrupt Delay register */
1890 ew32(TIDV, adapter->tx_int_delay);
1891 /* tx irq moderation */
1892 ew32(TADV, adapter->tx_abs_int_delay);
1894 /* Program the Transmit Control Register */
1896 tctl &= ~E1000_TCTL_CT;
1897 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1898 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1900 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
1902 /* set the speed mode bit, we'll clear it if we're not at
1903 * gigabit link later */
1904 #define SPEED_MODE_BIT (1 << 21)
1905 tarc |= SPEED_MODE_BIT;
1909 /* errata: program both queues to unweighted RR */
1910 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
1919 e1000e_config_collision_dist(hw);
1921 /* Setup Transmit Descriptor Settings for eop descriptor */
1922 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1924 /* only set IDE if we are delaying interrupts using the timers */
1925 if (adapter->tx_int_delay)
1926 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1928 /* enable Report Status bit */
1929 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1933 adapter->tx_queue_len = adapter->netdev->tx_queue_len;
1937 * e1000_setup_rctl - configure the receive control registers
1938 * @adapter: Board private structure
1940 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1941 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1942 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1944 struct e1000_hw *hw = &adapter->hw;
1949 /* Program MC offset vector base */
1951 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1952 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1953 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1954 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1956 /* Do not Store bad packets */
1957 rctl &= ~E1000_RCTL_SBP;
1959 /* Enable Long Packet receive */
1960 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1961 rctl &= ~E1000_RCTL_LPE;
1963 rctl |= E1000_RCTL_LPE;
1965 /* Setup buffer sizes */
1966 rctl &= ~E1000_RCTL_SZ_4096;
1967 rctl |= E1000_RCTL_BSEX;
1968 switch (adapter->rx_buffer_len) {
1970 rctl |= E1000_RCTL_SZ_256;
1971 rctl &= ~E1000_RCTL_BSEX;
1974 rctl |= E1000_RCTL_SZ_512;
1975 rctl &= ~E1000_RCTL_BSEX;
1978 rctl |= E1000_RCTL_SZ_1024;
1979 rctl &= ~E1000_RCTL_BSEX;
1983 rctl |= E1000_RCTL_SZ_2048;
1984 rctl &= ~E1000_RCTL_BSEX;
1987 rctl |= E1000_RCTL_SZ_4096;
1990 rctl |= E1000_RCTL_SZ_8192;
1993 rctl |= E1000_RCTL_SZ_16384;
1998 * 82571 and greater support packet-split where the protocol
1999 * header is placed in skb->data and the packet data is
2000 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2001 * In the case of a non-split, skb->data is linearly filled,
2002 * followed by the page buffers. Therefore, skb->data is
2003 * sized to hold the largest protocol header.
2005 * allocations using alloc_page take too long for regular MTU
2006 * so only enable packet split for jumbo frames
2008 * Using pages when the page size is greater than 16k wastes
2009 * a lot of memory, since we allocate 3 pages at all times
2012 adapter->rx_ps_pages = 0;
2013 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2014 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
2015 adapter->rx_ps_pages = pages;
2017 if (adapter->rx_ps_pages) {
2018 /* Configure extra packet-split registers */
2019 rfctl = er32(RFCTL);
2020 rfctl |= E1000_RFCTL_EXTEN;
2021 /* disable packet split support for IPv6 extension headers,
2022 * because some malformed IPv6 headers can hang the RX */
2023 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2024 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2028 /* Enable Packet split descriptors */
2029 rctl |= E1000_RCTL_DTYP_PS;
2031 /* Enable hardware CRC frame stripping */
2032 rctl |= E1000_RCTL_SECRC;
2034 psrctl |= adapter->rx_ps_bsize0 >>
2035 E1000_PSRCTL_BSIZE0_SHIFT;
2037 switch (adapter->rx_ps_pages) {
2039 psrctl |= PAGE_SIZE <<
2040 E1000_PSRCTL_BSIZE3_SHIFT;
2042 psrctl |= PAGE_SIZE <<
2043 E1000_PSRCTL_BSIZE2_SHIFT;
2045 psrctl |= PAGE_SIZE >>
2046 E1000_PSRCTL_BSIZE1_SHIFT;
2050 ew32(PSRCTL, psrctl);
2057 * e1000_configure_rx - Configure Receive Unit after Reset
2058 * @adapter: board private structure
2060 * Configure the Rx unit of the MAC after a reset.
2062 static void e1000_configure_rx(struct e1000_adapter *adapter)
2064 struct e1000_hw *hw = &adapter->hw;
2065 struct e1000_ring *rx_ring = adapter->rx_ring;
2067 u32 rdlen, rctl, rxcsum, ctrl_ext;
2069 if (adapter->rx_ps_pages) {
2070 /* this is a 32 byte descriptor */
2071 rdlen = rx_ring->count *
2072 sizeof(union e1000_rx_desc_packet_split);
2073 adapter->clean_rx = e1000_clean_rx_irq_ps;
2074 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2075 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + VLAN_HLEN + 4) {
2076 rdlen = rx_ring->count *
2077 sizeof(struct e1000_rx_desc);
2078 adapter->clean_rx = e1000_clean_rx_irq_jumbo;
2079 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_jumbo;
2081 rdlen = rx_ring->count *
2082 sizeof(struct e1000_rx_desc);
2083 adapter->clean_rx = e1000_clean_rx_irq;
2084 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2087 /* disable receives while setting up the descriptors */
2089 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2093 /* set the Receive Delay Timer Register */
2094 ew32(RDTR, adapter->rx_int_delay);
2096 /* irq moderation */
2097 ew32(RADV, adapter->rx_abs_int_delay);
2098 if (adapter->itr_setting != 0)
2100 1000000000 / (adapter->itr * 256));
2102 ctrl_ext = er32(CTRL_EXT);
2103 /* Reset delay timers after every interrupt */
2104 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
2105 /* Auto-Mask interrupts upon ICR access */
2106 ctrl_ext |= E1000_CTRL_EXT_IAME;
2107 ew32(IAM, 0xffffffff);
2108 ew32(CTRL_EXT, ctrl_ext);
2111 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2112 * the Base and Length of the Rx Descriptor Ring */
2113 rdba = rx_ring->dma;
2114 ew32(RDBAL, (rdba & DMA_32BIT_MASK));
2115 ew32(RDBAH, (rdba >> 32));
2119 rx_ring->head = E1000_RDH;
2120 rx_ring->tail = E1000_RDT;
2122 /* Enable Receive Checksum Offload for TCP and UDP */
2123 rxcsum = er32(RXCSUM);
2124 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2125 rxcsum |= E1000_RXCSUM_TUOFL;
2127 /* IPv4 payload checksum for UDP fragments must be
2128 * used in conjunction with packet-split. */
2129 if (adapter->rx_ps_pages)
2130 rxcsum |= E1000_RXCSUM_IPPCSE;
2132 rxcsum &= ~E1000_RXCSUM_TUOFL;
2133 /* no need to clear IPPCSE as it defaults to 0 */
2135 ew32(RXCSUM, rxcsum);
2137 /* Enable early receives on supported devices, only takes effect when
2138 * packet size is equal or larger than the specified value (in 8 byte
2139 * units), e.g. using jumbo frames when setting to E1000_ERT_2048 */
2140 if ((adapter->flags & FLAG_HAS_ERT) &&
2141 (adapter->netdev->mtu > ETH_DATA_LEN))
2142 ew32(ERT, E1000_ERT_2048);
2144 /* Enable Receives */
2149 * e1000_mc_addr_list_update - Update Multicast addresses
2150 * @hw: pointer to the HW structure
2151 * @mc_addr_list: array of multicast addresses to program
2152 * @mc_addr_count: number of multicast addresses to program
2153 * @rar_used_count: the first RAR register free to program
2154 * @rar_count: total number of supported Receive Address Registers
2156 * Updates the Receive Address Registers and Multicast Table Array.
2157 * The caller must have a packed mc_addr_list of multicast addresses.
2158 * The parameter rar_count will usually be hw->mac.rar_entry_count
2159 * unless there are workarounds that change this. Currently no func pointer
2160 * exists and all implementations are handled in the generic version of this
2163 static void e1000_mc_addr_list_update(struct e1000_hw *hw, u8 *mc_addr_list,
2164 u32 mc_addr_count, u32 rar_used_count,
2167 hw->mac.ops.mc_addr_list_update(hw, mc_addr_list, mc_addr_count,
2168 rar_used_count, rar_count);
2172 * e1000_set_multi - Multicast and Promiscuous mode set
2173 * @netdev: network interface device structure
2175 * The set_multi entry point is called whenever the multicast address
2176 * list or the network interface flags are updated. This routine is
2177 * responsible for configuring the hardware for proper multicast,
2178 * promiscuous mode, and all-multi behavior.
2180 static void e1000_set_multi(struct net_device *netdev)
2182 struct e1000_adapter *adapter = netdev_priv(netdev);
2183 struct e1000_hw *hw = &adapter->hw;
2184 struct e1000_mac_info *mac = &hw->mac;
2185 struct dev_mc_list *mc_ptr;
2190 /* Check for Promiscuous and All Multicast modes */
2194 if (netdev->flags & IFF_PROMISC) {
2195 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2196 } else if (netdev->flags & IFF_ALLMULTI) {
2197 rctl |= E1000_RCTL_MPE;
2198 rctl &= ~E1000_RCTL_UPE;
2200 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2205 if (netdev->mc_count) {
2206 mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);
2210 /* prepare a packed array of only addresses. */
2211 mc_ptr = netdev->mc_list;
2213 for (i = 0; i < netdev->mc_count; i++) {
2216 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
2218 mc_ptr = mc_ptr->next;
2221 e1000_mc_addr_list_update(hw, mta_list, i, 1,
2222 mac->rar_entry_count);
2226 * if we're called from probe, we might not have
2227 * anything to do here, so clear out the list
2229 e1000_mc_addr_list_update(hw, NULL, 0, 1,
2230 mac->rar_entry_count);
2235 * e1000_configure - configure the hardware for RX and TX
2236 * @adapter: private board structure
2238 static void e1000_configure(struct e1000_adapter *adapter)
2240 e1000_set_multi(adapter->netdev);
2242 e1000_restore_vlan(adapter);
2243 e1000_init_manageability(adapter);
2245 e1000_configure_tx(adapter);
2246 e1000_setup_rctl(adapter);
2247 e1000_configure_rx(adapter);
2248 adapter->alloc_rx_buf(adapter,
2249 e1000_desc_unused(adapter->rx_ring));
2253 * e1000e_power_up_phy - restore link in case the phy was powered down
2254 * @adapter: address of board private structure
2256 * The phy may be powered down to save power and turn off link when the
2257 * driver is unloaded and wake on lan is not enabled (among others)
2258 * *** this routine MUST be followed by a call to e1000e_reset ***
2260 void e1000e_power_up_phy(struct e1000_adapter *adapter)
2264 /* Just clear the power down bit to wake the phy back up */
2265 if (adapter->hw.media_type == e1000_media_type_copper) {
2266 /* according to the manual, the phy will retain its
2267 * settings across a power-down/up cycle */
2268 e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);
2269 mii_reg &= ~MII_CR_POWER_DOWN;
2270 e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);
2273 adapter->hw.mac.ops.setup_link(&adapter->hw);
2277 * e1000_power_down_phy - Power down the PHY
2279 * Power down the PHY so no link is implied when interface is down
2280 * The PHY cannot be powered down is management or WoL is active
2282 static void e1000_power_down_phy(struct e1000_adapter *adapter)
2284 struct e1000_hw *hw = &adapter->hw;
2287 /* WoL is enabled */
2291 /* non-copper PHY? */
2292 if (adapter->hw.media_type != e1000_media_type_copper)
2295 /* reset is blocked because of a SoL/IDER session */
2296 if (e1000e_check_mng_mode(hw) ||
2297 e1000_check_reset_block(hw))
2300 /* managebility (AMT) is enabled */
2301 if (er32(MANC) & E1000_MANC_SMBUS_EN)
2304 /* power down the PHY */
2305 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2306 mii_reg |= MII_CR_POWER_DOWN;
2307 e1e_wphy(hw, PHY_CONTROL, mii_reg);
2312 * e1000e_reset - bring the hardware into a known good state
2314 * This function boots the hardware and enables some settings that
2315 * require a configuration cycle of the hardware - those cannot be
2316 * set/changed during runtime. After reset the device needs to be
2317 * properly configured for rx, tx etc.
2319 void e1000e_reset(struct e1000_adapter *adapter)
2321 struct e1000_mac_info *mac = &adapter->hw.mac;
2322 struct e1000_hw *hw = &adapter->hw;
2323 u32 tx_space, min_tx_space, min_rx_space;
2327 ew32(PBA, adapter->pba);
2329 if (mac->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN ) {
2330 /* To maintain wire speed transmits, the Tx FIFO should be
2331 * large enough to accommodate two full transmit packets,
2332 * rounded up to the next 1KB and expressed in KB. Likewise,
2333 * the Rx FIFO should be large enough to accommodate at least
2334 * one full receive packet and is similarly rounded up and
2335 * expressed in KB. */
2337 /* upper 16 bits has Tx packet buffer allocation size in KB */
2338 tx_space = pba >> 16;
2339 /* lower 16 bits has Rx packet buffer allocation size in KB */
2341 /* the tx fifo also stores 16 bytes of information about the tx
2342 * but don't include ethernet FCS because hardware appends it */
2343 min_tx_space = (mac->max_frame_size +
2344 sizeof(struct e1000_tx_desc) -
2346 min_tx_space = ALIGN(min_tx_space, 1024);
2347 min_tx_space >>= 10;
2348 /* software strips receive CRC, so leave room for it */
2349 min_rx_space = mac->max_frame_size;
2350 min_rx_space = ALIGN(min_rx_space, 1024);
2351 min_rx_space >>= 10;
2353 /* If current Tx allocation is less than the min Tx FIFO size,
2354 * and the min Tx FIFO size is less than the current Rx FIFO
2355 * allocation, take space away from current Rx allocation */
2356 if ((tx_space < min_tx_space) &&
2357 ((min_tx_space - tx_space) < pba)) {
2358 pba -= min_tx_space - tx_space;
2360 /* if short on rx space, rx wins and must trump tx
2361 * adjustment or use Early Receive if available */
2362 if ((pba < min_rx_space) &&
2363 (!(adapter->flags & FLAG_HAS_ERT)))
2364 /* ERT enabled in e1000_configure_rx */
2372 /* flow control settings */
2373 /* The high water mark must be low enough to fit one full frame
2374 * (or the size used for early receive) above it in the Rx FIFO.
2375 * Set it to the lower of:
2376 * - 90% of the Rx FIFO size, and
2377 * - the full Rx FIFO size minus the early receive size (for parts
2378 * with ERT support assuming ERT set to E1000_ERT_2048), or
2379 * - the full Rx FIFO size minus one full frame */
2380 if (adapter->flags & FLAG_HAS_ERT)
2381 hwm = min(((adapter->pba << 10) * 9 / 10),
2382 ((adapter->pba << 10) - (E1000_ERT_2048 << 3)));
2384 hwm = min(((adapter->pba << 10) * 9 / 10),
2385 ((adapter->pba << 10) - mac->max_frame_size));
2387 mac->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
2388 mac->fc_low_water = mac->fc_high_water - 8;
2390 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
2391 mac->fc_pause_time = 0xFFFF;
2393 mac->fc_pause_time = E1000_FC_PAUSE_TIME;
2394 mac->fc = mac->original_fc;
2396 /* Allow time for pending master requests to run */
2397 mac->ops.reset_hw(hw);
2400 if (mac->ops.init_hw(hw))
2401 ndev_err(adapter->netdev, "Hardware Error\n");
2403 e1000_update_mng_vlan(adapter);
2405 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2406 ew32(VET, ETH_P_8021Q);
2408 e1000e_reset_adaptive(hw);
2409 e1000_get_phy_info(hw);
2411 if (!(adapter->flags & FLAG_SMART_POWER_DOWN)) {
2413 /* speed up time to link by disabling smart power down, ignore
2414 * the return value of this function because there is nothing
2415 * different we would do if it failed */
2416 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
2417 phy_data &= ~IGP02E1000_PM_SPD;
2418 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
2421 e1000_release_manageability(adapter);
2424 int e1000e_up(struct e1000_adapter *adapter)
2426 struct e1000_hw *hw = &adapter->hw;
2428 /* hardware has been reset, we need to reload some things */
2429 e1000_configure(adapter);
2431 clear_bit(__E1000_DOWN, &adapter->state);
2433 napi_enable(&adapter->napi);
2434 e1000_irq_enable(adapter);
2436 /* fire a link change interrupt to start the watchdog */
2437 ew32(ICS, E1000_ICS_LSC);
2441 void e1000e_down(struct e1000_adapter *adapter)
2443 struct net_device *netdev = adapter->netdev;
2444 struct e1000_hw *hw = &adapter->hw;
2447 /* signal that we're down so the interrupt handler does not
2448 * reschedule our watchdog timer */
2449 set_bit(__E1000_DOWN, &adapter->state);
2451 /* disable receives in the hardware */
2453 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2454 /* flush and sleep below */
2456 netif_stop_queue(netdev);
2458 /* disable transmits in the hardware */
2460 tctl &= ~E1000_TCTL_EN;
2462 /* flush both disables and wait for them to finish */
2466 napi_disable(&adapter->napi);
2467 e1000_irq_disable(adapter);
2469 del_timer_sync(&adapter->watchdog_timer);
2470 del_timer_sync(&adapter->phy_info_timer);
2472 netdev->tx_queue_len = adapter->tx_queue_len;
2473 netif_carrier_off(netdev);
2474 adapter->link_speed = 0;
2475 adapter->link_duplex = 0;
2477 e1000e_reset(adapter);
2478 e1000_clean_tx_ring(adapter);
2479 e1000_clean_rx_ring(adapter);
2482 * TODO: for power management, we could drop the link and
2483 * pci_disable_device here.
2487 void e1000e_reinit_locked(struct e1000_adapter *adapter)
2490 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
2492 e1000e_down(adapter);
2494 clear_bit(__E1000_RESETTING, &adapter->state);
2498 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2499 * @adapter: board private structure to initialize
2501 * e1000_sw_init initializes the Adapter private data structure.
2502 * Fields are initialized based on PCI device information and
2503 * OS network device settings (MTU size).
2505 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
2507 struct e1000_hw *hw = &adapter->hw;
2508 struct net_device *netdev = adapter->netdev;
2510 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
2511 adapter->rx_ps_bsize0 = 128;
2512 hw->mac.max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2513 hw->mac.min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
2515 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2516 if (!adapter->tx_ring)
2519 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2520 if (!adapter->rx_ring)
2523 spin_lock_init(&adapter->tx_queue_lock);
2525 /* Explicitly disable IRQ since the NIC can be in any state. */
2526 atomic_set(&adapter->irq_sem, 0);
2527 e1000_irq_disable(adapter);
2529 spin_lock_init(&adapter->stats_lock);
2531 set_bit(__E1000_DOWN, &adapter->state);
2535 ndev_err(netdev, "Unable to allocate memory for queues\n");
2536 kfree(adapter->rx_ring);
2537 kfree(adapter->tx_ring);
2542 * e1000_open - Called when a network interface is made active
2543 * @netdev: network interface device structure
2545 * Returns 0 on success, negative value on failure
2547 * The open entry point is called when a network interface is made
2548 * active by the system (IFF_UP). At this point all resources needed
2549 * for transmit and receive operations are allocated, the interrupt
2550 * handler is registered with the OS, the watchdog timer is started,
2551 * and the stack is notified that the interface is ready.
2553 static int e1000_open(struct net_device *netdev)
2555 struct e1000_adapter *adapter = netdev_priv(netdev);
2556 struct e1000_hw *hw = &adapter->hw;
2559 /* disallow open during test */
2560 if (test_bit(__E1000_TESTING, &adapter->state))
2563 /* allocate transmit descriptors */
2564 err = e1000e_setup_tx_resources(adapter);
2568 /* allocate receive descriptors */
2569 err = e1000e_setup_rx_resources(adapter);
2573 e1000e_power_up_phy(adapter);
2575 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2576 if ((adapter->hw.mng_cookie.status &
2577 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
2578 e1000_update_mng_vlan(adapter);
2580 /* If AMT is enabled, let the firmware know that the network
2581 * interface is now open */
2582 if ((adapter->flags & FLAG_HAS_AMT) &&
2583 e1000e_check_mng_mode(&adapter->hw))
2584 e1000_get_hw_control(adapter);
2586 /* before we allocate an interrupt, we must be ready to handle it.
2587 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
2588 * as soon as we call pci_request_irq, so we have to setup our
2589 * clean_rx handler before we do so. */
2590 e1000_configure(adapter);
2592 err = e1000_request_irq(adapter);
2596 /* From here on the code is the same as e1000e_up() */
2597 clear_bit(__E1000_DOWN, &adapter->state);
2599 napi_enable(&adapter->napi);
2601 e1000_irq_enable(adapter);
2603 /* fire a link status change interrupt to start the watchdog */
2604 ew32(ICS, E1000_ICS_LSC);
2609 e1000_release_hw_control(adapter);
2610 e1000_power_down_phy(adapter);
2611 e1000e_free_rx_resources(adapter);
2613 e1000e_free_tx_resources(adapter);
2615 e1000e_reset(adapter);
2621 * e1000_close - Disables a network interface
2622 * @netdev: network interface device structure
2624 * Returns 0, this is not allowed to fail
2626 * The close entry point is called when an interface is de-activated
2627 * by the OS. The hardware is still under the drivers control, but
2628 * needs to be disabled. A global MAC reset is issued to stop the
2629 * hardware, and all transmit and receive resources are freed.
2631 static int e1000_close(struct net_device *netdev)
2633 struct e1000_adapter *adapter = netdev_priv(netdev);
2635 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
2636 e1000e_down(adapter);
2637 e1000_power_down_phy(adapter);
2638 e1000_free_irq(adapter);
2640 e1000e_free_tx_resources(adapter);
2641 e1000e_free_rx_resources(adapter);
2643 /* kill manageability vlan ID if supported, but not if a vlan with
2644 * the same ID is registered on the host OS (let 8021q kill it) */
2645 if ((adapter->hw.mng_cookie.status &
2646 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2648 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
2649 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2651 /* If AMT is enabled, let the firmware know that the network
2652 * interface is now closed */
2653 if ((adapter->flags & FLAG_HAS_AMT) &&
2654 e1000e_check_mng_mode(&adapter->hw))
2655 e1000_release_hw_control(adapter);
2660 * e1000_set_mac - Change the Ethernet Address of the NIC
2661 * @netdev: network interface device structure
2662 * @p: pointer to an address structure
2664 * Returns 0 on success, negative on failure
2666 static int e1000_set_mac(struct net_device *netdev, void *p)
2668 struct e1000_adapter *adapter = netdev_priv(netdev);
2669 struct sockaddr *addr = p;
2671 if (!is_valid_ether_addr(addr->sa_data))
2672 return -EADDRNOTAVAIL;
2674 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2675 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
2677 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
2679 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
2680 /* activate the work around */
2681 e1000e_set_laa_state_82571(&adapter->hw, 1);
2683 /* Hold a copy of the LAA in RAR[14] This is done so that
2684 * between the time RAR[0] gets clobbered and the time it
2685 * gets fixed (in e1000_watchdog), the actual LAA is in one
2686 * of the RARs and no incoming packets directed to this port
2687 * are dropped. Eventually the LAA will be in RAR[0] and
2689 e1000e_rar_set(&adapter->hw,
2690 adapter->hw.mac.addr,
2691 adapter->hw.mac.rar_entry_count - 1);
2697 /* Need to wait a few seconds after link up to get diagnostic information from
2699 static void e1000_update_phy_info(unsigned long data)
2701 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2702 e1000_get_phy_info(&adapter->hw);
2706 * e1000e_update_stats - Update the board statistics counters
2707 * @adapter: board private structure
2709 void e1000e_update_stats(struct e1000_adapter *adapter)
2711 struct e1000_hw *hw = &adapter->hw;
2712 struct pci_dev *pdev = adapter->pdev;
2713 unsigned long irq_flags;
2716 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2719 * Prevent stats update while adapter is being reset, or if the pci
2720 * connection is down.
2722 if (adapter->link_speed == 0)
2724 if (pci_channel_offline(pdev))
2727 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
2729 /* these counters are modified from e1000_adjust_tbi_stats,
2730 * called from the interrupt context, so they must only
2731 * be written while holding adapter->stats_lock
2734 adapter->stats.crcerrs += er32(CRCERRS);
2735 adapter->stats.gprc += er32(GPRC);
2736 adapter->stats.gorcl += er32(GORCL);
2737 adapter->stats.gorch += er32(GORCH);
2738 adapter->stats.bprc += er32(BPRC);
2739 adapter->stats.mprc += er32(MPRC);
2740 adapter->stats.roc += er32(ROC);
2742 if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) {
2743 adapter->stats.prc64 += er32(PRC64);
2744 adapter->stats.prc127 += er32(PRC127);
2745 adapter->stats.prc255 += er32(PRC255);
2746 adapter->stats.prc511 += er32(PRC511);
2747 adapter->stats.prc1023 += er32(PRC1023);
2748 adapter->stats.prc1522 += er32(PRC1522);
2749 adapter->stats.symerrs += er32(SYMERRS);
2750 adapter->stats.sec += er32(SEC);
2753 adapter->stats.mpc += er32(MPC);
2754 adapter->stats.scc += er32(SCC);
2755 adapter->stats.ecol += er32(ECOL);
2756 adapter->stats.mcc += er32(MCC);
2757 adapter->stats.latecol += er32(LATECOL);
2758 adapter->stats.dc += er32(DC);
2759 adapter->stats.rlec += er32(RLEC);
2760 adapter->stats.xonrxc += er32(XONRXC);
2761 adapter->stats.xontxc += er32(XONTXC);
2762 adapter->stats.xoffrxc += er32(XOFFRXC);
2763 adapter->stats.xofftxc += er32(XOFFTXC);
2764 adapter->stats.fcruc += er32(FCRUC);
2765 adapter->stats.gptc += er32(GPTC);
2766 adapter->stats.gotcl += er32(GOTCL);
2767 adapter->stats.gotch += er32(GOTCH);
2768 adapter->stats.rnbc += er32(RNBC);
2769 adapter->stats.ruc += er32(RUC);
2770 adapter->stats.rfc += er32(RFC);
2771 adapter->stats.rjc += er32(RJC);
2772 adapter->stats.torl += er32(TORL);
2773 adapter->stats.torh += er32(TORH);
2774 adapter->stats.totl += er32(TOTL);
2775 adapter->stats.toth += er32(TOTH);
2776 adapter->stats.tpr += er32(TPR);
2778 if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) {
2779 adapter->stats.ptc64 += er32(PTC64);
2780 adapter->stats.ptc127 += er32(PTC127);
2781 adapter->stats.ptc255 += er32(PTC255);
2782 adapter->stats.ptc511 += er32(PTC511);
2783 adapter->stats.ptc1023 += er32(PTC1023);
2784 adapter->stats.ptc1522 += er32(PTC1522);
2787 adapter->stats.mptc += er32(MPTC);
2788 adapter->stats.bptc += er32(BPTC);
2790 /* used for adaptive IFS */
2792 hw->mac.tx_packet_delta = er32(TPT);
2793 adapter->stats.tpt += hw->mac.tx_packet_delta;
2794 hw->mac.collision_delta = er32(COLC);
2795 adapter->stats.colc += hw->mac.collision_delta;
2797 adapter->stats.algnerrc += er32(ALGNERRC);
2798 adapter->stats.rxerrc += er32(RXERRC);
2799 adapter->stats.tncrs += er32(TNCRS);
2800 adapter->stats.cexterr += er32(CEXTERR);
2801 adapter->stats.tsctc += er32(TSCTC);
2802 adapter->stats.tsctfc += er32(TSCTFC);
2804 adapter->stats.iac += er32(IAC);
2806 if (adapter->flags & FLAG_HAS_STATS_ICR_ICT) {
2807 adapter->stats.icrxoc += er32(ICRXOC);
2808 adapter->stats.icrxptc += er32(ICRXPTC);
2809 adapter->stats.icrxatc += er32(ICRXATC);
2810 adapter->stats.ictxptc += er32(ICTXPTC);
2811 adapter->stats.ictxatc += er32(ICTXATC);
2812 adapter->stats.ictxqec += er32(ICTXQEC);
2813 adapter->stats.ictxqmtc += er32(ICTXQMTC);
2814 adapter->stats.icrxdmtc += er32(ICRXDMTC);
2817 /* Fill out the OS statistics structure */
2818 adapter->net_stats.rx_packets = adapter->stats.gprc;
2819 adapter->net_stats.tx_packets = adapter->stats.gptc;
2820 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
2821 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
2822 adapter->net_stats.multicast = adapter->stats.mprc;
2823 adapter->net_stats.collisions = adapter->stats.colc;
2827 /* RLEC on some newer hardware can be incorrect so build
2828 * our own version based on RUC and ROC */
2829 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
2830 adapter->stats.crcerrs + adapter->stats.algnerrc +
2831 adapter->stats.ruc + adapter->stats.roc +
2832 adapter->stats.cexterr;
2833 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
2835 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2836 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
2837 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
2840 adapter->net_stats.tx_errors = adapter->stats.ecol +
2841 adapter->stats.latecol;
2842 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
2843 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
2844 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
2846 /* Tx Dropped needs to be maintained elsewhere */
2849 if (hw->media_type == e1000_media_type_copper) {
2850 if ((adapter->link_speed == SPEED_1000) &&
2851 (!e1e_rphy(hw, PHY_1000T_STATUS, &phy_tmp))) {
2852 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
2853 adapter->phy_stats.idle_errors += phy_tmp;
2857 /* Management Stats */
2858 adapter->stats.mgptc += er32(MGTPTC);
2859 adapter->stats.mgprc += er32(MGTPRC);
2860 adapter->stats.mgpdc += er32(MGTPDC);
2862 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
2865 static void e1000_print_link_info(struct e1000_adapter *adapter)
2867 struct net_device *netdev = adapter->netdev;
2868 struct e1000_hw *hw = &adapter->hw;
2869 u32 ctrl = er32(CTRL);
2872 "Link is Up %d Mbps %s, Flow Control: %s\n",
2873 adapter->link_speed,
2874 (adapter->link_duplex == FULL_DUPLEX) ?
2875 "Full Duplex" : "Half Duplex",
2876 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
2878 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
2879 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
2883 * e1000_watchdog - Timer Call-back
2884 * @data: pointer to adapter cast into an unsigned long
2886 static void e1000_watchdog(unsigned long data)
2888 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2890 /* Do the rest outside of interrupt context */
2891 schedule_work(&adapter->watchdog_task);
2893 /* TODO: make this use queue_delayed_work() */
2896 static void e1000_watchdog_task(struct work_struct *work)
2898 struct e1000_adapter *adapter = container_of(work,
2899 struct e1000_adapter, watchdog_task);
2901 struct net_device *netdev = adapter->netdev;
2902 struct e1000_mac_info *mac = &adapter->hw.mac;
2903 struct e1000_ring *tx_ring = adapter->tx_ring;
2904 struct e1000_hw *hw = &adapter->hw;
2909 if ((netif_carrier_ok(netdev)) &&
2910 (er32(STATUS) & E1000_STATUS_LU))
2913 ret_val = mac->ops.check_for_link(hw);
2914 if ((ret_val == E1000_ERR_PHY) &&
2915 (adapter->hw.phy.type == e1000_phy_igp_3) &&
2917 E1000_PHY_CTRL_GBE_DISABLE)) {
2918 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
2920 "Gigabit has been disabled, downgrading speed\n");
2923 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
2924 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
2925 e1000_update_mng_vlan(adapter);
2927 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2928 !(er32(TXCW) & E1000_TXCW_ANE))
2929 link = adapter->hw.mac.serdes_has_link;
2931 link = er32(STATUS) & E1000_STATUS_LU;
2934 if (!netif_carrier_ok(netdev)) {
2936 mac->ops.get_link_up_info(&adapter->hw,
2937 &adapter->link_speed,
2938 &adapter->link_duplex);
2939 e1000_print_link_info(adapter);
2940 /* tweak tx_queue_len according to speed/duplex
2941 * and adjust the timeout factor */
2942 netdev->tx_queue_len = adapter->tx_queue_len;
2943 adapter->tx_timeout_factor = 1;
2944 switch (adapter->link_speed) {
2947 netdev->tx_queue_len = 10;
2948 adapter->tx_timeout_factor = 14;
2952 netdev->tx_queue_len = 100;
2953 /* maybe add some timeout factor ? */
2957 /* workaround: re-program speed mode bit after
2959 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
2962 tarc0 = er32(TARC0);
2963 tarc0 &= ~SPEED_MODE_BIT;
2967 /* disable TSO for pcie and 10/100 speeds, to avoid
2968 * some hardware issues */
2969 if (!(adapter->flags & FLAG_TSO_FORCE)) {
2970 switch (adapter->link_speed) {
2974 "10/100 speed: disabling TSO\n");
2975 netdev->features &= ~NETIF_F_TSO;
2976 netdev->features &= ~NETIF_F_TSO6;
2979 netdev->features |= NETIF_F_TSO;
2980 netdev->features |= NETIF_F_TSO6;
2988 /* enable transmits in the hardware, need to do this
2989 * after setting TARC0 */
2991 tctl |= E1000_TCTL_EN;
2994 netif_carrier_on(netdev);
2995 netif_wake_queue(netdev);
2997 if (!test_bit(__E1000_DOWN, &adapter->state))
2998 mod_timer(&adapter->phy_info_timer,
2999 round_jiffies(jiffies + 2 * HZ));
3001 /* make sure the receive unit is started */
3002 if (adapter->flags & FLAG_RX_NEEDS_RESTART) {
3003 u32 rctl = er32(RCTL);
3009 if (netif_carrier_ok(netdev)) {
3010 adapter->link_speed = 0;
3011 adapter->link_duplex = 0;
3012 ndev_info(netdev, "Link is Down\n");
3013 netif_carrier_off(netdev);
3014 netif_stop_queue(netdev);
3015 if (!test_bit(__E1000_DOWN, &adapter->state))
3016 mod_timer(&adapter->phy_info_timer,
3017 round_jiffies(jiffies + 2 * HZ));
3019 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3020 schedule_work(&adapter->reset_task);
3025 e1000e_update_stats(adapter);
3027 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
3028 adapter->tpt_old = adapter->stats.tpt;
3029 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
3030 adapter->colc_old = adapter->stats.colc;
3032 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
3033 adapter->gorcl_old = adapter->stats.gorcl;
3034 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
3035 adapter->gotcl_old = adapter->stats.gotcl;
3037 e1000e_update_adaptive(&adapter->hw);
3039 if (!netif_carrier_ok(netdev)) {
3040 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
3043 /* We've lost link, so the controller stops DMA,
3044 * but we've got queued Tx work that's never going
3045 * to get done, so reset controller to flush Tx.
3046 * (Do the reset outside of interrupt context). */
3047 adapter->tx_timeout_count++;
3048 schedule_work(&adapter->reset_task);
3052 /* Cause software interrupt to ensure rx ring is cleaned */
3053 ew32(ICS, E1000_ICS_RXDMT0);
3055 /* Force detection of hung controller every watchdog period */
3056 adapter->detect_tx_hung = 1;
3058 /* With 82571 controllers, LAA may be overwritten due to controller
3059 * reset from the other port. Set the appropriate LAA in RAR[0] */
3060 if (e1000e_get_laa_state_82571(hw))
3061 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
3063 /* Reset the timer */
3064 if (!test_bit(__E1000_DOWN, &adapter->state))
3065 mod_timer(&adapter->watchdog_timer,
3066 round_jiffies(jiffies + 2 * HZ));
3069 #define E1000_TX_FLAGS_CSUM 0x00000001
3070 #define E1000_TX_FLAGS_VLAN 0x00000002
3071 #define E1000_TX_FLAGS_TSO 0x00000004
3072 #define E1000_TX_FLAGS_IPV4 0x00000008
3073 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
3074 #define E1000_TX_FLAGS_VLAN_SHIFT 16
3076 static int e1000_tso(struct e1000_adapter *adapter,
3077 struct sk_buff *skb)
3079 struct e1000_ring *tx_ring = adapter->tx_ring;
3080 struct e1000_context_desc *context_desc;
3081 struct e1000_buffer *buffer_info;
3084 u16 ipcse = 0, tucse, mss;
3085 u8 ipcss, ipcso, tucss, tucso, hdr_len;
3088 if (skb_is_gso(skb)) {
3089 if (skb_header_cloned(skb)) {
3090 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3095 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3096 mss = skb_shinfo(skb)->gso_size;
3097 if (skb->protocol == htons(ETH_P_IP)) {
3098 struct iphdr *iph = ip_hdr(skb);
3101 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3105 cmd_length = E1000_TXD_CMD_IP;
3106 ipcse = skb_transport_offset(skb) - 1;
3107 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3108 ipv6_hdr(skb)->payload_len = 0;
3109 tcp_hdr(skb)->check =
3110 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3111 &ipv6_hdr(skb)->daddr,
3115 ipcss = skb_network_offset(skb);
3116 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
3117 tucss = skb_transport_offset(skb);
3118 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
3121 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
3122 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
3124 i = tx_ring->next_to_use;
3125 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3126 buffer_info = &tx_ring->buffer_info[i];
3128 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3129 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3130 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3131 context_desc->upper_setup.tcp_fields.tucss = tucss;
3132 context_desc->upper_setup.tcp_fields.tucso = tucso;
3133 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3134 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3135 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3136 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3138 buffer_info->time_stamp = jiffies;
3139 buffer_info->next_to_watch = i;
3142 if (i == tx_ring->count)
3144 tx_ring->next_to_use = i;
3152 static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
3154 struct e1000_ring *tx_ring = adapter->tx_ring;
3155 struct e1000_context_desc *context_desc;
3156 struct e1000_buffer *buffer_info;
3160 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3161 css = skb_transport_offset(skb);
3163 i = tx_ring->next_to_use;
3164 buffer_info = &tx_ring->buffer_info[i];
3165 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3167 context_desc->lower_setup.ip_config = 0;
3168 context_desc->upper_setup.tcp_fields.tucss = css;
3169 context_desc->upper_setup.tcp_fields.tucso =
3170 css + skb->csum_offset;
3171 context_desc->upper_setup.tcp_fields.tucse = 0;
3172 context_desc->tcp_seg_setup.data = 0;
3173 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
3175 buffer_info->time_stamp = jiffies;
3176 buffer_info->next_to_watch = i;
3179 if (i == tx_ring->count)
3181 tx_ring->next_to_use = i;
3189 #define E1000_MAX_PER_TXD 8192
3190 #define E1000_MAX_TXD_PWR 12
3192 static int e1000_tx_map(struct e1000_adapter *adapter,
3193 struct sk_buff *skb, unsigned int first,
3194 unsigned int max_per_txd, unsigned int nr_frags,
3197 struct e1000_ring *tx_ring = adapter->tx_ring;
3198 struct e1000_buffer *buffer_info;
3199 unsigned int len = skb->len - skb->data_len;
3200 unsigned int offset = 0, size, count = 0, i;
3203 i = tx_ring->next_to_use;
3206 buffer_info = &tx_ring->buffer_info[i];
3207 size = min(len, max_per_txd);
3209 /* Workaround for premature desc write-backs
3210 * in TSO mode. Append 4-byte sentinel desc */
3211 if (mss && !nr_frags && size == len && size > 8)
3214 buffer_info->length = size;
3215 /* set time_stamp *before* dma to help avoid a possible race */
3216 buffer_info->time_stamp = jiffies;
3218 pci_map_single(adapter->pdev,
3222 if (pci_dma_mapping_error(buffer_info->dma)) {
3223 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
3224 adapter->tx_dma_failed++;
3227 buffer_info->next_to_watch = i;
3233 if (i == tx_ring->count)
3237 for (f = 0; f < nr_frags; f++) {
3238 struct skb_frag_struct *frag;
3240 frag = &skb_shinfo(skb)->frags[f];
3242 offset = frag->page_offset;
3245 buffer_info = &tx_ring->buffer_info[i];
3246 size = min(len, max_per_txd);
3247 /* Workaround for premature desc write-backs
3248 * in TSO mode. Append 4-byte sentinel desc */
3249 if (mss && f == (nr_frags-1) && size == len && size > 8)
3252 buffer_info->length = size;
3253 buffer_info->time_stamp = jiffies;
3255 pci_map_page(adapter->pdev,
3260 if (pci_dma_mapping_error(buffer_info->dma)) {
3261 dev_err(&adapter->pdev->dev,
3262 "TX DMA page map failed\n");
3263 adapter->tx_dma_failed++;
3267 buffer_info->next_to_watch = i;
3274 if (i == tx_ring->count)
3280 i = tx_ring->count - 1;
3284 tx_ring->buffer_info[i].skb = skb;
3285 tx_ring->buffer_info[first].next_to_watch = i;
3290 static void e1000_tx_queue(struct e1000_adapter *adapter,
3291 int tx_flags, int count)
3293 struct e1000_ring *tx_ring = adapter->tx_ring;
3294 struct e1000_tx_desc *tx_desc = NULL;
3295 struct e1000_buffer *buffer_info;
3296 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3299 if (tx_flags & E1000_TX_FLAGS_TSO) {
3300 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3302 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3304 if (tx_flags & E1000_TX_FLAGS_IPV4)
3305 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3308 if (tx_flags & E1000_TX_FLAGS_CSUM) {
3309 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3310 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3313 if (tx_flags & E1000_TX_FLAGS_VLAN) {
3314 txd_lower |= E1000_TXD_CMD_VLE;
3315 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3318 i = tx_ring->next_to_use;
3321 buffer_info = &tx_ring->buffer_info[i];
3322 tx_desc = E1000_TX_DESC(*tx_ring, i);
3323 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3324 tx_desc->lower.data =
3325 cpu_to_le32(txd_lower | buffer_info->length);
3326 tx_desc->upper.data = cpu_to_le32(txd_upper);
3329 if (i == tx_ring->count)
3333 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3335 /* Force memory writes to complete before letting h/w
3336 * know there are new descriptors to fetch. (Only
3337 * applicable for weak-ordered memory model archs,
3338 * such as IA-64). */
3341 tx_ring->next_to_use = i;
3342 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3343 /* we need this if more than one processor can write to our tail
3344 * at a time, it synchronizes IO on IA64/Altix systems */
3348 #define MINIMUM_DHCP_PACKET_SIZE 282
3349 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3350 struct sk_buff *skb)
3352 struct e1000_hw *hw = &adapter->hw;
3355 if (vlan_tx_tag_present(skb)) {
3356 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id)
3357 && (adapter->hw.mng_cookie.status &
3358 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
3362 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
3365 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
3369 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
3372 if (ip->protocol != IPPROTO_UDP)
3375 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
3376 if (ntohs(udp->dest) != 67)
3379 offset = (u8 *)udp + 8 - skb->data;
3380 length = skb->len - offset;
3381 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
3387 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3389 struct e1000_adapter *adapter = netdev_priv(netdev);
3391 netif_stop_queue(netdev);
3392 /* Herbert's original patch had:
3393 * smp_mb__after_netif_stop_queue();
3394 * but since that doesn't exist yet, just open code it. */
3397 /* We need to check again in a case another CPU has just
3398 * made room available. */
3399 if (e1000_desc_unused(adapter->tx_ring) < size)
3403 netif_start_queue(netdev);
3404 ++adapter->restart_queue;
3408 static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
3410 struct e1000_adapter *adapter = netdev_priv(netdev);
3412 if (e1000_desc_unused(adapter->tx_ring) >= size)
3414 return __e1000_maybe_stop_tx(netdev, size);
3417 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3418 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3420 struct e1000_adapter *adapter = netdev_priv(netdev);
3421 struct e1000_ring *tx_ring = adapter->tx_ring;
3423 unsigned int max_per_txd = E1000_MAX_PER_TXD;
3424 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3425 unsigned int tx_flags = 0;
3426 unsigned int len = skb->len - skb->data_len;
3427 unsigned long irq_flags;
3428 unsigned int nr_frags;
3434 if (test_bit(__E1000_DOWN, &adapter->state)) {
3435 dev_kfree_skb_any(skb);
3436 return NETDEV_TX_OK;
3439 if (skb->len <= 0) {
3440 dev_kfree_skb_any(skb);
3441 return NETDEV_TX_OK;
3444 mss = skb_shinfo(skb)->gso_size;
3445 /* The controller does a simple calculation to
3446 * make sure there is enough room in the FIFO before
3447 * initiating the DMA for each buffer. The calc is:
3448 * 4 = ceil(buffer len/mss). To make sure we don't
3449 * overrun the FIFO, adjust the max buffer len if mss
3453 max_per_txd = min(mss << 2, max_per_txd);
3454 max_txd_pwr = fls(max_per_txd) - 1;
3456 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3457 * points to just header, pull a few bytes of payload from
3458 * frags into skb->data */
3459 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3460 if (skb->data_len && (hdr_len == len)) {
3461 unsigned int pull_size;
3463 pull_size = min((unsigned int)4, skb->data_len);
3464 if (!__pskb_pull_tail(skb, pull_size)) {
3466 "__pskb_pull_tail failed.\n");
3467 dev_kfree_skb_any(skb);
3468 return NETDEV_TX_OK;
3470 len = skb->len - skb->data_len;
3474 /* reserve a descriptor for the offload context */
3475 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3479 count += TXD_USE_COUNT(len, max_txd_pwr);
3481 nr_frags = skb_shinfo(skb)->nr_frags;
3482 for (f = 0; f < nr_frags; f++)
3483 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3486 if (adapter->hw.mac.tx_pkt_filtering)
3487 e1000_transfer_dhcp_info(adapter, skb);
3489 if (!spin_trylock_irqsave(&adapter->tx_queue_lock, irq_flags))
3490 /* Collision - tell upper layer to requeue */
3491 return NETDEV_TX_LOCKED;
3493 /* need: count + 2 desc gap to keep tail from touching
3494 * head, otherwise try next time */
3495 if (e1000_maybe_stop_tx(netdev, count + 2)) {
3496 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3497 return NETDEV_TX_BUSY;
3500 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3501 tx_flags |= E1000_TX_FLAGS_VLAN;
3502 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3505 first = tx_ring->next_to_use;
3507 tso = e1000_tso(adapter, skb);
3509 dev_kfree_skb_any(skb);
3510 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3511 return NETDEV_TX_OK;
3515 tx_flags |= E1000_TX_FLAGS_TSO;
3516 else if (e1000_tx_csum(adapter, skb))
3517 tx_flags |= E1000_TX_FLAGS_CSUM;
3519 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3520 * 82571 hardware supports TSO capabilities for IPv6 as well...
3521 * no longer assume, we must. */
3522 if (skb->protocol == htons(ETH_P_IP))
3523 tx_flags |= E1000_TX_FLAGS_IPV4;
3525 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
3527 /* handle pci_map_single() error in e1000_tx_map */
3528 dev_kfree_skb_any(skb);
3529 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3530 return NETDEV_TX_OK;
3533 e1000_tx_queue(adapter, tx_flags, count);
3535 netdev->trans_start = jiffies;
3537 /* Make sure there is space in the ring for the next send. */
3538 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
3540 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3541 return NETDEV_TX_OK;
3545 * e1000_tx_timeout - Respond to a Tx Hang
3546 * @netdev: network interface device structure
3548 static void e1000_tx_timeout(struct net_device *netdev)
3550 struct e1000_adapter *adapter = netdev_priv(netdev);
3552 /* Do the reset outside of interrupt context */
3553 adapter->tx_timeout_count++;
3554 schedule_work(&adapter->reset_task);
3557 static void e1000_reset_task(struct work_struct *work)
3559 struct e1000_adapter *adapter;
3560 adapter = container_of(work, struct e1000_adapter, reset_task);
3562 e1000e_reinit_locked(adapter);
3566 * e1000_get_stats - Get System Network Statistics
3567 * @netdev: network interface device structure
3569 * Returns the address of the device statistics structure.
3570 * The statistics are actually updated from the timer callback.
3572 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3574 struct e1000_adapter *adapter = netdev_priv(netdev);
3576 /* only return the current stats */
3577 return &adapter->net_stats;
3581 * e1000_change_mtu - Change the Maximum Transfer Unit
3582 * @netdev: network interface device structure
3583 * @new_mtu: new value for maximum frame size
3585 * Returns 0 on success, negative on failure
3587 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3589 struct e1000_adapter *adapter = netdev_priv(netdev);
3590 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3592 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
3593 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3594 ndev_err(netdev, "Invalid MTU setting\n");
3598 /* Jumbo frame size limits */
3599 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
3600 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
3601 ndev_err(netdev, "Jumbo Frames not supported.\n");
3604 if (adapter->hw.phy.type == e1000_phy_ife) {
3605 ndev_err(netdev, "Jumbo Frames not supported.\n");
3610 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3611 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3612 ndev_err(netdev, "MTU > 9216 not supported.\n");
3616 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3618 /* e1000e_down has a dependency on max_frame_size */
3619 adapter->hw.mac.max_frame_size = max_frame;
3620 if (netif_running(netdev))
3621 e1000e_down(adapter);
3623 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3624 * means we reserve 2 more, this pushes us to allocate from the next
3626 * i.e. RXBUFFER_2048 --> size-4096 slab
3627 * however with the new *_jumbo* routines, jumbo receives will use
3628 * fragmented skbs */
3630 if (max_frame <= 256)
3631 adapter->rx_buffer_len = 256;
3632 else if (max_frame <= 512)
3633 adapter->rx_buffer_len = 512;
3634 else if (max_frame <= 1024)
3635 adapter->rx_buffer_len = 1024;
3636 else if (max_frame <= 2048)
3637 adapter->rx_buffer_len = 2048;
3639 adapter->rx_buffer_len = 4096;
3641 /* adjust allocation if LPE protects us, and we aren't using SBP */
3642 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
3643 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
3644 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
3647 ndev_info(netdev, "changing MTU from %d to %d\n",
3648 netdev->mtu, new_mtu);
3649 netdev->mtu = new_mtu;
3651 if (netif_running(netdev))
3654 e1000e_reset(adapter);
3656 clear_bit(__E1000_RESETTING, &adapter->state);
3661 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
3664 struct e1000_adapter *adapter = netdev_priv(netdev);
3665 struct mii_ioctl_data *data = if_mii(ifr);
3666 unsigned long irq_flags;
3668 if (adapter->hw.media_type != e1000_media_type_copper)
3673 data->phy_id = adapter->hw.phy.addr;
3676 if (!capable(CAP_NET_ADMIN))
3678 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
3679 if (e1e_rphy(&adapter->hw, data->reg_num & 0x1F,
3681 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
3684 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
3693 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3699 return e1000_mii_ioctl(netdev, ifr, cmd);
3705 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
3707 struct net_device *netdev = pci_get_drvdata(pdev);
3708 struct e1000_adapter *adapter = netdev_priv(netdev);
3709 struct e1000_hw *hw = &adapter->hw;
3710 u32 ctrl, ctrl_ext, rctl, status;
3711 u32 wufc = adapter->wol;
3714 netif_device_detach(netdev);
3716 if (netif_running(netdev)) {
3717 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3718 e1000e_down(adapter);
3719 e1000_free_irq(adapter);
3722 retval = pci_save_state(pdev);
3726 status = er32(STATUS);
3727 if (status & E1000_STATUS_LU)
3728 wufc &= ~E1000_WUFC_LNKC;
3731 e1000_setup_rctl(adapter);
3732 e1000_set_multi(netdev);
3734 /* turn on all-multi mode if wake on multicast is enabled */
3735 if (wufc & E1000_WUFC_MC) {
3737 rctl |= E1000_RCTL_MPE;
3742 /* advertise wake from D3Cold */
3743 #define E1000_CTRL_ADVD3WUC 0x00100000
3744 /* phy power management enable */
3745 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3746 ctrl |= E1000_CTRL_ADVD3WUC |
3747 E1000_CTRL_EN_PHY_PWR_MGMT;
3750 if (adapter->hw.media_type == e1000_media_type_fiber ||
3751 adapter->hw.media_type == e1000_media_type_internal_serdes) {
3752 /* keep the laser running in D3 */
3753 ctrl_ext = er32(CTRL_EXT);
3754 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
3755 ew32(CTRL_EXT, ctrl_ext);
3758 /* Allow time for pending master requests to run */
3759 e1000e_disable_pcie_master(&adapter->hw);
3761 ew32(WUC, E1000_WUC_PME_EN);
3763 pci_enable_wake(pdev, PCI_D3hot, 1);
3764 pci_enable_wake(pdev, PCI_D3cold, 1);
3768 pci_enable_wake(pdev, PCI_D3hot, 0);
3769 pci_enable_wake(pdev, PCI_D3cold, 0);
3772 e1000_release_manageability(adapter);
3774 /* make sure adapter isn't asleep if manageability is enabled */
3775 if (adapter->flags & FLAG_MNG_PT_ENABLED) {
3776 pci_enable_wake(pdev, PCI_D3hot, 1);
3777 pci_enable_wake(pdev, PCI_D3cold, 1);
3780 if (adapter->hw.phy.type == e1000_phy_igp_3)
3781 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
3783 /* Release control of h/w to f/w. If f/w is AMT enabled, this
3784 * would have already happened in close and is redundant. */
3785 e1000_release_hw_control(adapter);
3787 pci_disable_device(pdev);
3789 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3795 static int e1000_resume(struct pci_dev *pdev)
3797 struct net_device *netdev = pci_get_drvdata(pdev);
3798 struct e1000_adapter *adapter = netdev_priv(netdev);
3799 struct e1000_hw *hw = &adapter->hw;
3802 pci_set_power_state(pdev, PCI_D0);
3803 pci_restore_state(pdev);
3804 err = pci_enable_device(pdev);
3807 "Cannot enable PCI device from suspend\n");
3811 pci_set_master(pdev);
3813 pci_enable_wake(pdev, PCI_D3hot, 0);
3814 pci_enable_wake(pdev, PCI_D3cold, 0);
3816 if (netif_running(netdev)) {
3817 err = e1000_request_irq(adapter);
3822 e1000e_power_up_phy(adapter);
3823 e1000e_reset(adapter);
3826 e1000_init_manageability(adapter);
3828 if (netif_running(netdev))
3831 netif_device_attach(netdev);
3833 /* If the controller has AMT, do not set DRV_LOAD until the interface
3834 * is up. For all other cases, let the f/w know that the h/w is now
3835 * under the control of the driver. */
3836 if (!(adapter->flags & FLAG_HAS_AMT) || !e1000e_check_mng_mode(&adapter->hw))
3837 e1000_get_hw_control(adapter);
3843 static void e1000_shutdown(struct pci_dev *pdev)
3845 e1000_suspend(pdev, PMSG_SUSPEND);
3848 #ifdef CONFIG_NET_POLL_CONTROLLER
3850 * Polling 'interrupt' - used by things like netconsole to send skbs
3851 * without having to re-enable interrupts. It's not called while
3852 * the interrupt routine is executing.
3854 static void e1000_netpoll(struct net_device *netdev)
3856 struct e1000_adapter *adapter = netdev_priv(netdev);
3858 disable_irq(adapter->pdev->irq);
3859 e1000_intr(adapter->pdev->irq, netdev);
3861 e1000_clean_tx_irq(adapter);
3863 enable_irq(adapter->pdev->irq);
3868 * e1000_io_error_detected - called when PCI error is detected
3869 * @pdev: Pointer to PCI device
3870 * @state: The current pci connection state
3872 * This function is called after a PCI bus error affecting
3873 * this device has been detected.
3875 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
3876 pci_channel_state_t state)
3878 struct net_device *netdev = pci_get_drvdata(pdev);
3879 struct e1000_adapter *adapter = netdev_priv(netdev);
3881 netif_device_detach(netdev);
3883 if (netif_running(netdev))
3884 e1000e_down(adapter);
3885 pci_disable_device(pdev);
3887 /* Request a slot slot reset. */
3888 return PCI_ERS_RESULT_NEED_RESET;
3892 * e1000_io_slot_reset - called after the pci bus has been reset.
3893 * @pdev: Pointer to PCI device
3895 * Restart the card from scratch, as if from a cold-boot. Implementation
3896 * resembles the first-half of the e1000_resume routine.
3898 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
3900 struct net_device *netdev = pci_get_drvdata(pdev);
3901 struct e1000_adapter *adapter = netdev_priv(netdev);
3902 struct e1000_hw *hw = &adapter->hw;
3904 if (pci_enable_device(pdev)) {
3906 "Cannot re-enable PCI device after reset.\n");
3907 return PCI_ERS_RESULT_DISCONNECT;
3909 pci_set_master(pdev);
3911 pci_enable_wake(pdev, PCI_D3hot, 0);
3912 pci_enable_wake(pdev, PCI_D3cold, 0);
3914 e1000e_reset(adapter);
3917 return PCI_ERS_RESULT_RECOVERED;
3921 * e1000_io_resume - called when traffic can start flowing again.
3922 * @pdev: Pointer to PCI device
3924 * This callback is called when the error recovery driver tells us that
3925 * its OK to resume normal operation. Implementation resembles the
3926 * second-half of the e1000_resume routine.
3928 static void e1000_io_resume(struct pci_dev *pdev)
3930 struct net_device *netdev = pci_get_drvdata(pdev);
3931 struct e1000_adapter *adapter = netdev_priv(netdev);
3933 e1000_init_manageability(adapter);
3935 if (netif_running(netdev)) {
3936 if (e1000e_up(adapter)) {
3938 "can't bring device back up after reset\n");
3943 netif_device_attach(netdev);
3945 /* If the controller has AMT, do not set DRV_LOAD until the interface
3946 * is up. For all other cases, let the f/w know that the h/w is now
3947 * under the control of the driver. */
3948 if (!(adapter->flags & FLAG_HAS_AMT) ||
3949 !e1000e_check_mng_mode(&adapter->hw))
3950 e1000_get_hw_control(adapter);
3954 static void e1000_print_device_info(struct e1000_adapter *adapter)
3956 struct e1000_hw *hw = &adapter->hw;
3957 struct net_device *netdev = adapter->netdev;
3960 /* print bus type/speed/width info */
3961 ndev_info(netdev, "(PCI Express:2.5GB/s:%s) "
3962 "%02x:%02x:%02x:%02x:%02x:%02x\n",
3964 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
3967 netdev->dev_addr[0], netdev->dev_addr[1],
3968 netdev->dev_addr[2], netdev->dev_addr[3],
3969 netdev->dev_addr[4], netdev->dev_addr[5]);
3970 ndev_info(netdev, "Intel(R) PRO/%s Network Connection\n",
3971 (hw->phy.type == e1000_phy_ife)
3972 ? "10/100" : "1000");
3973 e1000e_read_part_num(hw, &part_num);
3974 ndev_info(netdev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
3975 hw->mac.type, hw->phy.type,
3976 (part_num >> 8), (part_num & 0xff));
3980 * e1000_probe - Device Initialization Routine
3981 * @pdev: PCI device information struct
3982 * @ent: entry in e1000_pci_tbl
3984 * Returns 0 on success, negative on failure
3986 * e1000_probe initializes an adapter identified by a pci_dev structure.
3987 * The OS initialization, configuring of the adapter private structure,
3988 * and a hardware reset occur.
3990 static int __devinit e1000_probe(struct pci_dev *pdev,
3991 const struct pci_device_id *ent)
3993 struct net_device *netdev;
3994 struct e1000_adapter *adapter;
3995 struct e1000_hw *hw;
3996 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
3997 unsigned long mmio_start, mmio_len;
3998 unsigned long flash_start, flash_len;
4000 static int cards_found;
4001 int i, err, pci_using_dac;
4002 u16 eeprom_data = 0;
4003 u16 eeprom_apme_mask = E1000_EEPROM_APME;
4005 err = pci_enable_device(pdev);
4010 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
4012 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
4016 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4018 err = pci_set_consistent_dma_mask(pdev,
4021 dev_err(&pdev->dev, "No usable DMA "
4022 "configuration, aborting\n");
4028 err = pci_request_regions(pdev, e1000e_driver_name);
4032 pci_set_master(pdev);
4035 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
4037 goto err_alloc_etherdev;
4039 SET_NETDEV_DEV(netdev, &pdev->dev);
4041 pci_set_drvdata(pdev, netdev);
4042 adapter = netdev_priv(netdev);
4044 adapter->netdev = netdev;
4045 adapter->pdev = pdev;
4047 adapter->pba = ei->pba;
4048 adapter->flags = ei->flags;
4049 adapter->hw.adapter = adapter;
4050 adapter->hw.mac.type = ei->mac;
4051 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
4053 mmio_start = pci_resource_start(pdev, 0);
4054 mmio_len = pci_resource_len(pdev, 0);
4057 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
4058 if (!adapter->hw.hw_addr)
4061 if ((adapter->flags & FLAG_HAS_FLASH) &&
4062 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
4063 flash_start = pci_resource_start(pdev, 1);
4064 flash_len = pci_resource_len(pdev, 1);
4065 adapter->hw.flash_address = ioremap(flash_start, flash_len);
4066 if (!adapter->hw.flash_address)
4070 /* construct the net_device struct */
4071 netdev->open = &e1000_open;
4072 netdev->stop = &e1000_close;
4073 netdev->hard_start_xmit = &e1000_xmit_frame;
4074 netdev->get_stats = &e1000_get_stats;
4075 netdev->set_multicast_list = &e1000_set_multi;
4076 netdev->set_mac_address = &e1000_set_mac;
4077 netdev->change_mtu = &e1000_change_mtu;
4078 netdev->do_ioctl = &e1000_ioctl;
4079 e1000e_set_ethtool_ops(netdev);
4080 netdev->tx_timeout = &e1000_tx_timeout;
4081 netdev->watchdog_timeo = 5 * HZ;
4082 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
4083 netdev->vlan_rx_register = e1000_vlan_rx_register;
4084 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
4085 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
4086 #ifdef CONFIG_NET_POLL_CONTROLLER
4087 netdev->poll_controller = e1000_netpoll;
4089 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
4091 netdev->mem_start = mmio_start;
4092 netdev->mem_end = mmio_start + mmio_len;
4094 adapter->bd_number = cards_found++;
4096 /* setup adapter struct */
4097 err = e1000_sw_init(adapter);
4103 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
4104 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
4105 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
4107 err = ei->get_invariants(adapter);
4111 hw->mac.ops.get_bus_info(&adapter->hw);
4113 adapter->hw.phy.wait_for_link = 0;
4115 /* Copper options */
4116 if (adapter->hw.media_type == e1000_media_type_copper) {
4117 adapter->hw.phy.mdix = AUTO_ALL_MODES;
4118 adapter->hw.phy.disable_polarity_correction = 0;
4119 adapter->hw.phy.ms_type = e1000_ms_hw_default;
4122 if (e1000_check_reset_block(&adapter->hw))
4124 "PHY reset is blocked due to SOL/IDER session.\n");
4126 netdev->features = NETIF_F_SG |
4128 NETIF_F_HW_VLAN_TX |
4131 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
4132 netdev->features |= NETIF_F_HW_VLAN_FILTER;
4134 netdev->features |= NETIF_F_TSO;
4135 netdev->features |= NETIF_F_TSO6;
4138 netdev->features |= NETIF_F_HIGHDMA;
4140 /* We should not be using LLTX anymore, but we are still TX faster with
4142 netdev->features |= NETIF_F_LLTX;
4144 if (e1000e_enable_mng_pass_thru(&adapter->hw))
4145 adapter->flags |= FLAG_MNG_PT_ENABLED;
4147 /* before reading the NVM, reset the controller to
4148 * put the device in a known good starting state */
4149 adapter->hw.mac.ops.reset_hw(&adapter->hw);
4152 * systems with ASPM and others may see the checksum fail on the first
4153 * attempt. Let's give it a few tries
4156 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
4159 ndev_err(netdev, "The NVM Checksum Is Not Valid\n");
4165 /* copy the MAC address out of the NVM */
4166 if (e1000e_read_mac_addr(&adapter->hw))
4167 ndev_err(netdev, "NVM Read Error while reading MAC address\n");
4169 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
4170 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
4172 if (!is_valid_ether_addr(netdev->perm_addr)) {
4173 ndev_err(netdev, "Invalid MAC Address: "
4174 "%02x:%02x:%02x:%02x:%02x:%02x\n",
4175 netdev->perm_addr[0], netdev->perm_addr[1],
4176 netdev->perm_addr[2], netdev->perm_addr[3],
4177 netdev->perm_addr[4], netdev->perm_addr[5]);
4182 init_timer(&adapter->watchdog_timer);
4183 adapter->watchdog_timer.function = &e1000_watchdog;
4184 adapter->watchdog_timer.data = (unsigned long) adapter;
4186 init_timer(&adapter->phy_info_timer);
4187 adapter->phy_info_timer.function = &e1000_update_phy_info;
4188 adapter->phy_info_timer.data = (unsigned long) adapter;
4190 INIT_WORK(&adapter->reset_task, e1000_reset_task);
4191 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
4193 e1000e_check_options(adapter);
4195 /* Initialize link parameters. User can change them with ethtool */
4196 adapter->hw.mac.autoneg = 1;
4197 adapter->fc_autoneg = 1;
4198 adapter->hw.mac.original_fc = e1000_fc_default;
4199 adapter->hw.mac.fc = e1000_fc_default;
4200 adapter->hw.phy.autoneg_advertised = 0x2f;
4202 /* ring size defaults */
4203 adapter->rx_ring->count = 256;
4204 adapter->tx_ring->count = 256;
4207 * Initial Wake on LAN setting - If APM wake is enabled in
4208 * the EEPROM, enable the ACPI Magic Packet filter
4210 if (adapter->flags & FLAG_APME_IN_WUC) {
4211 /* APME bit in EEPROM is mapped to WUC.APME */
4212 eeprom_data = er32(WUC);
4213 eeprom_apme_mask = E1000_WUC_APME;
4214 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
4215 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
4216 (adapter->hw.bus.func == 1))
4217 e1000_read_nvm(&adapter->hw,
4218 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
4220 e1000_read_nvm(&adapter->hw,
4221 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
4224 /* fetch WoL from EEPROM */
4225 if (eeprom_data & eeprom_apme_mask)
4226 adapter->eeprom_wol |= E1000_WUFC_MAG;
4229 * now that we have the eeprom settings, apply the special cases
4230 * where the eeprom may be wrong or the board simply won't support
4231 * wake on lan on a particular port
4233 if (!(adapter->flags & FLAG_HAS_WOL))
4234 adapter->eeprom_wol = 0;
4236 /* initialize the wol settings based on the eeprom settings */
4237 adapter->wol = adapter->eeprom_wol;
4239 /* reset the hardware with the new settings */
4240 e1000e_reset(adapter);
4242 /* If the controller has AMT, do not set DRV_LOAD until the interface
4243 * is up. For all other cases, let the f/w know that the h/w is now
4244 * under the control of the driver. */
4245 if (!(adapter->flags & FLAG_HAS_AMT) ||
4246 !e1000e_check_mng_mode(&adapter->hw))
4247 e1000_get_hw_control(adapter);
4249 /* tell the stack to leave us alone until e1000_open() is called */
4250 netif_carrier_off(netdev);
4251 netif_stop_queue(netdev);
4253 strcpy(netdev->name, "eth%d");
4254 err = register_netdev(netdev);
4258 e1000_print_device_info(adapter);
4264 e1000_release_hw_control(adapter);
4266 if (!e1000_check_reset_block(&adapter->hw))
4267 e1000_phy_hw_reset(&adapter->hw);
4269 if (adapter->hw.flash_address)
4270 iounmap(adapter->hw.flash_address);
4273 kfree(adapter->tx_ring);
4274 kfree(adapter->rx_ring);
4276 iounmap(adapter->hw.hw_addr);
4278 free_netdev(netdev);
4280 pci_release_regions(pdev);
4283 pci_disable_device(pdev);
4288 * e1000_remove - Device Removal Routine
4289 * @pdev: PCI device information struct
4291 * e1000_remove is called by the PCI subsystem to alert the driver
4292 * that it should release a PCI device. The could be caused by a
4293 * Hot-Plug event, or because the driver is going to be removed from
4296 static void __devexit e1000_remove(struct pci_dev *pdev)
4298 struct net_device *netdev = pci_get_drvdata(pdev);
4299 struct e1000_adapter *adapter = netdev_priv(netdev);
4301 /* flush_scheduled work may reschedule our watchdog task, so
4302 * explicitly disable watchdog tasks from being rescheduled */
4303 set_bit(__E1000_DOWN, &adapter->state);
4304 del_timer_sync(&adapter->watchdog_timer);
4305 del_timer_sync(&adapter->phy_info_timer);
4307 flush_scheduled_work();
4309 e1000_release_manageability(adapter);
4311 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4312 * would have already happened in close and is redundant. */
4313 e1000_release_hw_control(adapter);
4315 unregister_netdev(netdev);
4317 if (!e1000_check_reset_block(&adapter->hw))
4318 e1000_phy_hw_reset(&adapter->hw);
4320 kfree(adapter->tx_ring);
4321 kfree(adapter->rx_ring);
4323 iounmap(adapter->hw.hw_addr);
4324 if (adapter->hw.flash_address)
4325 iounmap(adapter->hw.flash_address);
4326 pci_release_regions(pdev);
4328 free_netdev(netdev);
4330 pci_disable_device(pdev);
4333 /* PCI Error Recovery (ERS) */
4334 static struct pci_error_handlers e1000_err_handler = {
4335 .error_detected = e1000_io_error_detected,
4336 .slot_reset = e1000_io_slot_reset,
4337 .resume = e1000_io_resume,
4340 static struct pci_device_id e1000_pci_tbl[] = {
4342 * Support for 82571/2/3, es2lan and ich8 will be phased in
4345 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
4346 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
4347 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
4348 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
4349 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
4350 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
4351 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
4352 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
4353 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
4354 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
4355 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
4356 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
4357 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
4358 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
4359 board_80003es2lan },
4360 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
4361 board_80003es2lan },
4362 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
4363 board_80003es2lan },
4364 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
4365 board_80003es2lan },
4366 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
4367 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
4368 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
4369 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
4370 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
4371 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
4372 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
4375 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
4376 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
4377 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
4378 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
4379 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
4381 { } /* terminate list */
4383 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
4385 /* PCI Device API Driver */
4386 static struct pci_driver e1000_driver = {
4387 .name = e1000e_driver_name,
4388 .id_table = e1000_pci_tbl,
4389 .probe = e1000_probe,
4390 .remove = __devexit_p(e1000_remove),
4392 /* Power Managment Hooks */
4393 .suspend = e1000_suspend,
4394 .resume = e1000_resume,
4396 .shutdown = e1000_shutdown,
4397 .err_handler = &e1000_err_handler
4401 * e1000_init_module - Driver Registration Routine
4403 * e1000_init_module is the first routine called when the driver is
4404 * loaded. All it does is register with the PCI subsystem.
4406 static int __init e1000_init_module(void)
4409 printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
4410 e1000e_driver_name, e1000e_driver_version);
4411 printk(KERN_INFO "%s: Copyright (c) 1999-2007 Intel Corporation.\n",
4412 e1000e_driver_name);
4413 ret = pci_register_driver(&e1000_driver);
4417 module_init(e1000_init_module);
4420 * e1000_exit_module - Driver Exit Cleanup Routine
4422 * e1000_exit_module is called just before the driver is removed
4425 static void __exit e1000_exit_module(void)
4427 pci_unregister_driver(&e1000_driver);
4429 module_exit(e1000_exit_module);
4432 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
4433 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
4434 MODULE_LICENSE("GPL");
4435 MODULE_VERSION(DRV_VERSION);