blob: 679885a122b4da068878a4bcd471c45ecd4e905a [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanad680762008-03-28 09:15:03 -07004 Copyright(c) 1999 - 2008 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
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>
Bruce Allan97ac8ca2008-04-29 09:16:05 -070046#include <linux/pm_qos_params.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000047#include <linux/aer.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070048
49#include "e1000.h"
50
Bruce Allan3be8c942009-06-02 11:29:56 +000051#define DRV_VERSION "1.0.2-k2"
Auke Kokbc7f75f2007-09-17 12:30:59 -070052char e1000e_driver_name[] = "e1000e";
53const char e1000e_driver_version[] = DRV_VERSION;
54
55static const struct e1000_info *e1000_info_tbl[] = {
56 [board_82571] = &e1000_82571_info,
57 [board_82572] = &e1000_82572_info,
58 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070059 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000060 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070061 [board_80003es2lan] = &e1000_es2_info,
62 [board_ich8lan] = &e1000_ich8_info,
63 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070064 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000065 [board_pchlan] = &e1000_pch_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070066};
67
68#ifdef DEBUG
69/**
70 * e1000_get_hw_dev_name - return device name string
71 * used by hardware layer to print debugging information
72 **/
73char *e1000e_get_hw_dev_name(struct e1000_hw *hw)
74{
Auke Kok589c0852007-10-04 11:38:43 -070075 return hw->adapter->netdev->name;
Auke Kokbc7f75f2007-09-17 12:30:59 -070076}
77#endif
78
79/**
80 * e1000_desc_unused - calculate if we have unused descriptors
81 **/
82static int e1000_desc_unused(struct e1000_ring *ring)
83{
84 if (ring->next_to_clean > ring->next_to_use)
85 return ring->next_to_clean - ring->next_to_use - 1;
86
87 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
88}
89
90/**
Bruce Allanad680762008-03-28 09:15:03 -070091 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -070092 * @adapter: board private structure
93 * @status: descriptor status field as written by hardware
94 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
95 * @skb: pointer to sk_buff to be indicated to stack
96 **/
97static void e1000_receive_skb(struct e1000_adapter *adapter,
98 struct net_device *netdev,
99 struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000100 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700101{
102 skb->protocol = eth_type_trans(skb, netdev);
103
104 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
Herbert Xuc405b822009-01-14 20:37:59 -0800105 vlan_gro_receive(&adapter->napi, adapter->vlgrp,
106 le16_to_cpu(vlan), skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700107 else
Herbert Xu89c88b12008-12-15 23:46:15 -0800108 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700109}
110
111/**
112 * e1000_rx_checksum - Receive Checksum Offload for 82543
113 * @adapter: board private structure
114 * @status_err: receive descriptor status and error fields
115 * @csum: receive descriptor csum field
116 * @sk_buff: socket buffer with received data
117 **/
118static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
119 u32 csum, struct sk_buff *skb)
120{
121 u16 status = (u16)status_err;
122 u8 errors = (u8)(status_err >> 24);
123 skb->ip_summed = CHECKSUM_NONE;
124
125 /* Ignore Checksum bit is set */
126 if (status & E1000_RXD_STAT_IXSM)
127 return;
128 /* TCP/UDP checksum error bit is set */
129 if (errors & E1000_RXD_ERR_TCPE) {
130 /* let the stack verify checksum errors */
131 adapter->hw_csum_err++;
132 return;
133 }
134
135 /* TCP/UDP Checksum has not been calculated */
136 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
137 return;
138
139 /* It must be a TCP or UDP packet with a valid checksum */
140 if (status & E1000_RXD_STAT_TCPCS) {
141 /* TCP checksum is good */
142 skb->ip_summed = CHECKSUM_UNNECESSARY;
143 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700144 /*
145 * IP fragment with UDP payload
146 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700147 * and then put the value in host order for further stack use.
148 */
Al Viroa39fe742007-12-11 19:50:34 +0000149 __sum16 sum = (__force __sum16)htons(csum);
150 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700151 skb->ip_summed = CHECKSUM_COMPLETE;
152 }
153 adapter->hw_csum_good++;
154}
155
156/**
157 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
158 * @adapter: address of board private structure
159 **/
160static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
161 int cleaned_count)
162{
163 struct net_device *netdev = adapter->netdev;
164 struct pci_dev *pdev = adapter->pdev;
165 struct e1000_ring *rx_ring = adapter->rx_ring;
166 struct e1000_rx_desc *rx_desc;
167 struct e1000_buffer *buffer_info;
168 struct sk_buff *skb;
169 unsigned int i;
170 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
171
172 i = rx_ring->next_to_use;
173 buffer_info = &rx_ring->buffer_info[i];
174
175 while (cleaned_count--) {
176 skb = buffer_info->skb;
177 if (skb) {
178 skb_trim(skb, 0);
179 goto map_skb;
180 }
181
182 skb = netdev_alloc_skb(netdev, bufsz);
183 if (!skb) {
184 /* Better luck next round */
185 adapter->alloc_rx_buff_failed++;
186 break;
187 }
188
Bruce Allanad680762008-03-28 09:15:03 -0700189 /*
190 * Make buffer alignment 2 beyond a 16 byte boundary
Auke Kokbc7f75f2007-09-17 12:30:59 -0700191 * this will result in a 16 byte aligned IP header after
192 * the 14 byte MAC header is removed
193 */
194 skb_reserve(skb, NET_IP_ALIGN);
195
196 buffer_info->skb = skb;
197map_skb:
198 buffer_info->dma = pci_map_single(pdev, skb->data,
199 adapter->rx_buffer_len,
200 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700201 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700202 dev_err(&pdev->dev, "RX DMA map failed\n");
203 adapter->rx_dma_failed++;
204 break;
205 }
206
207 rx_desc = E1000_RX_DESC(*rx_ring, i);
208 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
209
210 i++;
211 if (i == rx_ring->count)
212 i = 0;
213 buffer_info = &rx_ring->buffer_info[i];
214 }
215
216 if (rx_ring->next_to_use != i) {
217 rx_ring->next_to_use = i;
218 if (i-- == 0)
219 i = (rx_ring->count - 1);
220
Bruce Allanad680762008-03-28 09:15:03 -0700221 /*
222 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -0700223 * know there are new descriptors to fetch. (Only
224 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -0700225 * such as IA-64).
226 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700227 wmb();
228 writel(i, adapter->hw.hw_addr + rx_ring->tail);
229 }
230}
231
232/**
233 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
234 * @adapter: address of board private structure
235 **/
236static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
237 int cleaned_count)
238{
239 struct net_device *netdev = adapter->netdev;
240 struct pci_dev *pdev = adapter->pdev;
241 union e1000_rx_desc_packet_split *rx_desc;
242 struct e1000_ring *rx_ring = adapter->rx_ring;
243 struct e1000_buffer *buffer_info;
244 struct e1000_ps_page *ps_page;
245 struct sk_buff *skb;
246 unsigned int i, j;
247
248 i = rx_ring->next_to_use;
249 buffer_info = &rx_ring->buffer_info[i];
250
251 while (cleaned_count--) {
252 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
253
254 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700255 ps_page = &buffer_info->ps_pages[j];
256 if (j >= adapter->rx_ps_pages) {
257 /* all unused desc entries get hw null ptr */
Al Viroa39fe742007-12-11 19:50:34 +0000258 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700259 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700260 }
Auke Kok47f44e42007-10-25 13:57:44 -0700261 if (!ps_page->page) {
262 ps_page->page = alloc_page(GFP_ATOMIC);
263 if (!ps_page->page) {
264 adapter->alloc_rx_buff_failed++;
265 goto no_buffers;
266 }
267 ps_page->dma = pci_map_page(pdev,
268 ps_page->page,
269 0, PAGE_SIZE,
270 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700271 if (pci_dma_mapping_error(pdev, ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700272 dev_err(&adapter->pdev->dev,
273 "RX DMA page map failed\n");
274 adapter->rx_dma_failed++;
275 goto no_buffers;
276 }
277 }
278 /*
279 * Refresh the desc even if buffer_addrs
280 * didn't change because each write-back
281 * erases this info.
282 */
283 rx_desc->read.buffer_addr[j+1] =
284 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700285 }
286
287 skb = netdev_alloc_skb(netdev,
288 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
289
290 if (!skb) {
291 adapter->alloc_rx_buff_failed++;
292 break;
293 }
294
Bruce Allanad680762008-03-28 09:15:03 -0700295 /*
296 * Make buffer alignment 2 beyond a 16 byte boundary
Auke Kokbc7f75f2007-09-17 12:30:59 -0700297 * this will result in a 16 byte aligned IP header after
298 * the 14 byte MAC header is removed
299 */
300 skb_reserve(skb, NET_IP_ALIGN);
301
302 buffer_info->skb = skb;
303 buffer_info->dma = pci_map_single(pdev, skb->data,
304 adapter->rx_ps_bsize0,
305 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700306 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700307 dev_err(&pdev->dev, "RX DMA map failed\n");
308 adapter->rx_dma_failed++;
309 /* cleanup skb */
310 dev_kfree_skb_any(skb);
311 buffer_info->skb = NULL;
312 break;
313 }
314
315 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
316
317 i++;
318 if (i == rx_ring->count)
319 i = 0;
320 buffer_info = &rx_ring->buffer_info[i];
321 }
322
323no_buffers:
324 if (rx_ring->next_to_use != i) {
325 rx_ring->next_to_use = i;
326
327 if (!(i--))
328 i = (rx_ring->count - 1);
329
Bruce Allanad680762008-03-28 09:15:03 -0700330 /*
331 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -0700332 * know there are new descriptors to fetch. (Only
333 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -0700334 * such as IA-64).
335 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700336 wmb();
Bruce Allanad680762008-03-28 09:15:03 -0700337 /*
338 * Hardware increments by 16 bytes, but packet split
Auke Kokbc7f75f2007-09-17 12:30:59 -0700339 * descriptors are 32 bytes...so we increment tail
340 * twice as much.
341 */
342 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
343 }
344}
345
346/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700347 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
348 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700349 * @cleaned_count: number of buffers to allocate this pass
350 **/
351
352static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
353 int cleaned_count)
354{
355 struct net_device *netdev = adapter->netdev;
356 struct pci_dev *pdev = adapter->pdev;
357 struct e1000_rx_desc *rx_desc;
358 struct e1000_ring *rx_ring = adapter->rx_ring;
359 struct e1000_buffer *buffer_info;
360 struct sk_buff *skb;
361 unsigned int i;
362 unsigned int bufsz = 256 -
363 16 /* for skb_reserve */ -
364 NET_IP_ALIGN;
365
366 i = rx_ring->next_to_use;
367 buffer_info = &rx_ring->buffer_info[i];
368
369 while (cleaned_count--) {
370 skb = buffer_info->skb;
371 if (skb) {
372 skb_trim(skb, 0);
373 goto check_page;
374 }
375
376 skb = netdev_alloc_skb(netdev, bufsz);
377 if (unlikely(!skb)) {
378 /* Better luck next round */
379 adapter->alloc_rx_buff_failed++;
380 break;
381 }
382
383 /* Make buffer alignment 2 beyond a 16 byte boundary
384 * this will result in a 16 byte aligned IP header after
385 * the 14 byte MAC header is removed
386 */
387 skb_reserve(skb, NET_IP_ALIGN);
388
389 buffer_info->skb = skb;
390check_page:
391 /* allocate a new page if necessary */
392 if (!buffer_info->page) {
393 buffer_info->page = alloc_page(GFP_ATOMIC);
394 if (unlikely(!buffer_info->page)) {
395 adapter->alloc_rx_buff_failed++;
396 break;
397 }
398 }
399
400 if (!buffer_info->dma)
401 buffer_info->dma = pci_map_page(pdev,
402 buffer_info->page, 0,
403 PAGE_SIZE,
404 PCI_DMA_FROMDEVICE);
405
406 rx_desc = E1000_RX_DESC(*rx_ring, i);
407 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
408
409 if (unlikely(++i == rx_ring->count))
410 i = 0;
411 buffer_info = &rx_ring->buffer_info[i];
412 }
413
414 if (likely(rx_ring->next_to_use != i)) {
415 rx_ring->next_to_use = i;
416 if (unlikely(i-- == 0))
417 i = (rx_ring->count - 1);
418
419 /* Force memory writes to complete before letting h/w
420 * know there are new descriptors to fetch. (Only
421 * applicable for weak-ordered memory model archs,
422 * such as IA-64). */
423 wmb();
424 writel(i, adapter->hw.hw_addr + rx_ring->tail);
425 }
426}
427
428/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700429 * e1000_clean_rx_irq - Send received data up the network stack; legacy
430 * @adapter: board private structure
431 *
432 * the return value indicates whether actual cleaning was done, there
433 * is no guarantee that everything was cleaned
434 **/
435static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
436 int *work_done, int work_to_do)
437{
438 struct net_device *netdev = adapter->netdev;
439 struct pci_dev *pdev = adapter->pdev;
440 struct e1000_ring *rx_ring = adapter->rx_ring;
441 struct e1000_rx_desc *rx_desc, *next_rxd;
442 struct e1000_buffer *buffer_info, *next_buffer;
443 u32 length;
444 unsigned int i;
445 int cleaned_count = 0;
446 bool cleaned = 0;
447 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
448
449 i = rx_ring->next_to_clean;
450 rx_desc = E1000_RX_DESC(*rx_ring, i);
451 buffer_info = &rx_ring->buffer_info[i];
452
453 while (rx_desc->status & E1000_RXD_STAT_DD) {
454 struct sk_buff *skb;
455 u8 status;
456
457 if (*work_done >= work_to_do)
458 break;
459 (*work_done)++;
460
461 status = rx_desc->status;
462 skb = buffer_info->skb;
463 buffer_info->skb = NULL;
464
465 prefetch(skb->data - NET_IP_ALIGN);
466
467 i++;
468 if (i == rx_ring->count)
469 i = 0;
470 next_rxd = E1000_RX_DESC(*rx_ring, i);
471 prefetch(next_rxd);
472
473 next_buffer = &rx_ring->buffer_info[i];
474
475 cleaned = 1;
476 cleaned_count++;
477 pci_unmap_single(pdev,
478 buffer_info->dma,
479 adapter->rx_buffer_len,
480 PCI_DMA_FROMDEVICE);
481 buffer_info->dma = 0;
482
483 length = le16_to_cpu(rx_desc->length);
484
485 /* !EOP means multiple descriptors were used to store a single
486 * packet, also make sure the frame isn't just CRC only */
487 if (!(status & E1000_RXD_STAT_EOP) || (length <= 4)) {
488 /* All receives must fit into a single buffer */
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700489 e_dbg("%s: Receive packet consumed multiple buffers\n",
490 netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700491 /* recycle */
492 buffer_info->skb = skb;
493 goto next_desc;
494 }
495
496 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
497 /* recycle */
498 buffer_info->skb = skb;
499 goto next_desc;
500 }
501
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000502 /* adjust length to remove Ethernet CRC */
503 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
504 length -= 4;
505
Auke Kokbc7f75f2007-09-17 12:30:59 -0700506 total_rx_bytes += length;
507 total_rx_packets++;
508
Bruce Allanad680762008-03-28 09:15:03 -0700509 /*
510 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700511 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700512 * of reassembly being done in the stack
513 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700514 if (length < copybreak) {
515 struct sk_buff *new_skb =
516 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
517 if (new_skb) {
518 skb_reserve(new_skb, NET_IP_ALIGN);
Bruce Allan808ff672008-08-08 18:35:56 -0700519 skb_copy_to_linear_data_offset(new_skb,
520 -NET_IP_ALIGN,
521 (skb->data -
522 NET_IP_ALIGN),
523 (length +
524 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700525 /* save the skb in buffer_info as good */
526 buffer_info->skb = skb;
527 skb = new_skb;
528 }
529 /* else just continue with the old one */
530 }
531 /* end copybreak code */
532 skb_put(skb, length);
533
534 /* Receive Checksum Offload */
535 e1000_rx_checksum(adapter,
536 (u32)(status) |
537 ((u32)(rx_desc->errors) << 24),
538 le16_to_cpu(rx_desc->csum), skb);
539
540 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
541
542next_desc:
543 rx_desc->status = 0;
544
545 /* return some buffers to hardware, one at a time is too slow */
546 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
547 adapter->alloc_rx_buf(adapter, cleaned_count);
548 cleaned_count = 0;
549 }
550
551 /* use prefetched values */
552 rx_desc = next_rxd;
553 buffer_info = next_buffer;
554 }
555 rx_ring->next_to_clean = i;
556
557 cleaned_count = e1000_desc_unused(rx_ring);
558 if (cleaned_count)
559 adapter->alloc_rx_buf(adapter, cleaned_count);
560
Auke Kokbc7f75f2007-09-17 12:30:59 -0700561 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700562 adapter->total_rx_packets += total_rx_packets;
Auke Kok41988692007-11-13 20:48:36 -0800563 adapter->net_stats.rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700564 adapter->net_stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700565 return cleaned;
566}
567
Auke Kokbc7f75f2007-09-17 12:30:59 -0700568static void e1000_put_txbuf(struct e1000_adapter *adapter,
569 struct e1000_buffer *buffer_info)
570{
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -0800571 buffer_info->dma = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700572 if (buffer_info->skb) {
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -0800573 skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
574 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700575 dev_kfree_skb_any(buffer_info->skb);
576 buffer_info->skb = NULL;
577 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000578 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700579}
580
581static void e1000_print_tx_hang(struct e1000_adapter *adapter)
582{
583 struct e1000_ring *tx_ring = adapter->tx_ring;
584 unsigned int i = tx_ring->next_to_clean;
585 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
586 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700587
588 /* detected Tx unit hang */
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700589 e_err("Detected Tx Unit Hang:\n"
590 " TDH <%x>\n"
591 " TDT <%x>\n"
592 " next_to_use <%x>\n"
593 " next_to_clean <%x>\n"
594 "buffer_info[next_to_clean]:\n"
595 " time_stamp <%lx>\n"
596 " next_to_watch <%x>\n"
597 " jiffies <%lx>\n"
598 " next_to_watch.status <%x>\n",
599 readl(adapter->hw.hw_addr + tx_ring->head),
600 readl(adapter->hw.hw_addr + tx_ring->tail),
601 tx_ring->next_to_use,
602 tx_ring->next_to_clean,
603 tx_ring->buffer_info[eop].time_stamp,
604 eop,
605 jiffies,
606 eop_desc->upper.fields.status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700607}
608
609/**
610 * e1000_clean_tx_irq - Reclaim resources after transmit completes
611 * @adapter: board private structure
612 *
613 * the return value indicates whether actual cleaning was done, there
614 * is no guarantee that everything was cleaned
615 **/
616static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
617{
618 struct net_device *netdev = adapter->netdev;
619 struct e1000_hw *hw = &adapter->hw;
620 struct e1000_ring *tx_ring = adapter->tx_ring;
621 struct e1000_tx_desc *tx_desc, *eop_desc;
622 struct e1000_buffer *buffer_info;
623 unsigned int i, eop;
624 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700625 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
626
627 i = tx_ring->next_to_clean;
628 eop = tx_ring->buffer_info[i].next_to_watch;
629 eop_desc = E1000_TX_DESC(*tx_ring, eop);
630
Alexander Duyck12d04a32009-03-25 22:05:03 +0000631 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
632 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +0000633 bool cleaned = false;
634 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700635 tx_desc = E1000_TX_DESC(*tx_ring, i);
636 buffer_info = &tx_ring->buffer_info[i];
637 cleaned = (i == eop);
638
639 if (cleaned) {
640 struct sk_buff *skb = buffer_info->skb;
641 unsigned int segs, bytecount;
642 segs = skb_shinfo(skb)->gso_segs ?: 1;
643 /* multiply data chunks by size of headers */
644 bytecount = ((segs - 1) * skb_headlen(skb)) +
645 skb->len;
646 total_tx_packets += segs;
647 total_tx_bytes += bytecount;
648 }
649
650 e1000_put_txbuf(adapter, buffer_info);
651 tx_desc->upper.data = 0;
652
653 i++;
654 if (i == tx_ring->count)
655 i = 0;
656 }
657
658 eop = tx_ring->buffer_info[i].next_to_watch;
659 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660 }
661
662 tx_ring->next_to_clean = i;
663
664#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +0000665 if (count && netif_carrier_ok(netdev) &&
666 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700667 /* Make sure that anybody stopping the queue after this
668 * sees the new next_to_clean.
669 */
670 smp_mb();
671
672 if (netif_queue_stopped(netdev) &&
673 !(test_bit(__E1000_DOWN, &adapter->state))) {
674 netif_wake_queue(netdev);
675 ++adapter->restart_queue;
676 }
677 }
678
679 if (adapter->detect_tx_hung) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000680 /* Detect a transmit hang in hardware, this serializes the
681 * check with the clearing of time_stamp and movement of i */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700682 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +0000683 if (tx_ring->buffer_info[i].time_stamp &&
684 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Auke Kokbc7f75f2007-09-17 12:30:59 -0700685 + (adapter->tx_timeout_factor * HZ))
Bruce Allanad680762008-03-28 09:15:03 -0700686 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700687 e1000_print_tx_hang(adapter);
688 netif_stop_queue(netdev);
689 }
690 }
691 adapter->total_tx_bytes += total_tx_bytes;
692 adapter->total_tx_packets += total_tx_packets;
Auke Kok41988692007-11-13 20:48:36 -0800693 adapter->net_stats.tx_bytes += total_tx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700694 adapter->net_stats.tx_packets += total_tx_packets;
Alexander Duyck12d04a32009-03-25 22:05:03 +0000695 return (count < tx_ring->count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700696}
697
698/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700699 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
700 * @adapter: board private structure
701 *
702 * the return value indicates whether actual cleaning was done, there
703 * is no guarantee that everything was cleaned
704 **/
705static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
706 int *work_done, int work_to_do)
707{
708 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
709 struct net_device *netdev = adapter->netdev;
710 struct pci_dev *pdev = adapter->pdev;
711 struct e1000_ring *rx_ring = adapter->rx_ring;
712 struct e1000_buffer *buffer_info, *next_buffer;
713 struct e1000_ps_page *ps_page;
714 struct sk_buff *skb;
715 unsigned int i, j;
716 u32 length, staterr;
717 int cleaned_count = 0;
718 bool cleaned = 0;
719 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
720
721 i = rx_ring->next_to_clean;
722 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
723 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
724 buffer_info = &rx_ring->buffer_info[i];
725
726 while (staterr & E1000_RXD_STAT_DD) {
727 if (*work_done >= work_to_do)
728 break;
729 (*work_done)++;
730 skb = buffer_info->skb;
731
732 /* in the packet split case this is header only */
733 prefetch(skb->data - NET_IP_ALIGN);
734
735 i++;
736 if (i == rx_ring->count)
737 i = 0;
738 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
739 prefetch(next_rxd);
740
741 next_buffer = &rx_ring->buffer_info[i];
742
743 cleaned = 1;
744 cleaned_count++;
745 pci_unmap_single(pdev, buffer_info->dma,
746 adapter->rx_ps_bsize0,
747 PCI_DMA_FROMDEVICE);
748 buffer_info->dma = 0;
749
750 if (!(staterr & E1000_RXD_STAT_EOP)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700751 e_dbg("%s: Packet Split buffers didn't pick up the "
752 "full packet\n", netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700753 dev_kfree_skb_irq(skb);
754 goto next_desc;
755 }
756
757 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
758 dev_kfree_skb_irq(skb);
759 goto next_desc;
760 }
761
762 length = le16_to_cpu(rx_desc->wb.middle.length0);
763
764 if (!length) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700765 e_dbg("%s: Last part of the packet spanning multiple "
766 "descriptors\n", netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700767 dev_kfree_skb_irq(skb);
768 goto next_desc;
769 }
770
771 /* Good Receive */
772 skb_put(skb, length);
773
774 {
Bruce Allanad680762008-03-28 09:15:03 -0700775 /*
776 * this looks ugly, but it seems compiler issues make it
777 * more efficient than reusing j
778 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700779 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
780
Bruce Allanad680762008-03-28 09:15:03 -0700781 /*
782 * page alloc/put takes too long and effects small packet
783 * throughput, so unsplit small packets and save the alloc/put
784 * only valid in softirq (napi) context to call kmap_*
785 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700786 if (l1 && (l1 <= copybreak) &&
787 ((length + l1) <= adapter->rx_ps_bsize0)) {
788 u8 *vaddr;
789
Auke Kok47f44e42007-10-25 13:57:44 -0700790 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700791
Bruce Allanad680762008-03-28 09:15:03 -0700792 /*
793 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -0700794 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -0700795 * very long
796 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700797 pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
798 PAGE_SIZE, PCI_DMA_FROMDEVICE);
799 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
800 memcpy(skb_tail_pointer(skb), vaddr, l1);
801 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
802 pci_dma_sync_single_for_device(pdev, ps_page->dma,
803 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kok140a7482007-10-25 13:57:58 -0700804
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000805 /* remove the CRC */
806 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
807 l1 -= 4;
808
Auke Kokbc7f75f2007-09-17 12:30:59 -0700809 skb_put(skb, l1);
810 goto copydone;
811 } /* if */
812 }
813
814 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
815 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
816 if (!length)
817 break;
818
Auke Kok47f44e42007-10-25 13:57:44 -0700819 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700820 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
821 PCI_DMA_FROMDEVICE);
822 ps_page->dma = 0;
823 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
824 ps_page->page = NULL;
825 skb->len += length;
826 skb->data_len += length;
827 skb->truesize += length;
828 }
829
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000830 /* strip the ethernet crc, problem is we're using pages now so
831 * this whole operation can get a little cpu intensive
832 */
833 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
834 pskb_trim(skb, skb->len - 4);
835
Auke Kokbc7f75f2007-09-17 12:30:59 -0700836copydone:
837 total_rx_bytes += skb->len;
838 total_rx_packets++;
839
840 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
841 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
842
843 if (rx_desc->wb.upper.header_status &
844 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
845 adapter->rx_hdr_split++;
846
847 e1000_receive_skb(adapter, netdev, skb,
848 staterr, rx_desc->wb.middle.vlan);
849
850next_desc:
851 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
852 buffer_info->skb = NULL;
853
854 /* return some buffers to hardware, one at a time is too slow */
855 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
856 adapter->alloc_rx_buf(adapter, cleaned_count);
857 cleaned_count = 0;
858 }
859
860 /* use prefetched values */
861 rx_desc = next_rxd;
862 buffer_info = next_buffer;
863
864 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
865 }
866 rx_ring->next_to_clean = i;
867
868 cleaned_count = e1000_desc_unused(rx_ring);
869 if (cleaned_count)
870 adapter->alloc_rx_buf(adapter, cleaned_count);
871
Auke Kokbc7f75f2007-09-17 12:30:59 -0700872 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700873 adapter->total_rx_packets += total_rx_packets;
Auke Kok41988692007-11-13 20:48:36 -0800874 adapter->net_stats.rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700875 adapter->net_stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700876 return cleaned;
877}
878
879/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700880 * e1000_consume_page - helper function
881 **/
882static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
883 u16 length)
884{
885 bi->page = NULL;
886 skb->len += length;
887 skb->data_len += length;
888 skb->truesize += length;
889}
890
891/**
892 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
893 * @adapter: board private structure
894 *
895 * the return value indicates whether actual cleaning was done, there
896 * is no guarantee that everything was cleaned
897 **/
898
899static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
900 int *work_done, int work_to_do)
901{
902 struct net_device *netdev = adapter->netdev;
903 struct pci_dev *pdev = adapter->pdev;
904 struct e1000_ring *rx_ring = adapter->rx_ring;
905 struct e1000_rx_desc *rx_desc, *next_rxd;
906 struct e1000_buffer *buffer_info, *next_buffer;
907 u32 length;
908 unsigned int i;
909 int cleaned_count = 0;
910 bool cleaned = false;
911 unsigned int total_rx_bytes=0, total_rx_packets=0;
912
913 i = rx_ring->next_to_clean;
914 rx_desc = E1000_RX_DESC(*rx_ring, i);
915 buffer_info = &rx_ring->buffer_info[i];
916
917 while (rx_desc->status & E1000_RXD_STAT_DD) {
918 struct sk_buff *skb;
919 u8 status;
920
921 if (*work_done >= work_to_do)
922 break;
923 (*work_done)++;
924
925 status = rx_desc->status;
926 skb = buffer_info->skb;
927 buffer_info->skb = NULL;
928
929 ++i;
930 if (i == rx_ring->count)
931 i = 0;
932 next_rxd = E1000_RX_DESC(*rx_ring, i);
933 prefetch(next_rxd);
934
935 next_buffer = &rx_ring->buffer_info[i];
936
937 cleaned = true;
938 cleaned_count++;
939 pci_unmap_page(pdev, buffer_info->dma, PAGE_SIZE,
940 PCI_DMA_FROMDEVICE);
941 buffer_info->dma = 0;
942
943 length = le16_to_cpu(rx_desc->length);
944
945 /* errors is only valid for DD + EOP descriptors */
946 if (unlikely((status & E1000_RXD_STAT_EOP) &&
947 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
948 /* recycle both page and skb */
949 buffer_info->skb = skb;
950 /* an error means any chain goes out the window
951 * too */
952 if (rx_ring->rx_skb_top)
953 dev_kfree_skb(rx_ring->rx_skb_top);
954 rx_ring->rx_skb_top = NULL;
955 goto next_desc;
956 }
957
958#define rxtop rx_ring->rx_skb_top
959 if (!(status & E1000_RXD_STAT_EOP)) {
960 /* this descriptor is only the beginning (or middle) */
961 if (!rxtop) {
962 /* this is the beginning of a chain */
963 rxtop = skb;
964 skb_fill_page_desc(rxtop, 0, buffer_info->page,
965 0, length);
966 } else {
967 /* this is the middle of a chain */
968 skb_fill_page_desc(rxtop,
969 skb_shinfo(rxtop)->nr_frags,
970 buffer_info->page, 0, length);
971 /* re-use the skb, only consumed the page */
972 buffer_info->skb = skb;
973 }
974 e1000_consume_page(buffer_info, rxtop, length);
975 goto next_desc;
976 } else {
977 if (rxtop) {
978 /* end of the chain */
979 skb_fill_page_desc(rxtop,
980 skb_shinfo(rxtop)->nr_frags,
981 buffer_info->page, 0, length);
982 /* re-use the current skb, we only consumed the
983 * page */
984 buffer_info->skb = skb;
985 skb = rxtop;
986 rxtop = NULL;
987 e1000_consume_page(buffer_info, skb, length);
988 } else {
989 /* no chain, got EOP, this buf is the packet
990 * copybreak to save the put_page/alloc_page */
991 if (length <= copybreak &&
992 skb_tailroom(skb) >= length) {
993 u8 *vaddr;
994 vaddr = kmap_atomic(buffer_info->page,
995 KM_SKB_DATA_SOFTIRQ);
996 memcpy(skb_tail_pointer(skb), vaddr,
997 length);
998 kunmap_atomic(vaddr,
999 KM_SKB_DATA_SOFTIRQ);
1000 /* re-use the page, so don't erase
1001 * buffer_info->page */
1002 skb_put(skb, length);
1003 } else {
1004 skb_fill_page_desc(skb, 0,
1005 buffer_info->page, 0,
1006 length);
1007 e1000_consume_page(buffer_info, skb,
1008 length);
1009 }
1010 }
1011 }
1012
1013 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1014 e1000_rx_checksum(adapter,
1015 (u32)(status) |
1016 ((u32)(rx_desc->errors) << 24),
1017 le16_to_cpu(rx_desc->csum), skb);
1018
1019 /* probably a little skewed due to removing CRC */
1020 total_rx_bytes += skb->len;
1021 total_rx_packets++;
1022
1023 /* eth type trans needs skb->data to point to something */
1024 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001025 e_err("pskb_may_pull failed.\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001026 dev_kfree_skb(skb);
1027 goto next_desc;
1028 }
1029
1030 e1000_receive_skb(adapter, netdev, skb, status,
1031 rx_desc->special);
1032
1033next_desc:
1034 rx_desc->status = 0;
1035
1036 /* return some buffers to hardware, one at a time is too slow */
1037 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1038 adapter->alloc_rx_buf(adapter, cleaned_count);
1039 cleaned_count = 0;
1040 }
1041
1042 /* use prefetched values */
1043 rx_desc = next_rxd;
1044 buffer_info = next_buffer;
1045 }
1046 rx_ring->next_to_clean = i;
1047
1048 cleaned_count = e1000_desc_unused(rx_ring);
1049 if (cleaned_count)
1050 adapter->alloc_rx_buf(adapter, cleaned_count);
1051
1052 adapter->total_rx_bytes += total_rx_bytes;
1053 adapter->total_rx_packets += total_rx_packets;
1054 adapter->net_stats.rx_bytes += total_rx_bytes;
1055 adapter->net_stats.rx_packets += total_rx_packets;
1056 return cleaned;
1057}
1058
1059/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001060 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1061 * @adapter: board private structure
1062 **/
1063static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1064{
1065 struct e1000_ring *rx_ring = adapter->rx_ring;
1066 struct e1000_buffer *buffer_info;
1067 struct e1000_ps_page *ps_page;
1068 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001069 unsigned int i, j;
1070
1071 /* Free all the Rx ring sk_buffs */
1072 for (i = 0; i < rx_ring->count; i++) {
1073 buffer_info = &rx_ring->buffer_info[i];
1074 if (buffer_info->dma) {
1075 if (adapter->clean_rx == e1000_clean_rx_irq)
1076 pci_unmap_single(pdev, buffer_info->dma,
1077 adapter->rx_buffer_len,
1078 PCI_DMA_FROMDEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001079 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1080 pci_unmap_page(pdev, buffer_info->dma,
1081 PAGE_SIZE,
1082 PCI_DMA_FROMDEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001083 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1084 pci_unmap_single(pdev, buffer_info->dma,
1085 adapter->rx_ps_bsize0,
1086 PCI_DMA_FROMDEVICE);
1087 buffer_info->dma = 0;
1088 }
1089
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001090 if (buffer_info->page) {
1091 put_page(buffer_info->page);
1092 buffer_info->page = NULL;
1093 }
1094
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095 if (buffer_info->skb) {
1096 dev_kfree_skb(buffer_info->skb);
1097 buffer_info->skb = NULL;
1098 }
1099
1100 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001101 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102 if (!ps_page->page)
1103 break;
1104 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
1105 PCI_DMA_FROMDEVICE);
1106 ps_page->dma = 0;
1107 put_page(ps_page->page);
1108 ps_page->page = NULL;
1109 }
1110 }
1111
1112 /* there also may be some cached data from a chained receive */
1113 if (rx_ring->rx_skb_top) {
1114 dev_kfree_skb(rx_ring->rx_skb_top);
1115 rx_ring->rx_skb_top = NULL;
1116 }
1117
Auke Kokbc7f75f2007-09-17 12:30:59 -07001118 /* Zero out the descriptor ring */
1119 memset(rx_ring->desc, 0, rx_ring->size);
1120
1121 rx_ring->next_to_clean = 0;
1122 rx_ring->next_to_use = 0;
1123
1124 writel(0, adapter->hw.hw_addr + rx_ring->head);
1125 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1126}
1127
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001128static void e1000e_downshift_workaround(struct work_struct *work)
1129{
1130 struct e1000_adapter *adapter = container_of(work,
1131 struct e1000_adapter, downshift_task);
1132
1133 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1134}
1135
Auke Kokbc7f75f2007-09-17 12:30:59 -07001136/**
1137 * e1000_intr_msi - Interrupt Handler
1138 * @irq: interrupt number
1139 * @data: pointer to a network interface device structure
1140 **/
1141static irqreturn_t e1000_intr_msi(int irq, void *data)
1142{
1143 struct net_device *netdev = data;
1144 struct e1000_adapter *adapter = netdev_priv(netdev);
1145 struct e1000_hw *hw = &adapter->hw;
1146 u32 icr = er32(ICR);
1147
Bruce Allanad680762008-03-28 09:15:03 -07001148 /*
1149 * read ICR disables interrupts using IAM
1150 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001151
dave graham573cca82009-02-10 12:52:05 +00001152 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001153 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001154 /*
1155 * ICH8 workaround-- Call gig speed drop workaround on cable
1156 * disconnect (LSC) before accessing any PHY registers
1157 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1159 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001160 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001161
Bruce Allanad680762008-03-28 09:15:03 -07001162 /*
1163 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001164 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001165 * adapter in watchdog
1166 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167 if (netif_carrier_ok(netdev) &&
1168 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1169 /* disable receives */
1170 u32 rctl = er32(RCTL);
1171 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001172 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001173 }
1174 /* guard against interrupt when we're going down */
1175 if (!test_bit(__E1000_DOWN, &adapter->state))
1176 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1177 }
1178
Ben Hutchings288379f2009-01-19 16:43:59 -08001179 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180 adapter->total_tx_bytes = 0;
1181 adapter->total_tx_packets = 0;
1182 adapter->total_rx_bytes = 0;
1183 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001184 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 }
1186
1187 return IRQ_HANDLED;
1188}
1189
1190/**
1191 * e1000_intr - Interrupt Handler
1192 * @irq: interrupt number
1193 * @data: pointer to a network interface device structure
1194 **/
1195static irqreturn_t e1000_intr(int irq, void *data)
1196{
1197 struct net_device *netdev = data;
1198 struct e1000_adapter *adapter = netdev_priv(netdev);
1199 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001201
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202 if (!icr)
1203 return IRQ_NONE; /* Not our interrupt */
1204
Bruce Allanad680762008-03-28 09:15:03 -07001205 /*
1206 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1207 * not set, then the adapter didn't send an interrupt
1208 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209 if (!(icr & E1000_ICR_INT_ASSERTED))
1210 return IRQ_NONE;
1211
Bruce Allanad680762008-03-28 09:15:03 -07001212 /*
1213 * Interrupt Auto-Mask...upon reading ICR,
1214 * interrupts are masked. No need for the
1215 * IMC write
1216 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217
dave graham573cca82009-02-10 12:52:05 +00001218 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001219 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001220 /*
1221 * ICH8 workaround-- Call gig speed drop workaround on cable
1222 * disconnect (LSC) before accessing any PHY registers
1223 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001224 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1225 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001226 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001227
Bruce Allanad680762008-03-28 09:15:03 -07001228 /*
1229 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001230 * For packet buffer work-around on link down event;
1231 * disable receives here in the ISR and
1232 * reset adapter in watchdog
1233 */
1234 if (netif_carrier_ok(netdev) &&
1235 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1236 /* disable receives */
1237 rctl = er32(RCTL);
1238 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001239 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001240 }
1241 /* guard against interrupt when we're going down */
1242 if (!test_bit(__E1000_DOWN, &adapter->state))
1243 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1244 }
1245
Ben Hutchings288379f2009-01-19 16:43:59 -08001246 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001247 adapter->total_tx_bytes = 0;
1248 adapter->total_tx_packets = 0;
1249 adapter->total_rx_bytes = 0;
1250 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001251 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001252 }
1253
1254 return IRQ_HANDLED;
1255}
1256
Bruce Allan4662e822008-08-26 18:37:06 -07001257static irqreturn_t e1000_msix_other(int irq, void *data)
1258{
1259 struct net_device *netdev = data;
1260 struct e1000_adapter *adapter = netdev_priv(netdev);
1261 struct e1000_hw *hw = &adapter->hw;
1262 u32 icr = er32(ICR);
1263
1264 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001265 if (!test_bit(__E1000_DOWN, &adapter->state))
1266 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001267 return IRQ_NONE;
1268 }
1269
1270 if (icr & adapter->eiac_mask)
1271 ew32(ICS, (icr & adapter->eiac_mask));
1272
1273 if (icr & E1000_ICR_OTHER) {
1274 if (!(icr & E1000_ICR_LSC))
1275 goto no_link_interrupt;
1276 hw->mac.get_link_status = 1;
1277 /* guard against interrupt when we're going down */
1278 if (!test_bit(__E1000_DOWN, &adapter->state))
1279 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1280 }
1281
1282no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001283 if (!test_bit(__E1000_DOWN, &adapter->state))
1284 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001285
1286 return IRQ_HANDLED;
1287}
1288
1289
1290static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1291{
1292 struct net_device *netdev = data;
1293 struct e1000_adapter *adapter = netdev_priv(netdev);
1294 struct e1000_hw *hw = &adapter->hw;
1295 struct e1000_ring *tx_ring = adapter->tx_ring;
1296
1297
1298 adapter->total_tx_bytes = 0;
1299 adapter->total_tx_packets = 0;
1300
1301 if (!e1000_clean_tx_irq(adapter))
1302 /* Ring was not completely cleaned, so fire another interrupt */
1303 ew32(ICS, tx_ring->ims_val);
1304
1305 return IRQ_HANDLED;
1306}
1307
1308static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1309{
1310 struct net_device *netdev = data;
1311 struct e1000_adapter *adapter = netdev_priv(netdev);
1312
1313 /* Write the ITR value calculated at the end of the
1314 * previous interrupt.
1315 */
1316 if (adapter->rx_ring->set_itr) {
1317 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1318 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1319 adapter->rx_ring->set_itr = 0;
1320 }
1321
Ben Hutchings288379f2009-01-19 16:43:59 -08001322 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001323 adapter->total_rx_bytes = 0;
1324 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001325 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001326 }
1327 return IRQ_HANDLED;
1328}
1329
1330/**
1331 * e1000_configure_msix - Configure MSI-X hardware
1332 *
1333 * e1000_configure_msix sets up the hardware to properly
1334 * generate MSI-X interrupts.
1335 **/
1336static void e1000_configure_msix(struct e1000_adapter *adapter)
1337{
1338 struct e1000_hw *hw = &adapter->hw;
1339 struct e1000_ring *rx_ring = adapter->rx_ring;
1340 struct e1000_ring *tx_ring = adapter->tx_ring;
1341 int vector = 0;
1342 u32 ctrl_ext, ivar = 0;
1343
1344 adapter->eiac_mask = 0;
1345
1346 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1347 if (hw->mac.type == e1000_82574) {
1348 u32 rfctl = er32(RFCTL);
1349 rfctl |= E1000_RFCTL_ACK_DIS;
1350 ew32(RFCTL, rfctl);
1351 }
1352
1353#define E1000_IVAR_INT_ALLOC_VALID 0x8
1354 /* Configure Rx vector */
1355 rx_ring->ims_val = E1000_IMS_RXQ0;
1356 adapter->eiac_mask |= rx_ring->ims_val;
1357 if (rx_ring->itr_val)
1358 writel(1000000000 / (rx_ring->itr_val * 256),
1359 hw->hw_addr + rx_ring->itr_register);
1360 else
1361 writel(1, hw->hw_addr + rx_ring->itr_register);
1362 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1363
1364 /* Configure Tx vector */
1365 tx_ring->ims_val = E1000_IMS_TXQ0;
1366 vector++;
1367 if (tx_ring->itr_val)
1368 writel(1000000000 / (tx_ring->itr_val * 256),
1369 hw->hw_addr + tx_ring->itr_register);
1370 else
1371 writel(1, hw->hw_addr + tx_ring->itr_register);
1372 adapter->eiac_mask |= tx_ring->ims_val;
1373 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1374
1375 /* set vector for Other Causes, e.g. link changes */
1376 vector++;
1377 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1378 if (rx_ring->itr_val)
1379 writel(1000000000 / (rx_ring->itr_val * 256),
1380 hw->hw_addr + E1000_EITR_82574(vector));
1381 else
1382 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1383
1384 /* Cause Tx interrupts on every write back */
1385 ivar |= (1 << 31);
1386
1387 ew32(IVAR, ivar);
1388
1389 /* enable MSI-X PBA support */
1390 ctrl_ext = er32(CTRL_EXT);
1391 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1392
1393 /* Auto-Mask Other interrupts upon ICR read */
1394#define E1000_EIAC_MASK_82574 0x01F00000
1395 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1396 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1397 ew32(CTRL_EXT, ctrl_ext);
1398 e1e_flush();
1399}
1400
1401void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1402{
1403 if (adapter->msix_entries) {
1404 pci_disable_msix(adapter->pdev);
1405 kfree(adapter->msix_entries);
1406 adapter->msix_entries = NULL;
1407 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1408 pci_disable_msi(adapter->pdev);
1409 adapter->flags &= ~FLAG_MSI_ENABLED;
1410 }
1411
1412 return;
1413}
1414
1415/**
1416 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1417 *
1418 * Attempt to configure interrupts using the best available
1419 * capabilities of the hardware and kernel.
1420 **/
1421void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1422{
1423 int err;
1424 int numvecs, i;
1425
1426
1427 switch (adapter->int_mode) {
1428 case E1000E_INT_MODE_MSIX:
1429 if (adapter->flags & FLAG_HAS_MSIX) {
1430 numvecs = 3; /* RxQ0, TxQ0 and other */
1431 adapter->msix_entries = kcalloc(numvecs,
1432 sizeof(struct msix_entry),
1433 GFP_KERNEL);
1434 if (adapter->msix_entries) {
1435 for (i = 0; i < numvecs; i++)
1436 adapter->msix_entries[i].entry = i;
1437
1438 err = pci_enable_msix(adapter->pdev,
1439 adapter->msix_entries,
1440 numvecs);
1441 if (err == 0)
1442 return;
1443 }
1444 /* MSI-X failed, so fall through and try MSI */
1445 e_err("Failed to initialize MSI-X interrupts. "
1446 "Falling back to MSI interrupts.\n");
1447 e1000e_reset_interrupt_capability(adapter);
1448 }
1449 adapter->int_mode = E1000E_INT_MODE_MSI;
1450 /* Fall through */
1451 case E1000E_INT_MODE_MSI:
1452 if (!pci_enable_msi(adapter->pdev)) {
1453 adapter->flags |= FLAG_MSI_ENABLED;
1454 } else {
1455 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1456 e_err("Failed to initialize MSI interrupts. Falling "
1457 "back to legacy interrupts.\n");
1458 }
1459 /* Fall through */
1460 case E1000E_INT_MODE_LEGACY:
1461 /* Don't do anything; this is the system default */
1462 break;
1463 }
1464
1465 return;
1466}
1467
1468/**
1469 * e1000_request_msix - Initialize MSI-X interrupts
1470 *
1471 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1472 * kernel.
1473 **/
1474static int e1000_request_msix(struct e1000_adapter *adapter)
1475{
1476 struct net_device *netdev = adapter->netdev;
1477 int err = 0, vector = 0;
1478
1479 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001480 sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001481 else
1482 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1483 err = request_irq(adapter->msix_entries[vector].vector,
1484 &e1000_intr_msix_rx, 0, adapter->rx_ring->name,
1485 netdev);
1486 if (err)
1487 goto out;
1488 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1489 adapter->rx_ring->itr_val = adapter->itr;
1490 vector++;
1491
1492 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001493 sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001494 else
1495 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1496 err = request_irq(adapter->msix_entries[vector].vector,
1497 &e1000_intr_msix_tx, 0, adapter->tx_ring->name,
1498 netdev);
1499 if (err)
1500 goto out;
1501 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1502 adapter->tx_ring->itr_val = adapter->itr;
1503 vector++;
1504
1505 err = request_irq(adapter->msix_entries[vector].vector,
1506 &e1000_msix_other, 0, netdev->name, netdev);
1507 if (err)
1508 goto out;
1509
1510 e1000_configure_msix(adapter);
1511 return 0;
1512out:
1513 return err;
1514}
1515
Bruce Allanf8d59f72008-08-08 18:36:11 -07001516/**
1517 * e1000_request_irq - initialize interrupts
1518 *
1519 * Attempts to configure interrupts using the best available
1520 * capabilities of the hardware and kernel.
1521 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001522static int e1000_request_irq(struct e1000_adapter *adapter)
1523{
1524 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001525 int err;
1526
Bruce Allan4662e822008-08-26 18:37:06 -07001527 if (adapter->msix_entries) {
1528 err = e1000_request_msix(adapter);
1529 if (!err)
1530 return err;
1531 /* fall back to MSI */
1532 e1000e_reset_interrupt_capability(adapter);
1533 adapter->int_mode = E1000E_INT_MODE_MSI;
1534 e1000e_set_interrupt_capability(adapter);
1535 }
1536 if (adapter->flags & FLAG_MSI_ENABLED) {
1537 err = request_irq(adapter->pdev->irq, &e1000_intr_msi, 0,
1538 netdev->name, netdev);
1539 if (!err)
1540 return err;
1541
1542 /* fall back to legacy interrupt */
1543 e1000e_reset_interrupt_capability(adapter);
1544 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001545 }
1546
Bruce Allan4662e822008-08-26 18:37:06 -07001547 err = request_irq(adapter->pdev->irq, &e1000_intr, IRQF_SHARED,
1548 netdev->name, netdev);
1549 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001550 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001551
1552 return err;
1553}
1554
1555static void e1000_free_irq(struct e1000_adapter *adapter)
1556{
1557 struct net_device *netdev = adapter->netdev;
1558
Bruce Allan4662e822008-08-26 18:37:06 -07001559 if (adapter->msix_entries) {
1560 int vector = 0;
1561
1562 free_irq(adapter->msix_entries[vector].vector, netdev);
1563 vector++;
1564
1565 free_irq(adapter->msix_entries[vector].vector, netdev);
1566 vector++;
1567
1568 /* Other Causes interrupt vector */
1569 free_irq(adapter->msix_entries[vector].vector, netdev);
1570 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001571 }
Bruce Allan4662e822008-08-26 18:37:06 -07001572
1573 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574}
1575
1576/**
1577 * e1000_irq_disable - Mask off interrupt generation on the NIC
1578 **/
1579static void e1000_irq_disable(struct e1000_adapter *adapter)
1580{
1581 struct e1000_hw *hw = &adapter->hw;
1582
Auke Kokbc7f75f2007-09-17 12:30:59 -07001583 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001584 if (adapter->msix_entries)
1585 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001586 e1e_flush();
1587 synchronize_irq(adapter->pdev->irq);
1588}
1589
1590/**
1591 * e1000_irq_enable - Enable default interrupt generation settings
1592 **/
1593static void e1000_irq_enable(struct e1000_adapter *adapter)
1594{
1595 struct e1000_hw *hw = &adapter->hw;
1596
Bruce Allan4662e822008-08-26 18:37:06 -07001597 if (adapter->msix_entries) {
1598 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1599 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1600 } else {
1601 ew32(IMS, IMS_ENABLE_MASK);
1602 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001603 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001604}
1605
1606/**
1607 * e1000_get_hw_control - get control of the h/w from f/w
1608 * @adapter: address of board private structure
1609 *
Auke Kok489815c2008-02-21 15:11:07 -08001610 * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001611 * For ASF and Pass Through versions of f/w this means that
1612 * the driver is loaded. For AMT version (only with 82573)
1613 * of the f/w this means that the network i/f is open.
1614 **/
1615static void e1000_get_hw_control(struct e1000_adapter *adapter)
1616{
1617 struct e1000_hw *hw = &adapter->hw;
1618 u32 ctrl_ext;
1619 u32 swsm;
1620
1621 /* Let firmware know the driver has taken over */
1622 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1623 swsm = er32(SWSM);
1624 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1625 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1626 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07001627 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001628 }
1629}
1630
1631/**
1632 * e1000_release_hw_control - release control of the h/w to f/w
1633 * @adapter: address of board private structure
1634 *
Auke Kok489815c2008-02-21 15:11:07 -08001635 * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636 * For ASF and Pass Through versions of f/w this means that the
1637 * driver is no longer loaded. For AMT version (only with 82573) i
1638 * of the f/w this means that the network i/f is closed.
1639 *
1640 **/
1641static void e1000_release_hw_control(struct e1000_adapter *adapter)
1642{
1643 struct e1000_hw *hw = &adapter->hw;
1644 u32 ctrl_ext;
1645 u32 swsm;
1646
1647 /* Let firmware taken over control of h/w */
1648 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1649 swsm = er32(SWSM);
1650 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1651 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1652 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07001653 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654 }
1655}
1656
Auke Kokbc7f75f2007-09-17 12:30:59 -07001657/**
1658 * @e1000_alloc_ring - allocate memory for a ring structure
1659 **/
1660static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
1661 struct e1000_ring *ring)
1662{
1663 struct pci_dev *pdev = adapter->pdev;
1664
1665 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
1666 GFP_KERNEL);
1667 if (!ring->desc)
1668 return -ENOMEM;
1669
1670 return 0;
1671}
1672
1673/**
1674 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1675 * @adapter: board private structure
1676 *
1677 * Return 0 on success, negative on failure
1678 **/
1679int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
1680{
1681 struct e1000_ring *tx_ring = adapter->tx_ring;
1682 int err = -ENOMEM, size;
1683
1684 size = sizeof(struct e1000_buffer) * tx_ring->count;
1685 tx_ring->buffer_info = vmalloc(size);
1686 if (!tx_ring->buffer_info)
1687 goto err;
1688 memset(tx_ring->buffer_info, 0, size);
1689
1690 /* round up to nearest 4K */
1691 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1692 tx_ring->size = ALIGN(tx_ring->size, 4096);
1693
1694 err = e1000_alloc_ring_dma(adapter, tx_ring);
1695 if (err)
1696 goto err;
1697
1698 tx_ring->next_to_use = 0;
1699 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001700
1701 return 0;
1702err:
1703 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001704 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705 return err;
1706}
1707
1708/**
1709 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1710 * @adapter: board private structure
1711 *
1712 * Returns 0 on success, negative on failure
1713 **/
1714int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
1715{
1716 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07001717 struct e1000_buffer *buffer_info;
1718 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001719
1720 size = sizeof(struct e1000_buffer) * rx_ring->count;
1721 rx_ring->buffer_info = vmalloc(size);
1722 if (!rx_ring->buffer_info)
1723 goto err;
1724 memset(rx_ring->buffer_info, 0, size);
1725
Auke Kok47f44e42007-10-25 13:57:44 -07001726 for (i = 0; i < rx_ring->count; i++) {
1727 buffer_info = &rx_ring->buffer_info[i];
1728 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
1729 sizeof(struct e1000_ps_page),
1730 GFP_KERNEL);
1731 if (!buffer_info->ps_pages)
1732 goto err_pages;
1733 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001734
1735 desc_len = sizeof(union e1000_rx_desc_packet_split);
1736
1737 /* Round up to nearest 4K */
1738 rx_ring->size = rx_ring->count * desc_len;
1739 rx_ring->size = ALIGN(rx_ring->size, 4096);
1740
1741 err = e1000_alloc_ring_dma(adapter, rx_ring);
1742 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07001743 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001744
1745 rx_ring->next_to_clean = 0;
1746 rx_ring->next_to_use = 0;
1747 rx_ring->rx_skb_top = NULL;
1748
1749 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07001750
1751err_pages:
1752 for (i = 0; i < rx_ring->count; i++) {
1753 buffer_info = &rx_ring->buffer_info[i];
1754 kfree(buffer_info->ps_pages);
1755 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001756err:
1757 vfree(rx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001758 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001759 return err;
1760}
1761
1762/**
1763 * e1000_clean_tx_ring - Free Tx Buffers
1764 * @adapter: board private structure
1765 **/
1766static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
1767{
1768 struct e1000_ring *tx_ring = adapter->tx_ring;
1769 struct e1000_buffer *buffer_info;
1770 unsigned long size;
1771 unsigned int i;
1772
1773 for (i = 0; i < tx_ring->count; i++) {
1774 buffer_info = &tx_ring->buffer_info[i];
1775 e1000_put_txbuf(adapter, buffer_info);
1776 }
1777
1778 size = sizeof(struct e1000_buffer) * tx_ring->count;
1779 memset(tx_ring->buffer_info, 0, size);
1780
1781 memset(tx_ring->desc, 0, tx_ring->size);
1782
1783 tx_ring->next_to_use = 0;
1784 tx_ring->next_to_clean = 0;
1785
1786 writel(0, adapter->hw.hw_addr + tx_ring->head);
1787 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1788}
1789
1790/**
1791 * e1000e_free_tx_resources - Free Tx Resources per Queue
1792 * @adapter: board private structure
1793 *
1794 * Free all transmit software resources
1795 **/
1796void e1000e_free_tx_resources(struct e1000_adapter *adapter)
1797{
1798 struct pci_dev *pdev = adapter->pdev;
1799 struct e1000_ring *tx_ring = adapter->tx_ring;
1800
1801 e1000_clean_tx_ring(adapter);
1802
1803 vfree(tx_ring->buffer_info);
1804 tx_ring->buffer_info = NULL;
1805
1806 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1807 tx_ring->dma);
1808 tx_ring->desc = NULL;
1809}
1810
1811/**
1812 * e1000e_free_rx_resources - Free Rx Resources
1813 * @adapter: board private structure
1814 *
1815 * Free all receive software resources
1816 **/
1817
1818void e1000e_free_rx_resources(struct e1000_adapter *adapter)
1819{
1820 struct pci_dev *pdev = adapter->pdev;
1821 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07001822 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001823
1824 e1000_clean_rx_ring(adapter);
1825
Auke Kok47f44e42007-10-25 13:57:44 -07001826 for (i = 0; i < rx_ring->count; i++) {
1827 kfree(rx_ring->buffer_info[i].ps_pages);
1828 }
1829
Auke Kokbc7f75f2007-09-17 12:30:59 -07001830 vfree(rx_ring->buffer_info);
1831 rx_ring->buffer_info = NULL;
1832
Auke Kokbc7f75f2007-09-17 12:30:59 -07001833 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1834 rx_ring->dma);
1835 rx_ring->desc = NULL;
1836}
1837
1838/**
1839 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08001840 * @adapter: pointer to adapter
1841 * @itr_setting: current adapter->itr
1842 * @packets: the number of packets during this measurement interval
1843 * @bytes: the number of bytes during this measurement interval
1844 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07001845 * Stores a new ITR value based on packets and byte
1846 * counts during the last interrupt. The advantage of per interrupt
1847 * computation is faster updates and more accurate ITR for the current
1848 * traffic pattern. Constants in this function were computed
1849 * based on theoretical maximum wire speed and thresholds were set based
1850 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07001851 * while increasing bulk throughput. This functionality is controlled
1852 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001853 **/
1854static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
1855 u16 itr_setting, int packets,
1856 int bytes)
1857{
1858 unsigned int retval = itr_setting;
1859
1860 if (packets == 0)
1861 goto update_itr_done;
1862
1863 switch (itr_setting) {
1864 case lowest_latency:
1865 /* handle TSO and jumbo frames */
1866 if (bytes/packets > 8000)
1867 retval = bulk_latency;
1868 else if ((packets < 5) && (bytes > 512)) {
1869 retval = low_latency;
1870 }
1871 break;
1872 case low_latency: /* 50 usec aka 20000 ints/s */
1873 if (bytes > 10000) {
1874 /* this if handles the TSO accounting */
1875 if (bytes/packets > 8000) {
1876 retval = bulk_latency;
1877 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
1878 retval = bulk_latency;
1879 } else if ((packets > 35)) {
1880 retval = lowest_latency;
1881 }
1882 } else if (bytes/packets > 2000) {
1883 retval = bulk_latency;
1884 } else if (packets <= 2 && bytes < 512) {
1885 retval = lowest_latency;
1886 }
1887 break;
1888 case bulk_latency: /* 250 usec aka 4000 ints/s */
1889 if (bytes > 25000) {
1890 if (packets > 35) {
1891 retval = low_latency;
1892 }
1893 } else if (bytes < 6000) {
1894 retval = low_latency;
1895 }
1896 break;
1897 }
1898
1899update_itr_done:
1900 return retval;
1901}
1902
1903static void e1000_set_itr(struct e1000_adapter *adapter)
1904{
1905 struct e1000_hw *hw = &adapter->hw;
1906 u16 current_itr;
1907 u32 new_itr = adapter->itr;
1908
1909 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1910 if (adapter->link_speed != SPEED_1000) {
1911 current_itr = 0;
1912 new_itr = 4000;
1913 goto set_itr_now;
1914 }
1915
1916 adapter->tx_itr = e1000_update_itr(adapter,
1917 adapter->tx_itr,
1918 adapter->total_tx_packets,
1919 adapter->total_tx_bytes);
1920 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1921 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
1922 adapter->tx_itr = low_latency;
1923
1924 adapter->rx_itr = e1000_update_itr(adapter,
1925 adapter->rx_itr,
1926 adapter->total_rx_packets,
1927 adapter->total_rx_bytes);
1928 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1929 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
1930 adapter->rx_itr = low_latency;
1931
1932 current_itr = max(adapter->rx_itr, adapter->tx_itr);
1933
1934 switch (current_itr) {
1935 /* counts and packets in update_itr are dependent on these numbers */
1936 case lowest_latency:
1937 new_itr = 70000;
1938 break;
1939 case low_latency:
1940 new_itr = 20000; /* aka hwitr = ~200 */
1941 break;
1942 case bulk_latency:
1943 new_itr = 4000;
1944 break;
1945 default:
1946 break;
1947 }
1948
1949set_itr_now:
1950 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07001951 /*
1952 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07001954 * increasing
1955 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001956 new_itr = new_itr > adapter->itr ?
1957 min(adapter->itr + (new_itr >> 2), new_itr) :
1958 new_itr;
1959 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07001960 adapter->rx_ring->itr_val = new_itr;
1961 if (adapter->msix_entries)
1962 adapter->rx_ring->set_itr = 1;
1963 else
1964 ew32(ITR, 1000000000 / (new_itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001965 }
1966}
1967
1968/**
Bruce Allan4662e822008-08-26 18:37:06 -07001969 * e1000_alloc_queues - Allocate memory for all rings
1970 * @adapter: board private structure to initialize
1971 **/
1972static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1973{
1974 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1975 if (!adapter->tx_ring)
1976 goto err;
1977
1978 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1979 if (!adapter->rx_ring)
1980 goto err;
1981
1982 return 0;
1983err:
1984 e_err("Unable to allocate memory for queues\n");
1985 kfree(adapter->rx_ring);
1986 kfree(adapter->tx_ring);
1987 return -ENOMEM;
1988}
1989
1990/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001991 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07001992 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08001993 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07001994 **/
1995static int e1000_clean(struct napi_struct *napi, int budget)
1996{
1997 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001998 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001999 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002000 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002001
Wang Chen4cf16532008-11-12 23:38:14 -08002002 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002003
Bruce Allan4662e822008-08-26 18:37:06 -07002004 if (adapter->msix_entries &&
2005 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2006 goto clean_rx;
2007
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002008 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002009
Bruce Allan4662e822008-08-26 18:37:06 -07002010clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002011 adapter->clean_rx(adapter, &work_done, budget);
2012
Alexander Duyck12d04a32009-03-25 22:05:03 +00002013 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002014 work_done = budget;
2015
David S. Miller53e52c72008-01-07 21:06:12 -08002016 /* If budget not fully consumed, exit the polling mode */
2017 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002018 if (adapter->itr_setting & 3)
2019 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002020 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002021 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2022 if (adapter->msix_entries)
2023 ew32(IMS, adapter->rx_ring->ims_val);
2024 else
2025 e1000_irq_enable(adapter);
2026 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002027 }
2028
2029 return work_done;
2030}
2031
2032static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2033{
2034 struct e1000_adapter *adapter = netdev_priv(netdev);
2035 struct e1000_hw *hw = &adapter->hw;
2036 u32 vfta, index;
2037
2038 /* don't update vlan cookie if already programmed */
2039 if ((adapter->hw.mng_cookie.status &
2040 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2041 (vid == adapter->mng_vlan_id))
2042 return;
2043 /* add VID to filter table */
2044 index = (vid >> 5) & 0x7F;
2045 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2046 vfta |= (1 << (vid & 0x1F));
2047 e1000e_write_vfta(hw, index, vfta);
2048}
2049
2050static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2051{
2052 struct e1000_adapter *adapter = netdev_priv(netdev);
2053 struct e1000_hw *hw = &adapter->hw;
2054 u32 vfta, index;
2055
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002056 if (!test_bit(__E1000_DOWN, &adapter->state))
2057 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002058 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002059
2060 if (!test_bit(__E1000_DOWN, &adapter->state))
2061 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002062
2063 if ((adapter->hw.mng_cookie.status &
2064 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2065 (vid == adapter->mng_vlan_id)) {
2066 /* release control to f/w */
2067 e1000_release_hw_control(adapter);
2068 return;
2069 }
2070
2071 /* remove VID from filter table */
2072 index = (vid >> 5) & 0x7F;
2073 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2074 vfta &= ~(1 << (vid & 0x1F));
2075 e1000e_write_vfta(hw, index, vfta);
2076}
2077
2078static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2079{
2080 struct net_device *netdev = adapter->netdev;
2081 u16 vid = adapter->hw.mng_cookie.vlan_id;
2082 u16 old_vid = adapter->mng_vlan_id;
2083
2084 if (!adapter->vlgrp)
2085 return;
2086
2087 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2088 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2089 if (adapter->hw.mng_cookie.status &
2090 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2091 e1000_vlan_rx_add_vid(netdev, vid);
2092 adapter->mng_vlan_id = vid;
2093 }
2094
2095 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2096 (vid != old_vid) &&
2097 !vlan_group_get_device(adapter->vlgrp, old_vid))
2098 e1000_vlan_rx_kill_vid(netdev, old_vid);
2099 } else {
2100 adapter->mng_vlan_id = vid;
2101 }
2102}
2103
2104
2105static void e1000_vlan_rx_register(struct net_device *netdev,
2106 struct vlan_group *grp)
2107{
2108 struct e1000_adapter *adapter = netdev_priv(netdev);
2109 struct e1000_hw *hw = &adapter->hw;
2110 u32 ctrl, rctl;
2111
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002112 if (!test_bit(__E1000_DOWN, &adapter->state))
2113 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002114 adapter->vlgrp = grp;
2115
2116 if (grp) {
2117 /* enable VLAN tag insert/strip */
2118 ctrl = er32(CTRL);
2119 ctrl |= E1000_CTRL_VME;
2120 ew32(CTRL, ctrl);
2121
2122 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2123 /* enable VLAN receive filtering */
2124 rctl = er32(RCTL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002125 rctl &= ~E1000_RCTL_CFIEN;
2126 ew32(RCTL, rctl);
2127 e1000_update_mng_vlan(adapter);
2128 }
2129 } else {
2130 /* disable VLAN tag insert/strip */
2131 ctrl = er32(CTRL);
2132 ctrl &= ~E1000_CTRL_VME;
2133 ew32(CTRL, ctrl);
2134
2135 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002136 if (adapter->mng_vlan_id !=
2137 (u16)E1000_MNG_VLAN_NONE) {
2138 e1000_vlan_rx_kill_vid(netdev,
2139 adapter->mng_vlan_id);
2140 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2141 }
2142 }
2143 }
2144
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002145 if (!test_bit(__E1000_DOWN, &adapter->state))
2146 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002147}
2148
2149static void e1000_restore_vlan(struct e1000_adapter *adapter)
2150{
2151 u16 vid;
2152
2153 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2154
2155 if (!adapter->vlgrp)
2156 return;
2157
2158 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2159 if (!vlan_group_get_device(adapter->vlgrp, vid))
2160 continue;
2161 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2162 }
2163}
2164
2165static void e1000_init_manageability(struct e1000_adapter *adapter)
2166{
2167 struct e1000_hw *hw = &adapter->hw;
2168 u32 manc, manc2h;
2169
2170 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2171 return;
2172
2173 manc = er32(MANC);
2174
Bruce Allanad680762008-03-28 09:15:03 -07002175 /*
2176 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002177 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002178 * the packets will be handled on SMBUS
2179 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002180 manc |= E1000_MANC_EN_MNG2HOST;
2181 manc2h = er32(MANC2H);
2182#define E1000_MNG2HOST_PORT_623 (1 << 5)
2183#define E1000_MNG2HOST_PORT_664 (1 << 6)
2184 manc2h |= E1000_MNG2HOST_PORT_623;
2185 manc2h |= E1000_MNG2HOST_PORT_664;
2186 ew32(MANC2H, manc2h);
2187 ew32(MANC, manc);
2188}
2189
2190/**
2191 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2192 * @adapter: board private structure
2193 *
2194 * Configure the Tx unit of the MAC after a reset.
2195 **/
2196static void e1000_configure_tx(struct e1000_adapter *adapter)
2197{
2198 struct e1000_hw *hw = &adapter->hw;
2199 struct e1000_ring *tx_ring = adapter->tx_ring;
2200 u64 tdba;
2201 u32 tdlen, tctl, tipg, tarc;
2202 u32 ipgr1, ipgr2;
2203
2204 /* Setup the HW Tx Head and Tail descriptor pointers */
2205 tdba = tx_ring->dma;
2206 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002207 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002208 ew32(TDBAH, (tdba >> 32));
2209 ew32(TDLEN, tdlen);
2210 ew32(TDH, 0);
2211 ew32(TDT, 0);
2212 tx_ring->head = E1000_TDH;
2213 tx_ring->tail = E1000_TDT;
2214
2215 /* Set the default values for the Tx Inter Packet Gap timer */
2216 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2217 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2218 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2219
2220 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2221 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2222
2223 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2224 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2225 ew32(TIPG, tipg);
2226
2227 /* Set the Tx Interrupt Delay register */
2228 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002229 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002230 ew32(TADV, adapter->tx_abs_int_delay);
2231
2232 /* Program the Transmit Control Register */
2233 tctl = er32(TCTL);
2234 tctl &= ~E1000_TCTL_CT;
2235 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2236 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2237
2238 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002239 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002240 /*
2241 * set the speed mode bit, we'll clear it if we're not at
2242 * gigabit link later
2243 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244#define SPEED_MODE_BIT (1 << 21)
2245 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002246 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002247 }
2248
2249 /* errata: program both queues to unweighted RR */
2250 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002251 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002252 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002253 ew32(TARC(0), tarc);
2254 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002255 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002256 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002257 }
2258
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259 /* Setup Transmit Descriptor Settings for eop descriptor */
2260 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2261
2262 /* only set IDE if we are delaying interrupts using the timers */
2263 if (adapter->tx_int_delay)
2264 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2265
2266 /* enable Report Status bit */
2267 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2268
2269 ew32(TCTL, tctl);
2270
Simon Hormanedfea6e62009-06-08 14:28:36 +00002271 e1000e_config_collision_dist(hw);
2272
Auke Kokbc7f75f2007-09-17 12:30:59 -07002273 adapter->tx_queue_len = adapter->netdev->tx_queue_len;
2274}
2275
2276/**
2277 * e1000_setup_rctl - configure the receive control registers
2278 * @adapter: Board private structure
2279 **/
2280#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2281 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2282static void e1000_setup_rctl(struct e1000_adapter *adapter)
2283{
2284 struct e1000_hw *hw = &adapter->hw;
2285 u32 rctl, rfctl;
2286 u32 psrctl = 0;
2287 u32 pages = 0;
2288
2289 /* Program MC offset vector base */
2290 rctl = er32(RCTL);
2291 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2292 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2293 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2294 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2295
2296 /* Do not Store bad packets */
2297 rctl &= ~E1000_RCTL_SBP;
2298
2299 /* Enable Long Packet receive */
2300 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2301 rctl &= ~E1000_RCTL_LPE;
2302 else
2303 rctl |= E1000_RCTL_LPE;
2304
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002305 /* Some systems expect that the CRC is included in SMBUS traffic. The
2306 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2307 * host memory when this is enabled
2308 */
2309 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2310 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002311
Bruce Allana4f58f52009-06-02 11:29:18 +00002312 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2313 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2314 u16 phy_data;
2315
2316 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2317 phy_data &= 0xfff8;
2318 phy_data |= (1 << 2);
2319 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2320
2321 e1e_rphy(hw, 22, &phy_data);
2322 phy_data &= 0x0fff;
2323 phy_data |= (1 << 14);
2324 e1e_wphy(hw, 0x10, 0x2823);
2325 e1e_wphy(hw, 0x11, 0x0003);
2326 e1e_wphy(hw, 22, phy_data);
2327 }
2328
Auke Kokbc7f75f2007-09-17 12:30:59 -07002329 /* Setup buffer sizes */
2330 rctl &= ~E1000_RCTL_SZ_4096;
2331 rctl |= E1000_RCTL_BSEX;
2332 switch (adapter->rx_buffer_len) {
2333 case 256:
2334 rctl |= E1000_RCTL_SZ_256;
2335 rctl &= ~E1000_RCTL_BSEX;
2336 break;
2337 case 512:
2338 rctl |= E1000_RCTL_SZ_512;
2339 rctl &= ~E1000_RCTL_BSEX;
2340 break;
2341 case 1024:
2342 rctl |= E1000_RCTL_SZ_1024;
2343 rctl &= ~E1000_RCTL_BSEX;
2344 break;
2345 case 2048:
2346 default:
2347 rctl |= E1000_RCTL_SZ_2048;
2348 rctl &= ~E1000_RCTL_BSEX;
2349 break;
2350 case 4096:
2351 rctl |= E1000_RCTL_SZ_4096;
2352 break;
2353 case 8192:
2354 rctl |= E1000_RCTL_SZ_8192;
2355 break;
2356 case 16384:
2357 rctl |= E1000_RCTL_SZ_16384;
2358 break;
2359 }
2360
2361 /*
2362 * 82571 and greater support packet-split where the protocol
2363 * header is placed in skb->data and the packet data is
2364 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2365 * In the case of a non-split, skb->data is linearly filled,
2366 * followed by the page buffers. Therefore, skb->data is
2367 * sized to hold the largest protocol header.
2368 *
2369 * allocations using alloc_page take too long for regular MTU
2370 * so only enable packet split for jumbo frames
2371 *
2372 * Using pages when the page size is greater than 16k wastes
2373 * a lot of memory, since we allocate 3 pages at all times
2374 * per packet.
2375 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002376 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002377 if (!(adapter->flags & FLAG_IS_ICH) && (pages <= 3) &&
2378 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002379 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002380 else
2381 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382
2383 if (adapter->rx_ps_pages) {
2384 /* Configure extra packet-split registers */
2385 rfctl = er32(RFCTL);
2386 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002387 /*
2388 * disable packet split support for IPv6 extension headers,
2389 * because some malformed IPv6 headers can hang the Rx
2390 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002391 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2392 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2393
2394 ew32(RFCTL, rfctl);
2395
Auke Kok140a7482007-10-25 13:57:58 -07002396 /* Enable Packet split descriptors */
2397 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398
2399 psrctl |= adapter->rx_ps_bsize0 >>
2400 E1000_PSRCTL_BSIZE0_SHIFT;
2401
2402 switch (adapter->rx_ps_pages) {
2403 case 3:
2404 psrctl |= PAGE_SIZE <<
2405 E1000_PSRCTL_BSIZE3_SHIFT;
2406 case 2:
2407 psrctl |= PAGE_SIZE <<
2408 E1000_PSRCTL_BSIZE2_SHIFT;
2409 case 1:
2410 psrctl |= PAGE_SIZE >>
2411 E1000_PSRCTL_BSIZE1_SHIFT;
2412 break;
2413 }
2414
2415 ew32(PSRCTL, psrctl);
2416 }
2417
2418 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002419 /* just started the receive unit, no need to restart */
2420 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002421}
2422
2423/**
2424 * e1000_configure_rx - Configure Receive Unit after Reset
2425 * @adapter: board private structure
2426 *
2427 * Configure the Rx unit of the MAC after a reset.
2428 **/
2429static void e1000_configure_rx(struct e1000_adapter *adapter)
2430{
2431 struct e1000_hw *hw = &adapter->hw;
2432 struct e1000_ring *rx_ring = adapter->rx_ring;
2433 u64 rdba;
2434 u32 rdlen, rctl, rxcsum, ctrl_ext;
2435
2436 if (adapter->rx_ps_pages) {
2437 /* this is a 32 byte descriptor */
2438 rdlen = rx_ring->count *
2439 sizeof(union e1000_rx_desc_packet_split);
2440 adapter->clean_rx = e1000_clean_rx_irq_ps;
2441 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002442 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2443 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2444 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2445 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002447 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002448 adapter->clean_rx = e1000_clean_rx_irq;
2449 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2450 }
2451
2452 /* disable receives while setting up the descriptors */
2453 rctl = er32(RCTL);
2454 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2455 e1e_flush();
2456 msleep(10);
2457
2458 /* set the Receive Delay Timer Register */
2459 ew32(RDTR, adapter->rx_int_delay);
2460
2461 /* irq moderation */
2462 ew32(RADV, adapter->rx_abs_int_delay);
2463 if (adapter->itr_setting != 0)
Bruce Allanad680762008-03-28 09:15:03 -07002464 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002465
2466 ctrl_ext = er32(CTRL_EXT);
2467 /* Reset delay timers after every interrupt */
2468 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
2469 /* Auto-Mask interrupts upon ICR access */
2470 ctrl_ext |= E1000_CTRL_EXT_IAME;
2471 ew32(IAM, 0xffffffff);
2472 ew32(CTRL_EXT, ctrl_ext);
2473 e1e_flush();
2474
Bruce Allanad680762008-03-28 09:15:03 -07002475 /*
2476 * Setup the HW Rx Head and Tail Descriptor Pointers and
2477 * the Base and Length of the Rx Descriptor Ring
2478 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002479 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002480 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002481 ew32(RDBAH, (rdba >> 32));
2482 ew32(RDLEN, rdlen);
2483 ew32(RDH, 0);
2484 ew32(RDT, 0);
2485 rx_ring->head = E1000_RDH;
2486 rx_ring->tail = E1000_RDT;
2487
2488 /* Enable Receive Checksum Offload for TCP and UDP */
2489 rxcsum = er32(RXCSUM);
2490 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2491 rxcsum |= E1000_RXCSUM_TUOFL;
2492
Bruce Allanad680762008-03-28 09:15:03 -07002493 /*
2494 * IPv4 payload checksum for UDP fragments must be
2495 * used in conjunction with packet-split.
2496 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002497 if (adapter->rx_ps_pages)
2498 rxcsum |= E1000_RXCSUM_IPPCSE;
2499 } else {
2500 rxcsum &= ~E1000_RXCSUM_TUOFL;
2501 /* no need to clear IPPCSE as it defaults to 0 */
2502 }
2503 ew32(RXCSUM, rxcsum);
2504
Bruce Allanad680762008-03-28 09:15:03 -07002505 /*
2506 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002507 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002508 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2509 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 if ((adapter->flags & FLAG_HAS_ERT) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002511 (adapter->netdev->mtu > ETH_DATA_LEN)) {
2512 u32 rxdctl = er32(RXDCTL(0));
2513 ew32(RXDCTL(0), rxdctl | 0x3);
2514 ew32(ERT, E1000_ERT_2048 | (1 << 13));
2515 /*
2516 * With jumbo frames and early-receive enabled, excessive
2517 * C4->C2 latencies result in dropped transactions.
2518 */
2519 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2520 e1000e_driver_name, 55);
2521 } else {
2522 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2523 e1000e_driver_name,
2524 PM_QOS_DEFAULT_VALUE);
2525 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526
2527 /* Enable Receives */
2528 ew32(RCTL, rctl);
2529}
2530
2531/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002532 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07002533 * @hw: pointer to the HW structure
2534 * @mc_addr_list: array of multicast addresses to program
2535 * @mc_addr_count: number of multicast addresses to program
2536 * @rar_used_count: the first RAR register free to program
2537 * @rar_count: total number of supported Receive Address Registers
2538 *
2539 * Updates the Receive Address Registers and Multicast Table Array.
2540 * The caller must have a packed mc_addr_list of multicast addresses.
2541 * The parameter rar_count will usually be hw->mac.rar_entry_count
2542 * unless there are workarounds that change this. Currently no func pointer
2543 * exists and all implementations are handled in the generic version of this
2544 * function.
2545 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002546static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
2547 u32 mc_addr_count, u32 rar_used_count,
2548 u32 rar_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002549{
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002550 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002551 rar_used_count, rar_count);
2552}
2553
2554/**
2555 * e1000_set_multi - Multicast and Promiscuous mode set
2556 * @netdev: network interface device structure
2557 *
2558 * The set_multi entry point is called whenever the multicast address
2559 * list or the network interface flags are updated. This routine is
2560 * responsible for configuring the hardware for proper multicast,
2561 * promiscuous mode, and all-multi behavior.
2562 **/
2563static void e1000_set_multi(struct net_device *netdev)
2564{
2565 struct e1000_adapter *adapter = netdev_priv(netdev);
2566 struct e1000_hw *hw = &adapter->hw;
2567 struct e1000_mac_info *mac = &hw->mac;
2568 struct dev_mc_list *mc_ptr;
2569 u8 *mta_list;
2570 u32 rctl;
2571 int i;
2572
2573 /* Check for Promiscuous and All Multicast modes */
2574
2575 rctl = er32(RCTL);
2576
2577 if (netdev->flags & IFF_PROMISC) {
2578 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002579 rctl &= ~E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002580 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002581 if (netdev->flags & IFF_ALLMULTI) {
2582 rctl |= E1000_RCTL_MPE;
2583 rctl &= ~E1000_RCTL_UPE;
2584 } else {
2585 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2586 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002587 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002588 rctl |= E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002589 }
2590
2591 ew32(RCTL, rctl);
2592
2593 if (netdev->mc_count) {
2594 mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);
2595 if (!mta_list)
2596 return;
2597
2598 /* prepare a packed array of only addresses. */
2599 mc_ptr = netdev->mc_list;
2600
2601 for (i = 0; i < netdev->mc_count; i++) {
2602 if (!mc_ptr)
2603 break;
2604 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
2605 ETH_ALEN);
2606 mc_ptr = mc_ptr->next;
2607 }
2608
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002609 e1000_update_mc_addr_list(hw, mta_list, i, 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002610 mac->rar_entry_count);
2611 kfree(mta_list);
2612 } else {
2613 /*
2614 * if we're called from probe, we might not have
2615 * anything to do here, so clear out the list
2616 */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002617 e1000_update_mc_addr_list(hw, NULL, 0, 1, mac->rar_entry_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002618 }
2619}
2620
2621/**
Bruce Allanad680762008-03-28 09:15:03 -07002622 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07002623 * @adapter: private board structure
2624 **/
2625static void e1000_configure(struct e1000_adapter *adapter)
2626{
2627 e1000_set_multi(adapter->netdev);
2628
2629 e1000_restore_vlan(adapter);
2630 e1000_init_manageability(adapter);
2631
2632 e1000_configure_tx(adapter);
2633 e1000_setup_rctl(adapter);
2634 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07002635 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002636}
2637
2638/**
2639 * e1000e_power_up_phy - restore link in case the phy was powered down
2640 * @adapter: address of board private structure
2641 *
2642 * The phy may be powered down to save power and turn off link when the
2643 * driver is unloaded and wake on lan is not enabled (among others)
2644 * *** this routine MUST be followed by a call to e1000e_reset ***
2645 **/
2646void e1000e_power_up_phy(struct e1000_adapter *adapter)
2647{
2648 u16 mii_reg = 0;
2649
2650 /* Just clear the power down bit to wake the phy back up */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002651 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Bruce Allanad680762008-03-28 09:15:03 -07002652 /*
2653 * According to the manual, the phy will retain its
2654 * settings across a power-down/up cycle
2655 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002656 e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);
2657 mii_reg &= ~MII_CR_POWER_DOWN;
2658 e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);
2659 }
2660
2661 adapter->hw.mac.ops.setup_link(&adapter->hw);
2662}
2663
2664/**
2665 * e1000_power_down_phy - Power down the PHY
2666 *
2667 * Power down the PHY so no link is implied when interface is down
2668 * The PHY cannot be powered down is management or WoL is active
2669 */
2670static void e1000_power_down_phy(struct e1000_adapter *adapter)
2671{
2672 struct e1000_hw *hw = &adapter->hw;
2673 u16 mii_reg;
2674
2675 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08002676 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002677 return;
2678
2679 /* non-copper PHY? */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002680 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002681 return;
2682
2683 /* reset is blocked because of a SoL/IDER session */
Bruce Allanad680762008-03-28 09:15:03 -07002684 if (e1000e_check_mng_mode(hw) || e1000_check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002685 return;
2686
Auke Kok489815c2008-02-21 15:11:07 -08002687 /* manageability (AMT) is enabled */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002688 if (er32(MANC) & E1000_MANC_SMBUS_EN)
2689 return;
2690
2691 /* power down the PHY */
2692 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2693 mii_reg |= MII_CR_POWER_DOWN;
2694 e1e_wphy(hw, PHY_CONTROL, mii_reg);
2695 mdelay(1);
2696}
2697
2698/**
2699 * e1000e_reset - bring the hardware into a known good state
2700 *
2701 * This function boots the hardware and enables some settings that
2702 * require a configuration cycle of the hardware - those cannot be
2703 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07002704 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705 */
2706void e1000e_reset(struct e1000_adapter *adapter)
2707{
2708 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002709 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002710 struct e1000_hw *hw = &adapter->hw;
2711 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002712 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002713 u16 hwm;
2714
Bruce Allanad680762008-03-28 09:15:03 -07002715 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002716 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07002717
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002718 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07002719 /*
2720 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07002721 * large enough to accommodate two full transmit packets,
2722 * rounded up to the next 1KB and expressed in KB. Likewise,
2723 * the Rx FIFO should be large enough to accommodate at least
2724 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07002725 * expressed in KB.
2726 */
Auke Kokdf762462007-10-25 13:57:53 -07002727 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002728 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07002729 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002730 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07002731 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07002732 /*
2733 * the Tx fifo also stores 16 bytes of information about the tx
2734 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002735 */
2736 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07002737 sizeof(struct e1000_tx_desc) -
2738 ETH_FCS_LEN) * 2;
2739 min_tx_space = ALIGN(min_tx_space, 1024);
2740 min_tx_space >>= 10;
2741 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002742 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002743 min_rx_space = ALIGN(min_rx_space, 1024);
2744 min_rx_space >>= 10;
2745
Bruce Allanad680762008-03-28 09:15:03 -07002746 /*
2747 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002748 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07002749 * allocation, take space away from current Rx allocation
2750 */
Auke Kokdf762462007-10-25 13:57:53 -07002751 if ((tx_space < min_tx_space) &&
2752 ((min_tx_space - tx_space) < pba)) {
2753 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002754
Bruce Allanad680762008-03-28 09:15:03 -07002755 /*
2756 * if short on Rx space, Rx wins and must trump tx
2757 * adjustment or use Early Receive if available
2758 */
Auke Kokdf762462007-10-25 13:57:53 -07002759 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07002760 (!(adapter->flags & FLAG_HAS_ERT)))
2761 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07002762 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002763 }
Auke Kokdf762462007-10-25 13:57:53 -07002764
2765 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002766 }
2767
Auke Kokbc7f75f2007-09-17 12:30:59 -07002768
Bruce Allanad680762008-03-28 09:15:03 -07002769 /*
2770 * flow control settings
2771 *
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002772 * The high water mark must be low enough to fit two full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07002773 * (or the size used for early receive) above it in the Rx FIFO.
2774 * Set it to the lower of:
2775 * - 90% of the Rx FIFO size, and
2776 * - the full Rx FIFO size minus the early receive size (for parts
2777 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002778 * - the full Rx FIFO size minus two full frames
Bruce Allanad680762008-03-28 09:15:03 -07002779 */
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002780 if ((adapter->flags & FLAG_HAS_ERT) &&
2781 (adapter->netdev->mtu > ETH_DATA_LEN))
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002782 hwm = min(((pba << 10) * 9 / 10),
2783 ((pba << 10) - (E1000_ERT_2048 << 3)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002784 else
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002785 hwm = min(((pba << 10) * 9 / 10),
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002786 ((pba << 10) - (2 * adapter->max_frame_size)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002788 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
2789 fc->low_water = (fc->high_water - (2 * adapter->max_frame_size));
2790 fc->low_water &= E1000_FCRTL_RTL; /* 8-byte granularity */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002791
2792 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002793 fc->pause_time = 0xFFFF;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002794 else
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002795 fc->pause_time = E1000_FC_PAUSE_TIME;
2796 fc->send_xon = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08002797 fc->current_mode = fc->requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002798
2799 /* Allow time for pending master requests to run */
2800 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002801
2802 /*
2803 * For parts with AMT enabled, let the firmware know
2804 * that the network interface is in control
2805 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07002806 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002807 e1000_get_hw_control(adapter);
2808
Auke Kokbc7f75f2007-09-17 12:30:59 -07002809 ew32(WUC, 0);
Bruce Allana4f58f52009-06-02 11:29:18 +00002810 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)
2811 e1e_wphy(&adapter->hw, BM_WUC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002812
2813 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002814 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815
2816 e1000_update_mng_vlan(adapter);
2817
2818 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2819 ew32(VET, ETH_P_8021Q);
2820
2821 e1000e_reset_adaptive(hw);
2822 e1000_get_phy_info(hw);
2823
Bruce Allan918d7192009-06-02 11:28:20 +00002824 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
2825 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002826 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07002827 /*
2828 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07002830 * different we would do if it failed
2831 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
2833 phy_data &= ~IGP02E1000_PM_SPD;
2834 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
2835 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002836}
2837
2838int e1000e_up(struct e1000_adapter *adapter)
2839{
2840 struct e1000_hw *hw = &adapter->hw;
2841
2842 /* hardware has been reset, we need to reload some things */
2843 e1000_configure(adapter);
2844
2845 clear_bit(__E1000_DOWN, &adapter->state);
2846
2847 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002848 if (adapter->msix_entries)
2849 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002850 e1000_irq_enable(adapter);
2851
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00002852 netif_wake_queue(adapter->netdev);
2853
Auke Kokbc7f75f2007-09-17 12:30:59 -07002854 /* fire a link change interrupt to start the watchdog */
2855 ew32(ICS, E1000_ICS_LSC);
2856 return 0;
2857}
2858
2859void e1000e_down(struct e1000_adapter *adapter)
2860{
2861 struct net_device *netdev = adapter->netdev;
2862 struct e1000_hw *hw = &adapter->hw;
2863 u32 tctl, rctl;
2864
Bruce Allanad680762008-03-28 09:15:03 -07002865 /*
2866 * signal that we're down so the interrupt handler does not
2867 * reschedule our watchdog timer
2868 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002869 set_bit(__E1000_DOWN, &adapter->state);
2870
2871 /* disable receives in the hardware */
2872 rctl = er32(RCTL);
2873 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2874 /* flush and sleep below */
2875
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00002876 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002877
2878 /* disable transmits in the hardware */
2879 tctl = er32(TCTL);
2880 tctl &= ~E1000_TCTL_EN;
2881 ew32(TCTL, tctl);
2882 /* flush both disables and wait for them to finish */
2883 e1e_flush();
2884 msleep(10);
2885
2886 napi_disable(&adapter->napi);
2887 e1000_irq_disable(adapter);
2888
2889 del_timer_sync(&adapter->watchdog_timer);
2890 del_timer_sync(&adapter->phy_info_timer);
2891
2892 netdev->tx_queue_len = adapter->tx_queue_len;
2893 netif_carrier_off(netdev);
2894 adapter->link_speed = 0;
2895 adapter->link_duplex = 0;
2896
Jeff Kirsher52cc3082008-06-24 17:01:29 -07002897 if (!pci_channel_offline(adapter->pdev))
2898 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002899 e1000_clean_tx_ring(adapter);
2900 e1000_clean_rx_ring(adapter);
2901
2902 /*
2903 * TODO: for power management, we could drop the link and
2904 * pci_disable_device here.
2905 */
2906}
2907
2908void e1000e_reinit_locked(struct e1000_adapter *adapter)
2909{
2910 might_sleep();
2911 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
2912 msleep(1);
2913 e1000e_down(adapter);
2914 e1000e_up(adapter);
2915 clear_bit(__E1000_RESETTING, &adapter->state);
2916}
2917
2918/**
2919 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2920 * @adapter: board private structure to initialize
2921 *
2922 * e1000_sw_init initializes the Adapter private data structure.
2923 * Fields are initialized based on PCI device information and
2924 * OS network device settings (MTU size).
2925 **/
2926static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
2927{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002928 struct net_device *netdev = adapter->netdev;
2929
2930 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
2931 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002932 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2933 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002934
Bruce Allan4662e822008-08-26 18:37:06 -07002935 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002936
Bruce Allan4662e822008-08-26 18:37:06 -07002937 if (e1000_alloc_queues(adapter))
2938 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002939
Auke Kokbc7f75f2007-09-17 12:30:59 -07002940 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002941 e1000_irq_disable(adapter);
2942
Auke Kokbc7f75f2007-09-17 12:30:59 -07002943 set_bit(__E1000_DOWN, &adapter->state);
2944 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002945}
2946
2947/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07002948 * e1000_intr_msi_test - Interrupt Handler
2949 * @irq: interrupt number
2950 * @data: pointer to a network interface device structure
2951 **/
2952static irqreturn_t e1000_intr_msi_test(int irq, void *data)
2953{
2954 struct net_device *netdev = data;
2955 struct e1000_adapter *adapter = netdev_priv(netdev);
2956 struct e1000_hw *hw = &adapter->hw;
2957 u32 icr = er32(ICR);
2958
2959 e_dbg("%s: icr is %08X\n", netdev->name, icr);
2960 if (icr & E1000_ICR_RXSEQ) {
2961 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
2962 wmb();
2963 }
2964
2965 return IRQ_HANDLED;
2966}
2967
2968/**
2969 * e1000_test_msi_interrupt - Returns 0 for successful test
2970 * @adapter: board private struct
2971 *
2972 * code flow taken from tg3.c
2973 **/
2974static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
2975{
2976 struct net_device *netdev = adapter->netdev;
2977 struct e1000_hw *hw = &adapter->hw;
2978 int err;
2979
2980 /* poll_enable hasn't been called yet, so don't need disable */
2981 /* clear any pending events */
2982 er32(ICR);
2983
2984 /* free the real vector and request a test handler */
2985 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07002986 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07002987
2988 /* Assume that the test fails, if it succeeds then the test
2989 * MSI irq handler will unset this flag */
2990 adapter->flags |= FLAG_MSI_TEST_FAILED;
2991
2992 err = pci_enable_msi(adapter->pdev);
2993 if (err)
2994 goto msi_test_failed;
2995
2996 err = request_irq(adapter->pdev->irq, &e1000_intr_msi_test, 0,
2997 netdev->name, netdev);
2998 if (err) {
2999 pci_disable_msi(adapter->pdev);
3000 goto msi_test_failed;
3001 }
3002
3003 wmb();
3004
3005 e1000_irq_enable(adapter);
3006
3007 /* fire an unusual interrupt on the test handler */
3008 ew32(ICS, E1000_ICS_RXSEQ);
3009 e1e_flush();
3010 msleep(50);
3011
3012 e1000_irq_disable(adapter);
3013
3014 rmb();
3015
3016 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003017 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Bruce Allanf8d59f72008-08-08 18:36:11 -07003018 err = -EIO;
3019 e_info("MSI interrupt test failed!\n");
3020 }
3021
3022 free_irq(adapter->pdev->irq, netdev);
3023 pci_disable_msi(adapter->pdev);
3024
3025 if (err == -EIO)
3026 goto msi_test_failed;
3027
3028 /* okay so the test worked, restore settings */
3029 e_dbg("%s: MSI interrupt test succeeded!\n", netdev->name);
3030msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003031 e1000e_set_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003032 e1000_request_irq(adapter);
3033 return err;
3034}
3035
3036/**
3037 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3038 * @adapter: board private struct
3039 *
3040 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3041 **/
3042static int e1000_test_msi(struct e1000_adapter *adapter)
3043{
3044 int err;
3045 u16 pci_cmd;
3046
3047 if (!(adapter->flags & FLAG_MSI_ENABLED))
3048 return 0;
3049
3050 /* disable SERR in case the MSI write causes a master abort */
3051 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3052 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3053 pci_cmd & ~PCI_COMMAND_SERR);
3054
3055 err = e1000_test_msi_interrupt(adapter);
3056
3057 /* restore previous setting of command word */
3058 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3059
3060 /* success ! */
3061 if (!err)
3062 return 0;
3063
3064 /* EIO means MSI test failed */
3065 if (err != -EIO)
3066 return err;
3067
3068 /* back to INTx mode */
3069 e_warn("MSI interrupt test failed, using legacy interrupt.\n");
3070
3071 e1000_free_irq(adapter);
3072
3073 err = e1000_request_irq(adapter);
3074
3075 return err;
3076}
3077
3078/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003079 * e1000_open - Called when a network interface is made active
3080 * @netdev: network interface device structure
3081 *
3082 * Returns 0 on success, negative value on failure
3083 *
3084 * The open entry point is called when a network interface is made
3085 * active by the system (IFF_UP). At this point all resources needed
3086 * for transmit and receive operations are allocated, the interrupt
3087 * handler is registered with the OS, the watchdog timer is started,
3088 * and the stack is notified that the interface is ready.
3089 **/
3090static int e1000_open(struct net_device *netdev)
3091{
3092 struct e1000_adapter *adapter = netdev_priv(netdev);
3093 struct e1000_hw *hw = &adapter->hw;
3094 int err;
3095
3096 /* disallow open during test */
3097 if (test_bit(__E1000_TESTING, &adapter->state))
3098 return -EBUSY;
3099
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003100 netif_carrier_off(netdev);
3101
Auke Kokbc7f75f2007-09-17 12:30:59 -07003102 /* allocate transmit descriptors */
3103 err = e1000e_setup_tx_resources(adapter);
3104 if (err)
3105 goto err_setup_tx;
3106
3107 /* allocate receive descriptors */
3108 err = e1000e_setup_rx_resources(adapter);
3109 if (err)
3110 goto err_setup_rx;
3111
3112 e1000e_power_up_phy(adapter);
3113
3114 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3115 if ((adapter->hw.mng_cookie.status &
3116 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3117 e1000_update_mng_vlan(adapter);
3118
Bruce Allanad680762008-03-28 09:15:03 -07003119 /*
3120 * If AMT is enabled, let the firmware know that the network
3121 * interface is now open
3122 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003123 if (adapter->flags & FLAG_HAS_AMT)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003124 e1000_get_hw_control(adapter);
3125
Bruce Allanad680762008-03-28 09:15:03 -07003126 /*
3127 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3129 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003130 * clean_rx handler before we do so.
3131 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003132 e1000_configure(adapter);
3133
3134 err = e1000_request_irq(adapter);
3135 if (err)
3136 goto err_req_irq;
3137
Bruce Allanf8d59f72008-08-08 18:36:11 -07003138 /*
3139 * Work around PCIe errata with MSI interrupts causing some chipsets to
3140 * ignore e1000e MSI messages, which means we need to test our MSI
3141 * interrupt now
3142 */
Bruce Allan4662e822008-08-26 18:37:06 -07003143 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003144 err = e1000_test_msi(adapter);
3145 if (err) {
3146 e_err("Interrupt allocation failed\n");
3147 goto err_req_irq;
3148 }
3149 }
3150
Auke Kokbc7f75f2007-09-17 12:30:59 -07003151 /* From here on the code is the same as e1000e_up() */
3152 clear_bit(__E1000_DOWN, &adapter->state);
3153
3154 napi_enable(&adapter->napi);
3155
3156 e1000_irq_enable(adapter);
3157
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003158 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003159
Auke Kokbc7f75f2007-09-17 12:30:59 -07003160 /* fire a link status change interrupt to start the watchdog */
3161 ew32(ICS, E1000_ICS_LSC);
3162
3163 return 0;
3164
3165err_req_irq:
3166 e1000_release_hw_control(adapter);
3167 e1000_power_down_phy(adapter);
3168 e1000e_free_rx_resources(adapter);
3169err_setup_rx:
3170 e1000e_free_tx_resources(adapter);
3171err_setup_tx:
3172 e1000e_reset(adapter);
3173
3174 return err;
3175}
3176
3177/**
3178 * e1000_close - Disables a network interface
3179 * @netdev: network interface device structure
3180 *
3181 * Returns 0, this is not allowed to fail
3182 *
3183 * The close entry point is called when an interface is de-activated
3184 * by the OS. The hardware is still under the drivers control, but
3185 * needs to be disabled. A global MAC reset is issued to stop the
3186 * hardware, and all transmit and receive resources are freed.
3187 **/
3188static int e1000_close(struct net_device *netdev)
3189{
3190 struct e1000_adapter *adapter = netdev_priv(netdev);
3191
3192 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3193 e1000e_down(adapter);
3194 e1000_power_down_phy(adapter);
3195 e1000_free_irq(adapter);
3196
3197 e1000e_free_tx_resources(adapter);
3198 e1000e_free_rx_resources(adapter);
3199
Bruce Allanad680762008-03-28 09:15:03 -07003200 /*
3201 * kill manageability vlan ID if supported, but not if a vlan with
3202 * the same ID is registered on the host OS (let 8021q kill it)
3203 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003204 if ((adapter->hw.mng_cookie.status &
3205 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3206 !(adapter->vlgrp &&
3207 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3208 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3209
Bruce Allanad680762008-03-28 09:15:03 -07003210 /*
3211 * If AMT is enabled, let the firmware know that the network
3212 * interface is now closed
3213 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003214 if (adapter->flags & FLAG_HAS_AMT)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003215 e1000_release_hw_control(adapter);
3216
3217 return 0;
3218}
3219/**
3220 * e1000_set_mac - Change the Ethernet Address of the NIC
3221 * @netdev: network interface device structure
3222 * @p: pointer to an address structure
3223 *
3224 * Returns 0 on success, negative on failure
3225 **/
3226static int e1000_set_mac(struct net_device *netdev, void *p)
3227{
3228 struct e1000_adapter *adapter = netdev_priv(netdev);
3229 struct sockaddr *addr = p;
3230
3231 if (!is_valid_ether_addr(addr->sa_data))
3232 return -EADDRNOTAVAIL;
3233
3234 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3235 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3236
3237 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3238
3239 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3240 /* activate the work around */
3241 e1000e_set_laa_state_82571(&adapter->hw, 1);
3242
Bruce Allanad680762008-03-28 09:15:03 -07003243 /*
3244 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003245 * between the time RAR[0] gets clobbered and the time it
3246 * gets fixed (in e1000_watchdog), the actual LAA is in one
3247 * of the RARs and no incoming packets directed to this port
3248 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003249 * RAR[14]
3250 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003251 e1000e_rar_set(&adapter->hw,
3252 adapter->hw.mac.addr,
3253 adapter->hw.mac.rar_entry_count - 1);
3254 }
3255
3256 return 0;
3257}
3258
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003259/**
3260 * e1000e_update_phy_task - work thread to update phy
3261 * @work: pointer to our work struct
3262 *
3263 * this worker thread exists because we must acquire a
3264 * semaphore to read the phy, which we could msleep while
3265 * waiting for it, and we can't msleep in a timer.
3266 **/
3267static void e1000e_update_phy_task(struct work_struct *work)
3268{
3269 struct e1000_adapter *adapter = container_of(work,
3270 struct e1000_adapter, update_phy_task);
3271 e1000_get_phy_info(&adapter->hw);
3272}
3273
Bruce Allanad680762008-03-28 09:15:03 -07003274/*
3275 * Need to wait a few seconds after link up to get diagnostic information from
3276 * the phy
3277 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003278static void e1000_update_phy_info(unsigned long data)
3279{
3280 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003281 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003282}
3283
3284/**
3285 * e1000e_update_stats - Update the board statistics counters
3286 * @adapter: board private structure
3287 **/
3288void e1000e_update_stats(struct e1000_adapter *adapter)
3289{
3290 struct e1000_hw *hw = &adapter->hw;
3291 struct pci_dev *pdev = adapter->pdev;
Bruce Allana4f58f52009-06-02 11:29:18 +00003292 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003293
3294 /*
3295 * Prevent stats update while adapter is being reset, or if the pci
3296 * connection is down.
3297 */
3298 if (adapter->link_speed == 0)
3299 return;
3300 if (pci_channel_offline(pdev))
3301 return;
3302
Auke Kokbc7f75f2007-09-17 12:30:59 -07003303 adapter->stats.crcerrs += er32(CRCERRS);
3304 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003305 adapter->stats.gorc += er32(GORCL);
3306 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003307 adapter->stats.bprc += er32(BPRC);
3308 adapter->stats.mprc += er32(MPRC);
3309 adapter->stats.roc += er32(ROC);
3310
Auke Kokbc7f75f2007-09-17 12:30:59 -07003311 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003312 if ((hw->phy.type == e1000_phy_82578) ||
3313 (hw->phy.type == e1000_phy_82577)) {
3314 e1e_rphy(hw, HV_SCC_UPPER, &phy_data);
3315 e1e_rphy(hw, HV_SCC_LOWER, &phy_data);
3316 adapter->stats.scc += phy_data;
3317
3318 e1e_rphy(hw, HV_ECOL_UPPER, &phy_data);
3319 e1e_rphy(hw, HV_ECOL_LOWER, &phy_data);
3320 adapter->stats.ecol += phy_data;
3321
3322 e1e_rphy(hw, HV_MCC_UPPER, &phy_data);
3323 e1e_rphy(hw, HV_MCC_LOWER, &phy_data);
3324 adapter->stats.mcc += phy_data;
3325
3326 e1e_rphy(hw, HV_LATECOL_UPPER, &phy_data);
3327 e1e_rphy(hw, HV_LATECOL_LOWER, &phy_data);
3328 adapter->stats.latecol += phy_data;
3329
3330 e1e_rphy(hw, HV_DC_UPPER, &phy_data);
3331 e1e_rphy(hw, HV_DC_LOWER, &phy_data);
3332 adapter->stats.dc += phy_data;
3333 } else {
3334 adapter->stats.scc += er32(SCC);
3335 adapter->stats.ecol += er32(ECOL);
3336 adapter->stats.mcc += er32(MCC);
3337 adapter->stats.latecol += er32(LATECOL);
3338 adapter->stats.dc += er32(DC);
3339 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003340 adapter->stats.xonrxc += er32(XONRXC);
3341 adapter->stats.xontxc += er32(XONTXC);
3342 adapter->stats.xoffrxc += er32(XOFFRXC);
3343 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003344 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003345 adapter->stats.gotc += er32(GOTCL);
3346 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003347 adapter->stats.rnbc += er32(RNBC);
3348 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003349
3350 adapter->stats.mptc += er32(MPTC);
3351 adapter->stats.bptc += er32(BPTC);
3352
3353 /* used for adaptive IFS */
3354
3355 hw->mac.tx_packet_delta = er32(TPT);
3356 adapter->stats.tpt += hw->mac.tx_packet_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003357 if ((hw->phy.type == e1000_phy_82578) ||
3358 (hw->phy.type == e1000_phy_82577)) {
3359 e1e_rphy(hw, HV_COLC_UPPER, &phy_data);
3360 e1e_rphy(hw, HV_COLC_LOWER, &phy_data);
3361 hw->mac.collision_delta = phy_data;
3362 } else {
3363 hw->mac.collision_delta = er32(COLC);
3364 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003365 adapter->stats.colc += hw->mac.collision_delta;
3366
3367 adapter->stats.algnerrc += er32(ALGNERRC);
3368 adapter->stats.rxerrc += er32(RXERRC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003369 if ((hw->phy.type == e1000_phy_82578) ||
3370 (hw->phy.type == e1000_phy_82577)) {
3371 e1e_rphy(hw, HV_TNCRS_UPPER, &phy_data);
3372 e1e_rphy(hw, HV_TNCRS_LOWER, &phy_data);
3373 adapter->stats.tncrs += phy_data;
3374 } else {
3375 if ((hw->mac.type != e1000_82574) &&
3376 (hw->mac.type != e1000_82583))
3377 adapter->stats.tncrs += er32(TNCRS);
3378 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003379 adapter->stats.cexterr += er32(CEXTERR);
3380 adapter->stats.tsctc += er32(TSCTC);
3381 adapter->stats.tsctfc += er32(TSCTFC);
3382
Auke Kokbc7f75f2007-09-17 12:30:59 -07003383 /* Fill out the OS statistics structure */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003384 adapter->net_stats.multicast = adapter->stats.mprc;
3385 adapter->net_stats.collisions = adapter->stats.colc;
3386
3387 /* Rx Errors */
3388
Bruce Allanad680762008-03-28 09:15:03 -07003389 /*
3390 * RLEC on some newer hardware can be incorrect so build
3391 * our own version based on RUC and ROC
3392 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003393 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3394 adapter->stats.crcerrs + adapter->stats.algnerrc +
3395 adapter->stats.ruc + adapter->stats.roc +
3396 adapter->stats.cexterr;
3397 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3398 adapter->stats.roc;
3399 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3400 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3401 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3402
3403 /* Tx Errors */
3404 adapter->net_stats.tx_errors = adapter->stats.ecol +
3405 adapter->stats.latecol;
3406 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3407 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3408 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3409
3410 /* Tx Dropped needs to be maintained elsewhere */
3411
Auke Kokbc7f75f2007-09-17 12:30:59 -07003412 /* Management Stats */
3413 adapter->stats.mgptc += er32(MGTPTC);
3414 adapter->stats.mgprc += er32(MGTPRC);
3415 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003416}
3417
Bruce Allan7c257692008-04-23 11:09:00 -07003418/**
3419 * e1000_phy_read_status - Update the PHY register status snapshot
3420 * @adapter: board private structure
3421 **/
3422static void e1000_phy_read_status(struct e1000_adapter *adapter)
3423{
3424 struct e1000_hw *hw = &adapter->hw;
3425 struct e1000_phy_regs *phy = &adapter->phy_regs;
3426 int ret_val;
Bruce Allan7c257692008-04-23 11:09:00 -07003427
3428 if ((er32(STATUS) & E1000_STATUS_LU) &&
3429 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
3430 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
3431 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
3432 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
3433 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
3434 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
3435 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
3436 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
3437 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
3438 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003439 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07003440 } else {
3441 /*
3442 * Do not read PHY registers if link is not up
3443 * Set values to typical power-on defaults
3444 */
3445 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
3446 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
3447 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
3448 BMSR_ERCAP);
3449 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
3450 ADVERTISE_ALL | ADVERTISE_CSMA);
3451 phy->lpa = 0;
3452 phy->expansion = EXPANSION_ENABLENPAGE;
3453 phy->ctrl1000 = ADVERTISE_1000FULL;
3454 phy->stat1000 = 0;
3455 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
3456 }
Bruce Allan7c257692008-04-23 11:09:00 -07003457}
3458
Auke Kokbc7f75f2007-09-17 12:30:59 -07003459static void e1000_print_link_info(struct e1000_adapter *adapter)
3460{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003461 struct e1000_hw *hw = &adapter->hw;
3462 u32 ctrl = er32(CTRL);
3463
Bruce Allan8f12fe82008-11-21 16:54:43 -08003464 /* Link status message must follow this format for user tools */
3465 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
3466 "Flow Control: %s\n",
3467 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003468 adapter->link_speed,
3469 (adapter->link_duplex == FULL_DUPLEX) ?
3470 "Full Duplex" : "Half Duplex",
3471 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
3472 "RX/TX" :
3473 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
3474 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003475}
3476
Bruce Allana20e4cf2008-11-21 17:01:35 -08003477bool e1000_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003478{
3479 struct e1000_hw *hw = &adapter->hw;
3480 bool link_active = 0;
3481 s32 ret_val = 0;
3482
3483 /*
3484 * get_link_status is set on LSC (link status) interrupt or
3485 * Rx sequence error interrupt. get_link_status will stay
3486 * false until the check_for_link establishes link
3487 * for copper adapters ONLY
3488 */
3489 switch (hw->phy.media_type) {
3490 case e1000_media_type_copper:
3491 if (hw->mac.get_link_status) {
3492 ret_val = hw->mac.ops.check_for_link(hw);
3493 link_active = !hw->mac.get_link_status;
3494 } else {
3495 link_active = 1;
3496 }
3497 break;
3498 case e1000_media_type_fiber:
3499 ret_val = hw->mac.ops.check_for_link(hw);
3500 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
3501 break;
3502 case e1000_media_type_internal_serdes:
3503 ret_val = hw->mac.ops.check_for_link(hw);
3504 link_active = adapter->hw.mac.serdes_has_link;
3505 break;
3506 default:
3507 case e1000_media_type_unknown:
3508 break;
3509 }
3510
3511 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
3512 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
3513 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003514 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003515 }
3516
3517 return link_active;
3518}
3519
3520static void e1000e_enable_receives(struct e1000_adapter *adapter)
3521{
3522 /* make sure the receive unit is started */
3523 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
3524 (adapter->flags & FLAG_RX_RESTART_NOW)) {
3525 struct e1000_hw *hw = &adapter->hw;
3526 u32 rctl = er32(RCTL);
3527 ew32(RCTL, rctl | E1000_RCTL_EN);
3528 adapter->flags &= ~FLAG_RX_RESTART_NOW;
3529 }
3530}
3531
Auke Kokbc7f75f2007-09-17 12:30:59 -07003532/**
3533 * e1000_watchdog - Timer Call-back
3534 * @data: pointer to adapter cast into an unsigned long
3535 **/
3536static void e1000_watchdog(unsigned long data)
3537{
3538 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
3539
3540 /* Do the rest outside of interrupt context */
3541 schedule_work(&adapter->watchdog_task);
3542
3543 /* TODO: make this use queue_delayed_work() */
3544}
3545
3546static void e1000_watchdog_task(struct work_struct *work)
3547{
3548 struct e1000_adapter *adapter = container_of(work,
3549 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003550 struct net_device *netdev = adapter->netdev;
3551 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08003552 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003553 struct e1000_ring *tx_ring = adapter->tx_ring;
3554 struct e1000_hw *hw = &adapter->hw;
3555 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003556 int tx_pending = 0;
3557
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003558 link = e1000_has_link(adapter);
3559 if ((netif_carrier_ok(netdev)) && link) {
3560 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003561 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003562 }
3563
3564 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
3565 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
3566 e1000_update_mng_vlan(adapter);
3567
Auke Kokbc7f75f2007-09-17 12:30:59 -07003568 if (link) {
3569 if (!netif_carrier_ok(netdev)) {
3570 bool txb2b = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003571 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07003572 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003573 mac->ops.get_link_up_info(&adapter->hw,
3574 &adapter->link_speed,
3575 &adapter->link_duplex);
3576 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003577 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07003578 * On supported PHYs, check for duplex mismatch only
3579 * if link has autonegotiated at 10/100 half
3580 */
3581 if ((hw->phy.type == e1000_phy_igp_3 ||
3582 hw->phy.type == e1000_phy_bm) &&
3583 (hw->mac.autoneg == true) &&
3584 (adapter->link_speed == SPEED_10 ||
3585 adapter->link_speed == SPEED_100) &&
3586 (adapter->link_duplex == HALF_DUPLEX)) {
3587 u16 autoneg_exp;
3588
3589 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
3590
3591 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
3592 e_info("Autonegotiated half duplex but"
3593 " link partner cannot autoneg. "
3594 " Try forcing full duplex if "
3595 "link gets many collisions.\n");
3596 }
3597
3598 /*
Bruce Allanad680762008-03-28 09:15:03 -07003599 * tweak tx_queue_len according to speed/duplex
3600 * and adjust the timeout factor
3601 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003602 netdev->tx_queue_len = adapter->tx_queue_len;
3603 adapter->tx_timeout_factor = 1;
3604 switch (adapter->link_speed) {
3605 case SPEED_10:
3606 txb2b = 0;
3607 netdev->tx_queue_len = 10;
Bruce Allan10f1b492008-08-08 18:36:01 -07003608 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003609 break;
3610 case SPEED_100:
3611 txb2b = 0;
3612 netdev->tx_queue_len = 100;
3613 /* maybe add some timeout factor ? */
3614 break;
3615 }
3616
Bruce Allanad680762008-03-28 09:15:03 -07003617 /*
3618 * workaround: re-program speed mode bit after
3619 * link-up event
3620 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003621 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
3622 !txb2b) {
3623 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003624 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003625 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003626 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003627 }
3628
Bruce Allanad680762008-03-28 09:15:03 -07003629 /*
3630 * disable TSO for pcie and 10/100 speeds, to avoid
3631 * some hardware issues
3632 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003633 if (!(adapter->flags & FLAG_TSO_FORCE)) {
3634 switch (adapter->link_speed) {
3635 case SPEED_10:
3636 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003637 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003638 netdev->features &= ~NETIF_F_TSO;
3639 netdev->features &= ~NETIF_F_TSO6;
3640 break;
3641 case SPEED_1000:
3642 netdev->features |= NETIF_F_TSO;
3643 netdev->features |= NETIF_F_TSO6;
3644 break;
3645 default:
3646 /* oops */
3647 break;
3648 }
3649 }
3650
Bruce Allanad680762008-03-28 09:15:03 -07003651 /*
3652 * enable transmits in the hardware, need to do this
3653 * after setting TARC(0)
3654 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003655 tctl = er32(TCTL);
3656 tctl |= E1000_TCTL_EN;
3657 ew32(TCTL, tctl);
3658
Bruce Allan75eb0fa2008-11-21 16:53:51 -08003659 /*
3660 * Perform any post-link-up configuration before
3661 * reporting link up.
3662 */
3663 if (phy->ops.cfg_on_link_up)
3664 phy->ops.cfg_on_link_up(hw);
3665
Auke Kokbc7f75f2007-09-17 12:30:59 -07003666 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003667
3668 if (!test_bit(__E1000_DOWN, &adapter->state))
3669 mod_timer(&adapter->phy_info_timer,
3670 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003671 }
3672 } else {
3673 if (netif_carrier_ok(netdev)) {
3674 adapter->link_speed = 0;
3675 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08003676 /* Link status message must follow this format */
3677 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
3678 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003679 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003680 if (!test_bit(__E1000_DOWN, &adapter->state))
3681 mod_timer(&adapter->phy_info_timer,
3682 round_jiffies(jiffies + 2 * HZ));
3683
3684 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3685 schedule_work(&adapter->reset_task);
3686 }
3687 }
3688
3689link_up:
3690 e1000e_update_stats(adapter);
3691
3692 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
3693 adapter->tpt_old = adapter->stats.tpt;
3694 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
3695 adapter->colc_old = adapter->stats.colc;
3696
Bruce Allan7c257692008-04-23 11:09:00 -07003697 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
3698 adapter->gorc_old = adapter->stats.gorc;
3699 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
3700 adapter->gotc_old = adapter->stats.gotc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003701
3702 e1000e_update_adaptive(&adapter->hw);
3703
3704 if (!netif_carrier_ok(netdev)) {
3705 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
3706 tx_ring->count);
3707 if (tx_pending) {
Bruce Allanad680762008-03-28 09:15:03 -07003708 /*
3709 * We've lost link, so the controller stops DMA,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003710 * but we've got queued Tx work that's never going
3711 * to get done, so reset controller to flush Tx.
Bruce Allanad680762008-03-28 09:15:03 -07003712 * (Do the reset outside of interrupt context).
3713 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003714 adapter->tx_timeout_count++;
3715 schedule_work(&adapter->reset_task);
Jesse Brandeburgc2d5ab42009-05-07 11:07:35 +00003716 /* return immediately since reset is imminent */
3717 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003718 }
3719 }
3720
Bruce Allanad680762008-03-28 09:15:03 -07003721 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07003722 if (adapter->msix_entries)
3723 ew32(ICS, adapter->rx_ring->ims_val);
3724 else
3725 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003726
3727 /* Force detection of hung controller every watchdog period */
3728 adapter->detect_tx_hung = 1;
3729
Bruce Allanad680762008-03-28 09:15:03 -07003730 /*
3731 * With 82571 controllers, LAA may be overwritten due to controller
3732 * reset from the other port. Set the appropriate LAA in RAR[0]
3733 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003734 if (e1000e_get_laa_state_82571(hw))
3735 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
3736
3737 /* Reset the timer */
3738 if (!test_bit(__E1000_DOWN, &adapter->state))
3739 mod_timer(&adapter->watchdog_timer,
3740 round_jiffies(jiffies + 2 * HZ));
3741}
3742
3743#define E1000_TX_FLAGS_CSUM 0x00000001
3744#define E1000_TX_FLAGS_VLAN 0x00000002
3745#define E1000_TX_FLAGS_TSO 0x00000004
3746#define E1000_TX_FLAGS_IPV4 0x00000008
3747#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
3748#define E1000_TX_FLAGS_VLAN_SHIFT 16
3749
3750static int e1000_tso(struct e1000_adapter *adapter,
3751 struct sk_buff *skb)
3752{
3753 struct e1000_ring *tx_ring = adapter->tx_ring;
3754 struct e1000_context_desc *context_desc;
3755 struct e1000_buffer *buffer_info;
3756 unsigned int i;
3757 u32 cmd_length = 0;
3758 u16 ipcse = 0, tucse, mss;
3759 u8 ipcss, ipcso, tucss, tucso, hdr_len;
3760 int err;
3761
3762 if (skb_is_gso(skb)) {
3763 if (skb_header_cloned(skb)) {
3764 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3765 if (err)
3766 return err;
3767 }
3768
3769 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3770 mss = skb_shinfo(skb)->gso_size;
3771 if (skb->protocol == htons(ETH_P_IP)) {
3772 struct iphdr *iph = ip_hdr(skb);
3773 iph->tot_len = 0;
3774 iph->check = 0;
3775 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3776 iph->daddr, 0,
3777 IPPROTO_TCP,
3778 0);
3779 cmd_length = E1000_TXD_CMD_IP;
3780 ipcse = skb_transport_offset(skb) - 1;
3781 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3782 ipv6_hdr(skb)->payload_len = 0;
3783 tcp_hdr(skb)->check =
3784 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3785 &ipv6_hdr(skb)->daddr,
3786 0, IPPROTO_TCP, 0);
3787 ipcse = 0;
3788 }
3789 ipcss = skb_network_offset(skb);
3790 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
3791 tucss = skb_transport_offset(skb);
3792 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
3793 tucse = 0;
3794
3795 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
3796 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
3797
3798 i = tx_ring->next_to_use;
3799 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3800 buffer_info = &tx_ring->buffer_info[i];
3801
3802 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3803 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3804 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3805 context_desc->upper_setup.tcp_fields.tucss = tucss;
3806 context_desc->upper_setup.tcp_fields.tucso = tucso;
3807 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3808 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3809 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3810 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3811
3812 buffer_info->time_stamp = jiffies;
3813 buffer_info->next_to_watch = i;
3814
3815 i++;
3816 if (i == tx_ring->count)
3817 i = 0;
3818 tx_ring->next_to_use = i;
3819
3820 return 1;
3821 }
3822
3823 return 0;
3824}
3825
3826static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
3827{
3828 struct e1000_ring *tx_ring = adapter->tx_ring;
3829 struct e1000_context_desc *context_desc;
3830 struct e1000_buffer *buffer_info;
3831 unsigned int i;
3832 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07003833 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00003834 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003835
Dave Grahamaf807c82008-10-09 14:28:58 -07003836 if (skb->ip_summed != CHECKSUM_PARTIAL)
3837 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003838
Arthur Jones5f66f202009-03-19 01:13:08 +00003839 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
3840 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
3841 else
3842 protocol = skb->protocol;
3843
Arthur Jones3f518392009-03-20 15:56:35 -07003844 switch (protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08003845 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07003846 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3847 cmd_len |= E1000_TXD_CMD_TCP;
3848 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08003849 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07003850 /* XXX not handling all IPV6 headers */
3851 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3852 cmd_len |= E1000_TXD_CMD_TCP;
3853 break;
3854 default:
3855 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00003856 e_warn("checksum_partial proto=%x!\n",
3857 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07003858 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003859 }
3860
Dave Grahamaf807c82008-10-09 14:28:58 -07003861 css = skb_transport_offset(skb);
3862
3863 i = tx_ring->next_to_use;
3864 buffer_info = &tx_ring->buffer_info[i];
3865 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3866
3867 context_desc->lower_setup.ip_config = 0;
3868 context_desc->upper_setup.tcp_fields.tucss = css;
3869 context_desc->upper_setup.tcp_fields.tucso =
3870 css + skb->csum_offset;
3871 context_desc->upper_setup.tcp_fields.tucse = 0;
3872 context_desc->tcp_seg_setup.data = 0;
3873 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
3874
3875 buffer_info->time_stamp = jiffies;
3876 buffer_info->next_to_watch = i;
3877
3878 i++;
3879 if (i == tx_ring->count)
3880 i = 0;
3881 tx_ring->next_to_use = i;
3882
3883 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003884}
3885
3886#define E1000_MAX_PER_TXD 8192
3887#define E1000_MAX_TXD_PWR 12
3888
3889static int e1000_tx_map(struct e1000_adapter *adapter,
3890 struct sk_buff *skb, unsigned int first,
3891 unsigned int max_per_txd, unsigned int nr_frags,
3892 unsigned int mss)
3893{
3894 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003895 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003896 unsigned int len = skb_headlen(skb);
3897 unsigned int offset, size, count = 0, i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003898 unsigned int f;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003899 dma_addr_t *map;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003900
3901 i = tx_ring->next_to_use;
3902
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003903 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
3904 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
3905 adapter->tx_dma_failed++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003906 return 0;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003907 }
3908
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003909 map = skb_shinfo(skb)->dma_maps;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003910 offset = 0;
3911
Auke Kokbc7f75f2007-09-17 12:30:59 -07003912 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003913 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07003914 size = min(len, max_per_txd);
3915
Auke Kokbc7f75f2007-09-17 12:30:59 -07003916 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003917 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003918 buffer_info->next_to_watch = i;
Eric Dumazet042a53a2009-06-05 04:04:16 +00003919 buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003920 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003921
3922 len -= size;
3923 offset += size;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003924
3925 if (len) {
3926 i++;
3927 if (i == tx_ring->count)
3928 i = 0;
3929 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003930 }
3931
3932 for (f = 0; f < nr_frags; f++) {
3933 struct skb_frag_struct *frag;
3934
3935 frag = &skb_shinfo(skb)->frags[f];
3936 len = frag->size;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003937 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003938
3939 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003940 i++;
3941 if (i == tx_ring->count)
3942 i = 0;
3943
Auke Kokbc7f75f2007-09-17 12:30:59 -07003944 buffer_info = &tx_ring->buffer_info[i];
3945 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003946
3947 buffer_info->length = size;
3948 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003949 buffer_info->next_to_watch = i;
Eric Dumazet042a53a2009-06-05 04:04:16 +00003950 buffer_info->dma = map[f] + offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003951
3952 len -= size;
3953 offset += size;
3954 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003955 }
3956 }
3957
Auke Kokbc7f75f2007-09-17 12:30:59 -07003958 tx_ring->buffer_info[i].skb = skb;
3959 tx_ring->buffer_info[first].next_to_watch = i;
3960
3961 return count;
3962}
3963
3964static void e1000_tx_queue(struct e1000_adapter *adapter,
3965 int tx_flags, int count)
3966{
3967 struct e1000_ring *tx_ring = adapter->tx_ring;
3968 struct e1000_tx_desc *tx_desc = NULL;
3969 struct e1000_buffer *buffer_info;
3970 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3971 unsigned int i;
3972
3973 if (tx_flags & E1000_TX_FLAGS_TSO) {
3974 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3975 E1000_TXD_CMD_TSE;
3976 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3977
3978 if (tx_flags & E1000_TX_FLAGS_IPV4)
3979 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3980 }
3981
3982 if (tx_flags & E1000_TX_FLAGS_CSUM) {
3983 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3984 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3985 }
3986
3987 if (tx_flags & E1000_TX_FLAGS_VLAN) {
3988 txd_lower |= E1000_TXD_CMD_VLE;
3989 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3990 }
3991
3992 i = tx_ring->next_to_use;
3993
3994 while (count--) {
3995 buffer_info = &tx_ring->buffer_info[i];
3996 tx_desc = E1000_TX_DESC(*tx_ring, i);
3997 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3998 tx_desc->lower.data =
3999 cpu_to_le32(txd_lower | buffer_info->length);
4000 tx_desc->upper.data = cpu_to_le32(txd_upper);
4001
4002 i++;
4003 if (i == tx_ring->count)
4004 i = 0;
4005 }
4006
4007 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4008
Bruce Allanad680762008-03-28 09:15:03 -07004009 /*
4010 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004011 * know there are new descriptors to fetch. (Only
4012 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004013 * such as IA-64).
4014 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004015 wmb();
4016
4017 tx_ring->next_to_use = i;
4018 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07004019 /*
4020 * we need this if more than one processor can write to our tail
4021 * at a time, it synchronizes IO on IA64/Altix systems
4022 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004023 mmiowb();
4024}
4025
4026#define MINIMUM_DHCP_PACKET_SIZE 282
4027static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4028 struct sk_buff *skb)
4029{
4030 struct e1000_hw *hw = &adapter->hw;
4031 u16 length, offset;
4032
4033 if (vlan_tx_tag_present(skb)) {
4034 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id)
4035 && (adapter->hw.mng_cookie.status &
4036 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4037 return 0;
4038 }
4039
4040 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4041 return 0;
4042
4043 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4044 return 0;
4045
4046 {
4047 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4048 struct udphdr *udp;
4049
4050 if (ip->protocol != IPPROTO_UDP)
4051 return 0;
4052
4053 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4054 if (ntohs(udp->dest) != 67)
4055 return 0;
4056
4057 offset = (u8 *)udp + 8 - skb->data;
4058 length = skb->len - offset;
4059 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4060 }
4061
4062 return 0;
4063}
4064
4065static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4066{
4067 struct e1000_adapter *adapter = netdev_priv(netdev);
4068
4069 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004070 /*
4071 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004072 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004073 * but since that doesn't exist yet, just open code it.
4074 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004075 smp_mb();
4076
Bruce Allanad680762008-03-28 09:15:03 -07004077 /*
4078 * We need to check again in a case another CPU has just
4079 * made room available.
4080 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004081 if (e1000_desc_unused(adapter->tx_ring) < size)
4082 return -EBUSY;
4083
4084 /* A reprieve! */
4085 netif_start_queue(netdev);
4086 ++adapter->restart_queue;
4087 return 0;
4088}
4089
4090static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4091{
4092 struct e1000_adapter *adapter = netdev_priv(netdev);
4093
4094 if (e1000_desc_unused(adapter->tx_ring) >= size)
4095 return 0;
4096 return __e1000_maybe_stop_tx(netdev, size);
4097}
4098
4099#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4100static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
4101{
4102 struct e1000_adapter *adapter = netdev_priv(netdev);
4103 struct e1000_ring *tx_ring = adapter->tx_ring;
4104 unsigned int first;
4105 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4106 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4107 unsigned int tx_flags = 0;
Auke Kok4e6c7092007-10-05 14:15:23 -07004108 unsigned int len = skb->len - skb->data_len;
Auke Kok4e6c7092007-10-05 14:15:23 -07004109 unsigned int nr_frags;
4110 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004111 int count = 0;
4112 int tso;
4113 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004114
4115 if (test_bit(__E1000_DOWN, &adapter->state)) {
4116 dev_kfree_skb_any(skb);
4117 return NETDEV_TX_OK;
4118 }
4119
4120 if (skb->len <= 0) {
4121 dev_kfree_skb_any(skb);
4122 return NETDEV_TX_OK;
4123 }
4124
4125 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004126 /*
4127 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004128 * make sure there is enough room in the FIFO before
4129 * initiating the DMA for each buffer. The calc is:
4130 * 4 = ceil(buffer len/mss). To make sure we don't
4131 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004132 * drops.
4133 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004134 if (mss) {
4135 u8 hdr_len;
4136 max_per_txd = min(mss << 2, max_per_txd);
4137 max_txd_pwr = fls(max_per_txd) - 1;
4138
Bruce Allanad680762008-03-28 09:15:03 -07004139 /*
4140 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4141 * points to just header, pull a few bytes of payload from
4142 * frags into skb->data
4143 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004144 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004145 /*
4146 * we do this workaround for ES2LAN, but it is un-necessary,
4147 * avoiding it could save a lot of cycles
4148 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004149 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004150 unsigned int pull_size;
4151
4152 pull_size = min((unsigned int)4, skb->data_len);
4153 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004154 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004155 dev_kfree_skb_any(skb);
4156 return NETDEV_TX_OK;
4157 }
4158 len = skb->len - skb->data_len;
4159 }
4160 }
4161
4162 /* reserve a descriptor for the offload context */
4163 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4164 count++;
4165 count++;
4166
4167 count += TXD_USE_COUNT(len, max_txd_pwr);
4168
4169 nr_frags = skb_shinfo(skb)->nr_frags;
4170 for (f = 0; f < nr_frags; f++)
4171 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4172 max_txd_pwr);
4173
4174 if (adapter->hw.mac.tx_pkt_filtering)
4175 e1000_transfer_dhcp_info(adapter, skb);
4176
Bruce Allanad680762008-03-28 09:15:03 -07004177 /*
4178 * need: count + 2 desc gap to keep tail from touching
4179 * head, otherwise try next time
4180 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004181 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004182 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004183
4184 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4185 tx_flags |= E1000_TX_FLAGS_VLAN;
4186 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4187 }
4188
4189 first = tx_ring->next_to_use;
4190
4191 tso = e1000_tso(adapter, skb);
4192 if (tso < 0) {
4193 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004194 return NETDEV_TX_OK;
4195 }
4196
4197 if (tso)
4198 tx_flags |= E1000_TX_FLAGS_TSO;
4199 else if (e1000_tx_csum(adapter, skb))
4200 tx_flags |= E1000_TX_FLAGS_CSUM;
4201
Bruce Allanad680762008-03-28 09:15:03 -07004202 /*
4203 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004204 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004205 * no longer assume, we must.
4206 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004207 if (skb->protocol == htons(ETH_P_IP))
4208 tx_flags |= E1000_TX_FLAGS_IPV4;
4209
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004210 /* if count is 0 then mapping error has occured */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004211 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004212 if (count) {
4213 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004214 /* Make sure there is space in the ring for the next send. */
4215 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4216
4217 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004218 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004219 tx_ring->buffer_info[first].time_stamp = 0;
4220 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004221 }
4222
Auke Kokbc7f75f2007-09-17 12:30:59 -07004223 return NETDEV_TX_OK;
4224}
4225
4226/**
4227 * e1000_tx_timeout - Respond to a Tx Hang
4228 * @netdev: network interface device structure
4229 **/
4230static void e1000_tx_timeout(struct net_device *netdev)
4231{
4232 struct e1000_adapter *adapter = netdev_priv(netdev);
4233
4234 /* Do the reset outside of interrupt context */
4235 adapter->tx_timeout_count++;
4236 schedule_work(&adapter->reset_task);
4237}
4238
4239static void e1000_reset_task(struct work_struct *work)
4240{
4241 struct e1000_adapter *adapter;
4242 adapter = container_of(work, struct e1000_adapter, reset_task);
4243
4244 e1000e_reinit_locked(adapter);
4245}
4246
4247/**
4248 * e1000_get_stats - Get System Network Statistics
4249 * @netdev: network interface device structure
4250 *
4251 * Returns the address of the device statistics structure.
4252 * The statistics are actually updated from the timer callback.
4253 **/
4254static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
4255{
4256 struct e1000_adapter *adapter = netdev_priv(netdev);
4257
4258 /* only return the current stats */
4259 return &adapter->net_stats;
4260}
4261
4262/**
4263 * e1000_change_mtu - Change the Maximum Transfer Unit
4264 * @netdev: network interface device structure
4265 * @new_mtu: new value for maximum frame size
4266 *
4267 * Returns 0 on success, negative on failure
4268 **/
4269static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4270{
4271 struct e1000_adapter *adapter = netdev_priv(netdev);
4272 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4273
Bruce Allan2adc55c2009-06-02 11:28:58 +00004274 /* Jumbo frame support */
4275 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
4276 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
4277 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004278 return -EINVAL;
4279 }
4280
Bruce Allan2adc55c2009-06-02 11:28:58 +00004281 /* Supported frame sizes */
4282 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
4283 (max_frame > adapter->max_hw_frame_size)) {
4284 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004285 return -EINVAL;
4286 }
4287
4288 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4289 msleep(1);
4290 /* e1000e_down has a dependency on max_frame_size */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004291 adapter->max_frame_size = max_frame;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004292 if (netif_running(netdev))
4293 e1000e_down(adapter);
4294
Bruce Allanad680762008-03-28 09:15:03 -07004295 /*
4296 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07004297 * means we reserve 2 more, this pushes us to allocate from the next
4298 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07004299 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004300 * However with the new *_jumbo_rx* routines, jumbo receives will use
4301 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07004302 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004303
4304 if (max_frame <= 256)
4305 adapter->rx_buffer_len = 256;
4306 else if (max_frame <= 512)
4307 adapter->rx_buffer_len = 512;
4308 else if (max_frame <= 1024)
4309 adapter->rx_buffer_len = 1024;
4310 else if (max_frame <= 2048)
4311 adapter->rx_buffer_len = 2048;
4312 else
4313 adapter->rx_buffer_len = 4096;
4314
4315 /* adjust allocation if LPE protects us, and we aren't using SBP */
4316 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
4317 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
4318 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07004319 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004320
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004321 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004322 netdev->mtu = new_mtu;
4323
4324 if (netif_running(netdev))
4325 e1000e_up(adapter);
4326 else
4327 e1000e_reset(adapter);
4328
4329 clear_bit(__E1000_RESETTING, &adapter->state);
4330
4331 return 0;
4332}
4333
4334static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4335 int cmd)
4336{
4337 struct e1000_adapter *adapter = netdev_priv(netdev);
4338 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004339
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004340 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004341 return -EOPNOTSUPP;
4342
4343 switch (cmd) {
4344 case SIOCGMIIPHY:
4345 data->phy_id = adapter->hw.phy.addr;
4346 break;
4347 case SIOCGMIIREG:
4348 if (!capable(CAP_NET_ADMIN))
4349 return -EPERM;
Bruce Allan7c257692008-04-23 11:09:00 -07004350 switch (data->reg_num & 0x1F) {
4351 case MII_BMCR:
4352 data->val_out = adapter->phy_regs.bmcr;
4353 break;
4354 case MII_BMSR:
4355 data->val_out = adapter->phy_regs.bmsr;
4356 break;
4357 case MII_PHYSID1:
4358 data->val_out = (adapter->hw.phy.id >> 16);
4359 break;
4360 case MII_PHYSID2:
4361 data->val_out = (adapter->hw.phy.id & 0xFFFF);
4362 break;
4363 case MII_ADVERTISE:
4364 data->val_out = adapter->phy_regs.advertise;
4365 break;
4366 case MII_LPA:
4367 data->val_out = adapter->phy_regs.lpa;
4368 break;
4369 case MII_EXPANSION:
4370 data->val_out = adapter->phy_regs.expansion;
4371 break;
4372 case MII_CTRL1000:
4373 data->val_out = adapter->phy_regs.ctrl1000;
4374 break;
4375 case MII_STAT1000:
4376 data->val_out = adapter->phy_regs.stat1000;
4377 break;
4378 case MII_ESTATUS:
4379 data->val_out = adapter->phy_regs.estatus;
4380 break;
4381 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004382 return -EIO;
4383 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004384 break;
4385 case SIOCSMIIREG:
4386 default:
4387 return -EOPNOTSUPP;
4388 }
4389 return 0;
4390}
4391
4392static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4393{
4394 switch (cmd) {
4395 case SIOCGMIIPHY:
4396 case SIOCGMIIREG:
4397 case SIOCSMIIREG:
4398 return e1000_mii_ioctl(netdev, ifr, cmd);
4399 default:
4400 return -EOPNOTSUPP;
4401 }
4402}
4403
Bruce Allana4f58f52009-06-02 11:29:18 +00004404static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
4405{
4406 struct e1000_hw *hw = &adapter->hw;
4407 u32 i, mac_reg;
4408 u16 phy_reg;
4409 int retval = 0;
4410
4411 /* copy MAC RARs to PHY RARs */
4412 for (i = 0; i < adapter->hw.mac.rar_entry_count; i++) {
4413 mac_reg = er32(RAL(i));
4414 e1e_wphy(hw, BM_RAR_L(i), (u16)(mac_reg & 0xFFFF));
4415 e1e_wphy(hw, BM_RAR_M(i), (u16)((mac_reg >> 16) & 0xFFFF));
4416 mac_reg = er32(RAH(i));
4417 e1e_wphy(hw, BM_RAR_H(i), (u16)(mac_reg & 0xFFFF));
4418 e1e_wphy(hw, BM_RAR_CTRL(i), (u16)((mac_reg >> 16) & 0xFFFF));
4419 }
4420
4421 /* copy MAC MTA to PHY MTA */
4422 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
4423 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
4424 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
4425 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
4426 }
4427
4428 /* configure PHY Rx Control register */
4429 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
4430 mac_reg = er32(RCTL);
4431 if (mac_reg & E1000_RCTL_UPE)
4432 phy_reg |= BM_RCTL_UPE;
4433 if (mac_reg & E1000_RCTL_MPE)
4434 phy_reg |= BM_RCTL_MPE;
4435 phy_reg &= ~(BM_RCTL_MO_MASK);
4436 if (mac_reg & E1000_RCTL_MO_3)
4437 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
4438 << BM_RCTL_MO_SHIFT);
4439 if (mac_reg & E1000_RCTL_BAM)
4440 phy_reg |= BM_RCTL_BAM;
4441 if (mac_reg & E1000_RCTL_PMCF)
4442 phy_reg |= BM_RCTL_PMCF;
4443 mac_reg = er32(CTRL);
4444 if (mac_reg & E1000_CTRL_RFCE)
4445 phy_reg |= BM_RCTL_RFCE;
4446 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
4447
4448 /* enable PHY wakeup in MAC register */
4449 ew32(WUFC, wufc);
4450 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
4451
4452 /* configure and enable PHY wakeup in PHY registers */
4453 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
4454 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
4455
4456 /* activate PHY wakeup */
4457 retval = hw->phy.ops.acquire_phy(hw);
4458 if (retval) {
4459 e_err("Could not acquire PHY\n");
4460 return retval;
4461 }
4462 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4463 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
4464 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
4465 if (retval) {
4466 e_err("Could not read PHY page 769\n");
4467 goto out;
4468 }
4469 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
4470 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
4471 if (retval)
4472 e_err("Could not set PHY Host Wakeup bit\n");
4473out:
4474 hw->phy.ops.release_phy(hw);
4475
4476 return retval;
4477}
4478
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004479static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004480{
4481 struct net_device *netdev = pci_get_drvdata(pdev);
4482 struct e1000_adapter *adapter = netdev_priv(netdev);
4483 struct e1000_hw *hw = &adapter->hw;
4484 u32 ctrl, ctrl_ext, rctl, status;
4485 u32 wufc = adapter->wol;
4486 int retval = 0;
4487
4488 netif_device_detach(netdev);
4489
4490 if (netif_running(netdev)) {
4491 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
4492 e1000e_down(adapter);
4493 e1000_free_irq(adapter);
4494 }
Bruce Allan4662e822008-08-26 18:37:06 -07004495 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004496
4497 retval = pci_save_state(pdev);
4498 if (retval)
4499 return retval;
4500
4501 status = er32(STATUS);
4502 if (status & E1000_STATUS_LU)
4503 wufc &= ~E1000_WUFC_LNKC;
4504
4505 if (wufc) {
4506 e1000_setup_rctl(adapter);
4507 e1000_set_multi(netdev);
4508
4509 /* turn on all-multi mode if wake on multicast is enabled */
4510 if (wufc & E1000_WUFC_MC) {
4511 rctl = er32(RCTL);
4512 rctl |= E1000_RCTL_MPE;
4513 ew32(RCTL, rctl);
4514 }
4515
4516 ctrl = er32(CTRL);
4517 /* advertise wake from D3Cold */
4518 #define E1000_CTRL_ADVD3WUC 0x00100000
4519 /* phy power management enable */
4520 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00004521 ctrl |= E1000_CTRL_ADVD3WUC;
4522 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
4523 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004524 ew32(CTRL, ctrl);
4525
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004526 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
4527 adapter->hw.phy.media_type ==
4528 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004529 /* keep the laser running in D3 */
4530 ctrl_ext = er32(CTRL_EXT);
4531 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4532 ew32(CTRL_EXT, ctrl_ext);
4533 }
4534
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004535 if (adapter->flags & FLAG_IS_ICH)
4536 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
4537
Auke Kokbc7f75f2007-09-17 12:30:59 -07004538 /* Allow time for pending master requests to run */
4539 e1000e_disable_pcie_master(&adapter->hw);
4540
Bruce Allana4f58f52009-06-02 11:29:18 +00004541 if ((adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) &&
4542 !(hw->mac.ops.check_mng_mode(hw))) {
4543 /* enable wakeup by the PHY */
4544 retval = e1000_init_phy_wakeup(adapter, wufc);
4545 if (retval)
4546 return retval;
4547 } else {
4548 /* enable wakeup by the MAC */
4549 ew32(WUFC, wufc);
4550 ew32(WUC, E1000_WUC_PME_EN);
4551 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004552 } else {
4553 ew32(WUC, 0);
4554 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004555 }
4556
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004557 *enable_wake = !!wufc;
4558
Auke Kokbc7f75f2007-09-17 12:30:59 -07004559 /* make sure adapter isn't asleep if manageability is enabled */
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004560 if (adapter->flags & FLAG_MNG_PT_ENABLED)
4561 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004562
4563 if (adapter->hw.phy.type == e1000_phy_igp_3)
4564 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
4565
Bruce Allanad680762008-03-28 09:15:03 -07004566 /*
4567 * Release control of h/w to f/w. If f/w is AMT enabled, this
4568 * would have already happened in close and is redundant.
4569 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004570 e1000_release_hw_control(adapter);
4571
4572 pci_disable_device(pdev);
4573
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004574 return 0;
4575}
4576
4577static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
4578{
4579 if (sleep && wake) {
4580 pci_prepare_to_sleep(pdev);
4581 return;
4582 }
4583
4584 pci_wake_from_d3(pdev, wake);
4585 pci_set_power_state(pdev, PCI_D3hot);
4586}
4587
4588static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
4589 bool wake)
4590{
4591 struct net_device *netdev = pci_get_drvdata(pdev);
4592 struct e1000_adapter *adapter = netdev_priv(netdev);
4593
Alexander Duyck005cbdf2008-11-21 16:49:10 -08004594 /*
4595 * The pci-e switch on some quad port adapters will report a
4596 * correctable error when the MAC transitions from D0 to D3. To
4597 * prevent this we need to mask off the correctable errors on the
4598 * downstream port of the pci-e switch.
4599 */
4600 if (adapter->flags & FLAG_IS_QUAD_PORT) {
4601 struct pci_dev *us_dev = pdev->bus->self;
4602 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
4603 u16 devctl;
4604
4605 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
4606 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
4607 (devctl & ~PCI_EXP_DEVCTL_CERE));
4608
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004609 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08004610
4611 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
4612 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004613 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08004614 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004615}
4616
Auke Kok1eae4eb2007-10-31 15:22:00 -07004617static void e1000e_disable_l1aspm(struct pci_dev *pdev)
4618{
4619 int pos;
Auke Kok1eae4eb2007-10-31 15:22:00 -07004620 u16 val;
4621
4622 /*
4623 * 82573 workaround - disable L1 ASPM on mobile chipsets
4624 *
4625 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
4626 * resulting in lost data or garbage information on the pci-e link
4627 * level. This could result in (false) bad EEPROM checksum errors,
4628 * long ping times (up to 2s) or even a system freeze/hang.
4629 *
4630 * Unfortunately this feature saves about 1W power consumption when
4631 * active.
4632 */
4633 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
Auke Kok1eae4eb2007-10-31 15:22:00 -07004634 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val);
4635 if (val & 0x2) {
4636 dev_warn(&pdev->dev, "Disabling L1 ASPM\n");
4637 val &= ~0x2;
4638 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val);
4639 }
4640}
4641
Auke Kokbc7f75f2007-09-17 12:30:59 -07004642#ifdef CONFIG_PM
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004643static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4644{
4645 int retval;
4646 bool wake;
4647
4648 retval = __e1000_shutdown(pdev, &wake);
4649 if (!retval)
4650 e1000_complete_shutdown(pdev, true, wake);
4651
4652 return retval;
4653}
4654
Auke Kokbc7f75f2007-09-17 12:30:59 -07004655static int e1000_resume(struct pci_dev *pdev)
4656{
4657 struct net_device *netdev = pci_get_drvdata(pdev);
4658 struct e1000_adapter *adapter = netdev_priv(netdev);
4659 struct e1000_hw *hw = &adapter->hw;
4660 u32 err;
4661
4662 pci_set_power_state(pdev, PCI_D0);
4663 pci_restore_state(pdev);
Auke Kok1eae4eb2007-10-31 15:22:00 -07004664 e1000e_disable_l1aspm(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004665
Bruce Allanf0f422e2008-08-04 17:21:53 -07004666 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004667 if (err) {
4668 dev_err(&pdev->dev,
4669 "Cannot enable PCI device from suspend\n");
4670 return err;
4671 }
4672
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00004673 /* AER (Advanced Error Reporting) hooks */
4674 err = pci_enable_pcie_error_reporting(pdev);
4675 if (err) {
4676 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4677 "0x%x\n", err);
4678 /* non-fatal, continue */
4679 }
4680
Auke Kokbc7f75f2007-09-17 12:30:59 -07004681 pci_set_master(pdev);
4682
4683 pci_enable_wake(pdev, PCI_D3hot, 0);
4684 pci_enable_wake(pdev, PCI_D3cold, 0);
4685
Bruce Allan4662e822008-08-26 18:37:06 -07004686 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004687 if (netif_running(netdev)) {
4688 err = e1000_request_irq(adapter);
4689 if (err)
4690 return err;
4691 }
4692
4693 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00004694
4695 /* report the system wakeup cause from S3/S4 */
4696 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
4697 u16 phy_data;
4698
4699 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
4700 if (phy_data) {
4701 e_info("PHY Wakeup cause - %s\n",
4702 phy_data & E1000_WUS_EX ? "Unicast Packet" :
4703 phy_data & E1000_WUS_MC ? "Multicast Packet" :
4704 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
4705 phy_data & E1000_WUS_MAG ? "Magic Packet" :
4706 phy_data & E1000_WUS_LNKC ? "Link Status "
4707 " Change" : "other");
4708 }
4709 e1e_wphy(&adapter->hw, BM_WUS, ~0);
4710 } else {
4711 u32 wus = er32(WUS);
4712 if (wus) {
4713 e_info("MAC Wakeup cause - %s\n",
4714 wus & E1000_WUS_EX ? "Unicast Packet" :
4715 wus & E1000_WUS_MC ? "Multicast Packet" :
4716 wus & E1000_WUS_BC ? "Broadcast Packet" :
4717 wus & E1000_WUS_MAG ? "Magic Packet" :
4718 wus & E1000_WUS_LNKC ? "Link Status Change" :
4719 "other");
4720 }
4721 ew32(WUS, ~0);
4722 }
4723
Auke Kokbc7f75f2007-09-17 12:30:59 -07004724 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004725
4726 e1000_init_manageability(adapter);
4727
4728 if (netif_running(netdev))
4729 e1000e_up(adapter);
4730
4731 netif_device_attach(netdev);
4732
Bruce Allanad680762008-03-28 09:15:03 -07004733 /*
4734 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004735 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07004736 * under the control of the driver.
4737 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004738 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004739 e1000_get_hw_control(adapter);
4740
4741 return 0;
4742}
4743#endif
4744
4745static void e1000_shutdown(struct pci_dev *pdev)
4746{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004747 bool wake = false;
4748
4749 __e1000_shutdown(pdev, &wake);
4750
4751 if (system_state == SYSTEM_POWER_OFF)
4752 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004753}
4754
4755#ifdef CONFIG_NET_POLL_CONTROLLER
4756/*
4757 * Polling 'interrupt' - used by things like netconsole to send skbs
4758 * without having to re-enable interrupts. It's not called while
4759 * the interrupt routine is executing.
4760 */
4761static void e1000_netpoll(struct net_device *netdev)
4762{
4763 struct e1000_adapter *adapter = netdev_priv(netdev);
4764
4765 disable_irq(adapter->pdev->irq);
4766 e1000_intr(adapter->pdev->irq, netdev);
4767
Auke Kokbc7f75f2007-09-17 12:30:59 -07004768 enable_irq(adapter->pdev->irq);
4769}
4770#endif
4771
4772/**
4773 * e1000_io_error_detected - called when PCI error is detected
4774 * @pdev: Pointer to PCI device
4775 * @state: The current pci connection state
4776 *
4777 * This function is called after a PCI bus error affecting
4778 * this device has been detected.
4779 */
4780static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
4781 pci_channel_state_t state)
4782{
4783 struct net_device *netdev = pci_get_drvdata(pdev);
4784 struct e1000_adapter *adapter = netdev_priv(netdev);
4785
4786 netif_device_detach(netdev);
4787
4788 if (netif_running(netdev))
4789 e1000e_down(adapter);
4790 pci_disable_device(pdev);
4791
4792 /* Request a slot slot reset. */
4793 return PCI_ERS_RESULT_NEED_RESET;
4794}
4795
4796/**
4797 * e1000_io_slot_reset - called after the pci bus has been reset.
4798 * @pdev: Pointer to PCI device
4799 *
4800 * Restart the card from scratch, as if from a cold-boot. Implementation
4801 * resembles the first-half of the e1000_resume routine.
4802 */
4803static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4804{
4805 struct net_device *netdev = pci_get_drvdata(pdev);
4806 struct e1000_adapter *adapter = netdev_priv(netdev);
4807 struct e1000_hw *hw = &adapter->hw;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004808 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00004809 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004810
Auke Kok1eae4eb2007-10-31 15:22:00 -07004811 e1000e_disable_l1aspm(pdev);
Bruce Allanf0f422e2008-08-04 17:21:53 -07004812 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004813 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004814 dev_err(&pdev->dev,
4815 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00004816 result = PCI_ERS_RESULT_DISCONNECT;
4817 } else {
4818 pci_set_master(pdev);
4819 pci_restore_state(pdev);
4820
4821 pci_enable_wake(pdev, PCI_D3hot, 0);
4822 pci_enable_wake(pdev, PCI_D3cold, 0);
4823
4824 e1000e_reset(adapter);
4825 ew32(WUS, ~0);
4826 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004827 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004828
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00004829 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004830
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00004831 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004832}
4833
4834/**
4835 * e1000_io_resume - called when traffic can start flowing again.
4836 * @pdev: Pointer to PCI device
4837 *
4838 * This callback is called when the error recovery driver tells us that
4839 * its OK to resume normal operation. Implementation resembles the
4840 * second-half of the e1000_resume routine.
4841 */
4842static void e1000_io_resume(struct pci_dev *pdev)
4843{
4844 struct net_device *netdev = pci_get_drvdata(pdev);
4845 struct e1000_adapter *adapter = netdev_priv(netdev);
4846
4847 e1000_init_manageability(adapter);
4848
4849 if (netif_running(netdev)) {
4850 if (e1000e_up(adapter)) {
4851 dev_err(&pdev->dev,
4852 "can't bring device back up after reset\n");
4853 return;
4854 }
4855 }
4856
4857 netif_device_attach(netdev);
4858
Bruce Allanad680762008-03-28 09:15:03 -07004859 /*
4860 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004861 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07004862 * under the control of the driver.
4863 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004864 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004865 e1000_get_hw_control(adapter);
4866
4867}
4868
4869static void e1000_print_device_info(struct e1000_adapter *adapter)
4870{
4871 struct e1000_hw *hw = &adapter->hw;
4872 struct net_device *netdev = adapter->netdev;
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004873 u32 pba_num;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004874
4875 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07004876 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004877 /* bus width */
4878 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
4879 "Width x1"),
4880 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07004881 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004882 e_info("Intel(R) PRO/%s Network Connection\n",
4883 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004884 e1000e_read_pba_num(hw, &pba_num);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004885 e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4886 hw->mac.type, hw->phy.type, (pba_num >> 8), (pba_num & 0xff));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004887}
4888
Auke Kok10aa4c02008-08-04 17:21:20 -07004889static void e1000_eeprom_checks(struct e1000_adapter *adapter)
4890{
4891 struct e1000_hw *hw = &adapter->hw;
4892 int ret_val;
4893 u16 buf = 0;
4894
4895 if (hw->mac.type != e1000_82573)
4896 return;
4897
4898 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08004899 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07004900 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07004901 dev_warn(&adapter->pdev->dev,
4902 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07004903 }
4904
4905 ret_val = e1000_read_nvm(hw, NVM_INIT_3GIO_3, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08004906 if (!ret_val && (le16_to_cpu(buf) & (3 << 2))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07004907 /* ASPM enable */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07004908 dev_warn(&adapter->pdev->dev,
4909 "Warning: detected ASPM enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07004910 }
4911}
4912
Stephen Hemminger651c2462008-11-19 21:57:48 -08004913static const struct net_device_ops e1000e_netdev_ops = {
4914 .ndo_open = e1000_open,
4915 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08004916 .ndo_start_xmit = e1000_xmit_frame,
Stephen Hemminger651c2462008-11-19 21:57:48 -08004917 .ndo_get_stats = e1000_get_stats,
4918 .ndo_set_multicast_list = e1000_set_multi,
4919 .ndo_set_mac_address = e1000_set_mac,
4920 .ndo_change_mtu = e1000_change_mtu,
4921 .ndo_do_ioctl = e1000_ioctl,
4922 .ndo_tx_timeout = e1000_tx_timeout,
4923 .ndo_validate_addr = eth_validate_addr,
4924
4925 .ndo_vlan_rx_register = e1000_vlan_rx_register,
4926 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
4927 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
4928#ifdef CONFIG_NET_POLL_CONTROLLER
4929 .ndo_poll_controller = e1000_netpoll,
4930#endif
4931};
4932
Auke Kokbc7f75f2007-09-17 12:30:59 -07004933/**
4934 * e1000_probe - Device Initialization Routine
4935 * @pdev: PCI device information struct
4936 * @ent: entry in e1000_pci_tbl
4937 *
4938 * Returns 0 on success, negative on failure
4939 *
4940 * e1000_probe initializes an adapter identified by a pci_dev structure.
4941 * The OS initialization, configuring of the adapter private structure,
4942 * and a hardware reset occur.
4943 **/
4944static int __devinit e1000_probe(struct pci_dev *pdev,
4945 const struct pci_device_id *ent)
4946{
4947 struct net_device *netdev;
4948 struct e1000_adapter *adapter;
4949 struct e1000_hw *hw;
4950 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05004951 resource_size_t mmio_start, mmio_len;
4952 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004953
4954 static int cards_found;
4955 int i, err, pci_using_dac;
4956 u16 eeprom_data = 0;
4957 u16 eeprom_apme_mask = E1000_EEPROM_APME;
4958
Auke Kok1eae4eb2007-10-31 15:22:00 -07004959 e1000e_disable_l1aspm(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004960
Bruce Allanf0f422e2008-08-04 17:21:53 -07004961 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004962 if (err)
4963 return err;
4964
4965 pci_using_dac = 0;
Yang Hongyang6a355282009-04-06 19:01:13 -07004966 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004967 if (!err) {
Yang Hongyang6a355282009-04-06 19:01:13 -07004968 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004969 if (!err)
4970 pci_using_dac = 1;
4971 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07004972 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004973 if (err) {
4974 err = pci_set_consistent_dma_mask(pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07004975 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004976 if (err) {
4977 dev_err(&pdev->dev, "No usable DMA "
4978 "configuration, aborting\n");
4979 goto err_dma;
4980 }
4981 }
4982 }
4983
Arjan van de Vene8de1482008-10-22 19:55:31 -07004984 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07004985 pci_select_bars(pdev, IORESOURCE_MEM),
4986 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004987 if (err)
4988 goto err_pci_reg;
4989
4990 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08004991 /* PCI config space info */
4992 err = pci_save_state(pdev);
4993 if (err)
4994 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004995
4996 err = -ENOMEM;
4997 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
4998 if (!netdev)
4999 goto err_alloc_etherdev;
5000
Auke Kokbc7f75f2007-09-17 12:30:59 -07005001 SET_NETDEV_DEV(netdev, &pdev->dev);
5002
5003 pci_set_drvdata(pdev, netdev);
5004 adapter = netdev_priv(netdev);
5005 hw = &adapter->hw;
5006 adapter->netdev = netdev;
5007 adapter->pdev = pdev;
5008 adapter->ei = ei;
5009 adapter->pba = ei->pba;
5010 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005011 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005012 adapter->hw.adapter = adapter;
5013 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005014 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005015 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5016
5017 mmio_start = pci_resource_start(pdev, 0);
5018 mmio_len = pci_resource_len(pdev, 0);
5019
5020 err = -EIO;
5021 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5022 if (!adapter->hw.hw_addr)
5023 goto err_ioremap;
5024
5025 if ((adapter->flags & FLAG_HAS_FLASH) &&
5026 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5027 flash_start = pci_resource_start(pdev, 1);
5028 flash_len = pci_resource_len(pdev, 1);
5029 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5030 if (!adapter->hw.flash_address)
5031 goto err_flashmap;
5032 }
5033
5034 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005035 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005036 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037 netdev->watchdog_timeo = 5 * HZ;
5038 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005039 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5040
5041 netdev->mem_start = mmio_start;
5042 netdev->mem_end = mmio_start + mmio_len;
5043
5044 adapter->bd_number = cards_found++;
5045
Bruce Allan4662e822008-08-26 18:37:06 -07005046 e1000e_check_options(adapter);
5047
Auke Kokbc7f75f2007-09-17 12:30:59 -07005048 /* setup adapter struct */
5049 err = e1000_sw_init(adapter);
5050 if (err)
5051 goto err_sw_init;
5052
5053 err = -EIO;
5054
5055 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5056 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5057 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5058
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005059 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005060 if (err)
5061 goto err_hw_init;
5062
Bruce Allan4a770352008-10-01 17:18:35 -07005063 if ((adapter->flags & FLAG_IS_ICH) &&
5064 (adapter->flags & FLAG_READ_ONLY_NVM))
5065 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5066
Auke Kokbc7f75f2007-09-17 12:30:59 -07005067 hw->mac.ops.get_bus_info(&adapter->hw);
5068
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005069 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005070
5071 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005072 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005073 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5074 adapter->hw.phy.disable_polarity_correction = 0;
5075 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5076 }
5077
5078 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005079 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005080
5081 netdev->features = NETIF_F_SG |
5082 NETIF_F_HW_CSUM |
5083 NETIF_F_HW_VLAN_TX |
5084 NETIF_F_HW_VLAN_RX;
5085
5086 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5087 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5088
5089 netdev->features |= NETIF_F_TSO;
5090 netdev->features |= NETIF_F_TSO6;
5091
Jeff Kirshera5136e22008-06-05 04:07:28 -07005092 netdev->vlan_features |= NETIF_F_TSO;
5093 netdev->vlan_features |= NETIF_F_TSO6;
5094 netdev->vlan_features |= NETIF_F_HW_CSUM;
5095 netdev->vlan_features |= NETIF_F_SG;
5096
Auke Kokbc7f75f2007-09-17 12:30:59 -07005097 if (pci_using_dac)
5098 netdev->features |= NETIF_F_HIGHDMA;
5099
Auke Kokbc7f75f2007-09-17 12:30:59 -07005100 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5101 adapter->flags |= FLAG_MNG_PT_ENABLED;
5102
Bruce Allanad680762008-03-28 09:15:03 -07005103 /*
5104 * before reading the NVM, reset the controller to
5105 * put the device in a known good starting state
5106 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5108
5109 /*
5110 * systems with ASPM and others may see the checksum fail on the first
5111 * attempt. Let's give it a few tries
5112 */
5113 for (i = 0;; i++) {
5114 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5115 break;
5116 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005117 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005118 err = -EIO;
5119 goto err_eeprom;
5120 }
5121 }
5122
Auke Kok10aa4c02008-08-04 17:21:20 -07005123 e1000_eeprom_checks(adapter);
5124
Auke Kokbc7f75f2007-09-17 12:30:59 -07005125 /* copy the MAC address out of the NVM */
5126 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005127 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005128
5129 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5130 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5131
5132 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07005133 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005134 err = -EIO;
5135 goto err_eeprom;
5136 }
5137
5138 init_timer(&adapter->watchdog_timer);
5139 adapter->watchdog_timer.function = &e1000_watchdog;
5140 adapter->watchdog_timer.data = (unsigned long) adapter;
5141
5142 init_timer(&adapter->phy_info_timer);
5143 adapter->phy_info_timer.function = &e1000_update_phy_info;
5144 adapter->phy_info_timer.data = (unsigned long) adapter;
5145
5146 INIT_WORK(&adapter->reset_task, e1000_reset_task);
5147 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07005148 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
5149 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005150
Auke Kokbc7f75f2007-09-17 12:30:59 -07005151 /* Initialize link parameters. User can change them with ethtool */
5152 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07005153 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08005154 adapter->hw.fc.requested_mode = e1000_fc_default;
5155 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005156 adapter->hw.phy.autoneg_advertised = 0x2f;
5157
5158 /* ring size defaults */
5159 adapter->rx_ring->count = 256;
5160 adapter->tx_ring->count = 256;
5161
5162 /*
5163 * Initial Wake on LAN setting - If APM wake is enabled in
5164 * the EEPROM, enable the ACPI Magic Packet filter
5165 */
5166 if (adapter->flags & FLAG_APME_IN_WUC) {
5167 /* APME bit in EEPROM is mapped to WUC.APME */
5168 eeprom_data = er32(WUC);
5169 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allana4f58f52009-06-02 11:29:18 +00005170 if (eeprom_data & E1000_WUC_PHY_WAKE)
5171 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005172 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
5173 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
5174 (adapter->hw.bus.func == 1))
5175 e1000_read_nvm(&adapter->hw,
5176 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
5177 else
5178 e1000_read_nvm(&adapter->hw,
5179 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
5180 }
5181
5182 /* fetch WoL from EEPROM */
5183 if (eeprom_data & eeprom_apme_mask)
5184 adapter->eeprom_wol |= E1000_WUFC_MAG;
5185
5186 /*
5187 * now that we have the eeprom settings, apply the special cases
5188 * where the eeprom may be wrong or the board simply won't support
5189 * wake on lan on a particular port
5190 */
5191 if (!(adapter->flags & FLAG_HAS_WOL))
5192 adapter->eeprom_wol = 0;
5193
5194 /* initialize the wol settings based on the eeprom settings */
5195 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00005196 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005197
Bruce Allan84527592008-11-21 17:00:22 -08005198 /* save off EEPROM version number */
5199 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
5200
Auke Kokbc7f75f2007-09-17 12:30:59 -07005201 /* reset the hardware with the new settings */
5202 e1000e_reset(adapter);
5203
Bruce Allanad680762008-03-28 09:15:03 -07005204 /*
5205 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005206 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005207 * under the control of the driver.
5208 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005209 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005210 e1000_get_hw_control(adapter);
5211
Auke Kokbc7f75f2007-09-17 12:30:59 -07005212 strcpy(netdev->name, "eth%d");
5213 err = register_netdev(netdev);
5214 if (err)
5215 goto err_register;
5216
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00005217 /* carrier off reporting is important to ethtool even BEFORE open */
5218 netif_carrier_off(netdev);
5219
Auke Kokbc7f75f2007-09-17 12:30:59 -07005220 e1000_print_device_info(adapter);
5221
5222 return 0;
5223
5224err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005225 if (!(adapter->flags & FLAG_HAS_AMT))
5226 e1000_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005227err_eeprom:
5228 if (!e1000_check_reset_block(&adapter->hw))
5229 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005230err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005231
Auke Kokbc7f75f2007-09-17 12:30:59 -07005232 kfree(adapter->tx_ring);
5233 kfree(adapter->rx_ring);
5234err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005235 if (adapter->hw.flash_address)
5236 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00005237 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005238err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005239 iounmap(adapter->hw.hw_addr);
5240err_ioremap:
5241 free_netdev(netdev);
5242err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07005243 pci_release_selected_regions(pdev,
5244 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005245err_pci_reg:
5246err_dma:
5247 pci_disable_device(pdev);
5248 return err;
5249}
5250
5251/**
5252 * e1000_remove - Device Removal Routine
5253 * @pdev: PCI device information struct
5254 *
5255 * e1000_remove is called by the PCI subsystem to alert the driver
5256 * that it should release a PCI device. The could be caused by a
5257 * Hot-Plug event, or because the driver is going to be removed from
5258 * memory.
5259 **/
5260static void __devexit e1000_remove(struct pci_dev *pdev)
5261{
5262 struct net_device *netdev = pci_get_drvdata(pdev);
5263 struct e1000_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005264 int err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005265
Bruce Allanad680762008-03-28 09:15:03 -07005266 /*
5267 * flush_scheduled work may reschedule our watchdog task, so
5268 * explicitly disable watchdog tasks from being rescheduled
5269 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005270 set_bit(__E1000_DOWN, &adapter->state);
5271 del_timer_sync(&adapter->watchdog_timer);
5272 del_timer_sync(&adapter->phy_info_timer);
5273
5274 flush_scheduled_work();
5275
Bruce Allanad680762008-03-28 09:15:03 -07005276 /*
5277 * Release control of h/w to f/w. If f/w is AMT enabled, this
5278 * would have already happened in close and is redundant.
5279 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005280 e1000_release_hw_control(adapter);
5281
5282 unregister_netdev(netdev);
5283
5284 if (!e1000_check_reset_block(&adapter->hw))
5285 e1000_phy_hw_reset(&adapter->hw);
5286
Bruce Allan4662e822008-08-26 18:37:06 -07005287 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005288 kfree(adapter->tx_ring);
5289 kfree(adapter->rx_ring);
5290
5291 iounmap(adapter->hw.hw_addr);
5292 if (adapter->hw.flash_address)
5293 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07005294 pci_release_selected_regions(pdev,
5295 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005296
5297 free_netdev(netdev);
5298
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005299 /* AER disable */
5300 err = pci_disable_pcie_error_reporting(pdev);
5301 if (err)
5302 dev_err(&pdev->dev,
5303 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
5304
Auke Kokbc7f75f2007-09-17 12:30:59 -07005305 pci_disable_device(pdev);
5306}
5307
5308/* PCI Error Recovery (ERS) */
5309static struct pci_error_handlers e1000_err_handler = {
5310 .error_detected = e1000_io_error_detected,
5311 .slot_reset = e1000_io_slot_reset,
5312 .resume = e1000_io_resume,
5313};
5314
5315static struct pci_device_id e1000_pci_tbl[] = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005316 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
5317 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
5318 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
5319 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
5320 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
5321 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07005322 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
5323 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
5324 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07005325
Auke Kokbc7f75f2007-09-17 12:30:59 -07005326 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
5327 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
5328 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
5329 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07005330
Auke Kokbc7f75f2007-09-17 12:30:59 -07005331 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
5332 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
5333 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07005334
Bruce Allan4662e822008-08-26 18:37:06 -07005335 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07005336 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00005337 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07005338
Auke Kokbc7f75f2007-09-17 12:30:59 -07005339 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
5340 board_80003es2lan },
5341 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
5342 board_80003es2lan },
5343 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
5344 board_80003es2lan },
5345 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
5346 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07005347
Auke Kokbc7f75f2007-09-17 12:30:59 -07005348 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
5349 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
5350 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
5351 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
5352 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
5353 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
5354 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07005355
Auke Kokbc7f75f2007-09-17 12:30:59 -07005356 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
5357 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
5358 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
5359 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
5360 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07005361 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005362 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
5363 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
5364 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
5365
5366 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
5367 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
5368 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07005369
Bruce Allanf4187b52008-08-26 18:36:50 -07005370 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
5371 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
5372
Bruce Allana4f58f52009-06-02 11:29:18 +00005373 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
5374 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
5375 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
5376 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
5377
Auke Kokbc7f75f2007-09-17 12:30:59 -07005378 { } /* terminate list */
5379};
5380MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
5381
5382/* PCI Device API Driver */
5383static struct pci_driver e1000_driver = {
5384 .name = e1000e_driver_name,
5385 .id_table = e1000_pci_tbl,
5386 .probe = e1000_probe,
5387 .remove = __devexit_p(e1000_remove),
5388#ifdef CONFIG_PM
Bruce Allanad680762008-03-28 09:15:03 -07005389 /* Power Management Hooks */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005390 .suspend = e1000_suspend,
5391 .resume = e1000_resume,
5392#endif
5393 .shutdown = e1000_shutdown,
5394 .err_handler = &e1000_err_handler
5395};
5396
5397/**
5398 * e1000_init_module - Driver Registration Routine
5399 *
5400 * e1000_init_module is the first routine called when the driver is
5401 * loaded. All it does is register with the PCI subsystem.
5402 **/
5403static int __init e1000_init_module(void)
5404{
5405 int ret;
5406 printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
5407 e1000e_driver_name, e1000e_driver_version);
Bruce Allanad680762008-03-28 09:15:03 -07005408 printk(KERN_INFO "%s: Copyright (c) 1999-2008 Intel Corporation.\n",
Auke Kokbc7f75f2007-09-17 12:30:59 -07005409 e1000e_driver_name);
5410 ret = pci_register_driver(&e1000_driver);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005411 pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name,
5412 PM_QOS_DEFAULT_VALUE);
5413
Auke Kokbc7f75f2007-09-17 12:30:59 -07005414 return ret;
5415}
5416module_init(e1000_init_module);
5417
5418/**
5419 * e1000_exit_module - Driver Exit Cleanup Routine
5420 *
5421 * e1000_exit_module is called just before the driver is removed
5422 * from memory.
5423 **/
5424static void __exit e1000_exit_module(void)
5425{
5426 pci_unregister_driver(&e1000_driver);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005427 pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005428}
5429module_exit(e1000_exit_module);
5430
5431
5432MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
5433MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
5434MODULE_LICENSE("GPL");
5435MODULE_VERSION(DRV_VERSION);
5436
5437/* e1000_main.c */