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