blob: 174633c9332510a5ac62a1105d67ede853e7f2d0 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allan8544b9f2010-03-24 12:55:30 +000029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031#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/tcp.h>
40#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/mii.h>
45#include <linux/ethtool.h>
46#include <linux/if_vlan.h>
47#include <linux/cpu.h>
48#include <linux/smp.h>
Bruce Allan97ac8ca2008-04-29 09:16:05 -070049#include <linux/pm_qos_params.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000050#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000051#include <linux/aer.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070052
53#include "e1000.h"
54
Bruce Allanc14c6432010-06-16 13:28:34 +000055#define DRV_EXTRAVERSION "-k2"
56
Bruce Allanc920aa82010-12-01 08:45:24 +000057#define DRV_VERSION "1.2.20" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070058char e1000e_driver_name[] = "e1000e";
59const char e1000e_driver_version[] = DRV_VERSION;
60
61static const struct e1000_info *e1000_info_tbl[] = {
62 [board_82571] = &e1000_82571_info,
63 [board_82572] = &e1000_82572_info,
64 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070065 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000066 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070067 [board_80003es2lan] = &e1000_es2_info,
68 [board_ich8lan] = &e1000_ich8_info,
69 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070070 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000071 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000072 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070073};
74
Taku Izumi84f4ee92010-04-27 14:39:08 +000075struct e1000_reg_info {
76 u32 ofs;
77 char *name;
78};
79
Bruce Allanaf667a22010-12-31 06:10:01 +000080#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
81#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
82#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
83#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
84#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000085
Bruce Allanaf667a22010-12-31 06:10:01 +000086#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
87#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
88#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
89#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
90#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000091
92static const struct e1000_reg_info e1000_reg_info_tbl[] = {
93
94 /* General Registers */
95 {E1000_CTRL, "CTRL"},
96 {E1000_STATUS, "STATUS"},
97 {E1000_CTRL_EXT, "CTRL_EXT"},
98
99 /* Interrupt Registers */
100 {E1000_ICR, "ICR"},
101
Bruce Allanaf667a22010-12-31 06:10:01 +0000102 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000103 {E1000_RCTL, "RCTL"},
104 {E1000_RDLEN, "RDLEN"},
105 {E1000_RDH, "RDH"},
106 {E1000_RDT, "RDT"},
107 {E1000_RDTR, "RDTR"},
108 {E1000_RXDCTL(0), "RXDCTL"},
109 {E1000_ERT, "ERT"},
110 {E1000_RDBAL, "RDBAL"},
111 {E1000_RDBAH, "RDBAH"},
112 {E1000_RDFH, "RDFH"},
113 {E1000_RDFT, "RDFT"},
114 {E1000_RDFHS, "RDFHS"},
115 {E1000_RDFTS, "RDFTS"},
116 {E1000_RDFPC, "RDFPC"},
117
Bruce Allanaf667a22010-12-31 06:10:01 +0000118 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000119 {E1000_TCTL, "TCTL"},
120 {E1000_TDBAL, "TDBAL"},
121 {E1000_TDBAH, "TDBAH"},
122 {E1000_TDLEN, "TDLEN"},
123 {E1000_TDH, "TDH"},
124 {E1000_TDT, "TDT"},
125 {E1000_TIDV, "TIDV"},
126 {E1000_TXDCTL(0), "TXDCTL"},
127 {E1000_TADV, "TADV"},
128 {E1000_TARC(0), "TARC"},
129 {E1000_TDFH, "TDFH"},
130 {E1000_TDFT, "TDFT"},
131 {E1000_TDFHS, "TDFHS"},
132 {E1000_TDFTS, "TDFTS"},
133 {E1000_TDFPC, "TDFPC"},
134
135 /* List Terminator */
136 {}
137};
138
139/*
140 * e1000_regdump - register printout routine
141 */
142static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
143{
144 int n = 0;
145 char rname[16];
146 u32 regs[8];
147
148 switch (reginfo->ofs) {
149 case E1000_RXDCTL(0):
150 for (n = 0; n < 2; n++)
151 regs[n] = __er32(hw, E1000_RXDCTL(n));
152 break;
153 case E1000_TXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_TXDCTL(n));
156 break;
157 case E1000_TARC(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TARC(n));
160 break;
161 default:
162 printk(KERN_INFO "%-15s %08x\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000163 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000164 return;
165 }
166
167 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
168 printk(KERN_INFO "%-15s ", rname);
169 for (n = 0; n < 2; n++)
170 printk(KERN_CONT "%08x ", regs[n]);
171 printk(KERN_CONT "\n");
172}
173
Taku Izumi84f4ee92010-04-27 14:39:08 +0000174/*
Bruce Allanaf667a22010-12-31 06:10:01 +0000175 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Taku Izumi84f4ee92010-04-27 14:39:08 +0000176 */
177static void e1000e_dump(struct e1000_adapter *adapter)
178{
179 struct net_device *netdev = adapter->netdev;
180 struct e1000_hw *hw = &adapter->hw;
181 struct e1000_reg_info *reginfo;
182 struct e1000_ring *tx_ring = adapter->tx_ring;
183 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000184 struct my_u0 {
185 u64 a;
186 u64 b;
187 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000188 struct e1000_buffer *buffer_info;
189 struct e1000_ring *rx_ring = adapter->rx_ring;
190 union e1000_rx_desc_packet_split *rx_desc_ps;
191 struct e1000_rx_desc *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000192 struct my_u1 {
193 u64 a;
194 u64 b;
195 u64 c;
196 u64 d;
197 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000198 u32 staterr;
199 int i = 0;
200
201 if (!netif_msg_hw(adapter))
202 return;
203
204 /* Print netdevice Info */
205 if (netdev) {
206 dev_info(&adapter->pdev->dev, "Net device Info\n");
207 printk(KERN_INFO "Device Name state "
Bruce Allanaf667a22010-12-31 06:10:01 +0000208 "trans_start last_rx\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000209 printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000210 netdev->name, netdev->state, netdev->trans_start,
211 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000212 }
213
214 /* Print Registers */
215 dev_info(&adapter->pdev->dev, "Register Dump\n");
216 printk(KERN_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);
220 }
221
Bruce Allanaf667a22010-12-31 06:10:01 +0000222 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000223 if (!netdev || !netif_running(netdev))
224 goto exit;
225
Bruce Allanaf667a22010-12-31 06:10:01 +0000226 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000227 printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000228 " leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000229 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
230 printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000231 0, tx_ring->next_to_use, tx_ring->next_to_clean,
232 (unsigned long long)buffer_info->dma,
233 buffer_info->length,
234 buffer_info->next_to_watch,
235 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000236
Bruce Allanaf667a22010-12-31 06:10:01 +0000237 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000238 if (!netif_msg_tx_done(adapter))
239 goto rx_ring_summary;
240
Bruce Allanaf667a22010-12-31 06:10:01 +0000241 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000242
243 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
244 *
245 * Legacy Transmit Descriptor
246 * +--------------------------------------------------------------+
247 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
248 * +--------------------------------------------------------------+
249 * 8 | Special | CSS | Status | CMD | CSO | Length |
250 * +--------------------------------------------------------------+
251 * 63 48 47 36 35 32 31 24 23 16 15 0
252 *
253 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
254 * 63 48 47 40 39 32 31 16 15 8 7 0
255 * +----------------------------------------------------------------+
256 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
257 * +----------------------------------------------------------------+
258 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
259 * +----------------------------------------------------------------+
260 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
261 *
262 * Extended Data Descriptor (DTYP=0x1)
263 * +----------------------------------------------------------------+
264 * 0 | Buffer Address [63:0] |
265 * +----------------------------------------------------------------+
266 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
267 * +----------------------------------------------------------------+
268 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
269 */
270 printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000271 " [bi->dma ] leng ntw timestamp bi->skb "
272 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000273 printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000274 " [bi->dma ] leng ntw timestamp bi->skb "
275 "<-- Ext Context format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000276 printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000277 " [bi->dma ] leng ntw timestamp bi->skb "
278 "<-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000279 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
280 tx_desc = E1000_TX_DESC(*tx_ring, i);
281 buffer_info = &tx_ring->buffer_info[i];
282 u0 = (struct my_u0 *)tx_desc;
283 printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000284 "%04X %3X %016llX %p",
285 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
286 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), i,
Bruce Allan8eb64e62010-06-29 18:12:30 +0000287 (unsigned long long)le64_to_cpu(u0->a),
288 (unsigned long long)le64_to_cpu(u0->b),
289 (unsigned long long)buffer_info->dma,
290 buffer_info->length, buffer_info->next_to_watch,
291 (unsigned long long)buffer_info->time_stamp,
Taku Izumi84f4ee92010-04-27 14:39:08 +0000292 buffer_info->skb);
293 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
294 printk(KERN_CONT " NTC/U\n");
295 else if (i == tx_ring->next_to_use)
296 printk(KERN_CONT " NTU\n");
297 else if (i == tx_ring->next_to_clean)
298 printk(KERN_CONT " NTC\n");
299 else
300 printk(KERN_CONT "\n");
301
302 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
303 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Bruce Allanaf667a22010-12-31 06:10:01 +0000304 16, 1, phys_to_virt(buffer_info->dma),
305 buffer_info->length, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000306 }
307
Bruce Allanaf667a22010-12-31 06:10:01 +0000308 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000309rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000310 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000311 printk(KERN_INFO "Queue [NTU] [NTC]\n");
312 printk(KERN_INFO " %5d %5X %5X\n", 0,
Bruce Allanaf667a22010-12-31 06:10:01 +0000313 rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000314
Bruce Allanaf667a22010-12-31 06:10:01 +0000315 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000316 if (!netif_msg_rx_status(adapter))
317 goto exit;
318
Bruce Allanaf667a22010-12-31 06:10:01 +0000319 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000320 switch (adapter->rx_ps_pages) {
321 case 1:
322 case 2:
323 case 3:
324 /* [Extended] Packet Split Receive Descriptor Format
325 *
326 * +-----------------------------------------------------+
327 * 0 | Buffer Address 0 [63:0] |
328 * +-----------------------------------------------------+
329 * 8 | Buffer Address 1 [63:0] |
330 * +-----------------------------------------------------+
331 * 16 | Buffer Address 2 [63:0] |
332 * +-----------------------------------------------------+
333 * 24 | Buffer Address 3 [63:0] |
334 * +-----------------------------------------------------+
335 */
336 printk(KERN_INFO "R [desc] [buffer 0 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000337 "[buffer 1 63:0 ] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000338 "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] "
339 "[bi->skb] <-- Ext Pkt Split format\n");
340 /* [Extended] Receive Descriptor (Write-Back) Format
341 *
342 * 63 48 47 32 31 13 12 8 7 4 3 0
343 * +------------------------------------------------------+
344 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
345 * | Checksum | Ident | | Queue | | Type |
346 * +------------------------------------------------------+
347 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
348 * +------------------------------------------------------+
349 * 63 48 47 32 31 20 19 0
350 */
351 printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000352 "[vl l0 ee es] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000353 "[ l3 l2 l1 hs] [reserved ] ---------------- "
354 "[bi->skb] <-- Ext Rx Write-Back format\n");
355 for (i = 0; i < rx_ring->count; i++) {
356 buffer_info = &rx_ring->buffer_info[i];
357 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
358 u1 = (struct my_u1 *)rx_desc_ps;
359 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000360 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000361 if (staterr & E1000_RXD_STAT_DD) {
362 /* Descriptor Done */
363 printk(KERN_INFO "RWB[0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000364 "%016llX %016llX %016llX "
365 "---------------- %p", i,
366 (unsigned long long)le64_to_cpu(u1->a),
367 (unsigned long long)le64_to_cpu(u1->b),
368 (unsigned long long)le64_to_cpu(u1->c),
369 (unsigned long long)le64_to_cpu(u1->d),
370 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000371 } else {
372 printk(KERN_INFO "R [0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000373 "%016llX %016llX %016llX %016llX %p", i,
374 (unsigned long long)le64_to_cpu(u1->a),
375 (unsigned long long)le64_to_cpu(u1->b),
376 (unsigned long long)le64_to_cpu(u1->c),
377 (unsigned long long)le64_to_cpu(u1->d),
378 (unsigned long long)buffer_info->dma,
379 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000380
381 if (netif_msg_pktdata(adapter))
382 print_hex_dump(KERN_INFO, "",
383 DUMP_PREFIX_ADDRESS, 16, 1,
384 phys_to_virt(buffer_info->dma),
385 adapter->rx_ps_bsize0, true);
386 }
387
388 if (i == rx_ring->next_to_use)
389 printk(KERN_CONT " NTU\n");
390 else if (i == rx_ring->next_to_clean)
391 printk(KERN_CONT " NTC\n");
392 else
393 printk(KERN_CONT "\n");
394 }
395 break;
396 default:
397 case 0:
398 /* Legacy Receive Descriptor Format
399 *
400 * +-----------------------------------------------------+
401 * | Buffer Address [63:0] |
402 * +-----------------------------------------------------+
403 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
404 * +-----------------------------------------------------+
405 * 63 48 47 40 39 32 31 16 15 0
406 */
407 printk(KERN_INFO "Rl[desc] [address 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000408 "[vl er S cks ln] [bi->dma ] [bi->skb] "
409 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000410 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
411 rx_desc = E1000_RX_DESC(*rx_ring, i);
412 buffer_info = &rx_ring->buffer_info[i];
413 u0 = (struct my_u0 *)rx_desc;
414 printk(KERN_INFO "Rl[0x%03X] %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000415 "%016llX %p", i,
416 (unsigned long long)le64_to_cpu(u0->a),
417 (unsigned long long)le64_to_cpu(u0->b),
418 (unsigned long long)buffer_info->dma,
419 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000420 if (i == rx_ring->next_to_use)
421 printk(KERN_CONT " NTU\n");
422 else if (i == rx_ring->next_to_clean)
423 printk(KERN_CONT " NTC\n");
424 else
425 printk(KERN_CONT "\n");
426
427 if (netif_msg_pktdata(adapter))
428 print_hex_dump(KERN_INFO, "",
Bruce Allanaf667a22010-12-31 06:10:01 +0000429 DUMP_PREFIX_ADDRESS,
430 16, 1,
431 phys_to_virt(buffer_info->dma),
432 adapter->rx_buffer_len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000433 }
434 }
435
436exit:
437 return;
438}
439
Auke Kokbc7f75f2007-09-17 12:30:59 -0700440/**
441 * e1000_desc_unused - calculate if we have unused descriptors
442 **/
443static int e1000_desc_unused(struct e1000_ring *ring)
444{
445 if (ring->next_to_clean > ring->next_to_use)
446 return ring->next_to_clean - ring->next_to_use - 1;
447
448 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
449}
450
451/**
Bruce Allanad680762008-03-28 09:15:03 -0700452 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700453 * @adapter: board private structure
454 * @status: descriptor status field as written by hardware
455 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
456 * @skb: pointer to sk_buff to be indicated to stack
457 **/
458static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000459 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000460 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700461{
462 skb->protocol = eth_type_trans(skb, netdev);
463
464 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
Herbert Xuc405b822009-01-14 20:37:59 -0800465 vlan_gro_receive(&adapter->napi, adapter->vlgrp,
466 le16_to_cpu(vlan), skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700467 else
Herbert Xu89c88b12008-12-15 23:46:15 -0800468 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700469}
470
471/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000472 * e1000_rx_checksum - Receive Checksum Offload
Auke Kokbc7f75f2007-09-17 12:30:59 -0700473 * @adapter: board private structure
474 * @status_err: receive descriptor status and error fields
475 * @csum: receive descriptor csum field
476 * @sk_buff: socket buffer with received data
477 **/
478static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
479 u32 csum, struct sk_buff *skb)
480{
481 u16 status = (u16)status_err;
482 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700483
484 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700485
486 /* Ignore Checksum bit is set */
487 if (status & E1000_RXD_STAT_IXSM)
488 return;
489 /* TCP/UDP checksum error bit is set */
490 if (errors & E1000_RXD_ERR_TCPE) {
491 /* let the stack verify checksum errors */
492 adapter->hw_csum_err++;
493 return;
494 }
495
496 /* TCP/UDP Checksum has not been calculated */
497 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
498 return;
499
500 /* It must be a TCP or UDP packet with a valid checksum */
501 if (status & E1000_RXD_STAT_TCPCS) {
502 /* TCP checksum is good */
503 skb->ip_summed = CHECKSUM_UNNECESSARY;
504 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700505 /*
506 * IP fragment with UDP payload
507 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700508 * and then put the value in host order for further stack use.
509 */
Al Viroa39fe742007-12-11 19:50:34 +0000510 __sum16 sum = (__force __sum16)htons(csum);
511 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700512 skb->ip_summed = CHECKSUM_COMPLETE;
513 }
514 adapter->hw_csum_good++;
515}
516
517/**
518 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
519 * @adapter: address of board private structure
520 **/
521static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
522 int cleaned_count)
523{
524 struct net_device *netdev = adapter->netdev;
525 struct pci_dev *pdev = adapter->pdev;
526 struct e1000_ring *rx_ring = adapter->rx_ring;
527 struct e1000_rx_desc *rx_desc;
528 struct e1000_buffer *buffer_info;
529 struct sk_buff *skb;
530 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000531 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532
533 i = rx_ring->next_to_use;
534 buffer_info = &rx_ring->buffer_info[i];
535
536 while (cleaned_count--) {
537 skb = buffer_info->skb;
538 if (skb) {
539 skb_trim(skb, 0);
540 goto map_skb;
541 }
542
Eric Dumazet89d71a62009-10-13 05:34:20 +0000543 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700544 if (!skb) {
545 /* Better luck next round */
546 adapter->alloc_rx_buff_failed++;
547 break;
548 }
549
Auke Kokbc7f75f2007-09-17 12:30:59 -0700550 buffer_info->skb = skb;
551map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000552 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700553 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000554 DMA_FROM_DEVICE);
555 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000556 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557 adapter->rx_dma_failed++;
558 break;
559 }
560
561 rx_desc = E1000_RX_DESC(*rx_ring, i);
562 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
563
Tom Herbert50849d72010-05-05 14:02:49 +0000564 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
565 /*
566 * Force memory writes to complete before letting h/w
567 * know there are new descriptors to fetch. (Only
568 * applicable for weak-ordered memory model archs,
569 * such as IA-64).
570 */
571 wmb();
572 writel(i, adapter->hw.hw_addr + rx_ring->tail);
573 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700574 i++;
575 if (i == rx_ring->count)
576 i = 0;
577 buffer_info = &rx_ring->buffer_info[i];
578 }
579
Tom Herbert50849d72010-05-05 14:02:49 +0000580 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700581}
582
583/**
584 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
585 * @adapter: address of board private structure
586 **/
587static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
588 int cleaned_count)
589{
590 struct net_device *netdev = adapter->netdev;
591 struct pci_dev *pdev = adapter->pdev;
592 union e1000_rx_desc_packet_split *rx_desc;
593 struct e1000_ring *rx_ring = adapter->rx_ring;
594 struct e1000_buffer *buffer_info;
595 struct e1000_ps_page *ps_page;
596 struct sk_buff *skb;
597 unsigned int i, j;
598
599 i = rx_ring->next_to_use;
600 buffer_info = &rx_ring->buffer_info[i];
601
602 while (cleaned_count--) {
603 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
604
605 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700606 ps_page = &buffer_info->ps_pages[j];
607 if (j >= adapter->rx_ps_pages) {
608 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000609 rx_desc->read.buffer_addr[j + 1] =
610 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700611 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700612 }
Auke Kok47f44e42007-10-25 13:57:44 -0700613 if (!ps_page->page) {
614 ps_page->page = alloc_page(GFP_ATOMIC);
615 if (!ps_page->page) {
616 adapter->alloc_rx_buff_failed++;
617 goto no_buffers;
618 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000619 ps_page->dma = dma_map_page(&pdev->dev,
620 ps_page->page,
621 0, PAGE_SIZE,
622 DMA_FROM_DEVICE);
623 if (dma_mapping_error(&pdev->dev,
624 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700625 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000626 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700627 adapter->rx_dma_failed++;
628 goto no_buffers;
629 }
630 }
631 /*
632 * Refresh the desc even if buffer_addrs
633 * didn't change because each write-back
634 * erases this info.
635 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000636 rx_desc->read.buffer_addr[j + 1] =
637 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700638 }
639
Eric Dumazet89d71a62009-10-13 05:34:20 +0000640 skb = netdev_alloc_skb_ip_align(netdev,
641 adapter->rx_ps_bsize0);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700642
643 if (!skb) {
644 adapter->alloc_rx_buff_failed++;
645 break;
646 }
647
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000649 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700650 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000651 DMA_FROM_DEVICE);
652 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000653 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700654 adapter->rx_dma_failed++;
655 /* cleanup skb */
656 dev_kfree_skb_any(skb);
657 buffer_info->skb = NULL;
658 break;
659 }
660
661 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
662
Tom Herbert50849d72010-05-05 14:02:49 +0000663 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
664 /*
665 * Force memory writes to complete before letting h/w
666 * know there are new descriptors to fetch. (Only
667 * applicable for weak-ordered memory model archs,
668 * such as IA-64).
669 */
670 wmb();
Bruce Allanaf667a22010-12-31 06:10:01 +0000671 writel(i << 1, adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000672 }
673
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674 i++;
675 if (i == rx_ring->count)
676 i = 0;
677 buffer_info = &rx_ring->buffer_info[i];
678 }
679
680no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000681 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700682}
683
684/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700685 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
686 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700687 * @cleaned_count: number of buffers to allocate this pass
688 **/
689
690static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
691 int cleaned_count)
692{
693 struct net_device *netdev = adapter->netdev;
694 struct pci_dev *pdev = adapter->pdev;
695 struct e1000_rx_desc *rx_desc;
696 struct e1000_ring *rx_ring = adapter->rx_ring;
697 struct e1000_buffer *buffer_info;
698 struct sk_buff *skb;
699 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000700 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700701
702 i = rx_ring->next_to_use;
703 buffer_info = &rx_ring->buffer_info[i];
704
705 while (cleaned_count--) {
706 skb = buffer_info->skb;
707 if (skb) {
708 skb_trim(skb, 0);
709 goto check_page;
710 }
711
Eric Dumazet89d71a62009-10-13 05:34:20 +0000712 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700713 if (unlikely(!skb)) {
714 /* Better luck next round */
715 adapter->alloc_rx_buff_failed++;
716 break;
717 }
718
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700719 buffer_info->skb = skb;
720check_page:
721 /* allocate a new page if necessary */
722 if (!buffer_info->page) {
723 buffer_info->page = alloc_page(GFP_ATOMIC);
724 if (unlikely(!buffer_info->page)) {
725 adapter->alloc_rx_buff_failed++;
726 break;
727 }
728 }
729
730 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000731 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700732 buffer_info->page, 0,
733 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000734 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700735
736 rx_desc = E1000_RX_DESC(*rx_ring, i);
737 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
738
739 if (unlikely(++i == rx_ring->count))
740 i = 0;
741 buffer_info = &rx_ring->buffer_info[i];
742 }
743
744 if (likely(rx_ring->next_to_use != i)) {
745 rx_ring->next_to_use = i;
746 if (unlikely(i-- == 0))
747 i = (rx_ring->count - 1);
748
749 /* Force memory writes to complete before letting h/w
750 * know there are new descriptors to fetch. (Only
751 * applicable for weak-ordered memory model archs,
752 * such as IA-64). */
753 wmb();
754 writel(i, adapter->hw.hw_addr + rx_ring->tail);
755 }
756}
757
758/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700759 * e1000_clean_rx_irq - Send received data up the network stack; legacy
760 * @adapter: board private structure
761 *
762 * the return value indicates whether actual cleaning was done, there
763 * is no guarantee that everything was cleaned
764 **/
765static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
766 int *work_done, int work_to_do)
767{
768 struct net_device *netdev = adapter->netdev;
769 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000770 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700771 struct e1000_ring *rx_ring = adapter->rx_ring;
772 struct e1000_rx_desc *rx_desc, *next_rxd;
773 struct e1000_buffer *buffer_info, *next_buffer;
774 u32 length;
775 unsigned int i;
776 int cleaned_count = 0;
777 bool cleaned = 0;
778 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
779
780 i = rx_ring->next_to_clean;
781 rx_desc = E1000_RX_DESC(*rx_ring, i);
782 buffer_info = &rx_ring->buffer_info[i];
783
784 while (rx_desc->status & E1000_RXD_STAT_DD) {
785 struct sk_buff *skb;
786 u8 status;
787
788 if (*work_done >= work_to_do)
789 break;
790 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000791 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700792
793 status = rx_desc->status;
794 skb = buffer_info->skb;
795 buffer_info->skb = NULL;
796
797 prefetch(skb->data - NET_IP_ALIGN);
798
799 i++;
800 if (i == rx_ring->count)
801 i = 0;
802 next_rxd = E1000_RX_DESC(*rx_ring, i);
803 prefetch(next_rxd);
804
805 next_buffer = &rx_ring->buffer_info[i];
806
807 cleaned = 1;
808 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000809 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810 buffer_info->dma,
811 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000812 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700813 buffer_info->dma = 0;
814
815 length = le16_to_cpu(rx_desc->length);
816
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000817 /*
818 * !EOP means multiple descriptors were used to store a single
819 * packet, if that's the case we need to toss it. In fact, we
820 * need to toss every packet with the EOP bit clear and the
821 * next frame that _does_ have the EOP bit set, as it is by
822 * definition only a frame fragment
823 */
824 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
825 adapter->flags2 |= FLAG2_IS_DISCARDING;
826
827 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700828 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000829 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700830 /* recycle */
831 buffer_info->skb = skb;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000832 if (status & E1000_RXD_STAT_EOP)
833 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700834 goto next_desc;
835 }
836
837 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
838 /* recycle */
839 buffer_info->skb = skb;
840 goto next_desc;
841 }
842
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000843 /* adjust length to remove Ethernet CRC */
844 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
845 length -= 4;
846
Auke Kokbc7f75f2007-09-17 12:30:59 -0700847 total_rx_bytes += length;
848 total_rx_packets++;
849
Bruce Allanad680762008-03-28 09:15:03 -0700850 /*
851 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700853 * of reassembly being done in the stack
854 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700855 if (length < copybreak) {
856 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000857 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700858 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700859 skb_copy_to_linear_data_offset(new_skb,
860 -NET_IP_ALIGN,
861 (skb->data -
862 NET_IP_ALIGN),
863 (length +
864 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700865 /* save the skb in buffer_info as good */
866 buffer_info->skb = skb;
867 skb = new_skb;
868 }
869 /* else just continue with the old one */
870 }
871 /* end copybreak code */
872 skb_put(skb, length);
873
874 /* Receive Checksum Offload */
875 e1000_rx_checksum(adapter,
876 (u32)(status) |
877 ((u32)(rx_desc->errors) << 24),
878 le16_to_cpu(rx_desc->csum), skb);
879
880 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
881
882next_desc:
883 rx_desc->status = 0;
884
885 /* return some buffers to hardware, one at a time is too slow */
886 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
887 adapter->alloc_rx_buf(adapter, cleaned_count);
888 cleaned_count = 0;
889 }
890
891 /* use prefetched values */
892 rx_desc = next_rxd;
893 buffer_info = next_buffer;
894 }
895 rx_ring->next_to_clean = i;
896
897 cleaned_count = e1000_desc_unused(rx_ring);
898 if (cleaned_count)
899 adapter->alloc_rx_buf(adapter, cleaned_count);
900
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700902 adapter->total_rx_packets += total_rx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +0000903 netdev->stats.rx_bytes += total_rx_bytes;
904 netdev->stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700905 return cleaned;
906}
907
Auke Kokbc7f75f2007-09-17 12:30:59 -0700908static void e1000_put_txbuf(struct e1000_adapter *adapter,
909 struct e1000_buffer *buffer_info)
910{
Alexander Duyck03b13202009-12-02 16:45:31 +0000911 if (buffer_info->dma) {
912 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +0000913 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
914 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000915 else
Nick Nunley0be3f552010-04-27 13:09:05 +0000916 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
917 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000918 buffer_info->dma = 0;
919 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700920 if (buffer_info->skb) {
921 dev_kfree_skb_any(buffer_info->skb);
922 buffer_info->skb = NULL;
923 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000924 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700925}
926
Bruce Allan41cec6f2009-11-20 23:28:56 +0000927static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700928{
Bruce Allan41cec6f2009-11-20 23:28:56 +0000929 struct e1000_adapter *adapter = container_of(work,
930 struct e1000_adapter,
931 print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932 struct e1000_ring *tx_ring = adapter->tx_ring;
933 unsigned int i = tx_ring->next_to_clean;
934 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
935 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +0000936 struct e1000_hw *hw = &adapter->hw;
937 u16 phy_status, phy_1000t_status, phy_ext_status;
938 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939
Jesse Brandeburg615b32a2011-02-02 10:19:45 +0000940 if (test_bit(__E1000_DOWN, &adapter->state))
941 return;
942
Bruce Allan41cec6f2009-11-20 23:28:56 +0000943 e1e_rphy(hw, PHY_STATUS, &phy_status);
944 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
945 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
946
947 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
948
949 /* detected Hardware unit hang */
950 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700951 " TDH <%x>\n"
952 " TDT <%x>\n"
953 " next_to_use <%x>\n"
954 " next_to_clean <%x>\n"
955 "buffer_info[next_to_clean]:\n"
956 " time_stamp <%lx>\n"
957 " next_to_watch <%x>\n"
958 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +0000959 " next_to_watch.status <%x>\n"
960 "MAC Status <%x>\n"
961 "PHY Status <%x>\n"
962 "PHY 1000BASE-T Status <%x>\n"
963 "PHY Extended Status <%x>\n"
964 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700965 readl(adapter->hw.hw_addr + tx_ring->head),
966 readl(adapter->hw.hw_addr + tx_ring->tail),
967 tx_ring->next_to_use,
968 tx_ring->next_to_clean,
969 tx_ring->buffer_info[eop].time_stamp,
970 eop,
971 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +0000972 eop_desc->upper.fields.status,
973 er32(STATUS),
974 phy_status,
975 phy_1000t_status,
976 phy_ext_status,
977 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978}
979
980/**
981 * e1000_clean_tx_irq - Reclaim resources after transmit completes
982 * @adapter: board private structure
983 *
984 * the return value indicates whether actual cleaning was done, there
985 * is no guarantee that everything was cleaned
986 **/
987static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
988{
989 struct net_device *netdev = adapter->netdev;
990 struct e1000_hw *hw = &adapter->hw;
991 struct e1000_ring *tx_ring = adapter->tx_ring;
992 struct e1000_tx_desc *tx_desc, *eop_desc;
993 struct e1000_buffer *buffer_info;
994 unsigned int i, eop;
995 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700996 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
997
998 i = tx_ring->next_to_clean;
999 eop = tx_ring->buffer_info[i].next_to_watch;
1000 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1001
Alexander Duyck12d04a32009-03-25 22:05:03 +00001002 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1003 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001004 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001005 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001006 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001007 tx_desc = E1000_TX_DESC(*tx_ring, i);
1008 buffer_info = &tx_ring->buffer_info[i];
1009 cleaned = (i == eop);
1010
1011 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001012 total_tx_packets += buffer_info->segs;
1013 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014 }
1015
1016 e1000_put_txbuf(adapter, buffer_info);
1017 tx_desc->upper.data = 0;
1018
1019 i++;
1020 if (i == tx_ring->count)
1021 i = 0;
1022 }
1023
Terry Loftindac87612010-04-09 10:29:49 +00001024 if (i == tx_ring->next_to_use)
1025 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026 eop = tx_ring->buffer_info[i].next_to_watch;
1027 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001028 }
1029
1030 tx_ring->next_to_clean = i;
1031
1032#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001033 if (count && netif_carrier_ok(netdev) &&
1034 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035 /* Make sure that anybody stopping the queue after this
1036 * sees the new next_to_clean.
1037 */
1038 smp_mb();
1039
1040 if (netif_queue_stopped(netdev) &&
1041 !(test_bit(__E1000_DOWN, &adapter->state))) {
1042 netif_wake_queue(netdev);
1043 ++adapter->restart_queue;
1044 }
1045 }
1046
1047 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001048 /*
1049 * Detect a transmit hang in hardware, this serializes the
1050 * check with the clearing of time_stamp and movement of i
1051 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001052 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001053 if (tx_ring->buffer_info[i].time_stamp &&
1054 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001055 + (adapter->tx_timeout_factor * HZ)) &&
1056 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001057 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058 netif_stop_queue(netdev);
1059 }
1060 }
1061 adapter->total_tx_bytes += total_tx_bytes;
1062 adapter->total_tx_packets += total_tx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +00001063 netdev->stats.tx_bytes += total_tx_bytes;
1064 netdev->stats.tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001065 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001066}
1067
1068/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001069 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1070 * @adapter: board private structure
1071 *
1072 * the return value indicates whether actual cleaning was done, there
1073 * is no guarantee that everything was cleaned
1074 **/
1075static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1076 int *work_done, int work_to_do)
1077{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001078 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001079 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1080 struct net_device *netdev = adapter->netdev;
1081 struct pci_dev *pdev = adapter->pdev;
1082 struct e1000_ring *rx_ring = adapter->rx_ring;
1083 struct e1000_buffer *buffer_info, *next_buffer;
1084 struct e1000_ps_page *ps_page;
1085 struct sk_buff *skb;
1086 unsigned int i, j;
1087 u32 length, staterr;
1088 int cleaned_count = 0;
1089 bool cleaned = 0;
1090 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1091
1092 i = rx_ring->next_to_clean;
1093 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1094 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1095 buffer_info = &rx_ring->buffer_info[i];
1096
1097 while (staterr & E1000_RXD_STAT_DD) {
1098 if (*work_done >= work_to_do)
1099 break;
1100 (*work_done)++;
1101 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001102 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001103
1104 /* in the packet split case this is header only */
1105 prefetch(skb->data - NET_IP_ALIGN);
1106
1107 i++;
1108 if (i == rx_ring->count)
1109 i = 0;
1110 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1111 prefetch(next_rxd);
1112
1113 next_buffer = &rx_ring->buffer_info[i];
1114
1115 cleaned = 1;
1116 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001117 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001118 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001119 buffer_info->dma = 0;
1120
Bruce Allanaf667a22010-12-31 06:10:01 +00001121 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001122 if (!(staterr & E1000_RXD_STAT_EOP))
1123 adapter->flags2 |= FLAG2_IS_DISCARDING;
1124
1125 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001126 e_dbg("Packet Split buffers didn't pick up the full "
1127 "packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001129 if (staterr & E1000_RXD_STAT_EOP)
1130 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001131 goto next_desc;
1132 }
1133
1134 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1135 dev_kfree_skb_irq(skb);
1136 goto next_desc;
1137 }
1138
1139 length = le16_to_cpu(rx_desc->wb.middle.length0);
1140
1141 if (!length) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001142 e_dbg("Last part of the packet spanning multiple "
1143 "descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144 dev_kfree_skb_irq(skb);
1145 goto next_desc;
1146 }
1147
1148 /* Good Receive */
1149 skb_put(skb, length);
1150
1151 {
Bruce Allanad680762008-03-28 09:15:03 -07001152 /*
1153 * this looks ugly, but it seems compiler issues make it
1154 * more efficient than reusing j
1155 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001156 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1157
Bruce Allanad680762008-03-28 09:15:03 -07001158 /*
1159 * page alloc/put takes too long and effects small packet
1160 * throughput, so unsplit small packets and save the alloc/put
1161 * only valid in softirq (napi) context to call kmap_*
1162 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 if (l1 && (l1 <= copybreak) &&
1164 ((length + l1) <= adapter->rx_ps_bsize0)) {
1165 u8 *vaddr;
1166
Auke Kok47f44e42007-10-25 13:57:44 -07001167 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001168
Bruce Allanad680762008-03-28 09:15:03 -07001169 /*
1170 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001171 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001172 * very long
1173 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001174 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1175 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001176 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1177 memcpy(skb_tail_pointer(skb), vaddr, l1);
1178 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001179 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1180 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001181
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001182 /* remove the CRC */
1183 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1184 l1 -= 4;
1185
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186 skb_put(skb, l1);
1187 goto copydone;
1188 } /* if */
1189 }
1190
1191 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1192 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1193 if (!length)
1194 break;
1195
Auke Kok47f44e42007-10-25 13:57:44 -07001196 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001197 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1198 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001199 ps_page->dma = 0;
1200 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1201 ps_page->page = NULL;
1202 skb->len += length;
1203 skb->data_len += length;
1204 skb->truesize += length;
1205 }
1206
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001207 /* strip the ethernet crc, problem is we're using pages now so
1208 * this whole operation can get a little cpu intensive
1209 */
1210 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1211 pskb_trim(skb, skb->len - 4);
1212
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213copydone:
1214 total_rx_bytes += skb->len;
1215 total_rx_packets++;
1216
1217 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1218 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1219
1220 if (rx_desc->wb.upper.header_status &
1221 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1222 adapter->rx_hdr_split++;
1223
1224 e1000_receive_skb(adapter, netdev, skb,
1225 staterr, rx_desc->wb.middle.vlan);
1226
1227next_desc:
1228 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1229 buffer_info->skb = NULL;
1230
1231 /* return some buffers to hardware, one at a time is too slow */
1232 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1233 adapter->alloc_rx_buf(adapter, cleaned_count);
1234 cleaned_count = 0;
1235 }
1236
1237 /* use prefetched values */
1238 rx_desc = next_rxd;
1239 buffer_info = next_buffer;
1240
1241 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1242 }
1243 rx_ring->next_to_clean = i;
1244
1245 cleaned_count = e1000_desc_unused(rx_ring);
1246 if (cleaned_count)
1247 adapter->alloc_rx_buf(adapter, cleaned_count);
1248
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001250 adapter->total_rx_packets += total_rx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +00001251 netdev->stats.rx_bytes += total_rx_bytes;
1252 netdev->stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001253 return cleaned;
1254}
1255
1256/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001257 * e1000_consume_page - helper function
1258 **/
1259static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1260 u16 length)
1261{
1262 bi->page = NULL;
1263 skb->len += length;
1264 skb->data_len += length;
1265 skb->truesize += length;
1266}
1267
1268/**
1269 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1270 * @adapter: board private structure
1271 *
1272 * the return value indicates whether actual cleaning was done, there
1273 * is no guarantee that everything was cleaned
1274 **/
1275
1276static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1277 int *work_done, int work_to_do)
1278{
1279 struct net_device *netdev = adapter->netdev;
1280 struct pci_dev *pdev = adapter->pdev;
1281 struct e1000_ring *rx_ring = adapter->rx_ring;
1282 struct e1000_rx_desc *rx_desc, *next_rxd;
1283 struct e1000_buffer *buffer_info, *next_buffer;
1284 u32 length;
1285 unsigned int i;
1286 int cleaned_count = 0;
1287 bool cleaned = false;
1288 unsigned int total_rx_bytes=0, total_rx_packets=0;
1289
1290 i = rx_ring->next_to_clean;
1291 rx_desc = E1000_RX_DESC(*rx_ring, i);
1292 buffer_info = &rx_ring->buffer_info[i];
1293
1294 while (rx_desc->status & E1000_RXD_STAT_DD) {
1295 struct sk_buff *skb;
1296 u8 status;
1297
1298 if (*work_done >= work_to_do)
1299 break;
1300 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001301 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001302
1303 status = rx_desc->status;
1304 skb = buffer_info->skb;
1305 buffer_info->skb = NULL;
1306
1307 ++i;
1308 if (i == rx_ring->count)
1309 i = 0;
1310 next_rxd = E1000_RX_DESC(*rx_ring, i);
1311 prefetch(next_rxd);
1312
1313 next_buffer = &rx_ring->buffer_info[i];
1314
1315 cleaned = true;
1316 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001317 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1318 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001319 buffer_info->dma = 0;
1320
1321 length = le16_to_cpu(rx_desc->length);
1322
1323 /* errors is only valid for DD + EOP descriptors */
1324 if (unlikely((status & E1000_RXD_STAT_EOP) &&
1325 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
1326 /* recycle both page and skb */
1327 buffer_info->skb = skb;
1328 /* an error means any chain goes out the window
1329 * too */
1330 if (rx_ring->rx_skb_top)
1331 dev_kfree_skb(rx_ring->rx_skb_top);
1332 rx_ring->rx_skb_top = NULL;
1333 goto next_desc;
1334 }
1335
Bruce Allanf0f1a172010-12-11 05:53:32 +00001336#define rxtop (rx_ring->rx_skb_top)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001337 if (!(status & E1000_RXD_STAT_EOP)) {
1338 /* this descriptor is only the beginning (or middle) */
1339 if (!rxtop) {
1340 /* this is the beginning of a chain */
1341 rxtop = skb;
1342 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1343 0, length);
1344 } else {
1345 /* this is the middle of a chain */
1346 skb_fill_page_desc(rxtop,
1347 skb_shinfo(rxtop)->nr_frags,
1348 buffer_info->page, 0, length);
1349 /* re-use the skb, only consumed the page */
1350 buffer_info->skb = skb;
1351 }
1352 e1000_consume_page(buffer_info, rxtop, length);
1353 goto next_desc;
1354 } else {
1355 if (rxtop) {
1356 /* end of the chain */
1357 skb_fill_page_desc(rxtop,
1358 skb_shinfo(rxtop)->nr_frags,
1359 buffer_info->page, 0, length);
1360 /* re-use the current skb, we only consumed the
1361 * page */
1362 buffer_info->skb = skb;
1363 skb = rxtop;
1364 rxtop = NULL;
1365 e1000_consume_page(buffer_info, skb, length);
1366 } else {
1367 /* no chain, got EOP, this buf is the packet
1368 * copybreak to save the put_page/alloc_page */
1369 if (length <= copybreak &&
1370 skb_tailroom(skb) >= length) {
1371 u8 *vaddr;
1372 vaddr = kmap_atomic(buffer_info->page,
1373 KM_SKB_DATA_SOFTIRQ);
1374 memcpy(skb_tail_pointer(skb), vaddr,
1375 length);
1376 kunmap_atomic(vaddr,
1377 KM_SKB_DATA_SOFTIRQ);
1378 /* re-use the page, so don't erase
1379 * buffer_info->page */
1380 skb_put(skb, length);
1381 } else {
1382 skb_fill_page_desc(skb, 0,
1383 buffer_info->page, 0,
1384 length);
1385 e1000_consume_page(buffer_info, skb,
1386 length);
1387 }
1388 }
1389 }
1390
1391 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1392 e1000_rx_checksum(adapter,
1393 (u32)(status) |
1394 ((u32)(rx_desc->errors) << 24),
1395 le16_to_cpu(rx_desc->csum), skb);
1396
1397 /* probably a little skewed due to removing CRC */
1398 total_rx_bytes += skb->len;
1399 total_rx_packets++;
1400
1401 /* eth type trans needs skb->data to point to something */
1402 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001403 e_err("pskb_may_pull failed.\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001404 dev_kfree_skb(skb);
1405 goto next_desc;
1406 }
1407
1408 e1000_receive_skb(adapter, netdev, skb, status,
1409 rx_desc->special);
1410
1411next_desc:
1412 rx_desc->status = 0;
1413
1414 /* return some buffers to hardware, one at a time is too slow */
1415 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1416 adapter->alloc_rx_buf(adapter, cleaned_count);
1417 cleaned_count = 0;
1418 }
1419
1420 /* use prefetched values */
1421 rx_desc = next_rxd;
1422 buffer_info = next_buffer;
1423 }
1424 rx_ring->next_to_clean = i;
1425
1426 cleaned_count = e1000_desc_unused(rx_ring);
1427 if (cleaned_count)
1428 adapter->alloc_rx_buf(adapter, cleaned_count);
1429
1430 adapter->total_rx_bytes += total_rx_bytes;
1431 adapter->total_rx_packets += total_rx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +00001432 netdev->stats.rx_bytes += total_rx_bytes;
1433 netdev->stats.rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001434 return cleaned;
1435}
1436
1437/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001438 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1439 * @adapter: board private structure
1440 **/
1441static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1442{
1443 struct e1000_ring *rx_ring = adapter->rx_ring;
1444 struct e1000_buffer *buffer_info;
1445 struct e1000_ps_page *ps_page;
1446 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001447 unsigned int i, j;
1448
1449 /* Free all the Rx ring sk_buffs */
1450 for (i = 0; i < rx_ring->count; i++) {
1451 buffer_info = &rx_ring->buffer_info[i];
1452 if (buffer_info->dma) {
1453 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001454 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001455 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001456 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001457 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001458 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001459 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001460 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001462 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001463 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001464 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001465 buffer_info->dma = 0;
1466 }
1467
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001468 if (buffer_info->page) {
1469 put_page(buffer_info->page);
1470 buffer_info->page = NULL;
1471 }
1472
Auke Kokbc7f75f2007-09-17 12:30:59 -07001473 if (buffer_info->skb) {
1474 dev_kfree_skb(buffer_info->skb);
1475 buffer_info->skb = NULL;
1476 }
1477
1478 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001479 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001480 if (!ps_page->page)
1481 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001482 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1483 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001484 ps_page->dma = 0;
1485 put_page(ps_page->page);
1486 ps_page->page = NULL;
1487 }
1488 }
1489
1490 /* there also may be some cached data from a chained receive */
1491 if (rx_ring->rx_skb_top) {
1492 dev_kfree_skb(rx_ring->rx_skb_top);
1493 rx_ring->rx_skb_top = NULL;
1494 }
1495
Auke Kokbc7f75f2007-09-17 12:30:59 -07001496 /* Zero out the descriptor ring */
1497 memset(rx_ring->desc, 0, rx_ring->size);
1498
1499 rx_ring->next_to_clean = 0;
1500 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001501 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001502
1503 writel(0, adapter->hw.hw_addr + rx_ring->head);
1504 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1505}
1506
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001507static void e1000e_downshift_workaround(struct work_struct *work)
1508{
1509 struct e1000_adapter *adapter = container_of(work,
1510 struct e1000_adapter, downshift_task);
1511
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001512 if (test_bit(__E1000_DOWN, &adapter->state))
1513 return;
1514
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001515 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1516}
1517
Auke Kokbc7f75f2007-09-17 12:30:59 -07001518/**
1519 * e1000_intr_msi - Interrupt Handler
1520 * @irq: interrupt number
1521 * @data: pointer to a network interface device structure
1522 **/
1523static irqreturn_t e1000_intr_msi(int irq, void *data)
1524{
1525 struct net_device *netdev = data;
1526 struct e1000_adapter *adapter = netdev_priv(netdev);
1527 struct e1000_hw *hw = &adapter->hw;
1528 u32 icr = er32(ICR);
1529
Bruce Allanad680762008-03-28 09:15:03 -07001530 /*
1531 * read ICR disables interrupts using IAM
1532 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001533
dave graham573cca82009-02-10 12:52:05 +00001534 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001535 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001536 /*
1537 * ICH8 workaround-- Call gig speed drop workaround on cable
1538 * disconnect (LSC) before accessing any PHY registers
1539 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001540 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1541 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001542 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001543
Bruce Allanad680762008-03-28 09:15:03 -07001544 /*
1545 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001546 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001547 * adapter in watchdog
1548 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001549 if (netif_carrier_ok(netdev) &&
1550 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1551 /* disable receives */
1552 u32 rctl = er32(RCTL);
1553 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001554 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001555 }
1556 /* guard against interrupt when we're going down */
1557 if (!test_bit(__E1000_DOWN, &adapter->state))
1558 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1559 }
1560
Ben Hutchings288379f2009-01-19 16:43:59 -08001561 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562 adapter->total_tx_bytes = 0;
1563 adapter->total_tx_packets = 0;
1564 adapter->total_rx_bytes = 0;
1565 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001566 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001567 }
1568
1569 return IRQ_HANDLED;
1570}
1571
1572/**
1573 * e1000_intr - Interrupt Handler
1574 * @irq: interrupt number
1575 * @data: pointer to a network interface device structure
1576 **/
1577static irqreturn_t e1000_intr(int irq, void *data)
1578{
1579 struct net_device *netdev = data;
1580 struct e1000_adapter *adapter = netdev_priv(netdev);
1581 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001582 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001583
Bruce Allana68ea772009-11-20 23:23:16 +00001584 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585 return IRQ_NONE; /* Not our interrupt */
1586
Bruce Allanad680762008-03-28 09:15:03 -07001587 /*
1588 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1589 * not set, then the adapter didn't send an interrupt
1590 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001591 if (!(icr & E1000_ICR_INT_ASSERTED))
1592 return IRQ_NONE;
1593
Bruce Allanad680762008-03-28 09:15:03 -07001594 /*
1595 * Interrupt Auto-Mask...upon reading ICR,
1596 * interrupts are masked. No need for the
1597 * IMC write
1598 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001599
dave graham573cca82009-02-10 12:52:05 +00001600 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001601 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001602 /*
1603 * ICH8 workaround-- Call gig speed drop workaround on cable
1604 * disconnect (LSC) before accessing any PHY registers
1605 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001606 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1607 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001608 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001609
Bruce Allanad680762008-03-28 09:15:03 -07001610 /*
1611 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001612 * For packet buffer work-around on link down event;
1613 * disable receives here in the ISR and
1614 * reset adapter in watchdog
1615 */
1616 if (netif_carrier_ok(netdev) &&
1617 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1618 /* disable receives */
1619 rctl = er32(RCTL);
1620 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001621 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001622 }
1623 /* guard against interrupt when we're going down */
1624 if (!test_bit(__E1000_DOWN, &adapter->state))
1625 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1626 }
1627
Ben Hutchings288379f2009-01-19 16:43:59 -08001628 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001629 adapter->total_tx_bytes = 0;
1630 adapter->total_tx_packets = 0;
1631 adapter->total_rx_bytes = 0;
1632 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001633 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634 }
1635
1636 return IRQ_HANDLED;
1637}
1638
Bruce Allan4662e822008-08-26 18:37:06 -07001639static irqreturn_t e1000_msix_other(int irq, void *data)
1640{
1641 struct net_device *netdev = data;
1642 struct e1000_adapter *adapter = netdev_priv(netdev);
1643 struct e1000_hw *hw = &adapter->hw;
1644 u32 icr = er32(ICR);
1645
1646 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001647 if (!test_bit(__E1000_DOWN, &adapter->state))
1648 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001649 return IRQ_NONE;
1650 }
1651
1652 if (icr & adapter->eiac_mask)
1653 ew32(ICS, (icr & adapter->eiac_mask));
1654
1655 if (icr & E1000_ICR_OTHER) {
1656 if (!(icr & E1000_ICR_LSC))
1657 goto no_link_interrupt;
1658 hw->mac.get_link_status = 1;
1659 /* guard against interrupt when we're going down */
1660 if (!test_bit(__E1000_DOWN, &adapter->state))
1661 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1662 }
1663
1664no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001665 if (!test_bit(__E1000_DOWN, &adapter->state))
1666 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001667
1668 return IRQ_HANDLED;
1669}
1670
1671
1672static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1673{
1674 struct net_device *netdev = data;
1675 struct e1000_adapter *adapter = netdev_priv(netdev);
1676 struct e1000_hw *hw = &adapter->hw;
1677 struct e1000_ring *tx_ring = adapter->tx_ring;
1678
1679
1680 adapter->total_tx_bytes = 0;
1681 adapter->total_tx_packets = 0;
1682
1683 if (!e1000_clean_tx_irq(adapter))
1684 /* Ring was not completely cleaned, so fire another interrupt */
1685 ew32(ICS, tx_ring->ims_val);
1686
1687 return IRQ_HANDLED;
1688}
1689
1690static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1691{
1692 struct net_device *netdev = data;
1693 struct e1000_adapter *adapter = netdev_priv(netdev);
1694
1695 /* Write the ITR value calculated at the end of the
1696 * previous interrupt.
1697 */
1698 if (adapter->rx_ring->set_itr) {
1699 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1700 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1701 adapter->rx_ring->set_itr = 0;
1702 }
1703
Ben Hutchings288379f2009-01-19 16:43:59 -08001704 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001705 adapter->total_rx_bytes = 0;
1706 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001707 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001708 }
1709 return IRQ_HANDLED;
1710}
1711
1712/**
1713 * e1000_configure_msix - Configure MSI-X hardware
1714 *
1715 * e1000_configure_msix sets up the hardware to properly
1716 * generate MSI-X interrupts.
1717 **/
1718static void e1000_configure_msix(struct e1000_adapter *adapter)
1719{
1720 struct e1000_hw *hw = &adapter->hw;
1721 struct e1000_ring *rx_ring = adapter->rx_ring;
1722 struct e1000_ring *tx_ring = adapter->tx_ring;
1723 int vector = 0;
1724 u32 ctrl_ext, ivar = 0;
1725
1726 adapter->eiac_mask = 0;
1727
1728 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1729 if (hw->mac.type == e1000_82574) {
1730 u32 rfctl = er32(RFCTL);
1731 rfctl |= E1000_RFCTL_ACK_DIS;
1732 ew32(RFCTL, rfctl);
1733 }
1734
1735#define E1000_IVAR_INT_ALLOC_VALID 0x8
1736 /* Configure Rx vector */
1737 rx_ring->ims_val = E1000_IMS_RXQ0;
1738 adapter->eiac_mask |= rx_ring->ims_val;
1739 if (rx_ring->itr_val)
1740 writel(1000000000 / (rx_ring->itr_val * 256),
1741 hw->hw_addr + rx_ring->itr_register);
1742 else
1743 writel(1, hw->hw_addr + rx_ring->itr_register);
1744 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1745
1746 /* Configure Tx vector */
1747 tx_ring->ims_val = E1000_IMS_TXQ0;
1748 vector++;
1749 if (tx_ring->itr_val)
1750 writel(1000000000 / (tx_ring->itr_val * 256),
1751 hw->hw_addr + tx_ring->itr_register);
1752 else
1753 writel(1, hw->hw_addr + tx_ring->itr_register);
1754 adapter->eiac_mask |= tx_ring->ims_val;
1755 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1756
1757 /* set vector for Other Causes, e.g. link changes */
1758 vector++;
1759 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1760 if (rx_ring->itr_val)
1761 writel(1000000000 / (rx_ring->itr_val * 256),
1762 hw->hw_addr + E1000_EITR_82574(vector));
1763 else
1764 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1765
1766 /* Cause Tx interrupts on every write back */
1767 ivar |= (1 << 31);
1768
1769 ew32(IVAR, ivar);
1770
1771 /* enable MSI-X PBA support */
1772 ctrl_ext = er32(CTRL_EXT);
1773 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1774
1775 /* Auto-Mask Other interrupts upon ICR read */
1776#define E1000_EIAC_MASK_82574 0x01F00000
1777 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1778 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1779 ew32(CTRL_EXT, ctrl_ext);
1780 e1e_flush();
1781}
1782
1783void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1784{
1785 if (adapter->msix_entries) {
1786 pci_disable_msix(adapter->pdev);
1787 kfree(adapter->msix_entries);
1788 adapter->msix_entries = NULL;
1789 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1790 pci_disable_msi(adapter->pdev);
1791 adapter->flags &= ~FLAG_MSI_ENABLED;
1792 }
Bruce Allan4662e822008-08-26 18:37:06 -07001793}
1794
1795/**
1796 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1797 *
1798 * Attempt to configure interrupts using the best available
1799 * capabilities of the hardware and kernel.
1800 **/
1801void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1802{
1803 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001804 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001805
1806 switch (adapter->int_mode) {
1807 case E1000E_INT_MODE_MSIX:
1808 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001809 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1810 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001811 sizeof(struct msix_entry),
1812 GFP_KERNEL);
1813 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001814 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001815 adapter->msix_entries[i].entry = i;
1816
1817 err = pci_enable_msix(adapter->pdev,
1818 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001819 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001820 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001821 return;
1822 }
1823 /* MSI-X failed, so fall through and try MSI */
1824 e_err("Failed to initialize MSI-X interrupts. "
1825 "Falling back to MSI interrupts.\n");
1826 e1000e_reset_interrupt_capability(adapter);
1827 }
1828 adapter->int_mode = E1000E_INT_MODE_MSI;
1829 /* Fall through */
1830 case E1000E_INT_MODE_MSI:
1831 if (!pci_enable_msi(adapter->pdev)) {
1832 adapter->flags |= FLAG_MSI_ENABLED;
1833 } else {
1834 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1835 e_err("Failed to initialize MSI interrupts. Falling "
1836 "back to legacy interrupts.\n");
1837 }
1838 /* Fall through */
1839 case E1000E_INT_MODE_LEGACY:
1840 /* Don't do anything; this is the system default */
1841 break;
1842 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001843
1844 /* store the number of vectors being used */
1845 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001846}
1847
1848/**
1849 * e1000_request_msix - Initialize MSI-X interrupts
1850 *
1851 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1852 * kernel.
1853 **/
1854static int e1000_request_msix(struct e1000_adapter *adapter)
1855{
1856 struct net_device *netdev = adapter->netdev;
1857 int err = 0, vector = 0;
1858
1859 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001860 sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001861 else
1862 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1863 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001864 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001865 netdev);
1866 if (err)
1867 goto out;
1868 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1869 adapter->rx_ring->itr_val = adapter->itr;
1870 vector++;
1871
1872 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001873 sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001874 else
1875 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1876 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001877 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001878 netdev);
1879 if (err)
1880 goto out;
1881 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1882 adapter->tx_ring->itr_val = adapter->itr;
1883 vector++;
1884
1885 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001886 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001887 if (err)
1888 goto out;
1889
1890 e1000_configure_msix(adapter);
1891 return 0;
1892out:
1893 return err;
1894}
1895
Bruce Allanf8d59f72008-08-08 18:36:11 -07001896/**
1897 * e1000_request_irq - initialize interrupts
1898 *
1899 * Attempts to configure interrupts using the best available
1900 * capabilities of the hardware and kernel.
1901 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001902static int e1000_request_irq(struct e1000_adapter *adapter)
1903{
1904 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001905 int err;
1906
Bruce Allan4662e822008-08-26 18:37:06 -07001907 if (adapter->msix_entries) {
1908 err = e1000_request_msix(adapter);
1909 if (!err)
1910 return err;
1911 /* fall back to MSI */
1912 e1000e_reset_interrupt_capability(adapter);
1913 adapter->int_mode = E1000E_INT_MODE_MSI;
1914 e1000e_set_interrupt_capability(adapter);
1915 }
1916 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001917 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001918 netdev->name, netdev);
1919 if (!err)
1920 return err;
1921
1922 /* fall back to legacy interrupt */
1923 e1000e_reset_interrupt_capability(adapter);
1924 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001925 }
1926
Joe Perchesa0607fd2009-11-18 23:29:17 -08001927 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001928 netdev->name, netdev);
1929 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001930 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001931
1932 return err;
1933}
1934
1935static void e1000_free_irq(struct e1000_adapter *adapter)
1936{
1937 struct net_device *netdev = adapter->netdev;
1938
Bruce Allan4662e822008-08-26 18:37:06 -07001939 if (adapter->msix_entries) {
1940 int vector = 0;
1941
1942 free_irq(adapter->msix_entries[vector].vector, netdev);
1943 vector++;
1944
1945 free_irq(adapter->msix_entries[vector].vector, netdev);
1946 vector++;
1947
1948 /* Other Causes interrupt vector */
1949 free_irq(adapter->msix_entries[vector].vector, netdev);
1950 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001951 }
Bruce Allan4662e822008-08-26 18:37:06 -07001952
1953 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001954}
1955
1956/**
1957 * e1000_irq_disable - Mask off interrupt generation on the NIC
1958 **/
1959static void e1000_irq_disable(struct e1000_adapter *adapter)
1960{
1961 struct e1000_hw *hw = &adapter->hw;
1962
Auke Kokbc7f75f2007-09-17 12:30:59 -07001963 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001964 if (adapter->msix_entries)
1965 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001966 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001967
1968 if (adapter->msix_entries) {
1969 int i;
1970 for (i = 0; i < adapter->num_vectors; i++)
1971 synchronize_irq(adapter->msix_entries[i].vector);
1972 } else {
1973 synchronize_irq(adapter->pdev->irq);
1974 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001975}
1976
1977/**
1978 * e1000_irq_enable - Enable default interrupt generation settings
1979 **/
1980static void e1000_irq_enable(struct e1000_adapter *adapter)
1981{
1982 struct e1000_hw *hw = &adapter->hw;
1983
Bruce Allan4662e822008-08-26 18:37:06 -07001984 if (adapter->msix_entries) {
1985 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1986 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1987 } else {
1988 ew32(IMS, IMS_ENABLE_MASK);
1989 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001990 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001991}
1992
1993/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001994 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995 * @adapter: address of board private structure
1996 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001997 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001998 * For ASF and Pass Through versions of f/w this means that
1999 * the driver is loaded. For AMT version (only with 82573)
2000 * of the f/w this means that the network i/f is open.
2001 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002002void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002003{
2004 struct e1000_hw *hw = &adapter->hw;
2005 u32 ctrl_ext;
2006 u32 swsm;
2007
2008 /* Let firmware know the driver has taken over */
2009 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2010 swsm = er32(SWSM);
2011 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2012 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2013 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002014 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002015 }
2016}
2017
2018/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002019 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002020 * @adapter: address of board private structure
2021 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002022 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002023 * For ASF and Pass Through versions of f/w this means that the
2024 * driver is no longer loaded. For AMT version (only with 82573) i
2025 * of the f/w this means that the network i/f is closed.
2026 *
2027 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002028void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002029{
2030 struct e1000_hw *hw = &adapter->hw;
2031 u32 ctrl_ext;
2032 u32 swsm;
2033
2034 /* Let firmware taken over control of h/w */
2035 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2036 swsm = er32(SWSM);
2037 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2038 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2039 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002040 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002041 }
2042}
2043
Auke Kokbc7f75f2007-09-17 12:30:59 -07002044/**
2045 * @e1000_alloc_ring - allocate memory for a ring structure
2046 **/
2047static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2048 struct e1000_ring *ring)
2049{
2050 struct pci_dev *pdev = adapter->pdev;
2051
2052 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2053 GFP_KERNEL);
2054 if (!ring->desc)
2055 return -ENOMEM;
2056
2057 return 0;
2058}
2059
2060/**
2061 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2062 * @adapter: board private structure
2063 *
2064 * Return 0 on success, negative on failure
2065 **/
2066int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2067{
2068 struct e1000_ring *tx_ring = adapter->tx_ring;
2069 int err = -ENOMEM, size;
2070
2071 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002072 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002073 if (!tx_ring->buffer_info)
2074 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002075
2076 /* round up to nearest 4K */
2077 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2078 tx_ring->size = ALIGN(tx_ring->size, 4096);
2079
2080 err = e1000_alloc_ring_dma(adapter, tx_ring);
2081 if (err)
2082 goto err;
2083
2084 tx_ring->next_to_use = 0;
2085 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002086
2087 return 0;
2088err:
2089 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002090 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002091 return err;
2092}
2093
2094/**
2095 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2096 * @adapter: board private structure
2097 *
2098 * Returns 0 on success, negative on failure
2099 **/
2100int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2101{
2102 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002103 struct e1000_buffer *buffer_info;
2104 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002105
2106 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002107 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002108 if (!rx_ring->buffer_info)
2109 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002110
Auke Kok47f44e42007-10-25 13:57:44 -07002111 for (i = 0; i < rx_ring->count; i++) {
2112 buffer_info = &rx_ring->buffer_info[i];
2113 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2114 sizeof(struct e1000_ps_page),
2115 GFP_KERNEL);
2116 if (!buffer_info->ps_pages)
2117 goto err_pages;
2118 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002119
2120 desc_len = sizeof(union e1000_rx_desc_packet_split);
2121
2122 /* Round up to nearest 4K */
2123 rx_ring->size = rx_ring->count * desc_len;
2124 rx_ring->size = ALIGN(rx_ring->size, 4096);
2125
2126 err = e1000_alloc_ring_dma(adapter, rx_ring);
2127 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002128 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002129
2130 rx_ring->next_to_clean = 0;
2131 rx_ring->next_to_use = 0;
2132 rx_ring->rx_skb_top = NULL;
2133
2134 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002135
2136err_pages:
2137 for (i = 0; i < rx_ring->count; i++) {
2138 buffer_info = &rx_ring->buffer_info[i];
2139 kfree(buffer_info->ps_pages);
2140 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002141err:
2142 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002143 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002144 return err;
2145}
2146
2147/**
2148 * e1000_clean_tx_ring - Free Tx Buffers
2149 * @adapter: board private structure
2150 **/
2151static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2152{
2153 struct e1000_ring *tx_ring = adapter->tx_ring;
2154 struct e1000_buffer *buffer_info;
2155 unsigned long size;
2156 unsigned int i;
2157
2158 for (i = 0; i < tx_ring->count; i++) {
2159 buffer_info = &tx_ring->buffer_info[i];
2160 e1000_put_txbuf(adapter, buffer_info);
2161 }
2162
2163 size = sizeof(struct e1000_buffer) * tx_ring->count;
2164 memset(tx_ring->buffer_info, 0, size);
2165
2166 memset(tx_ring->desc, 0, tx_ring->size);
2167
2168 tx_ring->next_to_use = 0;
2169 tx_ring->next_to_clean = 0;
2170
2171 writel(0, adapter->hw.hw_addr + tx_ring->head);
2172 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2173}
2174
2175/**
2176 * e1000e_free_tx_resources - Free Tx Resources per Queue
2177 * @adapter: board private structure
2178 *
2179 * Free all transmit software resources
2180 **/
2181void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2182{
2183 struct pci_dev *pdev = adapter->pdev;
2184 struct e1000_ring *tx_ring = adapter->tx_ring;
2185
2186 e1000_clean_tx_ring(adapter);
2187
2188 vfree(tx_ring->buffer_info);
2189 tx_ring->buffer_info = NULL;
2190
2191 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2192 tx_ring->dma);
2193 tx_ring->desc = NULL;
2194}
2195
2196/**
2197 * e1000e_free_rx_resources - Free Rx Resources
2198 * @adapter: board private structure
2199 *
2200 * Free all receive software resources
2201 **/
2202
2203void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2204{
2205 struct pci_dev *pdev = adapter->pdev;
2206 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002207 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002208
2209 e1000_clean_rx_ring(adapter);
2210
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002211 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002212 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002213
Auke Kokbc7f75f2007-09-17 12:30:59 -07002214 vfree(rx_ring->buffer_info);
2215 rx_ring->buffer_info = NULL;
2216
Auke Kokbc7f75f2007-09-17 12:30:59 -07002217 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2218 rx_ring->dma);
2219 rx_ring->desc = NULL;
2220}
2221
2222/**
2223 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002224 * @adapter: pointer to adapter
2225 * @itr_setting: current adapter->itr
2226 * @packets: the number of packets during this measurement interval
2227 * @bytes: the number of bytes during this measurement interval
2228 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229 * Stores a new ITR value based on packets and byte
2230 * counts during the last interrupt. The advantage of per interrupt
2231 * computation is faster updates and more accurate ITR for the current
2232 * traffic pattern. Constants in this function were computed
2233 * based on theoretical maximum wire speed and thresholds were set based
2234 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002235 * while increasing bulk throughput. This functionality is controlled
2236 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002237 **/
2238static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2239 u16 itr_setting, int packets,
2240 int bytes)
2241{
2242 unsigned int retval = itr_setting;
2243
2244 if (packets == 0)
2245 goto update_itr_done;
2246
2247 switch (itr_setting) {
2248 case lowest_latency:
2249 /* handle TSO and jumbo frames */
2250 if (bytes/packets > 8000)
2251 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002252 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002254 break;
2255 case low_latency: /* 50 usec aka 20000 ints/s */
2256 if (bytes > 10000) {
2257 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002258 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002260 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002261 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002262 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002263 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002264 } else if (bytes/packets > 2000) {
2265 retval = bulk_latency;
2266 } else if (packets <= 2 && bytes < 512) {
2267 retval = lowest_latency;
2268 }
2269 break;
2270 case bulk_latency: /* 250 usec aka 4000 ints/s */
2271 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002272 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002273 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002274 } else if (bytes < 6000) {
2275 retval = low_latency;
2276 }
2277 break;
2278 }
2279
2280update_itr_done:
2281 return retval;
2282}
2283
2284static void e1000_set_itr(struct e1000_adapter *adapter)
2285{
2286 struct e1000_hw *hw = &adapter->hw;
2287 u16 current_itr;
2288 u32 new_itr = adapter->itr;
2289
2290 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2291 if (adapter->link_speed != SPEED_1000) {
2292 current_itr = 0;
2293 new_itr = 4000;
2294 goto set_itr_now;
2295 }
2296
Bruce Allan828bac82010-09-29 21:39:37 +00002297 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2298 new_itr = 0;
2299 goto set_itr_now;
2300 }
2301
Auke Kokbc7f75f2007-09-17 12:30:59 -07002302 adapter->tx_itr = e1000_update_itr(adapter,
2303 adapter->tx_itr,
2304 adapter->total_tx_packets,
2305 adapter->total_tx_bytes);
2306 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2307 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2308 adapter->tx_itr = low_latency;
2309
2310 adapter->rx_itr = e1000_update_itr(adapter,
2311 adapter->rx_itr,
2312 adapter->total_rx_packets,
2313 adapter->total_rx_bytes);
2314 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2315 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2316 adapter->rx_itr = low_latency;
2317
2318 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2319
2320 switch (current_itr) {
2321 /* counts and packets in update_itr are dependent on these numbers */
2322 case lowest_latency:
2323 new_itr = 70000;
2324 break;
2325 case low_latency:
2326 new_itr = 20000; /* aka hwitr = ~200 */
2327 break;
2328 case bulk_latency:
2329 new_itr = 4000;
2330 break;
2331 default:
2332 break;
2333 }
2334
2335set_itr_now:
2336 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002337 /*
2338 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002339 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002340 * increasing
2341 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002342 new_itr = new_itr > adapter->itr ?
2343 min(adapter->itr + (new_itr >> 2), new_itr) :
2344 new_itr;
2345 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002346 adapter->rx_ring->itr_val = new_itr;
2347 if (adapter->msix_entries)
2348 adapter->rx_ring->set_itr = 1;
2349 else
Bruce Allan828bac82010-09-29 21:39:37 +00002350 if (new_itr)
2351 ew32(ITR, 1000000000 / (new_itr * 256));
2352 else
2353 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002354 }
2355}
2356
2357/**
Bruce Allan4662e822008-08-26 18:37:06 -07002358 * e1000_alloc_queues - Allocate memory for all rings
2359 * @adapter: board private structure to initialize
2360 **/
2361static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2362{
2363 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2364 if (!adapter->tx_ring)
2365 goto err;
2366
2367 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2368 if (!adapter->rx_ring)
2369 goto err;
2370
2371 return 0;
2372err:
2373 e_err("Unable to allocate memory for queues\n");
2374 kfree(adapter->rx_ring);
2375 kfree(adapter->tx_ring);
2376 return -ENOMEM;
2377}
2378
2379/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002380 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002381 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002382 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002383 **/
2384static int e1000_clean(struct napi_struct *napi, int budget)
2385{
2386 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002387 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002388 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002389 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002390
Wang Chen4cf16532008-11-12 23:38:14 -08002391 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002392
Bruce Allan4662e822008-08-26 18:37:06 -07002393 if (adapter->msix_entries &&
2394 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2395 goto clean_rx;
2396
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002397 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398
Bruce Allan4662e822008-08-26 18:37:06 -07002399clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002400 adapter->clean_rx(adapter, &work_done, budget);
2401
Alexander Duyck12d04a32009-03-25 22:05:03 +00002402 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002403 work_done = budget;
2404
David S. Miller53e52c72008-01-07 21:06:12 -08002405 /* If budget not fully consumed, exit the polling mode */
2406 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002407 if (adapter->itr_setting & 3)
2408 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002409 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002410 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2411 if (adapter->msix_entries)
2412 ew32(IMS, adapter->rx_ring->ims_val);
2413 else
2414 e1000_irq_enable(adapter);
2415 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002416 }
2417
2418 return work_done;
2419}
2420
2421static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2422{
2423 struct e1000_adapter *adapter = netdev_priv(netdev);
2424 struct e1000_hw *hw = &adapter->hw;
2425 u32 vfta, index;
2426
2427 /* don't update vlan cookie if already programmed */
2428 if ((adapter->hw.mng_cookie.status &
2429 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2430 (vid == adapter->mng_vlan_id))
2431 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002432
Auke Kokbc7f75f2007-09-17 12:30:59 -07002433 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002434 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2435 index = (vid >> 5) & 0x7F;
2436 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2437 vfta |= (1 << (vid & 0x1F));
2438 hw->mac.ops.write_vfta(hw, index, vfta);
2439 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440}
2441
2442static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2443{
2444 struct e1000_adapter *adapter = netdev_priv(netdev);
2445 struct e1000_hw *hw = &adapter->hw;
2446 u32 vfta, index;
2447
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002448 if (!test_bit(__E1000_DOWN, &adapter->state))
2449 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002450 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002451
2452 if (!test_bit(__E1000_DOWN, &adapter->state))
2453 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454
2455 if ((adapter->hw.mng_cookie.status &
2456 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2457 (vid == adapter->mng_vlan_id)) {
2458 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002459 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002460 return;
2461 }
2462
2463 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002464 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2465 index = (vid >> 5) & 0x7F;
2466 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2467 vfta &= ~(1 << (vid & 0x1F));
2468 hw->mac.ops.write_vfta(hw, index, vfta);
2469 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002470}
2471
2472static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2473{
2474 struct net_device *netdev = adapter->netdev;
2475 u16 vid = adapter->hw.mng_cookie.vlan_id;
2476 u16 old_vid = adapter->mng_vlan_id;
2477
2478 if (!adapter->vlgrp)
2479 return;
2480
2481 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2482 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2483 if (adapter->hw.mng_cookie.status &
2484 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2485 e1000_vlan_rx_add_vid(netdev, vid);
2486 adapter->mng_vlan_id = vid;
2487 }
2488
2489 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2490 (vid != old_vid) &&
2491 !vlan_group_get_device(adapter->vlgrp, old_vid))
2492 e1000_vlan_rx_kill_vid(netdev, old_vid);
2493 } else {
2494 adapter->mng_vlan_id = vid;
2495 }
2496}
2497
2498
2499static void e1000_vlan_rx_register(struct net_device *netdev,
2500 struct vlan_group *grp)
2501{
2502 struct e1000_adapter *adapter = netdev_priv(netdev);
2503 struct e1000_hw *hw = &adapter->hw;
2504 u32 ctrl, rctl;
2505
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002506 if (!test_bit(__E1000_DOWN, &adapter->state))
2507 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002508 adapter->vlgrp = grp;
2509
2510 if (grp) {
2511 /* enable VLAN tag insert/strip */
2512 ctrl = er32(CTRL);
2513 ctrl |= E1000_CTRL_VME;
2514 ew32(CTRL, ctrl);
2515
2516 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2517 /* enable VLAN receive filtering */
2518 rctl = er32(RCTL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002519 rctl &= ~E1000_RCTL_CFIEN;
2520 ew32(RCTL, rctl);
2521 e1000_update_mng_vlan(adapter);
2522 }
2523 } else {
2524 /* disable VLAN tag insert/strip */
2525 ctrl = er32(CTRL);
2526 ctrl &= ~E1000_CTRL_VME;
2527 ew32(CTRL, ctrl);
2528
2529 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002530 if (adapter->mng_vlan_id !=
2531 (u16)E1000_MNG_VLAN_NONE) {
2532 e1000_vlan_rx_kill_vid(netdev,
2533 adapter->mng_vlan_id);
2534 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2535 }
2536 }
2537 }
2538
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002539 if (!test_bit(__E1000_DOWN, &adapter->state))
2540 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002541}
2542
2543static void e1000_restore_vlan(struct e1000_adapter *adapter)
2544{
2545 u16 vid;
2546
2547 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2548
2549 if (!adapter->vlgrp)
2550 return;
2551
Jesse Grossb7381272010-10-20 13:56:02 +00002552 for (vid = 0; vid < VLAN_N_VID; vid++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002553 if (!vlan_group_get_device(adapter->vlgrp, vid))
2554 continue;
2555 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2556 }
2557}
2558
Bruce Allancd791612010-05-10 14:59:51 +00002559static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560{
2561 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002562 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563
2564 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2565 return;
2566
2567 manc = er32(MANC);
2568
Bruce Allanad680762008-03-28 09:15:03 -07002569 /*
2570 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002571 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002572 * the packets will be handled on SMBUS
2573 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002574 manc |= E1000_MANC_EN_MNG2HOST;
2575 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002576
2577 switch (hw->mac.type) {
2578 default:
2579 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2580 break;
2581 case e1000_82574:
2582 case e1000_82583:
2583 /*
2584 * Check if IPMI pass-through decision filter already exists;
2585 * if so, enable it.
2586 */
2587 for (i = 0, j = 0; i < 8; i++) {
2588 mdef = er32(MDEF(i));
2589
2590 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002591 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002592 continue;
2593
2594 /* Enable this decision filter in MANC2H */
2595 if (mdef)
2596 manc2h |= (1 << i);
2597
2598 j |= mdef;
2599 }
2600
2601 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2602 break;
2603
2604 /* Create new decision filter in an empty filter */
2605 for (i = 0, j = 0; i < 8; i++)
2606 if (er32(MDEF(i)) == 0) {
2607 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2608 E1000_MDEF_PORT_664));
2609 manc2h |= (1 << 1);
2610 j++;
2611 break;
2612 }
2613
2614 if (!j)
2615 e_warn("Unable to create IPMI pass-through filter\n");
2616 break;
2617 }
2618
Auke Kokbc7f75f2007-09-17 12:30:59 -07002619 ew32(MANC2H, manc2h);
2620 ew32(MANC, manc);
2621}
2622
2623/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002624 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002625 * @adapter: board private structure
2626 *
2627 * Configure the Tx unit of the MAC after a reset.
2628 **/
2629static void e1000_configure_tx(struct e1000_adapter *adapter)
2630{
2631 struct e1000_hw *hw = &adapter->hw;
2632 struct e1000_ring *tx_ring = adapter->tx_ring;
2633 u64 tdba;
2634 u32 tdlen, tctl, tipg, tarc;
2635 u32 ipgr1, ipgr2;
2636
2637 /* Setup the HW Tx Head and Tail descriptor pointers */
2638 tdba = tx_ring->dma;
2639 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002640 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002641 ew32(TDBAH, (tdba >> 32));
2642 ew32(TDLEN, tdlen);
2643 ew32(TDH, 0);
2644 ew32(TDT, 0);
2645 tx_ring->head = E1000_TDH;
2646 tx_ring->tail = E1000_TDT;
2647
2648 /* Set the default values for the Tx Inter Packet Gap timer */
2649 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2650 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2651 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2652
2653 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2654 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2655
2656 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2657 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2658 ew32(TIPG, tipg);
2659
2660 /* Set the Tx Interrupt Delay register */
2661 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002662 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663 ew32(TADV, adapter->tx_abs_int_delay);
2664
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002665 if (adapter->flags2 & FLAG2_DMA_BURST) {
2666 u32 txdctl = er32(TXDCTL(0));
2667 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2668 E1000_TXDCTL_WTHRESH);
2669 /*
2670 * set up some performance related parameters to encourage the
2671 * hardware to use the bus more efficiently in bursts, depends
2672 * on the tx_int_delay to be enabled,
2673 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2674 * hthresh = 1 ==> prefetch when one or more available
2675 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2676 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002677 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002678 */
2679 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2680 ew32(TXDCTL(0), txdctl);
2681 /* erratum work around: set txdctl the same for both queues */
2682 ew32(TXDCTL(1), txdctl);
2683 }
2684
Auke Kokbc7f75f2007-09-17 12:30:59 -07002685 /* Program the Transmit Control Register */
2686 tctl = er32(TCTL);
2687 tctl &= ~E1000_TCTL_CT;
2688 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2689 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2690
2691 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002692 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002693 /*
2694 * set the speed mode bit, we'll clear it if we're not at
2695 * gigabit link later
2696 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002697#define SPEED_MODE_BIT (1 << 21)
2698 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002699 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002700 }
2701
2702 /* errata: program both queues to unweighted RR */
2703 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002704 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002706 ew32(TARC(0), tarc);
2707 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002708 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002709 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002710 }
2711
Auke Kokbc7f75f2007-09-17 12:30:59 -07002712 /* Setup Transmit Descriptor Settings for eop descriptor */
2713 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2714
2715 /* only set IDE if we are delaying interrupts using the timers */
2716 if (adapter->tx_int_delay)
2717 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2718
2719 /* enable Report Status bit */
2720 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2721
2722 ew32(TCTL, tctl);
2723
Simon Hormanedfea6e62009-06-08 14:28:36 +00002724 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002725}
2726
2727/**
2728 * e1000_setup_rctl - configure the receive control registers
2729 * @adapter: Board private structure
2730 **/
2731#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2732 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2733static void e1000_setup_rctl(struct e1000_adapter *adapter)
2734{
2735 struct e1000_hw *hw = &adapter->hw;
2736 u32 rctl, rfctl;
2737 u32 psrctl = 0;
2738 u32 pages = 0;
2739
Bruce Allana1ce6472010-09-22 17:16:40 +00002740 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2741 if (hw->mac.type == e1000_pch2lan) {
2742 s32 ret_val;
2743
2744 if (adapter->netdev->mtu > ETH_DATA_LEN)
2745 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2746 else
2747 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002748
2749 if (ret_val)
2750 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002751 }
2752
Auke Kokbc7f75f2007-09-17 12:30:59 -07002753 /* Program MC offset vector base */
2754 rctl = er32(RCTL);
2755 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2756 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2757 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2758 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2759
2760 /* Do not Store bad packets */
2761 rctl &= ~E1000_RCTL_SBP;
2762
2763 /* Enable Long Packet receive */
2764 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2765 rctl &= ~E1000_RCTL_LPE;
2766 else
2767 rctl |= E1000_RCTL_LPE;
2768
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002769 /* Some systems expect that the CRC is included in SMBUS traffic. The
2770 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2771 * host memory when this is enabled
2772 */
2773 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2774 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002775
Bruce Allana4f58f52009-06-02 11:29:18 +00002776 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2777 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2778 u16 phy_data;
2779
2780 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2781 phy_data &= 0xfff8;
2782 phy_data |= (1 << 2);
2783 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2784
2785 e1e_rphy(hw, 22, &phy_data);
2786 phy_data &= 0x0fff;
2787 phy_data |= (1 << 14);
2788 e1e_wphy(hw, 0x10, 0x2823);
2789 e1e_wphy(hw, 0x11, 0x0003);
2790 e1e_wphy(hw, 22, phy_data);
2791 }
2792
Auke Kokbc7f75f2007-09-17 12:30:59 -07002793 /* Setup buffer sizes */
2794 rctl &= ~E1000_RCTL_SZ_4096;
2795 rctl |= E1000_RCTL_BSEX;
2796 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002797 case 2048:
2798 default:
2799 rctl |= E1000_RCTL_SZ_2048;
2800 rctl &= ~E1000_RCTL_BSEX;
2801 break;
2802 case 4096:
2803 rctl |= E1000_RCTL_SZ_4096;
2804 break;
2805 case 8192:
2806 rctl |= E1000_RCTL_SZ_8192;
2807 break;
2808 case 16384:
2809 rctl |= E1000_RCTL_SZ_16384;
2810 break;
2811 }
2812
2813 /*
2814 * 82571 and greater support packet-split where the protocol
2815 * header is placed in skb->data and the packet data is
2816 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2817 * In the case of a non-split, skb->data is linearly filled,
2818 * followed by the page buffers. Therefore, skb->data is
2819 * sized to hold the largest protocol header.
2820 *
2821 * allocations using alloc_page take too long for regular MTU
2822 * so only enable packet split for jumbo frames
2823 *
2824 * Using pages when the page size is greater than 16k wastes
2825 * a lot of memory, since we allocate 3 pages at all times
2826 * per packet.
2827 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002828 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fec2010-06-17 18:59:27 +00002829 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002830 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002832 else
2833 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002834
2835 if (adapter->rx_ps_pages) {
2836 /* Configure extra packet-split registers */
2837 rfctl = er32(RFCTL);
2838 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002839 /*
2840 * disable packet split support for IPv6 extension headers,
2841 * because some malformed IPv6 headers can hang the Rx
2842 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002843 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2844 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2845
2846 ew32(RFCTL, rfctl);
2847
Auke Kok140a7482007-10-25 13:57:58 -07002848 /* Enable Packet split descriptors */
2849 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002850
2851 psrctl |= adapter->rx_ps_bsize0 >>
2852 E1000_PSRCTL_BSIZE0_SHIFT;
2853
2854 switch (adapter->rx_ps_pages) {
2855 case 3:
2856 psrctl |= PAGE_SIZE <<
2857 E1000_PSRCTL_BSIZE3_SHIFT;
2858 case 2:
2859 psrctl |= PAGE_SIZE <<
2860 E1000_PSRCTL_BSIZE2_SHIFT;
2861 case 1:
2862 psrctl |= PAGE_SIZE >>
2863 E1000_PSRCTL_BSIZE1_SHIFT;
2864 break;
2865 }
2866
2867 ew32(PSRCTL, psrctl);
2868 }
2869
2870 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002871 /* just started the receive unit, no need to restart */
2872 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002873}
2874
2875/**
2876 * e1000_configure_rx - Configure Receive Unit after Reset
2877 * @adapter: board private structure
2878 *
2879 * Configure the Rx unit of the MAC after a reset.
2880 **/
2881static void e1000_configure_rx(struct e1000_adapter *adapter)
2882{
2883 struct e1000_hw *hw = &adapter->hw;
2884 struct e1000_ring *rx_ring = adapter->rx_ring;
2885 u64 rdba;
2886 u32 rdlen, rctl, rxcsum, ctrl_ext;
2887
2888 if (adapter->rx_ps_pages) {
2889 /* this is a 32 byte descriptor */
2890 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002891 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002892 adapter->clean_rx = e1000_clean_rx_irq_ps;
2893 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002894 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2895 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2896 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2897 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002898 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002899 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002900 adapter->clean_rx = e1000_clean_rx_irq;
2901 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2902 }
2903
2904 /* disable receives while setting up the descriptors */
2905 rctl = er32(RCTL);
2906 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2907 e1e_flush();
2908 msleep(10);
2909
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002910 if (adapter->flags2 & FLAG2_DMA_BURST) {
2911 /*
2912 * set the writeback threshold (only takes effect if the RDTR
2913 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00002914 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002915 * granularity = 01
2916 * wthresh = 04,
2917 * hthresh = 04,
2918 * pthresh = 0x20
2919 */
2920 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
2921 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
2922
2923 /*
2924 * override the delay timers for enabling bursting, only if
2925 * the value was not set by the user via module options
2926 */
2927 if (adapter->rx_int_delay == DEFAULT_RDTR)
2928 adapter->rx_int_delay = BURST_RDTR;
2929 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
2930 adapter->rx_abs_int_delay = BURST_RADV;
2931 }
2932
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933 /* set the Receive Delay Timer Register */
2934 ew32(RDTR, adapter->rx_int_delay);
2935
2936 /* irq moderation */
2937 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00002938 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07002939 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002940
2941 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002942 /* Auto-Mask interrupts upon ICR access */
2943 ctrl_ext |= E1000_CTRL_EXT_IAME;
2944 ew32(IAM, 0xffffffff);
2945 ew32(CTRL_EXT, ctrl_ext);
2946 e1e_flush();
2947
Bruce Allanad680762008-03-28 09:15:03 -07002948 /*
2949 * Setup the HW Rx Head and Tail Descriptor Pointers and
2950 * the Base and Length of the Rx Descriptor Ring
2951 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002952 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002953 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002954 ew32(RDBAH, (rdba >> 32));
2955 ew32(RDLEN, rdlen);
2956 ew32(RDH, 0);
2957 ew32(RDT, 0);
2958 rx_ring->head = E1000_RDH;
2959 rx_ring->tail = E1000_RDT;
2960
2961 /* Enable Receive Checksum Offload for TCP and UDP */
2962 rxcsum = er32(RXCSUM);
2963 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2964 rxcsum |= E1000_RXCSUM_TUOFL;
2965
Bruce Allanad680762008-03-28 09:15:03 -07002966 /*
2967 * IPv4 payload checksum for UDP fragments must be
2968 * used in conjunction with packet-split.
2969 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002970 if (adapter->rx_ps_pages)
2971 rxcsum |= E1000_RXCSUM_IPPCSE;
2972 } else {
2973 rxcsum &= ~E1000_RXCSUM_TUOFL;
2974 /* no need to clear IPPCSE as it defaults to 0 */
2975 }
2976 ew32(RXCSUM, rxcsum);
2977
Bruce Allanad680762008-03-28 09:15:03 -07002978 /*
2979 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002980 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002981 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2982 */
Bruce Allan828bac82010-09-29 21:39:37 +00002983 if ((adapter->flags & FLAG_HAS_ERT) ||
2984 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00002985 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2986 u32 rxdctl = er32(RXDCTL(0));
2987 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00002988 if (adapter->flags & FLAG_HAS_ERT)
2989 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00002990 /*
2991 * With jumbo frames and early-receive enabled,
2992 * excessive C-state transition latencies result in
2993 * dropped transactions.
2994 */
Bruce Allanaf667a22010-12-31 06:10:01 +00002995 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00002996 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00002997 pm_qos_update_request(&adapter->netdev->pm_qos_req,
2998 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00002999 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003000 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003001
3002 /* Enable Receives */
3003 ew32(RCTL, rctl);
3004}
3005
3006/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003007 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07003008 * @hw: pointer to the HW structure
3009 * @mc_addr_list: array of multicast addresses to program
3010 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07003011 *
Bruce Allanab8932f2010-01-13 02:05:38 +00003012 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003013 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003014 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003015static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003016 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003017{
Bruce Allanab8932f2010-01-13 02:05:38 +00003018 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003019}
3020
3021/**
3022 * e1000_set_multi - Multicast and Promiscuous mode set
3023 * @netdev: network interface device structure
3024 *
3025 * The set_multi entry point is called whenever the multicast address
3026 * list or the network interface flags are updated. This routine is
3027 * responsible for configuring the hardware for proper multicast,
3028 * promiscuous mode, and all-multi behavior.
3029 **/
3030static void e1000_set_multi(struct net_device *netdev)
3031{
3032 struct e1000_adapter *adapter = netdev_priv(netdev);
3033 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003034 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003035 u8 *mta_list;
3036 u32 rctl;
3037 int i;
3038
3039 /* Check for Promiscuous and All Multicast modes */
3040
3041 rctl = er32(RCTL);
3042
3043 if (netdev->flags & IFF_PROMISC) {
3044 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003045 rctl &= ~E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003046 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003047 if (netdev->flags & IFF_ALLMULTI) {
3048 rctl |= E1000_RCTL_MPE;
3049 rctl &= ~E1000_RCTL_UPE;
3050 } else {
3051 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3052 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07003053 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardy746b9f02008-07-16 20:15:45 -07003054 rctl |= E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003055 }
3056
3057 ew32(RCTL, rctl);
3058
Jiri Pirko7aeef972010-02-05 02:52:39 +00003059 if (!netdev_mc_empty(netdev)) {
3060 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003061 if (!mta_list)
3062 return;
3063
3064 /* prepare a packed array of only addresses. */
Jiri Pirko7aeef972010-02-05 02:52:39 +00003065 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003066 netdev_for_each_mc_addr(ha, netdev)
3067 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003068
Bruce Allanab8932f2010-01-13 02:05:38 +00003069 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003070 kfree(mta_list);
3071 } else {
3072 /*
3073 * if we're called from probe, we might not have
3074 * anything to do here, so clear out the list
3075 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003076 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003077 }
3078}
3079
3080/**
Bruce Allanad680762008-03-28 09:15:03 -07003081 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003082 * @adapter: private board structure
3083 **/
3084static void e1000_configure(struct e1000_adapter *adapter)
3085{
3086 e1000_set_multi(adapter->netdev);
3087
3088 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003089 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003090
3091 e1000_configure_tx(adapter);
3092 e1000_setup_rctl(adapter);
3093 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003094 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003095}
3096
3097/**
3098 * e1000e_power_up_phy - restore link in case the phy was powered down
3099 * @adapter: address of board private structure
3100 *
3101 * The phy may be powered down to save power and turn off link when the
3102 * driver is unloaded and wake on lan is not enabled (among others)
3103 * *** this routine MUST be followed by a call to e1000e_reset ***
3104 **/
3105void e1000e_power_up_phy(struct e1000_adapter *adapter)
3106{
Bruce Allan17f208d2009-12-01 15:47:22 +00003107 if (adapter->hw.phy.ops.power_up)
3108 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003109
3110 adapter->hw.mac.ops.setup_link(&adapter->hw);
3111}
3112
3113/**
3114 * e1000_power_down_phy - Power down the PHY
3115 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003116 * Power down the PHY so no link is implied when interface is down.
3117 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003118 */
3119static void e1000_power_down_phy(struct e1000_adapter *adapter)
3120{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003121 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003122 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003123 return;
3124
Bruce Allan17f208d2009-12-01 15:47:22 +00003125 if (adapter->hw.phy.ops.power_down)
3126 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003127}
3128
3129/**
3130 * e1000e_reset - bring the hardware into a known good state
3131 *
3132 * This function boots the hardware and enables some settings that
3133 * require a configuration cycle of the hardware - those cannot be
3134 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003135 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003136 */
3137void e1000e_reset(struct e1000_adapter *adapter)
3138{
3139 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003140 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003141 struct e1000_hw *hw = &adapter->hw;
3142 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003143 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003144 u16 hwm;
3145
Bruce Allanad680762008-03-28 09:15:03 -07003146 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003147 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003148
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003149 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003150 /*
3151 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003152 * large enough to accommodate two full transmit packets,
3153 * rounded up to the next 1KB and expressed in KB. Likewise,
3154 * the Rx FIFO should be large enough to accommodate at least
3155 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003156 * expressed in KB.
3157 */
Auke Kokdf762462007-10-25 13:57:53 -07003158 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003159 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003160 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003161 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003162 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003163 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003164 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003165 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003166 */
3167 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003168 sizeof(struct e1000_tx_desc) -
3169 ETH_FCS_LEN) * 2;
3170 min_tx_space = ALIGN(min_tx_space, 1024);
3171 min_tx_space >>= 10;
3172 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003173 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003174 min_rx_space = ALIGN(min_rx_space, 1024);
3175 min_rx_space >>= 10;
3176
Bruce Allanad680762008-03-28 09:15:03 -07003177 /*
3178 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003179 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003180 * allocation, take space away from current Rx allocation
3181 */
Auke Kokdf762462007-10-25 13:57:53 -07003182 if ((tx_space < min_tx_space) &&
3183 ((min_tx_space - tx_space) < pba)) {
3184 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003185
Bruce Allanad680762008-03-28 09:15:03 -07003186 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003187 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003188 * adjustment or use Early Receive if available
3189 */
Auke Kokdf762462007-10-25 13:57:53 -07003190 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003191 (!(adapter->flags & FLAG_HAS_ERT)))
3192 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003193 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003194 }
Auke Kokdf762462007-10-25 13:57:53 -07003195
3196 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003197 }
3198
Bruce Allanad680762008-03-28 09:15:03 -07003199 /*
3200 * flow control settings
3201 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003202 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003203 * (or the size used for early receive) above it in the Rx FIFO.
3204 * Set it to the lower of:
3205 * - 90% of the Rx FIFO size, and
3206 * - the full Rx FIFO size minus the early receive size (for parts
3207 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003208 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003209 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003210 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3211 fc->pause_time = 0xFFFF;
3212 else
3213 fc->pause_time = E1000_FC_PAUSE_TIME;
3214 fc->send_xon = 1;
3215 fc->current_mode = fc->requested_mode;
3216
3217 switch (hw->mac.type) {
3218 default:
3219 if ((adapter->flags & FLAG_HAS_ERT) &&
3220 (adapter->netdev->mtu > ETH_DATA_LEN))
3221 hwm = min(((pba << 10) * 9 / 10),
3222 ((pba << 10) - (E1000_ERT_2048 << 3)));
3223 else
3224 hwm = min(((pba << 10) * 9 / 10),
3225 ((pba << 10) - adapter->max_frame_size));
3226
3227 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3228 fc->low_water = fc->high_water - 8;
3229 break;
3230 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003231 /*
3232 * Workaround PCH LOM adapter hangs with certain network
3233 * loads. If hangs persist, try disabling Tx flow control.
3234 */
3235 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3236 fc->high_water = 0x3500;
3237 fc->low_water = 0x1500;
3238 } else {
3239 fc->high_water = 0x5000;
3240 fc->low_water = 0x3000;
3241 }
Bruce Allana3055952010-05-10 15:02:12 +00003242 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003243 break;
3244 case e1000_pch2lan:
3245 fc->high_water = 0x05C20;
3246 fc->low_water = 0x05048;
3247 fc->pause_time = 0x0650;
3248 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003249 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3250 pba = 14;
3251 ew32(PBA, pba);
3252 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003253 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003254 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003255
Bruce Allan828bac82010-09-29 21:39:37 +00003256 /*
3257 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3258 * fit in receive buffer and early-receive not supported.
3259 */
3260 if (adapter->itr_setting & 0x3) {
3261 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3262 !(adapter->flags & FLAG_HAS_ERT)) {
3263 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3264 dev_info(&adapter->pdev->dev,
3265 "Interrupt Throttle Rate turned off\n");
3266 adapter->flags2 |= FLAG2_DISABLE_AIM;
3267 ew32(ITR, 0);
3268 }
3269 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3270 dev_info(&adapter->pdev->dev,
3271 "Interrupt Throttle Rate turned on\n");
3272 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3273 adapter->itr = 20000;
3274 ew32(ITR, 1000000000 / (adapter->itr * 256));
3275 }
3276 }
3277
Auke Kokbc7f75f2007-09-17 12:30:59 -07003278 /* Allow time for pending master requests to run */
3279 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003280
3281 /*
3282 * For parts with AMT enabled, let the firmware know
3283 * that the network interface is in control
3284 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003285 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003286 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003287
Auke Kokbc7f75f2007-09-17 12:30:59 -07003288 ew32(WUC, 0);
3289
3290 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003291 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003292
3293 e1000_update_mng_vlan(adapter);
3294
3295 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3296 ew32(VET, ETH_P_8021Q);
3297
3298 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003299
3300 if (!netif_running(adapter->netdev) &&
3301 !test_bit(__E1000_TESTING, &adapter->state)) {
3302 e1000_power_down_phy(adapter);
3303 return;
3304 }
3305
Auke Kokbc7f75f2007-09-17 12:30:59 -07003306 e1000_get_phy_info(hw);
3307
Bruce Allan918d7192009-06-02 11:28:20 +00003308 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3309 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003310 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003311 /*
3312 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003313 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003314 * different we would do if it failed
3315 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003316 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3317 phy_data &= ~IGP02E1000_PM_SPD;
3318 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3319 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003320}
3321
3322int e1000e_up(struct e1000_adapter *adapter)
3323{
3324 struct e1000_hw *hw = &adapter->hw;
3325
3326 /* hardware has been reset, we need to reload some things */
3327 e1000_configure(adapter);
3328
3329 clear_bit(__E1000_DOWN, &adapter->state);
3330
3331 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003332 if (adapter->msix_entries)
3333 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003334 e1000_irq_enable(adapter);
3335
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003336 netif_wake_queue(adapter->netdev);
3337
Auke Kokbc7f75f2007-09-17 12:30:59 -07003338 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003339 if (adapter->msix_entries)
3340 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3341 else
3342 ew32(ICS, E1000_ICS_LSC);
3343
Auke Kokbc7f75f2007-09-17 12:30:59 -07003344 return 0;
3345}
3346
3347void e1000e_down(struct e1000_adapter *adapter)
3348{
3349 struct net_device *netdev = adapter->netdev;
3350 struct e1000_hw *hw = &adapter->hw;
3351 u32 tctl, rctl;
3352
Bruce Allanad680762008-03-28 09:15:03 -07003353 /*
3354 * signal that we're down so the interrupt handler does not
3355 * reschedule our watchdog timer
3356 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003357 set_bit(__E1000_DOWN, &adapter->state);
3358
3359 /* disable receives in the hardware */
3360 rctl = er32(RCTL);
3361 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3362 /* flush and sleep below */
3363
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003364 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003365
3366 /* disable transmits in the hardware */
3367 tctl = er32(TCTL);
3368 tctl &= ~E1000_TCTL_EN;
3369 ew32(TCTL, tctl);
3370 /* flush both disables and wait for them to finish */
3371 e1e_flush();
3372 msleep(10);
3373
3374 napi_disable(&adapter->napi);
3375 e1000_irq_disable(adapter);
3376
3377 del_timer_sync(&adapter->watchdog_timer);
3378 del_timer_sync(&adapter->phy_info_timer);
3379
Auke Kokbc7f75f2007-09-17 12:30:59 -07003380 netif_carrier_off(netdev);
3381 adapter->link_speed = 0;
3382 adapter->link_duplex = 0;
3383
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003384 if (!pci_channel_offline(adapter->pdev))
3385 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003386 e1000_clean_tx_ring(adapter);
3387 e1000_clean_rx_ring(adapter);
3388
3389 /*
3390 * TODO: for power management, we could drop the link and
3391 * pci_disable_device here.
3392 */
3393}
3394
3395void e1000e_reinit_locked(struct e1000_adapter *adapter)
3396{
3397 might_sleep();
3398 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3399 msleep(1);
3400 e1000e_down(adapter);
3401 e1000e_up(adapter);
3402 clear_bit(__E1000_RESETTING, &adapter->state);
3403}
3404
3405/**
3406 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3407 * @adapter: board private structure to initialize
3408 *
3409 * e1000_sw_init initializes the Adapter private data structure.
3410 * Fields are initialized based on PCI device information and
3411 * OS network device settings (MTU size).
3412 **/
3413static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3414{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003415 struct net_device *netdev = adapter->netdev;
3416
3417 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3418 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003419 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3420 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003421
Bruce Allan4662e822008-08-26 18:37:06 -07003422 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003423
Bruce Allan4662e822008-08-26 18:37:06 -07003424 if (e1000_alloc_queues(adapter))
3425 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426
Auke Kokbc7f75f2007-09-17 12:30:59 -07003427 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003428 e1000_irq_disable(adapter);
3429
Auke Kokbc7f75f2007-09-17 12:30:59 -07003430 set_bit(__E1000_DOWN, &adapter->state);
3431 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003432}
3433
3434/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003435 * e1000_intr_msi_test - Interrupt Handler
3436 * @irq: interrupt number
3437 * @data: pointer to a network interface device structure
3438 **/
3439static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3440{
3441 struct net_device *netdev = data;
3442 struct e1000_adapter *adapter = netdev_priv(netdev);
3443 struct e1000_hw *hw = &adapter->hw;
3444 u32 icr = er32(ICR);
3445
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003446 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003447 if (icr & E1000_ICR_RXSEQ) {
3448 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3449 wmb();
3450 }
3451
3452 return IRQ_HANDLED;
3453}
3454
3455/**
3456 * e1000_test_msi_interrupt - Returns 0 for successful test
3457 * @adapter: board private struct
3458 *
3459 * code flow taken from tg3.c
3460 **/
3461static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3462{
3463 struct net_device *netdev = adapter->netdev;
3464 struct e1000_hw *hw = &adapter->hw;
3465 int err;
3466
3467 /* poll_enable hasn't been called yet, so don't need disable */
3468 /* clear any pending events */
3469 er32(ICR);
3470
3471 /* free the real vector and request a test handler */
3472 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003473 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003474
3475 /* Assume that the test fails, if it succeeds then the test
3476 * MSI irq handler will unset this flag */
3477 adapter->flags |= FLAG_MSI_TEST_FAILED;
3478
3479 err = pci_enable_msi(adapter->pdev);
3480 if (err)
3481 goto msi_test_failed;
3482
Joe Perchesa0607fd2009-11-18 23:29:17 -08003483 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003484 netdev->name, netdev);
3485 if (err) {
3486 pci_disable_msi(adapter->pdev);
3487 goto msi_test_failed;
3488 }
3489
3490 wmb();
3491
3492 e1000_irq_enable(adapter);
3493
3494 /* fire an unusual interrupt on the test handler */
3495 ew32(ICS, E1000_ICS_RXSEQ);
3496 e1e_flush();
3497 msleep(50);
3498
3499 e1000_irq_disable(adapter);
3500
3501 rmb();
3502
3503 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003504 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003505 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3506 } else
3507 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003508
3509 free_irq(adapter->pdev->irq, netdev);
3510 pci_disable_msi(adapter->pdev);
3511
Bruce Allanf8d59f72008-08-08 18:36:11 -07003512msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003513 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003514 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003515}
3516
3517/**
3518 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3519 * @adapter: board private struct
3520 *
3521 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3522 **/
3523static int e1000_test_msi(struct e1000_adapter *adapter)
3524{
3525 int err;
3526 u16 pci_cmd;
3527
3528 if (!(adapter->flags & FLAG_MSI_ENABLED))
3529 return 0;
3530
3531 /* disable SERR in case the MSI write causes a master abort */
3532 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003533 if (pci_cmd & PCI_COMMAND_SERR)
3534 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3535 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003536
3537 err = e1000_test_msi_interrupt(adapter);
3538
Dean Nelson36f24072010-06-29 18:12:05 +00003539 /* re-enable SERR */
3540 if (pci_cmd & PCI_COMMAND_SERR) {
3541 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3542 pci_cmd |= PCI_COMMAND_SERR;
3543 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3544 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003545
Bruce Allanf8d59f72008-08-08 18:36:11 -07003546 return err;
3547}
3548
3549/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003550 * e1000_open - Called when a network interface is made active
3551 * @netdev: network interface device structure
3552 *
3553 * Returns 0 on success, negative value on failure
3554 *
3555 * The open entry point is called when a network interface is made
3556 * active by the system (IFF_UP). At this point all resources needed
3557 * for transmit and receive operations are allocated, the interrupt
3558 * handler is registered with the OS, the watchdog timer is started,
3559 * and the stack is notified that the interface is ready.
3560 **/
3561static int e1000_open(struct net_device *netdev)
3562{
3563 struct e1000_adapter *adapter = netdev_priv(netdev);
3564 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003565 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003566 int err;
3567
3568 /* disallow open during test */
3569 if (test_bit(__E1000_TESTING, &adapter->state))
3570 return -EBUSY;
3571
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003572 pm_runtime_get_sync(&pdev->dev);
3573
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003574 netif_carrier_off(netdev);
3575
Auke Kokbc7f75f2007-09-17 12:30:59 -07003576 /* allocate transmit descriptors */
3577 err = e1000e_setup_tx_resources(adapter);
3578 if (err)
3579 goto err_setup_tx;
3580
3581 /* allocate receive descriptors */
3582 err = e1000e_setup_rx_resources(adapter);
3583 if (err)
3584 goto err_setup_rx;
3585
Bruce Allan11b08be2010-05-10 14:59:31 +00003586 /*
3587 * If AMT is enabled, let the firmware know that the network
3588 * interface is now open and reset the part to a known state.
3589 */
3590 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003591 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003592 e1000e_reset(adapter);
3593 }
3594
Auke Kokbc7f75f2007-09-17 12:30:59 -07003595 e1000e_power_up_phy(adapter);
3596
3597 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3598 if ((adapter->hw.mng_cookie.status &
3599 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3600 e1000_update_mng_vlan(adapter);
3601
Florian Micklerc128ec22010-08-02 14:27:00 +00003602 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003603 if ((adapter->flags & FLAG_HAS_ERT) ||
3604 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003605 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3606 PM_QOS_CPU_DMA_LATENCY,
3607 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003608
Bruce Allanad680762008-03-28 09:15:03 -07003609 /*
Bruce Allanad680762008-03-28 09:15:03 -07003610 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003611 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3612 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003613 * clean_rx handler before we do so.
3614 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003615 e1000_configure(adapter);
3616
3617 err = e1000_request_irq(adapter);
3618 if (err)
3619 goto err_req_irq;
3620
Bruce Allanf8d59f72008-08-08 18:36:11 -07003621 /*
3622 * Work around PCIe errata with MSI interrupts causing some chipsets to
3623 * ignore e1000e MSI messages, which means we need to test our MSI
3624 * interrupt now
3625 */
Bruce Allan4662e822008-08-26 18:37:06 -07003626 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003627 err = e1000_test_msi(adapter);
3628 if (err) {
3629 e_err("Interrupt allocation failed\n");
3630 goto err_req_irq;
3631 }
3632 }
3633
Auke Kokbc7f75f2007-09-17 12:30:59 -07003634 /* From here on the code is the same as e1000e_up() */
3635 clear_bit(__E1000_DOWN, &adapter->state);
3636
3637 napi_enable(&adapter->napi);
3638
3639 e1000_irq_enable(adapter);
3640
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003641 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003642
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003643 adapter->idle_check = true;
3644 pm_runtime_put(&pdev->dev);
3645
Auke Kokbc7f75f2007-09-17 12:30:59 -07003646 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003647 if (adapter->msix_entries)
3648 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3649 else
3650 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003651
3652 return 0;
3653
3654err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003655 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656 e1000_power_down_phy(adapter);
3657 e1000e_free_rx_resources(adapter);
3658err_setup_rx:
3659 e1000e_free_tx_resources(adapter);
3660err_setup_tx:
3661 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003662 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003663
3664 return err;
3665}
3666
3667/**
3668 * e1000_close - Disables a network interface
3669 * @netdev: network interface device structure
3670 *
3671 * Returns 0, this is not allowed to fail
3672 *
3673 * The close entry point is called when an interface is de-activated
3674 * by the OS. The hardware is still under the drivers control, but
3675 * needs to be disabled. A global MAC reset is issued to stop the
3676 * hardware, and all transmit and receive resources are freed.
3677 **/
3678static int e1000_close(struct net_device *netdev)
3679{
3680 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003681 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682
3683 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003684
3685 pm_runtime_get_sync(&pdev->dev);
3686
3687 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3688 e1000e_down(adapter);
3689 e1000_free_irq(adapter);
3690 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003692
3693 e1000e_free_tx_resources(adapter);
3694 e1000e_free_rx_resources(adapter);
3695
Bruce Allanad680762008-03-28 09:15:03 -07003696 /*
3697 * kill manageability vlan ID if supported, but not if a vlan with
3698 * the same ID is registered on the host OS (let 8021q kill it)
3699 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003700 if ((adapter->hw.mng_cookie.status &
3701 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3702 !(adapter->vlgrp &&
3703 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3704 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3705
Bruce Allanad680762008-03-28 09:15:03 -07003706 /*
3707 * If AMT is enabled, let the firmware know that the network
3708 * interface is now closed
3709 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003710 if ((adapter->flags & FLAG_HAS_AMT) &&
3711 !test_bit(__E1000_TESTING, &adapter->state))
3712 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003713
Bruce Allan828bac82010-09-29 21:39:37 +00003714 if ((adapter->flags & FLAG_HAS_ERT) ||
3715 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003716 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003717
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003718 pm_runtime_put_sync(&pdev->dev);
3719
Auke Kokbc7f75f2007-09-17 12:30:59 -07003720 return 0;
3721}
3722/**
3723 * e1000_set_mac - Change the Ethernet Address of the NIC
3724 * @netdev: network interface device structure
3725 * @p: pointer to an address structure
3726 *
3727 * Returns 0 on success, negative on failure
3728 **/
3729static int e1000_set_mac(struct net_device *netdev, void *p)
3730{
3731 struct e1000_adapter *adapter = netdev_priv(netdev);
3732 struct sockaddr *addr = p;
3733
3734 if (!is_valid_ether_addr(addr->sa_data))
3735 return -EADDRNOTAVAIL;
3736
3737 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3738 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3739
3740 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3741
3742 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3743 /* activate the work around */
3744 e1000e_set_laa_state_82571(&adapter->hw, 1);
3745
Bruce Allanad680762008-03-28 09:15:03 -07003746 /*
3747 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003748 * between the time RAR[0] gets clobbered and the time it
3749 * gets fixed (in e1000_watchdog), the actual LAA is in one
3750 * of the RARs and no incoming packets directed to this port
3751 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003752 * RAR[14]
3753 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003754 e1000e_rar_set(&adapter->hw,
3755 adapter->hw.mac.addr,
3756 adapter->hw.mac.rar_entry_count - 1);
3757 }
3758
3759 return 0;
3760}
3761
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003762/**
3763 * e1000e_update_phy_task - work thread to update phy
3764 * @work: pointer to our work struct
3765 *
3766 * this worker thread exists because we must acquire a
3767 * semaphore to read the phy, which we could msleep while
3768 * waiting for it, and we can't msleep in a timer.
3769 **/
3770static void e1000e_update_phy_task(struct work_struct *work)
3771{
3772 struct e1000_adapter *adapter = container_of(work,
3773 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003774
3775 if (test_bit(__E1000_DOWN, &adapter->state))
3776 return;
3777
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003778 e1000_get_phy_info(&adapter->hw);
3779}
3780
Bruce Allanad680762008-03-28 09:15:03 -07003781/*
3782 * Need to wait a few seconds after link up to get diagnostic information from
3783 * the phy
3784 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003785static void e1000_update_phy_info(unsigned long data)
3786{
3787 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003788
3789 if (test_bit(__E1000_DOWN, &adapter->state))
3790 return;
3791
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003792 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003793}
3794
3795/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003796 * e1000e_update_phy_stats - Update the PHY statistics counters
3797 * @adapter: board private structure
3798 **/
3799static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3800{
3801 struct e1000_hw *hw = &adapter->hw;
3802 s32 ret_val;
3803 u16 phy_data;
3804
3805 ret_val = hw->phy.ops.acquire(hw);
3806 if (ret_val)
3807 return;
3808
3809 hw->phy.addr = 1;
3810
3811#define HV_PHY_STATS_PAGE 778
3812 /*
3813 * A page set is expensive so check if already on desired page.
3814 * If not, set to the page with the PHY status registers.
3815 */
3816 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3817 &phy_data);
3818 if (ret_val)
3819 goto release;
3820 if (phy_data != (HV_PHY_STATS_PAGE << IGP_PAGE_SHIFT)) {
3821 ret_val = e1000e_write_phy_reg_mdic(hw,
3822 IGP01E1000_PHY_PAGE_SELECT,
3823 (HV_PHY_STATS_PAGE <<
3824 IGP_PAGE_SHIFT));
3825 if (ret_val)
3826 goto release;
3827 }
3828
3829 /* Read/clear the upper 16-bit registers and read/accumulate lower */
3830
3831 /* Single Collision Count */
3832 e1000e_read_phy_reg_mdic(hw, HV_SCC_UPPER & MAX_PHY_REG_ADDRESS,
3833 &phy_data);
3834 ret_val = e1000e_read_phy_reg_mdic(hw,
3835 HV_SCC_LOWER & MAX_PHY_REG_ADDRESS,
3836 &phy_data);
3837 if (!ret_val)
3838 adapter->stats.scc += phy_data;
3839
3840 /* Excessive Collision Count */
3841 e1000e_read_phy_reg_mdic(hw, HV_ECOL_UPPER & MAX_PHY_REG_ADDRESS,
3842 &phy_data);
3843 ret_val = e1000e_read_phy_reg_mdic(hw,
3844 HV_ECOL_LOWER & MAX_PHY_REG_ADDRESS,
3845 &phy_data);
3846 if (!ret_val)
3847 adapter->stats.ecol += phy_data;
3848
3849 /* Multiple Collision Count */
3850 e1000e_read_phy_reg_mdic(hw, HV_MCC_UPPER & MAX_PHY_REG_ADDRESS,
3851 &phy_data);
3852 ret_val = e1000e_read_phy_reg_mdic(hw,
3853 HV_MCC_LOWER & MAX_PHY_REG_ADDRESS,
3854 &phy_data);
3855 if (!ret_val)
3856 adapter->stats.mcc += phy_data;
3857
3858 /* Late Collision Count */
3859 e1000e_read_phy_reg_mdic(hw, HV_LATECOL_UPPER & MAX_PHY_REG_ADDRESS,
3860 &phy_data);
3861 ret_val = e1000e_read_phy_reg_mdic(hw,
3862 HV_LATECOL_LOWER &
3863 MAX_PHY_REG_ADDRESS,
3864 &phy_data);
3865 if (!ret_val)
3866 adapter->stats.latecol += phy_data;
3867
3868 /* Collision Count - also used for adaptive IFS */
3869 e1000e_read_phy_reg_mdic(hw, HV_COLC_UPPER & MAX_PHY_REG_ADDRESS,
3870 &phy_data);
3871 ret_val = e1000e_read_phy_reg_mdic(hw,
3872 HV_COLC_LOWER & MAX_PHY_REG_ADDRESS,
3873 &phy_data);
3874 if (!ret_val)
3875 hw->mac.collision_delta = phy_data;
3876
3877 /* Defer Count */
3878 e1000e_read_phy_reg_mdic(hw, HV_DC_UPPER & MAX_PHY_REG_ADDRESS,
3879 &phy_data);
3880 ret_val = e1000e_read_phy_reg_mdic(hw,
3881 HV_DC_LOWER & MAX_PHY_REG_ADDRESS,
3882 &phy_data);
3883 if (!ret_val)
3884 adapter->stats.dc += phy_data;
3885
3886 /* Transmit with no CRS */
3887 e1000e_read_phy_reg_mdic(hw, HV_TNCRS_UPPER & MAX_PHY_REG_ADDRESS,
3888 &phy_data);
3889 ret_val = e1000e_read_phy_reg_mdic(hw,
3890 HV_TNCRS_LOWER & MAX_PHY_REG_ADDRESS,
3891 &phy_data);
3892 if (!ret_val)
3893 adapter->stats.tncrs += phy_data;
3894
3895release:
3896 hw->phy.ops.release(hw);
3897}
3898
3899/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003900 * e1000e_update_stats - Update the board statistics counters
3901 * @adapter: board private structure
3902 **/
3903void e1000e_update_stats(struct e1000_adapter *adapter)
3904{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003905 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003906 struct e1000_hw *hw = &adapter->hw;
3907 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003908
3909 /*
3910 * Prevent stats update while adapter is being reset, or if the pci
3911 * connection is down.
3912 */
3913 if (adapter->link_speed == 0)
3914 return;
3915 if (pci_channel_offline(pdev))
3916 return;
3917
Auke Kokbc7f75f2007-09-17 12:30:59 -07003918 adapter->stats.crcerrs += er32(CRCERRS);
3919 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003920 adapter->stats.gorc += er32(GORCL);
3921 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003922 adapter->stats.bprc += er32(BPRC);
3923 adapter->stats.mprc += er32(MPRC);
3924 adapter->stats.roc += er32(ROC);
3925
Auke Kokbc7f75f2007-09-17 12:30:59 -07003926 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003927
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003928 /* Half-duplex statistics */
3929 if (adapter->link_duplex == HALF_DUPLEX) {
3930 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
3931 e1000e_update_phy_stats(adapter);
3932 } else {
3933 adapter->stats.scc += er32(SCC);
3934 adapter->stats.ecol += er32(ECOL);
3935 adapter->stats.mcc += er32(MCC);
3936 adapter->stats.latecol += er32(LATECOL);
3937 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003938
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003939 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003940
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003941 if ((hw->mac.type != e1000_82574) &&
3942 (hw->mac.type != e1000_82583))
3943 adapter->stats.tncrs += er32(TNCRS);
3944 }
3945 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003946 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003947
Auke Kokbc7f75f2007-09-17 12:30:59 -07003948 adapter->stats.xonrxc += er32(XONRXC);
3949 adapter->stats.xontxc += er32(XONTXC);
3950 adapter->stats.xoffrxc += er32(XOFFRXC);
3951 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003952 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003953 adapter->stats.gotc += er32(GOTCL);
3954 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003955 adapter->stats.rnbc += er32(RNBC);
3956 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003957
3958 adapter->stats.mptc += er32(MPTC);
3959 adapter->stats.bptc += er32(BPTC);
3960
3961 /* used for adaptive IFS */
3962
3963 hw->mac.tx_packet_delta = er32(TPT);
3964 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003965
3966 adapter->stats.algnerrc += er32(ALGNERRC);
3967 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003968 adapter->stats.cexterr += er32(CEXTERR);
3969 adapter->stats.tsctc += er32(TSCTC);
3970 adapter->stats.tsctfc += er32(TSCTFC);
3971
Auke Kokbc7f75f2007-09-17 12:30:59 -07003972 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003973 netdev->stats.multicast = adapter->stats.mprc;
3974 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003975
3976 /* Rx Errors */
3977
Bruce Allanad680762008-03-28 09:15:03 -07003978 /*
3979 * RLEC on some newer hardware can be incorrect so build
3980 * our own version based on RUC and ROC
3981 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003982 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983 adapter->stats.crcerrs + adapter->stats.algnerrc +
3984 adapter->stats.ruc + adapter->stats.roc +
3985 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003986 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003987 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003988 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3989 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3990 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003991
3992 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003993 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003994 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003995 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3996 netdev->stats.tx_window_errors = adapter->stats.latecol;
3997 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003998
3999 /* Tx Dropped needs to be maintained elsewhere */
4000
Auke Kokbc7f75f2007-09-17 12:30:59 -07004001 /* Management Stats */
4002 adapter->stats.mgptc += er32(MGTPTC);
4003 adapter->stats.mgprc += er32(MGTPRC);
4004 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004005}
4006
Bruce Allan7c257692008-04-23 11:09:00 -07004007/**
4008 * e1000_phy_read_status - Update the PHY register status snapshot
4009 * @adapter: board private structure
4010 **/
4011static void e1000_phy_read_status(struct e1000_adapter *adapter)
4012{
4013 struct e1000_hw *hw = &adapter->hw;
4014 struct e1000_phy_regs *phy = &adapter->phy_regs;
4015 int ret_val;
Bruce Allan7c257692008-04-23 11:09:00 -07004016
4017 if ((er32(STATUS) & E1000_STATUS_LU) &&
4018 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
4019 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4020 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4021 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4022 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4023 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4024 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4025 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4026 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4027 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004028 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004029 } else {
4030 /*
4031 * Do not read PHY registers if link is not up
4032 * Set values to typical power-on defaults
4033 */
4034 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4035 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4036 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4037 BMSR_ERCAP);
4038 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4039 ADVERTISE_ALL | ADVERTISE_CSMA);
4040 phy->lpa = 0;
4041 phy->expansion = EXPANSION_ENABLENPAGE;
4042 phy->ctrl1000 = ADVERTISE_1000FULL;
4043 phy->stat1000 = 0;
4044 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4045 }
Bruce Allan7c257692008-04-23 11:09:00 -07004046}
4047
Auke Kokbc7f75f2007-09-17 12:30:59 -07004048static void e1000_print_link_info(struct e1000_adapter *adapter)
4049{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004050 struct e1000_hw *hw = &adapter->hw;
4051 u32 ctrl = er32(CTRL);
4052
Bruce Allan8f12fe82008-11-21 16:54:43 -08004053 /* Link status message must follow this format for user tools */
4054 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4055 "Flow Control: %s\n",
4056 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004057 adapter->link_speed,
4058 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004059 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004060 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004061 "Rx/Tx" :
4062 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4063 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004064}
4065
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004066static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004067{
4068 struct e1000_hw *hw = &adapter->hw;
4069 bool link_active = 0;
4070 s32 ret_val = 0;
4071
4072 /*
4073 * get_link_status is set on LSC (link status) interrupt or
4074 * Rx sequence error interrupt. get_link_status will stay
4075 * false until the check_for_link establishes link
4076 * for copper adapters ONLY
4077 */
4078 switch (hw->phy.media_type) {
4079 case e1000_media_type_copper:
4080 if (hw->mac.get_link_status) {
4081 ret_val = hw->mac.ops.check_for_link(hw);
4082 link_active = !hw->mac.get_link_status;
4083 } else {
4084 link_active = 1;
4085 }
4086 break;
4087 case e1000_media_type_fiber:
4088 ret_val = hw->mac.ops.check_for_link(hw);
4089 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4090 break;
4091 case e1000_media_type_internal_serdes:
4092 ret_val = hw->mac.ops.check_for_link(hw);
4093 link_active = adapter->hw.mac.serdes_has_link;
4094 break;
4095 default:
4096 case e1000_media_type_unknown:
4097 break;
4098 }
4099
4100 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4101 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4102 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004103 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004104 }
4105
4106 return link_active;
4107}
4108
4109static void e1000e_enable_receives(struct e1000_adapter *adapter)
4110{
4111 /* make sure the receive unit is started */
4112 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4113 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4114 struct e1000_hw *hw = &adapter->hw;
4115 u32 rctl = er32(RCTL);
4116 ew32(RCTL, rctl | E1000_RCTL_EN);
4117 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4118 }
4119}
4120
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004121static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4122{
4123 struct e1000_hw *hw = &adapter->hw;
4124
4125 /*
4126 * With 82574 controllers, PHY needs to be checked periodically
4127 * for hung state and reset, if two calls return true
4128 */
4129 if (e1000_check_phy_82574(hw))
4130 adapter->phy_hang_count++;
4131 else
4132 adapter->phy_hang_count = 0;
4133
4134 if (adapter->phy_hang_count > 1) {
4135 adapter->phy_hang_count = 0;
4136 schedule_work(&adapter->reset_task);
4137 }
4138}
4139
Auke Kokbc7f75f2007-09-17 12:30:59 -07004140/**
4141 * e1000_watchdog - Timer Call-back
4142 * @data: pointer to adapter cast into an unsigned long
4143 **/
4144static void e1000_watchdog(unsigned long data)
4145{
4146 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4147
4148 /* Do the rest outside of interrupt context */
4149 schedule_work(&adapter->watchdog_task);
4150
4151 /* TODO: make this use queue_delayed_work() */
4152}
4153
4154static void e1000_watchdog_task(struct work_struct *work)
4155{
4156 struct e1000_adapter *adapter = container_of(work,
4157 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004158 struct net_device *netdev = adapter->netdev;
4159 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004160 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004161 struct e1000_ring *tx_ring = adapter->tx_ring;
4162 struct e1000_hw *hw = &adapter->hw;
4163 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004164 int tx_pending = 0;
4165
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004166 if (test_bit(__E1000_DOWN, &adapter->state))
4167 return;
4168
David S. Millerb405e8d2010-02-04 22:31:41 -08004169 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004170 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004171 /* Cancel scheduled suspend requests. */
4172 pm_runtime_resume(netdev->dev.parent);
4173
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004174 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004175 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176 }
4177
4178 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4179 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4180 e1000_update_mng_vlan(adapter);
4181
Auke Kokbc7f75f2007-09-17 12:30:59 -07004182 if (link) {
4183 if (!netif_carrier_ok(netdev)) {
4184 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004185
4186 /* Cancel scheduled suspend requests. */
4187 pm_runtime_resume(netdev->dev.parent);
4188
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004189 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004190 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004191 mac->ops.get_link_up_info(&adapter->hw,
4192 &adapter->link_speed,
4193 &adapter->link_duplex);
4194 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004195 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004196 * On supported PHYs, check for duplex mismatch only
4197 * if link has autonegotiated at 10/100 half
4198 */
4199 if ((hw->phy.type == e1000_phy_igp_3 ||
4200 hw->phy.type == e1000_phy_bm) &&
4201 (hw->mac.autoneg == true) &&
4202 (adapter->link_speed == SPEED_10 ||
4203 adapter->link_speed == SPEED_100) &&
4204 (adapter->link_duplex == HALF_DUPLEX)) {
4205 u16 autoneg_exp;
4206
4207 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4208
4209 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4210 e_info("Autonegotiated half duplex but"
4211 " link partner cannot autoneg. "
4212 " Try forcing full duplex if "
4213 "link gets many collisions.\n");
4214 }
4215
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004216 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004217 adapter->tx_timeout_factor = 1;
4218 switch (adapter->link_speed) {
4219 case SPEED_10:
4220 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004221 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222 break;
4223 case SPEED_100:
4224 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004225 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004226 break;
4227 }
4228
Bruce Allanad680762008-03-28 09:15:03 -07004229 /*
4230 * workaround: re-program speed mode bit after
4231 * link-up event
4232 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004233 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4234 !txb2b) {
4235 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004236 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004237 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004238 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004239 }
4240
Bruce Allanad680762008-03-28 09:15:03 -07004241 /*
4242 * disable TSO for pcie and 10/100 speeds, to avoid
4243 * some hardware issues
4244 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004245 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4246 switch (adapter->link_speed) {
4247 case SPEED_10:
4248 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004249 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004250 netdev->features &= ~NETIF_F_TSO;
4251 netdev->features &= ~NETIF_F_TSO6;
4252 break;
4253 case SPEED_1000:
4254 netdev->features |= NETIF_F_TSO;
4255 netdev->features |= NETIF_F_TSO6;
4256 break;
4257 default:
4258 /* oops */
4259 break;
4260 }
4261 }
4262
Bruce Allanad680762008-03-28 09:15:03 -07004263 /*
4264 * enable transmits in the hardware, need to do this
4265 * after setting TARC(0)
4266 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004267 tctl = er32(TCTL);
4268 tctl |= E1000_TCTL_EN;
4269 ew32(TCTL, tctl);
4270
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004271 /*
4272 * Perform any post-link-up configuration before
4273 * reporting link up.
4274 */
4275 if (phy->ops.cfg_on_link_up)
4276 phy->ops.cfg_on_link_up(hw);
4277
Auke Kokbc7f75f2007-09-17 12:30:59 -07004278 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004279
4280 if (!test_bit(__E1000_DOWN, &adapter->state))
4281 mod_timer(&adapter->phy_info_timer,
4282 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004283 }
4284 } else {
4285 if (netif_carrier_ok(netdev)) {
4286 adapter->link_speed = 0;
4287 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004288 /* Link status message must follow this format */
4289 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4290 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004291 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004292 if (!test_bit(__E1000_DOWN, &adapter->state))
4293 mod_timer(&adapter->phy_info_timer,
4294 round_jiffies(jiffies + 2 * HZ));
4295
4296 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4297 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004298 else
4299 pm_schedule_suspend(netdev->dev.parent,
4300 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004301 }
4302 }
4303
4304link_up:
4305 e1000e_update_stats(adapter);
4306
4307 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4308 adapter->tpt_old = adapter->stats.tpt;
4309 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4310 adapter->colc_old = adapter->stats.colc;
4311
Bruce Allan7c257692008-04-23 11:09:00 -07004312 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4313 adapter->gorc_old = adapter->stats.gorc;
4314 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4315 adapter->gotc_old = adapter->stats.gotc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004316
4317 e1000e_update_adaptive(&adapter->hw);
4318
4319 if (!netif_carrier_ok(netdev)) {
4320 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
4321 tx_ring->count);
4322 if (tx_pending) {
Bruce Allanad680762008-03-28 09:15:03 -07004323 /*
4324 * We've lost link, so the controller stops DMA,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004325 * but we've got queued Tx work that's never going
4326 * to get done, so reset controller to flush Tx.
Bruce Allanad680762008-03-28 09:15:03 -07004327 * (Do the reset outside of interrupt context).
4328 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004329 schedule_work(&adapter->reset_task);
Jesse Brandeburgc2d5ab42009-05-07 11:07:35 +00004330 /* return immediately since reset is imminent */
4331 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004332 }
4333 }
4334
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004335 /* Simple mode for Interrupt Throttle Rate (ITR) */
4336 if (adapter->itr_setting == 4) {
4337 /*
4338 * Symmetric Tx/Rx gets a reduced ITR=2000;
4339 * Total asymmetrical Tx or Rx gets ITR=8000;
4340 * everyone else is between 2000-8000.
4341 */
4342 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4343 u32 dif = (adapter->gotc > adapter->gorc ?
4344 adapter->gotc - adapter->gorc :
4345 adapter->gorc - adapter->gotc) / 10000;
4346 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4347
4348 ew32(ITR, 1000000000 / (itr * 256));
4349 }
4350
Bruce Allanad680762008-03-28 09:15:03 -07004351 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004352 if (adapter->msix_entries)
4353 ew32(ICS, adapter->rx_ring->ims_val);
4354 else
4355 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004356
4357 /* Force detection of hung controller every watchdog period */
4358 adapter->detect_tx_hung = 1;
4359
Bruce Allanaf667a22010-12-31 06:10:01 +00004360 /* flush partial descriptors to memory before detecting Tx hang */
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00004361 if (adapter->flags2 & FLAG2_DMA_BURST) {
4362 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4363 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4364 /*
4365 * no need to flush the writes because the timeout code does
4366 * an er32 first thing
4367 */
4368 }
4369
Bruce Allanad680762008-03-28 09:15:03 -07004370 /*
4371 * With 82571 controllers, LAA may be overwritten due to controller
4372 * reset from the other port. Set the appropriate LAA in RAR[0]
4373 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004374 if (e1000e_get_laa_state_82571(hw))
4375 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4376
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004377 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4378 e1000e_check_82574_phy_workaround(adapter);
4379
Auke Kokbc7f75f2007-09-17 12:30:59 -07004380 /* Reset the timer */
4381 if (!test_bit(__E1000_DOWN, &adapter->state))
4382 mod_timer(&adapter->watchdog_timer,
4383 round_jiffies(jiffies + 2 * HZ));
4384}
4385
4386#define E1000_TX_FLAGS_CSUM 0x00000001
4387#define E1000_TX_FLAGS_VLAN 0x00000002
4388#define E1000_TX_FLAGS_TSO 0x00000004
4389#define E1000_TX_FLAGS_IPV4 0x00000008
4390#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4391#define E1000_TX_FLAGS_VLAN_SHIFT 16
4392
4393static int e1000_tso(struct e1000_adapter *adapter,
4394 struct sk_buff *skb)
4395{
4396 struct e1000_ring *tx_ring = adapter->tx_ring;
4397 struct e1000_context_desc *context_desc;
4398 struct e1000_buffer *buffer_info;
4399 unsigned int i;
4400 u32 cmd_length = 0;
4401 u16 ipcse = 0, tucse, mss;
4402 u8 ipcss, ipcso, tucss, tucso, hdr_len;
4403 int err;
4404
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004405 if (!skb_is_gso(skb))
4406 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004408 if (skb_header_cloned(skb)) {
4409 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4410 if (err)
4411 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004412 }
4413
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004414 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4415 mss = skb_shinfo(skb)->gso_size;
4416 if (skb->protocol == htons(ETH_P_IP)) {
4417 struct iphdr *iph = ip_hdr(skb);
4418 iph->tot_len = 0;
4419 iph->check = 0;
4420 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4421 0, IPPROTO_TCP, 0);
4422 cmd_length = E1000_TXD_CMD_IP;
4423 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004424 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004425 ipv6_hdr(skb)->payload_len = 0;
4426 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4427 &ipv6_hdr(skb)->daddr,
4428 0, IPPROTO_TCP, 0);
4429 ipcse = 0;
4430 }
4431 ipcss = skb_network_offset(skb);
4432 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4433 tucss = skb_transport_offset(skb);
4434 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4435 tucse = 0;
4436
4437 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4438 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4439
4440 i = tx_ring->next_to_use;
4441 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4442 buffer_info = &tx_ring->buffer_info[i];
4443
4444 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4445 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4446 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4447 context_desc->upper_setup.tcp_fields.tucss = tucss;
4448 context_desc->upper_setup.tcp_fields.tucso = tucso;
4449 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4450 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4451 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4452 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4453
4454 buffer_info->time_stamp = jiffies;
4455 buffer_info->next_to_watch = i;
4456
4457 i++;
4458 if (i == tx_ring->count)
4459 i = 0;
4460 tx_ring->next_to_use = i;
4461
4462 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004463}
4464
4465static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4466{
4467 struct e1000_ring *tx_ring = adapter->tx_ring;
4468 struct e1000_context_desc *context_desc;
4469 struct e1000_buffer *buffer_info;
4470 unsigned int i;
4471 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004472 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004473 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004474
Dave Grahamaf807c82008-10-09 14:28:58 -07004475 if (skb->ip_summed != CHECKSUM_PARTIAL)
4476 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004477
Arthur Jones5f66f202009-03-19 01:13:08 +00004478 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4479 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4480 else
4481 protocol = skb->protocol;
4482
Arthur Jones3f518392009-03-20 15:56:35 -07004483 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004484 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004485 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4486 cmd_len |= E1000_TXD_CMD_TCP;
4487 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004488 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004489 /* XXX not handling all IPV6 headers */
4490 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4491 cmd_len |= E1000_TXD_CMD_TCP;
4492 break;
4493 default:
4494 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004495 e_warn("checksum_partial proto=%x!\n",
4496 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004497 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004498 }
4499
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004500 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004501
4502 i = tx_ring->next_to_use;
4503 buffer_info = &tx_ring->buffer_info[i];
4504 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4505
4506 context_desc->lower_setup.ip_config = 0;
4507 context_desc->upper_setup.tcp_fields.tucss = css;
4508 context_desc->upper_setup.tcp_fields.tucso =
4509 css + skb->csum_offset;
4510 context_desc->upper_setup.tcp_fields.tucse = 0;
4511 context_desc->tcp_seg_setup.data = 0;
4512 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4513
4514 buffer_info->time_stamp = jiffies;
4515 buffer_info->next_to_watch = i;
4516
4517 i++;
4518 if (i == tx_ring->count)
4519 i = 0;
4520 tx_ring->next_to_use = i;
4521
4522 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004523}
4524
4525#define E1000_MAX_PER_TXD 8192
4526#define E1000_MAX_TXD_PWR 12
4527
4528static int e1000_tx_map(struct e1000_adapter *adapter,
4529 struct sk_buff *skb, unsigned int first,
4530 unsigned int max_per_txd, unsigned int nr_frags,
4531 unsigned int mss)
4532{
4533 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004534 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004535 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004536 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004537 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004538 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004539
4540 i = tx_ring->next_to_use;
4541
4542 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004543 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004544 size = min(len, max_per_txd);
4545
Auke Kokbc7f75f2007-09-17 12:30:59 -07004546 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004547 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004548 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004549 buffer_info->dma = dma_map_single(&pdev->dev,
4550 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004551 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004552 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004553 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004554 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004555
4556 len -= size;
4557 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004558 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004559
4560 if (len) {
4561 i++;
4562 if (i == tx_ring->count)
4563 i = 0;
4564 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004565 }
4566
4567 for (f = 0; f < nr_frags; f++) {
4568 struct skb_frag_struct *frag;
4569
4570 frag = &skb_shinfo(skb)->frags[f];
4571 len = frag->size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004572 offset = frag->page_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004573
4574 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004575 i++;
4576 if (i == tx_ring->count)
4577 i = 0;
4578
Auke Kokbc7f75f2007-09-17 12:30:59 -07004579 buffer_info = &tx_ring->buffer_info[i];
4580 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004581
4582 buffer_info->length = size;
4583 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004584 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004585 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
Alexander Duyck03b13202009-12-02 16:45:31 +00004586 offset, size,
Nick Nunley0be3f552010-04-27 13:09:05 +00004587 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004588 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004589 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004590 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004591
4592 len -= size;
4593 offset += size;
4594 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004595 }
4596 }
4597
Bruce Allanaf667a22010-12-31 06:10:01 +00004598 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004599 /* multiply data chunks by size of headers */
4600 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4601
Auke Kokbc7f75f2007-09-17 12:30:59 -07004602 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004603 tx_ring->buffer_info[i].segs = segs;
4604 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004605 tx_ring->buffer_info[first].next_to_watch = i;
4606
4607 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004608
4609dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004610 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004611 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004612 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004613 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004614
4615 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004616 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004617 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004618 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004619 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004620 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004621 }
4622
4623 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004624}
4625
4626static void e1000_tx_queue(struct e1000_adapter *adapter,
4627 int tx_flags, int count)
4628{
4629 struct e1000_ring *tx_ring = adapter->tx_ring;
4630 struct e1000_tx_desc *tx_desc = NULL;
4631 struct e1000_buffer *buffer_info;
4632 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4633 unsigned int i;
4634
4635 if (tx_flags & E1000_TX_FLAGS_TSO) {
4636 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4637 E1000_TXD_CMD_TSE;
4638 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4639
4640 if (tx_flags & E1000_TX_FLAGS_IPV4)
4641 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4642 }
4643
4644 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4645 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4646 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4647 }
4648
4649 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4650 txd_lower |= E1000_TXD_CMD_VLE;
4651 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4652 }
4653
4654 i = tx_ring->next_to_use;
4655
Bruce Allan36b973d2010-11-24 07:42:43 +00004656 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004657 buffer_info = &tx_ring->buffer_info[i];
4658 tx_desc = E1000_TX_DESC(*tx_ring, i);
4659 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4660 tx_desc->lower.data =
4661 cpu_to_le32(txd_lower | buffer_info->length);
4662 tx_desc->upper.data = cpu_to_le32(txd_upper);
4663
4664 i++;
4665 if (i == tx_ring->count)
4666 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004667 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004668
4669 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4670
Bruce Allanad680762008-03-28 09:15:03 -07004671 /*
4672 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004673 * know there are new descriptors to fetch. (Only
4674 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004675 * such as IA-64).
4676 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004677 wmb();
4678
4679 tx_ring->next_to_use = i;
4680 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07004681 /*
4682 * we need this if more than one processor can write to our tail
4683 * at a time, it synchronizes IO on IA64/Altix systems
4684 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004685 mmiowb();
4686}
4687
4688#define MINIMUM_DHCP_PACKET_SIZE 282
4689static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4690 struct sk_buff *skb)
4691{
4692 struct e1000_hw *hw = &adapter->hw;
4693 u16 length, offset;
4694
4695 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004696 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4697 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004698 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4699 return 0;
4700 }
4701
4702 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4703 return 0;
4704
4705 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4706 return 0;
4707
4708 {
4709 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4710 struct udphdr *udp;
4711
4712 if (ip->protocol != IPPROTO_UDP)
4713 return 0;
4714
4715 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4716 if (ntohs(udp->dest) != 67)
4717 return 0;
4718
4719 offset = (u8 *)udp + 8 - skb->data;
4720 length = skb->len - offset;
4721 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4722 }
4723
4724 return 0;
4725}
4726
4727static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4728{
4729 struct e1000_adapter *adapter = netdev_priv(netdev);
4730
4731 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004732 /*
4733 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004734 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004735 * but since that doesn't exist yet, just open code it.
4736 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004737 smp_mb();
4738
Bruce Allanad680762008-03-28 09:15:03 -07004739 /*
4740 * We need to check again in a case another CPU has just
4741 * made room available.
4742 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004743 if (e1000_desc_unused(adapter->tx_ring) < size)
4744 return -EBUSY;
4745
4746 /* A reprieve! */
4747 netif_start_queue(netdev);
4748 ++adapter->restart_queue;
4749 return 0;
4750}
4751
4752static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4753{
4754 struct e1000_adapter *adapter = netdev_priv(netdev);
4755
4756 if (e1000_desc_unused(adapter->tx_ring) >= size)
4757 return 0;
4758 return __e1000_maybe_stop_tx(netdev, size);
4759}
4760
4761#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004762static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4763 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004764{
4765 struct e1000_adapter *adapter = netdev_priv(netdev);
4766 struct e1000_ring *tx_ring = adapter->tx_ring;
4767 unsigned int first;
4768 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4769 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4770 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004771 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004772 unsigned int nr_frags;
4773 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004774 int count = 0;
4775 int tso;
4776 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004777
4778 if (test_bit(__E1000_DOWN, &adapter->state)) {
4779 dev_kfree_skb_any(skb);
4780 return NETDEV_TX_OK;
4781 }
4782
4783 if (skb->len <= 0) {
4784 dev_kfree_skb_any(skb);
4785 return NETDEV_TX_OK;
4786 }
4787
4788 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004789 /*
4790 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004791 * make sure there is enough room in the FIFO before
4792 * initiating the DMA for each buffer. The calc is:
4793 * 4 = ceil(buffer len/mss). To make sure we don't
4794 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004795 * drops.
4796 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004797 if (mss) {
4798 u8 hdr_len;
4799 max_per_txd = min(mss << 2, max_per_txd);
4800 max_txd_pwr = fls(max_per_txd) - 1;
4801
Bruce Allanad680762008-03-28 09:15:03 -07004802 /*
4803 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4804 * points to just header, pull a few bytes of payload from
4805 * frags into skb->data
4806 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004807 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004808 /*
4809 * we do this workaround for ES2LAN, but it is un-necessary,
4810 * avoiding it could save a lot of cycles
4811 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004812 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004813 unsigned int pull_size;
4814
4815 pull_size = min((unsigned int)4, skb->data_len);
4816 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004817 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004818 dev_kfree_skb_any(skb);
4819 return NETDEV_TX_OK;
4820 }
Eric Dumazete743d312010-04-14 15:59:40 -07004821 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004822 }
4823 }
4824
4825 /* reserve a descriptor for the offload context */
4826 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4827 count++;
4828 count++;
4829
4830 count += TXD_USE_COUNT(len, max_txd_pwr);
4831
4832 nr_frags = skb_shinfo(skb)->nr_frags;
4833 for (f = 0; f < nr_frags; f++)
4834 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4835 max_txd_pwr);
4836
4837 if (adapter->hw.mac.tx_pkt_filtering)
4838 e1000_transfer_dhcp_info(adapter, skb);
4839
Bruce Allanad680762008-03-28 09:15:03 -07004840 /*
4841 * need: count + 2 desc gap to keep tail from touching
4842 * head, otherwise try next time
4843 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004844 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004845 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004846
Jesse Grosseab6d182010-10-20 13:56:03 +00004847 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004848 tx_flags |= E1000_TX_FLAGS_VLAN;
4849 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4850 }
4851
4852 first = tx_ring->next_to_use;
4853
4854 tso = e1000_tso(adapter, skb);
4855 if (tso < 0) {
4856 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004857 return NETDEV_TX_OK;
4858 }
4859
4860 if (tso)
4861 tx_flags |= E1000_TX_FLAGS_TSO;
4862 else if (e1000_tx_csum(adapter, skb))
4863 tx_flags |= E1000_TX_FLAGS_CSUM;
4864
Bruce Allanad680762008-03-28 09:15:03 -07004865 /*
4866 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004867 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004868 * no longer assume, we must.
4869 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004870 if (skb->protocol == htons(ETH_P_IP))
4871 tx_flags |= E1000_TX_FLAGS_IPV4;
4872
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004873 /* if count is 0 then mapping error has occured */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004874 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004875 if (count) {
4876 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004877 /* Make sure there is space in the ring for the next send. */
4878 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4879
4880 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004881 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004882 tx_ring->buffer_info[first].time_stamp = 0;
4883 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004884 }
4885
Auke Kokbc7f75f2007-09-17 12:30:59 -07004886 return NETDEV_TX_OK;
4887}
4888
4889/**
4890 * e1000_tx_timeout - Respond to a Tx Hang
4891 * @netdev: network interface device structure
4892 **/
4893static void e1000_tx_timeout(struct net_device *netdev)
4894{
4895 struct e1000_adapter *adapter = netdev_priv(netdev);
4896
4897 /* Do the reset outside of interrupt context */
4898 adapter->tx_timeout_count++;
4899 schedule_work(&adapter->reset_task);
4900}
4901
4902static void e1000_reset_task(struct work_struct *work)
4903{
4904 struct e1000_adapter *adapter;
4905 adapter = container_of(work, struct e1000_adapter, reset_task);
4906
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004907 /* don't run the task if already down */
4908 if (test_bit(__E1000_DOWN, &adapter->state))
4909 return;
4910
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00004911 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4912 (adapter->flags & FLAG_RX_RESTART_NOW))) {
4913 e1000e_dump(adapter);
4914 e_err("Reset adapter\n");
4915 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004916 e1000e_reinit_locked(adapter);
4917}
4918
4919/**
4920 * e1000_get_stats - Get System Network Statistics
4921 * @netdev: network interface device structure
4922 *
4923 * Returns the address of the device statistics structure.
4924 * The statistics are actually updated from the timer callback.
4925 **/
4926static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
4927{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004928 /* only return the current stats */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004929 return &netdev->stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004930}
4931
4932/**
4933 * e1000_change_mtu - Change the Maximum Transfer Unit
4934 * @netdev: network interface device structure
4935 * @new_mtu: new value for maximum frame size
4936 *
4937 * Returns 0 on success, negative on failure
4938 **/
4939static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4940{
4941 struct e1000_adapter *adapter = netdev_priv(netdev);
4942 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4943
Bruce Allan2adc55c2009-06-02 11:28:58 +00004944 /* Jumbo frame support */
4945 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
4946 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
4947 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004948 return -EINVAL;
4949 }
4950
Bruce Allan2adc55c2009-06-02 11:28:58 +00004951 /* Supported frame sizes */
4952 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
4953 (max_frame > adapter->max_hw_frame_size)) {
4954 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004955 return -EINVAL;
4956 }
4957
Bruce Allana1ce6472010-09-22 17:16:40 +00004958 /* Jumbo frame workaround on 82579 requires CRC be stripped */
4959 if ((adapter->hw.mac.type == e1000_pch2lan) &&
4960 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
4961 (new_mtu > ETH_DATA_LEN)) {
4962 e_err("Jumbo Frames not supported on 82579 when CRC "
4963 "stripping is disabled.\n");
4964 return -EINVAL;
4965 }
4966
Bruce Allan6f461f62010-04-27 03:33:04 +00004967 /* 82573 Errata 17 */
4968 if (((adapter->hw.mac.type == e1000_82573) ||
4969 (adapter->hw.mac.type == e1000_82574)) &&
4970 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
4971 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
4972 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
4973 }
4974
Auke Kokbc7f75f2007-09-17 12:30:59 -07004975 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4976 msleep(1);
Bruce Allan610c9922009-11-19 12:35:45 +00004977 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004978 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00004979 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
4980 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004981 if (netif_running(netdev))
4982 e1000e_down(adapter);
4983
Bruce Allanad680762008-03-28 09:15:03 -07004984 /*
4985 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07004986 * means we reserve 2 more, this pushes us to allocate from the next
4987 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07004988 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004989 * However with the new *_jumbo_rx* routines, jumbo receives will use
4990 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07004991 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004992
Jesse Brandeburg99261462010-01-22 22:56:16 +00004993 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004994 adapter->rx_buffer_len = 2048;
4995 else
4996 adapter->rx_buffer_len = 4096;
4997
4998 /* adjust allocation if LPE protects us, and we aren't using SBP */
4999 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5000 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5001 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005002 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005003
Auke Kokbc7f75f2007-09-17 12:30:59 -07005004 if (netif_running(netdev))
5005 e1000e_up(adapter);
5006 else
5007 e1000e_reset(adapter);
5008
5009 clear_bit(__E1000_RESETTING, &adapter->state);
5010
5011 return 0;
5012}
5013
5014static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5015 int cmd)
5016{
5017 struct e1000_adapter *adapter = netdev_priv(netdev);
5018 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005019
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005020 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005021 return -EOPNOTSUPP;
5022
5023 switch (cmd) {
5024 case SIOCGMIIPHY:
5025 data->phy_id = adapter->hw.phy.addr;
5026 break;
5027 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005028 e1000_phy_read_status(adapter);
5029
Bruce Allan7c257692008-04-23 11:09:00 -07005030 switch (data->reg_num & 0x1F) {
5031 case MII_BMCR:
5032 data->val_out = adapter->phy_regs.bmcr;
5033 break;
5034 case MII_BMSR:
5035 data->val_out = adapter->phy_regs.bmsr;
5036 break;
5037 case MII_PHYSID1:
5038 data->val_out = (adapter->hw.phy.id >> 16);
5039 break;
5040 case MII_PHYSID2:
5041 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5042 break;
5043 case MII_ADVERTISE:
5044 data->val_out = adapter->phy_regs.advertise;
5045 break;
5046 case MII_LPA:
5047 data->val_out = adapter->phy_regs.lpa;
5048 break;
5049 case MII_EXPANSION:
5050 data->val_out = adapter->phy_regs.expansion;
5051 break;
5052 case MII_CTRL1000:
5053 data->val_out = adapter->phy_regs.ctrl1000;
5054 break;
5055 case MII_STAT1000:
5056 data->val_out = adapter->phy_regs.stat1000;
5057 break;
5058 case MII_ESTATUS:
5059 data->val_out = adapter->phy_regs.estatus;
5060 break;
5061 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005062 return -EIO;
5063 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005064 break;
5065 case SIOCSMIIREG:
5066 default:
5067 return -EOPNOTSUPP;
5068 }
5069 return 0;
5070}
5071
5072static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5073{
5074 switch (cmd) {
5075 case SIOCGMIIPHY:
5076 case SIOCGMIIREG:
5077 case SIOCSMIIREG:
5078 return e1000_mii_ioctl(netdev, ifr, cmd);
5079 default:
5080 return -EOPNOTSUPP;
5081 }
5082}
5083
Bruce Allana4f58f52009-06-02 11:29:18 +00005084static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5085{
5086 struct e1000_hw *hw = &adapter->hw;
5087 u32 i, mac_reg;
5088 u16 phy_reg;
5089 int retval = 0;
5090
5091 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005092 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005093
5094 /* copy MAC MTA to PHY MTA */
5095 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5096 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5097 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
5098 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
5099 }
5100
5101 /* configure PHY Rx Control register */
5102 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
5103 mac_reg = er32(RCTL);
5104 if (mac_reg & E1000_RCTL_UPE)
5105 phy_reg |= BM_RCTL_UPE;
5106 if (mac_reg & E1000_RCTL_MPE)
5107 phy_reg |= BM_RCTL_MPE;
5108 phy_reg &= ~(BM_RCTL_MO_MASK);
5109 if (mac_reg & E1000_RCTL_MO_3)
5110 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5111 << BM_RCTL_MO_SHIFT);
5112 if (mac_reg & E1000_RCTL_BAM)
5113 phy_reg |= BM_RCTL_BAM;
5114 if (mac_reg & E1000_RCTL_PMCF)
5115 phy_reg |= BM_RCTL_PMCF;
5116 mac_reg = er32(CTRL);
5117 if (mac_reg & E1000_CTRL_RFCE)
5118 phy_reg |= BM_RCTL_RFCE;
5119 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
5120
5121 /* enable PHY wakeup in MAC register */
5122 ew32(WUFC, wufc);
5123 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5124
5125 /* configure and enable PHY wakeup in PHY registers */
5126 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
5127 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5128
5129 /* activate PHY wakeup */
Bruce Allan94d81862009-11-20 23:25:26 +00005130 retval = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005131 if (retval) {
5132 e_err("Could not acquire PHY\n");
5133 return retval;
5134 }
5135 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
5136 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
5137 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
5138 if (retval) {
5139 e_err("Could not read PHY page 769\n");
5140 goto out;
5141 }
5142 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5143 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
5144 if (retval)
5145 e_err("Could not set PHY Host Wakeup bit\n");
5146out:
Bruce Allan94d81862009-11-20 23:25:26 +00005147 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005148
5149 return retval;
5150}
5151
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005152static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5153 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005154{
5155 struct net_device *netdev = pci_get_drvdata(pdev);
5156 struct e1000_adapter *adapter = netdev_priv(netdev);
5157 struct e1000_hw *hw = &adapter->hw;
5158 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005159 /* Runtime suspend should only enable wakeup for link changes */
5160 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005161 int retval = 0;
5162
5163 netif_device_detach(netdev);
5164
5165 if (netif_running(netdev)) {
5166 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5167 e1000e_down(adapter);
5168 e1000_free_irq(adapter);
5169 }
Bruce Allan4662e822008-08-26 18:37:06 -07005170 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005171
5172 retval = pci_save_state(pdev);
5173 if (retval)
5174 return retval;
5175
5176 status = er32(STATUS);
5177 if (status & E1000_STATUS_LU)
5178 wufc &= ~E1000_WUFC_LNKC;
5179
5180 if (wufc) {
5181 e1000_setup_rctl(adapter);
5182 e1000_set_multi(netdev);
5183
5184 /* turn on all-multi mode if wake on multicast is enabled */
5185 if (wufc & E1000_WUFC_MC) {
5186 rctl = er32(RCTL);
5187 rctl |= E1000_RCTL_MPE;
5188 ew32(RCTL, rctl);
5189 }
5190
5191 ctrl = er32(CTRL);
5192 /* advertise wake from D3Cold */
5193 #define E1000_CTRL_ADVD3WUC 0x00100000
5194 /* phy power management enable */
5195 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005196 ctrl |= E1000_CTRL_ADVD3WUC;
5197 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5198 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005199 ew32(CTRL, ctrl);
5200
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005201 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5202 adapter->hw.phy.media_type ==
5203 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005204 /* keep the laser running in D3 */
5205 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005206 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005207 ew32(CTRL_EXT, ctrl_ext);
5208 }
5209
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005210 if (adapter->flags & FLAG_IS_ICH)
5211 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
5212
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213 /* Allow time for pending master requests to run */
5214 e1000e_disable_pcie_master(&adapter->hw);
5215
Bruce Allan82776a42009-08-14 14:35:33 +00005216 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005217 /* enable wakeup by the PHY */
5218 retval = e1000_init_phy_wakeup(adapter, wufc);
5219 if (retval)
5220 return retval;
5221 } else {
5222 /* enable wakeup by the MAC */
5223 ew32(WUFC, wufc);
5224 ew32(WUC, E1000_WUC_PME_EN);
5225 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005226 } else {
5227 ew32(WUC, 0);
5228 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005229 }
5230
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005231 *enable_wake = !!wufc;
5232
Auke Kokbc7f75f2007-09-17 12:30:59 -07005233 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005234 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5235 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005236 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005237
5238 if (adapter->hw.phy.type == e1000_phy_igp_3)
5239 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5240
Bruce Allanad680762008-03-28 09:15:03 -07005241 /*
5242 * Release control of h/w to f/w. If f/w is AMT enabled, this
5243 * would have already happened in close and is redundant.
5244 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005245 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005246
5247 pci_disable_device(pdev);
5248
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005249 return 0;
5250}
5251
5252static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5253{
5254 if (sleep && wake) {
5255 pci_prepare_to_sleep(pdev);
5256 return;
5257 }
5258
5259 pci_wake_from_d3(pdev, wake);
5260 pci_set_power_state(pdev, PCI_D3hot);
5261}
5262
5263static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5264 bool wake)
5265{
5266 struct net_device *netdev = pci_get_drvdata(pdev);
5267 struct e1000_adapter *adapter = netdev_priv(netdev);
5268
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005269 /*
5270 * The pci-e switch on some quad port adapters will report a
5271 * correctable error when the MAC transitions from D0 to D3. To
5272 * prevent this we need to mask off the correctable errors on the
5273 * downstream port of the pci-e switch.
5274 */
5275 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5276 struct pci_dev *us_dev = pdev->bus->self;
5277 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
5278 u16 devctl;
5279
5280 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5281 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5282 (devctl & ~PCI_EXP_DEVCTL_CERE));
5283
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005284 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005285
5286 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5287 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005288 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005289 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005290}
5291
Bruce Allan6f461f62010-04-27 03:33:04 +00005292#ifdef CONFIG_PCIEASPM
5293static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5294{
5295 pci_disable_link_state(pdev, state);
5296}
5297#else
5298static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005299{
5300 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005301 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005302
5303 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005304 * Both device and parent should have the same ASPM setting.
5305 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005306 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005307 pos = pci_pcie_cap(pdev);
5308 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5309 reg16 &= ~state;
5310 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5311
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005312 if (!pdev->bus->self)
5313 return;
5314
Bruce Allan6f461f62010-04-27 03:33:04 +00005315 pos = pci_pcie_cap(pdev->bus->self);
5316 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5317 reg16 &= ~state;
5318 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5319}
5320#endif
5321void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5322{
5323 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5324 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5325 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5326
5327 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005328}
5329
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005330#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005331static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005332{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005333 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005334}
5335
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005336static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005337{
5338 struct net_device *netdev = pci_get_drvdata(pdev);
5339 struct e1000_adapter *adapter = netdev_priv(netdev);
5340 struct e1000_hw *hw = &adapter->hw;
5341 u32 err;
5342
5343 pci_set_power_state(pdev, PCI_D0);
5344 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005345 pci_save_state(pdev);
Bruce Allan6f461f62010-04-27 03:33:04 +00005346 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5347 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005348
Bruce Allan4662e822008-08-26 18:37:06 -07005349 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005350 if (netif_running(netdev)) {
5351 err = e1000_request_irq(adapter);
5352 if (err)
5353 return err;
5354 }
5355
5356 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005357
5358 /* report the system wakeup cause from S3/S4 */
5359 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5360 u16 phy_data;
5361
5362 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5363 if (phy_data) {
5364 e_info("PHY Wakeup cause - %s\n",
5365 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5366 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5367 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5368 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5369 phy_data & E1000_WUS_LNKC ? "Link Status "
5370 " Change" : "other");
5371 }
5372 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5373 } else {
5374 u32 wus = er32(WUS);
5375 if (wus) {
5376 e_info("MAC Wakeup cause - %s\n",
5377 wus & E1000_WUS_EX ? "Unicast Packet" :
5378 wus & E1000_WUS_MC ? "Multicast Packet" :
5379 wus & E1000_WUS_BC ? "Broadcast Packet" :
5380 wus & E1000_WUS_MAG ? "Magic Packet" :
5381 wus & E1000_WUS_LNKC ? "Link Status Change" :
5382 "other");
5383 }
5384 ew32(WUS, ~0);
5385 }
5386
Auke Kokbc7f75f2007-09-17 12:30:59 -07005387 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005388
Bruce Allancd791612010-05-10 14:59:51 +00005389 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005390
5391 if (netif_running(netdev))
5392 e1000e_up(adapter);
5393
5394 netif_device_attach(netdev);
5395
Bruce Allanad680762008-03-28 09:15:03 -07005396 /*
5397 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005398 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005399 * under the control of the driver.
5400 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005401 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005402 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005403
5404 return 0;
5405}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005406
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005407#ifdef CONFIG_PM_SLEEP
5408static int e1000_suspend(struct device *dev)
5409{
5410 struct pci_dev *pdev = to_pci_dev(dev);
5411 int retval;
5412 bool wake;
5413
5414 retval = __e1000_shutdown(pdev, &wake, false);
5415 if (!retval)
5416 e1000_complete_shutdown(pdev, true, wake);
5417
5418 return retval;
5419}
5420
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005421static int e1000_resume(struct device *dev)
5422{
5423 struct pci_dev *pdev = to_pci_dev(dev);
5424 struct net_device *netdev = pci_get_drvdata(pdev);
5425 struct e1000_adapter *adapter = netdev_priv(netdev);
5426
5427 if (e1000e_pm_ready(adapter))
5428 adapter->idle_check = true;
5429
5430 return __e1000_resume(pdev);
5431}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005432#endif /* CONFIG_PM_SLEEP */
5433
5434#ifdef CONFIG_PM_RUNTIME
5435static int e1000_runtime_suspend(struct device *dev)
5436{
5437 struct pci_dev *pdev = to_pci_dev(dev);
5438 struct net_device *netdev = pci_get_drvdata(pdev);
5439 struct e1000_adapter *adapter = netdev_priv(netdev);
5440
5441 if (e1000e_pm_ready(adapter)) {
5442 bool wake;
5443
5444 __e1000_shutdown(pdev, &wake, true);
5445 }
5446
5447 return 0;
5448}
5449
5450static int e1000_idle(struct device *dev)
5451{
5452 struct pci_dev *pdev = to_pci_dev(dev);
5453 struct net_device *netdev = pci_get_drvdata(pdev);
5454 struct e1000_adapter *adapter = netdev_priv(netdev);
5455
5456 if (!e1000e_pm_ready(adapter))
5457 return 0;
5458
5459 if (adapter->idle_check) {
5460 adapter->idle_check = false;
5461 if (!e1000e_has_link(adapter))
5462 pm_schedule_suspend(dev, MSEC_PER_SEC);
5463 }
5464
5465 return -EBUSY;
5466}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005467
5468static int e1000_runtime_resume(struct device *dev)
5469{
5470 struct pci_dev *pdev = to_pci_dev(dev);
5471 struct net_device *netdev = pci_get_drvdata(pdev);
5472 struct e1000_adapter *adapter = netdev_priv(netdev);
5473
5474 if (!e1000e_pm_ready(adapter))
5475 return 0;
5476
5477 adapter->idle_check = !dev->power.runtime_auto;
5478 return __e1000_resume(pdev);
5479}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005480#endif /* CONFIG_PM_RUNTIME */
5481#endif /* CONFIG_PM_OPS */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005482
5483static void e1000_shutdown(struct pci_dev *pdev)
5484{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005485 bool wake = false;
5486
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005487 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005488
5489 if (system_state == SYSTEM_POWER_OFF)
5490 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005491}
5492
5493#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005494
5495static irqreturn_t e1000_intr_msix(int irq, void *data)
5496{
5497 struct net_device *netdev = data;
5498 struct e1000_adapter *adapter = netdev_priv(netdev);
5499 int vector, msix_irq;
5500
5501 if (adapter->msix_entries) {
5502 vector = 0;
5503 msix_irq = adapter->msix_entries[vector].vector;
5504 disable_irq(msix_irq);
5505 e1000_intr_msix_rx(msix_irq, netdev);
5506 enable_irq(msix_irq);
5507
5508 vector++;
5509 msix_irq = adapter->msix_entries[vector].vector;
5510 disable_irq(msix_irq);
5511 e1000_intr_msix_tx(msix_irq, netdev);
5512 enable_irq(msix_irq);
5513
5514 vector++;
5515 msix_irq = adapter->msix_entries[vector].vector;
5516 disable_irq(msix_irq);
5517 e1000_msix_other(msix_irq, netdev);
5518 enable_irq(msix_irq);
5519 }
5520
5521 return IRQ_HANDLED;
5522}
5523
Auke Kokbc7f75f2007-09-17 12:30:59 -07005524/*
5525 * Polling 'interrupt' - used by things like netconsole to send skbs
5526 * without having to re-enable interrupts. It's not called while
5527 * the interrupt routine is executing.
5528 */
5529static void e1000_netpoll(struct net_device *netdev)
5530{
5531 struct e1000_adapter *adapter = netdev_priv(netdev);
5532
Dongdong Deng147b2c82010-11-16 19:50:15 -08005533 switch (adapter->int_mode) {
5534 case E1000E_INT_MODE_MSIX:
5535 e1000_intr_msix(adapter->pdev->irq, netdev);
5536 break;
5537 case E1000E_INT_MODE_MSI:
5538 disable_irq(adapter->pdev->irq);
5539 e1000_intr_msi(adapter->pdev->irq, netdev);
5540 enable_irq(adapter->pdev->irq);
5541 break;
5542 default: /* E1000E_INT_MODE_LEGACY */
5543 disable_irq(adapter->pdev->irq);
5544 e1000_intr(adapter->pdev->irq, netdev);
5545 enable_irq(adapter->pdev->irq);
5546 break;
5547 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005548}
5549#endif
5550
5551/**
5552 * e1000_io_error_detected - called when PCI error is detected
5553 * @pdev: Pointer to PCI device
5554 * @state: The current pci connection state
5555 *
5556 * This function is called after a PCI bus error affecting
5557 * this device has been detected.
5558 */
5559static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5560 pci_channel_state_t state)
5561{
5562 struct net_device *netdev = pci_get_drvdata(pdev);
5563 struct e1000_adapter *adapter = netdev_priv(netdev);
5564
5565 netif_device_detach(netdev);
5566
Mike Masonc93b5a72009-06-30 12:45:53 +00005567 if (state == pci_channel_io_perm_failure)
5568 return PCI_ERS_RESULT_DISCONNECT;
5569
Auke Kokbc7f75f2007-09-17 12:30:59 -07005570 if (netif_running(netdev))
5571 e1000e_down(adapter);
5572 pci_disable_device(pdev);
5573
5574 /* Request a slot slot reset. */
5575 return PCI_ERS_RESULT_NEED_RESET;
5576}
5577
5578/**
5579 * e1000_io_slot_reset - called after the pci bus has been reset.
5580 * @pdev: Pointer to PCI device
5581 *
5582 * Restart the card from scratch, as if from a cold-boot. Implementation
5583 * resembles the first-half of the e1000_resume routine.
5584 */
5585static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5586{
5587 struct net_device *netdev = pci_get_drvdata(pdev);
5588 struct e1000_adapter *adapter = netdev_priv(netdev);
5589 struct e1000_hw *hw = &adapter->hw;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005590 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005591 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005592
Bruce Allan6f461f62010-04-27 03:33:04 +00005593 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5594 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Bruce Allanf0f422e2008-08-04 17:21:53 -07005595 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005596 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005597 dev_err(&pdev->dev,
5598 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005599 result = PCI_ERS_RESULT_DISCONNECT;
5600 } else {
5601 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005602 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005603 pci_restore_state(pdev);
5604
5605 pci_enable_wake(pdev, PCI_D3hot, 0);
5606 pci_enable_wake(pdev, PCI_D3cold, 0);
5607
5608 e1000e_reset(adapter);
5609 ew32(WUS, ~0);
5610 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005611 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005612
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005613 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005614
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005615 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005616}
5617
5618/**
5619 * e1000_io_resume - called when traffic can start flowing again.
5620 * @pdev: Pointer to PCI device
5621 *
5622 * This callback is called when the error recovery driver tells us that
5623 * its OK to resume normal operation. Implementation resembles the
5624 * second-half of the e1000_resume routine.
5625 */
5626static void e1000_io_resume(struct pci_dev *pdev)
5627{
5628 struct net_device *netdev = pci_get_drvdata(pdev);
5629 struct e1000_adapter *adapter = netdev_priv(netdev);
5630
Bruce Allancd791612010-05-10 14:59:51 +00005631 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005632
5633 if (netif_running(netdev)) {
5634 if (e1000e_up(adapter)) {
5635 dev_err(&pdev->dev,
5636 "can't bring device back up after reset\n");
5637 return;
5638 }
5639 }
5640
5641 netif_device_attach(netdev);
5642
Bruce Allanad680762008-03-28 09:15:03 -07005643 /*
5644 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005645 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005646 * under the control of the driver.
5647 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005648 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005649 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005650
5651}
5652
5653static void e1000_print_device_info(struct e1000_adapter *adapter)
5654{
5655 struct e1000_hw *hw = &adapter->hw;
5656 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005657 u32 ret_val;
5658 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005659
5660 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005661 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005662 /* bus width */
5663 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5664 "Width x1"),
5665 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005666 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005667 e_info("Intel(R) PRO/%s Network Connection\n",
5668 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005669 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5670 E1000_PBANUM_LENGTH);
5671 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005672 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005673 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5674 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005675}
5676
Auke Kok10aa4c02008-08-04 17:21:20 -07005677static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5678{
5679 struct e1000_hw *hw = &adapter->hw;
5680 int ret_val;
5681 u16 buf = 0;
5682
5683 if (hw->mac.type != e1000_82573)
5684 return;
5685
5686 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005687 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005688 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005689 dev_warn(&adapter->pdev->dev,
5690 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005691 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005692}
5693
Stephen Hemminger651c2462008-11-19 21:57:48 -08005694static const struct net_device_ops e1000e_netdev_ops = {
5695 .ndo_open = e1000_open,
5696 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005697 .ndo_start_xmit = e1000_xmit_frame,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005698 .ndo_get_stats = e1000_get_stats,
5699 .ndo_set_multicast_list = e1000_set_multi,
5700 .ndo_set_mac_address = e1000_set_mac,
5701 .ndo_change_mtu = e1000_change_mtu,
5702 .ndo_do_ioctl = e1000_ioctl,
5703 .ndo_tx_timeout = e1000_tx_timeout,
5704 .ndo_validate_addr = eth_validate_addr,
5705
5706 .ndo_vlan_rx_register = e1000_vlan_rx_register,
5707 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5708 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5709#ifdef CONFIG_NET_POLL_CONTROLLER
5710 .ndo_poll_controller = e1000_netpoll,
5711#endif
5712};
5713
Auke Kokbc7f75f2007-09-17 12:30:59 -07005714/**
5715 * e1000_probe - Device Initialization Routine
5716 * @pdev: PCI device information struct
5717 * @ent: entry in e1000_pci_tbl
5718 *
5719 * Returns 0 on success, negative on failure
5720 *
5721 * e1000_probe initializes an adapter identified by a pci_dev structure.
5722 * The OS initialization, configuring of the adapter private structure,
5723 * and a hardware reset occur.
5724 **/
5725static int __devinit e1000_probe(struct pci_dev *pdev,
5726 const struct pci_device_id *ent)
5727{
5728 struct net_device *netdev;
5729 struct e1000_adapter *adapter;
5730 struct e1000_hw *hw;
5731 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005732 resource_size_t mmio_start, mmio_len;
5733 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005734
5735 static int cards_found;
5736 int i, err, pci_using_dac;
5737 u16 eeprom_data = 0;
5738 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5739
Bruce Allan6f461f62010-04-27 03:33:04 +00005740 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
5741 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005742
Bruce Allanf0f422e2008-08-04 17:21:53 -07005743 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005744 if (err)
5745 return err;
5746
5747 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005748 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005749 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005750 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005751 if (!err)
5752 pci_using_dac = 1;
5753 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005754 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005755 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005756 err = dma_set_coherent_mask(&pdev->dev,
5757 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005758 if (err) {
5759 dev_err(&pdev->dev, "No usable DMA "
5760 "configuration, aborting\n");
5761 goto err_dma;
5762 }
5763 }
5764 }
5765
Arjan van de Vene8de1482008-10-22 19:55:31 -07005766 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005767 pci_select_bars(pdev, IORESOURCE_MEM),
5768 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005769 if (err)
5770 goto err_pci_reg;
5771
Xiaotian Feng68eac462009-08-14 14:35:52 +00005772 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005773 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005774
Auke Kokbc7f75f2007-09-17 12:30:59 -07005775 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005776 /* PCI config space info */
5777 err = pci_save_state(pdev);
5778 if (err)
5779 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005780
5781 err = -ENOMEM;
5782 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5783 if (!netdev)
5784 goto err_alloc_etherdev;
5785
Auke Kokbc7f75f2007-09-17 12:30:59 -07005786 SET_NETDEV_DEV(netdev, &pdev->dev);
5787
Tom Herbertf85e4df2010-05-05 14:03:32 +00005788 netdev->irq = pdev->irq;
5789
Auke Kokbc7f75f2007-09-17 12:30:59 -07005790 pci_set_drvdata(pdev, netdev);
5791 adapter = netdev_priv(netdev);
5792 hw = &adapter->hw;
5793 adapter->netdev = netdev;
5794 adapter->pdev = pdev;
5795 adapter->ei = ei;
5796 adapter->pba = ei->pba;
5797 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005798 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005799 adapter->hw.adapter = adapter;
5800 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005801 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005802 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5803
5804 mmio_start = pci_resource_start(pdev, 0);
5805 mmio_len = pci_resource_len(pdev, 0);
5806
5807 err = -EIO;
5808 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5809 if (!adapter->hw.hw_addr)
5810 goto err_ioremap;
5811
5812 if ((adapter->flags & FLAG_HAS_FLASH) &&
5813 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5814 flash_start = pci_resource_start(pdev, 1);
5815 flash_len = pci_resource_len(pdev, 1);
5816 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5817 if (!adapter->hw.flash_address)
5818 goto err_flashmap;
5819 }
5820
5821 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005822 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005823 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005824 netdev->watchdog_timeo = 5 * HZ;
5825 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005826 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5827
5828 netdev->mem_start = mmio_start;
5829 netdev->mem_end = mmio_start + mmio_len;
5830
5831 adapter->bd_number = cards_found++;
5832
Bruce Allan4662e822008-08-26 18:37:06 -07005833 e1000e_check_options(adapter);
5834
Auke Kokbc7f75f2007-09-17 12:30:59 -07005835 /* setup adapter struct */
5836 err = e1000_sw_init(adapter);
5837 if (err)
5838 goto err_sw_init;
5839
Auke Kokbc7f75f2007-09-17 12:30:59 -07005840 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5841 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5842 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5843
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005844 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005845 if (err)
5846 goto err_hw_init;
5847
Bruce Allan4a770352008-10-01 17:18:35 -07005848 if ((adapter->flags & FLAG_IS_ICH) &&
5849 (adapter->flags & FLAG_READ_ONLY_NVM))
5850 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5851
Auke Kokbc7f75f2007-09-17 12:30:59 -07005852 hw->mac.ops.get_bus_info(&adapter->hw);
5853
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005854 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005855
5856 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005857 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005858 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5859 adapter->hw.phy.disable_polarity_correction = 0;
5860 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5861 }
5862
5863 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005864 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005865
5866 netdev->features = NETIF_F_SG |
5867 NETIF_F_HW_CSUM |
5868 NETIF_F_HW_VLAN_TX |
5869 NETIF_F_HW_VLAN_RX;
5870
5871 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5872 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5873
5874 netdev->features |= NETIF_F_TSO;
5875 netdev->features |= NETIF_F_TSO6;
5876
Jeff Kirshera5136e22008-06-05 04:07:28 -07005877 netdev->vlan_features |= NETIF_F_TSO;
5878 netdev->vlan_features |= NETIF_F_TSO6;
5879 netdev->vlan_features |= NETIF_F_HW_CSUM;
5880 netdev->vlan_features |= NETIF_F_SG;
5881
Yi Zou7b872a52010-09-22 17:57:58 +00005882 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005883 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00005884 netdev->vlan_features |= NETIF_F_HIGHDMA;
5885 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005886
Auke Kokbc7f75f2007-09-17 12:30:59 -07005887 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5888 adapter->flags |= FLAG_MNG_PT_ENABLED;
5889
Bruce Allanad680762008-03-28 09:15:03 -07005890 /*
5891 * before reading the NVM, reset the controller to
5892 * put the device in a known good starting state
5893 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005894 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5895
5896 /*
5897 * systems with ASPM and others may see the checksum fail on the first
5898 * attempt. Let's give it a few tries
5899 */
5900 for (i = 0;; i++) {
5901 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5902 break;
5903 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005904 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005905 err = -EIO;
5906 goto err_eeprom;
5907 }
5908 }
5909
Auke Kok10aa4c02008-08-04 17:21:20 -07005910 e1000_eeprom_checks(adapter);
5911
Bruce Allan608f8a02010-01-13 02:04:58 +00005912 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005913 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005914 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005915
5916 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5917 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5918
5919 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07005920 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005921 err = -EIO;
5922 goto err_eeprom;
5923 }
5924
5925 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005926 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005927 adapter->watchdog_timer.data = (unsigned long) adapter;
5928
5929 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005930 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005931 adapter->phy_info_timer.data = (unsigned long) adapter;
5932
5933 INIT_WORK(&adapter->reset_task, e1000_reset_task);
5934 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07005935 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
5936 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00005937 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Holger Eitzenberger9633e632010-11-17 15:43:52 +00005938 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005939
Auke Kokbc7f75f2007-09-17 12:30:59 -07005940 /* Initialize link parameters. User can change them with ethtool */
5941 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07005942 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08005943 adapter->hw.fc.requested_mode = e1000_fc_default;
5944 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005945 adapter->hw.phy.autoneg_advertised = 0x2f;
5946
5947 /* ring size defaults */
5948 adapter->rx_ring->count = 256;
5949 adapter->tx_ring->count = 256;
5950
5951 /*
5952 * Initial Wake on LAN setting - If APM wake is enabled in
5953 * the EEPROM, enable the ACPI Magic Packet filter
5954 */
5955 if (adapter->flags & FLAG_APME_IN_WUC) {
5956 /* APME bit in EEPROM is mapped to WUC.APME */
5957 eeprom_data = er32(WUC);
5958 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allana4f58f52009-06-02 11:29:18 +00005959 if (eeprom_data & E1000_WUC_PHY_WAKE)
5960 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005961 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
5962 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
5963 (adapter->hw.bus.func == 1))
5964 e1000_read_nvm(&adapter->hw,
5965 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
5966 else
5967 e1000_read_nvm(&adapter->hw,
5968 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
5969 }
5970
5971 /* fetch WoL from EEPROM */
5972 if (eeprom_data & eeprom_apme_mask)
5973 adapter->eeprom_wol |= E1000_WUFC_MAG;
5974
5975 /*
5976 * now that we have the eeprom settings, apply the special cases
5977 * where the eeprom may be wrong or the board simply won't support
5978 * wake on lan on a particular port
5979 */
5980 if (!(adapter->flags & FLAG_HAS_WOL))
5981 adapter->eeprom_wol = 0;
5982
5983 /* initialize the wol settings based on the eeprom settings */
5984 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00005985 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005986
Bruce Allan84527592008-11-21 17:00:22 -08005987 /* save off EEPROM version number */
5988 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
5989
Auke Kokbc7f75f2007-09-17 12:30:59 -07005990 /* reset the hardware with the new settings */
5991 e1000e_reset(adapter);
5992
Bruce Allanad680762008-03-28 09:15:03 -07005993 /*
5994 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005995 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005996 * under the control of the driver.
5997 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005998 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005999 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006000
Bruce Allane0dc4f12011-01-06 14:29:50 +00006001 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006002 err = register_netdev(netdev);
6003 if (err)
6004 goto err_register;
6005
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006006 /* carrier off reporting is important to ethtool even BEFORE open */
6007 netif_carrier_off(netdev);
6008
Auke Kokbc7f75f2007-09-17 12:30:59 -07006009 e1000_print_device_info(adapter);
6010
Alan Sternf3ec4f82010-06-08 15:23:51 -04006011 if (pci_dev_run_wake(pdev))
6012 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006013
Auke Kokbc7f75f2007-09-17 12:30:59 -07006014 return 0;
6015
6016err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006017 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006018 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006019err_eeprom:
6020 if (!e1000_check_reset_block(&adapter->hw))
6021 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006022err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006023 kfree(adapter->tx_ring);
6024 kfree(adapter->rx_ring);
6025err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006026 if (adapter->hw.flash_address)
6027 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006028 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006029err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006030 iounmap(adapter->hw.hw_addr);
6031err_ioremap:
6032 free_netdev(netdev);
6033err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006034 pci_release_selected_regions(pdev,
6035 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006036err_pci_reg:
6037err_dma:
6038 pci_disable_device(pdev);
6039 return err;
6040}
6041
6042/**
6043 * e1000_remove - Device Removal Routine
6044 * @pdev: PCI device information struct
6045 *
6046 * e1000_remove is called by the PCI subsystem to alert the driver
6047 * that it should release a PCI device. The could be caused by a
6048 * Hot-Plug event, or because the driver is going to be removed from
6049 * memory.
6050 **/
6051static void __devexit e1000_remove(struct pci_dev *pdev)
6052{
6053 struct net_device *netdev = pci_get_drvdata(pdev);
6054 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006055 bool down = test_bit(__E1000_DOWN, &adapter->state);
6056
Bruce Allanad680762008-03-28 09:15:03 -07006057 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006058 * The timers may be rescheduled, so explicitly disable them
6059 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006060 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006061 if (!down)
6062 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006063 del_timer_sync(&adapter->watchdog_timer);
6064 del_timer_sync(&adapter->phy_info_timer);
6065
Bruce Allan41cec6f2009-11-20 23:28:56 +00006066 cancel_work_sync(&adapter->reset_task);
6067 cancel_work_sync(&adapter->watchdog_task);
6068 cancel_work_sync(&adapter->downshift_task);
6069 cancel_work_sync(&adapter->update_phy_task);
Tejun Heo23f333a2010-12-12 16:45:14 +01006070 cancel_work_sync(&adapter->led_blink_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006071 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006072
Bruce Allan17f208d2009-12-01 15:47:22 +00006073 if (!(netdev->flags & IFF_UP))
6074 e1000_power_down_phy(adapter);
6075
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006076 /* Don't lie to e1000_close() down the road. */
6077 if (!down)
6078 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006079 unregister_netdev(netdev);
6080
Alan Sternf3ec4f82010-06-08 15:23:51 -04006081 if (pci_dev_run_wake(pdev))
6082 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006083
Bruce Allanad680762008-03-28 09:15:03 -07006084 /*
6085 * Release control of h/w to f/w. If f/w is AMT enabled, this
6086 * would have already happened in close and is redundant.
6087 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006088 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006089
Bruce Allan4662e822008-08-26 18:37:06 -07006090 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006091 kfree(adapter->tx_ring);
6092 kfree(adapter->rx_ring);
6093
6094 iounmap(adapter->hw.hw_addr);
6095 if (adapter->hw.flash_address)
6096 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006097 pci_release_selected_regions(pdev,
6098 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006099
6100 free_netdev(netdev);
6101
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006102 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006103 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006104
Auke Kokbc7f75f2007-09-17 12:30:59 -07006105 pci_disable_device(pdev);
6106}
6107
6108/* PCI Error Recovery (ERS) */
6109static struct pci_error_handlers e1000_err_handler = {
6110 .error_detected = e1000_io_error_detected,
6111 .slot_reset = e1000_io_slot_reset,
6112 .resume = e1000_io_resume,
6113};
6114
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006115static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006116 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6117 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6118 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6119 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6120 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6121 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006122 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6123 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6124 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006125
Auke Kokbc7f75f2007-09-17 12:30:59 -07006126 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6127 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6128 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6129 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006130
Auke Kokbc7f75f2007-09-17 12:30:59 -07006131 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6132 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6133 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006134
Bruce Allan4662e822008-08-26 18:37:06 -07006135 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006136 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006137 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006138
Auke Kokbc7f75f2007-09-17 12:30:59 -07006139 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6140 board_80003es2lan },
6141 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6142 board_80003es2lan },
6143 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6144 board_80003es2lan },
6145 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6146 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006147
Auke Kokbc7f75f2007-09-17 12:30:59 -07006148 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6149 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6150 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6151 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6152 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6153 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6154 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006155 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006156
Auke Kokbc7f75f2007-09-17 12:30:59 -07006157 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6158 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6159 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6160 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6161 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006162 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006163 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6164 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6165 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6166
6167 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6168 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6169 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006170
Bruce Allanf4187b52008-08-26 18:36:50 -07006171 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6172 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006173 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006174
Bruce Allana4f58f52009-06-02 11:29:18 +00006175 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6176 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6177 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6178 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6179
Bruce Alland3738bb2010-06-16 13:27:28 +00006180 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6181 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6182
Auke Kokbc7f75f2007-09-17 12:30:59 -07006183 { } /* terminate list */
6184};
6185MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6186
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006187#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006188static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006189 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6190 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6191 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006192};
David S. Millere50208a2010-03-16 23:36:24 -07006193#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006194
Auke Kokbc7f75f2007-09-17 12:30:59 -07006195/* PCI Device API Driver */
6196static struct pci_driver e1000_driver = {
6197 .name = e1000e_driver_name,
6198 .id_table = e1000_pci_tbl,
6199 .probe = e1000_probe,
6200 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006201#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006202 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006203#endif
6204 .shutdown = e1000_shutdown,
6205 .err_handler = &e1000_err_handler
6206};
6207
6208/**
6209 * e1000_init_module - Driver Registration Routine
6210 *
6211 * e1000_init_module is the first routine called when the driver is
6212 * loaded. All it does is register with the PCI subsystem.
6213 **/
6214static int __init e1000_init_module(void)
6215{
6216 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006217 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6218 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006219 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006220 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006221
Auke Kokbc7f75f2007-09-17 12:30:59 -07006222 return ret;
6223}
6224module_init(e1000_init_module);
6225
6226/**
6227 * e1000_exit_module - Driver Exit Cleanup Routine
6228 *
6229 * e1000_exit_module is called just before the driver is removed
6230 * from memory.
6231 **/
6232static void __exit e1000_exit_module(void)
6233{
6234 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006235}
6236module_exit(e1000_exit_module);
6237
6238
6239MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6240MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6241MODULE_LICENSE("GPL");
6242MODULE_VERSION(DRV_VERSION);
6243
6244/* e1000_main.c */