Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / net / e1000e / netdev.c
blob3a02e13b3e0d339b899e94f8de5310b801210614
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2007 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
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".
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include <linux/module.h>
30 #include <linux/types.h>
31 #include <linux/init.h>
32 #include <linux/pci.h>
33 #include <linux/vmalloc.h>
34 #include <linux/pagemap.h>
35 #include <linux/delay.h>
36 #include <linux/netdevice.h>
37 #include <linux/tcp.h>
38 #include <linux/ipv6.h>
39 #include <net/checksum.h>
40 #include <net/ip6_checksum.h>
41 #include <linux/mii.h>
42 #include <linux/ethtool.h>
43 #include <linux/if_vlan.h>
44 #include <linux/cpu.h>
45 #include <linux/smp.h>
47 #include "e1000.h"
49 #define DRV_VERSION "0.2.0"
50 char e1000e_driver_name[] = "e1000e";
51 const char e1000e_driver_version[] = DRV_VERSION;
53 static const struct e1000_info *e1000_info_tbl[] = {
54 [board_82571] = &e1000_82571_info,
55 [board_82572] = &e1000_82572_info,
56 [board_82573] = &e1000_82573_info,
57 [board_80003es2lan] = &e1000_es2_info,
58 [board_ich8lan] = &e1000_ich8_info,
59 [board_ich9lan] = &e1000_ich9_info,
62 #ifdef DEBUG
63 /**
64 * e1000_get_hw_dev_name - return device name string
65 * used by hardware layer to print debugging information
66 **/
67 char *e1000e_get_hw_dev_name(struct e1000_hw *hw)
69 return hw->adapter->netdev->name;
71 #endif
73 /**
74 * e1000_desc_unused - calculate if we have unused descriptors
75 **/
76 static int e1000_desc_unused(struct e1000_ring *ring)
78 if (ring->next_to_clean > ring->next_to_use)
79 return ring->next_to_clean - ring->next_to_use - 1;
81 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
84 /**
85 * e1000_receive_skb - helper function to handle rx indications
86 * @adapter: board private structure
87 * @status: descriptor status field as written by hardware
88 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
89 * @skb: pointer to sk_buff to be indicated to stack
90 **/
91 static void e1000_receive_skb(struct e1000_adapter *adapter,
92 struct net_device *netdev,
93 struct sk_buff *skb,
94 u8 status, __le16 vlan)
96 skb->protocol = eth_type_trans(skb, netdev);
98 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
99 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
100 le16_to_cpu(vlan) &
101 E1000_RXD_SPC_VLAN_MASK);
102 else
103 netif_receive_skb(skb);
105 netdev->last_rx = jiffies;
109 * e1000_rx_checksum - Receive Checksum Offload for 82543
110 * @adapter: board private structure
111 * @status_err: receive descriptor status and error fields
112 * @csum: receive descriptor csum field
113 * @sk_buff: socket buffer with received data
115 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
116 u32 csum, struct sk_buff *skb)
118 u16 status = (u16)status_err;
119 u8 errors = (u8)(status_err >> 24);
120 skb->ip_summed = CHECKSUM_NONE;
122 /* Ignore Checksum bit is set */
123 if (status & E1000_RXD_STAT_IXSM)
124 return;
125 /* TCP/UDP checksum error bit is set */
126 if (errors & E1000_RXD_ERR_TCPE) {
127 /* let the stack verify checksum errors */
128 adapter->hw_csum_err++;
129 return;
132 /* TCP/UDP Checksum has not been calculated */
133 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
134 return;
136 /* It must be a TCP or UDP packet with a valid checksum */
137 if (status & E1000_RXD_STAT_TCPCS) {
138 /* TCP checksum is good */
139 skb->ip_summed = CHECKSUM_UNNECESSARY;
140 } else {
141 /* IP fragment with UDP payload */
142 /* Hardware complements the payload checksum, so we undo it
143 * and then put the value in host order for further stack use.
145 __sum16 sum = (__force __sum16)htons(csum);
146 skb->csum = csum_unfold(~sum);
147 skb->ip_summed = CHECKSUM_COMPLETE;
149 adapter->hw_csum_good++;
153 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
154 * @adapter: address of board private structure
156 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
157 int cleaned_count)
159 struct net_device *netdev = adapter->netdev;
160 struct pci_dev *pdev = adapter->pdev;
161 struct e1000_ring *rx_ring = adapter->rx_ring;
162 struct e1000_rx_desc *rx_desc;
163 struct e1000_buffer *buffer_info;
164 struct sk_buff *skb;
165 unsigned int i;
166 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
168 i = rx_ring->next_to_use;
169 buffer_info = &rx_ring->buffer_info[i];
171 while (cleaned_count--) {
172 skb = buffer_info->skb;
173 if (skb) {
174 skb_trim(skb, 0);
175 goto map_skb;
178 skb = netdev_alloc_skb(netdev, bufsz);
179 if (!skb) {
180 /* Better luck next round */
181 adapter->alloc_rx_buff_failed++;
182 break;
185 /* Make buffer alignment 2 beyond a 16 byte boundary
186 * this will result in a 16 byte aligned IP header after
187 * the 14 byte MAC header is removed
189 skb_reserve(skb, NET_IP_ALIGN);
191 buffer_info->skb = skb;
192 map_skb:
193 buffer_info->dma = pci_map_single(pdev, skb->data,
194 adapter->rx_buffer_len,
195 PCI_DMA_FROMDEVICE);
196 if (pci_dma_mapping_error(buffer_info->dma)) {
197 dev_err(&pdev->dev, "RX DMA map failed\n");
198 adapter->rx_dma_failed++;
199 break;
202 rx_desc = E1000_RX_DESC(*rx_ring, i);
203 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
205 i++;
206 if (i == rx_ring->count)
207 i = 0;
208 buffer_info = &rx_ring->buffer_info[i];
211 if (rx_ring->next_to_use != i) {
212 rx_ring->next_to_use = i;
213 if (i-- == 0)
214 i = (rx_ring->count - 1);
216 /* Force memory writes to complete before letting h/w
217 * know there are new descriptors to fetch. (Only
218 * applicable for weak-ordered memory model archs,
219 * such as IA-64). */
220 wmb();
221 writel(i, adapter->hw.hw_addr + rx_ring->tail);
226 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
227 * @adapter: address of board private structure
229 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
230 int cleaned_count)
232 struct net_device *netdev = adapter->netdev;
233 struct pci_dev *pdev = adapter->pdev;
234 union e1000_rx_desc_packet_split *rx_desc;
235 struct e1000_ring *rx_ring = adapter->rx_ring;
236 struct e1000_buffer *buffer_info;
237 struct e1000_ps_page *ps_page;
238 struct sk_buff *skb;
239 unsigned int i, j;
241 i = rx_ring->next_to_use;
242 buffer_info = &rx_ring->buffer_info[i];
244 while (cleaned_count--) {
245 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
247 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
248 ps_page = &buffer_info->ps_pages[j];
249 if (j >= adapter->rx_ps_pages) {
250 /* all unused desc entries get hw null ptr */
251 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
252 continue;
254 if (!ps_page->page) {
255 ps_page->page = alloc_page(GFP_ATOMIC);
256 if (!ps_page->page) {
257 adapter->alloc_rx_buff_failed++;
258 goto no_buffers;
260 ps_page->dma = pci_map_page(pdev,
261 ps_page->page,
262 0, PAGE_SIZE,
263 PCI_DMA_FROMDEVICE);
264 if (pci_dma_mapping_error(ps_page->dma)) {
265 dev_err(&adapter->pdev->dev,
266 "RX DMA page map failed\n");
267 adapter->rx_dma_failed++;
268 goto no_buffers;
272 * Refresh the desc even if buffer_addrs
273 * didn't change because each write-back
274 * erases this info.
276 rx_desc->read.buffer_addr[j+1] =
277 cpu_to_le64(ps_page->dma);
280 skb = netdev_alloc_skb(netdev,
281 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
283 if (!skb) {
284 adapter->alloc_rx_buff_failed++;
285 break;
288 /* Make buffer alignment 2 beyond a 16 byte boundary
289 * this will result in a 16 byte aligned IP header after
290 * the 14 byte MAC header is removed
292 skb_reserve(skb, NET_IP_ALIGN);
294 buffer_info->skb = skb;
295 buffer_info->dma = pci_map_single(pdev, skb->data,
296 adapter->rx_ps_bsize0,
297 PCI_DMA_FROMDEVICE);
298 if (pci_dma_mapping_error(buffer_info->dma)) {
299 dev_err(&pdev->dev, "RX DMA map failed\n");
300 adapter->rx_dma_failed++;
301 /* cleanup skb */
302 dev_kfree_skb_any(skb);
303 buffer_info->skb = NULL;
304 break;
307 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
309 i++;
310 if (i == rx_ring->count)
311 i = 0;
312 buffer_info = &rx_ring->buffer_info[i];
315 no_buffers:
316 if (rx_ring->next_to_use != i) {
317 rx_ring->next_to_use = i;
319 if (!(i--))
320 i = (rx_ring->count - 1);
322 /* Force memory writes to complete before letting h/w
323 * know there are new descriptors to fetch. (Only
324 * applicable for weak-ordered memory model archs,
325 * such as IA-64). */
326 wmb();
327 /* Hardware increments by 16 bytes, but packet split
328 * descriptors are 32 bytes...so we increment tail
329 * twice as much.
331 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
336 * e1000_clean_rx_irq - Send received data up the network stack; legacy
337 * @adapter: board private structure
339 * the return value indicates whether actual cleaning was done, there
340 * is no guarantee that everything was cleaned
342 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
343 int *work_done, int work_to_do)
345 struct net_device *netdev = adapter->netdev;
346 struct pci_dev *pdev = adapter->pdev;
347 struct e1000_ring *rx_ring = adapter->rx_ring;
348 struct e1000_rx_desc *rx_desc, *next_rxd;
349 struct e1000_buffer *buffer_info, *next_buffer;
350 u32 length;
351 unsigned int i;
352 int cleaned_count = 0;
353 bool cleaned = 0;
354 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
356 i = rx_ring->next_to_clean;
357 rx_desc = E1000_RX_DESC(*rx_ring, i);
358 buffer_info = &rx_ring->buffer_info[i];
360 while (rx_desc->status & E1000_RXD_STAT_DD) {
361 struct sk_buff *skb;
362 u8 status;
364 if (*work_done >= work_to_do)
365 break;
366 (*work_done)++;
368 status = rx_desc->status;
369 skb = buffer_info->skb;
370 buffer_info->skb = NULL;
372 prefetch(skb->data - NET_IP_ALIGN);
374 i++;
375 if (i == rx_ring->count)
376 i = 0;
377 next_rxd = E1000_RX_DESC(*rx_ring, i);
378 prefetch(next_rxd);
380 next_buffer = &rx_ring->buffer_info[i];
382 cleaned = 1;
383 cleaned_count++;
384 pci_unmap_single(pdev,
385 buffer_info->dma,
386 adapter->rx_buffer_len,
387 PCI_DMA_FROMDEVICE);
388 buffer_info->dma = 0;
390 length = le16_to_cpu(rx_desc->length);
392 /* !EOP means multiple descriptors were used to store a single
393 * packet, also make sure the frame isn't just CRC only */
394 if (!(status & E1000_RXD_STAT_EOP) || (length <= 4)) {
395 /* All receives must fit into a single buffer */
396 ndev_dbg(netdev, "%s: Receive packet consumed "
397 "multiple buffers\n", netdev->name);
398 /* recycle */
399 buffer_info->skb = skb;
400 goto next_desc;
403 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
404 /* recycle */
405 buffer_info->skb = skb;
406 goto next_desc;
409 total_rx_bytes += length;
410 total_rx_packets++;
412 /* code added for copybreak, this should improve
413 * performance for small packets with large amounts
414 * of reassembly being done in the stack */
415 if (length < copybreak) {
416 struct sk_buff *new_skb =
417 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
418 if (new_skb) {
419 skb_reserve(new_skb, NET_IP_ALIGN);
420 memcpy(new_skb->data - NET_IP_ALIGN,
421 skb->data - NET_IP_ALIGN,
422 length + NET_IP_ALIGN);
423 /* save the skb in buffer_info as good */
424 buffer_info->skb = skb;
425 skb = new_skb;
427 /* else just continue with the old one */
429 /* end copybreak code */
430 skb_put(skb, length);
432 /* Receive Checksum Offload */
433 e1000_rx_checksum(adapter,
434 (u32)(status) |
435 ((u32)(rx_desc->errors) << 24),
436 le16_to_cpu(rx_desc->csum), skb);
438 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
440 next_desc:
441 rx_desc->status = 0;
443 /* return some buffers to hardware, one at a time is too slow */
444 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
445 adapter->alloc_rx_buf(adapter, cleaned_count);
446 cleaned_count = 0;
449 /* use prefetched values */
450 rx_desc = next_rxd;
451 buffer_info = next_buffer;
453 rx_ring->next_to_clean = i;
455 cleaned_count = e1000_desc_unused(rx_ring);
456 if (cleaned_count)
457 adapter->alloc_rx_buf(adapter, cleaned_count);
459 adapter->total_rx_packets += total_rx_packets;
460 adapter->total_rx_bytes += total_rx_bytes;
461 adapter->net_stats.rx_packets += total_rx_packets;
462 adapter->net_stats.rx_bytes += total_rx_bytes;
463 return cleaned;
466 static void e1000_put_txbuf(struct e1000_adapter *adapter,
467 struct e1000_buffer *buffer_info)
469 if (buffer_info->dma) {
470 pci_unmap_page(adapter->pdev, buffer_info->dma,
471 buffer_info->length, PCI_DMA_TODEVICE);
472 buffer_info->dma = 0;
474 if (buffer_info->skb) {
475 dev_kfree_skb_any(buffer_info->skb);
476 buffer_info->skb = NULL;
480 static void e1000_print_tx_hang(struct e1000_adapter *adapter)
482 struct e1000_ring *tx_ring = adapter->tx_ring;
483 unsigned int i = tx_ring->next_to_clean;
484 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
485 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
486 struct net_device *netdev = adapter->netdev;
488 /* detected Tx unit hang */
489 ndev_err(netdev,
490 "Detected Tx Unit Hang:\n"
491 " TDH <%x>\n"
492 " TDT <%x>\n"
493 " next_to_use <%x>\n"
494 " next_to_clean <%x>\n"
495 "buffer_info[next_to_clean]:\n"
496 " time_stamp <%lx>\n"
497 " next_to_watch <%x>\n"
498 " jiffies <%lx>\n"
499 " next_to_watch.status <%x>\n",
500 readl(adapter->hw.hw_addr + tx_ring->head),
501 readl(adapter->hw.hw_addr + tx_ring->tail),
502 tx_ring->next_to_use,
503 tx_ring->next_to_clean,
504 tx_ring->buffer_info[eop].time_stamp,
505 eop,
506 jiffies,
507 eop_desc->upper.fields.status);
511 * e1000_clean_tx_irq - Reclaim resources after transmit completes
512 * @adapter: board private structure
514 * the return value indicates whether actual cleaning was done, there
515 * is no guarantee that everything was cleaned
517 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
519 struct net_device *netdev = adapter->netdev;
520 struct e1000_hw *hw = &adapter->hw;
521 struct e1000_ring *tx_ring = adapter->tx_ring;
522 struct e1000_tx_desc *tx_desc, *eop_desc;
523 struct e1000_buffer *buffer_info;
524 unsigned int i, eop;
525 unsigned int count = 0;
526 bool cleaned = 0;
527 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
529 i = tx_ring->next_to_clean;
530 eop = tx_ring->buffer_info[i].next_to_watch;
531 eop_desc = E1000_TX_DESC(*tx_ring, eop);
533 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
534 for (cleaned = 0; !cleaned; ) {
535 tx_desc = E1000_TX_DESC(*tx_ring, i);
536 buffer_info = &tx_ring->buffer_info[i];
537 cleaned = (i == eop);
539 if (cleaned) {
540 struct sk_buff *skb = buffer_info->skb;
541 unsigned int segs, bytecount;
542 segs = skb_shinfo(skb)->gso_segs ?: 1;
543 /* multiply data chunks by size of headers */
544 bytecount = ((segs - 1) * skb_headlen(skb)) +
545 skb->len;
546 total_tx_packets += segs;
547 total_tx_bytes += bytecount;
550 e1000_put_txbuf(adapter, buffer_info);
551 tx_desc->upper.data = 0;
553 i++;
554 if (i == tx_ring->count)
555 i = 0;
558 eop = tx_ring->buffer_info[i].next_to_watch;
559 eop_desc = E1000_TX_DESC(*tx_ring, eop);
560 #define E1000_TX_WEIGHT 64
561 /* weight of a sort for tx, to avoid endless transmit cleanup */
562 if (count++ == E1000_TX_WEIGHT)
563 break;
566 tx_ring->next_to_clean = i;
568 #define TX_WAKE_THRESHOLD 32
569 if (cleaned && netif_carrier_ok(netdev) &&
570 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
571 /* Make sure that anybody stopping the queue after this
572 * sees the new next_to_clean.
574 smp_mb();
576 if (netif_queue_stopped(netdev) &&
577 !(test_bit(__E1000_DOWN, &adapter->state))) {
578 netif_wake_queue(netdev);
579 ++adapter->restart_queue;
583 if (adapter->detect_tx_hung) {
584 /* Detect a transmit hang in hardware, this serializes the
585 * check with the clearing of time_stamp and movement of i */
586 adapter->detect_tx_hung = 0;
587 if (tx_ring->buffer_info[eop].dma &&
588 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp
589 + (adapter->tx_timeout_factor * HZ))
590 && !(er32(STATUS) &
591 E1000_STATUS_TXOFF)) {
592 e1000_print_tx_hang(adapter);
593 netif_stop_queue(netdev);
596 adapter->total_tx_bytes += total_tx_bytes;
597 adapter->total_tx_packets += total_tx_packets;
598 adapter->net_stats.tx_packets += total_tx_packets;
599 adapter->net_stats.tx_bytes += total_tx_bytes;
600 return cleaned;
604 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
605 * @adapter: board private structure
607 * the return value indicates whether actual cleaning was done, there
608 * is no guarantee that everything was cleaned
610 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
611 int *work_done, int work_to_do)
613 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
614 struct net_device *netdev = adapter->netdev;
615 struct pci_dev *pdev = adapter->pdev;
616 struct e1000_ring *rx_ring = adapter->rx_ring;
617 struct e1000_buffer *buffer_info, *next_buffer;
618 struct e1000_ps_page *ps_page;
619 struct sk_buff *skb;
620 unsigned int i, j;
621 u32 length, staterr;
622 int cleaned_count = 0;
623 bool cleaned = 0;
624 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
626 i = rx_ring->next_to_clean;
627 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
628 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
629 buffer_info = &rx_ring->buffer_info[i];
631 while (staterr & E1000_RXD_STAT_DD) {
632 if (*work_done >= work_to_do)
633 break;
634 (*work_done)++;
635 skb = buffer_info->skb;
637 /* in the packet split case this is header only */
638 prefetch(skb->data - NET_IP_ALIGN);
640 i++;
641 if (i == rx_ring->count)
642 i = 0;
643 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
644 prefetch(next_rxd);
646 next_buffer = &rx_ring->buffer_info[i];
648 cleaned = 1;
649 cleaned_count++;
650 pci_unmap_single(pdev, buffer_info->dma,
651 adapter->rx_ps_bsize0,
652 PCI_DMA_FROMDEVICE);
653 buffer_info->dma = 0;
655 if (!(staterr & E1000_RXD_STAT_EOP)) {
656 ndev_dbg(netdev, "%s: Packet Split buffers didn't pick "
657 "up the full packet\n", netdev->name);
658 dev_kfree_skb_irq(skb);
659 goto next_desc;
662 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
663 dev_kfree_skb_irq(skb);
664 goto next_desc;
667 length = le16_to_cpu(rx_desc->wb.middle.length0);
669 if (!length) {
670 ndev_dbg(netdev, "%s: Last part of the packet spanning"
671 " multiple descriptors\n", netdev->name);
672 dev_kfree_skb_irq(skb);
673 goto next_desc;
676 /* Good Receive */
677 skb_put(skb, length);
680 /* this looks ugly, but it seems compiler issues make it
681 more efficient than reusing j */
682 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
684 /* page alloc/put takes too long and effects small packet
685 * throughput, so unsplit small packets and save the alloc/put*/
686 if (l1 && (l1 <= copybreak) &&
687 ((length + l1) <= adapter->rx_ps_bsize0)) {
688 u8 *vaddr;
690 ps_page = &buffer_info->ps_pages[0];
692 /* there is no documentation about how to call
693 * kmap_atomic, so we can't hold the mapping
694 * very long */
695 pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
696 PAGE_SIZE, PCI_DMA_FROMDEVICE);
697 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
698 memcpy(skb_tail_pointer(skb), vaddr, l1);
699 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
700 pci_dma_sync_single_for_device(pdev, ps_page->dma,
701 PAGE_SIZE, PCI_DMA_FROMDEVICE);
703 skb_put(skb, l1);
704 goto copydone;
705 } /* if */
708 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
709 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
710 if (!length)
711 break;
713 ps_page = &buffer_info->ps_pages[j];
714 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
715 PCI_DMA_FROMDEVICE);
716 ps_page->dma = 0;
717 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
718 ps_page->page = NULL;
719 skb->len += length;
720 skb->data_len += length;
721 skb->truesize += length;
724 copydone:
725 total_rx_bytes += skb->len;
726 total_rx_packets++;
728 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
729 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
731 if (rx_desc->wb.upper.header_status &
732 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
733 adapter->rx_hdr_split++;
735 e1000_receive_skb(adapter, netdev, skb,
736 staterr, rx_desc->wb.middle.vlan);
738 next_desc:
739 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
740 buffer_info->skb = NULL;
742 /* return some buffers to hardware, one at a time is too slow */
743 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
744 adapter->alloc_rx_buf(adapter, cleaned_count);
745 cleaned_count = 0;
748 /* use prefetched values */
749 rx_desc = next_rxd;
750 buffer_info = next_buffer;
752 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
754 rx_ring->next_to_clean = i;
756 cleaned_count = e1000_desc_unused(rx_ring);
757 if (cleaned_count)
758 adapter->alloc_rx_buf(adapter, cleaned_count);
760 adapter->total_rx_packets += total_rx_packets;
761 adapter->total_rx_bytes += total_rx_bytes;
762 adapter->net_stats.rx_packets += total_rx_packets;
763 adapter->net_stats.rx_bytes += total_rx_bytes;
764 return cleaned;
768 * e1000_clean_rx_ring - Free Rx Buffers per Queue
769 * @adapter: board private structure
771 static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
773 struct e1000_ring *rx_ring = adapter->rx_ring;
774 struct e1000_buffer *buffer_info;
775 struct e1000_ps_page *ps_page;
776 struct pci_dev *pdev = adapter->pdev;
777 unsigned int i, j;
779 /* Free all the Rx ring sk_buffs */
780 for (i = 0; i < rx_ring->count; i++) {
781 buffer_info = &rx_ring->buffer_info[i];
782 if (buffer_info->dma) {
783 if (adapter->clean_rx == e1000_clean_rx_irq)
784 pci_unmap_single(pdev, buffer_info->dma,
785 adapter->rx_buffer_len,
786 PCI_DMA_FROMDEVICE);
787 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
788 pci_unmap_single(pdev, buffer_info->dma,
789 adapter->rx_ps_bsize0,
790 PCI_DMA_FROMDEVICE);
791 buffer_info->dma = 0;
794 if (buffer_info->skb) {
795 dev_kfree_skb(buffer_info->skb);
796 buffer_info->skb = NULL;
799 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
800 ps_page = &buffer_info->ps_pages[j];
801 if (!ps_page->page)
802 break;
803 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
804 PCI_DMA_FROMDEVICE);
805 ps_page->dma = 0;
806 put_page(ps_page->page);
807 ps_page->page = NULL;
811 /* there also may be some cached data from a chained receive */
812 if (rx_ring->rx_skb_top) {
813 dev_kfree_skb(rx_ring->rx_skb_top);
814 rx_ring->rx_skb_top = NULL;
817 /* Zero out the descriptor ring */
818 memset(rx_ring->desc, 0, rx_ring->size);
820 rx_ring->next_to_clean = 0;
821 rx_ring->next_to_use = 0;
823 writel(0, adapter->hw.hw_addr + rx_ring->head);
824 writel(0, adapter->hw.hw_addr + rx_ring->tail);
828 * e1000_intr_msi - Interrupt Handler
829 * @irq: interrupt number
830 * @data: pointer to a network interface device structure
832 static irqreturn_t e1000_intr_msi(int irq, void *data)
834 struct net_device *netdev = data;
835 struct e1000_adapter *adapter = netdev_priv(netdev);
836 struct e1000_hw *hw = &adapter->hw;
837 u32 icr = er32(ICR);
839 /* read ICR disables interrupts using IAM, so keep up with our
840 * enable/disable accounting */
841 atomic_inc(&adapter->irq_sem);
843 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
844 hw->mac.get_link_status = 1;
845 /* ICH8 workaround-- Call gig speed drop workaround on cable
846 * disconnect (LSC) before accessing any PHY registers */
847 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
848 (!(er32(STATUS) & E1000_STATUS_LU)))
849 e1000e_gig_downshift_workaround_ich8lan(hw);
851 /* 80003ES2LAN workaround-- For packet buffer work-around on
852 * link down event; disable receives here in the ISR and reset
853 * adapter in watchdog */
854 if (netif_carrier_ok(netdev) &&
855 adapter->flags & FLAG_RX_NEEDS_RESTART) {
856 /* disable receives */
857 u32 rctl = er32(RCTL);
858 ew32(RCTL, rctl & ~E1000_RCTL_EN);
860 /* guard against interrupt when we're going down */
861 if (!test_bit(__E1000_DOWN, &adapter->state))
862 mod_timer(&adapter->watchdog_timer, jiffies + 1);
865 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
866 adapter->total_tx_bytes = 0;
867 adapter->total_tx_packets = 0;
868 adapter->total_rx_bytes = 0;
869 adapter->total_rx_packets = 0;
870 __netif_rx_schedule(netdev, &adapter->napi);
871 } else {
872 atomic_dec(&adapter->irq_sem);
875 return IRQ_HANDLED;
879 * e1000_intr - Interrupt Handler
880 * @irq: interrupt number
881 * @data: pointer to a network interface device structure
883 static irqreturn_t e1000_intr(int irq, void *data)
885 struct net_device *netdev = data;
886 struct e1000_adapter *adapter = netdev_priv(netdev);
887 struct e1000_hw *hw = &adapter->hw;
889 u32 rctl, icr = er32(ICR);
890 if (!icr)
891 return IRQ_NONE; /* Not our interrupt */
893 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
894 * not set, then the adapter didn't send an interrupt */
895 if (!(icr & E1000_ICR_INT_ASSERTED))
896 return IRQ_NONE;
898 /* Interrupt Auto-Mask...upon reading ICR,
899 * interrupts are masked. No need for the
900 * IMC write, but it does mean we should
901 * account for it ASAP. */
902 atomic_inc(&adapter->irq_sem);
904 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
905 hw->mac.get_link_status = 1;
906 /* ICH8 workaround-- Call gig speed drop workaround on cable
907 * disconnect (LSC) before accessing any PHY registers */
908 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
909 (!(er32(STATUS) & E1000_STATUS_LU)))
910 e1000e_gig_downshift_workaround_ich8lan(hw);
912 /* 80003ES2LAN workaround--
913 * For packet buffer work-around on link down event;
914 * disable receives here in the ISR and
915 * reset adapter in watchdog
917 if (netif_carrier_ok(netdev) &&
918 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
919 /* disable receives */
920 rctl = er32(RCTL);
921 ew32(RCTL, rctl & ~E1000_RCTL_EN);
923 /* guard against interrupt when we're going down */
924 if (!test_bit(__E1000_DOWN, &adapter->state))
925 mod_timer(&adapter->watchdog_timer, jiffies + 1);
928 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
929 adapter->total_tx_bytes = 0;
930 adapter->total_tx_packets = 0;
931 adapter->total_rx_bytes = 0;
932 adapter->total_rx_packets = 0;
933 __netif_rx_schedule(netdev, &adapter->napi);
934 } else {
935 atomic_dec(&adapter->irq_sem);
938 return IRQ_HANDLED;
941 static int e1000_request_irq(struct e1000_adapter *adapter)
943 struct net_device *netdev = adapter->netdev;
944 irq_handler_t handler = e1000_intr;
945 int irq_flags = IRQF_SHARED;
946 int err;
948 if (!pci_enable_msi(adapter->pdev)) {
949 adapter->flags |= FLAG_MSI_ENABLED;
950 handler = e1000_intr_msi;
951 irq_flags = 0;
954 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
955 netdev);
956 if (err) {
957 ndev_err(netdev,
958 "Unable to allocate %s interrupt (return: %d)\n",
959 adapter->flags & FLAG_MSI_ENABLED ? "MSI":"INTx",
960 err);
961 if (adapter->flags & FLAG_MSI_ENABLED)
962 pci_disable_msi(adapter->pdev);
965 return err;
968 static void e1000_free_irq(struct e1000_adapter *adapter)
970 struct net_device *netdev = adapter->netdev;
972 free_irq(adapter->pdev->irq, netdev);
973 if (adapter->flags & FLAG_MSI_ENABLED) {
974 pci_disable_msi(adapter->pdev);
975 adapter->flags &= ~FLAG_MSI_ENABLED;
980 * e1000_irq_disable - Mask off interrupt generation on the NIC
982 static void e1000_irq_disable(struct e1000_adapter *adapter)
984 struct e1000_hw *hw = &adapter->hw;
986 atomic_inc(&adapter->irq_sem);
987 ew32(IMC, ~0);
988 e1e_flush();
989 synchronize_irq(adapter->pdev->irq);
993 * e1000_irq_enable - Enable default interrupt generation settings
995 static void e1000_irq_enable(struct e1000_adapter *adapter)
997 struct e1000_hw *hw = &adapter->hw;
999 if (atomic_dec_and_test(&adapter->irq_sem)) {
1000 ew32(IMS, IMS_ENABLE_MASK);
1001 e1e_flush();
1006 * e1000_get_hw_control - get control of the h/w from f/w
1007 * @adapter: address of board private structure
1009 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
1010 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
1011 =======
1012 * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1013 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
1014 * For ASF and Pass Through versions of f/w this means that
1015 * the driver is loaded. For AMT version (only with 82573)
1016 * of the f/w this means that the network i/f is open.
1018 static void e1000_get_hw_control(struct e1000_adapter *adapter)
1020 struct e1000_hw *hw = &adapter->hw;
1021 u32 ctrl_ext;
1022 u32 swsm;
1024 /* Let firmware know the driver has taken over */
1025 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1026 swsm = er32(SWSM);
1027 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1028 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1029 ctrl_ext = er32(CTRL_EXT);
1030 ew32(CTRL_EXT,
1031 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1036 * e1000_release_hw_control - release control of the h/w to f/w
1037 * @adapter: address of board private structure
1039 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
1040 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
1041 =======
1042 * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1043 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
1044 * For ASF and Pass Through versions of f/w this means that the
1045 * driver is no longer loaded. For AMT version (only with 82573) i
1046 * of the f/w this means that the network i/f is closed.
1049 static void e1000_release_hw_control(struct e1000_adapter *adapter)
1051 struct e1000_hw *hw = &adapter->hw;
1052 u32 ctrl_ext;
1053 u32 swsm;
1055 /* Let firmware taken over control of h/w */
1056 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1057 swsm = er32(SWSM);
1058 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1059 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1060 ctrl_ext = er32(CTRL_EXT);
1061 ew32(CTRL_EXT,
1062 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1066 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
1067 static void e1000_release_manageability(struct e1000_adapter *adapter)
1069 if (adapter->flags & FLAG_MNG_PT_ENABLED) {
1070 struct e1000_hw *hw = &adapter->hw;
1072 u32 manc = er32(MANC);
1074 /* re-enable hardware interception of ARP */
1075 manc |= E1000_MANC_ARP_EN;
1076 manc &= ~E1000_MANC_EN_MNG2HOST;
1078 /* don't explicitly have to mess with MANC2H since
1079 * MANC has an enable disable that gates MANC2H */
1080 ew32(MANC, manc);
1084 =======
1085 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
1087 * @e1000_alloc_ring - allocate memory for a ring structure
1089 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
1090 struct e1000_ring *ring)
1092 struct pci_dev *pdev = adapter->pdev;
1094 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
1095 GFP_KERNEL);
1096 if (!ring->desc)
1097 return -ENOMEM;
1099 return 0;
1103 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1104 * @adapter: board private structure
1106 * Return 0 on success, negative on failure
1108 int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
1110 struct e1000_ring *tx_ring = adapter->tx_ring;
1111 int err = -ENOMEM, size;
1113 size = sizeof(struct e1000_buffer) * tx_ring->count;
1114 tx_ring->buffer_info = vmalloc(size);
1115 if (!tx_ring->buffer_info)
1116 goto err;
1117 memset(tx_ring->buffer_info, 0, size);
1119 /* round up to nearest 4K */
1120 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1121 tx_ring->size = ALIGN(tx_ring->size, 4096);
1123 err = e1000_alloc_ring_dma(adapter, tx_ring);
1124 if (err)
1125 goto err;
1127 tx_ring->next_to_use = 0;
1128 tx_ring->next_to_clean = 0;
1129 spin_lock_init(&adapter->tx_queue_lock);
1131 return 0;
1132 err:
1133 vfree(tx_ring->buffer_info);
1134 ndev_err(adapter->netdev,
1135 "Unable to allocate memory for the transmit descriptor ring\n");
1136 return err;
1140 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1141 * @adapter: board private structure
1143 * Returns 0 on success, negative on failure
1145 int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
1147 struct e1000_ring *rx_ring = adapter->rx_ring;
1148 struct e1000_buffer *buffer_info;
1149 int i, size, desc_len, err = -ENOMEM;
1151 size = sizeof(struct e1000_buffer) * rx_ring->count;
1152 rx_ring->buffer_info = vmalloc(size);
1153 if (!rx_ring->buffer_info)
1154 goto err;
1155 memset(rx_ring->buffer_info, 0, size);
1157 for (i = 0; i < rx_ring->count; i++) {
1158 buffer_info = &rx_ring->buffer_info[i];
1159 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
1160 sizeof(struct e1000_ps_page),
1161 GFP_KERNEL);
1162 if (!buffer_info->ps_pages)
1163 goto err_pages;
1166 desc_len = sizeof(union e1000_rx_desc_packet_split);
1168 /* Round up to nearest 4K */
1169 rx_ring->size = rx_ring->count * desc_len;
1170 rx_ring->size = ALIGN(rx_ring->size, 4096);
1172 err = e1000_alloc_ring_dma(adapter, rx_ring);
1173 if (err)
1174 goto err_pages;
1176 rx_ring->next_to_clean = 0;
1177 rx_ring->next_to_use = 0;
1178 rx_ring->rx_skb_top = NULL;
1180 return 0;
1182 err_pages:
1183 for (i = 0; i < rx_ring->count; i++) {
1184 buffer_info = &rx_ring->buffer_info[i];
1185 kfree(buffer_info->ps_pages);
1187 err:
1188 vfree(rx_ring->buffer_info);
1189 ndev_err(adapter->netdev,
1190 "Unable to allocate memory for the transmit descriptor ring\n");
1191 return err;
1195 * e1000_clean_tx_ring - Free Tx Buffers
1196 * @adapter: board private structure
1198 static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
1200 struct e1000_ring *tx_ring = adapter->tx_ring;
1201 struct e1000_buffer *buffer_info;
1202 unsigned long size;
1203 unsigned int i;
1205 for (i = 0; i < tx_ring->count; i++) {
1206 buffer_info = &tx_ring->buffer_info[i];
1207 e1000_put_txbuf(adapter, buffer_info);
1210 size = sizeof(struct e1000_buffer) * tx_ring->count;
1211 memset(tx_ring->buffer_info, 0, size);
1213 memset(tx_ring->desc, 0, tx_ring->size);
1215 tx_ring->next_to_use = 0;
1216 tx_ring->next_to_clean = 0;
1218 writel(0, adapter->hw.hw_addr + tx_ring->head);
1219 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1223 * e1000e_free_tx_resources - Free Tx Resources per Queue
1224 * @adapter: board private structure
1226 * Free all transmit software resources
1228 void e1000e_free_tx_resources(struct e1000_adapter *adapter)
1230 struct pci_dev *pdev = adapter->pdev;
1231 struct e1000_ring *tx_ring = adapter->tx_ring;
1233 e1000_clean_tx_ring(adapter);
1235 vfree(tx_ring->buffer_info);
1236 tx_ring->buffer_info = NULL;
1238 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1239 tx_ring->dma);
1240 tx_ring->desc = NULL;
1244 * e1000e_free_rx_resources - Free Rx Resources
1245 * @adapter: board private structure
1247 * Free all receive software resources
1250 void e1000e_free_rx_resources(struct e1000_adapter *adapter)
1252 struct pci_dev *pdev = adapter->pdev;
1253 struct e1000_ring *rx_ring = adapter->rx_ring;
1254 int i;
1256 e1000_clean_rx_ring(adapter);
1258 for (i = 0; i < rx_ring->count; i++) {
1259 kfree(rx_ring->buffer_info[i].ps_pages);
1262 vfree(rx_ring->buffer_info);
1263 rx_ring->buffer_info = NULL;
1265 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1266 rx_ring->dma);
1267 rx_ring->desc = NULL;
1271 * e1000_update_itr - update the dynamic ITR value based on statistics
1272 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
1273 =======
1274 * @adapter: pointer to adapter
1275 * @itr_setting: current adapter->itr
1276 * @packets: the number of packets during this measurement interval
1277 * @bytes: the number of bytes during this measurement interval
1279 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
1280 * Stores a new ITR value based on packets and byte
1281 * counts during the last interrupt. The advantage of per interrupt
1282 * computation is faster updates and more accurate ITR for the current
1283 * traffic pattern. Constants in this function were computed
1284 * based on theoretical maximum wire speed and thresholds were set based
1285 * on testing data as well as attempting to minimize response time
1286 * while increasing bulk throughput.
1287 * this functionality is controlled by the InterruptThrottleRate module
1288 * parameter (see e1000_param.c)
1289 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
1290 * @adapter: pointer to adapter
1291 * @itr_setting: current adapter->itr
1292 * @packets: the number of packets during this measurement interval
1293 * @bytes: the number of bytes during this measurement interval
1294 =======
1295 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
1297 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
1298 u16 itr_setting, int packets,
1299 int bytes)
1301 unsigned int retval = itr_setting;
1303 if (packets == 0)
1304 goto update_itr_done;
1306 switch (itr_setting) {
1307 case lowest_latency:
1308 /* handle TSO and jumbo frames */
1309 if (bytes/packets > 8000)
1310 retval = bulk_latency;
1311 else if ((packets < 5) && (bytes > 512)) {
1312 retval = low_latency;
1314 break;
1315 case low_latency: /* 50 usec aka 20000 ints/s */
1316 if (bytes > 10000) {
1317 /* this if handles the TSO accounting */
1318 if (bytes/packets > 8000) {
1319 retval = bulk_latency;
1320 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
1321 retval = bulk_latency;
1322 } else if ((packets > 35)) {
1323 retval = lowest_latency;
1325 } else if (bytes/packets > 2000) {
1326 retval = bulk_latency;
1327 } else if (packets <= 2 && bytes < 512) {
1328 retval = lowest_latency;
1330 break;
1331 case bulk_latency: /* 250 usec aka 4000 ints/s */
1332 if (bytes > 25000) {
1333 if (packets > 35) {
1334 retval = low_latency;
1336 } else if (bytes < 6000) {
1337 retval = low_latency;
1339 break;
1342 update_itr_done:
1343 return retval;
1346 static void e1000_set_itr(struct e1000_adapter *adapter)
1348 struct e1000_hw *hw = &adapter->hw;
1349 u16 current_itr;
1350 u32 new_itr = adapter->itr;
1352 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1353 if (adapter->link_speed != SPEED_1000) {
1354 current_itr = 0;
1355 new_itr = 4000;
1356 goto set_itr_now;
1359 adapter->tx_itr = e1000_update_itr(adapter,
1360 adapter->tx_itr,
1361 adapter->total_tx_packets,
1362 adapter->total_tx_bytes);
1363 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1364 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
1365 adapter->tx_itr = low_latency;
1367 adapter->rx_itr = e1000_update_itr(adapter,
1368 adapter->rx_itr,
1369 adapter->total_rx_packets,
1370 adapter->total_rx_bytes);
1371 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1372 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
1373 adapter->rx_itr = low_latency;
1375 current_itr = max(adapter->rx_itr, adapter->tx_itr);
1377 switch (current_itr) {
1378 /* counts and packets in update_itr are dependent on these numbers */
1379 case lowest_latency:
1380 new_itr = 70000;
1381 break;
1382 case low_latency:
1383 new_itr = 20000; /* aka hwitr = ~200 */
1384 break;
1385 case bulk_latency:
1386 new_itr = 4000;
1387 break;
1388 default:
1389 break;
1392 set_itr_now:
1393 if (new_itr != adapter->itr) {
1394 /* this attempts to bias the interrupt rate towards Bulk
1395 * by adding intermediate steps when interrupt rate is
1396 * increasing */
1397 new_itr = new_itr > adapter->itr ?
1398 min(adapter->itr + (new_itr >> 2), new_itr) :
1399 new_itr;
1400 adapter->itr = new_itr;
1401 ew32(ITR, 1000000000 / (new_itr * 256));
1406 * e1000_clean - NAPI Rx polling callback
1407 * @adapter: board private structure
1408 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
1409 =======
1410 * @budget: amount of packets driver is allowed to process this poll
1411 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
1413 static int e1000_clean(struct napi_struct *napi, int budget)
1415 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
1416 struct net_device *poll_dev = adapter->netdev;
1417 int tx_cleaned = 0, work_done = 0;
1419 /* Must NOT use netdev_priv macro here. */
1420 adapter = poll_dev->priv;
1422 /* e1000_clean is called per-cpu. This lock protects
1423 * tx_ring from being cleaned by multiple cpus
1424 * simultaneously. A failure obtaining the lock means
1425 * tx_ring is currently being cleaned anyway. */
1426 if (spin_trylock(&adapter->tx_queue_lock)) {
1427 tx_cleaned = e1000_clean_tx_irq(adapter);
1428 spin_unlock(&adapter->tx_queue_lock);
1431 adapter->clean_rx(adapter, &work_done, budget);
1433 if (tx_cleaned)
1434 work_done = budget;
1436 /* If budget not fully consumed, exit the polling mode */
1437 if (work_done < budget) {
1438 if (adapter->itr_setting & 3)
1439 e1000_set_itr(adapter);
1440 netif_rx_complete(poll_dev, napi);
1441 e1000_irq_enable(adapter);
1444 return work_done;
1447 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1449 struct e1000_adapter *adapter = netdev_priv(netdev);
1450 struct e1000_hw *hw = &adapter->hw;
1451 u32 vfta, index;
1453 /* don't update vlan cookie if already programmed */
1454 if ((adapter->hw.mng_cookie.status &
1455 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
1456 (vid == adapter->mng_vlan_id))
1457 return;
1458 /* add VID to filter table */
1459 index = (vid >> 5) & 0x7F;
1460 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
1461 vfta |= (1 << (vid & 0x1F));
1462 e1000e_write_vfta(hw, index, vfta);
1465 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1467 struct e1000_adapter *adapter = netdev_priv(netdev);
1468 struct e1000_hw *hw = &adapter->hw;
1469 u32 vfta, index;
1471 e1000_irq_disable(adapter);
1472 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1473 e1000_irq_enable(adapter);
1475 if ((adapter->hw.mng_cookie.status &
1476 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
1477 (vid == adapter->mng_vlan_id)) {
1478 /* release control to f/w */
1479 e1000_release_hw_control(adapter);
1480 return;
1483 /* remove VID from filter table */
1484 index = (vid >> 5) & 0x7F;
1485 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
1486 vfta &= ~(1 << (vid & 0x1F));
1487 e1000e_write_vfta(hw, index, vfta);
1490 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
1492 struct net_device *netdev = adapter->netdev;
1493 u16 vid = adapter->hw.mng_cookie.vlan_id;
1494 u16 old_vid = adapter->mng_vlan_id;
1496 if (!adapter->vlgrp)
1497 return;
1499 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
1500 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1501 if (adapter->hw.mng_cookie.status &
1502 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1503 e1000_vlan_rx_add_vid(netdev, vid);
1504 adapter->mng_vlan_id = vid;
1507 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
1508 (vid != old_vid) &&
1509 !vlan_group_get_device(adapter->vlgrp, old_vid))
1510 e1000_vlan_rx_kill_vid(netdev, old_vid);
1511 } else {
1512 adapter->mng_vlan_id = vid;
1517 static void e1000_vlan_rx_register(struct net_device *netdev,
1518 struct vlan_group *grp)
1520 struct e1000_adapter *adapter = netdev_priv(netdev);
1521 struct e1000_hw *hw = &adapter->hw;
1522 u32 ctrl, rctl;
1524 e1000_irq_disable(adapter);
1525 adapter->vlgrp = grp;
1527 if (grp) {
1528 /* enable VLAN tag insert/strip */
1529 ctrl = er32(CTRL);
1530 ctrl |= E1000_CTRL_VME;
1531 ew32(CTRL, ctrl);
1533 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
1534 /* enable VLAN receive filtering */
1535 rctl = er32(RCTL);
1536 rctl |= E1000_RCTL_VFE;
1537 rctl &= ~E1000_RCTL_CFIEN;
1538 ew32(RCTL, rctl);
1539 e1000_update_mng_vlan(adapter);
1541 } else {
1542 /* disable VLAN tag insert/strip */
1543 ctrl = er32(CTRL);
1544 ctrl &= ~E1000_CTRL_VME;
1545 ew32(CTRL, ctrl);
1547 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
1548 /* disable VLAN filtering */
1549 rctl = er32(RCTL);
1550 rctl &= ~E1000_RCTL_VFE;
1551 ew32(RCTL, rctl);
1552 if (adapter->mng_vlan_id !=
1553 (u16)E1000_MNG_VLAN_NONE) {
1554 e1000_vlan_rx_kill_vid(netdev,
1555 adapter->mng_vlan_id);
1556 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1561 e1000_irq_enable(adapter);
1564 static void e1000_restore_vlan(struct e1000_adapter *adapter)
1566 u16 vid;
1568 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1570 if (!adapter->vlgrp)
1571 return;
1573 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1574 if (!vlan_group_get_device(adapter->vlgrp, vid))
1575 continue;
1576 e1000_vlan_rx_add_vid(adapter->netdev, vid);
1580 static void e1000_init_manageability(struct e1000_adapter *adapter)
1582 struct e1000_hw *hw = &adapter->hw;
1583 u32 manc, manc2h;
1585 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
1586 return;
1588 manc = er32(MANC);
1590 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
1591 /* disable hardware interception of ARP */
1592 manc &= ~(E1000_MANC_ARP_EN);
1594 =======
1595 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
1596 /* enable receiving management packets to the host. this will probably
1597 * generate destination unreachable messages from the host OS, but
1598 * the packets will be handled on SMBUS */
1599 manc |= E1000_MANC_EN_MNG2HOST;
1600 manc2h = er32(MANC2H);
1601 #define E1000_MNG2HOST_PORT_623 (1 << 5)
1602 #define E1000_MNG2HOST_PORT_664 (1 << 6)
1603 manc2h |= E1000_MNG2HOST_PORT_623;
1604 manc2h |= E1000_MNG2HOST_PORT_664;
1605 ew32(MANC2H, manc2h);
1606 ew32(MANC, manc);
1610 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1611 * @adapter: board private structure
1613 * Configure the Tx unit of the MAC after a reset.
1615 static void e1000_configure_tx(struct e1000_adapter *adapter)
1617 struct e1000_hw *hw = &adapter->hw;
1618 struct e1000_ring *tx_ring = adapter->tx_ring;
1619 u64 tdba;
1620 u32 tdlen, tctl, tipg, tarc;
1621 u32 ipgr1, ipgr2;
1623 /* Setup the HW Tx Head and Tail descriptor pointers */
1624 tdba = tx_ring->dma;
1625 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
1626 ew32(TDBAL, (tdba & DMA_32BIT_MASK));
1627 ew32(TDBAH, (tdba >> 32));
1628 ew32(TDLEN, tdlen);
1629 ew32(TDH, 0);
1630 ew32(TDT, 0);
1631 tx_ring->head = E1000_TDH;
1632 tx_ring->tail = E1000_TDT;
1634 /* Set the default values for the Tx Inter Packet Gap timer */
1635 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
1636 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
1637 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
1639 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
1640 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
1642 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1643 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1644 ew32(TIPG, tipg);
1646 /* Set the Tx Interrupt Delay register */
1647 ew32(TIDV, adapter->tx_int_delay);
1648 /* tx irq moderation */
1649 ew32(TADV, adapter->tx_abs_int_delay);
1651 /* Program the Transmit Control Register */
1652 tctl = er32(TCTL);
1653 tctl &= ~E1000_TCTL_CT;
1654 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1655 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1657 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
1658 tarc = er32(TARC0);
1659 /* set the speed mode bit, we'll clear it if we're not at
1660 * gigabit link later */
1661 #define SPEED_MODE_BIT (1 << 21)
1662 tarc |= SPEED_MODE_BIT;
1663 ew32(TARC0, tarc);
1666 /* errata: program both queues to unweighted RR */
1667 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
1668 tarc = er32(TARC0);
1669 tarc |= 1;
1670 ew32(TARC0, tarc);
1671 tarc = er32(TARC1);
1672 tarc |= 1;
1673 ew32(TARC1, tarc);
1676 e1000e_config_collision_dist(hw);
1678 /* Setup Transmit Descriptor Settings for eop descriptor */
1679 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1681 /* only set IDE if we are delaying interrupts using the timers */
1682 if (adapter->tx_int_delay)
1683 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1685 /* enable Report Status bit */
1686 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1688 ew32(TCTL, tctl);
1690 adapter->tx_queue_len = adapter->netdev->tx_queue_len;
1694 * e1000_setup_rctl - configure the receive control registers
1695 * @adapter: Board private structure
1697 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1698 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1699 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1701 struct e1000_hw *hw = &adapter->hw;
1702 u32 rctl, rfctl;
1703 u32 psrctl = 0;
1704 u32 pages = 0;
1706 /* Program MC offset vector base */
1707 rctl = er32(RCTL);
1708 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1709 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1710 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1711 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1713 /* Do not Store bad packets */
1714 rctl &= ~E1000_RCTL_SBP;
1716 /* Enable Long Packet receive */
1717 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1718 rctl &= ~E1000_RCTL_LPE;
1719 else
1720 rctl |= E1000_RCTL_LPE;
1722 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
1723 =======
1724 /* Enable hardware CRC frame stripping */
1725 rctl |= E1000_RCTL_SECRC;
1727 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
1728 /* Setup buffer sizes */
1729 rctl &= ~E1000_RCTL_SZ_4096;
1730 rctl |= E1000_RCTL_BSEX;
1731 switch (adapter->rx_buffer_len) {
1732 case 256:
1733 rctl |= E1000_RCTL_SZ_256;
1734 rctl &= ~E1000_RCTL_BSEX;
1735 break;
1736 case 512:
1737 rctl |= E1000_RCTL_SZ_512;
1738 rctl &= ~E1000_RCTL_BSEX;
1739 break;
1740 case 1024:
1741 rctl |= E1000_RCTL_SZ_1024;
1742 rctl &= ~E1000_RCTL_BSEX;
1743 break;
1744 case 2048:
1745 default:
1746 rctl |= E1000_RCTL_SZ_2048;
1747 rctl &= ~E1000_RCTL_BSEX;
1748 break;
1749 case 4096:
1750 rctl |= E1000_RCTL_SZ_4096;
1751 break;
1752 case 8192:
1753 rctl |= E1000_RCTL_SZ_8192;
1754 break;
1755 case 16384:
1756 rctl |= E1000_RCTL_SZ_16384;
1757 break;
1761 * 82571 and greater support packet-split where the protocol
1762 * header is placed in skb->data and the packet data is
1763 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1764 * In the case of a non-split, skb->data is linearly filled,
1765 * followed by the page buffers. Therefore, skb->data is
1766 * sized to hold the largest protocol header.
1768 * allocations using alloc_page take too long for regular MTU
1769 * so only enable packet split for jumbo frames
1771 * Using pages when the page size is greater than 16k wastes
1772 * a lot of memory, since we allocate 3 pages at all times
1773 * per packet.
1775 adapter->rx_ps_pages = 0;
1776 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1777 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
1778 adapter->rx_ps_pages = pages;
1780 if (adapter->rx_ps_pages) {
1781 /* Configure extra packet-split registers */
1782 rfctl = er32(RFCTL);
1783 rfctl |= E1000_RFCTL_EXTEN;
1784 /* disable packet split support for IPv6 extension headers,
1785 * because some malformed IPv6 headers can hang the RX */
1786 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1787 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1789 ew32(RFCTL, rfctl);
1791 /* Enable Packet split descriptors */
1792 rctl |= E1000_RCTL_DTYP_PS;
1793 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
1795 /* Enable hardware CRC frame stripping */
1796 rctl |= E1000_RCTL_SECRC;
1797 =======
1798 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
1800 psrctl |= adapter->rx_ps_bsize0 >>
1801 E1000_PSRCTL_BSIZE0_SHIFT;
1803 switch (adapter->rx_ps_pages) {
1804 case 3:
1805 psrctl |= PAGE_SIZE <<
1806 E1000_PSRCTL_BSIZE3_SHIFT;
1807 case 2:
1808 psrctl |= PAGE_SIZE <<
1809 E1000_PSRCTL_BSIZE2_SHIFT;
1810 case 1:
1811 psrctl |= PAGE_SIZE >>
1812 E1000_PSRCTL_BSIZE1_SHIFT;
1813 break;
1816 ew32(PSRCTL, psrctl);
1819 ew32(RCTL, rctl);
1823 * e1000_configure_rx - Configure Receive Unit after Reset
1824 * @adapter: board private structure
1826 * Configure the Rx unit of the MAC after a reset.
1828 static void e1000_configure_rx(struct e1000_adapter *adapter)
1830 struct e1000_hw *hw = &adapter->hw;
1831 struct e1000_ring *rx_ring = adapter->rx_ring;
1832 u64 rdba;
1833 u32 rdlen, rctl, rxcsum, ctrl_ext;
1835 if (adapter->rx_ps_pages) {
1836 /* this is a 32 byte descriptor */
1837 rdlen = rx_ring->count *
1838 sizeof(union e1000_rx_desc_packet_split);
1839 adapter->clean_rx = e1000_clean_rx_irq_ps;
1840 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1841 } else {
1842 rdlen = rx_ring->count *
1843 sizeof(struct e1000_rx_desc);
1844 adapter->clean_rx = e1000_clean_rx_irq;
1845 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1848 /* disable receives while setting up the descriptors */
1849 rctl = er32(RCTL);
1850 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1851 e1e_flush();
1852 msleep(10);
1854 /* set the Receive Delay Timer Register */
1855 ew32(RDTR, adapter->rx_int_delay);
1857 /* irq moderation */
1858 ew32(RADV, adapter->rx_abs_int_delay);
1859 if (adapter->itr_setting != 0)
1860 ew32(ITR,
1861 1000000000 / (adapter->itr * 256));
1863 ctrl_ext = er32(CTRL_EXT);
1864 /* Reset delay timers after every interrupt */
1865 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
1866 /* Auto-Mask interrupts upon ICR access */
1867 ctrl_ext |= E1000_CTRL_EXT_IAME;
1868 ew32(IAM, 0xffffffff);
1869 ew32(CTRL_EXT, ctrl_ext);
1870 e1e_flush();
1872 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1873 * the Base and Length of the Rx Descriptor Ring */
1874 rdba = rx_ring->dma;
1875 ew32(RDBAL, (rdba & DMA_32BIT_MASK));
1876 ew32(RDBAH, (rdba >> 32));
1877 ew32(RDLEN, rdlen);
1878 ew32(RDH, 0);
1879 ew32(RDT, 0);
1880 rx_ring->head = E1000_RDH;
1881 rx_ring->tail = E1000_RDT;
1883 /* Enable Receive Checksum Offload for TCP and UDP */
1884 rxcsum = er32(RXCSUM);
1885 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
1886 rxcsum |= E1000_RXCSUM_TUOFL;
1888 /* IPv4 payload checksum for UDP fragments must be
1889 * used in conjunction with packet-split. */
1890 if (adapter->rx_ps_pages)
1891 rxcsum |= E1000_RXCSUM_IPPCSE;
1892 } else {
1893 rxcsum &= ~E1000_RXCSUM_TUOFL;
1894 /* no need to clear IPPCSE as it defaults to 0 */
1896 ew32(RXCSUM, rxcsum);
1898 /* Enable early receives on supported devices, only takes effect when
1899 * packet size is equal or larger than the specified value (in 8 byte
1900 * units), e.g. using jumbo frames when setting to E1000_ERT_2048 */
1901 if ((adapter->flags & FLAG_HAS_ERT) &&
1902 (adapter->netdev->mtu > ETH_DATA_LEN))
1903 ew32(ERT, E1000_ERT_2048);
1905 /* Enable Receives */
1906 ew32(RCTL, rctl);
1910 * e1000_mc_addr_list_update - Update Multicast addresses
1911 * @hw: pointer to the HW structure
1912 * @mc_addr_list: array of multicast addresses to program
1913 * @mc_addr_count: number of multicast addresses to program
1914 * @rar_used_count: the first RAR register free to program
1915 * @rar_count: total number of supported Receive Address Registers
1917 * Updates the Receive Address Registers and Multicast Table Array.
1918 * The caller must have a packed mc_addr_list of multicast addresses.
1919 * The parameter rar_count will usually be hw->mac.rar_entry_count
1920 * unless there are workarounds that change this. Currently no func pointer
1921 * exists and all implementations are handled in the generic version of this
1922 * function.
1924 static void e1000_mc_addr_list_update(struct e1000_hw *hw, u8 *mc_addr_list,
1925 u32 mc_addr_count, u32 rar_used_count,
1926 u32 rar_count)
1928 hw->mac.ops.mc_addr_list_update(hw, mc_addr_list, mc_addr_count,
1929 rar_used_count, rar_count);
1933 * e1000_set_multi - Multicast and Promiscuous mode set
1934 * @netdev: network interface device structure
1936 * The set_multi entry point is called whenever the multicast address
1937 * list or the network interface flags are updated. This routine is
1938 * responsible for configuring the hardware for proper multicast,
1939 * promiscuous mode, and all-multi behavior.
1941 static void e1000_set_multi(struct net_device *netdev)
1943 struct e1000_adapter *adapter = netdev_priv(netdev);
1944 struct e1000_hw *hw = &adapter->hw;
1945 struct e1000_mac_info *mac = &hw->mac;
1946 struct dev_mc_list *mc_ptr;
1947 u8 *mta_list;
1948 u32 rctl;
1949 int i;
1951 /* Check for Promiscuous and All Multicast modes */
1953 rctl = er32(RCTL);
1955 if (netdev->flags & IFF_PROMISC) {
1956 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1957 } else if (netdev->flags & IFF_ALLMULTI) {
1958 rctl |= E1000_RCTL_MPE;
1959 rctl &= ~E1000_RCTL_UPE;
1960 } else {
1961 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
1964 ew32(RCTL, rctl);
1966 if (netdev->mc_count) {
1967 mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);
1968 if (!mta_list)
1969 return;
1971 /* prepare a packed array of only addresses. */
1972 mc_ptr = netdev->mc_list;
1974 for (i = 0; i < netdev->mc_count; i++) {
1975 if (!mc_ptr)
1976 break;
1977 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
1978 ETH_ALEN);
1979 mc_ptr = mc_ptr->next;
1982 e1000_mc_addr_list_update(hw, mta_list, i, 1,
1983 mac->rar_entry_count);
1984 kfree(mta_list);
1985 } else {
1987 * if we're called from probe, we might not have
1988 * anything to do here, so clear out the list
1990 e1000_mc_addr_list_update(hw, NULL, 0, 1,
1991 mac->rar_entry_count);
1996 * e1000_configure - configure the hardware for RX and TX
1997 * @adapter: private board structure
1999 static void e1000_configure(struct e1000_adapter *adapter)
2001 e1000_set_multi(adapter->netdev);
2003 e1000_restore_vlan(adapter);
2004 e1000_init_manageability(adapter);
2006 e1000_configure_tx(adapter);
2007 e1000_setup_rctl(adapter);
2008 e1000_configure_rx(adapter);
2009 adapter->alloc_rx_buf(adapter,
2010 e1000_desc_unused(adapter->rx_ring));
2014 * e1000e_power_up_phy - restore link in case the phy was powered down
2015 * @adapter: address of board private structure
2017 * The phy may be powered down to save power and turn off link when the
2018 * driver is unloaded and wake on lan is not enabled (among others)
2019 * *** this routine MUST be followed by a call to e1000e_reset ***
2021 void e1000e_power_up_phy(struct e1000_adapter *adapter)
2023 u16 mii_reg = 0;
2025 /* Just clear the power down bit to wake the phy back up */
2026 if (adapter->hw.media_type == e1000_media_type_copper) {
2027 /* according to the manual, the phy will retain its
2028 * settings across a power-down/up cycle */
2029 e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);
2030 mii_reg &= ~MII_CR_POWER_DOWN;
2031 e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);
2034 adapter->hw.mac.ops.setup_link(&adapter->hw);
2038 * e1000_power_down_phy - Power down the PHY
2040 * Power down the PHY so no link is implied when interface is down
2041 * The PHY cannot be powered down is management or WoL is active
2043 static void e1000_power_down_phy(struct e1000_adapter *adapter)
2045 struct e1000_hw *hw = &adapter->hw;
2046 u16 mii_reg;
2048 /* WoL is enabled */
2049 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
2050 if (!adapter->wol)
2051 =======
2052 if (adapter->wol)
2053 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
2054 return;
2056 /* non-copper PHY? */
2057 if (adapter->hw.media_type != e1000_media_type_copper)
2058 return;
2060 /* reset is blocked because of a SoL/IDER session */
2061 if (e1000e_check_mng_mode(hw) ||
2062 e1000_check_reset_block(hw))
2063 return;
2065 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
2066 /* managebility (AMT) is enabled */
2067 =======
2068 /* manageability (AMT) is enabled */
2069 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
2070 if (er32(MANC) & E1000_MANC_SMBUS_EN)
2071 return;
2073 /* power down the PHY */
2074 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2075 mii_reg |= MII_CR_POWER_DOWN;
2076 e1e_wphy(hw, PHY_CONTROL, mii_reg);
2077 mdelay(1);
2081 * e1000e_reset - bring the hardware into a known good state
2083 * This function boots the hardware and enables some settings that
2084 * require a configuration cycle of the hardware - those cannot be
2085 * set/changed during runtime. After reset the device needs to be
2086 * properly configured for rx, tx etc.
2088 void e1000e_reset(struct e1000_adapter *adapter)
2090 struct e1000_mac_info *mac = &adapter->hw.mac;
2091 struct e1000_hw *hw = &adapter->hw;
2092 u32 tx_space, min_tx_space, min_rx_space;
2093 u32 pba;
2094 u16 hwm;
2096 ew32(PBA, adapter->pba);
2098 if (mac->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN ) {
2099 /* To maintain wire speed transmits, the Tx FIFO should be
2100 * large enough to accommodate two full transmit packets,
2101 * rounded up to the next 1KB and expressed in KB. Likewise,
2102 * the Rx FIFO should be large enough to accommodate at least
2103 * one full receive packet and is similarly rounded up and
2104 * expressed in KB. */
2105 pba = er32(PBA);
2106 /* upper 16 bits has Tx packet buffer allocation size in KB */
2107 tx_space = pba >> 16;
2108 /* lower 16 bits has Rx packet buffer allocation size in KB */
2109 pba &= 0xffff;
2110 /* the tx fifo also stores 16 bytes of information about the tx
2111 * but don't include ethernet FCS because hardware appends it */
2112 min_tx_space = (mac->max_frame_size +
2113 sizeof(struct e1000_tx_desc) -
2114 ETH_FCS_LEN) * 2;
2115 min_tx_space = ALIGN(min_tx_space, 1024);
2116 min_tx_space >>= 10;
2117 /* software strips receive CRC, so leave room for it */
2118 min_rx_space = mac->max_frame_size;
2119 min_rx_space = ALIGN(min_rx_space, 1024);
2120 min_rx_space >>= 10;
2122 /* If current Tx allocation is less than the min Tx FIFO size,
2123 * and the min Tx FIFO size is less than the current Rx FIFO
2124 * allocation, take space away from current Rx allocation */
2125 if ((tx_space < min_tx_space) &&
2126 ((min_tx_space - tx_space) < pba)) {
2127 pba -= min_tx_space - tx_space;
2129 /* if short on rx space, rx wins and must trump tx
2130 * adjustment or use Early Receive if available */
2131 if ((pba < min_rx_space) &&
2132 (!(adapter->flags & FLAG_HAS_ERT)))
2133 /* ERT enabled in e1000_configure_rx */
2134 pba = min_rx_space;
2137 ew32(PBA, pba);
2141 /* flow control settings */
2142 /* The high water mark must be low enough to fit one full frame
2143 * (or the size used for early receive) above it in the Rx FIFO.
2144 * Set it to the lower of:
2145 * - 90% of the Rx FIFO size, and
2146 * - the full Rx FIFO size minus the early receive size (for parts
2147 * with ERT support assuming ERT set to E1000_ERT_2048), or
2148 * - the full Rx FIFO size minus one full frame */
2149 if (adapter->flags & FLAG_HAS_ERT)
2150 hwm = min(((adapter->pba << 10) * 9 / 10),
2151 ((adapter->pba << 10) - (E1000_ERT_2048 << 3)));
2152 else
2153 hwm = min(((adapter->pba << 10) * 9 / 10),
2154 ((adapter->pba << 10) - mac->max_frame_size));
2156 mac->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
2157 mac->fc_low_water = mac->fc_high_water - 8;
2159 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
2160 mac->fc_pause_time = 0xFFFF;
2161 else
2162 mac->fc_pause_time = E1000_FC_PAUSE_TIME;
2163 mac->fc = mac->original_fc;
2165 /* Allow time for pending master requests to run */
2166 mac->ops.reset_hw(hw);
2167 ew32(WUC, 0);
2169 if (mac->ops.init_hw(hw))
2170 ndev_err(adapter->netdev, "Hardware Error\n");
2172 e1000_update_mng_vlan(adapter);
2174 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2175 ew32(VET, ETH_P_8021Q);
2177 e1000e_reset_adaptive(hw);
2178 e1000_get_phy_info(hw);
2180 if (!(adapter->flags & FLAG_SMART_POWER_DOWN)) {
2181 u16 phy_data = 0;
2182 /* speed up time to link by disabling smart power down, ignore
2183 * the return value of this function because there is nothing
2184 * different we would do if it failed */
2185 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
2186 phy_data &= ~IGP02E1000_PM_SPD;
2187 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
2189 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
2191 e1000_release_manageability(adapter);
2192 =======
2193 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
2196 int e1000e_up(struct e1000_adapter *adapter)
2198 struct e1000_hw *hw = &adapter->hw;
2200 /* hardware has been reset, we need to reload some things */
2201 e1000_configure(adapter);
2203 clear_bit(__E1000_DOWN, &adapter->state);
2205 napi_enable(&adapter->napi);
2206 e1000_irq_enable(adapter);
2208 /* fire a link change interrupt to start the watchdog */
2209 ew32(ICS, E1000_ICS_LSC);
2210 return 0;
2213 void e1000e_down(struct e1000_adapter *adapter)
2215 struct net_device *netdev = adapter->netdev;
2216 struct e1000_hw *hw = &adapter->hw;
2217 u32 tctl, rctl;
2219 /* signal that we're down so the interrupt handler does not
2220 * reschedule our watchdog timer */
2221 set_bit(__E1000_DOWN, &adapter->state);
2223 /* disable receives in the hardware */
2224 rctl = er32(RCTL);
2225 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2226 /* flush and sleep below */
2228 netif_stop_queue(netdev);
2230 /* disable transmits in the hardware */
2231 tctl = er32(TCTL);
2232 tctl &= ~E1000_TCTL_EN;
2233 ew32(TCTL, tctl);
2234 /* flush both disables and wait for them to finish */
2235 e1e_flush();
2236 msleep(10);
2238 napi_disable(&adapter->napi);
2239 atomic_set(&adapter->irq_sem, 0);
2240 e1000_irq_disable(adapter);
2242 del_timer_sync(&adapter->watchdog_timer);
2243 del_timer_sync(&adapter->phy_info_timer);
2245 netdev->tx_queue_len = adapter->tx_queue_len;
2246 netif_carrier_off(netdev);
2247 adapter->link_speed = 0;
2248 adapter->link_duplex = 0;
2250 e1000e_reset(adapter);
2251 e1000_clean_tx_ring(adapter);
2252 e1000_clean_rx_ring(adapter);
2255 * TODO: for power management, we could drop the link and
2256 * pci_disable_device here.
2260 void e1000e_reinit_locked(struct e1000_adapter *adapter)
2262 might_sleep();
2263 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
2264 msleep(1);
2265 e1000e_down(adapter);
2266 e1000e_up(adapter);
2267 clear_bit(__E1000_RESETTING, &adapter->state);
2271 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2272 * @adapter: board private structure to initialize
2274 * e1000_sw_init initializes the Adapter private data structure.
2275 * Fields are initialized based on PCI device information and
2276 * OS network device settings (MTU size).
2278 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
2280 struct e1000_hw *hw = &adapter->hw;
2281 struct net_device *netdev = adapter->netdev;
2283 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
2284 adapter->rx_ps_bsize0 = 128;
2285 hw->mac.max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2286 hw->mac.min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
2288 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2289 if (!adapter->tx_ring)
2290 goto err;
2292 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2293 if (!adapter->rx_ring)
2294 goto err;
2296 spin_lock_init(&adapter->tx_queue_lock);
2298 /* Explicitly disable IRQ since the NIC can be in any state. */
2299 atomic_set(&adapter->irq_sem, 0);
2300 e1000_irq_disable(adapter);
2302 spin_lock_init(&adapter->stats_lock);
2304 set_bit(__E1000_DOWN, &adapter->state);
2305 return 0;
2307 err:
2308 ndev_err(netdev, "Unable to allocate memory for queues\n");
2309 kfree(adapter->rx_ring);
2310 kfree(adapter->tx_ring);
2311 return -ENOMEM;
2315 * e1000_open - Called when a network interface is made active
2316 * @netdev: network interface device structure
2318 * Returns 0 on success, negative value on failure
2320 * The open entry point is called when a network interface is made
2321 * active by the system (IFF_UP). At this point all resources needed
2322 * for transmit and receive operations are allocated, the interrupt
2323 * handler is registered with the OS, the watchdog timer is started,
2324 * and the stack is notified that the interface is ready.
2326 static int e1000_open(struct net_device *netdev)
2328 struct e1000_adapter *adapter = netdev_priv(netdev);
2329 struct e1000_hw *hw = &adapter->hw;
2330 int err;
2332 /* disallow open during test */
2333 if (test_bit(__E1000_TESTING, &adapter->state))
2334 return -EBUSY;
2336 /* allocate transmit descriptors */
2337 err = e1000e_setup_tx_resources(adapter);
2338 if (err)
2339 goto err_setup_tx;
2341 /* allocate receive descriptors */
2342 err = e1000e_setup_rx_resources(adapter);
2343 if (err)
2344 goto err_setup_rx;
2346 e1000e_power_up_phy(adapter);
2348 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2349 if ((adapter->hw.mng_cookie.status &
2350 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
2351 e1000_update_mng_vlan(adapter);
2353 /* If AMT is enabled, let the firmware know that the network
2354 * interface is now open */
2355 if ((adapter->flags & FLAG_HAS_AMT) &&
2356 e1000e_check_mng_mode(&adapter->hw))
2357 e1000_get_hw_control(adapter);
2359 /* before we allocate an interrupt, we must be ready to handle it.
2360 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
2361 * as soon as we call pci_request_irq, so we have to setup our
2362 * clean_rx handler before we do so. */
2363 e1000_configure(adapter);
2365 err = e1000_request_irq(adapter);
2366 if (err)
2367 goto err_req_irq;
2369 /* From here on the code is the same as e1000e_up() */
2370 clear_bit(__E1000_DOWN, &adapter->state);
2372 napi_enable(&adapter->napi);
2374 e1000_irq_enable(adapter);
2376 /* fire a link status change interrupt to start the watchdog */
2377 ew32(ICS, E1000_ICS_LSC);
2379 return 0;
2381 err_req_irq:
2382 e1000_release_hw_control(adapter);
2383 e1000_power_down_phy(adapter);
2384 e1000e_free_rx_resources(adapter);
2385 err_setup_rx:
2386 e1000e_free_tx_resources(adapter);
2387 err_setup_tx:
2388 e1000e_reset(adapter);
2390 return err;
2394 * e1000_close - Disables a network interface
2395 * @netdev: network interface device structure
2397 * Returns 0, this is not allowed to fail
2399 * The close entry point is called when an interface is de-activated
2400 * by the OS. The hardware is still under the drivers control, but
2401 * needs to be disabled. A global MAC reset is issued to stop the
2402 * hardware, and all transmit and receive resources are freed.
2404 static int e1000_close(struct net_device *netdev)
2406 struct e1000_adapter *adapter = netdev_priv(netdev);
2408 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
2409 e1000e_down(adapter);
2410 e1000_power_down_phy(adapter);
2411 e1000_free_irq(adapter);
2413 e1000e_free_tx_resources(adapter);
2414 e1000e_free_rx_resources(adapter);
2416 /* kill manageability vlan ID if supported, but not if a vlan with
2417 * the same ID is registered on the host OS (let 8021q kill it) */
2418 if ((adapter->hw.mng_cookie.status &
2419 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2420 !(adapter->vlgrp &&
2421 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
2422 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2424 /* If AMT is enabled, let the firmware know that the network
2425 * interface is now closed */
2426 if ((adapter->flags & FLAG_HAS_AMT) &&
2427 e1000e_check_mng_mode(&adapter->hw))
2428 e1000_release_hw_control(adapter);
2430 return 0;
2433 * e1000_set_mac - Change the Ethernet Address of the NIC
2434 * @netdev: network interface device structure
2435 * @p: pointer to an address structure
2437 * Returns 0 on success, negative on failure
2439 static int e1000_set_mac(struct net_device *netdev, void *p)
2441 struct e1000_adapter *adapter = netdev_priv(netdev);
2442 struct sockaddr *addr = p;
2444 if (!is_valid_ether_addr(addr->sa_data))
2445 return -EADDRNOTAVAIL;
2447 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2448 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
2450 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
2452 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
2453 /* activate the work around */
2454 e1000e_set_laa_state_82571(&adapter->hw, 1);
2456 /* Hold a copy of the LAA in RAR[14] This is done so that
2457 * between the time RAR[0] gets clobbered and the time it
2458 * gets fixed (in e1000_watchdog), the actual LAA is in one
2459 * of the RARs and no incoming packets directed to this port
2460 * are dropped. Eventually the LAA will be in RAR[0] and
2461 * RAR[14] */
2462 e1000e_rar_set(&adapter->hw,
2463 adapter->hw.mac.addr,
2464 adapter->hw.mac.rar_entry_count - 1);
2467 return 0;
2470 /* Need to wait a few seconds after link up to get diagnostic information from
2471 * the phy */
2472 static void e1000_update_phy_info(unsigned long data)
2474 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2475 e1000_get_phy_info(&adapter->hw);
2479 * e1000e_update_stats - Update the board statistics counters
2480 * @adapter: board private structure
2482 void e1000e_update_stats(struct e1000_adapter *adapter)
2484 struct e1000_hw *hw = &adapter->hw;
2485 struct pci_dev *pdev = adapter->pdev;
2486 unsigned long irq_flags;
2487 u16 phy_tmp;
2489 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2492 * Prevent stats update while adapter is being reset, or if the pci
2493 * connection is down.
2495 if (adapter->link_speed == 0)
2496 return;
2497 if (pci_channel_offline(pdev))
2498 return;
2500 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
2502 /* these counters are modified from e1000_adjust_tbi_stats,
2503 * called from the interrupt context, so they must only
2504 * be written while holding adapter->stats_lock
2507 adapter->stats.crcerrs += er32(CRCERRS);
2508 adapter->stats.gprc += er32(GPRC);
2509 adapter->stats.gorcl += er32(GORCL);
2510 adapter->stats.gorch += er32(GORCH);
2511 adapter->stats.bprc += er32(BPRC);
2512 adapter->stats.mprc += er32(MPRC);
2513 adapter->stats.roc += er32(ROC);
2515 if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) {
2516 adapter->stats.prc64 += er32(PRC64);
2517 adapter->stats.prc127 += er32(PRC127);
2518 adapter->stats.prc255 += er32(PRC255);
2519 adapter->stats.prc511 += er32(PRC511);
2520 adapter->stats.prc1023 += er32(PRC1023);
2521 adapter->stats.prc1522 += er32(PRC1522);
2522 adapter->stats.symerrs += er32(SYMERRS);
2523 adapter->stats.sec += er32(SEC);
2526 adapter->stats.mpc += er32(MPC);
2527 adapter->stats.scc += er32(SCC);
2528 adapter->stats.ecol += er32(ECOL);
2529 adapter->stats.mcc += er32(MCC);
2530 adapter->stats.latecol += er32(LATECOL);
2531 adapter->stats.dc += er32(DC);
2532 adapter->stats.rlec += er32(RLEC);
2533 adapter->stats.xonrxc += er32(XONRXC);
2534 adapter->stats.xontxc += er32(XONTXC);
2535 adapter->stats.xoffrxc += er32(XOFFRXC);
2536 adapter->stats.xofftxc += er32(XOFFTXC);
2537 adapter->stats.fcruc += er32(FCRUC);
2538 adapter->stats.gptc += er32(GPTC);
2539 adapter->stats.gotcl += er32(GOTCL);
2540 adapter->stats.gotch += er32(GOTCH);
2541 adapter->stats.rnbc += er32(RNBC);
2542 adapter->stats.ruc += er32(RUC);
2543 adapter->stats.rfc += er32(RFC);
2544 adapter->stats.rjc += er32(RJC);
2545 adapter->stats.torl += er32(TORL);
2546 adapter->stats.torh += er32(TORH);
2547 adapter->stats.totl += er32(TOTL);
2548 adapter->stats.toth += er32(TOTH);
2549 adapter->stats.tpr += er32(TPR);
2551 if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) {
2552 adapter->stats.ptc64 += er32(PTC64);
2553 adapter->stats.ptc127 += er32(PTC127);
2554 adapter->stats.ptc255 += er32(PTC255);
2555 adapter->stats.ptc511 += er32(PTC511);
2556 adapter->stats.ptc1023 += er32(PTC1023);
2557 adapter->stats.ptc1522 += er32(PTC1522);
2560 adapter->stats.mptc += er32(MPTC);
2561 adapter->stats.bptc += er32(BPTC);
2563 /* used for adaptive IFS */
2565 hw->mac.tx_packet_delta = er32(TPT);
2566 adapter->stats.tpt += hw->mac.tx_packet_delta;
2567 hw->mac.collision_delta = er32(COLC);
2568 adapter->stats.colc += hw->mac.collision_delta;
2570 adapter->stats.algnerrc += er32(ALGNERRC);
2571 adapter->stats.rxerrc += er32(RXERRC);
2572 adapter->stats.tncrs += er32(TNCRS);
2573 adapter->stats.cexterr += er32(CEXTERR);
2574 adapter->stats.tsctc += er32(TSCTC);
2575 adapter->stats.tsctfc += er32(TSCTFC);
2577 adapter->stats.iac += er32(IAC);
2579 if (adapter->flags & FLAG_HAS_STATS_ICR_ICT) {
2580 adapter->stats.icrxoc += er32(ICRXOC);
2581 adapter->stats.icrxptc += er32(ICRXPTC);
2582 adapter->stats.icrxatc += er32(ICRXATC);
2583 adapter->stats.ictxptc += er32(ICTXPTC);
2584 adapter->stats.ictxatc += er32(ICTXATC);
2585 adapter->stats.ictxqec += er32(ICTXQEC);
2586 adapter->stats.ictxqmtc += er32(ICTXQMTC);
2587 adapter->stats.icrxdmtc += er32(ICRXDMTC);
2590 /* Fill out the OS statistics structure */
2591 adapter->net_stats.multicast = adapter->stats.mprc;
2592 adapter->net_stats.collisions = adapter->stats.colc;
2594 /* Rx Errors */
2596 /* RLEC on some newer hardware can be incorrect so build
2597 * our own version based on RUC and ROC */
2598 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
2599 adapter->stats.crcerrs + adapter->stats.algnerrc +
2600 adapter->stats.ruc + adapter->stats.roc +
2601 adapter->stats.cexterr;
2602 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
2603 adapter->stats.roc;
2604 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2605 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
2606 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
2608 /* Tx Errors */
2609 adapter->net_stats.tx_errors = adapter->stats.ecol +
2610 adapter->stats.latecol;
2611 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
2612 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
2613 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
2615 /* Tx Dropped needs to be maintained elsewhere */
2617 /* Phy Stats */
2618 if (hw->media_type == e1000_media_type_copper) {
2619 if ((adapter->link_speed == SPEED_1000) &&
2620 (!e1e_rphy(hw, PHY_1000T_STATUS, &phy_tmp))) {
2621 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
2622 adapter->phy_stats.idle_errors += phy_tmp;
2626 /* Management Stats */
2627 adapter->stats.mgptc += er32(MGTPTC);
2628 adapter->stats.mgprc += er32(MGTPRC);
2629 adapter->stats.mgpdc += er32(MGTPDC);
2631 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
2634 static void e1000_print_link_info(struct e1000_adapter *adapter)
2636 struct net_device *netdev = adapter->netdev;
2637 struct e1000_hw *hw = &adapter->hw;
2638 u32 ctrl = er32(CTRL);
2640 ndev_info(netdev,
2641 "Link is Up %d Mbps %s, Flow Control: %s\n",
2642 adapter->link_speed,
2643 (adapter->link_duplex == FULL_DUPLEX) ?
2644 "Full Duplex" : "Half Duplex",
2645 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
2646 "RX/TX" :
2647 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
2648 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
2652 * e1000_watchdog - Timer Call-back
2653 * @data: pointer to adapter cast into an unsigned long
2655 static void e1000_watchdog(unsigned long data)
2657 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2659 /* Do the rest outside of interrupt context */
2660 schedule_work(&adapter->watchdog_task);
2662 /* TODO: make this use queue_delayed_work() */
2665 static void e1000_watchdog_task(struct work_struct *work)
2667 struct e1000_adapter *adapter = container_of(work,
2668 struct e1000_adapter, watchdog_task);
2670 struct net_device *netdev = adapter->netdev;
2671 struct e1000_mac_info *mac = &adapter->hw.mac;
2672 struct e1000_ring *tx_ring = adapter->tx_ring;
2673 struct e1000_hw *hw = &adapter->hw;
2674 u32 link, tctl;
2675 s32 ret_val;
2676 int tx_pending = 0;
2678 if ((netif_carrier_ok(netdev)) &&
2679 (er32(STATUS) & E1000_STATUS_LU))
2680 goto link_up;
2682 ret_val = mac->ops.check_for_link(hw);
2683 if ((ret_val == E1000_ERR_PHY) &&
2684 (adapter->hw.phy.type == e1000_phy_igp_3) &&
2685 (er32(CTRL) &
2686 E1000_PHY_CTRL_GBE_DISABLE)) {
2687 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
2688 ndev_info(netdev,
2689 "Gigabit has been disabled, downgrading speed\n");
2692 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
2693 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
2694 e1000_update_mng_vlan(adapter);
2696 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2697 !(er32(TXCW) & E1000_TXCW_ANE))
2698 link = adapter->hw.mac.serdes_has_link;
2699 else
2700 link = er32(STATUS) & E1000_STATUS_LU;
2702 if (link) {
2703 if (!netif_carrier_ok(netdev)) {
2704 bool txb2b = 1;
2705 mac->ops.get_link_up_info(&adapter->hw,
2706 &adapter->link_speed,
2707 &adapter->link_duplex);
2708 e1000_print_link_info(adapter);
2709 /* tweak tx_queue_len according to speed/duplex
2710 * and adjust the timeout factor */
2711 netdev->tx_queue_len = adapter->tx_queue_len;
2712 adapter->tx_timeout_factor = 1;
2713 switch (adapter->link_speed) {
2714 case SPEED_10:
2715 txb2b = 0;
2716 netdev->tx_queue_len = 10;
2717 adapter->tx_timeout_factor = 14;
2718 break;
2719 case SPEED_100:
2720 txb2b = 0;
2721 netdev->tx_queue_len = 100;
2722 /* maybe add some timeout factor ? */
2723 break;
2726 /* workaround: re-program speed mode bit after
2727 * link-up event */
2728 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
2729 !txb2b) {
2730 u32 tarc0;
2731 tarc0 = er32(TARC0);
2732 tarc0 &= ~SPEED_MODE_BIT;
2733 ew32(TARC0, tarc0);
2736 /* disable TSO for pcie and 10/100 speeds, to avoid
2737 * some hardware issues */
2738 if (!(adapter->flags & FLAG_TSO_FORCE)) {
2739 switch (adapter->link_speed) {
2740 case SPEED_10:
2741 case SPEED_100:
2742 ndev_info(netdev,
2743 "10/100 speed: disabling TSO\n");
2744 netdev->features &= ~NETIF_F_TSO;
2745 netdev->features &= ~NETIF_F_TSO6;
2746 break;
2747 case SPEED_1000:
2748 netdev->features |= NETIF_F_TSO;
2749 netdev->features |= NETIF_F_TSO6;
2750 break;
2751 default:
2752 /* oops */
2753 break;
2757 /* enable transmits in the hardware, need to do this
2758 * after setting TARC0 */
2759 tctl = er32(TCTL);
2760 tctl |= E1000_TCTL_EN;
2761 ew32(TCTL, tctl);
2763 netif_carrier_on(netdev);
2764 netif_wake_queue(netdev);
2766 if (!test_bit(__E1000_DOWN, &adapter->state))
2767 mod_timer(&adapter->phy_info_timer,
2768 round_jiffies(jiffies + 2 * HZ));
2769 } else {
2770 /* make sure the receive unit is started */
2771 if (adapter->flags & FLAG_RX_NEEDS_RESTART) {
2772 u32 rctl = er32(RCTL);
2773 ew32(RCTL, rctl |
2774 E1000_RCTL_EN);
2777 } else {
2778 if (netif_carrier_ok(netdev)) {
2779 adapter->link_speed = 0;
2780 adapter->link_duplex = 0;
2781 ndev_info(netdev, "Link is Down\n");
2782 netif_carrier_off(netdev);
2783 netif_stop_queue(netdev);
2784 if (!test_bit(__E1000_DOWN, &adapter->state))
2785 mod_timer(&adapter->phy_info_timer,
2786 round_jiffies(jiffies + 2 * HZ));
2788 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
2789 schedule_work(&adapter->reset_task);
2793 link_up:
2794 e1000e_update_stats(adapter);
2796 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2797 adapter->tpt_old = adapter->stats.tpt;
2798 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
2799 adapter->colc_old = adapter->stats.colc;
2801 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2802 adapter->gorcl_old = adapter->stats.gorcl;
2803 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2804 adapter->gotcl_old = adapter->stats.gotcl;
2806 e1000e_update_adaptive(&adapter->hw);
2808 if (!netif_carrier_ok(netdev)) {
2809 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
2810 tx_ring->count);
2811 if (tx_pending) {
2812 /* We've lost link, so the controller stops DMA,
2813 * but we've got queued Tx work that's never going
2814 * to get done, so reset controller to flush Tx.
2815 * (Do the reset outside of interrupt context). */
2816 adapter->tx_timeout_count++;
2817 schedule_work(&adapter->reset_task);
2821 /* Cause software interrupt to ensure rx ring is cleaned */
2822 ew32(ICS, E1000_ICS_RXDMT0);
2824 /* Force detection of hung controller every watchdog period */
2825 adapter->detect_tx_hung = 1;
2827 /* With 82571 controllers, LAA may be overwritten due to controller
2828 * reset from the other port. Set the appropriate LAA in RAR[0] */
2829 if (e1000e_get_laa_state_82571(hw))
2830 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
2832 /* Reset the timer */
2833 if (!test_bit(__E1000_DOWN, &adapter->state))
2834 mod_timer(&adapter->watchdog_timer,
2835 round_jiffies(jiffies + 2 * HZ));
2838 #define E1000_TX_FLAGS_CSUM 0x00000001
2839 #define E1000_TX_FLAGS_VLAN 0x00000002
2840 #define E1000_TX_FLAGS_TSO 0x00000004
2841 #define E1000_TX_FLAGS_IPV4 0x00000008
2842 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2843 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2845 static int e1000_tso(struct e1000_adapter *adapter,
2846 struct sk_buff *skb)
2848 struct e1000_ring *tx_ring = adapter->tx_ring;
2849 struct e1000_context_desc *context_desc;
2850 struct e1000_buffer *buffer_info;
2851 unsigned int i;
2852 u32 cmd_length = 0;
2853 u16 ipcse = 0, tucse, mss;
2854 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2855 int err;
2857 if (skb_is_gso(skb)) {
2858 if (skb_header_cloned(skb)) {
2859 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2860 if (err)
2861 return err;
2864 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2865 mss = skb_shinfo(skb)->gso_size;
2866 if (skb->protocol == htons(ETH_P_IP)) {
2867 struct iphdr *iph = ip_hdr(skb);
2868 iph->tot_len = 0;
2869 iph->check = 0;
2870 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2871 iph->daddr, 0,
2872 IPPROTO_TCP,
2874 cmd_length = E1000_TXD_CMD_IP;
2875 ipcse = skb_transport_offset(skb) - 1;
2876 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
2877 ipv6_hdr(skb)->payload_len = 0;
2878 tcp_hdr(skb)->check =
2879 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2880 &ipv6_hdr(skb)->daddr,
2881 0, IPPROTO_TCP, 0);
2882 ipcse = 0;
2884 ipcss = skb_network_offset(skb);
2885 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2886 tucss = skb_transport_offset(skb);
2887 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2888 tucse = 0;
2890 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2891 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2893 i = tx_ring->next_to_use;
2894 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2895 buffer_info = &tx_ring->buffer_info[i];
2897 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2898 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2899 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2900 context_desc->upper_setup.tcp_fields.tucss = tucss;
2901 context_desc->upper_setup.tcp_fields.tucso = tucso;
2902 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2903 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2904 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2905 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2907 buffer_info->time_stamp = jiffies;
2908 buffer_info->next_to_watch = i;
2910 i++;
2911 if (i == tx_ring->count)
2912 i = 0;
2913 tx_ring->next_to_use = i;
2915 return 1;
2918 return 0;
2921 static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
2923 struct e1000_ring *tx_ring = adapter->tx_ring;
2924 struct e1000_context_desc *context_desc;
2925 struct e1000_buffer *buffer_info;
2926 unsigned int i;
2927 u8 css;
2929 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2930 css = skb_transport_offset(skb);
2932 i = tx_ring->next_to_use;
2933 buffer_info = &tx_ring->buffer_info[i];
2934 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2936 context_desc->lower_setup.ip_config = 0;
2937 context_desc->upper_setup.tcp_fields.tucss = css;
2938 context_desc->upper_setup.tcp_fields.tucso =
2939 css + skb->csum_offset;
2940 context_desc->upper_setup.tcp_fields.tucse = 0;
2941 context_desc->tcp_seg_setup.data = 0;
2942 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2944 buffer_info->time_stamp = jiffies;
2945 buffer_info->next_to_watch = i;
2947 i++;
2948 if (i == tx_ring->count)
2949 i = 0;
2950 tx_ring->next_to_use = i;
2952 return 1;
2955 return 0;
2958 #define E1000_MAX_PER_TXD 8192
2959 #define E1000_MAX_TXD_PWR 12
2961 static int e1000_tx_map(struct e1000_adapter *adapter,
2962 struct sk_buff *skb, unsigned int first,
2963 unsigned int max_per_txd, unsigned int nr_frags,
2964 unsigned int mss)
2966 struct e1000_ring *tx_ring = adapter->tx_ring;
2967 struct e1000_buffer *buffer_info;
2968 unsigned int len = skb->len - skb->data_len;
2969 unsigned int offset = 0, size, count = 0, i;
2970 unsigned int f;
2972 i = tx_ring->next_to_use;
2974 while (len) {
2975 buffer_info = &tx_ring->buffer_info[i];
2976 size = min(len, max_per_txd);
2978 /* Workaround for premature desc write-backs
2979 * in TSO mode. Append 4-byte sentinel desc */
2980 if (mss && !nr_frags && size == len && size > 8)
2981 size -= 4;
2983 buffer_info->length = size;
2984 /* set time_stamp *before* dma to help avoid a possible race */
2985 buffer_info->time_stamp = jiffies;
2986 buffer_info->dma =
2987 pci_map_single(adapter->pdev,
2988 skb->data + offset,
2989 size,
2990 PCI_DMA_TODEVICE);
2991 if (pci_dma_mapping_error(buffer_info->dma)) {
2992 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
2993 adapter->tx_dma_failed++;
2994 return -1;
2996 buffer_info->next_to_watch = i;
2998 len -= size;
2999 offset += size;
3000 count++;
3001 i++;
3002 if (i == tx_ring->count)
3003 i = 0;
3006 for (f = 0; f < nr_frags; f++) {
3007 struct skb_frag_struct *frag;
3009 frag = &skb_shinfo(skb)->frags[f];
3010 len = frag->size;
3011 offset = frag->page_offset;
3013 while (len) {
3014 buffer_info = &tx_ring->buffer_info[i];
3015 size = min(len, max_per_txd);
3016 /* Workaround for premature desc write-backs
3017 * in TSO mode. Append 4-byte sentinel desc */
3018 if (mss && f == (nr_frags-1) && size == len && size > 8)
3019 size -= 4;
3021 buffer_info->length = size;
3022 buffer_info->time_stamp = jiffies;
3023 buffer_info->dma =
3024 pci_map_page(adapter->pdev,
3025 frag->page,
3026 offset,
3027 size,
3028 PCI_DMA_TODEVICE);
3029 if (pci_dma_mapping_error(buffer_info->dma)) {
3030 dev_err(&adapter->pdev->dev,
3031 "TX DMA page map failed\n");
3032 adapter->tx_dma_failed++;
3033 return -1;
3036 buffer_info->next_to_watch = i;
3038 len -= size;
3039 offset += size;
3040 count++;
3042 i++;
3043 if (i == tx_ring->count)
3044 i = 0;
3048 if (i == 0)
3049 i = tx_ring->count - 1;
3050 else
3051 i--;
3053 tx_ring->buffer_info[i].skb = skb;
3054 tx_ring->buffer_info[first].next_to_watch = i;
3056 return count;
3059 static void e1000_tx_queue(struct e1000_adapter *adapter,
3060 int tx_flags, int count)
3062 struct e1000_ring *tx_ring = adapter->tx_ring;
3063 struct e1000_tx_desc *tx_desc = NULL;
3064 struct e1000_buffer *buffer_info;
3065 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3066 unsigned int i;
3068 if (tx_flags & E1000_TX_FLAGS_TSO) {
3069 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3070 E1000_TXD_CMD_TSE;
3071 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3073 if (tx_flags & E1000_TX_FLAGS_IPV4)
3074 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3077 if (tx_flags & E1000_TX_FLAGS_CSUM) {
3078 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3079 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3082 if (tx_flags & E1000_TX_FLAGS_VLAN) {
3083 txd_lower |= E1000_TXD_CMD_VLE;
3084 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3087 i = tx_ring->next_to_use;
3089 while (count--) {
3090 buffer_info = &tx_ring->buffer_info[i];
3091 tx_desc = E1000_TX_DESC(*tx_ring, i);
3092 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3093 tx_desc->lower.data =
3094 cpu_to_le32(txd_lower | buffer_info->length);
3095 tx_desc->upper.data = cpu_to_le32(txd_upper);
3097 i++;
3098 if (i == tx_ring->count)
3099 i = 0;
3102 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3104 /* Force memory writes to complete before letting h/w
3105 * know there are new descriptors to fetch. (Only
3106 * applicable for weak-ordered memory model archs,
3107 * such as IA-64). */
3108 wmb();
3110 tx_ring->next_to_use = i;
3111 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3112 /* we need this if more than one processor can write to our tail
3113 * at a time, it synchronizes IO on IA64/Altix systems */
3114 mmiowb();
3117 #define MINIMUM_DHCP_PACKET_SIZE 282
3118 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3119 struct sk_buff *skb)
3121 struct e1000_hw *hw = &adapter->hw;
3122 u16 length, offset;
3124 if (vlan_tx_tag_present(skb)) {
3125 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id)
3126 && (adapter->hw.mng_cookie.status &
3127 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
3128 return 0;
3131 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
3132 return 0;
3134 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
3135 return 0;
3138 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
3139 struct udphdr *udp;
3141 if (ip->protocol != IPPROTO_UDP)
3142 return 0;
3144 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
3145 if (ntohs(udp->dest) != 67)
3146 return 0;
3148 offset = (u8 *)udp + 8 - skb->data;
3149 length = skb->len - offset;
3150 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
3153 return 0;
3156 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3158 struct e1000_adapter *adapter = netdev_priv(netdev);
3160 netif_stop_queue(netdev);
3161 /* Herbert's original patch had:
3162 * smp_mb__after_netif_stop_queue();
3163 * but since that doesn't exist yet, just open code it. */
3164 smp_mb();
3166 /* We need to check again in a case another CPU has just
3167 * made room available. */
3168 if (e1000_desc_unused(adapter->tx_ring) < size)
3169 return -EBUSY;
3171 /* A reprieve! */
3172 netif_start_queue(netdev);
3173 ++adapter->restart_queue;
3174 return 0;
3177 static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
3179 struct e1000_adapter *adapter = netdev_priv(netdev);
3181 if (e1000_desc_unused(adapter->tx_ring) >= size)
3182 return 0;
3183 return __e1000_maybe_stop_tx(netdev, size);
3186 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3187 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3189 struct e1000_adapter *adapter = netdev_priv(netdev);
3190 struct e1000_ring *tx_ring = adapter->tx_ring;
3191 unsigned int first;
3192 unsigned int max_per_txd = E1000_MAX_PER_TXD;
3193 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3194 unsigned int tx_flags = 0;
3195 unsigned int len = skb->len - skb->data_len;
3196 unsigned long irq_flags;
3197 unsigned int nr_frags;
3198 unsigned int mss;
3199 int count = 0;
3200 int tso;
3201 unsigned int f;
3203 if (test_bit(__E1000_DOWN, &adapter->state)) {
3204 dev_kfree_skb_any(skb);
3205 return NETDEV_TX_OK;
3208 if (skb->len <= 0) {
3209 dev_kfree_skb_any(skb);
3210 return NETDEV_TX_OK;
3213 mss = skb_shinfo(skb)->gso_size;
3214 /* The controller does a simple calculation to
3215 * make sure there is enough room in the FIFO before
3216 * initiating the DMA for each buffer. The calc is:
3217 * 4 = ceil(buffer len/mss). To make sure we don't
3218 * overrun the FIFO, adjust the max buffer len if mss
3219 * drops. */
3220 if (mss) {
3221 u8 hdr_len;
3222 max_per_txd = min(mss << 2, max_per_txd);
3223 max_txd_pwr = fls(max_per_txd) - 1;
3225 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3226 * points to just header, pull a few bytes of payload from
3227 * frags into skb->data */
3228 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3229 if (skb->data_len && (hdr_len == len)) {
3230 unsigned int pull_size;
3232 pull_size = min((unsigned int)4, skb->data_len);
3233 if (!__pskb_pull_tail(skb, pull_size)) {
3234 ndev_err(netdev,
3235 "__pskb_pull_tail failed.\n");
3236 dev_kfree_skb_any(skb);
3237 return NETDEV_TX_OK;
3239 len = skb->len - skb->data_len;
3243 /* reserve a descriptor for the offload context */
3244 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3245 count++;
3246 count++;
3248 count += TXD_USE_COUNT(len, max_txd_pwr);
3250 nr_frags = skb_shinfo(skb)->nr_frags;
3251 for (f = 0; f < nr_frags; f++)
3252 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3253 max_txd_pwr);
3255 if (adapter->hw.mac.tx_pkt_filtering)
3256 e1000_transfer_dhcp_info(adapter, skb);
3258 if (!spin_trylock_irqsave(&adapter->tx_queue_lock, irq_flags))
3259 /* Collision - tell upper layer to requeue */
3260 return NETDEV_TX_LOCKED;
3262 /* need: count + 2 desc gap to keep tail from touching
3263 * head, otherwise try next time */
3264 if (e1000_maybe_stop_tx(netdev, count + 2)) {
3265 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3266 return NETDEV_TX_BUSY;
3269 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3270 tx_flags |= E1000_TX_FLAGS_VLAN;
3271 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3274 first = tx_ring->next_to_use;
3276 tso = e1000_tso(adapter, skb);
3277 if (tso < 0) {
3278 dev_kfree_skb_any(skb);
3279 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3280 return NETDEV_TX_OK;
3283 if (tso)
3284 tx_flags |= E1000_TX_FLAGS_TSO;
3285 else if (e1000_tx_csum(adapter, skb))
3286 tx_flags |= E1000_TX_FLAGS_CSUM;
3288 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3289 * 82571 hardware supports TSO capabilities for IPv6 as well...
3290 * no longer assume, we must. */
3291 if (skb->protocol == htons(ETH_P_IP))
3292 tx_flags |= E1000_TX_FLAGS_IPV4;
3294 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
3295 if (count < 0) {
3296 /* handle pci_map_single() error in e1000_tx_map */
3297 dev_kfree_skb_any(skb);
3298 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3299 return NETDEV_TX_OK;
3302 e1000_tx_queue(adapter, tx_flags, count);
3304 netdev->trans_start = jiffies;
3306 /* Make sure there is space in the ring for the next send. */
3307 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
3309 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
3310 return NETDEV_TX_OK;
3314 * e1000_tx_timeout - Respond to a Tx Hang
3315 * @netdev: network interface device structure
3317 static void e1000_tx_timeout(struct net_device *netdev)
3319 struct e1000_adapter *adapter = netdev_priv(netdev);
3321 /* Do the reset outside of interrupt context */
3322 adapter->tx_timeout_count++;
3323 schedule_work(&adapter->reset_task);
3326 static void e1000_reset_task(struct work_struct *work)
3328 struct e1000_adapter *adapter;
3329 adapter = container_of(work, struct e1000_adapter, reset_task);
3331 e1000e_reinit_locked(adapter);
3335 * e1000_get_stats - Get System Network Statistics
3336 * @netdev: network interface device structure
3338 * Returns the address of the device statistics structure.
3339 * The statistics are actually updated from the timer callback.
3341 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3343 struct e1000_adapter *adapter = netdev_priv(netdev);
3345 /* only return the current stats */
3346 return &adapter->net_stats;
3350 * e1000_change_mtu - Change the Maximum Transfer Unit
3351 * @netdev: network interface device structure
3352 * @new_mtu: new value for maximum frame size
3354 * Returns 0 on success, negative on failure
3356 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3358 struct e1000_adapter *adapter = netdev_priv(netdev);
3359 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3361 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
3362 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3363 ndev_err(netdev, "Invalid MTU setting\n");
3364 return -EINVAL;
3367 /* Jumbo frame size limits */
3368 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
3369 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
3370 ndev_err(netdev, "Jumbo Frames not supported.\n");
3371 return -EINVAL;
3373 if (adapter->hw.phy.type == e1000_phy_ife) {
3374 ndev_err(netdev, "Jumbo Frames not supported.\n");
3375 return -EINVAL;
3379 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3380 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3381 ndev_err(netdev, "MTU > 9216 not supported.\n");
3382 return -EINVAL;
3385 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3386 msleep(1);
3387 /* e1000e_down has a dependency on max_frame_size */
3388 adapter->hw.mac.max_frame_size = max_frame;
3389 if (netif_running(netdev))
3390 e1000e_down(adapter);
3392 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3393 * means we reserve 2 more, this pushes us to allocate from the next
3394 * larger slab size.
3395 * i.e. RXBUFFER_2048 --> size-4096 slab */
3397 if (max_frame <= 256)
3398 adapter->rx_buffer_len = 256;
3399 else if (max_frame <= 512)
3400 adapter->rx_buffer_len = 512;
3401 else if (max_frame <= 1024)
3402 adapter->rx_buffer_len = 1024;
3403 else if (max_frame <= 2048)
3404 adapter->rx_buffer_len = 2048;
3405 else
3406 adapter->rx_buffer_len = 4096;
3408 /* adjust allocation if LPE protects us, and we aren't using SBP */
3409 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
3410 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
3411 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
3412 + ETH_FCS_LEN ;
3414 ndev_info(netdev, "changing MTU from %d to %d\n",
3415 netdev->mtu, new_mtu);
3416 netdev->mtu = new_mtu;
3418 if (netif_running(netdev))
3419 e1000e_up(adapter);
3420 else
3421 e1000e_reset(adapter);
3423 clear_bit(__E1000_RESETTING, &adapter->state);
3425 return 0;
3428 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
3429 int cmd)
3431 struct e1000_adapter *adapter = netdev_priv(netdev);
3432 struct mii_ioctl_data *data = if_mii(ifr);
3433 unsigned long irq_flags;
3435 if (adapter->hw.media_type != e1000_media_type_copper)
3436 return -EOPNOTSUPP;
3438 switch (cmd) {
3439 case SIOCGMIIPHY:
3440 data->phy_id = adapter->hw.phy.addr;
3441 break;
3442 case SIOCGMIIREG:
3443 if (!capable(CAP_NET_ADMIN))
3444 return -EPERM;
3445 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
3446 if (e1e_rphy(&adapter->hw, data->reg_num & 0x1F,
3447 &data->val_out)) {
3448 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
3449 return -EIO;
3451 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
3452 break;
3453 case SIOCSMIIREG:
3454 default:
3455 return -EOPNOTSUPP;
3457 return 0;
3460 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3462 switch (cmd) {
3463 case SIOCGMIIPHY:
3464 case SIOCGMIIREG:
3465 case SIOCSMIIREG:
3466 return e1000_mii_ioctl(netdev, ifr, cmd);
3467 default:
3468 return -EOPNOTSUPP;
3472 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
3474 struct net_device *netdev = pci_get_drvdata(pdev);
3475 struct e1000_adapter *adapter = netdev_priv(netdev);
3476 struct e1000_hw *hw = &adapter->hw;
3477 u32 ctrl, ctrl_ext, rctl, status;
3478 u32 wufc = adapter->wol;
3479 int retval = 0;
3481 netif_device_detach(netdev);
3483 if (netif_running(netdev)) {
3484 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3485 e1000e_down(adapter);
3486 e1000_free_irq(adapter);
3489 retval = pci_save_state(pdev);
3490 if (retval)
3491 return retval;
3493 status = er32(STATUS);
3494 if (status & E1000_STATUS_LU)
3495 wufc &= ~E1000_WUFC_LNKC;
3497 if (wufc) {
3498 e1000_setup_rctl(adapter);
3499 e1000_set_multi(netdev);
3501 /* turn on all-multi mode if wake on multicast is enabled */
3502 if (wufc & E1000_WUFC_MC) {
3503 rctl = er32(RCTL);
3504 rctl |= E1000_RCTL_MPE;
3505 ew32(RCTL, rctl);
3508 ctrl = er32(CTRL);
3509 /* advertise wake from D3Cold */
3510 #define E1000_CTRL_ADVD3WUC 0x00100000
3511 /* phy power management enable */
3512 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3513 ctrl |= E1000_CTRL_ADVD3WUC |
3514 E1000_CTRL_EN_PHY_PWR_MGMT;
3515 ew32(CTRL, ctrl);
3517 if (adapter->hw.media_type == e1000_media_type_fiber ||
3518 adapter->hw.media_type == e1000_media_type_internal_serdes) {
3519 /* keep the laser running in D3 */
3520 ctrl_ext = er32(CTRL_EXT);
3521 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
3522 ew32(CTRL_EXT, ctrl_ext);
3525 /* Allow time for pending master requests to run */
3526 e1000e_disable_pcie_master(&adapter->hw);
3528 ew32(WUC, E1000_WUC_PME_EN);
3529 ew32(WUFC, wufc);
3530 pci_enable_wake(pdev, PCI_D3hot, 1);
3531 pci_enable_wake(pdev, PCI_D3cold, 1);
3532 } else {
3533 ew32(WUC, 0);
3534 ew32(WUFC, 0);
3535 pci_enable_wake(pdev, PCI_D3hot, 0);
3536 pci_enable_wake(pdev, PCI_D3cold, 0);
3539 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
3540 e1000_release_manageability(adapter);
3542 =======
3543 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
3544 /* make sure adapter isn't asleep if manageability is enabled */
3545 if (adapter->flags & FLAG_MNG_PT_ENABLED) {
3546 pci_enable_wake(pdev, PCI_D3hot, 1);
3547 pci_enable_wake(pdev, PCI_D3cold, 1);
3550 if (adapter->hw.phy.type == e1000_phy_igp_3)
3551 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
3553 /* Release control of h/w to f/w. If f/w is AMT enabled, this
3554 * would have already happened in close and is redundant. */
3555 e1000_release_hw_control(adapter);
3557 pci_disable_device(pdev);
3559 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3561 return 0;
3564 static void e1000e_disable_l1aspm(struct pci_dev *pdev)
3566 int pos;
3567 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
3568 u32 cap;
3569 =======
3570 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
3571 u16 val;
3574 * 82573 workaround - disable L1 ASPM on mobile chipsets
3576 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
3577 * resulting in lost data or garbage information on the pci-e link
3578 * level. This could result in (false) bad EEPROM checksum errors,
3579 * long ping times (up to 2s) or even a system freeze/hang.
3581 * Unfortunately this feature saves about 1W power consumption when
3582 * active.
3584 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
3585 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
3586 pci_read_config_dword(pdev, pos + PCI_EXP_LNKCAP, &cap);
3587 =======
3588 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
3589 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val);
3590 if (val & 0x2) {
3591 dev_warn(&pdev->dev, "Disabling L1 ASPM\n");
3592 val &= ~0x2;
3593 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val);
3597 #ifdef CONFIG_PM
3598 static int e1000_resume(struct pci_dev *pdev)
3600 struct net_device *netdev = pci_get_drvdata(pdev);
3601 struct e1000_adapter *adapter = netdev_priv(netdev);
3602 struct e1000_hw *hw = &adapter->hw;
3603 u32 err;
3605 pci_set_power_state(pdev, PCI_D0);
3606 pci_restore_state(pdev);
3607 e1000e_disable_l1aspm(pdev);
3608 err = pci_enable_device(pdev);
3609 if (err) {
3610 dev_err(&pdev->dev,
3611 "Cannot enable PCI device from suspend\n");
3612 return err;
3615 pci_set_master(pdev);
3617 pci_enable_wake(pdev, PCI_D3hot, 0);
3618 pci_enable_wake(pdev, PCI_D3cold, 0);
3620 if (netif_running(netdev)) {
3621 err = e1000_request_irq(adapter);
3622 if (err)
3623 return err;
3626 e1000e_power_up_phy(adapter);
3627 e1000e_reset(adapter);
3628 ew32(WUS, ~0);
3630 e1000_init_manageability(adapter);
3632 if (netif_running(netdev))
3633 e1000e_up(adapter);
3635 netif_device_attach(netdev);
3637 /* If the controller has AMT, do not set DRV_LOAD until the interface
3638 * is up. For all other cases, let the f/w know that the h/w is now
3639 * under the control of the driver. */
3640 if (!(adapter->flags & FLAG_HAS_AMT) || !e1000e_check_mng_mode(&adapter->hw))
3641 e1000_get_hw_control(adapter);
3643 return 0;
3645 #endif
3647 static void e1000_shutdown(struct pci_dev *pdev)
3649 e1000_suspend(pdev, PMSG_SUSPEND);
3652 #ifdef CONFIG_NET_POLL_CONTROLLER
3654 * Polling 'interrupt' - used by things like netconsole to send skbs
3655 * without having to re-enable interrupts. It's not called while
3656 * the interrupt routine is executing.
3658 static void e1000_netpoll(struct net_device *netdev)
3660 struct e1000_adapter *adapter = netdev_priv(netdev);
3662 disable_irq(adapter->pdev->irq);
3663 e1000_intr(adapter->pdev->irq, netdev);
3665 e1000_clean_tx_irq(adapter);
3667 enable_irq(adapter->pdev->irq);
3669 #endif
3672 * e1000_io_error_detected - called when PCI error is detected
3673 * @pdev: Pointer to PCI device
3674 * @state: The current pci connection state
3676 * This function is called after a PCI bus error affecting
3677 * this device has been detected.
3679 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
3680 pci_channel_state_t state)
3682 struct net_device *netdev = pci_get_drvdata(pdev);
3683 struct e1000_adapter *adapter = netdev_priv(netdev);
3685 netif_device_detach(netdev);
3687 if (netif_running(netdev))
3688 e1000e_down(adapter);
3689 pci_disable_device(pdev);
3691 /* Request a slot slot reset. */
3692 return PCI_ERS_RESULT_NEED_RESET;
3696 * e1000_io_slot_reset - called after the pci bus has been reset.
3697 * @pdev: Pointer to PCI device
3699 * Restart the card from scratch, as if from a cold-boot. Implementation
3700 * resembles the first-half of the e1000_resume routine.
3702 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
3704 struct net_device *netdev = pci_get_drvdata(pdev);
3705 struct e1000_adapter *adapter = netdev_priv(netdev);
3706 struct e1000_hw *hw = &adapter->hw;
3708 e1000e_disable_l1aspm(pdev);
3709 if (pci_enable_device(pdev)) {
3710 dev_err(&pdev->dev,
3711 "Cannot re-enable PCI device after reset.\n");
3712 return PCI_ERS_RESULT_DISCONNECT;
3714 pci_set_master(pdev);
3716 pci_enable_wake(pdev, PCI_D3hot, 0);
3717 pci_enable_wake(pdev, PCI_D3cold, 0);
3719 e1000e_reset(adapter);
3720 ew32(WUS, ~0);
3722 return PCI_ERS_RESULT_RECOVERED;
3726 * e1000_io_resume - called when traffic can start flowing again.
3727 * @pdev: Pointer to PCI device
3729 * This callback is called when the error recovery driver tells us that
3730 * its OK to resume normal operation. Implementation resembles the
3731 * second-half of the e1000_resume routine.
3733 static void e1000_io_resume(struct pci_dev *pdev)
3735 struct net_device *netdev = pci_get_drvdata(pdev);
3736 struct e1000_adapter *adapter = netdev_priv(netdev);
3738 e1000_init_manageability(adapter);
3740 if (netif_running(netdev)) {
3741 if (e1000e_up(adapter)) {
3742 dev_err(&pdev->dev,
3743 "can't bring device back up after reset\n");
3744 return;
3748 netif_device_attach(netdev);
3750 /* If the controller has AMT, do not set DRV_LOAD until the interface
3751 * is up. For all other cases, let the f/w know that the h/w is now
3752 * under the control of the driver. */
3753 if (!(adapter->flags & FLAG_HAS_AMT) ||
3754 !e1000e_check_mng_mode(&adapter->hw))
3755 e1000_get_hw_control(adapter);
3759 static void e1000_print_device_info(struct e1000_adapter *adapter)
3761 struct e1000_hw *hw = &adapter->hw;
3762 struct net_device *netdev = adapter->netdev;
3763 u32 part_num;
3765 /* print bus type/speed/width info */
3766 ndev_info(netdev, "(PCI Express:2.5GB/s:%s) "
3767 "%02x:%02x:%02x:%02x:%02x:%02x\n",
3768 /* bus width */
3769 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
3770 "Width x1"),
3771 /* MAC address */
3772 netdev->dev_addr[0], netdev->dev_addr[1],
3773 netdev->dev_addr[2], netdev->dev_addr[3],
3774 netdev->dev_addr[4], netdev->dev_addr[5]);
3775 ndev_info(netdev, "Intel(R) PRO/%s Network Connection\n",
3776 (hw->phy.type == e1000_phy_ife)
3777 ? "10/100" : "1000");
3778 e1000e_read_part_num(hw, &part_num);
3779 ndev_info(netdev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
3780 hw->mac.type, hw->phy.type,
3781 (part_num >> 8), (part_num & 0xff));
3785 * e1000_probe - Device Initialization Routine
3786 * @pdev: PCI device information struct
3787 * @ent: entry in e1000_pci_tbl
3789 * Returns 0 on success, negative on failure
3791 * e1000_probe initializes an adapter identified by a pci_dev structure.
3792 * The OS initialization, configuring of the adapter private structure,
3793 * and a hardware reset occur.
3795 static int __devinit e1000_probe(struct pci_dev *pdev,
3796 const struct pci_device_id *ent)
3798 struct net_device *netdev;
3799 struct e1000_adapter *adapter;
3800 struct e1000_hw *hw;
3801 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
3802 unsigned long mmio_start, mmio_len;
3803 unsigned long flash_start, flash_len;
3805 static int cards_found;
3806 int i, err, pci_using_dac;
3807 u16 eeprom_data = 0;
3808 u16 eeprom_apme_mask = E1000_EEPROM_APME;
3810 e1000e_disable_l1aspm(pdev);
3811 err = pci_enable_device(pdev);
3812 if (err)
3813 return err;
3815 pci_using_dac = 0;
3816 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
3817 if (!err) {
3818 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
3819 if (!err)
3820 pci_using_dac = 1;
3821 } else {
3822 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
3823 if (err) {
3824 err = pci_set_consistent_dma_mask(pdev,
3825 DMA_32BIT_MASK);
3826 if (err) {
3827 dev_err(&pdev->dev, "No usable DMA "
3828 "configuration, aborting\n");
3829 goto err_dma;
3834 err = pci_request_regions(pdev, e1000e_driver_name);
3835 if (err)
3836 goto err_pci_reg;
3838 pci_set_master(pdev);
3840 err = -ENOMEM;
3841 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
3842 if (!netdev)
3843 goto err_alloc_etherdev;
3845 SET_NETDEV_DEV(netdev, &pdev->dev);
3847 pci_set_drvdata(pdev, netdev);
3848 adapter = netdev_priv(netdev);
3849 hw = &adapter->hw;
3850 adapter->netdev = netdev;
3851 adapter->pdev = pdev;
3852 adapter->ei = ei;
3853 adapter->pba = ei->pba;
3854 adapter->flags = ei->flags;
3855 adapter->hw.adapter = adapter;
3856 adapter->hw.mac.type = ei->mac;
3857 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
3859 mmio_start = pci_resource_start(pdev, 0);
3860 mmio_len = pci_resource_len(pdev, 0);
3862 err = -EIO;
3863 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
3864 if (!adapter->hw.hw_addr)
3865 goto err_ioremap;
3867 if ((adapter->flags & FLAG_HAS_FLASH) &&
3868 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
3869 flash_start = pci_resource_start(pdev, 1);
3870 flash_len = pci_resource_len(pdev, 1);
3871 adapter->hw.flash_address = ioremap(flash_start, flash_len);
3872 if (!adapter->hw.flash_address)
3873 goto err_flashmap;
3876 /* construct the net_device struct */
3877 netdev->open = &e1000_open;
3878 netdev->stop = &e1000_close;
3879 netdev->hard_start_xmit = &e1000_xmit_frame;
3880 netdev->get_stats = &e1000_get_stats;
3881 netdev->set_multicast_list = &e1000_set_multi;
3882 netdev->set_mac_address = &e1000_set_mac;
3883 netdev->change_mtu = &e1000_change_mtu;
3884 netdev->do_ioctl = &e1000_ioctl;
3885 e1000e_set_ethtool_ops(netdev);
3886 netdev->tx_timeout = &e1000_tx_timeout;
3887 netdev->watchdog_timeo = 5 * HZ;
3888 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
3889 netdev->vlan_rx_register = e1000_vlan_rx_register;
3890 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
3891 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
3892 #ifdef CONFIG_NET_POLL_CONTROLLER
3893 netdev->poll_controller = e1000_netpoll;
3894 #endif
3895 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
3897 netdev->mem_start = mmio_start;
3898 netdev->mem_end = mmio_start + mmio_len;
3900 adapter->bd_number = cards_found++;
3902 /* setup adapter struct */
3903 err = e1000_sw_init(adapter);
3904 if (err)
3905 goto err_sw_init;
3907 err = -EIO;
3909 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
3910 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
3911 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
3913 err = ei->get_invariants(adapter);
3914 if (err)
3915 goto err_hw_init;
3917 hw->mac.ops.get_bus_info(&adapter->hw);
3919 adapter->hw.phy.wait_for_link = 0;
3921 /* Copper options */
3922 if (adapter->hw.media_type == e1000_media_type_copper) {
3923 adapter->hw.phy.mdix = AUTO_ALL_MODES;
3924 adapter->hw.phy.disable_polarity_correction = 0;
3925 adapter->hw.phy.ms_type = e1000_ms_hw_default;
3928 if (e1000_check_reset_block(&adapter->hw))
3929 ndev_info(netdev,
3930 "PHY reset is blocked due to SOL/IDER session.\n");
3932 netdev->features = NETIF_F_SG |
3933 NETIF_F_HW_CSUM |
3934 NETIF_F_HW_VLAN_TX |
3935 NETIF_F_HW_VLAN_RX;
3937 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
3938 netdev->features |= NETIF_F_HW_VLAN_FILTER;
3940 netdev->features |= NETIF_F_TSO;
3941 netdev->features |= NETIF_F_TSO6;
3943 if (pci_using_dac)
3944 netdev->features |= NETIF_F_HIGHDMA;
3946 /* We should not be using LLTX anymore, but we are still TX faster with
3947 * it. */
3948 netdev->features |= NETIF_F_LLTX;
3950 if (e1000e_enable_mng_pass_thru(&adapter->hw))
3951 adapter->flags |= FLAG_MNG_PT_ENABLED;
3953 /* before reading the NVM, reset the controller to
3954 * put the device in a known good starting state */
3955 adapter->hw.mac.ops.reset_hw(&adapter->hw);
3958 * systems with ASPM and others may see the checksum fail on the first
3959 * attempt. Let's give it a few tries
3961 for (i = 0;; i++) {
3962 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
3963 break;
3964 if (i == 2) {
3965 ndev_err(netdev, "The NVM Checksum Is Not Valid\n");
3966 err = -EIO;
3967 goto err_eeprom;
3971 /* copy the MAC address out of the NVM */
3972 if (e1000e_read_mac_addr(&adapter->hw))
3973 ndev_err(netdev, "NVM Read Error while reading MAC address\n");
3975 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
3976 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
3978 if (!is_valid_ether_addr(netdev->perm_addr)) {
3979 ndev_err(netdev, "Invalid MAC Address: "
3980 "%02x:%02x:%02x:%02x:%02x:%02x\n",
3981 netdev->perm_addr[0], netdev->perm_addr[1],
3982 netdev->perm_addr[2], netdev->perm_addr[3],
3983 netdev->perm_addr[4], netdev->perm_addr[5]);
3984 err = -EIO;
3985 goto err_eeprom;
3988 init_timer(&adapter->watchdog_timer);
3989 adapter->watchdog_timer.function = &e1000_watchdog;
3990 adapter->watchdog_timer.data = (unsigned long) adapter;
3992 init_timer(&adapter->phy_info_timer);
3993 adapter->phy_info_timer.function = &e1000_update_phy_info;
3994 adapter->phy_info_timer.data = (unsigned long) adapter;
3996 INIT_WORK(&adapter->reset_task, e1000_reset_task);
3997 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
3999 e1000e_check_options(adapter);
4001 /* Initialize link parameters. User can change them with ethtool */
4002 adapter->hw.mac.autoneg = 1;
4003 adapter->fc_autoneg = 1;
4004 adapter->hw.mac.original_fc = e1000_fc_default;
4005 adapter->hw.mac.fc = e1000_fc_default;
4006 adapter->hw.phy.autoneg_advertised = 0x2f;
4008 /* ring size defaults */
4009 adapter->rx_ring->count = 256;
4010 adapter->tx_ring->count = 256;
4013 * Initial Wake on LAN setting - If APM wake is enabled in
4014 * the EEPROM, enable the ACPI Magic Packet filter
4016 if (adapter->flags & FLAG_APME_IN_WUC) {
4017 /* APME bit in EEPROM is mapped to WUC.APME */
4018 eeprom_data = er32(WUC);
4019 eeprom_apme_mask = E1000_WUC_APME;
4020 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
4021 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
4022 (adapter->hw.bus.func == 1))
4023 e1000_read_nvm(&adapter->hw,
4024 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
4025 else
4026 e1000_read_nvm(&adapter->hw,
4027 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
4030 /* fetch WoL from EEPROM */
4031 if (eeprom_data & eeprom_apme_mask)
4032 adapter->eeprom_wol |= E1000_WUFC_MAG;
4035 * now that we have the eeprom settings, apply the special cases
4036 * where the eeprom may be wrong or the board simply won't support
4037 * wake on lan on a particular port
4039 if (!(adapter->flags & FLAG_HAS_WOL))
4040 adapter->eeprom_wol = 0;
4042 /* initialize the wol settings based on the eeprom settings */
4043 adapter->wol = adapter->eeprom_wol;
4045 /* reset the hardware with the new settings */
4046 e1000e_reset(adapter);
4048 /* If the controller has AMT, do not set DRV_LOAD until the interface
4049 * is up. For all other cases, let the f/w know that the h/w is now
4050 * under the control of the driver. */
4051 if (!(adapter->flags & FLAG_HAS_AMT) ||
4052 !e1000e_check_mng_mode(&adapter->hw))
4053 e1000_get_hw_control(adapter);
4055 /* tell the stack to leave us alone until e1000_open() is called */
4056 netif_carrier_off(netdev);
4057 netif_stop_queue(netdev);
4059 strcpy(netdev->name, "eth%d");
4060 err = register_netdev(netdev);
4061 if (err)
4062 goto err_register;
4064 e1000_print_device_info(adapter);
4066 return 0;
4068 err_register:
4069 err_hw_init:
4070 e1000_release_hw_control(adapter);
4071 err_eeprom:
4072 if (!e1000_check_reset_block(&adapter->hw))
4073 e1000_phy_hw_reset(&adapter->hw);
4075 if (adapter->hw.flash_address)
4076 iounmap(adapter->hw.flash_address);
4078 err_flashmap:
4079 kfree(adapter->tx_ring);
4080 kfree(adapter->rx_ring);
4081 err_sw_init:
4082 iounmap(adapter->hw.hw_addr);
4083 err_ioremap:
4084 free_netdev(netdev);
4085 err_alloc_etherdev:
4086 pci_release_regions(pdev);
4087 err_pci_reg:
4088 err_dma:
4089 pci_disable_device(pdev);
4090 return err;
4094 * e1000_remove - Device Removal Routine
4095 * @pdev: PCI device information struct
4097 * e1000_remove is called by the PCI subsystem to alert the driver
4098 * that it should release a PCI device. The could be caused by a
4099 * Hot-Plug event, or because the driver is going to be removed from
4100 * memory.
4102 static void __devexit e1000_remove(struct pci_dev *pdev)
4104 struct net_device *netdev = pci_get_drvdata(pdev);
4105 struct e1000_adapter *adapter = netdev_priv(netdev);
4107 /* flush_scheduled work may reschedule our watchdog task, so
4108 * explicitly disable watchdog tasks from being rescheduled */
4109 set_bit(__E1000_DOWN, &adapter->state);
4110 del_timer_sync(&adapter->watchdog_timer);
4111 del_timer_sync(&adapter->phy_info_timer);
4113 flush_scheduled_work();
4115 <<<<<<< HEAD:drivers/net/e1000e/netdev.c
4116 e1000_release_manageability(adapter);
4118 =======
4119 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/netdev.c
4120 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4121 * would have already happened in close and is redundant. */
4122 e1000_release_hw_control(adapter);
4124 unregister_netdev(netdev);
4126 if (!e1000_check_reset_block(&adapter->hw))
4127 e1000_phy_hw_reset(&adapter->hw);
4129 kfree(adapter->tx_ring);
4130 kfree(adapter->rx_ring);
4132 iounmap(adapter->hw.hw_addr);
4133 if (adapter->hw.flash_address)
4134 iounmap(adapter->hw.flash_address);
4135 pci_release_regions(pdev);
4137 free_netdev(netdev);
4139 pci_disable_device(pdev);
4142 /* PCI Error Recovery (ERS) */
4143 static struct pci_error_handlers e1000_err_handler = {
4144 .error_detected = e1000_io_error_detected,
4145 .slot_reset = e1000_io_slot_reset,
4146 .resume = e1000_io_resume,
4149 static struct pci_device_id e1000_pci_tbl[] = {
4150 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
4151 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
4152 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
4153 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
4154 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
4155 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
4156 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
4157 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
4158 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
4159 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
4160 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
4161 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
4162 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
4163 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
4164 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
4165 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
4166 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
4167 board_80003es2lan },
4168 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
4169 board_80003es2lan },
4170 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
4171 board_80003es2lan },
4172 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
4173 board_80003es2lan },
4174 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
4175 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
4176 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
4177 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
4178 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
4179 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
4180 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
4181 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
4182 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
4183 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
4184 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
4185 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
4187 { } /* terminate list */
4189 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
4191 /* PCI Device API Driver */
4192 static struct pci_driver e1000_driver = {
4193 .name = e1000e_driver_name,
4194 .id_table = e1000_pci_tbl,
4195 .probe = e1000_probe,
4196 .remove = __devexit_p(e1000_remove),
4197 #ifdef CONFIG_PM
4198 /* Power Managment Hooks */
4199 .suspend = e1000_suspend,
4200 .resume = e1000_resume,
4201 #endif
4202 .shutdown = e1000_shutdown,
4203 .err_handler = &e1000_err_handler
4207 * e1000_init_module - Driver Registration Routine
4209 * e1000_init_module is the first routine called when the driver is
4210 * loaded. All it does is register with the PCI subsystem.
4212 static int __init e1000_init_module(void)
4214 int ret;
4215 printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
4216 e1000e_driver_name, e1000e_driver_version);
4217 printk(KERN_INFO "%s: Copyright (c) 1999-2007 Intel Corporation.\n",
4218 e1000e_driver_name);
4219 ret = pci_register_driver(&e1000_driver);
4221 return ret;
4223 module_init(e1000_init_module);
4226 * e1000_exit_module - Driver Exit Cleanup Routine
4228 * e1000_exit_module is called just before the driver is removed
4229 * from memory.
4231 static void __exit e1000_exit_module(void)
4233 pci_unregister_driver(&e1000_driver);
4235 module_exit(e1000_exit_module);
4238 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
4239 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
4240 MODULE_LICENSE("GPL");
4241 MODULE_VERSION(DRV_VERSION);
4243 /* e1000_main.c */