rename dev_hw_addr_random and remove redundant second
[linux/fpc-iii.git] / drivers / net / ethernet / intel / e1000e / netdev.c
blobf868fb822a303ac6f62eed632ae066865d5b7b8f
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
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.
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.
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
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
27 *******************************************************************************/
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/module.h>
32 #include <linux/types.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/vmalloc.h>
36 #include <linux/pagemap.h>
37 #include <linux/delay.h>
38 #include <linux/netdevice.h>
39 #include <linux/interrupt.h>
40 #include <linux/tcp.h>
41 #include <linux/ipv6.h>
42 #include <linux/slab.h>
43 #include <net/checksum.h>
44 #include <net/ip6_checksum.h>
45 #include <linux/mii.h>
46 #include <linux/ethtool.h>
47 #include <linux/if_vlan.h>
48 #include <linux/cpu.h>
49 #include <linux/smp.h>
50 #include <linux/pm_qos.h>
51 #include <linux/pm_runtime.h>
52 #include <linux/aer.h>
53 #include <linux/prefetch.h>
55 #include "e1000.h"
57 #define DRV_EXTRAVERSION "-k"
59 #define DRV_VERSION "1.9.5" DRV_EXTRAVERSION
60 char e1000e_driver_name[] = "e1000e";
61 const char e1000e_driver_version[] = DRV_VERSION;
63 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
65 static const struct e1000_info *e1000_info_tbl[] = {
66 [board_82571] = &e1000_82571_info,
67 [board_82572] = &e1000_82572_info,
68 [board_82573] = &e1000_82573_info,
69 [board_82574] = &e1000_82574_info,
70 [board_82583] = &e1000_82583_info,
71 [board_80003es2lan] = &e1000_es2_info,
72 [board_ich8lan] = &e1000_ich8_info,
73 [board_ich9lan] = &e1000_ich9_info,
74 [board_ich10lan] = &e1000_ich10_info,
75 [board_pchlan] = &e1000_pch_info,
76 [board_pch2lan] = &e1000_pch2_info,
79 struct e1000_reg_info {
80 u32 ofs;
81 char *name;
84 #define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
85 #define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
86 #define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
87 #define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
88 #define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
90 #define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
91 #define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
92 #define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
93 #define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
94 #define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
96 static const struct e1000_reg_info e1000_reg_info_tbl[] = {
98 /* General Registers */
99 {E1000_CTRL, "CTRL"},
100 {E1000_STATUS, "STATUS"},
101 {E1000_CTRL_EXT, "CTRL_EXT"},
103 /* Interrupt Registers */
104 {E1000_ICR, "ICR"},
106 /* Rx Registers */
107 {E1000_RCTL, "RCTL"},
108 {E1000_RDLEN, "RDLEN"},
109 {E1000_RDH, "RDH"},
110 {E1000_RDT, "RDT"},
111 {E1000_RDTR, "RDTR"},
112 {E1000_RXDCTL(0), "RXDCTL"},
113 {E1000_ERT, "ERT"},
114 {E1000_RDBAL, "RDBAL"},
115 {E1000_RDBAH, "RDBAH"},
116 {E1000_RDFH, "RDFH"},
117 {E1000_RDFT, "RDFT"},
118 {E1000_RDFHS, "RDFHS"},
119 {E1000_RDFTS, "RDFTS"},
120 {E1000_RDFPC, "RDFPC"},
122 /* Tx Registers */
123 {E1000_TCTL, "TCTL"},
124 {E1000_TDBAL, "TDBAL"},
125 {E1000_TDBAH, "TDBAH"},
126 {E1000_TDLEN, "TDLEN"},
127 {E1000_TDH, "TDH"},
128 {E1000_TDT, "TDT"},
129 {E1000_TIDV, "TIDV"},
130 {E1000_TXDCTL(0), "TXDCTL"},
131 {E1000_TADV, "TADV"},
132 {E1000_TARC(0), "TARC"},
133 {E1000_TDFH, "TDFH"},
134 {E1000_TDFT, "TDFT"},
135 {E1000_TDFHS, "TDFHS"},
136 {E1000_TDFTS, "TDFTS"},
137 {E1000_TDFPC, "TDFPC"},
139 /* List Terminator */
140 {0, NULL}
144 * e1000_regdump - register printout routine
146 static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
148 int n = 0;
149 char rname[16];
150 u32 regs[8];
152 switch (reginfo->ofs) {
153 case E1000_RXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_RXDCTL(n));
156 break;
157 case E1000_TXDCTL(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TXDCTL(n));
160 break;
161 case E1000_TARC(0):
162 for (n = 0; n < 2; n++)
163 regs[n] = __er32(hw, E1000_TARC(n));
164 break;
165 default:
166 pr_info("%-15s %08x\n",
167 reginfo->name, __er32(hw, reginfo->ofs));
168 return;
171 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
172 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
176 * e1000e_dump - Print registers, Tx-ring and Rx-ring
178 static void e1000e_dump(struct e1000_adapter *adapter)
180 struct net_device *netdev = adapter->netdev;
181 struct e1000_hw *hw = &adapter->hw;
182 struct e1000_reg_info *reginfo;
183 struct e1000_ring *tx_ring = adapter->tx_ring;
184 struct e1000_tx_desc *tx_desc;
185 struct my_u0 {
186 __le64 a;
187 __le64 b;
188 } *u0;
189 struct e1000_buffer *buffer_info;
190 struct e1000_ring *rx_ring = adapter->rx_ring;
191 union e1000_rx_desc_packet_split *rx_desc_ps;
192 union e1000_rx_desc_extended *rx_desc;
193 struct my_u1 {
194 __le64 a;
195 __le64 b;
196 __le64 c;
197 __le64 d;
198 } *u1;
199 u32 staterr;
200 int i = 0;
202 if (!netif_msg_hw(adapter))
203 return;
205 /* Print netdevice Info */
206 if (netdev) {
207 dev_info(&adapter->pdev->dev, "Net device Info\n");
208 pr_info("Device Name state trans_start last_rx\n");
209 pr_info("%-15s %016lX %016lX %016lX\n",
210 netdev->name, netdev->state, netdev->trans_start,
211 netdev->last_rx);
214 /* Print Registers */
215 dev_info(&adapter->pdev->dev, "Register Dump\n");
216 pr_info(" Register Name Value\n");
217 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
218 reginfo->name; reginfo++) {
219 e1000_regdump(hw, reginfo);
222 /* Print Tx Ring Summary */
223 if (!netdev || !netif_running(netdev))
224 return;
226 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
227 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
228 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
229 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
230 0, tx_ring->next_to_use, tx_ring->next_to_clean,
231 (unsigned long long)buffer_info->dma,
232 buffer_info->length,
233 buffer_info->next_to_watch,
234 (unsigned long long)buffer_info->time_stamp);
236 /* Print Tx Ring */
237 if (!netif_msg_tx_done(adapter))
238 goto rx_ring_summary;
240 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
242 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
244 * Legacy Transmit Descriptor
245 * +--------------------------------------------------------------+
246 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
247 * +--------------------------------------------------------------+
248 * 8 | Special | CSS | Status | CMD | CSO | Length |
249 * +--------------------------------------------------------------+
250 * 63 48 47 36 35 32 31 24 23 16 15 0
252 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
253 * 63 48 47 40 39 32 31 16 15 8 7 0
254 * +----------------------------------------------------------------+
255 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
256 * +----------------------------------------------------------------+
257 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
258 * +----------------------------------------------------------------+
259 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
261 * Extended Data Descriptor (DTYP=0x1)
262 * +----------------------------------------------------------------+
263 * 0 | Buffer Address [63:0] |
264 * +----------------------------------------------------------------+
265 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
266 * +----------------------------------------------------------------+
267 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
269 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
270 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
271 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
272 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
273 const char *next_desc;
274 tx_desc = E1000_TX_DESC(*tx_ring, i);
275 buffer_info = &tx_ring->buffer_info[i];
276 u0 = (struct my_u0 *)tx_desc;
277 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
278 next_desc = " NTC/U";
279 else if (i == tx_ring->next_to_use)
280 next_desc = " NTU";
281 else if (i == tx_ring->next_to_clean)
282 next_desc = " NTC";
283 else
284 next_desc = "";
285 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
286 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
287 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
289 (unsigned long long)le64_to_cpu(u0->a),
290 (unsigned long long)le64_to_cpu(u0->b),
291 (unsigned long long)buffer_info->dma,
292 buffer_info->length, buffer_info->next_to_watch,
293 (unsigned long long)buffer_info->time_stamp,
294 buffer_info->skb, next_desc);
296 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
297 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
298 16, 1, phys_to_virt(buffer_info->dma),
299 buffer_info->length, true);
302 /* Print Rx Ring Summary */
303 rx_ring_summary:
304 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
305 pr_info("Queue [NTU] [NTC]\n");
306 pr_info(" %5d %5X %5X\n",
307 0, rx_ring->next_to_use, rx_ring->next_to_clean);
309 /* Print Rx Ring */
310 if (!netif_msg_rx_status(adapter))
311 return;
313 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
314 switch (adapter->rx_ps_pages) {
315 case 1:
316 case 2:
317 case 3:
318 /* [Extended] Packet Split Receive Descriptor Format
320 * +-----------------------------------------------------+
321 * 0 | Buffer Address 0 [63:0] |
322 * +-----------------------------------------------------+
323 * 8 | Buffer Address 1 [63:0] |
324 * +-----------------------------------------------------+
325 * 16 | Buffer Address 2 [63:0] |
326 * +-----------------------------------------------------+
327 * 24 | Buffer Address 3 [63:0] |
328 * +-----------------------------------------------------+
330 pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
331 /* [Extended] Receive Descriptor (Write-Back) Format
333 * 63 48 47 32 31 13 12 8 7 4 3 0
334 * +------------------------------------------------------+
335 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
336 * | Checksum | Ident | | Queue | | Type |
337 * +------------------------------------------------------+
338 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
339 * +------------------------------------------------------+
340 * 63 48 47 32 31 20 19 0
342 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
343 for (i = 0; i < rx_ring->count; i++) {
344 const char *next_desc;
345 buffer_info = &rx_ring->buffer_info[i];
346 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
347 u1 = (struct my_u1 *)rx_desc_ps;
348 staterr =
349 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
351 if (i == rx_ring->next_to_use)
352 next_desc = " NTU";
353 else if (i == rx_ring->next_to_clean)
354 next_desc = " NTC";
355 else
356 next_desc = "";
358 if (staterr & E1000_RXD_STAT_DD) {
359 /* Descriptor Done */
360 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
361 "RWB", i,
362 (unsigned long long)le64_to_cpu(u1->a),
363 (unsigned long long)le64_to_cpu(u1->b),
364 (unsigned long long)le64_to_cpu(u1->c),
365 (unsigned long long)le64_to_cpu(u1->d),
366 buffer_info->skb, next_desc);
367 } else {
368 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
369 "R ", i,
370 (unsigned long long)le64_to_cpu(u1->a),
371 (unsigned long long)le64_to_cpu(u1->b),
372 (unsigned long long)le64_to_cpu(u1->c),
373 (unsigned long long)le64_to_cpu(u1->d),
374 (unsigned long long)buffer_info->dma,
375 buffer_info->skb, next_desc);
377 if (netif_msg_pktdata(adapter))
378 print_hex_dump(KERN_INFO, "",
379 DUMP_PREFIX_ADDRESS, 16, 1,
380 phys_to_virt(buffer_info->dma),
381 adapter->rx_ps_bsize0, true);
384 break;
385 default:
386 case 0:
387 /* Extended Receive Descriptor (Read) Format
389 * +-----------------------------------------------------+
390 * 0 | Buffer Address [63:0] |
391 * +-----------------------------------------------------+
392 * 8 | Reserved |
393 * +-----------------------------------------------------+
395 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
396 /* Extended Receive Descriptor (Write-Back) Format
398 * 63 48 47 32 31 24 23 4 3 0
399 * +------------------------------------------------------+
400 * | RSS Hash | | | |
401 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
402 * | Packet | IP | | | Type |
403 * | Checksum | Ident | | | |
404 * +------------------------------------------------------+
405 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
406 * +------------------------------------------------------+
407 * 63 48 47 32 31 20 19 0
409 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
411 for (i = 0; i < rx_ring->count; i++) {
412 const char *next_desc;
414 buffer_info = &rx_ring->buffer_info[i];
415 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
416 u1 = (struct my_u1 *)rx_desc;
417 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
419 if (i == rx_ring->next_to_use)
420 next_desc = " NTU";
421 else if (i == rx_ring->next_to_clean)
422 next_desc = " NTC";
423 else
424 next_desc = "";
426 if (staterr & E1000_RXD_STAT_DD) {
427 /* Descriptor Done */
428 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
429 "RWB", i,
430 (unsigned long long)le64_to_cpu(u1->a),
431 (unsigned long long)le64_to_cpu(u1->b),
432 buffer_info->skb, next_desc);
433 } else {
434 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
435 "R ", i,
436 (unsigned long long)le64_to_cpu(u1->a),
437 (unsigned long long)le64_to_cpu(u1->b),
438 (unsigned long long)buffer_info->dma,
439 buffer_info->skb, next_desc);
441 if (netif_msg_pktdata(adapter))
442 print_hex_dump(KERN_INFO, "",
443 DUMP_PREFIX_ADDRESS, 16,
445 phys_to_virt
446 (buffer_info->dma),
447 adapter->rx_buffer_len,
448 true);
455 * e1000_desc_unused - calculate if we have unused descriptors
457 static int e1000_desc_unused(struct e1000_ring *ring)
459 if (ring->next_to_clean > ring->next_to_use)
460 return ring->next_to_clean - ring->next_to_use - 1;
462 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
466 * e1000_receive_skb - helper function to handle Rx indications
467 * @adapter: board private structure
468 * @status: descriptor status field as written by hardware
469 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
470 * @skb: pointer to sk_buff to be indicated to stack
472 static void e1000_receive_skb(struct e1000_adapter *adapter,
473 struct net_device *netdev, struct sk_buff *skb,
474 u8 status, __le16 vlan)
476 u16 tag = le16_to_cpu(vlan);
477 skb->protocol = eth_type_trans(skb, netdev);
479 if (status & E1000_RXD_STAT_VP)
480 __vlan_hwaccel_put_tag(skb, tag);
482 napi_gro_receive(&adapter->napi, skb);
486 * e1000_rx_checksum - Receive Checksum Offload
487 * @adapter: board private structure
488 * @status_err: receive descriptor status and error fields
489 * @csum: receive descriptor csum field
490 * @sk_buff: socket buffer with received data
492 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
493 __le16 csum, struct sk_buff *skb)
495 u16 status = (u16)status_err;
496 u8 errors = (u8)(status_err >> 24);
498 skb_checksum_none_assert(skb);
500 /* Rx checksum disabled */
501 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
502 return;
504 /* Ignore Checksum bit is set */
505 if (status & E1000_RXD_STAT_IXSM)
506 return;
508 /* TCP/UDP checksum error bit is set */
509 if (errors & E1000_RXD_ERR_TCPE) {
510 /* let the stack verify checksum errors */
511 adapter->hw_csum_err++;
512 return;
515 /* TCP/UDP Checksum has not been calculated */
516 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
517 return;
519 /* It must be a TCP or UDP packet with a valid checksum */
520 if (status & E1000_RXD_STAT_TCPCS) {
521 /* TCP checksum is good */
522 skb->ip_summed = CHECKSUM_UNNECESSARY;
523 } else {
525 * IP fragment with UDP payload
526 * Hardware complements the payload checksum, so we undo it
527 * and then put the value in host order for further stack use.
529 __sum16 sum = (__force __sum16)swab16((__force u16)csum);
530 skb->csum = csum_unfold(~sum);
531 skb->ip_summed = CHECKSUM_COMPLETE;
533 adapter->hw_csum_good++;
537 * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa()
538 * @hw: pointer to the HW structure
539 * @tail: address of tail descriptor register
540 * @i: value to write to tail descriptor register
542 * When updating the tail register, the ME could be accessing Host CSR
543 * registers at the same time. Normally, this is handled in h/w by an
544 * arbiter but on some parts there is a bug that acknowledges Host accesses
545 * later than it should which could result in the descriptor register to
546 * have an incorrect value. Workaround this by checking the FWSM register
547 * which has bit 24 set while ME is accessing Host CSR registers, wait
548 * if it is set and try again a number of times.
550 static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, void __iomem *tail,
551 unsigned int i)
553 unsigned int j = 0;
555 while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) &&
556 (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI))
557 udelay(50);
559 writel(i, tail);
561 if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail)))
562 return E1000_ERR_SWFW_SYNC;
564 return 0;
567 static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
569 struct e1000_adapter *adapter = rx_ring->adapter;
570 struct e1000_hw *hw = &adapter->hw;
572 if (e1000e_update_tail_wa(hw, rx_ring->tail, i)) {
573 u32 rctl = er32(RCTL);
574 ew32(RCTL, rctl & ~E1000_RCTL_EN);
575 e_err("ME firmware caused invalid RDT - resetting\n");
576 schedule_work(&adapter->reset_task);
580 static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
582 struct e1000_adapter *adapter = tx_ring->adapter;
583 struct e1000_hw *hw = &adapter->hw;
585 if (e1000e_update_tail_wa(hw, tx_ring->tail, i)) {
586 u32 tctl = er32(TCTL);
587 ew32(TCTL, tctl & ~E1000_TCTL_EN);
588 e_err("ME firmware caused invalid TDT - resetting\n");
589 schedule_work(&adapter->reset_task);
594 * e1000_alloc_rx_buffers - Replace used receive buffers
595 * @rx_ring: Rx descriptor ring
597 static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
598 int cleaned_count, gfp_t gfp)
600 struct e1000_adapter *adapter = rx_ring->adapter;
601 struct net_device *netdev = adapter->netdev;
602 struct pci_dev *pdev = adapter->pdev;
603 union e1000_rx_desc_extended *rx_desc;
604 struct e1000_buffer *buffer_info;
605 struct sk_buff *skb;
606 unsigned int i;
607 unsigned int bufsz = adapter->rx_buffer_len;
609 i = rx_ring->next_to_use;
610 buffer_info = &rx_ring->buffer_info[i];
612 while (cleaned_count--) {
613 skb = buffer_info->skb;
614 if (skb) {
615 skb_trim(skb, 0);
616 goto map_skb;
619 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
620 if (!skb) {
621 /* Better luck next round */
622 adapter->alloc_rx_buff_failed++;
623 break;
626 buffer_info->skb = skb;
627 map_skb:
628 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
629 adapter->rx_buffer_len,
630 DMA_FROM_DEVICE);
631 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
632 dev_err(&pdev->dev, "Rx DMA map failed\n");
633 adapter->rx_dma_failed++;
634 break;
637 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
638 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
640 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
642 * Force memory writes to complete before letting h/w
643 * know there are new descriptors to fetch. (Only
644 * applicable for weak-ordered memory model archs,
645 * such as IA-64).
647 wmb();
648 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
649 e1000e_update_rdt_wa(rx_ring, i);
650 else
651 writel(i, rx_ring->tail);
653 i++;
654 if (i == rx_ring->count)
655 i = 0;
656 buffer_info = &rx_ring->buffer_info[i];
659 rx_ring->next_to_use = i;
663 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
664 * @rx_ring: Rx descriptor ring
666 static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
667 int cleaned_count, gfp_t gfp)
669 struct e1000_adapter *adapter = rx_ring->adapter;
670 struct net_device *netdev = adapter->netdev;
671 struct pci_dev *pdev = adapter->pdev;
672 union e1000_rx_desc_packet_split *rx_desc;
673 struct e1000_buffer *buffer_info;
674 struct e1000_ps_page *ps_page;
675 struct sk_buff *skb;
676 unsigned int i, j;
678 i = rx_ring->next_to_use;
679 buffer_info = &rx_ring->buffer_info[i];
681 while (cleaned_count--) {
682 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
684 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
685 ps_page = &buffer_info->ps_pages[j];
686 if (j >= adapter->rx_ps_pages) {
687 /* all unused desc entries get hw null ptr */
688 rx_desc->read.buffer_addr[j + 1] =
689 ~cpu_to_le64(0);
690 continue;
692 if (!ps_page->page) {
693 ps_page->page = alloc_page(gfp);
694 if (!ps_page->page) {
695 adapter->alloc_rx_buff_failed++;
696 goto no_buffers;
698 ps_page->dma = dma_map_page(&pdev->dev,
699 ps_page->page,
700 0, PAGE_SIZE,
701 DMA_FROM_DEVICE);
702 if (dma_mapping_error(&pdev->dev,
703 ps_page->dma)) {
704 dev_err(&adapter->pdev->dev,
705 "Rx DMA page map failed\n");
706 adapter->rx_dma_failed++;
707 goto no_buffers;
711 * Refresh the desc even if buffer_addrs
712 * didn't change because each write-back
713 * erases this info.
715 rx_desc->read.buffer_addr[j + 1] =
716 cpu_to_le64(ps_page->dma);
719 skb = __netdev_alloc_skb_ip_align(netdev,
720 adapter->rx_ps_bsize0,
721 gfp);
723 if (!skb) {
724 adapter->alloc_rx_buff_failed++;
725 break;
728 buffer_info->skb = skb;
729 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
730 adapter->rx_ps_bsize0,
731 DMA_FROM_DEVICE);
732 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
733 dev_err(&pdev->dev, "Rx DMA map failed\n");
734 adapter->rx_dma_failed++;
735 /* cleanup skb */
736 dev_kfree_skb_any(skb);
737 buffer_info->skb = NULL;
738 break;
741 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
743 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
745 * Force memory writes to complete before letting h/w
746 * know there are new descriptors to fetch. (Only
747 * applicable for weak-ordered memory model archs,
748 * such as IA-64).
750 wmb();
751 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
752 e1000e_update_rdt_wa(rx_ring, i << 1);
753 else
754 writel(i << 1, rx_ring->tail);
757 i++;
758 if (i == rx_ring->count)
759 i = 0;
760 buffer_info = &rx_ring->buffer_info[i];
763 no_buffers:
764 rx_ring->next_to_use = i;
768 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
769 * @rx_ring: Rx descriptor ring
770 * @cleaned_count: number of buffers to allocate this pass
773 static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
774 int cleaned_count, gfp_t gfp)
776 struct e1000_adapter *adapter = rx_ring->adapter;
777 struct net_device *netdev = adapter->netdev;
778 struct pci_dev *pdev = adapter->pdev;
779 union e1000_rx_desc_extended *rx_desc;
780 struct e1000_buffer *buffer_info;
781 struct sk_buff *skb;
782 unsigned int i;
783 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
785 i = rx_ring->next_to_use;
786 buffer_info = &rx_ring->buffer_info[i];
788 while (cleaned_count--) {
789 skb = buffer_info->skb;
790 if (skb) {
791 skb_trim(skb, 0);
792 goto check_page;
795 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
796 if (unlikely(!skb)) {
797 /* Better luck next round */
798 adapter->alloc_rx_buff_failed++;
799 break;
802 buffer_info->skb = skb;
803 check_page:
804 /* allocate a new page if necessary */
805 if (!buffer_info->page) {
806 buffer_info->page = alloc_page(gfp);
807 if (unlikely(!buffer_info->page)) {
808 adapter->alloc_rx_buff_failed++;
809 break;
813 if (!buffer_info->dma)
814 buffer_info->dma = dma_map_page(&pdev->dev,
815 buffer_info->page, 0,
816 PAGE_SIZE,
817 DMA_FROM_DEVICE);
819 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
820 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
822 if (unlikely(++i == rx_ring->count))
823 i = 0;
824 buffer_info = &rx_ring->buffer_info[i];
827 if (likely(rx_ring->next_to_use != i)) {
828 rx_ring->next_to_use = i;
829 if (unlikely(i-- == 0))
830 i = (rx_ring->count - 1);
832 /* Force memory writes to complete before letting h/w
833 * know there are new descriptors to fetch. (Only
834 * applicable for weak-ordered memory model archs,
835 * such as IA-64). */
836 wmb();
837 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
838 e1000e_update_rdt_wa(rx_ring, i);
839 else
840 writel(i, rx_ring->tail);
844 static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
845 struct sk_buff *skb)
847 if (netdev->features & NETIF_F_RXHASH)
848 skb->rxhash = le32_to_cpu(rss);
852 * e1000_clean_rx_irq - Send received data up the network stack
853 * @rx_ring: Rx descriptor ring
855 * the return value indicates whether actual cleaning was done, there
856 * is no guarantee that everything was cleaned
858 static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
859 int work_to_do)
861 struct e1000_adapter *adapter = rx_ring->adapter;
862 struct net_device *netdev = adapter->netdev;
863 struct pci_dev *pdev = adapter->pdev;
864 struct e1000_hw *hw = &adapter->hw;
865 union e1000_rx_desc_extended *rx_desc, *next_rxd;
866 struct e1000_buffer *buffer_info, *next_buffer;
867 u32 length, staterr;
868 unsigned int i;
869 int cleaned_count = 0;
870 bool cleaned = false;
871 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
873 i = rx_ring->next_to_clean;
874 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
875 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
876 buffer_info = &rx_ring->buffer_info[i];
878 while (staterr & E1000_RXD_STAT_DD) {
879 struct sk_buff *skb;
881 if (*work_done >= work_to_do)
882 break;
883 (*work_done)++;
884 rmb(); /* read descriptor and rx_buffer_info after status DD */
886 skb = buffer_info->skb;
887 buffer_info->skb = NULL;
889 prefetch(skb->data - NET_IP_ALIGN);
891 i++;
892 if (i == rx_ring->count)
893 i = 0;
894 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
895 prefetch(next_rxd);
897 next_buffer = &rx_ring->buffer_info[i];
899 cleaned = true;
900 cleaned_count++;
901 dma_unmap_single(&pdev->dev,
902 buffer_info->dma,
903 adapter->rx_buffer_len,
904 DMA_FROM_DEVICE);
905 buffer_info->dma = 0;
907 length = le16_to_cpu(rx_desc->wb.upper.length);
910 * !EOP means multiple descriptors were used to store a single
911 * packet, if that's the case we need to toss it. In fact, we
912 * need to toss every packet with the EOP bit clear and the
913 * next frame that _does_ have the EOP bit set, as it is by
914 * definition only a frame fragment
916 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
917 adapter->flags2 |= FLAG2_IS_DISCARDING;
919 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
920 /* All receives must fit into a single buffer */
921 e_dbg("Receive packet consumed multiple buffers\n");
922 /* recycle */
923 buffer_info->skb = skb;
924 if (staterr & E1000_RXD_STAT_EOP)
925 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
926 goto next_desc;
929 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
930 /* recycle */
931 buffer_info->skb = skb;
932 goto next_desc;
935 /* adjust length to remove Ethernet CRC */
936 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
937 length -= 4;
939 total_rx_bytes += length;
940 total_rx_packets++;
943 * code added for copybreak, this should improve
944 * performance for small packets with large amounts
945 * of reassembly being done in the stack
947 if (length < copybreak) {
948 struct sk_buff *new_skb =
949 netdev_alloc_skb_ip_align(netdev, length);
950 if (new_skb) {
951 skb_copy_to_linear_data_offset(new_skb,
952 -NET_IP_ALIGN,
953 (skb->data -
954 NET_IP_ALIGN),
955 (length +
956 NET_IP_ALIGN));
957 /* save the skb in buffer_info as good */
958 buffer_info->skb = skb;
959 skb = new_skb;
961 /* else just continue with the old one */
963 /* end copybreak code */
964 skb_put(skb, length);
966 /* Receive Checksum Offload */
967 e1000_rx_checksum(adapter, staterr,
968 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
970 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
972 e1000_receive_skb(adapter, netdev, skb, staterr,
973 rx_desc->wb.upper.vlan);
975 next_desc:
976 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
978 /* return some buffers to hardware, one at a time is too slow */
979 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
980 adapter->alloc_rx_buf(rx_ring, cleaned_count,
981 GFP_ATOMIC);
982 cleaned_count = 0;
985 /* use prefetched values */
986 rx_desc = next_rxd;
987 buffer_info = next_buffer;
989 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
991 rx_ring->next_to_clean = i;
993 cleaned_count = e1000_desc_unused(rx_ring);
994 if (cleaned_count)
995 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
997 adapter->total_rx_bytes += total_rx_bytes;
998 adapter->total_rx_packets += total_rx_packets;
999 return cleaned;
1002 static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1003 struct e1000_buffer *buffer_info)
1005 struct e1000_adapter *adapter = tx_ring->adapter;
1007 if (buffer_info->dma) {
1008 if (buffer_info->mapped_as_page)
1009 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1010 buffer_info->length, DMA_TO_DEVICE);
1011 else
1012 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1013 buffer_info->length, DMA_TO_DEVICE);
1014 buffer_info->dma = 0;
1016 if (buffer_info->skb) {
1017 dev_kfree_skb_any(buffer_info->skb);
1018 buffer_info->skb = NULL;
1020 buffer_info->time_stamp = 0;
1023 static void e1000_print_hw_hang(struct work_struct *work)
1025 struct e1000_adapter *adapter = container_of(work,
1026 struct e1000_adapter,
1027 print_hang_task);
1028 struct net_device *netdev = adapter->netdev;
1029 struct e1000_ring *tx_ring = adapter->tx_ring;
1030 unsigned int i = tx_ring->next_to_clean;
1031 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1032 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
1033 struct e1000_hw *hw = &adapter->hw;
1034 u16 phy_status, phy_1000t_status, phy_ext_status;
1035 u16 pci_status;
1037 if (test_bit(__E1000_DOWN, &adapter->state))
1038 return;
1040 if (!adapter->tx_hang_recheck &&
1041 (adapter->flags2 & FLAG2_DMA_BURST)) {
1042 /* May be block on write-back, flush and detect again
1043 * flush pending descriptor writebacks to memory
1045 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1046 /* execute the writes immediately */
1047 e1e_flush();
1048 adapter->tx_hang_recheck = true;
1049 return;
1051 /* Real hang detected */
1052 adapter->tx_hang_recheck = false;
1053 netif_stop_queue(netdev);
1055 e1e_rphy(hw, PHY_STATUS, &phy_status);
1056 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1057 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1059 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1061 /* detected Hardware unit hang */
1062 e_err("Detected Hardware Unit Hang:\n"
1063 " TDH <%x>\n"
1064 " TDT <%x>\n"
1065 " next_to_use <%x>\n"
1066 " next_to_clean <%x>\n"
1067 "buffer_info[next_to_clean]:\n"
1068 " time_stamp <%lx>\n"
1069 " next_to_watch <%x>\n"
1070 " jiffies <%lx>\n"
1071 " next_to_watch.status <%x>\n"
1072 "MAC Status <%x>\n"
1073 "PHY Status <%x>\n"
1074 "PHY 1000BASE-T Status <%x>\n"
1075 "PHY Extended Status <%x>\n"
1076 "PCI Status <%x>\n",
1077 readl(tx_ring->head),
1078 readl(tx_ring->tail),
1079 tx_ring->next_to_use,
1080 tx_ring->next_to_clean,
1081 tx_ring->buffer_info[eop].time_stamp,
1082 eop,
1083 jiffies,
1084 eop_desc->upper.fields.status,
1085 er32(STATUS),
1086 phy_status,
1087 phy_1000t_status,
1088 phy_ext_status,
1089 pci_status);
1093 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1094 * @tx_ring: Tx descriptor ring
1096 * the return value indicates whether actual cleaning was done, there
1097 * is no guarantee that everything was cleaned
1099 static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
1101 struct e1000_adapter *adapter = tx_ring->adapter;
1102 struct net_device *netdev = adapter->netdev;
1103 struct e1000_hw *hw = &adapter->hw;
1104 struct e1000_tx_desc *tx_desc, *eop_desc;
1105 struct e1000_buffer *buffer_info;
1106 unsigned int i, eop;
1107 unsigned int count = 0;
1108 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1109 unsigned int bytes_compl = 0, pkts_compl = 0;
1111 i = tx_ring->next_to_clean;
1112 eop = tx_ring->buffer_info[i].next_to_watch;
1113 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1115 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1116 (count < tx_ring->count)) {
1117 bool cleaned = false;
1118 rmb(); /* read buffer_info after eop_desc */
1119 for (; !cleaned; count++) {
1120 tx_desc = E1000_TX_DESC(*tx_ring, i);
1121 buffer_info = &tx_ring->buffer_info[i];
1122 cleaned = (i == eop);
1124 if (cleaned) {
1125 total_tx_packets += buffer_info->segs;
1126 total_tx_bytes += buffer_info->bytecount;
1127 if (buffer_info->skb) {
1128 bytes_compl += buffer_info->skb->len;
1129 pkts_compl++;
1133 e1000_put_txbuf(tx_ring, buffer_info);
1134 tx_desc->upper.data = 0;
1136 i++;
1137 if (i == tx_ring->count)
1138 i = 0;
1141 if (i == tx_ring->next_to_use)
1142 break;
1143 eop = tx_ring->buffer_info[i].next_to_watch;
1144 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1147 tx_ring->next_to_clean = i;
1149 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1151 #define TX_WAKE_THRESHOLD 32
1152 if (count && netif_carrier_ok(netdev) &&
1153 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
1154 /* Make sure that anybody stopping the queue after this
1155 * sees the new next_to_clean.
1157 smp_mb();
1159 if (netif_queue_stopped(netdev) &&
1160 !(test_bit(__E1000_DOWN, &adapter->state))) {
1161 netif_wake_queue(netdev);
1162 ++adapter->restart_queue;
1166 if (adapter->detect_tx_hung) {
1168 * Detect a transmit hang in hardware, this serializes the
1169 * check with the clearing of time_stamp and movement of i
1171 adapter->detect_tx_hung = false;
1172 if (tx_ring->buffer_info[i].time_stamp &&
1173 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
1174 + (adapter->tx_timeout_factor * HZ)) &&
1175 !(er32(STATUS) & E1000_STATUS_TXOFF))
1176 schedule_work(&adapter->print_hang_task);
1177 else
1178 adapter->tx_hang_recheck = false;
1180 adapter->total_tx_bytes += total_tx_bytes;
1181 adapter->total_tx_packets += total_tx_packets;
1182 return count < tx_ring->count;
1186 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1187 * @rx_ring: Rx descriptor ring
1189 * the return value indicates whether actual cleaning was done, there
1190 * is no guarantee that everything was cleaned
1192 static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1193 int work_to_do)
1195 struct e1000_adapter *adapter = rx_ring->adapter;
1196 struct e1000_hw *hw = &adapter->hw;
1197 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1198 struct net_device *netdev = adapter->netdev;
1199 struct pci_dev *pdev = adapter->pdev;
1200 struct e1000_buffer *buffer_info, *next_buffer;
1201 struct e1000_ps_page *ps_page;
1202 struct sk_buff *skb;
1203 unsigned int i, j;
1204 u32 length, staterr;
1205 int cleaned_count = 0;
1206 bool cleaned = false;
1207 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1209 i = rx_ring->next_to_clean;
1210 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1211 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1212 buffer_info = &rx_ring->buffer_info[i];
1214 while (staterr & E1000_RXD_STAT_DD) {
1215 if (*work_done >= work_to_do)
1216 break;
1217 (*work_done)++;
1218 skb = buffer_info->skb;
1219 rmb(); /* read descriptor and rx_buffer_info after status DD */
1221 /* in the packet split case this is header only */
1222 prefetch(skb->data - NET_IP_ALIGN);
1224 i++;
1225 if (i == rx_ring->count)
1226 i = 0;
1227 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1228 prefetch(next_rxd);
1230 next_buffer = &rx_ring->buffer_info[i];
1232 cleaned = true;
1233 cleaned_count++;
1234 dma_unmap_single(&pdev->dev, buffer_info->dma,
1235 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
1236 buffer_info->dma = 0;
1238 /* see !EOP comment in other Rx routine */
1239 if (!(staterr & E1000_RXD_STAT_EOP))
1240 adapter->flags2 |= FLAG2_IS_DISCARDING;
1242 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
1243 e_dbg("Packet Split buffers didn't pick up the full packet\n");
1244 dev_kfree_skb_irq(skb);
1245 if (staterr & E1000_RXD_STAT_EOP)
1246 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1247 goto next_desc;
1250 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1251 dev_kfree_skb_irq(skb);
1252 goto next_desc;
1255 length = le16_to_cpu(rx_desc->wb.middle.length0);
1257 if (!length) {
1258 e_dbg("Last part of the packet spanning multiple descriptors\n");
1259 dev_kfree_skb_irq(skb);
1260 goto next_desc;
1263 /* Good Receive */
1264 skb_put(skb, length);
1268 * this looks ugly, but it seems compiler issues make
1269 * it more efficient than reusing j
1271 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1274 * page alloc/put takes too long and effects small
1275 * packet throughput, so unsplit small packets and
1276 * save the alloc/put only valid in softirq (napi)
1277 * context to call kmap_*
1279 if (l1 && (l1 <= copybreak) &&
1280 ((length + l1) <= adapter->rx_ps_bsize0)) {
1281 u8 *vaddr;
1283 ps_page = &buffer_info->ps_pages[0];
1286 * there is no documentation about how to call
1287 * kmap_atomic, so we can't hold the mapping
1288 * very long
1290 dma_sync_single_for_cpu(&pdev->dev,
1291 ps_page->dma,
1292 PAGE_SIZE,
1293 DMA_FROM_DEVICE);
1294 vaddr = kmap_atomic(ps_page->page,
1295 KM_SKB_DATA_SOFTIRQ);
1296 memcpy(skb_tail_pointer(skb), vaddr, l1);
1297 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
1298 dma_sync_single_for_device(&pdev->dev,
1299 ps_page->dma,
1300 PAGE_SIZE,
1301 DMA_FROM_DEVICE);
1303 /* remove the CRC */
1304 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1305 l1 -= 4;
1307 skb_put(skb, l1);
1308 goto copydone;
1309 } /* if */
1312 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1313 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1314 if (!length)
1315 break;
1317 ps_page = &buffer_info->ps_pages[j];
1318 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1319 DMA_FROM_DEVICE);
1320 ps_page->dma = 0;
1321 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1322 ps_page->page = NULL;
1323 skb->len += length;
1324 skb->data_len += length;
1325 skb->truesize += PAGE_SIZE;
1328 /* strip the ethernet crc, problem is we're using pages now so
1329 * this whole operation can get a little cpu intensive
1331 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1332 pskb_trim(skb, skb->len - 4);
1334 copydone:
1335 total_rx_bytes += skb->len;
1336 total_rx_packets++;
1338 e1000_rx_checksum(adapter, staterr,
1339 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1341 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1343 if (rx_desc->wb.upper.header_status &
1344 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1345 adapter->rx_hdr_split++;
1347 e1000_receive_skb(adapter, netdev, skb,
1348 staterr, rx_desc->wb.middle.vlan);
1350 next_desc:
1351 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1352 buffer_info->skb = NULL;
1354 /* return some buffers to hardware, one at a time is too slow */
1355 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1356 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1357 GFP_ATOMIC);
1358 cleaned_count = 0;
1361 /* use prefetched values */
1362 rx_desc = next_rxd;
1363 buffer_info = next_buffer;
1365 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1367 rx_ring->next_to_clean = i;
1369 cleaned_count = e1000_desc_unused(rx_ring);
1370 if (cleaned_count)
1371 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1373 adapter->total_rx_bytes += total_rx_bytes;
1374 adapter->total_rx_packets += total_rx_packets;
1375 return cleaned;
1379 * e1000_consume_page - helper function
1381 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1382 u16 length)
1384 bi->page = NULL;
1385 skb->len += length;
1386 skb->data_len += length;
1387 skb->truesize += PAGE_SIZE;
1391 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1392 * @adapter: board private structure
1394 * the return value indicates whether actual cleaning was done, there
1395 * is no guarantee that everything was cleaned
1397 static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1398 int work_to_do)
1400 struct e1000_adapter *adapter = rx_ring->adapter;
1401 struct net_device *netdev = adapter->netdev;
1402 struct pci_dev *pdev = adapter->pdev;
1403 union e1000_rx_desc_extended *rx_desc, *next_rxd;
1404 struct e1000_buffer *buffer_info, *next_buffer;
1405 u32 length, staterr;
1406 unsigned int i;
1407 int cleaned_count = 0;
1408 bool cleaned = false;
1409 unsigned int total_rx_bytes=0, total_rx_packets=0;
1411 i = rx_ring->next_to_clean;
1412 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1413 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1414 buffer_info = &rx_ring->buffer_info[i];
1416 while (staterr & E1000_RXD_STAT_DD) {
1417 struct sk_buff *skb;
1419 if (*work_done >= work_to_do)
1420 break;
1421 (*work_done)++;
1422 rmb(); /* read descriptor and rx_buffer_info after status DD */
1424 skb = buffer_info->skb;
1425 buffer_info->skb = NULL;
1427 ++i;
1428 if (i == rx_ring->count)
1429 i = 0;
1430 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
1431 prefetch(next_rxd);
1433 next_buffer = &rx_ring->buffer_info[i];
1435 cleaned = true;
1436 cleaned_count++;
1437 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1438 DMA_FROM_DEVICE);
1439 buffer_info->dma = 0;
1441 length = le16_to_cpu(rx_desc->wb.upper.length);
1443 /* errors is only valid for DD + EOP descriptors */
1444 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1445 (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
1446 /* recycle both page and skb */
1447 buffer_info->skb = skb;
1448 /* an error means any chain goes out the window too */
1449 if (rx_ring->rx_skb_top)
1450 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1451 rx_ring->rx_skb_top = NULL;
1452 goto next_desc;
1455 #define rxtop (rx_ring->rx_skb_top)
1456 if (!(staterr & E1000_RXD_STAT_EOP)) {
1457 /* this descriptor is only the beginning (or middle) */
1458 if (!rxtop) {
1459 /* this is the beginning of a chain */
1460 rxtop = skb;
1461 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1462 0, length);
1463 } else {
1464 /* this is the middle of a chain */
1465 skb_fill_page_desc(rxtop,
1466 skb_shinfo(rxtop)->nr_frags,
1467 buffer_info->page, 0, length);
1468 /* re-use the skb, only consumed the page */
1469 buffer_info->skb = skb;
1471 e1000_consume_page(buffer_info, rxtop, length);
1472 goto next_desc;
1473 } else {
1474 if (rxtop) {
1475 /* end of the chain */
1476 skb_fill_page_desc(rxtop,
1477 skb_shinfo(rxtop)->nr_frags,
1478 buffer_info->page, 0, length);
1479 /* re-use the current skb, we only consumed the
1480 * page */
1481 buffer_info->skb = skb;
1482 skb = rxtop;
1483 rxtop = NULL;
1484 e1000_consume_page(buffer_info, skb, length);
1485 } else {
1486 /* no chain, got EOP, this buf is the packet
1487 * copybreak to save the put_page/alloc_page */
1488 if (length <= copybreak &&
1489 skb_tailroom(skb) >= length) {
1490 u8 *vaddr;
1491 vaddr = kmap_atomic(buffer_info->page,
1492 KM_SKB_DATA_SOFTIRQ);
1493 memcpy(skb_tail_pointer(skb), vaddr,
1494 length);
1495 kunmap_atomic(vaddr,
1496 KM_SKB_DATA_SOFTIRQ);
1497 /* re-use the page, so don't erase
1498 * buffer_info->page */
1499 skb_put(skb, length);
1500 } else {
1501 skb_fill_page_desc(skb, 0,
1502 buffer_info->page, 0,
1503 length);
1504 e1000_consume_page(buffer_info, skb,
1505 length);
1510 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1511 e1000_rx_checksum(adapter, staterr,
1512 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1514 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1516 /* probably a little skewed due to removing CRC */
1517 total_rx_bytes += skb->len;
1518 total_rx_packets++;
1520 /* eth type trans needs skb->data to point to something */
1521 if (!pskb_may_pull(skb, ETH_HLEN)) {
1522 e_err("pskb_may_pull failed.\n");
1523 dev_kfree_skb_irq(skb);
1524 goto next_desc;
1527 e1000_receive_skb(adapter, netdev, skb, staterr,
1528 rx_desc->wb.upper.vlan);
1530 next_desc:
1531 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
1533 /* return some buffers to hardware, one at a time is too slow */
1534 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1535 adapter->alloc_rx_buf(rx_ring, cleaned_count,
1536 GFP_ATOMIC);
1537 cleaned_count = 0;
1540 /* use prefetched values */
1541 rx_desc = next_rxd;
1542 buffer_info = next_buffer;
1544 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1546 rx_ring->next_to_clean = i;
1548 cleaned_count = e1000_desc_unused(rx_ring);
1549 if (cleaned_count)
1550 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
1552 adapter->total_rx_bytes += total_rx_bytes;
1553 adapter->total_rx_packets += total_rx_packets;
1554 return cleaned;
1558 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1559 * @rx_ring: Rx descriptor ring
1561 static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
1563 struct e1000_adapter *adapter = rx_ring->adapter;
1564 struct e1000_buffer *buffer_info;
1565 struct e1000_ps_page *ps_page;
1566 struct pci_dev *pdev = adapter->pdev;
1567 unsigned int i, j;
1569 /* Free all the Rx ring sk_buffs */
1570 for (i = 0; i < rx_ring->count; i++) {
1571 buffer_info = &rx_ring->buffer_info[i];
1572 if (buffer_info->dma) {
1573 if (adapter->clean_rx == e1000_clean_rx_irq)
1574 dma_unmap_single(&pdev->dev, buffer_info->dma,
1575 adapter->rx_buffer_len,
1576 DMA_FROM_DEVICE);
1577 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1578 dma_unmap_page(&pdev->dev, buffer_info->dma,
1579 PAGE_SIZE,
1580 DMA_FROM_DEVICE);
1581 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1582 dma_unmap_single(&pdev->dev, buffer_info->dma,
1583 adapter->rx_ps_bsize0,
1584 DMA_FROM_DEVICE);
1585 buffer_info->dma = 0;
1588 if (buffer_info->page) {
1589 put_page(buffer_info->page);
1590 buffer_info->page = NULL;
1593 if (buffer_info->skb) {
1594 dev_kfree_skb(buffer_info->skb);
1595 buffer_info->skb = NULL;
1598 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1599 ps_page = &buffer_info->ps_pages[j];
1600 if (!ps_page->page)
1601 break;
1602 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1603 DMA_FROM_DEVICE);
1604 ps_page->dma = 0;
1605 put_page(ps_page->page);
1606 ps_page->page = NULL;
1610 /* there also may be some cached data from a chained receive */
1611 if (rx_ring->rx_skb_top) {
1612 dev_kfree_skb(rx_ring->rx_skb_top);
1613 rx_ring->rx_skb_top = NULL;
1616 /* Zero out the descriptor ring */
1617 memset(rx_ring->desc, 0, rx_ring->size);
1619 rx_ring->next_to_clean = 0;
1620 rx_ring->next_to_use = 0;
1621 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
1623 writel(0, rx_ring->head);
1624 writel(0, rx_ring->tail);
1627 static void e1000e_downshift_workaround(struct work_struct *work)
1629 struct e1000_adapter *adapter = container_of(work,
1630 struct e1000_adapter, downshift_task);
1632 if (test_bit(__E1000_DOWN, &adapter->state))
1633 return;
1635 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1639 * e1000_intr_msi - Interrupt Handler
1640 * @irq: interrupt number
1641 * @data: pointer to a network interface device structure
1643 static irqreturn_t e1000_intr_msi(int irq, void *data)
1645 struct net_device *netdev = data;
1646 struct e1000_adapter *adapter = netdev_priv(netdev);
1647 struct e1000_hw *hw = &adapter->hw;
1648 u32 icr = er32(ICR);
1651 * read ICR disables interrupts using IAM
1654 if (icr & E1000_ICR_LSC) {
1655 hw->mac.get_link_status = true;
1657 * ICH8 workaround-- Call gig speed drop workaround on cable
1658 * disconnect (LSC) before accessing any PHY registers
1660 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1661 (!(er32(STATUS) & E1000_STATUS_LU)))
1662 schedule_work(&adapter->downshift_task);
1665 * 80003ES2LAN workaround-- For packet buffer work-around on
1666 * link down event; disable receives here in the ISR and reset
1667 * adapter in watchdog
1669 if (netif_carrier_ok(netdev) &&
1670 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1671 /* disable receives */
1672 u32 rctl = er32(RCTL);
1673 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1674 adapter->flags |= FLAG_RX_RESTART_NOW;
1676 /* guard against interrupt when we're going down */
1677 if (!test_bit(__E1000_DOWN, &adapter->state))
1678 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1681 if (napi_schedule_prep(&adapter->napi)) {
1682 adapter->total_tx_bytes = 0;
1683 adapter->total_tx_packets = 0;
1684 adapter->total_rx_bytes = 0;
1685 adapter->total_rx_packets = 0;
1686 __napi_schedule(&adapter->napi);
1689 return IRQ_HANDLED;
1693 * e1000_intr - Interrupt Handler
1694 * @irq: interrupt number
1695 * @data: pointer to a network interface device structure
1697 static irqreturn_t e1000_intr(int irq, void *data)
1699 struct net_device *netdev = data;
1700 struct e1000_adapter *adapter = netdev_priv(netdev);
1701 struct e1000_hw *hw = &adapter->hw;
1702 u32 rctl, icr = er32(ICR);
1704 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
1705 return IRQ_NONE; /* Not our interrupt */
1708 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1709 * not set, then the adapter didn't send an interrupt
1711 if (!(icr & E1000_ICR_INT_ASSERTED))
1712 return IRQ_NONE;
1715 * Interrupt Auto-Mask...upon reading ICR,
1716 * interrupts are masked. No need for the
1717 * IMC write
1720 if (icr & E1000_ICR_LSC) {
1721 hw->mac.get_link_status = true;
1723 * ICH8 workaround-- Call gig speed drop workaround on cable
1724 * disconnect (LSC) before accessing any PHY registers
1726 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1727 (!(er32(STATUS) & E1000_STATUS_LU)))
1728 schedule_work(&adapter->downshift_task);
1731 * 80003ES2LAN workaround--
1732 * For packet buffer work-around on link down event;
1733 * disable receives here in the ISR and
1734 * reset adapter in watchdog
1736 if (netif_carrier_ok(netdev) &&
1737 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1738 /* disable receives */
1739 rctl = er32(RCTL);
1740 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1741 adapter->flags |= FLAG_RX_RESTART_NOW;
1743 /* guard against interrupt when we're going down */
1744 if (!test_bit(__E1000_DOWN, &adapter->state))
1745 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1748 if (napi_schedule_prep(&adapter->napi)) {
1749 adapter->total_tx_bytes = 0;
1750 adapter->total_tx_packets = 0;
1751 adapter->total_rx_bytes = 0;
1752 adapter->total_rx_packets = 0;
1753 __napi_schedule(&adapter->napi);
1756 return IRQ_HANDLED;
1759 static irqreturn_t e1000_msix_other(int irq, void *data)
1761 struct net_device *netdev = data;
1762 struct e1000_adapter *adapter = netdev_priv(netdev);
1763 struct e1000_hw *hw = &adapter->hw;
1764 u32 icr = er32(ICR);
1766 if (!(icr & E1000_ICR_INT_ASSERTED)) {
1767 if (!test_bit(__E1000_DOWN, &adapter->state))
1768 ew32(IMS, E1000_IMS_OTHER);
1769 return IRQ_NONE;
1772 if (icr & adapter->eiac_mask)
1773 ew32(ICS, (icr & adapter->eiac_mask));
1775 if (icr & E1000_ICR_OTHER) {
1776 if (!(icr & E1000_ICR_LSC))
1777 goto no_link_interrupt;
1778 hw->mac.get_link_status = true;
1779 /* guard against interrupt when we're going down */
1780 if (!test_bit(__E1000_DOWN, &adapter->state))
1781 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1784 no_link_interrupt:
1785 if (!test_bit(__E1000_DOWN, &adapter->state))
1786 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
1788 return IRQ_HANDLED;
1792 static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1794 struct net_device *netdev = data;
1795 struct e1000_adapter *adapter = netdev_priv(netdev);
1796 struct e1000_hw *hw = &adapter->hw;
1797 struct e1000_ring *tx_ring = adapter->tx_ring;
1800 adapter->total_tx_bytes = 0;
1801 adapter->total_tx_packets = 0;
1803 if (!e1000_clean_tx_irq(tx_ring))
1804 /* Ring was not completely cleaned, so fire another interrupt */
1805 ew32(ICS, tx_ring->ims_val);
1807 return IRQ_HANDLED;
1810 static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1812 struct net_device *netdev = data;
1813 struct e1000_adapter *adapter = netdev_priv(netdev);
1814 struct e1000_ring *rx_ring = adapter->rx_ring;
1816 /* Write the ITR value calculated at the end of the
1817 * previous interrupt.
1819 if (rx_ring->set_itr) {
1820 writel(1000000000 / (rx_ring->itr_val * 256),
1821 rx_ring->itr_register);
1822 rx_ring->set_itr = 0;
1825 if (napi_schedule_prep(&adapter->napi)) {
1826 adapter->total_rx_bytes = 0;
1827 adapter->total_rx_packets = 0;
1828 __napi_schedule(&adapter->napi);
1830 return IRQ_HANDLED;
1834 * e1000_configure_msix - Configure MSI-X hardware
1836 * e1000_configure_msix sets up the hardware to properly
1837 * generate MSI-X interrupts.
1839 static void e1000_configure_msix(struct e1000_adapter *adapter)
1841 struct e1000_hw *hw = &adapter->hw;
1842 struct e1000_ring *rx_ring = adapter->rx_ring;
1843 struct e1000_ring *tx_ring = adapter->tx_ring;
1844 int vector = 0;
1845 u32 ctrl_ext, ivar = 0;
1847 adapter->eiac_mask = 0;
1849 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1850 if (hw->mac.type == e1000_82574) {
1851 u32 rfctl = er32(RFCTL);
1852 rfctl |= E1000_RFCTL_ACK_DIS;
1853 ew32(RFCTL, rfctl);
1856 #define E1000_IVAR_INT_ALLOC_VALID 0x8
1857 /* Configure Rx vector */
1858 rx_ring->ims_val = E1000_IMS_RXQ0;
1859 adapter->eiac_mask |= rx_ring->ims_val;
1860 if (rx_ring->itr_val)
1861 writel(1000000000 / (rx_ring->itr_val * 256),
1862 rx_ring->itr_register);
1863 else
1864 writel(1, rx_ring->itr_register);
1865 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1867 /* Configure Tx vector */
1868 tx_ring->ims_val = E1000_IMS_TXQ0;
1869 vector++;
1870 if (tx_ring->itr_val)
1871 writel(1000000000 / (tx_ring->itr_val * 256),
1872 tx_ring->itr_register);
1873 else
1874 writel(1, tx_ring->itr_register);
1875 adapter->eiac_mask |= tx_ring->ims_val;
1876 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1878 /* set vector for Other Causes, e.g. link changes */
1879 vector++;
1880 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1881 if (rx_ring->itr_val)
1882 writel(1000000000 / (rx_ring->itr_val * 256),
1883 hw->hw_addr + E1000_EITR_82574(vector));
1884 else
1885 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1887 /* Cause Tx interrupts on every write back */
1888 ivar |= (1 << 31);
1890 ew32(IVAR, ivar);
1892 /* enable MSI-X PBA support */
1893 ctrl_ext = er32(CTRL_EXT);
1894 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1896 /* Auto-Mask Other interrupts upon ICR read */
1897 #define E1000_EIAC_MASK_82574 0x01F00000
1898 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1899 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1900 ew32(CTRL_EXT, ctrl_ext);
1901 e1e_flush();
1904 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1906 if (adapter->msix_entries) {
1907 pci_disable_msix(adapter->pdev);
1908 kfree(adapter->msix_entries);
1909 adapter->msix_entries = NULL;
1910 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1911 pci_disable_msi(adapter->pdev);
1912 adapter->flags &= ~FLAG_MSI_ENABLED;
1917 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1919 * Attempt to configure interrupts using the best available
1920 * capabilities of the hardware and kernel.
1922 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1924 int err;
1925 int i;
1927 switch (adapter->int_mode) {
1928 case E1000E_INT_MODE_MSIX:
1929 if (adapter->flags & FLAG_HAS_MSIX) {
1930 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1931 adapter->msix_entries = kcalloc(adapter->num_vectors,
1932 sizeof(struct msix_entry),
1933 GFP_KERNEL);
1934 if (adapter->msix_entries) {
1935 for (i = 0; i < adapter->num_vectors; i++)
1936 adapter->msix_entries[i].entry = i;
1938 err = pci_enable_msix(adapter->pdev,
1939 adapter->msix_entries,
1940 adapter->num_vectors);
1941 if (err == 0)
1942 return;
1944 /* MSI-X failed, so fall through and try MSI */
1945 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
1946 e1000e_reset_interrupt_capability(adapter);
1948 adapter->int_mode = E1000E_INT_MODE_MSI;
1949 /* Fall through */
1950 case E1000E_INT_MODE_MSI:
1951 if (!pci_enable_msi(adapter->pdev)) {
1952 adapter->flags |= FLAG_MSI_ENABLED;
1953 } else {
1954 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1955 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
1957 /* Fall through */
1958 case E1000E_INT_MODE_LEGACY:
1959 /* Don't do anything; this is the system default */
1960 break;
1963 /* store the number of vectors being used */
1964 adapter->num_vectors = 1;
1968 * e1000_request_msix - Initialize MSI-X interrupts
1970 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1971 * kernel.
1973 static int e1000_request_msix(struct e1000_adapter *adapter)
1975 struct net_device *netdev = adapter->netdev;
1976 int err = 0, vector = 0;
1978 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1979 snprintf(adapter->rx_ring->name,
1980 sizeof(adapter->rx_ring->name) - 1,
1981 "%s-rx-0", netdev->name);
1982 else
1983 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1984 err = request_irq(adapter->msix_entries[vector].vector,
1985 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
1986 netdev);
1987 if (err)
1988 goto out;
1989 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
1990 E1000_EITR_82574(vector);
1991 adapter->rx_ring->itr_val = adapter->itr;
1992 vector++;
1994 if (strlen(netdev->name) < (IFNAMSIZ - 5))
1995 snprintf(adapter->tx_ring->name,
1996 sizeof(adapter->tx_ring->name) - 1,
1997 "%s-tx-0", netdev->name);
1998 else
1999 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2000 err = request_irq(adapter->msix_entries[vector].vector,
2001 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
2002 netdev);
2003 if (err)
2004 goto out;
2005 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2006 E1000_EITR_82574(vector);
2007 adapter->tx_ring->itr_val = adapter->itr;
2008 vector++;
2010 err = request_irq(adapter->msix_entries[vector].vector,
2011 e1000_msix_other, 0, netdev->name, netdev);
2012 if (err)
2013 goto out;
2015 e1000_configure_msix(adapter);
2016 return 0;
2017 out:
2018 return err;
2022 * e1000_request_irq - initialize interrupts
2024 * Attempts to configure interrupts using the best available
2025 * capabilities of the hardware and kernel.
2027 static int e1000_request_irq(struct e1000_adapter *adapter)
2029 struct net_device *netdev = adapter->netdev;
2030 int err;
2032 if (adapter->msix_entries) {
2033 err = e1000_request_msix(adapter);
2034 if (!err)
2035 return err;
2036 /* fall back to MSI */
2037 e1000e_reset_interrupt_capability(adapter);
2038 adapter->int_mode = E1000E_INT_MODE_MSI;
2039 e1000e_set_interrupt_capability(adapter);
2041 if (adapter->flags & FLAG_MSI_ENABLED) {
2042 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
2043 netdev->name, netdev);
2044 if (!err)
2045 return err;
2047 /* fall back to legacy interrupt */
2048 e1000e_reset_interrupt_capability(adapter);
2049 adapter->int_mode = E1000E_INT_MODE_LEGACY;
2052 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
2053 netdev->name, netdev);
2054 if (err)
2055 e_err("Unable to allocate interrupt, Error: %d\n", err);
2057 return err;
2060 static void e1000_free_irq(struct e1000_adapter *adapter)
2062 struct net_device *netdev = adapter->netdev;
2064 if (adapter->msix_entries) {
2065 int vector = 0;
2067 free_irq(adapter->msix_entries[vector].vector, netdev);
2068 vector++;
2070 free_irq(adapter->msix_entries[vector].vector, netdev);
2071 vector++;
2073 /* Other Causes interrupt vector */
2074 free_irq(adapter->msix_entries[vector].vector, netdev);
2075 return;
2078 free_irq(adapter->pdev->irq, netdev);
2082 * e1000_irq_disable - Mask off interrupt generation on the NIC
2084 static void e1000_irq_disable(struct e1000_adapter *adapter)
2086 struct e1000_hw *hw = &adapter->hw;
2088 ew32(IMC, ~0);
2089 if (adapter->msix_entries)
2090 ew32(EIAC_82574, 0);
2091 e1e_flush();
2093 if (adapter->msix_entries) {
2094 int i;
2095 for (i = 0; i < adapter->num_vectors; i++)
2096 synchronize_irq(adapter->msix_entries[i].vector);
2097 } else {
2098 synchronize_irq(adapter->pdev->irq);
2103 * e1000_irq_enable - Enable default interrupt generation settings
2105 static void e1000_irq_enable(struct e1000_adapter *adapter)
2107 struct e1000_hw *hw = &adapter->hw;
2109 if (adapter->msix_entries) {
2110 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2111 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2112 } else {
2113 ew32(IMS, IMS_ENABLE_MASK);
2115 e1e_flush();
2119 * e1000e_get_hw_control - get control of the h/w from f/w
2120 * @adapter: address of board private structure
2122 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2123 * For ASF and Pass Through versions of f/w this means that
2124 * the driver is loaded. For AMT version (only with 82573)
2125 * of the f/w this means that the network i/f is open.
2127 void e1000e_get_hw_control(struct e1000_adapter *adapter)
2129 struct e1000_hw *hw = &adapter->hw;
2130 u32 ctrl_ext;
2131 u32 swsm;
2133 /* Let firmware know the driver has taken over */
2134 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2135 swsm = er32(SWSM);
2136 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2137 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2138 ctrl_ext = er32(CTRL_EXT);
2139 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2144 * e1000e_release_hw_control - release control of the h/w to f/w
2145 * @adapter: address of board private structure
2147 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
2148 * For ASF and Pass Through versions of f/w this means that the
2149 * driver is no longer loaded. For AMT version (only with 82573) i
2150 * of the f/w this means that the network i/f is closed.
2153 void e1000e_release_hw_control(struct e1000_adapter *adapter)
2155 struct e1000_hw *hw = &adapter->hw;
2156 u32 ctrl_ext;
2157 u32 swsm;
2159 /* Let firmware taken over control of h/w */
2160 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2161 swsm = er32(SWSM);
2162 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2163 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2164 ctrl_ext = er32(CTRL_EXT);
2165 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2170 * @e1000_alloc_ring - allocate memory for a ring structure
2172 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2173 struct e1000_ring *ring)
2175 struct pci_dev *pdev = adapter->pdev;
2177 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2178 GFP_KERNEL);
2179 if (!ring->desc)
2180 return -ENOMEM;
2182 return 0;
2186 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2187 * @tx_ring: Tx descriptor ring
2189 * Return 0 on success, negative on failure
2191 int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
2193 struct e1000_adapter *adapter = tx_ring->adapter;
2194 int err = -ENOMEM, size;
2196 size = sizeof(struct e1000_buffer) * tx_ring->count;
2197 tx_ring->buffer_info = vzalloc(size);
2198 if (!tx_ring->buffer_info)
2199 goto err;
2201 /* round up to nearest 4K */
2202 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2203 tx_ring->size = ALIGN(tx_ring->size, 4096);
2205 err = e1000_alloc_ring_dma(adapter, tx_ring);
2206 if (err)
2207 goto err;
2209 tx_ring->next_to_use = 0;
2210 tx_ring->next_to_clean = 0;
2212 return 0;
2213 err:
2214 vfree(tx_ring->buffer_info);
2215 e_err("Unable to allocate memory for the transmit descriptor ring\n");
2216 return err;
2220 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2221 * @rx_ring: Rx descriptor ring
2223 * Returns 0 on success, negative on failure
2225 int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
2227 struct e1000_adapter *adapter = rx_ring->adapter;
2228 struct e1000_buffer *buffer_info;
2229 int i, size, desc_len, err = -ENOMEM;
2231 size = sizeof(struct e1000_buffer) * rx_ring->count;
2232 rx_ring->buffer_info = vzalloc(size);
2233 if (!rx_ring->buffer_info)
2234 goto err;
2236 for (i = 0; i < rx_ring->count; i++) {
2237 buffer_info = &rx_ring->buffer_info[i];
2238 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2239 sizeof(struct e1000_ps_page),
2240 GFP_KERNEL);
2241 if (!buffer_info->ps_pages)
2242 goto err_pages;
2245 desc_len = sizeof(union e1000_rx_desc_packet_split);
2247 /* Round up to nearest 4K */
2248 rx_ring->size = rx_ring->count * desc_len;
2249 rx_ring->size = ALIGN(rx_ring->size, 4096);
2251 err = e1000_alloc_ring_dma(adapter, rx_ring);
2252 if (err)
2253 goto err_pages;
2255 rx_ring->next_to_clean = 0;
2256 rx_ring->next_to_use = 0;
2257 rx_ring->rx_skb_top = NULL;
2259 return 0;
2261 err_pages:
2262 for (i = 0; i < rx_ring->count; i++) {
2263 buffer_info = &rx_ring->buffer_info[i];
2264 kfree(buffer_info->ps_pages);
2266 err:
2267 vfree(rx_ring->buffer_info);
2268 e_err("Unable to allocate memory for the receive descriptor ring\n");
2269 return err;
2273 * e1000_clean_tx_ring - Free Tx Buffers
2274 * @tx_ring: Tx descriptor ring
2276 static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
2278 struct e1000_adapter *adapter = tx_ring->adapter;
2279 struct e1000_buffer *buffer_info;
2280 unsigned long size;
2281 unsigned int i;
2283 for (i = 0; i < tx_ring->count; i++) {
2284 buffer_info = &tx_ring->buffer_info[i];
2285 e1000_put_txbuf(tx_ring, buffer_info);
2288 netdev_reset_queue(adapter->netdev);
2289 size = sizeof(struct e1000_buffer) * tx_ring->count;
2290 memset(tx_ring->buffer_info, 0, size);
2292 memset(tx_ring->desc, 0, tx_ring->size);
2294 tx_ring->next_to_use = 0;
2295 tx_ring->next_to_clean = 0;
2297 writel(0, tx_ring->head);
2298 writel(0, tx_ring->tail);
2302 * e1000e_free_tx_resources - Free Tx Resources per Queue
2303 * @tx_ring: Tx descriptor ring
2305 * Free all transmit software resources
2307 void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
2309 struct e1000_adapter *adapter = tx_ring->adapter;
2310 struct pci_dev *pdev = adapter->pdev;
2312 e1000_clean_tx_ring(tx_ring);
2314 vfree(tx_ring->buffer_info);
2315 tx_ring->buffer_info = NULL;
2317 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2318 tx_ring->dma);
2319 tx_ring->desc = NULL;
2323 * e1000e_free_rx_resources - Free Rx Resources
2324 * @rx_ring: Rx descriptor ring
2326 * Free all receive software resources
2328 void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
2330 struct e1000_adapter *adapter = rx_ring->adapter;
2331 struct pci_dev *pdev = adapter->pdev;
2332 int i;
2334 e1000_clean_rx_ring(rx_ring);
2336 for (i = 0; i < rx_ring->count; i++)
2337 kfree(rx_ring->buffer_info[i].ps_pages);
2339 vfree(rx_ring->buffer_info);
2340 rx_ring->buffer_info = NULL;
2342 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2343 rx_ring->dma);
2344 rx_ring->desc = NULL;
2348 * e1000_update_itr - update the dynamic ITR value based on statistics
2349 * @adapter: pointer to adapter
2350 * @itr_setting: current adapter->itr
2351 * @packets: the number of packets during this measurement interval
2352 * @bytes: the number of bytes during this measurement interval
2354 * Stores a new ITR value based on packets and byte
2355 * counts during the last interrupt. The advantage of per interrupt
2356 * computation is faster updates and more accurate ITR for the current
2357 * traffic pattern. Constants in this function were computed
2358 * based on theoretical maximum wire speed and thresholds were set based
2359 * on testing data as well as attempting to minimize response time
2360 * while increasing bulk throughput. This functionality is controlled
2361 * by the InterruptThrottleRate module parameter.
2363 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2364 u16 itr_setting, int packets,
2365 int bytes)
2367 unsigned int retval = itr_setting;
2369 if (packets == 0)
2370 goto update_itr_done;
2372 switch (itr_setting) {
2373 case lowest_latency:
2374 /* handle TSO and jumbo frames */
2375 if (bytes/packets > 8000)
2376 retval = bulk_latency;
2377 else if ((packets < 5) && (bytes > 512))
2378 retval = low_latency;
2379 break;
2380 case low_latency: /* 50 usec aka 20000 ints/s */
2381 if (bytes > 10000) {
2382 /* this if handles the TSO accounting */
2383 if (bytes/packets > 8000)
2384 retval = bulk_latency;
2385 else if ((packets < 10) || ((bytes/packets) > 1200))
2386 retval = bulk_latency;
2387 else if ((packets > 35))
2388 retval = lowest_latency;
2389 } else if (bytes/packets > 2000) {
2390 retval = bulk_latency;
2391 } else if (packets <= 2 && bytes < 512) {
2392 retval = lowest_latency;
2394 break;
2395 case bulk_latency: /* 250 usec aka 4000 ints/s */
2396 if (bytes > 25000) {
2397 if (packets > 35)
2398 retval = low_latency;
2399 } else if (bytes < 6000) {
2400 retval = low_latency;
2402 break;
2405 update_itr_done:
2406 return retval;
2409 static void e1000_set_itr(struct e1000_adapter *adapter)
2411 struct e1000_hw *hw = &adapter->hw;
2412 u16 current_itr;
2413 u32 new_itr = adapter->itr;
2415 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2416 if (adapter->link_speed != SPEED_1000) {
2417 current_itr = 0;
2418 new_itr = 4000;
2419 goto set_itr_now;
2422 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2423 new_itr = 0;
2424 goto set_itr_now;
2427 adapter->tx_itr = e1000_update_itr(adapter,
2428 adapter->tx_itr,
2429 adapter->total_tx_packets,
2430 adapter->total_tx_bytes);
2431 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2432 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2433 adapter->tx_itr = low_latency;
2435 adapter->rx_itr = e1000_update_itr(adapter,
2436 adapter->rx_itr,
2437 adapter->total_rx_packets,
2438 adapter->total_rx_bytes);
2439 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2440 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2441 adapter->rx_itr = low_latency;
2443 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2445 switch (current_itr) {
2446 /* counts and packets in update_itr are dependent on these numbers */
2447 case lowest_latency:
2448 new_itr = 70000;
2449 break;
2450 case low_latency:
2451 new_itr = 20000; /* aka hwitr = ~200 */
2452 break;
2453 case bulk_latency:
2454 new_itr = 4000;
2455 break;
2456 default:
2457 break;
2460 set_itr_now:
2461 if (new_itr != adapter->itr) {
2463 * this attempts to bias the interrupt rate towards Bulk
2464 * by adding intermediate steps when interrupt rate is
2465 * increasing
2467 new_itr = new_itr > adapter->itr ?
2468 min(adapter->itr + (new_itr >> 2), new_itr) :
2469 new_itr;
2470 adapter->itr = new_itr;
2471 adapter->rx_ring->itr_val = new_itr;
2472 if (adapter->msix_entries)
2473 adapter->rx_ring->set_itr = 1;
2474 else
2475 if (new_itr)
2476 ew32(ITR, 1000000000 / (new_itr * 256));
2477 else
2478 ew32(ITR, 0);
2483 * e1000_alloc_queues - Allocate memory for all rings
2484 * @adapter: board private structure to initialize
2486 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2488 int size = sizeof(struct e1000_ring);
2490 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
2491 if (!adapter->tx_ring)
2492 goto err;
2493 adapter->tx_ring->count = adapter->tx_ring_count;
2494 adapter->tx_ring->adapter = adapter;
2496 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
2497 if (!adapter->rx_ring)
2498 goto err;
2499 adapter->rx_ring->count = adapter->rx_ring_count;
2500 adapter->rx_ring->adapter = adapter;
2502 return 0;
2503 err:
2504 e_err("Unable to allocate memory for queues\n");
2505 kfree(adapter->rx_ring);
2506 kfree(adapter->tx_ring);
2507 return -ENOMEM;
2511 * e1000_clean - NAPI Rx polling callback
2512 * @napi: struct associated with this polling callback
2513 * @budget: amount of packets driver is allowed to process this poll
2515 static int e1000_clean(struct napi_struct *napi, int budget)
2517 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
2518 struct e1000_hw *hw = &adapter->hw;
2519 struct net_device *poll_dev = adapter->netdev;
2520 int tx_cleaned = 1, work_done = 0;
2522 adapter = netdev_priv(poll_dev);
2524 if (adapter->msix_entries &&
2525 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2526 goto clean_rx;
2528 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
2530 clean_rx:
2531 adapter->clean_rx(adapter->rx_ring, &work_done, budget);
2533 if (!tx_cleaned)
2534 work_done = budget;
2536 /* If budget not fully consumed, exit the polling mode */
2537 if (work_done < budget) {
2538 if (adapter->itr_setting & 3)
2539 e1000_set_itr(adapter);
2540 napi_complete(napi);
2541 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2542 if (adapter->msix_entries)
2543 ew32(IMS, adapter->rx_ring->ims_val);
2544 else
2545 e1000_irq_enable(adapter);
2549 return work_done;
2552 static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2554 struct e1000_adapter *adapter = netdev_priv(netdev);
2555 struct e1000_hw *hw = &adapter->hw;
2556 u32 vfta, index;
2558 /* don't update vlan cookie if already programmed */
2559 if ((adapter->hw.mng_cookie.status &
2560 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2561 (vid == adapter->mng_vlan_id))
2562 return 0;
2564 /* add VID to filter table */
2565 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2566 index = (vid >> 5) & 0x7F;
2567 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2568 vfta |= (1 << (vid & 0x1F));
2569 hw->mac.ops.write_vfta(hw, index, vfta);
2572 set_bit(vid, adapter->active_vlans);
2574 return 0;
2577 static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2579 struct e1000_adapter *adapter = netdev_priv(netdev);
2580 struct e1000_hw *hw = &adapter->hw;
2581 u32 vfta, index;
2583 if ((adapter->hw.mng_cookie.status &
2584 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2585 (vid == adapter->mng_vlan_id)) {
2586 /* release control to f/w */
2587 e1000e_release_hw_control(adapter);
2588 return 0;
2591 /* remove VID from filter table */
2592 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2593 index = (vid >> 5) & 0x7F;
2594 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2595 vfta &= ~(1 << (vid & 0x1F));
2596 hw->mac.ops.write_vfta(hw, index, vfta);
2599 clear_bit(vid, adapter->active_vlans);
2601 return 0;
2605 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2606 * @adapter: board private structure to initialize
2608 static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2610 struct net_device *netdev = adapter->netdev;
2611 struct e1000_hw *hw = &adapter->hw;
2612 u32 rctl;
2614 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2615 /* disable VLAN receive filtering */
2616 rctl = er32(RCTL);
2617 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2618 ew32(RCTL, rctl);
2620 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2621 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2622 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2628 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2629 * @adapter: board private structure to initialize
2631 static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2633 struct e1000_hw *hw = &adapter->hw;
2634 u32 rctl;
2636 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2637 /* enable VLAN receive filtering */
2638 rctl = er32(RCTL);
2639 rctl |= E1000_RCTL_VFE;
2640 rctl &= ~E1000_RCTL_CFIEN;
2641 ew32(RCTL, rctl);
2646 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2647 * @adapter: board private structure to initialize
2649 static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2651 struct e1000_hw *hw = &adapter->hw;
2652 u32 ctrl;
2654 /* disable VLAN tag insert/strip */
2655 ctrl = er32(CTRL);
2656 ctrl &= ~E1000_CTRL_VME;
2657 ew32(CTRL, ctrl);
2661 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2662 * @adapter: board private structure to initialize
2664 static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2666 struct e1000_hw *hw = &adapter->hw;
2667 u32 ctrl;
2669 /* enable VLAN tag insert/strip */
2670 ctrl = er32(CTRL);
2671 ctrl |= E1000_CTRL_VME;
2672 ew32(CTRL, ctrl);
2675 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2677 struct net_device *netdev = adapter->netdev;
2678 u16 vid = adapter->hw.mng_cookie.vlan_id;
2679 u16 old_vid = adapter->mng_vlan_id;
2681 if (adapter->hw.mng_cookie.status &
2682 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2683 e1000_vlan_rx_add_vid(netdev, vid);
2684 adapter->mng_vlan_id = vid;
2687 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2688 e1000_vlan_rx_kill_vid(netdev, old_vid);
2691 static void e1000_restore_vlan(struct e1000_adapter *adapter)
2693 u16 vid;
2695 e1000_vlan_rx_add_vid(adapter->netdev, 0);
2697 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
2698 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2701 static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
2703 struct e1000_hw *hw = &adapter->hw;
2704 u32 manc, manc2h, mdef, i, j;
2706 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2707 return;
2709 manc = er32(MANC);
2712 * enable receiving management packets to the host. this will probably
2713 * generate destination unreachable messages from the host OS, but
2714 * the packets will be handled on SMBUS
2716 manc |= E1000_MANC_EN_MNG2HOST;
2717 manc2h = er32(MANC2H);
2719 switch (hw->mac.type) {
2720 default:
2721 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2722 break;
2723 case e1000_82574:
2724 case e1000_82583:
2726 * Check if IPMI pass-through decision filter already exists;
2727 * if so, enable it.
2729 for (i = 0, j = 0; i < 8; i++) {
2730 mdef = er32(MDEF(i));
2732 /* Ignore filters with anything other than IPMI ports */
2733 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2734 continue;
2736 /* Enable this decision filter in MANC2H */
2737 if (mdef)
2738 manc2h |= (1 << i);
2740 j |= mdef;
2743 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2744 break;
2746 /* Create new decision filter in an empty filter */
2747 for (i = 0, j = 0; i < 8; i++)
2748 if (er32(MDEF(i)) == 0) {
2749 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2750 E1000_MDEF_PORT_664));
2751 manc2h |= (1 << 1);
2752 j++;
2753 break;
2756 if (!j)
2757 e_warn("Unable to create IPMI pass-through filter\n");
2758 break;
2761 ew32(MANC2H, manc2h);
2762 ew32(MANC, manc);
2766 * e1000_configure_tx - Configure Transmit Unit after Reset
2767 * @adapter: board private structure
2769 * Configure the Tx unit of the MAC after a reset.
2771 static void e1000_configure_tx(struct e1000_adapter *adapter)
2773 struct e1000_hw *hw = &adapter->hw;
2774 struct e1000_ring *tx_ring = adapter->tx_ring;
2775 u64 tdba;
2776 u32 tdlen, tarc;
2778 /* Setup the HW Tx Head and Tail descriptor pointers */
2779 tdba = tx_ring->dma;
2780 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
2781 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
2782 ew32(TDBAH, (tdba >> 32));
2783 ew32(TDLEN, tdlen);
2784 ew32(TDH, 0);
2785 ew32(TDT, 0);
2786 tx_ring->head = adapter->hw.hw_addr + E1000_TDH;
2787 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT;
2789 /* Set the Tx Interrupt Delay register */
2790 ew32(TIDV, adapter->tx_int_delay);
2791 /* Tx irq moderation */
2792 ew32(TADV, adapter->tx_abs_int_delay);
2794 if (adapter->flags2 & FLAG2_DMA_BURST) {
2795 u32 txdctl = er32(TXDCTL(0));
2796 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2797 E1000_TXDCTL_WTHRESH);
2799 * set up some performance related parameters to encourage the
2800 * hardware to use the bus more efficiently in bursts, depends
2801 * on the tx_int_delay to be enabled,
2802 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2803 * hthresh = 1 ==> prefetch when one or more available
2804 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2805 * BEWARE: this seems to work but should be considered first if
2806 * there are Tx hangs or other Tx related bugs
2808 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2809 ew32(TXDCTL(0), txdctl);
2811 /* erratum work around: set txdctl the same for both queues */
2812 ew32(TXDCTL(1), er32(TXDCTL(0)));
2814 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
2815 tarc = er32(TARC(0));
2817 * set the speed mode bit, we'll clear it if we're not at
2818 * gigabit link later
2820 #define SPEED_MODE_BIT (1 << 21)
2821 tarc |= SPEED_MODE_BIT;
2822 ew32(TARC(0), tarc);
2825 /* errata: program both queues to unweighted RR */
2826 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
2827 tarc = er32(TARC(0));
2828 tarc |= 1;
2829 ew32(TARC(0), tarc);
2830 tarc = er32(TARC(1));
2831 tarc |= 1;
2832 ew32(TARC(1), tarc);
2835 /* Setup Transmit Descriptor Settings for eop descriptor */
2836 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2838 /* only set IDE if we are delaying interrupts using the timers */
2839 if (adapter->tx_int_delay)
2840 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2842 /* enable Report Status bit */
2843 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2845 e1000e_config_collision_dist(hw);
2849 * e1000_setup_rctl - configure the receive control registers
2850 * @adapter: Board private structure
2852 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2853 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2854 static void e1000_setup_rctl(struct e1000_adapter *adapter)
2856 struct e1000_hw *hw = &adapter->hw;
2857 u32 rctl, rfctl;
2858 u32 pages = 0;
2860 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2861 if (hw->mac.type == e1000_pch2lan) {
2862 s32 ret_val;
2864 if (adapter->netdev->mtu > ETH_DATA_LEN)
2865 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2866 else
2867 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
2869 if (ret_val)
2870 e_dbg("failed to enable jumbo frame workaround mode\n");
2873 /* Program MC offset vector base */
2874 rctl = er32(RCTL);
2875 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2876 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2877 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2878 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2880 /* Do not Store bad packets */
2881 rctl &= ~E1000_RCTL_SBP;
2883 /* Enable Long Packet receive */
2884 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2885 rctl &= ~E1000_RCTL_LPE;
2886 else
2887 rctl |= E1000_RCTL_LPE;
2889 /* Some systems expect that the CRC is included in SMBUS traffic. The
2890 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2891 * host memory when this is enabled
2893 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2894 rctl |= E1000_RCTL_SECRC;
2896 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2897 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2898 u16 phy_data;
2900 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2901 phy_data &= 0xfff8;
2902 phy_data |= (1 << 2);
2903 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2905 e1e_rphy(hw, 22, &phy_data);
2906 phy_data &= 0x0fff;
2907 phy_data |= (1 << 14);
2908 e1e_wphy(hw, 0x10, 0x2823);
2909 e1e_wphy(hw, 0x11, 0x0003);
2910 e1e_wphy(hw, 22, phy_data);
2913 /* Setup buffer sizes */
2914 rctl &= ~E1000_RCTL_SZ_4096;
2915 rctl |= E1000_RCTL_BSEX;
2916 switch (adapter->rx_buffer_len) {
2917 case 2048:
2918 default:
2919 rctl |= E1000_RCTL_SZ_2048;
2920 rctl &= ~E1000_RCTL_BSEX;
2921 break;
2922 case 4096:
2923 rctl |= E1000_RCTL_SZ_4096;
2924 break;
2925 case 8192:
2926 rctl |= E1000_RCTL_SZ_8192;
2927 break;
2928 case 16384:
2929 rctl |= E1000_RCTL_SZ_16384;
2930 break;
2933 /* Enable Extended Status in all Receive Descriptors */
2934 rfctl = er32(RFCTL);
2935 rfctl |= E1000_RFCTL_EXTEN;
2938 * 82571 and greater support packet-split where the protocol
2939 * header is placed in skb->data and the packet data is
2940 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2941 * In the case of a non-split, skb->data is linearly filled,
2942 * followed by the page buffers. Therefore, skb->data is
2943 * sized to hold the largest protocol header.
2945 * allocations using alloc_page take too long for regular MTU
2946 * so only enable packet split for jumbo frames
2948 * Using pages when the page size is greater than 16k wastes
2949 * a lot of memory, since we allocate 3 pages at all times
2950 * per packet.
2952 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2953 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
2954 adapter->rx_ps_pages = pages;
2955 else
2956 adapter->rx_ps_pages = 0;
2958 if (adapter->rx_ps_pages) {
2959 u32 psrctl = 0;
2962 * disable packet split support for IPv6 extension headers,
2963 * because some malformed IPv6 headers can hang the Rx
2965 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2966 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2968 /* Enable Packet split descriptors */
2969 rctl |= E1000_RCTL_DTYP_PS;
2971 psrctl |= adapter->rx_ps_bsize0 >>
2972 E1000_PSRCTL_BSIZE0_SHIFT;
2974 switch (adapter->rx_ps_pages) {
2975 case 3:
2976 psrctl |= PAGE_SIZE <<
2977 E1000_PSRCTL_BSIZE3_SHIFT;
2978 case 2:
2979 psrctl |= PAGE_SIZE <<
2980 E1000_PSRCTL_BSIZE2_SHIFT;
2981 case 1:
2982 psrctl |= PAGE_SIZE >>
2983 E1000_PSRCTL_BSIZE1_SHIFT;
2984 break;
2987 ew32(PSRCTL, psrctl);
2990 ew32(RFCTL, rfctl);
2991 ew32(RCTL, rctl);
2992 /* just started the receive unit, no need to restart */
2993 adapter->flags &= ~FLAG_RX_RESTART_NOW;
2997 * e1000_configure_rx - Configure Receive Unit after Reset
2998 * @adapter: board private structure
3000 * Configure the Rx unit of the MAC after a reset.
3002 static void e1000_configure_rx(struct e1000_adapter *adapter)
3004 struct e1000_hw *hw = &adapter->hw;
3005 struct e1000_ring *rx_ring = adapter->rx_ring;
3006 u64 rdba;
3007 u32 rdlen, rctl, rxcsum, ctrl_ext;
3009 if (adapter->rx_ps_pages) {
3010 /* this is a 32 byte descriptor */
3011 rdlen = rx_ring->count *
3012 sizeof(union e1000_rx_desc_packet_split);
3013 adapter->clean_rx = e1000_clean_rx_irq_ps;
3014 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
3015 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
3016 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3017 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3018 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
3019 } else {
3020 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
3021 adapter->clean_rx = e1000_clean_rx_irq;
3022 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3025 /* disable receives while setting up the descriptors */
3026 rctl = er32(RCTL);
3027 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3028 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3029 e1e_flush();
3030 usleep_range(10000, 20000);
3032 if (adapter->flags2 & FLAG2_DMA_BURST) {
3034 * set the writeback threshold (only takes effect if the RDTR
3035 * is set). set GRAN=1 and write back up to 0x4 worth, and
3036 * enable prefetching of 0x20 Rx descriptors
3037 * granularity = 01
3038 * wthresh = 04,
3039 * hthresh = 04,
3040 * pthresh = 0x20
3042 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3043 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3046 * override the delay timers for enabling bursting, only if
3047 * the value was not set by the user via module options
3049 if (adapter->rx_int_delay == DEFAULT_RDTR)
3050 adapter->rx_int_delay = BURST_RDTR;
3051 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3052 adapter->rx_abs_int_delay = BURST_RADV;
3055 /* set the Receive Delay Timer Register */
3056 ew32(RDTR, adapter->rx_int_delay);
3058 /* irq moderation */
3059 ew32(RADV, adapter->rx_abs_int_delay);
3060 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
3061 ew32(ITR, 1000000000 / (adapter->itr * 256));
3063 ctrl_ext = er32(CTRL_EXT);
3064 /* Auto-Mask interrupts upon ICR access */
3065 ctrl_ext |= E1000_CTRL_EXT_IAME;
3066 ew32(IAM, 0xffffffff);
3067 ew32(CTRL_EXT, ctrl_ext);
3068 e1e_flush();
3071 * Setup the HW Rx Head and Tail Descriptor Pointers and
3072 * the Base and Length of the Rx Descriptor Ring
3074 rdba = rx_ring->dma;
3075 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
3076 ew32(RDBAH, (rdba >> 32));
3077 ew32(RDLEN, rdlen);
3078 ew32(RDH, 0);
3079 ew32(RDT, 0);
3080 rx_ring->head = adapter->hw.hw_addr + E1000_RDH;
3081 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT;
3083 /* Enable Receive Checksum Offload for TCP and UDP */
3084 rxcsum = er32(RXCSUM);
3085 if (adapter->netdev->features & NETIF_F_RXCSUM) {
3086 rxcsum |= E1000_RXCSUM_TUOFL;
3089 * IPv4 payload checksum for UDP fragments must be
3090 * used in conjunction with packet-split.
3092 if (adapter->rx_ps_pages)
3093 rxcsum |= E1000_RXCSUM_IPPCSE;
3094 } else {
3095 rxcsum &= ~E1000_RXCSUM_TUOFL;
3096 /* no need to clear IPPCSE as it defaults to 0 */
3098 ew32(RXCSUM, rxcsum);
3100 if (adapter->hw.mac.type == e1000_pch2lan) {
3102 * With jumbo frames, excessive C-state transition
3103 * latencies result in dropped transactions.
3105 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3106 u32 rxdctl = er32(RXDCTL(0));
3107 ew32(RXDCTL(0), rxdctl | 0x3);
3108 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
3109 } else {
3110 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3111 PM_QOS_DEFAULT_VALUE);
3115 /* Enable Receives */
3116 ew32(RCTL, rctl);
3120 * e1000e_write_mc_addr_list - write multicast addresses to MTA
3121 * @netdev: network interface device structure
3123 * Writes multicast address list to the MTA hash table.
3124 * Returns: -ENOMEM on failure
3125 * 0 on no addresses written
3126 * X on writing X addresses to MTA
3128 static int e1000e_write_mc_addr_list(struct net_device *netdev)
3130 struct e1000_adapter *adapter = netdev_priv(netdev);
3131 struct e1000_hw *hw = &adapter->hw;
3132 struct netdev_hw_addr *ha;
3133 u8 *mta_list;
3134 int i;
3136 if (netdev_mc_empty(netdev)) {
3137 /* nothing to program, so clear mc list */
3138 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3139 return 0;
3142 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3143 if (!mta_list)
3144 return -ENOMEM;
3146 /* update_mc_addr_list expects a packed array of only addresses. */
3147 i = 0;
3148 netdev_for_each_mc_addr(ha, netdev)
3149 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3151 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3152 kfree(mta_list);
3154 return netdev_mc_count(netdev);
3158 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3159 * @netdev: network interface device structure
3161 * Writes unicast address list to the RAR table.
3162 * Returns: -ENOMEM on failure/insufficient address space
3163 * 0 on no addresses written
3164 * X on writing X addresses to the RAR table
3166 static int e1000e_write_uc_addr_list(struct net_device *netdev)
3168 struct e1000_adapter *adapter = netdev_priv(netdev);
3169 struct e1000_hw *hw = &adapter->hw;
3170 unsigned int rar_entries = hw->mac.rar_entry_count;
3171 int count = 0;
3173 /* save a rar entry for our hardware address */
3174 rar_entries--;
3176 /* save a rar entry for the LAA workaround */
3177 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3178 rar_entries--;
3180 /* return ENOMEM indicating insufficient memory for addresses */
3181 if (netdev_uc_count(netdev) > rar_entries)
3182 return -ENOMEM;
3184 if (!netdev_uc_empty(netdev) && rar_entries) {
3185 struct netdev_hw_addr *ha;
3188 * write the addresses in reverse order to avoid write
3189 * combining
3191 netdev_for_each_uc_addr(ha, netdev) {
3192 if (!rar_entries)
3193 break;
3194 e1000e_rar_set(hw, ha->addr, rar_entries--);
3195 count++;
3199 /* zero out the remaining RAR entries not used above */
3200 for (; rar_entries > 0; rar_entries--) {
3201 ew32(RAH(rar_entries), 0);
3202 ew32(RAL(rar_entries), 0);
3204 e1e_flush();
3206 return count;
3210 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3211 * @netdev: network interface device structure
3213 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3214 * address list or the network interface flags are updated. This routine is
3215 * responsible for configuring the hardware for proper unicast, multicast,
3216 * promiscuous mode, and all-multi behavior.
3218 static void e1000e_set_rx_mode(struct net_device *netdev)
3220 struct e1000_adapter *adapter = netdev_priv(netdev);
3221 struct e1000_hw *hw = &adapter->hw;
3222 u32 rctl;
3224 /* Check for Promiscuous and All Multicast modes */
3225 rctl = er32(RCTL);
3227 /* clear the affected bits */
3228 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3230 if (netdev->flags & IFF_PROMISC) {
3231 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
3232 /* Do not hardware filter VLANs in promisc mode */
3233 e1000e_vlan_filter_disable(adapter);
3234 } else {
3235 int count;
3236 if (netdev->flags & IFF_ALLMULTI) {
3237 rctl |= E1000_RCTL_MPE;
3238 } else {
3240 * Write addresses to the MTA, if the attempt fails
3241 * then we should just turn on promiscuous mode so
3242 * that we can at least receive multicast traffic
3244 count = e1000e_write_mc_addr_list(netdev);
3245 if (count < 0)
3246 rctl |= E1000_RCTL_MPE;
3248 e1000e_vlan_filter_enable(adapter);
3250 * Write addresses to available RAR registers, if there is not
3251 * sufficient space to store all the addresses then enable
3252 * unicast promiscuous mode
3254 count = e1000e_write_uc_addr_list(netdev);
3255 if (count < 0)
3256 rctl |= E1000_RCTL_UPE;
3259 ew32(RCTL, rctl);
3261 if (netdev->features & NETIF_F_HW_VLAN_RX)
3262 e1000e_vlan_strip_enable(adapter);
3263 else
3264 e1000e_vlan_strip_disable(adapter);
3267 static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3269 struct e1000_hw *hw = &adapter->hw;
3270 u32 mrqc, rxcsum;
3271 int i;
3272 static const u32 rsskey[10] = {
3273 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3274 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3277 /* Fill out hash function seed */
3278 for (i = 0; i < 10; i++)
3279 ew32(RSSRK(i), rsskey[i]);
3281 /* Direct all traffic to queue 0 */
3282 for (i = 0; i < 32; i++)
3283 ew32(RETA(i), 0);
3286 * Disable raw packet checksumming so that RSS hash is placed in
3287 * descriptor on writeback.
3289 rxcsum = er32(RXCSUM);
3290 rxcsum |= E1000_RXCSUM_PCSD;
3292 ew32(RXCSUM, rxcsum);
3294 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3295 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3296 E1000_MRQC_RSS_FIELD_IPV6 |
3297 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3298 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3300 ew32(MRQC, mrqc);
3304 * e1000_configure - configure the hardware for Rx and Tx
3305 * @adapter: private board structure
3307 static void e1000_configure(struct e1000_adapter *adapter)
3309 struct e1000_ring *rx_ring = adapter->rx_ring;
3311 e1000e_set_rx_mode(adapter->netdev);
3313 e1000_restore_vlan(adapter);
3314 e1000_init_manageability_pt(adapter);
3316 e1000_configure_tx(adapter);
3318 if (adapter->netdev->features & NETIF_F_RXHASH)
3319 e1000e_setup_rss_hash(adapter);
3320 e1000_setup_rctl(adapter);
3321 e1000_configure_rx(adapter);
3322 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
3326 * e1000e_power_up_phy - restore link in case the phy was powered down
3327 * @adapter: address of board private structure
3329 * The phy may be powered down to save power and turn off link when the
3330 * driver is unloaded and wake on lan is not enabled (among others)
3331 * *** this routine MUST be followed by a call to e1000e_reset ***
3333 void e1000e_power_up_phy(struct e1000_adapter *adapter)
3335 if (adapter->hw.phy.ops.power_up)
3336 adapter->hw.phy.ops.power_up(&adapter->hw);
3338 adapter->hw.mac.ops.setup_link(&adapter->hw);
3342 * e1000_power_down_phy - Power down the PHY
3344 * Power down the PHY so no link is implied when interface is down.
3345 * The PHY cannot be powered down if management or WoL is active.
3347 static void e1000_power_down_phy(struct e1000_adapter *adapter)
3349 /* WoL is enabled */
3350 if (adapter->wol)
3351 return;
3353 if (adapter->hw.phy.ops.power_down)
3354 adapter->hw.phy.ops.power_down(&adapter->hw);
3358 * e1000e_reset - bring the hardware into a known good state
3360 * This function boots the hardware and enables some settings that
3361 * require a configuration cycle of the hardware - those cannot be
3362 * set/changed during runtime. After reset the device needs to be
3363 * properly configured for Rx, Tx etc.
3365 void e1000e_reset(struct e1000_adapter *adapter)
3367 struct e1000_mac_info *mac = &adapter->hw.mac;
3368 struct e1000_fc_info *fc = &adapter->hw.fc;
3369 struct e1000_hw *hw = &adapter->hw;
3370 u32 tx_space, min_tx_space, min_rx_space;
3371 u32 pba = adapter->pba;
3372 u16 hwm;
3374 /* reset Packet Buffer Allocation to default */
3375 ew32(PBA, pba);
3377 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
3379 * To maintain wire speed transmits, the Tx FIFO should be
3380 * large enough to accommodate two full transmit packets,
3381 * rounded up to the next 1KB and expressed in KB. Likewise,
3382 * the Rx FIFO should be large enough to accommodate at least
3383 * one full receive packet and is similarly rounded up and
3384 * expressed in KB.
3386 pba = er32(PBA);
3387 /* upper 16 bits has Tx packet buffer allocation size in KB */
3388 tx_space = pba >> 16;
3389 /* lower 16 bits has Rx packet buffer allocation size in KB */
3390 pba &= 0xffff;
3392 * the Tx fifo also stores 16 bytes of information about the Tx
3393 * but don't include ethernet FCS because hardware appends it
3395 min_tx_space = (adapter->max_frame_size +
3396 sizeof(struct e1000_tx_desc) -
3397 ETH_FCS_LEN) * 2;
3398 min_tx_space = ALIGN(min_tx_space, 1024);
3399 min_tx_space >>= 10;
3400 /* software strips receive CRC, so leave room for it */
3401 min_rx_space = adapter->max_frame_size;
3402 min_rx_space = ALIGN(min_rx_space, 1024);
3403 min_rx_space >>= 10;
3406 * If current Tx allocation is less than the min Tx FIFO size,
3407 * and the min Tx FIFO size is less than the current Rx FIFO
3408 * allocation, take space away from current Rx allocation
3410 if ((tx_space < min_tx_space) &&
3411 ((min_tx_space - tx_space) < pba)) {
3412 pba -= min_tx_space - tx_space;
3415 * if short on Rx space, Rx wins and must trump Tx
3416 * adjustment or use Early Receive if available
3418 if (pba < min_rx_space)
3419 pba = min_rx_space;
3422 ew32(PBA, pba);
3426 * flow control settings
3428 * The high water mark must be low enough to fit one full frame
3429 * (or the size used for early receive) above it in the Rx FIFO.
3430 * Set it to the lower of:
3431 * - 90% of the Rx FIFO size, and
3432 * - the full Rx FIFO size minus one full frame
3434 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3435 fc->pause_time = 0xFFFF;
3436 else
3437 fc->pause_time = E1000_FC_PAUSE_TIME;
3438 fc->send_xon = 1;
3439 fc->current_mode = fc->requested_mode;
3441 switch (hw->mac.type) {
3442 case e1000_ich9lan:
3443 case e1000_ich10lan:
3444 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3445 pba = 14;
3446 ew32(PBA, pba);
3447 fc->high_water = 0x2800;
3448 fc->low_water = fc->high_water - 8;
3449 break;
3451 /* fall-through */
3452 default:
3453 hwm = min(((pba << 10) * 9 / 10),
3454 ((pba << 10) - adapter->max_frame_size));
3456 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3457 fc->low_water = fc->high_water - 8;
3458 break;
3459 case e1000_pchlan:
3461 * Workaround PCH LOM adapter hangs with certain network
3462 * loads. If hangs persist, try disabling Tx flow control.
3464 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3465 fc->high_water = 0x3500;
3466 fc->low_water = 0x1500;
3467 } else {
3468 fc->high_water = 0x5000;
3469 fc->low_water = 0x3000;
3471 fc->refresh_time = 0x1000;
3472 break;
3473 case e1000_pch2lan:
3474 fc->high_water = 0x05C20;
3475 fc->low_water = 0x05048;
3476 fc->pause_time = 0x0650;
3477 fc->refresh_time = 0x0400;
3478 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3479 pba = 14;
3480 ew32(PBA, pba);
3482 break;
3486 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3487 * fit in receive buffer.
3489 if (adapter->itr_setting & 0x3) {
3490 if ((adapter->max_frame_size * 2) > (pba << 10)) {
3491 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3492 dev_info(&adapter->pdev->dev,
3493 "Interrupt Throttle Rate turned off\n");
3494 adapter->flags2 |= FLAG2_DISABLE_AIM;
3495 ew32(ITR, 0);
3497 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3498 dev_info(&adapter->pdev->dev,
3499 "Interrupt Throttle Rate turned on\n");
3500 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3501 adapter->itr = 20000;
3502 ew32(ITR, 1000000000 / (adapter->itr * 256));
3506 /* Allow time for pending master requests to run */
3507 mac->ops.reset_hw(hw);
3510 * For parts with AMT enabled, let the firmware know
3511 * that the network interface is in control
3513 if (adapter->flags & FLAG_HAS_AMT)
3514 e1000e_get_hw_control(adapter);
3516 ew32(WUC, 0);
3518 if (mac->ops.init_hw(hw))
3519 e_err("Hardware Error\n");
3521 e1000_update_mng_vlan(adapter);
3523 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3524 ew32(VET, ETH_P_8021Q);
3526 e1000e_reset_adaptive(hw);
3528 if (!netif_running(adapter->netdev) &&
3529 !test_bit(__E1000_TESTING, &adapter->state)) {
3530 e1000_power_down_phy(adapter);
3531 return;
3534 e1000_get_phy_info(hw);
3536 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3537 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
3538 u16 phy_data = 0;
3540 * speed up time to link by disabling smart power down, ignore
3541 * the return value of this function because there is nothing
3542 * different we would do if it failed
3544 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3545 phy_data &= ~IGP02E1000_PM_SPD;
3546 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3550 int e1000e_up(struct e1000_adapter *adapter)
3552 struct e1000_hw *hw = &adapter->hw;
3554 /* hardware has been reset, we need to reload some things */
3555 e1000_configure(adapter);
3557 clear_bit(__E1000_DOWN, &adapter->state);
3559 if (adapter->msix_entries)
3560 e1000_configure_msix(adapter);
3561 e1000_irq_enable(adapter);
3563 netif_start_queue(adapter->netdev);
3565 /* fire a link change interrupt to start the watchdog */
3566 if (adapter->msix_entries)
3567 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3568 else
3569 ew32(ICS, E1000_ICS_LSC);
3571 return 0;
3574 static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3576 struct e1000_hw *hw = &adapter->hw;
3578 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3579 return;
3581 /* flush pending descriptor writebacks to memory */
3582 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3583 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3585 /* execute the writes immediately */
3586 e1e_flush();
3589 static void e1000e_update_stats(struct e1000_adapter *adapter);
3591 void e1000e_down(struct e1000_adapter *adapter)
3593 struct net_device *netdev = adapter->netdev;
3594 struct e1000_hw *hw = &adapter->hw;
3595 u32 tctl, rctl;
3598 * signal that we're down so the interrupt handler does not
3599 * reschedule our watchdog timer
3601 set_bit(__E1000_DOWN, &adapter->state);
3603 /* disable receives in the hardware */
3604 rctl = er32(RCTL);
3605 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3606 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3607 /* flush and sleep below */
3609 netif_stop_queue(netdev);
3611 /* disable transmits in the hardware */
3612 tctl = er32(TCTL);
3613 tctl &= ~E1000_TCTL_EN;
3614 ew32(TCTL, tctl);
3616 /* flush both disables and wait for them to finish */
3617 e1e_flush();
3618 usleep_range(10000, 20000);
3620 e1000_irq_disable(adapter);
3622 del_timer_sync(&adapter->watchdog_timer);
3623 del_timer_sync(&adapter->phy_info_timer);
3625 netif_carrier_off(netdev);
3627 spin_lock(&adapter->stats64_lock);
3628 e1000e_update_stats(adapter);
3629 spin_unlock(&adapter->stats64_lock);
3631 e1000e_flush_descriptors(adapter);
3632 e1000_clean_tx_ring(adapter->tx_ring);
3633 e1000_clean_rx_ring(adapter->rx_ring);
3635 adapter->link_speed = 0;
3636 adapter->link_duplex = 0;
3638 if (!pci_channel_offline(adapter->pdev))
3639 e1000e_reset(adapter);
3642 * TODO: for power management, we could drop the link and
3643 * pci_disable_device here.
3647 void e1000e_reinit_locked(struct e1000_adapter *adapter)
3649 might_sleep();
3650 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3651 usleep_range(1000, 2000);
3652 e1000e_down(adapter);
3653 e1000e_up(adapter);
3654 clear_bit(__E1000_RESETTING, &adapter->state);
3658 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3659 * @adapter: board private structure to initialize
3661 * e1000_sw_init initializes the Adapter private data structure.
3662 * Fields are initialized based on PCI device information and
3663 * OS network device settings (MTU size).
3665 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3667 struct net_device *netdev = adapter->netdev;
3669 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3670 adapter->rx_ps_bsize0 = 128;
3671 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3672 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
3673 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3674 adapter->rx_ring_count = E1000_DEFAULT_RXD;
3676 spin_lock_init(&adapter->stats64_lock);
3678 e1000e_set_interrupt_capability(adapter);
3680 if (e1000_alloc_queues(adapter))
3681 return -ENOMEM;
3683 /* Explicitly disable IRQ since the NIC can be in any state. */
3684 e1000_irq_disable(adapter);
3686 set_bit(__E1000_DOWN, &adapter->state);
3687 return 0;
3691 * e1000_intr_msi_test - Interrupt Handler
3692 * @irq: interrupt number
3693 * @data: pointer to a network interface device structure
3695 static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3697 struct net_device *netdev = data;
3698 struct e1000_adapter *adapter = netdev_priv(netdev);
3699 struct e1000_hw *hw = &adapter->hw;
3700 u32 icr = er32(ICR);
3702 e_dbg("icr is %08X\n", icr);
3703 if (icr & E1000_ICR_RXSEQ) {
3704 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3705 wmb();
3708 return IRQ_HANDLED;
3712 * e1000_test_msi_interrupt - Returns 0 for successful test
3713 * @adapter: board private struct
3715 * code flow taken from tg3.c
3717 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3719 struct net_device *netdev = adapter->netdev;
3720 struct e1000_hw *hw = &adapter->hw;
3721 int err;
3723 /* poll_enable hasn't been called yet, so don't need disable */
3724 /* clear any pending events */
3725 er32(ICR);
3727 /* free the real vector and request a test handler */
3728 e1000_free_irq(adapter);
3729 e1000e_reset_interrupt_capability(adapter);
3731 /* Assume that the test fails, if it succeeds then the test
3732 * MSI irq handler will unset this flag */
3733 adapter->flags |= FLAG_MSI_TEST_FAILED;
3735 err = pci_enable_msi(adapter->pdev);
3736 if (err)
3737 goto msi_test_failed;
3739 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
3740 netdev->name, netdev);
3741 if (err) {
3742 pci_disable_msi(adapter->pdev);
3743 goto msi_test_failed;
3746 wmb();
3748 e1000_irq_enable(adapter);
3750 /* fire an unusual interrupt on the test handler */
3751 ew32(ICS, E1000_ICS_RXSEQ);
3752 e1e_flush();
3753 msleep(50);
3755 e1000_irq_disable(adapter);
3757 rmb();
3759 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
3760 adapter->int_mode = E1000E_INT_MODE_LEGACY;
3761 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3762 } else {
3763 e_dbg("MSI interrupt test succeeded!\n");
3766 free_irq(adapter->pdev->irq, netdev);
3767 pci_disable_msi(adapter->pdev);
3769 msi_test_failed:
3770 e1000e_set_interrupt_capability(adapter);
3771 return e1000_request_irq(adapter);
3775 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3776 * @adapter: board private struct
3778 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3780 static int e1000_test_msi(struct e1000_adapter *adapter)
3782 int err;
3783 u16 pci_cmd;
3785 if (!(adapter->flags & FLAG_MSI_ENABLED))
3786 return 0;
3788 /* disable SERR in case the MSI write causes a master abort */
3789 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3790 if (pci_cmd & PCI_COMMAND_SERR)
3791 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3792 pci_cmd & ~PCI_COMMAND_SERR);
3794 err = e1000_test_msi_interrupt(adapter);
3796 /* re-enable SERR */
3797 if (pci_cmd & PCI_COMMAND_SERR) {
3798 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3799 pci_cmd |= PCI_COMMAND_SERR;
3800 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3803 return err;
3807 * e1000_open - Called when a network interface is made active
3808 * @netdev: network interface device structure
3810 * Returns 0 on success, negative value on failure
3812 * The open entry point is called when a network interface is made
3813 * active by the system (IFF_UP). At this point all resources needed
3814 * for transmit and receive operations are allocated, the interrupt
3815 * handler is registered with the OS, the watchdog timer is started,
3816 * and the stack is notified that the interface is ready.
3818 static int e1000_open(struct net_device *netdev)
3820 struct e1000_adapter *adapter = netdev_priv(netdev);
3821 struct e1000_hw *hw = &adapter->hw;
3822 struct pci_dev *pdev = adapter->pdev;
3823 int err;
3825 /* disallow open during test */
3826 if (test_bit(__E1000_TESTING, &adapter->state))
3827 return -EBUSY;
3829 pm_runtime_get_sync(&pdev->dev);
3831 netif_carrier_off(netdev);
3833 /* allocate transmit descriptors */
3834 err = e1000e_setup_tx_resources(adapter->tx_ring);
3835 if (err)
3836 goto err_setup_tx;
3838 /* allocate receive descriptors */
3839 err = e1000e_setup_rx_resources(adapter->rx_ring);
3840 if (err)
3841 goto err_setup_rx;
3844 * If AMT is enabled, let the firmware know that the network
3845 * interface is now open and reset the part to a known state.
3847 if (adapter->flags & FLAG_HAS_AMT) {
3848 e1000e_get_hw_control(adapter);
3849 e1000e_reset(adapter);
3852 e1000e_power_up_phy(adapter);
3854 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3855 if ((adapter->hw.mng_cookie.status &
3856 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3857 e1000_update_mng_vlan(adapter);
3859 /* DMA latency requirement to workaround jumbo issue */
3860 if (adapter->hw.mac.type == e1000_pch2lan)
3861 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3862 PM_QOS_CPU_DMA_LATENCY,
3863 PM_QOS_DEFAULT_VALUE);
3866 * before we allocate an interrupt, we must be ready to handle it.
3867 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3868 * as soon as we call pci_request_irq, so we have to setup our
3869 * clean_rx handler before we do so.
3871 e1000_configure(adapter);
3873 err = e1000_request_irq(adapter);
3874 if (err)
3875 goto err_req_irq;
3878 * Work around PCIe errata with MSI interrupts causing some chipsets to
3879 * ignore e1000e MSI messages, which means we need to test our MSI
3880 * interrupt now
3882 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
3883 err = e1000_test_msi(adapter);
3884 if (err) {
3885 e_err("Interrupt allocation failed\n");
3886 goto err_req_irq;
3890 /* From here on the code is the same as e1000e_up() */
3891 clear_bit(__E1000_DOWN, &adapter->state);
3893 napi_enable(&adapter->napi);
3895 e1000_irq_enable(adapter);
3897 adapter->tx_hang_recheck = false;
3898 netif_start_queue(netdev);
3900 adapter->idle_check = true;
3901 pm_runtime_put(&pdev->dev);
3903 /* fire a link status change interrupt to start the watchdog */
3904 if (adapter->msix_entries)
3905 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3906 else
3907 ew32(ICS, E1000_ICS_LSC);
3909 return 0;
3911 err_req_irq:
3912 e1000e_release_hw_control(adapter);
3913 e1000_power_down_phy(adapter);
3914 e1000e_free_rx_resources(adapter->rx_ring);
3915 err_setup_rx:
3916 e1000e_free_tx_resources(adapter->tx_ring);
3917 err_setup_tx:
3918 e1000e_reset(adapter);
3919 pm_runtime_put_sync(&pdev->dev);
3921 return err;
3925 * e1000_close - Disables a network interface
3926 * @netdev: network interface device structure
3928 * Returns 0, this is not allowed to fail
3930 * The close entry point is called when an interface is de-activated
3931 * by the OS. The hardware is still under the drivers control, but
3932 * needs to be disabled. A global MAC reset is issued to stop the
3933 * hardware, and all transmit and receive resources are freed.
3935 static int e1000_close(struct net_device *netdev)
3937 struct e1000_adapter *adapter = netdev_priv(netdev);
3938 struct pci_dev *pdev = adapter->pdev;
3940 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3942 pm_runtime_get_sync(&pdev->dev);
3944 napi_disable(&adapter->napi);
3946 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3947 e1000e_down(adapter);
3948 e1000_free_irq(adapter);
3950 e1000_power_down_phy(adapter);
3952 e1000e_free_tx_resources(adapter->tx_ring);
3953 e1000e_free_rx_resources(adapter->rx_ring);
3956 * kill manageability vlan ID if supported, but not if a vlan with
3957 * the same ID is registered on the host OS (let 8021q kill it)
3959 if (adapter->hw.mng_cookie.status &
3960 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
3961 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3964 * If AMT is enabled, let the firmware know that the network
3965 * interface is now closed
3967 if ((adapter->flags & FLAG_HAS_AMT) &&
3968 !test_bit(__E1000_TESTING, &adapter->state))
3969 e1000e_release_hw_control(adapter);
3971 if (adapter->hw.mac.type == e1000_pch2lan)
3972 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
3974 pm_runtime_put_sync(&pdev->dev);
3976 return 0;
3979 * e1000_set_mac - Change the Ethernet Address of the NIC
3980 * @netdev: network interface device structure
3981 * @p: pointer to an address structure
3983 * Returns 0 on success, negative on failure
3985 static int e1000_set_mac(struct net_device *netdev, void *p)
3987 struct e1000_adapter *adapter = netdev_priv(netdev);
3988 struct sockaddr *addr = p;
3990 if (!is_valid_ether_addr(addr->sa_data))
3991 return -EADDRNOTAVAIL;
3993 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3994 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3996 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3998 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3999 /* activate the work around */
4000 e1000e_set_laa_state_82571(&adapter->hw, 1);
4003 * Hold a copy of the LAA in RAR[14] This is done so that
4004 * between the time RAR[0] gets clobbered and the time it
4005 * gets fixed (in e1000_watchdog), the actual LAA is in one
4006 * of the RARs and no incoming packets directed to this port
4007 * are dropped. Eventually the LAA will be in RAR[0] and
4008 * RAR[14]
4010 e1000e_rar_set(&adapter->hw,
4011 adapter->hw.mac.addr,
4012 adapter->hw.mac.rar_entry_count - 1);
4015 return 0;
4019 * e1000e_update_phy_task - work thread to update phy
4020 * @work: pointer to our work struct
4022 * this worker thread exists because we must acquire a
4023 * semaphore to read the phy, which we could msleep while
4024 * waiting for it, and we can't msleep in a timer.
4026 static void e1000e_update_phy_task(struct work_struct *work)
4028 struct e1000_adapter *adapter = container_of(work,
4029 struct e1000_adapter, update_phy_task);
4031 if (test_bit(__E1000_DOWN, &adapter->state))
4032 return;
4034 e1000_get_phy_info(&adapter->hw);
4038 * Need to wait a few seconds after link up to get diagnostic information from
4039 * the phy
4041 static void e1000_update_phy_info(unsigned long data)
4043 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4045 if (test_bit(__E1000_DOWN, &adapter->state))
4046 return;
4048 schedule_work(&adapter->update_phy_task);
4052 * e1000e_update_phy_stats - Update the PHY statistics counters
4053 * @adapter: board private structure
4055 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
4057 static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4059 struct e1000_hw *hw = &adapter->hw;
4060 s32 ret_val;
4061 u16 phy_data;
4063 ret_val = hw->phy.ops.acquire(hw);
4064 if (ret_val)
4065 return;
4068 * A page set is expensive so check if already on desired page.
4069 * If not, set to the page with the PHY status registers.
4071 hw->phy.addr = 1;
4072 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4073 &phy_data);
4074 if (ret_val)
4075 goto release;
4076 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4077 ret_val = hw->phy.ops.set_page(hw,
4078 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4079 if (ret_val)
4080 goto release;
4083 /* Single Collision Count */
4084 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4085 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4086 if (!ret_val)
4087 adapter->stats.scc += phy_data;
4089 /* Excessive Collision Count */
4090 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4091 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4092 if (!ret_val)
4093 adapter->stats.ecol += phy_data;
4095 /* Multiple Collision Count */
4096 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4097 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4098 if (!ret_val)
4099 adapter->stats.mcc += phy_data;
4101 /* Late Collision Count */
4102 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4103 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4104 if (!ret_val)
4105 adapter->stats.latecol += phy_data;
4107 /* Collision Count - also used for adaptive IFS */
4108 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4109 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4110 if (!ret_val)
4111 hw->mac.collision_delta = phy_data;
4113 /* Defer Count */
4114 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4115 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4116 if (!ret_val)
4117 adapter->stats.dc += phy_data;
4119 /* Transmit with no CRS */
4120 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4121 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4122 if (!ret_val)
4123 adapter->stats.tncrs += phy_data;
4125 release:
4126 hw->phy.ops.release(hw);
4130 * e1000e_update_stats - Update the board statistics counters
4131 * @adapter: board private structure
4133 static void e1000e_update_stats(struct e1000_adapter *adapter)
4135 struct net_device *netdev = adapter->netdev;
4136 struct e1000_hw *hw = &adapter->hw;
4137 struct pci_dev *pdev = adapter->pdev;
4140 * Prevent stats update while adapter is being reset, or if the pci
4141 * connection is down.
4143 if (adapter->link_speed == 0)
4144 return;
4145 if (pci_channel_offline(pdev))
4146 return;
4148 adapter->stats.crcerrs += er32(CRCERRS);
4149 adapter->stats.gprc += er32(GPRC);
4150 adapter->stats.gorc += er32(GORCL);
4151 er32(GORCH); /* Clear gorc */
4152 adapter->stats.bprc += er32(BPRC);
4153 adapter->stats.mprc += er32(MPRC);
4154 adapter->stats.roc += er32(ROC);
4156 adapter->stats.mpc += er32(MPC);
4158 /* Half-duplex statistics */
4159 if (adapter->link_duplex == HALF_DUPLEX) {
4160 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4161 e1000e_update_phy_stats(adapter);
4162 } else {
4163 adapter->stats.scc += er32(SCC);
4164 adapter->stats.ecol += er32(ECOL);
4165 adapter->stats.mcc += er32(MCC);
4166 adapter->stats.latecol += er32(LATECOL);
4167 adapter->stats.dc += er32(DC);
4169 hw->mac.collision_delta = er32(COLC);
4171 if ((hw->mac.type != e1000_82574) &&
4172 (hw->mac.type != e1000_82583))
4173 adapter->stats.tncrs += er32(TNCRS);
4175 adapter->stats.colc += hw->mac.collision_delta;
4178 adapter->stats.xonrxc += er32(XONRXC);
4179 adapter->stats.xontxc += er32(XONTXC);
4180 adapter->stats.xoffrxc += er32(XOFFRXC);
4181 adapter->stats.xofftxc += er32(XOFFTXC);
4182 adapter->stats.gptc += er32(GPTC);
4183 adapter->stats.gotc += er32(GOTCL);
4184 er32(GOTCH); /* Clear gotc */
4185 adapter->stats.rnbc += er32(RNBC);
4186 adapter->stats.ruc += er32(RUC);
4188 adapter->stats.mptc += er32(MPTC);
4189 adapter->stats.bptc += er32(BPTC);
4191 /* used for adaptive IFS */
4193 hw->mac.tx_packet_delta = er32(TPT);
4194 adapter->stats.tpt += hw->mac.tx_packet_delta;
4196 adapter->stats.algnerrc += er32(ALGNERRC);
4197 adapter->stats.rxerrc += er32(RXERRC);
4198 adapter->stats.cexterr += er32(CEXTERR);
4199 adapter->stats.tsctc += er32(TSCTC);
4200 adapter->stats.tsctfc += er32(TSCTFC);
4202 /* Fill out the OS statistics structure */
4203 netdev->stats.multicast = adapter->stats.mprc;
4204 netdev->stats.collisions = adapter->stats.colc;
4206 /* Rx Errors */
4209 * RLEC on some newer hardware can be incorrect so build
4210 * our own version based on RUC and ROC
4212 netdev->stats.rx_errors = adapter->stats.rxerrc +
4213 adapter->stats.crcerrs + adapter->stats.algnerrc +
4214 adapter->stats.ruc + adapter->stats.roc +
4215 adapter->stats.cexterr;
4216 netdev->stats.rx_length_errors = adapter->stats.ruc +
4217 adapter->stats.roc;
4218 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4219 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4220 netdev->stats.rx_missed_errors = adapter->stats.mpc;
4222 /* Tx Errors */
4223 netdev->stats.tx_errors = adapter->stats.ecol +
4224 adapter->stats.latecol;
4225 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4226 netdev->stats.tx_window_errors = adapter->stats.latecol;
4227 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
4229 /* Tx Dropped needs to be maintained elsewhere */
4231 /* Management Stats */
4232 adapter->stats.mgptc += er32(MGTPTC);
4233 adapter->stats.mgprc += er32(MGTPRC);
4234 adapter->stats.mgpdc += er32(MGTPDC);
4238 * e1000_phy_read_status - Update the PHY register status snapshot
4239 * @adapter: board private structure
4241 static void e1000_phy_read_status(struct e1000_adapter *adapter)
4243 struct e1000_hw *hw = &adapter->hw;
4244 struct e1000_phy_regs *phy = &adapter->phy_regs;
4246 if ((er32(STATUS) & E1000_STATUS_LU) &&
4247 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
4248 int ret_val;
4250 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4251 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4252 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4253 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4254 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4255 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4256 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4257 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4258 if (ret_val)
4259 e_warn("Error reading PHY register\n");
4260 } else {
4262 * Do not read PHY registers if link is not up
4263 * Set values to typical power-on defaults
4265 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4266 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4267 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4268 BMSR_ERCAP);
4269 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4270 ADVERTISE_ALL | ADVERTISE_CSMA);
4271 phy->lpa = 0;
4272 phy->expansion = EXPANSION_ENABLENPAGE;
4273 phy->ctrl1000 = ADVERTISE_1000FULL;
4274 phy->stat1000 = 0;
4275 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4279 static void e1000_print_link_info(struct e1000_adapter *adapter)
4281 struct e1000_hw *hw = &adapter->hw;
4282 u32 ctrl = er32(CTRL);
4284 /* Link status message must follow this format for user tools */
4285 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4286 adapter->netdev->name,
4287 adapter->link_speed,
4288 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4289 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4290 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4291 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
4294 static bool e1000e_has_link(struct e1000_adapter *adapter)
4296 struct e1000_hw *hw = &adapter->hw;
4297 bool link_active = false;
4298 s32 ret_val = 0;
4301 * get_link_status is set on LSC (link status) interrupt or
4302 * Rx sequence error interrupt. get_link_status will stay
4303 * false until the check_for_link establishes link
4304 * for copper adapters ONLY
4306 switch (hw->phy.media_type) {
4307 case e1000_media_type_copper:
4308 if (hw->mac.get_link_status) {
4309 ret_val = hw->mac.ops.check_for_link(hw);
4310 link_active = !hw->mac.get_link_status;
4311 } else {
4312 link_active = true;
4314 break;
4315 case e1000_media_type_fiber:
4316 ret_val = hw->mac.ops.check_for_link(hw);
4317 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4318 break;
4319 case e1000_media_type_internal_serdes:
4320 ret_val = hw->mac.ops.check_for_link(hw);
4321 link_active = adapter->hw.mac.serdes_has_link;
4322 break;
4323 default:
4324 case e1000_media_type_unknown:
4325 break;
4328 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4329 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4330 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
4331 e_info("Gigabit has been disabled, downgrading speed\n");
4334 return link_active;
4337 static void e1000e_enable_receives(struct e1000_adapter *adapter)
4339 /* make sure the receive unit is started */
4340 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4341 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4342 struct e1000_hw *hw = &adapter->hw;
4343 u32 rctl = er32(RCTL);
4344 ew32(RCTL, rctl | E1000_RCTL_EN);
4345 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4349 static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4351 struct e1000_hw *hw = &adapter->hw;
4354 * With 82574 controllers, PHY needs to be checked periodically
4355 * for hung state and reset, if two calls return true
4357 if (e1000_check_phy_82574(hw))
4358 adapter->phy_hang_count++;
4359 else
4360 adapter->phy_hang_count = 0;
4362 if (adapter->phy_hang_count > 1) {
4363 adapter->phy_hang_count = 0;
4364 schedule_work(&adapter->reset_task);
4369 * e1000_watchdog - Timer Call-back
4370 * @data: pointer to adapter cast into an unsigned long
4372 static void e1000_watchdog(unsigned long data)
4374 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4376 /* Do the rest outside of interrupt context */
4377 schedule_work(&adapter->watchdog_task);
4379 /* TODO: make this use queue_delayed_work() */
4382 static void e1000_watchdog_task(struct work_struct *work)
4384 struct e1000_adapter *adapter = container_of(work,
4385 struct e1000_adapter, watchdog_task);
4386 struct net_device *netdev = adapter->netdev;
4387 struct e1000_mac_info *mac = &adapter->hw.mac;
4388 struct e1000_phy_info *phy = &adapter->hw.phy;
4389 struct e1000_ring *tx_ring = adapter->tx_ring;
4390 struct e1000_hw *hw = &adapter->hw;
4391 u32 link, tctl;
4393 if (test_bit(__E1000_DOWN, &adapter->state))
4394 return;
4396 link = e1000e_has_link(adapter);
4397 if ((netif_carrier_ok(netdev)) && link) {
4398 /* Cancel scheduled suspend requests. */
4399 pm_runtime_resume(netdev->dev.parent);
4401 e1000e_enable_receives(adapter);
4402 goto link_up;
4405 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4406 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4407 e1000_update_mng_vlan(adapter);
4409 if (link) {
4410 if (!netif_carrier_ok(netdev)) {
4411 bool txb2b = true;
4413 /* Cancel scheduled suspend requests. */
4414 pm_runtime_resume(netdev->dev.parent);
4416 /* update snapshot of PHY registers on LSC */
4417 e1000_phy_read_status(adapter);
4418 mac->ops.get_link_up_info(&adapter->hw,
4419 &adapter->link_speed,
4420 &adapter->link_duplex);
4421 e1000_print_link_info(adapter);
4423 * On supported PHYs, check for duplex mismatch only
4424 * if link has autonegotiated at 10/100 half
4426 if ((hw->phy.type == e1000_phy_igp_3 ||
4427 hw->phy.type == e1000_phy_bm) &&
4428 (hw->mac.autoneg == true) &&
4429 (adapter->link_speed == SPEED_10 ||
4430 adapter->link_speed == SPEED_100) &&
4431 (adapter->link_duplex == HALF_DUPLEX)) {
4432 u16 autoneg_exp;
4434 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4436 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4437 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
4440 /* adjust timeout factor according to speed/duplex */
4441 adapter->tx_timeout_factor = 1;
4442 switch (adapter->link_speed) {
4443 case SPEED_10:
4444 txb2b = false;
4445 adapter->tx_timeout_factor = 16;
4446 break;
4447 case SPEED_100:
4448 txb2b = false;
4449 adapter->tx_timeout_factor = 10;
4450 break;
4454 * workaround: re-program speed mode bit after
4455 * link-up event
4457 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4458 !txb2b) {
4459 u32 tarc0;
4460 tarc0 = er32(TARC(0));
4461 tarc0 &= ~SPEED_MODE_BIT;
4462 ew32(TARC(0), tarc0);
4466 * disable TSO for pcie and 10/100 speeds, to avoid
4467 * some hardware issues
4469 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4470 switch (adapter->link_speed) {
4471 case SPEED_10:
4472 case SPEED_100:
4473 e_info("10/100 speed: disabling TSO\n");
4474 netdev->features &= ~NETIF_F_TSO;
4475 netdev->features &= ~NETIF_F_TSO6;
4476 break;
4477 case SPEED_1000:
4478 netdev->features |= NETIF_F_TSO;
4479 netdev->features |= NETIF_F_TSO6;
4480 break;
4481 default:
4482 /* oops */
4483 break;
4488 * enable transmits in the hardware, need to do this
4489 * after setting TARC(0)
4491 tctl = er32(TCTL);
4492 tctl |= E1000_TCTL_EN;
4493 ew32(TCTL, tctl);
4496 * Perform any post-link-up configuration before
4497 * reporting link up.
4499 if (phy->ops.cfg_on_link_up)
4500 phy->ops.cfg_on_link_up(hw);
4502 netif_carrier_on(netdev);
4504 if (!test_bit(__E1000_DOWN, &adapter->state))
4505 mod_timer(&adapter->phy_info_timer,
4506 round_jiffies(jiffies + 2 * HZ));
4508 } else {
4509 if (netif_carrier_ok(netdev)) {
4510 adapter->link_speed = 0;
4511 adapter->link_duplex = 0;
4512 /* Link status message must follow this format */
4513 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4514 adapter->netdev->name);
4515 netif_carrier_off(netdev);
4516 if (!test_bit(__E1000_DOWN, &adapter->state))
4517 mod_timer(&adapter->phy_info_timer,
4518 round_jiffies(jiffies + 2 * HZ));
4520 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4521 schedule_work(&adapter->reset_task);
4522 else
4523 pm_schedule_suspend(netdev->dev.parent,
4524 LINK_TIMEOUT);
4528 link_up:
4529 spin_lock(&adapter->stats64_lock);
4530 e1000e_update_stats(adapter);
4532 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4533 adapter->tpt_old = adapter->stats.tpt;
4534 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4535 adapter->colc_old = adapter->stats.colc;
4537 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4538 adapter->gorc_old = adapter->stats.gorc;
4539 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4540 adapter->gotc_old = adapter->stats.gotc;
4541 spin_unlock(&adapter->stats64_lock);
4543 e1000e_update_adaptive(&adapter->hw);
4545 if (!netif_carrier_ok(netdev) &&
4546 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4548 * We've lost link, so the controller stops DMA,
4549 * but we've got queued Tx work that's never going
4550 * to get done, so reset controller to flush Tx.
4551 * (Do the reset outside of interrupt context).
4553 schedule_work(&adapter->reset_task);
4554 /* return immediately since reset is imminent */
4555 return;
4558 /* Simple mode for Interrupt Throttle Rate (ITR) */
4559 if (adapter->itr_setting == 4) {
4561 * Symmetric Tx/Rx gets a reduced ITR=2000;
4562 * Total asymmetrical Tx or Rx gets ITR=8000;
4563 * everyone else is between 2000-8000.
4565 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4566 u32 dif = (adapter->gotc > adapter->gorc ?
4567 adapter->gotc - adapter->gorc :
4568 adapter->gorc - adapter->gotc) / 10000;
4569 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4571 ew32(ITR, 1000000000 / (itr * 256));
4574 /* Cause software interrupt to ensure Rx ring is cleaned */
4575 if (adapter->msix_entries)
4576 ew32(ICS, adapter->rx_ring->ims_val);
4577 else
4578 ew32(ICS, E1000_ICS_RXDMT0);
4580 /* flush pending descriptors to memory before detecting Tx hang */
4581 e1000e_flush_descriptors(adapter);
4583 /* Force detection of hung controller every watchdog period */
4584 adapter->detect_tx_hung = true;
4587 * With 82571 controllers, LAA may be overwritten due to controller
4588 * reset from the other port. Set the appropriate LAA in RAR[0]
4590 if (e1000e_get_laa_state_82571(hw))
4591 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4593 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4594 e1000e_check_82574_phy_workaround(adapter);
4596 /* Reset the timer */
4597 if (!test_bit(__E1000_DOWN, &adapter->state))
4598 mod_timer(&adapter->watchdog_timer,
4599 round_jiffies(jiffies + 2 * HZ));
4602 #define E1000_TX_FLAGS_CSUM 0x00000001
4603 #define E1000_TX_FLAGS_VLAN 0x00000002
4604 #define E1000_TX_FLAGS_TSO 0x00000004
4605 #define E1000_TX_FLAGS_IPV4 0x00000008
4606 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4607 #define E1000_TX_FLAGS_VLAN_SHIFT 16
4609 static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
4611 struct e1000_context_desc *context_desc;
4612 struct e1000_buffer *buffer_info;
4613 unsigned int i;
4614 u32 cmd_length = 0;
4615 u16 ipcse = 0, tucse, mss;
4616 u8 ipcss, ipcso, tucss, tucso, hdr_len;
4618 if (!skb_is_gso(skb))
4619 return 0;
4621 if (skb_header_cloned(skb)) {
4622 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4624 if (err)
4625 return err;
4628 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4629 mss = skb_shinfo(skb)->gso_size;
4630 if (skb->protocol == htons(ETH_P_IP)) {
4631 struct iphdr *iph = ip_hdr(skb);
4632 iph->tot_len = 0;
4633 iph->check = 0;
4634 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4635 0, IPPROTO_TCP, 0);
4636 cmd_length = E1000_TXD_CMD_IP;
4637 ipcse = skb_transport_offset(skb) - 1;
4638 } else if (skb_is_gso_v6(skb)) {
4639 ipv6_hdr(skb)->payload_len = 0;
4640 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4641 &ipv6_hdr(skb)->daddr,
4642 0, IPPROTO_TCP, 0);
4643 ipcse = 0;
4645 ipcss = skb_network_offset(skb);
4646 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4647 tucss = skb_transport_offset(skb);
4648 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4649 tucse = 0;
4651 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4652 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4654 i = tx_ring->next_to_use;
4655 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4656 buffer_info = &tx_ring->buffer_info[i];
4658 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4659 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4660 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4661 context_desc->upper_setup.tcp_fields.tucss = tucss;
4662 context_desc->upper_setup.tcp_fields.tucso = tucso;
4663 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4664 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4665 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4666 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4668 buffer_info->time_stamp = jiffies;
4669 buffer_info->next_to_watch = i;
4671 i++;
4672 if (i == tx_ring->count)
4673 i = 0;
4674 tx_ring->next_to_use = i;
4676 return 1;
4679 static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
4681 struct e1000_adapter *adapter = tx_ring->adapter;
4682 struct e1000_context_desc *context_desc;
4683 struct e1000_buffer *buffer_info;
4684 unsigned int i;
4685 u8 css;
4686 u32 cmd_len = E1000_TXD_CMD_DEXT;
4687 __be16 protocol;
4689 if (skb->ip_summed != CHECKSUM_PARTIAL)
4690 return 0;
4692 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4693 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4694 else
4695 protocol = skb->protocol;
4697 switch (protocol) {
4698 case cpu_to_be16(ETH_P_IP):
4699 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4700 cmd_len |= E1000_TXD_CMD_TCP;
4701 break;
4702 case cpu_to_be16(ETH_P_IPV6):
4703 /* XXX not handling all IPV6 headers */
4704 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4705 cmd_len |= E1000_TXD_CMD_TCP;
4706 break;
4707 default:
4708 if (unlikely(net_ratelimit()))
4709 e_warn("checksum_partial proto=%x!\n",
4710 be16_to_cpu(protocol));
4711 break;
4714 css = skb_checksum_start_offset(skb);
4716 i = tx_ring->next_to_use;
4717 buffer_info = &tx_ring->buffer_info[i];
4718 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4720 context_desc->lower_setup.ip_config = 0;
4721 context_desc->upper_setup.tcp_fields.tucss = css;
4722 context_desc->upper_setup.tcp_fields.tucso =
4723 css + skb->csum_offset;
4724 context_desc->upper_setup.tcp_fields.tucse = 0;
4725 context_desc->tcp_seg_setup.data = 0;
4726 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4728 buffer_info->time_stamp = jiffies;
4729 buffer_info->next_to_watch = i;
4731 i++;
4732 if (i == tx_ring->count)
4733 i = 0;
4734 tx_ring->next_to_use = i;
4736 return 1;
4739 #define E1000_MAX_PER_TXD 8192
4740 #define E1000_MAX_TXD_PWR 12
4742 static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
4743 unsigned int first, unsigned int max_per_txd,
4744 unsigned int nr_frags, unsigned int mss)
4746 struct e1000_adapter *adapter = tx_ring->adapter;
4747 struct pci_dev *pdev = adapter->pdev;
4748 struct e1000_buffer *buffer_info;
4749 unsigned int len = skb_headlen(skb);
4750 unsigned int offset = 0, size, count = 0, i;
4751 unsigned int f, bytecount, segs;
4753 i = tx_ring->next_to_use;
4755 while (len) {
4756 buffer_info = &tx_ring->buffer_info[i];
4757 size = min(len, max_per_txd);
4759 buffer_info->length = size;
4760 buffer_info->time_stamp = jiffies;
4761 buffer_info->next_to_watch = i;
4762 buffer_info->dma = dma_map_single(&pdev->dev,
4763 skb->data + offset,
4764 size, DMA_TO_DEVICE);
4765 buffer_info->mapped_as_page = false;
4766 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4767 goto dma_error;
4769 len -= size;
4770 offset += size;
4771 count++;
4773 if (len) {
4774 i++;
4775 if (i == tx_ring->count)
4776 i = 0;
4780 for (f = 0; f < nr_frags; f++) {
4781 const struct skb_frag_struct *frag;
4783 frag = &skb_shinfo(skb)->frags[f];
4784 len = skb_frag_size(frag);
4785 offset = 0;
4787 while (len) {
4788 i++;
4789 if (i == tx_ring->count)
4790 i = 0;
4792 buffer_info = &tx_ring->buffer_info[i];
4793 size = min(len, max_per_txd);
4795 buffer_info->length = size;
4796 buffer_info->time_stamp = jiffies;
4797 buffer_info->next_to_watch = i;
4798 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4799 offset, size, DMA_TO_DEVICE);
4800 buffer_info->mapped_as_page = true;
4801 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
4802 goto dma_error;
4804 len -= size;
4805 offset += size;
4806 count++;
4810 segs = skb_shinfo(skb)->gso_segs ? : 1;
4811 /* multiply data chunks by size of headers */
4812 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4814 tx_ring->buffer_info[i].skb = skb;
4815 tx_ring->buffer_info[i].segs = segs;
4816 tx_ring->buffer_info[i].bytecount = bytecount;
4817 tx_ring->buffer_info[first].next_to_watch = i;
4819 return count;
4821 dma_error:
4822 dev_err(&pdev->dev, "Tx DMA map failed\n");
4823 buffer_info->dma = 0;
4824 if (count)
4825 count--;
4827 while (count--) {
4828 if (i == 0)
4829 i += tx_ring->count;
4830 i--;
4831 buffer_info = &tx_ring->buffer_info[i];
4832 e1000_put_txbuf(tx_ring, buffer_info);
4835 return 0;
4838 static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
4840 struct e1000_adapter *adapter = tx_ring->adapter;
4841 struct e1000_tx_desc *tx_desc = NULL;
4842 struct e1000_buffer *buffer_info;
4843 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4844 unsigned int i;
4846 if (tx_flags & E1000_TX_FLAGS_TSO) {
4847 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4848 E1000_TXD_CMD_TSE;
4849 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4851 if (tx_flags & E1000_TX_FLAGS_IPV4)
4852 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4855 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4856 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4857 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4860 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4861 txd_lower |= E1000_TXD_CMD_VLE;
4862 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4865 i = tx_ring->next_to_use;
4867 do {
4868 buffer_info = &tx_ring->buffer_info[i];
4869 tx_desc = E1000_TX_DESC(*tx_ring, i);
4870 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4871 tx_desc->lower.data =
4872 cpu_to_le32(txd_lower | buffer_info->length);
4873 tx_desc->upper.data = cpu_to_le32(txd_upper);
4875 i++;
4876 if (i == tx_ring->count)
4877 i = 0;
4878 } while (--count > 0);
4880 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4883 * Force memory writes to complete before letting h/w
4884 * know there are new descriptors to fetch. (Only
4885 * applicable for weak-ordered memory model archs,
4886 * such as IA-64).
4888 wmb();
4890 tx_ring->next_to_use = i;
4892 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4893 e1000e_update_tdt_wa(tx_ring, i);
4894 else
4895 writel(i, tx_ring->tail);
4898 * we need this if more than one processor can write to our tail
4899 * at a time, it synchronizes IO on IA64/Altix systems
4901 mmiowb();
4904 #define MINIMUM_DHCP_PACKET_SIZE 282
4905 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4906 struct sk_buff *skb)
4908 struct e1000_hw *hw = &adapter->hw;
4909 u16 length, offset;
4911 if (vlan_tx_tag_present(skb)) {
4912 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4913 (adapter->hw.mng_cookie.status &
4914 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4915 return 0;
4918 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4919 return 0;
4921 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4922 return 0;
4925 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4926 struct udphdr *udp;
4928 if (ip->protocol != IPPROTO_UDP)
4929 return 0;
4931 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4932 if (ntohs(udp->dest) != 67)
4933 return 0;
4935 offset = (u8 *)udp + 8 - skb->data;
4936 length = skb->len - offset;
4937 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4940 return 0;
4943 static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
4945 struct e1000_adapter *adapter = tx_ring->adapter;
4947 netif_stop_queue(adapter->netdev);
4949 * Herbert's original patch had:
4950 * smp_mb__after_netif_stop_queue();
4951 * but since that doesn't exist yet, just open code it.
4953 smp_mb();
4956 * We need to check again in a case another CPU has just
4957 * made room available.
4959 if (e1000_desc_unused(tx_ring) < size)
4960 return -EBUSY;
4962 /* A reprieve! */
4963 netif_start_queue(adapter->netdev);
4964 ++adapter->restart_queue;
4965 return 0;
4968 static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
4970 if (e1000_desc_unused(tx_ring) >= size)
4971 return 0;
4972 return __e1000_maybe_stop_tx(tx_ring, size);
4975 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1)
4976 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4977 struct net_device *netdev)
4979 struct e1000_adapter *adapter = netdev_priv(netdev);
4980 struct e1000_ring *tx_ring = adapter->tx_ring;
4981 unsigned int first;
4982 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4983 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4984 unsigned int tx_flags = 0;
4985 unsigned int len = skb_headlen(skb);
4986 unsigned int nr_frags;
4987 unsigned int mss;
4988 int count = 0;
4989 int tso;
4990 unsigned int f;
4992 if (test_bit(__E1000_DOWN, &adapter->state)) {
4993 dev_kfree_skb_any(skb);
4994 return NETDEV_TX_OK;
4997 if (skb->len <= 0) {
4998 dev_kfree_skb_any(skb);
4999 return NETDEV_TX_OK;
5002 mss = skb_shinfo(skb)->gso_size;
5004 * The controller does a simple calculation to
5005 * make sure there is enough room in the FIFO before
5006 * initiating the DMA for each buffer. The calc is:
5007 * 4 = ceil(buffer len/mss). To make sure we don't
5008 * overrun the FIFO, adjust the max buffer len if mss
5009 * drops.
5011 if (mss) {
5012 u8 hdr_len;
5013 max_per_txd = min(mss << 2, max_per_txd);
5014 max_txd_pwr = fls(max_per_txd) - 1;
5017 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
5018 * points to just header, pull a few bytes of payload from
5019 * frags into skb->data
5021 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5023 * we do this workaround for ES2LAN, but it is un-necessary,
5024 * avoiding it could save a lot of cycles
5026 if (skb->data_len && (hdr_len == len)) {
5027 unsigned int pull_size;
5029 pull_size = min_t(unsigned int, 4, skb->data_len);
5030 if (!__pskb_pull_tail(skb, pull_size)) {
5031 e_err("__pskb_pull_tail failed.\n");
5032 dev_kfree_skb_any(skb);
5033 return NETDEV_TX_OK;
5035 len = skb_headlen(skb);
5039 /* reserve a descriptor for the offload context */
5040 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5041 count++;
5042 count++;
5044 count += TXD_USE_COUNT(len, max_txd_pwr);
5046 nr_frags = skb_shinfo(skb)->nr_frags;
5047 for (f = 0; f < nr_frags; f++)
5048 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5049 max_txd_pwr);
5051 if (adapter->hw.mac.tx_pkt_filtering)
5052 e1000_transfer_dhcp_info(adapter, skb);
5055 * need: count + 2 desc gap to keep tail from touching
5056 * head, otherwise try next time
5058 if (e1000_maybe_stop_tx(tx_ring, count + 2))
5059 return NETDEV_TX_BUSY;
5061 if (vlan_tx_tag_present(skb)) {
5062 tx_flags |= E1000_TX_FLAGS_VLAN;
5063 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5066 first = tx_ring->next_to_use;
5068 tso = e1000_tso(tx_ring, skb);
5069 if (tso < 0) {
5070 dev_kfree_skb_any(skb);
5071 return NETDEV_TX_OK;
5074 if (tso)
5075 tx_flags |= E1000_TX_FLAGS_TSO;
5076 else if (e1000_tx_csum(tx_ring, skb))
5077 tx_flags |= E1000_TX_FLAGS_CSUM;
5080 * Old method was to assume IPv4 packet by default if TSO was enabled.
5081 * 82571 hardware supports TSO capabilities for IPv6 as well...
5082 * no longer assume, we must.
5084 if (skb->protocol == htons(ETH_P_IP))
5085 tx_flags |= E1000_TX_FLAGS_IPV4;
5087 /* if count is 0 then mapping error has occurred */
5088 count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss);
5089 if (count) {
5090 netdev_sent_queue(netdev, skb->len);
5091 e1000_tx_queue(tx_ring, tx_flags, count);
5092 /* Make sure there is space in the ring for the next send. */
5093 e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2);
5095 } else {
5096 dev_kfree_skb_any(skb);
5097 tx_ring->buffer_info[first].time_stamp = 0;
5098 tx_ring->next_to_use = first;
5101 return NETDEV_TX_OK;
5105 * e1000_tx_timeout - Respond to a Tx Hang
5106 * @netdev: network interface device structure
5108 static void e1000_tx_timeout(struct net_device *netdev)
5110 struct e1000_adapter *adapter = netdev_priv(netdev);
5112 /* Do the reset outside of interrupt context */
5113 adapter->tx_timeout_count++;
5114 schedule_work(&adapter->reset_task);
5117 static void e1000_reset_task(struct work_struct *work)
5119 struct e1000_adapter *adapter;
5120 adapter = container_of(work, struct e1000_adapter, reset_task);
5122 /* don't run the task if already down */
5123 if (test_bit(__E1000_DOWN, &adapter->state))
5124 return;
5126 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5127 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5128 e1000e_dump(adapter);
5129 e_err("Reset adapter\n");
5131 e1000e_reinit_locked(adapter);
5135 * e1000_get_stats64 - Get System Network Statistics
5136 * @netdev: network interface device structure
5137 * @stats: rtnl_link_stats64 pointer
5139 * Returns the address of the device statistics structure.
5141 struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5142 struct rtnl_link_stats64 *stats)
5144 struct e1000_adapter *adapter = netdev_priv(netdev);
5146 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5147 spin_lock(&adapter->stats64_lock);
5148 e1000e_update_stats(adapter);
5149 /* Fill out the OS statistics structure */
5150 stats->rx_bytes = adapter->stats.gorc;
5151 stats->rx_packets = adapter->stats.gprc;
5152 stats->tx_bytes = adapter->stats.gotc;
5153 stats->tx_packets = adapter->stats.gptc;
5154 stats->multicast = adapter->stats.mprc;
5155 stats->collisions = adapter->stats.colc;
5157 /* Rx Errors */
5160 * RLEC on some newer hardware can be incorrect so build
5161 * our own version based on RUC and ROC
5163 stats->rx_errors = adapter->stats.rxerrc +
5164 adapter->stats.crcerrs + adapter->stats.algnerrc +
5165 adapter->stats.ruc + adapter->stats.roc +
5166 adapter->stats.cexterr;
5167 stats->rx_length_errors = adapter->stats.ruc +
5168 adapter->stats.roc;
5169 stats->rx_crc_errors = adapter->stats.crcerrs;
5170 stats->rx_frame_errors = adapter->stats.algnerrc;
5171 stats->rx_missed_errors = adapter->stats.mpc;
5173 /* Tx Errors */
5174 stats->tx_errors = adapter->stats.ecol +
5175 adapter->stats.latecol;
5176 stats->tx_aborted_errors = adapter->stats.ecol;
5177 stats->tx_window_errors = adapter->stats.latecol;
5178 stats->tx_carrier_errors = adapter->stats.tncrs;
5180 /* Tx Dropped needs to be maintained elsewhere */
5182 spin_unlock(&adapter->stats64_lock);
5183 return stats;
5187 * e1000_change_mtu - Change the Maximum Transfer Unit
5188 * @netdev: network interface device structure
5189 * @new_mtu: new value for maximum frame size
5191 * Returns 0 on success, negative on failure
5193 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5195 struct e1000_adapter *adapter = netdev_priv(netdev);
5196 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5198 /* Jumbo frame support */
5199 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
5200 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5201 e_err("Jumbo Frames not supported.\n");
5202 return -EINVAL;
5206 * IP payload checksum (enabled with jumbos/packet-split when
5207 * Rx checksum is enabled) and generation of RSS hash is
5208 * mutually exclusive in the hardware.
5210 if ((netdev->features & NETIF_F_RXCSUM) &&
5211 (netdev->features & NETIF_F_RXHASH)) {
5212 e_err("Jumbo frames cannot be enabled when both receive checksum offload and receive hashing are enabled. Disable one of the receive offload features before enabling jumbos.\n");
5213 return -EINVAL;
5217 /* Supported frame sizes */
5218 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5219 (max_frame > adapter->max_hw_frame_size)) {
5220 e_err("Unsupported MTU setting\n");
5221 return -EINVAL;
5224 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5225 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5226 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5227 (new_mtu > ETH_DATA_LEN)) {
5228 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
5229 return -EINVAL;
5232 /* 82573 Errata 17 */
5233 if (((adapter->hw.mac.type == e1000_82573) ||
5234 (adapter->hw.mac.type == e1000_82574)) &&
5235 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5236 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5237 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5240 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
5241 usleep_range(1000, 2000);
5242 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
5243 adapter->max_frame_size = max_frame;
5244 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5245 netdev->mtu = new_mtu;
5246 if (netif_running(netdev))
5247 e1000e_down(adapter);
5250 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
5251 * means we reserve 2 more, this pushes us to allocate from the next
5252 * larger slab size.
5253 * i.e. RXBUFFER_2048 --> size-4096 slab
5254 * However with the new *_jumbo_rx* routines, jumbo receives will use
5255 * fragmented skbs
5258 if (max_frame <= 2048)
5259 adapter->rx_buffer_len = 2048;
5260 else
5261 adapter->rx_buffer_len = 4096;
5263 /* adjust allocation if LPE protects us, and we aren't using SBP */
5264 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5265 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5266 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
5267 + ETH_FCS_LEN;
5269 if (netif_running(netdev))
5270 e1000e_up(adapter);
5271 else
5272 e1000e_reset(adapter);
5274 clear_bit(__E1000_RESETTING, &adapter->state);
5276 return 0;
5279 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5280 int cmd)
5282 struct e1000_adapter *adapter = netdev_priv(netdev);
5283 struct mii_ioctl_data *data = if_mii(ifr);
5285 if (adapter->hw.phy.media_type != e1000_media_type_copper)
5286 return -EOPNOTSUPP;
5288 switch (cmd) {
5289 case SIOCGMIIPHY:
5290 data->phy_id = adapter->hw.phy.addr;
5291 break;
5292 case SIOCGMIIREG:
5293 e1000_phy_read_status(adapter);
5295 switch (data->reg_num & 0x1F) {
5296 case MII_BMCR:
5297 data->val_out = adapter->phy_regs.bmcr;
5298 break;
5299 case MII_BMSR:
5300 data->val_out = adapter->phy_regs.bmsr;
5301 break;
5302 case MII_PHYSID1:
5303 data->val_out = (adapter->hw.phy.id >> 16);
5304 break;
5305 case MII_PHYSID2:
5306 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5307 break;
5308 case MII_ADVERTISE:
5309 data->val_out = adapter->phy_regs.advertise;
5310 break;
5311 case MII_LPA:
5312 data->val_out = adapter->phy_regs.lpa;
5313 break;
5314 case MII_EXPANSION:
5315 data->val_out = adapter->phy_regs.expansion;
5316 break;
5317 case MII_CTRL1000:
5318 data->val_out = adapter->phy_regs.ctrl1000;
5319 break;
5320 case MII_STAT1000:
5321 data->val_out = adapter->phy_regs.stat1000;
5322 break;
5323 case MII_ESTATUS:
5324 data->val_out = adapter->phy_regs.estatus;
5325 break;
5326 default:
5327 return -EIO;
5329 break;
5330 case SIOCSMIIREG:
5331 default:
5332 return -EOPNOTSUPP;
5334 return 0;
5337 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5339 switch (cmd) {
5340 case SIOCGMIIPHY:
5341 case SIOCGMIIREG:
5342 case SIOCSMIIREG:
5343 return e1000_mii_ioctl(netdev, ifr, cmd);
5344 default:
5345 return -EOPNOTSUPP;
5349 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5351 struct e1000_hw *hw = &adapter->hw;
5352 u32 i, mac_reg;
5353 u16 phy_reg, wuc_enable;
5354 int retval = 0;
5356 /* copy MAC RARs to PHY RARs */
5357 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
5359 retval = hw->phy.ops.acquire(hw);
5360 if (retval) {
5361 e_err("Could not acquire PHY\n");
5362 return retval;
5365 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5366 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5367 if (retval)
5368 goto out;
5370 /* copy MAC MTA to PHY MTA - only needed for pchlan */
5371 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5372 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5373 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5374 (u16)(mac_reg & 0xFFFF));
5375 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5376 (u16)((mac_reg >> 16) & 0xFFFF));
5379 /* configure PHY Rx Control register */
5380 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
5381 mac_reg = er32(RCTL);
5382 if (mac_reg & E1000_RCTL_UPE)
5383 phy_reg |= BM_RCTL_UPE;
5384 if (mac_reg & E1000_RCTL_MPE)
5385 phy_reg |= BM_RCTL_MPE;
5386 phy_reg &= ~(BM_RCTL_MO_MASK);
5387 if (mac_reg & E1000_RCTL_MO_3)
5388 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5389 << BM_RCTL_MO_SHIFT);
5390 if (mac_reg & E1000_RCTL_BAM)
5391 phy_reg |= BM_RCTL_BAM;
5392 if (mac_reg & E1000_RCTL_PMCF)
5393 phy_reg |= BM_RCTL_PMCF;
5394 mac_reg = er32(CTRL);
5395 if (mac_reg & E1000_CTRL_RFCE)
5396 phy_reg |= BM_RCTL_RFCE;
5397 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
5399 /* enable PHY wakeup in MAC register */
5400 ew32(WUFC, wufc);
5401 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5403 /* configure and enable PHY wakeup in PHY registers */
5404 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5405 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5407 /* activate PHY wakeup */
5408 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5409 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5410 if (retval)
5411 e_err("Could not set PHY Host Wakeup bit\n");
5412 out:
5413 hw->phy.ops.release(hw);
5415 return retval;
5418 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5419 bool runtime)
5421 struct net_device *netdev = pci_get_drvdata(pdev);
5422 struct e1000_adapter *adapter = netdev_priv(netdev);
5423 struct e1000_hw *hw = &adapter->hw;
5424 u32 ctrl, ctrl_ext, rctl, status;
5425 /* Runtime suspend should only enable wakeup for link changes */
5426 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
5427 int retval = 0;
5429 netif_device_detach(netdev);
5431 if (netif_running(netdev)) {
5432 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5433 e1000e_down(adapter);
5434 e1000_free_irq(adapter);
5436 e1000e_reset_interrupt_capability(adapter);
5438 retval = pci_save_state(pdev);
5439 if (retval)
5440 return retval;
5442 status = er32(STATUS);
5443 if (status & E1000_STATUS_LU)
5444 wufc &= ~E1000_WUFC_LNKC;
5446 if (wufc) {
5447 e1000_setup_rctl(adapter);
5448 e1000e_set_rx_mode(netdev);
5450 /* turn on all-multi mode if wake on multicast is enabled */
5451 if (wufc & E1000_WUFC_MC) {
5452 rctl = er32(RCTL);
5453 rctl |= E1000_RCTL_MPE;
5454 ew32(RCTL, rctl);
5457 ctrl = er32(CTRL);
5458 /* advertise wake from D3Cold */
5459 #define E1000_CTRL_ADVD3WUC 0x00100000
5460 /* phy power management enable */
5461 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5462 ctrl |= E1000_CTRL_ADVD3WUC;
5463 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5464 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
5465 ew32(CTRL, ctrl);
5467 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5468 adapter->hw.phy.media_type ==
5469 e1000_media_type_internal_serdes) {
5470 /* keep the laser running in D3 */
5471 ctrl_ext = er32(CTRL_EXT);
5472 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
5473 ew32(CTRL_EXT, ctrl_ext);
5476 if (adapter->flags & FLAG_IS_ICH)
5477 e1000_suspend_workarounds_ich8lan(&adapter->hw);
5479 /* Allow time for pending master requests to run */
5480 e1000e_disable_pcie_master(&adapter->hw);
5482 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5483 /* enable wakeup by the PHY */
5484 retval = e1000_init_phy_wakeup(adapter, wufc);
5485 if (retval)
5486 return retval;
5487 } else {
5488 /* enable wakeup by the MAC */
5489 ew32(WUFC, wufc);
5490 ew32(WUC, E1000_WUC_PME_EN);
5492 } else {
5493 ew32(WUC, 0);
5494 ew32(WUFC, 0);
5497 *enable_wake = !!wufc;
5499 /* make sure adapter isn't asleep if manageability is enabled */
5500 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5501 (hw->mac.ops.check_mng_mode(hw)))
5502 *enable_wake = true;
5504 if (adapter->hw.phy.type == e1000_phy_igp_3)
5505 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5508 * Release control of h/w to f/w. If f/w is AMT enabled, this
5509 * would have already happened in close and is redundant.
5511 e1000e_release_hw_control(adapter);
5513 pci_disable_device(pdev);
5515 return 0;
5518 static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5520 if (sleep && wake) {
5521 pci_prepare_to_sleep(pdev);
5522 return;
5525 pci_wake_from_d3(pdev, wake);
5526 pci_set_power_state(pdev, PCI_D3hot);
5529 static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5530 bool wake)
5532 struct net_device *netdev = pci_get_drvdata(pdev);
5533 struct e1000_adapter *adapter = netdev_priv(netdev);
5536 * The pci-e switch on some quad port adapters will report a
5537 * correctable error when the MAC transitions from D0 to D3. To
5538 * prevent this we need to mask off the correctable errors on the
5539 * downstream port of the pci-e switch.
5541 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5542 struct pci_dev *us_dev = pdev->bus->self;
5543 int pos = pci_pcie_cap(us_dev);
5544 u16 devctl;
5546 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5547 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5548 (devctl & ~PCI_EXP_DEVCTL_CERE));
5550 e1000_power_off(pdev, sleep, wake);
5552 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5553 } else {
5554 e1000_power_off(pdev, sleep, wake);
5558 #ifdef CONFIG_PCIEASPM
5559 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5561 pci_disable_link_state_locked(pdev, state);
5563 #else
5564 static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5566 int pos;
5567 u16 reg16;
5570 * Both device and parent should have the same ASPM setting.
5571 * Disable ASPM in downstream component first and then upstream.
5573 pos = pci_pcie_cap(pdev);
5574 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5575 reg16 &= ~state;
5576 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5578 if (!pdev->bus->self)
5579 return;
5581 pos = pci_pcie_cap(pdev->bus->self);
5582 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5583 reg16 &= ~state;
5584 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5586 #endif
5587 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5589 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5590 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5591 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5593 __e1000e_disable_aspm(pdev, state);
5596 #ifdef CONFIG_PM
5597 static bool e1000e_pm_ready(struct e1000_adapter *adapter)
5599 return !!adapter->tx_ring->buffer_info;
5602 static int __e1000_resume(struct pci_dev *pdev)
5604 struct net_device *netdev = pci_get_drvdata(pdev);
5605 struct e1000_adapter *adapter = netdev_priv(netdev);
5606 struct e1000_hw *hw = &adapter->hw;
5607 u16 aspm_disable_flag = 0;
5608 u32 err;
5610 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5611 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5612 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5613 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5614 if (aspm_disable_flag)
5615 e1000e_disable_aspm(pdev, aspm_disable_flag);
5617 pci_set_power_state(pdev, PCI_D0);
5618 pci_restore_state(pdev);
5619 pci_save_state(pdev);
5621 e1000e_set_interrupt_capability(adapter);
5622 if (netif_running(netdev)) {
5623 err = e1000_request_irq(adapter);
5624 if (err)
5625 return err;
5628 if (hw->mac.type == e1000_pch2lan)
5629 e1000_resume_workarounds_pchlan(&adapter->hw);
5631 e1000e_power_up_phy(adapter);
5633 /* report the system wakeup cause from S3/S4 */
5634 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5635 u16 phy_data;
5637 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5638 if (phy_data) {
5639 e_info("PHY Wakeup cause - %s\n",
5640 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5641 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5642 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5643 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5644 phy_data & E1000_WUS_LNKC ?
5645 "Link Status Change" : "other");
5647 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5648 } else {
5649 u32 wus = er32(WUS);
5650 if (wus) {
5651 e_info("MAC Wakeup cause - %s\n",
5652 wus & E1000_WUS_EX ? "Unicast Packet" :
5653 wus & E1000_WUS_MC ? "Multicast Packet" :
5654 wus & E1000_WUS_BC ? "Broadcast Packet" :
5655 wus & E1000_WUS_MAG ? "Magic Packet" :
5656 wus & E1000_WUS_LNKC ? "Link Status Change" :
5657 "other");
5659 ew32(WUS, ~0);
5662 e1000e_reset(adapter);
5664 e1000_init_manageability_pt(adapter);
5666 if (netif_running(netdev))
5667 e1000e_up(adapter);
5669 netif_device_attach(netdev);
5672 * If the controller has AMT, do not set DRV_LOAD until the interface
5673 * is up. For all other cases, let the f/w know that the h/w is now
5674 * under the control of the driver.
5676 if (!(adapter->flags & FLAG_HAS_AMT))
5677 e1000e_get_hw_control(adapter);
5679 return 0;
5682 #ifdef CONFIG_PM_SLEEP
5683 static int e1000_suspend(struct device *dev)
5685 struct pci_dev *pdev = to_pci_dev(dev);
5686 int retval;
5687 bool wake;
5689 retval = __e1000_shutdown(pdev, &wake, false);
5690 if (!retval)
5691 e1000_complete_shutdown(pdev, true, wake);
5693 return retval;
5696 static int e1000_resume(struct device *dev)
5698 struct pci_dev *pdev = to_pci_dev(dev);
5699 struct net_device *netdev = pci_get_drvdata(pdev);
5700 struct e1000_adapter *adapter = netdev_priv(netdev);
5702 if (e1000e_pm_ready(adapter))
5703 adapter->idle_check = true;
5705 return __e1000_resume(pdev);
5707 #endif /* CONFIG_PM_SLEEP */
5709 #ifdef CONFIG_PM_RUNTIME
5710 static int e1000_runtime_suspend(struct device *dev)
5712 struct pci_dev *pdev = to_pci_dev(dev);
5713 struct net_device *netdev = pci_get_drvdata(pdev);
5714 struct e1000_adapter *adapter = netdev_priv(netdev);
5716 if (e1000e_pm_ready(adapter)) {
5717 bool wake;
5719 __e1000_shutdown(pdev, &wake, true);
5722 return 0;
5725 static int e1000_idle(struct device *dev)
5727 struct pci_dev *pdev = to_pci_dev(dev);
5728 struct net_device *netdev = pci_get_drvdata(pdev);
5729 struct e1000_adapter *adapter = netdev_priv(netdev);
5731 if (!e1000e_pm_ready(adapter))
5732 return 0;
5734 if (adapter->idle_check) {
5735 adapter->idle_check = false;
5736 if (!e1000e_has_link(adapter))
5737 pm_schedule_suspend(dev, MSEC_PER_SEC);
5740 return -EBUSY;
5743 static int e1000_runtime_resume(struct device *dev)
5745 struct pci_dev *pdev = to_pci_dev(dev);
5746 struct net_device *netdev = pci_get_drvdata(pdev);
5747 struct e1000_adapter *adapter = netdev_priv(netdev);
5749 if (!e1000e_pm_ready(adapter))
5750 return 0;
5752 adapter->idle_check = !dev->power.runtime_auto;
5753 return __e1000_resume(pdev);
5755 #endif /* CONFIG_PM_RUNTIME */
5756 #endif /* CONFIG_PM */
5758 static void e1000_shutdown(struct pci_dev *pdev)
5760 bool wake = false;
5762 __e1000_shutdown(pdev, &wake, false);
5764 if (system_state == SYSTEM_POWER_OFF)
5765 e1000_complete_shutdown(pdev, false, wake);
5768 #ifdef CONFIG_NET_POLL_CONTROLLER
5770 static irqreturn_t e1000_intr_msix(int irq, void *data)
5772 struct net_device *netdev = data;
5773 struct e1000_adapter *adapter = netdev_priv(netdev);
5775 if (adapter->msix_entries) {
5776 int vector, msix_irq;
5778 vector = 0;
5779 msix_irq = adapter->msix_entries[vector].vector;
5780 disable_irq(msix_irq);
5781 e1000_intr_msix_rx(msix_irq, netdev);
5782 enable_irq(msix_irq);
5784 vector++;
5785 msix_irq = adapter->msix_entries[vector].vector;
5786 disable_irq(msix_irq);
5787 e1000_intr_msix_tx(msix_irq, netdev);
5788 enable_irq(msix_irq);
5790 vector++;
5791 msix_irq = adapter->msix_entries[vector].vector;
5792 disable_irq(msix_irq);
5793 e1000_msix_other(msix_irq, netdev);
5794 enable_irq(msix_irq);
5797 return IRQ_HANDLED;
5801 * Polling 'interrupt' - used by things like netconsole to send skbs
5802 * without having to re-enable interrupts. It's not called while
5803 * the interrupt routine is executing.
5805 static void e1000_netpoll(struct net_device *netdev)
5807 struct e1000_adapter *adapter = netdev_priv(netdev);
5809 switch (adapter->int_mode) {
5810 case E1000E_INT_MODE_MSIX:
5811 e1000_intr_msix(adapter->pdev->irq, netdev);
5812 break;
5813 case E1000E_INT_MODE_MSI:
5814 disable_irq(adapter->pdev->irq);
5815 e1000_intr_msi(adapter->pdev->irq, netdev);
5816 enable_irq(adapter->pdev->irq);
5817 break;
5818 default: /* E1000E_INT_MODE_LEGACY */
5819 disable_irq(adapter->pdev->irq);
5820 e1000_intr(adapter->pdev->irq, netdev);
5821 enable_irq(adapter->pdev->irq);
5822 break;
5825 #endif
5828 * e1000_io_error_detected - called when PCI error is detected
5829 * @pdev: Pointer to PCI device
5830 * @state: The current pci connection state
5832 * This function is called after a PCI bus error affecting
5833 * this device has been detected.
5835 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5836 pci_channel_state_t state)
5838 struct net_device *netdev = pci_get_drvdata(pdev);
5839 struct e1000_adapter *adapter = netdev_priv(netdev);
5841 netif_device_detach(netdev);
5843 if (state == pci_channel_io_perm_failure)
5844 return PCI_ERS_RESULT_DISCONNECT;
5846 if (netif_running(netdev))
5847 e1000e_down(adapter);
5848 pci_disable_device(pdev);
5850 /* Request a slot slot reset. */
5851 return PCI_ERS_RESULT_NEED_RESET;
5855 * e1000_io_slot_reset - called after the pci bus has been reset.
5856 * @pdev: Pointer to PCI device
5858 * Restart the card from scratch, as if from a cold-boot. Implementation
5859 * resembles the first-half of the e1000_resume routine.
5861 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5863 struct net_device *netdev = pci_get_drvdata(pdev);
5864 struct e1000_adapter *adapter = netdev_priv(netdev);
5865 struct e1000_hw *hw = &adapter->hw;
5866 u16 aspm_disable_flag = 0;
5867 int err;
5868 pci_ers_result_t result;
5870 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5871 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5872 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5873 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5874 if (aspm_disable_flag)
5875 e1000e_disable_aspm(pdev, aspm_disable_flag);
5877 err = pci_enable_device_mem(pdev);
5878 if (err) {
5879 dev_err(&pdev->dev,
5880 "Cannot re-enable PCI device after reset.\n");
5881 result = PCI_ERS_RESULT_DISCONNECT;
5882 } else {
5883 pci_set_master(pdev);
5884 pdev->state_saved = true;
5885 pci_restore_state(pdev);
5887 pci_enable_wake(pdev, PCI_D3hot, 0);
5888 pci_enable_wake(pdev, PCI_D3cold, 0);
5890 e1000e_reset(adapter);
5891 ew32(WUS, ~0);
5892 result = PCI_ERS_RESULT_RECOVERED;
5895 pci_cleanup_aer_uncorrect_error_status(pdev);
5897 return result;
5901 * e1000_io_resume - called when traffic can start flowing again.
5902 * @pdev: Pointer to PCI device
5904 * This callback is called when the error recovery driver tells us that
5905 * its OK to resume normal operation. Implementation resembles the
5906 * second-half of the e1000_resume routine.
5908 static void e1000_io_resume(struct pci_dev *pdev)
5910 struct net_device *netdev = pci_get_drvdata(pdev);
5911 struct e1000_adapter *adapter = netdev_priv(netdev);
5913 e1000_init_manageability_pt(adapter);
5915 if (netif_running(netdev)) {
5916 if (e1000e_up(adapter)) {
5917 dev_err(&pdev->dev,
5918 "can't bring device back up after reset\n");
5919 return;
5923 netif_device_attach(netdev);
5926 * If the controller has AMT, do not set DRV_LOAD until the interface
5927 * is up. For all other cases, let the f/w know that the h/w is now
5928 * under the control of the driver.
5930 if (!(adapter->flags & FLAG_HAS_AMT))
5931 e1000e_get_hw_control(adapter);
5935 static void e1000_print_device_info(struct e1000_adapter *adapter)
5937 struct e1000_hw *hw = &adapter->hw;
5938 struct net_device *netdev = adapter->netdev;
5939 u32 ret_val;
5940 u8 pba_str[E1000_PBANUM_LENGTH];
5942 /* print bus type/speed/width info */
5943 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
5944 /* bus width */
5945 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5946 "Width x1"),
5947 /* MAC address */
5948 netdev->dev_addr);
5949 e_info("Intel(R) PRO/%s Network Connection\n",
5950 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
5951 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5952 E1000_PBANUM_LENGTH);
5953 if (ret_val)
5954 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
5955 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5956 hw->mac.type, hw->phy.type, pba_str);
5959 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5961 struct e1000_hw *hw = &adapter->hw;
5962 int ret_val;
5963 u16 buf = 0;
5965 if (hw->mac.type != e1000_82573)
5966 return;
5968 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
5969 le16_to_cpus(&buf);
5970 if (!ret_val && (!(buf & (1 << 0)))) {
5971 /* Deep Smart Power Down (DSPD) */
5972 dev_warn(&adapter->pdev->dev,
5973 "Warning: detected DSPD enabled in EEPROM\n");
5977 static int e1000_set_features(struct net_device *netdev,
5978 netdev_features_t features)
5980 struct e1000_adapter *adapter = netdev_priv(netdev);
5981 netdev_features_t changed = features ^ netdev->features;
5983 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5984 adapter->flags |= FLAG_TSO_FORCE;
5986 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
5987 NETIF_F_RXCSUM | NETIF_F_RXHASH)))
5988 return 0;
5991 * IP payload checksum (enabled with jumbos/packet-split when Rx
5992 * checksum is enabled) and generation of RSS hash is mutually
5993 * exclusive in the hardware.
5995 if (adapter->rx_ps_pages &&
5996 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
5997 e_err("Enabling both receive checksum offload and receive hashing is not possible with jumbo frames. Disable jumbos or enable only one of the receive offload features.\n");
5998 return -EINVAL;
6001 netdev->features = features;
6003 if (netif_running(netdev))
6004 e1000e_reinit_locked(adapter);
6005 else
6006 e1000e_reset(adapter);
6008 return 0;
6011 static const struct net_device_ops e1000e_netdev_ops = {
6012 .ndo_open = e1000_open,
6013 .ndo_stop = e1000_close,
6014 .ndo_start_xmit = e1000_xmit_frame,
6015 .ndo_get_stats64 = e1000e_get_stats64,
6016 .ndo_set_rx_mode = e1000e_set_rx_mode,
6017 .ndo_set_mac_address = e1000_set_mac,
6018 .ndo_change_mtu = e1000_change_mtu,
6019 .ndo_do_ioctl = e1000_ioctl,
6020 .ndo_tx_timeout = e1000_tx_timeout,
6021 .ndo_validate_addr = eth_validate_addr,
6023 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6024 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6025 #ifdef CONFIG_NET_POLL_CONTROLLER
6026 .ndo_poll_controller = e1000_netpoll,
6027 #endif
6028 .ndo_set_features = e1000_set_features,
6032 * e1000_probe - Device Initialization Routine
6033 * @pdev: PCI device information struct
6034 * @ent: entry in e1000_pci_tbl
6036 * Returns 0 on success, negative on failure
6038 * e1000_probe initializes an adapter identified by a pci_dev structure.
6039 * The OS initialization, configuring of the adapter private structure,
6040 * and a hardware reset occur.
6042 static int __devinit e1000_probe(struct pci_dev *pdev,
6043 const struct pci_device_id *ent)
6045 struct net_device *netdev;
6046 struct e1000_adapter *adapter;
6047 struct e1000_hw *hw;
6048 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
6049 resource_size_t mmio_start, mmio_len;
6050 resource_size_t flash_start, flash_len;
6052 static int cards_found;
6053 u16 aspm_disable_flag = 0;
6054 int i, err, pci_using_dac;
6055 u16 eeprom_data = 0;
6056 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6058 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6059 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6060 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
6061 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6062 if (aspm_disable_flag)
6063 e1000e_disable_aspm(pdev, aspm_disable_flag);
6065 err = pci_enable_device_mem(pdev);
6066 if (err)
6067 return err;
6069 pci_using_dac = 0;
6070 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
6071 if (!err) {
6072 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
6073 if (!err)
6074 pci_using_dac = 1;
6075 } else {
6076 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
6077 if (err) {
6078 err = dma_set_coherent_mask(&pdev->dev,
6079 DMA_BIT_MASK(32));
6080 if (err) {
6081 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
6082 goto err_dma;
6087 err = pci_request_selected_regions_exclusive(pdev,
6088 pci_select_bars(pdev, IORESOURCE_MEM),
6089 e1000e_driver_name);
6090 if (err)
6091 goto err_pci_reg;
6093 /* AER (Advanced Error Reporting) hooks */
6094 pci_enable_pcie_error_reporting(pdev);
6096 pci_set_master(pdev);
6097 /* PCI config space info */
6098 err = pci_save_state(pdev);
6099 if (err)
6100 goto err_alloc_etherdev;
6102 err = -ENOMEM;
6103 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6104 if (!netdev)
6105 goto err_alloc_etherdev;
6107 SET_NETDEV_DEV(netdev, &pdev->dev);
6109 netdev->irq = pdev->irq;
6111 pci_set_drvdata(pdev, netdev);
6112 adapter = netdev_priv(netdev);
6113 hw = &adapter->hw;
6114 adapter->netdev = netdev;
6115 adapter->pdev = pdev;
6116 adapter->ei = ei;
6117 adapter->pba = ei->pba;
6118 adapter->flags = ei->flags;
6119 adapter->flags2 = ei->flags2;
6120 adapter->hw.adapter = adapter;
6121 adapter->hw.mac.type = ei->mac;
6122 adapter->max_hw_frame_size = ei->max_hw_frame_size;
6123 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6125 mmio_start = pci_resource_start(pdev, 0);
6126 mmio_len = pci_resource_len(pdev, 0);
6128 err = -EIO;
6129 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6130 if (!adapter->hw.hw_addr)
6131 goto err_ioremap;
6133 if ((adapter->flags & FLAG_HAS_FLASH) &&
6134 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6135 flash_start = pci_resource_start(pdev, 1);
6136 flash_len = pci_resource_len(pdev, 1);
6137 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6138 if (!adapter->hw.flash_address)
6139 goto err_flashmap;
6142 /* construct the net_device struct */
6143 netdev->netdev_ops = &e1000e_netdev_ops;
6144 e1000e_set_ethtool_ops(netdev);
6145 netdev->watchdog_timeo = 5 * HZ;
6146 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
6147 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
6149 netdev->mem_start = mmio_start;
6150 netdev->mem_end = mmio_start + mmio_len;
6152 adapter->bd_number = cards_found++;
6154 e1000e_check_options(adapter);
6156 /* setup adapter struct */
6157 err = e1000_sw_init(adapter);
6158 if (err)
6159 goto err_sw_init;
6161 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6162 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6163 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6165 err = ei->get_variants(adapter);
6166 if (err)
6167 goto err_hw_init;
6169 if ((adapter->flags & FLAG_IS_ICH) &&
6170 (adapter->flags & FLAG_READ_ONLY_NVM))
6171 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6173 hw->mac.ops.get_bus_info(&adapter->hw);
6175 adapter->hw.phy.autoneg_wait_to_complete = 0;
6177 /* Copper options */
6178 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
6179 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6180 adapter->hw.phy.disable_polarity_correction = 0;
6181 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6184 if (e1000_check_reset_block(&adapter->hw))
6185 e_info("PHY reset is blocked due to SOL/IDER session.\n");
6187 /* Set initial default active device features */
6188 netdev->features = (NETIF_F_SG |
6189 NETIF_F_HW_VLAN_RX |
6190 NETIF_F_HW_VLAN_TX |
6191 NETIF_F_TSO |
6192 NETIF_F_TSO6 |
6193 NETIF_F_RXHASH |
6194 NETIF_F_RXCSUM |
6195 NETIF_F_HW_CSUM);
6197 /* Set user-changeable features (subset of all device features) */
6198 netdev->hw_features = netdev->features;
6200 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6201 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6203 netdev->vlan_features |= (NETIF_F_SG |
6204 NETIF_F_TSO |
6205 NETIF_F_TSO6 |
6206 NETIF_F_HW_CSUM);
6208 netdev->priv_flags |= IFF_UNICAST_FLT;
6210 if (pci_using_dac) {
6211 netdev->features |= NETIF_F_HIGHDMA;
6212 netdev->vlan_features |= NETIF_F_HIGHDMA;
6215 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6216 adapter->flags |= FLAG_MNG_PT_ENABLED;
6219 * before reading the NVM, reset the controller to
6220 * put the device in a known good starting state
6222 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6225 * systems with ASPM and others may see the checksum fail on the first
6226 * attempt. Let's give it a few tries
6228 for (i = 0;; i++) {
6229 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6230 break;
6231 if (i == 2) {
6232 e_err("The NVM Checksum Is Not Valid\n");
6233 err = -EIO;
6234 goto err_eeprom;
6238 e1000_eeprom_checks(adapter);
6240 /* copy the MAC address */
6241 if (e1000e_read_mac_addr(&adapter->hw))
6242 e_err("NVM Read Error while reading MAC address\n");
6244 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6245 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6247 if (!is_valid_ether_addr(netdev->perm_addr)) {
6248 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
6249 err = -EIO;
6250 goto err_eeprom;
6253 init_timer(&adapter->watchdog_timer);
6254 adapter->watchdog_timer.function = e1000_watchdog;
6255 adapter->watchdog_timer.data = (unsigned long) adapter;
6257 init_timer(&adapter->phy_info_timer);
6258 adapter->phy_info_timer.function = e1000_update_phy_info;
6259 adapter->phy_info_timer.data = (unsigned long) adapter;
6261 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6262 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
6263 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6264 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
6265 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
6267 /* Initialize link parameters. User can change them with ethtool */
6268 adapter->hw.mac.autoneg = 1;
6269 adapter->fc_autoneg = true;
6270 adapter->hw.fc.requested_mode = e1000_fc_default;
6271 adapter->hw.fc.current_mode = e1000_fc_default;
6272 adapter->hw.phy.autoneg_advertised = 0x2f;
6274 /* ring size defaults */
6275 adapter->rx_ring->count = 256;
6276 adapter->tx_ring->count = 256;
6279 * Initial Wake on LAN setting - If APM wake is enabled in
6280 * the EEPROM, enable the ACPI Magic Packet filter
6282 if (adapter->flags & FLAG_APME_IN_WUC) {
6283 /* APME bit in EEPROM is mapped to WUC.APME */
6284 eeprom_data = er32(WUC);
6285 eeprom_apme_mask = E1000_WUC_APME;
6286 if ((hw->mac.type > e1000_ich10lan) &&
6287 (eeprom_data & E1000_WUC_PHY_WAKE))
6288 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
6289 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6290 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6291 (adapter->hw.bus.func == 1))
6292 e1000_read_nvm(&adapter->hw,
6293 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6294 else
6295 e1000_read_nvm(&adapter->hw,
6296 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6299 /* fetch WoL from EEPROM */
6300 if (eeprom_data & eeprom_apme_mask)
6301 adapter->eeprom_wol |= E1000_WUFC_MAG;
6304 * now that we have the eeprom settings, apply the special cases
6305 * where the eeprom may be wrong or the board simply won't support
6306 * wake on lan on a particular port
6308 if (!(adapter->flags & FLAG_HAS_WOL))
6309 adapter->eeprom_wol = 0;
6311 /* initialize the wol settings based on the eeprom settings */
6312 adapter->wol = adapter->eeprom_wol;
6313 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
6315 /* save off EEPROM version number */
6316 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6318 /* reset the hardware with the new settings */
6319 e1000e_reset(adapter);
6322 * If the controller has AMT, do not set DRV_LOAD until the interface
6323 * is up. For all other cases, let the f/w know that the h/w is now
6324 * under the control of the driver.
6326 if (!(adapter->flags & FLAG_HAS_AMT))
6327 e1000e_get_hw_control(adapter);
6329 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
6330 err = register_netdev(netdev);
6331 if (err)
6332 goto err_register;
6334 /* carrier off reporting is important to ethtool even BEFORE open */
6335 netif_carrier_off(netdev);
6337 e1000_print_device_info(adapter);
6339 if (pci_dev_run_wake(pdev))
6340 pm_runtime_put_noidle(&pdev->dev);
6342 return 0;
6344 err_register:
6345 if (!(adapter->flags & FLAG_HAS_AMT))
6346 e1000e_release_hw_control(adapter);
6347 err_eeprom:
6348 if (!e1000_check_reset_block(&adapter->hw))
6349 e1000_phy_hw_reset(&adapter->hw);
6350 err_hw_init:
6351 kfree(adapter->tx_ring);
6352 kfree(adapter->rx_ring);
6353 err_sw_init:
6354 if (adapter->hw.flash_address)
6355 iounmap(adapter->hw.flash_address);
6356 e1000e_reset_interrupt_capability(adapter);
6357 err_flashmap:
6358 iounmap(adapter->hw.hw_addr);
6359 err_ioremap:
6360 free_netdev(netdev);
6361 err_alloc_etherdev:
6362 pci_release_selected_regions(pdev,
6363 pci_select_bars(pdev, IORESOURCE_MEM));
6364 err_pci_reg:
6365 err_dma:
6366 pci_disable_device(pdev);
6367 return err;
6371 * e1000_remove - Device Removal Routine
6372 * @pdev: PCI device information struct
6374 * e1000_remove is called by the PCI subsystem to alert the driver
6375 * that it should release a PCI device. The could be caused by a
6376 * Hot-Plug event, or because the driver is going to be removed from
6377 * memory.
6379 static void __devexit e1000_remove(struct pci_dev *pdev)
6381 struct net_device *netdev = pci_get_drvdata(pdev);
6382 struct e1000_adapter *adapter = netdev_priv(netdev);
6383 bool down = test_bit(__E1000_DOWN, &adapter->state);
6386 * The timers may be rescheduled, so explicitly disable them
6387 * from being rescheduled.
6389 if (!down)
6390 set_bit(__E1000_DOWN, &adapter->state);
6391 del_timer_sync(&adapter->watchdog_timer);
6392 del_timer_sync(&adapter->phy_info_timer);
6394 cancel_work_sync(&adapter->reset_task);
6395 cancel_work_sync(&adapter->watchdog_task);
6396 cancel_work_sync(&adapter->downshift_task);
6397 cancel_work_sync(&adapter->update_phy_task);
6398 cancel_work_sync(&adapter->print_hang_task);
6400 if (!(netdev->flags & IFF_UP))
6401 e1000_power_down_phy(adapter);
6403 /* Don't lie to e1000_close() down the road. */
6404 if (!down)
6405 clear_bit(__E1000_DOWN, &adapter->state);
6406 unregister_netdev(netdev);
6408 if (pci_dev_run_wake(pdev))
6409 pm_runtime_get_noresume(&pdev->dev);
6412 * Release control of h/w to f/w. If f/w is AMT enabled, this
6413 * would have already happened in close and is redundant.
6415 e1000e_release_hw_control(adapter);
6417 e1000e_reset_interrupt_capability(adapter);
6418 kfree(adapter->tx_ring);
6419 kfree(adapter->rx_ring);
6421 iounmap(adapter->hw.hw_addr);
6422 if (adapter->hw.flash_address)
6423 iounmap(adapter->hw.flash_address);
6424 pci_release_selected_regions(pdev,
6425 pci_select_bars(pdev, IORESOURCE_MEM));
6427 free_netdev(netdev);
6429 /* AER disable */
6430 pci_disable_pcie_error_reporting(pdev);
6432 pci_disable_device(pdev);
6435 /* PCI Error Recovery (ERS) */
6436 static struct pci_error_handlers e1000_err_handler = {
6437 .error_detected = e1000_io_error_detected,
6438 .slot_reset = e1000_io_slot_reset,
6439 .resume = e1000_io_resume,
6442 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
6443 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6444 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6445 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6446 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6447 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6448 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
6449 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6450 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6451 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
6453 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6454 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6455 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6456 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
6458 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6459 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6460 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
6462 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
6463 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
6464 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
6466 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6467 board_80003es2lan },
6468 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6469 board_80003es2lan },
6470 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6471 board_80003es2lan },
6472 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6473 board_80003es2lan },
6475 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6476 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6477 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6478 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6479 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6480 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6481 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
6482 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
6484 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6485 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6486 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6487 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6488 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
6489 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
6490 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6491 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6492 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6494 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6495 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6496 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
6498 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6499 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
6500 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
6502 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6503 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6504 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6505 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6507 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6508 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6510 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
6512 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6514 #ifdef CONFIG_PM
6515 static const struct dev_pm_ops e1000_pm_ops = {
6516 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6517 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6518 e1000_runtime_resume, e1000_idle)
6520 #endif
6522 /* PCI Device API Driver */
6523 static struct pci_driver e1000_driver = {
6524 .name = e1000e_driver_name,
6525 .id_table = e1000_pci_tbl,
6526 .probe = e1000_probe,
6527 .remove = __devexit_p(e1000_remove),
6528 #ifdef CONFIG_PM
6529 .driver = {
6530 .pm = &e1000_pm_ops,
6532 #endif
6533 .shutdown = e1000_shutdown,
6534 .err_handler = &e1000_err_handler
6538 * e1000_init_module - Driver Registration Routine
6540 * e1000_init_module is the first routine called when the driver is
6541 * loaded. All it does is register with the PCI subsystem.
6543 static int __init e1000_init_module(void)
6545 int ret;
6546 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6547 e1000e_driver_version);
6548 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
6549 ret = pci_register_driver(&e1000_driver);
6551 return ret;
6553 module_init(e1000_init_module);
6556 * e1000_exit_module - Driver Exit Cleanup Routine
6558 * e1000_exit_module is called just before the driver is removed
6559 * from memory.
6561 static void __exit e1000_exit_module(void)
6563 pci_unregister_driver(&e1000_driver);
6565 module_exit(e1000_exit_module);
6568 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6569 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6570 MODULE_LICENSE("GPL");
6571 MODULE_VERSION(DRV_VERSION);
6573 /* e1000_main.c */