blob: 7cedfeb505b2dc022870d3dbf691657ba0c9fc8d [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))
Bruce Allan79f5e842011-01-19 04:20:59 +00001846 snprintf(adapter->rx_ring->name,
1847 sizeof(adapter->rx_ring->name) - 1,
1848 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001849 else
1850 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1851 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001852 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001853 netdev);
1854 if (err)
1855 goto out;
1856 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1857 adapter->rx_ring->itr_val = adapter->itr;
1858 vector++;
1859
1860 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001861 snprintf(adapter->tx_ring->name,
1862 sizeof(adapter->tx_ring->name) - 1,
1863 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001864 else
1865 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1866 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001867 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001868 netdev);
1869 if (err)
1870 goto out;
1871 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1872 adapter->tx_ring->itr_val = adapter->itr;
1873 vector++;
1874
1875 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001876 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001877 if (err)
1878 goto out;
1879
1880 e1000_configure_msix(adapter);
1881 return 0;
1882out:
1883 return err;
1884}
1885
Bruce Allanf8d59f72008-08-08 18:36:11 -07001886/**
1887 * e1000_request_irq - initialize interrupts
1888 *
1889 * Attempts to configure interrupts using the best available
1890 * capabilities of the hardware and kernel.
1891 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001892static int e1000_request_irq(struct e1000_adapter *adapter)
1893{
1894 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001895 int err;
1896
Bruce Allan4662e822008-08-26 18:37:06 -07001897 if (adapter->msix_entries) {
1898 err = e1000_request_msix(adapter);
1899 if (!err)
1900 return err;
1901 /* fall back to MSI */
1902 e1000e_reset_interrupt_capability(adapter);
1903 adapter->int_mode = E1000E_INT_MODE_MSI;
1904 e1000e_set_interrupt_capability(adapter);
1905 }
1906 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001907 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001908 netdev->name, netdev);
1909 if (!err)
1910 return err;
1911
1912 /* fall back to legacy interrupt */
1913 e1000e_reset_interrupt_capability(adapter);
1914 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001915 }
1916
Joe Perchesa0607fd2009-11-18 23:29:17 -08001917 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001918 netdev->name, netdev);
1919 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001920 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001921
1922 return err;
1923}
1924
1925static void e1000_free_irq(struct e1000_adapter *adapter)
1926{
1927 struct net_device *netdev = adapter->netdev;
1928
Bruce Allan4662e822008-08-26 18:37:06 -07001929 if (adapter->msix_entries) {
1930 int vector = 0;
1931
1932 free_irq(adapter->msix_entries[vector].vector, netdev);
1933 vector++;
1934
1935 free_irq(adapter->msix_entries[vector].vector, netdev);
1936 vector++;
1937
1938 /* Other Causes interrupt vector */
1939 free_irq(adapter->msix_entries[vector].vector, netdev);
1940 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001941 }
Bruce Allan4662e822008-08-26 18:37:06 -07001942
1943 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001944}
1945
1946/**
1947 * e1000_irq_disable - Mask off interrupt generation on the NIC
1948 **/
1949static void e1000_irq_disable(struct e1000_adapter *adapter)
1950{
1951 struct e1000_hw *hw = &adapter->hw;
1952
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001954 if (adapter->msix_entries)
1955 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001956 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001957
1958 if (adapter->msix_entries) {
1959 int i;
1960 for (i = 0; i < adapter->num_vectors; i++)
1961 synchronize_irq(adapter->msix_entries[i].vector);
1962 } else {
1963 synchronize_irq(adapter->pdev->irq);
1964 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001965}
1966
1967/**
1968 * e1000_irq_enable - Enable default interrupt generation settings
1969 **/
1970static void e1000_irq_enable(struct e1000_adapter *adapter)
1971{
1972 struct e1000_hw *hw = &adapter->hw;
1973
Bruce Allan4662e822008-08-26 18:37:06 -07001974 if (adapter->msix_entries) {
1975 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1976 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1977 } else {
1978 ew32(IMS, IMS_ENABLE_MASK);
1979 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001980 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001981}
1982
1983/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001984 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07001985 * @adapter: address of board private structure
1986 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001987 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001988 * For ASF and Pass Through versions of f/w this means that
1989 * the driver is loaded. For AMT version (only with 82573)
1990 * of the f/w this means that the network i/f is open.
1991 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001992void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001993{
1994 struct e1000_hw *hw = &adapter->hw;
1995 u32 ctrl_ext;
1996 u32 swsm;
1997
1998 /* Let firmware know the driver has taken over */
1999 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2000 swsm = er32(SWSM);
2001 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2002 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2003 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002004 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002005 }
2006}
2007
2008/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002009 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002010 * @adapter: address of board private structure
2011 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002012 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002013 * For ASF and Pass Through versions of f/w this means that the
2014 * driver is no longer loaded. For AMT version (only with 82573) i
2015 * of the f/w this means that the network i/f is closed.
2016 *
2017 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002018void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002019{
2020 struct e1000_hw *hw = &adapter->hw;
2021 u32 ctrl_ext;
2022 u32 swsm;
2023
2024 /* Let firmware taken over control of h/w */
2025 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2026 swsm = er32(SWSM);
2027 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2028 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2029 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002030 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002031 }
2032}
2033
Auke Kokbc7f75f2007-09-17 12:30:59 -07002034/**
2035 * @e1000_alloc_ring - allocate memory for a ring structure
2036 **/
2037static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2038 struct e1000_ring *ring)
2039{
2040 struct pci_dev *pdev = adapter->pdev;
2041
2042 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2043 GFP_KERNEL);
2044 if (!ring->desc)
2045 return -ENOMEM;
2046
2047 return 0;
2048}
2049
2050/**
2051 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2052 * @adapter: board private structure
2053 *
2054 * Return 0 on success, negative on failure
2055 **/
2056int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2057{
2058 struct e1000_ring *tx_ring = adapter->tx_ring;
2059 int err = -ENOMEM, size;
2060
2061 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002062 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002063 if (!tx_ring->buffer_info)
2064 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002065
2066 /* round up to nearest 4K */
2067 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2068 tx_ring->size = ALIGN(tx_ring->size, 4096);
2069
2070 err = e1000_alloc_ring_dma(adapter, tx_ring);
2071 if (err)
2072 goto err;
2073
2074 tx_ring->next_to_use = 0;
2075 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002076
2077 return 0;
2078err:
2079 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002080 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002081 return err;
2082}
2083
2084/**
2085 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2086 * @adapter: board private structure
2087 *
2088 * Returns 0 on success, negative on failure
2089 **/
2090int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2091{
2092 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002093 struct e1000_buffer *buffer_info;
2094 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002095
2096 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002097 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002098 if (!rx_ring->buffer_info)
2099 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002100
Auke Kok47f44e42007-10-25 13:57:44 -07002101 for (i = 0; i < rx_ring->count; i++) {
2102 buffer_info = &rx_ring->buffer_info[i];
2103 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2104 sizeof(struct e1000_ps_page),
2105 GFP_KERNEL);
2106 if (!buffer_info->ps_pages)
2107 goto err_pages;
2108 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002109
2110 desc_len = sizeof(union e1000_rx_desc_packet_split);
2111
2112 /* Round up to nearest 4K */
2113 rx_ring->size = rx_ring->count * desc_len;
2114 rx_ring->size = ALIGN(rx_ring->size, 4096);
2115
2116 err = e1000_alloc_ring_dma(adapter, rx_ring);
2117 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002118 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002119
2120 rx_ring->next_to_clean = 0;
2121 rx_ring->next_to_use = 0;
2122 rx_ring->rx_skb_top = NULL;
2123
2124 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002125
2126err_pages:
2127 for (i = 0; i < rx_ring->count; i++) {
2128 buffer_info = &rx_ring->buffer_info[i];
2129 kfree(buffer_info->ps_pages);
2130 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002131err:
2132 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002133 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002134 return err;
2135}
2136
2137/**
2138 * e1000_clean_tx_ring - Free Tx Buffers
2139 * @adapter: board private structure
2140 **/
2141static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2142{
2143 struct e1000_ring *tx_ring = adapter->tx_ring;
2144 struct e1000_buffer *buffer_info;
2145 unsigned long size;
2146 unsigned int i;
2147
2148 for (i = 0; i < tx_ring->count; i++) {
2149 buffer_info = &tx_ring->buffer_info[i];
2150 e1000_put_txbuf(adapter, buffer_info);
2151 }
2152
2153 size = sizeof(struct e1000_buffer) * tx_ring->count;
2154 memset(tx_ring->buffer_info, 0, size);
2155
2156 memset(tx_ring->desc, 0, tx_ring->size);
2157
2158 tx_ring->next_to_use = 0;
2159 tx_ring->next_to_clean = 0;
2160
2161 writel(0, adapter->hw.hw_addr + tx_ring->head);
2162 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2163}
2164
2165/**
2166 * e1000e_free_tx_resources - Free Tx Resources per Queue
2167 * @adapter: board private structure
2168 *
2169 * Free all transmit software resources
2170 **/
2171void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2172{
2173 struct pci_dev *pdev = adapter->pdev;
2174 struct e1000_ring *tx_ring = adapter->tx_ring;
2175
2176 e1000_clean_tx_ring(adapter);
2177
2178 vfree(tx_ring->buffer_info);
2179 tx_ring->buffer_info = NULL;
2180
2181 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2182 tx_ring->dma);
2183 tx_ring->desc = NULL;
2184}
2185
2186/**
2187 * e1000e_free_rx_resources - Free Rx Resources
2188 * @adapter: board private structure
2189 *
2190 * Free all receive software resources
2191 **/
2192
2193void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2194{
2195 struct pci_dev *pdev = adapter->pdev;
2196 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002197 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002198
2199 e1000_clean_rx_ring(adapter);
2200
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002201 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002202 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002203
Auke Kokbc7f75f2007-09-17 12:30:59 -07002204 vfree(rx_ring->buffer_info);
2205 rx_ring->buffer_info = NULL;
2206
Auke Kokbc7f75f2007-09-17 12:30:59 -07002207 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2208 rx_ring->dma);
2209 rx_ring->desc = NULL;
2210}
2211
2212/**
2213 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002214 * @adapter: pointer to adapter
2215 * @itr_setting: current adapter->itr
2216 * @packets: the number of packets during this measurement interval
2217 * @bytes: the number of bytes during this measurement interval
2218 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002219 * Stores a new ITR value based on packets and byte
2220 * counts during the last interrupt. The advantage of per interrupt
2221 * computation is faster updates and more accurate ITR for the current
2222 * traffic pattern. Constants in this function were computed
2223 * based on theoretical maximum wire speed and thresholds were set based
2224 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002225 * while increasing bulk throughput. This functionality is controlled
2226 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002227 **/
2228static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2229 u16 itr_setting, int packets,
2230 int bytes)
2231{
2232 unsigned int retval = itr_setting;
2233
2234 if (packets == 0)
2235 goto update_itr_done;
2236
2237 switch (itr_setting) {
2238 case lowest_latency:
2239 /* handle TSO and jumbo frames */
2240 if (bytes/packets > 8000)
2241 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002242 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002243 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244 break;
2245 case low_latency: /* 50 usec aka 20000 ints/s */
2246 if (bytes > 10000) {
2247 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002248 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002249 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002250 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002252 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002254 } else if (bytes/packets > 2000) {
2255 retval = bulk_latency;
2256 } else if (packets <= 2 && bytes < 512) {
2257 retval = lowest_latency;
2258 }
2259 break;
2260 case bulk_latency: /* 250 usec aka 4000 ints/s */
2261 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002262 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002263 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002264 } else if (bytes < 6000) {
2265 retval = low_latency;
2266 }
2267 break;
2268 }
2269
2270update_itr_done:
2271 return retval;
2272}
2273
2274static void e1000_set_itr(struct e1000_adapter *adapter)
2275{
2276 struct e1000_hw *hw = &adapter->hw;
2277 u16 current_itr;
2278 u32 new_itr = adapter->itr;
2279
2280 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2281 if (adapter->link_speed != SPEED_1000) {
2282 current_itr = 0;
2283 new_itr = 4000;
2284 goto set_itr_now;
2285 }
2286
Bruce Allan828bac82010-09-29 21:39:37 +00002287 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2288 new_itr = 0;
2289 goto set_itr_now;
2290 }
2291
Auke Kokbc7f75f2007-09-17 12:30:59 -07002292 adapter->tx_itr = e1000_update_itr(adapter,
2293 adapter->tx_itr,
2294 adapter->total_tx_packets,
2295 adapter->total_tx_bytes);
2296 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2297 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2298 adapter->tx_itr = low_latency;
2299
2300 adapter->rx_itr = e1000_update_itr(adapter,
2301 adapter->rx_itr,
2302 adapter->total_rx_packets,
2303 adapter->total_rx_bytes);
2304 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2305 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2306 adapter->rx_itr = low_latency;
2307
2308 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2309
2310 switch (current_itr) {
2311 /* counts and packets in update_itr are dependent on these numbers */
2312 case lowest_latency:
2313 new_itr = 70000;
2314 break;
2315 case low_latency:
2316 new_itr = 20000; /* aka hwitr = ~200 */
2317 break;
2318 case bulk_latency:
2319 new_itr = 4000;
2320 break;
2321 default:
2322 break;
2323 }
2324
2325set_itr_now:
2326 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002327 /*
2328 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002329 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002330 * increasing
2331 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002332 new_itr = new_itr > adapter->itr ?
2333 min(adapter->itr + (new_itr >> 2), new_itr) :
2334 new_itr;
2335 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002336 adapter->rx_ring->itr_val = new_itr;
2337 if (adapter->msix_entries)
2338 adapter->rx_ring->set_itr = 1;
2339 else
Bruce Allan828bac82010-09-29 21:39:37 +00002340 if (new_itr)
2341 ew32(ITR, 1000000000 / (new_itr * 256));
2342 else
2343 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344 }
2345}
2346
2347/**
Bruce Allan4662e822008-08-26 18:37:06 -07002348 * e1000_alloc_queues - Allocate memory for all rings
2349 * @adapter: board private structure to initialize
2350 **/
2351static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2352{
2353 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2354 if (!adapter->tx_ring)
2355 goto err;
2356
2357 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2358 if (!adapter->rx_ring)
2359 goto err;
2360
2361 return 0;
2362err:
2363 e_err("Unable to allocate memory for queues\n");
2364 kfree(adapter->rx_ring);
2365 kfree(adapter->tx_ring);
2366 return -ENOMEM;
2367}
2368
2369/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002370 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002371 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002372 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373 **/
2374static int e1000_clean(struct napi_struct *napi, int budget)
2375{
2376 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002377 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002379 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002380
Wang Chen4cf16532008-11-12 23:38:14 -08002381 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382
Bruce Allan4662e822008-08-26 18:37:06 -07002383 if (adapter->msix_entries &&
2384 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2385 goto clean_rx;
2386
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002387 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002388
Bruce Allan4662e822008-08-26 18:37:06 -07002389clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002390 adapter->clean_rx(adapter, &work_done, budget);
2391
Alexander Duyck12d04a32009-03-25 22:05:03 +00002392 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002393 work_done = budget;
2394
David S. Miller53e52c72008-01-07 21:06:12 -08002395 /* If budget not fully consumed, exit the polling mode */
2396 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002397 if (adapter->itr_setting & 3)
2398 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002399 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002400 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2401 if (adapter->msix_entries)
2402 ew32(IMS, adapter->rx_ring->ims_val);
2403 else
2404 e1000_irq_enable(adapter);
2405 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002406 }
2407
2408 return work_done;
2409}
2410
2411static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2412{
2413 struct e1000_adapter *adapter = netdev_priv(netdev);
2414 struct e1000_hw *hw = &adapter->hw;
2415 u32 vfta, index;
2416
2417 /* don't update vlan cookie if already programmed */
2418 if ((adapter->hw.mng_cookie.status &
2419 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2420 (vid == adapter->mng_vlan_id))
2421 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002422
Auke Kokbc7f75f2007-09-17 12:30:59 -07002423 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002424 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2425 index = (vid >> 5) & 0x7F;
2426 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2427 vfta |= (1 << (vid & 0x1F));
2428 hw->mac.ops.write_vfta(hw, index, vfta);
2429 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002430}
2431
2432static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2433{
2434 struct e1000_adapter *adapter = netdev_priv(netdev);
2435 struct e1000_hw *hw = &adapter->hw;
2436 u32 vfta, index;
2437
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002438 if (!test_bit(__E1000_DOWN, &adapter->state))
2439 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002441
2442 if (!test_bit(__E1000_DOWN, &adapter->state))
2443 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002444
2445 if ((adapter->hw.mng_cookie.status &
2446 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2447 (vid == adapter->mng_vlan_id)) {
2448 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002449 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002450 return;
2451 }
2452
2453 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002454 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2455 index = (vid >> 5) & 0x7F;
2456 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2457 vfta &= ~(1 << (vid & 0x1F));
2458 hw->mac.ops.write_vfta(hw, index, vfta);
2459 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002460}
2461
2462static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2463{
2464 struct net_device *netdev = adapter->netdev;
2465 u16 vid = adapter->hw.mng_cookie.vlan_id;
2466 u16 old_vid = adapter->mng_vlan_id;
2467
2468 if (!adapter->vlgrp)
2469 return;
2470
2471 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2472 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2473 if (adapter->hw.mng_cookie.status &
2474 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2475 e1000_vlan_rx_add_vid(netdev, vid);
2476 adapter->mng_vlan_id = vid;
2477 }
2478
2479 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2480 (vid != old_vid) &&
2481 !vlan_group_get_device(adapter->vlgrp, old_vid))
2482 e1000_vlan_rx_kill_vid(netdev, old_vid);
2483 } else {
2484 adapter->mng_vlan_id = vid;
2485 }
2486}
2487
2488
2489static void e1000_vlan_rx_register(struct net_device *netdev,
2490 struct vlan_group *grp)
2491{
2492 struct e1000_adapter *adapter = netdev_priv(netdev);
2493 struct e1000_hw *hw = &adapter->hw;
2494 u32 ctrl, rctl;
2495
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002496 if (!test_bit(__E1000_DOWN, &adapter->state))
2497 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002498 adapter->vlgrp = grp;
2499
2500 if (grp) {
2501 /* enable VLAN tag insert/strip */
2502 ctrl = er32(CTRL);
2503 ctrl |= E1000_CTRL_VME;
2504 ew32(CTRL, ctrl);
2505
2506 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2507 /* enable VLAN receive filtering */
2508 rctl = er32(RCTL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 rctl &= ~E1000_RCTL_CFIEN;
2510 ew32(RCTL, rctl);
2511 e1000_update_mng_vlan(adapter);
2512 }
2513 } else {
2514 /* disable VLAN tag insert/strip */
2515 ctrl = er32(CTRL);
2516 ctrl &= ~E1000_CTRL_VME;
2517 ew32(CTRL, ctrl);
2518
2519 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520 if (adapter->mng_vlan_id !=
2521 (u16)E1000_MNG_VLAN_NONE) {
2522 e1000_vlan_rx_kill_vid(netdev,
2523 adapter->mng_vlan_id);
2524 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2525 }
2526 }
2527 }
2528
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002529 if (!test_bit(__E1000_DOWN, &adapter->state))
2530 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002531}
2532
2533static void e1000_restore_vlan(struct e1000_adapter *adapter)
2534{
2535 u16 vid;
2536
2537 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2538
2539 if (!adapter->vlgrp)
2540 return;
2541
Jesse Grossb7381272010-10-20 13:56:02 +00002542 for (vid = 0; vid < VLAN_N_VID; vid++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002543 if (!vlan_group_get_device(adapter->vlgrp, vid))
2544 continue;
2545 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2546 }
2547}
2548
Bruce Allancd791612010-05-10 14:59:51 +00002549static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002550{
2551 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002552 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002553
2554 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2555 return;
2556
2557 manc = er32(MANC);
2558
Bruce Allanad680762008-03-28 09:15:03 -07002559 /*
2560 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002561 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002562 * the packets will be handled on SMBUS
2563 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002564 manc |= E1000_MANC_EN_MNG2HOST;
2565 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002566
2567 switch (hw->mac.type) {
2568 default:
2569 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2570 break;
2571 case e1000_82574:
2572 case e1000_82583:
2573 /*
2574 * Check if IPMI pass-through decision filter already exists;
2575 * if so, enable it.
2576 */
2577 for (i = 0, j = 0; i < 8; i++) {
2578 mdef = er32(MDEF(i));
2579
2580 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002581 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002582 continue;
2583
2584 /* Enable this decision filter in MANC2H */
2585 if (mdef)
2586 manc2h |= (1 << i);
2587
2588 j |= mdef;
2589 }
2590
2591 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2592 break;
2593
2594 /* Create new decision filter in an empty filter */
2595 for (i = 0, j = 0; i < 8; i++)
2596 if (er32(MDEF(i)) == 0) {
2597 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2598 E1000_MDEF_PORT_664));
2599 manc2h |= (1 << 1);
2600 j++;
2601 break;
2602 }
2603
2604 if (!j)
2605 e_warn("Unable to create IPMI pass-through filter\n");
2606 break;
2607 }
2608
Auke Kokbc7f75f2007-09-17 12:30:59 -07002609 ew32(MANC2H, manc2h);
2610 ew32(MANC, manc);
2611}
2612
2613/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002614 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002615 * @adapter: board private structure
2616 *
2617 * Configure the Tx unit of the MAC after a reset.
2618 **/
2619static void e1000_configure_tx(struct e1000_adapter *adapter)
2620{
2621 struct e1000_hw *hw = &adapter->hw;
2622 struct e1000_ring *tx_ring = adapter->tx_ring;
2623 u64 tdba;
2624 u32 tdlen, tctl, tipg, tarc;
2625 u32 ipgr1, ipgr2;
2626
2627 /* Setup the HW Tx Head and Tail descriptor pointers */
2628 tdba = tx_ring->dma;
2629 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002630 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002631 ew32(TDBAH, (tdba >> 32));
2632 ew32(TDLEN, tdlen);
2633 ew32(TDH, 0);
2634 ew32(TDT, 0);
2635 tx_ring->head = E1000_TDH;
2636 tx_ring->tail = E1000_TDT;
2637
2638 /* Set the default values for the Tx Inter Packet Gap timer */
2639 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2640 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2641 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2642
2643 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2644 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2645
2646 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2647 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2648 ew32(TIPG, tipg);
2649
2650 /* Set the Tx Interrupt Delay register */
2651 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002652 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002653 ew32(TADV, adapter->tx_abs_int_delay);
2654
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002655 if (adapter->flags2 & FLAG2_DMA_BURST) {
2656 u32 txdctl = er32(TXDCTL(0));
2657 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2658 E1000_TXDCTL_WTHRESH);
2659 /*
2660 * set up some performance related parameters to encourage the
2661 * hardware to use the bus more efficiently in bursts, depends
2662 * on the tx_int_delay to be enabled,
2663 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2664 * hthresh = 1 ==> prefetch when one or more available
2665 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2666 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002667 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002668 */
2669 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2670 ew32(TXDCTL(0), txdctl);
2671 /* erratum work around: set txdctl the same for both queues */
2672 ew32(TXDCTL(1), txdctl);
2673 }
2674
Auke Kokbc7f75f2007-09-17 12:30:59 -07002675 /* Program the Transmit Control Register */
2676 tctl = er32(TCTL);
2677 tctl &= ~E1000_TCTL_CT;
2678 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2679 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2680
2681 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002682 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002683 /*
2684 * set the speed mode bit, we'll clear it if we're not at
2685 * gigabit link later
2686 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002687#define SPEED_MODE_BIT (1 << 21)
2688 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002689 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002690 }
2691
2692 /* errata: program both queues to unweighted RR */
2693 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002694 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002695 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002696 ew32(TARC(0), tarc);
2697 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002698 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002699 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002700 }
2701
Auke Kokbc7f75f2007-09-17 12:30:59 -07002702 /* Setup Transmit Descriptor Settings for eop descriptor */
2703 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2704
2705 /* only set IDE if we are delaying interrupts using the timers */
2706 if (adapter->tx_int_delay)
2707 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2708
2709 /* enable Report Status bit */
2710 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2711
2712 ew32(TCTL, tctl);
2713
Simon Hormanedfea6e62009-06-08 14:28:36 +00002714 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002715}
2716
2717/**
2718 * e1000_setup_rctl - configure the receive control registers
2719 * @adapter: Board private structure
2720 **/
2721#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2722 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2723static void e1000_setup_rctl(struct e1000_adapter *adapter)
2724{
2725 struct e1000_hw *hw = &adapter->hw;
2726 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002727 u32 pages = 0;
2728
Bruce Allana1ce6472010-09-22 17:16:40 +00002729 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2730 if (hw->mac.type == e1000_pch2lan) {
2731 s32 ret_val;
2732
2733 if (adapter->netdev->mtu > ETH_DATA_LEN)
2734 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2735 else
2736 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002737
2738 if (ret_val)
2739 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002740 }
2741
Auke Kokbc7f75f2007-09-17 12:30:59 -07002742 /* Program MC offset vector base */
2743 rctl = er32(RCTL);
2744 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2745 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2746 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2747 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2748
2749 /* Do not Store bad packets */
2750 rctl &= ~E1000_RCTL_SBP;
2751
2752 /* Enable Long Packet receive */
2753 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2754 rctl &= ~E1000_RCTL_LPE;
2755 else
2756 rctl |= E1000_RCTL_LPE;
2757
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002758 /* Some systems expect that the CRC is included in SMBUS traffic. The
2759 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2760 * host memory when this is enabled
2761 */
2762 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2763 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002764
Bruce Allana4f58f52009-06-02 11:29:18 +00002765 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2766 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2767 u16 phy_data;
2768
2769 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2770 phy_data &= 0xfff8;
2771 phy_data |= (1 << 2);
2772 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2773
2774 e1e_rphy(hw, 22, &phy_data);
2775 phy_data &= 0x0fff;
2776 phy_data |= (1 << 14);
2777 e1e_wphy(hw, 0x10, 0x2823);
2778 e1e_wphy(hw, 0x11, 0x0003);
2779 e1e_wphy(hw, 22, phy_data);
2780 }
2781
Auke Kokbc7f75f2007-09-17 12:30:59 -07002782 /* Setup buffer sizes */
2783 rctl &= ~E1000_RCTL_SZ_4096;
2784 rctl |= E1000_RCTL_BSEX;
2785 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002786 case 2048:
2787 default:
2788 rctl |= E1000_RCTL_SZ_2048;
2789 rctl &= ~E1000_RCTL_BSEX;
2790 break;
2791 case 4096:
2792 rctl |= E1000_RCTL_SZ_4096;
2793 break;
2794 case 8192:
2795 rctl |= E1000_RCTL_SZ_8192;
2796 break;
2797 case 16384:
2798 rctl |= E1000_RCTL_SZ_16384;
2799 break;
2800 }
2801
2802 /*
2803 * 82571 and greater support packet-split where the protocol
2804 * header is placed in skb->data and the packet data is
2805 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2806 * In the case of a non-split, skb->data is linearly filled,
2807 * followed by the page buffers. Therefore, skb->data is
2808 * sized to hold the largest protocol header.
2809 *
2810 * allocations using alloc_page take too long for regular MTU
2811 * so only enable packet split for jumbo frames
2812 *
2813 * Using pages when the page size is greater than 16k wastes
2814 * a lot of memory, since we allocate 3 pages at all times
2815 * per packet.
2816 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002817 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fec2010-06-17 18:59:27 +00002818 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002819 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002820 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002821 else
2822 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002823
2824 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002825 u32 psrctl = 0;
2826
Auke Kokbc7f75f2007-09-17 12:30:59 -07002827 /* Configure extra packet-split registers */
2828 rfctl = er32(RFCTL);
2829 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002830 /*
2831 * disable packet split support for IPv6 extension headers,
2832 * because some malformed IPv6 headers can hang the Rx
2833 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002834 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2835 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2836
2837 ew32(RFCTL, rfctl);
2838
Auke Kok140a7482007-10-25 13:57:58 -07002839 /* Enable Packet split descriptors */
2840 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002841
2842 psrctl |= adapter->rx_ps_bsize0 >>
2843 E1000_PSRCTL_BSIZE0_SHIFT;
2844
2845 switch (adapter->rx_ps_pages) {
2846 case 3:
2847 psrctl |= PAGE_SIZE <<
2848 E1000_PSRCTL_BSIZE3_SHIFT;
2849 case 2:
2850 psrctl |= PAGE_SIZE <<
2851 E1000_PSRCTL_BSIZE2_SHIFT;
2852 case 1:
2853 psrctl |= PAGE_SIZE >>
2854 E1000_PSRCTL_BSIZE1_SHIFT;
2855 break;
2856 }
2857
2858 ew32(PSRCTL, psrctl);
2859 }
2860
2861 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002862 /* just started the receive unit, no need to restart */
2863 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002864}
2865
2866/**
2867 * e1000_configure_rx - Configure Receive Unit after Reset
2868 * @adapter: board private structure
2869 *
2870 * Configure the Rx unit of the MAC after a reset.
2871 **/
2872static void e1000_configure_rx(struct e1000_adapter *adapter)
2873{
2874 struct e1000_hw *hw = &adapter->hw;
2875 struct e1000_ring *rx_ring = adapter->rx_ring;
2876 u64 rdba;
2877 u32 rdlen, rctl, rxcsum, ctrl_ext;
2878
2879 if (adapter->rx_ps_pages) {
2880 /* this is a 32 byte descriptor */
2881 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002882 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002883 adapter->clean_rx = e1000_clean_rx_irq_ps;
2884 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002885 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2886 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2887 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2888 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002889 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002890 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002891 adapter->clean_rx = e1000_clean_rx_irq;
2892 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2893 }
2894
2895 /* disable receives while setting up the descriptors */
2896 rctl = er32(RCTL);
2897 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2898 e1e_flush();
2899 msleep(10);
2900
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002901 if (adapter->flags2 & FLAG2_DMA_BURST) {
2902 /*
2903 * set the writeback threshold (only takes effect if the RDTR
2904 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00002905 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002906 * granularity = 01
2907 * wthresh = 04,
2908 * hthresh = 04,
2909 * pthresh = 0x20
2910 */
2911 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
2912 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
2913
2914 /*
2915 * override the delay timers for enabling bursting, only if
2916 * the value was not set by the user via module options
2917 */
2918 if (adapter->rx_int_delay == DEFAULT_RDTR)
2919 adapter->rx_int_delay = BURST_RDTR;
2920 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
2921 adapter->rx_abs_int_delay = BURST_RADV;
2922 }
2923
Auke Kokbc7f75f2007-09-17 12:30:59 -07002924 /* set the Receive Delay Timer Register */
2925 ew32(RDTR, adapter->rx_int_delay);
2926
2927 /* irq moderation */
2928 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00002929 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07002930 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002931
2932 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933 /* Auto-Mask interrupts upon ICR access */
2934 ctrl_ext |= E1000_CTRL_EXT_IAME;
2935 ew32(IAM, 0xffffffff);
2936 ew32(CTRL_EXT, ctrl_ext);
2937 e1e_flush();
2938
Bruce Allanad680762008-03-28 09:15:03 -07002939 /*
2940 * Setup the HW Rx Head and Tail Descriptor Pointers and
2941 * the Base and Length of the Rx Descriptor Ring
2942 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002943 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002944 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002945 ew32(RDBAH, (rdba >> 32));
2946 ew32(RDLEN, rdlen);
2947 ew32(RDH, 0);
2948 ew32(RDT, 0);
2949 rx_ring->head = E1000_RDH;
2950 rx_ring->tail = E1000_RDT;
2951
2952 /* Enable Receive Checksum Offload for TCP and UDP */
2953 rxcsum = er32(RXCSUM);
2954 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2955 rxcsum |= E1000_RXCSUM_TUOFL;
2956
Bruce Allanad680762008-03-28 09:15:03 -07002957 /*
2958 * IPv4 payload checksum for UDP fragments must be
2959 * used in conjunction with packet-split.
2960 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961 if (adapter->rx_ps_pages)
2962 rxcsum |= E1000_RXCSUM_IPPCSE;
2963 } else {
2964 rxcsum &= ~E1000_RXCSUM_TUOFL;
2965 /* no need to clear IPPCSE as it defaults to 0 */
2966 }
2967 ew32(RXCSUM, rxcsum);
2968
Bruce Allanad680762008-03-28 09:15:03 -07002969 /*
2970 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002971 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002972 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2973 */
Bruce Allan828bac82010-09-29 21:39:37 +00002974 if ((adapter->flags & FLAG_HAS_ERT) ||
2975 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00002976 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2977 u32 rxdctl = er32(RXDCTL(0));
2978 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00002979 if (adapter->flags & FLAG_HAS_ERT)
2980 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00002981 /*
2982 * With jumbo frames and early-receive enabled,
2983 * excessive C-state transition latencies result in
2984 * dropped transactions.
2985 */
Bruce Allanaf667a22010-12-31 06:10:01 +00002986 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00002987 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00002988 pm_qos_update_request(&adapter->netdev->pm_qos_req,
2989 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00002990 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002991 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002992
2993 /* Enable Receives */
2994 ew32(RCTL, rctl);
2995}
2996
2997/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07002998 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07002999 * @hw: pointer to the HW structure
3000 * @mc_addr_list: array of multicast addresses to program
3001 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07003002 *
Bruce Allanab8932f2010-01-13 02:05:38 +00003003 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003004 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003005 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003006static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003007 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003008{
Bruce Allanab8932f2010-01-13 02:05:38 +00003009 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003010}
3011
3012/**
3013 * e1000_set_multi - Multicast and Promiscuous mode set
3014 * @netdev: network interface device structure
3015 *
3016 * The set_multi entry point is called whenever the multicast address
3017 * list or the network interface flags are updated. This routine is
3018 * responsible for configuring the hardware for proper multicast,
3019 * promiscuous mode, and all-multi behavior.
3020 **/
3021static void e1000_set_multi(struct net_device *netdev)
3022{
3023 struct e1000_adapter *adapter = netdev_priv(netdev);
3024 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003025 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003026 u8 *mta_list;
3027 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003028
3029 /* Check for Promiscuous and All Multicast modes */
3030
3031 rctl = er32(RCTL);
3032
3033 if (netdev->flags & IFF_PROMISC) {
3034 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003035 rctl &= ~E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003036 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003037 if (netdev->flags & IFF_ALLMULTI) {
3038 rctl |= E1000_RCTL_MPE;
3039 rctl &= ~E1000_RCTL_UPE;
3040 } else {
3041 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3042 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07003043 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardy746b9f02008-07-16 20:15:45 -07003044 rctl |= E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003045 }
3046
3047 ew32(RCTL, rctl);
3048
Jiri Pirko7aeef972010-02-05 02:52:39 +00003049 if (!netdev_mc_empty(netdev)) {
Bruce Allan90da0662011-01-06 07:02:53 +00003050 int i = 0;
3051
Jiri Pirko7aeef972010-02-05 02:52:39 +00003052 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003053 if (!mta_list)
3054 return;
3055
3056 /* prepare a packed array of only addresses. */
Jiri Pirko22bedad32010-04-01 21:22:57 +00003057 netdev_for_each_mc_addr(ha, netdev)
3058 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003059
Bruce Allanab8932f2010-01-13 02:05:38 +00003060 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003061 kfree(mta_list);
3062 } else {
3063 /*
3064 * if we're called from probe, we might not have
3065 * anything to do here, so clear out the list
3066 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003067 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003068 }
3069}
3070
3071/**
Bruce Allanad680762008-03-28 09:15:03 -07003072 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003073 * @adapter: private board structure
3074 **/
3075static void e1000_configure(struct e1000_adapter *adapter)
3076{
3077 e1000_set_multi(adapter->netdev);
3078
3079 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003080 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081
3082 e1000_configure_tx(adapter);
3083 e1000_setup_rctl(adapter);
3084 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003085 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003086}
3087
3088/**
3089 * e1000e_power_up_phy - restore link in case the phy was powered down
3090 * @adapter: address of board private structure
3091 *
3092 * The phy may be powered down to save power and turn off link when the
3093 * driver is unloaded and wake on lan is not enabled (among others)
3094 * *** this routine MUST be followed by a call to e1000e_reset ***
3095 **/
3096void e1000e_power_up_phy(struct e1000_adapter *adapter)
3097{
Bruce Allan17f208d2009-12-01 15:47:22 +00003098 if (adapter->hw.phy.ops.power_up)
3099 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003100
3101 adapter->hw.mac.ops.setup_link(&adapter->hw);
3102}
3103
3104/**
3105 * e1000_power_down_phy - Power down the PHY
3106 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003107 * Power down the PHY so no link is implied when interface is down.
3108 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003109 */
3110static void e1000_power_down_phy(struct e1000_adapter *adapter)
3111{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003112 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003113 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003114 return;
3115
Bruce Allan17f208d2009-12-01 15:47:22 +00003116 if (adapter->hw.phy.ops.power_down)
3117 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003118}
3119
3120/**
3121 * e1000e_reset - bring the hardware into a known good state
3122 *
3123 * This function boots the hardware and enables some settings that
3124 * require a configuration cycle of the hardware - those cannot be
3125 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003126 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003127 */
3128void e1000e_reset(struct e1000_adapter *adapter)
3129{
3130 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003131 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003132 struct e1000_hw *hw = &adapter->hw;
3133 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003134 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003135 u16 hwm;
3136
Bruce Allanad680762008-03-28 09:15:03 -07003137 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003138 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003139
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003140 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003141 /*
3142 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003143 * large enough to accommodate two full transmit packets,
3144 * rounded up to the next 1KB and expressed in KB. Likewise,
3145 * the Rx FIFO should be large enough to accommodate at least
3146 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003147 * expressed in KB.
3148 */
Auke Kokdf762462007-10-25 13:57:53 -07003149 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003150 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003151 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003152 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003153 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003154 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003155 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003156 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003157 */
3158 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003159 sizeof(struct e1000_tx_desc) -
3160 ETH_FCS_LEN) * 2;
3161 min_tx_space = ALIGN(min_tx_space, 1024);
3162 min_tx_space >>= 10;
3163 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003164 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003165 min_rx_space = ALIGN(min_rx_space, 1024);
3166 min_rx_space >>= 10;
3167
Bruce Allanad680762008-03-28 09:15:03 -07003168 /*
3169 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003170 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003171 * allocation, take space away from current Rx allocation
3172 */
Auke Kokdf762462007-10-25 13:57:53 -07003173 if ((tx_space < min_tx_space) &&
3174 ((min_tx_space - tx_space) < pba)) {
3175 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003176
Bruce Allanad680762008-03-28 09:15:03 -07003177 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003178 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003179 * adjustment or use Early Receive if available
3180 */
Auke Kokdf762462007-10-25 13:57:53 -07003181 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003182 (!(adapter->flags & FLAG_HAS_ERT)))
3183 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003184 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003185 }
Auke Kokdf762462007-10-25 13:57:53 -07003186
3187 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003188 }
3189
Bruce Allanad680762008-03-28 09:15:03 -07003190 /*
3191 * flow control settings
3192 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003193 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003194 * (or the size used for early receive) above it in the Rx FIFO.
3195 * Set it to the lower of:
3196 * - 90% of the Rx FIFO size, and
3197 * - the full Rx FIFO size minus the early receive size (for parts
3198 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003199 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003200 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003201 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3202 fc->pause_time = 0xFFFF;
3203 else
3204 fc->pause_time = E1000_FC_PAUSE_TIME;
3205 fc->send_xon = 1;
3206 fc->current_mode = fc->requested_mode;
3207
3208 switch (hw->mac.type) {
3209 default:
3210 if ((adapter->flags & FLAG_HAS_ERT) &&
3211 (adapter->netdev->mtu > ETH_DATA_LEN))
3212 hwm = min(((pba << 10) * 9 / 10),
3213 ((pba << 10) - (E1000_ERT_2048 << 3)));
3214 else
3215 hwm = min(((pba << 10) * 9 / 10),
3216 ((pba << 10) - adapter->max_frame_size));
3217
3218 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3219 fc->low_water = fc->high_water - 8;
3220 break;
3221 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003222 /*
3223 * Workaround PCH LOM adapter hangs with certain network
3224 * loads. If hangs persist, try disabling Tx flow control.
3225 */
3226 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3227 fc->high_water = 0x3500;
3228 fc->low_water = 0x1500;
3229 } else {
3230 fc->high_water = 0x5000;
3231 fc->low_water = 0x3000;
3232 }
Bruce Allana3055952010-05-10 15:02:12 +00003233 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003234 break;
3235 case e1000_pch2lan:
3236 fc->high_water = 0x05C20;
3237 fc->low_water = 0x05048;
3238 fc->pause_time = 0x0650;
3239 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003240 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3241 pba = 14;
3242 ew32(PBA, pba);
3243 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003244 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003245 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003246
Bruce Allan828bac82010-09-29 21:39:37 +00003247 /*
3248 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3249 * fit in receive buffer and early-receive not supported.
3250 */
3251 if (adapter->itr_setting & 0x3) {
3252 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3253 !(adapter->flags & FLAG_HAS_ERT)) {
3254 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3255 dev_info(&adapter->pdev->dev,
3256 "Interrupt Throttle Rate turned off\n");
3257 adapter->flags2 |= FLAG2_DISABLE_AIM;
3258 ew32(ITR, 0);
3259 }
3260 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3261 dev_info(&adapter->pdev->dev,
3262 "Interrupt Throttle Rate turned on\n");
3263 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3264 adapter->itr = 20000;
3265 ew32(ITR, 1000000000 / (adapter->itr * 256));
3266 }
3267 }
3268
Auke Kokbc7f75f2007-09-17 12:30:59 -07003269 /* Allow time for pending master requests to run */
3270 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003271
3272 /*
3273 * For parts with AMT enabled, let the firmware know
3274 * that the network interface is in control
3275 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003276 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003277 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003278
Auke Kokbc7f75f2007-09-17 12:30:59 -07003279 ew32(WUC, 0);
3280
3281 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003282 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003283
3284 e1000_update_mng_vlan(adapter);
3285
3286 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3287 ew32(VET, ETH_P_8021Q);
3288
3289 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003290
3291 if (!netif_running(adapter->netdev) &&
3292 !test_bit(__E1000_TESTING, &adapter->state)) {
3293 e1000_power_down_phy(adapter);
3294 return;
3295 }
3296
Auke Kokbc7f75f2007-09-17 12:30:59 -07003297 e1000_get_phy_info(hw);
3298
Bruce Allan918d7192009-06-02 11:28:20 +00003299 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3300 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003301 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003302 /*
3303 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003304 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003305 * different we would do if it failed
3306 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003307 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3308 phy_data &= ~IGP02E1000_PM_SPD;
3309 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3310 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003311}
3312
3313int e1000e_up(struct e1000_adapter *adapter)
3314{
3315 struct e1000_hw *hw = &adapter->hw;
3316
3317 /* hardware has been reset, we need to reload some things */
3318 e1000_configure(adapter);
3319
3320 clear_bit(__E1000_DOWN, &adapter->state);
3321
3322 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003323 if (adapter->msix_entries)
3324 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325 e1000_irq_enable(adapter);
3326
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003327 netif_wake_queue(adapter->netdev);
3328
Auke Kokbc7f75f2007-09-17 12:30:59 -07003329 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003330 if (adapter->msix_entries)
3331 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3332 else
3333 ew32(ICS, E1000_ICS_LSC);
3334
Auke Kokbc7f75f2007-09-17 12:30:59 -07003335 return 0;
3336}
3337
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003338static void e1000e_update_stats(struct e1000_adapter *adapter);
3339
Auke Kokbc7f75f2007-09-17 12:30:59 -07003340void e1000e_down(struct e1000_adapter *adapter)
3341{
3342 struct net_device *netdev = adapter->netdev;
3343 struct e1000_hw *hw = &adapter->hw;
3344 u32 tctl, rctl;
3345
Bruce Allanad680762008-03-28 09:15:03 -07003346 /*
3347 * signal that we're down so the interrupt handler does not
3348 * reschedule our watchdog timer
3349 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003350 set_bit(__E1000_DOWN, &adapter->state);
3351
3352 /* disable receives in the hardware */
3353 rctl = er32(RCTL);
3354 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3355 /* flush and sleep below */
3356
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003357 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003358
3359 /* disable transmits in the hardware */
3360 tctl = er32(TCTL);
3361 tctl &= ~E1000_TCTL_EN;
3362 ew32(TCTL, tctl);
3363 /* flush both disables and wait for them to finish */
3364 e1e_flush();
3365 msleep(10);
3366
3367 napi_disable(&adapter->napi);
3368 e1000_irq_disable(adapter);
3369
3370 del_timer_sync(&adapter->watchdog_timer);
3371 del_timer_sync(&adapter->phy_info_timer);
3372
Auke Kokbc7f75f2007-09-17 12:30:59 -07003373 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003374
3375 spin_lock(&adapter->stats64_lock);
3376 e1000e_update_stats(adapter);
3377 spin_unlock(&adapter->stats64_lock);
3378
Auke Kokbc7f75f2007-09-17 12:30:59 -07003379 adapter->link_speed = 0;
3380 adapter->link_duplex = 0;
3381
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003382 if (!pci_channel_offline(adapter->pdev))
3383 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003384 e1000_clean_tx_ring(adapter);
3385 e1000_clean_rx_ring(adapter);
3386
3387 /*
3388 * TODO: for power management, we could drop the link and
3389 * pci_disable_device here.
3390 */
3391}
3392
3393void e1000e_reinit_locked(struct e1000_adapter *adapter)
3394{
3395 might_sleep();
3396 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3397 msleep(1);
3398 e1000e_down(adapter);
3399 e1000e_up(adapter);
3400 clear_bit(__E1000_RESETTING, &adapter->state);
3401}
3402
3403/**
3404 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3405 * @adapter: board private structure to initialize
3406 *
3407 * e1000_sw_init initializes the Adapter private data structure.
3408 * Fields are initialized based on PCI device information and
3409 * OS network device settings (MTU size).
3410 **/
3411static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3412{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003413 struct net_device *netdev = adapter->netdev;
3414
3415 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3416 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003417 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3418 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003419
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003420 spin_lock_init(&adapter->stats64_lock);
3421
Bruce Allan4662e822008-08-26 18:37:06 -07003422 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003423
Bruce Allan4662e822008-08-26 18:37:06 -07003424 if (e1000_alloc_queues(adapter))
3425 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426
Auke Kokbc7f75f2007-09-17 12:30:59 -07003427 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003428 e1000_irq_disable(adapter);
3429
Auke Kokbc7f75f2007-09-17 12:30:59 -07003430 set_bit(__E1000_DOWN, &adapter->state);
3431 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003432}
3433
3434/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003435 * e1000_intr_msi_test - Interrupt Handler
3436 * @irq: interrupt number
3437 * @data: pointer to a network interface device structure
3438 **/
3439static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3440{
3441 struct net_device *netdev = data;
3442 struct e1000_adapter *adapter = netdev_priv(netdev);
3443 struct e1000_hw *hw = &adapter->hw;
3444 u32 icr = er32(ICR);
3445
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003446 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003447 if (icr & E1000_ICR_RXSEQ) {
3448 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3449 wmb();
3450 }
3451
3452 return IRQ_HANDLED;
3453}
3454
3455/**
3456 * e1000_test_msi_interrupt - Returns 0 for successful test
3457 * @adapter: board private struct
3458 *
3459 * code flow taken from tg3.c
3460 **/
3461static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3462{
3463 struct net_device *netdev = adapter->netdev;
3464 struct e1000_hw *hw = &adapter->hw;
3465 int err;
3466
3467 /* poll_enable hasn't been called yet, so don't need disable */
3468 /* clear any pending events */
3469 er32(ICR);
3470
3471 /* free the real vector and request a test handler */
3472 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003473 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003474
3475 /* Assume that the test fails, if it succeeds then the test
3476 * MSI irq handler will unset this flag */
3477 adapter->flags |= FLAG_MSI_TEST_FAILED;
3478
3479 err = pci_enable_msi(adapter->pdev);
3480 if (err)
3481 goto msi_test_failed;
3482
Joe Perchesa0607fd2009-11-18 23:29:17 -08003483 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003484 netdev->name, netdev);
3485 if (err) {
3486 pci_disable_msi(adapter->pdev);
3487 goto msi_test_failed;
3488 }
3489
3490 wmb();
3491
3492 e1000_irq_enable(adapter);
3493
3494 /* fire an unusual interrupt on the test handler */
3495 ew32(ICS, E1000_ICS_RXSEQ);
3496 e1e_flush();
3497 msleep(50);
3498
3499 e1000_irq_disable(adapter);
3500
3501 rmb();
3502
3503 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003504 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003505 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3506 } else
3507 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003508
3509 free_irq(adapter->pdev->irq, netdev);
3510 pci_disable_msi(adapter->pdev);
3511
Bruce Allanf8d59f72008-08-08 18:36:11 -07003512msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003513 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003514 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003515}
3516
3517/**
3518 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3519 * @adapter: board private struct
3520 *
3521 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3522 **/
3523static int e1000_test_msi(struct e1000_adapter *adapter)
3524{
3525 int err;
3526 u16 pci_cmd;
3527
3528 if (!(adapter->flags & FLAG_MSI_ENABLED))
3529 return 0;
3530
3531 /* disable SERR in case the MSI write causes a master abort */
3532 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003533 if (pci_cmd & PCI_COMMAND_SERR)
3534 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3535 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003536
3537 err = e1000_test_msi_interrupt(adapter);
3538
Dean Nelson36f24072010-06-29 18:12:05 +00003539 /* re-enable SERR */
3540 if (pci_cmd & PCI_COMMAND_SERR) {
3541 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3542 pci_cmd |= PCI_COMMAND_SERR;
3543 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3544 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003545
Bruce Allanf8d59f72008-08-08 18:36:11 -07003546 return err;
3547}
3548
3549/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003550 * e1000_open - Called when a network interface is made active
3551 * @netdev: network interface device structure
3552 *
3553 * Returns 0 on success, negative value on failure
3554 *
3555 * The open entry point is called when a network interface is made
3556 * active by the system (IFF_UP). At this point all resources needed
3557 * for transmit and receive operations are allocated, the interrupt
3558 * handler is registered with the OS, the watchdog timer is started,
3559 * and the stack is notified that the interface is ready.
3560 **/
3561static int e1000_open(struct net_device *netdev)
3562{
3563 struct e1000_adapter *adapter = netdev_priv(netdev);
3564 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003565 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003566 int err;
3567
3568 /* disallow open during test */
3569 if (test_bit(__E1000_TESTING, &adapter->state))
3570 return -EBUSY;
3571
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003572 pm_runtime_get_sync(&pdev->dev);
3573
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003574 netif_carrier_off(netdev);
3575
Auke Kokbc7f75f2007-09-17 12:30:59 -07003576 /* allocate transmit descriptors */
3577 err = e1000e_setup_tx_resources(adapter);
3578 if (err)
3579 goto err_setup_tx;
3580
3581 /* allocate receive descriptors */
3582 err = e1000e_setup_rx_resources(adapter);
3583 if (err)
3584 goto err_setup_rx;
3585
Bruce Allan11b08be2010-05-10 14:59:31 +00003586 /*
3587 * If AMT is enabled, let the firmware know that the network
3588 * interface is now open and reset the part to a known state.
3589 */
3590 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003591 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003592 e1000e_reset(adapter);
3593 }
3594
Auke Kokbc7f75f2007-09-17 12:30:59 -07003595 e1000e_power_up_phy(adapter);
3596
3597 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3598 if ((adapter->hw.mng_cookie.status &
3599 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3600 e1000_update_mng_vlan(adapter);
3601
Florian Micklerc128ec22010-08-02 14:27:00 +00003602 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003603 if ((adapter->flags & FLAG_HAS_ERT) ||
3604 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003605 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3606 PM_QOS_CPU_DMA_LATENCY,
3607 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003608
Bruce Allanad680762008-03-28 09:15:03 -07003609 /*
Bruce Allanad680762008-03-28 09:15:03 -07003610 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003611 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3612 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003613 * clean_rx handler before we do so.
3614 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003615 e1000_configure(adapter);
3616
3617 err = e1000_request_irq(adapter);
3618 if (err)
3619 goto err_req_irq;
3620
Bruce Allanf8d59f72008-08-08 18:36:11 -07003621 /*
3622 * Work around PCIe errata with MSI interrupts causing some chipsets to
3623 * ignore e1000e MSI messages, which means we need to test our MSI
3624 * interrupt now
3625 */
Bruce Allan4662e822008-08-26 18:37:06 -07003626 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003627 err = e1000_test_msi(adapter);
3628 if (err) {
3629 e_err("Interrupt allocation failed\n");
3630 goto err_req_irq;
3631 }
3632 }
3633
Auke Kokbc7f75f2007-09-17 12:30:59 -07003634 /* From here on the code is the same as e1000e_up() */
3635 clear_bit(__E1000_DOWN, &adapter->state);
3636
3637 napi_enable(&adapter->napi);
3638
3639 e1000_irq_enable(adapter);
3640
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003641 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003642
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003643 adapter->idle_check = true;
3644 pm_runtime_put(&pdev->dev);
3645
Auke Kokbc7f75f2007-09-17 12:30:59 -07003646 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003647 if (adapter->msix_entries)
3648 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3649 else
3650 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003651
3652 return 0;
3653
3654err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003655 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656 e1000_power_down_phy(adapter);
3657 e1000e_free_rx_resources(adapter);
3658err_setup_rx:
3659 e1000e_free_tx_resources(adapter);
3660err_setup_tx:
3661 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003662 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003663
3664 return err;
3665}
3666
3667/**
3668 * e1000_close - Disables a network interface
3669 * @netdev: network interface device structure
3670 *
3671 * Returns 0, this is not allowed to fail
3672 *
3673 * The close entry point is called when an interface is de-activated
3674 * by the OS. The hardware is still under the drivers control, but
3675 * needs to be disabled. A global MAC reset is issued to stop the
3676 * hardware, and all transmit and receive resources are freed.
3677 **/
3678static int e1000_close(struct net_device *netdev)
3679{
3680 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003681 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682
3683 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003684
3685 pm_runtime_get_sync(&pdev->dev);
3686
3687 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3688 e1000e_down(adapter);
3689 e1000_free_irq(adapter);
3690 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003692
3693 e1000e_free_tx_resources(adapter);
3694 e1000e_free_rx_resources(adapter);
3695
Bruce Allanad680762008-03-28 09:15:03 -07003696 /*
3697 * kill manageability vlan ID if supported, but not if a vlan with
3698 * the same ID is registered on the host OS (let 8021q kill it)
3699 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003700 if ((adapter->hw.mng_cookie.status &
3701 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3702 !(adapter->vlgrp &&
3703 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3704 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3705
Bruce Allanad680762008-03-28 09:15:03 -07003706 /*
3707 * If AMT is enabled, let the firmware know that the network
3708 * interface is now closed
3709 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003710 if ((adapter->flags & FLAG_HAS_AMT) &&
3711 !test_bit(__E1000_TESTING, &adapter->state))
3712 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003713
Bruce Allan828bac82010-09-29 21:39:37 +00003714 if ((adapter->flags & FLAG_HAS_ERT) ||
3715 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003716 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003717
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003718 pm_runtime_put_sync(&pdev->dev);
3719
Auke Kokbc7f75f2007-09-17 12:30:59 -07003720 return 0;
3721}
3722/**
3723 * e1000_set_mac - Change the Ethernet Address of the NIC
3724 * @netdev: network interface device structure
3725 * @p: pointer to an address structure
3726 *
3727 * Returns 0 on success, negative on failure
3728 **/
3729static int e1000_set_mac(struct net_device *netdev, void *p)
3730{
3731 struct e1000_adapter *adapter = netdev_priv(netdev);
3732 struct sockaddr *addr = p;
3733
3734 if (!is_valid_ether_addr(addr->sa_data))
3735 return -EADDRNOTAVAIL;
3736
3737 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3738 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3739
3740 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3741
3742 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3743 /* activate the work around */
3744 e1000e_set_laa_state_82571(&adapter->hw, 1);
3745
Bruce Allanad680762008-03-28 09:15:03 -07003746 /*
3747 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003748 * between the time RAR[0] gets clobbered and the time it
3749 * gets fixed (in e1000_watchdog), the actual LAA is in one
3750 * of the RARs and no incoming packets directed to this port
3751 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003752 * RAR[14]
3753 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003754 e1000e_rar_set(&adapter->hw,
3755 adapter->hw.mac.addr,
3756 adapter->hw.mac.rar_entry_count - 1);
3757 }
3758
3759 return 0;
3760}
3761
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003762/**
3763 * e1000e_update_phy_task - work thread to update phy
3764 * @work: pointer to our work struct
3765 *
3766 * this worker thread exists because we must acquire a
3767 * semaphore to read the phy, which we could msleep while
3768 * waiting for it, and we can't msleep in a timer.
3769 **/
3770static void e1000e_update_phy_task(struct work_struct *work)
3771{
3772 struct e1000_adapter *adapter = container_of(work,
3773 struct e1000_adapter, update_phy_task);
3774 e1000_get_phy_info(&adapter->hw);
3775}
3776
Bruce Allanad680762008-03-28 09:15:03 -07003777/*
3778 * Need to wait a few seconds after link up to get diagnostic information from
3779 * the phy
3780 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003781static void e1000_update_phy_info(unsigned long data)
3782{
3783 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003784 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003785}
3786
3787/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003788 * e1000e_update_phy_stats - Update the PHY statistics counters
3789 * @adapter: board private structure
3790 **/
3791static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3792{
3793 struct e1000_hw *hw = &adapter->hw;
3794 s32 ret_val;
3795 u16 phy_data;
3796
3797 ret_val = hw->phy.ops.acquire(hw);
3798 if (ret_val)
3799 return;
3800
3801 hw->phy.addr = 1;
3802
3803#define HV_PHY_STATS_PAGE 778
3804 /*
3805 * A page set is expensive so check if already on desired page.
3806 * If not, set to the page with the PHY status registers.
3807 */
3808 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3809 &phy_data);
3810 if (ret_val)
3811 goto release;
3812 if (phy_data != (HV_PHY_STATS_PAGE << IGP_PAGE_SHIFT)) {
3813 ret_val = e1000e_write_phy_reg_mdic(hw,
3814 IGP01E1000_PHY_PAGE_SELECT,
3815 (HV_PHY_STATS_PAGE <<
3816 IGP_PAGE_SHIFT));
3817 if (ret_val)
3818 goto release;
3819 }
3820
3821 /* Read/clear the upper 16-bit registers and read/accumulate lower */
3822
3823 /* Single Collision Count */
3824 e1000e_read_phy_reg_mdic(hw, HV_SCC_UPPER & MAX_PHY_REG_ADDRESS,
3825 &phy_data);
3826 ret_val = e1000e_read_phy_reg_mdic(hw,
3827 HV_SCC_LOWER & MAX_PHY_REG_ADDRESS,
3828 &phy_data);
3829 if (!ret_val)
3830 adapter->stats.scc += phy_data;
3831
3832 /* Excessive Collision Count */
3833 e1000e_read_phy_reg_mdic(hw, HV_ECOL_UPPER & MAX_PHY_REG_ADDRESS,
3834 &phy_data);
3835 ret_val = e1000e_read_phy_reg_mdic(hw,
3836 HV_ECOL_LOWER & MAX_PHY_REG_ADDRESS,
3837 &phy_data);
3838 if (!ret_val)
3839 adapter->stats.ecol += phy_data;
3840
3841 /* Multiple Collision Count */
3842 e1000e_read_phy_reg_mdic(hw, HV_MCC_UPPER & MAX_PHY_REG_ADDRESS,
3843 &phy_data);
3844 ret_val = e1000e_read_phy_reg_mdic(hw,
3845 HV_MCC_LOWER & MAX_PHY_REG_ADDRESS,
3846 &phy_data);
3847 if (!ret_val)
3848 adapter->stats.mcc += phy_data;
3849
3850 /* Late Collision Count */
3851 e1000e_read_phy_reg_mdic(hw, HV_LATECOL_UPPER & MAX_PHY_REG_ADDRESS,
3852 &phy_data);
3853 ret_val = e1000e_read_phy_reg_mdic(hw,
3854 HV_LATECOL_LOWER &
3855 MAX_PHY_REG_ADDRESS,
3856 &phy_data);
3857 if (!ret_val)
3858 adapter->stats.latecol += phy_data;
3859
3860 /* Collision Count - also used for adaptive IFS */
3861 e1000e_read_phy_reg_mdic(hw, HV_COLC_UPPER & MAX_PHY_REG_ADDRESS,
3862 &phy_data);
3863 ret_val = e1000e_read_phy_reg_mdic(hw,
3864 HV_COLC_LOWER & MAX_PHY_REG_ADDRESS,
3865 &phy_data);
3866 if (!ret_val)
3867 hw->mac.collision_delta = phy_data;
3868
3869 /* Defer Count */
3870 e1000e_read_phy_reg_mdic(hw, HV_DC_UPPER & MAX_PHY_REG_ADDRESS,
3871 &phy_data);
3872 ret_val = e1000e_read_phy_reg_mdic(hw,
3873 HV_DC_LOWER & MAX_PHY_REG_ADDRESS,
3874 &phy_data);
3875 if (!ret_val)
3876 adapter->stats.dc += phy_data;
3877
3878 /* Transmit with no CRS */
3879 e1000e_read_phy_reg_mdic(hw, HV_TNCRS_UPPER & MAX_PHY_REG_ADDRESS,
3880 &phy_data);
3881 ret_val = e1000e_read_phy_reg_mdic(hw,
3882 HV_TNCRS_LOWER & MAX_PHY_REG_ADDRESS,
3883 &phy_data);
3884 if (!ret_val)
3885 adapter->stats.tncrs += phy_data;
3886
3887release:
3888 hw->phy.ops.release(hw);
3889}
3890
3891/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003892 * e1000e_update_stats - Update the board statistics counters
3893 * @adapter: board private structure
3894 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003895static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003896{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003897 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003898 struct e1000_hw *hw = &adapter->hw;
3899 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003900
3901 /*
3902 * Prevent stats update while adapter is being reset, or if the pci
3903 * connection is down.
3904 */
3905 if (adapter->link_speed == 0)
3906 return;
3907 if (pci_channel_offline(pdev))
3908 return;
3909
Auke Kokbc7f75f2007-09-17 12:30:59 -07003910 adapter->stats.crcerrs += er32(CRCERRS);
3911 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003912 adapter->stats.gorc += er32(GORCL);
3913 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003914 adapter->stats.bprc += er32(BPRC);
3915 adapter->stats.mprc += er32(MPRC);
3916 adapter->stats.roc += er32(ROC);
3917
Auke Kokbc7f75f2007-09-17 12:30:59 -07003918 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003919
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003920 /* Half-duplex statistics */
3921 if (adapter->link_duplex == HALF_DUPLEX) {
3922 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
3923 e1000e_update_phy_stats(adapter);
3924 } else {
3925 adapter->stats.scc += er32(SCC);
3926 adapter->stats.ecol += er32(ECOL);
3927 adapter->stats.mcc += er32(MCC);
3928 adapter->stats.latecol += er32(LATECOL);
3929 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003930
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003931 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003932
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003933 if ((hw->mac.type != e1000_82574) &&
3934 (hw->mac.type != e1000_82583))
3935 adapter->stats.tncrs += er32(TNCRS);
3936 }
3937 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003938 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003939
Auke Kokbc7f75f2007-09-17 12:30:59 -07003940 adapter->stats.xonrxc += er32(XONRXC);
3941 adapter->stats.xontxc += er32(XONTXC);
3942 adapter->stats.xoffrxc += er32(XOFFRXC);
3943 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003944 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003945 adapter->stats.gotc += er32(GOTCL);
3946 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003947 adapter->stats.rnbc += er32(RNBC);
3948 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003949
3950 adapter->stats.mptc += er32(MPTC);
3951 adapter->stats.bptc += er32(BPTC);
3952
3953 /* used for adaptive IFS */
3954
3955 hw->mac.tx_packet_delta = er32(TPT);
3956 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003957
3958 adapter->stats.algnerrc += er32(ALGNERRC);
3959 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003960 adapter->stats.cexterr += er32(CEXTERR);
3961 adapter->stats.tsctc += er32(TSCTC);
3962 adapter->stats.tsctfc += er32(TSCTFC);
3963
Auke Kokbc7f75f2007-09-17 12:30:59 -07003964 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003965 netdev->stats.multicast = adapter->stats.mprc;
3966 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003967
3968 /* Rx Errors */
3969
Bruce Allanad680762008-03-28 09:15:03 -07003970 /*
3971 * RLEC on some newer hardware can be incorrect so build
3972 * our own version based on RUC and ROC
3973 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003974 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003975 adapter->stats.crcerrs + adapter->stats.algnerrc +
3976 adapter->stats.ruc + adapter->stats.roc +
3977 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003978 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003979 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003980 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3981 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3982 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983
3984 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003985 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003986 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003987 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3988 netdev->stats.tx_window_errors = adapter->stats.latecol;
3989 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003990
3991 /* Tx Dropped needs to be maintained elsewhere */
3992
Auke Kokbc7f75f2007-09-17 12:30:59 -07003993 /* Management Stats */
3994 adapter->stats.mgptc += er32(MGTPTC);
3995 adapter->stats.mgprc += er32(MGTPRC);
3996 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003997}
3998
Bruce Allan7c257692008-04-23 11:09:00 -07003999/**
4000 * e1000_phy_read_status - Update the PHY register status snapshot
4001 * @adapter: board private structure
4002 **/
4003static void e1000_phy_read_status(struct e1000_adapter *adapter)
4004{
4005 struct e1000_hw *hw = &adapter->hw;
4006 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004007
4008 if ((er32(STATUS) & E1000_STATUS_LU) &&
4009 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004010 int ret_val;
4011
Bruce Allan7c257692008-04-23 11:09:00 -07004012 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4013 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4014 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4015 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4016 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4017 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4018 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4019 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4020 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004021 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004022 } else {
4023 /*
4024 * Do not read PHY registers if link is not up
4025 * Set values to typical power-on defaults
4026 */
4027 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4028 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4029 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4030 BMSR_ERCAP);
4031 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4032 ADVERTISE_ALL | ADVERTISE_CSMA);
4033 phy->lpa = 0;
4034 phy->expansion = EXPANSION_ENABLENPAGE;
4035 phy->ctrl1000 = ADVERTISE_1000FULL;
4036 phy->stat1000 = 0;
4037 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4038 }
Bruce Allan7c257692008-04-23 11:09:00 -07004039}
4040
Auke Kokbc7f75f2007-09-17 12:30:59 -07004041static void e1000_print_link_info(struct e1000_adapter *adapter)
4042{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004043 struct e1000_hw *hw = &adapter->hw;
4044 u32 ctrl = er32(CTRL);
4045
Bruce Allan8f12fe82008-11-21 16:54:43 -08004046 /* Link status message must follow this format for user tools */
4047 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4048 "Flow Control: %s\n",
4049 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004050 adapter->link_speed,
4051 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004052 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004053 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004054 "Rx/Tx" :
4055 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4056 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004057}
4058
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004059static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004060{
4061 struct e1000_hw *hw = &adapter->hw;
4062 bool link_active = 0;
4063 s32 ret_val = 0;
4064
4065 /*
4066 * get_link_status is set on LSC (link status) interrupt or
4067 * Rx sequence error interrupt. get_link_status will stay
4068 * false until the check_for_link establishes link
4069 * for copper adapters ONLY
4070 */
4071 switch (hw->phy.media_type) {
4072 case e1000_media_type_copper:
4073 if (hw->mac.get_link_status) {
4074 ret_val = hw->mac.ops.check_for_link(hw);
4075 link_active = !hw->mac.get_link_status;
4076 } else {
4077 link_active = 1;
4078 }
4079 break;
4080 case e1000_media_type_fiber:
4081 ret_val = hw->mac.ops.check_for_link(hw);
4082 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4083 break;
4084 case e1000_media_type_internal_serdes:
4085 ret_val = hw->mac.ops.check_for_link(hw);
4086 link_active = adapter->hw.mac.serdes_has_link;
4087 break;
4088 default:
4089 case e1000_media_type_unknown:
4090 break;
4091 }
4092
4093 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4094 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4095 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004096 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004097 }
4098
4099 return link_active;
4100}
4101
4102static void e1000e_enable_receives(struct e1000_adapter *adapter)
4103{
4104 /* make sure the receive unit is started */
4105 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4106 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4107 struct e1000_hw *hw = &adapter->hw;
4108 u32 rctl = er32(RCTL);
4109 ew32(RCTL, rctl | E1000_RCTL_EN);
4110 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4111 }
4112}
4113
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004114static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4115{
4116 struct e1000_hw *hw = &adapter->hw;
4117
4118 /*
4119 * With 82574 controllers, PHY needs to be checked periodically
4120 * for hung state and reset, if two calls return true
4121 */
4122 if (e1000_check_phy_82574(hw))
4123 adapter->phy_hang_count++;
4124 else
4125 adapter->phy_hang_count = 0;
4126
4127 if (adapter->phy_hang_count > 1) {
4128 adapter->phy_hang_count = 0;
4129 schedule_work(&adapter->reset_task);
4130 }
4131}
4132
Auke Kokbc7f75f2007-09-17 12:30:59 -07004133/**
4134 * e1000_watchdog - Timer Call-back
4135 * @data: pointer to adapter cast into an unsigned long
4136 **/
4137static void e1000_watchdog(unsigned long data)
4138{
4139 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4140
4141 /* Do the rest outside of interrupt context */
4142 schedule_work(&adapter->watchdog_task);
4143
4144 /* TODO: make this use queue_delayed_work() */
4145}
4146
4147static void e1000_watchdog_task(struct work_struct *work)
4148{
4149 struct e1000_adapter *adapter = container_of(work,
4150 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004151 struct net_device *netdev = adapter->netdev;
4152 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004153 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004154 struct e1000_ring *tx_ring = adapter->tx_ring;
4155 struct e1000_hw *hw = &adapter->hw;
4156 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004157
David S. Millerb405e8d2010-02-04 22:31:41 -08004158 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004159 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004160 /* Cancel scheduled suspend requests. */
4161 pm_runtime_resume(netdev->dev.parent);
4162
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004163 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004164 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004165 }
4166
4167 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4168 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4169 e1000_update_mng_vlan(adapter);
4170
Auke Kokbc7f75f2007-09-17 12:30:59 -07004171 if (link) {
4172 if (!netif_carrier_ok(netdev)) {
4173 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004174
4175 /* Cancel scheduled suspend requests. */
4176 pm_runtime_resume(netdev->dev.parent);
4177
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004178 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004179 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004180 mac->ops.get_link_up_info(&adapter->hw,
4181 &adapter->link_speed,
4182 &adapter->link_duplex);
4183 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004184 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004185 * On supported PHYs, check for duplex mismatch only
4186 * if link has autonegotiated at 10/100 half
4187 */
4188 if ((hw->phy.type == e1000_phy_igp_3 ||
4189 hw->phy.type == e1000_phy_bm) &&
4190 (hw->mac.autoneg == true) &&
4191 (adapter->link_speed == SPEED_10 ||
4192 adapter->link_speed == SPEED_100) &&
4193 (adapter->link_duplex == HALF_DUPLEX)) {
4194 u16 autoneg_exp;
4195
4196 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4197
4198 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4199 e_info("Autonegotiated half duplex but"
4200 " link partner cannot autoneg. "
4201 " Try forcing full duplex if "
4202 "link gets many collisions.\n");
4203 }
4204
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004205 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004206 adapter->tx_timeout_factor = 1;
4207 switch (adapter->link_speed) {
4208 case SPEED_10:
4209 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004210 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004211 break;
4212 case SPEED_100:
4213 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004214 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004215 break;
4216 }
4217
Bruce Allanad680762008-03-28 09:15:03 -07004218 /*
4219 * workaround: re-program speed mode bit after
4220 * link-up event
4221 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4223 !txb2b) {
4224 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004225 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004226 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004227 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004228 }
4229
Bruce Allanad680762008-03-28 09:15:03 -07004230 /*
4231 * disable TSO for pcie and 10/100 speeds, to avoid
4232 * some hardware issues
4233 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004234 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4235 switch (adapter->link_speed) {
4236 case SPEED_10:
4237 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004238 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004239 netdev->features &= ~NETIF_F_TSO;
4240 netdev->features &= ~NETIF_F_TSO6;
4241 break;
4242 case SPEED_1000:
4243 netdev->features |= NETIF_F_TSO;
4244 netdev->features |= NETIF_F_TSO6;
4245 break;
4246 default:
4247 /* oops */
4248 break;
4249 }
4250 }
4251
Bruce Allanad680762008-03-28 09:15:03 -07004252 /*
4253 * enable transmits in the hardware, need to do this
4254 * after setting TARC(0)
4255 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004256 tctl = er32(TCTL);
4257 tctl |= E1000_TCTL_EN;
4258 ew32(TCTL, tctl);
4259
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004260 /*
4261 * Perform any post-link-up configuration before
4262 * reporting link up.
4263 */
4264 if (phy->ops.cfg_on_link_up)
4265 phy->ops.cfg_on_link_up(hw);
4266
Auke Kokbc7f75f2007-09-17 12:30:59 -07004267 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004268
4269 if (!test_bit(__E1000_DOWN, &adapter->state))
4270 mod_timer(&adapter->phy_info_timer,
4271 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004272 }
4273 } else {
4274 if (netif_carrier_ok(netdev)) {
4275 adapter->link_speed = 0;
4276 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004277 /* Link status message must follow this format */
4278 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4279 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004280 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004281 if (!test_bit(__E1000_DOWN, &adapter->state))
4282 mod_timer(&adapter->phy_info_timer,
4283 round_jiffies(jiffies + 2 * HZ));
4284
4285 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4286 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004287 else
4288 pm_schedule_suspend(netdev->dev.parent,
4289 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004290 }
4291 }
4292
4293link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004294 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004295 e1000e_update_stats(adapter);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004296 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004297
4298 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4299 adapter->tpt_old = adapter->stats.tpt;
4300 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4301 adapter->colc_old = adapter->stats.colc;
4302
Bruce Allan7c257692008-04-23 11:09:00 -07004303 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4304 adapter->gorc_old = adapter->stats.gorc;
4305 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4306 adapter->gotc_old = adapter->stats.gotc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004307
4308 e1000e_update_adaptive(&adapter->hw);
4309
Bruce Allan90da0662011-01-06 07:02:53 +00004310 if (!netif_carrier_ok(netdev) &&
4311 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4312 /*
4313 * We've lost link, so the controller stops DMA,
4314 * but we've got queued Tx work that's never going
4315 * to get done, so reset controller to flush Tx.
4316 * (Do the reset outside of interrupt context).
4317 */
Bruce Allan90da0662011-01-06 07:02:53 +00004318 schedule_work(&adapter->reset_task);
4319 /* return immediately since reset is imminent */
4320 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004321 }
4322
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004323 /* Simple mode for Interrupt Throttle Rate (ITR) */
4324 if (adapter->itr_setting == 4) {
4325 /*
4326 * Symmetric Tx/Rx gets a reduced ITR=2000;
4327 * Total asymmetrical Tx or Rx gets ITR=8000;
4328 * everyone else is between 2000-8000.
4329 */
4330 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4331 u32 dif = (adapter->gotc > adapter->gorc ?
4332 adapter->gotc - adapter->gorc :
4333 adapter->gorc - adapter->gotc) / 10000;
4334 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4335
4336 ew32(ITR, 1000000000 / (itr * 256));
4337 }
4338
Bruce Allanad680762008-03-28 09:15:03 -07004339 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004340 if (adapter->msix_entries)
4341 ew32(ICS, adapter->rx_ring->ims_val);
4342 else
4343 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004344
4345 /* Force detection of hung controller every watchdog period */
4346 adapter->detect_tx_hung = 1;
4347
Bruce Allanaf667a22010-12-31 06:10:01 +00004348 /* flush partial descriptors to memory before detecting Tx hang */
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00004349 if (adapter->flags2 & FLAG2_DMA_BURST) {
4350 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4351 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4352 /*
4353 * no need to flush the writes because the timeout code does
4354 * an er32 first thing
4355 */
4356 }
4357
Bruce Allanad680762008-03-28 09:15:03 -07004358 /*
4359 * With 82571 controllers, LAA may be overwritten due to controller
4360 * reset from the other port. Set the appropriate LAA in RAR[0]
4361 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004362 if (e1000e_get_laa_state_82571(hw))
4363 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4364
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004365 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4366 e1000e_check_82574_phy_workaround(adapter);
4367
Auke Kokbc7f75f2007-09-17 12:30:59 -07004368 /* Reset the timer */
4369 if (!test_bit(__E1000_DOWN, &adapter->state))
4370 mod_timer(&adapter->watchdog_timer,
4371 round_jiffies(jiffies + 2 * HZ));
4372}
4373
4374#define E1000_TX_FLAGS_CSUM 0x00000001
4375#define E1000_TX_FLAGS_VLAN 0x00000002
4376#define E1000_TX_FLAGS_TSO 0x00000004
4377#define E1000_TX_FLAGS_IPV4 0x00000008
4378#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4379#define E1000_TX_FLAGS_VLAN_SHIFT 16
4380
4381static int e1000_tso(struct e1000_adapter *adapter,
4382 struct sk_buff *skb)
4383{
4384 struct e1000_ring *tx_ring = adapter->tx_ring;
4385 struct e1000_context_desc *context_desc;
4386 struct e1000_buffer *buffer_info;
4387 unsigned int i;
4388 u32 cmd_length = 0;
4389 u16 ipcse = 0, tucse, mss;
4390 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004391
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004392 if (!skb_is_gso(skb))
4393 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004394
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004395 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004396 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4397
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004398 if (err)
4399 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004400 }
4401
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004402 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4403 mss = skb_shinfo(skb)->gso_size;
4404 if (skb->protocol == htons(ETH_P_IP)) {
4405 struct iphdr *iph = ip_hdr(skb);
4406 iph->tot_len = 0;
4407 iph->check = 0;
4408 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4409 0, IPPROTO_TCP, 0);
4410 cmd_length = E1000_TXD_CMD_IP;
4411 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004412 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004413 ipv6_hdr(skb)->payload_len = 0;
4414 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4415 &ipv6_hdr(skb)->daddr,
4416 0, IPPROTO_TCP, 0);
4417 ipcse = 0;
4418 }
4419 ipcss = skb_network_offset(skb);
4420 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4421 tucss = skb_transport_offset(skb);
4422 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4423 tucse = 0;
4424
4425 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4426 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4427
4428 i = tx_ring->next_to_use;
4429 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4430 buffer_info = &tx_ring->buffer_info[i];
4431
4432 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4433 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4434 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4435 context_desc->upper_setup.tcp_fields.tucss = tucss;
4436 context_desc->upper_setup.tcp_fields.tucso = tucso;
4437 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4438 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4439 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4440 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4441
4442 buffer_info->time_stamp = jiffies;
4443 buffer_info->next_to_watch = i;
4444
4445 i++;
4446 if (i == tx_ring->count)
4447 i = 0;
4448 tx_ring->next_to_use = i;
4449
4450 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004451}
4452
4453static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4454{
4455 struct e1000_ring *tx_ring = adapter->tx_ring;
4456 struct e1000_context_desc *context_desc;
4457 struct e1000_buffer *buffer_info;
4458 unsigned int i;
4459 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004460 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004461 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004462
Dave Grahamaf807c82008-10-09 14:28:58 -07004463 if (skb->ip_summed != CHECKSUM_PARTIAL)
4464 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004465
Arthur Jones5f66f202009-03-19 01:13:08 +00004466 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4467 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4468 else
4469 protocol = skb->protocol;
4470
Arthur Jones3f518392009-03-20 15:56:35 -07004471 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004472 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004473 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4474 cmd_len |= E1000_TXD_CMD_TCP;
4475 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004476 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004477 /* XXX not handling all IPV6 headers */
4478 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4479 cmd_len |= E1000_TXD_CMD_TCP;
4480 break;
4481 default:
4482 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004483 e_warn("checksum_partial proto=%x!\n",
4484 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004485 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004486 }
4487
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004488 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004489
4490 i = tx_ring->next_to_use;
4491 buffer_info = &tx_ring->buffer_info[i];
4492 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4493
4494 context_desc->lower_setup.ip_config = 0;
4495 context_desc->upper_setup.tcp_fields.tucss = css;
4496 context_desc->upper_setup.tcp_fields.tucso =
4497 css + skb->csum_offset;
4498 context_desc->upper_setup.tcp_fields.tucse = 0;
4499 context_desc->tcp_seg_setup.data = 0;
4500 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4501
4502 buffer_info->time_stamp = jiffies;
4503 buffer_info->next_to_watch = i;
4504
4505 i++;
4506 if (i == tx_ring->count)
4507 i = 0;
4508 tx_ring->next_to_use = i;
4509
4510 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004511}
4512
4513#define E1000_MAX_PER_TXD 8192
4514#define E1000_MAX_TXD_PWR 12
4515
4516static int e1000_tx_map(struct e1000_adapter *adapter,
4517 struct sk_buff *skb, unsigned int first,
4518 unsigned int max_per_txd, unsigned int nr_frags,
4519 unsigned int mss)
4520{
4521 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004522 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004523 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004524 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004525 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004526 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004527
4528 i = tx_ring->next_to_use;
4529
4530 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004531 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004532 size = min(len, max_per_txd);
4533
Auke Kokbc7f75f2007-09-17 12:30:59 -07004534 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004535 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004536 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004537 buffer_info->dma = dma_map_single(&pdev->dev,
4538 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004539 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004540 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004541 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004542 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004543
4544 len -= size;
4545 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004546 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004547
4548 if (len) {
4549 i++;
4550 if (i == tx_ring->count)
4551 i = 0;
4552 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004553 }
4554
4555 for (f = 0; f < nr_frags; f++) {
4556 struct skb_frag_struct *frag;
4557
4558 frag = &skb_shinfo(skb)->frags[f];
4559 len = frag->size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004560 offset = frag->page_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004561
4562 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004563 i++;
4564 if (i == tx_ring->count)
4565 i = 0;
4566
Auke Kokbc7f75f2007-09-17 12:30:59 -07004567 buffer_info = &tx_ring->buffer_info[i];
4568 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004569
4570 buffer_info->length = size;
4571 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004572 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004573 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
Alexander Duyck03b13202009-12-02 16:45:31 +00004574 offset, size,
Nick Nunley0be3f552010-04-27 13:09:05 +00004575 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004576 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004577 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004578 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004579
4580 len -= size;
4581 offset += size;
4582 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004583 }
4584 }
4585
Bruce Allanaf667a22010-12-31 06:10:01 +00004586 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004587 /* multiply data chunks by size of headers */
4588 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4589
Auke Kokbc7f75f2007-09-17 12:30:59 -07004590 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004591 tx_ring->buffer_info[i].segs = segs;
4592 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004593 tx_ring->buffer_info[first].next_to_watch = i;
4594
4595 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004596
4597dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004598 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004599 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004600 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004601 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004602
4603 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004604 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004605 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004606 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004607 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004608 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004609 }
4610
4611 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004612}
4613
4614static void e1000_tx_queue(struct e1000_adapter *adapter,
4615 int tx_flags, int count)
4616{
4617 struct e1000_ring *tx_ring = adapter->tx_ring;
4618 struct e1000_tx_desc *tx_desc = NULL;
4619 struct e1000_buffer *buffer_info;
4620 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4621 unsigned int i;
4622
4623 if (tx_flags & E1000_TX_FLAGS_TSO) {
4624 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4625 E1000_TXD_CMD_TSE;
4626 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4627
4628 if (tx_flags & E1000_TX_FLAGS_IPV4)
4629 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4630 }
4631
4632 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4633 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4634 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4635 }
4636
4637 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4638 txd_lower |= E1000_TXD_CMD_VLE;
4639 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4640 }
4641
4642 i = tx_ring->next_to_use;
4643
Bruce Allan36b973d2010-11-24 07:42:43 +00004644 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004645 buffer_info = &tx_ring->buffer_info[i];
4646 tx_desc = E1000_TX_DESC(*tx_ring, i);
4647 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4648 tx_desc->lower.data =
4649 cpu_to_le32(txd_lower | buffer_info->length);
4650 tx_desc->upper.data = cpu_to_le32(txd_upper);
4651
4652 i++;
4653 if (i == tx_ring->count)
4654 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004655 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004656
4657 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4658
Bruce Allanad680762008-03-28 09:15:03 -07004659 /*
4660 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004661 * know there are new descriptors to fetch. (Only
4662 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004663 * such as IA-64).
4664 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004665 wmb();
4666
4667 tx_ring->next_to_use = i;
4668 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07004669 /*
4670 * we need this if more than one processor can write to our tail
4671 * at a time, it synchronizes IO on IA64/Altix systems
4672 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004673 mmiowb();
4674}
4675
4676#define MINIMUM_DHCP_PACKET_SIZE 282
4677static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4678 struct sk_buff *skb)
4679{
4680 struct e1000_hw *hw = &adapter->hw;
4681 u16 length, offset;
4682
4683 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004684 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4685 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004686 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4687 return 0;
4688 }
4689
4690 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4691 return 0;
4692
4693 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4694 return 0;
4695
4696 {
4697 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4698 struct udphdr *udp;
4699
4700 if (ip->protocol != IPPROTO_UDP)
4701 return 0;
4702
4703 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4704 if (ntohs(udp->dest) != 67)
4705 return 0;
4706
4707 offset = (u8 *)udp + 8 - skb->data;
4708 length = skb->len - offset;
4709 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4710 }
4711
4712 return 0;
4713}
4714
4715static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4716{
4717 struct e1000_adapter *adapter = netdev_priv(netdev);
4718
4719 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004720 /*
4721 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004722 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004723 * but since that doesn't exist yet, just open code it.
4724 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004725 smp_mb();
4726
Bruce Allanad680762008-03-28 09:15:03 -07004727 /*
4728 * We need to check again in a case another CPU has just
4729 * made room available.
4730 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004731 if (e1000_desc_unused(adapter->tx_ring) < size)
4732 return -EBUSY;
4733
4734 /* A reprieve! */
4735 netif_start_queue(netdev);
4736 ++adapter->restart_queue;
4737 return 0;
4738}
4739
4740static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4741{
4742 struct e1000_adapter *adapter = netdev_priv(netdev);
4743
4744 if (e1000_desc_unused(adapter->tx_ring) >= size)
4745 return 0;
4746 return __e1000_maybe_stop_tx(netdev, size);
4747}
4748
4749#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004750static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4751 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004752{
4753 struct e1000_adapter *adapter = netdev_priv(netdev);
4754 struct e1000_ring *tx_ring = adapter->tx_ring;
4755 unsigned int first;
4756 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4757 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4758 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004759 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004760 unsigned int nr_frags;
4761 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004762 int count = 0;
4763 int tso;
4764 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004765
4766 if (test_bit(__E1000_DOWN, &adapter->state)) {
4767 dev_kfree_skb_any(skb);
4768 return NETDEV_TX_OK;
4769 }
4770
4771 if (skb->len <= 0) {
4772 dev_kfree_skb_any(skb);
4773 return NETDEV_TX_OK;
4774 }
4775
4776 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004777 /*
4778 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004779 * make sure there is enough room in the FIFO before
4780 * initiating the DMA for each buffer. The calc is:
4781 * 4 = ceil(buffer len/mss). To make sure we don't
4782 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004783 * drops.
4784 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004785 if (mss) {
4786 u8 hdr_len;
4787 max_per_txd = min(mss << 2, max_per_txd);
4788 max_txd_pwr = fls(max_per_txd) - 1;
4789
Bruce Allanad680762008-03-28 09:15:03 -07004790 /*
4791 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4792 * points to just header, pull a few bytes of payload from
4793 * frags into skb->data
4794 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004795 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004796 /*
4797 * we do this workaround for ES2LAN, but it is un-necessary,
4798 * avoiding it could save a lot of cycles
4799 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004800 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004801 unsigned int pull_size;
4802
4803 pull_size = min((unsigned int)4, skb->data_len);
4804 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004805 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004806 dev_kfree_skb_any(skb);
4807 return NETDEV_TX_OK;
4808 }
Eric Dumazete743d312010-04-14 15:59:40 -07004809 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004810 }
4811 }
4812
4813 /* reserve a descriptor for the offload context */
4814 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4815 count++;
4816 count++;
4817
4818 count += TXD_USE_COUNT(len, max_txd_pwr);
4819
4820 nr_frags = skb_shinfo(skb)->nr_frags;
4821 for (f = 0; f < nr_frags; f++)
4822 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4823 max_txd_pwr);
4824
4825 if (adapter->hw.mac.tx_pkt_filtering)
4826 e1000_transfer_dhcp_info(adapter, skb);
4827
Bruce Allanad680762008-03-28 09:15:03 -07004828 /*
4829 * need: count + 2 desc gap to keep tail from touching
4830 * head, otherwise try next time
4831 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004832 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004833 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004834
Jesse Grosseab6d182010-10-20 13:56:03 +00004835 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004836 tx_flags |= E1000_TX_FLAGS_VLAN;
4837 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4838 }
4839
4840 first = tx_ring->next_to_use;
4841
4842 tso = e1000_tso(adapter, skb);
4843 if (tso < 0) {
4844 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004845 return NETDEV_TX_OK;
4846 }
4847
4848 if (tso)
4849 tx_flags |= E1000_TX_FLAGS_TSO;
4850 else if (e1000_tx_csum(adapter, skb))
4851 tx_flags |= E1000_TX_FLAGS_CSUM;
4852
Bruce Allanad680762008-03-28 09:15:03 -07004853 /*
4854 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004855 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004856 * no longer assume, we must.
4857 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004858 if (skb->protocol == htons(ETH_P_IP))
4859 tx_flags |= E1000_TX_FLAGS_IPV4;
4860
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004861 /* if count is 0 then mapping error has occured */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004862 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004863 if (count) {
4864 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004865 /* Make sure there is space in the ring for the next send. */
4866 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4867
4868 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004869 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004870 tx_ring->buffer_info[first].time_stamp = 0;
4871 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004872 }
4873
Auke Kokbc7f75f2007-09-17 12:30:59 -07004874 return NETDEV_TX_OK;
4875}
4876
4877/**
4878 * e1000_tx_timeout - Respond to a Tx Hang
4879 * @netdev: network interface device structure
4880 **/
4881static void e1000_tx_timeout(struct net_device *netdev)
4882{
4883 struct e1000_adapter *adapter = netdev_priv(netdev);
4884
4885 /* Do the reset outside of interrupt context */
4886 adapter->tx_timeout_count++;
4887 schedule_work(&adapter->reset_task);
4888}
4889
4890static void e1000_reset_task(struct work_struct *work)
4891{
4892 struct e1000_adapter *adapter;
4893 adapter = container_of(work, struct e1000_adapter, reset_task);
4894
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00004895 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4896 (adapter->flags & FLAG_RX_RESTART_NOW))) {
4897 e1000e_dump(adapter);
4898 e_err("Reset adapter\n");
4899 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004900 e1000e_reinit_locked(adapter);
4901}
4902
4903/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004904 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07004905 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004906 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07004907 *
4908 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004909 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004910struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
4911 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004912{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004913 struct e1000_adapter *adapter = netdev_priv(netdev);
4914
4915 memset(stats, 0, sizeof(struct rtnl_link_stats64));
4916 spin_lock(&adapter->stats64_lock);
4917 e1000e_update_stats(adapter);
4918 /* Fill out the OS statistics structure */
4919 stats->rx_bytes = adapter->stats.gorc;
4920 stats->rx_packets = adapter->stats.gprc;
4921 stats->tx_bytes = adapter->stats.gotc;
4922 stats->tx_packets = adapter->stats.gptc;
4923 stats->multicast = adapter->stats.mprc;
4924 stats->collisions = adapter->stats.colc;
4925
4926 /* Rx Errors */
4927
4928 /*
4929 * RLEC on some newer hardware can be incorrect so build
4930 * our own version based on RUC and ROC
4931 */
4932 stats->rx_errors = adapter->stats.rxerrc +
4933 adapter->stats.crcerrs + adapter->stats.algnerrc +
4934 adapter->stats.ruc + adapter->stats.roc +
4935 adapter->stats.cexterr;
4936 stats->rx_length_errors = adapter->stats.ruc +
4937 adapter->stats.roc;
4938 stats->rx_crc_errors = adapter->stats.crcerrs;
4939 stats->rx_frame_errors = adapter->stats.algnerrc;
4940 stats->rx_missed_errors = adapter->stats.mpc;
4941
4942 /* Tx Errors */
4943 stats->tx_errors = adapter->stats.ecol +
4944 adapter->stats.latecol;
4945 stats->tx_aborted_errors = adapter->stats.ecol;
4946 stats->tx_window_errors = adapter->stats.latecol;
4947 stats->tx_carrier_errors = adapter->stats.tncrs;
4948
4949 /* Tx Dropped needs to be maintained elsewhere */
4950
4951 spin_unlock(&adapter->stats64_lock);
4952 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004953}
4954
4955/**
4956 * e1000_change_mtu - Change the Maximum Transfer Unit
4957 * @netdev: network interface device structure
4958 * @new_mtu: new value for maximum frame size
4959 *
4960 * Returns 0 on success, negative on failure
4961 **/
4962static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4963{
4964 struct e1000_adapter *adapter = netdev_priv(netdev);
4965 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4966
Bruce Allan2adc55c2009-06-02 11:28:58 +00004967 /* Jumbo frame support */
4968 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
4969 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
4970 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004971 return -EINVAL;
4972 }
4973
Bruce Allan2adc55c2009-06-02 11:28:58 +00004974 /* Supported frame sizes */
4975 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
4976 (max_frame > adapter->max_hw_frame_size)) {
4977 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004978 return -EINVAL;
4979 }
4980
Bruce Allana1ce6472010-09-22 17:16:40 +00004981 /* Jumbo frame workaround on 82579 requires CRC be stripped */
4982 if ((adapter->hw.mac.type == e1000_pch2lan) &&
4983 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
4984 (new_mtu > ETH_DATA_LEN)) {
4985 e_err("Jumbo Frames not supported on 82579 when CRC "
4986 "stripping is disabled.\n");
4987 return -EINVAL;
4988 }
4989
Bruce Allan6f461f62010-04-27 03:33:04 +00004990 /* 82573 Errata 17 */
4991 if (((adapter->hw.mac.type == e1000_82573) ||
4992 (adapter->hw.mac.type == e1000_82574)) &&
4993 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
4994 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
4995 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
4996 }
4997
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4999 msleep(1);
Bruce Allan610c9922009-11-19 12:35:45 +00005000 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005001 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005002 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5003 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005004 if (netif_running(netdev))
5005 e1000e_down(adapter);
5006
Bruce Allanad680762008-03-28 09:15:03 -07005007 /*
5008 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005009 * means we reserve 2 more, this pushes us to allocate from the next
5010 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005011 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005012 * However with the new *_jumbo_rx* routines, jumbo receives will use
5013 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005014 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005015
Jesse Brandeburg99261462010-01-22 22:56:16 +00005016 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005017 adapter->rx_buffer_len = 2048;
5018 else
5019 adapter->rx_buffer_len = 4096;
5020
5021 /* adjust allocation if LPE protects us, and we aren't using SBP */
5022 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5023 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5024 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005025 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005026
Auke Kokbc7f75f2007-09-17 12:30:59 -07005027 if (netif_running(netdev))
5028 e1000e_up(adapter);
5029 else
5030 e1000e_reset(adapter);
5031
5032 clear_bit(__E1000_RESETTING, &adapter->state);
5033
5034 return 0;
5035}
5036
5037static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5038 int cmd)
5039{
5040 struct e1000_adapter *adapter = netdev_priv(netdev);
5041 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005042
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005043 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005044 return -EOPNOTSUPP;
5045
5046 switch (cmd) {
5047 case SIOCGMIIPHY:
5048 data->phy_id = adapter->hw.phy.addr;
5049 break;
5050 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005051 e1000_phy_read_status(adapter);
5052
Bruce Allan7c257692008-04-23 11:09:00 -07005053 switch (data->reg_num & 0x1F) {
5054 case MII_BMCR:
5055 data->val_out = adapter->phy_regs.bmcr;
5056 break;
5057 case MII_BMSR:
5058 data->val_out = adapter->phy_regs.bmsr;
5059 break;
5060 case MII_PHYSID1:
5061 data->val_out = (adapter->hw.phy.id >> 16);
5062 break;
5063 case MII_PHYSID2:
5064 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5065 break;
5066 case MII_ADVERTISE:
5067 data->val_out = adapter->phy_regs.advertise;
5068 break;
5069 case MII_LPA:
5070 data->val_out = adapter->phy_regs.lpa;
5071 break;
5072 case MII_EXPANSION:
5073 data->val_out = adapter->phy_regs.expansion;
5074 break;
5075 case MII_CTRL1000:
5076 data->val_out = adapter->phy_regs.ctrl1000;
5077 break;
5078 case MII_STAT1000:
5079 data->val_out = adapter->phy_regs.stat1000;
5080 break;
5081 case MII_ESTATUS:
5082 data->val_out = adapter->phy_regs.estatus;
5083 break;
5084 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005085 return -EIO;
5086 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005087 break;
5088 case SIOCSMIIREG:
5089 default:
5090 return -EOPNOTSUPP;
5091 }
5092 return 0;
5093}
5094
5095static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5096{
5097 switch (cmd) {
5098 case SIOCGMIIPHY:
5099 case SIOCGMIIREG:
5100 case SIOCSMIIREG:
5101 return e1000_mii_ioctl(netdev, ifr, cmd);
5102 default:
5103 return -EOPNOTSUPP;
5104 }
5105}
5106
Bruce Allana4f58f52009-06-02 11:29:18 +00005107static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5108{
5109 struct e1000_hw *hw = &adapter->hw;
5110 u32 i, mac_reg;
5111 u16 phy_reg;
5112 int retval = 0;
5113
5114 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005115 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005116
5117 /* copy MAC MTA to PHY MTA */
5118 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5119 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5120 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
5121 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
5122 }
5123
5124 /* configure PHY Rx Control register */
5125 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
5126 mac_reg = er32(RCTL);
5127 if (mac_reg & E1000_RCTL_UPE)
5128 phy_reg |= BM_RCTL_UPE;
5129 if (mac_reg & E1000_RCTL_MPE)
5130 phy_reg |= BM_RCTL_MPE;
5131 phy_reg &= ~(BM_RCTL_MO_MASK);
5132 if (mac_reg & E1000_RCTL_MO_3)
5133 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5134 << BM_RCTL_MO_SHIFT);
5135 if (mac_reg & E1000_RCTL_BAM)
5136 phy_reg |= BM_RCTL_BAM;
5137 if (mac_reg & E1000_RCTL_PMCF)
5138 phy_reg |= BM_RCTL_PMCF;
5139 mac_reg = er32(CTRL);
5140 if (mac_reg & E1000_CTRL_RFCE)
5141 phy_reg |= BM_RCTL_RFCE;
5142 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
5143
5144 /* enable PHY wakeup in MAC register */
5145 ew32(WUFC, wufc);
5146 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5147
5148 /* configure and enable PHY wakeup in PHY registers */
5149 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
5150 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5151
5152 /* activate PHY wakeup */
Bruce Allan94d81862009-11-20 23:25:26 +00005153 retval = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005154 if (retval) {
5155 e_err("Could not acquire PHY\n");
5156 return retval;
5157 }
5158 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
5159 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
5160 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
5161 if (retval) {
5162 e_err("Could not read PHY page 769\n");
5163 goto out;
5164 }
5165 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5166 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
5167 if (retval)
5168 e_err("Could not set PHY Host Wakeup bit\n");
5169out:
Bruce Allan94d81862009-11-20 23:25:26 +00005170 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005171
5172 return retval;
5173}
5174
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005175static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5176 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005177{
5178 struct net_device *netdev = pci_get_drvdata(pdev);
5179 struct e1000_adapter *adapter = netdev_priv(netdev);
5180 struct e1000_hw *hw = &adapter->hw;
5181 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005182 /* Runtime suspend should only enable wakeup for link changes */
5183 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005184 int retval = 0;
5185
5186 netif_device_detach(netdev);
5187
5188 if (netif_running(netdev)) {
5189 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5190 e1000e_down(adapter);
5191 e1000_free_irq(adapter);
5192 }
Bruce Allan4662e822008-08-26 18:37:06 -07005193 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005194
5195 retval = pci_save_state(pdev);
5196 if (retval)
5197 return retval;
5198
5199 status = er32(STATUS);
5200 if (status & E1000_STATUS_LU)
5201 wufc &= ~E1000_WUFC_LNKC;
5202
5203 if (wufc) {
5204 e1000_setup_rctl(adapter);
5205 e1000_set_multi(netdev);
5206
5207 /* turn on all-multi mode if wake on multicast is enabled */
5208 if (wufc & E1000_WUFC_MC) {
5209 rctl = er32(RCTL);
5210 rctl |= E1000_RCTL_MPE;
5211 ew32(RCTL, rctl);
5212 }
5213
5214 ctrl = er32(CTRL);
5215 /* advertise wake from D3Cold */
5216 #define E1000_CTRL_ADVD3WUC 0x00100000
5217 /* phy power management enable */
5218 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005219 ctrl |= E1000_CTRL_ADVD3WUC;
5220 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5221 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005222 ew32(CTRL, ctrl);
5223
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005224 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5225 adapter->hw.phy.media_type ==
5226 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005227 /* keep the laser running in D3 */
5228 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005229 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005230 ew32(CTRL_EXT, ctrl_ext);
5231 }
5232
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005233 if (adapter->flags & FLAG_IS_ICH)
5234 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
5235
Auke Kokbc7f75f2007-09-17 12:30:59 -07005236 /* Allow time for pending master requests to run */
5237 e1000e_disable_pcie_master(&adapter->hw);
5238
Bruce Allan82776a42009-08-14 14:35:33 +00005239 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005240 /* enable wakeup by the PHY */
5241 retval = e1000_init_phy_wakeup(adapter, wufc);
5242 if (retval)
5243 return retval;
5244 } else {
5245 /* enable wakeup by the MAC */
5246 ew32(WUFC, wufc);
5247 ew32(WUC, E1000_WUC_PME_EN);
5248 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005249 } else {
5250 ew32(WUC, 0);
5251 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005252 }
5253
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005254 *enable_wake = !!wufc;
5255
Auke Kokbc7f75f2007-09-17 12:30:59 -07005256 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005257 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5258 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005259 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005260
5261 if (adapter->hw.phy.type == e1000_phy_igp_3)
5262 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5263
Bruce Allanad680762008-03-28 09:15:03 -07005264 /*
5265 * Release control of h/w to f/w. If f/w is AMT enabled, this
5266 * would have already happened in close and is redundant.
5267 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005268 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005269
5270 pci_disable_device(pdev);
5271
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005272 return 0;
5273}
5274
5275static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5276{
5277 if (sleep && wake) {
5278 pci_prepare_to_sleep(pdev);
5279 return;
5280 }
5281
5282 pci_wake_from_d3(pdev, wake);
5283 pci_set_power_state(pdev, PCI_D3hot);
5284}
5285
5286static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5287 bool wake)
5288{
5289 struct net_device *netdev = pci_get_drvdata(pdev);
5290 struct e1000_adapter *adapter = netdev_priv(netdev);
5291
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005292 /*
5293 * The pci-e switch on some quad port adapters will report a
5294 * correctable error when the MAC transitions from D0 to D3. To
5295 * prevent this we need to mask off the correctable errors on the
5296 * downstream port of the pci-e switch.
5297 */
5298 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5299 struct pci_dev *us_dev = pdev->bus->self;
5300 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
5301 u16 devctl;
5302
5303 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5304 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5305 (devctl & ~PCI_EXP_DEVCTL_CERE));
5306
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005307 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005308
5309 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5310 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005311 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005312 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005313}
5314
Bruce Allan6f461f62010-04-27 03:33:04 +00005315#ifdef CONFIG_PCIEASPM
5316static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5317{
5318 pci_disable_link_state(pdev, state);
5319}
5320#else
5321static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005322{
5323 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005324 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005325
5326 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005327 * Both device and parent should have the same ASPM setting.
5328 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005329 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005330 pos = pci_pcie_cap(pdev);
5331 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5332 reg16 &= ~state;
5333 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5334
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005335 if (!pdev->bus->self)
5336 return;
5337
Bruce Allan6f461f62010-04-27 03:33:04 +00005338 pos = pci_pcie_cap(pdev->bus->self);
5339 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5340 reg16 &= ~state;
5341 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5342}
5343#endif
5344void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5345{
5346 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5347 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5348 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5349
5350 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005351}
5352
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005353#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005354static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005355{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005356 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005357}
5358
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005359static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005360{
5361 struct net_device *netdev = pci_get_drvdata(pdev);
5362 struct e1000_adapter *adapter = netdev_priv(netdev);
5363 struct e1000_hw *hw = &adapter->hw;
5364 u32 err;
5365
5366 pci_set_power_state(pdev, PCI_D0);
5367 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005368 pci_save_state(pdev);
Bruce Allan6f461f62010-04-27 03:33:04 +00005369 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5370 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005371
Bruce Allan4662e822008-08-26 18:37:06 -07005372 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005373 if (netif_running(netdev)) {
5374 err = e1000_request_irq(adapter);
5375 if (err)
5376 return err;
5377 }
5378
5379 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005380
5381 /* report the system wakeup cause from S3/S4 */
5382 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5383 u16 phy_data;
5384
5385 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5386 if (phy_data) {
5387 e_info("PHY Wakeup cause - %s\n",
5388 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5389 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5390 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5391 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5392 phy_data & E1000_WUS_LNKC ? "Link Status "
5393 " Change" : "other");
5394 }
5395 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5396 } else {
5397 u32 wus = er32(WUS);
5398 if (wus) {
5399 e_info("MAC Wakeup cause - %s\n",
5400 wus & E1000_WUS_EX ? "Unicast Packet" :
5401 wus & E1000_WUS_MC ? "Multicast Packet" :
5402 wus & E1000_WUS_BC ? "Broadcast Packet" :
5403 wus & E1000_WUS_MAG ? "Magic Packet" :
5404 wus & E1000_WUS_LNKC ? "Link Status Change" :
5405 "other");
5406 }
5407 ew32(WUS, ~0);
5408 }
5409
Auke Kokbc7f75f2007-09-17 12:30:59 -07005410 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005411
Bruce Allancd791612010-05-10 14:59:51 +00005412 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005413
5414 if (netif_running(netdev))
5415 e1000e_up(adapter);
5416
5417 netif_device_attach(netdev);
5418
Bruce Allanad680762008-03-28 09:15:03 -07005419 /*
5420 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005421 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005422 * under the control of the driver.
5423 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005424 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005425 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005426
5427 return 0;
5428}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005429
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005430#ifdef CONFIG_PM_SLEEP
5431static int e1000_suspend(struct device *dev)
5432{
5433 struct pci_dev *pdev = to_pci_dev(dev);
5434 int retval;
5435 bool wake;
5436
5437 retval = __e1000_shutdown(pdev, &wake, false);
5438 if (!retval)
5439 e1000_complete_shutdown(pdev, true, wake);
5440
5441 return retval;
5442}
5443
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005444static int e1000_resume(struct device *dev)
5445{
5446 struct pci_dev *pdev = to_pci_dev(dev);
5447 struct net_device *netdev = pci_get_drvdata(pdev);
5448 struct e1000_adapter *adapter = netdev_priv(netdev);
5449
5450 if (e1000e_pm_ready(adapter))
5451 adapter->idle_check = true;
5452
5453 return __e1000_resume(pdev);
5454}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005455#endif /* CONFIG_PM_SLEEP */
5456
5457#ifdef CONFIG_PM_RUNTIME
5458static int e1000_runtime_suspend(struct device *dev)
5459{
5460 struct pci_dev *pdev = to_pci_dev(dev);
5461 struct net_device *netdev = pci_get_drvdata(pdev);
5462 struct e1000_adapter *adapter = netdev_priv(netdev);
5463
5464 if (e1000e_pm_ready(adapter)) {
5465 bool wake;
5466
5467 __e1000_shutdown(pdev, &wake, true);
5468 }
5469
5470 return 0;
5471}
5472
5473static int e1000_idle(struct device *dev)
5474{
5475 struct pci_dev *pdev = to_pci_dev(dev);
5476 struct net_device *netdev = pci_get_drvdata(pdev);
5477 struct e1000_adapter *adapter = netdev_priv(netdev);
5478
5479 if (!e1000e_pm_ready(adapter))
5480 return 0;
5481
5482 if (adapter->idle_check) {
5483 adapter->idle_check = false;
5484 if (!e1000e_has_link(adapter))
5485 pm_schedule_suspend(dev, MSEC_PER_SEC);
5486 }
5487
5488 return -EBUSY;
5489}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005490
5491static int e1000_runtime_resume(struct device *dev)
5492{
5493 struct pci_dev *pdev = to_pci_dev(dev);
5494 struct net_device *netdev = pci_get_drvdata(pdev);
5495 struct e1000_adapter *adapter = netdev_priv(netdev);
5496
5497 if (!e1000e_pm_ready(adapter))
5498 return 0;
5499
5500 adapter->idle_check = !dev->power.runtime_auto;
5501 return __e1000_resume(pdev);
5502}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005503#endif /* CONFIG_PM_RUNTIME */
5504#endif /* CONFIG_PM_OPS */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005505
5506static void e1000_shutdown(struct pci_dev *pdev)
5507{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005508 bool wake = false;
5509
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005510 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005511
5512 if (system_state == SYSTEM_POWER_OFF)
5513 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005514}
5515
5516#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005517
5518static irqreturn_t e1000_intr_msix(int irq, void *data)
5519{
5520 struct net_device *netdev = data;
5521 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005522
5523 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005524 int vector, msix_irq;
5525
Dongdong Deng147b2c82010-11-16 19:50:15 -08005526 vector = 0;
5527 msix_irq = adapter->msix_entries[vector].vector;
5528 disable_irq(msix_irq);
5529 e1000_intr_msix_rx(msix_irq, netdev);
5530 enable_irq(msix_irq);
5531
5532 vector++;
5533 msix_irq = adapter->msix_entries[vector].vector;
5534 disable_irq(msix_irq);
5535 e1000_intr_msix_tx(msix_irq, netdev);
5536 enable_irq(msix_irq);
5537
5538 vector++;
5539 msix_irq = adapter->msix_entries[vector].vector;
5540 disable_irq(msix_irq);
5541 e1000_msix_other(msix_irq, netdev);
5542 enable_irq(msix_irq);
5543 }
5544
5545 return IRQ_HANDLED;
5546}
5547
Auke Kokbc7f75f2007-09-17 12:30:59 -07005548/*
5549 * Polling 'interrupt' - used by things like netconsole to send skbs
5550 * without having to re-enable interrupts. It's not called while
5551 * the interrupt routine is executing.
5552 */
5553static void e1000_netpoll(struct net_device *netdev)
5554{
5555 struct e1000_adapter *adapter = netdev_priv(netdev);
5556
Dongdong Deng147b2c82010-11-16 19:50:15 -08005557 switch (adapter->int_mode) {
5558 case E1000E_INT_MODE_MSIX:
5559 e1000_intr_msix(adapter->pdev->irq, netdev);
5560 break;
5561 case E1000E_INT_MODE_MSI:
5562 disable_irq(adapter->pdev->irq);
5563 e1000_intr_msi(adapter->pdev->irq, netdev);
5564 enable_irq(adapter->pdev->irq);
5565 break;
5566 default: /* E1000E_INT_MODE_LEGACY */
5567 disable_irq(adapter->pdev->irq);
5568 e1000_intr(adapter->pdev->irq, netdev);
5569 enable_irq(adapter->pdev->irq);
5570 break;
5571 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005572}
5573#endif
5574
5575/**
5576 * e1000_io_error_detected - called when PCI error is detected
5577 * @pdev: Pointer to PCI device
5578 * @state: The current pci connection state
5579 *
5580 * This function is called after a PCI bus error affecting
5581 * this device has been detected.
5582 */
5583static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5584 pci_channel_state_t state)
5585{
5586 struct net_device *netdev = pci_get_drvdata(pdev);
5587 struct e1000_adapter *adapter = netdev_priv(netdev);
5588
5589 netif_device_detach(netdev);
5590
Mike Masonc93b5a72009-06-30 12:45:53 +00005591 if (state == pci_channel_io_perm_failure)
5592 return PCI_ERS_RESULT_DISCONNECT;
5593
Auke Kokbc7f75f2007-09-17 12:30:59 -07005594 if (netif_running(netdev))
5595 e1000e_down(adapter);
5596 pci_disable_device(pdev);
5597
5598 /* Request a slot slot reset. */
5599 return PCI_ERS_RESULT_NEED_RESET;
5600}
5601
5602/**
5603 * e1000_io_slot_reset - called after the pci bus has been reset.
5604 * @pdev: Pointer to PCI device
5605 *
5606 * Restart the card from scratch, as if from a cold-boot. Implementation
5607 * resembles the first-half of the e1000_resume routine.
5608 */
5609static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5610{
5611 struct net_device *netdev = pci_get_drvdata(pdev);
5612 struct e1000_adapter *adapter = netdev_priv(netdev);
5613 struct e1000_hw *hw = &adapter->hw;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005614 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005615 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005616
Bruce Allan6f461f62010-04-27 03:33:04 +00005617 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5618 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Bruce Allanf0f422e2008-08-04 17:21:53 -07005619 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005620 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005621 dev_err(&pdev->dev,
5622 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005623 result = PCI_ERS_RESULT_DISCONNECT;
5624 } else {
5625 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005626 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005627 pci_restore_state(pdev);
5628
5629 pci_enable_wake(pdev, PCI_D3hot, 0);
5630 pci_enable_wake(pdev, PCI_D3cold, 0);
5631
5632 e1000e_reset(adapter);
5633 ew32(WUS, ~0);
5634 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005635 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005636
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005637 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005638
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005639 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005640}
5641
5642/**
5643 * e1000_io_resume - called when traffic can start flowing again.
5644 * @pdev: Pointer to PCI device
5645 *
5646 * This callback is called when the error recovery driver tells us that
5647 * its OK to resume normal operation. Implementation resembles the
5648 * second-half of the e1000_resume routine.
5649 */
5650static void e1000_io_resume(struct pci_dev *pdev)
5651{
5652 struct net_device *netdev = pci_get_drvdata(pdev);
5653 struct e1000_adapter *adapter = netdev_priv(netdev);
5654
Bruce Allancd791612010-05-10 14:59:51 +00005655 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005656
5657 if (netif_running(netdev)) {
5658 if (e1000e_up(adapter)) {
5659 dev_err(&pdev->dev,
5660 "can't bring device back up after reset\n");
5661 return;
5662 }
5663 }
5664
5665 netif_device_attach(netdev);
5666
Bruce Allanad680762008-03-28 09:15:03 -07005667 /*
5668 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005669 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005670 * under the control of the driver.
5671 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005672 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005673 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005674
5675}
5676
5677static void e1000_print_device_info(struct e1000_adapter *adapter)
5678{
5679 struct e1000_hw *hw = &adapter->hw;
5680 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005681 u32 ret_val;
5682 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005683
5684 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005685 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005686 /* bus width */
5687 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5688 "Width x1"),
5689 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005690 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005691 e_info("Intel(R) PRO/%s Network Connection\n",
5692 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005693 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5694 E1000_PBANUM_LENGTH);
5695 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005696 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005697 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5698 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005699}
5700
Auke Kok10aa4c02008-08-04 17:21:20 -07005701static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5702{
5703 struct e1000_hw *hw = &adapter->hw;
5704 int ret_val;
5705 u16 buf = 0;
5706
5707 if (hw->mac.type != e1000_82573)
5708 return;
5709
5710 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005711 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005712 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005713 dev_warn(&adapter->pdev->dev,
5714 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005715 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005716}
5717
Stephen Hemminger651c2462008-11-19 21:57:48 -08005718static const struct net_device_ops e1000e_netdev_ops = {
5719 .ndo_open = e1000_open,
5720 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005721 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005722 .ndo_get_stats64 = e1000e_get_stats64,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005723 .ndo_set_multicast_list = e1000_set_multi,
5724 .ndo_set_mac_address = e1000_set_mac,
5725 .ndo_change_mtu = e1000_change_mtu,
5726 .ndo_do_ioctl = e1000_ioctl,
5727 .ndo_tx_timeout = e1000_tx_timeout,
5728 .ndo_validate_addr = eth_validate_addr,
5729
5730 .ndo_vlan_rx_register = e1000_vlan_rx_register,
5731 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5732 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5733#ifdef CONFIG_NET_POLL_CONTROLLER
5734 .ndo_poll_controller = e1000_netpoll,
5735#endif
5736};
5737
Auke Kokbc7f75f2007-09-17 12:30:59 -07005738/**
5739 * e1000_probe - Device Initialization Routine
5740 * @pdev: PCI device information struct
5741 * @ent: entry in e1000_pci_tbl
5742 *
5743 * Returns 0 on success, negative on failure
5744 *
5745 * e1000_probe initializes an adapter identified by a pci_dev structure.
5746 * The OS initialization, configuring of the adapter private structure,
5747 * and a hardware reset occur.
5748 **/
5749static int __devinit e1000_probe(struct pci_dev *pdev,
5750 const struct pci_device_id *ent)
5751{
5752 struct net_device *netdev;
5753 struct e1000_adapter *adapter;
5754 struct e1000_hw *hw;
5755 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005756 resource_size_t mmio_start, mmio_len;
5757 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005758
5759 static int cards_found;
5760 int i, err, pci_using_dac;
5761 u16 eeprom_data = 0;
5762 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5763
Bruce Allan6f461f62010-04-27 03:33:04 +00005764 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
5765 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005766
Bruce Allanf0f422e2008-08-04 17:21:53 -07005767 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005768 if (err)
5769 return err;
5770
5771 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005772 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005773 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005774 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005775 if (!err)
5776 pci_using_dac = 1;
5777 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005778 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005779 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005780 err = dma_set_coherent_mask(&pdev->dev,
5781 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005782 if (err) {
5783 dev_err(&pdev->dev, "No usable DMA "
5784 "configuration, aborting\n");
5785 goto err_dma;
5786 }
5787 }
5788 }
5789
Arjan van de Vene8de1482008-10-22 19:55:31 -07005790 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005791 pci_select_bars(pdev, IORESOURCE_MEM),
5792 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005793 if (err)
5794 goto err_pci_reg;
5795
Xiaotian Feng68eac462009-08-14 14:35:52 +00005796 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005797 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005798
Auke Kokbc7f75f2007-09-17 12:30:59 -07005799 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005800 /* PCI config space info */
5801 err = pci_save_state(pdev);
5802 if (err)
5803 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005804
5805 err = -ENOMEM;
5806 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5807 if (!netdev)
5808 goto err_alloc_etherdev;
5809
Auke Kokbc7f75f2007-09-17 12:30:59 -07005810 SET_NETDEV_DEV(netdev, &pdev->dev);
5811
Tom Herbertf85e4df2010-05-05 14:03:32 +00005812 netdev->irq = pdev->irq;
5813
Auke Kokbc7f75f2007-09-17 12:30:59 -07005814 pci_set_drvdata(pdev, netdev);
5815 adapter = netdev_priv(netdev);
5816 hw = &adapter->hw;
5817 adapter->netdev = netdev;
5818 adapter->pdev = pdev;
5819 adapter->ei = ei;
5820 adapter->pba = ei->pba;
5821 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005822 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005823 adapter->hw.adapter = adapter;
5824 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005825 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005826 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5827
5828 mmio_start = pci_resource_start(pdev, 0);
5829 mmio_len = pci_resource_len(pdev, 0);
5830
5831 err = -EIO;
5832 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5833 if (!adapter->hw.hw_addr)
5834 goto err_ioremap;
5835
5836 if ((adapter->flags & FLAG_HAS_FLASH) &&
5837 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5838 flash_start = pci_resource_start(pdev, 1);
5839 flash_len = pci_resource_len(pdev, 1);
5840 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5841 if (!adapter->hw.flash_address)
5842 goto err_flashmap;
5843 }
5844
5845 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005846 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005847 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005848 netdev->watchdog_timeo = 5 * HZ;
5849 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005850 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5851
5852 netdev->mem_start = mmio_start;
5853 netdev->mem_end = mmio_start + mmio_len;
5854
5855 adapter->bd_number = cards_found++;
5856
Bruce Allan4662e822008-08-26 18:37:06 -07005857 e1000e_check_options(adapter);
5858
Auke Kokbc7f75f2007-09-17 12:30:59 -07005859 /* setup adapter struct */
5860 err = e1000_sw_init(adapter);
5861 if (err)
5862 goto err_sw_init;
5863
Auke Kokbc7f75f2007-09-17 12:30:59 -07005864 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5865 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5866 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5867
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005868 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005869 if (err)
5870 goto err_hw_init;
5871
Bruce Allan4a770352008-10-01 17:18:35 -07005872 if ((adapter->flags & FLAG_IS_ICH) &&
5873 (adapter->flags & FLAG_READ_ONLY_NVM))
5874 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5875
Auke Kokbc7f75f2007-09-17 12:30:59 -07005876 hw->mac.ops.get_bus_info(&adapter->hw);
5877
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005878 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005879
5880 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005881 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005882 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5883 adapter->hw.phy.disable_polarity_correction = 0;
5884 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5885 }
5886
5887 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005888 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005889
5890 netdev->features = NETIF_F_SG |
5891 NETIF_F_HW_CSUM |
5892 NETIF_F_HW_VLAN_TX |
5893 NETIF_F_HW_VLAN_RX;
5894
5895 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5896 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5897
5898 netdev->features |= NETIF_F_TSO;
5899 netdev->features |= NETIF_F_TSO6;
5900
Jeff Kirshera5136e22008-06-05 04:07:28 -07005901 netdev->vlan_features |= NETIF_F_TSO;
5902 netdev->vlan_features |= NETIF_F_TSO6;
5903 netdev->vlan_features |= NETIF_F_HW_CSUM;
5904 netdev->vlan_features |= NETIF_F_SG;
5905
Yi Zou7b872a52010-09-22 17:57:58 +00005906 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005907 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00005908 netdev->vlan_features |= NETIF_F_HIGHDMA;
5909 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005910
Auke Kokbc7f75f2007-09-17 12:30:59 -07005911 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5912 adapter->flags |= FLAG_MNG_PT_ENABLED;
5913
Bruce Allanad680762008-03-28 09:15:03 -07005914 /*
5915 * before reading the NVM, reset the controller to
5916 * put the device in a known good starting state
5917 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005918 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5919
5920 /*
5921 * systems with ASPM and others may see the checksum fail on the first
5922 * attempt. Let's give it a few tries
5923 */
5924 for (i = 0;; i++) {
5925 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5926 break;
5927 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005928 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005929 err = -EIO;
5930 goto err_eeprom;
5931 }
5932 }
5933
Auke Kok10aa4c02008-08-04 17:21:20 -07005934 e1000_eeprom_checks(adapter);
5935
Bruce Allan608f8a02010-01-13 02:04:58 +00005936 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005937 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005938 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005939
5940 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5941 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5942
5943 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07005944 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005945 err = -EIO;
5946 goto err_eeprom;
5947 }
5948
5949 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005950 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005951 adapter->watchdog_timer.data = (unsigned long) adapter;
5952
5953 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005954 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955 adapter->phy_info_timer.data = (unsigned long) adapter;
5956
5957 INIT_WORK(&adapter->reset_task, e1000_reset_task);
5958 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07005959 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
5960 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00005961 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Holger Eitzenberger9633e632010-11-17 15:43:52 +00005962 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005963
Auke Kokbc7f75f2007-09-17 12:30:59 -07005964 /* Initialize link parameters. User can change them with ethtool */
5965 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07005966 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08005967 adapter->hw.fc.requested_mode = e1000_fc_default;
5968 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005969 adapter->hw.phy.autoneg_advertised = 0x2f;
5970
5971 /* ring size defaults */
5972 adapter->rx_ring->count = 256;
5973 adapter->tx_ring->count = 256;
5974
5975 /*
5976 * Initial Wake on LAN setting - If APM wake is enabled in
5977 * the EEPROM, enable the ACPI Magic Packet filter
5978 */
5979 if (adapter->flags & FLAG_APME_IN_WUC) {
5980 /* APME bit in EEPROM is mapped to WUC.APME */
5981 eeprom_data = er32(WUC);
5982 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allana4f58f52009-06-02 11:29:18 +00005983 if (eeprom_data & E1000_WUC_PHY_WAKE)
5984 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005985 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
5986 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
5987 (adapter->hw.bus.func == 1))
5988 e1000_read_nvm(&adapter->hw,
5989 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
5990 else
5991 e1000_read_nvm(&adapter->hw,
5992 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
5993 }
5994
5995 /* fetch WoL from EEPROM */
5996 if (eeprom_data & eeprom_apme_mask)
5997 adapter->eeprom_wol |= E1000_WUFC_MAG;
5998
5999 /*
6000 * now that we have the eeprom settings, apply the special cases
6001 * where the eeprom may be wrong or the board simply won't support
6002 * wake on lan on a particular port
6003 */
6004 if (!(adapter->flags & FLAG_HAS_WOL))
6005 adapter->eeprom_wol = 0;
6006
6007 /* initialize the wol settings based on the eeprom settings */
6008 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006009 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006010
Bruce Allan84527592008-11-21 17:00:22 -08006011 /* save off EEPROM version number */
6012 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6013
Auke Kokbc7f75f2007-09-17 12:30:59 -07006014 /* reset the hardware with the new settings */
6015 e1000e_reset(adapter);
6016
Bruce Allanad680762008-03-28 09:15:03 -07006017 /*
6018 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006019 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006020 * under the control of the driver.
6021 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006022 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006023 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006024
Bruce Allane0dc4f12011-01-06 14:29:50 +00006025 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006026 err = register_netdev(netdev);
6027 if (err)
6028 goto err_register;
6029
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006030 /* carrier off reporting is important to ethtool even BEFORE open */
6031 netif_carrier_off(netdev);
6032
Auke Kokbc7f75f2007-09-17 12:30:59 -07006033 e1000_print_device_info(adapter);
6034
Alan Sternf3ec4f82010-06-08 15:23:51 -04006035 if (pci_dev_run_wake(pdev))
6036 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006037
Auke Kokbc7f75f2007-09-17 12:30:59 -07006038 return 0;
6039
6040err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006041 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006042 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006043err_eeprom:
6044 if (!e1000_check_reset_block(&adapter->hw))
6045 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006046err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006047 kfree(adapter->tx_ring);
6048 kfree(adapter->rx_ring);
6049err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006050 if (adapter->hw.flash_address)
6051 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006052 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006053err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006054 iounmap(adapter->hw.hw_addr);
6055err_ioremap:
6056 free_netdev(netdev);
6057err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006058 pci_release_selected_regions(pdev,
6059 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006060err_pci_reg:
6061err_dma:
6062 pci_disable_device(pdev);
6063 return err;
6064}
6065
6066/**
6067 * e1000_remove - Device Removal Routine
6068 * @pdev: PCI device information struct
6069 *
6070 * e1000_remove is called by the PCI subsystem to alert the driver
6071 * that it should release a PCI device. The could be caused by a
6072 * Hot-Plug event, or because the driver is going to be removed from
6073 * memory.
6074 **/
6075static void __devexit e1000_remove(struct pci_dev *pdev)
6076{
6077 struct net_device *netdev = pci_get_drvdata(pdev);
6078 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006079 bool down = test_bit(__E1000_DOWN, &adapter->state);
6080
Bruce Allanad680762008-03-28 09:15:03 -07006081 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006082 * The timers may be rescheduled, so explicitly disable them
6083 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006084 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006085 if (!down)
6086 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006087 del_timer_sync(&adapter->watchdog_timer);
6088 del_timer_sync(&adapter->phy_info_timer);
6089
Bruce Allan41cec6f2009-11-20 23:28:56 +00006090 cancel_work_sync(&adapter->reset_task);
6091 cancel_work_sync(&adapter->watchdog_task);
6092 cancel_work_sync(&adapter->downshift_task);
6093 cancel_work_sync(&adapter->update_phy_task);
Tejun Heo23f333a2010-12-12 16:45:14 +01006094 cancel_work_sync(&adapter->led_blink_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006095 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006096
Bruce Allan17f208d2009-12-01 15:47:22 +00006097 if (!(netdev->flags & IFF_UP))
6098 e1000_power_down_phy(adapter);
6099
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006100 /* Don't lie to e1000_close() down the road. */
6101 if (!down)
6102 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006103 unregister_netdev(netdev);
6104
Alan Sternf3ec4f82010-06-08 15:23:51 -04006105 if (pci_dev_run_wake(pdev))
6106 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006107
Bruce Allanad680762008-03-28 09:15:03 -07006108 /*
6109 * Release control of h/w to f/w. If f/w is AMT enabled, this
6110 * would have already happened in close and is redundant.
6111 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006112 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006113
Bruce Allan4662e822008-08-26 18:37:06 -07006114 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006115 kfree(adapter->tx_ring);
6116 kfree(adapter->rx_ring);
6117
6118 iounmap(adapter->hw.hw_addr);
6119 if (adapter->hw.flash_address)
6120 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006121 pci_release_selected_regions(pdev,
6122 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006123
6124 free_netdev(netdev);
6125
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006126 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006127 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006128
Auke Kokbc7f75f2007-09-17 12:30:59 -07006129 pci_disable_device(pdev);
6130}
6131
6132/* PCI Error Recovery (ERS) */
6133static struct pci_error_handlers e1000_err_handler = {
6134 .error_detected = e1000_io_error_detected,
6135 .slot_reset = e1000_io_slot_reset,
6136 .resume = e1000_io_resume,
6137};
6138
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006139static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006140 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6141 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6142 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6143 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6144 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6145 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006146 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6147 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6148 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006149
Auke Kokbc7f75f2007-09-17 12:30:59 -07006150 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6151 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6152 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6153 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006154
Auke Kokbc7f75f2007-09-17 12:30:59 -07006155 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6156 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6157 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006158
Bruce Allan4662e822008-08-26 18:37:06 -07006159 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006160 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006161 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006162
Auke Kokbc7f75f2007-09-17 12:30:59 -07006163 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6164 board_80003es2lan },
6165 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6166 board_80003es2lan },
6167 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6168 board_80003es2lan },
6169 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6170 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006171
Auke Kokbc7f75f2007-09-17 12:30:59 -07006172 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6173 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6174 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6175 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6176 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6177 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6178 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006179 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006180
Auke Kokbc7f75f2007-09-17 12:30:59 -07006181 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6182 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6183 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6184 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6185 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006186 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006187 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6188 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6189 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6190
6191 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6192 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6193 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006194
Bruce Allanf4187b52008-08-26 18:36:50 -07006195 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6196 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006197 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006198
Bruce Allana4f58f52009-06-02 11:29:18 +00006199 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6200 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6201 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6202 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6203
Bruce Alland3738bb2010-06-16 13:27:28 +00006204 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6205 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6206
Auke Kokbc7f75f2007-09-17 12:30:59 -07006207 { } /* terminate list */
6208};
6209MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6210
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006211#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006212static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006213 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6214 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6215 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006216};
David S. Millere50208a2010-03-16 23:36:24 -07006217#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006218
Auke Kokbc7f75f2007-09-17 12:30:59 -07006219/* PCI Device API Driver */
6220static struct pci_driver e1000_driver = {
6221 .name = e1000e_driver_name,
6222 .id_table = e1000_pci_tbl,
6223 .probe = e1000_probe,
6224 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006225#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006226 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006227#endif
6228 .shutdown = e1000_shutdown,
6229 .err_handler = &e1000_err_handler
6230};
6231
6232/**
6233 * e1000_init_module - Driver Registration Routine
6234 *
6235 * e1000_init_module is the first routine called when the driver is
6236 * loaded. All it does is register with the PCI subsystem.
6237 **/
6238static int __init e1000_init_module(void)
6239{
6240 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006241 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6242 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006243 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006244 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006245
Auke Kokbc7f75f2007-09-17 12:30:59 -07006246 return ret;
6247}
6248module_init(e1000_init_module);
6249
6250/**
6251 * e1000_exit_module - Driver Exit Cleanup Routine
6252 *
6253 * e1000_exit_module is called just before the driver is removed
6254 * from memory.
6255 **/
6256static void __exit e1000_exit_module(void)
6257{
6258 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006259}
6260module_exit(e1000_exit_module);
6261
6262
6263MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6264MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6265MODULE_LICENSE("GPL");
6266MODULE_VERSION(DRV_VERSION);
6267
6268/* e1000_main.c */