blob: a9a4ea2c616eff20549d4f0872567c1ac454c648 [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 Allan058e8ed2011-12-16 00:47:04 +000059#define DRV_VERSION "1.9.5" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070060char e1000e_driver_name[] = "e1000e";
61const char e1000e_driver_version[] = DRV_VERSION;
62
Bruce Allan78cd29d2011-03-24 03:09:03 +000063static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
64
Auke Kokbc7f75f2007-09-17 12:30:59 -070065static const struct e1000_info *e1000_info_tbl[] = {
66 [board_82571] = &e1000_82571_info,
67 [board_82572] = &e1000_82572_info,
68 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070069 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000070 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070071 [board_80003es2lan] = &e1000_es2_info,
72 [board_ich8lan] = &e1000_ich8_info,
73 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070074 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000075 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000076 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070077};
78
Taku Izumi84f4ee92010-04-27 14:39:08 +000079struct e1000_reg_info {
80 u32 ofs;
81 char *name;
82};
83
Bruce Allanaf667a22010-12-31 06:10:01 +000084#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
85#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
86#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
87#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
88#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000089
Bruce Allanaf667a22010-12-31 06:10:01 +000090#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
91#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
92#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
93#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
94#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000095
96static const struct e1000_reg_info e1000_reg_info_tbl[] = {
97
98 /* General Registers */
99 {E1000_CTRL, "CTRL"},
100 {E1000_STATUS, "STATUS"},
101 {E1000_CTRL_EXT, "CTRL_EXT"},
102
103 /* Interrupt Registers */
104 {E1000_ICR, "ICR"},
105
Bruce Allanaf667a22010-12-31 06:10:01 +0000106 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000107 {E1000_RCTL, "RCTL"},
108 {E1000_RDLEN, "RDLEN"},
109 {E1000_RDH, "RDH"},
110 {E1000_RDT, "RDT"},
111 {E1000_RDTR, "RDTR"},
112 {E1000_RXDCTL(0), "RXDCTL"},
113 {E1000_ERT, "ERT"},
114 {E1000_RDBAL, "RDBAL"},
115 {E1000_RDBAH, "RDBAH"},
116 {E1000_RDFH, "RDFH"},
117 {E1000_RDFT, "RDFT"},
118 {E1000_RDFHS, "RDFHS"},
119 {E1000_RDFTS, "RDFTS"},
120 {E1000_RDFPC, "RDFPC"},
121
Bruce Allanaf667a22010-12-31 06:10:01 +0000122 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000123 {E1000_TCTL, "TCTL"},
124 {E1000_TDBAL, "TDBAL"},
125 {E1000_TDBAH, "TDBAH"},
126 {E1000_TDLEN, "TDLEN"},
127 {E1000_TDH, "TDH"},
128 {E1000_TDT, "TDT"},
129 {E1000_TIDV, "TIDV"},
130 {E1000_TXDCTL(0), "TXDCTL"},
131 {E1000_TADV, "TADV"},
132 {E1000_TARC(0), "TARC"},
133 {E1000_TDFH, "TDFH"},
134 {E1000_TDFT, "TDFT"},
135 {E1000_TDFHS, "TDFHS"},
136 {E1000_TDFTS, "TDFTS"},
137 {E1000_TDFPC, "TDFPC"},
138
139 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000140 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000141};
142
143/*
144 * e1000_regdump - register printout routine
145 */
146static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
147{
148 int n = 0;
149 char rname[16];
150 u32 regs[8];
151
152 switch (reginfo->ofs) {
153 case E1000_RXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_RXDCTL(n));
156 break;
157 case E1000_TXDCTL(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TXDCTL(n));
160 break;
161 case E1000_TARC(0):
162 for (n = 0; n < 2; n++)
163 regs[n] = __er32(hw, E1000_TARC(n));
164 break;
165 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000166 pr_info("%-15s %08x\n",
167 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000168 return;
169 }
170
171 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000172 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000173}
174
Taku Izumi84f4ee92010-04-27 14:39:08 +0000175/*
Bruce Allanaf667a22010-12-31 06:10:01 +0000176 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Taku Izumi84f4ee92010-04-27 14:39:08 +0000177 */
178static void e1000e_dump(struct e1000_adapter *adapter)
179{
180 struct net_device *netdev = adapter->netdev;
181 struct e1000_hw *hw = &adapter->hw;
182 struct e1000_reg_info *reginfo;
183 struct e1000_ring *tx_ring = adapter->tx_ring;
184 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000185 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000186 __le64 a;
187 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000188 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000189 struct e1000_buffer *buffer_info;
190 struct e1000_ring *rx_ring = adapter->rx_ring;
191 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000192 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000193 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000194 __le64 a;
195 __le64 b;
196 __le64 c;
197 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000198 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000199 u32 staterr;
200 int i = 0;
201
202 if (!netif_msg_hw(adapter))
203 return;
204
205 /* Print netdevice Info */
206 if (netdev) {
207 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000208 pr_info("Device Name state trans_start last_rx\n");
209 pr_info("%-15s %016lX %016lX %016lX\n",
210 netdev->name, netdev->state, netdev->trans_start,
211 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000212 }
213
214 /* Print Registers */
215 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000216 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000217 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
218 reginfo->name; reginfo++) {
219 e1000_regdump(hw, reginfo);
220 }
221
Bruce Allanaf667a22010-12-31 06:10:01 +0000222 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000223 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000224 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000225
Bruce Allanaf667a22010-12-31 06:10:01 +0000226 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000227 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000228 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000229 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
230 0, tx_ring->next_to_use, tx_ring->next_to_clean,
231 (unsigned long long)buffer_info->dma,
232 buffer_info->length,
233 buffer_info->next_to_watch,
234 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000235
Bruce Allanaf667a22010-12-31 06:10:01 +0000236 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000237 if (!netif_msg_tx_done(adapter))
238 goto rx_ring_summary;
239
Bruce Allanaf667a22010-12-31 06:10:01 +0000240 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000241
242 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
243 *
244 * Legacy Transmit Descriptor
245 * +--------------------------------------------------------------+
246 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
247 * +--------------------------------------------------------------+
248 * 8 | Special | CSS | Status | CMD | CSO | Length |
249 * +--------------------------------------------------------------+
250 * 63 48 47 36 35 32 31 24 23 16 15 0
251 *
252 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
253 * 63 48 47 40 39 32 31 16 15 8 7 0
254 * +----------------------------------------------------------------+
255 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
256 * +----------------------------------------------------------------+
257 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
258 * +----------------------------------------------------------------+
259 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
260 *
261 * Extended Data Descriptor (DTYP=0x1)
262 * +----------------------------------------------------------------+
263 * 0 | Buffer Address [63:0] |
264 * +----------------------------------------------------------------+
265 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
266 * +----------------------------------------------------------------+
267 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
268 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000269 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
270 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
271 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 +0000272 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000273 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000274 tx_desc = E1000_TX_DESC(*tx_ring, i);
275 buffer_info = &tx_ring->buffer_info[i];
276 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000277 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000278 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000279 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000280 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000281 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000282 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000283 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000284 next_desc = "";
285 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
286 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
287 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
288 i,
289 (unsigned long long)le64_to_cpu(u0->a),
290 (unsigned long long)le64_to_cpu(u0->b),
291 (unsigned long long)buffer_info->dma,
292 buffer_info->length, buffer_info->next_to_watch,
293 (unsigned long long)buffer_info->time_stamp,
294 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000295
296 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
297 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Bruce Allanaf667a22010-12-31 06:10:01 +0000298 16, 1, phys_to_virt(buffer_info->dma),
299 buffer_info->length, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000300 }
301
Bruce Allanaf667a22010-12-31 06:10:01 +0000302 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000303rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000304 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000305 pr_info("Queue [NTU] [NTC]\n");
306 pr_info(" %5d %5X %5X\n",
307 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000308
Bruce Allanaf667a22010-12-31 06:10:01 +0000309 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000310 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000311 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000312
Bruce Allanaf667a22010-12-31 06:10:01 +0000313 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000314 switch (adapter->rx_ps_pages) {
315 case 1:
316 case 2:
317 case 3:
318 /* [Extended] Packet Split Receive Descriptor Format
319 *
320 * +-----------------------------------------------------+
321 * 0 | Buffer Address 0 [63:0] |
322 * +-----------------------------------------------------+
323 * 8 | Buffer Address 1 [63:0] |
324 * +-----------------------------------------------------+
325 * 16 | Buffer Address 2 [63:0] |
326 * +-----------------------------------------------------+
327 * 24 | Buffer Address 3 [63:0] |
328 * +-----------------------------------------------------+
329 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000330 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 +0000331 /* [Extended] Receive Descriptor (Write-Back) Format
332 *
333 * 63 48 47 32 31 13 12 8 7 4 3 0
334 * +------------------------------------------------------+
335 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
336 * | Checksum | Ident | | Queue | | Type |
337 * +------------------------------------------------------+
338 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
339 * +------------------------------------------------------+
340 * 63 48 47 32 31 20 19 0
341 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000342 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 +0000343 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000344 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000345 buffer_info = &rx_ring->buffer_info[i];
346 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
347 u1 = (struct my_u1 *)rx_desc_ps;
348 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000349 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000350
351 if (i == rx_ring->next_to_use)
352 next_desc = " NTU";
353 else if (i == rx_ring->next_to_clean)
354 next_desc = " NTC";
355 else
356 next_desc = "";
357
Taku Izumi84f4ee92010-04-27 14:39:08 +0000358 if (staterr & E1000_RXD_STAT_DD) {
359 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000360 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
361 "RWB", i,
362 (unsigned long long)le64_to_cpu(u1->a),
363 (unsigned long long)le64_to_cpu(u1->b),
364 (unsigned long long)le64_to_cpu(u1->c),
365 (unsigned long long)le64_to_cpu(u1->d),
366 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000367 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000368 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
369 "R ", i,
370 (unsigned long long)le64_to_cpu(u1->a),
371 (unsigned long long)le64_to_cpu(u1->b),
372 (unsigned long long)le64_to_cpu(u1->c),
373 (unsigned long long)le64_to_cpu(u1->d),
374 (unsigned long long)buffer_info->dma,
375 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000376
377 if (netif_msg_pktdata(adapter))
378 print_hex_dump(KERN_INFO, "",
379 DUMP_PREFIX_ADDRESS, 16, 1,
380 phys_to_virt(buffer_info->dma),
381 adapter->rx_ps_bsize0, true);
382 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000383 }
384 break;
385 default:
386 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000387 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000388 *
Bruce Allan5f450212011-07-22 06:21:46 +0000389 * +-----------------------------------------------------+
390 * 0 | Buffer Address [63:0] |
391 * +-----------------------------------------------------+
392 * 8 | Reserved |
393 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000394 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000395 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 +0000396 /* Extended Receive Descriptor (Write-Back) Format
397 *
398 * 63 48 47 32 31 24 23 4 3 0
399 * +------------------------------------------------------+
400 * | RSS Hash | | | |
401 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
402 * | Packet | IP | | | Type |
403 * | Checksum | Ident | | | |
404 * +------------------------------------------------------+
405 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
406 * +------------------------------------------------------+
407 * 63 48 47 32 31 20 19 0
408 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000409 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 +0000410
411 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000412 const char *next_desc;
413
Taku Izumi84f4ee92010-04-27 14:39:08 +0000414 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000415 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
416 u1 = (struct my_u1 *)rx_desc;
417 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000418
419 if (i == rx_ring->next_to_use)
420 next_desc = " NTU";
421 else if (i == rx_ring->next_to_clean)
422 next_desc = " NTC";
423 else
424 next_desc = "";
425
Bruce Allan5f450212011-07-22 06:21:46 +0000426 if (staterr & E1000_RXD_STAT_DD) {
427 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000428 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
429 "RWB", i,
430 (unsigned long long)le64_to_cpu(u1->a),
431 (unsigned long long)le64_to_cpu(u1->b),
432 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000433 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000434 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
435 "R ", i,
436 (unsigned long long)le64_to_cpu(u1->a),
437 (unsigned long long)le64_to_cpu(u1->b),
438 (unsigned long long)buffer_info->dma,
439 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000440
441 if (netif_msg_pktdata(adapter))
442 print_hex_dump(KERN_INFO, "",
443 DUMP_PREFIX_ADDRESS, 16,
444 1,
445 phys_to_virt
446 (buffer_info->dma),
447 adapter->rx_buffer_len,
448 true);
449 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000450 }
451 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000452}
453
Auke Kokbc7f75f2007-09-17 12:30:59 -0700454/**
455 * e1000_desc_unused - calculate if we have unused descriptors
456 **/
457static int e1000_desc_unused(struct e1000_ring *ring)
458{
459 if (ring->next_to_clean > ring->next_to_use)
460 return ring->next_to_clean - ring->next_to_use - 1;
461
462 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
463}
464
465/**
Bruce Allanad680762008-03-28 09:15:03 -0700466 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700467 * @adapter: board private structure
468 * @status: descriptor status field as written by hardware
469 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
470 * @skb: pointer to sk_buff to be indicated to stack
471 **/
472static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000473 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000474 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700475{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000476 u16 tag = le16_to_cpu(vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700477 skb->protocol = eth_type_trans(skb, netdev);
478
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000479 if (status & E1000_RXD_STAT_VP)
480 __vlan_hwaccel_put_tag(skb, tag);
481
482 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700483}
484
485/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000486 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000487 * @adapter: board private structure
488 * @status_err: receive descriptor status and error fields
489 * @csum: receive descriptor csum field
490 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700491 **/
492static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allanafd12932012-01-05 00:34:05 +0000493 __le16 csum, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700494{
495 u16 status = (u16)status_err;
496 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700497
498 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700499
Bruce Allanafd12932012-01-05 00:34:05 +0000500 /* Rx checksum disabled */
501 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
502 return;
503
Auke Kokbc7f75f2007-09-17 12:30:59 -0700504 /* Ignore Checksum bit is set */
505 if (status & E1000_RXD_STAT_IXSM)
506 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000507
Auke Kokbc7f75f2007-09-17 12:30:59 -0700508 /* TCP/UDP checksum error bit is set */
509 if (errors & E1000_RXD_ERR_TCPE) {
510 /* let the stack verify checksum errors */
511 adapter->hw_csum_err++;
512 return;
513 }
514
515 /* TCP/UDP Checksum has not been calculated */
516 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
517 return;
518
519 /* It must be a TCP or UDP packet with a valid checksum */
520 if (status & E1000_RXD_STAT_TCPCS) {
521 /* TCP checksum is good */
522 skb->ip_summed = CHECKSUM_UNNECESSARY;
523 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700524 /*
525 * IP fragment with UDP payload
526 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700527 * and then put the value in host order for further stack use.
528 */
Bruce Allanafd12932012-01-05 00:34:05 +0000529 __sum16 sum = (__force __sum16)swab16((__force u16)csum);
Al Viroa39fe742007-12-11 19:50:34 +0000530 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700531 skb->ip_summed = CHECKSUM_COMPLETE;
532 }
533 adapter->hw_csum_good++;
534}
535
536/**
David S. Miller823dcd22011-08-20 10:39:12 -0700537 * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa()
538 * @hw: pointer to the HW structure
539 * @tail: address of tail descriptor register
540 * @i: value to write to tail descriptor register
541 *
542 * When updating the tail register, the ME could be accessing Host CSR
543 * registers at the same time. Normally, this is handled in h/w by an
544 * arbiter but on some parts there is a bug that acknowledges Host accesses
545 * later than it should which could result in the descriptor register to
546 * have an incorrect value. Workaround this by checking the FWSM register
547 * which has bit 24 set while ME is accessing Host CSR registers, wait
548 * if it is set and try again a number of times.
549 **/
Bruce Allanc5083cf2011-12-16 00:45:40 +0000550static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, void __iomem *tail,
David S. Miller823dcd22011-08-20 10:39:12 -0700551 unsigned int i)
552{
553 unsigned int j = 0;
554
555 while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) &&
556 (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI))
557 udelay(50);
558
559 writel(i, tail);
560
561 if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail)))
562 return E1000_ERR_SWFW_SYNC;
563
564 return 0;
565}
566
Bruce Allan55aa6982011-12-16 00:45:45 +0000567static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700568{
Bruce Allan55aa6982011-12-16 00:45:45 +0000569 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700570 struct e1000_hw *hw = &adapter->hw;
571
Bruce Allan55aa6982011-12-16 00:45:45 +0000572 if (e1000e_update_tail_wa(hw, rx_ring->tail, i)) {
David S. Miller823dcd22011-08-20 10:39:12 -0700573 u32 rctl = er32(RCTL);
574 ew32(RCTL, rctl & ~E1000_RCTL_EN);
575 e_err("ME firmware caused invalid RDT - resetting\n");
576 schedule_work(&adapter->reset_task);
577 }
578}
579
Bruce Allan55aa6982011-12-16 00:45:45 +0000580static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700581{
Bruce Allan55aa6982011-12-16 00:45:45 +0000582 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700583 struct e1000_hw *hw = &adapter->hw;
584
Bruce Allan55aa6982011-12-16 00:45:45 +0000585 if (e1000e_update_tail_wa(hw, tx_ring->tail, i)) {
David S. Miller823dcd22011-08-20 10:39:12 -0700586 u32 tctl = er32(TCTL);
587 ew32(TCTL, tctl & ~E1000_TCTL_EN);
588 e_err("ME firmware caused invalid TDT - resetting\n");
589 schedule_work(&adapter->reset_task);
590 }
591}
592
593/**
Bruce Allan5f450212011-07-22 06:21:46 +0000594 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000595 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700596 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000597static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000598 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700599{
Bruce Allan55aa6982011-12-16 00:45:45 +0000600 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700601 struct net_device *netdev = adapter->netdev;
602 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000603 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700604 struct e1000_buffer *buffer_info;
605 struct sk_buff *skb;
606 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000607 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700608
609 i = rx_ring->next_to_use;
610 buffer_info = &rx_ring->buffer_info[i];
611
612 while (cleaned_count--) {
613 skb = buffer_info->skb;
614 if (skb) {
615 skb_trim(skb, 0);
616 goto map_skb;
617 }
618
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000619 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700620 if (!skb) {
621 /* Better luck next round */
622 adapter->alloc_rx_buff_failed++;
623 break;
624 }
625
Auke Kokbc7f75f2007-09-17 12:30:59 -0700626 buffer_info->skb = skb;
627map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000628 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700629 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000630 DMA_FROM_DEVICE);
631 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000632 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700633 adapter->rx_dma_failed++;
634 break;
635 }
636
Bruce Allan5f450212011-07-22 06:21:46 +0000637 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
638 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700639
Tom Herbert50849d72010-05-05 14:02:49 +0000640 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
641 /*
642 * Force memory writes to complete before letting h/w
643 * know there are new descriptors to fetch. (Only
644 * applicable for weak-ordered memory model archs,
645 * such as IA-64).
646 */
647 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700648 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000649 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700650 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000651 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000652 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700653 i++;
654 if (i == rx_ring->count)
655 i = 0;
656 buffer_info = &rx_ring->buffer_info[i];
657 }
658
Tom Herbert50849d72010-05-05 14:02:49 +0000659 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660}
661
662/**
663 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000664 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700665 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000666static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000667 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700668{
Bruce Allan55aa6982011-12-16 00:45:45 +0000669 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700670 struct net_device *netdev = adapter->netdev;
671 struct pci_dev *pdev = adapter->pdev;
672 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700673 struct e1000_buffer *buffer_info;
674 struct e1000_ps_page *ps_page;
675 struct sk_buff *skb;
676 unsigned int i, j;
677
678 i = rx_ring->next_to_use;
679 buffer_info = &rx_ring->buffer_info[i];
680
681 while (cleaned_count--) {
682 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
683
684 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700685 ps_page = &buffer_info->ps_pages[j];
686 if (j >= adapter->rx_ps_pages) {
687 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000688 rx_desc->read.buffer_addr[j + 1] =
689 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700690 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700691 }
Auke Kok47f44e42007-10-25 13:57:44 -0700692 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000693 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700694 if (!ps_page->page) {
695 adapter->alloc_rx_buff_failed++;
696 goto no_buffers;
697 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000698 ps_page->dma = dma_map_page(&pdev->dev,
699 ps_page->page,
700 0, PAGE_SIZE,
701 DMA_FROM_DEVICE);
702 if (dma_mapping_error(&pdev->dev,
703 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700704 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000705 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700706 adapter->rx_dma_failed++;
707 goto no_buffers;
708 }
709 }
710 /*
711 * Refresh the desc even if buffer_addrs
712 * didn't change because each write-back
713 * erases this info.
714 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000715 rx_desc->read.buffer_addr[j + 1] =
716 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700717 }
718
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000719 skb = __netdev_alloc_skb_ip_align(netdev,
720 adapter->rx_ps_bsize0,
721 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700722
723 if (!skb) {
724 adapter->alloc_rx_buff_failed++;
725 break;
726 }
727
Auke Kokbc7f75f2007-09-17 12:30:59 -0700728 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000729 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700730 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000731 DMA_FROM_DEVICE);
732 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000733 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700734 adapter->rx_dma_failed++;
735 /* cleanup skb */
736 dev_kfree_skb_any(skb);
737 buffer_info->skb = NULL;
738 break;
739 }
740
741 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
742
Tom Herbert50849d72010-05-05 14:02:49 +0000743 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
744 /*
745 * Force memory writes to complete before letting h/w
746 * know there are new descriptors to fetch. (Only
747 * applicable for weak-ordered memory model archs,
748 * such as IA-64).
749 */
750 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700751 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000752 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700753 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000754 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000755 }
756
Auke Kokbc7f75f2007-09-17 12:30:59 -0700757 i++;
758 if (i == rx_ring->count)
759 i = 0;
760 buffer_info = &rx_ring->buffer_info[i];
761 }
762
763no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000764 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700765}
766
767/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700768 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000769 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700770 * @cleaned_count: number of buffers to allocate this pass
771 **/
772
Bruce Allan55aa6982011-12-16 00:45:45 +0000773static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000774 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700775{
Bruce Allan55aa6982011-12-16 00:45:45 +0000776 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700777 struct net_device *netdev = adapter->netdev;
778 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000779 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700780 struct e1000_buffer *buffer_info;
781 struct sk_buff *skb;
782 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000783 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700784
785 i = rx_ring->next_to_use;
786 buffer_info = &rx_ring->buffer_info[i];
787
788 while (cleaned_count--) {
789 skb = buffer_info->skb;
790 if (skb) {
791 skb_trim(skb, 0);
792 goto check_page;
793 }
794
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000795 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700796 if (unlikely(!skb)) {
797 /* Better luck next round */
798 adapter->alloc_rx_buff_failed++;
799 break;
800 }
801
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700802 buffer_info->skb = skb;
803check_page:
804 /* allocate a new page if necessary */
805 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000806 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700807 if (unlikely(!buffer_info->page)) {
808 adapter->alloc_rx_buff_failed++;
809 break;
810 }
811 }
812
813 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000814 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700815 buffer_info->page, 0,
816 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000817 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700818
Bruce Allan5f450212011-07-22 06:21:46 +0000819 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
820 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700821
822 if (unlikely(++i == rx_ring->count))
823 i = 0;
824 buffer_info = &rx_ring->buffer_info[i];
825 }
826
827 if (likely(rx_ring->next_to_use != i)) {
828 rx_ring->next_to_use = i;
829 if (unlikely(i-- == 0))
830 i = (rx_ring->count - 1);
831
832 /* Force memory writes to complete before letting h/w
833 * know there are new descriptors to fetch. (Only
834 * applicable for weak-ordered memory model archs,
835 * such as IA-64). */
836 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700837 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000838 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700839 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000840 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700841 }
842}
843
Bruce Allan70495a52012-01-11 01:26:50 +0000844static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
845 struct sk_buff *skb)
846{
847 if (netdev->features & NETIF_F_RXHASH)
848 skb->rxhash = le32_to_cpu(rss);
849}
850
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700851/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000852 * e1000_clean_rx_irq - Send received data up the network stack
853 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700854 *
855 * the return value indicates whether actual cleaning was done, there
856 * is no guarantee that everything was cleaned
857 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000858static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
859 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860{
Bruce Allan55aa6982011-12-16 00:45:45 +0000861 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700862 struct net_device *netdev = adapter->netdev;
863 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000864 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000865 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700866 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000867 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700868 unsigned int i;
869 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000870 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700871 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
872
873 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000874 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
875 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700876 buffer_info = &rx_ring->buffer_info[i];
877
Bruce Allan5f450212011-07-22 06:21:46 +0000878 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700879 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700880
881 if (*work_done >= work_to_do)
882 break;
883 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000884 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700885
Auke Kokbc7f75f2007-09-17 12:30:59 -0700886 skb = buffer_info->skb;
887 buffer_info->skb = NULL;
888
889 prefetch(skb->data - NET_IP_ALIGN);
890
891 i++;
892 if (i == rx_ring->count)
893 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000894 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700895 prefetch(next_rxd);
896
897 next_buffer = &rx_ring->buffer_info[i];
898
Rusty Russell3db1cd52011-12-19 13:56:45 +0000899 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700900 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000901 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700902 buffer_info->dma,
903 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000904 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700905 buffer_info->dma = 0;
906
Bruce Allan5f450212011-07-22 06:21:46 +0000907 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700908
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000909 /*
910 * !EOP means multiple descriptors were used to store a single
911 * packet, if that's the case we need to toss it. In fact, we
912 * need to toss every packet with the EOP bit clear and the
913 * next frame that _does_ have the EOP bit set, as it is by
914 * definition only a frame fragment
915 */
Bruce Allan5f450212011-07-22 06:21:46 +0000916 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000917 adapter->flags2 |= FLAG2_IS_DISCARDING;
918
919 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700920 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000921 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700922 /* recycle */
923 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000924 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000925 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700926 goto next_desc;
927 }
928
Ben Greearcf955e62012-02-11 15:39:51 +0000929 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
930 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700931 /* recycle */
932 buffer_info->skb = skb;
933 goto next_desc;
934 }
935
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000936 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000937 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
938 /* If configured to store CRC, don't subtract FCS,
939 * but keep the FCS bytes out of the total_rx_bytes
940 * counter
941 */
942 if (netdev->features & NETIF_F_RXFCS)
943 total_rx_bytes -= 4;
944 else
945 length -= 4;
946 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000947
Auke Kokbc7f75f2007-09-17 12:30:59 -0700948 total_rx_bytes += length;
949 total_rx_packets++;
950
Bruce Allanad680762008-03-28 09:15:03 -0700951 /*
952 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700953 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700954 * of reassembly being done in the stack
955 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700956 if (length < copybreak) {
957 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000958 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700959 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700960 skb_copy_to_linear_data_offset(new_skb,
961 -NET_IP_ALIGN,
962 (skb->data -
963 NET_IP_ALIGN),
964 (length +
965 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700966 /* save the skb in buffer_info as good */
967 buffer_info->skb = skb;
968 skb = new_skb;
969 }
970 /* else just continue with the old one */
971 }
972 /* end copybreak code */
973 skb_put(skb, length);
974
975 /* Receive Checksum Offload */
Bruce Allan5f450212011-07-22 06:21:46 +0000976 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +0000977 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978
Bruce Allan70495a52012-01-11 01:26:50 +0000979 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
980
Bruce Allan5f450212011-07-22 06:21:46 +0000981 e1000_receive_skb(adapter, netdev, skb, staterr,
982 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700983
984next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +0000985 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700986
987 /* return some buffers to hardware, one at a time is too slow */
988 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +0000989 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000990 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 cleaned_count = 0;
992 }
993
994 /* use prefetched values */
995 rx_desc = next_rxd;
996 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000997
998 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999 }
1000 rx_ring->next_to_clean = i;
1001
1002 cleaned_count = e1000_desc_unused(rx_ring);
1003 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001004 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005
Auke Kokbc7f75f2007-09-17 12:30:59 -07001006 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001007 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001008 return cleaned;
1009}
1010
Bruce Allan55aa6982011-12-16 00:45:45 +00001011static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1012 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001013{
Bruce Allan55aa6982011-12-16 00:45:45 +00001014 struct e1000_adapter *adapter = tx_ring->adapter;
1015
Alexander Duyck03b13202009-12-02 16:45:31 +00001016 if (buffer_info->dma) {
1017 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001018 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1019 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001020 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001021 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1022 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001023 buffer_info->dma = 0;
1024 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001025 if (buffer_info->skb) {
1026 dev_kfree_skb_any(buffer_info->skb);
1027 buffer_info->skb = NULL;
1028 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001029 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001030}
1031
Bruce Allan41cec6f2009-11-20 23:28:56 +00001032static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001033{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001034 struct e1000_adapter *adapter = container_of(work,
1035 struct e1000_adapter,
1036 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001037 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001038 struct e1000_ring *tx_ring = adapter->tx_ring;
1039 unsigned int i = tx_ring->next_to_clean;
1040 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1041 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001042 struct e1000_hw *hw = &adapter->hw;
1043 u16 phy_status, phy_1000t_status, phy_ext_status;
1044 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001045
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001046 if (test_bit(__E1000_DOWN, &adapter->state))
1047 return;
1048
Jeff Kirsher09357b02011-11-18 14:25:00 +00001049 if (!adapter->tx_hang_recheck &&
1050 (adapter->flags2 & FLAG2_DMA_BURST)) {
1051 /* May be block on write-back, flush and detect again
1052 * flush pending descriptor writebacks to memory
1053 */
1054 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1055 /* execute the writes immediately */
1056 e1e_flush();
1057 adapter->tx_hang_recheck = true;
1058 return;
1059 }
1060 /* Real hang detected */
1061 adapter->tx_hang_recheck = false;
1062 netif_stop_queue(netdev);
1063
Bruce Allan41cec6f2009-11-20 23:28:56 +00001064 e1e_rphy(hw, PHY_STATUS, &phy_status);
1065 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1066 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1067
1068 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1069
1070 /* detected Hardware unit hang */
1071 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001072 " TDH <%x>\n"
1073 " TDT <%x>\n"
1074 " next_to_use <%x>\n"
1075 " next_to_clean <%x>\n"
1076 "buffer_info[next_to_clean]:\n"
1077 " time_stamp <%lx>\n"
1078 " next_to_watch <%x>\n"
1079 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001080 " next_to_watch.status <%x>\n"
1081 "MAC Status <%x>\n"
1082 "PHY Status <%x>\n"
1083 "PHY 1000BASE-T Status <%x>\n"
1084 "PHY Extended Status <%x>\n"
1085 "PCI Status <%x>\n",
Bruce Allanc5083cf2011-12-16 00:45:40 +00001086 readl(tx_ring->head),
1087 readl(tx_ring->tail),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001088 tx_ring->next_to_use,
1089 tx_ring->next_to_clean,
1090 tx_ring->buffer_info[eop].time_stamp,
1091 eop,
1092 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001093 eop_desc->upper.fields.status,
1094 er32(STATUS),
1095 phy_status,
1096 phy_1000t_status,
1097 phy_ext_status,
1098 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099}
1100
1101/**
1102 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001103 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001104 *
1105 * the return value indicates whether actual cleaning was done, there
1106 * is no guarantee that everything was cleaned
1107 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001108static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001109{
Bruce Allan55aa6982011-12-16 00:45:45 +00001110 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001111 struct net_device *netdev = adapter->netdev;
1112 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001113 struct e1000_tx_desc *tx_desc, *eop_desc;
1114 struct e1000_buffer *buffer_info;
1115 unsigned int i, eop;
1116 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001117 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001118 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001119
1120 i = tx_ring->next_to_clean;
1121 eop = tx_ring->buffer_info[i].next_to_watch;
1122 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1123
Alexander Duyck12d04a32009-03-25 22:05:03 +00001124 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1125 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001126 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001127 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001128 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129 tx_desc = E1000_TX_DESC(*tx_ring, i);
1130 buffer_info = &tx_ring->buffer_info[i];
1131 cleaned = (i == eop);
1132
1133 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001134 total_tx_packets += buffer_info->segs;
1135 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001136 if (buffer_info->skb) {
1137 bytes_compl += buffer_info->skb->len;
1138 pkts_compl++;
1139 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140 }
1141
Bruce Allan55aa6982011-12-16 00:45:45 +00001142 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143 tx_desc->upper.data = 0;
1144
1145 i++;
1146 if (i == tx_ring->count)
1147 i = 0;
1148 }
1149
Terry Loftindac87612010-04-09 10:29:49 +00001150 if (i == tx_ring->next_to_use)
1151 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001152 eop = tx_ring->buffer_info[i].next_to_watch;
1153 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001154 }
1155
1156 tx_ring->next_to_clean = i;
1157
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001158 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1159
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001161 if (count && netif_carrier_ok(netdev) &&
1162 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 /* Make sure that anybody stopping the queue after this
1164 * sees the new next_to_clean.
1165 */
1166 smp_mb();
1167
1168 if (netif_queue_stopped(netdev) &&
1169 !(test_bit(__E1000_DOWN, &adapter->state))) {
1170 netif_wake_queue(netdev);
1171 ++adapter->restart_queue;
1172 }
1173 }
1174
1175 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001176 /*
1177 * Detect a transmit hang in hardware, this serializes the
1178 * check with the clearing of time_stamp and movement of i
1179 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001180 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001181 if (tx_ring->buffer_info[i].time_stamp &&
1182 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001183 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001184 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001185 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001186 else
1187 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001188 }
1189 adapter->total_tx_bytes += total_tx_bytes;
1190 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001191 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192}
1193
1194/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001195 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001196 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001197 *
1198 * the return value indicates whether actual cleaning was done, there
1199 * is no guarantee that everything was cleaned
1200 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001201static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1202 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001203{
Bruce Allan55aa6982011-12-16 00:45:45 +00001204 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001205 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001206 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1207 struct net_device *netdev = adapter->netdev;
1208 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209 struct e1000_buffer *buffer_info, *next_buffer;
1210 struct e1000_ps_page *ps_page;
1211 struct sk_buff *skb;
1212 unsigned int i, j;
1213 u32 length, staterr;
1214 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001215 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001216 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1217
1218 i = rx_ring->next_to_clean;
1219 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1220 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1221 buffer_info = &rx_ring->buffer_info[i];
1222
1223 while (staterr & E1000_RXD_STAT_DD) {
1224 if (*work_done >= work_to_do)
1225 break;
1226 (*work_done)++;
1227 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001228 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001229
1230 /* in the packet split case this is header only */
1231 prefetch(skb->data - NET_IP_ALIGN);
1232
1233 i++;
1234 if (i == rx_ring->count)
1235 i = 0;
1236 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1237 prefetch(next_rxd);
1238
1239 next_buffer = &rx_ring->buffer_info[i];
1240
Rusty Russell3db1cd52011-12-19 13:56:45 +00001241 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001242 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001243 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001244 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001245 buffer_info->dma = 0;
1246
Bruce Allanaf667a22010-12-31 06:10:01 +00001247 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001248 if (!(staterr & E1000_RXD_STAT_EOP))
1249 adapter->flags2 |= FLAG2_IS_DISCARDING;
1250
1251 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001252 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001253 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001254 if (staterr & E1000_RXD_STAT_EOP)
1255 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001256 goto next_desc;
1257 }
1258
Ben Greearcf955e62012-02-11 15:39:51 +00001259 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1260 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001261 dev_kfree_skb_irq(skb);
1262 goto next_desc;
1263 }
1264
1265 length = le16_to_cpu(rx_desc->wb.middle.length0);
1266
1267 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001268 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001269 dev_kfree_skb_irq(skb);
1270 goto next_desc;
1271 }
1272
1273 /* Good Receive */
1274 skb_put(skb, length);
1275
1276 {
Bruce Allan0e15df42012-01-31 06:37:11 +00001277 /*
1278 * this looks ugly, but it seems compiler issues make
1279 * it more efficient than reusing j
1280 */
1281 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282
Bruce Allanad680762008-03-28 09:15:03 -07001283 /*
Bruce Allan0e15df42012-01-31 06:37:11 +00001284 * page alloc/put takes too long and effects small
1285 * packet throughput, so unsplit small packets and
1286 * save the alloc/put only valid in softirq (napi)
1287 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001288 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001289 if (l1 && (l1 <= copybreak) &&
1290 ((length + l1) <= adapter->rx_ps_bsize0)) {
1291 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001292
Bruce Allan0e15df42012-01-31 06:37:11 +00001293 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001294
Bruce Allan0e15df42012-01-31 06:37:11 +00001295 /*
1296 * there is no documentation about how to call
1297 * kmap_atomic, so we can't hold the mapping
1298 * very long
1299 */
1300 dma_sync_single_for_cpu(&pdev->dev,
1301 ps_page->dma,
1302 PAGE_SIZE,
1303 DMA_FROM_DEVICE);
1304 vaddr = kmap_atomic(ps_page->page,
1305 KM_SKB_DATA_SOFTIRQ);
1306 memcpy(skb_tail_pointer(skb), vaddr, l1);
1307 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
1308 dma_sync_single_for_device(&pdev->dev,
1309 ps_page->dma,
1310 PAGE_SIZE,
1311 DMA_FROM_DEVICE);
1312
1313 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001314 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1315 if (!(netdev->features & NETIF_F_RXFCS))
1316 l1 -= 4;
1317 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001318
1319 skb_put(skb, l1);
1320 goto copydone;
1321 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001322 }
1323
1324 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1325 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1326 if (!length)
1327 break;
1328
Auke Kok47f44e42007-10-25 13:57:44 -07001329 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001330 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1331 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001332 ps_page->dma = 0;
1333 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1334 ps_page->page = NULL;
1335 skb->len += length;
1336 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001337 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001338 }
1339
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001340 /* strip the ethernet crc, problem is we're using pages now so
1341 * this whole operation can get a little cpu intensive
1342 */
Ben Greear01840392012-02-11 15:39:25 +00001343 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1344 if (!(netdev->features & NETIF_F_RXFCS))
1345 pskb_trim(skb, skb->len - 4);
1346 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001347
Auke Kokbc7f75f2007-09-17 12:30:59 -07001348copydone:
1349 total_rx_bytes += skb->len;
1350 total_rx_packets++;
1351
Bruce Allanafd12932012-01-05 00:34:05 +00001352 e1000_rx_checksum(adapter, staterr,
1353 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001354
Bruce Allan70495a52012-01-11 01:26:50 +00001355 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1356
Auke Kokbc7f75f2007-09-17 12:30:59 -07001357 if (rx_desc->wb.upper.header_status &
1358 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1359 adapter->rx_hdr_split++;
1360
1361 e1000_receive_skb(adapter, netdev, skb,
1362 staterr, rx_desc->wb.middle.vlan);
1363
1364next_desc:
1365 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1366 buffer_info->skb = NULL;
1367
1368 /* return some buffers to hardware, one at a time is too slow */
1369 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001370 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001371 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001372 cleaned_count = 0;
1373 }
1374
1375 /* use prefetched values */
1376 rx_desc = next_rxd;
1377 buffer_info = next_buffer;
1378
1379 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1380 }
1381 rx_ring->next_to_clean = i;
1382
1383 cleaned_count = e1000_desc_unused(rx_ring);
1384 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001385 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001386
Auke Kokbc7f75f2007-09-17 12:30:59 -07001387 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001388 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001389 return cleaned;
1390}
1391
1392/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001393 * e1000_consume_page - helper function
1394 **/
1395static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1396 u16 length)
1397{
1398 bi->page = NULL;
1399 skb->len += length;
1400 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001401 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001402}
1403
1404/**
1405 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1406 * @adapter: board private structure
1407 *
1408 * the return value indicates whether actual cleaning was done, there
1409 * is no guarantee that everything was cleaned
1410 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001411static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1412 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001413{
Bruce Allan55aa6982011-12-16 00:45:45 +00001414 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001415 struct net_device *netdev = adapter->netdev;
1416 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001417 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001418 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001419 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001420 unsigned int i;
1421 int cleaned_count = 0;
1422 bool cleaned = false;
1423 unsigned int total_rx_bytes=0, total_rx_packets=0;
1424
1425 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001426 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1427 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001428 buffer_info = &rx_ring->buffer_info[i];
1429
Bruce Allan5f450212011-07-22 06:21:46 +00001430 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001431 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001432
1433 if (*work_done >= work_to_do)
1434 break;
1435 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001436 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001437
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001438 skb = buffer_info->skb;
1439 buffer_info->skb = NULL;
1440
1441 ++i;
1442 if (i == rx_ring->count)
1443 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001444 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001445 prefetch(next_rxd);
1446
1447 next_buffer = &rx_ring->buffer_info[i];
1448
1449 cleaned = true;
1450 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001451 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1452 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001453 buffer_info->dma = 0;
1454
Bruce Allan5f450212011-07-22 06:21:46 +00001455 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001456
1457 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001458 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001459 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1460 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001461 /* recycle both page and skb */
1462 buffer_info->skb = skb;
1463 /* an error means any chain goes out the window too */
1464 if (rx_ring->rx_skb_top)
1465 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1466 rx_ring->rx_skb_top = NULL;
1467 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001468 }
1469
Bruce Allanf0f1a172010-12-11 05:53:32 +00001470#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001471 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001472 /* this descriptor is only the beginning (or middle) */
1473 if (!rxtop) {
1474 /* this is the beginning of a chain */
1475 rxtop = skb;
1476 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1477 0, length);
1478 } else {
1479 /* this is the middle of a chain */
1480 skb_fill_page_desc(rxtop,
1481 skb_shinfo(rxtop)->nr_frags,
1482 buffer_info->page, 0, length);
1483 /* re-use the skb, only consumed the page */
1484 buffer_info->skb = skb;
1485 }
1486 e1000_consume_page(buffer_info, rxtop, length);
1487 goto next_desc;
1488 } else {
1489 if (rxtop) {
1490 /* end of the chain */
1491 skb_fill_page_desc(rxtop,
1492 skb_shinfo(rxtop)->nr_frags,
1493 buffer_info->page, 0, length);
1494 /* re-use the current skb, we only consumed the
1495 * page */
1496 buffer_info->skb = skb;
1497 skb = rxtop;
1498 rxtop = NULL;
1499 e1000_consume_page(buffer_info, skb, length);
1500 } else {
1501 /* no chain, got EOP, this buf is the packet
1502 * copybreak to save the put_page/alloc_page */
1503 if (length <= copybreak &&
1504 skb_tailroom(skb) >= length) {
1505 u8 *vaddr;
1506 vaddr = kmap_atomic(buffer_info->page,
1507 KM_SKB_DATA_SOFTIRQ);
1508 memcpy(skb_tail_pointer(skb), vaddr,
1509 length);
1510 kunmap_atomic(vaddr,
1511 KM_SKB_DATA_SOFTIRQ);
1512 /* re-use the page, so don't erase
1513 * buffer_info->page */
1514 skb_put(skb, length);
1515 } else {
1516 skb_fill_page_desc(skb, 0,
1517 buffer_info->page, 0,
1518 length);
1519 e1000_consume_page(buffer_info, skb,
1520 length);
1521 }
1522 }
1523 }
1524
1525 /* Receive Checksum Offload XXX recompute due to CRC strip? */
Bruce Allan5f450212011-07-22 06:21:46 +00001526 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +00001527 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001528
Bruce Allan70495a52012-01-11 01:26:50 +00001529 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1530
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001531 /* probably a little skewed due to removing CRC */
1532 total_rx_bytes += skb->len;
1533 total_rx_packets++;
1534
1535 /* eth type trans needs skb->data to point to something */
1536 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001537 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001538 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001539 goto next_desc;
1540 }
1541
Bruce Allan5f450212011-07-22 06:21:46 +00001542 e1000_receive_skb(adapter, netdev, skb, staterr,
1543 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001544
1545next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001546 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001547
1548 /* return some buffers to hardware, one at a time is too slow */
1549 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001550 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001551 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001552 cleaned_count = 0;
1553 }
1554
1555 /* use prefetched values */
1556 rx_desc = next_rxd;
1557 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001558
1559 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001560 }
1561 rx_ring->next_to_clean = i;
1562
1563 cleaned_count = e1000_desc_unused(rx_ring);
1564 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001565 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001566
1567 adapter->total_rx_bytes += total_rx_bytes;
1568 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001569 return cleaned;
1570}
1571
1572/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001573 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001574 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001575 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001576static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577{
Bruce Allan55aa6982011-12-16 00:45:45 +00001578 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001579 struct e1000_buffer *buffer_info;
1580 struct e1000_ps_page *ps_page;
1581 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001582 unsigned int i, j;
1583
1584 /* Free all the Rx ring sk_buffs */
1585 for (i = 0; i < rx_ring->count; i++) {
1586 buffer_info = &rx_ring->buffer_info[i];
1587 if (buffer_info->dma) {
1588 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001589 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001590 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001591 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001592 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001593 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001594 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001595 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001596 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001597 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001598 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001599 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001600 buffer_info->dma = 0;
1601 }
1602
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001603 if (buffer_info->page) {
1604 put_page(buffer_info->page);
1605 buffer_info->page = NULL;
1606 }
1607
Auke Kokbc7f75f2007-09-17 12:30:59 -07001608 if (buffer_info->skb) {
1609 dev_kfree_skb(buffer_info->skb);
1610 buffer_info->skb = NULL;
1611 }
1612
1613 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001614 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001615 if (!ps_page->page)
1616 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001617 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1618 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001619 ps_page->dma = 0;
1620 put_page(ps_page->page);
1621 ps_page->page = NULL;
1622 }
1623 }
1624
1625 /* there also may be some cached data from a chained receive */
1626 if (rx_ring->rx_skb_top) {
1627 dev_kfree_skb(rx_ring->rx_skb_top);
1628 rx_ring->rx_skb_top = NULL;
1629 }
1630
Auke Kokbc7f75f2007-09-17 12:30:59 -07001631 /* Zero out the descriptor ring */
1632 memset(rx_ring->desc, 0, rx_ring->size);
1633
1634 rx_ring->next_to_clean = 0;
1635 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001636 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001637
Bruce Allanc5083cf2011-12-16 00:45:40 +00001638 writel(0, rx_ring->head);
1639 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001640}
1641
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001642static void e1000e_downshift_workaround(struct work_struct *work)
1643{
1644 struct e1000_adapter *adapter = container_of(work,
1645 struct e1000_adapter, downshift_task);
1646
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001647 if (test_bit(__E1000_DOWN, &adapter->state))
1648 return;
1649
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001650 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1651}
1652
Auke Kokbc7f75f2007-09-17 12:30:59 -07001653/**
1654 * e1000_intr_msi - Interrupt Handler
1655 * @irq: interrupt number
1656 * @data: pointer to a network interface device structure
1657 **/
1658static irqreturn_t e1000_intr_msi(int irq, void *data)
1659{
1660 struct net_device *netdev = data;
1661 struct e1000_adapter *adapter = netdev_priv(netdev);
1662 struct e1000_hw *hw = &adapter->hw;
1663 u32 icr = er32(ICR);
1664
Bruce Allanad680762008-03-28 09:15:03 -07001665 /*
1666 * read ICR disables interrupts using IAM
1667 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001668
dave graham573cca82009-02-10 12:52:05 +00001669 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001670 hw->mac.get_link_status = true;
Bruce Allanad680762008-03-28 09:15:03 -07001671 /*
1672 * ICH8 workaround-- Call gig speed drop workaround on cable
1673 * disconnect (LSC) before accessing any PHY registers
1674 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001675 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1676 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001677 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678
Bruce Allanad680762008-03-28 09:15:03 -07001679 /*
1680 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001682 * adapter in watchdog
1683 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001684 if (netif_carrier_ok(netdev) &&
1685 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1686 /* disable receives */
1687 u32 rctl = er32(RCTL);
1688 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001689 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001690 }
1691 /* guard against interrupt when we're going down */
1692 if (!test_bit(__E1000_DOWN, &adapter->state))
1693 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1694 }
1695
Ben Hutchings288379f2009-01-19 16:43:59 -08001696 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001697 adapter->total_tx_bytes = 0;
1698 adapter->total_tx_packets = 0;
1699 adapter->total_rx_bytes = 0;
1700 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001701 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001702 }
1703
1704 return IRQ_HANDLED;
1705}
1706
1707/**
1708 * e1000_intr - Interrupt Handler
1709 * @irq: interrupt number
1710 * @data: pointer to a network interface device structure
1711 **/
1712static irqreturn_t e1000_intr(int irq, void *data)
1713{
1714 struct net_device *netdev = data;
1715 struct e1000_adapter *adapter = netdev_priv(netdev);
1716 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001718
Bruce Allana68ea772009-11-20 23:23:16 +00001719 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001720 return IRQ_NONE; /* Not our interrupt */
1721
Bruce Allanad680762008-03-28 09:15:03 -07001722 /*
1723 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1724 * not set, then the adapter didn't send an interrupt
1725 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001726 if (!(icr & E1000_ICR_INT_ASSERTED))
1727 return IRQ_NONE;
1728
Bruce Allanad680762008-03-28 09:15:03 -07001729 /*
1730 * Interrupt Auto-Mask...upon reading ICR,
1731 * interrupts are masked. No need for the
1732 * IMC write
1733 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001734
dave graham573cca82009-02-10 12:52:05 +00001735 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001736 hw->mac.get_link_status = true;
Bruce Allanad680762008-03-28 09:15:03 -07001737 /*
1738 * ICH8 workaround-- Call gig speed drop workaround on cable
1739 * disconnect (LSC) before accessing any PHY registers
1740 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1742 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001743 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001744
Bruce Allanad680762008-03-28 09:15:03 -07001745 /*
1746 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001747 * For packet buffer work-around on link down event;
1748 * disable receives here in the ISR and
1749 * reset adapter in watchdog
1750 */
1751 if (netif_carrier_ok(netdev) &&
1752 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1753 /* disable receives */
1754 rctl = er32(RCTL);
1755 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001756 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001757 }
1758 /* guard against interrupt when we're going down */
1759 if (!test_bit(__E1000_DOWN, &adapter->state))
1760 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1761 }
1762
Ben Hutchings288379f2009-01-19 16:43:59 -08001763 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001764 adapter->total_tx_bytes = 0;
1765 adapter->total_tx_packets = 0;
1766 adapter->total_rx_bytes = 0;
1767 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001768 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001769 }
1770
1771 return IRQ_HANDLED;
1772}
1773
Bruce Allan4662e822008-08-26 18:37:06 -07001774static irqreturn_t e1000_msix_other(int irq, void *data)
1775{
1776 struct net_device *netdev = data;
1777 struct e1000_adapter *adapter = netdev_priv(netdev);
1778 struct e1000_hw *hw = &adapter->hw;
1779 u32 icr = er32(ICR);
1780
1781 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001782 if (!test_bit(__E1000_DOWN, &adapter->state))
1783 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001784 return IRQ_NONE;
1785 }
1786
1787 if (icr & adapter->eiac_mask)
1788 ew32(ICS, (icr & adapter->eiac_mask));
1789
1790 if (icr & E1000_ICR_OTHER) {
1791 if (!(icr & E1000_ICR_LSC))
1792 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001793 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001794 /* guard against interrupt when we're going down */
1795 if (!test_bit(__E1000_DOWN, &adapter->state))
1796 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1797 }
1798
1799no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001800 if (!test_bit(__E1000_DOWN, &adapter->state))
1801 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001802
1803 return IRQ_HANDLED;
1804}
1805
1806
1807static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1808{
1809 struct net_device *netdev = data;
1810 struct e1000_adapter *adapter = netdev_priv(netdev);
1811 struct e1000_hw *hw = &adapter->hw;
1812 struct e1000_ring *tx_ring = adapter->tx_ring;
1813
1814
1815 adapter->total_tx_bytes = 0;
1816 adapter->total_tx_packets = 0;
1817
Bruce Allan55aa6982011-12-16 00:45:45 +00001818 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001819 /* Ring was not completely cleaned, so fire another interrupt */
1820 ew32(ICS, tx_ring->ims_val);
1821
1822 return IRQ_HANDLED;
1823}
1824
1825static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1826{
1827 struct net_device *netdev = data;
1828 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001829 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001830
1831 /* Write the ITR value calculated at the end of the
1832 * previous interrupt.
1833 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001834 if (rx_ring->set_itr) {
1835 writel(1000000000 / (rx_ring->itr_val * 256),
1836 rx_ring->itr_register);
1837 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001838 }
1839
Ben Hutchings288379f2009-01-19 16:43:59 -08001840 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001841 adapter->total_rx_bytes = 0;
1842 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001843 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001844 }
1845 return IRQ_HANDLED;
1846}
1847
1848/**
1849 * e1000_configure_msix - Configure MSI-X hardware
1850 *
1851 * e1000_configure_msix sets up the hardware to properly
1852 * generate MSI-X interrupts.
1853 **/
1854static void e1000_configure_msix(struct e1000_adapter *adapter)
1855{
1856 struct e1000_hw *hw = &adapter->hw;
1857 struct e1000_ring *rx_ring = adapter->rx_ring;
1858 struct e1000_ring *tx_ring = adapter->tx_ring;
1859 int vector = 0;
1860 u32 ctrl_ext, ivar = 0;
1861
1862 adapter->eiac_mask = 0;
1863
1864 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1865 if (hw->mac.type == e1000_82574) {
1866 u32 rfctl = er32(RFCTL);
1867 rfctl |= E1000_RFCTL_ACK_DIS;
1868 ew32(RFCTL, rfctl);
1869 }
1870
1871#define E1000_IVAR_INT_ALLOC_VALID 0x8
1872 /* Configure Rx vector */
1873 rx_ring->ims_val = E1000_IMS_RXQ0;
1874 adapter->eiac_mask |= rx_ring->ims_val;
1875 if (rx_ring->itr_val)
1876 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001877 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001878 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001879 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001880 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1881
1882 /* Configure Tx vector */
1883 tx_ring->ims_val = E1000_IMS_TXQ0;
1884 vector++;
1885 if (tx_ring->itr_val)
1886 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001887 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001888 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001889 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001890 adapter->eiac_mask |= tx_ring->ims_val;
1891 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1892
1893 /* set vector for Other Causes, e.g. link changes */
1894 vector++;
1895 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1896 if (rx_ring->itr_val)
1897 writel(1000000000 / (rx_ring->itr_val * 256),
1898 hw->hw_addr + E1000_EITR_82574(vector));
1899 else
1900 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1901
1902 /* Cause Tx interrupts on every write back */
1903 ivar |= (1 << 31);
1904
1905 ew32(IVAR, ivar);
1906
1907 /* enable MSI-X PBA support */
1908 ctrl_ext = er32(CTRL_EXT);
1909 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1910
1911 /* Auto-Mask Other interrupts upon ICR read */
1912#define E1000_EIAC_MASK_82574 0x01F00000
1913 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1914 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1915 ew32(CTRL_EXT, ctrl_ext);
1916 e1e_flush();
1917}
1918
1919void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1920{
1921 if (adapter->msix_entries) {
1922 pci_disable_msix(adapter->pdev);
1923 kfree(adapter->msix_entries);
1924 adapter->msix_entries = NULL;
1925 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1926 pci_disable_msi(adapter->pdev);
1927 adapter->flags &= ~FLAG_MSI_ENABLED;
1928 }
Bruce Allan4662e822008-08-26 18:37:06 -07001929}
1930
1931/**
1932 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1933 *
1934 * Attempt to configure interrupts using the best available
1935 * capabilities of the hardware and kernel.
1936 **/
1937void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1938{
1939 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001940 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001941
1942 switch (adapter->int_mode) {
1943 case E1000E_INT_MODE_MSIX:
1944 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001945 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1946 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001947 sizeof(struct msix_entry),
1948 GFP_KERNEL);
1949 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001950 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001951 adapter->msix_entries[i].entry = i;
1952
1953 err = pci_enable_msix(adapter->pdev,
1954 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001955 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001956 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001957 return;
1958 }
1959 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00001960 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001961 e1000e_reset_interrupt_capability(adapter);
1962 }
1963 adapter->int_mode = E1000E_INT_MODE_MSI;
1964 /* Fall through */
1965 case E1000E_INT_MODE_MSI:
1966 if (!pci_enable_msi(adapter->pdev)) {
1967 adapter->flags |= FLAG_MSI_ENABLED;
1968 } else {
1969 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00001970 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001971 }
1972 /* Fall through */
1973 case E1000E_INT_MODE_LEGACY:
1974 /* Don't do anything; this is the system default */
1975 break;
1976 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001977
1978 /* store the number of vectors being used */
1979 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001980}
1981
1982/**
1983 * e1000_request_msix - Initialize MSI-X interrupts
1984 *
1985 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1986 * kernel.
1987 **/
1988static int e1000_request_msix(struct e1000_adapter *adapter)
1989{
1990 struct net_device *netdev = adapter->netdev;
1991 int err = 0, vector = 0;
1992
1993 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001994 snprintf(adapter->rx_ring->name,
1995 sizeof(adapter->rx_ring->name) - 1,
1996 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001997 else
1998 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1999 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002000 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002001 netdev);
2002 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002003 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002004 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2005 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002006 adapter->rx_ring->itr_val = adapter->itr;
2007 vector++;
2008
2009 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002010 snprintf(adapter->tx_ring->name,
2011 sizeof(adapter->tx_ring->name) - 1,
2012 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002013 else
2014 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2015 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002016 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002017 netdev);
2018 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002019 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002020 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2021 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002022 adapter->tx_ring->itr_val = adapter->itr;
2023 vector++;
2024
2025 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002026 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002027 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002028 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002029
2030 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002031
Bruce Allan4662e822008-08-26 18:37:06 -07002032 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002033}
2034
Bruce Allanf8d59f72008-08-08 18:36:11 -07002035/**
2036 * e1000_request_irq - initialize interrupts
2037 *
2038 * Attempts to configure interrupts using the best available
2039 * capabilities of the hardware and kernel.
2040 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002041static int e1000_request_irq(struct e1000_adapter *adapter)
2042{
2043 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002044 int err;
2045
Bruce Allan4662e822008-08-26 18:37:06 -07002046 if (adapter->msix_entries) {
2047 err = e1000_request_msix(adapter);
2048 if (!err)
2049 return err;
2050 /* fall back to MSI */
2051 e1000e_reset_interrupt_capability(adapter);
2052 adapter->int_mode = E1000E_INT_MODE_MSI;
2053 e1000e_set_interrupt_capability(adapter);
2054 }
2055 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002056 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002057 netdev->name, netdev);
2058 if (!err)
2059 return err;
2060
2061 /* fall back to legacy interrupt */
2062 e1000e_reset_interrupt_capability(adapter);
2063 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002064 }
2065
Joe Perchesa0607fd2009-11-18 23:29:17 -08002066 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002067 netdev->name, netdev);
2068 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002069 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002070
2071 return err;
2072}
2073
2074static void e1000_free_irq(struct e1000_adapter *adapter)
2075{
2076 struct net_device *netdev = adapter->netdev;
2077
Bruce Allan4662e822008-08-26 18:37:06 -07002078 if (adapter->msix_entries) {
2079 int vector = 0;
2080
2081 free_irq(adapter->msix_entries[vector].vector, netdev);
2082 vector++;
2083
2084 free_irq(adapter->msix_entries[vector].vector, netdev);
2085 vector++;
2086
2087 /* Other Causes interrupt vector */
2088 free_irq(adapter->msix_entries[vector].vector, netdev);
2089 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002090 }
Bruce Allan4662e822008-08-26 18:37:06 -07002091
2092 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002093}
2094
2095/**
2096 * e1000_irq_disable - Mask off interrupt generation on the NIC
2097 **/
2098static void e1000_irq_disable(struct e1000_adapter *adapter)
2099{
2100 struct e1000_hw *hw = &adapter->hw;
2101
Auke Kokbc7f75f2007-09-17 12:30:59 -07002102 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002103 if (adapter->msix_entries)
2104 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002105 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002106
2107 if (adapter->msix_entries) {
2108 int i;
2109 for (i = 0; i < adapter->num_vectors; i++)
2110 synchronize_irq(adapter->msix_entries[i].vector);
2111 } else {
2112 synchronize_irq(adapter->pdev->irq);
2113 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002114}
2115
2116/**
2117 * e1000_irq_enable - Enable default interrupt generation settings
2118 **/
2119static void e1000_irq_enable(struct e1000_adapter *adapter)
2120{
2121 struct e1000_hw *hw = &adapter->hw;
2122
Bruce Allan4662e822008-08-26 18:37:06 -07002123 if (adapter->msix_entries) {
2124 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2125 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2126 } else {
2127 ew32(IMS, IMS_ENABLE_MASK);
2128 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002129 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002130}
2131
2132/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002133 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002134 * @adapter: address of board private structure
2135 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002136 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002137 * For ASF and Pass Through versions of f/w this means that
2138 * the driver is loaded. For AMT version (only with 82573)
2139 * of the f/w this means that the network i/f is open.
2140 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002141void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002142{
2143 struct e1000_hw *hw = &adapter->hw;
2144 u32 ctrl_ext;
2145 u32 swsm;
2146
2147 /* Let firmware know the driver has taken over */
2148 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2149 swsm = er32(SWSM);
2150 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2151 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2152 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002153 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002154 }
2155}
2156
2157/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002158 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002159 * @adapter: address of board private structure
2160 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002161 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002162 * For ASF and Pass Through versions of f/w this means that the
2163 * driver is no longer loaded. For AMT version (only with 82573) i
2164 * of the f/w this means that the network i/f is closed.
2165 *
2166 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002167void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002168{
2169 struct e1000_hw *hw = &adapter->hw;
2170 u32 ctrl_ext;
2171 u32 swsm;
2172
2173 /* Let firmware taken over control of h/w */
2174 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2175 swsm = er32(SWSM);
2176 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2177 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2178 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002179 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002180 }
2181}
2182
Auke Kokbc7f75f2007-09-17 12:30:59 -07002183/**
2184 * @e1000_alloc_ring - allocate memory for a ring structure
2185 **/
2186static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2187 struct e1000_ring *ring)
2188{
2189 struct pci_dev *pdev = adapter->pdev;
2190
2191 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2192 GFP_KERNEL);
2193 if (!ring->desc)
2194 return -ENOMEM;
2195
2196 return 0;
2197}
2198
2199/**
2200 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002201 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002202 *
2203 * Return 0 on success, negative on failure
2204 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002205int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002206{
Bruce Allan55aa6982011-12-16 00:45:45 +00002207 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002208 int err = -ENOMEM, size;
2209
2210 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002211 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002212 if (!tx_ring->buffer_info)
2213 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002214
2215 /* round up to nearest 4K */
2216 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2217 tx_ring->size = ALIGN(tx_ring->size, 4096);
2218
2219 err = e1000_alloc_ring_dma(adapter, tx_ring);
2220 if (err)
2221 goto err;
2222
2223 tx_ring->next_to_use = 0;
2224 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002225
2226 return 0;
2227err:
2228 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002229 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002230 return err;
2231}
2232
2233/**
2234 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002235 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002236 *
2237 * Returns 0 on success, negative on failure
2238 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002239int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002240{
Bruce Allan55aa6982011-12-16 00:45:45 +00002241 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002242 struct e1000_buffer *buffer_info;
2243 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244
2245 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002246 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002247 if (!rx_ring->buffer_info)
2248 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002249
Auke Kok47f44e42007-10-25 13:57:44 -07002250 for (i = 0; i < rx_ring->count; i++) {
2251 buffer_info = &rx_ring->buffer_info[i];
2252 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2253 sizeof(struct e1000_ps_page),
2254 GFP_KERNEL);
2255 if (!buffer_info->ps_pages)
2256 goto err_pages;
2257 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002258
2259 desc_len = sizeof(union e1000_rx_desc_packet_split);
2260
2261 /* Round up to nearest 4K */
2262 rx_ring->size = rx_ring->count * desc_len;
2263 rx_ring->size = ALIGN(rx_ring->size, 4096);
2264
2265 err = e1000_alloc_ring_dma(adapter, rx_ring);
2266 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002267 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002268
2269 rx_ring->next_to_clean = 0;
2270 rx_ring->next_to_use = 0;
2271 rx_ring->rx_skb_top = NULL;
2272
2273 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002274
2275err_pages:
2276 for (i = 0; i < rx_ring->count; i++) {
2277 buffer_info = &rx_ring->buffer_info[i];
2278 kfree(buffer_info->ps_pages);
2279 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002280err:
2281 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002282 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002283 return err;
2284}
2285
2286/**
2287 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002288 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002289 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002290static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002291{
Bruce Allan55aa6982011-12-16 00:45:45 +00002292 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002293 struct e1000_buffer *buffer_info;
2294 unsigned long size;
2295 unsigned int i;
2296
2297 for (i = 0; i < tx_ring->count; i++) {
2298 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002299 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002300 }
2301
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002302 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002303 size = sizeof(struct e1000_buffer) * tx_ring->count;
2304 memset(tx_ring->buffer_info, 0, size);
2305
2306 memset(tx_ring->desc, 0, tx_ring->size);
2307
2308 tx_ring->next_to_use = 0;
2309 tx_ring->next_to_clean = 0;
2310
Bruce Allanc5083cf2011-12-16 00:45:40 +00002311 writel(0, tx_ring->head);
2312 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002313}
2314
2315/**
2316 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002317 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002318 *
2319 * Free all transmit software resources
2320 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002321void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002322{
Bruce Allan55aa6982011-12-16 00:45:45 +00002323 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325
Bruce Allan55aa6982011-12-16 00:45:45 +00002326 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327
2328 vfree(tx_ring->buffer_info);
2329 tx_ring->buffer_info = NULL;
2330
2331 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2332 tx_ring->dma);
2333 tx_ring->desc = NULL;
2334}
2335
2336/**
2337 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002338 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002339 *
2340 * Free all receive software resources
2341 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002342void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002343{
Bruce Allan55aa6982011-12-16 00:45:45 +00002344 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002345 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002346 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002347
Bruce Allan55aa6982011-12-16 00:45:45 +00002348 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002349
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002350 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002351 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002352
Auke Kokbc7f75f2007-09-17 12:30:59 -07002353 vfree(rx_ring->buffer_info);
2354 rx_ring->buffer_info = NULL;
2355
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2357 rx_ring->dma);
2358 rx_ring->desc = NULL;
2359}
2360
2361/**
2362 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002363 * @adapter: pointer to adapter
2364 * @itr_setting: current adapter->itr
2365 * @packets: the number of packets during this measurement interval
2366 * @bytes: the number of bytes during this measurement interval
2367 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002368 * Stores a new ITR value based on packets and byte
2369 * counts during the last interrupt. The advantage of per interrupt
2370 * computation is faster updates and more accurate ITR for the current
2371 * traffic pattern. Constants in this function were computed
2372 * based on theoretical maximum wire speed and thresholds were set based
2373 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002374 * while increasing bulk throughput. This functionality is controlled
2375 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002376 **/
2377static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2378 u16 itr_setting, int packets,
2379 int bytes)
2380{
2381 unsigned int retval = itr_setting;
2382
2383 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002384 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002385
2386 switch (itr_setting) {
2387 case lowest_latency:
2388 /* handle TSO and jumbo frames */
2389 if (bytes/packets > 8000)
2390 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002391 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002392 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002393 break;
2394 case low_latency: /* 50 usec aka 20000 ints/s */
2395 if (bytes > 10000) {
2396 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002397 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002399 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002400 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002401 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002402 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002403 } else if (bytes/packets > 2000) {
2404 retval = bulk_latency;
2405 } else if (packets <= 2 && bytes < 512) {
2406 retval = lowest_latency;
2407 }
2408 break;
2409 case bulk_latency: /* 250 usec aka 4000 ints/s */
2410 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002411 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002412 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002413 } else if (bytes < 6000) {
2414 retval = low_latency;
2415 }
2416 break;
2417 }
2418
Auke Kokbc7f75f2007-09-17 12:30:59 -07002419 return retval;
2420}
2421
2422static void e1000_set_itr(struct e1000_adapter *adapter)
2423{
2424 struct e1000_hw *hw = &adapter->hw;
2425 u16 current_itr;
2426 u32 new_itr = adapter->itr;
2427
2428 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2429 if (adapter->link_speed != SPEED_1000) {
2430 current_itr = 0;
2431 new_itr = 4000;
2432 goto set_itr_now;
2433 }
2434
Bruce Allan828bac82010-09-29 21:39:37 +00002435 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2436 new_itr = 0;
2437 goto set_itr_now;
2438 }
2439
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440 adapter->tx_itr = e1000_update_itr(adapter,
2441 adapter->tx_itr,
2442 adapter->total_tx_packets,
2443 adapter->total_tx_bytes);
2444 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2445 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2446 adapter->tx_itr = low_latency;
2447
2448 adapter->rx_itr = e1000_update_itr(adapter,
2449 adapter->rx_itr,
2450 adapter->total_rx_packets,
2451 adapter->total_rx_bytes);
2452 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2453 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2454 adapter->rx_itr = low_latency;
2455
2456 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2457
2458 switch (current_itr) {
2459 /* counts and packets in update_itr are dependent on these numbers */
2460 case lowest_latency:
2461 new_itr = 70000;
2462 break;
2463 case low_latency:
2464 new_itr = 20000; /* aka hwitr = ~200 */
2465 break;
2466 case bulk_latency:
2467 new_itr = 4000;
2468 break;
2469 default:
2470 break;
2471 }
2472
2473set_itr_now:
2474 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002475 /*
2476 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002477 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002478 * increasing
2479 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002480 new_itr = new_itr > adapter->itr ?
2481 min(adapter->itr + (new_itr >> 2), new_itr) :
2482 new_itr;
2483 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002484 adapter->rx_ring->itr_val = new_itr;
2485 if (adapter->msix_entries)
2486 adapter->rx_ring->set_itr = 1;
2487 else
Bruce Allan828bac82010-09-29 21:39:37 +00002488 if (new_itr)
2489 ew32(ITR, 1000000000 / (new_itr * 256));
2490 else
2491 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002492 }
2493}
2494
2495/**
Bruce Allan4662e822008-08-26 18:37:06 -07002496 * e1000_alloc_queues - Allocate memory for all rings
2497 * @adapter: board private structure to initialize
2498 **/
2499static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2500{
Bruce Allan55aa6982011-12-16 00:45:45 +00002501 int size = sizeof(struct e1000_ring);
2502
2503 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002504 if (!adapter->tx_ring)
2505 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002506 adapter->tx_ring->count = adapter->tx_ring_count;
2507 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002508
Bruce Allan55aa6982011-12-16 00:45:45 +00002509 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002510 if (!adapter->rx_ring)
2511 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002512 adapter->rx_ring->count = adapter->rx_ring_count;
2513 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002514
2515 return 0;
2516err:
2517 e_err("Unable to allocate memory for queues\n");
2518 kfree(adapter->rx_ring);
2519 kfree(adapter->tx_ring);
2520 return -ENOMEM;
2521}
2522
2523/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002524 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002525 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002526 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527 **/
2528static int e1000_clean(struct napi_struct *napi, int budget)
2529{
2530 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002531 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002532 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002533 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002534
Wang Chen4cf16532008-11-12 23:38:14 -08002535 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002536
Bruce Allan4662e822008-08-26 18:37:06 -07002537 if (adapter->msix_entries &&
2538 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2539 goto clean_rx;
2540
Bruce Allan55aa6982011-12-16 00:45:45 +00002541 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002542
Bruce Allan4662e822008-08-26 18:37:06 -07002543clean_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00002544 adapter->clean_rx(adapter->rx_ring, &work_done, budget);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002545
Alexander Duyck12d04a32009-03-25 22:05:03 +00002546 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002547 work_done = budget;
2548
David S. Miller53e52c72008-01-07 21:06:12 -08002549 /* If budget not fully consumed, exit the polling mode */
2550 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002551 if (adapter->itr_setting & 3)
2552 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002553 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002554 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2555 if (adapter->msix_entries)
2556 ew32(IMS, adapter->rx_ring->ims_val);
2557 else
2558 e1000_irq_enable(adapter);
2559 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560 }
2561
2562 return work_done;
2563}
2564
Jiri Pirko8e586132011-12-08 19:52:37 -05002565static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566{
2567 struct e1000_adapter *adapter = netdev_priv(netdev);
2568 struct e1000_hw *hw = &adapter->hw;
2569 u32 vfta, index;
2570
2571 /* don't update vlan cookie if already programmed */
2572 if ((adapter->hw.mng_cookie.status &
2573 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2574 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002575 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002576
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002578 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2579 index = (vid >> 5) & 0x7F;
2580 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2581 vfta |= (1 << (vid & 0x1F));
2582 hw->mac.ops.write_vfta(hw, index, vfta);
2583 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002584
2585 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002586
2587 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002588}
2589
Jiri Pirko8e586132011-12-08 19:52:37 -05002590static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002591{
2592 struct e1000_adapter *adapter = netdev_priv(netdev);
2593 struct e1000_hw *hw = &adapter->hw;
2594 u32 vfta, index;
2595
Auke Kokbc7f75f2007-09-17 12:30:59 -07002596 if ((adapter->hw.mng_cookie.status &
2597 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2598 (vid == adapter->mng_vlan_id)) {
2599 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002600 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002601 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002602 }
2603
2604 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002605 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2606 index = (vid >> 5) & 0x7F;
2607 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2608 vfta &= ~(1 << (vid & 0x1F));
2609 hw->mac.ops.write_vfta(hw, index, vfta);
2610 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002611
2612 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002613
2614 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002615}
2616
2617/**
2618 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2619 * @adapter: board private structure to initialize
2620 **/
2621static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2622{
2623 struct net_device *netdev = adapter->netdev;
2624 struct e1000_hw *hw = &adapter->hw;
2625 u32 rctl;
2626
2627 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2628 /* disable VLAN receive filtering */
2629 rctl = er32(RCTL);
2630 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2631 ew32(RCTL, rctl);
2632
2633 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2634 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2635 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2636 }
2637 }
2638}
2639
2640/**
2641 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2642 * @adapter: board private structure to initialize
2643 **/
2644static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2645{
2646 struct e1000_hw *hw = &adapter->hw;
2647 u32 rctl;
2648
2649 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2650 /* enable VLAN receive filtering */
2651 rctl = er32(RCTL);
2652 rctl |= E1000_RCTL_VFE;
2653 rctl &= ~E1000_RCTL_CFIEN;
2654 ew32(RCTL, rctl);
2655 }
2656}
2657
2658/**
2659 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2660 * @adapter: board private structure to initialize
2661 **/
2662static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2663{
2664 struct e1000_hw *hw = &adapter->hw;
2665 u32 ctrl;
2666
2667 /* disable VLAN tag insert/strip */
2668 ctrl = er32(CTRL);
2669 ctrl &= ~E1000_CTRL_VME;
2670 ew32(CTRL, ctrl);
2671}
2672
2673/**
2674 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2675 * @adapter: board private structure to initialize
2676 **/
2677static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2678{
2679 struct e1000_hw *hw = &adapter->hw;
2680 u32 ctrl;
2681
2682 /* enable VLAN tag insert/strip */
2683 ctrl = er32(CTRL);
2684 ctrl |= E1000_CTRL_VME;
2685 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002686}
2687
2688static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2689{
2690 struct net_device *netdev = adapter->netdev;
2691 u16 vid = adapter->hw.mng_cookie.vlan_id;
2692 u16 old_vid = adapter->mng_vlan_id;
2693
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002694 if (adapter->hw.mng_cookie.status &
2695 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2696 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002697 adapter->mng_vlan_id = vid;
2698 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002699
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002700 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2701 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002702}
2703
2704static void e1000_restore_vlan(struct e1000_adapter *adapter)
2705{
2706 u16 vid;
2707
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002708 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002709
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002710 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002712}
2713
Bruce Allancd791612010-05-10 14:59:51 +00002714static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002715{
2716 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002717 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002718
2719 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2720 return;
2721
2722 manc = er32(MANC);
2723
Bruce Allanad680762008-03-28 09:15:03 -07002724 /*
2725 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002726 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002727 * the packets will be handled on SMBUS
2728 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002729 manc |= E1000_MANC_EN_MNG2HOST;
2730 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002731
2732 switch (hw->mac.type) {
2733 default:
2734 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2735 break;
2736 case e1000_82574:
2737 case e1000_82583:
2738 /*
2739 * Check if IPMI pass-through decision filter already exists;
2740 * if so, enable it.
2741 */
2742 for (i = 0, j = 0; i < 8; i++) {
2743 mdef = er32(MDEF(i));
2744
2745 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002746 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002747 continue;
2748
2749 /* Enable this decision filter in MANC2H */
2750 if (mdef)
2751 manc2h |= (1 << i);
2752
2753 j |= mdef;
2754 }
2755
2756 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2757 break;
2758
2759 /* Create new decision filter in an empty filter */
2760 for (i = 0, j = 0; i < 8; i++)
2761 if (er32(MDEF(i)) == 0) {
2762 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2763 E1000_MDEF_PORT_664));
2764 manc2h |= (1 << 1);
2765 j++;
2766 break;
2767 }
2768
2769 if (!j)
2770 e_warn("Unable to create IPMI pass-through filter\n");
2771 break;
2772 }
2773
Auke Kokbc7f75f2007-09-17 12:30:59 -07002774 ew32(MANC2H, manc2h);
2775 ew32(MANC, manc);
2776}
2777
2778/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002779 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002780 * @adapter: board private structure
2781 *
2782 * Configure the Tx unit of the MAC after a reset.
2783 **/
2784static void e1000_configure_tx(struct e1000_adapter *adapter)
2785{
2786 struct e1000_hw *hw = &adapter->hw;
2787 struct e1000_ring *tx_ring = adapter->tx_ring;
2788 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002789 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002790
2791 /* Setup the HW Tx Head and Tail descriptor pointers */
2792 tdba = tx_ring->dma;
2793 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002794 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002795 ew32(TDBAH, (tdba >> 32));
2796 ew32(TDLEN, tdlen);
2797 ew32(TDH, 0);
2798 ew32(TDT, 0);
Bruce Allanc5083cf2011-12-16 00:45:40 +00002799 tx_ring->head = adapter->hw.hw_addr + E1000_TDH;
2800 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801
Auke Kokbc7f75f2007-09-17 12:30:59 -07002802 /* Set the Tx Interrupt Delay register */
2803 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002804 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002805 ew32(TADV, adapter->tx_abs_int_delay);
2806
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002807 if (adapter->flags2 & FLAG2_DMA_BURST) {
2808 u32 txdctl = er32(TXDCTL(0));
2809 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2810 E1000_TXDCTL_WTHRESH);
2811 /*
2812 * set up some performance related parameters to encourage the
2813 * hardware to use the bus more efficiently in bursts, depends
2814 * on the tx_int_delay to be enabled,
2815 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2816 * hthresh = 1 ==> prefetch when one or more available
2817 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2818 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002819 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002820 */
2821 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2822 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002823 }
Bruce Allan56032be2011-12-16 00:46:01 +00002824 /* erratum work around: set txdctl the same for both queues */
2825 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002826
Auke Kokbc7f75f2007-09-17 12:30:59 -07002827 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002828 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002829 /*
2830 * set the speed mode bit, we'll clear it if we're not at
2831 * gigabit link later
2832 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833#define SPEED_MODE_BIT (1 << 21)
2834 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002835 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002836 }
2837
2838 /* errata: program both queues to unweighted RR */
2839 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002840 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002841 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002842 ew32(TARC(0), tarc);
2843 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002845 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002846 }
2847
Auke Kokbc7f75f2007-09-17 12:30:59 -07002848 /* Setup Transmit Descriptor Settings for eop descriptor */
2849 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2850
2851 /* only set IDE if we are delaying interrupts using the timers */
2852 if (adapter->tx_int_delay)
2853 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2854
2855 /* enable Report Status bit */
2856 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2857
Bruce Allan57cde762012-02-22 09:02:58 +00002858 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002859}
2860
2861/**
2862 * e1000_setup_rctl - configure the receive control registers
2863 * @adapter: Board private structure
2864 **/
2865#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2866 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2867static void e1000_setup_rctl(struct e1000_adapter *adapter)
2868{
2869 struct e1000_hw *hw = &adapter->hw;
2870 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002871 u32 pages = 0;
2872
Bruce Allana1ce6472010-09-22 17:16:40 +00002873 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2874 if (hw->mac.type == e1000_pch2lan) {
2875 s32 ret_val;
2876
2877 if (adapter->netdev->mtu > ETH_DATA_LEN)
2878 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2879 else
2880 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002881
2882 if (ret_val)
2883 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002884 }
2885
Auke Kokbc7f75f2007-09-17 12:30:59 -07002886 /* Program MC offset vector base */
2887 rctl = er32(RCTL);
2888 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2889 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2890 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2891 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2892
2893 /* Do not Store bad packets */
2894 rctl &= ~E1000_RCTL_SBP;
2895
2896 /* Enable Long Packet receive */
2897 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2898 rctl &= ~E1000_RCTL_LPE;
2899 else
2900 rctl |= E1000_RCTL_LPE;
2901
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002902 /* Some systems expect that the CRC is included in SMBUS traffic. The
2903 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2904 * host memory when this is enabled
2905 */
2906 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2907 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002908
Bruce Allana4f58f52009-06-02 11:29:18 +00002909 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2910 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2911 u16 phy_data;
2912
2913 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2914 phy_data &= 0xfff8;
2915 phy_data |= (1 << 2);
2916 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2917
2918 e1e_rphy(hw, 22, &phy_data);
2919 phy_data &= 0x0fff;
2920 phy_data |= (1 << 14);
2921 e1e_wphy(hw, 0x10, 0x2823);
2922 e1e_wphy(hw, 0x11, 0x0003);
2923 e1e_wphy(hw, 22, phy_data);
2924 }
2925
Auke Kokbc7f75f2007-09-17 12:30:59 -07002926 /* Setup buffer sizes */
2927 rctl &= ~E1000_RCTL_SZ_4096;
2928 rctl |= E1000_RCTL_BSEX;
2929 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002930 case 2048:
2931 default:
2932 rctl |= E1000_RCTL_SZ_2048;
2933 rctl &= ~E1000_RCTL_BSEX;
2934 break;
2935 case 4096:
2936 rctl |= E1000_RCTL_SZ_4096;
2937 break;
2938 case 8192:
2939 rctl |= E1000_RCTL_SZ_8192;
2940 break;
2941 case 16384:
2942 rctl |= E1000_RCTL_SZ_16384;
2943 break;
2944 }
2945
Bruce Allan5f450212011-07-22 06:21:46 +00002946 /* Enable Extended Status in all Receive Descriptors */
2947 rfctl = er32(RFCTL);
2948 rfctl |= E1000_RFCTL_EXTEN;
2949
Auke Kokbc7f75f2007-09-17 12:30:59 -07002950 /*
2951 * 82571 and greater support packet-split where the protocol
2952 * header is placed in skb->data and the packet data is
2953 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2954 * In the case of a non-split, skb->data is linearly filled,
2955 * followed by the page buffers. Therefore, skb->data is
2956 * sized to hold the largest protocol header.
2957 *
2958 * allocations using alloc_page take too long for regular MTU
2959 * so only enable packet split for jumbo frames
2960 *
2961 * Using pages when the page size is greater than 16k wastes
2962 * a lot of memory, since we allocate 3 pages at all times
2963 * per packet.
2964 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002965 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00002966 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002967 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002968 else
2969 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002970
2971 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002972 u32 psrctl = 0;
2973
Bruce Allanad680762008-03-28 09:15:03 -07002974 /*
2975 * disable packet split support for IPv6 extension headers,
2976 * because some malformed IPv6 headers can hang the Rx
2977 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002978 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2979 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2980
Auke Kok140a7482007-10-25 13:57:58 -07002981 /* Enable Packet split descriptors */
2982 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002983
2984 psrctl |= adapter->rx_ps_bsize0 >>
2985 E1000_PSRCTL_BSIZE0_SHIFT;
2986
2987 switch (adapter->rx_ps_pages) {
2988 case 3:
2989 psrctl |= PAGE_SIZE <<
2990 E1000_PSRCTL_BSIZE3_SHIFT;
2991 case 2:
2992 psrctl |= PAGE_SIZE <<
2993 E1000_PSRCTL_BSIZE2_SHIFT;
2994 case 1:
2995 psrctl |= PAGE_SIZE >>
2996 E1000_PSRCTL_BSIZE1_SHIFT;
2997 break;
2998 }
2999
3000 ew32(PSRCTL, psrctl);
3001 }
3002
Ben Greearcf955e62012-02-11 15:39:51 +00003003 /* This is useful for sniffing bad packets. */
3004 if (adapter->netdev->features & NETIF_F_RXALL) {
3005 /* UPE and MPE will be handled by normal PROMISC logic
3006 * in e1000e_set_rx_mode */
3007 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3008 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3009 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3010
3011 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3012 E1000_RCTL_DPF | /* Allow filtered pause */
3013 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3014 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3015 * and that breaks VLANs.
3016 */
3017 }
3018
Bruce Allan5f450212011-07-22 06:21:46 +00003019 ew32(RFCTL, rfctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003020 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003021 /* just started the receive unit, no need to restart */
3022 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003023}
3024
3025/**
3026 * e1000_configure_rx - Configure Receive Unit after Reset
3027 * @adapter: board private structure
3028 *
3029 * Configure the Rx unit of the MAC after a reset.
3030 **/
3031static void e1000_configure_rx(struct e1000_adapter *adapter)
3032{
3033 struct e1000_hw *hw = &adapter->hw;
3034 struct e1000_ring *rx_ring = adapter->rx_ring;
3035 u64 rdba;
3036 u32 rdlen, rctl, rxcsum, ctrl_ext;
3037
3038 if (adapter->rx_ps_pages) {
3039 /* this is a 32 byte descriptor */
3040 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003041 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003042 adapter->clean_rx = e1000_clean_rx_irq_ps;
3043 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003044 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003045 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003046 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3047 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003048 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003049 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003050 adapter->clean_rx = e1000_clean_rx_irq;
3051 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3052 }
3053
3054 /* disable receives while setting up the descriptors */
3055 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003056 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3057 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003058 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003059 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003060
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003061 if (adapter->flags2 & FLAG2_DMA_BURST) {
3062 /*
3063 * set the writeback threshold (only takes effect if the RDTR
3064 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003065 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003066 * granularity = 01
3067 * wthresh = 04,
3068 * hthresh = 04,
3069 * pthresh = 0x20
3070 */
3071 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3072 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3073
3074 /*
3075 * override the delay timers for enabling bursting, only if
3076 * the value was not set by the user via module options
3077 */
3078 if (adapter->rx_int_delay == DEFAULT_RDTR)
3079 adapter->rx_int_delay = BURST_RDTR;
3080 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3081 adapter->rx_abs_int_delay = BURST_RADV;
3082 }
3083
Auke Kokbc7f75f2007-09-17 12:30:59 -07003084 /* set the Receive Delay Timer Register */
3085 ew32(RDTR, adapter->rx_int_delay);
3086
3087 /* irq moderation */
3088 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003089 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003090 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003091
3092 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003093 /* Auto-Mask interrupts upon ICR access */
3094 ctrl_ext |= E1000_CTRL_EXT_IAME;
3095 ew32(IAM, 0xffffffff);
3096 ew32(CTRL_EXT, ctrl_ext);
3097 e1e_flush();
3098
Bruce Allanad680762008-03-28 09:15:03 -07003099 /*
3100 * Setup the HW Rx Head and Tail Descriptor Pointers and
3101 * the Base and Length of the Rx Descriptor Ring
3102 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003103 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07003104 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003105 ew32(RDBAH, (rdba >> 32));
3106 ew32(RDLEN, rdlen);
3107 ew32(RDH, 0);
3108 ew32(RDT, 0);
Bruce Allanc5083cf2011-12-16 00:45:40 +00003109 rx_ring->head = adapter->hw.hw_addr + E1000_RDH;
3110 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003111
3112 /* Enable Receive Checksum Offload for TCP and UDP */
3113 rxcsum = er32(RXCSUM);
Bruce Allandc221292011-08-19 03:23:48 +00003114 if (adapter->netdev->features & NETIF_F_RXCSUM) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003115 rxcsum |= E1000_RXCSUM_TUOFL;
3116
Bruce Allanad680762008-03-28 09:15:03 -07003117 /*
3118 * IPv4 payload checksum for UDP fragments must be
3119 * used in conjunction with packet-split.
3120 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003121 if (adapter->rx_ps_pages)
3122 rxcsum |= E1000_RXCSUM_IPPCSE;
3123 } else {
3124 rxcsum &= ~E1000_RXCSUM_TUOFL;
3125 /* no need to clear IPPCSE as it defaults to 0 */
3126 }
3127 ew32(RXCSUM, rxcsum);
3128
Bruce Allan79d4e902011-12-16 00:46:27 +00003129 if (adapter->hw.mac.type == e1000_pch2lan) {
3130 /*
3131 * With jumbo frames, excessive C-state transition
3132 * latencies result in dropped transactions.
3133 */
Bruce Allan53ec5492009-11-20 23:27:40 +00003134 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3135 u32 rxdctl = er32(RXDCTL(0));
3136 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allanaf667a22010-12-31 06:10:01 +00003137 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003138 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003139 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3140 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003141 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003142 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003143
3144 /* Enable Receives */
3145 ew32(RCTL, rctl);
3146}
3147
3148/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003149 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003150 * @netdev: network interface device structure
3151 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003152 * Writes multicast address list to the MTA hash table.
3153 * Returns: -ENOMEM on failure
3154 * 0 on no addresses written
3155 * X on writing X addresses to MTA
3156 */
3157static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003158{
3159 struct e1000_adapter *adapter = netdev_priv(netdev);
3160 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003161 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003162 u8 *mta_list;
3163 int i;
3164
3165 if (netdev_mc_empty(netdev)) {
3166 /* nothing to program, so clear mc list */
3167 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3168 return 0;
3169 }
3170
3171 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3172 if (!mta_list)
3173 return -ENOMEM;
3174
3175 /* update_mc_addr_list expects a packed array of only addresses. */
3176 i = 0;
3177 netdev_for_each_mc_addr(ha, netdev)
3178 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3179
3180 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3181 kfree(mta_list);
3182
3183 return netdev_mc_count(netdev);
3184}
3185
3186/**
3187 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3188 * @netdev: network interface device structure
3189 *
3190 * Writes unicast address list to the RAR table.
3191 * Returns: -ENOMEM on failure/insufficient address space
3192 * 0 on no addresses written
3193 * X on writing X addresses to the RAR table
3194 **/
3195static int e1000e_write_uc_addr_list(struct net_device *netdev)
3196{
3197 struct e1000_adapter *adapter = netdev_priv(netdev);
3198 struct e1000_hw *hw = &adapter->hw;
3199 unsigned int rar_entries = hw->mac.rar_entry_count;
3200 int count = 0;
3201
3202 /* save a rar entry for our hardware address */
3203 rar_entries--;
3204
3205 /* save a rar entry for the LAA workaround */
3206 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3207 rar_entries--;
3208
3209 /* return ENOMEM indicating insufficient memory for addresses */
3210 if (netdev_uc_count(netdev) > rar_entries)
3211 return -ENOMEM;
3212
3213 if (!netdev_uc_empty(netdev) && rar_entries) {
3214 struct netdev_hw_addr *ha;
3215
3216 /*
3217 * write the addresses in reverse order to avoid write
3218 * combining
3219 */
3220 netdev_for_each_uc_addr(ha, netdev) {
3221 if (!rar_entries)
3222 break;
3223 e1000e_rar_set(hw, ha->addr, rar_entries--);
3224 count++;
3225 }
3226 }
3227
3228 /* zero out the remaining RAR entries not used above */
3229 for (; rar_entries > 0; rar_entries--) {
3230 ew32(RAH(rar_entries), 0);
3231 ew32(RAL(rar_entries), 0);
3232 }
3233 e1e_flush();
3234
3235 return count;
3236}
3237
3238/**
3239 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3240 * @netdev: network interface device structure
3241 *
3242 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3243 * address list or the network interface flags are updated. This routine is
3244 * responsible for configuring the hardware for proper unicast, multicast,
3245 * promiscuous mode, and all-multi behavior.
3246 **/
3247static void e1000e_set_rx_mode(struct net_device *netdev)
3248{
3249 struct e1000_adapter *adapter = netdev_priv(netdev);
3250 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003251 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003252
3253 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003254 rctl = er32(RCTL);
3255
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003256 /* clear the affected bits */
3257 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3258
Auke Kokbc7f75f2007-09-17 12:30:59 -07003259 if (netdev->flags & IFF_PROMISC) {
3260 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003261 /* Do not hardware filter VLANs in promisc mode */
3262 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003263 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003264 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003265
Patrick McHardy746b9f02008-07-16 20:15:45 -07003266 if (netdev->flags & IFF_ALLMULTI) {
3267 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003268 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003269 /*
3270 * Write addresses to the MTA, if the attempt fails
3271 * then we should just turn on promiscuous mode so
3272 * that we can at least receive multicast traffic
3273 */
3274 count = e1000e_write_mc_addr_list(netdev);
3275 if (count < 0)
3276 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003277 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003278 e1000e_vlan_filter_enable(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003279 /*
3280 * Write addresses to available RAR registers, if there is not
3281 * sufficient space to store all the addresses then enable
3282 * unicast promiscuous mode
3283 */
3284 count = e1000e_write_uc_addr_list(netdev);
3285 if (count < 0)
3286 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003287 }
3288
3289 ew32(RCTL, rctl);
3290
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003291 if (netdev->features & NETIF_F_HW_VLAN_RX)
3292 e1000e_vlan_strip_enable(adapter);
3293 else
3294 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003295}
3296
Bruce Allan70495a52012-01-11 01:26:50 +00003297static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3298{
3299 struct e1000_hw *hw = &adapter->hw;
3300 u32 mrqc, rxcsum;
3301 int i;
3302 static const u32 rsskey[10] = {
3303 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3304 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3305 };
3306
3307 /* Fill out hash function seed */
3308 for (i = 0; i < 10; i++)
3309 ew32(RSSRK(i), rsskey[i]);
3310
3311 /* Direct all traffic to queue 0 */
3312 for (i = 0; i < 32; i++)
3313 ew32(RETA(i), 0);
3314
3315 /*
3316 * Disable raw packet checksumming so that RSS hash is placed in
3317 * descriptor on writeback.
3318 */
3319 rxcsum = er32(RXCSUM);
3320 rxcsum |= E1000_RXCSUM_PCSD;
3321
3322 ew32(RXCSUM, rxcsum);
3323
3324 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3325 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3326 E1000_MRQC_RSS_FIELD_IPV6 |
3327 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3328 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3329
3330 ew32(MRQC, mrqc);
3331}
3332
Auke Kokbc7f75f2007-09-17 12:30:59 -07003333/**
Bruce Allanad680762008-03-28 09:15:03 -07003334 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003335 * @adapter: private board structure
3336 **/
3337static void e1000_configure(struct e1000_adapter *adapter)
3338{
Bruce Allan55aa6982011-12-16 00:45:45 +00003339 struct e1000_ring *rx_ring = adapter->rx_ring;
3340
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003341 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003342
3343 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003344 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003345
3346 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003347
3348 if (adapter->netdev->features & NETIF_F_RXHASH)
3349 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003350 e1000_setup_rctl(adapter);
3351 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003352 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003353}
3354
3355/**
3356 * e1000e_power_up_phy - restore link in case the phy was powered down
3357 * @adapter: address of board private structure
3358 *
3359 * The phy may be powered down to save power and turn off link when the
3360 * driver is unloaded and wake on lan is not enabled (among others)
3361 * *** this routine MUST be followed by a call to e1000e_reset ***
3362 **/
3363void e1000e_power_up_phy(struct e1000_adapter *adapter)
3364{
Bruce Allan17f208d2009-12-01 15:47:22 +00003365 if (adapter->hw.phy.ops.power_up)
3366 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003367
3368 adapter->hw.mac.ops.setup_link(&adapter->hw);
3369}
3370
3371/**
3372 * e1000_power_down_phy - Power down the PHY
3373 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003374 * Power down the PHY so no link is implied when interface is down.
3375 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003376 */
3377static void e1000_power_down_phy(struct e1000_adapter *adapter)
3378{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003379 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003380 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003381 return;
3382
Bruce Allan17f208d2009-12-01 15:47:22 +00003383 if (adapter->hw.phy.ops.power_down)
3384 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003385}
3386
3387/**
3388 * e1000e_reset - bring the hardware into a known good state
3389 *
3390 * This function boots the hardware and enables some settings that
3391 * require a configuration cycle of the hardware - those cannot be
3392 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003393 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003394 */
3395void e1000e_reset(struct e1000_adapter *adapter)
3396{
3397 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003398 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003399 struct e1000_hw *hw = &adapter->hw;
3400 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003401 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003402 u16 hwm;
3403
Bruce Allanad680762008-03-28 09:15:03 -07003404 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003405 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003406
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003407 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003408 /*
3409 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003410 * large enough to accommodate two full transmit packets,
3411 * rounded up to the next 1KB and expressed in KB. Likewise,
3412 * the Rx FIFO should be large enough to accommodate at least
3413 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003414 * expressed in KB.
3415 */
Auke Kokdf762462007-10-25 13:57:53 -07003416 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003417 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003418 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003419 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003420 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003421 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003422 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003423 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003424 */
3425 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426 sizeof(struct e1000_tx_desc) -
3427 ETH_FCS_LEN) * 2;
3428 min_tx_space = ALIGN(min_tx_space, 1024);
3429 min_tx_space >>= 10;
3430 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003431 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003432 min_rx_space = ALIGN(min_rx_space, 1024);
3433 min_rx_space >>= 10;
3434
Bruce Allanad680762008-03-28 09:15:03 -07003435 /*
3436 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003437 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003438 * allocation, take space away from current Rx allocation
3439 */
Auke Kokdf762462007-10-25 13:57:53 -07003440 if ((tx_space < min_tx_space) &&
3441 ((min_tx_space - tx_space) < pba)) {
3442 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003443
Bruce Allanad680762008-03-28 09:15:03 -07003444 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003445 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003446 * adjustment or use Early Receive if available
3447 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003448 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003449 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003450 }
Auke Kokdf762462007-10-25 13:57:53 -07003451
3452 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003453 }
3454
Bruce Allanad680762008-03-28 09:15:03 -07003455 /*
3456 * flow control settings
3457 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003458 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003459 * (or the size used for early receive) above it in the Rx FIFO.
3460 * Set it to the lower of:
3461 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003462 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003463 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003464 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3465 fc->pause_time = 0xFFFF;
3466 else
3467 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003468 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003469 fc->current_mode = fc->requested_mode;
3470
3471 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003472 case e1000_ich9lan:
3473 case e1000_ich10lan:
3474 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3475 pba = 14;
3476 ew32(PBA, pba);
3477 fc->high_water = 0x2800;
3478 fc->low_water = fc->high_water - 8;
3479 break;
3480 }
3481 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003482 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003483 hwm = min(((pba << 10) * 9 / 10),
3484 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003485
3486 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3487 fc->low_water = fc->high_water - 8;
3488 break;
3489 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003490 /*
3491 * Workaround PCH LOM adapter hangs with certain network
3492 * loads. If hangs persist, try disabling Tx flow control.
3493 */
3494 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3495 fc->high_water = 0x3500;
3496 fc->low_water = 0x1500;
3497 } else {
3498 fc->high_water = 0x5000;
3499 fc->low_water = 0x3000;
3500 }
Bruce Allana3055952010-05-10 15:02:12 +00003501 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003502 break;
3503 case e1000_pch2lan:
3504 fc->high_water = 0x05C20;
3505 fc->low_water = 0x05048;
3506 fc->pause_time = 0x0650;
3507 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003508 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3509 pba = 14;
3510 ew32(PBA, pba);
3511 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003512 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003513 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003514
Bruce Allan828bac82010-09-29 21:39:37 +00003515 /*
3516 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003517 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003518 */
3519 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003520 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003521 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3522 dev_info(&adapter->pdev->dev,
3523 "Interrupt Throttle Rate turned off\n");
3524 adapter->flags2 |= FLAG2_DISABLE_AIM;
3525 ew32(ITR, 0);
3526 }
3527 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3528 dev_info(&adapter->pdev->dev,
3529 "Interrupt Throttle Rate turned on\n");
3530 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3531 adapter->itr = 20000;
3532 ew32(ITR, 1000000000 / (adapter->itr * 256));
3533 }
3534 }
3535
Auke Kokbc7f75f2007-09-17 12:30:59 -07003536 /* Allow time for pending master requests to run */
3537 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003538
3539 /*
3540 * For parts with AMT enabled, let the firmware know
3541 * that the network interface is in control
3542 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003543 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003544 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003545
Auke Kokbc7f75f2007-09-17 12:30:59 -07003546 ew32(WUC, 0);
3547
3548 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003549 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003550
3551 e1000_update_mng_vlan(adapter);
3552
3553 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3554 ew32(VET, ETH_P_8021Q);
3555
3556 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003557
3558 if (!netif_running(adapter->netdev) &&
3559 !test_bit(__E1000_TESTING, &adapter->state)) {
3560 e1000_power_down_phy(adapter);
3561 return;
3562 }
3563
Auke Kokbc7f75f2007-09-17 12:30:59 -07003564 e1000_get_phy_info(hw);
3565
Bruce Allan918d7192009-06-02 11:28:20 +00003566 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3567 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003568 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003569 /*
3570 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003571 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003572 * different we would do if it failed
3573 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003574 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3575 phy_data &= ~IGP02E1000_PM_SPD;
3576 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3577 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003578}
3579
3580int e1000e_up(struct e1000_adapter *adapter)
3581{
3582 struct e1000_hw *hw = &adapter->hw;
3583
3584 /* hardware has been reset, we need to reload some things */
3585 e1000_configure(adapter);
3586
3587 clear_bit(__E1000_DOWN, &adapter->state);
3588
Bruce Allan4662e822008-08-26 18:37:06 -07003589 if (adapter->msix_entries)
3590 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003591 e1000_irq_enable(adapter);
3592
Bruce Allan400484f2011-05-13 07:20:03 +00003593 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003594
Auke Kokbc7f75f2007-09-17 12:30:59 -07003595 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003596 if (adapter->msix_entries)
3597 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3598 else
3599 ew32(ICS, E1000_ICS_LSC);
3600
Auke Kokbc7f75f2007-09-17 12:30:59 -07003601 return 0;
3602}
3603
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003604static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3605{
3606 struct e1000_hw *hw = &adapter->hw;
3607
3608 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3609 return;
3610
3611 /* flush pending descriptor writebacks to memory */
3612 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3613 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3614
3615 /* execute the writes immediately */
3616 e1e_flush();
3617}
3618
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003619static void e1000e_update_stats(struct e1000_adapter *adapter);
3620
Auke Kokbc7f75f2007-09-17 12:30:59 -07003621void e1000e_down(struct e1000_adapter *adapter)
3622{
3623 struct net_device *netdev = adapter->netdev;
3624 struct e1000_hw *hw = &adapter->hw;
3625 u32 tctl, rctl;
3626
Bruce Allanad680762008-03-28 09:15:03 -07003627 /*
3628 * signal that we're down so the interrupt handler does not
3629 * reschedule our watchdog timer
3630 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003631 set_bit(__E1000_DOWN, &adapter->state);
3632
3633 /* disable receives in the hardware */
3634 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003635 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3636 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003637 /* flush and sleep below */
3638
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003639 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003640
3641 /* disable transmits in the hardware */
3642 tctl = er32(TCTL);
3643 tctl &= ~E1000_TCTL_EN;
3644 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003645
Auke Kokbc7f75f2007-09-17 12:30:59 -07003646 /* flush both disables and wait for them to finish */
3647 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003648 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003649
Auke Kokbc7f75f2007-09-17 12:30:59 -07003650 e1000_irq_disable(adapter);
3651
3652 del_timer_sync(&adapter->watchdog_timer);
3653 del_timer_sync(&adapter->phy_info_timer);
3654
Auke Kokbc7f75f2007-09-17 12:30:59 -07003655 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003656
3657 spin_lock(&adapter->stats64_lock);
3658 e1000e_update_stats(adapter);
3659 spin_unlock(&adapter->stats64_lock);
3660
Bruce Allan400484f2011-05-13 07:20:03 +00003661 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003662 e1000_clean_tx_ring(adapter->tx_ring);
3663 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00003664
Auke Kokbc7f75f2007-09-17 12:30:59 -07003665 adapter->link_speed = 0;
3666 adapter->link_duplex = 0;
3667
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003668 if (!pci_channel_offline(adapter->pdev))
3669 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003670
Auke Kokbc7f75f2007-09-17 12:30:59 -07003671 /*
3672 * TODO: for power management, we could drop the link and
3673 * pci_disable_device here.
3674 */
3675}
3676
3677void e1000e_reinit_locked(struct e1000_adapter *adapter)
3678{
3679 might_sleep();
3680 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003681 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682 e1000e_down(adapter);
3683 e1000e_up(adapter);
3684 clear_bit(__E1000_RESETTING, &adapter->state);
3685}
3686
3687/**
3688 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3689 * @adapter: board private structure to initialize
3690 *
3691 * e1000_sw_init initializes the Adapter private data structure.
3692 * Fields are initialized based on PCI device information and
3693 * OS network device settings (MTU size).
3694 **/
3695static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3696{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003697 struct net_device *netdev = adapter->netdev;
3698
3699 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3700 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003701 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3702 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00003703 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3704 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003705
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003706 spin_lock_init(&adapter->stats64_lock);
3707
Bruce Allan4662e822008-08-26 18:37:06 -07003708 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003709
Bruce Allan4662e822008-08-26 18:37:06 -07003710 if (e1000_alloc_queues(adapter))
3711 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003712
Auke Kokbc7f75f2007-09-17 12:30:59 -07003713 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003714 e1000_irq_disable(adapter);
3715
Auke Kokbc7f75f2007-09-17 12:30:59 -07003716 set_bit(__E1000_DOWN, &adapter->state);
3717 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003718}
3719
3720/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003721 * e1000_intr_msi_test - Interrupt Handler
3722 * @irq: interrupt number
3723 * @data: pointer to a network interface device structure
3724 **/
3725static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3726{
3727 struct net_device *netdev = data;
3728 struct e1000_adapter *adapter = netdev_priv(netdev);
3729 struct e1000_hw *hw = &adapter->hw;
3730 u32 icr = er32(ICR);
3731
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003732 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003733 if (icr & E1000_ICR_RXSEQ) {
3734 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3735 wmb();
3736 }
3737
3738 return IRQ_HANDLED;
3739}
3740
3741/**
3742 * e1000_test_msi_interrupt - Returns 0 for successful test
3743 * @adapter: board private struct
3744 *
3745 * code flow taken from tg3.c
3746 **/
3747static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3748{
3749 struct net_device *netdev = adapter->netdev;
3750 struct e1000_hw *hw = &adapter->hw;
3751 int err;
3752
3753 /* poll_enable hasn't been called yet, so don't need disable */
3754 /* clear any pending events */
3755 er32(ICR);
3756
3757 /* free the real vector and request a test handler */
3758 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003759 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003760
3761 /* Assume that the test fails, if it succeeds then the test
3762 * MSI irq handler will unset this flag */
3763 adapter->flags |= FLAG_MSI_TEST_FAILED;
3764
3765 err = pci_enable_msi(adapter->pdev);
3766 if (err)
3767 goto msi_test_failed;
3768
Joe Perchesa0607fd2009-11-18 23:29:17 -08003769 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003770 netdev->name, netdev);
3771 if (err) {
3772 pci_disable_msi(adapter->pdev);
3773 goto msi_test_failed;
3774 }
3775
3776 wmb();
3777
3778 e1000_irq_enable(adapter);
3779
3780 /* fire an unusual interrupt on the test handler */
3781 ew32(ICS, E1000_ICS_RXSEQ);
3782 e1e_flush();
3783 msleep(50);
3784
3785 e1000_irq_disable(adapter);
3786
3787 rmb();
3788
3789 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003790 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003791 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003792 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00003793 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003794 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003795
3796 free_irq(adapter->pdev->irq, netdev);
3797 pci_disable_msi(adapter->pdev);
3798
Bruce Allanf8d59f72008-08-08 18:36:11 -07003799msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003800 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003801 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003802}
3803
3804/**
3805 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3806 * @adapter: board private struct
3807 *
3808 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3809 **/
3810static int e1000_test_msi(struct e1000_adapter *adapter)
3811{
3812 int err;
3813 u16 pci_cmd;
3814
3815 if (!(adapter->flags & FLAG_MSI_ENABLED))
3816 return 0;
3817
3818 /* disable SERR in case the MSI write causes a master abort */
3819 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003820 if (pci_cmd & PCI_COMMAND_SERR)
3821 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3822 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003823
3824 err = e1000_test_msi_interrupt(adapter);
3825
Dean Nelson36f24072010-06-29 18:12:05 +00003826 /* re-enable SERR */
3827 if (pci_cmd & PCI_COMMAND_SERR) {
3828 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3829 pci_cmd |= PCI_COMMAND_SERR;
3830 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3831 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003832
Bruce Allanf8d59f72008-08-08 18:36:11 -07003833 return err;
3834}
3835
3836/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003837 * e1000_open - Called when a network interface is made active
3838 * @netdev: network interface device structure
3839 *
3840 * Returns 0 on success, negative value on failure
3841 *
3842 * The open entry point is called when a network interface is made
3843 * active by the system (IFF_UP). At this point all resources needed
3844 * for transmit and receive operations are allocated, the interrupt
3845 * handler is registered with the OS, the watchdog timer is started,
3846 * and the stack is notified that the interface is ready.
3847 **/
3848static int e1000_open(struct net_device *netdev)
3849{
3850 struct e1000_adapter *adapter = netdev_priv(netdev);
3851 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003852 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003853 int err;
3854
3855 /* disallow open during test */
3856 if (test_bit(__E1000_TESTING, &adapter->state))
3857 return -EBUSY;
3858
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003859 pm_runtime_get_sync(&pdev->dev);
3860
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003861 netif_carrier_off(netdev);
3862
Auke Kokbc7f75f2007-09-17 12:30:59 -07003863 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003864 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003865 if (err)
3866 goto err_setup_tx;
3867
3868 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003869 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003870 if (err)
3871 goto err_setup_rx;
3872
Bruce Allan11b08be2010-05-10 14:59:31 +00003873 /*
3874 * If AMT is enabled, let the firmware know that the network
3875 * interface is now open and reset the part to a known state.
3876 */
3877 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003878 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003879 e1000e_reset(adapter);
3880 }
3881
Auke Kokbc7f75f2007-09-17 12:30:59 -07003882 e1000e_power_up_phy(adapter);
3883
3884 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3885 if ((adapter->hw.mng_cookie.status &
3886 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3887 e1000_update_mng_vlan(adapter);
3888
Bruce Allan79d4e902011-12-16 00:46:27 +00003889 /* DMA latency requirement to workaround jumbo issue */
3890 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07003891 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3892 PM_QOS_CPU_DMA_LATENCY,
3893 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003894
Bruce Allanad680762008-03-28 09:15:03 -07003895 /*
Bruce Allanad680762008-03-28 09:15:03 -07003896 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003897 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3898 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003899 * clean_rx handler before we do so.
3900 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003901 e1000_configure(adapter);
3902
3903 err = e1000_request_irq(adapter);
3904 if (err)
3905 goto err_req_irq;
3906
Bruce Allanf8d59f72008-08-08 18:36:11 -07003907 /*
3908 * Work around PCIe errata with MSI interrupts causing some chipsets to
3909 * ignore e1000e MSI messages, which means we need to test our MSI
3910 * interrupt now
3911 */
Bruce Allan4662e822008-08-26 18:37:06 -07003912 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003913 err = e1000_test_msi(adapter);
3914 if (err) {
3915 e_err("Interrupt allocation failed\n");
3916 goto err_req_irq;
3917 }
3918 }
3919
Auke Kokbc7f75f2007-09-17 12:30:59 -07003920 /* From here on the code is the same as e1000e_up() */
3921 clear_bit(__E1000_DOWN, &adapter->state);
3922
3923 napi_enable(&adapter->napi);
3924
3925 e1000_irq_enable(adapter);
3926
Jeff Kirsher09357b02011-11-18 14:25:00 +00003927 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003928 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003929
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003930 adapter->idle_check = true;
3931 pm_runtime_put(&pdev->dev);
3932
Auke Kokbc7f75f2007-09-17 12:30:59 -07003933 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003934 if (adapter->msix_entries)
3935 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3936 else
3937 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003938
3939 return 0;
3940
3941err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003942 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003943 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003944 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003945err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00003946 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003947err_setup_tx:
3948 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003949 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003950
3951 return err;
3952}
3953
3954/**
3955 * e1000_close - Disables a network interface
3956 * @netdev: network interface device structure
3957 *
3958 * Returns 0, this is not allowed to fail
3959 *
3960 * The close entry point is called when an interface is de-activated
3961 * by the OS. The hardware is still under the drivers control, but
3962 * needs to be disabled. A global MAC reset is issued to stop the
3963 * hardware, and all transmit and receive resources are freed.
3964 **/
3965static int e1000_close(struct net_device *netdev)
3966{
3967 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003968 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003969
3970 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003971
3972 pm_runtime_get_sync(&pdev->dev);
3973
Bruce Allan5f4a7802011-11-29 08:09:19 +00003974 napi_disable(&adapter->napi);
3975
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003976 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3977 e1000e_down(adapter);
3978 e1000_free_irq(adapter);
3979 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003980 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003981
Bruce Allan55aa6982011-12-16 00:45:45 +00003982 e1000e_free_tx_resources(adapter->tx_ring);
3983 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003984
Bruce Allanad680762008-03-28 09:15:03 -07003985 /*
3986 * kill manageability vlan ID if supported, but not if a vlan with
3987 * the same ID is registered on the host OS (let 8021q kill it)
3988 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003989 if (adapter->hw.mng_cookie.status &
3990 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003991 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3992
Bruce Allanad680762008-03-28 09:15:03 -07003993 /*
3994 * If AMT is enabled, let the firmware know that the network
3995 * interface is now closed
3996 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003997 if ((adapter->flags & FLAG_HAS_AMT) &&
3998 !test_bit(__E1000_TESTING, &adapter->state))
3999 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004000
Bruce Allan79d4e902011-12-16 00:46:27 +00004001 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07004002 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004003
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004004 pm_runtime_put_sync(&pdev->dev);
4005
Auke Kokbc7f75f2007-09-17 12:30:59 -07004006 return 0;
4007}
4008/**
4009 * e1000_set_mac - Change the Ethernet Address of the NIC
4010 * @netdev: network interface device structure
4011 * @p: pointer to an address structure
4012 *
4013 * Returns 0 on success, negative on failure
4014 **/
4015static int e1000_set_mac(struct net_device *netdev, void *p)
4016{
4017 struct e1000_adapter *adapter = netdev_priv(netdev);
4018 struct sockaddr *addr = p;
4019
4020 if (!is_valid_ether_addr(addr->sa_data))
4021 return -EADDRNOTAVAIL;
4022
4023 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4024 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4025
4026 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
4027
4028 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4029 /* activate the work around */
4030 e1000e_set_laa_state_82571(&adapter->hw, 1);
4031
Bruce Allanad680762008-03-28 09:15:03 -07004032 /*
4033 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004034 * between the time RAR[0] gets clobbered and the time it
4035 * gets fixed (in e1000_watchdog), the actual LAA is in one
4036 * of the RARs and no incoming packets directed to this port
4037 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004038 * RAR[14]
4039 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004040 e1000e_rar_set(&adapter->hw,
4041 adapter->hw.mac.addr,
4042 adapter->hw.mac.rar_entry_count - 1);
4043 }
4044
4045 return 0;
4046}
4047
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004048/**
4049 * e1000e_update_phy_task - work thread to update phy
4050 * @work: pointer to our work struct
4051 *
4052 * this worker thread exists because we must acquire a
4053 * semaphore to read the phy, which we could msleep while
4054 * waiting for it, and we can't msleep in a timer.
4055 **/
4056static void e1000e_update_phy_task(struct work_struct *work)
4057{
4058 struct e1000_adapter *adapter = container_of(work,
4059 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004060
4061 if (test_bit(__E1000_DOWN, &adapter->state))
4062 return;
4063
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004064 e1000_get_phy_info(&adapter->hw);
4065}
4066
Bruce Allanad680762008-03-28 09:15:03 -07004067/*
4068 * Need to wait a few seconds after link up to get diagnostic information from
4069 * the phy
4070 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004071static void e1000_update_phy_info(unsigned long data)
4072{
4073 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004074
4075 if (test_bit(__E1000_DOWN, &adapter->state))
4076 return;
4077
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004078 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004079}
4080
4081/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004082 * e1000e_update_phy_stats - Update the PHY statistics counters
4083 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004084 *
4085 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004086 **/
4087static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4088{
4089 struct e1000_hw *hw = &adapter->hw;
4090 s32 ret_val;
4091 u16 phy_data;
4092
4093 ret_val = hw->phy.ops.acquire(hw);
4094 if (ret_val)
4095 return;
4096
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004097 /*
4098 * A page set is expensive so check if already on desired page.
4099 * If not, set to the page with the PHY status registers.
4100 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004101 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004102 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4103 &phy_data);
4104 if (ret_val)
4105 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004106 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4107 ret_val = hw->phy.ops.set_page(hw,
4108 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004109 if (ret_val)
4110 goto release;
4111 }
4112
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004113 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004114 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4115 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004116 if (!ret_val)
4117 adapter->stats.scc += phy_data;
4118
4119 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004120 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4121 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004122 if (!ret_val)
4123 adapter->stats.ecol += phy_data;
4124
4125 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004126 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4127 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004128 if (!ret_val)
4129 adapter->stats.mcc += phy_data;
4130
4131 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004132 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4133 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004134 if (!ret_val)
4135 adapter->stats.latecol += phy_data;
4136
4137 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004138 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4139 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004140 if (!ret_val)
4141 hw->mac.collision_delta = phy_data;
4142
4143 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004144 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4145 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004146 if (!ret_val)
4147 adapter->stats.dc += phy_data;
4148
4149 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004150 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4151 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004152 if (!ret_val)
4153 adapter->stats.tncrs += phy_data;
4154
4155release:
4156 hw->phy.ops.release(hw);
4157}
4158
4159/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004160 * e1000e_update_stats - Update the board statistics counters
4161 * @adapter: board private structure
4162 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004163static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004164{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004165 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004166 struct e1000_hw *hw = &adapter->hw;
4167 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004168
4169 /*
4170 * Prevent stats update while adapter is being reset, or if the pci
4171 * connection is down.
4172 */
4173 if (adapter->link_speed == 0)
4174 return;
4175 if (pci_channel_offline(pdev))
4176 return;
4177
Auke Kokbc7f75f2007-09-17 12:30:59 -07004178 adapter->stats.crcerrs += er32(CRCERRS);
4179 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004180 adapter->stats.gorc += er32(GORCL);
4181 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004182 adapter->stats.bprc += er32(BPRC);
4183 adapter->stats.mprc += er32(MPRC);
4184 adapter->stats.roc += er32(ROC);
4185
Auke Kokbc7f75f2007-09-17 12:30:59 -07004186 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004187
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004188 /* Half-duplex statistics */
4189 if (adapter->link_duplex == HALF_DUPLEX) {
4190 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4191 e1000e_update_phy_stats(adapter);
4192 } else {
4193 adapter->stats.scc += er32(SCC);
4194 adapter->stats.ecol += er32(ECOL);
4195 adapter->stats.mcc += er32(MCC);
4196 adapter->stats.latecol += er32(LATECOL);
4197 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004198
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004199 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004200
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004201 if ((hw->mac.type != e1000_82574) &&
4202 (hw->mac.type != e1000_82583))
4203 adapter->stats.tncrs += er32(TNCRS);
4204 }
4205 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004206 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004207
Auke Kokbc7f75f2007-09-17 12:30:59 -07004208 adapter->stats.xonrxc += er32(XONRXC);
4209 adapter->stats.xontxc += er32(XONTXC);
4210 adapter->stats.xoffrxc += er32(XOFFRXC);
4211 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004212 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004213 adapter->stats.gotc += er32(GOTCL);
4214 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004215 adapter->stats.rnbc += er32(RNBC);
4216 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004217
4218 adapter->stats.mptc += er32(MPTC);
4219 adapter->stats.bptc += er32(BPTC);
4220
4221 /* used for adaptive IFS */
4222
4223 hw->mac.tx_packet_delta = er32(TPT);
4224 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004225
4226 adapter->stats.algnerrc += er32(ALGNERRC);
4227 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004228 adapter->stats.cexterr += er32(CEXTERR);
4229 adapter->stats.tsctc += er32(TSCTC);
4230 adapter->stats.tsctfc += er32(TSCTFC);
4231
Auke Kokbc7f75f2007-09-17 12:30:59 -07004232 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004233 netdev->stats.multicast = adapter->stats.mprc;
4234 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004235
4236 /* Rx Errors */
4237
Bruce Allanad680762008-03-28 09:15:03 -07004238 /*
4239 * RLEC on some newer hardware can be incorrect so build
4240 * our own version based on RUC and ROC
4241 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004242 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004243 adapter->stats.crcerrs + adapter->stats.algnerrc +
4244 adapter->stats.ruc + adapter->stats.roc +
4245 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004246 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004247 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004248 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4249 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4250 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004251
4252 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004253 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004254 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004255 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4256 netdev->stats.tx_window_errors = adapter->stats.latecol;
4257 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004258
4259 /* Tx Dropped needs to be maintained elsewhere */
4260
Auke Kokbc7f75f2007-09-17 12:30:59 -07004261 /* Management Stats */
4262 adapter->stats.mgptc += er32(MGTPTC);
4263 adapter->stats.mgprc += er32(MGTPRC);
4264 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004265}
4266
Bruce Allan7c257692008-04-23 11:09:00 -07004267/**
4268 * e1000_phy_read_status - Update the PHY register status snapshot
4269 * @adapter: board private structure
4270 **/
4271static void e1000_phy_read_status(struct e1000_adapter *adapter)
4272{
4273 struct e1000_hw *hw = &adapter->hw;
4274 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004275
4276 if ((er32(STATUS) & E1000_STATUS_LU) &&
4277 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004278 int ret_val;
4279
Bruce Allan7c257692008-04-23 11:09:00 -07004280 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4281 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4282 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4283 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4284 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4285 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4286 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4287 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4288 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004289 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004290 } else {
4291 /*
4292 * Do not read PHY registers if link is not up
4293 * Set values to typical power-on defaults
4294 */
4295 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4296 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4297 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4298 BMSR_ERCAP);
4299 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4300 ADVERTISE_ALL | ADVERTISE_CSMA);
4301 phy->lpa = 0;
4302 phy->expansion = EXPANSION_ENABLENPAGE;
4303 phy->ctrl1000 = ADVERTISE_1000FULL;
4304 phy->stat1000 = 0;
4305 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4306 }
Bruce Allan7c257692008-04-23 11:09:00 -07004307}
4308
Auke Kokbc7f75f2007-09-17 12:30:59 -07004309static void e1000_print_link_info(struct e1000_adapter *adapter)
4310{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004311 struct e1000_hw *hw = &adapter->hw;
4312 u32 ctrl = er32(CTRL);
4313
Bruce Allan8f12fe82008-11-21 16:54:43 -08004314 /* Link status message must follow this format for user tools */
Jeff Kirsheref456f82011-11-03 11:40:28 +00004315 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4316 adapter->netdev->name,
4317 adapter->link_speed,
4318 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4319 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4320 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4321 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004322}
4323
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004324static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004325{
4326 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004327 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004328 s32 ret_val = 0;
4329
4330 /*
4331 * get_link_status is set on LSC (link status) interrupt or
4332 * Rx sequence error interrupt. get_link_status will stay
4333 * false until the check_for_link establishes link
4334 * for copper adapters ONLY
4335 */
4336 switch (hw->phy.media_type) {
4337 case e1000_media_type_copper:
4338 if (hw->mac.get_link_status) {
4339 ret_val = hw->mac.ops.check_for_link(hw);
4340 link_active = !hw->mac.get_link_status;
4341 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004342 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004343 }
4344 break;
4345 case e1000_media_type_fiber:
4346 ret_val = hw->mac.ops.check_for_link(hw);
4347 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4348 break;
4349 case e1000_media_type_internal_serdes:
4350 ret_val = hw->mac.ops.check_for_link(hw);
4351 link_active = adapter->hw.mac.serdes_has_link;
4352 break;
4353 default:
4354 case e1000_media_type_unknown:
4355 break;
4356 }
4357
4358 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4359 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4360 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004361 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004362 }
4363
4364 return link_active;
4365}
4366
4367static void e1000e_enable_receives(struct e1000_adapter *adapter)
4368{
4369 /* make sure the receive unit is started */
4370 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4371 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4372 struct e1000_hw *hw = &adapter->hw;
4373 u32 rctl = er32(RCTL);
4374 ew32(RCTL, rctl | E1000_RCTL_EN);
4375 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4376 }
4377}
4378
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004379static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4380{
4381 struct e1000_hw *hw = &adapter->hw;
4382
4383 /*
4384 * With 82574 controllers, PHY needs to be checked periodically
4385 * for hung state and reset, if two calls return true
4386 */
4387 if (e1000_check_phy_82574(hw))
4388 adapter->phy_hang_count++;
4389 else
4390 adapter->phy_hang_count = 0;
4391
4392 if (adapter->phy_hang_count > 1) {
4393 adapter->phy_hang_count = 0;
4394 schedule_work(&adapter->reset_task);
4395 }
4396}
4397
Auke Kokbc7f75f2007-09-17 12:30:59 -07004398/**
4399 * e1000_watchdog - Timer Call-back
4400 * @data: pointer to adapter cast into an unsigned long
4401 **/
4402static void e1000_watchdog(unsigned long data)
4403{
4404 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4405
4406 /* Do the rest outside of interrupt context */
4407 schedule_work(&adapter->watchdog_task);
4408
4409 /* TODO: make this use queue_delayed_work() */
4410}
4411
4412static void e1000_watchdog_task(struct work_struct *work)
4413{
4414 struct e1000_adapter *adapter = container_of(work,
4415 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004416 struct net_device *netdev = adapter->netdev;
4417 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004418 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004419 struct e1000_ring *tx_ring = adapter->tx_ring;
4420 struct e1000_hw *hw = &adapter->hw;
4421 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004422
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004423 if (test_bit(__E1000_DOWN, &adapter->state))
4424 return;
4425
David S. Millerb405e8d2010-02-04 22:31:41 -08004426 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004427 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004428 /* Cancel scheduled suspend requests. */
4429 pm_runtime_resume(netdev->dev.parent);
4430
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004431 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004432 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004433 }
4434
4435 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4436 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4437 e1000_update_mng_vlan(adapter);
4438
Auke Kokbc7f75f2007-09-17 12:30:59 -07004439 if (link) {
4440 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004441 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004442
4443 /* Cancel scheduled suspend requests. */
4444 pm_runtime_resume(netdev->dev.parent);
4445
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004446 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004447 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004448 mac->ops.get_link_up_info(&adapter->hw,
4449 &adapter->link_speed,
4450 &adapter->link_duplex);
4451 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004452 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004453 * On supported PHYs, check for duplex mismatch only
4454 * if link has autonegotiated at 10/100 half
4455 */
4456 if ((hw->phy.type == e1000_phy_igp_3 ||
4457 hw->phy.type == e1000_phy_bm) &&
4458 (hw->mac.autoneg == true) &&
4459 (adapter->link_speed == SPEED_10 ||
4460 adapter->link_speed == SPEED_100) &&
4461 (adapter->link_duplex == HALF_DUPLEX)) {
4462 u16 autoneg_exp;
4463
4464 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4465
4466 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004467 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 -07004468 }
4469
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004470 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004471 adapter->tx_timeout_factor = 1;
4472 switch (adapter->link_speed) {
4473 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004474 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004475 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004476 break;
4477 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004478 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004479 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004480 break;
4481 }
4482
Bruce Allanad680762008-03-28 09:15:03 -07004483 /*
4484 * workaround: re-program speed mode bit after
4485 * link-up event
4486 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004487 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4488 !txb2b) {
4489 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004490 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004491 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004492 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004493 }
4494
Bruce Allanad680762008-03-28 09:15:03 -07004495 /*
4496 * disable TSO for pcie and 10/100 speeds, to avoid
4497 * some hardware issues
4498 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004499 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4500 switch (adapter->link_speed) {
4501 case SPEED_10:
4502 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004503 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004504 netdev->features &= ~NETIF_F_TSO;
4505 netdev->features &= ~NETIF_F_TSO6;
4506 break;
4507 case SPEED_1000:
4508 netdev->features |= NETIF_F_TSO;
4509 netdev->features |= NETIF_F_TSO6;
4510 break;
4511 default:
4512 /* oops */
4513 break;
4514 }
4515 }
4516
Bruce Allanad680762008-03-28 09:15:03 -07004517 /*
4518 * enable transmits in the hardware, need to do this
4519 * after setting TARC(0)
4520 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004521 tctl = er32(TCTL);
4522 tctl |= E1000_TCTL_EN;
4523 ew32(TCTL, tctl);
4524
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004525 /*
4526 * Perform any post-link-up configuration before
4527 * reporting link up.
4528 */
4529 if (phy->ops.cfg_on_link_up)
4530 phy->ops.cfg_on_link_up(hw);
4531
Auke Kokbc7f75f2007-09-17 12:30:59 -07004532 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004533
4534 if (!test_bit(__E1000_DOWN, &adapter->state))
4535 mod_timer(&adapter->phy_info_timer,
4536 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004537 }
4538 } else {
4539 if (netif_carrier_ok(netdev)) {
4540 adapter->link_speed = 0;
4541 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004542 /* Link status message must follow this format */
4543 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4544 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004545 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004546 if (!test_bit(__E1000_DOWN, &adapter->state))
4547 mod_timer(&adapter->phy_info_timer,
4548 round_jiffies(jiffies + 2 * HZ));
4549
4550 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4551 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004552 else
4553 pm_schedule_suspend(netdev->dev.parent,
4554 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004555 }
4556 }
4557
4558link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004559 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004560 e1000e_update_stats(adapter);
4561
4562 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4563 adapter->tpt_old = adapter->stats.tpt;
4564 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4565 adapter->colc_old = adapter->stats.colc;
4566
Bruce Allan7c257692008-04-23 11:09:00 -07004567 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4568 adapter->gorc_old = adapter->stats.gorc;
4569 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4570 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004571 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004572
4573 e1000e_update_adaptive(&adapter->hw);
4574
Bruce Allan90da0662011-01-06 07:02:53 +00004575 if (!netif_carrier_ok(netdev) &&
4576 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4577 /*
4578 * We've lost link, so the controller stops DMA,
4579 * but we've got queued Tx work that's never going
4580 * to get done, so reset controller to flush Tx.
4581 * (Do the reset outside of interrupt context).
4582 */
Bruce Allan90da0662011-01-06 07:02:53 +00004583 schedule_work(&adapter->reset_task);
4584 /* return immediately since reset is imminent */
4585 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004586 }
4587
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004588 /* Simple mode for Interrupt Throttle Rate (ITR) */
4589 if (adapter->itr_setting == 4) {
4590 /*
4591 * Symmetric Tx/Rx gets a reduced ITR=2000;
4592 * Total asymmetrical Tx or Rx gets ITR=8000;
4593 * everyone else is between 2000-8000.
4594 */
4595 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4596 u32 dif = (adapter->gotc > adapter->gorc ?
4597 adapter->gotc - adapter->gorc :
4598 adapter->gorc - adapter->gotc) / 10000;
4599 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4600
4601 ew32(ITR, 1000000000 / (itr * 256));
4602 }
4603
Bruce Allanad680762008-03-28 09:15:03 -07004604 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004605 if (adapter->msix_entries)
4606 ew32(ICS, adapter->rx_ring->ims_val);
4607 else
4608 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004609
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004610 /* flush pending descriptors to memory before detecting Tx hang */
4611 e1000e_flush_descriptors(adapter);
4612
Auke Kokbc7f75f2007-09-17 12:30:59 -07004613 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004614 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004615
Bruce Allanad680762008-03-28 09:15:03 -07004616 /*
4617 * With 82571 controllers, LAA may be overwritten due to controller
4618 * reset from the other port. Set the appropriate LAA in RAR[0]
4619 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004620 if (e1000e_get_laa_state_82571(hw))
4621 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4622
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004623 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4624 e1000e_check_82574_phy_workaround(adapter);
4625
Auke Kokbc7f75f2007-09-17 12:30:59 -07004626 /* Reset the timer */
4627 if (!test_bit(__E1000_DOWN, &adapter->state))
4628 mod_timer(&adapter->watchdog_timer,
4629 round_jiffies(jiffies + 2 * HZ));
4630}
4631
4632#define E1000_TX_FLAGS_CSUM 0x00000001
4633#define E1000_TX_FLAGS_VLAN 0x00000002
4634#define E1000_TX_FLAGS_TSO 0x00000004
4635#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00004636#define E1000_TX_FLAGS_NO_FCS 0x00000010
Auke Kokbc7f75f2007-09-17 12:30:59 -07004637#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4638#define E1000_TX_FLAGS_VLAN_SHIFT 16
4639
Bruce Allan55aa6982011-12-16 00:45:45 +00004640static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004641{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004642 struct e1000_context_desc *context_desc;
4643 struct e1000_buffer *buffer_info;
4644 unsigned int i;
4645 u32 cmd_length = 0;
4646 u16 ipcse = 0, tucse, mss;
4647 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004648
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004649 if (!skb_is_gso(skb))
4650 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004651
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004652 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004653 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4654
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004655 if (err)
4656 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004657 }
4658
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004659 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4660 mss = skb_shinfo(skb)->gso_size;
4661 if (skb->protocol == htons(ETH_P_IP)) {
4662 struct iphdr *iph = ip_hdr(skb);
4663 iph->tot_len = 0;
4664 iph->check = 0;
4665 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4666 0, IPPROTO_TCP, 0);
4667 cmd_length = E1000_TXD_CMD_IP;
4668 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004669 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004670 ipv6_hdr(skb)->payload_len = 0;
4671 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4672 &ipv6_hdr(skb)->daddr,
4673 0, IPPROTO_TCP, 0);
4674 ipcse = 0;
4675 }
4676 ipcss = skb_network_offset(skb);
4677 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4678 tucss = skb_transport_offset(skb);
4679 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4680 tucse = 0;
4681
4682 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4683 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4684
4685 i = tx_ring->next_to_use;
4686 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4687 buffer_info = &tx_ring->buffer_info[i];
4688
4689 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4690 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4691 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4692 context_desc->upper_setup.tcp_fields.tucss = tucss;
4693 context_desc->upper_setup.tcp_fields.tucso = tucso;
4694 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4695 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4696 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4697 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4698
4699 buffer_info->time_stamp = jiffies;
4700 buffer_info->next_to_watch = i;
4701
4702 i++;
4703 if (i == tx_ring->count)
4704 i = 0;
4705 tx_ring->next_to_use = i;
4706
4707 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004708}
4709
Bruce Allan55aa6982011-12-16 00:45:45 +00004710static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004711{
Bruce Allan55aa6982011-12-16 00:45:45 +00004712 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004713 struct e1000_context_desc *context_desc;
4714 struct e1000_buffer *buffer_info;
4715 unsigned int i;
4716 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004717 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004718 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004719
Dave Grahamaf807c82008-10-09 14:28:58 -07004720 if (skb->ip_summed != CHECKSUM_PARTIAL)
4721 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004722
Arthur Jones5f66f202009-03-19 01:13:08 +00004723 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4724 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4725 else
4726 protocol = skb->protocol;
4727
Arthur Jones3f518392009-03-20 15:56:35 -07004728 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004729 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004730 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4731 cmd_len |= E1000_TXD_CMD_TCP;
4732 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004733 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004734 /* XXX not handling all IPV6 headers */
4735 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4736 cmd_len |= E1000_TXD_CMD_TCP;
4737 break;
4738 default:
4739 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004740 e_warn("checksum_partial proto=%x!\n",
4741 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004742 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004743 }
4744
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004745 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004746
4747 i = tx_ring->next_to_use;
4748 buffer_info = &tx_ring->buffer_info[i];
4749 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4750
4751 context_desc->lower_setup.ip_config = 0;
4752 context_desc->upper_setup.tcp_fields.tucss = css;
4753 context_desc->upper_setup.tcp_fields.tucso =
4754 css + skb->csum_offset;
4755 context_desc->upper_setup.tcp_fields.tucse = 0;
4756 context_desc->tcp_seg_setup.data = 0;
4757 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4758
4759 buffer_info->time_stamp = jiffies;
4760 buffer_info->next_to_watch = i;
4761
4762 i++;
4763 if (i == tx_ring->count)
4764 i = 0;
4765 tx_ring->next_to_use = i;
4766
4767 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004768}
4769
4770#define E1000_MAX_PER_TXD 8192
4771#define E1000_MAX_TXD_PWR 12
4772
Bruce Allan55aa6982011-12-16 00:45:45 +00004773static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
4774 unsigned int first, unsigned int max_per_txd,
4775 unsigned int nr_frags, unsigned int mss)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004776{
Bruce Allan55aa6982011-12-16 00:45:45 +00004777 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00004778 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004779 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004780 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004781 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004782 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004783
4784 i = tx_ring->next_to_use;
4785
4786 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004787 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004788 size = min(len, max_per_txd);
4789
Auke Kokbc7f75f2007-09-17 12:30:59 -07004790 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004791 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004792 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004793 buffer_info->dma = dma_map_single(&pdev->dev,
4794 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004795 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004796 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004797 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004798 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004799
4800 len -= size;
4801 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004802 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004803
4804 if (len) {
4805 i++;
4806 if (i == tx_ring->count)
4807 i = 0;
4808 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004809 }
4810
4811 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004812 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004813
4814 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004815 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004816 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004817
4818 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004819 i++;
4820 if (i == tx_ring->count)
4821 i = 0;
4822
Auke Kokbc7f75f2007-09-17 12:30:59 -07004823 buffer_info = &tx_ring->buffer_info[i];
4824 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004825
4826 buffer_info->length = size;
4827 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004828 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004829 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4830 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004831 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004832 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004833 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004834
4835 len -= size;
4836 offset += size;
4837 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004838 }
4839 }
4840
Bruce Allanaf667a22010-12-31 06:10:01 +00004841 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004842 /* multiply data chunks by size of headers */
4843 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4844
Auke Kokbc7f75f2007-09-17 12:30:59 -07004845 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004846 tx_ring->buffer_info[i].segs = segs;
4847 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004848 tx_ring->buffer_info[first].next_to_watch = i;
4849
4850 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004851
4852dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004853 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004854 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004855 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004856 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004857
4858 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004859 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004860 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004861 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004862 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00004863 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004864 }
4865
4866 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004867}
4868
Bruce Allan55aa6982011-12-16 00:45:45 +00004869static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004870{
Bruce Allan55aa6982011-12-16 00:45:45 +00004871 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004872 struct e1000_tx_desc *tx_desc = NULL;
4873 struct e1000_buffer *buffer_info;
4874 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4875 unsigned int i;
4876
4877 if (tx_flags & E1000_TX_FLAGS_TSO) {
4878 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4879 E1000_TXD_CMD_TSE;
4880 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4881
4882 if (tx_flags & E1000_TX_FLAGS_IPV4)
4883 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4884 }
4885
4886 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4887 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4888 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4889 }
4890
4891 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4892 txd_lower |= E1000_TXD_CMD_VLE;
4893 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4894 }
4895
Ben Greear943146d2012-02-11 15:39:40 +00004896 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4897 txd_lower &= ~(E1000_TXD_CMD_IFCS);
4898
Auke Kokbc7f75f2007-09-17 12:30:59 -07004899 i = tx_ring->next_to_use;
4900
Bruce Allan36b973d2010-11-24 07:42:43 +00004901 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004902 buffer_info = &tx_ring->buffer_info[i];
4903 tx_desc = E1000_TX_DESC(*tx_ring, i);
4904 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4905 tx_desc->lower.data =
4906 cpu_to_le32(txd_lower | buffer_info->length);
4907 tx_desc->upper.data = cpu_to_le32(txd_upper);
4908
4909 i++;
4910 if (i == tx_ring->count)
4911 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004912 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004913
4914 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4915
Ben Greear943146d2012-02-11 15:39:40 +00004916 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
4917 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4918 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
4919
Bruce Allanad680762008-03-28 09:15:03 -07004920 /*
4921 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004922 * know there are new descriptors to fetch. (Only
4923 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004924 * such as IA-64).
4925 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004926 wmb();
4927
4928 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004929
4930 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00004931 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07004932 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00004933 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07004934
Bruce Allanad680762008-03-28 09:15:03 -07004935 /*
4936 * we need this if more than one processor can write to our tail
4937 * at a time, it synchronizes IO on IA64/Altix systems
4938 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004939 mmiowb();
4940}
4941
4942#define MINIMUM_DHCP_PACKET_SIZE 282
4943static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4944 struct sk_buff *skb)
4945{
4946 struct e1000_hw *hw = &adapter->hw;
4947 u16 length, offset;
4948
4949 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004950 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4951 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004952 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4953 return 0;
4954 }
4955
4956 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4957 return 0;
4958
4959 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4960 return 0;
4961
4962 {
4963 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4964 struct udphdr *udp;
4965
4966 if (ip->protocol != IPPROTO_UDP)
4967 return 0;
4968
4969 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4970 if (ntohs(udp->dest) != 67)
4971 return 0;
4972
4973 offset = (u8 *)udp + 8 - skb->data;
4974 length = skb->len - offset;
4975 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4976 }
4977
4978 return 0;
4979}
4980
Bruce Allan55aa6982011-12-16 00:45:45 +00004981static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004982{
Bruce Allan55aa6982011-12-16 00:45:45 +00004983 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004984
Bruce Allan55aa6982011-12-16 00:45:45 +00004985 netif_stop_queue(adapter->netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004986 /*
4987 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004988 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004989 * but since that doesn't exist yet, just open code it.
4990 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004991 smp_mb();
4992
Bruce Allanad680762008-03-28 09:15:03 -07004993 /*
4994 * We need to check again in a case another CPU has just
4995 * made room available.
4996 */
Bruce Allan55aa6982011-12-16 00:45:45 +00004997 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998 return -EBUSY;
4999
5000 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005001 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005002 ++adapter->restart_queue;
5003 return 0;
5004}
5005
Bruce Allan55aa6982011-12-16 00:45:45 +00005006static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005007{
Bruce Allan55aa6982011-12-16 00:45:45 +00005008 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005009 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005010 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005011}
5012
Bruce Allan0e15df42012-01-31 06:37:11 +00005013#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1)
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005014static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5015 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005016{
5017 struct e1000_adapter *adapter = netdev_priv(netdev);
5018 struct e1000_ring *tx_ring = adapter->tx_ring;
5019 unsigned int first;
5020 unsigned int max_per_txd = E1000_MAX_PER_TXD;
5021 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
5022 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005023 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005024 unsigned int nr_frags;
5025 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005026 int count = 0;
5027 int tso;
5028 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005029
5030 if (test_bit(__E1000_DOWN, &adapter->state)) {
5031 dev_kfree_skb_any(skb);
5032 return NETDEV_TX_OK;
5033 }
5034
5035 if (skb->len <= 0) {
5036 dev_kfree_skb_any(skb);
5037 return NETDEV_TX_OK;
5038 }
5039
5040 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07005041 /*
5042 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07005043 * make sure there is enough room in the FIFO before
5044 * initiating the DMA for each buffer. The calc is:
5045 * 4 = ceil(buffer len/mss). To make sure we don't
5046 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07005047 * drops.
5048 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005049 if (mss) {
5050 u8 hdr_len;
5051 max_per_txd = min(mss << 2, max_per_txd);
5052 max_txd_pwr = fls(max_per_txd) - 1;
5053
Bruce Allanad680762008-03-28 09:15:03 -07005054 /*
5055 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
5056 * points to just header, pull a few bytes of payload from
5057 * frags into skb->data
5058 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005059 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07005060 /*
5061 * we do this workaround for ES2LAN, but it is un-necessary,
5062 * avoiding it could save a lot of cycles
5063 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005064 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005065 unsigned int pull_size;
5066
Bruce Allana2a5b322012-01-31 06:37:17 +00005067 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005068 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005069 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005070 dev_kfree_skb_any(skb);
5071 return NETDEV_TX_OK;
5072 }
Eric Dumazete743d312010-04-14 15:59:40 -07005073 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005074 }
5075 }
5076
5077 /* reserve a descriptor for the offload context */
5078 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5079 count++;
5080 count++;
5081
5082 count += TXD_USE_COUNT(len, max_txd_pwr);
5083
5084 nr_frags = skb_shinfo(skb)->nr_frags;
5085 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00005086 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07005087 max_txd_pwr);
5088
5089 if (adapter->hw.mac.tx_pkt_filtering)
5090 e1000_transfer_dhcp_info(adapter, skb);
5091
Bruce Allanad680762008-03-28 09:15:03 -07005092 /*
5093 * need: count + 2 desc gap to keep tail from touching
5094 * head, otherwise try next time
5095 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005096 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005097 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005098
Jesse Grosseab6d182010-10-20 13:56:03 +00005099 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005100 tx_flags |= E1000_TX_FLAGS_VLAN;
5101 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5102 }
5103
5104 first = tx_ring->next_to_use;
5105
Bruce Allan55aa6982011-12-16 00:45:45 +00005106 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107 if (tso < 0) {
5108 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005109 return NETDEV_TX_OK;
5110 }
5111
5112 if (tso)
5113 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005114 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005115 tx_flags |= E1000_TX_FLAGS_CSUM;
5116
Bruce Allanad680762008-03-28 09:15:03 -07005117 /*
5118 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005119 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005120 * no longer assume, we must.
5121 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005122 if (skb->protocol == htons(ETH_P_IP))
5123 tx_flags |= E1000_TX_FLAGS_IPV4;
5124
Ben Greear943146d2012-02-11 15:39:40 +00005125 if (unlikely(skb->no_fcs))
5126 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5127
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005128 /* if count is 0 then mapping error has occurred */
Bruce Allan55aa6982011-12-16 00:45:45 +00005129 count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005130 if (count) {
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005131 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005132 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005133 /* Make sure there is space in the ring for the next send. */
Bruce Allan55aa6982011-12-16 00:45:45 +00005134 e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005135
5136 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005137 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005138 tx_ring->buffer_info[first].time_stamp = 0;
5139 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005140 }
5141
Auke Kokbc7f75f2007-09-17 12:30:59 -07005142 return NETDEV_TX_OK;
5143}
5144
5145/**
5146 * e1000_tx_timeout - Respond to a Tx Hang
5147 * @netdev: network interface device structure
5148 **/
5149static void e1000_tx_timeout(struct net_device *netdev)
5150{
5151 struct e1000_adapter *adapter = netdev_priv(netdev);
5152
5153 /* Do the reset outside of interrupt context */
5154 adapter->tx_timeout_count++;
5155 schedule_work(&adapter->reset_task);
5156}
5157
5158static void e1000_reset_task(struct work_struct *work)
5159{
5160 struct e1000_adapter *adapter;
5161 adapter = container_of(work, struct e1000_adapter, reset_task);
5162
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005163 /* don't run the task if already down */
5164 if (test_bit(__E1000_DOWN, &adapter->state))
5165 return;
5166
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005167 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5168 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5169 e1000e_dump(adapter);
5170 e_err("Reset adapter\n");
5171 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005172 e1000e_reinit_locked(adapter);
5173}
5174
5175/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005176 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005177 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005178 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005179 *
5180 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005181 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005182struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5183 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005184{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005185 struct e1000_adapter *adapter = netdev_priv(netdev);
5186
5187 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5188 spin_lock(&adapter->stats64_lock);
5189 e1000e_update_stats(adapter);
5190 /* Fill out the OS statistics structure */
5191 stats->rx_bytes = adapter->stats.gorc;
5192 stats->rx_packets = adapter->stats.gprc;
5193 stats->tx_bytes = adapter->stats.gotc;
5194 stats->tx_packets = adapter->stats.gptc;
5195 stats->multicast = adapter->stats.mprc;
5196 stats->collisions = adapter->stats.colc;
5197
5198 /* Rx Errors */
5199
5200 /*
5201 * RLEC on some newer hardware can be incorrect so build
5202 * our own version based on RUC and ROC
5203 */
5204 stats->rx_errors = adapter->stats.rxerrc +
5205 adapter->stats.crcerrs + adapter->stats.algnerrc +
5206 adapter->stats.ruc + adapter->stats.roc +
5207 adapter->stats.cexterr;
5208 stats->rx_length_errors = adapter->stats.ruc +
5209 adapter->stats.roc;
5210 stats->rx_crc_errors = adapter->stats.crcerrs;
5211 stats->rx_frame_errors = adapter->stats.algnerrc;
5212 stats->rx_missed_errors = adapter->stats.mpc;
5213
5214 /* Tx Errors */
5215 stats->tx_errors = adapter->stats.ecol +
5216 adapter->stats.latecol;
5217 stats->tx_aborted_errors = adapter->stats.ecol;
5218 stats->tx_window_errors = adapter->stats.latecol;
5219 stats->tx_carrier_errors = adapter->stats.tncrs;
5220
5221 /* Tx Dropped needs to be maintained elsewhere */
5222
5223 spin_unlock(&adapter->stats64_lock);
5224 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005225}
5226
5227/**
5228 * e1000_change_mtu - Change the Maximum Transfer Unit
5229 * @netdev: network interface device structure
5230 * @new_mtu: new value for maximum frame size
5231 *
5232 * Returns 0 on success, negative on failure
5233 **/
5234static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5235{
5236 struct e1000_adapter *adapter = netdev_priv(netdev);
5237 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5238
Bruce Allan2adc55c2009-06-02 11:28:58 +00005239 /* Jumbo frame support */
Bruce Allan70495a52012-01-11 01:26:50 +00005240 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
5241 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5242 e_err("Jumbo Frames not supported.\n");
5243 return -EINVAL;
5244 }
5245
5246 /*
5247 * IP payload checksum (enabled with jumbos/packet-split when
5248 * Rx checksum is enabled) and generation of RSS hash is
5249 * mutually exclusive in the hardware.
5250 */
5251 if ((netdev->features & NETIF_F_RXCSUM) &&
5252 (netdev->features & NETIF_F_RXHASH)) {
5253 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");
5254 return -EINVAL;
5255 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005256 }
5257
Bruce Allan2adc55c2009-06-02 11:28:58 +00005258 /* Supported frame sizes */
5259 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5260 (max_frame > adapter->max_hw_frame_size)) {
5261 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005262 return -EINVAL;
5263 }
5264
Bruce Allana1ce6472010-09-22 17:16:40 +00005265 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5266 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5267 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5268 (new_mtu > ETH_DATA_LEN)) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00005269 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005270 return -EINVAL;
5271 }
5272
Bruce Allan6f461f62010-04-27 03:33:04 +00005273 /* 82573 Errata 17 */
5274 if (((adapter->hw.mac.type == e1000_82573) ||
5275 (adapter->hw.mac.type == e1000_82574)) &&
5276 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5277 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5278 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5279 }
5280
Auke Kokbc7f75f2007-09-17 12:30:59 -07005281 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005282 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005283 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005284 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005285 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5286 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005287 if (netif_running(netdev))
5288 e1000e_down(adapter);
5289
Bruce Allanad680762008-03-28 09:15:03 -07005290 /*
5291 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005292 * means we reserve 2 more, this pushes us to allocate from the next
5293 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005294 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005295 * However with the new *_jumbo_rx* routines, jumbo receives will use
5296 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005297 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005298
Jesse Brandeburg99261462010-01-22 22:56:16 +00005299 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005300 adapter->rx_buffer_len = 2048;
5301 else
5302 adapter->rx_buffer_len = 4096;
5303
5304 /* adjust allocation if LPE protects us, and we aren't using SBP */
5305 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5306 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5307 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005308 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005309
Auke Kokbc7f75f2007-09-17 12:30:59 -07005310 if (netif_running(netdev))
5311 e1000e_up(adapter);
5312 else
5313 e1000e_reset(adapter);
5314
5315 clear_bit(__E1000_RESETTING, &adapter->state);
5316
5317 return 0;
5318}
5319
5320static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5321 int cmd)
5322{
5323 struct e1000_adapter *adapter = netdev_priv(netdev);
5324 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005325
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005326 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005327 return -EOPNOTSUPP;
5328
5329 switch (cmd) {
5330 case SIOCGMIIPHY:
5331 data->phy_id = adapter->hw.phy.addr;
5332 break;
5333 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005334 e1000_phy_read_status(adapter);
5335
Bruce Allan7c257692008-04-23 11:09:00 -07005336 switch (data->reg_num & 0x1F) {
5337 case MII_BMCR:
5338 data->val_out = adapter->phy_regs.bmcr;
5339 break;
5340 case MII_BMSR:
5341 data->val_out = adapter->phy_regs.bmsr;
5342 break;
5343 case MII_PHYSID1:
5344 data->val_out = (adapter->hw.phy.id >> 16);
5345 break;
5346 case MII_PHYSID2:
5347 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5348 break;
5349 case MII_ADVERTISE:
5350 data->val_out = adapter->phy_regs.advertise;
5351 break;
5352 case MII_LPA:
5353 data->val_out = adapter->phy_regs.lpa;
5354 break;
5355 case MII_EXPANSION:
5356 data->val_out = adapter->phy_regs.expansion;
5357 break;
5358 case MII_CTRL1000:
5359 data->val_out = adapter->phy_regs.ctrl1000;
5360 break;
5361 case MII_STAT1000:
5362 data->val_out = adapter->phy_regs.stat1000;
5363 break;
5364 case MII_ESTATUS:
5365 data->val_out = adapter->phy_regs.estatus;
5366 break;
5367 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005368 return -EIO;
5369 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005370 break;
5371 case SIOCSMIIREG:
5372 default:
5373 return -EOPNOTSUPP;
5374 }
5375 return 0;
5376}
5377
5378static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5379{
5380 switch (cmd) {
5381 case SIOCGMIIPHY:
5382 case SIOCGMIIREG:
5383 case SIOCSMIIREG:
5384 return e1000_mii_ioctl(netdev, ifr, cmd);
5385 default:
5386 return -EOPNOTSUPP;
5387 }
5388}
5389
Bruce Allana4f58f52009-06-02 11:29:18 +00005390static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5391{
5392 struct e1000_hw *hw = &adapter->hw;
5393 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005394 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005395 int retval = 0;
5396
5397 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005398 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005399
Bruce Allan2b6b1682011-05-13 07:20:09 +00005400 retval = hw->phy.ops.acquire(hw);
5401 if (retval) {
5402 e_err("Could not acquire PHY\n");
5403 return retval;
5404 }
5405
5406 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5407 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5408 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005409 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005410
5411 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005412 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5413 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005414 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5415 (u16)(mac_reg & 0xFFFF));
5416 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5417 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005418 }
5419
5420 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005421 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005422 mac_reg = er32(RCTL);
5423 if (mac_reg & E1000_RCTL_UPE)
5424 phy_reg |= BM_RCTL_UPE;
5425 if (mac_reg & E1000_RCTL_MPE)
5426 phy_reg |= BM_RCTL_MPE;
5427 phy_reg &= ~(BM_RCTL_MO_MASK);
5428 if (mac_reg & E1000_RCTL_MO_3)
5429 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5430 << BM_RCTL_MO_SHIFT);
5431 if (mac_reg & E1000_RCTL_BAM)
5432 phy_reg |= BM_RCTL_BAM;
5433 if (mac_reg & E1000_RCTL_PMCF)
5434 phy_reg |= BM_RCTL_PMCF;
5435 mac_reg = er32(CTRL);
5436 if (mac_reg & E1000_CTRL_RFCE)
5437 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005438 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005439
5440 /* enable PHY wakeup in MAC register */
5441 ew32(WUFC, wufc);
5442 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5443
5444 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005445 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5446 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005447
5448 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005449 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5450 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005451 if (retval)
5452 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005453release:
Bruce Allan94d81862009-11-20 23:25:26 +00005454 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005455
5456 return retval;
5457}
5458
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005459static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5460 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005461{
5462 struct net_device *netdev = pci_get_drvdata(pdev);
5463 struct e1000_adapter *adapter = netdev_priv(netdev);
5464 struct e1000_hw *hw = &adapter->hw;
5465 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005466 /* Runtime suspend should only enable wakeup for link changes */
5467 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005468 int retval = 0;
5469
5470 netif_device_detach(netdev);
5471
5472 if (netif_running(netdev)) {
5473 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5474 e1000e_down(adapter);
5475 e1000_free_irq(adapter);
5476 }
Bruce Allan4662e822008-08-26 18:37:06 -07005477 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005478
5479 retval = pci_save_state(pdev);
5480 if (retval)
5481 return retval;
5482
5483 status = er32(STATUS);
5484 if (status & E1000_STATUS_LU)
5485 wufc &= ~E1000_WUFC_LNKC;
5486
5487 if (wufc) {
5488 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005489 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005490
5491 /* turn on all-multi mode if wake on multicast is enabled */
5492 if (wufc & E1000_WUFC_MC) {
5493 rctl = er32(RCTL);
5494 rctl |= E1000_RCTL_MPE;
5495 ew32(RCTL, rctl);
5496 }
5497
5498 ctrl = er32(CTRL);
5499 /* advertise wake from D3Cold */
5500 #define E1000_CTRL_ADVD3WUC 0x00100000
5501 /* phy power management enable */
5502 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005503 ctrl |= E1000_CTRL_ADVD3WUC;
5504 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5505 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005506 ew32(CTRL, ctrl);
5507
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005508 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5509 adapter->hw.phy.media_type ==
5510 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005511 /* keep the laser running in D3 */
5512 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005513 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005514 ew32(CTRL_EXT, ctrl_ext);
5515 }
5516
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005517 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005518 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005519
Auke Kokbc7f75f2007-09-17 12:30:59 -07005520 /* Allow time for pending master requests to run */
5521 e1000e_disable_pcie_master(&adapter->hw);
5522
Bruce Allan82776a42009-08-14 14:35:33 +00005523 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005524 /* enable wakeup by the PHY */
5525 retval = e1000_init_phy_wakeup(adapter, wufc);
5526 if (retval)
5527 return retval;
5528 } else {
5529 /* enable wakeup by the MAC */
5530 ew32(WUFC, wufc);
5531 ew32(WUC, E1000_WUC_PME_EN);
5532 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005533 } else {
5534 ew32(WUC, 0);
5535 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005536 }
5537
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005538 *enable_wake = !!wufc;
5539
Auke Kokbc7f75f2007-09-17 12:30:59 -07005540 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005541 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5542 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005543 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005544
5545 if (adapter->hw.phy.type == e1000_phy_igp_3)
5546 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5547
Bruce Allanad680762008-03-28 09:15:03 -07005548 /*
5549 * Release control of h/w to f/w. If f/w is AMT enabled, this
5550 * would have already happened in close and is redundant.
5551 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005552 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005553
5554 pci_disable_device(pdev);
5555
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005556 return 0;
5557}
5558
5559static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5560{
5561 if (sleep && wake) {
5562 pci_prepare_to_sleep(pdev);
5563 return;
5564 }
5565
5566 pci_wake_from_d3(pdev, wake);
5567 pci_set_power_state(pdev, PCI_D3hot);
5568}
5569
5570static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5571 bool wake)
5572{
5573 struct net_device *netdev = pci_get_drvdata(pdev);
5574 struct e1000_adapter *adapter = netdev_priv(netdev);
5575
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005576 /*
5577 * The pci-e switch on some quad port adapters will report a
5578 * correctable error when the MAC transitions from D0 to D3. To
5579 * prevent this we need to mask off the correctable errors on the
5580 * downstream port of the pci-e switch.
5581 */
5582 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5583 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005584 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005585 u16 devctl;
5586
5587 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5588 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5589 (devctl & ~PCI_EXP_DEVCTL_CERE));
5590
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005591 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005592
5593 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5594 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005595 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005596 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005597}
5598
Bruce Allan6f461f62010-04-27 03:33:04 +00005599#ifdef CONFIG_PCIEASPM
5600static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5601{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005602 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005603}
5604#else
5605static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005606{
5607 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005608 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005609
5610 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005611 * Both device and parent should have the same ASPM setting.
5612 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005613 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005614 pos = pci_pcie_cap(pdev);
5615 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5616 reg16 &= ~state;
5617 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5618
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005619 if (!pdev->bus->self)
5620 return;
5621
Bruce Allan6f461f62010-04-27 03:33:04 +00005622 pos = pci_pcie_cap(pdev->bus->self);
5623 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5624 reg16 &= ~state;
5625 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5626}
5627#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005628static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005629{
5630 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5631 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5632 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5633
5634 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005635}
5636
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005637#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005638static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005639{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005640 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005641}
5642
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005643static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005644{
5645 struct net_device *netdev = pci_get_drvdata(pdev);
5646 struct e1000_adapter *adapter = netdev_priv(netdev);
5647 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005648 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005649 u32 err;
5650
Bruce Allan78cd29d2011-03-24 03:09:03 +00005651 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5652 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5653 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5654 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5655 if (aspm_disable_flag)
5656 e1000e_disable_aspm(pdev, aspm_disable_flag);
5657
Auke Kokbc7f75f2007-09-17 12:30:59 -07005658 pci_set_power_state(pdev, PCI_D0);
5659 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005660 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005661
Bruce Allan4662e822008-08-26 18:37:06 -07005662 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005663 if (netif_running(netdev)) {
5664 err = e1000_request_irq(adapter);
5665 if (err)
5666 return err;
5667 }
5668
Bruce Allan99730e42011-05-13 07:19:48 +00005669 if (hw->mac.type == e1000_pch2lan)
5670 e1000_resume_workarounds_pchlan(&adapter->hw);
5671
Auke Kokbc7f75f2007-09-17 12:30:59 -07005672 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005673
5674 /* report the system wakeup cause from S3/S4 */
5675 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5676 u16 phy_data;
5677
5678 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5679 if (phy_data) {
5680 e_info("PHY Wakeup cause - %s\n",
5681 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5682 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5683 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5684 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005685 phy_data & E1000_WUS_LNKC ?
5686 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005687 }
5688 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5689 } else {
5690 u32 wus = er32(WUS);
5691 if (wus) {
5692 e_info("MAC Wakeup cause - %s\n",
5693 wus & E1000_WUS_EX ? "Unicast Packet" :
5694 wus & E1000_WUS_MC ? "Multicast Packet" :
5695 wus & E1000_WUS_BC ? "Broadcast Packet" :
5696 wus & E1000_WUS_MAG ? "Magic Packet" :
5697 wus & E1000_WUS_LNKC ? "Link Status Change" :
5698 "other");
5699 }
5700 ew32(WUS, ~0);
5701 }
5702
Auke Kokbc7f75f2007-09-17 12:30:59 -07005703 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005704
Bruce Allancd791612010-05-10 14:59:51 +00005705 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005706
5707 if (netif_running(netdev))
5708 e1000e_up(adapter);
5709
5710 netif_device_attach(netdev);
5711
Bruce Allanad680762008-03-28 09:15:03 -07005712 /*
5713 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005714 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005715 * under the control of the driver.
5716 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005717 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005718 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005719
5720 return 0;
5721}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005722
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005723#ifdef CONFIG_PM_SLEEP
5724static int e1000_suspend(struct device *dev)
5725{
5726 struct pci_dev *pdev = to_pci_dev(dev);
5727 int retval;
5728 bool wake;
5729
5730 retval = __e1000_shutdown(pdev, &wake, false);
5731 if (!retval)
5732 e1000_complete_shutdown(pdev, true, wake);
5733
5734 return retval;
5735}
5736
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005737static int e1000_resume(struct device *dev)
5738{
5739 struct pci_dev *pdev = to_pci_dev(dev);
5740 struct net_device *netdev = pci_get_drvdata(pdev);
5741 struct e1000_adapter *adapter = netdev_priv(netdev);
5742
5743 if (e1000e_pm_ready(adapter))
5744 adapter->idle_check = true;
5745
5746 return __e1000_resume(pdev);
5747}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005748#endif /* CONFIG_PM_SLEEP */
5749
5750#ifdef CONFIG_PM_RUNTIME
5751static int e1000_runtime_suspend(struct device *dev)
5752{
5753 struct pci_dev *pdev = to_pci_dev(dev);
5754 struct net_device *netdev = pci_get_drvdata(pdev);
5755 struct e1000_adapter *adapter = netdev_priv(netdev);
5756
5757 if (e1000e_pm_ready(adapter)) {
5758 bool wake;
5759
5760 __e1000_shutdown(pdev, &wake, true);
5761 }
5762
5763 return 0;
5764}
5765
5766static int e1000_idle(struct device *dev)
5767{
5768 struct pci_dev *pdev = to_pci_dev(dev);
5769 struct net_device *netdev = pci_get_drvdata(pdev);
5770 struct e1000_adapter *adapter = netdev_priv(netdev);
5771
5772 if (!e1000e_pm_ready(adapter))
5773 return 0;
5774
5775 if (adapter->idle_check) {
5776 adapter->idle_check = false;
5777 if (!e1000e_has_link(adapter))
5778 pm_schedule_suspend(dev, MSEC_PER_SEC);
5779 }
5780
5781 return -EBUSY;
5782}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005783
5784static int e1000_runtime_resume(struct device *dev)
5785{
5786 struct pci_dev *pdev = to_pci_dev(dev);
5787 struct net_device *netdev = pci_get_drvdata(pdev);
5788 struct e1000_adapter *adapter = netdev_priv(netdev);
5789
5790 if (!e1000e_pm_ready(adapter))
5791 return 0;
5792
5793 adapter->idle_check = !dev->power.runtime_auto;
5794 return __e1000_resume(pdev);
5795}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005796#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005797#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005798
5799static void e1000_shutdown(struct pci_dev *pdev)
5800{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005801 bool wake = false;
5802
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005803 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005804
5805 if (system_state == SYSTEM_POWER_OFF)
5806 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005807}
5808
5809#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005810
5811static irqreturn_t e1000_intr_msix(int irq, void *data)
5812{
5813 struct net_device *netdev = data;
5814 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005815
5816 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005817 int vector, msix_irq;
5818
Dongdong Deng147b2c82010-11-16 19:50:15 -08005819 vector = 0;
5820 msix_irq = adapter->msix_entries[vector].vector;
5821 disable_irq(msix_irq);
5822 e1000_intr_msix_rx(msix_irq, netdev);
5823 enable_irq(msix_irq);
5824
5825 vector++;
5826 msix_irq = adapter->msix_entries[vector].vector;
5827 disable_irq(msix_irq);
5828 e1000_intr_msix_tx(msix_irq, netdev);
5829 enable_irq(msix_irq);
5830
5831 vector++;
5832 msix_irq = adapter->msix_entries[vector].vector;
5833 disable_irq(msix_irq);
5834 e1000_msix_other(msix_irq, netdev);
5835 enable_irq(msix_irq);
5836 }
5837
5838 return IRQ_HANDLED;
5839}
5840
Auke Kokbc7f75f2007-09-17 12:30:59 -07005841/*
5842 * Polling 'interrupt' - used by things like netconsole to send skbs
5843 * without having to re-enable interrupts. It's not called while
5844 * the interrupt routine is executing.
5845 */
5846static void e1000_netpoll(struct net_device *netdev)
5847{
5848 struct e1000_adapter *adapter = netdev_priv(netdev);
5849
Dongdong Deng147b2c82010-11-16 19:50:15 -08005850 switch (adapter->int_mode) {
5851 case E1000E_INT_MODE_MSIX:
5852 e1000_intr_msix(adapter->pdev->irq, netdev);
5853 break;
5854 case E1000E_INT_MODE_MSI:
5855 disable_irq(adapter->pdev->irq);
5856 e1000_intr_msi(adapter->pdev->irq, netdev);
5857 enable_irq(adapter->pdev->irq);
5858 break;
5859 default: /* E1000E_INT_MODE_LEGACY */
5860 disable_irq(adapter->pdev->irq);
5861 e1000_intr(adapter->pdev->irq, netdev);
5862 enable_irq(adapter->pdev->irq);
5863 break;
5864 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005865}
5866#endif
5867
5868/**
5869 * e1000_io_error_detected - called when PCI error is detected
5870 * @pdev: Pointer to PCI device
5871 * @state: The current pci connection state
5872 *
5873 * This function is called after a PCI bus error affecting
5874 * this device has been detected.
5875 */
5876static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5877 pci_channel_state_t state)
5878{
5879 struct net_device *netdev = pci_get_drvdata(pdev);
5880 struct e1000_adapter *adapter = netdev_priv(netdev);
5881
5882 netif_device_detach(netdev);
5883
Mike Masonc93b5a72009-06-30 12:45:53 +00005884 if (state == pci_channel_io_perm_failure)
5885 return PCI_ERS_RESULT_DISCONNECT;
5886
Auke Kokbc7f75f2007-09-17 12:30:59 -07005887 if (netif_running(netdev))
5888 e1000e_down(adapter);
5889 pci_disable_device(pdev);
5890
5891 /* Request a slot slot reset. */
5892 return PCI_ERS_RESULT_NEED_RESET;
5893}
5894
5895/**
5896 * e1000_io_slot_reset - called after the pci bus has been reset.
5897 * @pdev: Pointer to PCI device
5898 *
5899 * Restart the card from scratch, as if from a cold-boot. Implementation
5900 * resembles the first-half of the e1000_resume routine.
5901 */
5902static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5903{
5904 struct net_device *netdev = pci_get_drvdata(pdev);
5905 struct e1000_adapter *adapter = netdev_priv(netdev);
5906 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005907 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005908 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005909 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005910
Bruce Allan78cd29d2011-03-24 03:09:03 +00005911 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5912 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005913 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005914 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5915 if (aspm_disable_flag)
5916 e1000e_disable_aspm(pdev, aspm_disable_flag);
5917
Bruce Allanf0f422e2008-08-04 17:21:53 -07005918 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005919 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005920 dev_err(&pdev->dev,
5921 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005922 result = PCI_ERS_RESULT_DISCONNECT;
5923 } else {
5924 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005925 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005926 pci_restore_state(pdev);
5927
5928 pci_enable_wake(pdev, PCI_D3hot, 0);
5929 pci_enable_wake(pdev, PCI_D3cold, 0);
5930
5931 e1000e_reset(adapter);
5932 ew32(WUS, ~0);
5933 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005934 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005935
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005936 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005937
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005938 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005939}
5940
5941/**
5942 * e1000_io_resume - called when traffic can start flowing again.
5943 * @pdev: Pointer to PCI device
5944 *
5945 * This callback is called when the error recovery driver tells us that
5946 * its OK to resume normal operation. Implementation resembles the
5947 * second-half of the e1000_resume routine.
5948 */
5949static void e1000_io_resume(struct pci_dev *pdev)
5950{
5951 struct net_device *netdev = pci_get_drvdata(pdev);
5952 struct e1000_adapter *adapter = netdev_priv(netdev);
5953
Bruce Allancd791612010-05-10 14:59:51 +00005954 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955
5956 if (netif_running(netdev)) {
5957 if (e1000e_up(adapter)) {
5958 dev_err(&pdev->dev,
5959 "can't bring device back up after reset\n");
5960 return;
5961 }
5962 }
5963
5964 netif_device_attach(netdev);
5965
Bruce Allanad680762008-03-28 09:15:03 -07005966 /*
5967 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005968 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005969 * under the control of the driver.
5970 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005971 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005972 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005973
5974}
5975
5976static void e1000_print_device_info(struct e1000_adapter *adapter)
5977{
5978 struct e1000_hw *hw = &adapter->hw;
5979 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005980 u32 ret_val;
5981 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005982
5983 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005984 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005985 /* bus width */
5986 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5987 "Width x1"),
5988 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005989 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005990 e_info("Intel(R) PRO/%s Network Connection\n",
5991 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005992 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5993 E1000_PBANUM_LENGTH);
5994 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00005995 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00005996 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5997 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005998}
5999
Auke Kok10aa4c02008-08-04 17:21:20 -07006000static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6001{
6002 struct e1000_hw *hw = &adapter->hw;
6003 int ret_val;
6004 u16 buf = 0;
6005
6006 if (hw->mac.type != e1000_82573)
6007 return;
6008
6009 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006010 le16_to_cpus(&buf);
6011 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006012 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006013 dev_warn(&adapter->pdev->dev,
6014 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006015 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006016}
6017
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006018static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006019 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006020{
6021 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006022 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006023
6024 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6025 adapter->flags |= FLAG_TSO_FORCE;
6026
6027 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006028 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6029 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006030 return 0;
6031
Bruce Allan70495a52012-01-11 01:26:50 +00006032 /*
6033 * IP payload checksum (enabled with jumbos/packet-split when Rx
6034 * checksum is enabled) and generation of RSS hash is mutually
6035 * exclusive in the hardware.
6036 */
6037 if (adapter->rx_ps_pages &&
6038 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
6039 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");
6040 return -EINVAL;
6041 }
6042
Ben Greear01840392012-02-11 15:39:25 +00006043 if (changed & NETIF_F_RXFCS) {
6044 if (features & NETIF_F_RXFCS) {
6045 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6046 } else {
6047 /* We need to take it back to defaults, which might mean
6048 * stripping is still disabled at the adapter level.
6049 */
6050 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6051 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6052 else
6053 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6054 }
6055 }
6056
Bruce Allan70495a52012-01-11 01:26:50 +00006057 netdev->features = features;
6058
Bruce Allandc221292011-08-19 03:23:48 +00006059 if (netif_running(netdev))
6060 e1000e_reinit_locked(adapter);
6061 else
6062 e1000e_reset(adapter);
6063
6064 return 0;
6065}
6066
Stephen Hemminger651c2462008-11-19 21:57:48 -08006067static const struct net_device_ops e1000e_netdev_ops = {
6068 .ndo_open = e1000_open,
6069 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006070 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006071 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006072 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006073 .ndo_set_mac_address = e1000_set_mac,
6074 .ndo_change_mtu = e1000_change_mtu,
6075 .ndo_do_ioctl = e1000_ioctl,
6076 .ndo_tx_timeout = e1000_tx_timeout,
6077 .ndo_validate_addr = eth_validate_addr,
6078
Stephen Hemminger651c2462008-11-19 21:57:48 -08006079 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6080 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6081#ifdef CONFIG_NET_POLL_CONTROLLER
6082 .ndo_poll_controller = e1000_netpoll,
6083#endif
Bruce Allandc221292011-08-19 03:23:48 +00006084 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006085};
6086
Auke Kokbc7f75f2007-09-17 12:30:59 -07006087/**
6088 * e1000_probe - Device Initialization Routine
6089 * @pdev: PCI device information struct
6090 * @ent: entry in e1000_pci_tbl
6091 *
6092 * Returns 0 on success, negative on failure
6093 *
6094 * e1000_probe initializes an adapter identified by a pci_dev structure.
6095 * The OS initialization, configuring of the adapter private structure,
6096 * and a hardware reset occur.
6097 **/
6098static int __devinit e1000_probe(struct pci_dev *pdev,
6099 const struct pci_device_id *ent)
6100{
6101 struct net_device *netdev;
6102 struct e1000_adapter *adapter;
6103 struct e1000_hw *hw;
6104 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006105 resource_size_t mmio_start, mmio_len;
6106 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006107 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006108 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006109 int i, err, pci_using_dac;
6110 u16 eeprom_data = 0;
6111 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6112
Bruce Allan78cd29d2011-03-24 03:09:03 +00006113 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6114 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006115 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006116 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6117 if (aspm_disable_flag)
6118 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006119
Bruce Allanf0f422e2008-08-04 17:21:53 -07006120 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006121 if (err)
6122 return err;
6123
6124 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006125 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006126 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006127 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006128 if (!err)
6129 pci_using_dac = 1;
6130 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006131 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006132 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006133 err = dma_set_coherent_mask(&pdev->dev,
6134 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006135 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006136 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006137 goto err_dma;
6138 }
6139 }
6140 }
6141
Arjan van de Vene8de1482008-10-22 19:55:31 -07006142 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006143 pci_select_bars(pdev, IORESOURCE_MEM),
6144 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006145 if (err)
6146 goto err_pci_reg;
6147
Xiaotian Feng68eac462009-08-14 14:35:52 +00006148 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006149 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006150
Auke Kokbc7f75f2007-09-17 12:30:59 -07006151 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006152 /* PCI config space info */
6153 err = pci_save_state(pdev);
6154 if (err)
6155 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006156
6157 err = -ENOMEM;
6158 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6159 if (!netdev)
6160 goto err_alloc_etherdev;
6161
Auke Kokbc7f75f2007-09-17 12:30:59 -07006162 SET_NETDEV_DEV(netdev, &pdev->dev);
6163
Tom Herbertf85e4df2010-05-05 14:03:32 +00006164 netdev->irq = pdev->irq;
6165
Auke Kokbc7f75f2007-09-17 12:30:59 -07006166 pci_set_drvdata(pdev, netdev);
6167 adapter = netdev_priv(netdev);
6168 hw = &adapter->hw;
6169 adapter->netdev = netdev;
6170 adapter->pdev = pdev;
6171 adapter->ei = ei;
6172 adapter->pba = ei->pba;
6173 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006174 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006175 adapter->hw.adapter = adapter;
6176 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006177 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006178 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6179
6180 mmio_start = pci_resource_start(pdev, 0);
6181 mmio_len = pci_resource_len(pdev, 0);
6182
6183 err = -EIO;
6184 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6185 if (!adapter->hw.hw_addr)
6186 goto err_ioremap;
6187
6188 if ((adapter->flags & FLAG_HAS_FLASH) &&
6189 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6190 flash_start = pci_resource_start(pdev, 1);
6191 flash_len = pci_resource_len(pdev, 1);
6192 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6193 if (!adapter->hw.flash_address)
6194 goto err_flashmap;
6195 }
6196
6197 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006198 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006199 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006200 netdev->watchdog_timeo = 5 * HZ;
6201 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006202 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006203
6204 netdev->mem_start = mmio_start;
6205 netdev->mem_end = mmio_start + mmio_len;
6206
6207 adapter->bd_number = cards_found++;
6208
Bruce Allan4662e822008-08-26 18:37:06 -07006209 e1000e_check_options(adapter);
6210
Auke Kokbc7f75f2007-09-17 12:30:59 -07006211 /* setup adapter struct */
6212 err = e1000_sw_init(adapter);
6213 if (err)
6214 goto err_sw_init;
6215
Auke Kokbc7f75f2007-09-17 12:30:59 -07006216 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6217 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6218 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6219
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006220 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006221 if (err)
6222 goto err_hw_init;
6223
Bruce Allan4a770352008-10-01 17:18:35 -07006224 if ((adapter->flags & FLAG_IS_ICH) &&
6225 (adapter->flags & FLAG_READ_ONLY_NVM))
6226 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6227
Auke Kokbc7f75f2007-09-17 12:30:59 -07006228 hw->mac.ops.get_bus_info(&adapter->hw);
6229
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006230 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006231
6232 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006233 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006234 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6235 adapter->hw.phy.disable_polarity_correction = 0;
6236 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6237 }
6238
Bruce Allan44abd5c2012-02-22 09:02:37 +00006239 if (hw->phy.ops.check_reset_block(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006240 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006241
Bruce Allandc221292011-08-19 03:23:48 +00006242 /* Set initial default active device features */
6243 netdev->features = (NETIF_F_SG |
6244 NETIF_F_HW_VLAN_RX |
6245 NETIF_F_HW_VLAN_TX |
6246 NETIF_F_TSO |
6247 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006248 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006249 NETIF_F_RXCSUM |
6250 NETIF_F_HW_CSUM);
6251
6252 /* Set user-changeable features (subset of all device features) */
6253 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006254 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006255 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006256 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006257
6258 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6259 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6260
Bruce Allandc221292011-08-19 03:23:48 +00006261 netdev->vlan_features |= (NETIF_F_SG |
6262 NETIF_F_TSO |
6263 NETIF_F_TSO6 |
6264 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006265
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006266 netdev->priv_flags |= IFF_UNICAST_FLT;
6267
Yi Zou7b872a52010-09-22 17:57:58 +00006268 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006269 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006270 netdev->vlan_features |= NETIF_F_HIGHDMA;
6271 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006272
Auke Kokbc7f75f2007-09-17 12:30:59 -07006273 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6274 adapter->flags |= FLAG_MNG_PT_ENABLED;
6275
Bruce Allanad680762008-03-28 09:15:03 -07006276 /*
6277 * before reading the NVM, reset the controller to
6278 * put the device in a known good starting state
6279 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006280 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6281
6282 /*
6283 * systems with ASPM and others may see the checksum fail on the first
6284 * attempt. Let's give it a few tries
6285 */
6286 for (i = 0;; i++) {
6287 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6288 break;
6289 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006290 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006291 err = -EIO;
6292 goto err_eeprom;
6293 }
6294 }
6295
Auke Kok10aa4c02008-08-04 17:21:20 -07006296 e1000_eeprom_checks(adapter);
6297
Bruce Allan608f8a02010-01-13 02:04:58 +00006298 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006299 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006300 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006301
6302 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6303 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6304
6305 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006306 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006307 err = -EIO;
6308 goto err_eeprom;
6309 }
6310
6311 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006312 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006313 adapter->watchdog_timer.data = (unsigned long) adapter;
6314
6315 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006316 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006317 adapter->phy_info_timer.data = (unsigned long) adapter;
6318
6319 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6320 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006321 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6322 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006323 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006324
Auke Kokbc7f75f2007-09-17 12:30:59 -07006325 /* Initialize link parameters. User can change them with ethtool */
6326 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006327 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006328 adapter->hw.fc.requested_mode = e1000_fc_default;
6329 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006330 adapter->hw.phy.autoneg_advertised = 0x2f;
6331
6332 /* ring size defaults */
6333 adapter->rx_ring->count = 256;
6334 adapter->tx_ring->count = 256;
6335
6336 /*
6337 * Initial Wake on LAN setting - If APM wake is enabled in
6338 * the EEPROM, enable the ACPI Magic Packet filter
6339 */
6340 if (adapter->flags & FLAG_APME_IN_WUC) {
6341 /* APME bit in EEPROM is mapped to WUC.APME */
6342 eeprom_data = er32(WUC);
6343 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006344 if ((hw->mac.type > e1000_ich10lan) &&
6345 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006346 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006347 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6348 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6349 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006350 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6351 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006352 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006353 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6354 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006355 }
6356
6357 /* fetch WoL from EEPROM */
6358 if (eeprom_data & eeprom_apme_mask)
6359 adapter->eeprom_wol |= E1000_WUFC_MAG;
6360
6361 /*
6362 * now that we have the eeprom settings, apply the special cases
6363 * where the eeprom may be wrong or the board simply won't support
6364 * wake on lan on a particular port
6365 */
6366 if (!(adapter->flags & FLAG_HAS_WOL))
6367 adapter->eeprom_wol = 0;
6368
6369 /* initialize the wol settings based on the eeprom settings */
6370 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006371 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006372
Bruce Allan84527592008-11-21 17:00:22 -08006373 /* save off EEPROM version number */
6374 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6375
Auke Kokbc7f75f2007-09-17 12:30:59 -07006376 /* reset the hardware with the new settings */
6377 e1000e_reset(adapter);
6378
Bruce Allanad680762008-03-28 09:15:03 -07006379 /*
6380 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006381 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006382 * under the control of the driver.
6383 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006384 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006385 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006386
Bruce Allanf2315bf2011-12-16 00:46:59 +00006387 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006388 err = register_netdev(netdev);
6389 if (err)
6390 goto err_register;
6391
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006392 /* carrier off reporting is important to ethtool even BEFORE open */
6393 netif_carrier_off(netdev);
6394
Auke Kokbc7f75f2007-09-17 12:30:59 -07006395 e1000_print_device_info(adapter);
6396
Alan Sternf3ec4f82010-06-08 15:23:51 -04006397 if (pci_dev_run_wake(pdev))
6398 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006399
Auke Kokbc7f75f2007-09-17 12:30:59 -07006400 return 0;
6401
6402err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006403 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006404 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006405err_eeprom:
Bruce Allan44abd5c2012-02-22 09:02:37 +00006406 if (!hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006407 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006408err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006409 kfree(adapter->tx_ring);
6410 kfree(adapter->rx_ring);
6411err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006412 if (adapter->hw.flash_address)
6413 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006414 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006415err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006416 iounmap(adapter->hw.hw_addr);
6417err_ioremap:
6418 free_netdev(netdev);
6419err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006420 pci_release_selected_regions(pdev,
6421 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006422err_pci_reg:
6423err_dma:
6424 pci_disable_device(pdev);
6425 return err;
6426}
6427
6428/**
6429 * e1000_remove - Device Removal Routine
6430 * @pdev: PCI device information struct
6431 *
6432 * e1000_remove is called by the PCI subsystem to alert the driver
6433 * that it should release a PCI device. The could be caused by a
6434 * Hot-Plug event, or because the driver is going to be removed from
6435 * memory.
6436 **/
6437static void __devexit e1000_remove(struct pci_dev *pdev)
6438{
6439 struct net_device *netdev = pci_get_drvdata(pdev);
6440 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006441 bool down = test_bit(__E1000_DOWN, &adapter->state);
6442
Bruce Allanad680762008-03-28 09:15:03 -07006443 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006444 * The timers may be rescheduled, so explicitly disable them
6445 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006446 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006447 if (!down)
6448 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006449 del_timer_sync(&adapter->watchdog_timer);
6450 del_timer_sync(&adapter->phy_info_timer);
6451
Bruce Allan41cec6f2009-11-20 23:28:56 +00006452 cancel_work_sync(&adapter->reset_task);
6453 cancel_work_sync(&adapter->watchdog_task);
6454 cancel_work_sync(&adapter->downshift_task);
6455 cancel_work_sync(&adapter->update_phy_task);
6456 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006457
Bruce Allan17f208d2009-12-01 15:47:22 +00006458 if (!(netdev->flags & IFF_UP))
6459 e1000_power_down_phy(adapter);
6460
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006461 /* Don't lie to e1000_close() down the road. */
6462 if (!down)
6463 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006464 unregister_netdev(netdev);
6465
Alan Sternf3ec4f82010-06-08 15:23:51 -04006466 if (pci_dev_run_wake(pdev))
6467 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006468
Bruce Allanad680762008-03-28 09:15:03 -07006469 /*
6470 * Release control of h/w to f/w. If f/w is AMT enabled, this
6471 * would have already happened in close and is redundant.
6472 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006473 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006474
Bruce Allan4662e822008-08-26 18:37:06 -07006475 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006476 kfree(adapter->tx_ring);
6477 kfree(adapter->rx_ring);
6478
6479 iounmap(adapter->hw.hw_addr);
6480 if (adapter->hw.flash_address)
6481 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006482 pci_release_selected_regions(pdev,
6483 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006484
6485 free_netdev(netdev);
6486
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006487 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006488 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006489
Auke Kokbc7f75f2007-09-17 12:30:59 -07006490 pci_disable_device(pdev);
6491}
6492
6493/* PCI Error Recovery (ERS) */
6494static struct pci_error_handlers e1000_err_handler = {
6495 .error_detected = e1000_io_error_detected,
6496 .slot_reset = e1000_io_slot_reset,
6497 .resume = e1000_io_resume,
6498};
6499
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006500static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006501 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6502 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6503 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6504 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6505 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6506 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006507 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6508 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6509 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006510
Auke Kokbc7f75f2007-09-17 12:30:59 -07006511 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6512 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6513 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6514 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006515
Auke Kokbc7f75f2007-09-17 12:30:59 -07006516 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6517 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6518 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006519
Bruce Allan4662e822008-08-26 18:37:06 -07006520 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006521 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006522 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006523
Auke Kokbc7f75f2007-09-17 12:30:59 -07006524 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6525 board_80003es2lan },
6526 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6527 board_80003es2lan },
6528 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6529 board_80003es2lan },
6530 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6531 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006532
Auke Kokbc7f75f2007-09-17 12:30:59 -07006533 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6534 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6535 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6536 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6537 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6538 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6539 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006540 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006541
Auke Kokbc7f75f2007-09-17 12:30:59 -07006542 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6543 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6544 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6545 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6546 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006547 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006548 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6549 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6550 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6551
6552 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6553 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6554 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006555
Bruce Allanf4187b52008-08-26 18:36:50 -07006556 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6557 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006558 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006559
Bruce Allana4f58f52009-06-02 11:29:18 +00006560 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6561 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6562 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6563 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6564
Bruce Alland3738bb2010-06-16 13:27:28 +00006565 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6566 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6567
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006568 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006569};
6570MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6571
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006572#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006573static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006574 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6575 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6576 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006577};
David S. Millere50208a2010-03-16 23:36:24 -07006578#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006579
Auke Kokbc7f75f2007-09-17 12:30:59 -07006580/* PCI Device API Driver */
6581static struct pci_driver e1000_driver = {
6582 .name = e1000e_driver_name,
6583 .id_table = e1000_pci_tbl,
6584 .probe = e1000_probe,
6585 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006586#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006587 .driver = {
6588 .pm = &e1000_pm_ops,
6589 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006590#endif
6591 .shutdown = e1000_shutdown,
6592 .err_handler = &e1000_err_handler
6593};
6594
6595/**
6596 * e1000_init_module - Driver Registration Routine
6597 *
6598 * e1000_init_module is the first routine called when the driver is
6599 * loaded. All it does is register with the PCI subsystem.
6600 **/
6601static int __init e1000_init_module(void)
6602{
6603 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006604 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6605 e1000e_driver_version);
Bruce Allanf5e261e2012-01-01 16:00:03 +00006606 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006607 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006608
Auke Kokbc7f75f2007-09-17 12:30:59 -07006609 return ret;
6610}
6611module_init(e1000_init_module);
6612
6613/**
6614 * e1000_exit_module - Driver Exit Cleanup Routine
6615 *
6616 * e1000_exit_module is called just before the driver is removed
6617 * from memory.
6618 **/
6619static void __exit e1000_exit_module(void)
6620{
6621 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006622}
6623module_exit(e1000_exit_module);
6624
6625
6626MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6627MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6628MODULE_LICENSE("GPL");
6629MODULE_VERSION(DRV_VERSION);
6630
Bruce Allan06c24b92012-02-23 03:13:13 +00006631/* netdev.c */