blob: 4353ad56cf166d1e4b2939a303b6358004326d00 [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>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000034#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070035#include <linux/pci.h>
36#include <linux/vmalloc.h>
37#include <linux/pagemap.h>
38#include <linux/delay.h>
39#include <linux/netdevice.h>
40#include <linux/tcp.h>
41#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070043#include <net/checksum.h>
44#include <net/ip6_checksum.h>
45#include <linux/mii.h>
46#include <linux/ethtool.h>
47#include <linux/if_vlan.h>
48#include <linux/cpu.h>
49#include <linux/smp.h>
Bruce Allan97ac8ca2008-04-29 09:16:05 -070050#include <linux/pm_qos_params.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000051#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000052#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040053#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070054
55#include "e1000.h"
56
Bruce Allanb3ccf262011-05-19 01:53:41 +000057#define DRV_EXTRAVERSION "-k"
Bruce Allanc14c6432010-06-16 13:28:34 +000058
Bruce Allanb3ccf262011-05-19 01:53:41 +000059#define DRV_VERSION "1.3.16" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070060char e1000e_driver_name[] = "e1000e";
61const char e1000e_driver_version[] = DRV_VERSION;
62
Bruce Allan78cd29d2011-03-24 03:09:03 +000063static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
64
Auke Kokbc7f75f2007-09-17 12:30:59 -070065static const struct e1000_info *e1000_info_tbl[] = {
66 [board_82571] = &e1000_82571_info,
67 [board_82572] = &e1000_82572_info,
68 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070069 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000070 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070071 [board_80003es2lan] = &e1000_es2_info,
72 [board_ich8lan] = &e1000_ich8_info,
73 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070074 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000075 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000076 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070077};
78
Taku Izumi84f4ee92010-04-27 14:39:08 +000079struct e1000_reg_info {
80 u32 ofs;
81 char *name;
82};
83
Bruce Allanaf667a22010-12-31 06:10:01 +000084#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
85#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
86#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
87#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
88#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000089
Bruce Allanaf667a22010-12-31 06:10:01 +000090#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
91#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
92#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
93#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
94#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000095
96static const struct e1000_reg_info e1000_reg_info_tbl[] = {
97
98 /* General Registers */
99 {E1000_CTRL, "CTRL"},
100 {E1000_STATUS, "STATUS"},
101 {E1000_CTRL_EXT, "CTRL_EXT"},
102
103 /* Interrupt Registers */
104 {E1000_ICR, "ICR"},
105
Bruce Allanaf667a22010-12-31 06:10:01 +0000106 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000107 {E1000_RCTL, "RCTL"},
108 {E1000_RDLEN, "RDLEN"},
109 {E1000_RDH, "RDH"},
110 {E1000_RDT, "RDT"},
111 {E1000_RDTR, "RDTR"},
112 {E1000_RXDCTL(0), "RXDCTL"},
113 {E1000_ERT, "ERT"},
114 {E1000_RDBAL, "RDBAL"},
115 {E1000_RDBAH, "RDBAH"},
116 {E1000_RDFH, "RDFH"},
117 {E1000_RDFT, "RDFT"},
118 {E1000_RDFHS, "RDFHS"},
119 {E1000_RDFTS, "RDFTS"},
120 {E1000_RDFPC, "RDFPC"},
121
Bruce Allanaf667a22010-12-31 06:10:01 +0000122 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000123 {E1000_TCTL, "TCTL"},
124 {E1000_TDBAL, "TDBAL"},
125 {E1000_TDBAH, "TDBAH"},
126 {E1000_TDLEN, "TDLEN"},
127 {E1000_TDH, "TDH"},
128 {E1000_TDT, "TDT"},
129 {E1000_TIDV, "TIDV"},
130 {E1000_TXDCTL(0), "TXDCTL"},
131 {E1000_TADV, "TADV"},
132 {E1000_TARC(0), "TARC"},
133 {E1000_TDFH, "TDFH"},
134 {E1000_TDFT, "TDFT"},
135 {E1000_TDFHS, "TDFHS"},
136 {E1000_TDFTS, "TDFTS"},
137 {E1000_TDFPC, "TDFPC"},
138
139 /* List Terminator */
140 {}
141};
142
143/*
144 * e1000_regdump - register printout routine
145 */
146static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
147{
148 int n = 0;
149 char rname[16];
150 u32 regs[8];
151
152 switch (reginfo->ofs) {
153 case E1000_RXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_RXDCTL(n));
156 break;
157 case E1000_TXDCTL(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TXDCTL(n));
160 break;
161 case E1000_TARC(0):
162 for (n = 0; n < 2; n++)
163 regs[n] = __er32(hw, E1000_TARC(n));
164 break;
165 default:
166 printk(KERN_INFO "%-15s %08x\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000167 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000168 return;
169 }
170
171 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
172 printk(KERN_INFO "%-15s ", rname);
173 for (n = 0; n < 2; n++)
174 printk(KERN_CONT "%08x ", regs[n]);
175 printk(KERN_CONT "\n");
176}
177
Taku Izumi84f4ee92010-04-27 14:39:08 +0000178/*
Bruce Allanaf667a22010-12-31 06:10:01 +0000179 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Taku Izumi84f4ee92010-04-27 14:39:08 +0000180 */
181static void e1000e_dump(struct e1000_adapter *adapter)
182{
183 struct net_device *netdev = adapter->netdev;
184 struct e1000_hw *hw = &adapter->hw;
185 struct e1000_reg_info *reginfo;
186 struct e1000_ring *tx_ring = adapter->tx_ring;
187 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000188 struct my_u0 {
189 u64 a;
190 u64 b;
191 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000192 struct e1000_buffer *buffer_info;
193 struct e1000_ring *rx_ring = adapter->rx_ring;
194 union e1000_rx_desc_packet_split *rx_desc_ps;
195 struct e1000_rx_desc *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000196 struct my_u1 {
197 u64 a;
198 u64 b;
199 u64 c;
200 u64 d;
201 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000202 u32 staterr;
203 int i = 0;
204
205 if (!netif_msg_hw(adapter))
206 return;
207
208 /* Print netdevice Info */
209 if (netdev) {
210 dev_info(&adapter->pdev->dev, "Net device Info\n");
211 printk(KERN_INFO "Device Name state "
Bruce Allanaf667a22010-12-31 06:10:01 +0000212 "trans_start last_rx\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000213 printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000214 netdev->name, netdev->state, netdev->trans_start,
215 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000216 }
217
218 /* Print Registers */
219 dev_info(&adapter->pdev->dev, "Register Dump\n");
220 printk(KERN_INFO " Register Name Value\n");
221 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
222 reginfo->name; reginfo++) {
223 e1000_regdump(hw, reginfo);
224 }
225
Bruce Allanaf667a22010-12-31 06:10:01 +0000226 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000227 if (!netdev || !netif_running(netdev))
228 goto exit;
229
Bruce Allanaf667a22010-12-31 06:10:01 +0000230 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000231 printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000232 " leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000233 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
234 printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000235 0, tx_ring->next_to_use, tx_ring->next_to_clean,
236 (unsigned long long)buffer_info->dma,
237 buffer_info->length,
238 buffer_info->next_to_watch,
239 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000240
Bruce Allanaf667a22010-12-31 06:10:01 +0000241 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000242 if (!netif_msg_tx_done(adapter))
243 goto rx_ring_summary;
244
Bruce Allanaf667a22010-12-31 06:10:01 +0000245 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000246
247 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
248 *
249 * Legacy Transmit Descriptor
250 * +--------------------------------------------------------------+
251 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
252 * +--------------------------------------------------------------+
253 * 8 | Special | CSS | Status | CMD | CSO | Length |
254 * +--------------------------------------------------------------+
255 * 63 48 47 36 35 32 31 24 23 16 15 0
256 *
257 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
258 * 63 48 47 40 39 32 31 16 15 8 7 0
259 * +----------------------------------------------------------------+
260 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
261 * +----------------------------------------------------------------+
262 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
263 * +----------------------------------------------------------------+
264 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
265 *
266 * Extended Data Descriptor (DTYP=0x1)
267 * +----------------------------------------------------------------+
268 * 0 | Buffer Address [63:0] |
269 * +----------------------------------------------------------------+
270 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
271 * +----------------------------------------------------------------+
272 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
273 */
274 printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000275 " [bi->dma ] leng ntw timestamp bi->skb "
276 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000277 printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000278 " [bi->dma ] leng ntw timestamp bi->skb "
279 "<-- Ext Context format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000280 printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000281 " [bi->dma ] leng ntw timestamp bi->skb "
282 "<-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000283 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
284 tx_desc = E1000_TX_DESC(*tx_ring, i);
285 buffer_info = &tx_ring->buffer_info[i];
286 u0 = (struct my_u0 *)tx_desc;
287 printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000288 "%04X %3X %016llX %p",
289 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
290 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), i,
Bruce Allan8eb64e62010-06-29 18:12:30 +0000291 (unsigned long long)le64_to_cpu(u0->a),
292 (unsigned long long)le64_to_cpu(u0->b),
293 (unsigned long long)buffer_info->dma,
294 buffer_info->length, buffer_info->next_to_watch,
295 (unsigned long long)buffer_info->time_stamp,
Taku Izumi84f4ee92010-04-27 14:39:08 +0000296 buffer_info->skb);
297 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
298 printk(KERN_CONT " NTC/U\n");
299 else if (i == tx_ring->next_to_use)
300 printk(KERN_CONT " NTU\n");
301 else if (i == tx_ring->next_to_clean)
302 printk(KERN_CONT " NTC\n");
303 else
304 printk(KERN_CONT "\n");
305
306 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
307 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Bruce Allanaf667a22010-12-31 06:10:01 +0000308 16, 1, phys_to_virt(buffer_info->dma),
309 buffer_info->length, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000310 }
311
Bruce Allanaf667a22010-12-31 06:10:01 +0000312 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000313rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000314 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000315 printk(KERN_INFO "Queue [NTU] [NTC]\n");
316 printk(KERN_INFO " %5d %5X %5X\n", 0,
Bruce Allanaf667a22010-12-31 06:10:01 +0000317 rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000318
Bruce Allanaf667a22010-12-31 06:10:01 +0000319 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000320 if (!netif_msg_rx_status(adapter))
321 goto exit;
322
Bruce Allanaf667a22010-12-31 06:10:01 +0000323 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000324 switch (adapter->rx_ps_pages) {
325 case 1:
326 case 2:
327 case 3:
328 /* [Extended] Packet Split Receive Descriptor Format
329 *
330 * +-----------------------------------------------------+
331 * 0 | Buffer Address 0 [63:0] |
332 * +-----------------------------------------------------+
333 * 8 | Buffer Address 1 [63:0] |
334 * +-----------------------------------------------------+
335 * 16 | Buffer Address 2 [63:0] |
336 * +-----------------------------------------------------+
337 * 24 | Buffer Address 3 [63:0] |
338 * +-----------------------------------------------------+
339 */
340 printk(KERN_INFO "R [desc] [buffer 0 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000341 "[buffer 1 63:0 ] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000342 "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] "
343 "[bi->skb] <-- Ext Pkt Split format\n");
344 /* [Extended] Receive Descriptor (Write-Back) Format
345 *
346 * 63 48 47 32 31 13 12 8 7 4 3 0
347 * +------------------------------------------------------+
348 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
349 * | Checksum | Ident | | Queue | | Type |
350 * +------------------------------------------------------+
351 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
352 * +------------------------------------------------------+
353 * 63 48 47 32 31 20 19 0
354 */
355 printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000356 "[vl l0 ee es] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000357 "[ l3 l2 l1 hs] [reserved ] ---------------- "
358 "[bi->skb] <-- Ext Rx Write-Back format\n");
359 for (i = 0; i < rx_ring->count; i++) {
360 buffer_info = &rx_ring->buffer_info[i];
361 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
362 u1 = (struct my_u1 *)rx_desc_ps;
363 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000364 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000365 if (staterr & E1000_RXD_STAT_DD) {
366 /* Descriptor Done */
367 printk(KERN_INFO "RWB[0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000368 "%016llX %016llX %016llX "
369 "---------------- %p", i,
370 (unsigned long long)le64_to_cpu(u1->a),
371 (unsigned long long)le64_to_cpu(u1->b),
372 (unsigned long long)le64_to_cpu(u1->c),
373 (unsigned long long)le64_to_cpu(u1->d),
374 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000375 } else {
376 printk(KERN_INFO "R [0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000377 "%016llX %016llX %016llX %016llX %p", i,
378 (unsigned long long)le64_to_cpu(u1->a),
379 (unsigned long long)le64_to_cpu(u1->b),
380 (unsigned long long)le64_to_cpu(u1->c),
381 (unsigned long long)le64_to_cpu(u1->d),
382 (unsigned long long)buffer_info->dma,
383 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000384
385 if (netif_msg_pktdata(adapter))
386 print_hex_dump(KERN_INFO, "",
387 DUMP_PREFIX_ADDRESS, 16, 1,
388 phys_to_virt(buffer_info->dma),
389 adapter->rx_ps_bsize0, true);
390 }
391
392 if (i == rx_ring->next_to_use)
393 printk(KERN_CONT " NTU\n");
394 else if (i == rx_ring->next_to_clean)
395 printk(KERN_CONT " NTC\n");
396 else
397 printk(KERN_CONT "\n");
398 }
399 break;
400 default:
401 case 0:
402 /* Legacy Receive Descriptor Format
403 *
404 * +-----------------------------------------------------+
405 * | Buffer Address [63:0] |
406 * +-----------------------------------------------------+
407 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
408 * +-----------------------------------------------------+
409 * 63 48 47 40 39 32 31 16 15 0
410 */
411 printk(KERN_INFO "Rl[desc] [address 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000412 "[vl er S cks ln] [bi->dma ] [bi->skb] "
413 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000414 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
415 rx_desc = E1000_RX_DESC(*rx_ring, i);
416 buffer_info = &rx_ring->buffer_info[i];
417 u0 = (struct my_u0 *)rx_desc;
418 printk(KERN_INFO "Rl[0x%03X] %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000419 "%016llX %p", i,
420 (unsigned long long)le64_to_cpu(u0->a),
421 (unsigned long long)le64_to_cpu(u0->b),
422 (unsigned long long)buffer_info->dma,
423 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000424 if (i == rx_ring->next_to_use)
425 printk(KERN_CONT " NTU\n");
426 else if (i == rx_ring->next_to_clean)
427 printk(KERN_CONT " NTC\n");
428 else
429 printk(KERN_CONT "\n");
430
431 if (netif_msg_pktdata(adapter))
432 print_hex_dump(KERN_INFO, "",
Bruce Allanaf667a22010-12-31 06:10:01 +0000433 DUMP_PREFIX_ADDRESS,
434 16, 1,
435 phys_to_virt(buffer_info->dma),
436 adapter->rx_buffer_len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000437 }
438 }
439
440exit:
441 return;
442}
443
Auke Kokbc7f75f2007-09-17 12:30:59 -0700444/**
445 * e1000_desc_unused - calculate if we have unused descriptors
446 **/
447static int e1000_desc_unused(struct e1000_ring *ring)
448{
449 if (ring->next_to_clean > ring->next_to_use)
450 return ring->next_to_clean - ring->next_to_use - 1;
451
452 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
453}
454
455/**
Bruce Allanad680762008-03-28 09:15:03 -0700456 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700457 * @adapter: board private structure
458 * @status: descriptor status field as written by hardware
459 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
460 * @skb: pointer to sk_buff to be indicated to stack
461 **/
462static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000463 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000464 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700465{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000466 u16 tag = le16_to_cpu(vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700467 skb->protocol = eth_type_trans(skb, netdev);
468
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000469 if (status & E1000_RXD_STAT_VP)
470 __vlan_hwaccel_put_tag(skb, tag);
471
472 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700473}
474
475/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000476 * e1000_rx_checksum - Receive Checksum Offload
Auke Kokbc7f75f2007-09-17 12:30:59 -0700477 * @adapter: board private structure
478 * @status_err: receive descriptor status and error fields
479 * @csum: receive descriptor csum field
480 * @sk_buff: socket buffer with received data
481 **/
482static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
483 u32 csum, struct sk_buff *skb)
484{
485 u16 status = (u16)status_err;
486 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700487
488 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700489
490 /* Ignore Checksum bit is set */
491 if (status & E1000_RXD_STAT_IXSM)
492 return;
493 /* TCP/UDP checksum error bit is set */
494 if (errors & E1000_RXD_ERR_TCPE) {
495 /* let the stack verify checksum errors */
496 adapter->hw_csum_err++;
497 return;
498 }
499
500 /* TCP/UDP Checksum has not been calculated */
501 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
502 return;
503
504 /* It must be a TCP or UDP packet with a valid checksum */
505 if (status & E1000_RXD_STAT_TCPCS) {
506 /* TCP checksum is good */
507 skb->ip_summed = CHECKSUM_UNNECESSARY;
508 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700509 /*
510 * IP fragment with UDP payload
511 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700512 * and then put the value in host order for further stack use.
513 */
Al Viroa39fe742007-12-11 19:50:34 +0000514 __sum16 sum = (__force __sum16)htons(csum);
515 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700516 skb->ip_summed = CHECKSUM_COMPLETE;
517 }
518 adapter->hw_csum_good++;
519}
520
521/**
522 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
523 * @adapter: address of board private structure
524 **/
525static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000526 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700527{
528 struct net_device *netdev = adapter->netdev;
529 struct pci_dev *pdev = adapter->pdev;
530 struct e1000_ring *rx_ring = adapter->rx_ring;
531 struct e1000_rx_desc *rx_desc;
532 struct e1000_buffer *buffer_info;
533 struct sk_buff *skb;
534 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000535 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700536
537 i = rx_ring->next_to_use;
538 buffer_info = &rx_ring->buffer_info[i];
539
540 while (cleaned_count--) {
541 skb = buffer_info->skb;
542 if (skb) {
543 skb_trim(skb, 0);
544 goto map_skb;
545 }
546
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000547 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700548 if (!skb) {
549 /* Better luck next round */
550 adapter->alloc_rx_buff_failed++;
551 break;
552 }
553
Auke Kokbc7f75f2007-09-17 12:30:59 -0700554 buffer_info->skb = skb;
555map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000556 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000558 DMA_FROM_DEVICE);
559 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000560 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700561 adapter->rx_dma_failed++;
562 break;
563 }
564
565 rx_desc = E1000_RX_DESC(*rx_ring, i);
566 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
567
Tom Herbert50849d72010-05-05 14:02:49 +0000568 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
569 /*
570 * Force memory writes to complete before letting h/w
571 * know there are new descriptors to fetch. (Only
572 * applicable for weak-ordered memory model archs,
573 * such as IA-64).
574 */
575 wmb();
576 writel(i, adapter->hw.hw_addr + rx_ring->tail);
577 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700578 i++;
579 if (i == rx_ring->count)
580 i = 0;
581 buffer_info = &rx_ring->buffer_info[i];
582 }
583
Tom Herbert50849d72010-05-05 14:02:49 +0000584 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700585}
586
587/**
588 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
589 * @adapter: address of board private structure
590 **/
591static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000592 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700593{
594 struct net_device *netdev = adapter->netdev;
595 struct pci_dev *pdev = adapter->pdev;
596 union e1000_rx_desc_packet_split *rx_desc;
597 struct e1000_ring *rx_ring = adapter->rx_ring;
598 struct e1000_buffer *buffer_info;
599 struct e1000_ps_page *ps_page;
600 struct sk_buff *skb;
601 unsigned int i, j;
602
603 i = rx_ring->next_to_use;
604 buffer_info = &rx_ring->buffer_info[i];
605
606 while (cleaned_count--) {
607 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
608
609 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700610 ps_page = &buffer_info->ps_pages[j];
611 if (j >= adapter->rx_ps_pages) {
612 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000613 rx_desc->read.buffer_addr[j + 1] =
614 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700615 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700616 }
Auke Kok47f44e42007-10-25 13:57:44 -0700617 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000618 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700619 if (!ps_page->page) {
620 adapter->alloc_rx_buff_failed++;
621 goto no_buffers;
622 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000623 ps_page->dma = dma_map_page(&pdev->dev,
624 ps_page->page,
625 0, PAGE_SIZE,
626 DMA_FROM_DEVICE);
627 if (dma_mapping_error(&pdev->dev,
628 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700629 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000630 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700631 adapter->rx_dma_failed++;
632 goto no_buffers;
633 }
634 }
635 /*
636 * Refresh the desc even if buffer_addrs
637 * didn't change because each write-back
638 * erases this info.
639 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000640 rx_desc->read.buffer_addr[j + 1] =
641 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700642 }
643
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000644 skb = __netdev_alloc_skb_ip_align(netdev,
645 adapter->rx_ps_bsize0,
646 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700647
648 if (!skb) {
649 adapter->alloc_rx_buff_failed++;
650 break;
651 }
652
Auke Kokbc7f75f2007-09-17 12:30:59 -0700653 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000654 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700655 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000656 DMA_FROM_DEVICE);
657 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000658 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700659 adapter->rx_dma_failed++;
660 /* cleanup skb */
661 dev_kfree_skb_any(skb);
662 buffer_info->skb = NULL;
663 break;
664 }
665
666 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
667
Tom Herbert50849d72010-05-05 14:02:49 +0000668 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
669 /*
670 * Force memory writes to complete before letting h/w
671 * know there are new descriptors to fetch. (Only
672 * applicable for weak-ordered memory model archs,
673 * such as IA-64).
674 */
675 wmb();
Bruce Allanaf667a22010-12-31 06:10:01 +0000676 writel(i << 1, adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000677 }
678
Auke Kokbc7f75f2007-09-17 12:30:59 -0700679 i++;
680 if (i == rx_ring->count)
681 i = 0;
682 buffer_info = &rx_ring->buffer_info[i];
683 }
684
685no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000686 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700687}
688
689/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700690 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
691 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700692 * @cleaned_count: number of buffers to allocate this pass
693 **/
694
695static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000696 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700697{
698 struct net_device *netdev = adapter->netdev;
699 struct pci_dev *pdev = adapter->pdev;
700 struct e1000_rx_desc *rx_desc;
701 struct e1000_ring *rx_ring = adapter->rx_ring;
702 struct e1000_buffer *buffer_info;
703 struct sk_buff *skb;
704 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000705 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700706
707 i = rx_ring->next_to_use;
708 buffer_info = &rx_ring->buffer_info[i];
709
710 while (cleaned_count--) {
711 skb = buffer_info->skb;
712 if (skb) {
713 skb_trim(skb, 0);
714 goto check_page;
715 }
716
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000717 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700718 if (unlikely(!skb)) {
719 /* Better luck next round */
720 adapter->alloc_rx_buff_failed++;
721 break;
722 }
723
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700724 buffer_info->skb = skb;
725check_page:
726 /* allocate a new page if necessary */
727 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000728 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700729 if (unlikely(!buffer_info->page)) {
730 adapter->alloc_rx_buff_failed++;
731 break;
732 }
733 }
734
735 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000736 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700737 buffer_info->page, 0,
738 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000739 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700740
741 rx_desc = E1000_RX_DESC(*rx_ring, i);
742 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
743
744 if (unlikely(++i == rx_ring->count))
745 i = 0;
746 buffer_info = &rx_ring->buffer_info[i];
747 }
748
749 if (likely(rx_ring->next_to_use != i)) {
750 rx_ring->next_to_use = i;
751 if (unlikely(i-- == 0))
752 i = (rx_ring->count - 1);
753
754 /* Force memory writes to complete before letting h/w
755 * know there are new descriptors to fetch. (Only
756 * applicable for weak-ordered memory model archs,
757 * such as IA-64). */
758 wmb();
759 writel(i, adapter->hw.hw_addr + rx_ring->tail);
760 }
761}
762
763/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700764 * e1000_clean_rx_irq - Send received data up the network stack; legacy
765 * @adapter: board private structure
766 *
767 * the return value indicates whether actual cleaning was done, there
768 * is no guarantee that everything was cleaned
769 **/
770static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
771 int *work_done, int work_to_do)
772{
773 struct net_device *netdev = adapter->netdev;
774 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000775 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700776 struct e1000_ring *rx_ring = adapter->rx_ring;
777 struct e1000_rx_desc *rx_desc, *next_rxd;
778 struct e1000_buffer *buffer_info, *next_buffer;
779 u32 length;
780 unsigned int i;
781 int cleaned_count = 0;
782 bool cleaned = 0;
783 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
784
785 i = rx_ring->next_to_clean;
786 rx_desc = E1000_RX_DESC(*rx_ring, i);
787 buffer_info = &rx_ring->buffer_info[i];
788
789 while (rx_desc->status & E1000_RXD_STAT_DD) {
790 struct sk_buff *skb;
791 u8 status;
792
793 if (*work_done >= work_to_do)
794 break;
795 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000796 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700797
798 status = rx_desc->status;
799 skb = buffer_info->skb;
800 buffer_info->skb = NULL;
801
802 prefetch(skb->data - NET_IP_ALIGN);
803
804 i++;
805 if (i == rx_ring->count)
806 i = 0;
807 next_rxd = E1000_RX_DESC(*rx_ring, i);
808 prefetch(next_rxd);
809
810 next_buffer = &rx_ring->buffer_info[i];
811
812 cleaned = 1;
813 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000814 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700815 buffer_info->dma,
816 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000817 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700818 buffer_info->dma = 0;
819
820 length = le16_to_cpu(rx_desc->length);
821
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000822 /*
823 * !EOP means multiple descriptors were used to store a single
824 * packet, if that's the case we need to toss it. In fact, we
825 * need to toss every packet with the EOP bit clear and the
826 * next frame that _does_ have the EOP bit set, as it is by
827 * definition only a frame fragment
828 */
829 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
830 adapter->flags2 |= FLAG2_IS_DISCARDING;
831
832 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700833 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000834 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700835 /* recycle */
836 buffer_info->skb = skb;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000837 if (status & E1000_RXD_STAT_EOP)
838 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700839 goto next_desc;
840 }
841
842 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
843 /* recycle */
844 buffer_info->skb = skb;
845 goto next_desc;
846 }
847
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000848 /* adjust length to remove Ethernet CRC */
849 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
850 length -= 4;
851
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852 total_rx_bytes += length;
853 total_rx_packets++;
854
Bruce Allanad680762008-03-28 09:15:03 -0700855 /*
856 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700857 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700858 * of reassembly being done in the stack
859 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860 if (length < copybreak) {
861 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000862 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700863 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700864 skb_copy_to_linear_data_offset(new_skb,
865 -NET_IP_ALIGN,
866 (skb->data -
867 NET_IP_ALIGN),
868 (length +
869 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700870 /* save the skb in buffer_info as good */
871 buffer_info->skb = skb;
872 skb = new_skb;
873 }
874 /* else just continue with the old one */
875 }
876 /* end copybreak code */
877 skb_put(skb, length);
878
879 /* Receive Checksum Offload */
880 e1000_rx_checksum(adapter,
881 (u32)(status) |
882 ((u32)(rx_desc->errors) << 24),
883 le16_to_cpu(rx_desc->csum), skb);
884
885 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
886
887next_desc:
888 rx_desc->status = 0;
889
890 /* return some buffers to hardware, one at a time is too slow */
891 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000892 adapter->alloc_rx_buf(adapter, cleaned_count,
893 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700894 cleaned_count = 0;
895 }
896
897 /* use prefetched values */
898 rx_desc = next_rxd;
899 buffer_info = next_buffer;
900 }
901 rx_ring->next_to_clean = i;
902
903 cleaned_count = e1000_desc_unused(rx_ring);
904 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000905 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700906
Auke Kokbc7f75f2007-09-17 12:30:59 -0700907 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700908 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700909 return cleaned;
910}
911
Auke Kokbc7f75f2007-09-17 12:30:59 -0700912static void e1000_put_txbuf(struct e1000_adapter *adapter,
913 struct e1000_buffer *buffer_info)
914{
Alexander Duyck03b13202009-12-02 16:45:31 +0000915 if (buffer_info->dma) {
916 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +0000917 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
918 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000919 else
Nick Nunley0be3f552010-04-27 13:09:05 +0000920 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
921 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000922 buffer_info->dma = 0;
923 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700924 if (buffer_info->skb) {
925 dev_kfree_skb_any(buffer_info->skb);
926 buffer_info->skb = NULL;
927 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000928 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700929}
930
Bruce Allan41cec6f2009-11-20 23:28:56 +0000931static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932{
Bruce Allan41cec6f2009-11-20 23:28:56 +0000933 struct e1000_adapter *adapter = container_of(work,
934 struct e1000_adapter,
935 print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700936 struct e1000_ring *tx_ring = adapter->tx_ring;
937 unsigned int i = tx_ring->next_to_clean;
938 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
939 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +0000940 struct e1000_hw *hw = &adapter->hw;
941 u16 phy_status, phy_1000t_status, phy_ext_status;
942 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943
Jesse Brandeburg615b32a2011-02-02 10:19:45 +0000944 if (test_bit(__E1000_DOWN, &adapter->state))
945 return;
946
Bruce Allan41cec6f2009-11-20 23:28:56 +0000947 e1e_rphy(hw, PHY_STATUS, &phy_status);
948 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
949 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
950
951 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
952
953 /* detected Hardware unit hang */
954 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700955 " TDH <%x>\n"
956 " TDT <%x>\n"
957 " next_to_use <%x>\n"
958 " next_to_clean <%x>\n"
959 "buffer_info[next_to_clean]:\n"
960 " time_stamp <%lx>\n"
961 " next_to_watch <%x>\n"
962 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +0000963 " next_to_watch.status <%x>\n"
964 "MAC Status <%x>\n"
965 "PHY Status <%x>\n"
966 "PHY 1000BASE-T Status <%x>\n"
967 "PHY Extended Status <%x>\n"
968 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700969 readl(adapter->hw.hw_addr + tx_ring->head),
970 readl(adapter->hw.hw_addr + tx_ring->tail),
971 tx_ring->next_to_use,
972 tx_ring->next_to_clean,
973 tx_ring->buffer_info[eop].time_stamp,
974 eop,
975 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +0000976 eop_desc->upper.fields.status,
977 er32(STATUS),
978 phy_status,
979 phy_1000t_status,
980 phy_ext_status,
981 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982}
983
984/**
985 * e1000_clean_tx_irq - Reclaim resources after transmit completes
986 * @adapter: board private structure
987 *
988 * the return value indicates whether actual cleaning was done, there
989 * is no guarantee that everything was cleaned
990 **/
991static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
992{
993 struct net_device *netdev = adapter->netdev;
994 struct e1000_hw *hw = &adapter->hw;
995 struct e1000_ring *tx_ring = adapter->tx_ring;
996 struct e1000_tx_desc *tx_desc, *eop_desc;
997 struct e1000_buffer *buffer_info;
998 unsigned int i, eop;
999 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001000 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1001
1002 i = tx_ring->next_to_clean;
1003 eop = tx_ring->buffer_info[i].next_to_watch;
1004 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1005
Alexander Duyck12d04a32009-03-25 22:05:03 +00001006 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1007 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001008 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001009 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001010 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001011 tx_desc = E1000_TX_DESC(*tx_ring, i);
1012 buffer_info = &tx_ring->buffer_info[i];
1013 cleaned = (i == eop);
1014
1015 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001016 total_tx_packets += buffer_info->segs;
1017 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001018 }
1019
1020 e1000_put_txbuf(adapter, buffer_info);
1021 tx_desc->upper.data = 0;
1022
1023 i++;
1024 if (i == tx_ring->count)
1025 i = 0;
1026 }
1027
Terry Loftindac87612010-04-09 10:29:49 +00001028 if (i == tx_ring->next_to_use)
1029 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001030 eop = tx_ring->buffer_info[i].next_to_watch;
1031 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001032 }
1033
1034 tx_ring->next_to_clean = i;
1035
1036#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001037 if (count && netif_carrier_ok(netdev) &&
1038 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001039 /* Make sure that anybody stopping the queue after this
1040 * sees the new next_to_clean.
1041 */
1042 smp_mb();
1043
1044 if (netif_queue_stopped(netdev) &&
1045 !(test_bit(__E1000_DOWN, &adapter->state))) {
1046 netif_wake_queue(netdev);
1047 ++adapter->restart_queue;
1048 }
1049 }
1050
1051 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001052 /*
1053 * Detect a transmit hang in hardware, this serializes the
1054 * check with the clearing of time_stamp and movement of i
1055 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001056 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001057 if (tx_ring->buffer_info[i].time_stamp &&
1058 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001059 + (adapter->tx_timeout_factor * HZ)) &&
1060 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001061 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001062 netif_stop_queue(netdev);
1063 }
1064 }
1065 adapter->total_tx_bytes += total_tx_bytes;
1066 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001067 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001068}
1069
1070/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001071 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1072 * @adapter: board private structure
1073 *
1074 * the return value indicates whether actual cleaning was done, there
1075 * is no guarantee that everything was cleaned
1076 **/
1077static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1078 int *work_done, int work_to_do)
1079{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001080 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001081 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1082 struct net_device *netdev = adapter->netdev;
1083 struct pci_dev *pdev = adapter->pdev;
1084 struct e1000_ring *rx_ring = adapter->rx_ring;
1085 struct e1000_buffer *buffer_info, *next_buffer;
1086 struct e1000_ps_page *ps_page;
1087 struct sk_buff *skb;
1088 unsigned int i, j;
1089 u32 length, staterr;
1090 int cleaned_count = 0;
1091 bool cleaned = 0;
1092 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1093
1094 i = rx_ring->next_to_clean;
1095 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1096 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1097 buffer_info = &rx_ring->buffer_info[i];
1098
1099 while (staterr & E1000_RXD_STAT_DD) {
1100 if (*work_done >= work_to_do)
1101 break;
1102 (*work_done)++;
1103 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001104 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001105
1106 /* in the packet split case this is header only */
1107 prefetch(skb->data - NET_IP_ALIGN);
1108
1109 i++;
1110 if (i == rx_ring->count)
1111 i = 0;
1112 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1113 prefetch(next_rxd);
1114
1115 next_buffer = &rx_ring->buffer_info[i];
1116
1117 cleaned = 1;
1118 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001119 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001120 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001121 buffer_info->dma = 0;
1122
Bruce Allanaf667a22010-12-31 06:10:01 +00001123 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001124 if (!(staterr & E1000_RXD_STAT_EOP))
1125 adapter->flags2 |= FLAG2_IS_DISCARDING;
1126
1127 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001128 e_dbg("Packet Split buffers didn't pick up the full "
1129 "packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001130 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001131 if (staterr & E1000_RXD_STAT_EOP)
1132 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001133 goto next_desc;
1134 }
1135
1136 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1137 dev_kfree_skb_irq(skb);
1138 goto next_desc;
1139 }
1140
1141 length = le16_to_cpu(rx_desc->wb.middle.length0);
1142
1143 if (!length) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001144 e_dbg("Last part of the packet spanning multiple "
1145 "descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001146 dev_kfree_skb_irq(skb);
1147 goto next_desc;
1148 }
1149
1150 /* Good Receive */
1151 skb_put(skb, length);
1152
1153 {
Bruce Allanad680762008-03-28 09:15:03 -07001154 /*
1155 * this looks ugly, but it seems compiler issues make it
1156 * more efficient than reusing j
1157 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1159
Bruce Allanad680762008-03-28 09:15:03 -07001160 /*
1161 * page alloc/put takes too long and effects small packet
1162 * throughput, so unsplit small packets and save the alloc/put
1163 * only valid in softirq (napi) context to call kmap_*
1164 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001165 if (l1 && (l1 <= copybreak) &&
1166 ((length + l1) <= adapter->rx_ps_bsize0)) {
1167 u8 *vaddr;
1168
Auke Kok47f44e42007-10-25 13:57:44 -07001169 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001170
Bruce Allanad680762008-03-28 09:15:03 -07001171 /*
1172 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001173 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001174 * very long
1175 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001176 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1177 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001178 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1179 memcpy(skb_tail_pointer(skb), vaddr, l1);
1180 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001181 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1182 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001183
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001184 /* remove the CRC */
1185 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1186 l1 -= 4;
1187
Auke Kokbc7f75f2007-09-17 12:30:59 -07001188 skb_put(skb, l1);
1189 goto copydone;
1190 } /* if */
1191 }
1192
1193 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1194 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1195 if (!length)
1196 break;
1197
Auke Kok47f44e42007-10-25 13:57:44 -07001198 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001199 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1200 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001201 ps_page->dma = 0;
1202 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1203 ps_page->page = NULL;
1204 skb->len += length;
1205 skb->data_len += length;
1206 skb->truesize += length;
1207 }
1208
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001209 /* strip the ethernet crc, problem is we're using pages now so
1210 * this whole operation can get a little cpu intensive
1211 */
1212 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1213 pskb_trim(skb, skb->len - 4);
1214
Auke Kokbc7f75f2007-09-17 12:30:59 -07001215copydone:
1216 total_rx_bytes += skb->len;
1217 total_rx_packets++;
1218
1219 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1220 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1221
1222 if (rx_desc->wb.upper.header_status &
1223 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1224 adapter->rx_hdr_split++;
1225
1226 e1000_receive_skb(adapter, netdev, skb,
1227 staterr, rx_desc->wb.middle.vlan);
1228
1229next_desc:
1230 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1231 buffer_info->skb = NULL;
1232
1233 /* return some buffers to hardware, one at a time is too slow */
1234 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001235 adapter->alloc_rx_buf(adapter, cleaned_count,
1236 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001237 cleaned_count = 0;
1238 }
1239
1240 /* use prefetched values */
1241 rx_desc = next_rxd;
1242 buffer_info = next_buffer;
1243
1244 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1245 }
1246 rx_ring->next_to_clean = i;
1247
1248 cleaned_count = e1000_desc_unused(rx_ring);
1249 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001250 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001251
Auke Kokbc7f75f2007-09-17 12:30:59 -07001252 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001253 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001254 return cleaned;
1255}
1256
1257/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001258 * e1000_consume_page - helper function
1259 **/
1260static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1261 u16 length)
1262{
1263 bi->page = NULL;
1264 skb->len += length;
1265 skb->data_len += length;
1266 skb->truesize += length;
1267}
1268
1269/**
1270 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1271 * @adapter: board private structure
1272 *
1273 * the return value indicates whether actual cleaning was done, there
1274 * is no guarantee that everything was cleaned
1275 **/
1276
1277static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1278 int *work_done, int work_to_do)
1279{
1280 struct net_device *netdev = adapter->netdev;
1281 struct pci_dev *pdev = adapter->pdev;
1282 struct e1000_ring *rx_ring = adapter->rx_ring;
1283 struct e1000_rx_desc *rx_desc, *next_rxd;
1284 struct e1000_buffer *buffer_info, *next_buffer;
1285 u32 length;
1286 unsigned int i;
1287 int cleaned_count = 0;
1288 bool cleaned = false;
1289 unsigned int total_rx_bytes=0, total_rx_packets=0;
1290
1291 i = rx_ring->next_to_clean;
1292 rx_desc = E1000_RX_DESC(*rx_ring, i);
1293 buffer_info = &rx_ring->buffer_info[i];
1294
1295 while (rx_desc->status & E1000_RXD_STAT_DD) {
1296 struct sk_buff *skb;
1297 u8 status;
1298
1299 if (*work_done >= work_to_do)
1300 break;
1301 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001302 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001303
1304 status = rx_desc->status;
1305 skb = buffer_info->skb;
1306 buffer_info->skb = NULL;
1307
1308 ++i;
1309 if (i == rx_ring->count)
1310 i = 0;
1311 next_rxd = E1000_RX_DESC(*rx_ring, i);
1312 prefetch(next_rxd);
1313
1314 next_buffer = &rx_ring->buffer_info[i];
1315
1316 cleaned = true;
1317 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001318 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1319 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001320 buffer_info->dma = 0;
1321
1322 length = le16_to_cpu(rx_desc->length);
1323
1324 /* errors is only valid for DD + EOP descriptors */
1325 if (unlikely((status & E1000_RXD_STAT_EOP) &&
1326 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
1327 /* recycle both page and skb */
1328 buffer_info->skb = skb;
1329 /* an error means any chain goes out the window
1330 * too */
1331 if (rx_ring->rx_skb_top)
Bruce Allanef5ab892011-02-10 08:17:21 +00001332 dev_kfree_skb_irq(rx_ring->rx_skb_top);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001333 rx_ring->rx_skb_top = NULL;
1334 goto next_desc;
1335 }
1336
Bruce Allanf0f1a172010-12-11 05:53:32 +00001337#define rxtop (rx_ring->rx_skb_top)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001338 if (!(status & E1000_RXD_STAT_EOP)) {
1339 /* this descriptor is only the beginning (or middle) */
1340 if (!rxtop) {
1341 /* this is the beginning of a chain */
1342 rxtop = skb;
1343 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1344 0, length);
1345 } else {
1346 /* this is the middle of a chain */
1347 skb_fill_page_desc(rxtop,
1348 skb_shinfo(rxtop)->nr_frags,
1349 buffer_info->page, 0, length);
1350 /* re-use the skb, only consumed the page */
1351 buffer_info->skb = skb;
1352 }
1353 e1000_consume_page(buffer_info, rxtop, length);
1354 goto next_desc;
1355 } else {
1356 if (rxtop) {
1357 /* end of the chain */
1358 skb_fill_page_desc(rxtop,
1359 skb_shinfo(rxtop)->nr_frags,
1360 buffer_info->page, 0, length);
1361 /* re-use the current skb, we only consumed the
1362 * page */
1363 buffer_info->skb = skb;
1364 skb = rxtop;
1365 rxtop = NULL;
1366 e1000_consume_page(buffer_info, skb, length);
1367 } else {
1368 /* no chain, got EOP, this buf is the packet
1369 * copybreak to save the put_page/alloc_page */
1370 if (length <= copybreak &&
1371 skb_tailroom(skb) >= length) {
1372 u8 *vaddr;
1373 vaddr = kmap_atomic(buffer_info->page,
1374 KM_SKB_DATA_SOFTIRQ);
1375 memcpy(skb_tail_pointer(skb), vaddr,
1376 length);
1377 kunmap_atomic(vaddr,
1378 KM_SKB_DATA_SOFTIRQ);
1379 /* re-use the page, so don't erase
1380 * buffer_info->page */
1381 skb_put(skb, length);
1382 } else {
1383 skb_fill_page_desc(skb, 0,
1384 buffer_info->page, 0,
1385 length);
1386 e1000_consume_page(buffer_info, skb,
1387 length);
1388 }
1389 }
1390 }
1391
1392 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1393 e1000_rx_checksum(adapter,
1394 (u32)(status) |
1395 ((u32)(rx_desc->errors) << 24),
1396 le16_to_cpu(rx_desc->csum), skb);
1397
1398 /* probably a little skewed due to removing CRC */
1399 total_rx_bytes += skb->len;
1400 total_rx_packets++;
1401
1402 /* eth type trans needs skb->data to point to something */
1403 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001404 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001405 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001406 goto next_desc;
1407 }
1408
1409 e1000_receive_skb(adapter, netdev, skb, status,
1410 rx_desc->special);
1411
1412next_desc:
1413 rx_desc->status = 0;
1414
1415 /* return some buffers to hardware, one at a time is too slow */
1416 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001417 adapter->alloc_rx_buf(adapter, cleaned_count,
1418 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001419 cleaned_count = 0;
1420 }
1421
1422 /* use prefetched values */
1423 rx_desc = next_rxd;
1424 buffer_info = next_buffer;
1425 }
1426 rx_ring->next_to_clean = i;
1427
1428 cleaned_count = e1000_desc_unused(rx_ring);
1429 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001430 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001431
1432 adapter->total_rx_bytes += total_rx_bytes;
1433 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001434 return cleaned;
1435}
1436
1437/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001438 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1439 * @adapter: board private structure
1440 **/
1441static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1442{
1443 struct e1000_ring *rx_ring = adapter->rx_ring;
1444 struct e1000_buffer *buffer_info;
1445 struct e1000_ps_page *ps_page;
1446 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001447 unsigned int i, j;
1448
1449 /* Free all the Rx ring sk_buffs */
1450 for (i = 0; i < rx_ring->count; i++) {
1451 buffer_info = &rx_ring->buffer_info[i];
1452 if (buffer_info->dma) {
1453 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001454 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001455 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001456 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001457 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001458 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001459 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001460 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001462 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001463 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001464 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001465 buffer_info->dma = 0;
1466 }
1467
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001468 if (buffer_info->page) {
1469 put_page(buffer_info->page);
1470 buffer_info->page = NULL;
1471 }
1472
Auke Kokbc7f75f2007-09-17 12:30:59 -07001473 if (buffer_info->skb) {
1474 dev_kfree_skb(buffer_info->skb);
1475 buffer_info->skb = NULL;
1476 }
1477
1478 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001479 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001480 if (!ps_page->page)
1481 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001482 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1483 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001484 ps_page->dma = 0;
1485 put_page(ps_page->page);
1486 ps_page->page = NULL;
1487 }
1488 }
1489
1490 /* there also may be some cached data from a chained receive */
1491 if (rx_ring->rx_skb_top) {
1492 dev_kfree_skb(rx_ring->rx_skb_top);
1493 rx_ring->rx_skb_top = NULL;
1494 }
1495
Auke Kokbc7f75f2007-09-17 12:30:59 -07001496 /* Zero out the descriptor ring */
1497 memset(rx_ring->desc, 0, rx_ring->size);
1498
1499 rx_ring->next_to_clean = 0;
1500 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001501 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001502
1503 writel(0, adapter->hw.hw_addr + rx_ring->head);
1504 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1505}
1506
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001507static void e1000e_downshift_workaround(struct work_struct *work)
1508{
1509 struct e1000_adapter *adapter = container_of(work,
1510 struct e1000_adapter, downshift_task);
1511
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001512 if (test_bit(__E1000_DOWN, &adapter->state))
1513 return;
1514
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001515 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1516}
1517
Auke Kokbc7f75f2007-09-17 12:30:59 -07001518/**
1519 * e1000_intr_msi - Interrupt Handler
1520 * @irq: interrupt number
1521 * @data: pointer to a network interface device structure
1522 **/
1523static irqreturn_t e1000_intr_msi(int irq, void *data)
1524{
1525 struct net_device *netdev = data;
1526 struct e1000_adapter *adapter = netdev_priv(netdev);
1527 struct e1000_hw *hw = &adapter->hw;
1528 u32 icr = er32(ICR);
1529
Bruce Allanad680762008-03-28 09:15:03 -07001530 /*
1531 * read ICR disables interrupts using IAM
1532 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001533
dave graham573cca82009-02-10 12:52:05 +00001534 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001535 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001536 /*
1537 * ICH8 workaround-- Call gig speed drop workaround on cable
1538 * disconnect (LSC) before accessing any PHY registers
1539 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001540 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1541 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001542 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001543
Bruce Allanad680762008-03-28 09:15:03 -07001544 /*
1545 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001546 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001547 * adapter in watchdog
1548 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001549 if (netif_carrier_ok(netdev) &&
1550 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1551 /* disable receives */
1552 u32 rctl = er32(RCTL);
1553 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001554 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001555 }
1556 /* guard against interrupt when we're going down */
1557 if (!test_bit(__E1000_DOWN, &adapter->state))
1558 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1559 }
1560
Ben Hutchings288379f2009-01-19 16:43:59 -08001561 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562 adapter->total_tx_bytes = 0;
1563 adapter->total_tx_packets = 0;
1564 adapter->total_rx_bytes = 0;
1565 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001566 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001567 }
1568
1569 return IRQ_HANDLED;
1570}
1571
1572/**
1573 * e1000_intr - Interrupt Handler
1574 * @irq: interrupt number
1575 * @data: pointer to a network interface device structure
1576 **/
1577static irqreturn_t e1000_intr(int irq, void *data)
1578{
1579 struct net_device *netdev = data;
1580 struct e1000_adapter *adapter = netdev_priv(netdev);
1581 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001582 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001583
Bruce Allana68ea772009-11-20 23:23:16 +00001584 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585 return IRQ_NONE; /* Not our interrupt */
1586
Bruce Allanad680762008-03-28 09:15:03 -07001587 /*
1588 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1589 * not set, then the adapter didn't send an interrupt
1590 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001591 if (!(icr & E1000_ICR_INT_ASSERTED))
1592 return IRQ_NONE;
1593
Bruce Allanad680762008-03-28 09:15:03 -07001594 /*
1595 * Interrupt Auto-Mask...upon reading ICR,
1596 * interrupts are masked. No need for the
1597 * IMC write
1598 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001599
dave graham573cca82009-02-10 12:52:05 +00001600 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001601 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001602 /*
1603 * ICH8 workaround-- Call gig speed drop workaround on cable
1604 * disconnect (LSC) before accessing any PHY registers
1605 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001606 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1607 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001608 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001609
Bruce Allanad680762008-03-28 09:15:03 -07001610 /*
1611 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001612 * For packet buffer work-around on link down event;
1613 * disable receives here in the ISR and
1614 * reset adapter in watchdog
1615 */
1616 if (netif_carrier_ok(netdev) &&
1617 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1618 /* disable receives */
1619 rctl = er32(RCTL);
1620 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001621 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001622 }
1623 /* guard against interrupt when we're going down */
1624 if (!test_bit(__E1000_DOWN, &adapter->state))
1625 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1626 }
1627
Ben Hutchings288379f2009-01-19 16:43:59 -08001628 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001629 adapter->total_tx_bytes = 0;
1630 adapter->total_tx_packets = 0;
1631 adapter->total_rx_bytes = 0;
1632 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001633 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634 }
1635
1636 return IRQ_HANDLED;
1637}
1638
Bruce Allan4662e822008-08-26 18:37:06 -07001639static irqreturn_t e1000_msix_other(int irq, void *data)
1640{
1641 struct net_device *netdev = data;
1642 struct e1000_adapter *adapter = netdev_priv(netdev);
1643 struct e1000_hw *hw = &adapter->hw;
1644 u32 icr = er32(ICR);
1645
1646 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001647 if (!test_bit(__E1000_DOWN, &adapter->state))
1648 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001649 return IRQ_NONE;
1650 }
1651
1652 if (icr & adapter->eiac_mask)
1653 ew32(ICS, (icr & adapter->eiac_mask));
1654
1655 if (icr & E1000_ICR_OTHER) {
1656 if (!(icr & E1000_ICR_LSC))
1657 goto no_link_interrupt;
1658 hw->mac.get_link_status = 1;
1659 /* guard against interrupt when we're going down */
1660 if (!test_bit(__E1000_DOWN, &adapter->state))
1661 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1662 }
1663
1664no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001665 if (!test_bit(__E1000_DOWN, &adapter->state))
1666 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001667
1668 return IRQ_HANDLED;
1669}
1670
1671
1672static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1673{
1674 struct net_device *netdev = data;
1675 struct e1000_adapter *adapter = netdev_priv(netdev);
1676 struct e1000_hw *hw = &adapter->hw;
1677 struct e1000_ring *tx_ring = adapter->tx_ring;
1678
1679
1680 adapter->total_tx_bytes = 0;
1681 adapter->total_tx_packets = 0;
1682
1683 if (!e1000_clean_tx_irq(adapter))
1684 /* Ring was not completely cleaned, so fire another interrupt */
1685 ew32(ICS, tx_ring->ims_val);
1686
1687 return IRQ_HANDLED;
1688}
1689
1690static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1691{
1692 struct net_device *netdev = data;
1693 struct e1000_adapter *adapter = netdev_priv(netdev);
1694
1695 /* Write the ITR value calculated at the end of the
1696 * previous interrupt.
1697 */
1698 if (adapter->rx_ring->set_itr) {
1699 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1700 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1701 adapter->rx_ring->set_itr = 0;
1702 }
1703
Ben Hutchings288379f2009-01-19 16:43:59 -08001704 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001705 adapter->total_rx_bytes = 0;
1706 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001707 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001708 }
1709 return IRQ_HANDLED;
1710}
1711
1712/**
1713 * e1000_configure_msix - Configure MSI-X hardware
1714 *
1715 * e1000_configure_msix sets up the hardware to properly
1716 * generate MSI-X interrupts.
1717 **/
1718static void e1000_configure_msix(struct e1000_adapter *adapter)
1719{
1720 struct e1000_hw *hw = &adapter->hw;
1721 struct e1000_ring *rx_ring = adapter->rx_ring;
1722 struct e1000_ring *tx_ring = adapter->tx_ring;
1723 int vector = 0;
1724 u32 ctrl_ext, ivar = 0;
1725
1726 adapter->eiac_mask = 0;
1727
1728 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1729 if (hw->mac.type == e1000_82574) {
1730 u32 rfctl = er32(RFCTL);
1731 rfctl |= E1000_RFCTL_ACK_DIS;
1732 ew32(RFCTL, rfctl);
1733 }
1734
1735#define E1000_IVAR_INT_ALLOC_VALID 0x8
1736 /* Configure Rx vector */
1737 rx_ring->ims_val = E1000_IMS_RXQ0;
1738 adapter->eiac_mask |= rx_ring->ims_val;
1739 if (rx_ring->itr_val)
1740 writel(1000000000 / (rx_ring->itr_val * 256),
1741 hw->hw_addr + rx_ring->itr_register);
1742 else
1743 writel(1, hw->hw_addr + rx_ring->itr_register);
1744 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1745
1746 /* Configure Tx vector */
1747 tx_ring->ims_val = E1000_IMS_TXQ0;
1748 vector++;
1749 if (tx_ring->itr_val)
1750 writel(1000000000 / (tx_ring->itr_val * 256),
1751 hw->hw_addr + tx_ring->itr_register);
1752 else
1753 writel(1, hw->hw_addr + tx_ring->itr_register);
1754 adapter->eiac_mask |= tx_ring->ims_val;
1755 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1756
1757 /* set vector for Other Causes, e.g. link changes */
1758 vector++;
1759 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1760 if (rx_ring->itr_val)
1761 writel(1000000000 / (rx_ring->itr_val * 256),
1762 hw->hw_addr + E1000_EITR_82574(vector));
1763 else
1764 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1765
1766 /* Cause Tx interrupts on every write back */
1767 ivar |= (1 << 31);
1768
1769 ew32(IVAR, ivar);
1770
1771 /* enable MSI-X PBA support */
1772 ctrl_ext = er32(CTRL_EXT);
1773 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1774
1775 /* Auto-Mask Other interrupts upon ICR read */
1776#define E1000_EIAC_MASK_82574 0x01F00000
1777 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1778 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1779 ew32(CTRL_EXT, ctrl_ext);
1780 e1e_flush();
1781}
1782
1783void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1784{
1785 if (adapter->msix_entries) {
1786 pci_disable_msix(adapter->pdev);
1787 kfree(adapter->msix_entries);
1788 adapter->msix_entries = NULL;
1789 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1790 pci_disable_msi(adapter->pdev);
1791 adapter->flags &= ~FLAG_MSI_ENABLED;
1792 }
Bruce Allan4662e822008-08-26 18:37:06 -07001793}
1794
1795/**
1796 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1797 *
1798 * Attempt to configure interrupts using the best available
1799 * capabilities of the hardware and kernel.
1800 **/
1801void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1802{
1803 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001804 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001805
1806 switch (adapter->int_mode) {
1807 case E1000E_INT_MODE_MSIX:
1808 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001809 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1810 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001811 sizeof(struct msix_entry),
1812 GFP_KERNEL);
1813 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001814 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001815 adapter->msix_entries[i].entry = i;
1816
1817 err = pci_enable_msix(adapter->pdev,
1818 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001819 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001820 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001821 return;
1822 }
1823 /* MSI-X failed, so fall through and try MSI */
1824 e_err("Failed to initialize MSI-X interrupts. "
1825 "Falling back to MSI interrupts.\n");
1826 e1000e_reset_interrupt_capability(adapter);
1827 }
1828 adapter->int_mode = E1000E_INT_MODE_MSI;
1829 /* Fall through */
1830 case E1000E_INT_MODE_MSI:
1831 if (!pci_enable_msi(adapter->pdev)) {
1832 adapter->flags |= FLAG_MSI_ENABLED;
1833 } else {
1834 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1835 e_err("Failed to initialize MSI interrupts. Falling "
1836 "back to legacy interrupts.\n");
1837 }
1838 /* Fall through */
1839 case E1000E_INT_MODE_LEGACY:
1840 /* Don't do anything; this is the system default */
1841 break;
1842 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001843
1844 /* store the number of vectors being used */
1845 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001846}
1847
1848/**
1849 * e1000_request_msix - Initialize MSI-X interrupts
1850 *
1851 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1852 * kernel.
1853 **/
1854static int e1000_request_msix(struct e1000_adapter *adapter)
1855{
1856 struct net_device *netdev = adapter->netdev;
1857 int err = 0, vector = 0;
1858
1859 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001860 snprintf(adapter->rx_ring->name,
1861 sizeof(adapter->rx_ring->name) - 1,
1862 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001863 else
1864 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1865 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001866 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001867 netdev);
1868 if (err)
1869 goto out;
1870 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1871 adapter->rx_ring->itr_val = adapter->itr;
1872 vector++;
1873
1874 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001875 snprintf(adapter->tx_ring->name,
1876 sizeof(adapter->tx_ring->name) - 1,
1877 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001878 else
1879 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1880 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001881 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001882 netdev);
1883 if (err)
1884 goto out;
1885 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1886 adapter->tx_ring->itr_val = adapter->itr;
1887 vector++;
1888
1889 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001890 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001891 if (err)
1892 goto out;
1893
1894 e1000_configure_msix(adapter);
1895 return 0;
1896out:
1897 return err;
1898}
1899
Bruce Allanf8d59f72008-08-08 18:36:11 -07001900/**
1901 * e1000_request_irq - initialize interrupts
1902 *
1903 * Attempts to configure interrupts using the best available
1904 * capabilities of the hardware and kernel.
1905 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001906static int e1000_request_irq(struct e1000_adapter *adapter)
1907{
1908 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001909 int err;
1910
Bruce Allan4662e822008-08-26 18:37:06 -07001911 if (adapter->msix_entries) {
1912 err = e1000_request_msix(adapter);
1913 if (!err)
1914 return err;
1915 /* fall back to MSI */
1916 e1000e_reset_interrupt_capability(adapter);
1917 adapter->int_mode = E1000E_INT_MODE_MSI;
1918 e1000e_set_interrupt_capability(adapter);
1919 }
1920 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001921 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001922 netdev->name, netdev);
1923 if (!err)
1924 return err;
1925
1926 /* fall back to legacy interrupt */
1927 e1000e_reset_interrupt_capability(adapter);
1928 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001929 }
1930
Joe Perchesa0607fd2009-11-18 23:29:17 -08001931 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001932 netdev->name, netdev);
1933 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001934 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001935
1936 return err;
1937}
1938
1939static void e1000_free_irq(struct e1000_adapter *adapter)
1940{
1941 struct net_device *netdev = adapter->netdev;
1942
Bruce Allan4662e822008-08-26 18:37:06 -07001943 if (adapter->msix_entries) {
1944 int vector = 0;
1945
1946 free_irq(adapter->msix_entries[vector].vector, netdev);
1947 vector++;
1948
1949 free_irq(adapter->msix_entries[vector].vector, netdev);
1950 vector++;
1951
1952 /* Other Causes interrupt vector */
1953 free_irq(adapter->msix_entries[vector].vector, netdev);
1954 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001955 }
Bruce Allan4662e822008-08-26 18:37:06 -07001956
1957 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001958}
1959
1960/**
1961 * e1000_irq_disable - Mask off interrupt generation on the NIC
1962 **/
1963static void e1000_irq_disable(struct e1000_adapter *adapter)
1964{
1965 struct e1000_hw *hw = &adapter->hw;
1966
Auke Kokbc7f75f2007-09-17 12:30:59 -07001967 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001968 if (adapter->msix_entries)
1969 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001970 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001971
1972 if (adapter->msix_entries) {
1973 int i;
1974 for (i = 0; i < adapter->num_vectors; i++)
1975 synchronize_irq(adapter->msix_entries[i].vector);
1976 } else {
1977 synchronize_irq(adapter->pdev->irq);
1978 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001979}
1980
1981/**
1982 * e1000_irq_enable - Enable default interrupt generation settings
1983 **/
1984static void e1000_irq_enable(struct e1000_adapter *adapter)
1985{
1986 struct e1000_hw *hw = &adapter->hw;
1987
Bruce Allan4662e822008-08-26 18:37:06 -07001988 if (adapter->msix_entries) {
1989 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1990 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1991 } else {
1992 ew32(IMS, IMS_ENABLE_MASK);
1993 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001994 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995}
1996
1997/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001998 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07001999 * @adapter: address of board private structure
2000 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002001 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002002 * For ASF and Pass Through versions of f/w this means that
2003 * the driver is loaded. For AMT version (only with 82573)
2004 * of the f/w this means that the network i/f is open.
2005 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002006void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002007{
2008 struct e1000_hw *hw = &adapter->hw;
2009 u32 ctrl_ext;
2010 u32 swsm;
2011
2012 /* Let firmware know the driver has taken over */
2013 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2014 swsm = er32(SWSM);
2015 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2016 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2017 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002018 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002019 }
2020}
2021
2022/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002023 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002024 * @adapter: address of board private structure
2025 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002026 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002027 * For ASF and Pass Through versions of f/w this means that the
2028 * driver is no longer loaded. For AMT version (only with 82573) i
2029 * of the f/w this means that the network i/f is closed.
2030 *
2031 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002032void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002033{
2034 struct e1000_hw *hw = &adapter->hw;
2035 u32 ctrl_ext;
2036 u32 swsm;
2037
2038 /* Let firmware taken over control of h/w */
2039 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2040 swsm = er32(SWSM);
2041 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2042 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2043 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002044 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002045 }
2046}
2047
Auke Kokbc7f75f2007-09-17 12:30:59 -07002048/**
2049 * @e1000_alloc_ring - allocate memory for a ring structure
2050 **/
2051static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2052 struct e1000_ring *ring)
2053{
2054 struct pci_dev *pdev = adapter->pdev;
2055
2056 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2057 GFP_KERNEL);
2058 if (!ring->desc)
2059 return -ENOMEM;
2060
2061 return 0;
2062}
2063
2064/**
2065 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2066 * @adapter: board private structure
2067 *
2068 * Return 0 on success, negative on failure
2069 **/
2070int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2071{
2072 struct e1000_ring *tx_ring = adapter->tx_ring;
2073 int err = -ENOMEM, size;
2074
2075 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002076 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002077 if (!tx_ring->buffer_info)
2078 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002079
2080 /* round up to nearest 4K */
2081 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2082 tx_ring->size = ALIGN(tx_ring->size, 4096);
2083
2084 err = e1000_alloc_ring_dma(adapter, tx_ring);
2085 if (err)
2086 goto err;
2087
2088 tx_ring->next_to_use = 0;
2089 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002090
2091 return 0;
2092err:
2093 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002094 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002095 return err;
2096}
2097
2098/**
2099 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2100 * @adapter: board private structure
2101 *
2102 * Returns 0 on success, negative on failure
2103 **/
2104int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2105{
2106 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002107 struct e1000_buffer *buffer_info;
2108 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002109
2110 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002111 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002112 if (!rx_ring->buffer_info)
2113 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002114
Auke Kok47f44e42007-10-25 13:57:44 -07002115 for (i = 0; i < rx_ring->count; i++) {
2116 buffer_info = &rx_ring->buffer_info[i];
2117 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2118 sizeof(struct e1000_ps_page),
2119 GFP_KERNEL);
2120 if (!buffer_info->ps_pages)
2121 goto err_pages;
2122 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002123
2124 desc_len = sizeof(union e1000_rx_desc_packet_split);
2125
2126 /* Round up to nearest 4K */
2127 rx_ring->size = rx_ring->count * desc_len;
2128 rx_ring->size = ALIGN(rx_ring->size, 4096);
2129
2130 err = e1000_alloc_ring_dma(adapter, rx_ring);
2131 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002132 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002133
2134 rx_ring->next_to_clean = 0;
2135 rx_ring->next_to_use = 0;
2136 rx_ring->rx_skb_top = NULL;
2137
2138 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002139
2140err_pages:
2141 for (i = 0; i < rx_ring->count; i++) {
2142 buffer_info = &rx_ring->buffer_info[i];
2143 kfree(buffer_info->ps_pages);
2144 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002145err:
2146 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002147 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002148 return err;
2149}
2150
2151/**
2152 * e1000_clean_tx_ring - Free Tx Buffers
2153 * @adapter: board private structure
2154 **/
2155static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2156{
2157 struct e1000_ring *tx_ring = adapter->tx_ring;
2158 struct e1000_buffer *buffer_info;
2159 unsigned long size;
2160 unsigned int i;
2161
2162 for (i = 0; i < tx_ring->count; i++) {
2163 buffer_info = &tx_ring->buffer_info[i];
2164 e1000_put_txbuf(adapter, buffer_info);
2165 }
2166
2167 size = sizeof(struct e1000_buffer) * tx_ring->count;
2168 memset(tx_ring->buffer_info, 0, size);
2169
2170 memset(tx_ring->desc, 0, tx_ring->size);
2171
2172 tx_ring->next_to_use = 0;
2173 tx_ring->next_to_clean = 0;
2174
2175 writel(0, adapter->hw.hw_addr + tx_ring->head);
2176 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2177}
2178
2179/**
2180 * e1000e_free_tx_resources - Free Tx Resources per Queue
2181 * @adapter: board private structure
2182 *
2183 * Free all transmit software resources
2184 **/
2185void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2186{
2187 struct pci_dev *pdev = adapter->pdev;
2188 struct e1000_ring *tx_ring = adapter->tx_ring;
2189
2190 e1000_clean_tx_ring(adapter);
2191
2192 vfree(tx_ring->buffer_info);
2193 tx_ring->buffer_info = NULL;
2194
2195 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2196 tx_ring->dma);
2197 tx_ring->desc = NULL;
2198}
2199
2200/**
2201 * e1000e_free_rx_resources - Free Rx Resources
2202 * @adapter: board private structure
2203 *
2204 * Free all receive software resources
2205 **/
2206
2207void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2208{
2209 struct pci_dev *pdev = adapter->pdev;
2210 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002211 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002212
2213 e1000_clean_rx_ring(adapter);
2214
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002215 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002216 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002217
Auke Kokbc7f75f2007-09-17 12:30:59 -07002218 vfree(rx_ring->buffer_info);
2219 rx_ring->buffer_info = NULL;
2220
Auke Kokbc7f75f2007-09-17 12:30:59 -07002221 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2222 rx_ring->dma);
2223 rx_ring->desc = NULL;
2224}
2225
2226/**
2227 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002228 * @adapter: pointer to adapter
2229 * @itr_setting: current adapter->itr
2230 * @packets: the number of packets during this measurement interval
2231 * @bytes: the number of bytes during this measurement interval
2232 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002233 * Stores a new ITR value based on packets and byte
2234 * counts during the last interrupt. The advantage of per interrupt
2235 * computation is faster updates and more accurate ITR for the current
2236 * traffic pattern. Constants in this function were computed
2237 * based on theoretical maximum wire speed and thresholds were set based
2238 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002239 * while increasing bulk throughput. This functionality is controlled
2240 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002241 **/
2242static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2243 u16 itr_setting, int packets,
2244 int bytes)
2245{
2246 unsigned int retval = itr_setting;
2247
2248 if (packets == 0)
2249 goto update_itr_done;
2250
2251 switch (itr_setting) {
2252 case lowest_latency:
2253 /* handle TSO and jumbo frames */
2254 if (bytes/packets > 8000)
2255 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002256 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002257 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002258 break;
2259 case low_latency: /* 50 usec aka 20000 ints/s */
2260 if (bytes > 10000) {
2261 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002262 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002263 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002264 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002265 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002266 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002267 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002268 } else if (bytes/packets > 2000) {
2269 retval = bulk_latency;
2270 } else if (packets <= 2 && bytes < 512) {
2271 retval = lowest_latency;
2272 }
2273 break;
2274 case bulk_latency: /* 250 usec aka 4000 ints/s */
2275 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002276 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002277 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002278 } else if (bytes < 6000) {
2279 retval = low_latency;
2280 }
2281 break;
2282 }
2283
2284update_itr_done:
2285 return retval;
2286}
2287
2288static void e1000_set_itr(struct e1000_adapter *adapter)
2289{
2290 struct e1000_hw *hw = &adapter->hw;
2291 u16 current_itr;
2292 u32 new_itr = adapter->itr;
2293
2294 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2295 if (adapter->link_speed != SPEED_1000) {
2296 current_itr = 0;
2297 new_itr = 4000;
2298 goto set_itr_now;
2299 }
2300
Bruce Allan828bac82010-09-29 21:39:37 +00002301 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2302 new_itr = 0;
2303 goto set_itr_now;
2304 }
2305
Auke Kokbc7f75f2007-09-17 12:30:59 -07002306 adapter->tx_itr = e1000_update_itr(adapter,
2307 adapter->tx_itr,
2308 adapter->total_tx_packets,
2309 adapter->total_tx_bytes);
2310 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2311 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2312 adapter->tx_itr = low_latency;
2313
2314 adapter->rx_itr = e1000_update_itr(adapter,
2315 adapter->rx_itr,
2316 adapter->total_rx_packets,
2317 adapter->total_rx_bytes);
2318 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2319 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2320 adapter->rx_itr = low_latency;
2321
2322 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2323
2324 switch (current_itr) {
2325 /* counts and packets in update_itr are dependent on these numbers */
2326 case lowest_latency:
2327 new_itr = 70000;
2328 break;
2329 case low_latency:
2330 new_itr = 20000; /* aka hwitr = ~200 */
2331 break;
2332 case bulk_latency:
2333 new_itr = 4000;
2334 break;
2335 default:
2336 break;
2337 }
2338
2339set_itr_now:
2340 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002341 /*
2342 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002343 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002344 * increasing
2345 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002346 new_itr = new_itr > adapter->itr ?
2347 min(adapter->itr + (new_itr >> 2), new_itr) :
2348 new_itr;
2349 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002350 adapter->rx_ring->itr_val = new_itr;
2351 if (adapter->msix_entries)
2352 adapter->rx_ring->set_itr = 1;
2353 else
Bruce Allan828bac82010-09-29 21:39:37 +00002354 if (new_itr)
2355 ew32(ITR, 1000000000 / (new_itr * 256));
2356 else
2357 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002358 }
2359}
2360
2361/**
Bruce Allan4662e822008-08-26 18:37:06 -07002362 * e1000_alloc_queues - Allocate memory for all rings
2363 * @adapter: board private structure to initialize
2364 **/
2365static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2366{
2367 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2368 if (!adapter->tx_ring)
2369 goto err;
2370
2371 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2372 if (!adapter->rx_ring)
2373 goto err;
2374
2375 return 0;
2376err:
2377 e_err("Unable to allocate memory for queues\n");
2378 kfree(adapter->rx_ring);
2379 kfree(adapter->tx_ring);
2380 return -ENOMEM;
2381}
2382
2383/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002385 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002386 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002387 **/
2388static int e1000_clean(struct napi_struct *napi, int budget)
2389{
2390 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002391 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002392 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002393 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002394
Wang Chen4cf16532008-11-12 23:38:14 -08002395 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002396
Bruce Allan4662e822008-08-26 18:37:06 -07002397 if (adapter->msix_entries &&
2398 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2399 goto clean_rx;
2400
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002401 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002402
Bruce Allan4662e822008-08-26 18:37:06 -07002403clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002404 adapter->clean_rx(adapter, &work_done, budget);
2405
Alexander Duyck12d04a32009-03-25 22:05:03 +00002406 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002407 work_done = budget;
2408
David S. Miller53e52c72008-01-07 21:06:12 -08002409 /* If budget not fully consumed, exit the polling mode */
2410 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002411 if (adapter->itr_setting & 3)
2412 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002413 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002414 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2415 if (adapter->msix_entries)
2416 ew32(IMS, adapter->rx_ring->ims_val);
2417 else
2418 e1000_irq_enable(adapter);
2419 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002420 }
2421
2422 return work_done;
2423}
2424
2425static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2426{
2427 struct e1000_adapter *adapter = netdev_priv(netdev);
2428 struct e1000_hw *hw = &adapter->hw;
2429 u32 vfta, index;
2430
2431 /* don't update vlan cookie if already programmed */
2432 if ((adapter->hw.mng_cookie.status &
2433 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2434 (vid == adapter->mng_vlan_id))
2435 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002436
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002438 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2439 index = (vid >> 5) & 0x7F;
2440 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2441 vfta |= (1 << (vid & 0x1F));
2442 hw->mac.ops.write_vfta(hw, index, vfta);
2443 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002444
2445 set_bit(vid, adapter->active_vlans);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446}
2447
2448static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2449{
2450 struct e1000_adapter *adapter = netdev_priv(netdev);
2451 struct e1000_hw *hw = &adapter->hw;
2452 u32 vfta, index;
2453
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 if ((adapter->hw.mng_cookie.status &
2455 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2456 (vid == adapter->mng_vlan_id)) {
2457 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002458 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002459 return;
2460 }
2461
2462 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002463 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2464 index = (vid >> 5) & 0x7F;
2465 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2466 vfta &= ~(1 << (vid & 0x1F));
2467 hw->mac.ops.write_vfta(hw, index, vfta);
2468 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002469
2470 clear_bit(vid, adapter->active_vlans);
2471}
2472
2473/**
2474 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2475 * @adapter: board private structure to initialize
2476 **/
2477static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2478{
2479 struct net_device *netdev = adapter->netdev;
2480 struct e1000_hw *hw = &adapter->hw;
2481 u32 rctl;
2482
2483 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2484 /* disable VLAN receive filtering */
2485 rctl = er32(RCTL);
2486 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2487 ew32(RCTL, rctl);
2488
2489 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2490 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2491 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2492 }
2493 }
2494}
2495
2496/**
2497 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2498 * @adapter: board private structure to initialize
2499 **/
2500static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2501{
2502 struct e1000_hw *hw = &adapter->hw;
2503 u32 rctl;
2504
2505 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2506 /* enable VLAN receive filtering */
2507 rctl = er32(RCTL);
2508 rctl |= E1000_RCTL_VFE;
2509 rctl &= ~E1000_RCTL_CFIEN;
2510 ew32(RCTL, rctl);
2511 }
2512}
2513
2514/**
2515 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2516 * @adapter: board private structure to initialize
2517 **/
2518static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2519{
2520 struct e1000_hw *hw = &adapter->hw;
2521 u32 ctrl;
2522
2523 /* disable VLAN tag insert/strip */
2524 ctrl = er32(CTRL);
2525 ctrl &= ~E1000_CTRL_VME;
2526 ew32(CTRL, ctrl);
2527}
2528
2529/**
2530 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2531 * @adapter: board private structure to initialize
2532 **/
2533static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2534{
2535 struct e1000_hw *hw = &adapter->hw;
2536 u32 ctrl;
2537
2538 /* enable VLAN tag insert/strip */
2539 ctrl = er32(CTRL);
2540 ctrl |= E1000_CTRL_VME;
2541 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002542}
2543
2544static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2545{
2546 struct net_device *netdev = adapter->netdev;
2547 u16 vid = adapter->hw.mng_cookie.vlan_id;
2548 u16 old_vid = adapter->mng_vlan_id;
2549
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002550 if (adapter->hw.mng_cookie.status &
2551 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2552 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002553 adapter->mng_vlan_id = vid;
2554 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002555
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002556 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2557 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002558}
2559
2560static void e1000_restore_vlan(struct e1000_adapter *adapter)
2561{
2562 u16 vid;
2563
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002564 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002565
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002566 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002567 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002568}
2569
Bruce Allancd791612010-05-10 14:59:51 +00002570static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002571{
2572 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002573 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002574
2575 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2576 return;
2577
2578 manc = er32(MANC);
2579
Bruce Allanad680762008-03-28 09:15:03 -07002580 /*
2581 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002582 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002583 * the packets will be handled on SMBUS
2584 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002585 manc |= E1000_MANC_EN_MNG2HOST;
2586 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002587
2588 switch (hw->mac.type) {
2589 default:
2590 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2591 break;
2592 case e1000_82574:
2593 case e1000_82583:
2594 /*
2595 * Check if IPMI pass-through decision filter already exists;
2596 * if so, enable it.
2597 */
2598 for (i = 0, j = 0; i < 8; i++) {
2599 mdef = er32(MDEF(i));
2600
2601 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002602 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002603 continue;
2604
2605 /* Enable this decision filter in MANC2H */
2606 if (mdef)
2607 manc2h |= (1 << i);
2608
2609 j |= mdef;
2610 }
2611
2612 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2613 break;
2614
2615 /* Create new decision filter in an empty filter */
2616 for (i = 0, j = 0; i < 8; i++)
2617 if (er32(MDEF(i)) == 0) {
2618 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2619 E1000_MDEF_PORT_664));
2620 manc2h |= (1 << 1);
2621 j++;
2622 break;
2623 }
2624
2625 if (!j)
2626 e_warn("Unable to create IPMI pass-through filter\n");
2627 break;
2628 }
2629
Auke Kokbc7f75f2007-09-17 12:30:59 -07002630 ew32(MANC2H, manc2h);
2631 ew32(MANC, manc);
2632}
2633
2634/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002635 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002636 * @adapter: board private structure
2637 *
2638 * Configure the Tx unit of the MAC after a reset.
2639 **/
2640static void e1000_configure_tx(struct e1000_adapter *adapter)
2641{
2642 struct e1000_hw *hw = &adapter->hw;
2643 struct e1000_ring *tx_ring = adapter->tx_ring;
2644 u64 tdba;
2645 u32 tdlen, tctl, tipg, tarc;
2646 u32 ipgr1, ipgr2;
2647
2648 /* Setup the HW Tx Head and Tail descriptor pointers */
2649 tdba = tx_ring->dma;
2650 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002651 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002652 ew32(TDBAH, (tdba >> 32));
2653 ew32(TDLEN, tdlen);
2654 ew32(TDH, 0);
2655 ew32(TDT, 0);
2656 tx_ring->head = E1000_TDH;
2657 tx_ring->tail = E1000_TDT;
2658
2659 /* Set the default values for the Tx Inter Packet Gap timer */
2660 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2661 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2662 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2663
2664 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2665 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2666
2667 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2668 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2669 ew32(TIPG, tipg);
2670
2671 /* Set the Tx Interrupt Delay register */
2672 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002673 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002674 ew32(TADV, adapter->tx_abs_int_delay);
2675
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002676 if (adapter->flags2 & FLAG2_DMA_BURST) {
2677 u32 txdctl = er32(TXDCTL(0));
2678 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2679 E1000_TXDCTL_WTHRESH);
2680 /*
2681 * set up some performance related parameters to encourage the
2682 * hardware to use the bus more efficiently in bursts, depends
2683 * on the tx_int_delay to be enabled,
2684 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2685 * hthresh = 1 ==> prefetch when one or more available
2686 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2687 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002688 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002689 */
2690 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2691 ew32(TXDCTL(0), txdctl);
2692 /* erratum work around: set txdctl the same for both queues */
2693 ew32(TXDCTL(1), txdctl);
2694 }
2695
Auke Kokbc7f75f2007-09-17 12:30:59 -07002696 /* Program the Transmit Control Register */
2697 tctl = er32(TCTL);
2698 tctl &= ~E1000_TCTL_CT;
2699 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2700 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2701
2702 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002703 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002704 /*
2705 * set the speed mode bit, we'll clear it if we're not at
2706 * gigabit link later
2707 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002708#define SPEED_MODE_BIT (1 << 21)
2709 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002710 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711 }
2712
2713 /* errata: program both queues to unweighted RR */
2714 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002715 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002716 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002717 ew32(TARC(0), tarc);
2718 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002719 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002720 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002721 }
2722
Auke Kokbc7f75f2007-09-17 12:30:59 -07002723 /* Setup Transmit Descriptor Settings for eop descriptor */
2724 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2725
2726 /* only set IDE if we are delaying interrupts using the timers */
2727 if (adapter->tx_int_delay)
2728 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2729
2730 /* enable Report Status bit */
2731 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2732
2733 ew32(TCTL, tctl);
2734
Simon Hormanedfea6e62009-06-08 14:28:36 +00002735 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002736}
2737
2738/**
2739 * e1000_setup_rctl - configure the receive control registers
2740 * @adapter: Board private structure
2741 **/
2742#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2743 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2744static void e1000_setup_rctl(struct e1000_adapter *adapter)
2745{
2746 struct e1000_hw *hw = &adapter->hw;
2747 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002748 u32 pages = 0;
2749
Bruce Allana1ce6472010-09-22 17:16:40 +00002750 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2751 if (hw->mac.type == e1000_pch2lan) {
2752 s32 ret_val;
2753
2754 if (adapter->netdev->mtu > ETH_DATA_LEN)
2755 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2756 else
2757 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002758
2759 if (ret_val)
2760 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002761 }
2762
Auke Kokbc7f75f2007-09-17 12:30:59 -07002763 /* Program MC offset vector base */
2764 rctl = er32(RCTL);
2765 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2766 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2767 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2768 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2769
2770 /* Do not Store bad packets */
2771 rctl &= ~E1000_RCTL_SBP;
2772
2773 /* Enable Long Packet receive */
2774 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2775 rctl &= ~E1000_RCTL_LPE;
2776 else
2777 rctl |= E1000_RCTL_LPE;
2778
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002779 /* Some systems expect that the CRC is included in SMBUS traffic. The
2780 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2781 * host memory when this is enabled
2782 */
2783 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2784 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002785
Bruce Allana4f58f52009-06-02 11:29:18 +00002786 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2787 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2788 u16 phy_data;
2789
2790 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2791 phy_data &= 0xfff8;
2792 phy_data |= (1 << 2);
2793 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2794
2795 e1e_rphy(hw, 22, &phy_data);
2796 phy_data &= 0x0fff;
2797 phy_data |= (1 << 14);
2798 e1e_wphy(hw, 0x10, 0x2823);
2799 e1e_wphy(hw, 0x11, 0x0003);
2800 e1e_wphy(hw, 22, phy_data);
2801 }
2802
Auke Kokbc7f75f2007-09-17 12:30:59 -07002803 /* Setup buffer sizes */
2804 rctl &= ~E1000_RCTL_SZ_4096;
2805 rctl |= E1000_RCTL_BSEX;
2806 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002807 case 2048:
2808 default:
2809 rctl |= E1000_RCTL_SZ_2048;
2810 rctl &= ~E1000_RCTL_BSEX;
2811 break;
2812 case 4096:
2813 rctl |= E1000_RCTL_SZ_4096;
2814 break;
2815 case 8192:
2816 rctl |= E1000_RCTL_SZ_8192;
2817 break;
2818 case 16384:
2819 rctl |= E1000_RCTL_SZ_16384;
2820 break;
2821 }
2822
2823 /*
2824 * 82571 and greater support packet-split where the protocol
2825 * header is placed in skb->data and the packet data is
2826 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2827 * In the case of a non-split, skb->data is linearly filled,
2828 * followed by the page buffers. Therefore, skb->data is
2829 * sized to hold the largest protocol header.
2830 *
2831 * allocations using alloc_page take too long for regular MTU
2832 * so only enable packet split for jumbo frames
2833 *
2834 * Using pages when the page size is greater than 16k wastes
2835 * a lot of memory, since we allocate 3 pages at all times
2836 * per packet.
2837 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fe2010-06-17 18:59:27 +00002839 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002840 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002841 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002842 else
2843 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844
2845 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002846 u32 psrctl = 0;
2847
Auke Kokbc7f75f2007-09-17 12:30:59 -07002848 /* Configure extra packet-split registers */
2849 rfctl = er32(RFCTL);
2850 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002851 /*
2852 * disable packet split support for IPv6 extension headers,
2853 * because some malformed IPv6 headers can hang the Rx
2854 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002855 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2856 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2857
2858 ew32(RFCTL, rfctl);
2859
Auke Kok140a7482007-10-25 13:57:58 -07002860 /* Enable Packet split descriptors */
2861 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002862
2863 psrctl |= adapter->rx_ps_bsize0 >>
2864 E1000_PSRCTL_BSIZE0_SHIFT;
2865
2866 switch (adapter->rx_ps_pages) {
2867 case 3:
2868 psrctl |= PAGE_SIZE <<
2869 E1000_PSRCTL_BSIZE3_SHIFT;
2870 case 2:
2871 psrctl |= PAGE_SIZE <<
2872 E1000_PSRCTL_BSIZE2_SHIFT;
2873 case 1:
2874 psrctl |= PAGE_SIZE >>
2875 E1000_PSRCTL_BSIZE1_SHIFT;
2876 break;
2877 }
2878
2879 ew32(PSRCTL, psrctl);
2880 }
2881
2882 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002883 /* just started the receive unit, no need to restart */
2884 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002885}
2886
2887/**
2888 * e1000_configure_rx - Configure Receive Unit after Reset
2889 * @adapter: board private structure
2890 *
2891 * Configure the Rx unit of the MAC after a reset.
2892 **/
2893static void e1000_configure_rx(struct e1000_adapter *adapter)
2894{
2895 struct e1000_hw *hw = &adapter->hw;
2896 struct e1000_ring *rx_ring = adapter->rx_ring;
2897 u64 rdba;
2898 u32 rdlen, rctl, rxcsum, ctrl_ext;
2899
2900 if (adapter->rx_ps_pages) {
2901 /* this is a 32 byte descriptor */
2902 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002903 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002904 adapter->clean_rx = e1000_clean_rx_irq_ps;
2905 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002906 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2907 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2908 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2909 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002910 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002911 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002912 adapter->clean_rx = e1000_clean_rx_irq;
2913 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2914 }
2915
2916 /* disable receives while setting up the descriptors */
2917 rctl = er32(RCTL);
2918 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2919 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00002920 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002921
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002922 if (adapter->flags2 & FLAG2_DMA_BURST) {
2923 /*
2924 * set the writeback threshold (only takes effect if the RDTR
2925 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00002926 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002927 * granularity = 01
2928 * wthresh = 04,
2929 * hthresh = 04,
2930 * pthresh = 0x20
2931 */
2932 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
2933 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
2934
2935 /*
2936 * override the delay timers for enabling bursting, only if
2937 * the value was not set by the user via module options
2938 */
2939 if (adapter->rx_int_delay == DEFAULT_RDTR)
2940 adapter->rx_int_delay = BURST_RDTR;
2941 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
2942 adapter->rx_abs_int_delay = BURST_RADV;
2943 }
2944
Auke Kokbc7f75f2007-09-17 12:30:59 -07002945 /* set the Receive Delay Timer Register */
2946 ew32(RDTR, adapter->rx_int_delay);
2947
2948 /* irq moderation */
2949 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00002950 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07002951 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002952
2953 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002954 /* Auto-Mask interrupts upon ICR access */
2955 ctrl_ext |= E1000_CTRL_EXT_IAME;
2956 ew32(IAM, 0xffffffff);
2957 ew32(CTRL_EXT, ctrl_ext);
2958 e1e_flush();
2959
Bruce Allanad680762008-03-28 09:15:03 -07002960 /*
2961 * Setup the HW Rx Head and Tail Descriptor Pointers and
2962 * the Base and Length of the Rx Descriptor Ring
2963 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002965 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002966 ew32(RDBAH, (rdba >> 32));
2967 ew32(RDLEN, rdlen);
2968 ew32(RDH, 0);
2969 ew32(RDT, 0);
2970 rx_ring->head = E1000_RDH;
2971 rx_ring->tail = E1000_RDT;
2972
2973 /* Enable Receive Checksum Offload for TCP and UDP */
2974 rxcsum = er32(RXCSUM);
2975 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2976 rxcsum |= E1000_RXCSUM_TUOFL;
2977
Bruce Allanad680762008-03-28 09:15:03 -07002978 /*
2979 * IPv4 payload checksum for UDP fragments must be
2980 * used in conjunction with packet-split.
2981 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002982 if (adapter->rx_ps_pages)
2983 rxcsum |= E1000_RXCSUM_IPPCSE;
2984 } else {
2985 rxcsum &= ~E1000_RXCSUM_TUOFL;
2986 /* no need to clear IPPCSE as it defaults to 0 */
2987 }
2988 ew32(RXCSUM, rxcsum);
2989
Bruce Allanad680762008-03-28 09:15:03 -07002990 /*
2991 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002992 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002993 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2994 */
Bruce Allan828bac82010-09-29 21:39:37 +00002995 if ((adapter->flags & FLAG_HAS_ERT) ||
2996 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00002997 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2998 u32 rxdctl = er32(RXDCTL(0));
2999 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00003000 if (adapter->flags & FLAG_HAS_ERT)
3001 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00003002 /*
3003 * With jumbo frames and early-receive enabled,
3004 * excessive C-state transition latencies result in
3005 * dropped transactions.
3006 */
Bruce Allanaf667a22010-12-31 06:10:01 +00003007 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003008 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003009 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3010 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003011 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003012 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003013
3014 /* Enable Receives */
3015 ew32(RCTL, rctl);
3016}
3017
3018/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003019 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07003020 * @hw: pointer to the HW structure
3021 * @mc_addr_list: array of multicast addresses to program
3022 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07003023 *
Bruce Allanab8932f2010-01-13 02:05:38 +00003024 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003025 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003026 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003027static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003028 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003029{
Bruce Allanab8932f2010-01-13 02:05:38 +00003030 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003031}
3032
3033/**
3034 * e1000_set_multi - Multicast and Promiscuous mode set
3035 * @netdev: network interface device structure
3036 *
3037 * The set_multi entry point is called whenever the multicast address
3038 * list or the network interface flags are updated. This routine is
3039 * responsible for configuring the hardware for proper multicast,
3040 * promiscuous mode, and all-multi behavior.
3041 **/
3042static void e1000_set_multi(struct net_device *netdev)
3043{
3044 struct e1000_adapter *adapter = netdev_priv(netdev);
3045 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003046 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003047 u8 *mta_list;
3048 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003049
3050 /* Check for Promiscuous and All Multicast modes */
3051
3052 rctl = er32(RCTL);
3053
3054 if (netdev->flags & IFF_PROMISC) {
3055 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003056 rctl &= ~E1000_RCTL_VFE;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003057 /* Do not hardware filter VLANs in promisc mode */
3058 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003059 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003060 if (netdev->flags & IFF_ALLMULTI) {
3061 rctl |= E1000_RCTL_MPE;
3062 rctl &= ~E1000_RCTL_UPE;
3063 } else {
3064 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3065 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003066 e1000e_vlan_filter_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003067 }
3068
3069 ew32(RCTL, rctl);
3070
Jiri Pirko7aeef972010-02-05 02:52:39 +00003071 if (!netdev_mc_empty(netdev)) {
Bruce Allan90da0662011-01-06 07:02:53 +00003072 int i = 0;
3073
Jiri Pirko7aeef972010-02-05 02:52:39 +00003074 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003075 if (!mta_list)
3076 return;
3077
3078 /* prepare a packed array of only addresses. */
Jiri Pirko22bedad32010-04-01 21:22:57 +00003079 netdev_for_each_mc_addr(ha, netdev)
3080 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081
Bruce Allanab8932f2010-01-13 02:05:38 +00003082 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003083 kfree(mta_list);
3084 } else {
3085 /*
3086 * if we're called from probe, we might not have
3087 * anything to do here, so clear out the list
3088 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003089 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003090 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003091
3092 if (netdev->features & NETIF_F_HW_VLAN_RX)
3093 e1000e_vlan_strip_enable(adapter);
3094 else
3095 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096}
3097
3098/**
Bruce Allanad680762008-03-28 09:15:03 -07003099 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003100 * @adapter: private board structure
3101 **/
3102static void e1000_configure(struct e1000_adapter *adapter)
3103{
3104 e1000_set_multi(adapter->netdev);
3105
3106 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003107 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003108
3109 e1000_configure_tx(adapter);
3110 e1000_setup_rctl(adapter);
3111 e1000_configure_rx(adapter);
Jeff Kirsherc2fed992011-07-12 16:10:12 +00003112 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring),
3113 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003114}
3115
3116/**
3117 * e1000e_power_up_phy - restore link in case the phy was powered down
3118 * @adapter: address of board private structure
3119 *
3120 * The phy may be powered down to save power and turn off link when the
3121 * driver is unloaded and wake on lan is not enabled (among others)
3122 * *** this routine MUST be followed by a call to e1000e_reset ***
3123 **/
3124void e1000e_power_up_phy(struct e1000_adapter *adapter)
3125{
Bruce Allan17f208d2009-12-01 15:47:22 +00003126 if (adapter->hw.phy.ops.power_up)
3127 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128
3129 adapter->hw.mac.ops.setup_link(&adapter->hw);
3130}
3131
3132/**
3133 * e1000_power_down_phy - Power down the PHY
3134 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003135 * Power down the PHY so no link is implied when interface is down.
3136 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003137 */
3138static void e1000_power_down_phy(struct e1000_adapter *adapter)
3139{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003140 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003141 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003142 return;
3143
Bruce Allan17f208d2009-12-01 15:47:22 +00003144 if (adapter->hw.phy.ops.power_down)
3145 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146}
3147
3148/**
3149 * e1000e_reset - bring the hardware into a known good state
3150 *
3151 * This function boots the hardware and enables some settings that
3152 * require a configuration cycle of the hardware - those cannot be
3153 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003154 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003155 */
3156void e1000e_reset(struct e1000_adapter *adapter)
3157{
3158 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003159 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003160 struct e1000_hw *hw = &adapter->hw;
3161 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003162 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003163 u16 hwm;
3164
Bruce Allanad680762008-03-28 09:15:03 -07003165 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003166 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003167
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003168 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003169 /*
3170 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003171 * large enough to accommodate two full transmit packets,
3172 * rounded up to the next 1KB and expressed in KB. Likewise,
3173 * the Rx FIFO should be large enough to accommodate at least
3174 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003175 * expressed in KB.
3176 */
Auke Kokdf762462007-10-25 13:57:53 -07003177 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003178 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003179 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003180 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003181 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003182 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003183 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003184 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003185 */
3186 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003187 sizeof(struct e1000_tx_desc) -
3188 ETH_FCS_LEN) * 2;
3189 min_tx_space = ALIGN(min_tx_space, 1024);
3190 min_tx_space >>= 10;
3191 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003192 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003193 min_rx_space = ALIGN(min_rx_space, 1024);
3194 min_rx_space >>= 10;
3195
Bruce Allanad680762008-03-28 09:15:03 -07003196 /*
3197 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003198 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003199 * allocation, take space away from current Rx allocation
3200 */
Auke Kokdf762462007-10-25 13:57:53 -07003201 if ((tx_space < min_tx_space) &&
3202 ((min_tx_space - tx_space) < pba)) {
3203 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003204
Bruce Allanad680762008-03-28 09:15:03 -07003205 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003206 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003207 * adjustment or use Early Receive if available
3208 */
Auke Kokdf762462007-10-25 13:57:53 -07003209 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003210 (!(adapter->flags & FLAG_HAS_ERT)))
3211 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003212 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003213 }
Auke Kokdf762462007-10-25 13:57:53 -07003214
3215 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003216 }
3217
Bruce Allanad680762008-03-28 09:15:03 -07003218 /*
3219 * flow control settings
3220 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003221 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003222 * (or the size used for early receive) above it in the Rx FIFO.
3223 * Set it to the lower of:
3224 * - 90% of the Rx FIFO size, and
3225 * - the full Rx FIFO size minus the early receive size (for parts
3226 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003227 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003228 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003229 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3230 fc->pause_time = 0xFFFF;
3231 else
3232 fc->pause_time = E1000_FC_PAUSE_TIME;
3233 fc->send_xon = 1;
3234 fc->current_mode = fc->requested_mode;
3235
3236 switch (hw->mac.type) {
3237 default:
3238 if ((adapter->flags & FLAG_HAS_ERT) &&
3239 (adapter->netdev->mtu > ETH_DATA_LEN))
3240 hwm = min(((pba << 10) * 9 / 10),
3241 ((pba << 10) - (E1000_ERT_2048 << 3)));
3242 else
3243 hwm = min(((pba << 10) * 9 / 10),
3244 ((pba << 10) - adapter->max_frame_size));
3245
3246 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3247 fc->low_water = fc->high_water - 8;
3248 break;
3249 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003250 /*
3251 * Workaround PCH LOM adapter hangs with certain network
3252 * loads. If hangs persist, try disabling Tx flow control.
3253 */
3254 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3255 fc->high_water = 0x3500;
3256 fc->low_water = 0x1500;
3257 } else {
3258 fc->high_water = 0x5000;
3259 fc->low_water = 0x3000;
3260 }
Bruce Allana3055952010-05-10 15:02:12 +00003261 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003262 break;
3263 case e1000_pch2lan:
3264 fc->high_water = 0x05C20;
3265 fc->low_water = 0x05048;
3266 fc->pause_time = 0x0650;
3267 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003268 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3269 pba = 14;
3270 ew32(PBA, pba);
3271 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003272 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003273 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003274
Bruce Allan828bac82010-09-29 21:39:37 +00003275 /*
3276 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3277 * fit in receive buffer and early-receive not supported.
3278 */
3279 if (adapter->itr_setting & 0x3) {
3280 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3281 !(adapter->flags & FLAG_HAS_ERT)) {
3282 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3283 dev_info(&adapter->pdev->dev,
3284 "Interrupt Throttle Rate turned off\n");
3285 adapter->flags2 |= FLAG2_DISABLE_AIM;
3286 ew32(ITR, 0);
3287 }
3288 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3289 dev_info(&adapter->pdev->dev,
3290 "Interrupt Throttle Rate turned on\n");
3291 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3292 adapter->itr = 20000;
3293 ew32(ITR, 1000000000 / (adapter->itr * 256));
3294 }
3295 }
3296
Auke Kokbc7f75f2007-09-17 12:30:59 -07003297 /* Allow time for pending master requests to run */
3298 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003299
3300 /*
3301 * For parts with AMT enabled, let the firmware know
3302 * that the network interface is in control
3303 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003304 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003305 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003306
Auke Kokbc7f75f2007-09-17 12:30:59 -07003307 ew32(WUC, 0);
3308
3309 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003310 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003311
3312 e1000_update_mng_vlan(adapter);
3313
3314 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3315 ew32(VET, ETH_P_8021Q);
3316
3317 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003318
3319 if (!netif_running(adapter->netdev) &&
3320 !test_bit(__E1000_TESTING, &adapter->state)) {
3321 e1000_power_down_phy(adapter);
3322 return;
3323 }
3324
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325 e1000_get_phy_info(hw);
3326
Bruce Allan918d7192009-06-02 11:28:20 +00003327 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3328 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003329 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003330 /*
3331 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003332 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003333 * different we would do if it failed
3334 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003335 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3336 phy_data &= ~IGP02E1000_PM_SPD;
3337 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3338 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003339}
3340
3341int e1000e_up(struct e1000_adapter *adapter)
3342{
3343 struct e1000_hw *hw = &adapter->hw;
3344
3345 /* hardware has been reset, we need to reload some things */
3346 e1000_configure(adapter);
3347
3348 clear_bit(__E1000_DOWN, &adapter->state);
3349
3350 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003351 if (adapter->msix_entries)
3352 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003353 e1000_irq_enable(adapter);
3354
Bruce Allan400484f2011-05-13 07:20:03 +00003355 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003356
Auke Kokbc7f75f2007-09-17 12:30:59 -07003357 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003358 if (adapter->msix_entries)
3359 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3360 else
3361 ew32(ICS, E1000_ICS_LSC);
3362
Auke Kokbc7f75f2007-09-17 12:30:59 -07003363 return 0;
3364}
3365
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003366static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3367{
3368 struct e1000_hw *hw = &adapter->hw;
3369
3370 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3371 return;
3372
3373 /* flush pending descriptor writebacks to memory */
3374 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3375 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3376
3377 /* execute the writes immediately */
3378 e1e_flush();
3379}
3380
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003381static void e1000e_update_stats(struct e1000_adapter *adapter);
3382
Auke Kokbc7f75f2007-09-17 12:30:59 -07003383void e1000e_down(struct e1000_adapter *adapter)
3384{
3385 struct net_device *netdev = adapter->netdev;
3386 struct e1000_hw *hw = &adapter->hw;
3387 u32 tctl, rctl;
3388
Bruce Allanad680762008-03-28 09:15:03 -07003389 /*
3390 * signal that we're down so the interrupt handler does not
3391 * reschedule our watchdog timer
3392 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003393 set_bit(__E1000_DOWN, &adapter->state);
3394
3395 /* disable receives in the hardware */
3396 rctl = er32(RCTL);
3397 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3398 /* flush and sleep below */
3399
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003400 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003401
3402 /* disable transmits in the hardware */
3403 tctl = er32(TCTL);
3404 tctl &= ~E1000_TCTL_EN;
3405 ew32(TCTL, tctl);
3406 /* flush both disables and wait for them to finish */
3407 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003408 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003409
3410 napi_disable(&adapter->napi);
3411 e1000_irq_disable(adapter);
3412
3413 del_timer_sync(&adapter->watchdog_timer);
3414 del_timer_sync(&adapter->phy_info_timer);
3415
Auke Kokbc7f75f2007-09-17 12:30:59 -07003416 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003417
3418 spin_lock(&adapter->stats64_lock);
3419 e1000e_update_stats(adapter);
3420 spin_unlock(&adapter->stats64_lock);
3421
Bruce Allan400484f2011-05-13 07:20:03 +00003422 e1000e_flush_descriptors(adapter);
3423 e1000_clean_tx_ring(adapter);
3424 e1000_clean_rx_ring(adapter);
3425
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426 adapter->link_speed = 0;
3427 adapter->link_duplex = 0;
3428
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003429 if (!pci_channel_offline(adapter->pdev))
3430 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003431
Auke Kokbc7f75f2007-09-17 12:30:59 -07003432 /*
3433 * TODO: for power management, we could drop the link and
3434 * pci_disable_device here.
3435 */
3436}
3437
3438void e1000e_reinit_locked(struct e1000_adapter *adapter)
3439{
3440 might_sleep();
3441 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003442 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003443 e1000e_down(adapter);
3444 e1000e_up(adapter);
3445 clear_bit(__E1000_RESETTING, &adapter->state);
3446}
3447
3448/**
3449 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3450 * @adapter: board private structure to initialize
3451 *
3452 * e1000_sw_init initializes the Adapter private data structure.
3453 * Fields are initialized based on PCI device information and
3454 * OS network device settings (MTU size).
3455 **/
3456static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3457{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003458 struct net_device *netdev = adapter->netdev;
3459
3460 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3461 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003462 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3463 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003464
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003465 spin_lock_init(&adapter->stats64_lock);
3466
Bruce Allan4662e822008-08-26 18:37:06 -07003467 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003468
Bruce Allan4662e822008-08-26 18:37:06 -07003469 if (e1000_alloc_queues(adapter))
3470 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003471
Auke Kokbc7f75f2007-09-17 12:30:59 -07003472 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003473 e1000_irq_disable(adapter);
3474
Auke Kokbc7f75f2007-09-17 12:30:59 -07003475 set_bit(__E1000_DOWN, &adapter->state);
3476 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003477}
3478
3479/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003480 * e1000_intr_msi_test - Interrupt Handler
3481 * @irq: interrupt number
3482 * @data: pointer to a network interface device structure
3483 **/
3484static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3485{
3486 struct net_device *netdev = data;
3487 struct e1000_adapter *adapter = netdev_priv(netdev);
3488 struct e1000_hw *hw = &adapter->hw;
3489 u32 icr = er32(ICR);
3490
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003491 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003492 if (icr & E1000_ICR_RXSEQ) {
3493 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3494 wmb();
3495 }
3496
3497 return IRQ_HANDLED;
3498}
3499
3500/**
3501 * e1000_test_msi_interrupt - Returns 0 for successful test
3502 * @adapter: board private struct
3503 *
3504 * code flow taken from tg3.c
3505 **/
3506static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3507{
3508 struct net_device *netdev = adapter->netdev;
3509 struct e1000_hw *hw = &adapter->hw;
3510 int err;
3511
3512 /* poll_enable hasn't been called yet, so don't need disable */
3513 /* clear any pending events */
3514 er32(ICR);
3515
3516 /* free the real vector and request a test handler */
3517 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003518 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003519
3520 /* Assume that the test fails, if it succeeds then the test
3521 * MSI irq handler will unset this flag */
3522 adapter->flags |= FLAG_MSI_TEST_FAILED;
3523
3524 err = pci_enable_msi(adapter->pdev);
3525 if (err)
3526 goto msi_test_failed;
3527
Joe Perchesa0607fd2009-11-18 23:29:17 -08003528 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003529 netdev->name, netdev);
3530 if (err) {
3531 pci_disable_msi(adapter->pdev);
3532 goto msi_test_failed;
3533 }
3534
3535 wmb();
3536
3537 e1000_irq_enable(adapter);
3538
3539 /* fire an unusual interrupt on the test handler */
3540 ew32(ICS, E1000_ICS_RXSEQ);
3541 e1e_flush();
3542 msleep(50);
3543
3544 e1000_irq_disable(adapter);
3545
3546 rmb();
3547
3548 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003549 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003550 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3551 } else
3552 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003553
3554 free_irq(adapter->pdev->irq, netdev);
3555 pci_disable_msi(adapter->pdev);
3556
Bruce Allanf8d59f72008-08-08 18:36:11 -07003557msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003558 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003559 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003560}
3561
3562/**
3563 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3564 * @adapter: board private struct
3565 *
3566 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3567 **/
3568static int e1000_test_msi(struct e1000_adapter *adapter)
3569{
3570 int err;
3571 u16 pci_cmd;
3572
3573 if (!(adapter->flags & FLAG_MSI_ENABLED))
3574 return 0;
3575
3576 /* disable SERR in case the MSI write causes a master abort */
3577 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003578 if (pci_cmd & PCI_COMMAND_SERR)
3579 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3580 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003581
3582 err = e1000_test_msi_interrupt(adapter);
3583
Dean Nelson36f24072010-06-29 18:12:05 +00003584 /* re-enable SERR */
3585 if (pci_cmd & PCI_COMMAND_SERR) {
3586 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3587 pci_cmd |= PCI_COMMAND_SERR;
3588 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3589 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003590
Bruce Allanf8d59f72008-08-08 18:36:11 -07003591 return err;
3592}
3593
3594/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003595 * e1000_open - Called when a network interface is made active
3596 * @netdev: network interface device structure
3597 *
3598 * Returns 0 on success, negative value on failure
3599 *
3600 * The open entry point is called when a network interface is made
3601 * active by the system (IFF_UP). At this point all resources needed
3602 * for transmit and receive operations are allocated, the interrupt
3603 * handler is registered with the OS, the watchdog timer is started,
3604 * and the stack is notified that the interface is ready.
3605 **/
3606static int e1000_open(struct net_device *netdev)
3607{
3608 struct e1000_adapter *adapter = netdev_priv(netdev);
3609 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003610 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003611 int err;
3612
3613 /* disallow open during test */
3614 if (test_bit(__E1000_TESTING, &adapter->state))
3615 return -EBUSY;
3616
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003617 pm_runtime_get_sync(&pdev->dev);
3618
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003619 netif_carrier_off(netdev);
3620
Auke Kokbc7f75f2007-09-17 12:30:59 -07003621 /* allocate transmit descriptors */
3622 err = e1000e_setup_tx_resources(adapter);
3623 if (err)
3624 goto err_setup_tx;
3625
3626 /* allocate receive descriptors */
3627 err = e1000e_setup_rx_resources(adapter);
3628 if (err)
3629 goto err_setup_rx;
3630
Bruce Allan11b08be2010-05-10 14:59:31 +00003631 /*
3632 * If AMT is enabled, let the firmware know that the network
3633 * interface is now open and reset the part to a known state.
3634 */
3635 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003636 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003637 e1000e_reset(adapter);
3638 }
3639
Auke Kokbc7f75f2007-09-17 12:30:59 -07003640 e1000e_power_up_phy(adapter);
3641
3642 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3643 if ((adapter->hw.mng_cookie.status &
3644 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3645 e1000_update_mng_vlan(adapter);
3646
Florian Micklerc128ec22010-08-02 14:27:00 +00003647 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003648 if ((adapter->flags & FLAG_HAS_ERT) ||
3649 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003650 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3651 PM_QOS_CPU_DMA_LATENCY,
3652 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003653
Bruce Allanad680762008-03-28 09:15:03 -07003654 /*
Bruce Allanad680762008-03-28 09:15:03 -07003655 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3657 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003658 * clean_rx handler before we do so.
3659 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003660 e1000_configure(adapter);
3661
3662 err = e1000_request_irq(adapter);
3663 if (err)
3664 goto err_req_irq;
3665
Bruce Allanf8d59f72008-08-08 18:36:11 -07003666 /*
3667 * Work around PCIe errata with MSI interrupts causing some chipsets to
3668 * ignore e1000e MSI messages, which means we need to test our MSI
3669 * interrupt now
3670 */
Bruce Allan4662e822008-08-26 18:37:06 -07003671 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003672 err = e1000_test_msi(adapter);
3673 if (err) {
3674 e_err("Interrupt allocation failed\n");
3675 goto err_req_irq;
3676 }
3677 }
3678
Auke Kokbc7f75f2007-09-17 12:30:59 -07003679 /* From here on the code is the same as e1000e_up() */
3680 clear_bit(__E1000_DOWN, &adapter->state);
3681
3682 napi_enable(&adapter->napi);
3683
3684 e1000_irq_enable(adapter);
3685
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003686 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003687
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003688 adapter->idle_check = true;
3689 pm_runtime_put(&pdev->dev);
3690
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003692 if (adapter->msix_entries)
3693 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3694 else
3695 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696
3697 return 0;
3698
3699err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003700 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003701 e1000_power_down_phy(adapter);
3702 e1000e_free_rx_resources(adapter);
3703err_setup_rx:
3704 e1000e_free_tx_resources(adapter);
3705err_setup_tx:
3706 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003707 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003708
3709 return err;
3710}
3711
3712/**
3713 * e1000_close - Disables a network interface
3714 * @netdev: network interface device structure
3715 *
3716 * Returns 0, this is not allowed to fail
3717 *
3718 * The close entry point is called when an interface is de-activated
3719 * by the OS. The hardware is still under the drivers control, but
3720 * needs to be disabled. A global MAC reset is issued to stop the
3721 * hardware, and all transmit and receive resources are freed.
3722 **/
3723static int e1000_close(struct net_device *netdev)
3724{
3725 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003726 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003727
3728 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003729
3730 pm_runtime_get_sync(&pdev->dev);
3731
3732 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3733 e1000e_down(adapter);
3734 e1000_free_irq(adapter);
3735 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003736 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003737
3738 e1000e_free_tx_resources(adapter);
3739 e1000e_free_rx_resources(adapter);
3740
Bruce Allanad680762008-03-28 09:15:03 -07003741 /*
3742 * kill manageability vlan ID if supported, but not if a vlan with
3743 * the same ID is registered on the host OS (let 8021q kill it)
3744 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003745 if (adapter->hw.mng_cookie.status &
3746 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003747 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3748
Bruce Allanad680762008-03-28 09:15:03 -07003749 /*
3750 * If AMT is enabled, let the firmware know that the network
3751 * interface is now closed
3752 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003753 if ((adapter->flags & FLAG_HAS_AMT) &&
3754 !test_bit(__E1000_TESTING, &adapter->state))
3755 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003756
Bruce Allan828bac82010-09-29 21:39:37 +00003757 if ((adapter->flags & FLAG_HAS_ERT) ||
3758 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003759 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003760
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003761 pm_runtime_put_sync(&pdev->dev);
3762
Auke Kokbc7f75f2007-09-17 12:30:59 -07003763 return 0;
3764}
3765/**
3766 * e1000_set_mac - Change the Ethernet Address of the NIC
3767 * @netdev: network interface device structure
3768 * @p: pointer to an address structure
3769 *
3770 * Returns 0 on success, negative on failure
3771 **/
3772static int e1000_set_mac(struct net_device *netdev, void *p)
3773{
3774 struct e1000_adapter *adapter = netdev_priv(netdev);
3775 struct sockaddr *addr = p;
3776
3777 if (!is_valid_ether_addr(addr->sa_data))
3778 return -EADDRNOTAVAIL;
3779
3780 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3781 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3782
3783 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3784
3785 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3786 /* activate the work around */
3787 e1000e_set_laa_state_82571(&adapter->hw, 1);
3788
Bruce Allanad680762008-03-28 09:15:03 -07003789 /*
3790 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003791 * between the time RAR[0] gets clobbered and the time it
3792 * gets fixed (in e1000_watchdog), the actual LAA is in one
3793 * of the RARs and no incoming packets directed to this port
3794 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003795 * RAR[14]
3796 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003797 e1000e_rar_set(&adapter->hw,
3798 adapter->hw.mac.addr,
3799 adapter->hw.mac.rar_entry_count - 1);
3800 }
3801
3802 return 0;
3803}
3804
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003805/**
3806 * e1000e_update_phy_task - work thread to update phy
3807 * @work: pointer to our work struct
3808 *
3809 * this worker thread exists because we must acquire a
3810 * semaphore to read the phy, which we could msleep while
3811 * waiting for it, and we can't msleep in a timer.
3812 **/
3813static void e1000e_update_phy_task(struct work_struct *work)
3814{
3815 struct e1000_adapter *adapter = container_of(work,
3816 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003817
3818 if (test_bit(__E1000_DOWN, &adapter->state))
3819 return;
3820
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003821 e1000_get_phy_info(&adapter->hw);
3822}
3823
Bruce Allanad680762008-03-28 09:15:03 -07003824/*
3825 * Need to wait a few seconds after link up to get diagnostic information from
3826 * the phy
3827 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003828static void e1000_update_phy_info(unsigned long data)
3829{
3830 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003831
3832 if (test_bit(__E1000_DOWN, &adapter->state))
3833 return;
3834
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003835 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003836}
3837
3838/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003839 * e1000e_update_phy_stats - Update the PHY statistics counters
3840 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00003841 *
3842 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003843 **/
3844static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3845{
3846 struct e1000_hw *hw = &adapter->hw;
3847 s32 ret_val;
3848 u16 phy_data;
3849
3850 ret_val = hw->phy.ops.acquire(hw);
3851 if (ret_val)
3852 return;
3853
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003854 /*
3855 * A page set is expensive so check if already on desired page.
3856 * If not, set to the page with the PHY status registers.
3857 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003858 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003859 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3860 &phy_data);
3861 if (ret_val)
3862 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00003863 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
3864 ret_val = hw->phy.ops.set_page(hw,
3865 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003866 if (ret_val)
3867 goto release;
3868 }
3869
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003870 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003871 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
3872 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003873 if (!ret_val)
3874 adapter->stats.scc += phy_data;
3875
3876 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003877 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
3878 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003879 if (!ret_val)
3880 adapter->stats.ecol += phy_data;
3881
3882 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003883 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
3884 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003885 if (!ret_val)
3886 adapter->stats.mcc += phy_data;
3887
3888 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003889 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
3890 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003891 if (!ret_val)
3892 adapter->stats.latecol += phy_data;
3893
3894 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003895 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
3896 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003897 if (!ret_val)
3898 hw->mac.collision_delta = phy_data;
3899
3900 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003901 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
3902 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003903 if (!ret_val)
3904 adapter->stats.dc += phy_data;
3905
3906 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003907 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
3908 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003909 if (!ret_val)
3910 adapter->stats.tncrs += phy_data;
3911
3912release:
3913 hw->phy.ops.release(hw);
3914}
3915
3916/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003917 * e1000e_update_stats - Update the board statistics counters
3918 * @adapter: board private structure
3919 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003920static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003921{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003922 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003923 struct e1000_hw *hw = &adapter->hw;
3924 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003925
3926 /*
3927 * Prevent stats update while adapter is being reset, or if the pci
3928 * connection is down.
3929 */
3930 if (adapter->link_speed == 0)
3931 return;
3932 if (pci_channel_offline(pdev))
3933 return;
3934
Auke Kokbc7f75f2007-09-17 12:30:59 -07003935 adapter->stats.crcerrs += er32(CRCERRS);
3936 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003937 adapter->stats.gorc += er32(GORCL);
3938 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003939 adapter->stats.bprc += er32(BPRC);
3940 adapter->stats.mprc += er32(MPRC);
3941 adapter->stats.roc += er32(ROC);
3942
Auke Kokbc7f75f2007-09-17 12:30:59 -07003943 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003944
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003945 /* Half-duplex statistics */
3946 if (adapter->link_duplex == HALF_DUPLEX) {
3947 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
3948 e1000e_update_phy_stats(adapter);
3949 } else {
3950 adapter->stats.scc += er32(SCC);
3951 adapter->stats.ecol += er32(ECOL);
3952 adapter->stats.mcc += er32(MCC);
3953 adapter->stats.latecol += er32(LATECOL);
3954 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003955
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003956 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003957
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003958 if ((hw->mac.type != e1000_82574) &&
3959 (hw->mac.type != e1000_82583))
3960 adapter->stats.tncrs += er32(TNCRS);
3961 }
3962 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003963 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003964
Auke Kokbc7f75f2007-09-17 12:30:59 -07003965 adapter->stats.xonrxc += er32(XONRXC);
3966 adapter->stats.xontxc += er32(XONTXC);
3967 adapter->stats.xoffrxc += er32(XOFFRXC);
3968 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003969 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003970 adapter->stats.gotc += er32(GOTCL);
3971 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003972 adapter->stats.rnbc += er32(RNBC);
3973 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003974
3975 adapter->stats.mptc += er32(MPTC);
3976 adapter->stats.bptc += er32(BPTC);
3977
3978 /* used for adaptive IFS */
3979
3980 hw->mac.tx_packet_delta = er32(TPT);
3981 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003982
3983 adapter->stats.algnerrc += er32(ALGNERRC);
3984 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003985 adapter->stats.cexterr += er32(CEXTERR);
3986 adapter->stats.tsctc += er32(TSCTC);
3987 adapter->stats.tsctfc += er32(TSCTFC);
3988
Auke Kokbc7f75f2007-09-17 12:30:59 -07003989 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003990 netdev->stats.multicast = adapter->stats.mprc;
3991 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003992
3993 /* Rx Errors */
3994
Bruce Allanad680762008-03-28 09:15:03 -07003995 /*
3996 * RLEC on some newer hardware can be incorrect so build
3997 * our own version based on RUC and ROC
3998 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003999 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004000 adapter->stats.crcerrs + adapter->stats.algnerrc +
4001 adapter->stats.ruc + adapter->stats.roc +
4002 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004003 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004004 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004005 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4006 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4007 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008
4009 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004010 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004011 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004012 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4013 netdev->stats.tx_window_errors = adapter->stats.latecol;
4014 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004015
4016 /* Tx Dropped needs to be maintained elsewhere */
4017
Auke Kokbc7f75f2007-09-17 12:30:59 -07004018 /* Management Stats */
4019 adapter->stats.mgptc += er32(MGTPTC);
4020 adapter->stats.mgprc += er32(MGTPRC);
4021 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004022}
4023
Bruce Allan7c257692008-04-23 11:09:00 -07004024/**
4025 * e1000_phy_read_status - Update the PHY register status snapshot
4026 * @adapter: board private structure
4027 **/
4028static void e1000_phy_read_status(struct e1000_adapter *adapter)
4029{
4030 struct e1000_hw *hw = &adapter->hw;
4031 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004032
4033 if ((er32(STATUS) & E1000_STATUS_LU) &&
4034 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004035 int ret_val;
4036
Bruce Allan7c257692008-04-23 11:09:00 -07004037 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4038 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4039 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4040 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4041 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4042 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4043 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4044 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4045 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004046 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004047 } else {
4048 /*
4049 * Do not read PHY registers if link is not up
4050 * Set values to typical power-on defaults
4051 */
4052 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4053 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4054 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4055 BMSR_ERCAP);
4056 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4057 ADVERTISE_ALL | ADVERTISE_CSMA);
4058 phy->lpa = 0;
4059 phy->expansion = EXPANSION_ENABLENPAGE;
4060 phy->ctrl1000 = ADVERTISE_1000FULL;
4061 phy->stat1000 = 0;
4062 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4063 }
Bruce Allan7c257692008-04-23 11:09:00 -07004064}
4065
Auke Kokbc7f75f2007-09-17 12:30:59 -07004066static void e1000_print_link_info(struct e1000_adapter *adapter)
4067{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004068 struct e1000_hw *hw = &adapter->hw;
4069 u32 ctrl = er32(CTRL);
4070
Bruce Allan8f12fe82008-11-21 16:54:43 -08004071 /* Link status message must follow this format for user tools */
4072 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4073 "Flow Control: %s\n",
4074 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004075 adapter->link_speed,
4076 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004077 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004078 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004079 "Rx/Tx" :
4080 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4081 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004082}
4083
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004084static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004085{
4086 struct e1000_hw *hw = &adapter->hw;
4087 bool link_active = 0;
4088 s32 ret_val = 0;
4089
4090 /*
4091 * get_link_status is set on LSC (link status) interrupt or
4092 * Rx sequence error interrupt. get_link_status will stay
4093 * false until the check_for_link establishes link
4094 * for copper adapters ONLY
4095 */
4096 switch (hw->phy.media_type) {
4097 case e1000_media_type_copper:
4098 if (hw->mac.get_link_status) {
4099 ret_val = hw->mac.ops.check_for_link(hw);
4100 link_active = !hw->mac.get_link_status;
4101 } else {
4102 link_active = 1;
4103 }
4104 break;
4105 case e1000_media_type_fiber:
4106 ret_val = hw->mac.ops.check_for_link(hw);
4107 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4108 break;
4109 case e1000_media_type_internal_serdes:
4110 ret_val = hw->mac.ops.check_for_link(hw);
4111 link_active = adapter->hw.mac.serdes_has_link;
4112 break;
4113 default:
4114 case e1000_media_type_unknown:
4115 break;
4116 }
4117
4118 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4119 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4120 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004121 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004122 }
4123
4124 return link_active;
4125}
4126
4127static void e1000e_enable_receives(struct e1000_adapter *adapter)
4128{
4129 /* make sure the receive unit is started */
4130 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4131 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4132 struct e1000_hw *hw = &adapter->hw;
4133 u32 rctl = er32(RCTL);
4134 ew32(RCTL, rctl | E1000_RCTL_EN);
4135 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4136 }
4137}
4138
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004139static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4140{
4141 struct e1000_hw *hw = &adapter->hw;
4142
4143 /*
4144 * With 82574 controllers, PHY needs to be checked periodically
4145 * for hung state and reset, if two calls return true
4146 */
4147 if (e1000_check_phy_82574(hw))
4148 adapter->phy_hang_count++;
4149 else
4150 adapter->phy_hang_count = 0;
4151
4152 if (adapter->phy_hang_count > 1) {
4153 adapter->phy_hang_count = 0;
4154 schedule_work(&adapter->reset_task);
4155 }
4156}
4157
Auke Kokbc7f75f2007-09-17 12:30:59 -07004158/**
4159 * e1000_watchdog - Timer Call-back
4160 * @data: pointer to adapter cast into an unsigned long
4161 **/
4162static void e1000_watchdog(unsigned long data)
4163{
4164 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4165
4166 /* Do the rest outside of interrupt context */
4167 schedule_work(&adapter->watchdog_task);
4168
4169 /* TODO: make this use queue_delayed_work() */
4170}
4171
4172static void e1000_watchdog_task(struct work_struct *work)
4173{
4174 struct e1000_adapter *adapter = container_of(work,
4175 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176 struct net_device *netdev = adapter->netdev;
4177 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004178 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004179 struct e1000_ring *tx_ring = adapter->tx_ring;
4180 struct e1000_hw *hw = &adapter->hw;
4181 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004182
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004183 if (test_bit(__E1000_DOWN, &adapter->state))
4184 return;
4185
David S. Millerb405e8d2010-02-04 22:31:41 -08004186 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004187 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004188 /* Cancel scheduled suspend requests. */
4189 pm_runtime_resume(netdev->dev.parent);
4190
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004191 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004192 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004193 }
4194
4195 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4196 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4197 e1000_update_mng_vlan(adapter);
4198
Auke Kokbc7f75f2007-09-17 12:30:59 -07004199 if (link) {
4200 if (!netif_carrier_ok(netdev)) {
4201 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004202
4203 /* Cancel scheduled suspend requests. */
4204 pm_runtime_resume(netdev->dev.parent);
4205
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004206 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004207 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004208 mac->ops.get_link_up_info(&adapter->hw,
4209 &adapter->link_speed,
4210 &adapter->link_duplex);
4211 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004212 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004213 * On supported PHYs, check for duplex mismatch only
4214 * if link has autonegotiated at 10/100 half
4215 */
4216 if ((hw->phy.type == e1000_phy_igp_3 ||
4217 hw->phy.type == e1000_phy_bm) &&
4218 (hw->mac.autoneg == true) &&
4219 (adapter->link_speed == SPEED_10 ||
4220 adapter->link_speed == SPEED_100) &&
4221 (adapter->link_duplex == HALF_DUPLEX)) {
4222 u16 autoneg_exp;
4223
4224 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4225
4226 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4227 e_info("Autonegotiated half duplex but"
4228 " link partner cannot autoneg. "
4229 " Try forcing full duplex if "
4230 "link gets many collisions.\n");
4231 }
4232
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004233 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004234 adapter->tx_timeout_factor = 1;
4235 switch (adapter->link_speed) {
4236 case SPEED_10:
4237 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004238 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004239 break;
4240 case SPEED_100:
4241 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004242 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004243 break;
4244 }
4245
Bruce Allanad680762008-03-28 09:15:03 -07004246 /*
4247 * workaround: re-program speed mode bit after
4248 * link-up event
4249 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004250 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4251 !txb2b) {
4252 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004253 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004254 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004255 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004256 }
4257
Bruce Allanad680762008-03-28 09:15:03 -07004258 /*
4259 * disable TSO for pcie and 10/100 speeds, to avoid
4260 * some hardware issues
4261 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004262 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4263 switch (adapter->link_speed) {
4264 case SPEED_10:
4265 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004266 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004267 netdev->features &= ~NETIF_F_TSO;
4268 netdev->features &= ~NETIF_F_TSO6;
4269 break;
4270 case SPEED_1000:
4271 netdev->features |= NETIF_F_TSO;
4272 netdev->features |= NETIF_F_TSO6;
4273 break;
4274 default:
4275 /* oops */
4276 break;
4277 }
4278 }
4279
Bruce Allanad680762008-03-28 09:15:03 -07004280 /*
4281 * enable transmits in the hardware, need to do this
4282 * after setting TARC(0)
4283 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004284 tctl = er32(TCTL);
4285 tctl |= E1000_TCTL_EN;
4286 ew32(TCTL, tctl);
4287
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004288 /*
4289 * Perform any post-link-up configuration before
4290 * reporting link up.
4291 */
4292 if (phy->ops.cfg_on_link_up)
4293 phy->ops.cfg_on_link_up(hw);
4294
Auke Kokbc7f75f2007-09-17 12:30:59 -07004295 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004296
4297 if (!test_bit(__E1000_DOWN, &adapter->state))
4298 mod_timer(&adapter->phy_info_timer,
4299 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004300 }
4301 } else {
4302 if (netif_carrier_ok(netdev)) {
4303 adapter->link_speed = 0;
4304 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004305 /* Link status message must follow this format */
4306 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4307 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004308 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004309 if (!test_bit(__E1000_DOWN, &adapter->state))
4310 mod_timer(&adapter->phy_info_timer,
4311 round_jiffies(jiffies + 2 * HZ));
4312
4313 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4314 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004315 else
4316 pm_schedule_suspend(netdev->dev.parent,
4317 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004318 }
4319 }
4320
4321link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004322 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004323 e1000e_update_stats(adapter);
4324
4325 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4326 adapter->tpt_old = adapter->stats.tpt;
4327 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4328 adapter->colc_old = adapter->stats.colc;
4329
Bruce Allan7c257692008-04-23 11:09:00 -07004330 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4331 adapter->gorc_old = adapter->stats.gorc;
4332 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4333 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004334 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004335
4336 e1000e_update_adaptive(&adapter->hw);
4337
Bruce Allan90da0662011-01-06 07:02:53 +00004338 if (!netif_carrier_ok(netdev) &&
4339 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4340 /*
4341 * We've lost link, so the controller stops DMA,
4342 * but we've got queued Tx work that's never going
4343 * to get done, so reset controller to flush Tx.
4344 * (Do the reset outside of interrupt context).
4345 */
Bruce Allan90da0662011-01-06 07:02:53 +00004346 schedule_work(&adapter->reset_task);
4347 /* return immediately since reset is imminent */
4348 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004349 }
4350
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004351 /* Simple mode for Interrupt Throttle Rate (ITR) */
4352 if (adapter->itr_setting == 4) {
4353 /*
4354 * Symmetric Tx/Rx gets a reduced ITR=2000;
4355 * Total asymmetrical Tx or Rx gets ITR=8000;
4356 * everyone else is between 2000-8000.
4357 */
4358 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4359 u32 dif = (adapter->gotc > adapter->gorc ?
4360 adapter->gotc - adapter->gorc :
4361 adapter->gorc - adapter->gotc) / 10000;
4362 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4363
4364 ew32(ITR, 1000000000 / (itr * 256));
4365 }
4366
Bruce Allanad680762008-03-28 09:15:03 -07004367 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004368 if (adapter->msix_entries)
4369 ew32(ICS, adapter->rx_ring->ims_val);
4370 else
4371 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004372
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004373 /* flush pending descriptors to memory before detecting Tx hang */
4374 e1000e_flush_descriptors(adapter);
4375
Auke Kokbc7f75f2007-09-17 12:30:59 -07004376 /* Force detection of hung controller every watchdog period */
4377 adapter->detect_tx_hung = 1;
4378
Bruce Allanad680762008-03-28 09:15:03 -07004379 /*
4380 * With 82571 controllers, LAA may be overwritten due to controller
4381 * reset from the other port. Set the appropriate LAA in RAR[0]
4382 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004383 if (e1000e_get_laa_state_82571(hw))
4384 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4385
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004386 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4387 e1000e_check_82574_phy_workaround(adapter);
4388
Auke Kokbc7f75f2007-09-17 12:30:59 -07004389 /* Reset the timer */
4390 if (!test_bit(__E1000_DOWN, &adapter->state))
4391 mod_timer(&adapter->watchdog_timer,
4392 round_jiffies(jiffies + 2 * HZ));
4393}
4394
4395#define E1000_TX_FLAGS_CSUM 0x00000001
4396#define E1000_TX_FLAGS_VLAN 0x00000002
4397#define E1000_TX_FLAGS_TSO 0x00000004
4398#define E1000_TX_FLAGS_IPV4 0x00000008
4399#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4400#define E1000_TX_FLAGS_VLAN_SHIFT 16
4401
4402static int e1000_tso(struct e1000_adapter *adapter,
4403 struct sk_buff *skb)
4404{
4405 struct e1000_ring *tx_ring = adapter->tx_ring;
4406 struct e1000_context_desc *context_desc;
4407 struct e1000_buffer *buffer_info;
4408 unsigned int i;
4409 u32 cmd_length = 0;
4410 u16 ipcse = 0, tucse, mss;
4411 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004412
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004413 if (!skb_is_gso(skb))
4414 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004415
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004416 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004417 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4418
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004419 if (err)
4420 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004421 }
4422
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004423 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4424 mss = skb_shinfo(skb)->gso_size;
4425 if (skb->protocol == htons(ETH_P_IP)) {
4426 struct iphdr *iph = ip_hdr(skb);
4427 iph->tot_len = 0;
4428 iph->check = 0;
4429 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4430 0, IPPROTO_TCP, 0);
4431 cmd_length = E1000_TXD_CMD_IP;
4432 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004433 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004434 ipv6_hdr(skb)->payload_len = 0;
4435 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4436 &ipv6_hdr(skb)->daddr,
4437 0, IPPROTO_TCP, 0);
4438 ipcse = 0;
4439 }
4440 ipcss = skb_network_offset(skb);
4441 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4442 tucss = skb_transport_offset(skb);
4443 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4444 tucse = 0;
4445
4446 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4447 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4448
4449 i = tx_ring->next_to_use;
4450 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4451 buffer_info = &tx_ring->buffer_info[i];
4452
4453 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4454 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4455 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4456 context_desc->upper_setup.tcp_fields.tucss = tucss;
4457 context_desc->upper_setup.tcp_fields.tucso = tucso;
4458 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4459 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4460 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4461 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4462
4463 buffer_info->time_stamp = jiffies;
4464 buffer_info->next_to_watch = i;
4465
4466 i++;
4467 if (i == tx_ring->count)
4468 i = 0;
4469 tx_ring->next_to_use = i;
4470
4471 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004472}
4473
4474static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4475{
4476 struct e1000_ring *tx_ring = adapter->tx_ring;
4477 struct e1000_context_desc *context_desc;
4478 struct e1000_buffer *buffer_info;
4479 unsigned int i;
4480 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004481 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004482 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004483
Dave Grahamaf807c82008-10-09 14:28:58 -07004484 if (skb->ip_summed != CHECKSUM_PARTIAL)
4485 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004486
Arthur Jones5f66f202009-03-19 01:13:08 +00004487 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4488 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4489 else
4490 protocol = skb->protocol;
4491
Arthur Jones3f518392009-03-20 15:56:35 -07004492 switch (protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08004493 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004494 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4495 cmd_len |= E1000_TXD_CMD_TCP;
4496 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08004497 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004498 /* XXX not handling all IPV6 headers */
4499 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4500 cmd_len |= E1000_TXD_CMD_TCP;
4501 break;
4502 default:
4503 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004504 e_warn("checksum_partial proto=%x!\n",
4505 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004506 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004507 }
4508
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004509 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004510
4511 i = tx_ring->next_to_use;
4512 buffer_info = &tx_ring->buffer_info[i];
4513 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4514
4515 context_desc->lower_setup.ip_config = 0;
4516 context_desc->upper_setup.tcp_fields.tucss = css;
4517 context_desc->upper_setup.tcp_fields.tucso =
4518 css + skb->csum_offset;
4519 context_desc->upper_setup.tcp_fields.tucse = 0;
4520 context_desc->tcp_seg_setup.data = 0;
4521 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4522
4523 buffer_info->time_stamp = jiffies;
4524 buffer_info->next_to_watch = i;
4525
4526 i++;
4527 if (i == tx_ring->count)
4528 i = 0;
4529 tx_ring->next_to_use = i;
4530
4531 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004532}
4533
4534#define E1000_MAX_PER_TXD 8192
4535#define E1000_MAX_TXD_PWR 12
4536
4537static int e1000_tx_map(struct e1000_adapter *adapter,
4538 struct sk_buff *skb, unsigned int first,
4539 unsigned int max_per_txd, unsigned int nr_frags,
4540 unsigned int mss)
4541{
4542 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004543 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004544 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004545 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004546 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004547 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004548
4549 i = tx_ring->next_to_use;
4550
4551 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004552 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004553 size = min(len, max_per_txd);
4554
Auke Kokbc7f75f2007-09-17 12:30:59 -07004555 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004556 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004557 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004558 buffer_info->dma = dma_map_single(&pdev->dev,
4559 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004560 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004561 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004562 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004563 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004564
4565 len -= size;
4566 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004567 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004568
4569 if (len) {
4570 i++;
4571 if (i == tx_ring->count)
4572 i = 0;
4573 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004574 }
4575
4576 for (f = 0; f < nr_frags; f++) {
4577 struct skb_frag_struct *frag;
4578
4579 frag = &skb_shinfo(skb)->frags[f];
4580 len = frag->size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004581 offset = frag->page_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004582
4583 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004584 i++;
4585 if (i == tx_ring->count)
4586 i = 0;
4587
Auke Kokbc7f75f2007-09-17 12:30:59 -07004588 buffer_info = &tx_ring->buffer_info[i];
4589 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004590
4591 buffer_info->length = size;
4592 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004593 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004594 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
Alexander Duyck03b13202009-12-02 16:45:31 +00004595 offset, size,
Nick Nunley0be3f552010-04-27 13:09:05 +00004596 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004597 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004598 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004599 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004600
4601 len -= size;
4602 offset += size;
4603 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004604 }
4605 }
4606
Bruce Allanaf667a22010-12-31 06:10:01 +00004607 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004608 /* multiply data chunks by size of headers */
4609 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4610
Auke Kokbc7f75f2007-09-17 12:30:59 -07004611 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004612 tx_ring->buffer_info[i].segs = segs;
4613 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004614 tx_ring->buffer_info[first].next_to_watch = i;
4615
4616 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004617
4618dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004619 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004620 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004621 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004622 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004623
4624 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004625 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004626 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004627 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004628 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004629 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004630 }
4631
4632 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004633}
4634
4635static void e1000_tx_queue(struct e1000_adapter *adapter,
4636 int tx_flags, int count)
4637{
4638 struct e1000_ring *tx_ring = adapter->tx_ring;
4639 struct e1000_tx_desc *tx_desc = NULL;
4640 struct e1000_buffer *buffer_info;
4641 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4642 unsigned int i;
4643
4644 if (tx_flags & E1000_TX_FLAGS_TSO) {
4645 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4646 E1000_TXD_CMD_TSE;
4647 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4648
4649 if (tx_flags & E1000_TX_FLAGS_IPV4)
4650 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4651 }
4652
4653 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4654 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4655 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4656 }
4657
4658 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4659 txd_lower |= E1000_TXD_CMD_VLE;
4660 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4661 }
4662
4663 i = tx_ring->next_to_use;
4664
Bruce Allan36b973d2010-11-24 07:42:43 +00004665 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004666 buffer_info = &tx_ring->buffer_info[i];
4667 tx_desc = E1000_TX_DESC(*tx_ring, i);
4668 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4669 tx_desc->lower.data =
4670 cpu_to_le32(txd_lower | buffer_info->length);
4671 tx_desc->upper.data = cpu_to_le32(txd_upper);
4672
4673 i++;
4674 if (i == tx_ring->count)
4675 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004676 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004677
4678 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4679
Bruce Allanad680762008-03-28 09:15:03 -07004680 /*
4681 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004682 * know there are new descriptors to fetch. (Only
4683 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004684 * such as IA-64).
4685 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004686 wmb();
4687
4688 tx_ring->next_to_use = i;
4689 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07004690 /*
4691 * we need this if more than one processor can write to our tail
4692 * at a time, it synchronizes IO on IA64/Altix systems
4693 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004694 mmiowb();
4695}
4696
4697#define MINIMUM_DHCP_PACKET_SIZE 282
4698static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4699 struct sk_buff *skb)
4700{
4701 struct e1000_hw *hw = &adapter->hw;
4702 u16 length, offset;
4703
4704 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004705 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4706 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004707 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4708 return 0;
4709 }
4710
4711 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4712 return 0;
4713
4714 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4715 return 0;
4716
4717 {
4718 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4719 struct udphdr *udp;
4720
4721 if (ip->protocol != IPPROTO_UDP)
4722 return 0;
4723
4724 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4725 if (ntohs(udp->dest) != 67)
4726 return 0;
4727
4728 offset = (u8 *)udp + 8 - skb->data;
4729 length = skb->len - offset;
4730 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4731 }
4732
4733 return 0;
4734}
4735
4736static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4737{
4738 struct e1000_adapter *adapter = netdev_priv(netdev);
4739
4740 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004741 /*
4742 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004743 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004744 * but since that doesn't exist yet, just open code it.
4745 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004746 smp_mb();
4747
Bruce Allanad680762008-03-28 09:15:03 -07004748 /*
4749 * We need to check again in a case another CPU has just
4750 * made room available.
4751 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004752 if (e1000_desc_unused(adapter->tx_ring) < size)
4753 return -EBUSY;
4754
4755 /* A reprieve! */
4756 netif_start_queue(netdev);
4757 ++adapter->restart_queue;
4758 return 0;
4759}
4760
4761static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4762{
4763 struct e1000_adapter *adapter = netdev_priv(netdev);
4764
4765 if (e1000_desc_unused(adapter->tx_ring) >= size)
4766 return 0;
4767 return __e1000_maybe_stop_tx(netdev, size);
4768}
4769
4770#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004771static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4772 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004773{
4774 struct e1000_adapter *adapter = netdev_priv(netdev);
4775 struct e1000_ring *tx_ring = adapter->tx_ring;
4776 unsigned int first;
4777 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4778 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4779 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004780 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004781 unsigned int nr_frags;
4782 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004783 int count = 0;
4784 int tso;
4785 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004786
4787 if (test_bit(__E1000_DOWN, &adapter->state)) {
4788 dev_kfree_skb_any(skb);
4789 return NETDEV_TX_OK;
4790 }
4791
4792 if (skb->len <= 0) {
4793 dev_kfree_skb_any(skb);
4794 return NETDEV_TX_OK;
4795 }
4796
4797 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004798 /*
4799 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004800 * make sure there is enough room in the FIFO before
4801 * initiating the DMA for each buffer. The calc is:
4802 * 4 = ceil(buffer len/mss). To make sure we don't
4803 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004804 * drops.
4805 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004806 if (mss) {
4807 u8 hdr_len;
4808 max_per_txd = min(mss << 2, max_per_txd);
4809 max_txd_pwr = fls(max_per_txd) - 1;
4810
Bruce Allanad680762008-03-28 09:15:03 -07004811 /*
4812 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4813 * points to just header, pull a few bytes of payload from
4814 * frags into skb->data
4815 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004816 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004817 /*
4818 * we do this workaround for ES2LAN, but it is un-necessary,
4819 * avoiding it could save a lot of cycles
4820 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004821 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004822 unsigned int pull_size;
4823
4824 pull_size = min((unsigned int)4, skb->data_len);
4825 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004826 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004827 dev_kfree_skb_any(skb);
4828 return NETDEV_TX_OK;
4829 }
Eric Dumazete743d312010-04-14 15:59:40 -07004830 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004831 }
4832 }
4833
4834 /* reserve a descriptor for the offload context */
4835 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4836 count++;
4837 count++;
4838
4839 count += TXD_USE_COUNT(len, max_txd_pwr);
4840
4841 nr_frags = skb_shinfo(skb)->nr_frags;
4842 for (f = 0; f < nr_frags; f++)
4843 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4844 max_txd_pwr);
4845
4846 if (adapter->hw.mac.tx_pkt_filtering)
4847 e1000_transfer_dhcp_info(adapter, skb);
4848
Bruce Allanad680762008-03-28 09:15:03 -07004849 /*
4850 * need: count + 2 desc gap to keep tail from touching
4851 * head, otherwise try next time
4852 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004853 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004854 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004855
Jesse Grosseab6d182010-10-20 13:56:03 +00004856 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004857 tx_flags |= E1000_TX_FLAGS_VLAN;
4858 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4859 }
4860
4861 first = tx_ring->next_to_use;
4862
4863 tso = e1000_tso(adapter, skb);
4864 if (tso < 0) {
4865 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004866 return NETDEV_TX_OK;
4867 }
4868
4869 if (tso)
4870 tx_flags |= E1000_TX_FLAGS_TSO;
4871 else if (e1000_tx_csum(adapter, skb))
4872 tx_flags |= E1000_TX_FLAGS_CSUM;
4873
Bruce Allanad680762008-03-28 09:15:03 -07004874 /*
4875 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004876 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004877 * no longer assume, we must.
4878 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004879 if (skb->protocol == htons(ETH_P_IP))
4880 tx_flags |= E1000_TX_FLAGS_IPV4;
4881
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004882 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004883 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004884 if (count) {
4885 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004886 /* Make sure there is space in the ring for the next send. */
4887 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4888
4889 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004890 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004891 tx_ring->buffer_info[first].time_stamp = 0;
4892 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004893 }
4894
Auke Kokbc7f75f2007-09-17 12:30:59 -07004895 return NETDEV_TX_OK;
4896}
4897
4898/**
4899 * e1000_tx_timeout - Respond to a Tx Hang
4900 * @netdev: network interface device structure
4901 **/
4902static void e1000_tx_timeout(struct net_device *netdev)
4903{
4904 struct e1000_adapter *adapter = netdev_priv(netdev);
4905
4906 /* Do the reset outside of interrupt context */
4907 adapter->tx_timeout_count++;
4908 schedule_work(&adapter->reset_task);
4909}
4910
4911static void e1000_reset_task(struct work_struct *work)
4912{
4913 struct e1000_adapter *adapter;
4914 adapter = container_of(work, struct e1000_adapter, reset_task);
4915
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004916 /* don't run the task if already down */
4917 if (test_bit(__E1000_DOWN, &adapter->state))
4918 return;
4919
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00004920 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4921 (adapter->flags & FLAG_RX_RESTART_NOW))) {
4922 e1000e_dump(adapter);
4923 e_err("Reset adapter\n");
4924 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004925 e1000e_reinit_locked(adapter);
4926}
4927
4928/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004929 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07004930 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004931 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07004932 *
4933 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004934 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004935struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
4936 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004937{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004938 struct e1000_adapter *adapter = netdev_priv(netdev);
4939
4940 memset(stats, 0, sizeof(struct rtnl_link_stats64));
4941 spin_lock(&adapter->stats64_lock);
4942 e1000e_update_stats(adapter);
4943 /* Fill out the OS statistics structure */
4944 stats->rx_bytes = adapter->stats.gorc;
4945 stats->rx_packets = adapter->stats.gprc;
4946 stats->tx_bytes = adapter->stats.gotc;
4947 stats->tx_packets = adapter->stats.gptc;
4948 stats->multicast = adapter->stats.mprc;
4949 stats->collisions = adapter->stats.colc;
4950
4951 /* Rx Errors */
4952
4953 /*
4954 * RLEC on some newer hardware can be incorrect so build
4955 * our own version based on RUC and ROC
4956 */
4957 stats->rx_errors = adapter->stats.rxerrc +
4958 adapter->stats.crcerrs + adapter->stats.algnerrc +
4959 adapter->stats.ruc + adapter->stats.roc +
4960 adapter->stats.cexterr;
4961 stats->rx_length_errors = adapter->stats.ruc +
4962 adapter->stats.roc;
4963 stats->rx_crc_errors = adapter->stats.crcerrs;
4964 stats->rx_frame_errors = adapter->stats.algnerrc;
4965 stats->rx_missed_errors = adapter->stats.mpc;
4966
4967 /* Tx Errors */
4968 stats->tx_errors = adapter->stats.ecol +
4969 adapter->stats.latecol;
4970 stats->tx_aborted_errors = adapter->stats.ecol;
4971 stats->tx_window_errors = adapter->stats.latecol;
4972 stats->tx_carrier_errors = adapter->stats.tncrs;
4973
4974 /* Tx Dropped needs to be maintained elsewhere */
4975
4976 spin_unlock(&adapter->stats64_lock);
4977 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004978}
4979
4980/**
4981 * e1000_change_mtu - Change the Maximum Transfer Unit
4982 * @netdev: network interface device structure
4983 * @new_mtu: new value for maximum frame size
4984 *
4985 * Returns 0 on success, negative on failure
4986 **/
4987static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4988{
4989 struct e1000_adapter *adapter = netdev_priv(netdev);
4990 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4991
Bruce Allan2adc55c2009-06-02 11:28:58 +00004992 /* Jumbo frame support */
4993 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
4994 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
4995 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004996 return -EINVAL;
4997 }
4998
Bruce Allan2adc55c2009-06-02 11:28:58 +00004999 /* Supported frame sizes */
5000 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5001 (max_frame > adapter->max_hw_frame_size)) {
5002 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005003 return -EINVAL;
5004 }
5005
Bruce Allana1ce6472010-09-22 17:16:40 +00005006 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5007 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5008 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5009 (new_mtu > ETH_DATA_LEN)) {
5010 e_err("Jumbo Frames not supported on 82579 when CRC "
5011 "stripping is disabled.\n");
5012 return -EINVAL;
5013 }
5014
Bruce Allan6f461f62010-04-27 03:33:04 +00005015 /* 82573 Errata 17 */
5016 if (((adapter->hw.mac.type == e1000_82573) ||
5017 (adapter->hw.mac.type == e1000_82574)) &&
5018 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5019 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5020 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5021 }
5022
Auke Kokbc7f75f2007-09-17 12:30:59 -07005023 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005024 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005025 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005026 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005027 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5028 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005029 if (netif_running(netdev))
5030 e1000e_down(adapter);
5031
Bruce Allanad680762008-03-28 09:15:03 -07005032 /*
5033 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005034 * means we reserve 2 more, this pushes us to allocate from the next
5035 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005036 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005037 * However with the new *_jumbo_rx* routines, jumbo receives will use
5038 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005039 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005040
Jesse Brandeburg99261462010-01-22 22:56:16 +00005041 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005042 adapter->rx_buffer_len = 2048;
5043 else
5044 adapter->rx_buffer_len = 4096;
5045
5046 /* adjust allocation if LPE protects us, and we aren't using SBP */
5047 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5048 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5049 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005050 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005051
Auke Kokbc7f75f2007-09-17 12:30:59 -07005052 if (netif_running(netdev))
5053 e1000e_up(adapter);
5054 else
5055 e1000e_reset(adapter);
5056
5057 clear_bit(__E1000_RESETTING, &adapter->state);
5058
5059 return 0;
5060}
5061
5062static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5063 int cmd)
5064{
5065 struct e1000_adapter *adapter = netdev_priv(netdev);
5066 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005067
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005068 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005069 return -EOPNOTSUPP;
5070
5071 switch (cmd) {
5072 case SIOCGMIIPHY:
5073 data->phy_id = adapter->hw.phy.addr;
5074 break;
5075 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005076 e1000_phy_read_status(adapter);
5077
Bruce Allan7c257692008-04-23 11:09:00 -07005078 switch (data->reg_num & 0x1F) {
5079 case MII_BMCR:
5080 data->val_out = adapter->phy_regs.bmcr;
5081 break;
5082 case MII_BMSR:
5083 data->val_out = adapter->phy_regs.bmsr;
5084 break;
5085 case MII_PHYSID1:
5086 data->val_out = (adapter->hw.phy.id >> 16);
5087 break;
5088 case MII_PHYSID2:
5089 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5090 break;
5091 case MII_ADVERTISE:
5092 data->val_out = adapter->phy_regs.advertise;
5093 break;
5094 case MII_LPA:
5095 data->val_out = adapter->phy_regs.lpa;
5096 break;
5097 case MII_EXPANSION:
5098 data->val_out = adapter->phy_regs.expansion;
5099 break;
5100 case MII_CTRL1000:
5101 data->val_out = adapter->phy_regs.ctrl1000;
5102 break;
5103 case MII_STAT1000:
5104 data->val_out = adapter->phy_regs.stat1000;
5105 break;
5106 case MII_ESTATUS:
5107 data->val_out = adapter->phy_regs.estatus;
5108 break;
5109 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005110 return -EIO;
5111 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005112 break;
5113 case SIOCSMIIREG:
5114 default:
5115 return -EOPNOTSUPP;
5116 }
5117 return 0;
5118}
5119
5120static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5121{
5122 switch (cmd) {
5123 case SIOCGMIIPHY:
5124 case SIOCGMIIREG:
5125 case SIOCSMIIREG:
5126 return e1000_mii_ioctl(netdev, ifr, cmd);
5127 default:
5128 return -EOPNOTSUPP;
5129 }
5130}
5131
Bruce Allana4f58f52009-06-02 11:29:18 +00005132static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5133{
5134 struct e1000_hw *hw = &adapter->hw;
5135 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005136 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005137 int retval = 0;
5138
5139 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005140 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005141
Bruce Allan2b6b1682011-05-13 07:20:09 +00005142 retval = hw->phy.ops.acquire(hw);
5143 if (retval) {
5144 e_err("Could not acquire PHY\n");
5145 return retval;
5146 }
5147
5148 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5149 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5150 if (retval)
5151 goto out;
5152
5153 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005154 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5155 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005156 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5157 (u16)(mac_reg & 0xFFFF));
5158 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5159 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005160 }
5161
5162 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005163 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005164 mac_reg = er32(RCTL);
5165 if (mac_reg & E1000_RCTL_UPE)
5166 phy_reg |= BM_RCTL_UPE;
5167 if (mac_reg & E1000_RCTL_MPE)
5168 phy_reg |= BM_RCTL_MPE;
5169 phy_reg &= ~(BM_RCTL_MO_MASK);
5170 if (mac_reg & E1000_RCTL_MO_3)
5171 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5172 << BM_RCTL_MO_SHIFT);
5173 if (mac_reg & E1000_RCTL_BAM)
5174 phy_reg |= BM_RCTL_BAM;
5175 if (mac_reg & E1000_RCTL_PMCF)
5176 phy_reg |= BM_RCTL_PMCF;
5177 mac_reg = er32(CTRL);
5178 if (mac_reg & E1000_CTRL_RFCE)
5179 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005180 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005181
5182 /* enable PHY wakeup in MAC register */
5183 ew32(WUFC, wufc);
5184 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5185
5186 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005187 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5188 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005189
5190 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005191 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5192 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005193 if (retval)
5194 e_err("Could not set PHY Host Wakeup bit\n");
5195out:
Bruce Allan94d81862009-11-20 23:25:26 +00005196 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005197
5198 return retval;
5199}
5200
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005201static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5202 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005203{
5204 struct net_device *netdev = pci_get_drvdata(pdev);
5205 struct e1000_adapter *adapter = netdev_priv(netdev);
5206 struct e1000_hw *hw = &adapter->hw;
5207 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005208 /* Runtime suspend should only enable wakeup for link changes */
5209 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005210 int retval = 0;
5211
5212 netif_device_detach(netdev);
5213
5214 if (netif_running(netdev)) {
5215 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5216 e1000e_down(adapter);
5217 e1000_free_irq(adapter);
5218 }
Bruce Allan4662e822008-08-26 18:37:06 -07005219 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005220
5221 retval = pci_save_state(pdev);
5222 if (retval)
5223 return retval;
5224
5225 status = er32(STATUS);
5226 if (status & E1000_STATUS_LU)
5227 wufc &= ~E1000_WUFC_LNKC;
5228
5229 if (wufc) {
5230 e1000_setup_rctl(adapter);
5231 e1000_set_multi(netdev);
5232
5233 /* turn on all-multi mode if wake on multicast is enabled */
5234 if (wufc & E1000_WUFC_MC) {
5235 rctl = er32(RCTL);
5236 rctl |= E1000_RCTL_MPE;
5237 ew32(RCTL, rctl);
5238 }
5239
5240 ctrl = er32(CTRL);
5241 /* advertise wake from D3Cold */
5242 #define E1000_CTRL_ADVD3WUC 0x00100000
5243 /* phy power management enable */
5244 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005245 ctrl |= E1000_CTRL_ADVD3WUC;
5246 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5247 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005248 ew32(CTRL, ctrl);
5249
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005250 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5251 adapter->hw.phy.media_type ==
5252 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005253 /* keep the laser running in D3 */
5254 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005255 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005256 ew32(CTRL_EXT, ctrl_ext);
5257 }
5258
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005259 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005260 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005261
Auke Kokbc7f75f2007-09-17 12:30:59 -07005262 /* Allow time for pending master requests to run */
5263 e1000e_disable_pcie_master(&adapter->hw);
5264
Bruce Allan82776a42009-08-14 14:35:33 +00005265 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005266 /* enable wakeup by the PHY */
5267 retval = e1000_init_phy_wakeup(adapter, wufc);
5268 if (retval)
5269 return retval;
5270 } else {
5271 /* enable wakeup by the MAC */
5272 ew32(WUFC, wufc);
5273 ew32(WUC, E1000_WUC_PME_EN);
5274 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005275 } else {
5276 ew32(WUC, 0);
5277 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005278 }
5279
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005280 *enable_wake = !!wufc;
5281
Auke Kokbc7f75f2007-09-17 12:30:59 -07005282 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005283 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5284 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005285 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005286
5287 if (adapter->hw.phy.type == e1000_phy_igp_3)
5288 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5289
Bruce Allanad680762008-03-28 09:15:03 -07005290 /*
5291 * Release control of h/w to f/w. If f/w is AMT enabled, this
5292 * would have already happened in close and is redundant.
5293 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005294 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005295
5296 pci_disable_device(pdev);
5297
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005298 return 0;
5299}
5300
5301static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5302{
5303 if (sleep && wake) {
5304 pci_prepare_to_sleep(pdev);
5305 return;
5306 }
5307
5308 pci_wake_from_d3(pdev, wake);
5309 pci_set_power_state(pdev, PCI_D3hot);
5310}
5311
5312static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5313 bool wake)
5314{
5315 struct net_device *netdev = pci_get_drvdata(pdev);
5316 struct e1000_adapter *adapter = netdev_priv(netdev);
5317
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005318 /*
5319 * The pci-e switch on some quad port adapters will report a
5320 * correctable error when the MAC transitions from D0 to D3. To
5321 * prevent this we need to mask off the correctable errors on the
5322 * downstream port of the pci-e switch.
5323 */
5324 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5325 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005326 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005327 u16 devctl;
5328
5329 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5330 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5331 (devctl & ~PCI_EXP_DEVCTL_CERE));
5332
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005333 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005334
5335 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5336 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005337 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005338 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005339}
5340
Bruce Allan6f461f62010-04-27 03:33:04 +00005341#ifdef CONFIG_PCIEASPM
5342static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5343{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005344 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005345}
5346#else
5347static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005348{
5349 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005350 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005351
5352 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005353 * Both device and parent should have the same ASPM setting.
5354 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005355 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005356 pos = pci_pcie_cap(pdev);
5357 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5358 reg16 &= ~state;
5359 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5360
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005361 if (!pdev->bus->self)
5362 return;
5363
Bruce Allan6f461f62010-04-27 03:33:04 +00005364 pos = pci_pcie_cap(pdev->bus->self);
5365 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5366 reg16 &= ~state;
5367 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5368}
5369#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005370static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005371{
5372 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5373 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5374 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5375
5376 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005377}
5378
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005379#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005380static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005381{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005382 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005383}
5384
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005385static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005386{
5387 struct net_device *netdev = pci_get_drvdata(pdev);
5388 struct e1000_adapter *adapter = netdev_priv(netdev);
5389 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005390 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005391 u32 err;
5392
Bruce Allan78cd29d2011-03-24 03:09:03 +00005393 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5394 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5395 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5396 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5397 if (aspm_disable_flag)
5398 e1000e_disable_aspm(pdev, aspm_disable_flag);
5399
Auke Kokbc7f75f2007-09-17 12:30:59 -07005400 pci_set_power_state(pdev, PCI_D0);
5401 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005402 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005403
Bruce Allan4662e822008-08-26 18:37:06 -07005404 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005405 if (netif_running(netdev)) {
5406 err = e1000_request_irq(adapter);
5407 if (err)
5408 return err;
5409 }
5410
Bruce Allan99730e42011-05-13 07:19:48 +00005411 if (hw->mac.type == e1000_pch2lan)
5412 e1000_resume_workarounds_pchlan(&adapter->hw);
5413
Auke Kokbc7f75f2007-09-17 12:30:59 -07005414 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005415
5416 /* report the system wakeup cause from S3/S4 */
5417 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5418 u16 phy_data;
5419
5420 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5421 if (phy_data) {
5422 e_info("PHY Wakeup cause - %s\n",
5423 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5424 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5425 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5426 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5427 phy_data & E1000_WUS_LNKC ? "Link Status "
5428 " Change" : "other");
5429 }
5430 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5431 } else {
5432 u32 wus = er32(WUS);
5433 if (wus) {
5434 e_info("MAC Wakeup cause - %s\n",
5435 wus & E1000_WUS_EX ? "Unicast Packet" :
5436 wus & E1000_WUS_MC ? "Multicast Packet" :
5437 wus & E1000_WUS_BC ? "Broadcast Packet" :
5438 wus & E1000_WUS_MAG ? "Magic Packet" :
5439 wus & E1000_WUS_LNKC ? "Link Status Change" :
5440 "other");
5441 }
5442 ew32(WUS, ~0);
5443 }
5444
Auke Kokbc7f75f2007-09-17 12:30:59 -07005445 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005446
Bruce Allancd791612010-05-10 14:59:51 +00005447 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005448
5449 if (netif_running(netdev))
5450 e1000e_up(adapter);
5451
5452 netif_device_attach(netdev);
5453
Bruce Allanad680762008-03-28 09:15:03 -07005454 /*
5455 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005456 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005457 * under the control of the driver.
5458 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005459 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005460 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005461
5462 return 0;
5463}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005464
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005465#ifdef CONFIG_PM_SLEEP
5466static int e1000_suspend(struct device *dev)
5467{
5468 struct pci_dev *pdev = to_pci_dev(dev);
5469 int retval;
5470 bool wake;
5471
5472 retval = __e1000_shutdown(pdev, &wake, false);
5473 if (!retval)
5474 e1000_complete_shutdown(pdev, true, wake);
5475
5476 return retval;
5477}
5478
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005479static int e1000_resume(struct device *dev)
5480{
5481 struct pci_dev *pdev = to_pci_dev(dev);
5482 struct net_device *netdev = pci_get_drvdata(pdev);
5483 struct e1000_adapter *adapter = netdev_priv(netdev);
5484
5485 if (e1000e_pm_ready(adapter))
5486 adapter->idle_check = true;
5487
5488 return __e1000_resume(pdev);
5489}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005490#endif /* CONFIG_PM_SLEEP */
5491
5492#ifdef CONFIG_PM_RUNTIME
5493static int e1000_runtime_suspend(struct device *dev)
5494{
5495 struct pci_dev *pdev = to_pci_dev(dev);
5496 struct net_device *netdev = pci_get_drvdata(pdev);
5497 struct e1000_adapter *adapter = netdev_priv(netdev);
5498
5499 if (e1000e_pm_ready(adapter)) {
5500 bool wake;
5501
5502 __e1000_shutdown(pdev, &wake, true);
5503 }
5504
5505 return 0;
5506}
5507
5508static int e1000_idle(struct device *dev)
5509{
5510 struct pci_dev *pdev = to_pci_dev(dev);
5511 struct net_device *netdev = pci_get_drvdata(pdev);
5512 struct e1000_adapter *adapter = netdev_priv(netdev);
5513
5514 if (!e1000e_pm_ready(adapter))
5515 return 0;
5516
5517 if (adapter->idle_check) {
5518 adapter->idle_check = false;
5519 if (!e1000e_has_link(adapter))
5520 pm_schedule_suspend(dev, MSEC_PER_SEC);
5521 }
5522
5523 return -EBUSY;
5524}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005525
5526static int e1000_runtime_resume(struct device *dev)
5527{
5528 struct pci_dev *pdev = to_pci_dev(dev);
5529 struct net_device *netdev = pci_get_drvdata(pdev);
5530 struct e1000_adapter *adapter = netdev_priv(netdev);
5531
5532 if (!e1000e_pm_ready(adapter))
5533 return 0;
5534
5535 adapter->idle_check = !dev->power.runtime_auto;
5536 return __e1000_resume(pdev);
5537}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005538#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005539#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005540
5541static void e1000_shutdown(struct pci_dev *pdev)
5542{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005543 bool wake = false;
5544
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005545 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005546
5547 if (system_state == SYSTEM_POWER_OFF)
5548 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005549}
5550
5551#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005552
5553static irqreturn_t e1000_intr_msix(int irq, void *data)
5554{
5555 struct net_device *netdev = data;
5556 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005557
5558 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005559 int vector, msix_irq;
5560
Dongdong Deng147b2c82010-11-16 19:50:15 -08005561 vector = 0;
5562 msix_irq = adapter->msix_entries[vector].vector;
5563 disable_irq(msix_irq);
5564 e1000_intr_msix_rx(msix_irq, netdev);
5565 enable_irq(msix_irq);
5566
5567 vector++;
5568 msix_irq = adapter->msix_entries[vector].vector;
5569 disable_irq(msix_irq);
5570 e1000_intr_msix_tx(msix_irq, netdev);
5571 enable_irq(msix_irq);
5572
5573 vector++;
5574 msix_irq = adapter->msix_entries[vector].vector;
5575 disable_irq(msix_irq);
5576 e1000_msix_other(msix_irq, netdev);
5577 enable_irq(msix_irq);
5578 }
5579
5580 return IRQ_HANDLED;
5581}
5582
Auke Kokbc7f75f2007-09-17 12:30:59 -07005583/*
5584 * Polling 'interrupt' - used by things like netconsole to send skbs
5585 * without having to re-enable interrupts. It's not called while
5586 * the interrupt routine is executing.
5587 */
5588static void e1000_netpoll(struct net_device *netdev)
5589{
5590 struct e1000_adapter *adapter = netdev_priv(netdev);
5591
Dongdong Deng147b2c82010-11-16 19:50:15 -08005592 switch (adapter->int_mode) {
5593 case E1000E_INT_MODE_MSIX:
5594 e1000_intr_msix(adapter->pdev->irq, netdev);
5595 break;
5596 case E1000E_INT_MODE_MSI:
5597 disable_irq(adapter->pdev->irq);
5598 e1000_intr_msi(adapter->pdev->irq, netdev);
5599 enable_irq(adapter->pdev->irq);
5600 break;
5601 default: /* E1000E_INT_MODE_LEGACY */
5602 disable_irq(adapter->pdev->irq);
5603 e1000_intr(adapter->pdev->irq, netdev);
5604 enable_irq(adapter->pdev->irq);
5605 break;
5606 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005607}
5608#endif
5609
5610/**
5611 * e1000_io_error_detected - called when PCI error is detected
5612 * @pdev: Pointer to PCI device
5613 * @state: The current pci connection state
5614 *
5615 * This function is called after a PCI bus error affecting
5616 * this device has been detected.
5617 */
5618static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5619 pci_channel_state_t state)
5620{
5621 struct net_device *netdev = pci_get_drvdata(pdev);
5622 struct e1000_adapter *adapter = netdev_priv(netdev);
5623
5624 netif_device_detach(netdev);
5625
Mike Masonc93b5a72009-06-30 12:45:53 +00005626 if (state == pci_channel_io_perm_failure)
5627 return PCI_ERS_RESULT_DISCONNECT;
5628
Auke Kokbc7f75f2007-09-17 12:30:59 -07005629 if (netif_running(netdev))
5630 e1000e_down(adapter);
5631 pci_disable_device(pdev);
5632
5633 /* Request a slot slot reset. */
5634 return PCI_ERS_RESULT_NEED_RESET;
5635}
5636
5637/**
5638 * e1000_io_slot_reset - called after the pci bus has been reset.
5639 * @pdev: Pointer to PCI device
5640 *
5641 * Restart the card from scratch, as if from a cold-boot. Implementation
5642 * resembles the first-half of the e1000_resume routine.
5643 */
5644static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5645{
5646 struct net_device *netdev = pci_get_drvdata(pdev);
5647 struct e1000_adapter *adapter = netdev_priv(netdev);
5648 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005649 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005650 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005651 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005652
Bruce Allan78cd29d2011-03-24 03:09:03 +00005653 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5654 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005655 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005656 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5657 if (aspm_disable_flag)
5658 e1000e_disable_aspm(pdev, aspm_disable_flag);
5659
Bruce Allanf0f422e2008-08-04 17:21:53 -07005660 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005661 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005662 dev_err(&pdev->dev,
5663 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005664 result = PCI_ERS_RESULT_DISCONNECT;
5665 } else {
5666 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005667 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005668 pci_restore_state(pdev);
5669
5670 pci_enable_wake(pdev, PCI_D3hot, 0);
5671 pci_enable_wake(pdev, PCI_D3cold, 0);
5672
5673 e1000e_reset(adapter);
5674 ew32(WUS, ~0);
5675 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005676 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005677
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005678 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005679
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005680 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005681}
5682
5683/**
5684 * e1000_io_resume - called when traffic can start flowing again.
5685 * @pdev: Pointer to PCI device
5686 *
5687 * This callback is called when the error recovery driver tells us that
5688 * its OK to resume normal operation. Implementation resembles the
5689 * second-half of the e1000_resume routine.
5690 */
5691static void e1000_io_resume(struct pci_dev *pdev)
5692{
5693 struct net_device *netdev = pci_get_drvdata(pdev);
5694 struct e1000_adapter *adapter = netdev_priv(netdev);
5695
Bruce Allancd791612010-05-10 14:59:51 +00005696 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005697
5698 if (netif_running(netdev)) {
5699 if (e1000e_up(adapter)) {
5700 dev_err(&pdev->dev,
5701 "can't bring device back up after reset\n");
5702 return;
5703 }
5704 }
5705
5706 netif_device_attach(netdev);
5707
Bruce Allanad680762008-03-28 09:15:03 -07005708 /*
5709 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005710 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005711 * under the control of the driver.
5712 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005713 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005714 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005715
5716}
5717
5718static void e1000_print_device_info(struct e1000_adapter *adapter)
5719{
5720 struct e1000_hw *hw = &adapter->hw;
5721 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005722 u32 ret_val;
5723 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005724
5725 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005726 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005727 /* bus width */
5728 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5729 "Width x1"),
5730 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005731 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005732 e_info("Intel(R) PRO/%s Network Connection\n",
5733 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005734 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5735 E1000_PBANUM_LENGTH);
5736 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005737 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005738 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5739 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005740}
5741
Auke Kok10aa4c02008-08-04 17:21:20 -07005742static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5743{
5744 struct e1000_hw *hw = &adapter->hw;
5745 int ret_val;
5746 u16 buf = 0;
5747
5748 if (hw->mac.type != e1000_82573)
5749 return;
5750
5751 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005752 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005753 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005754 dev_warn(&adapter->pdev->dev,
5755 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005756 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005757}
5758
Stephen Hemminger651c2462008-11-19 21:57:48 -08005759static const struct net_device_ops e1000e_netdev_ops = {
5760 .ndo_open = e1000_open,
5761 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005762 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005763 .ndo_get_stats64 = e1000e_get_stats64,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005764 .ndo_set_multicast_list = e1000_set_multi,
5765 .ndo_set_mac_address = e1000_set_mac,
5766 .ndo_change_mtu = e1000_change_mtu,
5767 .ndo_do_ioctl = e1000_ioctl,
5768 .ndo_tx_timeout = e1000_tx_timeout,
5769 .ndo_validate_addr = eth_validate_addr,
5770
Stephen Hemminger651c2462008-11-19 21:57:48 -08005771 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5772 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5773#ifdef CONFIG_NET_POLL_CONTROLLER
5774 .ndo_poll_controller = e1000_netpoll,
5775#endif
5776};
5777
Auke Kokbc7f75f2007-09-17 12:30:59 -07005778/**
5779 * e1000_probe - Device Initialization Routine
5780 * @pdev: PCI device information struct
5781 * @ent: entry in e1000_pci_tbl
5782 *
5783 * Returns 0 on success, negative on failure
5784 *
5785 * e1000_probe initializes an adapter identified by a pci_dev structure.
5786 * The OS initialization, configuring of the adapter private structure,
5787 * and a hardware reset occur.
5788 **/
5789static int __devinit e1000_probe(struct pci_dev *pdev,
5790 const struct pci_device_id *ent)
5791{
5792 struct net_device *netdev;
5793 struct e1000_adapter *adapter;
5794 struct e1000_hw *hw;
5795 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005796 resource_size_t mmio_start, mmio_len;
5797 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005798
5799 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005800 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005801 int i, err, pci_using_dac;
5802 u16 eeprom_data = 0;
5803 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5804
Bruce Allan78cd29d2011-03-24 03:09:03 +00005805 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
5806 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005807 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005808 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5809 if (aspm_disable_flag)
5810 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005811
Bruce Allanf0f422e2008-08-04 17:21:53 -07005812 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005813 if (err)
5814 return err;
5815
5816 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005817 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005818 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005819 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005820 if (!err)
5821 pci_using_dac = 1;
5822 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005823 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005824 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005825 err = dma_set_coherent_mask(&pdev->dev,
5826 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005827 if (err) {
5828 dev_err(&pdev->dev, "No usable DMA "
5829 "configuration, aborting\n");
5830 goto err_dma;
5831 }
5832 }
5833 }
5834
Arjan van de Vene8de1482008-10-22 19:55:31 -07005835 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005836 pci_select_bars(pdev, IORESOURCE_MEM),
5837 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005838 if (err)
5839 goto err_pci_reg;
5840
Xiaotian Feng68eac462009-08-14 14:35:52 +00005841 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005842 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005843
Auke Kokbc7f75f2007-09-17 12:30:59 -07005844 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005845 /* PCI config space info */
5846 err = pci_save_state(pdev);
5847 if (err)
5848 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005849
5850 err = -ENOMEM;
5851 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5852 if (!netdev)
5853 goto err_alloc_etherdev;
5854
Auke Kokbc7f75f2007-09-17 12:30:59 -07005855 SET_NETDEV_DEV(netdev, &pdev->dev);
5856
Tom Herbertf85e4df2010-05-05 14:03:32 +00005857 netdev->irq = pdev->irq;
5858
Auke Kokbc7f75f2007-09-17 12:30:59 -07005859 pci_set_drvdata(pdev, netdev);
5860 adapter = netdev_priv(netdev);
5861 hw = &adapter->hw;
5862 adapter->netdev = netdev;
5863 adapter->pdev = pdev;
5864 adapter->ei = ei;
5865 adapter->pba = ei->pba;
5866 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005867 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005868 adapter->hw.adapter = adapter;
5869 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005870 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005871 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5872
5873 mmio_start = pci_resource_start(pdev, 0);
5874 mmio_len = pci_resource_len(pdev, 0);
5875
5876 err = -EIO;
5877 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5878 if (!adapter->hw.hw_addr)
5879 goto err_ioremap;
5880
5881 if ((adapter->flags & FLAG_HAS_FLASH) &&
5882 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5883 flash_start = pci_resource_start(pdev, 1);
5884 flash_len = pci_resource_len(pdev, 1);
5885 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5886 if (!adapter->hw.flash_address)
5887 goto err_flashmap;
5888 }
5889
5890 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005891 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005892 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005893 netdev->watchdog_timeo = 5 * HZ;
5894 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005895 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5896
5897 netdev->mem_start = mmio_start;
5898 netdev->mem_end = mmio_start + mmio_len;
5899
5900 adapter->bd_number = cards_found++;
5901
Bruce Allan4662e822008-08-26 18:37:06 -07005902 e1000e_check_options(adapter);
5903
Auke Kokbc7f75f2007-09-17 12:30:59 -07005904 /* setup adapter struct */
5905 err = e1000_sw_init(adapter);
5906 if (err)
5907 goto err_sw_init;
5908
Auke Kokbc7f75f2007-09-17 12:30:59 -07005909 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5910 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5911 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5912
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005913 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005914 if (err)
5915 goto err_hw_init;
5916
Bruce Allan4a770352008-10-01 17:18:35 -07005917 if ((adapter->flags & FLAG_IS_ICH) &&
5918 (adapter->flags & FLAG_READ_ONLY_NVM))
5919 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5920
Auke Kokbc7f75f2007-09-17 12:30:59 -07005921 hw->mac.ops.get_bus_info(&adapter->hw);
5922
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005923 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005924
5925 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005926 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005927 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5928 adapter->hw.phy.disable_polarity_correction = 0;
5929 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5930 }
5931
5932 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005933 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005934
5935 netdev->features = NETIF_F_SG |
5936 NETIF_F_HW_CSUM |
5937 NETIF_F_HW_VLAN_TX |
5938 NETIF_F_HW_VLAN_RX;
5939
5940 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5941 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5942
5943 netdev->features |= NETIF_F_TSO;
5944 netdev->features |= NETIF_F_TSO6;
5945
Jeff Kirshera5136e22008-06-05 04:07:28 -07005946 netdev->vlan_features |= NETIF_F_TSO;
5947 netdev->vlan_features |= NETIF_F_TSO6;
5948 netdev->vlan_features |= NETIF_F_HW_CSUM;
5949 netdev->vlan_features |= NETIF_F_SG;
5950
Yi Zou7b872a52010-09-22 17:57:58 +00005951 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005952 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00005953 netdev->vlan_features |= NETIF_F_HIGHDMA;
5954 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955
Auke Kokbc7f75f2007-09-17 12:30:59 -07005956 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5957 adapter->flags |= FLAG_MNG_PT_ENABLED;
5958
Bruce Allanad680762008-03-28 09:15:03 -07005959 /*
5960 * before reading the NVM, reset the controller to
5961 * put the device in a known good starting state
5962 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005963 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5964
5965 /*
5966 * systems with ASPM and others may see the checksum fail on the first
5967 * attempt. Let's give it a few tries
5968 */
5969 for (i = 0;; i++) {
5970 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5971 break;
5972 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005973 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005974 err = -EIO;
5975 goto err_eeprom;
5976 }
5977 }
5978
Auke Kok10aa4c02008-08-04 17:21:20 -07005979 e1000_eeprom_checks(adapter);
5980
Bruce Allan608f8a02010-01-13 02:04:58 +00005981 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005982 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005983 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005984
5985 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5986 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5987
5988 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07005989 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005990 err = -EIO;
5991 goto err_eeprom;
5992 }
5993
5994 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005995 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005996 adapter->watchdog_timer.data = (unsigned long) adapter;
5997
5998 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005999 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006000 adapter->phy_info_timer.data = (unsigned long) adapter;
6001
6002 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6003 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006004 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6005 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006006 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006007
Auke Kokbc7f75f2007-09-17 12:30:59 -07006008 /* Initialize link parameters. User can change them with ethtool */
6009 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07006010 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006011 adapter->hw.fc.requested_mode = e1000_fc_default;
6012 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006013 adapter->hw.phy.autoneg_advertised = 0x2f;
6014
6015 /* ring size defaults */
6016 adapter->rx_ring->count = 256;
6017 adapter->tx_ring->count = 256;
6018
6019 /*
6020 * Initial Wake on LAN setting - If APM wake is enabled in
6021 * the EEPROM, enable the ACPI Magic Packet filter
6022 */
6023 if (adapter->flags & FLAG_APME_IN_WUC) {
6024 /* APME bit in EEPROM is mapped to WUC.APME */
6025 eeprom_data = er32(WUC);
6026 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006027 if ((hw->mac.type > e1000_ich10lan) &&
6028 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006029 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006030 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6031 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6032 (adapter->hw.bus.func == 1))
6033 e1000_read_nvm(&adapter->hw,
6034 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6035 else
6036 e1000_read_nvm(&adapter->hw,
6037 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6038 }
6039
6040 /* fetch WoL from EEPROM */
6041 if (eeprom_data & eeprom_apme_mask)
6042 adapter->eeprom_wol |= E1000_WUFC_MAG;
6043
6044 /*
6045 * now that we have the eeprom settings, apply the special cases
6046 * where the eeprom may be wrong or the board simply won't support
6047 * wake on lan on a particular port
6048 */
6049 if (!(adapter->flags & FLAG_HAS_WOL))
6050 adapter->eeprom_wol = 0;
6051
6052 /* initialize the wol settings based on the eeprom settings */
6053 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006054 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006055
Bruce Allan84527592008-11-21 17:00:22 -08006056 /* save off EEPROM version number */
6057 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6058
Auke Kokbc7f75f2007-09-17 12:30:59 -07006059 /* reset the hardware with the new settings */
6060 e1000e_reset(adapter);
6061
Bruce Allanad680762008-03-28 09:15:03 -07006062 /*
6063 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006064 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006065 * under the control of the driver.
6066 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006067 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006068 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006069
Bruce Allane0dc4f12011-01-06 14:29:50 +00006070 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006071 err = register_netdev(netdev);
6072 if (err)
6073 goto err_register;
6074
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006075 /* carrier off reporting is important to ethtool even BEFORE open */
6076 netif_carrier_off(netdev);
6077
Auke Kokbc7f75f2007-09-17 12:30:59 -07006078 e1000_print_device_info(adapter);
6079
Alan Sternf3ec4f82010-06-08 15:23:51 -04006080 if (pci_dev_run_wake(pdev))
6081 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006082
Auke Kokbc7f75f2007-09-17 12:30:59 -07006083 return 0;
6084
6085err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006086 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006087 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006088err_eeprom:
6089 if (!e1000_check_reset_block(&adapter->hw))
6090 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006091err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006092 kfree(adapter->tx_ring);
6093 kfree(adapter->rx_ring);
6094err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006095 if (adapter->hw.flash_address)
6096 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006097 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006098err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006099 iounmap(adapter->hw.hw_addr);
6100err_ioremap:
6101 free_netdev(netdev);
6102err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006103 pci_release_selected_regions(pdev,
6104 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006105err_pci_reg:
6106err_dma:
6107 pci_disable_device(pdev);
6108 return err;
6109}
6110
6111/**
6112 * e1000_remove - Device Removal Routine
6113 * @pdev: PCI device information struct
6114 *
6115 * e1000_remove is called by the PCI subsystem to alert the driver
6116 * that it should release a PCI device. The could be caused by a
6117 * Hot-Plug event, or because the driver is going to be removed from
6118 * memory.
6119 **/
6120static void __devexit e1000_remove(struct pci_dev *pdev)
6121{
6122 struct net_device *netdev = pci_get_drvdata(pdev);
6123 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006124 bool down = test_bit(__E1000_DOWN, &adapter->state);
6125
Bruce Allanad680762008-03-28 09:15:03 -07006126 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006127 * The timers may be rescheduled, so explicitly disable them
6128 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006129 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006130 if (!down)
6131 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006132 del_timer_sync(&adapter->watchdog_timer);
6133 del_timer_sync(&adapter->phy_info_timer);
6134
Bruce Allan41cec6f2009-11-20 23:28:56 +00006135 cancel_work_sync(&adapter->reset_task);
6136 cancel_work_sync(&adapter->watchdog_task);
6137 cancel_work_sync(&adapter->downshift_task);
6138 cancel_work_sync(&adapter->update_phy_task);
6139 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006140
Bruce Allan17f208d2009-12-01 15:47:22 +00006141 if (!(netdev->flags & IFF_UP))
6142 e1000_power_down_phy(adapter);
6143
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006144 /* Don't lie to e1000_close() down the road. */
6145 if (!down)
6146 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006147 unregister_netdev(netdev);
6148
Alan Sternf3ec4f82010-06-08 15:23:51 -04006149 if (pci_dev_run_wake(pdev))
6150 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006151
Bruce Allanad680762008-03-28 09:15:03 -07006152 /*
6153 * Release control of h/w to f/w. If f/w is AMT enabled, this
6154 * would have already happened in close and is redundant.
6155 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006156 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006157
Bruce Allan4662e822008-08-26 18:37:06 -07006158 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006159 kfree(adapter->tx_ring);
6160 kfree(adapter->rx_ring);
6161
6162 iounmap(adapter->hw.hw_addr);
6163 if (adapter->hw.flash_address)
6164 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006165 pci_release_selected_regions(pdev,
6166 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006167
6168 free_netdev(netdev);
6169
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006170 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006171 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006172
Auke Kokbc7f75f2007-09-17 12:30:59 -07006173 pci_disable_device(pdev);
6174}
6175
6176/* PCI Error Recovery (ERS) */
6177static struct pci_error_handlers e1000_err_handler = {
6178 .error_detected = e1000_io_error_detected,
6179 .slot_reset = e1000_io_slot_reset,
6180 .resume = e1000_io_resume,
6181};
6182
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006183static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006184 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6185 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6186 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6187 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6188 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6189 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006190 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6191 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6192 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006193
Auke Kokbc7f75f2007-09-17 12:30:59 -07006194 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6195 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6196 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6197 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006198
Auke Kokbc7f75f2007-09-17 12:30:59 -07006199 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6200 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6201 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006202
Bruce Allan4662e822008-08-26 18:37:06 -07006203 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006204 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006205 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006206
Auke Kokbc7f75f2007-09-17 12:30:59 -07006207 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6208 board_80003es2lan },
6209 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6210 board_80003es2lan },
6211 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6212 board_80003es2lan },
6213 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6214 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006215
Auke Kokbc7f75f2007-09-17 12:30:59 -07006216 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6217 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6218 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6219 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6220 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6221 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6222 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006223 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006224
Auke Kokbc7f75f2007-09-17 12:30:59 -07006225 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6226 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6227 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6228 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6229 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006230 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006231 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6232 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6233 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6234
6235 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6236 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6237 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006238
Bruce Allanf4187b52008-08-26 18:36:50 -07006239 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6240 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006241 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006242
Bruce Allana4f58f52009-06-02 11:29:18 +00006243 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6244 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6245 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6246 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6247
Bruce Alland3738bb2010-06-16 13:27:28 +00006248 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6249 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6250
Auke Kokbc7f75f2007-09-17 12:30:59 -07006251 { } /* terminate list */
6252};
6253MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6254
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006255#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006256static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006257 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6258 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6259 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006260};
David S. Millere50208a2010-03-16 23:36:24 -07006261#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006262
Auke Kokbc7f75f2007-09-17 12:30:59 -07006263/* PCI Device API Driver */
6264static struct pci_driver e1000_driver = {
6265 .name = e1000e_driver_name,
6266 .id_table = e1000_pci_tbl,
6267 .probe = e1000_probe,
6268 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006269#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006270 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006271#endif
6272 .shutdown = e1000_shutdown,
6273 .err_handler = &e1000_err_handler
6274};
6275
6276/**
6277 * e1000_init_module - Driver Registration Routine
6278 *
6279 * e1000_init_module is the first routine called when the driver is
6280 * loaded. All it does is register with the PCI subsystem.
6281 **/
6282static int __init e1000_init_module(void)
6283{
6284 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006285 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6286 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006287 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006288 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006289
Auke Kokbc7f75f2007-09-17 12:30:59 -07006290 return ret;
6291}
6292module_init(e1000_init_module);
6293
6294/**
6295 * e1000_exit_module - Driver Exit Cleanup Routine
6296 *
6297 * e1000_exit_module is called just before the driver is removed
6298 * from memory.
6299 **/
6300static void __exit e1000_exit_module(void)
6301{
6302 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006303}
6304module_exit(e1000_exit_module);
6305
6306
6307MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6308MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6309MODULE_LICENSE("GPL");
6310MODULE_VERSION(DRV_VERSION);
6311
6312/* e1000_main.c */