1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2009 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 <linux/slab.h>
40 #include <net/checksum.h>
41 #include <net/ip6_checksum.h>
42 #include <linux/mii.h>
43 #include <linux/ethtool.h>
44 #include <linux/if_vlan.h>
45 #include <linux/cpu.h>
46 #include <linux/smp.h>
47 #include <linux/pm_qos_params.h>
48 #include <linux/aer.h>
52 #define DRV_VERSION "1.0.2-k2"
53 char e1000e_driver_name[] = "e1000e";
54 const char e1000e_driver_version[] = DRV_VERSION;
56 static const struct e1000_info *e1000_info_tbl[] = {
57 [board_82571] = &e1000_82571_info,
58 [board_82572] = &e1000_82572_info,
59 [board_82573] = &e1000_82573_info,
60 [board_82574] = &e1000_82574_info,
61 [board_82583] = &e1000_82583_info,
62 [board_80003es2lan] = &e1000_es2_info,
63 [board_ich8lan] = &e1000_ich8_info,
64 [board_ich9lan] = &e1000_ich9_info,
65 [board_ich10lan] = &e1000_ich10_info,
66 [board_pchlan] = &e1000_pch_info,
70 * e1000_desc_unused - calculate if we have unused descriptors
72 static int e1000_desc_unused(struct e1000_ring *ring)
74 if (ring->next_to_clean > ring->next_to_use)
75 return ring->next_to_clean - ring->next_to_use - 1;
77 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
81 * e1000_receive_skb - helper function to handle Rx indications
82 * @adapter: board private structure
83 * @status: descriptor status field as written by hardware
84 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
85 * @skb: pointer to sk_buff to be indicated to stack
87 static void e1000_receive_skb(struct e1000_adapter *adapter,
88 struct net_device *netdev,
90 u8 status, __le16 vlan)
92 skb->protocol = eth_type_trans(skb, netdev);
94 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
95 vlan_gro_receive(&adapter->napi, adapter->vlgrp,
96 le16_to_cpu(vlan), skb);
98 napi_gro_receive(&adapter->napi, skb);
102 * e1000_rx_checksum - Receive Checksum Offload for 82543
103 * @adapter: board private structure
104 * @status_err: receive descriptor status and error fields
105 * @csum: receive descriptor csum field
106 * @sk_buff: socket buffer with received data
108 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
109 u32 csum, struct sk_buff *skb)
111 u16 status = (u16)status_err;
112 u8 errors = (u8)(status_err >> 24);
113 skb->ip_summed = CHECKSUM_NONE;
115 /* Ignore Checksum bit is set */
116 if (status & E1000_RXD_STAT_IXSM)
118 /* TCP/UDP checksum error bit is set */
119 if (errors & E1000_RXD_ERR_TCPE) {
120 /* let the stack verify checksum errors */
121 adapter->hw_csum_err++;
125 /* TCP/UDP Checksum has not been calculated */
126 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
129 /* It must be a TCP or UDP packet with a valid checksum */
130 if (status & E1000_RXD_STAT_TCPCS) {
131 /* TCP checksum is good */
132 skb->ip_summed = CHECKSUM_UNNECESSARY;
135 * IP fragment with UDP payload
136 * Hardware complements the payload checksum, so we undo it
137 * and then put the value in host order for further stack use.
139 __sum16 sum = (__force __sum16)htons(csum);
140 skb->csum = csum_unfold(~sum);
141 skb->ip_summed = CHECKSUM_COMPLETE;
143 adapter->hw_csum_good++;
147 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
148 * @adapter: address of board private structure
150 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
153 struct net_device *netdev = adapter->netdev;
154 struct pci_dev *pdev = adapter->pdev;
155 struct e1000_ring *rx_ring = adapter->rx_ring;
156 struct e1000_rx_desc *rx_desc;
157 struct e1000_buffer *buffer_info;
160 unsigned int bufsz = adapter->rx_buffer_len;
162 i = rx_ring->next_to_use;
163 buffer_info = &rx_ring->buffer_info[i];
165 while (cleaned_count--) {
166 skb = buffer_info->skb;
172 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
174 /* Better luck next round */
175 adapter->alloc_rx_buff_failed++;
179 buffer_info->skb = skb;
181 buffer_info->dma = pci_map_single(pdev, skb->data,
182 adapter->rx_buffer_len,
184 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
185 dev_err(&pdev->dev, "RX DMA map failed\n");
186 adapter->rx_dma_failed++;
190 rx_desc = E1000_RX_DESC(*rx_ring, i);
191 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
194 if (i == rx_ring->count)
196 buffer_info = &rx_ring->buffer_info[i];
199 if (rx_ring->next_to_use != i) {
200 rx_ring->next_to_use = i;
202 i = (rx_ring->count - 1);
205 * Force memory writes to complete before letting h/w
206 * know there are new descriptors to fetch. (Only
207 * applicable for weak-ordered memory model archs,
211 writel(i, adapter->hw.hw_addr + rx_ring->tail);
216 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
217 * @adapter: address of board private structure
219 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
222 struct net_device *netdev = adapter->netdev;
223 struct pci_dev *pdev = adapter->pdev;
224 union e1000_rx_desc_packet_split *rx_desc;
225 struct e1000_ring *rx_ring = adapter->rx_ring;
226 struct e1000_buffer *buffer_info;
227 struct e1000_ps_page *ps_page;
231 i = rx_ring->next_to_use;
232 buffer_info = &rx_ring->buffer_info[i];
234 while (cleaned_count--) {
235 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
237 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
238 ps_page = &buffer_info->ps_pages[j];
239 if (j >= adapter->rx_ps_pages) {
240 /* all unused desc entries get hw null ptr */
241 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
244 if (!ps_page->page) {
245 ps_page->page = alloc_page(GFP_ATOMIC);
246 if (!ps_page->page) {
247 adapter->alloc_rx_buff_failed++;
250 ps_page->dma = pci_map_page(pdev,
254 if (pci_dma_mapping_error(pdev, ps_page->dma)) {
255 dev_err(&adapter->pdev->dev,
256 "RX DMA page map failed\n");
257 adapter->rx_dma_failed++;
262 * Refresh the desc even if buffer_addrs
263 * didn't change because each write-back
266 rx_desc->read.buffer_addr[j+1] =
267 cpu_to_le64(ps_page->dma);
270 skb = netdev_alloc_skb_ip_align(netdev,
271 adapter->rx_ps_bsize0);
274 adapter->alloc_rx_buff_failed++;
278 buffer_info->skb = skb;
279 buffer_info->dma = pci_map_single(pdev, skb->data,
280 adapter->rx_ps_bsize0,
282 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
283 dev_err(&pdev->dev, "RX DMA map failed\n");
284 adapter->rx_dma_failed++;
286 dev_kfree_skb_any(skb);
287 buffer_info->skb = NULL;
291 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
294 if (i == rx_ring->count)
296 buffer_info = &rx_ring->buffer_info[i];
300 if (rx_ring->next_to_use != i) {
301 rx_ring->next_to_use = i;
304 i = (rx_ring->count - 1);
307 * Force memory writes to complete before letting h/w
308 * know there are new descriptors to fetch. (Only
309 * applicable for weak-ordered memory model archs,
314 * Hardware increments by 16 bytes, but packet split
315 * descriptors are 32 bytes...so we increment tail
318 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
323 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
324 * @adapter: address of board private structure
325 * @cleaned_count: number of buffers to allocate this pass
328 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
331 struct net_device *netdev = adapter->netdev;
332 struct pci_dev *pdev = adapter->pdev;
333 struct e1000_rx_desc *rx_desc;
334 struct e1000_ring *rx_ring = adapter->rx_ring;
335 struct e1000_buffer *buffer_info;
338 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
340 i = rx_ring->next_to_use;
341 buffer_info = &rx_ring->buffer_info[i];
343 while (cleaned_count--) {
344 skb = buffer_info->skb;
350 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
351 if (unlikely(!skb)) {
352 /* Better luck next round */
353 adapter->alloc_rx_buff_failed++;
357 buffer_info->skb = skb;
359 /* allocate a new page if necessary */
360 if (!buffer_info->page) {
361 buffer_info->page = alloc_page(GFP_ATOMIC);
362 if (unlikely(!buffer_info->page)) {
363 adapter->alloc_rx_buff_failed++;
368 if (!buffer_info->dma)
369 buffer_info->dma = pci_map_page(pdev,
370 buffer_info->page, 0,
374 rx_desc = E1000_RX_DESC(*rx_ring, i);
375 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
377 if (unlikely(++i == rx_ring->count))
379 buffer_info = &rx_ring->buffer_info[i];
382 if (likely(rx_ring->next_to_use != i)) {
383 rx_ring->next_to_use = i;
384 if (unlikely(i-- == 0))
385 i = (rx_ring->count - 1);
387 /* Force memory writes to complete before letting h/w
388 * know there are new descriptors to fetch. (Only
389 * applicable for weak-ordered memory model archs,
392 writel(i, adapter->hw.hw_addr + rx_ring->tail);
397 * e1000_clean_rx_irq - Send received data up the network stack; legacy
398 * @adapter: board private structure
400 * the return value indicates whether actual cleaning was done, there
401 * is no guarantee that everything was cleaned
403 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
404 int *work_done, int work_to_do)
406 struct net_device *netdev = adapter->netdev;
407 struct pci_dev *pdev = adapter->pdev;
408 struct e1000_hw *hw = &adapter->hw;
409 struct e1000_ring *rx_ring = adapter->rx_ring;
410 struct e1000_rx_desc *rx_desc, *next_rxd;
411 struct e1000_buffer *buffer_info, *next_buffer;
414 int cleaned_count = 0;
416 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
418 i = rx_ring->next_to_clean;
419 rx_desc = E1000_RX_DESC(*rx_ring, i);
420 buffer_info = &rx_ring->buffer_info[i];
422 while (rx_desc->status & E1000_RXD_STAT_DD) {
426 if (*work_done >= work_to_do)
430 status = rx_desc->status;
431 skb = buffer_info->skb;
432 buffer_info->skb = NULL;
434 prefetch(skb->data - NET_IP_ALIGN);
437 if (i == rx_ring->count)
439 next_rxd = E1000_RX_DESC(*rx_ring, i);
442 next_buffer = &rx_ring->buffer_info[i];
446 pci_unmap_single(pdev,
448 adapter->rx_buffer_len,
450 buffer_info->dma = 0;
452 length = le16_to_cpu(rx_desc->length);
455 * !EOP means multiple descriptors were used to store a single
456 * packet, if that's the case we need to toss it. In fact, we
457 * need to toss every packet with the EOP bit clear and the
458 * next frame that _does_ have the EOP bit set, as it is by
459 * definition only a frame fragment
461 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
462 adapter->flags2 |= FLAG2_IS_DISCARDING;
464 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
465 /* All receives must fit into a single buffer */
466 e_dbg("Receive packet consumed multiple buffers\n");
468 buffer_info->skb = skb;
469 if (status & E1000_RXD_STAT_EOP)
470 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
474 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
476 buffer_info->skb = skb;
480 /* adjust length to remove Ethernet CRC */
481 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
484 total_rx_bytes += length;
488 * code added for copybreak, this should improve
489 * performance for small packets with large amounts
490 * of reassembly being done in the stack
492 if (length < copybreak) {
493 struct sk_buff *new_skb =
494 netdev_alloc_skb_ip_align(netdev, length);
496 skb_copy_to_linear_data_offset(new_skb,
502 /* save the skb in buffer_info as good */
503 buffer_info->skb = skb;
506 /* else just continue with the old one */
508 /* end copybreak code */
509 skb_put(skb, length);
511 /* Receive Checksum Offload */
512 e1000_rx_checksum(adapter,
514 ((u32)(rx_desc->errors) << 24),
515 le16_to_cpu(rx_desc->csum), skb);
517 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
522 /* return some buffers to hardware, one at a time is too slow */
523 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
524 adapter->alloc_rx_buf(adapter, cleaned_count);
528 /* use prefetched values */
530 buffer_info = next_buffer;
532 rx_ring->next_to_clean = i;
534 cleaned_count = e1000_desc_unused(rx_ring);
536 adapter->alloc_rx_buf(adapter, cleaned_count);
538 adapter->total_rx_bytes += total_rx_bytes;
539 adapter->total_rx_packets += total_rx_packets;
540 netdev->stats.rx_bytes += total_rx_bytes;
541 netdev->stats.rx_packets += total_rx_packets;
545 static void e1000_put_txbuf(struct e1000_adapter *adapter,
546 struct e1000_buffer *buffer_info)
548 if (buffer_info->dma) {
549 if (buffer_info->mapped_as_page)
550 pci_unmap_page(adapter->pdev, buffer_info->dma,
551 buffer_info->length, PCI_DMA_TODEVICE);
553 pci_unmap_single(adapter->pdev, buffer_info->dma,
556 buffer_info->dma = 0;
558 if (buffer_info->skb) {
559 dev_kfree_skb_any(buffer_info->skb);
560 buffer_info->skb = NULL;
562 buffer_info->time_stamp = 0;
565 static void e1000_print_hw_hang(struct work_struct *work)
567 struct e1000_adapter *adapter = container_of(work,
568 struct e1000_adapter,
570 struct e1000_ring *tx_ring = adapter->tx_ring;
571 unsigned int i = tx_ring->next_to_clean;
572 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
573 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
574 struct e1000_hw *hw = &adapter->hw;
575 u16 phy_status, phy_1000t_status, phy_ext_status;
578 e1e_rphy(hw, PHY_STATUS, &phy_status);
579 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
580 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
582 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
584 /* detected Hardware unit hang */
585 e_err("Detected Hardware Unit Hang:\n"
588 " next_to_use <%x>\n"
589 " next_to_clean <%x>\n"
590 "buffer_info[next_to_clean]:\n"
591 " time_stamp <%lx>\n"
592 " next_to_watch <%x>\n"
594 " next_to_watch.status <%x>\n"
597 "PHY 1000BASE-T Status <%x>\n"
598 "PHY Extended Status <%x>\n"
600 readl(adapter->hw.hw_addr + tx_ring->head),
601 readl(adapter->hw.hw_addr + tx_ring->tail),
602 tx_ring->next_to_use,
603 tx_ring->next_to_clean,
604 tx_ring->buffer_info[eop].time_stamp,
607 eop_desc->upper.fields.status,
616 * e1000_clean_tx_irq - Reclaim resources after transmit completes
617 * @adapter: board private structure
619 * the return value indicates whether actual cleaning was done, there
620 * is no guarantee that everything was cleaned
622 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
624 struct net_device *netdev = adapter->netdev;
625 struct e1000_hw *hw = &adapter->hw;
626 struct e1000_ring *tx_ring = adapter->tx_ring;
627 struct e1000_tx_desc *tx_desc, *eop_desc;
628 struct e1000_buffer *buffer_info;
630 unsigned int count = 0;
631 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
633 i = tx_ring->next_to_clean;
634 eop = tx_ring->buffer_info[i].next_to_watch;
635 eop_desc = E1000_TX_DESC(*tx_ring, eop);
637 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
638 (count < tx_ring->count)) {
639 bool cleaned = false;
640 for (; !cleaned; count++) {
641 tx_desc = E1000_TX_DESC(*tx_ring, i);
642 buffer_info = &tx_ring->buffer_info[i];
643 cleaned = (i == eop);
646 struct sk_buff *skb = buffer_info->skb;
647 unsigned int segs, bytecount;
648 segs = skb_shinfo(skb)->gso_segs ?: 1;
649 /* multiply data chunks by size of headers */
650 bytecount = ((segs - 1) * skb_headlen(skb)) +
652 total_tx_packets += segs;
653 total_tx_bytes += bytecount;
656 e1000_put_txbuf(adapter, buffer_info);
657 tx_desc->upper.data = 0;
660 if (i == tx_ring->count)
664 eop = tx_ring->buffer_info[i].next_to_watch;
665 eop_desc = E1000_TX_DESC(*tx_ring, eop);
668 tx_ring->next_to_clean = i;
670 #define TX_WAKE_THRESHOLD 32
671 if (count && 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) {
687 * Detect a transmit hang in hardware, this serializes the
688 * check with the clearing of time_stamp and movement of i
690 adapter->detect_tx_hung = 0;
691 if (tx_ring->buffer_info[i].time_stamp &&
692 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
693 + (adapter->tx_timeout_factor * HZ)) &&
694 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
695 schedule_work(&adapter->print_hang_task);
696 netif_stop_queue(netdev);
699 adapter->total_tx_bytes += total_tx_bytes;
700 adapter->total_tx_packets += total_tx_packets;
701 netdev->stats.tx_bytes += total_tx_bytes;
702 netdev->stats.tx_packets += total_tx_packets;
703 return (count < tx_ring->count);
707 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
708 * @adapter: board private structure
710 * the return value indicates whether actual cleaning was done, there
711 * is no guarantee that everything was cleaned
713 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
714 int *work_done, int work_to_do)
716 struct e1000_hw *hw = &adapter->hw;
717 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
718 struct net_device *netdev = adapter->netdev;
719 struct pci_dev *pdev = adapter->pdev;
720 struct e1000_ring *rx_ring = adapter->rx_ring;
721 struct e1000_buffer *buffer_info, *next_buffer;
722 struct e1000_ps_page *ps_page;
726 int cleaned_count = 0;
728 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
730 i = rx_ring->next_to_clean;
731 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
732 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
733 buffer_info = &rx_ring->buffer_info[i];
735 while (staterr & E1000_RXD_STAT_DD) {
736 if (*work_done >= work_to_do)
739 skb = buffer_info->skb;
741 /* in the packet split case this is header only */
742 prefetch(skb->data - NET_IP_ALIGN);
745 if (i == rx_ring->count)
747 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
750 next_buffer = &rx_ring->buffer_info[i];
754 pci_unmap_single(pdev, buffer_info->dma,
755 adapter->rx_ps_bsize0,
757 buffer_info->dma = 0;
759 /* see !EOP comment in other rx routine */
760 if (!(staterr & E1000_RXD_STAT_EOP))
761 adapter->flags2 |= FLAG2_IS_DISCARDING;
763 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
764 e_dbg("Packet Split buffers didn't pick up the full "
766 dev_kfree_skb_irq(skb);
767 if (staterr & E1000_RXD_STAT_EOP)
768 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
772 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
773 dev_kfree_skb_irq(skb);
777 length = le16_to_cpu(rx_desc->wb.middle.length0);
780 e_dbg("Last part of the packet spanning multiple "
782 dev_kfree_skb_irq(skb);
787 skb_put(skb, length);
791 * this looks ugly, but it seems compiler issues make it
792 * more efficient than reusing j
794 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
797 * page alloc/put takes too long and effects small packet
798 * throughput, so unsplit small packets and save the alloc/put
799 * only valid in softirq (napi) context to call kmap_*
801 if (l1 && (l1 <= copybreak) &&
802 ((length + l1) <= adapter->rx_ps_bsize0)) {
805 ps_page = &buffer_info->ps_pages[0];
808 * there is no documentation about how to call
809 * kmap_atomic, so we can't hold the mapping
812 pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
813 PAGE_SIZE, PCI_DMA_FROMDEVICE);
814 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
815 memcpy(skb_tail_pointer(skb), vaddr, l1);
816 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
817 pci_dma_sync_single_for_device(pdev, ps_page->dma,
818 PAGE_SIZE, PCI_DMA_FROMDEVICE);
821 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
829 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
830 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
834 ps_page = &buffer_info->ps_pages[j];
835 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
838 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
839 ps_page->page = NULL;
841 skb->data_len += length;
842 skb->truesize += length;
845 /* strip the ethernet crc, problem is we're using pages now so
846 * this whole operation can get a little cpu intensive
848 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
849 pskb_trim(skb, skb->len - 4);
852 total_rx_bytes += skb->len;
855 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
856 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
858 if (rx_desc->wb.upper.header_status &
859 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
860 adapter->rx_hdr_split++;
862 e1000_receive_skb(adapter, netdev, skb,
863 staterr, rx_desc->wb.middle.vlan);
866 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
867 buffer_info->skb = NULL;
869 /* return some buffers to hardware, one at a time is too slow */
870 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
871 adapter->alloc_rx_buf(adapter, cleaned_count);
875 /* use prefetched values */
877 buffer_info = next_buffer;
879 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
881 rx_ring->next_to_clean = i;
883 cleaned_count = e1000_desc_unused(rx_ring);
885 adapter->alloc_rx_buf(adapter, cleaned_count);
887 adapter->total_rx_bytes += total_rx_bytes;
888 adapter->total_rx_packets += total_rx_packets;
889 netdev->stats.rx_bytes += total_rx_bytes;
890 netdev->stats.rx_packets += total_rx_packets;
895 * e1000_consume_page - helper function
897 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
902 skb->data_len += length;
903 skb->truesize += length;
907 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
908 * @adapter: board private structure
910 * the return value indicates whether actual cleaning was done, there
911 * is no guarantee that everything was cleaned
914 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
915 int *work_done, int work_to_do)
917 struct net_device *netdev = adapter->netdev;
918 struct pci_dev *pdev = adapter->pdev;
919 struct e1000_ring *rx_ring = adapter->rx_ring;
920 struct e1000_rx_desc *rx_desc, *next_rxd;
921 struct e1000_buffer *buffer_info, *next_buffer;
924 int cleaned_count = 0;
925 bool cleaned = false;
926 unsigned int total_rx_bytes=0, total_rx_packets=0;
928 i = rx_ring->next_to_clean;
929 rx_desc = E1000_RX_DESC(*rx_ring, i);
930 buffer_info = &rx_ring->buffer_info[i];
932 while (rx_desc->status & E1000_RXD_STAT_DD) {
936 if (*work_done >= work_to_do)
940 status = rx_desc->status;
941 skb = buffer_info->skb;
942 buffer_info->skb = NULL;
945 if (i == rx_ring->count)
947 next_rxd = E1000_RX_DESC(*rx_ring, i);
950 next_buffer = &rx_ring->buffer_info[i];
954 pci_unmap_page(pdev, buffer_info->dma, PAGE_SIZE,
956 buffer_info->dma = 0;
958 length = le16_to_cpu(rx_desc->length);
960 /* errors is only valid for DD + EOP descriptors */
961 if (unlikely((status & E1000_RXD_STAT_EOP) &&
962 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
963 /* recycle both page and skb */
964 buffer_info->skb = skb;
965 /* an error means any chain goes out the window
967 if (rx_ring->rx_skb_top)
968 dev_kfree_skb(rx_ring->rx_skb_top);
969 rx_ring->rx_skb_top = NULL;
973 #define rxtop rx_ring->rx_skb_top
974 if (!(status & E1000_RXD_STAT_EOP)) {
975 /* this descriptor is only the beginning (or middle) */
977 /* this is the beginning of a chain */
979 skb_fill_page_desc(rxtop, 0, buffer_info->page,
982 /* this is the middle of a chain */
983 skb_fill_page_desc(rxtop,
984 skb_shinfo(rxtop)->nr_frags,
985 buffer_info->page, 0, length);
986 /* re-use the skb, only consumed the page */
987 buffer_info->skb = skb;
989 e1000_consume_page(buffer_info, rxtop, length);
993 /* end of the chain */
994 skb_fill_page_desc(rxtop,
995 skb_shinfo(rxtop)->nr_frags,
996 buffer_info->page, 0, length);
997 /* re-use the current skb, we only consumed the
999 buffer_info->skb = skb;
1002 e1000_consume_page(buffer_info, skb, length);
1004 /* no chain, got EOP, this buf is the packet
1005 * copybreak to save the put_page/alloc_page */
1006 if (length <= copybreak &&
1007 skb_tailroom(skb) >= length) {
1009 vaddr = kmap_atomic(buffer_info->page,
1010 KM_SKB_DATA_SOFTIRQ);
1011 memcpy(skb_tail_pointer(skb), vaddr,
1013 kunmap_atomic(vaddr,
1014 KM_SKB_DATA_SOFTIRQ);
1015 /* re-use the page, so don't erase
1016 * buffer_info->page */
1017 skb_put(skb, length);
1019 skb_fill_page_desc(skb, 0,
1020 buffer_info->page, 0,
1022 e1000_consume_page(buffer_info, skb,
1028 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1029 e1000_rx_checksum(adapter,
1031 ((u32)(rx_desc->errors) << 24),
1032 le16_to_cpu(rx_desc->csum), skb);
1034 /* probably a little skewed due to removing CRC */
1035 total_rx_bytes += skb->len;
1038 /* eth type trans needs skb->data to point to something */
1039 if (!pskb_may_pull(skb, ETH_HLEN)) {
1040 e_err("pskb_may_pull failed.\n");
1045 e1000_receive_skb(adapter, netdev, skb, status,
1049 rx_desc->status = 0;
1051 /* return some buffers to hardware, one at a time is too slow */
1052 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1053 adapter->alloc_rx_buf(adapter, cleaned_count);
1057 /* use prefetched values */
1059 buffer_info = next_buffer;
1061 rx_ring->next_to_clean = i;
1063 cleaned_count = e1000_desc_unused(rx_ring);
1065 adapter->alloc_rx_buf(adapter, cleaned_count);
1067 adapter->total_rx_bytes += total_rx_bytes;
1068 adapter->total_rx_packets += total_rx_packets;
1069 netdev->stats.rx_bytes += total_rx_bytes;
1070 netdev->stats.rx_packets += total_rx_packets;
1075 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1076 * @adapter: board private structure
1078 static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1080 struct e1000_ring *rx_ring = adapter->rx_ring;
1081 struct e1000_buffer *buffer_info;
1082 struct e1000_ps_page *ps_page;
1083 struct pci_dev *pdev = adapter->pdev;
1086 /* Free all the Rx ring sk_buffs */
1087 for (i = 0; i < rx_ring->count; i++) {
1088 buffer_info = &rx_ring->buffer_info[i];
1089 if (buffer_info->dma) {
1090 if (adapter->clean_rx == e1000_clean_rx_irq)
1091 pci_unmap_single(pdev, buffer_info->dma,
1092 adapter->rx_buffer_len,
1093 PCI_DMA_FROMDEVICE);
1094 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1095 pci_unmap_page(pdev, buffer_info->dma,
1097 PCI_DMA_FROMDEVICE);
1098 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1099 pci_unmap_single(pdev, buffer_info->dma,
1100 adapter->rx_ps_bsize0,
1101 PCI_DMA_FROMDEVICE);
1102 buffer_info->dma = 0;
1105 if (buffer_info->page) {
1106 put_page(buffer_info->page);
1107 buffer_info->page = NULL;
1110 if (buffer_info->skb) {
1111 dev_kfree_skb(buffer_info->skb);
1112 buffer_info->skb = NULL;
1115 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1116 ps_page = &buffer_info->ps_pages[j];
1119 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
1120 PCI_DMA_FROMDEVICE);
1122 put_page(ps_page->page);
1123 ps_page->page = NULL;
1127 /* there also may be some cached data from a chained receive */
1128 if (rx_ring->rx_skb_top) {
1129 dev_kfree_skb(rx_ring->rx_skb_top);
1130 rx_ring->rx_skb_top = NULL;
1133 /* Zero out the descriptor ring */
1134 memset(rx_ring->desc, 0, rx_ring->size);
1136 rx_ring->next_to_clean = 0;
1137 rx_ring->next_to_use = 0;
1138 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1140 writel(0, adapter->hw.hw_addr + rx_ring->head);
1141 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1144 static void e1000e_downshift_workaround(struct work_struct *work)
1146 struct e1000_adapter *adapter = container_of(work,
1147 struct e1000_adapter, downshift_task);
1149 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1153 * e1000_intr_msi - Interrupt Handler
1154 * @irq: interrupt number
1155 * @data: pointer to a network interface device structure
1157 static irqreturn_t e1000_intr_msi(int irq, void *data)
1159 struct net_device *netdev = data;
1160 struct e1000_adapter *adapter = netdev_priv(netdev);
1161 struct e1000_hw *hw = &adapter->hw;
1162 u32 icr = er32(ICR);
1165 * read ICR disables interrupts using IAM
1168 if (icr & E1000_ICR_LSC) {
1169 hw->mac.get_link_status = 1;
1171 * ICH8 workaround-- Call gig speed drop workaround on cable
1172 * disconnect (LSC) before accessing any PHY registers
1174 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1175 (!(er32(STATUS) & E1000_STATUS_LU)))
1176 schedule_work(&adapter->downshift_task);
1179 * 80003ES2LAN workaround-- For packet buffer work-around on
1180 * link down event; disable receives here in the ISR and reset
1181 * adapter in watchdog
1183 if (netif_carrier_ok(netdev) &&
1184 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1185 /* disable receives */
1186 u32 rctl = er32(RCTL);
1187 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1188 adapter->flags |= FLAG_RX_RESTART_NOW;
1190 /* guard against interrupt when we're going down */
1191 if (!test_bit(__E1000_DOWN, &adapter->state))
1192 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1195 if (napi_schedule_prep(&adapter->napi)) {
1196 adapter->total_tx_bytes = 0;
1197 adapter->total_tx_packets = 0;
1198 adapter->total_rx_bytes = 0;
1199 adapter->total_rx_packets = 0;
1200 __napi_schedule(&adapter->napi);
1207 * e1000_intr - Interrupt Handler
1208 * @irq: interrupt number
1209 * @data: pointer to a network interface device structure
1211 static irqreturn_t e1000_intr(int irq, void *data)
1213 struct net_device *netdev = data;
1214 struct e1000_adapter *adapter = netdev_priv(netdev);
1215 struct e1000_hw *hw = &adapter->hw;
1216 u32 rctl, icr = er32(ICR);
1218 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
1219 return IRQ_NONE; /* Not our interrupt */
1222 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1223 * not set, then the adapter didn't send an interrupt
1225 if (!(icr & E1000_ICR_INT_ASSERTED))
1229 * Interrupt Auto-Mask...upon reading ICR,
1230 * interrupts are masked. No need for the
1234 if (icr & E1000_ICR_LSC) {
1235 hw->mac.get_link_status = 1;
1237 * ICH8 workaround-- Call gig speed drop workaround on cable
1238 * disconnect (LSC) before accessing any PHY registers
1240 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1241 (!(er32(STATUS) & E1000_STATUS_LU)))
1242 schedule_work(&adapter->downshift_task);
1245 * 80003ES2LAN workaround--
1246 * For packet buffer work-around on link down event;
1247 * disable receives here in the ISR and
1248 * reset adapter in watchdog
1250 if (netif_carrier_ok(netdev) &&
1251 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1252 /* disable receives */
1254 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1255 adapter->flags |= FLAG_RX_RESTART_NOW;
1257 /* guard against interrupt when we're going down */
1258 if (!test_bit(__E1000_DOWN, &adapter->state))
1259 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1262 if (napi_schedule_prep(&adapter->napi)) {
1263 adapter->total_tx_bytes = 0;
1264 adapter->total_tx_packets = 0;
1265 adapter->total_rx_bytes = 0;
1266 adapter->total_rx_packets = 0;
1267 __napi_schedule(&adapter->napi);
1273 static irqreturn_t e1000_msix_other(int irq, void *data)
1275 struct net_device *netdev = data;
1276 struct e1000_adapter *adapter = netdev_priv(netdev);
1277 struct e1000_hw *hw = &adapter->hw;
1278 u32 icr = er32(ICR);
1280 if (!(icr & E1000_ICR_INT_ASSERTED)) {
1281 if (!test_bit(__E1000_DOWN, &adapter->state))
1282 ew32(IMS, E1000_IMS_OTHER);
1286 if (icr & adapter->eiac_mask)
1287 ew32(ICS, (icr & adapter->eiac_mask));
1289 if (icr & E1000_ICR_OTHER) {
1290 if (!(icr & E1000_ICR_LSC))
1291 goto no_link_interrupt;
1292 hw->mac.get_link_status = 1;
1293 /* guard against interrupt when we're going down */
1294 if (!test_bit(__E1000_DOWN, &adapter->state))
1295 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1299 if (!test_bit(__E1000_DOWN, &adapter->state))
1300 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
1306 static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1308 struct net_device *netdev = data;
1309 struct e1000_adapter *adapter = netdev_priv(netdev);
1310 struct e1000_hw *hw = &adapter->hw;
1311 struct e1000_ring *tx_ring = adapter->tx_ring;
1314 adapter->total_tx_bytes = 0;
1315 adapter->total_tx_packets = 0;
1317 if (!e1000_clean_tx_irq(adapter))
1318 /* Ring was not completely cleaned, so fire another interrupt */
1319 ew32(ICS, tx_ring->ims_val);
1324 static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1326 struct net_device *netdev = data;
1327 struct e1000_adapter *adapter = netdev_priv(netdev);
1329 /* Write the ITR value calculated at the end of the
1330 * previous interrupt.
1332 if (adapter->rx_ring->set_itr) {
1333 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1334 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1335 adapter->rx_ring->set_itr = 0;
1338 if (napi_schedule_prep(&adapter->napi)) {
1339 adapter->total_rx_bytes = 0;
1340 adapter->total_rx_packets = 0;
1341 __napi_schedule(&adapter->napi);
1347 * e1000_configure_msix - Configure MSI-X hardware
1349 * e1000_configure_msix sets up the hardware to properly
1350 * generate MSI-X interrupts.
1352 static void e1000_configure_msix(struct e1000_adapter *adapter)
1354 struct e1000_hw *hw = &adapter->hw;
1355 struct e1000_ring *rx_ring = adapter->rx_ring;
1356 struct e1000_ring *tx_ring = adapter->tx_ring;
1358 u32 ctrl_ext, ivar = 0;
1360 adapter->eiac_mask = 0;
1362 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1363 if (hw->mac.type == e1000_82574) {
1364 u32 rfctl = er32(RFCTL);
1365 rfctl |= E1000_RFCTL_ACK_DIS;
1369 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1370 /* Configure Rx vector */
1371 rx_ring->ims_val = E1000_IMS_RXQ0;
1372 adapter->eiac_mask |= rx_ring->ims_val;
1373 if (rx_ring->itr_val)
1374 writel(1000000000 / (rx_ring->itr_val * 256),
1375 hw->hw_addr + rx_ring->itr_register);
1377 writel(1, hw->hw_addr + rx_ring->itr_register);
1378 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1380 /* Configure Tx vector */
1381 tx_ring->ims_val = E1000_IMS_TXQ0;
1383 if (tx_ring->itr_val)
1384 writel(1000000000 / (tx_ring->itr_val * 256),
1385 hw->hw_addr + tx_ring->itr_register);
1387 writel(1, hw->hw_addr + tx_ring->itr_register);
1388 adapter->eiac_mask |= tx_ring->ims_val;
1389 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1391 /* set vector for Other Causes, e.g. link changes */
1393 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1394 if (rx_ring->itr_val)
1395 writel(1000000000 / (rx_ring->itr_val * 256),
1396 hw->hw_addr + E1000_EITR_82574(vector));
1398 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1400 /* Cause Tx interrupts on every write back */
1405 /* enable MSI-X PBA support */
1406 ctrl_ext = er32(CTRL_EXT);
1407 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1409 /* Auto-Mask Other interrupts upon ICR read */
1410 #define E1000_EIAC_MASK_82574 0x01F00000
1411 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1412 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1413 ew32(CTRL_EXT, ctrl_ext);
1417 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1419 if (adapter->msix_entries) {
1420 pci_disable_msix(adapter->pdev);
1421 kfree(adapter->msix_entries);
1422 adapter->msix_entries = NULL;
1423 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1424 pci_disable_msi(adapter->pdev);
1425 adapter->flags &= ~FLAG_MSI_ENABLED;
1432 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1434 * Attempt to configure interrupts using the best available
1435 * capabilities of the hardware and kernel.
1437 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1443 switch (adapter->int_mode) {
1444 case E1000E_INT_MODE_MSIX:
1445 if (adapter->flags & FLAG_HAS_MSIX) {
1446 numvecs = 3; /* RxQ0, TxQ0 and other */
1447 adapter->msix_entries = kcalloc(numvecs,
1448 sizeof(struct msix_entry),
1450 if (adapter->msix_entries) {
1451 for (i = 0; i < numvecs; i++)
1452 adapter->msix_entries[i].entry = i;
1454 err = pci_enable_msix(adapter->pdev,
1455 adapter->msix_entries,
1460 /* MSI-X failed, so fall through and try MSI */
1461 e_err("Failed to initialize MSI-X interrupts. "
1462 "Falling back to MSI interrupts.\n");
1463 e1000e_reset_interrupt_capability(adapter);
1465 adapter->int_mode = E1000E_INT_MODE_MSI;
1467 case E1000E_INT_MODE_MSI:
1468 if (!pci_enable_msi(adapter->pdev)) {
1469 adapter->flags |= FLAG_MSI_ENABLED;
1471 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1472 e_err("Failed to initialize MSI interrupts. Falling "
1473 "back to legacy interrupts.\n");
1476 case E1000E_INT_MODE_LEGACY:
1477 /* Don't do anything; this is the system default */
1485 * e1000_request_msix - Initialize MSI-X interrupts
1487 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1490 static int e1000_request_msix(struct e1000_adapter *adapter)
1492 struct net_device *netdev = adapter->netdev;
1493 int err = 0, vector = 0;
1495 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1496 sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
1498 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1499 err = request_irq(adapter->msix_entries[vector].vector,
1500 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
1504 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1505 adapter->rx_ring->itr_val = adapter->itr;
1508 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1509 sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
1511 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1512 err = request_irq(adapter->msix_entries[vector].vector,
1513 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
1517 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1518 adapter->tx_ring->itr_val = adapter->itr;
1521 err = request_irq(adapter->msix_entries[vector].vector,
1522 e1000_msix_other, 0, netdev->name, netdev);
1526 e1000_configure_msix(adapter);
1533 * e1000_request_irq - initialize interrupts
1535 * Attempts to configure interrupts using the best available
1536 * capabilities of the hardware and kernel.
1538 static int e1000_request_irq(struct e1000_adapter *adapter)
1540 struct net_device *netdev = adapter->netdev;
1543 if (adapter->msix_entries) {
1544 err = e1000_request_msix(adapter);
1547 /* fall back to MSI */
1548 e1000e_reset_interrupt_capability(adapter);
1549 adapter->int_mode = E1000E_INT_MODE_MSI;
1550 e1000e_set_interrupt_capability(adapter);
1552 if (adapter->flags & FLAG_MSI_ENABLED) {
1553 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
1554 netdev->name, netdev);
1558 /* fall back to legacy interrupt */
1559 e1000e_reset_interrupt_capability(adapter);
1560 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1563 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
1564 netdev->name, netdev);
1566 e_err("Unable to allocate interrupt, Error: %d\n", err);
1571 static void e1000_free_irq(struct e1000_adapter *adapter)
1573 struct net_device *netdev = adapter->netdev;
1575 if (adapter->msix_entries) {
1578 free_irq(adapter->msix_entries[vector].vector, netdev);
1581 free_irq(adapter->msix_entries[vector].vector, netdev);
1584 /* Other Causes interrupt vector */
1585 free_irq(adapter->msix_entries[vector].vector, netdev);
1589 free_irq(adapter->pdev->irq, netdev);
1593 * e1000_irq_disable - Mask off interrupt generation on the NIC
1595 static void e1000_irq_disable(struct e1000_adapter *adapter)
1597 struct e1000_hw *hw = &adapter->hw;
1600 if (adapter->msix_entries)
1601 ew32(EIAC_82574, 0);
1603 synchronize_irq(adapter->pdev->irq);
1607 * e1000_irq_enable - Enable default interrupt generation settings
1609 static void e1000_irq_enable(struct e1000_adapter *adapter)
1611 struct e1000_hw *hw = &adapter->hw;
1613 if (adapter->msix_entries) {
1614 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1615 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1617 ew32(IMS, IMS_ENABLE_MASK);
1623 * e1000_get_hw_control - get control of the h/w from f/w
1624 * @adapter: address of board private structure
1626 * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1627 * For ASF and Pass Through versions of f/w this means that
1628 * the driver is loaded. For AMT version (only with 82573)
1629 * of the f/w this means that the network i/f is open.
1631 static void e1000_get_hw_control(struct e1000_adapter *adapter)
1633 struct e1000_hw *hw = &adapter->hw;
1637 /* Let firmware know the driver has taken over */
1638 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1640 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1641 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1642 ctrl_ext = er32(CTRL_EXT);
1643 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1648 * e1000_release_hw_control - release control of the h/w to f/w
1649 * @adapter: address of board private structure
1651 * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1652 * For ASF and Pass Through versions of f/w this means that the
1653 * driver is no longer loaded. For AMT version (only with 82573) i
1654 * of the f/w this means that the network i/f is closed.
1657 static void e1000_release_hw_control(struct e1000_adapter *adapter)
1659 struct e1000_hw *hw = &adapter->hw;
1663 /* Let firmware taken over control of h/w */
1664 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1666 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1667 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1668 ctrl_ext = er32(CTRL_EXT);
1669 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1674 * @e1000_alloc_ring - allocate memory for a ring structure
1676 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
1677 struct e1000_ring *ring)
1679 struct pci_dev *pdev = adapter->pdev;
1681 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
1690 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1691 * @adapter: board private structure
1693 * Return 0 on success, negative on failure
1695 int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
1697 struct e1000_ring *tx_ring = adapter->tx_ring;
1698 int err = -ENOMEM, size;
1700 size = sizeof(struct e1000_buffer) * tx_ring->count;
1701 tx_ring->buffer_info = vmalloc(size);
1702 if (!tx_ring->buffer_info)
1704 memset(tx_ring->buffer_info, 0, size);
1706 /* round up to nearest 4K */
1707 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1708 tx_ring->size = ALIGN(tx_ring->size, 4096);
1710 err = e1000_alloc_ring_dma(adapter, tx_ring);
1714 tx_ring->next_to_use = 0;
1715 tx_ring->next_to_clean = 0;
1719 vfree(tx_ring->buffer_info);
1720 e_err("Unable to allocate memory for the transmit descriptor ring\n");
1725 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1726 * @adapter: board private structure
1728 * Returns 0 on success, negative on failure
1730 int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
1732 struct e1000_ring *rx_ring = adapter->rx_ring;
1733 struct e1000_buffer *buffer_info;
1734 int i, size, desc_len, err = -ENOMEM;
1736 size = sizeof(struct e1000_buffer) * rx_ring->count;
1737 rx_ring->buffer_info = vmalloc(size);
1738 if (!rx_ring->buffer_info)
1740 memset(rx_ring->buffer_info, 0, size);
1742 for (i = 0; i < rx_ring->count; i++) {
1743 buffer_info = &rx_ring->buffer_info[i];
1744 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
1745 sizeof(struct e1000_ps_page),
1747 if (!buffer_info->ps_pages)
1751 desc_len = sizeof(union e1000_rx_desc_packet_split);
1753 /* Round up to nearest 4K */
1754 rx_ring->size = rx_ring->count * desc_len;
1755 rx_ring->size = ALIGN(rx_ring->size, 4096);
1757 err = e1000_alloc_ring_dma(adapter, rx_ring);
1761 rx_ring->next_to_clean = 0;
1762 rx_ring->next_to_use = 0;
1763 rx_ring->rx_skb_top = NULL;
1768 for (i = 0; i < rx_ring->count; i++) {
1769 buffer_info = &rx_ring->buffer_info[i];
1770 kfree(buffer_info->ps_pages);
1773 vfree(rx_ring->buffer_info);
1774 e_err("Unable to allocate memory for the transmit descriptor ring\n");
1779 * e1000_clean_tx_ring - Free Tx Buffers
1780 * @adapter: board private structure
1782 static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
1784 struct e1000_ring *tx_ring = adapter->tx_ring;
1785 struct e1000_buffer *buffer_info;
1789 for (i = 0; i < tx_ring->count; i++) {
1790 buffer_info = &tx_ring->buffer_info[i];
1791 e1000_put_txbuf(adapter, buffer_info);
1794 size = sizeof(struct e1000_buffer) * tx_ring->count;
1795 memset(tx_ring->buffer_info, 0, size);
1797 memset(tx_ring->desc, 0, tx_ring->size);
1799 tx_ring->next_to_use = 0;
1800 tx_ring->next_to_clean = 0;
1802 writel(0, adapter->hw.hw_addr + tx_ring->head);
1803 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1807 * e1000e_free_tx_resources - Free Tx Resources per Queue
1808 * @adapter: board private structure
1810 * Free all transmit software resources
1812 void e1000e_free_tx_resources(struct e1000_adapter *adapter)
1814 struct pci_dev *pdev = adapter->pdev;
1815 struct e1000_ring *tx_ring = adapter->tx_ring;
1817 e1000_clean_tx_ring(adapter);
1819 vfree(tx_ring->buffer_info);
1820 tx_ring->buffer_info = NULL;
1822 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1824 tx_ring->desc = NULL;
1828 * e1000e_free_rx_resources - Free Rx Resources
1829 * @adapter: board private structure
1831 * Free all receive software resources
1834 void e1000e_free_rx_resources(struct e1000_adapter *adapter)
1836 struct pci_dev *pdev = adapter->pdev;
1837 struct e1000_ring *rx_ring = adapter->rx_ring;
1840 e1000_clean_rx_ring(adapter);
1842 for (i = 0; i < rx_ring->count; i++) {
1843 kfree(rx_ring->buffer_info[i].ps_pages);
1846 vfree(rx_ring->buffer_info);
1847 rx_ring->buffer_info = NULL;
1849 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1851 rx_ring->desc = NULL;
1855 * e1000_update_itr - update the dynamic ITR value based on statistics
1856 * @adapter: pointer to adapter
1857 * @itr_setting: current adapter->itr
1858 * @packets: the number of packets during this measurement interval
1859 * @bytes: the number of bytes during this measurement interval
1861 * Stores a new ITR value based on packets and byte
1862 * counts during the last interrupt. The advantage of per interrupt
1863 * computation is faster updates and more accurate ITR for the current
1864 * traffic pattern. Constants in this function were computed
1865 * based on theoretical maximum wire speed and thresholds were set based
1866 * on testing data as well as attempting to minimize response time
1867 * while increasing bulk throughput. This functionality is controlled
1868 * by the InterruptThrottleRate module parameter.
1870 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
1871 u16 itr_setting, int packets,
1874 unsigned int retval = itr_setting;
1877 goto update_itr_done;
1879 switch (itr_setting) {
1880 case lowest_latency:
1881 /* handle TSO and jumbo frames */
1882 if (bytes/packets > 8000)
1883 retval = bulk_latency;
1884 else if ((packets < 5) && (bytes > 512)) {
1885 retval = low_latency;
1888 case low_latency: /* 50 usec aka 20000 ints/s */
1889 if (bytes > 10000) {
1890 /* this if handles the TSO accounting */
1891 if (bytes/packets > 8000) {
1892 retval = bulk_latency;
1893 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
1894 retval = bulk_latency;
1895 } else if ((packets > 35)) {
1896 retval = lowest_latency;
1898 } else if (bytes/packets > 2000) {
1899 retval = bulk_latency;
1900 } else if (packets <= 2 && bytes < 512) {
1901 retval = lowest_latency;
1904 case bulk_latency: /* 250 usec aka 4000 ints/s */
1905 if (bytes > 25000) {
1907 retval = low_latency;
1909 } else if (bytes < 6000) {
1910 retval = low_latency;
1919 static void e1000_set_itr(struct e1000_adapter *adapter)
1921 struct e1000_hw *hw = &adapter->hw;
1923 u32 new_itr = adapter->itr;
1925 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1926 if (adapter->link_speed != SPEED_1000) {
1932 adapter->tx_itr = e1000_update_itr(adapter,
1934 adapter->total_tx_packets,
1935 adapter->total_tx_bytes);
1936 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1937 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
1938 adapter->tx_itr = low_latency;
1940 adapter->rx_itr = e1000_update_itr(adapter,
1942 adapter->total_rx_packets,
1943 adapter->total_rx_bytes);
1944 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1945 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
1946 adapter->rx_itr = low_latency;
1948 current_itr = max(adapter->rx_itr, adapter->tx_itr);
1950 switch (current_itr) {
1951 /* counts and packets in update_itr are dependent on these numbers */
1952 case lowest_latency:
1956 new_itr = 20000; /* aka hwitr = ~200 */
1966 if (new_itr != adapter->itr) {
1968 * this attempts to bias the interrupt rate towards Bulk
1969 * by adding intermediate steps when interrupt rate is
1972 new_itr = new_itr > adapter->itr ?
1973 min(adapter->itr + (new_itr >> 2), new_itr) :
1975 adapter->itr = new_itr;
1976 adapter->rx_ring->itr_val = new_itr;
1977 if (adapter->msix_entries)
1978 adapter->rx_ring->set_itr = 1;
1980 ew32(ITR, 1000000000 / (new_itr * 256));
1985 * e1000_alloc_queues - Allocate memory for all rings
1986 * @adapter: board private structure to initialize
1988 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1990 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1991 if (!adapter->tx_ring)
1994 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1995 if (!adapter->rx_ring)
2000 e_err("Unable to allocate memory for queues\n");
2001 kfree(adapter->rx_ring);
2002 kfree(adapter->tx_ring);
2007 * e1000_clean - NAPI Rx polling callback
2008 * @napi: struct associated with this polling callback
2009 * @budget: amount of packets driver is allowed to process this poll
2011 static int e1000_clean(struct napi_struct *napi, int budget)
2013 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
2014 struct e1000_hw *hw = &adapter->hw;
2015 struct net_device *poll_dev = adapter->netdev;
2016 int tx_cleaned = 1, work_done = 0;
2018 adapter = netdev_priv(poll_dev);
2020 if (adapter->msix_entries &&
2021 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2024 tx_cleaned = e1000_clean_tx_irq(adapter);
2027 adapter->clean_rx(adapter, &work_done, budget);
2032 /* If budget not fully consumed, exit the polling mode */
2033 if (work_done < budget) {
2034 if (adapter->itr_setting & 3)
2035 e1000_set_itr(adapter);
2036 napi_complete(napi);
2037 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2038 if (adapter->msix_entries)
2039 ew32(IMS, adapter->rx_ring->ims_val);
2041 e1000_irq_enable(adapter);
2048 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2050 struct e1000_adapter *adapter = netdev_priv(netdev);
2051 struct e1000_hw *hw = &adapter->hw;
2054 /* don't update vlan cookie if already programmed */
2055 if ((adapter->hw.mng_cookie.status &
2056 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2057 (vid == adapter->mng_vlan_id))
2060 /* add VID to filter table */
2061 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2062 index = (vid >> 5) & 0x7F;
2063 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2064 vfta |= (1 << (vid & 0x1F));
2065 hw->mac.ops.write_vfta(hw, index, vfta);
2069 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2071 struct e1000_adapter *adapter = netdev_priv(netdev);
2072 struct e1000_hw *hw = &adapter->hw;
2075 if (!test_bit(__E1000_DOWN, &adapter->state))
2076 e1000_irq_disable(adapter);
2077 vlan_group_set_device(adapter->vlgrp, vid, NULL);
2079 if (!test_bit(__E1000_DOWN, &adapter->state))
2080 e1000_irq_enable(adapter);
2082 if ((adapter->hw.mng_cookie.status &
2083 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2084 (vid == adapter->mng_vlan_id)) {
2085 /* release control to f/w */
2086 e1000_release_hw_control(adapter);
2090 /* remove VID from filter table */
2091 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2092 index = (vid >> 5) & 0x7F;
2093 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2094 vfta &= ~(1 << (vid & 0x1F));
2095 hw->mac.ops.write_vfta(hw, index, vfta);
2099 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2101 struct net_device *netdev = adapter->netdev;
2102 u16 vid = adapter->hw.mng_cookie.vlan_id;
2103 u16 old_vid = adapter->mng_vlan_id;
2105 if (!adapter->vlgrp)
2108 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2109 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2110 if (adapter->hw.mng_cookie.status &
2111 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2112 e1000_vlan_rx_add_vid(netdev, vid);
2113 adapter->mng_vlan_id = vid;
2116 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2118 !vlan_group_get_device(adapter->vlgrp, old_vid))
2119 e1000_vlan_rx_kill_vid(netdev, old_vid);
2121 adapter->mng_vlan_id = vid;
2126 static void e1000_vlan_rx_register(struct net_device *netdev,
2127 struct vlan_group *grp)
2129 struct e1000_adapter *adapter = netdev_priv(netdev);
2130 struct e1000_hw *hw = &adapter->hw;
2133 if (!test_bit(__E1000_DOWN, &adapter->state))
2134 e1000_irq_disable(adapter);
2135 adapter->vlgrp = grp;
2138 /* enable VLAN tag insert/strip */
2140 ctrl |= E1000_CTRL_VME;
2143 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2144 /* enable VLAN receive filtering */
2146 rctl &= ~E1000_RCTL_CFIEN;
2148 e1000_update_mng_vlan(adapter);
2151 /* disable VLAN tag insert/strip */
2153 ctrl &= ~E1000_CTRL_VME;
2156 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2157 if (adapter->mng_vlan_id !=
2158 (u16)E1000_MNG_VLAN_NONE) {
2159 e1000_vlan_rx_kill_vid(netdev,
2160 adapter->mng_vlan_id);
2161 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2166 if (!test_bit(__E1000_DOWN, &adapter->state))
2167 e1000_irq_enable(adapter);
2170 static void e1000_restore_vlan(struct e1000_adapter *adapter)
2174 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2176 if (!adapter->vlgrp)
2179 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2180 if (!vlan_group_get_device(adapter->vlgrp, vid))
2182 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2186 static void e1000_init_manageability(struct e1000_adapter *adapter)
2188 struct e1000_hw *hw = &adapter->hw;
2191 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2197 * enable receiving management packets to the host. this will probably
2198 * generate destination unreachable messages from the host OS, but
2199 * the packets will be handled on SMBUS
2201 manc |= E1000_MANC_EN_MNG2HOST;
2202 manc2h = er32(MANC2H);
2203 #define E1000_MNG2HOST_PORT_623 (1 << 5)
2204 #define E1000_MNG2HOST_PORT_664 (1 << 6)
2205 manc2h |= E1000_MNG2HOST_PORT_623;
2206 manc2h |= E1000_MNG2HOST_PORT_664;
2207 ew32(MANC2H, manc2h);
2212 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2213 * @adapter: board private structure
2215 * Configure the Tx unit of the MAC after a reset.
2217 static void e1000_configure_tx(struct e1000_adapter *adapter)
2219 struct e1000_hw *hw = &adapter->hw;
2220 struct e1000_ring *tx_ring = adapter->tx_ring;
2222 u32 tdlen, tctl, tipg, tarc;
2225 /* Setup the HW Tx Head and Tail descriptor pointers */
2226 tdba = tx_ring->dma;
2227 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2228 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
2229 ew32(TDBAH, (tdba >> 32));
2233 tx_ring->head = E1000_TDH;
2234 tx_ring->tail = E1000_TDT;
2236 /* Set the default values for the Tx Inter Packet Gap timer */
2237 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2238 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2239 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2241 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2242 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2244 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2245 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2248 /* Set the Tx Interrupt Delay register */
2249 ew32(TIDV, adapter->tx_int_delay);
2250 /* Tx irq moderation */
2251 ew32(TADV, adapter->tx_abs_int_delay);
2253 /* Program the Transmit Control Register */
2255 tctl &= ~E1000_TCTL_CT;
2256 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2257 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2259 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
2260 tarc = er32(TARC(0));
2262 * set the speed mode bit, we'll clear it if we're not at
2263 * gigabit link later
2265 #define SPEED_MODE_BIT (1 << 21)
2266 tarc |= SPEED_MODE_BIT;
2267 ew32(TARC(0), tarc);
2270 /* errata: program both queues to unweighted RR */
2271 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
2272 tarc = er32(TARC(0));
2274 ew32(TARC(0), tarc);
2275 tarc = er32(TARC(1));
2277 ew32(TARC(1), tarc);
2280 /* Setup Transmit Descriptor Settings for eop descriptor */
2281 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2283 /* only set IDE if we are delaying interrupts using the timers */
2284 if (adapter->tx_int_delay)
2285 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2287 /* enable Report Status bit */
2288 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2292 e1000e_config_collision_dist(hw);
2296 * e1000_setup_rctl - configure the receive control registers
2297 * @adapter: Board private structure
2299 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2300 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2301 static void e1000_setup_rctl(struct e1000_adapter *adapter)
2303 struct e1000_hw *hw = &adapter->hw;
2308 /* Program MC offset vector base */
2310 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2311 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2312 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2313 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2315 /* Do not Store bad packets */
2316 rctl &= ~E1000_RCTL_SBP;
2318 /* Enable Long Packet receive */
2319 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2320 rctl &= ~E1000_RCTL_LPE;
2322 rctl |= E1000_RCTL_LPE;
2324 /* Some systems expect that the CRC is included in SMBUS traffic. The
2325 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2326 * host memory when this is enabled
2328 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2329 rctl |= E1000_RCTL_SECRC;
2331 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2332 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2335 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2337 phy_data |= (1 << 2);
2338 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2340 e1e_rphy(hw, 22, &phy_data);
2342 phy_data |= (1 << 14);
2343 e1e_wphy(hw, 0x10, 0x2823);
2344 e1e_wphy(hw, 0x11, 0x0003);
2345 e1e_wphy(hw, 22, phy_data);
2348 /* Setup buffer sizes */
2349 rctl &= ~E1000_RCTL_SZ_4096;
2350 rctl |= E1000_RCTL_BSEX;
2351 switch (adapter->rx_buffer_len) {
2354 rctl |= E1000_RCTL_SZ_2048;
2355 rctl &= ~E1000_RCTL_BSEX;
2358 rctl |= E1000_RCTL_SZ_4096;
2361 rctl |= E1000_RCTL_SZ_8192;
2364 rctl |= E1000_RCTL_SZ_16384;
2369 * 82571 and greater support packet-split where the protocol
2370 * header is placed in skb->data and the packet data is
2371 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2372 * In the case of a non-split, skb->data is linearly filled,
2373 * followed by the page buffers. Therefore, skb->data is
2374 * sized to hold the largest protocol header.
2376 * allocations using alloc_page take too long for regular MTU
2377 * so only enable packet split for jumbo frames
2379 * Using pages when the page size is greater than 16k wastes
2380 * a lot of memory, since we allocate 3 pages at all times
2383 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2384 if (!(adapter->flags & FLAG_IS_ICH) && (pages <= 3) &&
2385 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
2386 adapter->rx_ps_pages = pages;
2388 adapter->rx_ps_pages = 0;
2390 if (adapter->rx_ps_pages) {
2391 /* Configure extra packet-split registers */
2392 rfctl = er32(RFCTL);
2393 rfctl |= E1000_RFCTL_EXTEN;
2395 * disable packet split support for IPv6 extension headers,
2396 * because some malformed IPv6 headers can hang the Rx
2398 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2399 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2403 /* Enable Packet split descriptors */
2404 rctl |= E1000_RCTL_DTYP_PS;
2406 psrctl |= adapter->rx_ps_bsize0 >>
2407 E1000_PSRCTL_BSIZE0_SHIFT;
2409 switch (adapter->rx_ps_pages) {
2411 psrctl |= PAGE_SIZE <<
2412 E1000_PSRCTL_BSIZE3_SHIFT;
2414 psrctl |= PAGE_SIZE <<
2415 E1000_PSRCTL_BSIZE2_SHIFT;
2417 psrctl |= PAGE_SIZE >>
2418 E1000_PSRCTL_BSIZE1_SHIFT;
2422 ew32(PSRCTL, psrctl);
2426 /* just started the receive unit, no need to restart */
2427 adapter->flags &= ~FLAG_RX_RESTART_NOW;
2431 * e1000_configure_rx - Configure Receive Unit after Reset
2432 * @adapter: board private structure
2434 * Configure the Rx unit of the MAC after a reset.
2436 static void e1000_configure_rx(struct e1000_adapter *adapter)
2438 struct e1000_hw *hw = &adapter->hw;
2439 struct e1000_ring *rx_ring = adapter->rx_ring;
2441 u32 rdlen, rctl, rxcsum, ctrl_ext;
2443 if (adapter->rx_ps_pages) {
2444 /* this is a 32 byte descriptor */
2445 rdlen = rx_ring->count *
2446 sizeof(union e1000_rx_desc_packet_split);
2447 adapter->clean_rx = e1000_clean_rx_irq_ps;
2448 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2449 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2450 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2451 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2452 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
2454 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2455 adapter->clean_rx = e1000_clean_rx_irq;
2456 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2459 /* disable receives while setting up the descriptors */
2461 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2465 /* set the Receive Delay Timer Register */
2466 ew32(RDTR, adapter->rx_int_delay);
2468 /* irq moderation */
2469 ew32(RADV, adapter->rx_abs_int_delay);
2470 if (adapter->itr_setting != 0)
2471 ew32(ITR, 1000000000 / (adapter->itr * 256));
2473 ctrl_ext = er32(CTRL_EXT);
2474 /* Auto-Mask interrupts upon ICR access */
2475 ctrl_ext |= E1000_CTRL_EXT_IAME;
2476 ew32(IAM, 0xffffffff);
2477 ew32(CTRL_EXT, ctrl_ext);
2481 * Setup the HW Rx Head and Tail Descriptor Pointers and
2482 * the Base and Length of the Rx Descriptor Ring
2484 rdba = rx_ring->dma;
2485 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
2486 ew32(RDBAH, (rdba >> 32));
2490 rx_ring->head = E1000_RDH;
2491 rx_ring->tail = E1000_RDT;
2493 /* Enable Receive Checksum Offload for TCP and UDP */
2494 rxcsum = er32(RXCSUM);
2495 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2496 rxcsum |= E1000_RXCSUM_TUOFL;
2499 * IPv4 payload checksum for UDP fragments must be
2500 * used in conjunction with packet-split.
2502 if (adapter->rx_ps_pages)
2503 rxcsum |= E1000_RXCSUM_IPPCSE;
2505 rxcsum &= ~E1000_RXCSUM_TUOFL;
2506 /* no need to clear IPPCSE as it defaults to 0 */
2508 ew32(RXCSUM, rxcsum);
2511 * Enable early receives on supported devices, only takes effect when
2512 * packet size is equal or larger than the specified value (in 8 byte
2513 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2515 if (adapter->flags & FLAG_HAS_ERT) {
2516 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2517 u32 rxdctl = er32(RXDCTL(0));
2518 ew32(RXDCTL(0), rxdctl | 0x3);
2519 ew32(ERT, E1000_ERT_2048 | (1 << 13));
2521 * With jumbo frames and early-receive enabled,
2522 * excessive C-state transition latencies result in
2523 * dropped transactions.
2525 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2526 adapter->netdev->name, 55);
2528 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2529 adapter->netdev->name,
2530 PM_QOS_DEFAULT_VALUE);
2534 /* Enable Receives */
2539 * e1000_update_mc_addr_list - Update Multicast addresses
2540 * @hw: pointer to the HW structure
2541 * @mc_addr_list: array of multicast addresses to program
2542 * @mc_addr_count: number of multicast addresses to program
2544 * Updates the Multicast Table Array.
2545 * The caller must have a packed mc_addr_list of multicast addresses.
2547 static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
2550 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
2554 * e1000_set_multi - Multicast and Promiscuous mode set
2555 * @netdev: network interface device structure
2557 * The set_multi entry point is called whenever the multicast address
2558 * list or the network interface flags are updated. This routine is
2559 * responsible for configuring the hardware for proper multicast,
2560 * promiscuous mode, and all-multi behavior.
2562 static void e1000_set_multi(struct net_device *netdev)
2564 struct e1000_adapter *adapter = netdev_priv(netdev);
2565 struct e1000_hw *hw = &adapter->hw;
2566 struct dev_mc_list *mc_ptr;
2571 /* Check for Promiscuous and All Multicast modes */
2575 if (netdev->flags & IFF_PROMISC) {
2576 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2577 rctl &= ~E1000_RCTL_VFE;
2579 if (netdev->flags & IFF_ALLMULTI) {
2580 rctl |= E1000_RCTL_MPE;
2581 rctl &= ~E1000_RCTL_UPE;
2583 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2585 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
2586 rctl |= E1000_RCTL_VFE;
2591 if (!netdev_mc_empty(netdev)) {
2592 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
2596 /* prepare a packed array of only addresses. */
2598 netdev_for_each_mc_addr(mc_ptr, netdev)
2599 memcpy(mta_list + (i++ * ETH_ALEN),
2600 mc_ptr->dmi_addr, ETH_ALEN);
2602 e1000_update_mc_addr_list(hw, mta_list, i);
2606 * if we're called from probe, we might not have
2607 * anything to do here, so clear out the list
2609 e1000_update_mc_addr_list(hw, NULL, 0);
2614 * e1000_configure - configure the hardware for Rx and Tx
2615 * @adapter: private board structure
2617 static void e1000_configure(struct e1000_adapter *adapter)
2619 e1000_set_multi(adapter->netdev);
2621 e1000_restore_vlan(adapter);
2622 e1000_init_manageability(adapter);
2624 e1000_configure_tx(adapter);
2625 e1000_setup_rctl(adapter);
2626 e1000_configure_rx(adapter);
2627 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
2631 * e1000e_power_up_phy - restore link in case the phy was powered down
2632 * @adapter: address of board private structure
2634 * The phy may be powered down to save power and turn off link when the
2635 * driver is unloaded and wake on lan is not enabled (among others)
2636 * *** this routine MUST be followed by a call to e1000e_reset ***
2638 void e1000e_power_up_phy(struct e1000_adapter *adapter)
2640 if (adapter->hw.phy.ops.power_up)
2641 adapter->hw.phy.ops.power_up(&adapter->hw);
2643 adapter->hw.mac.ops.setup_link(&adapter->hw);
2647 * e1000_power_down_phy - Power down the PHY
2649 * Power down the PHY so no link is implied when interface is down.
2650 * The PHY cannot be powered down if management or WoL is active.
2652 static void e1000_power_down_phy(struct e1000_adapter *adapter)
2654 /* WoL is enabled */
2658 if (adapter->hw.phy.ops.power_down)
2659 adapter->hw.phy.ops.power_down(&adapter->hw);
2663 * e1000e_reset - bring the hardware into a known good state
2665 * This function boots the hardware and enables some settings that
2666 * require a configuration cycle of the hardware - those cannot be
2667 * set/changed during runtime. After reset the device needs to be
2668 * properly configured for Rx, Tx etc.
2670 void e1000e_reset(struct e1000_adapter *adapter)
2672 struct e1000_mac_info *mac = &adapter->hw.mac;
2673 struct e1000_fc_info *fc = &adapter->hw.fc;
2674 struct e1000_hw *hw = &adapter->hw;
2675 u32 tx_space, min_tx_space, min_rx_space;
2676 u32 pba = adapter->pba;
2679 /* reset Packet Buffer Allocation to default */
2682 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
2684 * To maintain wire speed transmits, the Tx FIFO should be
2685 * large enough to accommodate two full transmit packets,
2686 * rounded up to the next 1KB and expressed in KB. Likewise,
2687 * the Rx FIFO should be large enough to accommodate at least
2688 * one full receive packet and is similarly rounded up and
2692 /* upper 16 bits has Tx packet buffer allocation size in KB */
2693 tx_space = pba >> 16;
2694 /* lower 16 bits has Rx packet buffer allocation size in KB */
2697 * the Tx fifo also stores 16 bytes of information about the tx
2698 * but don't include ethernet FCS because hardware appends it
2700 min_tx_space = (adapter->max_frame_size +
2701 sizeof(struct e1000_tx_desc) -
2703 min_tx_space = ALIGN(min_tx_space, 1024);
2704 min_tx_space >>= 10;
2705 /* software strips receive CRC, so leave room for it */
2706 min_rx_space = adapter->max_frame_size;
2707 min_rx_space = ALIGN(min_rx_space, 1024);
2708 min_rx_space >>= 10;
2711 * If current Tx allocation is less than the min Tx FIFO size,
2712 * and the min Tx FIFO size is less than the current Rx FIFO
2713 * allocation, take space away from current Rx allocation
2715 if ((tx_space < min_tx_space) &&
2716 ((min_tx_space - tx_space) < pba)) {
2717 pba -= min_tx_space - tx_space;
2720 * if short on Rx space, Rx wins and must trump tx
2721 * adjustment or use Early Receive if available
2723 if ((pba < min_rx_space) &&
2724 (!(adapter->flags & FLAG_HAS_ERT)))
2725 /* ERT enabled in e1000_configure_rx */
2734 * flow control settings
2736 * The high water mark must be low enough to fit one full frame
2737 * (or the size used for early receive) above it in the Rx FIFO.
2738 * Set it to the lower of:
2739 * - 90% of the Rx FIFO size, and
2740 * - the full Rx FIFO size minus the early receive size (for parts
2741 * with ERT support assuming ERT set to E1000_ERT_2048), or
2742 * - the full Rx FIFO size minus one full frame
2744 if (hw->mac.type == e1000_pchlan) {
2746 * Workaround PCH LOM adapter hangs with certain network
2747 * loads. If hangs persist, try disabling Tx flow control.
2749 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2750 fc->high_water = 0x3500;
2751 fc->low_water = 0x1500;
2753 fc->high_water = 0x5000;
2754 fc->low_water = 0x3000;
2757 if ((adapter->flags & FLAG_HAS_ERT) &&
2758 (adapter->netdev->mtu > ETH_DATA_LEN))
2759 hwm = min(((pba << 10) * 9 / 10),
2760 ((pba << 10) - (E1000_ERT_2048 << 3)));
2762 hwm = min(((pba << 10) * 9 / 10),
2763 ((pba << 10) - adapter->max_frame_size));
2765 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
2766 fc->low_water = fc->high_water - 8;
2769 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
2770 fc->pause_time = 0xFFFF;
2772 fc->pause_time = E1000_FC_PAUSE_TIME;
2774 fc->current_mode = fc->requested_mode;
2776 /* Allow time for pending master requests to run */
2777 mac->ops.reset_hw(hw);
2780 * For parts with AMT enabled, let the firmware know
2781 * that the network interface is in control
2783 if (adapter->flags & FLAG_HAS_AMT)
2784 e1000_get_hw_control(adapter);
2787 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)
2788 e1e_wphy(&adapter->hw, BM_WUC, 0);
2790 if (mac->ops.init_hw(hw))
2791 e_err("Hardware Error\n");
2793 /* additional part of the flow-control workaround above */
2794 if (hw->mac.type == e1000_pchlan)
2795 ew32(FCRTV_PCH, 0x1000);
2797 e1000_update_mng_vlan(adapter);
2799 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2800 ew32(VET, ETH_P_8021Q);
2802 e1000e_reset_adaptive(hw);
2803 e1000_get_phy_info(hw);
2805 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
2806 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
2809 * speed up time to link by disabling smart power down, ignore
2810 * the return value of this function because there is nothing
2811 * different we would do if it failed
2813 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
2814 phy_data &= ~IGP02E1000_PM_SPD;
2815 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
2819 int e1000e_up(struct e1000_adapter *adapter)
2821 struct e1000_hw *hw = &adapter->hw;
2823 /* DMA latency requirement to workaround early-receive/jumbo issue */
2824 if (adapter->flags & FLAG_HAS_ERT)
2825 pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY,
2826 adapter->netdev->name,
2827 PM_QOS_DEFAULT_VALUE);
2829 /* hardware has been reset, we need to reload some things */
2830 e1000_configure(adapter);
2832 clear_bit(__E1000_DOWN, &adapter->state);
2834 napi_enable(&adapter->napi);
2835 if (adapter->msix_entries)
2836 e1000_configure_msix(adapter);
2837 e1000_irq_enable(adapter);
2839 netif_wake_queue(adapter->netdev);
2841 /* fire a link change interrupt to start the watchdog */
2842 ew32(ICS, E1000_ICS_LSC);
2846 void e1000e_down(struct e1000_adapter *adapter)
2848 struct net_device *netdev = adapter->netdev;
2849 struct e1000_hw *hw = &adapter->hw;
2853 * signal that we're down so the interrupt handler does not
2854 * reschedule our watchdog timer
2856 set_bit(__E1000_DOWN, &adapter->state);
2858 /* disable receives in the hardware */
2860 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2861 /* flush and sleep below */
2863 netif_stop_queue(netdev);
2865 /* disable transmits in the hardware */
2867 tctl &= ~E1000_TCTL_EN;
2869 /* flush both disables and wait for them to finish */
2873 napi_disable(&adapter->napi);
2874 e1000_irq_disable(adapter);
2876 del_timer_sync(&adapter->watchdog_timer);
2877 del_timer_sync(&adapter->phy_info_timer);
2879 netif_carrier_off(netdev);
2880 adapter->link_speed = 0;
2881 adapter->link_duplex = 0;
2883 if (!pci_channel_offline(adapter->pdev))
2884 e1000e_reset(adapter);
2885 e1000_clean_tx_ring(adapter);
2886 e1000_clean_rx_ring(adapter);
2888 if (adapter->flags & FLAG_HAS_ERT)
2889 pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY,
2890 adapter->netdev->name);
2893 * TODO: for power management, we could drop the link and
2894 * pci_disable_device here.
2898 void e1000e_reinit_locked(struct e1000_adapter *adapter)
2901 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
2903 e1000e_down(adapter);
2905 clear_bit(__E1000_RESETTING, &adapter->state);
2909 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2910 * @adapter: board private structure to initialize
2912 * e1000_sw_init initializes the Adapter private data structure.
2913 * Fields are initialized based on PCI device information and
2914 * OS network device settings (MTU size).
2916 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
2918 struct net_device *netdev = adapter->netdev;
2920 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
2921 adapter->rx_ps_bsize0 = 128;
2922 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2923 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
2925 e1000e_set_interrupt_capability(adapter);
2927 if (e1000_alloc_queues(adapter))
2930 /* Explicitly disable IRQ since the NIC can be in any state. */
2931 e1000_irq_disable(adapter);
2933 set_bit(__E1000_DOWN, &adapter->state);
2938 * e1000_intr_msi_test - Interrupt Handler
2939 * @irq: interrupt number
2940 * @data: pointer to a network interface device structure
2942 static irqreturn_t e1000_intr_msi_test(int irq, void *data)
2944 struct net_device *netdev = data;
2945 struct e1000_adapter *adapter = netdev_priv(netdev);
2946 struct e1000_hw *hw = &adapter->hw;
2947 u32 icr = er32(ICR);
2949 e_dbg("icr is %08X\n", icr);
2950 if (icr & E1000_ICR_RXSEQ) {
2951 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
2959 * e1000_test_msi_interrupt - Returns 0 for successful test
2960 * @adapter: board private struct
2962 * code flow taken from tg3.c
2964 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
2966 struct net_device *netdev = adapter->netdev;
2967 struct e1000_hw *hw = &adapter->hw;
2970 /* poll_enable hasn't been called yet, so don't need disable */
2971 /* clear any pending events */
2974 /* free the real vector and request a test handler */
2975 e1000_free_irq(adapter);
2976 e1000e_reset_interrupt_capability(adapter);
2978 /* Assume that the test fails, if it succeeds then the test
2979 * MSI irq handler will unset this flag */
2980 adapter->flags |= FLAG_MSI_TEST_FAILED;
2982 err = pci_enable_msi(adapter->pdev);
2984 goto msi_test_failed;
2986 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
2987 netdev->name, netdev);
2989 pci_disable_msi(adapter->pdev);
2990 goto msi_test_failed;
2995 e1000_irq_enable(adapter);
2997 /* fire an unusual interrupt on the test handler */
2998 ew32(ICS, E1000_ICS_RXSEQ);
3002 e1000_irq_disable(adapter);
3006 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
3007 adapter->int_mode = E1000E_INT_MODE_LEGACY;
3009 e_info("MSI interrupt test failed!\n");
3012 free_irq(adapter->pdev->irq, netdev);
3013 pci_disable_msi(adapter->pdev);
3016 goto msi_test_failed;
3018 /* okay so the test worked, restore settings */
3019 e_dbg("MSI interrupt test succeeded!\n");
3021 e1000e_set_interrupt_capability(adapter);
3022 e1000_request_irq(adapter);
3027 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3028 * @adapter: board private struct
3030 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3032 static int e1000_test_msi(struct e1000_adapter *adapter)
3037 if (!(adapter->flags & FLAG_MSI_ENABLED))
3040 /* disable SERR in case the MSI write causes a master abort */
3041 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3042 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3043 pci_cmd & ~PCI_COMMAND_SERR);
3045 err = e1000_test_msi_interrupt(adapter);
3047 /* restore previous setting of command word */
3048 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3054 /* EIO means MSI test failed */
3058 /* back to INTx mode */
3059 e_warn("MSI interrupt test failed, using legacy interrupt.\n");
3061 e1000_free_irq(adapter);
3063 err = e1000_request_irq(adapter);
3069 * e1000_open - Called when a network interface is made active
3070 * @netdev: network interface device structure
3072 * Returns 0 on success, negative value on failure
3074 * The open entry point is called when a network interface is made
3075 * active by the system (IFF_UP). At this point all resources needed
3076 * for transmit and receive operations are allocated, the interrupt
3077 * handler is registered with the OS, the watchdog timer is started,
3078 * and the stack is notified that the interface is ready.
3080 static int e1000_open(struct net_device *netdev)
3082 struct e1000_adapter *adapter = netdev_priv(netdev);
3083 struct e1000_hw *hw = &adapter->hw;
3086 /* disallow open during test */
3087 if (test_bit(__E1000_TESTING, &adapter->state))
3090 netif_carrier_off(netdev);
3092 /* allocate transmit descriptors */
3093 err = e1000e_setup_tx_resources(adapter);
3097 /* allocate receive descriptors */
3098 err = e1000e_setup_rx_resources(adapter);
3102 e1000e_power_up_phy(adapter);
3104 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3105 if ((adapter->hw.mng_cookie.status &
3106 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3107 e1000_update_mng_vlan(adapter);
3110 * If AMT is enabled, let the firmware know that the network
3111 * interface is now open
3113 if (adapter->flags & FLAG_HAS_AMT)
3114 e1000_get_hw_control(adapter);
3117 * before we allocate an interrupt, we must be ready to handle it.
3118 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3119 * as soon as we call pci_request_irq, so we have to setup our
3120 * clean_rx handler before we do so.
3122 e1000_configure(adapter);
3124 err = e1000_request_irq(adapter);
3129 * Work around PCIe errata with MSI interrupts causing some chipsets to
3130 * ignore e1000e MSI messages, which means we need to test our MSI
3133 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
3134 err = e1000_test_msi(adapter);
3136 e_err("Interrupt allocation failed\n");
3141 /* From here on the code is the same as e1000e_up() */
3142 clear_bit(__E1000_DOWN, &adapter->state);
3144 napi_enable(&adapter->napi);
3146 e1000_irq_enable(adapter);
3148 netif_start_queue(netdev);
3150 /* fire a link status change interrupt to start the watchdog */
3151 ew32(ICS, E1000_ICS_LSC);
3156 e1000_release_hw_control(adapter);
3157 e1000_power_down_phy(adapter);
3158 e1000e_free_rx_resources(adapter);
3160 e1000e_free_tx_resources(adapter);
3162 e1000e_reset(adapter);
3168 * e1000_close - Disables a network interface
3169 * @netdev: network interface device structure
3171 * Returns 0, this is not allowed to fail
3173 * The close entry point is called when an interface is de-activated
3174 * by the OS. The hardware is still under the drivers control, but
3175 * needs to be disabled. A global MAC reset is issued to stop the
3176 * hardware, and all transmit and receive resources are freed.
3178 static int e1000_close(struct net_device *netdev)
3180 struct e1000_adapter *adapter = netdev_priv(netdev);
3182 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3183 e1000e_down(adapter);
3184 e1000_power_down_phy(adapter);
3185 e1000_free_irq(adapter);
3187 e1000e_free_tx_resources(adapter);
3188 e1000e_free_rx_resources(adapter);
3191 * kill manageability vlan ID if supported, but not if a vlan with
3192 * the same ID is registered on the host OS (let 8021q kill it)
3194 if ((adapter->hw.mng_cookie.status &
3195 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3197 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3198 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3201 * If AMT is enabled, let the firmware know that the network
3202 * interface is now closed
3204 if (adapter->flags & FLAG_HAS_AMT)
3205 e1000_release_hw_control(adapter);
3210 * e1000_set_mac - Change the Ethernet Address of the NIC
3211 * @netdev: network interface device structure
3212 * @p: pointer to an address structure
3214 * Returns 0 on success, negative on failure
3216 static int e1000_set_mac(struct net_device *netdev, void *p)
3218 struct e1000_adapter *adapter = netdev_priv(netdev);
3219 struct sockaddr *addr = p;
3221 if (!is_valid_ether_addr(addr->sa_data))
3222 return -EADDRNOTAVAIL;
3224 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3225 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3227 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3229 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3230 /* activate the work around */
3231 e1000e_set_laa_state_82571(&adapter->hw, 1);
3234 * Hold a copy of the LAA in RAR[14] This is done so that
3235 * between the time RAR[0] gets clobbered and the time it
3236 * gets fixed (in e1000_watchdog), the actual LAA is in one
3237 * of the RARs and no incoming packets directed to this port
3238 * are dropped. Eventually the LAA will be in RAR[0] and
3241 e1000e_rar_set(&adapter->hw,
3242 adapter->hw.mac.addr,
3243 adapter->hw.mac.rar_entry_count - 1);
3250 * e1000e_update_phy_task - work thread to update phy
3251 * @work: pointer to our work struct
3253 * this worker thread exists because we must acquire a
3254 * semaphore to read the phy, which we could msleep while
3255 * waiting for it, and we can't msleep in a timer.
3257 static void e1000e_update_phy_task(struct work_struct *work)
3259 struct e1000_adapter *adapter = container_of(work,
3260 struct e1000_adapter, update_phy_task);
3261 e1000_get_phy_info(&adapter->hw);
3265 * Need to wait a few seconds after link up to get diagnostic information from
3268 static void e1000_update_phy_info(unsigned long data)
3270 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
3271 schedule_work(&adapter->update_phy_task);
3275 * e1000e_update_stats - Update the board statistics counters
3276 * @adapter: board private structure
3278 void e1000e_update_stats(struct e1000_adapter *adapter)
3280 struct net_device *netdev = adapter->netdev;
3281 struct e1000_hw *hw = &adapter->hw;
3282 struct pci_dev *pdev = adapter->pdev;
3286 * Prevent stats update while adapter is being reset, or if the pci
3287 * connection is down.
3289 if (adapter->link_speed == 0)
3291 if (pci_channel_offline(pdev))
3294 adapter->stats.crcerrs += er32(CRCERRS);
3295 adapter->stats.gprc += er32(GPRC);
3296 adapter->stats.gorc += er32(GORCL);
3297 er32(GORCH); /* Clear gorc */
3298 adapter->stats.bprc += er32(BPRC);
3299 adapter->stats.mprc += er32(MPRC);
3300 adapter->stats.roc += er32(ROC);
3302 adapter->stats.mpc += er32(MPC);
3303 if ((hw->phy.type == e1000_phy_82578) ||
3304 (hw->phy.type == e1000_phy_82577)) {
3305 e1e_rphy(hw, HV_SCC_UPPER, &phy_data);
3306 if (!e1e_rphy(hw, HV_SCC_LOWER, &phy_data))
3307 adapter->stats.scc += phy_data;
3309 e1e_rphy(hw, HV_ECOL_UPPER, &phy_data);
3310 if (!e1e_rphy(hw, HV_ECOL_LOWER, &phy_data))
3311 adapter->stats.ecol += phy_data;
3313 e1e_rphy(hw, HV_MCC_UPPER, &phy_data);
3314 if (!e1e_rphy(hw, HV_MCC_LOWER, &phy_data))
3315 adapter->stats.mcc += phy_data;
3317 e1e_rphy(hw, HV_LATECOL_UPPER, &phy_data);
3318 if (!e1e_rphy(hw, HV_LATECOL_LOWER, &phy_data))
3319 adapter->stats.latecol += phy_data;
3321 e1e_rphy(hw, HV_DC_UPPER, &phy_data);
3322 if (!e1e_rphy(hw, HV_DC_LOWER, &phy_data))
3323 adapter->stats.dc += phy_data;
3325 adapter->stats.scc += er32(SCC);
3326 adapter->stats.ecol += er32(ECOL);
3327 adapter->stats.mcc += er32(MCC);
3328 adapter->stats.latecol += er32(LATECOL);
3329 adapter->stats.dc += er32(DC);
3331 adapter->stats.xonrxc += er32(XONRXC);
3332 adapter->stats.xontxc += er32(XONTXC);
3333 adapter->stats.xoffrxc += er32(XOFFRXC);
3334 adapter->stats.xofftxc += er32(XOFFTXC);
3335 adapter->stats.gptc += er32(GPTC);
3336 adapter->stats.gotc += er32(GOTCL);
3337 er32(GOTCH); /* Clear gotc */
3338 adapter->stats.rnbc += er32(RNBC);
3339 adapter->stats.ruc += er32(RUC);
3341 adapter->stats.mptc += er32(MPTC);
3342 adapter->stats.bptc += er32(BPTC);
3344 /* used for adaptive IFS */
3346 hw->mac.tx_packet_delta = er32(TPT);
3347 adapter->stats.tpt += hw->mac.tx_packet_delta;
3348 if ((hw->phy.type == e1000_phy_82578) ||
3349 (hw->phy.type == e1000_phy_82577)) {
3350 e1e_rphy(hw, HV_COLC_UPPER, &phy_data);
3351 if (!e1e_rphy(hw, HV_COLC_LOWER, &phy_data))
3352 hw->mac.collision_delta = phy_data;
3354 hw->mac.collision_delta = er32(COLC);
3356 adapter->stats.colc += hw->mac.collision_delta;
3358 adapter->stats.algnerrc += er32(ALGNERRC);
3359 adapter->stats.rxerrc += er32(RXERRC);
3360 if ((hw->phy.type == e1000_phy_82578) ||
3361 (hw->phy.type == e1000_phy_82577)) {
3362 e1e_rphy(hw, HV_TNCRS_UPPER, &phy_data);
3363 if (!e1e_rphy(hw, HV_TNCRS_LOWER, &phy_data))
3364 adapter->stats.tncrs += phy_data;
3366 if ((hw->mac.type != e1000_82574) &&
3367 (hw->mac.type != e1000_82583))
3368 adapter->stats.tncrs += er32(TNCRS);
3370 adapter->stats.cexterr += er32(CEXTERR);
3371 adapter->stats.tsctc += er32(TSCTC);
3372 adapter->stats.tsctfc += er32(TSCTFC);
3374 /* Fill out the OS statistics structure */
3375 netdev->stats.multicast = adapter->stats.mprc;
3376 netdev->stats.collisions = adapter->stats.colc;
3381 * RLEC on some newer hardware can be incorrect so build
3382 * our own version based on RUC and ROC
3384 netdev->stats.rx_errors = adapter->stats.rxerrc +
3385 adapter->stats.crcerrs + adapter->stats.algnerrc +
3386 adapter->stats.ruc + adapter->stats.roc +
3387 adapter->stats.cexterr;
3388 netdev->stats.rx_length_errors = adapter->stats.ruc +
3390 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3391 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3392 netdev->stats.rx_missed_errors = adapter->stats.mpc;
3395 netdev->stats.tx_errors = adapter->stats.ecol +
3396 adapter->stats.latecol;
3397 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3398 netdev->stats.tx_window_errors = adapter->stats.latecol;
3399 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
3401 /* Tx Dropped needs to be maintained elsewhere */
3403 /* Management Stats */
3404 adapter->stats.mgptc += er32(MGTPTC);
3405 adapter->stats.mgprc += er32(MGTPRC);
3406 adapter->stats.mgpdc += er32(MGTPDC);
3410 * e1000_phy_read_status - Update the PHY register status snapshot
3411 * @adapter: board private structure
3413 static void e1000_phy_read_status(struct e1000_adapter *adapter)
3415 struct e1000_hw *hw = &adapter->hw;
3416 struct e1000_phy_regs *phy = &adapter->phy_regs;
3419 if ((er32(STATUS) & E1000_STATUS_LU) &&
3420 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
3421 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
3422 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
3423 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
3424 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
3425 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
3426 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
3427 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
3428 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
3430 e_warn("Error reading PHY register\n");
3433 * Do not read PHY registers if link is not up
3434 * Set values to typical power-on defaults
3436 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
3437 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
3438 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
3440 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
3441 ADVERTISE_ALL | ADVERTISE_CSMA);
3443 phy->expansion = EXPANSION_ENABLENPAGE;
3444 phy->ctrl1000 = ADVERTISE_1000FULL;
3446 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
3450 static void e1000_print_link_info(struct e1000_adapter *adapter)
3452 struct e1000_hw *hw = &adapter->hw;
3453 u32 ctrl = er32(CTRL);
3455 /* Link status message must follow this format for user tools */
3456 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
3457 "Flow Control: %s\n",
3458 adapter->netdev->name,
3459 adapter->link_speed,
3460 (adapter->link_duplex == FULL_DUPLEX) ?
3461 "Full Duplex" : "Half Duplex",
3462 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
3464 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
3465 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
3468 bool e1000e_has_link(struct e1000_adapter *adapter)
3470 struct e1000_hw *hw = &adapter->hw;
3471 bool link_active = 0;
3475 * get_link_status is set on LSC (link status) interrupt or
3476 * Rx sequence error interrupt. get_link_status will stay
3477 * false until the check_for_link establishes link
3478 * for copper adapters ONLY
3480 switch (hw->phy.media_type) {
3481 case e1000_media_type_copper:
3482 if (hw->mac.get_link_status) {
3483 ret_val = hw->mac.ops.check_for_link(hw);
3484 link_active = !hw->mac.get_link_status;
3489 case e1000_media_type_fiber:
3490 ret_val = hw->mac.ops.check_for_link(hw);
3491 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
3493 case e1000_media_type_internal_serdes:
3494 ret_val = hw->mac.ops.check_for_link(hw);
3495 link_active = adapter->hw.mac.serdes_has_link;
3498 case e1000_media_type_unknown:
3502 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
3503 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
3504 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
3505 e_info("Gigabit has been disabled, downgrading speed\n");
3511 static void e1000e_enable_receives(struct e1000_adapter *adapter)
3513 /* make sure the receive unit is started */
3514 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
3515 (adapter->flags & FLAG_RX_RESTART_NOW)) {
3516 struct e1000_hw *hw = &adapter->hw;
3517 u32 rctl = er32(RCTL);
3518 ew32(RCTL, rctl | E1000_RCTL_EN);
3519 adapter->flags &= ~FLAG_RX_RESTART_NOW;
3524 * e1000_watchdog - Timer Call-back
3525 * @data: pointer to adapter cast into an unsigned long
3527 static void e1000_watchdog(unsigned long data)
3529 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
3531 /* Do the rest outside of interrupt context */
3532 schedule_work(&adapter->watchdog_task);
3534 /* TODO: make this use queue_delayed_work() */
3537 static void e1000_watchdog_task(struct work_struct *work)
3539 struct e1000_adapter *adapter = container_of(work,
3540 struct e1000_adapter, watchdog_task);
3541 struct net_device *netdev = adapter->netdev;
3542 struct e1000_mac_info *mac = &adapter->hw.mac;
3543 struct e1000_phy_info *phy = &adapter->hw.phy;
3544 struct e1000_ring *tx_ring = adapter->tx_ring;
3545 struct e1000_hw *hw = &adapter->hw;
3549 link = e1000e_has_link(adapter);
3550 if ((netif_carrier_ok(netdev)) && link) {
3551 e1000e_enable_receives(adapter);
3555 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
3556 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
3557 e1000_update_mng_vlan(adapter);
3560 if (!netif_carrier_ok(netdev)) {
3562 /* update snapshot of PHY registers on LSC */
3563 e1000_phy_read_status(adapter);
3564 mac->ops.get_link_up_info(&adapter->hw,
3565 &adapter->link_speed,
3566 &adapter->link_duplex);
3567 e1000_print_link_info(adapter);
3569 * On supported PHYs, check for duplex mismatch only
3570 * if link has autonegotiated at 10/100 half
3572 if ((hw->phy.type == e1000_phy_igp_3 ||
3573 hw->phy.type == e1000_phy_bm) &&
3574 (hw->mac.autoneg == true) &&
3575 (adapter->link_speed == SPEED_10 ||
3576 adapter->link_speed == SPEED_100) &&
3577 (adapter->link_duplex == HALF_DUPLEX)) {
3580 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
3582 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
3583 e_info("Autonegotiated half duplex but"
3584 " link partner cannot autoneg. "
3585 " Try forcing full duplex if "
3586 "link gets many collisions.\n");
3589 /* adjust timeout factor according to speed/duplex */
3590 adapter->tx_timeout_factor = 1;
3591 switch (adapter->link_speed) {
3594 adapter->tx_timeout_factor = 16;
3598 adapter->tx_timeout_factor = 10;
3603 * workaround: re-program speed mode bit after
3606 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
3609 tarc0 = er32(TARC(0));
3610 tarc0 &= ~SPEED_MODE_BIT;
3611 ew32(TARC(0), tarc0);
3615 * disable TSO for pcie and 10/100 speeds, to avoid
3616 * some hardware issues
3618 if (!(adapter->flags & FLAG_TSO_FORCE)) {
3619 switch (adapter->link_speed) {
3622 e_info("10/100 speed: disabling TSO\n");
3623 netdev->features &= ~NETIF_F_TSO;
3624 netdev->features &= ~NETIF_F_TSO6;
3627 netdev->features |= NETIF_F_TSO;
3628 netdev->features |= NETIF_F_TSO6;
3637 * enable transmits in the hardware, need to do this
3638 * after setting TARC(0)
3641 tctl |= E1000_TCTL_EN;
3645 * Perform any post-link-up configuration before
3646 * reporting link up.
3648 if (phy->ops.cfg_on_link_up)
3649 phy->ops.cfg_on_link_up(hw);
3651 netif_carrier_on(netdev);
3653 if (!test_bit(__E1000_DOWN, &adapter->state))
3654 mod_timer(&adapter->phy_info_timer,
3655 round_jiffies(jiffies + 2 * HZ));
3658 if (netif_carrier_ok(netdev)) {
3659 adapter->link_speed = 0;
3660 adapter->link_duplex = 0;
3661 /* Link status message must follow this format */
3662 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
3663 adapter->netdev->name);
3664 netif_carrier_off(netdev);
3665 if (!test_bit(__E1000_DOWN, &adapter->state))
3666 mod_timer(&adapter->phy_info_timer,
3667 round_jiffies(jiffies + 2 * HZ));
3669 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3670 schedule_work(&adapter->reset_task);
3675 e1000e_update_stats(adapter);
3677 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
3678 adapter->tpt_old = adapter->stats.tpt;
3679 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
3680 adapter->colc_old = adapter->stats.colc;
3682 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
3683 adapter->gorc_old = adapter->stats.gorc;
3684 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
3685 adapter->gotc_old = adapter->stats.gotc;
3687 e1000e_update_adaptive(&adapter->hw);
3689 if (!netif_carrier_ok(netdev)) {
3690 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
3694 * We've lost link, so the controller stops DMA,
3695 * but we've got queued Tx work that's never going
3696 * to get done, so reset controller to flush Tx.
3697 * (Do the reset outside of interrupt context).
3699 adapter->tx_timeout_count++;
3700 schedule_work(&adapter->reset_task);
3701 /* return immediately since reset is imminent */
3706 /* Cause software interrupt to ensure Rx ring is cleaned */
3707 if (adapter->msix_entries)
3708 ew32(ICS, adapter->rx_ring->ims_val);
3710 ew32(ICS, E1000_ICS_RXDMT0);
3712 /* Force detection of hung controller every watchdog period */
3713 adapter->detect_tx_hung = 1;
3716 * With 82571 controllers, LAA may be overwritten due to controller
3717 * reset from the other port. Set the appropriate LAA in RAR[0]
3719 if (e1000e_get_laa_state_82571(hw))
3720 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
3722 /* Reset the timer */
3723 if (!test_bit(__E1000_DOWN, &adapter->state))
3724 mod_timer(&adapter->watchdog_timer,
3725 round_jiffies(jiffies + 2 * HZ));
3728 #define E1000_TX_FLAGS_CSUM 0x00000001
3729 #define E1000_TX_FLAGS_VLAN 0x00000002
3730 #define E1000_TX_FLAGS_TSO 0x00000004
3731 #define E1000_TX_FLAGS_IPV4 0x00000008
3732 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
3733 #define E1000_TX_FLAGS_VLAN_SHIFT 16
3735 static int e1000_tso(struct e1000_adapter *adapter,
3736 struct sk_buff *skb)
3738 struct e1000_ring *tx_ring = adapter->tx_ring;
3739 struct e1000_context_desc *context_desc;
3740 struct e1000_buffer *buffer_info;
3743 u16 ipcse = 0, tucse, mss;
3744 u8 ipcss, ipcso, tucss, tucso, hdr_len;
3747 if (!skb_is_gso(skb))
3750 if (skb_header_cloned(skb)) {
3751 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3756 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3757 mss = skb_shinfo(skb)->gso_size;
3758 if (skb->protocol == htons(ETH_P_IP)) {
3759 struct iphdr *iph = ip_hdr(skb);
3762 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
3764 cmd_length = E1000_TXD_CMD_IP;
3765 ipcse = skb_transport_offset(skb) - 1;
3766 } else if (skb_is_gso_v6(skb)) {
3767 ipv6_hdr(skb)->payload_len = 0;
3768 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3769 &ipv6_hdr(skb)->daddr,
3773 ipcss = skb_network_offset(skb);
3774 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
3775 tucss = skb_transport_offset(skb);
3776 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
3779 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
3780 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
3782 i = tx_ring->next_to_use;
3783 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3784 buffer_info = &tx_ring->buffer_info[i];
3786 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3787 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3788 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3789 context_desc->upper_setup.tcp_fields.tucss = tucss;
3790 context_desc->upper_setup.tcp_fields.tucso = tucso;
3791 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3792 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3793 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3794 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3796 buffer_info->time_stamp = jiffies;
3797 buffer_info->next_to_watch = i;
3800 if (i == tx_ring->count)
3802 tx_ring->next_to_use = i;
3807 static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
3809 struct e1000_ring *tx_ring = adapter->tx_ring;
3810 struct e1000_context_desc *context_desc;
3811 struct e1000_buffer *buffer_info;
3814 u32 cmd_len = E1000_TXD_CMD_DEXT;
3817 if (skb->ip_summed != CHECKSUM_PARTIAL)
3820 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
3821 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
3823 protocol = skb->protocol;
3826 case cpu_to_be16(ETH_P_IP):
3827 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3828 cmd_len |= E1000_TXD_CMD_TCP;
3830 case cpu_to_be16(ETH_P_IPV6):
3831 /* XXX not handling all IPV6 headers */
3832 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3833 cmd_len |= E1000_TXD_CMD_TCP;
3836 if (unlikely(net_ratelimit()))
3837 e_warn("checksum_partial proto=%x!\n",
3838 be16_to_cpu(protocol));
3842 css = skb_transport_offset(skb);
3844 i = tx_ring->next_to_use;
3845 buffer_info = &tx_ring->buffer_info[i];
3846 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3848 context_desc->lower_setup.ip_config = 0;
3849 context_desc->upper_setup.tcp_fields.tucss = css;
3850 context_desc->upper_setup.tcp_fields.tucso =
3851 css + skb->csum_offset;
3852 context_desc->upper_setup.tcp_fields.tucse = 0;
3853 context_desc->tcp_seg_setup.data = 0;
3854 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
3856 buffer_info->time_stamp = jiffies;
3857 buffer_info->next_to_watch = i;
3860 if (i == tx_ring->count)
3862 tx_ring->next_to_use = i;
3867 #define E1000_MAX_PER_TXD 8192
3868 #define E1000_MAX_TXD_PWR 12
3870 static int e1000_tx_map(struct e1000_adapter *adapter,
3871 struct sk_buff *skb, unsigned int first,
3872 unsigned int max_per_txd, unsigned int nr_frags,
3875 struct e1000_ring *tx_ring = adapter->tx_ring;
3876 struct pci_dev *pdev = adapter->pdev;
3877 struct e1000_buffer *buffer_info;
3878 unsigned int len = skb_headlen(skb);
3879 unsigned int offset = 0, size, count = 0, i;
3882 i = tx_ring->next_to_use;
3885 buffer_info = &tx_ring->buffer_info[i];
3886 size = min(len, max_per_txd);
3888 buffer_info->length = size;
3889 buffer_info->time_stamp = jiffies;
3890 buffer_info->next_to_watch = i;
3891 buffer_info->dma = pci_map_single(pdev, skb->data + offset,
3892 size, PCI_DMA_TODEVICE);
3893 buffer_info->mapped_as_page = false;
3894 if (pci_dma_mapping_error(pdev, buffer_info->dma))
3903 if (i == tx_ring->count)
3908 for (f = 0; f < nr_frags; f++) {
3909 struct skb_frag_struct *frag;
3911 frag = &skb_shinfo(skb)->frags[f];
3913 offset = frag->page_offset;
3917 if (i == tx_ring->count)
3920 buffer_info = &tx_ring->buffer_info[i];
3921 size = min(len, max_per_txd);
3923 buffer_info->length = size;
3924 buffer_info->time_stamp = jiffies;
3925 buffer_info->next_to_watch = i;
3926 buffer_info->dma = pci_map_page(pdev, frag->page,
3929 buffer_info->mapped_as_page = true;
3930 if (pci_dma_mapping_error(pdev, buffer_info->dma))
3939 tx_ring->buffer_info[i].skb = skb;
3940 tx_ring->buffer_info[first].next_to_watch = i;
3945 dev_err(&pdev->dev, "TX DMA map failed\n");
3946 buffer_info->dma = 0;
3952 i += tx_ring->count;
3954 buffer_info = &tx_ring->buffer_info[i];
3955 e1000_put_txbuf(adapter, buffer_info);;
3961 static void e1000_tx_queue(struct e1000_adapter *adapter,
3962 int tx_flags, int count)
3964 struct e1000_ring *tx_ring = adapter->tx_ring;
3965 struct e1000_tx_desc *tx_desc = NULL;
3966 struct e1000_buffer *buffer_info;
3967 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3970 if (tx_flags & E1000_TX_FLAGS_TSO) {
3971 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3973 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3975 if (tx_flags & E1000_TX_FLAGS_IPV4)
3976 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3979 if (tx_flags & E1000_TX_FLAGS_CSUM) {
3980 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3981 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3984 if (tx_flags & E1000_TX_FLAGS_VLAN) {
3985 txd_lower |= E1000_TXD_CMD_VLE;
3986 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3989 i = tx_ring->next_to_use;
3992 buffer_info = &tx_ring->buffer_info[i];
3993 tx_desc = E1000_TX_DESC(*tx_ring, i);
3994 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3995 tx_desc->lower.data =
3996 cpu_to_le32(txd_lower | buffer_info->length);
3997 tx_desc->upper.data = cpu_to_le32(txd_upper);
4000 if (i == tx_ring->count)
4004 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4007 * Force memory writes to complete before letting h/w
4008 * know there are new descriptors to fetch. (Only
4009 * applicable for weak-ordered memory model archs,
4014 tx_ring->next_to_use = i;
4015 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4017 * we need this if more than one processor can write to our tail
4018 * at a time, it synchronizes IO on IA64/Altix systems
4023 #define MINIMUM_DHCP_PACKET_SIZE 282
4024 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4025 struct sk_buff *skb)
4027 struct e1000_hw *hw = &adapter->hw;
4030 if (vlan_tx_tag_present(skb)) {
4031 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4032 (adapter->hw.mng_cookie.status &
4033 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4037 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4040 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4044 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4047 if (ip->protocol != IPPROTO_UDP)
4050 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4051 if (ntohs(udp->dest) != 67)
4054 offset = (u8 *)udp + 8 - skb->data;
4055 length = skb->len - offset;
4056 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4062 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4064 struct e1000_adapter *adapter = netdev_priv(netdev);
4066 netif_stop_queue(netdev);
4068 * Herbert's original patch had:
4069 * smp_mb__after_netif_stop_queue();
4070 * but since that doesn't exist yet, just open code it.
4075 * We need to check again in a case another CPU has just
4076 * made room available.
4078 if (e1000_desc_unused(adapter->tx_ring) < size)
4082 netif_start_queue(netdev);
4083 ++adapter->restart_queue;
4087 static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4089 struct e1000_adapter *adapter = netdev_priv(netdev);
4091 if (e1000_desc_unused(adapter->tx_ring) >= size)
4093 return __e1000_maybe_stop_tx(netdev, size);
4096 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4097 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4098 struct net_device *netdev)
4100 struct e1000_adapter *adapter = netdev_priv(netdev);
4101 struct e1000_ring *tx_ring = adapter->tx_ring;
4103 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4104 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4105 unsigned int tx_flags = 0;
4106 unsigned int len = skb->len - skb->data_len;
4107 unsigned int nr_frags;
4113 if (test_bit(__E1000_DOWN, &adapter->state)) {
4114 dev_kfree_skb_any(skb);
4115 return NETDEV_TX_OK;
4118 if (skb->len <= 0) {
4119 dev_kfree_skb_any(skb);
4120 return NETDEV_TX_OK;
4123 mss = skb_shinfo(skb)->gso_size;
4125 * The controller does a simple calculation to
4126 * make sure there is enough room in the FIFO before
4127 * initiating the DMA for each buffer. The calc is:
4128 * 4 = ceil(buffer len/mss). To make sure we don't
4129 * overrun the FIFO, adjust the max buffer len if mss
4134 max_per_txd = min(mss << 2, max_per_txd);
4135 max_txd_pwr = fls(max_per_txd) - 1;
4138 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4139 * points to just header, pull a few bytes of payload from
4140 * frags into skb->data
4142 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4144 * we do this workaround for ES2LAN, but it is un-necessary,
4145 * avoiding it could save a lot of cycles
4147 if (skb->data_len && (hdr_len == len)) {
4148 unsigned int pull_size;
4150 pull_size = min((unsigned int)4, skb->data_len);
4151 if (!__pskb_pull_tail(skb, pull_size)) {
4152 e_err("__pskb_pull_tail failed.\n");
4153 dev_kfree_skb_any(skb);
4154 return NETDEV_TX_OK;
4156 len = skb->len - skb->data_len;
4160 /* reserve a descriptor for the offload context */
4161 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4165 count += TXD_USE_COUNT(len, max_txd_pwr);
4167 nr_frags = skb_shinfo(skb)->nr_frags;
4168 for (f = 0; f < nr_frags; f++)
4169 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4172 if (adapter->hw.mac.tx_pkt_filtering)
4173 e1000_transfer_dhcp_info(adapter, skb);
4176 * need: count + 2 desc gap to keep tail from touching
4177 * head, otherwise try next time
4179 if (e1000_maybe_stop_tx(netdev, count + 2))
4180 return NETDEV_TX_BUSY;
4182 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4183 tx_flags |= E1000_TX_FLAGS_VLAN;
4184 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4187 first = tx_ring->next_to_use;
4189 tso = e1000_tso(adapter, skb);
4191 dev_kfree_skb_any(skb);
4192 return NETDEV_TX_OK;
4196 tx_flags |= E1000_TX_FLAGS_TSO;
4197 else if (e1000_tx_csum(adapter, skb))
4198 tx_flags |= E1000_TX_FLAGS_CSUM;
4201 * Old method was to assume IPv4 packet by default if TSO was enabled.
4202 * 82571 hardware supports TSO capabilities for IPv6 as well...
4203 * no longer assume, we must.
4205 if (skb->protocol == htons(ETH_P_IP))
4206 tx_flags |= E1000_TX_FLAGS_IPV4;
4208 /* if count is 0 then mapping error has occured */
4209 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
4211 e1000_tx_queue(adapter, tx_flags, count);
4212 /* Make sure there is space in the ring for the next send. */
4213 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4216 dev_kfree_skb_any(skb);
4217 tx_ring->buffer_info[first].time_stamp = 0;
4218 tx_ring->next_to_use = first;
4221 return NETDEV_TX_OK;
4225 * e1000_tx_timeout - Respond to a Tx Hang
4226 * @netdev: network interface device structure
4228 static void e1000_tx_timeout(struct net_device *netdev)
4230 struct e1000_adapter *adapter = netdev_priv(netdev);
4232 /* Do the reset outside of interrupt context */
4233 adapter->tx_timeout_count++;
4234 schedule_work(&adapter->reset_task);
4237 static void e1000_reset_task(struct work_struct *work)
4239 struct e1000_adapter *adapter;
4240 adapter = container_of(work, struct e1000_adapter, reset_task);
4242 e1000e_reinit_locked(adapter);
4246 * e1000_get_stats - Get System Network Statistics
4247 * @netdev: network interface device structure
4249 * Returns the address of the device statistics structure.
4250 * The statistics are actually updated from the timer callback.
4252 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
4254 /* only return the current stats */
4255 return &netdev->stats;
4259 * e1000_change_mtu - Change the Maximum Transfer Unit
4260 * @netdev: network interface device structure
4261 * @new_mtu: new value for maximum frame size
4263 * Returns 0 on success, negative on failure
4265 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4267 struct e1000_adapter *adapter = netdev_priv(netdev);
4268 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4270 /* Jumbo frame support */
4271 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
4272 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
4273 e_err("Jumbo Frames not supported.\n");
4277 /* Supported frame sizes */
4278 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
4279 (max_frame > adapter->max_hw_frame_size)) {
4280 e_err("Unsupported MTU setting\n");
4284 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4286 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
4287 adapter->max_frame_size = max_frame;
4288 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
4289 netdev->mtu = new_mtu;
4290 if (netif_running(netdev))
4291 e1000e_down(adapter);
4294 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
4295 * means we reserve 2 more, this pushes us to allocate from the next
4297 * i.e. RXBUFFER_2048 --> size-4096 slab
4298 * However with the new *_jumbo_rx* routines, jumbo receives will use
4302 if (max_frame <= 2048)
4303 adapter->rx_buffer_len = 2048;
4305 adapter->rx_buffer_len = 4096;
4307 /* adjust allocation if LPE protects us, and we aren't using SBP */
4308 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
4309 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
4310 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
4313 if (netif_running(netdev))
4316 e1000e_reset(adapter);
4318 clear_bit(__E1000_RESETTING, &adapter->state);
4323 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4326 struct e1000_adapter *adapter = netdev_priv(netdev);
4327 struct mii_ioctl_data *data = if_mii(ifr);
4329 if (adapter->hw.phy.media_type != e1000_media_type_copper)
4334 data->phy_id = adapter->hw.phy.addr;
4337 e1000_phy_read_status(adapter);
4339 switch (data->reg_num & 0x1F) {
4341 data->val_out = adapter->phy_regs.bmcr;
4344 data->val_out = adapter->phy_regs.bmsr;
4347 data->val_out = (adapter->hw.phy.id >> 16);
4350 data->val_out = (adapter->hw.phy.id & 0xFFFF);
4353 data->val_out = adapter->phy_regs.advertise;
4356 data->val_out = adapter->phy_regs.lpa;
4359 data->val_out = adapter->phy_regs.expansion;
4362 data->val_out = adapter->phy_regs.ctrl1000;
4365 data->val_out = adapter->phy_regs.stat1000;
4368 data->val_out = adapter->phy_regs.estatus;
4381 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4387 return e1000_mii_ioctl(netdev, ifr, cmd);
4393 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
4395 struct e1000_hw *hw = &adapter->hw;
4400 /* copy MAC RARs to PHY RARs */
4401 for (i = 0; i < adapter->hw.mac.rar_entry_count; i++) {
4402 mac_reg = er32(RAL(i));
4403 e1e_wphy(hw, BM_RAR_L(i), (u16)(mac_reg & 0xFFFF));
4404 e1e_wphy(hw, BM_RAR_M(i), (u16)((mac_reg >> 16) & 0xFFFF));
4405 mac_reg = er32(RAH(i));
4406 e1e_wphy(hw, BM_RAR_H(i), (u16)(mac_reg & 0xFFFF));
4407 e1e_wphy(hw, BM_RAR_CTRL(i), (u16)((mac_reg >> 16) & 0xFFFF));
4410 /* copy MAC MTA to PHY MTA */
4411 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
4412 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
4413 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
4414 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
4417 /* configure PHY Rx Control register */
4418 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
4419 mac_reg = er32(RCTL);
4420 if (mac_reg & E1000_RCTL_UPE)
4421 phy_reg |= BM_RCTL_UPE;
4422 if (mac_reg & E1000_RCTL_MPE)
4423 phy_reg |= BM_RCTL_MPE;
4424 phy_reg &= ~(BM_RCTL_MO_MASK);
4425 if (mac_reg & E1000_RCTL_MO_3)
4426 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
4427 << BM_RCTL_MO_SHIFT);
4428 if (mac_reg & E1000_RCTL_BAM)
4429 phy_reg |= BM_RCTL_BAM;
4430 if (mac_reg & E1000_RCTL_PMCF)
4431 phy_reg |= BM_RCTL_PMCF;
4432 mac_reg = er32(CTRL);
4433 if (mac_reg & E1000_CTRL_RFCE)
4434 phy_reg |= BM_RCTL_RFCE;
4435 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
4437 /* enable PHY wakeup in MAC register */
4439 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
4441 /* configure and enable PHY wakeup in PHY registers */
4442 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
4443 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
4445 /* activate PHY wakeup */
4446 retval = hw->phy.ops.acquire(hw);
4448 e_err("Could not acquire PHY\n");
4451 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4452 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
4453 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
4455 e_err("Could not read PHY page 769\n");
4458 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
4459 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
4461 e_err("Could not set PHY Host Wakeup bit\n");
4463 hw->phy.ops.release(hw);
4468 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
4470 struct net_device *netdev = pci_get_drvdata(pdev);
4471 struct e1000_adapter *adapter = netdev_priv(netdev);
4472 struct e1000_hw *hw = &adapter->hw;
4473 u32 ctrl, ctrl_ext, rctl, status;
4474 u32 wufc = adapter->wol;
4477 netif_device_detach(netdev);
4479 if (netif_running(netdev)) {
4480 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
4481 e1000e_down(adapter);
4482 e1000_free_irq(adapter);
4484 e1000e_reset_interrupt_capability(adapter);
4486 retval = pci_save_state(pdev);
4490 status = er32(STATUS);
4491 if (status & E1000_STATUS_LU)
4492 wufc &= ~E1000_WUFC_LNKC;
4495 e1000_setup_rctl(adapter);
4496 e1000_set_multi(netdev);
4498 /* turn on all-multi mode if wake on multicast is enabled */
4499 if (wufc & E1000_WUFC_MC) {
4501 rctl |= E1000_RCTL_MPE;
4506 /* advertise wake from D3Cold */
4507 #define E1000_CTRL_ADVD3WUC 0x00100000
4508 /* phy power management enable */
4509 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4510 ctrl |= E1000_CTRL_ADVD3WUC;
4511 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
4512 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
4515 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
4516 adapter->hw.phy.media_type ==
4517 e1000_media_type_internal_serdes) {
4518 /* keep the laser running in D3 */
4519 ctrl_ext = er32(CTRL_EXT);
4520 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
4521 ew32(CTRL_EXT, ctrl_ext);
4524 if (adapter->flags & FLAG_IS_ICH)
4525 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
4527 /* Allow time for pending master requests to run */
4528 e1000e_disable_pcie_master(&adapter->hw);
4530 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
4531 /* enable wakeup by the PHY */
4532 retval = e1000_init_phy_wakeup(adapter, wufc);
4536 /* enable wakeup by the MAC */
4538 ew32(WUC, E1000_WUC_PME_EN);
4545 *enable_wake = !!wufc;
4547 /* make sure adapter isn't asleep if manageability is enabled */
4548 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
4549 (hw->mac.ops.check_mng_mode(hw)))
4550 *enable_wake = true;
4552 if (adapter->hw.phy.type == e1000_phy_igp_3)
4553 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
4556 * Release control of h/w to f/w. If f/w is AMT enabled, this
4557 * would have already happened in close and is redundant.
4559 e1000_release_hw_control(adapter);
4561 pci_disable_device(pdev);
4566 static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
4568 if (sleep && wake) {
4569 pci_prepare_to_sleep(pdev);
4573 pci_wake_from_d3(pdev, wake);
4574 pci_set_power_state(pdev, PCI_D3hot);
4577 static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
4580 struct net_device *netdev = pci_get_drvdata(pdev);
4581 struct e1000_adapter *adapter = netdev_priv(netdev);
4584 * The pci-e switch on some quad port adapters will report a
4585 * correctable error when the MAC transitions from D0 to D3. To
4586 * prevent this we need to mask off the correctable errors on the
4587 * downstream port of the pci-e switch.
4589 if (adapter->flags & FLAG_IS_QUAD_PORT) {
4590 struct pci_dev *us_dev = pdev->bus->self;
4591 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
4594 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
4595 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
4596 (devctl & ~PCI_EXP_DEVCTL_CERE));
4598 e1000_power_off(pdev, sleep, wake);
4600 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
4602 e1000_power_off(pdev, sleep, wake);
4606 static void e1000e_disable_l1aspm(struct pci_dev *pdev)
4612 * 82573 workaround - disable L1 ASPM on mobile chipsets
4614 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
4615 * resulting in lost data or garbage information on the pci-e link
4616 * level. This could result in (false) bad EEPROM checksum errors,
4617 * long ping times (up to 2s) or even a system freeze/hang.
4619 * Unfortunately this feature saves about 1W power consumption when
4622 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
4623 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val);
4625 dev_warn(&pdev->dev, "Disabling L1 ASPM\n");
4627 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val);
4632 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4637 retval = __e1000_shutdown(pdev, &wake);
4639 e1000_complete_shutdown(pdev, true, wake);
4644 static int e1000_resume(struct pci_dev *pdev)
4646 struct net_device *netdev = pci_get_drvdata(pdev);
4647 struct e1000_adapter *adapter = netdev_priv(netdev);
4648 struct e1000_hw *hw = &adapter->hw;
4651 pci_set_power_state(pdev, PCI_D0);
4652 pci_restore_state(pdev);
4653 pci_save_state(pdev);
4654 e1000e_disable_l1aspm(pdev);
4656 err = pci_enable_device_mem(pdev);
4659 "Cannot enable PCI device from suspend\n");
4663 pci_set_master(pdev);
4665 pci_enable_wake(pdev, PCI_D3hot, 0);
4666 pci_enable_wake(pdev, PCI_D3cold, 0);
4668 e1000e_set_interrupt_capability(adapter);
4669 if (netif_running(netdev)) {
4670 err = e1000_request_irq(adapter);
4675 e1000e_power_up_phy(adapter);
4677 /* report the system wakeup cause from S3/S4 */
4678 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
4681 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
4683 e_info("PHY Wakeup cause - %s\n",
4684 phy_data & E1000_WUS_EX ? "Unicast Packet" :
4685 phy_data & E1000_WUS_MC ? "Multicast Packet" :
4686 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
4687 phy_data & E1000_WUS_MAG ? "Magic Packet" :
4688 phy_data & E1000_WUS_LNKC ? "Link Status "
4689 " Change" : "other");
4691 e1e_wphy(&adapter->hw, BM_WUS, ~0);
4693 u32 wus = er32(WUS);
4695 e_info("MAC Wakeup cause - %s\n",
4696 wus & E1000_WUS_EX ? "Unicast Packet" :
4697 wus & E1000_WUS_MC ? "Multicast Packet" :
4698 wus & E1000_WUS_BC ? "Broadcast Packet" :
4699 wus & E1000_WUS_MAG ? "Magic Packet" :
4700 wus & E1000_WUS_LNKC ? "Link Status Change" :
4706 e1000e_reset(adapter);
4708 e1000_init_manageability(adapter);
4710 if (netif_running(netdev))
4713 netif_device_attach(netdev);
4716 * If the controller has AMT, do not set DRV_LOAD until the interface
4717 * is up. For all other cases, let the f/w know that the h/w is now
4718 * under the control of the driver.
4720 if (!(adapter->flags & FLAG_HAS_AMT))
4721 e1000_get_hw_control(adapter);
4727 static void e1000_shutdown(struct pci_dev *pdev)
4731 __e1000_shutdown(pdev, &wake);
4733 if (system_state == SYSTEM_POWER_OFF)
4734 e1000_complete_shutdown(pdev, false, wake);
4737 #ifdef CONFIG_NET_POLL_CONTROLLER
4739 * Polling 'interrupt' - used by things like netconsole to send skbs
4740 * without having to re-enable interrupts. It's not called while
4741 * the interrupt routine is executing.
4743 static void e1000_netpoll(struct net_device *netdev)
4745 struct e1000_adapter *adapter = netdev_priv(netdev);
4747 disable_irq(adapter->pdev->irq);
4748 e1000_intr(adapter->pdev->irq, netdev);
4750 enable_irq(adapter->pdev->irq);
4755 * e1000_io_error_detected - called when PCI error is detected
4756 * @pdev: Pointer to PCI device
4757 * @state: The current pci connection state
4759 * This function is called after a PCI bus error affecting
4760 * this device has been detected.
4762 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
4763 pci_channel_state_t state)
4765 struct net_device *netdev = pci_get_drvdata(pdev);
4766 struct e1000_adapter *adapter = netdev_priv(netdev);
4768 netif_device_detach(netdev);
4770 if (state == pci_channel_io_perm_failure)
4771 return PCI_ERS_RESULT_DISCONNECT;
4773 if (netif_running(netdev))
4774 e1000e_down(adapter);
4775 pci_disable_device(pdev);
4777 /* Request a slot slot reset. */
4778 return PCI_ERS_RESULT_NEED_RESET;
4782 * e1000_io_slot_reset - called after the pci bus has been reset.
4783 * @pdev: Pointer to PCI device
4785 * Restart the card from scratch, as if from a cold-boot. Implementation
4786 * resembles the first-half of the e1000_resume routine.
4788 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4790 struct net_device *netdev = pci_get_drvdata(pdev);
4791 struct e1000_adapter *adapter = netdev_priv(netdev);
4792 struct e1000_hw *hw = &adapter->hw;
4794 pci_ers_result_t result;
4796 e1000e_disable_l1aspm(pdev);
4797 err = pci_enable_device_mem(pdev);
4800 "Cannot re-enable PCI device after reset.\n");
4801 result = PCI_ERS_RESULT_DISCONNECT;
4803 pci_set_master(pdev);
4804 pci_restore_state(pdev);
4805 pci_save_state(pdev);
4807 pci_enable_wake(pdev, PCI_D3hot, 0);
4808 pci_enable_wake(pdev, PCI_D3cold, 0);
4810 e1000e_reset(adapter);
4812 result = PCI_ERS_RESULT_RECOVERED;
4815 pci_cleanup_aer_uncorrect_error_status(pdev);
4821 * e1000_io_resume - called when traffic can start flowing again.
4822 * @pdev: Pointer to PCI device
4824 * This callback is called when the error recovery driver tells us that
4825 * its OK to resume normal operation. Implementation resembles the
4826 * second-half of the e1000_resume routine.
4828 static void e1000_io_resume(struct pci_dev *pdev)
4830 struct net_device *netdev = pci_get_drvdata(pdev);
4831 struct e1000_adapter *adapter = netdev_priv(netdev);
4833 e1000_init_manageability(adapter);
4835 if (netif_running(netdev)) {
4836 if (e1000e_up(adapter)) {
4838 "can't bring device back up after reset\n");
4843 netif_device_attach(netdev);
4846 * If the controller has AMT, do not set DRV_LOAD until the interface
4847 * is up. For all other cases, let the f/w know that the h/w is now
4848 * under the control of the driver.
4850 if (!(adapter->flags & FLAG_HAS_AMT))
4851 e1000_get_hw_control(adapter);
4855 static void e1000_print_device_info(struct e1000_adapter *adapter)
4857 struct e1000_hw *hw = &adapter->hw;
4858 struct net_device *netdev = adapter->netdev;
4861 /* print bus type/speed/width info */
4862 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
4864 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
4868 e_info("Intel(R) PRO/%s Network Connection\n",
4869 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
4870 e1000e_read_pba_num(hw, &pba_num);
4871 e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4872 hw->mac.type, hw->phy.type, (pba_num >> 8), (pba_num & 0xff));
4875 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
4877 struct e1000_hw *hw = &adapter->hw;
4881 if (hw->mac.type != e1000_82573)
4884 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
4885 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
4886 /* Deep Smart Power Down (DSPD) */
4887 dev_warn(&adapter->pdev->dev,
4888 "Warning: detected DSPD enabled in EEPROM\n");
4891 ret_val = e1000_read_nvm(hw, NVM_INIT_3GIO_3, 1, &buf);
4892 if (!ret_val && (le16_to_cpu(buf) & (3 << 2))) {
4894 dev_warn(&adapter->pdev->dev,
4895 "Warning: detected ASPM enabled in EEPROM\n");
4899 static const struct net_device_ops e1000e_netdev_ops = {
4900 .ndo_open = e1000_open,
4901 .ndo_stop = e1000_close,
4902 .ndo_start_xmit = e1000_xmit_frame,
4903 .ndo_get_stats = e1000_get_stats,
4904 .ndo_set_multicast_list = e1000_set_multi,
4905 .ndo_set_mac_address = e1000_set_mac,
4906 .ndo_change_mtu = e1000_change_mtu,
4907 .ndo_do_ioctl = e1000_ioctl,
4908 .ndo_tx_timeout = e1000_tx_timeout,
4909 .ndo_validate_addr = eth_validate_addr,
4911 .ndo_vlan_rx_register = e1000_vlan_rx_register,
4912 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
4913 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
4914 #ifdef CONFIG_NET_POLL_CONTROLLER
4915 .ndo_poll_controller = e1000_netpoll,
4920 * e1000_probe - Device Initialization Routine
4921 * @pdev: PCI device information struct
4922 * @ent: entry in e1000_pci_tbl
4924 * Returns 0 on success, negative on failure
4926 * e1000_probe initializes an adapter identified by a pci_dev structure.
4927 * The OS initialization, configuring of the adapter private structure,
4928 * and a hardware reset occur.
4930 static int __devinit e1000_probe(struct pci_dev *pdev,
4931 const struct pci_device_id *ent)
4933 struct net_device *netdev;
4934 struct e1000_adapter *adapter;
4935 struct e1000_hw *hw;
4936 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
4937 resource_size_t mmio_start, mmio_len;
4938 resource_size_t flash_start, flash_len;
4940 static int cards_found;
4941 int i, err, pci_using_dac;
4942 u16 eeprom_data = 0;
4943 u16 eeprom_apme_mask = E1000_EEPROM_APME;
4945 e1000e_disable_l1aspm(pdev);
4947 err = pci_enable_device_mem(pdev);
4952 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
4954 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
4958 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
4960 err = pci_set_consistent_dma_mask(pdev,
4963 dev_err(&pdev->dev, "No usable DMA "
4964 "configuration, aborting\n");
4970 err = pci_request_selected_regions_exclusive(pdev,
4971 pci_select_bars(pdev, IORESOURCE_MEM),
4972 e1000e_driver_name);
4976 /* AER (Advanced Error Reporting) hooks */
4977 pci_enable_pcie_error_reporting(pdev);
4979 pci_set_master(pdev);
4980 /* PCI config space info */
4981 err = pci_save_state(pdev);
4983 goto err_alloc_etherdev;
4986 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
4988 goto err_alloc_etherdev;
4990 SET_NETDEV_DEV(netdev, &pdev->dev);
4992 pci_set_drvdata(pdev, netdev);
4993 adapter = netdev_priv(netdev);
4995 adapter->netdev = netdev;
4996 adapter->pdev = pdev;
4998 adapter->pba = ei->pba;
4999 adapter->flags = ei->flags;
5000 adapter->flags2 = ei->flags2;
5001 adapter->hw.adapter = adapter;
5002 adapter->hw.mac.type = ei->mac;
5003 adapter->max_hw_frame_size = ei->max_hw_frame_size;
5004 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5006 mmio_start = pci_resource_start(pdev, 0);
5007 mmio_len = pci_resource_len(pdev, 0);
5010 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5011 if (!adapter->hw.hw_addr)
5014 if ((adapter->flags & FLAG_HAS_FLASH) &&
5015 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5016 flash_start = pci_resource_start(pdev, 1);
5017 flash_len = pci_resource_len(pdev, 1);
5018 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5019 if (!adapter->hw.flash_address)
5023 /* construct the net_device struct */
5024 netdev->netdev_ops = &e1000e_netdev_ops;
5025 e1000e_set_ethtool_ops(netdev);
5026 netdev->watchdog_timeo = 5 * HZ;
5027 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
5028 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5030 netdev->mem_start = mmio_start;
5031 netdev->mem_end = mmio_start + mmio_len;
5033 adapter->bd_number = cards_found++;
5035 e1000e_check_options(adapter);
5037 /* setup adapter struct */
5038 err = e1000_sw_init(adapter);
5044 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5045 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5046 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5048 err = ei->get_variants(adapter);
5052 if ((adapter->flags & FLAG_IS_ICH) &&
5053 (adapter->flags & FLAG_READ_ONLY_NVM))
5054 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5056 hw->mac.ops.get_bus_info(&adapter->hw);
5058 adapter->hw.phy.autoneg_wait_to_complete = 0;
5060 /* Copper options */
5061 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
5062 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5063 adapter->hw.phy.disable_polarity_correction = 0;
5064 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5067 if (e1000_check_reset_block(&adapter->hw))
5068 e_info("PHY reset is blocked due to SOL/IDER session.\n");
5070 netdev->features = NETIF_F_SG |
5072 NETIF_F_HW_VLAN_TX |
5075 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5076 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5078 netdev->features |= NETIF_F_TSO;
5079 netdev->features |= NETIF_F_TSO6;
5081 netdev->vlan_features |= NETIF_F_TSO;
5082 netdev->vlan_features |= NETIF_F_TSO6;
5083 netdev->vlan_features |= NETIF_F_HW_CSUM;
5084 netdev->vlan_features |= NETIF_F_SG;
5087 netdev->features |= NETIF_F_HIGHDMA;
5089 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5090 adapter->flags |= FLAG_MNG_PT_ENABLED;
5093 * before reading the NVM, reset the controller to
5094 * put the device in a known good starting state
5096 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5099 * systems with ASPM and others may see the checksum fail on the first
5100 * attempt. Let's give it a few tries
5103 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5106 e_err("The NVM Checksum Is Not Valid\n");
5112 e1000_eeprom_checks(adapter);
5114 /* copy the MAC address */
5115 if (e1000e_read_mac_addr(&adapter->hw))
5116 e_err("NVM Read Error while reading MAC address\n");
5118 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5119 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5121 if (!is_valid_ether_addr(netdev->perm_addr)) {
5122 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
5127 init_timer(&adapter->watchdog_timer);
5128 adapter->watchdog_timer.function = &e1000_watchdog;
5129 adapter->watchdog_timer.data = (unsigned long) adapter;
5131 init_timer(&adapter->phy_info_timer);
5132 adapter->phy_info_timer.function = &e1000_update_phy_info;
5133 adapter->phy_info_timer.data = (unsigned long) adapter;
5135 INIT_WORK(&adapter->reset_task, e1000_reset_task);
5136 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
5137 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
5138 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
5139 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
5141 /* Initialize link parameters. User can change them with ethtool */
5142 adapter->hw.mac.autoneg = 1;
5143 adapter->fc_autoneg = 1;
5144 adapter->hw.fc.requested_mode = e1000_fc_default;
5145 adapter->hw.fc.current_mode = e1000_fc_default;
5146 adapter->hw.phy.autoneg_advertised = 0x2f;
5148 /* ring size defaults */
5149 adapter->rx_ring->count = 256;
5150 adapter->tx_ring->count = 256;
5153 * Initial Wake on LAN setting - If APM wake is enabled in
5154 * the EEPROM, enable the ACPI Magic Packet filter
5156 if (adapter->flags & FLAG_APME_IN_WUC) {
5157 /* APME bit in EEPROM is mapped to WUC.APME */
5158 eeprom_data = er32(WUC);
5159 eeprom_apme_mask = E1000_WUC_APME;
5160 if (eeprom_data & E1000_WUC_PHY_WAKE)
5161 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
5162 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
5163 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
5164 (adapter->hw.bus.func == 1))
5165 e1000_read_nvm(&adapter->hw,
5166 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
5168 e1000_read_nvm(&adapter->hw,
5169 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
5172 /* fetch WoL from EEPROM */
5173 if (eeprom_data & eeprom_apme_mask)
5174 adapter->eeprom_wol |= E1000_WUFC_MAG;
5177 * now that we have the eeprom settings, apply the special cases
5178 * where the eeprom may be wrong or the board simply won't support
5179 * wake on lan on a particular port
5181 if (!(adapter->flags & FLAG_HAS_WOL))
5182 adapter->eeprom_wol = 0;
5184 /* initialize the wol settings based on the eeprom settings */
5185 adapter->wol = adapter->eeprom_wol;
5186 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5188 /* save off EEPROM version number */
5189 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
5191 /* reset the hardware with the new settings */
5192 e1000e_reset(adapter);
5195 * If the controller has AMT, do not set DRV_LOAD until the interface
5196 * is up. For all other cases, let the f/w know that the h/w is now
5197 * under the control of the driver.
5199 if (!(adapter->flags & FLAG_HAS_AMT))
5200 e1000_get_hw_control(adapter);
5202 strcpy(netdev->name, "eth%d");
5203 err = register_netdev(netdev);
5207 /* carrier off reporting is important to ethtool even BEFORE open */
5208 netif_carrier_off(netdev);
5210 e1000_print_device_info(adapter);
5215 if (!(adapter->flags & FLAG_HAS_AMT))
5216 e1000_release_hw_control(adapter);
5218 if (!e1000_check_reset_block(&adapter->hw))
5219 e1000_phy_hw_reset(&adapter->hw);
5222 kfree(adapter->tx_ring);
5223 kfree(adapter->rx_ring);
5225 if (adapter->hw.flash_address)
5226 iounmap(adapter->hw.flash_address);
5227 e1000e_reset_interrupt_capability(adapter);
5229 iounmap(adapter->hw.hw_addr);
5231 free_netdev(netdev);
5233 pci_release_selected_regions(pdev,
5234 pci_select_bars(pdev, IORESOURCE_MEM));
5237 pci_disable_device(pdev);
5242 * e1000_remove - Device Removal Routine
5243 * @pdev: PCI device information struct
5245 * e1000_remove is called by the PCI subsystem to alert the driver
5246 * that it should release a PCI device. The could be caused by a
5247 * Hot-Plug event, or because the driver is going to be removed from
5250 static void __devexit e1000_remove(struct pci_dev *pdev)
5252 struct net_device *netdev = pci_get_drvdata(pdev);
5253 struct e1000_adapter *adapter = netdev_priv(netdev);
5256 * flush_scheduled work may reschedule our watchdog task, so
5257 * explicitly disable watchdog tasks from being rescheduled
5259 set_bit(__E1000_DOWN, &adapter->state);
5260 del_timer_sync(&adapter->watchdog_timer);
5261 del_timer_sync(&adapter->phy_info_timer);
5263 cancel_work_sync(&adapter->reset_task);
5264 cancel_work_sync(&adapter->watchdog_task);
5265 cancel_work_sync(&adapter->downshift_task);
5266 cancel_work_sync(&adapter->update_phy_task);
5267 cancel_work_sync(&adapter->print_hang_task);
5268 flush_scheduled_work();
5270 if (!(netdev->flags & IFF_UP))
5271 e1000_power_down_phy(adapter);
5273 unregister_netdev(netdev);
5276 * Release control of h/w to f/w. If f/w is AMT enabled, this
5277 * would have already happened in close and is redundant.
5279 e1000_release_hw_control(adapter);
5281 e1000e_reset_interrupt_capability(adapter);
5282 kfree(adapter->tx_ring);
5283 kfree(adapter->rx_ring);
5285 iounmap(adapter->hw.hw_addr);
5286 if (adapter->hw.flash_address)
5287 iounmap(adapter->hw.flash_address);
5288 pci_release_selected_regions(pdev,
5289 pci_select_bars(pdev, IORESOURCE_MEM));
5291 free_netdev(netdev);
5294 pci_disable_pcie_error_reporting(pdev);
5296 pci_disable_device(pdev);
5299 /* PCI Error Recovery (ERS) */
5300 static struct pci_error_handlers e1000_err_handler = {
5301 .error_detected = e1000_io_error_detected,
5302 .slot_reset = e1000_io_slot_reset,
5303 .resume = e1000_io_resume,
5306 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
5307 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
5308 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
5309 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
5310 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
5311 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
5312 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
5313 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
5314 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
5315 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
5317 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
5318 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
5319 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
5320 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
5322 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
5323 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
5324 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
5326 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
5327 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
5328 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
5330 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
5331 board_80003es2lan },
5332 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
5333 board_80003es2lan },
5334 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
5335 board_80003es2lan },
5336 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
5337 board_80003es2lan },
5339 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
5340 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
5341 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
5342 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
5343 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
5344 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
5345 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
5346 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
5348 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
5349 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
5350 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
5351 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
5352 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
5353 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
5354 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
5355 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
5356 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
5358 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
5359 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
5360 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
5362 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
5363 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
5365 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
5366 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
5367 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
5368 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
5370 { } /* terminate list */
5372 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
5374 /* PCI Device API Driver */
5375 static struct pci_driver e1000_driver = {
5376 .name = e1000e_driver_name,
5377 .id_table = e1000_pci_tbl,
5378 .probe = e1000_probe,
5379 .remove = __devexit_p(e1000_remove),
5381 /* Power Management Hooks */
5382 .suspend = e1000_suspend,
5383 .resume = e1000_resume,
5385 .shutdown = e1000_shutdown,
5386 .err_handler = &e1000_err_handler
5390 * e1000_init_module - Driver Registration Routine
5392 * e1000_init_module is the first routine called when the driver is
5393 * loaded. All it does is register with the PCI subsystem.
5395 static int __init e1000_init_module(void)
5398 printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
5399 e1000e_driver_name, e1000e_driver_version);
5400 printk(KERN_INFO "%s: Copyright (c) 1999 - 2009 Intel Corporation.\n",
5401 e1000e_driver_name);
5402 ret = pci_register_driver(&e1000_driver);
5406 module_init(e1000_init_module);
5409 * e1000_exit_module - Driver Exit Cleanup Routine
5411 * e1000_exit_module is called just before the driver is removed
5414 static void __exit e1000_exit_module(void)
5416 pci_unregister_driver(&e1000_driver);
5418 module_exit(e1000_exit_module);
5421 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
5422 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
5423 MODULE_LICENSE("GPL");
5424 MODULE_VERSION(DRV_VERSION);