]> Pileus Git - ~andy/linux/blob - drivers/net/e1000e/netdev.c
e1000e: don't clean Rx ring while resetting
[~andy/linux] / drivers / net / e1000e / netdev.c
1 /*******************************************************************************
2
3   Intel PRO/1000 Linux driver
4   Copyright(c) 1999 - 2008 Intel Corporation.
5
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.
9
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.
14
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.
18
19   The full GNU General Public License is included in this distribution in
20   the file called "COPYING".
21
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
26
27 *******************************************************************************/
28
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>
46 #include <linux/pm_qos_params.h>
47 #include <linux/aer.h>
48
49 #include "e1000.h"
50
51 #define DRV_VERSION "1.0.2-k2"
52 char e1000e_driver_name[] = "e1000e";
53 const char e1000e_driver_version[] = DRV_VERSION;
54
55 static const struct e1000_info *e1000_info_tbl[] = {
56         [board_82571]           = &e1000_82571_info,
57         [board_82572]           = &e1000_82572_info,
58         [board_82573]           = &e1000_82573_info,
59         [board_82574]           = &e1000_82574_info,
60         [board_82583]           = &e1000_82583_info,
61         [board_80003es2lan]     = &e1000_es2_info,
62         [board_ich8lan]         = &e1000_ich8_info,
63         [board_ich9lan]         = &e1000_ich9_info,
64         [board_ich10lan]        = &e1000_ich10_info,
65         [board_pchlan]          = &e1000_pch_info,
66 };
67
68 #ifdef DEBUG
69 /**
70  * e1000_get_hw_dev_name - return device name string
71  * used by hardware layer to print debugging information
72  **/
73 char *e1000e_get_hw_dev_name(struct e1000_hw *hw)
74 {
75         return hw->adapter->netdev->name;
76 }
77 #endif
78
79 /**
80  * e1000_desc_unused - calculate if we have unused descriptors
81  **/
82 static int e1000_desc_unused(struct e1000_ring *ring)
83 {
84         if (ring->next_to_clean > ring->next_to_use)
85                 return ring->next_to_clean - ring->next_to_use - 1;
86
87         return ring->count + ring->next_to_clean - ring->next_to_use - 1;
88 }
89
90 /**
91  * e1000_receive_skb - helper function to handle Rx indications
92  * @adapter: board private structure
93  * @status: descriptor status field as written by hardware
94  * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
95  * @skb: pointer to sk_buff to be indicated to stack
96  **/
97 static void e1000_receive_skb(struct e1000_adapter *adapter,
98                               struct net_device *netdev,
99                               struct sk_buff *skb,
100                               u8 status, __le16 vlan)
101 {
102         skb->protocol = eth_type_trans(skb, netdev);
103
104         if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
105                 vlan_gro_receive(&adapter->napi, adapter->vlgrp,
106                                  le16_to_cpu(vlan), skb);
107         else
108                 napi_gro_receive(&adapter->napi, skb);
109 }
110
111 /**
112  * e1000_rx_checksum - Receive Checksum Offload for 82543
113  * @adapter:     board private structure
114  * @status_err:  receive descriptor status and error fields
115  * @csum:       receive descriptor csum field
116  * @sk_buff:     socket buffer with received data
117  **/
118 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
119                               u32 csum, struct sk_buff *skb)
120 {
121         u16 status = (u16)status_err;
122         u8 errors = (u8)(status_err >> 24);
123         skb->ip_summed = CHECKSUM_NONE;
124
125         /* Ignore Checksum bit is set */
126         if (status & E1000_RXD_STAT_IXSM)
127                 return;
128         /* TCP/UDP checksum error bit is set */
129         if (errors & E1000_RXD_ERR_TCPE) {
130                 /* let the stack verify checksum errors */
131                 adapter->hw_csum_err++;
132                 return;
133         }
134
135         /* TCP/UDP Checksum has not been calculated */
136         if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
137                 return;
138
139         /* It must be a TCP or UDP packet with a valid checksum */
140         if (status & E1000_RXD_STAT_TCPCS) {
141                 /* TCP checksum is good */
142                 skb->ip_summed = CHECKSUM_UNNECESSARY;
143         } else {
144                 /*
145                  * IP fragment with UDP payload
146                  * Hardware complements the payload checksum, so we undo it
147                  * and then put the value in host order for further stack use.
148                  */
149                 __sum16 sum = (__force __sum16)htons(csum);
150                 skb->csum = csum_unfold(~sum);
151                 skb->ip_summed = CHECKSUM_COMPLETE;
152         }
153         adapter->hw_csum_good++;
154 }
155
156 /**
157  * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
158  * @adapter: address of board private structure
159  **/
160 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
161                                    int cleaned_count)
162 {
163         struct net_device *netdev = adapter->netdev;
164         struct pci_dev *pdev = adapter->pdev;
165         struct e1000_ring *rx_ring = adapter->rx_ring;
166         struct e1000_rx_desc *rx_desc;
167         struct e1000_buffer *buffer_info;
168         struct sk_buff *skb;
169         unsigned int i;
170         unsigned int bufsz = adapter->rx_buffer_len;
171
172         i = rx_ring->next_to_use;
173         buffer_info = &rx_ring->buffer_info[i];
174
175         while (cleaned_count--) {
176                 skb = buffer_info->skb;
177                 if (skb) {
178                         skb_trim(skb, 0);
179                         goto map_skb;
180                 }
181
182                 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
183                 if (!skb) {
184                         /* Better luck next round */
185                         adapter->alloc_rx_buff_failed++;
186                         break;
187                 }
188
189                 buffer_info->skb = skb;
190 map_skb:
191                 buffer_info->dma = pci_map_single(pdev, skb->data,
192                                                   adapter->rx_buffer_len,
193                                                   PCI_DMA_FROMDEVICE);
194                 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
195                         dev_err(&pdev->dev, "RX DMA map failed\n");
196                         adapter->rx_dma_failed++;
197                         break;
198                 }
199
200                 rx_desc = E1000_RX_DESC(*rx_ring, i);
201                 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
202
203                 i++;
204                 if (i == rx_ring->count)
205                         i = 0;
206                 buffer_info = &rx_ring->buffer_info[i];
207         }
208
209         if (rx_ring->next_to_use != i) {
210                 rx_ring->next_to_use = i;
211                 if (i-- == 0)
212                         i = (rx_ring->count - 1);
213
214                 /*
215                  * Force memory writes to complete before letting h/w
216                  * know there are new descriptors to fetch.  (Only
217                  * applicable for weak-ordered memory model archs,
218                  * such as IA-64).
219                  */
220                 wmb();
221                 writel(i, adapter->hw.hw_addr + rx_ring->tail);
222         }
223 }
224
225 /**
226  * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
227  * @adapter: address of board private structure
228  **/
229 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
230                                       int cleaned_count)
231 {
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;
240
241         i = rx_ring->next_to_use;
242         buffer_info = &rx_ring->buffer_info[i];
243
244         while (cleaned_count--) {
245                 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
246
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;
253                         }
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;
259                                 }
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(pdev, 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;
269                                 }
270                         }
271                         /*
272                          * Refresh the desc even if buffer_addrs
273                          * didn't change because each write-back
274                          * erases this info.
275                          */
276                         rx_desc->read.buffer_addr[j+1] =
277                              cpu_to_le64(ps_page->dma);
278                 }
279
280                 skb = netdev_alloc_skb_ip_align(netdev,
281                                                 adapter->rx_ps_bsize0);
282
283                 if (!skb) {
284                         adapter->alloc_rx_buff_failed++;
285                         break;
286                 }
287
288                 buffer_info->skb = skb;
289                 buffer_info->dma = pci_map_single(pdev, skb->data,
290                                                   adapter->rx_ps_bsize0,
291                                                   PCI_DMA_FROMDEVICE);
292                 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
293                         dev_err(&pdev->dev, "RX DMA map failed\n");
294                         adapter->rx_dma_failed++;
295                         /* cleanup skb */
296                         dev_kfree_skb_any(skb);
297                         buffer_info->skb = NULL;
298                         break;
299                 }
300
301                 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
302
303                 i++;
304                 if (i == rx_ring->count)
305                         i = 0;
306                 buffer_info = &rx_ring->buffer_info[i];
307         }
308
309 no_buffers:
310         if (rx_ring->next_to_use != i) {
311                 rx_ring->next_to_use = i;
312
313                 if (!(i--))
314                         i = (rx_ring->count - 1);
315
316                 /*
317                  * Force memory writes to complete before letting h/w
318                  * know there are new descriptors to fetch.  (Only
319                  * applicable for weak-ordered memory model archs,
320                  * such as IA-64).
321                  */
322                 wmb();
323                 /*
324                  * Hardware increments by 16 bytes, but packet split
325                  * descriptors are 32 bytes...so we increment tail
326                  * twice as much.
327                  */
328                 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
329         }
330 }
331
332 /**
333  * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
334  * @adapter: address of board private structure
335  * @cleaned_count: number of buffers to allocate this pass
336  **/
337
338 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
339                                          int cleaned_count)
340 {
341         struct net_device *netdev = adapter->netdev;
342         struct pci_dev *pdev = adapter->pdev;
343         struct e1000_rx_desc *rx_desc;
344         struct e1000_ring *rx_ring = adapter->rx_ring;
345         struct e1000_buffer *buffer_info;
346         struct sk_buff *skb;
347         unsigned int i;
348         unsigned int bufsz = 256 - 16 /* for skb_reserve */;
349
350         i = rx_ring->next_to_use;
351         buffer_info = &rx_ring->buffer_info[i];
352
353         while (cleaned_count--) {
354                 skb = buffer_info->skb;
355                 if (skb) {
356                         skb_trim(skb, 0);
357                         goto check_page;
358                 }
359
360                 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
361                 if (unlikely(!skb)) {
362                         /* Better luck next round */
363                         adapter->alloc_rx_buff_failed++;
364                         break;
365                 }
366
367                 buffer_info->skb = skb;
368 check_page:
369                 /* allocate a new page if necessary */
370                 if (!buffer_info->page) {
371                         buffer_info->page = alloc_page(GFP_ATOMIC);
372                         if (unlikely(!buffer_info->page)) {
373                                 adapter->alloc_rx_buff_failed++;
374                                 break;
375                         }
376                 }
377
378                 if (!buffer_info->dma)
379                         buffer_info->dma = pci_map_page(pdev,
380                                                         buffer_info->page, 0,
381                                                         PAGE_SIZE,
382                                                         PCI_DMA_FROMDEVICE);
383
384                 rx_desc = E1000_RX_DESC(*rx_ring, i);
385                 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
386
387                 if (unlikely(++i == rx_ring->count))
388                         i = 0;
389                 buffer_info = &rx_ring->buffer_info[i];
390         }
391
392         if (likely(rx_ring->next_to_use != i)) {
393                 rx_ring->next_to_use = i;
394                 if (unlikely(i-- == 0))
395                         i = (rx_ring->count - 1);
396
397                 /* Force memory writes to complete before letting h/w
398                  * know there are new descriptors to fetch.  (Only
399                  * applicable for weak-ordered memory model archs,
400                  * such as IA-64). */
401                 wmb();
402                 writel(i, adapter->hw.hw_addr + rx_ring->tail);
403         }
404 }
405
406 /**
407  * e1000_clean_rx_irq - Send received data up the network stack; legacy
408  * @adapter: board private structure
409  *
410  * the return value indicates whether actual cleaning was done, there
411  * is no guarantee that everything was cleaned
412  **/
413 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
414                                int *work_done, int work_to_do)
415 {
416         struct net_device *netdev = adapter->netdev;
417         struct pci_dev *pdev = adapter->pdev;
418         struct e1000_ring *rx_ring = adapter->rx_ring;
419         struct e1000_rx_desc *rx_desc, *next_rxd;
420         struct e1000_buffer *buffer_info, *next_buffer;
421         u32 length;
422         unsigned int i;
423         int cleaned_count = 0;
424         bool cleaned = 0;
425         unsigned int total_rx_bytes = 0, total_rx_packets = 0;
426
427         i = rx_ring->next_to_clean;
428         rx_desc = E1000_RX_DESC(*rx_ring, i);
429         buffer_info = &rx_ring->buffer_info[i];
430
431         while (rx_desc->status & E1000_RXD_STAT_DD) {
432                 struct sk_buff *skb;
433                 u8 status;
434
435                 if (*work_done >= work_to_do)
436                         break;
437                 (*work_done)++;
438
439                 status = rx_desc->status;
440                 skb = buffer_info->skb;
441                 buffer_info->skb = NULL;
442
443                 prefetch(skb->data - NET_IP_ALIGN);
444
445                 i++;
446                 if (i == rx_ring->count)
447                         i = 0;
448                 next_rxd = E1000_RX_DESC(*rx_ring, i);
449                 prefetch(next_rxd);
450
451                 next_buffer = &rx_ring->buffer_info[i];
452
453                 cleaned = 1;
454                 cleaned_count++;
455                 pci_unmap_single(pdev,
456                                  buffer_info->dma,
457                                  adapter->rx_buffer_len,
458                                  PCI_DMA_FROMDEVICE);
459                 buffer_info->dma = 0;
460
461                 length = le16_to_cpu(rx_desc->length);
462
463                 /* !EOP means multiple descriptors were used to store a single
464                  * packet, also make sure the frame isn't just CRC only */
465                 if (!(status & E1000_RXD_STAT_EOP) || (length <= 4)) {
466                         /* All receives must fit into a single buffer */
467                         e_dbg("%s: Receive packet consumed multiple buffers\n",
468                               netdev->name);
469                         /* recycle */
470                         buffer_info->skb = skb;
471                         goto next_desc;
472                 }
473
474                 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
475                         /* recycle */
476                         buffer_info->skb = skb;
477                         goto next_desc;
478                 }
479
480                 /* adjust length to remove Ethernet CRC */
481                 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
482                         length -= 4;
483
484                 total_rx_bytes += length;
485                 total_rx_packets++;
486
487                 /*
488                  * code added for copybreak, this should improve
489                  * performance for small packets with large amounts
490                  * of reassembly being done in the stack
491                  */
492                 if (length < copybreak) {
493                         struct sk_buff *new_skb =
494                             netdev_alloc_skb_ip_align(netdev, length);
495                         if (new_skb) {
496                                 skb_copy_to_linear_data_offset(new_skb,
497                                                                -NET_IP_ALIGN,
498                                                                (skb->data -
499                                                                 NET_IP_ALIGN),
500                                                                (length +
501                                                                 NET_IP_ALIGN));
502                                 /* save the skb in buffer_info as good */
503                                 buffer_info->skb = skb;
504                                 skb = new_skb;
505                         }
506                         /* else just continue with the old one */
507                 }
508                 /* end copybreak code */
509                 skb_put(skb, length);
510
511                 /* Receive Checksum Offload */
512                 e1000_rx_checksum(adapter,
513                                   (u32)(status) |
514                                   ((u32)(rx_desc->errors) << 24),
515                                   le16_to_cpu(rx_desc->csum), skb);
516
517                 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
518
519 next_desc:
520                 rx_desc->status = 0;
521
522                 /* return some buffers to hardware, one at a time is too slow */
523                 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
524                         adapter->alloc_rx_buf(adapter, cleaned_count);
525                         cleaned_count = 0;
526                 }
527
528                 /* use prefetched values */
529                 rx_desc = next_rxd;
530                 buffer_info = next_buffer;
531         }
532         rx_ring->next_to_clean = i;
533
534         cleaned_count = e1000_desc_unused(rx_ring);
535         if (cleaned_count)
536                 adapter->alloc_rx_buf(adapter, cleaned_count);
537
538         adapter->total_rx_bytes += total_rx_bytes;
539         adapter->total_rx_packets += total_rx_packets;
540         netdev->stats.rx_bytes += total_rx_bytes;
541         netdev->stats.rx_packets += total_rx_packets;
542         return cleaned;
543 }
544
545 static void e1000_put_txbuf(struct e1000_adapter *adapter,
546                              struct e1000_buffer *buffer_info)
547 {
548         buffer_info->dma = 0;
549         if (buffer_info->skb) {
550                 skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
551                               DMA_TO_DEVICE);
552                 dev_kfree_skb_any(buffer_info->skb);
553                 buffer_info->skb = NULL;
554         }
555         buffer_info->time_stamp = 0;
556 }
557
558 static void e1000_print_tx_hang(struct e1000_adapter *adapter)
559 {
560         struct e1000_ring *tx_ring = adapter->tx_ring;
561         unsigned int i = tx_ring->next_to_clean;
562         unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
563         struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
564
565         /* detected Tx unit hang */
566         e_err("Detected Tx Unit Hang:\n"
567               "  TDH                  <%x>\n"
568               "  TDT                  <%x>\n"
569               "  next_to_use          <%x>\n"
570               "  next_to_clean        <%x>\n"
571               "buffer_info[next_to_clean]:\n"
572               "  time_stamp           <%lx>\n"
573               "  next_to_watch        <%x>\n"
574               "  jiffies              <%lx>\n"
575               "  next_to_watch.status <%x>\n",
576               readl(adapter->hw.hw_addr + tx_ring->head),
577               readl(adapter->hw.hw_addr + tx_ring->tail),
578               tx_ring->next_to_use,
579               tx_ring->next_to_clean,
580               tx_ring->buffer_info[eop].time_stamp,
581               eop,
582               jiffies,
583               eop_desc->upper.fields.status);
584 }
585
586 /**
587  * e1000_clean_tx_irq - Reclaim resources after transmit completes
588  * @adapter: board private structure
589  *
590  * the return value indicates whether actual cleaning was done, there
591  * is no guarantee that everything was cleaned
592  **/
593 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
594 {
595         struct net_device *netdev = adapter->netdev;
596         struct e1000_hw *hw = &adapter->hw;
597         struct e1000_ring *tx_ring = adapter->tx_ring;
598         struct e1000_tx_desc *tx_desc, *eop_desc;
599         struct e1000_buffer *buffer_info;
600         unsigned int i, eop;
601         unsigned int count = 0;
602         unsigned int total_tx_bytes = 0, total_tx_packets = 0;
603
604         i = tx_ring->next_to_clean;
605         eop = tx_ring->buffer_info[i].next_to_watch;
606         eop_desc = E1000_TX_DESC(*tx_ring, eop);
607
608         while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
609                (count < tx_ring->count)) {
610                 bool cleaned = false;
611                 for (; !cleaned; count++) {
612                         tx_desc = E1000_TX_DESC(*tx_ring, i);
613                         buffer_info = &tx_ring->buffer_info[i];
614                         cleaned = (i == eop);
615
616                         if (cleaned) {
617                                 struct sk_buff *skb = buffer_info->skb;
618                                 unsigned int segs, bytecount;
619                                 segs = skb_shinfo(skb)->gso_segs ?: 1;
620                                 /* multiply data chunks by size of headers */
621                                 bytecount = ((segs - 1) * skb_headlen(skb)) +
622                                             skb->len;
623                                 total_tx_packets += segs;
624                                 total_tx_bytes += bytecount;
625                         }
626
627                         e1000_put_txbuf(adapter, buffer_info);
628                         tx_desc->upper.data = 0;
629
630                         i++;
631                         if (i == tx_ring->count)
632                                 i = 0;
633                 }
634
635                 eop = tx_ring->buffer_info[i].next_to_watch;
636                 eop_desc = E1000_TX_DESC(*tx_ring, eop);
637         }
638
639         tx_ring->next_to_clean = i;
640
641 #define TX_WAKE_THRESHOLD 32
642         if (count && netif_carrier_ok(netdev) &&
643             e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
644                 /* Make sure that anybody stopping the queue after this
645                  * sees the new next_to_clean.
646                  */
647                 smp_mb();
648
649                 if (netif_queue_stopped(netdev) &&
650                     !(test_bit(__E1000_DOWN, &adapter->state))) {
651                         netif_wake_queue(netdev);
652                         ++adapter->restart_queue;
653                 }
654         }
655
656         if (adapter->detect_tx_hung) {
657                 /* Detect a transmit hang in hardware, this serializes the
658                  * check with the clearing of time_stamp and movement of i */
659                 adapter->detect_tx_hung = 0;
660                 if (tx_ring->buffer_info[i].time_stamp &&
661                     time_after(jiffies, tx_ring->buffer_info[i].time_stamp
662                                + (adapter->tx_timeout_factor * HZ))
663                     && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
664                         e1000_print_tx_hang(adapter);
665                         netif_stop_queue(netdev);
666                 }
667         }
668         adapter->total_tx_bytes += total_tx_bytes;
669         adapter->total_tx_packets += total_tx_packets;
670         netdev->stats.tx_bytes += total_tx_bytes;
671         netdev->stats.tx_packets += total_tx_packets;
672         return (count < tx_ring->count);
673 }
674
675 /**
676  * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
677  * @adapter: board private structure
678  *
679  * the return value indicates whether actual cleaning was done, there
680  * is no guarantee that everything was cleaned
681  **/
682 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
683                                   int *work_done, int work_to_do)
684 {
685         union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
686         struct net_device *netdev = adapter->netdev;
687         struct pci_dev *pdev = adapter->pdev;
688         struct e1000_ring *rx_ring = adapter->rx_ring;
689         struct e1000_buffer *buffer_info, *next_buffer;
690         struct e1000_ps_page *ps_page;
691         struct sk_buff *skb;
692         unsigned int i, j;
693         u32 length, staterr;
694         int cleaned_count = 0;
695         bool cleaned = 0;
696         unsigned int total_rx_bytes = 0, total_rx_packets = 0;
697
698         i = rx_ring->next_to_clean;
699         rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
700         staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
701         buffer_info = &rx_ring->buffer_info[i];
702
703         while (staterr & E1000_RXD_STAT_DD) {
704                 if (*work_done >= work_to_do)
705                         break;
706                 (*work_done)++;
707                 skb = buffer_info->skb;
708
709                 /* in the packet split case this is header only */
710                 prefetch(skb->data - NET_IP_ALIGN);
711
712                 i++;
713                 if (i == rx_ring->count)
714                         i = 0;
715                 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
716                 prefetch(next_rxd);
717
718                 next_buffer = &rx_ring->buffer_info[i];
719
720                 cleaned = 1;
721                 cleaned_count++;
722                 pci_unmap_single(pdev, buffer_info->dma,
723                                  adapter->rx_ps_bsize0,
724                                  PCI_DMA_FROMDEVICE);
725                 buffer_info->dma = 0;
726
727                 if (!(staterr & E1000_RXD_STAT_EOP)) {
728                         e_dbg("%s: Packet Split buffers didn't pick up the "
729                               "full packet\n", netdev->name);
730                         dev_kfree_skb_irq(skb);
731                         goto next_desc;
732                 }
733
734                 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
735                         dev_kfree_skb_irq(skb);
736                         goto next_desc;
737                 }
738
739                 length = le16_to_cpu(rx_desc->wb.middle.length0);
740
741                 if (!length) {
742                         e_dbg("%s: Last part of the packet spanning multiple "
743                               "descriptors\n", netdev->name);
744                         dev_kfree_skb_irq(skb);
745                         goto next_desc;
746                 }
747
748                 /* Good Receive */
749                 skb_put(skb, length);
750
751                 {
752                 /*
753                  * this looks ugly, but it seems compiler issues make it
754                  * more efficient than reusing j
755                  */
756                 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
757
758                 /*
759                  * page alloc/put takes too long and effects small packet
760                  * throughput, so unsplit small packets and save the alloc/put
761                  * only valid in softirq (napi) context to call kmap_*
762                  */
763                 if (l1 && (l1 <= copybreak) &&
764                     ((length + l1) <= adapter->rx_ps_bsize0)) {
765                         u8 *vaddr;
766
767                         ps_page = &buffer_info->ps_pages[0];
768
769                         /*
770                          * there is no documentation about how to call
771                          * kmap_atomic, so we can't hold the mapping
772                          * very long
773                          */
774                         pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
775                                 PAGE_SIZE, PCI_DMA_FROMDEVICE);
776                         vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
777                         memcpy(skb_tail_pointer(skb), vaddr, l1);
778                         kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
779                         pci_dma_sync_single_for_device(pdev, ps_page->dma,
780                                 PAGE_SIZE, PCI_DMA_FROMDEVICE);
781
782                         /* remove the CRC */
783                         if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
784                                 l1 -= 4;
785
786                         skb_put(skb, l1);
787                         goto copydone;
788                 } /* if */
789                 }
790
791                 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
792                         length = le16_to_cpu(rx_desc->wb.upper.length[j]);
793                         if (!length)
794                                 break;
795
796                         ps_page = &buffer_info->ps_pages[j];
797                         pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
798                                        PCI_DMA_FROMDEVICE);
799                         ps_page->dma = 0;
800                         skb_fill_page_desc(skb, j, ps_page->page, 0, length);
801                         ps_page->page = NULL;
802                         skb->len += length;
803                         skb->data_len += length;
804                         skb->truesize += length;
805                 }
806
807                 /* strip the ethernet crc, problem is we're using pages now so
808                  * this whole operation can get a little cpu intensive
809                  */
810                 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
811                         pskb_trim(skb, skb->len - 4);
812
813 copydone:
814                 total_rx_bytes += skb->len;
815                 total_rx_packets++;
816
817                 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
818                         rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
819
820                 if (rx_desc->wb.upper.header_status &
821                            cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
822                         adapter->rx_hdr_split++;
823
824                 e1000_receive_skb(adapter, netdev, skb,
825                                   staterr, rx_desc->wb.middle.vlan);
826
827 next_desc:
828                 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
829                 buffer_info->skb = NULL;
830
831                 /* return some buffers to hardware, one at a time is too slow */
832                 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
833                         adapter->alloc_rx_buf(adapter, cleaned_count);
834                         cleaned_count = 0;
835                 }
836
837                 /* use prefetched values */
838                 rx_desc = next_rxd;
839                 buffer_info = next_buffer;
840
841                 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
842         }
843         rx_ring->next_to_clean = i;
844
845         cleaned_count = e1000_desc_unused(rx_ring);
846         if (cleaned_count)
847                 adapter->alloc_rx_buf(adapter, cleaned_count);
848
849         adapter->total_rx_bytes += total_rx_bytes;
850         adapter->total_rx_packets += total_rx_packets;
851         netdev->stats.rx_bytes += total_rx_bytes;
852         netdev->stats.rx_packets += total_rx_packets;
853         return cleaned;
854 }
855
856 /**
857  * e1000_consume_page - helper function
858  **/
859 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
860                                u16 length)
861 {
862         bi->page = NULL;
863         skb->len += length;
864         skb->data_len += length;
865         skb->truesize += length;
866 }
867
868 /**
869  * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
870  * @adapter: board private structure
871  *
872  * the return value indicates whether actual cleaning was done, there
873  * is no guarantee that everything was cleaned
874  **/
875
876 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
877                                      int *work_done, int work_to_do)
878 {
879         struct net_device *netdev = adapter->netdev;
880         struct pci_dev *pdev = adapter->pdev;
881         struct e1000_ring *rx_ring = adapter->rx_ring;
882         struct e1000_rx_desc *rx_desc, *next_rxd;
883         struct e1000_buffer *buffer_info, *next_buffer;
884         u32 length;
885         unsigned int i;
886         int cleaned_count = 0;
887         bool cleaned = false;
888         unsigned int total_rx_bytes=0, total_rx_packets=0;
889
890         i = rx_ring->next_to_clean;
891         rx_desc = E1000_RX_DESC(*rx_ring, i);
892         buffer_info = &rx_ring->buffer_info[i];
893
894         while (rx_desc->status & E1000_RXD_STAT_DD) {
895                 struct sk_buff *skb;
896                 u8 status;
897
898                 if (*work_done >= work_to_do)
899                         break;
900                 (*work_done)++;
901
902                 status = rx_desc->status;
903                 skb = buffer_info->skb;
904                 buffer_info->skb = NULL;
905
906                 ++i;
907                 if (i == rx_ring->count)
908                         i = 0;
909                 next_rxd = E1000_RX_DESC(*rx_ring, i);
910                 prefetch(next_rxd);
911
912                 next_buffer = &rx_ring->buffer_info[i];
913
914                 cleaned = true;
915                 cleaned_count++;
916                 pci_unmap_page(pdev, buffer_info->dma, PAGE_SIZE,
917                                PCI_DMA_FROMDEVICE);
918                 buffer_info->dma = 0;
919
920                 length = le16_to_cpu(rx_desc->length);
921
922                 /* errors is only valid for DD + EOP descriptors */
923                 if (unlikely((status & E1000_RXD_STAT_EOP) &&
924                     (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
925                                 /* recycle both page and skb */
926                                 buffer_info->skb = skb;
927                                 /* an error means any chain goes out the window
928                                  * too */
929                                 if (rx_ring->rx_skb_top)
930                                         dev_kfree_skb(rx_ring->rx_skb_top);
931                                 rx_ring->rx_skb_top = NULL;
932                                 goto next_desc;
933                 }
934
935 #define rxtop rx_ring->rx_skb_top
936                 if (!(status & E1000_RXD_STAT_EOP)) {
937                         /* this descriptor is only the beginning (or middle) */
938                         if (!rxtop) {
939                                 /* this is the beginning of a chain */
940                                 rxtop = skb;
941                                 skb_fill_page_desc(rxtop, 0, buffer_info->page,
942                                                    0, length);
943                         } else {
944                                 /* this is the middle of a chain */
945                                 skb_fill_page_desc(rxtop,
946                                     skb_shinfo(rxtop)->nr_frags,
947                                     buffer_info->page, 0, length);
948                                 /* re-use the skb, only consumed the page */
949                                 buffer_info->skb = skb;
950                         }
951                         e1000_consume_page(buffer_info, rxtop, length);
952                         goto next_desc;
953                 } else {
954                         if (rxtop) {
955                                 /* end of the chain */
956                                 skb_fill_page_desc(rxtop,
957                                     skb_shinfo(rxtop)->nr_frags,
958                                     buffer_info->page, 0, length);
959                                 /* re-use the current skb, we only consumed the
960                                  * page */
961                                 buffer_info->skb = skb;
962                                 skb = rxtop;
963                                 rxtop = NULL;
964                                 e1000_consume_page(buffer_info, skb, length);
965                         } else {
966                                 /* no chain, got EOP, this buf is the packet
967                                  * copybreak to save the put_page/alloc_page */
968                                 if (length <= copybreak &&
969                                     skb_tailroom(skb) >= length) {
970                                         u8 *vaddr;
971                                         vaddr = kmap_atomic(buffer_info->page,
972                                                            KM_SKB_DATA_SOFTIRQ);
973                                         memcpy(skb_tail_pointer(skb), vaddr,
974                                                length);
975                                         kunmap_atomic(vaddr,
976                                                       KM_SKB_DATA_SOFTIRQ);
977                                         /* re-use the page, so don't erase
978                                          * buffer_info->page */
979                                         skb_put(skb, length);
980                                 } else {
981                                         skb_fill_page_desc(skb, 0,
982                                                            buffer_info->page, 0,
983                                                            length);
984                                         e1000_consume_page(buffer_info, skb,
985                                                            length);
986                                 }
987                         }
988                 }
989
990                 /* Receive Checksum Offload XXX recompute due to CRC strip? */
991                 e1000_rx_checksum(adapter,
992                                   (u32)(status) |
993                                   ((u32)(rx_desc->errors) << 24),
994                                   le16_to_cpu(rx_desc->csum), skb);
995
996                 /* probably a little skewed due to removing CRC */
997                 total_rx_bytes += skb->len;
998                 total_rx_packets++;
999
1000                 /* eth type trans needs skb->data to point to something */
1001                 if (!pskb_may_pull(skb, ETH_HLEN)) {
1002                         e_err("pskb_may_pull failed.\n");
1003                         dev_kfree_skb(skb);
1004                         goto next_desc;
1005                 }
1006
1007                 e1000_receive_skb(adapter, netdev, skb, status,
1008                                   rx_desc->special);
1009
1010 next_desc:
1011                 rx_desc->status = 0;
1012
1013                 /* return some buffers to hardware, one at a time is too slow */
1014                 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1015                         adapter->alloc_rx_buf(adapter, cleaned_count);
1016                         cleaned_count = 0;
1017                 }
1018
1019                 /* use prefetched values */
1020                 rx_desc = next_rxd;
1021                 buffer_info = next_buffer;
1022         }
1023         rx_ring->next_to_clean = i;
1024
1025         cleaned_count = e1000_desc_unused(rx_ring);
1026         if (cleaned_count)
1027                 adapter->alloc_rx_buf(adapter, cleaned_count);
1028
1029         adapter->total_rx_bytes += total_rx_bytes;
1030         adapter->total_rx_packets += total_rx_packets;
1031         netdev->stats.rx_bytes += total_rx_bytes;
1032         netdev->stats.rx_packets += total_rx_packets;
1033         return cleaned;
1034 }
1035
1036 /**
1037  * e1000_clean_rx_ring - Free Rx Buffers per Queue
1038  * @adapter: board private structure
1039  **/
1040 static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1041 {
1042         struct e1000_ring *rx_ring = adapter->rx_ring;
1043         struct e1000_buffer *buffer_info;
1044         struct e1000_ps_page *ps_page;
1045         struct pci_dev *pdev = adapter->pdev;
1046         unsigned int i, j;
1047
1048         /* Free all the Rx ring sk_buffs */
1049         for (i = 0; i < rx_ring->count; i++) {
1050                 buffer_info = &rx_ring->buffer_info[i];
1051                 if (buffer_info->dma) {
1052                         if (adapter->clean_rx == e1000_clean_rx_irq)
1053                                 pci_unmap_single(pdev, buffer_info->dma,
1054                                                  adapter->rx_buffer_len,
1055                                                  PCI_DMA_FROMDEVICE);
1056                         else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1057                                 pci_unmap_page(pdev, buffer_info->dma,
1058                                                PAGE_SIZE,
1059                                                PCI_DMA_FROMDEVICE);
1060                         else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1061                                 pci_unmap_single(pdev, buffer_info->dma,
1062                                                  adapter->rx_ps_bsize0,
1063                                                  PCI_DMA_FROMDEVICE);
1064                         buffer_info->dma = 0;
1065                 }
1066
1067                 if (buffer_info->page) {
1068                         put_page(buffer_info->page);
1069                         buffer_info->page = NULL;
1070                 }
1071
1072                 if (buffer_info->skb) {
1073                         dev_kfree_skb(buffer_info->skb);
1074                         buffer_info->skb = NULL;
1075                 }
1076
1077                 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1078                         ps_page = &buffer_info->ps_pages[j];
1079                         if (!ps_page->page)
1080                                 break;
1081                         pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
1082                                        PCI_DMA_FROMDEVICE);
1083                         ps_page->dma = 0;
1084                         put_page(ps_page->page);
1085                         ps_page->page = NULL;
1086                 }
1087         }
1088
1089         /* there also may be some cached data from a chained receive */
1090         if (rx_ring->rx_skb_top) {
1091                 dev_kfree_skb(rx_ring->rx_skb_top);
1092                 rx_ring->rx_skb_top = NULL;
1093         }
1094
1095         /* Zero out the descriptor ring */
1096         memset(rx_ring->desc, 0, rx_ring->size);
1097
1098         rx_ring->next_to_clean = 0;
1099         rx_ring->next_to_use = 0;
1100
1101         writel(0, adapter->hw.hw_addr + rx_ring->head);
1102         writel(0, adapter->hw.hw_addr + rx_ring->tail);
1103 }
1104
1105 static void e1000e_downshift_workaround(struct work_struct *work)
1106 {
1107         struct e1000_adapter *adapter = container_of(work,
1108                                         struct e1000_adapter, downshift_task);
1109
1110         e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1111 }
1112
1113 /**
1114  * e1000_intr_msi - Interrupt Handler
1115  * @irq: interrupt number
1116  * @data: pointer to a network interface device structure
1117  **/
1118 static irqreturn_t e1000_intr_msi(int irq, void *data)
1119 {
1120         struct net_device *netdev = data;
1121         struct e1000_adapter *adapter = netdev_priv(netdev);
1122         struct e1000_hw *hw = &adapter->hw;
1123         u32 icr = er32(ICR);
1124
1125         /*
1126          * read ICR disables interrupts using IAM
1127          */
1128
1129         if (icr & E1000_ICR_LSC) {
1130                 hw->mac.get_link_status = 1;
1131                 /*
1132                  * ICH8 workaround-- Call gig speed drop workaround on cable
1133                  * disconnect (LSC) before accessing any PHY registers
1134                  */
1135                 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1136                     (!(er32(STATUS) & E1000_STATUS_LU)))
1137                         schedule_work(&adapter->downshift_task);
1138
1139                 /*
1140                  * 80003ES2LAN workaround-- For packet buffer work-around on
1141                  * link down event; disable receives here in the ISR and reset
1142                  * adapter in watchdog
1143                  */
1144                 if (netif_carrier_ok(netdev) &&
1145                     adapter->flags & FLAG_RX_NEEDS_RESTART) {
1146                         /* disable receives */
1147                         u32 rctl = er32(RCTL);
1148                         ew32(RCTL, rctl & ~E1000_RCTL_EN);
1149                         adapter->flags |= FLAG_RX_RESTART_NOW;
1150                 }
1151                 /* guard against interrupt when we're going down */
1152                 if (!test_bit(__E1000_DOWN, &adapter->state))
1153                         mod_timer(&adapter->watchdog_timer, jiffies + 1);
1154         }
1155
1156         if (napi_schedule_prep(&adapter->napi)) {
1157                 adapter->total_tx_bytes = 0;
1158                 adapter->total_tx_packets = 0;
1159                 adapter->total_rx_bytes = 0;
1160                 adapter->total_rx_packets = 0;
1161                 __napi_schedule(&adapter->napi);
1162         }
1163
1164         return IRQ_HANDLED;
1165 }
1166
1167 /**
1168  * e1000_intr - Interrupt Handler
1169  * @irq: interrupt number
1170  * @data: pointer to a network interface device structure
1171  **/
1172 static irqreturn_t e1000_intr(int irq, void *data)
1173 {
1174         struct net_device *netdev = data;
1175         struct e1000_adapter *adapter = netdev_priv(netdev);
1176         struct e1000_hw *hw = &adapter->hw;
1177         u32 rctl, icr = er32(ICR);
1178
1179         if (!icr || test_bit(__E1000_DOWN, &adapter->state))
1180                 return IRQ_NONE;  /* Not our interrupt */
1181
1182         /*
1183          * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1184          * not set, then the adapter didn't send an interrupt
1185          */
1186         if (!(icr & E1000_ICR_INT_ASSERTED))
1187                 return IRQ_NONE;
1188
1189         /*
1190          * Interrupt Auto-Mask...upon reading ICR,
1191          * interrupts are masked.  No need for the
1192          * IMC write
1193          */
1194
1195         if (icr & E1000_ICR_LSC) {
1196                 hw->mac.get_link_status = 1;
1197                 /*
1198                  * ICH8 workaround-- Call gig speed drop workaround on cable
1199                  * disconnect (LSC) before accessing any PHY registers
1200                  */
1201                 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1202                     (!(er32(STATUS) & E1000_STATUS_LU)))
1203                         schedule_work(&adapter->downshift_task);
1204
1205                 /*
1206                  * 80003ES2LAN workaround--
1207                  * For packet buffer work-around on link down event;
1208                  * disable receives here in the ISR and
1209                  * reset adapter in watchdog
1210                  */
1211                 if (netif_carrier_ok(netdev) &&
1212                     (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1213                         /* disable receives */
1214                         rctl = er32(RCTL);
1215                         ew32(RCTL, rctl & ~E1000_RCTL_EN);
1216                         adapter->flags |= FLAG_RX_RESTART_NOW;
1217                 }
1218                 /* guard against interrupt when we're going down */
1219                 if (!test_bit(__E1000_DOWN, &adapter->state))
1220                         mod_timer(&adapter->watchdog_timer, jiffies + 1);
1221         }
1222
1223         if (napi_schedule_prep(&adapter->napi)) {
1224                 adapter->total_tx_bytes = 0;
1225                 adapter->total_tx_packets = 0;
1226                 adapter->total_rx_bytes = 0;
1227                 adapter->total_rx_packets = 0;
1228                 __napi_schedule(&adapter->napi);
1229         }
1230
1231         return IRQ_HANDLED;
1232 }
1233
1234 static irqreturn_t e1000_msix_other(int irq, void *data)
1235 {
1236         struct net_device *netdev = data;
1237         struct e1000_adapter *adapter = netdev_priv(netdev);
1238         struct e1000_hw *hw = &adapter->hw;
1239         u32 icr = er32(ICR);
1240
1241         if (!(icr & E1000_ICR_INT_ASSERTED)) {
1242                 if (!test_bit(__E1000_DOWN, &adapter->state))
1243                         ew32(IMS, E1000_IMS_OTHER);
1244                 return IRQ_NONE;
1245         }
1246
1247         if (icr & adapter->eiac_mask)
1248                 ew32(ICS, (icr & adapter->eiac_mask));
1249
1250         if (icr & E1000_ICR_OTHER) {
1251                 if (!(icr & E1000_ICR_LSC))
1252                         goto no_link_interrupt;
1253                 hw->mac.get_link_status = 1;
1254                 /* guard against interrupt when we're going down */
1255                 if (!test_bit(__E1000_DOWN, &adapter->state))
1256                         mod_timer(&adapter->watchdog_timer, jiffies + 1);
1257         }
1258
1259 no_link_interrupt:
1260         if (!test_bit(__E1000_DOWN, &adapter->state))
1261                 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
1262
1263         return IRQ_HANDLED;
1264 }
1265
1266
1267 static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1268 {
1269         struct net_device *netdev = data;
1270         struct e1000_adapter *adapter = netdev_priv(netdev);
1271         struct e1000_hw *hw = &adapter->hw;
1272         struct e1000_ring *tx_ring = adapter->tx_ring;
1273
1274
1275         adapter->total_tx_bytes = 0;
1276         adapter->total_tx_packets = 0;
1277
1278         if (!e1000_clean_tx_irq(adapter))
1279                 /* Ring was not completely cleaned, so fire another interrupt */
1280                 ew32(ICS, tx_ring->ims_val);
1281
1282         return IRQ_HANDLED;
1283 }
1284
1285 static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1286 {
1287         struct net_device *netdev = data;
1288         struct e1000_adapter *adapter = netdev_priv(netdev);
1289
1290         /* Write the ITR value calculated at the end of the
1291          * previous interrupt.
1292          */
1293         if (adapter->rx_ring->set_itr) {
1294                 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1295                        adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1296                 adapter->rx_ring->set_itr = 0;
1297         }
1298
1299         if (napi_schedule_prep(&adapter->napi)) {
1300                 adapter->total_rx_bytes = 0;
1301                 adapter->total_rx_packets = 0;
1302                 __napi_schedule(&adapter->napi);
1303         }
1304         return IRQ_HANDLED;
1305 }
1306
1307 /**
1308  * e1000_configure_msix - Configure MSI-X hardware
1309  *
1310  * e1000_configure_msix sets up the hardware to properly
1311  * generate MSI-X interrupts.
1312  **/
1313 static void e1000_configure_msix(struct e1000_adapter *adapter)
1314 {
1315         struct e1000_hw *hw = &adapter->hw;
1316         struct e1000_ring *rx_ring = adapter->rx_ring;
1317         struct e1000_ring *tx_ring = adapter->tx_ring;
1318         int vector = 0;
1319         u32 ctrl_ext, ivar = 0;
1320
1321         adapter->eiac_mask = 0;
1322
1323         /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1324         if (hw->mac.type == e1000_82574) {
1325                 u32 rfctl = er32(RFCTL);
1326                 rfctl |= E1000_RFCTL_ACK_DIS;
1327                 ew32(RFCTL, rfctl);
1328         }
1329
1330 #define E1000_IVAR_INT_ALLOC_VALID      0x8
1331         /* Configure Rx vector */
1332         rx_ring->ims_val = E1000_IMS_RXQ0;
1333         adapter->eiac_mask |= rx_ring->ims_val;
1334         if (rx_ring->itr_val)
1335                 writel(1000000000 / (rx_ring->itr_val * 256),
1336                        hw->hw_addr + rx_ring->itr_register);
1337         else
1338                 writel(1, hw->hw_addr + rx_ring->itr_register);
1339         ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1340
1341         /* Configure Tx vector */
1342         tx_ring->ims_val = E1000_IMS_TXQ0;
1343         vector++;
1344         if (tx_ring->itr_val)
1345                 writel(1000000000 / (tx_ring->itr_val * 256),
1346                        hw->hw_addr + tx_ring->itr_register);
1347         else
1348                 writel(1, hw->hw_addr + tx_ring->itr_register);
1349         adapter->eiac_mask |= tx_ring->ims_val;
1350         ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1351
1352         /* set vector for Other Causes, e.g. link changes */
1353         vector++;
1354         ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1355         if (rx_ring->itr_val)
1356                 writel(1000000000 / (rx_ring->itr_val * 256),
1357                        hw->hw_addr + E1000_EITR_82574(vector));
1358         else
1359                 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1360
1361         /* Cause Tx interrupts on every write back */
1362         ivar |= (1 << 31);
1363
1364         ew32(IVAR, ivar);
1365
1366         /* enable MSI-X PBA support */
1367         ctrl_ext = er32(CTRL_EXT);
1368         ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1369
1370         /* Auto-Mask Other interrupts upon ICR read */
1371 #define E1000_EIAC_MASK_82574   0x01F00000
1372         ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1373         ctrl_ext |= E1000_CTRL_EXT_EIAME;
1374         ew32(CTRL_EXT, ctrl_ext);
1375         e1e_flush();
1376 }
1377
1378 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1379 {
1380         if (adapter->msix_entries) {
1381                 pci_disable_msix(adapter->pdev);
1382                 kfree(adapter->msix_entries);
1383                 adapter->msix_entries = NULL;
1384         } else if (adapter->flags & FLAG_MSI_ENABLED) {
1385                 pci_disable_msi(adapter->pdev);
1386                 adapter->flags &= ~FLAG_MSI_ENABLED;
1387         }
1388
1389         return;
1390 }
1391
1392 /**
1393  * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1394  *
1395  * Attempt to configure interrupts using the best available
1396  * capabilities of the hardware and kernel.
1397  **/
1398 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1399 {
1400         int err;
1401         int numvecs, i;
1402
1403
1404         switch (adapter->int_mode) {
1405         case E1000E_INT_MODE_MSIX:
1406                 if (adapter->flags & FLAG_HAS_MSIX) {
1407                         numvecs = 3; /* RxQ0, TxQ0 and other */
1408                         adapter->msix_entries = kcalloc(numvecs,
1409                                                       sizeof(struct msix_entry),
1410                                                       GFP_KERNEL);
1411                         if (adapter->msix_entries) {
1412                                 for (i = 0; i < numvecs; i++)
1413                                         adapter->msix_entries[i].entry = i;
1414
1415                                 err = pci_enable_msix(adapter->pdev,
1416                                                       adapter->msix_entries,
1417                                                       numvecs);
1418                                 if (err == 0)
1419                                         return;
1420                         }
1421                         /* MSI-X failed, so fall through and try MSI */
1422                         e_err("Failed to initialize MSI-X interrupts.  "
1423                               "Falling back to MSI interrupts.\n");
1424                         e1000e_reset_interrupt_capability(adapter);
1425                 }
1426                 adapter->int_mode = E1000E_INT_MODE_MSI;
1427                 /* Fall through */
1428         case E1000E_INT_MODE_MSI:
1429                 if (!pci_enable_msi(adapter->pdev)) {
1430                         adapter->flags |= FLAG_MSI_ENABLED;
1431                 } else {
1432                         adapter->int_mode = E1000E_INT_MODE_LEGACY;
1433                         e_err("Failed to initialize MSI interrupts.  Falling "
1434                               "back to legacy interrupts.\n");
1435                 }
1436                 /* Fall through */
1437         case E1000E_INT_MODE_LEGACY:
1438                 /* Don't do anything; this is the system default */
1439                 break;
1440         }
1441
1442         return;
1443 }
1444
1445 /**
1446  * e1000_request_msix - Initialize MSI-X interrupts
1447  *
1448  * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1449  * kernel.
1450  **/
1451 static int e1000_request_msix(struct e1000_adapter *adapter)
1452 {
1453         struct net_device *netdev = adapter->netdev;
1454         int err = 0, vector = 0;
1455
1456         if (strlen(netdev->name) < (IFNAMSIZ - 5))
1457                 sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
1458         else
1459                 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1460         err = request_irq(adapter->msix_entries[vector].vector,
1461                           e1000_intr_msix_rx, 0, adapter->rx_ring->name,
1462                           netdev);
1463         if (err)
1464                 goto out;
1465         adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1466         adapter->rx_ring->itr_val = adapter->itr;
1467         vector++;
1468
1469         if (strlen(netdev->name) < (IFNAMSIZ - 5))
1470                 sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
1471         else
1472                 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1473         err = request_irq(adapter->msix_entries[vector].vector,
1474                           e1000_intr_msix_tx, 0, adapter->tx_ring->name,
1475                           netdev);
1476         if (err)
1477                 goto out;
1478         adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1479         adapter->tx_ring->itr_val = adapter->itr;
1480         vector++;
1481
1482         err = request_irq(adapter->msix_entries[vector].vector,
1483                           e1000_msix_other, 0, netdev->name, netdev);
1484         if (err)
1485                 goto out;
1486
1487         e1000_configure_msix(adapter);
1488         return 0;
1489 out:
1490         return err;
1491 }
1492
1493 /**
1494  * e1000_request_irq - initialize interrupts
1495  *
1496  * Attempts to configure interrupts using the best available
1497  * capabilities of the hardware and kernel.
1498  **/
1499 static int e1000_request_irq(struct e1000_adapter *adapter)
1500 {
1501         struct net_device *netdev = adapter->netdev;
1502         int err;
1503
1504         if (adapter->msix_entries) {
1505                 err = e1000_request_msix(adapter);
1506                 if (!err)
1507                         return err;
1508                 /* fall back to MSI */
1509                 e1000e_reset_interrupt_capability(adapter);
1510                 adapter->int_mode = E1000E_INT_MODE_MSI;
1511                 e1000e_set_interrupt_capability(adapter);
1512         }
1513         if (adapter->flags & FLAG_MSI_ENABLED) {
1514                 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
1515                                   netdev->name, netdev);
1516                 if (!err)
1517                         return err;
1518
1519                 /* fall back to legacy interrupt */
1520                 e1000e_reset_interrupt_capability(adapter);
1521                 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1522         }
1523
1524         err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
1525                           netdev->name, netdev);
1526         if (err)
1527                 e_err("Unable to allocate interrupt, Error: %d\n", err);
1528
1529         return err;
1530 }
1531
1532 static void e1000_free_irq(struct e1000_adapter *adapter)
1533 {
1534         struct net_device *netdev = adapter->netdev;
1535
1536         if (adapter->msix_entries) {
1537                 int vector = 0;
1538
1539                 free_irq(adapter->msix_entries[vector].vector, netdev);
1540                 vector++;
1541
1542                 free_irq(adapter->msix_entries[vector].vector, netdev);
1543                 vector++;
1544
1545                 /* Other Causes interrupt vector */
1546                 free_irq(adapter->msix_entries[vector].vector, netdev);
1547                 return;
1548         }
1549
1550         free_irq(adapter->pdev->irq, netdev);
1551 }
1552
1553 /**
1554  * e1000_irq_disable - Mask off interrupt generation on the NIC
1555  **/
1556 static void e1000_irq_disable(struct e1000_adapter *adapter)
1557 {
1558         struct e1000_hw *hw = &adapter->hw;
1559
1560         ew32(IMC, ~0);
1561         if (adapter->msix_entries)
1562                 ew32(EIAC_82574, 0);
1563         e1e_flush();
1564         synchronize_irq(adapter->pdev->irq);
1565 }
1566
1567 /**
1568  * e1000_irq_enable - Enable default interrupt generation settings
1569  **/
1570 static void e1000_irq_enable(struct e1000_adapter *adapter)
1571 {
1572         struct e1000_hw *hw = &adapter->hw;
1573
1574         if (adapter->msix_entries) {
1575                 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1576                 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1577         } else {
1578                 ew32(IMS, IMS_ENABLE_MASK);
1579         }
1580         e1e_flush();
1581 }
1582
1583 /**
1584  * e1000_get_hw_control - get control of the h/w from f/w
1585  * @adapter: address of board private structure
1586  *
1587  * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1588  * For ASF and Pass Through versions of f/w this means that
1589  * the driver is loaded. For AMT version (only with 82573)
1590  * of the f/w this means that the network i/f is open.
1591  **/
1592 static void e1000_get_hw_control(struct e1000_adapter *adapter)
1593 {
1594         struct e1000_hw *hw = &adapter->hw;
1595         u32 ctrl_ext;
1596         u32 swsm;
1597
1598         /* Let firmware know the driver has taken over */
1599         if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1600                 swsm = er32(SWSM);
1601                 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1602         } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1603                 ctrl_ext = er32(CTRL_EXT);
1604                 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1605         }
1606 }
1607
1608 /**
1609  * e1000_release_hw_control - release control of the h/w to f/w
1610  * @adapter: address of board private structure
1611  *
1612  * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
1613  * For ASF and Pass Through versions of f/w this means that the
1614  * driver is no longer loaded. For AMT version (only with 82573) i
1615  * of the f/w this means that the network i/f is closed.
1616  *
1617  **/
1618 static void e1000_release_hw_control(struct e1000_adapter *adapter)
1619 {
1620         struct e1000_hw *hw = &adapter->hw;
1621         u32 ctrl_ext;
1622         u32 swsm;
1623
1624         /* Let firmware taken over control of h/w */
1625         if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1626                 swsm = er32(SWSM);
1627                 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1628         } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1629                 ctrl_ext = er32(CTRL_EXT);
1630                 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1631         }
1632 }
1633
1634 /**
1635  * @e1000_alloc_ring - allocate memory for a ring structure
1636  **/
1637 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
1638                                 struct e1000_ring *ring)
1639 {
1640         struct pci_dev *pdev = adapter->pdev;
1641
1642         ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
1643                                         GFP_KERNEL);
1644         if (!ring->desc)
1645                 return -ENOMEM;
1646
1647         return 0;
1648 }
1649
1650 /**
1651  * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1652  * @adapter: board private structure
1653  *
1654  * Return 0 on success, negative on failure
1655  **/
1656 int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
1657 {
1658         struct e1000_ring *tx_ring = adapter->tx_ring;
1659         int err = -ENOMEM, size;
1660
1661         size = sizeof(struct e1000_buffer) * tx_ring->count;
1662         tx_ring->buffer_info = vmalloc(size);
1663         if (!tx_ring->buffer_info)
1664                 goto err;
1665         memset(tx_ring->buffer_info, 0, size);
1666
1667         /* round up to nearest 4K */
1668         tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1669         tx_ring->size = ALIGN(tx_ring->size, 4096);
1670
1671         err = e1000_alloc_ring_dma(adapter, tx_ring);
1672         if (err)
1673                 goto err;
1674
1675         tx_ring->next_to_use = 0;
1676         tx_ring->next_to_clean = 0;
1677
1678         return 0;
1679 err:
1680         vfree(tx_ring->buffer_info);
1681         e_err("Unable to allocate memory for the transmit descriptor ring\n");
1682         return err;
1683 }
1684
1685 /**
1686  * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1687  * @adapter: board private structure
1688  *
1689  * Returns 0 on success, negative on failure
1690  **/
1691 int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
1692 {
1693         struct e1000_ring *rx_ring = adapter->rx_ring;
1694         struct e1000_buffer *buffer_info;
1695         int i, size, desc_len, err = -ENOMEM;
1696
1697         size = sizeof(struct e1000_buffer) * rx_ring->count;
1698         rx_ring->buffer_info = vmalloc(size);
1699         if (!rx_ring->buffer_info)
1700                 goto err;
1701         memset(rx_ring->buffer_info, 0, size);
1702
1703         for (i = 0; i < rx_ring->count; i++) {
1704                 buffer_info = &rx_ring->buffer_info[i];
1705                 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
1706                                                 sizeof(struct e1000_ps_page),
1707                                                 GFP_KERNEL);
1708                 if (!buffer_info->ps_pages)
1709                         goto err_pages;
1710         }
1711
1712         desc_len = sizeof(union e1000_rx_desc_packet_split);
1713
1714         /* Round up to nearest 4K */
1715         rx_ring->size = rx_ring->count * desc_len;
1716         rx_ring->size = ALIGN(rx_ring->size, 4096);
1717
1718         err = e1000_alloc_ring_dma(adapter, rx_ring);
1719         if (err)
1720                 goto err_pages;
1721
1722         rx_ring->next_to_clean = 0;
1723         rx_ring->next_to_use = 0;
1724         rx_ring->rx_skb_top = NULL;
1725
1726         return 0;
1727
1728 err_pages:
1729         for (i = 0; i < rx_ring->count; i++) {
1730                 buffer_info = &rx_ring->buffer_info[i];
1731                 kfree(buffer_info->ps_pages);
1732         }
1733 err:
1734         vfree(rx_ring->buffer_info);
1735         e_err("Unable to allocate memory for the transmit descriptor ring\n");
1736         return err;
1737 }
1738
1739 /**
1740  * e1000_clean_tx_ring - Free Tx Buffers
1741  * @adapter: board private structure
1742  **/
1743 static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
1744 {
1745         struct e1000_ring *tx_ring = adapter->tx_ring;
1746         struct e1000_buffer *buffer_info;
1747         unsigned long size;
1748         unsigned int i;
1749
1750         for (i = 0; i < tx_ring->count; i++) {
1751                 buffer_info = &tx_ring->buffer_info[i];
1752                 e1000_put_txbuf(adapter, buffer_info);
1753         }
1754
1755         size = sizeof(struct e1000_buffer) * tx_ring->count;
1756         memset(tx_ring->buffer_info, 0, size);
1757
1758         memset(tx_ring->desc, 0, tx_ring->size);
1759
1760         tx_ring->next_to_use = 0;
1761         tx_ring->next_to_clean = 0;
1762
1763         writel(0, adapter->hw.hw_addr + tx_ring->head);
1764         writel(0, adapter->hw.hw_addr + tx_ring->tail);
1765 }
1766
1767 /**
1768  * e1000e_free_tx_resources - Free Tx Resources per Queue
1769  * @adapter: board private structure
1770  *
1771  * Free all transmit software resources
1772  **/
1773 void e1000e_free_tx_resources(struct e1000_adapter *adapter)
1774 {
1775         struct pci_dev *pdev = adapter->pdev;
1776         struct e1000_ring *tx_ring = adapter->tx_ring;
1777
1778         e1000_clean_tx_ring(adapter);
1779
1780         vfree(tx_ring->buffer_info);
1781         tx_ring->buffer_info = NULL;
1782
1783         dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1784                           tx_ring->dma);
1785         tx_ring->desc = NULL;
1786 }
1787
1788 /**
1789  * e1000e_free_rx_resources - Free Rx Resources
1790  * @adapter: board private structure
1791  *
1792  * Free all receive software resources
1793  **/
1794
1795 void e1000e_free_rx_resources(struct e1000_adapter *adapter)
1796 {
1797         struct pci_dev *pdev = adapter->pdev;
1798         struct e1000_ring *rx_ring = adapter->rx_ring;
1799         int i;
1800
1801         e1000_clean_rx_ring(adapter);
1802
1803         for (i = 0; i < rx_ring->count; i++) {
1804                 kfree(rx_ring->buffer_info[i].ps_pages);
1805         }
1806
1807         vfree(rx_ring->buffer_info);
1808         rx_ring->buffer_info = NULL;
1809
1810         dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1811                           rx_ring->dma);
1812         rx_ring->desc = NULL;
1813 }
1814
1815 /**
1816  * e1000_update_itr - update the dynamic ITR value based on statistics
1817  * @adapter: pointer to adapter
1818  * @itr_setting: current adapter->itr
1819  * @packets: the number of packets during this measurement interval
1820  * @bytes: the number of bytes during this measurement interval
1821  *
1822  *      Stores a new ITR value based on packets and byte
1823  *      counts during the last interrupt.  The advantage of per interrupt
1824  *      computation is faster updates and more accurate ITR for the current
1825  *      traffic pattern.  Constants in this function were computed
1826  *      based on theoretical maximum wire speed and thresholds were set based
1827  *      on testing data as well as attempting to minimize response time
1828  *      while increasing bulk throughput.  This functionality is controlled
1829  *      by the InterruptThrottleRate module parameter.
1830  **/
1831 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
1832                                      u16 itr_setting, int packets,
1833                                      int bytes)
1834 {
1835         unsigned int retval = itr_setting;
1836
1837         if (packets == 0)
1838                 goto update_itr_done;
1839
1840         switch (itr_setting) {
1841         case lowest_latency:
1842                 /* handle TSO and jumbo frames */
1843                 if (bytes/packets > 8000)
1844                         retval = bulk_latency;
1845                 else if ((packets < 5) && (bytes > 512)) {
1846                         retval = low_latency;
1847                 }
1848                 break;
1849         case low_latency:  /* 50 usec aka 20000 ints/s */
1850                 if (bytes > 10000) {
1851                         /* this if handles the TSO accounting */
1852                         if (bytes/packets > 8000) {
1853                                 retval = bulk_latency;
1854                         } else if ((packets < 10) || ((bytes/packets) > 1200)) {
1855                                 retval = bulk_latency;
1856                         } else if ((packets > 35)) {
1857                                 retval = lowest_latency;
1858                         }
1859                 } else if (bytes/packets > 2000) {
1860                         retval = bulk_latency;
1861                 } else if (packets <= 2 && bytes < 512) {
1862                         retval = lowest_latency;
1863                 }
1864                 break;
1865         case bulk_latency: /* 250 usec aka 4000 ints/s */
1866                 if (bytes > 25000) {
1867                         if (packets > 35) {
1868                                 retval = low_latency;
1869                         }
1870                 } else if (bytes < 6000) {
1871                         retval = low_latency;
1872                 }
1873                 break;
1874         }
1875
1876 update_itr_done:
1877         return retval;
1878 }
1879
1880 static void e1000_set_itr(struct e1000_adapter *adapter)
1881 {
1882         struct e1000_hw *hw = &adapter->hw;
1883         u16 current_itr;
1884         u32 new_itr = adapter->itr;
1885
1886         /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1887         if (adapter->link_speed != SPEED_1000) {
1888                 current_itr = 0;
1889                 new_itr = 4000;
1890                 goto set_itr_now;
1891         }
1892
1893         adapter->tx_itr = e1000_update_itr(adapter,
1894                                     adapter->tx_itr,
1895                                     adapter->total_tx_packets,
1896                                     adapter->total_tx_bytes);
1897         /* conservative mode (itr 3) eliminates the lowest_latency setting */
1898         if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
1899                 adapter->tx_itr = low_latency;
1900
1901         adapter->rx_itr = e1000_update_itr(adapter,
1902                                     adapter->rx_itr,
1903                                     adapter->total_rx_packets,
1904                                     adapter->total_rx_bytes);
1905         /* conservative mode (itr 3) eliminates the lowest_latency setting */
1906         if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
1907                 adapter->rx_itr = low_latency;
1908
1909         current_itr = max(adapter->rx_itr, adapter->tx_itr);
1910
1911         switch (current_itr) {
1912         /* counts and packets in update_itr are dependent on these numbers */
1913         case lowest_latency:
1914                 new_itr = 70000;
1915                 break;
1916         case low_latency:
1917                 new_itr = 20000; /* aka hwitr = ~200 */
1918                 break;
1919         case bulk_latency:
1920                 new_itr = 4000;
1921                 break;
1922         default:
1923                 break;
1924         }
1925
1926 set_itr_now:
1927         if (new_itr != adapter->itr) {
1928                 /*
1929                  * this attempts to bias the interrupt rate towards Bulk
1930                  * by adding intermediate steps when interrupt rate is
1931                  * increasing
1932                  */
1933                 new_itr = new_itr > adapter->itr ?
1934                              min(adapter->itr + (new_itr >> 2), new_itr) :
1935                              new_itr;
1936                 adapter->itr = new_itr;
1937                 adapter->rx_ring->itr_val = new_itr;
1938                 if (adapter->msix_entries)
1939                         adapter->rx_ring->set_itr = 1;
1940                 else
1941                         ew32(ITR, 1000000000 / (new_itr * 256));
1942         }
1943 }
1944
1945 /**
1946  * e1000_alloc_queues - Allocate memory for all rings
1947  * @adapter: board private structure to initialize
1948  **/
1949 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1950 {
1951         adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1952         if (!adapter->tx_ring)
1953                 goto err;
1954
1955         adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1956         if (!adapter->rx_ring)
1957                 goto err;
1958
1959         return 0;
1960 err:
1961         e_err("Unable to allocate memory for queues\n");
1962         kfree(adapter->rx_ring);
1963         kfree(adapter->tx_ring);
1964         return -ENOMEM;
1965 }
1966
1967 /**
1968  * e1000_clean - NAPI Rx polling callback
1969  * @napi: struct associated with this polling callback
1970  * @budget: amount of packets driver is allowed to process this poll
1971  **/
1972 static int e1000_clean(struct napi_struct *napi, int budget)
1973 {
1974         struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
1975         struct e1000_hw *hw = &adapter->hw;
1976         struct net_device *poll_dev = adapter->netdev;
1977         int tx_cleaned = 1, work_done = 0;
1978
1979         adapter = netdev_priv(poll_dev);
1980
1981         if (adapter->msix_entries &&
1982             !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
1983                 goto clean_rx;
1984
1985         tx_cleaned = e1000_clean_tx_irq(adapter);
1986
1987 clean_rx:
1988         adapter->clean_rx(adapter, &work_done, budget);
1989
1990         if (!tx_cleaned)
1991                 work_done = budget;
1992
1993         /* If budget not fully consumed, exit the polling mode */
1994         if (work_done < budget) {
1995                 if (adapter->itr_setting & 3)
1996                         e1000_set_itr(adapter);
1997                 napi_complete(napi);
1998                 if (!test_bit(__E1000_DOWN, &adapter->state)) {
1999                         if (adapter->msix_entries)
2000                                 ew32(IMS, adapter->rx_ring->ims_val);
2001                         else
2002                                 e1000_irq_enable(adapter);
2003                 }
2004         }
2005
2006         return work_done;
2007 }
2008
2009 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2010 {
2011         struct e1000_adapter *adapter = netdev_priv(netdev);
2012         struct e1000_hw *hw = &adapter->hw;
2013         u32 vfta, index;
2014
2015         /* don't update vlan cookie if already programmed */
2016         if ((adapter->hw.mng_cookie.status &
2017              E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2018             (vid == adapter->mng_vlan_id))
2019                 return;
2020         /* add VID to filter table */
2021         index = (vid >> 5) & 0x7F;
2022         vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2023         vfta |= (1 << (vid & 0x1F));
2024         e1000e_write_vfta(hw, index, vfta);
2025 }
2026
2027 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2028 {
2029         struct e1000_adapter *adapter = netdev_priv(netdev);
2030         struct e1000_hw *hw = &adapter->hw;
2031         u32 vfta, index;
2032
2033         if (!test_bit(__E1000_DOWN, &adapter->state))
2034                 e1000_irq_disable(adapter);
2035         vlan_group_set_device(adapter->vlgrp, vid, NULL);
2036
2037         if (!test_bit(__E1000_DOWN, &adapter->state))
2038                 e1000_irq_enable(adapter);
2039
2040         if ((adapter->hw.mng_cookie.status &
2041              E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2042             (vid == adapter->mng_vlan_id)) {
2043                 /* release control to f/w */
2044                 e1000_release_hw_control(adapter);
2045                 return;
2046         }
2047
2048         /* remove VID from filter table */
2049         index = (vid >> 5) & 0x7F;
2050         vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2051         vfta &= ~(1 << (vid & 0x1F));
2052         e1000e_write_vfta(hw, index, vfta);
2053 }
2054
2055 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2056 {
2057         struct net_device *netdev = adapter->netdev;
2058         u16 vid = adapter->hw.mng_cookie.vlan_id;
2059         u16 old_vid = adapter->mng_vlan_id;
2060
2061         if (!adapter->vlgrp)
2062                 return;
2063
2064         if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2065                 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2066                 if (adapter->hw.mng_cookie.status &
2067                         E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2068                         e1000_vlan_rx_add_vid(netdev, vid);
2069                         adapter->mng_vlan_id = vid;
2070                 }
2071
2072                 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2073                                 (vid != old_vid) &&
2074                     !vlan_group_get_device(adapter->vlgrp, old_vid))
2075                         e1000_vlan_rx_kill_vid(netdev, old_vid);
2076         } else {
2077                 adapter->mng_vlan_id = vid;
2078         }
2079 }
2080
2081
2082 static void e1000_vlan_rx_register(struct net_device *netdev,
2083                                    struct vlan_group *grp)
2084 {
2085         struct e1000_adapter *adapter = netdev_priv(netdev);
2086         struct e1000_hw *hw = &adapter->hw;
2087         u32 ctrl, rctl;
2088
2089         if (!test_bit(__E1000_DOWN, &adapter->state))
2090                 e1000_irq_disable(adapter);
2091         adapter->vlgrp = grp;
2092
2093         if (grp) {
2094                 /* enable VLAN tag insert/strip */
2095                 ctrl = er32(CTRL);
2096                 ctrl |= E1000_CTRL_VME;
2097                 ew32(CTRL, ctrl);
2098
2099                 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2100                         /* enable VLAN receive filtering */
2101                         rctl = er32(RCTL);
2102                         rctl &= ~E1000_RCTL_CFIEN;
2103                         ew32(RCTL, rctl);
2104                         e1000_update_mng_vlan(adapter);
2105                 }
2106         } else {
2107                 /* disable VLAN tag insert/strip */
2108                 ctrl = er32(CTRL);
2109                 ctrl &= ~E1000_CTRL_VME;
2110                 ew32(CTRL, ctrl);
2111
2112                 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2113                         if (adapter->mng_vlan_id !=
2114                             (u16)E1000_MNG_VLAN_NONE) {
2115                                 e1000_vlan_rx_kill_vid(netdev,
2116                                                        adapter->mng_vlan_id);
2117                                 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2118                         }
2119                 }
2120         }
2121
2122         if (!test_bit(__E1000_DOWN, &adapter->state))
2123                 e1000_irq_enable(adapter);
2124 }
2125
2126 static void e1000_restore_vlan(struct e1000_adapter *adapter)
2127 {
2128         u16 vid;
2129
2130         e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2131
2132         if (!adapter->vlgrp)
2133                 return;
2134
2135         for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2136                 if (!vlan_group_get_device(adapter->vlgrp, vid))
2137                         continue;
2138                 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2139         }
2140 }
2141
2142 static void e1000_init_manageability(struct e1000_adapter *adapter)
2143 {
2144         struct e1000_hw *hw = &adapter->hw;
2145         u32 manc, manc2h;
2146
2147         if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2148                 return;
2149
2150         manc = er32(MANC);
2151
2152         /*
2153          * enable receiving management packets to the host. this will probably
2154          * generate destination unreachable messages from the host OS, but
2155          * the packets will be handled on SMBUS
2156          */
2157         manc |= E1000_MANC_EN_MNG2HOST;
2158         manc2h = er32(MANC2H);
2159 #define E1000_MNG2HOST_PORT_623 (1 << 5)
2160 #define E1000_MNG2HOST_PORT_664 (1 << 6)
2161         manc2h |= E1000_MNG2HOST_PORT_623;
2162         manc2h |= E1000_MNG2HOST_PORT_664;
2163         ew32(MANC2H, manc2h);
2164         ew32(MANC, manc);
2165 }
2166
2167 /**
2168  * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2169  * @adapter: board private structure
2170  *
2171  * Configure the Tx unit of the MAC after a reset.
2172  **/
2173 static void e1000_configure_tx(struct e1000_adapter *adapter)
2174 {
2175         struct e1000_hw *hw = &adapter->hw;
2176         struct e1000_ring *tx_ring = adapter->tx_ring;
2177         u64 tdba;
2178         u32 tdlen, tctl, tipg, tarc;
2179         u32 ipgr1, ipgr2;
2180
2181         /* Setup the HW Tx Head and Tail descriptor pointers */
2182         tdba = tx_ring->dma;
2183         tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2184         ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
2185         ew32(TDBAH, (tdba >> 32));
2186         ew32(TDLEN, tdlen);
2187         ew32(TDH, 0);
2188         ew32(TDT, 0);
2189         tx_ring->head = E1000_TDH;
2190         tx_ring->tail = E1000_TDT;
2191
2192         /* Set the default values for the Tx Inter Packet Gap timer */
2193         tipg = DEFAULT_82543_TIPG_IPGT_COPPER;          /*  8  */
2194         ipgr1 = DEFAULT_82543_TIPG_IPGR1;               /*  8  */
2195         ipgr2 = DEFAULT_82543_TIPG_IPGR2;               /*  6  */
2196
2197         if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2198                 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /*  7  */
2199
2200         tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2201         tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2202         ew32(TIPG, tipg);
2203
2204         /* Set the Tx Interrupt Delay register */
2205         ew32(TIDV, adapter->tx_int_delay);
2206         /* Tx irq moderation */
2207         ew32(TADV, adapter->tx_abs_int_delay);
2208
2209         /* Program the Transmit Control Register */
2210         tctl = er32(TCTL);
2211         tctl &= ~E1000_TCTL_CT;
2212         tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2213                 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2214
2215         if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
2216                 tarc = er32(TARC(0));
2217                 /*
2218                  * set the speed mode bit, we'll clear it if we're not at
2219                  * gigabit link later
2220                  */
2221 #define SPEED_MODE_BIT (1 << 21)
2222                 tarc |= SPEED_MODE_BIT;
2223                 ew32(TARC(0), tarc);
2224         }
2225
2226         /* errata: program both queues to unweighted RR */
2227         if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
2228                 tarc = er32(TARC(0));
2229                 tarc |= 1;
2230                 ew32(TARC(0), tarc);
2231                 tarc = er32(TARC(1));
2232                 tarc |= 1;
2233                 ew32(TARC(1), tarc);
2234         }
2235
2236         /* Setup Transmit Descriptor Settings for eop descriptor */
2237         adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2238
2239         /* only set IDE if we are delaying interrupts using the timers */
2240         if (adapter->tx_int_delay)
2241                 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2242
2243         /* enable Report Status bit */
2244         adapter->txd_cmd |= E1000_TXD_CMD_RS;
2245
2246         ew32(TCTL, tctl);
2247
2248         e1000e_config_collision_dist(hw);
2249
2250         adapter->tx_queue_len = adapter->netdev->tx_queue_len;
2251 }
2252
2253 /**
2254  * e1000_setup_rctl - configure the receive control registers
2255  * @adapter: Board private structure
2256  **/
2257 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2258                            (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2259 static void e1000_setup_rctl(struct e1000_adapter *adapter)
2260 {
2261         struct e1000_hw *hw = &adapter->hw;
2262         u32 rctl, rfctl;
2263         u32 psrctl = 0;
2264         u32 pages = 0;
2265
2266         /* Program MC offset vector base */
2267         rctl = er32(RCTL);
2268         rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2269         rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2270                 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2271                 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2272
2273         /* Do not Store bad packets */
2274         rctl &= ~E1000_RCTL_SBP;
2275
2276         /* Enable Long Packet receive */
2277         if (adapter->netdev->mtu <= ETH_DATA_LEN)
2278                 rctl &= ~E1000_RCTL_LPE;
2279         else
2280                 rctl |= E1000_RCTL_LPE;
2281
2282         /* Some systems expect that the CRC is included in SMBUS traffic. The
2283          * hardware strips the CRC before sending to both SMBUS (BMC) and to
2284          * host memory when this is enabled
2285          */
2286         if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2287                 rctl |= E1000_RCTL_SECRC;
2288
2289         /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2290         if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2291                 u16 phy_data;
2292
2293                 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2294                 phy_data &= 0xfff8;
2295                 phy_data |= (1 << 2);
2296                 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2297
2298                 e1e_rphy(hw, 22, &phy_data);
2299                 phy_data &= 0x0fff;
2300                 phy_data |= (1 << 14);
2301                 e1e_wphy(hw, 0x10, 0x2823);
2302                 e1e_wphy(hw, 0x11, 0x0003);
2303                 e1e_wphy(hw, 22, phy_data);
2304         }
2305
2306         /* Setup buffer sizes */
2307         rctl &= ~E1000_RCTL_SZ_4096;
2308         rctl |= E1000_RCTL_BSEX;
2309         switch (adapter->rx_buffer_len) {
2310         case 256:
2311                 rctl |= E1000_RCTL_SZ_256;
2312                 rctl &= ~E1000_RCTL_BSEX;
2313                 break;
2314         case 512:
2315                 rctl |= E1000_RCTL_SZ_512;
2316                 rctl &= ~E1000_RCTL_BSEX;
2317                 break;
2318         case 1024:
2319                 rctl |= E1000_RCTL_SZ_1024;
2320                 rctl &= ~E1000_RCTL_BSEX;
2321                 break;
2322         case 2048:
2323         default:
2324                 rctl |= E1000_RCTL_SZ_2048;
2325                 rctl &= ~E1000_RCTL_BSEX;
2326                 break;
2327         case 4096:
2328                 rctl |= E1000_RCTL_SZ_4096;
2329                 break;
2330         case 8192:
2331                 rctl |= E1000_RCTL_SZ_8192;
2332                 break;
2333         case 16384:
2334                 rctl |= E1000_RCTL_SZ_16384;
2335                 break;
2336         }
2337
2338         /*
2339          * 82571 and greater support packet-split where the protocol
2340          * header is placed in skb->data and the packet data is
2341          * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2342          * In the case of a non-split, skb->data is linearly filled,
2343          * followed by the page buffers.  Therefore, skb->data is
2344          * sized to hold the largest protocol header.
2345          *
2346          * allocations using alloc_page take too long for regular MTU
2347          * so only enable packet split for jumbo frames
2348          *
2349          * Using pages when the page size is greater than 16k wastes
2350          * a lot of memory, since we allocate 3 pages at all times
2351          * per packet.
2352          */
2353         pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2354         if (!(adapter->flags & FLAG_IS_ICH) && (pages <= 3) &&
2355             (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
2356                 adapter->rx_ps_pages = pages;
2357         else
2358                 adapter->rx_ps_pages = 0;
2359
2360         if (adapter->rx_ps_pages) {
2361                 /* Configure extra packet-split registers */
2362                 rfctl = er32(RFCTL);
2363                 rfctl |= E1000_RFCTL_EXTEN;
2364                 /*
2365                  * disable packet split support for IPv6 extension headers,
2366                  * because some malformed IPv6 headers can hang the Rx
2367                  */
2368                 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2369                           E1000_RFCTL_NEW_IPV6_EXT_DIS);
2370
2371                 ew32(RFCTL, rfctl);
2372
2373                 /* Enable Packet split descriptors */
2374                 rctl |= E1000_RCTL_DTYP_PS;
2375
2376                 psrctl |= adapter->rx_ps_bsize0 >>
2377                         E1000_PSRCTL_BSIZE0_SHIFT;
2378
2379                 switch (adapter->rx_ps_pages) {
2380                 case 3:
2381                         psrctl |= PAGE_SIZE <<
2382                                 E1000_PSRCTL_BSIZE3_SHIFT;
2383                 case 2:
2384                         psrctl |= PAGE_SIZE <<
2385                                 E1000_PSRCTL_BSIZE2_SHIFT;
2386                 case 1:
2387                         psrctl |= PAGE_SIZE >>
2388                                 E1000_PSRCTL_BSIZE1_SHIFT;
2389                         break;
2390                 }
2391
2392                 ew32(PSRCTL, psrctl);
2393         }
2394
2395         ew32(RCTL, rctl);
2396         /* just started the receive unit, no need to restart */
2397         adapter->flags &= ~FLAG_RX_RESTART_NOW;
2398 }
2399
2400 /**
2401  * e1000_configure_rx - Configure Receive Unit after Reset
2402  * @adapter: board private structure
2403  *
2404  * Configure the Rx unit of the MAC after a reset.
2405  **/
2406 static void e1000_configure_rx(struct e1000_adapter *adapter)
2407 {
2408         struct e1000_hw *hw = &adapter->hw;
2409         struct e1000_ring *rx_ring = adapter->rx_ring;
2410         u64 rdba;
2411         u32 rdlen, rctl, rxcsum, ctrl_ext;
2412
2413         if (adapter->rx_ps_pages) {
2414                 /* this is a 32 byte descriptor */
2415                 rdlen = rx_ring->count *
2416                         sizeof(union e1000_rx_desc_packet_split);
2417                 adapter->clean_rx = e1000_clean_rx_irq_ps;
2418                 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2419         } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2420                 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2421                 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2422                 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
2423         } else {
2424                 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2425                 adapter->clean_rx = e1000_clean_rx_irq;
2426                 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2427         }
2428
2429         /* disable receives while setting up the descriptors */
2430         rctl = er32(RCTL);
2431         ew32(RCTL, rctl & ~E1000_RCTL_EN);
2432         e1e_flush();
2433         msleep(10);
2434
2435         /* set the Receive Delay Timer Register */
2436         ew32(RDTR, adapter->rx_int_delay);
2437
2438         /* irq moderation */
2439         ew32(RADV, adapter->rx_abs_int_delay);
2440         if (adapter->itr_setting != 0)
2441                 ew32(ITR, 1000000000 / (adapter->itr * 256));
2442
2443         ctrl_ext = er32(CTRL_EXT);
2444         /* Auto-Mask interrupts upon ICR access */
2445         ctrl_ext |= E1000_CTRL_EXT_IAME;
2446         ew32(IAM, 0xffffffff);
2447         ew32(CTRL_EXT, ctrl_ext);
2448         e1e_flush();
2449
2450         /*
2451          * Setup the HW Rx Head and Tail Descriptor Pointers and
2452          * the Base and Length of the Rx Descriptor Ring
2453          */
2454         rdba = rx_ring->dma;
2455         ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
2456         ew32(RDBAH, (rdba >> 32));
2457         ew32(RDLEN, rdlen);
2458         ew32(RDH, 0);
2459         ew32(RDT, 0);
2460         rx_ring->head = E1000_RDH;
2461         rx_ring->tail = E1000_RDT;
2462
2463         /* Enable Receive Checksum Offload for TCP and UDP */
2464         rxcsum = er32(RXCSUM);
2465         if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2466                 rxcsum |= E1000_RXCSUM_TUOFL;
2467
2468                 /*
2469                  * IPv4 payload checksum for UDP fragments must be
2470                  * used in conjunction with packet-split.
2471                  */
2472                 if (adapter->rx_ps_pages)
2473                         rxcsum |= E1000_RXCSUM_IPPCSE;
2474         } else {
2475                 rxcsum &= ~E1000_RXCSUM_TUOFL;
2476                 /* no need to clear IPPCSE as it defaults to 0 */
2477         }
2478         ew32(RXCSUM, rxcsum);
2479
2480         /*
2481          * Enable early receives on supported devices, only takes effect when
2482          * packet size is equal or larger than the specified value (in 8 byte
2483          * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2484          */
2485         if ((adapter->flags & FLAG_HAS_ERT) &&
2486             (adapter->netdev->mtu > ETH_DATA_LEN)) {
2487                 u32 rxdctl = er32(RXDCTL(0));
2488                 ew32(RXDCTL(0), rxdctl | 0x3);
2489                 ew32(ERT, E1000_ERT_2048 | (1 << 13));
2490                 /*
2491                  * With jumbo frames and early-receive enabled, excessive
2492                  * C4->C2 latencies result in dropped transactions.
2493                  */
2494                 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2495                                           e1000e_driver_name, 55);
2496         } else {
2497                 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2498                                           e1000e_driver_name,
2499                                           PM_QOS_DEFAULT_VALUE);
2500         }
2501
2502         /* Enable Receives */
2503         ew32(RCTL, rctl);
2504 }
2505
2506 /**
2507  *  e1000_update_mc_addr_list - Update Multicast addresses
2508  *  @hw: pointer to the HW structure
2509  *  @mc_addr_list: array of multicast addresses to program
2510  *  @mc_addr_count: number of multicast addresses to program
2511  *  @rar_used_count: the first RAR register free to program
2512  *  @rar_count: total number of supported Receive Address Registers
2513  *
2514  *  Updates the Receive Address Registers and Multicast Table Array.
2515  *  The caller must have a packed mc_addr_list of multicast addresses.
2516  *  The parameter rar_count will usually be hw->mac.rar_entry_count
2517  *  unless there are workarounds that change this.  Currently no func pointer
2518  *  exists and all implementations are handled in the generic version of this
2519  *  function.
2520  **/
2521 static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
2522                                       u32 mc_addr_count, u32 rar_used_count,
2523                                       u32 rar_count)
2524 {
2525         hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count,
2526                                         rar_used_count, rar_count);
2527 }
2528
2529 /**
2530  * e1000_set_multi - Multicast and Promiscuous mode set
2531  * @netdev: network interface device structure
2532  *
2533  * The set_multi entry point is called whenever the multicast address
2534  * list or the network interface flags are updated.  This routine is
2535  * responsible for configuring the hardware for proper multicast,
2536  * promiscuous mode, and all-multi behavior.
2537  **/
2538 static void e1000_set_multi(struct net_device *netdev)
2539 {
2540         struct e1000_adapter *adapter = netdev_priv(netdev);
2541         struct e1000_hw *hw = &adapter->hw;
2542         struct e1000_mac_info *mac = &hw->mac;
2543         struct dev_mc_list *mc_ptr;
2544         u8  *mta_list;
2545         u32 rctl;
2546         int i;
2547
2548         /* Check for Promiscuous and All Multicast modes */
2549
2550         rctl = er32(RCTL);
2551
2552         if (netdev->flags & IFF_PROMISC) {
2553                 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2554                 rctl &= ~E1000_RCTL_VFE;
2555         } else {
2556                 if (netdev->flags & IFF_ALLMULTI) {
2557                         rctl |= E1000_RCTL_MPE;
2558                         rctl &= ~E1000_RCTL_UPE;
2559                 } else {
2560                         rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2561                 }
2562                 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
2563                         rctl |= E1000_RCTL_VFE;
2564         }
2565
2566         ew32(RCTL, rctl);
2567
2568         if (netdev->mc_count) {
2569                 mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);
2570                 if (!mta_list)
2571                         return;
2572
2573                 /* prepare a packed array of only addresses. */
2574                 mc_ptr = netdev->mc_list;
2575
2576                 for (i = 0; i < netdev->mc_count; i++) {
2577                         if (!mc_ptr)
2578                                 break;
2579                         memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
2580                                ETH_ALEN);
2581                         mc_ptr = mc_ptr->next;
2582                 }
2583
2584                 e1000_update_mc_addr_list(hw, mta_list, i, 1,
2585                                           mac->rar_entry_count);
2586                 kfree(mta_list);
2587         } else {
2588                 /*
2589                  * if we're called from probe, we might not have
2590                  * anything to do here, so clear out the list
2591                  */
2592                 e1000_update_mc_addr_list(hw, NULL, 0, 1, mac->rar_entry_count);
2593         }
2594 }
2595
2596 /**
2597  * e1000_configure - configure the hardware for Rx and Tx
2598  * @adapter: private board structure
2599  **/
2600 static void e1000_configure(struct e1000_adapter *adapter)
2601 {
2602         e1000_set_multi(adapter->netdev);
2603
2604         e1000_restore_vlan(adapter);
2605         e1000_init_manageability(adapter);
2606
2607         e1000_configure_tx(adapter);
2608         e1000_setup_rctl(adapter);
2609         e1000_configure_rx(adapter);
2610         adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
2611 }
2612
2613 /**
2614  * e1000e_power_up_phy - restore link in case the phy was powered down
2615  * @adapter: address of board private structure
2616  *
2617  * The phy may be powered down to save power and turn off link when the
2618  * driver is unloaded and wake on lan is not enabled (among others)
2619  * *** this routine MUST be followed by a call to e1000e_reset ***
2620  **/
2621 void e1000e_power_up_phy(struct e1000_adapter *adapter)
2622 {
2623         u16 mii_reg = 0;
2624
2625         /* Just clear the power down bit to wake the phy back up */
2626         if (adapter->hw.phy.media_type == e1000_media_type_copper) {
2627                 /*
2628                  * According to the manual, the phy will retain its
2629                  * settings across a power-down/up cycle
2630                  */
2631                 e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);
2632                 mii_reg &= ~MII_CR_POWER_DOWN;
2633                 e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);
2634         }
2635
2636         adapter->hw.mac.ops.setup_link(&adapter->hw);
2637 }
2638
2639 /**
2640  * e1000_power_down_phy - Power down the PHY
2641  *
2642  * Power down the PHY so no link is implied when interface is down
2643  * The PHY cannot be powered down is management or WoL is active
2644  */
2645 static void e1000_power_down_phy(struct e1000_adapter *adapter)
2646 {
2647         struct e1000_hw *hw = &adapter->hw;
2648         u16 mii_reg;
2649
2650         /* WoL is enabled */
2651         if (adapter->wol)
2652                 return;
2653
2654         /* non-copper PHY? */
2655         if (adapter->hw.phy.media_type != e1000_media_type_copper)
2656                 return;
2657
2658         /* reset is blocked because of a SoL/IDER session */
2659         if (e1000e_check_mng_mode(hw) || e1000_check_reset_block(hw))
2660                 return;
2661
2662         /* manageability (AMT) is enabled */
2663         if (er32(MANC) & E1000_MANC_SMBUS_EN)
2664                 return;
2665
2666         /* power down the PHY */
2667         e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2668         mii_reg |= MII_CR_POWER_DOWN;
2669         e1e_wphy(hw, PHY_CONTROL, mii_reg);
2670         mdelay(1);
2671 }
2672
2673 /**
2674  * e1000e_reset - bring the hardware into a known good state
2675  *
2676  * This function boots the hardware and enables some settings that
2677  * require a configuration cycle of the hardware - those cannot be
2678  * set/changed during runtime. After reset the device needs to be
2679  * properly configured for Rx, Tx etc.
2680  */
2681 void e1000e_reset(struct e1000_adapter *adapter)
2682 {
2683         struct e1000_mac_info *mac = &adapter->hw.mac;
2684         struct e1000_fc_info *fc = &adapter->hw.fc;
2685         struct e1000_hw *hw = &adapter->hw;
2686         u32 tx_space, min_tx_space, min_rx_space;
2687         u32 pba = adapter->pba;
2688         u16 hwm;
2689
2690         /* reset Packet Buffer Allocation to default */
2691         ew32(PBA, pba);
2692
2693         if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
2694                 /*
2695                  * To maintain wire speed transmits, the Tx FIFO should be
2696                  * large enough to accommodate two full transmit packets,
2697                  * rounded up to the next 1KB and expressed in KB.  Likewise,
2698                  * the Rx FIFO should be large enough to accommodate at least
2699                  * one full receive packet and is similarly rounded up and
2700                  * expressed in KB.
2701                  */
2702                 pba = er32(PBA);
2703                 /* upper 16 bits has Tx packet buffer allocation size in KB */
2704                 tx_space = pba >> 16;
2705                 /* lower 16 bits has Rx packet buffer allocation size in KB */
2706                 pba &= 0xffff;
2707                 /*
2708                  * the Tx fifo also stores 16 bytes of information about the tx
2709                  * but don't include ethernet FCS because hardware appends it
2710                  */
2711                 min_tx_space = (adapter->max_frame_size +
2712                                 sizeof(struct e1000_tx_desc) -
2713                                 ETH_FCS_LEN) * 2;
2714                 min_tx_space = ALIGN(min_tx_space, 1024);
2715                 min_tx_space >>= 10;
2716                 /* software strips receive CRC, so leave room for it */
2717                 min_rx_space = adapter->max_frame_size;
2718                 min_rx_space = ALIGN(min_rx_space, 1024);
2719                 min_rx_space >>= 10;
2720
2721                 /*
2722                  * If current Tx allocation is less than the min Tx FIFO size,
2723                  * and the min Tx FIFO size is less than the current Rx FIFO
2724                  * allocation, take space away from current Rx allocation
2725                  */
2726                 if ((tx_space < min_tx_space) &&
2727                     ((min_tx_space - tx_space) < pba)) {
2728                         pba -= min_tx_space - tx_space;
2729
2730                         /*
2731                          * if short on Rx space, Rx wins and must trump tx
2732                          * adjustment or use Early Receive if available
2733                          */
2734                         if ((pba < min_rx_space) &&
2735                             (!(adapter->flags & FLAG_HAS_ERT)))
2736                                 /* ERT enabled in e1000_configure_rx */
2737                                 pba = min_rx_space;
2738                 }
2739
2740                 ew32(PBA, pba);
2741         }
2742
2743
2744         /*
2745          * flow control settings
2746          *
2747          * The high water mark must be low enough to fit two full frame
2748          * (or the size used for early receive) above it in the Rx FIFO.
2749          * Set it to the lower of:
2750          * - 90% of the Rx FIFO size, and
2751          * - the full Rx FIFO size minus the early receive size (for parts
2752          *   with ERT support assuming ERT set to E1000_ERT_2048), or
2753          * - the full Rx FIFO size minus two full frames
2754          */
2755         if ((adapter->flags & FLAG_HAS_ERT) &&
2756             (adapter->netdev->mtu > ETH_DATA_LEN))
2757                 hwm = min(((pba << 10) * 9 / 10),
2758                           ((pba << 10) - (E1000_ERT_2048 << 3)));
2759         else
2760                 hwm = min(((pba << 10) * 9 / 10),
2761                           ((pba << 10) - (2 * adapter->max_frame_size)));
2762
2763         fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
2764         fc->low_water = (fc->high_water - (2 * adapter->max_frame_size));
2765         fc->low_water &= E1000_FCRTL_RTL; /* 8-byte granularity */
2766
2767         if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
2768                 fc->pause_time = 0xFFFF;
2769         else
2770                 fc->pause_time = E1000_FC_PAUSE_TIME;
2771         fc->send_xon = 1;
2772         fc->current_mode = fc->requested_mode;
2773
2774         /* Allow time for pending master requests to run */
2775         mac->ops.reset_hw(hw);
2776
2777         /*
2778          * For parts with AMT enabled, let the firmware know
2779          * that the network interface is in control
2780          */
2781         if (adapter->flags & FLAG_HAS_AMT)
2782                 e1000_get_hw_control(adapter);
2783
2784         ew32(WUC, 0);
2785         if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)
2786                 e1e_wphy(&adapter->hw, BM_WUC, 0);
2787
2788         if (mac->ops.init_hw(hw))
2789                 e_err("Hardware Error\n");
2790
2791         e1000_update_mng_vlan(adapter);
2792
2793         /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2794         ew32(VET, ETH_P_8021Q);
2795
2796         e1000e_reset_adaptive(hw);
2797         e1000_get_phy_info(hw);
2798
2799         if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
2800             !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
2801                 u16 phy_data = 0;
2802                 /*
2803                  * speed up time to link by disabling smart power down, ignore
2804                  * the return value of this function because there is nothing
2805                  * different we would do if it failed
2806                  */
2807                 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
2808                 phy_data &= ~IGP02E1000_PM_SPD;
2809                 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
2810         }
2811 }
2812
2813 int e1000e_up(struct e1000_adapter *adapter)
2814 {
2815         struct e1000_hw *hw = &adapter->hw;
2816
2817         /* hardware has been reset, we need to reload some things */
2818         e1000_configure(adapter);
2819
2820         clear_bit(__E1000_DOWN, &adapter->state);
2821
2822         napi_enable(&adapter->napi);
2823         if (adapter->msix_entries)
2824                 e1000_configure_msix(adapter);
2825         e1000_irq_enable(adapter);
2826
2827         netif_wake_queue(adapter->netdev);
2828
2829         /* fire a link change interrupt to start the watchdog */
2830         ew32(ICS, E1000_ICS_LSC);
2831         return 0;
2832 }
2833
2834 void e1000e_down(struct e1000_adapter *adapter)
2835 {
2836         struct net_device *netdev = adapter->netdev;
2837         struct e1000_hw *hw = &adapter->hw;
2838         u32 tctl, rctl;
2839
2840         /*
2841          * signal that we're down so the interrupt handler does not
2842          * reschedule our watchdog timer
2843          */
2844         set_bit(__E1000_DOWN, &adapter->state);
2845
2846         /* disable receives in the hardware */
2847         rctl = er32(RCTL);
2848         ew32(RCTL, rctl & ~E1000_RCTL_EN);
2849         /* flush and sleep below */
2850
2851         netif_stop_queue(netdev);
2852
2853         /* disable transmits in the hardware */
2854         tctl = er32(TCTL);
2855         tctl &= ~E1000_TCTL_EN;
2856         ew32(TCTL, tctl);
2857         /* flush both disables and wait for them to finish */
2858         e1e_flush();
2859         msleep(10);
2860
2861         napi_disable(&adapter->napi);
2862         e1000_irq_disable(adapter);
2863
2864         del_timer_sync(&adapter->watchdog_timer);
2865         del_timer_sync(&adapter->phy_info_timer);
2866
2867         netdev->tx_queue_len = adapter->tx_queue_len;
2868         netif_carrier_off(netdev);
2869         adapter->link_speed = 0;
2870         adapter->link_duplex = 0;
2871
2872         if (!pci_channel_offline(adapter->pdev))
2873                 e1000e_reset(adapter);
2874         e1000_clean_tx_ring(adapter);
2875         e1000_clean_rx_ring(adapter);
2876
2877         /*
2878          * TODO: for power management, we could drop the link and
2879          * pci_disable_device here.
2880          */
2881 }
2882
2883 void e1000e_reinit_locked(struct e1000_adapter *adapter)
2884 {
2885         might_sleep();
2886         while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
2887                 msleep(1);
2888         e1000e_down(adapter);
2889         e1000e_up(adapter);
2890         clear_bit(__E1000_RESETTING, &adapter->state);
2891 }
2892
2893 /**
2894  * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2895  * @adapter: board private structure to initialize
2896  *
2897  * e1000_sw_init initializes the Adapter private data structure.
2898  * Fields are initialized based on PCI device information and
2899  * OS network device settings (MTU size).
2900  **/
2901 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
2902 {
2903         struct net_device *netdev = adapter->netdev;
2904
2905         adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
2906         adapter->rx_ps_bsize0 = 128;
2907         adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2908         adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
2909
2910         e1000e_set_interrupt_capability(adapter);
2911
2912         if (e1000_alloc_queues(adapter))
2913                 return -ENOMEM;
2914
2915         /* Explicitly disable IRQ since the NIC can be in any state. */
2916         e1000_irq_disable(adapter);
2917
2918         set_bit(__E1000_DOWN, &adapter->state);
2919         return 0;
2920 }
2921
2922 /**
2923  * e1000_intr_msi_test - Interrupt Handler
2924  * @irq: interrupt number
2925  * @data: pointer to a network interface device structure
2926  **/
2927 static irqreturn_t e1000_intr_msi_test(int irq, void *data)
2928 {
2929         struct net_device *netdev = data;
2930         struct e1000_adapter *adapter = netdev_priv(netdev);
2931         struct e1000_hw *hw = &adapter->hw;
2932         u32 icr = er32(ICR);
2933
2934         e_dbg("%s: icr is %08X\n", netdev->name, icr);
2935         if (icr & E1000_ICR_RXSEQ) {
2936                 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
2937                 wmb();
2938         }
2939
2940         return IRQ_HANDLED;
2941 }
2942
2943 /**
2944  * e1000_test_msi_interrupt - Returns 0 for successful test
2945  * @adapter: board private struct
2946  *
2947  * code flow taken from tg3.c
2948  **/
2949 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
2950 {
2951         struct net_device *netdev = adapter->netdev;
2952         struct e1000_hw *hw = &adapter->hw;
2953         int err;
2954
2955         /* poll_enable hasn't been called yet, so don't need disable */
2956         /* clear any pending events */
2957         er32(ICR);
2958
2959         /* free the real vector and request a test handler */
2960         e1000_free_irq(adapter);
2961         e1000e_reset_interrupt_capability(adapter);
2962
2963         /* Assume that the test fails, if it succeeds then the test
2964          * MSI irq handler will unset this flag */
2965         adapter->flags |= FLAG_MSI_TEST_FAILED;
2966
2967         err = pci_enable_msi(adapter->pdev);
2968         if (err)
2969                 goto msi_test_failed;
2970
2971         err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
2972                           netdev->name, netdev);
2973         if (err) {
2974                 pci_disable_msi(adapter->pdev);
2975                 goto msi_test_failed;
2976         }
2977
2978         wmb();
2979
2980         e1000_irq_enable(adapter);
2981
2982         /* fire an unusual interrupt on the test handler */
2983         ew32(ICS, E1000_ICS_RXSEQ);
2984         e1e_flush();
2985         msleep(50);
2986
2987         e1000_irq_disable(adapter);
2988
2989         rmb();
2990
2991         if (adapter->flags & FLAG_MSI_TEST_FAILED) {
2992                 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2993                 err = -EIO;
2994                 e_info("MSI interrupt test failed!\n");
2995         }
2996
2997         free_irq(adapter->pdev->irq, netdev);
2998         pci_disable_msi(adapter->pdev);
2999
3000         if (err == -EIO)
3001                 goto msi_test_failed;
3002
3003         /* okay so the test worked, restore settings */
3004         e_dbg("%s: MSI interrupt test succeeded!\n", netdev->name);
3005 msi_test_failed:
3006         e1000e_set_interrupt_capability(adapter);
3007         e1000_request_irq(adapter);
3008         return err;
3009 }
3010
3011 /**
3012  * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3013  * @adapter: board private struct
3014  *
3015  * code flow taken from tg3.c, called with e1000 interrupts disabled.
3016  **/
3017 static int e1000_test_msi(struct e1000_adapter *adapter)
3018 {
3019         int err;
3020         u16 pci_cmd;
3021
3022         if (!(adapter->flags & FLAG_MSI_ENABLED))
3023                 return 0;
3024
3025         /* disable SERR in case the MSI write causes a master abort */
3026         pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3027         pci_write_config_word(adapter->pdev, PCI_COMMAND,
3028                               pci_cmd & ~PCI_COMMAND_SERR);
3029
3030         err = e1000_test_msi_interrupt(adapter);
3031
3032         /* restore previous setting of command word */
3033         pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3034
3035         /* success ! */
3036         if (!err)
3037                 return 0;
3038
3039         /* EIO means MSI test failed */
3040         if (err != -EIO)
3041                 return err;
3042
3043         /* back to INTx mode */
3044         e_warn("MSI interrupt test failed, using legacy interrupt.\n");
3045
3046         e1000_free_irq(adapter);
3047
3048         err = e1000_request_irq(adapter);
3049
3050         return err;
3051 }
3052
3053 /**
3054  * e1000_open - Called when a network interface is made active
3055  * @netdev: network interface device structure
3056  *
3057  * Returns 0 on success, negative value on failure
3058  *
3059  * The open entry point is called when a network interface is made
3060  * active by the system (IFF_UP).  At this point all resources needed
3061  * for transmit and receive operations are allocated, the interrupt
3062  * handler is registered with the OS, the watchdog timer is started,
3063  * and the stack is notified that the interface is ready.
3064  **/
3065 static int e1000_open(struct net_device *netdev)
3066 {
3067         struct e1000_adapter *adapter = netdev_priv(netdev);
3068         struct e1000_hw *hw = &adapter->hw;
3069         int err;
3070
3071         /* disallow open during test */
3072         if (test_bit(__E1000_TESTING, &adapter->state))
3073                 return -EBUSY;
3074
3075         netif_carrier_off(netdev);
3076
3077         /* allocate transmit descriptors */
3078         err = e1000e_setup_tx_resources(adapter);
3079         if (err)
3080                 goto err_setup_tx;
3081
3082         /* allocate receive descriptors */
3083         err = e1000e_setup_rx_resources(adapter);
3084         if (err)
3085                 goto err_setup_rx;
3086
3087         e1000e_power_up_phy(adapter);
3088
3089         adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3090         if ((adapter->hw.mng_cookie.status &
3091              E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3092                 e1000_update_mng_vlan(adapter);
3093
3094         /*
3095          * If AMT is enabled, let the firmware know that the network
3096          * interface is now open
3097          */
3098         if (adapter->flags & FLAG_HAS_AMT)
3099                 e1000_get_hw_control(adapter);
3100
3101         /*
3102          * before we allocate an interrupt, we must be ready to handle it.
3103          * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3104          * as soon as we call pci_request_irq, so we have to setup our
3105          * clean_rx handler before we do so.
3106          */
3107         e1000_configure(adapter);
3108
3109         err = e1000_request_irq(adapter);
3110         if (err)
3111                 goto err_req_irq;
3112
3113         /*
3114          * Work around PCIe errata with MSI interrupts causing some chipsets to
3115          * ignore e1000e MSI messages, which means we need to test our MSI
3116          * interrupt now
3117          */
3118         if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
3119                 err = e1000_test_msi(adapter);
3120                 if (err) {
3121                         e_err("Interrupt allocation failed\n");
3122                         goto err_req_irq;
3123                 }
3124         }
3125
3126         /* From here on the code is the same as e1000e_up() */
3127         clear_bit(__E1000_DOWN, &adapter->state);
3128
3129         napi_enable(&adapter->napi);
3130
3131         e1000_irq_enable(adapter);
3132
3133         netif_start_queue(netdev);
3134
3135         /* fire a link status change interrupt to start the watchdog */
3136         ew32(ICS, E1000_ICS_LSC);
3137
3138         return 0;
3139
3140 err_req_irq:
3141         e1000_release_hw_control(adapter);
3142         e1000_power_down_phy(adapter);
3143         e1000e_free_rx_resources(adapter);
3144 err_setup_rx:
3145         e1000e_free_tx_resources(adapter);
3146 err_setup_tx:
3147         e1000e_reset(adapter);
3148
3149         return err;
3150 }
3151
3152 /**
3153  * e1000_close - Disables a network interface
3154  * @netdev: network interface device structure
3155  *
3156  * Returns 0, this is not allowed to fail
3157  *
3158  * The close entry point is called when an interface is de-activated
3159  * by the OS.  The hardware is still under the drivers control, but
3160  * needs to be disabled.  A global MAC reset is issued to stop the
3161  * hardware, and all transmit and receive resources are freed.
3162  **/
3163 static int e1000_close(struct net_device *netdev)
3164 {
3165         struct e1000_adapter *adapter = netdev_priv(netdev);
3166
3167         WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3168         e1000e_down(adapter);
3169         e1000_power_down_phy(adapter);
3170         e1000_free_irq(adapter);
3171
3172         e1000e_free_tx_resources(adapter);
3173         e1000e_free_rx_resources(adapter);
3174
3175         /*
3176          * kill manageability vlan ID if supported, but not if a vlan with
3177          * the same ID is registered on the host OS (let 8021q kill it)
3178          */
3179         if ((adapter->hw.mng_cookie.status &
3180                           E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3181              !(adapter->vlgrp &&
3182                vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3183                 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3184
3185         /*
3186          * If AMT is enabled, let the firmware know that the network
3187          * interface is now closed
3188          */
3189         if (adapter->flags & FLAG_HAS_AMT)
3190                 e1000_release_hw_control(adapter);
3191
3192         return 0;
3193 }
3194 /**
3195  * e1000_set_mac - Change the Ethernet Address of the NIC
3196  * @netdev: network interface device structure
3197  * @p: pointer to an address structure
3198  *
3199  * Returns 0 on success, negative on failure
3200  **/
3201 static int e1000_set_mac(struct net_device *netdev, void *p)
3202 {
3203         struct e1000_adapter *adapter = netdev_priv(netdev);
3204         struct sockaddr *addr = p;
3205
3206         if (!is_valid_ether_addr(addr->sa_data))
3207                 return -EADDRNOTAVAIL;
3208
3209         memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3210         memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3211
3212         e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3213
3214         if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3215                 /* activate the work around */
3216                 e1000e_set_laa_state_82571(&adapter->hw, 1);
3217
3218                 /*
3219                  * Hold a copy of the LAA in RAR[14] This is done so that
3220                  * between the time RAR[0] gets clobbered  and the time it
3221                  * gets fixed (in e1000_watchdog), the actual LAA is in one
3222                  * of the RARs and no incoming packets directed to this port
3223                  * are dropped. Eventually the LAA will be in RAR[0] and
3224                  * RAR[14]
3225                  */
3226                 e1000e_rar_set(&adapter->hw,
3227                               adapter->hw.mac.addr,
3228                               adapter->hw.mac.rar_entry_count - 1);
3229         }
3230
3231         return 0;
3232 }
3233
3234 /**
3235  * e1000e_update_phy_task - work thread to update phy
3236  * @work: pointer to our work struct
3237  *
3238  * this worker thread exists because we must acquire a
3239  * semaphore to read the phy, which we could msleep while
3240  * waiting for it, and we can't msleep in a timer.
3241  **/
3242 static void e1000e_update_phy_task(struct work_struct *work)
3243 {
3244         struct e1000_adapter *adapter = container_of(work,
3245                                         struct e1000_adapter, update_phy_task);
3246         e1000_get_phy_info(&adapter->hw);
3247 }
3248
3249 /*
3250  * Need to wait a few seconds after link up to get diagnostic information from
3251  * the phy
3252  */
3253 static void e1000_update_phy_info(unsigned long data)
3254 {
3255         struct e1000_adapter *adapter = (struct e1000_adapter *) data;
3256         schedule_work(&adapter->update_phy_task);
3257 }
3258
3259 /**
3260  * e1000e_update_stats - Update the board statistics counters
3261  * @adapter: board private structure
3262  **/
3263 void e1000e_update_stats(struct e1000_adapter *adapter)
3264 {
3265         struct net_device *netdev = adapter->netdev;
3266         struct e1000_hw *hw = &adapter->hw;
3267         struct pci_dev *pdev = adapter->pdev;
3268         u16 phy_data;
3269
3270         /*
3271          * Prevent stats update while adapter is being reset, or if the pci
3272          * connection is down.
3273          */
3274         if (adapter->link_speed == 0)
3275                 return;
3276         if (pci_channel_offline(pdev))
3277                 return;
3278
3279         adapter->stats.crcerrs += er32(CRCERRS);
3280         adapter->stats.gprc += er32(GPRC);
3281         adapter->stats.gorc += er32(GORCL);
3282         er32(GORCH); /* Clear gorc */
3283         adapter->stats.bprc += er32(BPRC);
3284         adapter->stats.mprc += er32(MPRC);
3285         adapter->stats.roc += er32(ROC);
3286
3287         adapter->stats.mpc += er32(MPC);
3288         if ((hw->phy.type == e1000_phy_82578) ||
3289             (hw->phy.type == e1000_phy_82577)) {
3290                 e1e_rphy(hw, HV_SCC_UPPER, &phy_data);
3291                 e1e_rphy(hw, HV_SCC_LOWER, &phy_data);
3292                 adapter->stats.scc += phy_data;
3293
3294                 e1e_rphy(hw, HV_ECOL_UPPER, &phy_data);
3295                 e1e_rphy(hw, HV_ECOL_LOWER, &phy_data);
3296                 adapter->stats.ecol += phy_data;
3297
3298                 e1e_rphy(hw, HV_MCC_UPPER, &phy_data);
3299                 e1e_rphy(hw, HV_MCC_LOWER, &phy_data);
3300                 adapter->stats.mcc += phy_data;
3301
3302                 e1e_rphy(hw, HV_LATECOL_UPPER, &phy_data);
3303                 e1e_rphy(hw, HV_LATECOL_LOWER, &phy_data);
3304                 adapter->stats.latecol += phy_data;
3305
3306                 e1e_rphy(hw, HV_DC_UPPER, &phy_data);
3307                 e1e_rphy(hw, HV_DC_LOWER, &phy_data);
3308                 adapter->stats.dc += phy_data;
3309         } else {
3310                 adapter->stats.scc += er32(SCC);
3311                 adapter->stats.ecol += er32(ECOL);
3312                 adapter->stats.mcc += er32(MCC);
3313                 adapter->stats.latecol += er32(LATECOL);
3314                 adapter->stats.dc += er32(DC);
3315         }
3316         adapter->stats.xonrxc += er32(XONRXC);
3317         adapter->stats.xontxc += er32(XONTXC);
3318         adapter->stats.xoffrxc += er32(XOFFRXC);
3319         adapter->stats.xofftxc += er32(XOFFTXC);
3320         adapter->stats.gptc += er32(GPTC);
3321         adapter->stats.gotc += er32(GOTCL);
3322         er32(GOTCH); /* Clear gotc */
3323         adapter->stats.rnbc += er32(RNBC);
3324         adapter->stats.ruc += er32(RUC);
3325
3326         adapter->stats.mptc += er32(MPTC);
3327         adapter->stats.bptc += er32(BPTC);
3328
3329         /* used for adaptive IFS */
3330
3331         hw->mac.tx_packet_delta = er32(TPT);
3332         adapter->stats.tpt += hw->mac.tx_packet_delta;
3333         if ((hw->phy.type == e1000_phy_82578) ||
3334             (hw->phy.type == e1000_phy_82577)) {
3335                 e1e_rphy(hw, HV_COLC_UPPER, &phy_data);
3336                 e1e_rphy(hw, HV_COLC_LOWER, &phy_data);
3337                 hw->mac.collision_delta = phy_data;
3338         } else {
3339                 hw->mac.collision_delta = er32(COLC);
3340         }
3341         adapter->stats.colc += hw->mac.collision_delta;
3342
3343         adapter->stats.algnerrc += er32(ALGNERRC);
3344         adapter->stats.rxerrc += er32(RXERRC);
3345         if ((hw->phy.type == e1000_phy_82578) ||
3346             (hw->phy.type == e1000_phy_82577)) {
3347                 e1e_rphy(hw, HV_TNCRS_UPPER, &phy_data);
3348                 e1e_rphy(hw, HV_TNCRS_LOWER, &phy_data);
3349                 adapter->stats.tncrs += phy_data;
3350         } else {
3351                 if ((hw->mac.type != e1000_82574) &&
3352                     (hw->mac.type != e1000_82583))
3353                         adapter->stats.tncrs += er32(TNCRS);
3354         }
3355         adapter->stats.cexterr += er32(CEXTERR);
3356         adapter->stats.tsctc += er32(TSCTC);
3357         adapter->stats.tsctfc += er32(TSCTFC);
3358
3359         /* Fill out the OS statistics structure */
3360         netdev->stats.multicast = adapter->stats.mprc;
3361         netdev->stats.collisions = adapter->stats.colc;
3362
3363         /* Rx Errors */
3364
3365         /*
3366          * RLEC on some newer hardware can be incorrect so build
3367          * our own version based on RUC and ROC
3368          */
3369         netdev->stats.rx_errors = adapter->stats.rxerrc +
3370                 adapter->stats.crcerrs + adapter->stats.algnerrc +
3371                 adapter->stats.ruc + adapter->stats.roc +
3372                 adapter->stats.cexterr;
3373         netdev->stats.rx_length_errors = adapter->stats.ruc +
3374                                               adapter->stats.roc;
3375         netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3376         netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3377         netdev->stats.rx_missed_errors = adapter->stats.mpc;
3378
3379         /* Tx Errors */
3380         netdev->stats.tx_errors = adapter->stats.ecol +
3381                                        adapter->stats.latecol;
3382         netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3383         netdev->stats.tx_window_errors = adapter->stats.latecol;
3384         netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
3385
3386         /* Tx Dropped needs to be maintained elsewhere */
3387
3388         /* Management Stats */
3389         adapter->stats.mgptc += er32(MGTPTC);
3390         adapter->stats.mgprc += er32(MGTPRC);
3391         adapter->stats.mgpdc += er32(MGTPDC);
3392 }
3393
3394 /**
3395  * e1000_phy_read_status - Update the PHY register status snapshot
3396  * @adapter: board private structure
3397  **/
3398 static void e1000_phy_read_status(struct e1000_adapter *adapter)
3399 {
3400         struct e1000_hw *hw = &adapter->hw;
3401         struct e1000_phy_regs *phy = &adapter->phy_regs;
3402         int ret_val;
3403
3404         if ((er32(STATUS) & E1000_STATUS_LU) &&
3405             (adapter->hw.phy.media_type == e1000_media_type_copper)) {
3406                 ret_val  = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
3407                 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
3408                 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
3409                 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
3410                 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
3411                 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
3412                 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
3413                 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
3414                 if (ret_val)
3415                         e_warn("Error reading PHY register\n");
3416         } else {
3417                 /*
3418                  * Do not read PHY registers if link is not up
3419                  * Set values to typical power-on defaults
3420                  */
3421                 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
3422                 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
3423                              BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
3424                              BMSR_ERCAP);
3425                 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
3426                                   ADVERTISE_ALL | ADVERTISE_CSMA);
3427                 phy->lpa = 0;
3428                 phy->expansion = EXPANSION_ENABLENPAGE;
3429                 phy->ctrl1000 = ADVERTISE_1000FULL;
3430                 phy->stat1000 = 0;
3431                 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
3432         }
3433 }
3434
3435 static void e1000_print_link_info(struct e1000_adapter *adapter)
3436 {
3437         struct e1000_hw *hw = &adapter->hw;
3438         u32 ctrl = er32(CTRL);
3439
3440         /* Link status message must follow this format for user tools */
3441         printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
3442                "Flow Control: %s\n",
3443                adapter->netdev->name,
3444                adapter->link_speed,
3445                (adapter->link_duplex == FULL_DUPLEX) ?
3446                                 "Full Duplex" : "Half Duplex",
3447                ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
3448                                 "RX/TX" :
3449                ((ctrl & E1000_CTRL_RFCE) ? "RX" :
3450                ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
3451 }
3452
3453 bool e1000_has_link(struct e1000_adapter *adapter)
3454 {
3455         struct e1000_hw *hw = &adapter->hw;
3456         bool link_active = 0;
3457         s32 ret_val = 0;
3458
3459         /*
3460          * get_link_status is set on LSC (link status) interrupt or
3461          * Rx sequence error interrupt.  get_link_status will stay
3462          * false until the check_for_link establishes link
3463          * for copper adapters ONLY
3464          */
3465         switch (hw->phy.media_type) {
3466         case e1000_media_type_copper:
3467                 if (hw->mac.get_link_status) {
3468                         ret_val = hw->mac.ops.check_for_link(hw);
3469                         link_active = !hw->mac.get_link_status;
3470                 } else {
3471                         link_active = 1;
3472                 }
3473                 break;
3474         case e1000_media_type_fiber:
3475                 ret_val = hw->mac.ops.check_for_link(hw);
3476                 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
3477                 break;
3478         case e1000_media_type_internal_serdes:
3479                 ret_val = hw->mac.ops.check_for_link(hw);
3480                 link_active = adapter->hw.mac.serdes_has_link;
3481                 break;
3482         default:
3483         case e1000_media_type_unknown:
3484                 break;
3485         }
3486
3487         if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
3488             (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
3489                 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
3490                 e_info("Gigabit has been disabled, downgrading speed\n");
3491         }
3492
3493         return link_active;
3494 }
3495
3496 static void e1000e_enable_receives(struct e1000_adapter *adapter)
3497 {
3498         /* make sure the receive unit is started */
3499         if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
3500             (adapter->flags & FLAG_RX_RESTART_NOW)) {
3501                 struct e1000_hw *hw = &adapter->hw;
3502                 u32 rctl = er32(RCTL);
3503                 ew32(RCTL, rctl | E1000_RCTL_EN);
3504                 adapter->flags &= ~FLAG_RX_RESTART_NOW;
3505         }
3506 }
3507
3508 /**
3509  * e1000_watchdog - Timer Call-back
3510  * @data: pointer to adapter cast into an unsigned long
3511  **/
3512 static void e1000_watchdog(unsigned long data)
3513 {
3514         struct e1000_adapter *adapter = (struct e1000_adapter *) data;
3515
3516         /* Do the rest outside of interrupt context */
3517         schedule_work(&adapter->watchdog_task);
3518
3519         /* TODO: make this use queue_delayed_work() */
3520 }
3521
3522 static void e1000_watchdog_task(struct work_struct *work)
3523 {
3524         struct e1000_adapter *adapter = container_of(work,
3525                                         struct e1000_adapter, watchdog_task);
3526         struct net_device *netdev = adapter->netdev;
3527         struct e1000_mac_info *mac = &adapter->hw.mac;
3528         struct e1000_phy_info *phy = &adapter->hw.phy;
3529         struct e1000_ring *tx_ring = adapter->tx_ring;
3530         struct e1000_hw *hw = &adapter->hw;
3531         u32 link, tctl;
3532         int tx_pending = 0;
3533
3534         link = e1000_has_link(adapter);
3535         if ((netif_carrier_ok(netdev)) && link) {
3536                 e1000e_enable_receives(adapter);
3537                 goto link_up;
3538         }
3539
3540         if ((e1000e_enable_tx_pkt_filtering(hw)) &&
3541             (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
3542                 e1000_update_mng_vlan(adapter);
3543
3544         if (link) {
3545                 if (!netif_carrier_ok(netdev)) {
3546                         bool txb2b = 1;
3547                         /* update snapshot of PHY registers on LSC */
3548                         e1000_phy_read_status(adapter);
3549                         mac->ops.get_link_up_info(&adapter->hw,
3550                                                    &adapter->link_speed,
3551                                                    &adapter->link_duplex);
3552                         e1000_print_link_info(adapter);
3553                         /*
3554                          * On supported PHYs, check for duplex mismatch only
3555                          * if link has autonegotiated at 10/100 half
3556                          */
3557                         if ((hw->phy.type == e1000_phy_igp_3 ||
3558                              hw->phy.type == e1000_phy_bm) &&
3559                             (hw->mac.autoneg == true) &&
3560                             (adapter->link_speed == SPEED_10 ||
3561                              adapter->link_speed == SPEED_100) &&
3562                             (adapter->link_duplex == HALF_DUPLEX)) {
3563                                 u16 autoneg_exp;
3564
3565                                 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
3566
3567                                 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
3568                                         e_info("Autonegotiated half duplex but"
3569                                                " link partner cannot autoneg. "
3570                                                " Try forcing full duplex if "
3571                                                "link gets many collisions.\n");
3572                         }
3573
3574                         /*
3575                          * tweak tx_queue_len according to speed/duplex
3576                          * and adjust the timeout factor
3577                          */
3578                         netdev->tx_queue_len = adapter->tx_queue_len;
3579                         adapter->tx_timeout_factor = 1;
3580                         switch (adapter->link_speed) {
3581                         case SPEED_10:
3582                                 txb2b = 0;
3583                                 netdev->tx_queue_len = 10;
3584                                 adapter->tx_timeout_factor = 16;
3585                                 break;
3586                         case SPEED_100:
3587                                 txb2b = 0;
3588                                 netdev->tx_queue_len = 100;
3589                                 /* maybe add some timeout factor ? */
3590                                 break;
3591                         }
3592
3593                         /*
3594                          * workaround: re-program speed mode bit after
3595                          * link-up event
3596                          */
3597                         if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
3598                             !txb2b) {
3599                                 u32 tarc0;
3600                                 tarc0 = er32(TARC(0));
3601                                 tarc0 &= ~SPEED_MODE_BIT;
3602                                 ew32(TARC(0), tarc0);
3603                         }
3604
3605                         /*
3606                          * disable TSO for pcie and 10/100 speeds, to avoid
3607                          * some hardware issues
3608                          */
3609                         if (!(adapter->flags & FLAG_TSO_FORCE)) {
3610                                 switch (adapter->link_speed) {
3611                                 case SPEED_10:
3612                                 case SPEED_100:
3613                                         e_info("10/100 speed: disabling TSO\n");
3614                                         netdev->features &= ~NETIF_F_TSO;
3615                                         netdev->features &= ~NETIF_F_TSO6;
3616                                         break;
3617                                 case SPEED_1000:
3618                                         netdev->features |= NETIF_F_TSO;
3619                                         netdev->features |= NETIF_F_TSO6;
3620                                         break;
3621                                 default:
3622                                         /* oops */
3623                                         break;
3624                                 }
3625                         }
3626
3627                         /*
3628                          * enable transmits in the hardware, need to do this
3629                          * after setting TARC(0)
3630                          */
3631                         tctl = er32(TCTL);
3632                         tctl |= E1000_TCTL_EN;
3633                         ew32(TCTL, tctl);
3634
3635                         /*
3636                          * Perform any post-link-up configuration before
3637                          * reporting link up.
3638                          */
3639                         if (phy->ops.cfg_on_link_up)
3640                                 phy->ops.cfg_on_link_up(hw);
3641
3642                         netif_carrier_on(netdev);
3643
3644                         if (!test_bit(__E1000_DOWN, &adapter->state))
3645                                 mod_timer(&adapter->phy_info_timer,
3646                                           round_jiffies(jiffies + 2 * HZ));
3647                 }
3648         } else {
3649                 if (netif_carrier_ok(netdev)) {
3650                         adapter->link_speed = 0;
3651                         adapter->link_duplex = 0;
3652                         /* Link status message must follow this format */
3653                         printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
3654                                adapter->netdev->name);
3655                         netif_carrier_off(netdev);
3656                         if (!test_bit(__E1000_DOWN, &adapter->state))
3657                                 mod_timer(&adapter->phy_info_timer,
3658                                           round_jiffies(jiffies + 2 * HZ));
3659
3660                         if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3661                                 schedule_work(&adapter->reset_task);
3662                 }
3663         }
3664
3665 link_up:
3666         e1000e_update_stats(adapter);
3667
3668         mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
3669         adapter->tpt_old = adapter->stats.tpt;
3670         mac->collision_delta = adapter->stats.colc - adapter->colc_old;
3671         adapter->colc_old = adapter->stats.colc;
3672
3673         adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
3674         adapter->gorc_old = adapter->stats.gorc;
3675         adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
3676         adapter->gotc_old = adapter->stats.gotc;
3677
3678         e1000e_update_adaptive(&adapter->hw);
3679
3680         if (!netif_carrier_ok(netdev)) {
3681                 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
3682                                tx_ring->count);
3683                 if (tx_pending) {
3684                         /*
3685                          * We've lost link, so the controller stops DMA,
3686                          * but we've got queued Tx work that's never going
3687                          * to get done, so reset controller to flush Tx.
3688                          * (Do the reset outside of interrupt context).
3689                          */
3690                         adapter->tx_timeout_count++;
3691                         schedule_work(&adapter->reset_task);
3692                         /* return immediately since reset is imminent */
3693                         return;
3694                 }
3695         }
3696
3697         /* Cause software interrupt to ensure Rx ring is cleaned */
3698         if (adapter->msix_entries)
3699                 ew32(ICS, adapter->rx_ring->ims_val);
3700         else
3701                 ew32(ICS, E1000_ICS_RXDMT0);
3702
3703         /* Force detection of hung controller every watchdog period */
3704         adapter->detect_tx_hung = 1;
3705
3706         /*
3707          * With 82571 controllers, LAA may be overwritten due to controller
3708          * reset from the other port. Set the appropriate LAA in RAR[0]
3709          */
3710         if (e1000e_get_laa_state_82571(hw))
3711                 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
3712
3713         /* Reset the timer */
3714         if (!test_bit(__E1000_DOWN, &adapter->state))
3715                 mod_timer(&adapter->watchdog_timer,
3716                           round_jiffies(jiffies + 2 * HZ));
3717 }
3718
3719 #define E1000_TX_FLAGS_CSUM             0x00000001
3720 #define E1000_TX_FLAGS_VLAN             0x00000002
3721 #define E1000_TX_FLAGS_TSO              0x00000004
3722 #define E1000_TX_FLAGS_IPV4             0x00000008
3723 #define E1000_TX_FLAGS_VLAN_MASK        0xffff0000
3724 #define E1000_TX_FLAGS_VLAN_SHIFT       16
3725
3726 static int e1000_tso(struct e1000_adapter *adapter,
3727                      struct sk_buff *skb)
3728 {
3729         struct e1000_ring *tx_ring = adapter->tx_ring;
3730         struct e1000_context_desc *context_desc;
3731         struct e1000_buffer *buffer_info;
3732         unsigned int i;
3733         u32 cmd_length = 0;
3734         u16 ipcse = 0, tucse, mss;
3735         u8 ipcss, ipcso, tucss, tucso, hdr_len;
3736         int err;
3737
3738         if (skb_is_gso(skb)) {
3739                 if (skb_header_cloned(skb)) {
3740                         err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3741                         if (err)
3742                                 return err;
3743                 }
3744
3745                 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3746                 mss = skb_shinfo(skb)->gso_size;
3747                 if (skb->protocol == htons(ETH_P_IP)) {
3748                         struct iphdr *iph = ip_hdr(skb);
3749                         iph->tot_len = 0;
3750                         iph->check = 0;
3751                         tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3752                                                                  iph->daddr, 0,
3753                                                                  IPPROTO_TCP,
3754                                                                  0);
3755                         cmd_length = E1000_TXD_CMD_IP;
3756                         ipcse = skb_transport_offset(skb) - 1;
3757                 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3758                         ipv6_hdr(skb)->payload_len = 0;
3759                         tcp_hdr(skb)->check =
3760                                 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3761                                                  &ipv6_hdr(skb)->daddr,
3762                                                  0, IPPROTO_TCP, 0);
3763                         ipcse = 0;
3764                 }
3765                 ipcss = skb_network_offset(skb);
3766                 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
3767                 tucss = skb_transport_offset(skb);
3768                 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
3769                 tucse = 0;
3770
3771                 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
3772                                E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
3773
3774                 i = tx_ring->next_to_use;
3775                 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3776                 buffer_info = &tx_ring->buffer_info[i];
3777
3778                 context_desc->lower_setup.ip_fields.ipcss  = ipcss;
3779                 context_desc->lower_setup.ip_fields.ipcso  = ipcso;
3780                 context_desc->lower_setup.ip_fields.ipcse  = cpu_to_le16(ipcse);
3781                 context_desc->upper_setup.tcp_fields.tucss = tucss;
3782                 context_desc->upper_setup.tcp_fields.tucso = tucso;
3783                 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3784                 context_desc->tcp_seg_setup.fields.mss     = cpu_to_le16(mss);
3785                 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3786                 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3787
3788                 buffer_info->time_stamp = jiffies;
3789                 buffer_info->next_to_watch = i;
3790
3791                 i++;
3792                 if (i == tx_ring->count)
3793                         i = 0;
3794                 tx_ring->next_to_use = i;
3795
3796                 return 1;
3797         }
3798
3799         return 0;
3800 }
3801
3802 static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
3803 {
3804         struct e1000_ring *tx_ring = adapter->tx_ring;
3805         struct e1000_context_desc *context_desc;
3806         struct e1000_buffer *buffer_info;
3807         unsigned int i;
3808         u8 css;
3809         u32 cmd_len = E1000_TXD_CMD_DEXT;
3810         __be16 protocol;
3811
3812         if (skb->ip_summed != CHECKSUM_PARTIAL)
3813                 return 0;
3814
3815         if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
3816                 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
3817         else
3818                 protocol = skb->protocol;
3819
3820         switch (protocol) {
3821         case cpu_to_be16(ETH_P_IP):
3822                 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3823                         cmd_len |= E1000_TXD_CMD_TCP;
3824                 break;
3825         case cpu_to_be16(ETH_P_IPV6):
3826                 /* XXX not handling all IPV6 headers */
3827                 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3828                         cmd_len |= E1000_TXD_CMD_TCP;
3829                 break;
3830         default:
3831                 if (unlikely(net_ratelimit()))
3832                         e_warn("checksum_partial proto=%x!\n",
3833                                be16_to_cpu(protocol));
3834                 break;
3835         }
3836
3837         css = skb_transport_offset(skb);
3838
3839         i = tx_ring->next_to_use;
3840         buffer_info = &tx_ring->buffer_info[i];
3841         context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3842
3843         context_desc->lower_setup.ip_config = 0;
3844         context_desc->upper_setup.tcp_fields.tucss = css;
3845         context_desc->upper_setup.tcp_fields.tucso =
3846                                 css + skb->csum_offset;
3847         context_desc->upper_setup.tcp_fields.tucse = 0;
3848         context_desc->tcp_seg_setup.data = 0;
3849         context_desc->cmd_and_length = cpu_to_le32(cmd_len);
3850
3851         buffer_info->time_stamp = jiffies;
3852         buffer_info->next_to_watch = i;
3853
3854         i++;
3855         if (i == tx_ring->count)
3856                 i = 0;
3857         tx_ring->next_to_use = i;
3858
3859         return 1;
3860 }
3861
3862 #define E1000_MAX_PER_TXD       8192
3863 #define E1000_MAX_TXD_PWR       12
3864
3865 static int e1000_tx_map(struct e1000_adapter *adapter,
3866                         struct sk_buff *skb, unsigned int first,
3867                         unsigned int max_per_txd, unsigned int nr_frags,
3868                         unsigned int mss)
3869 {
3870         struct e1000_ring *tx_ring = adapter->tx_ring;
3871         struct e1000_buffer *buffer_info;
3872         unsigned int len = skb_headlen(skb);
3873         unsigned int offset, size, count = 0, i;
3874         unsigned int f;
3875         dma_addr_t *map;
3876
3877         i = tx_ring->next_to_use;
3878
3879         if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
3880                 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
3881                 adapter->tx_dma_failed++;
3882                 return 0;
3883         }
3884
3885         map = skb_shinfo(skb)->dma_maps;
3886         offset = 0;
3887
3888         while (len) {
3889                 buffer_info = &tx_ring->buffer_info[i];
3890                 size = min(len, max_per_txd);
3891
3892                 buffer_info->length = size;
3893                 buffer_info->time_stamp = jiffies;
3894                 buffer_info->next_to_watch = i;
3895                 buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
3896                 count++;
3897
3898                 len -= size;
3899                 offset += size;
3900
3901                 if (len) {
3902                         i++;
3903                         if (i == tx_ring->count)
3904                                 i = 0;
3905                 }
3906         }
3907
3908         for (f = 0; f < nr_frags; f++) {
3909                 struct skb_frag_struct *frag;
3910
3911                 frag = &skb_shinfo(skb)->frags[f];
3912                 len = frag->size;
3913                 offset = 0;
3914
3915                 while (len) {
3916                         i++;
3917                         if (i == tx_ring->count)
3918                                 i = 0;
3919
3920                         buffer_info = &tx_ring->buffer_info[i];
3921                         size = min(len, max_per_txd);
3922
3923                         buffer_info->length = size;
3924                         buffer_info->time_stamp = jiffies;
3925                         buffer_info->next_to_watch = i;
3926                         buffer_info->dma = map[f] + offset;
3927
3928                         len -= size;
3929                         offset += size;
3930                         count++;
3931                 }
3932         }
3933
3934         tx_ring->buffer_info[i].skb = skb;
3935         tx_ring->buffer_info[first].next_to_watch = i;
3936
3937         return count;
3938 }
3939
3940 static void e1000_tx_queue(struct e1000_adapter *adapter,
3941                            int tx_flags, int count)
3942 {
3943         struct e1000_ring *tx_ring = adapter->tx_ring;
3944         struct e1000_tx_desc *tx_desc = NULL;
3945         struct e1000_buffer *buffer_info;
3946         u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3947         unsigned int i;
3948
3949         if (tx_flags & E1000_TX_FLAGS_TSO) {
3950                 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3951                              E1000_TXD_CMD_TSE;
3952                 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3953
3954                 if (tx_flags & E1000_TX_FLAGS_IPV4)
3955                         txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3956         }
3957
3958         if (tx_flags & E1000_TX_FLAGS_CSUM) {
3959                 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3960                 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3961         }
3962
3963         if (tx_flags & E1000_TX_FLAGS_VLAN) {
3964                 txd_lower |= E1000_TXD_CMD_VLE;
3965                 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3966         }
3967
3968         i = tx_ring->next_to_use;
3969
3970         while (count--) {
3971                 buffer_info = &tx_ring->buffer_info[i];
3972                 tx_desc = E1000_TX_DESC(*tx_ring, i);
3973                 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3974                 tx_desc->lower.data =
3975                         cpu_to_le32(txd_lower | buffer_info->length);
3976                 tx_desc->upper.data = cpu_to_le32(txd_upper);
3977
3978                 i++;
3979                 if (i == tx_ring->count)
3980                         i = 0;
3981         }
3982
3983         tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3984
3985         /*
3986          * Force memory writes to complete before letting h/w
3987          * know there are new descriptors to fetch.  (Only
3988          * applicable for weak-ordered memory model archs,
3989          * such as IA-64).
3990          */
3991         wmb();
3992
3993         tx_ring->next_to_use = i;
3994         writel(i, adapter->hw.hw_addr + tx_ring->tail);
3995         /*
3996          * we need this if more than one processor can write to our tail
3997          * at a time, it synchronizes IO on IA64/Altix systems
3998          */
3999         mmiowb();
4000 }
4001
4002 #define MINIMUM_DHCP_PACKET_SIZE 282
4003 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4004                                     struct sk_buff *skb)
4005 {
4006         struct e1000_hw *hw =  &adapter->hw;
4007         u16 length, offset;
4008
4009         if (vlan_tx_tag_present(skb)) {
4010                 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id)
4011                     && (adapter->hw.mng_cookie.status &
4012                         E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4013                         return 0;
4014         }
4015
4016         if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4017                 return 0;
4018
4019         if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4020                 return 0;
4021
4022         {
4023                 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4024                 struct udphdr *udp;
4025
4026                 if (ip->protocol != IPPROTO_UDP)
4027                         return 0;
4028
4029                 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4030                 if (ntohs(udp->dest) != 67)
4031                         return 0;
4032
4033                 offset = (u8 *)udp + 8 - skb->data;
4034                 length = skb->len - offset;
4035                 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4036         }
4037
4038         return 0;
4039 }
4040
4041 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4042 {
4043         struct e1000_adapter *adapter = netdev_priv(netdev);
4044
4045         netif_stop_queue(netdev);
4046         /*
4047          * Herbert's original patch had:
4048          *  smp_mb__after_netif_stop_queue();
4049          * but since that doesn't exist yet, just open code it.
4050          */
4051         smp_mb();
4052
4053         /*
4054          * We need to check again in a case another CPU has just
4055          * made room available.
4056          */
4057         if (e1000_desc_unused(adapter->tx_ring) < size)
4058                 return -EBUSY;
4059
4060         /* A reprieve! */
4061         netif_start_queue(netdev);
4062         ++adapter->restart_queue;
4063         return 0;
4064 }
4065
4066 static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4067 {
4068         struct e1000_adapter *adapter = netdev_priv(netdev);
4069
4070         if (e1000_desc_unused(adapter->tx_ring) >= size)
4071                 return 0;
4072         return __e1000_maybe_stop_tx(netdev, size);
4073 }
4074
4075 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4076 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4077                                     struct net_device *netdev)
4078 {
4079         struct e1000_adapter *adapter = netdev_priv(netdev);
4080         struct e1000_ring *tx_ring = adapter->tx_ring;
4081         unsigned int first;
4082         unsigned int max_per_txd = E1000_MAX_PER_TXD;
4083         unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4084         unsigned int tx_flags = 0;
4085         unsigned int len = skb->len - skb->data_len;
4086         unsigned int nr_frags;
4087         unsigned int mss;
4088         int count = 0;
4089         int tso;
4090         unsigned int f;
4091
4092         if (test_bit(__E1000_DOWN, &adapter->state)) {
4093                 dev_kfree_skb_any(skb);
4094                 return NETDEV_TX_OK;
4095         }
4096
4097         if (skb->len <= 0) {
4098                 dev_kfree_skb_any(skb);
4099                 return NETDEV_TX_OK;
4100         }
4101
4102         mss = skb_shinfo(skb)->gso_size;
4103         /*
4104          * The controller does a simple calculation to
4105          * make sure there is enough room in the FIFO before
4106          * initiating the DMA for each buffer.  The calc is:
4107          * 4 = ceil(buffer len/mss).  To make sure we don't
4108          * overrun the FIFO, adjust the max buffer len if mss
4109          * drops.
4110          */
4111         if (mss) {
4112                 u8 hdr_len;
4113                 max_per_txd = min(mss << 2, max_per_txd);
4114                 max_txd_pwr = fls(max_per_txd) - 1;
4115
4116                 /*
4117                  * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4118                  * points to just header, pull a few bytes of payload from
4119                  * frags into skb->data
4120                  */
4121                 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4122                 /*
4123                  * we do this workaround for ES2LAN, but it is un-necessary,
4124                  * avoiding it could save a lot of cycles
4125                  */
4126                 if (skb->data_len && (hdr_len == len)) {
4127                         unsigned int pull_size;
4128
4129                         pull_size = min((unsigned int)4, skb->data_len);
4130                         if (!__pskb_pull_tail(skb, pull_size)) {
4131                                 e_err("__pskb_pull_tail failed.\n");
4132                                 dev_kfree_skb_any(skb);
4133                                 return NETDEV_TX_OK;
4134                         }
4135                         len = skb->len - skb->data_len;
4136                 }
4137         }
4138
4139         /* reserve a descriptor for the offload context */
4140         if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4141                 count++;
4142         count++;
4143
4144         count += TXD_USE_COUNT(len, max_txd_pwr);
4145
4146         nr_frags = skb_shinfo(skb)->nr_frags;
4147         for (f = 0; f < nr_frags; f++)
4148                 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4149                                        max_txd_pwr);
4150
4151         if (adapter->hw.mac.tx_pkt_filtering)
4152                 e1000_transfer_dhcp_info(adapter, skb);
4153
4154         /*
4155          * need: count + 2 desc gap to keep tail from touching
4156          * head, otherwise try next time
4157          */
4158         if (e1000_maybe_stop_tx(netdev, count + 2))
4159                 return NETDEV_TX_BUSY;
4160
4161         if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4162                 tx_flags |= E1000_TX_FLAGS_VLAN;
4163                 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4164         }
4165
4166         first = tx_ring->next_to_use;
4167
4168         tso = e1000_tso(adapter, skb);
4169         if (tso < 0) {
4170                 dev_kfree_skb_any(skb);
4171                 return NETDEV_TX_OK;
4172         }
4173
4174         if (tso)
4175                 tx_flags |= E1000_TX_FLAGS_TSO;
4176         else if (e1000_tx_csum(adapter, skb))
4177                 tx_flags |= E1000_TX_FLAGS_CSUM;
4178
4179         /*
4180          * Old method was to assume IPv4 packet by default if TSO was enabled.
4181          * 82571 hardware supports TSO capabilities for IPv6 as well...
4182          * no longer assume, we must.
4183          */
4184         if (skb->protocol == htons(ETH_P_IP))
4185                 tx_flags |= E1000_TX_FLAGS_IPV4;
4186
4187         /* if count is 0 then mapping error has occured */
4188         count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
4189         if (count) {
4190                 e1000_tx_queue(adapter, tx_flags, count);
4191                 /* Make sure there is space in the ring for the next send. */
4192                 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4193
4194         } else {
4195                 dev_kfree_skb_any(skb);
4196                 tx_ring->buffer_info[first].time_stamp = 0;
4197                 tx_ring->next_to_use = first;
4198         }
4199
4200         return NETDEV_TX_OK;
4201 }
4202
4203 /**
4204  * e1000_tx_timeout - Respond to a Tx Hang
4205  * @netdev: network interface device structure
4206  **/
4207 static void e1000_tx_timeout(struct net_device *netdev)
4208 {
4209         struct e1000_adapter *adapter = netdev_priv(netdev);
4210
4211         /* Do the reset outside of interrupt context */
4212         adapter->tx_timeout_count++;
4213         schedule_work(&adapter->reset_task);
4214 }
4215
4216 static void e1000_reset_task(struct work_struct *work)
4217 {
4218         struct e1000_adapter *adapter;
4219         adapter = container_of(work, struct e1000_adapter, reset_task);
4220
4221         e1000e_reinit_locked(adapter);
4222 }
4223
4224 /**
4225  * e1000_get_stats - Get System Network Statistics
4226  * @netdev: network interface device structure
4227  *
4228  * Returns the address of the device statistics structure.
4229  * The statistics are actually updated from the timer callback.
4230  **/
4231 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
4232 {
4233         /* only return the current stats */
4234         return &netdev->stats;
4235 }
4236
4237 /**
4238  * e1000_change_mtu - Change the Maximum Transfer Unit
4239  * @netdev: network interface device structure
4240  * @new_mtu: new value for maximum frame size
4241  *
4242  * Returns 0 on success, negative on failure
4243  **/
4244 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4245 {
4246         struct e1000_adapter *adapter = netdev_priv(netdev);
4247         int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4248
4249         /* Jumbo frame support */
4250         if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
4251             !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
4252                 e_err("Jumbo Frames not supported.\n");
4253                 return -EINVAL;
4254         }
4255
4256         /* Supported frame sizes */
4257         if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
4258             (max_frame > adapter->max_hw_frame_size)) {
4259                 e_err("Unsupported MTU setting\n");
4260                 return -EINVAL;
4261         }
4262
4263         while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4264                 msleep(1);
4265         /* e1000e_down has a dependency on max_frame_size */
4266         adapter->max_frame_size = max_frame;
4267         if (netif_running(netdev))
4268                 e1000e_down(adapter);
4269
4270         /*
4271          * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
4272          * means we reserve 2 more, this pushes us to allocate from the next
4273          * larger slab size.
4274          * i.e. RXBUFFER_2048 --> size-4096 slab
4275          * However with the new *_jumbo_rx* routines, jumbo receives will use
4276          * fragmented skbs
4277          */
4278
4279         if (max_frame <= 256)
4280                 adapter->rx_buffer_len = 256;
4281         else if (max_frame <= 512)
4282                 adapter->rx_buffer_len = 512;
4283         else if (max_frame <= 1024)
4284                 adapter->rx_buffer_len = 1024;
4285         else if (max_frame <= 2048)
4286                 adapter->rx_buffer_len = 2048;
4287         else
4288                 adapter->rx_buffer_len = 4096;
4289
4290         /* adjust allocation if LPE protects us, and we aren't using SBP */
4291         if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
4292              (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
4293                 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
4294                                          + ETH_FCS_LEN;
4295
4296         e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
4297         netdev->mtu = new_mtu;
4298
4299         if (netif_running(netdev))
4300                 e1000e_up(adapter);
4301         else
4302                 e1000e_reset(adapter);
4303
4304         clear_bit(__E1000_RESETTING, &adapter->state);
4305
4306         return 0;
4307 }
4308
4309 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4310                            int cmd)
4311 {
4312         struct e1000_adapter *adapter = netdev_priv(netdev);
4313         struct mii_ioctl_data *data = if_mii(ifr);
4314
4315         if (adapter->hw.phy.media_type != e1000_media_type_copper)
4316                 return -EOPNOTSUPP;
4317
4318         switch (cmd) {
4319         case SIOCGMIIPHY:
4320                 data->phy_id = adapter->hw.phy.addr;
4321                 break;
4322         case SIOCGMIIREG:
4323                 switch (data->reg_num & 0x1F) {
4324                 case MII_BMCR:
4325                         data->val_out = adapter->phy_regs.bmcr;
4326                         break;
4327                 case MII_BMSR:
4328                         data->val_out = adapter->phy_regs.bmsr;
4329                         break;
4330                 case MII_PHYSID1:
4331                         data->val_out = (adapter->hw.phy.id >> 16);
4332                         break;
4333                 case MII_PHYSID2:
4334                         data->val_out = (adapter->hw.phy.id & 0xFFFF);
4335                         break;
4336                 case MII_ADVERTISE:
4337                         data->val_out = adapter->phy_regs.advertise;
4338                         break;
4339                 case MII_LPA:
4340                         data->val_out = adapter->phy_regs.lpa;
4341                         break;
4342                 case MII_EXPANSION:
4343                         data->val_out = adapter->phy_regs.expansion;
4344                         break;
4345                 case MII_CTRL1000:
4346                         data->val_out = adapter->phy_regs.ctrl1000;
4347                         break;
4348                 case MII_STAT1000:
4349                         data->val_out = adapter->phy_regs.stat1000;
4350                         break;
4351                 case MII_ESTATUS:
4352                         data->val_out = adapter->phy_regs.estatus;
4353                         break;
4354                 default:
4355                         return -EIO;
4356                 }
4357                 break;
4358         case SIOCSMIIREG:
4359         default:
4360                 return -EOPNOTSUPP;
4361         }
4362         return 0;
4363 }
4364
4365 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4366 {
4367         switch (cmd) {
4368         case SIOCGMIIPHY:
4369         case SIOCGMIIREG:
4370         case SIOCSMIIREG:
4371                 return e1000_mii_ioctl(netdev, ifr, cmd);
4372         default:
4373                 return -EOPNOTSUPP;
4374         }
4375 }
4376
4377 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
4378 {
4379         struct e1000_hw *hw = &adapter->hw;
4380         u32 i, mac_reg;
4381         u16 phy_reg;
4382         int retval = 0;
4383
4384         /* copy MAC RARs to PHY RARs */
4385         for (i = 0; i < adapter->hw.mac.rar_entry_count; i++) {
4386                 mac_reg = er32(RAL(i));
4387                 e1e_wphy(hw, BM_RAR_L(i), (u16)(mac_reg & 0xFFFF));
4388                 e1e_wphy(hw, BM_RAR_M(i), (u16)((mac_reg >> 16) & 0xFFFF));
4389                 mac_reg = er32(RAH(i));
4390                 e1e_wphy(hw, BM_RAR_H(i), (u16)(mac_reg & 0xFFFF));
4391                 e1e_wphy(hw, BM_RAR_CTRL(i), (u16)((mac_reg >> 16) & 0xFFFF));
4392         }
4393
4394         /* copy MAC MTA to PHY MTA */
4395         for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
4396                 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
4397                 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
4398                 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
4399         }
4400
4401         /* configure PHY Rx Control register */
4402         e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
4403         mac_reg = er32(RCTL);
4404         if (mac_reg & E1000_RCTL_UPE)
4405                 phy_reg |= BM_RCTL_UPE;
4406         if (mac_reg & E1000_RCTL_MPE)
4407                 phy_reg |= BM_RCTL_MPE;
4408         phy_reg &= ~(BM_RCTL_MO_MASK);
4409         if (mac_reg & E1000_RCTL_MO_3)
4410                 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
4411                                 << BM_RCTL_MO_SHIFT);
4412         if (mac_reg & E1000_RCTL_BAM)
4413                 phy_reg |= BM_RCTL_BAM;
4414         if (mac_reg & E1000_RCTL_PMCF)
4415                 phy_reg |= BM_RCTL_PMCF;
4416         mac_reg = er32(CTRL);
4417         if (mac_reg & E1000_CTRL_RFCE)
4418                 phy_reg |= BM_RCTL_RFCE;
4419         e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
4420
4421         /* enable PHY wakeup in MAC register */
4422         ew32(WUFC, wufc);
4423         ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
4424
4425         /* configure and enable PHY wakeup in PHY registers */
4426         e1e_wphy(&adapter->hw, BM_WUFC, wufc);
4427         e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
4428
4429         /* activate PHY wakeup */
4430         retval = hw->phy.ops.acquire_phy(hw);
4431         if (retval) {
4432                 e_err("Could not acquire PHY\n");
4433                 return retval;
4434         }
4435         e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4436                                  (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
4437         retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
4438         if (retval) {
4439                 e_err("Could not read PHY page 769\n");
4440                 goto out;
4441         }
4442         phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
4443         retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
4444         if (retval)
4445                 e_err("Could not set PHY Host Wakeup bit\n");
4446 out:
4447         hw->phy.ops.release_phy(hw);
4448
4449         return retval;
4450 }
4451
4452 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
4453 {
4454         struct net_device *netdev = pci_get_drvdata(pdev);
4455         struct e1000_adapter *adapter = netdev_priv(netdev);
4456         struct e1000_hw *hw = &adapter->hw;
4457         u32 ctrl, ctrl_ext, rctl, status;
4458         u32 wufc = adapter->wol;
4459         int retval = 0;
4460
4461         netif_device_detach(netdev);
4462
4463         if (netif_running(netdev)) {
4464                 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
4465                 e1000e_down(adapter);
4466                 e1000_free_irq(adapter);
4467         }
4468         e1000e_reset_interrupt_capability(adapter);
4469
4470         retval = pci_save_state(pdev);
4471         if (retval)
4472                 return retval;
4473
4474         status = er32(STATUS);
4475         if (status & E1000_STATUS_LU)
4476                 wufc &= ~E1000_WUFC_LNKC;
4477
4478         if (wufc) {
4479                 e1000_setup_rctl(adapter);
4480                 e1000_set_multi(netdev);
4481
4482                 /* turn on all-multi mode if wake on multicast is enabled */
4483                 if (wufc & E1000_WUFC_MC) {
4484                         rctl = er32(RCTL);
4485                         rctl |= E1000_RCTL_MPE;
4486                         ew32(RCTL, rctl);
4487                 }
4488
4489                 ctrl = er32(CTRL);
4490                 /* advertise wake from D3Cold */
4491                 #define E1000_CTRL_ADVD3WUC 0x00100000
4492                 /* phy power management enable */
4493                 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4494                 ctrl |= E1000_CTRL_ADVD3WUC;
4495                 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
4496                         ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
4497                 ew32(CTRL, ctrl);
4498
4499                 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
4500                     adapter->hw.phy.media_type ==
4501                     e1000_media_type_internal_serdes) {
4502                         /* keep the laser running in D3 */
4503                         ctrl_ext = er32(CTRL_EXT);
4504                         ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4505                         ew32(CTRL_EXT, ctrl_ext);
4506                 }
4507
4508                 if (adapter->flags & FLAG_IS_ICH)
4509                         e1000e_disable_gig_wol_ich8lan(&adapter->hw);
4510
4511                 /* Allow time for pending master requests to run */
4512                 e1000e_disable_pcie_master(&adapter->hw);
4513
4514                 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
4515                         /* enable wakeup by the PHY */
4516                         retval = e1000_init_phy_wakeup(adapter, wufc);
4517                         if (retval)
4518                                 return retval;
4519                 } else {
4520                         /* enable wakeup by the MAC */
4521                         ew32(WUFC, wufc);
4522                         ew32(WUC, E1000_WUC_PME_EN);
4523                 }
4524         } else {
4525                 ew32(WUC, 0);
4526                 ew32(WUFC, 0);
4527         }
4528
4529         *enable_wake = !!wufc;
4530
4531         /* make sure adapter isn't asleep if manageability is enabled */
4532         if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
4533             (hw->mac.ops.check_mng_mode(hw)))
4534                 *enable_wake = true;
4535
4536         if (adapter->hw.phy.type == e1000_phy_igp_3)
4537                 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
4538
4539         /*
4540          * Release control of h/w to f/w.  If f/w is AMT enabled, this
4541          * would have already happened in close and is redundant.
4542          */
4543         e1000_release_hw_control(adapter);
4544
4545         pci_disable_device(pdev);
4546
4547         return 0;
4548 }
4549
4550 static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
4551 {
4552         if (sleep && wake) {
4553                 pci_prepare_to_sleep(pdev);
4554                 return;
4555         }
4556
4557         pci_wake_from_d3(pdev, wake);
4558         pci_set_power_state(pdev, PCI_D3hot);
4559 }
4560
4561 static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
4562                                     bool wake)
4563 {
4564         struct net_device *netdev = pci_get_drvdata(pdev);
4565         struct e1000_adapter *adapter = netdev_priv(netdev);
4566
4567         /*
4568          * The pci-e switch on some quad port adapters will report a
4569          * correctable error when the MAC transitions from D0 to D3.  To
4570          * prevent this we need to mask off the correctable errors on the
4571          * downstream port of the pci-e switch.
4572          */
4573         if (adapter->flags & FLAG_IS_QUAD_PORT) {
4574                 struct pci_dev *us_dev = pdev->bus->self;
4575                 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
4576                 u16 devctl;
4577
4578                 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
4579                 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
4580                                       (devctl & ~PCI_EXP_DEVCTL_CERE));
4581
4582                 e1000_power_off(pdev, sleep, wake);
4583
4584                 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
4585         } else {
4586                 e1000_power_off(pdev, sleep, wake);
4587         }
4588 }
4589
4590 static void e1000e_disable_l1aspm(struct pci_dev *pdev)
4591 {
4592         int pos;
4593         u16 val;
4594
4595         /*
4596          * 82573 workaround - disable L1 ASPM on mobile chipsets
4597          *
4598          * L1 ASPM on various mobile (ich7) chipsets do not behave properly
4599          * resulting in lost data or garbage information on the pci-e link
4600          * level. This could result in (false) bad EEPROM checksum errors,
4601          * long ping times (up to 2s) or even a system freeze/hang.
4602          *
4603          * Unfortunately this feature saves about 1W power consumption when
4604          * active.
4605          */
4606         pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
4607         pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val);
4608         if (val & 0x2) {
4609                 dev_warn(&pdev->dev, "Disabling L1 ASPM\n");
4610                 val &= ~0x2;
4611                 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val);
4612         }
4613 }
4614
4615 #ifdef CONFIG_PM
4616 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4617 {
4618         int retval;
4619         bool wake;
4620
4621         retval = __e1000_shutdown(pdev, &wake);
4622         if (!retval)
4623                 e1000_complete_shutdown(pdev, true, wake);
4624
4625         return retval;
4626 }
4627
4628 static int e1000_resume(struct pci_dev *pdev)
4629 {
4630         struct net_device *netdev = pci_get_drvdata(pdev);
4631         struct e1000_adapter *adapter = netdev_priv(netdev);
4632         struct e1000_hw *hw = &adapter->hw;
4633         u32 err;
4634
4635         pci_set_power_state(pdev, PCI_D0);
4636         pci_restore_state(pdev);
4637         e1000e_disable_l1aspm(pdev);
4638
4639         err = pci_enable_device_mem(pdev);
4640         if (err) {
4641                 dev_err(&pdev->dev,
4642                         "Cannot enable PCI device from suspend\n");
4643                 return err;
4644         }
4645
4646         pci_set_master(pdev);
4647
4648         pci_enable_wake(pdev, PCI_D3hot, 0);
4649         pci_enable_wake(pdev, PCI_D3cold, 0);
4650
4651         e1000e_set_interrupt_capability(adapter);
4652         if (netif_running(netdev)) {
4653                 err = e1000_request_irq(adapter);
4654                 if (err)
4655                         return err;
4656         }
4657
4658         e1000e_power_up_phy(adapter);
4659
4660         /* report the system wakeup cause from S3/S4 */
4661         if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
4662                 u16 phy_data;
4663
4664                 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
4665                 if (phy_data) {
4666                         e_info("PHY Wakeup cause - %s\n",
4667                                 phy_data & E1000_WUS_EX ? "Unicast Packet" :
4668                                 phy_data & E1000_WUS_MC ? "Multicast Packet" :
4669                                 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
4670                                 phy_data & E1000_WUS_MAG ? "Magic Packet" :
4671                                 phy_data & E1000_WUS_LNKC ? "Link Status "
4672                                 " Change" : "other");
4673                 }
4674                 e1e_wphy(&adapter->hw, BM_WUS, ~0);
4675         } else {
4676                 u32 wus = er32(WUS);
4677                 if (wus) {
4678                         e_info("MAC Wakeup cause - %s\n",
4679                                 wus & E1000_WUS_EX ? "Unicast Packet" :
4680                                 wus & E1000_WUS_MC ? "Multicast Packet" :
4681                                 wus & E1000_WUS_BC ? "Broadcast Packet" :
4682                                 wus & E1000_WUS_MAG ? "Magic Packet" :
4683                                 wus & E1000_WUS_LNKC ? "Link Status Change" :
4684                                 "other");
4685                 }
4686                 ew32(WUS, ~0);
4687         }
4688
4689         e1000e_reset(adapter);
4690
4691         e1000_init_manageability(adapter);
4692
4693         if (netif_running(netdev))
4694                 e1000e_up(adapter);
4695
4696         netif_device_attach(netdev);
4697
4698         /*
4699          * If the controller has AMT, do not set DRV_LOAD until the interface
4700          * is up.  For all other cases, let the f/w know that the h/w is now
4701          * under the control of the driver.
4702          */
4703         if (!(adapter->flags & FLAG_HAS_AMT))
4704                 e1000_get_hw_control(adapter);
4705
4706         return 0;
4707 }
4708 #endif
4709
4710 static void e1000_shutdown(struct pci_dev *pdev)
4711 {
4712         bool wake = false;
4713
4714         __e1000_shutdown(pdev, &wake);
4715
4716         if (system_state == SYSTEM_POWER_OFF)
4717                 e1000_complete_shutdown(pdev, false, wake);
4718 }
4719
4720 #ifdef CONFIG_NET_POLL_CONTROLLER
4721 /*
4722  * Polling 'interrupt' - used by things like netconsole to send skbs
4723  * without having to re-enable interrupts. It's not called while
4724  * the interrupt routine is executing.
4725  */
4726 static void e1000_netpoll(struct net_device *netdev)
4727 {
4728         struct e1000_adapter *adapter = netdev_priv(netdev);
4729
4730         disable_irq(adapter->pdev->irq);
4731         e1000_intr(adapter->pdev->irq, netdev);
4732
4733         enable_irq(adapter->pdev->irq);
4734 }
4735 #endif
4736
4737 /**
4738  * e1000_io_error_detected - called when PCI error is detected
4739  * @pdev: Pointer to PCI device
4740  * @state: The current pci connection state
4741  *
4742  * This function is called after a PCI bus error affecting
4743  * this device has been detected.
4744  */
4745 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
4746                                                 pci_channel_state_t state)
4747 {
4748         struct net_device *netdev = pci_get_drvdata(pdev);
4749         struct e1000_adapter *adapter = netdev_priv(netdev);
4750
4751         netif_device_detach(netdev);
4752
4753         if (state == pci_channel_io_perm_failure)
4754                 return PCI_ERS_RESULT_DISCONNECT;
4755
4756         if (netif_running(netdev))
4757                 e1000e_down(adapter);
4758         pci_disable_device(pdev);
4759
4760         /* Request a slot slot reset. */
4761         return PCI_ERS_RESULT_NEED_RESET;
4762 }
4763
4764 /**
4765  * e1000_io_slot_reset - called after the pci bus has been reset.
4766  * @pdev: Pointer to PCI device
4767  *
4768  * Restart the card from scratch, as if from a cold-boot. Implementation
4769  * resembles the first-half of the e1000_resume routine.
4770  */
4771 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4772 {
4773         struct net_device *netdev = pci_get_drvdata(pdev);
4774         struct e1000_adapter *adapter = netdev_priv(netdev);
4775         struct e1000_hw *hw = &adapter->hw;
4776         int err;
4777         pci_ers_result_t result;
4778
4779         e1000e_disable_l1aspm(pdev);
4780         err = pci_enable_device_mem(pdev);
4781         if (err) {
4782                 dev_err(&pdev->dev,
4783                         "Cannot re-enable PCI device after reset.\n");
4784                 result = PCI_ERS_RESULT_DISCONNECT;
4785         } else {
4786                 pci_set_master(pdev);
4787                 pci_restore_state(pdev);
4788
4789                 pci_enable_wake(pdev, PCI_D3hot, 0);
4790                 pci_enable_wake(pdev, PCI_D3cold, 0);
4791
4792                 e1000e_reset(adapter);
4793                 ew32(WUS, ~0);
4794                 result = PCI_ERS_RESULT_RECOVERED;
4795         }
4796
4797         pci_cleanup_aer_uncorrect_error_status(pdev);
4798
4799         return result;
4800 }
4801
4802 /**
4803  * e1000_io_resume - called when traffic can start flowing again.
4804  * @pdev: Pointer to PCI device
4805  *
4806  * This callback is called when the error recovery driver tells us that
4807  * its OK to resume normal operation. Implementation resembles the
4808  * second-half of the e1000_resume routine.
4809  */
4810 static void e1000_io_resume(struct pci_dev *pdev)
4811 {
4812         struct net_device *netdev = pci_get_drvdata(pdev);
4813         struct e1000_adapter *adapter = netdev_priv(netdev);
4814
4815         e1000_init_manageability(adapter);
4816
4817         if (netif_running(netdev)) {
4818                 if (e1000e_up(adapter)) {
4819                         dev_err(&pdev->dev,
4820                                 "can't bring device back up after reset\n");
4821                         return;
4822                 }
4823         }
4824
4825         netif_device_attach(netdev);
4826
4827         /*
4828          * If the controller has AMT, do not set DRV_LOAD until the interface
4829          * is up.  For all other cases, let the f/w know that the h/w is now
4830          * under the control of the driver.
4831          */
4832         if (!(adapter->flags & FLAG_HAS_AMT))
4833                 e1000_get_hw_control(adapter);
4834
4835 }
4836
4837 static void e1000_print_device_info(struct e1000_adapter *adapter)
4838 {
4839         struct e1000_hw *hw = &adapter->hw;
4840         struct net_device *netdev = adapter->netdev;
4841         u32 pba_num;
4842
4843         /* print bus type/speed/width info */
4844         e_info("(PCI Express:2.5GB/s:%s) %pM\n",
4845                /* bus width */
4846                ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
4847                 "Width x1"),
4848                /* MAC address */
4849                netdev->dev_addr);
4850         e_info("Intel(R) PRO/%s Network Connection\n",
4851                (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
4852         e1000e_read_pba_num(hw, &pba_num);
4853         e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4854                hw->mac.type, hw->phy.type, (pba_num >> 8), (pba_num & 0xff));
4855 }
4856
4857 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
4858 {
4859         struct e1000_hw *hw = &adapter->hw;
4860         int ret_val;
4861         u16 buf = 0;
4862
4863         if (hw->mac.type != e1000_82573)
4864                 return;
4865
4866         ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
4867         if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
4868                 /* Deep Smart Power Down (DSPD) */
4869                 dev_warn(&adapter->pdev->dev,
4870                          "Warning: detected DSPD enabled in EEPROM\n");
4871         }
4872
4873         ret_val = e1000_read_nvm(hw, NVM_INIT_3GIO_3, 1, &buf);
4874         if (!ret_val && (le16_to_cpu(buf) & (3 << 2))) {
4875                 /* ASPM enable */
4876                 dev_warn(&adapter->pdev->dev,
4877                          "Warning: detected ASPM enabled in EEPROM\n");
4878         }
4879 }
4880
4881 static const struct net_device_ops e1000e_netdev_ops = {
4882         .ndo_open               = e1000_open,
4883         .ndo_stop               = e1000_close,
4884         .ndo_start_xmit         = e1000_xmit_frame,
4885         .ndo_get_stats          = e1000_get_stats,
4886         .ndo_set_multicast_list = e1000_set_multi,
4887         .ndo_set_mac_address    = e1000_set_mac,
4888         .ndo_change_mtu         = e1000_change_mtu,
4889         .ndo_do_ioctl           = e1000_ioctl,
4890         .ndo_tx_timeout         = e1000_tx_timeout,
4891         .ndo_validate_addr      = eth_validate_addr,
4892
4893         .ndo_vlan_rx_register   = e1000_vlan_rx_register,
4894         .ndo_vlan_rx_add_vid    = e1000_vlan_rx_add_vid,
4895         .ndo_vlan_rx_kill_vid   = e1000_vlan_rx_kill_vid,
4896 #ifdef CONFIG_NET_POLL_CONTROLLER
4897         .ndo_poll_controller    = e1000_netpoll,
4898 #endif
4899 };
4900
4901 /**
4902  * e1000_probe - Device Initialization Routine
4903  * @pdev: PCI device information struct
4904  * @ent: entry in e1000_pci_tbl
4905  *
4906  * Returns 0 on success, negative on failure
4907  *
4908  * e1000_probe initializes an adapter identified by a pci_dev structure.
4909  * The OS initialization, configuring of the adapter private structure,
4910  * and a hardware reset occur.
4911  **/
4912 static int __devinit e1000_probe(struct pci_dev *pdev,
4913                                  const struct pci_device_id *ent)
4914 {
4915         struct net_device *netdev;
4916         struct e1000_adapter *adapter;
4917         struct e1000_hw *hw;
4918         const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
4919         resource_size_t mmio_start, mmio_len;
4920         resource_size_t flash_start, flash_len;
4921
4922         static int cards_found;
4923         int i, err, pci_using_dac;
4924         u16 eeprom_data = 0;
4925         u16 eeprom_apme_mask = E1000_EEPROM_APME;
4926
4927         e1000e_disable_l1aspm(pdev);
4928
4929         err = pci_enable_device_mem(pdev);
4930         if (err)
4931                 return err;
4932
4933         pci_using_dac = 0;
4934         err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
4935         if (!err) {
4936                 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
4937                 if (!err)
4938                         pci_using_dac = 1;
4939         } else {
4940                 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
4941                 if (err) {
4942                         err = pci_set_consistent_dma_mask(pdev,
4943                                                           DMA_BIT_MASK(32));
4944                         if (err) {
4945                                 dev_err(&pdev->dev, "No usable DMA "
4946                                         "configuration, aborting\n");
4947                                 goto err_dma;
4948                         }
4949                 }
4950         }
4951
4952         err = pci_request_selected_regions_exclusive(pdev,
4953                                           pci_select_bars(pdev, IORESOURCE_MEM),
4954                                           e1000e_driver_name);
4955         if (err)
4956                 goto err_pci_reg;
4957
4958         /* AER (Advanced Error Reporting) hooks */
4959         pci_enable_pcie_error_reporting(pdev);
4960
4961         pci_set_master(pdev);
4962         /* PCI config space info */
4963         err = pci_save_state(pdev);
4964         if (err)
4965                 goto err_alloc_etherdev;
4966
4967         err = -ENOMEM;
4968         netdev = alloc_etherdev(sizeof(struct e1000_adapter));
4969         if (!netdev)
4970                 goto err_alloc_etherdev;
4971
4972         SET_NETDEV_DEV(netdev, &pdev->dev);
4973
4974         pci_set_drvdata(pdev, netdev);
4975         adapter = netdev_priv(netdev);
4976         hw = &adapter->hw;
4977         adapter->netdev = netdev;
4978         adapter->pdev = pdev;
4979         adapter->ei = ei;
4980         adapter->pba = ei->pba;
4981         adapter->flags = ei->flags;
4982         adapter->flags2 = ei->flags2;
4983         adapter->hw.adapter = adapter;
4984         adapter->hw.mac.type = ei->mac;
4985         adapter->max_hw_frame_size = ei->max_hw_frame_size;
4986         adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
4987
4988         mmio_start = pci_resource_start(pdev, 0);
4989         mmio_len = pci_resource_len(pdev, 0);
4990
4991         err = -EIO;
4992         adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
4993         if (!adapter->hw.hw_addr)
4994                 goto err_ioremap;
4995
4996         if ((adapter->flags & FLAG_HAS_FLASH) &&
4997             (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
4998                 flash_start = pci_resource_start(pdev, 1);
4999                 flash_len = pci_resource_len(pdev, 1);
5000                 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5001                 if (!adapter->hw.flash_address)
5002                         goto err_flashmap;
5003         }
5004
5005         /* construct the net_device struct */
5006         netdev->netdev_ops              = &e1000e_netdev_ops;
5007         e1000e_set_ethtool_ops(netdev);
5008         netdev->watchdog_timeo          = 5 * HZ;
5009         netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
5010         strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5011
5012         netdev->mem_start = mmio_start;
5013         netdev->mem_end = mmio_start + mmio_len;
5014
5015         adapter->bd_number = cards_found++;
5016
5017         e1000e_check_options(adapter);
5018
5019         /* setup adapter struct */
5020         err = e1000_sw_init(adapter);
5021         if (err)
5022                 goto err_sw_init;
5023
5024         err = -EIO;
5025
5026         memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5027         memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5028         memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5029
5030         err = ei->get_variants(adapter);
5031         if (err)
5032                 goto err_hw_init;
5033
5034         if ((adapter->flags & FLAG_IS_ICH) &&
5035             (adapter->flags & FLAG_READ_ONLY_NVM))
5036                 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5037
5038         hw->mac.ops.get_bus_info(&adapter->hw);
5039
5040         adapter->hw.phy.autoneg_wait_to_complete = 0;
5041
5042         /* Copper options */
5043         if (adapter->hw.phy.media_type == e1000_media_type_copper) {
5044                 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5045                 adapter->hw.phy.disable_polarity_correction = 0;
5046                 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5047         }
5048
5049         if (e1000_check_reset_block(&adapter->hw))
5050                 e_info("PHY reset is blocked due to SOL/IDER session.\n");
5051
5052         netdev->features = NETIF_F_SG |
5053                            NETIF_F_HW_CSUM |
5054                            NETIF_F_HW_VLAN_TX |
5055                            NETIF_F_HW_VLAN_RX;
5056
5057         if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5058                 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5059
5060         netdev->features |= NETIF_F_TSO;
5061         netdev->features |= NETIF_F_TSO6;
5062
5063         netdev->vlan_features |= NETIF_F_TSO;
5064         netdev->vlan_features |= NETIF_F_TSO6;
5065         netdev->vlan_features |= NETIF_F_HW_CSUM;
5066         netdev->vlan_features |= NETIF_F_SG;
5067
5068         if (pci_using_dac)
5069                 netdev->features |= NETIF_F_HIGHDMA;
5070
5071         if (e1000e_enable_mng_pass_thru(&adapter->hw))
5072                 adapter->flags |= FLAG_MNG_PT_ENABLED;
5073
5074         /*
5075          * before reading the NVM, reset the controller to
5076          * put the device in a known good starting state
5077          */
5078         adapter->hw.mac.ops.reset_hw(&adapter->hw);
5079
5080         /*
5081          * systems with ASPM and others may see the checksum fail on the first
5082          * attempt. Let's give it a few tries
5083          */
5084         for (i = 0;; i++) {
5085                 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5086                         break;
5087                 if (i == 2) {
5088                         e_err("The NVM Checksum Is Not Valid\n");
5089                         err = -EIO;
5090                         goto err_eeprom;
5091                 }
5092         }
5093
5094         e1000_eeprom_checks(adapter);
5095
5096         /* copy the MAC address out of the NVM */
5097         if (e1000e_read_mac_addr(&adapter->hw))
5098                 e_err("NVM Read Error while reading MAC address\n");
5099
5100         memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5101         memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5102
5103         if (!is_valid_ether_addr(netdev->perm_addr)) {
5104                 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
5105                 err = -EIO;
5106                 goto err_eeprom;
5107         }
5108
5109         init_timer(&adapter->watchdog_timer);
5110         adapter->watchdog_timer.function = &e1000_watchdog;
5111         adapter->watchdog_timer.data = (unsigned long) adapter;
5112
5113         init_timer(&adapter->phy_info_timer);
5114         adapter->phy_info_timer.function = &e1000_update_phy_info;
5115         adapter->phy_info_timer.data = (unsigned long) adapter;
5116
5117         INIT_WORK(&adapter->reset_task, e1000_reset_task);
5118         INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
5119         INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
5120         INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
5121
5122         /* Initialize link parameters. User can change them with ethtool */
5123         adapter->hw.mac.autoneg = 1;
5124         adapter->fc_autoneg = 1;
5125         adapter->hw.fc.requested_mode = e1000_fc_default;
5126         adapter->hw.fc.current_mode = e1000_fc_default;
5127         adapter->hw.phy.autoneg_advertised = 0x2f;
5128
5129         /* ring size defaults */
5130         adapter->rx_ring->count = 256;
5131         adapter->tx_ring->count = 256;
5132
5133         /*
5134          * Initial Wake on LAN setting - If APM wake is enabled in
5135          * the EEPROM, enable the ACPI Magic Packet filter
5136          */
5137         if (adapter->flags & FLAG_APME_IN_WUC) {
5138                 /* APME bit in EEPROM is mapped to WUC.APME */
5139                 eeprom_data = er32(WUC);
5140                 eeprom_apme_mask = E1000_WUC_APME;
5141                 if (eeprom_data & E1000_WUC_PHY_WAKE)
5142                         adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
5143         } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
5144                 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
5145                     (adapter->hw.bus.func == 1))
5146                         e1000_read_nvm(&adapter->hw,
5147                                 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
5148                 else
5149                         e1000_read_nvm(&adapter->hw,
5150                                 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
5151         }
5152
5153         /* fetch WoL from EEPROM */
5154         if (eeprom_data & eeprom_apme_mask)
5155                 adapter->eeprom_wol |= E1000_WUFC_MAG;
5156
5157         /*
5158          * now that we have the eeprom settings, apply the special cases
5159          * where the eeprom may be wrong or the board simply won't support
5160          * wake on lan on a particular port
5161          */
5162         if (!(adapter->flags & FLAG_HAS_WOL))
5163                 adapter->eeprom_wol = 0;
5164
5165         /* initialize the wol settings based on the eeprom settings */
5166         adapter->wol = adapter->eeprom_wol;
5167         device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5168
5169         /* save off EEPROM version number */
5170         e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
5171
5172         /* reset the hardware with the new settings */
5173         e1000e_reset(adapter);
5174
5175         /*
5176          * If the controller has AMT, do not set DRV_LOAD until the interface
5177          * is up.  For all other cases, let the f/w know that the h/w is now
5178          * under the control of the driver.
5179          */
5180         if (!(adapter->flags & FLAG_HAS_AMT))
5181                 e1000_get_hw_control(adapter);
5182
5183         strcpy(netdev->name, "eth%d");
5184         err = register_netdev(netdev);
5185         if (err)
5186                 goto err_register;
5187
5188         /* carrier off reporting is important to ethtool even BEFORE open */
5189         netif_carrier_off(netdev);
5190
5191         e1000_print_device_info(adapter);
5192
5193         return 0;
5194
5195 err_register:
5196         if (!(adapter->flags & FLAG_HAS_AMT))
5197                 e1000_release_hw_control(adapter);
5198 err_eeprom:
5199         if (!e1000_check_reset_block(&adapter->hw))
5200                 e1000_phy_hw_reset(&adapter->hw);
5201 err_hw_init:
5202
5203         kfree(adapter->tx_ring);
5204         kfree(adapter->rx_ring);
5205 err_sw_init:
5206         if (adapter->hw.flash_address)
5207                 iounmap(adapter->hw.flash_address);
5208         e1000e_reset_interrupt_capability(adapter);
5209 err_flashmap:
5210         iounmap(adapter->hw.hw_addr);
5211 err_ioremap:
5212         free_netdev(netdev);
5213 err_alloc_etherdev:
5214         pci_release_selected_regions(pdev,
5215                                      pci_select_bars(pdev, IORESOURCE_MEM));
5216 err_pci_reg:
5217 err_dma:
5218         pci_disable_device(pdev);
5219         return err;
5220 }
5221
5222 /**
5223  * e1000_remove - Device Removal Routine
5224  * @pdev: PCI device information struct
5225  *
5226  * e1000_remove is called by the PCI subsystem to alert the driver
5227  * that it should release a PCI device.  The could be caused by a
5228  * Hot-Plug event, or because the driver is going to be removed from
5229  * memory.
5230  **/
5231 static void __devexit e1000_remove(struct pci_dev *pdev)
5232 {
5233         struct net_device *netdev = pci_get_drvdata(pdev);
5234         struct e1000_adapter *adapter = netdev_priv(netdev);
5235
5236         /*
5237          * flush_scheduled work may reschedule our watchdog task, so
5238          * explicitly disable watchdog tasks from being rescheduled
5239          */
5240         set_bit(__E1000_DOWN, &adapter->state);
5241         del_timer_sync(&adapter->watchdog_timer);
5242         del_timer_sync(&adapter->phy_info_timer);
5243
5244         flush_scheduled_work();
5245
5246         /*
5247          * Release control of h/w to f/w.  If f/w is AMT enabled, this
5248          * would have already happened in close and is redundant.
5249          */
5250         e1000_release_hw_control(adapter);
5251
5252         unregister_netdev(netdev);
5253
5254         if (!e1000_check_reset_block(&adapter->hw))
5255                 e1000_phy_hw_reset(&adapter->hw);
5256
5257         e1000e_reset_interrupt_capability(adapter);
5258         kfree(adapter->tx_ring);
5259         kfree(adapter->rx_ring);
5260
5261         iounmap(adapter->hw.hw_addr);
5262         if (adapter->hw.flash_address)
5263                 iounmap(adapter->hw.flash_address);
5264         pci_release_selected_regions(pdev,
5265                                      pci_select_bars(pdev, IORESOURCE_MEM));
5266
5267         free_netdev(netdev);
5268
5269         /* AER disable */
5270         pci_disable_pcie_error_reporting(pdev);
5271
5272         pci_disable_device(pdev);
5273 }
5274
5275 /* PCI Error Recovery (ERS) */
5276 static struct pci_error_handlers e1000_err_handler = {
5277         .error_detected = e1000_io_error_detected,
5278         .slot_reset = e1000_io_slot_reset,
5279         .resume = e1000_io_resume,
5280 };
5281
5282 static struct pci_device_id e1000_pci_tbl[] = {
5283         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
5284         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
5285         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
5286         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
5287         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
5288         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
5289         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
5290         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
5291         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
5292
5293         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
5294         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
5295         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
5296         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
5297
5298         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
5299         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
5300         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
5301
5302         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
5303         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
5304         { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
5305
5306         { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
5307           board_80003es2lan },
5308         { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
5309           board_80003es2lan },
5310         { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
5311           board_80003es2lan },
5312         { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
5313           board_80003es2lan },
5314
5315         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
5316         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
5317         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
5318         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
5319         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
5320         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
5321         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
5322
5323         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
5324         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
5325         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
5326         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
5327         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
5328         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
5329         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
5330         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
5331         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
5332
5333         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
5334         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
5335         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
5336
5337         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
5338         { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
5339
5340         { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
5341         { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
5342         { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
5343         { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
5344
5345         { }     /* terminate list */
5346 };
5347 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
5348
5349 /* PCI Device API Driver */
5350 static struct pci_driver e1000_driver = {
5351         .name     = e1000e_driver_name,
5352         .id_table = e1000_pci_tbl,
5353         .probe    = e1000_probe,
5354         .remove   = __devexit_p(e1000_remove),
5355 #ifdef CONFIG_PM
5356         /* Power Management Hooks */
5357         .suspend  = e1000_suspend,
5358         .resume   = e1000_resume,
5359 #endif
5360         .shutdown = e1000_shutdown,
5361         .err_handler = &e1000_err_handler
5362 };
5363
5364 /**
5365  * e1000_init_module - Driver Registration Routine
5366  *
5367  * e1000_init_module is the first routine called when the driver is
5368  * loaded. All it does is register with the PCI subsystem.
5369  **/
5370 static int __init e1000_init_module(void)
5371 {
5372         int ret;
5373         printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
5374                e1000e_driver_name, e1000e_driver_version);
5375         printk(KERN_INFO "%s: Copyright (c) 1999-2008 Intel Corporation.\n",
5376                e1000e_driver_name);
5377         ret = pci_register_driver(&e1000_driver);
5378         pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name,
5379                                PM_QOS_DEFAULT_VALUE);
5380                                 
5381         return ret;
5382 }
5383 module_init(e1000_init_module);
5384
5385 /**
5386  * e1000_exit_module - Driver Exit Cleanup Routine
5387  *
5388  * e1000_exit_module is called just before the driver is removed
5389  * from memory.
5390  **/
5391 static void __exit e1000_exit_module(void)
5392 {
5393         pci_unregister_driver(&e1000_driver);
5394         pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name);
5395 }
5396 module_exit(e1000_exit_module);
5397
5398
5399 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
5400 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
5401 MODULE_LICENSE("GPL");
5402 MODULE_VERSION(DRV_VERSION);
5403
5404 /* e1000_main.c */