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 struct e1000_adapter *adapter = hw->back;
70 struct net_device *netdev = adapter->netdev;
76 * e1000_desc_unused - calculate if we have unused descriptors
78 static int e1000_desc_unused(struct e1000_ring *ring)
80 if (ring->next_to_clean > ring->next_to_use)
81 return ring->next_to_clean - ring->next_to_use - 1;
83 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
87 * e1000_receive_skb - helper function to handle rx indications
88 * @adapter: board private structure
89 * @status: descriptor status field as written by hardware
90 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
91 * @skb: pointer to sk_buff to be indicated to stack
93 static void e1000_receive_skb(struct e1000_adapter *adapter,
94 struct net_device *netdev,
98 skb->protocol = eth_type_trans(skb, netdev);
100 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
101 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
103 E1000_RXD_SPC_VLAN_MASK);
105 netif_receive_skb(skb);
107 netdev->last_rx = jiffies;
111 * e1000_rx_checksum - Receive Checksum Offload for 82543
112 * @adapter: board private structure
113 * @status_err: receive descriptor status and error fields
114 * @csum: receive descriptor csum field
115 * @sk_buff: socket buffer with received data
117 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
118 u32 csum, struct sk_buff *skb)
120 u16 status = (u16)status_err;
121 u8 errors = (u8)(status_err >> 24);
122 skb->ip_summed = CHECKSUM_NONE;
124 /* Ignore Checksum bit is set */
125 if (status & E1000_RXD_STAT_IXSM)
127 /* TCP/UDP checksum error bit is set */
128 if (errors & E1000_RXD_ERR_TCPE) {
129 /* let the stack verify checksum errors */
130 adapter->hw_csum_err++;
134 /* TCP/UDP Checksum has not been calculated */
135 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
138 /* It must be a TCP or UDP packet with a valid checksum */
139 if (status & E1000_RXD_STAT_TCPCS) {
140 /* TCP checksum is good */
141 skb->ip_summed = CHECKSUM_UNNECESSARY;
143 /* IP fragment with UDP payload */
144 /* Hardware complements the payload checksum, so we undo it
145 * and then put the value in host order for further stack use.
147 csum = ntohl(csum ^ 0xFFFF);
149 skb->ip_summed = CHECKSUM_COMPLETE;
151 adapter->hw_csum_good++;
155 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
156 * @adapter: address of board private structure
158 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
161 struct net_device *netdev = adapter->netdev;
162 struct pci_dev *pdev = adapter->pdev;
163 struct e1000_ring *rx_ring = adapter->rx_ring;
164 struct e1000_rx_desc *rx_desc;
165 struct e1000_buffer *buffer_info;
168 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
170 i = rx_ring->next_to_use;
171 buffer_info = &rx_ring->buffer_info[i];
173 while (cleaned_count--) {
174 skb = buffer_info->skb;
180 skb = netdev_alloc_skb(netdev, bufsz);
182 /* Better luck next round */
183 adapter->alloc_rx_buff_failed++;
187 /* Make buffer alignment 2 beyond a 16 byte boundary
188 * this will result in a 16 byte aligned IP header after
189 * the 14 byte MAC header is removed
191 skb_reserve(skb, NET_IP_ALIGN);
193 buffer_info->skb = skb;
195 buffer_info->dma = pci_map_single(pdev, skb->data,
196 adapter->rx_buffer_len,
198 if (pci_dma_mapping_error(buffer_info->dma)) {
199 dev_err(&pdev->dev, "RX DMA map failed\n");
200 adapter->rx_dma_failed++;
204 rx_desc = E1000_RX_DESC(*rx_ring, i);
205 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
208 if (i == rx_ring->count)
210 buffer_info = &rx_ring->buffer_info[i];
213 if (rx_ring->next_to_use != i) {
214 rx_ring->next_to_use = i;
216 i = (rx_ring->count - 1);
218 /* Force memory writes to complete before letting h/w
219 * know there are new descriptors to fetch. (Only
220 * applicable for weak-ordered memory model archs,
223 writel(i, adapter->hw.hw_addr + rx_ring->tail);
228 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
229 * @adapter: address of board private structure
231 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
234 struct net_device *netdev = adapter->netdev;
235 struct pci_dev *pdev = adapter->pdev;
236 union e1000_rx_desc_packet_split *rx_desc;
237 struct e1000_ring *rx_ring = adapter->rx_ring;
238 struct e1000_buffer *buffer_info;
239 struct e1000_ps_page *ps_page;
243 i = rx_ring->next_to_use;
244 buffer_info = &rx_ring->buffer_info[i];
246 while (cleaned_count--) {
247 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
249 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
250 ps_page = &rx_ring->ps_pages[(i * PS_PAGE_BUFFERS)
252 if (j < adapter->rx_ps_pages) {
253 if (!ps_page->page) {
254 ps_page->page = alloc_page(GFP_ATOMIC);
255 if (!ps_page->page) {
256 adapter->alloc_rx_buff_failed++;
259 ps_page->dma = pci_map_page(pdev,
263 if (pci_dma_mapping_error(
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);
279 rx_desc->read.buffer_addr[j+1] = ~0;
283 skb = netdev_alloc_skb(netdev,
284 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
287 adapter->alloc_rx_buff_failed++;
291 /* Make buffer alignment 2 beyond a 16 byte boundary
292 * this will result in a 16 byte aligned IP header after
293 * the 14 byte MAC header is removed
295 skb_reserve(skb, NET_IP_ALIGN);
297 buffer_info->skb = skb;
298 buffer_info->dma = pci_map_single(pdev, skb->data,
299 adapter->rx_ps_bsize0,
301 if (pci_dma_mapping_error(buffer_info->dma)) {
302 dev_err(&pdev->dev, "RX DMA map failed\n");
303 adapter->rx_dma_failed++;
305 dev_kfree_skb_any(skb);
306 buffer_info->skb = NULL;
310 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
313 if (i == rx_ring->count)
315 buffer_info = &rx_ring->buffer_info[i];
319 if (rx_ring->next_to_use != i) {
320 rx_ring->next_to_use = i;
323 i = (rx_ring->count - 1);
325 /* Force memory writes to complete before letting h/w
326 * know there are new descriptors to fetch. (Only
327 * applicable for weak-ordered memory model archs,
330 /* Hardware increments by 16 bytes, but packet split
331 * descriptors are 32 bytes...so we increment tail
334 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
339 * e1000_alloc_rx_buffers_jumbo - Replace used jumbo receive buffers
341 * @adapter: address of board private structure
342 * @cleaned_count: number of buffers to allocate this pass
344 static void e1000_alloc_rx_buffers_jumbo(struct e1000_adapter *adapter,
347 struct net_device *netdev = adapter->netdev;
348 struct pci_dev *pdev = adapter->pdev;
349 struct e1000_ring *rx_ring = adapter->rx_ring;
350 struct e1000_rx_desc *rx_desc;
351 struct e1000_buffer *buffer_info;
354 unsigned int bufsz = 256 -
355 16 /*for skb_reserve */ -
358 i = rx_ring->next_to_use;
359 buffer_info = &rx_ring->buffer_info[i];
361 while (cleaned_count--) {
362 skb = buffer_info->skb;
368 skb = netdev_alloc_skb(netdev, bufsz);
370 /* Better luck next round */
371 adapter->alloc_rx_buff_failed++;
375 /* Make buffer alignment 2 beyond a 16 byte boundary
376 * this will result in a 16 byte aligned IP header after
377 * the 14 byte MAC header is removed
379 skb_reserve(skb, NET_IP_ALIGN);
381 buffer_info->skb = skb;
383 /* allocate a new page if necessary */
384 if (!buffer_info->page) {
385 buffer_info->page = alloc_page(GFP_ATOMIC);
386 if (!buffer_info->page) {
387 adapter->alloc_rx_buff_failed++;
392 if (!buffer_info->dma)
393 buffer_info->dma = pci_map_page(pdev,
394 buffer_info->page, 0,
397 if (pci_dma_mapping_error(buffer_info->dma)) {
398 dev_err(&adapter->pdev->dev, "RX DMA page map failed\n");
399 adapter->rx_dma_failed++;
403 rx_desc = E1000_RX_DESC(*rx_ring, i);
404 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
407 if (i == rx_ring->count)
409 buffer_info = &rx_ring->buffer_info[i];
412 if (rx_ring->next_to_use != i) {
413 rx_ring->next_to_use = i;
415 i = (rx_ring->count - 1);
417 /* Force memory writes to complete before letting h/w
418 * know there are new descriptors to fetch. (Only
419 * applicable for weak-ordered memory model archs,
422 writel(i, adapter->hw.hw_addr + rx_ring->tail);
427 * e1000_clean_rx_irq - Send received data up the network stack; legacy
428 * @adapter: board private structure
430 * the return value indicates whether actual cleaning was done, there
431 * is no guarantee that everything was cleaned
433 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
434 int *work_done, int work_to_do)
436 struct net_device *netdev = adapter->netdev;
437 struct pci_dev *pdev = adapter->pdev;
438 struct e1000_ring *rx_ring = adapter->rx_ring;
439 struct e1000_rx_desc *rx_desc, *next_rxd;
440 struct e1000_buffer *buffer_info, *next_buffer;
443 int cleaned_count = 0;
445 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
447 i = rx_ring->next_to_clean;
448 rx_desc = E1000_RX_DESC(*rx_ring, i);
449 buffer_info = &rx_ring->buffer_info[i];
451 while (rx_desc->status & E1000_RXD_STAT_DD) {
455 if (*work_done >= work_to_do)
459 status = rx_desc->status;
460 skb = buffer_info->skb;
461 buffer_info->skb = NULL;
463 prefetch(skb->data - NET_IP_ALIGN);
466 if (i == rx_ring->count)
468 next_rxd = E1000_RX_DESC(*rx_ring, i);
471 next_buffer = &rx_ring->buffer_info[i];
475 pci_unmap_single(pdev,
477 adapter->rx_buffer_len,
479 buffer_info->dma = 0;
481 length = le16_to_cpu(rx_desc->length);
483 /* !EOP means multiple descriptors were used to store a single
484 * packet, also make sure the frame isn't just CRC only */
485 if (!(status & E1000_RXD_STAT_EOP) || (length <= 4)) {
486 /* All receives must fit into a single buffer */
487 ndev_dbg(netdev, "%s: Receive packet consumed "
488 "multiple buffers\n", netdev->name);
490 buffer_info->skb = skb;
494 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
496 buffer_info->skb = skb;
500 /* adjust length to remove Ethernet CRC */
503 /* probably a little skewed due to removing CRC */
504 total_rx_bytes += length;
507 /* code added for copybreak, this should improve
508 * performance for small packets with large amounts
509 * of reassembly being done in the stack */
510 if (length < copybreak) {
511 struct sk_buff *new_skb =
512 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
514 skb_reserve(new_skb, NET_IP_ALIGN);
515 memcpy(new_skb->data - NET_IP_ALIGN,
516 skb->data - NET_IP_ALIGN,
517 length + NET_IP_ALIGN);
518 /* save the skb in buffer_info as good */
519 buffer_info->skb = skb;
522 /* else just continue with the old one */
524 /* end copybreak code */
525 skb_put(skb, length);
527 /* Receive Checksum Offload */
528 e1000_rx_checksum(adapter,
530 ((u32)(rx_desc->errors) << 24),
531 le16_to_cpu(rx_desc->csum), skb);
533 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
538 /* return some buffers to hardware, one at a time is too slow */
539 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
540 adapter->alloc_rx_buf(adapter, cleaned_count);
544 /* use prefetched values */
546 buffer_info = next_buffer;
548 rx_ring->next_to_clean = i;
550 cleaned_count = e1000_desc_unused(rx_ring);
552 adapter->alloc_rx_buf(adapter, cleaned_count);
554 adapter->total_rx_packets += total_rx_packets;
555 adapter->total_rx_bytes += total_rx_bytes;
559 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
564 skb->data_len += length;
565 skb->truesize += length;
568 static void e1000_put_txbuf(struct e1000_adapter *adapter,
569 struct e1000_buffer *buffer_info)
571 if (buffer_info->dma) {
572 pci_unmap_page(adapter->pdev, buffer_info->dma,
573 buffer_info->length, PCI_DMA_TODEVICE);
574 buffer_info->dma = 0;
576 if (buffer_info->skb) {
577 dev_kfree_skb_any(buffer_info->skb);
578 buffer_info->skb = NULL;
582 static void e1000_print_tx_hang(struct e1000_adapter *adapter)
584 struct e1000_ring *tx_ring = adapter->tx_ring;
585 unsigned int i = tx_ring->next_to_clean;
586 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
587 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
588 struct net_device *netdev = adapter->netdev;
590 /* detected Tx unit hang */
592 "Detected Tx Unit Hang:\n"
595 " next_to_use <%x>\n"
596 " next_to_clean <%x>\n"
597 "buffer_info[next_to_clean]:\n"
598 " time_stamp <%lx>\n"
599 " next_to_watch <%x>\n"
601 " next_to_watch.status <%x>\n",
602 readl(adapter->hw.hw_addr + tx_ring->head),
603 readl(adapter->hw.hw_addr + tx_ring->tail),
604 tx_ring->next_to_use,
605 tx_ring->next_to_clean,
606 tx_ring->buffer_info[eop].time_stamp,
609 eop_desc->upper.fields.status);
613 * e1000_clean_tx_irq - Reclaim resources after transmit completes
614 * @adapter: board private structure
616 * the return value indicates whether actual cleaning was done, there
617 * is no guarantee that everything was cleaned
619 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
621 struct net_device *netdev = adapter->netdev;
622 struct e1000_hw *hw = &adapter->hw;
623 struct e1000_ring *tx_ring = adapter->tx_ring;
624 struct e1000_tx_desc *tx_desc, *eop_desc;
625 struct e1000_buffer *buffer_info;
627 unsigned int count = 0;
629 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
631 i = tx_ring->next_to_clean;
632 eop = tx_ring->buffer_info[i].next_to_watch;
633 eop_desc = E1000_TX_DESC(*tx_ring, eop);
635 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
636 for (cleaned = 0; !cleaned; ) {
637 tx_desc = E1000_TX_DESC(*tx_ring, i);
638 buffer_info = &tx_ring->buffer_info[i];
639 cleaned = (i == eop);
642 struct sk_buff *skb = buffer_info->skb;
643 unsigned int segs, bytecount;
644 segs = skb_shinfo(skb)->gso_segs ?: 1;
645 /* multiply data chunks by size of headers */
646 bytecount = ((segs - 1) * skb_headlen(skb)) +
648 total_tx_packets += segs;
649 total_tx_bytes += bytecount;
652 e1000_put_txbuf(adapter, buffer_info);
653 tx_desc->upper.data = 0;
656 if (i == tx_ring->count)
660 eop = tx_ring->buffer_info[i].next_to_watch;
661 eop_desc = E1000_TX_DESC(*tx_ring, eop);
662 #define E1000_TX_WEIGHT 64
663 /* weight of a sort for tx, to avoid endless transmit cleanup */
664 if (count++ == E1000_TX_WEIGHT)
668 tx_ring->next_to_clean = i;
670 #define TX_WAKE_THRESHOLD 32
671 if (cleaned && netif_carrier_ok(netdev) &&
672 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
673 /* Make sure that anybody stopping the queue after this
674 * sees the new next_to_clean.
678 if (netif_queue_stopped(netdev) &&
679 !(test_bit(__E1000_DOWN, &adapter->state))) {
680 netif_wake_queue(netdev);
681 ++adapter->restart_queue;
685 if (adapter->detect_tx_hung) {
686 /* Detect a transmit hang in hardware, this serializes the
687 * check with the clearing of time_stamp and movement of i */
688 adapter->detect_tx_hung = 0;
689 if (tx_ring->buffer_info[eop].dma &&
690 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp
691 + (adapter->tx_timeout_factor * HZ))
693 E1000_STATUS_TXOFF)) {
694 e1000_print_tx_hang(adapter);
695 netif_stop_queue(netdev);
698 adapter->total_tx_bytes += total_tx_bytes;
699 adapter->total_tx_packets += total_tx_packets;
704 * e1000_clean_rx_irq_jumbo - Send received data up the network stack; legacy
705 * @adapter: board private structure
707 * the return value indicates whether actual cleaning was done, there
708 * is no guarantee that everything was cleaned
710 static bool e1000_clean_rx_irq_jumbo(struct e1000_adapter *adapter,
711 int *work_done, int work_to_do)
713 struct net_device *netdev = adapter->netdev;
714 struct pci_dev *pdev = adapter->pdev;
715 struct e1000_ring *rx_ring = adapter->rx_ring;
716 struct e1000_rx_desc *rx_desc, *next_rxd;
717 struct e1000_buffer *buffer_info, *next_buffer;
720 int cleaned_count = 0;
722 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
724 i = rx_ring->next_to_clean;
725 rx_desc = E1000_RX_DESC(*rx_ring, i);
726 buffer_info = &rx_ring->buffer_info[i];
728 while (rx_desc->status & E1000_RXD_STAT_DD) {
732 if (*work_done >= work_to_do)
736 status = rx_desc->status;
737 skb = buffer_info->skb;
738 buffer_info->skb = NULL;
741 if (i == rx_ring->count)
743 next_rxd = E1000_RX_DESC(*rx_ring, i);
746 next_buffer = &rx_ring->buffer_info[i];
754 buffer_info->dma = 0;
756 length = le16_to_cpu(rx_desc->length);
758 /* errors is only valid for DD + EOP descriptors */
759 if ((status & E1000_RXD_STAT_EOP) &&
760 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
761 /* recycle both page and skb */
762 buffer_info->skb = skb;
763 /* an error means any chain goes out the window too */
764 if (rx_ring->rx_skb_top)
765 dev_kfree_skb(rx_ring->rx_skb_top);
766 rx_ring->rx_skb_top = NULL;
770 #define rxtop rx_ring->rx_skb_top
771 if (!(status & E1000_RXD_STAT_EOP)) {
772 /* this descriptor is only the beginning (or middle) */
774 /* this is the beginning of a chain */
776 skb_fill_page_desc(rxtop, 0, buffer_info->page,
779 /* this is the middle of a chain */
780 skb_fill_page_desc(rxtop,
781 skb_shinfo(rxtop)->nr_frags,
782 buffer_info->page, 0,
784 /* re-use the skb, only consumed the page */
785 buffer_info->skb = skb;
787 e1000_consume_page(buffer_info, rxtop, length);
791 /* end of the chain */
792 skb_fill_page_desc(rxtop,
793 skb_shinfo(rxtop)->nr_frags,
794 buffer_info->page, 0, length);
795 /* re-use the current skb, we only consumed the
797 buffer_info->skb = skb;
800 e1000_consume_page(buffer_info, skb, length);
802 /* no chain, got EOP, this buf is the packet
803 * copybreak to save the put_page/alloc_page */
804 if (length <= copybreak &&
805 skb_tailroom(skb) >= length) {
807 vaddr = kmap_atomic(buffer_info->page,
808 KM_SKB_DATA_SOFTIRQ);
809 memcpy(skb_tail_pointer(skb),
812 KM_SKB_DATA_SOFTIRQ);
813 /* re-use the page, so don't erase
814 * buffer_info->page */
815 skb_put(skb, length);
817 skb_fill_page_desc(skb, 0,
818 buffer_info->page, 0,
820 e1000_consume_page(buffer_info, skb,
826 /* Receive Checksum Offload XXX recompute due to CRC strip? */
827 e1000_rx_checksum(adapter,
829 ((u32)(rx_desc->errors) << 24),
830 le16_to_cpu(rx_desc->csum), skb);
832 pskb_trim(skb, skb->len - 4);
834 /* probably a little skewed due to removing CRC */
835 total_rx_bytes += skb->len;
838 /* eth type trans needs skb->data to point to something */
839 if (!pskb_may_pull(skb, ETH_HLEN)) {
840 ndev_err(netdev, "__pskb_pull_tail failed.\n");
845 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
850 /* return some buffers to hardware, one at a time is too slow */
851 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
852 adapter->alloc_rx_buf(adapter, cleaned_count);
856 /* use prefetched values */
858 buffer_info = next_buffer;
860 rx_ring->next_to_clean = i;
862 cleaned_count = e1000_desc_unused(rx_ring);
864 adapter->alloc_rx_buf(adapter, cleaned_count);
866 adapter->total_rx_packets += total_rx_packets;
867 adapter->total_rx_bytes += total_rx_bytes;
872 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
873 * @adapter: board private structure
875 * the return value indicates whether actual cleaning was done, there
876 * is no guarantee that everything was cleaned
878 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
879 int *work_done, int work_to_do)
881 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
882 struct net_device *netdev = adapter->netdev;
883 struct pci_dev *pdev = adapter->pdev;
884 struct e1000_ring *rx_ring = adapter->rx_ring;
885 struct e1000_buffer *buffer_info, *next_buffer;
886 struct e1000_ps_page *ps_page;
890 int cleaned_count = 0;
892 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
894 i = rx_ring->next_to_clean;
895 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
896 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
897 buffer_info = &rx_ring->buffer_info[i];
899 while (staterr & E1000_RXD_STAT_DD) {
900 if (*work_done >= work_to_do)
903 skb = buffer_info->skb;
905 /* in the packet split case this is header only */
906 prefetch(skb->data - NET_IP_ALIGN);
909 if (i == rx_ring->count)
911 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
914 next_buffer = &rx_ring->buffer_info[i];
918 pci_unmap_single(pdev, buffer_info->dma,
919 adapter->rx_ps_bsize0,
921 buffer_info->dma = 0;
923 if (!(staterr & E1000_RXD_STAT_EOP)) {
924 ndev_dbg(netdev, "%s: Packet Split buffers didn't pick "
925 "up the full packet\n", netdev->name);
926 dev_kfree_skb_irq(skb);
930 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
931 dev_kfree_skb_irq(skb);
935 length = le16_to_cpu(rx_desc->wb.middle.length0);
938 ndev_dbg(netdev, "%s: Last part of the packet spanning"
939 " multiple descriptors\n", netdev->name);
940 dev_kfree_skb_irq(skb);
945 skb_put(skb, length);
948 /* this looks ugly, but it seems compiler issues make it
949 more efficient than reusing j */
950 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
952 /* page alloc/put takes too long and effects small packet
953 * throughput, so unsplit small packets and save the alloc/put*/
954 if (l1 && (l1 <= copybreak) &&
955 ((length + l1) <= adapter->rx_ps_bsize0)) {
958 ps_page = &rx_ring->ps_pages[i * PS_PAGE_BUFFERS];
960 /* there is no documentation about how to call
961 * kmap_atomic, so we can't hold the mapping
963 pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
964 PAGE_SIZE, PCI_DMA_FROMDEVICE);
965 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
966 memcpy(skb_tail_pointer(skb), vaddr, l1);
967 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
968 pci_dma_sync_single_for_device(pdev, ps_page->dma,
969 PAGE_SIZE, PCI_DMA_FROMDEVICE);
977 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
978 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
982 ps_page = &rx_ring->ps_pages[(i * PS_PAGE_BUFFERS) + j];
983 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
986 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
987 ps_page->page = NULL;
989 skb->data_len += length;
990 skb->truesize += length;
993 /* strip the ethernet crc, problem is we're using pages now so
994 * this whole operation can get a little cpu intensive */
995 pskb_trim(skb, skb->len - 4);
998 total_rx_bytes += skb->len;
1001 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1002 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1004 if (rx_desc->wb.upper.header_status &
1005 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1006 adapter->rx_hdr_split++;
1008 e1000_receive_skb(adapter, netdev, skb,
1009 staterr, rx_desc->wb.middle.vlan);
1012 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1013 buffer_info->skb = NULL;
1015 /* return some buffers to hardware, one at a time is too slow */
1016 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1017 adapter->alloc_rx_buf(adapter, cleaned_count);
1021 /* use prefetched values */
1023 buffer_info = next_buffer;
1025 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1027 rx_ring->next_to_clean = i;
1029 cleaned_count = e1000_desc_unused(rx_ring);
1031 adapter->alloc_rx_buf(adapter, cleaned_count);
1033 adapter->total_rx_packets += total_rx_packets;
1034 adapter->total_rx_bytes += total_rx_bytes;
1039 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1040 * @adapter: board private structure
1042 static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1044 struct e1000_ring *rx_ring = adapter->rx_ring;
1045 struct e1000_buffer *buffer_info;
1046 struct e1000_ps_page *ps_page;
1047 struct pci_dev *pdev = adapter->pdev;
1051 /* Free all the Rx ring sk_buffs */
1052 for (i = 0; i < rx_ring->count; i++) {
1053 buffer_info = &rx_ring->buffer_info[i];
1054 if (buffer_info->dma) {
1055 if (adapter->clean_rx == e1000_clean_rx_irq)
1056 pci_unmap_single(pdev, buffer_info->dma,
1057 adapter->rx_buffer_len,
1058 PCI_DMA_FROMDEVICE);
1059 else if (adapter->clean_rx == e1000_clean_rx_irq_jumbo)
1060 pci_unmap_page(pdev, buffer_info->dma,
1061 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1062 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1063 pci_unmap_single(pdev, buffer_info->dma,
1064 adapter->rx_ps_bsize0,
1065 PCI_DMA_FROMDEVICE);
1066 buffer_info->dma = 0;
1069 if (buffer_info->page) {
1070 put_page(buffer_info->page);
1071 buffer_info->page = NULL;
1074 if (buffer_info->skb) {
1075 dev_kfree_skb(buffer_info->skb);
1076 buffer_info->skb = NULL;
1079 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1080 ps_page = &rx_ring->ps_pages[(i * PS_PAGE_BUFFERS)
1084 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
1085 PCI_DMA_FROMDEVICE);
1087 put_page(ps_page->page);
1088 ps_page->page = NULL;
1092 /* there also may be some cached data from a chained receive */
1093 if (rx_ring->rx_skb_top) {
1094 dev_kfree_skb(rx_ring->rx_skb_top);
1095 rx_ring->rx_skb_top = NULL;
1098 size = sizeof(struct e1000_buffer) * rx_ring->count;
1099 memset(rx_ring->buffer_info, 0, size);
1100 size = sizeof(struct e1000_ps_page)
1101 * (rx_ring->count * PS_PAGE_BUFFERS);
1102 memset(rx_ring->ps_pages, 0, size);
1104 /* Zero out the descriptor ring */
1105 memset(rx_ring->desc, 0, rx_ring->size);
1107 rx_ring->next_to_clean = 0;
1108 rx_ring->next_to_use = 0;
1110 writel(0, adapter->hw.hw_addr + rx_ring->head);
1111 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1115 * e1000_intr_msi - Interrupt Handler
1116 * @irq: interrupt number
1117 * @data: pointer to a network interface device structure
1119 static irqreturn_t e1000_intr_msi(int irq, void *data)
1121 struct net_device *netdev = data;
1122 struct e1000_adapter *adapter = netdev_priv(netdev);
1123 struct e1000_hw *hw = &adapter->hw;
1124 u32 icr = er32(ICR);
1126 /* read ICR disables interrupts using IAM, so keep up with our
1127 * enable/disable accounting */
1128 atomic_inc(&adapter->irq_sem);
1130 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
1131 hw->mac.get_link_status = 1;
1132 /* ICH8 workaround-- Call gig speed drop workaround on cable
1133 * disconnect (LSC) before accessing any PHY registers */
1134 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1135 (!(er32(STATUS) & E1000_STATUS_LU)))
1136 e1000e_gig_downshift_workaround_ich8lan(hw);
1138 /* 80003ES2LAN workaround-- For packet buffer work-around on
1139 * link down event; disable receives here in the ISR and reset
1140 * adapter in watchdog */
1141 if (netif_carrier_ok(netdev) &&
1142 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1143 /* disable receives */
1144 u32 rctl = er32(RCTL);
1145 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1147 /* guard against interrupt when we're going down */
1148 if (!test_bit(__E1000_DOWN, &adapter->state))
1149 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1152 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1153 adapter->total_tx_bytes = 0;
1154 adapter->total_tx_packets = 0;
1155 adapter->total_rx_bytes = 0;
1156 adapter->total_rx_packets = 0;
1157 __netif_rx_schedule(netdev, &adapter->napi);
1159 atomic_dec(&adapter->irq_sem);
1166 * e1000_intr - Interrupt Handler
1167 * @irq: interrupt number
1168 * @data: pointer to a network interface device structure
1170 static irqreturn_t e1000_intr(int irq, void *data)
1172 struct net_device *netdev = data;
1173 struct e1000_adapter *adapter = netdev_priv(netdev);
1174 struct e1000_hw *hw = &adapter->hw;
1176 u32 rctl, icr = er32(ICR);
1178 return IRQ_NONE; /* Not our interrupt */
1180 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1181 * not set, then the adapter didn't send an interrupt */
1182 if (!(icr & E1000_ICR_INT_ASSERTED))
1185 /* Interrupt Auto-Mask...upon reading ICR,
1186 * interrupts are masked. No need for the
1187 * IMC write, but it does mean we should
1188 * account for it ASAP. */
1189 atomic_inc(&adapter->irq_sem);
1191 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
1192 hw->mac.get_link_status = 1;
1193 /* ICH8 workaround-- Call gig speed drop workaround on cable
1194 * disconnect (LSC) before accessing any PHY registers */
1195 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1196 (!(er32(STATUS) & E1000_STATUS_LU)))
1197 e1000e_gig_downshift_workaround_ich8lan(hw);
1199 /* 80003ES2LAN workaround--
1200 * For packet buffer work-around on link down event;
1201 * disable receives here in the ISR and
1202 * reset adapter in watchdog
1204 if (netif_carrier_ok(netdev) &&
1205 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1206 /* disable receives */
1208 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1210 /* guard against interrupt when we're going down */
1211 if (!test_bit(__E1000_DOWN, &adapter->state))
1212 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1215 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1216 adapter->total_tx_bytes = 0;
1217 adapter->total_tx_packets = 0;
1218 adapter->total_rx_bytes = 0;
1219 adapter->total_rx_packets = 0;
1220 __netif_rx_schedule(netdev, &adapter->napi);
1222 atomic_dec(&adapter->irq_sem);
1228 static int e1000_request_irq(struct e1000_adapter *adapter)
1230 struct net_device *netdev = adapter->netdev;
1231 void (*handler) = &e1000_intr;
1232 int irq_flags = IRQF_SHARED;
1235 err = pci_enable_msi(adapter->pdev);
1238 "Unable to allocate MSI interrupt Error: %d\n", err);
1240 adapter->flags |= FLAG_MSI_ENABLED;
1241 handler = &e1000_intr_msi;
1245 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
1248 if (adapter->flags & FLAG_MSI_ENABLED)
1249 pci_disable_msi(adapter->pdev);
1251 "Unable to allocate interrupt Error: %d\n", err);
1257 static void e1000_free_irq(struct e1000_adapter *adapter)
1259 struct net_device *netdev = adapter->netdev;
1261 free_irq(adapter->pdev->irq, netdev);
1262 if (adapter->flags & FLAG_MSI_ENABLED) {
1263 pci_disable_msi(adapter->pdev);
1264 adapter->flags &= ~FLAG_MSI_ENABLED;
1269 * e1000_irq_disable - Mask off interrupt generation on the NIC
1271 static void e1000_irq_disable(struct e1000_adapter *adapter)
1273 struct e1000_hw *hw = &adapter->hw;
1275 atomic_inc(&adapter->irq_sem);
1278 synchronize_irq(adapter->pdev->irq);
1282 * e1000_irq_enable - Enable default interrupt generation settings
1284 static void e1000_irq_enable(struct e1000_adapter *adapter)
1286 struct e1000_hw *hw = &adapter->hw;
1288 if (atomic_dec_and_test(&adapter->irq_sem)) {
1289 ew32(IMS, IMS_ENABLE_MASK);
1295 * e1000_get_hw_control - get control of the h/w from f/w
1296 * @adapter: address of board private structure
1298 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
1299 * For ASF and Pass Through versions of f/w this means that
1300 * the driver is loaded. For AMT version (only with 82573)
1301 * of the f/w this means that the network i/f is open.
1303 static void e1000_get_hw_control(struct e1000_adapter *adapter)
1305 struct e1000_hw *hw = &adapter->hw;
1309 /* Let firmware know the driver has taken over */
1310 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1312 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1313 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1314 ctrl_ext = er32(CTRL_EXT);
1316 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1321 * e1000_release_hw_control - release control of the h/w to f/w
1322 * @adapter: address of board private structure
1324 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
1325 * For ASF and Pass Through versions of f/w this means that the
1326 * driver is no longer loaded. For AMT version (only with 82573) i
1327 * of the f/w this means that the network i/f is closed.
1330 static void e1000_release_hw_control(struct e1000_adapter *adapter)
1332 struct e1000_hw *hw = &adapter->hw;
1336 /* Let firmware taken over control of h/w */
1337 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1339 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1340 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1341 ctrl_ext = er32(CTRL_EXT);
1343 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1347 static void e1000_release_manageability(struct e1000_adapter *adapter)
1349 if (adapter->flags & FLAG_MNG_PT_ENABLED) {
1350 struct e1000_hw *hw = &adapter->hw;
1352 u32 manc = er32(MANC);
1354 /* re-enable hardware interception of ARP */
1355 manc |= E1000_MANC_ARP_EN;
1356 manc &= ~E1000_MANC_EN_MNG2HOST;
1358 /* don't explicitly have to mess with MANC2H since
1359 * MANC has an enable disable that gates MANC2H */
1365 * @e1000_alloc_ring - allocate memory for a ring structure
1367 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
1368 struct e1000_ring *ring)
1370 struct pci_dev *pdev = adapter->pdev;
1372 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
1381 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1382 * @adapter: board private structure
1384 * Return 0 on success, negative on failure
1386 int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
1388 struct e1000_ring *tx_ring = adapter->tx_ring;
1389 int err = -ENOMEM, size;
1391 size = sizeof(struct e1000_buffer) * tx_ring->count;
1392 tx_ring->buffer_info = vmalloc(size);
1393 if (!tx_ring->buffer_info)
1395 memset(tx_ring->buffer_info, 0, size);
1397 /* round up to nearest 4K */
1398 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1399 tx_ring->size = ALIGN(tx_ring->size, 4096);
1401 err = e1000_alloc_ring_dma(adapter, tx_ring);
1405 tx_ring->next_to_use = 0;
1406 tx_ring->next_to_clean = 0;
1407 spin_lock_init(&adapter->tx_queue_lock);
1411 vfree(tx_ring->buffer_info);
1412 ndev_err(adapter->netdev,
1413 "Unable to allocate memory for the transmit descriptor ring\n");
1418 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1419 * @adapter: board private structure
1421 * Returns 0 on success, negative on failure
1423 int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
1425 struct e1000_ring *rx_ring = adapter->rx_ring;
1426 int size, desc_len, err = -ENOMEM;
1428 size = sizeof(struct e1000_buffer) * rx_ring->count;
1429 rx_ring->buffer_info = vmalloc(size);
1430 if (!rx_ring->buffer_info)
1432 memset(rx_ring->buffer_info, 0, size);
1434 rx_ring->ps_pages = kcalloc(rx_ring->count * PS_PAGE_BUFFERS,
1435 sizeof(struct e1000_ps_page),
1437 if (!rx_ring->ps_pages)
1440 desc_len = sizeof(union e1000_rx_desc_packet_split);
1442 /* Round up to nearest 4K */
1443 rx_ring->size = rx_ring->count * desc_len;
1444 rx_ring->size = ALIGN(rx_ring->size, 4096);
1446 err = e1000_alloc_ring_dma(adapter, rx_ring);
1450 rx_ring->next_to_clean = 0;
1451 rx_ring->next_to_use = 0;
1452 rx_ring->rx_skb_top = NULL;
1456 vfree(rx_ring->buffer_info);
1457 kfree(rx_ring->ps_pages);
1458 ndev_err(adapter->netdev,
1459 "Unable to allocate memory for the transmit descriptor ring\n");
1464 * e1000_clean_tx_ring - Free Tx Buffers
1465 * @adapter: board private structure
1467 static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
1469 struct e1000_ring *tx_ring = adapter->tx_ring;
1470 struct e1000_buffer *buffer_info;
1474 for (i = 0; i < tx_ring->count; i++) {
1475 buffer_info = &tx_ring->buffer_info[i];
1476 e1000_put_txbuf(adapter, buffer_info);
1479 size = sizeof(struct e1000_buffer) * tx_ring->count;
1480 memset(tx_ring->buffer_info, 0, size);
1482 memset(tx_ring->desc, 0, tx_ring->size);
1484 tx_ring->next_to_use = 0;
1485 tx_ring->next_to_clean = 0;
1487 writel(0, adapter->hw.hw_addr + tx_ring->head);
1488 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1492 * e1000e_free_tx_resources - Free Tx Resources per Queue
1493 * @adapter: board private structure
1495 * Free all transmit software resources
1497 void e1000e_free_tx_resources(struct e1000_adapter *adapter)
1499 struct pci_dev *pdev = adapter->pdev;
1500 struct e1000_ring *tx_ring = adapter->tx_ring;
1502 e1000_clean_tx_ring(adapter);
1504 vfree(tx_ring->buffer_info);
1505 tx_ring->buffer_info = NULL;
1507 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1509 tx_ring->desc = NULL;
1513 * e1000e_free_rx_resources - Free Rx Resources
1514 * @adapter: board private structure
1516 * Free all receive software resources
1519 void e1000e_free_rx_resources(struct e1000_adapter *adapter)
1521 struct pci_dev *pdev = adapter->pdev;
1522 struct e1000_ring *rx_ring = adapter->rx_ring;
1524 e1000_clean_rx_ring(adapter);
1526 vfree(rx_ring->buffer_info);
1527 rx_ring->buffer_info = NULL;
1529 kfree(rx_ring->ps_pages);
1530 rx_ring->ps_pages = NULL;
1532 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1534 rx_ring->desc = NULL;
1538 * e1000_update_itr - update the dynamic ITR value based on statistics
1539 * Stores a new ITR value based on packets and byte
1540 * counts during the last interrupt. The advantage of per interrupt
1541 * computation is faster updates and more accurate ITR for the current
1542 * traffic pattern. Constants in this function were computed
1543 * based on theoretical maximum wire speed and thresholds were set based
1544 * on testing data as well as attempting to minimize response time
1545 * while increasing bulk throughput.
1546 * this functionality is controlled by the InterruptThrottleRate module
1547 * parameter (see e1000_param.c)
1548 * @adapter: pointer to adapter
1549 * @itr_setting: current adapter->itr
1550 * @packets: the number of packets during this measurement interval
1551 * @bytes: the number of bytes during this measurement interval
1553 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
1554 u16 itr_setting, int packets,
1557 unsigned int retval = itr_setting;
1560 goto update_itr_done;
1562 switch (itr_setting) {
1563 case lowest_latency:
1564 /* handle TSO and jumbo frames */
1565 if (bytes/packets > 8000)
1566 retval = bulk_latency;
1567 else if ((packets < 5) && (bytes > 512)) {
1568 retval = low_latency;
1571 case low_latency: /* 50 usec aka 20000 ints/s */
1572 if (bytes > 10000) {
1573 /* this if handles the TSO accounting */
1574 if (bytes/packets > 8000) {
1575 retval = bulk_latency;
1576 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
1577 retval = bulk_latency;
1578 } else if ((packets > 35)) {
1579 retval = lowest_latency;
1581 } else if (bytes/packets > 2000) {
1582 retval = bulk_latency;
1583 } else if (packets <= 2 && bytes < 512) {
1584 retval = lowest_latency;
1587 case bulk_latency: /* 250 usec aka 4000 ints/s */
1588 if (bytes > 25000) {
1590 retval = low_latency;
1592 } else if (bytes < 6000) {
1593 retval = low_latency;
1602 static void e1000_set_itr(struct e1000_adapter *adapter)
1604 struct e1000_hw *hw = &adapter->hw;
1606 u32 new_itr = adapter->itr;
1608 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1609 if (adapter->link_speed != SPEED_1000) {
1615 adapter->tx_itr = e1000_update_itr(adapter,
1617 adapter->total_tx_packets,
1618 adapter->total_tx_bytes);
1619 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1620 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
1621 adapter->tx_itr = low_latency;
1623 adapter->rx_itr = e1000_update_itr(adapter,
1625 adapter->total_rx_packets,
1626 adapter->total_rx_bytes);
1627 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1628 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
1629 adapter->rx_itr = low_latency;
1631 current_itr = max(adapter->rx_itr, adapter->tx_itr);
1633 switch (current_itr) {
1634 /* counts and packets in update_itr are dependent on these numbers */
1635 case lowest_latency:
1639 new_itr = 20000; /* aka hwitr = ~200 */
1649 if (new_itr != adapter->itr) {
1650 /* this attempts to bias the interrupt rate towards Bulk
1651 * by adding intermediate steps when interrupt rate is
1653 new_itr = new_itr > adapter->itr ?
1654 min(adapter->itr + (new_itr >> 2), new_itr) :
1656 adapter->itr = new_itr;
1657 ew32(ITR, 1000000000 / (new_itr * 256));
1662 * e1000_clean - NAPI Rx polling callback
1663 * @adapter: board private structure
1665 static int e1000_clean(struct napi_struct *napi, int budget)
1667 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
1668 struct net_device *poll_dev = adapter->netdev;
1669 int tx_cleaned = 0, work_done = 0;
1671 /* Must NOT use netdev_priv macro here. */
1672 adapter = poll_dev->priv;
1674 /* Keep link state information with original netdev */
1675 if (!netif_carrier_ok(poll_dev))
1678 /* e1000_clean is called per-cpu. This lock protects
1679 * tx_ring from being cleaned by multiple cpus
1680 * simultaneously. A failure obtaining the lock means
1681 * tx_ring is currently being cleaned anyway. */
1682 if (spin_trylock(&adapter->tx_queue_lock)) {
1683 tx_cleaned = e1000_clean_tx_irq(adapter);
1684 spin_unlock(&adapter->tx_queue_lock);
1687 adapter->clean_rx(adapter, &work_done, budget);
1689 /* If no Tx and not enough Rx work done, exit the polling mode */
1690 if ((!tx_cleaned && (work_done < budget)) ||
1691 !netif_running(poll_dev)) {
1693 if (adapter->itr_setting & 3)
1694 e1000_set_itr(adapter);
1695 netif_rx_complete(poll_dev, napi);
1696 e1000_irq_enable(adapter);
1702 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1704 struct e1000_adapter *adapter = netdev_priv(netdev);
1705 struct e1000_hw *hw = &adapter->hw;
1708 /* don't update vlan cookie if already programmed */
1709 if ((adapter->hw.mng_cookie.status &
1710 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
1711 (vid == adapter->mng_vlan_id))
1713 /* add VID to filter table */
1714 index = (vid >> 5) & 0x7F;
1715 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
1716 vfta |= (1 << (vid & 0x1F));
1717 e1000e_write_vfta(hw, index, vfta);
1720 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1722 struct e1000_adapter *adapter = netdev_priv(netdev);
1723 struct e1000_hw *hw = &adapter->hw;
1726 e1000_irq_disable(adapter);
1727 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1728 e1000_irq_enable(adapter);
1730 if ((adapter->hw.mng_cookie.status &
1731 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
1732 (vid == adapter->mng_vlan_id)) {
1733 /* release control to f/w */
1734 e1000_release_hw_control(adapter);
1738 /* remove VID from filter table */
1739 index = (vid >> 5) & 0x7F;
1740 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
1741 vfta &= ~(1 << (vid & 0x1F));
1742 e1000e_write_vfta(hw, index, vfta);
1745 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
1747 struct net_device *netdev = adapter->netdev;
1748 u16 vid = adapter->hw.mng_cookie.vlan_id;
1749 u16 old_vid = adapter->mng_vlan_id;
1751 if (!adapter->vlgrp)
1754 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
1755 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1756 if (adapter->hw.mng_cookie.status &
1757 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1758 e1000_vlan_rx_add_vid(netdev, vid);
1759 adapter->mng_vlan_id = vid;
1762 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
1764 !vlan_group_get_device(adapter->vlgrp, old_vid))
1765 e1000_vlan_rx_kill_vid(netdev, old_vid);
1767 adapter->mng_vlan_id = vid;
1772 static void e1000_vlan_rx_register(struct net_device *netdev,
1773 struct vlan_group *grp)
1775 struct e1000_adapter *adapter = netdev_priv(netdev);
1776 struct e1000_hw *hw = &adapter->hw;
1779 e1000_irq_disable(adapter);
1780 adapter->vlgrp = grp;
1783 /* enable VLAN tag insert/strip */
1785 ctrl |= E1000_CTRL_VME;
1788 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
1789 /* enable VLAN receive filtering */
1791 rctl |= E1000_RCTL_VFE;
1792 rctl &= ~E1000_RCTL_CFIEN;
1794 e1000_update_mng_vlan(adapter);
1797 /* disable VLAN tag insert/strip */
1799 ctrl &= ~E1000_CTRL_VME;
1802 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
1803 /* disable VLAN filtering */
1805 rctl &= ~E1000_RCTL_VFE;
1807 if (adapter->mng_vlan_id !=
1808 (u16)E1000_MNG_VLAN_NONE) {
1809 e1000_vlan_rx_kill_vid(netdev,
1810 adapter->mng_vlan_id);
1811 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1816 e1000_irq_enable(adapter);
1819 static void e1000_restore_vlan(struct e1000_adapter *adapter)
1823 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1825 if (!adapter->vlgrp)
1828 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1829 if (!vlan_group_get_device(adapter->vlgrp, vid))
1831 e1000_vlan_rx_add_vid(adapter->netdev, vid);
1835 static void e1000_init_manageability(struct e1000_adapter *adapter)
1837 struct e1000_hw *hw = &adapter->hw;
1840 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
1845 /* disable hardware interception of ARP */
1846 manc &= ~(E1000_MANC_ARP_EN);
1848 /* enable receiving management packets to the host. this will probably
1849 * generate destination unreachable messages from the host OS, but
1850 * the packets will be handled on SMBUS */
1851 manc |= E1000_MANC_EN_MNG2HOST;
1852 manc2h = er32(MANC2H);
1853 #define E1000_MNG2HOST_PORT_623 (1 << 5)
1854 #define E1000_MNG2HOST_PORT_664 (1 << 6)
1855 manc2h |= E1000_MNG2HOST_PORT_623;
1856 manc2h |= E1000_MNG2HOST_PORT_664;
1857 ew32(MANC2H, manc2h);
1862 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1863 * @adapter: board private structure
1865 * Configure the Tx unit of the MAC after a reset.
1867 static void e1000_configure_tx(struct e1000_adapter *adapter)
1869 struct e1000_hw *hw = &adapter->hw;
1870 struct e1000_ring *tx_ring = adapter->tx_ring;
1872 u32 tdlen, tctl, tipg, tarc;
1875 /* Setup the HW Tx Head and Tail descriptor pointers */
1876 tdba = tx_ring->dma;
1877 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
1878 ew32(TDBAL, (tdba & DMA_32BIT_MASK));
1879 ew32(TDBAH, (tdba >> 32));
1883 tx_ring->head = E1000_TDH;
1884 tx_ring->tail = E1000_TDT;
1886 /* Set the default values for the Tx Inter Packet Gap timer */
1887 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
1888 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
1889 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
1891 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
1892 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
1894 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1895 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1898 /* Set the Tx Interrupt Delay register */
1899 ew32(TIDV, adapter->tx_int_delay);
1900 /* tx irq moderation */
1901 ew32(TADV, adapter->tx_abs_int_delay);
1903 /* Program the Transmit Control Register */
1905 tctl &= ~E1000_TCTL_CT;
1906 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1907 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1909 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
1911 /* set the speed mode bit, we'll clear it if we're not at
1912 * gigabit link later */
1913 #define SPEED_MODE_BIT (1 << 21)
1914 tarc |= SPEED_MODE_BIT;
1918 /* errata: program both queues to unweighted RR */
1919 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
1928 e1000e_config_collision_dist(hw);
1930 /* Setup Transmit Descriptor Settings for eop descriptor */
1931 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1933 /* only set IDE if we are delaying interrupts using the timers */
1934 if (adapter->tx_int_delay)
1935 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1937 /* enable Report Status bit */
1938 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1942 adapter->tx_queue_len = adapter->netdev->tx_queue_len;
1946 * e1000_setup_rctl - configure the receive control registers
1947 * @adapter: Board private structure
1949 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1950 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1951 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1953 struct e1000_hw *hw = &adapter->hw;
1958 /* Program MC offset vector base */
1960 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1961 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1962 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1963 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1965 /* Do not Store bad packets */
1966 rctl &= ~E1000_RCTL_SBP;
1968 /* Enable Long Packet receive */
1969 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1970 rctl &= ~E1000_RCTL_LPE;
1972 rctl |= E1000_RCTL_LPE;
1974 /* Setup buffer sizes */
1975 rctl &= ~E1000_RCTL_SZ_4096;
1976 rctl |= E1000_RCTL_BSEX;
1977 switch (adapter->rx_buffer_len) {
1979 rctl |= E1000_RCTL_SZ_256;
1980 rctl &= ~E1000_RCTL_BSEX;
1983 rctl |= E1000_RCTL_SZ_512;
1984 rctl &= ~E1000_RCTL_BSEX;
1987 rctl |= E1000_RCTL_SZ_1024;
1988 rctl &= ~E1000_RCTL_BSEX;
1992 rctl |= E1000_RCTL_SZ_2048;
1993 rctl &= ~E1000_RCTL_BSEX;
1996 rctl |= E1000_RCTL_SZ_4096;
1999 rctl |= E1000_RCTL_SZ_8192;
2002 rctl |= E1000_RCTL_SZ_16384;
2007 * 82571 and greater support packet-split where the protocol
2008 * header is placed in skb->data and the packet data is
2009 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2010 * In the case of a non-split, skb->data is linearly filled,
2011 * followed by the page buffers. Therefore, skb->data is
2012 * sized to hold the largest protocol header.
2014 * allocations using alloc_page take too long for regular MTU
2015 * so only enable packet split for jumbo frames
2017 * Using pages when the page size is greater than 16k wastes
2018 * a lot of memory, since we allocate 3 pages at all times
2021 adapter->rx_ps_pages = 0;
2022 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2023 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
2024 adapter->rx_ps_pages = pages;
2026 if (adapter->rx_ps_pages) {
2027 /* Configure extra packet-split registers */
2028 rfctl = er32(RFCTL);
2029 rfctl |= E1000_RFCTL_EXTEN;
2030 /* disable packet split support for IPv6 extension headers,
2031 * because some malformed IPv6 headers can hang the RX */
2032 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2033 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2037 /* disable the stripping of CRC because it breaks
2038 * BMC firmware connected over SMBUS */
2039 rctl |= E1000_RCTL_DTYP_PS /* | E1000_RCTL_SECRC */;
2041 psrctl |= adapter->rx_ps_bsize0 >>
2042 E1000_PSRCTL_BSIZE0_SHIFT;
2044 switch (adapter->rx_ps_pages) {
2046 psrctl |= PAGE_SIZE <<
2047 E1000_PSRCTL_BSIZE3_SHIFT;
2049 psrctl |= PAGE_SIZE <<
2050 E1000_PSRCTL_BSIZE2_SHIFT;
2052 psrctl |= PAGE_SIZE >>
2053 E1000_PSRCTL_BSIZE1_SHIFT;
2057 ew32(PSRCTL, psrctl);
2064 * e1000_configure_rx - Configure Receive Unit after Reset
2065 * @adapter: board private structure
2067 * Configure the Rx unit of the MAC after a reset.
2069 static void e1000_configure_rx(struct e1000_adapter *adapter)
2071 struct e1000_hw *hw = &adapter->hw;
2072 struct e1000_ring *rx_ring = adapter->rx_ring;
2074 u32 rdlen, rctl, rxcsum, ctrl_ext;
2076 if (adapter->rx_ps_pages) {
2077 /* this is a 32 byte descriptor */
2078 rdlen = rx_ring->count *
2079 sizeof(union e1000_rx_desc_packet_split);
2080 adapter->clean_rx = e1000_clean_rx_irq_ps;
2081 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2082 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + VLAN_HLEN + 4) {
2083 rdlen = rx_ring->count *
2084 sizeof(struct e1000_rx_desc);
2085 adapter->clean_rx = e1000_clean_rx_irq_jumbo;
2086 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_jumbo;
2088 rdlen = rx_ring->count *
2089 sizeof(struct e1000_rx_desc);
2090 adapter->clean_rx = e1000_clean_rx_irq;
2091 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2094 /* disable receives while setting up the descriptors */
2096 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2100 /* set the Receive Delay Timer Register */
2101 ew32(RDTR, adapter->rx_int_delay);
2103 /* irq moderation */
2104 ew32(RADV, adapter->rx_abs_int_delay);
2105 if (adapter->itr_setting != 0)
2107 1000000000 / (adapter->itr * 256));
2109 ctrl_ext = er32(CTRL_EXT);
2110 /* Reset delay timers after every interrupt */
2111 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
2112 /* Auto-Mask interrupts upon ICR access */
2113 ctrl_ext |= E1000_CTRL_EXT_IAME;
2114 ew32(IAM, 0xffffffff);
2115 ew32(CTRL_EXT, ctrl_ext);
2118 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2119 * the Base and Length of the Rx Descriptor Ring */
2120 rdba = rx_ring->dma;
2121 ew32(RDBAL, (rdba & DMA_32BIT_MASK));
2122 ew32(RDBAH, (rdba >> 32));
2126 rx_ring->head = E1000_RDH;
2127 rx_ring->tail = E1000_RDT;
2129 /* Enable Receive Checksum Offload for TCP and UDP */
2130 rxcsum = er32(RXCSUM);
2131 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2132 rxcsum |= E1000_RXCSUM_TUOFL;
2134 /* IPv4 payload checksum for UDP fragments must be
2135 * used in conjunction with packet-split. */
2136 if (adapter->rx_ps_pages)
2137 rxcsum |= E1000_RXCSUM_IPPCSE;
2139 rxcsum &= ~E1000_RXCSUM_TUOFL;
2140 /* no need to clear IPPCSE as it defaults to 0 */
2142 ew32(RXCSUM, rxcsum);
2144 /* Enable early receives on supported devices, only takes effect when
2145 * packet size is equal or larger than the specified value (in 8 byte
2146 * units), e.g. using jumbo frames when setting to E1000_ERT_2048 */
2147 if ((adapter->flags & FLAG_HAS_ERT) &&
2148 (adapter->netdev->mtu > ETH_DATA_LEN))
2149 ew32(ERT, E1000_ERT_2048);
2151 /* Enable Receives */
2156 * e1000_mc_addr_list_update - Update Multicast addresses
2157 * @hw: pointer to the HW structure
2158 * @mc_addr_list: array of multicast addresses to program
2159 * @mc_addr_count: number of multicast addresses to program
2160 * @rar_used_count: the first RAR register free to program
2161 * @rar_count: total number of supported Receive Address Registers
2163 * Updates the Receive Address Registers and Multicast Table Array.
2164 * The caller must have a packed mc_addr_list of multicast addresses.
2165 * The parameter rar_count will usually be hw->mac.rar_entry_count
2166 * unless there are workarounds that change this. Currently no func pointer
2167 * exists and all implementations are handled in the generic version of this
2170 static void e1000_mc_addr_list_update(struct e1000_hw *hw, u8 *mc_addr_list,
2171 u32 mc_addr_count, u32 rar_used_count,
2174 hw->mac.ops.mc_addr_list_update(hw, mc_addr_list, mc_addr_count,
2175 rar_used_count, rar_count);
2179 * e1000_set_multi - Multicast and Promiscuous mode set
2180 * @netdev: network interface device structure
2182 * The set_multi entry point is called whenever the multicast address
2183 * list or the network interface flags are updated. This routine is
2184 * responsible for configuring the hardware for proper multicast,
2185 * promiscuous mode, and all-multi behavior.
2187 static void e1000_set_multi(struct net_device *netdev)
2189 struct e1000_adapter *adapter = netdev_priv(netdev);
2190 struct e1000_hw *hw = &adapter->hw;
2191 struct e1000_mac_info *mac = &hw->mac;
2192 struct dev_mc_list *mc_ptr;
2197 /* Check for Promiscuous and All Multicast modes */
2201 if (netdev->flags & IFF_PROMISC) {
2202 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2203 } else if (netdev->flags & IFF_ALLMULTI) {
2204 rctl |= E1000_RCTL_MPE;
2205 rctl &= ~E1000_RCTL_UPE;
2207 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2212 if (netdev->mc_count) {
2213 mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);
2217 /* prepare a packed array of only addresses. */
2218 mc_ptr = netdev->mc_list;
2220 for (i = 0; i < netdev->mc_count; i++) {
2223 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
2225 mc_ptr = mc_ptr->next;
2228 e1000_mc_addr_list_update(hw, mta_list, i, 1,
2229 mac->rar_entry_count);
2233 * if we're called from probe, we might not have
2234 * anything to do here, so clear out the list
2236 e1000_mc_addr_list_update(hw, NULL, 0, 1,
2237 mac->rar_entry_count);
2242 * e1000_configure - configure the hardware for RX and TX
2243 * @adapter: private board structure
2245 static void e1000_configure(struct e1000_adapter *adapter)
2247 e1000_set_multi(adapter->netdev);
2249 e1000_restore_vlan(adapter);
2250 e1000_init_manageability(adapter);
2252 e1000_configure_tx(adapter);
2253 e1000_setup_rctl(adapter);
2254 e1000_configure_rx(adapter);
2255 adapter->alloc_rx_buf(adapter,
2256 e1000_desc_unused(adapter->rx_ring));
2260 * e1000e_power_up_phy - restore link in case the phy was powered down
2261 * @adapter: address of board private structure
2263 * The phy may be powered down to save power and turn off link when the
2264 * driver is unloaded and wake on lan is not enabled (among others)
2265 * *** this routine MUST be followed by a call to e1000e_reset ***
2267 void e1000e_power_up_phy(struct e1000_adapter *adapter)
2271 /* Just clear the power down bit to wake the phy back up */
2272 if (adapter->hw.media_type == e1000_media_type_copper) {
2273 /* according to the manual, the phy will retain its
2274 * settings across a power-down/up cycle */
2275 e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);
2276 mii_reg &= ~MII_CR_POWER_DOWN;
2277 e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);
2280 adapter->hw.mac.ops.setup_link(&adapter->hw);
2284 * e1000_power_down_phy - Power down the PHY
2286 * Power down the PHY so no link is implied when interface is down
2287 * The PHY cannot be powered down is management or WoL is active
2289 static void e1000_power_down_phy(struct e1000_adapter *adapter)
2291 struct e1000_hw *hw = &adapter->hw;
2294 /* WoL is enabled */
2298 /* non-copper PHY? */
2299 if (adapter->hw.media_type != e1000_media_type_copper)
2302 /* reset is blocked because of a SoL/IDER session */
2303 if (e1000e_check_mng_mode(hw) ||
2304 e1000_check_reset_block(hw))
2307 /* managebility (AMT) is enabled */
2308 if (er32(MANC) & E1000_MANC_SMBUS_EN)
2311 /* power down the PHY */
2312 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2313 mii_reg |= MII_CR_POWER_DOWN;
2314 e1e_wphy(hw, PHY_CONTROL, mii_reg);
2319 * e1000e_reset - bring the hardware into a known good state
2321 * This function boots the hardware and enables some settings that
2322 * require a configuration cycle of the hardware - those cannot be
2323 * set/changed during runtime. After reset the device needs to be
2324 * properly configured for rx, tx etc.
2326 void e1000e_reset(struct e1000_adapter *adapter)
2328 struct e1000_mac_info *mac = &adapter->hw.mac;
2329 struct e1000_hw *hw = &adapter->hw;
2330 u32 tx_space, min_tx_space, min_rx_space;
2333 if (mac->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN ) {
2334 /* To maintain wire speed transmits, the Tx FIFO should be
2335 * large enough to accommodate two full transmit packets,
2336 * rounded up to the next 1KB and expressed in KB. Likewise,
2337 * the Rx FIFO should be large enough to accommodate at least
2338 * one full receive packet and is similarly rounded up and
2339 * expressed in KB. */
2340 adapter->pba = er32(PBA);
2341 /* upper 16 bits has Tx packet buffer allocation size in KB */
2342 tx_space = adapter->pba >> 16;
2343 /* lower 16 bits has Rx packet buffer allocation size in KB */
2344 adapter->pba &= 0xffff;
2345 /* the tx fifo also stores 16 bytes of information about the tx
2346 * but don't include ethernet FCS because hardware appends it */
2347 min_tx_space = (mac->max_frame_size +
2348 sizeof(struct e1000_tx_desc) -
2350 min_tx_space = ALIGN(min_tx_space, 1024);
2351 min_tx_space >>= 10;
2352 /* software strips receive CRC, so leave room for it */
2353 min_rx_space = mac->max_frame_size;
2354 min_rx_space = ALIGN(min_rx_space, 1024);
2355 min_rx_space >>= 10;
2357 /* If current Tx allocation is less than the min Tx FIFO size,
2358 * and the min Tx FIFO size is less than the current Rx FIFO
2359 * allocation, take space away from current Rx allocation */
2360 if (tx_space < min_tx_space &&
2361 ((min_tx_space - tx_space) < adapter->pba)) {
2362 adapter->pba -= - (min_tx_space - tx_space);
2364 /* if short on rx space, rx wins and must trump tx
2365 * adjustment or use Early Receive if available */
2366 if ((adapter->pba < min_rx_space) &&
2367 (!(adapter->flags & FLAG_HAS_ERT)))
2368 /* ERT enabled in e1000_configure_rx */
2369 adapter->pba = min_rx_space;
2373 ew32(PBA, adapter->pba);
2375 /* flow control settings */
2376 /* The high water mark must be low enough to fit one full frame
2377 * (or the size used for early receive) above it in the Rx FIFO.
2378 * Set it to the lower of:
2379 * - 90% of the Rx FIFO size, and
2380 * - the full Rx FIFO size minus the early receive size (for parts
2381 * with ERT support assuming ERT set to E1000_ERT_2048), or
2382 * - the full Rx FIFO size minus one full frame */
2383 if (adapter->flags & FLAG_HAS_ERT)
2384 hwm = min(((adapter->pba << 10) * 9 / 10),
2385 ((adapter->pba << 10) - (E1000_ERT_2048 << 3)));
2387 hwm = min(((adapter->pba << 10) * 9 / 10),
2388 ((adapter->pba << 10) - mac->max_frame_size));
2390 mac->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
2391 mac->fc_low_water = mac->fc_high_water - 8;
2393 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
2394 mac->fc_pause_time = 0xFFFF;
2396 mac->fc_pause_time = E1000_FC_PAUSE_TIME;
2397 mac->fc = mac->original_fc;
2399 /* Allow time for pending master requests to run */
2400 mac->ops.reset_hw(hw);
2403 if (mac->ops.init_hw(hw))
2404 ndev_err(adapter->netdev, "Hardware Error\n");
2406 e1000_update_mng_vlan(adapter);
2408 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2409 ew32(VET, ETH_P_8021Q);
2411 e1000e_reset_adaptive(hw);
2412 e1000_get_phy_info(hw);
2414 if (!(adapter->flags & FLAG_SMART_POWER_DOWN)) {
2416 /* speed up time to link by disabling smart power down, ignore
2417 * the return value of this function because there is nothing
2418 * different we would do if it failed */
2419 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
2420 phy_data &= ~IGP02E1000_PM_SPD;
2421 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
2424 e1000_release_manageability(adapter);
2427 int e1000e_up(struct e1000_adapter *adapter)
2429 struct e1000_hw *hw = &adapter->hw;
2431 /* hardware has been reset, we need to reload some things */
2432 e1000_configure(adapter);
2434 clear_bit(__E1000_DOWN, &adapter->state);
2436 napi_enable(&adapter->napi);
2437 e1000_irq_enable(adapter);
2439 /* fire a link change interrupt to start the watchdog */
2440 ew32(ICS, E1000_ICS_LSC);
2444 void e1000e_down(struct e1000_adapter *adapter)
2446 struct net_device *netdev = adapter->netdev;
2447 struct e1000_hw *hw = &adapter->hw;
2450 /* signal that we're down so the interrupt handler does not
2451 * reschedule our watchdog timer */
2452 set_bit(__E1000_DOWN, &adapter->state);
2454 /* disable receives in the hardware */
2456 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2457 /* flush and sleep below */
2459 netif_stop_queue(netdev);
2461 /* disable transmits in the hardware */
2463 tctl &= ~E1000_TCTL_EN;
2465 /* flush both disables and wait for them to finish */
2469 napi_disable(&adapter->napi);
2470 e1000_irq_disable(adapter);
2472 del_timer_sync(&adapter->watchdog_timer);
2473 del_timer_sync(&adapter->phy_info_timer);
2475 netdev->tx_queue_len = adapter->tx_queue_len;
2476 netif_carrier_off(netdev);
2477 adapter->link_speed = 0;
2478 adapter->link_duplex = 0;
2480 e1000e_reset(adapter);
2481 e1000_clean_tx_ring(adapter);
2482 e1000_clean_rx_ring(adapter);
2485 * TODO: for power management, we could drop the link and
2486 * pci_disable_device here.
2490 void e1000e_reinit_locked(struct e1000_adapter *adapter)
2493 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
2495 e1000e_down(adapter);
2497 clear_bit(__E1000_RESETTING, &adapter->state);
2501 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2502 * @adapter: board private structure to initialize
2504 * e1000_sw_init initializes the Adapter private data structure.
2505 * Fields are initialized based on PCI device information and
2506 * OS network device settings (MTU size).
2508 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
2510 struct e1000_hw *hw = &adapter->hw;
2511 struct net_device *netdev = adapter->netdev;
2513 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
2514 adapter->rx_ps_bsize0 = 128;
2515 hw->mac.max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2516 hw->mac.min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
2518 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2519 if (!adapter->tx_ring)
2522 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2523 if (!adapter->rx_ring)
2526 spin_lock_init(&adapter->tx_queue_lock);
2528 /* Explicitly disable IRQ since the NIC can be in any state. */
2529 atomic_set(&adapter->irq_sem, 0);
2530 e1000_irq_disable(adapter);
2532 spin_lock_init(&adapter->stats_lock);
2534 set_bit(__E1000_DOWN, &adapter->state);
2538 ndev_err(netdev, "Unable to allocate memory for queues\n");
2539 kfree(adapter->rx_ring);
2540 kfree(adapter->tx_ring);
2545 * e1000_open - Called when a network interface is made active
2546 * @netdev: network interface device structure
2548 * Returns 0 on success, negative value on failure
2550 * The open entry point is called when a network interface is made
2551 * active by the system (IFF_UP). At this point all resources needed
2552 * for transmit and receive operations are allocated, the interrupt
2553 * handler is registered with the OS, the watchdog timer is started,
2554 * and the stack is notified that the interface is ready.
2556 static int e1000_open(struct net_device *netdev)
2558 struct e1000_adapter *adapter = netdev_priv(netdev);
2559 struct e1000_hw *hw = &adapter->hw;
2562 /* disallow open during test */
2563 if (test_bit(__E1000_TESTING, &adapter->state))
2566 /* allocate transmit descriptors */
2567 err = e1000e_setup_tx_resources(adapter);
2571 /* allocate receive descriptors */
2572 err = e1000e_setup_rx_resources(adapter);
2576 e1000e_power_up_phy(adapter);
2578 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2579 if ((adapter->hw.mng_cookie.status &
2580 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
2581 e1000_update_mng_vlan(adapter);
2583 /* If AMT is enabled, let the firmware know that the network
2584 * interface is now open */
2585 if ((adapter->flags & FLAG_HAS_AMT) &&
2586 e1000e_check_mng_mode(&adapter->hw))
2587 e1000_get_hw_control(adapter);
2589 /* before we allocate an interrupt, we must be ready to handle it.
2590 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
2591 * as soon as we call pci_request_irq, so we have to setup our
2592 * clean_rx handler before we do so. */
2593 e1000_configure(adapter);
2595 err = e1000_request_irq(adapter);
2599 /* From here on the code is the same as e1000e_up() */
2600 clear_bit(__E1000_DOWN, &adapter->state);
2602 napi_enable(&adapter->napi);
2604 e1000_irq_enable(adapter);
2606 /* fire a link status change interrupt to start the watchdog */
2607 ew32(ICS, E1000_ICS_LSC);
2612 e1000_release_hw_control(adapter);
2613 e1000_power_down_phy(adapter);
2614 e1000e_free_rx_resources(adapter);
2616 e1000e_free_tx_resources(adapter);
2618 e1000e_reset(adapter);
2624 * e1000_close - Disables a network interface
2625 * @netdev: network interface device structure
2627 * Returns 0, this is not allowed to fail
2629 * The close entry point is called when an interface is de-activated
2630 * by the OS. The hardware is still under the drivers control, but
2631 * needs to be disabled. A global MAC reset is issued to stop the
2632 * hardware, and all transmit and receive resources are freed.
2634 static int e1000_close(struct net_device *netdev)
2636 struct e1000_adapter *adapter = netdev_priv(netdev);
2638 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
2639 e1000e_down(adapter);
2640 e1000_power_down_phy(adapter);
2641 e1000_free_irq(adapter);
2643 e1000e_free_tx_resources(adapter);
2644 e1000e_free_rx_resources(adapter);
2646 /* kill manageability vlan ID if supported, but not if a vlan with
2647 * the same ID is registered on the host OS (let 8021q kill it) */
2648 if ((adapter->hw.mng_cookie.status &
2649 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2651 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
2652 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2654 /* If AMT is enabled, let the firmware know that the network
2655 * interface is now closed */
2656 if ((adapter->flags & FLAG_HAS_AMT) &&
2657 e1000e_check_mng_mode(&adapter->hw))
2658 e1000_release_hw_control(adapter);
2663 * e1000_set_mac - Change the Ethernet Address of the NIC
2664 * @netdev: network interface device structure
2665 * @p: pointer to an address structure
2667 * Returns 0 on success, negative on failure
2669 static int e1000_set_mac(struct net_device *netdev, void *p)
2671 struct e1000_adapter *adapter = netdev_priv(netdev);
2672 struct sockaddr *addr = p;
2674 if (!is_valid_ether_addr(addr->sa_data))
2675 return -EADDRNOTAVAIL;
2677 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2678 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
2680 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
2682 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
2683 /* activate the work around */
2684 e1000e_set_laa_state_82571(&adapter->hw, 1);
2686 /* Hold a copy of the LAA in RAR[14] This is done so that
2687 * between the time RAR[0] gets clobbered and the time it
2688 * gets fixed (in e1000_watchdog), the actual LAA is in one
2689 * of the RARs and no incoming packets directed to this port
2690 * are dropped. Eventually the LAA will be in RAR[0] and
2692 e1000e_rar_set(&adapter->hw,
2693 adapter->hw.mac.addr,
2694 adapter->hw.mac.rar_entry_count - 1);
2700 /* Need to wait a few seconds after link up to get diagnostic information from
2702 static void e1000_update_phy_info(unsigned long data)
2704 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2705 e1000_get_phy_info(&adapter->hw);
2709 * e1000e_update_stats - Update the board statistics counters
2710 * @adapter: board private structure
2712 void e1000e_update_stats(struct e1000_adapter *adapter)
2714 struct e1000_hw *hw = &adapter->hw;
2715 struct pci_dev *pdev = adapter->pdev;
2716 unsigned long irq_flags;
2719 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2722 * Prevent stats update while adapter is being reset, or if the pci
2723 * connection is down.
2725 if (adapter->link_speed == 0)
2727 if (pci_channel_offline(pdev))
2730 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
2732 /* these counters are modified from e1000_adjust_tbi_stats,
2733 * called from the interrupt context, so they must only
2734 * be written while holding adapter->stats_lock
2737 adapter->stats.crcerrs += er32(CRCERRS);
2738 adapter->stats.gprc += er32(GPRC);
2739 adapter->stats.gorcl += er32(GORCL);
2740 adapter->stats.gorch += er32(GORCH);
2741 adapter->stats.bprc += er32(BPRC);
2742 adapter->stats.mprc += er32(MPRC);
2743 adapter->stats.roc += er32(ROC);
2745 if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) {
2746 adapter->stats.prc64 += er32(PRC64);
2747 adapter->stats.prc127 += er32(PRC127);
2748 adapter->stats.prc255 += er32(PRC255);
2749 adapter->stats.prc511 += er32(PRC511);
2750 adapter->stats.prc1023 += er32(PRC1023);
2751 adapter->stats.prc1522 += er32(PRC1522);
2752 adapter->stats.symerrs += er32(SYMERRS);
2753 adapter->stats.sec += er32(SEC);
2756 adapter->stats.mpc += er32(MPC);
2757 adapter->stats.scc += er32(SCC);
2758 adapter->stats.ecol += er32(ECOL);
2759 adapter->stats.mcc += er32(MCC);
2760 adapter->stats.latecol += er32(LATECOL);
2761 adapter->stats.dc += er32(DC);
2762 adapter->stats.rlec += er32(RLEC);
2763 adapter->stats.xonrxc += er32(XONRXC);
2764 adapter->stats.xontxc += er32(XONTXC);
2765 adapter->stats.xoffrxc += er32(XOFFRXC);
2766 adapter->stats.xofftxc += er32(XOFFTXC);
2767 adapter->stats.fcruc += er32(FCRUC);
2768 adapter->stats.gptc += er32(GPTC);
2769 adapter->stats.gotcl += er32(GOTCL);
2770 adapter->stats.gotch += er32(GOTCH);
2771 adapter->stats.rnbc += er32(RNBC);
2772 adapter->stats.ruc += er32(RUC);
2773 adapter->stats.rfc += er32(RFC);
2774 adapter->stats.rjc += er32(RJC);
2775 adapter->stats.torl += er32(TORL);
2776 adapter->stats.torh += er32(TORH);
2777 adapter->stats.totl += er32(TOTL);
2778 adapter->stats.toth += er32(TOTH);
2779 adapter->stats.tpr += er32(TPR);
2781 if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) {
2782 adapter->stats.ptc64 += er32(PTC64);
2783 adapter->stats.ptc127 += er32(PTC127);
2784 adapter->stats.ptc255 += er32(PTC255);
2785 adapter->stats.ptc511 += er32(PTC511);
2786 adapter->stats.ptc1023 += er32(PTC1023);
2787 adapter->stats.ptc1522 += er32(PTC1522);
2790 adapter->stats.mptc += er32(MPTC);
2791 adapter->stats.bptc += er32(BPTC);
2793 /* used for adaptive IFS */
2795 hw->mac.tx_packet_delta = er32(TPT);
2796 adapter->stats.tpt += hw->mac.tx_packet_delta;
2797 hw->mac.collision_delta = er32(COLC);
2798 adapter->stats.colc += hw->mac.collision_delta;
2800 adapter->stats.algnerrc += er32(ALGNERRC);
2801 adapter->stats.rxerrc += er32(RXERRC);
2802 adapter->stats.tncrs += er32(TNCRS);
2803 adapter->stats.cexterr += er32(CEXTERR);
2804 adapter->stats.tsctc += er32(TSCTC);
2805 adapter->stats.tsctfc += er32(TSCTFC);
2807 adapter->stats.iac += er32(IAC);
2809 if (adapter->flags & FLAG_HAS_STATS_ICR_ICT) {
2810 adapter->stats.icrxoc += er32(ICRXOC);
2811 adapter->stats.icrxptc += er32(ICRXPTC);
2812 adapter->stats.icrxatc += er32(ICRXATC);
2813 adapter->stats.ictxptc += er32(ICTXPTC);
2814 adapter->stats.ictxatc += er32(ICTXATC);
2815 adapter->stats.ictxqec += er32(ICTXQEC);
2816 adapter->stats.ictxqmtc += er32(ICTXQMTC);
2817 adapter->stats.icrxdmtc += er32(ICRXDMTC);
2820 /* Fill out the OS statistics structure */
2821 adapter->net_stats.rx_packets = adapter->stats.gprc;
2822 adapter->net_stats.tx_packets = adapter->stats.gptc;
2823 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
2824 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
2825 adapter->net_stats.multicast = adapter->stats.mprc;
2826 adapter->net_stats.collisions = adapter->stats.colc;
2830 /* RLEC on some newer hardware can be incorrect so build
2831 * our own version based on RUC and ROC */
2832 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
2833 adapter->stats.crcerrs + adapter->stats.algnerrc +
2834 adapter->stats.ruc + adapter->stats.roc +
2835 adapter->stats.cexterr;
2836 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
2838 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2839 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
2840 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
2843 adapter->net_stats.tx_errors = adapter->stats.ecol +
2844 adapter->stats.latecol;
2845 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
2846 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
2847 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
2849 /* Tx Dropped needs to be maintained elsewhere */
2852 if (hw->media_type == e1000_media_type_copper) {
2853 if ((adapter->link_speed == SPEED_1000) &&
2854 (!e1e_rphy(hw, PHY_1000T_STATUS, &phy_tmp))) {
2855 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
2856 adapter->phy_stats.idle_errors += phy_tmp;
2860 /* Management Stats */
2861 adapter->stats.mgptc += er32(MGTPTC);
2862 adapter->stats.mgprc += er32(MGTPRC);
2863 adapter->stats.mgpdc += er32(MGTPDC);
2865 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
2868 static void e1000_print_link_info(struct e1000_adapter *adapter)
2870 struct net_device *netdev = adapter->netdev;
2871 struct e1000_hw *hw = &adapter->hw;
2872 u32 ctrl = er32(CTRL);
2875 "Link is Up %d Mbps %s, Flow Control: %s\n",
2876 adapter->link_speed,
2877 (adapter->link_duplex == FULL_DUPLEX) ?
2878 "Full Duplex" : "Half Duplex",
2879 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
2881 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
2882 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
2886 * e1000_watchdog - Timer Call-back
2887 * @data: pointer to adapter cast into an unsigned long
2889 static void e1000_watchdog(unsigned long data)
2891 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2893 /* Do the rest outside of interrupt context */
2894 schedule_work(&adapter->watchdog_task);
2896 /* TODO: make this use queue_delayed_work() */
2899 static void e1000_watchdog_task(struct work_struct *work)
2901 struct e1000_adapter *adapter = container_of(work,
2902 struct e1000_adapter, watchdog_task);
2904 struct net_device *netdev = adapter->netdev;
2905 struct e1000_mac_info *mac = &adapter->hw.mac;
2906 struct e1000_ring *tx_ring = adapter->tx_ring;
2907 struct e1000_hw *hw = &adapter->hw;
2912 if ((netif_carrier_ok(netdev)) &&
2913 (er32(STATUS) & E1000_STATUS_LU))
2916 ret_val = mac->ops.check_for_link(hw);
2917 if ((ret_val == E1000_ERR_PHY) &&
2918 (adapter->hw.phy.type == e1000_phy_igp_3) &&
2920 E1000_PHY_CTRL_GBE_DISABLE)) {
2921 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
2923 "Gigabit has been disabled, downgrading speed\n");
2926 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
2927 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
2928 e1000_update_mng_vlan(adapter);
2930 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2931 !(er32(TXCW) & E1000_TXCW_ANE))
2932 link = adapter->hw.mac.serdes_has_link;
2934 link = er32(STATUS) & E1000_STATUS_LU;
2937 if (!netif_carrier_ok(netdev)) {
2939 mac->ops.get_link_up_info(&adapter->hw,
2940 &adapter->link_speed,
2941 &adapter->link_duplex);
2942 e1000_print_link_info(adapter);
2943 /* tweak tx_queue_len according to speed/duplex
2944 * and adjust the timeout factor */
2945 netdev->tx_queue_len = adapter->tx_queue_len;
2946 adapter->tx_timeout_factor = 1;
2947 switch (adapter->link_speed) {
2950 netdev->tx_queue_len = 10;
2951 adapter->tx_timeout_factor = 14;
2955 netdev->tx_queue_len = 100;
2956 /* maybe add some timeout factor ? */
2960 /* workaround: re-program speed mode bit after
2962 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
2965 tarc0 = er32(TARC0);
2966 tarc0 &= ~SPEED_MODE_BIT;
2970 /* disable TSO for pcie and 10/100 speeds, to avoid
2971 * some hardware issues */
2972 if (!(adapter->flags & FLAG_TSO_FORCE)) {
2973 switch (adapter->link_speed) {
2977 "10/100 speed: disabling TSO\n");
2978 netdev->features &= ~NETIF_F_TSO;
2979 netdev->features &= ~NETIF_F_TSO6;
2982 netdev->features |= NETIF_F_TSO;
2983 netdev->features |= NETIF_F_TSO6;
2991 /* enable transmits in the hardware, need to do this
2992 * after setting TARC0 */
2994 tctl |= E1000_TCTL_EN;
2997 netif_carrier_on(netdev);
2998 netif_wake_queue(netdev);
3000 if (!test_bit(__E1000_DOWN, &adapter->state))
3001 mod_timer(&adapter->phy_info_timer,
3002 round_jiffies(jiffies + 2 * HZ));
3004 /* make sure the receive unit is started */
3005 if (adapter->flags & FLAG_RX_NEEDS_RESTART) {
3006 u32 rctl = er32(RCTL);
3012 if (netif_carrier_ok(netdev)) {
3013 adapter->link_speed = 0;
3014 adapter->link_duplex = 0;
3015 ndev_info(netdev, "Link is Down\n");
3016 netif_carrier_off(netdev);
3017 netif_stop_queue(netdev);
3018 if (!test_bit(__E1000_DOWN, &adapter->state))
3019 mod_timer(&adapter->phy_info_timer,
3020 round_jiffies(jiffies + 2 * HZ));
3022 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3023 schedule_work(&adapter->reset_task);
3028 e1000e_update_stats(adapter);
3030 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
3031 adapter->tpt_old = adapter->stats.tpt;
3032 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
3033 adapter->colc_old = adapter->stats.colc;
3035 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
3036 adapter->gorcl_old = adapter->stats.gorcl;
3037 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
3038 adapter->gotcl_old = adapter->stats.gotcl;
3040 e1000e_update_adaptive(&adapter->hw);
3042 if (!netif_carrier_ok(netdev)) {
3043 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
3046 /* We've lost link, so the controller stops DMA,
3047 * but we've got queued Tx work that's never going
3048 * to get done, so reset controller to flush Tx.
3049 * (Do the reset outside of interrupt context). */
3050 adapter->tx_timeout_count++;
3051 schedule_work(&adapter->reset_task);
3055 /* Cause software interrupt to ensure rx ring is cleaned */
3056 ew32(ICS, E1000_ICS_RXDMT0);
3058 /* Force detection of hung controller every watchdog period */
3059 adapter->detect_tx_hung = 1;
3061 /* With 82571 controllers, LAA may be overwritten due to controller
3062 * reset from the other port. Set the appropriate LAA in RAR[0] */
3063 if (e1000e_get_laa_state_82571(hw))
3064 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
3066 /* Reset the timer */
3067 if (!test_bit(__E1000_DOWN, &adapter->state))
3068 mod_timer(&adapter->watchdog_timer,
3069 round_jiffies(jiffies + 2 * HZ));
3072 #define E1000_TX_FLAGS_CSUM 0x00000001
3073 #define E1000_TX_FLAGS_VLAN 0x00000002
3074 #define E1000_TX_FLAGS_TSO 0x00000004
3075 #define E1000_TX_FLAGS_IPV4 0x00000008
3076 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
3077 #define E1000_TX_FLAGS_VLAN_SHIFT 16
3079 static int e1000_tso(struct e1000_adapter *adapter,
3080 struct sk_buff *skb)
3082 struct e1000_ring *tx_ring = adapter->tx_ring;
3083 struct e1000_context_desc *context_desc;
3084 struct e1000_buffer *buffer_info;
3087 u16 ipcse = 0, tucse, mss;
3088 u8 ipcss, ipcso, tucss, tucso, hdr_len;
3091 if (skb_is_gso(skb)) {
3092 if (skb_header_cloned(skb)) {
3093 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3098 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3099 mss = skb_shinfo(skb)->gso_size;
3100 if (skb->protocol == htons(ETH_P_IP)) {
3101 struct iphdr *iph = ip_hdr(skb);
3104 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3108 cmd_length = E1000_TXD_CMD_IP;
3109 ipcse = skb_transport_offset(skb) - 1;
3110 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3111 ipv6_hdr(skb)->payload_len = 0;
3112 tcp_hdr(skb)->check =
3113 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3114 &ipv6_hdr(skb)->daddr,
3118 ipcss = skb_network_offset(skb);
3119 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
3120 tucss = skb_transport_offset(skb);
3121 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
3124 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
3125 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
3127 i = tx_ring->next_to_use;
3128 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3129 buffer_info = &tx_ring->buffer_info[i];
3131 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3132 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3133 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3134 context_desc->upper_setup.tcp_fields.tucss = tucss;
3135 context_desc->upper_setup.tcp_fields.tucso = tucso;
3136 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3137 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3138 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3139 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3141 buffer_info->time_stamp = jiffies;
3142 buffer_info->next_to_watch = i;
3145 if (i == tx_ring->count)
3147 tx_ring->next_to_use = i;
3155 static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
3157 struct e1000_ring *tx_ring = adapter->tx_ring;
3158 struct e1000_context_desc *context_desc;
3159 struct e1000_buffer *buffer_info;
3163 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3164 css = skb_transport_offset(skb);
3166 i = tx_ring->next_to_use;
3167 buffer_info = &tx_ring->buffer_info[i];
3168 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3170 context_desc->lower_setup.ip_config = 0;
3171 context_desc->upper_setup.tcp_fields.tucss = css;
3172 context_desc->upper_setup.tcp_fields.tucso =
3173 css + skb->csum_offset;
3174 context_desc->upper_setup.tcp_fields.tucse = 0;
3175 context_desc->tcp_seg_setup.data = 0;
3176 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
3178 buffer_info->time_stamp = jiffies;
3179 buffer_info->next_to_watch = i;
3182 if (i == tx_ring->count)
3184 tx_ring->next_to_use = i;
3192 #define E1000_MAX_PER_TXD 8192
3193 #define E1000_MAX_TXD_PWR 12
3195 static int e1000_tx_map(struct e1000_adapter *adapter,
3196 struct sk_buff *skb, unsigned int first,
3197 unsigned int max_per_txd, unsigned int nr_frags,
3200 struct e1000_ring *tx_ring = adapter->tx_ring;
3201 struct e1000_buffer *buffer_info;
3202 unsigned int len = skb->len - skb->data_len;
3203 unsigned int offset = 0, size, count = 0, i;
3206 i = tx_ring->next_to_use;
3209 buffer_info = &tx_ring->buffer_info[i];
3210 size = min(len, max_per_txd);
3212 /* Workaround for premature desc write-backs
3213 * in TSO mode. Append 4-byte sentinel desc */
3214 if (mss && !nr_frags && size == len && size > 8)
3217 buffer_info->length = size;
3218 /* set time_stamp *before* dma to help avoid a possible race */
3219 buffer_info->time_stamp = jiffies;
3221 pci_map_single(adapter->pdev,
3225 if (pci_dma_mapping_error(buffer_info->dma)) {
3226 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
3227 adapter->tx_dma_failed++;
3230 buffer_info->next_to_watch = i;
3236 if (i == tx_ring->count)
3240 for (f = 0; f < nr_frags; f++) {
3241 struct skb_frag_struct *frag;
3243 frag = &skb_shinfo(skb)->frags[f];
3245 offset = frag->page_offset;
3248 buffer_info = &tx_ring->buffer_info[i];
3249 size = min(len, max_per_txd);
3250 /* Workaround for premature desc write-backs
3251 * in TSO mode. Append 4-byte sentinel desc */
3252 if (mss && f == (nr_frags-1) && size == len && size > 8)
3255 buffer_info->length = size;
3256 buffer_info->time_stamp = jiffies;
3258 pci_map_page(adapter->pdev,
3263 if (pci_dma_mapping_error(buffer_info->dma)) {
3264 dev_err(&adapter->pdev->dev,
3265 "TX DMA page map failed\n");
3266 adapter->tx_dma_failed++;
3270 buffer_info->next_to_watch = i;
3277 if (i == tx_ring->count)
3283 i = tx_ring->count - 1;
3287 tx_ring->buffer_info[i].skb = skb;
3288 tx_ring->buffer_info[first].next_to_watch = i;
3293 static void e1000_tx_queue(struct e1000_adapter *adapter,
3294 int tx_flags, int count)
3296 struct e1000_ring *tx_ring = adapter->tx_ring;
3297 struct e1000_tx_desc *tx_desc = NULL;
3298 struct e1000_buffer *buffer_info;
3299 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3302 if (tx_flags & E1000_TX_FLAGS_TSO) {
3303 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3305 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3307 if (tx_flags & E1000_TX_FLAGS_IPV4)
3308 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3311 if (tx_flags & E1000_TX_FLAGS_CSUM) {
3312 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3313 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3316 if (tx_flags & E1000_TX_FLAGS_VLAN) {
3317 txd_lower |= E1000_TXD_CMD_VLE;
3318 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3321 i = tx_ring->next_to_use;
3324 buffer_info = &tx_ring->buffer_info[i];
3325 tx_desc = E1000_TX_DESC(*tx_ring, i);
3326 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3327 tx_desc->lower.data =
3328 cpu_to_le32(txd_lower | buffer_info->length);
3329 tx_desc->upper.data = cpu_to_le32(txd_upper);
3332 if (i == tx_ring->count)
3336 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3338 /* Force memory writes to complete before letting h/w
3339 * know there are new descriptors to fetch. (Only
3340 * applicable for weak-ordered memory model archs,
3341 * such as IA-64). */
3344 tx_ring->next_to_use = i;
3345 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3346 /* we need this if more than one processor can write to our tail
3347 * at a time, it synchronizes IO on IA64/Altix systems */
3351 #define MINIMUM_DHCP_PACKET_SIZE 282
3352 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3353 struct sk_buff *skb)
3355 struct e1000_hw *hw = &adapter->hw;
3358 if (vlan_tx_tag_present(skb)) {
3359 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id)
3360 && (adapter->hw.mng_cookie.status &
3361 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
3365 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
3368 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
3372 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
3375 if (ip->protocol != IPPROTO_UDP)
3378 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
3379 if (ntohs(udp->dest) != 67)
3382 offset = (u8 *)udp + 8 - skb->data;
3383 length = skb->len - offset;
3384 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
3390 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3392 struct e1000_adapter *adapter = netdev_priv(netdev);
3394 netif_stop_queue(netdev);
3395 /* Herbert's original patch had:
3396 * smp_mb__after_netif_stop_queue();
3397 * but since that doesn't exist yet, just open code it. */
3400 /* We need to check again in a case another CPU has just
3401 * made room available. */
3402 if (e1000_desc_unused(adapter->tx_ring) < size)
3406 netif_start_queue(netdev);
3407 ++adapter->restart_queue;
3411 static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
3413 struct e1000_adapter *adapter = netdev_priv(netdev);
3415 if (e1000_desc_unused(adapter->tx_ring) >= size)
3417 return __e1000_maybe_stop_tx(netdev, size);
3420 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3421 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3423 struct e1000_adapter *adapter = netdev_priv(netdev);
3424 struct e1000_ring *tx_ring = adapter->tx_ring;
3426 unsigned int max_per_txd = E1000_MAX_PER_TXD;
3427 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3428 unsigned int tx_flags = 0;
3429 unsigned int len = skb->len;
3430 unsigned long irq_flags;
3431 unsigned int nr_frags = 0;
3432 unsigned int mss = 0;
3436 len -= skb->data_len;
3438 if (test_bit(__E1000_DOWN, &adapter->state)) {
3439 dev_kfree_skb_any(skb);
3440 return NETDEV_TX_OK;
3443 if (skb->len <= 0) {
3444 dev_kfree_skb_any(skb);
3445 return NETDEV_TX_OK;
3448 mss = skb_shinfo(skb)->gso_size;
3449 /* The controller does a simple calculation to
3450 * make sure there is enough room in the FIFO before
3451 * initiating the DMA for each buffer. The calc is:
3452 * 4 = ceil(buffer len/mss). To make sure we don't
3453 * overrun the FIFO, adjust the max buffer len if mss
3457 max_per_txd = min(mss << 2, max_per_txd);
3458 max_txd_pwr = fls(max_per_txd) - 1;
3460 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3461 * points to just header, pull a few bytes of payload from
3462 * frags into skb->data */
3463 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3464 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3465 unsigned int pull_size;
3467 pull_size = min((unsigned int)4, skb->data_len);
3468 if (!__pskb_pull_tail(skb, pull_size)) {
3470 "__pskb_pull_tail failed.\n");
3471 dev_kfree_skb_any(skb);
3472 return NETDEV_TX_OK;
3474 len = skb->len - skb->data_len;
3478 /* reserve a descriptor for the offload context */
3479 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3483 count += TXD_USE_COUNT(len, max_txd_pwr);
3485 nr_frags = skb_shinfo(skb)->nr_frags;
3486 for (f = 0; f < nr_frags; f++)
3487 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3490 if (adapter->hw.mac.tx_pkt_filtering)
3491 e1000_transfer_dhcp_info(adapter, skb);
3493 if (!spin_trylock_irqsave(&adapter->tx_queue_lock, irq_flags))
3494 /* Collision - tell upper layer to requeue */
3495 return NETDEV_TX_LOCKED;
3497 /* need: count + 2 desc gap to keep tail from touching
3498 * head, otherwise try next time */
3499 if (e1000_maybe_stop_tx(netdev, count + 2)) {
3500 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3501 return NETDEV_TX_BUSY;
3504 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3505 tx_flags |= E1000_TX_FLAGS_VLAN;
3506 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3509 first = tx_ring->next_to_use;
3511 tso = e1000_tso(adapter, skb);
3513 dev_kfree_skb_any(skb);
3514 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3515 return NETDEV_TX_OK;
3519 tx_flags |= E1000_TX_FLAGS_TSO;
3520 else if (e1000_tx_csum(adapter, skb))
3521 tx_flags |= E1000_TX_FLAGS_CSUM;
3523 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3524 * 82571 hardware supports TSO capabilities for IPv6 as well...
3525 * no longer assume, we must. */
3526 if (skb->protocol == htons(ETH_P_IP))
3527 tx_flags |= E1000_TX_FLAGS_IPV4;
3529 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
3531 /* handle pci_map_single() error in e1000_tx_map */
3532 dev_kfree_skb_any(skb);
3533 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3534 return NETDEV_TX_OK;
3537 e1000_tx_queue(adapter, tx_flags, count);
3539 netdev->trans_start = jiffies;
3541 /* Make sure there is space in the ring for the next send. */
3542 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
3544 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3545 return NETDEV_TX_OK;
3549 * e1000_tx_timeout - Respond to a Tx Hang
3550 * @netdev: network interface device structure
3552 static void e1000_tx_timeout(struct net_device *netdev)
3554 struct e1000_adapter *adapter = netdev_priv(netdev);
3556 /* Do the reset outside of interrupt context */
3557 adapter->tx_timeout_count++;
3558 schedule_work(&adapter->reset_task);
3561 static void e1000_reset_task(struct work_struct *work)
3563 struct e1000_adapter *adapter;
3564 adapter = container_of(work, struct e1000_adapter, reset_task);
3566 e1000e_reinit_locked(adapter);
3570 * e1000_get_stats - Get System Network Statistics
3571 * @netdev: network interface device structure
3573 * Returns the address of the device statistics structure.
3574 * The statistics are actually updated from the timer callback.
3576 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3578 struct e1000_adapter *adapter = netdev_priv(netdev);
3580 /* only return the current stats */
3581 return &adapter->net_stats;
3585 * e1000_change_mtu - Change the Maximum Transfer Unit
3586 * @netdev: network interface device structure
3587 * @new_mtu: new value for maximum frame size
3589 * Returns 0 on success, negative on failure
3591 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3593 struct e1000_adapter *adapter = netdev_priv(netdev);
3594 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3596 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
3597 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3598 ndev_err(netdev, "Invalid MTU setting\n");
3602 /* Jumbo frame size limits */
3603 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
3604 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
3605 ndev_err(netdev, "Jumbo Frames not supported.\n");
3608 if (adapter->hw.phy.type == e1000_phy_ife) {
3609 ndev_err(netdev, "Jumbo Frames not supported.\n");
3614 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3615 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3616 ndev_err(netdev, "MTU > 9216 not supported.\n");
3620 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3622 /* e1000e_down has a dependency on max_frame_size */
3623 adapter->hw.mac.max_frame_size = max_frame;
3624 if (netif_running(netdev))
3625 e1000e_down(adapter);
3627 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3628 * means we reserve 2 more, this pushes us to allocate from the next
3630 * i.e. RXBUFFER_2048 --> size-4096 slab
3631 * however with the new *_jumbo* routines, jumbo receives will use
3632 * fragmented skbs */
3634 if (max_frame <= 256)
3635 adapter->rx_buffer_len = 256;
3636 else if (max_frame <= 512)
3637 adapter->rx_buffer_len = 512;
3638 else if (max_frame <= 1024)
3639 adapter->rx_buffer_len = 1024;
3640 else if (max_frame <= 2048)
3641 adapter->rx_buffer_len = 2048;
3643 adapter->rx_buffer_len = 4096;
3645 /* adjust allocation if LPE protects us, and we aren't using SBP */
3646 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
3647 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
3648 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
3651 ndev_info(netdev, "changing MTU from %d to %d\n",
3652 netdev->mtu, new_mtu);
3653 netdev->mtu = new_mtu;
3655 if (netif_running(netdev))
3658 e1000e_reset(adapter);
3660 clear_bit(__E1000_RESETTING, &adapter->state);
3665 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
3668 struct e1000_adapter *adapter = netdev_priv(netdev);
3669 struct mii_ioctl_data *data = if_mii(ifr);
3670 unsigned long irq_flags;
3672 if (adapter->hw.media_type != e1000_media_type_copper)
3677 data->phy_id = adapter->hw.phy.addr;
3680 if (!capable(CAP_NET_ADMIN))
3682 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
3683 if (e1e_rphy(&adapter->hw, data->reg_num & 0x1F,
3685 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
3688 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
3697 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3703 return e1000_mii_ioctl(netdev, ifr, cmd);
3709 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
3711 struct net_device *netdev = pci_get_drvdata(pdev);
3712 struct e1000_adapter *adapter = netdev_priv(netdev);
3713 struct e1000_hw *hw = &adapter->hw;
3714 u32 ctrl, ctrl_ext, rctl, status;
3715 u32 wufc = adapter->wol;
3718 netif_device_detach(netdev);
3720 if (netif_running(netdev)) {
3721 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3722 e1000e_down(adapter);
3723 e1000_free_irq(adapter);
3726 retval = pci_save_state(pdev);
3730 status = er32(STATUS);
3731 if (status & E1000_STATUS_LU)
3732 wufc &= ~E1000_WUFC_LNKC;
3735 e1000_setup_rctl(adapter);
3736 e1000_set_multi(netdev);
3738 /* turn on all-multi mode if wake on multicast is enabled */
3739 if (wufc & E1000_WUFC_MC) {
3741 rctl |= E1000_RCTL_MPE;
3746 /* advertise wake from D3Cold */
3747 #define E1000_CTRL_ADVD3WUC 0x00100000
3748 /* phy power management enable */
3749 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3750 ctrl |= E1000_CTRL_ADVD3WUC |
3751 E1000_CTRL_EN_PHY_PWR_MGMT;
3754 if (adapter->hw.media_type == e1000_media_type_fiber ||
3755 adapter->hw.media_type == e1000_media_type_internal_serdes) {
3756 /* keep the laser running in D3 */
3757 ctrl_ext = er32(CTRL_EXT);
3758 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
3759 ew32(CTRL_EXT, ctrl_ext);
3762 /* Allow time for pending master requests to run */
3763 e1000e_disable_pcie_master(&adapter->hw);
3765 ew32(WUC, E1000_WUC_PME_EN);
3767 pci_enable_wake(pdev, PCI_D3hot, 1);
3768 pci_enable_wake(pdev, PCI_D3cold, 1);
3772 pci_enable_wake(pdev, PCI_D3hot, 0);
3773 pci_enable_wake(pdev, PCI_D3cold, 0);
3776 e1000_release_manageability(adapter);
3778 /* make sure adapter isn't asleep if manageability is enabled */
3779 if (adapter->flags & FLAG_MNG_PT_ENABLED) {
3780 pci_enable_wake(pdev, PCI_D3hot, 1);
3781 pci_enable_wake(pdev, PCI_D3cold, 1);
3784 if (adapter->hw.phy.type == e1000_phy_igp_3)
3785 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
3787 /* Release control of h/w to f/w. If f/w is AMT enabled, this
3788 * would have already happened in close and is redundant. */
3789 e1000_release_hw_control(adapter);
3791 pci_disable_device(pdev);
3793 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3799 static int e1000_resume(struct pci_dev *pdev)
3801 struct net_device *netdev = pci_get_drvdata(pdev);
3802 struct e1000_adapter *adapter = netdev_priv(netdev);
3803 struct e1000_hw *hw = &adapter->hw;
3806 pci_set_power_state(pdev, PCI_D0);
3807 pci_restore_state(pdev);
3808 err = pci_enable_device(pdev);
3811 "Cannot enable PCI device from suspend\n");
3815 pci_set_master(pdev);
3817 pci_enable_wake(pdev, PCI_D3hot, 0);
3818 pci_enable_wake(pdev, PCI_D3cold, 0);
3820 if (netif_running(netdev)) {
3821 err = e1000_request_irq(adapter);
3826 e1000e_power_up_phy(adapter);
3827 e1000e_reset(adapter);
3830 e1000_init_manageability(adapter);
3832 if (netif_running(netdev))
3835 netif_device_attach(netdev);
3837 /* If the controller has AMT, do not set DRV_LOAD until the interface
3838 * is up. For all other cases, let the f/w know that the h/w is now
3839 * under the control of the driver. */
3840 if (!(adapter->flags & FLAG_HAS_AMT) || !e1000e_check_mng_mode(&adapter->hw))
3841 e1000_get_hw_control(adapter);
3847 static void e1000_shutdown(struct pci_dev *pdev)
3849 e1000_suspend(pdev, PMSG_SUSPEND);
3852 #ifdef CONFIG_NET_POLL_CONTROLLER
3854 * Polling 'interrupt' - used by things like netconsole to send skbs
3855 * without having to re-enable interrupts. It's not called while
3856 * the interrupt routine is executing.
3858 static void e1000_netpoll(struct net_device *netdev)
3860 struct e1000_adapter *adapter = netdev_priv(netdev);
3862 disable_irq(adapter->pdev->irq);
3863 e1000_intr(adapter->pdev->irq, netdev);
3865 e1000_clean_tx_irq(adapter);
3867 enable_irq(adapter->pdev->irq);
3872 * e1000_io_error_detected - called when PCI error is detected
3873 * @pdev: Pointer to PCI device
3874 * @state: The current pci connection state
3876 * This function is called after a PCI bus error affecting
3877 * this device has been detected.
3879 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
3880 pci_channel_state_t state)
3882 struct net_device *netdev = pci_get_drvdata(pdev);
3883 struct e1000_adapter *adapter = netdev_priv(netdev);
3885 netif_device_detach(netdev);
3887 if (netif_running(netdev))
3888 e1000e_down(adapter);
3889 pci_disable_device(pdev);
3891 /* Request a slot slot reset. */
3892 return PCI_ERS_RESULT_NEED_RESET;
3896 * e1000_io_slot_reset - called after the pci bus has been reset.
3897 * @pdev: Pointer to PCI device
3899 * Restart the card from scratch, as if from a cold-boot. Implementation
3900 * resembles the first-half of the e1000_resume routine.
3902 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
3904 struct net_device *netdev = pci_get_drvdata(pdev);
3905 struct e1000_adapter *adapter = netdev_priv(netdev);
3906 struct e1000_hw *hw = &adapter->hw;
3908 if (pci_enable_device(pdev)) {
3910 "Cannot re-enable PCI device after reset.\n");
3911 return PCI_ERS_RESULT_DISCONNECT;
3913 pci_set_master(pdev);
3915 pci_enable_wake(pdev, PCI_D3hot, 0);
3916 pci_enable_wake(pdev, PCI_D3cold, 0);
3918 e1000e_reset(adapter);
3921 return PCI_ERS_RESULT_RECOVERED;
3925 * e1000_io_resume - called when traffic can start flowing again.
3926 * @pdev: Pointer to PCI device
3928 * This callback is called when the error recovery driver tells us that
3929 * its OK to resume normal operation. Implementation resembles the
3930 * second-half of the e1000_resume routine.
3932 static void e1000_io_resume(struct pci_dev *pdev)
3934 struct net_device *netdev = pci_get_drvdata(pdev);
3935 struct e1000_adapter *adapter = netdev_priv(netdev);
3937 e1000_init_manageability(adapter);
3939 if (netif_running(netdev)) {
3940 if (e1000e_up(adapter)) {
3942 "can't bring device back up after reset\n");
3947 netif_device_attach(netdev);
3949 /* If the controller has AMT, do not set DRV_LOAD until the interface
3950 * is up. For all other cases, let the f/w know that the h/w is now
3951 * under the control of the driver. */
3952 if (!(adapter->flags & FLAG_HAS_AMT) ||
3953 !e1000e_check_mng_mode(&adapter->hw))
3954 e1000_get_hw_control(adapter);
3958 static void e1000_print_device_info(struct e1000_adapter *adapter)
3960 struct e1000_hw *hw = &adapter->hw;
3961 struct net_device *netdev = adapter->netdev;
3964 /* print bus type/speed/width info */
3965 ndev_info(netdev, "(PCI Express:2.5GB/s:%s) "
3966 "%02x:%02x:%02x:%02x:%02x:%02x\n",
3968 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
3971 netdev->dev_addr[0], netdev->dev_addr[1],
3972 netdev->dev_addr[2], netdev->dev_addr[3],
3973 netdev->dev_addr[4], netdev->dev_addr[5]);
3974 ndev_info(netdev, "Intel(R) PRO/%s Network Connection\n",
3975 (hw->phy.type == e1000_phy_ife)
3976 ? "10/100" : "1000");
3977 e1000e_read_part_num(hw, &part_num);
3978 ndev_info(netdev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
3979 hw->mac.type, hw->phy.type,
3980 (part_num >> 8), (part_num & 0xff));
3984 * e1000_probe - Device Initialization Routine
3985 * @pdev: PCI device information struct
3986 * @ent: entry in e1000_pci_tbl
3988 * Returns 0 on success, negative on failure
3990 * e1000_probe initializes an adapter identified by a pci_dev structure.
3991 * The OS initialization, configuring of the adapter private structure,
3992 * and a hardware reset occur.
3994 static int __devinit e1000_probe(struct pci_dev *pdev,
3995 const struct pci_device_id *ent)
3997 struct net_device *netdev;
3998 struct e1000_adapter *adapter;
3999 struct e1000_hw *hw;
4000 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
4001 unsigned long mmio_start, mmio_len;
4002 unsigned long flash_start, flash_len;
4004 static int cards_found;
4005 int i, err, pci_using_dac;
4006 u16 eeprom_data = 0;
4007 u16 eeprom_apme_mask = E1000_EEPROM_APME;
4009 err = pci_enable_device(pdev);
4014 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
4016 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
4020 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4022 err = pci_set_consistent_dma_mask(pdev,
4025 dev_err(&pdev->dev, "No usable DMA "
4026 "configuration, aborting\n");
4032 err = pci_request_regions(pdev, e1000e_driver_name);
4036 pci_set_master(pdev);
4039 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
4041 goto err_alloc_etherdev;
4043 SET_NETDEV_DEV(netdev, &pdev->dev);
4045 pci_set_drvdata(pdev, netdev);
4046 adapter = netdev_priv(netdev);
4048 adapter->netdev = netdev;
4049 adapter->pdev = pdev;
4051 adapter->pba = ei->pba;
4052 adapter->flags = ei->flags;
4053 adapter->hw.adapter = adapter;
4054 adapter->hw.mac.type = ei->mac;
4055 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
4057 mmio_start = pci_resource_start(pdev, 0);
4058 mmio_len = pci_resource_len(pdev, 0);
4061 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
4062 if (!adapter->hw.hw_addr)
4065 if ((adapter->flags & FLAG_HAS_FLASH) &&
4066 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
4067 flash_start = pci_resource_start(pdev, 1);
4068 flash_len = pci_resource_len(pdev, 1);
4069 adapter->hw.flash_address = ioremap(flash_start, flash_len);
4070 if (!adapter->hw.flash_address)
4074 /* construct the net_device struct */
4075 netdev->open = &e1000_open;
4076 netdev->stop = &e1000_close;
4077 netdev->hard_start_xmit = &e1000_xmit_frame;
4078 netdev->get_stats = &e1000_get_stats;
4079 netdev->set_multicast_list = &e1000_set_multi;
4080 netdev->set_mac_address = &e1000_set_mac;
4081 netdev->change_mtu = &e1000_change_mtu;
4082 netdev->do_ioctl = &e1000_ioctl;
4083 e1000e_set_ethtool_ops(netdev);
4084 netdev->tx_timeout = &e1000_tx_timeout;
4085 netdev->watchdog_timeo = 5 * HZ;
4086 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
4087 netdev->vlan_rx_register = e1000_vlan_rx_register;
4088 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
4089 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
4090 #ifdef CONFIG_NET_POLL_CONTROLLER
4091 netdev->poll_controller = e1000_netpoll;
4093 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
4095 netdev->mem_start = mmio_start;
4096 netdev->mem_end = mmio_start + mmio_len;
4098 adapter->bd_number = cards_found++;
4100 /* setup adapter struct */
4101 err = e1000_sw_init(adapter);
4107 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
4108 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
4109 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
4111 err = ei->get_invariants(adapter);
4115 hw->mac.ops.get_bus_info(&adapter->hw);
4117 adapter->hw.phy.wait_for_link = 0;
4119 /* Copper options */
4120 if (adapter->hw.media_type == e1000_media_type_copper) {
4121 adapter->hw.phy.mdix = AUTO_ALL_MODES;
4122 adapter->hw.phy.disable_polarity_correction = 0;
4123 adapter->hw.phy.ms_type = e1000_ms_hw_default;
4126 if (e1000_check_reset_block(&adapter->hw))
4128 "PHY reset is blocked due to SOL/IDER session.\n");
4130 netdev->features = NETIF_F_SG |
4132 NETIF_F_HW_VLAN_TX |
4135 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
4136 netdev->features |= NETIF_F_HW_VLAN_FILTER;
4138 netdev->features |= NETIF_F_TSO;
4139 netdev->features |= NETIF_F_TSO6;
4142 netdev->features |= NETIF_F_HIGHDMA;
4144 /* We should not be using LLTX anymore, but we are still TX faster with
4146 netdev->features |= NETIF_F_LLTX;
4148 if (e1000e_enable_mng_pass_thru(&adapter->hw))
4149 adapter->flags |= FLAG_MNG_PT_ENABLED;
4151 /* before reading the NVM, reset the controller to
4152 * put the device in a known good starting state */
4153 adapter->hw.mac.ops.reset_hw(&adapter->hw);
4156 * systems with ASPM and others may see the checksum fail on the first
4157 * attempt. Let's give it a few tries
4160 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
4163 ndev_err(netdev, "The NVM Checksum Is Not Valid\n");
4169 /* copy the MAC address out of the NVM */
4170 if (e1000e_read_mac_addr(&adapter->hw))
4171 ndev_err(netdev, "NVM Read Error while reading MAC address\n");
4173 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
4174 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
4176 if (!is_valid_ether_addr(netdev->perm_addr)) {
4177 ndev_err(netdev, "Invalid MAC Address: "
4178 "%02x:%02x:%02x:%02x:%02x:%02x\n",
4179 netdev->perm_addr[0], netdev->perm_addr[1],
4180 netdev->perm_addr[2], netdev->perm_addr[3],
4181 netdev->perm_addr[4], netdev->perm_addr[5]);
4186 init_timer(&adapter->watchdog_timer);
4187 adapter->watchdog_timer.function = &e1000_watchdog;
4188 adapter->watchdog_timer.data = (unsigned long) adapter;
4190 init_timer(&adapter->phy_info_timer);
4191 adapter->phy_info_timer.function = &e1000_update_phy_info;
4192 adapter->phy_info_timer.data = (unsigned long) adapter;
4194 INIT_WORK(&adapter->reset_task, e1000_reset_task);
4195 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
4197 e1000e_check_options(adapter);
4199 /* Initialize link parameters. User can change them with ethtool */
4200 adapter->hw.mac.autoneg = 1;
4201 adapter->hw.mac.original_fc = e1000_fc_default;
4202 adapter->hw.mac.fc = e1000_fc_default;
4203 adapter->hw.phy.autoneg_advertised = 0x2f;
4205 /* ring size defaults */
4206 adapter->rx_ring->count = 256;
4207 adapter->tx_ring->count = 256;
4210 * Initial Wake on LAN setting - If APM wake is enabled in
4211 * the EEPROM, enable the ACPI Magic Packet filter
4213 if (adapter->flags & FLAG_APME_IN_WUC) {
4214 /* APME bit in EEPROM is mapped to WUC.APME */
4215 eeprom_data = er32(WUC);
4216 eeprom_apme_mask = E1000_WUC_APME;
4217 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
4218 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
4219 (adapter->hw.bus.func == 1))
4220 e1000_read_nvm(&adapter->hw,
4221 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
4223 e1000_read_nvm(&adapter->hw,
4224 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
4227 /* fetch WoL from EEPROM */
4228 if (eeprom_data & eeprom_apme_mask)
4229 adapter->eeprom_wol |= E1000_WUFC_MAG;
4232 * now that we have the eeprom settings, apply the special cases
4233 * where the eeprom may be wrong or the board simply won't support
4234 * wake on lan on a particular port
4236 if (!(adapter->flags & FLAG_HAS_WOL))
4237 adapter->eeprom_wol = 0;
4239 /* initialize the wol settings based on the eeprom settings */
4240 adapter->wol = adapter->eeprom_wol;
4242 /* reset the hardware with the new settings */
4243 e1000e_reset(adapter);
4245 /* If the controller has AMT, do not set DRV_LOAD until the interface
4246 * is up. For all other cases, let the f/w know that the h/w is now
4247 * under the control of the driver. */
4248 if (!(adapter->flags & FLAG_HAS_AMT) ||
4249 !e1000e_check_mng_mode(&adapter->hw))
4250 e1000_get_hw_control(adapter);
4252 /* tell the stack to leave us alone until e1000_open() is called */
4253 netif_carrier_off(netdev);
4254 netif_stop_queue(netdev);
4256 strcpy(netdev->name, "eth%d");
4257 err = register_netdev(netdev);
4261 e1000_print_device_info(adapter);
4267 e1000_release_hw_control(adapter);
4269 if (!e1000_check_reset_block(&adapter->hw))
4270 e1000_phy_hw_reset(&adapter->hw);
4272 if (adapter->hw.flash_address)
4273 iounmap(adapter->hw.flash_address);
4276 kfree(adapter->tx_ring);
4277 kfree(adapter->rx_ring);
4279 iounmap(adapter->hw.hw_addr);
4281 free_netdev(netdev);
4283 pci_release_regions(pdev);
4286 pci_disable_device(pdev);
4291 * e1000_remove - Device Removal Routine
4292 * @pdev: PCI device information struct
4294 * e1000_remove is called by the PCI subsystem to alert the driver
4295 * that it should release a PCI device. The could be caused by a
4296 * Hot-Plug event, or because the driver is going to be removed from
4299 static void __devexit e1000_remove(struct pci_dev *pdev)
4301 struct net_device *netdev = pci_get_drvdata(pdev);
4302 struct e1000_adapter *adapter = netdev_priv(netdev);
4304 /* flush_scheduled work may reschedule our watchdog task, so
4305 * explicitly disable watchdog tasks from being rescheduled */
4306 set_bit(__E1000_DOWN, &adapter->state);
4307 del_timer_sync(&adapter->watchdog_timer);
4308 del_timer_sync(&adapter->phy_info_timer);
4310 flush_scheduled_work();
4312 e1000_release_manageability(adapter);
4314 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4315 * would have already happened in close and is redundant. */
4316 e1000_release_hw_control(adapter);
4318 unregister_netdev(netdev);
4320 if (!e1000_check_reset_block(&adapter->hw))
4321 e1000_phy_hw_reset(&adapter->hw);
4323 kfree(adapter->tx_ring);
4324 kfree(adapter->rx_ring);
4326 iounmap(adapter->hw.hw_addr);
4327 if (adapter->hw.flash_address)
4328 iounmap(adapter->hw.flash_address);
4329 pci_release_regions(pdev);
4331 free_netdev(netdev);
4333 pci_disable_device(pdev);
4336 /* PCI Error Recovery (ERS) */
4337 static struct pci_error_handlers e1000_err_handler = {
4338 .error_detected = e1000_io_error_detected,
4339 .slot_reset = e1000_io_slot_reset,
4340 .resume = e1000_io_resume,
4343 static struct pci_device_id e1000_pci_tbl[] = {
4345 * Support for 82571/2/3, es2lan and ich8 will be phased in
4348 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
4349 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
4350 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
4351 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
4352 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
4353 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
4354 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
4355 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
4356 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
4357 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
4358 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
4359 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
4360 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
4361 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
4362 board_80003es2lan },
4363 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
4364 board_80003es2lan },
4365 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
4366 board_80003es2lan },
4367 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
4368 board_80003es2lan },
4369 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
4370 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
4371 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
4372 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
4373 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
4374 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
4375 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
4378 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
4379 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
4380 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
4381 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
4382 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
4384 { } /* terminate list */
4386 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
4388 /* PCI Device API Driver */
4389 static struct pci_driver e1000_driver = {
4390 .name = e1000e_driver_name,
4391 .id_table = e1000_pci_tbl,
4392 .probe = e1000_probe,
4393 .remove = __devexit_p(e1000_remove),
4395 /* Power Managment Hooks */
4396 .suspend = e1000_suspend,
4397 .resume = e1000_resume,
4399 .shutdown = e1000_shutdown,
4400 .err_handler = &e1000_err_handler
4404 * e1000_init_module - Driver Registration Routine
4406 * e1000_init_module is the first routine called when the driver is
4407 * loaded. All it does is register with the PCI subsystem.
4409 static int __init e1000_init_module(void)
4412 printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
4413 e1000e_driver_name, e1000e_driver_version);
4414 printk(KERN_INFO "%s: Copyright (c) 1999-2007 Intel Corporation.\n",
4415 e1000e_driver_name);
4416 ret = pci_register_driver(&e1000_driver);
4420 module_init(e1000_init_module);
4423 * e1000_exit_module - Driver Exit Cleanup Routine
4425 * e1000_exit_module is called just before the driver is removed
4428 static void __exit e1000_exit_module(void)
4430 pci_unregister_driver(&e1000_driver);
4432 module_exit(e1000_exit_module);
4435 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
4436 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
4437 MODULE_LICENSE("GPL");
4438 MODULE_VERSION(DRV_VERSION);