blob: 8a3145e9aa3edf68b81456953611427cf714e151 [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 Allan70d279a2011-02-26 03:12:19 +000057#define DRV_VERSION "1.3.10" 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{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000462 u16 tag = le16_to_cpu(vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700463 skb->protocol = eth_type_trans(skb, netdev);
464
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000465 if (status & E1000_RXD_STAT_VP)
466 __vlan_hwaccel_put_tag(skb, tag);
467
468 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;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700903 return cleaned;
904}
905
Auke Kokbc7f75f2007-09-17 12:30:59 -0700906static void e1000_put_txbuf(struct e1000_adapter *adapter,
907 struct e1000_buffer *buffer_info)
908{
Alexander Duyck03b13202009-12-02 16:45:31 +0000909 if (buffer_info->dma) {
910 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +0000911 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
912 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000913 else
Nick Nunley0be3f552010-04-27 13:09:05 +0000914 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
915 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000916 buffer_info->dma = 0;
917 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918 if (buffer_info->skb) {
919 dev_kfree_skb_any(buffer_info->skb);
920 buffer_info->skb = NULL;
921 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000922 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700923}
924
Bruce Allan41cec6f2009-11-20 23:28:56 +0000925static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700926{
Bruce Allan41cec6f2009-11-20 23:28:56 +0000927 struct e1000_adapter *adapter = container_of(work,
928 struct e1000_adapter,
929 print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700930 struct e1000_ring *tx_ring = adapter->tx_ring;
931 unsigned int i = tx_ring->next_to_clean;
932 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
933 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +0000934 struct e1000_hw *hw = &adapter->hw;
935 u16 phy_status, phy_1000t_status, phy_ext_status;
936 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700937
Jesse Brandeburg615b32a2011-02-02 10:19:45 +0000938 if (test_bit(__E1000_DOWN, &adapter->state))
939 return;
940
Bruce Allan41cec6f2009-11-20 23:28:56 +0000941 e1e_rphy(hw, PHY_STATUS, &phy_status);
942 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
943 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
944
945 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
946
947 /* detected Hardware unit hang */
948 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700949 " TDH <%x>\n"
950 " TDT <%x>\n"
951 " next_to_use <%x>\n"
952 " next_to_clean <%x>\n"
953 "buffer_info[next_to_clean]:\n"
954 " time_stamp <%lx>\n"
955 " next_to_watch <%x>\n"
956 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +0000957 " next_to_watch.status <%x>\n"
958 "MAC Status <%x>\n"
959 "PHY Status <%x>\n"
960 "PHY 1000BASE-T Status <%x>\n"
961 "PHY Extended Status <%x>\n"
962 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700963 readl(adapter->hw.hw_addr + tx_ring->head),
964 readl(adapter->hw.hw_addr + tx_ring->tail),
965 tx_ring->next_to_use,
966 tx_ring->next_to_clean,
967 tx_ring->buffer_info[eop].time_stamp,
968 eop,
969 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +0000970 eop_desc->upper.fields.status,
971 er32(STATUS),
972 phy_status,
973 phy_1000t_status,
974 phy_ext_status,
975 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700976}
977
978/**
979 * e1000_clean_tx_irq - Reclaim resources after transmit completes
980 * @adapter: board private structure
981 *
982 * the return value indicates whether actual cleaning was done, there
983 * is no guarantee that everything was cleaned
984 **/
985static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
986{
987 struct net_device *netdev = adapter->netdev;
988 struct e1000_hw *hw = &adapter->hw;
989 struct e1000_ring *tx_ring = adapter->tx_ring;
990 struct e1000_tx_desc *tx_desc, *eop_desc;
991 struct e1000_buffer *buffer_info;
992 unsigned int i, eop;
993 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700994 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
995
996 i = tx_ring->next_to_clean;
997 eop = tx_ring->buffer_info[i].next_to_watch;
998 eop_desc = E1000_TX_DESC(*tx_ring, eop);
999
Alexander Duyck12d04a32009-03-25 22:05:03 +00001000 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1001 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001002 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001003 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001004 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005 tx_desc = E1000_TX_DESC(*tx_ring, i);
1006 buffer_info = &tx_ring->buffer_info[i];
1007 cleaned = (i == eop);
1008
1009 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001010 total_tx_packets += buffer_info->segs;
1011 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001012 }
1013
1014 e1000_put_txbuf(adapter, buffer_info);
1015 tx_desc->upper.data = 0;
1016
1017 i++;
1018 if (i == tx_ring->count)
1019 i = 0;
1020 }
1021
Terry Loftindac87612010-04-09 10:29:49 +00001022 if (i == tx_ring->next_to_use)
1023 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024 eop = tx_ring->buffer_info[i].next_to_watch;
1025 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026 }
1027
1028 tx_ring->next_to_clean = i;
1029
1030#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001031 if (count && netif_carrier_ok(netdev) &&
1032 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001033 /* Make sure that anybody stopping the queue after this
1034 * sees the new next_to_clean.
1035 */
1036 smp_mb();
1037
1038 if (netif_queue_stopped(netdev) &&
1039 !(test_bit(__E1000_DOWN, &adapter->state))) {
1040 netif_wake_queue(netdev);
1041 ++adapter->restart_queue;
1042 }
1043 }
1044
1045 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001046 /*
1047 * Detect a transmit hang in hardware, this serializes the
1048 * check with the clearing of time_stamp and movement of i
1049 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001050 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001051 if (tx_ring->buffer_info[i].time_stamp &&
1052 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001053 + (adapter->tx_timeout_factor * HZ)) &&
1054 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001055 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001056 netif_stop_queue(netdev);
1057 }
1058 }
1059 adapter->total_tx_bytes += total_tx_bytes;
1060 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001061 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001062}
1063
1064/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001065 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1066 * @adapter: board private structure
1067 *
1068 * the return value indicates whether actual cleaning was done, there
1069 * is no guarantee that everything was cleaned
1070 **/
1071static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1072 int *work_done, int work_to_do)
1073{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001074 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001075 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1076 struct net_device *netdev = adapter->netdev;
1077 struct pci_dev *pdev = adapter->pdev;
1078 struct e1000_ring *rx_ring = adapter->rx_ring;
1079 struct e1000_buffer *buffer_info, *next_buffer;
1080 struct e1000_ps_page *ps_page;
1081 struct sk_buff *skb;
1082 unsigned int i, j;
1083 u32 length, staterr;
1084 int cleaned_count = 0;
1085 bool cleaned = 0;
1086 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1087
1088 i = rx_ring->next_to_clean;
1089 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1090 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1091 buffer_info = &rx_ring->buffer_info[i];
1092
1093 while (staterr & E1000_RXD_STAT_DD) {
1094 if (*work_done >= work_to_do)
1095 break;
1096 (*work_done)++;
1097 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001098 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099
1100 /* in the packet split case this is header only */
1101 prefetch(skb->data - NET_IP_ALIGN);
1102
1103 i++;
1104 if (i == rx_ring->count)
1105 i = 0;
1106 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1107 prefetch(next_rxd);
1108
1109 next_buffer = &rx_ring->buffer_info[i];
1110
1111 cleaned = 1;
1112 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001113 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001114 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115 buffer_info->dma = 0;
1116
Bruce Allanaf667a22010-12-31 06:10:01 +00001117 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001118 if (!(staterr & E1000_RXD_STAT_EOP))
1119 adapter->flags2 |= FLAG2_IS_DISCARDING;
1120
1121 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001122 e_dbg("Packet Split buffers didn't pick up the full "
1123 "packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001124 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001125 if (staterr & E1000_RXD_STAT_EOP)
1126 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127 goto next_desc;
1128 }
1129
1130 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1131 dev_kfree_skb_irq(skb);
1132 goto next_desc;
1133 }
1134
1135 length = le16_to_cpu(rx_desc->wb.middle.length0);
1136
1137 if (!length) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001138 e_dbg("Last part of the packet spanning multiple "
1139 "descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140 dev_kfree_skb_irq(skb);
1141 goto next_desc;
1142 }
1143
1144 /* Good Receive */
1145 skb_put(skb, length);
1146
1147 {
Bruce Allanad680762008-03-28 09:15:03 -07001148 /*
1149 * this looks ugly, but it seems compiler issues make it
1150 * more efficient than reusing j
1151 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001152 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1153
Bruce Allanad680762008-03-28 09:15:03 -07001154 /*
1155 * page alloc/put takes too long and effects small packet
1156 * throughput, so unsplit small packets and save the alloc/put
1157 * only valid in softirq (napi) context to call kmap_*
1158 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001159 if (l1 && (l1 <= copybreak) &&
1160 ((length + l1) <= adapter->rx_ps_bsize0)) {
1161 u8 *vaddr;
1162
Auke Kok47f44e42007-10-25 13:57:44 -07001163 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001164
Bruce Allanad680762008-03-28 09:15:03 -07001165 /*
1166 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001168 * very long
1169 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001170 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1171 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001172 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1173 memcpy(skb_tail_pointer(skb), vaddr, l1);
1174 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001175 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1176 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001177
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001178 /* remove the CRC */
1179 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1180 l1 -= 4;
1181
Auke Kokbc7f75f2007-09-17 12:30:59 -07001182 skb_put(skb, l1);
1183 goto copydone;
1184 } /* if */
1185 }
1186
1187 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1188 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1189 if (!length)
1190 break;
1191
Auke Kok47f44e42007-10-25 13:57:44 -07001192 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001193 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1194 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001195 ps_page->dma = 0;
1196 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1197 ps_page->page = NULL;
1198 skb->len += length;
1199 skb->data_len += length;
1200 skb->truesize += length;
1201 }
1202
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001203 /* strip the ethernet crc, problem is we're using pages now so
1204 * this whole operation can get a little cpu intensive
1205 */
1206 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1207 pskb_trim(skb, skb->len - 4);
1208
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209copydone:
1210 total_rx_bytes += skb->len;
1211 total_rx_packets++;
1212
1213 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1214 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1215
1216 if (rx_desc->wb.upper.header_status &
1217 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1218 adapter->rx_hdr_split++;
1219
1220 e1000_receive_skb(adapter, netdev, skb,
1221 staterr, rx_desc->wb.middle.vlan);
1222
1223next_desc:
1224 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1225 buffer_info->skb = NULL;
1226
1227 /* return some buffers to hardware, one at a time is too slow */
1228 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1229 adapter->alloc_rx_buf(adapter, cleaned_count);
1230 cleaned_count = 0;
1231 }
1232
1233 /* use prefetched values */
1234 rx_desc = next_rxd;
1235 buffer_info = next_buffer;
1236
1237 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1238 }
1239 rx_ring->next_to_clean = i;
1240
1241 cleaned_count = e1000_desc_unused(rx_ring);
1242 if (cleaned_count)
1243 adapter->alloc_rx_buf(adapter, cleaned_count);
1244
Auke Kokbc7f75f2007-09-17 12:30:59 -07001245 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001246 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001247 return cleaned;
1248}
1249
1250/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001251 * e1000_consume_page - helper function
1252 **/
1253static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1254 u16 length)
1255{
1256 bi->page = NULL;
1257 skb->len += length;
1258 skb->data_len += length;
1259 skb->truesize += length;
1260}
1261
1262/**
1263 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1264 * @adapter: board private structure
1265 *
1266 * the return value indicates whether actual cleaning was done, there
1267 * is no guarantee that everything was cleaned
1268 **/
1269
1270static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1271 int *work_done, int work_to_do)
1272{
1273 struct net_device *netdev = adapter->netdev;
1274 struct pci_dev *pdev = adapter->pdev;
1275 struct e1000_ring *rx_ring = adapter->rx_ring;
1276 struct e1000_rx_desc *rx_desc, *next_rxd;
1277 struct e1000_buffer *buffer_info, *next_buffer;
1278 u32 length;
1279 unsigned int i;
1280 int cleaned_count = 0;
1281 bool cleaned = false;
1282 unsigned int total_rx_bytes=0, total_rx_packets=0;
1283
1284 i = rx_ring->next_to_clean;
1285 rx_desc = E1000_RX_DESC(*rx_ring, i);
1286 buffer_info = &rx_ring->buffer_info[i];
1287
1288 while (rx_desc->status & E1000_RXD_STAT_DD) {
1289 struct sk_buff *skb;
1290 u8 status;
1291
1292 if (*work_done >= work_to_do)
1293 break;
1294 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001295 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001296
1297 status = rx_desc->status;
1298 skb = buffer_info->skb;
1299 buffer_info->skb = NULL;
1300
1301 ++i;
1302 if (i == rx_ring->count)
1303 i = 0;
1304 next_rxd = E1000_RX_DESC(*rx_ring, i);
1305 prefetch(next_rxd);
1306
1307 next_buffer = &rx_ring->buffer_info[i];
1308
1309 cleaned = true;
1310 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001311 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1312 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001313 buffer_info->dma = 0;
1314
1315 length = le16_to_cpu(rx_desc->length);
1316
1317 /* errors is only valid for DD + EOP descriptors */
1318 if (unlikely((status & E1000_RXD_STAT_EOP) &&
1319 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
1320 /* recycle both page and skb */
1321 buffer_info->skb = skb;
1322 /* an error means any chain goes out the window
1323 * too */
1324 if (rx_ring->rx_skb_top)
Bruce Allanef5ab892011-02-10 08:17:21 +00001325 dev_kfree_skb_irq(rx_ring->rx_skb_top);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001326 rx_ring->rx_skb_top = NULL;
1327 goto next_desc;
1328 }
1329
Bruce Allanf0f1a172010-12-11 05:53:32 +00001330#define rxtop (rx_ring->rx_skb_top)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001331 if (!(status & E1000_RXD_STAT_EOP)) {
1332 /* this descriptor is only the beginning (or middle) */
1333 if (!rxtop) {
1334 /* this is the beginning of a chain */
1335 rxtop = skb;
1336 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1337 0, length);
1338 } else {
1339 /* this is the middle of a chain */
1340 skb_fill_page_desc(rxtop,
1341 skb_shinfo(rxtop)->nr_frags,
1342 buffer_info->page, 0, length);
1343 /* re-use the skb, only consumed the page */
1344 buffer_info->skb = skb;
1345 }
1346 e1000_consume_page(buffer_info, rxtop, length);
1347 goto next_desc;
1348 } else {
1349 if (rxtop) {
1350 /* end of the chain */
1351 skb_fill_page_desc(rxtop,
1352 skb_shinfo(rxtop)->nr_frags,
1353 buffer_info->page, 0, length);
1354 /* re-use the current skb, we only consumed the
1355 * page */
1356 buffer_info->skb = skb;
1357 skb = rxtop;
1358 rxtop = NULL;
1359 e1000_consume_page(buffer_info, skb, length);
1360 } else {
1361 /* no chain, got EOP, this buf is the packet
1362 * copybreak to save the put_page/alloc_page */
1363 if (length <= copybreak &&
1364 skb_tailroom(skb) >= length) {
1365 u8 *vaddr;
1366 vaddr = kmap_atomic(buffer_info->page,
1367 KM_SKB_DATA_SOFTIRQ);
1368 memcpy(skb_tail_pointer(skb), vaddr,
1369 length);
1370 kunmap_atomic(vaddr,
1371 KM_SKB_DATA_SOFTIRQ);
1372 /* re-use the page, so don't erase
1373 * buffer_info->page */
1374 skb_put(skb, length);
1375 } else {
1376 skb_fill_page_desc(skb, 0,
1377 buffer_info->page, 0,
1378 length);
1379 e1000_consume_page(buffer_info, skb,
1380 length);
1381 }
1382 }
1383 }
1384
1385 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1386 e1000_rx_checksum(adapter,
1387 (u32)(status) |
1388 ((u32)(rx_desc->errors) << 24),
1389 le16_to_cpu(rx_desc->csum), skb);
1390
1391 /* probably a little skewed due to removing CRC */
1392 total_rx_bytes += skb->len;
1393 total_rx_packets++;
1394
1395 /* eth type trans needs skb->data to point to something */
1396 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001397 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001398 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001399 goto next_desc;
1400 }
1401
1402 e1000_receive_skb(adapter, netdev, skb, status,
1403 rx_desc->special);
1404
1405next_desc:
1406 rx_desc->status = 0;
1407
1408 /* return some buffers to hardware, one at a time is too slow */
1409 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1410 adapter->alloc_rx_buf(adapter, cleaned_count);
1411 cleaned_count = 0;
1412 }
1413
1414 /* use prefetched values */
1415 rx_desc = next_rxd;
1416 buffer_info = next_buffer;
1417 }
1418 rx_ring->next_to_clean = i;
1419
1420 cleaned_count = e1000_desc_unused(rx_ring);
1421 if (cleaned_count)
1422 adapter->alloc_rx_buf(adapter, cleaned_count);
1423
1424 adapter->total_rx_bytes += total_rx_bytes;
1425 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001426 return cleaned;
1427}
1428
1429/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001430 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1431 * @adapter: board private structure
1432 **/
1433static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1434{
1435 struct e1000_ring *rx_ring = adapter->rx_ring;
1436 struct e1000_buffer *buffer_info;
1437 struct e1000_ps_page *ps_page;
1438 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001439 unsigned int i, j;
1440
1441 /* Free all the Rx ring sk_buffs */
1442 for (i = 0; i < rx_ring->count; i++) {
1443 buffer_info = &rx_ring->buffer_info[i];
1444 if (buffer_info->dma) {
1445 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001446 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001447 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001448 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001449 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001450 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001451 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001452 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001453 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
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_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001456 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001457 buffer_info->dma = 0;
1458 }
1459
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001460 if (buffer_info->page) {
1461 put_page(buffer_info->page);
1462 buffer_info->page = NULL;
1463 }
1464
Auke Kokbc7f75f2007-09-17 12:30:59 -07001465 if (buffer_info->skb) {
1466 dev_kfree_skb(buffer_info->skb);
1467 buffer_info->skb = NULL;
1468 }
1469
1470 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001471 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001472 if (!ps_page->page)
1473 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001474 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1475 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001476 ps_page->dma = 0;
1477 put_page(ps_page->page);
1478 ps_page->page = NULL;
1479 }
1480 }
1481
1482 /* there also may be some cached data from a chained receive */
1483 if (rx_ring->rx_skb_top) {
1484 dev_kfree_skb(rx_ring->rx_skb_top);
1485 rx_ring->rx_skb_top = NULL;
1486 }
1487
Auke Kokbc7f75f2007-09-17 12:30:59 -07001488 /* Zero out the descriptor ring */
1489 memset(rx_ring->desc, 0, rx_ring->size);
1490
1491 rx_ring->next_to_clean = 0;
1492 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001493 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001494
1495 writel(0, adapter->hw.hw_addr + rx_ring->head);
1496 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1497}
1498
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001499static void e1000e_downshift_workaround(struct work_struct *work)
1500{
1501 struct e1000_adapter *adapter = container_of(work,
1502 struct e1000_adapter, downshift_task);
1503
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001504 if (test_bit(__E1000_DOWN, &adapter->state))
1505 return;
1506
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001507 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1508}
1509
Auke Kokbc7f75f2007-09-17 12:30:59 -07001510/**
1511 * e1000_intr_msi - Interrupt Handler
1512 * @irq: interrupt number
1513 * @data: pointer to a network interface device structure
1514 **/
1515static irqreturn_t e1000_intr_msi(int irq, void *data)
1516{
1517 struct net_device *netdev = data;
1518 struct e1000_adapter *adapter = netdev_priv(netdev);
1519 struct e1000_hw *hw = &adapter->hw;
1520 u32 icr = er32(ICR);
1521
Bruce Allanad680762008-03-28 09:15:03 -07001522 /*
1523 * read ICR disables interrupts using IAM
1524 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001525
dave graham573cca82009-02-10 12:52:05 +00001526 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001527 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001528 /*
1529 * ICH8 workaround-- Call gig speed drop workaround on cable
1530 * disconnect (LSC) before accessing any PHY registers
1531 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001532 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1533 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001534 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001535
Bruce Allanad680762008-03-28 09:15:03 -07001536 /*
1537 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001538 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001539 * adapter in watchdog
1540 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001541 if (netif_carrier_ok(netdev) &&
1542 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1543 /* disable receives */
1544 u32 rctl = er32(RCTL);
1545 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001546 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001547 }
1548 /* guard against interrupt when we're going down */
1549 if (!test_bit(__E1000_DOWN, &adapter->state))
1550 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1551 }
1552
Ben Hutchings288379f2009-01-19 16:43:59 -08001553 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001554 adapter->total_tx_bytes = 0;
1555 adapter->total_tx_packets = 0;
1556 adapter->total_rx_bytes = 0;
1557 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001558 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001559 }
1560
1561 return IRQ_HANDLED;
1562}
1563
1564/**
1565 * e1000_intr - Interrupt Handler
1566 * @irq: interrupt number
1567 * @data: pointer to a network interface device structure
1568 **/
1569static irqreturn_t e1000_intr(int irq, void *data)
1570{
1571 struct net_device *netdev = data;
1572 struct e1000_adapter *adapter = netdev_priv(netdev);
1573 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001575
Bruce Allana68ea772009-11-20 23:23:16 +00001576 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577 return IRQ_NONE; /* Not our interrupt */
1578
Bruce Allanad680762008-03-28 09:15:03 -07001579 /*
1580 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1581 * not set, then the adapter didn't send an interrupt
1582 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001583 if (!(icr & E1000_ICR_INT_ASSERTED))
1584 return IRQ_NONE;
1585
Bruce Allanad680762008-03-28 09:15:03 -07001586 /*
1587 * Interrupt Auto-Mask...upon reading ICR,
1588 * interrupts are masked. No need for the
1589 * IMC write
1590 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001591
dave graham573cca82009-02-10 12:52:05 +00001592 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001593 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001594 /*
1595 * ICH8 workaround-- Call gig speed drop workaround on cable
1596 * disconnect (LSC) before accessing any PHY registers
1597 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001598 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1599 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001600 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001601
Bruce Allanad680762008-03-28 09:15:03 -07001602 /*
1603 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001604 * For packet buffer work-around on link down event;
1605 * disable receives here in the ISR and
1606 * reset adapter in watchdog
1607 */
1608 if (netif_carrier_ok(netdev) &&
1609 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1610 /* disable receives */
1611 rctl = er32(RCTL);
1612 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001613 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001614 }
1615 /* guard against interrupt when we're going down */
1616 if (!test_bit(__E1000_DOWN, &adapter->state))
1617 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1618 }
1619
Ben Hutchings288379f2009-01-19 16:43:59 -08001620 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001621 adapter->total_tx_bytes = 0;
1622 adapter->total_tx_packets = 0;
1623 adapter->total_rx_bytes = 0;
1624 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001625 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001626 }
1627
1628 return IRQ_HANDLED;
1629}
1630
Bruce Allan4662e822008-08-26 18:37:06 -07001631static irqreturn_t e1000_msix_other(int irq, void *data)
1632{
1633 struct net_device *netdev = data;
1634 struct e1000_adapter *adapter = netdev_priv(netdev);
1635 struct e1000_hw *hw = &adapter->hw;
1636 u32 icr = er32(ICR);
1637
1638 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001639 if (!test_bit(__E1000_DOWN, &adapter->state))
1640 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001641 return IRQ_NONE;
1642 }
1643
1644 if (icr & adapter->eiac_mask)
1645 ew32(ICS, (icr & adapter->eiac_mask));
1646
1647 if (icr & E1000_ICR_OTHER) {
1648 if (!(icr & E1000_ICR_LSC))
1649 goto no_link_interrupt;
1650 hw->mac.get_link_status = 1;
1651 /* guard against interrupt when we're going down */
1652 if (!test_bit(__E1000_DOWN, &adapter->state))
1653 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1654 }
1655
1656no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001657 if (!test_bit(__E1000_DOWN, &adapter->state))
1658 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001659
1660 return IRQ_HANDLED;
1661}
1662
1663
1664static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1665{
1666 struct net_device *netdev = data;
1667 struct e1000_adapter *adapter = netdev_priv(netdev);
1668 struct e1000_hw *hw = &adapter->hw;
1669 struct e1000_ring *tx_ring = adapter->tx_ring;
1670
1671
1672 adapter->total_tx_bytes = 0;
1673 adapter->total_tx_packets = 0;
1674
1675 if (!e1000_clean_tx_irq(adapter))
1676 /* Ring was not completely cleaned, so fire another interrupt */
1677 ew32(ICS, tx_ring->ims_val);
1678
1679 return IRQ_HANDLED;
1680}
1681
1682static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1683{
1684 struct net_device *netdev = data;
1685 struct e1000_adapter *adapter = netdev_priv(netdev);
1686
1687 /* Write the ITR value calculated at the end of the
1688 * previous interrupt.
1689 */
1690 if (adapter->rx_ring->set_itr) {
1691 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1692 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1693 adapter->rx_ring->set_itr = 0;
1694 }
1695
Ben Hutchings288379f2009-01-19 16:43:59 -08001696 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001697 adapter->total_rx_bytes = 0;
1698 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001699 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001700 }
1701 return IRQ_HANDLED;
1702}
1703
1704/**
1705 * e1000_configure_msix - Configure MSI-X hardware
1706 *
1707 * e1000_configure_msix sets up the hardware to properly
1708 * generate MSI-X interrupts.
1709 **/
1710static void e1000_configure_msix(struct e1000_adapter *adapter)
1711{
1712 struct e1000_hw *hw = &adapter->hw;
1713 struct e1000_ring *rx_ring = adapter->rx_ring;
1714 struct e1000_ring *tx_ring = adapter->tx_ring;
1715 int vector = 0;
1716 u32 ctrl_ext, ivar = 0;
1717
1718 adapter->eiac_mask = 0;
1719
1720 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1721 if (hw->mac.type == e1000_82574) {
1722 u32 rfctl = er32(RFCTL);
1723 rfctl |= E1000_RFCTL_ACK_DIS;
1724 ew32(RFCTL, rfctl);
1725 }
1726
1727#define E1000_IVAR_INT_ALLOC_VALID 0x8
1728 /* Configure Rx vector */
1729 rx_ring->ims_val = E1000_IMS_RXQ0;
1730 adapter->eiac_mask |= rx_ring->ims_val;
1731 if (rx_ring->itr_val)
1732 writel(1000000000 / (rx_ring->itr_val * 256),
1733 hw->hw_addr + rx_ring->itr_register);
1734 else
1735 writel(1, hw->hw_addr + rx_ring->itr_register);
1736 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1737
1738 /* Configure Tx vector */
1739 tx_ring->ims_val = E1000_IMS_TXQ0;
1740 vector++;
1741 if (tx_ring->itr_val)
1742 writel(1000000000 / (tx_ring->itr_val * 256),
1743 hw->hw_addr + tx_ring->itr_register);
1744 else
1745 writel(1, hw->hw_addr + tx_ring->itr_register);
1746 adapter->eiac_mask |= tx_ring->ims_val;
1747 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1748
1749 /* set vector for Other Causes, e.g. link changes */
1750 vector++;
1751 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1752 if (rx_ring->itr_val)
1753 writel(1000000000 / (rx_ring->itr_val * 256),
1754 hw->hw_addr + E1000_EITR_82574(vector));
1755 else
1756 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1757
1758 /* Cause Tx interrupts on every write back */
1759 ivar |= (1 << 31);
1760
1761 ew32(IVAR, ivar);
1762
1763 /* enable MSI-X PBA support */
1764 ctrl_ext = er32(CTRL_EXT);
1765 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1766
1767 /* Auto-Mask Other interrupts upon ICR read */
1768#define E1000_EIAC_MASK_82574 0x01F00000
1769 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1770 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1771 ew32(CTRL_EXT, ctrl_ext);
1772 e1e_flush();
1773}
1774
1775void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1776{
1777 if (adapter->msix_entries) {
1778 pci_disable_msix(adapter->pdev);
1779 kfree(adapter->msix_entries);
1780 adapter->msix_entries = NULL;
1781 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1782 pci_disable_msi(adapter->pdev);
1783 adapter->flags &= ~FLAG_MSI_ENABLED;
1784 }
Bruce Allan4662e822008-08-26 18:37:06 -07001785}
1786
1787/**
1788 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1789 *
1790 * Attempt to configure interrupts using the best available
1791 * capabilities of the hardware and kernel.
1792 **/
1793void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1794{
1795 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001796 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001797
1798 switch (adapter->int_mode) {
1799 case E1000E_INT_MODE_MSIX:
1800 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001801 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1802 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001803 sizeof(struct msix_entry),
1804 GFP_KERNEL);
1805 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001806 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001807 adapter->msix_entries[i].entry = i;
1808
1809 err = pci_enable_msix(adapter->pdev,
1810 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001811 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001812 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001813 return;
1814 }
1815 /* MSI-X failed, so fall through and try MSI */
1816 e_err("Failed to initialize MSI-X interrupts. "
1817 "Falling back to MSI interrupts.\n");
1818 e1000e_reset_interrupt_capability(adapter);
1819 }
1820 adapter->int_mode = E1000E_INT_MODE_MSI;
1821 /* Fall through */
1822 case E1000E_INT_MODE_MSI:
1823 if (!pci_enable_msi(adapter->pdev)) {
1824 adapter->flags |= FLAG_MSI_ENABLED;
1825 } else {
1826 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1827 e_err("Failed to initialize MSI interrupts. Falling "
1828 "back to legacy interrupts.\n");
1829 }
1830 /* Fall through */
1831 case E1000E_INT_MODE_LEGACY:
1832 /* Don't do anything; this is the system default */
1833 break;
1834 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001835
1836 /* store the number of vectors being used */
1837 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001838}
1839
1840/**
1841 * e1000_request_msix - Initialize MSI-X interrupts
1842 *
1843 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1844 * kernel.
1845 **/
1846static int e1000_request_msix(struct e1000_adapter *adapter)
1847{
1848 struct net_device *netdev = adapter->netdev;
1849 int err = 0, vector = 0;
1850
1851 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001852 snprintf(adapter->rx_ring->name,
1853 sizeof(adapter->rx_ring->name) - 1,
1854 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001855 else
1856 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1857 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001858 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001859 netdev);
1860 if (err)
1861 goto out;
1862 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1863 adapter->rx_ring->itr_val = adapter->itr;
1864 vector++;
1865
1866 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001867 snprintf(adapter->tx_ring->name,
1868 sizeof(adapter->tx_ring->name) - 1,
1869 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001870 else
1871 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1872 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001873 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001874 netdev);
1875 if (err)
1876 goto out;
1877 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1878 adapter->tx_ring->itr_val = adapter->itr;
1879 vector++;
1880
1881 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001882 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001883 if (err)
1884 goto out;
1885
1886 e1000_configure_msix(adapter);
1887 return 0;
1888out:
1889 return err;
1890}
1891
Bruce Allanf8d59f72008-08-08 18:36:11 -07001892/**
1893 * e1000_request_irq - initialize interrupts
1894 *
1895 * Attempts to configure interrupts using the best available
1896 * capabilities of the hardware and kernel.
1897 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001898static int e1000_request_irq(struct e1000_adapter *adapter)
1899{
1900 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001901 int err;
1902
Bruce Allan4662e822008-08-26 18:37:06 -07001903 if (adapter->msix_entries) {
1904 err = e1000_request_msix(adapter);
1905 if (!err)
1906 return err;
1907 /* fall back to MSI */
1908 e1000e_reset_interrupt_capability(adapter);
1909 adapter->int_mode = E1000E_INT_MODE_MSI;
1910 e1000e_set_interrupt_capability(adapter);
1911 }
1912 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001913 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001914 netdev->name, netdev);
1915 if (!err)
1916 return err;
1917
1918 /* fall back to legacy interrupt */
1919 e1000e_reset_interrupt_capability(adapter);
1920 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001921 }
1922
Joe Perchesa0607fd2009-11-18 23:29:17 -08001923 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001924 netdev->name, netdev);
1925 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001926 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001927
1928 return err;
1929}
1930
1931static void e1000_free_irq(struct e1000_adapter *adapter)
1932{
1933 struct net_device *netdev = adapter->netdev;
1934
Bruce Allan4662e822008-08-26 18:37:06 -07001935 if (adapter->msix_entries) {
1936 int vector = 0;
1937
1938 free_irq(adapter->msix_entries[vector].vector, netdev);
1939 vector++;
1940
1941 free_irq(adapter->msix_entries[vector].vector, netdev);
1942 vector++;
1943
1944 /* Other Causes interrupt vector */
1945 free_irq(adapter->msix_entries[vector].vector, netdev);
1946 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001947 }
Bruce Allan4662e822008-08-26 18:37:06 -07001948
1949 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001950}
1951
1952/**
1953 * e1000_irq_disable - Mask off interrupt generation on the NIC
1954 **/
1955static void e1000_irq_disable(struct e1000_adapter *adapter)
1956{
1957 struct e1000_hw *hw = &adapter->hw;
1958
Auke Kokbc7f75f2007-09-17 12:30:59 -07001959 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001960 if (adapter->msix_entries)
1961 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001962 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001963
1964 if (adapter->msix_entries) {
1965 int i;
1966 for (i = 0; i < adapter->num_vectors; i++)
1967 synchronize_irq(adapter->msix_entries[i].vector);
1968 } else {
1969 synchronize_irq(adapter->pdev->irq);
1970 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001971}
1972
1973/**
1974 * e1000_irq_enable - Enable default interrupt generation settings
1975 **/
1976static void e1000_irq_enable(struct e1000_adapter *adapter)
1977{
1978 struct e1000_hw *hw = &adapter->hw;
1979
Bruce Allan4662e822008-08-26 18:37:06 -07001980 if (adapter->msix_entries) {
1981 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1982 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1983 } else {
1984 ew32(IMS, IMS_ENABLE_MASK);
1985 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001986 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001987}
1988
1989/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001990 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07001991 * @adapter: address of board private structure
1992 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001993 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001994 * For ASF and Pass Through versions of f/w this means that
1995 * the driver is loaded. For AMT version (only with 82573)
1996 * of the f/w this means that the network i/f is open.
1997 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001998void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001999{
2000 struct e1000_hw *hw = &adapter->hw;
2001 u32 ctrl_ext;
2002 u32 swsm;
2003
2004 /* Let firmware know the driver has taken over */
2005 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2006 swsm = er32(SWSM);
2007 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2008 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2009 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002010 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002011 }
2012}
2013
2014/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002015 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002016 * @adapter: address of board private structure
2017 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002018 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002019 * For ASF and Pass Through versions of f/w this means that the
2020 * driver is no longer loaded. For AMT version (only with 82573) i
2021 * of the f/w this means that the network i/f is closed.
2022 *
2023 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002024void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002025{
2026 struct e1000_hw *hw = &adapter->hw;
2027 u32 ctrl_ext;
2028 u32 swsm;
2029
2030 /* Let firmware taken over control of h/w */
2031 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2032 swsm = er32(SWSM);
2033 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2034 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2035 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002036 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002037 }
2038}
2039
Auke Kokbc7f75f2007-09-17 12:30:59 -07002040/**
2041 * @e1000_alloc_ring - allocate memory for a ring structure
2042 **/
2043static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2044 struct e1000_ring *ring)
2045{
2046 struct pci_dev *pdev = adapter->pdev;
2047
2048 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2049 GFP_KERNEL);
2050 if (!ring->desc)
2051 return -ENOMEM;
2052
2053 return 0;
2054}
2055
2056/**
2057 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2058 * @adapter: board private structure
2059 *
2060 * Return 0 on success, negative on failure
2061 **/
2062int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2063{
2064 struct e1000_ring *tx_ring = adapter->tx_ring;
2065 int err = -ENOMEM, size;
2066
2067 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002068 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002069 if (!tx_ring->buffer_info)
2070 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002071
2072 /* round up to nearest 4K */
2073 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2074 tx_ring->size = ALIGN(tx_ring->size, 4096);
2075
2076 err = e1000_alloc_ring_dma(adapter, tx_ring);
2077 if (err)
2078 goto err;
2079
2080 tx_ring->next_to_use = 0;
2081 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002082
2083 return 0;
2084err:
2085 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002086 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002087 return err;
2088}
2089
2090/**
2091 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2092 * @adapter: board private structure
2093 *
2094 * Returns 0 on success, negative on failure
2095 **/
2096int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2097{
2098 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002099 struct e1000_buffer *buffer_info;
2100 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002101
2102 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002103 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002104 if (!rx_ring->buffer_info)
2105 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002106
Auke Kok47f44e42007-10-25 13:57:44 -07002107 for (i = 0; i < rx_ring->count; i++) {
2108 buffer_info = &rx_ring->buffer_info[i];
2109 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2110 sizeof(struct e1000_ps_page),
2111 GFP_KERNEL);
2112 if (!buffer_info->ps_pages)
2113 goto err_pages;
2114 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002115
2116 desc_len = sizeof(union e1000_rx_desc_packet_split);
2117
2118 /* Round up to nearest 4K */
2119 rx_ring->size = rx_ring->count * desc_len;
2120 rx_ring->size = ALIGN(rx_ring->size, 4096);
2121
2122 err = e1000_alloc_ring_dma(adapter, rx_ring);
2123 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002124 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002125
2126 rx_ring->next_to_clean = 0;
2127 rx_ring->next_to_use = 0;
2128 rx_ring->rx_skb_top = NULL;
2129
2130 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002131
2132err_pages:
2133 for (i = 0; i < rx_ring->count; i++) {
2134 buffer_info = &rx_ring->buffer_info[i];
2135 kfree(buffer_info->ps_pages);
2136 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002137err:
2138 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002139 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002140 return err;
2141}
2142
2143/**
2144 * e1000_clean_tx_ring - Free Tx Buffers
2145 * @adapter: board private structure
2146 **/
2147static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2148{
2149 struct e1000_ring *tx_ring = adapter->tx_ring;
2150 struct e1000_buffer *buffer_info;
2151 unsigned long size;
2152 unsigned int i;
2153
2154 for (i = 0; i < tx_ring->count; i++) {
2155 buffer_info = &tx_ring->buffer_info[i];
2156 e1000_put_txbuf(adapter, buffer_info);
2157 }
2158
2159 size = sizeof(struct e1000_buffer) * tx_ring->count;
2160 memset(tx_ring->buffer_info, 0, size);
2161
2162 memset(tx_ring->desc, 0, tx_ring->size);
2163
2164 tx_ring->next_to_use = 0;
2165 tx_ring->next_to_clean = 0;
2166
2167 writel(0, adapter->hw.hw_addr + tx_ring->head);
2168 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2169}
2170
2171/**
2172 * e1000e_free_tx_resources - Free Tx Resources per Queue
2173 * @adapter: board private structure
2174 *
2175 * Free all transmit software resources
2176 **/
2177void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2178{
2179 struct pci_dev *pdev = adapter->pdev;
2180 struct e1000_ring *tx_ring = adapter->tx_ring;
2181
2182 e1000_clean_tx_ring(adapter);
2183
2184 vfree(tx_ring->buffer_info);
2185 tx_ring->buffer_info = NULL;
2186
2187 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2188 tx_ring->dma);
2189 tx_ring->desc = NULL;
2190}
2191
2192/**
2193 * e1000e_free_rx_resources - Free Rx Resources
2194 * @adapter: board private structure
2195 *
2196 * Free all receive software resources
2197 **/
2198
2199void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2200{
2201 struct pci_dev *pdev = adapter->pdev;
2202 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002203 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002204
2205 e1000_clean_rx_ring(adapter);
2206
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002207 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002208 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002209
Auke Kokbc7f75f2007-09-17 12:30:59 -07002210 vfree(rx_ring->buffer_info);
2211 rx_ring->buffer_info = NULL;
2212
Auke Kokbc7f75f2007-09-17 12:30:59 -07002213 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2214 rx_ring->dma);
2215 rx_ring->desc = NULL;
2216}
2217
2218/**
2219 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002220 * @adapter: pointer to adapter
2221 * @itr_setting: current adapter->itr
2222 * @packets: the number of packets during this measurement interval
2223 * @bytes: the number of bytes during this measurement interval
2224 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002225 * Stores a new ITR value based on packets and byte
2226 * counts during the last interrupt. The advantage of per interrupt
2227 * computation is faster updates and more accurate ITR for the current
2228 * traffic pattern. Constants in this function were computed
2229 * based on theoretical maximum wire speed and thresholds were set based
2230 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002231 * while increasing bulk throughput. This functionality is controlled
2232 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002233 **/
2234static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2235 u16 itr_setting, int packets,
2236 int bytes)
2237{
2238 unsigned int retval = itr_setting;
2239
2240 if (packets == 0)
2241 goto update_itr_done;
2242
2243 switch (itr_setting) {
2244 case lowest_latency:
2245 /* handle TSO and jumbo frames */
2246 if (bytes/packets > 8000)
2247 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002248 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002249 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002250 break;
2251 case low_latency: /* 50 usec aka 20000 ints/s */
2252 if (bytes > 10000) {
2253 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002254 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002255 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002256 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002257 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002258 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002260 } else if (bytes/packets > 2000) {
2261 retval = bulk_latency;
2262 } else if (packets <= 2 && bytes < 512) {
2263 retval = lowest_latency;
2264 }
2265 break;
2266 case bulk_latency: /* 250 usec aka 4000 ints/s */
2267 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002268 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002269 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002270 } else if (bytes < 6000) {
2271 retval = low_latency;
2272 }
2273 break;
2274 }
2275
2276update_itr_done:
2277 return retval;
2278}
2279
2280static void e1000_set_itr(struct e1000_adapter *adapter)
2281{
2282 struct e1000_hw *hw = &adapter->hw;
2283 u16 current_itr;
2284 u32 new_itr = adapter->itr;
2285
2286 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2287 if (adapter->link_speed != SPEED_1000) {
2288 current_itr = 0;
2289 new_itr = 4000;
2290 goto set_itr_now;
2291 }
2292
Bruce Allan828bac82010-09-29 21:39:37 +00002293 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2294 new_itr = 0;
2295 goto set_itr_now;
2296 }
2297
Auke Kokbc7f75f2007-09-17 12:30:59 -07002298 adapter->tx_itr = e1000_update_itr(adapter,
2299 adapter->tx_itr,
2300 adapter->total_tx_packets,
2301 adapter->total_tx_bytes);
2302 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2303 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2304 adapter->tx_itr = low_latency;
2305
2306 adapter->rx_itr = e1000_update_itr(adapter,
2307 adapter->rx_itr,
2308 adapter->total_rx_packets,
2309 adapter->total_rx_bytes);
2310 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2311 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2312 adapter->rx_itr = low_latency;
2313
2314 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2315
2316 switch (current_itr) {
2317 /* counts and packets in update_itr are dependent on these numbers */
2318 case lowest_latency:
2319 new_itr = 70000;
2320 break;
2321 case low_latency:
2322 new_itr = 20000; /* aka hwitr = ~200 */
2323 break;
2324 case bulk_latency:
2325 new_itr = 4000;
2326 break;
2327 default:
2328 break;
2329 }
2330
2331set_itr_now:
2332 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002333 /*
2334 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002335 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002336 * increasing
2337 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002338 new_itr = new_itr > adapter->itr ?
2339 min(adapter->itr + (new_itr >> 2), new_itr) :
2340 new_itr;
2341 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002342 adapter->rx_ring->itr_val = new_itr;
2343 if (adapter->msix_entries)
2344 adapter->rx_ring->set_itr = 1;
2345 else
Bruce Allan828bac82010-09-29 21:39:37 +00002346 if (new_itr)
2347 ew32(ITR, 1000000000 / (new_itr * 256));
2348 else
2349 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002350 }
2351}
2352
2353/**
Bruce Allan4662e822008-08-26 18:37:06 -07002354 * e1000_alloc_queues - Allocate memory for all rings
2355 * @adapter: board private structure to initialize
2356 **/
2357static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2358{
2359 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2360 if (!adapter->tx_ring)
2361 goto err;
2362
2363 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2364 if (!adapter->rx_ring)
2365 goto err;
2366
2367 return 0;
2368err:
2369 e_err("Unable to allocate memory for queues\n");
2370 kfree(adapter->rx_ring);
2371 kfree(adapter->tx_ring);
2372 return -ENOMEM;
2373}
2374
2375/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002376 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002377 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002378 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002379 **/
2380static int e1000_clean(struct napi_struct *napi, int budget)
2381{
2382 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002383 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002385 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002386
Wang Chen4cf16532008-11-12 23:38:14 -08002387 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002388
Bruce Allan4662e822008-08-26 18:37:06 -07002389 if (adapter->msix_entries &&
2390 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2391 goto clean_rx;
2392
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002393 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002394
Bruce Allan4662e822008-08-26 18:37:06 -07002395clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002396 adapter->clean_rx(adapter, &work_done, budget);
2397
Alexander Duyck12d04a32009-03-25 22:05:03 +00002398 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002399 work_done = budget;
2400
David S. Miller53e52c72008-01-07 21:06:12 -08002401 /* If budget not fully consumed, exit the polling mode */
2402 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002403 if (adapter->itr_setting & 3)
2404 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002405 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002406 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2407 if (adapter->msix_entries)
2408 ew32(IMS, adapter->rx_ring->ims_val);
2409 else
2410 e1000_irq_enable(adapter);
2411 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002412 }
2413
2414 return work_done;
2415}
2416
2417static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2418{
2419 struct e1000_adapter *adapter = netdev_priv(netdev);
2420 struct e1000_hw *hw = &adapter->hw;
2421 u32 vfta, index;
2422
2423 /* don't update vlan cookie if already programmed */
2424 if ((adapter->hw.mng_cookie.status &
2425 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2426 (vid == adapter->mng_vlan_id))
2427 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002428
Auke Kokbc7f75f2007-09-17 12:30:59 -07002429 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002430 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2431 index = (vid >> 5) & 0x7F;
2432 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2433 vfta |= (1 << (vid & 0x1F));
2434 hw->mac.ops.write_vfta(hw, index, vfta);
2435 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002436
2437 set_bit(vid, adapter->active_vlans);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002438}
2439
2440static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2441{
2442 struct e1000_adapter *adapter = netdev_priv(netdev);
2443 struct e1000_hw *hw = &adapter->hw;
2444 u32 vfta, index;
2445
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446 if ((adapter->hw.mng_cookie.status &
2447 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2448 (vid == adapter->mng_vlan_id)) {
2449 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002450 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002451 return;
2452 }
2453
2454 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002455 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2456 index = (vid >> 5) & 0x7F;
2457 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2458 vfta &= ~(1 << (vid & 0x1F));
2459 hw->mac.ops.write_vfta(hw, index, vfta);
2460 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002461
2462 clear_bit(vid, adapter->active_vlans);
2463}
2464
2465/**
2466 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2467 * @adapter: board private structure to initialize
2468 **/
2469static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2470{
2471 struct net_device *netdev = adapter->netdev;
2472 struct e1000_hw *hw = &adapter->hw;
2473 u32 rctl;
2474
2475 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2476 /* disable VLAN receive filtering */
2477 rctl = er32(RCTL);
2478 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2479 ew32(RCTL, rctl);
2480
2481 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2482 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2483 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2484 }
2485 }
2486}
2487
2488/**
2489 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2490 * @adapter: board private structure to initialize
2491 **/
2492static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2493{
2494 struct e1000_hw *hw = &adapter->hw;
2495 u32 rctl;
2496
2497 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2498 /* enable VLAN receive filtering */
2499 rctl = er32(RCTL);
2500 rctl |= E1000_RCTL_VFE;
2501 rctl &= ~E1000_RCTL_CFIEN;
2502 ew32(RCTL, rctl);
2503 }
2504}
2505
2506/**
2507 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2508 * @adapter: board private structure to initialize
2509 **/
2510static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2511{
2512 struct e1000_hw *hw = &adapter->hw;
2513 u32 ctrl;
2514
2515 /* disable VLAN tag insert/strip */
2516 ctrl = er32(CTRL);
2517 ctrl &= ~E1000_CTRL_VME;
2518 ew32(CTRL, ctrl);
2519}
2520
2521/**
2522 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2523 * @adapter: board private structure to initialize
2524 **/
2525static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2526{
2527 struct e1000_hw *hw = &adapter->hw;
2528 u32 ctrl;
2529
2530 /* enable VLAN tag insert/strip */
2531 ctrl = er32(CTRL);
2532 ctrl |= E1000_CTRL_VME;
2533 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002534}
2535
2536static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2537{
2538 struct net_device *netdev = adapter->netdev;
2539 u16 vid = adapter->hw.mng_cookie.vlan_id;
2540 u16 old_vid = adapter->mng_vlan_id;
2541
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002542 if (adapter->hw.mng_cookie.status &
2543 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2544 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002545 adapter->mng_vlan_id = vid;
2546 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002547
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002548 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2549 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002550}
2551
2552static void e1000_restore_vlan(struct e1000_adapter *adapter)
2553{
2554 u16 vid;
2555
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002556 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002557
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002558 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002559 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560}
2561
Bruce Allancd791612010-05-10 14:59:51 +00002562static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563{
2564 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002565 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566
2567 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2568 return;
2569
2570 manc = er32(MANC);
2571
Bruce Allanad680762008-03-28 09:15:03 -07002572 /*
2573 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002574 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002575 * the packets will be handled on SMBUS
2576 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577 manc |= E1000_MANC_EN_MNG2HOST;
2578 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002579
2580 switch (hw->mac.type) {
2581 default:
2582 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2583 break;
2584 case e1000_82574:
2585 case e1000_82583:
2586 /*
2587 * Check if IPMI pass-through decision filter already exists;
2588 * if so, enable it.
2589 */
2590 for (i = 0, j = 0; i < 8; i++) {
2591 mdef = er32(MDEF(i));
2592
2593 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002594 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002595 continue;
2596
2597 /* Enable this decision filter in MANC2H */
2598 if (mdef)
2599 manc2h |= (1 << i);
2600
2601 j |= mdef;
2602 }
2603
2604 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2605 break;
2606
2607 /* Create new decision filter in an empty filter */
2608 for (i = 0, j = 0; i < 8; i++)
2609 if (er32(MDEF(i)) == 0) {
2610 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2611 E1000_MDEF_PORT_664));
2612 manc2h |= (1 << 1);
2613 j++;
2614 break;
2615 }
2616
2617 if (!j)
2618 e_warn("Unable to create IPMI pass-through filter\n");
2619 break;
2620 }
2621
Auke Kokbc7f75f2007-09-17 12:30:59 -07002622 ew32(MANC2H, manc2h);
2623 ew32(MANC, manc);
2624}
2625
2626/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002627 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002628 * @adapter: board private structure
2629 *
2630 * Configure the Tx unit of the MAC after a reset.
2631 **/
2632static void e1000_configure_tx(struct e1000_adapter *adapter)
2633{
2634 struct e1000_hw *hw = &adapter->hw;
2635 struct e1000_ring *tx_ring = adapter->tx_ring;
2636 u64 tdba;
2637 u32 tdlen, tctl, tipg, tarc;
2638 u32 ipgr1, ipgr2;
2639
2640 /* Setup the HW Tx Head and Tail descriptor pointers */
2641 tdba = tx_ring->dma;
2642 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002643 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002644 ew32(TDBAH, (tdba >> 32));
2645 ew32(TDLEN, tdlen);
2646 ew32(TDH, 0);
2647 ew32(TDT, 0);
2648 tx_ring->head = E1000_TDH;
2649 tx_ring->tail = E1000_TDT;
2650
2651 /* Set the default values for the Tx Inter Packet Gap timer */
2652 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2653 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2654 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2655
2656 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2657 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2658
2659 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2660 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2661 ew32(TIPG, tipg);
2662
2663 /* Set the Tx Interrupt Delay register */
2664 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002665 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002666 ew32(TADV, adapter->tx_abs_int_delay);
2667
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002668 if (adapter->flags2 & FLAG2_DMA_BURST) {
2669 u32 txdctl = er32(TXDCTL(0));
2670 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2671 E1000_TXDCTL_WTHRESH);
2672 /*
2673 * set up some performance related parameters to encourage the
2674 * hardware to use the bus more efficiently in bursts, depends
2675 * on the tx_int_delay to be enabled,
2676 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2677 * hthresh = 1 ==> prefetch when one or more available
2678 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2679 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002680 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002681 */
2682 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2683 ew32(TXDCTL(0), txdctl);
2684 /* erratum work around: set txdctl the same for both queues */
2685 ew32(TXDCTL(1), txdctl);
2686 }
2687
Auke Kokbc7f75f2007-09-17 12:30:59 -07002688 /* Program the Transmit Control Register */
2689 tctl = er32(TCTL);
2690 tctl &= ~E1000_TCTL_CT;
2691 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2692 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2693
2694 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002695 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002696 /*
2697 * set the speed mode bit, we'll clear it if we're not at
2698 * gigabit link later
2699 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002700#define SPEED_MODE_BIT (1 << 21)
2701 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002702 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002703 }
2704
2705 /* errata: program both queues to unweighted RR */
2706 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002707 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002708 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002709 ew32(TARC(0), tarc);
2710 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002712 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002713 }
2714
Auke Kokbc7f75f2007-09-17 12:30:59 -07002715 /* Setup Transmit Descriptor Settings for eop descriptor */
2716 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2717
2718 /* only set IDE if we are delaying interrupts using the timers */
2719 if (adapter->tx_int_delay)
2720 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2721
2722 /* enable Report Status bit */
2723 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2724
2725 ew32(TCTL, tctl);
2726
Simon Hormanedfea6e62009-06-08 14:28:36 +00002727 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002728}
2729
2730/**
2731 * e1000_setup_rctl - configure the receive control registers
2732 * @adapter: Board private structure
2733 **/
2734#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2735 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2736static void e1000_setup_rctl(struct e1000_adapter *adapter)
2737{
2738 struct e1000_hw *hw = &adapter->hw;
2739 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002740 u32 pages = 0;
2741
Bruce Allana1ce6472010-09-22 17:16:40 +00002742 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2743 if (hw->mac.type == e1000_pch2lan) {
2744 s32 ret_val;
2745
2746 if (adapter->netdev->mtu > ETH_DATA_LEN)
2747 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2748 else
2749 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002750
2751 if (ret_val)
2752 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002753 }
2754
Auke Kokbc7f75f2007-09-17 12:30:59 -07002755 /* Program MC offset vector base */
2756 rctl = er32(RCTL);
2757 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2758 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2759 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2760 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2761
2762 /* Do not Store bad packets */
2763 rctl &= ~E1000_RCTL_SBP;
2764
2765 /* Enable Long Packet receive */
2766 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2767 rctl &= ~E1000_RCTL_LPE;
2768 else
2769 rctl |= E1000_RCTL_LPE;
2770
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002771 /* Some systems expect that the CRC is included in SMBUS traffic. The
2772 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2773 * host memory when this is enabled
2774 */
2775 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2776 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002777
Bruce Allana4f58f52009-06-02 11:29:18 +00002778 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2779 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2780 u16 phy_data;
2781
2782 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2783 phy_data &= 0xfff8;
2784 phy_data |= (1 << 2);
2785 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2786
2787 e1e_rphy(hw, 22, &phy_data);
2788 phy_data &= 0x0fff;
2789 phy_data |= (1 << 14);
2790 e1e_wphy(hw, 0x10, 0x2823);
2791 e1e_wphy(hw, 0x11, 0x0003);
2792 e1e_wphy(hw, 22, phy_data);
2793 }
2794
Auke Kokbc7f75f2007-09-17 12:30:59 -07002795 /* Setup buffer sizes */
2796 rctl &= ~E1000_RCTL_SZ_4096;
2797 rctl |= E1000_RCTL_BSEX;
2798 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002799 case 2048:
2800 default:
2801 rctl |= E1000_RCTL_SZ_2048;
2802 rctl &= ~E1000_RCTL_BSEX;
2803 break;
2804 case 4096:
2805 rctl |= E1000_RCTL_SZ_4096;
2806 break;
2807 case 8192:
2808 rctl |= E1000_RCTL_SZ_8192;
2809 break;
2810 case 16384:
2811 rctl |= E1000_RCTL_SZ_16384;
2812 break;
2813 }
2814
2815 /*
2816 * 82571 and greater support packet-split where the protocol
2817 * header is placed in skb->data and the packet data is
2818 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2819 * In the case of a non-split, skb->data is linearly filled,
2820 * followed by the page buffers. Therefore, skb->data is
2821 * sized to hold the largest protocol header.
2822 *
2823 * allocations using alloc_page take too long for regular MTU
2824 * so only enable packet split for jumbo frames
2825 *
2826 * Using pages when the page size is greater than 16k wastes
2827 * a lot of memory, since we allocate 3 pages at all times
2828 * per packet.
2829 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002830 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fec2010-06-17 18:59:27 +00002831 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002832 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002834 else
2835 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002836
2837 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002838 u32 psrctl = 0;
2839
Auke Kokbc7f75f2007-09-17 12:30:59 -07002840 /* Configure extra packet-split registers */
2841 rfctl = er32(RFCTL);
2842 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002843 /*
2844 * disable packet split support for IPv6 extension headers,
2845 * because some malformed IPv6 headers can hang the Rx
2846 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002847 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2848 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2849
2850 ew32(RFCTL, rfctl);
2851
Auke Kok140a7482007-10-25 13:57:58 -07002852 /* Enable Packet split descriptors */
2853 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002854
2855 psrctl |= adapter->rx_ps_bsize0 >>
2856 E1000_PSRCTL_BSIZE0_SHIFT;
2857
2858 switch (adapter->rx_ps_pages) {
2859 case 3:
2860 psrctl |= PAGE_SIZE <<
2861 E1000_PSRCTL_BSIZE3_SHIFT;
2862 case 2:
2863 psrctl |= PAGE_SIZE <<
2864 E1000_PSRCTL_BSIZE2_SHIFT;
2865 case 1:
2866 psrctl |= PAGE_SIZE >>
2867 E1000_PSRCTL_BSIZE1_SHIFT;
2868 break;
2869 }
2870
2871 ew32(PSRCTL, psrctl);
2872 }
2873
2874 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002875 /* just started the receive unit, no need to restart */
2876 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002877}
2878
2879/**
2880 * e1000_configure_rx - Configure Receive Unit after Reset
2881 * @adapter: board private structure
2882 *
2883 * Configure the Rx unit of the MAC after a reset.
2884 **/
2885static void e1000_configure_rx(struct e1000_adapter *adapter)
2886{
2887 struct e1000_hw *hw = &adapter->hw;
2888 struct e1000_ring *rx_ring = adapter->rx_ring;
2889 u64 rdba;
2890 u32 rdlen, rctl, rxcsum, ctrl_ext;
2891
2892 if (adapter->rx_ps_pages) {
2893 /* this is a 32 byte descriptor */
2894 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002895 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002896 adapter->clean_rx = e1000_clean_rx_irq_ps;
2897 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002898 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2899 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2900 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2901 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002902 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002903 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002904 adapter->clean_rx = e1000_clean_rx_irq;
2905 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2906 }
2907
2908 /* disable receives while setting up the descriptors */
2909 rctl = er32(RCTL);
2910 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2911 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00002912 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002913
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002914 if (adapter->flags2 & FLAG2_DMA_BURST) {
2915 /*
2916 * set the writeback threshold (only takes effect if the RDTR
2917 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00002918 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002919 * granularity = 01
2920 * wthresh = 04,
2921 * hthresh = 04,
2922 * pthresh = 0x20
2923 */
2924 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
2925 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
2926
2927 /*
2928 * override the delay timers for enabling bursting, only if
2929 * the value was not set by the user via module options
2930 */
2931 if (adapter->rx_int_delay == DEFAULT_RDTR)
2932 adapter->rx_int_delay = BURST_RDTR;
2933 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
2934 adapter->rx_abs_int_delay = BURST_RADV;
2935 }
2936
Auke Kokbc7f75f2007-09-17 12:30:59 -07002937 /* set the Receive Delay Timer Register */
2938 ew32(RDTR, adapter->rx_int_delay);
2939
2940 /* irq moderation */
2941 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00002942 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07002943 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002944
2945 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946 /* Auto-Mask interrupts upon ICR access */
2947 ctrl_ext |= E1000_CTRL_EXT_IAME;
2948 ew32(IAM, 0xffffffff);
2949 ew32(CTRL_EXT, ctrl_ext);
2950 e1e_flush();
2951
Bruce Allanad680762008-03-28 09:15:03 -07002952 /*
2953 * Setup the HW Rx Head and Tail Descriptor Pointers and
2954 * the Base and Length of the Rx Descriptor Ring
2955 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002956 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002957 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958 ew32(RDBAH, (rdba >> 32));
2959 ew32(RDLEN, rdlen);
2960 ew32(RDH, 0);
2961 ew32(RDT, 0);
2962 rx_ring->head = E1000_RDH;
2963 rx_ring->tail = E1000_RDT;
2964
2965 /* Enable Receive Checksum Offload for TCP and UDP */
2966 rxcsum = er32(RXCSUM);
2967 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2968 rxcsum |= E1000_RXCSUM_TUOFL;
2969
Bruce Allanad680762008-03-28 09:15:03 -07002970 /*
2971 * IPv4 payload checksum for UDP fragments must be
2972 * used in conjunction with packet-split.
2973 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002974 if (adapter->rx_ps_pages)
2975 rxcsum |= E1000_RXCSUM_IPPCSE;
2976 } else {
2977 rxcsum &= ~E1000_RXCSUM_TUOFL;
2978 /* no need to clear IPPCSE as it defaults to 0 */
2979 }
2980 ew32(RXCSUM, rxcsum);
2981
Bruce Allanad680762008-03-28 09:15:03 -07002982 /*
2983 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002984 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002985 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2986 */
Bruce Allan828bac82010-09-29 21:39:37 +00002987 if ((adapter->flags & FLAG_HAS_ERT) ||
2988 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00002989 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2990 u32 rxdctl = er32(RXDCTL(0));
2991 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00002992 if (adapter->flags & FLAG_HAS_ERT)
2993 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00002994 /*
2995 * With jumbo frames and early-receive enabled,
2996 * excessive C-state transition latencies result in
2997 * dropped transactions.
2998 */
Bruce Allanaf667a22010-12-31 06:10:01 +00002999 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003000 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003001 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3002 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003003 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003004 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003005
3006 /* Enable Receives */
3007 ew32(RCTL, rctl);
3008}
3009
3010/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003011 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07003012 * @hw: pointer to the HW structure
3013 * @mc_addr_list: array of multicast addresses to program
3014 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07003015 *
Bruce Allanab8932f2010-01-13 02:05:38 +00003016 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003017 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003018 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003019static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003020 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003021{
Bruce Allanab8932f2010-01-13 02:05:38 +00003022 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003023}
3024
3025/**
3026 * e1000_set_multi - Multicast and Promiscuous mode set
3027 * @netdev: network interface device structure
3028 *
3029 * The set_multi entry point is called whenever the multicast address
3030 * list or the network interface flags are updated. This routine is
3031 * responsible for configuring the hardware for proper multicast,
3032 * promiscuous mode, and all-multi behavior.
3033 **/
3034static void e1000_set_multi(struct net_device *netdev)
3035{
3036 struct e1000_adapter *adapter = netdev_priv(netdev);
3037 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003038 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003039 u8 *mta_list;
3040 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003041
3042 /* Check for Promiscuous and All Multicast modes */
3043
3044 rctl = er32(RCTL);
3045
3046 if (netdev->flags & IFF_PROMISC) {
3047 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003048 rctl &= ~E1000_RCTL_VFE;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003049 /* Do not hardware filter VLANs in promisc mode */
3050 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003051 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003052 if (netdev->flags & IFF_ALLMULTI) {
3053 rctl |= E1000_RCTL_MPE;
3054 rctl &= ~E1000_RCTL_UPE;
3055 } else {
3056 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3057 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003058 e1000e_vlan_filter_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003059 }
3060
3061 ew32(RCTL, rctl);
3062
Jiri Pirko7aeef972010-02-05 02:52:39 +00003063 if (!netdev_mc_empty(netdev)) {
Bruce Allan90da0662011-01-06 07:02:53 +00003064 int i = 0;
3065
Jiri Pirko7aeef972010-02-05 02:52:39 +00003066 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003067 if (!mta_list)
3068 return;
3069
3070 /* prepare a packed array of only addresses. */
Jiri Pirko22bedad32010-04-01 21:22:57 +00003071 netdev_for_each_mc_addr(ha, netdev)
3072 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003073
Bruce Allanab8932f2010-01-13 02:05:38 +00003074 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003075 kfree(mta_list);
3076 } else {
3077 /*
3078 * if we're called from probe, we might not have
3079 * anything to do here, so clear out the list
3080 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003081 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003082 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003083
3084 if (netdev->features & NETIF_F_HW_VLAN_RX)
3085 e1000e_vlan_strip_enable(adapter);
3086 else
3087 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003088}
3089
3090/**
Bruce Allanad680762008-03-28 09:15:03 -07003091 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003092 * @adapter: private board structure
3093 **/
3094static void e1000_configure(struct e1000_adapter *adapter)
3095{
3096 e1000_set_multi(adapter->netdev);
3097
3098 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003099 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003100
3101 e1000_configure_tx(adapter);
3102 e1000_setup_rctl(adapter);
3103 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003104 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003105}
3106
3107/**
3108 * e1000e_power_up_phy - restore link in case the phy was powered down
3109 * @adapter: address of board private structure
3110 *
3111 * The phy may be powered down to save power and turn off link when the
3112 * driver is unloaded and wake on lan is not enabled (among others)
3113 * *** this routine MUST be followed by a call to e1000e_reset ***
3114 **/
3115void e1000e_power_up_phy(struct e1000_adapter *adapter)
3116{
Bruce Allan17f208d2009-12-01 15:47:22 +00003117 if (adapter->hw.phy.ops.power_up)
3118 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003119
3120 adapter->hw.mac.ops.setup_link(&adapter->hw);
3121}
3122
3123/**
3124 * e1000_power_down_phy - Power down the PHY
3125 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003126 * Power down the PHY so no link is implied when interface is down.
3127 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128 */
3129static void e1000_power_down_phy(struct e1000_adapter *adapter)
3130{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003131 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003132 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003133 return;
3134
Bruce Allan17f208d2009-12-01 15:47:22 +00003135 if (adapter->hw.phy.ops.power_down)
3136 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003137}
3138
3139/**
3140 * e1000e_reset - bring the hardware into a known good state
3141 *
3142 * This function boots the hardware and enables some settings that
3143 * require a configuration cycle of the hardware - those cannot be
3144 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003145 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146 */
3147void e1000e_reset(struct e1000_adapter *adapter)
3148{
3149 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003150 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003151 struct e1000_hw *hw = &adapter->hw;
3152 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003153 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003154 u16 hwm;
3155
Bruce Allanad680762008-03-28 09:15:03 -07003156 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003157 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003158
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003159 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003160 /*
3161 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003162 * large enough to accommodate two full transmit packets,
3163 * rounded up to the next 1KB and expressed in KB. Likewise,
3164 * the Rx FIFO should be large enough to accommodate at least
3165 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003166 * expressed in KB.
3167 */
Auke Kokdf762462007-10-25 13:57:53 -07003168 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003169 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003170 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003171 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003172 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003173 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003174 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003175 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003176 */
3177 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003178 sizeof(struct e1000_tx_desc) -
3179 ETH_FCS_LEN) * 2;
3180 min_tx_space = ALIGN(min_tx_space, 1024);
3181 min_tx_space >>= 10;
3182 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003183 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003184 min_rx_space = ALIGN(min_rx_space, 1024);
3185 min_rx_space >>= 10;
3186
Bruce Allanad680762008-03-28 09:15:03 -07003187 /*
3188 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003189 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003190 * allocation, take space away from current Rx allocation
3191 */
Auke Kokdf762462007-10-25 13:57:53 -07003192 if ((tx_space < min_tx_space) &&
3193 ((min_tx_space - tx_space) < pba)) {
3194 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003195
Bruce Allanad680762008-03-28 09:15:03 -07003196 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003197 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003198 * adjustment or use Early Receive if available
3199 */
Auke Kokdf762462007-10-25 13:57:53 -07003200 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003201 (!(adapter->flags & FLAG_HAS_ERT)))
3202 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003203 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003204 }
Auke Kokdf762462007-10-25 13:57:53 -07003205
3206 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003207 }
3208
Bruce Allanad680762008-03-28 09:15:03 -07003209 /*
3210 * flow control settings
3211 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003212 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003213 * (or the size used for early receive) above it in the Rx FIFO.
3214 * Set it to the lower of:
3215 * - 90% of the Rx FIFO size, and
3216 * - the full Rx FIFO size minus the early receive size (for parts
3217 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003218 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003219 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003220 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3221 fc->pause_time = 0xFFFF;
3222 else
3223 fc->pause_time = E1000_FC_PAUSE_TIME;
3224 fc->send_xon = 1;
3225 fc->current_mode = fc->requested_mode;
3226
3227 switch (hw->mac.type) {
3228 default:
3229 if ((adapter->flags & FLAG_HAS_ERT) &&
3230 (adapter->netdev->mtu > ETH_DATA_LEN))
3231 hwm = min(((pba << 10) * 9 / 10),
3232 ((pba << 10) - (E1000_ERT_2048 << 3)));
3233 else
3234 hwm = min(((pba << 10) * 9 / 10),
3235 ((pba << 10) - adapter->max_frame_size));
3236
3237 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3238 fc->low_water = fc->high_water - 8;
3239 break;
3240 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003241 /*
3242 * Workaround PCH LOM adapter hangs with certain network
3243 * loads. If hangs persist, try disabling Tx flow control.
3244 */
3245 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3246 fc->high_water = 0x3500;
3247 fc->low_water = 0x1500;
3248 } else {
3249 fc->high_water = 0x5000;
3250 fc->low_water = 0x3000;
3251 }
Bruce Allana3055952010-05-10 15:02:12 +00003252 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003253 break;
3254 case e1000_pch2lan:
3255 fc->high_water = 0x05C20;
3256 fc->low_water = 0x05048;
3257 fc->pause_time = 0x0650;
3258 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003259 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3260 pba = 14;
3261 ew32(PBA, pba);
3262 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003263 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003264 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003265
Bruce Allan828bac82010-09-29 21:39:37 +00003266 /*
3267 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3268 * fit in receive buffer and early-receive not supported.
3269 */
3270 if (adapter->itr_setting & 0x3) {
3271 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3272 !(adapter->flags & FLAG_HAS_ERT)) {
3273 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3274 dev_info(&adapter->pdev->dev,
3275 "Interrupt Throttle Rate turned off\n");
3276 adapter->flags2 |= FLAG2_DISABLE_AIM;
3277 ew32(ITR, 0);
3278 }
3279 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3280 dev_info(&adapter->pdev->dev,
3281 "Interrupt Throttle Rate turned on\n");
3282 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3283 adapter->itr = 20000;
3284 ew32(ITR, 1000000000 / (adapter->itr * 256));
3285 }
3286 }
3287
Auke Kokbc7f75f2007-09-17 12:30:59 -07003288 /* Allow time for pending master requests to run */
3289 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003290
3291 /*
3292 * For parts with AMT enabled, let the firmware know
3293 * that the network interface is in control
3294 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003295 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003296 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003297
Auke Kokbc7f75f2007-09-17 12:30:59 -07003298 ew32(WUC, 0);
3299
3300 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003301 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003302
3303 e1000_update_mng_vlan(adapter);
3304
3305 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3306 ew32(VET, ETH_P_8021Q);
3307
3308 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003309
3310 if (!netif_running(adapter->netdev) &&
3311 !test_bit(__E1000_TESTING, &adapter->state)) {
3312 e1000_power_down_phy(adapter);
3313 return;
3314 }
3315
Auke Kokbc7f75f2007-09-17 12:30:59 -07003316 e1000_get_phy_info(hw);
3317
Bruce Allan918d7192009-06-02 11:28:20 +00003318 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3319 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003320 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003321 /*
3322 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003323 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003324 * different we would do if it failed
3325 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003326 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3327 phy_data &= ~IGP02E1000_PM_SPD;
3328 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3329 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003330}
3331
3332int e1000e_up(struct e1000_adapter *adapter)
3333{
3334 struct e1000_hw *hw = &adapter->hw;
3335
3336 /* hardware has been reset, we need to reload some things */
3337 e1000_configure(adapter);
3338
3339 clear_bit(__E1000_DOWN, &adapter->state);
3340
3341 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003342 if (adapter->msix_entries)
3343 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003344 e1000_irq_enable(adapter);
3345
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003346 netif_wake_queue(adapter->netdev);
3347
Auke Kokbc7f75f2007-09-17 12:30:59 -07003348 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003349 if (adapter->msix_entries)
3350 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3351 else
3352 ew32(ICS, E1000_ICS_LSC);
3353
Auke Kokbc7f75f2007-09-17 12:30:59 -07003354 return 0;
3355}
3356
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003357static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3358{
3359 struct e1000_hw *hw = &adapter->hw;
3360
3361 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3362 return;
3363
3364 /* flush pending descriptor writebacks to memory */
3365 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3366 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3367
3368 /* execute the writes immediately */
3369 e1e_flush();
3370}
3371
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003372static void e1000e_update_stats(struct e1000_adapter *adapter);
3373
Auke Kokbc7f75f2007-09-17 12:30:59 -07003374void e1000e_down(struct e1000_adapter *adapter)
3375{
3376 struct net_device *netdev = adapter->netdev;
3377 struct e1000_hw *hw = &adapter->hw;
3378 u32 tctl, rctl;
3379
Bruce Allanad680762008-03-28 09:15:03 -07003380 /*
3381 * signal that we're down so the interrupt handler does not
3382 * reschedule our watchdog timer
3383 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003384 set_bit(__E1000_DOWN, &adapter->state);
3385
3386 /* disable receives in the hardware */
3387 rctl = er32(RCTL);
3388 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3389 /* flush and sleep below */
3390
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003391 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003392
3393 /* disable transmits in the hardware */
3394 tctl = er32(TCTL);
3395 tctl &= ~E1000_TCTL_EN;
3396 ew32(TCTL, tctl);
3397 /* flush both disables and wait for them to finish */
3398 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003399 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003400
3401 napi_disable(&adapter->napi);
3402 e1000_irq_disable(adapter);
3403
3404 del_timer_sync(&adapter->watchdog_timer);
3405 del_timer_sync(&adapter->phy_info_timer);
3406
Auke Kokbc7f75f2007-09-17 12:30:59 -07003407 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003408
3409 spin_lock(&adapter->stats64_lock);
3410 e1000e_update_stats(adapter);
3411 spin_unlock(&adapter->stats64_lock);
3412
Auke Kokbc7f75f2007-09-17 12:30:59 -07003413 adapter->link_speed = 0;
3414 adapter->link_duplex = 0;
3415
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003416 if (!pci_channel_offline(adapter->pdev))
3417 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003418
3419 e1000e_flush_descriptors(adapter);
3420
Auke Kokbc7f75f2007-09-17 12:30:59 -07003421 e1000_clean_tx_ring(adapter);
3422 e1000_clean_rx_ring(adapter);
3423
3424 /*
3425 * TODO: for power management, we could drop the link and
3426 * pci_disable_device here.
3427 */
3428}
3429
3430void e1000e_reinit_locked(struct e1000_adapter *adapter)
3431{
3432 might_sleep();
3433 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003434 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003435 e1000e_down(adapter);
3436 e1000e_up(adapter);
3437 clear_bit(__E1000_RESETTING, &adapter->state);
3438}
3439
3440/**
3441 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3442 * @adapter: board private structure to initialize
3443 *
3444 * e1000_sw_init initializes the Adapter private data structure.
3445 * Fields are initialized based on PCI device information and
3446 * OS network device settings (MTU size).
3447 **/
3448static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3449{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003450 struct net_device *netdev = adapter->netdev;
3451
3452 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3453 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003454 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3455 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003456
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003457 spin_lock_init(&adapter->stats64_lock);
3458
Bruce Allan4662e822008-08-26 18:37:06 -07003459 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003460
Bruce Allan4662e822008-08-26 18:37:06 -07003461 if (e1000_alloc_queues(adapter))
3462 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003463
Auke Kokbc7f75f2007-09-17 12:30:59 -07003464 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003465 e1000_irq_disable(adapter);
3466
Auke Kokbc7f75f2007-09-17 12:30:59 -07003467 set_bit(__E1000_DOWN, &adapter->state);
3468 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003469}
3470
3471/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003472 * e1000_intr_msi_test - Interrupt Handler
3473 * @irq: interrupt number
3474 * @data: pointer to a network interface device structure
3475 **/
3476static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3477{
3478 struct net_device *netdev = data;
3479 struct e1000_adapter *adapter = netdev_priv(netdev);
3480 struct e1000_hw *hw = &adapter->hw;
3481 u32 icr = er32(ICR);
3482
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003483 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003484 if (icr & E1000_ICR_RXSEQ) {
3485 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3486 wmb();
3487 }
3488
3489 return IRQ_HANDLED;
3490}
3491
3492/**
3493 * e1000_test_msi_interrupt - Returns 0 for successful test
3494 * @adapter: board private struct
3495 *
3496 * code flow taken from tg3.c
3497 **/
3498static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3499{
3500 struct net_device *netdev = adapter->netdev;
3501 struct e1000_hw *hw = &adapter->hw;
3502 int err;
3503
3504 /* poll_enable hasn't been called yet, so don't need disable */
3505 /* clear any pending events */
3506 er32(ICR);
3507
3508 /* free the real vector and request a test handler */
3509 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003510 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003511
3512 /* Assume that the test fails, if it succeeds then the test
3513 * MSI irq handler will unset this flag */
3514 adapter->flags |= FLAG_MSI_TEST_FAILED;
3515
3516 err = pci_enable_msi(adapter->pdev);
3517 if (err)
3518 goto msi_test_failed;
3519
Joe Perchesa0607fd2009-11-18 23:29:17 -08003520 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003521 netdev->name, netdev);
3522 if (err) {
3523 pci_disable_msi(adapter->pdev);
3524 goto msi_test_failed;
3525 }
3526
3527 wmb();
3528
3529 e1000_irq_enable(adapter);
3530
3531 /* fire an unusual interrupt on the test handler */
3532 ew32(ICS, E1000_ICS_RXSEQ);
3533 e1e_flush();
3534 msleep(50);
3535
3536 e1000_irq_disable(adapter);
3537
3538 rmb();
3539
3540 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003541 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003542 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3543 } else
3544 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003545
3546 free_irq(adapter->pdev->irq, netdev);
3547 pci_disable_msi(adapter->pdev);
3548
Bruce Allanf8d59f72008-08-08 18:36:11 -07003549msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003550 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003551 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003552}
3553
3554/**
3555 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3556 * @adapter: board private struct
3557 *
3558 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3559 **/
3560static int e1000_test_msi(struct e1000_adapter *adapter)
3561{
3562 int err;
3563 u16 pci_cmd;
3564
3565 if (!(adapter->flags & FLAG_MSI_ENABLED))
3566 return 0;
3567
3568 /* disable SERR in case the MSI write causes a master abort */
3569 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003570 if (pci_cmd & PCI_COMMAND_SERR)
3571 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3572 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003573
3574 err = e1000_test_msi_interrupt(adapter);
3575
Dean Nelson36f24072010-06-29 18:12:05 +00003576 /* re-enable SERR */
3577 if (pci_cmd & PCI_COMMAND_SERR) {
3578 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3579 pci_cmd |= PCI_COMMAND_SERR;
3580 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3581 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003582
Bruce Allanf8d59f72008-08-08 18:36:11 -07003583 return err;
3584}
3585
3586/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003587 * e1000_open - Called when a network interface is made active
3588 * @netdev: network interface device structure
3589 *
3590 * Returns 0 on success, negative value on failure
3591 *
3592 * The open entry point is called when a network interface is made
3593 * active by the system (IFF_UP). At this point all resources needed
3594 * for transmit and receive operations are allocated, the interrupt
3595 * handler is registered with the OS, the watchdog timer is started,
3596 * and the stack is notified that the interface is ready.
3597 **/
3598static int e1000_open(struct net_device *netdev)
3599{
3600 struct e1000_adapter *adapter = netdev_priv(netdev);
3601 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003602 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003603 int err;
3604
3605 /* disallow open during test */
3606 if (test_bit(__E1000_TESTING, &adapter->state))
3607 return -EBUSY;
3608
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003609 pm_runtime_get_sync(&pdev->dev);
3610
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003611 netif_carrier_off(netdev);
3612
Auke Kokbc7f75f2007-09-17 12:30:59 -07003613 /* allocate transmit descriptors */
3614 err = e1000e_setup_tx_resources(adapter);
3615 if (err)
3616 goto err_setup_tx;
3617
3618 /* allocate receive descriptors */
3619 err = e1000e_setup_rx_resources(adapter);
3620 if (err)
3621 goto err_setup_rx;
3622
Bruce Allan11b08be2010-05-10 14:59:31 +00003623 /*
3624 * If AMT is enabled, let the firmware know that the network
3625 * interface is now open and reset the part to a known state.
3626 */
3627 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003628 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003629 e1000e_reset(adapter);
3630 }
3631
Auke Kokbc7f75f2007-09-17 12:30:59 -07003632 e1000e_power_up_phy(adapter);
3633
3634 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3635 if ((adapter->hw.mng_cookie.status &
3636 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3637 e1000_update_mng_vlan(adapter);
3638
Florian Micklerc128ec22010-08-02 14:27:00 +00003639 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003640 if ((adapter->flags & FLAG_HAS_ERT) ||
3641 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003642 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3643 PM_QOS_CPU_DMA_LATENCY,
3644 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003645
Bruce Allanad680762008-03-28 09:15:03 -07003646 /*
Bruce Allanad680762008-03-28 09:15:03 -07003647 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003648 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3649 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003650 * clean_rx handler before we do so.
3651 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003652 e1000_configure(adapter);
3653
3654 err = e1000_request_irq(adapter);
3655 if (err)
3656 goto err_req_irq;
3657
Bruce Allanf8d59f72008-08-08 18:36:11 -07003658 /*
3659 * Work around PCIe errata with MSI interrupts causing some chipsets to
3660 * ignore e1000e MSI messages, which means we need to test our MSI
3661 * interrupt now
3662 */
Bruce Allan4662e822008-08-26 18:37:06 -07003663 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003664 err = e1000_test_msi(adapter);
3665 if (err) {
3666 e_err("Interrupt allocation failed\n");
3667 goto err_req_irq;
3668 }
3669 }
3670
Auke Kokbc7f75f2007-09-17 12:30:59 -07003671 /* From here on the code is the same as e1000e_up() */
3672 clear_bit(__E1000_DOWN, &adapter->state);
3673
3674 napi_enable(&adapter->napi);
3675
3676 e1000_irq_enable(adapter);
3677
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003678 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003679
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003680 adapter->idle_check = true;
3681 pm_runtime_put(&pdev->dev);
3682
Auke Kokbc7f75f2007-09-17 12:30:59 -07003683 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003684 if (adapter->msix_entries)
3685 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3686 else
3687 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003688
3689 return 0;
3690
3691err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003692 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003693 e1000_power_down_phy(adapter);
3694 e1000e_free_rx_resources(adapter);
3695err_setup_rx:
3696 e1000e_free_tx_resources(adapter);
3697err_setup_tx:
3698 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003699 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003700
3701 return err;
3702}
3703
3704/**
3705 * e1000_close - Disables a network interface
3706 * @netdev: network interface device structure
3707 *
3708 * Returns 0, this is not allowed to fail
3709 *
3710 * The close entry point is called when an interface is de-activated
3711 * by the OS. The hardware is still under the drivers control, but
3712 * needs to be disabled. A global MAC reset is issued to stop the
3713 * hardware, and all transmit and receive resources are freed.
3714 **/
3715static int e1000_close(struct net_device *netdev)
3716{
3717 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003718 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003719
3720 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003721
3722 pm_runtime_get_sync(&pdev->dev);
3723
3724 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3725 e1000e_down(adapter);
3726 e1000_free_irq(adapter);
3727 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003728 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003729
3730 e1000e_free_tx_resources(adapter);
3731 e1000e_free_rx_resources(adapter);
3732
Bruce Allanad680762008-03-28 09:15:03 -07003733 /*
3734 * kill manageability vlan ID if supported, but not if a vlan with
3735 * the same ID is registered on the host OS (let 8021q kill it)
3736 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003737 if (adapter->hw.mng_cookie.status &
3738 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003739 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3740
Bruce Allanad680762008-03-28 09:15:03 -07003741 /*
3742 * If AMT is enabled, let the firmware know that the network
3743 * interface is now closed
3744 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003745 if ((adapter->flags & FLAG_HAS_AMT) &&
3746 !test_bit(__E1000_TESTING, &adapter->state))
3747 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003748
Bruce Allan828bac82010-09-29 21:39:37 +00003749 if ((adapter->flags & FLAG_HAS_ERT) ||
3750 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003751 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003752
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003753 pm_runtime_put_sync(&pdev->dev);
3754
Auke Kokbc7f75f2007-09-17 12:30:59 -07003755 return 0;
3756}
3757/**
3758 * e1000_set_mac - Change the Ethernet Address of the NIC
3759 * @netdev: network interface device structure
3760 * @p: pointer to an address structure
3761 *
3762 * Returns 0 on success, negative on failure
3763 **/
3764static int e1000_set_mac(struct net_device *netdev, void *p)
3765{
3766 struct e1000_adapter *adapter = netdev_priv(netdev);
3767 struct sockaddr *addr = p;
3768
3769 if (!is_valid_ether_addr(addr->sa_data))
3770 return -EADDRNOTAVAIL;
3771
3772 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3773 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3774
3775 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3776
3777 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3778 /* activate the work around */
3779 e1000e_set_laa_state_82571(&adapter->hw, 1);
3780
Bruce Allanad680762008-03-28 09:15:03 -07003781 /*
3782 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003783 * between the time RAR[0] gets clobbered and the time it
3784 * gets fixed (in e1000_watchdog), the actual LAA is in one
3785 * of the RARs and no incoming packets directed to this port
3786 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003787 * RAR[14]
3788 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003789 e1000e_rar_set(&adapter->hw,
3790 adapter->hw.mac.addr,
3791 adapter->hw.mac.rar_entry_count - 1);
3792 }
3793
3794 return 0;
3795}
3796
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003797/**
3798 * e1000e_update_phy_task - work thread to update phy
3799 * @work: pointer to our work struct
3800 *
3801 * this worker thread exists because we must acquire a
3802 * semaphore to read the phy, which we could msleep while
3803 * waiting for it, and we can't msleep in a timer.
3804 **/
3805static void e1000e_update_phy_task(struct work_struct *work)
3806{
3807 struct e1000_adapter *adapter = container_of(work,
3808 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003809
3810 if (test_bit(__E1000_DOWN, &adapter->state))
3811 return;
3812
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003813 e1000_get_phy_info(&adapter->hw);
3814}
3815
Bruce Allanad680762008-03-28 09:15:03 -07003816/*
3817 * Need to wait a few seconds after link up to get diagnostic information from
3818 * the phy
3819 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003820static void e1000_update_phy_info(unsigned long data)
3821{
3822 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003823
3824 if (test_bit(__E1000_DOWN, &adapter->state))
3825 return;
3826
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003827 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003828}
3829
3830/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003831 * e1000e_update_phy_stats - Update the PHY statistics counters
3832 * @adapter: board private structure
3833 **/
3834static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3835{
3836 struct e1000_hw *hw = &adapter->hw;
3837 s32 ret_val;
3838 u16 phy_data;
3839
3840 ret_val = hw->phy.ops.acquire(hw);
3841 if (ret_val)
3842 return;
3843
3844 hw->phy.addr = 1;
3845
3846#define HV_PHY_STATS_PAGE 778
3847 /*
3848 * A page set is expensive so check if already on desired page.
3849 * If not, set to the page with the PHY status registers.
3850 */
3851 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3852 &phy_data);
3853 if (ret_val)
3854 goto release;
3855 if (phy_data != (HV_PHY_STATS_PAGE << IGP_PAGE_SHIFT)) {
3856 ret_val = e1000e_write_phy_reg_mdic(hw,
3857 IGP01E1000_PHY_PAGE_SELECT,
3858 (HV_PHY_STATS_PAGE <<
3859 IGP_PAGE_SHIFT));
3860 if (ret_val)
3861 goto release;
3862 }
3863
3864 /* Read/clear the upper 16-bit registers and read/accumulate lower */
3865
3866 /* Single Collision Count */
3867 e1000e_read_phy_reg_mdic(hw, HV_SCC_UPPER & MAX_PHY_REG_ADDRESS,
3868 &phy_data);
3869 ret_val = e1000e_read_phy_reg_mdic(hw,
3870 HV_SCC_LOWER & MAX_PHY_REG_ADDRESS,
3871 &phy_data);
3872 if (!ret_val)
3873 adapter->stats.scc += phy_data;
3874
3875 /* Excessive Collision Count */
3876 e1000e_read_phy_reg_mdic(hw, HV_ECOL_UPPER & MAX_PHY_REG_ADDRESS,
3877 &phy_data);
3878 ret_val = e1000e_read_phy_reg_mdic(hw,
3879 HV_ECOL_LOWER & MAX_PHY_REG_ADDRESS,
3880 &phy_data);
3881 if (!ret_val)
3882 adapter->stats.ecol += phy_data;
3883
3884 /* Multiple Collision Count */
3885 e1000e_read_phy_reg_mdic(hw, HV_MCC_UPPER & MAX_PHY_REG_ADDRESS,
3886 &phy_data);
3887 ret_val = e1000e_read_phy_reg_mdic(hw,
3888 HV_MCC_LOWER & MAX_PHY_REG_ADDRESS,
3889 &phy_data);
3890 if (!ret_val)
3891 adapter->stats.mcc += phy_data;
3892
3893 /* Late Collision Count */
3894 e1000e_read_phy_reg_mdic(hw, HV_LATECOL_UPPER & MAX_PHY_REG_ADDRESS,
3895 &phy_data);
3896 ret_val = e1000e_read_phy_reg_mdic(hw,
3897 HV_LATECOL_LOWER &
3898 MAX_PHY_REG_ADDRESS,
3899 &phy_data);
3900 if (!ret_val)
3901 adapter->stats.latecol += phy_data;
3902
3903 /* Collision Count - also used for adaptive IFS */
3904 e1000e_read_phy_reg_mdic(hw, HV_COLC_UPPER & MAX_PHY_REG_ADDRESS,
3905 &phy_data);
3906 ret_val = e1000e_read_phy_reg_mdic(hw,
3907 HV_COLC_LOWER & MAX_PHY_REG_ADDRESS,
3908 &phy_data);
3909 if (!ret_val)
3910 hw->mac.collision_delta = phy_data;
3911
3912 /* Defer Count */
3913 e1000e_read_phy_reg_mdic(hw, HV_DC_UPPER & MAX_PHY_REG_ADDRESS,
3914 &phy_data);
3915 ret_val = e1000e_read_phy_reg_mdic(hw,
3916 HV_DC_LOWER & MAX_PHY_REG_ADDRESS,
3917 &phy_data);
3918 if (!ret_val)
3919 adapter->stats.dc += phy_data;
3920
3921 /* Transmit with no CRS */
3922 e1000e_read_phy_reg_mdic(hw, HV_TNCRS_UPPER & MAX_PHY_REG_ADDRESS,
3923 &phy_data);
3924 ret_val = e1000e_read_phy_reg_mdic(hw,
3925 HV_TNCRS_LOWER & MAX_PHY_REG_ADDRESS,
3926 &phy_data);
3927 if (!ret_val)
3928 adapter->stats.tncrs += phy_data;
3929
3930release:
3931 hw->phy.ops.release(hw);
3932}
3933
3934/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003935 * e1000e_update_stats - Update the board statistics counters
3936 * @adapter: board private structure
3937 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003938static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003939{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003940 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941 struct e1000_hw *hw = &adapter->hw;
3942 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003943
3944 /*
3945 * Prevent stats update while adapter is being reset, or if the pci
3946 * connection is down.
3947 */
3948 if (adapter->link_speed == 0)
3949 return;
3950 if (pci_channel_offline(pdev))
3951 return;
3952
Auke Kokbc7f75f2007-09-17 12:30:59 -07003953 adapter->stats.crcerrs += er32(CRCERRS);
3954 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003955 adapter->stats.gorc += er32(GORCL);
3956 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003957 adapter->stats.bprc += er32(BPRC);
3958 adapter->stats.mprc += er32(MPRC);
3959 adapter->stats.roc += er32(ROC);
3960
Auke Kokbc7f75f2007-09-17 12:30:59 -07003961 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003962
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003963 /* Half-duplex statistics */
3964 if (adapter->link_duplex == HALF_DUPLEX) {
3965 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
3966 e1000e_update_phy_stats(adapter);
3967 } else {
3968 adapter->stats.scc += er32(SCC);
3969 adapter->stats.ecol += er32(ECOL);
3970 adapter->stats.mcc += er32(MCC);
3971 adapter->stats.latecol += er32(LATECOL);
3972 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003973
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003974 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003975
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003976 if ((hw->mac.type != e1000_82574) &&
3977 (hw->mac.type != e1000_82583))
3978 adapter->stats.tncrs += er32(TNCRS);
3979 }
3980 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003981 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003982
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983 adapter->stats.xonrxc += er32(XONRXC);
3984 adapter->stats.xontxc += er32(XONTXC);
3985 adapter->stats.xoffrxc += er32(XOFFRXC);
3986 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003987 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003988 adapter->stats.gotc += er32(GOTCL);
3989 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003990 adapter->stats.rnbc += er32(RNBC);
3991 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003992
3993 adapter->stats.mptc += er32(MPTC);
3994 adapter->stats.bptc += er32(BPTC);
3995
3996 /* used for adaptive IFS */
3997
3998 hw->mac.tx_packet_delta = er32(TPT);
3999 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004000
4001 adapter->stats.algnerrc += er32(ALGNERRC);
4002 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004003 adapter->stats.cexterr += er32(CEXTERR);
4004 adapter->stats.tsctc += er32(TSCTC);
4005 adapter->stats.tsctfc += er32(TSCTFC);
4006
Auke Kokbc7f75f2007-09-17 12:30:59 -07004007 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004008 netdev->stats.multicast = adapter->stats.mprc;
4009 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004010
4011 /* Rx Errors */
4012
Bruce Allanad680762008-03-28 09:15:03 -07004013 /*
4014 * RLEC on some newer hardware can be incorrect so build
4015 * our own version based on RUC and ROC
4016 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004017 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004018 adapter->stats.crcerrs + adapter->stats.algnerrc +
4019 adapter->stats.ruc + adapter->stats.roc +
4020 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004021 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004022 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004023 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4024 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4025 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004026
4027 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004028 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004029 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004030 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4031 netdev->stats.tx_window_errors = adapter->stats.latecol;
4032 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004033
4034 /* Tx Dropped needs to be maintained elsewhere */
4035
Auke Kokbc7f75f2007-09-17 12:30:59 -07004036 /* Management Stats */
4037 adapter->stats.mgptc += er32(MGTPTC);
4038 adapter->stats.mgprc += er32(MGTPRC);
4039 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004040}
4041
Bruce Allan7c257692008-04-23 11:09:00 -07004042/**
4043 * e1000_phy_read_status - Update the PHY register status snapshot
4044 * @adapter: board private structure
4045 **/
4046static void e1000_phy_read_status(struct e1000_adapter *adapter)
4047{
4048 struct e1000_hw *hw = &adapter->hw;
4049 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004050
4051 if ((er32(STATUS) & E1000_STATUS_LU) &&
4052 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004053 int ret_val;
4054
Bruce Allan7c257692008-04-23 11:09:00 -07004055 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4056 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4057 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4058 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4059 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4060 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4061 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4062 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4063 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004064 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004065 } else {
4066 /*
4067 * Do not read PHY registers if link is not up
4068 * Set values to typical power-on defaults
4069 */
4070 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4071 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4072 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4073 BMSR_ERCAP);
4074 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4075 ADVERTISE_ALL | ADVERTISE_CSMA);
4076 phy->lpa = 0;
4077 phy->expansion = EXPANSION_ENABLENPAGE;
4078 phy->ctrl1000 = ADVERTISE_1000FULL;
4079 phy->stat1000 = 0;
4080 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4081 }
Bruce Allan7c257692008-04-23 11:09:00 -07004082}
4083
Auke Kokbc7f75f2007-09-17 12:30:59 -07004084static void e1000_print_link_info(struct e1000_adapter *adapter)
4085{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004086 struct e1000_hw *hw = &adapter->hw;
4087 u32 ctrl = er32(CTRL);
4088
Bruce Allan8f12fe82008-11-21 16:54:43 -08004089 /* Link status message must follow this format for user tools */
4090 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4091 "Flow Control: %s\n",
4092 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004093 adapter->link_speed,
4094 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004095 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004096 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004097 "Rx/Tx" :
4098 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4099 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004100}
4101
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004102static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004103{
4104 struct e1000_hw *hw = &adapter->hw;
4105 bool link_active = 0;
4106 s32 ret_val = 0;
4107
4108 /*
4109 * get_link_status is set on LSC (link status) interrupt or
4110 * Rx sequence error interrupt. get_link_status will stay
4111 * false until the check_for_link establishes link
4112 * for copper adapters ONLY
4113 */
4114 switch (hw->phy.media_type) {
4115 case e1000_media_type_copper:
4116 if (hw->mac.get_link_status) {
4117 ret_val = hw->mac.ops.check_for_link(hw);
4118 link_active = !hw->mac.get_link_status;
4119 } else {
4120 link_active = 1;
4121 }
4122 break;
4123 case e1000_media_type_fiber:
4124 ret_val = hw->mac.ops.check_for_link(hw);
4125 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4126 break;
4127 case e1000_media_type_internal_serdes:
4128 ret_val = hw->mac.ops.check_for_link(hw);
4129 link_active = adapter->hw.mac.serdes_has_link;
4130 break;
4131 default:
4132 case e1000_media_type_unknown:
4133 break;
4134 }
4135
4136 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4137 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4138 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004139 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004140 }
4141
4142 return link_active;
4143}
4144
4145static void e1000e_enable_receives(struct e1000_adapter *adapter)
4146{
4147 /* make sure the receive unit is started */
4148 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4149 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4150 struct e1000_hw *hw = &adapter->hw;
4151 u32 rctl = er32(RCTL);
4152 ew32(RCTL, rctl | E1000_RCTL_EN);
4153 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4154 }
4155}
4156
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004157static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4158{
4159 struct e1000_hw *hw = &adapter->hw;
4160
4161 /*
4162 * With 82574 controllers, PHY needs to be checked periodically
4163 * for hung state and reset, if two calls return true
4164 */
4165 if (e1000_check_phy_82574(hw))
4166 adapter->phy_hang_count++;
4167 else
4168 adapter->phy_hang_count = 0;
4169
4170 if (adapter->phy_hang_count > 1) {
4171 adapter->phy_hang_count = 0;
4172 schedule_work(&adapter->reset_task);
4173 }
4174}
4175
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176/**
4177 * e1000_watchdog - Timer Call-back
4178 * @data: pointer to adapter cast into an unsigned long
4179 **/
4180static void e1000_watchdog(unsigned long data)
4181{
4182 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4183
4184 /* Do the rest outside of interrupt context */
4185 schedule_work(&adapter->watchdog_task);
4186
4187 /* TODO: make this use queue_delayed_work() */
4188}
4189
4190static void e1000_watchdog_task(struct work_struct *work)
4191{
4192 struct e1000_adapter *adapter = container_of(work,
4193 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004194 struct net_device *netdev = adapter->netdev;
4195 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004196 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004197 struct e1000_ring *tx_ring = adapter->tx_ring;
4198 struct e1000_hw *hw = &adapter->hw;
4199 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004200
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004201 if (test_bit(__E1000_DOWN, &adapter->state))
4202 return;
4203
David S. Millerb405e8d2010-02-04 22:31:41 -08004204 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004205 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004206 /* Cancel scheduled suspend requests. */
4207 pm_runtime_resume(netdev->dev.parent);
4208
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004209 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004210 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004211 }
4212
4213 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4214 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4215 e1000_update_mng_vlan(adapter);
4216
Auke Kokbc7f75f2007-09-17 12:30:59 -07004217 if (link) {
4218 if (!netif_carrier_ok(netdev)) {
4219 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004220
4221 /* Cancel scheduled suspend requests. */
4222 pm_runtime_resume(netdev->dev.parent);
4223
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004224 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004225 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004226 mac->ops.get_link_up_info(&adapter->hw,
4227 &adapter->link_speed,
4228 &adapter->link_duplex);
4229 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004230 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004231 * On supported PHYs, check for duplex mismatch only
4232 * if link has autonegotiated at 10/100 half
4233 */
4234 if ((hw->phy.type == e1000_phy_igp_3 ||
4235 hw->phy.type == e1000_phy_bm) &&
4236 (hw->mac.autoneg == true) &&
4237 (adapter->link_speed == SPEED_10 ||
4238 adapter->link_speed == SPEED_100) &&
4239 (adapter->link_duplex == HALF_DUPLEX)) {
4240 u16 autoneg_exp;
4241
4242 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4243
4244 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4245 e_info("Autonegotiated half duplex but"
4246 " link partner cannot autoneg. "
4247 " Try forcing full duplex if "
4248 "link gets many collisions.\n");
4249 }
4250
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004251 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004252 adapter->tx_timeout_factor = 1;
4253 switch (adapter->link_speed) {
4254 case SPEED_10:
4255 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004256 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004257 break;
4258 case SPEED_100:
4259 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004260 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004261 break;
4262 }
4263
Bruce Allanad680762008-03-28 09:15:03 -07004264 /*
4265 * workaround: re-program speed mode bit after
4266 * link-up event
4267 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004268 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4269 !txb2b) {
4270 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004271 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004272 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004273 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004274 }
4275
Bruce Allanad680762008-03-28 09:15:03 -07004276 /*
4277 * disable TSO for pcie and 10/100 speeds, to avoid
4278 * some hardware issues
4279 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004280 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4281 switch (adapter->link_speed) {
4282 case SPEED_10:
4283 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004284 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004285 netdev->features &= ~NETIF_F_TSO;
4286 netdev->features &= ~NETIF_F_TSO6;
4287 break;
4288 case SPEED_1000:
4289 netdev->features |= NETIF_F_TSO;
4290 netdev->features |= NETIF_F_TSO6;
4291 break;
4292 default:
4293 /* oops */
4294 break;
4295 }
4296 }
4297
Bruce Allanad680762008-03-28 09:15:03 -07004298 /*
4299 * enable transmits in the hardware, need to do this
4300 * after setting TARC(0)
4301 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004302 tctl = er32(TCTL);
4303 tctl |= E1000_TCTL_EN;
4304 ew32(TCTL, tctl);
4305
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004306 /*
4307 * Perform any post-link-up configuration before
4308 * reporting link up.
4309 */
4310 if (phy->ops.cfg_on_link_up)
4311 phy->ops.cfg_on_link_up(hw);
4312
Auke Kokbc7f75f2007-09-17 12:30:59 -07004313 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004314
4315 if (!test_bit(__E1000_DOWN, &adapter->state))
4316 mod_timer(&adapter->phy_info_timer,
4317 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004318 }
4319 } else {
4320 if (netif_carrier_ok(netdev)) {
4321 adapter->link_speed = 0;
4322 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004323 /* Link status message must follow this format */
4324 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4325 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004326 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004327 if (!test_bit(__E1000_DOWN, &adapter->state))
4328 mod_timer(&adapter->phy_info_timer,
4329 round_jiffies(jiffies + 2 * HZ));
4330
4331 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4332 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004333 else
4334 pm_schedule_suspend(netdev->dev.parent,
4335 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004336 }
4337 }
4338
4339link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004340 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004341 e1000e_update_stats(adapter);
4342
4343 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4344 adapter->tpt_old = adapter->stats.tpt;
4345 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4346 adapter->colc_old = adapter->stats.colc;
4347
Bruce Allan7c257692008-04-23 11:09:00 -07004348 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4349 adapter->gorc_old = adapter->stats.gorc;
4350 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4351 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004352 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004353
4354 e1000e_update_adaptive(&adapter->hw);
4355
Bruce Allan90da0662011-01-06 07:02:53 +00004356 if (!netif_carrier_ok(netdev) &&
4357 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4358 /*
4359 * We've lost link, so the controller stops DMA,
4360 * but we've got queued Tx work that's never going
4361 * to get done, so reset controller to flush Tx.
4362 * (Do the reset outside of interrupt context).
4363 */
Bruce Allan90da0662011-01-06 07:02:53 +00004364 schedule_work(&adapter->reset_task);
4365 /* return immediately since reset is imminent */
4366 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004367 }
4368
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004369 /* Simple mode for Interrupt Throttle Rate (ITR) */
4370 if (adapter->itr_setting == 4) {
4371 /*
4372 * Symmetric Tx/Rx gets a reduced ITR=2000;
4373 * Total asymmetrical Tx or Rx gets ITR=8000;
4374 * everyone else is between 2000-8000.
4375 */
4376 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4377 u32 dif = (adapter->gotc > adapter->gorc ?
4378 adapter->gotc - adapter->gorc :
4379 adapter->gorc - adapter->gotc) / 10000;
4380 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4381
4382 ew32(ITR, 1000000000 / (itr * 256));
4383 }
4384
Bruce Allanad680762008-03-28 09:15:03 -07004385 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004386 if (adapter->msix_entries)
4387 ew32(ICS, adapter->rx_ring->ims_val);
4388 else
4389 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004390
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004391 /* flush pending descriptors to memory before detecting Tx hang */
4392 e1000e_flush_descriptors(adapter);
4393
Auke Kokbc7f75f2007-09-17 12:30:59 -07004394 /* Force detection of hung controller every watchdog period */
4395 adapter->detect_tx_hung = 1;
4396
Bruce Allanad680762008-03-28 09:15:03 -07004397 /*
4398 * With 82571 controllers, LAA may be overwritten due to controller
4399 * reset from the other port. Set the appropriate LAA in RAR[0]
4400 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004401 if (e1000e_get_laa_state_82571(hw))
4402 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4403
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004404 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4405 e1000e_check_82574_phy_workaround(adapter);
4406
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407 /* Reset the timer */
4408 if (!test_bit(__E1000_DOWN, &adapter->state))
4409 mod_timer(&adapter->watchdog_timer,
4410 round_jiffies(jiffies + 2 * HZ));
4411}
4412
4413#define E1000_TX_FLAGS_CSUM 0x00000001
4414#define E1000_TX_FLAGS_VLAN 0x00000002
4415#define E1000_TX_FLAGS_TSO 0x00000004
4416#define E1000_TX_FLAGS_IPV4 0x00000008
4417#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4418#define E1000_TX_FLAGS_VLAN_SHIFT 16
4419
4420static int e1000_tso(struct e1000_adapter *adapter,
4421 struct sk_buff *skb)
4422{
4423 struct e1000_ring *tx_ring = adapter->tx_ring;
4424 struct e1000_context_desc *context_desc;
4425 struct e1000_buffer *buffer_info;
4426 unsigned int i;
4427 u32 cmd_length = 0;
4428 u16 ipcse = 0, tucse, mss;
4429 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004430
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004431 if (!skb_is_gso(skb))
4432 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004433
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004434 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004435 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4436
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004437 if (err)
4438 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004439 }
4440
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004441 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4442 mss = skb_shinfo(skb)->gso_size;
4443 if (skb->protocol == htons(ETH_P_IP)) {
4444 struct iphdr *iph = ip_hdr(skb);
4445 iph->tot_len = 0;
4446 iph->check = 0;
4447 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4448 0, IPPROTO_TCP, 0);
4449 cmd_length = E1000_TXD_CMD_IP;
4450 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004451 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004452 ipv6_hdr(skb)->payload_len = 0;
4453 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4454 &ipv6_hdr(skb)->daddr,
4455 0, IPPROTO_TCP, 0);
4456 ipcse = 0;
4457 }
4458 ipcss = skb_network_offset(skb);
4459 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4460 tucss = skb_transport_offset(skb);
4461 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4462 tucse = 0;
4463
4464 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4465 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4466
4467 i = tx_ring->next_to_use;
4468 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4469 buffer_info = &tx_ring->buffer_info[i];
4470
4471 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4472 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4473 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4474 context_desc->upper_setup.tcp_fields.tucss = tucss;
4475 context_desc->upper_setup.tcp_fields.tucso = tucso;
4476 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4477 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4478 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4479 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4480
4481 buffer_info->time_stamp = jiffies;
4482 buffer_info->next_to_watch = i;
4483
4484 i++;
4485 if (i == tx_ring->count)
4486 i = 0;
4487 tx_ring->next_to_use = i;
4488
4489 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004490}
4491
4492static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4493{
4494 struct e1000_ring *tx_ring = adapter->tx_ring;
4495 struct e1000_context_desc *context_desc;
4496 struct e1000_buffer *buffer_info;
4497 unsigned int i;
4498 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004499 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004500 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004501
Dave Grahamaf807c82008-10-09 14:28:58 -07004502 if (skb->ip_summed != CHECKSUM_PARTIAL)
4503 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004504
Arthur Jones5f66f202009-03-19 01:13:08 +00004505 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4506 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4507 else
4508 protocol = skb->protocol;
4509
Arthur Jones3f518392009-03-20 15:56:35 -07004510 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004511 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004512 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4513 cmd_len |= E1000_TXD_CMD_TCP;
4514 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004515 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004516 /* XXX not handling all IPV6 headers */
4517 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4518 cmd_len |= E1000_TXD_CMD_TCP;
4519 break;
4520 default:
4521 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004522 e_warn("checksum_partial proto=%x!\n",
4523 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004524 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004525 }
4526
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004527 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004528
4529 i = tx_ring->next_to_use;
4530 buffer_info = &tx_ring->buffer_info[i];
4531 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4532
4533 context_desc->lower_setup.ip_config = 0;
4534 context_desc->upper_setup.tcp_fields.tucss = css;
4535 context_desc->upper_setup.tcp_fields.tucso =
4536 css + skb->csum_offset;
4537 context_desc->upper_setup.tcp_fields.tucse = 0;
4538 context_desc->tcp_seg_setup.data = 0;
4539 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4540
4541 buffer_info->time_stamp = jiffies;
4542 buffer_info->next_to_watch = i;
4543
4544 i++;
4545 if (i == tx_ring->count)
4546 i = 0;
4547 tx_ring->next_to_use = i;
4548
4549 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004550}
4551
4552#define E1000_MAX_PER_TXD 8192
4553#define E1000_MAX_TXD_PWR 12
4554
4555static int e1000_tx_map(struct e1000_adapter *adapter,
4556 struct sk_buff *skb, unsigned int first,
4557 unsigned int max_per_txd, unsigned int nr_frags,
4558 unsigned int mss)
4559{
4560 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004561 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004562 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004563 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004564 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004565 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004566
4567 i = tx_ring->next_to_use;
4568
4569 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004570 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004571 size = min(len, max_per_txd);
4572
Auke Kokbc7f75f2007-09-17 12:30:59 -07004573 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004574 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004575 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004576 buffer_info->dma = dma_map_single(&pdev->dev,
4577 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004578 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004579 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004580 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004581 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004582
4583 len -= size;
4584 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004585 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004586
4587 if (len) {
4588 i++;
4589 if (i == tx_ring->count)
4590 i = 0;
4591 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004592 }
4593
4594 for (f = 0; f < nr_frags; f++) {
4595 struct skb_frag_struct *frag;
4596
4597 frag = &skb_shinfo(skb)->frags[f];
4598 len = frag->size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004599 offset = frag->page_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004600
4601 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004602 i++;
4603 if (i == tx_ring->count)
4604 i = 0;
4605
Auke Kokbc7f75f2007-09-17 12:30:59 -07004606 buffer_info = &tx_ring->buffer_info[i];
4607 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004608
4609 buffer_info->length = size;
4610 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004611 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004612 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
Alexander Duyck03b13202009-12-02 16:45:31 +00004613 offset, size,
Nick Nunley0be3f552010-04-27 13:09:05 +00004614 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004615 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004616 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004617 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004618
4619 len -= size;
4620 offset += size;
4621 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004622 }
4623 }
4624
Bruce Allanaf667a22010-12-31 06:10:01 +00004625 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004626 /* multiply data chunks by size of headers */
4627 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4628
Auke Kokbc7f75f2007-09-17 12:30:59 -07004629 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004630 tx_ring->buffer_info[i].segs = segs;
4631 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004632 tx_ring->buffer_info[first].next_to_watch = i;
4633
4634 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004635
4636dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004637 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004638 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004639 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004640 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004641
4642 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004643 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004644 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004645 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004646 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004647 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004648 }
4649
4650 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004651}
4652
4653static void e1000_tx_queue(struct e1000_adapter *adapter,
4654 int tx_flags, int count)
4655{
4656 struct e1000_ring *tx_ring = adapter->tx_ring;
4657 struct e1000_tx_desc *tx_desc = NULL;
4658 struct e1000_buffer *buffer_info;
4659 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4660 unsigned int i;
4661
4662 if (tx_flags & E1000_TX_FLAGS_TSO) {
4663 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4664 E1000_TXD_CMD_TSE;
4665 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4666
4667 if (tx_flags & E1000_TX_FLAGS_IPV4)
4668 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4669 }
4670
4671 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4672 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4673 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4674 }
4675
4676 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4677 txd_lower |= E1000_TXD_CMD_VLE;
4678 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4679 }
4680
4681 i = tx_ring->next_to_use;
4682
Bruce Allan36b973d2010-11-24 07:42:43 +00004683 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004684 buffer_info = &tx_ring->buffer_info[i];
4685 tx_desc = E1000_TX_DESC(*tx_ring, i);
4686 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4687 tx_desc->lower.data =
4688 cpu_to_le32(txd_lower | buffer_info->length);
4689 tx_desc->upper.data = cpu_to_le32(txd_upper);
4690
4691 i++;
4692 if (i == tx_ring->count)
4693 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004694 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004695
4696 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4697
Bruce Allanad680762008-03-28 09:15:03 -07004698 /*
4699 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004700 * know there are new descriptors to fetch. (Only
4701 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004702 * such as IA-64).
4703 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004704 wmb();
4705
4706 tx_ring->next_to_use = i;
4707 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07004708 /*
4709 * we need this if more than one processor can write to our tail
4710 * at a time, it synchronizes IO on IA64/Altix systems
4711 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004712 mmiowb();
4713}
4714
4715#define MINIMUM_DHCP_PACKET_SIZE 282
4716static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4717 struct sk_buff *skb)
4718{
4719 struct e1000_hw *hw = &adapter->hw;
4720 u16 length, offset;
4721
4722 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004723 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4724 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004725 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4726 return 0;
4727 }
4728
4729 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4730 return 0;
4731
4732 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4733 return 0;
4734
4735 {
4736 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4737 struct udphdr *udp;
4738
4739 if (ip->protocol != IPPROTO_UDP)
4740 return 0;
4741
4742 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4743 if (ntohs(udp->dest) != 67)
4744 return 0;
4745
4746 offset = (u8 *)udp + 8 - skb->data;
4747 length = skb->len - offset;
4748 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4749 }
4750
4751 return 0;
4752}
4753
4754static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4755{
4756 struct e1000_adapter *adapter = netdev_priv(netdev);
4757
4758 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004759 /*
4760 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004761 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004762 * but since that doesn't exist yet, just open code it.
4763 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004764 smp_mb();
4765
Bruce Allanad680762008-03-28 09:15:03 -07004766 /*
4767 * We need to check again in a case another CPU has just
4768 * made room available.
4769 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004770 if (e1000_desc_unused(adapter->tx_ring) < size)
4771 return -EBUSY;
4772
4773 /* A reprieve! */
4774 netif_start_queue(netdev);
4775 ++adapter->restart_queue;
4776 return 0;
4777}
4778
4779static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4780{
4781 struct e1000_adapter *adapter = netdev_priv(netdev);
4782
4783 if (e1000_desc_unused(adapter->tx_ring) >= size)
4784 return 0;
4785 return __e1000_maybe_stop_tx(netdev, size);
4786}
4787
4788#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004789static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4790 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004791{
4792 struct e1000_adapter *adapter = netdev_priv(netdev);
4793 struct e1000_ring *tx_ring = adapter->tx_ring;
4794 unsigned int first;
4795 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4796 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4797 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004798 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004799 unsigned int nr_frags;
4800 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004801 int count = 0;
4802 int tso;
4803 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004804
4805 if (test_bit(__E1000_DOWN, &adapter->state)) {
4806 dev_kfree_skb_any(skb);
4807 return NETDEV_TX_OK;
4808 }
4809
4810 if (skb->len <= 0) {
4811 dev_kfree_skb_any(skb);
4812 return NETDEV_TX_OK;
4813 }
4814
4815 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004816 /*
4817 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004818 * make sure there is enough room in the FIFO before
4819 * initiating the DMA for each buffer. The calc is:
4820 * 4 = ceil(buffer len/mss). To make sure we don't
4821 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004822 * drops.
4823 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004824 if (mss) {
4825 u8 hdr_len;
4826 max_per_txd = min(mss << 2, max_per_txd);
4827 max_txd_pwr = fls(max_per_txd) - 1;
4828
Bruce Allanad680762008-03-28 09:15:03 -07004829 /*
4830 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4831 * points to just header, pull a few bytes of payload from
4832 * frags into skb->data
4833 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004834 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004835 /*
4836 * we do this workaround for ES2LAN, but it is un-necessary,
4837 * avoiding it could save a lot of cycles
4838 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004839 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004840 unsigned int pull_size;
4841
4842 pull_size = min((unsigned int)4, skb->data_len);
4843 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004844 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004845 dev_kfree_skb_any(skb);
4846 return NETDEV_TX_OK;
4847 }
Eric Dumazete743d312010-04-14 15:59:40 -07004848 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004849 }
4850 }
4851
4852 /* reserve a descriptor for the offload context */
4853 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4854 count++;
4855 count++;
4856
4857 count += TXD_USE_COUNT(len, max_txd_pwr);
4858
4859 nr_frags = skb_shinfo(skb)->nr_frags;
4860 for (f = 0; f < nr_frags; f++)
4861 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4862 max_txd_pwr);
4863
4864 if (adapter->hw.mac.tx_pkt_filtering)
4865 e1000_transfer_dhcp_info(adapter, skb);
4866
Bruce Allanad680762008-03-28 09:15:03 -07004867 /*
4868 * need: count + 2 desc gap to keep tail from touching
4869 * head, otherwise try next time
4870 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004871 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004872 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004873
Jesse Grosseab6d182010-10-20 13:56:03 +00004874 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004875 tx_flags |= E1000_TX_FLAGS_VLAN;
4876 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4877 }
4878
4879 first = tx_ring->next_to_use;
4880
4881 tso = e1000_tso(adapter, skb);
4882 if (tso < 0) {
4883 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004884 return NETDEV_TX_OK;
4885 }
4886
4887 if (tso)
4888 tx_flags |= E1000_TX_FLAGS_TSO;
4889 else if (e1000_tx_csum(adapter, skb))
4890 tx_flags |= E1000_TX_FLAGS_CSUM;
4891
Bruce Allanad680762008-03-28 09:15:03 -07004892 /*
4893 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004894 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004895 * no longer assume, we must.
4896 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004897 if (skb->protocol == htons(ETH_P_IP))
4898 tx_flags |= E1000_TX_FLAGS_IPV4;
4899
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004900 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004901 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004902 if (count) {
4903 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004904 /* Make sure there is space in the ring for the next send. */
4905 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4906
4907 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004908 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004909 tx_ring->buffer_info[first].time_stamp = 0;
4910 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004911 }
4912
Auke Kokbc7f75f2007-09-17 12:30:59 -07004913 return NETDEV_TX_OK;
4914}
4915
4916/**
4917 * e1000_tx_timeout - Respond to a Tx Hang
4918 * @netdev: network interface device structure
4919 **/
4920static void e1000_tx_timeout(struct net_device *netdev)
4921{
4922 struct e1000_adapter *adapter = netdev_priv(netdev);
4923
4924 /* Do the reset outside of interrupt context */
4925 adapter->tx_timeout_count++;
4926 schedule_work(&adapter->reset_task);
4927}
4928
4929static void e1000_reset_task(struct work_struct *work)
4930{
4931 struct e1000_adapter *adapter;
4932 adapter = container_of(work, struct e1000_adapter, reset_task);
4933
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004934 /* don't run the task if already down */
4935 if (test_bit(__E1000_DOWN, &adapter->state))
4936 return;
4937
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00004938 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4939 (adapter->flags & FLAG_RX_RESTART_NOW))) {
4940 e1000e_dump(adapter);
4941 e_err("Reset adapter\n");
4942 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004943 e1000e_reinit_locked(adapter);
4944}
4945
4946/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004947 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07004948 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004949 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07004950 *
4951 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004952 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004953struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
4954 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004955{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004956 struct e1000_adapter *adapter = netdev_priv(netdev);
4957
4958 memset(stats, 0, sizeof(struct rtnl_link_stats64));
4959 spin_lock(&adapter->stats64_lock);
4960 e1000e_update_stats(adapter);
4961 /* Fill out the OS statistics structure */
4962 stats->rx_bytes = adapter->stats.gorc;
4963 stats->rx_packets = adapter->stats.gprc;
4964 stats->tx_bytes = adapter->stats.gotc;
4965 stats->tx_packets = adapter->stats.gptc;
4966 stats->multicast = adapter->stats.mprc;
4967 stats->collisions = adapter->stats.colc;
4968
4969 /* Rx Errors */
4970
4971 /*
4972 * RLEC on some newer hardware can be incorrect so build
4973 * our own version based on RUC and ROC
4974 */
4975 stats->rx_errors = adapter->stats.rxerrc +
4976 adapter->stats.crcerrs + adapter->stats.algnerrc +
4977 adapter->stats.ruc + adapter->stats.roc +
4978 adapter->stats.cexterr;
4979 stats->rx_length_errors = adapter->stats.ruc +
4980 adapter->stats.roc;
4981 stats->rx_crc_errors = adapter->stats.crcerrs;
4982 stats->rx_frame_errors = adapter->stats.algnerrc;
4983 stats->rx_missed_errors = adapter->stats.mpc;
4984
4985 /* Tx Errors */
4986 stats->tx_errors = adapter->stats.ecol +
4987 adapter->stats.latecol;
4988 stats->tx_aborted_errors = adapter->stats.ecol;
4989 stats->tx_window_errors = adapter->stats.latecol;
4990 stats->tx_carrier_errors = adapter->stats.tncrs;
4991
4992 /* Tx Dropped needs to be maintained elsewhere */
4993
4994 spin_unlock(&adapter->stats64_lock);
4995 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004996}
4997
4998/**
4999 * e1000_change_mtu - Change the Maximum Transfer Unit
5000 * @netdev: network interface device structure
5001 * @new_mtu: new value for maximum frame size
5002 *
5003 * Returns 0 on success, negative on failure
5004 **/
5005static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5006{
5007 struct e1000_adapter *adapter = netdev_priv(netdev);
5008 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5009
Bruce Allan2adc55c2009-06-02 11:28:58 +00005010 /* Jumbo frame support */
5011 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5012 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5013 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005014 return -EINVAL;
5015 }
5016
Bruce Allan2adc55c2009-06-02 11:28:58 +00005017 /* Supported frame sizes */
5018 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5019 (max_frame > adapter->max_hw_frame_size)) {
5020 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005021 return -EINVAL;
5022 }
5023
Bruce Allana1ce6472010-09-22 17:16:40 +00005024 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5025 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5026 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5027 (new_mtu > ETH_DATA_LEN)) {
5028 e_err("Jumbo Frames not supported on 82579 when CRC "
5029 "stripping is disabled.\n");
5030 return -EINVAL;
5031 }
5032
Bruce Allan6f461f62010-04-27 03:33:04 +00005033 /* 82573 Errata 17 */
5034 if (((adapter->hw.mac.type == e1000_82573) ||
5035 (adapter->hw.mac.type == e1000_82574)) &&
5036 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5037 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5038 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5039 }
5040
Auke Kokbc7f75f2007-09-17 12:30:59 -07005041 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005042 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005043 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005044 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005045 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5046 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005047 if (netif_running(netdev))
5048 e1000e_down(adapter);
5049
Bruce Allanad680762008-03-28 09:15:03 -07005050 /*
5051 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005052 * means we reserve 2 more, this pushes us to allocate from the next
5053 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005054 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005055 * However with the new *_jumbo_rx* routines, jumbo receives will use
5056 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005057 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005058
Jesse Brandeburg99261462010-01-22 22:56:16 +00005059 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005060 adapter->rx_buffer_len = 2048;
5061 else
5062 adapter->rx_buffer_len = 4096;
5063
5064 /* adjust allocation if LPE protects us, and we aren't using SBP */
5065 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5066 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5067 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005068 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005069
Auke Kokbc7f75f2007-09-17 12:30:59 -07005070 if (netif_running(netdev))
5071 e1000e_up(adapter);
5072 else
5073 e1000e_reset(adapter);
5074
5075 clear_bit(__E1000_RESETTING, &adapter->state);
5076
5077 return 0;
5078}
5079
5080static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5081 int cmd)
5082{
5083 struct e1000_adapter *adapter = netdev_priv(netdev);
5084 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005085
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005086 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005087 return -EOPNOTSUPP;
5088
5089 switch (cmd) {
5090 case SIOCGMIIPHY:
5091 data->phy_id = adapter->hw.phy.addr;
5092 break;
5093 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005094 e1000_phy_read_status(adapter);
5095
Bruce Allan7c257692008-04-23 11:09:00 -07005096 switch (data->reg_num & 0x1F) {
5097 case MII_BMCR:
5098 data->val_out = adapter->phy_regs.bmcr;
5099 break;
5100 case MII_BMSR:
5101 data->val_out = adapter->phy_regs.bmsr;
5102 break;
5103 case MII_PHYSID1:
5104 data->val_out = (adapter->hw.phy.id >> 16);
5105 break;
5106 case MII_PHYSID2:
5107 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5108 break;
5109 case MII_ADVERTISE:
5110 data->val_out = adapter->phy_regs.advertise;
5111 break;
5112 case MII_LPA:
5113 data->val_out = adapter->phy_regs.lpa;
5114 break;
5115 case MII_EXPANSION:
5116 data->val_out = adapter->phy_regs.expansion;
5117 break;
5118 case MII_CTRL1000:
5119 data->val_out = adapter->phy_regs.ctrl1000;
5120 break;
5121 case MII_STAT1000:
5122 data->val_out = adapter->phy_regs.stat1000;
5123 break;
5124 case MII_ESTATUS:
5125 data->val_out = adapter->phy_regs.estatus;
5126 break;
5127 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005128 return -EIO;
5129 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005130 break;
5131 case SIOCSMIIREG:
5132 default:
5133 return -EOPNOTSUPP;
5134 }
5135 return 0;
5136}
5137
5138static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5139{
5140 switch (cmd) {
5141 case SIOCGMIIPHY:
5142 case SIOCGMIIREG:
5143 case SIOCSMIIREG:
5144 return e1000_mii_ioctl(netdev, ifr, cmd);
5145 default:
5146 return -EOPNOTSUPP;
5147 }
5148}
5149
Bruce Allana4f58f52009-06-02 11:29:18 +00005150static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5151{
5152 struct e1000_hw *hw = &adapter->hw;
5153 u32 i, mac_reg;
5154 u16 phy_reg;
5155 int retval = 0;
5156
5157 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005158 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005159
5160 /* copy MAC MTA to PHY MTA */
5161 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5162 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5163 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
5164 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
5165 }
5166
5167 /* configure PHY Rx Control register */
5168 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
5169 mac_reg = er32(RCTL);
5170 if (mac_reg & E1000_RCTL_UPE)
5171 phy_reg |= BM_RCTL_UPE;
5172 if (mac_reg & E1000_RCTL_MPE)
5173 phy_reg |= BM_RCTL_MPE;
5174 phy_reg &= ~(BM_RCTL_MO_MASK);
5175 if (mac_reg & E1000_RCTL_MO_3)
5176 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5177 << BM_RCTL_MO_SHIFT);
5178 if (mac_reg & E1000_RCTL_BAM)
5179 phy_reg |= BM_RCTL_BAM;
5180 if (mac_reg & E1000_RCTL_PMCF)
5181 phy_reg |= BM_RCTL_PMCF;
5182 mac_reg = er32(CTRL);
5183 if (mac_reg & E1000_CTRL_RFCE)
5184 phy_reg |= BM_RCTL_RFCE;
5185 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
5186
5187 /* enable PHY wakeup in MAC register */
5188 ew32(WUFC, wufc);
5189 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5190
5191 /* configure and enable PHY wakeup in PHY registers */
5192 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
5193 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5194
5195 /* activate PHY wakeup */
Bruce Allan94d81862009-11-20 23:25:26 +00005196 retval = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005197 if (retval) {
5198 e_err("Could not acquire PHY\n");
5199 return retval;
5200 }
5201 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
5202 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
5203 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
5204 if (retval) {
5205 e_err("Could not read PHY page 769\n");
5206 goto out;
5207 }
5208 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5209 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
5210 if (retval)
5211 e_err("Could not set PHY Host Wakeup bit\n");
5212out:
Bruce Allan94d81862009-11-20 23:25:26 +00005213 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005214
5215 return retval;
5216}
5217
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005218static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5219 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005220{
5221 struct net_device *netdev = pci_get_drvdata(pdev);
5222 struct e1000_adapter *adapter = netdev_priv(netdev);
5223 struct e1000_hw *hw = &adapter->hw;
5224 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005225 /* Runtime suspend should only enable wakeup for link changes */
5226 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005227 int retval = 0;
5228
5229 netif_device_detach(netdev);
5230
5231 if (netif_running(netdev)) {
5232 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5233 e1000e_down(adapter);
5234 e1000_free_irq(adapter);
5235 }
Bruce Allan4662e822008-08-26 18:37:06 -07005236 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005237
5238 retval = pci_save_state(pdev);
5239 if (retval)
5240 return retval;
5241
5242 status = er32(STATUS);
5243 if (status & E1000_STATUS_LU)
5244 wufc &= ~E1000_WUFC_LNKC;
5245
5246 if (wufc) {
5247 e1000_setup_rctl(adapter);
5248 e1000_set_multi(netdev);
5249
5250 /* turn on all-multi mode if wake on multicast is enabled */
5251 if (wufc & E1000_WUFC_MC) {
5252 rctl = er32(RCTL);
5253 rctl |= E1000_RCTL_MPE;
5254 ew32(RCTL, rctl);
5255 }
5256
5257 ctrl = er32(CTRL);
5258 /* advertise wake from D3Cold */
5259 #define E1000_CTRL_ADVD3WUC 0x00100000
5260 /* phy power management enable */
5261 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005262 ctrl |= E1000_CTRL_ADVD3WUC;
5263 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5264 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005265 ew32(CTRL, ctrl);
5266
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005267 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5268 adapter->hw.phy.media_type ==
5269 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005270 /* keep the laser running in D3 */
5271 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005272 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005273 ew32(CTRL_EXT, ctrl_ext);
5274 }
5275
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005276 if (adapter->flags & FLAG_IS_ICH)
5277 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
5278
Auke Kokbc7f75f2007-09-17 12:30:59 -07005279 /* Allow time for pending master requests to run */
5280 e1000e_disable_pcie_master(&adapter->hw);
5281
Bruce Allan82776a42009-08-14 14:35:33 +00005282 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005283 /* enable wakeup by the PHY */
5284 retval = e1000_init_phy_wakeup(adapter, wufc);
5285 if (retval)
5286 return retval;
5287 } else {
5288 /* enable wakeup by the MAC */
5289 ew32(WUFC, wufc);
5290 ew32(WUC, E1000_WUC_PME_EN);
5291 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005292 } else {
5293 ew32(WUC, 0);
5294 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005295 }
5296
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005297 *enable_wake = !!wufc;
5298
Auke Kokbc7f75f2007-09-17 12:30:59 -07005299 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005300 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5301 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005302 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005303
5304 if (adapter->hw.phy.type == e1000_phy_igp_3)
5305 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5306
Bruce Allanad680762008-03-28 09:15:03 -07005307 /*
5308 * Release control of h/w to f/w. If f/w is AMT enabled, this
5309 * would have already happened in close and is redundant.
5310 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005311 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005312
5313 pci_disable_device(pdev);
5314
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005315 return 0;
5316}
5317
5318static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5319{
5320 if (sleep && wake) {
5321 pci_prepare_to_sleep(pdev);
5322 return;
5323 }
5324
5325 pci_wake_from_d3(pdev, wake);
5326 pci_set_power_state(pdev, PCI_D3hot);
5327}
5328
5329static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5330 bool wake)
5331{
5332 struct net_device *netdev = pci_get_drvdata(pdev);
5333 struct e1000_adapter *adapter = netdev_priv(netdev);
5334
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005335 /*
5336 * The pci-e switch on some quad port adapters will report a
5337 * correctable error when the MAC transitions from D0 to D3. To
5338 * prevent this we need to mask off the correctable errors on the
5339 * downstream port of the pci-e switch.
5340 */
5341 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5342 struct pci_dev *us_dev = pdev->bus->self;
5343 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
5344 u16 devctl;
5345
5346 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5347 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5348 (devctl & ~PCI_EXP_DEVCTL_CERE));
5349
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005350 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005351
5352 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5353 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005354 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005355 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005356}
5357
Bruce Allan6f461f62010-04-27 03:33:04 +00005358#ifdef CONFIG_PCIEASPM
5359static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5360{
5361 pci_disable_link_state(pdev, state);
5362}
5363#else
5364static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005365{
5366 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005367 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005368
5369 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005370 * Both device and parent should have the same ASPM setting.
5371 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005372 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005373 pos = pci_pcie_cap(pdev);
5374 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5375 reg16 &= ~state;
5376 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5377
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005378 if (!pdev->bus->self)
5379 return;
5380
Bruce Allan6f461f62010-04-27 03:33:04 +00005381 pos = pci_pcie_cap(pdev->bus->self);
5382 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5383 reg16 &= ~state;
5384 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5385}
5386#endif
5387void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5388{
5389 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5390 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5391 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5392
5393 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005394}
5395
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005396#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005397static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005398{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005399 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005400}
5401
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005402static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005403{
5404 struct net_device *netdev = pci_get_drvdata(pdev);
5405 struct e1000_adapter *adapter = netdev_priv(netdev);
5406 struct e1000_hw *hw = &adapter->hw;
5407 u32 err;
5408
5409 pci_set_power_state(pdev, PCI_D0);
5410 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005411 pci_save_state(pdev);
Bruce Allan6f461f62010-04-27 03:33:04 +00005412 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5413 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005414
Bruce Allan4662e822008-08-26 18:37:06 -07005415 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005416 if (netif_running(netdev)) {
5417 err = e1000_request_irq(adapter);
5418 if (err)
5419 return err;
5420 }
5421
5422 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005423
5424 /* report the system wakeup cause from S3/S4 */
5425 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5426 u16 phy_data;
5427
5428 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5429 if (phy_data) {
5430 e_info("PHY Wakeup cause - %s\n",
5431 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5432 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5433 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5434 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5435 phy_data & E1000_WUS_LNKC ? "Link Status "
5436 " Change" : "other");
5437 }
5438 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5439 } else {
5440 u32 wus = er32(WUS);
5441 if (wus) {
5442 e_info("MAC Wakeup cause - %s\n",
5443 wus & E1000_WUS_EX ? "Unicast Packet" :
5444 wus & E1000_WUS_MC ? "Multicast Packet" :
5445 wus & E1000_WUS_BC ? "Broadcast Packet" :
5446 wus & E1000_WUS_MAG ? "Magic Packet" :
5447 wus & E1000_WUS_LNKC ? "Link Status Change" :
5448 "other");
5449 }
5450 ew32(WUS, ~0);
5451 }
5452
Auke Kokbc7f75f2007-09-17 12:30:59 -07005453 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005454
Bruce Allancd791612010-05-10 14:59:51 +00005455 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005456
5457 if (netif_running(netdev))
5458 e1000e_up(adapter);
5459
5460 netif_device_attach(netdev);
5461
Bruce Allanad680762008-03-28 09:15:03 -07005462 /*
5463 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005464 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005465 * under the control of the driver.
5466 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005467 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005468 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005469
5470 return 0;
5471}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005472
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005473#ifdef CONFIG_PM_SLEEP
5474static int e1000_suspend(struct device *dev)
5475{
5476 struct pci_dev *pdev = to_pci_dev(dev);
5477 int retval;
5478 bool wake;
5479
5480 retval = __e1000_shutdown(pdev, &wake, false);
5481 if (!retval)
5482 e1000_complete_shutdown(pdev, true, wake);
5483
5484 return retval;
5485}
5486
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005487static int e1000_resume(struct device *dev)
5488{
5489 struct pci_dev *pdev = to_pci_dev(dev);
5490 struct net_device *netdev = pci_get_drvdata(pdev);
5491 struct e1000_adapter *adapter = netdev_priv(netdev);
5492
5493 if (e1000e_pm_ready(adapter))
5494 adapter->idle_check = true;
5495
5496 return __e1000_resume(pdev);
5497}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005498#endif /* CONFIG_PM_SLEEP */
5499
5500#ifdef CONFIG_PM_RUNTIME
5501static int e1000_runtime_suspend(struct device *dev)
5502{
5503 struct pci_dev *pdev = to_pci_dev(dev);
5504 struct net_device *netdev = pci_get_drvdata(pdev);
5505 struct e1000_adapter *adapter = netdev_priv(netdev);
5506
5507 if (e1000e_pm_ready(adapter)) {
5508 bool wake;
5509
5510 __e1000_shutdown(pdev, &wake, true);
5511 }
5512
5513 return 0;
5514}
5515
5516static int e1000_idle(struct device *dev)
5517{
5518 struct pci_dev *pdev = to_pci_dev(dev);
5519 struct net_device *netdev = pci_get_drvdata(pdev);
5520 struct e1000_adapter *adapter = netdev_priv(netdev);
5521
5522 if (!e1000e_pm_ready(adapter))
5523 return 0;
5524
5525 if (adapter->idle_check) {
5526 adapter->idle_check = false;
5527 if (!e1000e_has_link(adapter))
5528 pm_schedule_suspend(dev, MSEC_PER_SEC);
5529 }
5530
5531 return -EBUSY;
5532}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005533
5534static int e1000_runtime_resume(struct device *dev)
5535{
5536 struct pci_dev *pdev = to_pci_dev(dev);
5537 struct net_device *netdev = pci_get_drvdata(pdev);
5538 struct e1000_adapter *adapter = netdev_priv(netdev);
5539
5540 if (!e1000e_pm_ready(adapter))
5541 return 0;
5542
5543 adapter->idle_check = !dev->power.runtime_auto;
5544 return __e1000_resume(pdev);
5545}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005546#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005547#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005548
5549static void e1000_shutdown(struct pci_dev *pdev)
5550{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005551 bool wake = false;
5552
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005553 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005554
5555 if (system_state == SYSTEM_POWER_OFF)
5556 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005557}
5558
5559#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005560
5561static irqreturn_t e1000_intr_msix(int irq, void *data)
5562{
5563 struct net_device *netdev = data;
5564 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005565
5566 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005567 int vector, msix_irq;
5568
Dongdong Deng147b2c82010-11-16 19:50:15 -08005569 vector = 0;
5570 msix_irq = adapter->msix_entries[vector].vector;
5571 disable_irq(msix_irq);
5572 e1000_intr_msix_rx(msix_irq, netdev);
5573 enable_irq(msix_irq);
5574
5575 vector++;
5576 msix_irq = adapter->msix_entries[vector].vector;
5577 disable_irq(msix_irq);
5578 e1000_intr_msix_tx(msix_irq, netdev);
5579 enable_irq(msix_irq);
5580
5581 vector++;
5582 msix_irq = adapter->msix_entries[vector].vector;
5583 disable_irq(msix_irq);
5584 e1000_msix_other(msix_irq, netdev);
5585 enable_irq(msix_irq);
5586 }
5587
5588 return IRQ_HANDLED;
5589}
5590
Auke Kokbc7f75f2007-09-17 12:30:59 -07005591/*
5592 * Polling 'interrupt' - used by things like netconsole to send skbs
5593 * without having to re-enable interrupts. It's not called while
5594 * the interrupt routine is executing.
5595 */
5596static void e1000_netpoll(struct net_device *netdev)
5597{
5598 struct e1000_adapter *adapter = netdev_priv(netdev);
5599
Dongdong Deng147b2c82010-11-16 19:50:15 -08005600 switch (adapter->int_mode) {
5601 case E1000E_INT_MODE_MSIX:
5602 e1000_intr_msix(adapter->pdev->irq, netdev);
5603 break;
5604 case E1000E_INT_MODE_MSI:
5605 disable_irq(adapter->pdev->irq);
5606 e1000_intr_msi(adapter->pdev->irq, netdev);
5607 enable_irq(adapter->pdev->irq);
5608 break;
5609 default: /* E1000E_INT_MODE_LEGACY */
5610 disable_irq(adapter->pdev->irq);
5611 e1000_intr(adapter->pdev->irq, netdev);
5612 enable_irq(adapter->pdev->irq);
5613 break;
5614 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005615}
5616#endif
5617
5618/**
5619 * e1000_io_error_detected - called when PCI error is detected
5620 * @pdev: Pointer to PCI device
5621 * @state: The current pci connection state
5622 *
5623 * This function is called after a PCI bus error affecting
5624 * this device has been detected.
5625 */
5626static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5627 pci_channel_state_t state)
5628{
5629 struct net_device *netdev = pci_get_drvdata(pdev);
5630 struct e1000_adapter *adapter = netdev_priv(netdev);
5631
5632 netif_device_detach(netdev);
5633
Mike Masonc93b5a72009-06-30 12:45:53 +00005634 if (state == pci_channel_io_perm_failure)
5635 return PCI_ERS_RESULT_DISCONNECT;
5636
Auke Kokbc7f75f2007-09-17 12:30:59 -07005637 if (netif_running(netdev))
5638 e1000e_down(adapter);
5639 pci_disable_device(pdev);
5640
5641 /* Request a slot slot reset. */
5642 return PCI_ERS_RESULT_NEED_RESET;
5643}
5644
5645/**
5646 * e1000_io_slot_reset - called after the pci bus has been reset.
5647 * @pdev: Pointer to PCI device
5648 *
5649 * Restart the card from scratch, as if from a cold-boot. Implementation
5650 * resembles the first-half of the e1000_resume routine.
5651 */
5652static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5653{
5654 struct net_device *netdev = pci_get_drvdata(pdev);
5655 struct e1000_adapter *adapter = netdev_priv(netdev);
5656 struct e1000_hw *hw = &adapter->hw;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005657 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005658 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005659
Bruce Allan6f461f62010-04-27 03:33:04 +00005660 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5661 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Bruce Allanf0f422e2008-08-04 17:21:53 -07005662 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005663 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005664 dev_err(&pdev->dev,
5665 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005666 result = PCI_ERS_RESULT_DISCONNECT;
5667 } else {
5668 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005669 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005670 pci_restore_state(pdev);
5671
5672 pci_enable_wake(pdev, PCI_D3hot, 0);
5673 pci_enable_wake(pdev, PCI_D3cold, 0);
5674
5675 e1000e_reset(adapter);
5676 ew32(WUS, ~0);
5677 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005678 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005679
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005680 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005681
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005682 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005683}
5684
5685/**
5686 * e1000_io_resume - called when traffic can start flowing again.
5687 * @pdev: Pointer to PCI device
5688 *
5689 * This callback is called when the error recovery driver tells us that
5690 * its OK to resume normal operation. Implementation resembles the
5691 * second-half of the e1000_resume routine.
5692 */
5693static void e1000_io_resume(struct pci_dev *pdev)
5694{
5695 struct net_device *netdev = pci_get_drvdata(pdev);
5696 struct e1000_adapter *adapter = netdev_priv(netdev);
5697
Bruce Allancd791612010-05-10 14:59:51 +00005698 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005699
5700 if (netif_running(netdev)) {
5701 if (e1000e_up(adapter)) {
5702 dev_err(&pdev->dev,
5703 "can't bring device back up after reset\n");
5704 return;
5705 }
5706 }
5707
5708 netif_device_attach(netdev);
5709
Bruce Allanad680762008-03-28 09:15:03 -07005710 /*
5711 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005712 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005713 * under the control of the driver.
5714 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005715 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005716 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005717
5718}
5719
5720static void e1000_print_device_info(struct e1000_adapter *adapter)
5721{
5722 struct e1000_hw *hw = &adapter->hw;
5723 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005724 u32 ret_val;
5725 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005726
5727 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005728 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005729 /* bus width */
5730 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5731 "Width x1"),
5732 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005733 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005734 e_info("Intel(R) PRO/%s Network Connection\n",
5735 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005736 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5737 E1000_PBANUM_LENGTH);
5738 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005739 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005740 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5741 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005742}
5743
Auke Kok10aa4c02008-08-04 17:21:20 -07005744static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5745{
5746 struct e1000_hw *hw = &adapter->hw;
5747 int ret_val;
5748 u16 buf = 0;
5749
5750 if (hw->mac.type != e1000_82573)
5751 return;
5752
5753 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005754 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005755 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005756 dev_warn(&adapter->pdev->dev,
5757 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005758 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005759}
5760
Stephen Hemminger651c2462008-11-19 21:57:48 -08005761static const struct net_device_ops e1000e_netdev_ops = {
5762 .ndo_open = e1000_open,
5763 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005764 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005765 .ndo_get_stats64 = e1000e_get_stats64,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005766 .ndo_set_multicast_list = e1000_set_multi,
5767 .ndo_set_mac_address = e1000_set_mac,
5768 .ndo_change_mtu = e1000_change_mtu,
5769 .ndo_do_ioctl = e1000_ioctl,
5770 .ndo_tx_timeout = e1000_tx_timeout,
5771 .ndo_validate_addr = eth_validate_addr,
5772
Stephen Hemminger651c2462008-11-19 21:57:48 -08005773 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5774 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5775#ifdef CONFIG_NET_POLL_CONTROLLER
5776 .ndo_poll_controller = e1000_netpoll,
5777#endif
5778};
5779
Auke Kokbc7f75f2007-09-17 12:30:59 -07005780/**
5781 * e1000_probe - Device Initialization Routine
5782 * @pdev: PCI device information struct
5783 * @ent: entry in e1000_pci_tbl
5784 *
5785 * Returns 0 on success, negative on failure
5786 *
5787 * e1000_probe initializes an adapter identified by a pci_dev structure.
5788 * The OS initialization, configuring of the adapter private structure,
5789 * and a hardware reset occur.
5790 **/
5791static int __devinit e1000_probe(struct pci_dev *pdev,
5792 const struct pci_device_id *ent)
5793{
5794 struct net_device *netdev;
5795 struct e1000_adapter *adapter;
5796 struct e1000_hw *hw;
5797 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005798 resource_size_t mmio_start, mmio_len;
5799 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005800
5801 static int cards_found;
5802 int i, err, pci_using_dac;
5803 u16 eeprom_data = 0;
5804 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5805
Bruce Allan6f461f62010-04-27 03:33:04 +00005806 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
5807 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005808
Bruce Allanf0f422e2008-08-04 17:21:53 -07005809 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005810 if (err)
5811 return err;
5812
5813 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005814 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005815 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005816 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005817 if (!err)
5818 pci_using_dac = 1;
5819 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005820 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005821 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005822 err = dma_set_coherent_mask(&pdev->dev,
5823 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005824 if (err) {
5825 dev_err(&pdev->dev, "No usable DMA "
5826 "configuration, aborting\n");
5827 goto err_dma;
5828 }
5829 }
5830 }
5831
Arjan van de Vene8de1482008-10-22 19:55:31 -07005832 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005833 pci_select_bars(pdev, IORESOURCE_MEM),
5834 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005835 if (err)
5836 goto err_pci_reg;
5837
Xiaotian Feng68eac462009-08-14 14:35:52 +00005838 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005839 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005840
Auke Kokbc7f75f2007-09-17 12:30:59 -07005841 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005842 /* PCI config space info */
5843 err = pci_save_state(pdev);
5844 if (err)
5845 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005846
5847 err = -ENOMEM;
5848 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5849 if (!netdev)
5850 goto err_alloc_etherdev;
5851
Auke Kokbc7f75f2007-09-17 12:30:59 -07005852 SET_NETDEV_DEV(netdev, &pdev->dev);
5853
Tom Herbertf85e4df2010-05-05 14:03:32 +00005854 netdev->irq = pdev->irq;
5855
Auke Kokbc7f75f2007-09-17 12:30:59 -07005856 pci_set_drvdata(pdev, netdev);
5857 adapter = netdev_priv(netdev);
5858 hw = &adapter->hw;
5859 adapter->netdev = netdev;
5860 adapter->pdev = pdev;
5861 adapter->ei = ei;
5862 adapter->pba = ei->pba;
5863 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005864 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005865 adapter->hw.adapter = adapter;
5866 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005867 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005868 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5869
5870 mmio_start = pci_resource_start(pdev, 0);
5871 mmio_len = pci_resource_len(pdev, 0);
5872
5873 err = -EIO;
5874 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5875 if (!adapter->hw.hw_addr)
5876 goto err_ioremap;
5877
5878 if ((adapter->flags & FLAG_HAS_FLASH) &&
5879 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5880 flash_start = pci_resource_start(pdev, 1);
5881 flash_len = pci_resource_len(pdev, 1);
5882 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5883 if (!adapter->hw.flash_address)
5884 goto err_flashmap;
5885 }
5886
5887 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005888 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005889 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005890 netdev->watchdog_timeo = 5 * HZ;
5891 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005892 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5893
5894 netdev->mem_start = mmio_start;
5895 netdev->mem_end = mmio_start + mmio_len;
5896
5897 adapter->bd_number = cards_found++;
5898
Bruce Allan4662e822008-08-26 18:37:06 -07005899 e1000e_check_options(adapter);
5900
Auke Kokbc7f75f2007-09-17 12:30:59 -07005901 /* setup adapter struct */
5902 err = e1000_sw_init(adapter);
5903 if (err)
5904 goto err_sw_init;
5905
Auke Kokbc7f75f2007-09-17 12:30:59 -07005906 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5907 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5908 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5909
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005910 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005911 if (err)
5912 goto err_hw_init;
5913
Bruce Allan4a770352008-10-01 17:18:35 -07005914 if ((adapter->flags & FLAG_IS_ICH) &&
5915 (adapter->flags & FLAG_READ_ONLY_NVM))
5916 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5917
Auke Kokbc7f75f2007-09-17 12:30:59 -07005918 hw->mac.ops.get_bus_info(&adapter->hw);
5919
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005920 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005921
5922 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005923 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005924 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5925 adapter->hw.phy.disable_polarity_correction = 0;
5926 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5927 }
5928
5929 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005930 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005931
5932 netdev->features = NETIF_F_SG |
5933 NETIF_F_HW_CSUM |
5934 NETIF_F_HW_VLAN_TX |
5935 NETIF_F_HW_VLAN_RX;
5936
5937 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5938 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5939
5940 netdev->features |= NETIF_F_TSO;
5941 netdev->features |= NETIF_F_TSO6;
5942
Jeff Kirshera5136e22008-06-05 04:07:28 -07005943 netdev->vlan_features |= NETIF_F_TSO;
5944 netdev->vlan_features |= NETIF_F_TSO6;
5945 netdev->vlan_features |= NETIF_F_HW_CSUM;
5946 netdev->vlan_features |= NETIF_F_SG;
5947
Yi Zou7b872a52010-09-22 17:57:58 +00005948 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005949 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00005950 netdev->vlan_features |= NETIF_F_HIGHDMA;
5951 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005952
Auke Kokbc7f75f2007-09-17 12:30:59 -07005953 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5954 adapter->flags |= FLAG_MNG_PT_ENABLED;
5955
Bruce Allanad680762008-03-28 09:15:03 -07005956 /*
5957 * before reading the NVM, reset the controller to
5958 * put the device in a known good starting state
5959 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005960 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5961
5962 /*
5963 * systems with ASPM and others may see the checksum fail on the first
5964 * attempt. Let's give it a few tries
5965 */
5966 for (i = 0;; i++) {
5967 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5968 break;
5969 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005970 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005971 err = -EIO;
5972 goto err_eeprom;
5973 }
5974 }
5975
Auke Kok10aa4c02008-08-04 17:21:20 -07005976 e1000_eeprom_checks(adapter);
5977
Bruce Allan608f8a02010-01-13 02:04:58 +00005978 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005979 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005980 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005981
5982 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5983 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5984
5985 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07005986 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005987 err = -EIO;
5988 goto err_eeprom;
5989 }
5990
5991 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005992 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005993 adapter->watchdog_timer.data = (unsigned long) adapter;
5994
5995 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005996 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005997 adapter->phy_info_timer.data = (unsigned long) adapter;
5998
5999 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6000 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006001 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6002 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006003 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Holger Eitzenberger9633e632010-11-17 15:43:52 +00006004 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006005
Auke Kokbc7f75f2007-09-17 12:30:59 -07006006 /* Initialize link parameters. User can change them with ethtool */
6007 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07006008 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006009 adapter->hw.fc.requested_mode = e1000_fc_default;
6010 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006011 adapter->hw.phy.autoneg_advertised = 0x2f;
6012
6013 /* ring size defaults */
6014 adapter->rx_ring->count = 256;
6015 adapter->tx_ring->count = 256;
6016
6017 /*
6018 * Initial Wake on LAN setting - If APM wake is enabled in
6019 * the EEPROM, enable the ACPI Magic Packet filter
6020 */
6021 if (adapter->flags & FLAG_APME_IN_WUC) {
6022 /* APME bit in EEPROM is mapped to WUC.APME */
6023 eeprom_data = er32(WUC);
6024 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006025 if ((hw->mac.type > e1000_ich10lan) &&
6026 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006027 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006028 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6029 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6030 (adapter->hw.bus.func == 1))
6031 e1000_read_nvm(&adapter->hw,
6032 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6033 else
6034 e1000_read_nvm(&adapter->hw,
6035 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6036 }
6037
6038 /* fetch WoL from EEPROM */
6039 if (eeprom_data & eeprom_apme_mask)
6040 adapter->eeprom_wol |= E1000_WUFC_MAG;
6041
6042 /*
6043 * now that we have the eeprom settings, apply the special cases
6044 * where the eeprom may be wrong or the board simply won't support
6045 * wake on lan on a particular port
6046 */
6047 if (!(adapter->flags & FLAG_HAS_WOL))
6048 adapter->eeprom_wol = 0;
6049
6050 /* initialize the wol settings based on the eeprom settings */
6051 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006052 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006053
Bruce Allan84527592008-11-21 17:00:22 -08006054 /* save off EEPROM version number */
6055 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6056
Auke Kokbc7f75f2007-09-17 12:30:59 -07006057 /* reset the hardware with the new settings */
6058 e1000e_reset(adapter);
6059
Bruce Allanad680762008-03-28 09:15:03 -07006060 /*
6061 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006062 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006063 * under the control of the driver.
6064 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006065 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006066 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006067
Bruce Allane0dc4f12011-01-06 14:29:50 +00006068 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006069 err = register_netdev(netdev);
6070 if (err)
6071 goto err_register;
6072
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006073 /* carrier off reporting is important to ethtool even BEFORE open */
6074 netif_carrier_off(netdev);
6075
Auke Kokbc7f75f2007-09-17 12:30:59 -07006076 e1000_print_device_info(adapter);
6077
Alan Sternf3ec4f82010-06-08 15:23:51 -04006078 if (pci_dev_run_wake(pdev))
6079 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006080
Auke Kokbc7f75f2007-09-17 12:30:59 -07006081 return 0;
6082
6083err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006084 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006085 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006086err_eeprom:
6087 if (!e1000_check_reset_block(&adapter->hw))
6088 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006089err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006090 kfree(adapter->tx_ring);
6091 kfree(adapter->rx_ring);
6092err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006093 if (adapter->hw.flash_address)
6094 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006095 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006096err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006097 iounmap(adapter->hw.hw_addr);
6098err_ioremap:
6099 free_netdev(netdev);
6100err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006101 pci_release_selected_regions(pdev,
6102 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006103err_pci_reg:
6104err_dma:
6105 pci_disable_device(pdev);
6106 return err;
6107}
6108
6109/**
6110 * e1000_remove - Device Removal Routine
6111 * @pdev: PCI device information struct
6112 *
6113 * e1000_remove is called by the PCI subsystem to alert the driver
6114 * that it should release a PCI device. The could be caused by a
6115 * Hot-Plug event, or because the driver is going to be removed from
6116 * memory.
6117 **/
6118static void __devexit e1000_remove(struct pci_dev *pdev)
6119{
6120 struct net_device *netdev = pci_get_drvdata(pdev);
6121 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006122 bool down = test_bit(__E1000_DOWN, &adapter->state);
6123
Bruce Allanad680762008-03-28 09:15:03 -07006124 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006125 * The timers may be rescheduled, so explicitly disable them
6126 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006127 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006128 if (!down)
6129 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006130 del_timer_sync(&adapter->watchdog_timer);
6131 del_timer_sync(&adapter->phy_info_timer);
6132
Bruce Allan41cec6f2009-11-20 23:28:56 +00006133 cancel_work_sync(&adapter->reset_task);
6134 cancel_work_sync(&adapter->watchdog_task);
6135 cancel_work_sync(&adapter->downshift_task);
6136 cancel_work_sync(&adapter->update_phy_task);
Tejun Heo23f333a2010-12-12 16:45:14 +01006137 cancel_work_sync(&adapter->led_blink_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006138 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006139
Bruce Allan17f208d2009-12-01 15:47:22 +00006140 if (!(netdev->flags & IFF_UP))
6141 e1000_power_down_phy(adapter);
6142
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006143 /* Don't lie to e1000_close() down the road. */
6144 if (!down)
6145 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006146 unregister_netdev(netdev);
6147
Alan Sternf3ec4f82010-06-08 15:23:51 -04006148 if (pci_dev_run_wake(pdev))
6149 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006150
Bruce Allanad680762008-03-28 09:15:03 -07006151 /*
6152 * Release control of h/w to f/w. If f/w is AMT enabled, this
6153 * would have already happened in close and is redundant.
6154 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006155 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006156
Bruce Allan4662e822008-08-26 18:37:06 -07006157 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006158 kfree(adapter->tx_ring);
6159 kfree(adapter->rx_ring);
6160
6161 iounmap(adapter->hw.hw_addr);
6162 if (adapter->hw.flash_address)
6163 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006164 pci_release_selected_regions(pdev,
6165 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006166
6167 free_netdev(netdev);
6168
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006169 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006170 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006171
Auke Kokbc7f75f2007-09-17 12:30:59 -07006172 pci_disable_device(pdev);
6173}
6174
6175/* PCI Error Recovery (ERS) */
6176static struct pci_error_handlers e1000_err_handler = {
6177 .error_detected = e1000_io_error_detected,
6178 .slot_reset = e1000_io_slot_reset,
6179 .resume = e1000_io_resume,
6180};
6181
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006182static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006183 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6184 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6185 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6186 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6187 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6188 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006189 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6190 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6191 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006192
Auke Kokbc7f75f2007-09-17 12:30:59 -07006193 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6194 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6195 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6196 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006197
Auke Kokbc7f75f2007-09-17 12:30:59 -07006198 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6199 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6200 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006201
Bruce Allan4662e822008-08-26 18:37:06 -07006202 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006203 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006204 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006205
Auke Kokbc7f75f2007-09-17 12:30:59 -07006206 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6207 board_80003es2lan },
6208 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6209 board_80003es2lan },
6210 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6211 board_80003es2lan },
6212 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6213 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006214
Auke Kokbc7f75f2007-09-17 12:30:59 -07006215 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6216 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6217 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6218 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6219 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6220 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6221 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006222 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006223
Auke Kokbc7f75f2007-09-17 12:30:59 -07006224 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6225 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6226 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6227 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6228 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006229 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006230 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6231 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6232 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6233
6234 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6235 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6236 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006237
Bruce Allanf4187b52008-08-26 18:36:50 -07006238 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6239 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006240 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006241
Bruce Allana4f58f52009-06-02 11:29:18 +00006242 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6243 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6244 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6245 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6246
Bruce Alland3738bb2010-06-16 13:27:28 +00006247 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6248 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6249
Auke Kokbc7f75f2007-09-17 12:30:59 -07006250 { } /* terminate list */
6251};
6252MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6253
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006254#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006255static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006256 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6257 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6258 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006259};
David S. Millere50208a2010-03-16 23:36:24 -07006260#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006261
Auke Kokbc7f75f2007-09-17 12:30:59 -07006262/* PCI Device API Driver */
6263static struct pci_driver e1000_driver = {
6264 .name = e1000e_driver_name,
6265 .id_table = e1000_pci_tbl,
6266 .probe = e1000_probe,
6267 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006268#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006269 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006270#endif
6271 .shutdown = e1000_shutdown,
6272 .err_handler = &e1000_err_handler
6273};
6274
6275/**
6276 * e1000_init_module - Driver Registration Routine
6277 *
6278 * e1000_init_module is the first routine called when the driver is
6279 * loaded. All it does is register with the PCI subsystem.
6280 **/
6281static int __init e1000_init_module(void)
6282{
6283 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006284 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6285 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006286 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006287 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006288
Auke Kokbc7f75f2007-09-17 12:30:59 -07006289 return ret;
6290}
6291module_init(e1000_init_module);
6292
6293/**
6294 * e1000_exit_module - Driver Exit Cleanup Routine
6295 *
6296 * e1000_exit_module is called just before the driver is removed
6297 * from memory.
6298 **/
6299static void __exit e1000_exit_module(void)
6300{
6301 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006302}
6303module_exit(e1000_exit_module);
6304
6305
6306MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6307MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6308MODULE_LICENSE("GPL");
6309MODULE_VERSION(DRV_VERSION);
6310
6311/* e1000_main.c */