blob: d9600566a1fcc24d9d36fac4a2b41faab60fc8f3 [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>
Paul Gortmaker70c71602011-05-22 16:47:17 -040052#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070053
54#include "e1000.h"
55
Bruce Allanc14c6432010-06-16 13:28:34 +000056#define DRV_EXTRAVERSION "-k2"
57
Bruce Allan70d279a2011-02-26 03:12:19 +000058#define DRV_VERSION "1.3.10" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070059char e1000e_driver_name[] = "e1000e";
60const char e1000e_driver_version[] = DRV_VERSION;
61
Bruce Allan78cd29d2011-03-24 03:09:03 +000062static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
63
Auke Kokbc7f75f2007-09-17 12:30:59 -070064static const struct e1000_info *e1000_info_tbl[] = {
65 [board_82571] = &e1000_82571_info,
66 [board_82572] = &e1000_82572_info,
67 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070068 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000069 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070070 [board_80003es2lan] = &e1000_es2_info,
71 [board_ich8lan] = &e1000_ich8_info,
72 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070073 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000074 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000075 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070076};
77
Taku Izumi84f4ee92010-04-27 14:39:08 +000078struct e1000_reg_info {
79 u32 ofs;
80 char *name;
81};
82
Bruce Allanaf667a22010-12-31 06:10:01 +000083#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
84#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
85#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
86#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
87#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000088
Bruce Allanaf667a22010-12-31 06:10:01 +000089#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
90#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
91#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
92#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
93#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000094
95static const struct e1000_reg_info e1000_reg_info_tbl[] = {
96
97 /* General Registers */
98 {E1000_CTRL, "CTRL"},
99 {E1000_STATUS, "STATUS"},
100 {E1000_CTRL_EXT, "CTRL_EXT"},
101
102 /* Interrupt Registers */
103 {E1000_ICR, "ICR"},
104
Bruce Allanaf667a22010-12-31 06:10:01 +0000105 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000106 {E1000_RCTL, "RCTL"},
107 {E1000_RDLEN, "RDLEN"},
108 {E1000_RDH, "RDH"},
109 {E1000_RDT, "RDT"},
110 {E1000_RDTR, "RDTR"},
111 {E1000_RXDCTL(0), "RXDCTL"},
112 {E1000_ERT, "ERT"},
113 {E1000_RDBAL, "RDBAL"},
114 {E1000_RDBAH, "RDBAH"},
115 {E1000_RDFH, "RDFH"},
116 {E1000_RDFT, "RDFT"},
117 {E1000_RDFHS, "RDFHS"},
118 {E1000_RDFTS, "RDFTS"},
119 {E1000_RDFPC, "RDFPC"},
120
Bruce Allanaf667a22010-12-31 06:10:01 +0000121 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000122 {E1000_TCTL, "TCTL"},
123 {E1000_TDBAL, "TDBAL"},
124 {E1000_TDBAH, "TDBAH"},
125 {E1000_TDLEN, "TDLEN"},
126 {E1000_TDH, "TDH"},
127 {E1000_TDT, "TDT"},
128 {E1000_TIDV, "TIDV"},
129 {E1000_TXDCTL(0), "TXDCTL"},
130 {E1000_TADV, "TADV"},
131 {E1000_TARC(0), "TARC"},
132 {E1000_TDFH, "TDFH"},
133 {E1000_TDFT, "TDFT"},
134 {E1000_TDFHS, "TDFHS"},
135 {E1000_TDFTS, "TDFTS"},
136 {E1000_TDFPC, "TDFPC"},
137
138 /* List Terminator */
139 {}
140};
141
142/*
143 * e1000_regdump - register printout routine
144 */
145static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
146{
147 int n = 0;
148 char rname[16];
149 u32 regs[8];
150
151 switch (reginfo->ofs) {
152 case E1000_RXDCTL(0):
153 for (n = 0; n < 2; n++)
154 regs[n] = __er32(hw, E1000_RXDCTL(n));
155 break;
156 case E1000_TXDCTL(0):
157 for (n = 0; n < 2; n++)
158 regs[n] = __er32(hw, E1000_TXDCTL(n));
159 break;
160 case E1000_TARC(0):
161 for (n = 0; n < 2; n++)
162 regs[n] = __er32(hw, E1000_TARC(n));
163 break;
164 default:
165 printk(KERN_INFO "%-15s %08x\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000166 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000167 return;
168 }
169
170 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
171 printk(KERN_INFO "%-15s ", rname);
172 for (n = 0; n < 2; n++)
173 printk(KERN_CONT "%08x ", regs[n]);
174 printk(KERN_CONT "\n");
175}
176
Taku Izumi84f4ee92010-04-27 14:39:08 +0000177/*
Bruce Allanaf667a22010-12-31 06:10:01 +0000178 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Taku Izumi84f4ee92010-04-27 14:39:08 +0000179 */
180static void e1000e_dump(struct e1000_adapter *adapter)
181{
182 struct net_device *netdev = adapter->netdev;
183 struct e1000_hw *hw = &adapter->hw;
184 struct e1000_reg_info *reginfo;
185 struct e1000_ring *tx_ring = adapter->tx_ring;
186 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000187 struct my_u0 {
188 u64 a;
189 u64 b;
190 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000191 struct e1000_buffer *buffer_info;
192 struct e1000_ring *rx_ring = adapter->rx_ring;
193 union e1000_rx_desc_packet_split *rx_desc_ps;
194 struct e1000_rx_desc *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000195 struct my_u1 {
196 u64 a;
197 u64 b;
198 u64 c;
199 u64 d;
200 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000201 u32 staterr;
202 int i = 0;
203
204 if (!netif_msg_hw(adapter))
205 return;
206
207 /* Print netdevice Info */
208 if (netdev) {
209 dev_info(&adapter->pdev->dev, "Net device Info\n");
210 printk(KERN_INFO "Device Name state "
Bruce Allanaf667a22010-12-31 06:10:01 +0000211 "trans_start last_rx\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000212 printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000213 netdev->name, netdev->state, netdev->trans_start,
214 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000215 }
216
217 /* Print Registers */
218 dev_info(&adapter->pdev->dev, "Register Dump\n");
219 printk(KERN_INFO " Register Name Value\n");
220 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
221 reginfo->name; reginfo++) {
222 e1000_regdump(hw, reginfo);
223 }
224
Bruce Allanaf667a22010-12-31 06:10:01 +0000225 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000226 if (!netdev || !netif_running(netdev))
227 goto exit;
228
Bruce Allanaf667a22010-12-31 06:10:01 +0000229 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000230 printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000231 " leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000232 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
233 printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000234 0, tx_ring->next_to_use, tx_ring->next_to_clean,
235 (unsigned long long)buffer_info->dma,
236 buffer_info->length,
237 buffer_info->next_to_watch,
238 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000239
Bruce Allanaf667a22010-12-31 06:10:01 +0000240 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000241 if (!netif_msg_tx_done(adapter))
242 goto rx_ring_summary;
243
Bruce Allanaf667a22010-12-31 06:10:01 +0000244 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000245
246 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
247 *
248 * Legacy Transmit Descriptor
249 * +--------------------------------------------------------------+
250 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
251 * +--------------------------------------------------------------+
252 * 8 | Special | CSS | Status | CMD | CSO | Length |
253 * +--------------------------------------------------------------+
254 * 63 48 47 36 35 32 31 24 23 16 15 0
255 *
256 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
257 * 63 48 47 40 39 32 31 16 15 8 7 0
258 * +----------------------------------------------------------------+
259 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
260 * +----------------------------------------------------------------+
261 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
262 * +----------------------------------------------------------------+
263 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
264 *
265 * Extended Data Descriptor (DTYP=0x1)
266 * +----------------------------------------------------------------+
267 * 0 | Buffer Address [63:0] |
268 * +----------------------------------------------------------------+
269 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
270 * +----------------------------------------------------------------+
271 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
272 */
273 printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000274 " [bi->dma ] leng ntw timestamp bi->skb "
275 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000276 printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000277 " [bi->dma ] leng ntw timestamp bi->skb "
278 "<-- Ext Context format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000279 printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000280 " [bi->dma ] leng ntw timestamp bi->skb "
281 "<-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000282 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
283 tx_desc = E1000_TX_DESC(*tx_ring, i);
284 buffer_info = &tx_ring->buffer_info[i];
285 u0 = (struct my_u0 *)tx_desc;
286 printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000287 "%04X %3X %016llX %p",
288 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
289 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), i,
Bruce Allan8eb64e62010-06-29 18:12:30 +0000290 (unsigned long long)le64_to_cpu(u0->a),
291 (unsigned long long)le64_to_cpu(u0->b),
292 (unsigned long long)buffer_info->dma,
293 buffer_info->length, buffer_info->next_to_watch,
294 (unsigned long long)buffer_info->time_stamp,
Taku Izumi84f4ee92010-04-27 14:39:08 +0000295 buffer_info->skb);
296 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
297 printk(KERN_CONT " NTC/U\n");
298 else if (i == tx_ring->next_to_use)
299 printk(KERN_CONT " NTU\n");
300 else if (i == tx_ring->next_to_clean)
301 printk(KERN_CONT " NTC\n");
302 else
303 printk(KERN_CONT "\n");
304
305 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
306 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Bruce Allanaf667a22010-12-31 06:10:01 +0000307 16, 1, phys_to_virt(buffer_info->dma),
308 buffer_info->length, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000309 }
310
Bruce Allanaf667a22010-12-31 06:10:01 +0000311 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000312rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000313 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000314 printk(KERN_INFO "Queue [NTU] [NTC]\n");
315 printk(KERN_INFO " %5d %5X %5X\n", 0,
Bruce Allanaf667a22010-12-31 06:10:01 +0000316 rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000317
Bruce Allanaf667a22010-12-31 06:10:01 +0000318 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000319 if (!netif_msg_rx_status(adapter))
320 goto exit;
321
Bruce Allanaf667a22010-12-31 06:10:01 +0000322 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000323 switch (adapter->rx_ps_pages) {
324 case 1:
325 case 2:
326 case 3:
327 /* [Extended] Packet Split Receive Descriptor Format
328 *
329 * +-----------------------------------------------------+
330 * 0 | Buffer Address 0 [63:0] |
331 * +-----------------------------------------------------+
332 * 8 | Buffer Address 1 [63:0] |
333 * +-----------------------------------------------------+
334 * 16 | Buffer Address 2 [63:0] |
335 * +-----------------------------------------------------+
336 * 24 | Buffer Address 3 [63:0] |
337 * +-----------------------------------------------------+
338 */
339 printk(KERN_INFO "R [desc] [buffer 0 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000340 "[buffer 1 63:0 ] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000341 "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] "
342 "[bi->skb] <-- Ext Pkt Split format\n");
343 /* [Extended] Receive Descriptor (Write-Back) Format
344 *
345 * 63 48 47 32 31 13 12 8 7 4 3 0
346 * +------------------------------------------------------+
347 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
348 * | Checksum | Ident | | Queue | | Type |
349 * +------------------------------------------------------+
350 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
351 * +------------------------------------------------------+
352 * 63 48 47 32 31 20 19 0
353 */
354 printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000355 "[vl l0 ee es] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000356 "[ l3 l2 l1 hs] [reserved ] ---------------- "
357 "[bi->skb] <-- Ext Rx Write-Back format\n");
358 for (i = 0; i < rx_ring->count; i++) {
359 buffer_info = &rx_ring->buffer_info[i];
360 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
361 u1 = (struct my_u1 *)rx_desc_ps;
362 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000363 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000364 if (staterr & E1000_RXD_STAT_DD) {
365 /* Descriptor Done */
366 printk(KERN_INFO "RWB[0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000367 "%016llX %016llX %016llX "
368 "---------------- %p", i,
369 (unsigned long long)le64_to_cpu(u1->a),
370 (unsigned long long)le64_to_cpu(u1->b),
371 (unsigned long long)le64_to_cpu(u1->c),
372 (unsigned long long)le64_to_cpu(u1->d),
373 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000374 } else {
375 printk(KERN_INFO "R [0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000376 "%016llX %016llX %016llX %016llX %p", i,
377 (unsigned long long)le64_to_cpu(u1->a),
378 (unsigned long long)le64_to_cpu(u1->b),
379 (unsigned long long)le64_to_cpu(u1->c),
380 (unsigned long long)le64_to_cpu(u1->d),
381 (unsigned long long)buffer_info->dma,
382 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000383
384 if (netif_msg_pktdata(adapter))
385 print_hex_dump(KERN_INFO, "",
386 DUMP_PREFIX_ADDRESS, 16, 1,
387 phys_to_virt(buffer_info->dma),
388 adapter->rx_ps_bsize0, true);
389 }
390
391 if (i == rx_ring->next_to_use)
392 printk(KERN_CONT " NTU\n");
393 else if (i == rx_ring->next_to_clean)
394 printk(KERN_CONT " NTC\n");
395 else
396 printk(KERN_CONT "\n");
397 }
398 break;
399 default:
400 case 0:
401 /* Legacy Receive Descriptor Format
402 *
403 * +-----------------------------------------------------+
404 * | Buffer Address [63:0] |
405 * +-----------------------------------------------------+
406 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
407 * +-----------------------------------------------------+
408 * 63 48 47 40 39 32 31 16 15 0
409 */
410 printk(KERN_INFO "Rl[desc] [address 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000411 "[vl er S cks ln] [bi->dma ] [bi->skb] "
412 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000413 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
414 rx_desc = E1000_RX_DESC(*rx_ring, i);
415 buffer_info = &rx_ring->buffer_info[i];
416 u0 = (struct my_u0 *)rx_desc;
417 printk(KERN_INFO "Rl[0x%03X] %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000418 "%016llX %p", i,
419 (unsigned long long)le64_to_cpu(u0->a),
420 (unsigned long long)le64_to_cpu(u0->b),
421 (unsigned long long)buffer_info->dma,
422 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000423 if (i == rx_ring->next_to_use)
424 printk(KERN_CONT " NTU\n");
425 else if (i == rx_ring->next_to_clean)
426 printk(KERN_CONT " NTC\n");
427 else
428 printk(KERN_CONT "\n");
429
430 if (netif_msg_pktdata(adapter))
431 print_hex_dump(KERN_INFO, "",
Bruce Allanaf667a22010-12-31 06:10:01 +0000432 DUMP_PREFIX_ADDRESS,
433 16, 1,
434 phys_to_virt(buffer_info->dma),
435 adapter->rx_buffer_len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000436 }
437 }
438
439exit:
440 return;
441}
442
Auke Kokbc7f75f2007-09-17 12:30:59 -0700443/**
444 * e1000_desc_unused - calculate if we have unused descriptors
445 **/
446static int e1000_desc_unused(struct e1000_ring *ring)
447{
448 if (ring->next_to_clean > ring->next_to_use)
449 return ring->next_to_clean - ring->next_to_use - 1;
450
451 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
452}
453
454/**
Bruce Allanad680762008-03-28 09:15:03 -0700455 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700456 * @adapter: board private structure
457 * @status: descriptor status field as written by hardware
458 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
459 * @skb: pointer to sk_buff to be indicated to stack
460 **/
461static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000462 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000463 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700464{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000465 u16 tag = le16_to_cpu(vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700466 skb->protocol = eth_type_trans(skb, netdev);
467
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000468 if (status & E1000_RXD_STAT_VP)
469 __vlan_hwaccel_put_tag(skb, tag);
470
471 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700472}
473
474/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000475 * e1000_rx_checksum - Receive Checksum Offload
Auke Kokbc7f75f2007-09-17 12:30:59 -0700476 * @adapter: board private structure
477 * @status_err: receive descriptor status and error fields
478 * @csum: receive descriptor csum field
479 * @sk_buff: socket buffer with received data
480 **/
481static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
482 u32 csum, struct sk_buff *skb)
483{
484 u16 status = (u16)status_err;
485 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700486
487 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700488
489 /* Ignore Checksum bit is set */
490 if (status & E1000_RXD_STAT_IXSM)
491 return;
492 /* TCP/UDP checksum error bit is set */
493 if (errors & E1000_RXD_ERR_TCPE) {
494 /* let the stack verify checksum errors */
495 adapter->hw_csum_err++;
496 return;
497 }
498
499 /* TCP/UDP Checksum has not been calculated */
500 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
501 return;
502
503 /* It must be a TCP or UDP packet with a valid checksum */
504 if (status & E1000_RXD_STAT_TCPCS) {
505 /* TCP checksum is good */
506 skb->ip_summed = CHECKSUM_UNNECESSARY;
507 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700508 /*
509 * IP fragment with UDP payload
510 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700511 * and then put the value in host order for further stack use.
512 */
Al Viroa39fe742007-12-11 19:50:34 +0000513 __sum16 sum = (__force __sum16)htons(csum);
514 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700515 skb->ip_summed = CHECKSUM_COMPLETE;
516 }
517 adapter->hw_csum_good++;
518}
519
520/**
521 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
522 * @adapter: address of board private structure
523 **/
524static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
525 int cleaned_count)
526{
527 struct net_device *netdev = adapter->netdev;
528 struct pci_dev *pdev = adapter->pdev;
529 struct e1000_ring *rx_ring = adapter->rx_ring;
530 struct e1000_rx_desc *rx_desc;
531 struct e1000_buffer *buffer_info;
532 struct sk_buff *skb;
533 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000534 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700535
536 i = rx_ring->next_to_use;
537 buffer_info = &rx_ring->buffer_info[i];
538
539 while (cleaned_count--) {
540 skb = buffer_info->skb;
541 if (skb) {
542 skb_trim(skb, 0);
543 goto map_skb;
544 }
545
Eric Dumazet89d71a62009-10-13 05:34:20 +0000546 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700547 if (!skb) {
548 /* Better luck next round */
549 adapter->alloc_rx_buff_failed++;
550 break;
551 }
552
Auke Kokbc7f75f2007-09-17 12:30:59 -0700553 buffer_info->skb = skb;
554map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000555 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700556 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000557 DMA_FROM_DEVICE);
558 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000559 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700560 adapter->rx_dma_failed++;
561 break;
562 }
563
564 rx_desc = E1000_RX_DESC(*rx_ring, i);
565 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
566
Tom Herbert50849d72010-05-05 14:02:49 +0000567 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
568 /*
569 * Force memory writes to complete before letting h/w
570 * know there are new descriptors to fetch. (Only
571 * applicable for weak-ordered memory model archs,
572 * such as IA-64).
573 */
574 wmb();
575 writel(i, adapter->hw.hw_addr + rx_ring->tail);
576 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700577 i++;
578 if (i == rx_ring->count)
579 i = 0;
580 buffer_info = &rx_ring->buffer_info[i];
581 }
582
Tom Herbert50849d72010-05-05 14:02:49 +0000583 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700584}
585
586/**
587 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
588 * @adapter: address of board private structure
589 **/
590static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
591 int cleaned_count)
592{
593 struct net_device *netdev = adapter->netdev;
594 struct pci_dev *pdev = adapter->pdev;
595 union e1000_rx_desc_packet_split *rx_desc;
596 struct e1000_ring *rx_ring = adapter->rx_ring;
597 struct e1000_buffer *buffer_info;
598 struct e1000_ps_page *ps_page;
599 struct sk_buff *skb;
600 unsigned int i, j;
601
602 i = rx_ring->next_to_use;
603 buffer_info = &rx_ring->buffer_info[i];
604
605 while (cleaned_count--) {
606 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
607
608 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700609 ps_page = &buffer_info->ps_pages[j];
610 if (j >= adapter->rx_ps_pages) {
611 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000612 rx_desc->read.buffer_addr[j + 1] =
613 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700614 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700615 }
Auke Kok47f44e42007-10-25 13:57:44 -0700616 if (!ps_page->page) {
617 ps_page->page = alloc_page(GFP_ATOMIC);
618 if (!ps_page->page) {
619 adapter->alloc_rx_buff_failed++;
620 goto no_buffers;
621 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000622 ps_page->dma = dma_map_page(&pdev->dev,
623 ps_page->page,
624 0, PAGE_SIZE,
625 DMA_FROM_DEVICE);
626 if (dma_mapping_error(&pdev->dev,
627 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700628 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000629 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700630 adapter->rx_dma_failed++;
631 goto no_buffers;
632 }
633 }
634 /*
635 * Refresh the desc even if buffer_addrs
636 * didn't change because each write-back
637 * erases this info.
638 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000639 rx_desc->read.buffer_addr[j + 1] =
640 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700641 }
642
Eric Dumazet89d71a62009-10-13 05:34:20 +0000643 skb = netdev_alloc_skb_ip_align(netdev,
644 adapter->rx_ps_bsize0);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700645
646 if (!skb) {
647 adapter->alloc_rx_buff_failed++;
648 break;
649 }
650
Auke Kokbc7f75f2007-09-17 12:30:59 -0700651 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000652 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700653 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000654 DMA_FROM_DEVICE);
655 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000656 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700657 adapter->rx_dma_failed++;
658 /* cleanup skb */
659 dev_kfree_skb_any(skb);
660 buffer_info->skb = NULL;
661 break;
662 }
663
664 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
665
Tom Herbert50849d72010-05-05 14:02:49 +0000666 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
667 /*
668 * Force memory writes to complete before letting h/w
669 * know there are new descriptors to fetch. (Only
670 * applicable for weak-ordered memory model archs,
671 * such as IA-64).
672 */
673 wmb();
Bruce Allanaf667a22010-12-31 06:10:01 +0000674 writel(i << 1, adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000675 }
676
Auke Kokbc7f75f2007-09-17 12:30:59 -0700677 i++;
678 if (i == rx_ring->count)
679 i = 0;
680 buffer_info = &rx_ring->buffer_info[i];
681 }
682
683no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000684 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700685}
686
687/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700688 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
689 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700690 * @cleaned_count: number of buffers to allocate this pass
691 **/
692
693static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
694 int cleaned_count)
695{
696 struct net_device *netdev = adapter->netdev;
697 struct pci_dev *pdev = adapter->pdev;
698 struct e1000_rx_desc *rx_desc;
699 struct e1000_ring *rx_ring = adapter->rx_ring;
700 struct e1000_buffer *buffer_info;
701 struct sk_buff *skb;
702 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000703 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700704
705 i = rx_ring->next_to_use;
706 buffer_info = &rx_ring->buffer_info[i];
707
708 while (cleaned_count--) {
709 skb = buffer_info->skb;
710 if (skb) {
711 skb_trim(skb, 0);
712 goto check_page;
713 }
714
Eric Dumazet89d71a62009-10-13 05:34:20 +0000715 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700716 if (unlikely(!skb)) {
717 /* Better luck next round */
718 adapter->alloc_rx_buff_failed++;
719 break;
720 }
721
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700722 buffer_info->skb = skb;
723check_page:
724 /* allocate a new page if necessary */
725 if (!buffer_info->page) {
726 buffer_info->page = alloc_page(GFP_ATOMIC);
727 if (unlikely(!buffer_info->page)) {
728 adapter->alloc_rx_buff_failed++;
729 break;
730 }
731 }
732
733 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000734 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700735 buffer_info->page, 0,
736 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000737 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700738
739 rx_desc = E1000_RX_DESC(*rx_ring, i);
740 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
741
742 if (unlikely(++i == rx_ring->count))
743 i = 0;
744 buffer_info = &rx_ring->buffer_info[i];
745 }
746
747 if (likely(rx_ring->next_to_use != i)) {
748 rx_ring->next_to_use = i;
749 if (unlikely(i-- == 0))
750 i = (rx_ring->count - 1);
751
752 /* Force memory writes to complete before letting h/w
753 * know there are new descriptors to fetch. (Only
754 * applicable for weak-ordered memory model archs,
755 * such as IA-64). */
756 wmb();
757 writel(i, adapter->hw.hw_addr + rx_ring->tail);
758 }
759}
760
761/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700762 * e1000_clean_rx_irq - Send received data up the network stack; legacy
763 * @adapter: board private structure
764 *
765 * the return value indicates whether actual cleaning was done, there
766 * is no guarantee that everything was cleaned
767 **/
768static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
769 int *work_done, int work_to_do)
770{
771 struct net_device *netdev = adapter->netdev;
772 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000773 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700774 struct e1000_ring *rx_ring = adapter->rx_ring;
775 struct e1000_rx_desc *rx_desc, *next_rxd;
776 struct e1000_buffer *buffer_info, *next_buffer;
777 u32 length;
778 unsigned int i;
779 int cleaned_count = 0;
780 bool cleaned = 0;
781 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
782
783 i = rx_ring->next_to_clean;
784 rx_desc = E1000_RX_DESC(*rx_ring, i);
785 buffer_info = &rx_ring->buffer_info[i];
786
787 while (rx_desc->status & E1000_RXD_STAT_DD) {
788 struct sk_buff *skb;
789 u8 status;
790
791 if (*work_done >= work_to_do)
792 break;
793 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000794 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700795
796 status = rx_desc->status;
797 skb = buffer_info->skb;
798 buffer_info->skb = NULL;
799
800 prefetch(skb->data - NET_IP_ALIGN);
801
802 i++;
803 if (i == rx_ring->count)
804 i = 0;
805 next_rxd = E1000_RX_DESC(*rx_ring, i);
806 prefetch(next_rxd);
807
808 next_buffer = &rx_ring->buffer_info[i];
809
810 cleaned = 1;
811 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000812 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700813 buffer_info->dma,
814 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000815 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700816 buffer_info->dma = 0;
817
818 length = le16_to_cpu(rx_desc->length);
819
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000820 /*
821 * !EOP means multiple descriptors were used to store a single
822 * packet, if that's the case we need to toss it. In fact, we
823 * need to toss every packet with the EOP bit clear and the
824 * next frame that _does_ have the EOP bit set, as it is by
825 * definition only a frame fragment
826 */
827 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
828 adapter->flags2 |= FLAG2_IS_DISCARDING;
829
830 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700831 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000832 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700833 /* recycle */
834 buffer_info->skb = skb;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000835 if (status & E1000_RXD_STAT_EOP)
836 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700837 goto next_desc;
838 }
839
840 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
841 /* recycle */
842 buffer_info->skb = skb;
843 goto next_desc;
844 }
845
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000846 /* adjust length to remove Ethernet CRC */
847 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
848 length -= 4;
849
Auke Kokbc7f75f2007-09-17 12:30:59 -0700850 total_rx_bytes += length;
851 total_rx_packets++;
852
Bruce Allanad680762008-03-28 09:15:03 -0700853 /*
854 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700855 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700856 * of reassembly being done in the stack
857 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700858 if (length < copybreak) {
859 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000860 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700861 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700862 skb_copy_to_linear_data_offset(new_skb,
863 -NET_IP_ALIGN,
864 (skb->data -
865 NET_IP_ALIGN),
866 (length +
867 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700868 /* save the skb in buffer_info as good */
869 buffer_info->skb = skb;
870 skb = new_skb;
871 }
872 /* else just continue with the old one */
873 }
874 /* end copybreak code */
875 skb_put(skb, length);
876
877 /* Receive Checksum Offload */
878 e1000_rx_checksum(adapter,
879 (u32)(status) |
880 ((u32)(rx_desc->errors) << 24),
881 le16_to_cpu(rx_desc->csum), skb);
882
883 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
884
885next_desc:
886 rx_desc->status = 0;
887
888 /* return some buffers to hardware, one at a time is too slow */
889 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
890 adapter->alloc_rx_buf(adapter, cleaned_count);
891 cleaned_count = 0;
892 }
893
894 /* use prefetched values */
895 rx_desc = next_rxd;
896 buffer_info = next_buffer;
897 }
898 rx_ring->next_to_clean = i;
899
900 cleaned_count = e1000_desc_unused(rx_ring);
901 if (cleaned_count)
902 adapter->alloc_rx_buf(adapter, cleaned_count);
903
Auke Kokbc7f75f2007-09-17 12:30:59 -0700904 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700905 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700906 return cleaned;
907}
908
Auke Kokbc7f75f2007-09-17 12:30:59 -0700909static void e1000_put_txbuf(struct e1000_adapter *adapter,
910 struct e1000_buffer *buffer_info)
911{
Alexander Duyck03b13202009-12-02 16:45:31 +0000912 if (buffer_info->dma) {
913 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +0000914 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
915 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000916 else
Nick Nunley0be3f552010-04-27 13:09:05 +0000917 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
918 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000919 buffer_info->dma = 0;
920 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700921 if (buffer_info->skb) {
922 dev_kfree_skb_any(buffer_info->skb);
923 buffer_info->skb = NULL;
924 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000925 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700926}
927
Bruce Allan41cec6f2009-11-20 23:28:56 +0000928static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700929{
Bruce Allan41cec6f2009-11-20 23:28:56 +0000930 struct e1000_adapter *adapter = container_of(work,
931 struct e1000_adapter,
932 print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933 struct e1000_ring *tx_ring = adapter->tx_ring;
934 unsigned int i = tx_ring->next_to_clean;
935 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
936 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +0000937 struct e1000_hw *hw = &adapter->hw;
938 u16 phy_status, phy_1000t_status, phy_ext_status;
939 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700940
Jesse Brandeburg615b32a2011-02-02 10:19:45 +0000941 if (test_bit(__E1000_DOWN, &adapter->state))
942 return;
943
Bruce Allan41cec6f2009-11-20 23:28:56 +0000944 e1e_rphy(hw, PHY_STATUS, &phy_status);
945 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
946 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
947
948 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
949
950 /* detected Hardware unit hang */
951 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700952 " TDH <%x>\n"
953 " TDT <%x>\n"
954 " next_to_use <%x>\n"
955 " next_to_clean <%x>\n"
956 "buffer_info[next_to_clean]:\n"
957 " time_stamp <%lx>\n"
958 " next_to_watch <%x>\n"
959 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +0000960 " next_to_watch.status <%x>\n"
961 "MAC Status <%x>\n"
962 "PHY Status <%x>\n"
963 "PHY 1000BASE-T Status <%x>\n"
964 "PHY Extended Status <%x>\n"
965 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700966 readl(adapter->hw.hw_addr + tx_ring->head),
967 readl(adapter->hw.hw_addr + tx_ring->tail),
968 tx_ring->next_to_use,
969 tx_ring->next_to_clean,
970 tx_ring->buffer_info[eop].time_stamp,
971 eop,
972 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +0000973 eop_desc->upper.fields.status,
974 er32(STATUS),
975 phy_status,
976 phy_1000t_status,
977 phy_ext_status,
978 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700979}
980
981/**
982 * e1000_clean_tx_irq - Reclaim resources after transmit completes
983 * @adapter: board private structure
984 *
985 * the return value indicates whether actual cleaning was done, there
986 * is no guarantee that everything was cleaned
987 **/
988static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
989{
990 struct net_device *netdev = adapter->netdev;
991 struct e1000_hw *hw = &adapter->hw;
992 struct e1000_ring *tx_ring = adapter->tx_ring;
993 struct e1000_tx_desc *tx_desc, *eop_desc;
994 struct e1000_buffer *buffer_info;
995 unsigned int i, eop;
996 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700997 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
998
999 i = tx_ring->next_to_clean;
1000 eop = tx_ring->buffer_info[i].next_to_watch;
1001 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1002
Alexander Duyck12d04a32009-03-25 22:05:03 +00001003 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1004 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001005 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001006 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001007 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001008 tx_desc = E1000_TX_DESC(*tx_ring, i);
1009 buffer_info = &tx_ring->buffer_info[i];
1010 cleaned = (i == eop);
1011
1012 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001013 total_tx_packets += buffer_info->segs;
1014 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001015 }
1016
1017 e1000_put_txbuf(adapter, buffer_info);
1018 tx_desc->upper.data = 0;
1019
1020 i++;
1021 if (i == tx_ring->count)
1022 i = 0;
1023 }
1024
Terry Loftindac87612010-04-09 10:29:49 +00001025 if (i == tx_ring->next_to_use)
1026 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 eop = tx_ring->buffer_info[i].next_to_watch;
1028 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001029 }
1030
1031 tx_ring->next_to_clean = i;
1032
1033#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001034 if (count && netif_carrier_ok(netdev) &&
1035 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036 /* Make sure that anybody stopping the queue after this
1037 * sees the new next_to_clean.
1038 */
1039 smp_mb();
1040
1041 if (netif_queue_stopped(netdev) &&
1042 !(test_bit(__E1000_DOWN, &adapter->state))) {
1043 netif_wake_queue(netdev);
1044 ++adapter->restart_queue;
1045 }
1046 }
1047
1048 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001049 /*
1050 * Detect a transmit hang in hardware, this serializes the
1051 * check with the clearing of time_stamp and movement of i
1052 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001053 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001054 if (tx_ring->buffer_info[i].time_stamp &&
1055 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001056 + (adapter->tx_timeout_factor * HZ)) &&
1057 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001058 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001059 netif_stop_queue(netdev);
1060 }
1061 }
1062 adapter->total_tx_bytes += total_tx_bytes;
1063 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001064 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001065}
1066
1067/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001068 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1069 * @adapter: board private structure
1070 *
1071 * the return value indicates whether actual cleaning was done, there
1072 * is no guarantee that everything was cleaned
1073 **/
1074static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1075 int *work_done, int work_to_do)
1076{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001077 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001078 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1079 struct net_device *netdev = adapter->netdev;
1080 struct pci_dev *pdev = adapter->pdev;
1081 struct e1000_ring *rx_ring = adapter->rx_ring;
1082 struct e1000_buffer *buffer_info, *next_buffer;
1083 struct e1000_ps_page *ps_page;
1084 struct sk_buff *skb;
1085 unsigned int i, j;
1086 u32 length, staterr;
1087 int cleaned_count = 0;
1088 bool cleaned = 0;
1089 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1090
1091 i = rx_ring->next_to_clean;
1092 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1093 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1094 buffer_info = &rx_ring->buffer_info[i];
1095
1096 while (staterr & E1000_RXD_STAT_DD) {
1097 if (*work_done >= work_to_do)
1098 break;
1099 (*work_done)++;
1100 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001101 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102
1103 /* in the packet split case this is header only */
1104 prefetch(skb->data - NET_IP_ALIGN);
1105
1106 i++;
1107 if (i == rx_ring->count)
1108 i = 0;
1109 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1110 prefetch(next_rxd);
1111
1112 next_buffer = &rx_ring->buffer_info[i];
1113
1114 cleaned = 1;
1115 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001116 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001117 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001118 buffer_info->dma = 0;
1119
Bruce Allanaf667a22010-12-31 06:10:01 +00001120 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001121 if (!(staterr & E1000_RXD_STAT_EOP))
1122 adapter->flags2 |= FLAG2_IS_DISCARDING;
1123
1124 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001125 e_dbg("Packet Split buffers didn't pick up the full "
1126 "packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001128 if (staterr & E1000_RXD_STAT_EOP)
1129 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001130 goto next_desc;
1131 }
1132
1133 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1134 dev_kfree_skb_irq(skb);
1135 goto next_desc;
1136 }
1137
1138 length = le16_to_cpu(rx_desc->wb.middle.length0);
1139
1140 if (!length) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001141 e_dbg("Last part of the packet spanning multiple "
1142 "descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143 dev_kfree_skb_irq(skb);
1144 goto next_desc;
1145 }
1146
1147 /* Good Receive */
1148 skb_put(skb, length);
1149
1150 {
Bruce Allanad680762008-03-28 09:15:03 -07001151 /*
1152 * this looks ugly, but it seems compiler issues make it
1153 * more efficient than reusing j
1154 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001155 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1156
Bruce Allanad680762008-03-28 09:15:03 -07001157 /*
1158 * page alloc/put takes too long and effects small packet
1159 * throughput, so unsplit small packets and save the alloc/put
1160 * only valid in softirq (napi) context to call kmap_*
1161 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001162 if (l1 && (l1 <= copybreak) &&
1163 ((length + l1) <= adapter->rx_ps_bsize0)) {
1164 u8 *vaddr;
1165
Auke Kok47f44e42007-10-25 13:57:44 -07001166 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167
Bruce Allanad680762008-03-28 09:15:03 -07001168 /*
1169 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001170 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001171 * very long
1172 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001173 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1174 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001175 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1176 memcpy(skb_tail_pointer(skb), vaddr, l1);
1177 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001178 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1179 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001180
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001181 /* remove the CRC */
1182 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1183 l1 -= 4;
1184
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 skb_put(skb, l1);
1186 goto copydone;
1187 } /* if */
1188 }
1189
1190 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1191 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1192 if (!length)
1193 break;
1194
Auke Kok47f44e42007-10-25 13:57:44 -07001195 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001196 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1197 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001198 ps_page->dma = 0;
1199 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1200 ps_page->page = NULL;
1201 skb->len += length;
1202 skb->data_len += length;
1203 skb->truesize += length;
1204 }
1205
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001206 /* strip the ethernet crc, problem is we're using pages now so
1207 * this whole operation can get a little cpu intensive
1208 */
1209 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1210 pskb_trim(skb, skb->len - 4);
1211
Auke Kokbc7f75f2007-09-17 12:30:59 -07001212copydone:
1213 total_rx_bytes += skb->len;
1214 total_rx_packets++;
1215
1216 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1217 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1218
1219 if (rx_desc->wb.upper.header_status &
1220 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1221 adapter->rx_hdr_split++;
1222
1223 e1000_receive_skb(adapter, netdev, skb,
1224 staterr, rx_desc->wb.middle.vlan);
1225
1226next_desc:
1227 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1228 buffer_info->skb = NULL;
1229
1230 /* return some buffers to hardware, one at a time is too slow */
1231 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1232 adapter->alloc_rx_buf(adapter, cleaned_count);
1233 cleaned_count = 0;
1234 }
1235
1236 /* use prefetched values */
1237 rx_desc = next_rxd;
1238 buffer_info = next_buffer;
1239
1240 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1241 }
1242 rx_ring->next_to_clean = i;
1243
1244 cleaned_count = e1000_desc_unused(rx_ring);
1245 if (cleaned_count)
1246 adapter->alloc_rx_buf(adapter, cleaned_count);
1247
Auke Kokbc7f75f2007-09-17 12:30:59 -07001248 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001249 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 return cleaned;
1251}
1252
1253/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001254 * e1000_consume_page - helper function
1255 **/
1256static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1257 u16 length)
1258{
1259 bi->page = NULL;
1260 skb->len += length;
1261 skb->data_len += length;
1262 skb->truesize += length;
1263}
1264
1265/**
1266 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1267 * @adapter: board private structure
1268 *
1269 * the return value indicates whether actual cleaning was done, there
1270 * is no guarantee that everything was cleaned
1271 **/
1272
1273static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1274 int *work_done, int work_to_do)
1275{
1276 struct net_device *netdev = adapter->netdev;
1277 struct pci_dev *pdev = adapter->pdev;
1278 struct e1000_ring *rx_ring = adapter->rx_ring;
1279 struct e1000_rx_desc *rx_desc, *next_rxd;
1280 struct e1000_buffer *buffer_info, *next_buffer;
1281 u32 length;
1282 unsigned int i;
1283 int cleaned_count = 0;
1284 bool cleaned = false;
1285 unsigned int total_rx_bytes=0, total_rx_packets=0;
1286
1287 i = rx_ring->next_to_clean;
1288 rx_desc = E1000_RX_DESC(*rx_ring, i);
1289 buffer_info = &rx_ring->buffer_info[i];
1290
1291 while (rx_desc->status & E1000_RXD_STAT_DD) {
1292 struct sk_buff *skb;
1293 u8 status;
1294
1295 if (*work_done >= work_to_do)
1296 break;
1297 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001298 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001299
1300 status = rx_desc->status;
1301 skb = buffer_info->skb;
1302 buffer_info->skb = NULL;
1303
1304 ++i;
1305 if (i == rx_ring->count)
1306 i = 0;
1307 next_rxd = E1000_RX_DESC(*rx_ring, i);
1308 prefetch(next_rxd);
1309
1310 next_buffer = &rx_ring->buffer_info[i];
1311
1312 cleaned = true;
1313 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001314 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1315 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001316 buffer_info->dma = 0;
1317
1318 length = le16_to_cpu(rx_desc->length);
1319
1320 /* errors is only valid for DD + EOP descriptors */
1321 if (unlikely((status & E1000_RXD_STAT_EOP) &&
1322 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
1323 /* recycle both page and skb */
1324 buffer_info->skb = skb;
1325 /* an error means any chain goes out the window
1326 * too */
1327 if (rx_ring->rx_skb_top)
Bruce Allanef5ab892011-02-10 08:17:21 +00001328 dev_kfree_skb_irq(rx_ring->rx_skb_top);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001329 rx_ring->rx_skb_top = NULL;
1330 goto next_desc;
1331 }
1332
Bruce Allanf0f1a172010-12-11 05:53:32 +00001333#define rxtop (rx_ring->rx_skb_top)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001334 if (!(status & E1000_RXD_STAT_EOP)) {
1335 /* this descriptor is only the beginning (or middle) */
1336 if (!rxtop) {
1337 /* this is the beginning of a chain */
1338 rxtop = skb;
1339 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1340 0, length);
1341 } else {
1342 /* this is the middle of a chain */
1343 skb_fill_page_desc(rxtop,
1344 skb_shinfo(rxtop)->nr_frags,
1345 buffer_info->page, 0, length);
1346 /* re-use the skb, only consumed the page */
1347 buffer_info->skb = skb;
1348 }
1349 e1000_consume_page(buffer_info, rxtop, length);
1350 goto next_desc;
1351 } else {
1352 if (rxtop) {
1353 /* end of the chain */
1354 skb_fill_page_desc(rxtop,
1355 skb_shinfo(rxtop)->nr_frags,
1356 buffer_info->page, 0, length);
1357 /* re-use the current skb, we only consumed the
1358 * page */
1359 buffer_info->skb = skb;
1360 skb = rxtop;
1361 rxtop = NULL;
1362 e1000_consume_page(buffer_info, skb, length);
1363 } else {
1364 /* no chain, got EOP, this buf is the packet
1365 * copybreak to save the put_page/alloc_page */
1366 if (length <= copybreak &&
1367 skb_tailroom(skb) >= length) {
1368 u8 *vaddr;
1369 vaddr = kmap_atomic(buffer_info->page,
1370 KM_SKB_DATA_SOFTIRQ);
1371 memcpy(skb_tail_pointer(skb), vaddr,
1372 length);
1373 kunmap_atomic(vaddr,
1374 KM_SKB_DATA_SOFTIRQ);
1375 /* re-use the page, so don't erase
1376 * buffer_info->page */
1377 skb_put(skb, length);
1378 } else {
1379 skb_fill_page_desc(skb, 0,
1380 buffer_info->page, 0,
1381 length);
1382 e1000_consume_page(buffer_info, skb,
1383 length);
1384 }
1385 }
1386 }
1387
1388 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1389 e1000_rx_checksum(adapter,
1390 (u32)(status) |
1391 ((u32)(rx_desc->errors) << 24),
1392 le16_to_cpu(rx_desc->csum), skb);
1393
1394 /* probably a little skewed due to removing CRC */
1395 total_rx_bytes += skb->len;
1396 total_rx_packets++;
1397
1398 /* eth type trans needs skb->data to point to something */
1399 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001400 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001401 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001402 goto next_desc;
1403 }
1404
1405 e1000_receive_skb(adapter, netdev, skb, status,
1406 rx_desc->special);
1407
1408next_desc:
1409 rx_desc->status = 0;
1410
1411 /* return some buffers to hardware, one at a time is too slow */
1412 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1413 adapter->alloc_rx_buf(adapter, cleaned_count);
1414 cleaned_count = 0;
1415 }
1416
1417 /* use prefetched values */
1418 rx_desc = next_rxd;
1419 buffer_info = next_buffer;
1420 }
1421 rx_ring->next_to_clean = i;
1422
1423 cleaned_count = e1000_desc_unused(rx_ring);
1424 if (cleaned_count)
1425 adapter->alloc_rx_buf(adapter, cleaned_count);
1426
1427 adapter->total_rx_bytes += total_rx_bytes;
1428 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001429 return cleaned;
1430}
1431
1432/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001433 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1434 * @adapter: board private structure
1435 **/
1436static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1437{
1438 struct e1000_ring *rx_ring = adapter->rx_ring;
1439 struct e1000_buffer *buffer_info;
1440 struct e1000_ps_page *ps_page;
1441 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001442 unsigned int i, j;
1443
1444 /* Free all the Rx ring sk_buffs */
1445 for (i = 0; i < rx_ring->count; i++) {
1446 buffer_info = &rx_ring->buffer_info[i];
1447 if (buffer_info->dma) {
1448 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001449 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001450 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001451 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001452 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001453 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001454 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001455 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001456 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001457 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001458 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001459 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001460 buffer_info->dma = 0;
1461 }
1462
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001463 if (buffer_info->page) {
1464 put_page(buffer_info->page);
1465 buffer_info->page = NULL;
1466 }
1467
Auke Kokbc7f75f2007-09-17 12:30:59 -07001468 if (buffer_info->skb) {
1469 dev_kfree_skb(buffer_info->skb);
1470 buffer_info->skb = NULL;
1471 }
1472
1473 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001474 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001475 if (!ps_page->page)
1476 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001477 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1478 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001479 ps_page->dma = 0;
1480 put_page(ps_page->page);
1481 ps_page->page = NULL;
1482 }
1483 }
1484
1485 /* there also may be some cached data from a chained receive */
1486 if (rx_ring->rx_skb_top) {
1487 dev_kfree_skb(rx_ring->rx_skb_top);
1488 rx_ring->rx_skb_top = NULL;
1489 }
1490
Auke Kokbc7f75f2007-09-17 12:30:59 -07001491 /* Zero out the descriptor ring */
1492 memset(rx_ring->desc, 0, rx_ring->size);
1493
1494 rx_ring->next_to_clean = 0;
1495 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001496 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001497
1498 writel(0, adapter->hw.hw_addr + rx_ring->head);
1499 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1500}
1501
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001502static void e1000e_downshift_workaround(struct work_struct *work)
1503{
1504 struct e1000_adapter *adapter = container_of(work,
1505 struct e1000_adapter, downshift_task);
1506
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001507 if (test_bit(__E1000_DOWN, &adapter->state))
1508 return;
1509
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001510 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1511}
1512
Auke Kokbc7f75f2007-09-17 12:30:59 -07001513/**
1514 * e1000_intr_msi - Interrupt Handler
1515 * @irq: interrupt number
1516 * @data: pointer to a network interface device structure
1517 **/
1518static irqreturn_t e1000_intr_msi(int irq, void *data)
1519{
1520 struct net_device *netdev = data;
1521 struct e1000_adapter *adapter = netdev_priv(netdev);
1522 struct e1000_hw *hw = &adapter->hw;
1523 u32 icr = er32(ICR);
1524
Bruce Allanad680762008-03-28 09:15:03 -07001525 /*
1526 * read ICR disables interrupts using IAM
1527 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001528
dave graham573cca82009-02-10 12:52:05 +00001529 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001530 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001531 /*
1532 * ICH8 workaround-- Call gig speed drop workaround on cable
1533 * disconnect (LSC) before accessing any PHY registers
1534 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001535 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1536 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001537 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001538
Bruce Allanad680762008-03-28 09:15:03 -07001539 /*
1540 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001541 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001542 * adapter in watchdog
1543 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001544 if (netif_carrier_ok(netdev) &&
1545 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1546 /* disable receives */
1547 u32 rctl = er32(RCTL);
1548 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001549 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001550 }
1551 /* guard against interrupt when we're going down */
1552 if (!test_bit(__E1000_DOWN, &adapter->state))
1553 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1554 }
1555
Ben Hutchings288379f2009-01-19 16:43:59 -08001556 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001557 adapter->total_tx_bytes = 0;
1558 adapter->total_tx_packets = 0;
1559 adapter->total_rx_bytes = 0;
1560 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001561 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562 }
1563
1564 return IRQ_HANDLED;
1565}
1566
1567/**
1568 * e1000_intr - Interrupt Handler
1569 * @irq: interrupt number
1570 * @data: pointer to a network interface device structure
1571 **/
1572static irqreturn_t e1000_intr(int irq, void *data)
1573{
1574 struct net_device *netdev = data;
1575 struct e1000_adapter *adapter = netdev_priv(netdev);
1576 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001578
Bruce Allana68ea772009-11-20 23:23:16 +00001579 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001580 return IRQ_NONE; /* Not our interrupt */
1581
Bruce Allanad680762008-03-28 09:15:03 -07001582 /*
1583 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1584 * not set, then the adapter didn't send an interrupt
1585 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001586 if (!(icr & E1000_ICR_INT_ASSERTED))
1587 return IRQ_NONE;
1588
Bruce Allanad680762008-03-28 09:15:03 -07001589 /*
1590 * Interrupt Auto-Mask...upon reading ICR,
1591 * interrupts are masked. No need for the
1592 * IMC write
1593 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001594
dave graham573cca82009-02-10 12:52:05 +00001595 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001596 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001597 /*
1598 * ICH8 workaround-- Call gig speed drop workaround on cable
1599 * disconnect (LSC) before accessing any PHY registers
1600 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001601 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1602 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001603 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001604
Bruce Allanad680762008-03-28 09:15:03 -07001605 /*
1606 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001607 * For packet buffer work-around on link down event;
1608 * disable receives here in the ISR and
1609 * reset adapter in watchdog
1610 */
1611 if (netif_carrier_ok(netdev) &&
1612 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1613 /* disable receives */
1614 rctl = er32(RCTL);
1615 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001616 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001617 }
1618 /* guard against interrupt when we're going down */
1619 if (!test_bit(__E1000_DOWN, &adapter->state))
1620 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1621 }
1622
Ben Hutchings288379f2009-01-19 16:43:59 -08001623 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001624 adapter->total_tx_bytes = 0;
1625 adapter->total_tx_packets = 0;
1626 adapter->total_rx_bytes = 0;
1627 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001628 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001629 }
1630
1631 return IRQ_HANDLED;
1632}
1633
Bruce Allan4662e822008-08-26 18:37:06 -07001634static irqreturn_t e1000_msix_other(int irq, void *data)
1635{
1636 struct net_device *netdev = data;
1637 struct e1000_adapter *adapter = netdev_priv(netdev);
1638 struct e1000_hw *hw = &adapter->hw;
1639 u32 icr = er32(ICR);
1640
1641 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001642 if (!test_bit(__E1000_DOWN, &adapter->state))
1643 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001644 return IRQ_NONE;
1645 }
1646
1647 if (icr & adapter->eiac_mask)
1648 ew32(ICS, (icr & adapter->eiac_mask));
1649
1650 if (icr & E1000_ICR_OTHER) {
1651 if (!(icr & E1000_ICR_LSC))
1652 goto no_link_interrupt;
1653 hw->mac.get_link_status = 1;
1654 /* guard against interrupt when we're going down */
1655 if (!test_bit(__E1000_DOWN, &adapter->state))
1656 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1657 }
1658
1659no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001660 if (!test_bit(__E1000_DOWN, &adapter->state))
1661 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001662
1663 return IRQ_HANDLED;
1664}
1665
1666
1667static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1668{
1669 struct net_device *netdev = data;
1670 struct e1000_adapter *adapter = netdev_priv(netdev);
1671 struct e1000_hw *hw = &adapter->hw;
1672 struct e1000_ring *tx_ring = adapter->tx_ring;
1673
1674
1675 adapter->total_tx_bytes = 0;
1676 adapter->total_tx_packets = 0;
1677
1678 if (!e1000_clean_tx_irq(adapter))
1679 /* Ring was not completely cleaned, so fire another interrupt */
1680 ew32(ICS, tx_ring->ims_val);
1681
1682 return IRQ_HANDLED;
1683}
1684
1685static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1686{
1687 struct net_device *netdev = data;
1688 struct e1000_adapter *adapter = netdev_priv(netdev);
1689
1690 /* Write the ITR value calculated at the end of the
1691 * previous interrupt.
1692 */
1693 if (adapter->rx_ring->set_itr) {
1694 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1695 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1696 adapter->rx_ring->set_itr = 0;
1697 }
1698
Ben Hutchings288379f2009-01-19 16:43:59 -08001699 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001700 adapter->total_rx_bytes = 0;
1701 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001702 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001703 }
1704 return IRQ_HANDLED;
1705}
1706
1707/**
1708 * e1000_configure_msix - Configure MSI-X hardware
1709 *
1710 * e1000_configure_msix sets up the hardware to properly
1711 * generate MSI-X interrupts.
1712 **/
1713static void e1000_configure_msix(struct e1000_adapter *adapter)
1714{
1715 struct e1000_hw *hw = &adapter->hw;
1716 struct e1000_ring *rx_ring = adapter->rx_ring;
1717 struct e1000_ring *tx_ring = adapter->tx_ring;
1718 int vector = 0;
1719 u32 ctrl_ext, ivar = 0;
1720
1721 adapter->eiac_mask = 0;
1722
1723 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1724 if (hw->mac.type == e1000_82574) {
1725 u32 rfctl = er32(RFCTL);
1726 rfctl |= E1000_RFCTL_ACK_DIS;
1727 ew32(RFCTL, rfctl);
1728 }
1729
1730#define E1000_IVAR_INT_ALLOC_VALID 0x8
1731 /* Configure Rx vector */
1732 rx_ring->ims_val = E1000_IMS_RXQ0;
1733 adapter->eiac_mask |= rx_ring->ims_val;
1734 if (rx_ring->itr_val)
1735 writel(1000000000 / (rx_ring->itr_val * 256),
1736 hw->hw_addr + rx_ring->itr_register);
1737 else
1738 writel(1, hw->hw_addr + rx_ring->itr_register);
1739 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1740
1741 /* Configure Tx vector */
1742 tx_ring->ims_val = E1000_IMS_TXQ0;
1743 vector++;
1744 if (tx_ring->itr_val)
1745 writel(1000000000 / (tx_ring->itr_val * 256),
1746 hw->hw_addr + tx_ring->itr_register);
1747 else
1748 writel(1, hw->hw_addr + tx_ring->itr_register);
1749 adapter->eiac_mask |= tx_ring->ims_val;
1750 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1751
1752 /* set vector for Other Causes, e.g. link changes */
1753 vector++;
1754 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1755 if (rx_ring->itr_val)
1756 writel(1000000000 / (rx_ring->itr_val * 256),
1757 hw->hw_addr + E1000_EITR_82574(vector));
1758 else
1759 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1760
1761 /* Cause Tx interrupts on every write back */
1762 ivar |= (1 << 31);
1763
1764 ew32(IVAR, ivar);
1765
1766 /* enable MSI-X PBA support */
1767 ctrl_ext = er32(CTRL_EXT);
1768 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1769
1770 /* Auto-Mask Other interrupts upon ICR read */
1771#define E1000_EIAC_MASK_82574 0x01F00000
1772 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1773 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1774 ew32(CTRL_EXT, ctrl_ext);
1775 e1e_flush();
1776}
1777
1778void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1779{
1780 if (adapter->msix_entries) {
1781 pci_disable_msix(adapter->pdev);
1782 kfree(adapter->msix_entries);
1783 adapter->msix_entries = NULL;
1784 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1785 pci_disable_msi(adapter->pdev);
1786 adapter->flags &= ~FLAG_MSI_ENABLED;
1787 }
Bruce Allan4662e822008-08-26 18:37:06 -07001788}
1789
1790/**
1791 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1792 *
1793 * Attempt to configure interrupts using the best available
1794 * capabilities of the hardware and kernel.
1795 **/
1796void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1797{
1798 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001799 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001800
1801 switch (adapter->int_mode) {
1802 case E1000E_INT_MODE_MSIX:
1803 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001804 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1805 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001806 sizeof(struct msix_entry),
1807 GFP_KERNEL);
1808 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001809 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001810 adapter->msix_entries[i].entry = i;
1811
1812 err = pci_enable_msix(adapter->pdev,
1813 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001814 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001815 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001816 return;
1817 }
1818 /* MSI-X failed, so fall through and try MSI */
1819 e_err("Failed to initialize MSI-X interrupts. "
1820 "Falling back to MSI interrupts.\n");
1821 e1000e_reset_interrupt_capability(adapter);
1822 }
1823 adapter->int_mode = E1000E_INT_MODE_MSI;
1824 /* Fall through */
1825 case E1000E_INT_MODE_MSI:
1826 if (!pci_enable_msi(adapter->pdev)) {
1827 adapter->flags |= FLAG_MSI_ENABLED;
1828 } else {
1829 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1830 e_err("Failed to initialize MSI interrupts. Falling "
1831 "back to legacy interrupts.\n");
1832 }
1833 /* Fall through */
1834 case E1000E_INT_MODE_LEGACY:
1835 /* Don't do anything; this is the system default */
1836 break;
1837 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001838
1839 /* store the number of vectors being used */
1840 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001841}
1842
1843/**
1844 * e1000_request_msix - Initialize MSI-X interrupts
1845 *
1846 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1847 * kernel.
1848 **/
1849static int e1000_request_msix(struct e1000_adapter *adapter)
1850{
1851 struct net_device *netdev = adapter->netdev;
1852 int err = 0, vector = 0;
1853
1854 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001855 snprintf(adapter->rx_ring->name,
1856 sizeof(adapter->rx_ring->name) - 1,
1857 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001858 else
1859 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1860 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001861 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001862 netdev);
1863 if (err)
1864 goto out;
1865 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1866 adapter->rx_ring->itr_val = adapter->itr;
1867 vector++;
1868
1869 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001870 snprintf(adapter->tx_ring->name,
1871 sizeof(adapter->tx_ring->name) - 1,
1872 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001873 else
1874 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1875 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001876 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001877 netdev);
1878 if (err)
1879 goto out;
1880 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1881 adapter->tx_ring->itr_val = adapter->itr;
1882 vector++;
1883
1884 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001885 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001886 if (err)
1887 goto out;
1888
1889 e1000_configure_msix(adapter);
1890 return 0;
1891out:
1892 return err;
1893}
1894
Bruce Allanf8d59f72008-08-08 18:36:11 -07001895/**
1896 * e1000_request_irq - initialize interrupts
1897 *
1898 * Attempts to configure interrupts using the best available
1899 * capabilities of the hardware and kernel.
1900 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001901static int e1000_request_irq(struct e1000_adapter *adapter)
1902{
1903 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001904 int err;
1905
Bruce Allan4662e822008-08-26 18:37:06 -07001906 if (adapter->msix_entries) {
1907 err = e1000_request_msix(adapter);
1908 if (!err)
1909 return err;
1910 /* fall back to MSI */
1911 e1000e_reset_interrupt_capability(adapter);
1912 adapter->int_mode = E1000E_INT_MODE_MSI;
1913 e1000e_set_interrupt_capability(adapter);
1914 }
1915 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001916 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001917 netdev->name, netdev);
1918 if (!err)
1919 return err;
1920
1921 /* fall back to legacy interrupt */
1922 e1000e_reset_interrupt_capability(adapter);
1923 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001924 }
1925
Joe Perchesa0607fd2009-11-18 23:29:17 -08001926 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001927 netdev->name, netdev);
1928 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001929 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001930
1931 return err;
1932}
1933
1934static void e1000_free_irq(struct e1000_adapter *adapter)
1935{
1936 struct net_device *netdev = adapter->netdev;
1937
Bruce Allan4662e822008-08-26 18:37:06 -07001938 if (adapter->msix_entries) {
1939 int vector = 0;
1940
1941 free_irq(adapter->msix_entries[vector].vector, netdev);
1942 vector++;
1943
1944 free_irq(adapter->msix_entries[vector].vector, netdev);
1945 vector++;
1946
1947 /* Other Causes interrupt vector */
1948 free_irq(adapter->msix_entries[vector].vector, netdev);
1949 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001950 }
Bruce Allan4662e822008-08-26 18:37:06 -07001951
1952 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953}
1954
1955/**
1956 * e1000_irq_disable - Mask off interrupt generation on the NIC
1957 **/
1958static void e1000_irq_disable(struct e1000_adapter *adapter)
1959{
1960 struct e1000_hw *hw = &adapter->hw;
1961
Auke Kokbc7f75f2007-09-17 12:30:59 -07001962 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001963 if (adapter->msix_entries)
1964 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001965 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001966
1967 if (adapter->msix_entries) {
1968 int i;
1969 for (i = 0; i < adapter->num_vectors; i++)
1970 synchronize_irq(adapter->msix_entries[i].vector);
1971 } else {
1972 synchronize_irq(adapter->pdev->irq);
1973 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001974}
1975
1976/**
1977 * e1000_irq_enable - Enable default interrupt generation settings
1978 **/
1979static void e1000_irq_enable(struct e1000_adapter *adapter)
1980{
1981 struct e1000_hw *hw = &adapter->hw;
1982
Bruce Allan4662e822008-08-26 18:37:06 -07001983 if (adapter->msix_entries) {
1984 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1985 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1986 } else {
1987 ew32(IMS, IMS_ENABLE_MASK);
1988 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001989 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001990}
1991
1992/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001993 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07001994 * @adapter: address of board private structure
1995 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001996 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001997 * For ASF and Pass Through versions of f/w this means that
1998 * the driver is loaded. For AMT version (only with 82573)
1999 * of the f/w this means that the network i/f is open.
2000 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002001void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002002{
2003 struct e1000_hw *hw = &adapter->hw;
2004 u32 ctrl_ext;
2005 u32 swsm;
2006
2007 /* Let firmware know the driver has taken over */
2008 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2009 swsm = er32(SWSM);
2010 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2011 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2012 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002013 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002014 }
2015}
2016
2017/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002018 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002019 * @adapter: address of board private structure
2020 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002021 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002022 * For ASF and Pass Through versions of f/w this means that the
2023 * driver is no longer loaded. For AMT version (only with 82573) i
2024 * of the f/w this means that the network i/f is closed.
2025 *
2026 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002027void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002028{
2029 struct e1000_hw *hw = &adapter->hw;
2030 u32 ctrl_ext;
2031 u32 swsm;
2032
2033 /* Let firmware taken over control of h/w */
2034 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2035 swsm = er32(SWSM);
2036 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2037 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2038 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002039 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002040 }
2041}
2042
Auke Kokbc7f75f2007-09-17 12:30:59 -07002043/**
2044 * @e1000_alloc_ring - allocate memory for a ring structure
2045 **/
2046static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2047 struct e1000_ring *ring)
2048{
2049 struct pci_dev *pdev = adapter->pdev;
2050
2051 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2052 GFP_KERNEL);
2053 if (!ring->desc)
2054 return -ENOMEM;
2055
2056 return 0;
2057}
2058
2059/**
2060 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2061 * @adapter: board private structure
2062 *
2063 * Return 0 on success, negative on failure
2064 **/
2065int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2066{
2067 struct e1000_ring *tx_ring = adapter->tx_ring;
2068 int err = -ENOMEM, size;
2069
2070 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002071 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002072 if (!tx_ring->buffer_info)
2073 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002074
2075 /* round up to nearest 4K */
2076 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2077 tx_ring->size = ALIGN(tx_ring->size, 4096);
2078
2079 err = e1000_alloc_ring_dma(adapter, tx_ring);
2080 if (err)
2081 goto err;
2082
2083 tx_ring->next_to_use = 0;
2084 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002085
2086 return 0;
2087err:
2088 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002089 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002090 return err;
2091}
2092
2093/**
2094 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2095 * @adapter: board private structure
2096 *
2097 * Returns 0 on success, negative on failure
2098 **/
2099int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2100{
2101 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002102 struct e1000_buffer *buffer_info;
2103 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002104
2105 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002106 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002107 if (!rx_ring->buffer_info)
2108 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002109
Auke Kok47f44e42007-10-25 13:57:44 -07002110 for (i = 0; i < rx_ring->count; i++) {
2111 buffer_info = &rx_ring->buffer_info[i];
2112 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2113 sizeof(struct e1000_ps_page),
2114 GFP_KERNEL);
2115 if (!buffer_info->ps_pages)
2116 goto err_pages;
2117 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002118
2119 desc_len = sizeof(union e1000_rx_desc_packet_split);
2120
2121 /* Round up to nearest 4K */
2122 rx_ring->size = rx_ring->count * desc_len;
2123 rx_ring->size = ALIGN(rx_ring->size, 4096);
2124
2125 err = e1000_alloc_ring_dma(adapter, rx_ring);
2126 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002127 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002128
2129 rx_ring->next_to_clean = 0;
2130 rx_ring->next_to_use = 0;
2131 rx_ring->rx_skb_top = NULL;
2132
2133 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002134
2135err_pages:
2136 for (i = 0; i < rx_ring->count; i++) {
2137 buffer_info = &rx_ring->buffer_info[i];
2138 kfree(buffer_info->ps_pages);
2139 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002140err:
2141 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002142 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002143 return err;
2144}
2145
2146/**
2147 * e1000_clean_tx_ring - Free Tx Buffers
2148 * @adapter: board private structure
2149 **/
2150static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2151{
2152 struct e1000_ring *tx_ring = adapter->tx_ring;
2153 struct e1000_buffer *buffer_info;
2154 unsigned long size;
2155 unsigned int i;
2156
2157 for (i = 0; i < tx_ring->count; i++) {
2158 buffer_info = &tx_ring->buffer_info[i];
2159 e1000_put_txbuf(adapter, buffer_info);
2160 }
2161
2162 size = sizeof(struct e1000_buffer) * tx_ring->count;
2163 memset(tx_ring->buffer_info, 0, size);
2164
2165 memset(tx_ring->desc, 0, tx_ring->size);
2166
2167 tx_ring->next_to_use = 0;
2168 tx_ring->next_to_clean = 0;
2169
2170 writel(0, adapter->hw.hw_addr + tx_ring->head);
2171 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2172}
2173
2174/**
2175 * e1000e_free_tx_resources - Free Tx Resources per Queue
2176 * @adapter: board private structure
2177 *
2178 * Free all transmit software resources
2179 **/
2180void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2181{
2182 struct pci_dev *pdev = adapter->pdev;
2183 struct e1000_ring *tx_ring = adapter->tx_ring;
2184
2185 e1000_clean_tx_ring(adapter);
2186
2187 vfree(tx_ring->buffer_info);
2188 tx_ring->buffer_info = NULL;
2189
2190 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2191 tx_ring->dma);
2192 tx_ring->desc = NULL;
2193}
2194
2195/**
2196 * e1000e_free_rx_resources - Free Rx Resources
2197 * @adapter: board private structure
2198 *
2199 * Free all receive software resources
2200 **/
2201
2202void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2203{
2204 struct pci_dev *pdev = adapter->pdev;
2205 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002206 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002207
2208 e1000_clean_rx_ring(adapter);
2209
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002210 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002211 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002212
Auke Kokbc7f75f2007-09-17 12:30:59 -07002213 vfree(rx_ring->buffer_info);
2214 rx_ring->buffer_info = NULL;
2215
Auke Kokbc7f75f2007-09-17 12:30:59 -07002216 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2217 rx_ring->dma);
2218 rx_ring->desc = NULL;
2219}
2220
2221/**
2222 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002223 * @adapter: pointer to adapter
2224 * @itr_setting: current adapter->itr
2225 * @packets: the number of packets during this measurement interval
2226 * @bytes: the number of bytes during this measurement interval
2227 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002228 * Stores a new ITR value based on packets and byte
2229 * counts during the last interrupt. The advantage of per interrupt
2230 * computation is faster updates and more accurate ITR for the current
2231 * traffic pattern. Constants in this function were computed
2232 * based on theoretical maximum wire speed and thresholds were set based
2233 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002234 * while increasing bulk throughput. This functionality is controlled
2235 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002236 **/
2237static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2238 u16 itr_setting, int packets,
2239 int bytes)
2240{
2241 unsigned int retval = itr_setting;
2242
2243 if (packets == 0)
2244 goto update_itr_done;
2245
2246 switch (itr_setting) {
2247 case lowest_latency:
2248 /* handle TSO and jumbo frames */
2249 if (bytes/packets > 8000)
2250 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002251 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002252 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253 break;
2254 case low_latency: /* 50 usec aka 20000 ints/s */
2255 if (bytes > 10000) {
2256 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002257 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002258 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002259 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002260 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002261 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002262 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002263 } else if (bytes/packets > 2000) {
2264 retval = bulk_latency;
2265 } else if (packets <= 2 && bytes < 512) {
2266 retval = lowest_latency;
2267 }
2268 break;
2269 case bulk_latency: /* 250 usec aka 4000 ints/s */
2270 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002271 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002272 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002273 } else if (bytes < 6000) {
2274 retval = low_latency;
2275 }
2276 break;
2277 }
2278
2279update_itr_done:
2280 return retval;
2281}
2282
2283static void e1000_set_itr(struct e1000_adapter *adapter)
2284{
2285 struct e1000_hw *hw = &adapter->hw;
2286 u16 current_itr;
2287 u32 new_itr = adapter->itr;
2288
2289 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2290 if (adapter->link_speed != SPEED_1000) {
2291 current_itr = 0;
2292 new_itr = 4000;
2293 goto set_itr_now;
2294 }
2295
Bruce Allan828bac82010-09-29 21:39:37 +00002296 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2297 new_itr = 0;
2298 goto set_itr_now;
2299 }
2300
Auke Kokbc7f75f2007-09-17 12:30:59 -07002301 adapter->tx_itr = e1000_update_itr(adapter,
2302 adapter->tx_itr,
2303 adapter->total_tx_packets,
2304 adapter->total_tx_bytes);
2305 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2306 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2307 adapter->tx_itr = low_latency;
2308
2309 adapter->rx_itr = e1000_update_itr(adapter,
2310 adapter->rx_itr,
2311 adapter->total_rx_packets,
2312 adapter->total_rx_bytes);
2313 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2314 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2315 adapter->rx_itr = low_latency;
2316
2317 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2318
2319 switch (current_itr) {
2320 /* counts and packets in update_itr are dependent on these numbers */
2321 case lowest_latency:
2322 new_itr = 70000;
2323 break;
2324 case low_latency:
2325 new_itr = 20000; /* aka hwitr = ~200 */
2326 break;
2327 case bulk_latency:
2328 new_itr = 4000;
2329 break;
2330 default:
2331 break;
2332 }
2333
2334set_itr_now:
2335 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002336 /*
2337 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002338 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002339 * increasing
2340 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341 new_itr = new_itr > adapter->itr ?
2342 min(adapter->itr + (new_itr >> 2), new_itr) :
2343 new_itr;
2344 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002345 adapter->rx_ring->itr_val = new_itr;
2346 if (adapter->msix_entries)
2347 adapter->rx_ring->set_itr = 1;
2348 else
Bruce Allan828bac82010-09-29 21:39:37 +00002349 if (new_itr)
2350 ew32(ITR, 1000000000 / (new_itr * 256));
2351 else
2352 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002353 }
2354}
2355
2356/**
Bruce Allan4662e822008-08-26 18:37:06 -07002357 * e1000_alloc_queues - Allocate memory for all rings
2358 * @adapter: board private structure to initialize
2359 **/
2360static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2361{
2362 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2363 if (!adapter->tx_ring)
2364 goto err;
2365
2366 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2367 if (!adapter->rx_ring)
2368 goto err;
2369
2370 return 0;
2371err:
2372 e_err("Unable to allocate memory for queues\n");
2373 kfree(adapter->rx_ring);
2374 kfree(adapter->tx_ring);
2375 return -ENOMEM;
2376}
2377
2378/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002379 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002380 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002381 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382 **/
2383static int e1000_clean(struct napi_struct *napi, int budget)
2384{
2385 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002386 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002387 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002388 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389
Wang Chen4cf16532008-11-12 23:38:14 -08002390 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002391
Bruce Allan4662e822008-08-26 18:37:06 -07002392 if (adapter->msix_entries &&
2393 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2394 goto clean_rx;
2395
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002396 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002397
Bruce Allan4662e822008-08-26 18:37:06 -07002398clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002399 adapter->clean_rx(adapter, &work_done, budget);
2400
Alexander Duyck12d04a32009-03-25 22:05:03 +00002401 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002402 work_done = budget;
2403
David S. Miller53e52c72008-01-07 21:06:12 -08002404 /* If budget not fully consumed, exit the polling mode */
2405 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002406 if (adapter->itr_setting & 3)
2407 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002408 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002409 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2410 if (adapter->msix_entries)
2411 ew32(IMS, adapter->rx_ring->ims_val);
2412 else
2413 e1000_irq_enable(adapter);
2414 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002415 }
2416
2417 return work_done;
2418}
2419
2420static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2421{
2422 struct e1000_adapter *adapter = netdev_priv(netdev);
2423 struct e1000_hw *hw = &adapter->hw;
2424 u32 vfta, index;
2425
2426 /* don't update vlan cookie if already programmed */
2427 if ((adapter->hw.mng_cookie.status &
2428 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2429 (vid == adapter->mng_vlan_id))
2430 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002431
Auke Kokbc7f75f2007-09-17 12:30:59 -07002432 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002433 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2434 index = (vid >> 5) & 0x7F;
2435 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2436 vfta |= (1 << (vid & 0x1F));
2437 hw->mac.ops.write_vfta(hw, index, vfta);
2438 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002439
2440 set_bit(vid, adapter->active_vlans);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002441}
2442
2443static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2444{
2445 struct e1000_adapter *adapter = netdev_priv(netdev);
2446 struct e1000_hw *hw = &adapter->hw;
2447 u32 vfta, index;
2448
Auke Kokbc7f75f2007-09-17 12:30:59 -07002449 if ((adapter->hw.mng_cookie.status &
2450 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2451 (vid == adapter->mng_vlan_id)) {
2452 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002453 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 return;
2455 }
2456
2457 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002458 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2459 index = (vid >> 5) & 0x7F;
2460 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2461 vfta &= ~(1 << (vid & 0x1F));
2462 hw->mac.ops.write_vfta(hw, index, vfta);
2463 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002464
2465 clear_bit(vid, adapter->active_vlans);
2466}
2467
2468/**
2469 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2470 * @adapter: board private structure to initialize
2471 **/
2472static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2473{
2474 struct net_device *netdev = adapter->netdev;
2475 struct e1000_hw *hw = &adapter->hw;
2476 u32 rctl;
2477
2478 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2479 /* disable VLAN receive filtering */
2480 rctl = er32(RCTL);
2481 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2482 ew32(RCTL, rctl);
2483
2484 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2485 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2486 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2487 }
2488 }
2489}
2490
2491/**
2492 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2493 * @adapter: board private structure to initialize
2494 **/
2495static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2496{
2497 struct e1000_hw *hw = &adapter->hw;
2498 u32 rctl;
2499
2500 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2501 /* enable VLAN receive filtering */
2502 rctl = er32(RCTL);
2503 rctl |= E1000_RCTL_VFE;
2504 rctl &= ~E1000_RCTL_CFIEN;
2505 ew32(RCTL, rctl);
2506 }
2507}
2508
2509/**
2510 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2511 * @adapter: board private structure to initialize
2512 **/
2513static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2514{
2515 struct e1000_hw *hw = &adapter->hw;
2516 u32 ctrl;
2517
2518 /* disable VLAN tag insert/strip */
2519 ctrl = er32(CTRL);
2520 ctrl &= ~E1000_CTRL_VME;
2521 ew32(CTRL, ctrl);
2522}
2523
2524/**
2525 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2526 * @adapter: board private structure to initialize
2527 **/
2528static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2529{
2530 struct e1000_hw *hw = &adapter->hw;
2531 u32 ctrl;
2532
2533 /* enable VLAN tag insert/strip */
2534 ctrl = er32(CTRL);
2535 ctrl |= E1000_CTRL_VME;
2536 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002537}
2538
2539static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2540{
2541 struct net_device *netdev = adapter->netdev;
2542 u16 vid = adapter->hw.mng_cookie.vlan_id;
2543 u16 old_vid = adapter->mng_vlan_id;
2544
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002545 if (adapter->hw.mng_cookie.status &
2546 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2547 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002548 adapter->mng_vlan_id = vid;
2549 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002550
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002551 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2552 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002553}
2554
2555static void e1000_restore_vlan(struct e1000_adapter *adapter)
2556{
2557 u16 vid;
2558
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002559 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002561 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002562 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563}
2564
Bruce Allancd791612010-05-10 14:59:51 +00002565static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566{
2567 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002568 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002569
2570 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2571 return;
2572
2573 manc = er32(MANC);
2574
Bruce Allanad680762008-03-28 09:15:03 -07002575 /*
2576 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002578 * the packets will be handled on SMBUS
2579 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002580 manc |= E1000_MANC_EN_MNG2HOST;
2581 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002582
2583 switch (hw->mac.type) {
2584 default:
2585 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2586 break;
2587 case e1000_82574:
2588 case e1000_82583:
2589 /*
2590 * Check if IPMI pass-through decision filter already exists;
2591 * if so, enable it.
2592 */
2593 for (i = 0, j = 0; i < 8; i++) {
2594 mdef = er32(MDEF(i));
2595
2596 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002597 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002598 continue;
2599
2600 /* Enable this decision filter in MANC2H */
2601 if (mdef)
2602 manc2h |= (1 << i);
2603
2604 j |= mdef;
2605 }
2606
2607 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2608 break;
2609
2610 /* Create new decision filter in an empty filter */
2611 for (i = 0, j = 0; i < 8; i++)
2612 if (er32(MDEF(i)) == 0) {
2613 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2614 E1000_MDEF_PORT_664));
2615 manc2h |= (1 << 1);
2616 j++;
2617 break;
2618 }
2619
2620 if (!j)
2621 e_warn("Unable to create IPMI pass-through filter\n");
2622 break;
2623 }
2624
Auke Kokbc7f75f2007-09-17 12:30:59 -07002625 ew32(MANC2H, manc2h);
2626 ew32(MANC, manc);
2627}
2628
2629/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002630 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002631 * @adapter: board private structure
2632 *
2633 * Configure the Tx unit of the MAC after a reset.
2634 **/
2635static void e1000_configure_tx(struct e1000_adapter *adapter)
2636{
2637 struct e1000_hw *hw = &adapter->hw;
2638 struct e1000_ring *tx_ring = adapter->tx_ring;
2639 u64 tdba;
2640 u32 tdlen, tctl, tipg, tarc;
2641 u32 ipgr1, ipgr2;
2642
2643 /* Setup the HW Tx Head and Tail descriptor pointers */
2644 tdba = tx_ring->dma;
2645 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002646 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002647 ew32(TDBAH, (tdba >> 32));
2648 ew32(TDLEN, tdlen);
2649 ew32(TDH, 0);
2650 ew32(TDT, 0);
2651 tx_ring->head = E1000_TDH;
2652 tx_ring->tail = E1000_TDT;
2653
2654 /* Set the default values for the Tx Inter Packet Gap timer */
2655 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2656 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2657 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2658
2659 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2660 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2661
2662 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2663 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2664 ew32(TIPG, tipg);
2665
2666 /* Set the Tx Interrupt Delay register */
2667 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002668 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002669 ew32(TADV, adapter->tx_abs_int_delay);
2670
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002671 if (adapter->flags2 & FLAG2_DMA_BURST) {
2672 u32 txdctl = er32(TXDCTL(0));
2673 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2674 E1000_TXDCTL_WTHRESH);
2675 /*
2676 * set up some performance related parameters to encourage the
2677 * hardware to use the bus more efficiently in bursts, depends
2678 * on the tx_int_delay to be enabled,
2679 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2680 * hthresh = 1 ==> prefetch when one or more available
2681 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2682 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002683 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002684 */
2685 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2686 ew32(TXDCTL(0), txdctl);
2687 /* erratum work around: set txdctl the same for both queues */
2688 ew32(TXDCTL(1), txdctl);
2689 }
2690
Auke Kokbc7f75f2007-09-17 12:30:59 -07002691 /* Program the Transmit Control Register */
2692 tctl = er32(TCTL);
2693 tctl &= ~E1000_TCTL_CT;
2694 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2695 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2696
2697 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002698 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002699 /*
2700 * set the speed mode bit, we'll clear it if we're not at
2701 * gigabit link later
2702 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002703#define SPEED_MODE_BIT (1 << 21)
2704 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002705 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002706 }
2707
2708 /* errata: program both queues to unweighted RR */
2709 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002710 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002712 ew32(TARC(0), tarc);
2713 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002714 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002715 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002716 }
2717
Auke Kokbc7f75f2007-09-17 12:30:59 -07002718 /* Setup Transmit Descriptor Settings for eop descriptor */
2719 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2720
2721 /* only set IDE if we are delaying interrupts using the timers */
2722 if (adapter->tx_int_delay)
2723 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2724
2725 /* enable Report Status bit */
2726 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2727
2728 ew32(TCTL, tctl);
2729
Simon Hormanedfea6e62009-06-08 14:28:36 +00002730 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002731}
2732
2733/**
2734 * e1000_setup_rctl - configure the receive control registers
2735 * @adapter: Board private structure
2736 **/
2737#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2738 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2739static void e1000_setup_rctl(struct e1000_adapter *adapter)
2740{
2741 struct e1000_hw *hw = &adapter->hw;
2742 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002743 u32 pages = 0;
2744
Bruce Allana1ce6472010-09-22 17:16:40 +00002745 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2746 if (hw->mac.type == e1000_pch2lan) {
2747 s32 ret_val;
2748
2749 if (adapter->netdev->mtu > ETH_DATA_LEN)
2750 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2751 else
2752 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002753
2754 if (ret_val)
2755 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002756 }
2757
Auke Kokbc7f75f2007-09-17 12:30:59 -07002758 /* Program MC offset vector base */
2759 rctl = er32(RCTL);
2760 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2761 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2762 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2763 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2764
2765 /* Do not Store bad packets */
2766 rctl &= ~E1000_RCTL_SBP;
2767
2768 /* Enable Long Packet receive */
2769 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2770 rctl &= ~E1000_RCTL_LPE;
2771 else
2772 rctl |= E1000_RCTL_LPE;
2773
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002774 /* Some systems expect that the CRC is included in SMBUS traffic. The
2775 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2776 * host memory when this is enabled
2777 */
2778 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2779 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002780
Bruce Allana4f58f52009-06-02 11:29:18 +00002781 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2782 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2783 u16 phy_data;
2784
2785 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2786 phy_data &= 0xfff8;
2787 phy_data |= (1 << 2);
2788 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2789
2790 e1e_rphy(hw, 22, &phy_data);
2791 phy_data &= 0x0fff;
2792 phy_data |= (1 << 14);
2793 e1e_wphy(hw, 0x10, 0x2823);
2794 e1e_wphy(hw, 0x11, 0x0003);
2795 e1e_wphy(hw, 22, phy_data);
2796 }
2797
Auke Kokbc7f75f2007-09-17 12:30:59 -07002798 /* Setup buffer sizes */
2799 rctl &= ~E1000_RCTL_SZ_4096;
2800 rctl |= E1000_RCTL_BSEX;
2801 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002802 case 2048:
2803 default:
2804 rctl |= E1000_RCTL_SZ_2048;
2805 rctl &= ~E1000_RCTL_BSEX;
2806 break;
2807 case 4096:
2808 rctl |= E1000_RCTL_SZ_4096;
2809 break;
2810 case 8192:
2811 rctl |= E1000_RCTL_SZ_8192;
2812 break;
2813 case 16384:
2814 rctl |= E1000_RCTL_SZ_16384;
2815 break;
2816 }
2817
2818 /*
2819 * 82571 and greater support packet-split where the protocol
2820 * header is placed in skb->data and the packet data is
2821 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2822 * In the case of a non-split, skb->data is linearly filled,
2823 * followed by the page buffers. Therefore, skb->data is
2824 * sized to hold the largest protocol header.
2825 *
2826 * allocations using alloc_page take too long for regular MTU
2827 * so only enable packet split for jumbo frames
2828 *
2829 * Using pages when the page size is greater than 16k wastes
2830 * a lot of memory, since we allocate 3 pages at all times
2831 * per packet.
2832 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fec2010-06-17 18:59:27 +00002834 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002835 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002836 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002837 else
2838 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002839
2840 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002841 u32 psrctl = 0;
2842
Auke Kokbc7f75f2007-09-17 12:30:59 -07002843 /* Configure extra packet-split registers */
2844 rfctl = er32(RFCTL);
2845 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002846 /*
2847 * disable packet split support for IPv6 extension headers,
2848 * because some malformed IPv6 headers can hang the Rx
2849 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002850 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2851 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2852
2853 ew32(RFCTL, rfctl);
2854
Auke Kok140a7482007-10-25 13:57:58 -07002855 /* Enable Packet split descriptors */
2856 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002857
2858 psrctl |= adapter->rx_ps_bsize0 >>
2859 E1000_PSRCTL_BSIZE0_SHIFT;
2860
2861 switch (adapter->rx_ps_pages) {
2862 case 3:
2863 psrctl |= PAGE_SIZE <<
2864 E1000_PSRCTL_BSIZE3_SHIFT;
2865 case 2:
2866 psrctl |= PAGE_SIZE <<
2867 E1000_PSRCTL_BSIZE2_SHIFT;
2868 case 1:
2869 psrctl |= PAGE_SIZE >>
2870 E1000_PSRCTL_BSIZE1_SHIFT;
2871 break;
2872 }
2873
2874 ew32(PSRCTL, psrctl);
2875 }
2876
2877 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002878 /* just started the receive unit, no need to restart */
2879 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002880}
2881
2882/**
2883 * e1000_configure_rx - Configure Receive Unit after Reset
2884 * @adapter: board private structure
2885 *
2886 * Configure the Rx unit of the MAC after a reset.
2887 **/
2888static void e1000_configure_rx(struct e1000_adapter *adapter)
2889{
2890 struct e1000_hw *hw = &adapter->hw;
2891 struct e1000_ring *rx_ring = adapter->rx_ring;
2892 u64 rdba;
2893 u32 rdlen, rctl, rxcsum, ctrl_ext;
2894
2895 if (adapter->rx_ps_pages) {
2896 /* this is a 32 byte descriptor */
2897 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002898 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002899 adapter->clean_rx = e1000_clean_rx_irq_ps;
2900 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002901 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2902 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2903 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2904 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002906 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002907 adapter->clean_rx = e1000_clean_rx_irq;
2908 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2909 }
2910
2911 /* disable receives while setting up the descriptors */
2912 rctl = er32(RCTL);
2913 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2914 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00002915 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002916
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002917 if (adapter->flags2 & FLAG2_DMA_BURST) {
2918 /*
2919 * set the writeback threshold (only takes effect if the RDTR
2920 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00002921 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002922 * granularity = 01
2923 * wthresh = 04,
2924 * hthresh = 04,
2925 * pthresh = 0x20
2926 */
2927 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
2928 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
2929
2930 /*
2931 * override the delay timers for enabling bursting, only if
2932 * the value was not set by the user via module options
2933 */
2934 if (adapter->rx_int_delay == DEFAULT_RDTR)
2935 adapter->rx_int_delay = BURST_RDTR;
2936 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
2937 adapter->rx_abs_int_delay = BURST_RADV;
2938 }
2939
Auke Kokbc7f75f2007-09-17 12:30:59 -07002940 /* set the Receive Delay Timer Register */
2941 ew32(RDTR, adapter->rx_int_delay);
2942
2943 /* irq moderation */
2944 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00002945 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07002946 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002947
2948 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002949 /* Auto-Mask interrupts upon ICR access */
2950 ctrl_ext |= E1000_CTRL_EXT_IAME;
2951 ew32(IAM, 0xffffffff);
2952 ew32(CTRL_EXT, ctrl_ext);
2953 e1e_flush();
2954
Bruce Allanad680762008-03-28 09:15:03 -07002955 /*
2956 * Setup the HW Rx Head and Tail Descriptor Pointers and
2957 * the Base and Length of the Rx Descriptor Ring
2958 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002959 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002960 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961 ew32(RDBAH, (rdba >> 32));
2962 ew32(RDLEN, rdlen);
2963 ew32(RDH, 0);
2964 ew32(RDT, 0);
2965 rx_ring->head = E1000_RDH;
2966 rx_ring->tail = E1000_RDT;
2967
2968 /* Enable Receive Checksum Offload for TCP and UDP */
2969 rxcsum = er32(RXCSUM);
2970 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2971 rxcsum |= E1000_RXCSUM_TUOFL;
2972
Bruce Allanad680762008-03-28 09:15:03 -07002973 /*
2974 * IPv4 payload checksum for UDP fragments must be
2975 * used in conjunction with packet-split.
2976 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002977 if (adapter->rx_ps_pages)
2978 rxcsum |= E1000_RXCSUM_IPPCSE;
2979 } else {
2980 rxcsum &= ~E1000_RXCSUM_TUOFL;
2981 /* no need to clear IPPCSE as it defaults to 0 */
2982 }
2983 ew32(RXCSUM, rxcsum);
2984
Bruce Allanad680762008-03-28 09:15:03 -07002985 /*
2986 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002987 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002988 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2989 */
Bruce Allan828bac82010-09-29 21:39:37 +00002990 if ((adapter->flags & FLAG_HAS_ERT) ||
2991 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00002992 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2993 u32 rxdctl = er32(RXDCTL(0));
2994 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00002995 if (adapter->flags & FLAG_HAS_ERT)
2996 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00002997 /*
2998 * With jumbo frames and early-receive enabled,
2999 * excessive C-state transition latencies result in
3000 * dropped transactions.
3001 */
Bruce Allanaf667a22010-12-31 06:10:01 +00003002 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003003 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003004 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3005 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003006 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003007 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003008
3009 /* Enable Receives */
3010 ew32(RCTL, rctl);
3011}
3012
3013/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003014 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07003015 * @hw: pointer to the HW structure
3016 * @mc_addr_list: array of multicast addresses to program
3017 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07003018 *
Bruce Allanab8932f2010-01-13 02:05:38 +00003019 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003020 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003021 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003022static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003023 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003024{
Bruce Allanab8932f2010-01-13 02:05:38 +00003025 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003026}
3027
3028/**
3029 * e1000_set_multi - Multicast and Promiscuous mode set
3030 * @netdev: network interface device structure
3031 *
3032 * The set_multi entry point is called whenever the multicast address
3033 * list or the network interface flags are updated. This routine is
3034 * responsible for configuring the hardware for proper multicast,
3035 * promiscuous mode, and all-multi behavior.
3036 **/
3037static void e1000_set_multi(struct net_device *netdev)
3038{
3039 struct e1000_adapter *adapter = netdev_priv(netdev);
3040 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003041 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003042 u8 *mta_list;
3043 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003044
3045 /* Check for Promiscuous and All Multicast modes */
3046
3047 rctl = er32(RCTL);
3048
3049 if (netdev->flags & IFF_PROMISC) {
3050 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003051 rctl &= ~E1000_RCTL_VFE;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003052 /* Do not hardware filter VLANs in promisc mode */
3053 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003054 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003055 if (netdev->flags & IFF_ALLMULTI) {
3056 rctl |= E1000_RCTL_MPE;
3057 rctl &= ~E1000_RCTL_UPE;
3058 } else {
3059 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3060 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003061 e1000e_vlan_filter_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003062 }
3063
3064 ew32(RCTL, rctl);
3065
Jiri Pirko7aeef972010-02-05 02:52:39 +00003066 if (!netdev_mc_empty(netdev)) {
Bruce Allan90da0662011-01-06 07:02:53 +00003067 int i = 0;
3068
Jiri Pirko7aeef972010-02-05 02:52:39 +00003069 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003070 if (!mta_list)
3071 return;
3072
3073 /* prepare a packed array of only addresses. */
Jiri Pirko22bedad32010-04-01 21:22:57 +00003074 netdev_for_each_mc_addr(ha, netdev)
3075 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003076
Bruce Allanab8932f2010-01-13 02:05:38 +00003077 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003078 kfree(mta_list);
3079 } else {
3080 /*
3081 * if we're called from probe, we might not have
3082 * anything to do here, so clear out the list
3083 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003084 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003085 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003086
3087 if (netdev->features & NETIF_F_HW_VLAN_RX)
3088 e1000e_vlan_strip_enable(adapter);
3089 else
3090 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003091}
3092
3093/**
Bruce Allanad680762008-03-28 09:15:03 -07003094 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003095 * @adapter: private board structure
3096 **/
3097static void e1000_configure(struct e1000_adapter *adapter)
3098{
3099 e1000_set_multi(adapter->netdev);
3100
3101 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003102 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003103
3104 e1000_configure_tx(adapter);
3105 e1000_setup_rctl(adapter);
3106 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003107 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003108}
3109
3110/**
3111 * e1000e_power_up_phy - restore link in case the phy was powered down
3112 * @adapter: address of board private structure
3113 *
3114 * The phy may be powered down to save power and turn off link when the
3115 * driver is unloaded and wake on lan is not enabled (among others)
3116 * *** this routine MUST be followed by a call to e1000e_reset ***
3117 **/
3118void e1000e_power_up_phy(struct e1000_adapter *adapter)
3119{
Bruce Allan17f208d2009-12-01 15:47:22 +00003120 if (adapter->hw.phy.ops.power_up)
3121 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003122
3123 adapter->hw.mac.ops.setup_link(&adapter->hw);
3124}
3125
3126/**
3127 * e1000_power_down_phy - Power down the PHY
3128 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003129 * Power down the PHY so no link is implied when interface is down.
3130 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003131 */
3132static void e1000_power_down_phy(struct e1000_adapter *adapter)
3133{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003134 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003135 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003136 return;
3137
Bruce Allan17f208d2009-12-01 15:47:22 +00003138 if (adapter->hw.phy.ops.power_down)
3139 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003140}
3141
3142/**
3143 * e1000e_reset - bring the hardware into a known good state
3144 *
3145 * This function boots the hardware and enables some settings that
3146 * require a configuration cycle of the hardware - those cannot be
3147 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003148 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003149 */
3150void e1000e_reset(struct e1000_adapter *adapter)
3151{
3152 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003153 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003154 struct e1000_hw *hw = &adapter->hw;
3155 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003156 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003157 u16 hwm;
3158
Bruce Allanad680762008-03-28 09:15:03 -07003159 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003160 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003161
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003162 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003163 /*
3164 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003165 * large enough to accommodate two full transmit packets,
3166 * rounded up to the next 1KB and expressed in KB. Likewise,
3167 * the Rx FIFO should be large enough to accommodate at least
3168 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003169 * expressed in KB.
3170 */
Auke Kokdf762462007-10-25 13:57:53 -07003171 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003172 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003173 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003174 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003175 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003176 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003177 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003178 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003179 */
3180 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003181 sizeof(struct e1000_tx_desc) -
3182 ETH_FCS_LEN) * 2;
3183 min_tx_space = ALIGN(min_tx_space, 1024);
3184 min_tx_space >>= 10;
3185 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003186 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003187 min_rx_space = ALIGN(min_rx_space, 1024);
3188 min_rx_space >>= 10;
3189
Bruce Allanad680762008-03-28 09:15:03 -07003190 /*
3191 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003192 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003193 * allocation, take space away from current Rx allocation
3194 */
Auke Kokdf762462007-10-25 13:57:53 -07003195 if ((tx_space < min_tx_space) &&
3196 ((min_tx_space - tx_space) < pba)) {
3197 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003198
Bruce Allanad680762008-03-28 09:15:03 -07003199 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003200 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003201 * adjustment or use Early Receive if available
3202 */
Auke Kokdf762462007-10-25 13:57:53 -07003203 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003204 (!(adapter->flags & FLAG_HAS_ERT)))
3205 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003206 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003207 }
Auke Kokdf762462007-10-25 13:57:53 -07003208
3209 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003210 }
3211
Bruce Allanad680762008-03-28 09:15:03 -07003212 /*
3213 * flow control settings
3214 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003215 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003216 * (or the size used for early receive) above it in the Rx FIFO.
3217 * Set it to the lower of:
3218 * - 90% of the Rx FIFO size, and
3219 * - the full Rx FIFO size minus the early receive size (for parts
3220 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003221 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003222 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003223 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3224 fc->pause_time = 0xFFFF;
3225 else
3226 fc->pause_time = E1000_FC_PAUSE_TIME;
3227 fc->send_xon = 1;
3228 fc->current_mode = fc->requested_mode;
3229
3230 switch (hw->mac.type) {
3231 default:
3232 if ((adapter->flags & FLAG_HAS_ERT) &&
3233 (adapter->netdev->mtu > ETH_DATA_LEN))
3234 hwm = min(((pba << 10) * 9 / 10),
3235 ((pba << 10) - (E1000_ERT_2048 << 3)));
3236 else
3237 hwm = min(((pba << 10) * 9 / 10),
3238 ((pba << 10) - adapter->max_frame_size));
3239
3240 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3241 fc->low_water = fc->high_water - 8;
3242 break;
3243 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003244 /*
3245 * Workaround PCH LOM adapter hangs with certain network
3246 * loads. If hangs persist, try disabling Tx flow control.
3247 */
3248 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3249 fc->high_water = 0x3500;
3250 fc->low_water = 0x1500;
3251 } else {
3252 fc->high_water = 0x5000;
3253 fc->low_water = 0x3000;
3254 }
Bruce Allana3055952010-05-10 15:02:12 +00003255 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003256 break;
3257 case e1000_pch2lan:
3258 fc->high_water = 0x05C20;
3259 fc->low_water = 0x05048;
3260 fc->pause_time = 0x0650;
3261 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003262 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3263 pba = 14;
3264 ew32(PBA, pba);
3265 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003266 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003267 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003268
Bruce Allan828bac82010-09-29 21:39:37 +00003269 /*
3270 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3271 * fit in receive buffer and early-receive not supported.
3272 */
3273 if (adapter->itr_setting & 0x3) {
3274 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3275 !(adapter->flags & FLAG_HAS_ERT)) {
3276 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3277 dev_info(&adapter->pdev->dev,
3278 "Interrupt Throttle Rate turned off\n");
3279 adapter->flags2 |= FLAG2_DISABLE_AIM;
3280 ew32(ITR, 0);
3281 }
3282 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3283 dev_info(&adapter->pdev->dev,
3284 "Interrupt Throttle Rate turned on\n");
3285 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3286 adapter->itr = 20000;
3287 ew32(ITR, 1000000000 / (adapter->itr * 256));
3288 }
3289 }
3290
Auke Kokbc7f75f2007-09-17 12:30:59 -07003291 /* Allow time for pending master requests to run */
3292 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003293
3294 /*
3295 * For parts with AMT enabled, let the firmware know
3296 * that the network interface is in control
3297 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003298 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003299 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003300
Auke Kokbc7f75f2007-09-17 12:30:59 -07003301 ew32(WUC, 0);
3302
3303 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003304 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003305
3306 e1000_update_mng_vlan(adapter);
3307
3308 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3309 ew32(VET, ETH_P_8021Q);
3310
3311 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003312
3313 if (!netif_running(adapter->netdev) &&
3314 !test_bit(__E1000_TESTING, &adapter->state)) {
3315 e1000_power_down_phy(adapter);
3316 return;
3317 }
3318
Auke Kokbc7f75f2007-09-17 12:30:59 -07003319 e1000_get_phy_info(hw);
3320
Bruce Allan918d7192009-06-02 11:28:20 +00003321 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3322 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003323 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003324 /*
3325 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003326 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003327 * different we would do if it failed
3328 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003329 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3330 phy_data &= ~IGP02E1000_PM_SPD;
3331 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3332 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003333}
3334
3335int e1000e_up(struct e1000_adapter *adapter)
3336{
3337 struct e1000_hw *hw = &adapter->hw;
3338
3339 /* hardware has been reset, we need to reload some things */
3340 e1000_configure(adapter);
3341
3342 clear_bit(__E1000_DOWN, &adapter->state);
3343
3344 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003345 if (adapter->msix_entries)
3346 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003347 e1000_irq_enable(adapter);
3348
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003349 netif_wake_queue(adapter->netdev);
3350
Auke Kokbc7f75f2007-09-17 12:30:59 -07003351 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003352 if (adapter->msix_entries)
3353 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3354 else
3355 ew32(ICS, E1000_ICS_LSC);
3356
Auke Kokbc7f75f2007-09-17 12:30:59 -07003357 return 0;
3358}
3359
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003360static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3361{
3362 struct e1000_hw *hw = &adapter->hw;
3363
3364 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3365 return;
3366
3367 /* flush pending descriptor writebacks to memory */
3368 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3369 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3370
3371 /* execute the writes immediately */
3372 e1e_flush();
3373}
3374
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003375static void e1000e_update_stats(struct e1000_adapter *adapter);
3376
Auke Kokbc7f75f2007-09-17 12:30:59 -07003377void e1000e_down(struct e1000_adapter *adapter)
3378{
3379 struct net_device *netdev = adapter->netdev;
3380 struct e1000_hw *hw = &adapter->hw;
3381 u32 tctl, rctl;
3382
Bruce Allanad680762008-03-28 09:15:03 -07003383 /*
3384 * signal that we're down so the interrupt handler does not
3385 * reschedule our watchdog timer
3386 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003387 set_bit(__E1000_DOWN, &adapter->state);
3388
3389 /* disable receives in the hardware */
3390 rctl = er32(RCTL);
3391 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3392 /* flush and sleep below */
3393
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003394 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003395
3396 /* disable transmits in the hardware */
3397 tctl = er32(TCTL);
3398 tctl &= ~E1000_TCTL_EN;
3399 ew32(TCTL, tctl);
3400 /* flush both disables and wait for them to finish */
3401 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003402 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003403
3404 napi_disable(&adapter->napi);
3405 e1000_irq_disable(adapter);
3406
3407 del_timer_sync(&adapter->watchdog_timer);
3408 del_timer_sync(&adapter->phy_info_timer);
3409
Auke Kokbc7f75f2007-09-17 12:30:59 -07003410 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003411
3412 spin_lock(&adapter->stats64_lock);
3413 e1000e_update_stats(adapter);
3414 spin_unlock(&adapter->stats64_lock);
3415
Auke Kokbc7f75f2007-09-17 12:30:59 -07003416 adapter->link_speed = 0;
3417 adapter->link_duplex = 0;
3418
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003419 if (!pci_channel_offline(adapter->pdev))
3420 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003421
3422 e1000e_flush_descriptors(adapter);
3423
Auke Kokbc7f75f2007-09-17 12:30:59 -07003424 e1000_clean_tx_ring(adapter);
3425 e1000_clean_rx_ring(adapter);
3426
3427 /*
3428 * TODO: for power management, we could drop the link and
3429 * pci_disable_device here.
3430 */
3431}
3432
3433void e1000e_reinit_locked(struct e1000_adapter *adapter)
3434{
3435 might_sleep();
3436 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003437 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003438 e1000e_down(adapter);
3439 e1000e_up(adapter);
3440 clear_bit(__E1000_RESETTING, &adapter->state);
3441}
3442
3443/**
3444 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3445 * @adapter: board private structure to initialize
3446 *
3447 * e1000_sw_init initializes the Adapter private data structure.
3448 * Fields are initialized based on PCI device information and
3449 * OS network device settings (MTU size).
3450 **/
3451static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3452{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003453 struct net_device *netdev = adapter->netdev;
3454
3455 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3456 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003457 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3458 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003459
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003460 spin_lock_init(&adapter->stats64_lock);
3461
Bruce Allan4662e822008-08-26 18:37:06 -07003462 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003463
Bruce Allan4662e822008-08-26 18:37:06 -07003464 if (e1000_alloc_queues(adapter))
3465 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003466
Auke Kokbc7f75f2007-09-17 12:30:59 -07003467 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003468 e1000_irq_disable(adapter);
3469
Auke Kokbc7f75f2007-09-17 12:30:59 -07003470 set_bit(__E1000_DOWN, &adapter->state);
3471 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003472}
3473
3474/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003475 * e1000_intr_msi_test - Interrupt Handler
3476 * @irq: interrupt number
3477 * @data: pointer to a network interface device structure
3478 **/
3479static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3480{
3481 struct net_device *netdev = data;
3482 struct e1000_adapter *adapter = netdev_priv(netdev);
3483 struct e1000_hw *hw = &adapter->hw;
3484 u32 icr = er32(ICR);
3485
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003486 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003487 if (icr & E1000_ICR_RXSEQ) {
3488 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3489 wmb();
3490 }
3491
3492 return IRQ_HANDLED;
3493}
3494
3495/**
3496 * e1000_test_msi_interrupt - Returns 0 for successful test
3497 * @adapter: board private struct
3498 *
3499 * code flow taken from tg3.c
3500 **/
3501static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3502{
3503 struct net_device *netdev = adapter->netdev;
3504 struct e1000_hw *hw = &adapter->hw;
3505 int err;
3506
3507 /* poll_enable hasn't been called yet, so don't need disable */
3508 /* clear any pending events */
3509 er32(ICR);
3510
3511 /* free the real vector and request a test handler */
3512 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003513 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003514
3515 /* Assume that the test fails, if it succeeds then the test
3516 * MSI irq handler will unset this flag */
3517 adapter->flags |= FLAG_MSI_TEST_FAILED;
3518
3519 err = pci_enable_msi(adapter->pdev);
3520 if (err)
3521 goto msi_test_failed;
3522
Joe Perchesa0607fd2009-11-18 23:29:17 -08003523 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003524 netdev->name, netdev);
3525 if (err) {
3526 pci_disable_msi(adapter->pdev);
3527 goto msi_test_failed;
3528 }
3529
3530 wmb();
3531
3532 e1000_irq_enable(adapter);
3533
3534 /* fire an unusual interrupt on the test handler */
3535 ew32(ICS, E1000_ICS_RXSEQ);
3536 e1e_flush();
3537 msleep(50);
3538
3539 e1000_irq_disable(adapter);
3540
3541 rmb();
3542
3543 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003544 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003545 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3546 } else
3547 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003548
3549 free_irq(adapter->pdev->irq, netdev);
3550 pci_disable_msi(adapter->pdev);
3551
Bruce Allanf8d59f72008-08-08 18:36:11 -07003552msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003553 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003554 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003555}
3556
3557/**
3558 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3559 * @adapter: board private struct
3560 *
3561 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3562 **/
3563static int e1000_test_msi(struct e1000_adapter *adapter)
3564{
3565 int err;
3566 u16 pci_cmd;
3567
3568 if (!(adapter->flags & FLAG_MSI_ENABLED))
3569 return 0;
3570
3571 /* disable SERR in case the MSI write causes a master abort */
3572 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003573 if (pci_cmd & PCI_COMMAND_SERR)
3574 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3575 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003576
3577 err = e1000_test_msi_interrupt(adapter);
3578
Dean Nelson36f24072010-06-29 18:12:05 +00003579 /* re-enable SERR */
3580 if (pci_cmd & PCI_COMMAND_SERR) {
3581 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3582 pci_cmd |= PCI_COMMAND_SERR;
3583 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3584 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003585
Bruce Allanf8d59f72008-08-08 18:36:11 -07003586 return err;
3587}
3588
3589/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003590 * e1000_open - Called when a network interface is made active
3591 * @netdev: network interface device structure
3592 *
3593 * Returns 0 on success, negative value on failure
3594 *
3595 * The open entry point is called when a network interface is made
3596 * active by the system (IFF_UP). At this point all resources needed
3597 * for transmit and receive operations are allocated, the interrupt
3598 * handler is registered with the OS, the watchdog timer is started,
3599 * and the stack is notified that the interface is ready.
3600 **/
3601static int e1000_open(struct net_device *netdev)
3602{
3603 struct e1000_adapter *adapter = netdev_priv(netdev);
3604 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003605 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003606 int err;
3607
3608 /* disallow open during test */
3609 if (test_bit(__E1000_TESTING, &adapter->state))
3610 return -EBUSY;
3611
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003612 pm_runtime_get_sync(&pdev->dev);
3613
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003614 netif_carrier_off(netdev);
3615
Auke Kokbc7f75f2007-09-17 12:30:59 -07003616 /* allocate transmit descriptors */
3617 err = e1000e_setup_tx_resources(adapter);
3618 if (err)
3619 goto err_setup_tx;
3620
3621 /* allocate receive descriptors */
3622 err = e1000e_setup_rx_resources(adapter);
3623 if (err)
3624 goto err_setup_rx;
3625
Bruce Allan11b08be2010-05-10 14:59:31 +00003626 /*
3627 * If AMT is enabled, let the firmware know that the network
3628 * interface is now open and reset the part to a known state.
3629 */
3630 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003631 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003632 e1000e_reset(adapter);
3633 }
3634
Auke Kokbc7f75f2007-09-17 12:30:59 -07003635 e1000e_power_up_phy(adapter);
3636
3637 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3638 if ((adapter->hw.mng_cookie.status &
3639 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3640 e1000_update_mng_vlan(adapter);
3641
Florian Micklerc128ec22010-08-02 14:27:00 +00003642 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003643 if ((adapter->flags & FLAG_HAS_ERT) ||
3644 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003645 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3646 PM_QOS_CPU_DMA_LATENCY,
3647 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003648
Bruce Allanad680762008-03-28 09:15:03 -07003649 /*
Bruce Allanad680762008-03-28 09:15:03 -07003650 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003651 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3652 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003653 * clean_rx handler before we do so.
3654 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003655 e1000_configure(adapter);
3656
3657 err = e1000_request_irq(adapter);
3658 if (err)
3659 goto err_req_irq;
3660
Bruce Allanf8d59f72008-08-08 18:36:11 -07003661 /*
3662 * Work around PCIe errata with MSI interrupts causing some chipsets to
3663 * ignore e1000e MSI messages, which means we need to test our MSI
3664 * interrupt now
3665 */
Bruce Allan4662e822008-08-26 18:37:06 -07003666 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003667 err = e1000_test_msi(adapter);
3668 if (err) {
3669 e_err("Interrupt allocation failed\n");
3670 goto err_req_irq;
3671 }
3672 }
3673
Auke Kokbc7f75f2007-09-17 12:30:59 -07003674 /* From here on the code is the same as e1000e_up() */
3675 clear_bit(__E1000_DOWN, &adapter->state);
3676
3677 napi_enable(&adapter->napi);
3678
3679 e1000_irq_enable(adapter);
3680
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003681 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003682
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003683 adapter->idle_check = true;
3684 pm_runtime_put(&pdev->dev);
3685
Auke Kokbc7f75f2007-09-17 12:30:59 -07003686 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003687 if (adapter->msix_entries)
3688 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3689 else
3690 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691
3692 return 0;
3693
3694err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003695 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696 e1000_power_down_phy(adapter);
3697 e1000e_free_rx_resources(adapter);
3698err_setup_rx:
3699 e1000e_free_tx_resources(adapter);
3700err_setup_tx:
3701 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003702 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003703
3704 return err;
3705}
3706
3707/**
3708 * e1000_close - Disables a network interface
3709 * @netdev: network interface device structure
3710 *
3711 * Returns 0, this is not allowed to fail
3712 *
3713 * The close entry point is called when an interface is de-activated
3714 * by the OS. The hardware is still under the drivers control, but
3715 * needs to be disabled. A global MAC reset is issued to stop the
3716 * hardware, and all transmit and receive resources are freed.
3717 **/
3718static int e1000_close(struct net_device *netdev)
3719{
3720 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003721 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003722
3723 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003724
3725 pm_runtime_get_sync(&pdev->dev);
3726
3727 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3728 e1000e_down(adapter);
3729 e1000_free_irq(adapter);
3730 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003731 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003732
3733 e1000e_free_tx_resources(adapter);
3734 e1000e_free_rx_resources(adapter);
3735
Bruce Allanad680762008-03-28 09:15:03 -07003736 /*
3737 * kill manageability vlan ID if supported, but not if a vlan with
3738 * the same ID is registered on the host OS (let 8021q kill it)
3739 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003740 if (adapter->hw.mng_cookie.status &
3741 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003742 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3743
Bruce Allanad680762008-03-28 09:15:03 -07003744 /*
3745 * If AMT is enabled, let the firmware know that the network
3746 * interface is now closed
3747 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003748 if ((adapter->flags & FLAG_HAS_AMT) &&
3749 !test_bit(__E1000_TESTING, &adapter->state))
3750 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003751
Bruce Allan828bac82010-09-29 21:39:37 +00003752 if ((adapter->flags & FLAG_HAS_ERT) ||
3753 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003754 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003755
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003756 pm_runtime_put_sync(&pdev->dev);
3757
Auke Kokbc7f75f2007-09-17 12:30:59 -07003758 return 0;
3759}
3760/**
3761 * e1000_set_mac - Change the Ethernet Address of the NIC
3762 * @netdev: network interface device structure
3763 * @p: pointer to an address structure
3764 *
3765 * Returns 0 on success, negative on failure
3766 **/
3767static int e1000_set_mac(struct net_device *netdev, void *p)
3768{
3769 struct e1000_adapter *adapter = netdev_priv(netdev);
3770 struct sockaddr *addr = p;
3771
3772 if (!is_valid_ether_addr(addr->sa_data))
3773 return -EADDRNOTAVAIL;
3774
3775 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3776 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3777
3778 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3779
3780 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3781 /* activate the work around */
3782 e1000e_set_laa_state_82571(&adapter->hw, 1);
3783
Bruce Allanad680762008-03-28 09:15:03 -07003784 /*
3785 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003786 * between the time RAR[0] gets clobbered and the time it
3787 * gets fixed (in e1000_watchdog), the actual LAA is in one
3788 * of the RARs and no incoming packets directed to this port
3789 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003790 * RAR[14]
3791 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003792 e1000e_rar_set(&adapter->hw,
3793 adapter->hw.mac.addr,
3794 adapter->hw.mac.rar_entry_count - 1);
3795 }
3796
3797 return 0;
3798}
3799
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003800/**
3801 * e1000e_update_phy_task - work thread to update phy
3802 * @work: pointer to our work struct
3803 *
3804 * this worker thread exists because we must acquire a
3805 * semaphore to read the phy, which we could msleep while
3806 * waiting for it, and we can't msleep in a timer.
3807 **/
3808static void e1000e_update_phy_task(struct work_struct *work)
3809{
3810 struct e1000_adapter *adapter = container_of(work,
3811 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003812
3813 if (test_bit(__E1000_DOWN, &adapter->state))
3814 return;
3815
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003816 e1000_get_phy_info(&adapter->hw);
3817}
3818
Bruce Allanad680762008-03-28 09:15:03 -07003819/*
3820 * Need to wait a few seconds after link up to get diagnostic information from
3821 * the phy
3822 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003823static void e1000_update_phy_info(unsigned long data)
3824{
3825 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003826
3827 if (test_bit(__E1000_DOWN, &adapter->state))
3828 return;
3829
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003830 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003831}
3832
3833/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003834 * e1000e_update_phy_stats - Update the PHY statistics counters
3835 * @adapter: board private structure
3836 **/
3837static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3838{
3839 struct e1000_hw *hw = &adapter->hw;
3840 s32 ret_val;
3841 u16 phy_data;
3842
3843 ret_val = hw->phy.ops.acquire(hw);
3844 if (ret_val)
3845 return;
3846
3847 hw->phy.addr = 1;
3848
3849#define HV_PHY_STATS_PAGE 778
3850 /*
3851 * A page set is expensive so check if already on desired page.
3852 * If not, set to the page with the PHY status registers.
3853 */
3854 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3855 &phy_data);
3856 if (ret_val)
3857 goto release;
3858 if (phy_data != (HV_PHY_STATS_PAGE << IGP_PAGE_SHIFT)) {
3859 ret_val = e1000e_write_phy_reg_mdic(hw,
3860 IGP01E1000_PHY_PAGE_SELECT,
3861 (HV_PHY_STATS_PAGE <<
3862 IGP_PAGE_SHIFT));
3863 if (ret_val)
3864 goto release;
3865 }
3866
3867 /* Read/clear the upper 16-bit registers and read/accumulate lower */
3868
3869 /* Single Collision Count */
3870 e1000e_read_phy_reg_mdic(hw, HV_SCC_UPPER & MAX_PHY_REG_ADDRESS,
3871 &phy_data);
3872 ret_val = e1000e_read_phy_reg_mdic(hw,
3873 HV_SCC_LOWER & MAX_PHY_REG_ADDRESS,
3874 &phy_data);
3875 if (!ret_val)
3876 adapter->stats.scc += phy_data;
3877
3878 /* Excessive Collision Count */
3879 e1000e_read_phy_reg_mdic(hw, HV_ECOL_UPPER & MAX_PHY_REG_ADDRESS,
3880 &phy_data);
3881 ret_val = e1000e_read_phy_reg_mdic(hw,
3882 HV_ECOL_LOWER & MAX_PHY_REG_ADDRESS,
3883 &phy_data);
3884 if (!ret_val)
3885 adapter->stats.ecol += phy_data;
3886
3887 /* Multiple Collision Count */
3888 e1000e_read_phy_reg_mdic(hw, HV_MCC_UPPER & MAX_PHY_REG_ADDRESS,
3889 &phy_data);
3890 ret_val = e1000e_read_phy_reg_mdic(hw,
3891 HV_MCC_LOWER & MAX_PHY_REG_ADDRESS,
3892 &phy_data);
3893 if (!ret_val)
3894 adapter->stats.mcc += phy_data;
3895
3896 /* Late Collision Count */
3897 e1000e_read_phy_reg_mdic(hw, HV_LATECOL_UPPER & MAX_PHY_REG_ADDRESS,
3898 &phy_data);
3899 ret_val = e1000e_read_phy_reg_mdic(hw,
3900 HV_LATECOL_LOWER &
3901 MAX_PHY_REG_ADDRESS,
3902 &phy_data);
3903 if (!ret_val)
3904 adapter->stats.latecol += phy_data;
3905
3906 /* Collision Count - also used for adaptive IFS */
3907 e1000e_read_phy_reg_mdic(hw, HV_COLC_UPPER & MAX_PHY_REG_ADDRESS,
3908 &phy_data);
3909 ret_val = e1000e_read_phy_reg_mdic(hw,
3910 HV_COLC_LOWER & MAX_PHY_REG_ADDRESS,
3911 &phy_data);
3912 if (!ret_val)
3913 hw->mac.collision_delta = phy_data;
3914
3915 /* Defer Count */
3916 e1000e_read_phy_reg_mdic(hw, HV_DC_UPPER & MAX_PHY_REG_ADDRESS,
3917 &phy_data);
3918 ret_val = e1000e_read_phy_reg_mdic(hw,
3919 HV_DC_LOWER & MAX_PHY_REG_ADDRESS,
3920 &phy_data);
3921 if (!ret_val)
3922 adapter->stats.dc += phy_data;
3923
3924 /* Transmit with no CRS */
3925 e1000e_read_phy_reg_mdic(hw, HV_TNCRS_UPPER & MAX_PHY_REG_ADDRESS,
3926 &phy_data);
3927 ret_val = e1000e_read_phy_reg_mdic(hw,
3928 HV_TNCRS_LOWER & MAX_PHY_REG_ADDRESS,
3929 &phy_data);
3930 if (!ret_val)
3931 adapter->stats.tncrs += phy_data;
3932
3933release:
3934 hw->phy.ops.release(hw);
3935}
3936
3937/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003938 * e1000e_update_stats - Update the board statistics counters
3939 * @adapter: board private structure
3940 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003941static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003942{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003943 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003944 struct e1000_hw *hw = &adapter->hw;
3945 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003946
3947 /*
3948 * Prevent stats update while adapter is being reset, or if the pci
3949 * connection is down.
3950 */
3951 if (adapter->link_speed == 0)
3952 return;
3953 if (pci_channel_offline(pdev))
3954 return;
3955
Auke Kokbc7f75f2007-09-17 12:30:59 -07003956 adapter->stats.crcerrs += er32(CRCERRS);
3957 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003958 adapter->stats.gorc += er32(GORCL);
3959 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003960 adapter->stats.bprc += er32(BPRC);
3961 adapter->stats.mprc += er32(MPRC);
3962 adapter->stats.roc += er32(ROC);
3963
Auke Kokbc7f75f2007-09-17 12:30:59 -07003964 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003965
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003966 /* Half-duplex statistics */
3967 if (adapter->link_duplex == HALF_DUPLEX) {
3968 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
3969 e1000e_update_phy_stats(adapter);
3970 } else {
3971 adapter->stats.scc += er32(SCC);
3972 adapter->stats.ecol += er32(ECOL);
3973 adapter->stats.mcc += er32(MCC);
3974 adapter->stats.latecol += er32(LATECOL);
3975 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003976
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003977 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003978
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003979 if ((hw->mac.type != e1000_82574) &&
3980 (hw->mac.type != e1000_82583))
3981 adapter->stats.tncrs += er32(TNCRS);
3982 }
3983 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003984 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003985
Auke Kokbc7f75f2007-09-17 12:30:59 -07003986 adapter->stats.xonrxc += er32(XONRXC);
3987 adapter->stats.xontxc += er32(XONTXC);
3988 adapter->stats.xoffrxc += er32(XOFFRXC);
3989 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003990 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003991 adapter->stats.gotc += er32(GOTCL);
3992 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003993 adapter->stats.rnbc += er32(RNBC);
3994 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003995
3996 adapter->stats.mptc += er32(MPTC);
3997 adapter->stats.bptc += er32(BPTC);
3998
3999 /* used for adaptive IFS */
4000
4001 hw->mac.tx_packet_delta = er32(TPT);
4002 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004003
4004 adapter->stats.algnerrc += er32(ALGNERRC);
4005 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004006 adapter->stats.cexterr += er32(CEXTERR);
4007 adapter->stats.tsctc += er32(TSCTC);
4008 adapter->stats.tsctfc += er32(TSCTFC);
4009
Auke Kokbc7f75f2007-09-17 12:30:59 -07004010 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004011 netdev->stats.multicast = adapter->stats.mprc;
4012 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004013
4014 /* Rx Errors */
4015
Bruce Allanad680762008-03-28 09:15:03 -07004016 /*
4017 * RLEC on some newer hardware can be incorrect so build
4018 * our own version based on RUC and ROC
4019 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004020 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004021 adapter->stats.crcerrs + adapter->stats.algnerrc +
4022 adapter->stats.ruc + adapter->stats.roc +
4023 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004024 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004025 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004026 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4027 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4028 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004029
4030 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004031 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004032 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004033 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4034 netdev->stats.tx_window_errors = adapter->stats.latecol;
4035 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004036
4037 /* Tx Dropped needs to be maintained elsewhere */
4038
Auke Kokbc7f75f2007-09-17 12:30:59 -07004039 /* Management Stats */
4040 adapter->stats.mgptc += er32(MGTPTC);
4041 adapter->stats.mgprc += er32(MGTPRC);
4042 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004043}
4044
Bruce Allan7c257692008-04-23 11:09:00 -07004045/**
4046 * e1000_phy_read_status - Update the PHY register status snapshot
4047 * @adapter: board private structure
4048 **/
4049static void e1000_phy_read_status(struct e1000_adapter *adapter)
4050{
4051 struct e1000_hw *hw = &adapter->hw;
4052 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004053
4054 if ((er32(STATUS) & E1000_STATUS_LU) &&
4055 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004056 int ret_val;
4057
Bruce Allan7c257692008-04-23 11:09:00 -07004058 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4059 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4060 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4061 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4062 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4063 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4064 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4065 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4066 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004067 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004068 } else {
4069 /*
4070 * Do not read PHY registers if link is not up
4071 * Set values to typical power-on defaults
4072 */
4073 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4074 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4075 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4076 BMSR_ERCAP);
4077 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4078 ADVERTISE_ALL | ADVERTISE_CSMA);
4079 phy->lpa = 0;
4080 phy->expansion = EXPANSION_ENABLENPAGE;
4081 phy->ctrl1000 = ADVERTISE_1000FULL;
4082 phy->stat1000 = 0;
4083 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4084 }
Bruce Allan7c257692008-04-23 11:09:00 -07004085}
4086
Auke Kokbc7f75f2007-09-17 12:30:59 -07004087static void e1000_print_link_info(struct e1000_adapter *adapter)
4088{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004089 struct e1000_hw *hw = &adapter->hw;
4090 u32 ctrl = er32(CTRL);
4091
Bruce Allan8f12fe82008-11-21 16:54:43 -08004092 /* Link status message must follow this format for user tools */
4093 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4094 "Flow Control: %s\n",
4095 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004096 adapter->link_speed,
4097 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004098 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004099 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004100 "Rx/Tx" :
4101 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4102 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004103}
4104
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004105static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004106{
4107 struct e1000_hw *hw = &adapter->hw;
4108 bool link_active = 0;
4109 s32 ret_val = 0;
4110
4111 /*
4112 * get_link_status is set on LSC (link status) interrupt or
4113 * Rx sequence error interrupt. get_link_status will stay
4114 * false until the check_for_link establishes link
4115 * for copper adapters ONLY
4116 */
4117 switch (hw->phy.media_type) {
4118 case e1000_media_type_copper:
4119 if (hw->mac.get_link_status) {
4120 ret_val = hw->mac.ops.check_for_link(hw);
4121 link_active = !hw->mac.get_link_status;
4122 } else {
4123 link_active = 1;
4124 }
4125 break;
4126 case e1000_media_type_fiber:
4127 ret_val = hw->mac.ops.check_for_link(hw);
4128 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4129 break;
4130 case e1000_media_type_internal_serdes:
4131 ret_val = hw->mac.ops.check_for_link(hw);
4132 link_active = adapter->hw.mac.serdes_has_link;
4133 break;
4134 default:
4135 case e1000_media_type_unknown:
4136 break;
4137 }
4138
4139 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4140 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4141 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004142 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004143 }
4144
4145 return link_active;
4146}
4147
4148static void e1000e_enable_receives(struct e1000_adapter *adapter)
4149{
4150 /* make sure the receive unit is started */
4151 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4152 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4153 struct e1000_hw *hw = &adapter->hw;
4154 u32 rctl = er32(RCTL);
4155 ew32(RCTL, rctl | E1000_RCTL_EN);
4156 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4157 }
4158}
4159
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004160static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4161{
4162 struct e1000_hw *hw = &adapter->hw;
4163
4164 /*
4165 * With 82574 controllers, PHY needs to be checked periodically
4166 * for hung state and reset, if two calls return true
4167 */
4168 if (e1000_check_phy_82574(hw))
4169 adapter->phy_hang_count++;
4170 else
4171 adapter->phy_hang_count = 0;
4172
4173 if (adapter->phy_hang_count > 1) {
4174 adapter->phy_hang_count = 0;
4175 schedule_work(&adapter->reset_task);
4176 }
4177}
4178
Auke Kokbc7f75f2007-09-17 12:30:59 -07004179/**
4180 * e1000_watchdog - Timer Call-back
4181 * @data: pointer to adapter cast into an unsigned long
4182 **/
4183static void e1000_watchdog(unsigned long data)
4184{
4185 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4186
4187 /* Do the rest outside of interrupt context */
4188 schedule_work(&adapter->watchdog_task);
4189
4190 /* TODO: make this use queue_delayed_work() */
4191}
4192
4193static void e1000_watchdog_task(struct work_struct *work)
4194{
4195 struct e1000_adapter *adapter = container_of(work,
4196 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004197 struct net_device *netdev = adapter->netdev;
4198 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004199 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004200 struct e1000_ring *tx_ring = adapter->tx_ring;
4201 struct e1000_hw *hw = &adapter->hw;
4202 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004203
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004204 if (test_bit(__E1000_DOWN, &adapter->state))
4205 return;
4206
David S. Millerb405e8d2010-02-04 22:31:41 -08004207 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004208 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004209 /* Cancel scheduled suspend requests. */
4210 pm_runtime_resume(netdev->dev.parent);
4211
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004212 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004213 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004214 }
4215
4216 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4217 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4218 e1000_update_mng_vlan(adapter);
4219
Auke Kokbc7f75f2007-09-17 12:30:59 -07004220 if (link) {
4221 if (!netif_carrier_ok(netdev)) {
4222 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004223
4224 /* Cancel scheduled suspend requests. */
4225 pm_runtime_resume(netdev->dev.parent);
4226
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004227 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004228 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004229 mac->ops.get_link_up_info(&adapter->hw,
4230 &adapter->link_speed,
4231 &adapter->link_duplex);
4232 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004233 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004234 * On supported PHYs, check for duplex mismatch only
4235 * if link has autonegotiated at 10/100 half
4236 */
4237 if ((hw->phy.type == e1000_phy_igp_3 ||
4238 hw->phy.type == e1000_phy_bm) &&
4239 (hw->mac.autoneg == true) &&
4240 (adapter->link_speed == SPEED_10 ||
4241 adapter->link_speed == SPEED_100) &&
4242 (adapter->link_duplex == HALF_DUPLEX)) {
4243 u16 autoneg_exp;
4244
4245 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4246
4247 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4248 e_info("Autonegotiated half duplex but"
4249 " link partner cannot autoneg. "
4250 " Try forcing full duplex if "
4251 "link gets many collisions.\n");
4252 }
4253
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004254 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004255 adapter->tx_timeout_factor = 1;
4256 switch (adapter->link_speed) {
4257 case SPEED_10:
4258 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004259 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004260 break;
4261 case SPEED_100:
4262 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004263 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004264 break;
4265 }
4266
Bruce Allanad680762008-03-28 09:15:03 -07004267 /*
4268 * workaround: re-program speed mode bit after
4269 * link-up event
4270 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004271 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4272 !txb2b) {
4273 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004274 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004275 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004276 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004277 }
4278
Bruce Allanad680762008-03-28 09:15:03 -07004279 /*
4280 * disable TSO for pcie and 10/100 speeds, to avoid
4281 * some hardware issues
4282 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004283 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4284 switch (adapter->link_speed) {
4285 case SPEED_10:
4286 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004287 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004288 netdev->features &= ~NETIF_F_TSO;
4289 netdev->features &= ~NETIF_F_TSO6;
4290 break;
4291 case SPEED_1000:
4292 netdev->features |= NETIF_F_TSO;
4293 netdev->features |= NETIF_F_TSO6;
4294 break;
4295 default:
4296 /* oops */
4297 break;
4298 }
4299 }
4300
Bruce Allanad680762008-03-28 09:15:03 -07004301 /*
4302 * enable transmits in the hardware, need to do this
4303 * after setting TARC(0)
4304 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004305 tctl = er32(TCTL);
4306 tctl |= E1000_TCTL_EN;
4307 ew32(TCTL, tctl);
4308
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004309 /*
4310 * Perform any post-link-up configuration before
4311 * reporting link up.
4312 */
4313 if (phy->ops.cfg_on_link_up)
4314 phy->ops.cfg_on_link_up(hw);
4315
Auke Kokbc7f75f2007-09-17 12:30:59 -07004316 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004317
4318 if (!test_bit(__E1000_DOWN, &adapter->state))
4319 mod_timer(&adapter->phy_info_timer,
4320 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004321 }
4322 } else {
4323 if (netif_carrier_ok(netdev)) {
4324 adapter->link_speed = 0;
4325 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004326 /* Link status message must follow this format */
4327 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4328 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004329 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004330 if (!test_bit(__E1000_DOWN, &adapter->state))
4331 mod_timer(&adapter->phy_info_timer,
4332 round_jiffies(jiffies + 2 * HZ));
4333
4334 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4335 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004336 else
4337 pm_schedule_suspend(netdev->dev.parent,
4338 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004339 }
4340 }
4341
4342link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004343 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004344 e1000e_update_stats(adapter);
4345
4346 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4347 adapter->tpt_old = adapter->stats.tpt;
4348 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4349 adapter->colc_old = adapter->stats.colc;
4350
Bruce Allan7c257692008-04-23 11:09:00 -07004351 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4352 adapter->gorc_old = adapter->stats.gorc;
4353 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4354 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004355 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004356
4357 e1000e_update_adaptive(&adapter->hw);
4358
Bruce Allan90da0662011-01-06 07:02:53 +00004359 if (!netif_carrier_ok(netdev) &&
4360 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4361 /*
4362 * We've lost link, so the controller stops DMA,
4363 * but we've got queued Tx work that's never going
4364 * to get done, so reset controller to flush Tx.
4365 * (Do the reset outside of interrupt context).
4366 */
Bruce Allan90da0662011-01-06 07:02:53 +00004367 schedule_work(&adapter->reset_task);
4368 /* return immediately since reset is imminent */
4369 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004370 }
4371
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004372 /* Simple mode for Interrupt Throttle Rate (ITR) */
4373 if (adapter->itr_setting == 4) {
4374 /*
4375 * Symmetric Tx/Rx gets a reduced ITR=2000;
4376 * Total asymmetrical Tx or Rx gets ITR=8000;
4377 * everyone else is between 2000-8000.
4378 */
4379 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4380 u32 dif = (adapter->gotc > adapter->gorc ?
4381 adapter->gotc - adapter->gorc :
4382 adapter->gorc - adapter->gotc) / 10000;
4383 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4384
4385 ew32(ITR, 1000000000 / (itr * 256));
4386 }
4387
Bruce Allanad680762008-03-28 09:15:03 -07004388 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004389 if (adapter->msix_entries)
4390 ew32(ICS, adapter->rx_ring->ims_val);
4391 else
4392 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004393
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004394 /* flush pending descriptors to memory before detecting Tx hang */
4395 e1000e_flush_descriptors(adapter);
4396
Auke Kokbc7f75f2007-09-17 12:30:59 -07004397 /* Force detection of hung controller every watchdog period */
4398 adapter->detect_tx_hung = 1;
4399
Bruce Allanad680762008-03-28 09:15:03 -07004400 /*
4401 * With 82571 controllers, LAA may be overwritten due to controller
4402 * reset from the other port. Set the appropriate LAA in RAR[0]
4403 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004404 if (e1000e_get_laa_state_82571(hw))
4405 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4406
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004407 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4408 e1000e_check_82574_phy_workaround(adapter);
4409
Auke Kokbc7f75f2007-09-17 12:30:59 -07004410 /* Reset the timer */
4411 if (!test_bit(__E1000_DOWN, &adapter->state))
4412 mod_timer(&adapter->watchdog_timer,
4413 round_jiffies(jiffies + 2 * HZ));
4414}
4415
4416#define E1000_TX_FLAGS_CSUM 0x00000001
4417#define E1000_TX_FLAGS_VLAN 0x00000002
4418#define E1000_TX_FLAGS_TSO 0x00000004
4419#define E1000_TX_FLAGS_IPV4 0x00000008
4420#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4421#define E1000_TX_FLAGS_VLAN_SHIFT 16
4422
4423static int e1000_tso(struct e1000_adapter *adapter,
4424 struct sk_buff *skb)
4425{
4426 struct e1000_ring *tx_ring = adapter->tx_ring;
4427 struct e1000_context_desc *context_desc;
4428 struct e1000_buffer *buffer_info;
4429 unsigned int i;
4430 u32 cmd_length = 0;
4431 u16 ipcse = 0, tucse, mss;
4432 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004433
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004434 if (!skb_is_gso(skb))
4435 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004436
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004437 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004438 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4439
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004440 if (err)
4441 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004442 }
4443
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004444 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4445 mss = skb_shinfo(skb)->gso_size;
4446 if (skb->protocol == htons(ETH_P_IP)) {
4447 struct iphdr *iph = ip_hdr(skb);
4448 iph->tot_len = 0;
4449 iph->check = 0;
4450 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4451 0, IPPROTO_TCP, 0);
4452 cmd_length = E1000_TXD_CMD_IP;
4453 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004454 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004455 ipv6_hdr(skb)->payload_len = 0;
4456 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4457 &ipv6_hdr(skb)->daddr,
4458 0, IPPROTO_TCP, 0);
4459 ipcse = 0;
4460 }
4461 ipcss = skb_network_offset(skb);
4462 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4463 tucss = skb_transport_offset(skb);
4464 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4465 tucse = 0;
4466
4467 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4468 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4469
4470 i = tx_ring->next_to_use;
4471 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4472 buffer_info = &tx_ring->buffer_info[i];
4473
4474 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4475 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4476 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4477 context_desc->upper_setup.tcp_fields.tucss = tucss;
4478 context_desc->upper_setup.tcp_fields.tucso = tucso;
4479 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4480 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4481 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4482 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4483
4484 buffer_info->time_stamp = jiffies;
4485 buffer_info->next_to_watch = i;
4486
4487 i++;
4488 if (i == tx_ring->count)
4489 i = 0;
4490 tx_ring->next_to_use = i;
4491
4492 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004493}
4494
4495static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4496{
4497 struct e1000_ring *tx_ring = adapter->tx_ring;
4498 struct e1000_context_desc *context_desc;
4499 struct e1000_buffer *buffer_info;
4500 unsigned int i;
4501 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004502 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004503 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004504
Dave Grahamaf807c82008-10-09 14:28:58 -07004505 if (skb->ip_summed != CHECKSUM_PARTIAL)
4506 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004507
Arthur Jones5f66f202009-03-19 01:13:08 +00004508 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4509 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4510 else
4511 protocol = skb->protocol;
4512
Arthur Jones3f518392009-03-20 15:56:35 -07004513 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004514 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004515 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4516 cmd_len |= E1000_TXD_CMD_TCP;
4517 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004518 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004519 /* XXX not handling all IPV6 headers */
4520 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4521 cmd_len |= E1000_TXD_CMD_TCP;
4522 break;
4523 default:
4524 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004525 e_warn("checksum_partial proto=%x!\n",
4526 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004527 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004528 }
4529
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004530 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004531
4532 i = tx_ring->next_to_use;
4533 buffer_info = &tx_ring->buffer_info[i];
4534 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4535
4536 context_desc->lower_setup.ip_config = 0;
4537 context_desc->upper_setup.tcp_fields.tucss = css;
4538 context_desc->upper_setup.tcp_fields.tucso =
4539 css + skb->csum_offset;
4540 context_desc->upper_setup.tcp_fields.tucse = 0;
4541 context_desc->tcp_seg_setup.data = 0;
4542 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4543
4544 buffer_info->time_stamp = jiffies;
4545 buffer_info->next_to_watch = i;
4546
4547 i++;
4548 if (i == tx_ring->count)
4549 i = 0;
4550 tx_ring->next_to_use = i;
4551
4552 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004553}
4554
4555#define E1000_MAX_PER_TXD 8192
4556#define E1000_MAX_TXD_PWR 12
4557
4558static int e1000_tx_map(struct e1000_adapter *adapter,
4559 struct sk_buff *skb, unsigned int first,
4560 unsigned int max_per_txd, unsigned int nr_frags,
4561 unsigned int mss)
4562{
4563 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004564 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004565 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004566 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004567 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004568 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004569
4570 i = tx_ring->next_to_use;
4571
4572 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004573 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004574 size = min(len, max_per_txd);
4575
Auke Kokbc7f75f2007-09-17 12:30:59 -07004576 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004577 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004578 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004579 buffer_info->dma = dma_map_single(&pdev->dev,
4580 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004581 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004582 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004583 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004584 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004585
4586 len -= size;
4587 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004588 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004589
4590 if (len) {
4591 i++;
4592 if (i == tx_ring->count)
4593 i = 0;
4594 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004595 }
4596
4597 for (f = 0; f < nr_frags; f++) {
4598 struct skb_frag_struct *frag;
4599
4600 frag = &skb_shinfo(skb)->frags[f];
4601 len = frag->size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004602 offset = frag->page_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004603
4604 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004605 i++;
4606 if (i == tx_ring->count)
4607 i = 0;
4608
Auke Kokbc7f75f2007-09-17 12:30:59 -07004609 buffer_info = &tx_ring->buffer_info[i];
4610 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004611
4612 buffer_info->length = size;
4613 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004614 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004615 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
Alexander Duyck03b13202009-12-02 16:45:31 +00004616 offset, size,
Nick Nunley0be3f552010-04-27 13:09:05 +00004617 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004618 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004619 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004620 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004621
4622 len -= size;
4623 offset += size;
4624 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004625 }
4626 }
4627
Bruce Allanaf667a22010-12-31 06:10:01 +00004628 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004629 /* multiply data chunks by size of headers */
4630 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4631
Auke Kokbc7f75f2007-09-17 12:30:59 -07004632 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004633 tx_ring->buffer_info[i].segs = segs;
4634 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004635 tx_ring->buffer_info[first].next_to_watch = i;
4636
4637 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004638
4639dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004640 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004641 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004642 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004643 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004644
4645 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004646 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004647 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004648 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004649 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004650 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004651 }
4652
4653 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004654}
4655
4656static void e1000_tx_queue(struct e1000_adapter *adapter,
4657 int tx_flags, int count)
4658{
4659 struct e1000_ring *tx_ring = adapter->tx_ring;
4660 struct e1000_tx_desc *tx_desc = NULL;
4661 struct e1000_buffer *buffer_info;
4662 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4663 unsigned int i;
4664
4665 if (tx_flags & E1000_TX_FLAGS_TSO) {
4666 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4667 E1000_TXD_CMD_TSE;
4668 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4669
4670 if (tx_flags & E1000_TX_FLAGS_IPV4)
4671 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4672 }
4673
4674 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4675 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4676 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4677 }
4678
4679 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4680 txd_lower |= E1000_TXD_CMD_VLE;
4681 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4682 }
4683
4684 i = tx_ring->next_to_use;
4685
Bruce Allan36b973d2010-11-24 07:42:43 +00004686 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004687 buffer_info = &tx_ring->buffer_info[i];
4688 tx_desc = E1000_TX_DESC(*tx_ring, i);
4689 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4690 tx_desc->lower.data =
4691 cpu_to_le32(txd_lower | buffer_info->length);
4692 tx_desc->upper.data = cpu_to_le32(txd_upper);
4693
4694 i++;
4695 if (i == tx_ring->count)
4696 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004697 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004698
4699 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4700
Bruce Allanad680762008-03-28 09:15:03 -07004701 /*
4702 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004703 * know there are new descriptors to fetch. (Only
4704 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004705 * such as IA-64).
4706 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004707 wmb();
4708
4709 tx_ring->next_to_use = i;
4710 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07004711 /*
4712 * we need this if more than one processor can write to our tail
4713 * at a time, it synchronizes IO on IA64/Altix systems
4714 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004715 mmiowb();
4716}
4717
4718#define MINIMUM_DHCP_PACKET_SIZE 282
4719static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4720 struct sk_buff *skb)
4721{
4722 struct e1000_hw *hw = &adapter->hw;
4723 u16 length, offset;
4724
4725 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004726 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4727 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004728 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4729 return 0;
4730 }
4731
4732 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4733 return 0;
4734
4735 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4736 return 0;
4737
4738 {
4739 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4740 struct udphdr *udp;
4741
4742 if (ip->protocol != IPPROTO_UDP)
4743 return 0;
4744
4745 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4746 if (ntohs(udp->dest) != 67)
4747 return 0;
4748
4749 offset = (u8 *)udp + 8 - skb->data;
4750 length = skb->len - offset;
4751 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4752 }
4753
4754 return 0;
4755}
4756
4757static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4758{
4759 struct e1000_adapter *adapter = netdev_priv(netdev);
4760
4761 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004762 /*
4763 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004764 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004765 * but since that doesn't exist yet, just open code it.
4766 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004767 smp_mb();
4768
Bruce Allanad680762008-03-28 09:15:03 -07004769 /*
4770 * We need to check again in a case another CPU has just
4771 * made room available.
4772 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004773 if (e1000_desc_unused(adapter->tx_ring) < size)
4774 return -EBUSY;
4775
4776 /* A reprieve! */
4777 netif_start_queue(netdev);
4778 ++adapter->restart_queue;
4779 return 0;
4780}
4781
4782static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4783{
4784 struct e1000_adapter *adapter = netdev_priv(netdev);
4785
4786 if (e1000_desc_unused(adapter->tx_ring) >= size)
4787 return 0;
4788 return __e1000_maybe_stop_tx(netdev, size);
4789}
4790
4791#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004792static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4793 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004794{
4795 struct e1000_adapter *adapter = netdev_priv(netdev);
4796 struct e1000_ring *tx_ring = adapter->tx_ring;
4797 unsigned int first;
4798 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4799 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4800 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004801 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004802 unsigned int nr_frags;
4803 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004804 int count = 0;
4805 int tso;
4806 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004807
4808 if (test_bit(__E1000_DOWN, &adapter->state)) {
4809 dev_kfree_skb_any(skb);
4810 return NETDEV_TX_OK;
4811 }
4812
4813 if (skb->len <= 0) {
4814 dev_kfree_skb_any(skb);
4815 return NETDEV_TX_OK;
4816 }
4817
4818 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004819 /*
4820 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004821 * make sure there is enough room in the FIFO before
4822 * initiating the DMA for each buffer. The calc is:
4823 * 4 = ceil(buffer len/mss). To make sure we don't
4824 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004825 * drops.
4826 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004827 if (mss) {
4828 u8 hdr_len;
4829 max_per_txd = min(mss << 2, max_per_txd);
4830 max_txd_pwr = fls(max_per_txd) - 1;
4831
Bruce Allanad680762008-03-28 09:15:03 -07004832 /*
4833 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4834 * points to just header, pull a few bytes of payload from
4835 * frags into skb->data
4836 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004837 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004838 /*
4839 * we do this workaround for ES2LAN, but it is un-necessary,
4840 * avoiding it could save a lot of cycles
4841 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004842 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004843 unsigned int pull_size;
4844
4845 pull_size = min((unsigned int)4, skb->data_len);
4846 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004847 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004848 dev_kfree_skb_any(skb);
4849 return NETDEV_TX_OK;
4850 }
Eric Dumazete743d312010-04-14 15:59:40 -07004851 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004852 }
4853 }
4854
4855 /* reserve a descriptor for the offload context */
4856 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4857 count++;
4858 count++;
4859
4860 count += TXD_USE_COUNT(len, max_txd_pwr);
4861
4862 nr_frags = skb_shinfo(skb)->nr_frags;
4863 for (f = 0; f < nr_frags; f++)
4864 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4865 max_txd_pwr);
4866
4867 if (adapter->hw.mac.tx_pkt_filtering)
4868 e1000_transfer_dhcp_info(adapter, skb);
4869
Bruce Allanad680762008-03-28 09:15:03 -07004870 /*
4871 * need: count + 2 desc gap to keep tail from touching
4872 * head, otherwise try next time
4873 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004874 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004875 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004876
Jesse Grosseab6d182010-10-20 13:56:03 +00004877 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004878 tx_flags |= E1000_TX_FLAGS_VLAN;
4879 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4880 }
4881
4882 first = tx_ring->next_to_use;
4883
4884 tso = e1000_tso(adapter, skb);
4885 if (tso < 0) {
4886 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004887 return NETDEV_TX_OK;
4888 }
4889
4890 if (tso)
4891 tx_flags |= E1000_TX_FLAGS_TSO;
4892 else if (e1000_tx_csum(adapter, skb))
4893 tx_flags |= E1000_TX_FLAGS_CSUM;
4894
Bruce Allanad680762008-03-28 09:15:03 -07004895 /*
4896 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004897 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004898 * no longer assume, we must.
4899 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004900 if (skb->protocol == htons(ETH_P_IP))
4901 tx_flags |= E1000_TX_FLAGS_IPV4;
4902
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004903 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004904 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004905 if (count) {
4906 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004907 /* Make sure there is space in the ring for the next send. */
4908 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4909
4910 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004911 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004912 tx_ring->buffer_info[first].time_stamp = 0;
4913 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004914 }
4915
Auke Kokbc7f75f2007-09-17 12:30:59 -07004916 return NETDEV_TX_OK;
4917}
4918
4919/**
4920 * e1000_tx_timeout - Respond to a Tx Hang
4921 * @netdev: network interface device structure
4922 **/
4923static void e1000_tx_timeout(struct net_device *netdev)
4924{
4925 struct e1000_adapter *adapter = netdev_priv(netdev);
4926
4927 /* Do the reset outside of interrupt context */
4928 adapter->tx_timeout_count++;
4929 schedule_work(&adapter->reset_task);
4930}
4931
4932static void e1000_reset_task(struct work_struct *work)
4933{
4934 struct e1000_adapter *adapter;
4935 adapter = container_of(work, struct e1000_adapter, reset_task);
4936
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004937 /* don't run the task if already down */
4938 if (test_bit(__E1000_DOWN, &adapter->state))
4939 return;
4940
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00004941 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4942 (adapter->flags & FLAG_RX_RESTART_NOW))) {
4943 e1000e_dump(adapter);
4944 e_err("Reset adapter\n");
4945 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004946 e1000e_reinit_locked(adapter);
4947}
4948
4949/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004950 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07004951 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004952 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07004953 *
4954 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004955 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004956struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
4957 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004958{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004959 struct e1000_adapter *adapter = netdev_priv(netdev);
4960
4961 memset(stats, 0, sizeof(struct rtnl_link_stats64));
4962 spin_lock(&adapter->stats64_lock);
4963 e1000e_update_stats(adapter);
4964 /* Fill out the OS statistics structure */
4965 stats->rx_bytes = adapter->stats.gorc;
4966 stats->rx_packets = adapter->stats.gprc;
4967 stats->tx_bytes = adapter->stats.gotc;
4968 stats->tx_packets = adapter->stats.gptc;
4969 stats->multicast = adapter->stats.mprc;
4970 stats->collisions = adapter->stats.colc;
4971
4972 /* Rx Errors */
4973
4974 /*
4975 * RLEC on some newer hardware can be incorrect so build
4976 * our own version based on RUC and ROC
4977 */
4978 stats->rx_errors = adapter->stats.rxerrc +
4979 adapter->stats.crcerrs + adapter->stats.algnerrc +
4980 adapter->stats.ruc + adapter->stats.roc +
4981 adapter->stats.cexterr;
4982 stats->rx_length_errors = adapter->stats.ruc +
4983 adapter->stats.roc;
4984 stats->rx_crc_errors = adapter->stats.crcerrs;
4985 stats->rx_frame_errors = adapter->stats.algnerrc;
4986 stats->rx_missed_errors = adapter->stats.mpc;
4987
4988 /* Tx Errors */
4989 stats->tx_errors = adapter->stats.ecol +
4990 adapter->stats.latecol;
4991 stats->tx_aborted_errors = adapter->stats.ecol;
4992 stats->tx_window_errors = adapter->stats.latecol;
4993 stats->tx_carrier_errors = adapter->stats.tncrs;
4994
4995 /* Tx Dropped needs to be maintained elsewhere */
4996
4997 spin_unlock(&adapter->stats64_lock);
4998 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004999}
5000
5001/**
5002 * e1000_change_mtu - Change the Maximum Transfer Unit
5003 * @netdev: network interface device structure
5004 * @new_mtu: new value for maximum frame size
5005 *
5006 * Returns 0 on success, negative on failure
5007 **/
5008static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5009{
5010 struct e1000_adapter *adapter = netdev_priv(netdev);
5011 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5012
Bruce Allan2adc55c2009-06-02 11:28:58 +00005013 /* Jumbo frame support */
5014 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5015 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5016 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005017 return -EINVAL;
5018 }
5019
Bruce Allan2adc55c2009-06-02 11:28:58 +00005020 /* Supported frame sizes */
5021 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5022 (max_frame > adapter->max_hw_frame_size)) {
5023 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005024 return -EINVAL;
5025 }
5026
Bruce Allana1ce6472010-09-22 17:16:40 +00005027 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5028 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5029 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5030 (new_mtu > ETH_DATA_LEN)) {
5031 e_err("Jumbo Frames not supported on 82579 when CRC "
5032 "stripping is disabled.\n");
5033 return -EINVAL;
5034 }
5035
Bruce Allan6f461f62010-04-27 03:33:04 +00005036 /* 82573 Errata 17 */
5037 if (((adapter->hw.mac.type == e1000_82573) ||
5038 (adapter->hw.mac.type == e1000_82574)) &&
5039 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5040 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5041 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5042 }
5043
Auke Kokbc7f75f2007-09-17 12:30:59 -07005044 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005045 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005046 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005047 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005048 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5049 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005050 if (netif_running(netdev))
5051 e1000e_down(adapter);
5052
Bruce Allanad680762008-03-28 09:15:03 -07005053 /*
5054 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005055 * means we reserve 2 more, this pushes us to allocate from the next
5056 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005057 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005058 * However with the new *_jumbo_rx* routines, jumbo receives will use
5059 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005060 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005061
Jesse Brandeburg99261462010-01-22 22:56:16 +00005062 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005063 adapter->rx_buffer_len = 2048;
5064 else
5065 adapter->rx_buffer_len = 4096;
5066
5067 /* adjust allocation if LPE protects us, and we aren't using SBP */
5068 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5069 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5070 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005071 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005072
Auke Kokbc7f75f2007-09-17 12:30:59 -07005073 if (netif_running(netdev))
5074 e1000e_up(adapter);
5075 else
5076 e1000e_reset(adapter);
5077
5078 clear_bit(__E1000_RESETTING, &adapter->state);
5079
5080 return 0;
5081}
5082
5083static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5084 int cmd)
5085{
5086 struct e1000_adapter *adapter = netdev_priv(netdev);
5087 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005088
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005089 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005090 return -EOPNOTSUPP;
5091
5092 switch (cmd) {
5093 case SIOCGMIIPHY:
5094 data->phy_id = adapter->hw.phy.addr;
5095 break;
5096 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005097 e1000_phy_read_status(adapter);
5098
Bruce Allan7c257692008-04-23 11:09:00 -07005099 switch (data->reg_num & 0x1F) {
5100 case MII_BMCR:
5101 data->val_out = adapter->phy_regs.bmcr;
5102 break;
5103 case MII_BMSR:
5104 data->val_out = adapter->phy_regs.bmsr;
5105 break;
5106 case MII_PHYSID1:
5107 data->val_out = (adapter->hw.phy.id >> 16);
5108 break;
5109 case MII_PHYSID2:
5110 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5111 break;
5112 case MII_ADVERTISE:
5113 data->val_out = adapter->phy_regs.advertise;
5114 break;
5115 case MII_LPA:
5116 data->val_out = adapter->phy_regs.lpa;
5117 break;
5118 case MII_EXPANSION:
5119 data->val_out = adapter->phy_regs.expansion;
5120 break;
5121 case MII_CTRL1000:
5122 data->val_out = adapter->phy_regs.ctrl1000;
5123 break;
5124 case MII_STAT1000:
5125 data->val_out = adapter->phy_regs.stat1000;
5126 break;
5127 case MII_ESTATUS:
5128 data->val_out = adapter->phy_regs.estatus;
5129 break;
5130 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005131 return -EIO;
5132 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005133 break;
5134 case SIOCSMIIREG:
5135 default:
5136 return -EOPNOTSUPP;
5137 }
5138 return 0;
5139}
5140
5141static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5142{
5143 switch (cmd) {
5144 case SIOCGMIIPHY:
5145 case SIOCGMIIREG:
5146 case SIOCSMIIREG:
5147 return e1000_mii_ioctl(netdev, ifr, cmd);
5148 default:
5149 return -EOPNOTSUPP;
5150 }
5151}
5152
Bruce Allana4f58f52009-06-02 11:29:18 +00005153static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5154{
5155 struct e1000_hw *hw = &adapter->hw;
5156 u32 i, mac_reg;
5157 u16 phy_reg;
5158 int retval = 0;
5159
5160 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005161 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005162
5163 /* copy MAC MTA to PHY MTA */
5164 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5165 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5166 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
5167 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
5168 }
5169
5170 /* configure PHY Rx Control register */
5171 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
5172 mac_reg = er32(RCTL);
5173 if (mac_reg & E1000_RCTL_UPE)
5174 phy_reg |= BM_RCTL_UPE;
5175 if (mac_reg & E1000_RCTL_MPE)
5176 phy_reg |= BM_RCTL_MPE;
5177 phy_reg &= ~(BM_RCTL_MO_MASK);
5178 if (mac_reg & E1000_RCTL_MO_3)
5179 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5180 << BM_RCTL_MO_SHIFT);
5181 if (mac_reg & E1000_RCTL_BAM)
5182 phy_reg |= BM_RCTL_BAM;
5183 if (mac_reg & E1000_RCTL_PMCF)
5184 phy_reg |= BM_RCTL_PMCF;
5185 mac_reg = er32(CTRL);
5186 if (mac_reg & E1000_CTRL_RFCE)
5187 phy_reg |= BM_RCTL_RFCE;
5188 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
5189
5190 /* enable PHY wakeup in MAC register */
5191 ew32(WUFC, wufc);
5192 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5193
5194 /* configure and enable PHY wakeup in PHY registers */
5195 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
5196 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5197
5198 /* activate PHY wakeup */
Bruce Allan94d81862009-11-20 23:25:26 +00005199 retval = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005200 if (retval) {
5201 e_err("Could not acquire PHY\n");
5202 return retval;
5203 }
5204 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
5205 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
5206 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
5207 if (retval) {
5208 e_err("Could not read PHY page 769\n");
5209 goto out;
5210 }
5211 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5212 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
5213 if (retval)
5214 e_err("Could not set PHY Host Wakeup bit\n");
5215out:
Bruce Allan94d81862009-11-20 23:25:26 +00005216 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005217
5218 return retval;
5219}
5220
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005221static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5222 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005223{
5224 struct net_device *netdev = pci_get_drvdata(pdev);
5225 struct e1000_adapter *adapter = netdev_priv(netdev);
5226 struct e1000_hw *hw = &adapter->hw;
5227 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005228 /* Runtime suspend should only enable wakeup for link changes */
5229 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005230 int retval = 0;
5231
5232 netif_device_detach(netdev);
5233
5234 if (netif_running(netdev)) {
5235 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5236 e1000e_down(adapter);
5237 e1000_free_irq(adapter);
5238 }
Bruce Allan4662e822008-08-26 18:37:06 -07005239 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005240
5241 retval = pci_save_state(pdev);
5242 if (retval)
5243 return retval;
5244
5245 status = er32(STATUS);
5246 if (status & E1000_STATUS_LU)
5247 wufc &= ~E1000_WUFC_LNKC;
5248
5249 if (wufc) {
5250 e1000_setup_rctl(adapter);
5251 e1000_set_multi(netdev);
5252
5253 /* turn on all-multi mode if wake on multicast is enabled */
5254 if (wufc & E1000_WUFC_MC) {
5255 rctl = er32(RCTL);
5256 rctl |= E1000_RCTL_MPE;
5257 ew32(RCTL, rctl);
5258 }
5259
5260 ctrl = er32(CTRL);
5261 /* advertise wake from D3Cold */
5262 #define E1000_CTRL_ADVD3WUC 0x00100000
5263 /* phy power management enable */
5264 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005265 ctrl |= E1000_CTRL_ADVD3WUC;
5266 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5267 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005268 ew32(CTRL, ctrl);
5269
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005270 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5271 adapter->hw.phy.media_type ==
5272 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005273 /* keep the laser running in D3 */
5274 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005275 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005276 ew32(CTRL_EXT, ctrl_ext);
5277 }
5278
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005279 if (adapter->flags & FLAG_IS_ICH)
5280 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
5281
Auke Kokbc7f75f2007-09-17 12:30:59 -07005282 /* Allow time for pending master requests to run */
5283 e1000e_disable_pcie_master(&adapter->hw);
5284
Bruce Allan82776a42009-08-14 14:35:33 +00005285 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005286 /* enable wakeup by the PHY */
5287 retval = e1000_init_phy_wakeup(adapter, wufc);
5288 if (retval)
5289 return retval;
5290 } else {
5291 /* enable wakeup by the MAC */
5292 ew32(WUFC, wufc);
5293 ew32(WUC, E1000_WUC_PME_EN);
5294 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005295 } else {
5296 ew32(WUC, 0);
5297 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005298 }
5299
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005300 *enable_wake = !!wufc;
5301
Auke Kokbc7f75f2007-09-17 12:30:59 -07005302 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005303 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5304 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005305 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005306
5307 if (adapter->hw.phy.type == e1000_phy_igp_3)
5308 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5309
Bruce Allanad680762008-03-28 09:15:03 -07005310 /*
5311 * Release control of h/w to f/w. If f/w is AMT enabled, this
5312 * would have already happened in close and is redundant.
5313 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005314 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005315
5316 pci_disable_device(pdev);
5317
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005318 return 0;
5319}
5320
5321static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5322{
5323 if (sleep && wake) {
5324 pci_prepare_to_sleep(pdev);
5325 return;
5326 }
5327
5328 pci_wake_from_d3(pdev, wake);
5329 pci_set_power_state(pdev, PCI_D3hot);
5330}
5331
5332static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5333 bool wake)
5334{
5335 struct net_device *netdev = pci_get_drvdata(pdev);
5336 struct e1000_adapter *adapter = netdev_priv(netdev);
5337
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005338 /*
5339 * The pci-e switch on some quad port adapters will report a
5340 * correctable error when the MAC transitions from D0 to D3. To
5341 * prevent this we need to mask off the correctable errors on the
5342 * downstream port of the pci-e switch.
5343 */
5344 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5345 struct pci_dev *us_dev = pdev->bus->self;
5346 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
5347 u16 devctl;
5348
5349 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5350 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5351 (devctl & ~PCI_EXP_DEVCTL_CERE));
5352
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005353 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005354
5355 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5356 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005357 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005358 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005359}
5360
Bruce Allan6f461f62010-04-27 03:33:04 +00005361#ifdef CONFIG_PCIEASPM
5362static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5363{
5364 pci_disable_link_state(pdev, state);
5365}
5366#else
5367static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005368{
5369 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005370 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005371
5372 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005373 * Both device and parent should have the same ASPM setting.
5374 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005375 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005376 pos = pci_pcie_cap(pdev);
5377 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5378 reg16 &= ~state;
5379 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5380
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005381 if (!pdev->bus->self)
5382 return;
5383
Bruce Allan6f461f62010-04-27 03:33:04 +00005384 pos = pci_pcie_cap(pdev->bus->self);
5385 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5386 reg16 &= ~state;
5387 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5388}
5389#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005390static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005391{
5392 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5393 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5394 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5395
5396 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005397}
5398
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005399#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005400static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005401{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005402 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005403}
5404
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005405static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005406{
5407 struct net_device *netdev = pci_get_drvdata(pdev);
5408 struct e1000_adapter *adapter = netdev_priv(netdev);
5409 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005410 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005411 u32 err;
5412
Bruce Allan78cd29d2011-03-24 03:09:03 +00005413 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5414 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5415 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5416 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5417 if (aspm_disable_flag)
5418 e1000e_disable_aspm(pdev, aspm_disable_flag);
5419
Auke Kokbc7f75f2007-09-17 12:30:59 -07005420 pci_set_power_state(pdev, PCI_D0);
5421 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005422 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005423
Bruce Allan4662e822008-08-26 18:37:06 -07005424 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005425 if (netif_running(netdev)) {
5426 err = e1000_request_irq(adapter);
5427 if (err)
5428 return err;
5429 }
5430
5431 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005432
5433 /* report the system wakeup cause from S3/S4 */
5434 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5435 u16 phy_data;
5436
5437 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5438 if (phy_data) {
5439 e_info("PHY Wakeup cause - %s\n",
5440 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5441 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5442 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5443 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5444 phy_data & E1000_WUS_LNKC ? "Link Status "
5445 " Change" : "other");
5446 }
5447 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5448 } else {
5449 u32 wus = er32(WUS);
5450 if (wus) {
5451 e_info("MAC Wakeup cause - %s\n",
5452 wus & E1000_WUS_EX ? "Unicast Packet" :
5453 wus & E1000_WUS_MC ? "Multicast Packet" :
5454 wus & E1000_WUS_BC ? "Broadcast Packet" :
5455 wus & E1000_WUS_MAG ? "Magic Packet" :
5456 wus & E1000_WUS_LNKC ? "Link Status Change" :
5457 "other");
5458 }
5459 ew32(WUS, ~0);
5460 }
5461
Auke Kokbc7f75f2007-09-17 12:30:59 -07005462 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005463
Bruce Allancd791612010-05-10 14:59:51 +00005464 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005465
5466 if (netif_running(netdev))
5467 e1000e_up(adapter);
5468
5469 netif_device_attach(netdev);
5470
Bruce Allanad680762008-03-28 09:15:03 -07005471 /*
5472 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005473 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005474 * under the control of the driver.
5475 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005476 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005477 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005478
5479 return 0;
5480}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005481
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005482#ifdef CONFIG_PM_SLEEP
5483static int e1000_suspend(struct device *dev)
5484{
5485 struct pci_dev *pdev = to_pci_dev(dev);
5486 int retval;
5487 bool wake;
5488
5489 retval = __e1000_shutdown(pdev, &wake, false);
5490 if (!retval)
5491 e1000_complete_shutdown(pdev, true, wake);
5492
5493 return retval;
5494}
5495
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005496static int e1000_resume(struct device *dev)
5497{
5498 struct pci_dev *pdev = to_pci_dev(dev);
5499 struct net_device *netdev = pci_get_drvdata(pdev);
5500 struct e1000_adapter *adapter = netdev_priv(netdev);
5501
5502 if (e1000e_pm_ready(adapter))
5503 adapter->idle_check = true;
5504
5505 return __e1000_resume(pdev);
5506}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005507#endif /* CONFIG_PM_SLEEP */
5508
5509#ifdef CONFIG_PM_RUNTIME
5510static int e1000_runtime_suspend(struct device *dev)
5511{
5512 struct pci_dev *pdev = to_pci_dev(dev);
5513 struct net_device *netdev = pci_get_drvdata(pdev);
5514 struct e1000_adapter *adapter = netdev_priv(netdev);
5515
5516 if (e1000e_pm_ready(adapter)) {
5517 bool wake;
5518
5519 __e1000_shutdown(pdev, &wake, true);
5520 }
5521
5522 return 0;
5523}
5524
5525static int e1000_idle(struct device *dev)
5526{
5527 struct pci_dev *pdev = to_pci_dev(dev);
5528 struct net_device *netdev = pci_get_drvdata(pdev);
5529 struct e1000_adapter *adapter = netdev_priv(netdev);
5530
5531 if (!e1000e_pm_ready(adapter))
5532 return 0;
5533
5534 if (adapter->idle_check) {
5535 adapter->idle_check = false;
5536 if (!e1000e_has_link(adapter))
5537 pm_schedule_suspend(dev, MSEC_PER_SEC);
5538 }
5539
5540 return -EBUSY;
5541}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005542
5543static int e1000_runtime_resume(struct device *dev)
5544{
5545 struct pci_dev *pdev = to_pci_dev(dev);
5546 struct net_device *netdev = pci_get_drvdata(pdev);
5547 struct e1000_adapter *adapter = netdev_priv(netdev);
5548
5549 if (!e1000e_pm_ready(adapter))
5550 return 0;
5551
5552 adapter->idle_check = !dev->power.runtime_auto;
5553 return __e1000_resume(pdev);
5554}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005555#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005556#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005557
5558static void e1000_shutdown(struct pci_dev *pdev)
5559{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005560 bool wake = false;
5561
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005562 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005563
5564 if (system_state == SYSTEM_POWER_OFF)
5565 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005566}
5567
5568#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005569
5570static irqreturn_t e1000_intr_msix(int irq, void *data)
5571{
5572 struct net_device *netdev = data;
5573 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005574
5575 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005576 int vector, msix_irq;
5577
Dongdong Deng147b2c82010-11-16 19:50:15 -08005578 vector = 0;
5579 msix_irq = adapter->msix_entries[vector].vector;
5580 disable_irq(msix_irq);
5581 e1000_intr_msix_rx(msix_irq, netdev);
5582 enable_irq(msix_irq);
5583
5584 vector++;
5585 msix_irq = adapter->msix_entries[vector].vector;
5586 disable_irq(msix_irq);
5587 e1000_intr_msix_tx(msix_irq, netdev);
5588 enable_irq(msix_irq);
5589
5590 vector++;
5591 msix_irq = adapter->msix_entries[vector].vector;
5592 disable_irq(msix_irq);
5593 e1000_msix_other(msix_irq, netdev);
5594 enable_irq(msix_irq);
5595 }
5596
5597 return IRQ_HANDLED;
5598}
5599
Auke Kokbc7f75f2007-09-17 12:30:59 -07005600/*
5601 * Polling 'interrupt' - used by things like netconsole to send skbs
5602 * without having to re-enable interrupts. It's not called while
5603 * the interrupt routine is executing.
5604 */
5605static void e1000_netpoll(struct net_device *netdev)
5606{
5607 struct e1000_adapter *adapter = netdev_priv(netdev);
5608
Dongdong Deng147b2c82010-11-16 19:50:15 -08005609 switch (adapter->int_mode) {
5610 case E1000E_INT_MODE_MSIX:
5611 e1000_intr_msix(adapter->pdev->irq, netdev);
5612 break;
5613 case E1000E_INT_MODE_MSI:
5614 disable_irq(adapter->pdev->irq);
5615 e1000_intr_msi(adapter->pdev->irq, netdev);
5616 enable_irq(adapter->pdev->irq);
5617 break;
5618 default: /* E1000E_INT_MODE_LEGACY */
5619 disable_irq(adapter->pdev->irq);
5620 e1000_intr(adapter->pdev->irq, netdev);
5621 enable_irq(adapter->pdev->irq);
5622 break;
5623 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005624}
5625#endif
5626
5627/**
5628 * e1000_io_error_detected - called when PCI error is detected
5629 * @pdev: Pointer to PCI device
5630 * @state: The current pci connection state
5631 *
5632 * This function is called after a PCI bus error affecting
5633 * this device has been detected.
5634 */
5635static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5636 pci_channel_state_t state)
5637{
5638 struct net_device *netdev = pci_get_drvdata(pdev);
5639 struct e1000_adapter *adapter = netdev_priv(netdev);
5640
5641 netif_device_detach(netdev);
5642
Mike Masonc93b5a72009-06-30 12:45:53 +00005643 if (state == pci_channel_io_perm_failure)
5644 return PCI_ERS_RESULT_DISCONNECT;
5645
Auke Kokbc7f75f2007-09-17 12:30:59 -07005646 if (netif_running(netdev))
5647 e1000e_down(adapter);
5648 pci_disable_device(pdev);
5649
5650 /* Request a slot slot reset. */
5651 return PCI_ERS_RESULT_NEED_RESET;
5652}
5653
5654/**
5655 * e1000_io_slot_reset - called after the pci bus has been reset.
5656 * @pdev: Pointer to PCI device
5657 *
5658 * Restart the card from scratch, as if from a cold-boot. Implementation
5659 * resembles the first-half of the e1000_resume routine.
5660 */
5661static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5662{
5663 struct net_device *netdev = pci_get_drvdata(pdev);
5664 struct e1000_adapter *adapter = netdev_priv(netdev);
5665 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005666 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005667 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005668 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005669
Bruce Allan78cd29d2011-03-24 03:09:03 +00005670 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5671 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005672 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005673 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5674 if (aspm_disable_flag)
5675 e1000e_disable_aspm(pdev, aspm_disable_flag);
5676
Bruce Allanf0f422e2008-08-04 17:21:53 -07005677 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005678 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005679 dev_err(&pdev->dev,
5680 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005681 result = PCI_ERS_RESULT_DISCONNECT;
5682 } else {
5683 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005684 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005685 pci_restore_state(pdev);
5686
5687 pci_enable_wake(pdev, PCI_D3hot, 0);
5688 pci_enable_wake(pdev, PCI_D3cold, 0);
5689
5690 e1000e_reset(adapter);
5691 ew32(WUS, ~0);
5692 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005693 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005694
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005695 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005696
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005697 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005698}
5699
5700/**
5701 * e1000_io_resume - called when traffic can start flowing again.
5702 * @pdev: Pointer to PCI device
5703 *
5704 * This callback is called when the error recovery driver tells us that
5705 * its OK to resume normal operation. Implementation resembles the
5706 * second-half of the e1000_resume routine.
5707 */
5708static void e1000_io_resume(struct pci_dev *pdev)
5709{
5710 struct net_device *netdev = pci_get_drvdata(pdev);
5711 struct e1000_adapter *adapter = netdev_priv(netdev);
5712
Bruce Allancd791612010-05-10 14:59:51 +00005713 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005714
5715 if (netif_running(netdev)) {
5716 if (e1000e_up(adapter)) {
5717 dev_err(&pdev->dev,
5718 "can't bring device back up after reset\n");
5719 return;
5720 }
5721 }
5722
5723 netif_device_attach(netdev);
5724
Bruce Allanad680762008-03-28 09:15:03 -07005725 /*
5726 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005727 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005728 * under the control of the driver.
5729 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005730 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005731 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005732
5733}
5734
5735static void e1000_print_device_info(struct e1000_adapter *adapter)
5736{
5737 struct e1000_hw *hw = &adapter->hw;
5738 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005739 u32 ret_val;
5740 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005741
5742 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005743 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005744 /* bus width */
5745 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5746 "Width x1"),
5747 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005748 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005749 e_info("Intel(R) PRO/%s Network Connection\n",
5750 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005751 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5752 E1000_PBANUM_LENGTH);
5753 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005754 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005755 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5756 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005757}
5758
Auke Kok10aa4c02008-08-04 17:21:20 -07005759static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5760{
5761 struct e1000_hw *hw = &adapter->hw;
5762 int ret_val;
5763 u16 buf = 0;
5764
5765 if (hw->mac.type != e1000_82573)
5766 return;
5767
5768 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005769 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005770 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005771 dev_warn(&adapter->pdev->dev,
5772 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005773 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005774}
5775
Stephen Hemminger651c2462008-11-19 21:57:48 -08005776static const struct net_device_ops e1000e_netdev_ops = {
5777 .ndo_open = e1000_open,
5778 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005779 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005780 .ndo_get_stats64 = e1000e_get_stats64,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005781 .ndo_set_multicast_list = e1000_set_multi,
5782 .ndo_set_mac_address = e1000_set_mac,
5783 .ndo_change_mtu = e1000_change_mtu,
5784 .ndo_do_ioctl = e1000_ioctl,
5785 .ndo_tx_timeout = e1000_tx_timeout,
5786 .ndo_validate_addr = eth_validate_addr,
5787
Stephen Hemminger651c2462008-11-19 21:57:48 -08005788 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5789 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5790#ifdef CONFIG_NET_POLL_CONTROLLER
5791 .ndo_poll_controller = e1000_netpoll,
5792#endif
5793};
5794
Auke Kokbc7f75f2007-09-17 12:30:59 -07005795/**
5796 * e1000_probe - Device Initialization Routine
5797 * @pdev: PCI device information struct
5798 * @ent: entry in e1000_pci_tbl
5799 *
5800 * Returns 0 on success, negative on failure
5801 *
5802 * e1000_probe initializes an adapter identified by a pci_dev structure.
5803 * The OS initialization, configuring of the adapter private structure,
5804 * and a hardware reset occur.
5805 **/
5806static int __devinit e1000_probe(struct pci_dev *pdev,
5807 const struct pci_device_id *ent)
5808{
5809 struct net_device *netdev;
5810 struct e1000_adapter *adapter;
5811 struct e1000_hw *hw;
5812 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005813 resource_size_t mmio_start, mmio_len;
5814 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005815
5816 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005817 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005818 int i, err, pci_using_dac;
5819 u16 eeprom_data = 0;
5820 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5821
Bruce Allan78cd29d2011-03-24 03:09:03 +00005822 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
5823 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005824 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005825 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5826 if (aspm_disable_flag)
5827 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005828
Bruce Allanf0f422e2008-08-04 17:21:53 -07005829 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005830 if (err)
5831 return err;
5832
5833 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005834 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005835 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005836 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005837 if (!err)
5838 pci_using_dac = 1;
5839 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005840 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005841 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005842 err = dma_set_coherent_mask(&pdev->dev,
5843 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005844 if (err) {
5845 dev_err(&pdev->dev, "No usable DMA "
5846 "configuration, aborting\n");
5847 goto err_dma;
5848 }
5849 }
5850 }
5851
Arjan van de Vene8de1482008-10-22 19:55:31 -07005852 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005853 pci_select_bars(pdev, IORESOURCE_MEM),
5854 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005855 if (err)
5856 goto err_pci_reg;
5857
Xiaotian Feng68eac462009-08-14 14:35:52 +00005858 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005859 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005860
Auke Kokbc7f75f2007-09-17 12:30:59 -07005861 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005862 /* PCI config space info */
5863 err = pci_save_state(pdev);
5864 if (err)
5865 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005866
5867 err = -ENOMEM;
5868 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5869 if (!netdev)
5870 goto err_alloc_etherdev;
5871
Auke Kokbc7f75f2007-09-17 12:30:59 -07005872 SET_NETDEV_DEV(netdev, &pdev->dev);
5873
Tom Herbertf85e4df2010-05-05 14:03:32 +00005874 netdev->irq = pdev->irq;
5875
Auke Kokbc7f75f2007-09-17 12:30:59 -07005876 pci_set_drvdata(pdev, netdev);
5877 adapter = netdev_priv(netdev);
5878 hw = &adapter->hw;
5879 adapter->netdev = netdev;
5880 adapter->pdev = pdev;
5881 adapter->ei = ei;
5882 adapter->pba = ei->pba;
5883 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005884 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005885 adapter->hw.adapter = adapter;
5886 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005887 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005888 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5889
5890 mmio_start = pci_resource_start(pdev, 0);
5891 mmio_len = pci_resource_len(pdev, 0);
5892
5893 err = -EIO;
5894 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5895 if (!adapter->hw.hw_addr)
5896 goto err_ioremap;
5897
5898 if ((adapter->flags & FLAG_HAS_FLASH) &&
5899 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5900 flash_start = pci_resource_start(pdev, 1);
5901 flash_len = pci_resource_len(pdev, 1);
5902 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5903 if (!adapter->hw.flash_address)
5904 goto err_flashmap;
5905 }
5906
5907 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005908 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005909 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005910 netdev->watchdog_timeo = 5 * HZ;
5911 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005912 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5913
5914 netdev->mem_start = mmio_start;
5915 netdev->mem_end = mmio_start + mmio_len;
5916
5917 adapter->bd_number = cards_found++;
5918
Bruce Allan4662e822008-08-26 18:37:06 -07005919 e1000e_check_options(adapter);
5920
Auke Kokbc7f75f2007-09-17 12:30:59 -07005921 /* setup adapter struct */
5922 err = e1000_sw_init(adapter);
5923 if (err)
5924 goto err_sw_init;
5925
Auke Kokbc7f75f2007-09-17 12:30:59 -07005926 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5927 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5928 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5929
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005930 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005931 if (err)
5932 goto err_hw_init;
5933
Bruce Allan4a770352008-10-01 17:18:35 -07005934 if ((adapter->flags & FLAG_IS_ICH) &&
5935 (adapter->flags & FLAG_READ_ONLY_NVM))
5936 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5937
Auke Kokbc7f75f2007-09-17 12:30:59 -07005938 hw->mac.ops.get_bus_info(&adapter->hw);
5939
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005940 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005941
5942 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005943 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005944 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5945 adapter->hw.phy.disable_polarity_correction = 0;
5946 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5947 }
5948
5949 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005950 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005951
5952 netdev->features = NETIF_F_SG |
5953 NETIF_F_HW_CSUM |
5954 NETIF_F_HW_VLAN_TX |
5955 NETIF_F_HW_VLAN_RX;
5956
5957 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5958 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5959
5960 netdev->features |= NETIF_F_TSO;
5961 netdev->features |= NETIF_F_TSO6;
5962
Jeff Kirshera5136e22008-06-05 04:07:28 -07005963 netdev->vlan_features |= NETIF_F_TSO;
5964 netdev->vlan_features |= NETIF_F_TSO6;
5965 netdev->vlan_features |= NETIF_F_HW_CSUM;
5966 netdev->vlan_features |= NETIF_F_SG;
5967
Yi Zou7b872a52010-09-22 17:57:58 +00005968 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005969 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00005970 netdev->vlan_features |= NETIF_F_HIGHDMA;
5971 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005972
Auke Kokbc7f75f2007-09-17 12:30:59 -07005973 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5974 adapter->flags |= FLAG_MNG_PT_ENABLED;
5975
Bruce Allanad680762008-03-28 09:15:03 -07005976 /*
5977 * before reading the NVM, reset the controller to
5978 * put the device in a known good starting state
5979 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005980 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5981
5982 /*
5983 * systems with ASPM and others may see the checksum fail on the first
5984 * attempt. Let's give it a few tries
5985 */
5986 for (i = 0;; i++) {
5987 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5988 break;
5989 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005990 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005991 err = -EIO;
5992 goto err_eeprom;
5993 }
5994 }
5995
Auke Kok10aa4c02008-08-04 17:21:20 -07005996 e1000_eeprom_checks(adapter);
5997
Bruce Allan608f8a02010-01-13 02:04:58 +00005998 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005999 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006000 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006001
6002 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6003 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6004
6005 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006006 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006007 err = -EIO;
6008 goto err_eeprom;
6009 }
6010
6011 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006012 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006013 adapter->watchdog_timer.data = (unsigned long) adapter;
6014
6015 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006016 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006017 adapter->phy_info_timer.data = (unsigned long) adapter;
6018
6019 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6020 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006021 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6022 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006023 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006024
Auke Kokbc7f75f2007-09-17 12:30:59 -07006025 /* Initialize link parameters. User can change them with ethtool */
6026 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07006027 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006028 adapter->hw.fc.requested_mode = e1000_fc_default;
6029 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006030 adapter->hw.phy.autoneg_advertised = 0x2f;
6031
6032 /* ring size defaults */
6033 adapter->rx_ring->count = 256;
6034 adapter->tx_ring->count = 256;
6035
6036 /*
6037 * Initial Wake on LAN setting - If APM wake is enabled in
6038 * the EEPROM, enable the ACPI Magic Packet filter
6039 */
6040 if (adapter->flags & FLAG_APME_IN_WUC) {
6041 /* APME bit in EEPROM is mapped to WUC.APME */
6042 eeprom_data = er32(WUC);
6043 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006044 if ((hw->mac.type > e1000_ich10lan) &&
6045 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006046 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006047 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6048 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6049 (adapter->hw.bus.func == 1))
6050 e1000_read_nvm(&adapter->hw,
6051 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6052 else
6053 e1000_read_nvm(&adapter->hw,
6054 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6055 }
6056
6057 /* fetch WoL from EEPROM */
6058 if (eeprom_data & eeprom_apme_mask)
6059 adapter->eeprom_wol |= E1000_WUFC_MAG;
6060
6061 /*
6062 * now that we have the eeprom settings, apply the special cases
6063 * where the eeprom may be wrong or the board simply won't support
6064 * wake on lan on a particular port
6065 */
6066 if (!(adapter->flags & FLAG_HAS_WOL))
6067 adapter->eeprom_wol = 0;
6068
6069 /* initialize the wol settings based on the eeprom settings */
6070 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006071 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006072
Bruce Allan84527592008-11-21 17:00:22 -08006073 /* save off EEPROM version number */
6074 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6075
Auke Kokbc7f75f2007-09-17 12:30:59 -07006076 /* reset the hardware with the new settings */
6077 e1000e_reset(adapter);
6078
Bruce Allanad680762008-03-28 09:15:03 -07006079 /*
6080 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006081 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006082 * under the control of the driver.
6083 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006084 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006085 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006086
Bruce Allane0dc4f12011-01-06 14:29:50 +00006087 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006088 err = register_netdev(netdev);
6089 if (err)
6090 goto err_register;
6091
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006092 /* carrier off reporting is important to ethtool even BEFORE open */
6093 netif_carrier_off(netdev);
6094
Auke Kokbc7f75f2007-09-17 12:30:59 -07006095 e1000_print_device_info(adapter);
6096
Alan Sternf3ec4f82010-06-08 15:23:51 -04006097 if (pci_dev_run_wake(pdev))
6098 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006099
Auke Kokbc7f75f2007-09-17 12:30:59 -07006100 return 0;
6101
6102err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006103 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006104 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006105err_eeprom:
6106 if (!e1000_check_reset_block(&adapter->hw))
6107 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006108err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006109 kfree(adapter->tx_ring);
6110 kfree(adapter->rx_ring);
6111err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006112 if (adapter->hw.flash_address)
6113 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006114 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006115err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006116 iounmap(adapter->hw.hw_addr);
6117err_ioremap:
6118 free_netdev(netdev);
6119err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006120 pci_release_selected_regions(pdev,
6121 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006122err_pci_reg:
6123err_dma:
6124 pci_disable_device(pdev);
6125 return err;
6126}
6127
6128/**
6129 * e1000_remove - Device Removal Routine
6130 * @pdev: PCI device information struct
6131 *
6132 * e1000_remove is called by the PCI subsystem to alert the driver
6133 * that it should release a PCI device. The could be caused by a
6134 * Hot-Plug event, or because the driver is going to be removed from
6135 * memory.
6136 **/
6137static void __devexit e1000_remove(struct pci_dev *pdev)
6138{
6139 struct net_device *netdev = pci_get_drvdata(pdev);
6140 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006141 bool down = test_bit(__E1000_DOWN, &adapter->state);
6142
Bruce Allanad680762008-03-28 09:15:03 -07006143 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006144 * The timers may be rescheduled, so explicitly disable them
6145 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006146 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006147 if (!down)
6148 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006149 del_timer_sync(&adapter->watchdog_timer);
6150 del_timer_sync(&adapter->phy_info_timer);
6151
Bruce Allan41cec6f2009-11-20 23:28:56 +00006152 cancel_work_sync(&adapter->reset_task);
6153 cancel_work_sync(&adapter->watchdog_task);
6154 cancel_work_sync(&adapter->downshift_task);
6155 cancel_work_sync(&adapter->update_phy_task);
6156 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006157
Bruce Allan17f208d2009-12-01 15:47:22 +00006158 if (!(netdev->flags & IFF_UP))
6159 e1000_power_down_phy(adapter);
6160
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006161 /* Don't lie to e1000_close() down the road. */
6162 if (!down)
6163 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006164 unregister_netdev(netdev);
6165
Alan Sternf3ec4f82010-06-08 15:23:51 -04006166 if (pci_dev_run_wake(pdev))
6167 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006168
Bruce Allanad680762008-03-28 09:15:03 -07006169 /*
6170 * Release control of h/w to f/w. If f/w is AMT enabled, this
6171 * would have already happened in close and is redundant.
6172 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006173 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006174
Bruce Allan4662e822008-08-26 18:37:06 -07006175 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006176 kfree(adapter->tx_ring);
6177 kfree(adapter->rx_ring);
6178
6179 iounmap(adapter->hw.hw_addr);
6180 if (adapter->hw.flash_address)
6181 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006182 pci_release_selected_regions(pdev,
6183 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006184
6185 free_netdev(netdev);
6186
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006187 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006188 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006189
Auke Kokbc7f75f2007-09-17 12:30:59 -07006190 pci_disable_device(pdev);
6191}
6192
6193/* PCI Error Recovery (ERS) */
6194static struct pci_error_handlers e1000_err_handler = {
6195 .error_detected = e1000_io_error_detected,
6196 .slot_reset = e1000_io_slot_reset,
6197 .resume = e1000_io_resume,
6198};
6199
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006200static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006201 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6202 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6203 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6204 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6205 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6206 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006207 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6208 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6209 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006210
Auke Kokbc7f75f2007-09-17 12:30:59 -07006211 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6212 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6213 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6214 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006215
Auke Kokbc7f75f2007-09-17 12:30:59 -07006216 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6217 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6218 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006219
Bruce Allan4662e822008-08-26 18:37:06 -07006220 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006221 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006222 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006223
Auke Kokbc7f75f2007-09-17 12:30:59 -07006224 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6225 board_80003es2lan },
6226 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6227 board_80003es2lan },
6228 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6229 board_80003es2lan },
6230 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6231 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006232
Auke Kokbc7f75f2007-09-17 12:30:59 -07006233 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6234 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6235 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6236 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6237 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6238 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6239 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006240 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006241
Auke Kokbc7f75f2007-09-17 12:30:59 -07006242 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6243 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6244 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6245 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6246 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006247 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006248 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6249 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6250 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6251
6252 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6253 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6254 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006255
Bruce Allanf4187b52008-08-26 18:36:50 -07006256 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6257 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006258 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006259
Bruce Allana4f58f52009-06-02 11:29:18 +00006260 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6261 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6262 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6263 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6264
Bruce Alland3738bb2010-06-16 13:27:28 +00006265 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6266 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6267
Auke Kokbc7f75f2007-09-17 12:30:59 -07006268 { } /* terminate list */
6269};
6270MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6271
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006272#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006273static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006274 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6275 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6276 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006277};
David S. Millere50208a2010-03-16 23:36:24 -07006278#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006279
Auke Kokbc7f75f2007-09-17 12:30:59 -07006280/* PCI Device API Driver */
6281static struct pci_driver e1000_driver = {
6282 .name = e1000e_driver_name,
6283 .id_table = e1000_pci_tbl,
6284 .probe = e1000_probe,
6285 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006286#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006287 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006288#endif
6289 .shutdown = e1000_shutdown,
6290 .err_handler = &e1000_err_handler
6291};
6292
6293/**
6294 * e1000_init_module - Driver Registration Routine
6295 *
6296 * e1000_init_module is the first routine called when the driver is
6297 * loaded. All it does is register with the PCI subsystem.
6298 **/
6299static int __init e1000_init_module(void)
6300{
6301 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006302 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6303 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006304 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006305 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006306
Auke Kokbc7f75f2007-09-17 12:30:59 -07006307 return ret;
6308}
6309module_init(e1000_init_module);
6310
6311/**
6312 * e1000_exit_module - Driver Exit Cleanup Routine
6313 *
6314 * e1000_exit_module is called just before the driver is removed
6315 * from memory.
6316 **/
6317static void __exit e1000_exit_module(void)
6318{
6319 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006320}
6321module_exit(e1000_exit_module);
6322
6323
6324MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6325MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6326MODULE_LICENSE("GPL");
6327MODULE_VERSION(DRV_VERSION);
6328
6329/* e1000_main.c */