blob: 3eeae1cf994e5b05ed97e53863c75270f0fdc571 [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
Auke Kokbc7f75f2007-09-17 12:30:59 -0700500 total_rx_bytes += length;
501 total_rx_packets++;
502
Bruce Allanad680762008-03-28 09:15:03 -0700503 /*
504 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700505 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700506 * of reassembly being done in the stack
507 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700508 if (length < copybreak) {
509 struct sk_buff *new_skb =
510 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
511 if (new_skb) {
512 skb_reserve(new_skb, NET_IP_ALIGN);
Bruce Allan808ff672008-08-08 18:35:56 -0700513 skb_copy_to_linear_data_offset(new_skb,
514 -NET_IP_ALIGN,
515 (skb->data -
516 NET_IP_ALIGN),
517 (length +
518 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700519 /* save the skb in buffer_info as good */
520 buffer_info->skb = skb;
521 skb = new_skb;
522 }
523 /* else just continue with the old one */
524 }
525 /* end copybreak code */
526 skb_put(skb, length);
527
528 /* Receive Checksum Offload */
529 e1000_rx_checksum(adapter,
530 (u32)(status) |
531 ((u32)(rx_desc->errors) << 24),
532 le16_to_cpu(rx_desc->csum), skb);
533
534 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
535
536next_desc:
537 rx_desc->status = 0;
538
539 /* return some buffers to hardware, one at a time is too slow */
540 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
541 adapter->alloc_rx_buf(adapter, cleaned_count);
542 cleaned_count = 0;
543 }
544
545 /* use prefetched values */
546 rx_desc = next_rxd;
547 buffer_info = next_buffer;
548 }
549 rx_ring->next_to_clean = i;
550
551 cleaned_count = e1000_desc_unused(rx_ring);
552 if (cleaned_count)
553 adapter->alloc_rx_buf(adapter, cleaned_count);
554
Auke Kokbc7f75f2007-09-17 12:30:59 -0700555 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700556 adapter->total_rx_packets += total_rx_packets;
Auke Kok41988692007-11-13 20:48:36 -0800557 adapter->net_stats.rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700558 adapter->net_stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700559 return cleaned;
560}
561
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562static void e1000_put_txbuf(struct e1000_adapter *adapter,
563 struct e1000_buffer *buffer_info)
564{
565 if (buffer_info->dma) {
566 pci_unmap_page(adapter->pdev, buffer_info->dma,
567 buffer_info->length, PCI_DMA_TODEVICE);
568 buffer_info->dma = 0;
569 }
570 if (buffer_info->skb) {
571 dev_kfree_skb_any(buffer_info->skb);
572 buffer_info->skb = NULL;
573 }
574}
575
576static void e1000_print_tx_hang(struct e1000_adapter *adapter)
577{
578 struct e1000_ring *tx_ring = adapter->tx_ring;
579 unsigned int i = tx_ring->next_to_clean;
580 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
581 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700582
583 /* detected Tx unit hang */
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700584 e_err("Detected Tx Unit Hang:\n"
585 " TDH <%x>\n"
586 " TDT <%x>\n"
587 " next_to_use <%x>\n"
588 " next_to_clean <%x>\n"
589 "buffer_info[next_to_clean]:\n"
590 " time_stamp <%lx>\n"
591 " next_to_watch <%x>\n"
592 " jiffies <%lx>\n"
593 " next_to_watch.status <%x>\n",
594 readl(adapter->hw.hw_addr + tx_ring->head),
595 readl(adapter->hw.hw_addr + tx_ring->tail),
596 tx_ring->next_to_use,
597 tx_ring->next_to_clean,
598 tx_ring->buffer_info[eop].time_stamp,
599 eop,
600 jiffies,
601 eop_desc->upper.fields.status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602}
603
604/**
605 * e1000_clean_tx_irq - Reclaim resources after transmit completes
606 * @adapter: board private structure
607 *
608 * the return value indicates whether actual cleaning was done, there
609 * is no guarantee that everything was cleaned
610 **/
611static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
612{
613 struct net_device *netdev = adapter->netdev;
614 struct e1000_hw *hw = &adapter->hw;
615 struct e1000_ring *tx_ring = adapter->tx_ring;
616 struct e1000_tx_desc *tx_desc, *eop_desc;
617 struct e1000_buffer *buffer_info;
618 unsigned int i, eop;
619 unsigned int count = 0;
620 bool cleaned = 0;
621 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
622
623 i = tx_ring->next_to_clean;
624 eop = tx_ring->buffer_info[i].next_to_watch;
625 eop_desc = E1000_TX_DESC(*tx_ring, eop);
626
627 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
628 for (cleaned = 0; !cleaned; ) {
629 tx_desc = E1000_TX_DESC(*tx_ring, i);
630 buffer_info = &tx_ring->buffer_info[i];
631 cleaned = (i == eop);
632
633 if (cleaned) {
634 struct sk_buff *skb = buffer_info->skb;
635 unsigned int segs, bytecount;
636 segs = skb_shinfo(skb)->gso_segs ?: 1;
637 /* multiply data chunks by size of headers */
638 bytecount = ((segs - 1) * skb_headlen(skb)) +
639 skb->len;
640 total_tx_packets += segs;
641 total_tx_bytes += bytecount;
642 }
643
644 e1000_put_txbuf(adapter, buffer_info);
645 tx_desc->upper.data = 0;
646
647 i++;
648 if (i == tx_ring->count)
649 i = 0;
650 }
651
652 eop = tx_ring->buffer_info[i].next_to_watch;
653 eop_desc = E1000_TX_DESC(*tx_ring, eop);
654#define E1000_TX_WEIGHT 64
655 /* weight of a sort for tx, to avoid endless transmit cleanup */
656 if (count++ == E1000_TX_WEIGHT)
657 break;
658 }
659
660 tx_ring->next_to_clean = i;
661
662#define TX_WAKE_THRESHOLD 32
663 if (cleaned && netif_carrier_ok(netdev) &&
664 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
665 /* Make sure that anybody stopping the queue after this
666 * sees the new next_to_clean.
667 */
668 smp_mb();
669
670 if (netif_queue_stopped(netdev) &&
671 !(test_bit(__E1000_DOWN, &adapter->state))) {
672 netif_wake_queue(netdev);
673 ++adapter->restart_queue;
674 }
675 }
676
677 if (adapter->detect_tx_hung) {
Bruce Allanad680762008-03-28 09:15:03 -0700678 /*
679 * Detect a transmit hang in hardware, this serializes the
680 * check with the clearing of time_stamp and movement of i
681 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700682 adapter->detect_tx_hung = 0;
683 if (tx_ring->buffer_info[eop].dma &&
684 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp
685 + (adapter->tx_timeout_factor * HZ))
Bruce Allanad680762008-03-28 09:15:03 -0700686 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700687 e1000_print_tx_hang(adapter);
688 netif_stop_queue(netdev);
689 }
690 }
691 adapter->total_tx_bytes += total_tx_bytes;
692 adapter->total_tx_packets += total_tx_packets;
Auke Kok41988692007-11-13 20:48:36 -0800693 adapter->net_stats.tx_bytes += total_tx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700694 adapter->net_stats.tx_packets += total_tx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700695 return cleaned;
696}
697
698/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700699 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
700 * @adapter: board private structure
701 *
702 * the return value indicates whether actual cleaning was done, there
703 * is no guarantee that everything was cleaned
704 **/
705static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
706 int *work_done, int work_to_do)
707{
708 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
709 struct net_device *netdev = adapter->netdev;
710 struct pci_dev *pdev = adapter->pdev;
711 struct e1000_ring *rx_ring = adapter->rx_ring;
712 struct e1000_buffer *buffer_info, *next_buffer;
713 struct e1000_ps_page *ps_page;
714 struct sk_buff *skb;
715 unsigned int i, j;
716 u32 length, staterr;
717 int cleaned_count = 0;
718 bool cleaned = 0;
719 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
720
721 i = rx_ring->next_to_clean;
722 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
723 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
724 buffer_info = &rx_ring->buffer_info[i];
725
726 while (staterr & E1000_RXD_STAT_DD) {
727 if (*work_done >= work_to_do)
728 break;
729 (*work_done)++;
730 skb = buffer_info->skb;
731
732 /* in the packet split case this is header only */
733 prefetch(skb->data - NET_IP_ALIGN);
734
735 i++;
736 if (i == rx_ring->count)
737 i = 0;
738 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
739 prefetch(next_rxd);
740
741 next_buffer = &rx_ring->buffer_info[i];
742
743 cleaned = 1;
744 cleaned_count++;
745 pci_unmap_single(pdev, buffer_info->dma,
746 adapter->rx_ps_bsize0,
747 PCI_DMA_FROMDEVICE);
748 buffer_info->dma = 0;
749
750 if (!(staterr & E1000_RXD_STAT_EOP)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700751 e_dbg("%s: Packet Split buffers didn't pick up the "
752 "full packet\n", netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700753 dev_kfree_skb_irq(skb);
754 goto next_desc;
755 }
756
757 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
758 dev_kfree_skb_irq(skb);
759 goto next_desc;
760 }
761
762 length = le16_to_cpu(rx_desc->wb.middle.length0);
763
764 if (!length) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700765 e_dbg("%s: Last part of the packet spanning multiple "
766 "descriptors\n", netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700767 dev_kfree_skb_irq(skb);
768 goto next_desc;
769 }
770
771 /* Good Receive */
772 skb_put(skb, length);
773
774 {
Bruce Allanad680762008-03-28 09:15:03 -0700775 /*
776 * this looks ugly, but it seems compiler issues make it
777 * more efficient than reusing j
778 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700779 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
780
Bruce Allanad680762008-03-28 09:15:03 -0700781 /*
782 * page alloc/put takes too long and effects small packet
783 * throughput, so unsplit small packets and save the alloc/put
784 * only valid in softirq (napi) context to call kmap_*
785 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700786 if (l1 && (l1 <= copybreak) &&
787 ((length + l1) <= adapter->rx_ps_bsize0)) {
788 u8 *vaddr;
789
Auke Kok47f44e42007-10-25 13:57:44 -0700790 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700791
Bruce Allanad680762008-03-28 09:15:03 -0700792 /*
793 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -0700794 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -0700795 * very long
796 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700797 pci_dma_sync_single_for_cpu(pdev, ps_page->dma,
798 PAGE_SIZE, PCI_DMA_FROMDEVICE);
799 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
800 memcpy(skb_tail_pointer(skb), vaddr, l1);
801 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
802 pci_dma_sync_single_for_device(pdev, ps_page->dma,
803 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kok140a7482007-10-25 13:57:58 -0700804
Auke Kokbc7f75f2007-09-17 12:30:59 -0700805 skb_put(skb, l1);
806 goto copydone;
807 } /* if */
808 }
809
810 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
811 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
812 if (!length)
813 break;
814
Auke Kok47f44e42007-10-25 13:57:44 -0700815 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700816 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
817 PCI_DMA_FROMDEVICE);
818 ps_page->dma = 0;
819 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
820 ps_page->page = NULL;
821 skb->len += length;
822 skb->data_len += length;
823 skb->truesize += length;
824 }
825
Auke Kokbc7f75f2007-09-17 12:30:59 -0700826copydone:
827 total_rx_bytes += skb->len;
828 total_rx_packets++;
829
830 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
831 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
832
833 if (rx_desc->wb.upper.header_status &
834 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
835 adapter->rx_hdr_split++;
836
837 e1000_receive_skb(adapter, netdev, skb,
838 staterr, rx_desc->wb.middle.vlan);
839
840next_desc:
841 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
842 buffer_info->skb = NULL;
843
844 /* return some buffers to hardware, one at a time is too slow */
845 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
846 adapter->alloc_rx_buf(adapter, cleaned_count);
847 cleaned_count = 0;
848 }
849
850 /* use prefetched values */
851 rx_desc = next_rxd;
852 buffer_info = next_buffer;
853
854 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
855 }
856 rx_ring->next_to_clean = i;
857
858 cleaned_count = e1000_desc_unused(rx_ring);
859 if (cleaned_count)
860 adapter->alloc_rx_buf(adapter, cleaned_count);
861
Auke Kokbc7f75f2007-09-17 12:30:59 -0700862 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700863 adapter->total_rx_packets += total_rx_packets;
Auke Kok41988692007-11-13 20:48:36 -0800864 adapter->net_stats.rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700865 adapter->net_stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700866 return cleaned;
867}
868
869/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700870 * e1000_consume_page - helper function
871 **/
872static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
873 u16 length)
874{
875 bi->page = NULL;
876 skb->len += length;
877 skb->data_len += length;
878 skb->truesize += length;
879}
880
881/**
882 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
883 * @adapter: board private structure
884 *
885 * the return value indicates whether actual cleaning was done, there
886 * is no guarantee that everything was cleaned
887 **/
888
889static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
890 int *work_done, int work_to_do)
891{
892 struct net_device *netdev = adapter->netdev;
893 struct pci_dev *pdev = adapter->pdev;
894 struct e1000_ring *rx_ring = adapter->rx_ring;
895 struct e1000_rx_desc *rx_desc, *next_rxd;
896 struct e1000_buffer *buffer_info, *next_buffer;
897 u32 length;
898 unsigned int i;
899 int cleaned_count = 0;
900 bool cleaned = false;
901 unsigned int total_rx_bytes=0, total_rx_packets=0;
902
903 i = rx_ring->next_to_clean;
904 rx_desc = E1000_RX_DESC(*rx_ring, i);
905 buffer_info = &rx_ring->buffer_info[i];
906
907 while (rx_desc->status & E1000_RXD_STAT_DD) {
908 struct sk_buff *skb;
909 u8 status;
910
911 if (*work_done >= work_to_do)
912 break;
913 (*work_done)++;
914
915 status = rx_desc->status;
916 skb = buffer_info->skb;
917 buffer_info->skb = NULL;
918
919 ++i;
920 if (i == rx_ring->count)
921 i = 0;
922 next_rxd = E1000_RX_DESC(*rx_ring, i);
923 prefetch(next_rxd);
924
925 next_buffer = &rx_ring->buffer_info[i];
926
927 cleaned = true;
928 cleaned_count++;
929 pci_unmap_page(pdev, buffer_info->dma, PAGE_SIZE,
930 PCI_DMA_FROMDEVICE);
931 buffer_info->dma = 0;
932
933 length = le16_to_cpu(rx_desc->length);
934
935 /* errors is only valid for DD + EOP descriptors */
936 if (unlikely((status & E1000_RXD_STAT_EOP) &&
937 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
938 /* recycle both page and skb */
939 buffer_info->skb = skb;
940 /* an error means any chain goes out the window
941 * too */
942 if (rx_ring->rx_skb_top)
943 dev_kfree_skb(rx_ring->rx_skb_top);
944 rx_ring->rx_skb_top = NULL;
945 goto next_desc;
946 }
947
948#define rxtop rx_ring->rx_skb_top
949 if (!(status & E1000_RXD_STAT_EOP)) {
950 /* this descriptor is only the beginning (or middle) */
951 if (!rxtop) {
952 /* this is the beginning of a chain */
953 rxtop = skb;
954 skb_fill_page_desc(rxtop, 0, buffer_info->page,
955 0, length);
956 } else {
957 /* this is the middle of a chain */
958 skb_fill_page_desc(rxtop,
959 skb_shinfo(rxtop)->nr_frags,
960 buffer_info->page, 0, length);
961 /* re-use the skb, only consumed the page */
962 buffer_info->skb = skb;
963 }
964 e1000_consume_page(buffer_info, rxtop, length);
965 goto next_desc;
966 } else {
967 if (rxtop) {
968 /* end of the chain */
969 skb_fill_page_desc(rxtop,
970 skb_shinfo(rxtop)->nr_frags,
971 buffer_info->page, 0, length);
972 /* re-use the current skb, we only consumed the
973 * page */
974 buffer_info->skb = skb;
975 skb = rxtop;
976 rxtop = NULL;
977 e1000_consume_page(buffer_info, skb, length);
978 } else {
979 /* no chain, got EOP, this buf is the packet
980 * copybreak to save the put_page/alloc_page */
981 if (length <= copybreak &&
982 skb_tailroom(skb) >= length) {
983 u8 *vaddr;
984 vaddr = kmap_atomic(buffer_info->page,
985 KM_SKB_DATA_SOFTIRQ);
986 memcpy(skb_tail_pointer(skb), vaddr,
987 length);
988 kunmap_atomic(vaddr,
989 KM_SKB_DATA_SOFTIRQ);
990 /* re-use the page, so don't erase
991 * buffer_info->page */
992 skb_put(skb, length);
993 } else {
994 skb_fill_page_desc(skb, 0,
995 buffer_info->page, 0,
996 length);
997 e1000_consume_page(buffer_info, skb,
998 length);
999 }
1000 }
1001 }
1002
1003 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1004 e1000_rx_checksum(adapter,
1005 (u32)(status) |
1006 ((u32)(rx_desc->errors) << 24),
1007 le16_to_cpu(rx_desc->csum), skb);
1008
1009 /* probably a little skewed due to removing CRC */
1010 total_rx_bytes += skb->len;
1011 total_rx_packets++;
1012
1013 /* eth type trans needs skb->data to point to something */
1014 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001015 e_err("pskb_may_pull failed.\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001016 dev_kfree_skb(skb);
1017 goto next_desc;
1018 }
1019
1020 e1000_receive_skb(adapter, netdev, skb, status,
1021 rx_desc->special);
1022
1023next_desc:
1024 rx_desc->status = 0;
1025
1026 /* return some buffers to hardware, one at a time is too slow */
1027 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1028 adapter->alloc_rx_buf(adapter, cleaned_count);
1029 cleaned_count = 0;
1030 }
1031
1032 /* use prefetched values */
1033 rx_desc = next_rxd;
1034 buffer_info = next_buffer;
1035 }
1036 rx_ring->next_to_clean = i;
1037
1038 cleaned_count = e1000_desc_unused(rx_ring);
1039 if (cleaned_count)
1040 adapter->alloc_rx_buf(adapter, cleaned_count);
1041
1042 adapter->total_rx_bytes += total_rx_bytes;
1043 adapter->total_rx_packets += total_rx_packets;
1044 adapter->net_stats.rx_bytes += total_rx_bytes;
1045 adapter->net_stats.rx_packets += total_rx_packets;
1046 return cleaned;
1047}
1048
1049/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001050 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1051 * @adapter: board private structure
1052 **/
1053static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1054{
1055 struct e1000_ring *rx_ring = adapter->rx_ring;
1056 struct e1000_buffer *buffer_info;
1057 struct e1000_ps_page *ps_page;
1058 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001059 unsigned int i, j;
1060
1061 /* Free all the Rx ring sk_buffs */
1062 for (i = 0; i < rx_ring->count; i++) {
1063 buffer_info = &rx_ring->buffer_info[i];
1064 if (buffer_info->dma) {
1065 if (adapter->clean_rx == e1000_clean_rx_irq)
1066 pci_unmap_single(pdev, buffer_info->dma,
1067 adapter->rx_buffer_len,
1068 PCI_DMA_FROMDEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001069 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1070 pci_unmap_page(pdev, buffer_info->dma,
1071 PAGE_SIZE,
1072 PCI_DMA_FROMDEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001073 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1074 pci_unmap_single(pdev, buffer_info->dma,
1075 adapter->rx_ps_bsize0,
1076 PCI_DMA_FROMDEVICE);
1077 buffer_info->dma = 0;
1078 }
1079
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001080 if (buffer_info->page) {
1081 put_page(buffer_info->page);
1082 buffer_info->page = NULL;
1083 }
1084
Auke Kokbc7f75f2007-09-17 12:30:59 -07001085 if (buffer_info->skb) {
1086 dev_kfree_skb(buffer_info->skb);
1087 buffer_info->skb = NULL;
1088 }
1089
1090 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001091 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001092 if (!ps_page->page)
1093 break;
1094 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE,
1095 PCI_DMA_FROMDEVICE);
1096 ps_page->dma = 0;
1097 put_page(ps_page->page);
1098 ps_page->page = NULL;
1099 }
1100 }
1101
1102 /* there also may be some cached data from a chained receive */
1103 if (rx_ring->rx_skb_top) {
1104 dev_kfree_skb(rx_ring->rx_skb_top);
1105 rx_ring->rx_skb_top = NULL;
1106 }
1107
Auke Kokbc7f75f2007-09-17 12:30:59 -07001108 /* Zero out the descriptor ring */
1109 memset(rx_ring->desc, 0, rx_ring->size);
1110
1111 rx_ring->next_to_clean = 0;
1112 rx_ring->next_to_use = 0;
1113
1114 writel(0, adapter->hw.hw_addr + rx_ring->head);
1115 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1116}
1117
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001118static void e1000e_downshift_workaround(struct work_struct *work)
1119{
1120 struct e1000_adapter *adapter = container_of(work,
1121 struct e1000_adapter, downshift_task);
1122
1123 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1124}
1125
Auke Kokbc7f75f2007-09-17 12:30:59 -07001126/**
1127 * e1000_intr_msi - Interrupt Handler
1128 * @irq: interrupt number
1129 * @data: pointer to a network interface device structure
1130 **/
1131static irqreturn_t e1000_intr_msi(int irq, void *data)
1132{
1133 struct net_device *netdev = data;
1134 struct e1000_adapter *adapter = netdev_priv(netdev);
1135 struct e1000_hw *hw = &adapter->hw;
1136 u32 icr = er32(ICR);
1137
Bruce Allanad680762008-03-28 09:15:03 -07001138 /*
1139 * read ICR disables interrupts using IAM
1140 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001141
1142 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
1143 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001144 /*
1145 * ICH8 workaround-- Call gig speed drop workaround on cable
1146 * disconnect (LSC) before accessing any PHY registers
1147 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001148 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1149 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001150 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001151
Bruce Allanad680762008-03-28 09:15:03 -07001152 /*
1153 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001154 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001155 * adapter in watchdog
1156 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001157 if (netif_carrier_ok(netdev) &&
1158 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1159 /* disable receives */
1160 u32 rctl = er32(RCTL);
1161 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001162 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 }
1164 /* guard against interrupt when we're going down */
1165 if (!test_bit(__E1000_DOWN, &adapter->state))
1166 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1167 }
1168
1169 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1170 adapter->total_tx_bytes = 0;
1171 adapter->total_tx_packets = 0;
1172 adapter->total_rx_bytes = 0;
1173 adapter->total_rx_packets = 0;
1174 __netif_rx_schedule(netdev, &adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001175 }
1176
1177 return IRQ_HANDLED;
1178}
1179
1180/**
1181 * e1000_intr - Interrupt Handler
1182 * @irq: interrupt number
1183 * @data: pointer to a network interface device structure
1184 **/
1185static irqreturn_t e1000_intr(int irq, void *data)
1186{
1187 struct net_device *netdev = data;
1188 struct e1000_adapter *adapter = netdev_priv(netdev);
1189 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001191
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192 if (!icr)
1193 return IRQ_NONE; /* Not our interrupt */
1194
Bruce Allanad680762008-03-28 09:15:03 -07001195 /*
1196 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1197 * not set, then the adapter didn't send an interrupt
1198 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001199 if (!(icr & E1000_ICR_INT_ASSERTED))
1200 return IRQ_NONE;
1201
Bruce Allanad680762008-03-28 09:15:03 -07001202 /*
1203 * Interrupt Auto-Mask...upon reading ICR,
1204 * interrupts are masked. No need for the
1205 * IMC write
1206 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001207
1208 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
1209 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001210 /*
1211 * ICH8 workaround-- Call gig speed drop workaround on cable
1212 * disconnect (LSC) before accessing any PHY registers
1213 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001214 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1215 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001216 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217
Bruce Allanad680762008-03-28 09:15:03 -07001218 /*
1219 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001220 * For packet buffer work-around on link down event;
1221 * disable receives here in the ISR and
1222 * reset adapter in watchdog
1223 */
1224 if (netif_carrier_ok(netdev) &&
1225 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1226 /* disable receives */
1227 rctl = er32(RCTL);
1228 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001229 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001230 }
1231 /* guard against interrupt when we're going down */
1232 if (!test_bit(__E1000_DOWN, &adapter->state))
1233 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1234 }
1235
1236 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1237 adapter->total_tx_bytes = 0;
1238 adapter->total_tx_packets = 0;
1239 adapter->total_rx_bytes = 0;
1240 adapter->total_rx_packets = 0;
1241 __netif_rx_schedule(netdev, &adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001242 }
1243
1244 return IRQ_HANDLED;
1245}
1246
Bruce Allan4662e822008-08-26 18:37:06 -07001247static irqreturn_t e1000_msix_other(int irq, void *data)
1248{
1249 struct net_device *netdev = data;
1250 struct e1000_adapter *adapter = netdev_priv(netdev);
1251 struct e1000_hw *hw = &adapter->hw;
1252 u32 icr = er32(ICR);
1253
1254 if (!(icr & E1000_ICR_INT_ASSERTED)) {
1255 ew32(IMS, E1000_IMS_OTHER);
1256 return IRQ_NONE;
1257 }
1258
1259 if (icr & adapter->eiac_mask)
1260 ew32(ICS, (icr & adapter->eiac_mask));
1261
1262 if (icr & E1000_ICR_OTHER) {
1263 if (!(icr & E1000_ICR_LSC))
1264 goto no_link_interrupt;
1265 hw->mac.get_link_status = 1;
1266 /* guard against interrupt when we're going down */
1267 if (!test_bit(__E1000_DOWN, &adapter->state))
1268 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1269 }
1270
1271no_link_interrupt:
1272 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
1273
1274 return IRQ_HANDLED;
1275}
1276
1277
1278static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1279{
1280 struct net_device *netdev = data;
1281 struct e1000_adapter *adapter = netdev_priv(netdev);
1282 struct e1000_hw *hw = &adapter->hw;
1283 struct e1000_ring *tx_ring = adapter->tx_ring;
1284
1285
1286 adapter->total_tx_bytes = 0;
1287 adapter->total_tx_packets = 0;
1288
1289 if (!e1000_clean_tx_irq(adapter))
1290 /* Ring was not completely cleaned, so fire another interrupt */
1291 ew32(ICS, tx_ring->ims_val);
1292
1293 return IRQ_HANDLED;
1294}
1295
1296static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1297{
1298 struct net_device *netdev = data;
1299 struct e1000_adapter *adapter = netdev_priv(netdev);
1300
1301 /* Write the ITR value calculated at the end of the
1302 * previous interrupt.
1303 */
1304 if (adapter->rx_ring->set_itr) {
1305 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1306 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1307 adapter->rx_ring->set_itr = 0;
1308 }
1309
1310 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1311 adapter->total_rx_bytes = 0;
1312 adapter->total_rx_packets = 0;
1313 __netif_rx_schedule(netdev, &adapter->napi);
1314 }
1315 return IRQ_HANDLED;
1316}
1317
1318/**
1319 * e1000_configure_msix - Configure MSI-X hardware
1320 *
1321 * e1000_configure_msix sets up the hardware to properly
1322 * generate MSI-X interrupts.
1323 **/
1324static void e1000_configure_msix(struct e1000_adapter *adapter)
1325{
1326 struct e1000_hw *hw = &adapter->hw;
1327 struct e1000_ring *rx_ring = adapter->rx_ring;
1328 struct e1000_ring *tx_ring = adapter->tx_ring;
1329 int vector = 0;
1330 u32 ctrl_ext, ivar = 0;
1331
1332 adapter->eiac_mask = 0;
1333
1334 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1335 if (hw->mac.type == e1000_82574) {
1336 u32 rfctl = er32(RFCTL);
1337 rfctl |= E1000_RFCTL_ACK_DIS;
1338 ew32(RFCTL, rfctl);
1339 }
1340
1341#define E1000_IVAR_INT_ALLOC_VALID 0x8
1342 /* Configure Rx vector */
1343 rx_ring->ims_val = E1000_IMS_RXQ0;
1344 adapter->eiac_mask |= rx_ring->ims_val;
1345 if (rx_ring->itr_val)
1346 writel(1000000000 / (rx_ring->itr_val * 256),
1347 hw->hw_addr + rx_ring->itr_register);
1348 else
1349 writel(1, hw->hw_addr + rx_ring->itr_register);
1350 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1351
1352 /* Configure Tx vector */
1353 tx_ring->ims_val = E1000_IMS_TXQ0;
1354 vector++;
1355 if (tx_ring->itr_val)
1356 writel(1000000000 / (tx_ring->itr_val * 256),
1357 hw->hw_addr + tx_ring->itr_register);
1358 else
1359 writel(1, hw->hw_addr + tx_ring->itr_register);
1360 adapter->eiac_mask |= tx_ring->ims_val;
1361 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1362
1363 /* set vector for Other Causes, e.g. link changes */
1364 vector++;
1365 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1366 if (rx_ring->itr_val)
1367 writel(1000000000 / (rx_ring->itr_val * 256),
1368 hw->hw_addr + E1000_EITR_82574(vector));
1369 else
1370 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1371
1372 /* Cause Tx interrupts on every write back */
1373 ivar |= (1 << 31);
1374
1375 ew32(IVAR, ivar);
1376
1377 /* enable MSI-X PBA support */
1378 ctrl_ext = er32(CTRL_EXT);
1379 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1380
1381 /* Auto-Mask Other interrupts upon ICR read */
1382#define E1000_EIAC_MASK_82574 0x01F00000
1383 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1384 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1385 ew32(CTRL_EXT, ctrl_ext);
1386 e1e_flush();
1387}
1388
1389void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1390{
1391 if (adapter->msix_entries) {
1392 pci_disable_msix(adapter->pdev);
1393 kfree(adapter->msix_entries);
1394 adapter->msix_entries = NULL;
1395 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1396 pci_disable_msi(adapter->pdev);
1397 adapter->flags &= ~FLAG_MSI_ENABLED;
1398 }
1399
1400 return;
1401}
1402
1403/**
1404 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1405 *
1406 * Attempt to configure interrupts using the best available
1407 * capabilities of the hardware and kernel.
1408 **/
1409void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1410{
1411 int err;
1412 int numvecs, i;
1413
1414
1415 switch (adapter->int_mode) {
1416 case E1000E_INT_MODE_MSIX:
1417 if (adapter->flags & FLAG_HAS_MSIX) {
1418 numvecs = 3; /* RxQ0, TxQ0 and other */
1419 adapter->msix_entries = kcalloc(numvecs,
1420 sizeof(struct msix_entry),
1421 GFP_KERNEL);
1422 if (adapter->msix_entries) {
1423 for (i = 0; i < numvecs; i++)
1424 adapter->msix_entries[i].entry = i;
1425
1426 err = pci_enable_msix(adapter->pdev,
1427 adapter->msix_entries,
1428 numvecs);
1429 if (err == 0)
1430 return;
1431 }
1432 /* MSI-X failed, so fall through and try MSI */
1433 e_err("Failed to initialize MSI-X interrupts. "
1434 "Falling back to MSI interrupts.\n");
1435 e1000e_reset_interrupt_capability(adapter);
1436 }
1437 adapter->int_mode = E1000E_INT_MODE_MSI;
1438 /* Fall through */
1439 case E1000E_INT_MODE_MSI:
1440 if (!pci_enable_msi(adapter->pdev)) {
1441 adapter->flags |= FLAG_MSI_ENABLED;
1442 } else {
1443 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1444 e_err("Failed to initialize MSI interrupts. Falling "
1445 "back to legacy interrupts.\n");
1446 }
1447 /* Fall through */
1448 case E1000E_INT_MODE_LEGACY:
1449 /* Don't do anything; this is the system default */
1450 break;
1451 }
1452
1453 return;
1454}
1455
1456/**
1457 * e1000_request_msix - Initialize MSI-X interrupts
1458 *
1459 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1460 * kernel.
1461 **/
1462static int e1000_request_msix(struct e1000_adapter *adapter)
1463{
1464 struct net_device *netdev = adapter->netdev;
1465 int err = 0, vector = 0;
1466
1467 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1468 sprintf(adapter->rx_ring->name, "%s-rx0", netdev->name);
1469 else
1470 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1471 err = request_irq(adapter->msix_entries[vector].vector,
1472 &e1000_intr_msix_rx, 0, adapter->rx_ring->name,
1473 netdev);
1474 if (err)
1475 goto out;
1476 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1477 adapter->rx_ring->itr_val = adapter->itr;
1478 vector++;
1479
1480 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1481 sprintf(adapter->tx_ring->name, "%s-tx0", netdev->name);
1482 else
1483 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1484 err = request_irq(adapter->msix_entries[vector].vector,
1485 &e1000_intr_msix_tx, 0, adapter->tx_ring->name,
1486 netdev);
1487 if (err)
1488 goto out;
1489 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1490 adapter->tx_ring->itr_val = adapter->itr;
1491 vector++;
1492
1493 err = request_irq(adapter->msix_entries[vector].vector,
1494 &e1000_msix_other, 0, netdev->name, netdev);
1495 if (err)
1496 goto out;
1497
1498 e1000_configure_msix(adapter);
1499 return 0;
1500out:
1501 return err;
1502}
1503
Bruce Allanf8d59f72008-08-08 18:36:11 -07001504/**
1505 * e1000_request_irq - initialize interrupts
1506 *
1507 * Attempts to configure interrupts using the best available
1508 * capabilities of the hardware and kernel.
1509 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001510static int e1000_request_irq(struct e1000_adapter *adapter)
1511{
1512 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001513 int err;
1514
Bruce Allan4662e822008-08-26 18:37:06 -07001515 if (adapter->msix_entries) {
1516 err = e1000_request_msix(adapter);
1517 if (!err)
1518 return err;
1519 /* fall back to MSI */
1520 e1000e_reset_interrupt_capability(adapter);
1521 adapter->int_mode = E1000E_INT_MODE_MSI;
1522 e1000e_set_interrupt_capability(adapter);
1523 }
1524 if (adapter->flags & FLAG_MSI_ENABLED) {
1525 err = request_irq(adapter->pdev->irq, &e1000_intr_msi, 0,
1526 netdev->name, netdev);
1527 if (!err)
1528 return err;
1529
1530 /* fall back to legacy interrupt */
1531 e1000e_reset_interrupt_capability(adapter);
1532 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001533 }
1534
Bruce Allan4662e822008-08-26 18:37:06 -07001535 err = request_irq(adapter->pdev->irq, &e1000_intr, IRQF_SHARED,
1536 netdev->name, netdev);
1537 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001538 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001539
1540 return err;
1541}
1542
1543static void e1000_free_irq(struct e1000_adapter *adapter)
1544{
1545 struct net_device *netdev = adapter->netdev;
1546
Bruce Allan4662e822008-08-26 18:37:06 -07001547 if (adapter->msix_entries) {
1548 int vector = 0;
1549
1550 free_irq(adapter->msix_entries[vector].vector, netdev);
1551 vector++;
1552
1553 free_irq(adapter->msix_entries[vector].vector, netdev);
1554 vector++;
1555
1556 /* Other Causes interrupt vector */
1557 free_irq(adapter->msix_entries[vector].vector, netdev);
1558 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001559 }
Bruce Allan4662e822008-08-26 18:37:06 -07001560
1561 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562}
1563
1564/**
1565 * e1000_irq_disable - Mask off interrupt generation on the NIC
1566 **/
1567static void e1000_irq_disable(struct e1000_adapter *adapter)
1568{
1569 struct e1000_hw *hw = &adapter->hw;
1570
Auke Kokbc7f75f2007-09-17 12:30:59 -07001571 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001572 if (adapter->msix_entries)
1573 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574 e1e_flush();
1575 synchronize_irq(adapter->pdev->irq);
1576}
1577
1578/**
1579 * e1000_irq_enable - Enable default interrupt generation settings
1580 **/
1581static void e1000_irq_enable(struct e1000_adapter *adapter)
1582{
1583 struct e1000_hw *hw = &adapter->hw;
1584
Bruce Allan4662e822008-08-26 18:37:06 -07001585 if (adapter->msix_entries) {
1586 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1587 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1588 } else {
1589 ew32(IMS, IMS_ENABLE_MASK);
1590 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001591 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592}
1593
1594/**
1595 * e1000_get_hw_control - get control of the h/w from f/w
1596 * @adapter: address of board private structure
1597 *
Auke Kok489815c2008-02-21 15:11:07 -08001598 * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001599 * For ASF and Pass Through versions of f/w this means that
1600 * the driver is loaded. For AMT version (only with 82573)
1601 * of the f/w this means that the network i/f is open.
1602 **/
1603static void e1000_get_hw_control(struct e1000_adapter *adapter)
1604{
1605 struct e1000_hw *hw = &adapter->hw;
1606 u32 ctrl_ext;
1607 u32 swsm;
1608
1609 /* Let firmware know the driver has taken over */
1610 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1611 swsm = er32(SWSM);
1612 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1613 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1614 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07001615 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616 }
1617}
1618
1619/**
1620 * e1000_release_hw_control - release control of the h/w to f/w
1621 * @adapter: address of board private structure
1622 *
Auke Kok489815c2008-02-21 15:11:07 -08001623 * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001624 * For ASF and Pass Through versions of f/w this means that the
1625 * driver is no longer loaded. For AMT version (only with 82573) i
1626 * of the f/w this means that the network i/f is closed.
1627 *
1628 **/
1629static void e1000_release_hw_control(struct e1000_adapter *adapter)
1630{
1631 struct e1000_hw *hw = &adapter->hw;
1632 u32 ctrl_ext;
1633 u32 swsm;
1634
1635 /* Let firmware taken over control of h/w */
1636 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1637 swsm = er32(SWSM);
1638 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1639 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1640 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07001641 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001642 }
1643}
1644
Auke Kokbc7f75f2007-09-17 12:30:59 -07001645/**
1646 * @e1000_alloc_ring - allocate memory for a ring structure
1647 **/
1648static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
1649 struct e1000_ring *ring)
1650{
1651 struct pci_dev *pdev = adapter->pdev;
1652
1653 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
1654 GFP_KERNEL);
1655 if (!ring->desc)
1656 return -ENOMEM;
1657
1658 return 0;
1659}
1660
1661/**
1662 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
1663 * @adapter: board private structure
1664 *
1665 * Return 0 on success, negative on failure
1666 **/
1667int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
1668{
1669 struct e1000_ring *tx_ring = adapter->tx_ring;
1670 int err = -ENOMEM, size;
1671
1672 size = sizeof(struct e1000_buffer) * tx_ring->count;
1673 tx_ring->buffer_info = vmalloc(size);
1674 if (!tx_ring->buffer_info)
1675 goto err;
1676 memset(tx_ring->buffer_info, 0, size);
1677
1678 /* round up to nearest 4K */
1679 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1680 tx_ring->size = ALIGN(tx_ring->size, 4096);
1681
1682 err = e1000_alloc_ring_dma(adapter, tx_ring);
1683 if (err)
1684 goto err;
1685
1686 tx_ring->next_to_use = 0;
1687 tx_ring->next_to_clean = 0;
1688 spin_lock_init(&adapter->tx_queue_lock);
1689
1690 return 0;
1691err:
1692 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001693 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001694 return err;
1695}
1696
1697/**
1698 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
1699 * @adapter: board private structure
1700 *
1701 * Returns 0 on success, negative on failure
1702 **/
1703int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
1704{
1705 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07001706 struct e1000_buffer *buffer_info;
1707 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708
1709 size = sizeof(struct e1000_buffer) * rx_ring->count;
1710 rx_ring->buffer_info = vmalloc(size);
1711 if (!rx_ring->buffer_info)
1712 goto err;
1713 memset(rx_ring->buffer_info, 0, size);
1714
Auke Kok47f44e42007-10-25 13:57:44 -07001715 for (i = 0; i < rx_ring->count; i++) {
1716 buffer_info = &rx_ring->buffer_info[i];
1717 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
1718 sizeof(struct e1000_ps_page),
1719 GFP_KERNEL);
1720 if (!buffer_info->ps_pages)
1721 goto err_pages;
1722 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001723
1724 desc_len = sizeof(union e1000_rx_desc_packet_split);
1725
1726 /* Round up to nearest 4K */
1727 rx_ring->size = rx_ring->count * desc_len;
1728 rx_ring->size = ALIGN(rx_ring->size, 4096);
1729
1730 err = e1000_alloc_ring_dma(adapter, rx_ring);
1731 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07001732 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001733
1734 rx_ring->next_to_clean = 0;
1735 rx_ring->next_to_use = 0;
1736 rx_ring->rx_skb_top = NULL;
1737
1738 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07001739
1740err_pages:
1741 for (i = 0; i < rx_ring->count; i++) {
1742 buffer_info = &rx_ring->buffer_info[i];
1743 kfree(buffer_info->ps_pages);
1744 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001745err:
1746 vfree(rx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001747 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001748 return err;
1749}
1750
1751/**
1752 * e1000_clean_tx_ring - Free Tx Buffers
1753 * @adapter: board private structure
1754 **/
1755static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
1756{
1757 struct e1000_ring *tx_ring = adapter->tx_ring;
1758 struct e1000_buffer *buffer_info;
1759 unsigned long size;
1760 unsigned int i;
1761
1762 for (i = 0; i < tx_ring->count; i++) {
1763 buffer_info = &tx_ring->buffer_info[i];
1764 e1000_put_txbuf(adapter, buffer_info);
1765 }
1766
1767 size = sizeof(struct e1000_buffer) * tx_ring->count;
1768 memset(tx_ring->buffer_info, 0, size);
1769
1770 memset(tx_ring->desc, 0, tx_ring->size);
1771
1772 tx_ring->next_to_use = 0;
1773 tx_ring->next_to_clean = 0;
1774
1775 writel(0, adapter->hw.hw_addr + tx_ring->head);
1776 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1777}
1778
1779/**
1780 * e1000e_free_tx_resources - Free Tx Resources per Queue
1781 * @adapter: board private structure
1782 *
1783 * Free all transmit software resources
1784 **/
1785void e1000e_free_tx_resources(struct e1000_adapter *adapter)
1786{
1787 struct pci_dev *pdev = adapter->pdev;
1788 struct e1000_ring *tx_ring = adapter->tx_ring;
1789
1790 e1000_clean_tx_ring(adapter);
1791
1792 vfree(tx_ring->buffer_info);
1793 tx_ring->buffer_info = NULL;
1794
1795 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1796 tx_ring->dma);
1797 tx_ring->desc = NULL;
1798}
1799
1800/**
1801 * e1000e_free_rx_resources - Free Rx Resources
1802 * @adapter: board private structure
1803 *
1804 * Free all receive software resources
1805 **/
1806
1807void e1000e_free_rx_resources(struct e1000_adapter *adapter)
1808{
1809 struct pci_dev *pdev = adapter->pdev;
1810 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07001811 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001812
1813 e1000_clean_rx_ring(adapter);
1814
Auke Kok47f44e42007-10-25 13:57:44 -07001815 for (i = 0; i < rx_ring->count; i++) {
1816 kfree(rx_ring->buffer_info[i].ps_pages);
1817 }
1818
Auke Kokbc7f75f2007-09-17 12:30:59 -07001819 vfree(rx_ring->buffer_info);
1820 rx_ring->buffer_info = NULL;
1821
Auke Kokbc7f75f2007-09-17 12:30:59 -07001822 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1823 rx_ring->dma);
1824 rx_ring->desc = NULL;
1825}
1826
1827/**
1828 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08001829 * @adapter: pointer to adapter
1830 * @itr_setting: current adapter->itr
1831 * @packets: the number of packets during this measurement interval
1832 * @bytes: the number of bytes during this measurement interval
1833 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834 * Stores a new ITR value based on packets and byte
1835 * counts during the last interrupt. The advantage of per interrupt
1836 * computation is faster updates and more accurate ITR for the current
1837 * traffic pattern. Constants in this function were computed
1838 * based on theoretical maximum wire speed and thresholds were set based
1839 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07001840 * while increasing bulk throughput. This functionality is controlled
1841 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001842 **/
1843static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
1844 u16 itr_setting, int packets,
1845 int bytes)
1846{
1847 unsigned int retval = itr_setting;
1848
1849 if (packets == 0)
1850 goto update_itr_done;
1851
1852 switch (itr_setting) {
1853 case lowest_latency:
1854 /* handle TSO and jumbo frames */
1855 if (bytes/packets > 8000)
1856 retval = bulk_latency;
1857 else if ((packets < 5) && (bytes > 512)) {
1858 retval = low_latency;
1859 }
1860 break;
1861 case low_latency: /* 50 usec aka 20000 ints/s */
1862 if (bytes > 10000) {
1863 /* this if handles the TSO accounting */
1864 if (bytes/packets > 8000) {
1865 retval = bulk_latency;
1866 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
1867 retval = bulk_latency;
1868 } else if ((packets > 35)) {
1869 retval = lowest_latency;
1870 }
1871 } else if (bytes/packets > 2000) {
1872 retval = bulk_latency;
1873 } else if (packets <= 2 && bytes < 512) {
1874 retval = lowest_latency;
1875 }
1876 break;
1877 case bulk_latency: /* 250 usec aka 4000 ints/s */
1878 if (bytes > 25000) {
1879 if (packets > 35) {
1880 retval = low_latency;
1881 }
1882 } else if (bytes < 6000) {
1883 retval = low_latency;
1884 }
1885 break;
1886 }
1887
1888update_itr_done:
1889 return retval;
1890}
1891
1892static void e1000_set_itr(struct e1000_adapter *adapter)
1893{
1894 struct e1000_hw *hw = &adapter->hw;
1895 u16 current_itr;
1896 u32 new_itr = adapter->itr;
1897
1898 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
1899 if (adapter->link_speed != SPEED_1000) {
1900 current_itr = 0;
1901 new_itr = 4000;
1902 goto set_itr_now;
1903 }
1904
1905 adapter->tx_itr = e1000_update_itr(adapter,
1906 adapter->tx_itr,
1907 adapter->total_tx_packets,
1908 adapter->total_tx_bytes);
1909 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1910 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
1911 adapter->tx_itr = low_latency;
1912
1913 adapter->rx_itr = e1000_update_itr(adapter,
1914 adapter->rx_itr,
1915 adapter->total_rx_packets,
1916 adapter->total_rx_bytes);
1917 /* conservative mode (itr 3) eliminates the lowest_latency setting */
1918 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
1919 adapter->rx_itr = low_latency;
1920
1921 current_itr = max(adapter->rx_itr, adapter->tx_itr);
1922
1923 switch (current_itr) {
1924 /* counts and packets in update_itr are dependent on these numbers */
1925 case lowest_latency:
1926 new_itr = 70000;
1927 break;
1928 case low_latency:
1929 new_itr = 20000; /* aka hwitr = ~200 */
1930 break;
1931 case bulk_latency:
1932 new_itr = 4000;
1933 break;
1934 default:
1935 break;
1936 }
1937
1938set_itr_now:
1939 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07001940 /*
1941 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07001942 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07001943 * increasing
1944 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001945 new_itr = new_itr > adapter->itr ?
1946 min(adapter->itr + (new_itr >> 2), new_itr) :
1947 new_itr;
1948 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07001949 adapter->rx_ring->itr_val = new_itr;
1950 if (adapter->msix_entries)
1951 adapter->rx_ring->set_itr = 1;
1952 else
1953 ew32(ITR, 1000000000 / (new_itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001954 }
1955}
1956
1957/**
Bruce Allan4662e822008-08-26 18:37:06 -07001958 * e1000_alloc_queues - Allocate memory for all rings
1959 * @adapter: board private structure to initialize
1960 **/
1961static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1962{
1963 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1964 if (!adapter->tx_ring)
1965 goto err;
1966
1967 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
1968 if (!adapter->rx_ring)
1969 goto err;
1970
1971 return 0;
1972err:
1973 e_err("Unable to allocate memory for queues\n");
1974 kfree(adapter->rx_ring);
1975 kfree(adapter->tx_ring);
1976 return -ENOMEM;
1977}
1978
1979/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001980 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07001981 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08001982 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07001983 **/
1984static int e1000_clean(struct napi_struct *napi, int budget)
1985{
1986 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001987 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001988 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08001989 int tx_cleaned = 0, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001990
Wang Chen4cf16532008-11-12 23:38:14 -08001991 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001992
Bruce Allan4662e822008-08-26 18:37:06 -07001993 if (adapter->msix_entries &&
1994 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
1995 goto clean_rx;
1996
Bruce Allanad680762008-03-28 09:15:03 -07001997 /*
1998 * e1000_clean is called per-cpu. This lock protects
Auke Kokbc7f75f2007-09-17 12:30:59 -07001999 * tx_ring from being cleaned by multiple cpus
2000 * simultaneously. A failure obtaining the lock means
Bruce Allanad680762008-03-28 09:15:03 -07002001 * tx_ring is currently being cleaned anyway.
2002 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002003 if (spin_trylock(&adapter->tx_queue_lock)) {
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002004 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002005 spin_unlock(&adapter->tx_queue_lock);
2006 }
2007
Bruce Allan4662e822008-08-26 18:37:06 -07002008clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002009 adapter->clean_rx(adapter, &work_done, budget);
2010
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002011 if (tx_cleaned)
2012 work_done = budget;
2013
David S. Miller53e52c72008-01-07 21:06:12 -08002014 /* If budget not fully consumed, exit the polling mode */
2015 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002016 if (adapter->itr_setting & 3)
2017 e1000_set_itr(adapter);
2018 netif_rx_complete(poll_dev, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002019 if (adapter->msix_entries)
2020 ew32(IMS, adapter->rx_ring->ims_val);
2021 else
2022 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002023 }
2024
2025 return work_done;
2026}
2027
2028static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2029{
2030 struct e1000_adapter *adapter = netdev_priv(netdev);
2031 struct e1000_hw *hw = &adapter->hw;
2032 u32 vfta, index;
2033
2034 /* don't update vlan cookie if already programmed */
2035 if ((adapter->hw.mng_cookie.status &
2036 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2037 (vid == adapter->mng_vlan_id))
2038 return;
2039 /* add VID to filter table */
2040 index = (vid >> 5) & 0x7F;
2041 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2042 vfta |= (1 << (vid & 0x1F));
2043 e1000e_write_vfta(hw, index, vfta);
2044}
2045
2046static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2047{
2048 struct e1000_adapter *adapter = netdev_priv(netdev);
2049 struct e1000_hw *hw = &adapter->hw;
2050 u32 vfta, index;
2051
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002052 if (!test_bit(__E1000_DOWN, &adapter->state))
2053 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002054 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002055
2056 if (!test_bit(__E1000_DOWN, &adapter->state))
2057 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002058
2059 if ((adapter->hw.mng_cookie.status &
2060 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2061 (vid == adapter->mng_vlan_id)) {
2062 /* release control to f/w */
2063 e1000_release_hw_control(adapter);
2064 return;
2065 }
2066
2067 /* remove VID from filter table */
2068 index = (vid >> 5) & 0x7F;
2069 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2070 vfta &= ~(1 << (vid & 0x1F));
2071 e1000e_write_vfta(hw, index, vfta);
2072}
2073
2074static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2075{
2076 struct net_device *netdev = adapter->netdev;
2077 u16 vid = adapter->hw.mng_cookie.vlan_id;
2078 u16 old_vid = adapter->mng_vlan_id;
2079
2080 if (!adapter->vlgrp)
2081 return;
2082
2083 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2084 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2085 if (adapter->hw.mng_cookie.status &
2086 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2087 e1000_vlan_rx_add_vid(netdev, vid);
2088 adapter->mng_vlan_id = vid;
2089 }
2090
2091 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2092 (vid != old_vid) &&
2093 !vlan_group_get_device(adapter->vlgrp, old_vid))
2094 e1000_vlan_rx_kill_vid(netdev, old_vid);
2095 } else {
2096 adapter->mng_vlan_id = vid;
2097 }
2098}
2099
2100
2101static void e1000_vlan_rx_register(struct net_device *netdev,
2102 struct vlan_group *grp)
2103{
2104 struct e1000_adapter *adapter = netdev_priv(netdev);
2105 struct e1000_hw *hw = &adapter->hw;
2106 u32 ctrl, rctl;
2107
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002108 if (!test_bit(__E1000_DOWN, &adapter->state))
2109 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002110 adapter->vlgrp = grp;
2111
2112 if (grp) {
2113 /* enable VLAN tag insert/strip */
2114 ctrl = er32(CTRL);
2115 ctrl |= E1000_CTRL_VME;
2116 ew32(CTRL, ctrl);
2117
2118 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2119 /* enable VLAN receive filtering */
2120 rctl = er32(RCTL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002121 rctl &= ~E1000_RCTL_CFIEN;
2122 ew32(RCTL, rctl);
2123 e1000_update_mng_vlan(adapter);
2124 }
2125 } else {
2126 /* disable VLAN tag insert/strip */
2127 ctrl = er32(CTRL);
2128 ctrl &= ~E1000_CTRL_VME;
2129 ew32(CTRL, ctrl);
2130
2131 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002132 if (adapter->mng_vlan_id !=
2133 (u16)E1000_MNG_VLAN_NONE) {
2134 e1000_vlan_rx_kill_vid(netdev,
2135 adapter->mng_vlan_id);
2136 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2137 }
2138 }
2139 }
2140
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002141 if (!test_bit(__E1000_DOWN, &adapter->state))
2142 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002143}
2144
2145static void e1000_restore_vlan(struct e1000_adapter *adapter)
2146{
2147 u16 vid;
2148
2149 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2150
2151 if (!adapter->vlgrp)
2152 return;
2153
2154 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2155 if (!vlan_group_get_device(adapter->vlgrp, vid))
2156 continue;
2157 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2158 }
2159}
2160
2161static void e1000_init_manageability(struct e1000_adapter *adapter)
2162{
2163 struct e1000_hw *hw = &adapter->hw;
2164 u32 manc, manc2h;
2165
2166 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2167 return;
2168
2169 manc = er32(MANC);
2170
Bruce Allanad680762008-03-28 09:15:03 -07002171 /*
2172 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002173 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002174 * the packets will be handled on SMBUS
2175 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002176 manc |= E1000_MANC_EN_MNG2HOST;
2177 manc2h = er32(MANC2H);
2178#define E1000_MNG2HOST_PORT_623 (1 << 5)
2179#define E1000_MNG2HOST_PORT_664 (1 << 6)
2180 manc2h |= E1000_MNG2HOST_PORT_623;
2181 manc2h |= E1000_MNG2HOST_PORT_664;
2182 ew32(MANC2H, manc2h);
2183 ew32(MANC, manc);
2184}
2185
2186/**
2187 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2188 * @adapter: board private structure
2189 *
2190 * Configure the Tx unit of the MAC after a reset.
2191 **/
2192static void e1000_configure_tx(struct e1000_adapter *adapter)
2193{
2194 struct e1000_hw *hw = &adapter->hw;
2195 struct e1000_ring *tx_ring = adapter->tx_ring;
2196 u64 tdba;
2197 u32 tdlen, tctl, tipg, tarc;
2198 u32 ipgr1, ipgr2;
2199
2200 /* Setup the HW Tx Head and Tail descriptor pointers */
2201 tdba = tx_ring->dma;
2202 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2203 ew32(TDBAL, (tdba & DMA_32BIT_MASK));
2204 ew32(TDBAH, (tdba >> 32));
2205 ew32(TDLEN, tdlen);
2206 ew32(TDH, 0);
2207 ew32(TDT, 0);
2208 tx_ring->head = E1000_TDH;
2209 tx_ring->tail = E1000_TDT;
2210
2211 /* Set the default values for the Tx Inter Packet Gap timer */
2212 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2213 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2214 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2215
2216 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2217 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2218
2219 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2220 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2221 ew32(TIPG, tipg);
2222
2223 /* Set the Tx Interrupt Delay register */
2224 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002225 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002226 ew32(TADV, adapter->tx_abs_int_delay);
2227
2228 /* Program the Transmit Control Register */
2229 tctl = er32(TCTL);
2230 tctl &= ~E1000_TCTL_CT;
2231 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2232 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2233
2234 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002235 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002236 /*
2237 * set the speed mode bit, we'll clear it if we're not at
2238 * gigabit link later
2239 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002240#define SPEED_MODE_BIT (1 << 21)
2241 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002242 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002243 }
2244
2245 /* errata: program both queues to unweighted RR */
2246 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002247 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002248 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002249 ew32(TARC(0), tarc);
2250 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002252 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253 }
2254
2255 e1000e_config_collision_dist(hw);
2256
2257 /* Setup Transmit Descriptor Settings for eop descriptor */
2258 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2259
2260 /* only set IDE if we are delaying interrupts using the timers */
2261 if (adapter->tx_int_delay)
2262 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2263
2264 /* enable Report Status bit */
2265 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2266
2267 ew32(TCTL, tctl);
2268
2269 adapter->tx_queue_len = adapter->netdev->tx_queue_len;
2270}
2271
2272/**
2273 * e1000_setup_rctl - configure the receive control registers
2274 * @adapter: Board private structure
2275 **/
2276#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2277 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2278static void e1000_setup_rctl(struct e1000_adapter *adapter)
2279{
2280 struct e1000_hw *hw = &adapter->hw;
2281 u32 rctl, rfctl;
2282 u32 psrctl = 0;
2283 u32 pages = 0;
2284
2285 /* Program MC offset vector base */
2286 rctl = er32(RCTL);
2287 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2288 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2289 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2290 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2291
2292 /* Do not Store bad packets */
2293 rctl &= ~E1000_RCTL_SBP;
2294
2295 /* Enable Long Packet receive */
2296 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2297 rctl &= ~E1000_RCTL_LPE;
2298 else
2299 rctl |= E1000_RCTL_LPE;
2300
Auke Kok5918bd82008-02-12 15:20:24 -08002301 /* Enable hardware CRC frame stripping */
2302 rctl |= E1000_RCTL_SECRC;
2303
Auke Kokbc7f75f2007-09-17 12:30:59 -07002304 /* Setup buffer sizes */
2305 rctl &= ~E1000_RCTL_SZ_4096;
2306 rctl |= E1000_RCTL_BSEX;
2307 switch (adapter->rx_buffer_len) {
2308 case 256:
2309 rctl |= E1000_RCTL_SZ_256;
2310 rctl &= ~E1000_RCTL_BSEX;
2311 break;
2312 case 512:
2313 rctl |= E1000_RCTL_SZ_512;
2314 rctl &= ~E1000_RCTL_BSEX;
2315 break;
2316 case 1024:
2317 rctl |= E1000_RCTL_SZ_1024;
2318 rctl &= ~E1000_RCTL_BSEX;
2319 break;
2320 case 2048:
2321 default:
2322 rctl |= E1000_RCTL_SZ_2048;
2323 rctl &= ~E1000_RCTL_BSEX;
2324 break;
2325 case 4096:
2326 rctl |= E1000_RCTL_SZ_4096;
2327 break;
2328 case 8192:
2329 rctl |= E1000_RCTL_SZ_8192;
2330 break;
2331 case 16384:
2332 rctl |= E1000_RCTL_SZ_16384;
2333 break;
2334 }
2335
2336 /*
2337 * 82571 and greater support packet-split where the protocol
2338 * header is placed in skb->data and the packet data is
2339 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2340 * In the case of a non-split, skb->data is linearly filled,
2341 * followed by the page buffers. Therefore, skb->data is
2342 * sized to hold the largest protocol header.
2343 *
2344 * allocations using alloc_page take too long for regular MTU
2345 * so only enable packet split for jumbo frames
2346 *
2347 * Using pages when the page size is greater than 16k wastes
2348 * a lot of memory, since we allocate 3 pages at all times
2349 * per packet.
2350 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002351 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002352 if (!(adapter->flags & FLAG_IS_ICH) && (pages <= 3) &&
2353 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002354 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002355 else
2356 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002357
2358 if (adapter->rx_ps_pages) {
2359 /* Configure extra packet-split registers */
2360 rfctl = er32(RFCTL);
2361 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002362 /*
2363 * disable packet split support for IPv6 extension headers,
2364 * because some malformed IPv6 headers can hang the Rx
2365 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2367 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2368
2369 ew32(RFCTL, rfctl);
2370
Auke Kok140a7482007-10-25 13:57:58 -07002371 /* Enable Packet split descriptors */
2372 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373
2374 psrctl |= adapter->rx_ps_bsize0 >>
2375 E1000_PSRCTL_BSIZE0_SHIFT;
2376
2377 switch (adapter->rx_ps_pages) {
2378 case 3:
2379 psrctl |= PAGE_SIZE <<
2380 E1000_PSRCTL_BSIZE3_SHIFT;
2381 case 2:
2382 psrctl |= PAGE_SIZE <<
2383 E1000_PSRCTL_BSIZE2_SHIFT;
2384 case 1:
2385 psrctl |= PAGE_SIZE >>
2386 E1000_PSRCTL_BSIZE1_SHIFT;
2387 break;
2388 }
2389
2390 ew32(PSRCTL, psrctl);
2391 }
2392
2393 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002394 /* just started the receive unit, no need to restart */
2395 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002396}
2397
2398/**
2399 * e1000_configure_rx - Configure Receive Unit after Reset
2400 * @adapter: board private structure
2401 *
2402 * Configure the Rx unit of the MAC after a reset.
2403 **/
2404static void e1000_configure_rx(struct e1000_adapter *adapter)
2405{
2406 struct e1000_hw *hw = &adapter->hw;
2407 struct e1000_ring *rx_ring = adapter->rx_ring;
2408 u64 rdba;
2409 u32 rdlen, rctl, rxcsum, ctrl_ext;
2410
2411 if (adapter->rx_ps_pages) {
2412 /* this is a 32 byte descriptor */
2413 rdlen = rx_ring->count *
2414 sizeof(union e1000_rx_desc_packet_split);
2415 adapter->clean_rx = e1000_clean_rx_irq_ps;
2416 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002417 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2418 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2419 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2420 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002421 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002422 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002423 adapter->clean_rx = e1000_clean_rx_irq;
2424 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2425 }
2426
2427 /* disable receives while setting up the descriptors */
2428 rctl = er32(RCTL);
2429 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2430 e1e_flush();
2431 msleep(10);
2432
2433 /* set the Receive Delay Timer Register */
2434 ew32(RDTR, adapter->rx_int_delay);
2435
2436 /* irq moderation */
2437 ew32(RADV, adapter->rx_abs_int_delay);
2438 if (adapter->itr_setting != 0)
Bruce Allanad680762008-03-28 09:15:03 -07002439 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440
2441 ctrl_ext = er32(CTRL_EXT);
2442 /* Reset delay timers after every interrupt */
2443 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
2444 /* Auto-Mask interrupts upon ICR access */
2445 ctrl_ext |= E1000_CTRL_EXT_IAME;
2446 ew32(IAM, 0xffffffff);
2447 ew32(CTRL_EXT, ctrl_ext);
2448 e1e_flush();
2449
Bruce Allanad680762008-03-28 09:15:03 -07002450 /*
2451 * Setup the HW Rx Head and Tail Descriptor Pointers and
2452 * the Base and Length of the Rx Descriptor Ring
2453 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 rdba = rx_ring->dma;
2455 ew32(RDBAL, (rdba & DMA_32BIT_MASK));
2456 ew32(RDBAH, (rdba >> 32));
2457 ew32(RDLEN, rdlen);
2458 ew32(RDH, 0);
2459 ew32(RDT, 0);
2460 rx_ring->head = E1000_RDH;
2461 rx_ring->tail = E1000_RDT;
2462
2463 /* Enable Receive Checksum Offload for TCP and UDP */
2464 rxcsum = er32(RXCSUM);
2465 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2466 rxcsum |= E1000_RXCSUM_TUOFL;
2467
Bruce Allanad680762008-03-28 09:15:03 -07002468 /*
2469 * IPv4 payload checksum for UDP fragments must be
2470 * used in conjunction with packet-split.
2471 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002472 if (adapter->rx_ps_pages)
2473 rxcsum |= E1000_RXCSUM_IPPCSE;
2474 } else {
2475 rxcsum &= ~E1000_RXCSUM_TUOFL;
2476 /* no need to clear IPPCSE as it defaults to 0 */
2477 }
2478 ew32(RXCSUM, rxcsum);
2479
Bruce Allanad680762008-03-28 09:15:03 -07002480 /*
2481 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002482 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002483 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2484 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002485 if ((adapter->flags & FLAG_HAS_ERT) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002486 (adapter->netdev->mtu > ETH_DATA_LEN)) {
2487 u32 rxdctl = er32(RXDCTL(0));
2488 ew32(RXDCTL(0), rxdctl | 0x3);
2489 ew32(ERT, E1000_ERT_2048 | (1 << 13));
2490 /*
2491 * With jumbo frames and early-receive enabled, excessive
2492 * C4->C2 latencies result in dropped transactions.
2493 */
2494 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2495 e1000e_driver_name, 55);
2496 } else {
2497 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
2498 e1000e_driver_name,
2499 PM_QOS_DEFAULT_VALUE);
2500 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002501
2502 /* Enable Receives */
2503 ew32(RCTL, rctl);
2504}
2505
2506/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002507 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07002508 * @hw: pointer to the HW structure
2509 * @mc_addr_list: array of multicast addresses to program
2510 * @mc_addr_count: number of multicast addresses to program
2511 * @rar_used_count: the first RAR register free to program
2512 * @rar_count: total number of supported Receive Address Registers
2513 *
2514 * Updates the Receive Address Registers and Multicast Table Array.
2515 * The caller must have a packed mc_addr_list of multicast addresses.
2516 * The parameter rar_count will usually be hw->mac.rar_entry_count
2517 * unless there are workarounds that change this. Currently no func pointer
2518 * exists and all implementations are handled in the generic version of this
2519 * function.
2520 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002521static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
2522 u32 mc_addr_count, u32 rar_used_count,
2523 u32 rar_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002524{
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002525 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526 rar_used_count, rar_count);
2527}
2528
2529/**
2530 * e1000_set_multi - Multicast and Promiscuous mode set
2531 * @netdev: network interface device structure
2532 *
2533 * The set_multi entry point is called whenever the multicast address
2534 * list or the network interface flags are updated. This routine is
2535 * responsible for configuring the hardware for proper multicast,
2536 * promiscuous mode, and all-multi behavior.
2537 **/
2538static void e1000_set_multi(struct net_device *netdev)
2539{
2540 struct e1000_adapter *adapter = netdev_priv(netdev);
2541 struct e1000_hw *hw = &adapter->hw;
2542 struct e1000_mac_info *mac = &hw->mac;
2543 struct dev_mc_list *mc_ptr;
2544 u8 *mta_list;
2545 u32 rctl;
2546 int i;
2547
2548 /* Check for Promiscuous and All Multicast modes */
2549
2550 rctl = er32(RCTL);
2551
2552 if (netdev->flags & IFF_PROMISC) {
2553 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002554 rctl &= ~E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002555 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002556 if (netdev->flags & IFF_ALLMULTI) {
2557 rctl |= E1000_RCTL_MPE;
2558 rctl &= ~E1000_RCTL_UPE;
2559 } else {
2560 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2561 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002562 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002563 rctl |= E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002564 }
2565
2566 ew32(RCTL, rctl);
2567
2568 if (netdev->mc_count) {
2569 mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);
2570 if (!mta_list)
2571 return;
2572
2573 /* prepare a packed array of only addresses. */
2574 mc_ptr = netdev->mc_list;
2575
2576 for (i = 0; i < netdev->mc_count; i++) {
2577 if (!mc_ptr)
2578 break;
2579 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
2580 ETH_ALEN);
2581 mc_ptr = mc_ptr->next;
2582 }
2583
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002584 e1000_update_mc_addr_list(hw, mta_list, i, 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002585 mac->rar_entry_count);
2586 kfree(mta_list);
2587 } else {
2588 /*
2589 * if we're called from probe, we might not have
2590 * anything to do here, so clear out the list
2591 */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002592 e1000_update_mc_addr_list(hw, NULL, 0, 1, mac->rar_entry_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002593 }
2594}
2595
2596/**
Bruce Allanad680762008-03-28 09:15:03 -07002597 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07002598 * @adapter: private board structure
2599 **/
2600static void e1000_configure(struct e1000_adapter *adapter)
2601{
2602 e1000_set_multi(adapter->netdev);
2603
2604 e1000_restore_vlan(adapter);
2605 e1000_init_manageability(adapter);
2606
2607 e1000_configure_tx(adapter);
2608 e1000_setup_rctl(adapter);
2609 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07002610 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611}
2612
2613/**
2614 * e1000e_power_up_phy - restore link in case the phy was powered down
2615 * @adapter: address of board private structure
2616 *
2617 * The phy may be powered down to save power and turn off link when the
2618 * driver is unloaded and wake on lan is not enabled (among others)
2619 * *** this routine MUST be followed by a call to e1000e_reset ***
2620 **/
2621void e1000e_power_up_phy(struct e1000_adapter *adapter)
2622{
2623 u16 mii_reg = 0;
2624
2625 /* Just clear the power down bit to wake the phy back up */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002626 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Bruce Allanad680762008-03-28 09:15:03 -07002627 /*
2628 * According to the manual, the phy will retain its
2629 * settings across a power-down/up cycle
2630 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002631 e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);
2632 mii_reg &= ~MII_CR_POWER_DOWN;
2633 e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);
2634 }
2635
2636 adapter->hw.mac.ops.setup_link(&adapter->hw);
2637}
2638
2639/**
2640 * e1000_power_down_phy - Power down the PHY
2641 *
2642 * Power down the PHY so no link is implied when interface is down
2643 * The PHY cannot be powered down is management or WoL is active
2644 */
2645static void e1000_power_down_phy(struct e1000_adapter *adapter)
2646{
2647 struct e1000_hw *hw = &adapter->hw;
2648 u16 mii_reg;
2649
2650 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08002651 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002652 return;
2653
2654 /* non-copper PHY? */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002655 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002656 return;
2657
2658 /* reset is blocked because of a SoL/IDER session */
Bruce Allanad680762008-03-28 09:15:03 -07002659 if (e1000e_check_mng_mode(hw) || e1000_check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002660 return;
2661
Auke Kok489815c2008-02-21 15:11:07 -08002662 /* manageability (AMT) is enabled */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663 if (er32(MANC) & E1000_MANC_SMBUS_EN)
2664 return;
2665
2666 /* power down the PHY */
2667 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2668 mii_reg |= MII_CR_POWER_DOWN;
2669 e1e_wphy(hw, PHY_CONTROL, mii_reg);
2670 mdelay(1);
2671}
2672
2673/**
2674 * e1000e_reset - bring the hardware into a known good state
2675 *
2676 * This function boots the hardware and enables some settings that
2677 * require a configuration cycle of the hardware - those cannot be
2678 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07002679 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002680 */
2681void e1000e_reset(struct e1000_adapter *adapter)
2682{
2683 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002684 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002685 struct e1000_hw *hw = &adapter->hw;
2686 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002687 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002688 u16 hwm;
2689
Bruce Allanad680762008-03-28 09:15:03 -07002690 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002691 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07002692
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002693 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07002694 /*
2695 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07002696 * large enough to accommodate two full transmit packets,
2697 * rounded up to the next 1KB and expressed in KB. Likewise,
2698 * the Rx FIFO should be large enough to accommodate at least
2699 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07002700 * expressed in KB.
2701 */
Auke Kokdf762462007-10-25 13:57:53 -07002702 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002703 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07002704 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07002706 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07002707 /*
2708 * the Tx fifo also stores 16 bytes of information about the tx
2709 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002710 */
2711 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07002712 sizeof(struct e1000_tx_desc) -
2713 ETH_FCS_LEN) * 2;
2714 min_tx_space = ALIGN(min_tx_space, 1024);
2715 min_tx_space >>= 10;
2716 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002717 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002718 min_rx_space = ALIGN(min_rx_space, 1024);
2719 min_rx_space >>= 10;
2720
Bruce Allanad680762008-03-28 09:15:03 -07002721 /*
2722 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002723 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07002724 * allocation, take space away from current Rx allocation
2725 */
Auke Kokdf762462007-10-25 13:57:53 -07002726 if ((tx_space < min_tx_space) &&
2727 ((min_tx_space - tx_space) < pba)) {
2728 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002729
Bruce Allanad680762008-03-28 09:15:03 -07002730 /*
2731 * if short on Rx space, Rx wins and must trump tx
2732 * adjustment or use Early Receive if available
2733 */
Auke Kokdf762462007-10-25 13:57:53 -07002734 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07002735 (!(adapter->flags & FLAG_HAS_ERT)))
2736 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07002737 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002738 }
Auke Kokdf762462007-10-25 13:57:53 -07002739
2740 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002741 }
2742
Auke Kokbc7f75f2007-09-17 12:30:59 -07002743
Bruce Allanad680762008-03-28 09:15:03 -07002744 /*
2745 * flow control settings
2746 *
2747 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07002748 * (or the size used for early receive) above it in the Rx FIFO.
2749 * Set it to the lower of:
2750 * - 90% of the Rx FIFO size, and
2751 * - the full Rx FIFO size minus the early receive size (for parts
2752 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allanad680762008-03-28 09:15:03 -07002753 * - the full Rx FIFO size minus one full frame
2754 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002755 if (adapter->flags & FLAG_HAS_ERT)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002756 hwm = min(((pba << 10) * 9 / 10),
2757 ((pba << 10) - (E1000_ERT_2048 << 3)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002758 else
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002759 hwm = min(((pba << 10) * 9 / 10),
2760 ((pba << 10) - adapter->max_frame_size));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002761
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002762 fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */
2763 fc->low_water = fc->high_water - 8;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002764
2765 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002766 fc->pause_time = 0xFFFF;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002767 else
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002768 fc->pause_time = E1000_FC_PAUSE_TIME;
2769 fc->send_xon = 1;
2770 fc->type = fc->original_type;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002771
2772 /* Allow time for pending master requests to run */
2773 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002774
2775 /*
2776 * For parts with AMT enabled, let the firmware know
2777 * that the network interface is in control
2778 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07002779 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002780 e1000_get_hw_control(adapter);
2781
Auke Kokbc7f75f2007-09-17 12:30:59 -07002782 ew32(WUC, 0);
2783
2784 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002785 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002786
2787 e1000_update_mng_vlan(adapter);
2788
2789 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2790 ew32(VET, ETH_P_8021Q);
2791
2792 e1000e_reset_adaptive(hw);
2793 e1000_get_phy_info(hw);
2794
2795 if (!(adapter->flags & FLAG_SMART_POWER_DOWN)) {
2796 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07002797 /*
2798 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07002799 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07002800 * different we would do if it failed
2801 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002802 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
2803 phy_data &= ~IGP02E1000_PM_SPD;
2804 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
2805 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002806}
2807
2808int e1000e_up(struct e1000_adapter *adapter)
2809{
2810 struct e1000_hw *hw = &adapter->hw;
2811
2812 /* hardware has been reset, we need to reload some things */
2813 e1000_configure(adapter);
2814
2815 clear_bit(__E1000_DOWN, &adapter->state);
2816
2817 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002818 if (adapter->msix_entries)
2819 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002820 e1000_irq_enable(adapter);
2821
2822 /* fire a link change interrupt to start the watchdog */
2823 ew32(ICS, E1000_ICS_LSC);
2824 return 0;
2825}
2826
2827void e1000e_down(struct e1000_adapter *adapter)
2828{
2829 struct net_device *netdev = adapter->netdev;
2830 struct e1000_hw *hw = &adapter->hw;
2831 u32 tctl, rctl;
2832
Bruce Allanad680762008-03-28 09:15:03 -07002833 /*
2834 * signal that we're down so the interrupt handler does not
2835 * reschedule our watchdog timer
2836 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002837 set_bit(__E1000_DOWN, &adapter->state);
2838
2839 /* disable receives in the hardware */
2840 rctl = er32(RCTL);
2841 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2842 /* flush and sleep below */
2843
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07002844 netif_tx_stop_all_queues(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002845
2846 /* disable transmits in the hardware */
2847 tctl = er32(TCTL);
2848 tctl &= ~E1000_TCTL_EN;
2849 ew32(TCTL, tctl);
2850 /* flush both disables and wait for them to finish */
2851 e1e_flush();
2852 msleep(10);
2853
2854 napi_disable(&adapter->napi);
2855 e1000_irq_disable(adapter);
2856
2857 del_timer_sync(&adapter->watchdog_timer);
2858 del_timer_sync(&adapter->phy_info_timer);
2859
2860 netdev->tx_queue_len = adapter->tx_queue_len;
2861 netif_carrier_off(netdev);
2862 adapter->link_speed = 0;
2863 adapter->link_duplex = 0;
2864
Jeff Kirsher52cc3082008-06-24 17:01:29 -07002865 if (!pci_channel_offline(adapter->pdev))
2866 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002867 e1000_clean_tx_ring(adapter);
2868 e1000_clean_rx_ring(adapter);
2869
2870 /*
2871 * TODO: for power management, we could drop the link and
2872 * pci_disable_device here.
2873 */
2874}
2875
2876void e1000e_reinit_locked(struct e1000_adapter *adapter)
2877{
2878 might_sleep();
2879 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
2880 msleep(1);
2881 e1000e_down(adapter);
2882 e1000e_up(adapter);
2883 clear_bit(__E1000_RESETTING, &adapter->state);
2884}
2885
2886/**
2887 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2888 * @adapter: board private structure to initialize
2889 *
2890 * e1000_sw_init initializes the Adapter private data structure.
2891 * Fields are initialized based on PCI device information and
2892 * OS network device settings (MTU size).
2893 **/
2894static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
2895{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002896 struct net_device *netdev = adapter->netdev;
2897
2898 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
2899 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002900 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2901 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002902
Bruce Allan4662e822008-08-26 18:37:06 -07002903 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002904
Bruce Allan4662e822008-08-26 18:37:06 -07002905 if (e1000_alloc_queues(adapter))
2906 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002907
2908 spin_lock_init(&adapter->tx_queue_lock);
2909
2910 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002911 e1000_irq_disable(adapter);
2912
Auke Kokbc7f75f2007-09-17 12:30:59 -07002913 set_bit(__E1000_DOWN, &adapter->state);
2914 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002915}
2916
2917/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07002918 * e1000_intr_msi_test - Interrupt Handler
2919 * @irq: interrupt number
2920 * @data: pointer to a network interface device structure
2921 **/
2922static irqreturn_t e1000_intr_msi_test(int irq, void *data)
2923{
2924 struct net_device *netdev = data;
2925 struct e1000_adapter *adapter = netdev_priv(netdev);
2926 struct e1000_hw *hw = &adapter->hw;
2927 u32 icr = er32(ICR);
2928
2929 e_dbg("%s: icr is %08X\n", netdev->name, icr);
2930 if (icr & E1000_ICR_RXSEQ) {
2931 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
2932 wmb();
2933 }
2934
2935 return IRQ_HANDLED;
2936}
2937
2938/**
2939 * e1000_test_msi_interrupt - Returns 0 for successful test
2940 * @adapter: board private struct
2941 *
2942 * code flow taken from tg3.c
2943 **/
2944static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
2945{
2946 struct net_device *netdev = adapter->netdev;
2947 struct e1000_hw *hw = &adapter->hw;
2948 int err;
2949
2950 /* poll_enable hasn't been called yet, so don't need disable */
2951 /* clear any pending events */
2952 er32(ICR);
2953
2954 /* free the real vector and request a test handler */
2955 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07002956 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07002957
2958 /* Assume that the test fails, if it succeeds then the test
2959 * MSI irq handler will unset this flag */
2960 adapter->flags |= FLAG_MSI_TEST_FAILED;
2961
2962 err = pci_enable_msi(adapter->pdev);
2963 if (err)
2964 goto msi_test_failed;
2965
2966 err = request_irq(adapter->pdev->irq, &e1000_intr_msi_test, 0,
2967 netdev->name, netdev);
2968 if (err) {
2969 pci_disable_msi(adapter->pdev);
2970 goto msi_test_failed;
2971 }
2972
2973 wmb();
2974
2975 e1000_irq_enable(adapter);
2976
2977 /* fire an unusual interrupt on the test handler */
2978 ew32(ICS, E1000_ICS_RXSEQ);
2979 e1e_flush();
2980 msleep(50);
2981
2982 e1000_irq_disable(adapter);
2983
2984 rmb();
2985
2986 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07002987 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Bruce Allanf8d59f72008-08-08 18:36:11 -07002988 err = -EIO;
2989 e_info("MSI interrupt test failed!\n");
2990 }
2991
2992 free_irq(adapter->pdev->irq, netdev);
2993 pci_disable_msi(adapter->pdev);
2994
2995 if (err == -EIO)
2996 goto msi_test_failed;
2997
2998 /* okay so the test worked, restore settings */
2999 e_dbg("%s: MSI interrupt test succeeded!\n", netdev->name);
3000msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003001 e1000e_set_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003002 e1000_request_irq(adapter);
3003 return err;
3004}
3005
3006/**
3007 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3008 * @adapter: board private struct
3009 *
3010 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3011 **/
3012static int e1000_test_msi(struct e1000_adapter *adapter)
3013{
3014 int err;
3015 u16 pci_cmd;
3016
3017 if (!(adapter->flags & FLAG_MSI_ENABLED))
3018 return 0;
3019
3020 /* disable SERR in case the MSI write causes a master abort */
3021 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3022 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3023 pci_cmd & ~PCI_COMMAND_SERR);
3024
3025 err = e1000_test_msi_interrupt(adapter);
3026
3027 /* restore previous setting of command word */
3028 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3029
3030 /* success ! */
3031 if (!err)
3032 return 0;
3033
3034 /* EIO means MSI test failed */
3035 if (err != -EIO)
3036 return err;
3037
3038 /* back to INTx mode */
3039 e_warn("MSI interrupt test failed, using legacy interrupt.\n");
3040
3041 e1000_free_irq(adapter);
3042
3043 err = e1000_request_irq(adapter);
3044
3045 return err;
3046}
3047
3048/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003049 * e1000_open - Called when a network interface is made active
3050 * @netdev: network interface device structure
3051 *
3052 * Returns 0 on success, negative value on failure
3053 *
3054 * The open entry point is called when a network interface is made
3055 * active by the system (IFF_UP). At this point all resources needed
3056 * for transmit and receive operations are allocated, the interrupt
3057 * handler is registered with the OS, the watchdog timer is started,
3058 * and the stack is notified that the interface is ready.
3059 **/
3060static int e1000_open(struct net_device *netdev)
3061{
3062 struct e1000_adapter *adapter = netdev_priv(netdev);
3063 struct e1000_hw *hw = &adapter->hw;
3064 int err;
3065
3066 /* disallow open during test */
3067 if (test_bit(__E1000_TESTING, &adapter->state))
3068 return -EBUSY;
3069
3070 /* allocate transmit descriptors */
3071 err = e1000e_setup_tx_resources(adapter);
3072 if (err)
3073 goto err_setup_tx;
3074
3075 /* allocate receive descriptors */
3076 err = e1000e_setup_rx_resources(adapter);
3077 if (err)
3078 goto err_setup_rx;
3079
3080 e1000e_power_up_phy(adapter);
3081
3082 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3083 if ((adapter->hw.mng_cookie.status &
3084 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3085 e1000_update_mng_vlan(adapter);
3086
Bruce Allanad680762008-03-28 09:15:03 -07003087 /*
3088 * If AMT is enabled, let the firmware know that the network
3089 * interface is now open
3090 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003091 if (adapter->flags & FLAG_HAS_AMT)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003092 e1000_get_hw_control(adapter);
3093
Bruce Allanad680762008-03-28 09:15:03 -07003094 /*
3095 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3097 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003098 * clean_rx handler before we do so.
3099 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003100 e1000_configure(adapter);
3101
3102 err = e1000_request_irq(adapter);
3103 if (err)
3104 goto err_req_irq;
3105
Bruce Allanf8d59f72008-08-08 18:36:11 -07003106 /*
3107 * Work around PCIe errata with MSI interrupts causing some chipsets to
3108 * ignore e1000e MSI messages, which means we need to test our MSI
3109 * interrupt now
3110 */
Bruce Allan4662e822008-08-26 18:37:06 -07003111 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003112 err = e1000_test_msi(adapter);
3113 if (err) {
3114 e_err("Interrupt allocation failed\n");
3115 goto err_req_irq;
3116 }
3117 }
3118
Auke Kokbc7f75f2007-09-17 12:30:59 -07003119 /* From here on the code is the same as e1000e_up() */
3120 clear_bit(__E1000_DOWN, &adapter->state);
3121
3122 napi_enable(&adapter->napi);
3123
3124 e1000_irq_enable(adapter);
3125
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003126 netif_tx_start_all_queues(netdev);
3127
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128 /* fire a link status change interrupt to start the watchdog */
3129 ew32(ICS, E1000_ICS_LSC);
3130
3131 return 0;
3132
3133err_req_irq:
3134 e1000_release_hw_control(adapter);
3135 e1000_power_down_phy(adapter);
3136 e1000e_free_rx_resources(adapter);
3137err_setup_rx:
3138 e1000e_free_tx_resources(adapter);
3139err_setup_tx:
3140 e1000e_reset(adapter);
3141
3142 return err;
3143}
3144
3145/**
3146 * e1000_close - Disables a network interface
3147 * @netdev: network interface device structure
3148 *
3149 * Returns 0, this is not allowed to fail
3150 *
3151 * The close entry point is called when an interface is de-activated
3152 * by the OS. The hardware is still under the drivers control, but
3153 * needs to be disabled. A global MAC reset is issued to stop the
3154 * hardware, and all transmit and receive resources are freed.
3155 **/
3156static int e1000_close(struct net_device *netdev)
3157{
3158 struct e1000_adapter *adapter = netdev_priv(netdev);
3159
3160 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3161 e1000e_down(adapter);
3162 e1000_power_down_phy(adapter);
3163 e1000_free_irq(adapter);
3164
3165 e1000e_free_tx_resources(adapter);
3166 e1000e_free_rx_resources(adapter);
3167
Bruce Allanad680762008-03-28 09:15:03 -07003168 /*
3169 * kill manageability vlan ID if supported, but not if a vlan with
3170 * the same ID is registered on the host OS (let 8021q kill it)
3171 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003172 if ((adapter->hw.mng_cookie.status &
3173 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3174 !(adapter->vlgrp &&
3175 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3176 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3177
Bruce Allanad680762008-03-28 09:15:03 -07003178 /*
3179 * If AMT is enabled, let the firmware know that the network
3180 * interface is now closed
3181 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003182 if (adapter->flags & FLAG_HAS_AMT)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003183 e1000_release_hw_control(adapter);
3184
3185 return 0;
3186}
3187/**
3188 * e1000_set_mac - Change the Ethernet Address of the NIC
3189 * @netdev: network interface device structure
3190 * @p: pointer to an address structure
3191 *
3192 * Returns 0 on success, negative on failure
3193 **/
3194static int e1000_set_mac(struct net_device *netdev, void *p)
3195{
3196 struct e1000_adapter *adapter = netdev_priv(netdev);
3197 struct sockaddr *addr = p;
3198
3199 if (!is_valid_ether_addr(addr->sa_data))
3200 return -EADDRNOTAVAIL;
3201
3202 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3203 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3204
3205 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3206
3207 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3208 /* activate the work around */
3209 e1000e_set_laa_state_82571(&adapter->hw, 1);
3210
Bruce Allanad680762008-03-28 09:15:03 -07003211 /*
3212 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003213 * between the time RAR[0] gets clobbered and the time it
3214 * gets fixed (in e1000_watchdog), the actual LAA is in one
3215 * of the RARs and no incoming packets directed to this port
3216 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003217 * RAR[14]
3218 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003219 e1000e_rar_set(&adapter->hw,
3220 adapter->hw.mac.addr,
3221 adapter->hw.mac.rar_entry_count - 1);
3222 }
3223
3224 return 0;
3225}
3226
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003227/**
3228 * e1000e_update_phy_task - work thread to update phy
3229 * @work: pointer to our work struct
3230 *
3231 * this worker thread exists because we must acquire a
3232 * semaphore to read the phy, which we could msleep while
3233 * waiting for it, and we can't msleep in a timer.
3234 **/
3235static void e1000e_update_phy_task(struct work_struct *work)
3236{
3237 struct e1000_adapter *adapter = container_of(work,
3238 struct e1000_adapter, update_phy_task);
3239 e1000_get_phy_info(&adapter->hw);
3240}
3241
Bruce Allanad680762008-03-28 09:15:03 -07003242/*
3243 * Need to wait a few seconds after link up to get diagnostic information from
3244 * the phy
3245 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003246static void e1000_update_phy_info(unsigned long data)
3247{
3248 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003249 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003250}
3251
3252/**
3253 * e1000e_update_stats - Update the board statistics counters
3254 * @adapter: board private structure
3255 **/
3256void e1000e_update_stats(struct e1000_adapter *adapter)
3257{
3258 struct e1000_hw *hw = &adapter->hw;
3259 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003260
3261 /*
3262 * Prevent stats update while adapter is being reset, or if the pci
3263 * connection is down.
3264 */
3265 if (adapter->link_speed == 0)
3266 return;
3267 if (pci_channel_offline(pdev))
3268 return;
3269
Auke Kokbc7f75f2007-09-17 12:30:59 -07003270 adapter->stats.crcerrs += er32(CRCERRS);
3271 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003272 adapter->stats.gorc += er32(GORCL);
3273 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003274 adapter->stats.bprc += er32(BPRC);
3275 adapter->stats.mprc += er32(MPRC);
3276 adapter->stats.roc += er32(ROC);
3277
Auke Kokbc7f75f2007-09-17 12:30:59 -07003278 adapter->stats.mpc += er32(MPC);
3279 adapter->stats.scc += er32(SCC);
3280 adapter->stats.ecol += er32(ECOL);
3281 adapter->stats.mcc += er32(MCC);
3282 adapter->stats.latecol += er32(LATECOL);
3283 adapter->stats.dc += er32(DC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003284 adapter->stats.xonrxc += er32(XONRXC);
3285 adapter->stats.xontxc += er32(XONTXC);
3286 adapter->stats.xoffrxc += er32(XOFFRXC);
3287 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003288 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003289 adapter->stats.gotc += er32(GOTCL);
3290 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003291 adapter->stats.rnbc += er32(RNBC);
3292 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003293
3294 adapter->stats.mptc += er32(MPTC);
3295 adapter->stats.bptc += er32(BPTC);
3296
3297 /* used for adaptive IFS */
3298
3299 hw->mac.tx_packet_delta = er32(TPT);
3300 adapter->stats.tpt += hw->mac.tx_packet_delta;
3301 hw->mac.collision_delta = er32(COLC);
3302 adapter->stats.colc += hw->mac.collision_delta;
3303
3304 adapter->stats.algnerrc += er32(ALGNERRC);
3305 adapter->stats.rxerrc += er32(RXERRC);
Bruce Allan4662e822008-08-26 18:37:06 -07003306 if (hw->mac.type != e1000_82574)
3307 adapter->stats.tncrs += er32(TNCRS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003308 adapter->stats.cexterr += er32(CEXTERR);
3309 adapter->stats.tsctc += er32(TSCTC);
3310 adapter->stats.tsctfc += er32(TSCTFC);
3311
Auke Kokbc7f75f2007-09-17 12:30:59 -07003312 /* Fill out the OS statistics structure */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003313 adapter->net_stats.multicast = adapter->stats.mprc;
3314 adapter->net_stats.collisions = adapter->stats.colc;
3315
3316 /* Rx Errors */
3317
Bruce Allanad680762008-03-28 09:15:03 -07003318 /*
3319 * RLEC on some newer hardware can be incorrect so build
3320 * our own version based on RUC and ROC
3321 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003322 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3323 adapter->stats.crcerrs + adapter->stats.algnerrc +
3324 adapter->stats.ruc + adapter->stats.roc +
3325 adapter->stats.cexterr;
3326 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3327 adapter->stats.roc;
3328 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3329 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3330 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3331
3332 /* Tx Errors */
3333 adapter->net_stats.tx_errors = adapter->stats.ecol +
3334 adapter->stats.latecol;
3335 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3336 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3337 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3338
3339 /* Tx Dropped needs to be maintained elsewhere */
3340
Auke Kokbc7f75f2007-09-17 12:30:59 -07003341 /* Management Stats */
3342 adapter->stats.mgptc += er32(MGTPTC);
3343 adapter->stats.mgprc += er32(MGTPRC);
3344 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003345}
3346
Bruce Allan7c257692008-04-23 11:09:00 -07003347/**
3348 * e1000_phy_read_status - Update the PHY register status snapshot
3349 * @adapter: board private structure
3350 **/
3351static void e1000_phy_read_status(struct e1000_adapter *adapter)
3352{
3353 struct e1000_hw *hw = &adapter->hw;
3354 struct e1000_phy_regs *phy = &adapter->phy_regs;
3355 int ret_val;
Bruce Allan7c257692008-04-23 11:09:00 -07003356
3357 if ((er32(STATUS) & E1000_STATUS_LU) &&
3358 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
3359 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
3360 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
3361 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
3362 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
3363 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
3364 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
3365 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
3366 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
3367 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003368 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07003369 } else {
3370 /*
3371 * Do not read PHY registers if link is not up
3372 * Set values to typical power-on defaults
3373 */
3374 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
3375 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
3376 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
3377 BMSR_ERCAP);
3378 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
3379 ADVERTISE_ALL | ADVERTISE_CSMA);
3380 phy->lpa = 0;
3381 phy->expansion = EXPANSION_ENABLENPAGE;
3382 phy->ctrl1000 = ADVERTISE_1000FULL;
3383 phy->stat1000 = 0;
3384 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
3385 }
Bruce Allan7c257692008-04-23 11:09:00 -07003386}
3387
Auke Kokbc7f75f2007-09-17 12:30:59 -07003388static void e1000_print_link_info(struct e1000_adapter *adapter)
3389{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003390 struct e1000_hw *hw = &adapter->hw;
3391 u32 ctrl = er32(CTRL);
3392
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003393 e_info("Link is Up %d Mbps %s, Flow Control: %s\n",
3394 adapter->link_speed,
3395 (adapter->link_duplex == FULL_DUPLEX) ?
3396 "Full Duplex" : "Half Duplex",
3397 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
3398 "RX/TX" :
3399 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
3400 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" )));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003401}
3402
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003403static bool e1000_has_link(struct e1000_adapter *adapter)
3404{
3405 struct e1000_hw *hw = &adapter->hw;
3406 bool link_active = 0;
3407 s32 ret_val = 0;
3408
3409 /*
3410 * get_link_status is set on LSC (link status) interrupt or
3411 * Rx sequence error interrupt. get_link_status will stay
3412 * false until the check_for_link establishes link
3413 * for copper adapters ONLY
3414 */
3415 switch (hw->phy.media_type) {
3416 case e1000_media_type_copper:
3417 if (hw->mac.get_link_status) {
3418 ret_val = hw->mac.ops.check_for_link(hw);
3419 link_active = !hw->mac.get_link_status;
3420 } else {
3421 link_active = 1;
3422 }
3423 break;
3424 case e1000_media_type_fiber:
3425 ret_val = hw->mac.ops.check_for_link(hw);
3426 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
3427 break;
3428 case e1000_media_type_internal_serdes:
3429 ret_val = hw->mac.ops.check_for_link(hw);
3430 link_active = adapter->hw.mac.serdes_has_link;
3431 break;
3432 default:
3433 case e1000_media_type_unknown:
3434 break;
3435 }
3436
3437 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
3438 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
3439 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003440 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003441 }
3442
3443 return link_active;
3444}
3445
3446static void e1000e_enable_receives(struct e1000_adapter *adapter)
3447{
3448 /* make sure the receive unit is started */
3449 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
3450 (adapter->flags & FLAG_RX_RESTART_NOW)) {
3451 struct e1000_hw *hw = &adapter->hw;
3452 u32 rctl = er32(RCTL);
3453 ew32(RCTL, rctl | E1000_RCTL_EN);
3454 adapter->flags &= ~FLAG_RX_RESTART_NOW;
3455 }
3456}
3457
Auke Kokbc7f75f2007-09-17 12:30:59 -07003458/**
3459 * e1000_watchdog - Timer Call-back
3460 * @data: pointer to adapter cast into an unsigned long
3461 **/
3462static void e1000_watchdog(unsigned long data)
3463{
3464 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
3465
3466 /* Do the rest outside of interrupt context */
3467 schedule_work(&adapter->watchdog_task);
3468
3469 /* TODO: make this use queue_delayed_work() */
3470}
3471
3472static void e1000_watchdog_task(struct work_struct *work)
3473{
3474 struct e1000_adapter *adapter = container_of(work,
3475 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003476 struct net_device *netdev = adapter->netdev;
3477 struct e1000_mac_info *mac = &adapter->hw.mac;
3478 struct e1000_ring *tx_ring = adapter->tx_ring;
3479 struct e1000_hw *hw = &adapter->hw;
3480 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003481 int tx_pending = 0;
3482
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003483 link = e1000_has_link(adapter);
3484 if ((netif_carrier_ok(netdev)) && link) {
3485 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003486 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003487 }
3488
3489 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
3490 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
3491 e1000_update_mng_vlan(adapter);
3492
Auke Kokbc7f75f2007-09-17 12:30:59 -07003493 if (link) {
3494 if (!netif_carrier_ok(netdev)) {
3495 bool txb2b = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003496 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07003497 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003498 mac->ops.get_link_up_info(&adapter->hw,
3499 &adapter->link_speed,
3500 &adapter->link_duplex);
3501 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003502 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07003503 * On supported PHYs, check for duplex mismatch only
3504 * if link has autonegotiated at 10/100 half
3505 */
3506 if ((hw->phy.type == e1000_phy_igp_3 ||
3507 hw->phy.type == e1000_phy_bm) &&
3508 (hw->mac.autoneg == true) &&
3509 (adapter->link_speed == SPEED_10 ||
3510 adapter->link_speed == SPEED_100) &&
3511 (adapter->link_duplex == HALF_DUPLEX)) {
3512 u16 autoneg_exp;
3513
3514 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
3515
3516 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
3517 e_info("Autonegotiated half duplex but"
3518 " link partner cannot autoneg. "
3519 " Try forcing full duplex if "
3520 "link gets many collisions.\n");
3521 }
3522
3523 /*
Bruce Allanad680762008-03-28 09:15:03 -07003524 * tweak tx_queue_len according to speed/duplex
3525 * and adjust the timeout factor
3526 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003527 netdev->tx_queue_len = adapter->tx_queue_len;
3528 adapter->tx_timeout_factor = 1;
3529 switch (adapter->link_speed) {
3530 case SPEED_10:
3531 txb2b = 0;
3532 netdev->tx_queue_len = 10;
Bruce Allan10f1b492008-08-08 18:36:01 -07003533 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003534 break;
3535 case SPEED_100:
3536 txb2b = 0;
3537 netdev->tx_queue_len = 100;
3538 /* maybe add some timeout factor ? */
3539 break;
3540 }
3541
Bruce Allanad680762008-03-28 09:15:03 -07003542 /*
3543 * workaround: re-program speed mode bit after
3544 * link-up event
3545 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003546 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
3547 !txb2b) {
3548 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003549 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003550 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003551 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003552 }
3553
Bruce Allanad680762008-03-28 09:15:03 -07003554 /*
3555 * disable TSO for pcie and 10/100 speeds, to avoid
3556 * some hardware issues
3557 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003558 if (!(adapter->flags & FLAG_TSO_FORCE)) {
3559 switch (adapter->link_speed) {
3560 case SPEED_10:
3561 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003562 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003563 netdev->features &= ~NETIF_F_TSO;
3564 netdev->features &= ~NETIF_F_TSO6;
3565 break;
3566 case SPEED_1000:
3567 netdev->features |= NETIF_F_TSO;
3568 netdev->features |= NETIF_F_TSO6;
3569 break;
3570 default:
3571 /* oops */
3572 break;
3573 }
3574 }
3575
Bruce Allanad680762008-03-28 09:15:03 -07003576 /*
3577 * enable transmits in the hardware, need to do this
3578 * after setting TARC(0)
3579 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003580 tctl = er32(TCTL);
3581 tctl |= E1000_TCTL_EN;
3582 ew32(TCTL, tctl);
3583
3584 netif_carrier_on(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003585 netif_tx_wake_all_queues(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003586
3587 if (!test_bit(__E1000_DOWN, &adapter->state))
3588 mod_timer(&adapter->phy_info_timer,
3589 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003590 }
3591 } else {
3592 if (netif_carrier_ok(netdev)) {
3593 adapter->link_speed = 0;
3594 adapter->link_duplex = 0;
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003595 e_info("Link is Down\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003596 netif_carrier_off(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003597 netif_tx_stop_all_queues(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003598 if (!test_bit(__E1000_DOWN, &adapter->state))
3599 mod_timer(&adapter->phy_info_timer,
3600 round_jiffies(jiffies + 2 * HZ));
3601
3602 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3603 schedule_work(&adapter->reset_task);
3604 }
3605 }
3606
3607link_up:
3608 e1000e_update_stats(adapter);
3609
3610 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
3611 adapter->tpt_old = adapter->stats.tpt;
3612 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
3613 adapter->colc_old = adapter->stats.colc;
3614
Bruce Allan7c257692008-04-23 11:09:00 -07003615 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
3616 adapter->gorc_old = adapter->stats.gorc;
3617 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
3618 adapter->gotc_old = adapter->stats.gotc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003619
3620 e1000e_update_adaptive(&adapter->hw);
3621
3622 if (!netif_carrier_ok(netdev)) {
3623 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
3624 tx_ring->count);
3625 if (tx_pending) {
Bruce Allanad680762008-03-28 09:15:03 -07003626 /*
3627 * We've lost link, so the controller stops DMA,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003628 * but we've got queued Tx work that's never going
3629 * to get done, so reset controller to flush Tx.
Bruce Allanad680762008-03-28 09:15:03 -07003630 * (Do the reset outside of interrupt context).
3631 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003632 adapter->tx_timeout_count++;
3633 schedule_work(&adapter->reset_task);
3634 }
3635 }
3636
Bruce Allanad680762008-03-28 09:15:03 -07003637 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07003638 if (adapter->msix_entries)
3639 ew32(ICS, adapter->rx_ring->ims_val);
3640 else
3641 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003642
3643 /* Force detection of hung controller every watchdog period */
3644 adapter->detect_tx_hung = 1;
3645
Bruce Allanad680762008-03-28 09:15:03 -07003646 /*
3647 * With 82571 controllers, LAA may be overwritten due to controller
3648 * reset from the other port. Set the appropriate LAA in RAR[0]
3649 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003650 if (e1000e_get_laa_state_82571(hw))
3651 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
3652
3653 /* Reset the timer */
3654 if (!test_bit(__E1000_DOWN, &adapter->state))
3655 mod_timer(&adapter->watchdog_timer,
3656 round_jiffies(jiffies + 2 * HZ));
3657}
3658
3659#define E1000_TX_FLAGS_CSUM 0x00000001
3660#define E1000_TX_FLAGS_VLAN 0x00000002
3661#define E1000_TX_FLAGS_TSO 0x00000004
3662#define E1000_TX_FLAGS_IPV4 0x00000008
3663#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
3664#define E1000_TX_FLAGS_VLAN_SHIFT 16
3665
3666static int e1000_tso(struct e1000_adapter *adapter,
3667 struct sk_buff *skb)
3668{
3669 struct e1000_ring *tx_ring = adapter->tx_ring;
3670 struct e1000_context_desc *context_desc;
3671 struct e1000_buffer *buffer_info;
3672 unsigned int i;
3673 u32 cmd_length = 0;
3674 u16 ipcse = 0, tucse, mss;
3675 u8 ipcss, ipcso, tucss, tucso, hdr_len;
3676 int err;
3677
3678 if (skb_is_gso(skb)) {
3679 if (skb_header_cloned(skb)) {
3680 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3681 if (err)
3682 return err;
3683 }
3684
3685 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3686 mss = skb_shinfo(skb)->gso_size;
3687 if (skb->protocol == htons(ETH_P_IP)) {
3688 struct iphdr *iph = ip_hdr(skb);
3689 iph->tot_len = 0;
3690 iph->check = 0;
3691 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3692 iph->daddr, 0,
3693 IPPROTO_TCP,
3694 0);
3695 cmd_length = E1000_TXD_CMD_IP;
3696 ipcse = skb_transport_offset(skb) - 1;
3697 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3698 ipv6_hdr(skb)->payload_len = 0;
3699 tcp_hdr(skb)->check =
3700 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3701 &ipv6_hdr(skb)->daddr,
3702 0, IPPROTO_TCP, 0);
3703 ipcse = 0;
3704 }
3705 ipcss = skb_network_offset(skb);
3706 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
3707 tucss = skb_transport_offset(skb);
3708 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
3709 tucse = 0;
3710
3711 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
3712 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
3713
3714 i = tx_ring->next_to_use;
3715 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3716 buffer_info = &tx_ring->buffer_info[i];
3717
3718 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3719 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3720 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3721 context_desc->upper_setup.tcp_fields.tucss = tucss;
3722 context_desc->upper_setup.tcp_fields.tucso = tucso;
3723 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3724 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3725 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3726 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3727
3728 buffer_info->time_stamp = jiffies;
3729 buffer_info->next_to_watch = i;
3730
3731 i++;
3732 if (i == tx_ring->count)
3733 i = 0;
3734 tx_ring->next_to_use = i;
3735
3736 return 1;
3737 }
3738
3739 return 0;
3740}
3741
3742static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
3743{
3744 struct e1000_ring *tx_ring = adapter->tx_ring;
3745 struct e1000_context_desc *context_desc;
3746 struct e1000_buffer *buffer_info;
3747 unsigned int i;
3748 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07003749 u32 cmd_len = E1000_TXD_CMD_DEXT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750
Dave Grahamaf807c82008-10-09 14:28:58 -07003751 if (skb->ip_summed != CHECKSUM_PARTIAL)
3752 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003753
Dave Grahamaf807c82008-10-09 14:28:58 -07003754 switch (skb->protocol) {
3755 case __constant_htons(ETH_P_IP):
3756 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3757 cmd_len |= E1000_TXD_CMD_TCP;
3758 break;
3759 case __constant_htons(ETH_P_IPV6):
3760 /* XXX not handling all IPV6 headers */
3761 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3762 cmd_len |= E1000_TXD_CMD_TCP;
3763 break;
3764 default:
3765 if (unlikely(net_ratelimit()))
3766 e_warn("checksum_partial proto=%x!\n", skb->protocol);
3767 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003768 }
3769
Dave Grahamaf807c82008-10-09 14:28:58 -07003770 css = skb_transport_offset(skb);
3771
3772 i = tx_ring->next_to_use;
3773 buffer_info = &tx_ring->buffer_info[i];
3774 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3775
3776 context_desc->lower_setup.ip_config = 0;
3777 context_desc->upper_setup.tcp_fields.tucss = css;
3778 context_desc->upper_setup.tcp_fields.tucso =
3779 css + skb->csum_offset;
3780 context_desc->upper_setup.tcp_fields.tucse = 0;
3781 context_desc->tcp_seg_setup.data = 0;
3782 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
3783
3784 buffer_info->time_stamp = jiffies;
3785 buffer_info->next_to_watch = i;
3786
3787 i++;
3788 if (i == tx_ring->count)
3789 i = 0;
3790 tx_ring->next_to_use = i;
3791
3792 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003793}
3794
3795#define E1000_MAX_PER_TXD 8192
3796#define E1000_MAX_TXD_PWR 12
3797
3798static int e1000_tx_map(struct e1000_adapter *adapter,
3799 struct sk_buff *skb, unsigned int first,
3800 unsigned int max_per_txd, unsigned int nr_frags,
3801 unsigned int mss)
3802{
3803 struct e1000_ring *tx_ring = adapter->tx_ring;
3804 struct e1000_buffer *buffer_info;
3805 unsigned int len = skb->len - skb->data_len;
3806 unsigned int offset = 0, size, count = 0, i;
3807 unsigned int f;
3808
3809 i = tx_ring->next_to_use;
3810
3811 while (len) {
3812 buffer_info = &tx_ring->buffer_info[i];
3813 size = min(len, max_per_txd);
3814
3815 /* Workaround for premature desc write-backs
3816 * in TSO mode. Append 4-byte sentinel desc */
3817 if (mss && !nr_frags && size == len && size > 8)
3818 size -= 4;
3819
3820 buffer_info->length = size;
3821 /* set time_stamp *before* dma to help avoid a possible race */
3822 buffer_info->time_stamp = jiffies;
3823 buffer_info->dma =
3824 pci_map_single(adapter->pdev,
3825 skb->data + offset,
3826 size,
3827 PCI_DMA_TODEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07003828 if (pci_dma_mapping_error(adapter->pdev, buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003829 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
3830 adapter->tx_dma_failed++;
3831 return -1;
3832 }
3833 buffer_info->next_to_watch = i;
3834
3835 len -= size;
3836 offset += size;
3837 count++;
3838 i++;
3839 if (i == tx_ring->count)
3840 i = 0;
3841 }
3842
3843 for (f = 0; f < nr_frags; f++) {
3844 struct skb_frag_struct *frag;
3845
3846 frag = &skb_shinfo(skb)->frags[f];
3847 len = frag->size;
3848 offset = frag->page_offset;
3849
3850 while (len) {
3851 buffer_info = &tx_ring->buffer_info[i];
3852 size = min(len, max_per_txd);
3853 /* Workaround for premature desc write-backs
3854 * in TSO mode. Append 4-byte sentinel desc */
3855 if (mss && f == (nr_frags-1) && size == len && size > 8)
3856 size -= 4;
3857
3858 buffer_info->length = size;
3859 buffer_info->time_stamp = jiffies;
3860 buffer_info->dma =
3861 pci_map_page(adapter->pdev,
3862 frag->page,
3863 offset,
3864 size,
3865 PCI_DMA_TODEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07003866 if (pci_dma_mapping_error(adapter->pdev,
3867 buffer_info->dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003868 dev_err(&adapter->pdev->dev,
3869 "TX DMA page map failed\n");
3870 adapter->tx_dma_failed++;
3871 return -1;
3872 }
3873
3874 buffer_info->next_to_watch = i;
3875
3876 len -= size;
3877 offset += size;
3878 count++;
3879
3880 i++;
3881 if (i == tx_ring->count)
3882 i = 0;
3883 }
3884 }
3885
3886 if (i == 0)
3887 i = tx_ring->count - 1;
3888 else
3889 i--;
3890
3891 tx_ring->buffer_info[i].skb = skb;
3892 tx_ring->buffer_info[first].next_to_watch = i;
3893
3894 return count;
3895}
3896
3897static void e1000_tx_queue(struct e1000_adapter *adapter,
3898 int tx_flags, int count)
3899{
3900 struct e1000_ring *tx_ring = adapter->tx_ring;
3901 struct e1000_tx_desc *tx_desc = NULL;
3902 struct e1000_buffer *buffer_info;
3903 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3904 unsigned int i;
3905
3906 if (tx_flags & E1000_TX_FLAGS_TSO) {
3907 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3908 E1000_TXD_CMD_TSE;
3909 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3910
3911 if (tx_flags & E1000_TX_FLAGS_IPV4)
3912 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3913 }
3914
3915 if (tx_flags & E1000_TX_FLAGS_CSUM) {
3916 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3917 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3918 }
3919
3920 if (tx_flags & E1000_TX_FLAGS_VLAN) {
3921 txd_lower |= E1000_TXD_CMD_VLE;
3922 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3923 }
3924
3925 i = tx_ring->next_to_use;
3926
3927 while (count--) {
3928 buffer_info = &tx_ring->buffer_info[i];
3929 tx_desc = E1000_TX_DESC(*tx_ring, i);
3930 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3931 tx_desc->lower.data =
3932 cpu_to_le32(txd_lower | buffer_info->length);
3933 tx_desc->upper.data = cpu_to_le32(txd_upper);
3934
3935 i++;
3936 if (i == tx_ring->count)
3937 i = 0;
3938 }
3939
3940 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3941
Bruce Allanad680762008-03-28 09:15:03 -07003942 /*
3943 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07003944 * know there are new descriptors to fetch. (Only
3945 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07003946 * such as IA-64).
3947 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003948 wmb();
3949
3950 tx_ring->next_to_use = i;
3951 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07003952 /*
3953 * we need this if more than one processor can write to our tail
3954 * at a time, it synchronizes IO on IA64/Altix systems
3955 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003956 mmiowb();
3957}
3958
3959#define MINIMUM_DHCP_PACKET_SIZE 282
3960static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3961 struct sk_buff *skb)
3962{
3963 struct e1000_hw *hw = &adapter->hw;
3964 u16 length, offset;
3965
3966 if (vlan_tx_tag_present(skb)) {
3967 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id)
3968 && (adapter->hw.mng_cookie.status &
3969 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
3970 return 0;
3971 }
3972
3973 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
3974 return 0;
3975
3976 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
3977 return 0;
3978
3979 {
3980 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
3981 struct udphdr *udp;
3982
3983 if (ip->protocol != IPPROTO_UDP)
3984 return 0;
3985
3986 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
3987 if (ntohs(udp->dest) != 67)
3988 return 0;
3989
3990 offset = (u8 *)udp + 8 - skb->data;
3991 length = skb->len - offset;
3992 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
3993 }
3994
3995 return 0;
3996}
3997
3998static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3999{
4000 struct e1000_adapter *adapter = netdev_priv(netdev);
4001
4002 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004003 /*
4004 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004005 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004006 * but since that doesn't exist yet, just open code it.
4007 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008 smp_mb();
4009
Bruce Allanad680762008-03-28 09:15:03 -07004010 /*
4011 * We need to check again in a case another CPU has just
4012 * made room available.
4013 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004014 if (e1000_desc_unused(adapter->tx_ring) < size)
4015 return -EBUSY;
4016
4017 /* A reprieve! */
4018 netif_start_queue(netdev);
4019 ++adapter->restart_queue;
4020 return 0;
4021}
4022
4023static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4024{
4025 struct e1000_adapter *adapter = netdev_priv(netdev);
4026
4027 if (e1000_desc_unused(adapter->tx_ring) >= size)
4028 return 0;
4029 return __e1000_maybe_stop_tx(netdev, size);
4030}
4031
4032#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
4033static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
4034{
4035 struct e1000_adapter *adapter = netdev_priv(netdev);
4036 struct e1000_ring *tx_ring = adapter->tx_ring;
4037 unsigned int first;
4038 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4039 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4040 unsigned int tx_flags = 0;
Auke Kok4e6c7092007-10-05 14:15:23 -07004041 unsigned int len = skb->len - skb->data_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004042 unsigned long irq_flags;
Auke Kok4e6c7092007-10-05 14:15:23 -07004043 unsigned int nr_frags;
4044 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004045 int count = 0;
4046 int tso;
4047 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004048
4049 if (test_bit(__E1000_DOWN, &adapter->state)) {
4050 dev_kfree_skb_any(skb);
4051 return NETDEV_TX_OK;
4052 }
4053
4054 if (skb->len <= 0) {
4055 dev_kfree_skb_any(skb);
4056 return NETDEV_TX_OK;
4057 }
4058
4059 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004060 /*
4061 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004062 * make sure there is enough room in the FIFO before
4063 * initiating the DMA for each buffer. The calc is:
4064 * 4 = ceil(buffer len/mss). To make sure we don't
4065 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004066 * drops.
4067 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004068 if (mss) {
4069 u8 hdr_len;
4070 max_per_txd = min(mss << 2, max_per_txd);
4071 max_txd_pwr = fls(max_per_txd) - 1;
4072
Bruce Allanad680762008-03-28 09:15:03 -07004073 /*
4074 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4075 * points to just header, pull a few bytes of payload from
4076 * frags into skb->data
4077 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004078 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004079 /*
4080 * we do this workaround for ES2LAN, but it is un-necessary,
4081 * avoiding it could save a lot of cycles
4082 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004083 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004084 unsigned int pull_size;
4085
4086 pull_size = min((unsigned int)4, skb->data_len);
4087 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004088 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004089 dev_kfree_skb_any(skb);
4090 return NETDEV_TX_OK;
4091 }
4092 len = skb->len - skb->data_len;
4093 }
4094 }
4095
4096 /* reserve a descriptor for the offload context */
4097 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4098 count++;
4099 count++;
4100
4101 count += TXD_USE_COUNT(len, max_txd_pwr);
4102
4103 nr_frags = skb_shinfo(skb)->nr_frags;
4104 for (f = 0; f < nr_frags; f++)
4105 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4106 max_txd_pwr);
4107
4108 if (adapter->hw.mac.tx_pkt_filtering)
4109 e1000_transfer_dhcp_info(adapter, skb);
4110
4111 if (!spin_trylock_irqsave(&adapter->tx_queue_lock, irq_flags))
4112 /* Collision - tell upper layer to requeue */
4113 return NETDEV_TX_LOCKED;
4114
Bruce Allanad680762008-03-28 09:15:03 -07004115 /*
4116 * need: count + 2 desc gap to keep tail from touching
4117 * head, otherwise try next time
4118 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004119 if (e1000_maybe_stop_tx(netdev, count + 2)) {
4120 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
4121 return NETDEV_TX_BUSY;
4122 }
4123
4124 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4125 tx_flags |= E1000_TX_FLAGS_VLAN;
4126 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4127 }
4128
4129 first = tx_ring->next_to_use;
4130
4131 tso = e1000_tso(adapter, skb);
4132 if (tso < 0) {
4133 dev_kfree_skb_any(skb);
4134 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
4135 return NETDEV_TX_OK;
4136 }
4137
4138 if (tso)
4139 tx_flags |= E1000_TX_FLAGS_TSO;
4140 else if (e1000_tx_csum(adapter, skb))
4141 tx_flags |= E1000_TX_FLAGS_CSUM;
4142
Bruce Allanad680762008-03-28 09:15:03 -07004143 /*
4144 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004145 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004146 * no longer assume, we must.
4147 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004148 if (skb->protocol == htons(ETH_P_IP))
4149 tx_flags |= E1000_TX_FLAGS_IPV4;
4150
4151 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
4152 if (count < 0) {
4153 /* handle pci_map_single() error in e1000_tx_map */
4154 dev_kfree_skb_any(skb);
4155 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
Krishna Kumar7b5dfe1a2007-09-21 09:41:15 -07004156 return NETDEV_TX_OK;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004157 }
4158
4159 e1000_tx_queue(adapter, tx_flags, count);
4160
4161 netdev->trans_start = jiffies;
4162
4163 /* Make sure there is space in the ring for the next send. */
4164 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4165
4166 spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags);
4167 return NETDEV_TX_OK;
4168}
4169
4170/**
4171 * e1000_tx_timeout - Respond to a Tx Hang
4172 * @netdev: network interface device structure
4173 **/
4174static void e1000_tx_timeout(struct net_device *netdev)
4175{
4176 struct e1000_adapter *adapter = netdev_priv(netdev);
4177
4178 /* Do the reset outside of interrupt context */
4179 adapter->tx_timeout_count++;
4180 schedule_work(&adapter->reset_task);
4181}
4182
4183static void e1000_reset_task(struct work_struct *work)
4184{
4185 struct e1000_adapter *adapter;
4186 adapter = container_of(work, struct e1000_adapter, reset_task);
4187
4188 e1000e_reinit_locked(adapter);
4189}
4190
4191/**
4192 * e1000_get_stats - Get System Network Statistics
4193 * @netdev: network interface device structure
4194 *
4195 * Returns the address of the device statistics structure.
4196 * The statistics are actually updated from the timer callback.
4197 **/
4198static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
4199{
4200 struct e1000_adapter *adapter = netdev_priv(netdev);
4201
4202 /* only return the current stats */
4203 return &adapter->net_stats;
4204}
4205
4206/**
4207 * e1000_change_mtu - Change the Maximum Transfer Unit
4208 * @netdev: network interface device structure
4209 * @new_mtu: new value for maximum frame size
4210 *
4211 * Returns 0 on success, negative on failure
4212 **/
4213static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4214{
4215 struct e1000_adapter *adapter = netdev_priv(netdev);
4216 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4217
Bruce Alland53f7062008-08-08 18:36:06 -07004218 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -07004219 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004220 e_err("Invalid MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004221 return -EINVAL;
4222 }
4223
4224 /* Jumbo frame size limits */
4225 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
4226 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004227 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004228 return -EINVAL;
4229 }
4230 if (adapter->hw.phy.type == e1000_phy_ife) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004231 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004232 return -EINVAL;
4233 }
4234 }
4235
4236#define MAX_STD_JUMBO_FRAME_SIZE 9234
4237 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004238 e_err("MTU > 9216 not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004239 return -EINVAL;
4240 }
4241
4242 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4243 msleep(1);
4244 /* e1000e_down has a dependency on max_frame_size */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004245 adapter->max_frame_size = max_frame;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004246 if (netif_running(netdev))
4247 e1000e_down(adapter);
4248
Bruce Allanad680762008-03-28 09:15:03 -07004249 /*
4250 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07004251 * means we reserve 2 more, this pushes us to allocate from the next
4252 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07004253 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004254 * However with the new *_jumbo_rx* routines, jumbo receives will use
4255 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07004256 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004257
4258 if (max_frame <= 256)
4259 adapter->rx_buffer_len = 256;
4260 else if (max_frame <= 512)
4261 adapter->rx_buffer_len = 512;
4262 else if (max_frame <= 1024)
4263 adapter->rx_buffer_len = 1024;
4264 else if (max_frame <= 2048)
4265 adapter->rx_buffer_len = 2048;
4266 else
4267 adapter->rx_buffer_len = 4096;
4268
4269 /* adjust allocation if LPE protects us, and we aren't using SBP */
4270 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
4271 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
4272 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07004273 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004274
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004275 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004276 netdev->mtu = new_mtu;
4277
4278 if (netif_running(netdev))
4279 e1000e_up(adapter);
4280 else
4281 e1000e_reset(adapter);
4282
4283 clear_bit(__E1000_RESETTING, &adapter->state);
4284
4285 return 0;
4286}
4287
4288static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4289 int cmd)
4290{
4291 struct e1000_adapter *adapter = netdev_priv(netdev);
4292 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004293
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004294 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004295 return -EOPNOTSUPP;
4296
4297 switch (cmd) {
4298 case SIOCGMIIPHY:
4299 data->phy_id = adapter->hw.phy.addr;
4300 break;
4301 case SIOCGMIIREG:
4302 if (!capable(CAP_NET_ADMIN))
4303 return -EPERM;
Bruce Allan7c257692008-04-23 11:09:00 -07004304 switch (data->reg_num & 0x1F) {
4305 case MII_BMCR:
4306 data->val_out = adapter->phy_regs.bmcr;
4307 break;
4308 case MII_BMSR:
4309 data->val_out = adapter->phy_regs.bmsr;
4310 break;
4311 case MII_PHYSID1:
4312 data->val_out = (adapter->hw.phy.id >> 16);
4313 break;
4314 case MII_PHYSID2:
4315 data->val_out = (adapter->hw.phy.id & 0xFFFF);
4316 break;
4317 case MII_ADVERTISE:
4318 data->val_out = adapter->phy_regs.advertise;
4319 break;
4320 case MII_LPA:
4321 data->val_out = adapter->phy_regs.lpa;
4322 break;
4323 case MII_EXPANSION:
4324 data->val_out = adapter->phy_regs.expansion;
4325 break;
4326 case MII_CTRL1000:
4327 data->val_out = adapter->phy_regs.ctrl1000;
4328 break;
4329 case MII_STAT1000:
4330 data->val_out = adapter->phy_regs.stat1000;
4331 break;
4332 case MII_ESTATUS:
4333 data->val_out = adapter->phy_regs.estatus;
4334 break;
4335 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004336 return -EIO;
4337 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004338 break;
4339 case SIOCSMIIREG:
4340 default:
4341 return -EOPNOTSUPP;
4342 }
4343 return 0;
4344}
4345
4346static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4347{
4348 switch (cmd) {
4349 case SIOCGMIIPHY:
4350 case SIOCGMIIREG:
4351 case SIOCSMIIREG:
4352 return e1000_mii_ioctl(netdev, ifr, cmd);
4353 default:
4354 return -EOPNOTSUPP;
4355 }
4356}
4357
4358static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4359{
4360 struct net_device *netdev = pci_get_drvdata(pdev);
4361 struct e1000_adapter *adapter = netdev_priv(netdev);
4362 struct e1000_hw *hw = &adapter->hw;
4363 u32 ctrl, ctrl_ext, rctl, status;
4364 u32 wufc = adapter->wol;
4365 int retval = 0;
4366
4367 netif_device_detach(netdev);
4368
4369 if (netif_running(netdev)) {
4370 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
4371 e1000e_down(adapter);
4372 e1000_free_irq(adapter);
4373 }
Bruce Allan4662e822008-08-26 18:37:06 -07004374 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004375
4376 retval = pci_save_state(pdev);
4377 if (retval)
4378 return retval;
4379
4380 status = er32(STATUS);
4381 if (status & E1000_STATUS_LU)
4382 wufc &= ~E1000_WUFC_LNKC;
4383
4384 if (wufc) {
4385 e1000_setup_rctl(adapter);
4386 e1000_set_multi(netdev);
4387
4388 /* turn on all-multi mode if wake on multicast is enabled */
4389 if (wufc & E1000_WUFC_MC) {
4390 rctl = er32(RCTL);
4391 rctl |= E1000_RCTL_MPE;
4392 ew32(RCTL, rctl);
4393 }
4394
4395 ctrl = er32(CTRL);
4396 /* advertise wake from D3Cold */
4397 #define E1000_CTRL_ADVD3WUC 0x00100000
4398 /* phy power management enable */
4399 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4400 ctrl |= E1000_CTRL_ADVD3WUC |
4401 E1000_CTRL_EN_PHY_PWR_MGMT;
4402 ew32(CTRL, ctrl);
4403
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004404 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
4405 adapter->hw.phy.media_type ==
4406 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407 /* keep the laser running in D3 */
4408 ctrl_ext = er32(CTRL_EXT);
4409 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4410 ew32(CTRL_EXT, ctrl_ext);
4411 }
4412
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004413 if (adapter->flags & FLAG_IS_ICH)
4414 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
4415
Auke Kokbc7f75f2007-09-17 12:30:59 -07004416 /* Allow time for pending master requests to run */
4417 e1000e_disable_pcie_master(&adapter->hw);
4418
4419 ew32(WUC, E1000_WUC_PME_EN);
4420 ew32(WUFC, wufc);
4421 pci_enable_wake(pdev, PCI_D3hot, 1);
4422 pci_enable_wake(pdev, PCI_D3cold, 1);
4423 } else {
4424 ew32(WUC, 0);
4425 ew32(WUFC, 0);
4426 pci_enable_wake(pdev, PCI_D3hot, 0);
4427 pci_enable_wake(pdev, PCI_D3cold, 0);
4428 }
4429
Auke Kokbc7f75f2007-09-17 12:30:59 -07004430 /* make sure adapter isn't asleep if manageability is enabled */
4431 if (adapter->flags & FLAG_MNG_PT_ENABLED) {
4432 pci_enable_wake(pdev, PCI_D3hot, 1);
4433 pci_enable_wake(pdev, PCI_D3cold, 1);
4434 }
4435
4436 if (adapter->hw.phy.type == e1000_phy_igp_3)
4437 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
4438
Bruce Allanad680762008-03-28 09:15:03 -07004439 /*
4440 * Release control of h/w to f/w. If f/w is AMT enabled, this
4441 * would have already happened in close and is redundant.
4442 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004443 e1000_release_hw_control(adapter);
4444
4445 pci_disable_device(pdev);
4446
4447 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4448
4449 return 0;
4450}
4451
Auke Kok1eae4eb2007-10-31 15:22:00 -07004452static void e1000e_disable_l1aspm(struct pci_dev *pdev)
4453{
4454 int pos;
Auke Kok1eae4eb2007-10-31 15:22:00 -07004455 u16 val;
4456
4457 /*
4458 * 82573 workaround - disable L1 ASPM on mobile chipsets
4459 *
4460 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
4461 * resulting in lost data or garbage information on the pci-e link
4462 * level. This could result in (false) bad EEPROM checksum errors,
4463 * long ping times (up to 2s) or even a system freeze/hang.
4464 *
4465 * Unfortunately this feature saves about 1W power consumption when
4466 * active.
4467 */
4468 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
Auke Kok1eae4eb2007-10-31 15:22:00 -07004469 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val);
4470 if (val & 0x2) {
4471 dev_warn(&pdev->dev, "Disabling L1 ASPM\n");
4472 val &= ~0x2;
4473 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val);
4474 }
4475}
4476
Auke Kokbc7f75f2007-09-17 12:30:59 -07004477#ifdef CONFIG_PM
4478static int e1000_resume(struct pci_dev *pdev)
4479{
4480 struct net_device *netdev = pci_get_drvdata(pdev);
4481 struct e1000_adapter *adapter = netdev_priv(netdev);
4482 struct e1000_hw *hw = &adapter->hw;
4483 u32 err;
4484
4485 pci_set_power_state(pdev, PCI_D0);
4486 pci_restore_state(pdev);
Auke Kok1eae4eb2007-10-31 15:22:00 -07004487 e1000e_disable_l1aspm(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004488
Bruce Allanf0f422e2008-08-04 17:21:53 -07004489 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004490 if (err) {
4491 dev_err(&pdev->dev,
4492 "Cannot enable PCI device from suspend\n");
4493 return err;
4494 }
4495
4496 pci_set_master(pdev);
4497
4498 pci_enable_wake(pdev, PCI_D3hot, 0);
4499 pci_enable_wake(pdev, PCI_D3cold, 0);
4500
Bruce Allan4662e822008-08-26 18:37:06 -07004501 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004502 if (netif_running(netdev)) {
4503 err = e1000_request_irq(adapter);
4504 if (err)
4505 return err;
4506 }
4507
4508 e1000e_power_up_phy(adapter);
4509 e1000e_reset(adapter);
4510 ew32(WUS, ~0);
4511
4512 e1000_init_manageability(adapter);
4513
4514 if (netif_running(netdev))
4515 e1000e_up(adapter);
4516
4517 netif_device_attach(netdev);
4518
Bruce Allanad680762008-03-28 09:15:03 -07004519 /*
4520 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004521 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07004522 * under the control of the driver.
4523 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004524 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004525 e1000_get_hw_control(adapter);
4526
4527 return 0;
4528}
4529#endif
4530
4531static void e1000_shutdown(struct pci_dev *pdev)
4532{
4533 e1000_suspend(pdev, PMSG_SUSPEND);
4534}
4535
4536#ifdef CONFIG_NET_POLL_CONTROLLER
4537/*
4538 * Polling 'interrupt' - used by things like netconsole to send skbs
4539 * without having to re-enable interrupts. It's not called while
4540 * the interrupt routine is executing.
4541 */
4542static void e1000_netpoll(struct net_device *netdev)
4543{
4544 struct e1000_adapter *adapter = netdev_priv(netdev);
4545
4546 disable_irq(adapter->pdev->irq);
4547 e1000_intr(adapter->pdev->irq, netdev);
4548
Auke Kokbc7f75f2007-09-17 12:30:59 -07004549 enable_irq(adapter->pdev->irq);
4550}
4551#endif
4552
4553/**
4554 * e1000_io_error_detected - called when PCI error is detected
4555 * @pdev: Pointer to PCI device
4556 * @state: The current pci connection state
4557 *
4558 * This function is called after a PCI bus error affecting
4559 * this device has been detected.
4560 */
4561static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
4562 pci_channel_state_t state)
4563{
4564 struct net_device *netdev = pci_get_drvdata(pdev);
4565 struct e1000_adapter *adapter = netdev_priv(netdev);
4566
4567 netif_device_detach(netdev);
4568
4569 if (netif_running(netdev))
4570 e1000e_down(adapter);
4571 pci_disable_device(pdev);
4572
4573 /* Request a slot slot reset. */
4574 return PCI_ERS_RESULT_NEED_RESET;
4575}
4576
4577/**
4578 * e1000_io_slot_reset - called after the pci bus has been reset.
4579 * @pdev: Pointer to PCI device
4580 *
4581 * Restart the card from scratch, as if from a cold-boot. Implementation
4582 * resembles the first-half of the e1000_resume routine.
4583 */
4584static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4585{
4586 struct net_device *netdev = pci_get_drvdata(pdev);
4587 struct e1000_adapter *adapter = netdev_priv(netdev);
4588 struct e1000_hw *hw = &adapter->hw;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004589 int err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004590
Auke Kok1eae4eb2007-10-31 15:22:00 -07004591 e1000e_disable_l1aspm(pdev);
Bruce Allanf0f422e2008-08-04 17:21:53 -07004592 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004593 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004594 dev_err(&pdev->dev,
4595 "Cannot re-enable PCI device after reset.\n");
4596 return PCI_ERS_RESULT_DISCONNECT;
4597 }
4598 pci_set_master(pdev);
Wendy Xiongaad32732008-04-23 11:09:29 -07004599 pci_restore_state(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004600
4601 pci_enable_wake(pdev, PCI_D3hot, 0);
4602 pci_enable_wake(pdev, PCI_D3cold, 0);
4603
4604 e1000e_reset(adapter);
4605 ew32(WUS, ~0);
4606
4607 return PCI_ERS_RESULT_RECOVERED;
4608}
4609
4610/**
4611 * e1000_io_resume - called when traffic can start flowing again.
4612 * @pdev: Pointer to PCI device
4613 *
4614 * This callback is called when the error recovery driver tells us that
4615 * its OK to resume normal operation. Implementation resembles the
4616 * second-half of the e1000_resume routine.
4617 */
4618static void e1000_io_resume(struct pci_dev *pdev)
4619{
4620 struct net_device *netdev = pci_get_drvdata(pdev);
4621 struct e1000_adapter *adapter = netdev_priv(netdev);
4622
4623 e1000_init_manageability(adapter);
4624
4625 if (netif_running(netdev)) {
4626 if (e1000e_up(adapter)) {
4627 dev_err(&pdev->dev,
4628 "can't bring device back up after reset\n");
4629 return;
4630 }
4631 }
4632
4633 netif_device_attach(netdev);
4634
Bruce Allanad680762008-03-28 09:15:03 -07004635 /*
4636 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004637 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07004638 * under the control of the driver.
4639 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004640 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004641 e1000_get_hw_control(adapter);
4642
4643}
4644
4645static void e1000_print_device_info(struct e1000_adapter *adapter)
4646{
4647 struct e1000_hw *hw = &adapter->hw;
4648 struct net_device *netdev = adapter->netdev;
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004649 u32 pba_num;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004650
4651 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07004652 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004653 /* bus width */
4654 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
4655 "Width x1"),
4656 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07004657 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004658 e_info("Intel(R) PRO/%s Network Connection\n",
4659 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004660 e1000e_read_pba_num(hw, &pba_num);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004661 e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4662 hw->mac.type, hw->phy.type, (pba_num >> 8), (pba_num & 0xff));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004663}
4664
Auke Kok10aa4c02008-08-04 17:21:20 -07004665static void e1000_eeprom_checks(struct e1000_adapter *adapter)
4666{
4667 struct e1000_hw *hw = &adapter->hw;
4668 int ret_val;
4669 u16 buf = 0;
4670
4671 if (hw->mac.type != e1000_82573)
4672 return;
4673
4674 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
4675 if (!(le16_to_cpu(buf) & (1 << 0))) {
4676 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07004677 dev_warn(&adapter->pdev->dev,
4678 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07004679 }
4680
4681 ret_val = e1000_read_nvm(hw, NVM_INIT_3GIO_3, 1, &buf);
4682 if (le16_to_cpu(buf) & (3 << 2)) {
4683 /* ASPM enable */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07004684 dev_warn(&adapter->pdev->dev,
4685 "Warning: detected ASPM enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07004686 }
4687}
4688
Auke Kokbc7f75f2007-09-17 12:30:59 -07004689/**
4690 * e1000_probe - Device Initialization Routine
4691 * @pdev: PCI device information struct
4692 * @ent: entry in e1000_pci_tbl
4693 *
4694 * Returns 0 on success, negative on failure
4695 *
4696 * e1000_probe initializes an adapter identified by a pci_dev structure.
4697 * The OS initialization, configuring of the adapter private structure,
4698 * and a hardware reset occur.
4699 **/
4700static int __devinit e1000_probe(struct pci_dev *pdev,
4701 const struct pci_device_id *ent)
4702{
4703 struct net_device *netdev;
4704 struct e1000_adapter *adapter;
4705 struct e1000_hw *hw;
4706 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05004707 resource_size_t mmio_start, mmio_len;
4708 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004709
4710 static int cards_found;
4711 int i, err, pci_using_dac;
4712 u16 eeprom_data = 0;
4713 u16 eeprom_apme_mask = E1000_EEPROM_APME;
4714
Auke Kok1eae4eb2007-10-31 15:22:00 -07004715 e1000e_disable_l1aspm(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09004716
Bruce Allanf0f422e2008-08-04 17:21:53 -07004717 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004718 if (err)
4719 return err;
4720
4721 pci_using_dac = 0;
4722 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
4723 if (!err) {
4724 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
4725 if (!err)
4726 pci_using_dac = 1;
4727 } else {
4728 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4729 if (err) {
4730 err = pci_set_consistent_dma_mask(pdev,
4731 DMA_32BIT_MASK);
4732 if (err) {
4733 dev_err(&pdev->dev, "No usable DMA "
4734 "configuration, aborting\n");
4735 goto err_dma;
4736 }
4737 }
4738 }
4739
Bruce Allanf0f422e2008-08-04 17:21:53 -07004740 err = pci_request_selected_regions(pdev,
4741 pci_select_bars(pdev, IORESOURCE_MEM),
4742 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004743 if (err)
4744 goto err_pci_reg;
4745
4746 pci_set_master(pdev);
Wendy Xiongaad32732008-04-23 11:09:29 -07004747 pci_save_state(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004748
4749 err = -ENOMEM;
4750 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
4751 if (!netdev)
4752 goto err_alloc_etherdev;
4753
Auke Kokbc7f75f2007-09-17 12:30:59 -07004754 SET_NETDEV_DEV(netdev, &pdev->dev);
4755
4756 pci_set_drvdata(pdev, netdev);
4757 adapter = netdev_priv(netdev);
4758 hw = &adapter->hw;
4759 adapter->netdev = netdev;
4760 adapter->pdev = pdev;
4761 adapter->ei = ei;
4762 adapter->pba = ei->pba;
4763 adapter->flags = ei->flags;
4764 adapter->hw.adapter = adapter;
4765 adapter->hw.mac.type = ei->mac;
4766 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
4767
4768 mmio_start = pci_resource_start(pdev, 0);
4769 mmio_len = pci_resource_len(pdev, 0);
4770
4771 err = -EIO;
4772 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
4773 if (!adapter->hw.hw_addr)
4774 goto err_ioremap;
4775
4776 if ((adapter->flags & FLAG_HAS_FLASH) &&
4777 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
4778 flash_start = pci_resource_start(pdev, 1);
4779 flash_len = pci_resource_len(pdev, 1);
4780 adapter->hw.flash_address = ioremap(flash_start, flash_len);
4781 if (!adapter->hw.flash_address)
4782 goto err_flashmap;
4783 }
4784
4785 /* construct the net_device struct */
4786 netdev->open = &e1000_open;
4787 netdev->stop = &e1000_close;
4788 netdev->hard_start_xmit = &e1000_xmit_frame;
4789 netdev->get_stats = &e1000_get_stats;
4790 netdev->set_multicast_list = &e1000_set_multi;
4791 netdev->set_mac_address = &e1000_set_mac;
4792 netdev->change_mtu = &e1000_change_mtu;
4793 netdev->do_ioctl = &e1000_ioctl;
4794 e1000e_set_ethtool_ops(netdev);
4795 netdev->tx_timeout = &e1000_tx_timeout;
4796 netdev->watchdog_timeo = 5 * HZ;
4797 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
4798 netdev->vlan_rx_register = e1000_vlan_rx_register;
4799 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
4800 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
4801#ifdef CONFIG_NET_POLL_CONTROLLER
4802 netdev->poll_controller = e1000_netpoll;
4803#endif
4804 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
4805
4806 netdev->mem_start = mmio_start;
4807 netdev->mem_end = mmio_start + mmio_len;
4808
4809 adapter->bd_number = cards_found++;
4810
Bruce Allan4662e822008-08-26 18:37:06 -07004811 e1000e_check_options(adapter);
4812
Auke Kokbc7f75f2007-09-17 12:30:59 -07004813 /* setup adapter struct */
4814 err = e1000_sw_init(adapter);
4815 if (err)
4816 goto err_sw_init;
4817
4818 err = -EIO;
4819
4820 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
4821 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
4822 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
4823
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004824 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004825 if (err)
4826 goto err_hw_init;
4827
Bruce Allan4a770352008-10-01 17:18:35 -07004828 if ((adapter->flags & FLAG_IS_ICH) &&
4829 (adapter->flags & FLAG_READ_ONLY_NVM))
4830 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
4831
Auke Kokbc7f75f2007-09-17 12:30:59 -07004832 hw->mac.ops.get_bus_info(&adapter->hw);
4833
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004834 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004835
4836 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004837 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004838 adapter->hw.phy.mdix = AUTO_ALL_MODES;
4839 adapter->hw.phy.disable_polarity_correction = 0;
4840 adapter->hw.phy.ms_type = e1000_ms_hw_default;
4841 }
4842
4843 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004844 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004845
4846 netdev->features = NETIF_F_SG |
4847 NETIF_F_HW_CSUM |
4848 NETIF_F_HW_VLAN_TX |
4849 NETIF_F_HW_VLAN_RX;
4850
4851 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
4852 netdev->features |= NETIF_F_HW_VLAN_FILTER;
4853
4854 netdev->features |= NETIF_F_TSO;
4855 netdev->features |= NETIF_F_TSO6;
4856
Jeff Kirshera5136e22008-06-05 04:07:28 -07004857 netdev->vlan_features |= NETIF_F_TSO;
4858 netdev->vlan_features |= NETIF_F_TSO6;
4859 netdev->vlan_features |= NETIF_F_HW_CSUM;
4860 netdev->vlan_features |= NETIF_F_SG;
4861
Auke Kokbc7f75f2007-09-17 12:30:59 -07004862 if (pci_using_dac)
4863 netdev->features |= NETIF_F_HIGHDMA;
4864
Bruce Allanad680762008-03-28 09:15:03 -07004865 /*
4866 * We should not be using LLTX anymore, but we are still Tx faster with
4867 * it.
4868 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004869 netdev->features |= NETIF_F_LLTX;
4870
4871 if (e1000e_enable_mng_pass_thru(&adapter->hw))
4872 adapter->flags |= FLAG_MNG_PT_ENABLED;
4873
Bruce Allanad680762008-03-28 09:15:03 -07004874 /*
4875 * before reading the NVM, reset the controller to
4876 * put the device in a known good starting state
4877 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004878 adapter->hw.mac.ops.reset_hw(&adapter->hw);
4879
4880 /*
4881 * systems with ASPM and others may see the checksum fail on the first
4882 * attempt. Let's give it a few tries
4883 */
4884 for (i = 0;; i++) {
4885 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
4886 break;
4887 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004888 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004889 err = -EIO;
4890 goto err_eeprom;
4891 }
4892 }
4893
Auke Kok10aa4c02008-08-04 17:21:20 -07004894 e1000_eeprom_checks(adapter);
4895
Auke Kokbc7f75f2007-09-17 12:30:59 -07004896 /* copy the MAC address out of the NVM */
4897 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004898 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004899
4900 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
4901 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
4902
4903 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07004904 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004905 err = -EIO;
4906 goto err_eeprom;
4907 }
4908
4909 init_timer(&adapter->watchdog_timer);
4910 adapter->watchdog_timer.function = &e1000_watchdog;
4911 adapter->watchdog_timer.data = (unsigned long) adapter;
4912
4913 init_timer(&adapter->phy_info_timer);
4914 adapter->phy_info_timer.function = &e1000_update_phy_info;
4915 adapter->phy_info_timer.data = (unsigned long) adapter;
4916
4917 INIT_WORK(&adapter->reset_task, e1000_reset_task);
4918 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004919 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
4920 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004921
Auke Kokbc7f75f2007-09-17 12:30:59 -07004922 /* Initialize link parameters. User can change them with ethtool */
4923 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07004924 adapter->fc_autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004925 adapter->hw.fc.original_type = e1000_fc_default;
4926 adapter->hw.fc.type = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004927 adapter->hw.phy.autoneg_advertised = 0x2f;
4928
4929 /* ring size defaults */
4930 adapter->rx_ring->count = 256;
4931 adapter->tx_ring->count = 256;
4932
4933 /*
4934 * Initial Wake on LAN setting - If APM wake is enabled in
4935 * the EEPROM, enable the ACPI Magic Packet filter
4936 */
4937 if (adapter->flags & FLAG_APME_IN_WUC) {
4938 /* APME bit in EEPROM is mapped to WUC.APME */
4939 eeprom_data = er32(WUC);
4940 eeprom_apme_mask = E1000_WUC_APME;
4941 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
4942 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
4943 (adapter->hw.bus.func == 1))
4944 e1000_read_nvm(&adapter->hw,
4945 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
4946 else
4947 e1000_read_nvm(&adapter->hw,
4948 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
4949 }
4950
4951 /* fetch WoL from EEPROM */
4952 if (eeprom_data & eeprom_apme_mask)
4953 adapter->eeprom_wol |= E1000_WUFC_MAG;
4954
4955 /*
4956 * now that we have the eeprom settings, apply the special cases
4957 * where the eeprom may be wrong or the board simply won't support
4958 * wake on lan on a particular port
4959 */
4960 if (!(adapter->flags & FLAG_HAS_WOL))
4961 adapter->eeprom_wol = 0;
4962
4963 /* initialize the wol settings based on the eeprom settings */
4964 adapter->wol = adapter->eeprom_wol;
4965
4966 /* reset the hardware with the new settings */
4967 e1000e_reset(adapter);
4968
Bruce Allanad680762008-03-28 09:15:03 -07004969 /*
4970 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07004971 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07004972 * under the control of the driver.
4973 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004974 if (!(adapter->flags & FLAG_HAS_AMT))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004975 e1000_get_hw_control(adapter);
4976
4977 /* tell the stack to leave us alone until e1000_open() is called */
4978 netif_carrier_off(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004979 netif_tx_stop_all_queues(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004980
4981 strcpy(netdev->name, "eth%d");
4982 err = register_netdev(netdev);
4983 if (err)
4984 goto err_register;
4985
4986 e1000_print_device_info(adapter);
4987
4988 return 0;
4989
4990err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004991 if (!(adapter->flags & FLAG_HAS_AMT))
4992 e1000_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004993err_eeprom:
4994 if (!e1000_check_reset_block(&adapter->hw))
4995 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07004996err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004997
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998 kfree(adapter->tx_ring);
4999 kfree(adapter->rx_ring);
5000err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005001 if (adapter->hw.flash_address)
5002 iounmap(adapter->hw.flash_address);
5003err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005004 iounmap(adapter->hw.hw_addr);
5005err_ioremap:
5006 free_netdev(netdev);
5007err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07005008 pci_release_selected_regions(pdev,
5009 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005010err_pci_reg:
5011err_dma:
5012 pci_disable_device(pdev);
5013 return err;
5014}
5015
5016/**
5017 * e1000_remove - Device Removal Routine
5018 * @pdev: PCI device information struct
5019 *
5020 * e1000_remove is called by the PCI subsystem to alert the driver
5021 * that it should release a PCI device. The could be caused by a
5022 * Hot-Plug event, or because the driver is going to be removed from
5023 * memory.
5024 **/
5025static void __devexit e1000_remove(struct pci_dev *pdev)
5026{
5027 struct net_device *netdev = pci_get_drvdata(pdev);
5028 struct e1000_adapter *adapter = netdev_priv(netdev);
5029
Bruce Allanad680762008-03-28 09:15:03 -07005030 /*
5031 * flush_scheduled work may reschedule our watchdog task, so
5032 * explicitly disable watchdog tasks from being rescheduled
5033 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005034 set_bit(__E1000_DOWN, &adapter->state);
5035 del_timer_sync(&adapter->watchdog_timer);
5036 del_timer_sync(&adapter->phy_info_timer);
5037
5038 flush_scheduled_work();
5039
Bruce Allanad680762008-03-28 09:15:03 -07005040 /*
5041 * Release control of h/w to f/w. If f/w is AMT enabled, this
5042 * would have already happened in close and is redundant.
5043 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005044 e1000_release_hw_control(adapter);
5045
5046 unregister_netdev(netdev);
5047
5048 if (!e1000_check_reset_block(&adapter->hw))
5049 e1000_phy_hw_reset(&adapter->hw);
5050
Bruce Allan4662e822008-08-26 18:37:06 -07005051 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005052 kfree(adapter->tx_ring);
5053 kfree(adapter->rx_ring);
5054
5055 iounmap(adapter->hw.hw_addr);
5056 if (adapter->hw.flash_address)
5057 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07005058 pci_release_selected_regions(pdev,
5059 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005060
5061 free_netdev(netdev);
5062
5063 pci_disable_device(pdev);
5064}
5065
5066/* PCI Error Recovery (ERS) */
5067static struct pci_error_handlers e1000_err_handler = {
5068 .error_detected = e1000_io_error_detected,
5069 .slot_reset = e1000_io_slot_reset,
5070 .resume = e1000_io_resume,
5071};
5072
5073static struct pci_device_id e1000_pci_tbl[] = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005074 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
5075 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
5076 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
5077 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
5078 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
5079 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07005080 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
5081 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
5082 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07005083
Auke Kokbc7f75f2007-09-17 12:30:59 -07005084 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
5085 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
5086 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
5087 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07005088
Auke Kokbc7f75f2007-09-17 12:30:59 -07005089 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
5090 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
5091 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07005092
Bruce Allan4662e822008-08-26 18:37:06 -07005093 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
5094
Auke Kokbc7f75f2007-09-17 12:30:59 -07005095 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
5096 board_80003es2lan },
5097 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
5098 board_80003es2lan },
5099 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
5100 board_80003es2lan },
5101 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
5102 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07005103
Auke Kokbc7f75f2007-09-17 12:30:59 -07005104 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
5105 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
5106 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
5107 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
5108 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
5109 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
5110 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07005111
Auke Kokbc7f75f2007-09-17 12:30:59 -07005112 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
5113 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
5114 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
5115 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
5116 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07005117 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005118 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
5119 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
5120 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
5121
5122 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
5123 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
5124 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07005125
Bruce Allanf4187b52008-08-26 18:36:50 -07005126 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
5127 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
5128
Auke Kokbc7f75f2007-09-17 12:30:59 -07005129 { } /* terminate list */
5130};
5131MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
5132
5133/* PCI Device API Driver */
5134static struct pci_driver e1000_driver = {
5135 .name = e1000e_driver_name,
5136 .id_table = e1000_pci_tbl,
5137 .probe = e1000_probe,
5138 .remove = __devexit_p(e1000_remove),
5139#ifdef CONFIG_PM
Bruce Allanad680762008-03-28 09:15:03 -07005140 /* Power Management Hooks */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005141 .suspend = e1000_suspend,
5142 .resume = e1000_resume,
5143#endif
5144 .shutdown = e1000_shutdown,
5145 .err_handler = &e1000_err_handler
5146};
5147
5148/**
5149 * e1000_init_module - Driver Registration Routine
5150 *
5151 * e1000_init_module is the first routine called when the driver is
5152 * loaded. All it does is register with the PCI subsystem.
5153 **/
5154static int __init e1000_init_module(void)
5155{
5156 int ret;
5157 printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n",
5158 e1000e_driver_name, e1000e_driver_version);
Bruce Allanad680762008-03-28 09:15:03 -07005159 printk(KERN_INFO "%s: Copyright (c) 1999-2008 Intel Corporation.\n",
Auke Kokbc7f75f2007-09-17 12:30:59 -07005160 e1000e_driver_name);
5161 ret = pci_register_driver(&e1000_driver);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005162 pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name,
5163 PM_QOS_DEFAULT_VALUE);
5164
Auke Kokbc7f75f2007-09-17 12:30:59 -07005165 return ret;
5166}
5167module_init(e1000_init_module);
5168
5169/**
5170 * e1000_exit_module - Driver Exit Cleanup Routine
5171 *
5172 * e1000_exit_module is called just before the driver is removed
5173 * from memory.
5174 **/
5175static void __exit e1000_exit_module(void)
5176{
5177 pci_unregister_driver(&e1000_driver);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005178 pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005179}
5180module_exit(e1000_exit_module);
5181
5182
5183MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
5184MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
5185MODULE_LICENSE("GPL");
5186MODULE_VERSION(DRV_VERSION);
5187
5188/* e1000_main.c */