blob: c0e211b500cf307bf102dc83d67fa477fb672707 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanf5e261e2012-01-01 16:00:03 +00004 Copyright(c) 1999 - 2012 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>
Linus Torvalds7e0bb712011-10-25 15:18:39 +020050#include <linux/pm_qos.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 Allanfad59b02012-03-20 03:48:29 +000059#define DRV_VERSION "1.10.6" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070060char e1000e_driver_name[] = "e1000e";
61const char e1000e_driver_version[] = DRV_VERSION;
62
stephen hemmingerb3f4d592012-03-13 06:04:20 +000063#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
64static int debug = -1;
65module_param(debug, int, 0);
66MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
67
Bruce Allan78cd29d2011-03-24 03:09:03 +000068static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
69
Auke Kokbc7f75f2007-09-17 12:30:59 -070070static const struct e1000_info *e1000_info_tbl[] = {
71 [board_82571] = &e1000_82571_info,
72 [board_82572] = &e1000_82572_info,
73 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070074 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000075 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070076 [board_80003es2lan] = &e1000_es2_info,
77 [board_ich8lan] = &e1000_ich8_info,
78 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070079 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000080 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000081 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070082};
83
Taku Izumi84f4ee92010-04-27 14:39:08 +000084struct e1000_reg_info {
85 u32 ofs;
86 char *name;
87};
88
Bruce Allanaf667a22010-12-31 06:10:01 +000089#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
90#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
91#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
92#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
93#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000094
Bruce Allanaf667a22010-12-31 06:10:01 +000095#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
96#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
97#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
98#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
99#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000100
101static const struct e1000_reg_info e1000_reg_info_tbl[] = {
102
103 /* General Registers */
104 {E1000_CTRL, "CTRL"},
105 {E1000_STATUS, "STATUS"},
106 {E1000_CTRL_EXT, "CTRL_EXT"},
107
108 /* Interrupt Registers */
109 {E1000_ICR, "ICR"},
110
Bruce Allanaf667a22010-12-31 06:10:01 +0000111 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000112 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000113 {E1000_RDLEN(0), "RDLEN"},
114 {E1000_RDH(0), "RDH"},
115 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000116 {E1000_RDTR, "RDTR"},
117 {E1000_RXDCTL(0), "RXDCTL"},
118 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +0000119 {E1000_RDBAL(0), "RDBAL"},
120 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000121 {E1000_RDFH, "RDFH"},
122 {E1000_RDFT, "RDFT"},
123 {E1000_RDFHS, "RDFHS"},
124 {E1000_RDFTS, "RDFTS"},
125 {E1000_RDFPC, "RDFPC"},
126
Bruce Allanaf667a22010-12-31 06:10:01 +0000127 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000128 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000129 {E1000_TDBAL(0), "TDBAL"},
130 {E1000_TDBAH(0), "TDBAH"},
131 {E1000_TDLEN(0), "TDLEN"},
132 {E1000_TDH(0), "TDH"},
133 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000134 {E1000_TIDV, "TIDV"},
135 {E1000_TXDCTL(0), "TXDCTL"},
136 {E1000_TADV, "TADV"},
137 {E1000_TARC(0), "TARC"},
138 {E1000_TDFH, "TDFH"},
139 {E1000_TDFT, "TDFT"},
140 {E1000_TDFHS, "TDFHS"},
141 {E1000_TDFTS, "TDFTS"},
142 {E1000_TDFPC, "TDFPC"},
143
144 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000145 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000146};
147
148/*
149 * e1000_regdump - register printout routine
150 */
151static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
152{
153 int n = 0;
154 char rname[16];
155 u32 regs[8];
156
157 switch (reginfo->ofs) {
158 case E1000_RXDCTL(0):
159 for (n = 0; n < 2; n++)
160 regs[n] = __er32(hw, E1000_RXDCTL(n));
161 break;
162 case E1000_TXDCTL(0):
163 for (n = 0; n < 2; n++)
164 regs[n] = __er32(hw, E1000_TXDCTL(n));
165 break;
166 case E1000_TARC(0):
167 for (n = 0; n < 2; n++)
168 regs[n] = __er32(hw, E1000_TARC(n));
169 break;
170 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000171 pr_info("%-15s %08x\n",
172 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000173 return;
174 }
175
176 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000177 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000178}
179
Taku Izumi84f4ee92010-04-27 14:39:08 +0000180/*
Bruce Allanaf667a22010-12-31 06:10:01 +0000181 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Taku Izumi84f4ee92010-04-27 14:39:08 +0000182 */
183static void e1000e_dump(struct e1000_adapter *adapter)
184{
185 struct net_device *netdev = adapter->netdev;
186 struct e1000_hw *hw = &adapter->hw;
187 struct e1000_reg_info *reginfo;
188 struct e1000_ring *tx_ring = adapter->tx_ring;
189 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000190 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000191 __le64 a;
192 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000193 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000194 struct e1000_buffer *buffer_info;
195 struct e1000_ring *rx_ring = adapter->rx_ring;
196 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000197 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000198 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000199 __le64 a;
200 __le64 b;
201 __le64 c;
202 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000203 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000204 u32 staterr;
205 int i = 0;
206
207 if (!netif_msg_hw(adapter))
208 return;
209
210 /* Print netdevice Info */
211 if (netdev) {
212 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000213 pr_info("Device Name state trans_start last_rx\n");
214 pr_info("%-15s %016lX %016lX %016lX\n",
215 netdev->name, netdev->state, netdev->trans_start,
216 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000217 }
218
219 /* Print Registers */
220 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000221 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000222 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
223 reginfo->name; reginfo++) {
224 e1000_regdump(hw, reginfo);
225 }
226
Bruce Allanaf667a22010-12-31 06:10:01 +0000227 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000228 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000229 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000230
Bruce Allanaf667a22010-12-31 06:10:01 +0000231 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000232 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000233 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000234 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
235 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 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000274 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
275 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
276 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000277 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000278 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000279 tx_desc = E1000_TX_DESC(*tx_ring, i);
280 buffer_info = &tx_ring->buffer_info[i];
281 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000282 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000283 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000284 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000285 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000286 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000287 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000288 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000289 next_desc = "";
290 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
291 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
292 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
293 i,
294 (unsigned long long)le64_to_cpu(u0->a),
295 (unsigned long long)le64_to_cpu(u0->b),
296 (unsigned long long)buffer_info->dma,
297 buffer_info->length, buffer_info->next_to_watch,
298 (unsigned long long)buffer_info->time_stamp,
299 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000300
301 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
302 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Bruce Allanaf667a22010-12-31 06:10:01 +0000303 16, 1, phys_to_virt(buffer_info->dma),
304 buffer_info->length, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000305 }
306
Bruce Allanaf667a22010-12-31 06:10:01 +0000307 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000308rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000309 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000310 pr_info("Queue [NTU] [NTC]\n");
311 pr_info(" %5d %5X %5X\n",
312 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000313
Bruce Allanaf667a22010-12-31 06:10:01 +0000314 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000315 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000316 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000317
Bruce Allanaf667a22010-12-31 06:10:01 +0000318 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000319 switch (adapter->rx_ps_pages) {
320 case 1:
321 case 2:
322 case 3:
323 /* [Extended] Packet Split Receive Descriptor Format
324 *
325 * +-----------------------------------------------------+
326 * 0 | Buffer Address 0 [63:0] |
327 * +-----------------------------------------------------+
328 * 8 | Buffer Address 1 [63:0] |
329 * +-----------------------------------------------------+
330 * 16 | Buffer Address 2 [63:0] |
331 * +-----------------------------------------------------+
332 * 24 | Buffer Address 3 [63:0] |
333 * +-----------------------------------------------------+
334 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000335 pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000336 /* [Extended] Receive Descriptor (Write-Back) Format
337 *
338 * 63 48 47 32 31 13 12 8 7 4 3 0
339 * +------------------------------------------------------+
340 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
341 * | Checksum | Ident | | Queue | | Type |
342 * +------------------------------------------------------+
343 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
344 * +------------------------------------------------------+
345 * 63 48 47 32 31 20 19 0
346 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000347 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000348 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000349 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000350 buffer_info = &rx_ring->buffer_info[i];
351 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
352 u1 = (struct my_u1 *)rx_desc_ps;
353 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000354 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000355
356 if (i == rx_ring->next_to_use)
357 next_desc = " NTU";
358 else if (i == rx_ring->next_to_clean)
359 next_desc = " NTC";
360 else
361 next_desc = "";
362
Taku Izumi84f4ee92010-04-27 14:39:08 +0000363 if (staterr & E1000_RXD_STAT_DD) {
364 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000365 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
366 "RWB", i,
367 (unsigned long long)le64_to_cpu(u1->a),
368 (unsigned long long)le64_to_cpu(u1->b),
369 (unsigned long long)le64_to_cpu(u1->c),
370 (unsigned long long)le64_to_cpu(u1->d),
371 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000372 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000373 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
374 "R ", i,
375 (unsigned long long)le64_to_cpu(u1->a),
376 (unsigned long long)le64_to_cpu(u1->b),
377 (unsigned long long)le64_to_cpu(u1->c),
378 (unsigned long long)le64_to_cpu(u1->d),
379 (unsigned long long)buffer_info->dma,
380 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000381
382 if (netif_msg_pktdata(adapter))
383 print_hex_dump(KERN_INFO, "",
384 DUMP_PREFIX_ADDRESS, 16, 1,
385 phys_to_virt(buffer_info->dma),
386 adapter->rx_ps_bsize0, true);
387 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000388 }
389 break;
390 default:
391 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000392 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000393 *
Bruce Allan5f450212011-07-22 06:21:46 +0000394 * +-----------------------------------------------------+
395 * 0 | Buffer Address [63:0] |
396 * +-----------------------------------------------------+
397 * 8 | Reserved |
398 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000399 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000400 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000401 /* Extended Receive Descriptor (Write-Back) Format
402 *
403 * 63 48 47 32 31 24 23 4 3 0
404 * +------------------------------------------------------+
405 * | RSS Hash | | | |
406 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
407 * | Packet | IP | | | Type |
408 * | Checksum | Ident | | | |
409 * +------------------------------------------------------+
410 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
411 * +------------------------------------------------------+
412 * 63 48 47 32 31 20 19 0
413 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000414 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000415
416 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000417 const char *next_desc;
418
Taku Izumi84f4ee92010-04-27 14:39:08 +0000419 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000420 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
421 u1 = (struct my_u1 *)rx_desc;
422 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000423
424 if (i == rx_ring->next_to_use)
425 next_desc = " NTU";
426 else if (i == rx_ring->next_to_clean)
427 next_desc = " NTC";
428 else
429 next_desc = "";
430
Bruce Allan5f450212011-07-22 06:21:46 +0000431 if (staterr & E1000_RXD_STAT_DD) {
432 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000433 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
434 "RWB", i,
435 (unsigned long long)le64_to_cpu(u1->a),
436 (unsigned long long)le64_to_cpu(u1->b),
437 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000438 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000439 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
440 "R ", i,
441 (unsigned long long)le64_to_cpu(u1->a),
442 (unsigned long long)le64_to_cpu(u1->b),
443 (unsigned long long)buffer_info->dma,
444 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000445
446 if (netif_msg_pktdata(adapter))
447 print_hex_dump(KERN_INFO, "",
448 DUMP_PREFIX_ADDRESS, 16,
449 1,
450 phys_to_virt
451 (buffer_info->dma),
452 adapter->rx_buffer_len,
453 true);
454 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000455 }
456 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000457}
458
Auke Kokbc7f75f2007-09-17 12:30:59 -0700459/**
460 * e1000_desc_unused - calculate if we have unused descriptors
461 **/
462static int e1000_desc_unused(struct e1000_ring *ring)
463{
464 if (ring->next_to_clean > ring->next_to_use)
465 return ring->next_to_clean - ring->next_to_use - 1;
466
467 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
468}
469
470/**
Bruce Allanad680762008-03-28 09:15:03 -0700471 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700472 * @adapter: board private structure
473 * @status: descriptor status field as written by hardware
474 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
475 * @skb: pointer to sk_buff to be indicated to stack
476 **/
477static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000478 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000479 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700480{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000481 u16 tag = le16_to_cpu(vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700482 skb->protocol = eth_type_trans(skb, netdev);
483
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000484 if (status & E1000_RXD_STAT_VP)
485 __vlan_hwaccel_put_tag(skb, tag);
486
487 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700488}
489
490/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000491 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000492 * @adapter: board private structure
493 * @status_err: receive descriptor status and error fields
494 * @csum: receive descriptor csum field
495 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700496 **/
497static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allanafd12932012-01-05 00:34:05 +0000498 __le16 csum, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700499{
500 u16 status = (u16)status_err;
501 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700502
503 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700504
Bruce Allanafd12932012-01-05 00:34:05 +0000505 /* Rx checksum disabled */
506 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
507 return;
508
Auke Kokbc7f75f2007-09-17 12:30:59 -0700509 /* Ignore Checksum bit is set */
510 if (status & E1000_RXD_STAT_IXSM)
511 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000512
Auke Kokbc7f75f2007-09-17 12:30:59 -0700513 /* TCP/UDP checksum error bit is set */
514 if (errors & E1000_RXD_ERR_TCPE) {
515 /* let the stack verify checksum errors */
516 adapter->hw_csum_err++;
517 return;
518 }
519
520 /* TCP/UDP Checksum has not been calculated */
521 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
522 return;
523
524 /* It must be a TCP or UDP packet with a valid checksum */
525 if (status & E1000_RXD_STAT_TCPCS) {
526 /* TCP checksum is good */
527 skb->ip_summed = CHECKSUM_UNNECESSARY;
528 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700529 /*
530 * IP fragment with UDP payload
531 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532 * and then put the value in host order for further stack use.
533 */
Bruce Allanafd12932012-01-05 00:34:05 +0000534 __sum16 sum = (__force __sum16)swab16((__force u16)csum);
Al Viroa39fe742007-12-11 19:50:34 +0000535 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700536 skb->ip_summed = CHECKSUM_COMPLETE;
537 }
538 adapter->hw_csum_good++;
539}
540
Bruce Allan55aa6982011-12-16 00:45:45 +0000541static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700542{
Bruce Allan55aa6982011-12-16 00:45:45 +0000543 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700544 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000545 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700546
Bruce Allanbdc125f2012-03-20 03:47:52 +0000547 writel(i, rx_ring->tail);
548
549 if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700550 u32 rctl = er32(RCTL);
551 ew32(RCTL, rctl & ~E1000_RCTL_EN);
552 e_err("ME firmware caused invalid RDT - resetting\n");
553 schedule_work(&adapter->reset_task);
554 }
555}
556
Bruce Allan55aa6982011-12-16 00:45:45 +0000557static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700558{
Bruce Allan55aa6982011-12-16 00:45:45 +0000559 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700560 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000561 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700562
Bruce Allanbdc125f2012-03-20 03:47:52 +0000563 writel(i, tx_ring->tail);
564
565 if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700566 u32 tctl = er32(TCTL);
567 ew32(TCTL, tctl & ~E1000_TCTL_EN);
568 e_err("ME firmware caused invalid TDT - resetting\n");
569 schedule_work(&adapter->reset_task);
570 }
571}
572
573/**
Bruce Allan5f450212011-07-22 06:21:46 +0000574 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000575 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700576 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000577static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000578 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700579{
Bruce Allan55aa6982011-12-16 00:45:45 +0000580 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700581 struct net_device *netdev = adapter->netdev;
582 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000583 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700584 struct e1000_buffer *buffer_info;
585 struct sk_buff *skb;
586 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000587 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700588
589 i = rx_ring->next_to_use;
590 buffer_info = &rx_ring->buffer_info[i];
591
592 while (cleaned_count--) {
593 skb = buffer_info->skb;
594 if (skb) {
595 skb_trim(skb, 0);
596 goto map_skb;
597 }
598
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000599 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700600 if (!skb) {
601 /* Better luck next round */
602 adapter->alloc_rx_buff_failed++;
603 break;
604 }
605
Auke Kokbc7f75f2007-09-17 12:30:59 -0700606 buffer_info->skb = skb;
607map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000608 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700609 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000610 DMA_FROM_DEVICE);
611 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000612 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613 adapter->rx_dma_failed++;
614 break;
615 }
616
Bruce Allan5f450212011-07-22 06:21:46 +0000617 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
618 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700619
Tom Herbert50849d72010-05-05 14:02:49 +0000620 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
621 /*
622 * Force memory writes to complete before letting h/w
623 * know there are new descriptors to fetch. (Only
624 * applicable for weak-ordered memory model archs,
625 * such as IA-64).
626 */
627 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700628 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000629 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700630 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000631 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000632 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700633 i++;
634 if (i == rx_ring->count)
635 i = 0;
636 buffer_info = &rx_ring->buffer_info[i];
637 }
638
Tom Herbert50849d72010-05-05 14:02:49 +0000639 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640}
641
642/**
643 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000644 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700645 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000646static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000647 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648{
Bruce Allan55aa6982011-12-16 00:45:45 +0000649 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700650 struct net_device *netdev = adapter->netdev;
651 struct pci_dev *pdev = adapter->pdev;
652 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700653 struct e1000_buffer *buffer_info;
654 struct e1000_ps_page *ps_page;
655 struct sk_buff *skb;
656 unsigned int i, j;
657
658 i = rx_ring->next_to_use;
659 buffer_info = &rx_ring->buffer_info[i];
660
661 while (cleaned_count--) {
662 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
663
664 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700665 ps_page = &buffer_info->ps_pages[j];
666 if (j >= adapter->rx_ps_pages) {
667 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000668 rx_desc->read.buffer_addr[j + 1] =
669 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700670 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700671 }
Auke Kok47f44e42007-10-25 13:57:44 -0700672 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000673 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700674 if (!ps_page->page) {
675 adapter->alloc_rx_buff_failed++;
676 goto no_buffers;
677 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000678 ps_page->dma = dma_map_page(&pdev->dev,
679 ps_page->page,
680 0, PAGE_SIZE,
681 DMA_FROM_DEVICE);
682 if (dma_mapping_error(&pdev->dev,
683 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700684 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000685 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700686 adapter->rx_dma_failed++;
687 goto no_buffers;
688 }
689 }
690 /*
691 * Refresh the desc even if buffer_addrs
692 * didn't change because each write-back
693 * erases this info.
694 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000695 rx_desc->read.buffer_addr[j + 1] =
696 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700697 }
698
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000699 skb = __netdev_alloc_skb_ip_align(netdev,
700 adapter->rx_ps_bsize0,
701 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700702
703 if (!skb) {
704 adapter->alloc_rx_buff_failed++;
705 break;
706 }
707
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000709 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700710 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000711 DMA_FROM_DEVICE);
712 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000713 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700714 adapter->rx_dma_failed++;
715 /* cleanup skb */
716 dev_kfree_skb_any(skb);
717 buffer_info->skb = NULL;
718 break;
719 }
720
721 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
722
Tom Herbert50849d72010-05-05 14:02:49 +0000723 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
724 /*
725 * Force memory writes to complete before letting h/w
726 * know there are new descriptors to fetch. (Only
727 * applicable for weak-ordered memory model archs,
728 * such as IA-64).
729 */
730 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700731 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000732 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700733 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000734 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000735 }
736
Auke Kokbc7f75f2007-09-17 12:30:59 -0700737 i++;
738 if (i == rx_ring->count)
739 i = 0;
740 buffer_info = &rx_ring->buffer_info[i];
741 }
742
743no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000744 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700745}
746
747/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700748 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000749 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700750 * @cleaned_count: number of buffers to allocate this pass
751 **/
752
Bruce Allan55aa6982011-12-16 00:45:45 +0000753static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000754 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700755{
Bruce Allan55aa6982011-12-16 00:45:45 +0000756 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700757 struct net_device *netdev = adapter->netdev;
758 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000759 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700760 struct e1000_buffer *buffer_info;
761 struct sk_buff *skb;
762 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000763 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700764
765 i = rx_ring->next_to_use;
766 buffer_info = &rx_ring->buffer_info[i];
767
768 while (cleaned_count--) {
769 skb = buffer_info->skb;
770 if (skb) {
771 skb_trim(skb, 0);
772 goto check_page;
773 }
774
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000775 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700776 if (unlikely(!skb)) {
777 /* Better luck next round */
778 adapter->alloc_rx_buff_failed++;
779 break;
780 }
781
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700782 buffer_info->skb = skb;
783check_page:
784 /* allocate a new page if necessary */
785 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000786 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700787 if (unlikely(!buffer_info->page)) {
788 adapter->alloc_rx_buff_failed++;
789 break;
790 }
791 }
792
793 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000794 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700795 buffer_info->page, 0,
796 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000797 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700798
Bruce Allan5f450212011-07-22 06:21:46 +0000799 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
800 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700801
802 if (unlikely(++i == rx_ring->count))
803 i = 0;
804 buffer_info = &rx_ring->buffer_info[i];
805 }
806
807 if (likely(rx_ring->next_to_use != i)) {
808 rx_ring->next_to_use = i;
809 if (unlikely(i-- == 0))
810 i = (rx_ring->count - 1);
811
812 /* Force memory writes to complete before letting h/w
813 * know there are new descriptors to fetch. (Only
814 * applicable for weak-ordered memory model archs,
815 * such as IA-64). */
816 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700817 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000818 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700819 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000820 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700821 }
822}
823
Bruce Allan70495a52012-01-11 01:26:50 +0000824static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
825 struct sk_buff *skb)
826{
827 if (netdev->features & NETIF_F_RXHASH)
828 skb->rxhash = le32_to_cpu(rss);
829}
830
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700831/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000832 * e1000_clean_rx_irq - Send received data up the network stack
833 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700834 *
835 * the return value indicates whether actual cleaning was done, there
836 * is no guarantee that everything was cleaned
837 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000838static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
839 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700840{
Bruce Allan55aa6982011-12-16 00:45:45 +0000841 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700842 struct net_device *netdev = adapter->netdev;
843 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000844 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000845 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700846 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000847 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700848 unsigned int i;
849 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000850 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700851 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
852
853 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000854 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
855 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700856 buffer_info = &rx_ring->buffer_info[i];
857
Bruce Allan5f450212011-07-22 06:21:46 +0000858 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700859 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860
861 if (*work_done >= work_to_do)
862 break;
863 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000864 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700865
Auke Kokbc7f75f2007-09-17 12:30:59 -0700866 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;
Bruce Allan5f450212011-07-22 06:21:46 +0000874 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700875 prefetch(next_rxd);
876
877 next_buffer = &rx_ring->buffer_info[i];
878
Rusty Russell3db1cd52011-12-19 13:56:45 +0000879 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700880 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
Bruce Allan5f450212011-07-22 06:21:46 +0000887 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700888
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 */
Bruce Allan5f450212011-07-22 06:21:46 +0000896 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000897 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;
Bruce Allan5f450212011-07-22 06:21:46 +0000904 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000905 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700906 goto next_desc;
907 }
908
Ben Greearcf955e62012-02-11 15:39:51 +0000909 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
910 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700911 /* recycle */
912 buffer_info->skb = skb;
913 goto next_desc;
914 }
915
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000916 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000917 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
918 /* If configured to store CRC, don't subtract FCS,
919 * but keep the FCS bytes out of the total_rx_bytes
920 * counter
921 */
922 if (netdev->features & NETIF_F_RXFCS)
923 total_rx_bytes -= 4;
924 else
925 length -= 4;
926 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000927
Auke Kokbc7f75f2007-09-17 12:30:59 -0700928 total_rx_bytes += length;
929 total_rx_packets++;
930
Bruce Allanad680762008-03-28 09:15:03 -0700931 /*
932 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700934 * of reassembly being done in the stack
935 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700936 if (length < copybreak) {
937 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000938 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700940 skb_copy_to_linear_data_offset(new_skb,
941 -NET_IP_ALIGN,
942 (skb->data -
943 NET_IP_ALIGN),
944 (length +
945 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700946 /* save the skb in buffer_info as good */
947 buffer_info->skb = skb;
948 skb = new_skb;
949 }
950 /* else just continue with the old one */
951 }
952 /* end copybreak code */
953 skb_put(skb, length);
954
955 /* Receive Checksum Offload */
Bruce Allan5f450212011-07-22 06:21:46 +0000956 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +0000957 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700958
Bruce Allan70495a52012-01-11 01:26:50 +0000959 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
960
Bruce Allan5f450212011-07-22 06:21:46 +0000961 e1000_receive_skb(adapter, netdev, skb, staterr,
962 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700963
964next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +0000965 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700966
967 /* return some buffers to hardware, one at a time is too slow */
968 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +0000969 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000970 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700971 cleaned_count = 0;
972 }
973
974 /* use prefetched values */
975 rx_desc = next_rxd;
976 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000977
978 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700979 }
980 rx_ring->next_to_clean = i;
981
982 cleaned_count = e1000_desc_unused(rx_ring);
983 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +0000984 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700985
Auke Kokbc7f75f2007-09-17 12:30:59 -0700986 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700987 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988 return cleaned;
989}
990
Bruce Allan55aa6982011-12-16 00:45:45 +0000991static void e1000_put_txbuf(struct e1000_ring *tx_ring,
992 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700993{
Bruce Allan55aa6982011-12-16 00:45:45 +0000994 struct e1000_adapter *adapter = tx_ring->adapter;
995
Alexander Duyck03b13202009-12-02 16:45:31 +0000996 if (buffer_info->dma) {
997 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +0000998 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
999 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001000 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001001 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1002 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001003 buffer_info->dma = 0;
1004 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005 if (buffer_info->skb) {
1006 dev_kfree_skb_any(buffer_info->skb);
1007 buffer_info->skb = NULL;
1008 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001009 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010}
1011
Bruce Allan41cec6f2009-11-20 23:28:56 +00001012static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001013{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001014 struct e1000_adapter *adapter = container_of(work,
1015 struct e1000_adapter,
1016 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001017 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001018 struct e1000_ring *tx_ring = adapter->tx_ring;
1019 unsigned int i = tx_ring->next_to_clean;
1020 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1021 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001022 struct e1000_hw *hw = &adapter->hw;
1023 u16 phy_status, phy_1000t_status, phy_ext_status;
1024 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001025
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001026 if (test_bit(__E1000_DOWN, &adapter->state))
1027 return;
1028
Jeff Kirsher09357b02011-11-18 14:25:00 +00001029 if (!adapter->tx_hang_recheck &&
1030 (adapter->flags2 & FLAG2_DMA_BURST)) {
Matthew Vick397c0202012-03-16 09:03:01 +00001031 /*
1032 * May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001033 * flush pending descriptor writebacks to memory
1034 */
1035 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1036 /* execute the writes immediately */
1037 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00001038 /*
1039 * Due to rare timing issues, write to TIDV again to ensure
1040 * the write is successful
1041 */
1042 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1043 /* execute the writes immediately */
1044 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001045 adapter->tx_hang_recheck = true;
1046 return;
1047 }
1048 /* Real hang detected */
1049 adapter->tx_hang_recheck = false;
1050 netif_stop_queue(netdev);
1051
Bruce Allan41cec6f2009-11-20 23:28:56 +00001052 e1e_rphy(hw, PHY_STATUS, &phy_status);
1053 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1054 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1055
1056 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1057
1058 /* detected Hardware unit hang */
1059 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001060 " TDH <%x>\n"
1061 " TDT <%x>\n"
1062 " next_to_use <%x>\n"
1063 " next_to_clean <%x>\n"
1064 "buffer_info[next_to_clean]:\n"
1065 " time_stamp <%lx>\n"
1066 " next_to_watch <%x>\n"
1067 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001068 " next_to_watch.status <%x>\n"
1069 "MAC Status <%x>\n"
1070 "PHY Status <%x>\n"
1071 "PHY 1000BASE-T Status <%x>\n"
1072 "PHY Extended Status <%x>\n"
1073 "PCI Status <%x>\n",
Bruce Allanc5083cf2011-12-16 00:45:40 +00001074 readl(tx_ring->head),
1075 readl(tx_ring->tail),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001076 tx_ring->next_to_use,
1077 tx_ring->next_to_clean,
1078 tx_ring->buffer_info[eop].time_stamp,
1079 eop,
1080 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001081 eop_desc->upper.fields.status,
1082 er32(STATUS),
1083 phy_status,
1084 phy_1000t_status,
1085 phy_ext_status,
1086 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001087}
1088
1089/**
1090 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001091 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001092 *
1093 * the return value indicates whether actual cleaning was done, there
1094 * is no guarantee that everything was cleaned
1095 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001096static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097{
Bruce Allan55aa6982011-12-16 00:45:45 +00001098 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099 struct net_device *netdev = adapter->netdev;
1100 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001101 struct e1000_tx_desc *tx_desc, *eop_desc;
1102 struct e1000_buffer *buffer_info;
1103 unsigned int i, eop;
1104 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001105 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001106 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001107
1108 i = tx_ring->next_to_clean;
1109 eop = tx_ring->buffer_info[i].next_to_watch;
1110 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1111
Alexander Duyck12d04a32009-03-25 22:05:03 +00001112 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1113 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001114 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001115 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001116 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001117 tx_desc = E1000_TX_DESC(*tx_ring, i);
1118 buffer_info = &tx_ring->buffer_info[i];
1119 cleaned = (i == eop);
1120
1121 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001122 total_tx_packets += buffer_info->segs;
1123 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001124 if (buffer_info->skb) {
1125 bytes_compl += buffer_info->skb->len;
1126 pkts_compl++;
1127 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128 }
1129
Bruce Allan55aa6982011-12-16 00:45:45 +00001130 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001131 tx_desc->upper.data = 0;
1132
1133 i++;
1134 if (i == tx_ring->count)
1135 i = 0;
1136 }
1137
Terry Loftindac87612010-04-09 10:29:49 +00001138 if (i == tx_ring->next_to_use)
1139 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140 eop = tx_ring->buffer_info[i].next_to_watch;
1141 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001142 }
1143
1144 tx_ring->next_to_clean = i;
1145
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001146 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1147
Auke Kokbc7f75f2007-09-17 12:30:59 -07001148#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001149 if (count && netif_carrier_ok(netdev) &&
1150 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001151 /* Make sure that anybody stopping the queue after this
1152 * sees the new next_to_clean.
1153 */
1154 smp_mb();
1155
1156 if (netif_queue_stopped(netdev) &&
1157 !(test_bit(__E1000_DOWN, &adapter->state))) {
1158 netif_wake_queue(netdev);
1159 ++adapter->restart_queue;
1160 }
1161 }
1162
1163 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001164 /*
1165 * Detect a transmit hang in hardware, this serializes the
1166 * check with the clearing of time_stamp and movement of i
1167 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001168 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001169 if (tx_ring->buffer_info[i].time_stamp &&
1170 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001171 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001172 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001173 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001174 else
1175 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001176 }
1177 adapter->total_tx_bytes += total_tx_bytes;
1178 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001179 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180}
1181
1182/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001183 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001184 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 *
1186 * the return value indicates whether actual cleaning was done, there
1187 * is no guarantee that everything was cleaned
1188 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001189static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1190 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001191{
Bruce Allan55aa6982011-12-16 00:45:45 +00001192 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001193 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001194 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1195 struct net_device *netdev = adapter->netdev;
1196 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001197 struct e1000_buffer *buffer_info, *next_buffer;
1198 struct e1000_ps_page *ps_page;
1199 struct sk_buff *skb;
1200 unsigned int i, j;
1201 u32 length, staterr;
1202 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001203 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001204 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1205
1206 i = rx_ring->next_to_clean;
1207 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1208 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1209 buffer_info = &rx_ring->buffer_info[i];
1210
1211 while (staterr & E1000_RXD_STAT_DD) {
1212 if (*work_done >= work_to_do)
1213 break;
1214 (*work_done)++;
1215 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001216 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217
1218 /* in the packet split case this is header only */
1219 prefetch(skb->data - NET_IP_ALIGN);
1220
1221 i++;
1222 if (i == rx_ring->count)
1223 i = 0;
1224 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1225 prefetch(next_rxd);
1226
1227 next_buffer = &rx_ring->buffer_info[i];
1228
Rusty Russell3db1cd52011-12-19 13:56:45 +00001229 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001230 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001231 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001232 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233 buffer_info->dma = 0;
1234
Bruce Allanaf667a22010-12-31 06:10:01 +00001235 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001236 if (!(staterr & E1000_RXD_STAT_EOP))
1237 adapter->flags2 |= FLAG2_IS_DISCARDING;
1238
1239 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001240 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001241 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001242 if (staterr & E1000_RXD_STAT_EOP)
1243 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 goto next_desc;
1245 }
1246
Ben Greearcf955e62012-02-11 15:39:51 +00001247 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1248 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249 dev_kfree_skb_irq(skb);
1250 goto next_desc;
1251 }
1252
1253 length = le16_to_cpu(rx_desc->wb.middle.length0);
1254
1255 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001256 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001257 dev_kfree_skb_irq(skb);
1258 goto next_desc;
1259 }
1260
1261 /* Good Receive */
1262 skb_put(skb, length);
1263
1264 {
Bruce Allan0e15df42012-01-31 06:37:11 +00001265 /*
1266 * this looks ugly, but it seems compiler issues make
1267 * it more efficient than reusing j
1268 */
1269 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001270
Bruce Allanad680762008-03-28 09:15:03 -07001271 /*
Bruce Allan0e15df42012-01-31 06:37:11 +00001272 * page alloc/put takes too long and effects small
1273 * packet throughput, so unsplit small packets and
1274 * save the alloc/put only valid in softirq (napi)
1275 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001276 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001277 if (l1 && (l1 <= copybreak) &&
1278 ((length + l1) <= adapter->rx_ps_bsize0)) {
1279 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001280
Bruce Allan0e15df42012-01-31 06:37:11 +00001281 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001282
Bruce Allan0e15df42012-01-31 06:37:11 +00001283 /*
1284 * there is no documentation about how to call
1285 * kmap_atomic, so we can't hold the mapping
1286 * very long
1287 */
1288 dma_sync_single_for_cpu(&pdev->dev,
1289 ps_page->dma,
1290 PAGE_SIZE,
1291 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001292 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001293 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001294 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001295 dma_sync_single_for_device(&pdev->dev,
1296 ps_page->dma,
1297 PAGE_SIZE,
1298 DMA_FROM_DEVICE);
1299
1300 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001301 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1302 if (!(netdev->features & NETIF_F_RXFCS))
1303 l1 -= 4;
1304 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001305
1306 skb_put(skb, l1);
1307 goto copydone;
1308 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001309 }
1310
1311 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1312 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1313 if (!length)
1314 break;
1315
Auke Kok47f44e42007-10-25 13:57:44 -07001316 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001317 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1318 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001319 ps_page->dma = 0;
1320 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1321 ps_page->page = NULL;
1322 skb->len += length;
1323 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001324 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001325 }
1326
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001327 /* strip the ethernet crc, problem is we're using pages now so
1328 * this whole operation can get a little cpu intensive
1329 */
Ben Greear01840392012-02-11 15:39:25 +00001330 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1331 if (!(netdev->features & NETIF_F_RXFCS))
1332 pskb_trim(skb, skb->len - 4);
1333 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001334
Auke Kokbc7f75f2007-09-17 12:30:59 -07001335copydone:
1336 total_rx_bytes += skb->len;
1337 total_rx_packets++;
1338
Bruce Allanafd12932012-01-05 00:34:05 +00001339 e1000_rx_checksum(adapter, staterr,
1340 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001341
Bruce Allan70495a52012-01-11 01:26:50 +00001342 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1343
Auke Kokbc7f75f2007-09-17 12:30:59 -07001344 if (rx_desc->wb.upper.header_status &
1345 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1346 adapter->rx_hdr_split++;
1347
1348 e1000_receive_skb(adapter, netdev, skb,
1349 staterr, rx_desc->wb.middle.vlan);
1350
1351next_desc:
1352 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1353 buffer_info->skb = NULL;
1354
1355 /* return some buffers to hardware, one at a time is too slow */
1356 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001357 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001358 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001359 cleaned_count = 0;
1360 }
1361
1362 /* use prefetched values */
1363 rx_desc = next_rxd;
1364 buffer_info = next_buffer;
1365
1366 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1367 }
1368 rx_ring->next_to_clean = i;
1369
1370 cleaned_count = e1000_desc_unused(rx_ring);
1371 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001372 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001373
Auke Kokbc7f75f2007-09-17 12:30:59 -07001374 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001375 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001376 return cleaned;
1377}
1378
1379/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001380 * e1000_consume_page - helper function
1381 **/
1382static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1383 u16 length)
1384{
1385 bi->page = NULL;
1386 skb->len += length;
1387 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001388 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001389}
1390
1391/**
1392 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1393 * @adapter: board private structure
1394 *
1395 * the return value indicates whether actual cleaning was done, there
1396 * is no guarantee that everything was cleaned
1397 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001398static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1399 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001400{
Bruce Allan55aa6982011-12-16 00:45:45 +00001401 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001402 struct net_device *netdev = adapter->netdev;
1403 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001404 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001405 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001406 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001407 unsigned int i;
1408 int cleaned_count = 0;
1409 bool cleaned = false;
1410 unsigned int total_rx_bytes=0, total_rx_packets=0;
1411
1412 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001413 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1414 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001415 buffer_info = &rx_ring->buffer_info[i];
1416
Bruce Allan5f450212011-07-22 06:21:46 +00001417 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001418 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001419
1420 if (*work_done >= work_to_do)
1421 break;
1422 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001423 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001424
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001425 skb = buffer_info->skb;
1426 buffer_info->skb = NULL;
1427
1428 ++i;
1429 if (i == rx_ring->count)
1430 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001431 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001432 prefetch(next_rxd);
1433
1434 next_buffer = &rx_ring->buffer_info[i];
1435
1436 cleaned = true;
1437 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001438 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1439 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001440 buffer_info->dma = 0;
1441
Bruce Allan5f450212011-07-22 06:21:46 +00001442 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001443
1444 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001445 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001446 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1447 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001448 /* recycle both page and skb */
1449 buffer_info->skb = skb;
1450 /* an error means any chain goes out the window too */
1451 if (rx_ring->rx_skb_top)
1452 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1453 rx_ring->rx_skb_top = NULL;
1454 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001455 }
1456
Bruce Allanf0f1a172010-12-11 05:53:32 +00001457#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001458 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001459 /* this descriptor is only the beginning (or middle) */
1460 if (!rxtop) {
1461 /* this is the beginning of a chain */
1462 rxtop = skb;
1463 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1464 0, length);
1465 } else {
1466 /* this is the middle of a chain */
1467 skb_fill_page_desc(rxtop,
1468 skb_shinfo(rxtop)->nr_frags,
1469 buffer_info->page, 0, length);
1470 /* re-use the skb, only consumed the page */
1471 buffer_info->skb = skb;
1472 }
1473 e1000_consume_page(buffer_info, rxtop, length);
1474 goto next_desc;
1475 } else {
1476 if (rxtop) {
1477 /* end of the chain */
1478 skb_fill_page_desc(rxtop,
1479 skb_shinfo(rxtop)->nr_frags,
1480 buffer_info->page, 0, length);
1481 /* re-use the current skb, we only consumed the
1482 * page */
1483 buffer_info->skb = skb;
1484 skb = rxtop;
1485 rxtop = NULL;
1486 e1000_consume_page(buffer_info, skb, length);
1487 } else {
1488 /* no chain, got EOP, this buf is the packet
1489 * copybreak to save the put_page/alloc_page */
1490 if (length <= copybreak &&
1491 skb_tailroom(skb) >= length) {
1492 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001493 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001494 memcpy(skb_tail_pointer(skb), vaddr,
1495 length);
Cong Wang46790262011-11-25 23:14:23 +08001496 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001497 /* re-use the page, so don't erase
1498 * buffer_info->page */
1499 skb_put(skb, length);
1500 } else {
1501 skb_fill_page_desc(skb, 0,
1502 buffer_info->page, 0,
1503 length);
1504 e1000_consume_page(buffer_info, skb,
1505 length);
1506 }
1507 }
1508 }
1509
1510 /* Receive Checksum Offload XXX recompute due to CRC strip? */
Bruce Allan5f450212011-07-22 06:21:46 +00001511 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +00001512 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001513
Bruce Allan70495a52012-01-11 01:26:50 +00001514 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1515
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001516 /* probably a little skewed due to removing CRC */
1517 total_rx_bytes += skb->len;
1518 total_rx_packets++;
1519
1520 /* eth type trans needs skb->data to point to something */
1521 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001522 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001523 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001524 goto next_desc;
1525 }
1526
Bruce Allan5f450212011-07-22 06:21:46 +00001527 e1000_receive_skb(adapter, netdev, skb, staterr,
1528 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001529
1530next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001531 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001532
1533 /* return some buffers to hardware, one at a time is too slow */
1534 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001535 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001536 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001537 cleaned_count = 0;
1538 }
1539
1540 /* use prefetched values */
1541 rx_desc = next_rxd;
1542 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001543
1544 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001545 }
1546 rx_ring->next_to_clean = i;
1547
1548 cleaned_count = e1000_desc_unused(rx_ring);
1549 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001550 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001551
1552 adapter->total_rx_bytes += total_rx_bytes;
1553 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001554 return cleaned;
1555}
1556
1557/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001558 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001559 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001560 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001561static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562{
Bruce Allan55aa6982011-12-16 00:45:45 +00001563 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001564 struct e1000_buffer *buffer_info;
1565 struct e1000_ps_page *ps_page;
1566 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001567 unsigned int i, j;
1568
1569 /* Free all the Rx ring sk_buffs */
1570 for (i = 0; i < rx_ring->count; i++) {
1571 buffer_info = &rx_ring->buffer_info[i];
1572 if (buffer_info->dma) {
1573 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001574 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001575 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001576 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001577 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001578 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001579 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001580 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001581 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001582 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001583 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001584 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585 buffer_info->dma = 0;
1586 }
1587
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001588 if (buffer_info->page) {
1589 put_page(buffer_info->page);
1590 buffer_info->page = NULL;
1591 }
1592
Auke Kokbc7f75f2007-09-17 12:30:59 -07001593 if (buffer_info->skb) {
1594 dev_kfree_skb(buffer_info->skb);
1595 buffer_info->skb = NULL;
1596 }
1597
1598 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001599 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001600 if (!ps_page->page)
1601 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001602 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1603 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001604 ps_page->dma = 0;
1605 put_page(ps_page->page);
1606 ps_page->page = NULL;
1607 }
1608 }
1609
1610 /* there also may be some cached data from a chained receive */
1611 if (rx_ring->rx_skb_top) {
1612 dev_kfree_skb(rx_ring->rx_skb_top);
1613 rx_ring->rx_skb_top = NULL;
1614 }
1615
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616 /* Zero out the descriptor ring */
1617 memset(rx_ring->desc, 0, rx_ring->size);
1618
1619 rx_ring->next_to_clean = 0;
1620 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001621 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001622
Bruce Allanc5083cf2011-12-16 00:45:40 +00001623 writel(0, rx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00001624 if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
1625 e1000e_update_rdt_wa(rx_ring, 0);
1626 else
1627 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001628}
1629
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001630static void e1000e_downshift_workaround(struct work_struct *work)
1631{
1632 struct e1000_adapter *adapter = container_of(work,
1633 struct e1000_adapter, downshift_task);
1634
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001635 if (test_bit(__E1000_DOWN, &adapter->state))
1636 return;
1637
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001638 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1639}
1640
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641/**
1642 * e1000_intr_msi - Interrupt Handler
1643 * @irq: interrupt number
1644 * @data: pointer to a network interface device structure
1645 **/
1646static irqreturn_t e1000_intr_msi(int irq, void *data)
1647{
1648 struct net_device *netdev = data;
1649 struct e1000_adapter *adapter = netdev_priv(netdev);
1650 struct e1000_hw *hw = &adapter->hw;
1651 u32 icr = er32(ICR);
1652
Bruce Allanad680762008-03-28 09:15:03 -07001653 /*
1654 * read ICR disables interrupts using IAM
1655 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001656
dave graham573cca82009-02-10 12:52:05 +00001657 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001658 hw->mac.get_link_status = true;
Bruce Allanad680762008-03-28 09:15:03 -07001659 /*
1660 * ICH8 workaround-- Call gig speed drop workaround on cable
1661 * disconnect (LSC) before accessing any PHY registers
1662 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001663 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1664 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001665 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666
Bruce Allanad680762008-03-28 09:15:03 -07001667 /*
1668 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001669 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001670 * adapter in watchdog
1671 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001672 if (netif_carrier_ok(netdev) &&
1673 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1674 /* disable receives */
1675 u32 rctl = er32(RCTL);
1676 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001677 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678 }
1679 /* guard against interrupt when we're going down */
1680 if (!test_bit(__E1000_DOWN, &adapter->state))
1681 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1682 }
1683
Ben Hutchings288379f2009-01-19 16:43:59 -08001684 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001685 adapter->total_tx_bytes = 0;
1686 adapter->total_tx_packets = 0;
1687 adapter->total_rx_bytes = 0;
1688 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001689 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001690 }
1691
1692 return IRQ_HANDLED;
1693}
1694
1695/**
1696 * e1000_intr - Interrupt Handler
1697 * @irq: interrupt number
1698 * @data: pointer to a network interface device structure
1699 **/
1700static irqreturn_t e1000_intr(int irq, void *data)
1701{
1702 struct net_device *netdev = data;
1703 struct e1000_adapter *adapter = netdev_priv(netdev);
1704 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001706
Bruce Allana68ea772009-11-20 23:23:16 +00001707 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708 return IRQ_NONE; /* Not our interrupt */
1709
Bruce Allanad680762008-03-28 09:15:03 -07001710 /*
1711 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1712 * not set, then the adapter didn't send an interrupt
1713 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001714 if (!(icr & E1000_ICR_INT_ASSERTED))
1715 return IRQ_NONE;
1716
Bruce Allanad680762008-03-28 09:15:03 -07001717 /*
1718 * Interrupt Auto-Mask...upon reading ICR,
1719 * interrupts are masked. No need for the
1720 * IMC write
1721 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001722
dave graham573cca82009-02-10 12:52:05 +00001723 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001724 hw->mac.get_link_status = true;
Bruce Allanad680762008-03-28 09:15:03 -07001725 /*
1726 * ICH8 workaround-- Call gig speed drop workaround on cable
1727 * disconnect (LSC) before accessing any PHY registers
1728 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001729 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1730 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001731 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001732
Bruce Allanad680762008-03-28 09:15:03 -07001733 /*
1734 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001735 * For packet buffer work-around on link down event;
1736 * disable receives here in the ISR and
1737 * reset adapter in watchdog
1738 */
1739 if (netif_carrier_ok(netdev) &&
1740 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1741 /* disable receives */
1742 rctl = er32(RCTL);
1743 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001744 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001745 }
1746 /* guard against interrupt when we're going down */
1747 if (!test_bit(__E1000_DOWN, &adapter->state))
1748 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1749 }
1750
Ben Hutchings288379f2009-01-19 16:43:59 -08001751 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001752 adapter->total_tx_bytes = 0;
1753 adapter->total_tx_packets = 0;
1754 adapter->total_rx_bytes = 0;
1755 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001756 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001757 }
1758
1759 return IRQ_HANDLED;
1760}
1761
Bruce Allan4662e822008-08-26 18:37:06 -07001762static irqreturn_t e1000_msix_other(int irq, void *data)
1763{
1764 struct net_device *netdev = data;
1765 struct e1000_adapter *adapter = netdev_priv(netdev);
1766 struct e1000_hw *hw = &adapter->hw;
1767 u32 icr = er32(ICR);
1768
1769 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001770 if (!test_bit(__E1000_DOWN, &adapter->state))
1771 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001772 return IRQ_NONE;
1773 }
1774
1775 if (icr & adapter->eiac_mask)
1776 ew32(ICS, (icr & adapter->eiac_mask));
1777
1778 if (icr & E1000_ICR_OTHER) {
1779 if (!(icr & E1000_ICR_LSC))
1780 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001781 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001782 /* guard against interrupt when we're going down */
1783 if (!test_bit(__E1000_DOWN, &adapter->state))
1784 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1785 }
1786
1787no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001788 if (!test_bit(__E1000_DOWN, &adapter->state))
1789 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001790
1791 return IRQ_HANDLED;
1792}
1793
1794
1795static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1796{
1797 struct net_device *netdev = data;
1798 struct e1000_adapter *adapter = netdev_priv(netdev);
1799 struct e1000_hw *hw = &adapter->hw;
1800 struct e1000_ring *tx_ring = adapter->tx_ring;
1801
1802
1803 adapter->total_tx_bytes = 0;
1804 adapter->total_tx_packets = 0;
1805
Bruce Allan55aa6982011-12-16 00:45:45 +00001806 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001807 /* Ring was not completely cleaned, so fire another interrupt */
1808 ew32(ICS, tx_ring->ims_val);
1809
1810 return IRQ_HANDLED;
1811}
1812
1813static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1814{
1815 struct net_device *netdev = data;
1816 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001817 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001818
1819 /* Write the ITR value calculated at the end of the
1820 * previous interrupt.
1821 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001822 if (rx_ring->set_itr) {
1823 writel(1000000000 / (rx_ring->itr_val * 256),
1824 rx_ring->itr_register);
1825 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001826 }
1827
Ben Hutchings288379f2009-01-19 16:43:59 -08001828 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001829 adapter->total_rx_bytes = 0;
1830 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001831 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001832 }
1833 return IRQ_HANDLED;
1834}
1835
1836/**
1837 * e1000_configure_msix - Configure MSI-X hardware
1838 *
1839 * e1000_configure_msix sets up the hardware to properly
1840 * generate MSI-X interrupts.
1841 **/
1842static void e1000_configure_msix(struct e1000_adapter *adapter)
1843{
1844 struct e1000_hw *hw = &adapter->hw;
1845 struct e1000_ring *rx_ring = adapter->rx_ring;
1846 struct e1000_ring *tx_ring = adapter->tx_ring;
1847 int vector = 0;
1848 u32 ctrl_ext, ivar = 0;
1849
1850 adapter->eiac_mask = 0;
1851
1852 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1853 if (hw->mac.type == e1000_82574) {
1854 u32 rfctl = er32(RFCTL);
1855 rfctl |= E1000_RFCTL_ACK_DIS;
1856 ew32(RFCTL, rfctl);
1857 }
1858
1859#define E1000_IVAR_INT_ALLOC_VALID 0x8
1860 /* Configure Rx vector */
1861 rx_ring->ims_val = E1000_IMS_RXQ0;
1862 adapter->eiac_mask |= rx_ring->ims_val;
1863 if (rx_ring->itr_val)
1864 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001865 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001866 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001867 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001868 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1869
1870 /* Configure Tx vector */
1871 tx_ring->ims_val = E1000_IMS_TXQ0;
1872 vector++;
1873 if (tx_ring->itr_val)
1874 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001875 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001876 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001877 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001878 adapter->eiac_mask |= tx_ring->ims_val;
1879 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1880
1881 /* set vector for Other Causes, e.g. link changes */
1882 vector++;
1883 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1884 if (rx_ring->itr_val)
1885 writel(1000000000 / (rx_ring->itr_val * 256),
1886 hw->hw_addr + E1000_EITR_82574(vector));
1887 else
1888 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1889
1890 /* Cause Tx interrupts on every write back */
1891 ivar |= (1 << 31);
1892
1893 ew32(IVAR, ivar);
1894
1895 /* enable MSI-X PBA support */
1896 ctrl_ext = er32(CTRL_EXT);
1897 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1898
1899 /* Auto-Mask Other interrupts upon ICR read */
1900#define E1000_EIAC_MASK_82574 0x01F00000
1901 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1902 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1903 ew32(CTRL_EXT, ctrl_ext);
1904 e1e_flush();
1905}
1906
1907void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1908{
1909 if (adapter->msix_entries) {
1910 pci_disable_msix(adapter->pdev);
1911 kfree(adapter->msix_entries);
1912 adapter->msix_entries = NULL;
1913 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1914 pci_disable_msi(adapter->pdev);
1915 adapter->flags &= ~FLAG_MSI_ENABLED;
1916 }
Bruce Allan4662e822008-08-26 18:37:06 -07001917}
1918
1919/**
1920 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1921 *
1922 * Attempt to configure interrupts using the best available
1923 * capabilities of the hardware and kernel.
1924 **/
1925void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1926{
1927 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001928 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001929
1930 switch (adapter->int_mode) {
1931 case E1000E_INT_MODE_MSIX:
1932 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001933 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1934 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001935 sizeof(struct msix_entry),
1936 GFP_KERNEL);
1937 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001938 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001939 adapter->msix_entries[i].entry = i;
1940
1941 err = pci_enable_msix(adapter->pdev,
1942 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001943 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001944 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001945 return;
1946 }
1947 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00001948 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001949 e1000e_reset_interrupt_capability(adapter);
1950 }
1951 adapter->int_mode = E1000E_INT_MODE_MSI;
1952 /* Fall through */
1953 case E1000E_INT_MODE_MSI:
1954 if (!pci_enable_msi(adapter->pdev)) {
1955 adapter->flags |= FLAG_MSI_ENABLED;
1956 } else {
1957 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00001958 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001959 }
1960 /* Fall through */
1961 case E1000E_INT_MODE_LEGACY:
1962 /* Don't do anything; this is the system default */
1963 break;
1964 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001965
1966 /* store the number of vectors being used */
1967 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001968}
1969
1970/**
1971 * e1000_request_msix - Initialize MSI-X interrupts
1972 *
1973 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1974 * kernel.
1975 **/
1976static int e1000_request_msix(struct e1000_adapter *adapter)
1977{
1978 struct net_device *netdev = adapter->netdev;
1979 int err = 0, vector = 0;
1980
1981 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001982 snprintf(adapter->rx_ring->name,
1983 sizeof(adapter->rx_ring->name) - 1,
1984 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001985 else
1986 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1987 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001988 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001989 netdev);
1990 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00001991 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00001992 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
1993 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07001994 adapter->rx_ring->itr_val = adapter->itr;
1995 vector++;
1996
1997 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001998 snprintf(adapter->tx_ring->name,
1999 sizeof(adapter->tx_ring->name) - 1,
2000 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002001 else
2002 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2003 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002004 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002005 netdev);
2006 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002007 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002008 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2009 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002010 adapter->tx_ring->itr_val = adapter->itr;
2011 vector++;
2012
2013 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002014 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002015 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002016 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002017
2018 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002019
Bruce Allan4662e822008-08-26 18:37:06 -07002020 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002021}
2022
Bruce Allanf8d59f72008-08-08 18:36:11 -07002023/**
2024 * e1000_request_irq - initialize interrupts
2025 *
2026 * Attempts to configure interrupts using the best available
2027 * capabilities of the hardware and kernel.
2028 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002029static int e1000_request_irq(struct e1000_adapter *adapter)
2030{
2031 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002032 int err;
2033
Bruce Allan4662e822008-08-26 18:37:06 -07002034 if (adapter->msix_entries) {
2035 err = e1000_request_msix(adapter);
2036 if (!err)
2037 return err;
2038 /* fall back to MSI */
2039 e1000e_reset_interrupt_capability(adapter);
2040 adapter->int_mode = E1000E_INT_MODE_MSI;
2041 e1000e_set_interrupt_capability(adapter);
2042 }
2043 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002044 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002045 netdev->name, netdev);
2046 if (!err)
2047 return err;
2048
2049 /* fall back to legacy interrupt */
2050 e1000e_reset_interrupt_capability(adapter);
2051 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002052 }
2053
Joe Perchesa0607fd2009-11-18 23:29:17 -08002054 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002055 netdev->name, netdev);
2056 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002057 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002058
2059 return err;
2060}
2061
2062static void e1000_free_irq(struct e1000_adapter *adapter)
2063{
2064 struct net_device *netdev = adapter->netdev;
2065
Bruce Allan4662e822008-08-26 18:37:06 -07002066 if (adapter->msix_entries) {
2067 int vector = 0;
2068
2069 free_irq(adapter->msix_entries[vector].vector, netdev);
2070 vector++;
2071
2072 free_irq(adapter->msix_entries[vector].vector, netdev);
2073 vector++;
2074
2075 /* Other Causes interrupt vector */
2076 free_irq(adapter->msix_entries[vector].vector, netdev);
2077 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002078 }
Bruce Allan4662e822008-08-26 18:37:06 -07002079
2080 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002081}
2082
2083/**
2084 * e1000_irq_disable - Mask off interrupt generation on the NIC
2085 **/
2086static void e1000_irq_disable(struct e1000_adapter *adapter)
2087{
2088 struct e1000_hw *hw = &adapter->hw;
2089
Auke Kokbc7f75f2007-09-17 12:30:59 -07002090 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002091 if (adapter->msix_entries)
2092 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002093 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002094
2095 if (adapter->msix_entries) {
2096 int i;
2097 for (i = 0; i < adapter->num_vectors; i++)
2098 synchronize_irq(adapter->msix_entries[i].vector);
2099 } else {
2100 synchronize_irq(adapter->pdev->irq);
2101 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002102}
2103
2104/**
2105 * e1000_irq_enable - Enable default interrupt generation settings
2106 **/
2107static void e1000_irq_enable(struct e1000_adapter *adapter)
2108{
2109 struct e1000_hw *hw = &adapter->hw;
2110
Bruce Allan4662e822008-08-26 18:37:06 -07002111 if (adapter->msix_entries) {
2112 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2113 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2114 } else {
2115 ew32(IMS, IMS_ENABLE_MASK);
2116 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002117 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002118}
2119
2120/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002121 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002122 * @adapter: address of board private structure
2123 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002124 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002125 * For ASF and Pass Through versions of f/w this means that
2126 * the driver is loaded. For AMT version (only with 82573)
2127 * of the f/w this means that the network i/f is open.
2128 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002129void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002130{
2131 struct e1000_hw *hw = &adapter->hw;
2132 u32 ctrl_ext;
2133 u32 swsm;
2134
2135 /* Let firmware know the driver has taken over */
2136 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2137 swsm = er32(SWSM);
2138 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2139 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2140 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002141 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002142 }
2143}
2144
2145/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002146 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002147 * @adapter: address of board private structure
2148 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002149 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002150 * For ASF and Pass Through versions of f/w this means that the
2151 * driver is no longer loaded. For AMT version (only with 82573) i
2152 * of the f/w this means that the network i/f is closed.
2153 *
2154 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002155void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002156{
2157 struct e1000_hw *hw = &adapter->hw;
2158 u32 ctrl_ext;
2159 u32 swsm;
2160
2161 /* Let firmware taken over control of h/w */
2162 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2163 swsm = er32(SWSM);
2164 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2165 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2166 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002167 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002168 }
2169}
2170
Auke Kokbc7f75f2007-09-17 12:30:59 -07002171/**
2172 * @e1000_alloc_ring - allocate memory for a ring structure
2173 **/
2174static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2175 struct e1000_ring *ring)
2176{
2177 struct pci_dev *pdev = adapter->pdev;
2178
2179 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2180 GFP_KERNEL);
2181 if (!ring->desc)
2182 return -ENOMEM;
2183
2184 return 0;
2185}
2186
2187/**
2188 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002189 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190 *
2191 * Return 0 on success, negative on failure
2192 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002193int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002194{
Bruce Allan55aa6982011-12-16 00:45:45 +00002195 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002196 int err = -ENOMEM, size;
2197
2198 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002199 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002200 if (!tx_ring->buffer_info)
2201 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002202
2203 /* round up to nearest 4K */
2204 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2205 tx_ring->size = ALIGN(tx_ring->size, 4096);
2206
2207 err = e1000_alloc_ring_dma(adapter, tx_ring);
2208 if (err)
2209 goto err;
2210
2211 tx_ring->next_to_use = 0;
2212 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002213
2214 return 0;
2215err:
2216 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002217 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002218 return err;
2219}
2220
2221/**
2222 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002223 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002224 *
2225 * Returns 0 on success, negative on failure
2226 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002227int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002228{
Bruce Allan55aa6982011-12-16 00:45:45 +00002229 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002230 struct e1000_buffer *buffer_info;
2231 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002232
2233 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002234 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002235 if (!rx_ring->buffer_info)
2236 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002237
Auke Kok47f44e42007-10-25 13:57:44 -07002238 for (i = 0; i < rx_ring->count; i++) {
2239 buffer_info = &rx_ring->buffer_info[i];
2240 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2241 sizeof(struct e1000_ps_page),
2242 GFP_KERNEL);
2243 if (!buffer_info->ps_pages)
2244 goto err_pages;
2245 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002246
2247 desc_len = sizeof(union e1000_rx_desc_packet_split);
2248
2249 /* Round up to nearest 4K */
2250 rx_ring->size = rx_ring->count * desc_len;
2251 rx_ring->size = ALIGN(rx_ring->size, 4096);
2252
2253 err = e1000_alloc_ring_dma(adapter, rx_ring);
2254 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002255 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002256
2257 rx_ring->next_to_clean = 0;
2258 rx_ring->next_to_use = 0;
2259 rx_ring->rx_skb_top = NULL;
2260
2261 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002262
2263err_pages:
2264 for (i = 0; i < rx_ring->count; i++) {
2265 buffer_info = &rx_ring->buffer_info[i];
2266 kfree(buffer_info->ps_pages);
2267 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002268err:
2269 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002270 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002271 return err;
2272}
2273
2274/**
2275 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002276 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002277 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002278static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002279{
Bruce Allan55aa6982011-12-16 00:45:45 +00002280 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002281 struct e1000_buffer *buffer_info;
2282 unsigned long size;
2283 unsigned int i;
2284
2285 for (i = 0; i < tx_ring->count; i++) {
2286 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002287 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288 }
2289
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002290 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002291 size = sizeof(struct e1000_buffer) * tx_ring->count;
2292 memset(tx_ring->buffer_info, 0, size);
2293
2294 memset(tx_ring->desc, 0, tx_ring->size);
2295
2296 tx_ring->next_to_use = 0;
2297 tx_ring->next_to_clean = 0;
2298
Bruce Allanc5083cf2011-12-16 00:45:40 +00002299 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002300 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2301 e1000e_update_tdt_wa(tx_ring, 0);
2302 else
2303 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002304}
2305
2306/**
2307 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002308 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002309 *
2310 * Free all transmit software resources
2311 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002312void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002313{
Bruce Allan55aa6982011-12-16 00:45:45 +00002314 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002315 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002316
Bruce Allan55aa6982011-12-16 00:45:45 +00002317 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002318
2319 vfree(tx_ring->buffer_info);
2320 tx_ring->buffer_info = NULL;
2321
2322 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2323 tx_ring->dma);
2324 tx_ring->desc = NULL;
2325}
2326
2327/**
2328 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002329 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330 *
2331 * Free all receive software resources
2332 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002333void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334{
Bruce Allan55aa6982011-12-16 00:45:45 +00002335 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002336 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002337 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002338
Bruce Allan55aa6982011-12-16 00:45:45 +00002339 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002340
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002341 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002342 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002343
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344 vfree(rx_ring->buffer_info);
2345 rx_ring->buffer_info = NULL;
2346
Auke Kokbc7f75f2007-09-17 12:30:59 -07002347 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2348 rx_ring->dma);
2349 rx_ring->desc = NULL;
2350}
2351
2352/**
2353 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002354 * @adapter: pointer to adapter
2355 * @itr_setting: current adapter->itr
2356 * @packets: the number of packets during this measurement interval
2357 * @bytes: the number of bytes during this measurement interval
2358 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359 * Stores a new ITR value based on packets and byte
2360 * counts during the last interrupt. The advantage of per interrupt
2361 * computation is faster updates and more accurate ITR for the current
2362 * traffic pattern. Constants in this function were computed
2363 * based on theoretical maximum wire speed and thresholds were set based
2364 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002365 * while increasing bulk throughput. This functionality is controlled
2366 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002367 **/
2368static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2369 u16 itr_setting, int packets,
2370 int bytes)
2371{
2372 unsigned int retval = itr_setting;
2373
2374 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002375 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002376
2377 switch (itr_setting) {
2378 case lowest_latency:
2379 /* handle TSO and jumbo frames */
2380 if (bytes/packets > 8000)
2381 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002382 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002383 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384 break;
2385 case low_latency: /* 50 usec aka 20000 ints/s */
2386 if (bytes > 10000) {
2387 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002388 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002390 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002391 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002392 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002393 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002394 } else if (bytes/packets > 2000) {
2395 retval = bulk_latency;
2396 } else if (packets <= 2 && bytes < 512) {
2397 retval = lowest_latency;
2398 }
2399 break;
2400 case bulk_latency: /* 250 usec aka 4000 ints/s */
2401 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002402 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002403 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002404 } else if (bytes < 6000) {
2405 retval = low_latency;
2406 }
2407 break;
2408 }
2409
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410 return retval;
2411}
2412
2413static void e1000_set_itr(struct e1000_adapter *adapter)
2414{
2415 struct e1000_hw *hw = &adapter->hw;
2416 u16 current_itr;
2417 u32 new_itr = adapter->itr;
2418
2419 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2420 if (adapter->link_speed != SPEED_1000) {
2421 current_itr = 0;
2422 new_itr = 4000;
2423 goto set_itr_now;
2424 }
2425
Bruce Allan828bac82010-09-29 21:39:37 +00002426 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2427 new_itr = 0;
2428 goto set_itr_now;
2429 }
2430
Auke Kokbc7f75f2007-09-17 12:30:59 -07002431 adapter->tx_itr = e1000_update_itr(adapter,
2432 adapter->tx_itr,
2433 adapter->total_tx_packets,
2434 adapter->total_tx_bytes);
2435 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2436 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2437 adapter->tx_itr = low_latency;
2438
2439 adapter->rx_itr = e1000_update_itr(adapter,
2440 adapter->rx_itr,
2441 adapter->total_rx_packets,
2442 adapter->total_rx_bytes);
2443 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2444 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2445 adapter->rx_itr = low_latency;
2446
2447 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2448
2449 switch (current_itr) {
2450 /* counts and packets in update_itr are dependent on these numbers */
2451 case lowest_latency:
2452 new_itr = 70000;
2453 break;
2454 case low_latency:
2455 new_itr = 20000; /* aka hwitr = ~200 */
2456 break;
2457 case bulk_latency:
2458 new_itr = 4000;
2459 break;
2460 default:
2461 break;
2462 }
2463
2464set_itr_now:
2465 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002466 /*
2467 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002468 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002469 * increasing
2470 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002471 new_itr = new_itr > adapter->itr ?
2472 min(adapter->itr + (new_itr >> 2), new_itr) :
2473 new_itr;
2474 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002475 adapter->rx_ring->itr_val = new_itr;
2476 if (adapter->msix_entries)
2477 adapter->rx_ring->set_itr = 1;
2478 else
Bruce Allan828bac82010-09-29 21:39:37 +00002479 if (new_itr)
2480 ew32(ITR, 1000000000 / (new_itr * 256));
2481 else
2482 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483 }
2484}
2485
2486/**
Bruce Allan4662e822008-08-26 18:37:06 -07002487 * e1000_alloc_queues - Allocate memory for all rings
2488 * @adapter: board private structure to initialize
2489 **/
2490static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2491{
Bruce Allan55aa6982011-12-16 00:45:45 +00002492 int size = sizeof(struct e1000_ring);
2493
2494 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002495 if (!adapter->tx_ring)
2496 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002497 adapter->tx_ring->count = adapter->tx_ring_count;
2498 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002499
Bruce Allan55aa6982011-12-16 00:45:45 +00002500 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002501 if (!adapter->rx_ring)
2502 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002503 adapter->rx_ring->count = adapter->rx_ring_count;
2504 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002505
2506 return 0;
2507err:
2508 e_err("Unable to allocate memory for queues\n");
2509 kfree(adapter->rx_ring);
2510 kfree(adapter->tx_ring);
2511 return -ENOMEM;
2512}
2513
2514/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002515 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002516 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002517 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002518 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002519static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002521 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2522 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002523 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002524 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002525 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526
Wang Chen4cf16532008-11-12 23:38:14 -08002527 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002528
Bruce Allanc58c8a72012-03-20 03:48:19 +00002529 if (!adapter->msix_entries ||
2530 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2531 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002532
Bruce Allanc58c8a72012-03-20 03:48:19 +00002533 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002534
Alexander Duyck12d04a32009-03-25 22:05:03 +00002535 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002536 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002537
Bruce Allanc58c8a72012-03-20 03:48:19 +00002538 /* If weight not fully consumed, exit the polling mode */
2539 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002540 if (adapter->itr_setting & 3)
2541 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002542 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002543 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2544 if (adapter->msix_entries)
2545 ew32(IMS, adapter->rx_ring->ims_val);
2546 else
2547 e1000_irq_enable(adapter);
2548 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002549 }
2550
2551 return work_done;
2552}
2553
Jiri Pirko8e586132011-12-08 19:52:37 -05002554static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002555{
2556 struct e1000_adapter *adapter = netdev_priv(netdev);
2557 struct e1000_hw *hw = &adapter->hw;
2558 u32 vfta, index;
2559
2560 /* don't update vlan cookie if already programmed */
2561 if ((adapter->hw.mng_cookie.status &
2562 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2563 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002564 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002565
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002567 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2568 index = (vid >> 5) & 0x7F;
2569 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2570 vfta |= (1 << (vid & 0x1F));
2571 hw->mac.ops.write_vfta(hw, index, vfta);
2572 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002573
2574 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002575
2576 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577}
2578
Jiri Pirko8e586132011-12-08 19:52:37 -05002579static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002580{
2581 struct e1000_adapter *adapter = netdev_priv(netdev);
2582 struct e1000_hw *hw = &adapter->hw;
2583 u32 vfta, index;
2584
Auke Kokbc7f75f2007-09-17 12:30:59 -07002585 if ((adapter->hw.mng_cookie.status &
2586 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2587 (vid == adapter->mng_vlan_id)) {
2588 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002589 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002590 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002591 }
2592
2593 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002594 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2595 index = (vid >> 5) & 0x7F;
2596 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2597 vfta &= ~(1 << (vid & 0x1F));
2598 hw->mac.ops.write_vfta(hw, index, vfta);
2599 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002600
2601 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002602
2603 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002604}
2605
2606/**
2607 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2608 * @adapter: board private structure to initialize
2609 **/
2610static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2611{
2612 struct net_device *netdev = adapter->netdev;
2613 struct e1000_hw *hw = &adapter->hw;
2614 u32 rctl;
2615
2616 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2617 /* disable VLAN receive filtering */
2618 rctl = er32(RCTL);
2619 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2620 ew32(RCTL, rctl);
2621
2622 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2623 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2624 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2625 }
2626 }
2627}
2628
2629/**
2630 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2631 * @adapter: board private structure to initialize
2632 **/
2633static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2634{
2635 struct e1000_hw *hw = &adapter->hw;
2636 u32 rctl;
2637
2638 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2639 /* enable VLAN receive filtering */
2640 rctl = er32(RCTL);
2641 rctl |= E1000_RCTL_VFE;
2642 rctl &= ~E1000_RCTL_CFIEN;
2643 ew32(RCTL, rctl);
2644 }
2645}
2646
2647/**
2648 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2649 * @adapter: board private structure to initialize
2650 **/
2651static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2652{
2653 struct e1000_hw *hw = &adapter->hw;
2654 u32 ctrl;
2655
2656 /* disable VLAN tag insert/strip */
2657 ctrl = er32(CTRL);
2658 ctrl &= ~E1000_CTRL_VME;
2659 ew32(CTRL, ctrl);
2660}
2661
2662/**
2663 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2664 * @adapter: board private structure to initialize
2665 **/
2666static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2667{
2668 struct e1000_hw *hw = &adapter->hw;
2669 u32 ctrl;
2670
2671 /* enable VLAN tag insert/strip */
2672 ctrl = er32(CTRL);
2673 ctrl |= E1000_CTRL_VME;
2674 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002675}
2676
2677static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2678{
2679 struct net_device *netdev = adapter->netdev;
2680 u16 vid = adapter->hw.mng_cookie.vlan_id;
2681 u16 old_vid = adapter->mng_vlan_id;
2682
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002683 if (adapter->hw.mng_cookie.status &
2684 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2685 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002686 adapter->mng_vlan_id = vid;
2687 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002688
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002689 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2690 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002691}
2692
2693static void e1000_restore_vlan(struct e1000_adapter *adapter)
2694{
2695 u16 vid;
2696
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002697 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002698
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002699 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002700 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002701}
2702
Bruce Allancd791612010-05-10 14:59:51 +00002703static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002704{
2705 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002706 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002707
2708 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2709 return;
2710
2711 manc = er32(MANC);
2712
Bruce Allanad680762008-03-28 09:15:03 -07002713 /*
2714 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002715 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002716 * the packets will be handled on SMBUS
2717 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002718 manc |= E1000_MANC_EN_MNG2HOST;
2719 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002720
2721 switch (hw->mac.type) {
2722 default:
2723 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2724 break;
2725 case e1000_82574:
2726 case e1000_82583:
2727 /*
2728 * Check if IPMI pass-through decision filter already exists;
2729 * if so, enable it.
2730 */
2731 for (i = 0, j = 0; i < 8; i++) {
2732 mdef = er32(MDEF(i));
2733
2734 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002735 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002736 continue;
2737
2738 /* Enable this decision filter in MANC2H */
2739 if (mdef)
2740 manc2h |= (1 << i);
2741
2742 j |= mdef;
2743 }
2744
2745 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2746 break;
2747
2748 /* Create new decision filter in an empty filter */
2749 for (i = 0, j = 0; i < 8; i++)
2750 if (er32(MDEF(i)) == 0) {
2751 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2752 E1000_MDEF_PORT_664));
2753 manc2h |= (1 << 1);
2754 j++;
2755 break;
2756 }
2757
2758 if (!j)
2759 e_warn("Unable to create IPMI pass-through filter\n");
2760 break;
2761 }
2762
Auke Kokbc7f75f2007-09-17 12:30:59 -07002763 ew32(MANC2H, manc2h);
2764 ew32(MANC, manc);
2765}
2766
2767/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002768 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002769 * @adapter: board private structure
2770 *
2771 * Configure the Tx unit of the MAC after a reset.
2772 **/
2773static void e1000_configure_tx(struct e1000_adapter *adapter)
2774{
2775 struct e1000_hw *hw = &adapter->hw;
2776 struct e1000_ring *tx_ring = adapter->tx_ring;
2777 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002778 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002779
2780 /* Setup the HW Tx Head and Tail descriptor pointers */
2781 tdba = tx_ring->dma;
2782 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002783 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2784 ew32(TDBAH(0), (tdba >> 32));
2785 ew32(TDLEN(0), tdlen);
2786 ew32(TDH(0), 0);
2787 ew32(TDT(0), 0);
2788 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2789 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002790
Auke Kokbc7f75f2007-09-17 12:30:59 -07002791 /* Set the Tx Interrupt Delay register */
2792 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002793 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002794 ew32(TADV, adapter->tx_abs_int_delay);
2795
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002796 if (adapter->flags2 & FLAG2_DMA_BURST) {
2797 u32 txdctl = er32(TXDCTL(0));
2798 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2799 E1000_TXDCTL_WTHRESH);
2800 /*
2801 * set up some performance related parameters to encourage the
2802 * hardware to use the bus more efficiently in bursts, depends
2803 * on the tx_int_delay to be enabled,
2804 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2805 * hthresh = 1 ==> prefetch when one or more available
2806 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2807 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002808 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002809 */
2810 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2811 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002812 }
Bruce Allan56032be2011-12-16 00:46:01 +00002813 /* erratum work around: set txdctl the same for both queues */
2814 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002815
Auke Kokbc7f75f2007-09-17 12:30:59 -07002816 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002817 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002818 /*
2819 * set the speed mode bit, we'll clear it if we're not at
2820 * gigabit link later
2821 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002822#define SPEED_MODE_BIT (1 << 21)
2823 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002824 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002825 }
2826
2827 /* errata: program both queues to unweighted RR */
2828 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002829 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002830 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002831 ew32(TARC(0), tarc);
2832 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002834 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835 }
2836
Auke Kokbc7f75f2007-09-17 12:30:59 -07002837 /* Setup Transmit Descriptor Settings for eop descriptor */
2838 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2839
2840 /* only set IDE if we are delaying interrupts using the timers */
2841 if (adapter->tx_int_delay)
2842 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2843
2844 /* enable Report Status bit */
2845 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2846
Bruce Allan57cde762012-02-22 09:02:58 +00002847 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002848}
2849
2850/**
2851 * e1000_setup_rctl - configure the receive control registers
2852 * @adapter: Board private structure
2853 **/
2854#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2855 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2856static void e1000_setup_rctl(struct e1000_adapter *adapter)
2857{
2858 struct e1000_hw *hw = &adapter->hw;
2859 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002860 u32 pages = 0;
2861
Bruce Allana1ce6472010-09-22 17:16:40 +00002862 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2863 if (hw->mac.type == e1000_pch2lan) {
2864 s32 ret_val;
2865
2866 if (adapter->netdev->mtu > ETH_DATA_LEN)
2867 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2868 else
2869 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002870
2871 if (ret_val)
2872 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002873 }
2874
Auke Kokbc7f75f2007-09-17 12:30:59 -07002875 /* Program MC offset vector base */
2876 rctl = er32(RCTL);
2877 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2878 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2879 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2880 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2881
2882 /* Do not Store bad packets */
2883 rctl &= ~E1000_RCTL_SBP;
2884
2885 /* Enable Long Packet receive */
2886 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2887 rctl &= ~E1000_RCTL_LPE;
2888 else
2889 rctl |= E1000_RCTL_LPE;
2890
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002891 /* Some systems expect that the CRC is included in SMBUS traffic. The
2892 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2893 * host memory when this is enabled
2894 */
2895 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2896 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002897
Bruce Allana4f58f52009-06-02 11:29:18 +00002898 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2899 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2900 u16 phy_data;
2901
2902 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2903 phy_data &= 0xfff8;
2904 phy_data |= (1 << 2);
2905 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2906
2907 e1e_rphy(hw, 22, &phy_data);
2908 phy_data &= 0x0fff;
2909 phy_data |= (1 << 14);
2910 e1e_wphy(hw, 0x10, 0x2823);
2911 e1e_wphy(hw, 0x11, 0x0003);
2912 e1e_wphy(hw, 22, phy_data);
2913 }
2914
Auke Kokbc7f75f2007-09-17 12:30:59 -07002915 /* Setup buffer sizes */
2916 rctl &= ~E1000_RCTL_SZ_4096;
2917 rctl |= E1000_RCTL_BSEX;
2918 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002919 case 2048:
2920 default:
2921 rctl |= E1000_RCTL_SZ_2048;
2922 rctl &= ~E1000_RCTL_BSEX;
2923 break;
2924 case 4096:
2925 rctl |= E1000_RCTL_SZ_4096;
2926 break;
2927 case 8192:
2928 rctl |= E1000_RCTL_SZ_8192;
2929 break;
2930 case 16384:
2931 rctl |= E1000_RCTL_SZ_16384;
2932 break;
2933 }
2934
Bruce Allan5f450212011-07-22 06:21:46 +00002935 /* Enable Extended Status in all Receive Descriptors */
2936 rfctl = er32(RFCTL);
2937 rfctl |= E1000_RFCTL_EXTEN;
2938
Auke Kokbc7f75f2007-09-17 12:30:59 -07002939 /*
2940 * 82571 and greater support packet-split where the protocol
2941 * header is placed in skb->data and the packet data is
2942 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2943 * In the case of a non-split, skb->data is linearly filled,
2944 * followed by the page buffers. Therefore, skb->data is
2945 * sized to hold the largest protocol header.
2946 *
2947 * allocations using alloc_page take too long for regular MTU
2948 * so only enable packet split for jumbo frames
2949 *
2950 * Using pages when the page size is greater than 16k wastes
2951 * a lot of memory, since we allocate 3 pages at all times
2952 * per packet.
2953 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002954 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00002955 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002956 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002957 else
2958 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002959
2960 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002961 u32 psrctl = 0;
2962
Bruce Allanad680762008-03-28 09:15:03 -07002963 /*
2964 * disable packet split support for IPv6 extension headers,
2965 * because some malformed IPv6 headers can hang the Rx
2966 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002967 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2968 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2969
Auke Kok140a7482007-10-25 13:57:58 -07002970 /* Enable Packet split descriptors */
2971 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002972
2973 psrctl |= adapter->rx_ps_bsize0 >>
2974 E1000_PSRCTL_BSIZE0_SHIFT;
2975
2976 switch (adapter->rx_ps_pages) {
2977 case 3:
2978 psrctl |= PAGE_SIZE <<
2979 E1000_PSRCTL_BSIZE3_SHIFT;
2980 case 2:
2981 psrctl |= PAGE_SIZE <<
2982 E1000_PSRCTL_BSIZE2_SHIFT;
2983 case 1:
2984 psrctl |= PAGE_SIZE >>
2985 E1000_PSRCTL_BSIZE1_SHIFT;
2986 break;
2987 }
2988
2989 ew32(PSRCTL, psrctl);
2990 }
2991
Ben Greearcf955e62012-02-11 15:39:51 +00002992 /* This is useful for sniffing bad packets. */
2993 if (adapter->netdev->features & NETIF_F_RXALL) {
2994 /* UPE and MPE will be handled by normal PROMISC logic
2995 * in e1000e_set_rx_mode */
2996 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
2997 E1000_RCTL_BAM | /* RX All Bcast Pkts */
2998 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
2999
3000 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3001 E1000_RCTL_DPF | /* Allow filtered pause */
3002 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3003 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3004 * and that breaks VLANs.
3005 */
3006 }
3007
Bruce Allan5f450212011-07-22 06:21:46 +00003008 ew32(RFCTL, rfctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003009 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003010 /* just started the receive unit, no need to restart */
3011 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003012}
3013
3014/**
3015 * e1000_configure_rx - Configure Receive Unit after Reset
3016 * @adapter: board private structure
3017 *
3018 * Configure the Rx unit of the MAC after a reset.
3019 **/
3020static void e1000_configure_rx(struct e1000_adapter *adapter)
3021{
3022 struct e1000_hw *hw = &adapter->hw;
3023 struct e1000_ring *rx_ring = adapter->rx_ring;
3024 u64 rdba;
3025 u32 rdlen, rctl, rxcsum, ctrl_ext;
3026
3027 if (adapter->rx_ps_pages) {
3028 /* this is a 32 byte descriptor */
3029 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003030 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003031 adapter->clean_rx = e1000_clean_rx_irq_ps;
3032 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003033 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003034 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003035 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3036 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003037 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003038 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003039 adapter->clean_rx = e1000_clean_rx_irq;
3040 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3041 }
3042
3043 /* disable receives while setting up the descriptors */
3044 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003045 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3046 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003047 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003048 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003049
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003050 if (adapter->flags2 & FLAG2_DMA_BURST) {
3051 /*
3052 * set the writeback threshold (only takes effect if the RDTR
3053 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003054 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003055 * granularity = 01
3056 * wthresh = 04,
3057 * hthresh = 04,
3058 * pthresh = 0x20
3059 */
3060 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3061 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3062
3063 /*
3064 * override the delay timers for enabling bursting, only if
3065 * the value was not set by the user via module options
3066 */
3067 if (adapter->rx_int_delay == DEFAULT_RDTR)
3068 adapter->rx_int_delay = BURST_RDTR;
3069 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3070 adapter->rx_abs_int_delay = BURST_RADV;
3071 }
3072
Auke Kokbc7f75f2007-09-17 12:30:59 -07003073 /* set the Receive Delay Timer Register */
3074 ew32(RDTR, adapter->rx_int_delay);
3075
3076 /* irq moderation */
3077 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003078 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003079 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003080
3081 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003082 /* Auto-Mask interrupts upon ICR access */
3083 ctrl_ext |= E1000_CTRL_EXT_IAME;
3084 ew32(IAM, 0xffffffff);
3085 ew32(CTRL_EXT, ctrl_ext);
3086 e1e_flush();
3087
Bruce Allanad680762008-03-28 09:15:03 -07003088 /*
3089 * Setup the HW Rx Head and Tail Descriptor Pointers and
3090 * the Base and Length of the Rx Descriptor Ring
3091 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003092 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003093 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3094 ew32(RDBAH(0), (rdba >> 32));
3095 ew32(RDLEN(0), rdlen);
3096 ew32(RDH(0), 0);
3097 ew32(RDT(0), 0);
3098 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3099 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003100
3101 /* Enable Receive Checksum Offload for TCP and UDP */
3102 rxcsum = er32(RXCSUM);
Bruce Allandc221292011-08-19 03:23:48 +00003103 if (adapter->netdev->features & NETIF_F_RXCSUM) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003104 rxcsum |= E1000_RXCSUM_TUOFL;
3105
Bruce Allanad680762008-03-28 09:15:03 -07003106 /*
3107 * IPv4 payload checksum for UDP fragments must be
3108 * used in conjunction with packet-split.
3109 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003110 if (adapter->rx_ps_pages)
3111 rxcsum |= E1000_RXCSUM_IPPCSE;
3112 } else {
3113 rxcsum &= ~E1000_RXCSUM_TUOFL;
3114 /* no need to clear IPPCSE as it defaults to 0 */
3115 }
3116 ew32(RXCSUM, rxcsum);
3117
Bruce Allan79d4e902011-12-16 00:46:27 +00003118 if (adapter->hw.mac.type == e1000_pch2lan) {
3119 /*
3120 * With jumbo frames, excessive C-state transition
3121 * latencies result in dropped transactions.
3122 */
Bruce Allan53ec5492009-11-20 23:27:40 +00003123 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3124 u32 rxdctl = er32(RXDCTL(0));
3125 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allanaf667a22010-12-31 06:10:01 +00003126 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003127 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003128 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3129 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003130 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003131 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003132
3133 /* Enable Receives */
3134 ew32(RCTL, rctl);
3135}
3136
3137/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003138 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003139 * @netdev: network interface device structure
3140 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003141 * Writes multicast address list to the MTA hash table.
3142 * Returns: -ENOMEM on failure
3143 * 0 on no addresses written
3144 * X on writing X addresses to MTA
3145 */
3146static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003147{
3148 struct e1000_adapter *adapter = netdev_priv(netdev);
3149 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003150 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003151 u8 *mta_list;
3152 int i;
3153
3154 if (netdev_mc_empty(netdev)) {
3155 /* nothing to program, so clear mc list */
3156 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3157 return 0;
3158 }
3159
3160 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3161 if (!mta_list)
3162 return -ENOMEM;
3163
3164 /* update_mc_addr_list expects a packed array of only addresses. */
3165 i = 0;
3166 netdev_for_each_mc_addr(ha, netdev)
3167 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3168
3169 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3170 kfree(mta_list);
3171
3172 return netdev_mc_count(netdev);
3173}
3174
3175/**
3176 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3177 * @netdev: network interface device structure
3178 *
3179 * Writes unicast address list to the RAR table.
3180 * Returns: -ENOMEM on failure/insufficient address space
3181 * 0 on no addresses written
3182 * X on writing X addresses to the RAR table
3183 **/
3184static int e1000e_write_uc_addr_list(struct net_device *netdev)
3185{
3186 struct e1000_adapter *adapter = netdev_priv(netdev);
3187 struct e1000_hw *hw = &adapter->hw;
3188 unsigned int rar_entries = hw->mac.rar_entry_count;
3189 int count = 0;
3190
3191 /* save a rar entry for our hardware address */
3192 rar_entries--;
3193
3194 /* save a rar entry for the LAA workaround */
3195 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3196 rar_entries--;
3197
3198 /* return ENOMEM indicating insufficient memory for addresses */
3199 if (netdev_uc_count(netdev) > rar_entries)
3200 return -ENOMEM;
3201
3202 if (!netdev_uc_empty(netdev) && rar_entries) {
3203 struct netdev_hw_addr *ha;
3204
3205 /*
3206 * write the addresses in reverse order to avoid write
3207 * combining
3208 */
3209 netdev_for_each_uc_addr(ha, netdev) {
3210 if (!rar_entries)
3211 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003212 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003213 count++;
3214 }
3215 }
3216
3217 /* zero out the remaining RAR entries not used above */
3218 for (; rar_entries > 0; rar_entries--) {
3219 ew32(RAH(rar_entries), 0);
3220 ew32(RAL(rar_entries), 0);
3221 }
3222 e1e_flush();
3223
3224 return count;
3225}
3226
3227/**
3228 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3229 * @netdev: network interface device structure
3230 *
3231 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3232 * address list or the network interface flags are updated. This routine is
3233 * responsible for configuring the hardware for proper unicast, multicast,
3234 * promiscuous mode, and all-multi behavior.
3235 **/
3236static void e1000e_set_rx_mode(struct net_device *netdev)
3237{
3238 struct e1000_adapter *adapter = netdev_priv(netdev);
3239 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003240 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003241
3242 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003243 rctl = er32(RCTL);
3244
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003245 /* clear the affected bits */
3246 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3247
Auke Kokbc7f75f2007-09-17 12:30:59 -07003248 if (netdev->flags & IFF_PROMISC) {
3249 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003250 /* Do not hardware filter VLANs in promisc mode */
3251 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003252 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003253 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003254
Patrick McHardy746b9f02008-07-16 20:15:45 -07003255 if (netdev->flags & IFF_ALLMULTI) {
3256 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003257 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003258 /*
3259 * Write addresses to the MTA, if the attempt fails
3260 * then we should just turn on promiscuous mode so
3261 * that we can at least receive multicast traffic
3262 */
3263 count = e1000e_write_mc_addr_list(netdev);
3264 if (count < 0)
3265 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003266 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003267 e1000e_vlan_filter_enable(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003268 /*
3269 * Write addresses to available RAR registers, if there is not
3270 * sufficient space to store all the addresses then enable
3271 * unicast promiscuous mode
3272 */
3273 count = e1000e_write_uc_addr_list(netdev);
3274 if (count < 0)
3275 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003276 }
3277
3278 ew32(RCTL, rctl);
3279
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003280 if (netdev->features & NETIF_F_HW_VLAN_RX)
3281 e1000e_vlan_strip_enable(adapter);
3282 else
3283 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003284}
3285
Bruce Allan70495a52012-01-11 01:26:50 +00003286static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3287{
3288 struct e1000_hw *hw = &adapter->hw;
3289 u32 mrqc, rxcsum;
3290 int i;
3291 static const u32 rsskey[10] = {
3292 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3293 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3294 };
3295
3296 /* Fill out hash function seed */
3297 for (i = 0; i < 10; i++)
3298 ew32(RSSRK(i), rsskey[i]);
3299
3300 /* Direct all traffic to queue 0 */
3301 for (i = 0; i < 32; i++)
3302 ew32(RETA(i), 0);
3303
3304 /*
3305 * Disable raw packet checksumming so that RSS hash is placed in
3306 * descriptor on writeback.
3307 */
3308 rxcsum = er32(RXCSUM);
3309 rxcsum |= E1000_RXCSUM_PCSD;
3310
3311 ew32(RXCSUM, rxcsum);
3312
3313 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3314 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3315 E1000_MRQC_RSS_FIELD_IPV6 |
3316 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3317 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3318
3319 ew32(MRQC, mrqc);
3320}
3321
Auke Kokbc7f75f2007-09-17 12:30:59 -07003322/**
Bruce Allanad680762008-03-28 09:15:03 -07003323 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003324 * @adapter: private board structure
3325 **/
3326static void e1000_configure(struct e1000_adapter *adapter)
3327{
Bruce Allan55aa6982011-12-16 00:45:45 +00003328 struct e1000_ring *rx_ring = adapter->rx_ring;
3329
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003330 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003331
3332 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003333 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003334
3335 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003336
3337 if (adapter->netdev->features & NETIF_F_RXHASH)
3338 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003339 e1000_setup_rctl(adapter);
3340 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003341 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003342}
3343
3344/**
3345 * e1000e_power_up_phy - restore link in case the phy was powered down
3346 * @adapter: address of board private structure
3347 *
3348 * The phy may be powered down to save power and turn off link when the
3349 * driver is unloaded and wake on lan is not enabled (among others)
3350 * *** this routine MUST be followed by a call to e1000e_reset ***
3351 **/
3352void e1000e_power_up_phy(struct e1000_adapter *adapter)
3353{
Bruce Allan17f208d2009-12-01 15:47:22 +00003354 if (adapter->hw.phy.ops.power_up)
3355 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003356
3357 adapter->hw.mac.ops.setup_link(&adapter->hw);
3358}
3359
3360/**
3361 * e1000_power_down_phy - Power down the PHY
3362 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003363 * Power down the PHY so no link is implied when interface is down.
3364 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003365 */
3366static void e1000_power_down_phy(struct e1000_adapter *adapter)
3367{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003368 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003369 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003370 return;
3371
Bruce Allan17f208d2009-12-01 15:47:22 +00003372 if (adapter->hw.phy.ops.power_down)
3373 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003374}
3375
3376/**
3377 * e1000e_reset - bring the hardware into a known good state
3378 *
3379 * This function boots the hardware and enables some settings that
3380 * require a configuration cycle of the hardware - those cannot be
3381 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003382 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003383 */
3384void e1000e_reset(struct e1000_adapter *adapter)
3385{
3386 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003387 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003388 struct e1000_hw *hw = &adapter->hw;
3389 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003390 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003391 u16 hwm;
3392
Bruce Allanad680762008-03-28 09:15:03 -07003393 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003394 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003395
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003396 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003397 /*
3398 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003399 * large enough to accommodate two full transmit packets,
3400 * rounded up to the next 1KB and expressed in KB. Likewise,
3401 * the Rx FIFO should be large enough to accommodate at least
3402 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003403 * expressed in KB.
3404 */
Auke Kokdf762462007-10-25 13:57:53 -07003405 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003406 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003407 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003408 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003409 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003410 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003411 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003412 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003413 */
3414 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003415 sizeof(struct e1000_tx_desc) -
3416 ETH_FCS_LEN) * 2;
3417 min_tx_space = ALIGN(min_tx_space, 1024);
3418 min_tx_space >>= 10;
3419 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003420 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003421 min_rx_space = ALIGN(min_rx_space, 1024);
3422 min_rx_space >>= 10;
3423
Bruce Allanad680762008-03-28 09:15:03 -07003424 /*
3425 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003427 * allocation, take space away from current Rx allocation
3428 */
Auke Kokdf762462007-10-25 13:57:53 -07003429 if ((tx_space < min_tx_space) &&
3430 ((min_tx_space - tx_space) < pba)) {
3431 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003432
Bruce Allanad680762008-03-28 09:15:03 -07003433 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003434 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003435 * adjustment or use Early Receive if available
3436 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003437 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003438 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003439 }
Auke Kokdf762462007-10-25 13:57:53 -07003440
3441 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003442 }
3443
Bruce Allanad680762008-03-28 09:15:03 -07003444 /*
3445 * flow control settings
3446 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003447 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003448 * (or the size used for early receive) above it in the Rx FIFO.
3449 * Set it to the lower of:
3450 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003451 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003452 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003453 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3454 fc->pause_time = 0xFFFF;
3455 else
3456 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003457 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003458 fc->current_mode = fc->requested_mode;
3459
3460 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003461 case e1000_ich9lan:
3462 case e1000_ich10lan:
3463 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3464 pba = 14;
3465 ew32(PBA, pba);
3466 fc->high_water = 0x2800;
3467 fc->low_water = fc->high_water - 8;
3468 break;
3469 }
3470 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003471 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003472 hwm = min(((pba << 10) * 9 / 10),
3473 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003474
3475 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3476 fc->low_water = fc->high_water - 8;
3477 break;
3478 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003479 /*
3480 * Workaround PCH LOM adapter hangs with certain network
3481 * loads. If hangs persist, try disabling Tx flow control.
3482 */
3483 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3484 fc->high_water = 0x3500;
3485 fc->low_water = 0x1500;
3486 } else {
3487 fc->high_water = 0x5000;
3488 fc->low_water = 0x3000;
3489 }
Bruce Allana3055952010-05-10 15:02:12 +00003490 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003491 break;
3492 case e1000_pch2lan:
3493 fc->high_water = 0x05C20;
3494 fc->low_water = 0x05048;
3495 fc->pause_time = 0x0650;
3496 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003497 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3498 pba = 14;
3499 ew32(PBA, pba);
3500 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003501 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003502 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003503
Bruce Allan828bac82010-09-29 21:39:37 +00003504 /*
3505 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003506 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003507 */
3508 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003509 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003510 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3511 dev_info(&adapter->pdev->dev,
3512 "Interrupt Throttle Rate turned off\n");
3513 adapter->flags2 |= FLAG2_DISABLE_AIM;
3514 ew32(ITR, 0);
3515 }
3516 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3517 dev_info(&adapter->pdev->dev,
3518 "Interrupt Throttle Rate turned on\n");
3519 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3520 adapter->itr = 20000;
3521 ew32(ITR, 1000000000 / (adapter->itr * 256));
3522 }
3523 }
3524
Auke Kokbc7f75f2007-09-17 12:30:59 -07003525 /* Allow time for pending master requests to run */
3526 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003527
3528 /*
3529 * For parts with AMT enabled, let the firmware know
3530 * that the network interface is in control
3531 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003532 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003533 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003534
Auke Kokbc7f75f2007-09-17 12:30:59 -07003535 ew32(WUC, 0);
3536
3537 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003538 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003539
3540 e1000_update_mng_vlan(adapter);
3541
3542 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3543 ew32(VET, ETH_P_8021Q);
3544
3545 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003546
3547 if (!netif_running(adapter->netdev) &&
3548 !test_bit(__E1000_TESTING, &adapter->state)) {
3549 e1000_power_down_phy(adapter);
3550 return;
3551 }
3552
Auke Kokbc7f75f2007-09-17 12:30:59 -07003553 e1000_get_phy_info(hw);
3554
Bruce Allan918d7192009-06-02 11:28:20 +00003555 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3556 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003557 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003558 /*
3559 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003560 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003561 * different we would do if it failed
3562 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003563 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3564 phy_data &= ~IGP02E1000_PM_SPD;
3565 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3566 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003567}
3568
3569int e1000e_up(struct e1000_adapter *adapter)
3570{
3571 struct e1000_hw *hw = &adapter->hw;
3572
3573 /* hardware has been reset, we need to reload some things */
3574 e1000_configure(adapter);
3575
3576 clear_bit(__E1000_DOWN, &adapter->state);
3577
Bruce Allan4662e822008-08-26 18:37:06 -07003578 if (adapter->msix_entries)
3579 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003580 e1000_irq_enable(adapter);
3581
Bruce Allan400484f2011-05-13 07:20:03 +00003582 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003583
Auke Kokbc7f75f2007-09-17 12:30:59 -07003584 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003585 if (adapter->msix_entries)
3586 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3587 else
3588 ew32(ICS, E1000_ICS_LSC);
3589
Auke Kokbc7f75f2007-09-17 12:30:59 -07003590 return 0;
3591}
3592
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003593static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3594{
3595 struct e1000_hw *hw = &adapter->hw;
3596
3597 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3598 return;
3599
3600 /* flush pending descriptor writebacks to memory */
3601 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3602 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3603
3604 /* execute the writes immediately */
3605 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003606
3607 /*
3608 * due to rare timing issues, write to TIDV/RDTR again to ensure the
3609 * write is successful
3610 */
3611 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3612 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3613
3614 /* execute the writes immediately */
3615 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003616}
3617
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003618static void e1000e_update_stats(struct e1000_adapter *adapter);
3619
Auke Kokbc7f75f2007-09-17 12:30:59 -07003620void e1000e_down(struct e1000_adapter *adapter)
3621{
3622 struct net_device *netdev = adapter->netdev;
3623 struct e1000_hw *hw = &adapter->hw;
3624 u32 tctl, rctl;
3625
Bruce Allanad680762008-03-28 09:15:03 -07003626 /*
3627 * signal that we're down so the interrupt handler does not
3628 * reschedule our watchdog timer
3629 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003630 set_bit(__E1000_DOWN, &adapter->state);
3631
3632 /* disable receives in the hardware */
3633 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003634 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3635 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003636 /* flush and sleep below */
3637
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003638 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003639
3640 /* disable transmits in the hardware */
3641 tctl = er32(TCTL);
3642 tctl &= ~E1000_TCTL_EN;
3643 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003644
Auke Kokbc7f75f2007-09-17 12:30:59 -07003645 /* flush both disables and wait for them to finish */
3646 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003647 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003648
Auke Kokbc7f75f2007-09-17 12:30:59 -07003649 e1000_irq_disable(adapter);
3650
3651 del_timer_sync(&adapter->watchdog_timer);
3652 del_timer_sync(&adapter->phy_info_timer);
3653
Auke Kokbc7f75f2007-09-17 12:30:59 -07003654 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003655
3656 spin_lock(&adapter->stats64_lock);
3657 e1000e_update_stats(adapter);
3658 spin_unlock(&adapter->stats64_lock);
3659
Bruce Allan400484f2011-05-13 07:20:03 +00003660 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003661 e1000_clean_tx_ring(adapter->tx_ring);
3662 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00003663
Auke Kokbc7f75f2007-09-17 12:30:59 -07003664 adapter->link_speed = 0;
3665 adapter->link_duplex = 0;
3666
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003667 if (!pci_channel_offline(adapter->pdev))
3668 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003669
Auke Kokbc7f75f2007-09-17 12:30:59 -07003670 /*
3671 * TODO: for power management, we could drop the link and
3672 * pci_disable_device here.
3673 */
3674}
3675
3676void e1000e_reinit_locked(struct e1000_adapter *adapter)
3677{
3678 might_sleep();
3679 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003680 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681 e1000e_down(adapter);
3682 e1000e_up(adapter);
3683 clear_bit(__E1000_RESETTING, &adapter->state);
3684}
3685
3686/**
3687 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3688 * @adapter: board private structure to initialize
3689 *
3690 * e1000_sw_init initializes the Adapter private data structure.
3691 * Fields are initialized based on PCI device information and
3692 * OS network device settings (MTU size).
3693 **/
3694static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3695{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696 struct net_device *netdev = adapter->netdev;
3697
3698 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3699 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003700 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3701 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00003702 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3703 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003704
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003705 spin_lock_init(&adapter->stats64_lock);
3706
Bruce Allan4662e822008-08-26 18:37:06 -07003707 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003708
Bruce Allan4662e822008-08-26 18:37:06 -07003709 if (e1000_alloc_queues(adapter))
3710 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003711
Auke Kokbc7f75f2007-09-17 12:30:59 -07003712 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003713 e1000_irq_disable(adapter);
3714
Auke Kokbc7f75f2007-09-17 12:30:59 -07003715 set_bit(__E1000_DOWN, &adapter->state);
3716 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003717}
3718
3719/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003720 * e1000_intr_msi_test - Interrupt Handler
3721 * @irq: interrupt number
3722 * @data: pointer to a network interface device structure
3723 **/
3724static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3725{
3726 struct net_device *netdev = data;
3727 struct e1000_adapter *adapter = netdev_priv(netdev);
3728 struct e1000_hw *hw = &adapter->hw;
3729 u32 icr = er32(ICR);
3730
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003731 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003732 if (icr & E1000_ICR_RXSEQ) {
3733 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3734 wmb();
3735 }
3736
3737 return IRQ_HANDLED;
3738}
3739
3740/**
3741 * e1000_test_msi_interrupt - Returns 0 for successful test
3742 * @adapter: board private struct
3743 *
3744 * code flow taken from tg3.c
3745 **/
3746static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3747{
3748 struct net_device *netdev = adapter->netdev;
3749 struct e1000_hw *hw = &adapter->hw;
3750 int err;
3751
3752 /* poll_enable hasn't been called yet, so don't need disable */
3753 /* clear any pending events */
3754 er32(ICR);
3755
3756 /* free the real vector and request a test handler */
3757 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003758 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003759
3760 /* Assume that the test fails, if it succeeds then the test
3761 * MSI irq handler will unset this flag */
3762 adapter->flags |= FLAG_MSI_TEST_FAILED;
3763
3764 err = pci_enable_msi(adapter->pdev);
3765 if (err)
3766 goto msi_test_failed;
3767
Joe Perchesa0607fd2009-11-18 23:29:17 -08003768 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003769 netdev->name, netdev);
3770 if (err) {
3771 pci_disable_msi(adapter->pdev);
3772 goto msi_test_failed;
3773 }
3774
3775 wmb();
3776
3777 e1000_irq_enable(adapter);
3778
3779 /* fire an unusual interrupt on the test handler */
3780 ew32(ICS, E1000_ICS_RXSEQ);
3781 e1e_flush();
3782 msleep(50);
3783
3784 e1000_irq_disable(adapter);
3785
3786 rmb();
3787
3788 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003789 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003790 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003791 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00003792 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003793 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003794
3795 free_irq(adapter->pdev->irq, netdev);
3796 pci_disable_msi(adapter->pdev);
3797
Bruce Allanf8d59f72008-08-08 18:36:11 -07003798msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003799 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003800 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003801}
3802
3803/**
3804 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3805 * @adapter: board private struct
3806 *
3807 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3808 **/
3809static int e1000_test_msi(struct e1000_adapter *adapter)
3810{
3811 int err;
3812 u16 pci_cmd;
3813
3814 if (!(adapter->flags & FLAG_MSI_ENABLED))
3815 return 0;
3816
3817 /* disable SERR in case the MSI write causes a master abort */
3818 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003819 if (pci_cmd & PCI_COMMAND_SERR)
3820 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3821 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003822
3823 err = e1000_test_msi_interrupt(adapter);
3824
Dean Nelson36f24072010-06-29 18:12:05 +00003825 /* re-enable SERR */
3826 if (pci_cmd & PCI_COMMAND_SERR) {
3827 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3828 pci_cmd |= PCI_COMMAND_SERR;
3829 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3830 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003831
Bruce Allanf8d59f72008-08-08 18:36:11 -07003832 return err;
3833}
3834
3835/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003836 * e1000_open - Called when a network interface is made active
3837 * @netdev: network interface device structure
3838 *
3839 * Returns 0 on success, negative value on failure
3840 *
3841 * The open entry point is called when a network interface is made
3842 * active by the system (IFF_UP). At this point all resources needed
3843 * for transmit and receive operations are allocated, the interrupt
3844 * handler is registered with the OS, the watchdog timer is started,
3845 * and the stack is notified that the interface is ready.
3846 **/
3847static int e1000_open(struct net_device *netdev)
3848{
3849 struct e1000_adapter *adapter = netdev_priv(netdev);
3850 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003851 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003852 int err;
3853
3854 /* disallow open during test */
3855 if (test_bit(__E1000_TESTING, &adapter->state))
3856 return -EBUSY;
3857
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003858 pm_runtime_get_sync(&pdev->dev);
3859
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003860 netif_carrier_off(netdev);
3861
Auke Kokbc7f75f2007-09-17 12:30:59 -07003862 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003863 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003864 if (err)
3865 goto err_setup_tx;
3866
3867 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003868 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003869 if (err)
3870 goto err_setup_rx;
3871
Bruce Allan11b08be2010-05-10 14:59:31 +00003872 /*
3873 * If AMT is enabled, let the firmware know that the network
3874 * interface is now open and reset the part to a known state.
3875 */
3876 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003877 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003878 e1000e_reset(adapter);
3879 }
3880
Auke Kokbc7f75f2007-09-17 12:30:59 -07003881 e1000e_power_up_phy(adapter);
3882
3883 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3884 if ((adapter->hw.mng_cookie.status &
3885 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3886 e1000_update_mng_vlan(adapter);
3887
Bruce Allan79d4e902011-12-16 00:46:27 +00003888 /* DMA latency requirement to workaround jumbo issue */
3889 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07003890 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3891 PM_QOS_CPU_DMA_LATENCY,
3892 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003893
Bruce Allanad680762008-03-28 09:15:03 -07003894 /*
Bruce Allanad680762008-03-28 09:15:03 -07003895 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003896 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3897 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003898 * clean_rx handler before we do so.
3899 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003900 e1000_configure(adapter);
3901
3902 err = e1000_request_irq(adapter);
3903 if (err)
3904 goto err_req_irq;
3905
Bruce Allanf8d59f72008-08-08 18:36:11 -07003906 /*
3907 * Work around PCIe errata with MSI interrupts causing some chipsets to
3908 * ignore e1000e MSI messages, which means we need to test our MSI
3909 * interrupt now
3910 */
Bruce Allan4662e822008-08-26 18:37:06 -07003911 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003912 err = e1000_test_msi(adapter);
3913 if (err) {
3914 e_err("Interrupt allocation failed\n");
3915 goto err_req_irq;
3916 }
3917 }
3918
Auke Kokbc7f75f2007-09-17 12:30:59 -07003919 /* From here on the code is the same as e1000e_up() */
3920 clear_bit(__E1000_DOWN, &adapter->state);
3921
3922 napi_enable(&adapter->napi);
3923
3924 e1000_irq_enable(adapter);
3925
Jeff Kirsher09357b02011-11-18 14:25:00 +00003926 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003927 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003928
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003929 adapter->idle_check = true;
3930 pm_runtime_put(&pdev->dev);
3931
Auke Kokbc7f75f2007-09-17 12:30:59 -07003932 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003933 if (adapter->msix_entries)
3934 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3935 else
3936 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003937
3938 return 0;
3939
3940err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003941 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003942 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003943 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003944err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00003945 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003946err_setup_tx:
3947 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003948 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003949
3950 return err;
3951}
3952
3953/**
3954 * e1000_close - Disables a network interface
3955 * @netdev: network interface device structure
3956 *
3957 * Returns 0, this is not allowed to fail
3958 *
3959 * The close entry point is called when an interface is de-activated
3960 * by the OS. The hardware is still under the drivers control, but
3961 * needs to be disabled. A global MAC reset is issued to stop the
3962 * hardware, and all transmit and receive resources are freed.
3963 **/
3964static int e1000_close(struct net_device *netdev)
3965{
3966 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003967 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00003968 int count = E1000_CHECK_RESET_COUNT;
3969
3970 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
3971 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003972
3973 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003974
3975 pm_runtime_get_sync(&pdev->dev);
3976
Bruce Allan5f4a7802011-11-29 08:09:19 +00003977 napi_disable(&adapter->napi);
3978
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003979 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3980 e1000e_down(adapter);
3981 e1000_free_irq(adapter);
3982 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003984
Bruce Allan55aa6982011-12-16 00:45:45 +00003985 e1000e_free_tx_resources(adapter->tx_ring);
3986 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003987
Bruce Allanad680762008-03-28 09:15:03 -07003988 /*
3989 * kill manageability vlan ID if supported, but not if a vlan with
3990 * the same ID is registered on the host OS (let 8021q kill it)
3991 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003992 if (adapter->hw.mng_cookie.status &
3993 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003994 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3995
Bruce Allanad680762008-03-28 09:15:03 -07003996 /*
3997 * If AMT is enabled, let the firmware know that the network
3998 * interface is now closed
3999 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004000 if ((adapter->flags & FLAG_HAS_AMT) &&
4001 !test_bit(__E1000_TESTING, &adapter->state))
4002 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004003
Bruce Allan79d4e902011-12-16 00:46:27 +00004004 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07004005 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004006
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004007 pm_runtime_put_sync(&pdev->dev);
4008
Auke Kokbc7f75f2007-09-17 12:30:59 -07004009 return 0;
4010}
4011/**
4012 * e1000_set_mac - Change the Ethernet Address of the NIC
4013 * @netdev: network interface device structure
4014 * @p: pointer to an address structure
4015 *
4016 * Returns 0 on success, negative on failure
4017 **/
4018static int e1000_set_mac(struct net_device *netdev, void *p)
4019{
4020 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004021 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004022 struct sockaddr *addr = p;
4023
4024 if (!is_valid_ether_addr(addr->sa_data))
4025 return -EADDRNOTAVAIL;
4026
4027 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4028 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4029
Bruce Allan69e1e012012-04-14 03:28:50 +00004030 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004031
4032 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4033 /* activate the work around */
4034 e1000e_set_laa_state_82571(&adapter->hw, 1);
4035
Bruce Allanad680762008-03-28 09:15:03 -07004036 /*
4037 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004038 * between the time RAR[0] gets clobbered and the time it
4039 * gets fixed (in e1000_watchdog), the actual LAA is in one
4040 * of the RARs and no incoming packets directed to this port
4041 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004042 * RAR[14]
4043 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004044 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4045 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004046 }
4047
4048 return 0;
4049}
4050
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004051/**
4052 * e1000e_update_phy_task - work thread to update phy
4053 * @work: pointer to our work struct
4054 *
4055 * this worker thread exists because we must acquire a
4056 * semaphore to read the phy, which we could msleep while
4057 * waiting for it, and we can't msleep in a timer.
4058 **/
4059static void e1000e_update_phy_task(struct work_struct *work)
4060{
4061 struct e1000_adapter *adapter = container_of(work,
4062 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004063
4064 if (test_bit(__E1000_DOWN, &adapter->state))
4065 return;
4066
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004067 e1000_get_phy_info(&adapter->hw);
4068}
4069
Bruce Allanad680762008-03-28 09:15:03 -07004070/*
4071 * Need to wait a few seconds after link up to get diagnostic information from
4072 * the phy
4073 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004074static void e1000_update_phy_info(unsigned long data)
4075{
4076 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004077
4078 if (test_bit(__E1000_DOWN, &adapter->state))
4079 return;
4080
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004081 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004082}
4083
4084/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004085 * e1000e_update_phy_stats - Update the PHY statistics counters
4086 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004087 *
4088 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004089 **/
4090static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4091{
4092 struct e1000_hw *hw = &adapter->hw;
4093 s32 ret_val;
4094 u16 phy_data;
4095
4096 ret_val = hw->phy.ops.acquire(hw);
4097 if (ret_val)
4098 return;
4099
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004100 /*
4101 * A page set is expensive so check if already on desired page.
4102 * If not, set to the page with the PHY status registers.
4103 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004104 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004105 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4106 &phy_data);
4107 if (ret_val)
4108 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004109 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4110 ret_val = hw->phy.ops.set_page(hw,
4111 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004112 if (ret_val)
4113 goto release;
4114 }
4115
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004116 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004117 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4118 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004119 if (!ret_val)
4120 adapter->stats.scc += phy_data;
4121
4122 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004123 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4124 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004125 if (!ret_val)
4126 adapter->stats.ecol += phy_data;
4127
4128 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004129 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4130 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004131 if (!ret_val)
4132 adapter->stats.mcc += phy_data;
4133
4134 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004135 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4136 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004137 if (!ret_val)
4138 adapter->stats.latecol += phy_data;
4139
4140 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004141 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4142 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004143 if (!ret_val)
4144 hw->mac.collision_delta = phy_data;
4145
4146 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004147 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4148 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004149 if (!ret_val)
4150 adapter->stats.dc += phy_data;
4151
4152 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004153 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4154 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004155 if (!ret_val)
4156 adapter->stats.tncrs += phy_data;
4157
4158release:
4159 hw->phy.ops.release(hw);
4160}
4161
4162/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004163 * e1000e_update_stats - Update the board statistics counters
4164 * @adapter: board private structure
4165 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004166static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004167{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004168 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004169 struct e1000_hw *hw = &adapter->hw;
4170 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004171
4172 /*
4173 * Prevent stats update while adapter is being reset, or if the pci
4174 * connection is down.
4175 */
4176 if (adapter->link_speed == 0)
4177 return;
4178 if (pci_channel_offline(pdev))
4179 return;
4180
Auke Kokbc7f75f2007-09-17 12:30:59 -07004181 adapter->stats.crcerrs += er32(CRCERRS);
4182 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004183 adapter->stats.gorc += er32(GORCL);
4184 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004185 adapter->stats.bprc += er32(BPRC);
4186 adapter->stats.mprc += er32(MPRC);
4187 adapter->stats.roc += er32(ROC);
4188
Auke Kokbc7f75f2007-09-17 12:30:59 -07004189 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004190
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004191 /* Half-duplex statistics */
4192 if (adapter->link_duplex == HALF_DUPLEX) {
4193 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4194 e1000e_update_phy_stats(adapter);
4195 } else {
4196 adapter->stats.scc += er32(SCC);
4197 adapter->stats.ecol += er32(ECOL);
4198 adapter->stats.mcc += er32(MCC);
4199 adapter->stats.latecol += er32(LATECOL);
4200 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004201
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004202 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004203
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004204 if ((hw->mac.type != e1000_82574) &&
4205 (hw->mac.type != e1000_82583))
4206 adapter->stats.tncrs += er32(TNCRS);
4207 }
4208 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004209 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004210
Auke Kokbc7f75f2007-09-17 12:30:59 -07004211 adapter->stats.xonrxc += er32(XONRXC);
4212 adapter->stats.xontxc += er32(XONTXC);
4213 adapter->stats.xoffrxc += er32(XOFFRXC);
4214 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004215 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004216 adapter->stats.gotc += er32(GOTCL);
4217 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004218 adapter->stats.rnbc += er32(RNBC);
4219 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004220
4221 adapter->stats.mptc += er32(MPTC);
4222 adapter->stats.bptc += er32(BPTC);
4223
4224 /* used for adaptive IFS */
4225
4226 hw->mac.tx_packet_delta = er32(TPT);
4227 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004228
4229 adapter->stats.algnerrc += er32(ALGNERRC);
4230 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004231 adapter->stats.cexterr += er32(CEXTERR);
4232 adapter->stats.tsctc += er32(TSCTC);
4233 adapter->stats.tsctfc += er32(TSCTFC);
4234
Auke Kokbc7f75f2007-09-17 12:30:59 -07004235 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004236 netdev->stats.multicast = adapter->stats.mprc;
4237 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004238
4239 /* Rx Errors */
4240
Bruce Allanad680762008-03-28 09:15:03 -07004241 /*
4242 * RLEC on some newer hardware can be incorrect so build
4243 * our own version based on RUC and ROC
4244 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004245 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004246 adapter->stats.crcerrs + adapter->stats.algnerrc +
4247 adapter->stats.ruc + adapter->stats.roc +
4248 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004249 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004250 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004251 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4252 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4253 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004254
4255 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004256 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004257 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004258 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4259 netdev->stats.tx_window_errors = adapter->stats.latecol;
4260 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004261
4262 /* Tx Dropped needs to be maintained elsewhere */
4263
Auke Kokbc7f75f2007-09-17 12:30:59 -07004264 /* Management Stats */
4265 adapter->stats.mgptc += er32(MGTPTC);
4266 adapter->stats.mgprc += er32(MGTPRC);
4267 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004268}
4269
Bruce Allan7c257692008-04-23 11:09:00 -07004270/**
4271 * e1000_phy_read_status - Update the PHY register status snapshot
4272 * @adapter: board private structure
4273 **/
4274static void e1000_phy_read_status(struct e1000_adapter *adapter)
4275{
4276 struct e1000_hw *hw = &adapter->hw;
4277 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004278
4279 if ((er32(STATUS) & E1000_STATUS_LU) &&
4280 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004281 int ret_val;
4282
Bruce Allan7c257692008-04-23 11:09:00 -07004283 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4284 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4285 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4286 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4287 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4288 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4289 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4290 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4291 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004292 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004293 } else {
4294 /*
4295 * Do not read PHY registers if link is not up
4296 * Set values to typical power-on defaults
4297 */
4298 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4299 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4300 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4301 BMSR_ERCAP);
4302 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4303 ADVERTISE_ALL | ADVERTISE_CSMA);
4304 phy->lpa = 0;
4305 phy->expansion = EXPANSION_ENABLENPAGE;
4306 phy->ctrl1000 = ADVERTISE_1000FULL;
4307 phy->stat1000 = 0;
4308 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4309 }
Bruce Allan7c257692008-04-23 11:09:00 -07004310}
4311
Auke Kokbc7f75f2007-09-17 12:30:59 -07004312static void e1000_print_link_info(struct e1000_adapter *adapter)
4313{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004314 struct e1000_hw *hw = &adapter->hw;
4315 u32 ctrl = er32(CTRL);
4316
Bruce Allan8f12fe82008-11-21 16:54:43 -08004317 /* Link status message must follow this format for user tools */
Jeff Kirsheref456f82011-11-03 11:40:28 +00004318 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4319 adapter->netdev->name,
4320 adapter->link_speed,
4321 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4322 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4323 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4324 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004325}
4326
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004327static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004328{
4329 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004330 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004331 s32 ret_val = 0;
4332
4333 /*
4334 * get_link_status is set on LSC (link status) interrupt or
4335 * Rx sequence error interrupt. get_link_status will stay
4336 * false until the check_for_link establishes link
4337 * for copper adapters ONLY
4338 */
4339 switch (hw->phy.media_type) {
4340 case e1000_media_type_copper:
4341 if (hw->mac.get_link_status) {
4342 ret_val = hw->mac.ops.check_for_link(hw);
4343 link_active = !hw->mac.get_link_status;
4344 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004345 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004346 }
4347 break;
4348 case e1000_media_type_fiber:
4349 ret_val = hw->mac.ops.check_for_link(hw);
4350 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4351 break;
4352 case e1000_media_type_internal_serdes:
4353 ret_val = hw->mac.ops.check_for_link(hw);
4354 link_active = adapter->hw.mac.serdes_has_link;
4355 break;
4356 default:
4357 case e1000_media_type_unknown:
4358 break;
4359 }
4360
4361 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4362 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4363 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004364 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004365 }
4366
4367 return link_active;
4368}
4369
4370static void e1000e_enable_receives(struct e1000_adapter *adapter)
4371{
4372 /* make sure the receive unit is started */
4373 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4374 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4375 struct e1000_hw *hw = &adapter->hw;
4376 u32 rctl = er32(RCTL);
4377 ew32(RCTL, rctl | E1000_RCTL_EN);
4378 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4379 }
4380}
4381
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004382static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4383{
4384 struct e1000_hw *hw = &adapter->hw;
4385
4386 /*
4387 * With 82574 controllers, PHY needs to be checked periodically
4388 * for hung state and reset, if two calls return true
4389 */
4390 if (e1000_check_phy_82574(hw))
4391 adapter->phy_hang_count++;
4392 else
4393 adapter->phy_hang_count = 0;
4394
4395 if (adapter->phy_hang_count > 1) {
4396 adapter->phy_hang_count = 0;
4397 schedule_work(&adapter->reset_task);
4398 }
4399}
4400
Auke Kokbc7f75f2007-09-17 12:30:59 -07004401/**
4402 * e1000_watchdog - Timer Call-back
4403 * @data: pointer to adapter cast into an unsigned long
4404 **/
4405static void e1000_watchdog(unsigned long data)
4406{
4407 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4408
4409 /* Do the rest outside of interrupt context */
4410 schedule_work(&adapter->watchdog_task);
4411
4412 /* TODO: make this use queue_delayed_work() */
4413}
4414
4415static void e1000_watchdog_task(struct work_struct *work)
4416{
4417 struct e1000_adapter *adapter = container_of(work,
4418 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004419 struct net_device *netdev = adapter->netdev;
4420 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004421 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004422 struct e1000_ring *tx_ring = adapter->tx_ring;
4423 struct e1000_hw *hw = &adapter->hw;
4424 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004425
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004426 if (test_bit(__E1000_DOWN, &adapter->state))
4427 return;
4428
David S. Millerb405e8d2010-02-04 22:31:41 -08004429 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004430 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004431 /* Cancel scheduled suspend requests. */
4432 pm_runtime_resume(netdev->dev.parent);
4433
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004434 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004435 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004436 }
4437
4438 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4439 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4440 e1000_update_mng_vlan(adapter);
4441
Auke Kokbc7f75f2007-09-17 12:30:59 -07004442 if (link) {
4443 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004444 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004445
4446 /* Cancel scheduled suspend requests. */
4447 pm_runtime_resume(netdev->dev.parent);
4448
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004449 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004450 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004451 mac->ops.get_link_up_info(&adapter->hw,
4452 &adapter->link_speed,
4453 &adapter->link_duplex);
4454 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004455 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004456 * On supported PHYs, check for duplex mismatch only
4457 * if link has autonegotiated at 10/100 half
4458 */
4459 if ((hw->phy.type == e1000_phy_igp_3 ||
4460 hw->phy.type == e1000_phy_bm) &&
4461 (hw->mac.autoneg == true) &&
4462 (adapter->link_speed == SPEED_10 ||
4463 adapter->link_speed == SPEED_100) &&
4464 (adapter->link_duplex == HALF_DUPLEX)) {
4465 u16 autoneg_exp;
4466
4467 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4468
4469 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004470 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07004471 }
4472
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004473 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004474 adapter->tx_timeout_factor = 1;
4475 switch (adapter->link_speed) {
4476 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004477 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004478 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004479 break;
4480 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004481 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004482 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004483 break;
4484 }
4485
Bruce Allanad680762008-03-28 09:15:03 -07004486 /*
4487 * workaround: re-program speed mode bit after
4488 * link-up event
4489 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004490 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4491 !txb2b) {
4492 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004493 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004494 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004495 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004496 }
4497
Bruce Allanad680762008-03-28 09:15:03 -07004498 /*
4499 * disable TSO for pcie and 10/100 speeds, to avoid
4500 * some hardware issues
4501 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004502 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4503 switch (adapter->link_speed) {
4504 case SPEED_10:
4505 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004506 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004507 netdev->features &= ~NETIF_F_TSO;
4508 netdev->features &= ~NETIF_F_TSO6;
4509 break;
4510 case SPEED_1000:
4511 netdev->features |= NETIF_F_TSO;
4512 netdev->features |= NETIF_F_TSO6;
4513 break;
4514 default:
4515 /* oops */
4516 break;
4517 }
4518 }
4519
Bruce Allanad680762008-03-28 09:15:03 -07004520 /*
4521 * enable transmits in the hardware, need to do this
4522 * after setting TARC(0)
4523 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004524 tctl = er32(TCTL);
4525 tctl |= E1000_TCTL_EN;
4526 ew32(TCTL, tctl);
4527
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004528 /*
4529 * Perform any post-link-up configuration before
4530 * reporting link up.
4531 */
4532 if (phy->ops.cfg_on_link_up)
4533 phy->ops.cfg_on_link_up(hw);
4534
Auke Kokbc7f75f2007-09-17 12:30:59 -07004535 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004536
4537 if (!test_bit(__E1000_DOWN, &adapter->state))
4538 mod_timer(&adapter->phy_info_timer,
4539 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540 }
4541 } else {
4542 if (netif_carrier_ok(netdev)) {
4543 adapter->link_speed = 0;
4544 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004545 /* Link status message must follow this format */
4546 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4547 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004548 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004549 if (!test_bit(__E1000_DOWN, &adapter->state))
4550 mod_timer(&adapter->phy_info_timer,
4551 round_jiffies(jiffies + 2 * HZ));
4552
4553 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4554 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004555 else
4556 pm_schedule_suspend(netdev->dev.parent,
4557 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004558 }
4559 }
4560
4561link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004562 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004563 e1000e_update_stats(adapter);
4564
4565 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4566 adapter->tpt_old = adapter->stats.tpt;
4567 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4568 adapter->colc_old = adapter->stats.colc;
4569
Bruce Allan7c257692008-04-23 11:09:00 -07004570 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4571 adapter->gorc_old = adapter->stats.gorc;
4572 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4573 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004574 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004575
4576 e1000e_update_adaptive(&adapter->hw);
4577
Bruce Allan90da0662011-01-06 07:02:53 +00004578 if (!netif_carrier_ok(netdev) &&
4579 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4580 /*
4581 * We've lost link, so the controller stops DMA,
4582 * but we've got queued Tx work that's never going
4583 * to get done, so reset controller to flush Tx.
4584 * (Do the reset outside of interrupt context).
4585 */
Bruce Allan90da0662011-01-06 07:02:53 +00004586 schedule_work(&adapter->reset_task);
4587 /* return immediately since reset is imminent */
4588 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004589 }
4590
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004591 /* Simple mode for Interrupt Throttle Rate (ITR) */
4592 if (adapter->itr_setting == 4) {
4593 /*
4594 * Symmetric Tx/Rx gets a reduced ITR=2000;
4595 * Total asymmetrical Tx or Rx gets ITR=8000;
4596 * everyone else is between 2000-8000.
4597 */
4598 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4599 u32 dif = (adapter->gotc > adapter->gorc ?
4600 adapter->gotc - adapter->gorc :
4601 adapter->gorc - adapter->gotc) / 10000;
4602 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4603
4604 ew32(ITR, 1000000000 / (itr * 256));
4605 }
4606
Bruce Allanad680762008-03-28 09:15:03 -07004607 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004608 if (adapter->msix_entries)
4609 ew32(ICS, adapter->rx_ring->ims_val);
4610 else
4611 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004612
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004613 /* flush pending descriptors to memory before detecting Tx hang */
4614 e1000e_flush_descriptors(adapter);
4615
Auke Kokbc7f75f2007-09-17 12:30:59 -07004616 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004617 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004618
Bruce Allanad680762008-03-28 09:15:03 -07004619 /*
4620 * With 82571 controllers, LAA may be overwritten due to controller
4621 * reset from the other port. Set the appropriate LAA in RAR[0]
4622 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004623 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00004624 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004625
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004626 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4627 e1000e_check_82574_phy_workaround(adapter);
4628
Auke Kokbc7f75f2007-09-17 12:30:59 -07004629 /* Reset the timer */
4630 if (!test_bit(__E1000_DOWN, &adapter->state))
4631 mod_timer(&adapter->watchdog_timer,
4632 round_jiffies(jiffies + 2 * HZ));
4633}
4634
4635#define E1000_TX_FLAGS_CSUM 0x00000001
4636#define E1000_TX_FLAGS_VLAN 0x00000002
4637#define E1000_TX_FLAGS_TSO 0x00000004
4638#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00004639#define E1000_TX_FLAGS_NO_FCS 0x00000010
Auke Kokbc7f75f2007-09-17 12:30:59 -07004640#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4641#define E1000_TX_FLAGS_VLAN_SHIFT 16
4642
Bruce Allan55aa6982011-12-16 00:45:45 +00004643static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004644{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004645 struct e1000_context_desc *context_desc;
4646 struct e1000_buffer *buffer_info;
4647 unsigned int i;
4648 u32 cmd_length = 0;
4649 u16 ipcse = 0, tucse, mss;
4650 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004651
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004652 if (!skb_is_gso(skb))
4653 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004654
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004655 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004656 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4657
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004658 if (err)
4659 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004660 }
4661
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004662 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4663 mss = skb_shinfo(skb)->gso_size;
4664 if (skb->protocol == htons(ETH_P_IP)) {
4665 struct iphdr *iph = ip_hdr(skb);
4666 iph->tot_len = 0;
4667 iph->check = 0;
4668 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4669 0, IPPROTO_TCP, 0);
4670 cmd_length = E1000_TXD_CMD_IP;
4671 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004672 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004673 ipv6_hdr(skb)->payload_len = 0;
4674 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4675 &ipv6_hdr(skb)->daddr,
4676 0, IPPROTO_TCP, 0);
4677 ipcse = 0;
4678 }
4679 ipcss = skb_network_offset(skb);
4680 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4681 tucss = skb_transport_offset(skb);
4682 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4683 tucse = 0;
4684
4685 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4686 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4687
4688 i = tx_ring->next_to_use;
4689 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4690 buffer_info = &tx_ring->buffer_info[i];
4691
4692 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4693 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4694 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4695 context_desc->upper_setup.tcp_fields.tucss = tucss;
4696 context_desc->upper_setup.tcp_fields.tucso = tucso;
4697 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4698 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4699 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4700 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4701
4702 buffer_info->time_stamp = jiffies;
4703 buffer_info->next_to_watch = i;
4704
4705 i++;
4706 if (i == tx_ring->count)
4707 i = 0;
4708 tx_ring->next_to_use = i;
4709
4710 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004711}
4712
Bruce Allan55aa6982011-12-16 00:45:45 +00004713static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004714{
Bruce Allan55aa6982011-12-16 00:45:45 +00004715 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004716 struct e1000_context_desc *context_desc;
4717 struct e1000_buffer *buffer_info;
4718 unsigned int i;
4719 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004720 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004721 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004722
Dave Grahamaf807c82008-10-09 14:28:58 -07004723 if (skb->ip_summed != CHECKSUM_PARTIAL)
4724 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004725
Arthur Jones5f66f202009-03-19 01:13:08 +00004726 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4727 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4728 else
4729 protocol = skb->protocol;
4730
Arthur Jones3f518392009-03-20 15:56:35 -07004731 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004732 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004733 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4734 cmd_len |= E1000_TXD_CMD_TCP;
4735 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004736 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004737 /* XXX not handling all IPV6 headers */
4738 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4739 cmd_len |= E1000_TXD_CMD_TCP;
4740 break;
4741 default:
4742 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004743 e_warn("checksum_partial proto=%x!\n",
4744 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004745 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004746 }
4747
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004748 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004749
4750 i = tx_ring->next_to_use;
4751 buffer_info = &tx_ring->buffer_info[i];
4752 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4753
4754 context_desc->lower_setup.ip_config = 0;
4755 context_desc->upper_setup.tcp_fields.tucss = css;
4756 context_desc->upper_setup.tcp_fields.tucso =
4757 css + skb->csum_offset;
4758 context_desc->upper_setup.tcp_fields.tucse = 0;
4759 context_desc->tcp_seg_setup.data = 0;
4760 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4761
4762 buffer_info->time_stamp = jiffies;
4763 buffer_info->next_to_watch = i;
4764
4765 i++;
4766 if (i == tx_ring->count)
4767 i = 0;
4768 tx_ring->next_to_use = i;
4769
4770 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004771}
4772
4773#define E1000_MAX_PER_TXD 8192
4774#define E1000_MAX_TXD_PWR 12
4775
Bruce Allan55aa6982011-12-16 00:45:45 +00004776static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
4777 unsigned int first, unsigned int max_per_txd,
4778 unsigned int nr_frags, unsigned int mss)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004779{
Bruce Allan55aa6982011-12-16 00:45:45 +00004780 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00004781 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004782 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004783 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004784 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004785 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004786
4787 i = tx_ring->next_to_use;
4788
4789 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004790 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004791 size = min(len, max_per_txd);
4792
Auke Kokbc7f75f2007-09-17 12:30:59 -07004793 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004794 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004795 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004796 buffer_info->dma = dma_map_single(&pdev->dev,
4797 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004798 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004799 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004800 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004801 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004802
4803 len -= size;
4804 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004805 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004806
4807 if (len) {
4808 i++;
4809 if (i == tx_ring->count)
4810 i = 0;
4811 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004812 }
4813
4814 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004815 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004816
4817 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004818 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004819 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004820
4821 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004822 i++;
4823 if (i == tx_ring->count)
4824 i = 0;
4825
Auke Kokbc7f75f2007-09-17 12:30:59 -07004826 buffer_info = &tx_ring->buffer_info[i];
4827 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004828
4829 buffer_info->length = size;
4830 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004831 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004832 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4833 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004834 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004835 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004836 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004837
4838 len -= size;
4839 offset += size;
4840 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004841 }
4842 }
4843
Bruce Allanaf667a22010-12-31 06:10:01 +00004844 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004845 /* multiply data chunks by size of headers */
4846 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4847
Auke Kokbc7f75f2007-09-17 12:30:59 -07004848 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004849 tx_ring->buffer_info[i].segs = segs;
4850 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004851 tx_ring->buffer_info[first].next_to_watch = i;
4852
4853 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004854
4855dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004856 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004857 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004858 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004859 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004860
4861 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004862 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004863 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004864 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004865 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00004866 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004867 }
4868
4869 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004870}
4871
Bruce Allan55aa6982011-12-16 00:45:45 +00004872static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004873{
Bruce Allan55aa6982011-12-16 00:45:45 +00004874 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004875 struct e1000_tx_desc *tx_desc = NULL;
4876 struct e1000_buffer *buffer_info;
4877 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4878 unsigned int i;
4879
4880 if (tx_flags & E1000_TX_FLAGS_TSO) {
4881 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4882 E1000_TXD_CMD_TSE;
4883 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4884
4885 if (tx_flags & E1000_TX_FLAGS_IPV4)
4886 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4887 }
4888
4889 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4890 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4891 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4892 }
4893
4894 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4895 txd_lower |= E1000_TXD_CMD_VLE;
4896 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4897 }
4898
Ben Greear943146d2012-02-11 15:39:40 +00004899 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4900 txd_lower &= ~(E1000_TXD_CMD_IFCS);
4901
Auke Kokbc7f75f2007-09-17 12:30:59 -07004902 i = tx_ring->next_to_use;
4903
Bruce Allan36b973d2010-11-24 07:42:43 +00004904 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004905 buffer_info = &tx_ring->buffer_info[i];
4906 tx_desc = E1000_TX_DESC(*tx_ring, i);
4907 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4908 tx_desc->lower.data =
4909 cpu_to_le32(txd_lower | buffer_info->length);
4910 tx_desc->upper.data = cpu_to_le32(txd_upper);
4911
4912 i++;
4913 if (i == tx_ring->count)
4914 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004915 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004916
4917 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4918
Ben Greear943146d2012-02-11 15:39:40 +00004919 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
4920 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4921 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
4922
Bruce Allanad680762008-03-28 09:15:03 -07004923 /*
4924 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004925 * know there are new descriptors to fetch. (Only
4926 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004927 * such as IA-64).
4928 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004929 wmb();
4930
4931 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004932
4933 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00004934 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07004935 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00004936 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07004937
Bruce Allanad680762008-03-28 09:15:03 -07004938 /*
4939 * we need this if more than one processor can write to our tail
4940 * at a time, it synchronizes IO on IA64/Altix systems
4941 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004942 mmiowb();
4943}
4944
4945#define MINIMUM_DHCP_PACKET_SIZE 282
4946static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4947 struct sk_buff *skb)
4948{
4949 struct e1000_hw *hw = &adapter->hw;
4950 u16 length, offset;
4951
4952 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004953 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4954 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004955 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4956 return 0;
4957 }
4958
4959 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4960 return 0;
4961
4962 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4963 return 0;
4964
4965 {
4966 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4967 struct udphdr *udp;
4968
4969 if (ip->protocol != IPPROTO_UDP)
4970 return 0;
4971
4972 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4973 if (ntohs(udp->dest) != 67)
4974 return 0;
4975
4976 offset = (u8 *)udp + 8 - skb->data;
4977 length = skb->len - offset;
4978 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4979 }
4980
4981 return 0;
4982}
4983
Bruce Allan55aa6982011-12-16 00:45:45 +00004984static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004985{
Bruce Allan55aa6982011-12-16 00:45:45 +00004986 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004987
Bruce Allan55aa6982011-12-16 00:45:45 +00004988 netif_stop_queue(adapter->netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004989 /*
4990 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004991 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004992 * but since that doesn't exist yet, just open code it.
4993 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004994 smp_mb();
4995
Bruce Allanad680762008-03-28 09:15:03 -07004996 /*
4997 * We need to check again in a case another CPU has just
4998 * made room available.
4999 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005000 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005001 return -EBUSY;
5002
5003 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005004 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005005 ++adapter->restart_queue;
5006 return 0;
5007}
5008
Bruce Allan55aa6982011-12-16 00:45:45 +00005009static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005010{
Bruce Allan55aa6982011-12-16 00:45:45 +00005011 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005012 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005013 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005014}
5015
Bruce Allan0e15df42012-01-31 06:37:11 +00005016#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1)
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005017static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5018 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005019{
5020 struct e1000_adapter *adapter = netdev_priv(netdev);
5021 struct e1000_ring *tx_ring = adapter->tx_ring;
5022 unsigned int first;
5023 unsigned int max_per_txd = E1000_MAX_PER_TXD;
5024 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
5025 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005026 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005027 unsigned int nr_frags;
5028 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005029 int count = 0;
5030 int tso;
5031 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005032
5033 if (test_bit(__E1000_DOWN, &adapter->state)) {
5034 dev_kfree_skb_any(skb);
5035 return NETDEV_TX_OK;
5036 }
5037
5038 if (skb->len <= 0) {
5039 dev_kfree_skb_any(skb);
5040 return NETDEV_TX_OK;
5041 }
5042
5043 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07005044 /*
5045 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07005046 * make sure there is enough room in the FIFO before
5047 * initiating the DMA for each buffer. The calc is:
5048 * 4 = ceil(buffer len/mss). To make sure we don't
5049 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07005050 * drops.
5051 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005052 if (mss) {
5053 u8 hdr_len;
5054 max_per_txd = min(mss << 2, max_per_txd);
5055 max_txd_pwr = fls(max_per_txd) - 1;
5056
Bruce Allanad680762008-03-28 09:15:03 -07005057 /*
5058 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
5059 * points to just header, pull a few bytes of payload from
5060 * frags into skb->data
5061 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005062 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07005063 /*
5064 * we do this workaround for ES2LAN, but it is un-necessary,
5065 * avoiding it could save a lot of cycles
5066 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005067 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005068 unsigned int pull_size;
5069
Bruce Allana2a5b322012-01-31 06:37:17 +00005070 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005071 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005072 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005073 dev_kfree_skb_any(skb);
5074 return NETDEV_TX_OK;
5075 }
Eric Dumazete743d312010-04-14 15:59:40 -07005076 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005077 }
5078 }
5079
5080 /* reserve a descriptor for the offload context */
5081 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5082 count++;
5083 count++;
5084
5085 count += TXD_USE_COUNT(len, max_txd_pwr);
5086
5087 nr_frags = skb_shinfo(skb)->nr_frags;
5088 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00005089 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07005090 max_txd_pwr);
5091
5092 if (adapter->hw.mac.tx_pkt_filtering)
5093 e1000_transfer_dhcp_info(adapter, skb);
5094
Bruce Allanad680762008-03-28 09:15:03 -07005095 /*
5096 * need: count + 2 desc gap to keep tail from touching
5097 * head, otherwise try next time
5098 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005099 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005100 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005101
Jesse Grosseab6d182010-10-20 13:56:03 +00005102 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005103 tx_flags |= E1000_TX_FLAGS_VLAN;
5104 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5105 }
5106
5107 first = tx_ring->next_to_use;
5108
Bruce Allan55aa6982011-12-16 00:45:45 +00005109 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005110 if (tso < 0) {
5111 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005112 return NETDEV_TX_OK;
5113 }
5114
5115 if (tso)
5116 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005117 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005118 tx_flags |= E1000_TX_FLAGS_CSUM;
5119
Bruce Allanad680762008-03-28 09:15:03 -07005120 /*
5121 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005122 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005123 * no longer assume, we must.
5124 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005125 if (skb->protocol == htons(ETH_P_IP))
5126 tx_flags |= E1000_TX_FLAGS_IPV4;
5127
Ben Greear943146d2012-02-11 15:39:40 +00005128 if (unlikely(skb->no_fcs))
5129 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5130
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005131 /* if count is 0 then mapping error has occurred */
Bruce Allan55aa6982011-12-16 00:45:45 +00005132 count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005133 if (count) {
Willem de Bruijn80be3122012-04-27 09:04:05 +00005134 skb_tx_timestamp(skb);
5135
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005136 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005137 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005138 /* Make sure there is space in the ring for the next send. */
Bruce Allan55aa6982011-12-16 00:45:45 +00005139 e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005140
5141 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005142 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005143 tx_ring->buffer_info[first].time_stamp = 0;
5144 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005145 }
5146
Auke Kokbc7f75f2007-09-17 12:30:59 -07005147 return NETDEV_TX_OK;
5148}
5149
5150/**
5151 * e1000_tx_timeout - Respond to a Tx Hang
5152 * @netdev: network interface device structure
5153 **/
5154static void e1000_tx_timeout(struct net_device *netdev)
5155{
5156 struct e1000_adapter *adapter = netdev_priv(netdev);
5157
5158 /* Do the reset outside of interrupt context */
5159 adapter->tx_timeout_count++;
5160 schedule_work(&adapter->reset_task);
5161}
5162
5163static void e1000_reset_task(struct work_struct *work)
5164{
5165 struct e1000_adapter *adapter;
5166 adapter = container_of(work, struct e1000_adapter, reset_task);
5167
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005168 /* don't run the task if already down */
5169 if (test_bit(__E1000_DOWN, &adapter->state))
5170 return;
5171
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005172 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5173 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5174 e1000e_dump(adapter);
5175 e_err("Reset adapter\n");
5176 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005177 e1000e_reinit_locked(adapter);
5178}
5179
5180/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005181 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005182 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005183 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005184 *
5185 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005186 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005187struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5188 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005189{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005190 struct e1000_adapter *adapter = netdev_priv(netdev);
5191
5192 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5193 spin_lock(&adapter->stats64_lock);
5194 e1000e_update_stats(adapter);
5195 /* Fill out the OS statistics structure */
5196 stats->rx_bytes = adapter->stats.gorc;
5197 stats->rx_packets = adapter->stats.gprc;
5198 stats->tx_bytes = adapter->stats.gotc;
5199 stats->tx_packets = adapter->stats.gptc;
5200 stats->multicast = adapter->stats.mprc;
5201 stats->collisions = adapter->stats.colc;
5202
5203 /* Rx Errors */
5204
5205 /*
5206 * RLEC on some newer hardware can be incorrect so build
5207 * our own version based on RUC and ROC
5208 */
5209 stats->rx_errors = adapter->stats.rxerrc +
5210 adapter->stats.crcerrs + adapter->stats.algnerrc +
5211 adapter->stats.ruc + adapter->stats.roc +
5212 adapter->stats.cexterr;
5213 stats->rx_length_errors = adapter->stats.ruc +
5214 adapter->stats.roc;
5215 stats->rx_crc_errors = adapter->stats.crcerrs;
5216 stats->rx_frame_errors = adapter->stats.algnerrc;
5217 stats->rx_missed_errors = adapter->stats.mpc;
5218
5219 /* Tx Errors */
5220 stats->tx_errors = adapter->stats.ecol +
5221 adapter->stats.latecol;
5222 stats->tx_aborted_errors = adapter->stats.ecol;
5223 stats->tx_window_errors = adapter->stats.latecol;
5224 stats->tx_carrier_errors = adapter->stats.tncrs;
5225
5226 /* Tx Dropped needs to be maintained elsewhere */
5227
5228 spin_unlock(&adapter->stats64_lock);
5229 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005230}
5231
5232/**
5233 * e1000_change_mtu - Change the Maximum Transfer Unit
5234 * @netdev: network interface device structure
5235 * @new_mtu: new value for maximum frame size
5236 *
5237 * Returns 0 on success, negative on failure
5238 **/
5239static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5240{
5241 struct e1000_adapter *adapter = netdev_priv(netdev);
5242 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5243
Bruce Allan2adc55c2009-06-02 11:28:58 +00005244 /* Jumbo frame support */
Bruce Allan70495a52012-01-11 01:26:50 +00005245 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
5246 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5247 e_err("Jumbo Frames not supported.\n");
5248 return -EINVAL;
5249 }
5250
5251 /*
5252 * IP payload checksum (enabled with jumbos/packet-split when
5253 * Rx checksum is enabled) and generation of RSS hash is
5254 * mutually exclusive in the hardware.
5255 */
5256 if ((netdev->features & NETIF_F_RXCSUM) &&
5257 (netdev->features & NETIF_F_RXHASH)) {
5258 e_err("Jumbo frames cannot be enabled when both receive checksum offload and receive hashing are enabled. Disable one of the receive offload features before enabling jumbos.\n");
5259 return -EINVAL;
5260 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005261 }
5262
Bruce Allan2adc55c2009-06-02 11:28:58 +00005263 /* Supported frame sizes */
5264 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5265 (max_frame > adapter->max_hw_frame_size)) {
5266 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005267 return -EINVAL;
5268 }
5269
Bruce Allana1ce6472010-09-22 17:16:40 +00005270 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5271 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5272 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5273 (new_mtu > ETH_DATA_LEN)) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00005274 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005275 return -EINVAL;
5276 }
5277
Bruce Allan6f461f62010-04-27 03:33:04 +00005278 /* 82573 Errata 17 */
5279 if (((adapter->hw.mac.type == e1000_82573) ||
5280 (adapter->hw.mac.type == e1000_82574)) &&
5281 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5282 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5283 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5284 }
5285
Auke Kokbc7f75f2007-09-17 12:30:59 -07005286 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005287 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005288 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005289 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005290 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5291 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005292 if (netif_running(netdev))
5293 e1000e_down(adapter);
5294
Bruce Allanad680762008-03-28 09:15:03 -07005295 /*
5296 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005297 * means we reserve 2 more, this pushes us to allocate from the next
5298 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005299 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005300 * However with the new *_jumbo_rx* routines, jumbo receives will use
5301 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005302 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005303
Jesse Brandeburg99261462010-01-22 22:56:16 +00005304 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005305 adapter->rx_buffer_len = 2048;
5306 else
5307 adapter->rx_buffer_len = 4096;
5308
5309 /* adjust allocation if LPE protects us, and we aren't using SBP */
5310 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5311 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5312 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005313 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005314
Auke Kokbc7f75f2007-09-17 12:30:59 -07005315 if (netif_running(netdev))
5316 e1000e_up(adapter);
5317 else
5318 e1000e_reset(adapter);
5319
5320 clear_bit(__E1000_RESETTING, &adapter->state);
5321
5322 return 0;
5323}
5324
5325static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5326 int cmd)
5327{
5328 struct e1000_adapter *adapter = netdev_priv(netdev);
5329 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005330
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005331 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005332 return -EOPNOTSUPP;
5333
5334 switch (cmd) {
5335 case SIOCGMIIPHY:
5336 data->phy_id = adapter->hw.phy.addr;
5337 break;
5338 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005339 e1000_phy_read_status(adapter);
5340
Bruce Allan7c257692008-04-23 11:09:00 -07005341 switch (data->reg_num & 0x1F) {
5342 case MII_BMCR:
5343 data->val_out = adapter->phy_regs.bmcr;
5344 break;
5345 case MII_BMSR:
5346 data->val_out = adapter->phy_regs.bmsr;
5347 break;
5348 case MII_PHYSID1:
5349 data->val_out = (adapter->hw.phy.id >> 16);
5350 break;
5351 case MII_PHYSID2:
5352 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5353 break;
5354 case MII_ADVERTISE:
5355 data->val_out = adapter->phy_regs.advertise;
5356 break;
5357 case MII_LPA:
5358 data->val_out = adapter->phy_regs.lpa;
5359 break;
5360 case MII_EXPANSION:
5361 data->val_out = adapter->phy_regs.expansion;
5362 break;
5363 case MII_CTRL1000:
5364 data->val_out = adapter->phy_regs.ctrl1000;
5365 break;
5366 case MII_STAT1000:
5367 data->val_out = adapter->phy_regs.stat1000;
5368 break;
5369 case MII_ESTATUS:
5370 data->val_out = adapter->phy_regs.estatus;
5371 break;
5372 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005373 return -EIO;
5374 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005375 break;
5376 case SIOCSMIIREG:
5377 default:
5378 return -EOPNOTSUPP;
5379 }
5380 return 0;
5381}
5382
5383static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5384{
5385 switch (cmd) {
5386 case SIOCGMIIPHY:
5387 case SIOCGMIIREG:
5388 case SIOCSMIIREG:
5389 return e1000_mii_ioctl(netdev, ifr, cmd);
5390 default:
5391 return -EOPNOTSUPP;
5392 }
5393}
5394
Bruce Allana4f58f52009-06-02 11:29:18 +00005395static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5396{
5397 struct e1000_hw *hw = &adapter->hw;
5398 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005399 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005400 int retval = 0;
5401
5402 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005403 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005404
Bruce Allan2b6b1682011-05-13 07:20:09 +00005405 retval = hw->phy.ops.acquire(hw);
5406 if (retval) {
5407 e_err("Could not acquire PHY\n");
5408 return retval;
5409 }
5410
5411 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5412 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5413 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005414 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005415
5416 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005417 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5418 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005419 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5420 (u16)(mac_reg & 0xFFFF));
5421 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5422 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005423 }
5424
5425 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005426 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005427 mac_reg = er32(RCTL);
5428 if (mac_reg & E1000_RCTL_UPE)
5429 phy_reg |= BM_RCTL_UPE;
5430 if (mac_reg & E1000_RCTL_MPE)
5431 phy_reg |= BM_RCTL_MPE;
5432 phy_reg &= ~(BM_RCTL_MO_MASK);
5433 if (mac_reg & E1000_RCTL_MO_3)
5434 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5435 << BM_RCTL_MO_SHIFT);
5436 if (mac_reg & E1000_RCTL_BAM)
5437 phy_reg |= BM_RCTL_BAM;
5438 if (mac_reg & E1000_RCTL_PMCF)
5439 phy_reg |= BM_RCTL_PMCF;
5440 mac_reg = er32(CTRL);
5441 if (mac_reg & E1000_CTRL_RFCE)
5442 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005443 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005444
5445 /* enable PHY wakeup in MAC register */
5446 ew32(WUFC, wufc);
5447 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5448
5449 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005450 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5451 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005452
5453 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005454 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5455 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005456 if (retval)
5457 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005458release:
Bruce Allan94d81862009-11-20 23:25:26 +00005459 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005460
5461 return retval;
5462}
5463
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005464static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5465 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005466{
5467 struct net_device *netdev = pci_get_drvdata(pdev);
5468 struct e1000_adapter *adapter = netdev_priv(netdev);
5469 struct e1000_hw *hw = &adapter->hw;
5470 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005471 /* Runtime suspend should only enable wakeup for link changes */
5472 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005473 int retval = 0;
5474
5475 netif_device_detach(netdev);
5476
5477 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005478 int count = E1000_CHECK_RESET_COUNT;
5479
5480 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5481 usleep_range(10000, 20000);
5482
Auke Kokbc7f75f2007-09-17 12:30:59 -07005483 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5484 e1000e_down(adapter);
5485 e1000_free_irq(adapter);
5486 }
Bruce Allan4662e822008-08-26 18:37:06 -07005487 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005488
5489 retval = pci_save_state(pdev);
5490 if (retval)
5491 return retval;
5492
5493 status = er32(STATUS);
5494 if (status & E1000_STATUS_LU)
5495 wufc &= ~E1000_WUFC_LNKC;
5496
5497 if (wufc) {
5498 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005499 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005500
5501 /* turn on all-multi mode if wake on multicast is enabled */
5502 if (wufc & E1000_WUFC_MC) {
5503 rctl = er32(RCTL);
5504 rctl |= E1000_RCTL_MPE;
5505 ew32(RCTL, rctl);
5506 }
5507
5508 ctrl = er32(CTRL);
5509 /* advertise wake from D3Cold */
5510 #define E1000_CTRL_ADVD3WUC 0x00100000
5511 /* phy power management enable */
5512 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005513 ctrl |= E1000_CTRL_ADVD3WUC;
5514 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5515 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005516 ew32(CTRL, ctrl);
5517
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005518 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5519 adapter->hw.phy.media_type ==
5520 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005521 /* keep the laser running in D3 */
5522 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005523 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005524 ew32(CTRL_EXT, ctrl_ext);
5525 }
5526
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005527 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005528 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005529
Auke Kokbc7f75f2007-09-17 12:30:59 -07005530 /* Allow time for pending master requests to run */
5531 e1000e_disable_pcie_master(&adapter->hw);
5532
Bruce Allan82776a42009-08-14 14:35:33 +00005533 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005534 /* enable wakeup by the PHY */
5535 retval = e1000_init_phy_wakeup(adapter, wufc);
5536 if (retval)
5537 return retval;
5538 } else {
5539 /* enable wakeup by the MAC */
5540 ew32(WUFC, wufc);
5541 ew32(WUC, E1000_WUC_PME_EN);
5542 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005543 } else {
5544 ew32(WUC, 0);
5545 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005546 }
5547
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005548 *enable_wake = !!wufc;
5549
Auke Kokbc7f75f2007-09-17 12:30:59 -07005550 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005551 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5552 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005553 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005554
5555 if (adapter->hw.phy.type == e1000_phy_igp_3)
5556 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5557
Bruce Allanad680762008-03-28 09:15:03 -07005558 /*
5559 * Release control of h/w to f/w. If f/w is AMT enabled, this
5560 * would have already happened in close and is redundant.
5561 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005562 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005563
5564 pci_disable_device(pdev);
5565
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005566 return 0;
5567}
5568
5569static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5570{
5571 if (sleep && wake) {
5572 pci_prepare_to_sleep(pdev);
5573 return;
5574 }
5575
5576 pci_wake_from_d3(pdev, wake);
5577 pci_set_power_state(pdev, PCI_D3hot);
5578}
5579
5580static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5581 bool wake)
5582{
5583 struct net_device *netdev = pci_get_drvdata(pdev);
5584 struct e1000_adapter *adapter = netdev_priv(netdev);
5585
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005586 /*
5587 * The pci-e switch on some quad port adapters will report a
5588 * correctable error when the MAC transitions from D0 to D3. To
5589 * prevent this we need to mask off the correctable errors on the
5590 * downstream port of the pci-e switch.
5591 */
5592 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5593 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005594 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005595 u16 devctl;
5596
5597 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5598 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5599 (devctl & ~PCI_EXP_DEVCTL_CERE));
5600
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005601 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005602
5603 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5604 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005605 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005606 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005607}
5608
Bruce Allan6f461f62010-04-27 03:33:04 +00005609#ifdef CONFIG_PCIEASPM
5610static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5611{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005612 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005613}
5614#else
5615static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005616{
5617 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005618 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005619
5620 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005621 * Both device and parent should have the same ASPM setting.
5622 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005623 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005624 pos = pci_pcie_cap(pdev);
5625 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5626 reg16 &= ~state;
5627 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5628
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005629 if (!pdev->bus->self)
5630 return;
5631
Bruce Allan6f461f62010-04-27 03:33:04 +00005632 pos = pci_pcie_cap(pdev->bus->self);
5633 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5634 reg16 &= ~state;
5635 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5636}
5637#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005638static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005639{
5640 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5641 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5642 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5643
5644 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005645}
5646
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005647#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005648static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005649{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005650 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005651}
5652
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005653static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005654{
5655 struct net_device *netdev = pci_get_drvdata(pdev);
5656 struct e1000_adapter *adapter = netdev_priv(netdev);
5657 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005658 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005659 u32 err;
5660
Bruce Allan78cd29d2011-03-24 03:09:03 +00005661 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5662 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5663 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5664 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5665 if (aspm_disable_flag)
5666 e1000e_disable_aspm(pdev, aspm_disable_flag);
5667
Auke Kokbc7f75f2007-09-17 12:30:59 -07005668 pci_set_power_state(pdev, PCI_D0);
5669 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005670 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005671
Bruce Allan4662e822008-08-26 18:37:06 -07005672 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005673 if (netif_running(netdev)) {
5674 err = e1000_request_irq(adapter);
5675 if (err)
5676 return err;
5677 }
5678
Bruce Allan99730e42011-05-13 07:19:48 +00005679 if (hw->mac.type == e1000_pch2lan)
5680 e1000_resume_workarounds_pchlan(&adapter->hw);
5681
Auke Kokbc7f75f2007-09-17 12:30:59 -07005682 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005683
5684 /* report the system wakeup cause from S3/S4 */
5685 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5686 u16 phy_data;
5687
5688 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5689 if (phy_data) {
5690 e_info("PHY Wakeup cause - %s\n",
5691 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5692 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5693 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5694 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005695 phy_data & E1000_WUS_LNKC ?
5696 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005697 }
5698 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5699 } else {
5700 u32 wus = er32(WUS);
5701 if (wus) {
5702 e_info("MAC Wakeup cause - %s\n",
5703 wus & E1000_WUS_EX ? "Unicast Packet" :
5704 wus & E1000_WUS_MC ? "Multicast Packet" :
5705 wus & E1000_WUS_BC ? "Broadcast Packet" :
5706 wus & E1000_WUS_MAG ? "Magic Packet" :
5707 wus & E1000_WUS_LNKC ? "Link Status Change" :
5708 "other");
5709 }
5710 ew32(WUS, ~0);
5711 }
5712
Auke Kokbc7f75f2007-09-17 12:30:59 -07005713 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005714
Bruce Allancd791612010-05-10 14:59:51 +00005715 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005716
5717 if (netif_running(netdev))
5718 e1000e_up(adapter);
5719
5720 netif_device_attach(netdev);
5721
Bruce Allanad680762008-03-28 09:15:03 -07005722 /*
5723 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005724 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005725 * under the control of the driver.
5726 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005727 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005728 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005729
5730 return 0;
5731}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005732
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005733#ifdef CONFIG_PM_SLEEP
5734static int e1000_suspend(struct device *dev)
5735{
5736 struct pci_dev *pdev = to_pci_dev(dev);
5737 int retval;
5738 bool wake;
5739
5740 retval = __e1000_shutdown(pdev, &wake, false);
5741 if (!retval)
5742 e1000_complete_shutdown(pdev, true, wake);
5743
5744 return retval;
5745}
5746
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005747static int e1000_resume(struct device *dev)
5748{
5749 struct pci_dev *pdev = to_pci_dev(dev);
5750 struct net_device *netdev = pci_get_drvdata(pdev);
5751 struct e1000_adapter *adapter = netdev_priv(netdev);
5752
5753 if (e1000e_pm_ready(adapter))
5754 adapter->idle_check = true;
5755
5756 return __e1000_resume(pdev);
5757}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005758#endif /* CONFIG_PM_SLEEP */
5759
5760#ifdef CONFIG_PM_RUNTIME
5761static int e1000_runtime_suspend(struct device *dev)
5762{
5763 struct pci_dev *pdev = to_pci_dev(dev);
5764 struct net_device *netdev = pci_get_drvdata(pdev);
5765 struct e1000_adapter *adapter = netdev_priv(netdev);
5766
5767 if (e1000e_pm_ready(adapter)) {
5768 bool wake;
5769
5770 __e1000_shutdown(pdev, &wake, true);
5771 }
5772
5773 return 0;
5774}
5775
5776static int e1000_idle(struct device *dev)
5777{
5778 struct pci_dev *pdev = to_pci_dev(dev);
5779 struct net_device *netdev = pci_get_drvdata(pdev);
5780 struct e1000_adapter *adapter = netdev_priv(netdev);
5781
5782 if (!e1000e_pm_ready(adapter))
5783 return 0;
5784
5785 if (adapter->idle_check) {
5786 adapter->idle_check = false;
5787 if (!e1000e_has_link(adapter))
5788 pm_schedule_suspend(dev, MSEC_PER_SEC);
5789 }
5790
5791 return -EBUSY;
5792}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005793
5794static int e1000_runtime_resume(struct device *dev)
5795{
5796 struct pci_dev *pdev = to_pci_dev(dev);
5797 struct net_device *netdev = pci_get_drvdata(pdev);
5798 struct e1000_adapter *adapter = netdev_priv(netdev);
5799
5800 if (!e1000e_pm_ready(adapter))
5801 return 0;
5802
5803 adapter->idle_check = !dev->power.runtime_auto;
5804 return __e1000_resume(pdev);
5805}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005806#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005807#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005808
5809static void e1000_shutdown(struct pci_dev *pdev)
5810{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005811 bool wake = false;
5812
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005813 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005814
5815 if (system_state == SYSTEM_POWER_OFF)
5816 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005817}
5818
5819#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005820
5821static irqreturn_t e1000_intr_msix(int irq, void *data)
5822{
5823 struct net_device *netdev = data;
5824 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005825
5826 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005827 int vector, msix_irq;
5828
Dongdong Deng147b2c82010-11-16 19:50:15 -08005829 vector = 0;
5830 msix_irq = adapter->msix_entries[vector].vector;
5831 disable_irq(msix_irq);
5832 e1000_intr_msix_rx(msix_irq, netdev);
5833 enable_irq(msix_irq);
5834
5835 vector++;
5836 msix_irq = adapter->msix_entries[vector].vector;
5837 disable_irq(msix_irq);
5838 e1000_intr_msix_tx(msix_irq, netdev);
5839 enable_irq(msix_irq);
5840
5841 vector++;
5842 msix_irq = adapter->msix_entries[vector].vector;
5843 disable_irq(msix_irq);
5844 e1000_msix_other(msix_irq, netdev);
5845 enable_irq(msix_irq);
5846 }
5847
5848 return IRQ_HANDLED;
5849}
5850
Auke Kokbc7f75f2007-09-17 12:30:59 -07005851/*
5852 * Polling 'interrupt' - used by things like netconsole to send skbs
5853 * without having to re-enable interrupts. It's not called while
5854 * the interrupt routine is executing.
5855 */
5856static void e1000_netpoll(struct net_device *netdev)
5857{
5858 struct e1000_adapter *adapter = netdev_priv(netdev);
5859
Dongdong Deng147b2c82010-11-16 19:50:15 -08005860 switch (adapter->int_mode) {
5861 case E1000E_INT_MODE_MSIX:
5862 e1000_intr_msix(adapter->pdev->irq, netdev);
5863 break;
5864 case E1000E_INT_MODE_MSI:
5865 disable_irq(adapter->pdev->irq);
5866 e1000_intr_msi(adapter->pdev->irq, netdev);
5867 enable_irq(adapter->pdev->irq);
5868 break;
5869 default: /* E1000E_INT_MODE_LEGACY */
5870 disable_irq(adapter->pdev->irq);
5871 e1000_intr(adapter->pdev->irq, netdev);
5872 enable_irq(adapter->pdev->irq);
5873 break;
5874 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005875}
5876#endif
5877
5878/**
5879 * e1000_io_error_detected - called when PCI error is detected
5880 * @pdev: Pointer to PCI device
5881 * @state: The current pci connection state
5882 *
5883 * This function is called after a PCI bus error affecting
5884 * this device has been detected.
5885 */
5886static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5887 pci_channel_state_t state)
5888{
5889 struct net_device *netdev = pci_get_drvdata(pdev);
5890 struct e1000_adapter *adapter = netdev_priv(netdev);
5891
5892 netif_device_detach(netdev);
5893
Mike Masonc93b5a72009-06-30 12:45:53 +00005894 if (state == pci_channel_io_perm_failure)
5895 return PCI_ERS_RESULT_DISCONNECT;
5896
Auke Kokbc7f75f2007-09-17 12:30:59 -07005897 if (netif_running(netdev))
5898 e1000e_down(adapter);
5899 pci_disable_device(pdev);
5900
5901 /* Request a slot slot reset. */
5902 return PCI_ERS_RESULT_NEED_RESET;
5903}
5904
5905/**
5906 * e1000_io_slot_reset - called after the pci bus has been reset.
5907 * @pdev: Pointer to PCI device
5908 *
5909 * Restart the card from scratch, as if from a cold-boot. Implementation
5910 * resembles the first-half of the e1000_resume routine.
5911 */
5912static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5913{
5914 struct net_device *netdev = pci_get_drvdata(pdev);
5915 struct e1000_adapter *adapter = netdev_priv(netdev);
5916 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005917 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005918 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005919 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005920
Bruce Allan78cd29d2011-03-24 03:09:03 +00005921 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5922 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005923 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005924 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5925 if (aspm_disable_flag)
5926 e1000e_disable_aspm(pdev, aspm_disable_flag);
5927
Bruce Allanf0f422e2008-08-04 17:21:53 -07005928 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005929 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005930 dev_err(&pdev->dev,
5931 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005932 result = PCI_ERS_RESULT_DISCONNECT;
5933 } else {
5934 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005935 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005936 pci_restore_state(pdev);
5937
5938 pci_enable_wake(pdev, PCI_D3hot, 0);
5939 pci_enable_wake(pdev, PCI_D3cold, 0);
5940
5941 e1000e_reset(adapter);
5942 ew32(WUS, ~0);
5943 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005944 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005945
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005946 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005947
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005948 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005949}
5950
5951/**
5952 * e1000_io_resume - called when traffic can start flowing again.
5953 * @pdev: Pointer to PCI device
5954 *
5955 * This callback is called when the error recovery driver tells us that
5956 * its OK to resume normal operation. Implementation resembles the
5957 * second-half of the e1000_resume routine.
5958 */
5959static void e1000_io_resume(struct pci_dev *pdev)
5960{
5961 struct net_device *netdev = pci_get_drvdata(pdev);
5962 struct e1000_adapter *adapter = netdev_priv(netdev);
5963
Bruce Allancd791612010-05-10 14:59:51 +00005964 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005965
5966 if (netif_running(netdev)) {
5967 if (e1000e_up(adapter)) {
5968 dev_err(&pdev->dev,
5969 "can't bring device back up after reset\n");
5970 return;
5971 }
5972 }
5973
5974 netif_device_attach(netdev);
5975
Bruce Allanad680762008-03-28 09:15:03 -07005976 /*
5977 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005978 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005979 * under the control of the driver.
5980 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005981 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005982 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005983
5984}
5985
5986static void e1000_print_device_info(struct e1000_adapter *adapter)
5987{
5988 struct e1000_hw *hw = &adapter->hw;
5989 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005990 u32 ret_val;
5991 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005992
5993 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005994 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005995 /* bus width */
5996 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5997 "Width x1"),
5998 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005999 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006000 e_info("Intel(R) PRO/%s Network Connection\n",
6001 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006002 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6003 E1000_PBANUM_LENGTH);
6004 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006005 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006006 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6007 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006008}
6009
Auke Kok10aa4c02008-08-04 17:21:20 -07006010static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6011{
6012 struct e1000_hw *hw = &adapter->hw;
6013 int ret_val;
6014 u16 buf = 0;
6015
6016 if (hw->mac.type != e1000_82573)
6017 return;
6018
6019 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006020 le16_to_cpus(&buf);
6021 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006022 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006023 dev_warn(&adapter->pdev->dev,
6024 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006025 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006026}
6027
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006028static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006029 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006030{
6031 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006032 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006033
6034 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6035 adapter->flags |= FLAG_TSO_FORCE;
6036
6037 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006038 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6039 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006040 return 0;
6041
Bruce Allan70495a52012-01-11 01:26:50 +00006042 /*
6043 * IP payload checksum (enabled with jumbos/packet-split when Rx
6044 * checksum is enabled) and generation of RSS hash is mutually
6045 * exclusive in the hardware.
6046 */
6047 if (adapter->rx_ps_pages &&
6048 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
6049 e_err("Enabling both receive checksum offload and receive hashing is not possible with jumbo frames. Disable jumbos or enable only one of the receive offload features.\n");
6050 return -EINVAL;
6051 }
6052
Ben Greear01840392012-02-11 15:39:25 +00006053 if (changed & NETIF_F_RXFCS) {
6054 if (features & NETIF_F_RXFCS) {
6055 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6056 } else {
6057 /* We need to take it back to defaults, which might mean
6058 * stripping is still disabled at the adapter level.
6059 */
6060 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6061 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6062 else
6063 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6064 }
6065 }
6066
Bruce Allan70495a52012-01-11 01:26:50 +00006067 netdev->features = features;
6068
Bruce Allandc221292011-08-19 03:23:48 +00006069 if (netif_running(netdev))
6070 e1000e_reinit_locked(adapter);
6071 else
6072 e1000e_reset(adapter);
6073
6074 return 0;
6075}
6076
Stephen Hemminger651c2462008-11-19 21:57:48 -08006077static const struct net_device_ops e1000e_netdev_ops = {
6078 .ndo_open = e1000_open,
6079 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006080 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006081 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006082 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006083 .ndo_set_mac_address = e1000_set_mac,
6084 .ndo_change_mtu = e1000_change_mtu,
6085 .ndo_do_ioctl = e1000_ioctl,
6086 .ndo_tx_timeout = e1000_tx_timeout,
6087 .ndo_validate_addr = eth_validate_addr,
6088
Stephen Hemminger651c2462008-11-19 21:57:48 -08006089 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6090 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6091#ifdef CONFIG_NET_POLL_CONTROLLER
6092 .ndo_poll_controller = e1000_netpoll,
6093#endif
Bruce Allandc221292011-08-19 03:23:48 +00006094 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006095};
6096
Auke Kokbc7f75f2007-09-17 12:30:59 -07006097/**
6098 * e1000_probe - Device Initialization Routine
6099 * @pdev: PCI device information struct
6100 * @ent: entry in e1000_pci_tbl
6101 *
6102 * Returns 0 on success, negative on failure
6103 *
6104 * e1000_probe initializes an adapter identified by a pci_dev structure.
6105 * The OS initialization, configuring of the adapter private structure,
6106 * and a hardware reset occur.
6107 **/
6108static int __devinit e1000_probe(struct pci_dev *pdev,
6109 const struct pci_device_id *ent)
6110{
6111 struct net_device *netdev;
6112 struct e1000_adapter *adapter;
6113 struct e1000_hw *hw;
6114 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006115 resource_size_t mmio_start, mmio_len;
6116 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006117 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006118 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006119 int i, err, pci_using_dac;
6120 u16 eeprom_data = 0;
6121 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6122
Bruce Allan78cd29d2011-03-24 03:09:03 +00006123 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6124 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006125 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006126 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6127 if (aspm_disable_flag)
6128 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006129
Bruce Allanf0f422e2008-08-04 17:21:53 -07006130 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006131 if (err)
6132 return err;
6133
6134 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006135 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006136 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006137 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006138 if (!err)
6139 pci_using_dac = 1;
6140 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006141 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006142 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006143 err = dma_set_coherent_mask(&pdev->dev,
6144 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006145 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006146 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006147 goto err_dma;
6148 }
6149 }
6150 }
6151
Arjan van de Vene8de1482008-10-22 19:55:31 -07006152 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006153 pci_select_bars(pdev, IORESOURCE_MEM),
6154 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006155 if (err)
6156 goto err_pci_reg;
6157
Xiaotian Feng68eac462009-08-14 14:35:52 +00006158 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006159 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006160
Auke Kokbc7f75f2007-09-17 12:30:59 -07006161 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006162 /* PCI config space info */
6163 err = pci_save_state(pdev);
6164 if (err)
6165 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006166
6167 err = -ENOMEM;
6168 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6169 if (!netdev)
6170 goto err_alloc_etherdev;
6171
Auke Kokbc7f75f2007-09-17 12:30:59 -07006172 SET_NETDEV_DEV(netdev, &pdev->dev);
6173
Tom Herbertf85e4df2010-05-05 14:03:32 +00006174 netdev->irq = pdev->irq;
6175
Auke Kokbc7f75f2007-09-17 12:30:59 -07006176 pci_set_drvdata(pdev, netdev);
6177 adapter = netdev_priv(netdev);
6178 hw = &adapter->hw;
6179 adapter->netdev = netdev;
6180 adapter->pdev = pdev;
6181 adapter->ei = ei;
6182 adapter->pba = ei->pba;
6183 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006184 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006185 adapter->hw.adapter = adapter;
6186 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006187 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006188 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006189
6190 mmio_start = pci_resource_start(pdev, 0);
6191 mmio_len = pci_resource_len(pdev, 0);
6192
6193 err = -EIO;
6194 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6195 if (!adapter->hw.hw_addr)
6196 goto err_ioremap;
6197
6198 if ((adapter->flags & FLAG_HAS_FLASH) &&
6199 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6200 flash_start = pci_resource_start(pdev, 1);
6201 flash_len = pci_resource_len(pdev, 1);
6202 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6203 if (!adapter->hw.flash_address)
6204 goto err_flashmap;
6205 }
6206
6207 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006208 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006209 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006210 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006211 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006212 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006213
6214 netdev->mem_start = mmio_start;
6215 netdev->mem_end = mmio_start + mmio_len;
6216
6217 adapter->bd_number = cards_found++;
6218
Bruce Allan4662e822008-08-26 18:37:06 -07006219 e1000e_check_options(adapter);
6220
Auke Kokbc7f75f2007-09-17 12:30:59 -07006221 /* setup adapter struct */
6222 err = e1000_sw_init(adapter);
6223 if (err)
6224 goto err_sw_init;
6225
Auke Kokbc7f75f2007-09-17 12:30:59 -07006226 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6227 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6228 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6229
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006230 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006231 if (err)
6232 goto err_hw_init;
6233
Bruce Allan4a770352008-10-01 17:18:35 -07006234 if ((adapter->flags & FLAG_IS_ICH) &&
6235 (adapter->flags & FLAG_READ_ONLY_NVM))
6236 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6237
Auke Kokbc7f75f2007-09-17 12:30:59 -07006238 hw->mac.ops.get_bus_info(&adapter->hw);
6239
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006240 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006241
6242 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006243 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006244 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6245 adapter->hw.phy.disable_polarity_correction = 0;
6246 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6247 }
6248
Bruce Allan44abd5c2012-02-22 09:02:37 +00006249 if (hw->phy.ops.check_reset_block(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006250 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006251
Bruce Allandc221292011-08-19 03:23:48 +00006252 /* Set initial default active device features */
6253 netdev->features = (NETIF_F_SG |
6254 NETIF_F_HW_VLAN_RX |
6255 NETIF_F_HW_VLAN_TX |
6256 NETIF_F_TSO |
6257 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006258 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006259 NETIF_F_RXCSUM |
6260 NETIF_F_HW_CSUM);
6261
6262 /* Set user-changeable features (subset of all device features) */
6263 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006264 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006265 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006266 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006267
6268 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6269 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6270
Bruce Allandc221292011-08-19 03:23:48 +00006271 netdev->vlan_features |= (NETIF_F_SG |
6272 NETIF_F_TSO |
6273 NETIF_F_TSO6 |
6274 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006275
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006276 netdev->priv_flags |= IFF_UNICAST_FLT;
6277
Yi Zou7b872a52010-09-22 17:57:58 +00006278 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006279 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006280 netdev->vlan_features |= NETIF_F_HIGHDMA;
6281 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006282
Auke Kokbc7f75f2007-09-17 12:30:59 -07006283 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6284 adapter->flags |= FLAG_MNG_PT_ENABLED;
6285
Bruce Allanad680762008-03-28 09:15:03 -07006286 /*
6287 * before reading the NVM, reset the controller to
6288 * put the device in a known good starting state
6289 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006290 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6291
6292 /*
6293 * systems with ASPM and others may see the checksum fail on the first
6294 * attempt. Let's give it a few tries
6295 */
6296 for (i = 0;; i++) {
6297 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6298 break;
6299 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006300 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006301 err = -EIO;
6302 goto err_eeprom;
6303 }
6304 }
6305
Auke Kok10aa4c02008-08-04 17:21:20 -07006306 e1000_eeprom_checks(adapter);
6307
Bruce Allan608f8a02010-01-13 02:04:58 +00006308 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006309 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006310 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006311
6312 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6313 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6314
6315 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006316 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006317 err = -EIO;
6318 goto err_eeprom;
6319 }
6320
6321 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006322 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006323 adapter->watchdog_timer.data = (unsigned long) adapter;
6324
6325 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006326 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006327 adapter->phy_info_timer.data = (unsigned long) adapter;
6328
6329 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6330 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006331 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6332 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006333 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006334
Auke Kokbc7f75f2007-09-17 12:30:59 -07006335 /* Initialize link parameters. User can change them with ethtool */
6336 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006337 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006338 adapter->hw.fc.requested_mode = e1000_fc_default;
6339 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006340 adapter->hw.phy.autoneg_advertised = 0x2f;
6341
6342 /* ring size defaults */
6343 adapter->rx_ring->count = 256;
6344 adapter->tx_ring->count = 256;
6345
6346 /*
6347 * Initial Wake on LAN setting - If APM wake is enabled in
6348 * the EEPROM, enable the ACPI Magic Packet filter
6349 */
6350 if (adapter->flags & FLAG_APME_IN_WUC) {
6351 /* APME bit in EEPROM is mapped to WUC.APME */
6352 eeprom_data = er32(WUC);
6353 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006354 if ((hw->mac.type > e1000_ich10lan) &&
6355 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006356 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006357 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6358 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6359 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006360 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6361 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006362 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006363 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6364 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006365 }
6366
6367 /* fetch WoL from EEPROM */
6368 if (eeprom_data & eeprom_apme_mask)
6369 adapter->eeprom_wol |= E1000_WUFC_MAG;
6370
6371 /*
6372 * now that we have the eeprom settings, apply the special cases
6373 * where the eeprom may be wrong or the board simply won't support
6374 * wake on lan on a particular port
6375 */
6376 if (!(adapter->flags & FLAG_HAS_WOL))
6377 adapter->eeprom_wol = 0;
6378
6379 /* initialize the wol settings based on the eeprom settings */
6380 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006381 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006382
Bruce Allan84527592008-11-21 17:00:22 -08006383 /* save off EEPROM version number */
6384 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6385
Auke Kokbc7f75f2007-09-17 12:30:59 -07006386 /* reset the hardware with the new settings */
6387 e1000e_reset(adapter);
6388
Bruce Allanad680762008-03-28 09:15:03 -07006389 /*
6390 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006391 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006392 * under the control of the driver.
6393 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006394 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006395 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006396
Bruce Allanf2315bf2011-12-16 00:46:59 +00006397 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006398 err = register_netdev(netdev);
6399 if (err)
6400 goto err_register;
6401
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006402 /* carrier off reporting is important to ethtool even BEFORE open */
6403 netif_carrier_off(netdev);
6404
Auke Kokbc7f75f2007-09-17 12:30:59 -07006405 e1000_print_device_info(adapter);
6406
Alan Sternf3ec4f82010-06-08 15:23:51 -04006407 if (pci_dev_run_wake(pdev))
6408 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006409
Auke Kokbc7f75f2007-09-17 12:30:59 -07006410 return 0;
6411
6412err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006413 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006414 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006415err_eeprom:
Bruce Allan44abd5c2012-02-22 09:02:37 +00006416 if (!hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006417 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006418err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006419 kfree(adapter->tx_ring);
6420 kfree(adapter->rx_ring);
6421err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006422 if (adapter->hw.flash_address)
6423 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006424 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006425err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006426 iounmap(adapter->hw.hw_addr);
6427err_ioremap:
6428 free_netdev(netdev);
6429err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006430 pci_release_selected_regions(pdev,
6431 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006432err_pci_reg:
6433err_dma:
6434 pci_disable_device(pdev);
6435 return err;
6436}
6437
6438/**
6439 * e1000_remove - Device Removal Routine
6440 * @pdev: PCI device information struct
6441 *
6442 * e1000_remove is called by the PCI subsystem to alert the driver
6443 * that it should release a PCI device. The could be caused by a
6444 * Hot-Plug event, or because the driver is going to be removed from
6445 * memory.
6446 **/
6447static void __devexit e1000_remove(struct pci_dev *pdev)
6448{
6449 struct net_device *netdev = pci_get_drvdata(pdev);
6450 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006451 bool down = test_bit(__E1000_DOWN, &adapter->state);
6452
Bruce Allanad680762008-03-28 09:15:03 -07006453 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006454 * The timers may be rescheduled, so explicitly disable them
6455 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006456 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006457 if (!down)
6458 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006459 del_timer_sync(&adapter->watchdog_timer);
6460 del_timer_sync(&adapter->phy_info_timer);
6461
Bruce Allan41cec6f2009-11-20 23:28:56 +00006462 cancel_work_sync(&adapter->reset_task);
6463 cancel_work_sync(&adapter->watchdog_task);
6464 cancel_work_sync(&adapter->downshift_task);
6465 cancel_work_sync(&adapter->update_phy_task);
6466 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006467
Bruce Allan17f208d2009-12-01 15:47:22 +00006468 if (!(netdev->flags & IFF_UP))
6469 e1000_power_down_phy(adapter);
6470
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006471 /* Don't lie to e1000_close() down the road. */
6472 if (!down)
6473 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006474 unregister_netdev(netdev);
6475
Alan Sternf3ec4f82010-06-08 15:23:51 -04006476 if (pci_dev_run_wake(pdev))
6477 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006478
Bruce Allanad680762008-03-28 09:15:03 -07006479 /*
6480 * Release control of h/w to f/w. If f/w is AMT enabled, this
6481 * would have already happened in close and is redundant.
6482 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006483 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006484
Bruce Allan4662e822008-08-26 18:37:06 -07006485 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006486 kfree(adapter->tx_ring);
6487 kfree(adapter->rx_ring);
6488
6489 iounmap(adapter->hw.hw_addr);
6490 if (adapter->hw.flash_address)
6491 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006492 pci_release_selected_regions(pdev,
6493 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006494
6495 free_netdev(netdev);
6496
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006497 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006498 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006499
Auke Kokbc7f75f2007-09-17 12:30:59 -07006500 pci_disable_device(pdev);
6501}
6502
6503/* PCI Error Recovery (ERS) */
6504static struct pci_error_handlers e1000_err_handler = {
6505 .error_detected = e1000_io_error_detected,
6506 .slot_reset = e1000_io_slot_reset,
6507 .resume = e1000_io_resume,
6508};
6509
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006510static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006511 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6512 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6513 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6514 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6515 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6516 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006517 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6518 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6519 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006520
Auke Kokbc7f75f2007-09-17 12:30:59 -07006521 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6522 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6523 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6524 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006525
Auke Kokbc7f75f2007-09-17 12:30:59 -07006526 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6527 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6528 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006529
Bruce Allan4662e822008-08-26 18:37:06 -07006530 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006531 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006532 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006533
Auke Kokbc7f75f2007-09-17 12:30:59 -07006534 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6535 board_80003es2lan },
6536 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6537 board_80003es2lan },
6538 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6539 board_80003es2lan },
6540 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6541 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006542
Auke Kokbc7f75f2007-09-17 12:30:59 -07006543 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6544 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6545 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6546 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6547 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6548 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6549 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006550 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006551
Auke Kokbc7f75f2007-09-17 12:30:59 -07006552 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6553 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6554 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6555 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6556 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006557 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006558 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6559 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6560 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6561
6562 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6563 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6564 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006565
Bruce Allanf4187b52008-08-26 18:36:50 -07006566 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6567 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006568 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006569
Bruce Allana4f58f52009-06-02 11:29:18 +00006570 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6571 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6572 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6573 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6574
Bruce Alland3738bb2010-06-16 13:27:28 +00006575 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6576 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6577
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006578 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006579};
6580MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6581
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006582#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006583static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006584 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6585 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6586 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006587};
David S. Millere50208a2010-03-16 23:36:24 -07006588#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006589
Auke Kokbc7f75f2007-09-17 12:30:59 -07006590/* PCI Device API Driver */
6591static struct pci_driver e1000_driver = {
6592 .name = e1000e_driver_name,
6593 .id_table = e1000_pci_tbl,
6594 .probe = e1000_probe,
6595 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006596#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006597 .driver = {
6598 .pm = &e1000_pm_ops,
6599 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006600#endif
6601 .shutdown = e1000_shutdown,
6602 .err_handler = &e1000_err_handler
6603};
6604
6605/**
6606 * e1000_init_module - Driver Registration Routine
6607 *
6608 * e1000_init_module is the first routine called when the driver is
6609 * loaded. All it does is register with the PCI subsystem.
6610 **/
6611static int __init e1000_init_module(void)
6612{
6613 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006614 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6615 e1000e_driver_version);
Bruce Allanf5e261e2012-01-01 16:00:03 +00006616 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006617 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006618
Auke Kokbc7f75f2007-09-17 12:30:59 -07006619 return ret;
6620}
6621module_init(e1000_init_module);
6622
6623/**
6624 * e1000_exit_module - Driver Exit Cleanup Routine
6625 *
6626 * e1000_exit_module is called just before the driver is removed
6627 * from memory.
6628 **/
6629static void __exit e1000_exit_module(void)
6630{
6631 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006632}
6633module_exit(e1000_exit_module);
6634
6635
6636MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6637MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6638MODULE_LICENSE("GPL");
6639MODULE_VERSION(DRV_VERSION);
6640
Bruce Allan06c24b92012-02-23 03:13:13 +00006641/* netdev.c */