blob: ff9f9f1725e3e4aff73b1450e001c2377ba50706 [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;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000170 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700171
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
Eric Dumazet89d71a62009-10-13 05:34:20 +0000182 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700183 if (!skb) {
184 /* Better luck next round */
185 adapter->alloc_rx_buff_failed++;
186 break;
187 }
188
Auke Kokbc7f75f2007-09-17 12:30:59 -0700189 buffer_info->skb = skb;
190map_skb:
191 buffer_info->dma = pci_map_single(pdev, skb->data,
192 adapter->rx_buffer_len,
193 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700194 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700195 dev_err(&pdev->dev, "RX DMA map failed\n");
196 adapter->rx_dma_failed++;
197 break;
198 }
199
200 rx_desc = E1000_RX_DESC(*rx_ring, i);
201 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
202
203 i++;
204 if (i == rx_ring->count)
205 i = 0;
206 buffer_info = &rx_ring->buffer_info[i];
207 }
208
209 if (rx_ring->next_to_use != i) {
210 rx_ring->next_to_use = i;
211 if (i-- == 0)
212 i = (rx_ring->count - 1);
213
Bruce Allanad680762008-03-28 09:15:03 -0700214 /*
215 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -0700216 * know there are new descriptors to fetch. (Only
217 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -0700218 * such as IA-64).
219 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700220 wmb();
221 writel(i, adapter->hw.hw_addr + rx_ring->tail);
222 }
223}
224
225/**
226 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
227 * @adapter: address of board private structure
228 **/
229static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
230 int cleaned_count)
231{
232 struct net_device *netdev = adapter->netdev;
233 struct pci_dev *pdev = adapter->pdev;
234 union e1000_rx_desc_packet_split *rx_desc;
235 struct e1000_ring *rx_ring = adapter->rx_ring;
236 struct e1000_buffer *buffer_info;
237 struct e1000_ps_page *ps_page;
238 struct sk_buff *skb;
239 unsigned int i, j;
240
241 i = rx_ring->next_to_use;
242 buffer_info = &rx_ring->buffer_info[i];
243
244 while (cleaned_count--) {
245 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
246
247 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700248 ps_page = &buffer_info->ps_pages[j];
249 if (j >= adapter->rx_ps_pages) {
250 /* all unused desc entries get hw null ptr */
Al Viroa39fe742007-12-11 19:50:34 +0000251 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700252 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700253 }
Auke Kok47f44e42007-10-25 13:57:44 -0700254 if (!ps_page->page) {
255 ps_page->page = alloc_page(GFP_ATOMIC);
256 if (!ps_page->page) {
257 adapter->alloc_rx_buff_failed++;
258 goto no_buffers;
259 }
260 ps_page->dma = pci_map_page(pdev,
261 ps_page->page,
262 0, PAGE_SIZE,
263 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700264 if (pci_dma_mapping_error(pdev, ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700265 dev_err(&adapter->pdev->dev,
266 "RX DMA page map failed\n");
267 adapter->rx_dma_failed++;
268 goto no_buffers;
269 }
270 }
271 /*
272 * Refresh the desc even if buffer_addrs
273 * didn't change because each write-back
274 * erases this info.
275 */
276 rx_desc->read.buffer_addr[j+1] =
277 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700278 }
279
Eric Dumazet89d71a62009-10-13 05:34:20 +0000280 skb = netdev_alloc_skb_ip_align(netdev,
281 adapter->rx_ps_bsize0);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700282
283 if (!skb) {
284 adapter->alloc_rx_buff_failed++;
285 break;
286 }
287
Auke Kokbc7f75f2007-09-17 12:30:59 -0700288 buffer_info->skb = skb;
289 buffer_info->dma = pci_map_single(pdev, skb->data,
290 adapter->rx_ps_bsize0,
291 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700292 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700293 dev_err(&pdev->dev, "RX DMA map failed\n");
294 adapter->rx_dma_failed++;
295 /* cleanup skb */
296 dev_kfree_skb_any(skb);
297 buffer_info->skb = NULL;
298 break;
299 }
300
301 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
302
303 i++;
304 if (i == rx_ring->count)
305 i = 0;
306 buffer_info = &rx_ring->buffer_info[i];
307 }
308
309no_buffers:
310 if (rx_ring->next_to_use != i) {
311 rx_ring->next_to_use = i;
312
313 if (!(i--))
314 i = (rx_ring->count - 1);
315
Bruce Allanad680762008-03-28 09:15:03 -0700316 /*
317 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -0700318 * know there are new descriptors to fetch. (Only
319 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -0700320 * such as IA-64).
321 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700322 wmb();
Bruce Allanad680762008-03-28 09:15:03 -0700323 /*
324 * Hardware increments by 16 bytes, but packet split
Auke Kokbc7f75f2007-09-17 12:30:59 -0700325 * descriptors are 32 bytes...so we increment tail
326 * twice as much.
327 */
328 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
329 }
330}
331
332/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700333 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
334 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700335 * @cleaned_count: number of buffers to allocate this pass
336 **/
337
338static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
339 int cleaned_count)
340{
341 struct net_device *netdev = adapter->netdev;
342 struct pci_dev *pdev = adapter->pdev;
343 struct e1000_rx_desc *rx_desc;
344 struct e1000_ring *rx_ring = adapter->rx_ring;
345 struct e1000_buffer *buffer_info;
346 struct sk_buff *skb;
347 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000348 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700349
350 i = rx_ring->next_to_use;
351 buffer_info = &rx_ring->buffer_info[i];
352
353 while (cleaned_count--) {
354 skb = buffer_info->skb;
355 if (skb) {
356 skb_trim(skb, 0);
357 goto check_page;
358 }
359
Eric Dumazet89d71a62009-10-13 05:34:20 +0000360 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700361 if (unlikely(!skb)) {
362 /* Better luck next round */
363 adapter->alloc_rx_buff_failed++;
364 break;
365 }
366
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700367 buffer_info->skb = skb;
368check_page:
369 /* allocate a new page if necessary */
370 if (!buffer_info->page) {
371 buffer_info->page = alloc_page(GFP_ATOMIC);
372 if (unlikely(!buffer_info->page)) {
373 adapter->alloc_rx_buff_failed++;
374 break;
375 }
376 }
377
378 if (!buffer_info->dma)
379 buffer_info->dma = pci_map_page(pdev,
380 buffer_info->page, 0,
381 PAGE_SIZE,
382 PCI_DMA_FROMDEVICE);
383
384 rx_desc = E1000_RX_DESC(*rx_ring, i);
385 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
386
387 if (unlikely(++i == rx_ring->count))
388 i = 0;
389 buffer_info = &rx_ring->buffer_info[i];
390 }
391
392 if (likely(rx_ring->next_to_use != i)) {
393 rx_ring->next_to_use = i;
394 if (unlikely(i-- == 0))
395 i = (rx_ring->count - 1);
396
397 /* Force memory writes to complete before letting h/w
398 * know there are new descriptors to fetch. (Only
399 * applicable for weak-ordered memory model archs,
400 * such as IA-64). */
401 wmb();
402 writel(i, adapter->hw.hw_addr + rx_ring->tail);
403 }
404}
405
406/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700407 * e1000_clean_rx_irq - Send received data up the network stack; legacy
408 * @adapter: board private structure
409 *
410 * the return value indicates whether actual cleaning was done, there
411 * is no guarantee that everything was cleaned
412 **/
413static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
414 int *work_done, int work_to_do)
415{
416 struct net_device *netdev = adapter->netdev;
417 struct pci_dev *pdev = adapter->pdev;
418 struct e1000_ring *rx_ring = adapter->rx_ring;
419 struct e1000_rx_desc *rx_desc, *next_rxd;
420 struct e1000_buffer *buffer_info, *next_buffer;
421 u32 length;
422 unsigned int i;
423 int cleaned_count = 0;
424 bool cleaned = 0;
425 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
426
427 i = rx_ring->next_to_clean;
428 rx_desc = E1000_RX_DESC(*rx_ring, i);
429 buffer_info = &rx_ring->buffer_info[i];
430
431 while (rx_desc->status & E1000_RXD_STAT_DD) {
432 struct sk_buff *skb;
433 u8 status;
434
435 if (*work_done >= work_to_do)
436 break;
437 (*work_done)++;
438
439 status = rx_desc->status;
440 skb = buffer_info->skb;
441 buffer_info->skb = NULL;
442
443 prefetch(skb->data - NET_IP_ALIGN);
444
445 i++;
446 if (i == rx_ring->count)
447 i = 0;
448 next_rxd = E1000_RX_DESC(*rx_ring, i);
449 prefetch(next_rxd);
450
451 next_buffer = &rx_ring->buffer_info[i];
452
453 cleaned = 1;
454 cleaned_count++;
455 pci_unmap_single(pdev,
456 buffer_info->dma,
457 adapter->rx_buffer_len,
458 PCI_DMA_FROMDEVICE);
459 buffer_info->dma = 0;
460
461 length = le16_to_cpu(rx_desc->length);
462
463 /* !EOP means multiple descriptors were used to store a single
464 * packet, also make sure the frame isn't just CRC only */
465 if (!(status & E1000_RXD_STAT_EOP) || (length <= 4)) {
466 /* All receives must fit into a single buffer */
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700467 e_dbg("%s: Receive packet consumed multiple buffers\n",
468 netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700469 /* recycle */
470 buffer_info->skb = skb;
471 goto next_desc;
472 }
473
474 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
475 /* recycle */
476 buffer_info->skb = skb;
477 goto next_desc;
478 }
479
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000480 /* adjust length to remove Ethernet CRC */
481 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
482 length -= 4;
483
Auke Kokbc7f75f2007-09-17 12:30:59 -0700484 total_rx_bytes += length;
485 total_rx_packets++;
486
Bruce Allanad680762008-03-28 09:15:03 -0700487 /*
488 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700489 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700490 * of reassembly being done in the stack
491 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700492 if (length < copybreak) {
493 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000494 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700495 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700496 skb_copy_to_linear_data_offset(new_skb,
497 -NET_IP_ALIGN,
498 (skb->data -
499 NET_IP_ALIGN),
500 (length +
501 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700502 /* save the skb in buffer_info as good */
503 buffer_info->skb = skb;
504 skb = new_skb;
505 }
506 /* else just continue with the old one */
507 }
508 /* end copybreak code */
509 skb_put(skb, length);
510
511 /* Receive Checksum Offload */
512 e1000_rx_checksum(adapter,
513 (u32)(status) |
514 ((u32)(rx_desc->errors) << 24),
515 le16_to_cpu(rx_desc->csum), skb);
516
517 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
518
519next_desc:
520 rx_desc->status = 0;
521
522 /* return some buffers to hardware, one at a time is too slow */
523 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
524 adapter->alloc_rx_buf(adapter, cleaned_count);
525 cleaned_count = 0;
526 }
527
528 /* use prefetched values */
529 rx_desc = next_rxd;
530 buffer_info = next_buffer;
531 }
532 rx_ring->next_to_clean = i;
533
534 cleaned_count = e1000_desc_unused(rx_ring);
535 if (cleaned_count)
536 adapter->alloc_rx_buf(adapter, cleaned_count);
537
Auke Kokbc7f75f2007-09-17 12:30:59 -0700538 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700539 adapter->total_rx_packets += total_rx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +0000540 netdev->stats.rx_bytes += total_rx_bytes;
541 netdev->stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700542 return cleaned;
543}
544
Auke Kokbc7f75f2007-09-17 12:30:59 -0700545static void e1000_put_txbuf(struct e1000_adapter *adapter,
546 struct e1000_buffer *buffer_info)
547{
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -0800548 buffer_info->dma = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700549 if (buffer_info->skb) {
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -0800550 skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
551 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700552 dev_kfree_skb_any(buffer_info->skb);
553 buffer_info->skb = NULL;
554 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000555 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700556}
557
558static void e1000_print_tx_hang(struct e1000_adapter *adapter)
559{
560 struct e1000_ring *tx_ring = adapter->tx_ring;
561 unsigned int i = tx_ring->next_to_clean;
562 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
563 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700564
565 /* detected Tx unit hang */
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700566 e_err("Detected Tx Unit Hang:\n"
567 " TDH <%x>\n"
568 " TDT <%x>\n"
569 " next_to_use <%x>\n"
570 " next_to_clean <%x>\n"
571 "buffer_info[next_to_clean]:\n"
572 " time_stamp <%lx>\n"
573 " next_to_watch <%x>\n"
574 " jiffies <%lx>\n"
575 " next_to_watch.status <%x>\n",
576 readl(adapter->hw.hw_addr + tx_ring->head),
577 readl(adapter->hw.hw_addr + tx_ring->tail),
578 tx_ring->next_to_use,
579 tx_ring->next_to_clean,
580 tx_ring->buffer_info[eop].time_stamp,
581 eop,
582 jiffies,
583 eop_desc->upper.fields.status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700584}
585
586/**
587 * e1000_clean_tx_irq - Reclaim resources after transmit completes
588 * @adapter: board private structure
589 *
590 * the return value indicates whether actual cleaning was done, there
591 * is no guarantee that everything was cleaned
592 **/
593static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
594{
595 struct net_device *netdev = adapter->netdev;
596 struct e1000_hw *hw = &adapter->hw;
597 struct e1000_ring *tx_ring = adapter->tx_ring;
598 struct e1000_tx_desc *tx_desc, *eop_desc;
599 struct e1000_buffer *buffer_info;
600 unsigned int i, eop;
601 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
603
604 i = tx_ring->next_to_clean;
605 eop = tx_ring->buffer_info[i].next_to_watch;
606 eop_desc = E1000_TX_DESC(*tx_ring, eop);
607
Alexander Duyck12d04a32009-03-25 22:05:03 +0000608 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
609 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +0000610 bool cleaned = false;
611 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700612 tx_desc = E1000_TX_DESC(*tx_ring, i);
613 buffer_info = &tx_ring->buffer_info[i];
614 cleaned = (i == eop);
615
616 if (cleaned) {
617 struct sk_buff *skb = buffer_info->skb;
618 unsigned int segs, bytecount;
619 segs = skb_shinfo(skb)->gso_segs ?: 1;
620 /* multiply data chunks by size of headers */
621 bytecount = ((segs - 1) * skb_headlen(skb)) +
622 skb->len;
623 total_tx_packets += segs;
624 total_tx_bytes += bytecount;
625 }
626
627 e1000_put_txbuf(adapter, buffer_info);
628 tx_desc->upper.data = 0;
629
630 i++;
631 if (i == tx_ring->count)
632 i = 0;
633 }
634
635 eop = tx_ring->buffer_info[i].next_to_watch;
636 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700637 }
638
639 tx_ring->next_to_clean = i;
640
641#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +0000642 if (count && netif_carrier_ok(netdev) &&
643 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644 /* Make sure that anybody stopping the queue after this
645 * sees the new next_to_clean.
646 */
647 smp_mb();
648
649 if (netif_queue_stopped(netdev) &&
650 !(test_bit(__E1000_DOWN, &adapter->state))) {
651 netif_wake_queue(netdev);
652 ++adapter->restart_queue;
653 }
654 }
655
656 if (adapter->detect_tx_hung) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000657 /* Detect a transmit hang in hardware, this serializes the
658 * check with the clearing of time_stamp and movement of i */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700659 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +0000660 if (tx_ring->buffer_info[i].time_stamp &&
661 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Auke Kokbc7f75f2007-09-17 12:30:59 -0700662 + (adapter->tx_timeout_factor * HZ))
Bruce Allanad680762008-03-28 09:15:03 -0700663 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700664 e1000_print_tx_hang(adapter);
665 netif_stop_queue(netdev);
666 }
667 }
668 adapter->total_tx_bytes += total_tx_bytes;
669 adapter->total_tx_packets += total_tx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +0000670 netdev->stats.tx_bytes += total_tx_bytes;
671 netdev->stats.tx_packets += total_tx_packets;
Alexander Duyck12d04a32009-03-25 22:05:03 +0000672 return (count < tx_ring->count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700673}
674
675/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700676 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
677 * @adapter: board private structure
678 *
679 * the return value indicates whether actual cleaning was done, there
680 * is no guarantee that everything was cleaned
681 **/
682static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
683 int *work_done, int work_to_do)
684{
685 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
686 struct net_device *netdev = adapter->netdev;
687 struct pci_dev *pdev = adapter->pdev;
688 struct e1000_ring *rx_ring = adapter->rx_ring;
689 struct e1000_buffer *buffer_info, *next_buffer;
690 struct e1000_ps_page *ps_page;
691 struct sk_buff *skb;
692 unsigned int i, j;
693 u32 length, staterr;
694 int cleaned_count = 0;
695 bool cleaned = 0;
696 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
697
698 i = rx_ring->next_to_clean;
699 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
700 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
701 buffer_info = &rx_ring->buffer_info[i];
702
703 while (staterr & E1000_RXD_STAT_DD) {
704 if (*work_done >= work_to_do)
705 break;
706 (*work_done)++;
707 skb = buffer_info->skb;
708
709 /* in the packet split case this is header only */
710 prefetch(skb->data - NET_IP_ALIGN);
711
712 i++;
713 if (i == rx_ring->count)
714 i = 0;
715 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
716 prefetch(next_rxd);
717
718 next_buffer = &rx_ring->buffer_info[i];
719
720 cleaned = 1;
721 cleaned_count++;
722 pci_unmap_single(pdev, buffer_info->dma,
723 adapter->rx_ps_bsize0,
724 PCI_DMA_FROMDEVICE);
725 buffer_info->dma = 0;
726
727 if (!(staterr & E1000_RXD_STAT_EOP)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700728 e_dbg("%s: Packet Split buffers didn't pick up the "
729 "full packet\n", netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700730 dev_kfree_skb_irq(skb);
731 goto next_desc;
732 }
733
734 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
735 dev_kfree_skb_irq(skb);
736 goto next_desc;
737 }
738
739 length = le16_to_cpu(rx_desc->wb.middle.length0);
740
741 if (!length) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700742 e_dbg("%s: Last part of the packet spanning multiple "
743 "descriptors\n", netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700744 dev_kfree_skb_irq(skb);
745 goto next_desc;
746 }
747
748 /* Good Receive */
749 skb_put(skb, length);
750
751 {
Bruce Allanad680762008-03-28 09:15:03 -0700752 /*
753 * this looks ugly, but it seems compiler issues make it
754 * more efficient than reusing j
755 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700756 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
757
Bruce Allanad680762008-03-28 09:15:03 -0700758 /*
759 * page alloc/put takes too long and effects small packet
760 * throughput, so unsplit small packets and save the alloc/put
761 * only valid in softirq (napi) context to call kmap_*
762 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700763 if (l1 && (l1 <= copybreak) &&
764 ((length + l1) <= adapter->rx_ps_bsize0)) {
765 u8 *vaddr;
766
Auke Kok47f44e42007-10-25 13:57:44 -0700767 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700768
Bruce Allanad680762008-03-28 09:15:03 -0700769 /*
770 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -0700771 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -0700772 * very long
773 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700774 pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
775 PAGE_SIZE, PCI_DMA_FROMDEVICE);
776 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
777 memcpy(skb_tail_pointer(skb), vaddr, l1);
778 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
779 pci_dma_sync_single_for_device(pdev, ps_page->dma,
780 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kok140a7482007-10-25 13:57:58 -0700781
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000782 /* remove the CRC */
783 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
784 l1 -= 4;
785
Auke Kokbc7f75f2007-09-17 12:30:59 -0700786 skb_put(skb, l1);
787 goto copydone;
788 } /* if */
789 }
790
791 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
792 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
793 if (!length)
794 break;
795
Auke Kok47f44e42007-10-25 13:57:44 -0700796 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700797 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
798 PCI_DMA_FROMDEVICE);
799 ps_page->dma = 0;
800 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
801 ps_page->page = NULL;
802 skb->len += length;
803 skb->data_len += length;
804 skb->truesize += length;
805 }
806
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000807 /* strip the ethernet crc, problem is we're using pages now so
808 * this whole operation can get a little cpu intensive
809 */
810 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
811 pskb_trim(skb, skb->len - 4);
812
Auke Kokbc7f75f2007-09-17 12:30:59 -0700813copydone:
814 total_rx_bytes += skb->len;
815 total_rx_packets++;
816
817 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
818 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
819
820 if (rx_desc->wb.upper.header_status &
821 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
822 adapter->rx_hdr_split++;
823
824 e1000_receive_skb(adapter, netdev, skb,
825 staterr, rx_desc->wb.middle.vlan);
826
827next_desc:
828 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
829 buffer_info->skb = NULL;
830
831 /* return some buffers to hardware, one at a time is too slow */
832 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
833 adapter->alloc_rx_buf(adapter, cleaned_count);
834 cleaned_count = 0;
835 }
836
837 /* use prefetched values */
838 rx_desc = next_rxd;
839 buffer_info = next_buffer;
840
841 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
842 }
843 rx_ring->next_to_clean = i;
844
845 cleaned_count = e1000_desc_unused(rx_ring);
846 if (cleaned_count)
847 adapter->alloc_rx_buf(adapter, cleaned_count);
848
Auke Kokbc7f75f2007-09-17 12:30:59 -0700849 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700850 adapter->total_rx_packets += total_rx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +0000851 netdev->stats.rx_bytes += total_rx_bytes;
852 netdev->stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700853 return cleaned;
854}
855
856/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700857 * e1000_consume_page - helper function
858 **/
859static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
860 u16 length)
861{
862 bi->page = NULL;
863 skb->len += length;
864 skb->data_len += length;
865 skb->truesize += length;
866}
867
868/**
869 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
870 * @adapter: board private structure
871 *
872 * the return value indicates whether actual cleaning was done, there
873 * is no guarantee that everything was cleaned
874 **/
875
876static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
877 int *work_done, int work_to_do)
878{
879 struct net_device *netdev = adapter->netdev;
880 struct pci_dev *pdev = adapter->pdev;
881 struct e1000_ring *rx_ring = adapter->rx_ring;
882 struct e1000_rx_desc *rx_desc, *next_rxd;
883 struct e1000_buffer *buffer_info, *next_buffer;
884 u32 length;
885 unsigned int i;
886 int cleaned_count = 0;
887 bool cleaned = false;
888 unsigned int total_rx_bytes=0, total_rx_packets=0;
889
890 i = rx_ring->next_to_clean;
891 rx_desc = E1000_RX_DESC(*rx_ring, i);
892 buffer_info = &rx_ring->buffer_info[i];
893
894 while (rx_desc->status & E1000_RXD_STAT_DD) {
895 struct sk_buff *skb;
896 u8 status;
897
898 if (*work_done >= work_to_do)
899 break;
900 (*work_done)++;
901
902 status = rx_desc->status;
903 skb = buffer_info->skb;
904 buffer_info->skb = NULL;
905
906 ++i;
907 if (i == rx_ring->count)
908 i = 0;
909 next_rxd = E1000_RX_DESC(*rx_ring, i);
910 prefetch(next_rxd);
911
912 next_buffer = &rx_ring->buffer_info[i];
913
914 cleaned = true;
915 cleaned_count++;
916 pci_unmap_page(pdev, buffer_info->dma, PAGE_SIZE,
917 PCI_DMA_FROMDEVICE);
918 buffer_info->dma = 0;
919
920 length = le16_to_cpu(rx_desc->length);
921
922 /* errors is only valid for DD + EOP descriptors */
923 if (unlikely((status & E1000_RXD_STAT_EOP) &&
924 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
925 /* recycle both page and skb */
926 buffer_info->skb = skb;
927 /* an error means any chain goes out the window
928 * too */
929 if (rx_ring->rx_skb_top)
930 dev_kfree_skb(rx_ring->rx_skb_top);
931 rx_ring->rx_skb_top = NULL;
932 goto next_desc;
933 }
934
935#define rxtop rx_ring->rx_skb_top
936 if (!(status & E1000_RXD_STAT_EOP)) {
937 /* this descriptor is only the beginning (or middle) */
938 if (!rxtop) {
939 /* this is the beginning of a chain */
940 rxtop = skb;
941 skb_fill_page_desc(rxtop, 0, buffer_info->page,
942 0, length);
943 } else {
944 /* this is the middle of a chain */
945 skb_fill_page_desc(rxtop,
946 skb_shinfo(rxtop)->nr_frags,
947 buffer_info->page, 0, length);
948 /* re-use the skb, only consumed the page */
949 buffer_info->skb = skb;
950 }
951 e1000_consume_page(buffer_info, rxtop, length);
952 goto next_desc;
953 } else {
954 if (rxtop) {
955 /* end of the chain */
956 skb_fill_page_desc(rxtop,
957 skb_shinfo(rxtop)->nr_frags,
958 buffer_info->page, 0, length);
959 /* re-use the current skb, we only consumed the
960 * page */
961 buffer_info->skb = skb;
962 skb = rxtop;
963 rxtop = NULL;
964 e1000_consume_page(buffer_info, skb, length);
965 } else {
966 /* no chain, got EOP, this buf is the packet
967 * copybreak to save the put_page/alloc_page */
968 if (length <= copybreak &&
969 skb_tailroom(skb) >= length) {
970 u8 *vaddr;
971 vaddr = kmap_atomic(buffer_info->page,
972 KM_SKB_DATA_SOFTIRQ);
973 memcpy(skb_tail_pointer(skb), vaddr,
974 length);
975 kunmap_atomic(vaddr,
976 KM_SKB_DATA_SOFTIRQ);
977 /* re-use the page, so don't erase
978 * buffer_info->page */
979 skb_put(skb, length);
980 } else {
981 skb_fill_page_desc(skb, 0,
982 buffer_info->page, 0,
983 length);
984 e1000_consume_page(buffer_info, skb,
985 length);
986 }
987 }
988 }
989
990 /* Receive Checksum Offload XXX recompute due to CRC strip? */
991 e1000_rx_checksum(adapter,
992 (u32)(status) |
993 ((u32)(rx_desc->errors) << 24),
994 le16_to_cpu(rx_desc->csum), skb);
995
996 /* probably a little skewed due to removing CRC */
997 total_rx_bytes += skb->len;
998 total_rx_packets++;
999
1000 /* eth type trans needs skb->data to point to something */
1001 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001002 e_err("pskb_may_pull failed.\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001003 dev_kfree_skb(skb);
1004 goto next_desc;
1005 }
1006
1007 e1000_receive_skb(adapter, netdev, skb, status,
1008 rx_desc->special);
1009
1010next_desc:
1011 rx_desc->status = 0;
1012
1013 /* return some buffers to hardware, one at a time is too slow */
1014 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1015 adapter->alloc_rx_buf(adapter, cleaned_count);
1016 cleaned_count = 0;
1017 }
1018
1019 /* use prefetched values */
1020 rx_desc = next_rxd;
1021 buffer_info = next_buffer;
1022 }
1023 rx_ring->next_to_clean = i;
1024
1025 cleaned_count = e1000_desc_unused(rx_ring);
1026 if (cleaned_count)
1027 adapter->alloc_rx_buf(adapter, cleaned_count);
1028
1029 adapter->total_rx_bytes += total_rx_bytes;
1030 adapter->total_rx_packets += total_rx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +00001031 netdev->stats.rx_bytes += total_rx_bytes;
1032 netdev->stats.rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001033 return cleaned;
1034}
1035
1036/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1038 * @adapter: board private structure
1039 **/
1040static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1041{
1042 struct e1000_ring *rx_ring = adapter->rx_ring;
1043 struct e1000_buffer *buffer_info;
1044 struct e1000_ps_page *ps_page;
1045 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001046 unsigned int i, j;
1047
1048 /* Free all the Rx ring sk_buffs */
1049 for (i = 0; i < rx_ring->count; i++) {
1050 buffer_info = &rx_ring->buffer_info[i];
1051 if (buffer_info->dma) {
1052 if (adapter->clean_rx == e1000_clean_rx_irq)
1053 pci_unmap_single(pdev, buffer_info->dma,
1054 adapter->rx_buffer_len,
1055 PCI_DMA_FROMDEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001056 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1057 pci_unmap_page(pdev, buffer_info->dma,
1058 PAGE_SIZE,
1059 PCI_DMA_FROMDEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001060 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1061 pci_unmap_single(pdev, buffer_info->dma,
1062 adapter->rx_ps_bsize0,
1063 PCI_DMA_FROMDEVICE);
1064 buffer_info->dma = 0;
1065 }
1066
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001067 if (buffer_info->page) {
1068 put_page(buffer_info->page);
1069 buffer_info->page = NULL;
1070 }
1071
Auke Kokbc7f75f2007-09-17 12:30:59 -07001072 if (buffer_info->skb) {
1073 dev_kfree_skb(buffer_info->skb);
1074 buffer_info->skb = NULL;
1075 }
1076
1077 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001078 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001079 if (!ps_page->page)
1080 break;
1081 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
1082 PCI_DMA_FROMDEVICE);
1083 ps_page->dma = 0;
1084 put_page(ps_page->page);
1085 ps_page->page = NULL;
1086 }
1087 }
1088
1089 /* there also may be some cached data from a chained receive */
1090 if (rx_ring->rx_skb_top) {
1091 dev_kfree_skb(rx_ring->rx_skb_top);
1092 rx_ring->rx_skb_top = NULL;
1093 }
1094
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095 /* Zero out the descriptor ring */
1096 memset(rx_ring->desc, 0, rx_ring->size);
1097
1098 rx_ring->next_to_clean = 0;
1099 rx_ring->next_to_use = 0;
1100
1101 writel(0, adapter->hw.hw_addr + rx_ring->head);
1102 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1103}
1104
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001105static void e1000e_downshift_workaround(struct work_struct *work)
1106{
1107 struct e1000_adapter *adapter = container_of(work,
1108 struct e1000_adapter, downshift_task);
1109
1110 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1111}
1112
Auke Kokbc7f75f2007-09-17 12:30:59 -07001113/**
1114 * e1000_intr_msi - Interrupt Handler
1115 * @irq: interrupt number
1116 * @data: pointer to a network interface device structure
1117 **/
1118static irqreturn_t e1000_intr_msi(int irq, void *data)
1119{
1120 struct net_device *netdev = data;
1121 struct e1000_adapter *adapter = netdev_priv(netdev);
1122 struct e1000_hw *hw = &adapter->hw;
1123 u32 icr = er32(ICR);
1124
Bruce Allanad680762008-03-28 09:15:03 -07001125 /*
1126 * read ICR disables interrupts using IAM
1127 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128
dave graham573cca82009-02-10 12:52:05 +00001129 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001130 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001131 /*
1132 * ICH8 workaround-- Call gig speed drop workaround on cable
1133 * disconnect (LSC) before accessing any PHY registers
1134 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001135 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1136 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001137 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138
Bruce Allanad680762008-03-28 09:15:03 -07001139 /*
1140 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001141 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001142 * adapter in watchdog
1143 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144 if (netif_carrier_ok(netdev) &&
1145 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1146 /* disable receives */
1147 u32 rctl = er32(RCTL);
1148 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001149 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001150 }
1151 /* guard against interrupt when we're going down */
1152 if (!test_bit(__E1000_DOWN, &adapter->state))
1153 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1154 }
1155
Ben Hutchings288379f2009-01-19 16:43:59 -08001156 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001157 adapter->total_tx_bytes = 0;
1158 adapter->total_tx_packets = 0;
1159 adapter->total_rx_bytes = 0;
1160 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001161 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001162 }
1163
1164 return IRQ_HANDLED;
1165}
1166
1167/**
1168 * e1000_intr - Interrupt Handler
1169 * @irq: interrupt number
1170 * @data: pointer to a network interface device structure
1171 **/
1172static irqreturn_t e1000_intr(int irq, void *data)
1173{
1174 struct net_device *netdev = data;
1175 struct e1000_adapter *adapter = netdev_priv(netdev);
1176 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001177 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001178
Bruce Allana68ea772009-11-20 23:23:16 +00001179 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180 return IRQ_NONE; /* Not our interrupt */
1181
Bruce Allanad680762008-03-28 09:15:03 -07001182 /*
1183 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1184 * not set, then the adapter didn't send an interrupt
1185 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186 if (!(icr & E1000_ICR_INT_ASSERTED))
1187 return IRQ_NONE;
1188
Bruce Allanad680762008-03-28 09:15:03 -07001189 /*
1190 * Interrupt Auto-Mask...upon reading ICR,
1191 * interrupts are masked. No need for the
1192 * IMC write
1193 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001194
dave graham573cca82009-02-10 12:52:05 +00001195 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001196 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001197 /*
1198 * ICH8 workaround-- Call gig speed drop workaround on cable
1199 * disconnect (LSC) before accessing any PHY registers
1200 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001201 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1202 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001203 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001204
Bruce Allanad680762008-03-28 09:15:03 -07001205 /*
1206 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001207 * For packet buffer work-around on link down event;
1208 * disable receives here in the ISR and
1209 * reset adapter in watchdog
1210 */
1211 if (netif_carrier_ok(netdev) &&
1212 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1213 /* disable receives */
1214 rctl = er32(RCTL);
1215 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001216 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217 }
1218 /* guard against interrupt when we're going down */
1219 if (!test_bit(__E1000_DOWN, &adapter->state))
1220 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1221 }
1222
Ben Hutchings288379f2009-01-19 16:43:59 -08001223 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001224 adapter->total_tx_bytes = 0;
1225 adapter->total_tx_packets = 0;
1226 adapter->total_rx_bytes = 0;
1227 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001228 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001229 }
1230
1231 return IRQ_HANDLED;
1232}
1233
Bruce Allan4662e822008-08-26 18:37:06 -07001234static irqreturn_t e1000_msix_other(int irq, void *data)
1235{
1236 struct net_device *netdev = data;
1237 struct e1000_adapter *adapter = netdev_priv(netdev);
1238 struct e1000_hw *hw = &adapter->hw;
1239 u32 icr = er32(ICR);
1240
1241 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001242 if (!test_bit(__E1000_DOWN, &adapter->state))
1243 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001244 return IRQ_NONE;
1245 }
1246
1247 if (icr & adapter->eiac_mask)
1248 ew32(ICS, (icr & adapter->eiac_mask));
1249
1250 if (icr & E1000_ICR_OTHER) {
1251 if (!(icr & E1000_ICR_LSC))
1252 goto no_link_interrupt;
1253 hw->mac.get_link_status = 1;
1254 /* guard against interrupt when we're going down */
1255 if (!test_bit(__E1000_DOWN, &adapter->state))
1256 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1257 }
1258
1259no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001260 if (!test_bit(__E1000_DOWN, &adapter->state))
1261 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001262
1263 return IRQ_HANDLED;
1264}
1265
1266
1267static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1268{
1269 struct net_device *netdev = data;
1270 struct e1000_adapter *adapter = netdev_priv(netdev);
1271 struct e1000_hw *hw = &adapter->hw;
1272 struct e1000_ring *tx_ring = adapter->tx_ring;
1273
1274
1275 adapter->total_tx_bytes = 0;
1276 adapter->total_tx_packets = 0;
1277
1278 if (!e1000_clean_tx_irq(adapter))
1279 /* Ring was not completely cleaned, so fire another interrupt */
1280 ew32(ICS, tx_ring->ims_val);
1281
1282 return IRQ_HANDLED;
1283}
1284
1285static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1286{
1287 struct net_device *netdev = data;
1288 struct e1000_adapter *adapter = netdev_priv(netdev);
1289
1290 /* Write the ITR value calculated at the end of the
1291 * previous interrupt.
1292 */
1293 if (adapter->rx_ring->set_itr) {
1294 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1295 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1296 adapter->rx_ring->set_itr = 0;
1297 }
1298
Ben Hutchings288379f2009-01-19 16:43:59 -08001299 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001300 adapter->total_rx_bytes = 0;
1301 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001302 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001303 }
1304 return IRQ_HANDLED;
1305}
1306
1307/**
1308 * e1000_configure_msix - Configure MSI-X hardware
1309 *
1310 * e1000_configure_msix sets up the hardware to properly
1311 * generate MSI-X interrupts.
1312 **/
1313static void e1000_configure_msix(struct e1000_adapter *adapter)
1314{
1315 struct e1000_hw *hw = &adapter->hw;
1316 struct e1000_ring *rx_ring = adapter->rx_ring;
1317 struct e1000_ring *tx_ring = adapter->tx_ring;
1318 int vector = 0;
1319 u32 ctrl_ext, ivar = 0;
1320
1321 adapter->eiac_mask = 0;
1322
1323 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1324 if (hw->mac.type == e1000_82574) {
1325 u32 rfctl = er32(RFCTL);
1326 rfctl |= E1000_RFCTL_ACK_DIS;
1327 ew32(RFCTL, rfctl);
1328 }
1329
1330#define E1000_IVAR_INT_ALLOC_VALID 0x8
1331 /* Configure Rx vector */
1332 rx_ring->ims_val = E1000_IMS_RXQ0;
1333 adapter->eiac_mask |= rx_ring->ims_val;
1334 if (rx_ring->itr_val)
1335 writel(1000000000 / (rx_ring->itr_val * 256),
1336 hw->hw_addr + rx_ring->itr_register);
1337 else
1338 writel(1, hw->hw_addr + rx_ring->itr_register);
1339 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1340
1341 /* Configure Tx vector */
1342 tx_ring->ims_val = E1000_IMS_TXQ0;
1343 vector++;
1344 if (tx_ring->itr_val)
1345 writel(1000000000 / (tx_ring->itr_val * 256),
1346 hw->hw_addr + tx_ring->itr_register);
1347 else
1348 writel(1, hw->hw_addr + tx_ring->itr_register);
1349 adapter->eiac_mask |= tx_ring->ims_val;
1350 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1351
1352 /* set vector for Other Causes, e.g. link changes */
1353 vector++;
1354 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1355 if (rx_ring->itr_val)
1356 writel(1000000000 / (rx_ring->itr_val * 256),
1357 hw->hw_addr + E1000_EITR_82574(vector));
1358 else
1359 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1360
1361 /* Cause Tx interrupts on every write back */
1362 ivar |= (1 << 31);
1363
1364 ew32(IVAR, ivar);
1365
1366 /* enable MSI-X PBA support */
1367 ctrl_ext = er32(CTRL_EXT);
1368 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1369
1370 /* Auto-Mask Other interrupts upon ICR read */
1371#define E1000_EIAC_MASK_82574 0x01F00000
1372 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1373 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1374 ew32(CTRL_EXT, ctrl_ext);
1375 e1e_flush();
1376}
1377
1378void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1379{
1380 if (adapter->msix_entries) {
1381 pci_disable_msix(adapter->pdev);
1382 kfree(adapter->msix_entries);
1383 adapter->msix_entries = NULL;
1384 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1385 pci_disable_msi(adapter->pdev);
1386 adapter->flags &= ~FLAG_MSI_ENABLED;
1387 }
1388
1389 return;
1390}
1391
1392/**
1393 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1394 *
1395 * Attempt to configure interrupts using the best available
1396 * capabilities of the hardware and kernel.
1397 **/
1398void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1399{
1400 int err;
1401 int numvecs, i;
1402
1403
1404 switch (adapter->int_mode) {
1405 case E1000E_INT_MODE_MSIX:
1406 if (adapter->flags & FLAG_HAS_MSIX) {
1407 numvecs = 3; /* RxQ0, TxQ0 and other */
1408 adapter->msix_entries = kcalloc(numvecs,
1409 sizeof(struct msix_entry),
1410 GFP_KERNEL);
1411 if (adapter->msix_entries) {
1412 for (i = 0; i < numvecs; i++)
1413 adapter->msix_entries[i].entry = i;
1414
1415 err = pci_enable_msix(adapter->pdev,
1416 adapter->msix_entries,
1417 numvecs);
1418 if (err == 0)
1419 return;
1420 }
1421 /* MSI-X failed, so fall through and try MSI */
1422 e_err("Failed to initialize MSI-X interrupts. "
1423 "Falling back to MSI interrupts.\n");
1424 e1000e_reset_interrupt_capability(adapter);
1425 }
1426 adapter->int_mode = E1000E_INT_MODE_MSI;
1427 /* Fall through */
1428 case E1000E_INT_MODE_MSI:
1429 if (!pci_enable_msi(adapter->pdev)) {
1430 adapter->flags |= FLAG_MSI_ENABLED;
1431 } else {
1432 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1433 e_err("Failed to initialize MSI interrupts. Falling "
1434 "back to legacy interrupts.\n");
1435 }
1436 /* Fall through */
1437 case E1000E_INT_MODE_LEGACY:
1438 /* Don't do anything; this is the system default */
1439 break;
1440 }
1441
1442 return;
1443}
1444
1445/**
1446 * e1000_request_msix - Initialize MSI-X interrupts
1447 *
1448 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1449 * kernel.
1450 **/
1451static int e1000_request_msix(struct e1000_adapter *adapter)
1452{
1453 struct net_device *netdev = adapter->netdev;
1454 int err = 0, vector = 0;
1455
1456 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001457 sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001458 else
1459 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1460 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001461 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001462 netdev);
1463 if (err)
1464 goto out;
1465 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1466 adapter->rx_ring->itr_val = adapter->itr;
1467 vector++;
1468
1469 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001470 sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001471 else
1472 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1473 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001474 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001475 netdev);
1476 if (err)
1477 goto out;
1478 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1479 adapter->tx_ring->itr_val = adapter->itr;
1480 vector++;
1481
1482 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001483 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001484 if (err)
1485 goto out;
1486
1487 e1000_configure_msix(adapter);
1488 return 0;
1489out:
1490 return err;
1491}
1492
Bruce Allanf8d59f72008-08-08 18:36:11 -07001493/**
1494 * e1000_request_irq - initialize interrupts
1495 *
1496 * Attempts to configure interrupts using the best available
1497 * capabilities of the hardware and kernel.
1498 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001499static int e1000_request_irq(struct e1000_adapter *adapter)
1500{
1501 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001502 int err;
1503
Bruce Allan4662e822008-08-26 18:37:06 -07001504 if (adapter->msix_entries) {
1505 err = e1000_request_msix(adapter);
1506 if (!err)
1507 return err;
1508 /* fall back to MSI */
1509 e1000e_reset_interrupt_capability(adapter);
1510 adapter->int_mode = E1000E_INT_MODE_MSI;
1511 e1000e_set_interrupt_capability(adapter);
1512 }
1513 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001514 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001515 netdev->name, netdev);
1516 if (!err)
1517 return err;
1518
1519 /* fall back to legacy interrupt */
1520 e1000e_reset_interrupt_capability(adapter);
1521 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001522 }
1523
Joe Perchesa0607fd2009-11-18 23:29:17 -08001524 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001525 netdev->name, netdev);
1526 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001527 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001528
1529 return err;
1530}
1531
1532static void e1000_free_irq(struct e1000_adapter *adapter)
1533{
1534 struct net_device *netdev = adapter->netdev;
1535
Bruce Allan4662e822008-08-26 18:37:06 -07001536 if (adapter->msix_entries) {
1537 int vector = 0;
1538
1539 free_irq(adapter->msix_entries[vector].vector, netdev);
1540 vector++;
1541
1542 free_irq(adapter->msix_entries[vector].vector, netdev);
1543 vector++;
1544
1545 /* Other Causes interrupt vector */
1546 free_irq(adapter->msix_entries[vector].vector, netdev);
1547 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001548 }
Bruce Allan4662e822008-08-26 18:37:06 -07001549
1550 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001551}
1552
1553/**
1554 * e1000_irq_disable - Mask off interrupt generation on the NIC
1555 **/
1556static void e1000_irq_disable(struct e1000_adapter *adapter)
1557{
1558 struct e1000_hw *hw = &adapter->hw;
1559
Auke Kokbc7f75f2007-09-17 12:30:59 -07001560 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001561 if (adapter->msix_entries)
1562 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001563 e1e_flush();
1564 synchronize_irq(adapter->pdev->irq);
1565}
1566
1567/**
1568 * e1000_irq_enable - Enable default interrupt generation settings
1569 **/
1570static void e1000_irq_enable(struct e1000_adapter *adapter)
1571{
1572 struct e1000_hw *hw = &adapter->hw;
1573
Bruce Allan4662e822008-08-26 18:37:06 -07001574 if (adapter->msix_entries) {
1575 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1576 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1577 } else {
1578 ew32(IMS, IMS_ENABLE_MASK);
1579 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001580 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001581}
1582
1583/**
1584 * e1000_get_hw_control - get control of the h/w from f/w
1585 * @adapter: address of board private structure
1586 *
Auke Kok489815c2008-02-21 15:11:07 -08001587 * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001588 * For ASF and Pass Through versions of f/w this means that
1589 * the driver is loaded. For AMT version (only with 82573)
1590 * of the f/w this means that the network i/f is open.
1591 **/
1592static void e1000_get_hw_control(struct e1000_adapter *adapter)
1593{
1594 struct e1000_hw *hw = &adapter->hw;
1595 u32 ctrl_ext;
1596 u32 swsm;
1597
1598 /* Let firmware know the driver has taken over */
1599 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1600 swsm = er32(SWSM);
1601 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1602 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1603 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07001604 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001605 }
1606}
1607
1608/**
1609 * e1000_release_hw_control - release control of the h/w to f/w
1610 * @adapter: address of board private structure
1611 *
Auke Kok489815c2008-02-21 15:11:07 -08001612 * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001613 * For ASF and Pass Through versions of f/w this means that the
1614 * driver is no longer loaded. For AMT version (only with 82573) i
1615 * of the f/w this means that the network i/f is closed.
1616 *
1617 **/
1618static void e1000_release_hw_control(struct e1000_adapter *adapter)
1619{
1620 struct e1000_hw *hw = &adapter->hw;
1621 u32 ctrl_ext;
1622 u32 swsm;
1623
1624 /* Let firmware taken over control of h/w */
1625 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1626 swsm = er32(SWSM);
1627 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1628 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1629 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07001630 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001631 }
1632}
1633
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634/**
1635 * @e1000_alloc_ring - allocate memory for a ring structure
1636 **/
1637static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
1638 struct e1000_ring *ring)
1639{
1640 struct pci_dev *pdev = adapter->pdev;
1641
1642 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
1643 GFP_KERNEL);
1644 if (!ring->desc)
1645 return -ENOMEM;
1646
1647 return 0;
1648}
1649
1650/**
1651 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1652 * @adapter: board private structure
1653 *
1654 * Return 0 on success, negative on failure
1655 **/
1656int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
1657{
1658 struct e1000_ring *tx_ring = adapter->tx_ring;
1659 int err = -ENOMEM, size;
1660
1661 size = sizeof(struct e1000_buffer) * tx_ring->count;
1662 tx_ring->buffer_info = vmalloc(size);
1663 if (!tx_ring->buffer_info)
1664 goto err;
1665 memset(tx_ring->buffer_info, 0, size);
1666
1667 /* round up to nearest 4K */
1668 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1669 tx_ring->size = ALIGN(tx_ring->size, 4096);
1670
1671 err = e1000_alloc_ring_dma(adapter, tx_ring);
1672 if (err)
1673 goto err;
1674
1675 tx_ring->next_to_use = 0;
1676 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001677
1678 return 0;
1679err:
1680 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001681 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001682 return err;
1683}
1684
1685/**
1686 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1687 * @adapter: board private structure
1688 *
1689 * Returns 0 on success, negative on failure
1690 **/
1691int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
1692{
1693 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07001694 struct e1000_buffer *buffer_info;
1695 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001696
1697 size = sizeof(struct e1000_buffer) * rx_ring->count;
1698 rx_ring->buffer_info = vmalloc(size);
1699 if (!rx_ring->buffer_info)
1700 goto err;
1701 memset(rx_ring->buffer_info, 0, size);
1702
Auke Kok47f44e42007-10-25 13:57:44 -07001703 for (i = 0; i < rx_ring->count; i++) {
1704 buffer_info = &rx_ring->buffer_info[i];
1705 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
1706 sizeof(struct e1000_ps_page),
1707 GFP_KERNEL);
1708 if (!buffer_info->ps_pages)
1709 goto err_pages;
1710 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001711
1712 desc_len = sizeof(union e1000_rx_desc_packet_split);
1713
1714 /* Round up to nearest 4K */
1715 rx_ring->size = rx_ring->count * desc_len;
1716 rx_ring->size = ALIGN(rx_ring->size, 4096);
1717
1718 err = e1000_alloc_ring_dma(adapter, rx_ring);
1719 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07001720 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721
1722 rx_ring->next_to_clean = 0;
1723 rx_ring->next_to_use = 0;
1724 rx_ring->rx_skb_top = NULL;
1725
1726 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07001727
1728err_pages:
1729 for (i = 0; i < rx_ring->count; i++) {
1730 buffer_info = &rx_ring->buffer_info[i];
1731 kfree(buffer_info->ps_pages);
1732 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001733err:
1734 vfree(rx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001735 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001736 return err;
1737}
1738
1739/**
1740 * e1000_clean_tx_ring - Free Tx Buffers
1741 * @adapter: board private structure
1742 **/
1743static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
1744{
1745 struct e1000_ring *tx_ring = adapter->tx_ring;
1746 struct e1000_buffer *buffer_info;
1747 unsigned long size;
1748 unsigned int i;
1749
1750 for (i = 0; i < tx_ring->count; i++) {
1751 buffer_info = &tx_ring->buffer_info[i];
1752 e1000_put_txbuf(adapter, buffer_info);
1753 }
1754
1755 size = sizeof(struct e1000_buffer) * tx_ring->count;
1756 memset(tx_ring->buffer_info, 0, size);
1757
1758 memset(tx_ring->desc, 0, tx_ring->size);
1759
1760 tx_ring->next_to_use = 0;
1761 tx_ring->next_to_clean = 0;
1762
1763 writel(0, adapter->hw.hw_addr + tx_ring->head);
1764 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1765}
1766
1767/**
1768 * e1000e_free_tx_resources - Free Tx Resources per Queue
1769 * @adapter: board private structure
1770 *
1771 * Free all transmit software resources
1772 **/
1773void e1000e_free_tx_resources(struct e1000_adapter *adapter)
1774{
1775 struct pci_dev *pdev = adapter->pdev;
1776 struct e1000_ring *tx_ring = adapter->tx_ring;
1777
1778 e1000_clean_tx_ring(adapter);
1779
1780 vfree(tx_ring->buffer_info);
1781 tx_ring->buffer_info = NULL;
1782
1783 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1784 tx_ring->dma);
1785 tx_ring->desc = NULL;
1786}
1787
1788/**
1789 * e1000e_free_rx_resources - Free Rx Resources
1790 * @adapter: board private structure
1791 *
1792 * Free all receive software resources
1793 **/
1794
1795void e1000e_free_rx_resources(struct e1000_adapter *adapter)
1796{
1797 struct pci_dev *pdev = adapter->pdev;
1798 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07001799 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001800
1801 e1000_clean_rx_ring(adapter);
1802
Auke Kok47f44e42007-10-25 13:57:44 -07001803 for (i = 0; i < rx_ring->count; i++) {
1804 kfree(rx_ring->buffer_info[i].ps_pages);
1805 }
1806
Auke Kokbc7f75f2007-09-17 12:30:59 -07001807 vfree(rx_ring->buffer_info);
1808 rx_ring->buffer_info = NULL;
1809
Auke Kokbc7f75f2007-09-17 12:30:59 -07001810 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1811 rx_ring->dma);
1812 rx_ring->desc = NULL;
1813}
1814
1815/**
1816 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08001817 * @adapter: pointer to adapter
1818 * @itr_setting: current adapter->itr
1819 * @packets: the number of packets during this measurement interval
1820 * @bytes: the number of bytes during this measurement interval
1821 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07001822 * Stores a new ITR value based on packets and byte
1823 * counts during the last interrupt. The advantage of per interrupt
1824 * computation is faster updates and more accurate ITR for the current
1825 * traffic pattern. Constants in this function were computed
1826 * based on theoretical maximum wire speed and thresholds were set based
1827 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07001828 * while increasing bulk throughput. This functionality is controlled
1829 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001830 **/
1831static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
1832 u16 itr_setting, int packets,
1833 int bytes)
1834{
1835 unsigned int retval = itr_setting;
1836
1837 if (packets == 0)
1838 goto update_itr_done;
1839
1840 switch (itr_setting) {
1841 case lowest_latency:
1842 /* handle TSO and jumbo frames */
1843 if (bytes/packets > 8000)
1844 retval = bulk_latency;
1845 else if ((packets < 5) && (bytes > 512)) {
1846 retval = low_latency;
1847 }
1848 break;
1849 case low_latency: /* 50 usec aka 20000 ints/s */
1850 if (bytes > 10000) {
1851 /* this if handles the TSO accounting */
1852 if (bytes/packets > 8000) {
1853 retval = bulk_latency;
1854 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
1855 retval = bulk_latency;
1856 } else if ((packets > 35)) {
1857 retval = lowest_latency;
1858 }
1859 } else if (bytes/packets > 2000) {
1860 retval = bulk_latency;
1861 } else if (packets <= 2 && bytes < 512) {
1862 retval = lowest_latency;
1863 }
1864 break;
1865 case bulk_latency: /* 250 usec aka 4000 ints/s */
1866 if (bytes > 25000) {
1867 if (packets > 35) {
1868 retval = low_latency;
1869 }
1870 } else if (bytes < 6000) {
1871 retval = low_latency;
1872 }
1873 break;
1874 }
1875
1876update_itr_done:
1877 return retval;
1878}
1879
1880static void e1000_set_itr(struct e1000_adapter *adapter)
1881{
1882 struct e1000_hw *hw = &adapter->hw;
1883 u16 current_itr;
1884 u32 new_itr = adapter->itr;
1885
1886 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1887 if (adapter->link_speed != SPEED_1000) {
1888 current_itr = 0;
1889 new_itr = 4000;
1890 goto set_itr_now;
1891 }
1892
1893 adapter->tx_itr = e1000_update_itr(adapter,
1894 adapter->tx_itr,
1895 adapter->total_tx_packets,
1896 adapter->total_tx_bytes);
1897 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1898 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
1899 adapter->tx_itr = low_latency;
1900
1901 adapter->rx_itr = e1000_update_itr(adapter,
1902 adapter->rx_itr,
1903 adapter->total_rx_packets,
1904 adapter->total_rx_bytes);
1905 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1906 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
1907 adapter->rx_itr = low_latency;
1908
1909 current_itr = max(adapter->rx_itr, adapter->tx_itr);
1910
1911 switch (current_itr) {
1912 /* counts and packets in update_itr are dependent on these numbers */
1913 case lowest_latency:
1914 new_itr = 70000;
1915 break;
1916 case low_latency:
1917 new_itr = 20000; /* aka hwitr = ~200 */
1918 break;
1919 case bulk_latency:
1920 new_itr = 4000;
1921 break;
1922 default:
1923 break;
1924 }
1925
1926set_itr_now:
1927 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07001928 /*
1929 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07001930 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07001931 * increasing
1932 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001933 new_itr = new_itr > adapter->itr ?
1934 min(adapter->itr + (new_itr >> 2), new_itr) :
1935 new_itr;
1936 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07001937 adapter->rx_ring->itr_val = new_itr;
1938 if (adapter->msix_entries)
1939 adapter->rx_ring->set_itr = 1;
1940 else
1941 ew32(ITR, 1000000000 / (new_itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001942 }
1943}
1944
1945/**
Bruce Allan4662e822008-08-26 18:37:06 -07001946 * e1000_alloc_queues - Allocate memory for all rings
1947 * @adapter: board private structure to initialize
1948 **/
1949static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1950{
1951 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1952 if (!adapter->tx_ring)
1953 goto err;
1954
1955 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1956 if (!adapter->rx_ring)
1957 goto err;
1958
1959 return 0;
1960err:
1961 e_err("Unable to allocate memory for queues\n");
1962 kfree(adapter->rx_ring);
1963 kfree(adapter->tx_ring);
1964 return -ENOMEM;
1965}
1966
1967/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001968 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07001969 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08001970 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07001971 **/
1972static int e1000_clean(struct napi_struct *napi, int budget)
1973{
1974 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001975 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001976 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00001977 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001978
Wang Chen4cf16532008-11-12 23:38:14 -08001979 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001980
Bruce Allan4662e822008-08-26 18:37:06 -07001981 if (adapter->msix_entries &&
1982 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
1983 goto clean_rx;
1984
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00001985 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001986
Bruce Allan4662e822008-08-26 18:37:06 -07001987clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001988 adapter->clean_rx(adapter, &work_done, budget);
1989
Alexander Duyck12d04a32009-03-25 22:05:03 +00001990 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08001991 work_done = budget;
1992
David S. Miller53e52c72008-01-07 21:06:12 -08001993 /* If budget not fully consumed, exit the polling mode */
1994 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995 if (adapter->itr_setting & 3)
1996 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08001997 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001998 if (!test_bit(__E1000_DOWN, &adapter->state)) {
1999 if (adapter->msix_entries)
2000 ew32(IMS, adapter->rx_ring->ims_val);
2001 else
2002 e1000_irq_enable(adapter);
2003 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002004 }
2005
2006 return work_done;
2007}
2008
2009static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2010{
2011 struct e1000_adapter *adapter = netdev_priv(netdev);
2012 struct e1000_hw *hw = &adapter->hw;
2013 u32 vfta, index;
2014
2015 /* don't update vlan cookie if already programmed */
2016 if ((adapter->hw.mng_cookie.status &
2017 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2018 (vid == adapter->mng_vlan_id))
2019 return;
2020 /* add VID to filter table */
2021 index = (vid >> 5) & 0x7F;
2022 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2023 vfta |= (1 << (vid & 0x1F));
2024 e1000e_write_vfta(hw, index, vfta);
2025}
2026
2027static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2028{
2029 struct e1000_adapter *adapter = netdev_priv(netdev);
2030 struct e1000_hw *hw = &adapter->hw;
2031 u32 vfta, index;
2032
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002033 if (!test_bit(__E1000_DOWN, &adapter->state))
2034 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002035 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002036
2037 if (!test_bit(__E1000_DOWN, &adapter->state))
2038 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002039
2040 if ((adapter->hw.mng_cookie.status &
2041 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2042 (vid == adapter->mng_vlan_id)) {
2043 /* release control to f/w */
2044 e1000_release_hw_control(adapter);
2045 return;
2046 }
2047
2048 /* remove VID from filter table */
2049 index = (vid >> 5) & 0x7F;
2050 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2051 vfta &= ~(1 << (vid & 0x1F));
2052 e1000e_write_vfta(hw, index, vfta);
2053}
2054
2055static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2056{
2057 struct net_device *netdev = adapter->netdev;
2058 u16 vid = adapter->hw.mng_cookie.vlan_id;
2059 u16 old_vid = adapter->mng_vlan_id;
2060
2061 if (!adapter->vlgrp)
2062 return;
2063
2064 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2065 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2066 if (adapter->hw.mng_cookie.status &
2067 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2068 e1000_vlan_rx_add_vid(netdev, vid);
2069 adapter->mng_vlan_id = vid;
2070 }
2071
2072 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2073 (vid != old_vid) &&
2074 !vlan_group_get_device(adapter->vlgrp, old_vid))
2075 e1000_vlan_rx_kill_vid(netdev, old_vid);
2076 } else {
2077 adapter->mng_vlan_id = vid;
2078 }
2079}
2080
2081
2082static void e1000_vlan_rx_register(struct net_device *netdev,
2083 struct vlan_group *grp)
2084{
2085 struct e1000_adapter *adapter = netdev_priv(netdev);
2086 struct e1000_hw *hw = &adapter->hw;
2087 u32 ctrl, rctl;
2088
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002089 if (!test_bit(__E1000_DOWN, &adapter->state))
2090 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002091 adapter->vlgrp = grp;
2092
2093 if (grp) {
2094 /* enable VLAN tag insert/strip */
2095 ctrl = er32(CTRL);
2096 ctrl |= E1000_CTRL_VME;
2097 ew32(CTRL, ctrl);
2098
2099 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2100 /* enable VLAN receive filtering */
2101 rctl = er32(RCTL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002102 rctl &= ~E1000_RCTL_CFIEN;
2103 ew32(RCTL, rctl);
2104 e1000_update_mng_vlan(adapter);
2105 }
2106 } else {
2107 /* disable VLAN tag insert/strip */
2108 ctrl = er32(CTRL);
2109 ctrl &= ~E1000_CTRL_VME;
2110 ew32(CTRL, ctrl);
2111
2112 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002113 if (adapter->mng_vlan_id !=
2114 (u16)E1000_MNG_VLAN_NONE) {
2115 e1000_vlan_rx_kill_vid(netdev,
2116 adapter->mng_vlan_id);
2117 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2118 }
2119 }
2120 }
2121
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002122 if (!test_bit(__E1000_DOWN, &adapter->state))
2123 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002124}
2125
2126static void e1000_restore_vlan(struct e1000_adapter *adapter)
2127{
2128 u16 vid;
2129
2130 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2131
2132 if (!adapter->vlgrp)
2133 return;
2134
2135 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2136 if (!vlan_group_get_device(adapter->vlgrp, vid))
2137 continue;
2138 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2139 }
2140}
2141
2142static void e1000_init_manageability(struct e1000_adapter *adapter)
2143{
2144 struct e1000_hw *hw = &adapter->hw;
2145 u32 manc, manc2h;
2146
2147 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2148 return;
2149
2150 manc = er32(MANC);
2151
Bruce Allanad680762008-03-28 09:15:03 -07002152 /*
2153 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002154 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002155 * the packets will be handled on SMBUS
2156 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002157 manc |= E1000_MANC_EN_MNG2HOST;
2158 manc2h = er32(MANC2H);
2159#define E1000_MNG2HOST_PORT_623 (1 << 5)
2160#define E1000_MNG2HOST_PORT_664 (1 << 6)
2161 manc2h |= E1000_MNG2HOST_PORT_623;
2162 manc2h |= E1000_MNG2HOST_PORT_664;
2163 ew32(MANC2H, manc2h);
2164 ew32(MANC, manc);
2165}
2166
2167/**
2168 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2169 * @adapter: board private structure
2170 *
2171 * Configure the Tx unit of the MAC after a reset.
2172 **/
2173static void e1000_configure_tx(struct e1000_adapter *adapter)
2174{
2175 struct e1000_hw *hw = &adapter->hw;
2176 struct e1000_ring *tx_ring = adapter->tx_ring;
2177 u64 tdba;
2178 u32 tdlen, tctl, tipg, tarc;
2179 u32 ipgr1, ipgr2;
2180
2181 /* Setup the HW Tx Head and Tail descriptor pointers */
2182 tdba = tx_ring->dma;
2183 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002184 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002185 ew32(TDBAH, (tdba >> 32));
2186 ew32(TDLEN, tdlen);
2187 ew32(TDH, 0);
2188 ew32(TDT, 0);
2189 tx_ring->head = E1000_TDH;
2190 tx_ring->tail = E1000_TDT;
2191
2192 /* Set the default values for the Tx Inter Packet Gap timer */
2193 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2194 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2195 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2196
2197 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2198 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2199
2200 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2201 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2202 ew32(TIPG, tipg);
2203
2204 /* Set the Tx Interrupt Delay register */
2205 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002206 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002207 ew32(TADV, adapter->tx_abs_int_delay);
2208
2209 /* Program the Transmit Control Register */
2210 tctl = er32(TCTL);
2211 tctl &= ~E1000_TCTL_CT;
2212 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2213 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2214
2215 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002216 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002217 /*
2218 * set the speed mode bit, we'll clear it if we're not at
2219 * gigabit link later
2220 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002221#define SPEED_MODE_BIT (1 << 21)
2222 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002223 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002224 }
2225
2226 /* errata: program both queues to unweighted RR */
2227 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002228 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002230 ew32(TARC(0), tarc);
2231 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002232 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002233 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002234 }
2235
Auke Kokbc7f75f2007-09-17 12:30:59 -07002236 /* Setup Transmit Descriptor Settings for eop descriptor */
2237 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2238
2239 /* only set IDE if we are delaying interrupts using the timers */
2240 if (adapter->tx_int_delay)
2241 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2242
2243 /* enable Report Status bit */
2244 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2245
2246 ew32(TCTL, tctl);
2247
Simon Hormanedfea6e62009-06-08 14:28:36 +00002248 e1000e_config_collision_dist(hw);
2249
Auke Kokbc7f75f2007-09-17 12:30:59 -07002250 adapter->tx_queue_len = adapter->netdev->tx_queue_len;
2251}
2252
2253/**
2254 * e1000_setup_rctl - configure the receive control registers
2255 * @adapter: Board private structure
2256 **/
2257#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2258 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2259static void e1000_setup_rctl(struct e1000_adapter *adapter)
2260{
2261 struct e1000_hw *hw = &adapter->hw;
2262 u32 rctl, rfctl;
2263 u32 psrctl = 0;
2264 u32 pages = 0;
2265
2266 /* Program MC offset vector base */
2267 rctl = er32(RCTL);
2268 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2269 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2270 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2271 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2272
2273 /* Do not Store bad packets */
2274 rctl &= ~E1000_RCTL_SBP;
2275
2276 /* Enable Long Packet receive */
2277 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2278 rctl &= ~E1000_RCTL_LPE;
2279 else
2280 rctl |= E1000_RCTL_LPE;
2281
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002282 /* Some systems expect that the CRC is included in SMBUS traffic. The
2283 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2284 * host memory when this is enabled
2285 */
2286 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2287 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002288
Bruce Allana4f58f52009-06-02 11:29:18 +00002289 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2290 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2291 u16 phy_data;
2292
2293 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2294 phy_data &= 0xfff8;
2295 phy_data |= (1 << 2);
2296 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2297
2298 e1e_rphy(hw, 22, &phy_data);
2299 phy_data &= 0x0fff;
2300 phy_data |= (1 << 14);
2301 e1e_wphy(hw, 0x10, 0x2823);
2302 e1e_wphy(hw, 0x11, 0x0003);
2303 e1e_wphy(hw, 22, phy_data);
2304 }
2305
Auke Kokbc7f75f2007-09-17 12:30:59 -07002306 /* Setup buffer sizes */
2307 rctl &= ~E1000_RCTL_SZ_4096;
2308 rctl |= E1000_RCTL_BSEX;
2309 switch (adapter->rx_buffer_len) {
2310 case 256:
2311 rctl |= E1000_RCTL_SZ_256;
2312 rctl &= ~E1000_RCTL_BSEX;
2313 break;
2314 case 512:
2315 rctl |= E1000_RCTL_SZ_512;
2316 rctl &= ~E1000_RCTL_BSEX;
2317 break;
2318 case 1024:
2319 rctl |= E1000_RCTL_SZ_1024;
2320 rctl &= ~E1000_RCTL_BSEX;
2321 break;
2322 case 2048:
2323 default:
2324 rctl |= E1000_RCTL_SZ_2048;
2325 rctl &= ~E1000_RCTL_BSEX;
2326 break;
2327 case 4096:
2328 rctl |= E1000_RCTL_SZ_4096;
2329 break;
2330 case 8192:
2331 rctl |= E1000_RCTL_SZ_8192;
2332 break;
2333 case 16384:
2334 rctl |= E1000_RCTL_SZ_16384;
2335 break;
2336 }
2337
2338 /*
2339 * 82571 and greater support packet-split where the protocol
2340 * header is placed in skb->data and the packet data is
2341 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2342 * In the case of a non-split, skb->data is linearly filled,
2343 * followed by the page buffers. Therefore, skb->data is
2344 * sized to hold the largest protocol header.
2345 *
2346 * allocations using alloc_page take too long for regular MTU
2347 * so only enable packet split for jumbo frames
2348 *
2349 * Using pages when the page size is greater than 16k wastes
2350 * a lot of memory, since we allocate 3 pages at all times
2351 * per packet.
2352 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002353 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002354 if (!(adapter->flags & FLAG_IS_ICH) && (pages <= 3) &&
2355 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002357 else
2358 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359
2360 if (adapter->rx_ps_pages) {
2361 /* Configure extra packet-split registers */
2362 rfctl = er32(RFCTL);
2363 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002364 /*
2365 * disable packet split support for IPv6 extension headers,
2366 * because some malformed IPv6 headers can hang the Rx
2367 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002368 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2369 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2370
2371 ew32(RFCTL, rfctl);
2372
Auke Kok140a7482007-10-25 13:57:58 -07002373 /* Enable Packet split descriptors */
2374 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002375
2376 psrctl |= adapter->rx_ps_bsize0 >>
2377 E1000_PSRCTL_BSIZE0_SHIFT;
2378
2379 switch (adapter->rx_ps_pages) {
2380 case 3:
2381 psrctl |= PAGE_SIZE <<
2382 E1000_PSRCTL_BSIZE3_SHIFT;
2383 case 2:
2384 psrctl |= PAGE_SIZE <<
2385 E1000_PSRCTL_BSIZE2_SHIFT;
2386 case 1:
2387 psrctl |= PAGE_SIZE >>
2388 E1000_PSRCTL_BSIZE1_SHIFT;
2389 break;
2390 }
2391
2392 ew32(PSRCTL, psrctl);
2393 }
2394
2395 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002396 /* just started the receive unit, no need to restart */
2397 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398}
2399
2400/**
2401 * e1000_configure_rx - Configure Receive Unit after Reset
2402 * @adapter: board private structure
2403 *
2404 * Configure the Rx unit of the MAC after a reset.
2405 **/
2406static void e1000_configure_rx(struct e1000_adapter *adapter)
2407{
2408 struct e1000_hw *hw = &adapter->hw;
2409 struct e1000_ring *rx_ring = adapter->rx_ring;
2410 u64 rdba;
2411 u32 rdlen, rctl, rxcsum, ctrl_ext;
2412
2413 if (adapter->rx_ps_pages) {
2414 /* this is a 32 byte descriptor */
2415 rdlen = rx_ring->count *
2416 sizeof(union e1000_rx_desc_packet_split);
2417 adapter->clean_rx = e1000_clean_rx_irq_ps;
2418 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002419 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2420 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2421 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2422 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002423 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002424 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002425 adapter->clean_rx = e1000_clean_rx_irq;
2426 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2427 }
2428
2429 /* disable receives while setting up the descriptors */
2430 rctl = er32(RCTL);
2431 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2432 e1e_flush();
2433 msleep(10);
2434
2435 /* set the Receive Delay Timer Register */
2436 ew32(RDTR, adapter->rx_int_delay);
2437
2438 /* irq moderation */
2439 ew32(RADV, adapter->rx_abs_int_delay);
2440 if (adapter->itr_setting != 0)
Bruce Allanad680762008-03-28 09:15:03 -07002441 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002442
2443 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002444 /* Auto-Mask interrupts upon ICR access */
2445 ctrl_ext |= E1000_CTRL_EXT_IAME;
2446 ew32(IAM, 0xffffffff);
2447 ew32(CTRL_EXT, ctrl_ext);
2448 e1e_flush();
2449
Bruce Allanad680762008-03-28 09:15:03 -07002450 /*
2451 * Setup the HW Rx Head and Tail Descriptor Pointers and
2452 * the Base and Length of the Rx Descriptor Ring
2453 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002455 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002456 ew32(RDBAH, (rdba >> 32));
2457 ew32(RDLEN, rdlen);
2458 ew32(RDH, 0);
2459 ew32(RDT, 0);
2460 rx_ring->head = E1000_RDH;
2461 rx_ring->tail = E1000_RDT;
2462
2463 /* Enable Receive Checksum Offload for TCP and UDP */
2464 rxcsum = er32(RXCSUM);
2465 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2466 rxcsum |= E1000_RXCSUM_TUOFL;
2467
Bruce Allanad680762008-03-28 09:15:03 -07002468 /*
2469 * IPv4 payload checksum for UDP fragments must be
2470 * used in conjunction with packet-split.
2471 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002472 if (adapter->rx_ps_pages)
2473 rxcsum |= E1000_RXCSUM_IPPCSE;
2474 } else {
2475 rxcsum &= ~E1000_RXCSUM_TUOFL;
2476 /* no need to clear IPPCSE as it defaults to 0 */
2477 }
2478 ew32(RXCSUM, rxcsum);
2479
Bruce Allanad680762008-03-28 09:15:03 -07002480 /*
2481 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002482 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002483 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2484 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002485 if ((adapter->flags & FLAG_HAS_ERT) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002486 (adapter->netdev->mtu > ETH_DATA_LEN)) {
2487 u32 rxdctl = er32(RXDCTL(0));
2488 ew32(RXDCTL(0), rxdctl | 0x3);
2489 ew32(ERT, E1000_ERT_2048 | (1 << 13));
2490 /*
2491 * With jumbo frames and early-receive enabled, excessive
2492 * C4->C2 latencies result in dropped transactions.
2493 */
2494 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2495 e1000e_driver_name, 55);
2496 } else {
2497 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2498 e1000e_driver_name,
2499 PM_QOS_DEFAULT_VALUE);
2500 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002501
2502 /* Enable Receives */
2503 ew32(RCTL, rctl);
2504}
2505
2506/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002507 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07002508 * @hw: pointer to the HW structure
2509 * @mc_addr_list: array of multicast addresses to program
2510 * @mc_addr_count: number of multicast addresses to program
2511 * @rar_used_count: the first RAR register free to program
2512 * @rar_count: total number of supported Receive Address Registers
2513 *
2514 * Updates the Receive Address Registers and Multicast Table Array.
2515 * The caller must have a packed mc_addr_list of multicast addresses.
2516 * The parameter rar_count will usually be hw->mac.rar_entry_count
2517 * unless there are workarounds that change this. Currently no func pointer
2518 * exists and all implementations are handled in the generic version of this
2519 * function.
2520 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002521static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
2522 u32 mc_addr_count, u32 rar_used_count,
2523 u32 rar_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002524{
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002525 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526 rar_used_count, rar_count);
2527}
2528
2529/**
2530 * e1000_set_multi - Multicast and Promiscuous mode set
2531 * @netdev: network interface device structure
2532 *
2533 * The set_multi entry point is called whenever the multicast address
2534 * list or the network interface flags are updated. This routine is
2535 * responsible for configuring the hardware for proper multicast,
2536 * promiscuous mode, and all-multi behavior.
2537 **/
2538static void e1000_set_multi(struct net_device *netdev)
2539{
2540 struct e1000_adapter *adapter = netdev_priv(netdev);
2541 struct e1000_hw *hw = &adapter->hw;
2542 struct e1000_mac_info *mac = &hw->mac;
2543 struct dev_mc_list *mc_ptr;
2544 u8 *mta_list;
2545 u32 rctl;
2546 int i;
2547
2548 /* Check for Promiscuous and All Multicast modes */
2549
2550 rctl = er32(RCTL);
2551
2552 if (netdev->flags & IFF_PROMISC) {
2553 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002554 rctl &= ~E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002555 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002556 if (netdev->flags & IFF_ALLMULTI) {
2557 rctl |= E1000_RCTL_MPE;
2558 rctl &= ~E1000_RCTL_UPE;
2559 } else {
2560 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2561 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002562 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002563 rctl |= E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002564 }
2565
2566 ew32(RCTL, rctl);
2567
2568 if (netdev->mc_count) {
2569 mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);
2570 if (!mta_list)
2571 return;
2572
2573 /* prepare a packed array of only addresses. */
2574 mc_ptr = netdev->mc_list;
2575
2576 for (i = 0; i < netdev->mc_count; i++) {
2577 if (!mc_ptr)
2578 break;
2579 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
2580 ETH_ALEN);
2581 mc_ptr = mc_ptr->next;
2582 }
2583
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002584 e1000_update_mc_addr_list(hw, mta_list, i, 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002585 mac->rar_entry_count);
2586 kfree(mta_list);
2587 } else {
2588 /*
2589 * if we're called from probe, we might not have
2590 * anything to do here, so clear out the list
2591 */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002592 e1000_update_mc_addr_list(hw, NULL, 0, 1, mac->rar_entry_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002593 }
2594}
2595
2596/**
Bruce Allanad680762008-03-28 09:15:03 -07002597 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07002598 * @adapter: private board structure
2599 **/
2600static void e1000_configure(struct e1000_adapter *adapter)
2601{
2602 e1000_set_multi(adapter->netdev);
2603
2604 e1000_restore_vlan(adapter);
2605 e1000_init_manageability(adapter);
2606
2607 e1000_configure_tx(adapter);
2608 e1000_setup_rctl(adapter);
2609 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07002610 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611}
2612
2613/**
2614 * e1000e_power_up_phy - restore link in case the phy was powered down
2615 * @adapter: address of board private structure
2616 *
2617 * The phy may be powered down to save power and turn off link when the
2618 * driver is unloaded and wake on lan is not enabled (among others)
2619 * *** this routine MUST be followed by a call to e1000e_reset ***
2620 **/
2621void e1000e_power_up_phy(struct e1000_adapter *adapter)
2622{
2623 u16 mii_reg = 0;
2624
2625 /* Just clear the power down bit to wake the phy back up */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002626 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Bruce Allanad680762008-03-28 09:15:03 -07002627 /*
2628 * According to the manual, the phy will retain its
2629 * settings across a power-down/up cycle
2630 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002631 e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);
2632 mii_reg &= ~MII_CR_POWER_DOWN;
2633 e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);
2634 }
2635
2636 adapter->hw.mac.ops.setup_link(&adapter->hw);
2637}
2638
2639/**
2640 * e1000_power_down_phy - Power down the PHY
2641 *
2642 * Power down the PHY so no link is implied when interface is down
2643 * The PHY cannot be powered down is management or WoL is active
2644 */
2645static void e1000_power_down_phy(struct e1000_adapter *adapter)
2646{
2647 struct e1000_hw *hw = &adapter->hw;
2648 u16 mii_reg;
2649
2650 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08002651 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002652 return;
2653
2654 /* non-copper PHY? */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002655 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002656 return;
2657
2658 /* reset is blocked because of a SoL/IDER session */
Bruce Allanad680762008-03-28 09:15:03 -07002659 if (e1000e_check_mng_mode(hw) || e1000_check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002660 return;
2661
Auke Kok489815c2008-02-21 15:11:07 -08002662 /* manageability (AMT) is enabled */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663 if (er32(MANC) & E1000_MANC_SMBUS_EN)
2664 return;
2665
2666 /* power down the PHY */
2667 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2668 mii_reg |= MII_CR_POWER_DOWN;
2669 e1e_wphy(hw, PHY_CONTROL, mii_reg);
2670 mdelay(1);
2671}
2672
2673/**
2674 * e1000e_reset - bring the hardware into a known good state
2675 *
2676 * This function boots the hardware and enables some settings that
2677 * require a configuration cycle of the hardware - those cannot be
2678 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07002679 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002680 */
2681void e1000e_reset(struct e1000_adapter *adapter)
2682{
2683 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002684 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002685 struct e1000_hw *hw = &adapter->hw;
2686 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002687 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002688 u16 hwm;
2689
Bruce Allanad680762008-03-28 09:15:03 -07002690 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002691 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07002692
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002693 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07002694 /*
2695 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07002696 * large enough to accommodate two full transmit packets,
2697 * rounded up to the next 1KB and expressed in KB. Likewise,
2698 * the Rx FIFO should be large enough to accommodate at least
2699 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07002700 * expressed in KB.
2701 */
Auke Kokdf762462007-10-25 13:57:53 -07002702 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002703 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07002704 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07002706 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07002707 /*
2708 * the Tx fifo also stores 16 bytes of information about the tx
2709 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002710 */
2711 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07002712 sizeof(struct e1000_tx_desc) -
2713 ETH_FCS_LEN) * 2;
2714 min_tx_space = ALIGN(min_tx_space, 1024);
2715 min_tx_space >>= 10;
2716 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002717 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002718 min_rx_space = ALIGN(min_rx_space, 1024);
2719 min_rx_space >>= 10;
2720
Bruce Allanad680762008-03-28 09:15:03 -07002721 /*
2722 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002723 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07002724 * allocation, take space away from current Rx allocation
2725 */
Auke Kokdf762462007-10-25 13:57:53 -07002726 if ((tx_space < min_tx_space) &&
2727 ((min_tx_space - tx_space) < pba)) {
2728 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002729
Bruce Allanad680762008-03-28 09:15:03 -07002730 /*
2731 * if short on Rx space, Rx wins and must trump tx
2732 * adjustment or use Early Receive if available
2733 */
Auke Kokdf762462007-10-25 13:57:53 -07002734 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07002735 (!(adapter->flags & FLAG_HAS_ERT)))
2736 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07002737 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002738 }
Auke Kokdf762462007-10-25 13:57:53 -07002739
2740 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002741 }
2742
Auke Kokbc7f75f2007-09-17 12:30:59 -07002743
Bruce Allanad680762008-03-28 09:15:03 -07002744 /*
2745 * flow control settings
2746 *
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002747 * The high water mark must be low enough to fit two full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07002748 * (or the size used for early receive) above it in the Rx FIFO.
2749 * Set it to the lower of:
2750 * - 90% of the Rx FIFO size, and
2751 * - the full Rx FIFO size minus the early receive size (for parts
2752 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002753 * - the full Rx FIFO size minus two full frames
Bruce Allanad680762008-03-28 09:15:03 -07002754 */
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002755 if ((adapter->flags & FLAG_HAS_ERT) &&
2756 (adapter->netdev->mtu > ETH_DATA_LEN))
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002757 hwm = min(((pba << 10) * 9 / 10),
2758 ((pba << 10) - (E1000_ERT_2048 << 3)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002759 else
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002760 hwm = min(((pba << 10) * 9 / 10),
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002761 ((pba << 10) - (2 * adapter->max_frame_size)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002762
Bruce Allan3ec2a2b2009-06-02 11:28:39 +00002763 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
2764 fc->low_water = (fc->high_water - (2 * adapter->max_frame_size));
2765 fc->low_water &= E1000_FCRTL_RTL; /* 8-byte granularity */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002766
2767 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002768 fc->pause_time = 0xFFFF;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002769 else
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002770 fc->pause_time = E1000_FC_PAUSE_TIME;
2771 fc->send_xon = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08002772 fc->current_mode = fc->requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002773
2774 /* Allow time for pending master requests to run */
2775 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002776
2777 /*
2778 * For parts with AMT enabled, let the firmware know
2779 * that the network interface is in control
2780 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07002781 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002782 e1000_get_hw_control(adapter);
2783
Auke Kokbc7f75f2007-09-17 12:30:59 -07002784 ew32(WUC, 0);
Bruce Allana4f58f52009-06-02 11:29:18 +00002785 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)
2786 e1e_wphy(&adapter->hw, BM_WUC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787
2788 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002789 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002790
2791 e1000_update_mng_vlan(adapter);
2792
2793 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2794 ew32(VET, ETH_P_8021Q);
2795
2796 e1000e_reset_adaptive(hw);
2797 e1000_get_phy_info(hw);
2798
Bruce Allan918d7192009-06-02 11:28:20 +00002799 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
2800 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07002802 /*
2803 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07002804 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07002805 * different we would do if it failed
2806 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002807 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
2808 phy_data &= ~IGP02E1000_PM_SPD;
2809 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
2810 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002811}
2812
2813int e1000e_up(struct e1000_adapter *adapter)
2814{
2815 struct e1000_hw *hw = &adapter->hw;
2816
2817 /* hardware has been reset, we need to reload some things */
2818 e1000_configure(adapter);
2819
2820 clear_bit(__E1000_DOWN, &adapter->state);
2821
2822 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002823 if (adapter->msix_entries)
2824 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002825 e1000_irq_enable(adapter);
2826
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00002827 netif_wake_queue(adapter->netdev);
2828
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829 /* fire a link change interrupt to start the watchdog */
2830 ew32(ICS, E1000_ICS_LSC);
2831 return 0;
2832}
2833
2834void e1000e_down(struct e1000_adapter *adapter)
2835{
2836 struct net_device *netdev = adapter->netdev;
2837 struct e1000_hw *hw = &adapter->hw;
2838 u32 tctl, rctl;
2839
Bruce Allanad680762008-03-28 09:15:03 -07002840 /*
2841 * signal that we're down so the interrupt handler does not
2842 * reschedule our watchdog timer
2843 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844 set_bit(__E1000_DOWN, &adapter->state);
2845
2846 /* disable receives in the hardware */
2847 rctl = er32(RCTL);
2848 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2849 /* flush and sleep below */
2850
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00002851 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002852
2853 /* disable transmits in the hardware */
2854 tctl = er32(TCTL);
2855 tctl &= ~E1000_TCTL_EN;
2856 ew32(TCTL, tctl);
2857 /* flush both disables and wait for them to finish */
2858 e1e_flush();
2859 msleep(10);
2860
2861 napi_disable(&adapter->napi);
2862 e1000_irq_disable(adapter);
2863
2864 del_timer_sync(&adapter->watchdog_timer);
2865 del_timer_sync(&adapter->phy_info_timer);
2866
2867 netdev->tx_queue_len = adapter->tx_queue_len;
2868 netif_carrier_off(netdev);
2869 adapter->link_speed = 0;
2870 adapter->link_duplex = 0;
2871
Jeff Kirsher52cc3082008-06-24 17:01:29 -07002872 if (!pci_channel_offline(adapter->pdev))
2873 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002874 e1000_clean_tx_ring(adapter);
2875 e1000_clean_rx_ring(adapter);
2876
2877 /*
2878 * TODO: for power management, we could drop the link and
2879 * pci_disable_device here.
2880 */
2881}
2882
2883void e1000e_reinit_locked(struct e1000_adapter *adapter)
2884{
2885 might_sleep();
2886 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
2887 msleep(1);
2888 e1000e_down(adapter);
2889 e1000e_up(adapter);
2890 clear_bit(__E1000_RESETTING, &adapter->state);
2891}
2892
2893/**
2894 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2895 * @adapter: board private structure to initialize
2896 *
2897 * e1000_sw_init initializes the Adapter private data structure.
2898 * Fields are initialized based on PCI device information and
2899 * OS network device settings (MTU size).
2900 **/
2901static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
2902{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002903 struct net_device *netdev = adapter->netdev;
2904
2905 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
2906 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002907 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2908 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002909
Bruce Allan4662e822008-08-26 18:37:06 -07002910 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002911
Bruce Allan4662e822008-08-26 18:37:06 -07002912 if (e1000_alloc_queues(adapter))
2913 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002914
Auke Kokbc7f75f2007-09-17 12:30:59 -07002915 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002916 e1000_irq_disable(adapter);
2917
Auke Kokbc7f75f2007-09-17 12:30:59 -07002918 set_bit(__E1000_DOWN, &adapter->state);
2919 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002920}
2921
2922/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07002923 * e1000_intr_msi_test - Interrupt Handler
2924 * @irq: interrupt number
2925 * @data: pointer to a network interface device structure
2926 **/
2927static irqreturn_t e1000_intr_msi_test(int irq, void *data)
2928{
2929 struct net_device *netdev = data;
2930 struct e1000_adapter *adapter = netdev_priv(netdev);
2931 struct e1000_hw *hw = &adapter->hw;
2932 u32 icr = er32(ICR);
2933
2934 e_dbg("%s: icr is %08X\n", netdev->name, icr);
2935 if (icr & E1000_ICR_RXSEQ) {
2936 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
2937 wmb();
2938 }
2939
2940 return IRQ_HANDLED;
2941}
2942
2943/**
2944 * e1000_test_msi_interrupt - Returns 0 for successful test
2945 * @adapter: board private struct
2946 *
2947 * code flow taken from tg3.c
2948 **/
2949static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
2950{
2951 struct net_device *netdev = adapter->netdev;
2952 struct e1000_hw *hw = &adapter->hw;
2953 int err;
2954
2955 /* poll_enable hasn't been called yet, so don't need disable */
2956 /* clear any pending events */
2957 er32(ICR);
2958
2959 /* free the real vector and request a test handler */
2960 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07002961 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07002962
2963 /* Assume that the test fails, if it succeeds then the test
2964 * MSI irq handler will unset this flag */
2965 adapter->flags |= FLAG_MSI_TEST_FAILED;
2966
2967 err = pci_enable_msi(adapter->pdev);
2968 if (err)
2969 goto msi_test_failed;
2970
Joe Perchesa0607fd2009-11-18 23:29:17 -08002971 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07002972 netdev->name, netdev);
2973 if (err) {
2974 pci_disable_msi(adapter->pdev);
2975 goto msi_test_failed;
2976 }
2977
2978 wmb();
2979
2980 e1000_irq_enable(adapter);
2981
2982 /* fire an unusual interrupt on the test handler */
2983 ew32(ICS, E1000_ICS_RXSEQ);
2984 e1e_flush();
2985 msleep(50);
2986
2987 e1000_irq_disable(adapter);
2988
2989 rmb();
2990
2991 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07002992 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Bruce Allanf8d59f72008-08-08 18:36:11 -07002993 err = -EIO;
2994 e_info("MSI interrupt test failed!\n");
2995 }
2996
2997 free_irq(adapter->pdev->irq, netdev);
2998 pci_disable_msi(adapter->pdev);
2999
3000 if (err == -EIO)
3001 goto msi_test_failed;
3002
3003 /* okay so the test worked, restore settings */
3004 e_dbg("%s: MSI interrupt test succeeded!\n", netdev->name);
3005msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003006 e1000e_set_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003007 e1000_request_irq(adapter);
3008 return err;
3009}
3010
3011/**
3012 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3013 * @adapter: board private struct
3014 *
3015 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3016 **/
3017static int e1000_test_msi(struct e1000_adapter *adapter)
3018{
3019 int err;
3020 u16 pci_cmd;
3021
3022 if (!(adapter->flags & FLAG_MSI_ENABLED))
3023 return 0;
3024
3025 /* disable SERR in case the MSI write causes a master abort */
3026 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3027 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3028 pci_cmd & ~PCI_COMMAND_SERR);
3029
3030 err = e1000_test_msi_interrupt(adapter);
3031
3032 /* restore previous setting of command word */
3033 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3034
3035 /* success ! */
3036 if (!err)
3037 return 0;
3038
3039 /* EIO means MSI test failed */
3040 if (err != -EIO)
3041 return err;
3042
3043 /* back to INTx mode */
3044 e_warn("MSI interrupt test failed, using legacy interrupt.\n");
3045
3046 e1000_free_irq(adapter);
3047
3048 err = e1000_request_irq(adapter);
3049
3050 return err;
3051}
3052
3053/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003054 * e1000_open - Called when a network interface is made active
3055 * @netdev: network interface device structure
3056 *
3057 * Returns 0 on success, negative value on failure
3058 *
3059 * The open entry point is called when a network interface is made
3060 * active by the system (IFF_UP). At this point all resources needed
3061 * for transmit and receive operations are allocated, the interrupt
3062 * handler is registered with the OS, the watchdog timer is started,
3063 * and the stack is notified that the interface is ready.
3064 **/
3065static int e1000_open(struct net_device *netdev)
3066{
3067 struct e1000_adapter *adapter = netdev_priv(netdev);
3068 struct e1000_hw *hw = &adapter->hw;
3069 int err;
3070
3071 /* disallow open during test */
3072 if (test_bit(__E1000_TESTING, &adapter->state))
3073 return -EBUSY;
3074
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003075 netif_carrier_off(netdev);
3076
Auke Kokbc7f75f2007-09-17 12:30:59 -07003077 /* allocate transmit descriptors */
3078 err = e1000e_setup_tx_resources(adapter);
3079 if (err)
3080 goto err_setup_tx;
3081
3082 /* allocate receive descriptors */
3083 err = e1000e_setup_rx_resources(adapter);
3084 if (err)
3085 goto err_setup_rx;
3086
3087 e1000e_power_up_phy(adapter);
3088
3089 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3090 if ((adapter->hw.mng_cookie.status &
3091 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3092 e1000_update_mng_vlan(adapter);
3093
Bruce Allanad680762008-03-28 09:15:03 -07003094 /*
3095 * If AMT is enabled, let the firmware know that the network
3096 * interface is now open
3097 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003098 if (adapter->flags & FLAG_HAS_AMT)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003099 e1000_get_hw_control(adapter);
3100
Bruce Allanad680762008-03-28 09:15:03 -07003101 /*
3102 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003103 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3104 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003105 * clean_rx handler before we do so.
3106 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003107 e1000_configure(adapter);
3108
3109 err = e1000_request_irq(adapter);
3110 if (err)
3111 goto err_req_irq;
3112
Bruce Allanf8d59f72008-08-08 18:36:11 -07003113 /*
3114 * Work around PCIe errata with MSI interrupts causing some chipsets to
3115 * ignore e1000e MSI messages, which means we need to test our MSI
3116 * interrupt now
3117 */
Bruce Allan4662e822008-08-26 18:37:06 -07003118 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003119 err = e1000_test_msi(adapter);
3120 if (err) {
3121 e_err("Interrupt allocation failed\n");
3122 goto err_req_irq;
3123 }
3124 }
3125
Auke Kokbc7f75f2007-09-17 12:30:59 -07003126 /* From here on the code is the same as e1000e_up() */
3127 clear_bit(__E1000_DOWN, &adapter->state);
3128
3129 napi_enable(&adapter->napi);
3130
3131 e1000_irq_enable(adapter);
3132
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003133 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003134
Auke Kokbc7f75f2007-09-17 12:30:59 -07003135 /* fire a link status change interrupt to start the watchdog */
3136 ew32(ICS, E1000_ICS_LSC);
3137
3138 return 0;
3139
3140err_req_irq:
3141 e1000_release_hw_control(adapter);
3142 e1000_power_down_phy(adapter);
3143 e1000e_free_rx_resources(adapter);
3144err_setup_rx:
3145 e1000e_free_tx_resources(adapter);
3146err_setup_tx:
3147 e1000e_reset(adapter);
3148
3149 return err;
3150}
3151
3152/**
3153 * e1000_close - Disables a network interface
3154 * @netdev: network interface device structure
3155 *
3156 * Returns 0, this is not allowed to fail
3157 *
3158 * The close entry point is called when an interface is de-activated
3159 * by the OS. The hardware is still under the drivers control, but
3160 * needs to be disabled. A global MAC reset is issued to stop the
3161 * hardware, and all transmit and receive resources are freed.
3162 **/
3163static int e1000_close(struct net_device *netdev)
3164{
3165 struct e1000_adapter *adapter = netdev_priv(netdev);
3166
3167 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3168 e1000e_down(adapter);
3169 e1000_power_down_phy(adapter);
3170 e1000_free_irq(adapter);
3171
3172 e1000e_free_tx_resources(adapter);
3173 e1000e_free_rx_resources(adapter);
3174
Bruce Allanad680762008-03-28 09:15:03 -07003175 /*
3176 * kill manageability vlan ID if supported, but not if a vlan with
3177 * the same ID is registered on the host OS (let 8021q kill it)
3178 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003179 if ((adapter->hw.mng_cookie.status &
3180 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3181 !(adapter->vlgrp &&
3182 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3183 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3184
Bruce Allanad680762008-03-28 09:15:03 -07003185 /*
3186 * If AMT is enabled, let the firmware know that the network
3187 * interface is now closed
3188 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003189 if (adapter->flags & FLAG_HAS_AMT)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003190 e1000_release_hw_control(adapter);
3191
3192 return 0;
3193}
3194/**
3195 * e1000_set_mac - Change the Ethernet Address of the NIC
3196 * @netdev: network interface device structure
3197 * @p: pointer to an address structure
3198 *
3199 * Returns 0 on success, negative on failure
3200 **/
3201static int e1000_set_mac(struct net_device *netdev, void *p)
3202{
3203 struct e1000_adapter *adapter = netdev_priv(netdev);
3204 struct sockaddr *addr = p;
3205
3206 if (!is_valid_ether_addr(addr->sa_data))
3207 return -EADDRNOTAVAIL;
3208
3209 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3210 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3211
3212 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3213
3214 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3215 /* activate the work around */
3216 e1000e_set_laa_state_82571(&adapter->hw, 1);
3217
Bruce Allanad680762008-03-28 09:15:03 -07003218 /*
3219 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003220 * between the time RAR[0] gets clobbered and the time it
3221 * gets fixed (in e1000_watchdog), the actual LAA is in one
3222 * of the RARs and no incoming packets directed to this port
3223 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003224 * RAR[14]
3225 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003226 e1000e_rar_set(&adapter->hw,
3227 adapter->hw.mac.addr,
3228 adapter->hw.mac.rar_entry_count - 1);
3229 }
3230
3231 return 0;
3232}
3233
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003234/**
3235 * e1000e_update_phy_task - work thread to update phy
3236 * @work: pointer to our work struct
3237 *
3238 * this worker thread exists because we must acquire a
3239 * semaphore to read the phy, which we could msleep while
3240 * waiting for it, and we can't msleep in a timer.
3241 **/
3242static void e1000e_update_phy_task(struct work_struct *work)
3243{
3244 struct e1000_adapter *adapter = container_of(work,
3245 struct e1000_adapter, update_phy_task);
3246 e1000_get_phy_info(&adapter->hw);
3247}
3248
Bruce Allanad680762008-03-28 09:15:03 -07003249/*
3250 * Need to wait a few seconds after link up to get diagnostic information from
3251 * the phy
3252 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003253static void e1000_update_phy_info(unsigned long data)
3254{
3255 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003256 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003257}
3258
3259/**
3260 * e1000e_update_stats - Update the board statistics counters
3261 * @adapter: board private structure
3262 **/
3263void e1000e_update_stats(struct e1000_adapter *adapter)
3264{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003265 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003266 struct e1000_hw *hw = &adapter->hw;
3267 struct pci_dev *pdev = adapter->pdev;
Bruce Allana4f58f52009-06-02 11:29:18 +00003268 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003269
3270 /*
3271 * Prevent stats update while adapter is being reset, or if the pci
3272 * connection is down.
3273 */
3274 if (adapter->link_speed == 0)
3275 return;
3276 if (pci_channel_offline(pdev))
3277 return;
3278
Auke Kokbc7f75f2007-09-17 12:30:59 -07003279 adapter->stats.crcerrs += er32(CRCERRS);
3280 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003281 adapter->stats.gorc += er32(GORCL);
3282 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003283 adapter->stats.bprc += er32(BPRC);
3284 adapter->stats.mprc += er32(MPRC);
3285 adapter->stats.roc += er32(ROC);
3286
Auke Kokbc7f75f2007-09-17 12:30:59 -07003287 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003288 if ((hw->phy.type == e1000_phy_82578) ||
3289 (hw->phy.type == e1000_phy_82577)) {
3290 e1e_rphy(hw, HV_SCC_UPPER, &phy_data);
3291 e1e_rphy(hw, HV_SCC_LOWER, &phy_data);
3292 adapter->stats.scc += phy_data;
3293
3294 e1e_rphy(hw, HV_ECOL_UPPER, &phy_data);
3295 e1e_rphy(hw, HV_ECOL_LOWER, &phy_data);
3296 adapter->stats.ecol += phy_data;
3297
3298 e1e_rphy(hw, HV_MCC_UPPER, &phy_data);
3299 e1e_rphy(hw, HV_MCC_LOWER, &phy_data);
3300 adapter->stats.mcc += phy_data;
3301
3302 e1e_rphy(hw, HV_LATECOL_UPPER, &phy_data);
3303 e1e_rphy(hw, HV_LATECOL_LOWER, &phy_data);
3304 adapter->stats.latecol += phy_data;
3305
3306 e1e_rphy(hw, HV_DC_UPPER, &phy_data);
3307 e1e_rphy(hw, HV_DC_LOWER, &phy_data);
3308 adapter->stats.dc += phy_data;
3309 } else {
3310 adapter->stats.scc += er32(SCC);
3311 adapter->stats.ecol += er32(ECOL);
3312 adapter->stats.mcc += er32(MCC);
3313 adapter->stats.latecol += er32(LATECOL);
3314 adapter->stats.dc += er32(DC);
3315 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003316 adapter->stats.xonrxc += er32(XONRXC);
3317 adapter->stats.xontxc += er32(XONTXC);
3318 adapter->stats.xoffrxc += er32(XOFFRXC);
3319 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003320 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003321 adapter->stats.gotc += er32(GOTCL);
3322 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003323 adapter->stats.rnbc += er32(RNBC);
3324 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325
3326 adapter->stats.mptc += er32(MPTC);
3327 adapter->stats.bptc += er32(BPTC);
3328
3329 /* used for adaptive IFS */
3330
3331 hw->mac.tx_packet_delta = er32(TPT);
3332 adapter->stats.tpt += hw->mac.tx_packet_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003333 if ((hw->phy.type == e1000_phy_82578) ||
3334 (hw->phy.type == e1000_phy_82577)) {
3335 e1e_rphy(hw, HV_COLC_UPPER, &phy_data);
3336 e1e_rphy(hw, HV_COLC_LOWER, &phy_data);
3337 hw->mac.collision_delta = phy_data;
3338 } else {
3339 hw->mac.collision_delta = er32(COLC);
3340 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003341 adapter->stats.colc += hw->mac.collision_delta;
3342
3343 adapter->stats.algnerrc += er32(ALGNERRC);
3344 adapter->stats.rxerrc += er32(RXERRC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003345 if ((hw->phy.type == e1000_phy_82578) ||
3346 (hw->phy.type == e1000_phy_82577)) {
3347 e1e_rphy(hw, HV_TNCRS_UPPER, &phy_data);
3348 e1e_rphy(hw, HV_TNCRS_LOWER, &phy_data);
3349 adapter->stats.tncrs += phy_data;
3350 } else {
3351 if ((hw->mac.type != e1000_82574) &&
3352 (hw->mac.type != e1000_82583))
3353 adapter->stats.tncrs += er32(TNCRS);
3354 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003355 adapter->stats.cexterr += er32(CEXTERR);
3356 adapter->stats.tsctc += er32(TSCTC);
3357 adapter->stats.tsctfc += er32(TSCTFC);
3358
Auke Kokbc7f75f2007-09-17 12:30:59 -07003359 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003360 netdev->stats.multicast = adapter->stats.mprc;
3361 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003362
3363 /* Rx Errors */
3364
Bruce Allanad680762008-03-28 09:15:03 -07003365 /*
3366 * RLEC on some newer hardware can be incorrect so build
3367 * our own version based on RUC and ROC
3368 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003369 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003370 adapter->stats.crcerrs + adapter->stats.algnerrc +
3371 adapter->stats.ruc + adapter->stats.roc +
3372 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003373 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003374 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003375 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3376 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3377 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003378
3379 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003380 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003381 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003382 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3383 netdev->stats.tx_window_errors = adapter->stats.latecol;
3384 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003385
3386 /* Tx Dropped needs to be maintained elsewhere */
3387
Auke Kokbc7f75f2007-09-17 12:30:59 -07003388 /* Management Stats */
3389 adapter->stats.mgptc += er32(MGTPTC);
3390 adapter->stats.mgprc += er32(MGTPRC);
3391 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003392}
3393
Bruce Allan7c257692008-04-23 11:09:00 -07003394/**
3395 * e1000_phy_read_status - Update the PHY register status snapshot
3396 * @adapter: board private structure
3397 **/
3398static void e1000_phy_read_status(struct e1000_adapter *adapter)
3399{
3400 struct e1000_hw *hw = &adapter->hw;
3401 struct e1000_phy_regs *phy = &adapter->phy_regs;
3402 int ret_val;
Bruce Allan7c257692008-04-23 11:09:00 -07003403
3404 if ((er32(STATUS) & E1000_STATUS_LU) &&
3405 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
3406 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
3407 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
3408 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
3409 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
3410 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
3411 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
3412 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
3413 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
3414 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003415 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07003416 } else {
3417 /*
3418 * Do not read PHY registers if link is not up
3419 * Set values to typical power-on defaults
3420 */
3421 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
3422 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
3423 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
3424 BMSR_ERCAP);
3425 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
3426 ADVERTISE_ALL | ADVERTISE_CSMA);
3427 phy->lpa = 0;
3428 phy->expansion = EXPANSION_ENABLENPAGE;
3429 phy->ctrl1000 = ADVERTISE_1000FULL;
3430 phy->stat1000 = 0;
3431 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
3432 }
Bruce Allan7c257692008-04-23 11:09:00 -07003433}
3434
Auke Kokbc7f75f2007-09-17 12:30:59 -07003435static void e1000_print_link_info(struct e1000_adapter *adapter)
3436{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003437 struct e1000_hw *hw = &adapter->hw;
3438 u32 ctrl = er32(CTRL);
3439
Bruce Allan8f12fe82008-11-21 16:54:43 -08003440 /* Link status message must follow this format for user tools */
3441 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
3442 "Flow Control: %s\n",
3443 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003444 adapter->link_speed,
3445 (adapter->link_duplex == FULL_DUPLEX) ?
3446 "Full Duplex" : "Half Duplex",
3447 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
3448 "RX/TX" :
3449 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
3450 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003451}
3452
Bruce Allana20e4cf2008-11-21 17:01:35 -08003453bool e1000_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003454{
3455 struct e1000_hw *hw = &adapter->hw;
3456 bool link_active = 0;
3457 s32 ret_val = 0;
3458
3459 /*
3460 * get_link_status is set on LSC (link status) interrupt or
3461 * Rx sequence error interrupt. get_link_status will stay
3462 * false until the check_for_link establishes link
3463 * for copper adapters ONLY
3464 */
3465 switch (hw->phy.media_type) {
3466 case e1000_media_type_copper:
3467 if (hw->mac.get_link_status) {
3468 ret_val = hw->mac.ops.check_for_link(hw);
3469 link_active = !hw->mac.get_link_status;
3470 } else {
3471 link_active = 1;
3472 }
3473 break;
3474 case e1000_media_type_fiber:
3475 ret_val = hw->mac.ops.check_for_link(hw);
3476 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
3477 break;
3478 case e1000_media_type_internal_serdes:
3479 ret_val = hw->mac.ops.check_for_link(hw);
3480 link_active = adapter->hw.mac.serdes_has_link;
3481 break;
3482 default:
3483 case e1000_media_type_unknown:
3484 break;
3485 }
3486
3487 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
3488 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
3489 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003490 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003491 }
3492
3493 return link_active;
3494}
3495
3496static void e1000e_enable_receives(struct e1000_adapter *adapter)
3497{
3498 /* make sure the receive unit is started */
3499 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
3500 (adapter->flags & FLAG_RX_RESTART_NOW)) {
3501 struct e1000_hw *hw = &adapter->hw;
3502 u32 rctl = er32(RCTL);
3503 ew32(RCTL, rctl | E1000_RCTL_EN);
3504 adapter->flags &= ~FLAG_RX_RESTART_NOW;
3505 }
3506}
3507
Auke Kokbc7f75f2007-09-17 12:30:59 -07003508/**
3509 * e1000_watchdog - Timer Call-back
3510 * @data: pointer to adapter cast into an unsigned long
3511 **/
3512static void e1000_watchdog(unsigned long data)
3513{
3514 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
3515
3516 /* Do the rest outside of interrupt context */
3517 schedule_work(&adapter->watchdog_task);
3518
3519 /* TODO: make this use queue_delayed_work() */
3520}
3521
3522static void e1000_watchdog_task(struct work_struct *work)
3523{
3524 struct e1000_adapter *adapter = container_of(work,
3525 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003526 struct net_device *netdev = adapter->netdev;
3527 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08003528 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003529 struct e1000_ring *tx_ring = adapter->tx_ring;
3530 struct e1000_hw *hw = &adapter->hw;
3531 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003532 int tx_pending = 0;
3533
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003534 link = e1000_has_link(adapter);
3535 if ((netif_carrier_ok(netdev)) && link) {
3536 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003537 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003538 }
3539
3540 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
3541 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
3542 e1000_update_mng_vlan(adapter);
3543
Auke Kokbc7f75f2007-09-17 12:30:59 -07003544 if (link) {
3545 if (!netif_carrier_ok(netdev)) {
3546 bool txb2b = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003547 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07003548 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003549 mac->ops.get_link_up_info(&adapter->hw,
3550 &adapter->link_speed,
3551 &adapter->link_duplex);
3552 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003553 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07003554 * On supported PHYs, check for duplex mismatch only
3555 * if link has autonegotiated at 10/100 half
3556 */
3557 if ((hw->phy.type == e1000_phy_igp_3 ||
3558 hw->phy.type == e1000_phy_bm) &&
3559 (hw->mac.autoneg == true) &&
3560 (adapter->link_speed == SPEED_10 ||
3561 adapter->link_speed == SPEED_100) &&
3562 (adapter->link_duplex == HALF_DUPLEX)) {
3563 u16 autoneg_exp;
3564
3565 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
3566
3567 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
3568 e_info("Autonegotiated half duplex but"
3569 " link partner cannot autoneg. "
3570 " Try forcing full duplex if "
3571 "link gets many collisions.\n");
3572 }
3573
3574 /*
Bruce Allanad680762008-03-28 09:15:03 -07003575 * tweak tx_queue_len according to speed/duplex
3576 * and adjust the timeout factor
3577 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003578 netdev->tx_queue_len = adapter->tx_queue_len;
3579 adapter->tx_timeout_factor = 1;
3580 switch (adapter->link_speed) {
3581 case SPEED_10:
3582 txb2b = 0;
3583 netdev->tx_queue_len = 10;
Bruce Allan10f1b492008-08-08 18:36:01 -07003584 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003585 break;
3586 case SPEED_100:
3587 txb2b = 0;
3588 netdev->tx_queue_len = 100;
3589 /* maybe add some timeout factor ? */
3590 break;
3591 }
3592
Bruce Allanad680762008-03-28 09:15:03 -07003593 /*
3594 * workaround: re-program speed mode bit after
3595 * link-up event
3596 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003597 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
3598 !txb2b) {
3599 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003600 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003601 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003602 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003603 }
3604
Bruce Allanad680762008-03-28 09:15:03 -07003605 /*
3606 * disable TSO for pcie and 10/100 speeds, to avoid
3607 * some hardware issues
3608 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003609 if (!(adapter->flags & FLAG_TSO_FORCE)) {
3610 switch (adapter->link_speed) {
3611 case SPEED_10:
3612 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003613 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003614 netdev->features &= ~NETIF_F_TSO;
3615 netdev->features &= ~NETIF_F_TSO6;
3616 break;
3617 case SPEED_1000:
3618 netdev->features |= NETIF_F_TSO;
3619 netdev->features |= NETIF_F_TSO6;
3620 break;
3621 default:
3622 /* oops */
3623 break;
3624 }
3625 }
3626
Bruce Allanad680762008-03-28 09:15:03 -07003627 /*
3628 * enable transmits in the hardware, need to do this
3629 * after setting TARC(0)
3630 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003631 tctl = er32(TCTL);
3632 tctl |= E1000_TCTL_EN;
3633 ew32(TCTL, tctl);
3634
Bruce Allan75eb0fa2008-11-21 16:53:51 -08003635 /*
3636 * Perform any post-link-up configuration before
3637 * reporting link up.
3638 */
3639 if (phy->ops.cfg_on_link_up)
3640 phy->ops.cfg_on_link_up(hw);
3641
Auke Kokbc7f75f2007-09-17 12:30:59 -07003642 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003643
3644 if (!test_bit(__E1000_DOWN, &adapter->state))
3645 mod_timer(&adapter->phy_info_timer,
3646 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003647 }
3648 } else {
3649 if (netif_carrier_ok(netdev)) {
3650 adapter->link_speed = 0;
3651 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08003652 /* Link status message must follow this format */
3653 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
3654 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003655 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656 if (!test_bit(__E1000_DOWN, &adapter->state))
3657 mod_timer(&adapter->phy_info_timer,
3658 round_jiffies(jiffies + 2 * HZ));
3659
3660 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3661 schedule_work(&adapter->reset_task);
3662 }
3663 }
3664
3665link_up:
3666 e1000e_update_stats(adapter);
3667
3668 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
3669 adapter->tpt_old = adapter->stats.tpt;
3670 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
3671 adapter->colc_old = adapter->stats.colc;
3672
Bruce Allan7c257692008-04-23 11:09:00 -07003673 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
3674 adapter->gorc_old = adapter->stats.gorc;
3675 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
3676 adapter->gotc_old = adapter->stats.gotc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003677
3678 e1000e_update_adaptive(&adapter->hw);
3679
3680 if (!netif_carrier_ok(netdev)) {
3681 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
3682 tx_ring->count);
3683 if (tx_pending) {
Bruce Allanad680762008-03-28 09:15:03 -07003684 /*
3685 * We've lost link, so the controller stops DMA,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003686 * but we've got queued Tx work that's never going
3687 * to get done, so reset controller to flush Tx.
Bruce Allanad680762008-03-28 09:15:03 -07003688 * (Do the reset outside of interrupt context).
3689 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003690 adapter->tx_timeout_count++;
3691 schedule_work(&adapter->reset_task);
Jesse Brandeburgc2d5ab42009-05-07 11:07:35 +00003692 /* return immediately since reset is imminent */
3693 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003694 }
3695 }
3696
Bruce Allanad680762008-03-28 09:15:03 -07003697 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07003698 if (adapter->msix_entries)
3699 ew32(ICS, adapter->rx_ring->ims_val);
3700 else
3701 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003702
3703 /* Force detection of hung controller every watchdog period */
3704 adapter->detect_tx_hung = 1;
3705
Bruce Allanad680762008-03-28 09:15:03 -07003706 /*
3707 * With 82571 controllers, LAA may be overwritten due to controller
3708 * reset from the other port. Set the appropriate LAA in RAR[0]
3709 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003710 if (e1000e_get_laa_state_82571(hw))
3711 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
3712
3713 /* Reset the timer */
3714 if (!test_bit(__E1000_DOWN, &adapter->state))
3715 mod_timer(&adapter->watchdog_timer,
3716 round_jiffies(jiffies + 2 * HZ));
3717}
3718
3719#define E1000_TX_FLAGS_CSUM 0x00000001
3720#define E1000_TX_FLAGS_VLAN 0x00000002
3721#define E1000_TX_FLAGS_TSO 0x00000004
3722#define E1000_TX_FLAGS_IPV4 0x00000008
3723#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
3724#define E1000_TX_FLAGS_VLAN_SHIFT 16
3725
3726static int e1000_tso(struct e1000_adapter *adapter,
3727 struct sk_buff *skb)
3728{
3729 struct e1000_ring *tx_ring = adapter->tx_ring;
3730 struct e1000_context_desc *context_desc;
3731 struct e1000_buffer *buffer_info;
3732 unsigned int i;
3733 u32 cmd_length = 0;
3734 u16 ipcse = 0, tucse, mss;
3735 u8 ipcss, ipcso, tucss, tucso, hdr_len;
3736 int err;
3737
3738 if (skb_is_gso(skb)) {
3739 if (skb_header_cloned(skb)) {
3740 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3741 if (err)
3742 return err;
3743 }
3744
3745 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3746 mss = skb_shinfo(skb)->gso_size;
3747 if (skb->protocol == htons(ETH_P_IP)) {
3748 struct iphdr *iph = ip_hdr(skb);
3749 iph->tot_len = 0;
3750 iph->check = 0;
3751 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3752 iph->daddr, 0,
3753 IPPROTO_TCP,
3754 0);
3755 cmd_length = E1000_TXD_CMD_IP;
3756 ipcse = skb_transport_offset(skb) - 1;
3757 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3758 ipv6_hdr(skb)->payload_len = 0;
3759 tcp_hdr(skb)->check =
3760 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3761 &ipv6_hdr(skb)->daddr,
3762 0, IPPROTO_TCP, 0);
3763 ipcse = 0;
3764 }
3765 ipcss = skb_network_offset(skb);
3766 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
3767 tucss = skb_transport_offset(skb);
3768 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
3769 tucse = 0;
3770
3771 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
3772 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
3773
3774 i = tx_ring->next_to_use;
3775 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3776 buffer_info = &tx_ring->buffer_info[i];
3777
3778 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3779 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3780 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3781 context_desc->upper_setup.tcp_fields.tucss = tucss;
3782 context_desc->upper_setup.tcp_fields.tucso = tucso;
3783 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3784 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3785 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3786 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3787
3788 buffer_info->time_stamp = jiffies;
3789 buffer_info->next_to_watch = i;
3790
3791 i++;
3792 if (i == tx_ring->count)
3793 i = 0;
3794 tx_ring->next_to_use = i;
3795
3796 return 1;
3797 }
3798
3799 return 0;
3800}
3801
3802static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
3803{
3804 struct e1000_ring *tx_ring = adapter->tx_ring;
3805 struct e1000_context_desc *context_desc;
3806 struct e1000_buffer *buffer_info;
3807 unsigned int i;
3808 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07003809 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00003810 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003811
Dave Grahamaf807c82008-10-09 14:28:58 -07003812 if (skb->ip_summed != CHECKSUM_PARTIAL)
3813 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003814
Arthur Jones5f66f202009-03-19 01:13:08 +00003815 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
3816 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
3817 else
3818 protocol = skb->protocol;
3819
Arthur Jones3f518392009-03-20 15:56:35 -07003820 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08003821 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07003822 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3823 cmd_len |= E1000_TXD_CMD_TCP;
3824 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08003825 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07003826 /* XXX not handling all IPV6 headers */
3827 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3828 cmd_len |= E1000_TXD_CMD_TCP;
3829 break;
3830 default:
3831 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00003832 e_warn("checksum_partial proto=%x!\n",
3833 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07003834 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003835 }
3836
Dave Grahamaf807c82008-10-09 14:28:58 -07003837 css = skb_transport_offset(skb);
3838
3839 i = tx_ring->next_to_use;
3840 buffer_info = &tx_ring->buffer_info[i];
3841 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3842
3843 context_desc->lower_setup.ip_config = 0;
3844 context_desc->upper_setup.tcp_fields.tucss = css;
3845 context_desc->upper_setup.tcp_fields.tucso =
3846 css + skb->csum_offset;
3847 context_desc->upper_setup.tcp_fields.tucse = 0;
3848 context_desc->tcp_seg_setup.data = 0;
3849 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
3850
3851 buffer_info->time_stamp = jiffies;
3852 buffer_info->next_to_watch = i;
3853
3854 i++;
3855 if (i == tx_ring->count)
3856 i = 0;
3857 tx_ring->next_to_use = i;
3858
3859 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003860}
3861
3862#define E1000_MAX_PER_TXD 8192
3863#define E1000_MAX_TXD_PWR 12
3864
3865static int e1000_tx_map(struct e1000_adapter *adapter,
3866 struct sk_buff *skb, unsigned int first,
3867 unsigned int max_per_txd, unsigned int nr_frags,
3868 unsigned int mss)
3869{
3870 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003871 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003872 unsigned int len = skb_headlen(skb);
3873 unsigned int offset, size, count = 0, i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003874 unsigned int f;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003875 dma_addr_t *map;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003876
3877 i = tx_ring->next_to_use;
3878
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003879 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
3880 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
3881 adapter->tx_dma_failed++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003882 return 0;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003883 }
3884
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003885 map = skb_shinfo(skb)->dma_maps;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003886 offset = 0;
3887
Auke Kokbc7f75f2007-09-17 12:30:59 -07003888 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003889 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07003890 size = min(len, max_per_txd);
3891
Auke Kokbc7f75f2007-09-17 12:30:59 -07003892 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003893 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003894 buffer_info->next_to_watch = i;
Eric Dumazet042a53a2009-06-05 04:04:16 +00003895 buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003896 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003897
3898 len -= size;
3899 offset += size;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003900
3901 if (len) {
3902 i++;
3903 if (i == tx_ring->count)
3904 i = 0;
3905 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003906 }
3907
3908 for (f = 0; f < nr_frags; f++) {
3909 struct skb_frag_struct *frag;
3910
3911 frag = &skb_shinfo(skb)->frags[f];
3912 len = frag->size;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08003913 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003914
3915 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00003916 i++;
3917 if (i == tx_ring->count)
3918 i = 0;
3919
Auke Kokbc7f75f2007-09-17 12:30:59 -07003920 buffer_info = &tx_ring->buffer_info[i];
3921 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003922
3923 buffer_info->length = size;
3924 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003925 buffer_info->next_to_watch = i;
Eric Dumazet042a53a2009-06-05 04:04:16 +00003926 buffer_info->dma = map[f] + offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003927
3928 len -= size;
3929 offset += size;
3930 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003931 }
3932 }
3933
Auke Kokbc7f75f2007-09-17 12:30:59 -07003934 tx_ring->buffer_info[i].skb = skb;
3935 tx_ring->buffer_info[first].next_to_watch = i;
3936
3937 return count;
3938}
3939
3940static void e1000_tx_queue(struct e1000_adapter *adapter,
3941 int tx_flags, int count)
3942{
3943 struct e1000_ring *tx_ring = adapter->tx_ring;
3944 struct e1000_tx_desc *tx_desc = NULL;
3945 struct e1000_buffer *buffer_info;
3946 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3947 unsigned int i;
3948
3949 if (tx_flags & E1000_TX_FLAGS_TSO) {
3950 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3951 E1000_TXD_CMD_TSE;
3952 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3953
3954 if (tx_flags & E1000_TX_FLAGS_IPV4)
3955 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3956 }
3957
3958 if (tx_flags & E1000_TX_FLAGS_CSUM) {
3959 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3960 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3961 }
3962
3963 if (tx_flags & E1000_TX_FLAGS_VLAN) {
3964 txd_lower |= E1000_TXD_CMD_VLE;
3965 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3966 }
3967
3968 i = tx_ring->next_to_use;
3969
3970 while (count--) {
3971 buffer_info = &tx_ring->buffer_info[i];
3972 tx_desc = E1000_TX_DESC(*tx_ring, i);
3973 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3974 tx_desc->lower.data =
3975 cpu_to_le32(txd_lower | buffer_info->length);
3976 tx_desc->upper.data = cpu_to_le32(txd_upper);
3977
3978 i++;
3979 if (i == tx_ring->count)
3980 i = 0;
3981 }
3982
3983 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3984
Bruce Allanad680762008-03-28 09:15:03 -07003985 /*
3986 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07003987 * know there are new descriptors to fetch. (Only
3988 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07003989 * such as IA-64).
3990 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003991 wmb();
3992
3993 tx_ring->next_to_use = i;
3994 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07003995 /*
3996 * we need this if more than one processor can write to our tail
3997 * at a time, it synchronizes IO on IA64/Altix systems
3998 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003999 mmiowb();
4000}
4001
4002#define MINIMUM_DHCP_PACKET_SIZE 282
4003static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4004 struct sk_buff *skb)
4005{
4006 struct e1000_hw *hw = &adapter->hw;
4007 u16 length, offset;
4008
4009 if (vlan_tx_tag_present(skb)) {
4010 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id)
4011 && (adapter->hw.mng_cookie.status &
4012 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4013 return 0;
4014 }
4015
4016 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4017 return 0;
4018
4019 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4020 return 0;
4021
4022 {
4023 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4024 struct udphdr *udp;
4025
4026 if (ip->protocol != IPPROTO_UDP)
4027 return 0;
4028
4029 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4030 if (ntohs(udp->dest) != 67)
4031 return 0;
4032
4033 offset = (u8 *)udp + 8 - skb->data;
4034 length = skb->len - offset;
4035 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4036 }
4037
4038 return 0;
4039}
4040
4041static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4042{
4043 struct e1000_adapter *adapter = netdev_priv(netdev);
4044
4045 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004046 /*
4047 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004048 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004049 * but since that doesn't exist yet, just open code it.
4050 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004051 smp_mb();
4052
Bruce Allanad680762008-03-28 09:15:03 -07004053 /*
4054 * We need to check again in a case another CPU has just
4055 * made room available.
4056 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004057 if (e1000_desc_unused(adapter->tx_ring) < size)
4058 return -EBUSY;
4059
4060 /* A reprieve! */
4061 netif_start_queue(netdev);
4062 ++adapter->restart_queue;
4063 return 0;
4064}
4065
4066static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4067{
4068 struct e1000_adapter *adapter = netdev_priv(netdev);
4069
4070 if (e1000_desc_unused(adapter->tx_ring) >= size)
4071 return 0;
4072 return __e1000_maybe_stop_tx(netdev, size);
4073}
4074
4075#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004076static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4077 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004078{
4079 struct e1000_adapter *adapter = netdev_priv(netdev);
4080 struct e1000_ring *tx_ring = adapter->tx_ring;
4081 unsigned int first;
4082 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4083 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4084 unsigned int tx_flags = 0;
Auke Kok4e6c7092007-10-05 14:15:23 -07004085 unsigned int len = skb->len - skb->data_len;
Auke Kok4e6c7092007-10-05 14:15:23 -07004086 unsigned int nr_frags;
4087 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088 int count = 0;
4089 int tso;
4090 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004091
4092 if (test_bit(__E1000_DOWN, &adapter->state)) {
4093 dev_kfree_skb_any(skb);
4094 return NETDEV_TX_OK;
4095 }
4096
4097 if (skb->len <= 0) {
4098 dev_kfree_skb_any(skb);
4099 return NETDEV_TX_OK;
4100 }
4101
4102 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004103 /*
4104 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004105 * make sure there is enough room in the FIFO before
4106 * initiating the DMA for each buffer. The calc is:
4107 * 4 = ceil(buffer len/mss). To make sure we don't
4108 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004109 * drops.
4110 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004111 if (mss) {
4112 u8 hdr_len;
4113 max_per_txd = min(mss << 2, max_per_txd);
4114 max_txd_pwr = fls(max_per_txd) - 1;
4115
Bruce Allanad680762008-03-28 09:15:03 -07004116 /*
4117 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4118 * points to just header, pull a few bytes of payload from
4119 * frags into skb->data
4120 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004121 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004122 /*
4123 * we do this workaround for ES2LAN, but it is un-necessary,
4124 * avoiding it could save a lot of cycles
4125 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004126 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004127 unsigned int pull_size;
4128
4129 pull_size = min((unsigned int)4, skb->data_len);
4130 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004131 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004132 dev_kfree_skb_any(skb);
4133 return NETDEV_TX_OK;
4134 }
4135 len = skb->len - skb->data_len;
4136 }
4137 }
4138
4139 /* reserve a descriptor for the offload context */
4140 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4141 count++;
4142 count++;
4143
4144 count += TXD_USE_COUNT(len, max_txd_pwr);
4145
4146 nr_frags = skb_shinfo(skb)->nr_frags;
4147 for (f = 0; f < nr_frags; f++)
4148 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4149 max_txd_pwr);
4150
4151 if (adapter->hw.mac.tx_pkt_filtering)
4152 e1000_transfer_dhcp_info(adapter, skb);
4153
Bruce Allanad680762008-03-28 09:15:03 -07004154 /*
4155 * need: count + 2 desc gap to keep tail from touching
4156 * head, otherwise try next time
4157 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004158 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004159 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004160
4161 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4162 tx_flags |= E1000_TX_FLAGS_VLAN;
4163 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4164 }
4165
4166 first = tx_ring->next_to_use;
4167
4168 tso = e1000_tso(adapter, skb);
4169 if (tso < 0) {
4170 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004171 return NETDEV_TX_OK;
4172 }
4173
4174 if (tso)
4175 tx_flags |= E1000_TX_FLAGS_TSO;
4176 else if (e1000_tx_csum(adapter, skb))
4177 tx_flags |= E1000_TX_FLAGS_CSUM;
4178
Bruce Allanad680762008-03-28 09:15:03 -07004179 /*
4180 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004181 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004182 * no longer assume, we must.
4183 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004184 if (skb->protocol == htons(ETH_P_IP))
4185 tx_flags |= E1000_TX_FLAGS_IPV4;
4186
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004187 /* if count is 0 then mapping error has occured */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004188 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004189 if (count) {
4190 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004191 /* Make sure there is space in the ring for the next send. */
4192 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4193
4194 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004195 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004196 tx_ring->buffer_info[first].time_stamp = 0;
4197 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004198 }
4199
Auke Kokbc7f75f2007-09-17 12:30:59 -07004200 return NETDEV_TX_OK;
4201}
4202
4203/**
4204 * e1000_tx_timeout - Respond to a Tx Hang
4205 * @netdev: network interface device structure
4206 **/
4207static void e1000_tx_timeout(struct net_device *netdev)
4208{
4209 struct e1000_adapter *adapter = netdev_priv(netdev);
4210
4211 /* Do the reset outside of interrupt context */
4212 adapter->tx_timeout_count++;
4213 schedule_work(&adapter->reset_task);
4214}
4215
4216static void e1000_reset_task(struct work_struct *work)
4217{
4218 struct e1000_adapter *adapter;
4219 adapter = container_of(work, struct e1000_adapter, reset_task);
4220
4221 e1000e_reinit_locked(adapter);
4222}
4223
4224/**
4225 * e1000_get_stats - Get System Network Statistics
4226 * @netdev: network interface device structure
4227 *
4228 * Returns the address of the device statistics structure.
4229 * The statistics are actually updated from the timer callback.
4230 **/
4231static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
4232{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004233 /* only return the current stats */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004234 return &netdev->stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004235}
4236
4237/**
4238 * e1000_change_mtu - Change the Maximum Transfer Unit
4239 * @netdev: network interface device structure
4240 * @new_mtu: new value for maximum frame size
4241 *
4242 * Returns 0 on success, negative on failure
4243 **/
4244static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4245{
4246 struct e1000_adapter *adapter = netdev_priv(netdev);
4247 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4248
Bruce Allan2adc55c2009-06-02 11:28:58 +00004249 /* Jumbo frame support */
4250 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
4251 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
4252 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004253 return -EINVAL;
4254 }
4255
Bruce Allan2adc55c2009-06-02 11:28:58 +00004256 /* Supported frame sizes */
4257 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
4258 (max_frame > adapter->max_hw_frame_size)) {
4259 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004260 return -EINVAL;
4261 }
4262
4263 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4264 msleep(1);
4265 /* e1000e_down has a dependency on max_frame_size */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004266 adapter->max_frame_size = max_frame;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004267 if (netif_running(netdev))
4268 e1000e_down(adapter);
4269
Bruce Allanad680762008-03-28 09:15:03 -07004270 /*
4271 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07004272 * means we reserve 2 more, this pushes us to allocate from the next
4273 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07004274 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004275 * However with the new *_jumbo_rx* routines, jumbo receives will use
4276 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07004277 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004278
4279 if (max_frame <= 256)
4280 adapter->rx_buffer_len = 256;
4281 else if (max_frame <= 512)
4282 adapter->rx_buffer_len = 512;
4283 else if (max_frame <= 1024)
4284 adapter->rx_buffer_len = 1024;
4285 else if (max_frame <= 2048)
4286 adapter->rx_buffer_len = 2048;
4287 else
4288 adapter->rx_buffer_len = 4096;
4289
4290 /* adjust allocation if LPE protects us, and we aren't using SBP */
4291 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
4292 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
4293 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07004294 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004295
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004296 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004297 netdev->mtu = new_mtu;
4298
4299 if (netif_running(netdev))
4300 e1000e_up(adapter);
4301 else
4302 e1000e_reset(adapter);
4303
4304 clear_bit(__E1000_RESETTING, &adapter->state);
4305
4306 return 0;
4307}
4308
4309static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4310 int cmd)
4311{
4312 struct e1000_adapter *adapter = netdev_priv(netdev);
4313 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004314
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004315 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004316 return -EOPNOTSUPP;
4317
4318 switch (cmd) {
4319 case SIOCGMIIPHY:
4320 data->phy_id = adapter->hw.phy.addr;
4321 break;
4322 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00004323 e1000_phy_read_status(adapter);
4324
Bruce Allan7c257692008-04-23 11:09:00 -07004325 switch (data->reg_num & 0x1F) {
4326 case MII_BMCR:
4327 data->val_out = adapter->phy_regs.bmcr;
4328 break;
4329 case MII_BMSR:
4330 data->val_out = adapter->phy_regs.bmsr;
4331 break;
4332 case MII_PHYSID1:
4333 data->val_out = (adapter->hw.phy.id >> 16);
4334 break;
4335 case MII_PHYSID2:
4336 data->val_out = (adapter->hw.phy.id & 0xFFFF);
4337 break;
4338 case MII_ADVERTISE:
4339 data->val_out = adapter->phy_regs.advertise;
4340 break;
4341 case MII_LPA:
4342 data->val_out = adapter->phy_regs.lpa;
4343 break;
4344 case MII_EXPANSION:
4345 data->val_out = adapter->phy_regs.expansion;
4346 break;
4347 case MII_CTRL1000:
4348 data->val_out = adapter->phy_regs.ctrl1000;
4349 break;
4350 case MII_STAT1000:
4351 data->val_out = adapter->phy_regs.stat1000;
4352 break;
4353 case MII_ESTATUS:
4354 data->val_out = adapter->phy_regs.estatus;
4355 break;
4356 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004357 return -EIO;
4358 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004359 break;
4360 case SIOCSMIIREG:
4361 default:
4362 return -EOPNOTSUPP;
4363 }
4364 return 0;
4365}
4366
4367static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4368{
4369 switch (cmd) {
4370 case SIOCGMIIPHY:
4371 case SIOCGMIIREG:
4372 case SIOCSMIIREG:
4373 return e1000_mii_ioctl(netdev, ifr, cmd);
4374 default:
4375 return -EOPNOTSUPP;
4376 }
4377}
4378
Bruce Allana4f58f52009-06-02 11:29:18 +00004379static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
4380{
4381 struct e1000_hw *hw = &adapter->hw;
4382 u32 i, mac_reg;
4383 u16 phy_reg;
4384 int retval = 0;
4385
4386 /* copy MAC RARs to PHY RARs */
4387 for (i = 0; i < adapter->hw.mac.rar_entry_count; i++) {
4388 mac_reg = er32(RAL(i));
4389 e1e_wphy(hw, BM_RAR_L(i), (u16)(mac_reg & 0xFFFF));
4390 e1e_wphy(hw, BM_RAR_M(i), (u16)((mac_reg >> 16) & 0xFFFF));
4391 mac_reg = er32(RAH(i));
4392 e1e_wphy(hw, BM_RAR_H(i), (u16)(mac_reg & 0xFFFF));
4393 e1e_wphy(hw, BM_RAR_CTRL(i), (u16)((mac_reg >> 16) & 0xFFFF));
4394 }
4395
4396 /* copy MAC MTA to PHY MTA */
4397 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
4398 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
4399 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
4400 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
4401 }
4402
4403 /* configure PHY Rx Control register */
4404 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
4405 mac_reg = er32(RCTL);
4406 if (mac_reg & E1000_RCTL_UPE)
4407 phy_reg |= BM_RCTL_UPE;
4408 if (mac_reg & E1000_RCTL_MPE)
4409 phy_reg |= BM_RCTL_MPE;
4410 phy_reg &= ~(BM_RCTL_MO_MASK);
4411 if (mac_reg & E1000_RCTL_MO_3)
4412 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
4413 << BM_RCTL_MO_SHIFT);
4414 if (mac_reg & E1000_RCTL_BAM)
4415 phy_reg |= BM_RCTL_BAM;
4416 if (mac_reg & E1000_RCTL_PMCF)
4417 phy_reg |= BM_RCTL_PMCF;
4418 mac_reg = er32(CTRL);
4419 if (mac_reg & E1000_CTRL_RFCE)
4420 phy_reg |= BM_RCTL_RFCE;
4421 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
4422
4423 /* enable PHY wakeup in MAC register */
4424 ew32(WUFC, wufc);
4425 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
4426
4427 /* configure and enable PHY wakeup in PHY registers */
4428 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
4429 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
4430
4431 /* activate PHY wakeup */
4432 retval = hw->phy.ops.acquire_phy(hw);
4433 if (retval) {
4434 e_err("Could not acquire PHY\n");
4435 return retval;
4436 }
4437 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4438 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
4439 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
4440 if (retval) {
4441 e_err("Could not read PHY page 769\n");
4442 goto out;
4443 }
4444 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
4445 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
4446 if (retval)
4447 e_err("Could not set PHY Host Wakeup bit\n");
4448out:
4449 hw->phy.ops.release_phy(hw);
4450
4451 return retval;
4452}
4453
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004454static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004455{
4456 struct net_device *netdev = pci_get_drvdata(pdev);
4457 struct e1000_adapter *adapter = netdev_priv(netdev);
4458 struct e1000_hw *hw = &adapter->hw;
4459 u32 ctrl, ctrl_ext, rctl, status;
4460 u32 wufc = adapter->wol;
4461 int retval = 0;
4462
4463 netif_device_detach(netdev);
4464
4465 if (netif_running(netdev)) {
4466 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
4467 e1000e_down(adapter);
4468 e1000_free_irq(adapter);
4469 }
Bruce Allan4662e822008-08-26 18:37:06 -07004470 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004471
4472 retval = pci_save_state(pdev);
4473 if (retval)
4474 return retval;
4475
4476 status = er32(STATUS);
4477 if (status & E1000_STATUS_LU)
4478 wufc &= ~E1000_WUFC_LNKC;
4479
4480 if (wufc) {
4481 e1000_setup_rctl(adapter);
4482 e1000_set_multi(netdev);
4483
4484 /* turn on all-multi mode if wake on multicast is enabled */
4485 if (wufc & E1000_WUFC_MC) {
4486 rctl = er32(RCTL);
4487 rctl |= E1000_RCTL_MPE;
4488 ew32(RCTL, rctl);
4489 }
4490
4491 ctrl = er32(CTRL);
4492 /* advertise wake from D3Cold */
4493 #define E1000_CTRL_ADVD3WUC 0x00100000
4494 /* phy power management enable */
4495 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00004496 ctrl |= E1000_CTRL_ADVD3WUC;
4497 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
4498 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004499 ew32(CTRL, ctrl);
4500
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004501 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
4502 adapter->hw.phy.media_type ==
4503 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004504 /* keep the laser running in D3 */
4505 ctrl_ext = er32(CTRL_EXT);
4506 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4507 ew32(CTRL_EXT, ctrl_ext);
4508 }
4509
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004510 if (adapter->flags & FLAG_IS_ICH)
4511 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
4512
Auke Kokbc7f75f2007-09-17 12:30:59 -07004513 /* Allow time for pending master requests to run */
4514 e1000e_disable_pcie_master(&adapter->hw);
4515
Bruce Allan82776a42009-08-14 14:35:33 +00004516 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00004517 /* enable wakeup by the PHY */
4518 retval = e1000_init_phy_wakeup(adapter, wufc);
4519 if (retval)
4520 return retval;
4521 } else {
4522 /* enable wakeup by the MAC */
4523 ew32(WUFC, wufc);
4524 ew32(WUC, E1000_WUC_PME_EN);
4525 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004526 } else {
4527 ew32(WUC, 0);
4528 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004529 }
4530
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004531 *enable_wake = !!wufc;
4532
Auke Kokbc7f75f2007-09-17 12:30:59 -07004533 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00004534 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
4535 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004536 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004537
4538 if (adapter->hw.phy.type == e1000_phy_igp_3)
4539 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
4540
Bruce Allanad680762008-03-28 09:15:03 -07004541 /*
4542 * Release control of h/w to f/w. If f/w is AMT enabled, this
4543 * would have already happened in close and is redundant.
4544 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004545 e1000_release_hw_control(adapter);
4546
4547 pci_disable_device(pdev);
4548
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004549 return 0;
4550}
4551
4552static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
4553{
4554 if (sleep && wake) {
4555 pci_prepare_to_sleep(pdev);
4556 return;
4557 }
4558
4559 pci_wake_from_d3(pdev, wake);
4560 pci_set_power_state(pdev, PCI_D3hot);
4561}
4562
4563static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
4564 bool wake)
4565{
4566 struct net_device *netdev = pci_get_drvdata(pdev);
4567 struct e1000_adapter *adapter = netdev_priv(netdev);
4568
Alexander Duyck005cbdf2008-11-21 16:49:10 -08004569 /*
4570 * The pci-e switch on some quad port adapters will report a
4571 * correctable error when the MAC transitions from D0 to D3. To
4572 * prevent this we need to mask off the correctable errors on the
4573 * downstream port of the pci-e switch.
4574 */
4575 if (adapter->flags & FLAG_IS_QUAD_PORT) {
4576 struct pci_dev *us_dev = pdev->bus->self;
4577 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
4578 u16 devctl;
4579
4580 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
4581 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
4582 (devctl & ~PCI_EXP_DEVCTL_CERE));
4583
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004584 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08004585
4586 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
4587 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004588 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08004589 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004590}
4591
Auke Kok1eae4eb2007-10-31 15:22:00 -07004592static void e1000e_disable_l1aspm(struct pci_dev *pdev)
4593{
4594 int pos;
Auke Kok1eae4eb2007-10-31 15:22:00 -07004595 u16 val;
4596
4597 /*
4598 * 82573 workaround - disable L1 ASPM on mobile chipsets
4599 *
4600 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
4601 * resulting in lost data or garbage information on the pci-e link
4602 * level. This could result in (false) bad EEPROM checksum errors,
4603 * long ping times (up to 2s) or even a system freeze/hang.
4604 *
4605 * Unfortunately this feature saves about 1W power consumption when
4606 * active.
4607 */
4608 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
Auke Kok1eae4eb2007-10-31 15:22:00 -07004609 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val);
4610 if (val & 0x2) {
4611 dev_warn(&pdev->dev, "Disabling L1 ASPM\n");
4612 val &= ~0x2;
4613 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val);
4614 }
4615}
4616
Auke Kokbc7f75f2007-09-17 12:30:59 -07004617#ifdef CONFIG_PM
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004618static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4619{
4620 int retval;
4621 bool wake;
4622
4623 retval = __e1000_shutdown(pdev, &wake);
4624 if (!retval)
4625 e1000_complete_shutdown(pdev, true, wake);
4626
4627 return retval;
4628}
4629
Auke Kokbc7f75f2007-09-17 12:30:59 -07004630static int e1000_resume(struct pci_dev *pdev)
4631{
4632 struct net_device *netdev = pci_get_drvdata(pdev);
4633 struct e1000_adapter *adapter = netdev_priv(netdev);
4634 struct e1000_hw *hw = &adapter->hw;
4635 u32 err;
4636
4637 pci_set_power_state(pdev, PCI_D0);
4638 pci_restore_state(pdev);
Auke Kok1eae4eb2007-10-31 15:22:00 -07004639 e1000e_disable_l1aspm(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004640
Bruce Allanf0f422e2008-08-04 17:21:53 -07004641 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004642 if (err) {
4643 dev_err(&pdev->dev,
4644 "Cannot enable PCI device from suspend\n");
4645 return err;
4646 }
4647
4648 pci_set_master(pdev);
4649
4650 pci_enable_wake(pdev, PCI_D3hot, 0);
4651 pci_enable_wake(pdev, PCI_D3cold, 0);
4652
Bruce Allan4662e822008-08-26 18:37:06 -07004653 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004654 if (netif_running(netdev)) {
4655 err = e1000_request_irq(adapter);
4656 if (err)
4657 return err;
4658 }
4659
4660 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00004661
4662 /* report the system wakeup cause from S3/S4 */
4663 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
4664 u16 phy_data;
4665
4666 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
4667 if (phy_data) {
4668 e_info("PHY Wakeup cause - %s\n",
4669 phy_data & E1000_WUS_EX ? "Unicast Packet" :
4670 phy_data & E1000_WUS_MC ? "Multicast Packet" :
4671 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
4672 phy_data & E1000_WUS_MAG ? "Magic Packet" :
4673 phy_data & E1000_WUS_LNKC ? "Link Status "
4674 " Change" : "other");
4675 }
4676 e1e_wphy(&adapter->hw, BM_WUS, ~0);
4677 } else {
4678 u32 wus = er32(WUS);
4679 if (wus) {
4680 e_info("MAC Wakeup cause - %s\n",
4681 wus & E1000_WUS_EX ? "Unicast Packet" :
4682 wus & E1000_WUS_MC ? "Multicast Packet" :
4683 wus & E1000_WUS_BC ? "Broadcast Packet" :
4684 wus & E1000_WUS_MAG ? "Magic Packet" :
4685 wus & E1000_WUS_LNKC ? "Link Status Change" :
4686 "other");
4687 }
4688 ew32(WUS, ~0);
4689 }
4690
Auke Kokbc7f75f2007-09-17 12:30:59 -07004691 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004692
4693 e1000_init_manageability(adapter);
4694
4695 if (netif_running(netdev))
4696 e1000e_up(adapter);
4697
4698 netif_device_attach(netdev);
4699
Bruce Allanad680762008-03-28 09:15:03 -07004700 /*
4701 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004702 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07004703 * under the control of the driver.
4704 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004705 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004706 e1000_get_hw_control(adapter);
4707
4708 return 0;
4709}
4710#endif
4711
4712static void e1000_shutdown(struct pci_dev *pdev)
4713{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00004714 bool wake = false;
4715
4716 __e1000_shutdown(pdev, &wake);
4717
4718 if (system_state == SYSTEM_POWER_OFF)
4719 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004720}
4721
4722#ifdef CONFIG_NET_POLL_CONTROLLER
4723/*
4724 * Polling 'interrupt' - used by things like netconsole to send skbs
4725 * without having to re-enable interrupts. It's not called while
4726 * the interrupt routine is executing.
4727 */
4728static void e1000_netpoll(struct net_device *netdev)
4729{
4730 struct e1000_adapter *adapter = netdev_priv(netdev);
4731
4732 disable_irq(adapter->pdev->irq);
4733 e1000_intr(adapter->pdev->irq, netdev);
4734
Auke Kokbc7f75f2007-09-17 12:30:59 -07004735 enable_irq(adapter->pdev->irq);
4736}
4737#endif
4738
4739/**
4740 * e1000_io_error_detected - called when PCI error is detected
4741 * @pdev: Pointer to PCI device
4742 * @state: The current pci connection state
4743 *
4744 * This function is called after a PCI bus error affecting
4745 * this device has been detected.
4746 */
4747static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
4748 pci_channel_state_t state)
4749{
4750 struct net_device *netdev = pci_get_drvdata(pdev);
4751 struct e1000_adapter *adapter = netdev_priv(netdev);
4752
4753 netif_device_detach(netdev);
4754
Mike Masonc93b5a72009-06-30 12:45:53 +00004755 if (state == pci_channel_io_perm_failure)
4756 return PCI_ERS_RESULT_DISCONNECT;
4757
Auke Kokbc7f75f2007-09-17 12:30:59 -07004758 if (netif_running(netdev))
4759 e1000e_down(adapter);
4760 pci_disable_device(pdev);
4761
4762 /* Request a slot slot reset. */
4763 return PCI_ERS_RESULT_NEED_RESET;
4764}
4765
4766/**
4767 * e1000_io_slot_reset - called after the pci bus has been reset.
4768 * @pdev: Pointer to PCI device
4769 *
4770 * Restart the card from scratch, as if from a cold-boot. Implementation
4771 * resembles the first-half of the e1000_resume routine.
4772 */
4773static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4774{
4775 struct net_device *netdev = pci_get_drvdata(pdev);
4776 struct e1000_adapter *adapter = netdev_priv(netdev);
4777 struct e1000_hw *hw = &adapter->hw;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004778 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00004779 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004780
Auke Kok1eae4eb2007-10-31 15:22:00 -07004781 e1000e_disable_l1aspm(pdev);
Bruce Allanf0f422e2008-08-04 17:21:53 -07004782 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004783 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004784 dev_err(&pdev->dev,
4785 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00004786 result = PCI_ERS_RESULT_DISCONNECT;
4787 } else {
4788 pci_set_master(pdev);
4789 pci_restore_state(pdev);
4790
4791 pci_enable_wake(pdev, PCI_D3hot, 0);
4792 pci_enable_wake(pdev, PCI_D3cold, 0);
4793
4794 e1000e_reset(adapter);
4795 ew32(WUS, ~0);
4796 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004797 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004798
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00004799 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004800
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00004801 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004802}
4803
4804/**
4805 * e1000_io_resume - called when traffic can start flowing again.
4806 * @pdev: Pointer to PCI device
4807 *
4808 * This callback is called when the error recovery driver tells us that
4809 * its OK to resume normal operation. Implementation resembles the
4810 * second-half of the e1000_resume routine.
4811 */
4812static void e1000_io_resume(struct pci_dev *pdev)
4813{
4814 struct net_device *netdev = pci_get_drvdata(pdev);
4815 struct e1000_adapter *adapter = netdev_priv(netdev);
4816
4817 e1000_init_manageability(adapter);
4818
4819 if (netif_running(netdev)) {
4820 if (e1000e_up(adapter)) {
4821 dev_err(&pdev->dev,
4822 "can't bring device back up after reset\n");
4823 return;
4824 }
4825 }
4826
4827 netif_device_attach(netdev);
4828
Bruce Allanad680762008-03-28 09:15:03 -07004829 /*
4830 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004831 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07004832 * under the control of the driver.
4833 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004834 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004835 e1000_get_hw_control(adapter);
4836
4837}
4838
4839static void e1000_print_device_info(struct e1000_adapter *adapter)
4840{
4841 struct e1000_hw *hw = &adapter->hw;
4842 struct net_device *netdev = adapter->netdev;
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004843 u32 pba_num;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004844
4845 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07004846 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004847 /* bus width */
4848 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
4849 "Width x1"),
4850 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07004851 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004852 e_info("Intel(R) PRO/%s Network Connection\n",
4853 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004854 e1000e_read_pba_num(hw, &pba_num);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004855 e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4856 hw->mac.type, hw->phy.type, (pba_num >> 8), (pba_num & 0xff));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004857}
4858
Auke Kok10aa4c02008-08-04 17:21:20 -07004859static void e1000_eeprom_checks(struct e1000_adapter *adapter)
4860{
4861 struct e1000_hw *hw = &adapter->hw;
4862 int ret_val;
4863 u16 buf = 0;
4864
4865 if (hw->mac.type != e1000_82573)
4866 return;
4867
4868 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08004869 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07004870 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07004871 dev_warn(&adapter->pdev->dev,
4872 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07004873 }
4874
4875 ret_val = e1000_read_nvm(hw, NVM_INIT_3GIO_3, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08004876 if (!ret_val && (le16_to_cpu(buf) & (3 << 2))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07004877 /* ASPM enable */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07004878 dev_warn(&adapter->pdev->dev,
4879 "Warning: detected ASPM enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07004880 }
4881}
4882
Stephen Hemminger651c2462008-11-19 21:57:48 -08004883static const struct net_device_ops e1000e_netdev_ops = {
4884 .ndo_open = e1000_open,
4885 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08004886 .ndo_start_xmit = e1000_xmit_frame,
Stephen Hemminger651c2462008-11-19 21:57:48 -08004887 .ndo_get_stats = e1000_get_stats,
4888 .ndo_set_multicast_list = e1000_set_multi,
4889 .ndo_set_mac_address = e1000_set_mac,
4890 .ndo_change_mtu = e1000_change_mtu,
4891 .ndo_do_ioctl = e1000_ioctl,
4892 .ndo_tx_timeout = e1000_tx_timeout,
4893 .ndo_validate_addr = eth_validate_addr,
4894
4895 .ndo_vlan_rx_register = e1000_vlan_rx_register,
4896 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
4897 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
4898#ifdef CONFIG_NET_POLL_CONTROLLER
4899 .ndo_poll_controller = e1000_netpoll,
4900#endif
4901};
4902
Auke Kokbc7f75f2007-09-17 12:30:59 -07004903/**
4904 * e1000_probe - Device Initialization Routine
4905 * @pdev: PCI device information struct
4906 * @ent: entry in e1000_pci_tbl
4907 *
4908 * Returns 0 on success, negative on failure
4909 *
4910 * e1000_probe initializes an adapter identified by a pci_dev structure.
4911 * The OS initialization, configuring of the adapter private structure,
4912 * and a hardware reset occur.
4913 **/
4914static int __devinit e1000_probe(struct pci_dev *pdev,
4915 const struct pci_device_id *ent)
4916{
4917 struct net_device *netdev;
4918 struct e1000_adapter *adapter;
4919 struct e1000_hw *hw;
4920 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05004921 resource_size_t mmio_start, mmio_len;
4922 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004923
4924 static int cards_found;
4925 int i, err, pci_using_dac;
4926 u16 eeprom_data = 0;
4927 u16 eeprom_apme_mask = E1000_EEPROM_APME;
4928
Auke Kok1eae4eb2007-10-31 15:22:00 -07004929 e1000e_disable_l1aspm(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004930
Bruce Allanf0f422e2008-08-04 17:21:53 -07004931 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004932 if (err)
4933 return err;
4934
4935 pci_using_dac = 0;
Yang Hongyang6a355282009-04-06 19:01:13 -07004936 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004937 if (!err) {
Yang Hongyang6a355282009-04-06 19:01:13 -07004938 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004939 if (!err)
4940 pci_using_dac = 1;
4941 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07004942 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004943 if (err) {
4944 err = pci_set_consistent_dma_mask(pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07004945 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004946 if (err) {
4947 dev_err(&pdev->dev, "No usable DMA "
4948 "configuration, aborting\n");
4949 goto err_dma;
4950 }
4951 }
4952 }
4953
Arjan van de Vene8de1482008-10-22 19:55:31 -07004954 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07004955 pci_select_bars(pdev, IORESOURCE_MEM),
4956 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004957 if (err)
4958 goto err_pci_reg;
4959
Xiaotian Feng68eac462009-08-14 14:35:52 +00004960 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07004961 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00004962
Auke Kokbc7f75f2007-09-17 12:30:59 -07004963 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08004964 /* PCI config space info */
4965 err = pci_save_state(pdev);
4966 if (err)
4967 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004968
4969 err = -ENOMEM;
4970 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
4971 if (!netdev)
4972 goto err_alloc_etherdev;
4973
Auke Kokbc7f75f2007-09-17 12:30:59 -07004974 SET_NETDEV_DEV(netdev, &pdev->dev);
4975
4976 pci_set_drvdata(pdev, netdev);
4977 adapter = netdev_priv(netdev);
4978 hw = &adapter->hw;
4979 adapter->netdev = netdev;
4980 adapter->pdev = pdev;
4981 adapter->ei = ei;
4982 adapter->pba = ei->pba;
4983 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00004984 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004985 adapter->hw.adapter = adapter;
4986 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00004987 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004988 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
4989
4990 mmio_start = pci_resource_start(pdev, 0);
4991 mmio_len = pci_resource_len(pdev, 0);
4992
4993 err = -EIO;
4994 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
4995 if (!adapter->hw.hw_addr)
4996 goto err_ioremap;
4997
4998 if ((adapter->flags & FLAG_HAS_FLASH) &&
4999 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5000 flash_start = pci_resource_start(pdev, 1);
5001 flash_len = pci_resource_len(pdev, 1);
5002 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5003 if (!adapter->hw.flash_address)
5004 goto err_flashmap;
5005 }
5006
5007 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005008 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005009 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005010 netdev->watchdog_timeo = 5 * HZ;
5011 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005012 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5013
5014 netdev->mem_start = mmio_start;
5015 netdev->mem_end = mmio_start + mmio_len;
5016
5017 adapter->bd_number = cards_found++;
5018
Bruce Allan4662e822008-08-26 18:37:06 -07005019 e1000e_check_options(adapter);
5020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005021 /* setup adapter struct */
5022 err = e1000_sw_init(adapter);
5023 if (err)
5024 goto err_sw_init;
5025
5026 err = -EIO;
5027
5028 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5029 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5030 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5031
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005032 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005033 if (err)
5034 goto err_hw_init;
5035
Bruce Allan4a770352008-10-01 17:18:35 -07005036 if ((adapter->flags & FLAG_IS_ICH) &&
5037 (adapter->flags & FLAG_READ_ONLY_NVM))
5038 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5039
Auke Kokbc7f75f2007-09-17 12:30:59 -07005040 hw->mac.ops.get_bus_info(&adapter->hw);
5041
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005042 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005043
5044 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005045 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005046 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5047 adapter->hw.phy.disable_polarity_correction = 0;
5048 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5049 }
5050
5051 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005052 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005053
5054 netdev->features = NETIF_F_SG |
5055 NETIF_F_HW_CSUM |
5056 NETIF_F_HW_VLAN_TX |
5057 NETIF_F_HW_VLAN_RX;
5058
5059 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5060 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5061
5062 netdev->features |= NETIF_F_TSO;
5063 netdev->features |= NETIF_F_TSO6;
5064
Jeff Kirshera5136e22008-06-05 04:07:28 -07005065 netdev->vlan_features |= NETIF_F_TSO;
5066 netdev->vlan_features |= NETIF_F_TSO6;
5067 netdev->vlan_features |= NETIF_F_HW_CSUM;
5068 netdev->vlan_features |= NETIF_F_SG;
5069
Auke Kokbc7f75f2007-09-17 12:30:59 -07005070 if (pci_using_dac)
5071 netdev->features |= NETIF_F_HIGHDMA;
5072
Auke Kokbc7f75f2007-09-17 12:30:59 -07005073 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5074 adapter->flags |= FLAG_MNG_PT_ENABLED;
5075
Bruce Allanad680762008-03-28 09:15:03 -07005076 /*
5077 * before reading the NVM, reset the controller to
5078 * put the device in a known good starting state
5079 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005080 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5081
5082 /*
5083 * systems with ASPM and others may see the checksum fail on the first
5084 * attempt. Let's give it a few tries
5085 */
5086 for (i = 0;; i++) {
5087 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5088 break;
5089 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005090 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005091 err = -EIO;
5092 goto err_eeprom;
5093 }
5094 }
5095
Auke Kok10aa4c02008-08-04 17:21:20 -07005096 e1000_eeprom_checks(adapter);
5097
Auke Kokbc7f75f2007-09-17 12:30:59 -07005098 /* copy the MAC address out of the NVM */
5099 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005100 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005101
5102 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5103 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5104
5105 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07005106 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107 err = -EIO;
5108 goto err_eeprom;
5109 }
5110
5111 init_timer(&adapter->watchdog_timer);
5112 adapter->watchdog_timer.function = &e1000_watchdog;
5113 adapter->watchdog_timer.data = (unsigned long) adapter;
5114
5115 init_timer(&adapter->phy_info_timer);
5116 adapter->phy_info_timer.function = &e1000_update_phy_info;
5117 adapter->phy_info_timer.data = (unsigned long) adapter;
5118
5119 INIT_WORK(&adapter->reset_task, e1000_reset_task);
5120 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07005121 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
5122 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005123
Auke Kokbc7f75f2007-09-17 12:30:59 -07005124 /* Initialize link parameters. User can change them with ethtool */
5125 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07005126 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08005127 adapter->hw.fc.requested_mode = e1000_fc_default;
5128 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005129 adapter->hw.phy.autoneg_advertised = 0x2f;
5130
5131 /* ring size defaults */
5132 adapter->rx_ring->count = 256;
5133 adapter->tx_ring->count = 256;
5134
5135 /*
5136 * Initial Wake on LAN setting - If APM wake is enabled in
5137 * the EEPROM, enable the ACPI Magic Packet filter
5138 */
5139 if (adapter->flags & FLAG_APME_IN_WUC) {
5140 /* APME bit in EEPROM is mapped to WUC.APME */
5141 eeprom_data = er32(WUC);
5142 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allana4f58f52009-06-02 11:29:18 +00005143 if (eeprom_data & E1000_WUC_PHY_WAKE)
5144 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005145 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
5146 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
5147 (adapter->hw.bus.func == 1))
5148 e1000_read_nvm(&adapter->hw,
5149 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
5150 else
5151 e1000_read_nvm(&adapter->hw,
5152 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
5153 }
5154
5155 /* fetch WoL from EEPROM */
5156 if (eeprom_data & eeprom_apme_mask)
5157 adapter->eeprom_wol |= E1000_WUFC_MAG;
5158
5159 /*
5160 * now that we have the eeprom settings, apply the special cases
5161 * where the eeprom may be wrong or the board simply won't support
5162 * wake on lan on a particular port
5163 */
5164 if (!(adapter->flags & FLAG_HAS_WOL))
5165 adapter->eeprom_wol = 0;
5166
5167 /* initialize the wol settings based on the eeprom settings */
5168 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00005169 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005170
Bruce Allan84527592008-11-21 17:00:22 -08005171 /* save off EEPROM version number */
5172 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
5173
Auke Kokbc7f75f2007-09-17 12:30:59 -07005174 /* reset the hardware with the new settings */
5175 e1000e_reset(adapter);
5176
Bruce Allanad680762008-03-28 09:15:03 -07005177 /*
5178 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005179 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005180 * under the control of the driver.
5181 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005182 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005183 e1000_get_hw_control(adapter);
5184
Auke Kokbc7f75f2007-09-17 12:30:59 -07005185 strcpy(netdev->name, "eth%d");
5186 err = register_netdev(netdev);
5187 if (err)
5188 goto err_register;
5189
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00005190 /* carrier off reporting is important to ethtool even BEFORE open */
5191 netif_carrier_off(netdev);
5192
Auke Kokbc7f75f2007-09-17 12:30:59 -07005193 e1000_print_device_info(adapter);
5194
5195 return 0;
5196
5197err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005198 if (!(adapter->flags & FLAG_HAS_AMT))
5199 e1000_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005200err_eeprom:
5201 if (!e1000_check_reset_block(&adapter->hw))
5202 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005203err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005204
Auke Kokbc7f75f2007-09-17 12:30:59 -07005205 kfree(adapter->tx_ring);
5206 kfree(adapter->rx_ring);
5207err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005208 if (adapter->hw.flash_address)
5209 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00005210 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005211err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005212 iounmap(adapter->hw.hw_addr);
5213err_ioremap:
5214 free_netdev(netdev);
5215err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07005216 pci_release_selected_regions(pdev,
5217 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005218err_pci_reg:
5219err_dma:
5220 pci_disable_device(pdev);
5221 return err;
5222}
5223
5224/**
5225 * e1000_remove - Device Removal Routine
5226 * @pdev: PCI device information struct
5227 *
5228 * e1000_remove is called by the PCI subsystem to alert the driver
5229 * that it should release a PCI device. The could be caused by a
5230 * Hot-Plug event, or because the driver is going to be removed from
5231 * memory.
5232 **/
5233static void __devexit e1000_remove(struct pci_dev *pdev)
5234{
5235 struct net_device *netdev = pci_get_drvdata(pdev);
5236 struct e1000_adapter *adapter = netdev_priv(netdev);
5237
Bruce Allanad680762008-03-28 09:15:03 -07005238 /*
5239 * flush_scheduled work may reschedule our watchdog task, so
5240 * explicitly disable watchdog tasks from being rescheduled
5241 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005242 set_bit(__E1000_DOWN, &adapter->state);
5243 del_timer_sync(&adapter->watchdog_timer);
5244 del_timer_sync(&adapter->phy_info_timer);
5245
5246 flush_scheduled_work();
5247
Bruce Allanad680762008-03-28 09:15:03 -07005248 /*
5249 * Release control of h/w to f/w. If f/w is AMT enabled, this
5250 * would have already happened in close and is redundant.
5251 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005252 e1000_release_hw_control(adapter);
5253
5254 unregister_netdev(netdev);
5255
5256 if (!e1000_check_reset_block(&adapter->hw))
5257 e1000_phy_hw_reset(&adapter->hw);
5258
Bruce Allan4662e822008-08-26 18:37:06 -07005259 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005260 kfree(adapter->tx_ring);
5261 kfree(adapter->rx_ring);
5262
5263 iounmap(adapter->hw.hw_addr);
5264 if (adapter->hw.flash_address)
5265 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07005266 pci_release_selected_regions(pdev,
5267 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005268
5269 free_netdev(netdev);
5270
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005271 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07005272 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005273
Auke Kokbc7f75f2007-09-17 12:30:59 -07005274 pci_disable_device(pdev);
5275}
5276
5277/* PCI Error Recovery (ERS) */
5278static struct pci_error_handlers e1000_err_handler = {
5279 .error_detected = e1000_io_error_detected,
5280 .slot_reset = e1000_io_slot_reset,
5281 .resume = e1000_io_resume,
5282};
5283
5284static struct pci_device_id e1000_pci_tbl[] = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005285 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
5286 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
5287 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
5288 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
5289 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
5290 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07005291 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
5292 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
5293 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07005294
Auke Kokbc7f75f2007-09-17 12:30:59 -07005295 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
5296 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
5297 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
5298 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07005299
Auke Kokbc7f75f2007-09-17 12:30:59 -07005300 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
5301 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
5302 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07005303
Bruce Allan4662e822008-08-26 18:37:06 -07005304 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07005305 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00005306 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07005307
Auke Kokbc7f75f2007-09-17 12:30:59 -07005308 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
5309 board_80003es2lan },
5310 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
5311 board_80003es2lan },
5312 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
5313 board_80003es2lan },
5314 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
5315 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07005316
Auke Kokbc7f75f2007-09-17 12:30:59 -07005317 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
5318 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
5319 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
5320 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
5321 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
5322 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
5323 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07005324
Auke Kokbc7f75f2007-09-17 12:30:59 -07005325 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
5326 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
5327 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
5328 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
5329 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07005330 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005331 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
5332 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
5333 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
5334
5335 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
5336 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
5337 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07005338
Bruce Allanf4187b52008-08-26 18:36:50 -07005339 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
5340 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
5341
Bruce Allana4f58f52009-06-02 11:29:18 +00005342 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
5343 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
5344 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
5345 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
5346
Auke Kokbc7f75f2007-09-17 12:30:59 -07005347 { } /* terminate list */
5348};
5349MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
5350
5351/* PCI Device API Driver */
5352static struct pci_driver e1000_driver = {
5353 .name = e1000e_driver_name,
5354 .id_table = e1000_pci_tbl,
5355 .probe = e1000_probe,
5356 .remove = __devexit_p(e1000_remove),
5357#ifdef CONFIG_PM
Bruce Allanad680762008-03-28 09:15:03 -07005358 /* Power Management Hooks */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005359 .suspend = e1000_suspend,
5360 .resume = e1000_resume,
5361#endif
5362 .shutdown = e1000_shutdown,
5363 .err_handler = &e1000_err_handler
5364};
5365
5366/**
5367 * e1000_init_module - Driver Registration Routine
5368 *
5369 * e1000_init_module is the first routine called when the driver is
5370 * loaded. All it does is register with the PCI subsystem.
5371 **/
5372static int __init e1000_init_module(void)
5373{
5374 int ret;
5375 printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
5376 e1000e_driver_name, e1000e_driver_version);
Bruce Allanad680762008-03-28 09:15:03 -07005377 printk(KERN_INFO "%s: Copyright (c) 1999-2008 Intel Corporation.\n",
Auke Kokbc7f75f2007-09-17 12:30:59 -07005378 e1000e_driver_name);
5379 ret = pci_register_driver(&e1000_driver);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005380 pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name,
5381 PM_QOS_DEFAULT_VALUE);
5382
Auke Kokbc7f75f2007-09-17 12:30:59 -07005383 return ret;
5384}
5385module_init(e1000_init_module);
5386
5387/**
5388 * e1000_exit_module - Driver Exit Cleanup Routine
5389 *
5390 * e1000_exit_module is called just before the driver is removed
5391 * from memory.
5392 **/
5393static void __exit e1000_exit_module(void)
5394{
5395 pci_unregister_driver(&e1000_driver);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005396 pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005397}
5398module_exit(e1000_exit_module);
5399
5400
5401MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
5402MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
5403MODULE_LICENSE("GPL");
5404MODULE_VERSION(DRV_VERSION);
5405
5406/* e1000_main.c */