blob: f10252b055d42ed278d50489c3dddd0838ec9744 [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>
Auke Kokbc7f75f2007-09-17 12:30:59 -070047
48#include "e1000.h"
49
Jesse Brandeburg6f92a6a2008-10-02 16:33:45 -070050#define DRV_VERSION "0.3.3.3-k6"
Auke Kokbc7f75f2007-09-17 12:30:59 -070051char e1000e_driver_name[] = "e1000e";
52const char e1000e_driver_version[] = DRV_VERSION;
53
54static const struct e1000_info *e1000_info_tbl[] = {
55 [board_82571] = &e1000_82571_info,
56 [board_82572] = &e1000_82572_info,
57 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070058 [board_82574] = &e1000_82574_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070059 [board_80003es2lan] = &e1000_es2_info,
60 [board_ich8lan] = &e1000_ich8_info,
61 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070062 [board_ich10lan] = &e1000_ich10_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070063};
64
65#ifdef DEBUG
66/**
67 * e1000_get_hw_dev_name - return device name string
68 * used by hardware layer to print debugging information
69 **/
70char *e1000e_get_hw_dev_name(struct e1000_hw *hw)
71{
Auke Kok589c0852007-10-04 11:38:43 -070072 return hw->adapter->netdev->name;
Auke Kokbc7f75f2007-09-17 12:30:59 -070073}
74#endif
75
76/**
77 * e1000_desc_unused - calculate if we have unused descriptors
78 **/
79static int e1000_desc_unused(struct e1000_ring *ring)
80{
81 if (ring->next_to_clean > ring->next_to_use)
82 return ring->next_to_clean - ring->next_to_use - 1;
83
84 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
85}
86
87/**
Bruce Allanad680762008-03-28 09:15:03 -070088 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -070089 * @adapter: board private structure
90 * @status: descriptor status field as written by hardware
91 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
92 * @skb: pointer to sk_buff to be indicated to stack
93 **/
94static void e1000_receive_skb(struct e1000_adapter *adapter,
95 struct net_device *netdev,
96 struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +000097 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -070098{
99 skb->protocol = eth_type_trans(skb, netdev);
100
101 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
102 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -0700103 le16_to_cpu(vlan));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700104 else
105 netif_receive_skb(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700106}
107
108/**
109 * e1000_rx_checksum - Receive Checksum Offload for 82543
110 * @adapter: board private structure
111 * @status_err: receive descriptor status and error fields
112 * @csum: receive descriptor csum field
113 * @sk_buff: socket buffer with received data
114 **/
115static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
116 u32 csum, struct sk_buff *skb)
117{
118 u16 status = (u16)status_err;
119 u8 errors = (u8)(status_err >> 24);
120 skb->ip_summed = CHECKSUM_NONE;
121
122 /* Ignore Checksum bit is set */
123 if (status & E1000_RXD_STAT_IXSM)
124 return;
125 /* TCP/UDP checksum error bit is set */
126 if (errors & E1000_RXD_ERR_TCPE) {
127 /* let the stack verify checksum errors */
128 adapter->hw_csum_err++;
129 return;
130 }
131
132 /* TCP/UDP Checksum has not been calculated */
133 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
134 return;
135
136 /* It must be a TCP or UDP packet with a valid checksum */
137 if (status & E1000_RXD_STAT_TCPCS) {
138 /* TCP checksum is good */
139 skb->ip_summed = CHECKSUM_UNNECESSARY;
140 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700141 /*
142 * IP fragment with UDP payload
143 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700144 * and then put the value in host order for further stack use.
145 */
Al Viroa39fe742007-12-11 19:50:34 +0000146 __sum16 sum = (__force __sum16)htons(csum);
147 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700148 skb->ip_summed = CHECKSUM_COMPLETE;
149 }
150 adapter->hw_csum_good++;
151}
152
153/**
154 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
155 * @adapter: address of board private structure
156 **/
157static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
158 int cleaned_count)
159{
160 struct net_device *netdev = adapter->netdev;
161 struct pci_dev *pdev = adapter->pdev;
162 struct e1000_ring *rx_ring = adapter->rx_ring;
163 struct e1000_rx_desc *rx_desc;
164 struct e1000_buffer *buffer_info;
165 struct sk_buff *skb;
166 unsigned int i;
167 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
168
169 i = rx_ring->next_to_use;
170 buffer_info = &rx_ring->buffer_info[i];
171
172 while (cleaned_count--) {
173 skb = buffer_info->skb;
174 if (skb) {
175 skb_trim(skb, 0);
176 goto map_skb;
177 }
178
179 skb = netdev_alloc_skb(netdev, bufsz);
180 if (!skb) {
181 /* Better luck next round */
182 adapter->alloc_rx_buff_failed++;
183 break;
184 }
185
Bruce Allanad680762008-03-28 09:15:03 -0700186 /*
187 * Make buffer alignment 2 beyond a 16 byte boundary
Auke Kokbc7f75f2007-09-17 12:30:59 -0700188 * this will result in a 16 byte aligned IP header after
189 * the 14 byte MAC header is removed
190 */
191 skb_reserve(skb, NET_IP_ALIGN);
192
193 buffer_info->skb = skb;
194map_skb:
195 buffer_info->dma = pci_map_single(pdev, skb->data,
196 adapter->rx_buffer_len,
197 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700198 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700199 dev_err(&pdev->dev, "RX DMA map failed\n");
200 adapter->rx_dma_failed++;
201 break;
202 }
203
204 rx_desc = E1000_RX_DESC(*rx_ring, i);
205 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
206
207 i++;
208 if (i == rx_ring->count)
209 i = 0;
210 buffer_info = &rx_ring->buffer_info[i];
211 }
212
213 if (rx_ring->next_to_use != i) {
214 rx_ring->next_to_use = i;
215 if (i-- == 0)
216 i = (rx_ring->count - 1);
217
Bruce Allanad680762008-03-28 09:15:03 -0700218 /*
219 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -0700220 * know there are new descriptors to fetch. (Only
221 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -0700222 * such as IA-64).
223 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700224 wmb();
225 writel(i, adapter->hw.hw_addr + rx_ring->tail);
226 }
227}
228
229/**
230 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
231 * @adapter: address of board private structure
232 **/
233static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
234 int cleaned_count)
235{
236 struct net_device *netdev = adapter->netdev;
237 struct pci_dev *pdev = adapter->pdev;
238 union e1000_rx_desc_packet_split *rx_desc;
239 struct e1000_ring *rx_ring = adapter->rx_ring;
240 struct e1000_buffer *buffer_info;
241 struct e1000_ps_page *ps_page;
242 struct sk_buff *skb;
243 unsigned int i, j;
244
245 i = rx_ring->next_to_use;
246 buffer_info = &rx_ring->buffer_info[i];
247
248 while (cleaned_count--) {
249 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
250
251 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700252 ps_page = &buffer_info->ps_pages[j];
253 if (j >= adapter->rx_ps_pages) {
254 /* all unused desc entries get hw null ptr */
Al Viroa39fe742007-12-11 19:50:34 +0000255 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700256 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700257 }
Auke Kok47f44e42007-10-25 13:57:44 -0700258 if (!ps_page->page) {
259 ps_page->page = alloc_page(GFP_ATOMIC);
260 if (!ps_page->page) {
261 adapter->alloc_rx_buff_failed++;
262 goto no_buffers;
263 }
264 ps_page->dma = pci_map_page(pdev,
265 ps_page->page,
266 0, PAGE_SIZE,
267 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700268 if (pci_dma_mapping_error(pdev, ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700269 dev_err(&adapter->pdev->dev,
270 "RX DMA page map failed\n");
271 adapter->rx_dma_failed++;
272 goto no_buffers;
273 }
274 }
275 /*
276 * Refresh the desc even if buffer_addrs
277 * didn't change because each write-back
278 * erases this info.
279 */
280 rx_desc->read.buffer_addr[j+1] =
281 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700282 }
283
284 skb = netdev_alloc_skb(netdev,
285 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
286
287 if (!skb) {
288 adapter->alloc_rx_buff_failed++;
289 break;
290 }
291
Bruce Allanad680762008-03-28 09:15:03 -0700292 /*
293 * Make buffer alignment 2 beyond a 16 byte boundary
Auke Kokbc7f75f2007-09-17 12:30:59 -0700294 * this will result in a 16 byte aligned IP header after
295 * the 14 byte MAC header is removed
296 */
297 skb_reserve(skb, NET_IP_ALIGN);
298
299 buffer_info->skb = skb;
300 buffer_info->dma = pci_map_single(pdev, skb->data,
301 adapter->rx_ps_bsize0,
302 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700303 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700304 dev_err(&pdev->dev, "RX DMA map failed\n");
305 adapter->rx_dma_failed++;
306 /* cleanup skb */
307 dev_kfree_skb_any(skb);
308 buffer_info->skb = NULL;
309 break;
310 }
311
312 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
313
314 i++;
315 if (i == rx_ring->count)
316 i = 0;
317 buffer_info = &rx_ring->buffer_info[i];
318 }
319
320no_buffers:
321 if (rx_ring->next_to_use != i) {
322 rx_ring->next_to_use = i;
323
324 if (!(i--))
325 i = (rx_ring->count - 1);
326
Bruce Allanad680762008-03-28 09:15:03 -0700327 /*
328 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -0700329 * know there are new descriptors to fetch. (Only
330 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -0700331 * such as IA-64).
332 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700333 wmb();
Bruce Allanad680762008-03-28 09:15:03 -0700334 /*
335 * Hardware increments by 16 bytes, but packet split
Auke Kokbc7f75f2007-09-17 12:30:59 -0700336 * descriptors are 32 bytes...so we increment tail
337 * twice as much.
338 */
339 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
340 }
341}
342
343/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700344 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
345 * @adapter: address of board private structure
346 * @rx_ring: pointer to receive ring structure
347 * @cleaned_count: number of buffers to allocate this pass
348 **/
349
350static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
351 int cleaned_count)
352{
353 struct net_device *netdev = adapter->netdev;
354 struct pci_dev *pdev = adapter->pdev;
355 struct e1000_rx_desc *rx_desc;
356 struct e1000_ring *rx_ring = adapter->rx_ring;
357 struct e1000_buffer *buffer_info;
358 struct sk_buff *skb;
359 unsigned int i;
360 unsigned int bufsz = 256 -
361 16 /* for skb_reserve */ -
362 NET_IP_ALIGN;
363
364 i = rx_ring->next_to_use;
365 buffer_info = &rx_ring->buffer_info[i];
366
367 while (cleaned_count--) {
368 skb = buffer_info->skb;
369 if (skb) {
370 skb_trim(skb, 0);
371 goto check_page;
372 }
373
374 skb = netdev_alloc_skb(netdev, bufsz);
375 if (unlikely(!skb)) {
376 /* Better luck next round */
377 adapter->alloc_rx_buff_failed++;
378 break;
379 }
380
381 /* Make buffer alignment 2 beyond a 16 byte boundary
382 * this will result in a 16 byte aligned IP header after
383 * the 14 byte MAC header is removed
384 */
385 skb_reserve(skb, NET_IP_ALIGN);
386
387 buffer_info->skb = skb;
388check_page:
389 /* allocate a new page if necessary */
390 if (!buffer_info->page) {
391 buffer_info->page = alloc_page(GFP_ATOMIC);
392 if (unlikely(!buffer_info->page)) {
393 adapter->alloc_rx_buff_failed++;
394 break;
395 }
396 }
397
398 if (!buffer_info->dma)
399 buffer_info->dma = pci_map_page(pdev,
400 buffer_info->page, 0,
401 PAGE_SIZE,
402 PCI_DMA_FROMDEVICE);
403
404 rx_desc = E1000_RX_DESC(*rx_ring, i);
405 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
406
407 if (unlikely(++i == rx_ring->count))
408 i = 0;
409 buffer_info = &rx_ring->buffer_info[i];
410 }
411
412 if (likely(rx_ring->next_to_use != i)) {
413 rx_ring->next_to_use = i;
414 if (unlikely(i-- == 0))
415 i = (rx_ring->count - 1);
416
417 /* Force memory writes to complete before letting h/w
418 * know there are new descriptors to fetch. (Only
419 * applicable for weak-ordered memory model archs,
420 * such as IA-64). */
421 wmb();
422 writel(i, adapter->hw.hw_addr + rx_ring->tail);
423 }
424}
425
426/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700427 * e1000_clean_rx_irq - Send received data up the network stack; legacy
428 * @adapter: board private structure
429 *
430 * the return value indicates whether actual cleaning was done, there
431 * is no guarantee that everything was cleaned
432 **/
433static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
434 int *work_done, int work_to_do)
435{
436 struct net_device *netdev = adapter->netdev;
437 struct pci_dev *pdev = adapter->pdev;
438 struct e1000_ring *rx_ring = adapter->rx_ring;
439 struct e1000_rx_desc *rx_desc, *next_rxd;
440 struct e1000_buffer *buffer_info, *next_buffer;
441 u32 length;
442 unsigned int i;
443 int cleaned_count = 0;
444 bool cleaned = 0;
445 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
446
447 i = rx_ring->next_to_clean;
448 rx_desc = E1000_RX_DESC(*rx_ring, i);
449 buffer_info = &rx_ring->buffer_info[i];
450
451 while (rx_desc->status & E1000_RXD_STAT_DD) {
452 struct sk_buff *skb;
453 u8 status;
454
455 if (*work_done >= work_to_do)
456 break;
457 (*work_done)++;
458
459 status = rx_desc->status;
460 skb = buffer_info->skb;
461 buffer_info->skb = NULL;
462
463 prefetch(skb->data - NET_IP_ALIGN);
464
465 i++;
466 if (i == rx_ring->count)
467 i = 0;
468 next_rxd = E1000_RX_DESC(*rx_ring, i);
469 prefetch(next_rxd);
470
471 next_buffer = &rx_ring->buffer_info[i];
472
473 cleaned = 1;
474 cleaned_count++;
475 pci_unmap_single(pdev,
476 buffer_info->dma,
477 adapter->rx_buffer_len,
478 PCI_DMA_FROMDEVICE);
479 buffer_info->dma = 0;
480
481 length = le16_to_cpu(rx_desc->length);
482
483 /* !EOP means multiple descriptors were used to store a single
484 * packet, also make sure the frame isn't just CRC only */
485 if (!(status & E1000_RXD_STAT_EOP) || (length <= 4)) {
486 /* All receives must fit into a single buffer */
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700487 e_dbg("%s: Receive packet consumed multiple buffers\n",
488 netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700489 /* recycle */
490 buffer_info->skb = skb;
491 goto next_desc;
492 }
493
494 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
495 /* recycle */
496 buffer_info->skb = skb;
497 goto next_desc;
498 }
499
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000500 /* adjust length to remove Ethernet CRC */
501 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
502 length -= 4;
503
Auke Kokbc7f75f2007-09-17 12:30:59 -0700504 total_rx_bytes += length;
505 total_rx_packets++;
506
Bruce Allanad680762008-03-28 09:15:03 -0700507 /*
508 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700509 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700510 * of reassembly being done in the stack
511 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700512 if (length < copybreak) {
513 struct sk_buff *new_skb =
514 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
515 if (new_skb) {
516 skb_reserve(new_skb, NET_IP_ALIGN);
Bruce Allan808ff672008-08-08 18:35:56 -0700517 skb_copy_to_linear_data_offset(new_skb,
518 -NET_IP_ALIGN,
519 (skb->data -
520 NET_IP_ALIGN),
521 (length +
522 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700523 /* save the skb in buffer_info as good */
524 buffer_info->skb = skb;
525 skb = new_skb;
526 }
527 /* else just continue with the old one */
528 }
529 /* end copybreak code */
530 skb_put(skb, length);
531
532 /* Receive Checksum Offload */
533 e1000_rx_checksum(adapter,
534 (u32)(status) |
535 ((u32)(rx_desc->errors) << 24),
536 le16_to_cpu(rx_desc->csum), skb);
537
538 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
539
540next_desc:
541 rx_desc->status = 0;
542
543 /* return some buffers to hardware, one at a time is too slow */
544 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
545 adapter->alloc_rx_buf(adapter, cleaned_count);
546 cleaned_count = 0;
547 }
548
549 /* use prefetched values */
550 rx_desc = next_rxd;
551 buffer_info = next_buffer;
552 }
553 rx_ring->next_to_clean = i;
554
555 cleaned_count = e1000_desc_unused(rx_ring);
556 if (cleaned_count)
557 adapter->alloc_rx_buf(adapter, cleaned_count);
558
Auke Kokbc7f75f2007-09-17 12:30:59 -0700559 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700560 adapter->total_rx_packets += total_rx_packets;
Auke Kok41988692007-11-13 20:48:36 -0800561 adapter->net_stats.rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700562 adapter->net_stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700563 return cleaned;
564}
565
Auke Kokbc7f75f2007-09-17 12:30:59 -0700566static void e1000_put_txbuf(struct e1000_adapter *adapter,
567 struct e1000_buffer *buffer_info)
568{
569 if (buffer_info->dma) {
570 pci_unmap_page(adapter->pdev, buffer_info->dma,
571 buffer_info->length, PCI_DMA_TODEVICE);
572 buffer_info->dma = 0;
573 }
574 if (buffer_info->skb) {
575 dev_kfree_skb_any(buffer_info->skb);
576 buffer_info->skb = NULL;
577 }
578}
579
580static void e1000_print_tx_hang(struct e1000_adapter *adapter)
581{
582 struct e1000_ring *tx_ring = adapter->tx_ring;
583 unsigned int i = tx_ring->next_to_clean;
584 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
585 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700586
587 /* detected Tx unit hang */
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700588 e_err("Detected Tx Unit Hang:\n"
589 " TDH <%x>\n"
590 " TDT <%x>\n"
591 " next_to_use <%x>\n"
592 " next_to_clean <%x>\n"
593 "buffer_info[next_to_clean]:\n"
594 " time_stamp <%lx>\n"
595 " next_to_watch <%x>\n"
596 " jiffies <%lx>\n"
597 " next_to_watch.status <%x>\n",
598 readl(adapter->hw.hw_addr + tx_ring->head),
599 readl(adapter->hw.hw_addr + tx_ring->tail),
600 tx_ring->next_to_use,
601 tx_ring->next_to_clean,
602 tx_ring->buffer_info[eop].time_stamp,
603 eop,
604 jiffies,
605 eop_desc->upper.fields.status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700606}
607
608/**
609 * e1000_clean_tx_irq - Reclaim resources after transmit completes
610 * @adapter: board private structure
611 *
612 * the return value indicates whether actual cleaning was done, there
613 * is no guarantee that everything was cleaned
614 **/
615static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
616{
617 struct net_device *netdev = adapter->netdev;
618 struct e1000_hw *hw = &adapter->hw;
619 struct e1000_ring *tx_ring = adapter->tx_ring;
620 struct e1000_tx_desc *tx_desc, *eop_desc;
621 struct e1000_buffer *buffer_info;
622 unsigned int i, eop;
623 unsigned int count = 0;
624 bool cleaned = 0;
625 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
626
627 i = tx_ring->next_to_clean;
628 eop = tx_ring->buffer_info[i].next_to_watch;
629 eop_desc = E1000_TX_DESC(*tx_ring, eop);
630
631 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
632 for (cleaned = 0; !cleaned; ) {
633 tx_desc = E1000_TX_DESC(*tx_ring, i);
634 buffer_info = &tx_ring->buffer_info[i];
635 cleaned = (i == eop);
636
637 if (cleaned) {
638 struct sk_buff *skb = buffer_info->skb;
639 unsigned int segs, bytecount;
640 segs = skb_shinfo(skb)->gso_segs ?: 1;
641 /* multiply data chunks by size of headers */
642 bytecount = ((segs - 1) * skb_headlen(skb)) +
643 skb->len;
644 total_tx_packets += segs;
645 total_tx_bytes += bytecount;
646 }
647
648 e1000_put_txbuf(adapter, buffer_info);
649 tx_desc->upper.data = 0;
650
651 i++;
652 if (i == tx_ring->count)
653 i = 0;
654 }
655
656 eop = tx_ring->buffer_info[i].next_to_watch;
657 eop_desc = E1000_TX_DESC(*tx_ring, eop);
658#define E1000_TX_WEIGHT 64
659 /* weight of a sort for tx, to avoid endless transmit cleanup */
660 if (count++ == E1000_TX_WEIGHT)
661 break;
662 }
663
664 tx_ring->next_to_clean = i;
665
666#define TX_WAKE_THRESHOLD 32
667 if (cleaned && netif_carrier_ok(netdev) &&
668 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
669 /* Make sure that anybody stopping the queue after this
670 * sees the new next_to_clean.
671 */
672 smp_mb();
673
674 if (netif_queue_stopped(netdev) &&
675 !(test_bit(__E1000_DOWN, &adapter->state))) {
676 netif_wake_queue(netdev);
677 ++adapter->restart_queue;
678 }
679 }
680
681 if (adapter->detect_tx_hung) {
Bruce Allanad680762008-03-28 09:15:03 -0700682 /*
683 * Detect a transmit hang in hardware, this serializes the
684 * check with the clearing of time_stamp and movement of i
685 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700686 adapter->detect_tx_hung = 0;
687 if (tx_ring->buffer_info[eop].dma &&
688 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp
689 + (adapter->tx_timeout_factor * HZ))
Bruce Allanad680762008-03-28 09:15:03 -0700690 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700691 e1000_print_tx_hang(adapter);
692 netif_stop_queue(netdev);
693 }
694 }
695 adapter->total_tx_bytes += total_tx_bytes;
696 adapter->total_tx_packets += total_tx_packets;
Auke Kok41988692007-11-13 20:48:36 -0800697 adapter->net_stats.tx_bytes += total_tx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700698 adapter->net_stats.tx_packets += total_tx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700699 return cleaned;
700}
701
702/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700703 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
704 * @adapter: board private structure
705 *
706 * the return value indicates whether actual cleaning was done, there
707 * is no guarantee that everything was cleaned
708 **/
709static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
710 int *work_done, int work_to_do)
711{
712 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
713 struct net_device *netdev = adapter->netdev;
714 struct pci_dev *pdev = adapter->pdev;
715 struct e1000_ring *rx_ring = adapter->rx_ring;
716 struct e1000_buffer *buffer_info, *next_buffer;
717 struct e1000_ps_page *ps_page;
718 struct sk_buff *skb;
719 unsigned int i, j;
720 u32 length, staterr;
721 int cleaned_count = 0;
722 bool cleaned = 0;
723 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
724
725 i = rx_ring->next_to_clean;
726 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
727 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
728 buffer_info = &rx_ring->buffer_info[i];
729
730 while (staterr & E1000_RXD_STAT_DD) {
731 if (*work_done >= work_to_do)
732 break;
733 (*work_done)++;
734 skb = buffer_info->skb;
735
736 /* in the packet split case this is header only */
737 prefetch(skb->data - NET_IP_ALIGN);
738
739 i++;
740 if (i == rx_ring->count)
741 i = 0;
742 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
743 prefetch(next_rxd);
744
745 next_buffer = &rx_ring->buffer_info[i];
746
747 cleaned = 1;
748 cleaned_count++;
749 pci_unmap_single(pdev, buffer_info->dma,
750 adapter->rx_ps_bsize0,
751 PCI_DMA_FROMDEVICE);
752 buffer_info->dma = 0;
753
754 if (!(staterr & E1000_RXD_STAT_EOP)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700755 e_dbg("%s: Packet Split buffers didn't pick up the "
756 "full packet\n", netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700757 dev_kfree_skb_irq(skb);
758 goto next_desc;
759 }
760
761 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
762 dev_kfree_skb_irq(skb);
763 goto next_desc;
764 }
765
766 length = le16_to_cpu(rx_desc->wb.middle.length0);
767
768 if (!length) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700769 e_dbg("%s: Last part of the packet spanning multiple "
770 "descriptors\n", netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700771 dev_kfree_skb_irq(skb);
772 goto next_desc;
773 }
774
775 /* Good Receive */
776 skb_put(skb, length);
777
778 {
Bruce Allanad680762008-03-28 09:15:03 -0700779 /*
780 * this looks ugly, but it seems compiler issues make it
781 * more efficient than reusing j
782 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700783 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
784
Bruce Allanad680762008-03-28 09:15:03 -0700785 /*
786 * page alloc/put takes too long and effects small packet
787 * throughput, so unsplit small packets and save the alloc/put
788 * only valid in softirq (napi) context to call kmap_*
789 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700790 if (l1 && (l1 <= copybreak) &&
791 ((length + l1) <= adapter->rx_ps_bsize0)) {
792 u8 *vaddr;
793
Auke Kok47f44e42007-10-25 13:57:44 -0700794 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700795
Bruce Allanad680762008-03-28 09:15:03 -0700796 /*
797 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -0700798 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -0700799 * very long
800 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700801 pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
802 PAGE_SIZE, PCI_DMA_FROMDEVICE);
803 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
804 memcpy(skb_tail_pointer(skb), vaddr, l1);
805 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
806 pci_dma_sync_single_for_device(pdev, ps_page->dma,
807 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kok140a7482007-10-25 13:57:58 -0700808
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000809 /* remove the CRC */
810 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
811 l1 -= 4;
812
Auke Kokbc7f75f2007-09-17 12:30:59 -0700813 skb_put(skb, l1);
814 goto copydone;
815 } /* if */
816 }
817
818 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
819 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
820 if (!length)
821 break;
822
Auke Kok47f44e42007-10-25 13:57:44 -0700823 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700824 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
825 PCI_DMA_FROMDEVICE);
826 ps_page->dma = 0;
827 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
828 ps_page->page = NULL;
829 skb->len += length;
830 skb->data_len += length;
831 skb->truesize += length;
832 }
833
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000834 /* strip the ethernet crc, problem is we're using pages now so
835 * this whole operation can get a little cpu intensive
836 */
837 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
838 pskb_trim(skb, skb->len - 4);
839
Auke Kokbc7f75f2007-09-17 12:30:59 -0700840copydone:
841 total_rx_bytes += skb->len;
842 total_rx_packets++;
843
844 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
845 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
846
847 if (rx_desc->wb.upper.header_status &
848 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
849 adapter->rx_hdr_split++;
850
851 e1000_receive_skb(adapter, netdev, skb,
852 staterr, rx_desc->wb.middle.vlan);
853
854next_desc:
855 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
856 buffer_info->skb = NULL;
857
858 /* return some buffers to hardware, one at a time is too slow */
859 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
860 adapter->alloc_rx_buf(adapter, cleaned_count);
861 cleaned_count = 0;
862 }
863
864 /* use prefetched values */
865 rx_desc = next_rxd;
866 buffer_info = next_buffer;
867
868 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
869 }
870 rx_ring->next_to_clean = i;
871
872 cleaned_count = e1000_desc_unused(rx_ring);
873 if (cleaned_count)
874 adapter->alloc_rx_buf(adapter, cleaned_count);
875
Auke Kokbc7f75f2007-09-17 12:30:59 -0700876 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700877 adapter->total_rx_packets += total_rx_packets;
Auke Kok41988692007-11-13 20:48:36 -0800878 adapter->net_stats.rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700879 adapter->net_stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700880 return cleaned;
881}
882
883/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700884 * e1000_consume_page - helper function
885 **/
886static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
887 u16 length)
888{
889 bi->page = NULL;
890 skb->len += length;
891 skb->data_len += length;
892 skb->truesize += length;
893}
894
895/**
896 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
897 * @adapter: board private structure
898 *
899 * the return value indicates whether actual cleaning was done, there
900 * is no guarantee that everything was cleaned
901 **/
902
903static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
904 int *work_done, int work_to_do)
905{
906 struct net_device *netdev = adapter->netdev;
907 struct pci_dev *pdev = adapter->pdev;
908 struct e1000_ring *rx_ring = adapter->rx_ring;
909 struct e1000_rx_desc *rx_desc, *next_rxd;
910 struct e1000_buffer *buffer_info, *next_buffer;
911 u32 length;
912 unsigned int i;
913 int cleaned_count = 0;
914 bool cleaned = false;
915 unsigned int total_rx_bytes=0, total_rx_packets=0;
916
917 i = rx_ring->next_to_clean;
918 rx_desc = E1000_RX_DESC(*rx_ring, i);
919 buffer_info = &rx_ring->buffer_info[i];
920
921 while (rx_desc->status & E1000_RXD_STAT_DD) {
922 struct sk_buff *skb;
923 u8 status;
924
925 if (*work_done >= work_to_do)
926 break;
927 (*work_done)++;
928
929 status = rx_desc->status;
930 skb = buffer_info->skb;
931 buffer_info->skb = NULL;
932
933 ++i;
934 if (i == rx_ring->count)
935 i = 0;
936 next_rxd = E1000_RX_DESC(*rx_ring, i);
937 prefetch(next_rxd);
938
939 next_buffer = &rx_ring->buffer_info[i];
940
941 cleaned = true;
942 cleaned_count++;
943 pci_unmap_page(pdev, buffer_info->dma, PAGE_SIZE,
944 PCI_DMA_FROMDEVICE);
945 buffer_info->dma = 0;
946
947 length = le16_to_cpu(rx_desc->length);
948
949 /* errors is only valid for DD + EOP descriptors */
950 if (unlikely((status & E1000_RXD_STAT_EOP) &&
951 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
952 /* recycle both page and skb */
953 buffer_info->skb = skb;
954 /* an error means any chain goes out the window
955 * too */
956 if (rx_ring->rx_skb_top)
957 dev_kfree_skb(rx_ring->rx_skb_top);
958 rx_ring->rx_skb_top = NULL;
959 goto next_desc;
960 }
961
962#define rxtop rx_ring->rx_skb_top
963 if (!(status & E1000_RXD_STAT_EOP)) {
964 /* this descriptor is only the beginning (or middle) */
965 if (!rxtop) {
966 /* this is the beginning of a chain */
967 rxtop = skb;
968 skb_fill_page_desc(rxtop, 0, buffer_info->page,
969 0, length);
970 } else {
971 /* this is the middle of a chain */
972 skb_fill_page_desc(rxtop,
973 skb_shinfo(rxtop)->nr_frags,
974 buffer_info->page, 0, length);
975 /* re-use the skb, only consumed the page */
976 buffer_info->skb = skb;
977 }
978 e1000_consume_page(buffer_info, rxtop, length);
979 goto next_desc;
980 } else {
981 if (rxtop) {
982 /* end of the chain */
983 skb_fill_page_desc(rxtop,
984 skb_shinfo(rxtop)->nr_frags,
985 buffer_info->page, 0, length);
986 /* re-use the current skb, we only consumed the
987 * page */
988 buffer_info->skb = skb;
989 skb = rxtop;
990 rxtop = NULL;
991 e1000_consume_page(buffer_info, skb, length);
992 } else {
993 /* no chain, got EOP, this buf is the packet
994 * copybreak to save the put_page/alloc_page */
995 if (length <= copybreak &&
996 skb_tailroom(skb) >= length) {
997 u8 *vaddr;
998 vaddr = kmap_atomic(buffer_info->page,
999 KM_SKB_DATA_SOFTIRQ);
1000 memcpy(skb_tail_pointer(skb), vaddr,
1001 length);
1002 kunmap_atomic(vaddr,
1003 KM_SKB_DATA_SOFTIRQ);
1004 /* re-use the page, so don't erase
1005 * buffer_info->page */
1006 skb_put(skb, length);
1007 } else {
1008 skb_fill_page_desc(skb, 0,
1009 buffer_info->page, 0,
1010 length);
1011 e1000_consume_page(buffer_info, skb,
1012 length);
1013 }
1014 }
1015 }
1016
1017 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1018 e1000_rx_checksum(adapter,
1019 (u32)(status) |
1020 ((u32)(rx_desc->errors) << 24),
1021 le16_to_cpu(rx_desc->csum), skb);
1022
1023 /* probably a little skewed due to removing CRC */
1024 total_rx_bytes += skb->len;
1025 total_rx_packets++;
1026
1027 /* eth type trans needs skb->data to point to something */
1028 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001029 e_err("pskb_may_pull failed.\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001030 dev_kfree_skb(skb);
1031 goto next_desc;
1032 }
1033
1034 e1000_receive_skb(adapter, netdev, skb, status,
1035 rx_desc->special);
1036
1037next_desc:
1038 rx_desc->status = 0;
1039
1040 /* return some buffers to hardware, one at a time is too slow */
1041 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1042 adapter->alloc_rx_buf(adapter, cleaned_count);
1043 cleaned_count = 0;
1044 }
1045
1046 /* use prefetched values */
1047 rx_desc = next_rxd;
1048 buffer_info = next_buffer;
1049 }
1050 rx_ring->next_to_clean = i;
1051
1052 cleaned_count = e1000_desc_unused(rx_ring);
1053 if (cleaned_count)
1054 adapter->alloc_rx_buf(adapter, cleaned_count);
1055
1056 adapter->total_rx_bytes += total_rx_bytes;
1057 adapter->total_rx_packets += total_rx_packets;
1058 adapter->net_stats.rx_bytes += total_rx_bytes;
1059 adapter->net_stats.rx_packets += total_rx_packets;
1060 return cleaned;
1061}
1062
1063/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001064 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1065 * @adapter: board private structure
1066 **/
1067static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1068{
1069 struct e1000_ring *rx_ring = adapter->rx_ring;
1070 struct e1000_buffer *buffer_info;
1071 struct e1000_ps_page *ps_page;
1072 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001073 unsigned int i, j;
1074
1075 /* Free all the Rx ring sk_buffs */
1076 for (i = 0; i < rx_ring->count; i++) {
1077 buffer_info = &rx_ring->buffer_info[i];
1078 if (buffer_info->dma) {
1079 if (adapter->clean_rx == e1000_clean_rx_irq)
1080 pci_unmap_single(pdev, buffer_info->dma,
1081 adapter->rx_buffer_len,
1082 PCI_DMA_FROMDEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001083 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1084 pci_unmap_page(pdev, buffer_info->dma,
1085 PAGE_SIZE,
1086 PCI_DMA_FROMDEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001087 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1088 pci_unmap_single(pdev, buffer_info->dma,
1089 adapter->rx_ps_bsize0,
1090 PCI_DMA_FROMDEVICE);
1091 buffer_info->dma = 0;
1092 }
1093
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001094 if (buffer_info->page) {
1095 put_page(buffer_info->page);
1096 buffer_info->page = NULL;
1097 }
1098
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099 if (buffer_info->skb) {
1100 dev_kfree_skb(buffer_info->skb);
1101 buffer_info->skb = NULL;
1102 }
1103
1104 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001105 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001106 if (!ps_page->page)
1107 break;
1108 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
1109 PCI_DMA_FROMDEVICE);
1110 ps_page->dma = 0;
1111 put_page(ps_page->page);
1112 ps_page->page = NULL;
1113 }
1114 }
1115
1116 /* there also may be some cached data from a chained receive */
1117 if (rx_ring->rx_skb_top) {
1118 dev_kfree_skb(rx_ring->rx_skb_top);
1119 rx_ring->rx_skb_top = NULL;
1120 }
1121
Auke Kokbc7f75f2007-09-17 12:30:59 -07001122 /* Zero out the descriptor ring */
1123 memset(rx_ring->desc, 0, rx_ring->size);
1124
1125 rx_ring->next_to_clean = 0;
1126 rx_ring->next_to_use = 0;
1127
1128 writel(0, adapter->hw.hw_addr + rx_ring->head);
1129 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1130}
1131
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001132static void e1000e_downshift_workaround(struct work_struct *work)
1133{
1134 struct e1000_adapter *adapter = container_of(work,
1135 struct e1000_adapter, downshift_task);
1136
1137 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1138}
1139
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140/**
1141 * e1000_intr_msi - Interrupt Handler
1142 * @irq: interrupt number
1143 * @data: pointer to a network interface device structure
1144 **/
1145static irqreturn_t e1000_intr_msi(int irq, void *data)
1146{
1147 struct net_device *netdev = data;
1148 struct e1000_adapter *adapter = netdev_priv(netdev);
1149 struct e1000_hw *hw = &adapter->hw;
1150 u32 icr = er32(ICR);
1151
Bruce Allanad680762008-03-28 09:15:03 -07001152 /*
1153 * read ICR disables interrupts using IAM
1154 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001155
1156 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
1157 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001158 /*
1159 * ICH8 workaround-- Call gig speed drop workaround on cable
1160 * disconnect (LSC) before accessing any PHY registers
1161 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001162 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1163 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001164 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001165
Bruce Allanad680762008-03-28 09:15:03 -07001166 /*
1167 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001168 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001169 * adapter in watchdog
1170 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001171 if (netif_carrier_ok(netdev) &&
1172 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1173 /* disable receives */
1174 u32 rctl = er32(RCTL);
1175 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001176 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001177 }
1178 /* guard against interrupt when we're going down */
1179 if (!test_bit(__E1000_DOWN, &adapter->state))
1180 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1181 }
1182
1183 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1184 adapter->total_tx_bytes = 0;
1185 adapter->total_tx_packets = 0;
1186 adapter->total_rx_bytes = 0;
1187 adapter->total_rx_packets = 0;
1188 __netif_rx_schedule(netdev, &adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001189 }
1190
1191 return IRQ_HANDLED;
1192}
1193
1194/**
1195 * e1000_intr - Interrupt Handler
1196 * @irq: interrupt number
1197 * @data: pointer to a network interface device structure
1198 **/
1199static irqreturn_t e1000_intr(int irq, void *data)
1200{
1201 struct net_device *netdev = data;
1202 struct e1000_adapter *adapter = netdev_priv(netdev);
1203 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001204 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001205
Auke Kokbc7f75f2007-09-17 12:30:59 -07001206 if (!icr)
1207 return IRQ_NONE; /* Not our interrupt */
1208
Bruce Allanad680762008-03-28 09:15:03 -07001209 /*
1210 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1211 * not set, then the adapter didn't send an interrupt
1212 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213 if (!(icr & E1000_ICR_INT_ASSERTED))
1214 return IRQ_NONE;
1215
Bruce Allanad680762008-03-28 09:15:03 -07001216 /*
1217 * Interrupt Auto-Mask...upon reading ICR,
1218 * interrupts are masked. No need for the
1219 * IMC write
1220 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001221
1222 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
1223 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001224 /*
1225 * ICH8 workaround-- Call gig speed drop workaround on cable
1226 * disconnect (LSC) before accessing any PHY registers
1227 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001228 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1229 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001230 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001231
Bruce Allanad680762008-03-28 09:15:03 -07001232 /*
1233 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001234 * For packet buffer work-around on link down event;
1235 * disable receives here in the ISR and
1236 * reset adapter in watchdog
1237 */
1238 if (netif_carrier_ok(netdev) &&
1239 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1240 /* disable receives */
1241 rctl = er32(RCTL);
1242 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001243 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 }
1245 /* guard against interrupt when we're going down */
1246 if (!test_bit(__E1000_DOWN, &adapter->state))
1247 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1248 }
1249
1250 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1251 adapter->total_tx_bytes = 0;
1252 adapter->total_tx_packets = 0;
1253 adapter->total_rx_bytes = 0;
1254 adapter->total_rx_packets = 0;
1255 __netif_rx_schedule(netdev, &adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001256 }
1257
1258 return IRQ_HANDLED;
1259}
1260
Bruce Allan4662e822008-08-26 18:37:06 -07001261static irqreturn_t e1000_msix_other(int irq, void *data)
1262{
1263 struct net_device *netdev = data;
1264 struct e1000_adapter *adapter = netdev_priv(netdev);
1265 struct e1000_hw *hw = &adapter->hw;
1266 u32 icr = er32(ICR);
1267
1268 if (!(icr & E1000_ICR_INT_ASSERTED)) {
1269 ew32(IMS, E1000_IMS_OTHER);
1270 return IRQ_NONE;
1271 }
1272
1273 if (icr & adapter->eiac_mask)
1274 ew32(ICS, (icr & adapter->eiac_mask));
1275
1276 if (icr & E1000_ICR_OTHER) {
1277 if (!(icr & E1000_ICR_LSC))
1278 goto no_link_interrupt;
1279 hw->mac.get_link_status = 1;
1280 /* guard against interrupt when we're going down */
1281 if (!test_bit(__E1000_DOWN, &adapter->state))
1282 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1283 }
1284
1285no_link_interrupt:
1286 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
1287
1288 return IRQ_HANDLED;
1289}
1290
1291
1292static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1293{
1294 struct net_device *netdev = data;
1295 struct e1000_adapter *adapter = netdev_priv(netdev);
1296 struct e1000_hw *hw = &adapter->hw;
1297 struct e1000_ring *tx_ring = adapter->tx_ring;
1298
1299
1300 adapter->total_tx_bytes = 0;
1301 adapter->total_tx_packets = 0;
1302
1303 if (!e1000_clean_tx_irq(adapter))
1304 /* Ring was not completely cleaned, so fire another interrupt */
1305 ew32(ICS, tx_ring->ims_val);
1306
1307 return IRQ_HANDLED;
1308}
1309
1310static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1311{
1312 struct net_device *netdev = data;
1313 struct e1000_adapter *adapter = netdev_priv(netdev);
1314
1315 /* Write the ITR value calculated at the end of the
1316 * previous interrupt.
1317 */
1318 if (adapter->rx_ring->set_itr) {
1319 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1320 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1321 adapter->rx_ring->set_itr = 0;
1322 }
1323
1324 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1325 adapter->total_rx_bytes = 0;
1326 adapter->total_rx_packets = 0;
1327 __netif_rx_schedule(netdev, &adapter->napi);
1328 }
1329 return IRQ_HANDLED;
1330}
1331
1332/**
1333 * e1000_configure_msix - Configure MSI-X hardware
1334 *
1335 * e1000_configure_msix sets up the hardware to properly
1336 * generate MSI-X interrupts.
1337 **/
1338static void e1000_configure_msix(struct e1000_adapter *adapter)
1339{
1340 struct e1000_hw *hw = &adapter->hw;
1341 struct e1000_ring *rx_ring = adapter->rx_ring;
1342 struct e1000_ring *tx_ring = adapter->tx_ring;
1343 int vector = 0;
1344 u32 ctrl_ext, ivar = 0;
1345
1346 adapter->eiac_mask = 0;
1347
1348 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1349 if (hw->mac.type == e1000_82574) {
1350 u32 rfctl = er32(RFCTL);
1351 rfctl |= E1000_RFCTL_ACK_DIS;
1352 ew32(RFCTL, rfctl);
1353 }
1354
1355#define E1000_IVAR_INT_ALLOC_VALID 0x8
1356 /* Configure Rx vector */
1357 rx_ring->ims_val = E1000_IMS_RXQ0;
1358 adapter->eiac_mask |= rx_ring->ims_val;
1359 if (rx_ring->itr_val)
1360 writel(1000000000 / (rx_ring->itr_val * 256),
1361 hw->hw_addr + rx_ring->itr_register);
1362 else
1363 writel(1, hw->hw_addr + rx_ring->itr_register);
1364 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1365
1366 /* Configure Tx vector */
1367 tx_ring->ims_val = E1000_IMS_TXQ0;
1368 vector++;
1369 if (tx_ring->itr_val)
1370 writel(1000000000 / (tx_ring->itr_val * 256),
1371 hw->hw_addr + tx_ring->itr_register);
1372 else
1373 writel(1, hw->hw_addr + tx_ring->itr_register);
1374 adapter->eiac_mask |= tx_ring->ims_val;
1375 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1376
1377 /* set vector for Other Causes, e.g. link changes */
1378 vector++;
1379 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1380 if (rx_ring->itr_val)
1381 writel(1000000000 / (rx_ring->itr_val * 256),
1382 hw->hw_addr + E1000_EITR_82574(vector));
1383 else
1384 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1385
1386 /* Cause Tx interrupts on every write back */
1387 ivar |= (1 << 31);
1388
1389 ew32(IVAR, ivar);
1390
1391 /* enable MSI-X PBA support */
1392 ctrl_ext = er32(CTRL_EXT);
1393 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1394
1395 /* Auto-Mask Other interrupts upon ICR read */
1396#define E1000_EIAC_MASK_82574 0x01F00000
1397 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1398 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1399 ew32(CTRL_EXT, ctrl_ext);
1400 e1e_flush();
1401}
1402
1403void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1404{
1405 if (adapter->msix_entries) {
1406 pci_disable_msix(adapter->pdev);
1407 kfree(adapter->msix_entries);
1408 adapter->msix_entries = NULL;
1409 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1410 pci_disable_msi(adapter->pdev);
1411 adapter->flags &= ~FLAG_MSI_ENABLED;
1412 }
1413
1414 return;
1415}
1416
1417/**
1418 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1419 *
1420 * Attempt to configure interrupts using the best available
1421 * capabilities of the hardware and kernel.
1422 **/
1423void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1424{
1425 int err;
1426 int numvecs, i;
1427
1428
1429 switch (adapter->int_mode) {
1430 case E1000E_INT_MODE_MSIX:
1431 if (adapter->flags & FLAG_HAS_MSIX) {
1432 numvecs = 3; /* RxQ0, TxQ0 and other */
1433 adapter->msix_entries = kcalloc(numvecs,
1434 sizeof(struct msix_entry),
1435 GFP_KERNEL);
1436 if (adapter->msix_entries) {
1437 for (i = 0; i < numvecs; i++)
1438 adapter->msix_entries[i].entry = i;
1439
1440 err = pci_enable_msix(adapter->pdev,
1441 adapter->msix_entries,
1442 numvecs);
1443 if (err == 0)
1444 return;
1445 }
1446 /* MSI-X failed, so fall through and try MSI */
1447 e_err("Failed to initialize MSI-X interrupts. "
1448 "Falling back to MSI interrupts.\n");
1449 e1000e_reset_interrupt_capability(adapter);
1450 }
1451 adapter->int_mode = E1000E_INT_MODE_MSI;
1452 /* Fall through */
1453 case E1000E_INT_MODE_MSI:
1454 if (!pci_enable_msi(adapter->pdev)) {
1455 adapter->flags |= FLAG_MSI_ENABLED;
1456 } else {
1457 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1458 e_err("Failed to initialize MSI interrupts. Falling "
1459 "back to legacy interrupts.\n");
1460 }
1461 /* Fall through */
1462 case E1000E_INT_MODE_LEGACY:
1463 /* Don't do anything; this is the system default */
1464 break;
1465 }
1466
1467 return;
1468}
1469
1470/**
1471 * e1000_request_msix - Initialize MSI-X interrupts
1472 *
1473 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1474 * kernel.
1475 **/
1476static int e1000_request_msix(struct e1000_adapter *adapter)
1477{
1478 struct net_device *netdev = adapter->netdev;
1479 int err = 0, vector = 0;
1480
1481 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1482 sprintf(adapter->rx_ring->name, "%s-rx0", netdev->name);
1483 else
1484 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1485 err = request_irq(adapter->msix_entries[vector].vector,
1486 &e1000_intr_msix_rx, 0, adapter->rx_ring->name,
1487 netdev);
1488 if (err)
1489 goto out;
1490 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1491 adapter->rx_ring->itr_val = adapter->itr;
1492 vector++;
1493
1494 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1495 sprintf(adapter->tx_ring->name, "%s-tx0", netdev->name);
1496 else
1497 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1498 err = request_irq(adapter->msix_entries[vector].vector,
1499 &e1000_intr_msix_tx, 0, adapter->tx_ring->name,
1500 netdev);
1501 if (err)
1502 goto out;
1503 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1504 adapter->tx_ring->itr_val = adapter->itr;
1505 vector++;
1506
1507 err = request_irq(adapter->msix_entries[vector].vector,
1508 &e1000_msix_other, 0, netdev->name, netdev);
1509 if (err)
1510 goto out;
1511
1512 e1000_configure_msix(adapter);
1513 return 0;
1514out:
1515 return err;
1516}
1517
Bruce Allanf8d59f72008-08-08 18:36:11 -07001518/**
1519 * e1000_request_irq - initialize interrupts
1520 *
1521 * Attempts to configure interrupts using the best available
1522 * capabilities of the hardware and kernel.
1523 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001524static int e1000_request_irq(struct e1000_adapter *adapter)
1525{
1526 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001527 int err;
1528
Bruce Allan4662e822008-08-26 18:37:06 -07001529 if (adapter->msix_entries) {
1530 err = e1000_request_msix(adapter);
1531 if (!err)
1532 return err;
1533 /* fall back to MSI */
1534 e1000e_reset_interrupt_capability(adapter);
1535 adapter->int_mode = E1000E_INT_MODE_MSI;
1536 e1000e_set_interrupt_capability(adapter);
1537 }
1538 if (adapter->flags & FLAG_MSI_ENABLED) {
1539 err = request_irq(adapter->pdev->irq, &e1000_intr_msi, 0,
1540 netdev->name, netdev);
1541 if (!err)
1542 return err;
1543
1544 /* fall back to legacy interrupt */
1545 e1000e_reset_interrupt_capability(adapter);
1546 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001547 }
1548
Bruce Allan4662e822008-08-26 18:37:06 -07001549 err = request_irq(adapter->pdev->irq, &e1000_intr, IRQF_SHARED,
1550 netdev->name, netdev);
1551 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001552 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001553
1554 return err;
1555}
1556
1557static void e1000_free_irq(struct e1000_adapter *adapter)
1558{
1559 struct net_device *netdev = adapter->netdev;
1560
Bruce Allan4662e822008-08-26 18:37:06 -07001561 if (adapter->msix_entries) {
1562 int vector = 0;
1563
1564 free_irq(adapter->msix_entries[vector].vector, netdev);
1565 vector++;
1566
1567 free_irq(adapter->msix_entries[vector].vector, netdev);
1568 vector++;
1569
1570 /* Other Causes interrupt vector */
1571 free_irq(adapter->msix_entries[vector].vector, netdev);
1572 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001573 }
Bruce Allan4662e822008-08-26 18:37:06 -07001574
1575 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001576}
1577
1578/**
1579 * e1000_irq_disable - Mask off interrupt generation on the NIC
1580 **/
1581static void e1000_irq_disable(struct e1000_adapter *adapter)
1582{
1583 struct e1000_hw *hw = &adapter->hw;
1584
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001586 if (adapter->msix_entries)
1587 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001588 e1e_flush();
1589 synchronize_irq(adapter->pdev->irq);
1590}
1591
1592/**
1593 * e1000_irq_enable - Enable default interrupt generation settings
1594 **/
1595static void e1000_irq_enable(struct e1000_adapter *adapter)
1596{
1597 struct e1000_hw *hw = &adapter->hw;
1598
Bruce Allan4662e822008-08-26 18:37:06 -07001599 if (adapter->msix_entries) {
1600 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1601 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1602 } else {
1603 ew32(IMS, IMS_ENABLE_MASK);
1604 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001605 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001606}
1607
1608/**
1609 * e1000_get_hw_control - get control of the h/w from f/w
1610 * @adapter: address of board private structure
1611 *
Auke Kok489815c2008-02-21 15:11:07 -08001612 * e1000_get_hw_control sets {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
1614 * the driver is loaded. For AMT version (only with 82573)
1615 * of the f/w this means that the network i/f is open.
1616 **/
1617static void e1000_get_hw_control(struct e1000_adapter *adapter)
1618{
1619 struct e1000_hw *hw = &adapter->hw;
1620 u32 ctrl_ext;
1621 u32 swsm;
1622
1623 /* Let firmware know the driver has taken over */
1624 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1625 swsm = er32(SWSM);
1626 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1627 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1628 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07001629 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001630 }
1631}
1632
1633/**
1634 * e1000_release_hw_control - release control of the h/w to f/w
1635 * @adapter: address of board private structure
1636 *
Auke Kok489815c2008-02-21 15:11:07 -08001637 * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638 * For ASF and Pass Through versions of f/w this means that the
1639 * driver is no longer loaded. For AMT version (only with 82573) i
1640 * of the f/w this means that the network i/f is closed.
1641 *
1642 **/
1643static void e1000_release_hw_control(struct e1000_adapter *adapter)
1644{
1645 struct e1000_hw *hw = &adapter->hw;
1646 u32 ctrl_ext;
1647 u32 swsm;
1648
1649 /* Let firmware taken over control of h/w */
1650 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1651 swsm = er32(SWSM);
1652 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1653 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1654 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07001655 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001656 }
1657}
1658
Auke Kokbc7f75f2007-09-17 12:30:59 -07001659/**
1660 * @e1000_alloc_ring - allocate memory for a ring structure
1661 **/
1662static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
1663 struct e1000_ring *ring)
1664{
1665 struct pci_dev *pdev = adapter->pdev;
1666
1667 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
1668 GFP_KERNEL);
1669 if (!ring->desc)
1670 return -ENOMEM;
1671
1672 return 0;
1673}
1674
1675/**
1676 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1677 * @adapter: board private structure
1678 *
1679 * Return 0 on success, negative on failure
1680 **/
1681int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
1682{
1683 struct e1000_ring *tx_ring = adapter->tx_ring;
1684 int err = -ENOMEM, size;
1685
1686 size = sizeof(struct e1000_buffer) * tx_ring->count;
1687 tx_ring->buffer_info = vmalloc(size);
1688 if (!tx_ring->buffer_info)
1689 goto err;
1690 memset(tx_ring->buffer_info, 0, size);
1691
1692 /* round up to nearest 4K */
1693 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1694 tx_ring->size = ALIGN(tx_ring->size, 4096);
1695
1696 err = e1000_alloc_ring_dma(adapter, tx_ring);
1697 if (err)
1698 goto err;
1699
1700 tx_ring->next_to_use = 0;
1701 tx_ring->next_to_clean = 0;
1702 spin_lock_init(&adapter->tx_queue_lock);
1703
1704 return 0;
1705err:
1706 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001707 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708 return err;
1709}
1710
1711/**
1712 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1713 * @adapter: board private structure
1714 *
1715 * Returns 0 on success, negative on failure
1716 **/
1717int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
1718{
1719 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07001720 struct e1000_buffer *buffer_info;
1721 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001722
1723 size = sizeof(struct e1000_buffer) * rx_ring->count;
1724 rx_ring->buffer_info = vmalloc(size);
1725 if (!rx_ring->buffer_info)
1726 goto err;
1727 memset(rx_ring->buffer_info, 0, size);
1728
Auke Kok47f44e42007-10-25 13:57:44 -07001729 for (i = 0; i < rx_ring->count; i++) {
1730 buffer_info = &rx_ring->buffer_info[i];
1731 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
1732 sizeof(struct e1000_ps_page),
1733 GFP_KERNEL);
1734 if (!buffer_info->ps_pages)
1735 goto err_pages;
1736 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001737
1738 desc_len = sizeof(union e1000_rx_desc_packet_split);
1739
1740 /* Round up to nearest 4K */
1741 rx_ring->size = rx_ring->count * desc_len;
1742 rx_ring->size = ALIGN(rx_ring->size, 4096);
1743
1744 err = e1000_alloc_ring_dma(adapter, rx_ring);
1745 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07001746 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001747
1748 rx_ring->next_to_clean = 0;
1749 rx_ring->next_to_use = 0;
1750 rx_ring->rx_skb_top = NULL;
1751
1752 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07001753
1754err_pages:
1755 for (i = 0; i < rx_ring->count; i++) {
1756 buffer_info = &rx_ring->buffer_info[i];
1757 kfree(buffer_info->ps_pages);
1758 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001759err:
1760 vfree(rx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001761 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001762 return err;
1763}
1764
1765/**
1766 * e1000_clean_tx_ring - Free Tx Buffers
1767 * @adapter: board private structure
1768 **/
1769static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
1770{
1771 struct e1000_ring *tx_ring = adapter->tx_ring;
1772 struct e1000_buffer *buffer_info;
1773 unsigned long size;
1774 unsigned int i;
1775
1776 for (i = 0; i < tx_ring->count; i++) {
1777 buffer_info = &tx_ring->buffer_info[i];
1778 e1000_put_txbuf(adapter, buffer_info);
1779 }
1780
1781 size = sizeof(struct e1000_buffer) * tx_ring->count;
1782 memset(tx_ring->buffer_info, 0, size);
1783
1784 memset(tx_ring->desc, 0, tx_ring->size);
1785
1786 tx_ring->next_to_use = 0;
1787 tx_ring->next_to_clean = 0;
1788
1789 writel(0, adapter->hw.hw_addr + tx_ring->head);
1790 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1791}
1792
1793/**
1794 * e1000e_free_tx_resources - Free Tx Resources per Queue
1795 * @adapter: board private structure
1796 *
1797 * Free all transmit software resources
1798 **/
1799void e1000e_free_tx_resources(struct e1000_adapter *adapter)
1800{
1801 struct pci_dev *pdev = adapter->pdev;
1802 struct e1000_ring *tx_ring = adapter->tx_ring;
1803
1804 e1000_clean_tx_ring(adapter);
1805
1806 vfree(tx_ring->buffer_info);
1807 tx_ring->buffer_info = NULL;
1808
1809 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1810 tx_ring->dma);
1811 tx_ring->desc = NULL;
1812}
1813
1814/**
1815 * e1000e_free_rx_resources - Free Rx Resources
1816 * @adapter: board private structure
1817 *
1818 * Free all receive software resources
1819 **/
1820
1821void e1000e_free_rx_resources(struct e1000_adapter *adapter)
1822{
1823 struct pci_dev *pdev = adapter->pdev;
1824 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07001825 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001826
1827 e1000_clean_rx_ring(adapter);
1828
Auke Kok47f44e42007-10-25 13:57:44 -07001829 for (i = 0; i < rx_ring->count; i++) {
1830 kfree(rx_ring->buffer_info[i].ps_pages);
1831 }
1832
Auke Kokbc7f75f2007-09-17 12:30:59 -07001833 vfree(rx_ring->buffer_info);
1834 rx_ring->buffer_info = NULL;
1835
Auke Kokbc7f75f2007-09-17 12:30:59 -07001836 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1837 rx_ring->dma);
1838 rx_ring->desc = NULL;
1839}
1840
1841/**
1842 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08001843 * @adapter: pointer to adapter
1844 * @itr_setting: current adapter->itr
1845 * @packets: the number of packets during this measurement interval
1846 * @bytes: the number of bytes during this measurement interval
1847 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07001848 * Stores a new ITR value based on packets and byte
1849 * counts during the last interrupt. The advantage of per interrupt
1850 * computation is faster updates and more accurate ITR for the current
1851 * traffic pattern. Constants in this function were computed
1852 * based on theoretical maximum wire speed and thresholds were set based
1853 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07001854 * while increasing bulk throughput. This functionality is controlled
1855 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856 **/
1857static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
1858 u16 itr_setting, int packets,
1859 int bytes)
1860{
1861 unsigned int retval = itr_setting;
1862
1863 if (packets == 0)
1864 goto update_itr_done;
1865
1866 switch (itr_setting) {
1867 case lowest_latency:
1868 /* handle TSO and jumbo frames */
1869 if (bytes/packets > 8000)
1870 retval = bulk_latency;
1871 else if ((packets < 5) && (bytes > 512)) {
1872 retval = low_latency;
1873 }
1874 break;
1875 case low_latency: /* 50 usec aka 20000 ints/s */
1876 if (bytes > 10000) {
1877 /* this if handles the TSO accounting */
1878 if (bytes/packets > 8000) {
1879 retval = bulk_latency;
1880 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
1881 retval = bulk_latency;
1882 } else if ((packets > 35)) {
1883 retval = lowest_latency;
1884 }
1885 } else if (bytes/packets > 2000) {
1886 retval = bulk_latency;
1887 } else if (packets <= 2 && bytes < 512) {
1888 retval = lowest_latency;
1889 }
1890 break;
1891 case bulk_latency: /* 250 usec aka 4000 ints/s */
1892 if (bytes > 25000) {
1893 if (packets > 35) {
1894 retval = low_latency;
1895 }
1896 } else if (bytes < 6000) {
1897 retval = low_latency;
1898 }
1899 break;
1900 }
1901
1902update_itr_done:
1903 return retval;
1904}
1905
1906static void e1000_set_itr(struct e1000_adapter *adapter)
1907{
1908 struct e1000_hw *hw = &adapter->hw;
1909 u16 current_itr;
1910 u32 new_itr = adapter->itr;
1911
1912 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1913 if (adapter->link_speed != SPEED_1000) {
1914 current_itr = 0;
1915 new_itr = 4000;
1916 goto set_itr_now;
1917 }
1918
1919 adapter->tx_itr = e1000_update_itr(adapter,
1920 adapter->tx_itr,
1921 adapter->total_tx_packets,
1922 adapter->total_tx_bytes);
1923 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1924 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
1925 adapter->tx_itr = low_latency;
1926
1927 adapter->rx_itr = e1000_update_itr(adapter,
1928 adapter->rx_itr,
1929 adapter->total_rx_packets,
1930 adapter->total_rx_bytes);
1931 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1932 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
1933 adapter->rx_itr = low_latency;
1934
1935 current_itr = max(adapter->rx_itr, adapter->tx_itr);
1936
1937 switch (current_itr) {
1938 /* counts and packets in update_itr are dependent on these numbers */
1939 case lowest_latency:
1940 new_itr = 70000;
1941 break;
1942 case low_latency:
1943 new_itr = 20000; /* aka hwitr = ~200 */
1944 break;
1945 case bulk_latency:
1946 new_itr = 4000;
1947 break;
1948 default:
1949 break;
1950 }
1951
1952set_itr_now:
1953 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07001954 /*
1955 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07001956 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07001957 * increasing
1958 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001959 new_itr = new_itr > adapter->itr ?
1960 min(adapter->itr + (new_itr >> 2), new_itr) :
1961 new_itr;
1962 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07001963 adapter->rx_ring->itr_val = new_itr;
1964 if (adapter->msix_entries)
1965 adapter->rx_ring->set_itr = 1;
1966 else
1967 ew32(ITR, 1000000000 / (new_itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001968 }
1969}
1970
1971/**
Bruce Allan4662e822008-08-26 18:37:06 -07001972 * e1000_alloc_queues - Allocate memory for all rings
1973 * @adapter: board private structure to initialize
1974 **/
1975static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1976{
1977 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1978 if (!adapter->tx_ring)
1979 goto err;
1980
1981 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1982 if (!adapter->rx_ring)
1983 goto err;
1984
1985 return 0;
1986err:
1987 e_err("Unable to allocate memory for queues\n");
1988 kfree(adapter->rx_ring);
1989 kfree(adapter->tx_ring);
1990 return -ENOMEM;
1991}
1992
1993/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001994 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07001995 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08001996 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07001997 **/
1998static int e1000_clean(struct napi_struct *napi, int budget)
1999{
2000 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002001 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002002 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002003 int tx_cleaned = 0, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002004
Wang Chen4cf16532008-11-12 23:38:14 -08002005 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002006
Bruce Allan4662e822008-08-26 18:37:06 -07002007 if (adapter->msix_entries &&
2008 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2009 goto clean_rx;
2010
Bruce Allanad680762008-03-28 09:15:03 -07002011 /*
2012 * e1000_clean is called per-cpu. This lock protects
Auke Kokbc7f75f2007-09-17 12:30:59 -07002013 * tx_ring from being cleaned by multiple cpus
2014 * simultaneously. A failure obtaining the lock means
Bruce Allanad680762008-03-28 09:15:03 -07002015 * tx_ring is currently being cleaned anyway.
2016 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002017 if (spin_trylock(&adapter->tx_queue_lock)) {
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002018 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002019 spin_unlock(&adapter->tx_queue_lock);
2020 }
2021
Bruce Allan4662e822008-08-26 18:37:06 -07002022clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002023 adapter->clean_rx(adapter, &work_done, budget);
2024
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002025 if (tx_cleaned)
2026 work_done = budget;
2027
David S. Miller53e52c72008-01-07 21:06:12 -08002028 /* If budget not fully consumed, exit the polling mode */
2029 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002030 if (adapter->itr_setting & 3)
2031 e1000_set_itr(adapter);
2032 netif_rx_complete(poll_dev, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002033 if (adapter->msix_entries)
2034 ew32(IMS, adapter->rx_ring->ims_val);
2035 else
2036 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002037 }
2038
2039 return work_done;
2040}
2041
2042static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2043{
2044 struct e1000_adapter *adapter = netdev_priv(netdev);
2045 struct e1000_hw *hw = &adapter->hw;
2046 u32 vfta, index;
2047
2048 /* don't update vlan cookie if already programmed */
2049 if ((adapter->hw.mng_cookie.status &
2050 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2051 (vid == adapter->mng_vlan_id))
2052 return;
2053 /* add VID to filter table */
2054 index = (vid >> 5) & 0x7F;
2055 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2056 vfta |= (1 << (vid & 0x1F));
2057 e1000e_write_vfta(hw, index, vfta);
2058}
2059
2060static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2061{
2062 struct e1000_adapter *adapter = netdev_priv(netdev);
2063 struct e1000_hw *hw = &adapter->hw;
2064 u32 vfta, index;
2065
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002066 if (!test_bit(__E1000_DOWN, &adapter->state))
2067 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002068 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002069
2070 if (!test_bit(__E1000_DOWN, &adapter->state))
2071 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002072
2073 if ((adapter->hw.mng_cookie.status &
2074 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2075 (vid == adapter->mng_vlan_id)) {
2076 /* release control to f/w */
2077 e1000_release_hw_control(adapter);
2078 return;
2079 }
2080
2081 /* remove VID from filter table */
2082 index = (vid >> 5) & 0x7F;
2083 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2084 vfta &= ~(1 << (vid & 0x1F));
2085 e1000e_write_vfta(hw, index, vfta);
2086}
2087
2088static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2089{
2090 struct net_device *netdev = adapter->netdev;
2091 u16 vid = adapter->hw.mng_cookie.vlan_id;
2092 u16 old_vid = adapter->mng_vlan_id;
2093
2094 if (!adapter->vlgrp)
2095 return;
2096
2097 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2098 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2099 if (adapter->hw.mng_cookie.status &
2100 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2101 e1000_vlan_rx_add_vid(netdev, vid);
2102 adapter->mng_vlan_id = vid;
2103 }
2104
2105 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2106 (vid != old_vid) &&
2107 !vlan_group_get_device(adapter->vlgrp, old_vid))
2108 e1000_vlan_rx_kill_vid(netdev, old_vid);
2109 } else {
2110 adapter->mng_vlan_id = vid;
2111 }
2112}
2113
2114
2115static void e1000_vlan_rx_register(struct net_device *netdev,
2116 struct vlan_group *grp)
2117{
2118 struct e1000_adapter *adapter = netdev_priv(netdev);
2119 struct e1000_hw *hw = &adapter->hw;
2120 u32 ctrl, rctl;
2121
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002122 if (!test_bit(__E1000_DOWN, &adapter->state))
2123 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002124 adapter->vlgrp = grp;
2125
2126 if (grp) {
2127 /* enable VLAN tag insert/strip */
2128 ctrl = er32(CTRL);
2129 ctrl |= E1000_CTRL_VME;
2130 ew32(CTRL, ctrl);
2131
2132 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2133 /* enable VLAN receive filtering */
2134 rctl = er32(RCTL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002135 rctl &= ~E1000_RCTL_CFIEN;
2136 ew32(RCTL, rctl);
2137 e1000_update_mng_vlan(adapter);
2138 }
2139 } else {
2140 /* disable VLAN tag insert/strip */
2141 ctrl = er32(CTRL);
2142 ctrl &= ~E1000_CTRL_VME;
2143 ew32(CTRL, ctrl);
2144
2145 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002146 if (adapter->mng_vlan_id !=
2147 (u16)E1000_MNG_VLAN_NONE) {
2148 e1000_vlan_rx_kill_vid(netdev,
2149 adapter->mng_vlan_id);
2150 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2151 }
2152 }
2153 }
2154
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002155 if (!test_bit(__E1000_DOWN, &adapter->state))
2156 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002157}
2158
2159static void e1000_restore_vlan(struct e1000_adapter *adapter)
2160{
2161 u16 vid;
2162
2163 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2164
2165 if (!adapter->vlgrp)
2166 return;
2167
2168 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2169 if (!vlan_group_get_device(adapter->vlgrp, vid))
2170 continue;
2171 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2172 }
2173}
2174
2175static void e1000_init_manageability(struct e1000_adapter *adapter)
2176{
2177 struct e1000_hw *hw = &adapter->hw;
2178 u32 manc, manc2h;
2179
2180 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2181 return;
2182
2183 manc = er32(MANC);
2184
Bruce Allanad680762008-03-28 09:15:03 -07002185 /*
2186 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002187 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002188 * the packets will be handled on SMBUS
2189 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190 manc |= E1000_MANC_EN_MNG2HOST;
2191 manc2h = er32(MANC2H);
2192#define E1000_MNG2HOST_PORT_623 (1 << 5)
2193#define E1000_MNG2HOST_PORT_664 (1 << 6)
2194 manc2h |= E1000_MNG2HOST_PORT_623;
2195 manc2h |= E1000_MNG2HOST_PORT_664;
2196 ew32(MANC2H, manc2h);
2197 ew32(MANC, manc);
2198}
2199
2200/**
2201 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2202 * @adapter: board private structure
2203 *
2204 * Configure the Tx unit of the MAC after a reset.
2205 **/
2206static void e1000_configure_tx(struct e1000_adapter *adapter)
2207{
2208 struct e1000_hw *hw = &adapter->hw;
2209 struct e1000_ring *tx_ring = adapter->tx_ring;
2210 u64 tdba;
2211 u32 tdlen, tctl, tipg, tarc;
2212 u32 ipgr1, ipgr2;
2213
2214 /* Setup the HW Tx Head and Tail descriptor pointers */
2215 tdba = tx_ring->dma;
2216 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2217 ew32(TDBAL, (tdba & DMA_32BIT_MASK));
2218 ew32(TDBAH, (tdba >> 32));
2219 ew32(TDLEN, tdlen);
2220 ew32(TDH, 0);
2221 ew32(TDT, 0);
2222 tx_ring->head = E1000_TDH;
2223 tx_ring->tail = E1000_TDT;
2224
2225 /* Set the default values for the Tx Inter Packet Gap timer */
2226 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2227 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2228 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2229
2230 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2231 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2232
2233 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2234 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2235 ew32(TIPG, tipg);
2236
2237 /* Set the Tx Interrupt Delay register */
2238 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002239 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002240 ew32(TADV, adapter->tx_abs_int_delay);
2241
2242 /* Program the Transmit Control Register */
2243 tctl = er32(TCTL);
2244 tctl &= ~E1000_TCTL_CT;
2245 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2246 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2247
2248 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002249 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002250 /*
2251 * set the speed mode bit, we'll clear it if we're not at
2252 * gigabit link later
2253 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002254#define SPEED_MODE_BIT (1 << 21)
2255 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002256 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002257 }
2258
2259 /* errata: program both queues to unweighted RR */
2260 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002261 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002262 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002263 ew32(TARC(0), tarc);
2264 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002265 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002266 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002267 }
2268
2269 e1000e_config_collision_dist(hw);
2270
2271 /* Setup Transmit Descriptor Settings for eop descriptor */
2272 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2273
2274 /* only set IDE if we are delaying interrupts using the timers */
2275 if (adapter->tx_int_delay)
2276 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2277
2278 /* enable Report Status bit */
2279 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2280
2281 ew32(TCTL, tctl);
2282
2283 adapter->tx_queue_len = adapter->netdev->tx_queue_len;
2284}
2285
2286/**
2287 * e1000_setup_rctl - configure the receive control registers
2288 * @adapter: Board private structure
2289 **/
2290#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2291 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2292static void e1000_setup_rctl(struct e1000_adapter *adapter)
2293{
2294 struct e1000_hw *hw = &adapter->hw;
2295 u32 rctl, rfctl;
2296 u32 psrctl = 0;
2297 u32 pages = 0;
2298
2299 /* Program MC offset vector base */
2300 rctl = er32(RCTL);
2301 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2302 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2303 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2304 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2305
2306 /* Do not Store bad packets */
2307 rctl &= ~E1000_RCTL_SBP;
2308
2309 /* Enable Long Packet receive */
2310 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2311 rctl &= ~E1000_RCTL_LPE;
2312 else
2313 rctl |= E1000_RCTL_LPE;
2314
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002315 /* Some systems expect that the CRC is included in SMBUS traffic. The
2316 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2317 * host memory when this is enabled
2318 */
2319 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2320 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002321
Auke Kokbc7f75f2007-09-17 12:30:59 -07002322 /* Setup buffer sizes */
2323 rctl &= ~E1000_RCTL_SZ_4096;
2324 rctl |= E1000_RCTL_BSEX;
2325 switch (adapter->rx_buffer_len) {
2326 case 256:
2327 rctl |= E1000_RCTL_SZ_256;
2328 rctl &= ~E1000_RCTL_BSEX;
2329 break;
2330 case 512:
2331 rctl |= E1000_RCTL_SZ_512;
2332 rctl &= ~E1000_RCTL_BSEX;
2333 break;
2334 case 1024:
2335 rctl |= E1000_RCTL_SZ_1024;
2336 rctl &= ~E1000_RCTL_BSEX;
2337 break;
2338 case 2048:
2339 default:
2340 rctl |= E1000_RCTL_SZ_2048;
2341 rctl &= ~E1000_RCTL_BSEX;
2342 break;
2343 case 4096:
2344 rctl |= E1000_RCTL_SZ_4096;
2345 break;
2346 case 8192:
2347 rctl |= E1000_RCTL_SZ_8192;
2348 break;
2349 case 16384:
2350 rctl |= E1000_RCTL_SZ_16384;
2351 break;
2352 }
2353
2354 /*
2355 * 82571 and greater support packet-split where the protocol
2356 * header is placed in skb->data and the packet data is
2357 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2358 * In the case of a non-split, skb->data is linearly filled,
2359 * followed by the page buffers. Therefore, skb->data is
2360 * sized to hold the largest protocol header.
2361 *
2362 * allocations using alloc_page take too long for regular MTU
2363 * so only enable packet split for jumbo frames
2364 *
2365 * Using pages when the page size is greater than 16k wastes
2366 * a lot of memory, since we allocate 3 pages at all times
2367 * per packet.
2368 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002369 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002370 if (!(adapter->flags & FLAG_IS_ICH) && (pages <= 3) &&
2371 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002372 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002373 else
2374 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002375
2376 if (adapter->rx_ps_pages) {
2377 /* Configure extra packet-split registers */
2378 rfctl = er32(RFCTL);
2379 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002380 /*
2381 * disable packet split support for IPv6 extension headers,
2382 * because some malformed IPv6 headers can hang the Rx
2383 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2385 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2386
2387 ew32(RFCTL, rfctl);
2388
Auke Kok140a7482007-10-25 13:57:58 -07002389 /* Enable Packet split descriptors */
2390 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002391
2392 psrctl |= adapter->rx_ps_bsize0 >>
2393 E1000_PSRCTL_BSIZE0_SHIFT;
2394
2395 switch (adapter->rx_ps_pages) {
2396 case 3:
2397 psrctl |= PAGE_SIZE <<
2398 E1000_PSRCTL_BSIZE3_SHIFT;
2399 case 2:
2400 psrctl |= PAGE_SIZE <<
2401 E1000_PSRCTL_BSIZE2_SHIFT;
2402 case 1:
2403 psrctl |= PAGE_SIZE >>
2404 E1000_PSRCTL_BSIZE1_SHIFT;
2405 break;
2406 }
2407
2408 ew32(PSRCTL, psrctl);
2409 }
2410
2411 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002412 /* just started the receive unit, no need to restart */
2413 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002414}
2415
2416/**
2417 * e1000_configure_rx - Configure Receive Unit after Reset
2418 * @adapter: board private structure
2419 *
2420 * Configure the Rx unit of the MAC after a reset.
2421 **/
2422static void e1000_configure_rx(struct e1000_adapter *adapter)
2423{
2424 struct e1000_hw *hw = &adapter->hw;
2425 struct e1000_ring *rx_ring = adapter->rx_ring;
2426 u64 rdba;
2427 u32 rdlen, rctl, rxcsum, ctrl_ext;
2428
2429 if (adapter->rx_ps_pages) {
2430 /* this is a 32 byte descriptor */
2431 rdlen = rx_ring->count *
2432 sizeof(union e1000_rx_desc_packet_split);
2433 adapter->clean_rx = e1000_clean_rx_irq_ps;
2434 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002435 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2436 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2437 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2438 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002439 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002440 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002441 adapter->clean_rx = e1000_clean_rx_irq;
2442 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2443 }
2444
2445 /* disable receives while setting up the descriptors */
2446 rctl = er32(RCTL);
2447 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2448 e1e_flush();
2449 msleep(10);
2450
2451 /* set the Receive Delay Timer Register */
2452 ew32(RDTR, adapter->rx_int_delay);
2453
2454 /* irq moderation */
2455 ew32(RADV, adapter->rx_abs_int_delay);
2456 if (adapter->itr_setting != 0)
Bruce Allanad680762008-03-28 09:15:03 -07002457 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002458
2459 ctrl_ext = er32(CTRL_EXT);
2460 /* Reset delay timers after every interrupt */
2461 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
2462 /* Auto-Mask interrupts upon ICR access */
2463 ctrl_ext |= E1000_CTRL_EXT_IAME;
2464 ew32(IAM, 0xffffffff);
2465 ew32(CTRL_EXT, ctrl_ext);
2466 e1e_flush();
2467
Bruce Allanad680762008-03-28 09:15:03 -07002468 /*
2469 * Setup the HW Rx Head and Tail Descriptor Pointers and
2470 * the Base and Length of the Rx Descriptor Ring
2471 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002472 rdba = rx_ring->dma;
2473 ew32(RDBAL, (rdba & DMA_32BIT_MASK));
2474 ew32(RDBAH, (rdba >> 32));
2475 ew32(RDLEN, rdlen);
2476 ew32(RDH, 0);
2477 ew32(RDT, 0);
2478 rx_ring->head = E1000_RDH;
2479 rx_ring->tail = E1000_RDT;
2480
2481 /* Enable Receive Checksum Offload for TCP and UDP */
2482 rxcsum = er32(RXCSUM);
2483 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2484 rxcsum |= E1000_RXCSUM_TUOFL;
2485
Bruce Allanad680762008-03-28 09:15:03 -07002486 /*
2487 * IPv4 payload checksum for UDP fragments must be
2488 * used in conjunction with packet-split.
2489 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002490 if (adapter->rx_ps_pages)
2491 rxcsum |= E1000_RXCSUM_IPPCSE;
2492 } else {
2493 rxcsum &= ~E1000_RXCSUM_TUOFL;
2494 /* no need to clear IPPCSE as it defaults to 0 */
2495 }
2496 ew32(RXCSUM, rxcsum);
2497
Bruce Allanad680762008-03-28 09:15:03 -07002498 /*
2499 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002501 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2502 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002503 if ((adapter->flags & FLAG_HAS_ERT) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002504 (adapter->netdev->mtu > ETH_DATA_LEN)) {
2505 u32 rxdctl = er32(RXDCTL(0));
2506 ew32(RXDCTL(0), rxdctl | 0x3);
2507 ew32(ERT, E1000_ERT_2048 | (1 << 13));
2508 /*
2509 * With jumbo frames and early-receive enabled, excessive
2510 * C4->C2 latencies result in dropped transactions.
2511 */
2512 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2513 e1000e_driver_name, 55);
2514 } else {
2515 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2516 e1000e_driver_name,
2517 PM_QOS_DEFAULT_VALUE);
2518 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002519
2520 /* Enable Receives */
2521 ew32(RCTL, rctl);
2522}
2523
2524/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002525 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526 * @hw: pointer to the HW structure
2527 * @mc_addr_list: array of multicast addresses to program
2528 * @mc_addr_count: number of multicast addresses to program
2529 * @rar_used_count: the first RAR register free to program
2530 * @rar_count: total number of supported Receive Address Registers
2531 *
2532 * Updates the Receive Address Registers and Multicast Table Array.
2533 * The caller must have a packed mc_addr_list of multicast addresses.
2534 * The parameter rar_count will usually be hw->mac.rar_entry_count
2535 * unless there are workarounds that change this. Currently no func pointer
2536 * exists and all implementations are handled in the generic version of this
2537 * function.
2538 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002539static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
2540 u32 mc_addr_count, u32 rar_used_count,
2541 u32 rar_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002542{
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002543 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002544 rar_used_count, rar_count);
2545}
2546
2547/**
2548 * e1000_set_multi - Multicast and Promiscuous mode set
2549 * @netdev: network interface device structure
2550 *
2551 * The set_multi entry point is called whenever the multicast address
2552 * list or the network interface flags are updated. This routine is
2553 * responsible for configuring the hardware for proper multicast,
2554 * promiscuous mode, and all-multi behavior.
2555 **/
2556static void e1000_set_multi(struct net_device *netdev)
2557{
2558 struct e1000_adapter *adapter = netdev_priv(netdev);
2559 struct e1000_hw *hw = &adapter->hw;
2560 struct e1000_mac_info *mac = &hw->mac;
2561 struct dev_mc_list *mc_ptr;
2562 u8 *mta_list;
2563 u32 rctl;
2564 int i;
2565
2566 /* Check for Promiscuous and All Multicast modes */
2567
2568 rctl = er32(RCTL);
2569
2570 if (netdev->flags & IFF_PROMISC) {
2571 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002572 rctl &= ~E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002573 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002574 if (netdev->flags & IFF_ALLMULTI) {
2575 rctl |= E1000_RCTL_MPE;
2576 rctl &= ~E1000_RCTL_UPE;
2577 } else {
2578 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2579 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002580 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002581 rctl |= E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002582 }
2583
2584 ew32(RCTL, rctl);
2585
2586 if (netdev->mc_count) {
2587 mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);
2588 if (!mta_list)
2589 return;
2590
2591 /* prepare a packed array of only addresses. */
2592 mc_ptr = netdev->mc_list;
2593
2594 for (i = 0; i < netdev->mc_count; i++) {
2595 if (!mc_ptr)
2596 break;
2597 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
2598 ETH_ALEN);
2599 mc_ptr = mc_ptr->next;
2600 }
2601
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002602 e1000_update_mc_addr_list(hw, mta_list, i, 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002603 mac->rar_entry_count);
2604 kfree(mta_list);
2605 } else {
2606 /*
2607 * if we're called from probe, we might not have
2608 * anything to do here, so clear out the list
2609 */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002610 e1000_update_mc_addr_list(hw, NULL, 0, 1, mac->rar_entry_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611 }
2612}
2613
2614/**
Bruce Allanad680762008-03-28 09:15:03 -07002615 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07002616 * @adapter: private board structure
2617 **/
2618static void e1000_configure(struct e1000_adapter *adapter)
2619{
2620 e1000_set_multi(adapter->netdev);
2621
2622 e1000_restore_vlan(adapter);
2623 e1000_init_manageability(adapter);
2624
2625 e1000_configure_tx(adapter);
2626 e1000_setup_rctl(adapter);
2627 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07002628 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002629}
2630
2631/**
2632 * e1000e_power_up_phy - restore link in case the phy was powered down
2633 * @adapter: address of board private structure
2634 *
2635 * The phy may be powered down to save power and turn off link when the
2636 * driver is unloaded and wake on lan is not enabled (among others)
2637 * *** this routine MUST be followed by a call to e1000e_reset ***
2638 **/
2639void e1000e_power_up_phy(struct e1000_adapter *adapter)
2640{
2641 u16 mii_reg = 0;
2642
2643 /* Just clear the power down bit to wake the phy back up */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002644 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Bruce Allanad680762008-03-28 09:15:03 -07002645 /*
2646 * According to the manual, the phy will retain its
2647 * settings across a power-down/up cycle
2648 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002649 e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);
2650 mii_reg &= ~MII_CR_POWER_DOWN;
2651 e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);
2652 }
2653
2654 adapter->hw.mac.ops.setup_link(&adapter->hw);
2655}
2656
2657/**
2658 * e1000_power_down_phy - Power down the PHY
2659 *
2660 * Power down the PHY so no link is implied when interface is down
2661 * The PHY cannot be powered down is management or WoL is active
2662 */
2663static void e1000_power_down_phy(struct e1000_adapter *adapter)
2664{
2665 struct e1000_hw *hw = &adapter->hw;
2666 u16 mii_reg;
2667
2668 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08002669 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002670 return;
2671
2672 /* non-copper PHY? */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002673 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002674 return;
2675
2676 /* reset is blocked because of a SoL/IDER session */
Bruce Allanad680762008-03-28 09:15:03 -07002677 if (e1000e_check_mng_mode(hw) || e1000_check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002678 return;
2679
Auke Kok489815c2008-02-21 15:11:07 -08002680 /* manageability (AMT) is enabled */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002681 if (er32(MANC) & E1000_MANC_SMBUS_EN)
2682 return;
2683
2684 /* power down the PHY */
2685 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2686 mii_reg |= MII_CR_POWER_DOWN;
2687 e1e_wphy(hw, PHY_CONTROL, mii_reg);
2688 mdelay(1);
2689}
2690
2691/**
2692 * e1000e_reset - bring the hardware into a known good state
2693 *
2694 * This function boots the hardware and enables some settings that
2695 * require a configuration cycle of the hardware - those cannot be
2696 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07002697 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002698 */
2699void e1000e_reset(struct e1000_adapter *adapter)
2700{
2701 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002702 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002703 struct e1000_hw *hw = &adapter->hw;
2704 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002705 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002706 u16 hwm;
2707
Bruce Allanad680762008-03-28 09:15:03 -07002708 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002709 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07002710
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002711 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07002712 /*
2713 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07002714 * large enough to accommodate two full transmit packets,
2715 * rounded up to the next 1KB and expressed in KB. Likewise,
2716 * the Rx FIFO should be large enough to accommodate at least
2717 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07002718 * expressed in KB.
2719 */
Auke Kokdf762462007-10-25 13:57:53 -07002720 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002721 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07002722 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002723 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07002724 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07002725 /*
2726 * the Tx fifo also stores 16 bytes of information about the tx
2727 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002728 */
2729 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07002730 sizeof(struct e1000_tx_desc) -
2731 ETH_FCS_LEN) * 2;
2732 min_tx_space = ALIGN(min_tx_space, 1024);
2733 min_tx_space >>= 10;
2734 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002735 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002736 min_rx_space = ALIGN(min_rx_space, 1024);
2737 min_rx_space >>= 10;
2738
Bruce Allanad680762008-03-28 09:15:03 -07002739 /*
2740 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002741 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07002742 * allocation, take space away from current Rx allocation
2743 */
Auke Kokdf762462007-10-25 13:57:53 -07002744 if ((tx_space < min_tx_space) &&
2745 ((min_tx_space - tx_space) < pba)) {
2746 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002747
Bruce Allanad680762008-03-28 09:15:03 -07002748 /*
2749 * if short on Rx space, Rx wins and must trump tx
2750 * adjustment or use Early Receive if available
2751 */
Auke Kokdf762462007-10-25 13:57:53 -07002752 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07002753 (!(adapter->flags & FLAG_HAS_ERT)))
2754 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07002755 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002756 }
Auke Kokdf762462007-10-25 13:57:53 -07002757
2758 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002759 }
2760
Auke Kokbc7f75f2007-09-17 12:30:59 -07002761
Bruce Allanad680762008-03-28 09:15:03 -07002762 /*
2763 * flow control settings
2764 *
2765 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07002766 * (or the size used for early receive) above it in the Rx FIFO.
2767 * Set it to the lower of:
2768 * - 90% of the Rx FIFO size, and
2769 * - the full Rx FIFO size minus the early receive size (for parts
2770 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allanad680762008-03-28 09:15:03 -07002771 * - the full Rx FIFO size minus one full frame
2772 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002773 if (adapter->flags & FLAG_HAS_ERT)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002774 hwm = min(((pba << 10) * 9 / 10),
2775 ((pba << 10) - (E1000_ERT_2048 << 3)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002776 else
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002777 hwm = min(((pba << 10) * 9 / 10),
2778 ((pba << 10) - adapter->max_frame_size));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002779
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002780 fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */
2781 fc->low_water = fc->high_water - 8;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002782
2783 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002784 fc->pause_time = 0xFFFF;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002785 else
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002786 fc->pause_time = E1000_FC_PAUSE_TIME;
2787 fc->send_xon = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08002788 fc->current_mode = fc->requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002789
2790 /* Allow time for pending master requests to run */
2791 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002792
2793 /*
2794 * For parts with AMT enabled, let the firmware know
2795 * that the network interface is in control
2796 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07002797 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002798 e1000_get_hw_control(adapter);
2799
Auke Kokbc7f75f2007-09-17 12:30:59 -07002800 ew32(WUC, 0);
2801
2802 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002803 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002804
2805 e1000_update_mng_vlan(adapter);
2806
2807 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2808 ew32(VET, ETH_P_8021Q);
2809
2810 e1000e_reset_adaptive(hw);
2811 e1000_get_phy_info(hw);
2812
2813 if (!(adapter->flags & FLAG_SMART_POWER_DOWN)) {
2814 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07002815 /*
2816 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07002817 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07002818 * different we would do if it failed
2819 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002820 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
2821 phy_data &= ~IGP02E1000_PM_SPD;
2822 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
2823 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002824}
2825
2826int e1000e_up(struct e1000_adapter *adapter)
2827{
2828 struct e1000_hw *hw = &adapter->hw;
2829
2830 /* hardware has been reset, we need to reload some things */
2831 e1000_configure(adapter);
2832
2833 clear_bit(__E1000_DOWN, &adapter->state);
2834
2835 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002836 if (adapter->msix_entries)
2837 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838 e1000_irq_enable(adapter);
2839
2840 /* fire a link change interrupt to start the watchdog */
2841 ew32(ICS, E1000_ICS_LSC);
2842 return 0;
2843}
2844
2845void e1000e_down(struct e1000_adapter *adapter)
2846{
2847 struct net_device *netdev = adapter->netdev;
2848 struct e1000_hw *hw = &adapter->hw;
2849 u32 tctl, rctl;
2850
Bruce Allanad680762008-03-28 09:15:03 -07002851 /*
2852 * signal that we're down so the interrupt handler does not
2853 * reschedule our watchdog timer
2854 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002855 set_bit(__E1000_DOWN, &adapter->state);
2856
2857 /* disable receives in the hardware */
2858 rctl = er32(RCTL);
2859 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2860 /* flush and sleep below */
2861
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07002862 netif_tx_stop_all_queues(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002863
2864 /* disable transmits in the hardware */
2865 tctl = er32(TCTL);
2866 tctl &= ~E1000_TCTL_EN;
2867 ew32(TCTL, tctl);
2868 /* flush both disables and wait for them to finish */
2869 e1e_flush();
2870 msleep(10);
2871
2872 napi_disable(&adapter->napi);
2873 e1000_irq_disable(adapter);
2874
2875 del_timer_sync(&adapter->watchdog_timer);
2876 del_timer_sync(&adapter->phy_info_timer);
2877
2878 netdev->tx_queue_len = adapter->tx_queue_len;
2879 netif_carrier_off(netdev);
2880 adapter->link_speed = 0;
2881 adapter->link_duplex = 0;
2882
Jeff Kirsher52cc3082008-06-24 17:01:29 -07002883 if (!pci_channel_offline(adapter->pdev))
2884 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002885 e1000_clean_tx_ring(adapter);
2886 e1000_clean_rx_ring(adapter);
2887
2888 /*
2889 * TODO: for power management, we could drop the link and
2890 * pci_disable_device here.
2891 */
2892}
2893
2894void e1000e_reinit_locked(struct e1000_adapter *adapter)
2895{
2896 might_sleep();
2897 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
2898 msleep(1);
2899 e1000e_down(adapter);
2900 e1000e_up(adapter);
2901 clear_bit(__E1000_RESETTING, &adapter->state);
2902}
2903
2904/**
2905 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2906 * @adapter: board private structure to initialize
2907 *
2908 * e1000_sw_init initializes the Adapter private data structure.
2909 * Fields are initialized based on PCI device information and
2910 * OS network device settings (MTU size).
2911 **/
2912static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
2913{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002914 struct net_device *netdev = adapter->netdev;
2915
2916 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
2917 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002918 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2919 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002920
Bruce Allan4662e822008-08-26 18:37:06 -07002921 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002922
Bruce Allan4662e822008-08-26 18:37:06 -07002923 if (e1000_alloc_queues(adapter))
2924 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002925
2926 spin_lock_init(&adapter->tx_queue_lock);
2927
2928 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002929 e1000_irq_disable(adapter);
2930
Auke Kokbc7f75f2007-09-17 12:30:59 -07002931 set_bit(__E1000_DOWN, &adapter->state);
2932 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933}
2934
2935/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07002936 * e1000_intr_msi_test - Interrupt Handler
2937 * @irq: interrupt number
2938 * @data: pointer to a network interface device structure
2939 **/
2940static irqreturn_t e1000_intr_msi_test(int irq, void *data)
2941{
2942 struct net_device *netdev = data;
2943 struct e1000_adapter *adapter = netdev_priv(netdev);
2944 struct e1000_hw *hw = &adapter->hw;
2945 u32 icr = er32(ICR);
2946
2947 e_dbg("%s: icr is %08X\n", netdev->name, icr);
2948 if (icr & E1000_ICR_RXSEQ) {
2949 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
2950 wmb();
2951 }
2952
2953 return IRQ_HANDLED;
2954}
2955
2956/**
2957 * e1000_test_msi_interrupt - Returns 0 for successful test
2958 * @adapter: board private struct
2959 *
2960 * code flow taken from tg3.c
2961 **/
2962static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
2963{
2964 struct net_device *netdev = adapter->netdev;
2965 struct e1000_hw *hw = &adapter->hw;
2966 int err;
2967
2968 /* poll_enable hasn't been called yet, so don't need disable */
2969 /* clear any pending events */
2970 er32(ICR);
2971
2972 /* free the real vector and request a test handler */
2973 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07002974 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07002975
2976 /* Assume that the test fails, if it succeeds then the test
2977 * MSI irq handler will unset this flag */
2978 adapter->flags |= FLAG_MSI_TEST_FAILED;
2979
2980 err = pci_enable_msi(adapter->pdev);
2981 if (err)
2982 goto msi_test_failed;
2983
2984 err = request_irq(adapter->pdev->irq, &e1000_intr_msi_test, 0,
2985 netdev->name, netdev);
2986 if (err) {
2987 pci_disable_msi(adapter->pdev);
2988 goto msi_test_failed;
2989 }
2990
2991 wmb();
2992
2993 e1000_irq_enable(adapter);
2994
2995 /* fire an unusual interrupt on the test handler */
2996 ew32(ICS, E1000_ICS_RXSEQ);
2997 e1e_flush();
2998 msleep(50);
2999
3000 e1000_irq_disable(adapter);
3001
3002 rmb();
3003
3004 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003005 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Bruce Allanf8d59f72008-08-08 18:36:11 -07003006 err = -EIO;
3007 e_info("MSI interrupt test failed!\n");
3008 }
3009
3010 free_irq(adapter->pdev->irq, netdev);
3011 pci_disable_msi(adapter->pdev);
3012
3013 if (err == -EIO)
3014 goto msi_test_failed;
3015
3016 /* okay so the test worked, restore settings */
3017 e_dbg("%s: MSI interrupt test succeeded!\n", netdev->name);
3018msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003019 e1000e_set_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003020 e1000_request_irq(adapter);
3021 return err;
3022}
3023
3024/**
3025 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3026 * @adapter: board private struct
3027 *
3028 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3029 **/
3030static int e1000_test_msi(struct e1000_adapter *adapter)
3031{
3032 int err;
3033 u16 pci_cmd;
3034
3035 if (!(adapter->flags & FLAG_MSI_ENABLED))
3036 return 0;
3037
3038 /* disable SERR in case the MSI write causes a master abort */
3039 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3040 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3041 pci_cmd & ~PCI_COMMAND_SERR);
3042
3043 err = e1000_test_msi_interrupt(adapter);
3044
3045 /* restore previous setting of command word */
3046 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3047
3048 /* success ! */
3049 if (!err)
3050 return 0;
3051
3052 /* EIO means MSI test failed */
3053 if (err != -EIO)
3054 return err;
3055
3056 /* back to INTx mode */
3057 e_warn("MSI interrupt test failed, using legacy interrupt.\n");
3058
3059 e1000_free_irq(adapter);
3060
3061 err = e1000_request_irq(adapter);
3062
3063 return err;
3064}
3065
3066/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003067 * e1000_open - Called when a network interface is made active
3068 * @netdev: network interface device structure
3069 *
3070 * Returns 0 on success, negative value on failure
3071 *
3072 * The open entry point is called when a network interface is made
3073 * active by the system (IFF_UP). At this point all resources needed
3074 * for transmit and receive operations are allocated, the interrupt
3075 * handler is registered with the OS, the watchdog timer is started,
3076 * and the stack is notified that the interface is ready.
3077 **/
3078static int e1000_open(struct net_device *netdev)
3079{
3080 struct e1000_adapter *adapter = netdev_priv(netdev);
3081 struct e1000_hw *hw = &adapter->hw;
3082 int err;
3083
3084 /* disallow open during test */
3085 if (test_bit(__E1000_TESTING, &adapter->state))
3086 return -EBUSY;
3087
3088 /* allocate transmit descriptors */
3089 err = e1000e_setup_tx_resources(adapter);
3090 if (err)
3091 goto err_setup_tx;
3092
3093 /* allocate receive descriptors */
3094 err = e1000e_setup_rx_resources(adapter);
3095 if (err)
3096 goto err_setup_rx;
3097
3098 e1000e_power_up_phy(adapter);
3099
3100 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3101 if ((adapter->hw.mng_cookie.status &
3102 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3103 e1000_update_mng_vlan(adapter);
3104
Bruce Allanad680762008-03-28 09:15:03 -07003105 /*
3106 * If AMT is enabled, let the firmware know that the network
3107 * interface is now open
3108 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003109 if (adapter->flags & FLAG_HAS_AMT)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003110 e1000_get_hw_control(adapter);
3111
Bruce Allanad680762008-03-28 09:15:03 -07003112 /*
3113 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003114 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3115 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003116 * clean_rx handler before we do so.
3117 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003118 e1000_configure(adapter);
3119
3120 err = e1000_request_irq(adapter);
3121 if (err)
3122 goto err_req_irq;
3123
Bruce Allanf8d59f72008-08-08 18:36:11 -07003124 /*
3125 * Work around PCIe errata with MSI interrupts causing some chipsets to
3126 * ignore e1000e MSI messages, which means we need to test our MSI
3127 * interrupt now
3128 */
Bruce Allan4662e822008-08-26 18:37:06 -07003129 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003130 err = e1000_test_msi(adapter);
3131 if (err) {
3132 e_err("Interrupt allocation failed\n");
3133 goto err_req_irq;
3134 }
3135 }
3136
Auke Kokbc7f75f2007-09-17 12:30:59 -07003137 /* From here on the code is the same as e1000e_up() */
3138 clear_bit(__E1000_DOWN, &adapter->state);
3139
3140 napi_enable(&adapter->napi);
3141
3142 e1000_irq_enable(adapter);
3143
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003144 netif_tx_start_all_queues(netdev);
3145
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146 /* fire a link status change interrupt to start the watchdog */
3147 ew32(ICS, E1000_ICS_LSC);
3148
3149 return 0;
3150
3151err_req_irq:
3152 e1000_release_hw_control(adapter);
3153 e1000_power_down_phy(adapter);
3154 e1000e_free_rx_resources(adapter);
3155err_setup_rx:
3156 e1000e_free_tx_resources(adapter);
3157err_setup_tx:
3158 e1000e_reset(adapter);
3159
3160 return err;
3161}
3162
3163/**
3164 * e1000_close - Disables a network interface
3165 * @netdev: network interface device structure
3166 *
3167 * Returns 0, this is not allowed to fail
3168 *
3169 * The close entry point is called when an interface is de-activated
3170 * by the OS. The hardware is still under the drivers control, but
3171 * needs to be disabled. A global MAC reset is issued to stop the
3172 * hardware, and all transmit and receive resources are freed.
3173 **/
3174static int e1000_close(struct net_device *netdev)
3175{
3176 struct e1000_adapter *adapter = netdev_priv(netdev);
3177
3178 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3179 e1000e_down(adapter);
3180 e1000_power_down_phy(adapter);
3181 e1000_free_irq(adapter);
3182
3183 e1000e_free_tx_resources(adapter);
3184 e1000e_free_rx_resources(adapter);
3185
Bruce Allanad680762008-03-28 09:15:03 -07003186 /*
3187 * kill manageability vlan ID if supported, but not if a vlan with
3188 * the same ID is registered on the host OS (let 8021q kill it)
3189 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003190 if ((adapter->hw.mng_cookie.status &
3191 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3192 !(adapter->vlgrp &&
3193 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3194 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3195
Bruce Allanad680762008-03-28 09:15:03 -07003196 /*
3197 * If AMT is enabled, let the firmware know that the network
3198 * interface is now closed
3199 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003200 if (adapter->flags & FLAG_HAS_AMT)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003201 e1000_release_hw_control(adapter);
3202
3203 return 0;
3204}
3205/**
3206 * e1000_set_mac - Change the Ethernet Address of the NIC
3207 * @netdev: network interface device structure
3208 * @p: pointer to an address structure
3209 *
3210 * Returns 0 on success, negative on failure
3211 **/
3212static int e1000_set_mac(struct net_device *netdev, void *p)
3213{
3214 struct e1000_adapter *adapter = netdev_priv(netdev);
3215 struct sockaddr *addr = p;
3216
3217 if (!is_valid_ether_addr(addr->sa_data))
3218 return -EADDRNOTAVAIL;
3219
3220 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3221 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3222
3223 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3224
3225 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3226 /* activate the work around */
3227 e1000e_set_laa_state_82571(&adapter->hw, 1);
3228
Bruce Allanad680762008-03-28 09:15:03 -07003229 /*
3230 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003231 * between the time RAR[0] gets clobbered and the time it
3232 * gets fixed (in e1000_watchdog), the actual LAA is in one
3233 * of the RARs and no incoming packets directed to this port
3234 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003235 * RAR[14]
3236 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003237 e1000e_rar_set(&adapter->hw,
3238 adapter->hw.mac.addr,
3239 adapter->hw.mac.rar_entry_count - 1);
3240 }
3241
3242 return 0;
3243}
3244
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003245/**
3246 * e1000e_update_phy_task - work thread to update phy
3247 * @work: pointer to our work struct
3248 *
3249 * this worker thread exists because we must acquire a
3250 * semaphore to read the phy, which we could msleep while
3251 * waiting for it, and we can't msleep in a timer.
3252 **/
3253static void e1000e_update_phy_task(struct work_struct *work)
3254{
3255 struct e1000_adapter *adapter = container_of(work,
3256 struct e1000_adapter, update_phy_task);
3257 e1000_get_phy_info(&adapter->hw);
3258}
3259
Bruce Allanad680762008-03-28 09:15:03 -07003260/*
3261 * Need to wait a few seconds after link up to get diagnostic information from
3262 * the phy
3263 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003264static void e1000_update_phy_info(unsigned long data)
3265{
3266 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003267 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003268}
3269
3270/**
3271 * e1000e_update_stats - Update the board statistics counters
3272 * @adapter: board private structure
3273 **/
3274void e1000e_update_stats(struct e1000_adapter *adapter)
3275{
3276 struct e1000_hw *hw = &adapter->hw;
3277 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003278
3279 /*
3280 * Prevent stats update while adapter is being reset, or if the pci
3281 * connection is down.
3282 */
3283 if (adapter->link_speed == 0)
3284 return;
3285 if (pci_channel_offline(pdev))
3286 return;
3287
Auke Kokbc7f75f2007-09-17 12:30:59 -07003288 adapter->stats.crcerrs += er32(CRCERRS);
3289 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003290 adapter->stats.gorc += er32(GORCL);
3291 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003292 adapter->stats.bprc += er32(BPRC);
3293 adapter->stats.mprc += er32(MPRC);
3294 adapter->stats.roc += er32(ROC);
3295
Auke Kokbc7f75f2007-09-17 12:30:59 -07003296 adapter->stats.mpc += er32(MPC);
3297 adapter->stats.scc += er32(SCC);
3298 adapter->stats.ecol += er32(ECOL);
3299 adapter->stats.mcc += er32(MCC);
3300 adapter->stats.latecol += er32(LATECOL);
3301 adapter->stats.dc += er32(DC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003302 adapter->stats.xonrxc += er32(XONRXC);
3303 adapter->stats.xontxc += er32(XONTXC);
3304 adapter->stats.xoffrxc += er32(XOFFRXC);
3305 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003306 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003307 adapter->stats.gotc += er32(GOTCL);
3308 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003309 adapter->stats.rnbc += er32(RNBC);
3310 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003311
3312 adapter->stats.mptc += er32(MPTC);
3313 adapter->stats.bptc += er32(BPTC);
3314
3315 /* used for adaptive IFS */
3316
3317 hw->mac.tx_packet_delta = er32(TPT);
3318 adapter->stats.tpt += hw->mac.tx_packet_delta;
3319 hw->mac.collision_delta = er32(COLC);
3320 adapter->stats.colc += hw->mac.collision_delta;
3321
3322 adapter->stats.algnerrc += er32(ALGNERRC);
3323 adapter->stats.rxerrc += er32(RXERRC);
Bruce Allan4662e822008-08-26 18:37:06 -07003324 if (hw->mac.type != e1000_82574)
3325 adapter->stats.tncrs += er32(TNCRS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003326 adapter->stats.cexterr += er32(CEXTERR);
3327 adapter->stats.tsctc += er32(TSCTC);
3328 adapter->stats.tsctfc += er32(TSCTFC);
3329
Auke Kokbc7f75f2007-09-17 12:30:59 -07003330 /* Fill out the OS statistics structure */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003331 adapter->net_stats.multicast = adapter->stats.mprc;
3332 adapter->net_stats.collisions = adapter->stats.colc;
3333
3334 /* Rx Errors */
3335
Bruce Allanad680762008-03-28 09:15:03 -07003336 /*
3337 * RLEC on some newer hardware can be incorrect so build
3338 * our own version based on RUC and ROC
3339 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003340 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3341 adapter->stats.crcerrs + adapter->stats.algnerrc +
3342 adapter->stats.ruc + adapter->stats.roc +
3343 adapter->stats.cexterr;
3344 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3345 adapter->stats.roc;
3346 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3347 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3348 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3349
3350 /* Tx Errors */
3351 adapter->net_stats.tx_errors = adapter->stats.ecol +
3352 adapter->stats.latecol;
3353 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3354 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3355 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3356
3357 /* Tx Dropped needs to be maintained elsewhere */
3358
Auke Kokbc7f75f2007-09-17 12:30:59 -07003359 /* Management Stats */
3360 adapter->stats.mgptc += er32(MGTPTC);
3361 adapter->stats.mgprc += er32(MGTPRC);
3362 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003363}
3364
Bruce Allan7c257692008-04-23 11:09:00 -07003365/**
3366 * e1000_phy_read_status - Update the PHY register status snapshot
3367 * @adapter: board private structure
3368 **/
3369static void e1000_phy_read_status(struct e1000_adapter *adapter)
3370{
3371 struct e1000_hw *hw = &adapter->hw;
3372 struct e1000_phy_regs *phy = &adapter->phy_regs;
3373 int ret_val;
Bruce Allan7c257692008-04-23 11:09:00 -07003374
3375 if ((er32(STATUS) & E1000_STATUS_LU) &&
3376 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
3377 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
3378 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
3379 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
3380 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
3381 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
3382 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
3383 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
3384 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
3385 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003386 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07003387 } else {
3388 /*
3389 * Do not read PHY registers if link is not up
3390 * Set values to typical power-on defaults
3391 */
3392 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
3393 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
3394 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
3395 BMSR_ERCAP);
3396 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
3397 ADVERTISE_ALL | ADVERTISE_CSMA);
3398 phy->lpa = 0;
3399 phy->expansion = EXPANSION_ENABLENPAGE;
3400 phy->ctrl1000 = ADVERTISE_1000FULL;
3401 phy->stat1000 = 0;
3402 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
3403 }
Bruce Allan7c257692008-04-23 11:09:00 -07003404}
3405
Auke Kokbc7f75f2007-09-17 12:30:59 -07003406static void e1000_print_link_info(struct e1000_adapter *adapter)
3407{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003408 struct e1000_hw *hw = &adapter->hw;
3409 u32 ctrl = er32(CTRL);
3410
Bruce Allan8f12fe82008-11-21 16:54:43 -08003411 /* Link status message must follow this format for user tools */
3412 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
3413 "Flow Control: %s\n",
3414 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003415 adapter->link_speed,
3416 (adapter->link_duplex == FULL_DUPLEX) ?
3417 "Full Duplex" : "Half Duplex",
3418 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
3419 "RX/TX" :
3420 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
3421 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003422}
3423
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003424static bool e1000_has_link(struct e1000_adapter *adapter)
3425{
3426 struct e1000_hw *hw = &adapter->hw;
3427 bool link_active = 0;
3428 s32 ret_val = 0;
3429
3430 /*
3431 * get_link_status is set on LSC (link status) interrupt or
3432 * Rx sequence error interrupt. get_link_status will stay
3433 * false until the check_for_link establishes link
3434 * for copper adapters ONLY
3435 */
3436 switch (hw->phy.media_type) {
3437 case e1000_media_type_copper:
3438 if (hw->mac.get_link_status) {
3439 ret_val = hw->mac.ops.check_for_link(hw);
3440 link_active = !hw->mac.get_link_status;
3441 } else {
3442 link_active = 1;
3443 }
3444 break;
3445 case e1000_media_type_fiber:
3446 ret_val = hw->mac.ops.check_for_link(hw);
3447 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
3448 break;
3449 case e1000_media_type_internal_serdes:
3450 ret_val = hw->mac.ops.check_for_link(hw);
3451 link_active = adapter->hw.mac.serdes_has_link;
3452 break;
3453 default:
3454 case e1000_media_type_unknown:
3455 break;
3456 }
3457
3458 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
3459 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
3460 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003461 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003462 }
3463
3464 return link_active;
3465}
3466
3467static void e1000e_enable_receives(struct e1000_adapter *adapter)
3468{
3469 /* make sure the receive unit is started */
3470 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
3471 (adapter->flags & FLAG_RX_RESTART_NOW)) {
3472 struct e1000_hw *hw = &adapter->hw;
3473 u32 rctl = er32(RCTL);
3474 ew32(RCTL, rctl | E1000_RCTL_EN);
3475 adapter->flags &= ~FLAG_RX_RESTART_NOW;
3476 }
3477}
3478
Auke Kokbc7f75f2007-09-17 12:30:59 -07003479/**
3480 * e1000_watchdog - Timer Call-back
3481 * @data: pointer to adapter cast into an unsigned long
3482 **/
3483static void e1000_watchdog(unsigned long data)
3484{
3485 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
3486
3487 /* Do the rest outside of interrupt context */
3488 schedule_work(&adapter->watchdog_task);
3489
3490 /* TODO: make this use queue_delayed_work() */
3491}
3492
3493static void e1000_watchdog_task(struct work_struct *work)
3494{
3495 struct e1000_adapter *adapter = container_of(work,
3496 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003497 struct net_device *netdev = adapter->netdev;
3498 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08003499 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003500 struct e1000_ring *tx_ring = adapter->tx_ring;
3501 struct e1000_hw *hw = &adapter->hw;
3502 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003503 int tx_pending = 0;
3504
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003505 link = e1000_has_link(adapter);
3506 if ((netif_carrier_ok(netdev)) && link) {
3507 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003508 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003509 }
3510
3511 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
3512 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
3513 e1000_update_mng_vlan(adapter);
3514
Auke Kokbc7f75f2007-09-17 12:30:59 -07003515 if (link) {
3516 if (!netif_carrier_ok(netdev)) {
3517 bool txb2b = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003518 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07003519 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003520 mac->ops.get_link_up_info(&adapter->hw,
3521 &adapter->link_speed,
3522 &adapter->link_duplex);
3523 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003524 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07003525 * On supported PHYs, check for duplex mismatch only
3526 * if link has autonegotiated at 10/100 half
3527 */
3528 if ((hw->phy.type == e1000_phy_igp_3 ||
3529 hw->phy.type == e1000_phy_bm) &&
3530 (hw->mac.autoneg == true) &&
3531 (adapter->link_speed == SPEED_10 ||
3532 adapter->link_speed == SPEED_100) &&
3533 (adapter->link_duplex == HALF_DUPLEX)) {
3534 u16 autoneg_exp;
3535
3536 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
3537
3538 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
3539 e_info("Autonegotiated half duplex but"
3540 " link partner cannot autoneg. "
3541 " Try forcing full duplex if "
3542 "link gets many collisions.\n");
3543 }
3544
3545 /*
Bruce Allanad680762008-03-28 09:15:03 -07003546 * tweak tx_queue_len according to speed/duplex
3547 * and adjust the timeout factor
3548 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003549 netdev->tx_queue_len = adapter->tx_queue_len;
3550 adapter->tx_timeout_factor = 1;
3551 switch (adapter->link_speed) {
3552 case SPEED_10:
3553 txb2b = 0;
3554 netdev->tx_queue_len = 10;
Bruce Allan10f1b492008-08-08 18:36:01 -07003555 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003556 break;
3557 case SPEED_100:
3558 txb2b = 0;
3559 netdev->tx_queue_len = 100;
3560 /* maybe add some timeout factor ? */
3561 break;
3562 }
3563
Bruce Allanad680762008-03-28 09:15:03 -07003564 /*
3565 * workaround: re-program speed mode bit after
3566 * link-up event
3567 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003568 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
3569 !txb2b) {
3570 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003571 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003572 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003573 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003574 }
3575
Bruce Allanad680762008-03-28 09:15:03 -07003576 /*
3577 * disable TSO for pcie and 10/100 speeds, to avoid
3578 * some hardware issues
3579 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003580 if (!(adapter->flags & FLAG_TSO_FORCE)) {
3581 switch (adapter->link_speed) {
3582 case SPEED_10:
3583 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003584 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003585 netdev->features &= ~NETIF_F_TSO;
3586 netdev->features &= ~NETIF_F_TSO6;
3587 break;
3588 case SPEED_1000:
3589 netdev->features |= NETIF_F_TSO;
3590 netdev->features |= NETIF_F_TSO6;
3591 break;
3592 default:
3593 /* oops */
3594 break;
3595 }
3596 }
3597
Bruce Allanad680762008-03-28 09:15:03 -07003598 /*
3599 * enable transmits in the hardware, need to do this
3600 * after setting TARC(0)
3601 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003602 tctl = er32(TCTL);
3603 tctl |= E1000_TCTL_EN;
3604 ew32(TCTL, tctl);
3605
Bruce Allan75eb0fa2008-11-21 16:53:51 -08003606 /*
3607 * Perform any post-link-up configuration before
3608 * reporting link up.
3609 */
3610 if (phy->ops.cfg_on_link_up)
3611 phy->ops.cfg_on_link_up(hw);
3612
Auke Kokbc7f75f2007-09-17 12:30:59 -07003613 netif_carrier_on(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003614 netif_tx_wake_all_queues(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003615
3616 if (!test_bit(__E1000_DOWN, &adapter->state))
3617 mod_timer(&adapter->phy_info_timer,
3618 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003619 }
3620 } else {
3621 if (netif_carrier_ok(netdev)) {
3622 adapter->link_speed = 0;
3623 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08003624 /* Link status message must follow this format */
3625 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
3626 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003627 netif_carrier_off(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003628 netif_tx_stop_all_queues(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003629 if (!test_bit(__E1000_DOWN, &adapter->state))
3630 mod_timer(&adapter->phy_info_timer,
3631 round_jiffies(jiffies + 2 * HZ));
3632
3633 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3634 schedule_work(&adapter->reset_task);
3635 }
3636 }
3637
3638link_up:
3639 e1000e_update_stats(adapter);
3640
3641 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
3642 adapter->tpt_old = adapter->stats.tpt;
3643 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
3644 adapter->colc_old = adapter->stats.colc;
3645
Bruce Allan7c257692008-04-23 11:09:00 -07003646 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
3647 adapter->gorc_old = adapter->stats.gorc;
3648 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
3649 adapter->gotc_old = adapter->stats.gotc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003650
3651 e1000e_update_adaptive(&adapter->hw);
3652
3653 if (!netif_carrier_ok(netdev)) {
3654 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
3655 tx_ring->count);
3656 if (tx_pending) {
Bruce Allanad680762008-03-28 09:15:03 -07003657 /*
3658 * We've lost link, so the controller stops DMA,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003659 * but we've got queued Tx work that's never going
3660 * to get done, so reset controller to flush Tx.
Bruce Allanad680762008-03-28 09:15:03 -07003661 * (Do the reset outside of interrupt context).
3662 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003663 adapter->tx_timeout_count++;
3664 schedule_work(&adapter->reset_task);
3665 }
3666 }
3667
Bruce Allanad680762008-03-28 09:15:03 -07003668 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07003669 if (adapter->msix_entries)
3670 ew32(ICS, adapter->rx_ring->ims_val);
3671 else
3672 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003673
3674 /* Force detection of hung controller every watchdog period */
3675 adapter->detect_tx_hung = 1;
3676
Bruce Allanad680762008-03-28 09:15:03 -07003677 /*
3678 * With 82571 controllers, LAA may be overwritten due to controller
3679 * reset from the other port. Set the appropriate LAA in RAR[0]
3680 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681 if (e1000e_get_laa_state_82571(hw))
3682 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
3683
3684 /* Reset the timer */
3685 if (!test_bit(__E1000_DOWN, &adapter->state))
3686 mod_timer(&adapter->watchdog_timer,
3687 round_jiffies(jiffies + 2 * HZ));
3688}
3689
3690#define E1000_TX_FLAGS_CSUM 0x00000001
3691#define E1000_TX_FLAGS_VLAN 0x00000002
3692#define E1000_TX_FLAGS_TSO 0x00000004
3693#define E1000_TX_FLAGS_IPV4 0x00000008
3694#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
3695#define E1000_TX_FLAGS_VLAN_SHIFT 16
3696
3697static int e1000_tso(struct e1000_adapter *adapter,
3698 struct sk_buff *skb)
3699{
3700 struct e1000_ring *tx_ring = adapter->tx_ring;
3701 struct e1000_context_desc *context_desc;
3702 struct e1000_buffer *buffer_info;
3703 unsigned int i;
3704 u32 cmd_length = 0;
3705 u16 ipcse = 0, tucse, mss;
3706 u8 ipcss, ipcso, tucss, tucso, hdr_len;
3707 int err;
3708
3709 if (skb_is_gso(skb)) {
3710 if (skb_header_cloned(skb)) {
3711 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3712 if (err)
3713 return err;
3714 }
3715
3716 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3717 mss = skb_shinfo(skb)->gso_size;
3718 if (skb->protocol == htons(ETH_P_IP)) {
3719 struct iphdr *iph = ip_hdr(skb);
3720 iph->tot_len = 0;
3721 iph->check = 0;
3722 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3723 iph->daddr, 0,
3724 IPPROTO_TCP,
3725 0);
3726 cmd_length = E1000_TXD_CMD_IP;
3727 ipcse = skb_transport_offset(skb) - 1;
3728 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3729 ipv6_hdr(skb)->payload_len = 0;
3730 tcp_hdr(skb)->check =
3731 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3732 &ipv6_hdr(skb)->daddr,
3733 0, IPPROTO_TCP, 0);
3734 ipcse = 0;
3735 }
3736 ipcss = skb_network_offset(skb);
3737 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
3738 tucss = skb_transport_offset(skb);
3739 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
3740 tucse = 0;
3741
3742 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
3743 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
3744
3745 i = tx_ring->next_to_use;
3746 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3747 buffer_info = &tx_ring->buffer_info[i];
3748
3749 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3750 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3751 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3752 context_desc->upper_setup.tcp_fields.tucss = tucss;
3753 context_desc->upper_setup.tcp_fields.tucso = tucso;
3754 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3755 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3756 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3757 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3758
3759 buffer_info->time_stamp = jiffies;
3760 buffer_info->next_to_watch = i;
3761
3762 i++;
3763 if (i == tx_ring->count)
3764 i = 0;
3765 tx_ring->next_to_use = i;
3766
3767 return 1;
3768 }
3769
3770 return 0;
3771}
3772
3773static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
3774{
3775 struct e1000_ring *tx_ring = adapter->tx_ring;
3776 struct e1000_context_desc *context_desc;
3777 struct e1000_buffer *buffer_info;
3778 unsigned int i;
3779 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07003780 u32 cmd_len = E1000_TXD_CMD_DEXT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003781
Dave Grahamaf807c82008-10-09 14:28:58 -07003782 if (skb->ip_summed != CHECKSUM_PARTIAL)
3783 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003784
Dave Grahamaf807c82008-10-09 14:28:58 -07003785 switch (skb->protocol) {
3786 case __constant_htons(ETH_P_IP):
3787 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3788 cmd_len |= E1000_TXD_CMD_TCP;
3789 break;
3790 case __constant_htons(ETH_P_IPV6):
3791 /* XXX not handling all IPV6 headers */
3792 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3793 cmd_len |= E1000_TXD_CMD_TCP;
3794 break;
3795 default:
3796 if (unlikely(net_ratelimit()))
3797 e_warn("checksum_partial proto=%x!\n", skb->protocol);
3798 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003799 }
3800
Dave Grahamaf807c82008-10-09 14:28:58 -07003801 css = skb_transport_offset(skb);
3802
3803 i = tx_ring->next_to_use;
3804 buffer_info = &tx_ring->buffer_info[i];
3805 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3806
3807 context_desc->lower_setup.ip_config = 0;
3808 context_desc->upper_setup.tcp_fields.tucss = css;
3809 context_desc->upper_setup.tcp_fields.tucso =
3810 css + skb->csum_offset;
3811 context_desc->upper_setup.tcp_fields.tucse = 0;
3812 context_desc->tcp_seg_setup.data = 0;
3813 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
3814
3815 buffer_info->time_stamp = jiffies;
3816 buffer_info->next_to_watch = i;
3817
3818 i++;
3819 if (i == tx_ring->count)
3820 i = 0;
3821 tx_ring->next_to_use = i;
3822
3823 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003824}
3825
3826#define E1000_MAX_PER_TXD 8192
3827#define E1000_MAX_TXD_PWR 12
3828
3829static int e1000_tx_map(struct e1000_adapter *adapter,
3830 struct sk_buff *skb, unsigned int first,
3831 unsigned int max_per_txd, unsigned int nr_frags,
3832 unsigned int mss)
3833{
3834 struct e1000_ring *tx_ring = adapter->tx_ring;
3835 struct e1000_buffer *buffer_info;
3836 unsigned int len = skb->len - skb->data_len;
3837 unsigned int offset = 0, size, count = 0, i;
3838 unsigned int f;
3839
3840 i = tx_ring->next_to_use;
3841
3842 while (len) {
3843 buffer_info = &tx_ring->buffer_info[i];
3844 size = min(len, max_per_txd);
3845
3846 /* Workaround for premature desc write-backs
3847 * in TSO mode. Append 4-byte sentinel desc */
3848 if (mss && !nr_frags && size == len && size > 8)
3849 size -= 4;
3850
3851 buffer_info->length = size;
3852 /* set time_stamp *before* dma to help avoid a possible race */
3853 buffer_info->time_stamp = jiffies;
3854 buffer_info->dma =
3855 pci_map_single(adapter->pdev,
3856 skb->data + offset,
3857 size,
3858 PCI_DMA_TODEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07003859 if (pci_dma_mapping_error(adapter->pdev, buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003860 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
3861 adapter->tx_dma_failed++;
3862 return -1;
3863 }
3864 buffer_info->next_to_watch = i;
3865
3866 len -= size;
3867 offset += size;
3868 count++;
3869 i++;
3870 if (i == tx_ring->count)
3871 i = 0;
3872 }
3873
3874 for (f = 0; f < nr_frags; f++) {
3875 struct skb_frag_struct *frag;
3876
3877 frag = &skb_shinfo(skb)->frags[f];
3878 len = frag->size;
3879 offset = frag->page_offset;
3880
3881 while (len) {
3882 buffer_info = &tx_ring->buffer_info[i];
3883 size = min(len, max_per_txd);
3884 /* Workaround for premature desc write-backs
3885 * in TSO mode. Append 4-byte sentinel desc */
3886 if (mss && f == (nr_frags-1) && size == len && size > 8)
3887 size -= 4;
3888
3889 buffer_info->length = size;
3890 buffer_info->time_stamp = jiffies;
3891 buffer_info->dma =
3892 pci_map_page(adapter->pdev,
3893 frag->page,
3894 offset,
3895 size,
3896 PCI_DMA_TODEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07003897 if (pci_dma_mapping_error(adapter->pdev,
3898 buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003899 dev_err(&adapter->pdev->dev,
3900 "TX DMA page map failed\n");
3901 adapter->tx_dma_failed++;
3902 return -1;
3903 }
3904
3905 buffer_info->next_to_watch = i;
3906
3907 len -= size;
3908 offset += size;
3909 count++;
3910
3911 i++;
3912 if (i == tx_ring->count)
3913 i = 0;
3914 }
3915 }
3916
3917 if (i == 0)
3918 i = tx_ring->count - 1;
3919 else
3920 i--;
3921
3922 tx_ring->buffer_info[i].skb = skb;
3923 tx_ring->buffer_info[first].next_to_watch = i;
3924
3925 return count;
3926}
3927
3928static void e1000_tx_queue(struct e1000_adapter *adapter,
3929 int tx_flags, int count)
3930{
3931 struct e1000_ring *tx_ring = adapter->tx_ring;
3932 struct e1000_tx_desc *tx_desc = NULL;
3933 struct e1000_buffer *buffer_info;
3934 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3935 unsigned int i;
3936
3937 if (tx_flags & E1000_TX_FLAGS_TSO) {
3938 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3939 E1000_TXD_CMD_TSE;
3940 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3941
3942 if (tx_flags & E1000_TX_FLAGS_IPV4)
3943 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3944 }
3945
3946 if (tx_flags & E1000_TX_FLAGS_CSUM) {
3947 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3948 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3949 }
3950
3951 if (tx_flags & E1000_TX_FLAGS_VLAN) {
3952 txd_lower |= E1000_TXD_CMD_VLE;
3953 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3954 }
3955
3956 i = tx_ring->next_to_use;
3957
3958 while (count--) {
3959 buffer_info = &tx_ring->buffer_info[i];
3960 tx_desc = E1000_TX_DESC(*tx_ring, i);
3961 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3962 tx_desc->lower.data =
3963 cpu_to_le32(txd_lower | buffer_info->length);
3964 tx_desc->upper.data = cpu_to_le32(txd_upper);
3965
3966 i++;
3967 if (i == tx_ring->count)
3968 i = 0;
3969 }
3970
3971 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3972
Bruce Allanad680762008-03-28 09:15:03 -07003973 /*
3974 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07003975 * know there are new descriptors to fetch. (Only
3976 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07003977 * such as IA-64).
3978 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003979 wmb();
3980
3981 tx_ring->next_to_use = i;
3982 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07003983 /*
3984 * we need this if more than one processor can write to our tail
3985 * at a time, it synchronizes IO on IA64/Altix systems
3986 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003987 mmiowb();
3988}
3989
3990#define MINIMUM_DHCP_PACKET_SIZE 282
3991static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3992 struct sk_buff *skb)
3993{
3994 struct e1000_hw *hw = &adapter->hw;
3995 u16 length, offset;
3996
3997 if (vlan_tx_tag_present(skb)) {
3998 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id)
3999 && (adapter->hw.mng_cookie.status &
4000 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4001 return 0;
4002 }
4003
4004 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4005 return 0;
4006
4007 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4008 return 0;
4009
4010 {
4011 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4012 struct udphdr *udp;
4013
4014 if (ip->protocol != IPPROTO_UDP)
4015 return 0;
4016
4017 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4018 if (ntohs(udp->dest) != 67)
4019 return 0;
4020
4021 offset = (u8 *)udp + 8 - skb->data;
4022 length = skb->len - offset;
4023 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4024 }
4025
4026 return 0;
4027}
4028
4029static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4030{
4031 struct e1000_adapter *adapter = netdev_priv(netdev);
4032
4033 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004034 /*
4035 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004036 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004037 * but since that doesn't exist yet, just open code it.
4038 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004039 smp_mb();
4040
Bruce Allanad680762008-03-28 09:15:03 -07004041 /*
4042 * We need to check again in a case another CPU has just
4043 * made room available.
4044 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004045 if (e1000_desc_unused(adapter->tx_ring) < size)
4046 return -EBUSY;
4047
4048 /* A reprieve! */
4049 netif_start_queue(netdev);
4050 ++adapter->restart_queue;
4051 return 0;
4052}
4053
4054static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4055{
4056 struct e1000_adapter *adapter = netdev_priv(netdev);
4057
4058 if (e1000_desc_unused(adapter->tx_ring) >= size)
4059 return 0;
4060 return __e1000_maybe_stop_tx(netdev, size);
4061}
4062
4063#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4064static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
4065{
4066 struct e1000_adapter *adapter = netdev_priv(netdev);
4067 struct e1000_ring *tx_ring = adapter->tx_ring;
4068 unsigned int first;
4069 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4070 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4071 unsigned int tx_flags = 0;
Auke Kok4e6c7092007-10-05 14:15:23 -07004072 unsigned int len = skb->len - skb->data_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004073 unsigned long irq_flags;
Auke Kok4e6c7092007-10-05 14:15:23 -07004074 unsigned int nr_frags;
4075 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004076 int count = 0;
4077 int tso;
4078 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004079
4080 if (test_bit(__E1000_DOWN, &adapter->state)) {
4081 dev_kfree_skb_any(skb);
4082 return NETDEV_TX_OK;
4083 }
4084
4085 if (skb->len <= 0) {
4086 dev_kfree_skb_any(skb);
4087 return NETDEV_TX_OK;
4088 }
4089
4090 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004091 /*
4092 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004093 * make sure there is enough room in the FIFO before
4094 * initiating the DMA for each buffer. The calc is:
4095 * 4 = ceil(buffer len/mss). To make sure we don't
4096 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004097 * drops.
4098 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004099 if (mss) {
4100 u8 hdr_len;
4101 max_per_txd = min(mss << 2, max_per_txd);
4102 max_txd_pwr = fls(max_per_txd) - 1;
4103
Bruce Allanad680762008-03-28 09:15:03 -07004104 /*
4105 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4106 * points to just header, pull a few bytes of payload from
4107 * frags into skb->data
4108 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004109 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004110 /*
4111 * we do this workaround for ES2LAN, but it is un-necessary,
4112 * avoiding it could save a lot of cycles
4113 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004114 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004115 unsigned int pull_size;
4116
4117 pull_size = min((unsigned int)4, skb->data_len);
4118 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004119 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004120 dev_kfree_skb_any(skb);
4121 return NETDEV_TX_OK;
4122 }
4123 len = skb->len - skb->data_len;
4124 }
4125 }
4126
4127 /* reserve a descriptor for the offload context */
4128 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4129 count++;
4130 count++;
4131
4132 count += TXD_USE_COUNT(len, max_txd_pwr);
4133
4134 nr_frags = skb_shinfo(skb)->nr_frags;
4135 for (f = 0; f < nr_frags; f++)
4136 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4137 max_txd_pwr);
4138
4139 if (adapter->hw.mac.tx_pkt_filtering)
4140 e1000_transfer_dhcp_info(adapter, skb);
4141
4142 if (!spin_trylock_irqsave(&adapter->tx_queue_lock, irq_flags))
4143 /* Collision - tell upper layer to requeue */
4144 return NETDEV_TX_LOCKED;
4145
Bruce Allanad680762008-03-28 09:15:03 -07004146 /*
4147 * need: count + 2 desc gap to keep tail from touching
4148 * head, otherwise try next time
4149 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004150 if (e1000_maybe_stop_tx(netdev, count + 2)) {
4151 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
4152 return NETDEV_TX_BUSY;
4153 }
4154
4155 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4156 tx_flags |= E1000_TX_FLAGS_VLAN;
4157 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4158 }
4159
4160 first = tx_ring->next_to_use;
4161
4162 tso = e1000_tso(adapter, skb);
4163 if (tso < 0) {
4164 dev_kfree_skb_any(skb);
4165 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
4166 return NETDEV_TX_OK;
4167 }
4168
4169 if (tso)
4170 tx_flags |= E1000_TX_FLAGS_TSO;
4171 else if (e1000_tx_csum(adapter, skb))
4172 tx_flags |= E1000_TX_FLAGS_CSUM;
4173
Bruce Allanad680762008-03-28 09:15:03 -07004174 /*
4175 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004177 * no longer assume, we must.
4178 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004179 if (skb->protocol == htons(ETH_P_IP))
4180 tx_flags |= E1000_TX_FLAGS_IPV4;
4181
4182 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
4183 if (count < 0) {
4184 /* handle pci_map_single() error in e1000_tx_map */
4185 dev_kfree_skb_any(skb);
4186 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
Krishna Kumar7b5dfe1a2007-09-21 09:41:15 -07004187 return NETDEV_TX_OK;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004188 }
4189
4190 e1000_tx_queue(adapter, tx_flags, count);
4191
4192 netdev->trans_start = jiffies;
4193
4194 /* Make sure there is space in the ring for the next send. */
4195 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4196
4197 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
4198 return NETDEV_TX_OK;
4199}
4200
4201/**
4202 * e1000_tx_timeout - Respond to a Tx Hang
4203 * @netdev: network interface device structure
4204 **/
4205static void e1000_tx_timeout(struct net_device *netdev)
4206{
4207 struct e1000_adapter *adapter = netdev_priv(netdev);
4208
4209 /* Do the reset outside of interrupt context */
4210 adapter->tx_timeout_count++;
4211 schedule_work(&adapter->reset_task);
4212}
4213
4214static void e1000_reset_task(struct work_struct *work)
4215{
4216 struct e1000_adapter *adapter;
4217 adapter = container_of(work, struct e1000_adapter, reset_task);
4218
4219 e1000e_reinit_locked(adapter);
4220}
4221
4222/**
4223 * e1000_get_stats - Get System Network Statistics
4224 * @netdev: network interface device structure
4225 *
4226 * Returns the address of the device statistics structure.
4227 * The statistics are actually updated from the timer callback.
4228 **/
4229static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
4230{
4231 struct e1000_adapter *adapter = netdev_priv(netdev);
4232
4233 /* only return the current stats */
4234 return &adapter->net_stats;
4235}
4236
4237/**
4238 * e1000_change_mtu - Change the Maximum Transfer Unit
4239 * @netdev: network interface device structure
4240 * @new_mtu: new value for maximum frame size
4241 *
4242 * Returns 0 on success, negative on failure
4243 **/
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 Alland53f7062008-08-08 18:36:06 -07004249 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -07004250 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004251 e_err("Invalid MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004252 return -EINVAL;
4253 }
4254
4255 /* Jumbo frame size limits */
4256 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
4257 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004258 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004259 return -EINVAL;
4260 }
4261 if (adapter->hw.phy.type == e1000_phy_ife) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004262 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004263 return -EINVAL;
4264 }
4265 }
4266
4267#define MAX_STD_JUMBO_FRAME_SIZE 9234
4268 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004269 e_err("MTU > 9216 not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004270 return -EINVAL;
4271 }
4272
4273 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4274 msleep(1);
4275 /* e1000e_down has a dependency on max_frame_size */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004276 adapter->max_frame_size = max_frame;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004277 if (netif_running(netdev))
4278 e1000e_down(adapter);
4279
Bruce Allanad680762008-03-28 09:15:03 -07004280 /*
4281 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07004282 * means we reserve 2 more, this pushes us to allocate from the next
4283 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07004284 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004285 * However with the new *_jumbo_rx* routines, jumbo receives will use
4286 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07004287 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004288
4289 if (max_frame <= 256)
4290 adapter->rx_buffer_len = 256;
4291 else if (max_frame <= 512)
4292 adapter->rx_buffer_len = 512;
4293 else if (max_frame <= 1024)
4294 adapter->rx_buffer_len = 1024;
4295 else if (max_frame <= 2048)
4296 adapter->rx_buffer_len = 2048;
4297 else
4298 adapter->rx_buffer_len = 4096;
4299
4300 /* adjust allocation if LPE protects us, and we aren't using SBP */
4301 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
4302 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
4303 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07004304 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004305
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004306 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004307 netdev->mtu = new_mtu;
4308
4309 if (netif_running(netdev))
4310 e1000e_up(adapter);
4311 else
4312 e1000e_reset(adapter);
4313
4314 clear_bit(__E1000_RESETTING, &adapter->state);
4315
4316 return 0;
4317}
4318
4319static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4320 int cmd)
4321{
4322 struct e1000_adapter *adapter = netdev_priv(netdev);
4323 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004324
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004325 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004326 return -EOPNOTSUPP;
4327
4328 switch (cmd) {
4329 case SIOCGMIIPHY:
4330 data->phy_id = adapter->hw.phy.addr;
4331 break;
4332 case SIOCGMIIREG:
4333 if (!capable(CAP_NET_ADMIN))
4334 return -EPERM;
Bruce Allan7c257692008-04-23 11:09:00 -07004335 switch (data->reg_num & 0x1F) {
4336 case MII_BMCR:
4337 data->val_out = adapter->phy_regs.bmcr;
4338 break;
4339 case MII_BMSR:
4340 data->val_out = adapter->phy_regs.bmsr;
4341 break;
4342 case MII_PHYSID1:
4343 data->val_out = (adapter->hw.phy.id >> 16);
4344 break;
4345 case MII_PHYSID2:
4346 data->val_out = (adapter->hw.phy.id & 0xFFFF);
4347 break;
4348 case MII_ADVERTISE:
4349 data->val_out = adapter->phy_regs.advertise;
4350 break;
4351 case MII_LPA:
4352 data->val_out = adapter->phy_regs.lpa;
4353 break;
4354 case MII_EXPANSION:
4355 data->val_out = adapter->phy_regs.expansion;
4356 break;
4357 case MII_CTRL1000:
4358 data->val_out = adapter->phy_regs.ctrl1000;
4359 break;
4360 case MII_STAT1000:
4361 data->val_out = adapter->phy_regs.stat1000;
4362 break;
4363 case MII_ESTATUS:
4364 data->val_out = adapter->phy_regs.estatus;
4365 break;
4366 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004367 return -EIO;
4368 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004369 break;
4370 case SIOCSMIIREG:
4371 default:
4372 return -EOPNOTSUPP;
4373 }
4374 return 0;
4375}
4376
4377static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4378{
4379 switch (cmd) {
4380 case SIOCGMIIPHY:
4381 case SIOCGMIIREG:
4382 case SIOCSMIIREG:
4383 return e1000_mii_ioctl(netdev, ifr, cmd);
4384 default:
4385 return -EOPNOTSUPP;
4386 }
4387}
4388
4389static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4390{
4391 struct net_device *netdev = pci_get_drvdata(pdev);
4392 struct e1000_adapter *adapter = netdev_priv(netdev);
4393 struct e1000_hw *hw = &adapter->hw;
4394 u32 ctrl, ctrl_ext, rctl, status;
4395 u32 wufc = adapter->wol;
4396 int retval = 0;
4397
4398 netif_device_detach(netdev);
4399
4400 if (netif_running(netdev)) {
4401 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
4402 e1000e_down(adapter);
4403 e1000_free_irq(adapter);
4404 }
Bruce Allan4662e822008-08-26 18:37:06 -07004405 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004406
4407 retval = pci_save_state(pdev);
4408 if (retval)
4409 return retval;
4410
4411 status = er32(STATUS);
4412 if (status & E1000_STATUS_LU)
4413 wufc &= ~E1000_WUFC_LNKC;
4414
4415 if (wufc) {
4416 e1000_setup_rctl(adapter);
4417 e1000_set_multi(netdev);
4418
4419 /* turn on all-multi mode if wake on multicast is enabled */
4420 if (wufc & E1000_WUFC_MC) {
4421 rctl = er32(RCTL);
4422 rctl |= E1000_RCTL_MPE;
4423 ew32(RCTL, rctl);
4424 }
4425
4426 ctrl = er32(CTRL);
4427 /* advertise wake from D3Cold */
4428 #define E1000_CTRL_ADVD3WUC 0x00100000
4429 /* phy power management enable */
4430 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4431 ctrl |= E1000_CTRL_ADVD3WUC |
4432 E1000_CTRL_EN_PHY_PWR_MGMT;
4433 ew32(CTRL, ctrl);
4434
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004435 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
4436 adapter->hw.phy.media_type ==
4437 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004438 /* keep the laser running in D3 */
4439 ctrl_ext = er32(CTRL_EXT);
4440 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4441 ew32(CTRL_EXT, ctrl_ext);
4442 }
4443
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004444 if (adapter->flags & FLAG_IS_ICH)
4445 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
4446
Auke Kokbc7f75f2007-09-17 12:30:59 -07004447 /* Allow time for pending master requests to run */
4448 e1000e_disable_pcie_master(&adapter->hw);
4449
4450 ew32(WUC, E1000_WUC_PME_EN);
4451 ew32(WUFC, wufc);
4452 pci_enable_wake(pdev, PCI_D3hot, 1);
4453 pci_enable_wake(pdev, PCI_D3cold, 1);
4454 } else {
4455 ew32(WUC, 0);
4456 ew32(WUFC, 0);
4457 pci_enable_wake(pdev, PCI_D3hot, 0);
4458 pci_enable_wake(pdev, PCI_D3cold, 0);
4459 }
4460
Auke Kokbc7f75f2007-09-17 12:30:59 -07004461 /* make sure adapter isn't asleep if manageability is enabled */
4462 if (adapter->flags & FLAG_MNG_PT_ENABLED) {
4463 pci_enable_wake(pdev, PCI_D3hot, 1);
4464 pci_enable_wake(pdev, PCI_D3cold, 1);
4465 }
4466
4467 if (adapter->hw.phy.type == e1000_phy_igp_3)
4468 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
4469
Bruce Allanad680762008-03-28 09:15:03 -07004470 /*
4471 * Release control of h/w to f/w. If f/w is AMT enabled, this
4472 * would have already happened in close and is redundant.
4473 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004474 e1000_release_hw_control(adapter);
4475
4476 pci_disable_device(pdev);
4477
Alexander Duyck005cbdf2008-11-21 16:49:10 -08004478 /*
4479 * The pci-e switch on some quad port adapters will report a
4480 * correctable error when the MAC transitions from D0 to D3. To
4481 * prevent this we need to mask off the correctable errors on the
4482 * downstream port of the pci-e switch.
4483 */
4484 if (adapter->flags & FLAG_IS_QUAD_PORT) {
4485 struct pci_dev *us_dev = pdev->bus->self;
4486 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
4487 u16 devctl;
4488
4489 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
4490 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
4491 (devctl & ~PCI_EXP_DEVCTL_CERE));
4492
4493 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4494
4495 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
4496 } else {
4497 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4498 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004499
4500 return 0;
4501}
4502
Auke Kok1eae4eb2007-10-31 15:22:00 -07004503static void e1000e_disable_l1aspm(struct pci_dev *pdev)
4504{
4505 int pos;
Auke Kok1eae4eb2007-10-31 15:22:00 -07004506 u16 val;
4507
4508 /*
4509 * 82573 workaround - disable L1 ASPM on mobile chipsets
4510 *
4511 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
4512 * resulting in lost data or garbage information on the pci-e link
4513 * level. This could result in (false) bad EEPROM checksum errors,
4514 * long ping times (up to 2s) or even a system freeze/hang.
4515 *
4516 * Unfortunately this feature saves about 1W power consumption when
4517 * active.
4518 */
4519 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
Auke Kok1eae4eb2007-10-31 15:22:00 -07004520 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val);
4521 if (val & 0x2) {
4522 dev_warn(&pdev->dev, "Disabling L1 ASPM\n");
4523 val &= ~0x2;
4524 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val);
4525 }
4526}
4527
Auke Kokbc7f75f2007-09-17 12:30:59 -07004528#ifdef CONFIG_PM
4529static int e1000_resume(struct pci_dev *pdev)
4530{
4531 struct net_device *netdev = pci_get_drvdata(pdev);
4532 struct e1000_adapter *adapter = netdev_priv(netdev);
4533 struct e1000_hw *hw = &adapter->hw;
4534 u32 err;
4535
4536 pci_set_power_state(pdev, PCI_D0);
4537 pci_restore_state(pdev);
Auke Kok1eae4eb2007-10-31 15:22:00 -07004538 e1000e_disable_l1aspm(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004539
Bruce Allanf0f422e2008-08-04 17:21:53 -07004540 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004541 if (err) {
4542 dev_err(&pdev->dev,
4543 "Cannot enable PCI device from suspend\n");
4544 return err;
4545 }
4546
4547 pci_set_master(pdev);
4548
4549 pci_enable_wake(pdev, PCI_D3hot, 0);
4550 pci_enable_wake(pdev, PCI_D3cold, 0);
4551
Bruce Allan4662e822008-08-26 18:37:06 -07004552 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004553 if (netif_running(netdev)) {
4554 err = e1000_request_irq(adapter);
4555 if (err)
4556 return err;
4557 }
4558
4559 e1000e_power_up_phy(adapter);
4560 e1000e_reset(adapter);
4561 ew32(WUS, ~0);
4562
4563 e1000_init_manageability(adapter);
4564
4565 if (netif_running(netdev))
4566 e1000e_up(adapter);
4567
4568 netif_device_attach(netdev);
4569
Bruce Allanad680762008-03-28 09:15:03 -07004570 /*
4571 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004572 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07004573 * under the control of the driver.
4574 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004575 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004576 e1000_get_hw_control(adapter);
4577
4578 return 0;
4579}
4580#endif
4581
4582static void e1000_shutdown(struct pci_dev *pdev)
4583{
4584 e1000_suspend(pdev, PMSG_SUSPEND);
4585}
4586
4587#ifdef CONFIG_NET_POLL_CONTROLLER
4588/*
4589 * Polling 'interrupt' - used by things like netconsole to send skbs
4590 * without having to re-enable interrupts. It's not called while
4591 * the interrupt routine is executing.
4592 */
4593static void e1000_netpoll(struct net_device *netdev)
4594{
4595 struct e1000_adapter *adapter = netdev_priv(netdev);
4596
4597 disable_irq(adapter->pdev->irq);
4598 e1000_intr(adapter->pdev->irq, netdev);
4599
Auke Kokbc7f75f2007-09-17 12:30:59 -07004600 enable_irq(adapter->pdev->irq);
4601}
4602#endif
4603
4604/**
4605 * e1000_io_error_detected - called when PCI error is detected
4606 * @pdev: Pointer to PCI device
4607 * @state: The current pci connection state
4608 *
4609 * This function is called after a PCI bus error affecting
4610 * this device has been detected.
4611 */
4612static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
4613 pci_channel_state_t state)
4614{
4615 struct net_device *netdev = pci_get_drvdata(pdev);
4616 struct e1000_adapter *adapter = netdev_priv(netdev);
4617
4618 netif_device_detach(netdev);
4619
4620 if (netif_running(netdev))
4621 e1000e_down(adapter);
4622 pci_disable_device(pdev);
4623
4624 /* Request a slot slot reset. */
4625 return PCI_ERS_RESULT_NEED_RESET;
4626}
4627
4628/**
4629 * e1000_io_slot_reset - called after the pci bus has been reset.
4630 * @pdev: Pointer to PCI device
4631 *
4632 * Restart the card from scratch, as if from a cold-boot. Implementation
4633 * resembles the first-half of the e1000_resume routine.
4634 */
4635static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4636{
4637 struct net_device *netdev = pci_get_drvdata(pdev);
4638 struct e1000_adapter *adapter = netdev_priv(netdev);
4639 struct e1000_hw *hw = &adapter->hw;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004640 int err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004641
Auke Kok1eae4eb2007-10-31 15:22:00 -07004642 e1000e_disable_l1aspm(pdev);
Bruce Allanf0f422e2008-08-04 17:21:53 -07004643 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004644 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004645 dev_err(&pdev->dev,
4646 "Cannot re-enable PCI device after reset.\n");
4647 return PCI_ERS_RESULT_DISCONNECT;
4648 }
4649 pci_set_master(pdev);
Wendy Xiongaad32732008-04-23 11:09:29 -07004650 pci_restore_state(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004651
4652 pci_enable_wake(pdev, PCI_D3hot, 0);
4653 pci_enable_wake(pdev, PCI_D3cold, 0);
4654
4655 e1000e_reset(adapter);
4656 ew32(WUS, ~0);
4657
4658 return PCI_ERS_RESULT_RECOVERED;
4659}
4660
4661/**
4662 * e1000_io_resume - called when traffic can start flowing again.
4663 * @pdev: Pointer to PCI device
4664 *
4665 * This callback is called when the error recovery driver tells us that
4666 * its OK to resume normal operation. Implementation resembles the
4667 * second-half of the e1000_resume routine.
4668 */
4669static void e1000_io_resume(struct pci_dev *pdev)
4670{
4671 struct net_device *netdev = pci_get_drvdata(pdev);
4672 struct e1000_adapter *adapter = netdev_priv(netdev);
4673
4674 e1000_init_manageability(adapter);
4675
4676 if (netif_running(netdev)) {
4677 if (e1000e_up(adapter)) {
4678 dev_err(&pdev->dev,
4679 "can't bring device back up after reset\n");
4680 return;
4681 }
4682 }
4683
4684 netif_device_attach(netdev);
4685
Bruce Allanad680762008-03-28 09:15:03 -07004686 /*
4687 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004688 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07004689 * under the control of the driver.
4690 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004691 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004692 e1000_get_hw_control(adapter);
4693
4694}
4695
4696static void e1000_print_device_info(struct e1000_adapter *adapter)
4697{
4698 struct e1000_hw *hw = &adapter->hw;
4699 struct net_device *netdev = adapter->netdev;
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004700 u32 pba_num;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004701
4702 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07004703 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004704 /* bus width */
4705 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
4706 "Width x1"),
4707 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07004708 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004709 e_info("Intel(R) PRO/%s Network Connection\n",
4710 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004711 e1000e_read_pba_num(hw, &pba_num);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004712 e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4713 hw->mac.type, hw->phy.type, (pba_num >> 8), (pba_num & 0xff));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004714}
4715
Auke Kok10aa4c02008-08-04 17:21:20 -07004716static void e1000_eeprom_checks(struct e1000_adapter *adapter)
4717{
4718 struct e1000_hw *hw = &adapter->hw;
4719 int ret_val;
4720 u16 buf = 0;
4721
4722 if (hw->mac.type != e1000_82573)
4723 return;
4724
4725 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
4726 if (!(le16_to_cpu(buf) & (1 << 0))) {
4727 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07004728 dev_warn(&adapter->pdev->dev,
4729 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07004730 }
4731
4732 ret_val = e1000_read_nvm(hw, NVM_INIT_3GIO_3, 1, &buf);
4733 if (le16_to_cpu(buf) & (3 << 2)) {
4734 /* ASPM enable */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07004735 dev_warn(&adapter->pdev->dev,
4736 "Warning: detected ASPM enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07004737 }
4738}
4739
Stephen Hemminger651c2462008-11-19 21:57:48 -08004740static const struct net_device_ops e1000e_netdev_ops = {
4741 .ndo_open = e1000_open,
4742 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08004743 .ndo_start_xmit = e1000_xmit_frame,
Stephen Hemminger651c2462008-11-19 21:57:48 -08004744 .ndo_get_stats = e1000_get_stats,
4745 .ndo_set_multicast_list = e1000_set_multi,
4746 .ndo_set_mac_address = e1000_set_mac,
4747 .ndo_change_mtu = e1000_change_mtu,
4748 .ndo_do_ioctl = e1000_ioctl,
4749 .ndo_tx_timeout = e1000_tx_timeout,
4750 .ndo_validate_addr = eth_validate_addr,
4751
4752 .ndo_vlan_rx_register = e1000_vlan_rx_register,
4753 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
4754 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
4755#ifdef CONFIG_NET_POLL_CONTROLLER
4756 .ndo_poll_controller = e1000_netpoll,
4757#endif
4758};
4759
Auke Kokbc7f75f2007-09-17 12:30:59 -07004760/**
4761 * e1000_probe - Device Initialization Routine
4762 * @pdev: PCI device information struct
4763 * @ent: entry in e1000_pci_tbl
4764 *
4765 * Returns 0 on success, negative on failure
4766 *
4767 * e1000_probe initializes an adapter identified by a pci_dev structure.
4768 * The OS initialization, configuring of the adapter private structure,
4769 * and a hardware reset occur.
4770 **/
4771static int __devinit e1000_probe(struct pci_dev *pdev,
4772 const struct pci_device_id *ent)
4773{
4774 struct net_device *netdev;
4775 struct e1000_adapter *adapter;
4776 struct e1000_hw *hw;
4777 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05004778 resource_size_t mmio_start, mmio_len;
4779 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004780
4781 static int cards_found;
4782 int i, err, pci_using_dac;
4783 u16 eeprom_data = 0;
4784 u16 eeprom_apme_mask = E1000_EEPROM_APME;
4785
Auke Kok1eae4eb2007-10-31 15:22:00 -07004786 e1000e_disable_l1aspm(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004787
Bruce Allanf0f422e2008-08-04 17:21:53 -07004788 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004789 if (err)
4790 return err;
4791
4792 pci_using_dac = 0;
4793 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
4794 if (!err) {
4795 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
4796 if (!err)
4797 pci_using_dac = 1;
4798 } else {
4799 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4800 if (err) {
4801 err = pci_set_consistent_dma_mask(pdev,
4802 DMA_32BIT_MASK);
4803 if (err) {
4804 dev_err(&pdev->dev, "No usable DMA "
4805 "configuration, aborting\n");
4806 goto err_dma;
4807 }
4808 }
4809 }
4810
Bruce Allanf0f422e2008-08-04 17:21:53 -07004811 err = pci_request_selected_regions(pdev,
4812 pci_select_bars(pdev, IORESOURCE_MEM),
4813 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004814 if (err)
4815 goto err_pci_reg;
4816
4817 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08004818 /* PCI config space info */
4819 err = pci_save_state(pdev);
4820 if (err)
4821 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004822
4823 err = -ENOMEM;
4824 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
4825 if (!netdev)
4826 goto err_alloc_etherdev;
4827
Auke Kokbc7f75f2007-09-17 12:30:59 -07004828 SET_NETDEV_DEV(netdev, &pdev->dev);
4829
4830 pci_set_drvdata(pdev, netdev);
4831 adapter = netdev_priv(netdev);
4832 hw = &adapter->hw;
4833 adapter->netdev = netdev;
4834 adapter->pdev = pdev;
4835 adapter->ei = ei;
4836 adapter->pba = ei->pba;
4837 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00004838 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004839 adapter->hw.adapter = adapter;
4840 adapter->hw.mac.type = ei->mac;
4841 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
4842
4843 mmio_start = pci_resource_start(pdev, 0);
4844 mmio_len = pci_resource_len(pdev, 0);
4845
4846 err = -EIO;
4847 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
4848 if (!adapter->hw.hw_addr)
4849 goto err_ioremap;
4850
4851 if ((adapter->flags & FLAG_HAS_FLASH) &&
4852 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
4853 flash_start = pci_resource_start(pdev, 1);
4854 flash_len = pci_resource_len(pdev, 1);
4855 adapter->hw.flash_address = ioremap(flash_start, flash_len);
4856 if (!adapter->hw.flash_address)
4857 goto err_flashmap;
4858 }
4859
4860 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08004861 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004862 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004863 netdev->watchdog_timeo = 5 * HZ;
4864 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004865 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
4866
4867 netdev->mem_start = mmio_start;
4868 netdev->mem_end = mmio_start + mmio_len;
4869
4870 adapter->bd_number = cards_found++;
4871
Bruce Allan4662e822008-08-26 18:37:06 -07004872 e1000e_check_options(adapter);
4873
Auke Kokbc7f75f2007-09-17 12:30:59 -07004874 /* setup adapter struct */
4875 err = e1000_sw_init(adapter);
4876 if (err)
4877 goto err_sw_init;
4878
4879 err = -EIO;
4880
4881 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
4882 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
4883 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
4884
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004885 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004886 if (err)
4887 goto err_hw_init;
4888
Bruce Allan4a770352008-10-01 17:18:35 -07004889 if ((adapter->flags & FLAG_IS_ICH) &&
4890 (adapter->flags & FLAG_READ_ONLY_NVM))
4891 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
4892
Auke Kokbc7f75f2007-09-17 12:30:59 -07004893 hw->mac.ops.get_bus_info(&adapter->hw);
4894
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004895 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004896
4897 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004898 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004899 adapter->hw.phy.mdix = AUTO_ALL_MODES;
4900 adapter->hw.phy.disable_polarity_correction = 0;
4901 adapter->hw.phy.ms_type = e1000_ms_hw_default;
4902 }
4903
4904 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004905 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004906
4907 netdev->features = NETIF_F_SG |
4908 NETIF_F_HW_CSUM |
4909 NETIF_F_HW_VLAN_TX |
4910 NETIF_F_HW_VLAN_RX;
4911
4912 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
4913 netdev->features |= NETIF_F_HW_VLAN_FILTER;
4914
4915 netdev->features |= NETIF_F_TSO;
4916 netdev->features |= NETIF_F_TSO6;
4917
Jeff Kirshera5136e22008-06-05 04:07:28 -07004918 netdev->vlan_features |= NETIF_F_TSO;
4919 netdev->vlan_features |= NETIF_F_TSO6;
4920 netdev->vlan_features |= NETIF_F_HW_CSUM;
4921 netdev->vlan_features |= NETIF_F_SG;
4922
Auke Kokbc7f75f2007-09-17 12:30:59 -07004923 if (pci_using_dac)
4924 netdev->features |= NETIF_F_HIGHDMA;
4925
Bruce Allanad680762008-03-28 09:15:03 -07004926 /*
4927 * We should not be using LLTX anymore, but we are still Tx faster with
4928 * it.
4929 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004930 netdev->features |= NETIF_F_LLTX;
4931
4932 if (e1000e_enable_mng_pass_thru(&adapter->hw))
4933 adapter->flags |= FLAG_MNG_PT_ENABLED;
4934
Bruce Allanad680762008-03-28 09:15:03 -07004935 /*
4936 * before reading the NVM, reset the controller to
4937 * put the device in a known good starting state
4938 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004939 adapter->hw.mac.ops.reset_hw(&adapter->hw);
4940
4941 /*
4942 * systems with ASPM and others may see the checksum fail on the first
4943 * attempt. Let's give it a few tries
4944 */
4945 for (i = 0;; i++) {
4946 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
4947 break;
4948 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004949 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004950 err = -EIO;
4951 goto err_eeprom;
4952 }
4953 }
4954
Auke Kok10aa4c02008-08-04 17:21:20 -07004955 e1000_eeprom_checks(adapter);
4956
Auke Kokbc7f75f2007-09-17 12:30:59 -07004957 /* copy the MAC address out of the NVM */
4958 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004959 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004960
4961 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
4962 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
4963
4964 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07004965 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004966 err = -EIO;
4967 goto err_eeprom;
4968 }
4969
4970 init_timer(&adapter->watchdog_timer);
4971 adapter->watchdog_timer.function = &e1000_watchdog;
4972 adapter->watchdog_timer.data = (unsigned long) adapter;
4973
4974 init_timer(&adapter->phy_info_timer);
4975 adapter->phy_info_timer.function = &e1000_update_phy_info;
4976 adapter->phy_info_timer.data = (unsigned long) adapter;
4977
4978 INIT_WORK(&adapter->reset_task, e1000_reset_task);
4979 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004980 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
4981 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004982
Auke Kokbc7f75f2007-09-17 12:30:59 -07004983 /* Initialize link parameters. User can change them with ethtool */
4984 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07004985 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08004986 adapter->hw.fc.requested_mode = e1000_fc_default;
4987 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004988 adapter->hw.phy.autoneg_advertised = 0x2f;
4989
4990 /* ring size defaults */
4991 adapter->rx_ring->count = 256;
4992 adapter->tx_ring->count = 256;
4993
4994 /*
4995 * Initial Wake on LAN setting - If APM wake is enabled in
4996 * the EEPROM, enable the ACPI Magic Packet filter
4997 */
4998 if (adapter->flags & FLAG_APME_IN_WUC) {
4999 /* APME bit in EEPROM is mapped to WUC.APME */
5000 eeprom_data = er32(WUC);
5001 eeprom_apme_mask = E1000_WUC_APME;
5002 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
5003 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
5004 (adapter->hw.bus.func == 1))
5005 e1000_read_nvm(&adapter->hw,
5006 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
5007 else
5008 e1000_read_nvm(&adapter->hw,
5009 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
5010 }
5011
5012 /* fetch WoL from EEPROM */
5013 if (eeprom_data & eeprom_apme_mask)
5014 adapter->eeprom_wol |= E1000_WUFC_MAG;
5015
5016 /*
5017 * now that we have the eeprom settings, apply the special cases
5018 * where the eeprom may be wrong or the board simply won't support
5019 * wake on lan on a particular port
5020 */
5021 if (!(adapter->flags & FLAG_HAS_WOL))
5022 adapter->eeprom_wol = 0;
5023
5024 /* initialize the wol settings based on the eeprom settings */
5025 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00005026 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005027
5028 /* reset the hardware with the new settings */
5029 e1000e_reset(adapter);
5030
Bruce Allanad680762008-03-28 09:15:03 -07005031 /*
5032 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005033 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005034 * under the control of the driver.
5035 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005036 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037 e1000_get_hw_control(adapter);
5038
5039 /* tell the stack to leave us alone until e1000_open() is called */
5040 netif_carrier_off(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005041 netif_tx_stop_all_queues(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005042
5043 strcpy(netdev->name, "eth%d");
5044 err = register_netdev(netdev);
5045 if (err)
5046 goto err_register;
5047
5048 e1000_print_device_info(adapter);
5049
5050 return 0;
5051
5052err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005053 if (!(adapter->flags & FLAG_HAS_AMT))
5054 e1000_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005055err_eeprom:
5056 if (!e1000_check_reset_block(&adapter->hw))
5057 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005058err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005059
Auke Kokbc7f75f2007-09-17 12:30:59 -07005060 kfree(adapter->tx_ring);
5061 kfree(adapter->rx_ring);
5062err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005063 if (adapter->hw.flash_address)
5064 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00005065 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005066err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005067 iounmap(adapter->hw.hw_addr);
5068err_ioremap:
5069 free_netdev(netdev);
5070err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07005071 pci_release_selected_regions(pdev,
5072 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005073err_pci_reg:
5074err_dma:
5075 pci_disable_device(pdev);
5076 return err;
5077}
5078
5079/**
5080 * e1000_remove - Device Removal Routine
5081 * @pdev: PCI device information struct
5082 *
5083 * e1000_remove is called by the PCI subsystem to alert the driver
5084 * that it should release a PCI device. The could be caused by a
5085 * Hot-Plug event, or because the driver is going to be removed from
5086 * memory.
5087 **/
5088static void __devexit e1000_remove(struct pci_dev *pdev)
5089{
5090 struct net_device *netdev = pci_get_drvdata(pdev);
5091 struct e1000_adapter *adapter = netdev_priv(netdev);
5092
Bruce Allanad680762008-03-28 09:15:03 -07005093 /*
5094 * flush_scheduled work may reschedule our watchdog task, so
5095 * explicitly disable watchdog tasks from being rescheduled
5096 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005097 set_bit(__E1000_DOWN, &adapter->state);
5098 del_timer_sync(&adapter->watchdog_timer);
5099 del_timer_sync(&adapter->phy_info_timer);
5100
5101 flush_scheduled_work();
5102
Bruce Allanad680762008-03-28 09:15:03 -07005103 /*
5104 * Release control of h/w to f/w. If f/w is AMT enabled, this
5105 * would have already happened in close and is redundant.
5106 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107 e1000_release_hw_control(adapter);
5108
5109 unregister_netdev(netdev);
5110
5111 if (!e1000_check_reset_block(&adapter->hw))
5112 e1000_phy_hw_reset(&adapter->hw);
5113
Bruce Allan4662e822008-08-26 18:37:06 -07005114 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005115 kfree(adapter->tx_ring);
5116 kfree(adapter->rx_ring);
5117
5118 iounmap(adapter->hw.hw_addr);
5119 if (adapter->hw.flash_address)
5120 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07005121 pci_release_selected_regions(pdev,
5122 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005123
5124 free_netdev(netdev);
5125
5126 pci_disable_device(pdev);
5127}
5128
5129/* PCI Error Recovery (ERS) */
5130static struct pci_error_handlers e1000_err_handler = {
5131 .error_detected = e1000_io_error_detected,
5132 .slot_reset = e1000_io_slot_reset,
5133 .resume = e1000_io_resume,
5134};
5135
5136static struct pci_device_id e1000_pci_tbl[] = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005137 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
5138 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
5139 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
5140 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
5141 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
5142 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07005143 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
5144 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
5145 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07005146
Auke Kokbc7f75f2007-09-17 12:30:59 -07005147 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
5148 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
5149 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
5150 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07005151
Auke Kokbc7f75f2007-09-17 12:30:59 -07005152 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
5153 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
5154 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07005155
Bruce Allan4662e822008-08-26 18:37:06 -07005156 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
5157
Auke Kokbc7f75f2007-09-17 12:30:59 -07005158 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
5159 board_80003es2lan },
5160 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
5161 board_80003es2lan },
5162 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
5163 board_80003es2lan },
5164 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
5165 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07005166
Auke Kokbc7f75f2007-09-17 12:30:59 -07005167 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
5168 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
5169 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
5170 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
5171 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
5172 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
5173 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07005174
Auke Kokbc7f75f2007-09-17 12:30:59 -07005175 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
5176 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
5177 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
5178 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
5179 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07005180 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005181 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
5182 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
5183 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
5184
5185 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
5186 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
5187 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07005188
Bruce Allanf4187b52008-08-26 18:36:50 -07005189 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
5190 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
5191
Auke Kokbc7f75f2007-09-17 12:30:59 -07005192 { } /* terminate list */
5193};
5194MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
5195
5196/* PCI Device API Driver */
5197static struct pci_driver e1000_driver = {
5198 .name = e1000e_driver_name,
5199 .id_table = e1000_pci_tbl,
5200 .probe = e1000_probe,
5201 .remove = __devexit_p(e1000_remove),
5202#ifdef CONFIG_PM
Bruce Allanad680762008-03-28 09:15:03 -07005203 /* Power Management Hooks */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005204 .suspend = e1000_suspend,
5205 .resume = e1000_resume,
5206#endif
5207 .shutdown = e1000_shutdown,
5208 .err_handler = &e1000_err_handler
5209};
5210
5211/**
5212 * e1000_init_module - Driver Registration Routine
5213 *
5214 * e1000_init_module is the first routine called when the driver is
5215 * loaded. All it does is register with the PCI subsystem.
5216 **/
5217static int __init e1000_init_module(void)
5218{
5219 int ret;
5220 printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
5221 e1000e_driver_name, e1000e_driver_version);
Bruce Allanad680762008-03-28 09:15:03 -07005222 printk(KERN_INFO "%s: Copyright (c) 1999-2008 Intel Corporation.\n",
Auke Kokbc7f75f2007-09-17 12:30:59 -07005223 e1000e_driver_name);
5224 ret = pci_register_driver(&e1000_driver);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005225 pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name,
5226 PM_QOS_DEFAULT_VALUE);
5227
Auke Kokbc7f75f2007-09-17 12:30:59 -07005228 return ret;
5229}
5230module_init(e1000_init_module);
5231
5232/**
5233 * e1000_exit_module - Driver Exit Cleanup Routine
5234 *
5235 * e1000_exit_module is called just before the driver is removed
5236 * from memory.
5237 **/
5238static void __exit e1000_exit_module(void)
5239{
5240 pci_unregister_driver(&e1000_driver);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005241 pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005242}
5243module_exit(e1000_exit_module);
5244
5245
5246MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
5247MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
5248MODULE_LICENSE("GPL");
5249MODULE_VERSION(DRV_VERSION);
5250
5251/* e1000_main.c */