blob: 30c8c15d0396ad51d6bea81eb54f1882daec3b0f [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
Bruce Allan5f450212011-07-22 06:21:46 +0000929 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700930 /* recycle */
931 buffer_info->skb = skb;
932 goto next_desc;
933 }
934
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000935 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000936 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
937 /* If configured to store CRC, don't subtract FCS,
938 * but keep the FCS bytes out of the total_rx_bytes
939 * counter
940 */
941 if (netdev->features & NETIF_F_RXFCS)
942 total_rx_bytes -= 4;
943 else
944 length -= 4;
945 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000946
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947 total_rx_bytes += length;
948 total_rx_packets++;
949
Bruce Allanad680762008-03-28 09:15:03 -0700950 /*
951 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700953 * of reassembly being done in the stack
954 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700955 if (length < copybreak) {
956 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000957 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700958 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700959 skb_copy_to_linear_data_offset(new_skb,
960 -NET_IP_ALIGN,
961 (skb->data -
962 NET_IP_ALIGN),
963 (length +
964 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700965 /* save the skb in buffer_info as good */
966 buffer_info->skb = skb;
967 skb = new_skb;
968 }
969 /* else just continue with the old one */
970 }
971 /* end copybreak code */
972 skb_put(skb, length);
973
974 /* Receive Checksum Offload */
Bruce Allan5f450212011-07-22 06:21:46 +0000975 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +0000976 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700977
Bruce Allan70495a52012-01-11 01:26:50 +0000978 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
979
Bruce Allan5f450212011-07-22 06:21:46 +0000980 e1000_receive_skb(adapter, netdev, skb, staterr,
981 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982
983next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +0000984 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700985
986 /* return some buffers to hardware, one at a time is too slow */
987 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +0000988 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000989 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 cleaned_count = 0;
991 }
992
993 /* use prefetched values */
994 rx_desc = next_rxd;
995 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000996
997 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700998 }
999 rx_ring->next_to_clean = i;
1000
1001 cleaned_count = e1000_desc_unused(rx_ring);
1002 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001003 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001004
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001006 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001007 return cleaned;
1008}
1009
Bruce Allan55aa6982011-12-16 00:45:45 +00001010static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1011 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001012{
Bruce Allan55aa6982011-12-16 00:45:45 +00001013 struct e1000_adapter *adapter = tx_ring->adapter;
1014
Alexander Duyck03b13202009-12-02 16:45:31 +00001015 if (buffer_info->dma) {
1016 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001017 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1018 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001019 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001020 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1021 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001022 buffer_info->dma = 0;
1023 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024 if (buffer_info->skb) {
1025 dev_kfree_skb_any(buffer_info->skb);
1026 buffer_info->skb = NULL;
1027 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001028 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001029}
1030
Bruce Allan41cec6f2009-11-20 23:28:56 +00001031static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001032{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001033 struct e1000_adapter *adapter = container_of(work,
1034 struct e1000_adapter,
1035 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001036 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037 struct e1000_ring *tx_ring = adapter->tx_ring;
1038 unsigned int i = tx_ring->next_to_clean;
1039 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1040 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001041 struct e1000_hw *hw = &adapter->hw;
1042 u16 phy_status, phy_1000t_status, phy_ext_status;
1043 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001044
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001045 if (test_bit(__E1000_DOWN, &adapter->state))
1046 return;
1047
Jeff Kirsher09357b02011-11-18 14:25:00 +00001048 if (!adapter->tx_hang_recheck &&
1049 (adapter->flags2 & FLAG2_DMA_BURST)) {
1050 /* May be block on write-back, flush and detect again
1051 * flush pending descriptor writebacks to memory
1052 */
1053 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1054 /* execute the writes immediately */
1055 e1e_flush();
1056 adapter->tx_hang_recheck = true;
1057 return;
1058 }
1059 /* Real hang detected */
1060 adapter->tx_hang_recheck = false;
1061 netif_stop_queue(netdev);
1062
Bruce Allan41cec6f2009-11-20 23:28:56 +00001063 e1e_rphy(hw, PHY_STATUS, &phy_status);
1064 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1065 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1066
1067 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1068
1069 /* detected Hardware unit hang */
1070 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001071 " TDH <%x>\n"
1072 " TDT <%x>\n"
1073 " next_to_use <%x>\n"
1074 " next_to_clean <%x>\n"
1075 "buffer_info[next_to_clean]:\n"
1076 " time_stamp <%lx>\n"
1077 " next_to_watch <%x>\n"
1078 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001079 " next_to_watch.status <%x>\n"
1080 "MAC Status <%x>\n"
1081 "PHY Status <%x>\n"
1082 "PHY 1000BASE-T Status <%x>\n"
1083 "PHY Extended Status <%x>\n"
1084 "PCI Status <%x>\n",
Bruce Allanc5083cf2011-12-16 00:45:40 +00001085 readl(tx_ring->head),
1086 readl(tx_ring->tail),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001087 tx_ring->next_to_use,
1088 tx_ring->next_to_clean,
1089 tx_ring->buffer_info[eop].time_stamp,
1090 eop,
1091 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001092 eop_desc->upper.fields.status,
1093 er32(STATUS),
1094 phy_status,
1095 phy_1000t_status,
1096 phy_ext_status,
1097 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001098}
1099
1100/**
1101 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001102 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001103 *
1104 * the return value indicates whether actual cleaning was done, there
1105 * is no guarantee that everything was cleaned
1106 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001107static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001108{
Bruce Allan55aa6982011-12-16 00:45:45 +00001109 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001110 struct net_device *netdev = adapter->netdev;
1111 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001112 struct e1000_tx_desc *tx_desc, *eop_desc;
1113 struct e1000_buffer *buffer_info;
1114 unsigned int i, eop;
1115 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001116 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001117 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001118
1119 i = tx_ring->next_to_clean;
1120 eop = tx_ring->buffer_info[i].next_to_watch;
1121 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1122
Alexander Duyck12d04a32009-03-25 22:05:03 +00001123 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1124 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001125 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001126 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001127 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128 tx_desc = E1000_TX_DESC(*tx_ring, i);
1129 buffer_info = &tx_ring->buffer_info[i];
1130 cleaned = (i == eop);
1131
1132 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001133 total_tx_packets += buffer_info->segs;
1134 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001135 if (buffer_info->skb) {
1136 bytes_compl += buffer_info->skb->len;
1137 pkts_compl++;
1138 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001139 }
1140
Bruce Allan55aa6982011-12-16 00:45:45 +00001141 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001142 tx_desc->upper.data = 0;
1143
1144 i++;
1145 if (i == tx_ring->count)
1146 i = 0;
1147 }
1148
Terry Loftindac87612010-04-09 10:29:49 +00001149 if (i == tx_ring->next_to_use)
1150 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001151 eop = tx_ring->buffer_info[i].next_to_watch;
1152 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001153 }
1154
1155 tx_ring->next_to_clean = i;
1156
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001157 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1158
Auke Kokbc7f75f2007-09-17 12:30:59 -07001159#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001160 if (count && netif_carrier_ok(netdev) &&
1161 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001162 /* Make sure that anybody stopping the queue after this
1163 * sees the new next_to_clean.
1164 */
1165 smp_mb();
1166
1167 if (netif_queue_stopped(netdev) &&
1168 !(test_bit(__E1000_DOWN, &adapter->state))) {
1169 netif_wake_queue(netdev);
1170 ++adapter->restart_queue;
1171 }
1172 }
1173
1174 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001175 /*
1176 * Detect a transmit hang in hardware, this serializes the
1177 * check with the clearing of time_stamp and movement of i
1178 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001179 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001180 if (tx_ring->buffer_info[i].time_stamp &&
1181 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001182 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001183 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001184 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001185 else
1186 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001187 }
1188 adapter->total_tx_bytes += total_tx_bytes;
1189 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001190 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001191}
1192
1193/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001194 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001195 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001196 *
1197 * the return value indicates whether actual cleaning was done, there
1198 * is no guarantee that everything was cleaned
1199 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001200static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1201 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202{
Bruce Allan55aa6982011-12-16 00:45:45 +00001203 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001204 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001205 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1206 struct net_device *netdev = adapter->netdev;
1207 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001208 struct e1000_buffer *buffer_info, *next_buffer;
1209 struct e1000_ps_page *ps_page;
1210 struct sk_buff *skb;
1211 unsigned int i, j;
1212 u32 length, staterr;
1213 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001214 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001215 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1216
1217 i = rx_ring->next_to_clean;
1218 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1219 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1220 buffer_info = &rx_ring->buffer_info[i];
1221
1222 while (staterr & E1000_RXD_STAT_DD) {
1223 if (*work_done >= work_to_do)
1224 break;
1225 (*work_done)++;
1226 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001227 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001228
1229 /* in the packet split case this is header only */
1230 prefetch(skb->data - NET_IP_ALIGN);
1231
1232 i++;
1233 if (i == rx_ring->count)
1234 i = 0;
1235 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1236 prefetch(next_rxd);
1237
1238 next_buffer = &rx_ring->buffer_info[i];
1239
Rusty Russell3db1cd52011-12-19 13:56:45 +00001240 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001241 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001242 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001243 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 buffer_info->dma = 0;
1245
Bruce Allanaf667a22010-12-31 06:10:01 +00001246 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001247 if (!(staterr & E1000_RXD_STAT_EOP))
1248 adapter->flags2 |= FLAG2_IS_DISCARDING;
1249
1250 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001251 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001252 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001253 if (staterr & E1000_RXD_STAT_EOP)
1254 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001255 goto next_desc;
1256 }
1257
1258 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1259 dev_kfree_skb_irq(skb);
1260 goto next_desc;
1261 }
1262
1263 length = le16_to_cpu(rx_desc->wb.middle.length0);
1264
1265 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001266 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001267 dev_kfree_skb_irq(skb);
1268 goto next_desc;
1269 }
1270
1271 /* Good Receive */
1272 skb_put(skb, length);
1273
1274 {
Bruce Allan0e15df42012-01-31 06:37:11 +00001275 /*
1276 * this looks ugly, but it seems compiler issues make
1277 * it more efficient than reusing j
1278 */
1279 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001280
Bruce Allanad680762008-03-28 09:15:03 -07001281 /*
Bruce Allan0e15df42012-01-31 06:37:11 +00001282 * page alloc/put takes too long and effects small
1283 * packet throughput, so unsplit small packets and
1284 * save the alloc/put only valid in softirq (napi)
1285 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001286 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001287 if (l1 && (l1 <= copybreak) &&
1288 ((length + l1) <= adapter->rx_ps_bsize0)) {
1289 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001290
Bruce Allan0e15df42012-01-31 06:37:11 +00001291 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001292
Bruce Allan0e15df42012-01-31 06:37:11 +00001293 /*
1294 * there is no documentation about how to call
1295 * kmap_atomic, so we can't hold the mapping
1296 * very long
1297 */
1298 dma_sync_single_for_cpu(&pdev->dev,
1299 ps_page->dma,
1300 PAGE_SIZE,
1301 DMA_FROM_DEVICE);
1302 vaddr = kmap_atomic(ps_page->page,
1303 KM_SKB_DATA_SOFTIRQ);
1304 memcpy(skb_tail_pointer(skb), vaddr, l1);
1305 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
1306 dma_sync_single_for_device(&pdev->dev,
1307 ps_page->dma,
1308 PAGE_SIZE,
1309 DMA_FROM_DEVICE);
1310
1311 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001312 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1313 if (!(netdev->features & NETIF_F_RXFCS))
1314 l1 -= 4;
1315 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001316
1317 skb_put(skb, l1);
1318 goto copydone;
1319 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001320 }
1321
1322 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1323 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1324 if (!length)
1325 break;
1326
Auke Kok47f44e42007-10-25 13:57:44 -07001327 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001328 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1329 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001330 ps_page->dma = 0;
1331 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1332 ps_page->page = NULL;
1333 skb->len += length;
1334 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001335 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336 }
1337
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001338 /* strip the ethernet crc, problem is we're using pages now so
1339 * this whole operation can get a little cpu intensive
1340 */
Ben Greear01840392012-02-11 15:39:25 +00001341 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1342 if (!(netdev->features & NETIF_F_RXFCS))
1343 pskb_trim(skb, skb->len - 4);
1344 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001345
Auke Kokbc7f75f2007-09-17 12:30:59 -07001346copydone:
1347 total_rx_bytes += skb->len;
1348 total_rx_packets++;
1349
Bruce Allanafd12932012-01-05 00:34:05 +00001350 e1000_rx_checksum(adapter, staterr,
1351 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001352
Bruce Allan70495a52012-01-11 01:26:50 +00001353 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1354
Auke Kokbc7f75f2007-09-17 12:30:59 -07001355 if (rx_desc->wb.upper.header_status &
1356 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1357 adapter->rx_hdr_split++;
1358
1359 e1000_receive_skb(adapter, netdev, skb,
1360 staterr, rx_desc->wb.middle.vlan);
1361
1362next_desc:
1363 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1364 buffer_info->skb = NULL;
1365
1366 /* return some buffers to hardware, one at a time is too slow */
1367 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001368 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001369 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001370 cleaned_count = 0;
1371 }
1372
1373 /* use prefetched values */
1374 rx_desc = next_rxd;
1375 buffer_info = next_buffer;
1376
1377 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1378 }
1379 rx_ring->next_to_clean = i;
1380
1381 cleaned_count = e1000_desc_unused(rx_ring);
1382 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001383 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001384
Auke Kokbc7f75f2007-09-17 12:30:59 -07001385 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001386 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001387 return cleaned;
1388}
1389
1390/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001391 * e1000_consume_page - helper function
1392 **/
1393static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1394 u16 length)
1395{
1396 bi->page = NULL;
1397 skb->len += length;
1398 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001399 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001400}
1401
1402/**
1403 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1404 * @adapter: board private structure
1405 *
1406 * the return value indicates whether actual cleaning was done, there
1407 * is no guarantee that everything was cleaned
1408 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001409static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1410 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001411{
Bruce Allan55aa6982011-12-16 00:45:45 +00001412 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001413 struct net_device *netdev = adapter->netdev;
1414 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001415 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001416 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001417 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001418 unsigned int i;
1419 int cleaned_count = 0;
1420 bool cleaned = false;
1421 unsigned int total_rx_bytes=0, total_rx_packets=0;
1422
1423 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001424 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1425 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001426 buffer_info = &rx_ring->buffer_info[i];
1427
Bruce Allan5f450212011-07-22 06:21:46 +00001428 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001429 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001430
1431 if (*work_done >= work_to_do)
1432 break;
1433 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001434 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001435
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001436 skb = buffer_info->skb;
1437 buffer_info->skb = NULL;
1438
1439 ++i;
1440 if (i == rx_ring->count)
1441 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001442 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001443 prefetch(next_rxd);
1444
1445 next_buffer = &rx_ring->buffer_info[i];
1446
1447 cleaned = true;
1448 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001449 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1450 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001451 buffer_info->dma = 0;
1452
Bruce Allan5f450212011-07-22 06:21:46 +00001453 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001454
1455 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001456 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1457 (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
1458 /* recycle both page and skb */
1459 buffer_info->skb = skb;
1460 /* an error means any chain goes out the window too */
1461 if (rx_ring->rx_skb_top)
1462 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1463 rx_ring->rx_skb_top = NULL;
1464 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001465 }
1466
Bruce Allanf0f1a172010-12-11 05:53:32 +00001467#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001468 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001469 /* this descriptor is only the beginning (or middle) */
1470 if (!rxtop) {
1471 /* this is the beginning of a chain */
1472 rxtop = skb;
1473 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1474 0, length);
1475 } else {
1476 /* this is the middle of a chain */
1477 skb_fill_page_desc(rxtop,
1478 skb_shinfo(rxtop)->nr_frags,
1479 buffer_info->page, 0, length);
1480 /* re-use the skb, only consumed the page */
1481 buffer_info->skb = skb;
1482 }
1483 e1000_consume_page(buffer_info, rxtop, length);
1484 goto next_desc;
1485 } else {
1486 if (rxtop) {
1487 /* end of the chain */
1488 skb_fill_page_desc(rxtop,
1489 skb_shinfo(rxtop)->nr_frags,
1490 buffer_info->page, 0, length);
1491 /* re-use the current skb, we only consumed the
1492 * page */
1493 buffer_info->skb = skb;
1494 skb = rxtop;
1495 rxtop = NULL;
1496 e1000_consume_page(buffer_info, skb, length);
1497 } else {
1498 /* no chain, got EOP, this buf is the packet
1499 * copybreak to save the put_page/alloc_page */
1500 if (length <= copybreak &&
1501 skb_tailroom(skb) >= length) {
1502 u8 *vaddr;
1503 vaddr = kmap_atomic(buffer_info->page,
1504 KM_SKB_DATA_SOFTIRQ);
1505 memcpy(skb_tail_pointer(skb), vaddr,
1506 length);
1507 kunmap_atomic(vaddr,
1508 KM_SKB_DATA_SOFTIRQ);
1509 /* re-use the page, so don't erase
1510 * buffer_info->page */
1511 skb_put(skb, length);
1512 } else {
1513 skb_fill_page_desc(skb, 0,
1514 buffer_info->page, 0,
1515 length);
1516 e1000_consume_page(buffer_info, skb,
1517 length);
1518 }
1519 }
1520 }
1521
1522 /* Receive Checksum Offload XXX recompute due to CRC strip? */
Bruce Allan5f450212011-07-22 06:21:46 +00001523 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +00001524 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001525
Bruce Allan70495a52012-01-11 01:26:50 +00001526 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1527
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001528 /* probably a little skewed due to removing CRC */
1529 total_rx_bytes += skb->len;
1530 total_rx_packets++;
1531
1532 /* eth type trans needs skb->data to point to something */
1533 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001534 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001535 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001536 goto next_desc;
1537 }
1538
Bruce Allan5f450212011-07-22 06:21:46 +00001539 e1000_receive_skb(adapter, netdev, skb, staterr,
1540 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001541
1542next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001543 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001544
1545 /* return some buffers to hardware, one at a time is too slow */
1546 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001547 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001548 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001549 cleaned_count = 0;
1550 }
1551
1552 /* use prefetched values */
1553 rx_desc = next_rxd;
1554 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001555
1556 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001557 }
1558 rx_ring->next_to_clean = i;
1559
1560 cleaned_count = e1000_desc_unused(rx_ring);
1561 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001562 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001563
1564 adapter->total_rx_bytes += total_rx_bytes;
1565 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001566 return cleaned;
1567}
1568
1569/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001570 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001571 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001572 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001573static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574{
Bruce Allan55aa6982011-12-16 00:45:45 +00001575 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001576 struct e1000_buffer *buffer_info;
1577 struct e1000_ps_page *ps_page;
1578 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001579 unsigned int i, j;
1580
1581 /* Free all the Rx ring sk_buffs */
1582 for (i = 0; i < rx_ring->count; i++) {
1583 buffer_info = &rx_ring->buffer_info[i];
1584 if (buffer_info->dma) {
1585 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001586 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001587 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001588 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001589 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001590 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001591 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001592 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001593 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001594 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001595 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001596 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001597 buffer_info->dma = 0;
1598 }
1599
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001600 if (buffer_info->page) {
1601 put_page(buffer_info->page);
1602 buffer_info->page = NULL;
1603 }
1604
Auke Kokbc7f75f2007-09-17 12:30:59 -07001605 if (buffer_info->skb) {
1606 dev_kfree_skb(buffer_info->skb);
1607 buffer_info->skb = NULL;
1608 }
1609
1610 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001611 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001612 if (!ps_page->page)
1613 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001614 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1615 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616 ps_page->dma = 0;
1617 put_page(ps_page->page);
1618 ps_page->page = NULL;
1619 }
1620 }
1621
1622 /* there also may be some cached data from a chained receive */
1623 if (rx_ring->rx_skb_top) {
1624 dev_kfree_skb(rx_ring->rx_skb_top);
1625 rx_ring->rx_skb_top = NULL;
1626 }
1627
Auke Kokbc7f75f2007-09-17 12:30:59 -07001628 /* Zero out the descriptor ring */
1629 memset(rx_ring->desc, 0, rx_ring->size);
1630
1631 rx_ring->next_to_clean = 0;
1632 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001633 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634
Bruce Allanc5083cf2011-12-16 00:45:40 +00001635 writel(0, rx_ring->head);
1636 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001637}
1638
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001639static void e1000e_downshift_workaround(struct work_struct *work)
1640{
1641 struct e1000_adapter *adapter = container_of(work,
1642 struct e1000_adapter, downshift_task);
1643
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001644 if (test_bit(__E1000_DOWN, &adapter->state))
1645 return;
1646
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001647 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1648}
1649
Auke Kokbc7f75f2007-09-17 12:30:59 -07001650/**
1651 * e1000_intr_msi - Interrupt Handler
1652 * @irq: interrupt number
1653 * @data: pointer to a network interface device structure
1654 **/
1655static irqreturn_t e1000_intr_msi(int irq, void *data)
1656{
1657 struct net_device *netdev = data;
1658 struct e1000_adapter *adapter = netdev_priv(netdev);
1659 struct e1000_hw *hw = &adapter->hw;
1660 u32 icr = er32(ICR);
1661
Bruce Allanad680762008-03-28 09:15:03 -07001662 /*
1663 * read ICR disables interrupts using IAM
1664 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001665
dave graham573cca82009-02-10 12:52:05 +00001666 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001667 hw->mac.get_link_status = true;
Bruce Allanad680762008-03-28 09:15:03 -07001668 /*
1669 * ICH8 workaround-- Call gig speed drop workaround on cable
1670 * disconnect (LSC) before accessing any PHY registers
1671 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001672 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1673 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001674 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001675
Bruce Allanad680762008-03-28 09:15:03 -07001676 /*
1677 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001679 * adapter in watchdog
1680 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681 if (netif_carrier_ok(netdev) &&
1682 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1683 /* disable receives */
1684 u32 rctl = er32(RCTL);
1685 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001686 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687 }
1688 /* guard against interrupt when we're going down */
1689 if (!test_bit(__E1000_DOWN, &adapter->state))
1690 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1691 }
1692
Ben Hutchings288379f2009-01-19 16:43:59 -08001693 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001694 adapter->total_tx_bytes = 0;
1695 adapter->total_tx_packets = 0;
1696 adapter->total_rx_bytes = 0;
1697 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001698 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001699 }
1700
1701 return IRQ_HANDLED;
1702}
1703
1704/**
1705 * e1000_intr - Interrupt Handler
1706 * @irq: interrupt number
1707 * @data: pointer to a network interface device structure
1708 **/
1709static irqreturn_t e1000_intr(int irq, void *data)
1710{
1711 struct net_device *netdev = data;
1712 struct e1000_adapter *adapter = netdev_priv(netdev);
1713 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001714 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001715
Bruce Allana68ea772009-11-20 23:23:16 +00001716 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717 return IRQ_NONE; /* Not our interrupt */
1718
Bruce Allanad680762008-03-28 09:15:03 -07001719 /*
1720 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1721 * not set, then the adapter didn't send an interrupt
1722 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001723 if (!(icr & E1000_ICR_INT_ASSERTED))
1724 return IRQ_NONE;
1725
Bruce Allanad680762008-03-28 09:15:03 -07001726 /*
1727 * Interrupt Auto-Mask...upon reading ICR,
1728 * interrupts are masked. No need for the
1729 * IMC write
1730 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001731
dave graham573cca82009-02-10 12:52:05 +00001732 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001733 hw->mac.get_link_status = true;
Bruce Allanad680762008-03-28 09:15:03 -07001734 /*
1735 * ICH8 workaround-- Call gig speed drop workaround on cable
1736 * disconnect (LSC) before accessing any PHY registers
1737 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1739 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001740 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741
Bruce Allanad680762008-03-28 09:15:03 -07001742 /*
1743 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001744 * For packet buffer work-around on link down event;
1745 * disable receives here in the ISR and
1746 * reset adapter in watchdog
1747 */
1748 if (netif_carrier_ok(netdev) &&
1749 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1750 /* disable receives */
1751 rctl = er32(RCTL);
1752 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001753 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001754 }
1755 /* guard against interrupt when we're going down */
1756 if (!test_bit(__E1000_DOWN, &adapter->state))
1757 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1758 }
1759
Ben Hutchings288379f2009-01-19 16:43:59 -08001760 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001761 adapter->total_tx_bytes = 0;
1762 adapter->total_tx_packets = 0;
1763 adapter->total_rx_bytes = 0;
1764 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001765 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001766 }
1767
1768 return IRQ_HANDLED;
1769}
1770
Bruce Allan4662e822008-08-26 18:37:06 -07001771static irqreturn_t e1000_msix_other(int irq, void *data)
1772{
1773 struct net_device *netdev = data;
1774 struct e1000_adapter *adapter = netdev_priv(netdev);
1775 struct e1000_hw *hw = &adapter->hw;
1776 u32 icr = er32(ICR);
1777
1778 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001779 if (!test_bit(__E1000_DOWN, &adapter->state))
1780 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001781 return IRQ_NONE;
1782 }
1783
1784 if (icr & adapter->eiac_mask)
1785 ew32(ICS, (icr & adapter->eiac_mask));
1786
1787 if (icr & E1000_ICR_OTHER) {
1788 if (!(icr & E1000_ICR_LSC))
1789 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001790 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001791 /* guard against interrupt when we're going down */
1792 if (!test_bit(__E1000_DOWN, &adapter->state))
1793 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1794 }
1795
1796no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001797 if (!test_bit(__E1000_DOWN, &adapter->state))
1798 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001799
1800 return IRQ_HANDLED;
1801}
1802
1803
1804static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1805{
1806 struct net_device *netdev = data;
1807 struct e1000_adapter *adapter = netdev_priv(netdev);
1808 struct e1000_hw *hw = &adapter->hw;
1809 struct e1000_ring *tx_ring = adapter->tx_ring;
1810
1811
1812 adapter->total_tx_bytes = 0;
1813 adapter->total_tx_packets = 0;
1814
Bruce Allan55aa6982011-12-16 00:45:45 +00001815 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001816 /* Ring was not completely cleaned, so fire another interrupt */
1817 ew32(ICS, tx_ring->ims_val);
1818
1819 return IRQ_HANDLED;
1820}
1821
1822static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1823{
1824 struct net_device *netdev = data;
1825 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001826 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001827
1828 /* Write the ITR value calculated at the end of the
1829 * previous interrupt.
1830 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001831 if (rx_ring->set_itr) {
1832 writel(1000000000 / (rx_ring->itr_val * 256),
1833 rx_ring->itr_register);
1834 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001835 }
1836
Ben Hutchings288379f2009-01-19 16:43:59 -08001837 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001838 adapter->total_rx_bytes = 0;
1839 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001840 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001841 }
1842 return IRQ_HANDLED;
1843}
1844
1845/**
1846 * e1000_configure_msix - Configure MSI-X hardware
1847 *
1848 * e1000_configure_msix sets up the hardware to properly
1849 * generate MSI-X interrupts.
1850 **/
1851static void e1000_configure_msix(struct e1000_adapter *adapter)
1852{
1853 struct e1000_hw *hw = &adapter->hw;
1854 struct e1000_ring *rx_ring = adapter->rx_ring;
1855 struct e1000_ring *tx_ring = adapter->tx_ring;
1856 int vector = 0;
1857 u32 ctrl_ext, ivar = 0;
1858
1859 adapter->eiac_mask = 0;
1860
1861 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1862 if (hw->mac.type == e1000_82574) {
1863 u32 rfctl = er32(RFCTL);
1864 rfctl |= E1000_RFCTL_ACK_DIS;
1865 ew32(RFCTL, rfctl);
1866 }
1867
1868#define E1000_IVAR_INT_ALLOC_VALID 0x8
1869 /* Configure Rx vector */
1870 rx_ring->ims_val = E1000_IMS_RXQ0;
1871 adapter->eiac_mask |= rx_ring->ims_val;
1872 if (rx_ring->itr_val)
1873 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001874 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001875 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001876 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001877 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1878
1879 /* Configure Tx vector */
1880 tx_ring->ims_val = E1000_IMS_TXQ0;
1881 vector++;
1882 if (tx_ring->itr_val)
1883 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001884 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001885 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001886 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001887 adapter->eiac_mask |= tx_ring->ims_val;
1888 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1889
1890 /* set vector for Other Causes, e.g. link changes */
1891 vector++;
1892 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1893 if (rx_ring->itr_val)
1894 writel(1000000000 / (rx_ring->itr_val * 256),
1895 hw->hw_addr + E1000_EITR_82574(vector));
1896 else
1897 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1898
1899 /* Cause Tx interrupts on every write back */
1900 ivar |= (1 << 31);
1901
1902 ew32(IVAR, ivar);
1903
1904 /* enable MSI-X PBA support */
1905 ctrl_ext = er32(CTRL_EXT);
1906 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1907
1908 /* Auto-Mask Other interrupts upon ICR read */
1909#define E1000_EIAC_MASK_82574 0x01F00000
1910 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1911 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1912 ew32(CTRL_EXT, ctrl_ext);
1913 e1e_flush();
1914}
1915
1916void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1917{
1918 if (adapter->msix_entries) {
1919 pci_disable_msix(adapter->pdev);
1920 kfree(adapter->msix_entries);
1921 adapter->msix_entries = NULL;
1922 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1923 pci_disable_msi(adapter->pdev);
1924 adapter->flags &= ~FLAG_MSI_ENABLED;
1925 }
Bruce Allan4662e822008-08-26 18:37:06 -07001926}
1927
1928/**
1929 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1930 *
1931 * Attempt to configure interrupts using the best available
1932 * capabilities of the hardware and kernel.
1933 **/
1934void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1935{
1936 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001937 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001938
1939 switch (adapter->int_mode) {
1940 case E1000E_INT_MODE_MSIX:
1941 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001942 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1943 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001944 sizeof(struct msix_entry),
1945 GFP_KERNEL);
1946 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001947 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001948 adapter->msix_entries[i].entry = i;
1949
1950 err = pci_enable_msix(adapter->pdev,
1951 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001952 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001953 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001954 return;
1955 }
1956 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00001957 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001958 e1000e_reset_interrupt_capability(adapter);
1959 }
1960 adapter->int_mode = E1000E_INT_MODE_MSI;
1961 /* Fall through */
1962 case E1000E_INT_MODE_MSI:
1963 if (!pci_enable_msi(adapter->pdev)) {
1964 adapter->flags |= FLAG_MSI_ENABLED;
1965 } else {
1966 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00001967 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001968 }
1969 /* Fall through */
1970 case E1000E_INT_MODE_LEGACY:
1971 /* Don't do anything; this is the system default */
1972 break;
1973 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001974
1975 /* store the number of vectors being used */
1976 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001977}
1978
1979/**
1980 * e1000_request_msix - Initialize MSI-X interrupts
1981 *
1982 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1983 * kernel.
1984 **/
1985static int e1000_request_msix(struct e1000_adapter *adapter)
1986{
1987 struct net_device *netdev = adapter->netdev;
1988 int err = 0, vector = 0;
1989
1990 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001991 snprintf(adapter->rx_ring->name,
1992 sizeof(adapter->rx_ring->name) - 1,
1993 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001994 else
1995 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1996 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001997 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001998 netdev);
1999 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002000 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002001 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2002 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002003 adapter->rx_ring->itr_val = adapter->itr;
2004 vector++;
2005
2006 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002007 snprintf(adapter->tx_ring->name,
2008 sizeof(adapter->tx_ring->name) - 1,
2009 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002010 else
2011 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2012 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002013 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002014 netdev);
2015 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002016 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002017 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2018 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002019 adapter->tx_ring->itr_val = adapter->itr;
2020 vector++;
2021
2022 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002023 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002024 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002025 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002026
2027 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002028
Bruce Allan4662e822008-08-26 18:37:06 -07002029 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002030}
2031
Bruce Allanf8d59f72008-08-08 18:36:11 -07002032/**
2033 * e1000_request_irq - initialize interrupts
2034 *
2035 * Attempts to configure interrupts using the best available
2036 * capabilities of the hardware and kernel.
2037 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002038static int e1000_request_irq(struct e1000_adapter *adapter)
2039{
2040 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002041 int err;
2042
Bruce Allan4662e822008-08-26 18:37:06 -07002043 if (adapter->msix_entries) {
2044 err = e1000_request_msix(adapter);
2045 if (!err)
2046 return err;
2047 /* fall back to MSI */
2048 e1000e_reset_interrupt_capability(adapter);
2049 adapter->int_mode = E1000E_INT_MODE_MSI;
2050 e1000e_set_interrupt_capability(adapter);
2051 }
2052 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002053 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002054 netdev->name, netdev);
2055 if (!err)
2056 return err;
2057
2058 /* fall back to legacy interrupt */
2059 e1000e_reset_interrupt_capability(adapter);
2060 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002061 }
2062
Joe Perchesa0607fd2009-11-18 23:29:17 -08002063 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002064 netdev->name, netdev);
2065 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002066 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002067
2068 return err;
2069}
2070
2071static void e1000_free_irq(struct e1000_adapter *adapter)
2072{
2073 struct net_device *netdev = adapter->netdev;
2074
Bruce Allan4662e822008-08-26 18:37:06 -07002075 if (adapter->msix_entries) {
2076 int vector = 0;
2077
2078 free_irq(adapter->msix_entries[vector].vector, netdev);
2079 vector++;
2080
2081 free_irq(adapter->msix_entries[vector].vector, netdev);
2082 vector++;
2083
2084 /* Other Causes interrupt vector */
2085 free_irq(adapter->msix_entries[vector].vector, netdev);
2086 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002087 }
Bruce Allan4662e822008-08-26 18:37:06 -07002088
2089 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002090}
2091
2092/**
2093 * e1000_irq_disable - Mask off interrupt generation on the NIC
2094 **/
2095static void e1000_irq_disable(struct e1000_adapter *adapter)
2096{
2097 struct e1000_hw *hw = &adapter->hw;
2098
Auke Kokbc7f75f2007-09-17 12:30:59 -07002099 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002100 if (adapter->msix_entries)
2101 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002102 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002103
2104 if (adapter->msix_entries) {
2105 int i;
2106 for (i = 0; i < adapter->num_vectors; i++)
2107 synchronize_irq(adapter->msix_entries[i].vector);
2108 } else {
2109 synchronize_irq(adapter->pdev->irq);
2110 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002111}
2112
2113/**
2114 * e1000_irq_enable - Enable default interrupt generation settings
2115 **/
2116static void e1000_irq_enable(struct e1000_adapter *adapter)
2117{
2118 struct e1000_hw *hw = &adapter->hw;
2119
Bruce Allan4662e822008-08-26 18:37:06 -07002120 if (adapter->msix_entries) {
2121 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2122 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2123 } else {
2124 ew32(IMS, IMS_ENABLE_MASK);
2125 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002126 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002127}
2128
2129/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002130 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002131 * @adapter: address of board private structure
2132 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002133 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002134 * For ASF and Pass Through versions of f/w this means that
2135 * the driver is loaded. For AMT version (only with 82573)
2136 * of the f/w this means that the network i/f is open.
2137 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002138void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002139{
2140 struct e1000_hw *hw = &adapter->hw;
2141 u32 ctrl_ext;
2142 u32 swsm;
2143
2144 /* Let firmware know the driver has taken over */
2145 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2146 swsm = er32(SWSM);
2147 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2148 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2149 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002150 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002151 }
2152}
2153
2154/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002155 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002156 * @adapter: address of board private structure
2157 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002158 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002159 * For ASF and Pass Through versions of f/w this means that the
2160 * driver is no longer loaded. For AMT version (only with 82573) i
2161 * of the f/w this means that the network i/f is closed.
2162 *
2163 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002164void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002165{
2166 struct e1000_hw *hw = &adapter->hw;
2167 u32 ctrl_ext;
2168 u32 swsm;
2169
2170 /* Let firmware taken over control of h/w */
2171 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2172 swsm = er32(SWSM);
2173 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2174 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2175 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002176 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002177 }
2178}
2179
Auke Kokbc7f75f2007-09-17 12:30:59 -07002180/**
2181 * @e1000_alloc_ring - allocate memory for a ring structure
2182 **/
2183static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2184 struct e1000_ring *ring)
2185{
2186 struct pci_dev *pdev = adapter->pdev;
2187
2188 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2189 GFP_KERNEL);
2190 if (!ring->desc)
2191 return -ENOMEM;
2192
2193 return 0;
2194}
2195
2196/**
2197 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002198 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002199 *
2200 * Return 0 on success, negative on failure
2201 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002202int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002203{
Bruce Allan55aa6982011-12-16 00:45:45 +00002204 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002205 int err = -ENOMEM, size;
2206
2207 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002208 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002209 if (!tx_ring->buffer_info)
2210 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002211
2212 /* round up to nearest 4K */
2213 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2214 tx_ring->size = ALIGN(tx_ring->size, 4096);
2215
2216 err = e1000_alloc_ring_dma(adapter, tx_ring);
2217 if (err)
2218 goto err;
2219
2220 tx_ring->next_to_use = 0;
2221 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002222
2223 return 0;
2224err:
2225 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002226 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002227 return err;
2228}
2229
2230/**
2231 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002232 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002233 *
2234 * Returns 0 on success, negative on failure
2235 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002236int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002237{
Bruce Allan55aa6982011-12-16 00:45:45 +00002238 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002239 struct e1000_buffer *buffer_info;
2240 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002241
2242 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002243 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244 if (!rx_ring->buffer_info)
2245 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002246
Auke Kok47f44e42007-10-25 13:57:44 -07002247 for (i = 0; i < rx_ring->count; i++) {
2248 buffer_info = &rx_ring->buffer_info[i];
2249 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2250 sizeof(struct e1000_ps_page),
2251 GFP_KERNEL);
2252 if (!buffer_info->ps_pages)
2253 goto err_pages;
2254 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002255
2256 desc_len = sizeof(union e1000_rx_desc_packet_split);
2257
2258 /* Round up to nearest 4K */
2259 rx_ring->size = rx_ring->count * desc_len;
2260 rx_ring->size = ALIGN(rx_ring->size, 4096);
2261
2262 err = e1000_alloc_ring_dma(adapter, rx_ring);
2263 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002264 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002265
2266 rx_ring->next_to_clean = 0;
2267 rx_ring->next_to_use = 0;
2268 rx_ring->rx_skb_top = NULL;
2269
2270 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002271
2272err_pages:
2273 for (i = 0; i < rx_ring->count; i++) {
2274 buffer_info = &rx_ring->buffer_info[i];
2275 kfree(buffer_info->ps_pages);
2276 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002277err:
2278 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002279 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002280 return err;
2281}
2282
2283/**
2284 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002285 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002286 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002287static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288{
Bruce Allan55aa6982011-12-16 00:45:45 +00002289 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002290 struct e1000_buffer *buffer_info;
2291 unsigned long size;
2292 unsigned int i;
2293
2294 for (i = 0; i < tx_ring->count; i++) {
2295 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002296 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002297 }
2298
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002299 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002300 size = sizeof(struct e1000_buffer) * tx_ring->count;
2301 memset(tx_ring->buffer_info, 0, size);
2302
2303 memset(tx_ring->desc, 0, tx_ring->size);
2304
2305 tx_ring->next_to_use = 0;
2306 tx_ring->next_to_clean = 0;
2307
Bruce Allanc5083cf2011-12-16 00:45:40 +00002308 writel(0, tx_ring->head);
2309 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002310}
2311
2312/**
2313 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002314 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002315 *
2316 * Free all transmit software resources
2317 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002318void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319{
Bruce Allan55aa6982011-12-16 00:45:45 +00002320 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002321 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002322
Bruce Allan55aa6982011-12-16 00:45:45 +00002323 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324
2325 vfree(tx_ring->buffer_info);
2326 tx_ring->buffer_info = NULL;
2327
2328 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2329 tx_ring->dma);
2330 tx_ring->desc = NULL;
2331}
2332
2333/**
2334 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002335 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002336 *
2337 * Free all receive software resources
2338 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002339void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002340{
Bruce Allan55aa6982011-12-16 00:45:45 +00002341 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002342 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002343 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344
Bruce Allan55aa6982011-12-16 00:45:45 +00002345 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002346
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002347 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002348 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002349
Auke Kokbc7f75f2007-09-17 12:30:59 -07002350 vfree(rx_ring->buffer_info);
2351 rx_ring->buffer_info = NULL;
2352
Auke Kokbc7f75f2007-09-17 12:30:59 -07002353 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2354 rx_ring->dma);
2355 rx_ring->desc = NULL;
2356}
2357
2358/**
2359 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002360 * @adapter: pointer to adapter
2361 * @itr_setting: current adapter->itr
2362 * @packets: the number of packets during this measurement interval
2363 * @bytes: the number of bytes during this measurement interval
2364 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365 * Stores a new ITR value based on packets and byte
2366 * counts during the last interrupt. The advantage of per interrupt
2367 * computation is faster updates and more accurate ITR for the current
2368 * traffic pattern. Constants in this function were computed
2369 * based on theoretical maximum wire speed and thresholds were set based
2370 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002371 * while increasing bulk throughput. This functionality is controlled
2372 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373 **/
2374static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2375 u16 itr_setting, int packets,
2376 int bytes)
2377{
2378 unsigned int retval = itr_setting;
2379
2380 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002381 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382
2383 switch (itr_setting) {
2384 case lowest_latency:
2385 /* handle TSO and jumbo frames */
2386 if (bytes/packets > 8000)
2387 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002388 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002390 break;
2391 case low_latency: /* 50 usec aka 20000 ints/s */
2392 if (bytes > 10000) {
2393 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002394 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002395 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002396 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002397 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002398 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002399 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002400 } else if (bytes/packets > 2000) {
2401 retval = bulk_latency;
2402 } else if (packets <= 2 && bytes < 512) {
2403 retval = lowest_latency;
2404 }
2405 break;
2406 case bulk_latency: /* 250 usec aka 4000 ints/s */
2407 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002408 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002409 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410 } else if (bytes < 6000) {
2411 retval = low_latency;
2412 }
2413 break;
2414 }
2415
Auke Kokbc7f75f2007-09-17 12:30:59 -07002416 return retval;
2417}
2418
2419static void e1000_set_itr(struct e1000_adapter *adapter)
2420{
2421 struct e1000_hw *hw = &adapter->hw;
2422 u16 current_itr;
2423 u32 new_itr = adapter->itr;
2424
2425 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2426 if (adapter->link_speed != SPEED_1000) {
2427 current_itr = 0;
2428 new_itr = 4000;
2429 goto set_itr_now;
2430 }
2431
Bruce Allan828bac82010-09-29 21:39:37 +00002432 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2433 new_itr = 0;
2434 goto set_itr_now;
2435 }
2436
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437 adapter->tx_itr = e1000_update_itr(adapter,
2438 adapter->tx_itr,
2439 adapter->total_tx_packets,
2440 adapter->total_tx_bytes);
2441 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2442 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2443 adapter->tx_itr = low_latency;
2444
2445 adapter->rx_itr = e1000_update_itr(adapter,
2446 adapter->rx_itr,
2447 adapter->total_rx_packets,
2448 adapter->total_rx_bytes);
2449 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2450 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2451 adapter->rx_itr = low_latency;
2452
2453 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2454
2455 switch (current_itr) {
2456 /* counts and packets in update_itr are dependent on these numbers */
2457 case lowest_latency:
2458 new_itr = 70000;
2459 break;
2460 case low_latency:
2461 new_itr = 20000; /* aka hwitr = ~200 */
2462 break;
2463 case bulk_latency:
2464 new_itr = 4000;
2465 break;
2466 default:
2467 break;
2468 }
2469
2470set_itr_now:
2471 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002472 /*
2473 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002474 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002475 * increasing
2476 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002477 new_itr = new_itr > adapter->itr ?
2478 min(adapter->itr + (new_itr >> 2), new_itr) :
2479 new_itr;
2480 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002481 adapter->rx_ring->itr_val = new_itr;
2482 if (adapter->msix_entries)
2483 adapter->rx_ring->set_itr = 1;
2484 else
Bruce Allan828bac82010-09-29 21:39:37 +00002485 if (new_itr)
2486 ew32(ITR, 1000000000 / (new_itr * 256));
2487 else
2488 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002489 }
2490}
2491
2492/**
Bruce Allan4662e822008-08-26 18:37:06 -07002493 * e1000_alloc_queues - Allocate memory for all rings
2494 * @adapter: board private structure to initialize
2495 **/
2496static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2497{
Bruce Allan55aa6982011-12-16 00:45:45 +00002498 int size = sizeof(struct e1000_ring);
2499
2500 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002501 if (!adapter->tx_ring)
2502 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002503 adapter->tx_ring->count = adapter->tx_ring_count;
2504 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002505
Bruce Allan55aa6982011-12-16 00:45:45 +00002506 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002507 if (!adapter->rx_ring)
2508 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002509 adapter->rx_ring->count = adapter->rx_ring_count;
2510 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002511
2512 return 0;
2513err:
2514 e_err("Unable to allocate memory for queues\n");
2515 kfree(adapter->rx_ring);
2516 kfree(adapter->tx_ring);
2517 return -ENOMEM;
2518}
2519
2520/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002522 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002523 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002524 **/
2525static int e1000_clean(struct napi_struct *napi, int budget)
2526{
2527 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002528 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002529 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002530 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002531
Wang Chen4cf16532008-11-12 23:38:14 -08002532 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002533
Bruce Allan4662e822008-08-26 18:37:06 -07002534 if (adapter->msix_entries &&
2535 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2536 goto clean_rx;
2537
Bruce Allan55aa6982011-12-16 00:45:45 +00002538 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002539
Bruce Allan4662e822008-08-26 18:37:06 -07002540clean_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00002541 adapter->clean_rx(adapter->rx_ring, &work_done, budget);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002542
Alexander Duyck12d04a32009-03-25 22:05:03 +00002543 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002544 work_done = budget;
2545
David S. Miller53e52c72008-01-07 21:06:12 -08002546 /* If budget not fully consumed, exit the polling mode */
2547 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002548 if (adapter->itr_setting & 3)
2549 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002550 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002551 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2552 if (adapter->msix_entries)
2553 ew32(IMS, adapter->rx_ring->ims_val);
2554 else
2555 e1000_irq_enable(adapter);
2556 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002557 }
2558
2559 return work_done;
2560}
2561
Jiri Pirko8e586132011-12-08 19:52:37 -05002562static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563{
2564 struct e1000_adapter *adapter = netdev_priv(netdev);
2565 struct e1000_hw *hw = &adapter->hw;
2566 u32 vfta, index;
2567
2568 /* don't update vlan cookie if already programmed */
2569 if ((adapter->hw.mng_cookie.status &
2570 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2571 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002572 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002573
Auke Kokbc7f75f2007-09-17 12:30:59 -07002574 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002575 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2576 index = (vid >> 5) & 0x7F;
2577 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2578 vfta |= (1 << (vid & 0x1F));
2579 hw->mac.ops.write_vfta(hw, index, vfta);
2580 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002581
2582 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002583
2584 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002585}
2586
Jiri Pirko8e586132011-12-08 19:52:37 -05002587static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002588{
2589 struct e1000_adapter *adapter = netdev_priv(netdev);
2590 struct e1000_hw *hw = &adapter->hw;
2591 u32 vfta, index;
2592
Auke Kokbc7f75f2007-09-17 12:30:59 -07002593 if ((adapter->hw.mng_cookie.status &
2594 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2595 (vid == adapter->mng_vlan_id)) {
2596 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002597 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002598 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002599 }
2600
2601 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002602 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2603 index = (vid >> 5) & 0x7F;
2604 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2605 vfta &= ~(1 << (vid & 0x1F));
2606 hw->mac.ops.write_vfta(hw, index, vfta);
2607 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002608
2609 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002610
2611 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002612}
2613
2614/**
2615 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2616 * @adapter: board private structure to initialize
2617 **/
2618static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2619{
2620 struct net_device *netdev = adapter->netdev;
2621 struct e1000_hw *hw = &adapter->hw;
2622 u32 rctl;
2623
2624 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2625 /* disable VLAN receive filtering */
2626 rctl = er32(RCTL);
2627 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2628 ew32(RCTL, rctl);
2629
2630 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2631 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2632 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2633 }
2634 }
2635}
2636
2637/**
2638 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2639 * @adapter: board private structure to initialize
2640 **/
2641static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2642{
2643 struct e1000_hw *hw = &adapter->hw;
2644 u32 rctl;
2645
2646 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2647 /* enable VLAN receive filtering */
2648 rctl = er32(RCTL);
2649 rctl |= E1000_RCTL_VFE;
2650 rctl &= ~E1000_RCTL_CFIEN;
2651 ew32(RCTL, rctl);
2652 }
2653}
2654
2655/**
2656 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2657 * @adapter: board private structure to initialize
2658 **/
2659static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2660{
2661 struct e1000_hw *hw = &adapter->hw;
2662 u32 ctrl;
2663
2664 /* disable VLAN tag insert/strip */
2665 ctrl = er32(CTRL);
2666 ctrl &= ~E1000_CTRL_VME;
2667 ew32(CTRL, ctrl);
2668}
2669
2670/**
2671 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2672 * @adapter: board private structure to initialize
2673 **/
2674static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2675{
2676 struct e1000_hw *hw = &adapter->hw;
2677 u32 ctrl;
2678
2679 /* enable VLAN tag insert/strip */
2680 ctrl = er32(CTRL);
2681 ctrl |= E1000_CTRL_VME;
2682 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002683}
2684
2685static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2686{
2687 struct net_device *netdev = adapter->netdev;
2688 u16 vid = adapter->hw.mng_cookie.vlan_id;
2689 u16 old_vid = adapter->mng_vlan_id;
2690
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002691 if (adapter->hw.mng_cookie.status &
2692 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2693 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694 adapter->mng_vlan_id = vid;
2695 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002696
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002697 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2698 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002699}
2700
2701static void e1000_restore_vlan(struct e1000_adapter *adapter)
2702{
2703 u16 vid;
2704
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002705 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002706
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002707 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002708 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002709}
2710
Bruce Allancd791612010-05-10 14:59:51 +00002711static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002712{
2713 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002714 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002715
2716 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2717 return;
2718
2719 manc = er32(MANC);
2720
Bruce Allanad680762008-03-28 09:15:03 -07002721 /*
2722 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002723 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002724 * the packets will be handled on SMBUS
2725 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002726 manc |= E1000_MANC_EN_MNG2HOST;
2727 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002728
2729 switch (hw->mac.type) {
2730 default:
2731 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2732 break;
2733 case e1000_82574:
2734 case e1000_82583:
2735 /*
2736 * Check if IPMI pass-through decision filter already exists;
2737 * if so, enable it.
2738 */
2739 for (i = 0, j = 0; i < 8; i++) {
2740 mdef = er32(MDEF(i));
2741
2742 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002743 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002744 continue;
2745
2746 /* Enable this decision filter in MANC2H */
2747 if (mdef)
2748 manc2h |= (1 << i);
2749
2750 j |= mdef;
2751 }
2752
2753 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2754 break;
2755
2756 /* Create new decision filter in an empty filter */
2757 for (i = 0, j = 0; i < 8; i++)
2758 if (er32(MDEF(i)) == 0) {
2759 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2760 E1000_MDEF_PORT_664));
2761 manc2h |= (1 << 1);
2762 j++;
2763 break;
2764 }
2765
2766 if (!j)
2767 e_warn("Unable to create IPMI pass-through filter\n");
2768 break;
2769 }
2770
Auke Kokbc7f75f2007-09-17 12:30:59 -07002771 ew32(MANC2H, manc2h);
2772 ew32(MANC, manc);
2773}
2774
2775/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002776 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002777 * @adapter: board private structure
2778 *
2779 * Configure the Tx unit of the MAC after a reset.
2780 **/
2781static void e1000_configure_tx(struct e1000_adapter *adapter)
2782{
2783 struct e1000_hw *hw = &adapter->hw;
2784 struct e1000_ring *tx_ring = adapter->tx_ring;
2785 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002786 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787
2788 /* Setup the HW Tx Head and Tail descriptor pointers */
2789 tdba = tx_ring->dma;
2790 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002791 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002792 ew32(TDBAH, (tdba >> 32));
2793 ew32(TDLEN, tdlen);
2794 ew32(TDH, 0);
2795 ew32(TDT, 0);
Bruce Allanc5083cf2011-12-16 00:45:40 +00002796 tx_ring->head = adapter->hw.hw_addr + E1000_TDH;
2797 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002798
Auke Kokbc7f75f2007-09-17 12:30:59 -07002799 /* Set the Tx Interrupt Delay register */
2800 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002801 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002802 ew32(TADV, adapter->tx_abs_int_delay);
2803
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002804 if (adapter->flags2 & FLAG2_DMA_BURST) {
2805 u32 txdctl = er32(TXDCTL(0));
2806 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2807 E1000_TXDCTL_WTHRESH);
2808 /*
2809 * set up some performance related parameters to encourage the
2810 * hardware to use the bus more efficiently in bursts, depends
2811 * on the tx_int_delay to be enabled,
2812 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2813 * hthresh = 1 ==> prefetch when one or more available
2814 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2815 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002816 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002817 */
2818 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2819 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002820 }
Bruce Allan56032be2011-12-16 00:46:01 +00002821 /* erratum work around: set txdctl the same for both queues */
2822 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002823
Auke Kokbc7f75f2007-09-17 12:30:59 -07002824 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002825 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002826 /*
2827 * set the speed mode bit, we'll clear it if we're not at
2828 * gigabit link later
2829 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002830#define SPEED_MODE_BIT (1 << 21)
2831 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002832 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833 }
2834
2835 /* errata: program both queues to unweighted RR */
2836 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002837 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002839 ew32(TARC(0), tarc);
2840 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002841 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002842 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002843 }
2844
Auke Kokbc7f75f2007-09-17 12:30:59 -07002845 /* Setup Transmit Descriptor Settings for eop descriptor */
2846 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2847
2848 /* only set IDE if we are delaying interrupts using the timers */
2849 if (adapter->tx_int_delay)
2850 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2851
2852 /* enable Report Status bit */
2853 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2854
Simon Hormanedfea6e62009-06-08 14:28:36 +00002855 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002856}
2857
2858/**
2859 * e1000_setup_rctl - configure the receive control registers
2860 * @adapter: Board private structure
2861 **/
2862#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2863 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2864static void e1000_setup_rctl(struct e1000_adapter *adapter)
2865{
2866 struct e1000_hw *hw = &adapter->hw;
2867 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002868 u32 pages = 0;
2869
Bruce Allana1ce6472010-09-22 17:16:40 +00002870 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2871 if (hw->mac.type == e1000_pch2lan) {
2872 s32 ret_val;
2873
2874 if (adapter->netdev->mtu > ETH_DATA_LEN)
2875 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2876 else
2877 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002878
2879 if (ret_val)
2880 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002881 }
2882
Auke Kokbc7f75f2007-09-17 12:30:59 -07002883 /* Program MC offset vector base */
2884 rctl = er32(RCTL);
2885 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2886 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2887 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2888 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2889
2890 /* Do not Store bad packets */
2891 rctl &= ~E1000_RCTL_SBP;
2892
2893 /* Enable Long Packet receive */
2894 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2895 rctl &= ~E1000_RCTL_LPE;
2896 else
2897 rctl |= E1000_RCTL_LPE;
2898
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002899 /* Some systems expect that the CRC is included in SMBUS traffic. The
2900 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2901 * host memory when this is enabled
2902 */
2903 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2904 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002905
Bruce Allana4f58f52009-06-02 11:29:18 +00002906 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2907 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2908 u16 phy_data;
2909
2910 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2911 phy_data &= 0xfff8;
2912 phy_data |= (1 << 2);
2913 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2914
2915 e1e_rphy(hw, 22, &phy_data);
2916 phy_data &= 0x0fff;
2917 phy_data |= (1 << 14);
2918 e1e_wphy(hw, 0x10, 0x2823);
2919 e1e_wphy(hw, 0x11, 0x0003);
2920 e1e_wphy(hw, 22, phy_data);
2921 }
2922
Auke Kokbc7f75f2007-09-17 12:30:59 -07002923 /* Setup buffer sizes */
2924 rctl &= ~E1000_RCTL_SZ_4096;
2925 rctl |= E1000_RCTL_BSEX;
2926 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002927 case 2048:
2928 default:
2929 rctl |= E1000_RCTL_SZ_2048;
2930 rctl &= ~E1000_RCTL_BSEX;
2931 break;
2932 case 4096:
2933 rctl |= E1000_RCTL_SZ_4096;
2934 break;
2935 case 8192:
2936 rctl |= E1000_RCTL_SZ_8192;
2937 break;
2938 case 16384:
2939 rctl |= E1000_RCTL_SZ_16384;
2940 break;
2941 }
2942
Bruce Allan5f450212011-07-22 06:21:46 +00002943 /* Enable Extended Status in all Receive Descriptors */
2944 rfctl = er32(RFCTL);
2945 rfctl |= E1000_RFCTL_EXTEN;
2946
Auke Kokbc7f75f2007-09-17 12:30:59 -07002947 /*
2948 * 82571 and greater support packet-split where the protocol
2949 * header is placed in skb->data and the packet data is
2950 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2951 * In the case of a non-split, skb->data is linearly filled,
2952 * followed by the page buffers. Therefore, skb->data is
2953 * sized to hold the largest protocol header.
2954 *
2955 * allocations using alloc_page take too long for regular MTU
2956 * so only enable packet split for jumbo frames
2957 *
2958 * Using pages when the page size is greater than 16k wastes
2959 * a lot of memory, since we allocate 3 pages at all times
2960 * per packet.
2961 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002962 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00002963 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002965 else
2966 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002967
2968 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002969 u32 psrctl = 0;
2970
Bruce Allanad680762008-03-28 09:15:03 -07002971 /*
2972 * disable packet split support for IPv6 extension headers,
2973 * because some malformed IPv6 headers can hang the Rx
2974 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002975 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2976 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2977
Auke Kok140a7482007-10-25 13:57:58 -07002978 /* Enable Packet split descriptors */
2979 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002980
2981 psrctl |= adapter->rx_ps_bsize0 >>
2982 E1000_PSRCTL_BSIZE0_SHIFT;
2983
2984 switch (adapter->rx_ps_pages) {
2985 case 3:
2986 psrctl |= PAGE_SIZE <<
2987 E1000_PSRCTL_BSIZE3_SHIFT;
2988 case 2:
2989 psrctl |= PAGE_SIZE <<
2990 E1000_PSRCTL_BSIZE2_SHIFT;
2991 case 1:
2992 psrctl |= PAGE_SIZE >>
2993 E1000_PSRCTL_BSIZE1_SHIFT;
2994 break;
2995 }
2996
2997 ew32(PSRCTL, psrctl);
2998 }
2999
Bruce Allan5f450212011-07-22 06:21:46 +00003000 ew32(RFCTL, rfctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003001 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003002 /* just started the receive unit, no need to restart */
3003 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003004}
3005
3006/**
3007 * e1000_configure_rx - Configure Receive Unit after Reset
3008 * @adapter: board private structure
3009 *
3010 * Configure the Rx unit of the MAC after a reset.
3011 **/
3012static void e1000_configure_rx(struct e1000_adapter *adapter)
3013{
3014 struct e1000_hw *hw = &adapter->hw;
3015 struct e1000_ring *rx_ring = adapter->rx_ring;
3016 u64 rdba;
3017 u32 rdlen, rctl, rxcsum, ctrl_ext;
3018
3019 if (adapter->rx_ps_pages) {
3020 /* this is a 32 byte descriptor */
3021 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003022 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003023 adapter->clean_rx = e1000_clean_rx_irq_ps;
3024 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003025 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003026 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003027 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3028 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003029 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003030 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003031 adapter->clean_rx = e1000_clean_rx_irq;
3032 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3033 }
3034
3035 /* disable receives while setting up the descriptors */
3036 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003037 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3038 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003039 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003040 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003041
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003042 if (adapter->flags2 & FLAG2_DMA_BURST) {
3043 /*
3044 * set the writeback threshold (only takes effect if the RDTR
3045 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003046 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003047 * granularity = 01
3048 * wthresh = 04,
3049 * hthresh = 04,
3050 * pthresh = 0x20
3051 */
3052 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3053 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3054
3055 /*
3056 * override the delay timers for enabling bursting, only if
3057 * the value was not set by the user via module options
3058 */
3059 if (adapter->rx_int_delay == DEFAULT_RDTR)
3060 adapter->rx_int_delay = BURST_RDTR;
3061 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3062 adapter->rx_abs_int_delay = BURST_RADV;
3063 }
3064
Auke Kokbc7f75f2007-09-17 12:30:59 -07003065 /* set the Receive Delay Timer Register */
3066 ew32(RDTR, adapter->rx_int_delay);
3067
3068 /* irq moderation */
3069 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003070 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003071 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003072
3073 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003074 /* Auto-Mask interrupts upon ICR access */
3075 ctrl_ext |= E1000_CTRL_EXT_IAME;
3076 ew32(IAM, 0xffffffff);
3077 ew32(CTRL_EXT, ctrl_ext);
3078 e1e_flush();
3079
Bruce Allanad680762008-03-28 09:15:03 -07003080 /*
3081 * Setup the HW Rx Head and Tail Descriptor Pointers and
3082 * the Base and Length of the Rx Descriptor Ring
3083 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003084 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07003085 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003086 ew32(RDBAH, (rdba >> 32));
3087 ew32(RDLEN, rdlen);
3088 ew32(RDH, 0);
3089 ew32(RDT, 0);
Bruce Allanc5083cf2011-12-16 00:45:40 +00003090 rx_ring->head = adapter->hw.hw_addr + E1000_RDH;
3091 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003092
3093 /* Enable Receive Checksum Offload for TCP and UDP */
3094 rxcsum = er32(RXCSUM);
Bruce Allandc221292011-08-19 03:23:48 +00003095 if (adapter->netdev->features & NETIF_F_RXCSUM) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096 rxcsum |= E1000_RXCSUM_TUOFL;
3097
Bruce Allanad680762008-03-28 09:15:03 -07003098 /*
3099 * IPv4 payload checksum for UDP fragments must be
3100 * used in conjunction with packet-split.
3101 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003102 if (adapter->rx_ps_pages)
3103 rxcsum |= E1000_RXCSUM_IPPCSE;
3104 } else {
3105 rxcsum &= ~E1000_RXCSUM_TUOFL;
3106 /* no need to clear IPPCSE as it defaults to 0 */
3107 }
3108 ew32(RXCSUM, rxcsum);
3109
Bruce Allan79d4e902011-12-16 00:46:27 +00003110 if (adapter->hw.mac.type == e1000_pch2lan) {
3111 /*
3112 * With jumbo frames, excessive C-state transition
3113 * latencies result in dropped transactions.
3114 */
Bruce Allan53ec5492009-11-20 23:27:40 +00003115 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3116 u32 rxdctl = er32(RXDCTL(0));
3117 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allanaf667a22010-12-31 06:10:01 +00003118 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003119 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003120 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3121 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003122 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003123 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003124
3125 /* Enable Receives */
3126 ew32(RCTL, rctl);
3127}
3128
3129/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003130 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003131 * @netdev: network interface device structure
3132 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003133 * Writes multicast address list to the MTA hash table.
3134 * Returns: -ENOMEM on failure
3135 * 0 on no addresses written
3136 * X on writing X addresses to MTA
3137 */
3138static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003139{
3140 struct e1000_adapter *adapter = netdev_priv(netdev);
3141 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003142 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003143 u8 *mta_list;
3144 int i;
3145
3146 if (netdev_mc_empty(netdev)) {
3147 /* nothing to program, so clear mc list */
3148 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3149 return 0;
3150 }
3151
3152 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3153 if (!mta_list)
3154 return -ENOMEM;
3155
3156 /* update_mc_addr_list expects a packed array of only addresses. */
3157 i = 0;
3158 netdev_for_each_mc_addr(ha, netdev)
3159 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3160
3161 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3162 kfree(mta_list);
3163
3164 return netdev_mc_count(netdev);
3165}
3166
3167/**
3168 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3169 * @netdev: network interface device structure
3170 *
3171 * Writes unicast address list to the RAR table.
3172 * Returns: -ENOMEM on failure/insufficient address space
3173 * 0 on no addresses written
3174 * X on writing X addresses to the RAR table
3175 **/
3176static int e1000e_write_uc_addr_list(struct net_device *netdev)
3177{
3178 struct e1000_adapter *adapter = netdev_priv(netdev);
3179 struct e1000_hw *hw = &adapter->hw;
3180 unsigned int rar_entries = hw->mac.rar_entry_count;
3181 int count = 0;
3182
3183 /* save a rar entry for our hardware address */
3184 rar_entries--;
3185
3186 /* save a rar entry for the LAA workaround */
3187 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3188 rar_entries--;
3189
3190 /* return ENOMEM indicating insufficient memory for addresses */
3191 if (netdev_uc_count(netdev) > rar_entries)
3192 return -ENOMEM;
3193
3194 if (!netdev_uc_empty(netdev) && rar_entries) {
3195 struct netdev_hw_addr *ha;
3196
3197 /*
3198 * write the addresses in reverse order to avoid write
3199 * combining
3200 */
3201 netdev_for_each_uc_addr(ha, netdev) {
3202 if (!rar_entries)
3203 break;
3204 e1000e_rar_set(hw, ha->addr, rar_entries--);
3205 count++;
3206 }
3207 }
3208
3209 /* zero out the remaining RAR entries not used above */
3210 for (; rar_entries > 0; rar_entries--) {
3211 ew32(RAH(rar_entries), 0);
3212 ew32(RAL(rar_entries), 0);
3213 }
3214 e1e_flush();
3215
3216 return count;
3217}
3218
3219/**
3220 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3221 * @netdev: network interface device structure
3222 *
3223 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3224 * address list or the network interface flags are updated. This routine is
3225 * responsible for configuring the hardware for proper unicast, multicast,
3226 * promiscuous mode, and all-multi behavior.
3227 **/
3228static void e1000e_set_rx_mode(struct net_device *netdev)
3229{
3230 struct e1000_adapter *adapter = netdev_priv(netdev);
3231 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003232 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003233
3234 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003235 rctl = er32(RCTL);
3236
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003237 /* clear the affected bits */
3238 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3239
Auke Kokbc7f75f2007-09-17 12:30:59 -07003240 if (netdev->flags & IFF_PROMISC) {
3241 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003242 /* Do not hardware filter VLANs in promisc mode */
3243 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003244 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003245 int count;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003246 if (netdev->flags & IFF_ALLMULTI) {
3247 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003248 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003249 /*
3250 * Write addresses to the MTA, if the attempt fails
3251 * then we should just turn on promiscuous mode so
3252 * that we can at least receive multicast traffic
3253 */
3254 count = e1000e_write_mc_addr_list(netdev);
3255 if (count < 0)
3256 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003257 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003258 e1000e_vlan_filter_enable(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003259 /*
3260 * Write addresses to available RAR registers, if there is not
3261 * sufficient space to store all the addresses then enable
3262 * unicast promiscuous mode
3263 */
3264 count = e1000e_write_uc_addr_list(netdev);
3265 if (count < 0)
3266 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003267 }
3268
3269 ew32(RCTL, rctl);
3270
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003271 if (netdev->features & NETIF_F_HW_VLAN_RX)
3272 e1000e_vlan_strip_enable(adapter);
3273 else
3274 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003275}
3276
Bruce Allan70495a52012-01-11 01:26:50 +00003277static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3278{
3279 struct e1000_hw *hw = &adapter->hw;
3280 u32 mrqc, rxcsum;
3281 int i;
3282 static const u32 rsskey[10] = {
3283 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3284 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3285 };
3286
3287 /* Fill out hash function seed */
3288 for (i = 0; i < 10; i++)
3289 ew32(RSSRK(i), rsskey[i]);
3290
3291 /* Direct all traffic to queue 0 */
3292 for (i = 0; i < 32; i++)
3293 ew32(RETA(i), 0);
3294
3295 /*
3296 * Disable raw packet checksumming so that RSS hash is placed in
3297 * descriptor on writeback.
3298 */
3299 rxcsum = er32(RXCSUM);
3300 rxcsum |= E1000_RXCSUM_PCSD;
3301
3302 ew32(RXCSUM, rxcsum);
3303
3304 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3305 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3306 E1000_MRQC_RSS_FIELD_IPV6 |
3307 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3308 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3309
3310 ew32(MRQC, mrqc);
3311}
3312
Auke Kokbc7f75f2007-09-17 12:30:59 -07003313/**
Bruce Allanad680762008-03-28 09:15:03 -07003314 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003315 * @adapter: private board structure
3316 **/
3317static void e1000_configure(struct e1000_adapter *adapter)
3318{
Bruce Allan55aa6982011-12-16 00:45:45 +00003319 struct e1000_ring *rx_ring = adapter->rx_ring;
3320
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003321 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003322
3323 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003324 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325
3326 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003327
3328 if (adapter->netdev->features & NETIF_F_RXHASH)
3329 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003330 e1000_setup_rctl(adapter);
3331 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003332 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003333}
3334
3335/**
3336 * e1000e_power_up_phy - restore link in case the phy was powered down
3337 * @adapter: address of board private structure
3338 *
3339 * The phy may be powered down to save power and turn off link when the
3340 * driver is unloaded and wake on lan is not enabled (among others)
3341 * *** this routine MUST be followed by a call to e1000e_reset ***
3342 **/
3343void e1000e_power_up_phy(struct e1000_adapter *adapter)
3344{
Bruce Allan17f208d2009-12-01 15:47:22 +00003345 if (adapter->hw.phy.ops.power_up)
3346 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003347
3348 adapter->hw.mac.ops.setup_link(&adapter->hw);
3349}
3350
3351/**
3352 * e1000_power_down_phy - Power down the PHY
3353 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003354 * Power down the PHY so no link is implied when interface is down.
3355 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003356 */
3357static void e1000_power_down_phy(struct e1000_adapter *adapter)
3358{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003359 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003360 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003361 return;
3362
Bruce Allan17f208d2009-12-01 15:47:22 +00003363 if (adapter->hw.phy.ops.power_down)
3364 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003365}
3366
3367/**
3368 * e1000e_reset - bring the hardware into a known good state
3369 *
3370 * This function boots the hardware and enables some settings that
3371 * require a configuration cycle of the hardware - those cannot be
3372 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003373 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003374 */
3375void e1000e_reset(struct e1000_adapter *adapter)
3376{
3377 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003378 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003379 struct e1000_hw *hw = &adapter->hw;
3380 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003381 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003382 u16 hwm;
3383
Bruce Allanad680762008-03-28 09:15:03 -07003384 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003385 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003386
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003387 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003388 /*
3389 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003390 * large enough to accommodate two full transmit packets,
3391 * rounded up to the next 1KB and expressed in KB. Likewise,
3392 * the Rx FIFO should be large enough to accommodate at least
3393 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003394 * expressed in KB.
3395 */
Auke Kokdf762462007-10-25 13:57:53 -07003396 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003397 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003398 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003399 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003400 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003401 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003402 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003403 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003404 */
3405 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003406 sizeof(struct e1000_tx_desc) -
3407 ETH_FCS_LEN) * 2;
3408 min_tx_space = ALIGN(min_tx_space, 1024);
3409 min_tx_space >>= 10;
3410 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003411 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003412 min_rx_space = ALIGN(min_rx_space, 1024);
3413 min_rx_space >>= 10;
3414
Bruce Allanad680762008-03-28 09:15:03 -07003415 /*
3416 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003417 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003418 * allocation, take space away from current Rx allocation
3419 */
Auke Kokdf762462007-10-25 13:57:53 -07003420 if ((tx_space < min_tx_space) &&
3421 ((min_tx_space - tx_space) < pba)) {
3422 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003423
Bruce Allanad680762008-03-28 09:15:03 -07003424 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003425 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003426 * adjustment or use Early Receive if available
3427 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003428 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003429 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003430 }
Auke Kokdf762462007-10-25 13:57:53 -07003431
3432 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003433 }
3434
Bruce Allanad680762008-03-28 09:15:03 -07003435 /*
3436 * flow control settings
3437 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003438 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003439 * (or the size used for early receive) above it in the Rx FIFO.
3440 * Set it to the lower of:
3441 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003442 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003443 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003444 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3445 fc->pause_time = 0xFFFF;
3446 else
3447 fc->pause_time = E1000_FC_PAUSE_TIME;
3448 fc->send_xon = 1;
3449 fc->current_mode = fc->requested_mode;
3450
3451 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003452 case e1000_ich9lan:
3453 case e1000_ich10lan:
3454 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3455 pba = 14;
3456 ew32(PBA, pba);
3457 fc->high_water = 0x2800;
3458 fc->low_water = fc->high_water - 8;
3459 break;
3460 }
3461 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003462 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003463 hwm = min(((pba << 10) * 9 / 10),
3464 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003465
3466 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3467 fc->low_water = fc->high_water - 8;
3468 break;
3469 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003470 /*
3471 * Workaround PCH LOM adapter hangs with certain network
3472 * loads. If hangs persist, try disabling Tx flow control.
3473 */
3474 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3475 fc->high_water = 0x3500;
3476 fc->low_water = 0x1500;
3477 } else {
3478 fc->high_water = 0x5000;
3479 fc->low_water = 0x3000;
3480 }
Bruce Allana3055952010-05-10 15:02:12 +00003481 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003482 break;
3483 case e1000_pch2lan:
3484 fc->high_water = 0x05C20;
3485 fc->low_water = 0x05048;
3486 fc->pause_time = 0x0650;
3487 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003488 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3489 pba = 14;
3490 ew32(PBA, pba);
3491 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003492 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003493 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003494
Bruce Allan828bac82010-09-29 21:39:37 +00003495 /*
3496 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003497 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003498 */
3499 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003500 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003501 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3502 dev_info(&adapter->pdev->dev,
3503 "Interrupt Throttle Rate turned off\n");
3504 adapter->flags2 |= FLAG2_DISABLE_AIM;
3505 ew32(ITR, 0);
3506 }
3507 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3508 dev_info(&adapter->pdev->dev,
3509 "Interrupt Throttle Rate turned on\n");
3510 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3511 adapter->itr = 20000;
3512 ew32(ITR, 1000000000 / (adapter->itr * 256));
3513 }
3514 }
3515
Auke Kokbc7f75f2007-09-17 12:30:59 -07003516 /* Allow time for pending master requests to run */
3517 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003518
3519 /*
3520 * For parts with AMT enabled, let the firmware know
3521 * that the network interface is in control
3522 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003523 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003524 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003525
Auke Kokbc7f75f2007-09-17 12:30:59 -07003526 ew32(WUC, 0);
3527
3528 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003529 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003530
3531 e1000_update_mng_vlan(adapter);
3532
3533 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3534 ew32(VET, ETH_P_8021Q);
3535
3536 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003537
3538 if (!netif_running(adapter->netdev) &&
3539 !test_bit(__E1000_TESTING, &adapter->state)) {
3540 e1000_power_down_phy(adapter);
3541 return;
3542 }
3543
Auke Kokbc7f75f2007-09-17 12:30:59 -07003544 e1000_get_phy_info(hw);
3545
Bruce Allan918d7192009-06-02 11:28:20 +00003546 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3547 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003548 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003549 /*
3550 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003551 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003552 * different we would do if it failed
3553 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003554 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3555 phy_data &= ~IGP02E1000_PM_SPD;
3556 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3557 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003558}
3559
3560int e1000e_up(struct e1000_adapter *adapter)
3561{
3562 struct e1000_hw *hw = &adapter->hw;
3563
3564 /* hardware has been reset, we need to reload some things */
3565 e1000_configure(adapter);
3566
3567 clear_bit(__E1000_DOWN, &adapter->state);
3568
Bruce Allan4662e822008-08-26 18:37:06 -07003569 if (adapter->msix_entries)
3570 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003571 e1000_irq_enable(adapter);
3572
Bruce Allan400484f2011-05-13 07:20:03 +00003573 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003574
Auke Kokbc7f75f2007-09-17 12:30:59 -07003575 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003576 if (adapter->msix_entries)
3577 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3578 else
3579 ew32(ICS, E1000_ICS_LSC);
3580
Auke Kokbc7f75f2007-09-17 12:30:59 -07003581 return 0;
3582}
3583
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003584static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3585{
3586 struct e1000_hw *hw = &adapter->hw;
3587
3588 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3589 return;
3590
3591 /* flush pending descriptor writebacks to memory */
3592 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3593 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3594
3595 /* execute the writes immediately */
3596 e1e_flush();
3597}
3598
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003599static void e1000e_update_stats(struct e1000_adapter *adapter);
3600
Auke Kokbc7f75f2007-09-17 12:30:59 -07003601void e1000e_down(struct e1000_adapter *adapter)
3602{
3603 struct net_device *netdev = adapter->netdev;
3604 struct e1000_hw *hw = &adapter->hw;
3605 u32 tctl, rctl;
3606
Bruce Allanad680762008-03-28 09:15:03 -07003607 /*
3608 * signal that we're down so the interrupt handler does not
3609 * reschedule our watchdog timer
3610 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003611 set_bit(__E1000_DOWN, &adapter->state);
3612
3613 /* disable receives in the hardware */
3614 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003615 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3616 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003617 /* flush and sleep below */
3618
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003619 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003620
3621 /* disable transmits in the hardware */
3622 tctl = er32(TCTL);
3623 tctl &= ~E1000_TCTL_EN;
3624 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003625
Auke Kokbc7f75f2007-09-17 12:30:59 -07003626 /* flush both disables and wait for them to finish */
3627 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003628 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003629
Auke Kokbc7f75f2007-09-17 12:30:59 -07003630 e1000_irq_disable(adapter);
3631
3632 del_timer_sync(&adapter->watchdog_timer);
3633 del_timer_sync(&adapter->phy_info_timer);
3634
Auke Kokbc7f75f2007-09-17 12:30:59 -07003635 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003636
3637 spin_lock(&adapter->stats64_lock);
3638 e1000e_update_stats(adapter);
3639 spin_unlock(&adapter->stats64_lock);
3640
Bruce Allan400484f2011-05-13 07:20:03 +00003641 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003642 e1000_clean_tx_ring(adapter->tx_ring);
3643 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00003644
Auke Kokbc7f75f2007-09-17 12:30:59 -07003645 adapter->link_speed = 0;
3646 adapter->link_duplex = 0;
3647
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003648 if (!pci_channel_offline(adapter->pdev))
3649 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003650
Auke Kokbc7f75f2007-09-17 12:30:59 -07003651 /*
3652 * TODO: for power management, we could drop the link and
3653 * pci_disable_device here.
3654 */
3655}
3656
3657void e1000e_reinit_locked(struct e1000_adapter *adapter)
3658{
3659 might_sleep();
3660 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003661 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003662 e1000e_down(adapter);
3663 e1000e_up(adapter);
3664 clear_bit(__E1000_RESETTING, &adapter->state);
3665}
3666
3667/**
3668 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3669 * @adapter: board private structure to initialize
3670 *
3671 * e1000_sw_init initializes the Adapter private data structure.
3672 * Fields are initialized based on PCI device information and
3673 * OS network device settings (MTU size).
3674 **/
3675static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3676{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003677 struct net_device *netdev = adapter->netdev;
3678
3679 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3680 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003681 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3682 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00003683 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3684 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003685
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003686 spin_lock_init(&adapter->stats64_lock);
3687
Bruce Allan4662e822008-08-26 18:37:06 -07003688 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003689
Bruce Allan4662e822008-08-26 18:37:06 -07003690 if (e1000_alloc_queues(adapter))
3691 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003692
Auke Kokbc7f75f2007-09-17 12:30:59 -07003693 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003694 e1000_irq_disable(adapter);
3695
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696 set_bit(__E1000_DOWN, &adapter->state);
3697 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003698}
3699
3700/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003701 * e1000_intr_msi_test - Interrupt Handler
3702 * @irq: interrupt number
3703 * @data: pointer to a network interface device structure
3704 **/
3705static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3706{
3707 struct net_device *netdev = data;
3708 struct e1000_adapter *adapter = netdev_priv(netdev);
3709 struct e1000_hw *hw = &adapter->hw;
3710 u32 icr = er32(ICR);
3711
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003712 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003713 if (icr & E1000_ICR_RXSEQ) {
3714 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3715 wmb();
3716 }
3717
3718 return IRQ_HANDLED;
3719}
3720
3721/**
3722 * e1000_test_msi_interrupt - Returns 0 for successful test
3723 * @adapter: board private struct
3724 *
3725 * code flow taken from tg3.c
3726 **/
3727static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3728{
3729 struct net_device *netdev = adapter->netdev;
3730 struct e1000_hw *hw = &adapter->hw;
3731 int err;
3732
3733 /* poll_enable hasn't been called yet, so don't need disable */
3734 /* clear any pending events */
3735 er32(ICR);
3736
3737 /* free the real vector and request a test handler */
3738 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003739 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003740
3741 /* Assume that the test fails, if it succeeds then the test
3742 * MSI irq handler will unset this flag */
3743 adapter->flags |= FLAG_MSI_TEST_FAILED;
3744
3745 err = pci_enable_msi(adapter->pdev);
3746 if (err)
3747 goto msi_test_failed;
3748
Joe Perchesa0607fd2009-11-18 23:29:17 -08003749 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003750 netdev->name, netdev);
3751 if (err) {
3752 pci_disable_msi(adapter->pdev);
3753 goto msi_test_failed;
3754 }
3755
3756 wmb();
3757
3758 e1000_irq_enable(adapter);
3759
3760 /* fire an unusual interrupt on the test handler */
3761 ew32(ICS, E1000_ICS_RXSEQ);
3762 e1e_flush();
3763 msleep(50);
3764
3765 e1000_irq_disable(adapter);
3766
3767 rmb();
3768
3769 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003770 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003771 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003772 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00003773 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003774 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003775
3776 free_irq(adapter->pdev->irq, netdev);
3777 pci_disable_msi(adapter->pdev);
3778
Bruce Allanf8d59f72008-08-08 18:36:11 -07003779msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003780 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003781 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003782}
3783
3784/**
3785 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3786 * @adapter: board private struct
3787 *
3788 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3789 **/
3790static int e1000_test_msi(struct e1000_adapter *adapter)
3791{
3792 int err;
3793 u16 pci_cmd;
3794
3795 if (!(adapter->flags & FLAG_MSI_ENABLED))
3796 return 0;
3797
3798 /* disable SERR in case the MSI write causes a master abort */
3799 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003800 if (pci_cmd & PCI_COMMAND_SERR)
3801 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3802 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003803
3804 err = e1000_test_msi_interrupt(adapter);
3805
Dean Nelson36f24072010-06-29 18:12:05 +00003806 /* re-enable SERR */
3807 if (pci_cmd & PCI_COMMAND_SERR) {
3808 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3809 pci_cmd |= PCI_COMMAND_SERR;
3810 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3811 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003812
Bruce Allanf8d59f72008-08-08 18:36:11 -07003813 return err;
3814}
3815
3816/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003817 * e1000_open - Called when a network interface is made active
3818 * @netdev: network interface device structure
3819 *
3820 * Returns 0 on success, negative value on failure
3821 *
3822 * The open entry point is called when a network interface is made
3823 * active by the system (IFF_UP). At this point all resources needed
3824 * for transmit and receive operations are allocated, the interrupt
3825 * handler is registered with the OS, the watchdog timer is started,
3826 * and the stack is notified that the interface is ready.
3827 **/
3828static int e1000_open(struct net_device *netdev)
3829{
3830 struct e1000_adapter *adapter = netdev_priv(netdev);
3831 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003832 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003833 int err;
3834
3835 /* disallow open during test */
3836 if (test_bit(__E1000_TESTING, &adapter->state))
3837 return -EBUSY;
3838
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003839 pm_runtime_get_sync(&pdev->dev);
3840
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003841 netif_carrier_off(netdev);
3842
Auke Kokbc7f75f2007-09-17 12:30:59 -07003843 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003844 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003845 if (err)
3846 goto err_setup_tx;
3847
3848 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003849 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003850 if (err)
3851 goto err_setup_rx;
3852
Bruce Allan11b08be2010-05-10 14:59:31 +00003853 /*
3854 * If AMT is enabled, let the firmware know that the network
3855 * interface is now open and reset the part to a known state.
3856 */
3857 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003858 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003859 e1000e_reset(adapter);
3860 }
3861
Auke Kokbc7f75f2007-09-17 12:30:59 -07003862 e1000e_power_up_phy(adapter);
3863
3864 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3865 if ((adapter->hw.mng_cookie.status &
3866 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3867 e1000_update_mng_vlan(adapter);
3868
Bruce Allan79d4e902011-12-16 00:46:27 +00003869 /* DMA latency requirement to workaround jumbo issue */
3870 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07003871 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3872 PM_QOS_CPU_DMA_LATENCY,
3873 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003874
Bruce Allanad680762008-03-28 09:15:03 -07003875 /*
Bruce Allanad680762008-03-28 09:15:03 -07003876 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003877 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3878 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003879 * clean_rx handler before we do so.
3880 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003881 e1000_configure(adapter);
3882
3883 err = e1000_request_irq(adapter);
3884 if (err)
3885 goto err_req_irq;
3886
Bruce Allanf8d59f72008-08-08 18:36:11 -07003887 /*
3888 * Work around PCIe errata with MSI interrupts causing some chipsets to
3889 * ignore e1000e MSI messages, which means we need to test our MSI
3890 * interrupt now
3891 */
Bruce Allan4662e822008-08-26 18:37:06 -07003892 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003893 err = e1000_test_msi(adapter);
3894 if (err) {
3895 e_err("Interrupt allocation failed\n");
3896 goto err_req_irq;
3897 }
3898 }
3899
Auke Kokbc7f75f2007-09-17 12:30:59 -07003900 /* From here on the code is the same as e1000e_up() */
3901 clear_bit(__E1000_DOWN, &adapter->state);
3902
3903 napi_enable(&adapter->napi);
3904
3905 e1000_irq_enable(adapter);
3906
Jeff Kirsher09357b02011-11-18 14:25:00 +00003907 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003908 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003909
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003910 adapter->idle_check = true;
3911 pm_runtime_put(&pdev->dev);
3912
Auke Kokbc7f75f2007-09-17 12:30:59 -07003913 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003914 if (adapter->msix_entries)
3915 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3916 else
3917 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003918
3919 return 0;
3920
3921err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003922 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003923 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003924 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003925err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00003926 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003927err_setup_tx:
3928 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003929 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003930
3931 return err;
3932}
3933
3934/**
3935 * e1000_close - Disables a network interface
3936 * @netdev: network interface device structure
3937 *
3938 * Returns 0, this is not allowed to fail
3939 *
3940 * The close entry point is called when an interface is de-activated
3941 * by the OS. The hardware is still under the drivers control, but
3942 * needs to be disabled. A global MAC reset is issued to stop the
3943 * hardware, and all transmit and receive resources are freed.
3944 **/
3945static int e1000_close(struct net_device *netdev)
3946{
3947 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003948 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003949
3950 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003951
3952 pm_runtime_get_sync(&pdev->dev);
3953
Bruce Allan5f4a7802011-11-29 08:09:19 +00003954 napi_disable(&adapter->napi);
3955
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003956 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3957 e1000e_down(adapter);
3958 e1000_free_irq(adapter);
3959 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003960 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003961
Bruce Allan55aa6982011-12-16 00:45:45 +00003962 e1000e_free_tx_resources(adapter->tx_ring);
3963 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003964
Bruce Allanad680762008-03-28 09:15:03 -07003965 /*
3966 * kill manageability vlan ID if supported, but not if a vlan with
3967 * the same ID is registered on the host OS (let 8021q kill it)
3968 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003969 if (adapter->hw.mng_cookie.status &
3970 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003971 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3972
Bruce Allanad680762008-03-28 09:15:03 -07003973 /*
3974 * If AMT is enabled, let the firmware know that the network
3975 * interface is now closed
3976 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003977 if ((adapter->flags & FLAG_HAS_AMT) &&
3978 !test_bit(__E1000_TESTING, &adapter->state))
3979 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003980
Bruce Allan79d4e902011-12-16 00:46:27 +00003981 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07003982 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003983
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003984 pm_runtime_put_sync(&pdev->dev);
3985
Auke Kokbc7f75f2007-09-17 12:30:59 -07003986 return 0;
3987}
3988/**
3989 * e1000_set_mac - Change the Ethernet Address of the NIC
3990 * @netdev: network interface device structure
3991 * @p: pointer to an address structure
3992 *
3993 * Returns 0 on success, negative on failure
3994 **/
3995static int e1000_set_mac(struct net_device *netdev, void *p)
3996{
3997 struct e1000_adapter *adapter = netdev_priv(netdev);
3998 struct sockaddr *addr = p;
3999
4000 if (!is_valid_ether_addr(addr->sa_data))
4001 return -EADDRNOTAVAIL;
4002
4003 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4004 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4005
4006 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
4007
4008 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4009 /* activate the work around */
4010 e1000e_set_laa_state_82571(&adapter->hw, 1);
4011
Bruce Allanad680762008-03-28 09:15:03 -07004012 /*
4013 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004014 * between the time RAR[0] gets clobbered and the time it
4015 * gets fixed (in e1000_watchdog), the actual LAA is in one
4016 * of the RARs and no incoming packets directed to this port
4017 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004018 * RAR[14]
4019 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004020 e1000e_rar_set(&adapter->hw,
4021 adapter->hw.mac.addr,
4022 adapter->hw.mac.rar_entry_count - 1);
4023 }
4024
4025 return 0;
4026}
4027
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004028/**
4029 * e1000e_update_phy_task - work thread to update phy
4030 * @work: pointer to our work struct
4031 *
4032 * this worker thread exists because we must acquire a
4033 * semaphore to read the phy, which we could msleep while
4034 * waiting for it, and we can't msleep in a timer.
4035 **/
4036static void e1000e_update_phy_task(struct work_struct *work)
4037{
4038 struct e1000_adapter *adapter = container_of(work,
4039 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004040
4041 if (test_bit(__E1000_DOWN, &adapter->state))
4042 return;
4043
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004044 e1000_get_phy_info(&adapter->hw);
4045}
4046
Bruce Allanad680762008-03-28 09:15:03 -07004047/*
4048 * Need to wait a few seconds after link up to get diagnostic information from
4049 * the phy
4050 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004051static void e1000_update_phy_info(unsigned long data)
4052{
4053 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004054
4055 if (test_bit(__E1000_DOWN, &adapter->state))
4056 return;
4057
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004058 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004059}
4060
4061/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004062 * e1000e_update_phy_stats - Update the PHY statistics counters
4063 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004064 *
4065 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004066 **/
4067static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4068{
4069 struct e1000_hw *hw = &adapter->hw;
4070 s32 ret_val;
4071 u16 phy_data;
4072
4073 ret_val = hw->phy.ops.acquire(hw);
4074 if (ret_val)
4075 return;
4076
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004077 /*
4078 * A page set is expensive so check if already on desired page.
4079 * If not, set to the page with the PHY status registers.
4080 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004081 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004082 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4083 &phy_data);
4084 if (ret_val)
4085 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004086 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4087 ret_val = hw->phy.ops.set_page(hw,
4088 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004089 if (ret_val)
4090 goto release;
4091 }
4092
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004093 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004094 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4095 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004096 if (!ret_val)
4097 adapter->stats.scc += phy_data;
4098
4099 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004100 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4101 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004102 if (!ret_val)
4103 adapter->stats.ecol += phy_data;
4104
4105 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004106 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4107 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004108 if (!ret_val)
4109 adapter->stats.mcc += phy_data;
4110
4111 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004112 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4113 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004114 if (!ret_val)
4115 adapter->stats.latecol += phy_data;
4116
4117 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004118 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4119 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004120 if (!ret_val)
4121 hw->mac.collision_delta = phy_data;
4122
4123 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004124 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4125 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004126 if (!ret_val)
4127 adapter->stats.dc += phy_data;
4128
4129 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004130 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4131 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004132 if (!ret_val)
4133 adapter->stats.tncrs += phy_data;
4134
4135release:
4136 hw->phy.ops.release(hw);
4137}
4138
4139/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004140 * e1000e_update_stats - Update the board statistics counters
4141 * @adapter: board private structure
4142 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004143static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004144{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004145 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004146 struct e1000_hw *hw = &adapter->hw;
4147 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004148
4149 /*
4150 * Prevent stats update while adapter is being reset, or if the pci
4151 * connection is down.
4152 */
4153 if (adapter->link_speed == 0)
4154 return;
4155 if (pci_channel_offline(pdev))
4156 return;
4157
Auke Kokbc7f75f2007-09-17 12:30:59 -07004158 adapter->stats.crcerrs += er32(CRCERRS);
4159 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004160 adapter->stats.gorc += er32(GORCL);
4161 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004162 adapter->stats.bprc += er32(BPRC);
4163 adapter->stats.mprc += er32(MPRC);
4164 adapter->stats.roc += er32(ROC);
4165
Auke Kokbc7f75f2007-09-17 12:30:59 -07004166 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004167
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004168 /* Half-duplex statistics */
4169 if (adapter->link_duplex == HALF_DUPLEX) {
4170 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4171 e1000e_update_phy_stats(adapter);
4172 } else {
4173 adapter->stats.scc += er32(SCC);
4174 adapter->stats.ecol += er32(ECOL);
4175 adapter->stats.mcc += er32(MCC);
4176 adapter->stats.latecol += er32(LATECOL);
4177 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004178
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004179 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004180
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004181 if ((hw->mac.type != e1000_82574) &&
4182 (hw->mac.type != e1000_82583))
4183 adapter->stats.tncrs += er32(TNCRS);
4184 }
4185 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004186 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004187
Auke Kokbc7f75f2007-09-17 12:30:59 -07004188 adapter->stats.xonrxc += er32(XONRXC);
4189 adapter->stats.xontxc += er32(XONTXC);
4190 adapter->stats.xoffrxc += er32(XOFFRXC);
4191 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004192 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004193 adapter->stats.gotc += er32(GOTCL);
4194 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004195 adapter->stats.rnbc += er32(RNBC);
4196 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004197
4198 adapter->stats.mptc += er32(MPTC);
4199 adapter->stats.bptc += er32(BPTC);
4200
4201 /* used for adaptive IFS */
4202
4203 hw->mac.tx_packet_delta = er32(TPT);
4204 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004205
4206 adapter->stats.algnerrc += er32(ALGNERRC);
4207 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004208 adapter->stats.cexterr += er32(CEXTERR);
4209 adapter->stats.tsctc += er32(TSCTC);
4210 adapter->stats.tsctfc += er32(TSCTFC);
4211
Auke Kokbc7f75f2007-09-17 12:30:59 -07004212 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004213 netdev->stats.multicast = adapter->stats.mprc;
4214 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004215
4216 /* Rx Errors */
4217
Bruce Allanad680762008-03-28 09:15:03 -07004218 /*
4219 * RLEC on some newer hardware can be incorrect so build
4220 * our own version based on RUC and ROC
4221 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004222 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004223 adapter->stats.crcerrs + adapter->stats.algnerrc +
4224 adapter->stats.ruc + adapter->stats.roc +
4225 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004226 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004227 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004228 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4229 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4230 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004231
4232 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004233 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004234 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004235 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4236 netdev->stats.tx_window_errors = adapter->stats.latecol;
4237 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004238
4239 /* Tx Dropped needs to be maintained elsewhere */
4240
Auke Kokbc7f75f2007-09-17 12:30:59 -07004241 /* Management Stats */
4242 adapter->stats.mgptc += er32(MGTPTC);
4243 adapter->stats.mgprc += er32(MGTPRC);
4244 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004245}
4246
Bruce Allan7c257692008-04-23 11:09:00 -07004247/**
4248 * e1000_phy_read_status - Update the PHY register status snapshot
4249 * @adapter: board private structure
4250 **/
4251static void e1000_phy_read_status(struct e1000_adapter *adapter)
4252{
4253 struct e1000_hw *hw = &adapter->hw;
4254 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004255
4256 if ((er32(STATUS) & E1000_STATUS_LU) &&
4257 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004258 int ret_val;
4259
Bruce Allan7c257692008-04-23 11:09:00 -07004260 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4261 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4262 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4263 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4264 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4265 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4266 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4267 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4268 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004269 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004270 } else {
4271 /*
4272 * Do not read PHY registers if link is not up
4273 * Set values to typical power-on defaults
4274 */
4275 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4276 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4277 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4278 BMSR_ERCAP);
4279 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4280 ADVERTISE_ALL | ADVERTISE_CSMA);
4281 phy->lpa = 0;
4282 phy->expansion = EXPANSION_ENABLENPAGE;
4283 phy->ctrl1000 = ADVERTISE_1000FULL;
4284 phy->stat1000 = 0;
4285 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4286 }
Bruce Allan7c257692008-04-23 11:09:00 -07004287}
4288
Auke Kokbc7f75f2007-09-17 12:30:59 -07004289static void e1000_print_link_info(struct e1000_adapter *adapter)
4290{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004291 struct e1000_hw *hw = &adapter->hw;
4292 u32 ctrl = er32(CTRL);
4293
Bruce Allan8f12fe82008-11-21 16:54:43 -08004294 /* Link status message must follow this format for user tools */
Jeff Kirsheref456f82011-11-03 11:40:28 +00004295 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4296 adapter->netdev->name,
4297 adapter->link_speed,
4298 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4299 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4300 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4301 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004302}
4303
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004304static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004305{
4306 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004307 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004308 s32 ret_val = 0;
4309
4310 /*
4311 * get_link_status is set on LSC (link status) interrupt or
4312 * Rx sequence error interrupt. get_link_status will stay
4313 * false until the check_for_link establishes link
4314 * for copper adapters ONLY
4315 */
4316 switch (hw->phy.media_type) {
4317 case e1000_media_type_copper:
4318 if (hw->mac.get_link_status) {
4319 ret_val = hw->mac.ops.check_for_link(hw);
4320 link_active = !hw->mac.get_link_status;
4321 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004322 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004323 }
4324 break;
4325 case e1000_media_type_fiber:
4326 ret_val = hw->mac.ops.check_for_link(hw);
4327 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4328 break;
4329 case e1000_media_type_internal_serdes:
4330 ret_val = hw->mac.ops.check_for_link(hw);
4331 link_active = adapter->hw.mac.serdes_has_link;
4332 break;
4333 default:
4334 case e1000_media_type_unknown:
4335 break;
4336 }
4337
4338 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4339 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4340 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004341 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004342 }
4343
4344 return link_active;
4345}
4346
4347static void e1000e_enable_receives(struct e1000_adapter *adapter)
4348{
4349 /* make sure the receive unit is started */
4350 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4351 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4352 struct e1000_hw *hw = &adapter->hw;
4353 u32 rctl = er32(RCTL);
4354 ew32(RCTL, rctl | E1000_RCTL_EN);
4355 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4356 }
4357}
4358
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004359static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4360{
4361 struct e1000_hw *hw = &adapter->hw;
4362
4363 /*
4364 * With 82574 controllers, PHY needs to be checked periodically
4365 * for hung state and reset, if two calls return true
4366 */
4367 if (e1000_check_phy_82574(hw))
4368 adapter->phy_hang_count++;
4369 else
4370 adapter->phy_hang_count = 0;
4371
4372 if (adapter->phy_hang_count > 1) {
4373 adapter->phy_hang_count = 0;
4374 schedule_work(&adapter->reset_task);
4375 }
4376}
4377
Auke Kokbc7f75f2007-09-17 12:30:59 -07004378/**
4379 * e1000_watchdog - Timer Call-back
4380 * @data: pointer to adapter cast into an unsigned long
4381 **/
4382static void e1000_watchdog(unsigned long data)
4383{
4384 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4385
4386 /* Do the rest outside of interrupt context */
4387 schedule_work(&adapter->watchdog_task);
4388
4389 /* TODO: make this use queue_delayed_work() */
4390}
4391
4392static void e1000_watchdog_task(struct work_struct *work)
4393{
4394 struct e1000_adapter *adapter = container_of(work,
4395 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004396 struct net_device *netdev = adapter->netdev;
4397 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004398 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004399 struct e1000_ring *tx_ring = adapter->tx_ring;
4400 struct e1000_hw *hw = &adapter->hw;
4401 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004402
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004403 if (test_bit(__E1000_DOWN, &adapter->state))
4404 return;
4405
David S. Millerb405e8d2010-02-04 22:31:41 -08004406 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004407 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004408 /* Cancel scheduled suspend requests. */
4409 pm_runtime_resume(netdev->dev.parent);
4410
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004411 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004412 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004413 }
4414
4415 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4416 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4417 e1000_update_mng_vlan(adapter);
4418
Auke Kokbc7f75f2007-09-17 12:30:59 -07004419 if (link) {
4420 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004421 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004422
4423 /* Cancel scheduled suspend requests. */
4424 pm_runtime_resume(netdev->dev.parent);
4425
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004426 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004427 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004428 mac->ops.get_link_up_info(&adapter->hw,
4429 &adapter->link_speed,
4430 &adapter->link_duplex);
4431 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004432 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004433 * On supported PHYs, check for duplex mismatch only
4434 * if link has autonegotiated at 10/100 half
4435 */
4436 if ((hw->phy.type == e1000_phy_igp_3 ||
4437 hw->phy.type == e1000_phy_bm) &&
4438 (hw->mac.autoneg == true) &&
4439 (adapter->link_speed == SPEED_10 ||
4440 adapter->link_speed == SPEED_100) &&
4441 (adapter->link_duplex == HALF_DUPLEX)) {
4442 u16 autoneg_exp;
4443
4444 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4445
4446 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004447 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 -07004448 }
4449
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004450 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004451 adapter->tx_timeout_factor = 1;
4452 switch (adapter->link_speed) {
4453 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004454 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004455 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004456 break;
4457 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004458 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004459 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004460 break;
4461 }
4462
Bruce Allanad680762008-03-28 09:15:03 -07004463 /*
4464 * workaround: re-program speed mode bit after
4465 * link-up event
4466 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004467 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4468 !txb2b) {
4469 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004470 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004471 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004472 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004473 }
4474
Bruce Allanad680762008-03-28 09:15:03 -07004475 /*
4476 * disable TSO for pcie and 10/100 speeds, to avoid
4477 * some hardware issues
4478 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004479 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4480 switch (adapter->link_speed) {
4481 case SPEED_10:
4482 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004483 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004484 netdev->features &= ~NETIF_F_TSO;
4485 netdev->features &= ~NETIF_F_TSO6;
4486 break;
4487 case SPEED_1000:
4488 netdev->features |= NETIF_F_TSO;
4489 netdev->features |= NETIF_F_TSO6;
4490 break;
4491 default:
4492 /* oops */
4493 break;
4494 }
4495 }
4496
Bruce Allanad680762008-03-28 09:15:03 -07004497 /*
4498 * enable transmits in the hardware, need to do this
4499 * after setting TARC(0)
4500 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004501 tctl = er32(TCTL);
4502 tctl |= E1000_TCTL_EN;
4503 ew32(TCTL, tctl);
4504
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004505 /*
4506 * Perform any post-link-up configuration before
4507 * reporting link up.
4508 */
4509 if (phy->ops.cfg_on_link_up)
4510 phy->ops.cfg_on_link_up(hw);
4511
Auke Kokbc7f75f2007-09-17 12:30:59 -07004512 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004513
4514 if (!test_bit(__E1000_DOWN, &adapter->state))
4515 mod_timer(&adapter->phy_info_timer,
4516 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004517 }
4518 } else {
4519 if (netif_carrier_ok(netdev)) {
4520 adapter->link_speed = 0;
4521 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004522 /* Link status message must follow this format */
4523 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4524 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004525 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004526 if (!test_bit(__E1000_DOWN, &adapter->state))
4527 mod_timer(&adapter->phy_info_timer,
4528 round_jiffies(jiffies + 2 * HZ));
4529
4530 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4531 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004532 else
4533 pm_schedule_suspend(netdev->dev.parent,
4534 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004535 }
4536 }
4537
4538link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004539 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540 e1000e_update_stats(adapter);
4541
4542 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4543 adapter->tpt_old = adapter->stats.tpt;
4544 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4545 adapter->colc_old = adapter->stats.colc;
4546
Bruce Allan7c257692008-04-23 11:09:00 -07004547 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4548 adapter->gorc_old = adapter->stats.gorc;
4549 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4550 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004551 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004552
4553 e1000e_update_adaptive(&adapter->hw);
4554
Bruce Allan90da0662011-01-06 07:02:53 +00004555 if (!netif_carrier_ok(netdev) &&
4556 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4557 /*
4558 * We've lost link, so the controller stops DMA,
4559 * but we've got queued Tx work that's never going
4560 * to get done, so reset controller to flush Tx.
4561 * (Do the reset outside of interrupt context).
4562 */
Bruce Allan90da0662011-01-06 07:02:53 +00004563 schedule_work(&adapter->reset_task);
4564 /* return immediately since reset is imminent */
4565 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004566 }
4567
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004568 /* Simple mode for Interrupt Throttle Rate (ITR) */
4569 if (adapter->itr_setting == 4) {
4570 /*
4571 * Symmetric Tx/Rx gets a reduced ITR=2000;
4572 * Total asymmetrical Tx or Rx gets ITR=8000;
4573 * everyone else is between 2000-8000.
4574 */
4575 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4576 u32 dif = (adapter->gotc > adapter->gorc ?
4577 adapter->gotc - adapter->gorc :
4578 adapter->gorc - adapter->gotc) / 10000;
4579 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4580
4581 ew32(ITR, 1000000000 / (itr * 256));
4582 }
4583
Bruce Allanad680762008-03-28 09:15:03 -07004584 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004585 if (adapter->msix_entries)
4586 ew32(ICS, adapter->rx_ring->ims_val);
4587 else
4588 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004589
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004590 /* flush pending descriptors to memory before detecting Tx hang */
4591 e1000e_flush_descriptors(adapter);
4592
Auke Kokbc7f75f2007-09-17 12:30:59 -07004593 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004594 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004595
Bruce Allanad680762008-03-28 09:15:03 -07004596 /*
4597 * With 82571 controllers, LAA may be overwritten due to controller
4598 * reset from the other port. Set the appropriate LAA in RAR[0]
4599 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004600 if (e1000e_get_laa_state_82571(hw))
4601 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4602
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004603 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4604 e1000e_check_82574_phy_workaround(adapter);
4605
Auke Kokbc7f75f2007-09-17 12:30:59 -07004606 /* Reset the timer */
4607 if (!test_bit(__E1000_DOWN, &adapter->state))
4608 mod_timer(&adapter->watchdog_timer,
4609 round_jiffies(jiffies + 2 * HZ));
4610}
4611
4612#define E1000_TX_FLAGS_CSUM 0x00000001
4613#define E1000_TX_FLAGS_VLAN 0x00000002
4614#define E1000_TX_FLAGS_TSO 0x00000004
4615#define E1000_TX_FLAGS_IPV4 0x00000008
4616#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4617#define E1000_TX_FLAGS_VLAN_SHIFT 16
4618
Bruce Allan55aa6982011-12-16 00:45:45 +00004619static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004620{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004621 struct e1000_context_desc *context_desc;
4622 struct e1000_buffer *buffer_info;
4623 unsigned int i;
4624 u32 cmd_length = 0;
4625 u16 ipcse = 0, tucse, mss;
4626 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004627
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004628 if (!skb_is_gso(skb))
4629 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004630
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004631 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004632 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4633
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004634 if (err)
4635 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004636 }
4637
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004638 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4639 mss = skb_shinfo(skb)->gso_size;
4640 if (skb->protocol == htons(ETH_P_IP)) {
4641 struct iphdr *iph = ip_hdr(skb);
4642 iph->tot_len = 0;
4643 iph->check = 0;
4644 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4645 0, IPPROTO_TCP, 0);
4646 cmd_length = E1000_TXD_CMD_IP;
4647 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004648 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004649 ipv6_hdr(skb)->payload_len = 0;
4650 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4651 &ipv6_hdr(skb)->daddr,
4652 0, IPPROTO_TCP, 0);
4653 ipcse = 0;
4654 }
4655 ipcss = skb_network_offset(skb);
4656 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4657 tucss = skb_transport_offset(skb);
4658 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4659 tucse = 0;
4660
4661 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4662 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4663
4664 i = tx_ring->next_to_use;
4665 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4666 buffer_info = &tx_ring->buffer_info[i];
4667
4668 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4669 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4670 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4671 context_desc->upper_setup.tcp_fields.tucss = tucss;
4672 context_desc->upper_setup.tcp_fields.tucso = tucso;
4673 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4674 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4675 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4676 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4677
4678 buffer_info->time_stamp = jiffies;
4679 buffer_info->next_to_watch = i;
4680
4681 i++;
4682 if (i == tx_ring->count)
4683 i = 0;
4684 tx_ring->next_to_use = i;
4685
4686 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004687}
4688
Bruce Allan55aa6982011-12-16 00:45:45 +00004689static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004690{
Bruce Allan55aa6982011-12-16 00:45:45 +00004691 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004692 struct e1000_context_desc *context_desc;
4693 struct e1000_buffer *buffer_info;
4694 unsigned int i;
4695 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004696 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004697 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004698
Dave Grahamaf807c82008-10-09 14:28:58 -07004699 if (skb->ip_summed != CHECKSUM_PARTIAL)
4700 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004701
Arthur Jones5f66f202009-03-19 01:13:08 +00004702 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4703 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4704 else
4705 protocol = skb->protocol;
4706
Arthur Jones3f518392009-03-20 15:56:35 -07004707 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004708 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004709 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4710 cmd_len |= E1000_TXD_CMD_TCP;
4711 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004712 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004713 /* XXX not handling all IPV6 headers */
4714 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4715 cmd_len |= E1000_TXD_CMD_TCP;
4716 break;
4717 default:
4718 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004719 e_warn("checksum_partial proto=%x!\n",
4720 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004721 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004722 }
4723
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004724 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004725
4726 i = tx_ring->next_to_use;
4727 buffer_info = &tx_ring->buffer_info[i];
4728 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4729
4730 context_desc->lower_setup.ip_config = 0;
4731 context_desc->upper_setup.tcp_fields.tucss = css;
4732 context_desc->upper_setup.tcp_fields.tucso =
4733 css + skb->csum_offset;
4734 context_desc->upper_setup.tcp_fields.tucse = 0;
4735 context_desc->tcp_seg_setup.data = 0;
4736 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4737
4738 buffer_info->time_stamp = jiffies;
4739 buffer_info->next_to_watch = i;
4740
4741 i++;
4742 if (i == tx_ring->count)
4743 i = 0;
4744 tx_ring->next_to_use = i;
4745
4746 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004747}
4748
4749#define E1000_MAX_PER_TXD 8192
4750#define E1000_MAX_TXD_PWR 12
4751
Bruce Allan55aa6982011-12-16 00:45:45 +00004752static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
4753 unsigned int first, unsigned int max_per_txd,
4754 unsigned int nr_frags, unsigned int mss)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004755{
Bruce Allan55aa6982011-12-16 00:45:45 +00004756 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00004757 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004758 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004759 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004760 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004761 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004762
4763 i = tx_ring->next_to_use;
4764
4765 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004766 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004767 size = min(len, max_per_txd);
4768
Auke Kokbc7f75f2007-09-17 12:30:59 -07004769 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004770 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004771 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004772 buffer_info->dma = dma_map_single(&pdev->dev,
4773 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004774 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004775 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004776 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004777 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004778
4779 len -= size;
4780 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004781 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004782
4783 if (len) {
4784 i++;
4785 if (i == tx_ring->count)
4786 i = 0;
4787 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004788 }
4789
4790 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004791 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004792
4793 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004794 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004795 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004796
4797 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004798 i++;
4799 if (i == tx_ring->count)
4800 i = 0;
4801
Auke Kokbc7f75f2007-09-17 12:30:59 -07004802 buffer_info = &tx_ring->buffer_info[i];
4803 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004804
4805 buffer_info->length = size;
4806 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004807 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004808 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4809 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004810 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004811 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004812 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004813
4814 len -= size;
4815 offset += size;
4816 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004817 }
4818 }
4819
Bruce Allanaf667a22010-12-31 06:10:01 +00004820 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004821 /* multiply data chunks by size of headers */
4822 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4823
Auke Kokbc7f75f2007-09-17 12:30:59 -07004824 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004825 tx_ring->buffer_info[i].segs = segs;
4826 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004827 tx_ring->buffer_info[first].next_to_watch = i;
4828
4829 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004830
4831dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004832 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004833 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004834 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004835 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004836
4837 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004838 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004839 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004840 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004841 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00004842 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004843 }
4844
4845 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004846}
4847
Bruce Allan55aa6982011-12-16 00:45:45 +00004848static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004849{
Bruce Allan55aa6982011-12-16 00:45:45 +00004850 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004851 struct e1000_tx_desc *tx_desc = NULL;
4852 struct e1000_buffer *buffer_info;
4853 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4854 unsigned int i;
4855
4856 if (tx_flags & E1000_TX_FLAGS_TSO) {
4857 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4858 E1000_TXD_CMD_TSE;
4859 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4860
4861 if (tx_flags & E1000_TX_FLAGS_IPV4)
4862 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4863 }
4864
4865 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4866 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4867 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4868 }
4869
4870 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4871 txd_lower |= E1000_TXD_CMD_VLE;
4872 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4873 }
4874
4875 i = tx_ring->next_to_use;
4876
Bruce Allan36b973d2010-11-24 07:42:43 +00004877 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004878 buffer_info = &tx_ring->buffer_info[i];
4879 tx_desc = E1000_TX_DESC(*tx_ring, i);
4880 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4881 tx_desc->lower.data =
4882 cpu_to_le32(txd_lower | buffer_info->length);
4883 tx_desc->upper.data = cpu_to_le32(txd_upper);
4884
4885 i++;
4886 if (i == tx_ring->count)
4887 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004888 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004889
4890 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4891
Bruce Allanad680762008-03-28 09:15:03 -07004892 /*
4893 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004894 * know there are new descriptors to fetch. (Only
4895 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004896 * such as IA-64).
4897 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004898 wmb();
4899
4900 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004901
4902 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00004903 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07004904 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00004905 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07004906
Bruce Allanad680762008-03-28 09:15:03 -07004907 /*
4908 * we need this if more than one processor can write to our tail
4909 * at a time, it synchronizes IO on IA64/Altix systems
4910 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004911 mmiowb();
4912}
4913
4914#define MINIMUM_DHCP_PACKET_SIZE 282
4915static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4916 struct sk_buff *skb)
4917{
4918 struct e1000_hw *hw = &adapter->hw;
4919 u16 length, offset;
4920
4921 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004922 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4923 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004924 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4925 return 0;
4926 }
4927
4928 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4929 return 0;
4930
4931 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4932 return 0;
4933
4934 {
4935 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4936 struct udphdr *udp;
4937
4938 if (ip->protocol != IPPROTO_UDP)
4939 return 0;
4940
4941 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4942 if (ntohs(udp->dest) != 67)
4943 return 0;
4944
4945 offset = (u8 *)udp + 8 - skb->data;
4946 length = skb->len - offset;
4947 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4948 }
4949
4950 return 0;
4951}
4952
Bruce Allan55aa6982011-12-16 00:45:45 +00004953static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004954{
Bruce Allan55aa6982011-12-16 00:45:45 +00004955 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004956
Bruce Allan55aa6982011-12-16 00:45:45 +00004957 netif_stop_queue(adapter->netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004958 /*
4959 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004960 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004961 * but since that doesn't exist yet, just open code it.
4962 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004963 smp_mb();
4964
Bruce Allanad680762008-03-28 09:15:03 -07004965 /*
4966 * We need to check again in a case another CPU has just
4967 * made room available.
4968 */
Bruce Allan55aa6982011-12-16 00:45:45 +00004969 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004970 return -EBUSY;
4971
4972 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00004973 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004974 ++adapter->restart_queue;
4975 return 0;
4976}
4977
Bruce Allan55aa6982011-12-16 00:45:45 +00004978static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004979{
Bruce Allan55aa6982011-12-16 00:45:45 +00004980 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004981 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00004982 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004983}
4984
Bruce Allan0e15df42012-01-31 06:37:11 +00004985#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1)
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004986static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4987 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004988{
4989 struct e1000_adapter *adapter = netdev_priv(netdev);
4990 struct e1000_ring *tx_ring = adapter->tx_ring;
4991 unsigned int first;
4992 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4993 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4994 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004995 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004996 unsigned int nr_frags;
4997 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998 int count = 0;
4999 int tso;
5000 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005001
5002 if (test_bit(__E1000_DOWN, &adapter->state)) {
5003 dev_kfree_skb_any(skb);
5004 return NETDEV_TX_OK;
5005 }
5006
5007 if (skb->len <= 0) {
5008 dev_kfree_skb_any(skb);
5009 return NETDEV_TX_OK;
5010 }
5011
5012 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07005013 /*
5014 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07005015 * make sure there is enough room in the FIFO before
5016 * initiating the DMA for each buffer. The calc is:
5017 * 4 = ceil(buffer len/mss). To make sure we don't
5018 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07005019 * drops.
5020 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005021 if (mss) {
5022 u8 hdr_len;
5023 max_per_txd = min(mss << 2, max_per_txd);
5024 max_txd_pwr = fls(max_per_txd) - 1;
5025
Bruce Allanad680762008-03-28 09:15:03 -07005026 /*
5027 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
5028 * points to just header, pull a few bytes of payload from
5029 * frags into skb->data
5030 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005031 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07005032 /*
5033 * we do this workaround for ES2LAN, but it is un-necessary,
5034 * avoiding it could save a lot of cycles
5035 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005036 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037 unsigned int pull_size;
5038
Bruce Allana2a5b322012-01-31 06:37:17 +00005039 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005040 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005041 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005042 dev_kfree_skb_any(skb);
5043 return NETDEV_TX_OK;
5044 }
Eric Dumazete743d312010-04-14 15:59:40 -07005045 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005046 }
5047 }
5048
5049 /* reserve a descriptor for the offload context */
5050 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5051 count++;
5052 count++;
5053
5054 count += TXD_USE_COUNT(len, max_txd_pwr);
5055
5056 nr_frags = skb_shinfo(skb)->nr_frags;
5057 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00005058 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07005059 max_txd_pwr);
5060
5061 if (adapter->hw.mac.tx_pkt_filtering)
5062 e1000_transfer_dhcp_info(adapter, skb);
5063
Bruce Allanad680762008-03-28 09:15:03 -07005064 /*
5065 * need: count + 2 desc gap to keep tail from touching
5066 * head, otherwise try next time
5067 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005068 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005069 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005070
Jesse Grosseab6d182010-10-20 13:56:03 +00005071 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005072 tx_flags |= E1000_TX_FLAGS_VLAN;
5073 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5074 }
5075
5076 first = tx_ring->next_to_use;
5077
Bruce Allan55aa6982011-12-16 00:45:45 +00005078 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005079 if (tso < 0) {
5080 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005081 return NETDEV_TX_OK;
5082 }
5083
5084 if (tso)
5085 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005086 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005087 tx_flags |= E1000_TX_FLAGS_CSUM;
5088
Bruce Allanad680762008-03-28 09:15:03 -07005089 /*
5090 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005091 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005092 * no longer assume, we must.
5093 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005094 if (skb->protocol == htons(ETH_P_IP))
5095 tx_flags |= E1000_TX_FLAGS_IPV4;
5096
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005097 /* if count is 0 then mapping error has occurred */
Bruce Allan55aa6982011-12-16 00:45:45 +00005098 count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005099 if (count) {
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005100 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005101 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005102 /* Make sure there is space in the ring for the next send. */
Bruce Allan55aa6982011-12-16 00:45:45 +00005103 e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005104
5105 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005106 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005107 tx_ring->buffer_info[first].time_stamp = 0;
5108 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005109 }
5110
Auke Kokbc7f75f2007-09-17 12:30:59 -07005111 return NETDEV_TX_OK;
5112}
5113
5114/**
5115 * e1000_tx_timeout - Respond to a Tx Hang
5116 * @netdev: network interface device structure
5117 **/
5118static void e1000_tx_timeout(struct net_device *netdev)
5119{
5120 struct e1000_adapter *adapter = netdev_priv(netdev);
5121
5122 /* Do the reset outside of interrupt context */
5123 adapter->tx_timeout_count++;
5124 schedule_work(&adapter->reset_task);
5125}
5126
5127static void e1000_reset_task(struct work_struct *work)
5128{
5129 struct e1000_adapter *adapter;
5130 adapter = container_of(work, struct e1000_adapter, reset_task);
5131
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005132 /* don't run the task if already down */
5133 if (test_bit(__E1000_DOWN, &adapter->state))
5134 return;
5135
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005136 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5137 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5138 e1000e_dump(adapter);
5139 e_err("Reset adapter\n");
5140 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005141 e1000e_reinit_locked(adapter);
5142}
5143
5144/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005145 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005146 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005147 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005148 *
5149 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005150 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005151struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5152 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005153{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005154 struct e1000_adapter *adapter = netdev_priv(netdev);
5155
5156 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5157 spin_lock(&adapter->stats64_lock);
5158 e1000e_update_stats(adapter);
5159 /* Fill out the OS statistics structure */
5160 stats->rx_bytes = adapter->stats.gorc;
5161 stats->rx_packets = adapter->stats.gprc;
5162 stats->tx_bytes = adapter->stats.gotc;
5163 stats->tx_packets = adapter->stats.gptc;
5164 stats->multicast = adapter->stats.mprc;
5165 stats->collisions = adapter->stats.colc;
5166
5167 /* Rx Errors */
5168
5169 /*
5170 * RLEC on some newer hardware can be incorrect so build
5171 * our own version based on RUC and ROC
5172 */
5173 stats->rx_errors = adapter->stats.rxerrc +
5174 adapter->stats.crcerrs + adapter->stats.algnerrc +
5175 adapter->stats.ruc + adapter->stats.roc +
5176 adapter->stats.cexterr;
5177 stats->rx_length_errors = adapter->stats.ruc +
5178 adapter->stats.roc;
5179 stats->rx_crc_errors = adapter->stats.crcerrs;
5180 stats->rx_frame_errors = adapter->stats.algnerrc;
5181 stats->rx_missed_errors = adapter->stats.mpc;
5182
5183 /* Tx Errors */
5184 stats->tx_errors = adapter->stats.ecol +
5185 adapter->stats.latecol;
5186 stats->tx_aborted_errors = adapter->stats.ecol;
5187 stats->tx_window_errors = adapter->stats.latecol;
5188 stats->tx_carrier_errors = adapter->stats.tncrs;
5189
5190 /* Tx Dropped needs to be maintained elsewhere */
5191
5192 spin_unlock(&adapter->stats64_lock);
5193 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005194}
5195
5196/**
5197 * e1000_change_mtu - Change the Maximum Transfer Unit
5198 * @netdev: network interface device structure
5199 * @new_mtu: new value for maximum frame size
5200 *
5201 * Returns 0 on success, negative on failure
5202 **/
5203static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5204{
5205 struct e1000_adapter *adapter = netdev_priv(netdev);
5206 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5207
Bruce Allan2adc55c2009-06-02 11:28:58 +00005208 /* Jumbo frame support */
Bruce Allan70495a52012-01-11 01:26:50 +00005209 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
5210 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5211 e_err("Jumbo Frames not supported.\n");
5212 return -EINVAL;
5213 }
5214
5215 /*
5216 * IP payload checksum (enabled with jumbos/packet-split when
5217 * Rx checksum is enabled) and generation of RSS hash is
5218 * mutually exclusive in the hardware.
5219 */
5220 if ((netdev->features & NETIF_F_RXCSUM) &&
5221 (netdev->features & NETIF_F_RXHASH)) {
5222 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");
5223 return -EINVAL;
5224 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005225 }
5226
Bruce Allan2adc55c2009-06-02 11:28:58 +00005227 /* Supported frame sizes */
5228 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5229 (max_frame > adapter->max_hw_frame_size)) {
5230 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005231 return -EINVAL;
5232 }
5233
Bruce Allana1ce6472010-09-22 17:16:40 +00005234 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5235 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5236 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5237 (new_mtu > ETH_DATA_LEN)) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00005238 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005239 return -EINVAL;
5240 }
5241
Bruce Allan6f461f62010-04-27 03:33:04 +00005242 /* 82573 Errata 17 */
5243 if (((adapter->hw.mac.type == e1000_82573) ||
5244 (adapter->hw.mac.type == e1000_82574)) &&
5245 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5246 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5247 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5248 }
5249
Auke Kokbc7f75f2007-09-17 12:30:59 -07005250 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005251 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005252 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005253 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005254 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5255 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005256 if (netif_running(netdev))
5257 e1000e_down(adapter);
5258
Bruce Allanad680762008-03-28 09:15:03 -07005259 /*
5260 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005261 * means we reserve 2 more, this pushes us to allocate from the next
5262 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005263 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005264 * However with the new *_jumbo_rx* routines, jumbo receives will use
5265 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005266 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005267
Jesse Brandeburg99261462010-01-22 22:56:16 +00005268 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005269 adapter->rx_buffer_len = 2048;
5270 else
5271 adapter->rx_buffer_len = 4096;
5272
5273 /* adjust allocation if LPE protects us, and we aren't using SBP */
5274 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5275 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5276 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005277 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005278
Auke Kokbc7f75f2007-09-17 12:30:59 -07005279 if (netif_running(netdev))
5280 e1000e_up(adapter);
5281 else
5282 e1000e_reset(adapter);
5283
5284 clear_bit(__E1000_RESETTING, &adapter->state);
5285
5286 return 0;
5287}
5288
5289static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5290 int cmd)
5291{
5292 struct e1000_adapter *adapter = netdev_priv(netdev);
5293 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005294
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005295 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005296 return -EOPNOTSUPP;
5297
5298 switch (cmd) {
5299 case SIOCGMIIPHY:
5300 data->phy_id = adapter->hw.phy.addr;
5301 break;
5302 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005303 e1000_phy_read_status(adapter);
5304
Bruce Allan7c257692008-04-23 11:09:00 -07005305 switch (data->reg_num & 0x1F) {
5306 case MII_BMCR:
5307 data->val_out = adapter->phy_regs.bmcr;
5308 break;
5309 case MII_BMSR:
5310 data->val_out = adapter->phy_regs.bmsr;
5311 break;
5312 case MII_PHYSID1:
5313 data->val_out = (adapter->hw.phy.id >> 16);
5314 break;
5315 case MII_PHYSID2:
5316 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5317 break;
5318 case MII_ADVERTISE:
5319 data->val_out = adapter->phy_regs.advertise;
5320 break;
5321 case MII_LPA:
5322 data->val_out = adapter->phy_regs.lpa;
5323 break;
5324 case MII_EXPANSION:
5325 data->val_out = adapter->phy_regs.expansion;
5326 break;
5327 case MII_CTRL1000:
5328 data->val_out = adapter->phy_regs.ctrl1000;
5329 break;
5330 case MII_STAT1000:
5331 data->val_out = adapter->phy_regs.stat1000;
5332 break;
5333 case MII_ESTATUS:
5334 data->val_out = adapter->phy_regs.estatus;
5335 break;
5336 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005337 return -EIO;
5338 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005339 break;
5340 case SIOCSMIIREG:
5341 default:
5342 return -EOPNOTSUPP;
5343 }
5344 return 0;
5345}
5346
5347static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5348{
5349 switch (cmd) {
5350 case SIOCGMIIPHY:
5351 case SIOCGMIIREG:
5352 case SIOCSMIIREG:
5353 return e1000_mii_ioctl(netdev, ifr, cmd);
5354 default:
5355 return -EOPNOTSUPP;
5356 }
5357}
5358
Bruce Allana4f58f52009-06-02 11:29:18 +00005359static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5360{
5361 struct e1000_hw *hw = &adapter->hw;
5362 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005363 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005364 int retval = 0;
5365
5366 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005367 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005368
Bruce Allan2b6b1682011-05-13 07:20:09 +00005369 retval = hw->phy.ops.acquire(hw);
5370 if (retval) {
5371 e_err("Could not acquire PHY\n");
5372 return retval;
5373 }
5374
5375 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5376 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5377 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005378 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005379
5380 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005381 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5382 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005383 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5384 (u16)(mac_reg & 0xFFFF));
5385 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5386 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005387 }
5388
5389 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005390 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005391 mac_reg = er32(RCTL);
5392 if (mac_reg & E1000_RCTL_UPE)
5393 phy_reg |= BM_RCTL_UPE;
5394 if (mac_reg & E1000_RCTL_MPE)
5395 phy_reg |= BM_RCTL_MPE;
5396 phy_reg &= ~(BM_RCTL_MO_MASK);
5397 if (mac_reg & E1000_RCTL_MO_3)
5398 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5399 << BM_RCTL_MO_SHIFT);
5400 if (mac_reg & E1000_RCTL_BAM)
5401 phy_reg |= BM_RCTL_BAM;
5402 if (mac_reg & E1000_RCTL_PMCF)
5403 phy_reg |= BM_RCTL_PMCF;
5404 mac_reg = er32(CTRL);
5405 if (mac_reg & E1000_CTRL_RFCE)
5406 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005407 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005408
5409 /* enable PHY wakeup in MAC register */
5410 ew32(WUFC, wufc);
5411 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5412
5413 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005414 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5415 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005416
5417 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005418 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5419 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005420 if (retval)
5421 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005422release:
Bruce Allan94d81862009-11-20 23:25:26 +00005423 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005424
5425 return retval;
5426}
5427
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005428static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5429 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005430{
5431 struct net_device *netdev = pci_get_drvdata(pdev);
5432 struct e1000_adapter *adapter = netdev_priv(netdev);
5433 struct e1000_hw *hw = &adapter->hw;
5434 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005435 /* Runtime suspend should only enable wakeup for link changes */
5436 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005437 int retval = 0;
5438
5439 netif_device_detach(netdev);
5440
5441 if (netif_running(netdev)) {
5442 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5443 e1000e_down(adapter);
5444 e1000_free_irq(adapter);
5445 }
Bruce Allan4662e822008-08-26 18:37:06 -07005446 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005447
5448 retval = pci_save_state(pdev);
5449 if (retval)
5450 return retval;
5451
5452 status = er32(STATUS);
5453 if (status & E1000_STATUS_LU)
5454 wufc &= ~E1000_WUFC_LNKC;
5455
5456 if (wufc) {
5457 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005458 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005459
5460 /* turn on all-multi mode if wake on multicast is enabled */
5461 if (wufc & E1000_WUFC_MC) {
5462 rctl = er32(RCTL);
5463 rctl |= E1000_RCTL_MPE;
5464 ew32(RCTL, rctl);
5465 }
5466
5467 ctrl = er32(CTRL);
5468 /* advertise wake from D3Cold */
5469 #define E1000_CTRL_ADVD3WUC 0x00100000
5470 /* phy power management enable */
5471 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005472 ctrl |= E1000_CTRL_ADVD3WUC;
5473 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5474 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005475 ew32(CTRL, ctrl);
5476
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005477 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5478 adapter->hw.phy.media_type ==
5479 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005480 /* keep the laser running in D3 */
5481 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005482 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005483 ew32(CTRL_EXT, ctrl_ext);
5484 }
5485
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005486 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005487 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005488
Auke Kokbc7f75f2007-09-17 12:30:59 -07005489 /* Allow time for pending master requests to run */
5490 e1000e_disable_pcie_master(&adapter->hw);
5491
Bruce Allan82776a42009-08-14 14:35:33 +00005492 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005493 /* enable wakeup by the PHY */
5494 retval = e1000_init_phy_wakeup(adapter, wufc);
5495 if (retval)
5496 return retval;
5497 } else {
5498 /* enable wakeup by the MAC */
5499 ew32(WUFC, wufc);
5500 ew32(WUC, E1000_WUC_PME_EN);
5501 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005502 } else {
5503 ew32(WUC, 0);
5504 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005505 }
5506
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005507 *enable_wake = !!wufc;
5508
Auke Kokbc7f75f2007-09-17 12:30:59 -07005509 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005510 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5511 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005512 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005513
5514 if (adapter->hw.phy.type == e1000_phy_igp_3)
5515 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5516
Bruce Allanad680762008-03-28 09:15:03 -07005517 /*
5518 * Release control of h/w to f/w. If f/w is AMT enabled, this
5519 * would have already happened in close and is redundant.
5520 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005521 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005522
5523 pci_disable_device(pdev);
5524
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005525 return 0;
5526}
5527
5528static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5529{
5530 if (sleep && wake) {
5531 pci_prepare_to_sleep(pdev);
5532 return;
5533 }
5534
5535 pci_wake_from_d3(pdev, wake);
5536 pci_set_power_state(pdev, PCI_D3hot);
5537}
5538
5539static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5540 bool wake)
5541{
5542 struct net_device *netdev = pci_get_drvdata(pdev);
5543 struct e1000_adapter *adapter = netdev_priv(netdev);
5544
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005545 /*
5546 * The pci-e switch on some quad port adapters will report a
5547 * correctable error when the MAC transitions from D0 to D3. To
5548 * prevent this we need to mask off the correctable errors on the
5549 * downstream port of the pci-e switch.
5550 */
5551 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5552 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005553 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005554 u16 devctl;
5555
5556 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5557 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5558 (devctl & ~PCI_EXP_DEVCTL_CERE));
5559
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005560 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005561
5562 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5563 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005564 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005565 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005566}
5567
Bruce Allan6f461f62010-04-27 03:33:04 +00005568#ifdef CONFIG_PCIEASPM
5569static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5570{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005571 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005572}
5573#else
5574static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005575{
5576 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005577 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005578
5579 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005580 * Both device and parent should have the same ASPM setting.
5581 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005582 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005583 pos = pci_pcie_cap(pdev);
5584 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5585 reg16 &= ~state;
5586 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5587
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005588 if (!pdev->bus->self)
5589 return;
5590
Bruce Allan6f461f62010-04-27 03:33:04 +00005591 pos = pci_pcie_cap(pdev->bus->self);
5592 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5593 reg16 &= ~state;
5594 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5595}
5596#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005597static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005598{
5599 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5600 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5601 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5602
5603 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005604}
5605
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005606#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005607static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005608{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005609 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005610}
5611
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005612static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005613{
5614 struct net_device *netdev = pci_get_drvdata(pdev);
5615 struct e1000_adapter *adapter = netdev_priv(netdev);
5616 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005617 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005618 u32 err;
5619
Bruce Allan78cd29d2011-03-24 03:09:03 +00005620 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5621 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5622 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5623 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5624 if (aspm_disable_flag)
5625 e1000e_disable_aspm(pdev, aspm_disable_flag);
5626
Auke Kokbc7f75f2007-09-17 12:30:59 -07005627 pci_set_power_state(pdev, PCI_D0);
5628 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005629 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005630
Bruce Allan4662e822008-08-26 18:37:06 -07005631 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005632 if (netif_running(netdev)) {
5633 err = e1000_request_irq(adapter);
5634 if (err)
5635 return err;
5636 }
5637
Bruce Allan99730e42011-05-13 07:19:48 +00005638 if (hw->mac.type == e1000_pch2lan)
5639 e1000_resume_workarounds_pchlan(&adapter->hw);
5640
Auke Kokbc7f75f2007-09-17 12:30:59 -07005641 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005642
5643 /* report the system wakeup cause from S3/S4 */
5644 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5645 u16 phy_data;
5646
5647 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5648 if (phy_data) {
5649 e_info("PHY Wakeup cause - %s\n",
5650 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5651 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5652 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5653 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005654 phy_data & E1000_WUS_LNKC ?
5655 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005656 }
5657 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5658 } else {
5659 u32 wus = er32(WUS);
5660 if (wus) {
5661 e_info("MAC Wakeup cause - %s\n",
5662 wus & E1000_WUS_EX ? "Unicast Packet" :
5663 wus & E1000_WUS_MC ? "Multicast Packet" :
5664 wus & E1000_WUS_BC ? "Broadcast Packet" :
5665 wus & E1000_WUS_MAG ? "Magic Packet" :
5666 wus & E1000_WUS_LNKC ? "Link Status Change" :
5667 "other");
5668 }
5669 ew32(WUS, ~0);
5670 }
5671
Auke Kokbc7f75f2007-09-17 12:30:59 -07005672 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005673
Bruce Allancd791612010-05-10 14:59:51 +00005674 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005675
5676 if (netif_running(netdev))
5677 e1000e_up(adapter);
5678
5679 netif_device_attach(netdev);
5680
Bruce Allanad680762008-03-28 09:15:03 -07005681 /*
5682 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005683 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005684 * under the control of the driver.
5685 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005686 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005687 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005688
5689 return 0;
5690}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005691
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005692#ifdef CONFIG_PM_SLEEP
5693static int e1000_suspend(struct device *dev)
5694{
5695 struct pci_dev *pdev = to_pci_dev(dev);
5696 int retval;
5697 bool wake;
5698
5699 retval = __e1000_shutdown(pdev, &wake, false);
5700 if (!retval)
5701 e1000_complete_shutdown(pdev, true, wake);
5702
5703 return retval;
5704}
5705
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005706static int e1000_resume(struct device *dev)
5707{
5708 struct pci_dev *pdev = to_pci_dev(dev);
5709 struct net_device *netdev = pci_get_drvdata(pdev);
5710 struct e1000_adapter *adapter = netdev_priv(netdev);
5711
5712 if (e1000e_pm_ready(adapter))
5713 adapter->idle_check = true;
5714
5715 return __e1000_resume(pdev);
5716}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005717#endif /* CONFIG_PM_SLEEP */
5718
5719#ifdef CONFIG_PM_RUNTIME
5720static int e1000_runtime_suspend(struct device *dev)
5721{
5722 struct pci_dev *pdev = to_pci_dev(dev);
5723 struct net_device *netdev = pci_get_drvdata(pdev);
5724 struct e1000_adapter *adapter = netdev_priv(netdev);
5725
5726 if (e1000e_pm_ready(adapter)) {
5727 bool wake;
5728
5729 __e1000_shutdown(pdev, &wake, true);
5730 }
5731
5732 return 0;
5733}
5734
5735static int e1000_idle(struct device *dev)
5736{
5737 struct pci_dev *pdev = to_pci_dev(dev);
5738 struct net_device *netdev = pci_get_drvdata(pdev);
5739 struct e1000_adapter *adapter = netdev_priv(netdev);
5740
5741 if (!e1000e_pm_ready(adapter))
5742 return 0;
5743
5744 if (adapter->idle_check) {
5745 adapter->idle_check = false;
5746 if (!e1000e_has_link(adapter))
5747 pm_schedule_suspend(dev, MSEC_PER_SEC);
5748 }
5749
5750 return -EBUSY;
5751}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005752
5753static int e1000_runtime_resume(struct device *dev)
5754{
5755 struct pci_dev *pdev = to_pci_dev(dev);
5756 struct net_device *netdev = pci_get_drvdata(pdev);
5757 struct e1000_adapter *adapter = netdev_priv(netdev);
5758
5759 if (!e1000e_pm_ready(adapter))
5760 return 0;
5761
5762 adapter->idle_check = !dev->power.runtime_auto;
5763 return __e1000_resume(pdev);
5764}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005765#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005766#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005767
5768static void e1000_shutdown(struct pci_dev *pdev)
5769{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005770 bool wake = false;
5771
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005772 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005773
5774 if (system_state == SYSTEM_POWER_OFF)
5775 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005776}
5777
5778#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005779
5780static irqreturn_t e1000_intr_msix(int irq, void *data)
5781{
5782 struct net_device *netdev = data;
5783 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005784
5785 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005786 int vector, msix_irq;
5787
Dongdong Deng147b2c82010-11-16 19:50:15 -08005788 vector = 0;
5789 msix_irq = adapter->msix_entries[vector].vector;
5790 disable_irq(msix_irq);
5791 e1000_intr_msix_rx(msix_irq, netdev);
5792 enable_irq(msix_irq);
5793
5794 vector++;
5795 msix_irq = adapter->msix_entries[vector].vector;
5796 disable_irq(msix_irq);
5797 e1000_intr_msix_tx(msix_irq, netdev);
5798 enable_irq(msix_irq);
5799
5800 vector++;
5801 msix_irq = adapter->msix_entries[vector].vector;
5802 disable_irq(msix_irq);
5803 e1000_msix_other(msix_irq, netdev);
5804 enable_irq(msix_irq);
5805 }
5806
5807 return IRQ_HANDLED;
5808}
5809
Auke Kokbc7f75f2007-09-17 12:30:59 -07005810/*
5811 * Polling 'interrupt' - used by things like netconsole to send skbs
5812 * without having to re-enable interrupts. It's not called while
5813 * the interrupt routine is executing.
5814 */
5815static void e1000_netpoll(struct net_device *netdev)
5816{
5817 struct e1000_adapter *adapter = netdev_priv(netdev);
5818
Dongdong Deng147b2c82010-11-16 19:50:15 -08005819 switch (adapter->int_mode) {
5820 case E1000E_INT_MODE_MSIX:
5821 e1000_intr_msix(adapter->pdev->irq, netdev);
5822 break;
5823 case E1000E_INT_MODE_MSI:
5824 disable_irq(adapter->pdev->irq);
5825 e1000_intr_msi(adapter->pdev->irq, netdev);
5826 enable_irq(adapter->pdev->irq);
5827 break;
5828 default: /* E1000E_INT_MODE_LEGACY */
5829 disable_irq(adapter->pdev->irq);
5830 e1000_intr(adapter->pdev->irq, netdev);
5831 enable_irq(adapter->pdev->irq);
5832 break;
5833 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005834}
5835#endif
5836
5837/**
5838 * e1000_io_error_detected - called when PCI error is detected
5839 * @pdev: Pointer to PCI device
5840 * @state: The current pci connection state
5841 *
5842 * This function is called after a PCI bus error affecting
5843 * this device has been detected.
5844 */
5845static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5846 pci_channel_state_t state)
5847{
5848 struct net_device *netdev = pci_get_drvdata(pdev);
5849 struct e1000_adapter *adapter = netdev_priv(netdev);
5850
5851 netif_device_detach(netdev);
5852
Mike Masonc93b5a72009-06-30 12:45:53 +00005853 if (state == pci_channel_io_perm_failure)
5854 return PCI_ERS_RESULT_DISCONNECT;
5855
Auke Kokbc7f75f2007-09-17 12:30:59 -07005856 if (netif_running(netdev))
5857 e1000e_down(adapter);
5858 pci_disable_device(pdev);
5859
5860 /* Request a slot slot reset. */
5861 return PCI_ERS_RESULT_NEED_RESET;
5862}
5863
5864/**
5865 * e1000_io_slot_reset - called after the pci bus has been reset.
5866 * @pdev: Pointer to PCI device
5867 *
5868 * Restart the card from scratch, as if from a cold-boot. Implementation
5869 * resembles the first-half of the e1000_resume routine.
5870 */
5871static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5872{
5873 struct net_device *netdev = pci_get_drvdata(pdev);
5874 struct e1000_adapter *adapter = netdev_priv(netdev);
5875 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005876 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005877 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005878 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005879
Bruce Allan78cd29d2011-03-24 03:09:03 +00005880 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5881 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005882 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005883 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5884 if (aspm_disable_flag)
5885 e1000e_disable_aspm(pdev, aspm_disable_flag);
5886
Bruce Allanf0f422e2008-08-04 17:21:53 -07005887 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005888 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005889 dev_err(&pdev->dev,
5890 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005891 result = PCI_ERS_RESULT_DISCONNECT;
5892 } else {
5893 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005894 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005895 pci_restore_state(pdev);
5896
5897 pci_enable_wake(pdev, PCI_D3hot, 0);
5898 pci_enable_wake(pdev, PCI_D3cold, 0);
5899
5900 e1000e_reset(adapter);
5901 ew32(WUS, ~0);
5902 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005903 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005904
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005905 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005906
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005907 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005908}
5909
5910/**
5911 * e1000_io_resume - called when traffic can start flowing again.
5912 * @pdev: Pointer to PCI device
5913 *
5914 * This callback is called when the error recovery driver tells us that
5915 * its OK to resume normal operation. Implementation resembles the
5916 * second-half of the e1000_resume routine.
5917 */
5918static void e1000_io_resume(struct pci_dev *pdev)
5919{
5920 struct net_device *netdev = pci_get_drvdata(pdev);
5921 struct e1000_adapter *adapter = netdev_priv(netdev);
5922
Bruce Allancd791612010-05-10 14:59:51 +00005923 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005924
5925 if (netif_running(netdev)) {
5926 if (e1000e_up(adapter)) {
5927 dev_err(&pdev->dev,
5928 "can't bring device back up after reset\n");
5929 return;
5930 }
5931 }
5932
5933 netif_device_attach(netdev);
5934
Bruce Allanad680762008-03-28 09:15:03 -07005935 /*
5936 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005937 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005938 * under the control of the driver.
5939 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005940 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005941 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005942
5943}
5944
5945static void e1000_print_device_info(struct e1000_adapter *adapter)
5946{
5947 struct e1000_hw *hw = &adapter->hw;
5948 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005949 u32 ret_val;
5950 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005951
5952 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005953 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005954 /* bus width */
5955 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5956 "Width x1"),
5957 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005958 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005959 e_info("Intel(R) PRO/%s Network Connection\n",
5960 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005961 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5962 E1000_PBANUM_LENGTH);
5963 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00005964 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00005965 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5966 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005967}
5968
Auke Kok10aa4c02008-08-04 17:21:20 -07005969static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5970{
5971 struct e1000_hw *hw = &adapter->hw;
5972 int ret_val;
5973 u16 buf = 0;
5974
5975 if (hw->mac.type != e1000_82573)
5976 return;
5977
5978 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00005979 le16_to_cpus(&buf);
5980 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005981 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005982 dev_warn(&adapter->pdev->dev,
5983 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005984 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005985}
5986
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005987static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00005988 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00005989{
5990 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005991 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00005992
5993 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5994 adapter->flags |= FLAG_TSO_FORCE;
5995
5996 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greear01840392012-02-11 15:39:25 +00005997 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS)))
Bruce Allandc221292011-08-19 03:23:48 +00005998 return 0;
5999
Bruce Allan70495a52012-01-11 01:26:50 +00006000 /*
6001 * IP payload checksum (enabled with jumbos/packet-split when Rx
6002 * checksum is enabled) and generation of RSS hash is mutually
6003 * exclusive in the hardware.
6004 */
6005 if (adapter->rx_ps_pages &&
6006 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
6007 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");
6008 return -EINVAL;
6009 }
6010
Ben Greear01840392012-02-11 15:39:25 +00006011 if (changed & NETIF_F_RXFCS) {
6012 if (features & NETIF_F_RXFCS) {
6013 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6014 } else {
6015 /* We need to take it back to defaults, which might mean
6016 * stripping is still disabled at the adapter level.
6017 */
6018 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6019 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6020 else
6021 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6022 }
6023 }
6024
Bruce Allan70495a52012-01-11 01:26:50 +00006025 netdev->features = features;
6026
Bruce Allandc221292011-08-19 03:23:48 +00006027 if (netif_running(netdev))
6028 e1000e_reinit_locked(adapter);
6029 else
6030 e1000e_reset(adapter);
6031
6032 return 0;
6033}
6034
Stephen Hemminger651c2462008-11-19 21:57:48 -08006035static const struct net_device_ops e1000e_netdev_ops = {
6036 .ndo_open = e1000_open,
6037 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006038 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006039 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006040 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006041 .ndo_set_mac_address = e1000_set_mac,
6042 .ndo_change_mtu = e1000_change_mtu,
6043 .ndo_do_ioctl = e1000_ioctl,
6044 .ndo_tx_timeout = e1000_tx_timeout,
6045 .ndo_validate_addr = eth_validate_addr,
6046
Stephen Hemminger651c2462008-11-19 21:57:48 -08006047 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6048 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6049#ifdef CONFIG_NET_POLL_CONTROLLER
6050 .ndo_poll_controller = e1000_netpoll,
6051#endif
Bruce Allandc221292011-08-19 03:23:48 +00006052 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006053};
6054
Auke Kokbc7f75f2007-09-17 12:30:59 -07006055/**
6056 * e1000_probe - Device Initialization Routine
6057 * @pdev: PCI device information struct
6058 * @ent: entry in e1000_pci_tbl
6059 *
6060 * Returns 0 on success, negative on failure
6061 *
6062 * e1000_probe initializes an adapter identified by a pci_dev structure.
6063 * The OS initialization, configuring of the adapter private structure,
6064 * and a hardware reset occur.
6065 **/
6066static int __devinit e1000_probe(struct pci_dev *pdev,
6067 const struct pci_device_id *ent)
6068{
6069 struct net_device *netdev;
6070 struct e1000_adapter *adapter;
6071 struct e1000_hw *hw;
6072 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006073 resource_size_t mmio_start, mmio_len;
6074 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006075
6076 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006077 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006078 int i, err, pci_using_dac;
6079 u16 eeprom_data = 0;
6080 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6081
Bruce Allan78cd29d2011-03-24 03:09:03 +00006082 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6083 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006084 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006085 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6086 if (aspm_disable_flag)
6087 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006088
Bruce Allanf0f422e2008-08-04 17:21:53 -07006089 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006090 if (err)
6091 return err;
6092
6093 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006094 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006095 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006096 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006097 if (!err)
6098 pci_using_dac = 1;
6099 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006100 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006101 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006102 err = dma_set_coherent_mask(&pdev->dev,
6103 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006104 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006105 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006106 goto err_dma;
6107 }
6108 }
6109 }
6110
Arjan van de Vene8de1482008-10-22 19:55:31 -07006111 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006112 pci_select_bars(pdev, IORESOURCE_MEM),
6113 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006114 if (err)
6115 goto err_pci_reg;
6116
Xiaotian Feng68eac462009-08-14 14:35:52 +00006117 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006118 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006119
Auke Kokbc7f75f2007-09-17 12:30:59 -07006120 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006121 /* PCI config space info */
6122 err = pci_save_state(pdev);
6123 if (err)
6124 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006125
6126 err = -ENOMEM;
6127 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6128 if (!netdev)
6129 goto err_alloc_etherdev;
6130
Auke Kokbc7f75f2007-09-17 12:30:59 -07006131 SET_NETDEV_DEV(netdev, &pdev->dev);
6132
Tom Herbertf85e4df2010-05-05 14:03:32 +00006133 netdev->irq = pdev->irq;
6134
Auke Kokbc7f75f2007-09-17 12:30:59 -07006135 pci_set_drvdata(pdev, netdev);
6136 adapter = netdev_priv(netdev);
6137 hw = &adapter->hw;
6138 adapter->netdev = netdev;
6139 adapter->pdev = pdev;
6140 adapter->ei = ei;
6141 adapter->pba = ei->pba;
6142 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006143 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006144 adapter->hw.adapter = adapter;
6145 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006146 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006147 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6148
6149 mmio_start = pci_resource_start(pdev, 0);
6150 mmio_len = pci_resource_len(pdev, 0);
6151
6152 err = -EIO;
6153 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6154 if (!adapter->hw.hw_addr)
6155 goto err_ioremap;
6156
6157 if ((adapter->flags & FLAG_HAS_FLASH) &&
6158 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6159 flash_start = pci_resource_start(pdev, 1);
6160 flash_len = pci_resource_len(pdev, 1);
6161 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6162 if (!adapter->hw.flash_address)
6163 goto err_flashmap;
6164 }
6165
6166 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006167 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006168 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006169 netdev->watchdog_timeo = 5 * HZ;
6170 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006171 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006172
6173 netdev->mem_start = mmio_start;
6174 netdev->mem_end = mmio_start + mmio_len;
6175
6176 adapter->bd_number = cards_found++;
6177
Bruce Allan4662e822008-08-26 18:37:06 -07006178 e1000e_check_options(adapter);
6179
Auke Kokbc7f75f2007-09-17 12:30:59 -07006180 /* setup adapter struct */
6181 err = e1000_sw_init(adapter);
6182 if (err)
6183 goto err_sw_init;
6184
Auke Kokbc7f75f2007-09-17 12:30:59 -07006185 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6186 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6187 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6188
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006189 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006190 if (err)
6191 goto err_hw_init;
6192
Bruce Allan4a770352008-10-01 17:18:35 -07006193 if ((adapter->flags & FLAG_IS_ICH) &&
6194 (adapter->flags & FLAG_READ_ONLY_NVM))
6195 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6196
Auke Kokbc7f75f2007-09-17 12:30:59 -07006197 hw->mac.ops.get_bus_info(&adapter->hw);
6198
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006199 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006200
6201 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006202 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006203 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6204 adapter->hw.phy.disable_polarity_correction = 0;
6205 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6206 }
6207
6208 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006209 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006210
Bruce Allandc221292011-08-19 03:23:48 +00006211 /* Set initial default active device features */
6212 netdev->features = (NETIF_F_SG |
6213 NETIF_F_HW_VLAN_RX |
6214 NETIF_F_HW_VLAN_TX |
6215 NETIF_F_TSO |
6216 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006217 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006218 NETIF_F_RXCSUM |
6219 NETIF_F_HW_CSUM);
6220
6221 /* Set user-changeable features (subset of all device features) */
6222 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006223 netdev->hw_features |= NETIF_F_RXFCS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006224
6225 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6226 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6227
Bruce Allandc221292011-08-19 03:23:48 +00006228 netdev->vlan_features |= (NETIF_F_SG |
6229 NETIF_F_TSO |
6230 NETIF_F_TSO6 |
6231 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006232
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006233 netdev->priv_flags |= IFF_UNICAST_FLT;
6234
Yi Zou7b872a52010-09-22 17:57:58 +00006235 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006236 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006237 netdev->vlan_features |= NETIF_F_HIGHDMA;
6238 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006239
Auke Kokbc7f75f2007-09-17 12:30:59 -07006240 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6241 adapter->flags |= FLAG_MNG_PT_ENABLED;
6242
Bruce Allanad680762008-03-28 09:15:03 -07006243 /*
6244 * before reading the NVM, reset the controller to
6245 * put the device in a known good starting state
6246 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006247 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6248
6249 /*
6250 * systems with ASPM and others may see the checksum fail on the first
6251 * attempt. Let's give it a few tries
6252 */
6253 for (i = 0;; i++) {
6254 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6255 break;
6256 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006257 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006258 err = -EIO;
6259 goto err_eeprom;
6260 }
6261 }
6262
Auke Kok10aa4c02008-08-04 17:21:20 -07006263 e1000_eeprom_checks(adapter);
6264
Bruce Allan608f8a02010-01-13 02:04:58 +00006265 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006266 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006267 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006268
6269 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6270 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6271
6272 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006273 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006274 err = -EIO;
6275 goto err_eeprom;
6276 }
6277
6278 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006279 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006280 adapter->watchdog_timer.data = (unsigned long) adapter;
6281
6282 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006283 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006284 adapter->phy_info_timer.data = (unsigned long) adapter;
6285
6286 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6287 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006288 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6289 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006290 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006291
Auke Kokbc7f75f2007-09-17 12:30:59 -07006292 /* Initialize link parameters. User can change them with ethtool */
6293 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006294 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006295 adapter->hw.fc.requested_mode = e1000_fc_default;
6296 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006297 adapter->hw.phy.autoneg_advertised = 0x2f;
6298
6299 /* ring size defaults */
6300 adapter->rx_ring->count = 256;
6301 adapter->tx_ring->count = 256;
6302
6303 /*
6304 * Initial Wake on LAN setting - If APM wake is enabled in
6305 * the EEPROM, enable the ACPI Magic Packet filter
6306 */
6307 if (adapter->flags & FLAG_APME_IN_WUC) {
6308 /* APME bit in EEPROM is mapped to WUC.APME */
6309 eeprom_data = er32(WUC);
6310 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006311 if ((hw->mac.type > e1000_ich10lan) &&
6312 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006313 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006314 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6315 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6316 (adapter->hw.bus.func == 1))
6317 e1000_read_nvm(&adapter->hw,
6318 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6319 else
6320 e1000_read_nvm(&adapter->hw,
6321 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6322 }
6323
6324 /* fetch WoL from EEPROM */
6325 if (eeprom_data & eeprom_apme_mask)
6326 adapter->eeprom_wol |= E1000_WUFC_MAG;
6327
6328 /*
6329 * now that we have the eeprom settings, apply the special cases
6330 * where the eeprom may be wrong or the board simply won't support
6331 * wake on lan on a particular port
6332 */
6333 if (!(adapter->flags & FLAG_HAS_WOL))
6334 adapter->eeprom_wol = 0;
6335
6336 /* initialize the wol settings based on the eeprom settings */
6337 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006338 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006339
Bruce Allan84527592008-11-21 17:00:22 -08006340 /* save off EEPROM version number */
6341 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6342
Auke Kokbc7f75f2007-09-17 12:30:59 -07006343 /* reset the hardware with the new settings */
6344 e1000e_reset(adapter);
6345
Bruce Allanad680762008-03-28 09:15:03 -07006346 /*
6347 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006348 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006349 * under the control of the driver.
6350 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006351 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006352 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006353
Bruce Allanf2315bf2011-12-16 00:46:59 +00006354 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006355 err = register_netdev(netdev);
6356 if (err)
6357 goto err_register;
6358
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006359 /* carrier off reporting is important to ethtool even BEFORE open */
6360 netif_carrier_off(netdev);
6361
Auke Kokbc7f75f2007-09-17 12:30:59 -07006362 e1000_print_device_info(adapter);
6363
Alan Sternf3ec4f82010-06-08 15:23:51 -04006364 if (pci_dev_run_wake(pdev))
6365 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006366
Auke Kokbc7f75f2007-09-17 12:30:59 -07006367 return 0;
6368
6369err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006370 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006371 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006372err_eeprom:
6373 if (!e1000_check_reset_block(&adapter->hw))
6374 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006375err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006376 kfree(adapter->tx_ring);
6377 kfree(adapter->rx_ring);
6378err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006379 if (adapter->hw.flash_address)
6380 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006381 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006382err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006383 iounmap(adapter->hw.hw_addr);
6384err_ioremap:
6385 free_netdev(netdev);
6386err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006387 pci_release_selected_regions(pdev,
6388 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006389err_pci_reg:
6390err_dma:
6391 pci_disable_device(pdev);
6392 return err;
6393}
6394
6395/**
6396 * e1000_remove - Device Removal Routine
6397 * @pdev: PCI device information struct
6398 *
6399 * e1000_remove is called by the PCI subsystem to alert the driver
6400 * that it should release a PCI device. The could be caused by a
6401 * Hot-Plug event, or because the driver is going to be removed from
6402 * memory.
6403 **/
6404static void __devexit e1000_remove(struct pci_dev *pdev)
6405{
6406 struct net_device *netdev = pci_get_drvdata(pdev);
6407 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006408 bool down = test_bit(__E1000_DOWN, &adapter->state);
6409
Bruce Allanad680762008-03-28 09:15:03 -07006410 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006411 * The timers may be rescheduled, so explicitly disable them
6412 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006413 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006414 if (!down)
6415 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006416 del_timer_sync(&adapter->watchdog_timer);
6417 del_timer_sync(&adapter->phy_info_timer);
6418
Bruce Allan41cec6f2009-11-20 23:28:56 +00006419 cancel_work_sync(&adapter->reset_task);
6420 cancel_work_sync(&adapter->watchdog_task);
6421 cancel_work_sync(&adapter->downshift_task);
6422 cancel_work_sync(&adapter->update_phy_task);
6423 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006424
Bruce Allan17f208d2009-12-01 15:47:22 +00006425 if (!(netdev->flags & IFF_UP))
6426 e1000_power_down_phy(adapter);
6427
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006428 /* Don't lie to e1000_close() down the road. */
6429 if (!down)
6430 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006431 unregister_netdev(netdev);
6432
Alan Sternf3ec4f82010-06-08 15:23:51 -04006433 if (pci_dev_run_wake(pdev))
6434 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006435
Bruce Allanad680762008-03-28 09:15:03 -07006436 /*
6437 * Release control of h/w to f/w. If f/w is AMT enabled, this
6438 * would have already happened in close and is redundant.
6439 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006440 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006441
Bruce Allan4662e822008-08-26 18:37:06 -07006442 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006443 kfree(adapter->tx_ring);
6444 kfree(adapter->rx_ring);
6445
6446 iounmap(adapter->hw.hw_addr);
6447 if (adapter->hw.flash_address)
6448 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006449 pci_release_selected_regions(pdev,
6450 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006451
6452 free_netdev(netdev);
6453
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006454 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006455 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006456
Auke Kokbc7f75f2007-09-17 12:30:59 -07006457 pci_disable_device(pdev);
6458}
6459
6460/* PCI Error Recovery (ERS) */
6461static struct pci_error_handlers e1000_err_handler = {
6462 .error_detected = e1000_io_error_detected,
6463 .slot_reset = e1000_io_slot_reset,
6464 .resume = e1000_io_resume,
6465};
6466
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006467static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006468 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6469 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6470 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6471 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6472 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6473 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006474 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6475 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6476 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006477
Auke Kokbc7f75f2007-09-17 12:30:59 -07006478 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6479 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6480 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6481 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006482
Auke Kokbc7f75f2007-09-17 12:30:59 -07006483 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6484 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6485 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006486
Bruce Allan4662e822008-08-26 18:37:06 -07006487 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006488 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006489 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006490
Auke Kokbc7f75f2007-09-17 12:30:59 -07006491 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6492 board_80003es2lan },
6493 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6494 board_80003es2lan },
6495 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6496 board_80003es2lan },
6497 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6498 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006499
Auke Kokbc7f75f2007-09-17 12:30:59 -07006500 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6501 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6502 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6503 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6504 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6505 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6506 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006507 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006508
Auke Kokbc7f75f2007-09-17 12:30:59 -07006509 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6510 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6511 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6512 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6513 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006514 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006515 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6516 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6517 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6518
6519 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6520 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6521 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006522
Bruce Allanf4187b52008-08-26 18:36:50 -07006523 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6524 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006525 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006526
Bruce Allana4f58f52009-06-02 11:29:18 +00006527 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6528 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6529 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6530 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6531
Bruce Alland3738bb2010-06-16 13:27:28 +00006532 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6533 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6534
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006535 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006536};
6537MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6538
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006539#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006540static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006541 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6542 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6543 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006544};
David S. Millere50208a2010-03-16 23:36:24 -07006545#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006546
Auke Kokbc7f75f2007-09-17 12:30:59 -07006547/* PCI Device API Driver */
6548static struct pci_driver e1000_driver = {
6549 .name = e1000e_driver_name,
6550 .id_table = e1000_pci_tbl,
6551 .probe = e1000_probe,
6552 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006553#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006554 .driver = {
6555 .pm = &e1000_pm_ops,
6556 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006557#endif
6558 .shutdown = e1000_shutdown,
6559 .err_handler = &e1000_err_handler
6560};
6561
6562/**
6563 * e1000_init_module - Driver Registration Routine
6564 *
6565 * e1000_init_module is the first routine called when the driver is
6566 * loaded. All it does is register with the PCI subsystem.
6567 **/
6568static int __init e1000_init_module(void)
6569{
6570 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006571 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6572 e1000e_driver_version);
Bruce Allanf5e261e2012-01-01 16:00:03 +00006573 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006574 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006575
Auke Kokbc7f75f2007-09-17 12:30:59 -07006576 return ret;
6577}
6578module_init(e1000_init_module);
6579
6580/**
6581 * e1000_exit_module - Driver Exit Cleanup Routine
6582 *
6583 * e1000_exit_module is called just before the driver is removed
6584 * from memory.
6585 **/
6586static void __exit e1000_exit_module(void)
6587{
6588 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006589}
6590module_exit(e1000_exit_module);
6591
6592
6593MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6594MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6595MODULE_LICENSE("GPL");
6596MODULE_VERSION(DRV_VERSION);
6597
6598/* e1000_main.c */