blob: 2198e615f241c5fc7e640f7c7da078be16ece7f3 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allan8544b9f2010-03-24 12:55:30 +000029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/vmalloc.h>
36#include <linux/pagemap.h>
37#include <linux/delay.h>
38#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000039#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070040#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 Allan12440922011-07-22 06:22:02 +000059#define DRV_VERSION "1.4.4" 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/**
Bruce Allanc6e7f512011-07-29 05:53:02 +0000522 * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa()
523 * @hw: pointer to the HW structure
524 * @tail: address of tail descriptor register
525 * @i: value to write to tail descriptor register
526 *
527 * When updating the tail register, the ME could be accessing Host CSR
528 * registers at the same time. Normally, this is handled in h/w by an
529 * arbiter but on some parts there is a bug that acknowledges Host accesses
530 * later than it should which could result in the descriptor register to
531 * have an incorrect value. Workaround this by checking the FWSM register
532 * which has bit 24 set while ME is accessing Host CSR registers, wait
533 * if it is set and try again a number of times.
534 **/
535static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, u8 __iomem * tail,
536 unsigned int i)
537{
538 unsigned int j = 0;
539
540 while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) &&
541 (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI))
542 udelay(50);
543
544 writel(i, tail);
545
546 if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail)))
547 return E1000_ERR_SWFW_SYNC;
548
549 return 0;
550}
551
552static void e1000e_update_rdt_wa(struct e1000_adapter *adapter, unsigned int i)
553{
554 u8 __iomem *tail = (adapter->hw.hw_addr + adapter->rx_ring->tail);
555 struct e1000_hw *hw = &adapter->hw;
556
557 if (e1000e_update_tail_wa(hw, tail, i)) {
558 u32 rctl = er32(RCTL);
559 ew32(RCTL, rctl & ~E1000_RCTL_EN);
560 e_err("ME firmware caused invalid RDT - resetting\n");
561 schedule_work(&adapter->reset_task);
562 }
563}
564
565static void e1000e_update_tdt_wa(struct e1000_adapter *adapter, unsigned int i)
566{
567 u8 __iomem *tail = (adapter->hw.hw_addr + adapter->tx_ring->tail);
568 struct e1000_hw *hw = &adapter->hw;
569
570 if (e1000e_update_tail_wa(hw, tail, i)) {
571 u32 tctl = er32(TCTL);
572 ew32(TCTL, tctl & ~E1000_TCTL_EN);
573 e_err("ME firmware caused invalid TDT - resetting\n");
574 schedule_work(&adapter->reset_task);
575 }
576}
577
578/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700579 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
580 * @adapter: address of board private structure
581 **/
582static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000583 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700584{
585 struct net_device *netdev = adapter->netdev;
586 struct pci_dev *pdev = adapter->pdev;
587 struct e1000_ring *rx_ring = adapter->rx_ring;
588 struct e1000_rx_desc *rx_desc;
589 struct e1000_buffer *buffer_info;
590 struct sk_buff *skb;
591 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000592 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700593
594 i = rx_ring->next_to_use;
595 buffer_info = &rx_ring->buffer_info[i];
596
597 while (cleaned_count--) {
598 skb = buffer_info->skb;
599 if (skb) {
600 skb_trim(skb, 0);
601 goto map_skb;
602 }
603
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000604 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700605 if (!skb) {
606 /* Better luck next round */
607 adapter->alloc_rx_buff_failed++;
608 break;
609 }
610
Auke Kokbc7f75f2007-09-17 12:30:59 -0700611 buffer_info->skb = skb;
612map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000613 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000615 DMA_FROM_DEVICE);
616 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000617 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700618 adapter->rx_dma_failed++;
619 break;
620 }
621
622 rx_desc = E1000_RX_DESC(*rx_ring, i);
623 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
624
Tom Herbert50849d72010-05-05 14:02:49 +0000625 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
626 /*
627 * Force memory writes to complete before letting h/w
628 * know there are new descriptors to fetch. (Only
629 * applicable for weak-ordered memory model archs,
630 * such as IA-64).
631 */
632 wmb();
Bruce Allanc6e7f512011-07-29 05:53:02 +0000633 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
634 e1000e_update_rdt_wa(adapter, i);
635 else
636 writel(i, adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000637 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700638 i++;
639 if (i == rx_ring->count)
640 i = 0;
641 buffer_info = &rx_ring->buffer_info[i];
642 }
643
Tom Herbert50849d72010-05-05 14:02:49 +0000644 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700645}
646
647/**
648 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
649 * @adapter: address of board private structure
650 **/
651static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000652 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700653{
654 struct net_device *netdev = adapter->netdev;
655 struct pci_dev *pdev = adapter->pdev;
656 union e1000_rx_desc_packet_split *rx_desc;
657 struct e1000_ring *rx_ring = adapter->rx_ring;
658 struct e1000_buffer *buffer_info;
659 struct e1000_ps_page *ps_page;
660 struct sk_buff *skb;
661 unsigned int i, j;
662
663 i = rx_ring->next_to_use;
664 buffer_info = &rx_ring->buffer_info[i];
665
666 while (cleaned_count--) {
667 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
668
669 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700670 ps_page = &buffer_info->ps_pages[j];
671 if (j >= adapter->rx_ps_pages) {
672 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000673 rx_desc->read.buffer_addr[j + 1] =
674 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700675 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700676 }
Auke Kok47f44e42007-10-25 13:57:44 -0700677 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000678 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700679 if (!ps_page->page) {
680 adapter->alloc_rx_buff_failed++;
681 goto no_buffers;
682 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000683 ps_page->dma = dma_map_page(&pdev->dev,
684 ps_page->page,
685 0, PAGE_SIZE,
686 DMA_FROM_DEVICE);
687 if (dma_mapping_error(&pdev->dev,
688 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700689 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000690 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700691 adapter->rx_dma_failed++;
692 goto no_buffers;
693 }
694 }
695 /*
696 * Refresh the desc even if buffer_addrs
697 * didn't change because each write-back
698 * erases this info.
699 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000700 rx_desc->read.buffer_addr[j + 1] =
701 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700702 }
703
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000704 skb = __netdev_alloc_skb_ip_align(netdev,
705 adapter->rx_ps_bsize0,
706 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700707
708 if (!skb) {
709 adapter->alloc_rx_buff_failed++;
710 break;
711 }
712
Auke Kokbc7f75f2007-09-17 12:30:59 -0700713 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000714 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700715 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000716 DMA_FROM_DEVICE);
717 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000718 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700719 adapter->rx_dma_failed++;
720 /* cleanup skb */
721 dev_kfree_skb_any(skb);
722 buffer_info->skb = NULL;
723 break;
724 }
725
726 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
727
Tom Herbert50849d72010-05-05 14:02:49 +0000728 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
729 /*
730 * Force memory writes to complete before letting h/w
731 * know there are new descriptors to fetch. (Only
732 * applicable for weak-ordered memory model archs,
733 * such as IA-64).
734 */
735 wmb();
Bruce Allanc6e7f512011-07-29 05:53:02 +0000736 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
737 e1000e_update_rdt_wa(adapter, i << 1);
738 else
739 writel(i << 1,
740 adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000741 }
742
Auke Kokbc7f75f2007-09-17 12:30:59 -0700743 i++;
744 if (i == rx_ring->count)
745 i = 0;
746 buffer_info = &rx_ring->buffer_info[i];
747 }
748
749no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000750 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700751}
752
753/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700754 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
755 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700756 * @cleaned_count: number of buffers to allocate this pass
757 **/
758
759static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000760 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700761{
762 struct net_device *netdev = adapter->netdev;
763 struct pci_dev *pdev = adapter->pdev;
764 struct e1000_rx_desc *rx_desc;
765 struct e1000_ring *rx_ring = adapter->rx_ring;
766 struct e1000_buffer *buffer_info;
767 struct sk_buff *skb;
768 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000769 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700770
771 i = rx_ring->next_to_use;
772 buffer_info = &rx_ring->buffer_info[i];
773
774 while (cleaned_count--) {
775 skb = buffer_info->skb;
776 if (skb) {
777 skb_trim(skb, 0);
778 goto check_page;
779 }
780
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000781 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700782 if (unlikely(!skb)) {
783 /* Better luck next round */
784 adapter->alloc_rx_buff_failed++;
785 break;
786 }
787
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700788 buffer_info->skb = skb;
789check_page:
790 /* allocate a new page if necessary */
791 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000792 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700793 if (unlikely(!buffer_info->page)) {
794 adapter->alloc_rx_buff_failed++;
795 break;
796 }
797 }
798
799 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000800 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700801 buffer_info->page, 0,
802 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000803 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700804
805 rx_desc = E1000_RX_DESC(*rx_ring, i);
806 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
807
808 if (unlikely(++i == rx_ring->count))
809 i = 0;
810 buffer_info = &rx_ring->buffer_info[i];
811 }
812
813 if (likely(rx_ring->next_to_use != i)) {
814 rx_ring->next_to_use = i;
815 if (unlikely(i-- == 0))
816 i = (rx_ring->count - 1);
817
818 /* Force memory writes to complete before letting h/w
819 * know there are new descriptors to fetch. (Only
820 * applicable for weak-ordered memory model archs,
821 * such as IA-64). */
822 wmb();
Bruce Allanc6e7f512011-07-29 05:53:02 +0000823 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
824 e1000e_update_rdt_wa(adapter, i);
825 else
826 writel(i, adapter->hw.hw_addr + rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700827 }
828}
829
830/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700831 * e1000_clean_rx_irq - Send received data up the network stack; legacy
832 * @adapter: board private structure
833 *
834 * the return value indicates whether actual cleaning was done, there
835 * is no guarantee that everything was cleaned
836 **/
837static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
838 int *work_done, int work_to_do)
839{
840 struct net_device *netdev = adapter->netdev;
841 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000842 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700843 struct e1000_ring *rx_ring = adapter->rx_ring;
844 struct e1000_rx_desc *rx_desc, *next_rxd;
845 struct e1000_buffer *buffer_info, *next_buffer;
846 u32 length;
847 unsigned int i;
848 int cleaned_count = 0;
849 bool cleaned = 0;
850 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
851
852 i = rx_ring->next_to_clean;
853 rx_desc = E1000_RX_DESC(*rx_ring, i);
854 buffer_info = &rx_ring->buffer_info[i];
855
856 while (rx_desc->status & E1000_RXD_STAT_DD) {
857 struct sk_buff *skb;
858 u8 status;
859
860 if (*work_done >= work_to_do)
861 break;
862 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000863 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700864
865 status = rx_desc->status;
866 skb = buffer_info->skb;
867 buffer_info->skb = NULL;
868
869 prefetch(skb->data - NET_IP_ALIGN);
870
871 i++;
872 if (i == rx_ring->count)
873 i = 0;
874 next_rxd = E1000_RX_DESC(*rx_ring, i);
875 prefetch(next_rxd);
876
877 next_buffer = &rx_ring->buffer_info[i];
878
879 cleaned = 1;
880 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000881 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700882 buffer_info->dma,
883 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000884 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700885 buffer_info->dma = 0;
886
887 length = le16_to_cpu(rx_desc->length);
888
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000889 /*
890 * !EOP means multiple descriptors were used to store a single
891 * packet, if that's the case we need to toss it. In fact, we
892 * need to toss every packet with the EOP bit clear and the
893 * next frame that _does_ have the EOP bit set, as it is by
894 * definition only a frame fragment
895 */
896 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
897 adapter->flags2 |= FLAG2_IS_DISCARDING;
898
899 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700900 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000901 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700902 /* recycle */
903 buffer_info->skb = skb;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000904 if (status & E1000_RXD_STAT_EOP)
905 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700906 goto next_desc;
907 }
908
909 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
910 /* recycle */
911 buffer_info->skb = skb;
912 goto next_desc;
913 }
914
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000915 /* adjust length to remove Ethernet CRC */
916 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
917 length -= 4;
918
Auke Kokbc7f75f2007-09-17 12:30:59 -0700919 total_rx_bytes += length;
920 total_rx_packets++;
921
Bruce Allanad680762008-03-28 09:15:03 -0700922 /*
923 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700924 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700925 * of reassembly being done in the stack
926 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700927 if (length < copybreak) {
928 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000929 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700930 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700931 skb_copy_to_linear_data_offset(new_skb,
932 -NET_IP_ALIGN,
933 (skb->data -
934 NET_IP_ALIGN),
935 (length +
936 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700937 /* save the skb in buffer_info as good */
938 buffer_info->skb = skb;
939 skb = new_skb;
940 }
941 /* else just continue with the old one */
942 }
943 /* end copybreak code */
944 skb_put(skb, length);
945
946 /* Receive Checksum Offload */
947 e1000_rx_checksum(adapter,
948 (u32)(status) |
949 ((u32)(rx_desc->errors) << 24),
950 le16_to_cpu(rx_desc->csum), skb);
951
952 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
953
954next_desc:
955 rx_desc->status = 0;
956
957 /* return some buffers to hardware, one at a time is too slow */
958 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000959 adapter->alloc_rx_buf(adapter, cleaned_count,
960 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961 cleaned_count = 0;
962 }
963
964 /* use prefetched values */
965 rx_desc = next_rxd;
966 buffer_info = next_buffer;
967 }
968 rx_ring->next_to_clean = i;
969
970 cleaned_count = e1000_desc_unused(rx_ring);
971 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000972 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973
Auke Kokbc7f75f2007-09-17 12:30:59 -0700974 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700975 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700976 return cleaned;
977}
978
Auke Kokbc7f75f2007-09-17 12:30:59 -0700979static void e1000_put_txbuf(struct e1000_adapter *adapter,
980 struct e1000_buffer *buffer_info)
981{
Alexander Duyck03b13202009-12-02 16:45:31 +0000982 if (buffer_info->dma) {
983 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +0000984 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
985 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000986 else
Nick Nunley0be3f552010-04-27 13:09:05 +0000987 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
988 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000989 buffer_info->dma = 0;
990 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 if (buffer_info->skb) {
992 dev_kfree_skb_any(buffer_info->skb);
993 buffer_info->skb = NULL;
994 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000995 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700996}
997
Bruce Allan41cec6f2009-11-20 23:28:56 +0000998static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001000 struct e1000_adapter *adapter = container_of(work,
1001 struct e1000_adapter,
1002 print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003 struct e1000_ring *tx_ring = adapter->tx_ring;
1004 unsigned int i = tx_ring->next_to_clean;
1005 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1006 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001007 struct e1000_hw *hw = &adapter->hw;
1008 u16 phy_status, phy_1000t_status, phy_ext_status;
1009 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001011 if (test_bit(__E1000_DOWN, &adapter->state))
1012 return;
1013
Bruce Allan41cec6f2009-11-20 23:28:56 +00001014 e1e_rphy(hw, PHY_STATUS, &phy_status);
1015 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1016 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1017
1018 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1019
1020 /* detected Hardware unit hang */
1021 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001022 " TDH <%x>\n"
1023 " TDT <%x>\n"
1024 " next_to_use <%x>\n"
1025 " next_to_clean <%x>\n"
1026 "buffer_info[next_to_clean]:\n"
1027 " time_stamp <%lx>\n"
1028 " next_to_watch <%x>\n"
1029 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001030 " next_to_watch.status <%x>\n"
1031 "MAC Status <%x>\n"
1032 "PHY Status <%x>\n"
1033 "PHY 1000BASE-T Status <%x>\n"
1034 "PHY Extended Status <%x>\n"
1035 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001036 readl(adapter->hw.hw_addr + tx_ring->head),
1037 readl(adapter->hw.hw_addr + tx_ring->tail),
1038 tx_ring->next_to_use,
1039 tx_ring->next_to_clean,
1040 tx_ring->buffer_info[eop].time_stamp,
1041 eop,
1042 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001043 eop_desc->upper.fields.status,
1044 er32(STATUS),
1045 phy_status,
1046 phy_1000t_status,
1047 phy_ext_status,
1048 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049}
1050
1051/**
1052 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1053 * @adapter: board private structure
1054 *
1055 * the return value indicates whether actual cleaning was done, there
1056 * is no guarantee that everything was cleaned
1057 **/
1058static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
1059{
1060 struct net_device *netdev = adapter->netdev;
1061 struct e1000_hw *hw = &adapter->hw;
1062 struct e1000_ring *tx_ring = adapter->tx_ring;
1063 struct e1000_tx_desc *tx_desc, *eop_desc;
1064 struct e1000_buffer *buffer_info;
1065 unsigned int i, eop;
1066 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001067 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1068
1069 i = tx_ring->next_to_clean;
1070 eop = tx_ring->buffer_info[i].next_to_watch;
1071 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1072
Alexander Duyck12d04a32009-03-25 22:05:03 +00001073 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1074 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001075 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001076 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001077 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001078 tx_desc = E1000_TX_DESC(*tx_ring, i);
1079 buffer_info = &tx_ring->buffer_info[i];
1080 cleaned = (i == eop);
1081
1082 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001083 total_tx_packets += buffer_info->segs;
1084 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001085 }
1086
1087 e1000_put_txbuf(adapter, buffer_info);
1088 tx_desc->upper.data = 0;
1089
1090 i++;
1091 if (i == tx_ring->count)
1092 i = 0;
1093 }
1094
Terry Loftindac87612010-04-09 10:29:49 +00001095 if (i == tx_ring->next_to_use)
1096 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097 eop = tx_ring->buffer_info[i].next_to_watch;
1098 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099 }
1100
1101 tx_ring->next_to_clean = i;
1102
1103#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001104 if (count && netif_carrier_ok(netdev) &&
1105 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001106 /* Make sure that anybody stopping the queue after this
1107 * sees the new next_to_clean.
1108 */
1109 smp_mb();
1110
1111 if (netif_queue_stopped(netdev) &&
1112 !(test_bit(__E1000_DOWN, &adapter->state))) {
1113 netif_wake_queue(netdev);
1114 ++adapter->restart_queue;
1115 }
1116 }
1117
1118 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001119 /*
1120 * Detect a transmit hang in hardware, this serializes the
1121 * check with the clearing of time_stamp and movement of i
1122 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001123 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001124 if (tx_ring->buffer_info[i].time_stamp &&
1125 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001126 + (adapter->tx_timeout_factor * HZ)) &&
1127 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001128 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129 netif_stop_queue(netdev);
1130 }
1131 }
1132 adapter->total_tx_bytes += total_tx_bytes;
1133 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001134 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001135}
1136
1137/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1139 * @adapter: board private structure
1140 *
1141 * the return value indicates whether actual cleaning was done, there
1142 * is no guarantee that everything was cleaned
1143 **/
1144static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1145 int *work_done, int work_to_do)
1146{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001147 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001148 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1149 struct net_device *netdev = adapter->netdev;
1150 struct pci_dev *pdev = adapter->pdev;
1151 struct e1000_ring *rx_ring = adapter->rx_ring;
1152 struct e1000_buffer *buffer_info, *next_buffer;
1153 struct e1000_ps_page *ps_page;
1154 struct sk_buff *skb;
1155 unsigned int i, j;
1156 u32 length, staterr;
1157 int cleaned_count = 0;
1158 bool cleaned = 0;
1159 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1160
1161 i = rx_ring->next_to_clean;
1162 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1163 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1164 buffer_info = &rx_ring->buffer_info[i];
1165
1166 while (staterr & E1000_RXD_STAT_DD) {
1167 if (*work_done >= work_to_do)
1168 break;
1169 (*work_done)++;
1170 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001171 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001172
1173 /* in the packet split case this is header only */
1174 prefetch(skb->data - NET_IP_ALIGN);
1175
1176 i++;
1177 if (i == rx_ring->count)
1178 i = 0;
1179 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1180 prefetch(next_rxd);
1181
1182 next_buffer = &rx_ring->buffer_info[i];
1183
1184 cleaned = 1;
1185 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001186 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001187 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001188 buffer_info->dma = 0;
1189
Bruce Allanaf667a22010-12-31 06:10:01 +00001190 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001191 if (!(staterr & E1000_RXD_STAT_EOP))
1192 adapter->flags2 |= FLAG2_IS_DISCARDING;
1193
1194 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001195 e_dbg("Packet Split buffers didn't pick up the full "
1196 "packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001197 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001198 if (staterr & E1000_RXD_STAT_EOP)
1199 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 goto next_desc;
1201 }
1202
1203 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1204 dev_kfree_skb_irq(skb);
1205 goto next_desc;
1206 }
1207
1208 length = le16_to_cpu(rx_desc->wb.middle.length0);
1209
1210 if (!length) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001211 e_dbg("Last part of the packet spanning multiple "
1212 "descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213 dev_kfree_skb_irq(skb);
1214 goto next_desc;
1215 }
1216
1217 /* Good Receive */
1218 skb_put(skb, length);
1219
1220 {
Bruce Allanad680762008-03-28 09:15:03 -07001221 /*
1222 * this looks ugly, but it seems compiler issues make it
1223 * more efficient than reusing j
1224 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001225 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1226
Bruce Allanad680762008-03-28 09:15:03 -07001227 /*
1228 * page alloc/put takes too long and effects small packet
1229 * throughput, so unsplit small packets and save the alloc/put
1230 * only valid in softirq (napi) context to call kmap_*
1231 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001232 if (l1 && (l1 <= copybreak) &&
1233 ((length + l1) <= adapter->rx_ps_bsize0)) {
1234 u8 *vaddr;
1235
Auke Kok47f44e42007-10-25 13:57:44 -07001236 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001237
Bruce Allanad680762008-03-28 09:15:03 -07001238 /*
1239 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001240 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001241 * very long
1242 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001243 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1244 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001245 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1246 memcpy(skb_tail_pointer(skb), vaddr, l1);
1247 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001248 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1249 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001250
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001251 /* remove the CRC */
1252 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1253 l1 -= 4;
1254
Auke Kokbc7f75f2007-09-17 12:30:59 -07001255 skb_put(skb, l1);
1256 goto copydone;
1257 } /* if */
1258 }
1259
1260 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1261 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1262 if (!length)
1263 break;
1264
Auke Kok47f44e42007-10-25 13:57:44 -07001265 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001266 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1267 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001268 ps_page->dma = 0;
1269 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1270 ps_page->page = NULL;
1271 skb->len += length;
1272 skb->data_len += length;
1273 skb->truesize += length;
1274 }
1275
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001276 /* strip the ethernet crc, problem is we're using pages now so
1277 * this whole operation can get a little cpu intensive
1278 */
1279 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1280 pskb_trim(skb, skb->len - 4);
1281
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282copydone:
1283 total_rx_bytes += skb->len;
1284 total_rx_packets++;
1285
1286 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1287 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1288
1289 if (rx_desc->wb.upper.header_status &
1290 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1291 adapter->rx_hdr_split++;
1292
1293 e1000_receive_skb(adapter, netdev, skb,
1294 staterr, rx_desc->wb.middle.vlan);
1295
1296next_desc:
1297 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1298 buffer_info->skb = NULL;
1299
1300 /* return some buffers to hardware, one at a time is too slow */
1301 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001302 adapter->alloc_rx_buf(adapter, cleaned_count,
1303 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001304 cleaned_count = 0;
1305 }
1306
1307 /* use prefetched values */
1308 rx_desc = next_rxd;
1309 buffer_info = next_buffer;
1310
1311 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1312 }
1313 rx_ring->next_to_clean = i;
1314
1315 cleaned_count = e1000_desc_unused(rx_ring);
1316 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001317 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001318
Auke Kokbc7f75f2007-09-17 12:30:59 -07001319 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001320 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001321 return cleaned;
1322}
1323
1324/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001325 * e1000_consume_page - helper function
1326 **/
1327static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1328 u16 length)
1329{
1330 bi->page = NULL;
1331 skb->len += length;
1332 skb->data_len += length;
1333 skb->truesize += length;
1334}
1335
1336/**
1337 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1338 * @adapter: board private structure
1339 *
1340 * the return value indicates whether actual cleaning was done, there
1341 * is no guarantee that everything was cleaned
1342 **/
1343
1344static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1345 int *work_done, int work_to_do)
1346{
1347 struct net_device *netdev = adapter->netdev;
1348 struct pci_dev *pdev = adapter->pdev;
1349 struct e1000_ring *rx_ring = adapter->rx_ring;
1350 struct e1000_rx_desc *rx_desc, *next_rxd;
1351 struct e1000_buffer *buffer_info, *next_buffer;
1352 u32 length;
1353 unsigned int i;
1354 int cleaned_count = 0;
1355 bool cleaned = false;
1356 unsigned int total_rx_bytes=0, total_rx_packets=0;
1357
1358 i = rx_ring->next_to_clean;
1359 rx_desc = E1000_RX_DESC(*rx_ring, i);
1360 buffer_info = &rx_ring->buffer_info[i];
1361
1362 while (rx_desc->status & E1000_RXD_STAT_DD) {
1363 struct sk_buff *skb;
1364 u8 status;
1365
1366 if (*work_done >= work_to_do)
1367 break;
1368 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001369 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001370
1371 status = rx_desc->status;
1372 skb = buffer_info->skb;
1373 buffer_info->skb = NULL;
1374
1375 ++i;
1376 if (i == rx_ring->count)
1377 i = 0;
1378 next_rxd = E1000_RX_DESC(*rx_ring, i);
1379 prefetch(next_rxd);
1380
1381 next_buffer = &rx_ring->buffer_info[i];
1382
1383 cleaned = true;
1384 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001385 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1386 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001387 buffer_info->dma = 0;
1388
1389 length = le16_to_cpu(rx_desc->length);
1390
1391 /* errors is only valid for DD + EOP descriptors */
1392 if (unlikely((status & E1000_RXD_STAT_EOP) &&
1393 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
1394 /* recycle both page and skb */
1395 buffer_info->skb = skb;
1396 /* an error means any chain goes out the window
1397 * too */
1398 if (rx_ring->rx_skb_top)
Bruce Allanef5ab892011-02-10 08:17:21 +00001399 dev_kfree_skb_irq(rx_ring->rx_skb_top);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001400 rx_ring->rx_skb_top = NULL;
1401 goto next_desc;
1402 }
1403
Bruce Allanf0f1a172010-12-11 05:53:32 +00001404#define rxtop (rx_ring->rx_skb_top)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001405 if (!(status & E1000_RXD_STAT_EOP)) {
1406 /* this descriptor is only the beginning (or middle) */
1407 if (!rxtop) {
1408 /* this is the beginning of a chain */
1409 rxtop = skb;
1410 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1411 0, length);
1412 } else {
1413 /* this is the middle of a chain */
1414 skb_fill_page_desc(rxtop,
1415 skb_shinfo(rxtop)->nr_frags,
1416 buffer_info->page, 0, length);
1417 /* re-use the skb, only consumed the page */
1418 buffer_info->skb = skb;
1419 }
1420 e1000_consume_page(buffer_info, rxtop, length);
1421 goto next_desc;
1422 } else {
1423 if (rxtop) {
1424 /* end of the chain */
1425 skb_fill_page_desc(rxtop,
1426 skb_shinfo(rxtop)->nr_frags,
1427 buffer_info->page, 0, length);
1428 /* re-use the current skb, we only consumed the
1429 * page */
1430 buffer_info->skb = skb;
1431 skb = rxtop;
1432 rxtop = NULL;
1433 e1000_consume_page(buffer_info, skb, length);
1434 } else {
1435 /* no chain, got EOP, this buf is the packet
1436 * copybreak to save the put_page/alloc_page */
1437 if (length <= copybreak &&
1438 skb_tailroom(skb) >= length) {
1439 u8 *vaddr;
1440 vaddr = kmap_atomic(buffer_info->page,
1441 KM_SKB_DATA_SOFTIRQ);
1442 memcpy(skb_tail_pointer(skb), vaddr,
1443 length);
1444 kunmap_atomic(vaddr,
1445 KM_SKB_DATA_SOFTIRQ);
1446 /* re-use the page, so don't erase
1447 * buffer_info->page */
1448 skb_put(skb, length);
1449 } else {
1450 skb_fill_page_desc(skb, 0,
1451 buffer_info->page, 0,
1452 length);
1453 e1000_consume_page(buffer_info, skb,
1454 length);
1455 }
1456 }
1457 }
1458
1459 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1460 e1000_rx_checksum(adapter,
1461 (u32)(status) |
1462 ((u32)(rx_desc->errors) << 24),
1463 le16_to_cpu(rx_desc->csum), skb);
1464
1465 /* probably a little skewed due to removing CRC */
1466 total_rx_bytes += skb->len;
1467 total_rx_packets++;
1468
1469 /* eth type trans needs skb->data to point to something */
1470 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001471 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001472 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001473 goto next_desc;
1474 }
1475
1476 e1000_receive_skb(adapter, netdev, skb, status,
1477 rx_desc->special);
1478
1479next_desc:
1480 rx_desc->status = 0;
1481
1482 /* return some buffers to hardware, one at a time is too slow */
1483 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001484 adapter->alloc_rx_buf(adapter, cleaned_count,
1485 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001486 cleaned_count = 0;
1487 }
1488
1489 /* use prefetched values */
1490 rx_desc = next_rxd;
1491 buffer_info = next_buffer;
1492 }
1493 rx_ring->next_to_clean = i;
1494
1495 cleaned_count = e1000_desc_unused(rx_ring);
1496 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001497 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001498
1499 adapter->total_rx_bytes += total_rx_bytes;
1500 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001501 return cleaned;
1502}
1503
1504/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001505 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1506 * @adapter: board private structure
1507 **/
1508static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1509{
1510 struct e1000_ring *rx_ring = adapter->rx_ring;
1511 struct e1000_buffer *buffer_info;
1512 struct e1000_ps_page *ps_page;
1513 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001514 unsigned int i, j;
1515
1516 /* Free all the Rx ring sk_buffs */
1517 for (i = 0; i < rx_ring->count; i++) {
1518 buffer_info = &rx_ring->buffer_info[i];
1519 if (buffer_info->dma) {
1520 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001521 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001522 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001523 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001524 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001525 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001526 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001527 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001528 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001529 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001530 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001531 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001532 buffer_info->dma = 0;
1533 }
1534
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001535 if (buffer_info->page) {
1536 put_page(buffer_info->page);
1537 buffer_info->page = NULL;
1538 }
1539
Auke Kokbc7f75f2007-09-17 12:30:59 -07001540 if (buffer_info->skb) {
1541 dev_kfree_skb(buffer_info->skb);
1542 buffer_info->skb = NULL;
1543 }
1544
1545 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001546 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001547 if (!ps_page->page)
1548 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001549 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1550 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001551 ps_page->dma = 0;
1552 put_page(ps_page->page);
1553 ps_page->page = NULL;
1554 }
1555 }
1556
1557 /* there also may be some cached data from a chained receive */
1558 if (rx_ring->rx_skb_top) {
1559 dev_kfree_skb(rx_ring->rx_skb_top);
1560 rx_ring->rx_skb_top = NULL;
1561 }
1562
Auke Kokbc7f75f2007-09-17 12:30:59 -07001563 /* Zero out the descriptor ring */
1564 memset(rx_ring->desc, 0, rx_ring->size);
1565
1566 rx_ring->next_to_clean = 0;
1567 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001568 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001569
1570 writel(0, adapter->hw.hw_addr + rx_ring->head);
1571 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1572}
1573
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001574static void e1000e_downshift_workaround(struct work_struct *work)
1575{
1576 struct e1000_adapter *adapter = container_of(work,
1577 struct e1000_adapter, downshift_task);
1578
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001579 if (test_bit(__E1000_DOWN, &adapter->state))
1580 return;
1581
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001582 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1583}
1584
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585/**
1586 * e1000_intr_msi - Interrupt Handler
1587 * @irq: interrupt number
1588 * @data: pointer to a network interface device structure
1589 **/
1590static irqreturn_t e1000_intr_msi(int irq, void *data)
1591{
1592 struct net_device *netdev = data;
1593 struct e1000_adapter *adapter = netdev_priv(netdev);
1594 struct e1000_hw *hw = &adapter->hw;
1595 u32 icr = er32(ICR);
1596
Bruce Allanad680762008-03-28 09:15:03 -07001597 /*
1598 * read ICR disables interrupts using IAM
1599 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001600
dave graham573cca82009-02-10 12:52:05 +00001601 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001602 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001603 /*
1604 * ICH8 workaround-- Call gig speed drop workaround on cable
1605 * disconnect (LSC) before accessing any PHY registers
1606 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001607 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1608 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001609 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001610
Bruce Allanad680762008-03-28 09:15:03 -07001611 /*
1612 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001613 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001614 * adapter in watchdog
1615 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616 if (netif_carrier_ok(netdev) &&
1617 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1618 /* disable receives */
1619 u32 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
1639/**
1640 * e1000_intr - Interrupt Handler
1641 * @irq: interrupt number
1642 * @data: pointer to a network interface device structure
1643 **/
1644static irqreturn_t e1000_intr(int irq, void *data)
1645{
1646 struct net_device *netdev = data;
1647 struct e1000_adapter *adapter = netdev_priv(netdev);
1648 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001649 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001650
Bruce Allana68ea772009-11-20 23:23:16 +00001651 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001652 return IRQ_NONE; /* Not our interrupt */
1653
Bruce Allanad680762008-03-28 09:15:03 -07001654 /*
1655 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1656 * not set, then the adapter didn't send an interrupt
1657 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001658 if (!(icr & E1000_ICR_INT_ASSERTED))
1659 return IRQ_NONE;
1660
Bruce Allanad680762008-03-28 09:15:03 -07001661 /*
1662 * Interrupt Auto-Mask...upon reading ICR,
1663 * interrupts are masked. No need for the
1664 * IMC write
1665 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666
dave graham573cca82009-02-10 12:52:05 +00001667 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001668 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001669 /*
1670 * ICH8 workaround-- Call gig speed drop workaround on cable
1671 * disconnect (LSC) before accessing any PHY registers
1672 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001673 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1674 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001675 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001676
Bruce Allanad680762008-03-28 09:15:03 -07001677 /*
1678 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001679 * For packet buffer work-around on link down event;
1680 * disable receives here in the ISR and
1681 * reset adapter in watchdog
1682 */
1683 if (netif_carrier_ok(netdev) &&
1684 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1685 /* disable receives */
1686 rctl = er32(RCTL);
1687 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001688 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689 }
1690 /* guard against interrupt when we're going down */
1691 if (!test_bit(__E1000_DOWN, &adapter->state))
1692 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1693 }
1694
Ben Hutchings288379f2009-01-19 16:43:59 -08001695 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001696 adapter->total_tx_bytes = 0;
1697 adapter->total_tx_packets = 0;
1698 adapter->total_rx_bytes = 0;
1699 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001700 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001701 }
1702
1703 return IRQ_HANDLED;
1704}
1705
Bruce Allan4662e822008-08-26 18:37:06 -07001706static irqreturn_t e1000_msix_other(int irq, void *data)
1707{
1708 struct net_device *netdev = data;
1709 struct e1000_adapter *adapter = netdev_priv(netdev);
1710 struct e1000_hw *hw = &adapter->hw;
1711 u32 icr = er32(ICR);
1712
1713 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001714 if (!test_bit(__E1000_DOWN, &adapter->state))
1715 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001716 return IRQ_NONE;
1717 }
1718
1719 if (icr & adapter->eiac_mask)
1720 ew32(ICS, (icr & adapter->eiac_mask));
1721
1722 if (icr & E1000_ICR_OTHER) {
1723 if (!(icr & E1000_ICR_LSC))
1724 goto no_link_interrupt;
1725 hw->mac.get_link_status = 1;
1726 /* guard against interrupt when we're going down */
1727 if (!test_bit(__E1000_DOWN, &adapter->state))
1728 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1729 }
1730
1731no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001732 if (!test_bit(__E1000_DOWN, &adapter->state))
1733 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001734
1735 return IRQ_HANDLED;
1736}
1737
1738
1739static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1740{
1741 struct net_device *netdev = data;
1742 struct e1000_adapter *adapter = netdev_priv(netdev);
1743 struct e1000_hw *hw = &adapter->hw;
1744 struct e1000_ring *tx_ring = adapter->tx_ring;
1745
1746
1747 adapter->total_tx_bytes = 0;
1748 adapter->total_tx_packets = 0;
1749
1750 if (!e1000_clean_tx_irq(adapter))
1751 /* Ring was not completely cleaned, so fire another interrupt */
1752 ew32(ICS, tx_ring->ims_val);
1753
1754 return IRQ_HANDLED;
1755}
1756
1757static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1758{
1759 struct net_device *netdev = data;
1760 struct e1000_adapter *adapter = netdev_priv(netdev);
1761
1762 /* Write the ITR value calculated at the end of the
1763 * previous interrupt.
1764 */
1765 if (adapter->rx_ring->set_itr) {
1766 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1767 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1768 adapter->rx_ring->set_itr = 0;
1769 }
1770
Ben Hutchings288379f2009-01-19 16:43:59 -08001771 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001772 adapter->total_rx_bytes = 0;
1773 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001774 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001775 }
1776 return IRQ_HANDLED;
1777}
1778
1779/**
1780 * e1000_configure_msix - Configure MSI-X hardware
1781 *
1782 * e1000_configure_msix sets up the hardware to properly
1783 * generate MSI-X interrupts.
1784 **/
1785static void e1000_configure_msix(struct e1000_adapter *adapter)
1786{
1787 struct e1000_hw *hw = &adapter->hw;
1788 struct e1000_ring *rx_ring = adapter->rx_ring;
1789 struct e1000_ring *tx_ring = adapter->tx_ring;
1790 int vector = 0;
1791 u32 ctrl_ext, ivar = 0;
1792
1793 adapter->eiac_mask = 0;
1794
1795 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1796 if (hw->mac.type == e1000_82574) {
1797 u32 rfctl = er32(RFCTL);
1798 rfctl |= E1000_RFCTL_ACK_DIS;
1799 ew32(RFCTL, rfctl);
1800 }
1801
1802#define E1000_IVAR_INT_ALLOC_VALID 0x8
1803 /* Configure Rx vector */
1804 rx_ring->ims_val = E1000_IMS_RXQ0;
1805 adapter->eiac_mask |= rx_ring->ims_val;
1806 if (rx_ring->itr_val)
1807 writel(1000000000 / (rx_ring->itr_val * 256),
1808 hw->hw_addr + rx_ring->itr_register);
1809 else
1810 writel(1, hw->hw_addr + rx_ring->itr_register);
1811 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1812
1813 /* Configure Tx vector */
1814 tx_ring->ims_val = E1000_IMS_TXQ0;
1815 vector++;
1816 if (tx_ring->itr_val)
1817 writel(1000000000 / (tx_ring->itr_val * 256),
1818 hw->hw_addr + tx_ring->itr_register);
1819 else
1820 writel(1, hw->hw_addr + tx_ring->itr_register);
1821 adapter->eiac_mask |= tx_ring->ims_val;
1822 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1823
1824 /* set vector for Other Causes, e.g. link changes */
1825 vector++;
1826 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1827 if (rx_ring->itr_val)
1828 writel(1000000000 / (rx_ring->itr_val * 256),
1829 hw->hw_addr + E1000_EITR_82574(vector));
1830 else
1831 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1832
1833 /* Cause Tx interrupts on every write back */
1834 ivar |= (1 << 31);
1835
1836 ew32(IVAR, ivar);
1837
1838 /* enable MSI-X PBA support */
1839 ctrl_ext = er32(CTRL_EXT);
1840 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1841
1842 /* Auto-Mask Other interrupts upon ICR read */
1843#define E1000_EIAC_MASK_82574 0x01F00000
1844 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1845 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1846 ew32(CTRL_EXT, ctrl_ext);
1847 e1e_flush();
1848}
1849
1850void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1851{
1852 if (adapter->msix_entries) {
1853 pci_disable_msix(adapter->pdev);
1854 kfree(adapter->msix_entries);
1855 adapter->msix_entries = NULL;
1856 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1857 pci_disable_msi(adapter->pdev);
1858 adapter->flags &= ~FLAG_MSI_ENABLED;
1859 }
Bruce Allan4662e822008-08-26 18:37:06 -07001860}
1861
1862/**
1863 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1864 *
1865 * Attempt to configure interrupts using the best available
1866 * capabilities of the hardware and kernel.
1867 **/
1868void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1869{
1870 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001871 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001872
1873 switch (adapter->int_mode) {
1874 case E1000E_INT_MODE_MSIX:
1875 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001876 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1877 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001878 sizeof(struct msix_entry),
1879 GFP_KERNEL);
1880 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001881 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001882 adapter->msix_entries[i].entry = i;
1883
1884 err = pci_enable_msix(adapter->pdev,
1885 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001886 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001887 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001888 return;
1889 }
1890 /* MSI-X failed, so fall through and try MSI */
1891 e_err("Failed to initialize MSI-X interrupts. "
1892 "Falling back to MSI interrupts.\n");
1893 e1000e_reset_interrupt_capability(adapter);
1894 }
1895 adapter->int_mode = E1000E_INT_MODE_MSI;
1896 /* Fall through */
1897 case E1000E_INT_MODE_MSI:
1898 if (!pci_enable_msi(adapter->pdev)) {
1899 adapter->flags |= FLAG_MSI_ENABLED;
1900 } else {
1901 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1902 e_err("Failed to initialize MSI interrupts. Falling "
1903 "back to legacy interrupts.\n");
1904 }
1905 /* Fall through */
1906 case E1000E_INT_MODE_LEGACY:
1907 /* Don't do anything; this is the system default */
1908 break;
1909 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001910
1911 /* store the number of vectors being used */
1912 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001913}
1914
1915/**
1916 * e1000_request_msix - Initialize MSI-X interrupts
1917 *
1918 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1919 * kernel.
1920 **/
1921static int e1000_request_msix(struct e1000_adapter *adapter)
1922{
1923 struct net_device *netdev = adapter->netdev;
1924 int err = 0, vector = 0;
1925
1926 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001927 snprintf(adapter->rx_ring->name,
1928 sizeof(adapter->rx_ring->name) - 1,
1929 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001930 else
1931 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1932 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001933 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001934 netdev);
1935 if (err)
1936 goto out;
1937 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1938 adapter->rx_ring->itr_val = adapter->itr;
1939 vector++;
1940
1941 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001942 snprintf(adapter->tx_ring->name,
1943 sizeof(adapter->tx_ring->name) - 1,
1944 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001945 else
1946 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1947 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001948 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001949 netdev);
1950 if (err)
1951 goto out;
1952 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1953 adapter->tx_ring->itr_val = adapter->itr;
1954 vector++;
1955
1956 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001957 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001958 if (err)
1959 goto out;
1960
1961 e1000_configure_msix(adapter);
1962 return 0;
1963out:
1964 return err;
1965}
1966
Bruce Allanf8d59f72008-08-08 18:36:11 -07001967/**
1968 * e1000_request_irq - initialize interrupts
1969 *
1970 * Attempts to configure interrupts using the best available
1971 * capabilities of the hardware and kernel.
1972 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001973static int e1000_request_irq(struct e1000_adapter *adapter)
1974{
1975 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001976 int err;
1977
Bruce Allan4662e822008-08-26 18:37:06 -07001978 if (adapter->msix_entries) {
1979 err = e1000_request_msix(adapter);
1980 if (!err)
1981 return err;
1982 /* fall back to MSI */
1983 e1000e_reset_interrupt_capability(adapter);
1984 adapter->int_mode = E1000E_INT_MODE_MSI;
1985 e1000e_set_interrupt_capability(adapter);
1986 }
1987 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001988 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001989 netdev->name, netdev);
1990 if (!err)
1991 return err;
1992
1993 /* fall back to legacy interrupt */
1994 e1000e_reset_interrupt_capability(adapter);
1995 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001996 }
1997
Joe Perchesa0607fd2009-11-18 23:29:17 -08001998 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001999 netdev->name, netdev);
2000 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002001 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002002
2003 return err;
2004}
2005
2006static void e1000_free_irq(struct e1000_adapter *adapter)
2007{
2008 struct net_device *netdev = adapter->netdev;
2009
Bruce Allan4662e822008-08-26 18:37:06 -07002010 if (adapter->msix_entries) {
2011 int vector = 0;
2012
2013 free_irq(adapter->msix_entries[vector].vector, netdev);
2014 vector++;
2015
2016 free_irq(adapter->msix_entries[vector].vector, netdev);
2017 vector++;
2018
2019 /* Other Causes interrupt vector */
2020 free_irq(adapter->msix_entries[vector].vector, netdev);
2021 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002022 }
Bruce Allan4662e822008-08-26 18:37:06 -07002023
2024 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002025}
2026
2027/**
2028 * e1000_irq_disable - Mask off interrupt generation on the NIC
2029 **/
2030static void e1000_irq_disable(struct e1000_adapter *adapter)
2031{
2032 struct e1000_hw *hw = &adapter->hw;
2033
Auke Kokbc7f75f2007-09-17 12:30:59 -07002034 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002035 if (adapter->msix_entries)
2036 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002037 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002038
2039 if (adapter->msix_entries) {
2040 int i;
2041 for (i = 0; i < adapter->num_vectors; i++)
2042 synchronize_irq(adapter->msix_entries[i].vector);
2043 } else {
2044 synchronize_irq(adapter->pdev->irq);
2045 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002046}
2047
2048/**
2049 * e1000_irq_enable - Enable default interrupt generation settings
2050 **/
2051static void e1000_irq_enable(struct e1000_adapter *adapter)
2052{
2053 struct e1000_hw *hw = &adapter->hw;
2054
Bruce Allan4662e822008-08-26 18:37:06 -07002055 if (adapter->msix_entries) {
2056 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2057 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2058 } else {
2059 ew32(IMS, IMS_ENABLE_MASK);
2060 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002061 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002062}
2063
2064/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002065 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002066 * @adapter: address of board private structure
2067 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002068 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002069 * For ASF and Pass Through versions of f/w this means that
2070 * the driver is loaded. For AMT version (only with 82573)
2071 * of the f/w this means that the network i/f is open.
2072 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002073void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002074{
2075 struct e1000_hw *hw = &adapter->hw;
2076 u32 ctrl_ext;
2077 u32 swsm;
2078
2079 /* Let firmware know the driver has taken over */
2080 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2081 swsm = er32(SWSM);
2082 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2083 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2084 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002085 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002086 }
2087}
2088
2089/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002090 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002091 * @adapter: address of board private structure
2092 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002093 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002094 * For ASF and Pass Through versions of f/w this means that the
2095 * driver is no longer loaded. For AMT version (only with 82573) i
2096 * of the f/w this means that the network i/f is closed.
2097 *
2098 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002099void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002100{
2101 struct e1000_hw *hw = &adapter->hw;
2102 u32 ctrl_ext;
2103 u32 swsm;
2104
2105 /* Let firmware taken over control of h/w */
2106 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2107 swsm = er32(SWSM);
2108 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2109 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2110 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002111 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002112 }
2113}
2114
Auke Kokbc7f75f2007-09-17 12:30:59 -07002115/**
2116 * @e1000_alloc_ring - allocate memory for a ring structure
2117 **/
2118static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2119 struct e1000_ring *ring)
2120{
2121 struct pci_dev *pdev = adapter->pdev;
2122
2123 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2124 GFP_KERNEL);
2125 if (!ring->desc)
2126 return -ENOMEM;
2127
2128 return 0;
2129}
2130
2131/**
2132 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2133 * @adapter: board private structure
2134 *
2135 * Return 0 on success, negative on failure
2136 **/
2137int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2138{
2139 struct e1000_ring *tx_ring = adapter->tx_ring;
2140 int err = -ENOMEM, size;
2141
2142 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002143 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002144 if (!tx_ring->buffer_info)
2145 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002146
2147 /* round up to nearest 4K */
2148 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2149 tx_ring->size = ALIGN(tx_ring->size, 4096);
2150
2151 err = e1000_alloc_ring_dma(adapter, tx_ring);
2152 if (err)
2153 goto err;
2154
2155 tx_ring->next_to_use = 0;
2156 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002157
2158 return 0;
2159err:
2160 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002161 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002162 return err;
2163}
2164
2165/**
2166 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2167 * @adapter: board private structure
2168 *
2169 * Returns 0 on success, negative on failure
2170 **/
2171int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2172{
2173 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002174 struct e1000_buffer *buffer_info;
2175 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002176
2177 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002178 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002179 if (!rx_ring->buffer_info)
2180 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002181
Auke Kok47f44e42007-10-25 13:57:44 -07002182 for (i = 0; i < rx_ring->count; i++) {
2183 buffer_info = &rx_ring->buffer_info[i];
2184 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2185 sizeof(struct e1000_ps_page),
2186 GFP_KERNEL);
2187 if (!buffer_info->ps_pages)
2188 goto err_pages;
2189 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190
2191 desc_len = sizeof(union e1000_rx_desc_packet_split);
2192
2193 /* Round up to nearest 4K */
2194 rx_ring->size = rx_ring->count * desc_len;
2195 rx_ring->size = ALIGN(rx_ring->size, 4096);
2196
2197 err = e1000_alloc_ring_dma(adapter, rx_ring);
2198 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002199 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002200
2201 rx_ring->next_to_clean = 0;
2202 rx_ring->next_to_use = 0;
2203 rx_ring->rx_skb_top = NULL;
2204
2205 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002206
2207err_pages:
2208 for (i = 0; i < rx_ring->count; i++) {
2209 buffer_info = &rx_ring->buffer_info[i];
2210 kfree(buffer_info->ps_pages);
2211 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002212err:
2213 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002214 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002215 return err;
2216}
2217
2218/**
2219 * e1000_clean_tx_ring - Free Tx Buffers
2220 * @adapter: board private structure
2221 **/
2222static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2223{
2224 struct e1000_ring *tx_ring = adapter->tx_ring;
2225 struct e1000_buffer *buffer_info;
2226 unsigned long size;
2227 unsigned int i;
2228
2229 for (i = 0; i < tx_ring->count; i++) {
2230 buffer_info = &tx_ring->buffer_info[i];
2231 e1000_put_txbuf(adapter, buffer_info);
2232 }
2233
2234 size = sizeof(struct e1000_buffer) * tx_ring->count;
2235 memset(tx_ring->buffer_info, 0, size);
2236
2237 memset(tx_ring->desc, 0, tx_ring->size);
2238
2239 tx_ring->next_to_use = 0;
2240 tx_ring->next_to_clean = 0;
2241
2242 writel(0, adapter->hw.hw_addr + tx_ring->head);
2243 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2244}
2245
2246/**
2247 * e1000e_free_tx_resources - Free Tx Resources per Queue
2248 * @adapter: board private structure
2249 *
2250 * Free all transmit software resources
2251 **/
2252void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2253{
2254 struct pci_dev *pdev = adapter->pdev;
2255 struct e1000_ring *tx_ring = adapter->tx_ring;
2256
2257 e1000_clean_tx_ring(adapter);
2258
2259 vfree(tx_ring->buffer_info);
2260 tx_ring->buffer_info = NULL;
2261
2262 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2263 tx_ring->dma);
2264 tx_ring->desc = NULL;
2265}
2266
2267/**
2268 * e1000e_free_rx_resources - Free Rx Resources
2269 * @adapter: board private structure
2270 *
2271 * Free all receive software resources
2272 **/
2273
2274void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2275{
2276 struct pci_dev *pdev = adapter->pdev;
2277 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002278 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002279
2280 e1000_clean_rx_ring(adapter);
2281
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002282 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002283 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002284
Auke Kokbc7f75f2007-09-17 12:30:59 -07002285 vfree(rx_ring->buffer_info);
2286 rx_ring->buffer_info = NULL;
2287
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2289 rx_ring->dma);
2290 rx_ring->desc = NULL;
2291}
2292
2293/**
2294 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002295 * @adapter: pointer to adapter
2296 * @itr_setting: current adapter->itr
2297 * @packets: the number of packets during this measurement interval
2298 * @bytes: the number of bytes during this measurement interval
2299 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002300 * Stores a new ITR value based on packets and byte
2301 * counts during the last interrupt. The advantage of per interrupt
2302 * computation is faster updates and more accurate ITR for the current
2303 * traffic pattern. Constants in this function were computed
2304 * based on theoretical maximum wire speed and thresholds were set based
2305 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002306 * while increasing bulk throughput. This functionality is controlled
2307 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002308 **/
2309static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2310 u16 itr_setting, int packets,
2311 int bytes)
2312{
2313 unsigned int retval = itr_setting;
2314
2315 if (packets == 0)
2316 goto update_itr_done;
2317
2318 switch (itr_setting) {
2319 case lowest_latency:
2320 /* handle TSO and jumbo frames */
2321 if (bytes/packets > 8000)
2322 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002323 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325 break;
2326 case low_latency: /* 50 usec aka 20000 ints/s */
2327 if (bytes > 10000) {
2328 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002329 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002331 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002332 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002333 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002335 } else if (bytes/packets > 2000) {
2336 retval = bulk_latency;
2337 } else if (packets <= 2 && bytes < 512) {
2338 retval = lowest_latency;
2339 }
2340 break;
2341 case bulk_latency: /* 250 usec aka 4000 ints/s */
2342 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002343 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002345 } else if (bytes < 6000) {
2346 retval = low_latency;
2347 }
2348 break;
2349 }
2350
2351update_itr_done:
2352 return retval;
2353}
2354
2355static void e1000_set_itr(struct e1000_adapter *adapter)
2356{
2357 struct e1000_hw *hw = &adapter->hw;
2358 u16 current_itr;
2359 u32 new_itr = adapter->itr;
2360
2361 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2362 if (adapter->link_speed != SPEED_1000) {
2363 current_itr = 0;
2364 new_itr = 4000;
2365 goto set_itr_now;
2366 }
2367
Bruce Allan828bac82010-09-29 21:39:37 +00002368 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2369 new_itr = 0;
2370 goto set_itr_now;
2371 }
2372
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373 adapter->tx_itr = e1000_update_itr(adapter,
2374 adapter->tx_itr,
2375 adapter->total_tx_packets,
2376 adapter->total_tx_bytes);
2377 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2378 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2379 adapter->tx_itr = low_latency;
2380
2381 adapter->rx_itr = e1000_update_itr(adapter,
2382 adapter->rx_itr,
2383 adapter->total_rx_packets,
2384 adapter->total_rx_bytes);
2385 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2386 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2387 adapter->rx_itr = low_latency;
2388
2389 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2390
2391 switch (current_itr) {
2392 /* counts and packets in update_itr are dependent on these numbers */
2393 case lowest_latency:
2394 new_itr = 70000;
2395 break;
2396 case low_latency:
2397 new_itr = 20000; /* aka hwitr = ~200 */
2398 break;
2399 case bulk_latency:
2400 new_itr = 4000;
2401 break;
2402 default:
2403 break;
2404 }
2405
2406set_itr_now:
2407 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002408 /*
2409 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002411 * increasing
2412 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002413 new_itr = new_itr > adapter->itr ?
2414 min(adapter->itr + (new_itr >> 2), new_itr) :
2415 new_itr;
2416 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002417 adapter->rx_ring->itr_val = new_itr;
2418 if (adapter->msix_entries)
2419 adapter->rx_ring->set_itr = 1;
2420 else
Bruce Allan828bac82010-09-29 21:39:37 +00002421 if (new_itr)
2422 ew32(ITR, 1000000000 / (new_itr * 256));
2423 else
2424 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002425 }
2426}
2427
2428/**
Bruce Allan4662e822008-08-26 18:37:06 -07002429 * e1000_alloc_queues - Allocate memory for all rings
2430 * @adapter: board private structure to initialize
2431 **/
2432static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2433{
2434 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2435 if (!adapter->tx_ring)
2436 goto err;
2437
2438 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2439 if (!adapter->rx_ring)
2440 goto err;
2441
2442 return 0;
2443err:
2444 e_err("Unable to allocate memory for queues\n");
2445 kfree(adapter->rx_ring);
2446 kfree(adapter->tx_ring);
2447 return -ENOMEM;
2448}
2449
2450/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002451 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002452 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002453 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 **/
2455static int e1000_clean(struct napi_struct *napi, int budget)
2456{
2457 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002458 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002459 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002460 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002461
Wang Chen4cf16532008-11-12 23:38:14 -08002462 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002463
Bruce Allan4662e822008-08-26 18:37:06 -07002464 if (adapter->msix_entries &&
2465 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2466 goto clean_rx;
2467
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002468 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002469
Bruce Allan4662e822008-08-26 18:37:06 -07002470clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002471 adapter->clean_rx(adapter, &work_done, budget);
2472
Alexander Duyck12d04a32009-03-25 22:05:03 +00002473 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002474 work_done = budget;
2475
David S. Miller53e52c72008-01-07 21:06:12 -08002476 /* If budget not fully consumed, exit the polling mode */
2477 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002478 if (adapter->itr_setting & 3)
2479 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002480 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002481 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2482 if (adapter->msix_entries)
2483 ew32(IMS, adapter->rx_ring->ims_val);
2484 else
2485 e1000_irq_enable(adapter);
2486 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002487 }
2488
2489 return work_done;
2490}
2491
2492static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2493{
2494 struct e1000_adapter *adapter = netdev_priv(netdev);
2495 struct e1000_hw *hw = &adapter->hw;
2496 u32 vfta, index;
2497
2498 /* don't update vlan cookie if already programmed */
2499 if ((adapter->hw.mng_cookie.status &
2500 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2501 (vid == adapter->mng_vlan_id))
2502 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002503
Auke Kokbc7f75f2007-09-17 12:30:59 -07002504 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002505 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2506 index = (vid >> 5) & 0x7F;
2507 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2508 vfta |= (1 << (vid & 0x1F));
2509 hw->mac.ops.write_vfta(hw, index, vfta);
2510 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002511
2512 set_bit(vid, adapter->active_vlans);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002513}
2514
2515static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2516{
2517 struct e1000_adapter *adapter = netdev_priv(netdev);
2518 struct e1000_hw *hw = &adapter->hw;
2519 u32 vfta, index;
2520
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 if ((adapter->hw.mng_cookie.status &
2522 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2523 (vid == adapter->mng_vlan_id)) {
2524 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002525 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526 return;
2527 }
2528
2529 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002530 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2531 index = (vid >> 5) & 0x7F;
2532 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2533 vfta &= ~(1 << (vid & 0x1F));
2534 hw->mac.ops.write_vfta(hw, index, vfta);
2535 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002536
2537 clear_bit(vid, adapter->active_vlans);
2538}
2539
2540/**
2541 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2542 * @adapter: board private structure to initialize
2543 **/
2544static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2545{
2546 struct net_device *netdev = adapter->netdev;
2547 struct e1000_hw *hw = &adapter->hw;
2548 u32 rctl;
2549
2550 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2551 /* disable VLAN receive filtering */
2552 rctl = er32(RCTL);
2553 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2554 ew32(RCTL, rctl);
2555
2556 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2557 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2558 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2559 }
2560 }
2561}
2562
2563/**
2564 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2565 * @adapter: board private structure to initialize
2566 **/
2567static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2568{
2569 struct e1000_hw *hw = &adapter->hw;
2570 u32 rctl;
2571
2572 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2573 /* enable VLAN receive filtering */
2574 rctl = er32(RCTL);
2575 rctl |= E1000_RCTL_VFE;
2576 rctl &= ~E1000_RCTL_CFIEN;
2577 ew32(RCTL, rctl);
2578 }
2579}
2580
2581/**
2582 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2583 * @adapter: board private structure to initialize
2584 **/
2585static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2586{
2587 struct e1000_hw *hw = &adapter->hw;
2588 u32 ctrl;
2589
2590 /* disable VLAN tag insert/strip */
2591 ctrl = er32(CTRL);
2592 ctrl &= ~E1000_CTRL_VME;
2593 ew32(CTRL, ctrl);
2594}
2595
2596/**
2597 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2598 * @adapter: board private structure to initialize
2599 **/
2600static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2601{
2602 struct e1000_hw *hw = &adapter->hw;
2603 u32 ctrl;
2604
2605 /* enable VLAN tag insert/strip */
2606 ctrl = er32(CTRL);
2607 ctrl |= E1000_CTRL_VME;
2608 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002609}
2610
2611static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2612{
2613 struct net_device *netdev = adapter->netdev;
2614 u16 vid = adapter->hw.mng_cookie.vlan_id;
2615 u16 old_vid = adapter->mng_vlan_id;
2616
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002617 if (adapter->hw.mng_cookie.status &
2618 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2619 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002620 adapter->mng_vlan_id = vid;
2621 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002622
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002623 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2624 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002625}
2626
2627static void e1000_restore_vlan(struct e1000_adapter *adapter)
2628{
2629 u16 vid;
2630
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002631 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002632
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002633 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002634 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002635}
2636
Bruce Allancd791612010-05-10 14:59:51 +00002637static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002638{
2639 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002640 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002641
2642 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2643 return;
2644
2645 manc = er32(MANC);
2646
Bruce Allanad680762008-03-28 09:15:03 -07002647 /*
2648 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002649 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002650 * the packets will be handled on SMBUS
2651 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002652 manc |= E1000_MANC_EN_MNG2HOST;
2653 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002654
2655 switch (hw->mac.type) {
2656 default:
2657 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2658 break;
2659 case e1000_82574:
2660 case e1000_82583:
2661 /*
2662 * Check if IPMI pass-through decision filter already exists;
2663 * if so, enable it.
2664 */
2665 for (i = 0, j = 0; i < 8; i++) {
2666 mdef = er32(MDEF(i));
2667
2668 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002669 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002670 continue;
2671
2672 /* Enable this decision filter in MANC2H */
2673 if (mdef)
2674 manc2h |= (1 << i);
2675
2676 j |= mdef;
2677 }
2678
2679 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2680 break;
2681
2682 /* Create new decision filter in an empty filter */
2683 for (i = 0, j = 0; i < 8; i++)
2684 if (er32(MDEF(i)) == 0) {
2685 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2686 E1000_MDEF_PORT_664));
2687 manc2h |= (1 << 1);
2688 j++;
2689 break;
2690 }
2691
2692 if (!j)
2693 e_warn("Unable to create IPMI pass-through filter\n");
2694 break;
2695 }
2696
Auke Kokbc7f75f2007-09-17 12:30:59 -07002697 ew32(MANC2H, manc2h);
2698 ew32(MANC, manc);
2699}
2700
2701/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002702 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002703 * @adapter: board private structure
2704 *
2705 * Configure the Tx unit of the MAC after a reset.
2706 **/
2707static void e1000_configure_tx(struct e1000_adapter *adapter)
2708{
2709 struct e1000_hw *hw = &adapter->hw;
2710 struct e1000_ring *tx_ring = adapter->tx_ring;
2711 u64 tdba;
2712 u32 tdlen, tctl, tipg, tarc;
2713 u32 ipgr1, ipgr2;
2714
2715 /* Setup the HW Tx Head and Tail descriptor pointers */
2716 tdba = tx_ring->dma;
2717 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002718 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002719 ew32(TDBAH, (tdba >> 32));
2720 ew32(TDLEN, tdlen);
2721 ew32(TDH, 0);
2722 ew32(TDT, 0);
2723 tx_ring->head = E1000_TDH;
2724 tx_ring->tail = E1000_TDT;
2725
2726 /* Set the default values for the Tx Inter Packet Gap timer */
2727 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2728 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2729 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2730
2731 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2732 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2733
2734 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2735 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2736 ew32(TIPG, tipg);
2737
2738 /* Set the Tx Interrupt Delay register */
2739 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002740 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002741 ew32(TADV, adapter->tx_abs_int_delay);
2742
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002743 if (adapter->flags2 & FLAG2_DMA_BURST) {
2744 u32 txdctl = er32(TXDCTL(0));
2745 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2746 E1000_TXDCTL_WTHRESH);
2747 /*
2748 * set up some performance related parameters to encourage the
2749 * hardware to use the bus more efficiently in bursts, depends
2750 * on the tx_int_delay to be enabled,
2751 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2752 * hthresh = 1 ==> prefetch when one or more available
2753 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2754 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002755 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002756 */
2757 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2758 ew32(TXDCTL(0), txdctl);
2759 /* erratum work around: set txdctl the same for both queues */
2760 ew32(TXDCTL(1), txdctl);
2761 }
2762
Auke Kokbc7f75f2007-09-17 12:30:59 -07002763 /* Program the Transmit Control Register */
2764 tctl = er32(TCTL);
2765 tctl &= ~E1000_TCTL_CT;
2766 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2767 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2768
2769 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002770 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002771 /*
2772 * set the speed mode bit, we'll clear it if we're not at
2773 * gigabit link later
2774 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002775#define SPEED_MODE_BIT (1 << 21)
2776 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002777 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002778 }
2779
2780 /* errata: program both queues to unweighted RR */
2781 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002782 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002783 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002784 ew32(TARC(0), tarc);
2785 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002786 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002787 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002788 }
2789
Auke Kokbc7f75f2007-09-17 12:30:59 -07002790 /* Setup Transmit Descriptor Settings for eop descriptor */
2791 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2792
2793 /* only set IDE if we are delaying interrupts using the timers */
2794 if (adapter->tx_int_delay)
2795 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2796
2797 /* enable Report Status bit */
2798 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2799
2800 ew32(TCTL, tctl);
2801
Simon Hormanedfea6e62009-06-08 14:28:36 +00002802 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002803}
2804
2805/**
2806 * e1000_setup_rctl - configure the receive control registers
2807 * @adapter: Board private structure
2808 **/
2809#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2810 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2811static void e1000_setup_rctl(struct e1000_adapter *adapter)
2812{
2813 struct e1000_hw *hw = &adapter->hw;
2814 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815 u32 pages = 0;
2816
Bruce Allana1ce6472010-09-22 17:16:40 +00002817 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2818 if (hw->mac.type == e1000_pch2lan) {
2819 s32 ret_val;
2820
2821 if (adapter->netdev->mtu > ETH_DATA_LEN)
2822 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2823 else
2824 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002825
2826 if (ret_val)
2827 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002828 }
2829
Auke Kokbc7f75f2007-09-17 12:30:59 -07002830 /* Program MC offset vector base */
2831 rctl = er32(RCTL);
2832 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2833 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2834 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2835 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2836
2837 /* Do not Store bad packets */
2838 rctl &= ~E1000_RCTL_SBP;
2839
2840 /* Enable Long Packet receive */
2841 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2842 rctl &= ~E1000_RCTL_LPE;
2843 else
2844 rctl |= E1000_RCTL_LPE;
2845
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002846 /* Some systems expect that the CRC is included in SMBUS traffic. The
2847 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2848 * host memory when this is enabled
2849 */
2850 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2851 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002852
Bruce Allana4f58f52009-06-02 11:29:18 +00002853 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2854 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2855 u16 phy_data;
2856
2857 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2858 phy_data &= 0xfff8;
2859 phy_data |= (1 << 2);
2860 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2861
2862 e1e_rphy(hw, 22, &phy_data);
2863 phy_data &= 0x0fff;
2864 phy_data |= (1 << 14);
2865 e1e_wphy(hw, 0x10, 0x2823);
2866 e1e_wphy(hw, 0x11, 0x0003);
2867 e1e_wphy(hw, 22, phy_data);
2868 }
2869
Auke Kokbc7f75f2007-09-17 12:30:59 -07002870 /* Setup buffer sizes */
2871 rctl &= ~E1000_RCTL_SZ_4096;
2872 rctl |= E1000_RCTL_BSEX;
2873 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002874 case 2048:
2875 default:
2876 rctl |= E1000_RCTL_SZ_2048;
2877 rctl &= ~E1000_RCTL_BSEX;
2878 break;
2879 case 4096:
2880 rctl |= E1000_RCTL_SZ_4096;
2881 break;
2882 case 8192:
2883 rctl |= E1000_RCTL_SZ_8192;
2884 break;
2885 case 16384:
2886 rctl |= E1000_RCTL_SZ_16384;
2887 break;
2888 }
2889
2890 /*
2891 * 82571 and greater support packet-split where the protocol
2892 * header is placed in skb->data and the packet data is
2893 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2894 * In the case of a non-split, skb->data is linearly filled,
2895 * followed by the page buffers. Therefore, skb->data is
2896 * sized to hold the largest protocol header.
2897 *
2898 * allocations using alloc_page take too long for regular MTU
2899 * so only enable packet split for jumbo frames
2900 *
2901 * Using pages when the page size is greater than 16k wastes
2902 * a lot of memory, since we allocate 3 pages at all times
2903 * per packet.
2904 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fe2010-06-17 18:59:27 +00002906 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002907 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002908 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002909 else
2910 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002911
2912 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002913 u32 psrctl = 0;
2914
Auke Kokbc7f75f2007-09-17 12:30:59 -07002915 /* Configure extra packet-split registers */
2916 rfctl = er32(RFCTL);
2917 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002918 /*
2919 * disable packet split support for IPv6 extension headers,
2920 * because some malformed IPv6 headers can hang the Rx
2921 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002922 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2923 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2924
2925 ew32(RFCTL, rfctl);
2926
Auke Kok140a7482007-10-25 13:57:58 -07002927 /* Enable Packet split descriptors */
2928 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002929
2930 psrctl |= adapter->rx_ps_bsize0 >>
2931 E1000_PSRCTL_BSIZE0_SHIFT;
2932
2933 switch (adapter->rx_ps_pages) {
2934 case 3:
2935 psrctl |= PAGE_SIZE <<
2936 E1000_PSRCTL_BSIZE3_SHIFT;
2937 case 2:
2938 psrctl |= PAGE_SIZE <<
2939 E1000_PSRCTL_BSIZE2_SHIFT;
2940 case 1:
2941 psrctl |= PAGE_SIZE >>
2942 E1000_PSRCTL_BSIZE1_SHIFT;
2943 break;
2944 }
2945
2946 ew32(PSRCTL, psrctl);
2947 }
2948
2949 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002950 /* just started the receive unit, no need to restart */
2951 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002952}
2953
2954/**
2955 * e1000_configure_rx - Configure Receive Unit after Reset
2956 * @adapter: board private structure
2957 *
2958 * Configure the Rx unit of the MAC after a reset.
2959 **/
2960static void e1000_configure_rx(struct e1000_adapter *adapter)
2961{
2962 struct e1000_hw *hw = &adapter->hw;
2963 struct e1000_ring *rx_ring = adapter->rx_ring;
2964 u64 rdba;
2965 u32 rdlen, rctl, rxcsum, ctrl_ext;
2966
2967 if (adapter->rx_ps_pages) {
2968 /* this is a 32 byte descriptor */
2969 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002970 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002971 adapter->clean_rx = e1000_clean_rx_irq_ps;
2972 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002973 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2974 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2975 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2976 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002977 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002978 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002979 adapter->clean_rx = e1000_clean_rx_irq;
2980 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2981 }
2982
2983 /* disable receives while setting up the descriptors */
2984 rctl = er32(RCTL);
Bruce Allan7f99ae632011-07-22 06:21:35 +00002985 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
2986 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002987 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00002988 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002989
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002990 if (adapter->flags2 & FLAG2_DMA_BURST) {
2991 /*
2992 * set the writeback threshold (only takes effect if the RDTR
2993 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00002994 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002995 * granularity = 01
2996 * wthresh = 04,
2997 * hthresh = 04,
2998 * pthresh = 0x20
2999 */
3000 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3001 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3002
3003 /*
3004 * override the delay timers for enabling bursting, only if
3005 * the value was not set by the user via module options
3006 */
3007 if (adapter->rx_int_delay == DEFAULT_RDTR)
3008 adapter->rx_int_delay = BURST_RDTR;
3009 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3010 adapter->rx_abs_int_delay = BURST_RADV;
3011 }
3012
Auke Kokbc7f75f2007-09-17 12:30:59 -07003013 /* set the Receive Delay Timer Register */
3014 ew32(RDTR, adapter->rx_int_delay);
3015
3016 /* irq moderation */
3017 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003018 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003019 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003020
3021 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003022 /* Auto-Mask interrupts upon ICR access */
3023 ctrl_ext |= E1000_CTRL_EXT_IAME;
3024 ew32(IAM, 0xffffffff);
3025 ew32(CTRL_EXT, ctrl_ext);
3026 e1e_flush();
3027
Bruce Allanad680762008-03-28 09:15:03 -07003028 /*
3029 * Setup the HW Rx Head and Tail Descriptor Pointers and
3030 * the Base and Length of the Rx Descriptor Ring
3031 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003032 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07003033 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003034 ew32(RDBAH, (rdba >> 32));
3035 ew32(RDLEN, rdlen);
3036 ew32(RDH, 0);
3037 ew32(RDT, 0);
3038 rx_ring->head = E1000_RDH;
3039 rx_ring->tail = E1000_RDT;
3040
3041 /* Enable Receive Checksum Offload for TCP and UDP */
3042 rxcsum = er32(RXCSUM);
3043 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
3044 rxcsum |= E1000_RXCSUM_TUOFL;
3045
Bruce Allanad680762008-03-28 09:15:03 -07003046 /*
3047 * IPv4 payload checksum for UDP fragments must be
3048 * used in conjunction with packet-split.
3049 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003050 if (adapter->rx_ps_pages)
3051 rxcsum |= E1000_RXCSUM_IPPCSE;
3052 } else {
3053 rxcsum &= ~E1000_RXCSUM_TUOFL;
3054 /* no need to clear IPPCSE as it defaults to 0 */
3055 }
3056 ew32(RXCSUM, rxcsum);
3057
Bruce Allanad680762008-03-28 09:15:03 -07003058 /*
3059 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07003060 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07003061 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
3062 */
Bruce Allan828bac82010-09-29 21:39:37 +00003063 if ((adapter->flags & FLAG_HAS_ERT) ||
3064 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003065 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3066 u32 rxdctl = er32(RXDCTL(0));
3067 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00003068 if (adapter->flags & FLAG_HAS_ERT)
3069 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00003070 /*
3071 * With jumbo frames and early-receive enabled,
3072 * excessive C-state transition latencies result in
3073 * dropped transactions.
3074 */
Bruce Allanaf667a22010-12-31 06:10:01 +00003075 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003076 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003077 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3078 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003079 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003080 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081
3082 /* Enable Receives */
3083 ew32(RCTL, rctl);
3084}
3085
3086/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003087 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07003088 * @hw: pointer to the HW structure
3089 * @mc_addr_list: array of multicast addresses to program
3090 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07003091 *
Bruce Allanab8932f2010-01-13 02:05:38 +00003092 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003093 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003094 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003095static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003096 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003097{
Bruce Allanab8932f2010-01-13 02:05:38 +00003098 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003099}
3100
3101/**
3102 * e1000_set_multi - Multicast and Promiscuous mode set
3103 * @netdev: network interface device structure
3104 *
3105 * The set_multi entry point is called whenever the multicast address
3106 * list or the network interface flags are updated. This routine is
3107 * responsible for configuring the hardware for proper multicast,
3108 * promiscuous mode, and all-multi behavior.
3109 **/
3110static void e1000_set_multi(struct net_device *netdev)
3111{
3112 struct e1000_adapter *adapter = netdev_priv(netdev);
3113 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad2010-04-01 21:22:57 +00003114 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003115 u8 *mta_list;
3116 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003117
3118 /* Check for Promiscuous and All Multicast modes */
3119
3120 rctl = er32(RCTL);
3121
3122 if (netdev->flags & IFF_PROMISC) {
3123 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003124 rctl &= ~E1000_RCTL_VFE;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003125 /* Do not hardware filter VLANs in promisc mode */
3126 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003127 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003128 if (netdev->flags & IFF_ALLMULTI) {
3129 rctl |= E1000_RCTL_MPE;
3130 rctl &= ~E1000_RCTL_UPE;
3131 } else {
3132 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3133 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003134 e1000e_vlan_filter_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003135 }
3136
3137 ew32(RCTL, rctl);
3138
Jiri Pirko7aeef972010-02-05 02:52:39 +00003139 if (!netdev_mc_empty(netdev)) {
Bruce Allan90da0662011-01-06 07:02:53 +00003140 int i = 0;
3141
Jiri Pirko7aeef972010-02-05 02:52:39 +00003142 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003143 if (!mta_list)
3144 return;
3145
3146 /* prepare a packed array of only addresses. */
Jiri Pirko22bedad2010-04-01 21:22:57 +00003147 netdev_for_each_mc_addr(ha, netdev)
3148 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003149
Bruce Allanab8932f2010-01-13 02:05:38 +00003150 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003151 kfree(mta_list);
3152 } else {
3153 /*
3154 * if we're called from probe, we might not have
3155 * anything to do here, so clear out the list
3156 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003157 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003158 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003159
3160 if (netdev->features & NETIF_F_HW_VLAN_RX)
3161 e1000e_vlan_strip_enable(adapter);
3162 else
3163 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003164}
3165
3166/**
Bruce Allanad680762008-03-28 09:15:03 -07003167 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003168 * @adapter: private board structure
3169 **/
3170static void e1000_configure(struct e1000_adapter *adapter)
3171{
3172 e1000_set_multi(adapter->netdev);
3173
3174 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003175 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003176
3177 e1000_configure_tx(adapter);
3178 e1000_setup_rctl(adapter);
3179 e1000_configure_rx(adapter);
Jeff Kirsherc2fed992011-07-12 16:10:12 +00003180 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring),
3181 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003182}
3183
3184/**
3185 * e1000e_power_up_phy - restore link in case the phy was powered down
3186 * @adapter: address of board private structure
3187 *
3188 * The phy may be powered down to save power and turn off link when the
3189 * driver is unloaded and wake on lan is not enabled (among others)
3190 * *** this routine MUST be followed by a call to e1000e_reset ***
3191 **/
3192void e1000e_power_up_phy(struct e1000_adapter *adapter)
3193{
Bruce Allan17f208d2009-12-01 15:47:22 +00003194 if (adapter->hw.phy.ops.power_up)
3195 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003196
3197 adapter->hw.mac.ops.setup_link(&adapter->hw);
3198}
3199
3200/**
3201 * e1000_power_down_phy - Power down the PHY
3202 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003203 * Power down the PHY so no link is implied when interface is down.
3204 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003205 */
3206static void e1000_power_down_phy(struct e1000_adapter *adapter)
3207{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003208 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003209 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003210 return;
3211
Bruce Allan17f208d2009-12-01 15:47:22 +00003212 if (adapter->hw.phy.ops.power_down)
3213 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003214}
3215
3216/**
3217 * e1000e_reset - bring the hardware into a known good state
3218 *
3219 * This function boots the hardware and enables some settings that
3220 * require a configuration cycle of the hardware - those cannot be
3221 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003222 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003223 */
3224void e1000e_reset(struct e1000_adapter *adapter)
3225{
3226 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003227 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003228 struct e1000_hw *hw = &adapter->hw;
3229 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003230 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003231 u16 hwm;
3232
Bruce Allanad680762008-03-28 09:15:03 -07003233 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003234 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003235
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003236 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003237 /*
3238 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003239 * large enough to accommodate two full transmit packets,
3240 * rounded up to the next 1KB and expressed in KB. Likewise,
3241 * the Rx FIFO should be large enough to accommodate at least
3242 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003243 * expressed in KB.
3244 */
Auke Kokdf762462007-10-25 13:57:53 -07003245 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003246 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003247 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003248 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003249 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003250 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003251 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003252 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003253 */
3254 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003255 sizeof(struct e1000_tx_desc) -
3256 ETH_FCS_LEN) * 2;
3257 min_tx_space = ALIGN(min_tx_space, 1024);
3258 min_tx_space >>= 10;
3259 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003260 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003261 min_rx_space = ALIGN(min_rx_space, 1024);
3262 min_rx_space >>= 10;
3263
Bruce Allanad680762008-03-28 09:15:03 -07003264 /*
3265 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003266 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003267 * allocation, take space away from current Rx allocation
3268 */
Auke Kokdf762462007-10-25 13:57:53 -07003269 if ((tx_space < min_tx_space) &&
3270 ((min_tx_space - tx_space) < pba)) {
3271 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003272
Bruce Allanad680762008-03-28 09:15:03 -07003273 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003274 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003275 * adjustment or use Early Receive if available
3276 */
Auke Kokdf762462007-10-25 13:57:53 -07003277 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003278 (!(adapter->flags & FLAG_HAS_ERT)))
3279 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003280 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003281 }
Auke Kokdf762462007-10-25 13:57:53 -07003282
3283 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003284 }
3285
Bruce Allanad680762008-03-28 09:15:03 -07003286 /*
3287 * flow control settings
3288 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003289 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003290 * (or the size used for early receive) above it in the Rx FIFO.
3291 * Set it to the lower of:
3292 * - 90% of the Rx FIFO size, and
3293 * - the full Rx FIFO size minus the early receive size (for parts
3294 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003295 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003296 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003297 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3298 fc->pause_time = 0xFFFF;
3299 else
3300 fc->pause_time = E1000_FC_PAUSE_TIME;
3301 fc->send_xon = 1;
3302 fc->current_mode = fc->requested_mode;
3303
3304 switch (hw->mac.type) {
3305 default:
3306 if ((adapter->flags & FLAG_HAS_ERT) &&
3307 (adapter->netdev->mtu > ETH_DATA_LEN))
3308 hwm = min(((pba << 10) * 9 / 10),
3309 ((pba << 10) - (E1000_ERT_2048 << 3)));
3310 else
3311 hwm = min(((pba << 10) * 9 / 10),
3312 ((pba << 10) - adapter->max_frame_size));
3313
3314 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3315 fc->low_water = fc->high_water - 8;
3316 break;
3317 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003318 /*
3319 * Workaround PCH LOM adapter hangs with certain network
3320 * loads. If hangs persist, try disabling Tx flow control.
3321 */
3322 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3323 fc->high_water = 0x3500;
3324 fc->low_water = 0x1500;
3325 } else {
3326 fc->high_water = 0x5000;
3327 fc->low_water = 0x3000;
3328 }
Bruce Allana3055952010-05-10 15:02:12 +00003329 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003330 break;
3331 case e1000_pch2lan:
3332 fc->high_water = 0x05C20;
3333 fc->low_water = 0x05048;
3334 fc->pause_time = 0x0650;
3335 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003336 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3337 pba = 14;
3338 ew32(PBA, pba);
3339 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003340 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003341 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003342
Bruce Allan828bac82010-09-29 21:39:37 +00003343 /*
3344 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3345 * fit in receive buffer and early-receive not supported.
3346 */
3347 if (adapter->itr_setting & 0x3) {
3348 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3349 !(adapter->flags & FLAG_HAS_ERT)) {
3350 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3351 dev_info(&adapter->pdev->dev,
3352 "Interrupt Throttle Rate turned off\n");
3353 adapter->flags2 |= FLAG2_DISABLE_AIM;
3354 ew32(ITR, 0);
3355 }
3356 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3357 dev_info(&adapter->pdev->dev,
3358 "Interrupt Throttle Rate turned on\n");
3359 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3360 adapter->itr = 20000;
3361 ew32(ITR, 1000000000 / (adapter->itr * 256));
3362 }
3363 }
3364
Auke Kokbc7f75f2007-09-17 12:30:59 -07003365 /* Allow time for pending master requests to run */
3366 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003367
3368 /*
3369 * For parts with AMT enabled, let the firmware know
3370 * that the network interface is in control
3371 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003372 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003373 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003374
Auke Kokbc7f75f2007-09-17 12:30:59 -07003375 ew32(WUC, 0);
3376
3377 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003378 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003379
3380 e1000_update_mng_vlan(adapter);
3381
3382 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3383 ew32(VET, ETH_P_8021Q);
3384
3385 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003386
3387 if (!netif_running(adapter->netdev) &&
3388 !test_bit(__E1000_TESTING, &adapter->state)) {
3389 e1000_power_down_phy(adapter);
3390 return;
3391 }
3392
Auke Kokbc7f75f2007-09-17 12:30:59 -07003393 e1000_get_phy_info(hw);
3394
Bruce Allan918d7192009-06-02 11:28:20 +00003395 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3396 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003397 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003398 /*
3399 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003400 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003401 * different we would do if it failed
3402 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003403 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3404 phy_data &= ~IGP02E1000_PM_SPD;
3405 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3406 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003407}
3408
3409int e1000e_up(struct e1000_adapter *adapter)
3410{
3411 struct e1000_hw *hw = &adapter->hw;
3412
3413 /* hardware has been reset, we need to reload some things */
3414 e1000_configure(adapter);
3415
3416 clear_bit(__E1000_DOWN, &adapter->state);
3417
3418 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003419 if (adapter->msix_entries)
3420 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003421 e1000_irq_enable(adapter);
3422
Bruce Allan400484f2011-05-13 07:20:03 +00003423 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003424
Auke Kokbc7f75f2007-09-17 12:30:59 -07003425 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003426 if (adapter->msix_entries)
3427 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3428 else
3429 ew32(ICS, E1000_ICS_LSC);
3430
Auke Kokbc7f75f2007-09-17 12:30:59 -07003431 return 0;
3432}
3433
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003434static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3435{
3436 struct e1000_hw *hw = &adapter->hw;
3437
3438 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3439 return;
3440
3441 /* flush pending descriptor writebacks to memory */
3442 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3443 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3444
3445 /* execute the writes immediately */
3446 e1e_flush();
3447}
3448
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003449static void e1000e_update_stats(struct e1000_adapter *adapter);
3450
Auke Kokbc7f75f2007-09-17 12:30:59 -07003451void e1000e_down(struct e1000_adapter *adapter)
3452{
3453 struct net_device *netdev = adapter->netdev;
3454 struct e1000_hw *hw = &adapter->hw;
3455 u32 tctl, rctl;
3456
Bruce Allanad680762008-03-28 09:15:03 -07003457 /*
3458 * signal that we're down so the interrupt handler does not
3459 * reschedule our watchdog timer
3460 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003461 set_bit(__E1000_DOWN, &adapter->state);
3462
3463 /* disable receives in the hardware */
3464 rctl = er32(RCTL);
Bruce Allan7f99ae632011-07-22 06:21:35 +00003465 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3466 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003467 /* flush and sleep below */
3468
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003469 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003470
3471 /* disable transmits in the hardware */
3472 tctl = er32(TCTL);
3473 tctl &= ~E1000_TCTL_EN;
3474 ew32(TCTL, tctl);
Bruce Allan7f99ae632011-07-22 06:21:35 +00003475
Auke Kokbc7f75f2007-09-17 12:30:59 -07003476 /* flush both disables and wait for them to finish */
3477 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003478 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003479
3480 napi_disable(&adapter->napi);
3481 e1000_irq_disable(adapter);
3482
3483 del_timer_sync(&adapter->watchdog_timer);
3484 del_timer_sync(&adapter->phy_info_timer);
3485
Auke Kokbc7f75f2007-09-17 12:30:59 -07003486 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003487
3488 spin_lock(&adapter->stats64_lock);
3489 e1000e_update_stats(adapter);
3490 spin_unlock(&adapter->stats64_lock);
3491
Bruce Allan400484f2011-05-13 07:20:03 +00003492 e1000e_flush_descriptors(adapter);
3493 e1000_clean_tx_ring(adapter);
3494 e1000_clean_rx_ring(adapter);
3495
Auke Kokbc7f75f2007-09-17 12:30:59 -07003496 adapter->link_speed = 0;
3497 adapter->link_duplex = 0;
3498
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003499 if (!pci_channel_offline(adapter->pdev))
3500 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003501
Auke Kokbc7f75f2007-09-17 12:30:59 -07003502 /*
3503 * TODO: for power management, we could drop the link and
3504 * pci_disable_device here.
3505 */
3506}
3507
3508void e1000e_reinit_locked(struct e1000_adapter *adapter)
3509{
3510 might_sleep();
3511 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003512 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003513 e1000e_down(adapter);
3514 e1000e_up(adapter);
3515 clear_bit(__E1000_RESETTING, &adapter->state);
3516}
3517
3518/**
3519 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3520 * @adapter: board private structure to initialize
3521 *
3522 * e1000_sw_init initializes the Adapter private data structure.
3523 * Fields are initialized based on PCI device information and
3524 * OS network device settings (MTU size).
3525 **/
3526static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3527{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003528 struct net_device *netdev = adapter->netdev;
3529
3530 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3531 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003532 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3533 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003534
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003535 spin_lock_init(&adapter->stats64_lock);
3536
Bruce Allan4662e822008-08-26 18:37:06 -07003537 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003538
Bruce Allan4662e822008-08-26 18:37:06 -07003539 if (e1000_alloc_queues(adapter))
3540 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003541
Auke Kokbc7f75f2007-09-17 12:30:59 -07003542 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003543 e1000_irq_disable(adapter);
3544
Auke Kokbc7f75f2007-09-17 12:30:59 -07003545 set_bit(__E1000_DOWN, &adapter->state);
3546 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003547}
3548
3549/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003550 * e1000_intr_msi_test - Interrupt Handler
3551 * @irq: interrupt number
3552 * @data: pointer to a network interface device structure
3553 **/
3554static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3555{
3556 struct net_device *netdev = data;
3557 struct e1000_adapter *adapter = netdev_priv(netdev);
3558 struct e1000_hw *hw = &adapter->hw;
3559 u32 icr = er32(ICR);
3560
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003561 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003562 if (icr & E1000_ICR_RXSEQ) {
3563 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3564 wmb();
3565 }
3566
3567 return IRQ_HANDLED;
3568}
3569
3570/**
3571 * e1000_test_msi_interrupt - Returns 0 for successful test
3572 * @adapter: board private struct
3573 *
3574 * code flow taken from tg3.c
3575 **/
3576static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3577{
3578 struct net_device *netdev = adapter->netdev;
3579 struct e1000_hw *hw = &adapter->hw;
3580 int err;
3581
3582 /* poll_enable hasn't been called yet, so don't need disable */
3583 /* clear any pending events */
3584 er32(ICR);
3585
3586 /* free the real vector and request a test handler */
3587 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003588 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003589
3590 /* Assume that the test fails, if it succeeds then the test
3591 * MSI irq handler will unset this flag */
3592 adapter->flags |= FLAG_MSI_TEST_FAILED;
3593
3594 err = pci_enable_msi(adapter->pdev);
3595 if (err)
3596 goto msi_test_failed;
3597
Joe Perchesa0607fd2009-11-18 23:29:17 -08003598 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003599 netdev->name, netdev);
3600 if (err) {
3601 pci_disable_msi(adapter->pdev);
3602 goto msi_test_failed;
3603 }
3604
3605 wmb();
3606
3607 e1000_irq_enable(adapter);
3608
3609 /* fire an unusual interrupt on the test handler */
3610 ew32(ICS, E1000_ICS_RXSEQ);
3611 e1e_flush();
3612 msleep(50);
3613
3614 e1000_irq_disable(adapter);
3615
3616 rmb();
3617
3618 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003619 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003620 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3621 } else
3622 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003623
3624 free_irq(adapter->pdev->irq, netdev);
3625 pci_disable_msi(adapter->pdev);
3626
Bruce Allanf8d59f72008-08-08 18:36:11 -07003627msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003628 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003629 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003630}
3631
3632/**
3633 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3634 * @adapter: board private struct
3635 *
3636 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3637 **/
3638static int e1000_test_msi(struct e1000_adapter *adapter)
3639{
3640 int err;
3641 u16 pci_cmd;
3642
3643 if (!(adapter->flags & FLAG_MSI_ENABLED))
3644 return 0;
3645
3646 /* disable SERR in case the MSI write causes a master abort */
3647 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003648 if (pci_cmd & PCI_COMMAND_SERR)
3649 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3650 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003651
3652 err = e1000_test_msi_interrupt(adapter);
3653
Dean Nelson36f24072010-06-29 18:12:05 +00003654 /* re-enable SERR */
3655 if (pci_cmd & PCI_COMMAND_SERR) {
3656 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3657 pci_cmd |= PCI_COMMAND_SERR;
3658 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3659 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003660
Bruce Allanf8d59f72008-08-08 18:36:11 -07003661 return err;
3662}
3663
3664/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003665 * e1000_open - Called when a network interface is made active
3666 * @netdev: network interface device structure
3667 *
3668 * Returns 0 on success, negative value on failure
3669 *
3670 * The open entry point is called when a network interface is made
3671 * active by the system (IFF_UP). At this point all resources needed
3672 * for transmit and receive operations are allocated, the interrupt
3673 * handler is registered with the OS, the watchdog timer is started,
3674 * and the stack is notified that the interface is ready.
3675 **/
3676static int e1000_open(struct net_device *netdev)
3677{
3678 struct e1000_adapter *adapter = netdev_priv(netdev);
3679 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003680 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681 int err;
3682
3683 /* disallow open during test */
3684 if (test_bit(__E1000_TESTING, &adapter->state))
3685 return -EBUSY;
3686
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003687 pm_runtime_get_sync(&pdev->dev);
3688
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003689 netif_carrier_off(netdev);
3690
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691 /* allocate transmit descriptors */
3692 err = e1000e_setup_tx_resources(adapter);
3693 if (err)
3694 goto err_setup_tx;
3695
3696 /* allocate receive descriptors */
3697 err = e1000e_setup_rx_resources(adapter);
3698 if (err)
3699 goto err_setup_rx;
3700
Bruce Allan11b08be2010-05-10 14:59:31 +00003701 /*
3702 * If AMT is enabled, let the firmware know that the network
3703 * interface is now open and reset the part to a known state.
3704 */
3705 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003706 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003707 e1000e_reset(adapter);
3708 }
3709
Auke Kokbc7f75f2007-09-17 12:30:59 -07003710 e1000e_power_up_phy(adapter);
3711
3712 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3713 if ((adapter->hw.mng_cookie.status &
3714 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3715 e1000_update_mng_vlan(adapter);
3716
Florian Micklerc128ec22010-08-02 14:27:00 +00003717 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003718 if ((adapter->flags & FLAG_HAS_ERT) ||
3719 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003720 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3721 PM_QOS_CPU_DMA_LATENCY,
3722 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003723
Bruce Allanad680762008-03-28 09:15:03 -07003724 /*
Bruce Allanad680762008-03-28 09:15:03 -07003725 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003726 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3727 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003728 * clean_rx handler before we do so.
3729 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003730 e1000_configure(adapter);
3731
3732 err = e1000_request_irq(adapter);
3733 if (err)
3734 goto err_req_irq;
3735
Bruce Allanf8d59f72008-08-08 18:36:11 -07003736 /*
3737 * Work around PCIe errata with MSI interrupts causing some chipsets to
3738 * ignore e1000e MSI messages, which means we need to test our MSI
3739 * interrupt now
3740 */
Bruce Allan4662e822008-08-26 18:37:06 -07003741 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003742 err = e1000_test_msi(adapter);
3743 if (err) {
3744 e_err("Interrupt allocation failed\n");
3745 goto err_req_irq;
3746 }
3747 }
3748
Auke Kokbc7f75f2007-09-17 12:30:59 -07003749 /* From here on the code is the same as e1000e_up() */
3750 clear_bit(__E1000_DOWN, &adapter->state);
3751
3752 napi_enable(&adapter->napi);
3753
3754 e1000_irq_enable(adapter);
3755
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003756 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003757
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003758 adapter->idle_check = true;
3759 pm_runtime_put(&pdev->dev);
3760
Auke Kokbc7f75f2007-09-17 12:30:59 -07003761 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003762 if (adapter->msix_entries)
3763 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3764 else
3765 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003766
3767 return 0;
3768
3769err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003770 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003771 e1000_power_down_phy(adapter);
3772 e1000e_free_rx_resources(adapter);
3773err_setup_rx:
3774 e1000e_free_tx_resources(adapter);
3775err_setup_tx:
3776 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003777 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003778
3779 return err;
3780}
3781
3782/**
3783 * e1000_close - Disables a network interface
3784 * @netdev: network interface device structure
3785 *
3786 * Returns 0, this is not allowed to fail
3787 *
3788 * The close entry point is called when an interface is de-activated
3789 * by the OS. The hardware is still under the drivers control, but
3790 * needs to be disabled. A global MAC reset is issued to stop the
3791 * hardware, and all transmit and receive resources are freed.
3792 **/
3793static int e1000_close(struct net_device *netdev)
3794{
3795 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003796 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003797
3798 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003799
3800 pm_runtime_get_sync(&pdev->dev);
3801
3802 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3803 e1000e_down(adapter);
3804 e1000_free_irq(adapter);
3805 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003806 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003807
3808 e1000e_free_tx_resources(adapter);
3809 e1000e_free_rx_resources(adapter);
3810
Bruce Allanad680762008-03-28 09:15:03 -07003811 /*
3812 * kill manageability vlan ID if supported, but not if a vlan with
3813 * the same ID is registered on the host OS (let 8021q kill it)
3814 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003815 if (adapter->hw.mng_cookie.status &
3816 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003817 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3818
Bruce Allanad680762008-03-28 09:15:03 -07003819 /*
3820 * If AMT is enabled, let the firmware know that the network
3821 * interface is now closed
3822 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003823 if ((adapter->flags & FLAG_HAS_AMT) &&
3824 !test_bit(__E1000_TESTING, &adapter->state))
3825 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003826
Bruce Allan828bac82010-09-29 21:39:37 +00003827 if ((adapter->flags & FLAG_HAS_ERT) ||
3828 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003829 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003830
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003831 pm_runtime_put_sync(&pdev->dev);
3832
Auke Kokbc7f75f2007-09-17 12:30:59 -07003833 return 0;
3834}
3835/**
3836 * e1000_set_mac - Change the Ethernet Address of the NIC
3837 * @netdev: network interface device structure
3838 * @p: pointer to an address structure
3839 *
3840 * Returns 0 on success, negative on failure
3841 **/
3842static int e1000_set_mac(struct net_device *netdev, void *p)
3843{
3844 struct e1000_adapter *adapter = netdev_priv(netdev);
3845 struct sockaddr *addr = p;
3846
3847 if (!is_valid_ether_addr(addr->sa_data))
3848 return -EADDRNOTAVAIL;
3849
3850 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3851 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3852
3853 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3854
3855 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3856 /* activate the work around */
3857 e1000e_set_laa_state_82571(&adapter->hw, 1);
3858
Bruce Allanad680762008-03-28 09:15:03 -07003859 /*
3860 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003861 * between the time RAR[0] gets clobbered and the time it
3862 * gets fixed (in e1000_watchdog), the actual LAA is in one
3863 * of the RARs and no incoming packets directed to this port
3864 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003865 * RAR[14]
3866 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003867 e1000e_rar_set(&adapter->hw,
3868 adapter->hw.mac.addr,
3869 adapter->hw.mac.rar_entry_count - 1);
3870 }
3871
3872 return 0;
3873}
3874
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003875/**
3876 * e1000e_update_phy_task - work thread to update phy
3877 * @work: pointer to our work struct
3878 *
3879 * this worker thread exists because we must acquire a
3880 * semaphore to read the phy, which we could msleep while
3881 * waiting for it, and we can't msleep in a timer.
3882 **/
3883static void e1000e_update_phy_task(struct work_struct *work)
3884{
3885 struct e1000_adapter *adapter = container_of(work,
3886 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003887
3888 if (test_bit(__E1000_DOWN, &adapter->state))
3889 return;
3890
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003891 e1000_get_phy_info(&adapter->hw);
3892}
3893
Bruce Allanad680762008-03-28 09:15:03 -07003894/*
3895 * Need to wait a few seconds after link up to get diagnostic information from
3896 * the phy
3897 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003898static void e1000_update_phy_info(unsigned long data)
3899{
3900 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003901
3902 if (test_bit(__E1000_DOWN, &adapter->state))
3903 return;
3904
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003905 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003906}
3907
3908/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003909 * e1000e_update_phy_stats - Update the PHY statistics counters
3910 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00003911 *
3912 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003913 **/
3914static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3915{
3916 struct e1000_hw *hw = &adapter->hw;
3917 s32 ret_val;
3918 u16 phy_data;
3919
3920 ret_val = hw->phy.ops.acquire(hw);
3921 if (ret_val)
3922 return;
3923
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003924 /*
3925 * A page set is expensive so check if already on desired page.
3926 * If not, set to the page with the PHY status registers.
3927 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003928 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003929 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3930 &phy_data);
3931 if (ret_val)
3932 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00003933 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
3934 ret_val = hw->phy.ops.set_page(hw,
3935 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003936 if (ret_val)
3937 goto release;
3938 }
3939
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003940 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003941 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
3942 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003943 if (!ret_val)
3944 adapter->stats.scc += phy_data;
3945
3946 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003947 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
3948 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003949 if (!ret_val)
3950 adapter->stats.ecol += phy_data;
3951
3952 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003953 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
3954 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003955 if (!ret_val)
3956 adapter->stats.mcc += phy_data;
3957
3958 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003959 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
3960 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003961 if (!ret_val)
3962 adapter->stats.latecol += phy_data;
3963
3964 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003965 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
3966 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003967 if (!ret_val)
3968 hw->mac.collision_delta = phy_data;
3969
3970 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003971 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
3972 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003973 if (!ret_val)
3974 adapter->stats.dc += phy_data;
3975
3976 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003977 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
3978 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003979 if (!ret_val)
3980 adapter->stats.tncrs += phy_data;
3981
3982release:
3983 hw->phy.ops.release(hw);
3984}
3985
3986/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003987 * e1000e_update_stats - Update the board statistics counters
3988 * @adapter: board private structure
3989 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003990static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003991{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003992 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003993 struct e1000_hw *hw = &adapter->hw;
3994 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003995
3996 /*
3997 * Prevent stats update while adapter is being reset, or if the pci
3998 * connection is down.
3999 */
4000 if (adapter->link_speed == 0)
4001 return;
4002 if (pci_channel_offline(pdev))
4003 return;
4004
Auke Kokbc7f75f2007-09-17 12:30:59 -07004005 adapter->stats.crcerrs += er32(CRCERRS);
4006 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004007 adapter->stats.gorc += er32(GORCL);
4008 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004009 adapter->stats.bprc += er32(BPRC);
4010 adapter->stats.mprc += er32(MPRC);
4011 adapter->stats.roc += er32(ROC);
4012
Auke Kokbc7f75f2007-09-17 12:30:59 -07004013 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004014
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004015 /* Half-duplex statistics */
4016 if (adapter->link_duplex == HALF_DUPLEX) {
4017 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4018 e1000e_update_phy_stats(adapter);
4019 } else {
4020 adapter->stats.scc += er32(SCC);
4021 adapter->stats.ecol += er32(ECOL);
4022 adapter->stats.mcc += er32(MCC);
4023 adapter->stats.latecol += er32(LATECOL);
4024 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004025
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004026 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004027
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004028 if ((hw->mac.type != e1000_82574) &&
4029 (hw->mac.type != e1000_82583))
4030 adapter->stats.tncrs += er32(TNCRS);
4031 }
4032 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004033 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004034
Auke Kokbc7f75f2007-09-17 12:30:59 -07004035 adapter->stats.xonrxc += er32(XONRXC);
4036 adapter->stats.xontxc += er32(XONTXC);
4037 adapter->stats.xoffrxc += er32(XOFFRXC);
4038 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004039 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004040 adapter->stats.gotc += er32(GOTCL);
4041 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004042 adapter->stats.rnbc += er32(RNBC);
4043 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004044
4045 adapter->stats.mptc += er32(MPTC);
4046 adapter->stats.bptc += er32(BPTC);
4047
4048 /* used for adaptive IFS */
4049
4050 hw->mac.tx_packet_delta = er32(TPT);
4051 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004052
4053 adapter->stats.algnerrc += er32(ALGNERRC);
4054 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004055 adapter->stats.cexterr += er32(CEXTERR);
4056 adapter->stats.tsctc += er32(TSCTC);
4057 adapter->stats.tsctfc += er32(TSCTFC);
4058
Auke Kokbc7f75f2007-09-17 12:30:59 -07004059 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004060 netdev->stats.multicast = adapter->stats.mprc;
4061 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004062
4063 /* Rx Errors */
4064
Bruce Allanad680762008-03-28 09:15:03 -07004065 /*
4066 * RLEC on some newer hardware can be incorrect so build
4067 * our own version based on RUC and ROC
4068 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004069 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004070 adapter->stats.crcerrs + adapter->stats.algnerrc +
4071 adapter->stats.ruc + adapter->stats.roc +
4072 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004073 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004074 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004075 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4076 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4077 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004078
4079 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004080 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004081 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004082 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4083 netdev->stats.tx_window_errors = adapter->stats.latecol;
4084 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004085
4086 /* Tx Dropped needs to be maintained elsewhere */
4087
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088 /* Management Stats */
4089 adapter->stats.mgptc += er32(MGTPTC);
4090 adapter->stats.mgprc += er32(MGTPRC);
4091 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004092}
4093
Bruce Allan7c257692008-04-23 11:09:00 -07004094/**
4095 * e1000_phy_read_status - Update the PHY register status snapshot
4096 * @adapter: board private structure
4097 **/
4098static void e1000_phy_read_status(struct e1000_adapter *adapter)
4099{
4100 struct e1000_hw *hw = &adapter->hw;
4101 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004102
4103 if ((er32(STATUS) & E1000_STATUS_LU) &&
4104 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004105 int ret_val;
4106
Bruce Allan7c257692008-04-23 11:09:00 -07004107 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4108 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4109 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4110 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4111 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4112 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4113 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4114 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4115 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004116 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004117 } else {
4118 /*
4119 * Do not read PHY registers if link is not up
4120 * Set values to typical power-on defaults
4121 */
4122 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4123 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4124 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4125 BMSR_ERCAP);
4126 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4127 ADVERTISE_ALL | ADVERTISE_CSMA);
4128 phy->lpa = 0;
4129 phy->expansion = EXPANSION_ENABLENPAGE;
4130 phy->ctrl1000 = ADVERTISE_1000FULL;
4131 phy->stat1000 = 0;
4132 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4133 }
Bruce Allan7c257692008-04-23 11:09:00 -07004134}
4135
Auke Kokbc7f75f2007-09-17 12:30:59 -07004136static void e1000_print_link_info(struct e1000_adapter *adapter)
4137{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004138 struct e1000_hw *hw = &adapter->hw;
4139 u32 ctrl = er32(CTRL);
4140
Bruce Allan8f12fe82008-11-21 16:54:43 -08004141 /* Link status message must follow this format for user tools */
4142 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4143 "Flow Control: %s\n",
4144 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004145 adapter->link_speed,
4146 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004147 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004148 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004149 "Rx/Tx" :
4150 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4151 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004152}
4153
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004154static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004155{
4156 struct e1000_hw *hw = &adapter->hw;
4157 bool link_active = 0;
4158 s32 ret_val = 0;
4159
4160 /*
4161 * get_link_status is set on LSC (link status) interrupt or
4162 * Rx sequence error interrupt. get_link_status will stay
4163 * false until the check_for_link establishes link
4164 * for copper adapters ONLY
4165 */
4166 switch (hw->phy.media_type) {
4167 case e1000_media_type_copper:
4168 if (hw->mac.get_link_status) {
4169 ret_val = hw->mac.ops.check_for_link(hw);
4170 link_active = !hw->mac.get_link_status;
4171 } else {
4172 link_active = 1;
4173 }
4174 break;
4175 case e1000_media_type_fiber:
4176 ret_val = hw->mac.ops.check_for_link(hw);
4177 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4178 break;
4179 case e1000_media_type_internal_serdes:
4180 ret_val = hw->mac.ops.check_for_link(hw);
4181 link_active = adapter->hw.mac.serdes_has_link;
4182 break;
4183 default:
4184 case e1000_media_type_unknown:
4185 break;
4186 }
4187
4188 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4189 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4190 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004191 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004192 }
4193
4194 return link_active;
4195}
4196
4197static void e1000e_enable_receives(struct e1000_adapter *adapter)
4198{
4199 /* make sure the receive unit is started */
4200 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4201 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4202 struct e1000_hw *hw = &adapter->hw;
4203 u32 rctl = er32(RCTL);
4204 ew32(RCTL, rctl | E1000_RCTL_EN);
4205 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4206 }
4207}
4208
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004209static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4210{
4211 struct e1000_hw *hw = &adapter->hw;
4212
4213 /*
4214 * With 82574 controllers, PHY needs to be checked periodically
4215 * for hung state and reset, if two calls return true
4216 */
4217 if (e1000_check_phy_82574(hw))
4218 adapter->phy_hang_count++;
4219 else
4220 adapter->phy_hang_count = 0;
4221
4222 if (adapter->phy_hang_count > 1) {
4223 adapter->phy_hang_count = 0;
4224 schedule_work(&adapter->reset_task);
4225 }
4226}
4227
Auke Kokbc7f75f2007-09-17 12:30:59 -07004228/**
4229 * e1000_watchdog - Timer Call-back
4230 * @data: pointer to adapter cast into an unsigned long
4231 **/
4232static void e1000_watchdog(unsigned long data)
4233{
4234 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4235
4236 /* Do the rest outside of interrupt context */
4237 schedule_work(&adapter->watchdog_task);
4238
4239 /* TODO: make this use queue_delayed_work() */
4240}
4241
4242static void e1000_watchdog_task(struct work_struct *work)
4243{
4244 struct e1000_adapter *adapter = container_of(work,
4245 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004246 struct net_device *netdev = adapter->netdev;
4247 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004248 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004249 struct e1000_ring *tx_ring = adapter->tx_ring;
4250 struct e1000_hw *hw = &adapter->hw;
4251 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004252
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004253 if (test_bit(__E1000_DOWN, &adapter->state))
4254 return;
4255
David S. Millerb405e8d2010-02-04 22:31:41 -08004256 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004257 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004258 /* Cancel scheduled suspend requests. */
4259 pm_runtime_resume(netdev->dev.parent);
4260
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004261 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004262 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004263 }
4264
4265 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4266 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4267 e1000_update_mng_vlan(adapter);
4268
Auke Kokbc7f75f2007-09-17 12:30:59 -07004269 if (link) {
4270 if (!netif_carrier_ok(netdev)) {
4271 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004272
4273 /* Cancel scheduled suspend requests. */
4274 pm_runtime_resume(netdev->dev.parent);
4275
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004276 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004277 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004278 mac->ops.get_link_up_info(&adapter->hw,
4279 &adapter->link_speed,
4280 &adapter->link_duplex);
4281 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004282 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004283 * On supported PHYs, check for duplex mismatch only
4284 * if link has autonegotiated at 10/100 half
4285 */
4286 if ((hw->phy.type == e1000_phy_igp_3 ||
4287 hw->phy.type == e1000_phy_bm) &&
4288 (hw->mac.autoneg == true) &&
4289 (adapter->link_speed == SPEED_10 ||
4290 adapter->link_speed == SPEED_100) &&
4291 (adapter->link_duplex == HALF_DUPLEX)) {
4292 u16 autoneg_exp;
4293
4294 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4295
4296 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4297 e_info("Autonegotiated half duplex but"
4298 " link partner cannot autoneg. "
4299 " Try forcing full duplex if "
4300 "link gets many collisions.\n");
4301 }
4302
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004303 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004304 adapter->tx_timeout_factor = 1;
4305 switch (adapter->link_speed) {
4306 case SPEED_10:
4307 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004308 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004309 break;
4310 case SPEED_100:
4311 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004312 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004313 break;
4314 }
4315
Bruce Allanad680762008-03-28 09:15:03 -07004316 /*
4317 * workaround: re-program speed mode bit after
4318 * link-up event
4319 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004320 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4321 !txb2b) {
4322 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004323 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004324 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004325 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004326 }
4327
Bruce Allanad680762008-03-28 09:15:03 -07004328 /*
4329 * disable TSO for pcie and 10/100 speeds, to avoid
4330 * some hardware issues
4331 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004332 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4333 switch (adapter->link_speed) {
4334 case SPEED_10:
4335 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004336 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004337 netdev->features &= ~NETIF_F_TSO;
4338 netdev->features &= ~NETIF_F_TSO6;
4339 break;
4340 case SPEED_1000:
4341 netdev->features |= NETIF_F_TSO;
4342 netdev->features |= NETIF_F_TSO6;
4343 break;
4344 default:
4345 /* oops */
4346 break;
4347 }
4348 }
4349
Bruce Allanad680762008-03-28 09:15:03 -07004350 /*
4351 * enable transmits in the hardware, need to do this
4352 * after setting TARC(0)
4353 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004354 tctl = er32(TCTL);
4355 tctl |= E1000_TCTL_EN;
4356 ew32(TCTL, tctl);
4357
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004358 /*
4359 * Perform any post-link-up configuration before
4360 * reporting link up.
4361 */
4362 if (phy->ops.cfg_on_link_up)
4363 phy->ops.cfg_on_link_up(hw);
4364
Auke Kokbc7f75f2007-09-17 12:30:59 -07004365 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004366
4367 if (!test_bit(__E1000_DOWN, &adapter->state))
4368 mod_timer(&adapter->phy_info_timer,
4369 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004370 }
4371 } else {
4372 if (netif_carrier_ok(netdev)) {
4373 adapter->link_speed = 0;
4374 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004375 /* Link status message must follow this format */
4376 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4377 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004378 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004379 if (!test_bit(__E1000_DOWN, &adapter->state))
4380 mod_timer(&adapter->phy_info_timer,
4381 round_jiffies(jiffies + 2 * HZ));
4382
4383 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4384 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004385 else
4386 pm_schedule_suspend(netdev->dev.parent,
4387 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004388 }
4389 }
4390
4391link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004392 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004393 e1000e_update_stats(adapter);
4394
4395 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4396 adapter->tpt_old = adapter->stats.tpt;
4397 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4398 adapter->colc_old = adapter->stats.colc;
4399
Bruce Allan7c257692008-04-23 11:09:00 -07004400 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4401 adapter->gorc_old = adapter->stats.gorc;
4402 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4403 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004404 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004405
4406 e1000e_update_adaptive(&adapter->hw);
4407
Bruce Allan90da0662011-01-06 07:02:53 +00004408 if (!netif_carrier_ok(netdev) &&
4409 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4410 /*
4411 * We've lost link, so the controller stops DMA,
4412 * but we've got queued Tx work that's never going
4413 * to get done, so reset controller to flush Tx.
4414 * (Do the reset outside of interrupt context).
4415 */
Bruce Allan90da0662011-01-06 07:02:53 +00004416 schedule_work(&adapter->reset_task);
4417 /* return immediately since reset is imminent */
4418 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004419 }
4420
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004421 /* Simple mode for Interrupt Throttle Rate (ITR) */
4422 if (adapter->itr_setting == 4) {
4423 /*
4424 * Symmetric Tx/Rx gets a reduced ITR=2000;
4425 * Total asymmetrical Tx or Rx gets ITR=8000;
4426 * everyone else is between 2000-8000.
4427 */
4428 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4429 u32 dif = (adapter->gotc > adapter->gorc ?
4430 adapter->gotc - adapter->gorc :
4431 adapter->gorc - adapter->gotc) / 10000;
4432 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4433
4434 ew32(ITR, 1000000000 / (itr * 256));
4435 }
4436
Bruce Allanad680762008-03-28 09:15:03 -07004437 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004438 if (adapter->msix_entries)
4439 ew32(ICS, adapter->rx_ring->ims_val);
4440 else
4441 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004442
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004443 /* flush pending descriptors to memory before detecting Tx hang */
4444 e1000e_flush_descriptors(adapter);
4445
Auke Kokbc7f75f2007-09-17 12:30:59 -07004446 /* Force detection of hung controller every watchdog period */
4447 adapter->detect_tx_hung = 1;
4448
Bruce Allanad680762008-03-28 09:15:03 -07004449 /*
4450 * With 82571 controllers, LAA may be overwritten due to controller
4451 * reset from the other port. Set the appropriate LAA in RAR[0]
4452 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004453 if (e1000e_get_laa_state_82571(hw))
4454 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4455
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004456 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4457 e1000e_check_82574_phy_workaround(adapter);
4458
Auke Kokbc7f75f2007-09-17 12:30:59 -07004459 /* Reset the timer */
4460 if (!test_bit(__E1000_DOWN, &adapter->state))
4461 mod_timer(&adapter->watchdog_timer,
4462 round_jiffies(jiffies + 2 * HZ));
4463}
4464
4465#define E1000_TX_FLAGS_CSUM 0x00000001
4466#define E1000_TX_FLAGS_VLAN 0x00000002
4467#define E1000_TX_FLAGS_TSO 0x00000004
4468#define E1000_TX_FLAGS_IPV4 0x00000008
4469#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4470#define E1000_TX_FLAGS_VLAN_SHIFT 16
4471
4472static int e1000_tso(struct e1000_adapter *adapter,
4473 struct sk_buff *skb)
4474{
4475 struct e1000_ring *tx_ring = adapter->tx_ring;
4476 struct e1000_context_desc *context_desc;
4477 struct e1000_buffer *buffer_info;
4478 unsigned int i;
4479 u32 cmd_length = 0;
4480 u16 ipcse = 0, tucse, mss;
4481 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004482
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004483 if (!skb_is_gso(skb))
4484 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004485
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004486 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004487 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4488
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004489 if (err)
4490 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004491 }
4492
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004493 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4494 mss = skb_shinfo(skb)->gso_size;
4495 if (skb->protocol == htons(ETH_P_IP)) {
4496 struct iphdr *iph = ip_hdr(skb);
4497 iph->tot_len = 0;
4498 iph->check = 0;
4499 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4500 0, IPPROTO_TCP, 0);
4501 cmd_length = E1000_TXD_CMD_IP;
4502 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004503 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004504 ipv6_hdr(skb)->payload_len = 0;
4505 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4506 &ipv6_hdr(skb)->daddr,
4507 0, IPPROTO_TCP, 0);
4508 ipcse = 0;
4509 }
4510 ipcss = skb_network_offset(skb);
4511 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4512 tucss = skb_transport_offset(skb);
4513 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4514 tucse = 0;
4515
4516 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4517 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4518
4519 i = tx_ring->next_to_use;
4520 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4521 buffer_info = &tx_ring->buffer_info[i];
4522
4523 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4524 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4525 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4526 context_desc->upper_setup.tcp_fields.tucss = tucss;
4527 context_desc->upper_setup.tcp_fields.tucso = tucso;
4528 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4529 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4530 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4531 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4532
4533 buffer_info->time_stamp = jiffies;
4534 buffer_info->next_to_watch = i;
4535
4536 i++;
4537 if (i == tx_ring->count)
4538 i = 0;
4539 tx_ring->next_to_use = i;
4540
4541 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004542}
4543
4544static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4545{
4546 struct e1000_ring *tx_ring = adapter->tx_ring;
4547 struct e1000_context_desc *context_desc;
4548 struct e1000_buffer *buffer_info;
4549 unsigned int i;
4550 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004551 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004552 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004553
Dave Grahamaf807c82008-10-09 14:28:58 -07004554 if (skb->ip_summed != CHECKSUM_PARTIAL)
4555 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004556
Arthur Jones5f66f202009-03-19 01:13:08 +00004557 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4558 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4559 else
4560 protocol = skb->protocol;
4561
Arthur Jones3f518392009-03-20 15:56:35 -07004562 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004563 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004564 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4565 cmd_len |= E1000_TXD_CMD_TCP;
4566 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004567 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004568 /* XXX not handling all IPV6 headers */
4569 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4570 cmd_len |= E1000_TXD_CMD_TCP;
4571 break;
4572 default:
4573 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004574 e_warn("checksum_partial proto=%x!\n",
4575 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004576 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004577 }
4578
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004579 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004580
4581 i = tx_ring->next_to_use;
4582 buffer_info = &tx_ring->buffer_info[i];
4583 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4584
4585 context_desc->lower_setup.ip_config = 0;
4586 context_desc->upper_setup.tcp_fields.tucss = css;
4587 context_desc->upper_setup.tcp_fields.tucso =
4588 css + skb->csum_offset;
4589 context_desc->upper_setup.tcp_fields.tucse = 0;
4590 context_desc->tcp_seg_setup.data = 0;
4591 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4592
4593 buffer_info->time_stamp = jiffies;
4594 buffer_info->next_to_watch = i;
4595
4596 i++;
4597 if (i == tx_ring->count)
4598 i = 0;
4599 tx_ring->next_to_use = i;
4600
4601 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004602}
4603
4604#define E1000_MAX_PER_TXD 8192
4605#define E1000_MAX_TXD_PWR 12
4606
4607static int e1000_tx_map(struct e1000_adapter *adapter,
4608 struct sk_buff *skb, unsigned int first,
4609 unsigned int max_per_txd, unsigned int nr_frags,
4610 unsigned int mss)
4611{
4612 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004613 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004614 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004615 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004616 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004617 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004618
4619 i = tx_ring->next_to_use;
4620
4621 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004622 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004623 size = min(len, max_per_txd);
4624
Auke Kokbc7f75f2007-09-17 12:30:59 -07004625 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004626 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004627 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004628 buffer_info->dma = dma_map_single(&pdev->dev,
4629 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004630 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004631 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004632 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004633 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004634
4635 len -= size;
4636 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004637 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004638
4639 if (len) {
4640 i++;
4641 if (i == tx_ring->count)
4642 i = 0;
4643 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004644 }
4645
4646 for (f = 0; f < nr_frags; f++) {
4647 struct skb_frag_struct *frag;
4648
4649 frag = &skb_shinfo(skb)->frags[f];
4650 len = frag->size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004651 offset = frag->page_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004652
4653 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004654 i++;
4655 if (i == tx_ring->count)
4656 i = 0;
4657
Auke Kokbc7f75f2007-09-17 12:30:59 -07004658 buffer_info = &tx_ring->buffer_info[i];
4659 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004660
4661 buffer_info->length = size;
4662 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004663 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004664 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
Alexander Duyck03b13202009-12-02 16:45:31 +00004665 offset, size,
Nick Nunley0be3f552010-04-27 13:09:05 +00004666 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004667 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004668 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004669 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004670
4671 len -= size;
4672 offset += size;
4673 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004674 }
4675 }
4676
Bruce Allanaf667a22010-12-31 06:10:01 +00004677 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004678 /* multiply data chunks by size of headers */
4679 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4680
Auke Kokbc7f75f2007-09-17 12:30:59 -07004681 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004682 tx_ring->buffer_info[i].segs = segs;
4683 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004684 tx_ring->buffer_info[first].next_to_watch = i;
4685
4686 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004687
4688dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004689 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004690 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004691 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004692 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004693
4694 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004695 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004696 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004697 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004698 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004699 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004700 }
4701
4702 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004703}
4704
4705static void e1000_tx_queue(struct e1000_adapter *adapter,
4706 int tx_flags, int count)
4707{
4708 struct e1000_ring *tx_ring = adapter->tx_ring;
4709 struct e1000_tx_desc *tx_desc = NULL;
4710 struct e1000_buffer *buffer_info;
4711 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4712 unsigned int i;
4713
4714 if (tx_flags & E1000_TX_FLAGS_TSO) {
4715 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4716 E1000_TXD_CMD_TSE;
4717 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4718
4719 if (tx_flags & E1000_TX_FLAGS_IPV4)
4720 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4721 }
4722
4723 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4724 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4725 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4726 }
4727
4728 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4729 txd_lower |= E1000_TXD_CMD_VLE;
4730 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4731 }
4732
4733 i = tx_ring->next_to_use;
4734
Bruce Allan36b973d2010-11-24 07:42:43 +00004735 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004736 buffer_info = &tx_ring->buffer_info[i];
4737 tx_desc = E1000_TX_DESC(*tx_ring, i);
4738 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4739 tx_desc->lower.data =
4740 cpu_to_le32(txd_lower | buffer_info->length);
4741 tx_desc->upper.data = cpu_to_le32(txd_upper);
4742
4743 i++;
4744 if (i == tx_ring->count)
4745 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004746 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004747
4748 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4749
Bruce Allanad680762008-03-28 09:15:03 -07004750 /*
4751 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004752 * know there are new descriptors to fetch. (Only
4753 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004754 * such as IA-64).
4755 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004756 wmb();
4757
4758 tx_ring->next_to_use = i;
Bruce Allanc6e7f512011-07-29 05:53:02 +00004759
4760 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4761 e1000e_update_tdt_wa(adapter, i);
4762 else
4763 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4764
Bruce Allanad680762008-03-28 09:15:03 -07004765 /*
4766 * we need this if more than one processor can write to our tail
4767 * at a time, it synchronizes IO on IA64/Altix systems
4768 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004769 mmiowb();
4770}
4771
4772#define MINIMUM_DHCP_PACKET_SIZE 282
4773static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4774 struct sk_buff *skb)
4775{
4776 struct e1000_hw *hw = &adapter->hw;
4777 u16 length, offset;
4778
4779 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004780 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4781 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004782 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4783 return 0;
4784 }
4785
4786 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4787 return 0;
4788
4789 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4790 return 0;
4791
4792 {
4793 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4794 struct udphdr *udp;
4795
4796 if (ip->protocol != IPPROTO_UDP)
4797 return 0;
4798
4799 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4800 if (ntohs(udp->dest) != 67)
4801 return 0;
4802
4803 offset = (u8 *)udp + 8 - skb->data;
4804 length = skb->len - offset;
4805 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4806 }
4807
4808 return 0;
4809}
4810
4811static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4812{
4813 struct e1000_adapter *adapter = netdev_priv(netdev);
4814
4815 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004816 /*
4817 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004818 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004819 * but since that doesn't exist yet, just open code it.
4820 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004821 smp_mb();
4822
Bruce Allanad680762008-03-28 09:15:03 -07004823 /*
4824 * We need to check again in a case another CPU has just
4825 * made room available.
4826 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004827 if (e1000_desc_unused(adapter->tx_ring) < size)
4828 return -EBUSY;
4829
4830 /* A reprieve! */
4831 netif_start_queue(netdev);
4832 ++adapter->restart_queue;
4833 return 0;
4834}
4835
4836static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4837{
4838 struct e1000_adapter *adapter = netdev_priv(netdev);
4839
4840 if (e1000_desc_unused(adapter->tx_ring) >= size)
4841 return 0;
4842 return __e1000_maybe_stop_tx(netdev, size);
4843}
4844
4845#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004846static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4847 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004848{
4849 struct e1000_adapter *adapter = netdev_priv(netdev);
4850 struct e1000_ring *tx_ring = adapter->tx_ring;
4851 unsigned int first;
4852 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4853 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4854 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004855 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004856 unsigned int nr_frags;
4857 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004858 int count = 0;
4859 int tso;
4860 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004861
4862 if (test_bit(__E1000_DOWN, &adapter->state)) {
4863 dev_kfree_skb_any(skb);
4864 return NETDEV_TX_OK;
4865 }
4866
4867 if (skb->len <= 0) {
4868 dev_kfree_skb_any(skb);
4869 return NETDEV_TX_OK;
4870 }
4871
4872 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004873 /*
4874 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004875 * make sure there is enough room in the FIFO before
4876 * initiating the DMA for each buffer. The calc is:
4877 * 4 = ceil(buffer len/mss). To make sure we don't
4878 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004879 * drops.
4880 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004881 if (mss) {
4882 u8 hdr_len;
4883 max_per_txd = min(mss << 2, max_per_txd);
4884 max_txd_pwr = fls(max_per_txd) - 1;
4885
Bruce Allanad680762008-03-28 09:15:03 -07004886 /*
4887 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4888 * points to just header, pull a few bytes of payload from
4889 * frags into skb->data
4890 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004891 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004892 /*
4893 * we do this workaround for ES2LAN, but it is un-necessary,
4894 * avoiding it could save a lot of cycles
4895 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004896 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004897 unsigned int pull_size;
4898
4899 pull_size = min((unsigned int)4, skb->data_len);
4900 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004901 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004902 dev_kfree_skb_any(skb);
4903 return NETDEV_TX_OK;
4904 }
Eric Dumazete743d312010-04-14 15:59:40 -07004905 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004906 }
4907 }
4908
4909 /* reserve a descriptor for the offload context */
4910 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4911 count++;
4912 count++;
4913
4914 count += TXD_USE_COUNT(len, max_txd_pwr);
4915
4916 nr_frags = skb_shinfo(skb)->nr_frags;
4917 for (f = 0; f < nr_frags; f++)
4918 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4919 max_txd_pwr);
4920
4921 if (adapter->hw.mac.tx_pkt_filtering)
4922 e1000_transfer_dhcp_info(adapter, skb);
4923
Bruce Allanad680762008-03-28 09:15:03 -07004924 /*
4925 * need: count + 2 desc gap to keep tail from touching
4926 * head, otherwise try next time
4927 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004928 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004929 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004930
Jesse Grosseab6d182010-10-20 13:56:03 +00004931 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004932 tx_flags |= E1000_TX_FLAGS_VLAN;
4933 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4934 }
4935
4936 first = tx_ring->next_to_use;
4937
4938 tso = e1000_tso(adapter, skb);
4939 if (tso < 0) {
4940 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004941 return NETDEV_TX_OK;
4942 }
4943
4944 if (tso)
4945 tx_flags |= E1000_TX_FLAGS_TSO;
4946 else if (e1000_tx_csum(adapter, skb))
4947 tx_flags |= E1000_TX_FLAGS_CSUM;
4948
Bruce Allanad680762008-03-28 09:15:03 -07004949 /*
4950 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004951 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004952 * no longer assume, we must.
4953 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004954 if (skb->protocol == htons(ETH_P_IP))
4955 tx_flags |= E1000_TX_FLAGS_IPV4;
4956
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004957 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004958 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004959 if (count) {
4960 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004961 /* Make sure there is space in the ring for the next send. */
4962 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4963
4964 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004965 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004966 tx_ring->buffer_info[first].time_stamp = 0;
4967 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004968 }
4969
Auke Kokbc7f75f2007-09-17 12:30:59 -07004970 return NETDEV_TX_OK;
4971}
4972
4973/**
4974 * e1000_tx_timeout - Respond to a Tx Hang
4975 * @netdev: network interface device structure
4976 **/
4977static void e1000_tx_timeout(struct net_device *netdev)
4978{
4979 struct e1000_adapter *adapter = netdev_priv(netdev);
4980
4981 /* Do the reset outside of interrupt context */
4982 adapter->tx_timeout_count++;
4983 schedule_work(&adapter->reset_task);
4984}
4985
4986static void e1000_reset_task(struct work_struct *work)
4987{
4988 struct e1000_adapter *adapter;
4989 adapter = container_of(work, struct e1000_adapter, reset_task);
4990
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004991 /* don't run the task if already down */
4992 if (test_bit(__E1000_DOWN, &adapter->state))
4993 return;
4994
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00004995 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4996 (adapter->flags & FLAG_RX_RESTART_NOW))) {
4997 e1000e_dump(adapter);
4998 e_err("Reset adapter\n");
4999 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005000 e1000e_reinit_locked(adapter);
5001}
5002
5003/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005004 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005005 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005006 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005007 *
5008 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005009 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005010struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5011 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005012{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005013 struct e1000_adapter *adapter = netdev_priv(netdev);
5014
5015 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5016 spin_lock(&adapter->stats64_lock);
5017 e1000e_update_stats(adapter);
5018 /* Fill out the OS statistics structure */
5019 stats->rx_bytes = adapter->stats.gorc;
5020 stats->rx_packets = adapter->stats.gprc;
5021 stats->tx_bytes = adapter->stats.gotc;
5022 stats->tx_packets = adapter->stats.gptc;
5023 stats->multicast = adapter->stats.mprc;
5024 stats->collisions = adapter->stats.colc;
5025
5026 /* Rx Errors */
5027
5028 /*
5029 * RLEC on some newer hardware can be incorrect so build
5030 * our own version based on RUC and ROC
5031 */
5032 stats->rx_errors = adapter->stats.rxerrc +
5033 adapter->stats.crcerrs + adapter->stats.algnerrc +
5034 adapter->stats.ruc + adapter->stats.roc +
5035 adapter->stats.cexterr;
5036 stats->rx_length_errors = adapter->stats.ruc +
5037 adapter->stats.roc;
5038 stats->rx_crc_errors = adapter->stats.crcerrs;
5039 stats->rx_frame_errors = adapter->stats.algnerrc;
5040 stats->rx_missed_errors = adapter->stats.mpc;
5041
5042 /* Tx Errors */
5043 stats->tx_errors = adapter->stats.ecol +
5044 adapter->stats.latecol;
5045 stats->tx_aborted_errors = adapter->stats.ecol;
5046 stats->tx_window_errors = adapter->stats.latecol;
5047 stats->tx_carrier_errors = adapter->stats.tncrs;
5048
5049 /* Tx Dropped needs to be maintained elsewhere */
5050
5051 spin_unlock(&adapter->stats64_lock);
5052 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005053}
5054
5055/**
5056 * e1000_change_mtu - Change the Maximum Transfer Unit
5057 * @netdev: network interface device structure
5058 * @new_mtu: new value for maximum frame size
5059 *
5060 * Returns 0 on success, negative on failure
5061 **/
5062static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5063{
5064 struct e1000_adapter *adapter = netdev_priv(netdev);
5065 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5066
Bruce Allan2adc55c2009-06-02 11:28:58 +00005067 /* Jumbo frame support */
5068 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5069 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5070 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005071 return -EINVAL;
5072 }
5073
Bruce Allan2adc55c2009-06-02 11:28:58 +00005074 /* Supported frame sizes */
5075 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5076 (max_frame > adapter->max_hw_frame_size)) {
5077 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005078 return -EINVAL;
5079 }
5080
Bruce Allana1ce6472010-09-22 17:16:40 +00005081 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5082 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5083 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5084 (new_mtu > ETH_DATA_LEN)) {
5085 e_err("Jumbo Frames not supported on 82579 when CRC "
5086 "stripping is disabled.\n");
5087 return -EINVAL;
5088 }
5089
Bruce Allan6f461f62010-04-27 03:33:04 +00005090 /* 82573 Errata 17 */
5091 if (((adapter->hw.mac.type == e1000_82573) ||
5092 (adapter->hw.mac.type == e1000_82574)) &&
5093 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5094 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5095 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5096 }
5097
Auke Kokbc7f75f2007-09-17 12:30:59 -07005098 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005099 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005100 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005101 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005102 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5103 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005104 if (netif_running(netdev))
5105 e1000e_down(adapter);
5106
Bruce Allanad680762008-03-28 09:15:03 -07005107 /*
5108 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005109 * means we reserve 2 more, this pushes us to allocate from the next
5110 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005111 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005112 * However with the new *_jumbo_rx* routines, jumbo receives will use
5113 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005114 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005115
Jesse Brandeburg99261462010-01-22 22:56:16 +00005116 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005117 adapter->rx_buffer_len = 2048;
5118 else
5119 adapter->rx_buffer_len = 4096;
5120
5121 /* adjust allocation if LPE protects us, and we aren't using SBP */
5122 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5123 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5124 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005125 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005126
Auke Kokbc7f75f2007-09-17 12:30:59 -07005127 if (netif_running(netdev))
5128 e1000e_up(adapter);
5129 else
5130 e1000e_reset(adapter);
5131
5132 clear_bit(__E1000_RESETTING, &adapter->state);
5133
5134 return 0;
5135}
5136
5137static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5138 int cmd)
5139{
5140 struct e1000_adapter *adapter = netdev_priv(netdev);
5141 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005142
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005143 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005144 return -EOPNOTSUPP;
5145
5146 switch (cmd) {
5147 case SIOCGMIIPHY:
5148 data->phy_id = adapter->hw.phy.addr;
5149 break;
5150 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005151 e1000_phy_read_status(adapter);
5152
Bruce Allan7c257692008-04-23 11:09:00 -07005153 switch (data->reg_num & 0x1F) {
5154 case MII_BMCR:
5155 data->val_out = adapter->phy_regs.bmcr;
5156 break;
5157 case MII_BMSR:
5158 data->val_out = adapter->phy_regs.bmsr;
5159 break;
5160 case MII_PHYSID1:
5161 data->val_out = (adapter->hw.phy.id >> 16);
5162 break;
5163 case MII_PHYSID2:
5164 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5165 break;
5166 case MII_ADVERTISE:
5167 data->val_out = adapter->phy_regs.advertise;
5168 break;
5169 case MII_LPA:
5170 data->val_out = adapter->phy_regs.lpa;
5171 break;
5172 case MII_EXPANSION:
5173 data->val_out = adapter->phy_regs.expansion;
5174 break;
5175 case MII_CTRL1000:
5176 data->val_out = adapter->phy_regs.ctrl1000;
5177 break;
5178 case MII_STAT1000:
5179 data->val_out = adapter->phy_regs.stat1000;
5180 break;
5181 case MII_ESTATUS:
5182 data->val_out = adapter->phy_regs.estatus;
5183 break;
5184 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005185 return -EIO;
5186 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005187 break;
5188 case SIOCSMIIREG:
5189 default:
5190 return -EOPNOTSUPP;
5191 }
5192 return 0;
5193}
5194
5195static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5196{
5197 switch (cmd) {
5198 case SIOCGMIIPHY:
5199 case SIOCGMIIREG:
5200 case SIOCSMIIREG:
5201 return e1000_mii_ioctl(netdev, ifr, cmd);
5202 default:
5203 return -EOPNOTSUPP;
5204 }
5205}
5206
Bruce Allana4f58f52009-06-02 11:29:18 +00005207static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5208{
5209 struct e1000_hw *hw = &adapter->hw;
5210 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005211 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005212 int retval = 0;
5213
5214 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005215 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005216
Bruce Allan2b6b1682011-05-13 07:20:09 +00005217 retval = hw->phy.ops.acquire(hw);
5218 if (retval) {
5219 e_err("Could not acquire PHY\n");
5220 return retval;
5221 }
5222
5223 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5224 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5225 if (retval)
5226 goto out;
5227
5228 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005229 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5230 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005231 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5232 (u16)(mac_reg & 0xFFFF));
5233 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5234 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005235 }
5236
5237 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005238 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005239 mac_reg = er32(RCTL);
5240 if (mac_reg & E1000_RCTL_UPE)
5241 phy_reg |= BM_RCTL_UPE;
5242 if (mac_reg & E1000_RCTL_MPE)
5243 phy_reg |= BM_RCTL_MPE;
5244 phy_reg &= ~(BM_RCTL_MO_MASK);
5245 if (mac_reg & E1000_RCTL_MO_3)
5246 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5247 << BM_RCTL_MO_SHIFT);
5248 if (mac_reg & E1000_RCTL_BAM)
5249 phy_reg |= BM_RCTL_BAM;
5250 if (mac_reg & E1000_RCTL_PMCF)
5251 phy_reg |= BM_RCTL_PMCF;
5252 mac_reg = er32(CTRL);
5253 if (mac_reg & E1000_CTRL_RFCE)
5254 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005255 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005256
5257 /* enable PHY wakeup in MAC register */
5258 ew32(WUFC, wufc);
5259 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5260
5261 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005262 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5263 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005264
5265 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005266 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5267 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005268 if (retval)
5269 e_err("Could not set PHY Host Wakeup bit\n");
5270out:
Bruce Allan94d81862009-11-20 23:25:26 +00005271 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005272
5273 return retval;
5274}
5275
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005276static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5277 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005278{
5279 struct net_device *netdev = pci_get_drvdata(pdev);
5280 struct e1000_adapter *adapter = netdev_priv(netdev);
5281 struct e1000_hw *hw = &adapter->hw;
5282 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005283 /* Runtime suspend should only enable wakeup for link changes */
5284 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005285 int retval = 0;
5286
5287 netif_device_detach(netdev);
5288
5289 if (netif_running(netdev)) {
5290 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5291 e1000e_down(adapter);
5292 e1000_free_irq(adapter);
5293 }
Bruce Allan4662e822008-08-26 18:37:06 -07005294 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005295
5296 retval = pci_save_state(pdev);
5297 if (retval)
5298 return retval;
5299
5300 status = er32(STATUS);
5301 if (status & E1000_STATUS_LU)
5302 wufc &= ~E1000_WUFC_LNKC;
5303
5304 if (wufc) {
5305 e1000_setup_rctl(adapter);
5306 e1000_set_multi(netdev);
5307
5308 /* turn on all-multi mode if wake on multicast is enabled */
5309 if (wufc & E1000_WUFC_MC) {
5310 rctl = er32(RCTL);
5311 rctl |= E1000_RCTL_MPE;
5312 ew32(RCTL, rctl);
5313 }
5314
5315 ctrl = er32(CTRL);
5316 /* advertise wake from D3Cold */
5317 #define E1000_CTRL_ADVD3WUC 0x00100000
5318 /* phy power management enable */
5319 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005320 ctrl |= E1000_CTRL_ADVD3WUC;
5321 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5322 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005323 ew32(CTRL, ctrl);
5324
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005325 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5326 adapter->hw.phy.media_type ==
5327 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005328 /* keep the laser running in D3 */
5329 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005330 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005331 ew32(CTRL_EXT, ctrl_ext);
5332 }
5333
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005334 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005335 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005336
Auke Kokbc7f75f2007-09-17 12:30:59 -07005337 /* Allow time for pending master requests to run */
5338 e1000e_disable_pcie_master(&adapter->hw);
5339
Bruce Allan82776a42009-08-14 14:35:33 +00005340 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005341 /* enable wakeup by the PHY */
5342 retval = e1000_init_phy_wakeup(adapter, wufc);
5343 if (retval)
5344 return retval;
5345 } else {
5346 /* enable wakeup by the MAC */
5347 ew32(WUFC, wufc);
5348 ew32(WUC, E1000_WUC_PME_EN);
5349 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005350 } else {
5351 ew32(WUC, 0);
5352 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005353 }
5354
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005355 *enable_wake = !!wufc;
5356
Auke Kokbc7f75f2007-09-17 12:30:59 -07005357 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005358 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5359 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005360 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005361
5362 if (adapter->hw.phy.type == e1000_phy_igp_3)
5363 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5364
Bruce Allanad680762008-03-28 09:15:03 -07005365 /*
5366 * Release control of h/w to f/w. If f/w is AMT enabled, this
5367 * would have already happened in close and is redundant.
5368 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005369 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005370
5371 pci_disable_device(pdev);
5372
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005373 return 0;
5374}
5375
5376static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5377{
5378 if (sleep && wake) {
5379 pci_prepare_to_sleep(pdev);
5380 return;
5381 }
5382
5383 pci_wake_from_d3(pdev, wake);
5384 pci_set_power_state(pdev, PCI_D3hot);
5385}
5386
5387static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5388 bool wake)
5389{
5390 struct net_device *netdev = pci_get_drvdata(pdev);
5391 struct e1000_adapter *adapter = netdev_priv(netdev);
5392
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005393 /*
5394 * The pci-e switch on some quad port adapters will report a
5395 * correctable error when the MAC transitions from D0 to D3. To
5396 * prevent this we need to mask off the correctable errors on the
5397 * downstream port of the pci-e switch.
5398 */
5399 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5400 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005401 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005402 u16 devctl;
5403
5404 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5405 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5406 (devctl & ~PCI_EXP_DEVCTL_CERE));
5407
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005408 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005409
5410 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5411 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005412 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005413 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005414}
5415
Bruce Allan6f461f62010-04-27 03:33:04 +00005416#ifdef CONFIG_PCIEASPM
5417static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5418{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005419 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005420}
5421#else
5422static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005423{
5424 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005425 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005426
5427 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005428 * Both device and parent should have the same ASPM setting.
5429 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005430 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005431 pos = pci_pcie_cap(pdev);
5432 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5433 reg16 &= ~state;
5434 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5435
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005436 if (!pdev->bus->self)
5437 return;
5438
Bruce Allan6f461f62010-04-27 03:33:04 +00005439 pos = pci_pcie_cap(pdev->bus->self);
5440 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5441 reg16 &= ~state;
5442 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5443}
5444#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005445static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005446{
5447 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5448 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5449 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5450
5451 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005452}
5453
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005454#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005455static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005456{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005457 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005458}
5459
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005460static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005461{
5462 struct net_device *netdev = pci_get_drvdata(pdev);
5463 struct e1000_adapter *adapter = netdev_priv(netdev);
5464 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005465 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005466 u32 err;
5467
Bruce Allan78cd29d2011-03-24 03:09:03 +00005468 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5469 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5470 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5471 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5472 if (aspm_disable_flag)
5473 e1000e_disable_aspm(pdev, aspm_disable_flag);
5474
Auke Kokbc7f75f2007-09-17 12:30:59 -07005475 pci_set_power_state(pdev, PCI_D0);
5476 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005477 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005478
Bruce Allan4662e822008-08-26 18:37:06 -07005479 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005480 if (netif_running(netdev)) {
5481 err = e1000_request_irq(adapter);
5482 if (err)
5483 return err;
5484 }
5485
Bruce Allan99730e42011-05-13 07:19:48 +00005486 if (hw->mac.type == e1000_pch2lan)
5487 e1000_resume_workarounds_pchlan(&adapter->hw);
5488
Auke Kokbc7f75f2007-09-17 12:30:59 -07005489 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005490
5491 /* report the system wakeup cause from S3/S4 */
5492 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5493 u16 phy_data;
5494
5495 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5496 if (phy_data) {
5497 e_info("PHY Wakeup cause - %s\n",
5498 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5499 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5500 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5501 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5502 phy_data & E1000_WUS_LNKC ? "Link Status "
5503 " Change" : "other");
5504 }
5505 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5506 } else {
5507 u32 wus = er32(WUS);
5508 if (wus) {
5509 e_info("MAC Wakeup cause - %s\n",
5510 wus & E1000_WUS_EX ? "Unicast Packet" :
5511 wus & E1000_WUS_MC ? "Multicast Packet" :
5512 wus & E1000_WUS_BC ? "Broadcast Packet" :
5513 wus & E1000_WUS_MAG ? "Magic Packet" :
5514 wus & E1000_WUS_LNKC ? "Link Status Change" :
5515 "other");
5516 }
5517 ew32(WUS, ~0);
5518 }
5519
Auke Kokbc7f75f2007-09-17 12:30:59 -07005520 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005521
Bruce Allancd791612010-05-10 14:59:51 +00005522 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005523
5524 if (netif_running(netdev))
5525 e1000e_up(adapter);
5526
5527 netif_device_attach(netdev);
5528
Bruce Allanad680762008-03-28 09:15:03 -07005529 /*
5530 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005531 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005532 * under the control of the driver.
5533 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005534 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005535 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005536
5537 return 0;
5538}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005539
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005540#ifdef CONFIG_PM_SLEEP
5541static int e1000_suspend(struct device *dev)
5542{
5543 struct pci_dev *pdev = to_pci_dev(dev);
5544 int retval;
5545 bool wake;
5546
5547 retval = __e1000_shutdown(pdev, &wake, false);
5548 if (!retval)
5549 e1000_complete_shutdown(pdev, true, wake);
5550
5551 return retval;
5552}
5553
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005554static int e1000_resume(struct device *dev)
5555{
5556 struct pci_dev *pdev = to_pci_dev(dev);
5557 struct net_device *netdev = pci_get_drvdata(pdev);
5558 struct e1000_adapter *adapter = netdev_priv(netdev);
5559
5560 if (e1000e_pm_ready(adapter))
5561 adapter->idle_check = true;
5562
5563 return __e1000_resume(pdev);
5564}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005565#endif /* CONFIG_PM_SLEEP */
5566
5567#ifdef CONFIG_PM_RUNTIME
5568static int e1000_runtime_suspend(struct device *dev)
5569{
5570 struct pci_dev *pdev = to_pci_dev(dev);
5571 struct net_device *netdev = pci_get_drvdata(pdev);
5572 struct e1000_adapter *adapter = netdev_priv(netdev);
5573
5574 if (e1000e_pm_ready(adapter)) {
5575 bool wake;
5576
5577 __e1000_shutdown(pdev, &wake, true);
5578 }
5579
5580 return 0;
5581}
5582
5583static int e1000_idle(struct device *dev)
5584{
5585 struct pci_dev *pdev = to_pci_dev(dev);
5586 struct net_device *netdev = pci_get_drvdata(pdev);
5587 struct e1000_adapter *adapter = netdev_priv(netdev);
5588
5589 if (!e1000e_pm_ready(adapter))
5590 return 0;
5591
5592 if (adapter->idle_check) {
5593 adapter->idle_check = false;
5594 if (!e1000e_has_link(adapter))
5595 pm_schedule_suspend(dev, MSEC_PER_SEC);
5596 }
5597
5598 return -EBUSY;
5599}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005600
5601static int e1000_runtime_resume(struct device *dev)
5602{
5603 struct pci_dev *pdev = to_pci_dev(dev);
5604 struct net_device *netdev = pci_get_drvdata(pdev);
5605 struct e1000_adapter *adapter = netdev_priv(netdev);
5606
5607 if (!e1000e_pm_ready(adapter))
5608 return 0;
5609
5610 adapter->idle_check = !dev->power.runtime_auto;
5611 return __e1000_resume(pdev);
5612}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005613#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005614#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005615
5616static void e1000_shutdown(struct pci_dev *pdev)
5617{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005618 bool wake = false;
5619
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005620 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005621
5622 if (system_state == SYSTEM_POWER_OFF)
5623 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005624}
5625
5626#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005627
5628static irqreturn_t e1000_intr_msix(int irq, void *data)
5629{
5630 struct net_device *netdev = data;
5631 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005632
5633 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005634 int vector, msix_irq;
5635
Dongdong Deng147b2c82010-11-16 19:50:15 -08005636 vector = 0;
5637 msix_irq = adapter->msix_entries[vector].vector;
5638 disable_irq(msix_irq);
5639 e1000_intr_msix_rx(msix_irq, netdev);
5640 enable_irq(msix_irq);
5641
5642 vector++;
5643 msix_irq = adapter->msix_entries[vector].vector;
5644 disable_irq(msix_irq);
5645 e1000_intr_msix_tx(msix_irq, netdev);
5646 enable_irq(msix_irq);
5647
5648 vector++;
5649 msix_irq = adapter->msix_entries[vector].vector;
5650 disable_irq(msix_irq);
5651 e1000_msix_other(msix_irq, netdev);
5652 enable_irq(msix_irq);
5653 }
5654
5655 return IRQ_HANDLED;
5656}
5657
Auke Kokbc7f75f2007-09-17 12:30:59 -07005658/*
5659 * Polling 'interrupt' - used by things like netconsole to send skbs
5660 * without having to re-enable interrupts. It's not called while
5661 * the interrupt routine is executing.
5662 */
5663static void e1000_netpoll(struct net_device *netdev)
5664{
5665 struct e1000_adapter *adapter = netdev_priv(netdev);
5666
Dongdong Deng147b2c82010-11-16 19:50:15 -08005667 switch (adapter->int_mode) {
5668 case E1000E_INT_MODE_MSIX:
5669 e1000_intr_msix(adapter->pdev->irq, netdev);
5670 break;
5671 case E1000E_INT_MODE_MSI:
5672 disable_irq(adapter->pdev->irq);
5673 e1000_intr_msi(adapter->pdev->irq, netdev);
5674 enable_irq(adapter->pdev->irq);
5675 break;
5676 default: /* E1000E_INT_MODE_LEGACY */
5677 disable_irq(adapter->pdev->irq);
5678 e1000_intr(adapter->pdev->irq, netdev);
5679 enable_irq(adapter->pdev->irq);
5680 break;
5681 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005682}
5683#endif
5684
5685/**
5686 * e1000_io_error_detected - called when PCI error is detected
5687 * @pdev: Pointer to PCI device
5688 * @state: The current pci connection state
5689 *
5690 * This function is called after a PCI bus error affecting
5691 * this device has been detected.
5692 */
5693static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5694 pci_channel_state_t state)
5695{
5696 struct net_device *netdev = pci_get_drvdata(pdev);
5697 struct e1000_adapter *adapter = netdev_priv(netdev);
5698
5699 netif_device_detach(netdev);
5700
Mike Masonc93b5a72009-06-30 12:45:53 +00005701 if (state == pci_channel_io_perm_failure)
5702 return PCI_ERS_RESULT_DISCONNECT;
5703
Auke Kokbc7f75f2007-09-17 12:30:59 -07005704 if (netif_running(netdev))
5705 e1000e_down(adapter);
5706 pci_disable_device(pdev);
5707
5708 /* Request a slot slot reset. */
5709 return PCI_ERS_RESULT_NEED_RESET;
5710}
5711
5712/**
5713 * e1000_io_slot_reset - called after the pci bus has been reset.
5714 * @pdev: Pointer to PCI device
5715 *
5716 * Restart the card from scratch, as if from a cold-boot. Implementation
5717 * resembles the first-half of the e1000_resume routine.
5718 */
5719static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5720{
5721 struct net_device *netdev = pci_get_drvdata(pdev);
5722 struct e1000_adapter *adapter = netdev_priv(netdev);
5723 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005724 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005725 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005726 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005727
Bruce Allan78cd29d2011-03-24 03:09:03 +00005728 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5729 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005730 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005731 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5732 if (aspm_disable_flag)
5733 e1000e_disable_aspm(pdev, aspm_disable_flag);
5734
Bruce Allanf0f422e2008-08-04 17:21:53 -07005735 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005736 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005737 dev_err(&pdev->dev,
5738 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005739 result = PCI_ERS_RESULT_DISCONNECT;
5740 } else {
5741 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005742 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005743 pci_restore_state(pdev);
5744
5745 pci_enable_wake(pdev, PCI_D3hot, 0);
5746 pci_enable_wake(pdev, PCI_D3cold, 0);
5747
5748 e1000e_reset(adapter);
5749 ew32(WUS, ~0);
5750 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005751 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005752
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005753 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005754
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005755 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005756}
5757
5758/**
5759 * e1000_io_resume - called when traffic can start flowing again.
5760 * @pdev: Pointer to PCI device
5761 *
5762 * This callback is called when the error recovery driver tells us that
5763 * its OK to resume normal operation. Implementation resembles the
5764 * second-half of the e1000_resume routine.
5765 */
5766static void e1000_io_resume(struct pci_dev *pdev)
5767{
5768 struct net_device *netdev = pci_get_drvdata(pdev);
5769 struct e1000_adapter *adapter = netdev_priv(netdev);
5770
Bruce Allancd791612010-05-10 14:59:51 +00005771 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005772
5773 if (netif_running(netdev)) {
5774 if (e1000e_up(adapter)) {
5775 dev_err(&pdev->dev,
5776 "can't bring device back up after reset\n");
5777 return;
5778 }
5779 }
5780
5781 netif_device_attach(netdev);
5782
Bruce Allanad680762008-03-28 09:15:03 -07005783 /*
5784 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005785 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005786 * under the control of the driver.
5787 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005788 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005789 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005790
5791}
5792
5793static void e1000_print_device_info(struct e1000_adapter *adapter)
5794{
5795 struct e1000_hw *hw = &adapter->hw;
5796 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005797 u32 ret_val;
5798 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005799
5800 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005801 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005802 /* bus width */
5803 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5804 "Width x1"),
5805 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005806 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005807 e_info("Intel(R) PRO/%s Network Connection\n",
5808 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005809 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5810 E1000_PBANUM_LENGTH);
5811 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005812 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005813 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5814 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005815}
5816
Auke Kok10aa4c02008-08-04 17:21:20 -07005817static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5818{
5819 struct e1000_hw *hw = &adapter->hw;
5820 int ret_val;
5821 u16 buf = 0;
5822
5823 if (hw->mac.type != e1000_82573)
5824 return;
5825
5826 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005827 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005828 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005829 dev_warn(&adapter->pdev->dev,
5830 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005831 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005832}
5833
Stephen Hemminger651c2462008-11-19 21:57:48 -08005834static const struct net_device_ops e1000e_netdev_ops = {
5835 .ndo_open = e1000_open,
5836 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005837 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005838 .ndo_get_stats64 = e1000e_get_stats64,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005839 .ndo_set_multicast_list = e1000_set_multi,
5840 .ndo_set_mac_address = e1000_set_mac,
5841 .ndo_change_mtu = e1000_change_mtu,
5842 .ndo_do_ioctl = e1000_ioctl,
5843 .ndo_tx_timeout = e1000_tx_timeout,
5844 .ndo_validate_addr = eth_validate_addr,
5845
Stephen Hemminger651c2462008-11-19 21:57:48 -08005846 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5847 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5848#ifdef CONFIG_NET_POLL_CONTROLLER
5849 .ndo_poll_controller = e1000_netpoll,
5850#endif
5851};
5852
Auke Kokbc7f75f2007-09-17 12:30:59 -07005853/**
5854 * e1000_probe - Device Initialization Routine
5855 * @pdev: PCI device information struct
5856 * @ent: entry in e1000_pci_tbl
5857 *
5858 * Returns 0 on success, negative on failure
5859 *
5860 * e1000_probe initializes an adapter identified by a pci_dev structure.
5861 * The OS initialization, configuring of the adapter private structure,
5862 * and a hardware reset occur.
5863 **/
5864static int __devinit e1000_probe(struct pci_dev *pdev,
5865 const struct pci_device_id *ent)
5866{
5867 struct net_device *netdev;
5868 struct e1000_adapter *adapter;
5869 struct e1000_hw *hw;
5870 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005871 resource_size_t mmio_start, mmio_len;
5872 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005873
5874 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005875 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005876 int i, err, pci_using_dac;
5877 u16 eeprom_data = 0;
5878 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5879
Bruce Allan78cd29d2011-03-24 03:09:03 +00005880 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
5881 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005882 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005883 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5884 if (aspm_disable_flag)
5885 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005886
Bruce Allanf0f422e2008-08-04 17:21:53 -07005887 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005888 if (err)
5889 return err;
5890
5891 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005892 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005893 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005894 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005895 if (!err)
5896 pci_using_dac = 1;
5897 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005898 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005899 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005900 err = dma_set_coherent_mask(&pdev->dev,
5901 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005902 if (err) {
5903 dev_err(&pdev->dev, "No usable DMA "
5904 "configuration, aborting\n");
5905 goto err_dma;
5906 }
5907 }
5908 }
5909
Arjan van de Vene8de1482008-10-22 19:55:31 -07005910 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005911 pci_select_bars(pdev, IORESOURCE_MEM),
5912 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005913 if (err)
5914 goto err_pci_reg;
5915
Xiaotian Feng68eac462009-08-14 14:35:52 +00005916 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005917 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005918
Auke Kokbc7f75f2007-09-17 12:30:59 -07005919 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005920 /* PCI config space info */
5921 err = pci_save_state(pdev);
5922 if (err)
5923 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005924
5925 err = -ENOMEM;
5926 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5927 if (!netdev)
5928 goto err_alloc_etherdev;
5929
Auke Kokbc7f75f2007-09-17 12:30:59 -07005930 SET_NETDEV_DEV(netdev, &pdev->dev);
5931
Tom Herbertf85e4df2010-05-05 14:03:32 +00005932 netdev->irq = pdev->irq;
5933
Auke Kokbc7f75f2007-09-17 12:30:59 -07005934 pci_set_drvdata(pdev, netdev);
5935 adapter = netdev_priv(netdev);
5936 hw = &adapter->hw;
5937 adapter->netdev = netdev;
5938 adapter->pdev = pdev;
5939 adapter->ei = ei;
5940 adapter->pba = ei->pba;
5941 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005942 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005943 adapter->hw.adapter = adapter;
5944 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005945 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005946 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5947
5948 mmio_start = pci_resource_start(pdev, 0);
5949 mmio_len = pci_resource_len(pdev, 0);
5950
5951 err = -EIO;
5952 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5953 if (!adapter->hw.hw_addr)
5954 goto err_ioremap;
5955
5956 if ((adapter->flags & FLAG_HAS_FLASH) &&
5957 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5958 flash_start = pci_resource_start(pdev, 1);
5959 flash_len = pci_resource_len(pdev, 1);
5960 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5961 if (!adapter->hw.flash_address)
5962 goto err_flashmap;
5963 }
5964
5965 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005966 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005967 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005968 netdev->watchdog_timeo = 5 * HZ;
5969 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005970 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5971
5972 netdev->mem_start = mmio_start;
5973 netdev->mem_end = mmio_start + mmio_len;
5974
5975 adapter->bd_number = cards_found++;
5976
Bruce Allan4662e822008-08-26 18:37:06 -07005977 e1000e_check_options(adapter);
5978
Auke Kokbc7f75f2007-09-17 12:30:59 -07005979 /* setup adapter struct */
5980 err = e1000_sw_init(adapter);
5981 if (err)
5982 goto err_sw_init;
5983
Auke Kokbc7f75f2007-09-17 12:30:59 -07005984 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5985 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5986 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5987
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005988 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005989 if (err)
5990 goto err_hw_init;
5991
Bruce Allan4a770352008-10-01 17:18:35 -07005992 if ((adapter->flags & FLAG_IS_ICH) &&
5993 (adapter->flags & FLAG_READ_ONLY_NVM))
5994 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5995
Auke Kokbc7f75f2007-09-17 12:30:59 -07005996 hw->mac.ops.get_bus_info(&adapter->hw);
5997
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005998 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005999
6000 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006001 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006002 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6003 adapter->hw.phy.disable_polarity_correction = 0;
6004 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6005 }
6006
6007 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006008 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006009
6010 netdev->features = NETIF_F_SG |
6011 NETIF_F_HW_CSUM |
6012 NETIF_F_HW_VLAN_TX |
6013 NETIF_F_HW_VLAN_RX;
6014
6015 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6016 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6017
6018 netdev->features |= NETIF_F_TSO;
6019 netdev->features |= NETIF_F_TSO6;
6020
Jeff Kirshera5136e22008-06-05 04:07:28 -07006021 netdev->vlan_features |= NETIF_F_TSO;
6022 netdev->vlan_features |= NETIF_F_TSO6;
6023 netdev->vlan_features |= NETIF_F_HW_CSUM;
6024 netdev->vlan_features |= NETIF_F_SG;
6025
Yi Zou7b872a52010-09-22 17:57:58 +00006026 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006027 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006028 netdev->vlan_features |= NETIF_F_HIGHDMA;
6029 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006030
Auke Kokbc7f75f2007-09-17 12:30:59 -07006031 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6032 adapter->flags |= FLAG_MNG_PT_ENABLED;
6033
Bruce Allanad680762008-03-28 09:15:03 -07006034 /*
6035 * before reading the NVM, reset the controller to
6036 * put the device in a known good starting state
6037 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006038 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6039
6040 /*
6041 * systems with ASPM and others may see the checksum fail on the first
6042 * attempt. Let's give it a few tries
6043 */
6044 for (i = 0;; i++) {
6045 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6046 break;
6047 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006048 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006049 err = -EIO;
6050 goto err_eeprom;
6051 }
6052 }
6053
Auke Kok10aa4c02008-08-04 17:21:20 -07006054 e1000_eeprom_checks(adapter);
6055
Bruce Allan608f8a02010-01-13 02:04:58 +00006056 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006057 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006058 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006059
6060 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6061 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6062
6063 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006064 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006065 err = -EIO;
6066 goto err_eeprom;
6067 }
6068
6069 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006070 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006071 adapter->watchdog_timer.data = (unsigned long) adapter;
6072
6073 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006074 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006075 adapter->phy_info_timer.data = (unsigned long) adapter;
6076
6077 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6078 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006079 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6080 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006081 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006082
Auke Kokbc7f75f2007-09-17 12:30:59 -07006083 /* Initialize link parameters. User can change them with ethtool */
6084 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07006085 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006086 adapter->hw.fc.requested_mode = e1000_fc_default;
6087 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006088 adapter->hw.phy.autoneg_advertised = 0x2f;
6089
6090 /* ring size defaults */
6091 adapter->rx_ring->count = 256;
6092 adapter->tx_ring->count = 256;
6093
6094 /*
6095 * Initial Wake on LAN setting - If APM wake is enabled in
6096 * the EEPROM, enable the ACPI Magic Packet filter
6097 */
6098 if (adapter->flags & FLAG_APME_IN_WUC) {
6099 /* APME bit in EEPROM is mapped to WUC.APME */
6100 eeprom_data = er32(WUC);
6101 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006102 if ((hw->mac.type > e1000_ich10lan) &&
6103 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006104 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006105 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6106 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6107 (adapter->hw.bus.func == 1))
6108 e1000_read_nvm(&adapter->hw,
6109 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6110 else
6111 e1000_read_nvm(&adapter->hw,
6112 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6113 }
6114
6115 /* fetch WoL from EEPROM */
6116 if (eeprom_data & eeprom_apme_mask)
6117 adapter->eeprom_wol |= E1000_WUFC_MAG;
6118
6119 /*
6120 * now that we have the eeprom settings, apply the special cases
6121 * where the eeprom may be wrong or the board simply won't support
6122 * wake on lan on a particular port
6123 */
6124 if (!(adapter->flags & FLAG_HAS_WOL))
6125 adapter->eeprom_wol = 0;
6126
6127 /* initialize the wol settings based on the eeprom settings */
6128 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006129 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006130
Bruce Allan84527592008-11-21 17:00:22 -08006131 /* save off EEPROM version number */
6132 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6133
Auke Kokbc7f75f2007-09-17 12:30:59 -07006134 /* reset the hardware with the new settings */
6135 e1000e_reset(adapter);
6136
Bruce Allanad680762008-03-28 09:15:03 -07006137 /*
6138 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006139 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006140 * under the control of the driver.
6141 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006142 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006143 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006144
Bruce Allane0dc4f12011-01-06 14:29:50 +00006145 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006146 err = register_netdev(netdev);
6147 if (err)
6148 goto err_register;
6149
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006150 /* carrier off reporting is important to ethtool even BEFORE open */
6151 netif_carrier_off(netdev);
6152
Auke Kokbc7f75f2007-09-17 12:30:59 -07006153 e1000_print_device_info(adapter);
6154
Alan Sternf3ec4f82010-06-08 15:23:51 -04006155 if (pci_dev_run_wake(pdev))
6156 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006157
Auke Kokbc7f75f2007-09-17 12:30:59 -07006158 return 0;
6159
6160err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006161 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006162 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006163err_eeprom:
6164 if (!e1000_check_reset_block(&adapter->hw))
6165 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006166err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006167 kfree(adapter->tx_ring);
6168 kfree(adapter->rx_ring);
6169err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006170 if (adapter->hw.flash_address)
6171 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006172 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006173err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006174 iounmap(adapter->hw.hw_addr);
6175err_ioremap:
6176 free_netdev(netdev);
6177err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006178 pci_release_selected_regions(pdev,
6179 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006180err_pci_reg:
6181err_dma:
6182 pci_disable_device(pdev);
6183 return err;
6184}
6185
6186/**
6187 * e1000_remove - Device Removal Routine
6188 * @pdev: PCI device information struct
6189 *
6190 * e1000_remove is called by the PCI subsystem to alert the driver
6191 * that it should release a PCI device. The could be caused by a
6192 * Hot-Plug event, or because the driver is going to be removed from
6193 * memory.
6194 **/
6195static void __devexit e1000_remove(struct pci_dev *pdev)
6196{
6197 struct net_device *netdev = pci_get_drvdata(pdev);
6198 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006199 bool down = test_bit(__E1000_DOWN, &adapter->state);
6200
Bruce Allanad680762008-03-28 09:15:03 -07006201 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006202 * The timers may be rescheduled, so explicitly disable them
6203 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006204 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006205 if (!down)
6206 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006207 del_timer_sync(&adapter->watchdog_timer);
6208 del_timer_sync(&adapter->phy_info_timer);
6209
Bruce Allan41cec6f2009-11-20 23:28:56 +00006210 cancel_work_sync(&adapter->reset_task);
6211 cancel_work_sync(&adapter->watchdog_task);
6212 cancel_work_sync(&adapter->downshift_task);
6213 cancel_work_sync(&adapter->update_phy_task);
6214 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006215
Bruce Allan17f208d2009-12-01 15:47:22 +00006216 if (!(netdev->flags & IFF_UP))
6217 e1000_power_down_phy(adapter);
6218
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006219 /* Don't lie to e1000_close() down the road. */
6220 if (!down)
6221 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006222 unregister_netdev(netdev);
6223
Alan Sternf3ec4f82010-06-08 15:23:51 -04006224 if (pci_dev_run_wake(pdev))
6225 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006226
Bruce Allanad680762008-03-28 09:15:03 -07006227 /*
6228 * Release control of h/w to f/w. If f/w is AMT enabled, this
6229 * would have already happened in close and is redundant.
6230 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006231 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006232
Bruce Allan4662e822008-08-26 18:37:06 -07006233 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006234 kfree(adapter->tx_ring);
6235 kfree(adapter->rx_ring);
6236
6237 iounmap(adapter->hw.hw_addr);
6238 if (adapter->hw.flash_address)
6239 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006240 pci_release_selected_regions(pdev,
6241 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006242
6243 free_netdev(netdev);
6244
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006245 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006246 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006247
Auke Kokbc7f75f2007-09-17 12:30:59 -07006248 pci_disable_device(pdev);
6249}
6250
6251/* PCI Error Recovery (ERS) */
6252static struct pci_error_handlers e1000_err_handler = {
6253 .error_detected = e1000_io_error_detected,
6254 .slot_reset = e1000_io_slot_reset,
6255 .resume = e1000_io_resume,
6256};
6257
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006258static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006259 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6260 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6261 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6262 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6263 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6264 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006265 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6266 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6267 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006268
Auke Kokbc7f75f2007-09-17 12:30:59 -07006269 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6270 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6271 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6272 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006273
Auke Kokbc7f75f2007-09-17 12:30:59 -07006274 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6275 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6276 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006277
Bruce Allan4662e822008-08-26 18:37:06 -07006278 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006279 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006280 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006281
Auke Kokbc7f75f2007-09-17 12:30:59 -07006282 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6283 board_80003es2lan },
6284 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6285 board_80003es2lan },
6286 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6287 board_80003es2lan },
6288 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6289 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006290
Auke Kokbc7f75f2007-09-17 12:30:59 -07006291 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6292 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6293 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6294 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6295 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6296 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6297 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006298 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006299
Auke Kokbc7f75f2007-09-17 12:30:59 -07006300 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6301 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6302 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6303 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6304 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006305 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006306 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6307 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6308 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6309
6310 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6311 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6312 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006313
Bruce Allanf4187b52008-08-26 18:36:50 -07006314 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6315 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006316 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006317
Bruce Allana4f58f52009-06-02 11:29:18 +00006318 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6319 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6320 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6321 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6322
Bruce Alland3738bb2010-06-16 13:27:28 +00006323 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6324 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6325
Auke Kokbc7f75f2007-09-17 12:30:59 -07006326 { } /* terminate list */
6327};
6328MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6329
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006330#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006331static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006332 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6333 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6334 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006335};
David S. Millere50208a2010-03-16 23:36:24 -07006336#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006337
Auke Kokbc7f75f2007-09-17 12:30:59 -07006338/* PCI Device API Driver */
6339static struct pci_driver e1000_driver = {
6340 .name = e1000e_driver_name,
6341 .id_table = e1000_pci_tbl,
6342 .probe = e1000_probe,
6343 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006344#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006345 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006346#endif
6347 .shutdown = e1000_shutdown,
6348 .err_handler = &e1000_err_handler
6349};
6350
6351/**
6352 * e1000_init_module - Driver Registration Routine
6353 *
6354 * e1000_init_module is the first routine called when the driver is
6355 * loaded. All it does is register with the PCI subsystem.
6356 **/
6357static int __init e1000_init_module(void)
6358{
6359 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006360 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6361 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006362 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006363 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006364
Auke Kokbc7f75f2007-09-17 12:30:59 -07006365 return ret;
6366}
6367module_init(e1000_init_module);
6368
6369/**
6370 * e1000_exit_module - Driver Exit Cleanup Routine
6371 *
6372 * e1000_exit_module is called just before the driver is removed
6373 * from memory.
6374 **/
6375static void __exit e1000_exit_module(void)
6376{
6377 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006378}
6379module_exit(e1000_exit_module);
6380
6381
6382MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6383MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6384MODULE_LICENSE("GPL");
6385MODULE_VERSION(DRV_VERSION);
6386
6387/* e1000_main.c */