blob: 5b916b01805fe4153059d7d3415910fcb32cffe5 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allan8544b9f2010-03-24 12:55:30 +000029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/vmalloc.h>
36#include <linux/pagemap.h>
37#include <linux/delay.h>
38#include <linux/netdevice.h>
39#include <linux/tcp.h>
40#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/mii.h>
45#include <linux/ethtool.h>
46#include <linux/if_vlan.h>
47#include <linux/cpu.h>
48#include <linux/smp.h>
Bruce Allan97ac8ca2008-04-29 09:16:05 -070049#include <linux/pm_qos_params.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000050#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000051#include <linux/aer.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070052
53#include "e1000.h"
54
Bruce Allanc14c6432010-06-16 13:28:34 +000055#define DRV_EXTRAVERSION "-k2"
56
Bruce Allanc920aa82010-12-01 08:45:24 +000057#define DRV_VERSION "1.2.20" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070058char e1000e_driver_name[] = "e1000e";
59const char e1000e_driver_version[] = DRV_VERSION;
60
61static const struct e1000_info *e1000_info_tbl[] = {
62 [board_82571] = &e1000_82571_info,
63 [board_82572] = &e1000_82572_info,
64 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070065 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000066 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070067 [board_80003es2lan] = &e1000_es2_info,
68 [board_ich8lan] = &e1000_ich8_info,
69 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070070 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000071 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000072 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070073};
74
Taku Izumi84f4ee92010-04-27 14:39:08 +000075struct e1000_reg_info {
76 u32 ofs;
77 char *name;
78};
79
Bruce Allanaf667a22010-12-31 06:10:01 +000080#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
81#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
82#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
83#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
84#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000085
Bruce Allanaf667a22010-12-31 06:10:01 +000086#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
87#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
88#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
89#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
90#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000091
92static const struct e1000_reg_info e1000_reg_info_tbl[] = {
93
94 /* General Registers */
95 {E1000_CTRL, "CTRL"},
96 {E1000_STATUS, "STATUS"},
97 {E1000_CTRL_EXT, "CTRL_EXT"},
98
99 /* Interrupt Registers */
100 {E1000_ICR, "ICR"},
101
Bruce Allanaf667a22010-12-31 06:10:01 +0000102 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000103 {E1000_RCTL, "RCTL"},
104 {E1000_RDLEN, "RDLEN"},
105 {E1000_RDH, "RDH"},
106 {E1000_RDT, "RDT"},
107 {E1000_RDTR, "RDTR"},
108 {E1000_RXDCTL(0), "RXDCTL"},
109 {E1000_ERT, "ERT"},
110 {E1000_RDBAL, "RDBAL"},
111 {E1000_RDBAH, "RDBAH"},
112 {E1000_RDFH, "RDFH"},
113 {E1000_RDFT, "RDFT"},
114 {E1000_RDFHS, "RDFHS"},
115 {E1000_RDFTS, "RDFTS"},
116 {E1000_RDFPC, "RDFPC"},
117
Bruce Allanaf667a22010-12-31 06:10:01 +0000118 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000119 {E1000_TCTL, "TCTL"},
120 {E1000_TDBAL, "TDBAL"},
121 {E1000_TDBAH, "TDBAH"},
122 {E1000_TDLEN, "TDLEN"},
123 {E1000_TDH, "TDH"},
124 {E1000_TDT, "TDT"},
125 {E1000_TIDV, "TIDV"},
126 {E1000_TXDCTL(0), "TXDCTL"},
127 {E1000_TADV, "TADV"},
128 {E1000_TARC(0), "TARC"},
129 {E1000_TDFH, "TDFH"},
130 {E1000_TDFT, "TDFT"},
131 {E1000_TDFHS, "TDFHS"},
132 {E1000_TDFTS, "TDFTS"},
133 {E1000_TDFPC, "TDFPC"},
134
135 /* List Terminator */
136 {}
137};
138
139/*
140 * e1000_regdump - register printout routine
141 */
142static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
143{
144 int n = 0;
145 char rname[16];
146 u32 regs[8];
147
148 switch (reginfo->ofs) {
149 case E1000_RXDCTL(0):
150 for (n = 0; n < 2; n++)
151 regs[n] = __er32(hw, E1000_RXDCTL(n));
152 break;
153 case E1000_TXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_TXDCTL(n));
156 break;
157 case E1000_TARC(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TARC(n));
160 break;
161 default:
162 printk(KERN_INFO "%-15s %08x\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000163 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000164 return;
165 }
166
167 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
168 printk(KERN_INFO "%-15s ", rname);
169 for (n = 0; n < 2; n++)
170 printk(KERN_CONT "%08x ", regs[n]);
171 printk(KERN_CONT "\n");
172}
173
Taku Izumi84f4ee92010-04-27 14:39:08 +0000174/*
Bruce Allanaf667a22010-12-31 06:10:01 +0000175 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Taku Izumi84f4ee92010-04-27 14:39:08 +0000176 */
177static void e1000e_dump(struct e1000_adapter *adapter)
178{
179 struct net_device *netdev = adapter->netdev;
180 struct e1000_hw *hw = &adapter->hw;
181 struct e1000_reg_info *reginfo;
182 struct e1000_ring *tx_ring = adapter->tx_ring;
183 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000184 struct my_u0 {
185 u64 a;
186 u64 b;
187 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000188 struct e1000_buffer *buffer_info;
189 struct e1000_ring *rx_ring = adapter->rx_ring;
190 union e1000_rx_desc_packet_split *rx_desc_ps;
191 struct e1000_rx_desc *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000192 struct my_u1 {
193 u64 a;
194 u64 b;
195 u64 c;
196 u64 d;
197 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000198 u32 staterr;
199 int i = 0;
200
201 if (!netif_msg_hw(adapter))
202 return;
203
204 /* Print netdevice Info */
205 if (netdev) {
206 dev_info(&adapter->pdev->dev, "Net device Info\n");
207 printk(KERN_INFO "Device Name state "
Bruce Allanaf667a22010-12-31 06:10:01 +0000208 "trans_start last_rx\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000209 printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000210 netdev->name, netdev->state, netdev->trans_start,
211 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000212 }
213
214 /* Print Registers */
215 dev_info(&adapter->pdev->dev, "Register Dump\n");
216 printk(KERN_INFO " Register Name Value\n");
217 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
218 reginfo->name; reginfo++) {
219 e1000_regdump(hw, reginfo);
220 }
221
Bruce Allanaf667a22010-12-31 06:10:01 +0000222 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000223 if (!netdev || !netif_running(netdev))
224 goto exit;
225
Bruce Allanaf667a22010-12-31 06:10:01 +0000226 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000227 printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000228 " leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000229 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
230 printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000231 0, tx_ring->next_to_use, tx_ring->next_to_clean,
232 (unsigned long long)buffer_info->dma,
233 buffer_info->length,
234 buffer_info->next_to_watch,
235 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000236
Bruce Allanaf667a22010-12-31 06:10:01 +0000237 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000238 if (!netif_msg_tx_done(adapter))
239 goto rx_ring_summary;
240
Bruce Allanaf667a22010-12-31 06:10:01 +0000241 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000242
243 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
244 *
245 * Legacy Transmit Descriptor
246 * +--------------------------------------------------------------+
247 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
248 * +--------------------------------------------------------------+
249 * 8 | Special | CSS | Status | CMD | CSO | Length |
250 * +--------------------------------------------------------------+
251 * 63 48 47 36 35 32 31 24 23 16 15 0
252 *
253 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
254 * 63 48 47 40 39 32 31 16 15 8 7 0
255 * +----------------------------------------------------------------+
256 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
257 * +----------------------------------------------------------------+
258 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
259 * +----------------------------------------------------------------+
260 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
261 *
262 * Extended Data Descriptor (DTYP=0x1)
263 * +----------------------------------------------------------------+
264 * 0 | Buffer Address [63:0] |
265 * +----------------------------------------------------------------+
266 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
267 * +----------------------------------------------------------------+
268 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
269 */
270 printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000271 " [bi->dma ] leng ntw timestamp bi->skb "
272 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000273 printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000274 " [bi->dma ] leng ntw timestamp bi->skb "
275 "<-- Ext Context format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000276 printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000277 " [bi->dma ] leng ntw timestamp bi->skb "
278 "<-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000279 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
280 tx_desc = E1000_TX_DESC(*tx_ring, i);
281 buffer_info = &tx_ring->buffer_info[i];
282 u0 = (struct my_u0 *)tx_desc;
283 printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000284 "%04X %3X %016llX %p",
285 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
286 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), i,
Bruce Allan8eb64e62010-06-29 18:12:30 +0000287 (unsigned long long)le64_to_cpu(u0->a),
288 (unsigned long long)le64_to_cpu(u0->b),
289 (unsigned long long)buffer_info->dma,
290 buffer_info->length, buffer_info->next_to_watch,
291 (unsigned long long)buffer_info->time_stamp,
Taku Izumi84f4ee92010-04-27 14:39:08 +0000292 buffer_info->skb);
293 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
294 printk(KERN_CONT " NTC/U\n");
295 else if (i == tx_ring->next_to_use)
296 printk(KERN_CONT " NTU\n");
297 else if (i == tx_ring->next_to_clean)
298 printk(KERN_CONT " NTC\n");
299 else
300 printk(KERN_CONT "\n");
301
302 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
303 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Bruce Allanaf667a22010-12-31 06:10:01 +0000304 16, 1, phys_to_virt(buffer_info->dma),
305 buffer_info->length, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000306 }
307
Bruce Allanaf667a22010-12-31 06:10:01 +0000308 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000309rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000310 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000311 printk(KERN_INFO "Queue [NTU] [NTC]\n");
312 printk(KERN_INFO " %5d %5X %5X\n", 0,
Bruce Allanaf667a22010-12-31 06:10:01 +0000313 rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000314
Bruce Allanaf667a22010-12-31 06:10:01 +0000315 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000316 if (!netif_msg_rx_status(adapter))
317 goto exit;
318
Bruce Allanaf667a22010-12-31 06:10:01 +0000319 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000320 switch (adapter->rx_ps_pages) {
321 case 1:
322 case 2:
323 case 3:
324 /* [Extended] Packet Split Receive Descriptor Format
325 *
326 * +-----------------------------------------------------+
327 * 0 | Buffer Address 0 [63:0] |
328 * +-----------------------------------------------------+
329 * 8 | Buffer Address 1 [63:0] |
330 * +-----------------------------------------------------+
331 * 16 | Buffer Address 2 [63:0] |
332 * +-----------------------------------------------------+
333 * 24 | Buffer Address 3 [63:0] |
334 * +-----------------------------------------------------+
335 */
336 printk(KERN_INFO "R [desc] [buffer 0 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000337 "[buffer 1 63:0 ] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000338 "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] "
339 "[bi->skb] <-- Ext Pkt Split format\n");
340 /* [Extended] Receive Descriptor (Write-Back) Format
341 *
342 * 63 48 47 32 31 13 12 8 7 4 3 0
343 * +------------------------------------------------------+
344 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
345 * | Checksum | Ident | | Queue | | Type |
346 * +------------------------------------------------------+
347 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
348 * +------------------------------------------------------+
349 * 63 48 47 32 31 20 19 0
350 */
351 printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000352 "[vl l0 ee es] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000353 "[ l3 l2 l1 hs] [reserved ] ---------------- "
354 "[bi->skb] <-- Ext Rx Write-Back format\n");
355 for (i = 0; i < rx_ring->count; i++) {
356 buffer_info = &rx_ring->buffer_info[i];
357 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
358 u1 = (struct my_u1 *)rx_desc_ps;
359 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000360 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000361 if (staterr & E1000_RXD_STAT_DD) {
362 /* Descriptor Done */
363 printk(KERN_INFO "RWB[0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000364 "%016llX %016llX %016llX "
365 "---------------- %p", i,
366 (unsigned long long)le64_to_cpu(u1->a),
367 (unsigned long long)le64_to_cpu(u1->b),
368 (unsigned long long)le64_to_cpu(u1->c),
369 (unsigned long long)le64_to_cpu(u1->d),
370 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000371 } else {
372 printk(KERN_INFO "R [0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000373 "%016llX %016llX %016llX %016llX %p", i,
374 (unsigned long long)le64_to_cpu(u1->a),
375 (unsigned long long)le64_to_cpu(u1->b),
376 (unsigned long long)le64_to_cpu(u1->c),
377 (unsigned long long)le64_to_cpu(u1->d),
378 (unsigned long long)buffer_info->dma,
379 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000380
381 if (netif_msg_pktdata(adapter))
382 print_hex_dump(KERN_INFO, "",
383 DUMP_PREFIX_ADDRESS, 16, 1,
384 phys_to_virt(buffer_info->dma),
385 adapter->rx_ps_bsize0, true);
386 }
387
388 if (i == rx_ring->next_to_use)
389 printk(KERN_CONT " NTU\n");
390 else if (i == rx_ring->next_to_clean)
391 printk(KERN_CONT " NTC\n");
392 else
393 printk(KERN_CONT "\n");
394 }
395 break;
396 default:
397 case 0:
398 /* Legacy Receive Descriptor Format
399 *
400 * +-----------------------------------------------------+
401 * | Buffer Address [63:0] |
402 * +-----------------------------------------------------+
403 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
404 * +-----------------------------------------------------+
405 * 63 48 47 40 39 32 31 16 15 0
406 */
407 printk(KERN_INFO "Rl[desc] [address 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000408 "[vl er S cks ln] [bi->dma ] [bi->skb] "
409 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000410 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
411 rx_desc = E1000_RX_DESC(*rx_ring, i);
412 buffer_info = &rx_ring->buffer_info[i];
413 u0 = (struct my_u0 *)rx_desc;
414 printk(KERN_INFO "Rl[0x%03X] %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000415 "%016llX %p", i,
416 (unsigned long long)le64_to_cpu(u0->a),
417 (unsigned long long)le64_to_cpu(u0->b),
418 (unsigned long long)buffer_info->dma,
419 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000420 if (i == rx_ring->next_to_use)
421 printk(KERN_CONT " NTU\n");
422 else if (i == rx_ring->next_to_clean)
423 printk(KERN_CONT " NTC\n");
424 else
425 printk(KERN_CONT "\n");
426
427 if (netif_msg_pktdata(adapter))
428 print_hex_dump(KERN_INFO, "",
Bruce Allanaf667a22010-12-31 06:10:01 +0000429 DUMP_PREFIX_ADDRESS,
430 16, 1,
431 phys_to_virt(buffer_info->dma),
432 adapter->rx_buffer_len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000433 }
434 }
435
436exit:
437 return;
438}
439
Auke Kokbc7f75f2007-09-17 12:30:59 -0700440/**
441 * e1000_desc_unused - calculate if we have unused descriptors
442 **/
443static int e1000_desc_unused(struct e1000_ring *ring)
444{
445 if (ring->next_to_clean > ring->next_to_use)
446 return ring->next_to_clean - ring->next_to_use - 1;
447
448 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
449}
450
451/**
Bruce Allanad680762008-03-28 09:15:03 -0700452 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700453 * @adapter: board private structure
454 * @status: descriptor status field as written by hardware
455 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
456 * @skb: pointer to sk_buff to be indicated to stack
457 **/
458static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000459 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000460 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700461{
462 skb->protocol = eth_type_trans(skb, netdev);
463
464 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
Herbert Xuc405b822009-01-14 20:37:59 -0800465 vlan_gro_receive(&adapter->napi, adapter->vlgrp,
466 le16_to_cpu(vlan), skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700467 else
Herbert Xu89c88b12008-12-15 23:46:15 -0800468 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700469}
470
471/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000472 * e1000_rx_checksum - Receive Checksum Offload
Auke Kokbc7f75f2007-09-17 12:30:59 -0700473 * @adapter: board private structure
474 * @status_err: receive descriptor status and error fields
475 * @csum: receive descriptor csum field
476 * @sk_buff: socket buffer with received data
477 **/
478static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
479 u32 csum, struct sk_buff *skb)
480{
481 u16 status = (u16)status_err;
482 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700483
484 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700485
486 /* Ignore Checksum bit is set */
487 if (status & E1000_RXD_STAT_IXSM)
488 return;
489 /* TCP/UDP checksum error bit is set */
490 if (errors & E1000_RXD_ERR_TCPE) {
491 /* let the stack verify checksum errors */
492 adapter->hw_csum_err++;
493 return;
494 }
495
496 /* TCP/UDP Checksum has not been calculated */
497 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
498 return;
499
500 /* It must be a TCP or UDP packet with a valid checksum */
501 if (status & E1000_RXD_STAT_TCPCS) {
502 /* TCP checksum is good */
503 skb->ip_summed = CHECKSUM_UNNECESSARY;
504 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700505 /*
506 * IP fragment with UDP payload
507 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700508 * and then put the value in host order for further stack use.
509 */
Al Viroa39fe742007-12-11 19:50:34 +0000510 __sum16 sum = (__force __sum16)htons(csum);
511 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700512 skb->ip_summed = CHECKSUM_COMPLETE;
513 }
514 adapter->hw_csum_good++;
515}
516
517/**
518 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
519 * @adapter: address of board private structure
520 **/
521static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
522 int cleaned_count)
523{
524 struct net_device *netdev = adapter->netdev;
525 struct pci_dev *pdev = adapter->pdev;
526 struct e1000_ring *rx_ring = adapter->rx_ring;
527 struct e1000_rx_desc *rx_desc;
528 struct e1000_buffer *buffer_info;
529 struct sk_buff *skb;
530 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000531 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532
533 i = rx_ring->next_to_use;
534 buffer_info = &rx_ring->buffer_info[i];
535
536 while (cleaned_count--) {
537 skb = buffer_info->skb;
538 if (skb) {
539 skb_trim(skb, 0);
540 goto map_skb;
541 }
542
Eric Dumazet89d71a62009-10-13 05:34:20 +0000543 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700544 if (!skb) {
545 /* Better luck next round */
546 adapter->alloc_rx_buff_failed++;
547 break;
548 }
549
Auke Kokbc7f75f2007-09-17 12:30:59 -0700550 buffer_info->skb = skb;
551map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000552 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700553 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000554 DMA_FROM_DEVICE);
555 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000556 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557 adapter->rx_dma_failed++;
558 break;
559 }
560
561 rx_desc = E1000_RX_DESC(*rx_ring, i);
562 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
563
Tom Herbert50849d72010-05-05 14:02:49 +0000564 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
565 /*
566 * Force memory writes to complete before letting h/w
567 * know there are new descriptors to fetch. (Only
568 * applicable for weak-ordered memory model archs,
569 * such as IA-64).
570 */
571 wmb();
572 writel(i, adapter->hw.hw_addr + rx_ring->tail);
573 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700574 i++;
575 if (i == rx_ring->count)
576 i = 0;
577 buffer_info = &rx_ring->buffer_info[i];
578 }
579
Tom Herbert50849d72010-05-05 14:02:49 +0000580 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700581}
582
583/**
584 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
585 * @adapter: address of board private structure
586 **/
587static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
588 int cleaned_count)
589{
590 struct net_device *netdev = adapter->netdev;
591 struct pci_dev *pdev = adapter->pdev;
592 union e1000_rx_desc_packet_split *rx_desc;
593 struct e1000_ring *rx_ring = adapter->rx_ring;
594 struct e1000_buffer *buffer_info;
595 struct e1000_ps_page *ps_page;
596 struct sk_buff *skb;
597 unsigned int i, j;
598
599 i = rx_ring->next_to_use;
600 buffer_info = &rx_ring->buffer_info[i];
601
602 while (cleaned_count--) {
603 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
604
605 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700606 ps_page = &buffer_info->ps_pages[j];
607 if (j >= adapter->rx_ps_pages) {
608 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000609 rx_desc->read.buffer_addr[j + 1] =
610 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700611 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700612 }
Auke Kok47f44e42007-10-25 13:57:44 -0700613 if (!ps_page->page) {
614 ps_page->page = alloc_page(GFP_ATOMIC);
615 if (!ps_page->page) {
616 adapter->alloc_rx_buff_failed++;
617 goto no_buffers;
618 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000619 ps_page->dma = dma_map_page(&pdev->dev,
620 ps_page->page,
621 0, PAGE_SIZE,
622 DMA_FROM_DEVICE);
623 if (dma_mapping_error(&pdev->dev,
624 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700625 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000626 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700627 adapter->rx_dma_failed++;
628 goto no_buffers;
629 }
630 }
631 /*
632 * Refresh the desc even if buffer_addrs
633 * didn't change because each write-back
634 * erases this info.
635 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000636 rx_desc->read.buffer_addr[j + 1] =
637 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700638 }
639
Eric Dumazet89d71a62009-10-13 05:34:20 +0000640 skb = netdev_alloc_skb_ip_align(netdev,
641 adapter->rx_ps_bsize0);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700642
643 if (!skb) {
644 adapter->alloc_rx_buff_failed++;
645 break;
646 }
647
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000649 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700650 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000651 DMA_FROM_DEVICE);
652 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000653 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700654 adapter->rx_dma_failed++;
655 /* cleanup skb */
656 dev_kfree_skb_any(skb);
657 buffer_info->skb = NULL;
658 break;
659 }
660
661 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
662
Tom Herbert50849d72010-05-05 14:02:49 +0000663 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
664 /*
665 * Force memory writes to complete before letting h/w
666 * know there are new descriptors to fetch. (Only
667 * applicable for weak-ordered memory model archs,
668 * such as IA-64).
669 */
670 wmb();
Bruce Allanaf667a22010-12-31 06:10:01 +0000671 writel(i << 1, adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000672 }
673
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674 i++;
675 if (i == rx_ring->count)
676 i = 0;
677 buffer_info = &rx_ring->buffer_info[i];
678 }
679
680no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000681 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700682}
683
684/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700685 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
686 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700687 * @cleaned_count: number of buffers to allocate this pass
688 **/
689
690static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
691 int cleaned_count)
692{
693 struct net_device *netdev = adapter->netdev;
694 struct pci_dev *pdev = adapter->pdev;
695 struct e1000_rx_desc *rx_desc;
696 struct e1000_ring *rx_ring = adapter->rx_ring;
697 struct e1000_buffer *buffer_info;
698 struct sk_buff *skb;
699 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000700 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700701
702 i = rx_ring->next_to_use;
703 buffer_info = &rx_ring->buffer_info[i];
704
705 while (cleaned_count--) {
706 skb = buffer_info->skb;
707 if (skb) {
708 skb_trim(skb, 0);
709 goto check_page;
710 }
711
Eric Dumazet89d71a62009-10-13 05:34:20 +0000712 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700713 if (unlikely(!skb)) {
714 /* Better luck next round */
715 adapter->alloc_rx_buff_failed++;
716 break;
717 }
718
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700719 buffer_info->skb = skb;
720check_page:
721 /* allocate a new page if necessary */
722 if (!buffer_info->page) {
723 buffer_info->page = alloc_page(GFP_ATOMIC);
724 if (unlikely(!buffer_info->page)) {
725 adapter->alloc_rx_buff_failed++;
726 break;
727 }
728 }
729
730 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000731 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700732 buffer_info->page, 0,
733 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000734 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700735
736 rx_desc = E1000_RX_DESC(*rx_ring, i);
737 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
738
739 if (unlikely(++i == rx_ring->count))
740 i = 0;
741 buffer_info = &rx_ring->buffer_info[i];
742 }
743
744 if (likely(rx_ring->next_to_use != i)) {
745 rx_ring->next_to_use = i;
746 if (unlikely(i-- == 0))
747 i = (rx_ring->count - 1);
748
749 /* Force memory writes to complete before letting h/w
750 * know there are new descriptors to fetch. (Only
751 * applicable for weak-ordered memory model archs,
752 * such as IA-64). */
753 wmb();
754 writel(i, adapter->hw.hw_addr + rx_ring->tail);
755 }
756}
757
758/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700759 * e1000_clean_rx_irq - Send received data up the network stack; legacy
760 * @adapter: board private structure
761 *
762 * the return value indicates whether actual cleaning was done, there
763 * is no guarantee that everything was cleaned
764 **/
765static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
766 int *work_done, int work_to_do)
767{
768 struct net_device *netdev = adapter->netdev;
769 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000770 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700771 struct e1000_ring *rx_ring = adapter->rx_ring;
772 struct e1000_rx_desc *rx_desc, *next_rxd;
773 struct e1000_buffer *buffer_info, *next_buffer;
774 u32 length;
775 unsigned int i;
776 int cleaned_count = 0;
777 bool cleaned = 0;
778 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
779
780 i = rx_ring->next_to_clean;
781 rx_desc = E1000_RX_DESC(*rx_ring, i);
782 buffer_info = &rx_ring->buffer_info[i];
783
784 while (rx_desc->status & E1000_RXD_STAT_DD) {
785 struct sk_buff *skb;
786 u8 status;
787
788 if (*work_done >= work_to_do)
789 break;
790 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000791 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700792
793 status = rx_desc->status;
794 skb = buffer_info->skb;
795 buffer_info->skb = NULL;
796
797 prefetch(skb->data - NET_IP_ALIGN);
798
799 i++;
800 if (i == rx_ring->count)
801 i = 0;
802 next_rxd = E1000_RX_DESC(*rx_ring, i);
803 prefetch(next_rxd);
804
805 next_buffer = &rx_ring->buffer_info[i];
806
807 cleaned = 1;
808 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000809 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810 buffer_info->dma,
811 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000812 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700813 buffer_info->dma = 0;
814
815 length = le16_to_cpu(rx_desc->length);
816
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000817 /*
818 * !EOP means multiple descriptors were used to store a single
819 * packet, if that's the case we need to toss it. In fact, we
820 * need to toss every packet with the EOP bit clear and the
821 * next frame that _does_ have the EOP bit set, as it is by
822 * definition only a frame fragment
823 */
824 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
825 adapter->flags2 |= FLAG2_IS_DISCARDING;
826
827 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700828 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000829 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700830 /* recycle */
831 buffer_info->skb = skb;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000832 if (status & E1000_RXD_STAT_EOP)
833 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700834 goto next_desc;
835 }
836
837 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
838 /* recycle */
839 buffer_info->skb = skb;
840 goto next_desc;
841 }
842
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000843 /* adjust length to remove Ethernet CRC */
844 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
845 length -= 4;
846
Auke Kokbc7f75f2007-09-17 12:30:59 -0700847 total_rx_bytes += length;
848 total_rx_packets++;
849
Bruce Allanad680762008-03-28 09:15:03 -0700850 /*
851 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700853 * of reassembly being done in the stack
854 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700855 if (length < copybreak) {
856 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000857 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700858 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700859 skb_copy_to_linear_data_offset(new_skb,
860 -NET_IP_ALIGN,
861 (skb->data -
862 NET_IP_ALIGN),
863 (length +
864 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700865 /* save the skb in buffer_info as good */
866 buffer_info->skb = skb;
867 skb = new_skb;
868 }
869 /* else just continue with the old one */
870 }
871 /* end copybreak code */
872 skb_put(skb, length);
873
874 /* Receive Checksum Offload */
875 e1000_rx_checksum(adapter,
876 (u32)(status) |
877 ((u32)(rx_desc->errors) << 24),
878 le16_to_cpu(rx_desc->csum), skb);
879
880 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
881
882next_desc:
883 rx_desc->status = 0;
884
885 /* return some buffers to hardware, one at a time is too slow */
886 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
887 adapter->alloc_rx_buf(adapter, cleaned_count);
888 cleaned_count = 0;
889 }
890
891 /* use prefetched values */
892 rx_desc = next_rxd;
893 buffer_info = next_buffer;
894 }
895 rx_ring->next_to_clean = i;
896
897 cleaned_count = e1000_desc_unused(rx_ring);
898 if (cleaned_count)
899 adapter->alloc_rx_buf(adapter, cleaned_count);
900
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700902 adapter->total_rx_packets += total_rx_packets;
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
Bruce Allan41cec6f2009-11-20 23:28:56 +0000938 e1e_rphy(hw, PHY_STATUS, &phy_status);
939 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
940 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
941
942 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
943
944 /* detected Hardware unit hang */
945 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700946 " TDH <%x>\n"
947 " TDT <%x>\n"
948 " next_to_use <%x>\n"
949 " next_to_clean <%x>\n"
950 "buffer_info[next_to_clean]:\n"
951 " time_stamp <%lx>\n"
952 " next_to_watch <%x>\n"
953 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +0000954 " next_to_watch.status <%x>\n"
955 "MAC Status <%x>\n"
956 "PHY Status <%x>\n"
957 "PHY 1000BASE-T Status <%x>\n"
958 "PHY Extended Status <%x>\n"
959 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700960 readl(adapter->hw.hw_addr + tx_ring->head),
961 readl(adapter->hw.hw_addr + tx_ring->tail),
962 tx_ring->next_to_use,
963 tx_ring->next_to_clean,
964 tx_ring->buffer_info[eop].time_stamp,
965 eop,
966 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +0000967 eop_desc->upper.fields.status,
968 er32(STATUS),
969 phy_status,
970 phy_1000t_status,
971 phy_ext_status,
972 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973}
974
975/**
976 * e1000_clean_tx_irq - Reclaim resources after transmit completes
977 * @adapter: board private structure
978 *
979 * the return value indicates whether actual cleaning was done, there
980 * is no guarantee that everything was cleaned
981 **/
982static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
983{
984 struct net_device *netdev = adapter->netdev;
985 struct e1000_hw *hw = &adapter->hw;
986 struct e1000_ring *tx_ring = adapter->tx_ring;
987 struct e1000_tx_desc *tx_desc, *eop_desc;
988 struct e1000_buffer *buffer_info;
989 unsigned int i, eop;
990 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
992
993 i = tx_ring->next_to_clean;
994 eop = tx_ring->buffer_info[i].next_to_watch;
995 eop_desc = E1000_TX_DESC(*tx_ring, eop);
996
Alexander Duyck12d04a32009-03-25 22:05:03 +0000997 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
998 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +0000999 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001000 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001001 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001002 tx_desc = E1000_TX_DESC(*tx_ring, i);
1003 buffer_info = &tx_ring->buffer_info[i];
1004 cleaned = (i == eop);
1005
1006 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001007 total_tx_packets += buffer_info->segs;
1008 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001009 }
1010
1011 e1000_put_txbuf(adapter, buffer_info);
1012 tx_desc->upper.data = 0;
1013
1014 i++;
1015 if (i == tx_ring->count)
1016 i = 0;
1017 }
1018
Terry Loftindac87612010-04-09 10:29:49 +00001019 if (i == tx_ring->next_to_use)
1020 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001021 eop = tx_ring->buffer_info[i].next_to_watch;
1022 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023 }
1024
1025 tx_ring->next_to_clean = i;
1026
1027#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001028 if (count && netif_carrier_ok(netdev) &&
1029 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001030 /* Make sure that anybody stopping the queue after this
1031 * sees the new next_to_clean.
1032 */
1033 smp_mb();
1034
1035 if (netif_queue_stopped(netdev) &&
1036 !(test_bit(__E1000_DOWN, &adapter->state))) {
1037 netif_wake_queue(netdev);
1038 ++adapter->restart_queue;
1039 }
1040 }
1041
1042 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001043 /*
1044 * Detect a transmit hang in hardware, this serializes the
1045 * check with the clearing of time_stamp and movement of i
1046 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001047 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001048 if (tx_ring->buffer_info[i].time_stamp &&
1049 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001050 + (adapter->tx_timeout_factor * HZ)) &&
1051 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001052 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001053 netif_stop_queue(netdev);
1054 }
1055 }
1056 adapter->total_tx_bytes += total_tx_bytes;
1057 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001058 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001059}
1060
1061/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001062 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1063 * @adapter: board private structure
1064 *
1065 * the return value indicates whether actual cleaning was done, there
1066 * is no guarantee that everything was cleaned
1067 **/
1068static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1069 int *work_done, int work_to_do)
1070{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001071 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001072 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1073 struct net_device *netdev = adapter->netdev;
1074 struct pci_dev *pdev = adapter->pdev;
1075 struct e1000_ring *rx_ring = adapter->rx_ring;
1076 struct e1000_buffer *buffer_info, *next_buffer;
1077 struct e1000_ps_page *ps_page;
1078 struct sk_buff *skb;
1079 unsigned int i, j;
1080 u32 length, staterr;
1081 int cleaned_count = 0;
1082 bool cleaned = 0;
1083 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1084
1085 i = rx_ring->next_to_clean;
1086 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1087 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1088 buffer_info = &rx_ring->buffer_info[i];
1089
1090 while (staterr & E1000_RXD_STAT_DD) {
1091 if (*work_done >= work_to_do)
1092 break;
1093 (*work_done)++;
1094 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001095 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001096
1097 /* in the packet split case this is header only */
1098 prefetch(skb->data - NET_IP_ALIGN);
1099
1100 i++;
1101 if (i == rx_ring->count)
1102 i = 0;
1103 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1104 prefetch(next_rxd);
1105
1106 next_buffer = &rx_ring->buffer_info[i];
1107
1108 cleaned = 1;
1109 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001110 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001111 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001112 buffer_info->dma = 0;
1113
Bruce Allanaf667a22010-12-31 06:10:01 +00001114 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001115 if (!(staterr & E1000_RXD_STAT_EOP))
1116 adapter->flags2 |= FLAG2_IS_DISCARDING;
1117
1118 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001119 e_dbg("Packet Split buffers didn't pick up the full "
1120 "packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001121 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001122 if (staterr & E1000_RXD_STAT_EOP)
1123 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001124 goto next_desc;
1125 }
1126
1127 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1128 dev_kfree_skb_irq(skb);
1129 goto next_desc;
1130 }
1131
1132 length = le16_to_cpu(rx_desc->wb.middle.length0);
1133
1134 if (!length) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001135 e_dbg("Last part of the packet spanning multiple "
1136 "descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001137 dev_kfree_skb_irq(skb);
1138 goto next_desc;
1139 }
1140
1141 /* Good Receive */
1142 skb_put(skb, length);
1143
1144 {
Bruce Allanad680762008-03-28 09:15:03 -07001145 /*
1146 * this looks ugly, but it seems compiler issues make it
1147 * more efficient than reusing j
1148 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001149 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1150
Bruce Allanad680762008-03-28 09:15:03 -07001151 /*
1152 * page alloc/put takes too long and effects small packet
1153 * throughput, so unsplit small packets and save the alloc/put
1154 * only valid in softirq (napi) context to call kmap_*
1155 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001156 if (l1 && (l1 <= copybreak) &&
1157 ((length + l1) <= adapter->rx_ps_bsize0)) {
1158 u8 *vaddr;
1159
Auke Kok47f44e42007-10-25 13:57:44 -07001160 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001161
Bruce Allanad680762008-03-28 09:15:03 -07001162 /*
1163 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001164 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001165 * very long
1166 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001167 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1168 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001169 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1170 memcpy(skb_tail_pointer(skb), vaddr, l1);
1171 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001172 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1173 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001174
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001175 /* remove the CRC */
1176 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1177 l1 -= 4;
1178
Auke Kokbc7f75f2007-09-17 12:30:59 -07001179 skb_put(skb, l1);
1180 goto copydone;
1181 } /* if */
1182 }
1183
1184 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1185 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1186 if (!length)
1187 break;
1188
Auke Kok47f44e42007-10-25 13:57:44 -07001189 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001190 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1191 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192 ps_page->dma = 0;
1193 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1194 ps_page->page = NULL;
1195 skb->len += length;
1196 skb->data_len += length;
1197 skb->truesize += length;
1198 }
1199
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001200 /* strip the ethernet crc, problem is we're using pages now so
1201 * this whole operation can get a little cpu intensive
1202 */
1203 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1204 pskb_trim(skb, skb->len - 4);
1205
Auke Kokbc7f75f2007-09-17 12:30:59 -07001206copydone:
1207 total_rx_bytes += skb->len;
1208 total_rx_packets++;
1209
1210 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1211 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1212
1213 if (rx_desc->wb.upper.header_status &
1214 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1215 adapter->rx_hdr_split++;
1216
1217 e1000_receive_skb(adapter, netdev, skb,
1218 staterr, rx_desc->wb.middle.vlan);
1219
1220next_desc:
1221 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1222 buffer_info->skb = NULL;
1223
1224 /* return some buffers to hardware, one at a time is too slow */
1225 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1226 adapter->alloc_rx_buf(adapter, cleaned_count);
1227 cleaned_count = 0;
1228 }
1229
1230 /* use prefetched values */
1231 rx_desc = next_rxd;
1232 buffer_info = next_buffer;
1233
1234 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1235 }
1236 rx_ring->next_to_clean = i;
1237
1238 cleaned_count = e1000_desc_unused(rx_ring);
1239 if (cleaned_count)
1240 adapter->alloc_rx_buf(adapter, cleaned_count);
1241
Auke Kokbc7f75f2007-09-17 12:30:59 -07001242 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001243 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 return cleaned;
1245}
1246
1247/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001248 * e1000_consume_page - helper function
1249 **/
1250static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1251 u16 length)
1252{
1253 bi->page = NULL;
1254 skb->len += length;
1255 skb->data_len += length;
1256 skb->truesize += length;
1257}
1258
1259/**
1260 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1261 * @adapter: board private structure
1262 *
1263 * the return value indicates whether actual cleaning was done, there
1264 * is no guarantee that everything was cleaned
1265 **/
1266
1267static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1268 int *work_done, int work_to_do)
1269{
1270 struct net_device *netdev = adapter->netdev;
1271 struct pci_dev *pdev = adapter->pdev;
1272 struct e1000_ring *rx_ring = adapter->rx_ring;
1273 struct e1000_rx_desc *rx_desc, *next_rxd;
1274 struct e1000_buffer *buffer_info, *next_buffer;
1275 u32 length;
1276 unsigned int i;
1277 int cleaned_count = 0;
1278 bool cleaned = false;
1279 unsigned int total_rx_bytes=0, total_rx_packets=0;
1280
1281 i = rx_ring->next_to_clean;
1282 rx_desc = E1000_RX_DESC(*rx_ring, i);
1283 buffer_info = &rx_ring->buffer_info[i];
1284
1285 while (rx_desc->status & E1000_RXD_STAT_DD) {
1286 struct sk_buff *skb;
1287 u8 status;
1288
1289 if (*work_done >= work_to_do)
1290 break;
1291 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001292 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001293
1294 status = rx_desc->status;
1295 skb = buffer_info->skb;
1296 buffer_info->skb = NULL;
1297
1298 ++i;
1299 if (i == rx_ring->count)
1300 i = 0;
1301 next_rxd = E1000_RX_DESC(*rx_ring, i);
1302 prefetch(next_rxd);
1303
1304 next_buffer = &rx_ring->buffer_info[i];
1305
1306 cleaned = true;
1307 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001308 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1309 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001310 buffer_info->dma = 0;
1311
1312 length = le16_to_cpu(rx_desc->length);
1313
1314 /* errors is only valid for DD + EOP descriptors */
1315 if (unlikely((status & E1000_RXD_STAT_EOP) &&
1316 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
1317 /* recycle both page and skb */
1318 buffer_info->skb = skb;
1319 /* an error means any chain goes out the window
1320 * too */
1321 if (rx_ring->rx_skb_top)
1322 dev_kfree_skb(rx_ring->rx_skb_top);
1323 rx_ring->rx_skb_top = NULL;
1324 goto next_desc;
1325 }
1326
Bruce Allanf0f1a172010-12-11 05:53:32 +00001327#define rxtop (rx_ring->rx_skb_top)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001328 if (!(status & E1000_RXD_STAT_EOP)) {
1329 /* this descriptor is only the beginning (or middle) */
1330 if (!rxtop) {
1331 /* this is the beginning of a chain */
1332 rxtop = skb;
1333 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1334 0, length);
1335 } else {
1336 /* this is the middle of a chain */
1337 skb_fill_page_desc(rxtop,
1338 skb_shinfo(rxtop)->nr_frags,
1339 buffer_info->page, 0, length);
1340 /* re-use the skb, only consumed the page */
1341 buffer_info->skb = skb;
1342 }
1343 e1000_consume_page(buffer_info, rxtop, length);
1344 goto next_desc;
1345 } else {
1346 if (rxtop) {
1347 /* end of the chain */
1348 skb_fill_page_desc(rxtop,
1349 skb_shinfo(rxtop)->nr_frags,
1350 buffer_info->page, 0, length);
1351 /* re-use the current skb, we only consumed the
1352 * page */
1353 buffer_info->skb = skb;
1354 skb = rxtop;
1355 rxtop = NULL;
1356 e1000_consume_page(buffer_info, skb, length);
1357 } else {
1358 /* no chain, got EOP, this buf is the packet
1359 * copybreak to save the put_page/alloc_page */
1360 if (length <= copybreak &&
1361 skb_tailroom(skb) >= length) {
1362 u8 *vaddr;
1363 vaddr = kmap_atomic(buffer_info->page,
1364 KM_SKB_DATA_SOFTIRQ);
1365 memcpy(skb_tail_pointer(skb), vaddr,
1366 length);
1367 kunmap_atomic(vaddr,
1368 KM_SKB_DATA_SOFTIRQ);
1369 /* re-use the page, so don't erase
1370 * buffer_info->page */
1371 skb_put(skb, length);
1372 } else {
1373 skb_fill_page_desc(skb, 0,
1374 buffer_info->page, 0,
1375 length);
1376 e1000_consume_page(buffer_info, skb,
1377 length);
1378 }
1379 }
1380 }
1381
1382 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1383 e1000_rx_checksum(adapter,
1384 (u32)(status) |
1385 ((u32)(rx_desc->errors) << 24),
1386 le16_to_cpu(rx_desc->csum), skb);
1387
1388 /* probably a little skewed due to removing CRC */
1389 total_rx_bytes += skb->len;
1390 total_rx_packets++;
1391
1392 /* eth type trans needs skb->data to point to something */
1393 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001394 e_err("pskb_may_pull failed.\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001395 dev_kfree_skb(skb);
1396 goto next_desc;
1397 }
1398
1399 e1000_receive_skb(adapter, netdev, skb, status,
1400 rx_desc->special);
1401
1402next_desc:
1403 rx_desc->status = 0;
1404
1405 /* return some buffers to hardware, one at a time is too slow */
1406 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1407 adapter->alloc_rx_buf(adapter, cleaned_count);
1408 cleaned_count = 0;
1409 }
1410
1411 /* use prefetched values */
1412 rx_desc = next_rxd;
1413 buffer_info = next_buffer;
1414 }
1415 rx_ring->next_to_clean = i;
1416
1417 cleaned_count = e1000_desc_unused(rx_ring);
1418 if (cleaned_count)
1419 adapter->alloc_rx_buf(adapter, cleaned_count);
1420
1421 adapter->total_rx_bytes += total_rx_bytes;
1422 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001423 return cleaned;
1424}
1425
1426/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001427 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1428 * @adapter: board private structure
1429 **/
1430static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1431{
1432 struct e1000_ring *rx_ring = adapter->rx_ring;
1433 struct e1000_buffer *buffer_info;
1434 struct e1000_ps_page *ps_page;
1435 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001436 unsigned int i, j;
1437
1438 /* Free all the Rx ring sk_buffs */
1439 for (i = 0; i < rx_ring->count; i++) {
1440 buffer_info = &rx_ring->buffer_info[i];
1441 if (buffer_info->dma) {
1442 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001443 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001444 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001445 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001446 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001447 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001448 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001449 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001450 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001451 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001452 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001453 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001454 buffer_info->dma = 0;
1455 }
1456
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001457 if (buffer_info->page) {
1458 put_page(buffer_info->page);
1459 buffer_info->page = NULL;
1460 }
1461
Auke Kokbc7f75f2007-09-17 12:30:59 -07001462 if (buffer_info->skb) {
1463 dev_kfree_skb(buffer_info->skb);
1464 buffer_info->skb = NULL;
1465 }
1466
1467 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001468 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001469 if (!ps_page->page)
1470 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001471 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1472 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001473 ps_page->dma = 0;
1474 put_page(ps_page->page);
1475 ps_page->page = NULL;
1476 }
1477 }
1478
1479 /* there also may be some cached data from a chained receive */
1480 if (rx_ring->rx_skb_top) {
1481 dev_kfree_skb(rx_ring->rx_skb_top);
1482 rx_ring->rx_skb_top = NULL;
1483 }
1484
Auke Kokbc7f75f2007-09-17 12:30:59 -07001485 /* Zero out the descriptor ring */
1486 memset(rx_ring->desc, 0, rx_ring->size);
1487
1488 rx_ring->next_to_clean = 0;
1489 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001490 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001491
1492 writel(0, adapter->hw.hw_addr + rx_ring->head);
1493 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1494}
1495
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001496static void e1000e_downshift_workaround(struct work_struct *work)
1497{
1498 struct e1000_adapter *adapter = container_of(work,
1499 struct e1000_adapter, downshift_task);
1500
1501 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1502}
1503
Auke Kokbc7f75f2007-09-17 12:30:59 -07001504/**
1505 * e1000_intr_msi - Interrupt Handler
1506 * @irq: interrupt number
1507 * @data: pointer to a network interface device structure
1508 **/
1509static irqreturn_t e1000_intr_msi(int irq, void *data)
1510{
1511 struct net_device *netdev = data;
1512 struct e1000_adapter *adapter = netdev_priv(netdev);
1513 struct e1000_hw *hw = &adapter->hw;
1514 u32 icr = er32(ICR);
1515
Bruce Allanad680762008-03-28 09:15:03 -07001516 /*
1517 * read ICR disables interrupts using IAM
1518 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001519
dave graham573cca82009-02-10 12:52:05 +00001520 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001521 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001522 /*
1523 * ICH8 workaround-- Call gig speed drop workaround on cable
1524 * disconnect (LSC) before accessing any PHY registers
1525 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001526 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1527 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001528 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001529
Bruce Allanad680762008-03-28 09:15:03 -07001530 /*
1531 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001532 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001533 * adapter in watchdog
1534 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001535 if (netif_carrier_ok(netdev) &&
1536 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1537 /* disable receives */
1538 u32 rctl = er32(RCTL);
1539 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001540 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001541 }
1542 /* guard against interrupt when we're going down */
1543 if (!test_bit(__E1000_DOWN, &adapter->state))
1544 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1545 }
1546
Ben Hutchings288379f2009-01-19 16:43:59 -08001547 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001548 adapter->total_tx_bytes = 0;
1549 adapter->total_tx_packets = 0;
1550 adapter->total_rx_bytes = 0;
1551 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001552 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001553 }
1554
1555 return IRQ_HANDLED;
1556}
1557
1558/**
1559 * e1000_intr - Interrupt Handler
1560 * @irq: interrupt number
1561 * @data: pointer to a network interface device structure
1562 **/
1563static irqreturn_t e1000_intr(int irq, void *data)
1564{
1565 struct net_device *netdev = data;
1566 struct e1000_adapter *adapter = netdev_priv(netdev);
1567 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001568 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001569
Bruce Allana68ea772009-11-20 23:23:16 +00001570 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001571 return IRQ_NONE; /* Not our interrupt */
1572
Bruce Allanad680762008-03-28 09:15:03 -07001573 /*
1574 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1575 * not set, then the adapter didn't send an interrupt
1576 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577 if (!(icr & E1000_ICR_INT_ASSERTED))
1578 return IRQ_NONE;
1579
Bruce Allanad680762008-03-28 09:15:03 -07001580 /*
1581 * Interrupt Auto-Mask...upon reading ICR,
1582 * interrupts are masked. No need for the
1583 * IMC write
1584 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585
dave graham573cca82009-02-10 12:52:05 +00001586 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001587 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001588 /*
1589 * ICH8 workaround-- Call gig speed drop workaround on cable
1590 * disconnect (LSC) before accessing any PHY registers
1591 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1593 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001594 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001595
Bruce Allanad680762008-03-28 09:15:03 -07001596 /*
1597 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001598 * For packet buffer work-around on link down event;
1599 * disable receives here in the ISR and
1600 * reset adapter in watchdog
1601 */
1602 if (netif_carrier_ok(netdev) &&
1603 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1604 /* disable receives */
1605 rctl = er32(RCTL);
1606 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001607 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001608 }
1609 /* guard against interrupt when we're going down */
1610 if (!test_bit(__E1000_DOWN, &adapter->state))
1611 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1612 }
1613
Ben Hutchings288379f2009-01-19 16:43:59 -08001614 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001615 adapter->total_tx_bytes = 0;
1616 adapter->total_tx_packets = 0;
1617 adapter->total_rx_bytes = 0;
1618 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001619 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001620 }
1621
1622 return IRQ_HANDLED;
1623}
1624
Bruce Allan4662e822008-08-26 18:37:06 -07001625static irqreturn_t e1000_msix_other(int irq, void *data)
1626{
1627 struct net_device *netdev = data;
1628 struct e1000_adapter *adapter = netdev_priv(netdev);
1629 struct e1000_hw *hw = &adapter->hw;
1630 u32 icr = er32(ICR);
1631
1632 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001633 if (!test_bit(__E1000_DOWN, &adapter->state))
1634 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001635 return IRQ_NONE;
1636 }
1637
1638 if (icr & adapter->eiac_mask)
1639 ew32(ICS, (icr & adapter->eiac_mask));
1640
1641 if (icr & E1000_ICR_OTHER) {
1642 if (!(icr & E1000_ICR_LSC))
1643 goto no_link_interrupt;
1644 hw->mac.get_link_status = 1;
1645 /* guard against interrupt when we're going down */
1646 if (!test_bit(__E1000_DOWN, &adapter->state))
1647 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1648 }
1649
1650no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001651 if (!test_bit(__E1000_DOWN, &adapter->state))
1652 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001653
1654 return IRQ_HANDLED;
1655}
1656
1657
1658static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1659{
1660 struct net_device *netdev = data;
1661 struct e1000_adapter *adapter = netdev_priv(netdev);
1662 struct e1000_hw *hw = &adapter->hw;
1663 struct e1000_ring *tx_ring = adapter->tx_ring;
1664
1665
1666 adapter->total_tx_bytes = 0;
1667 adapter->total_tx_packets = 0;
1668
1669 if (!e1000_clean_tx_irq(adapter))
1670 /* Ring was not completely cleaned, so fire another interrupt */
1671 ew32(ICS, tx_ring->ims_val);
1672
1673 return IRQ_HANDLED;
1674}
1675
1676static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1677{
1678 struct net_device *netdev = data;
1679 struct e1000_adapter *adapter = netdev_priv(netdev);
1680
1681 /* Write the ITR value calculated at the end of the
1682 * previous interrupt.
1683 */
1684 if (adapter->rx_ring->set_itr) {
1685 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1686 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1687 adapter->rx_ring->set_itr = 0;
1688 }
1689
Ben Hutchings288379f2009-01-19 16:43:59 -08001690 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001691 adapter->total_rx_bytes = 0;
1692 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001693 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001694 }
1695 return IRQ_HANDLED;
1696}
1697
1698/**
1699 * e1000_configure_msix - Configure MSI-X hardware
1700 *
1701 * e1000_configure_msix sets up the hardware to properly
1702 * generate MSI-X interrupts.
1703 **/
1704static void e1000_configure_msix(struct e1000_adapter *adapter)
1705{
1706 struct e1000_hw *hw = &adapter->hw;
1707 struct e1000_ring *rx_ring = adapter->rx_ring;
1708 struct e1000_ring *tx_ring = adapter->tx_ring;
1709 int vector = 0;
1710 u32 ctrl_ext, ivar = 0;
1711
1712 adapter->eiac_mask = 0;
1713
1714 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1715 if (hw->mac.type == e1000_82574) {
1716 u32 rfctl = er32(RFCTL);
1717 rfctl |= E1000_RFCTL_ACK_DIS;
1718 ew32(RFCTL, rfctl);
1719 }
1720
1721#define E1000_IVAR_INT_ALLOC_VALID 0x8
1722 /* Configure Rx vector */
1723 rx_ring->ims_val = E1000_IMS_RXQ0;
1724 adapter->eiac_mask |= rx_ring->ims_val;
1725 if (rx_ring->itr_val)
1726 writel(1000000000 / (rx_ring->itr_val * 256),
1727 hw->hw_addr + rx_ring->itr_register);
1728 else
1729 writel(1, hw->hw_addr + rx_ring->itr_register);
1730 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1731
1732 /* Configure Tx vector */
1733 tx_ring->ims_val = E1000_IMS_TXQ0;
1734 vector++;
1735 if (tx_ring->itr_val)
1736 writel(1000000000 / (tx_ring->itr_val * 256),
1737 hw->hw_addr + tx_ring->itr_register);
1738 else
1739 writel(1, hw->hw_addr + tx_ring->itr_register);
1740 adapter->eiac_mask |= tx_ring->ims_val;
1741 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1742
1743 /* set vector for Other Causes, e.g. link changes */
1744 vector++;
1745 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1746 if (rx_ring->itr_val)
1747 writel(1000000000 / (rx_ring->itr_val * 256),
1748 hw->hw_addr + E1000_EITR_82574(vector));
1749 else
1750 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1751
1752 /* Cause Tx interrupts on every write back */
1753 ivar |= (1 << 31);
1754
1755 ew32(IVAR, ivar);
1756
1757 /* enable MSI-X PBA support */
1758 ctrl_ext = er32(CTRL_EXT);
1759 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1760
1761 /* Auto-Mask Other interrupts upon ICR read */
1762#define E1000_EIAC_MASK_82574 0x01F00000
1763 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1764 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1765 ew32(CTRL_EXT, ctrl_ext);
1766 e1e_flush();
1767}
1768
1769void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1770{
1771 if (adapter->msix_entries) {
1772 pci_disable_msix(adapter->pdev);
1773 kfree(adapter->msix_entries);
1774 adapter->msix_entries = NULL;
1775 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1776 pci_disable_msi(adapter->pdev);
1777 adapter->flags &= ~FLAG_MSI_ENABLED;
1778 }
Bruce Allan4662e822008-08-26 18:37:06 -07001779}
1780
1781/**
1782 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1783 *
1784 * Attempt to configure interrupts using the best available
1785 * capabilities of the hardware and kernel.
1786 **/
1787void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1788{
1789 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001790 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001791
1792 switch (adapter->int_mode) {
1793 case E1000E_INT_MODE_MSIX:
1794 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001795 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1796 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001797 sizeof(struct msix_entry),
1798 GFP_KERNEL);
1799 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001800 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001801 adapter->msix_entries[i].entry = i;
1802
1803 err = pci_enable_msix(adapter->pdev,
1804 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001805 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001806 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001807 return;
1808 }
1809 /* MSI-X failed, so fall through and try MSI */
1810 e_err("Failed to initialize MSI-X interrupts. "
1811 "Falling back to MSI interrupts.\n");
1812 e1000e_reset_interrupt_capability(adapter);
1813 }
1814 adapter->int_mode = E1000E_INT_MODE_MSI;
1815 /* Fall through */
1816 case E1000E_INT_MODE_MSI:
1817 if (!pci_enable_msi(adapter->pdev)) {
1818 adapter->flags |= FLAG_MSI_ENABLED;
1819 } else {
1820 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1821 e_err("Failed to initialize MSI interrupts. Falling "
1822 "back to legacy interrupts.\n");
1823 }
1824 /* Fall through */
1825 case E1000E_INT_MODE_LEGACY:
1826 /* Don't do anything; this is the system default */
1827 break;
1828 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001829
1830 /* store the number of vectors being used */
1831 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001832}
1833
1834/**
1835 * e1000_request_msix - Initialize MSI-X interrupts
1836 *
1837 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1838 * kernel.
1839 **/
1840static int e1000_request_msix(struct e1000_adapter *adapter)
1841{
1842 struct net_device *netdev = adapter->netdev;
1843 int err = 0, vector = 0;
1844
1845 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001846 sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001847 else
1848 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1849 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001850 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001851 netdev);
1852 if (err)
1853 goto out;
1854 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1855 adapter->rx_ring->itr_val = adapter->itr;
1856 vector++;
1857
1858 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001859 sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001860 else
1861 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1862 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001863 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001864 netdev);
1865 if (err)
1866 goto out;
1867 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1868 adapter->tx_ring->itr_val = adapter->itr;
1869 vector++;
1870
1871 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001872 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001873 if (err)
1874 goto out;
1875
1876 e1000_configure_msix(adapter);
1877 return 0;
1878out:
1879 return err;
1880}
1881
Bruce Allanf8d59f72008-08-08 18:36:11 -07001882/**
1883 * e1000_request_irq - initialize interrupts
1884 *
1885 * Attempts to configure interrupts using the best available
1886 * capabilities of the hardware and kernel.
1887 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001888static int e1000_request_irq(struct e1000_adapter *adapter)
1889{
1890 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001891 int err;
1892
Bruce Allan4662e822008-08-26 18:37:06 -07001893 if (adapter->msix_entries) {
1894 err = e1000_request_msix(adapter);
1895 if (!err)
1896 return err;
1897 /* fall back to MSI */
1898 e1000e_reset_interrupt_capability(adapter);
1899 adapter->int_mode = E1000E_INT_MODE_MSI;
1900 e1000e_set_interrupt_capability(adapter);
1901 }
1902 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001903 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001904 netdev->name, netdev);
1905 if (!err)
1906 return err;
1907
1908 /* fall back to legacy interrupt */
1909 e1000e_reset_interrupt_capability(adapter);
1910 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001911 }
1912
Joe Perchesa0607fd2009-11-18 23:29:17 -08001913 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001914 netdev->name, netdev);
1915 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001916 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001917
1918 return err;
1919}
1920
1921static void e1000_free_irq(struct e1000_adapter *adapter)
1922{
1923 struct net_device *netdev = adapter->netdev;
1924
Bruce Allan4662e822008-08-26 18:37:06 -07001925 if (adapter->msix_entries) {
1926 int vector = 0;
1927
1928 free_irq(adapter->msix_entries[vector].vector, netdev);
1929 vector++;
1930
1931 free_irq(adapter->msix_entries[vector].vector, netdev);
1932 vector++;
1933
1934 /* Other Causes interrupt vector */
1935 free_irq(adapter->msix_entries[vector].vector, netdev);
1936 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001937 }
Bruce Allan4662e822008-08-26 18:37:06 -07001938
1939 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001940}
1941
1942/**
1943 * e1000_irq_disable - Mask off interrupt generation on the NIC
1944 **/
1945static void e1000_irq_disable(struct e1000_adapter *adapter)
1946{
1947 struct e1000_hw *hw = &adapter->hw;
1948
Auke Kokbc7f75f2007-09-17 12:30:59 -07001949 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001950 if (adapter->msix_entries)
1951 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001952 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001953
1954 if (adapter->msix_entries) {
1955 int i;
1956 for (i = 0; i < adapter->num_vectors; i++)
1957 synchronize_irq(adapter->msix_entries[i].vector);
1958 } else {
1959 synchronize_irq(adapter->pdev->irq);
1960 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001961}
1962
1963/**
1964 * e1000_irq_enable - Enable default interrupt generation settings
1965 **/
1966static void e1000_irq_enable(struct e1000_adapter *adapter)
1967{
1968 struct e1000_hw *hw = &adapter->hw;
1969
Bruce Allan4662e822008-08-26 18:37:06 -07001970 if (adapter->msix_entries) {
1971 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1972 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1973 } else {
1974 ew32(IMS, IMS_ENABLE_MASK);
1975 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001976 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001977}
1978
1979/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001980 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07001981 * @adapter: address of board private structure
1982 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001983 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001984 * For ASF and Pass Through versions of f/w this means that
1985 * the driver is loaded. For AMT version (only with 82573)
1986 * of the f/w this means that the network i/f is open.
1987 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001988void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001989{
1990 struct e1000_hw *hw = &adapter->hw;
1991 u32 ctrl_ext;
1992 u32 swsm;
1993
1994 /* Let firmware know the driver has taken over */
1995 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
1996 swsm = er32(SWSM);
1997 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
1998 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
1999 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002000 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002001 }
2002}
2003
2004/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002005 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002006 * @adapter: address of board private structure
2007 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002008 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002009 * For ASF and Pass Through versions of f/w this means that the
2010 * driver is no longer loaded. For AMT version (only with 82573) i
2011 * of the f/w this means that the network i/f is closed.
2012 *
2013 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002014void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002015{
2016 struct e1000_hw *hw = &adapter->hw;
2017 u32 ctrl_ext;
2018 u32 swsm;
2019
2020 /* Let firmware taken over control of h/w */
2021 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2022 swsm = er32(SWSM);
2023 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2024 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2025 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002026 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002027 }
2028}
2029
Auke Kokbc7f75f2007-09-17 12:30:59 -07002030/**
2031 * @e1000_alloc_ring - allocate memory for a ring structure
2032 **/
2033static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2034 struct e1000_ring *ring)
2035{
2036 struct pci_dev *pdev = adapter->pdev;
2037
2038 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2039 GFP_KERNEL);
2040 if (!ring->desc)
2041 return -ENOMEM;
2042
2043 return 0;
2044}
2045
2046/**
2047 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2048 * @adapter: board private structure
2049 *
2050 * Return 0 on success, negative on failure
2051 **/
2052int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2053{
2054 struct e1000_ring *tx_ring = adapter->tx_ring;
2055 int err = -ENOMEM, size;
2056
2057 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002058 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002059 if (!tx_ring->buffer_info)
2060 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002061
2062 /* round up to nearest 4K */
2063 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2064 tx_ring->size = ALIGN(tx_ring->size, 4096);
2065
2066 err = e1000_alloc_ring_dma(adapter, tx_ring);
2067 if (err)
2068 goto err;
2069
2070 tx_ring->next_to_use = 0;
2071 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002072
2073 return 0;
2074err:
2075 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002076 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002077 return err;
2078}
2079
2080/**
2081 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2082 * @adapter: board private structure
2083 *
2084 * Returns 0 on success, negative on failure
2085 **/
2086int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2087{
2088 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002089 struct e1000_buffer *buffer_info;
2090 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002091
2092 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002093 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002094 if (!rx_ring->buffer_info)
2095 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002096
Auke Kok47f44e42007-10-25 13:57:44 -07002097 for (i = 0; i < rx_ring->count; i++) {
2098 buffer_info = &rx_ring->buffer_info[i];
2099 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2100 sizeof(struct e1000_ps_page),
2101 GFP_KERNEL);
2102 if (!buffer_info->ps_pages)
2103 goto err_pages;
2104 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002105
2106 desc_len = sizeof(union e1000_rx_desc_packet_split);
2107
2108 /* Round up to nearest 4K */
2109 rx_ring->size = rx_ring->count * desc_len;
2110 rx_ring->size = ALIGN(rx_ring->size, 4096);
2111
2112 err = e1000_alloc_ring_dma(adapter, rx_ring);
2113 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002114 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002115
2116 rx_ring->next_to_clean = 0;
2117 rx_ring->next_to_use = 0;
2118 rx_ring->rx_skb_top = NULL;
2119
2120 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002121
2122err_pages:
2123 for (i = 0; i < rx_ring->count; i++) {
2124 buffer_info = &rx_ring->buffer_info[i];
2125 kfree(buffer_info->ps_pages);
2126 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002127err:
2128 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002129 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002130 return err;
2131}
2132
2133/**
2134 * e1000_clean_tx_ring - Free Tx Buffers
2135 * @adapter: board private structure
2136 **/
2137static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2138{
2139 struct e1000_ring *tx_ring = adapter->tx_ring;
2140 struct e1000_buffer *buffer_info;
2141 unsigned long size;
2142 unsigned int i;
2143
2144 for (i = 0; i < tx_ring->count; i++) {
2145 buffer_info = &tx_ring->buffer_info[i];
2146 e1000_put_txbuf(adapter, buffer_info);
2147 }
2148
2149 size = sizeof(struct e1000_buffer) * tx_ring->count;
2150 memset(tx_ring->buffer_info, 0, size);
2151
2152 memset(tx_ring->desc, 0, tx_ring->size);
2153
2154 tx_ring->next_to_use = 0;
2155 tx_ring->next_to_clean = 0;
2156
2157 writel(0, adapter->hw.hw_addr + tx_ring->head);
2158 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2159}
2160
2161/**
2162 * e1000e_free_tx_resources - Free Tx Resources per Queue
2163 * @adapter: board private structure
2164 *
2165 * Free all transmit software resources
2166 **/
2167void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2168{
2169 struct pci_dev *pdev = adapter->pdev;
2170 struct e1000_ring *tx_ring = adapter->tx_ring;
2171
2172 e1000_clean_tx_ring(adapter);
2173
2174 vfree(tx_ring->buffer_info);
2175 tx_ring->buffer_info = NULL;
2176
2177 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2178 tx_ring->dma);
2179 tx_ring->desc = NULL;
2180}
2181
2182/**
2183 * e1000e_free_rx_resources - Free Rx Resources
2184 * @adapter: board private structure
2185 *
2186 * Free all receive software resources
2187 **/
2188
2189void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2190{
2191 struct pci_dev *pdev = adapter->pdev;
2192 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002193 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002194
2195 e1000_clean_rx_ring(adapter);
2196
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002197 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002198 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002199
Auke Kokbc7f75f2007-09-17 12:30:59 -07002200 vfree(rx_ring->buffer_info);
2201 rx_ring->buffer_info = NULL;
2202
Auke Kokbc7f75f2007-09-17 12:30:59 -07002203 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2204 rx_ring->dma);
2205 rx_ring->desc = NULL;
2206}
2207
2208/**
2209 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002210 * @adapter: pointer to adapter
2211 * @itr_setting: current adapter->itr
2212 * @packets: the number of packets during this measurement interval
2213 * @bytes: the number of bytes during this measurement interval
2214 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002215 * Stores a new ITR value based on packets and byte
2216 * counts during the last interrupt. The advantage of per interrupt
2217 * computation is faster updates and more accurate ITR for the current
2218 * traffic pattern. Constants in this function were computed
2219 * based on theoretical maximum wire speed and thresholds were set based
2220 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002221 * while increasing bulk throughput. This functionality is controlled
2222 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002223 **/
2224static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2225 u16 itr_setting, int packets,
2226 int bytes)
2227{
2228 unsigned int retval = itr_setting;
2229
2230 if (packets == 0)
2231 goto update_itr_done;
2232
2233 switch (itr_setting) {
2234 case lowest_latency:
2235 /* handle TSO and jumbo frames */
2236 if (bytes/packets > 8000)
2237 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002238 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002239 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002240 break;
2241 case low_latency: /* 50 usec aka 20000 ints/s */
2242 if (bytes > 10000) {
2243 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002244 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002245 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002246 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002247 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002248 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002249 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002250 } else if (bytes/packets > 2000) {
2251 retval = bulk_latency;
2252 } else if (packets <= 2 && bytes < 512) {
2253 retval = lowest_latency;
2254 }
2255 break;
2256 case bulk_latency: /* 250 usec aka 4000 ints/s */
2257 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002258 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002260 } else if (bytes < 6000) {
2261 retval = low_latency;
2262 }
2263 break;
2264 }
2265
2266update_itr_done:
2267 return retval;
2268}
2269
2270static void e1000_set_itr(struct e1000_adapter *adapter)
2271{
2272 struct e1000_hw *hw = &adapter->hw;
2273 u16 current_itr;
2274 u32 new_itr = adapter->itr;
2275
2276 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2277 if (adapter->link_speed != SPEED_1000) {
2278 current_itr = 0;
2279 new_itr = 4000;
2280 goto set_itr_now;
2281 }
2282
Bruce Allan828bac82010-09-29 21:39:37 +00002283 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2284 new_itr = 0;
2285 goto set_itr_now;
2286 }
2287
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288 adapter->tx_itr = e1000_update_itr(adapter,
2289 adapter->tx_itr,
2290 adapter->total_tx_packets,
2291 adapter->total_tx_bytes);
2292 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2293 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2294 adapter->tx_itr = low_latency;
2295
2296 adapter->rx_itr = e1000_update_itr(adapter,
2297 adapter->rx_itr,
2298 adapter->total_rx_packets,
2299 adapter->total_rx_bytes);
2300 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2301 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2302 adapter->rx_itr = low_latency;
2303
2304 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2305
2306 switch (current_itr) {
2307 /* counts and packets in update_itr are dependent on these numbers */
2308 case lowest_latency:
2309 new_itr = 70000;
2310 break;
2311 case low_latency:
2312 new_itr = 20000; /* aka hwitr = ~200 */
2313 break;
2314 case bulk_latency:
2315 new_itr = 4000;
2316 break;
2317 default:
2318 break;
2319 }
2320
2321set_itr_now:
2322 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002323 /*
2324 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002326 * increasing
2327 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002328 new_itr = new_itr > adapter->itr ?
2329 min(adapter->itr + (new_itr >> 2), new_itr) :
2330 new_itr;
2331 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002332 adapter->rx_ring->itr_val = new_itr;
2333 if (adapter->msix_entries)
2334 adapter->rx_ring->set_itr = 1;
2335 else
Bruce Allan828bac82010-09-29 21:39:37 +00002336 if (new_itr)
2337 ew32(ITR, 1000000000 / (new_itr * 256));
2338 else
2339 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002340 }
2341}
2342
2343/**
Bruce Allan4662e822008-08-26 18:37:06 -07002344 * e1000_alloc_queues - Allocate memory for all rings
2345 * @adapter: board private structure to initialize
2346 **/
2347static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2348{
2349 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2350 if (!adapter->tx_ring)
2351 goto err;
2352
2353 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2354 if (!adapter->rx_ring)
2355 goto err;
2356
2357 return 0;
2358err:
2359 e_err("Unable to allocate memory for queues\n");
2360 kfree(adapter->rx_ring);
2361 kfree(adapter->tx_ring);
2362 return -ENOMEM;
2363}
2364
2365/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002367 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002368 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002369 **/
2370static int e1000_clean(struct napi_struct *napi, int budget)
2371{
2372 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002373 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002374 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002375 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002376
Wang Chen4cf16532008-11-12 23:38:14 -08002377 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378
Bruce Allan4662e822008-08-26 18:37:06 -07002379 if (adapter->msix_entries &&
2380 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2381 goto clean_rx;
2382
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002383 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384
Bruce Allan4662e822008-08-26 18:37:06 -07002385clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002386 adapter->clean_rx(adapter, &work_done, budget);
2387
Alexander Duyck12d04a32009-03-25 22:05:03 +00002388 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002389 work_done = budget;
2390
David S. Miller53e52c72008-01-07 21:06:12 -08002391 /* If budget not fully consumed, exit the polling mode */
2392 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002393 if (adapter->itr_setting & 3)
2394 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002395 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002396 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2397 if (adapter->msix_entries)
2398 ew32(IMS, adapter->rx_ring->ims_val);
2399 else
2400 e1000_irq_enable(adapter);
2401 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002402 }
2403
2404 return work_done;
2405}
2406
2407static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2408{
2409 struct e1000_adapter *adapter = netdev_priv(netdev);
2410 struct e1000_hw *hw = &adapter->hw;
2411 u32 vfta, index;
2412
2413 /* don't update vlan cookie if already programmed */
2414 if ((adapter->hw.mng_cookie.status &
2415 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2416 (vid == adapter->mng_vlan_id))
2417 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002418
Auke Kokbc7f75f2007-09-17 12:30:59 -07002419 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002420 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2421 index = (vid >> 5) & 0x7F;
2422 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2423 vfta |= (1 << (vid & 0x1F));
2424 hw->mac.ops.write_vfta(hw, index, vfta);
2425 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002426}
2427
2428static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2429{
2430 struct e1000_adapter *adapter = netdev_priv(netdev);
2431 struct e1000_hw *hw = &adapter->hw;
2432 u32 vfta, index;
2433
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002434 if (!test_bit(__E1000_DOWN, &adapter->state))
2435 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002436 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002437
2438 if (!test_bit(__E1000_DOWN, &adapter->state))
2439 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440
2441 if ((adapter->hw.mng_cookie.status &
2442 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2443 (vid == adapter->mng_vlan_id)) {
2444 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002445 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446 return;
2447 }
2448
2449 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002450 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2451 index = (vid >> 5) & 0x7F;
2452 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2453 vfta &= ~(1 << (vid & 0x1F));
2454 hw->mac.ops.write_vfta(hw, index, vfta);
2455 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002456}
2457
2458static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2459{
2460 struct net_device *netdev = adapter->netdev;
2461 u16 vid = adapter->hw.mng_cookie.vlan_id;
2462 u16 old_vid = adapter->mng_vlan_id;
2463
2464 if (!adapter->vlgrp)
2465 return;
2466
2467 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2468 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2469 if (adapter->hw.mng_cookie.status &
2470 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2471 e1000_vlan_rx_add_vid(netdev, vid);
2472 adapter->mng_vlan_id = vid;
2473 }
2474
2475 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2476 (vid != old_vid) &&
2477 !vlan_group_get_device(adapter->vlgrp, old_vid))
2478 e1000_vlan_rx_kill_vid(netdev, old_vid);
2479 } else {
2480 adapter->mng_vlan_id = vid;
2481 }
2482}
2483
2484
2485static void e1000_vlan_rx_register(struct net_device *netdev,
2486 struct vlan_group *grp)
2487{
2488 struct e1000_adapter *adapter = netdev_priv(netdev);
2489 struct e1000_hw *hw = &adapter->hw;
2490 u32 ctrl, rctl;
2491
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002492 if (!test_bit(__E1000_DOWN, &adapter->state))
2493 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002494 adapter->vlgrp = grp;
2495
2496 if (grp) {
2497 /* enable VLAN tag insert/strip */
2498 ctrl = er32(CTRL);
2499 ctrl |= E1000_CTRL_VME;
2500 ew32(CTRL, ctrl);
2501
2502 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2503 /* enable VLAN receive filtering */
2504 rctl = er32(RCTL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002505 rctl &= ~E1000_RCTL_CFIEN;
2506 ew32(RCTL, rctl);
2507 e1000_update_mng_vlan(adapter);
2508 }
2509 } else {
2510 /* disable VLAN tag insert/strip */
2511 ctrl = er32(CTRL);
2512 ctrl &= ~E1000_CTRL_VME;
2513 ew32(CTRL, ctrl);
2514
2515 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002516 if (adapter->mng_vlan_id !=
2517 (u16)E1000_MNG_VLAN_NONE) {
2518 e1000_vlan_rx_kill_vid(netdev,
2519 adapter->mng_vlan_id);
2520 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2521 }
2522 }
2523 }
2524
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002525 if (!test_bit(__E1000_DOWN, &adapter->state))
2526 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527}
2528
2529static void e1000_restore_vlan(struct e1000_adapter *adapter)
2530{
2531 u16 vid;
2532
2533 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2534
2535 if (!adapter->vlgrp)
2536 return;
2537
Jesse Grossb7381272010-10-20 13:56:02 +00002538 for (vid = 0; vid < VLAN_N_VID; vid++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002539 if (!vlan_group_get_device(adapter->vlgrp, vid))
2540 continue;
2541 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2542 }
2543}
2544
Bruce Allancd791612010-05-10 14:59:51 +00002545static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002546{
2547 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002548 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002549
2550 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2551 return;
2552
2553 manc = er32(MANC);
2554
Bruce Allanad680762008-03-28 09:15:03 -07002555 /*
2556 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002557 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002558 * the packets will be handled on SMBUS
2559 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560 manc |= E1000_MANC_EN_MNG2HOST;
2561 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002562
2563 switch (hw->mac.type) {
2564 default:
2565 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2566 break;
2567 case e1000_82574:
2568 case e1000_82583:
2569 /*
2570 * Check if IPMI pass-through decision filter already exists;
2571 * if so, enable it.
2572 */
2573 for (i = 0, j = 0; i < 8; i++) {
2574 mdef = er32(MDEF(i));
2575
2576 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002577 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002578 continue;
2579
2580 /* Enable this decision filter in MANC2H */
2581 if (mdef)
2582 manc2h |= (1 << i);
2583
2584 j |= mdef;
2585 }
2586
2587 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2588 break;
2589
2590 /* Create new decision filter in an empty filter */
2591 for (i = 0, j = 0; i < 8; i++)
2592 if (er32(MDEF(i)) == 0) {
2593 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2594 E1000_MDEF_PORT_664));
2595 manc2h |= (1 << 1);
2596 j++;
2597 break;
2598 }
2599
2600 if (!j)
2601 e_warn("Unable to create IPMI pass-through filter\n");
2602 break;
2603 }
2604
Auke Kokbc7f75f2007-09-17 12:30:59 -07002605 ew32(MANC2H, manc2h);
2606 ew32(MANC, manc);
2607}
2608
2609/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002610 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611 * @adapter: board private structure
2612 *
2613 * Configure the Tx unit of the MAC after a reset.
2614 **/
2615static void e1000_configure_tx(struct e1000_adapter *adapter)
2616{
2617 struct e1000_hw *hw = &adapter->hw;
2618 struct e1000_ring *tx_ring = adapter->tx_ring;
2619 u64 tdba;
2620 u32 tdlen, tctl, tipg, tarc;
2621 u32 ipgr1, ipgr2;
2622
2623 /* Setup the HW Tx Head and Tail descriptor pointers */
2624 tdba = tx_ring->dma;
2625 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002626 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002627 ew32(TDBAH, (tdba >> 32));
2628 ew32(TDLEN, tdlen);
2629 ew32(TDH, 0);
2630 ew32(TDT, 0);
2631 tx_ring->head = E1000_TDH;
2632 tx_ring->tail = E1000_TDT;
2633
2634 /* Set the default values for the Tx Inter Packet Gap timer */
2635 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2636 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2637 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2638
2639 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2640 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2641
2642 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2643 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2644 ew32(TIPG, tipg);
2645
2646 /* Set the Tx Interrupt Delay register */
2647 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002648 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002649 ew32(TADV, adapter->tx_abs_int_delay);
2650
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002651 if (adapter->flags2 & FLAG2_DMA_BURST) {
2652 u32 txdctl = er32(TXDCTL(0));
2653 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2654 E1000_TXDCTL_WTHRESH);
2655 /*
2656 * set up some performance related parameters to encourage the
2657 * hardware to use the bus more efficiently in bursts, depends
2658 * on the tx_int_delay to be enabled,
2659 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2660 * hthresh = 1 ==> prefetch when one or more available
2661 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2662 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002663 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002664 */
2665 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2666 ew32(TXDCTL(0), txdctl);
2667 /* erratum work around: set txdctl the same for both queues */
2668 ew32(TXDCTL(1), txdctl);
2669 }
2670
Auke Kokbc7f75f2007-09-17 12:30:59 -07002671 /* Program the Transmit Control Register */
2672 tctl = er32(TCTL);
2673 tctl &= ~E1000_TCTL_CT;
2674 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2675 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2676
2677 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002678 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002679 /*
2680 * set the speed mode bit, we'll clear it if we're not at
2681 * gigabit link later
2682 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002683#define SPEED_MODE_BIT (1 << 21)
2684 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002685 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002686 }
2687
2688 /* errata: program both queues to unweighted RR */
2689 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002690 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002691 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002692 ew32(TARC(0), tarc);
2693 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002695 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002696 }
2697
Auke Kokbc7f75f2007-09-17 12:30:59 -07002698 /* Setup Transmit Descriptor Settings for eop descriptor */
2699 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2700
2701 /* only set IDE if we are delaying interrupts using the timers */
2702 if (adapter->tx_int_delay)
2703 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2704
2705 /* enable Report Status bit */
2706 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2707
2708 ew32(TCTL, tctl);
2709
Simon Hormanedfea6e62009-06-08 14:28:36 +00002710 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711}
2712
2713/**
2714 * e1000_setup_rctl - configure the receive control registers
2715 * @adapter: Board private structure
2716 **/
2717#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2718 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2719static void e1000_setup_rctl(struct e1000_adapter *adapter)
2720{
2721 struct e1000_hw *hw = &adapter->hw;
2722 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002723 u32 pages = 0;
2724
Bruce Allana1ce6472010-09-22 17:16:40 +00002725 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2726 if (hw->mac.type == e1000_pch2lan) {
2727 s32 ret_val;
2728
2729 if (adapter->netdev->mtu > ETH_DATA_LEN)
2730 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2731 else
2732 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002733
2734 if (ret_val)
2735 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002736 }
2737
Auke Kokbc7f75f2007-09-17 12:30:59 -07002738 /* Program MC offset vector base */
2739 rctl = er32(RCTL);
2740 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2741 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2742 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2743 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2744
2745 /* Do not Store bad packets */
2746 rctl &= ~E1000_RCTL_SBP;
2747
2748 /* Enable Long Packet receive */
2749 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2750 rctl &= ~E1000_RCTL_LPE;
2751 else
2752 rctl |= E1000_RCTL_LPE;
2753
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002754 /* Some systems expect that the CRC is included in SMBUS traffic. The
2755 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2756 * host memory when this is enabled
2757 */
2758 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2759 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002760
Bruce Allana4f58f52009-06-02 11:29:18 +00002761 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2762 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2763 u16 phy_data;
2764
2765 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2766 phy_data &= 0xfff8;
2767 phy_data |= (1 << 2);
2768 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2769
2770 e1e_rphy(hw, 22, &phy_data);
2771 phy_data &= 0x0fff;
2772 phy_data |= (1 << 14);
2773 e1e_wphy(hw, 0x10, 0x2823);
2774 e1e_wphy(hw, 0x11, 0x0003);
2775 e1e_wphy(hw, 22, phy_data);
2776 }
2777
Auke Kokbc7f75f2007-09-17 12:30:59 -07002778 /* Setup buffer sizes */
2779 rctl &= ~E1000_RCTL_SZ_4096;
2780 rctl |= E1000_RCTL_BSEX;
2781 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002782 case 2048:
2783 default:
2784 rctl |= E1000_RCTL_SZ_2048;
2785 rctl &= ~E1000_RCTL_BSEX;
2786 break;
2787 case 4096:
2788 rctl |= E1000_RCTL_SZ_4096;
2789 break;
2790 case 8192:
2791 rctl |= E1000_RCTL_SZ_8192;
2792 break;
2793 case 16384:
2794 rctl |= E1000_RCTL_SZ_16384;
2795 break;
2796 }
2797
2798 /*
2799 * 82571 and greater support packet-split where the protocol
2800 * header is placed in skb->data and the packet data is
2801 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2802 * In the case of a non-split, skb->data is linearly filled,
2803 * followed by the page buffers. Therefore, skb->data is
2804 * sized to hold the largest protocol header.
2805 *
2806 * allocations using alloc_page take too long for regular MTU
2807 * so only enable packet split for jumbo frames
2808 *
2809 * Using pages when the page size is greater than 16k wastes
2810 * a lot of memory, since we allocate 3 pages at all times
2811 * per packet.
2812 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fec2010-06-17 18:59:27 +00002814 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002815 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002816 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002817 else
2818 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819
2820 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002821 u32 psrctl = 0;
2822
Auke Kokbc7f75f2007-09-17 12:30:59 -07002823 /* Configure extra packet-split registers */
2824 rfctl = er32(RFCTL);
2825 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002826 /*
2827 * disable packet split support for IPv6 extension headers,
2828 * because some malformed IPv6 headers can hang the Rx
2829 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002830 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2831 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2832
2833 ew32(RFCTL, rfctl);
2834
Auke Kok140a7482007-10-25 13:57:58 -07002835 /* Enable Packet split descriptors */
2836 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002837
2838 psrctl |= adapter->rx_ps_bsize0 >>
2839 E1000_PSRCTL_BSIZE0_SHIFT;
2840
2841 switch (adapter->rx_ps_pages) {
2842 case 3:
2843 psrctl |= PAGE_SIZE <<
2844 E1000_PSRCTL_BSIZE3_SHIFT;
2845 case 2:
2846 psrctl |= PAGE_SIZE <<
2847 E1000_PSRCTL_BSIZE2_SHIFT;
2848 case 1:
2849 psrctl |= PAGE_SIZE >>
2850 E1000_PSRCTL_BSIZE1_SHIFT;
2851 break;
2852 }
2853
2854 ew32(PSRCTL, psrctl);
2855 }
2856
2857 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002858 /* just started the receive unit, no need to restart */
2859 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002860}
2861
2862/**
2863 * e1000_configure_rx - Configure Receive Unit after Reset
2864 * @adapter: board private structure
2865 *
2866 * Configure the Rx unit of the MAC after a reset.
2867 **/
2868static void e1000_configure_rx(struct e1000_adapter *adapter)
2869{
2870 struct e1000_hw *hw = &adapter->hw;
2871 struct e1000_ring *rx_ring = adapter->rx_ring;
2872 u64 rdba;
2873 u32 rdlen, rctl, rxcsum, ctrl_ext;
2874
2875 if (adapter->rx_ps_pages) {
2876 /* this is a 32 byte descriptor */
2877 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002878 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002879 adapter->clean_rx = e1000_clean_rx_irq_ps;
2880 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002881 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2882 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2883 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2884 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002885 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002886 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002887 adapter->clean_rx = e1000_clean_rx_irq;
2888 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2889 }
2890
2891 /* disable receives while setting up the descriptors */
2892 rctl = er32(RCTL);
2893 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2894 e1e_flush();
2895 msleep(10);
2896
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002897 if (adapter->flags2 & FLAG2_DMA_BURST) {
2898 /*
2899 * set the writeback threshold (only takes effect if the RDTR
2900 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00002901 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002902 * granularity = 01
2903 * wthresh = 04,
2904 * hthresh = 04,
2905 * pthresh = 0x20
2906 */
2907 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
2908 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
2909
2910 /*
2911 * override the delay timers for enabling bursting, only if
2912 * the value was not set by the user via module options
2913 */
2914 if (adapter->rx_int_delay == DEFAULT_RDTR)
2915 adapter->rx_int_delay = BURST_RDTR;
2916 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
2917 adapter->rx_abs_int_delay = BURST_RADV;
2918 }
2919
Auke Kokbc7f75f2007-09-17 12:30:59 -07002920 /* set the Receive Delay Timer Register */
2921 ew32(RDTR, adapter->rx_int_delay);
2922
2923 /* irq moderation */
2924 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00002925 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07002926 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002927
2928 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002929 /* Auto-Mask interrupts upon ICR access */
2930 ctrl_ext |= E1000_CTRL_EXT_IAME;
2931 ew32(IAM, 0xffffffff);
2932 ew32(CTRL_EXT, ctrl_ext);
2933 e1e_flush();
2934
Bruce Allanad680762008-03-28 09:15:03 -07002935 /*
2936 * Setup the HW Rx Head and Tail Descriptor Pointers and
2937 * the Base and Length of the Rx Descriptor Ring
2938 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002939 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002940 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002941 ew32(RDBAH, (rdba >> 32));
2942 ew32(RDLEN, rdlen);
2943 ew32(RDH, 0);
2944 ew32(RDT, 0);
2945 rx_ring->head = E1000_RDH;
2946 rx_ring->tail = E1000_RDT;
2947
2948 /* Enable Receive Checksum Offload for TCP and UDP */
2949 rxcsum = er32(RXCSUM);
2950 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2951 rxcsum |= E1000_RXCSUM_TUOFL;
2952
Bruce Allanad680762008-03-28 09:15:03 -07002953 /*
2954 * IPv4 payload checksum for UDP fragments must be
2955 * used in conjunction with packet-split.
2956 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002957 if (adapter->rx_ps_pages)
2958 rxcsum |= E1000_RXCSUM_IPPCSE;
2959 } else {
2960 rxcsum &= ~E1000_RXCSUM_TUOFL;
2961 /* no need to clear IPPCSE as it defaults to 0 */
2962 }
2963 ew32(RXCSUM, rxcsum);
2964
Bruce Allanad680762008-03-28 09:15:03 -07002965 /*
2966 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002967 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002968 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2969 */
Bruce Allan828bac82010-09-29 21:39:37 +00002970 if ((adapter->flags & FLAG_HAS_ERT) ||
2971 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00002972 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2973 u32 rxdctl = er32(RXDCTL(0));
2974 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00002975 if (adapter->flags & FLAG_HAS_ERT)
2976 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00002977 /*
2978 * With jumbo frames and early-receive enabled,
2979 * excessive C-state transition latencies result in
2980 * dropped transactions.
2981 */
Bruce Allanaf667a22010-12-31 06:10:01 +00002982 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00002983 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00002984 pm_qos_update_request(&adapter->netdev->pm_qos_req,
2985 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00002986 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002987 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002988
2989 /* Enable Receives */
2990 ew32(RCTL, rctl);
2991}
2992
2993/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002994 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07002995 * @hw: pointer to the HW structure
2996 * @mc_addr_list: array of multicast addresses to program
2997 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07002998 *
Bruce Allanab8932f2010-01-13 02:05:38 +00002999 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003000 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003001 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003002static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003003 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003004{
Bruce Allanab8932f2010-01-13 02:05:38 +00003005 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003006}
3007
3008/**
3009 * e1000_set_multi - Multicast and Promiscuous mode set
3010 * @netdev: network interface device structure
3011 *
3012 * The set_multi entry point is called whenever the multicast address
3013 * list or the network interface flags are updated. This routine is
3014 * responsible for configuring the hardware for proper multicast,
3015 * promiscuous mode, and all-multi behavior.
3016 **/
3017static void e1000_set_multi(struct net_device *netdev)
3018{
3019 struct e1000_adapter *adapter = netdev_priv(netdev);
3020 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003021 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003022 u8 *mta_list;
3023 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003024
3025 /* Check for Promiscuous and All Multicast modes */
3026
3027 rctl = er32(RCTL);
3028
3029 if (netdev->flags & IFF_PROMISC) {
3030 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003031 rctl &= ~E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003032 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003033 if (netdev->flags & IFF_ALLMULTI) {
3034 rctl |= E1000_RCTL_MPE;
3035 rctl &= ~E1000_RCTL_UPE;
3036 } else {
3037 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3038 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07003039 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardy746b9f02008-07-16 20:15:45 -07003040 rctl |= E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003041 }
3042
3043 ew32(RCTL, rctl);
3044
Jiri Pirko7aeef972010-02-05 02:52:39 +00003045 if (!netdev_mc_empty(netdev)) {
Bruce Allan90da0662011-01-06 07:02:53 +00003046 int i = 0;
3047
Jiri Pirko7aeef972010-02-05 02:52:39 +00003048 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003049 if (!mta_list)
3050 return;
3051
3052 /* prepare a packed array of only addresses. */
Jiri Pirko22bedad32010-04-01 21:22:57 +00003053 netdev_for_each_mc_addr(ha, netdev)
3054 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003055
Bruce Allanab8932f2010-01-13 02:05:38 +00003056 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003057 kfree(mta_list);
3058 } else {
3059 /*
3060 * if we're called from probe, we might not have
3061 * anything to do here, so clear out the list
3062 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003063 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003064 }
3065}
3066
3067/**
Bruce Allanad680762008-03-28 09:15:03 -07003068 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003069 * @adapter: private board structure
3070 **/
3071static void e1000_configure(struct e1000_adapter *adapter)
3072{
3073 e1000_set_multi(adapter->netdev);
3074
3075 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003076 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003077
3078 e1000_configure_tx(adapter);
3079 e1000_setup_rctl(adapter);
3080 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003081 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003082}
3083
3084/**
3085 * e1000e_power_up_phy - restore link in case the phy was powered down
3086 * @adapter: address of board private structure
3087 *
3088 * The phy may be powered down to save power and turn off link when the
3089 * driver is unloaded and wake on lan is not enabled (among others)
3090 * *** this routine MUST be followed by a call to e1000e_reset ***
3091 **/
3092void e1000e_power_up_phy(struct e1000_adapter *adapter)
3093{
Bruce Allan17f208d2009-12-01 15:47:22 +00003094 if (adapter->hw.phy.ops.power_up)
3095 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096
3097 adapter->hw.mac.ops.setup_link(&adapter->hw);
3098}
3099
3100/**
3101 * e1000_power_down_phy - Power down the PHY
3102 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003103 * Power down the PHY so no link is implied when interface is down.
3104 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003105 */
3106static void e1000_power_down_phy(struct e1000_adapter *adapter)
3107{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003108 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003109 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003110 return;
3111
Bruce Allan17f208d2009-12-01 15:47:22 +00003112 if (adapter->hw.phy.ops.power_down)
3113 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003114}
3115
3116/**
3117 * e1000e_reset - bring the hardware into a known good state
3118 *
3119 * This function boots the hardware and enables some settings that
3120 * require a configuration cycle of the hardware - those cannot be
3121 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003122 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003123 */
3124void e1000e_reset(struct e1000_adapter *adapter)
3125{
3126 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003127 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128 struct e1000_hw *hw = &adapter->hw;
3129 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003130 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003131 u16 hwm;
3132
Bruce Allanad680762008-03-28 09:15:03 -07003133 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003134 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003135
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003136 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003137 /*
3138 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003139 * large enough to accommodate two full transmit packets,
3140 * rounded up to the next 1KB and expressed in KB. Likewise,
3141 * the Rx FIFO should be large enough to accommodate at least
3142 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003143 * expressed in KB.
3144 */
Auke Kokdf762462007-10-25 13:57:53 -07003145 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003147 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003148 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003149 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003150 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003151 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003152 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003153 */
3154 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003155 sizeof(struct e1000_tx_desc) -
3156 ETH_FCS_LEN) * 2;
3157 min_tx_space = ALIGN(min_tx_space, 1024);
3158 min_tx_space >>= 10;
3159 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003160 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003161 min_rx_space = ALIGN(min_rx_space, 1024);
3162 min_rx_space >>= 10;
3163
Bruce Allanad680762008-03-28 09:15:03 -07003164 /*
3165 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003166 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003167 * allocation, take space away from current Rx allocation
3168 */
Auke Kokdf762462007-10-25 13:57:53 -07003169 if ((tx_space < min_tx_space) &&
3170 ((min_tx_space - tx_space) < pba)) {
3171 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003172
Bruce Allanad680762008-03-28 09:15:03 -07003173 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003174 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003175 * adjustment or use Early Receive if available
3176 */
Auke Kokdf762462007-10-25 13:57:53 -07003177 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003178 (!(adapter->flags & FLAG_HAS_ERT)))
3179 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003180 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003181 }
Auke Kokdf762462007-10-25 13:57:53 -07003182
3183 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003184 }
3185
Bruce Allanad680762008-03-28 09:15:03 -07003186 /*
3187 * flow control settings
3188 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003189 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003190 * (or the size used for early receive) above it in the Rx FIFO.
3191 * Set it to the lower of:
3192 * - 90% of the Rx FIFO size, and
3193 * - the full Rx FIFO size minus the early receive size (for parts
3194 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003195 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003196 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003197 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3198 fc->pause_time = 0xFFFF;
3199 else
3200 fc->pause_time = E1000_FC_PAUSE_TIME;
3201 fc->send_xon = 1;
3202 fc->current_mode = fc->requested_mode;
3203
3204 switch (hw->mac.type) {
3205 default:
3206 if ((adapter->flags & FLAG_HAS_ERT) &&
3207 (adapter->netdev->mtu > ETH_DATA_LEN))
3208 hwm = min(((pba << 10) * 9 / 10),
3209 ((pba << 10) - (E1000_ERT_2048 << 3)));
3210 else
3211 hwm = min(((pba << 10) * 9 / 10),
3212 ((pba << 10) - adapter->max_frame_size));
3213
3214 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3215 fc->low_water = fc->high_water - 8;
3216 break;
3217 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003218 /*
3219 * Workaround PCH LOM adapter hangs with certain network
3220 * loads. If hangs persist, try disabling Tx flow control.
3221 */
3222 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3223 fc->high_water = 0x3500;
3224 fc->low_water = 0x1500;
3225 } else {
3226 fc->high_water = 0x5000;
3227 fc->low_water = 0x3000;
3228 }
Bruce Allana3055952010-05-10 15:02:12 +00003229 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003230 break;
3231 case e1000_pch2lan:
3232 fc->high_water = 0x05C20;
3233 fc->low_water = 0x05048;
3234 fc->pause_time = 0x0650;
3235 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003236 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3237 pba = 14;
3238 ew32(PBA, pba);
3239 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003240 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003241 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003242
Bruce Allan828bac82010-09-29 21:39:37 +00003243 /*
3244 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3245 * fit in receive buffer and early-receive not supported.
3246 */
3247 if (adapter->itr_setting & 0x3) {
3248 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3249 !(adapter->flags & FLAG_HAS_ERT)) {
3250 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3251 dev_info(&adapter->pdev->dev,
3252 "Interrupt Throttle Rate turned off\n");
3253 adapter->flags2 |= FLAG2_DISABLE_AIM;
3254 ew32(ITR, 0);
3255 }
3256 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3257 dev_info(&adapter->pdev->dev,
3258 "Interrupt Throttle Rate turned on\n");
3259 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3260 adapter->itr = 20000;
3261 ew32(ITR, 1000000000 / (adapter->itr * 256));
3262 }
3263 }
3264
Auke Kokbc7f75f2007-09-17 12:30:59 -07003265 /* Allow time for pending master requests to run */
3266 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003267
3268 /*
3269 * For parts with AMT enabled, let the firmware know
3270 * that the network interface is in control
3271 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003272 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003273 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003274
Auke Kokbc7f75f2007-09-17 12:30:59 -07003275 ew32(WUC, 0);
3276
3277 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003278 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003279
3280 e1000_update_mng_vlan(adapter);
3281
3282 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3283 ew32(VET, ETH_P_8021Q);
3284
3285 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003286
3287 if (!netif_running(adapter->netdev) &&
3288 !test_bit(__E1000_TESTING, &adapter->state)) {
3289 e1000_power_down_phy(adapter);
3290 return;
3291 }
3292
Auke Kokbc7f75f2007-09-17 12:30:59 -07003293 e1000_get_phy_info(hw);
3294
Bruce Allan918d7192009-06-02 11:28:20 +00003295 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3296 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003297 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003298 /*
3299 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003300 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003301 * different we would do if it failed
3302 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003303 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3304 phy_data &= ~IGP02E1000_PM_SPD;
3305 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3306 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003307}
3308
3309int e1000e_up(struct e1000_adapter *adapter)
3310{
3311 struct e1000_hw *hw = &adapter->hw;
3312
3313 /* hardware has been reset, we need to reload some things */
3314 e1000_configure(adapter);
3315
3316 clear_bit(__E1000_DOWN, &adapter->state);
3317
3318 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003319 if (adapter->msix_entries)
3320 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003321 e1000_irq_enable(adapter);
3322
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003323 netif_wake_queue(adapter->netdev);
3324
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003326 if (adapter->msix_entries)
3327 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3328 else
3329 ew32(ICS, E1000_ICS_LSC);
3330
Auke Kokbc7f75f2007-09-17 12:30:59 -07003331 return 0;
3332}
3333
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003334static void e1000e_update_stats(struct e1000_adapter *adapter);
3335
Auke Kokbc7f75f2007-09-17 12:30:59 -07003336void e1000e_down(struct e1000_adapter *adapter)
3337{
3338 struct net_device *netdev = adapter->netdev;
3339 struct e1000_hw *hw = &adapter->hw;
3340 u32 tctl, rctl;
3341
Bruce Allanad680762008-03-28 09:15:03 -07003342 /*
3343 * signal that we're down so the interrupt handler does not
3344 * reschedule our watchdog timer
3345 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003346 set_bit(__E1000_DOWN, &adapter->state);
3347
3348 /* disable receives in the hardware */
3349 rctl = er32(RCTL);
3350 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3351 /* flush and sleep below */
3352
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003353 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003354
3355 /* disable transmits in the hardware */
3356 tctl = er32(TCTL);
3357 tctl &= ~E1000_TCTL_EN;
3358 ew32(TCTL, tctl);
3359 /* flush both disables and wait for them to finish */
3360 e1e_flush();
3361 msleep(10);
3362
3363 napi_disable(&adapter->napi);
3364 e1000_irq_disable(adapter);
3365
3366 del_timer_sync(&adapter->watchdog_timer);
3367 del_timer_sync(&adapter->phy_info_timer);
3368
Auke Kokbc7f75f2007-09-17 12:30:59 -07003369 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003370
3371 spin_lock(&adapter->stats64_lock);
3372 e1000e_update_stats(adapter);
3373 spin_unlock(&adapter->stats64_lock);
3374
Auke Kokbc7f75f2007-09-17 12:30:59 -07003375 adapter->link_speed = 0;
3376 adapter->link_duplex = 0;
3377
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003378 if (!pci_channel_offline(adapter->pdev))
3379 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003380 e1000_clean_tx_ring(adapter);
3381 e1000_clean_rx_ring(adapter);
3382
3383 /*
3384 * TODO: for power management, we could drop the link and
3385 * pci_disable_device here.
3386 */
3387}
3388
3389void e1000e_reinit_locked(struct e1000_adapter *adapter)
3390{
3391 might_sleep();
3392 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3393 msleep(1);
3394 e1000e_down(adapter);
3395 e1000e_up(adapter);
3396 clear_bit(__E1000_RESETTING, &adapter->state);
3397}
3398
3399/**
3400 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3401 * @adapter: board private structure to initialize
3402 *
3403 * e1000_sw_init initializes the Adapter private data structure.
3404 * Fields are initialized based on PCI device information and
3405 * OS network device settings (MTU size).
3406 **/
3407static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3408{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003409 struct net_device *netdev = adapter->netdev;
3410
3411 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3412 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003413 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3414 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003415
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003416 spin_lock_init(&adapter->stats64_lock);
3417
Bruce Allan4662e822008-08-26 18:37:06 -07003418 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003419
Bruce Allan4662e822008-08-26 18:37:06 -07003420 if (e1000_alloc_queues(adapter))
3421 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003422
Auke Kokbc7f75f2007-09-17 12:30:59 -07003423 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003424 e1000_irq_disable(adapter);
3425
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426 set_bit(__E1000_DOWN, &adapter->state);
3427 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003428}
3429
3430/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003431 * e1000_intr_msi_test - Interrupt Handler
3432 * @irq: interrupt number
3433 * @data: pointer to a network interface device structure
3434 **/
3435static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3436{
3437 struct net_device *netdev = data;
3438 struct e1000_adapter *adapter = netdev_priv(netdev);
3439 struct e1000_hw *hw = &adapter->hw;
3440 u32 icr = er32(ICR);
3441
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003442 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003443 if (icr & E1000_ICR_RXSEQ) {
3444 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3445 wmb();
3446 }
3447
3448 return IRQ_HANDLED;
3449}
3450
3451/**
3452 * e1000_test_msi_interrupt - Returns 0 for successful test
3453 * @adapter: board private struct
3454 *
3455 * code flow taken from tg3.c
3456 **/
3457static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3458{
3459 struct net_device *netdev = adapter->netdev;
3460 struct e1000_hw *hw = &adapter->hw;
3461 int err;
3462
3463 /* poll_enable hasn't been called yet, so don't need disable */
3464 /* clear any pending events */
3465 er32(ICR);
3466
3467 /* free the real vector and request a test handler */
3468 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003469 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003470
3471 /* Assume that the test fails, if it succeeds then the test
3472 * MSI irq handler will unset this flag */
3473 adapter->flags |= FLAG_MSI_TEST_FAILED;
3474
3475 err = pci_enable_msi(adapter->pdev);
3476 if (err)
3477 goto msi_test_failed;
3478
Joe Perchesa0607fd2009-11-18 23:29:17 -08003479 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003480 netdev->name, netdev);
3481 if (err) {
3482 pci_disable_msi(adapter->pdev);
3483 goto msi_test_failed;
3484 }
3485
3486 wmb();
3487
3488 e1000_irq_enable(adapter);
3489
3490 /* fire an unusual interrupt on the test handler */
3491 ew32(ICS, E1000_ICS_RXSEQ);
3492 e1e_flush();
3493 msleep(50);
3494
3495 e1000_irq_disable(adapter);
3496
3497 rmb();
3498
3499 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003500 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003501 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3502 } else
3503 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003504
3505 free_irq(adapter->pdev->irq, netdev);
3506 pci_disable_msi(adapter->pdev);
3507
Bruce Allanf8d59f72008-08-08 18:36:11 -07003508msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003509 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003510 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003511}
3512
3513/**
3514 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3515 * @adapter: board private struct
3516 *
3517 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3518 **/
3519static int e1000_test_msi(struct e1000_adapter *adapter)
3520{
3521 int err;
3522 u16 pci_cmd;
3523
3524 if (!(adapter->flags & FLAG_MSI_ENABLED))
3525 return 0;
3526
3527 /* disable SERR in case the MSI write causes a master abort */
3528 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003529 if (pci_cmd & PCI_COMMAND_SERR)
3530 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3531 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003532
3533 err = e1000_test_msi_interrupt(adapter);
3534
Dean Nelson36f24072010-06-29 18:12:05 +00003535 /* re-enable SERR */
3536 if (pci_cmd & PCI_COMMAND_SERR) {
3537 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3538 pci_cmd |= PCI_COMMAND_SERR;
3539 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3540 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003541
Bruce Allanf8d59f72008-08-08 18:36:11 -07003542 return err;
3543}
3544
3545/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003546 * e1000_open - Called when a network interface is made active
3547 * @netdev: network interface device structure
3548 *
3549 * Returns 0 on success, negative value on failure
3550 *
3551 * The open entry point is called when a network interface is made
3552 * active by the system (IFF_UP). At this point all resources needed
3553 * for transmit and receive operations are allocated, the interrupt
3554 * handler is registered with the OS, the watchdog timer is started,
3555 * and the stack is notified that the interface is ready.
3556 **/
3557static int e1000_open(struct net_device *netdev)
3558{
3559 struct e1000_adapter *adapter = netdev_priv(netdev);
3560 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003561 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003562 int err;
3563
3564 /* disallow open during test */
3565 if (test_bit(__E1000_TESTING, &adapter->state))
3566 return -EBUSY;
3567
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003568 pm_runtime_get_sync(&pdev->dev);
3569
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003570 netif_carrier_off(netdev);
3571
Auke Kokbc7f75f2007-09-17 12:30:59 -07003572 /* allocate transmit descriptors */
3573 err = e1000e_setup_tx_resources(adapter);
3574 if (err)
3575 goto err_setup_tx;
3576
3577 /* allocate receive descriptors */
3578 err = e1000e_setup_rx_resources(adapter);
3579 if (err)
3580 goto err_setup_rx;
3581
Bruce Allan11b08be2010-05-10 14:59:31 +00003582 /*
3583 * If AMT is enabled, let the firmware know that the network
3584 * interface is now open and reset the part to a known state.
3585 */
3586 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003587 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003588 e1000e_reset(adapter);
3589 }
3590
Auke Kokbc7f75f2007-09-17 12:30:59 -07003591 e1000e_power_up_phy(adapter);
3592
3593 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3594 if ((adapter->hw.mng_cookie.status &
3595 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3596 e1000_update_mng_vlan(adapter);
3597
Florian Micklerc128ec22010-08-02 14:27:00 +00003598 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003599 if ((adapter->flags & FLAG_HAS_ERT) ||
3600 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003601 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3602 PM_QOS_CPU_DMA_LATENCY,
3603 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003604
Bruce Allanad680762008-03-28 09:15:03 -07003605 /*
Bruce Allanad680762008-03-28 09:15:03 -07003606 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003607 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3608 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003609 * clean_rx handler before we do so.
3610 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003611 e1000_configure(adapter);
3612
3613 err = e1000_request_irq(adapter);
3614 if (err)
3615 goto err_req_irq;
3616
Bruce Allanf8d59f72008-08-08 18:36:11 -07003617 /*
3618 * Work around PCIe errata with MSI interrupts causing some chipsets to
3619 * ignore e1000e MSI messages, which means we need to test our MSI
3620 * interrupt now
3621 */
Bruce Allan4662e822008-08-26 18:37:06 -07003622 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003623 err = e1000_test_msi(adapter);
3624 if (err) {
3625 e_err("Interrupt allocation failed\n");
3626 goto err_req_irq;
3627 }
3628 }
3629
Auke Kokbc7f75f2007-09-17 12:30:59 -07003630 /* From here on the code is the same as e1000e_up() */
3631 clear_bit(__E1000_DOWN, &adapter->state);
3632
3633 napi_enable(&adapter->napi);
3634
3635 e1000_irq_enable(adapter);
3636
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003637 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003638
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003639 adapter->idle_check = true;
3640 pm_runtime_put(&pdev->dev);
3641
Auke Kokbc7f75f2007-09-17 12:30:59 -07003642 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003643 if (adapter->msix_entries)
3644 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3645 else
3646 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003647
3648 return 0;
3649
3650err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003651 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003652 e1000_power_down_phy(adapter);
3653 e1000e_free_rx_resources(adapter);
3654err_setup_rx:
3655 e1000e_free_tx_resources(adapter);
3656err_setup_tx:
3657 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003658 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003659
3660 return err;
3661}
3662
3663/**
3664 * e1000_close - Disables a network interface
3665 * @netdev: network interface device structure
3666 *
3667 * Returns 0, this is not allowed to fail
3668 *
3669 * The close entry point is called when an interface is de-activated
3670 * by the OS. The hardware is still under the drivers control, but
3671 * needs to be disabled. A global MAC reset is issued to stop the
3672 * hardware, and all transmit and receive resources are freed.
3673 **/
3674static int e1000_close(struct net_device *netdev)
3675{
3676 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003677 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003678
3679 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003680
3681 pm_runtime_get_sync(&pdev->dev);
3682
3683 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3684 e1000e_down(adapter);
3685 e1000_free_irq(adapter);
3686 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003687 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003688
3689 e1000e_free_tx_resources(adapter);
3690 e1000e_free_rx_resources(adapter);
3691
Bruce Allanad680762008-03-28 09:15:03 -07003692 /*
3693 * kill manageability vlan ID if supported, but not if a vlan with
3694 * the same ID is registered on the host OS (let 8021q kill it)
3695 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696 if ((adapter->hw.mng_cookie.status &
3697 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3698 !(adapter->vlgrp &&
3699 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3700 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3701
Bruce Allanad680762008-03-28 09:15:03 -07003702 /*
3703 * If AMT is enabled, let the firmware know that the network
3704 * interface is now closed
3705 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003706 if ((adapter->flags & FLAG_HAS_AMT) &&
3707 !test_bit(__E1000_TESTING, &adapter->state))
3708 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003709
Bruce Allan828bac82010-09-29 21:39:37 +00003710 if ((adapter->flags & FLAG_HAS_ERT) ||
3711 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003712 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003713
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003714 pm_runtime_put_sync(&pdev->dev);
3715
Auke Kokbc7f75f2007-09-17 12:30:59 -07003716 return 0;
3717}
3718/**
3719 * e1000_set_mac - Change the Ethernet Address of the NIC
3720 * @netdev: network interface device structure
3721 * @p: pointer to an address structure
3722 *
3723 * Returns 0 on success, negative on failure
3724 **/
3725static int e1000_set_mac(struct net_device *netdev, void *p)
3726{
3727 struct e1000_adapter *adapter = netdev_priv(netdev);
3728 struct sockaddr *addr = p;
3729
3730 if (!is_valid_ether_addr(addr->sa_data))
3731 return -EADDRNOTAVAIL;
3732
3733 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3734 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3735
3736 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3737
3738 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3739 /* activate the work around */
3740 e1000e_set_laa_state_82571(&adapter->hw, 1);
3741
Bruce Allanad680762008-03-28 09:15:03 -07003742 /*
3743 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003744 * between the time RAR[0] gets clobbered and the time it
3745 * gets fixed (in e1000_watchdog), the actual LAA is in one
3746 * of the RARs and no incoming packets directed to this port
3747 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003748 * RAR[14]
3749 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750 e1000e_rar_set(&adapter->hw,
3751 adapter->hw.mac.addr,
3752 adapter->hw.mac.rar_entry_count - 1);
3753 }
3754
3755 return 0;
3756}
3757
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003758/**
3759 * e1000e_update_phy_task - work thread to update phy
3760 * @work: pointer to our work struct
3761 *
3762 * this worker thread exists because we must acquire a
3763 * semaphore to read the phy, which we could msleep while
3764 * waiting for it, and we can't msleep in a timer.
3765 **/
3766static void e1000e_update_phy_task(struct work_struct *work)
3767{
3768 struct e1000_adapter *adapter = container_of(work,
3769 struct e1000_adapter, update_phy_task);
3770 e1000_get_phy_info(&adapter->hw);
3771}
3772
Bruce Allanad680762008-03-28 09:15:03 -07003773/*
3774 * Need to wait a few seconds after link up to get diagnostic information from
3775 * the phy
3776 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003777static void e1000_update_phy_info(unsigned long data)
3778{
3779 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003780 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003781}
3782
3783/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003784 * e1000e_update_phy_stats - Update the PHY statistics counters
3785 * @adapter: board private structure
3786 **/
3787static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3788{
3789 struct e1000_hw *hw = &adapter->hw;
3790 s32 ret_val;
3791 u16 phy_data;
3792
3793 ret_val = hw->phy.ops.acquire(hw);
3794 if (ret_val)
3795 return;
3796
3797 hw->phy.addr = 1;
3798
3799#define HV_PHY_STATS_PAGE 778
3800 /*
3801 * A page set is expensive so check if already on desired page.
3802 * If not, set to the page with the PHY status registers.
3803 */
3804 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3805 &phy_data);
3806 if (ret_val)
3807 goto release;
3808 if (phy_data != (HV_PHY_STATS_PAGE << IGP_PAGE_SHIFT)) {
3809 ret_val = e1000e_write_phy_reg_mdic(hw,
3810 IGP01E1000_PHY_PAGE_SELECT,
3811 (HV_PHY_STATS_PAGE <<
3812 IGP_PAGE_SHIFT));
3813 if (ret_val)
3814 goto release;
3815 }
3816
3817 /* Read/clear the upper 16-bit registers and read/accumulate lower */
3818
3819 /* Single Collision Count */
3820 e1000e_read_phy_reg_mdic(hw, HV_SCC_UPPER & MAX_PHY_REG_ADDRESS,
3821 &phy_data);
3822 ret_val = e1000e_read_phy_reg_mdic(hw,
3823 HV_SCC_LOWER & MAX_PHY_REG_ADDRESS,
3824 &phy_data);
3825 if (!ret_val)
3826 adapter->stats.scc += phy_data;
3827
3828 /* Excessive Collision Count */
3829 e1000e_read_phy_reg_mdic(hw, HV_ECOL_UPPER & MAX_PHY_REG_ADDRESS,
3830 &phy_data);
3831 ret_val = e1000e_read_phy_reg_mdic(hw,
3832 HV_ECOL_LOWER & MAX_PHY_REG_ADDRESS,
3833 &phy_data);
3834 if (!ret_val)
3835 adapter->stats.ecol += phy_data;
3836
3837 /* Multiple Collision Count */
3838 e1000e_read_phy_reg_mdic(hw, HV_MCC_UPPER & MAX_PHY_REG_ADDRESS,
3839 &phy_data);
3840 ret_val = e1000e_read_phy_reg_mdic(hw,
3841 HV_MCC_LOWER & MAX_PHY_REG_ADDRESS,
3842 &phy_data);
3843 if (!ret_val)
3844 adapter->stats.mcc += phy_data;
3845
3846 /* Late Collision Count */
3847 e1000e_read_phy_reg_mdic(hw, HV_LATECOL_UPPER & MAX_PHY_REG_ADDRESS,
3848 &phy_data);
3849 ret_val = e1000e_read_phy_reg_mdic(hw,
3850 HV_LATECOL_LOWER &
3851 MAX_PHY_REG_ADDRESS,
3852 &phy_data);
3853 if (!ret_val)
3854 adapter->stats.latecol += phy_data;
3855
3856 /* Collision Count - also used for adaptive IFS */
3857 e1000e_read_phy_reg_mdic(hw, HV_COLC_UPPER & MAX_PHY_REG_ADDRESS,
3858 &phy_data);
3859 ret_val = e1000e_read_phy_reg_mdic(hw,
3860 HV_COLC_LOWER & MAX_PHY_REG_ADDRESS,
3861 &phy_data);
3862 if (!ret_val)
3863 hw->mac.collision_delta = phy_data;
3864
3865 /* Defer Count */
3866 e1000e_read_phy_reg_mdic(hw, HV_DC_UPPER & MAX_PHY_REG_ADDRESS,
3867 &phy_data);
3868 ret_val = e1000e_read_phy_reg_mdic(hw,
3869 HV_DC_LOWER & MAX_PHY_REG_ADDRESS,
3870 &phy_data);
3871 if (!ret_val)
3872 adapter->stats.dc += phy_data;
3873
3874 /* Transmit with no CRS */
3875 e1000e_read_phy_reg_mdic(hw, HV_TNCRS_UPPER & MAX_PHY_REG_ADDRESS,
3876 &phy_data);
3877 ret_val = e1000e_read_phy_reg_mdic(hw,
3878 HV_TNCRS_LOWER & MAX_PHY_REG_ADDRESS,
3879 &phy_data);
3880 if (!ret_val)
3881 adapter->stats.tncrs += phy_data;
3882
3883release:
3884 hw->phy.ops.release(hw);
3885}
3886
3887/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003888 * e1000e_update_stats - Update the board statistics counters
3889 * @adapter: board private structure
3890 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003891static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003892{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003893 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003894 struct e1000_hw *hw = &adapter->hw;
3895 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003896
3897 /*
3898 * Prevent stats update while adapter is being reset, or if the pci
3899 * connection is down.
3900 */
3901 if (adapter->link_speed == 0)
3902 return;
3903 if (pci_channel_offline(pdev))
3904 return;
3905
Auke Kokbc7f75f2007-09-17 12:30:59 -07003906 adapter->stats.crcerrs += er32(CRCERRS);
3907 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003908 adapter->stats.gorc += er32(GORCL);
3909 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003910 adapter->stats.bprc += er32(BPRC);
3911 adapter->stats.mprc += er32(MPRC);
3912 adapter->stats.roc += er32(ROC);
3913
Auke Kokbc7f75f2007-09-17 12:30:59 -07003914 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003915
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003916 /* Half-duplex statistics */
3917 if (adapter->link_duplex == HALF_DUPLEX) {
3918 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
3919 e1000e_update_phy_stats(adapter);
3920 } else {
3921 adapter->stats.scc += er32(SCC);
3922 adapter->stats.ecol += er32(ECOL);
3923 adapter->stats.mcc += er32(MCC);
3924 adapter->stats.latecol += er32(LATECOL);
3925 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003926
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003927 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003928
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003929 if ((hw->mac.type != e1000_82574) &&
3930 (hw->mac.type != e1000_82583))
3931 adapter->stats.tncrs += er32(TNCRS);
3932 }
3933 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003934 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003935
Auke Kokbc7f75f2007-09-17 12:30:59 -07003936 adapter->stats.xonrxc += er32(XONRXC);
3937 adapter->stats.xontxc += er32(XONTXC);
3938 adapter->stats.xoffrxc += er32(XOFFRXC);
3939 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003940 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003941 adapter->stats.gotc += er32(GOTCL);
3942 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003943 adapter->stats.rnbc += er32(RNBC);
3944 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003945
3946 adapter->stats.mptc += er32(MPTC);
3947 adapter->stats.bptc += er32(BPTC);
3948
3949 /* used for adaptive IFS */
3950
3951 hw->mac.tx_packet_delta = er32(TPT);
3952 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003953
3954 adapter->stats.algnerrc += er32(ALGNERRC);
3955 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003956 adapter->stats.cexterr += er32(CEXTERR);
3957 adapter->stats.tsctc += er32(TSCTC);
3958 adapter->stats.tsctfc += er32(TSCTFC);
3959
Auke Kokbc7f75f2007-09-17 12:30:59 -07003960 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003961 netdev->stats.multicast = adapter->stats.mprc;
3962 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003963
3964 /* Rx Errors */
3965
Bruce Allanad680762008-03-28 09:15:03 -07003966 /*
3967 * RLEC on some newer hardware can be incorrect so build
3968 * our own version based on RUC and ROC
3969 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003970 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003971 adapter->stats.crcerrs + adapter->stats.algnerrc +
3972 adapter->stats.ruc + adapter->stats.roc +
3973 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003974 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003975 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003976 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3977 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3978 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003979
3980 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003981 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003982 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003983 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3984 netdev->stats.tx_window_errors = adapter->stats.latecol;
3985 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003986
3987 /* Tx Dropped needs to be maintained elsewhere */
3988
Auke Kokbc7f75f2007-09-17 12:30:59 -07003989 /* Management Stats */
3990 adapter->stats.mgptc += er32(MGTPTC);
3991 adapter->stats.mgprc += er32(MGTPRC);
3992 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003993}
3994
Bruce Allan7c257692008-04-23 11:09:00 -07003995/**
3996 * e1000_phy_read_status - Update the PHY register status snapshot
3997 * @adapter: board private structure
3998 **/
3999static void e1000_phy_read_status(struct e1000_adapter *adapter)
4000{
4001 struct e1000_hw *hw = &adapter->hw;
4002 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004003
4004 if ((er32(STATUS) & E1000_STATUS_LU) &&
4005 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004006 int ret_val;
4007
Bruce Allan7c257692008-04-23 11:09:00 -07004008 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4009 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4010 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4011 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4012 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4013 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4014 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4015 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4016 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004017 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004018 } else {
4019 /*
4020 * Do not read PHY registers if link is not up
4021 * Set values to typical power-on defaults
4022 */
4023 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4024 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4025 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4026 BMSR_ERCAP);
4027 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4028 ADVERTISE_ALL | ADVERTISE_CSMA);
4029 phy->lpa = 0;
4030 phy->expansion = EXPANSION_ENABLENPAGE;
4031 phy->ctrl1000 = ADVERTISE_1000FULL;
4032 phy->stat1000 = 0;
4033 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4034 }
Bruce Allan7c257692008-04-23 11:09:00 -07004035}
4036
Auke Kokbc7f75f2007-09-17 12:30:59 -07004037static void e1000_print_link_info(struct e1000_adapter *adapter)
4038{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004039 struct e1000_hw *hw = &adapter->hw;
4040 u32 ctrl = er32(CTRL);
4041
Bruce Allan8f12fe82008-11-21 16:54:43 -08004042 /* Link status message must follow this format for user tools */
4043 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4044 "Flow Control: %s\n",
4045 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004046 adapter->link_speed,
4047 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004048 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004049 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004050 "Rx/Tx" :
4051 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4052 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004053}
4054
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004055static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004056{
4057 struct e1000_hw *hw = &adapter->hw;
4058 bool link_active = 0;
4059 s32 ret_val = 0;
4060
4061 /*
4062 * get_link_status is set on LSC (link status) interrupt or
4063 * Rx sequence error interrupt. get_link_status will stay
4064 * false until the check_for_link establishes link
4065 * for copper adapters ONLY
4066 */
4067 switch (hw->phy.media_type) {
4068 case e1000_media_type_copper:
4069 if (hw->mac.get_link_status) {
4070 ret_val = hw->mac.ops.check_for_link(hw);
4071 link_active = !hw->mac.get_link_status;
4072 } else {
4073 link_active = 1;
4074 }
4075 break;
4076 case e1000_media_type_fiber:
4077 ret_val = hw->mac.ops.check_for_link(hw);
4078 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4079 break;
4080 case e1000_media_type_internal_serdes:
4081 ret_val = hw->mac.ops.check_for_link(hw);
4082 link_active = adapter->hw.mac.serdes_has_link;
4083 break;
4084 default:
4085 case e1000_media_type_unknown:
4086 break;
4087 }
4088
4089 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4090 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4091 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004092 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004093 }
4094
4095 return link_active;
4096}
4097
4098static void e1000e_enable_receives(struct e1000_adapter *adapter)
4099{
4100 /* make sure the receive unit is started */
4101 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4102 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4103 struct e1000_hw *hw = &adapter->hw;
4104 u32 rctl = er32(RCTL);
4105 ew32(RCTL, rctl | E1000_RCTL_EN);
4106 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4107 }
4108}
4109
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004110static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4111{
4112 struct e1000_hw *hw = &adapter->hw;
4113
4114 /*
4115 * With 82574 controllers, PHY needs to be checked periodically
4116 * for hung state and reset, if two calls return true
4117 */
4118 if (e1000_check_phy_82574(hw))
4119 adapter->phy_hang_count++;
4120 else
4121 adapter->phy_hang_count = 0;
4122
4123 if (adapter->phy_hang_count > 1) {
4124 adapter->phy_hang_count = 0;
4125 schedule_work(&adapter->reset_task);
4126 }
4127}
4128
Auke Kokbc7f75f2007-09-17 12:30:59 -07004129/**
4130 * e1000_watchdog - Timer Call-back
4131 * @data: pointer to adapter cast into an unsigned long
4132 **/
4133static void e1000_watchdog(unsigned long data)
4134{
4135 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4136
4137 /* Do the rest outside of interrupt context */
4138 schedule_work(&adapter->watchdog_task);
4139
4140 /* TODO: make this use queue_delayed_work() */
4141}
4142
4143static void e1000_watchdog_task(struct work_struct *work)
4144{
4145 struct e1000_adapter *adapter = container_of(work,
4146 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004147 struct net_device *netdev = adapter->netdev;
4148 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004149 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004150 struct e1000_ring *tx_ring = adapter->tx_ring;
4151 struct e1000_hw *hw = &adapter->hw;
4152 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004153
David S. Millerb405e8d2010-02-04 22:31:41 -08004154 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004155 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004156 /* Cancel scheduled suspend requests. */
4157 pm_runtime_resume(netdev->dev.parent);
4158
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004159 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004160 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004161 }
4162
4163 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4164 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4165 e1000_update_mng_vlan(adapter);
4166
Auke Kokbc7f75f2007-09-17 12:30:59 -07004167 if (link) {
4168 if (!netif_carrier_ok(netdev)) {
4169 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004170
4171 /* Cancel scheduled suspend requests. */
4172 pm_runtime_resume(netdev->dev.parent);
4173
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004174 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004175 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176 mac->ops.get_link_up_info(&adapter->hw,
4177 &adapter->link_speed,
4178 &adapter->link_duplex);
4179 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004180 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004181 * On supported PHYs, check for duplex mismatch only
4182 * if link has autonegotiated at 10/100 half
4183 */
4184 if ((hw->phy.type == e1000_phy_igp_3 ||
4185 hw->phy.type == e1000_phy_bm) &&
4186 (hw->mac.autoneg == true) &&
4187 (adapter->link_speed == SPEED_10 ||
4188 adapter->link_speed == SPEED_100) &&
4189 (adapter->link_duplex == HALF_DUPLEX)) {
4190 u16 autoneg_exp;
4191
4192 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4193
4194 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4195 e_info("Autonegotiated half duplex but"
4196 " link partner cannot autoneg. "
4197 " Try forcing full duplex if "
4198 "link gets many collisions.\n");
4199 }
4200
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004201 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004202 adapter->tx_timeout_factor = 1;
4203 switch (adapter->link_speed) {
4204 case SPEED_10:
4205 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004206 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004207 break;
4208 case SPEED_100:
4209 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004210 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004211 break;
4212 }
4213
Bruce Allanad680762008-03-28 09:15:03 -07004214 /*
4215 * workaround: re-program speed mode bit after
4216 * link-up event
4217 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004218 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4219 !txb2b) {
4220 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004221 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004223 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004224 }
4225
Bruce Allanad680762008-03-28 09:15:03 -07004226 /*
4227 * disable TSO for pcie and 10/100 speeds, to avoid
4228 * some hardware issues
4229 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004230 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4231 switch (adapter->link_speed) {
4232 case SPEED_10:
4233 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004234 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004235 netdev->features &= ~NETIF_F_TSO;
4236 netdev->features &= ~NETIF_F_TSO6;
4237 break;
4238 case SPEED_1000:
4239 netdev->features |= NETIF_F_TSO;
4240 netdev->features |= NETIF_F_TSO6;
4241 break;
4242 default:
4243 /* oops */
4244 break;
4245 }
4246 }
4247
Bruce Allanad680762008-03-28 09:15:03 -07004248 /*
4249 * enable transmits in the hardware, need to do this
4250 * after setting TARC(0)
4251 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004252 tctl = er32(TCTL);
4253 tctl |= E1000_TCTL_EN;
4254 ew32(TCTL, tctl);
4255
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004256 /*
4257 * Perform any post-link-up configuration before
4258 * reporting link up.
4259 */
4260 if (phy->ops.cfg_on_link_up)
4261 phy->ops.cfg_on_link_up(hw);
4262
Auke Kokbc7f75f2007-09-17 12:30:59 -07004263 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004264
4265 if (!test_bit(__E1000_DOWN, &adapter->state))
4266 mod_timer(&adapter->phy_info_timer,
4267 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004268 }
4269 } else {
4270 if (netif_carrier_ok(netdev)) {
4271 adapter->link_speed = 0;
4272 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004273 /* Link status message must follow this format */
4274 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4275 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004276 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004277 if (!test_bit(__E1000_DOWN, &adapter->state))
4278 mod_timer(&adapter->phy_info_timer,
4279 round_jiffies(jiffies + 2 * HZ));
4280
4281 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4282 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004283 else
4284 pm_schedule_suspend(netdev->dev.parent,
4285 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004286 }
4287 }
4288
4289link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004290 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004291 e1000e_update_stats(adapter);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004292 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004293
4294 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4295 adapter->tpt_old = adapter->stats.tpt;
4296 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4297 adapter->colc_old = adapter->stats.colc;
4298
Bruce Allan7c257692008-04-23 11:09:00 -07004299 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4300 adapter->gorc_old = adapter->stats.gorc;
4301 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4302 adapter->gotc_old = adapter->stats.gotc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004303
4304 e1000e_update_adaptive(&adapter->hw);
4305
Bruce Allan90da0662011-01-06 07:02:53 +00004306 if (!netif_carrier_ok(netdev) &&
4307 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4308 /*
4309 * We've lost link, so the controller stops DMA,
4310 * but we've got queued Tx work that's never going
4311 * to get done, so reset controller to flush Tx.
4312 * (Do the reset outside of interrupt context).
4313 */
4314 adapter->tx_timeout_count++;
4315 schedule_work(&adapter->reset_task);
4316 /* return immediately since reset is imminent */
4317 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004318 }
4319
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004320 /* Simple mode for Interrupt Throttle Rate (ITR) */
4321 if (adapter->itr_setting == 4) {
4322 /*
4323 * Symmetric Tx/Rx gets a reduced ITR=2000;
4324 * Total asymmetrical Tx or Rx gets ITR=8000;
4325 * everyone else is between 2000-8000.
4326 */
4327 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4328 u32 dif = (adapter->gotc > adapter->gorc ?
4329 adapter->gotc - adapter->gorc :
4330 adapter->gorc - adapter->gotc) / 10000;
4331 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4332
4333 ew32(ITR, 1000000000 / (itr * 256));
4334 }
4335
Bruce Allanad680762008-03-28 09:15:03 -07004336 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004337 if (adapter->msix_entries)
4338 ew32(ICS, adapter->rx_ring->ims_val);
4339 else
4340 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004341
4342 /* Force detection of hung controller every watchdog period */
4343 adapter->detect_tx_hung = 1;
4344
Bruce Allanaf667a22010-12-31 06:10:01 +00004345 /* flush partial descriptors to memory before detecting Tx hang */
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00004346 if (adapter->flags2 & FLAG2_DMA_BURST) {
4347 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4348 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4349 /*
4350 * no need to flush the writes because the timeout code does
4351 * an er32 first thing
4352 */
4353 }
4354
Bruce Allanad680762008-03-28 09:15:03 -07004355 /*
4356 * With 82571 controllers, LAA may be overwritten due to controller
4357 * reset from the other port. Set the appropriate LAA in RAR[0]
4358 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004359 if (e1000e_get_laa_state_82571(hw))
4360 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4361
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004362 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4363 e1000e_check_82574_phy_workaround(adapter);
4364
Auke Kokbc7f75f2007-09-17 12:30:59 -07004365 /* Reset the timer */
4366 if (!test_bit(__E1000_DOWN, &adapter->state))
4367 mod_timer(&adapter->watchdog_timer,
4368 round_jiffies(jiffies + 2 * HZ));
4369}
4370
4371#define E1000_TX_FLAGS_CSUM 0x00000001
4372#define E1000_TX_FLAGS_VLAN 0x00000002
4373#define E1000_TX_FLAGS_TSO 0x00000004
4374#define E1000_TX_FLAGS_IPV4 0x00000008
4375#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4376#define E1000_TX_FLAGS_VLAN_SHIFT 16
4377
4378static int e1000_tso(struct e1000_adapter *adapter,
4379 struct sk_buff *skb)
4380{
4381 struct e1000_ring *tx_ring = adapter->tx_ring;
4382 struct e1000_context_desc *context_desc;
4383 struct e1000_buffer *buffer_info;
4384 unsigned int i;
4385 u32 cmd_length = 0;
4386 u16 ipcse = 0, tucse, mss;
4387 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004388
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004389 if (!skb_is_gso(skb))
4390 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004391
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004392 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004393 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4394
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004395 if (err)
4396 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004397 }
4398
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004399 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4400 mss = skb_shinfo(skb)->gso_size;
4401 if (skb->protocol == htons(ETH_P_IP)) {
4402 struct iphdr *iph = ip_hdr(skb);
4403 iph->tot_len = 0;
4404 iph->check = 0;
4405 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4406 0, IPPROTO_TCP, 0);
4407 cmd_length = E1000_TXD_CMD_IP;
4408 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004409 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004410 ipv6_hdr(skb)->payload_len = 0;
4411 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4412 &ipv6_hdr(skb)->daddr,
4413 0, IPPROTO_TCP, 0);
4414 ipcse = 0;
4415 }
4416 ipcss = skb_network_offset(skb);
4417 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4418 tucss = skb_transport_offset(skb);
4419 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4420 tucse = 0;
4421
4422 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4423 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4424
4425 i = tx_ring->next_to_use;
4426 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4427 buffer_info = &tx_ring->buffer_info[i];
4428
4429 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4430 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4431 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4432 context_desc->upper_setup.tcp_fields.tucss = tucss;
4433 context_desc->upper_setup.tcp_fields.tucso = tucso;
4434 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4435 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4436 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4437 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4438
4439 buffer_info->time_stamp = jiffies;
4440 buffer_info->next_to_watch = i;
4441
4442 i++;
4443 if (i == tx_ring->count)
4444 i = 0;
4445 tx_ring->next_to_use = i;
4446
4447 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004448}
4449
4450static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4451{
4452 struct e1000_ring *tx_ring = adapter->tx_ring;
4453 struct e1000_context_desc *context_desc;
4454 struct e1000_buffer *buffer_info;
4455 unsigned int i;
4456 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004457 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004458 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004459
Dave Grahamaf807c82008-10-09 14:28:58 -07004460 if (skb->ip_summed != CHECKSUM_PARTIAL)
4461 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004462
Arthur Jones5f66f202009-03-19 01:13:08 +00004463 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4464 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4465 else
4466 protocol = skb->protocol;
4467
Arthur Jones3f518392009-03-20 15:56:35 -07004468 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004469 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004470 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4471 cmd_len |= E1000_TXD_CMD_TCP;
4472 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004473 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004474 /* XXX not handling all IPV6 headers */
4475 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4476 cmd_len |= E1000_TXD_CMD_TCP;
4477 break;
4478 default:
4479 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004480 e_warn("checksum_partial proto=%x!\n",
4481 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004482 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004483 }
4484
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004485 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004486
4487 i = tx_ring->next_to_use;
4488 buffer_info = &tx_ring->buffer_info[i];
4489 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4490
4491 context_desc->lower_setup.ip_config = 0;
4492 context_desc->upper_setup.tcp_fields.tucss = css;
4493 context_desc->upper_setup.tcp_fields.tucso =
4494 css + skb->csum_offset;
4495 context_desc->upper_setup.tcp_fields.tucse = 0;
4496 context_desc->tcp_seg_setup.data = 0;
4497 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4498
4499 buffer_info->time_stamp = jiffies;
4500 buffer_info->next_to_watch = i;
4501
4502 i++;
4503 if (i == tx_ring->count)
4504 i = 0;
4505 tx_ring->next_to_use = i;
4506
4507 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004508}
4509
4510#define E1000_MAX_PER_TXD 8192
4511#define E1000_MAX_TXD_PWR 12
4512
4513static int e1000_tx_map(struct e1000_adapter *adapter,
4514 struct sk_buff *skb, unsigned int first,
4515 unsigned int max_per_txd, unsigned int nr_frags,
4516 unsigned int mss)
4517{
4518 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004519 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004520 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004521 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004522 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004523 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004524
4525 i = tx_ring->next_to_use;
4526
4527 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004528 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004529 size = min(len, max_per_txd);
4530
Auke Kokbc7f75f2007-09-17 12:30:59 -07004531 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004532 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004533 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004534 buffer_info->dma = dma_map_single(&pdev->dev,
4535 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004536 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004537 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004538 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004539 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540
4541 len -= size;
4542 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004543 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004544
4545 if (len) {
4546 i++;
4547 if (i == tx_ring->count)
4548 i = 0;
4549 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004550 }
4551
4552 for (f = 0; f < nr_frags; f++) {
4553 struct skb_frag_struct *frag;
4554
4555 frag = &skb_shinfo(skb)->frags[f];
4556 len = frag->size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004557 offset = frag->page_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004558
4559 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004560 i++;
4561 if (i == tx_ring->count)
4562 i = 0;
4563
Auke Kokbc7f75f2007-09-17 12:30:59 -07004564 buffer_info = &tx_ring->buffer_info[i];
4565 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004566
4567 buffer_info->length = size;
4568 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004569 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004570 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
Alexander Duyck03b13202009-12-02 16:45:31 +00004571 offset, size,
Nick Nunley0be3f552010-04-27 13:09:05 +00004572 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004573 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004574 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004575 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004576
4577 len -= size;
4578 offset += size;
4579 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004580 }
4581 }
4582
Bruce Allanaf667a22010-12-31 06:10:01 +00004583 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004584 /* multiply data chunks by size of headers */
4585 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4586
Auke Kokbc7f75f2007-09-17 12:30:59 -07004587 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004588 tx_ring->buffer_info[i].segs = segs;
4589 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004590 tx_ring->buffer_info[first].next_to_watch = i;
4591
4592 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004593
4594dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004595 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004596 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004597 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004598 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004599
4600 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004601 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004602 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004603 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004604 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004605 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004606 }
4607
4608 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004609}
4610
4611static void e1000_tx_queue(struct e1000_adapter *adapter,
4612 int tx_flags, int count)
4613{
4614 struct e1000_ring *tx_ring = adapter->tx_ring;
4615 struct e1000_tx_desc *tx_desc = NULL;
4616 struct e1000_buffer *buffer_info;
4617 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4618 unsigned int i;
4619
4620 if (tx_flags & E1000_TX_FLAGS_TSO) {
4621 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4622 E1000_TXD_CMD_TSE;
4623 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4624
4625 if (tx_flags & E1000_TX_FLAGS_IPV4)
4626 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4627 }
4628
4629 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4630 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4631 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4632 }
4633
4634 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4635 txd_lower |= E1000_TXD_CMD_VLE;
4636 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4637 }
4638
4639 i = tx_ring->next_to_use;
4640
Bruce Allan36b973d2010-11-24 07:42:43 +00004641 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004642 buffer_info = &tx_ring->buffer_info[i];
4643 tx_desc = E1000_TX_DESC(*tx_ring, i);
4644 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4645 tx_desc->lower.data =
4646 cpu_to_le32(txd_lower | buffer_info->length);
4647 tx_desc->upper.data = cpu_to_le32(txd_upper);
4648
4649 i++;
4650 if (i == tx_ring->count)
4651 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004652 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004653
4654 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4655
Bruce Allanad680762008-03-28 09:15:03 -07004656 /*
4657 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004658 * know there are new descriptors to fetch. (Only
4659 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004660 * such as IA-64).
4661 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004662 wmb();
4663
4664 tx_ring->next_to_use = i;
4665 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07004666 /*
4667 * we need this if more than one processor can write to our tail
4668 * at a time, it synchronizes IO on IA64/Altix systems
4669 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004670 mmiowb();
4671}
4672
4673#define MINIMUM_DHCP_PACKET_SIZE 282
4674static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4675 struct sk_buff *skb)
4676{
4677 struct e1000_hw *hw = &adapter->hw;
4678 u16 length, offset;
4679
4680 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004681 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4682 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004683 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4684 return 0;
4685 }
4686
4687 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4688 return 0;
4689
4690 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4691 return 0;
4692
4693 {
4694 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4695 struct udphdr *udp;
4696
4697 if (ip->protocol != IPPROTO_UDP)
4698 return 0;
4699
4700 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4701 if (ntohs(udp->dest) != 67)
4702 return 0;
4703
4704 offset = (u8 *)udp + 8 - skb->data;
4705 length = skb->len - offset;
4706 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4707 }
4708
4709 return 0;
4710}
4711
4712static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4713{
4714 struct e1000_adapter *adapter = netdev_priv(netdev);
4715
4716 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004717 /*
4718 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004719 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004720 * but since that doesn't exist yet, just open code it.
4721 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004722 smp_mb();
4723
Bruce Allanad680762008-03-28 09:15:03 -07004724 /*
4725 * We need to check again in a case another CPU has just
4726 * made room available.
4727 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004728 if (e1000_desc_unused(adapter->tx_ring) < size)
4729 return -EBUSY;
4730
4731 /* A reprieve! */
4732 netif_start_queue(netdev);
4733 ++adapter->restart_queue;
4734 return 0;
4735}
4736
4737static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4738{
4739 struct e1000_adapter *adapter = netdev_priv(netdev);
4740
4741 if (e1000_desc_unused(adapter->tx_ring) >= size)
4742 return 0;
4743 return __e1000_maybe_stop_tx(netdev, size);
4744}
4745
4746#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004747static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4748 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004749{
4750 struct e1000_adapter *adapter = netdev_priv(netdev);
4751 struct e1000_ring *tx_ring = adapter->tx_ring;
4752 unsigned int first;
4753 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4754 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4755 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004756 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004757 unsigned int nr_frags;
4758 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004759 int count = 0;
4760 int tso;
4761 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004762
4763 if (test_bit(__E1000_DOWN, &adapter->state)) {
4764 dev_kfree_skb_any(skb);
4765 return NETDEV_TX_OK;
4766 }
4767
4768 if (skb->len <= 0) {
4769 dev_kfree_skb_any(skb);
4770 return NETDEV_TX_OK;
4771 }
4772
4773 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004774 /*
4775 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004776 * make sure there is enough room in the FIFO before
4777 * initiating the DMA for each buffer. The calc is:
4778 * 4 = ceil(buffer len/mss). To make sure we don't
4779 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004780 * drops.
4781 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004782 if (mss) {
4783 u8 hdr_len;
4784 max_per_txd = min(mss << 2, max_per_txd);
4785 max_txd_pwr = fls(max_per_txd) - 1;
4786
Bruce Allanad680762008-03-28 09:15:03 -07004787 /*
4788 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4789 * points to just header, pull a few bytes of payload from
4790 * frags into skb->data
4791 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004792 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004793 /*
4794 * we do this workaround for ES2LAN, but it is un-necessary,
4795 * avoiding it could save a lot of cycles
4796 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004797 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004798 unsigned int pull_size;
4799
4800 pull_size = min((unsigned int)4, skb->data_len);
4801 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004802 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004803 dev_kfree_skb_any(skb);
4804 return NETDEV_TX_OK;
4805 }
Eric Dumazete743d312010-04-14 15:59:40 -07004806 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004807 }
4808 }
4809
4810 /* reserve a descriptor for the offload context */
4811 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4812 count++;
4813 count++;
4814
4815 count += TXD_USE_COUNT(len, max_txd_pwr);
4816
4817 nr_frags = skb_shinfo(skb)->nr_frags;
4818 for (f = 0; f < nr_frags; f++)
4819 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4820 max_txd_pwr);
4821
4822 if (adapter->hw.mac.tx_pkt_filtering)
4823 e1000_transfer_dhcp_info(adapter, skb);
4824
Bruce Allanad680762008-03-28 09:15:03 -07004825 /*
4826 * need: count + 2 desc gap to keep tail from touching
4827 * head, otherwise try next time
4828 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004829 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004830 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004831
Jesse Grosseab6d182010-10-20 13:56:03 +00004832 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004833 tx_flags |= E1000_TX_FLAGS_VLAN;
4834 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4835 }
4836
4837 first = tx_ring->next_to_use;
4838
4839 tso = e1000_tso(adapter, skb);
4840 if (tso < 0) {
4841 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004842 return NETDEV_TX_OK;
4843 }
4844
4845 if (tso)
4846 tx_flags |= E1000_TX_FLAGS_TSO;
4847 else if (e1000_tx_csum(adapter, skb))
4848 tx_flags |= E1000_TX_FLAGS_CSUM;
4849
Bruce Allanad680762008-03-28 09:15:03 -07004850 /*
4851 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004852 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004853 * no longer assume, we must.
4854 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004855 if (skb->protocol == htons(ETH_P_IP))
4856 tx_flags |= E1000_TX_FLAGS_IPV4;
4857
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004858 /* if count is 0 then mapping error has occured */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004859 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004860 if (count) {
4861 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004862 /* Make sure there is space in the ring for the next send. */
4863 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4864
4865 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004866 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004867 tx_ring->buffer_info[first].time_stamp = 0;
4868 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004869 }
4870
Auke Kokbc7f75f2007-09-17 12:30:59 -07004871 return NETDEV_TX_OK;
4872}
4873
4874/**
4875 * e1000_tx_timeout - Respond to a Tx Hang
4876 * @netdev: network interface device structure
4877 **/
4878static void e1000_tx_timeout(struct net_device *netdev)
4879{
4880 struct e1000_adapter *adapter = netdev_priv(netdev);
4881
4882 /* Do the reset outside of interrupt context */
4883 adapter->tx_timeout_count++;
4884 schedule_work(&adapter->reset_task);
4885}
4886
4887static void e1000_reset_task(struct work_struct *work)
4888{
4889 struct e1000_adapter *adapter;
4890 adapter = container_of(work, struct e1000_adapter, reset_task);
4891
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00004892 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4893 (adapter->flags & FLAG_RX_RESTART_NOW))) {
4894 e1000e_dump(adapter);
4895 e_err("Reset adapter\n");
4896 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004897 e1000e_reinit_locked(adapter);
4898}
4899
4900/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004901 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07004902 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004903 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07004904 *
4905 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004906 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004907struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
4908 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004909{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004910 struct e1000_adapter *adapter = netdev_priv(netdev);
4911
4912 memset(stats, 0, sizeof(struct rtnl_link_stats64));
4913 spin_lock(&adapter->stats64_lock);
4914 e1000e_update_stats(adapter);
4915 /* Fill out the OS statistics structure */
4916 stats->rx_bytes = adapter->stats.gorc;
4917 stats->rx_packets = adapter->stats.gprc;
4918 stats->tx_bytes = adapter->stats.gotc;
4919 stats->tx_packets = adapter->stats.gptc;
4920 stats->multicast = adapter->stats.mprc;
4921 stats->collisions = adapter->stats.colc;
4922
4923 /* Rx Errors */
4924
4925 /*
4926 * RLEC on some newer hardware can be incorrect so build
4927 * our own version based on RUC and ROC
4928 */
4929 stats->rx_errors = adapter->stats.rxerrc +
4930 adapter->stats.crcerrs + adapter->stats.algnerrc +
4931 adapter->stats.ruc + adapter->stats.roc +
4932 adapter->stats.cexterr;
4933 stats->rx_length_errors = adapter->stats.ruc +
4934 adapter->stats.roc;
4935 stats->rx_crc_errors = adapter->stats.crcerrs;
4936 stats->rx_frame_errors = adapter->stats.algnerrc;
4937 stats->rx_missed_errors = adapter->stats.mpc;
4938
4939 /* Tx Errors */
4940 stats->tx_errors = adapter->stats.ecol +
4941 adapter->stats.latecol;
4942 stats->tx_aborted_errors = adapter->stats.ecol;
4943 stats->tx_window_errors = adapter->stats.latecol;
4944 stats->tx_carrier_errors = adapter->stats.tncrs;
4945
4946 /* Tx Dropped needs to be maintained elsewhere */
4947
4948 spin_unlock(&adapter->stats64_lock);
4949 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004950}
4951
4952/**
4953 * e1000_change_mtu - Change the Maximum Transfer Unit
4954 * @netdev: network interface device structure
4955 * @new_mtu: new value for maximum frame size
4956 *
4957 * Returns 0 on success, negative on failure
4958 **/
4959static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4960{
4961 struct e1000_adapter *adapter = netdev_priv(netdev);
4962 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4963
Bruce Allan2adc55c2009-06-02 11:28:58 +00004964 /* Jumbo frame support */
4965 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
4966 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
4967 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004968 return -EINVAL;
4969 }
4970
Bruce Allan2adc55c2009-06-02 11:28:58 +00004971 /* Supported frame sizes */
4972 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
4973 (max_frame > adapter->max_hw_frame_size)) {
4974 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004975 return -EINVAL;
4976 }
4977
Bruce Allana1ce6472010-09-22 17:16:40 +00004978 /* Jumbo frame workaround on 82579 requires CRC be stripped */
4979 if ((adapter->hw.mac.type == e1000_pch2lan) &&
4980 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
4981 (new_mtu > ETH_DATA_LEN)) {
4982 e_err("Jumbo Frames not supported on 82579 when CRC "
4983 "stripping is disabled.\n");
4984 return -EINVAL;
4985 }
4986
Bruce Allan6f461f62010-04-27 03:33:04 +00004987 /* 82573 Errata 17 */
4988 if (((adapter->hw.mac.type == e1000_82573) ||
4989 (adapter->hw.mac.type == e1000_82574)) &&
4990 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
4991 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
4992 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
4993 }
4994
Auke Kokbc7f75f2007-09-17 12:30:59 -07004995 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4996 msleep(1);
Bruce Allan610c9922009-11-19 12:35:45 +00004997 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004998 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00004999 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5000 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005001 if (netif_running(netdev))
5002 e1000e_down(adapter);
5003
Bruce Allanad680762008-03-28 09:15:03 -07005004 /*
5005 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005006 * means we reserve 2 more, this pushes us to allocate from the next
5007 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005008 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005009 * However with the new *_jumbo_rx* routines, jumbo receives will use
5010 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005011 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005012
Jesse Brandeburg99261462010-01-22 22:56:16 +00005013 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005014 adapter->rx_buffer_len = 2048;
5015 else
5016 adapter->rx_buffer_len = 4096;
5017
5018 /* adjust allocation if LPE protects us, and we aren't using SBP */
5019 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5020 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5021 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005022 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005023
Auke Kokbc7f75f2007-09-17 12:30:59 -07005024 if (netif_running(netdev))
5025 e1000e_up(adapter);
5026 else
5027 e1000e_reset(adapter);
5028
5029 clear_bit(__E1000_RESETTING, &adapter->state);
5030
5031 return 0;
5032}
5033
5034static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5035 int cmd)
5036{
5037 struct e1000_adapter *adapter = netdev_priv(netdev);
5038 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005039
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005040 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005041 return -EOPNOTSUPP;
5042
5043 switch (cmd) {
5044 case SIOCGMIIPHY:
5045 data->phy_id = adapter->hw.phy.addr;
5046 break;
5047 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005048 e1000_phy_read_status(adapter);
5049
Bruce Allan7c257692008-04-23 11:09:00 -07005050 switch (data->reg_num & 0x1F) {
5051 case MII_BMCR:
5052 data->val_out = adapter->phy_regs.bmcr;
5053 break;
5054 case MII_BMSR:
5055 data->val_out = adapter->phy_regs.bmsr;
5056 break;
5057 case MII_PHYSID1:
5058 data->val_out = (adapter->hw.phy.id >> 16);
5059 break;
5060 case MII_PHYSID2:
5061 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5062 break;
5063 case MII_ADVERTISE:
5064 data->val_out = adapter->phy_regs.advertise;
5065 break;
5066 case MII_LPA:
5067 data->val_out = adapter->phy_regs.lpa;
5068 break;
5069 case MII_EXPANSION:
5070 data->val_out = adapter->phy_regs.expansion;
5071 break;
5072 case MII_CTRL1000:
5073 data->val_out = adapter->phy_regs.ctrl1000;
5074 break;
5075 case MII_STAT1000:
5076 data->val_out = adapter->phy_regs.stat1000;
5077 break;
5078 case MII_ESTATUS:
5079 data->val_out = adapter->phy_regs.estatus;
5080 break;
5081 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005082 return -EIO;
5083 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005084 break;
5085 case SIOCSMIIREG:
5086 default:
5087 return -EOPNOTSUPP;
5088 }
5089 return 0;
5090}
5091
5092static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5093{
5094 switch (cmd) {
5095 case SIOCGMIIPHY:
5096 case SIOCGMIIREG:
5097 case SIOCSMIIREG:
5098 return e1000_mii_ioctl(netdev, ifr, cmd);
5099 default:
5100 return -EOPNOTSUPP;
5101 }
5102}
5103
Bruce Allana4f58f52009-06-02 11:29:18 +00005104static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5105{
5106 struct e1000_hw *hw = &adapter->hw;
5107 u32 i, mac_reg;
5108 u16 phy_reg;
5109 int retval = 0;
5110
5111 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005112 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005113
5114 /* copy MAC MTA to PHY MTA */
5115 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5116 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5117 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
5118 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
5119 }
5120
5121 /* configure PHY Rx Control register */
5122 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
5123 mac_reg = er32(RCTL);
5124 if (mac_reg & E1000_RCTL_UPE)
5125 phy_reg |= BM_RCTL_UPE;
5126 if (mac_reg & E1000_RCTL_MPE)
5127 phy_reg |= BM_RCTL_MPE;
5128 phy_reg &= ~(BM_RCTL_MO_MASK);
5129 if (mac_reg & E1000_RCTL_MO_3)
5130 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5131 << BM_RCTL_MO_SHIFT);
5132 if (mac_reg & E1000_RCTL_BAM)
5133 phy_reg |= BM_RCTL_BAM;
5134 if (mac_reg & E1000_RCTL_PMCF)
5135 phy_reg |= BM_RCTL_PMCF;
5136 mac_reg = er32(CTRL);
5137 if (mac_reg & E1000_CTRL_RFCE)
5138 phy_reg |= BM_RCTL_RFCE;
5139 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
5140
5141 /* enable PHY wakeup in MAC register */
5142 ew32(WUFC, wufc);
5143 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5144
5145 /* configure and enable PHY wakeup in PHY registers */
5146 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
5147 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5148
5149 /* activate PHY wakeup */
Bruce Allan94d81862009-11-20 23:25:26 +00005150 retval = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005151 if (retval) {
5152 e_err("Could not acquire PHY\n");
5153 return retval;
5154 }
5155 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
5156 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
5157 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
5158 if (retval) {
5159 e_err("Could not read PHY page 769\n");
5160 goto out;
5161 }
5162 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5163 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
5164 if (retval)
5165 e_err("Could not set PHY Host Wakeup bit\n");
5166out:
Bruce Allan94d81862009-11-20 23:25:26 +00005167 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005168
5169 return retval;
5170}
5171
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005172static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5173 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005174{
5175 struct net_device *netdev = pci_get_drvdata(pdev);
5176 struct e1000_adapter *adapter = netdev_priv(netdev);
5177 struct e1000_hw *hw = &adapter->hw;
5178 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005179 /* Runtime suspend should only enable wakeup for link changes */
5180 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005181 int retval = 0;
5182
5183 netif_device_detach(netdev);
5184
5185 if (netif_running(netdev)) {
5186 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5187 e1000e_down(adapter);
5188 e1000_free_irq(adapter);
5189 }
Bruce Allan4662e822008-08-26 18:37:06 -07005190 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005191
5192 retval = pci_save_state(pdev);
5193 if (retval)
5194 return retval;
5195
5196 status = er32(STATUS);
5197 if (status & E1000_STATUS_LU)
5198 wufc &= ~E1000_WUFC_LNKC;
5199
5200 if (wufc) {
5201 e1000_setup_rctl(adapter);
5202 e1000_set_multi(netdev);
5203
5204 /* turn on all-multi mode if wake on multicast is enabled */
5205 if (wufc & E1000_WUFC_MC) {
5206 rctl = er32(RCTL);
5207 rctl |= E1000_RCTL_MPE;
5208 ew32(RCTL, rctl);
5209 }
5210
5211 ctrl = er32(CTRL);
5212 /* advertise wake from D3Cold */
5213 #define E1000_CTRL_ADVD3WUC 0x00100000
5214 /* phy power management enable */
5215 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005216 ctrl |= E1000_CTRL_ADVD3WUC;
5217 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5218 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005219 ew32(CTRL, ctrl);
5220
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005221 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5222 adapter->hw.phy.media_type ==
5223 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005224 /* keep the laser running in D3 */
5225 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005226 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005227 ew32(CTRL_EXT, ctrl_ext);
5228 }
5229
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005230 if (adapter->flags & FLAG_IS_ICH)
5231 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
5232
Auke Kokbc7f75f2007-09-17 12:30:59 -07005233 /* Allow time for pending master requests to run */
5234 e1000e_disable_pcie_master(&adapter->hw);
5235
Bruce Allan82776a42009-08-14 14:35:33 +00005236 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005237 /* enable wakeup by the PHY */
5238 retval = e1000_init_phy_wakeup(adapter, wufc);
5239 if (retval)
5240 return retval;
5241 } else {
5242 /* enable wakeup by the MAC */
5243 ew32(WUFC, wufc);
5244 ew32(WUC, E1000_WUC_PME_EN);
5245 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005246 } else {
5247 ew32(WUC, 0);
5248 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005249 }
5250
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005251 *enable_wake = !!wufc;
5252
Auke Kokbc7f75f2007-09-17 12:30:59 -07005253 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005254 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5255 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005256 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005257
5258 if (adapter->hw.phy.type == e1000_phy_igp_3)
5259 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5260
Bruce Allanad680762008-03-28 09:15:03 -07005261 /*
5262 * Release control of h/w to f/w. If f/w is AMT enabled, this
5263 * would have already happened in close and is redundant.
5264 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005265 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005266
5267 pci_disable_device(pdev);
5268
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005269 return 0;
5270}
5271
5272static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5273{
5274 if (sleep && wake) {
5275 pci_prepare_to_sleep(pdev);
5276 return;
5277 }
5278
5279 pci_wake_from_d3(pdev, wake);
5280 pci_set_power_state(pdev, PCI_D3hot);
5281}
5282
5283static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5284 bool wake)
5285{
5286 struct net_device *netdev = pci_get_drvdata(pdev);
5287 struct e1000_adapter *adapter = netdev_priv(netdev);
5288
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005289 /*
5290 * The pci-e switch on some quad port adapters will report a
5291 * correctable error when the MAC transitions from D0 to D3. To
5292 * prevent this we need to mask off the correctable errors on the
5293 * downstream port of the pci-e switch.
5294 */
5295 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5296 struct pci_dev *us_dev = pdev->bus->self;
5297 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
5298 u16 devctl;
5299
5300 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5301 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5302 (devctl & ~PCI_EXP_DEVCTL_CERE));
5303
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005304 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005305
5306 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5307 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005308 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005309 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005310}
5311
Bruce Allan6f461f62010-04-27 03:33:04 +00005312#ifdef CONFIG_PCIEASPM
5313static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5314{
5315 pci_disable_link_state(pdev, state);
5316}
5317#else
5318static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005319{
5320 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005321 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005322
5323 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005324 * Both device and parent should have the same ASPM setting.
5325 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005326 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005327 pos = pci_pcie_cap(pdev);
5328 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5329 reg16 &= ~state;
5330 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5331
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005332 if (!pdev->bus->self)
5333 return;
5334
Bruce Allan6f461f62010-04-27 03:33:04 +00005335 pos = pci_pcie_cap(pdev->bus->self);
5336 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5337 reg16 &= ~state;
5338 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5339}
5340#endif
5341void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5342{
5343 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5344 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5345 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5346
5347 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005348}
5349
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005350#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005351static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005352{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005353 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005354}
5355
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005356static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005357{
5358 struct net_device *netdev = pci_get_drvdata(pdev);
5359 struct e1000_adapter *adapter = netdev_priv(netdev);
5360 struct e1000_hw *hw = &adapter->hw;
5361 u32 err;
5362
5363 pci_set_power_state(pdev, PCI_D0);
5364 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005365 pci_save_state(pdev);
Bruce Allan6f461f62010-04-27 03:33:04 +00005366 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5367 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005368
Bruce Allan4662e822008-08-26 18:37:06 -07005369 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005370 if (netif_running(netdev)) {
5371 err = e1000_request_irq(adapter);
5372 if (err)
5373 return err;
5374 }
5375
5376 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005377
5378 /* report the system wakeup cause from S3/S4 */
5379 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5380 u16 phy_data;
5381
5382 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5383 if (phy_data) {
5384 e_info("PHY Wakeup cause - %s\n",
5385 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5386 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5387 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5388 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5389 phy_data & E1000_WUS_LNKC ? "Link Status "
5390 " Change" : "other");
5391 }
5392 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5393 } else {
5394 u32 wus = er32(WUS);
5395 if (wus) {
5396 e_info("MAC Wakeup cause - %s\n",
5397 wus & E1000_WUS_EX ? "Unicast Packet" :
5398 wus & E1000_WUS_MC ? "Multicast Packet" :
5399 wus & E1000_WUS_BC ? "Broadcast Packet" :
5400 wus & E1000_WUS_MAG ? "Magic Packet" :
5401 wus & E1000_WUS_LNKC ? "Link Status Change" :
5402 "other");
5403 }
5404 ew32(WUS, ~0);
5405 }
5406
Auke Kokbc7f75f2007-09-17 12:30:59 -07005407 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005408
Bruce Allancd791612010-05-10 14:59:51 +00005409 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005410
5411 if (netif_running(netdev))
5412 e1000e_up(adapter);
5413
5414 netif_device_attach(netdev);
5415
Bruce Allanad680762008-03-28 09:15:03 -07005416 /*
5417 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005418 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005419 * under the control of the driver.
5420 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005421 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005422 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005423
5424 return 0;
5425}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005426
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005427#ifdef CONFIG_PM_SLEEP
5428static int e1000_suspend(struct device *dev)
5429{
5430 struct pci_dev *pdev = to_pci_dev(dev);
5431 int retval;
5432 bool wake;
5433
5434 retval = __e1000_shutdown(pdev, &wake, false);
5435 if (!retval)
5436 e1000_complete_shutdown(pdev, true, wake);
5437
5438 return retval;
5439}
5440
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005441static int e1000_resume(struct device *dev)
5442{
5443 struct pci_dev *pdev = to_pci_dev(dev);
5444 struct net_device *netdev = pci_get_drvdata(pdev);
5445 struct e1000_adapter *adapter = netdev_priv(netdev);
5446
5447 if (e1000e_pm_ready(adapter))
5448 adapter->idle_check = true;
5449
5450 return __e1000_resume(pdev);
5451}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005452#endif /* CONFIG_PM_SLEEP */
5453
5454#ifdef CONFIG_PM_RUNTIME
5455static int e1000_runtime_suspend(struct device *dev)
5456{
5457 struct pci_dev *pdev = to_pci_dev(dev);
5458 struct net_device *netdev = pci_get_drvdata(pdev);
5459 struct e1000_adapter *adapter = netdev_priv(netdev);
5460
5461 if (e1000e_pm_ready(adapter)) {
5462 bool wake;
5463
5464 __e1000_shutdown(pdev, &wake, true);
5465 }
5466
5467 return 0;
5468}
5469
5470static int e1000_idle(struct device *dev)
5471{
5472 struct pci_dev *pdev = to_pci_dev(dev);
5473 struct net_device *netdev = pci_get_drvdata(pdev);
5474 struct e1000_adapter *adapter = netdev_priv(netdev);
5475
5476 if (!e1000e_pm_ready(adapter))
5477 return 0;
5478
5479 if (adapter->idle_check) {
5480 adapter->idle_check = false;
5481 if (!e1000e_has_link(adapter))
5482 pm_schedule_suspend(dev, MSEC_PER_SEC);
5483 }
5484
5485 return -EBUSY;
5486}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005487
5488static int e1000_runtime_resume(struct device *dev)
5489{
5490 struct pci_dev *pdev = to_pci_dev(dev);
5491 struct net_device *netdev = pci_get_drvdata(pdev);
5492 struct e1000_adapter *adapter = netdev_priv(netdev);
5493
5494 if (!e1000e_pm_ready(adapter))
5495 return 0;
5496
5497 adapter->idle_check = !dev->power.runtime_auto;
5498 return __e1000_resume(pdev);
5499}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005500#endif /* CONFIG_PM_RUNTIME */
5501#endif /* CONFIG_PM_OPS */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005502
5503static void e1000_shutdown(struct pci_dev *pdev)
5504{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005505 bool wake = false;
5506
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005507 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005508
5509 if (system_state == SYSTEM_POWER_OFF)
5510 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005511}
5512
5513#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005514
5515static irqreturn_t e1000_intr_msix(int irq, void *data)
5516{
5517 struct net_device *netdev = data;
5518 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005519
5520 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005521 int vector, msix_irq;
5522
Dongdong Deng147b2c82010-11-16 19:50:15 -08005523 vector = 0;
5524 msix_irq = adapter->msix_entries[vector].vector;
5525 disable_irq(msix_irq);
5526 e1000_intr_msix_rx(msix_irq, netdev);
5527 enable_irq(msix_irq);
5528
5529 vector++;
5530 msix_irq = adapter->msix_entries[vector].vector;
5531 disable_irq(msix_irq);
5532 e1000_intr_msix_tx(msix_irq, netdev);
5533 enable_irq(msix_irq);
5534
5535 vector++;
5536 msix_irq = adapter->msix_entries[vector].vector;
5537 disable_irq(msix_irq);
5538 e1000_msix_other(msix_irq, netdev);
5539 enable_irq(msix_irq);
5540 }
5541
5542 return IRQ_HANDLED;
5543}
5544
Auke Kokbc7f75f2007-09-17 12:30:59 -07005545/*
5546 * Polling 'interrupt' - used by things like netconsole to send skbs
5547 * without having to re-enable interrupts. It's not called while
5548 * the interrupt routine is executing.
5549 */
5550static void e1000_netpoll(struct net_device *netdev)
5551{
5552 struct e1000_adapter *adapter = netdev_priv(netdev);
5553
Dongdong Deng147b2c82010-11-16 19:50:15 -08005554 switch (adapter->int_mode) {
5555 case E1000E_INT_MODE_MSIX:
5556 e1000_intr_msix(adapter->pdev->irq, netdev);
5557 break;
5558 case E1000E_INT_MODE_MSI:
5559 disable_irq(adapter->pdev->irq);
5560 e1000_intr_msi(adapter->pdev->irq, netdev);
5561 enable_irq(adapter->pdev->irq);
5562 break;
5563 default: /* E1000E_INT_MODE_LEGACY */
5564 disable_irq(adapter->pdev->irq);
5565 e1000_intr(adapter->pdev->irq, netdev);
5566 enable_irq(adapter->pdev->irq);
5567 break;
5568 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005569}
5570#endif
5571
5572/**
5573 * e1000_io_error_detected - called when PCI error is detected
5574 * @pdev: Pointer to PCI device
5575 * @state: The current pci connection state
5576 *
5577 * This function is called after a PCI bus error affecting
5578 * this device has been detected.
5579 */
5580static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5581 pci_channel_state_t state)
5582{
5583 struct net_device *netdev = pci_get_drvdata(pdev);
5584 struct e1000_adapter *adapter = netdev_priv(netdev);
5585
5586 netif_device_detach(netdev);
5587
Mike Masonc93b5a72009-06-30 12:45:53 +00005588 if (state == pci_channel_io_perm_failure)
5589 return PCI_ERS_RESULT_DISCONNECT;
5590
Auke Kokbc7f75f2007-09-17 12:30:59 -07005591 if (netif_running(netdev))
5592 e1000e_down(adapter);
5593 pci_disable_device(pdev);
5594
5595 /* Request a slot slot reset. */
5596 return PCI_ERS_RESULT_NEED_RESET;
5597}
5598
5599/**
5600 * e1000_io_slot_reset - called after the pci bus has been reset.
5601 * @pdev: Pointer to PCI device
5602 *
5603 * Restart the card from scratch, as if from a cold-boot. Implementation
5604 * resembles the first-half of the e1000_resume routine.
5605 */
5606static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5607{
5608 struct net_device *netdev = pci_get_drvdata(pdev);
5609 struct e1000_adapter *adapter = netdev_priv(netdev);
5610 struct e1000_hw *hw = &adapter->hw;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005611 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005612 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005613
Bruce Allan6f461f62010-04-27 03:33:04 +00005614 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5615 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Bruce Allanf0f422e2008-08-04 17:21:53 -07005616 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005617 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005618 dev_err(&pdev->dev,
5619 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005620 result = PCI_ERS_RESULT_DISCONNECT;
5621 } else {
5622 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005623 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005624 pci_restore_state(pdev);
5625
5626 pci_enable_wake(pdev, PCI_D3hot, 0);
5627 pci_enable_wake(pdev, PCI_D3cold, 0);
5628
5629 e1000e_reset(adapter);
5630 ew32(WUS, ~0);
5631 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005632 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005633
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005634 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005635
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005636 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005637}
5638
5639/**
5640 * e1000_io_resume - called when traffic can start flowing again.
5641 * @pdev: Pointer to PCI device
5642 *
5643 * This callback is called when the error recovery driver tells us that
5644 * its OK to resume normal operation. Implementation resembles the
5645 * second-half of the e1000_resume routine.
5646 */
5647static void e1000_io_resume(struct pci_dev *pdev)
5648{
5649 struct net_device *netdev = pci_get_drvdata(pdev);
5650 struct e1000_adapter *adapter = netdev_priv(netdev);
5651
Bruce Allancd791612010-05-10 14:59:51 +00005652 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005653
5654 if (netif_running(netdev)) {
5655 if (e1000e_up(adapter)) {
5656 dev_err(&pdev->dev,
5657 "can't bring device back up after reset\n");
5658 return;
5659 }
5660 }
5661
5662 netif_device_attach(netdev);
5663
Bruce Allanad680762008-03-28 09:15:03 -07005664 /*
5665 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005666 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005667 * under the control of the driver.
5668 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005669 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005670 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005671
5672}
5673
5674static void e1000_print_device_info(struct e1000_adapter *adapter)
5675{
5676 struct e1000_hw *hw = &adapter->hw;
5677 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005678 u32 ret_val;
5679 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005680
5681 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005682 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005683 /* bus width */
5684 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5685 "Width x1"),
5686 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005687 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005688 e_info("Intel(R) PRO/%s Network Connection\n",
5689 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005690 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5691 E1000_PBANUM_LENGTH);
5692 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005693 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005694 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5695 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005696}
5697
Auke Kok10aa4c02008-08-04 17:21:20 -07005698static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5699{
5700 struct e1000_hw *hw = &adapter->hw;
5701 int ret_val;
5702 u16 buf = 0;
5703
5704 if (hw->mac.type != e1000_82573)
5705 return;
5706
5707 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005708 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005709 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005710 dev_warn(&adapter->pdev->dev,
5711 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005712 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005713}
5714
Stephen Hemminger651c2462008-11-19 21:57:48 -08005715static const struct net_device_ops e1000e_netdev_ops = {
5716 .ndo_open = e1000_open,
5717 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005718 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005719 .ndo_get_stats64 = e1000e_get_stats64,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005720 .ndo_set_multicast_list = e1000_set_multi,
5721 .ndo_set_mac_address = e1000_set_mac,
5722 .ndo_change_mtu = e1000_change_mtu,
5723 .ndo_do_ioctl = e1000_ioctl,
5724 .ndo_tx_timeout = e1000_tx_timeout,
5725 .ndo_validate_addr = eth_validate_addr,
5726
5727 .ndo_vlan_rx_register = e1000_vlan_rx_register,
5728 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5729 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5730#ifdef CONFIG_NET_POLL_CONTROLLER
5731 .ndo_poll_controller = e1000_netpoll,
5732#endif
5733};
5734
Auke Kokbc7f75f2007-09-17 12:30:59 -07005735/**
5736 * e1000_probe - Device Initialization Routine
5737 * @pdev: PCI device information struct
5738 * @ent: entry in e1000_pci_tbl
5739 *
5740 * Returns 0 on success, negative on failure
5741 *
5742 * e1000_probe initializes an adapter identified by a pci_dev structure.
5743 * The OS initialization, configuring of the adapter private structure,
5744 * and a hardware reset occur.
5745 **/
5746static int __devinit e1000_probe(struct pci_dev *pdev,
5747 const struct pci_device_id *ent)
5748{
5749 struct net_device *netdev;
5750 struct e1000_adapter *adapter;
5751 struct e1000_hw *hw;
5752 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005753 resource_size_t mmio_start, mmio_len;
5754 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005755
5756 static int cards_found;
5757 int i, err, pci_using_dac;
5758 u16 eeprom_data = 0;
5759 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5760
Bruce Allan6f461f62010-04-27 03:33:04 +00005761 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
5762 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005763
Bruce Allanf0f422e2008-08-04 17:21:53 -07005764 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005765 if (err)
5766 return err;
5767
5768 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005769 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005770 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005771 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005772 if (!err)
5773 pci_using_dac = 1;
5774 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005775 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005776 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005777 err = dma_set_coherent_mask(&pdev->dev,
5778 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005779 if (err) {
5780 dev_err(&pdev->dev, "No usable DMA "
5781 "configuration, aborting\n");
5782 goto err_dma;
5783 }
5784 }
5785 }
5786
Arjan van de Vene8de1482008-10-22 19:55:31 -07005787 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005788 pci_select_bars(pdev, IORESOURCE_MEM),
5789 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005790 if (err)
5791 goto err_pci_reg;
5792
Xiaotian Feng68eac462009-08-14 14:35:52 +00005793 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005794 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005795
Auke Kokbc7f75f2007-09-17 12:30:59 -07005796 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005797 /* PCI config space info */
5798 err = pci_save_state(pdev);
5799 if (err)
5800 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005801
5802 err = -ENOMEM;
5803 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5804 if (!netdev)
5805 goto err_alloc_etherdev;
5806
Auke Kokbc7f75f2007-09-17 12:30:59 -07005807 SET_NETDEV_DEV(netdev, &pdev->dev);
5808
Tom Herbertf85e4df2010-05-05 14:03:32 +00005809 netdev->irq = pdev->irq;
5810
Auke Kokbc7f75f2007-09-17 12:30:59 -07005811 pci_set_drvdata(pdev, netdev);
5812 adapter = netdev_priv(netdev);
5813 hw = &adapter->hw;
5814 adapter->netdev = netdev;
5815 adapter->pdev = pdev;
5816 adapter->ei = ei;
5817 adapter->pba = ei->pba;
5818 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005819 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005820 adapter->hw.adapter = adapter;
5821 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005822 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005823 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5824
5825 mmio_start = pci_resource_start(pdev, 0);
5826 mmio_len = pci_resource_len(pdev, 0);
5827
5828 err = -EIO;
5829 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5830 if (!adapter->hw.hw_addr)
5831 goto err_ioremap;
5832
5833 if ((adapter->flags & FLAG_HAS_FLASH) &&
5834 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5835 flash_start = pci_resource_start(pdev, 1);
5836 flash_len = pci_resource_len(pdev, 1);
5837 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5838 if (!adapter->hw.flash_address)
5839 goto err_flashmap;
5840 }
5841
5842 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005843 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005844 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005845 netdev->watchdog_timeo = 5 * HZ;
5846 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005847 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5848
5849 netdev->mem_start = mmio_start;
5850 netdev->mem_end = mmio_start + mmio_len;
5851
5852 adapter->bd_number = cards_found++;
5853
Bruce Allan4662e822008-08-26 18:37:06 -07005854 e1000e_check_options(adapter);
5855
Auke Kokbc7f75f2007-09-17 12:30:59 -07005856 /* setup adapter struct */
5857 err = e1000_sw_init(adapter);
5858 if (err)
5859 goto err_sw_init;
5860
Auke Kokbc7f75f2007-09-17 12:30:59 -07005861 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5862 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5863 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5864
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005865 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005866 if (err)
5867 goto err_hw_init;
5868
Bruce Allan4a770352008-10-01 17:18:35 -07005869 if ((adapter->flags & FLAG_IS_ICH) &&
5870 (adapter->flags & FLAG_READ_ONLY_NVM))
5871 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5872
Auke Kokbc7f75f2007-09-17 12:30:59 -07005873 hw->mac.ops.get_bus_info(&adapter->hw);
5874
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005875 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005876
5877 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005878 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005879 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5880 adapter->hw.phy.disable_polarity_correction = 0;
5881 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5882 }
5883
5884 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005885 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005886
5887 netdev->features = NETIF_F_SG |
5888 NETIF_F_HW_CSUM |
5889 NETIF_F_HW_VLAN_TX |
5890 NETIF_F_HW_VLAN_RX;
5891
5892 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5893 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5894
5895 netdev->features |= NETIF_F_TSO;
5896 netdev->features |= NETIF_F_TSO6;
5897
Jeff Kirshera5136e22008-06-05 04:07:28 -07005898 netdev->vlan_features |= NETIF_F_TSO;
5899 netdev->vlan_features |= NETIF_F_TSO6;
5900 netdev->vlan_features |= NETIF_F_HW_CSUM;
5901 netdev->vlan_features |= NETIF_F_SG;
5902
Yi Zou7b872a52010-09-22 17:57:58 +00005903 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005904 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00005905 netdev->vlan_features |= NETIF_F_HIGHDMA;
5906 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005907
Auke Kokbc7f75f2007-09-17 12:30:59 -07005908 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5909 adapter->flags |= FLAG_MNG_PT_ENABLED;
5910
Bruce Allanad680762008-03-28 09:15:03 -07005911 /*
5912 * before reading the NVM, reset the controller to
5913 * put the device in a known good starting state
5914 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005915 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5916
5917 /*
5918 * systems with ASPM and others may see the checksum fail on the first
5919 * attempt. Let's give it a few tries
5920 */
5921 for (i = 0;; i++) {
5922 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5923 break;
5924 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005925 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005926 err = -EIO;
5927 goto err_eeprom;
5928 }
5929 }
5930
Auke Kok10aa4c02008-08-04 17:21:20 -07005931 e1000_eeprom_checks(adapter);
5932
Bruce Allan608f8a02010-01-13 02:04:58 +00005933 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005934 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005935 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005936
5937 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5938 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5939
5940 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07005941 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005942 err = -EIO;
5943 goto err_eeprom;
5944 }
5945
5946 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005947 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005948 adapter->watchdog_timer.data = (unsigned long) adapter;
5949
5950 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005951 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005952 adapter->phy_info_timer.data = (unsigned long) adapter;
5953
5954 INIT_WORK(&adapter->reset_task, e1000_reset_task);
5955 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07005956 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
5957 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00005958 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Holger Eitzenberger9633e632010-11-17 15:43:52 +00005959 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005960
Auke Kokbc7f75f2007-09-17 12:30:59 -07005961 /* Initialize link parameters. User can change them with ethtool */
5962 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07005963 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08005964 adapter->hw.fc.requested_mode = e1000_fc_default;
5965 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005966 adapter->hw.phy.autoneg_advertised = 0x2f;
5967
5968 /* ring size defaults */
5969 adapter->rx_ring->count = 256;
5970 adapter->tx_ring->count = 256;
5971
5972 /*
5973 * Initial Wake on LAN setting - If APM wake is enabled in
5974 * the EEPROM, enable the ACPI Magic Packet filter
5975 */
5976 if (adapter->flags & FLAG_APME_IN_WUC) {
5977 /* APME bit in EEPROM is mapped to WUC.APME */
5978 eeprom_data = er32(WUC);
5979 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allana4f58f52009-06-02 11:29:18 +00005980 if (eeprom_data & E1000_WUC_PHY_WAKE)
5981 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005982 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
5983 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
5984 (adapter->hw.bus.func == 1))
5985 e1000_read_nvm(&adapter->hw,
5986 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
5987 else
5988 e1000_read_nvm(&adapter->hw,
5989 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
5990 }
5991
5992 /* fetch WoL from EEPROM */
5993 if (eeprom_data & eeprom_apme_mask)
5994 adapter->eeprom_wol |= E1000_WUFC_MAG;
5995
5996 /*
5997 * now that we have the eeprom settings, apply the special cases
5998 * where the eeprom may be wrong or the board simply won't support
5999 * wake on lan on a particular port
6000 */
6001 if (!(adapter->flags & FLAG_HAS_WOL))
6002 adapter->eeprom_wol = 0;
6003
6004 /* initialize the wol settings based on the eeprom settings */
6005 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006006 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006007
Bruce Allan84527592008-11-21 17:00:22 -08006008 /* save off EEPROM version number */
6009 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6010
Auke Kokbc7f75f2007-09-17 12:30:59 -07006011 /* reset the hardware with the new settings */
6012 e1000e_reset(adapter);
6013
Bruce Allanad680762008-03-28 09:15:03 -07006014 /*
6015 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006016 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006017 * under the control of the driver.
6018 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006019 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006020 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006021
Bruce Allane0dc4f12011-01-06 14:29:50 +00006022 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006023 err = register_netdev(netdev);
6024 if (err)
6025 goto err_register;
6026
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006027 /* carrier off reporting is important to ethtool even BEFORE open */
6028 netif_carrier_off(netdev);
6029
Auke Kokbc7f75f2007-09-17 12:30:59 -07006030 e1000_print_device_info(adapter);
6031
Alan Sternf3ec4f82010-06-08 15:23:51 -04006032 if (pci_dev_run_wake(pdev))
6033 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006034
Auke Kokbc7f75f2007-09-17 12:30:59 -07006035 return 0;
6036
6037err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006038 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006039 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006040err_eeprom:
6041 if (!e1000_check_reset_block(&adapter->hw))
6042 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006043err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006044 kfree(adapter->tx_ring);
6045 kfree(adapter->rx_ring);
6046err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006047 if (adapter->hw.flash_address)
6048 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006049 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006050err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006051 iounmap(adapter->hw.hw_addr);
6052err_ioremap:
6053 free_netdev(netdev);
6054err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006055 pci_release_selected_regions(pdev,
6056 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006057err_pci_reg:
6058err_dma:
6059 pci_disable_device(pdev);
6060 return err;
6061}
6062
6063/**
6064 * e1000_remove - Device Removal Routine
6065 * @pdev: PCI device information struct
6066 *
6067 * e1000_remove is called by the PCI subsystem to alert the driver
6068 * that it should release a PCI device. The could be caused by a
6069 * Hot-Plug event, or because the driver is going to be removed from
6070 * memory.
6071 **/
6072static void __devexit e1000_remove(struct pci_dev *pdev)
6073{
6074 struct net_device *netdev = pci_get_drvdata(pdev);
6075 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006076 bool down = test_bit(__E1000_DOWN, &adapter->state);
6077
Bruce Allanad680762008-03-28 09:15:03 -07006078 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006079 * The timers may be rescheduled, so explicitly disable them
6080 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006081 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006082 if (!down)
6083 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006084 del_timer_sync(&adapter->watchdog_timer);
6085 del_timer_sync(&adapter->phy_info_timer);
6086
Bruce Allan41cec6f2009-11-20 23:28:56 +00006087 cancel_work_sync(&adapter->reset_task);
6088 cancel_work_sync(&adapter->watchdog_task);
6089 cancel_work_sync(&adapter->downshift_task);
6090 cancel_work_sync(&adapter->update_phy_task);
Tejun Heo23f333a2010-12-12 16:45:14 +01006091 cancel_work_sync(&adapter->led_blink_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006092 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006093
Bruce Allan17f208d2009-12-01 15:47:22 +00006094 if (!(netdev->flags & IFF_UP))
6095 e1000_power_down_phy(adapter);
6096
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006097 /* Don't lie to e1000_close() down the road. */
6098 if (!down)
6099 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006100 unregister_netdev(netdev);
6101
Alan Sternf3ec4f82010-06-08 15:23:51 -04006102 if (pci_dev_run_wake(pdev))
6103 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006104
Bruce Allanad680762008-03-28 09:15:03 -07006105 /*
6106 * Release control of h/w to f/w. If f/w is AMT enabled, this
6107 * would have already happened in close and is redundant.
6108 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006109 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006110
Bruce Allan4662e822008-08-26 18:37:06 -07006111 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006112 kfree(adapter->tx_ring);
6113 kfree(adapter->rx_ring);
6114
6115 iounmap(adapter->hw.hw_addr);
6116 if (adapter->hw.flash_address)
6117 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006118 pci_release_selected_regions(pdev,
6119 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006120
6121 free_netdev(netdev);
6122
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006123 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006124 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006125
Auke Kokbc7f75f2007-09-17 12:30:59 -07006126 pci_disable_device(pdev);
6127}
6128
6129/* PCI Error Recovery (ERS) */
6130static struct pci_error_handlers e1000_err_handler = {
6131 .error_detected = e1000_io_error_detected,
6132 .slot_reset = e1000_io_slot_reset,
6133 .resume = e1000_io_resume,
6134};
6135
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006136static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006137 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6138 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6139 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6140 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6141 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6142 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006143 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6144 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6145 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006146
Auke Kokbc7f75f2007-09-17 12:30:59 -07006147 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6148 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6149 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6150 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006151
Auke Kokbc7f75f2007-09-17 12:30:59 -07006152 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6153 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6154 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006155
Bruce Allan4662e822008-08-26 18:37:06 -07006156 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006157 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006158 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006159
Auke Kokbc7f75f2007-09-17 12:30:59 -07006160 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6161 board_80003es2lan },
6162 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6163 board_80003es2lan },
6164 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6165 board_80003es2lan },
6166 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6167 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006168
Auke Kokbc7f75f2007-09-17 12:30:59 -07006169 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6170 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6171 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6172 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6173 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6174 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6175 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006176 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006177
Auke Kokbc7f75f2007-09-17 12:30:59 -07006178 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6179 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6180 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6181 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6182 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006183 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006184 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6185 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6186 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6187
6188 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6189 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6190 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006191
Bruce Allanf4187b52008-08-26 18:36:50 -07006192 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6193 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006194 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006195
Bruce Allana4f58f52009-06-02 11:29:18 +00006196 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6197 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6198 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6199 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6200
Bruce Alland3738bb2010-06-16 13:27:28 +00006201 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6202 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6203
Auke Kokbc7f75f2007-09-17 12:30:59 -07006204 { } /* terminate list */
6205};
6206MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6207
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006208#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006209static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006210 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6211 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6212 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006213};
David S. Millere50208a2010-03-16 23:36:24 -07006214#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006215
Auke Kokbc7f75f2007-09-17 12:30:59 -07006216/* PCI Device API Driver */
6217static struct pci_driver e1000_driver = {
6218 .name = e1000e_driver_name,
6219 .id_table = e1000_pci_tbl,
6220 .probe = e1000_probe,
6221 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006222#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006223 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006224#endif
6225 .shutdown = e1000_shutdown,
6226 .err_handler = &e1000_err_handler
6227};
6228
6229/**
6230 * e1000_init_module - Driver Registration Routine
6231 *
6232 * e1000_init_module is the first routine called when the driver is
6233 * loaded. All it does is register with the PCI subsystem.
6234 **/
6235static int __init e1000_init_module(void)
6236{
6237 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006238 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6239 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006240 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006241 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006242
Auke Kokbc7f75f2007-09-17 12:30:59 -07006243 return ret;
6244}
6245module_init(e1000_init_module);
6246
6247/**
6248 * e1000_exit_module - Driver Exit Cleanup Routine
6249 *
6250 * e1000_exit_module is called just before the driver is removed
6251 * from memory.
6252 **/
6253static void __exit e1000_exit_module(void)
6254{
6255 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006256}
6257module_exit(e1000_exit_module);
6258
6259
6260MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6261MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6262MODULE_LICENSE("GPL");
6263MODULE_VERSION(DRV_VERSION);
6264
6265/* e1000_main.c */