blob: c079b9b0810d2dc792b77e559d9cb0ebb5e92ebd [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 */
936 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
937 length -= 4;
938
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939 total_rx_bytes += length;
940 total_rx_packets++;
941
Bruce Allanad680762008-03-28 09:15:03 -0700942 /*
943 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700944 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700945 * of reassembly being done in the stack
946 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947 if (length < copybreak) {
948 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000949 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700950 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700951 skb_copy_to_linear_data_offset(new_skb,
952 -NET_IP_ALIGN,
953 (skb->data -
954 NET_IP_ALIGN),
955 (length +
956 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957 /* save the skb in buffer_info as good */
958 buffer_info->skb = skb;
959 skb = new_skb;
960 }
961 /* else just continue with the old one */
962 }
963 /* end copybreak code */
964 skb_put(skb, length);
965
966 /* Receive Checksum Offload */
Bruce Allan5f450212011-07-22 06:21:46 +0000967 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +0000968 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700969
Bruce Allan70495a52012-01-11 01:26:50 +0000970 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
971
Bruce Allan5f450212011-07-22 06:21:46 +0000972 e1000_receive_skb(adapter, netdev, skb, staterr,
973 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700974
975next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +0000976 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700977
978 /* return some buffers to hardware, one at a time is too slow */
979 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +0000980 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000981 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 cleaned_count = 0;
983 }
984
985 /* use prefetched values */
986 rx_desc = next_rxd;
987 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000988
989 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 }
991 rx_ring->next_to_clean = i;
992
993 cleaned_count = e1000_desc_unused(rx_ring);
994 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +0000995 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700996
Auke Kokbc7f75f2007-09-17 12:30:59 -0700997 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700998 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999 return cleaned;
1000}
1001
Bruce Allan55aa6982011-12-16 00:45:45 +00001002static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1003 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001004{
Bruce Allan55aa6982011-12-16 00:45:45 +00001005 struct e1000_adapter *adapter = tx_ring->adapter;
1006
Alexander Duyck03b13202009-12-02 16:45:31 +00001007 if (buffer_info->dma) {
1008 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001009 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1010 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001011 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001012 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1013 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001014 buffer_info->dma = 0;
1015 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001016 if (buffer_info->skb) {
1017 dev_kfree_skb_any(buffer_info->skb);
1018 buffer_info->skb = NULL;
1019 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001020 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001021}
1022
Bruce Allan41cec6f2009-11-20 23:28:56 +00001023static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001025 struct e1000_adapter *adapter = container_of(work,
1026 struct e1000_adapter,
1027 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001028 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001029 struct e1000_ring *tx_ring = adapter->tx_ring;
1030 unsigned int i = tx_ring->next_to_clean;
1031 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1032 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001033 struct e1000_hw *hw = &adapter->hw;
1034 u16 phy_status, phy_1000t_status, phy_ext_status;
1035 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001037 if (test_bit(__E1000_DOWN, &adapter->state))
1038 return;
1039
Jeff Kirsher09357b02011-11-18 14:25:00 +00001040 if (!adapter->tx_hang_recheck &&
1041 (adapter->flags2 & FLAG2_DMA_BURST)) {
1042 /* May be block on write-back, flush and detect again
1043 * flush pending descriptor writebacks to memory
1044 */
1045 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1046 /* execute the writes immediately */
1047 e1e_flush();
1048 adapter->tx_hang_recheck = true;
1049 return;
1050 }
1051 /* Real hang detected */
1052 adapter->tx_hang_recheck = false;
1053 netif_stop_queue(netdev);
1054
Bruce Allan41cec6f2009-11-20 23:28:56 +00001055 e1e_rphy(hw, PHY_STATUS, &phy_status);
1056 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1057 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1058
1059 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1060
1061 /* detected Hardware unit hang */
1062 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001063 " TDH <%x>\n"
1064 " TDT <%x>\n"
1065 " next_to_use <%x>\n"
1066 " next_to_clean <%x>\n"
1067 "buffer_info[next_to_clean]:\n"
1068 " time_stamp <%lx>\n"
1069 " next_to_watch <%x>\n"
1070 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001071 " next_to_watch.status <%x>\n"
1072 "MAC Status <%x>\n"
1073 "PHY Status <%x>\n"
1074 "PHY 1000BASE-T Status <%x>\n"
1075 "PHY Extended Status <%x>\n"
1076 "PCI Status <%x>\n",
Bruce Allanc5083cf2011-12-16 00:45:40 +00001077 readl(tx_ring->head),
1078 readl(tx_ring->tail),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001079 tx_ring->next_to_use,
1080 tx_ring->next_to_clean,
1081 tx_ring->buffer_info[eop].time_stamp,
1082 eop,
1083 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001084 eop_desc->upper.fields.status,
1085 er32(STATUS),
1086 phy_status,
1087 phy_1000t_status,
1088 phy_ext_status,
1089 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001090}
1091
1092/**
1093 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001094 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095 *
1096 * the return value indicates whether actual cleaning was done, there
1097 * is no guarantee that everything was cleaned
1098 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001099static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001100{
Bruce Allan55aa6982011-12-16 00:45:45 +00001101 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102 struct net_device *netdev = adapter->netdev;
1103 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001104 struct e1000_tx_desc *tx_desc, *eop_desc;
1105 struct e1000_buffer *buffer_info;
1106 unsigned int i, eop;
1107 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001108 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001109 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001110
1111 i = tx_ring->next_to_clean;
1112 eop = tx_ring->buffer_info[i].next_to_watch;
1113 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1114
Alexander Duyck12d04a32009-03-25 22:05:03 +00001115 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1116 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001117 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001118 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001119 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001120 tx_desc = E1000_TX_DESC(*tx_ring, i);
1121 buffer_info = &tx_ring->buffer_info[i];
1122 cleaned = (i == eop);
1123
1124 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001125 total_tx_packets += buffer_info->segs;
1126 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001127 if (buffer_info->skb) {
1128 bytes_compl += buffer_info->skb->len;
1129 pkts_compl++;
1130 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001131 }
1132
Bruce Allan55aa6982011-12-16 00:45:45 +00001133 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001134 tx_desc->upper.data = 0;
1135
1136 i++;
1137 if (i == tx_ring->count)
1138 i = 0;
1139 }
1140
Terry Loftindac87612010-04-09 10:29:49 +00001141 if (i == tx_ring->next_to_use)
1142 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143 eop = tx_ring->buffer_info[i].next_to_watch;
1144 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001145 }
1146
1147 tx_ring->next_to_clean = i;
1148
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001149 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1150
Auke Kokbc7f75f2007-09-17 12:30:59 -07001151#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001152 if (count && netif_carrier_ok(netdev) &&
1153 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001154 /* Make sure that anybody stopping the queue after this
1155 * sees the new next_to_clean.
1156 */
1157 smp_mb();
1158
1159 if (netif_queue_stopped(netdev) &&
1160 !(test_bit(__E1000_DOWN, &adapter->state))) {
1161 netif_wake_queue(netdev);
1162 ++adapter->restart_queue;
1163 }
1164 }
1165
1166 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001167 /*
1168 * Detect a transmit hang in hardware, this serializes the
1169 * check with the clearing of time_stamp and movement of i
1170 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001171 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001172 if (tx_ring->buffer_info[i].time_stamp &&
1173 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001174 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001175 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001176 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001177 else
1178 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001179 }
1180 adapter->total_tx_bytes += total_tx_bytes;
1181 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001182 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001183}
1184
1185/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001187 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001188 *
1189 * the return value indicates whether actual cleaning was done, there
1190 * is no guarantee that everything was cleaned
1191 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001192static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1193 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001194{
Bruce Allan55aa6982011-12-16 00:45:45 +00001195 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001196 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001197 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1198 struct net_device *netdev = adapter->netdev;
1199 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 struct e1000_buffer *buffer_info, *next_buffer;
1201 struct e1000_ps_page *ps_page;
1202 struct sk_buff *skb;
1203 unsigned int i, j;
1204 u32 length, staterr;
1205 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001206 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001207 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1208
1209 i = rx_ring->next_to_clean;
1210 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1211 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1212 buffer_info = &rx_ring->buffer_info[i];
1213
1214 while (staterr & E1000_RXD_STAT_DD) {
1215 if (*work_done >= work_to_do)
1216 break;
1217 (*work_done)++;
1218 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001219 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001220
1221 /* in the packet split case this is header only */
1222 prefetch(skb->data - NET_IP_ALIGN);
1223
1224 i++;
1225 if (i == rx_ring->count)
1226 i = 0;
1227 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1228 prefetch(next_rxd);
1229
1230 next_buffer = &rx_ring->buffer_info[i];
1231
Rusty Russell3db1cd52011-12-19 13:56:45 +00001232 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001234 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001235 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001236 buffer_info->dma = 0;
1237
Bruce Allanaf667a22010-12-31 06:10:01 +00001238 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001239 if (!(staterr & E1000_RXD_STAT_EOP))
1240 adapter->flags2 |= FLAG2_IS_DISCARDING;
1241
1242 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001243 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001245 if (staterr & E1000_RXD_STAT_EOP)
1246 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001247 goto next_desc;
1248 }
1249
1250 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1251 dev_kfree_skb_irq(skb);
1252 goto next_desc;
1253 }
1254
1255 length = le16_to_cpu(rx_desc->wb.middle.length0);
1256
1257 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001258 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001259 dev_kfree_skb_irq(skb);
1260 goto next_desc;
1261 }
1262
1263 /* Good Receive */
1264 skb_put(skb, length);
1265
1266 {
Bruce Allan0e15df42012-01-31 06:37:11 +00001267 /*
1268 * this looks ugly, but it seems compiler issues make
1269 * it more efficient than reusing j
1270 */
1271 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001272
Bruce Allanad680762008-03-28 09:15:03 -07001273 /*
Bruce Allan0e15df42012-01-31 06:37:11 +00001274 * page alloc/put takes too long and effects small
1275 * packet throughput, so unsplit small packets and
1276 * save the alloc/put only valid in softirq (napi)
1277 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001278 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001279 if (l1 && (l1 <= copybreak) &&
1280 ((length + l1) <= adapter->rx_ps_bsize0)) {
1281 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001282
Bruce Allan0e15df42012-01-31 06:37:11 +00001283 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001284
Bruce Allan0e15df42012-01-31 06:37:11 +00001285 /*
1286 * there is no documentation about how to call
1287 * kmap_atomic, so we can't hold the mapping
1288 * very long
1289 */
1290 dma_sync_single_for_cpu(&pdev->dev,
1291 ps_page->dma,
1292 PAGE_SIZE,
1293 DMA_FROM_DEVICE);
1294 vaddr = kmap_atomic(ps_page->page,
1295 KM_SKB_DATA_SOFTIRQ);
1296 memcpy(skb_tail_pointer(skb), vaddr, l1);
1297 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
1298 dma_sync_single_for_device(&pdev->dev,
1299 ps_page->dma,
1300 PAGE_SIZE,
1301 DMA_FROM_DEVICE);
1302
1303 /* remove the CRC */
1304 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1305 l1 -= 4;
1306
1307 skb_put(skb, l1);
1308 goto copydone;
1309 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001310 }
1311
1312 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1313 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1314 if (!length)
1315 break;
1316
Auke Kok47f44e42007-10-25 13:57:44 -07001317 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001318 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1319 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001320 ps_page->dma = 0;
1321 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1322 ps_page->page = NULL;
1323 skb->len += length;
1324 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001325 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001326 }
1327
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001328 /* strip the ethernet crc, problem is we're using pages now so
1329 * this whole operation can get a little cpu intensive
1330 */
1331 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1332 pskb_trim(skb, skb->len - 4);
1333
Auke Kokbc7f75f2007-09-17 12:30:59 -07001334copydone:
1335 total_rx_bytes += skb->len;
1336 total_rx_packets++;
1337
Bruce Allanafd12932012-01-05 00:34:05 +00001338 e1000_rx_checksum(adapter, staterr,
1339 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001340
Bruce Allan70495a52012-01-11 01:26:50 +00001341 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1342
Auke Kokbc7f75f2007-09-17 12:30:59 -07001343 if (rx_desc->wb.upper.header_status &
1344 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1345 adapter->rx_hdr_split++;
1346
1347 e1000_receive_skb(adapter, netdev, skb,
1348 staterr, rx_desc->wb.middle.vlan);
1349
1350next_desc:
1351 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1352 buffer_info->skb = NULL;
1353
1354 /* return some buffers to hardware, one at a time is too slow */
1355 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001356 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001357 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001358 cleaned_count = 0;
1359 }
1360
1361 /* use prefetched values */
1362 rx_desc = next_rxd;
1363 buffer_info = next_buffer;
1364
1365 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1366 }
1367 rx_ring->next_to_clean = i;
1368
1369 cleaned_count = e1000_desc_unused(rx_ring);
1370 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001371 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001372
Auke Kokbc7f75f2007-09-17 12:30:59 -07001373 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001374 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001375 return cleaned;
1376}
1377
1378/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001379 * e1000_consume_page - helper function
1380 **/
1381static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1382 u16 length)
1383{
1384 bi->page = NULL;
1385 skb->len += length;
1386 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001387 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001388}
1389
1390/**
1391 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1392 * @adapter: board private structure
1393 *
1394 * the return value indicates whether actual cleaning was done, there
1395 * is no guarantee that everything was cleaned
1396 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001397static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1398 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001399{
Bruce Allan55aa6982011-12-16 00:45:45 +00001400 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001401 struct net_device *netdev = adapter->netdev;
1402 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001403 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001404 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001405 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001406 unsigned int i;
1407 int cleaned_count = 0;
1408 bool cleaned = false;
1409 unsigned int total_rx_bytes=0, total_rx_packets=0;
1410
1411 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001412 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1413 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001414 buffer_info = &rx_ring->buffer_info[i];
1415
Bruce Allan5f450212011-07-22 06:21:46 +00001416 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001417 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001418
1419 if (*work_done >= work_to_do)
1420 break;
1421 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001422 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001423
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001424 skb = buffer_info->skb;
1425 buffer_info->skb = NULL;
1426
1427 ++i;
1428 if (i == rx_ring->count)
1429 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001430 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001431 prefetch(next_rxd);
1432
1433 next_buffer = &rx_ring->buffer_info[i];
1434
1435 cleaned = true;
1436 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001437 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1438 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001439 buffer_info->dma = 0;
1440
Bruce Allan5f450212011-07-22 06:21:46 +00001441 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001442
1443 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001444 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1445 (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
1446 /* recycle both page and skb */
1447 buffer_info->skb = skb;
1448 /* an error means any chain goes out the window too */
1449 if (rx_ring->rx_skb_top)
1450 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1451 rx_ring->rx_skb_top = NULL;
1452 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001453 }
1454
Bruce Allanf0f1a172010-12-11 05:53:32 +00001455#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001456 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001457 /* this descriptor is only the beginning (or middle) */
1458 if (!rxtop) {
1459 /* this is the beginning of a chain */
1460 rxtop = skb;
1461 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1462 0, length);
1463 } else {
1464 /* this is the middle of a chain */
1465 skb_fill_page_desc(rxtop,
1466 skb_shinfo(rxtop)->nr_frags,
1467 buffer_info->page, 0, length);
1468 /* re-use the skb, only consumed the page */
1469 buffer_info->skb = skb;
1470 }
1471 e1000_consume_page(buffer_info, rxtop, length);
1472 goto next_desc;
1473 } else {
1474 if (rxtop) {
1475 /* end of the chain */
1476 skb_fill_page_desc(rxtop,
1477 skb_shinfo(rxtop)->nr_frags,
1478 buffer_info->page, 0, length);
1479 /* re-use the current skb, we only consumed the
1480 * page */
1481 buffer_info->skb = skb;
1482 skb = rxtop;
1483 rxtop = NULL;
1484 e1000_consume_page(buffer_info, skb, length);
1485 } else {
1486 /* no chain, got EOP, this buf is the packet
1487 * copybreak to save the put_page/alloc_page */
1488 if (length <= copybreak &&
1489 skb_tailroom(skb) >= length) {
1490 u8 *vaddr;
1491 vaddr = kmap_atomic(buffer_info->page,
1492 KM_SKB_DATA_SOFTIRQ);
1493 memcpy(skb_tail_pointer(skb), vaddr,
1494 length);
1495 kunmap_atomic(vaddr,
1496 KM_SKB_DATA_SOFTIRQ);
1497 /* re-use the page, so don't erase
1498 * buffer_info->page */
1499 skb_put(skb, length);
1500 } else {
1501 skb_fill_page_desc(skb, 0,
1502 buffer_info->page, 0,
1503 length);
1504 e1000_consume_page(buffer_info, skb,
1505 length);
1506 }
1507 }
1508 }
1509
1510 /* Receive Checksum Offload XXX recompute due to CRC strip? */
Bruce Allan5f450212011-07-22 06:21:46 +00001511 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +00001512 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001513
Bruce Allan70495a52012-01-11 01:26:50 +00001514 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1515
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001516 /* probably a little skewed due to removing CRC */
1517 total_rx_bytes += skb->len;
1518 total_rx_packets++;
1519
1520 /* eth type trans needs skb->data to point to something */
1521 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001522 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001523 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001524 goto next_desc;
1525 }
1526
Bruce Allan5f450212011-07-22 06:21:46 +00001527 e1000_receive_skb(adapter, netdev, skb, staterr,
1528 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001529
1530next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001531 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001532
1533 /* return some buffers to hardware, one at a time is too slow */
1534 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001535 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001536 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001537 cleaned_count = 0;
1538 }
1539
1540 /* use prefetched values */
1541 rx_desc = next_rxd;
1542 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001543
1544 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001545 }
1546 rx_ring->next_to_clean = i;
1547
1548 cleaned_count = e1000_desc_unused(rx_ring);
1549 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001550 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001551
1552 adapter->total_rx_bytes += total_rx_bytes;
1553 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001554 return cleaned;
1555}
1556
1557/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001558 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001559 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001560 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001561static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562{
Bruce Allan55aa6982011-12-16 00:45:45 +00001563 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001564 struct e1000_buffer *buffer_info;
1565 struct e1000_ps_page *ps_page;
1566 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001567 unsigned int i, j;
1568
1569 /* Free all the Rx ring sk_buffs */
1570 for (i = 0; i < rx_ring->count; i++) {
1571 buffer_info = &rx_ring->buffer_info[i];
1572 if (buffer_info->dma) {
1573 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001574 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001575 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001576 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001577 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001578 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001579 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001580 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001581 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001582 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001583 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001584 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585 buffer_info->dma = 0;
1586 }
1587
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001588 if (buffer_info->page) {
1589 put_page(buffer_info->page);
1590 buffer_info->page = NULL;
1591 }
1592
Auke Kokbc7f75f2007-09-17 12:30:59 -07001593 if (buffer_info->skb) {
1594 dev_kfree_skb(buffer_info->skb);
1595 buffer_info->skb = NULL;
1596 }
1597
1598 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001599 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001600 if (!ps_page->page)
1601 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001602 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1603 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001604 ps_page->dma = 0;
1605 put_page(ps_page->page);
1606 ps_page->page = NULL;
1607 }
1608 }
1609
1610 /* there also may be some cached data from a chained receive */
1611 if (rx_ring->rx_skb_top) {
1612 dev_kfree_skb(rx_ring->rx_skb_top);
1613 rx_ring->rx_skb_top = NULL;
1614 }
1615
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616 /* Zero out the descriptor ring */
1617 memset(rx_ring->desc, 0, rx_ring->size);
1618
1619 rx_ring->next_to_clean = 0;
1620 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001621 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001622
Bruce Allanc5083cf2011-12-16 00:45:40 +00001623 writel(0, rx_ring->head);
1624 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001625}
1626
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001627static void e1000e_downshift_workaround(struct work_struct *work)
1628{
1629 struct e1000_adapter *adapter = container_of(work,
1630 struct e1000_adapter, downshift_task);
1631
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001632 if (test_bit(__E1000_DOWN, &adapter->state))
1633 return;
1634
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001635 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1636}
1637
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638/**
1639 * e1000_intr_msi - Interrupt Handler
1640 * @irq: interrupt number
1641 * @data: pointer to a network interface device structure
1642 **/
1643static irqreturn_t e1000_intr_msi(int irq, void *data)
1644{
1645 struct net_device *netdev = data;
1646 struct e1000_adapter *adapter = netdev_priv(netdev);
1647 struct e1000_hw *hw = &adapter->hw;
1648 u32 icr = er32(ICR);
1649
Bruce Allanad680762008-03-28 09:15:03 -07001650 /*
1651 * read ICR disables interrupts using IAM
1652 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001653
dave graham573cca82009-02-10 12:52:05 +00001654 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001655 hw->mac.get_link_status = true;
Bruce Allanad680762008-03-28 09:15:03 -07001656 /*
1657 * ICH8 workaround-- Call gig speed drop workaround on cable
1658 * disconnect (LSC) before accessing any PHY registers
1659 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001660 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1661 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001662 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001663
Bruce Allanad680762008-03-28 09:15:03 -07001664 /*
1665 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001667 * adapter in watchdog
1668 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001669 if (netif_carrier_ok(netdev) &&
1670 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1671 /* disable receives */
1672 u32 rctl = er32(RCTL);
1673 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001674 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001675 }
1676 /* guard against interrupt when we're going down */
1677 if (!test_bit(__E1000_DOWN, &adapter->state))
1678 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1679 }
1680
Ben Hutchings288379f2009-01-19 16:43:59 -08001681 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001682 adapter->total_tx_bytes = 0;
1683 adapter->total_tx_packets = 0;
1684 adapter->total_rx_bytes = 0;
1685 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001686 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687 }
1688
1689 return IRQ_HANDLED;
1690}
1691
1692/**
1693 * e1000_intr - Interrupt Handler
1694 * @irq: interrupt number
1695 * @data: pointer to a network interface device structure
1696 **/
1697static irqreturn_t e1000_intr(int irq, void *data)
1698{
1699 struct net_device *netdev = data;
1700 struct e1000_adapter *adapter = netdev_priv(netdev);
1701 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001702 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001703
Bruce Allana68ea772009-11-20 23:23:16 +00001704 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705 return IRQ_NONE; /* Not our interrupt */
1706
Bruce Allanad680762008-03-28 09:15:03 -07001707 /*
1708 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1709 * not set, then the adapter didn't send an interrupt
1710 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001711 if (!(icr & E1000_ICR_INT_ASSERTED))
1712 return IRQ_NONE;
1713
Bruce Allanad680762008-03-28 09:15:03 -07001714 /*
1715 * Interrupt Auto-Mask...upon reading ICR,
1716 * interrupts are masked. No need for the
1717 * IMC write
1718 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001719
dave graham573cca82009-02-10 12:52:05 +00001720 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001721 hw->mac.get_link_status = true;
Bruce Allanad680762008-03-28 09:15:03 -07001722 /*
1723 * ICH8 workaround-- Call gig speed drop workaround on cable
1724 * disconnect (LSC) before accessing any PHY registers
1725 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001726 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1727 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001728 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001729
Bruce Allanad680762008-03-28 09:15:03 -07001730 /*
1731 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001732 * For packet buffer work-around on link down event;
1733 * disable receives here in the ISR and
1734 * reset adapter in watchdog
1735 */
1736 if (netif_carrier_ok(netdev) &&
1737 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1738 /* disable receives */
1739 rctl = er32(RCTL);
1740 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001741 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001742 }
1743 /* guard against interrupt when we're going down */
1744 if (!test_bit(__E1000_DOWN, &adapter->state))
1745 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1746 }
1747
Ben Hutchings288379f2009-01-19 16:43:59 -08001748 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001749 adapter->total_tx_bytes = 0;
1750 adapter->total_tx_packets = 0;
1751 adapter->total_rx_bytes = 0;
1752 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001753 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001754 }
1755
1756 return IRQ_HANDLED;
1757}
1758
Bruce Allan4662e822008-08-26 18:37:06 -07001759static irqreturn_t e1000_msix_other(int irq, void *data)
1760{
1761 struct net_device *netdev = data;
1762 struct e1000_adapter *adapter = netdev_priv(netdev);
1763 struct e1000_hw *hw = &adapter->hw;
1764 u32 icr = er32(ICR);
1765
1766 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001767 if (!test_bit(__E1000_DOWN, &adapter->state))
1768 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001769 return IRQ_NONE;
1770 }
1771
1772 if (icr & adapter->eiac_mask)
1773 ew32(ICS, (icr & adapter->eiac_mask));
1774
1775 if (icr & E1000_ICR_OTHER) {
1776 if (!(icr & E1000_ICR_LSC))
1777 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001778 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001779 /* guard against interrupt when we're going down */
1780 if (!test_bit(__E1000_DOWN, &adapter->state))
1781 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1782 }
1783
1784no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001785 if (!test_bit(__E1000_DOWN, &adapter->state))
1786 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001787
1788 return IRQ_HANDLED;
1789}
1790
1791
1792static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1793{
1794 struct net_device *netdev = data;
1795 struct e1000_adapter *adapter = netdev_priv(netdev);
1796 struct e1000_hw *hw = &adapter->hw;
1797 struct e1000_ring *tx_ring = adapter->tx_ring;
1798
1799
1800 adapter->total_tx_bytes = 0;
1801 adapter->total_tx_packets = 0;
1802
Bruce Allan55aa6982011-12-16 00:45:45 +00001803 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001804 /* Ring was not completely cleaned, so fire another interrupt */
1805 ew32(ICS, tx_ring->ims_val);
1806
1807 return IRQ_HANDLED;
1808}
1809
1810static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1811{
1812 struct net_device *netdev = data;
1813 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001814 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001815
1816 /* Write the ITR value calculated at the end of the
1817 * previous interrupt.
1818 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001819 if (rx_ring->set_itr) {
1820 writel(1000000000 / (rx_ring->itr_val * 256),
1821 rx_ring->itr_register);
1822 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001823 }
1824
Ben Hutchings288379f2009-01-19 16:43:59 -08001825 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001826 adapter->total_rx_bytes = 0;
1827 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001828 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001829 }
1830 return IRQ_HANDLED;
1831}
1832
1833/**
1834 * e1000_configure_msix - Configure MSI-X hardware
1835 *
1836 * e1000_configure_msix sets up the hardware to properly
1837 * generate MSI-X interrupts.
1838 **/
1839static void e1000_configure_msix(struct e1000_adapter *adapter)
1840{
1841 struct e1000_hw *hw = &adapter->hw;
1842 struct e1000_ring *rx_ring = adapter->rx_ring;
1843 struct e1000_ring *tx_ring = adapter->tx_ring;
1844 int vector = 0;
1845 u32 ctrl_ext, ivar = 0;
1846
1847 adapter->eiac_mask = 0;
1848
1849 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1850 if (hw->mac.type == e1000_82574) {
1851 u32 rfctl = er32(RFCTL);
1852 rfctl |= E1000_RFCTL_ACK_DIS;
1853 ew32(RFCTL, rfctl);
1854 }
1855
1856#define E1000_IVAR_INT_ALLOC_VALID 0x8
1857 /* Configure Rx vector */
1858 rx_ring->ims_val = E1000_IMS_RXQ0;
1859 adapter->eiac_mask |= rx_ring->ims_val;
1860 if (rx_ring->itr_val)
1861 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001862 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001863 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001864 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001865 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1866
1867 /* Configure Tx vector */
1868 tx_ring->ims_val = E1000_IMS_TXQ0;
1869 vector++;
1870 if (tx_ring->itr_val)
1871 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001872 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001873 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001874 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001875 adapter->eiac_mask |= tx_ring->ims_val;
1876 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1877
1878 /* set vector for Other Causes, e.g. link changes */
1879 vector++;
1880 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1881 if (rx_ring->itr_val)
1882 writel(1000000000 / (rx_ring->itr_val * 256),
1883 hw->hw_addr + E1000_EITR_82574(vector));
1884 else
1885 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1886
1887 /* Cause Tx interrupts on every write back */
1888 ivar |= (1 << 31);
1889
1890 ew32(IVAR, ivar);
1891
1892 /* enable MSI-X PBA support */
1893 ctrl_ext = er32(CTRL_EXT);
1894 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1895
1896 /* Auto-Mask Other interrupts upon ICR read */
1897#define E1000_EIAC_MASK_82574 0x01F00000
1898 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1899 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1900 ew32(CTRL_EXT, ctrl_ext);
1901 e1e_flush();
1902}
1903
1904void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1905{
1906 if (adapter->msix_entries) {
1907 pci_disable_msix(adapter->pdev);
1908 kfree(adapter->msix_entries);
1909 adapter->msix_entries = NULL;
1910 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1911 pci_disable_msi(adapter->pdev);
1912 adapter->flags &= ~FLAG_MSI_ENABLED;
1913 }
Bruce Allan4662e822008-08-26 18:37:06 -07001914}
1915
1916/**
1917 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1918 *
1919 * Attempt to configure interrupts using the best available
1920 * capabilities of the hardware and kernel.
1921 **/
1922void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1923{
1924 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001925 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001926
1927 switch (adapter->int_mode) {
1928 case E1000E_INT_MODE_MSIX:
1929 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001930 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1931 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001932 sizeof(struct msix_entry),
1933 GFP_KERNEL);
1934 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001935 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001936 adapter->msix_entries[i].entry = i;
1937
1938 err = pci_enable_msix(adapter->pdev,
1939 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001940 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001941 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001942 return;
1943 }
1944 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00001945 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001946 e1000e_reset_interrupt_capability(adapter);
1947 }
1948 adapter->int_mode = E1000E_INT_MODE_MSI;
1949 /* Fall through */
1950 case E1000E_INT_MODE_MSI:
1951 if (!pci_enable_msi(adapter->pdev)) {
1952 adapter->flags |= FLAG_MSI_ENABLED;
1953 } else {
1954 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00001955 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001956 }
1957 /* Fall through */
1958 case E1000E_INT_MODE_LEGACY:
1959 /* Don't do anything; this is the system default */
1960 break;
1961 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001962
1963 /* store the number of vectors being used */
1964 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001965}
1966
1967/**
1968 * e1000_request_msix - Initialize MSI-X interrupts
1969 *
1970 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1971 * kernel.
1972 **/
1973static int e1000_request_msix(struct e1000_adapter *adapter)
1974{
1975 struct net_device *netdev = adapter->netdev;
1976 int err = 0, vector = 0;
1977
1978 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001979 snprintf(adapter->rx_ring->name,
1980 sizeof(adapter->rx_ring->name) - 1,
1981 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001982 else
1983 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1984 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001985 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001986 netdev);
1987 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00001988 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00001989 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
1990 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07001991 adapter->rx_ring->itr_val = adapter->itr;
1992 vector++;
1993
1994 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001995 snprintf(adapter->tx_ring->name,
1996 sizeof(adapter->tx_ring->name) - 1,
1997 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001998 else
1999 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2000 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002001 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002002 netdev);
2003 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002004 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002005 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2006 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002007 adapter->tx_ring->itr_val = adapter->itr;
2008 vector++;
2009
2010 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002011 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002012 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002013 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002014
2015 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002016
Bruce Allan4662e822008-08-26 18:37:06 -07002017 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002018}
2019
Bruce Allanf8d59f72008-08-08 18:36:11 -07002020/**
2021 * e1000_request_irq - initialize interrupts
2022 *
2023 * Attempts to configure interrupts using the best available
2024 * capabilities of the hardware and kernel.
2025 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002026static int e1000_request_irq(struct e1000_adapter *adapter)
2027{
2028 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002029 int err;
2030
Bruce Allan4662e822008-08-26 18:37:06 -07002031 if (adapter->msix_entries) {
2032 err = e1000_request_msix(adapter);
2033 if (!err)
2034 return err;
2035 /* fall back to MSI */
2036 e1000e_reset_interrupt_capability(adapter);
2037 adapter->int_mode = E1000E_INT_MODE_MSI;
2038 e1000e_set_interrupt_capability(adapter);
2039 }
2040 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002041 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002042 netdev->name, netdev);
2043 if (!err)
2044 return err;
2045
2046 /* fall back to legacy interrupt */
2047 e1000e_reset_interrupt_capability(adapter);
2048 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002049 }
2050
Joe Perchesa0607fd2009-11-18 23:29:17 -08002051 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002052 netdev->name, netdev);
2053 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002054 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002055
2056 return err;
2057}
2058
2059static void e1000_free_irq(struct e1000_adapter *adapter)
2060{
2061 struct net_device *netdev = adapter->netdev;
2062
Bruce Allan4662e822008-08-26 18:37:06 -07002063 if (adapter->msix_entries) {
2064 int vector = 0;
2065
2066 free_irq(adapter->msix_entries[vector].vector, netdev);
2067 vector++;
2068
2069 free_irq(adapter->msix_entries[vector].vector, netdev);
2070 vector++;
2071
2072 /* Other Causes interrupt vector */
2073 free_irq(adapter->msix_entries[vector].vector, netdev);
2074 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002075 }
Bruce Allan4662e822008-08-26 18:37:06 -07002076
2077 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002078}
2079
2080/**
2081 * e1000_irq_disable - Mask off interrupt generation on the NIC
2082 **/
2083static void e1000_irq_disable(struct e1000_adapter *adapter)
2084{
2085 struct e1000_hw *hw = &adapter->hw;
2086
Auke Kokbc7f75f2007-09-17 12:30:59 -07002087 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002088 if (adapter->msix_entries)
2089 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002090 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002091
2092 if (adapter->msix_entries) {
2093 int i;
2094 for (i = 0; i < adapter->num_vectors; i++)
2095 synchronize_irq(adapter->msix_entries[i].vector);
2096 } else {
2097 synchronize_irq(adapter->pdev->irq);
2098 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002099}
2100
2101/**
2102 * e1000_irq_enable - Enable default interrupt generation settings
2103 **/
2104static void e1000_irq_enable(struct e1000_adapter *adapter)
2105{
2106 struct e1000_hw *hw = &adapter->hw;
2107
Bruce Allan4662e822008-08-26 18:37:06 -07002108 if (adapter->msix_entries) {
2109 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2110 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2111 } else {
2112 ew32(IMS, IMS_ENABLE_MASK);
2113 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002114 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002115}
2116
2117/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002118 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002119 * @adapter: address of board private structure
2120 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002121 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002122 * For ASF and Pass Through versions of f/w this means that
2123 * the driver is loaded. For AMT version (only with 82573)
2124 * of the f/w this means that the network i/f is open.
2125 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002126void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002127{
2128 struct e1000_hw *hw = &adapter->hw;
2129 u32 ctrl_ext;
2130 u32 swsm;
2131
2132 /* Let firmware know the driver has taken over */
2133 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2134 swsm = er32(SWSM);
2135 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2136 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2137 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002138 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002139 }
2140}
2141
2142/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002143 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002144 * @adapter: address of board private structure
2145 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002146 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002147 * For ASF and Pass Through versions of f/w this means that the
2148 * driver is no longer loaded. For AMT version (only with 82573) i
2149 * of the f/w this means that the network i/f is closed.
2150 *
2151 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002152void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002153{
2154 struct e1000_hw *hw = &adapter->hw;
2155 u32 ctrl_ext;
2156 u32 swsm;
2157
2158 /* Let firmware taken over control of h/w */
2159 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2160 swsm = er32(SWSM);
2161 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2162 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2163 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002164 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002165 }
2166}
2167
Auke Kokbc7f75f2007-09-17 12:30:59 -07002168/**
2169 * @e1000_alloc_ring - allocate memory for a ring structure
2170 **/
2171static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2172 struct e1000_ring *ring)
2173{
2174 struct pci_dev *pdev = adapter->pdev;
2175
2176 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2177 GFP_KERNEL);
2178 if (!ring->desc)
2179 return -ENOMEM;
2180
2181 return 0;
2182}
2183
2184/**
2185 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002186 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002187 *
2188 * Return 0 on success, negative on failure
2189 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002190int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002191{
Bruce Allan55aa6982011-12-16 00:45:45 +00002192 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002193 int err = -ENOMEM, size;
2194
2195 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002196 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002197 if (!tx_ring->buffer_info)
2198 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002199
2200 /* round up to nearest 4K */
2201 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2202 tx_ring->size = ALIGN(tx_ring->size, 4096);
2203
2204 err = e1000_alloc_ring_dma(adapter, tx_ring);
2205 if (err)
2206 goto err;
2207
2208 tx_ring->next_to_use = 0;
2209 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002210
2211 return 0;
2212err:
2213 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002214 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002215 return err;
2216}
2217
2218/**
2219 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002220 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002221 *
2222 * Returns 0 on success, negative on failure
2223 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002224int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002225{
Bruce Allan55aa6982011-12-16 00:45:45 +00002226 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002227 struct e1000_buffer *buffer_info;
2228 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229
2230 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002231 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002232 if (!rx_ring->buffer_info)
2233 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002234
Auke Kok47f44e42007-10-25 13:57:44 -07002235 for (i = 0; i < rx_ring->count; i++) {
2236 buffer_info = &rx_ring->buffer_info[i];
2237 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2238 sizeof(struct e1000_ps_page),
2239 GFP_KERNEL);
2240 if (!buffer_info->ps_pages)
2241 goto err_pages;
2242 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002243
2244 desc_len = sizeof(union e1000_rx_desc_packet_split);
2245
2246 /* Round up to nearest 4K */
2247 rx_ring->size = rx_ring->count * desc_len;
2248 rx_ring->size = ALIGN(rx_ring->size, 4096);
2249
2250 err = e1000_alloc_ring_dma(adapter, rx_ring);
2251 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002252 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253
2254 rx_ring->next_to_clean = 0;
2255 rx_ring->next_to_use = 0;
2256 rx_ring->rx_skb_top = NULL;
2257
2258 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002259
2260err_pages:
2261 for (i = 0; i < rx_ring->count; i++) {
2262 buffer_info = &rx_ring->buffer_info[i];
2263 kfree(buffer_info->ps_pages);
2264 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002265err:
2266 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002267 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002268 return err;
2269}
2270
2271/**
2272 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002273 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002274 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002275static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002276{
Bruce Allan55aa6982011-12-16 00:45:45 +00002277 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002278 struct e1000_buffer *buffer_info;
2279 unsigned long size;
2280 unsigned int i;
2281
2282 for (i = 0; i < tx_ring->count; i++) {
2283 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002284 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002285 }
2286
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002287 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288 size = sizeof(struct e1000_buffer) * tx_ring->count;
2289 memset(tx_ring->buffer_info, 0, size);
2290
2291 memset(tx_ring->desc, 0, tx_ring->size);
2292
2293 tx_ring->next_to_use = 0;
2294 tx_ring->next_to_clean = 0;
2295
Bruce Allanc5083cf2011-12-16 00:45:40 +00002296 writel(0, tx_ring->head);
2297 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002298}
2299
2300/**
2301 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002302 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002303 *
2304 * Free all transmit software resources
2305 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002306void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002307{
Bruce Allan55aa6982011-12-16 00:45:45 +00002308 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002309 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002310
Bruce Allan55aa6982011-12-16 00:45:45 +00002311 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002312
2313 vfree(tx_ring->buffer_info);
2314 tx_ring->buffer_info = NULL;
2315
2316 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2317 tx_ring->dma);
2318 tx_ring->desc = NULL;
2319}
2320
2321/**
2322 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002323 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324 *
2325 * Free all receive software resources
2326 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002327void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002328{
Bruce Allan55aa6982011-12-16 00:45:45 +00002329 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002331 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002332
Bruce Allan55aa6982011-12-16 00:45:45 +00002333 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002335 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002336 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002337
Auke Kokbc7f75f2007-09-17 12:30:59 -07002338 vfree(rx_ring->buffer_info);
2339 rx_ring->buffer_info = NULL;
2340
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2342 rx_ring->dma);
2343 rx_ring->desc = NULL;
2344}
2345
2346/**
2347 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002348 * @adapter: pointer to adapter
2349 * @itr_setting: current adapter->itr
2350 * @packets: the number of packets during this measurement interval
2351 * @bytes: the number of bytes during this measurement interval
2352 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002353 * Stores a new ITR value based on packets and byte
2354 * counts during the last interrupt. The advantage of per interrupt
2355 * computation is faster updates and more accurate ITR for the current
2356 * traffic pattern. Constants in this function were computed
2357 * based on theoretical maximum wire speed and thresholds were set based
2358 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002359 * while increasing bulk throughput. This functionality is controlled
2360 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002361 **/
2362static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2363 u16 itr_setting, int packets,
2364 int bytes)
2365{
2366 unsigned int retval = itr_setting;
2367
2368 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002369 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002370
2371 switch (itr_setting) {
2372 case lowest_latency:
2373 /* handle TSO and jumbo frames */
2374 if (bytes/packets > 8000)
2375 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002376 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002377 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378 break;
2379 case low_latency: /* 50 usec aka 20000 ints/s */
2380 if (bytes > 10000) {
2381 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002382 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002383 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002384 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002385 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002386 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002387 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002388 } else if (bytes/packets > 2000) {
2389 retval = bulk_latency;
2390 } else if (packets <= 2 && bytes < 512) {
2391 retval = lowest_latency;
2392 }
2393 break;
2394 case bulk_latency: /* 250 usec aka 4000 ints/s */
2395 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002396 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002397 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398 } else if (bytes < 6000) {
2399 retval = low_latency;
2400 }
2401 break;
2402 }
2403
Auke Kokbc7f75f2007-09-17 12:30:59 -07002404 return retval;
2405}
2406
2407static void e1000_set_itr(struct e1000_adapter *adapter)
2408{
2409 struct e1000_hw *hw = &adapter->hw;
2410 u16 current_itr;
2411 u32 new_itr = adapter->itr;
2412
2413 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2414 if (adapter->link_speed != SPEED_1000) {
2415 current_itr = 0;
2416 new_itr = 4000;
2417 goto set_itr_now;
2418 }
2419
Bruce Allan828bac82010-09-29 21:39:37 +00002420 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2421 new_itr = 0;
2422 goto set_itr_now;
2423 }
2424
Auke Kokbc7f75f2007-09-17 12:30:59 -07002425 adapter->tx_itr = e1000_update_itr(adapter,
2426 adapter->tx_itr,
2427 adapter->total_tx_packets,
2428 adapter->total_tx_bytes);
2429 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2430 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2431 adapter->tx_itr = low_latency;
2432
2433 adapter->rx_itr = e1000_update_itr(adapter,
2434 adapter->rx_itr,
2435 adapter->total_rx_packets,
2436 adapter->total_rx_bytes);
2437 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2438 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2439 adapter->rx_itr = low_latency;
2440
2441 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2442
2443 switch (current_itr) {
2444 /* counts and packets in update_itr are dependent on these numbers */
2445 case lowest_latency:
2446 new_itr = 70000;
2447 break;
2448 case low_latency:
2449 new_itr = 20000; /* aka hwitr = ~200 */
2450 break;
2451 case bulk_latency:
2452 new_itr = 4000;
2453 break;
2454 default:
2455 break;
2456 }
2457
2458set_itr_now:
2459 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002460 /*
2461 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002462 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002463 * increasing
2464 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002465 new_itr = new_itr > adapter->itr ?
2466 min(adapter->itr + (new_itr >> 2), new_itr) :
2467 new_itr;
2468 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002469 adapter->rx_ring->itr_val = new_itr;
2470 if (adapter->msix_entries)
2471 adapter->rx_ring->set_itr = 1;
2472 else
Bruce Allan828bac82010-09-29 21:39:37 +00002473 if (new_itr)
2474 ew32(ITR, 1000000000 / (new_itr * 256));
2475 else
2476 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002477 }
2478}
2479
2480/**
Bruce Allan4662e822008-08-26 18:37:06 -07002481 * e1000_alloc_queues - Allocate memory for all rings
2482 * @adapter: board private structure to initialize
2483 **/
2484static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2485{
Bruce Allan55aa6982011-12-16 00:45:45 +00002486 int size = sizeof(struct e1000_ring);
2487
2488 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002489 if (!adapter->tx_ring)
2490 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002491 adapter->tx_ring->count = adapter->tx_ring_count;
2492 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002493
Bruce Allan55aa6982011-12-16 00:45:45 +00002494 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002495 if (!adapter->rx_ring)
2496 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002497 adapter->rx_ring->count = adapter->rx_ring_count;
2498 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002499
2500 return 0;
2501err:
2502 e_err("Unable to allocate memory for queues\n");
2503 kfree(adapter->rx_ring);
2504 kfree(adapter->tx_ring);
2505 return -ENOMEM;
2506}
2507
2508/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002510 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002511 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002512 **/
2513static int e1000_clean(struct napi_struct *napi, int budget)
2514{
2515 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002516 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002517 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002518 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002519
Wang Chen4cf16532008-11-12 23:38:14 -08002520 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521
Bruce Allan4662e822008-08-26 18:37:06 -07002522 if (adapter->msix_entries &&
2523 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2524 goto clean_rx;
2525
Bruce Allan55aa6982011-12-16 00:45:45 +00002526 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527
Bruce Allan4662e822008-08-26 18:37:06 -07002528clean_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00002529 adapter->clean_rx(adapter->rx_ring, &work_done, budget);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002530
Alexander Duyck12d04a32009-03-25 22:05:03 +00002531 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002532 work_done = budget;
2533
David S. Miller53e52c72008-01-07 21:06:12 -08002534 /* If budget not fully consumed, exit the polling mode */
2535 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002536 if (adapter->itr_setting & 3)
2537 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002538 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002539 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2540 if (adapter->msix_entries)
2541 ew32(IMS, adapter->rx_ring->ims_val);
2542 else
2543 e1000_irq_enable(adapter);
2544 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002545 }
2546
2547 return work_done;
2548}
2549
Jiri Pirko8e586132011-12-08 19:52:37 -05002550static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002551{
2552 struct e1000_adapter *adapter = netdev_priv(netdev);
2553 struct e1000_hw *hw = &adapter->hw;
2554 u32 vfta, index;
2555
2556 /* don't update vlan cookie if already programmed */
2557 if ((adapter->hw.mng_cookie.status &
2558 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2559 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002560 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002561
Auke Kokbc7f75f2007-09-17 12:30:59 -07002562 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002563 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2564 index = (vid >> 5) & 0x7F;
2565 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2566 vfta |= (1 << (vid & 0x1F));
2567 hw->mac.ops.write_vfta(hw, index, vfta);
2568 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002569
2570 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002571
2572 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002573}
2574
Jiri Pirko8e586132011-12-08 19:52:37 -05002575static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002576{
2577 struct e1000_adapter *adapter = netdev_priv(netdev);
2578 struct e1000_hw *hw = &adapter->hw;
2579 u32 vfta, index;
2580
Auke Kokbc7f75f2007-09-17 12:30:59 -07002581 if ((adapter->hw.mng_cookie.status &
2582 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2583 (vid == adapter->mng_vlan_id)) {
2584 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002585 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002586 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002587 }
2588
2589 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002590 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2591 index = (vid >> 5) & 0x7F;
2592 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2593 vfta &= ~(1 << (vid & 0x1F));
2594 hw->mac.ops.write_vfta(hw, index, vfta);
2595 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002596
2597 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002598
2599 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002600}
2601
2602/**
2603 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2604 * @adapter: board private structure to initialize
2605 **/
2606static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2607{
2608 struct net_device *netdev = adapter->netdev;
2609 struct e1000_hw *hw = &adapter->hw;
2610 u32 rctl;
2611
2612 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2613 /* disable VLAN receive filtering */
2614 rctl = er32(RCTL);
2615 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2616 ew32(RCTL, rctl);
2617
2618 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2619 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2620 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2621 }
2622 }
2623}
2624
2625/**
2626 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2627 * @adapter: board private structure to initialize
2628 **/
2629static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2630{
2631 struct e1000_hw *hw = &adapter->hw;
2632 u32 rctl;
2633
2634 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2635 /* enable VLAN receive filtering */
2636 rctl = er32(RCTL);
2637 rctl |= E1000_RCTL_VFE;
2638 rctl &= ~E1000_RCTL_CFIEN;
2639 ew32(RCTL, rctl);
2640 }
2641}
2642
2643/**
2644 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2645 * @adapter: board private structure to initialize
2646 **/
2647static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2648{
2649 struct e1000_hw *hw = &adapter->hw;
2650 u32 ctrl;
2651
2652 /* disable VLAN tag insert/strip */
2653 ctrl = er32(CTRL);
2654 ctrl &= ~E1000_CTRL_VME;
2655 ew32(CTRL, ctrl);
2656}
2657
2658/**
2659 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2660 * @adapter: board private structure to initialize
2661 **/
2662static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2663{
2664 struct e1000_hw *hw = &adapter->hw;
2665 u32 ctrl;
2666
2667 /* enable VLAN tag insert/strip */
2668 ctrl = er32(CTRL);
2669 ctrl |= E1000_CTRL_VME;
2670 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002671}
2672
2673static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2674{
2675 struct net_device *netdev = adapter->netdev;
2676 u16 vid = adapter->hw.mng_cookie.vlan_id;
2677 u16 old_vid = adapter->mng_vlan_id;
2678
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002679 if (adapter->hw.mng_cookie.status &
2680 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2681 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002682 adapter->mng_vlan_id = vid;
2683 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002684
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002685 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2686 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002687}
2688
2689static void e1000_restore_vlan(struct e1000_adapter *adapter)
2690{
2691 u16 vid;
2692
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002693 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002695 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002696 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002697}
2698
Bruce Allancd791612010-05-10 14:59:51 +00002699static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002700{
2701 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002702 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002703
2704 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2705 return;
2706
2707 manc = er32(MANC);
2708
Bruce Allanad680762008-03-28 09:15:03 -07002709 /*
2710 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002712 * the packets will be handled on SMBUS
2713 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002714 manc |= E1000_MANC_EN_MNG2HOST;
2715 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002716
2717 switch (hw->mac.type) {
2718 default:
2719 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2720 break;
2721 case e1000_82574:
2722 case e1000_82583:
2723 /*
2724 * Check if IPMI pass-through decision filter already exists;
2725 * if so, enable it.
2726 */
2727 for (i = 0, j = 0; i < 8; i++) {
2728 mdef = er32(MDEF(i));
2729
2730 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002731 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002732 continue;
2733
2734 /* Enable this decision filter in MANC2H */
2735 if (mdef)
2736 manc2h |= (1 << i);
2737
2738 j |= mdef;
2739 }
2740
2741 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2742 break;
2743
2744 /* Create new decision filter in an empty filter */
2745 for (i = 0, j = 0; i < 8; i++)
2746 if (er32(MDEF(i)) == 0) {
2747 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2748 E1000_MDEF_PORT_664));
2749 manc2h |= (1 << 1);
2750 j++;
2751 break;
2752 }
2753
2754 if (!j)
2755 e_warn("Unable to create IPMI pass-through filter\n");
2756 break;
2757 }
2758
Auke Kokbc7f75f2007-09-17 12:30:59 -07002759 ew32(MANC2H, manc2h);
2760 ew32(MANC, manc);
2761}
2762
2763/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002764 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002765 * @adapter: board private structure
2766 *
2767 * Configure the Tx unit of the MAC after a reset.
2768 **/
2769static void e1000_configure_tx(struct e1000_adapter *adapter)
2770{
2771 struct e1000_hw *hw = &adapter->hw;
2772 struct e1000_ring *tx_ring = adapter->tx_ring;
2773 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002774 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002775
2776 /* Setup the HW Tx Head and Tail descriptor pointers */
2777 tdba = tx_ring->dma;
2778 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002779 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002780 ew32(TDBAH, (tdba >> 32));
2781 ew32(TDLEN, tdlen);
2782 ew32(TDH, 0);
2783 ew32(TDT, 0);
Bruce Allanc5083cf2011-12-16 00:45:40 +00002784 tx_ring->head = adapter->hw.hw_addr + E1000_TDH;
2785 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002786
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787 /* Set the Tx Interrupt Delay register */
2788 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002789 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002790 ew32(TADV, adapter->tx_abs_int_delay);
2791
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002792 if (adapter->flags2 & FLAG2_DMA_BURST) {
2793 u32 txdctl = er32(TXDCTL(0));
2794 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2795 E1000_TXDCTL_WTHRESH);
2796 /*
2797 * set up some performance related parameters to encourage the
2798 * hardware to use the bus more efficiently in bursts, depends
2799 * on the tx_int_delay to be enabled,
2800 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2801 * hthresh = 1 ==> prefetch when one or more available
2802 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2803 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002804 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002805 */
2806 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2807 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002808 }
Bruce Allan56032be2011-12-16 00:46:01 +00002809 /* erratum work around: set txdctl the same for both queues */
2810 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002811
Auke Kokbc7f75f2007-09-17 12:30:59 -07002812 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002813 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002814 /*
2815 * set the speed mode bit, we'll clear it if we're not at
2816 * gigabit link later
2817 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002818#define SPEED_MODE_BIT (1 << 21)
2819 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002820 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002821 }
2822
2823 /* errata: program both queues to unweighted RR */
2824 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002825 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002826 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002827 ew32(TARC(0), tarc);
2828 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002830 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831 }
2832
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833 /* Setup Transmit Descriptor Settings for eop descriptor */
2834 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2835
2836 /* only set IDE if we are delaying interrupts using the timers */
2837 if (adapter->tx_int_delay)
2838 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2839
2840 /* enable Report Status bit */
2841 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2842
Simon Hormanedfea6e62009-06-08 14:28:36 +00002843 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844}
2845
2846/**
2847 * e1000_setup_rctl - configure the receive control registers
2848 * @adapter: Board private structure
2849 **/
2850#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2851 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2852static void e1000_setup_rctl(struct e1000_adapter *adapter)
2853{
2854 struct e1000_hw *hw = &adapter->hw;
2855 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002856 u32 pages = 0;
2857
Bruce Allana1ce6472010-09-22 17:16:40 +00002858 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2859 if (hw->mac.type == e1000_pch2lan) {
2860 s32 ret_val;
2861
2862 if (adapter->netdev->mtu > ETH_DATA_LEN)
2863 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2864 else
2865 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002866
2867 if (ret_val)
2868 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002869 }
2870
Auke Kokbc7f75f2007-09-17 12:30:59 -07002871 /* Program MC offset vector base */
2872 rctl = er32(RCTL);
2873 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2874 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2875 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2876 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2877
2878 /* Do not Store bad packets */
2879 rctl &= ~E1000_RCTL_SBP;
2880
2881 /* Enable Long Packet receive */
2882 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2883 rctl &= ~E1000_RCTL_LPE;
2884 else
2885 rctl |= E1000_RCTL_LPE;
2886
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002887 /* Some systems expect that the CRC is included in SMBUS traffic. The
2888 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2889 * host memory when this is enabled
2890 */
2891 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2892 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002893
Bruce Allana4f58f52009-06-02 11:29:18 +00002894 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2895 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2896 u16 phy_data;
2897
2898 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2899 phy_data &= 0xfff8;
2900 phy_data |= (1 << 2);
2901 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2902
2903 e1e_rphy(hw, 22, &phy_data);
2904 phy_data &= 0x0fff;
2905 phy_data |= (1 << 14);
2906 e1e_wphy(hw, 0x10, 0x2823);
2907 e1e_wphy(hw, 0x11, 0x0003);
2908 e1e_wphy(hw, 22, phy_data);
2909 }
2910
Auke Kokbc7f75f2007-09-17 12:30:59 -07002911 /* Setup buffer sizes */
2912 rctl &= ~E1000_RCTL_SZ_4096;
2913 rctl |= E1000_RCTL_BSEX;
2914 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002915 case 2048:
2916 default:
2917 rctl |= E1000_RCTL_SZ_2048;
2918 rctl &= ~E1000_RCTL_BSEX;
2919 break;
2920 case 4096:
2921 rctl |= E1000_RCTL_SZ_4096;
2922 break;
2923 case 8192:
2924 rctl |= E1000_RCTL_SZ_8192;
2925 break;
2926 case 16384:
2927 rctl |= E1000_RCTL_SZ_16384;
2928 break;
2929 }
2930
Bruce Allan5f450212011-07-22 06:21:46 +00002931 /* Enable Extended Status in all Receive Descriptors */
2932 rfctl = er32(RFCTL);
2933 rfctl |= E1000_RFCTL_EXTEN;
2934
Auke Kokbc7f75f2007-09-17 12:30:59 -07002935 /*
2936 * 82571 and greater support packet-split where the protocol
2937 * header is placed in skb->data and the packet data is
2938 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2939 * In the case of a non-split, skb->data is linearly filled,
2940 * followed by the page buffers. Therefore, skb->data is
2941 * sized to hold the largest protocol header.
2942 *
2943 * allocations using alloc_page take too long for regular MTU
2944 * so only enable packet split for jumbo frames
2945 *
2946 * Using pages when the page size is greater than 16k wastes
2947 * a lot of memory, since we allocate 3 pages at all times
2948 * per packet.
2949 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002950 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00002951 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002952 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002953 else
2954 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002955
2956 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002957 u32 psrctl = 0;
2958
Bruce Allanad680762008-03-28 09:15:03 -07002959 /*
2960 * disable packet split support for IPv6 extension headers,
2961 * because some malformed IPv6 headers can hang the Rx
2962 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002963 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2964 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2965
Auke Kok140a7482007-10-25 13:57:58 -07002966 /* Enable Packet split descriptors */
2967 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002968
2969 psrctl |= adapter->rx_ps_bsize0 >>
2970 E1000_PSRCTL_BSIZE0_SHIFT;
2971
2972 switch (adapter->rx_ps_pages) {
2973 case 3:
2974 psrctl |= PAGE_SIZE <<
2975 E1000_PSRCTL_BSIZE3_SHIFT;
2976 case 2:
2977 psrctl |= PAGE_SIZE <<
2978 E1000_PSRCTL_BSIZE2_SHIFT;
2979 case 1:
2980 psrctl |= PAGE_SIZE >>
2981 E1000_PSRCTL_BSIZE1_SHIFT;
2982 break;
2983 }
2984
2985 ew32(PSRCTL, psrctl);
2986 }
2987
Bruce Allan5f450212011-07-22 06:21:46 +00002988 ew32(RFCTL, rfctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002989 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002990 /* just started the receive unit, no need to restart */
2991 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002992}
2993
2994/**
2995 * e1000_configure_rx - Configure Receive Unit after Reset
2996 * @adapter: board private structure
2997 *
2998 * Configure the Rx unit of the MAC after a reset.
2999 **/
3000static void e1000_configure_rx(struct e1000_adapter *adapter)
3001{
3002 struct e1000_hw *hw = &adapter->hw;
3003 struct e1000_ring *rx_ring = adapter->rx_ring;
3004 u64 rdba;
3005 u32 rdlen, rctl, rxcsum, ctrl_ext;
3006
3007 if (adapter->rx_ps_pages) {
3008 /* this is a 32 byte descriptor */
3009 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003010 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003011 adapter->clean_rx = e1000_clean_rx_irq_ps;
3012 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003013 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003014 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003015 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3016 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003017 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003018 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003019 adapter->clean_rx = e1000_clean_rx_irq;
3020 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3021 }
3022
3023 /* disable receives while setting up the descriptors */
3024 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003025 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3026 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003027 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003028 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003029
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003030 if (adapter->flags2 & FLAG2_DMA_BURST) {
3031 /*
3032 * set the writeback threshold (only takes effect if the RDTR
3033 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003034 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003035 * granularity = 01
3036 * wthresh = 04,
3037 * hthresh = 04,
3038 * pthresh = 0x20
3039 */
3040 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3041 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3042
3043 /*
3044 * override the delay timers for enabling bursting, only if
3045 * the value was not set by the user via module options
3046 */
3047 if (adapter->rx_int_delay == DEFAULT_RDTR)
3048 adapter->rx_int_delay = BURST_RDTR;
3049 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3050 adapter->rx_abs_int_delay = BURST_RADV;
3051 }
3052
Auke Kokbc7f75f2007-09-17 12:30:59 -07003053 /* set the Receive Delay Timer Register */
3054 ew32(RDTR, adapter->rx_int_delay);
3055
3056 /* irq moderation */
3057 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003058 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003059 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003060
3061 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003062 /* Auto-Mask interrupts upon ICR access */
3063 ctrl_ext |= E1000_CTRL_EXT_IAME;
3064 ew32(IAM, 0xffffffff);
3065 ew32(CTRL_EXT, ctrl_ext);
3066 e1e_flush();
3067
Bruce Allanad680762008-03-28 09:15:03 -07003068 /*
3069 * Setup the HW Rx Head and Tail Descriptor Pointers and
3070 * the Base and Length of the Rx Descriptor Ring
3071 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003072 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07003073 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003074 ew32(RDBAH, (rdba >> 32));
3075 ew32(RDLEN, rdlen);
3076 ew32(RDH, 0);
3077 ew32(RDT, 0);
Bruce Allanc5083cf2011-12-16 00:45:40 +00003078 rx_ring->head = adapter->hw.hw_addr + E1000_RDH;
3079 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003080
3081 /* Enable Receive Checksum Offload for TCP and UDP */
3082 rxcsum = er32(RXCSUM);
Bruce Allandc221292011-08-19 03:23:48 +00003083 if (adapter->netdev->features & NETIF_F_RXCSUM) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003084 rxcsum |= E1000_RXCSUM_TUOFL;
3085
Bruce Allanad680762008-03-28 09:15:03 -07003086 /*
3087 * IPv4 payload checksum for UDP fragments must be
3088 * used in conjunction with packet-split.
3089 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003090 if (adapter->rx_ps_pages)
3091 rxcsum |= E1000_RXCSUM_IPPCSE;
3092 } else {
3093 rxcsum &= ~E1000_RXCSUM_TUOFL;
3094 /* no need to clear IPPCSE as it defaults to 0 */
3095 }
3096 ew32(RXCSUM, rxcsum);
3097
Bruce Allan79d4e902011-12-16 00:46:27 +00003098 if (adapter->hw.mac.type == e1000_pch2lan) {
3099 /*
3100 * With jumbo frames, excessive C-state transition
3101 * latencies result in dropped transactions.
3102 */
Bruce Allan53ec5492009-11-20 23:27:40 +00003103 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3104 u32 rxdctl = er32(RXDCTL(0));
3105 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allanaf667a22010-12-31 06:10:01 +00003106 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003107 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003108 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3109 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003110 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003111 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003112
3113 /* Enable Receives */
3114 ew32(RCTL, rctl);
3115}
3116
3117/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003118 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003119 * @netdev: network interface device structure
3120 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003121 * Writes multicast address list to the MTA hash table.
3122 * Returns: -ENOMEM on failure
3123 * 0 on no addresses written
3124 * X on writing X addresses to MTA
3125 */
3126static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003127{
3128 struct e1000_adapter *adapter = netdev_priv(netdev);
3129 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003130 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003131 u8 *mta_list;
3132 int i;
3133
3134 if (netdev_mc_empty(netdev)) {
3135 /* nothing to program, so clear mc list */
3136 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3137 return 0;
3138 }
3139
3140 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3141 if (!mta_list)
3142 return -ENOMEM;
3143
3144 /* update_mc_addr_list expects a packed array of only addresses. */
3145 i = 0;
3146 netdev_for_each_mc_addr(ha, netdev)
3147 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3148
3149 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3150 kfree(mta_list);
3151
3152 return netdev_mc_count(netdev);
3153}
3154
3155/**
3156 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3157 * @netdev: network interface device structure
3158 *
3159 * Writes unicast address list to the RAR table.
3160 * Returns: -ENOMEM on failure/insufficient address space
3161 * 0 on no addresses written
3162 * X on writing X addresses to the RAR table
3163 **/
3164static int e1000e_write_uc_addr_list(struct net_device *netdev)
3165{
3166 struct e1000_adapter *adapter = netdev_priv(netdev);
3167 struct e1000_hw *hw = &adapter->hw;
3168 unsigned int rar_entries = hw->mac.rar_entry_count;
3169 int count = 0;
3170
3171 /* save a rar entry for our hardware address */
3172 rar_entries--;
3173
3174 /* save a rar entry for the LAA workaround */
3175 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3176 rar_entries--;
3177
3178 /* return ENOMEM indicating insufficient memory for addresses */
3179 if (netdev_uc_count(netdev) > rar_entries)
3180 return -ENOMEM;
3181
3182 if (!netdev_uc_empty(netdev) && rar_entries) {
3183 struct netdev_hw_addr *ha;
3184
3185 /*
3186 * write the addresses in reverse order to avoid write
3187 * combining
3188 */
3189 netdev_for_each_uc_addr(ha, netdev) {
3190 if (!rar_entries)
3191 break;
3192 e1000e_rar_set(hw, ha->addr, rar_entries--);
3193 count++;
3194 }
3195 }
3196
3197 /* zero out the remaining RAR entries not used above */
3198 for (; rar_entries > 0; rar_entries--) {
3199 ew32(RAH(rar_entries), 0);
3200 ew32(RAL(rar_entries), 0);
3201 }
3202 e1e_flush();
3203
3204 return count;
3205}
3206
3207/**
3208 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3209 * @netdev: network interface device structure
3210 *
3211 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3212 * address list or the network interface flags are updated. This routine is
3213 * responsible for configuring the hardware for proper unicast, multicast,
3214 * promiscuous mode, and all-multi behavior.
3215 **/
3216static void e1000e_set_rx_mode(struct net_device *netdev)
3217{
3218 struct e1000_adapter *adapter = netdev_priv(netdev);
3219 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003220 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003221
3222 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003223 rctl = er32(RCTL);
3224
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003225 /* clear the affected bits */
3226 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3227
Auke Kokbc7f75f2007-09-17 12:30:59 -07003228 if (netdev->flags & IFF_PROMISC) {
3229 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003230 /* Do not hardware filter VLANs in promisc mode */
3231 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003232 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003233 int count;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003234 if (netdev->flags & IFF_ALLMULTI) {
3235 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003236 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003237 /*
3238 * Write addresses to the MTA, if the attempt fails
3239 * then we should just turn on promiscuous mode so
3240 * that we can at least receive multicast traffic
3241 */
3242 count = e1000e_write_mc_addr_list(netdev);
3243 if (count < 0)
3244 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003245 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003246 e1000e_vlan_filter_enable(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003247 /*
3248 * Write addresses to available RAR registers, if there is not
3249 * sufficient space to store all the addresses then enable
3250 * unicast promiscuous mode
3251 */
3252 count = e1000e_write_uc_addr_list(netdev);
3253 if (count < 0)
3254 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003255 }
3256
3257 ew32(RCTL, rctl);
3258
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003259 if (netdev->features & NETIF_F_HW_VLAN_RX)
3260 e1000e_vlan_strip_enable(adapter);
3261 else
3262 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003263}
3264
Bruce Allan70495a52012-01-11 01:26:50 +00003265static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3266{
3267 struct e1000_hw *hw = &adapter->hw;
3268 u32 mrqc, rxcsum;
3269 int i;
3270 static const u32 rsskey[10] = {
3271 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3272 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3273 };
3274
3275 /* Fill out hash function seed */
3276 for (i = 0; i < 10; i++)
3277 ew32(RSSRK(i), rsskey[i]);
3278
3279 /* Direct all traffic to queue 0 */
3280 for (i = 0; i < 32; i++)
3281 ew32(RETA(i), 0);
3282
3283 /*
3284 * Disable raw packet checksumming so that RSS hash is placed in
3285 * descriptor on writeback.
3286 */
3287 rxcsum = er32(RXCSUM);
3288 rxcsum |= E1000_RXCSUM_PCSD;
3289
3290 ew32(RXCSUM, rxcsum);
3291
3292 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3293 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3294 E1000_MRQC_RSS_FIELD_IPV6 |
3295 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3296 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3297
3298 ew32(MRQC, mrqc);
3299}
3300
Auke Kokbc7f75f2007-09-17 12:30:59 -07003301/**
Bruce Allanad680762008-03-28 09:15:03 -07003302 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003303 * @adapter: private board structure
3304 **/
3305static void e1000_configure(struct e1000_adapter *adapter)
3306{
Bruce Allan55aa6982011-12-16 00:45:45 +00003307 struct e1000_ring *rx_ring = adapter->rx_ring;
3308
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003309 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003310
3311 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003312 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003313
3314 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003315
3316 if (adapter->netdev->features & NETIF_F_RXHASH)
3317 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003318 e1000_setup_rctl(adapter);
3319 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003320 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003321}
3322
3323/**
3324 * e1000e_power_up_phy - restore link in case the phy was powered down
3325 * @adapter: address of board private structure
3326 *
3327 * The phy may be powered down to save power and turn off link when the
3328 * driver is unloaded and wake on lan is not enabled (among others)
3329 * *** this routine MUST be followed by a call to e1000e_reset ***
3330 **/
3331void e1000e_power_up_phy(struct e1000_adapter *adapter)
3332{
Bruce Allan17f208d2009-12-01 15:47:22 +00003333 if (adapter->hw.phy.ops.power_up)
3334 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003335
3336 adapter->hw.mac.ops.setup_link(&adapter->hw);
3337}
3338
3339/**
3340 * e1000_power_down_phy - Power down the PHY
3341 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003342 * Power down the PHY so no link is implied when interface is down.
3343 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003344 */
3345static void e1000_power_down_phy(struct e1000_adapter *adapter)
3346{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003347 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003348 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003349 return;
3350
Bruce Allan17f208d2009-12-01 15:47:22 +00003351 if (adapter->hw.phy.ops.power_down)
3352 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003353}
3354
3355/**
3356 * e1000e_reset - bring the hardware into a known good state
3357 *
3358 * This function boots the hardware and enables some settings that
3359 * require a configuration cycle of the hardware - those cannot be
3360 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003361 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003362 */
3363void e1000e_reset(struct e1000_adapter *adapter)
3364{
3365 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003366 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003367 struct e1000_hw *hw = &adapter->hw;
3368 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003369 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003370 u16 hwm;
3371
Bruce Allanad680762008-03-28 09:15:03 -07003372 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003373 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003374
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003375 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003376 /*
3377 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003378 * large enough to accommodate two full transmit packets,
3379 * rounded up to the next 1KB and expressed in KB. Likewise,
3380 * the Rx FIFO should be large enough to accommodate at least
3381 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003382 * expressed in KB.
3383 */
Auke Kokdf762462007-10-25 13:57:53 -07003384 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003385 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003386 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003387 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003388 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003389 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003390 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003391 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003392 */
3393 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003394 sizeof(struct e1000_tx_desc) -
3395 ETH_FCS_LEN) * 2;
3396 min_tx_space = ALIGN(min_tx_space, 1024);
3397 min_tx_space >>= 10;
3398 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003399 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003400 min_rx_space = ALIGN(min_rx_space, 1024);
3401 min_rx_space >>= 10;
3402
Bruce Allanad680762008-03-28 09:15:03 -07003403 /*
3404 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003405 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003406 * allocation, take space away from current Rx allocation
3407 */
Auke Kokdf762462007-10-25 13:57:53 -07003408 if ((tx_space < min_tx_space) &&
3409 ((min_tx_space - tx_space) < pba)) {
3410 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003411
Bruce Allanad680762008-03-28 09:15:03 -07003412 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003413 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003414 * adjustment or use Early Receive if available
3415 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003416 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003417 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003418 }
Auke Kokdf762462007-10-25 13:57:53 -07003419
3420 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003421 }
3422
Bruce Allanad680762008-03-28 09:15:03 -07003423 /*
3424 * flow control settings
3425 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003426 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003427 * (or the size used for early receive) above it in the Rx FIFO.
3428 * Set it to the lower of:
3429 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003430 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003431 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003432 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3433 fc->pause_time = 0xFFFF;
3434 else
3435 fc->pause_time = E1000_FC_PAUSE_TIME;
3436 fc->send_xon = 1;
3437 fc->current_mode = fc->requested_mode;
3438
3439 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003440 case e1000_ich9lan:
3441 case e1000_ich10lan:
3442 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3443 pba = 14;
3444 ew32(PBA, pba);
3445 fc->high_water = 0x2800;
3446 fc->low_water = fc->high_water - 8;
3447 break;
3448 }
3449 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003450 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003451 hwm = min(((pba << 10) * 9 / 10),
3452 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003453
3454 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3455 fc->low_water = fc->high_water - 8;
3456 break;
3457 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003458 /*
3459 * Workaround PCH LOM adapter hangs with certain network
3460 * loads. If hangs persist, try disabling Tx flow control.
3461 */
3462 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3463 fc->high_water = 0x3500;
3464 fc->low_water = 0x1500;
3465 } else {
3466 fc->high_water = 0x5000;
3467 fc->low_water = 0x3000;
3468 }
Bruce Allana3055952010-05-10 15:02:12 +00003469 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003470 break;
3471 case e1000_pch2lan:
3472 fc->high_water = 0x05C20;
3473 fc->low_water = 0x05048;
3474 fc->pause_time = 0x0650;
3475 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003476 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3477 pba = 14;
3478 ew32(PBA, pba);
3479 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003480 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003481 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003482
Bruce Allan828bac82010-09-29 21:39:37 +00003483 /*
3484 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003485 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003486 */
3487 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003488 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003489 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3490 dev_info(&adapter->pdev->dev,
3491 "Interrupt Throttle Rate turned off\n");
3492 adapter->flags2 |= FLAG2_DISABLE_AIM;
3493 ew32(ITR, 0);
3494 }
3495 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3496 dev_info(&adapter->pdev->dev,
3497 "Interrupt Throttle Rate turned on\n");
3498 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3499 adapter->itr = 20000;
3500 ew32(ITR, 1000000000 / (adapter->itr * 256));
3501 }
3502 }
3503
Auke Kokbc7f75f2007-09-17 12:30:59 -07003504 /* Allow time for pending master requests to run */
3505 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003506
3507 /*
3508 * For parts with AMT enabled, let the firmware know
3509 * that the network interface is in control
3510 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003511 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003512 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003513
Auke Kokbc7f75f2007-09-17 12:30:59 -07003514 ew32(WUC, 0);
3515
3516 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003517 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003518
3519 e1000_update_mng_vlan(adapter);
3520
3521 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3522 ew32(VET, ETH_P_8021Q);
3523
3524 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003525
3526 if (!netif_running(adapter->netdev) &&
3527 !test_bit(__E1000_TESTING, &adapter->state)) {
3528 e1000_power_down_phy(adapter);
3529 return;
3530 }
3531
Auke Kokbc7f75f2007-09-17 12:30:59 -07003532 e1000_get_phy_info(hw);
3533
Bruce Allan918d7192009-06-02 11:28:20 +00003534 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3535 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003536 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003537 /*
3538 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003539 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003540 * different we would do if it failed
3541 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003542 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3543 phy_data &= ~IGP02E1000_PM_SPD;
3544 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3545 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003546}
3547
3548int e1000e_up(struct e1000_adapter *adapter)
3549{
3550 struct e1000_hw *hw = &adapter->hw;
3551
3552 /* hardware has been reset, we need to reload some things */
3553 e1000_configure(adapter);
3554
3555 clear_bit(__E1000_DOWN, &adapter->state);
3556
Bruce Allan4662e822008-08-26 18:37:06 -07003557 if (adapter->msix_entries)
3558 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003559 e1000_irq_enable(adapter);
3560
Bruce Allan400484f2011-05-13 07:20:03 +00003561 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003562
Auke Kokbc7f75f2007-09-17 12:30:59 -07003563 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003564 if (adapter->msix_entries)
3565 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3566 else
3567 ew32(ICS, E1000_ICS_LSC);
3568
Auke Kokbc7f75f2007-09-17 12:30:59 -07003569 return 0;
3570}
3571
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003572static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3573{
3574 struct e1000_hw *hw = &adapter->hw;
3575
3576 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3577 return;
3578
3579 /* flush pending descriptor writebacks to memory */
3580 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3581 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3582
3583 /* execute the writes immediately */
3584 e1e_flush();
3585}
3586
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003587static void e1000e_update_stats(struct e1000_adapter *adapter);
3588
Auke Kokbc7f75f2007-09-17 12:30:59 -07003589void e1000e_down(struct e1000_adapter *adapter)
3590{
3591 struct net_device *netdev = adapter->netdev;
3592 struct e1000_hw *hw = &adapter->hw;
3593 u32 tctl, rctl;
3594
Bruce Allanad680762008-03-28 09:15:03 -07003595 /*
3596 * signal that we're down so the interrupt handler does not
3597 * reschedule our watchdog timer
3598 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003599 set_bit(__E1000_DOWN, &adapter->state);
3600
3601 /* disable receives in the hardware */
3602 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003603 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3604 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003605 /* flush and sleep below */
3606
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003607 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003608
3609 /* disable transmits in the hardware */
3610 tctl = er32(TCTL);
3611 tctl &= ~E1000_TCTL_EN;
3612 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003613
Auke Kokbc7f75f2007-09-17 12:30:59 -07003614 /* flush both disables and wait for them to finish */
3615 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003616 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003617
Auke Kokbc7f75f2007-09-17 12:30:59 -07003618 e1000_irq_disable(adapter);
3619
3620 del_timer_sync(&adapter->watchdog_timer);
3621 del_timer_sync(&adapter->phy_info_timer);
3622
Auke Kokbc7f75f2007-09-17 12:30:59 -07003623 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003624
3625 spin_lock(&adapter->stats64_lock);
3626 e1000e_update_stats(adapter);
3627 spin_unlock(&adapter->stats64_lock);
3628
Bruce Allan400484f2011-05-13 07:20:03 +00003629 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003630 e1000_clean_tx_ring(adapter->tx_ring);
3631 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00003632
Auke Kokbc7f75f2007-09-17 12:30:59 -07003633 adapter->link_speed = 0;
3634 adapter->link_duplex = 0;
3635
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003636 if (!pci_channel_offline(adapter->pdev))
3637 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003638
Auke Kokbc7f75f2007-09-17 12:30:59 -07003639 /*
3640 * TODO: for power management, we could drop the link and
3641 * pci_disable_device here.
3642 */
3643}
3644
3645void e1000e_reinit_locked(struct e1000_adapter *adapter)
3646{
3647 might_sleep();
3648 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003649 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003650 e1000e_down(adapter);
3651 e1000e_up(adapter);
3652 clear_bit(__E1000_RESETTING, &adapter->state);
3653}
3654
3655/**
3656 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3657 * @adapter: board private structure to initialize
3658 *
3659 * e1000_sw_init initializes the Adapter private data structure.
3660 * Fields are initialized based on PCI device information and
3661 * OS network device settings (MTU size).
3662 **/
3663static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3664{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003665 struct net_device *netdev = adapter->netdev;
3666
3667 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3668 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003669 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3670 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00003671 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3672 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003673
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003674 spin_lock_init(&adapter->stats64_lock);
3675
Bruce Allan4662e822008-08-26 18:37:06 -07003676 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003677
Bruce Allan4662e822008-08-26 18:37:06 -07003678 if (e1000_alloc_queues(adapter))
3679 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003680
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682 e1000_irq_disable(adapter);
3683
Auke Kokbc7f75f2007-09-17 12:30:59 -07003684 set_bit(__E1000_DOWN, &adapter->state);
3685 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003686}
3687
3688/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003689 * e1000_intr_msi_test - Interrupt Handler
3690 * @irq: interrupt number
3691 * @data: pointer to a network interface device structure
3692 **/
3693static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3694{
3695 struct net_device *netdev = data;
3696 struct e1000_adapter *adapter = netdev_priv(netdev);
3697 struct e1000_hw *hw = &adapter->hw;
3698 u32 icr = er32(ICR);
3699
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003700 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003701 if (icr & E1000_ICR_RXSEQ) {
3702 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3703 wmb();
3704 }
3705
3706 return IRQ_HANDLED;
3707}
3708
3709/**
3710 * e1000_test_msi_interrupt - Returns 0 for successful test
3711 * @adapter: board private struct
3712 *
3713 * code flow taken from tg3.c
3714 **/
3715static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3716{
3717 struct net_device *netdev = adapter->netdev;
3718 struct e1000_hw *hw = &adapter->hw;
3719 int err;
3720
3721 /* poll_enable hasn't been called yet, so don't need disable */
3722 /* clear any pending events */
3723 er32(ICR);
3724
3725 /* free the real vector and request a test handler */
3726 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003727 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003728
3729 /* Assume that the test fails, if it succeeds then the test
3730 * MSI irq handler will unset this flag */
3731 adapter->flags |= FLAG_MSI_TEST_FAILED;
3732
3733 err = pci_enable_msi(adapter->pdev);
3734 if (err)
3735 goto msi_test_failed;
3736
Joe Perchesa0607fd2009-11-18 23:29:17 -08003737 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003738 netdev->name, netdev);
3739 if (err) {
3740 pci_disable_msi(adapter->pdev);
3741 goto msi_test_failed;
3742 }
3743
3744 wmb();
3745
3746 e1000_irq_enable(adapter);
3747
3748 /* fire an unusual interrupt on the test handler */
3749 ew32(ICS, E1000_ICS_RXSEQ);
3750 e1e_flush();
3751 msleep(50);
3752
3753 e1000_irq_disable(adapter);
3754
3755 rmb();
3756
3757 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003758 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003759 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003760 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00003761 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003762 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003763
3764 free_irq(adapter->pdev->irq, netdev);
3765 pci_disable_msi(adapter->pdev);
3766
Bruce Allanf8d59f72008-08-08 18:36:11 -07003767msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003768 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003769 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003770}
3771
3772/**
3773 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3774 * @adapter: board private struct
3775 *
3776 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3777 **/
3778static int e1000_test_msi(struct e1000_adapter *adapter)
3779{
3780 int err;
3781 u16 pci_cmd;
3782
3783 if (!(adapter->flags & FLAG_MSI_ENABLED))
3784 return 0;
3785
3786 /* disable SERR in case the MSI write causes a master abort */
3787 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003788 if (pci_cmd & PCI_COMMAND_SERR)
3789 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3790 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003791
3792 err = e1000_test_msi_interrupt(adapter);
3793
Dean Nelson36f24072010-06-29 18:12:05 +00003794 /* re-enable SERR */
3795 if (pci_cmd & PCI_COMMAND_SERR) {
3796 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3797 pci_cmd |= PCI_COMMAND_SERR;
3798 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3799 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003800
Bruce Allanf8d59f72008-08-08 18:36:11 -07003801 return err;
3802}
3803
3804/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003805 * e1000_open - Called when a network interface is made active
3806 * @netdev: network interface device structure
3807 *
3808 * Returns 0 on success, negative value on failure
3809 *
3810 * The open entry point is called when a network interface is made
3811 * active by the system (IFF_UP). At this point all resources needed
3812 * for transmit and receive operations are allocated, the interrupt
3813 * handler is registered with the OS, the watchdog timer is started,
3814 * and the stack is notified that the interface is ready.
3815 **/
3816static int e1000_open(struct net_device *netdev)
3817{
3818 struct e1000_adapter *adapter = netdev_priv(netdev);
3819 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003820 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003821 int err;
3822
3823 /* disallow open during test */
3824 if (test_bit(__E1000_TESTING, &adapter->state))
3825 return -EBUSY;
3826
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003827 pm_runtime_get_sync(&pdev->dev);
3828
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003829 netif_carrier_off(netdev);
3830
Auke Kokbc7f75f2007-09-17 12:30:59 -07003831 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003832 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003833 if (err)
3834 goto err_setup_tx;
3835
3836 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003837 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003838 if (err)
3839 goto err_setup_rx;
3840
Bruce Allan11b08be2010-05-10 14:59:31 +00003841 /*
3842 * If AMT is enabled, let the firmware know that the network
3843 * interface is now open and reset the part to a known state.
3844 */
3845 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003846 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003847 e1000e_reset(adapter);
3848 }
3849
Auke Kokbc7f75f2007-09-17 12:30:59 -07003850 e1000e_power_up_phy(adapter);
3851
3852 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3853 if ((adapter->hw.mng_cookie.status &
3854 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3855 e1000_update_mng_vlan(adapter);
3856
Bruce Allan79d4e902011-12-16 00:46:27 +00003857 /* DMA latency requirement to workaround jumbo issue */
3858 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07003859 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3860 PM_QOS_CPU_DMA_LATENCY,
3861 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003862
Bruce Allanad680762008-03-28 09:15:03 -07003863 /*
Bruce Allanad680762008-03-28 09:15:03 -07003864 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003865 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3866 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003867 * clean_rx handler before we do so.
3868 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003869 e1000_configure(adapter);
3870
3871 err = e1000_request_irq(adapter);
3872 if (err)
3873 goto err_req_irq;
3874
Bruce Allanf8d59f72008-08-08 18:36:11 -07003875 /*
3876 * Work around PCIe errata with MSI interrupts causing some chipsets to
3877 * ignore e1000e MSI messages, which means we need to test our MSI
3878 * interrupt now
3879 */
Bruce Allan4662e822008-08-26 18:37:06 -07003880 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003881 err = e1000_test_msi(adapter);
3882 if (err) {
3883 e_err("Interrupt allocation failed\n");
3884 goto err_req_irq;
3885 }
3886 }
3887
Auke Kokbc7f75f2007-09-17 12:30:59 -07003888 /* From here on the code is the same as e1000e_up() */
3889 clear_bit(__E1000_DOWN, &adapter->state);
3890
3891 napi_enable(&adapter->napi);
3892
3893 e1000_irq_enable(adapter);
3894
Jeff Kirsher09357b02011-11-18 14:25:00 +00003895 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003896 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003897
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003898 adapter->idle_check = true;
3899 pm_runtime_put(&pdev->dev);
3900
Auke Kokbc7f75f2007-09-17 12:30:59 -07003901 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003902 if (adapter->msix_entries)
3903 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3904 else
3905 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003906
3907 return 0;
3908
3909err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003910 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003911 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003912 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003913err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00003914 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003915err_setup_tx:
3916 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003917 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003918
3919 return err;
3920}
3921
3922/**
3923 * e1000_close - Disables a network interface
3924 * @netdev: network interface device structure
3925 *
3926 * Returns 0, this is not allowed to fail
3927 *
3928 * The close entry point is called when an interface is de-activated
3929 * by the OS. The hardware is still under the drivers control, but
3930 * needs to be disabled. A global MAC reset is issued to stop the
3931 * hardware, and all transmit and receive resources are freed.
3932 **/
3933static int e1000_close(struct net_device *netdev)
3934{
3935 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003936 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003937
3938 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003939
3940 pm_runtime_get_sync(&pdev->dev);
3941
Bruce Allan5f4a7802011-11-29 08:09:19 +00003942 napi_disable(&adapter->napi);
3943
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003944 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3945 e1000e_down(adapter);
3946 e1000_free_irq(adapter);
3947 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003948 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003949
Bruce Allan55aa6982011-12-16 00:45:45 +00003950 e1000e_free_tx_resources(adapter->tx_ring);
3951 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003952
Bruce Allanad680762008-03-28 09:15:03 -07003953 /*
3954 * kill manageability vlan ID if supported, but not if a vlan with
3955 * the same ID is registered on the host OS (let 8021q kill it)
3956 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003957 if (adapter->hw.mng_cookie.status &
3958 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003959 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3960
Bruce Allanad680762008-03-28 09:15:03 -07003961 /*
3962 * If AMT is enabled, let the firmware know that the network
3963 * interface is now closed
3964 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003965 if ((adapter->flags & FLAG_HAS_AMT) &&
3966 !test_bit(__E1000_TESTING, &adapter->state))
3967 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003968
Bruce Allan79d4e902011-12-16 00:46:27 +00003969 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07003970 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003971
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003972 pm_runtime_put_sync(&pdev->dev);
3973
Auke Kokbc7f75f2007-09-17 12:30:59 -07003974 return 0;
3975}
3976/**
3977 * e1000_set_mac - Change the Ethernet Address of the NIC
3978 * @netdev: network interface device structure
3979 * @p: pointer to an address structure
3980 *
3981 * Returns 0 on success, negative on failure
3982 **/
3983static int e1000_set_mac(struct net_device *netdev, void *p)
3984{
3985 struct e1000_adapter *adapter = netdev_priv(netdev);
3986 struct sockaddr *addr = p;
3987
3988 if (!is_valid_ether_addr(addr->sa_data))
3989 return -EADDRNOTAVAIL;
3990
3991 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3992 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3993
3994 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3995
3996 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3997 /* activate the work around */
3998 e1000e_set_laa_state_82571(&adapter->hw, 1);
3999
Bruce Allanad680762008-03-28 09:15:03 -07004000 /*
4001 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004002 * between the time RAR[0] gets clobbered and the time it
4003 * gets fixed (in e1000_watchdog), the actual LAA is in one
4004 * of the RARs and no incoming packets directed to this port
4005 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004006 * RAR[14]
4007 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008 e1000e_rar_set(&adapter->hw,
4009 adapter->hw.mac.addr,
4010 adapter->hw.mac.rar_entry_count - 1);
4011 }
4012
4013 return 0;
4014}
4015
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004016/**
4017 * e1000e_update_phy_task - work thread to update phy
4018 * @work: pointer to our work struct
4019 *
4020 * this worker thread exists because we must acquire a
4021 * semaphore to read the phy, which we could msleep while
4022 * waiting for it, and we can't msleep in a timer.
4023 **/
4024static void e1000e_update_phy_task(struct work_struct *work)
4025{
4026 struct e1000_adapter *adapter = container_of(work,
4027 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004028
4029 if (test_bit(__E1000_DOWN, &adapter->state))
4030 return;
4031
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004032 e1000_get_phy_info(&adapter->hw);
4033}
4034
Bruce Allanad680762008-03-28 09:15:03 -07004035/*
4036 * Need to wait a few seconds after link up to get diagnostic information from
4037 * the phy
4038 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004039static void e1000_update_phy_info(unsigned long data)
4040{
4041 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004042
4043 if (test_bit(__E1000_DOWN, &adapter->state))
4044 return;
4045
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004046 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004047}
4048
4049/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004050 * e1000e_update_phy_stats - Update the PHY statistics counters
4051 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004052 *
4053 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004054 **/
4055static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4056{
4057 struct e1000_hw *hw = &adapter->hw;
4058 s32 ret_val;
4059 u16 phy_data;
4060
4061 ret_val = hw->phy.ops.acquire(hw);
4062 if (ret_val)
4063 return;
4064
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004065 /*
4066 * A page set is expensive so check if already on desired page.
4067 * If not, set to the page with the PHY status registers.
4068 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004069 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004070 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4071 &phy_data);
4072 if (ret_val)
4073 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004074 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4075 ret_val = hw->phy.ops.set_page(hw,
4076 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004077 if (ret_val)
4078 goto release;
4079 }
4080
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004081 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004082 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4083 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004084 if (!ret_val)
4085 adapter->stats.scc += phy_data;
4086
4087 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004088 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4089 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004090 if (!ret_val)
4091 adapter->stats.ecol += phy_data;
4092
4093 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004094 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4095 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004096 if (!ret_val)
4097 adapter->stats.mcc += phy_data;
4098
4099 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004100 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4101 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004102 if (!ret_val)
4103 adapter->stats.latecol += phy_data;
4104
4105 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004106 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4107 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004108 if (!ret_val)
4109 hw->mac.collision_delta = phy_data;
4110
4111 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004112 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4113 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004114 if (!ret_val)
4115 adapter->stats.dc += phy_data;
4116
4117 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004118 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4119 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004120 if (!ret_val)
4121 adapter->stats.tncrs += phy_data;
4122
4123release:
4124 hw->phy.ops.release(hw);
4125}
4126
4127/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004128 * e1000e_update_stats - Update the board statistics counters
4129 * @adapter: board private structure
4130 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004131static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004132{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004133 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004134 struct e1000_hw *hw = &adapter->hw;
4135 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004136
4137 /*
4138 * Prevent stats update while adapter is being reset, or if the pci
4139 * connection is down.
4140 */
4141 if (adapter->link_speed == 0)
4142 return;
4143 if (pci_channel_offline(pdev))
4144 return;
4145
Auke Kokbc7f75f2007-09-17 12:30:59 -07004146 adapter->stats.crcerrs += er32(CRCERRS);
4147 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004148 adapter->stats.gorc += er32(GORCL);
4149 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004150 adapter->stats.bprc += er32(BPRC);
4151 adapter->stats.mprc += er32(MPRC);
4152 adapter->stats.roc += er32(ROC);
4153
Auke Kokbc7f75f2007-09-17 12:30:59 -07004154 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004155
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004156 /* Half-duplex statistics */
4157 if (adapter->link_duplex == HALF_DUPLEX) {
4158 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4159 e1000e_update_phy_stats(adapter);
4160 } else {
4161 adapter->stats.scc += er32(SCC);
4162 adapter->stats.ecol += er32(ECOL);
4163 adapter->stats.mcc += er32(MCC);
4164 adapter->stats.latecol += er32(LATECOL);
4165 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004166
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004167 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004168
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004169 if ((hw->mac.type != e1000_82574) &&
4170 (hw->mac.type != e1000_82583))
4171 adapter->stats.tncrs += er32(TNCRS);
4172 }
4173 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004174 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004175
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176 adapter->stats.xonrxc += er32(XONRXC);
4177 adapter->stats.xontxc += er32(XONTXC);
4178 adapter->stats.xoffrxc += er32(XOFFRXC);
4179 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004180 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004181 adapter->stats.gotc += er32(GOTCL);
4182 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004183 adapter->stats.rnbc += er32(RNBC);
4184 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004185
4186 adapter->stats.mptc += er32(MPTC);
4187 adapter->stats.bptc += er32(BPTC);
4188
4189 /* used for adaptive IFS */
4190
4191 hw->mac.tx_packet_delta = er32(TPT);
4192 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004193
4194 adapter->stats.algnerrc += er32(ALGNERRC);
4195 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004196 adapter->stats.cexterr += er32(CEXTERR);
4197 adapter->stats.tsctc += er32(TSCTC);
4198 adapter->stats.tsctfc += er32(TSCTFC);
4199
Auke Kokbc7f75f2007-09-17 12:30:59 -07004200 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004201 netdev->stats.multicast = adapter->stats.mprc;
4202 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004203
4204 /* Rx Errors */
4205
Bruce Allanad680762008-03-28 09:15:03 -07004206 /*
4207 * RLEC on some newer hardware can be incorrect so build
4208 * our own version based on RUC and ROC
4209 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004210 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004211 adapter->stats.crcerrs + adapter->stats.algnerrc +
4212 adapter->stats.ruc + adapter->stats.roc +
4213 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004214 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004215 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004216 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4217 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4218 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004219
4220 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004221 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004223 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4224 netdev->stats.tx_window_errors = adapter->stats.latecol;
4225 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004226
4227 /* Tx Dropped needs to be maintained elsewhere */
4228
Auke Kokbc7f75f2007-09-17 12:30:59 -07004229 /* Management Stats */
4230 adapter->stats.mgptc += er32(MGTPTC);
4231 adapter->stats.mgprc += er32(MGTPRC);
4232 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004233}
4234
Bruce Allan7c257692008-04-23 11:09:00 -07004235/**
4236 * e1000_phy_read_status - Update the PHY register status snapshot
4237 * @adapter: board private structure
4238 **/
4239static void e1000_phy_read_status(struct e1000_adapter *adapter)
4240{
4241 struct e1000_hw *hw = &adapter->hw;
4242 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004243
4244 if ((er32(STATUS) & E1000_STATUS_LU) &&
4245 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004246 int ret_val;
4247
Bruce Allan7c257692008-04-23 11:09:00 -07004248 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4249 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4250 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4251 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4252 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4253 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4254 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4255 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4256 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004257 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004258 } else {
4259 /*
4260 * Do not read PHY registers if link is not up
4261 * Set values to typical power-on defaults
4262 */
4263 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4264 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4265 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4266 BMSR_ERCAP);
4267 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4268 ADVERTISE_ALL | ADVERTISE_CSMA);
4269 phy->lpa = 0;
4270 phy->expansion = EXPANSION_ENABLENPAGE;
4271 phy->ctrl1000 = ADVERTISE_1000FULL;
4272 phy->stat1000 = 0;
4273 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4274 }
Bruce Allan7c257692008-04-23 11:09:00 -07004275}
4276
Auke Kokbc7f75f2007-09-17 12:30:59 -07004277static void e1000_print_link_info(struct e1000_adapter *adapter)
4278{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004279 struct e1000_hw *hw = &adapter->hw;
4280 u32 ctrl = er32(CTRL);
4281
Bruce Allan8f12fe82008-11-21 16:54:43 -08004282 /* Link status message must follow this format for user tools */
Jeff Kirsheref456f82011-11-03 11:40:28 +00004283 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4284 adapter->netdev->name,
4285 adapter->link_speed,
4286 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4287 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4288 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4289 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004290}
4291
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004292static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004293{
4294 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004295 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004296 s32 ret_val = 0;
4297
4298 /*
4299 * get_link_status is set on LSC (link status) interrupt or
4300 * Rx sequence error interrupt. get_link_status will stay
4301 * false until the check_for_link establishes link
4302 * for copper adapters ONLY
4303 */
4304 switch (hw->phy.media_type) {
4305 case e1000_media_type_copper:
4306 if (hw->mac.get_link_status) {
4307 ret_val = hw->mac.ops.check_for_link(hw);
4308 link_active = !hw->mac.get_link_status;
4309 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004310 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004311 }
4312 break;
4313 case e1000_media_type_fiber:
4314 ret_val = hw->mac.ops.check_for_link(hw);
4315 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4316 break;
4317 case e1000_media_type_internal_serdes:
4318 ret_val = hw->mac.ops.check_for_link(hw);
4319 link_active = adapter->hw.mac.serdes_has_link;
4320 break;
4321 default:
4322 case e1000_media_type_unknown:
4323 break;
4324 }
4325
4326 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4327 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4328 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004329 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004330 }
4331
4332 return link_active;
4333}
4334
4335static void e1000e_enable_receives(struct e1000_adapter *adapter)
4336{
4337 /* make sure the receive unit is started */
4338 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4339 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4340 struct e1000_hw *hw = &adapter->hw;
4341 u32 rctl = er32(RCTL);
4342 ew32(RCTL, rctl | E1000_RCTL_EN);
4343 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4344 }
4345}
4346
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004347static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4348{
4349 struct e1000_hw *hw = &adapter->hw;
4350
4351 /*
4352 * With 82574 controllers, PHY needs to be checked periodically
4353 * for hung state and reset, if two calls return true
4354 */
4355 if (e1000_check_phy_82574(hw))
4356 adapter->phy_hang_count++;
4357 else
4358 adapter->phy_hang_count = 0;
4359
4360 if (adapter->phy_hang_count > 1) {
4361 adapter->phy_hang_count = 0;
4362 schedule_work(&adapter->reset_task);
4363 }
4364}
4365
Auke Kokbc7f75f2007-09-17 12:30:59 -07004366/**
4367 * e1000_watchdog - Timer Call-back
4368 * @data: pointer to adapter cast into an unsigned long
4369 **/
4370static void e1000_watchdog(unsigned long data)
4371{
4372 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4373
4374 /* Do the rest outside of interrupt context */
4375 schedule_work(&adapter->watchdog_task);
4376
4377 /* TODO: make this use queue_delayed_work() */
4378}
4379
4380static void e1000_watchdog_task(struct work_struct *work)
4381{
4382 struct e1000_adapter *adapter = container_of(work,
4383 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004384 struct net_device *netdev = adapter->netdev;
4385 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004386 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004387 struct e1000_ring *tx_ring = adapter->tx_ring;
4388 struct e1000_hw *hw = &adapter->hw;
4389 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004390
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004391 if (test_bit(__E1000_DOWN, &adapter->state))
4392 return;
4393
David S. Millerb405e8d2010-02-04 22:31:41 -08004394 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004395 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004396 /* Cancel scheduled suspend requests. */
4397 pm_runtime_resume(netdev->dev.parent);
4398
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004399 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004400 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004401 }
4402
4403 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4404 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4405 e1000_update_mng_vlan(adapter);
4406
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407 if (link) {
4408 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004409 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004410
4411 /* Cancel scheduled suspend requests. */
4412 pm_runtime_resume(netdev->dev.parent);
4413
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004414 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004415 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004416 mac->ops.get_link_up_info(&adapter->hw,
4417 &adapter->link_speed,
4418 &adapter->link_duplex);
4419 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004420 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004421 * On supported PHYs, check for duplex mismatch only
4422 * if link has autonegotiated at 10/100 half
4423 */
4424 if ((hw->phy.type == e1000_phy_igp_3 ||
4425 hw->phy.type == e1000_phy_bm) &&
4426 (hw->mac.autoneg == true) &&
4427 (adapter->link_speed == SPEED_10 ||
4428 adapter->link_speed == SPEED_100) &&
4429 (adapter->link_duplex == HALF_DUPLEX)) {
4430 u16 autoneg_exp;
4431
4432 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4433
4434 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004435 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 -07004436 }
4437
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004438 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004439 adapter->tx_timeout_factor = 1;
4440 switch (adapter->link_speed) {
4441 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004442 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004443 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004444 break;
4445 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004446 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004447 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004448 break;
4449 }
4450
Bruce Allanad680762008-03-28 09:15:03 -07004451 /*
4452 * workaround: re-program speed mode bit after
4453 * link-up event
4454 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004455 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4456 !txb2b) {
4457 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004458 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004459 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004460 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004461 }
4462
Bruce Allanad680762008-03-28 09:15:03 -07004463 /*
4464 * disable TSO for pcie and 10/100 speeds, to avoid
4465 * some hardware issues
4466 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004467 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4468 switch (adapter->link_speed) {
4469 case SPEED_10:
4470 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004471 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004472 netdev->features &= ~NETIF_F_TSO;
4473 netdev->features &= ~NETIF_F_TSO6;
4474 break;
4475 case SPEED_1000:
4476 netdev->features |= NETIF_F_TSO;
4477 netdev->features |= NETIF_F_TSO6;
4478 break;
4479 default:
4480 /* oops */
4481 break;
4482 }
4483 }
4484
Bruce Allanad680762008-03-28 09:15:03 -07004485 /*
4486 * enable transmits in the hardware, need to do this
4487 * after setting TARC(0)
4488 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004489 tctl = er32(TCTL);
4490 tctl |= E1000_TCTL_EN;
4491 ew32(TCTL, tctl);
4492
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004493 /*
4494 * Perform any post-link-up configuration before
4495 * reporting link up.
4496 */
4497 if (phy->ops.cfg_on_link_up)
4498 phy->ops.cfg_on_link_up(hw);
4499
Auke Kokbc7f75f2007-09-17 12:30:59 -07004500 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004501
4502 if (!test_bit(__E1000_DOWN, &adapter->state))
4503 mod_timer(&adapter->phy_info_timer,
4504 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004505 }
4506 } else {
4507 if (netif_carrier_ok(netdev)) {
4508 adapter->link_speed = 0;
4509 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004510 /* Link status message must follow this format */
4511 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4512 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004513 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004514 if (!test_bit(__E1000_DOWN, &adapter->state))
4515 mod_timer(&adapter->phy_info_timer,
4516 round_jiffies(jiffies + 2 * HZ));
4517
4518 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4519 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004520 else
4521 pm_schedule_suspend(netdev->dev.parent,
4522 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004523 }
4524 }
4525
4526link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004527 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004528 e1000e_update_stats(adapter);
4529
4530 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4531 adapter->tpt_old = adapter->stats.tpt;
4532 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4533 adapter->colc_old = adapter->stats.colc;
4534
Bruce Allan7c257692008-04-23 11:09:00 -07004535 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4536 adapter->gorc_old = adapter->stats.gorc;
4537 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4538 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004539 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540
4541 e1000e_update_adaptive(&adapter->hw);
4542
Bruce Allan90da0662011-01-06 07:02:53 +00004543 if (!netif_carrier_ok(netdev) &&
4544 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4545 /*
4546 * We've lost link, so the controller stops DMA,
4547 * but we've got queued Tx work that's never going
4548 * to get done, so reset controller to flush Tx.
4549 * (Do the reset outside of interrupt context).
4550 */
Bruce Allan90da0662011-01-06 07:02:53 +00004551 schedule_work(&adapter->reset_task);
4552 /* return immediately since reset is imminent */
4553 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004554 }
4555
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004556 /* Simple mode for Interrupt Throttle Rate (ITR) */
4557 if (adapter->itr_setting == 4) {
4558 /*
4559 * Symmetric Tx/Rx gets a reduced ITR=2000;
4560 * Total asymmetrical Tx or Rx gets ITR=8000;
4561 * everyone else is between 2000-8000.
4562 */
4563 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4564 u32 dif = (adapter->gotc > adapter->gorc ?
4565 adapter->gotc - adapter->gorc :
4566 adapter->gorc - adapter->gotc) / 10000;
4567 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4568
4569 ew32(ITR, 1000000000 / (itr * 256));
4570 }
4571
Bruce Allanad680762008-03-28 09:15:03 -07004572 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004573 if (adapter->msix_entries)
4574 ew32(ICS, adapter->rx_ring->ims_val);
4575 else
4576 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004577
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004578 /* flush pending descriptors to memory before detecting Tx hang */
4579 e1000e_flush_descriptors(adapter);
4580
Auke Kokbc7f75f2007-09-17 12:30:59 -07004581 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004582 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004583
Bruce Allanad680762008-03-28 09:15:03 -07004584 /*
4585 * With 82571 controllers, LAA may be overwritten due to controller
4586 * reset from the other port. Set the appropriate LAA in RAR[0]
4587 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004588 if (e1000e_get_laa_state_82571(hw))
4589 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4590
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004591 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4592 e1000e_check_82574_phy_workaround(adapter);
4593
Auke Kokbc7f75f2007-09-17 12:30:59 -07004594 /* Reset the timer */
4595 if (!test_bit(__E1000_DOWN, &adapter->state))
4596 mod_timer(&adapter->watchdog_timer,
4597 round_jiffies(jiffies + 2 * HZ));
4598}
4599
4600#define E1000_TX_FLAGS_CSUM 0x00000001
4601#define E1000_TX_FLAGS_VLAN 0x00000002
4602#define E1000_TX_FLAGS_TSO 0x00000004
4603#define E1000_TX_FLAGS_IPV4 0x00000008
4604#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4605#define E1000_TX_FLAGS_VLAN_SHIFT 16
4606
Bruce Allan55aa6982011-12-16 00:45:45 +00004607static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004608{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004609 struct e1000_context_desc *context_desc;
4610 struct e1000_buffer *buffer_info;
4611 unsigned int i;
4612 u32 cmd_length = 0;
4613 u16 ipcse = 0, tucse, mss;
4614 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004615
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004616 if (!skb_is_gso(skb))
4617 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004618
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004619 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004620 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4621
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004622 if (err)
4623 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004624 }
4625
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004626 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4627 mss = skb_shinfo(skb)->gso_size;
4628 if (skb->protocol == htons(ETH_P_IP)) {
4629 struct iphdr *iph = ip_hdr(skb);
4630 iph->tot_len = 0;
4631 iph->check = 0;
4632 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4633 0, IPPROTO_TCP, 0);
4634 cmd_length = E1000_TXD_CMD_IP;
4635 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004636 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004637 ipv6_hdr(skb)->payload_len = 0;
4638 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4639 &ipv6_hdr(skb)->daddr,
4640 0, IPPROTO_TCP, 0);
4641 ipcse = 0;
4642 }
4643 ipcss = skb_network_offset(skb);
4644 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4645 tucss = skb_transport_offset(skb);
4646 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4647 tucse = 0;
4648
4649 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4650 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4651
4652 i = tx_ring->next_to_use;
4653 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4654 buffer_info = &tx_ring->buffer_info[i];
4655
4656 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4657 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4658 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4659 context_desc->upper_setup.tcp_fields.tucss = tucss;
4660 context_desc->upper_setup.tcp_fields.tucso = tucso;
4661 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4662 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4663 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4664 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4665
4666 buffer_info->time_stamp = jiffies;
4667 buffer_info->next_to_watch = i;
4668
4669 i++;
4670 if (i == tx_ring->count)
4671 i = 0;
4672 tx_ring->next_to_use = i;
4673
4674 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004675}
4676
Bruce Allan55aa6982011-12-16 00:45:45 +00004677static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004678{
Bruce Allan55aa6982011-12-16 00:45:45 +00004679 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004680 struct e1000_context_desc *context_desc;
4681 struct e1000_buffer *buffer_info;
4682 unsigned int i;
4683 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004684 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004685 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004686
Dave Grahamaf807c82008-10-09 14:28:58 -07004687 if (skb->ip_summed != CHECKSUM_PARTIAL)
4688 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004689
Arthur Jones5f66f202009-03-19 01:13:08 +00004690 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4691 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4692 else
4693 protocol = skb->protocol;
4694
Arthur Jones3f518392009-03-20 15:56:35 -07004695 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004696 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004697 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4698 cmd_len |= E1000_TXD_CMD_TCP;
4699 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004700 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004701 /* XXX not handling all IPV6 headers */
4702 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4703 cmd_len |= E1000_TXD_CMD_TCP;
4704 break;
4705 default:
4706 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004707 e_warn("checksum_partial proto=%x!\n",
4708 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004709 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004710 }
4711
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004712 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004713
4714 i = tx_ring->next_to_use;
4715 buffer_info = &tx_ring->buffer_info[i];
4716 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4717
4718 context_desc->lower_setup.ip_config = 0;
4719 context_desc->upper_setup.tcp_fields.tucss = css;
4720 context_desc->upper_setup.tcp_fields.tucso =
4721 css + skb->csum_offset;
4722 context_desc->upper_setup.tcp_fields.tucse = 0;
4723 context_desc->tcp_seg_setup.data = 0;
4724 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4725
4726 buffer_info->time_stamp = jiffies;
4727 buffer_info->next_to_watch = i;
4728
4729 i++;
4730 if (i == tx_ring->count)
4731 i = 0;
4732 tx_ring->next_to_use = i;
4733
4734 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004735}
4736
4737#define E1000_MAX_PER_TXD 8192
4738#define E1000_MAX_TXD_PWR 12
4739
Bruce Allan55aa6982011-12-16 00:45:45 +00004740static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
4741 unsigned int first, unsigned int max_per_txd,
4742 unsigned int nr_frags, unsigned int mss)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004743{
Bruce Allan55aa6982011-12-16 00:45:45 +00004744 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00004745 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004746 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004747 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004748 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004749 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004750
4751 i = tx_ring->next_to_use;
4752
4753 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004754 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004755 size = min(len, max_per_txd);
4756
Auke Kokbc7f75f2007-09-17 12:30:59 -07004757 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004758 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004759 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004760 buffer_info->dma = dma_map_single(&pdev->dev,
4761 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004762 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004763 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004764 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004765 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004766
4767 len -= size;
4768 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004769 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004770
4771 if (len) {
4772 i++;
4773 if (i == tx_ring->count)
4774 i = 0;
4775 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004776 }
4777
4778 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004779 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004780
4781 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004782 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004783 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004784
4785 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004786 i++;
4787 if (i == tx_ring->count)
4788 i = 0;
4789
Auke Kokbc7f75f2007-09-17 12:30:59 -07004790 buffer_info = &tx_ring->buffer_info[i];
4791 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004792
4793 buffer_info->length = size;
4794 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004795 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004796 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4797 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004798 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004799 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004800 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004801
4802 len -= size;
4803 offset += size;
4804 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004805 }
4806 }
4807
Bruce Allanaf667a22010-12-31 06:10:01 +00004808 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004809 /* multiply data chunks by size of headers */
4810 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4811
Auke Kokbc7f75f2007-09-17 12:30:59 -07004812 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004813 tx_ring->buffer_info[i].segs = segs;
4814 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004815 tx_ring->buffer_info[first].next_to_watch = i;
4816
4817 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004818
4819dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004820 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004821 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004822 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004823 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004824
4825 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004826 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004827 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004828 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004829 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00004830 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004831 }
4832
4833 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004834}
4835
Bruce Allan55aa6982011-12-16 00:45:45 +00004836static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004837{
Bruce Allan55aa6982011-12-16 00:45:45 +00004838 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004839 struct e1000_tx_desc *tx_desc = NULL;
4840 struct e1000_buffer *buffer_info;
4841 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4842 unsigned int i;
4843
4844 if (tx_flags & E1000_TX_FLAGS_TSO) {
4845 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4846 E1000_TXD_CMD_TSE;
4847 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4848
4849 if (tx_flags & E1000_TX_FLAGS_IPV4)
4850 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4851 }
4852
4853 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4854 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4855 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4856 }
4857
4858 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4859 txd_lower |= E1000_TXD_CMD_VLE;
4860 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4861 }
4862
4863 i = tx_ring->next_to_use;
4864
Bruce Allan36b973d2010-11-24 07:42:43 +00004865 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004866 buffer_info = &tx_ring->buffer_info[i];
4867 tx_desc = E1000_TX_DESC(*tx_ring, i);
4868 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4869 tx_desc->lower.data =
4870 cpu_to_le32(txd_lower | buffer_info->length);
4871 tx_desc->upper.data = cpu_to_le32(txd_upper);
4872
4873 i++;
4874 if (i == tx_ring->count)
4875 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004876 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004877
4878 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4879
Bruce Allanad680762008-03-28 09:15:03 -07004880 /*
4881 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004882 * know there are new descriptors to fetch. (Only
4883 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004884 * such as IA-64).
4885 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004886 wmb();
4887
4888 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004889
4890 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00004891 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07004892 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00004893 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07004894
Bruce Allanad680762008-03-28 09:15:03 -07004895 /*
4896 * we need this if more than one processor can write to our tail
4897 * at a time, it synchronizes IO on IA64/Altix systems
4898 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004899 mmiowb();
4900}
4901
4902#define MINIMUM_DHCP_PACKET_SIZE 282
4903static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4904 struct sk_buff *skb)
4905{
4906 struct e1000_hw *hw = &adapter->hw;
4907 u16 length, offset;
4908
4909 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004910 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4911 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004912 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4913 return 0;
4914 }
4915
4916 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4917 return 0;
4918
4919 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4920 return 0;
4921
4922 {
4923 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4924 struct udphdr *udp;
4925
4926 if (ip->protocol != IPPROTO_UDP)
4927 return 0;
4928
4929 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4930 if (ntohs(udp->dest) != 67)
4931 return 0;
4932
4933 offset = (u8 *)udp + 8 - skb->data;
4934 length = skb->len - offset;
4935 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4936 }
4937
4938 return 0;
4939}
4940
Bruce Allan55aa6982011-12-16 00:45:45 +00004941static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004942{
Bruce Allan55aa6982011-12-16 00:45:45 +00004943 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004944
Bruce Allan55aa6982011-12-16 00:45:45 +00004945 netif_stop_queue(adapter->netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004946 /*
4947 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004948 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004949 * but since that doesn't exist yet, just open code it.
4950 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004951 smp_mb();
4952
Bruce Allanad680762008-03-28 09:15:03 -07004953 /*
4954 * We need to check again in a case another CPU has just
4955 * made room available.
4956 */
Bruce Allan55aa6982011-12-16 00:45:45 +00004957 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004958 return -EBUSY;
4959
4960 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00004961 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004962 ++adapter->restart_queue;
4963 return 0;
4964}
4965
Bruce Allan55aa6982011-12-16 00:45:45 +00004966static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004967{
Bruce Allan55aa6982011-12-16 00:45:45 +00004968 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004969 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00004970 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004971}
4972
Bruce Allan0e15df42012-01-31 06:37:11 +00004973#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1)
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004974static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4975 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004976{
4977 struct e1000_adapter *adapter = netdev_priv(netdev);
4978 struct e1000_ring *tx_ring = adapter->tx_ring;
4979 unsigned int first;
4980 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4981 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4982 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004983 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004984 unsigned int nr_frags;
4985 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004986 int count = 0;
4987 int tso;
4988 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004989
4990 if (test_bit(__E1000_DOWN, &adapter->state)) {
4991 dev_kfree_skb_any(skb);
4992 return NETDEV_TX_OK;
4993 }
4994
4995 if (skb->len <= 0) {
4996 dev_kfree_skb_any(skb);
4997 return NETDEV_TX_OK;
4998 }
4999
5000 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07005001 /*
5002 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07005003 * make sure there is enough room in the FIFO before
5004 * initiating the DMA for each buffer. The calc is:
5005 * 4 = ceil(buffer len/mss). To make sure we don't
5006 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07005007 * drops.
5008 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005009 if (mss) {
5010 u8 hdr_len;
5011 max_per_txd = min(mss << 2, max_per_txd);
5012 max_txd_pwr = fls(max_per_txd) - 1;
5013
Bruce Allanad680762008-03-28 09:15:03 -07005014 /*
5015 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
5016 * points to just header, pull a few bytes of payload from
5017 * frags into skb->data
5018 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005019 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07005020 /*
5021 * we do this workaround for ES2LAN, but it is un-necessary,
5022 * avoiding it could save a lot of cycles
5023 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005024 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005025 unsigned int pull_size;
5026
Bruce Allana2a5b322012-01-31 06:37:17 +00005027 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005028 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005029 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005030 dev_kfree_skb_any(skb);
5031 return NETDEV_TX_OK;
5032 }
Eric Dumazete743d312010-04-14 15:59:40 -07005033 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005034 }
5035 }
5036
5037 /* reserve a descriptor for the offload context */
5038 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5039 count++;
5040 count++;
5041
5042 count += TXD_USE_COUNT(len, max_txd_pwr);
5043
5044 nr_frags = skb_shinfo(skb)->nr_frags;
5045 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00005046 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07005047 max_txd_pwr);
5048
5049 if (adapter->hw.mac.tx_pkt_filtering)
5050 e1000_transfer_dhcp_info(adapter, skb);
5051
Bruce Allanad680762008-03-28 09:15:03 -07005052 /*
5053 * need: count + 2 desc gap to keep tail from touching
5054 * head, otherwise try next time
5055 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005056 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005057 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005058
Jesse Grosseab6d182010-10-20 13:56:03 +00005059 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005060 tx_flags |= E1000_TX_FLAGS_VLAN;
5061 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5062 }
5063
5064 first = tx_ring->next_to_use;
5065
Bruce Allan55aa6982011-12-16 00:45:45 +00005066 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005067 if (tso < 0) {
5068 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005069 return NETDEV_TX_OK;
5070 }
5071
5072 if (tso)
5073 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005074 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005075 tx_flags |= E1000_TX_FLAGS_CSUM;
5076
Bruce Allanad680762008-03-28 09:15:03 -07005077 /*
5078 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005079 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005080 * no longer assume, we must.
5081 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005082 if (skb->protocol == htons(ETH_P_IP))
5083 tx_flags |= E1000_TX_FLAGS_IPV4;
5084
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005085 /* if count is 0 then mapping error has occurred */
Bruce Allan55aa6982011-12-16 00:45:45 +00005086 count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005087 if (count) {
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005088 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005089 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005090 /* Make sure there is space in the ring for the next send. */
Bruce Allan55aa6982011-12-16 00:45:45 +00005091 e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005092
5093 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005094 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005095 tx_ring->buffer_info[first].time_stamp = 0;
5096 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005097 }
5098
Auke Kokbc7f75f2007-09-17 12:30:59 -07005099 return NETDEV_TX_OK;
5100}
5101
5102/**
5103 * e1000_tx_timeout - Respond to a Tx Hang
5104 * @netdev: network interface device structure
5105 **/
5106static void e1000_tx_timeout(struct net_device *netdev)
5107{
5108 struct e1000_adapter *adapter = netdev_priv(netdev);
5109
5110 /* Do the reset outside of interrupt context */
5111 adapter->tx_timeout_count++;
5112 schedule_work(&adapter->reset_task);
5113}
5114
5115static void e1000_reset_task(struct work_struct *work)
5116{
5117 struct e1000_adapter *adapter;
5118 adapter = container_of(work, struct e1000_adapter, reset_task);
5119
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005120 /* don't run the task if already down */
5121 if (test_bit(__E1000_DOWN, &adapter->state))
5122 return;
5123
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005124 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5125 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5126 e1000e_dump(adapter);
5127 e_err("Reset adapter\n");
5128 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005129 e1000e_reinit_locked(adapter);
5130}
5131
5132/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005133 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005134 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005135 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005136 *
5137 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005138 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005139struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5140 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005141{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005142 struct e1000_adapter *adapter = netdev_priv(netdev);
5143
5144 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5145 spin_lock(&adapter->stats64_lock);
5146 e1000e_update_stats(adapter);
5147 /* Fill out the OS statistics structure */
5148 stats->rx_bytes = adapter->stats.gorc;
5149 stats->rx_packets = adapter->stats.gprc;
5150 stats->tx_bytes = adapter->stats.gotc;
5151 stats->tx_packets = adapter->stats.gptc;
5152 stats->multicast = adapter->stats.mprc;
5153 stats->collisions = adapter->stats.colc;
5154
5155 /* Rx Errors */
5156
5157 /*
5158 * RLEC on some newer hardware can be incorrect so build
5159 * our own version based on RUC and ROC
5160 */
5161 stats->rx_errors = adapter->stats.rxerrc +
5162 adapter->stats.crcerrs + adapter->stats.algnerrc +
5163 adapter->stats.ruc + adapter->stats.roc +
5164 adapter->stats.cexterr;
5165 stats->rx_length_errors = adapter->stats.ruc +
5166 adapter->stats.roc;
5167 stats->rx_crc_errors = adapter->stats.crcerrs;
5168 stats->rx_frame_errors = adapter->stats.algnerrc;
5169 stats->rx_missed_errors = adapter->stats.mpc;
5170
5171 /* Tx Errors */
5172 stats->tx_errors = adapter->stats.ecol +
5173 adapter->stats.latecol;
5174 stats->tx_aborted_errors = adapter->stats.ecol;
5175 stats->tx_window_errors = adapter->stats.latecol;
5176 stats->tx_carrier_errors = adapter->stats.tncrs;
5177
5178 /* Tx Dropped needs to be maintained elsewhere */
5179
5180 spin_unlock(&adapter->stats64_lock);
5181 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005182}
5183
5184/**
5185 * e1000_change_mtu - Change the Maximum Transfer Unit
5186 * @netdev: network interface device structure
5187 * @new_mtu: new value for maximum frame size
5188 *
5189 * Returns 0 on success, negative on failure
5190 **/
5191static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5192{
5193 struct e1000_adapter *adapter = netdev_priv(netdev);
5194 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5195
Bruce Allan2adc55c2009-06-02 11:28:58 +00005196 /* Jumbo frame support */
Bruce Allan70495a52012-01-11 01:26:50 +00005197 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
5198 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5199 e_err("Jumbo Frames not supported.\n");
5200 return -EINVAL;
5201 }
5202
5203 /*
5204 * IP payload checksum (enabled with jumbos/packet-split when
5205 * Rx checksum is enabled) and generation of RSS hash is
5206 * mutually exclusive in the hardware.
5207 */
5208 if ((netdev->features & NETIF_F_RXCSUM) &&
5209 (netdev->features & NETIF_F_RXHASH)) {
5210 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");
5211 return -EINVAL;
5212 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213 }
5214
Bruce Allan2adc55c2009-06-02 11:28:58 +00005215 /* Supported frame sizes */
5216 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5217 (max_frame > adapter->max_hw_frame_size)) {
5218 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005219 return -EINVAL;
5220 }
5221
Bruce Allana1ce6472010-09-22 17:16:40 +00005222 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5223 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5224 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5225 (new_mtu > ETH_DATA_LEN)) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00005226 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005227 return -EINVAL;
5228 }
5229
Bruce Allan6f461f62010-04-27 03:33:04 +00005230 /* 82573 Errata 17 */
5231 if (((adapter->hw.mac.type == e1000_82573) ||
5232 (adapter->hw.mac.type == e1000_82574)) &&
5233 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5234 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5235 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5236 }
5237
Auke Kokbc7f75f2007-09-17 12:30:59 -07005238 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005239 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005240 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005241 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005242 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5243 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005244 if (netif_running(netdev))
5245 e1000e_down(adapter);
5246
Bruce Allanad680762008-03-28 09:15:03 -07005247 /*
5248 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005249 * means we reserve 2 more, this pushes us to allocate from the next
5250 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005251 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005252 * However with the new *_jumbo_rx* routines, jumbo receives will use
5253 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005254 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005255
Jesse Brandeburg99261462010-01-22 22:56:16 +00005256 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005257 adapter->rx_buffer_len = 2048;
5258 else
5259 adapter->rx_buffer_len = 4096;
5260
5261 /* adjust allocation if LPE protects us, and we aren't using SBP */
5262 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5263 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5264 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005265 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005266
Auke Kokbc7f75f2007-09-17 12:30:59 -07005267 if (netif_running(netdev))
5268 e1000e_up(adapter);
5269 else
5270 e1000e_reset(adapter);
5271
5272 clear_bit(__E1000_RESETTING, &adapter->state);
5273
5274 return 0;
5275}
5276
5277static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5278 int cmd)
5279{
5280 struct e1000_adapter *adapter = netdev_priv(netdev);
5281 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005282
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005283 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005284 return -EOPNOTSUPP;
5285
5286 switch (cmd) {
5287 case SIOCGMIIPHY:
5288 data->phy_id = adapter->hw.phy.addr;
5289 break;
5290 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005291 e1000_phy_read_status(adapter);
5292
Bruce Allan7c257692008-04-23 11:09:00 -07005293 switch (data->reg_num & 0x1F) {
5294 case MII_BMCR:
5295 data->val_out = adapter->phy_regs.bmcr;
5296 break;
5297 case MII_BMSR:
5298 data->val_out = adapter->phy_regs.bmsr;
5299 break;
5300 case MII_PHYSID1:
5301 data->val_out = (adapter->hw.phy.id >> 16);
5302 break;
5303 case MII_PHYSID2:
5304 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5305 break;
5306 case MII_ADVERTISE:
5307 data->val_out = adapter->phy_regs.advertise;
5308 break;
5309 case MII_LPA:
5310 data->val_out = adapter->phy_regs.lpa;
5311 break;
5312 case MII_EXPANSION:
5313 data->val_out = adapter->phy_regs.expansion;
5314 break;
5315 case MII_CTRL1000:
5316 data->val_out = adapter->phy_regs.ctrl1000;
5317 break;
5318 case MII_STAT1000:
5319 data->val_out = adapter->phy_regs.stat1000;
5320 break;
5321 case MII_ESTATUS:
5322 data->val_out = adapter->phy_regs.estatus;
5323 break;
5324 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005325 return -EIO;
5326 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005327 break;
5328 case SIOCSMIIREG:
5329 default:
5330 return -EOPNOTSUPP;
5331 }
5332 return 0;
5333}
5334
5335static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5336{
5337 switch (cmd) {
5338 case SIOCGMIIPHY:
5339 case SIOCGMIIREG:
5340 case SIOCSMIIREG:
5341 return e1000_mii_ioctl(netdev, ifr, cmd);
5342 default:
5343 return -EOPNOTSUPP;
5344 }
5345}
5346
Bruce Allana4f58f52009-06-02 11:29:18 +00005347static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5348{
5349 struct e1000_hw *hw = &adapter->hw;
5350 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005351 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005352 int retval = 0;
5353
5354 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005355 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005356
Bruce Allan2b6b1682011-05-13 07:20:09 +00005357 retval = hw->phy.ops.acquire(hw);
5358 if (retval) {
5359 e_err("Could not acquire PHY\n");
5360 return retval;
5361 }
5362
5363 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5364 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5365 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005366 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005367
5368 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005369 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5370 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005371 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5372 (u16)(mac_reg & 0xFFFF));
5373 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5374 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005375 }
5376
5377 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005378 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005379 mac_reg = er32(RCTL);
5380 if (mac_reg & E1000_RCTL_UPE)
5381 phy_reg |= BM_RCTL_UPE;
5382 if (mac_reg & E1000_RCTL_MPE)
5383 phy_reg |= BM_RCTL_MPE;
5384 phy_reg &= ~(BM_RCTL_MO_MASK);
5385 if (mac_reg & E1000_RCTL_MO_3)
5386 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5387 << BM_RCTL_MO_SHIFT);
5388 if (mac_reg & E1000_RCTL_BAM)
5389 phy_reg |= BM_RCTL_BAM;
5390 if (mac_reg & E1000_RCTL_PMCF)
5391 phy_reg |= BM_RCTL_PMCF;
5392 mac_reg = er32(CTRL);
5393 if (mac_reg & E1000_CTRL_RFCE)
5394 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005395 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005396
5397 /* enable PHY wakeup in MAC register */
5398 ew32(WUFC, wufc);
5399 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5400
5401 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005402 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5403 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005404
5405 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005406 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5407 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005408 if (retval)
5409 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005410release:
Bruce Allan94d81862009-11-20 23:25:26 +00005411 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005412
5413 return retval;
5414}
5415
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005416static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5417 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005418{
5419 struct net_device *netdev = pci_get_drvdata(pdev);
5420 struct e1000_adapter *adapter = netdev_priv(netdev);
5421 struct e1000_hw *hw = &adapter->hw;
5422 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005423 /* Runtime suspend should only enable wakeup for link changes */
5424 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005425 int retval = 0;
5426
5427 netif_device_detach(netdev);
5428
5429 if (netif_running(netdev)) {
5430 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5431 e1000e_down(adapter);
5432 e1000_free_irq(adapter);
5433 }
Bruce Allan4662e822008-08-26 18:37:06 -07005434 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005435
5436 retval = pci_save_state(pdev);
5437 if (retval)
5438 return retval;
5439
5440 status = er32(STATUS);
5441 if (status & E1000_STATUS_LU)
5442 wufc &= ~E1000_WUFC_LNKC;
5443
5444 if (wufc) {
5445 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005446 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005447
5448 /* turn on all-multi mode if wake on multicast is enabled */
5449 if (wufc & E1000_WUFC_MC) {
5450 rctl = er32(RCTL);
5451 rctl |= E1000_RCTL_MPE;
5452 ew32(RCTL, rctl);
5453 }
5454
5455 ctrl = er32(CTRL);
5456 /* advertise wake from D3Cold */
5457 #define E1000_CTRL_ADVD3WUC 0x00100000
5458 /* phy power management enable */
5459 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005460 ctrl |= E1000_CTRL_ADVD3WUC;
5461 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5462 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005463 ew32(CTRL, ctrl);
5464
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005465 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5466 adapter->hw.phy.media_type ==
5467 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005468 /* keep the laser running in D3 */
5469 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005470 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005471 ew32(CTRL_EXT, ctrl_ext);
5472 }
5473
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005474 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005475 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005476
Auke Kokbc7f75f2007-09-17 12:30:59 -07005477 /* Allow time for pending master requests to run */
5478 e1000e_disable_pcie_master(&adapter->hw);
5479
Bruce Allan82776a42009-08-14 14:35:33 +00005480 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005481 /* enable wakeup by the PHY */
5482 retval = e1000_init_phy_wakeup(adapter, wufc);
5483 if (retval)
5484 return retval;
5485 } else {
5486 /* enable wakeup by the MAC */
5487 ew32(WUFC, wufc);
5488 ew32(WUC, E1000_WUC_PME_EN);
5489 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005490 } else {
5491 ew32(WUC, 0);
5492 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005493 }
5494
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005495 *enable_wake = !!wufc;
5496
Auke Kokbc7f75f2007-09-17 12:30:59 -07005497 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005498 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5499 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005500 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005501
5502 if (adapter->hw.phy.type == e1000_phy_igp_3)
5503 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5504
Bruce Allanad680762008-03-28 09:15:03 -07005505 /*
5506 * Release control of h/w to f/w. If f/w is AMT enabled, this
5507 * would have already happened in close and is redundant.
5508 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005509 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005510
5511 pci_disable_device(pdev);
5512
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005513 return 0;
5514}
5515
5516static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5517{
5518 if (sleep && wake) {
5519 pci_prepare_to_sleep(pdev);
5520 return;
5521 }
5522
5523 pci_wake_from_d3(pdev, wake);
5524 pci_set_power_state(pdev, PCI_D3hot);
5525}
5526
5527static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5528 bool wake)
5529{
5530 struct net_device *netdev = pci_get_drvdata(pdev);
5531 struct e1000_adapter *adapter = netdev_priv(netdev);
5532
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005533 /*
5534 * The pci-e switch on some quad port adapters will report a
5535 * correctable error when the MAC transitions from D0 to D3. To
5536 * prevent this we need to mask off the correctable errors on the
5537 * downstream port of the pci-e switch.
5538 */
5539 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5540 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005541 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005542 u16 devctl;
5543
5544 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5545 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5546 (devctl & ~PCI_EXP_DEVCTL_CERE));
5547
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005548 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005549
5550 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5551 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005552 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005553 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005554}
5555
Bruce Allan6f461f62010-04-27 03:33:04 +00005556#ifdef CONFIG_PCIEASPM
5557static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5558{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005559 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005560}
5561#else
5562static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005563{
5564 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005565 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005566
5567 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005568 * Both device and parent should have the same ASPM setting.
5569 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005570 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005571 pos = pci_pcie_cap(pdev);
5572 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5573 reg16 &= ~state;
5574 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5575
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005576 if (!pdev->bus->self)
5577 return;
5578
Bruce Allan6f461f62010-04-27 03:33:04 +00005579 pos = pci_pcie_cap(pdev->bus->self);
5580 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5581 reg16 &= ~state;
5582 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5583}
5584#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005585static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005586{
5587 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5588 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5589 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5590
5591 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005592}
5593
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005594#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005595static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005596{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005597 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005598}
5599
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005600static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005601{
5602 struct net_device *netdev = pci_get_drvdata(pdev);
5603 struct e1000_adapter *adapter = netdev_priv(netdev);
5604 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005605 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005606 u32 err;
5607
Bruce Allan78cd29d2011-03-24 03:09:03 +00005608 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5609 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5610 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5611 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5612 if (aspm_disable_flag)
5613 e1000e_disable_aspm(pdev, aspm_disable_flag);
5614
Auke Kokbc7f75f2007-09-17 12:30:59 -07005615 pci_set_power_state(pdev, PCI_D0);
5616 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005617 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005618
Bruce Allan4662e822008-08-26 18:37:06 -07005619 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005620 if (netif_running(netdev)) {
5621 err = e1000_request_irq(adapter);
5622 if (err)
5623 return err;
5624 }
5625
Bruce Allan99730e42011-05-13 07:19:48 +00005626 if (hw->mac.type == e1000_pch2lan)
5627 e1000_resume_workarounds_pchlan(&adapter->hw);
5628
Auke Kokbc7f75f2007-09-17 12:30:59 -07005629 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005630
5631 /* report the system wakeup cause from S3/S4 */
5632 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5633 u16 phy_data;
5634
5635 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5636 if (phy_data) {
5637 e_info("PHY Wakeup cause - %s\n",
5638 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5639 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5640 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5641 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005642 phy_data & E1000_WUS_LNKC ?
5643 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005644 }
5645 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5646 } else {
5647 u32 wus = er32(WUS);
5648 if (wus) {
5649 e_info("MAC Wakeup cause - %s\n",
5650 wus & E1000_WUS_EX ? "Unicast Packet" :
5651 wus & E1000_WUS_MC ? "Multicast Packet" :
5652 wus & E1000_WUS_BC ? "Broadcast Packet" :
5653 wus & E1000_WUS_MAG ? "Magic Packet" :
5654 wus & E1000_WUS_LNKC ? "Link Status Change" :
5655 "other");
5656 }
5657 ew32(WUS, ~0);
5658 }
5659
Auke Kokbc7f75f2007-09-17 12:30:59 -07005660 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005661
Bruce Allancd791612010-05-10 14:59:51 +00005662 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005663
5664 if (netif_running(netdev))
5665 e1000e_up(adapter);
5666
5667 netif_device_attach(netdev);
5668
Bruce Allanad680762008-03-28 09:15:03 -07005669 /*
5670 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005671 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005672 * under the control of the driver.
5673 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005674 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005675 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005676
5677 return 0;
5678}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005679
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005680#ifdef CONFIG_PM_SLEEP
5681static int e1000_suspend(struct device *dev)
5682{
5683 struct pci_dev *pdev = to_pci_dev(dev);
5684 int retval;
5685 bool wake;
5686
5687 retval = __e1000_shutdown(pdev, &wake, false);
5688 if (!retval)
5689 e1000_complete_shutdown(pdev, true, wake);
5690
5691 return retval;
5692}
5693
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005694static int e1000_resume(struct device *dev)
5695{
5696 struct pci_dev *pdev = to_pci_dev(dev);
5697 struct net_device *netdev = pci_get_drvdata(pdev);
5698 struct e1000_adapter *adapter = netdev_priv(netdev);
5699
5700 if (e1000e_pm_ready(adapter))
5701 adapter->idle_check = true;
5702
5703 return __e1000_resume(pdev);
5704}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005705#endif /* CONFIG_PM_SLEEP */
5706
5707#ifdef CONFIG_PM_RUNTIME
5708static int e1000_runtime_suspend(struct device *dev)
5709{
5710 struct pci_dev *pdev = to_pci_dev(dev);
5711 struct net_device *netdev = pci_get_drvdata(pdev);
5712 struct e1000_adapter *adapter = netdev_priv(netdev);
5713
5714 if (e1000e_pm_ready(adapter)) {
5715 bool wake;
5716
5717 __e1000_shutdown(pdev, &wake, true);
5718 }
5719
5720 return 0;
5721}
5722
5723static int e1000_idle(struct device *dev)
5724{
5725 struct pci_dev *pdev = to_pci_dev(dev);
5726 struct net_device *netdev = pci_get_drvdata(pdev);
5727 struct e1000_adapter *adapter = netdev_priv(netdev);
5728
5729 if (!e1000e_pm_ready(adapter))
5730 return 0;
5731
5732 if (adapter->idle_check) {
5733 adapter->idle_check = false;
5734 if (!e1000e_has_link(adapter))
5735 pm_schedule_suspend(dev, MSEC_PER_SEC);
5736 }
5737
5738 return -EBUSY;
5739}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005740
5741static int e1000_runtime_resume(struct device *dev)
5742{
5743 struct pci_dev *pdev = to_pci_dev(dev);
5744 struct net_device *netdev = pci_get_drvdata(pdev);
5745 struct e1000_adapter *adapter = netdev_priv(netdev);
5746
5747 if (!e1000e_pm_ready(adapter))
5748 return 0;
5749
5750 adapter->idle_check = !dev->power.runtime_auto;
5751 return __e1000_resume(pdev);
5752}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005753#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005754#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005755
5756static void e1000_shutdown(struct pci_dev *pdev)
5757{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005758 bool wake = false;
5759
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005760 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005761
5762 if (system_state == SYSTEM_POWER_OFF)
5763 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005764}
5765
5766#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005767
5768static irqreturn_t e1000_intr_msix(int irq, void *data)
5769{
5770 struct net_device *netdev = data;
5771 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005772
5773 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005774 int vector, msix_irq;
5775
Dongdong Deng147b2c82010-11-16 19:50:15 -08005776 vector = 0;
5777 msix_irq = adapter->msix_entries[vector].vector;
5778 disable_irq(msix_irq);
5779 e1000_intr_msix_rx(msix_irq, netdev);
5780 enable_irq(msix_irq);
5781
5782 vector++;
5783 msix_irq = adapter->msix_entries[vector].vector;
5784 disable_irq(msix_irq);
5785 e1000_intr_msix_tx(msix_irq, netdev);
5786 enable_irq(msix_irq);
5787
5788 vector++;
5789 msix_irq = adapter->msix_entries[vector].vector;
5790 disable_irq(msix_irq);
5791 e1000_msix_other(msix_irq, netdev);
5792 enable_irq(msix_irq);
5793 }
5794
5795 return IRQ_HANDLED;
5796}
5797
Auke Kokbc7f75f2007-09-17 12:30:59 -07005798/*
5799 * Polling 'interrupt' - used by things like netconsole to send skbs
5800 * without having to re-enable interrupts. It's not called while
5801 * the interrupt routine is executing.
5802 */
5803static void e1000_netpoll(struct net_device *netdev)
5804{
5805 struct e1000_adapter *adapter = netdev_priv(netdev);
5806
Dongdong Deng147b2c82010-11-16 19:50:15 -08005807 switch (adapter->int_mode) {
5808 case E1000E_INT_MODE_MSIX:
5809 e1000_intr_msix(adapter->pdev->irq, netdev);
5810 break;
5811 case E1000E_INT_MODE_MSI:
5812 disable_irq(adapter->pdev->irq);
5813 e1000_intr_msi(adapter->pdev->irq, netdev);
5814 enable_irq(adapter->pdev->irq);
5815 break;
5816 default: /* E1000E_INT_MODE_LEGACY */
5817 disable_irq(adapter->pdev->irq);
5818 e1000_intr(adapter->pdev->irq, netdev);
5819 enable_irq(adapter->pdev->irq);
5820 break;
5821 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005822}
5823#endif
5824
5825/**
5826 * e1000_io_error_detected - called when PCI error is detected
5827 * @pdev: Pointer to PCI device
5828 * @state: The current pci connection state
5829 *
5830 * This function is called after a PCI bus error affecting
5831 * this device has been detected.
5832 */
5833static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5834 pci_channel_state_t state)
5835{
5836 struct net_device *netdev = pci_get_drvdata(pdev);
5837 struct e1000_adapter *adapter = netdev_priv(netdev);
5838
5839 netif_device_detach(netdev);
5840
Mike Masonc93b5a72009-06-30 12:45:53 +00005841 if (state == pci_channel_io_perm_failure)
5842 return PCI_ERS_RESULT_DISCONNECT;
5843
Auke Kokbc7f75f2007-09-17 12:30:59 -07005844 if (netif_running(netdev))
5845 e1000e_down(adapter);
5846 pci_disable_device(pdev);
5847
5848 /* Request a slot slot reset. */
5849 return PCI_ERS_RESULT_NEED_RESET;
5850}
5851
5852/**
5853 * e1000_io_slot_reset - called after the pci bus has been reset.
5854 * @pdev: Pointer to PCI device
5855 *
5856 * Restart the card from scratch, as if from a cold-boot. Implementation
5857 * resembles the first-half of the e1000_resume routine.
5858 */
5859static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5860{
5861 struct net_device *netdev = pci_get_drvdata(pdev);
5862 struct e1000_adapter *adapter = netdev_priv(netdev);
5863 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005864 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005865 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005866 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005867
Bruce Allan78cd29d2011-03-24 03:09:03 +00005868 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5869 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005870 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005871 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5872 if (aspm_disable_flag)
5873 e1000e_disable_aspm(pdev, aspm_disable_flag);
5874
Bruce Allanf0f422e2008-08-04 17:21:53 -07005875 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005876 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005877 dev_err(&pdev->dev,
5878 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005879 result = PCI_ERS_RESULT_DISCONNECT;
5880 } else {
5881 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005882 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005883 pci_restore_state(pdev);
5884
5885 pci_enable_wake(pdev, PCI_D3hot, 0);
5886 pci_enable_wake(pdev, PCI_D3cold, 0);
5887
5888 e1000e_reset(adapter);
5889 ew32(WUS, ~0);
5890 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005891 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005892
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005893 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005894
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005895 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005896}
5897
5898/**
5899 * e1000_io_resume - called when traffic can start flowing again.
5900 * @pdev: Pointer to PCI device
5901 *
5902 * This callback is called when the error recovery driver tells us that
5903 * its OK to resume normal operation. Implementation resembles the
5904 * second-half of the e1000_resume routine.
5905 */
5906static void e1000_io_resume(struct pci_dev *pdev)
5907{
5908 struct net_device *netdev = pci_get_drvdata(pdev);
5909 struct e1000_adapter *adapter = netdev_priv(netdev);
5910
Bruce Allancd791612010-05-10 14:59:51 +00005911 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005912
5913 if (netif_running(netdev)) {
5914 if (e1000e_up(adapter)) {
5915 dev_err(&pdev->dev,
5916 "can't bring device back up after reset\n");
5917 return;
5918 }
5919 }
5920
5921 netif_device_attach(netdev);
5922
Bruce Allanad680762008-03-28 09:15:03 -07005923 /*
5924 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005925 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005926 * under the control of the driver.
5927 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005928 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005929 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005930
5931}
5932
5933static void e1000_print_device_info(struct e1000_adapter *adapter)
5934{
5935 struct e1000_hw *hw = &adapter->hw;
5936 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005937 u32 ret_val;
5938 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005939
5940 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005941 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005942 /* bus width */
5943 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5944 "Width x1"),
5945 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005946 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005947 e_info("Intel(R) PRO/%s Network Connection\n",
5948 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005949 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5950 E1000_PBANUM_LENGTH);
5951 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00005952 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00005953 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5954 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955}
5956
Auke Kok10aa4c02008-08-04 17:21:20 -07005957static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5958{
5959 struct e1000_hw *hw = &adapter->hw;
5960 int ret_val;
5961 u16 buf = 0;
5962
5963 if (hw->mac.type != e1000_82573)
5964 return;
5965
5966 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00005967 le16_to_cpus(&buf);
5968 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005969 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005970 dev_warn(&adapter->pdev->dev,
5971 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005972 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005973}
5974
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005975static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00005976 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00005977{
5978 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005979 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00005980
5981 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5982 adapter->flags |= FLAG_TSO_FORCE;
5983
5984 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Bruce Allan70495a52012-01-11 01:26:50 +00005985 NETIF_F_RXCSUM | NETIF_F_RXHASH)))
Bruce Allandc221292011-08-19 03:23:48 +00005986 return 0;
5987
Bruce Allan70495a52012-01-11 01:26:50 +00005988 /*
5989 * IP payload checksum (enabled with jumbos/packet-split when Rx
5990 * checksum is enabled) and generation of RSS hash is mutually
5991 * exclusive in the hardware.
5992 */
5993 if (adapter->rx_ps_pages &&
5994 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
5995 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");
5996 return -EINVAL;
5997 }
5998
5999 netdev->features = features;
6000
Bruce Allandc221292011-08-19 03:23:48 +00006001 if (netif_running(netdev))
6002 e1000e_reinit_locked(adapter);
6003 else
6004 e1000e_reset(adapter);
6005
6006 return 0;
6007}
6008
Stephen Hemminger651c2462008-11-19 21:57:48 -08006009static const struct net_device_ops e1000e_netdev_ops = {
6010 .ndo_open = e1000_open,
6011 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006012 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006013 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006014 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006015 .ndo_set_mac_address = e1000_set_mac,
6016 .ndo_change_mtu = e1000_change_mtu,
6017 .ndo_do_ioctl = e1000_ioctl,
6018 .ndo_tx_timeout = e1000_tx_timeout,
6019 .ndo_validate_addr = eth_validate_addr,
6020
Stephen Hemminger651c2462008-11-19 21:57:48 -08006021 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6022 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6023#ifdef CONFIG_NET_POLL_CONTROLLER
6024 .ndo_poll_controller = e1000_netpoll,
6025#endif
Bruce Allandc221292011-08-19 03:23:48 +00006026 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006027};
6028
Auke Kokbc7f75f2007-09-17 12:30:59 -07006029/**
6030 * e1000_probe - Device Initialization Routine
6031 * @pdev: PCI device information struct
6032 * @ent: entry in e1000_pci_tbl
6033 *
6034 * Returns 0 on success, negative on failure
6035 *
6036 * e1000_probe initializes an adapter identified by a pci_dev structure.
6037 * The OS initialization, configuring of the adapter private structure,
6038 * and a hardware reset occur.
6039 **/
6040static int __devinit e1000_probe(struct pci_dev *pdev,
6041 const struct pci_device_id *ent)
6042{
6043 struct net_device *netdev;
6044 struct e1000_adapter *adapter;
6045 struct e1000_hw *hw;
6046 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006047 resource_size_t mmio_start, mmio_len;
6048 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006049
6050 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006051 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006052 int i, err, pci_using_dac;
6053 u16 eeprom_data = 0;
6054 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6055
Bruce Allan78cd29d2011-03-24 03:09:03 +00006056 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6057 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006058 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006059 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6060 if (aspm_disable_flag)
6061 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006062
Bruce Allanf0f422e2008-08-04 17:21:53 -07006063 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006064 if (err)
6065 return err;
6066
6067 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006068 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006069 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006070 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006071 if (!err)
6072 pci_using_dac = 1;
6073 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006074 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006075 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006076 err = dma_set_coherent_mask(&pdev->dev,
6077 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006078 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006079 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006080 goto err_dma;
6081 }
6082 }
6083 }
6084
Arjan van de Vene8de1482008-10-22 19:55:31 -07006085 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006086 pci_select_bars(pdev, IORESOURCE_MEM),
6087 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006088 if (err)
6089 goto err_pci_reg;
6090
Xiaotian Feng68eac462009-08-14 14:35:52 +00006091 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006092 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006093
Auke Kokbc7f75f2007-09-17 12:30:59 -07006094 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006095 /* PCI config space info */
6096 err = pci_save_state(pdev);
6097 if (err)
6098 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006099
6100 err = -ENOMEM;
6101 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6102 if (!netdev)
6103 goto err_alloc_etherdev;
6104
Auke Kokbc7f75f2007-09-17 12:30:59 -07006105 SET_NETDEV_DEV(netdev, &pdev->dev);
6106
Tom Herbertf85e4df2010-05-05 14:03:32 +00006107 netdev->irq = pdev->irq;
6108
Auke Kokbc7f75f2007-09-17 12:30:59 -07006109 pci_set_drvdata(pdev, netdev);
6110 adapter = netdev_priv(netdev);
6111 hw = &adapter->hw;
6112 adapter->netdev = netdev;
6113 adapter->pdev = pdev;
6114 adapter->ei = ei;
6115 adapter->pba = ei->pba;
6116 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006117 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006118 adapter->hw.adapter = adapter;
6119 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006120 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006121 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6122
6123 mmio_start = pci_resource_start(pdev, 0);
6124 mmio_len = pci_resource_len(pdev, 0);
6125
6126 err = -EIO;
6127 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6128 if (!adapter->hw.hw_addr)
6129 goto err_ioremap;
6130
6131 if ((adapter->flags & FLAG_HAS_FLASH) &&
6132 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6133 flash_start = pci_resource_start(pdev, 1);
6134 flash_len = pci_resource_len(pdev, 1);
6135 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6136 if (!adapter->hw.flash_address)
6137 goto err_flashmap;
6138 }
6139
6140 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006141 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006142 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006143 netdev->watchdog_timeo = 5 * HZ;
6144 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006145 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006146
6147 netdev->mem_start = mmio_start;
6148 netdev->mem_end = mmio_start + mmio_len;
6149
6150 adapter->bd_number = cards_found++;
6151
Bruce Allan4662e822008-08-26 18:37:06 -07006152 e1000e_check_options(adapter);
6153
Auke Kokbc7f75f2007-09-17 12:30:59 -07006154 /* setup adapter struct */
6155 err = e1000_sw_init(adapter);
6156 if (err)
6157 goto err_sw_init;
6158
Auke Kokbc7f75f2007-09-17 12:30:59 -07006159 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6160 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6161 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6162
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006163 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006164 if (err)
6165 goto err_hw_init;
6166
Bruce Allan4a770352008-10-01 17:18:35 -07006167 if ((adapter->flags & FLAG_IS_ICH) &&
6168 (adapter->flags & FLAG_READ_ONLY_NVM))
6169 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6170
Auke Kokbc7f75f2007-09-17 12:30:59 -07006171 hw->mac.ops.get_bus_info(&adapter->hw);
6172
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006173 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006174
6175 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006176 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006177 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6178 adapter->hw.phy.disable_polarity_correction = 0;
6179 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6180 }
6181
6182 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006183 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006184
Bruce Allandc221292011-08-19 03:23:48 +00006185 /* Set initial default active device features */
6186 netdev->features = (NETIF_F_SG |
6187 NETIF_F_HW_VLAN_RX |
6188 NETIF_F_HW_VLAN_TX |
6189 NETIF_F_TSO |
6190 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006191 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006192 NETIF_F_RXCSUM |
6193 NETIF_F_HW_CSUM);
6194
6195 /* Set user-changeable features (subset of all device features) */
6196 netdev->hw_features = netdev->features;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006197
6198 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6199 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6200
Bruce Allandc221292011-08-19 03:23:48 +00006201 netdev->vlan_features |= (NETIF_F_SG |
6202 NETIF_F_TSO |
6203 NETIF_F_TSO6 |
6204 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006205
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006206 netdev->priv_flags |= IFF_UNICAST_FLT;
6207
Yi Zou7b872a52010-09-22 17:57:58 +00006208 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006209 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006210 netdev->vlan_features |= NETIF_F_HIGHDMA;
6211 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006212
Auke Kokbc7f75f2007-09-17 12:30:59 -07006213 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6214 adapter->flags |= FLAG_MNG_PT_ENABLED;
6215
Bruce Allanad680762008-03-28 09:15:03 -07006216 /*
6217 * before reading the NVM, reset the controller to
6218 * put the device in a known good starting state
6219 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006220 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6221
6222 /*
6223 * systems with ASPM and others may see the checksum fail on the first
6224 * attempt. Let's give it a few tries
6225 */
6226 for (i = 0;; i++) {
6227 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6228 break;
6229 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006230 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006231 err = -EIO;
6232 goto err_eeprom;
6233 }
6234 }
6235
Auke Kok10aa4c02008-08-04 17:21:20 -07006236 e1000_eeprom_checks(adapter);
6237
Bruce Allan608f8a02010-01-13 02:04:58 +00006238 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006239 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006240 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006241
6242 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6243 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6244
6245 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006246 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006247 err = -EIO;
6248 goto err_eeprom;
6249 }
6250
6251 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006252 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006253 adapter->watchdog_timer.data = (unsigned long) adapter;
6254
6255 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006256 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006257 adapter->phy_info_timer.data = (unsigned long) adapter;
6258
6259 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6260 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006261 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6262 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006263 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006264
Auke Kokbc7f75f2007-09-17 12:30:59 -07006265 /* Initialize link parameters. User can change them with ethtool */
6266 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006267 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006268 adapter->hw.fc.requested_mode = e1000_fc_default;
6269 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006270 adapter->hw.phy.autoneg_advertised = 0x2f;
6271
6272 /* ring size defaults */
6273 adapter->rx_ring->count = 256;
6274 adapter->tx_ring->count = 256;
6275
6276 /*
6277 * Initial Wake on LAN setting - If APM wake is enabled in
6278 * the EEPROM, enable the ACPI Magic Packet filter
6279 */
6280 if (adapter->flags & FLAG_APME_IN_WUC) {
6281 /* APME bit in EEPROM is mapped to WUC.APME */
6282 eeprom_data = er32(WUC);
6283 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006284 if ((hw->mac.type > e1000_ich10lan) &&
6285 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006286 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006287 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6288 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6289 (adapter->hw.bus.func == 1))
6290 e1000_read_nvm(&adapter->hw,
6291 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6292 else
6293 e1000_read_nvm(&adapter->hw,
6294 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6295 }
6296
6297 /* fetch WoL from EEPROM */
6298 if (eeprom_data & eeprom_apme_mask)
6299 adapter->eeprom_wol |= E1000_WUFC_MAG;
6300
6301 /*
6302 * now that we have the eeprom settings, apply the special cases
6303 * where the eeprom may be wrong or the board simply won't support
6304 * wake on lan on a particular port
6305 */
6306 if (!(adapter->flags & FLAG_HAS_WOL))
6307 adapter->eeprom_wol = 0;
6308
6309 /* initialize the wol settings based on the eeprom settings */
6310 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006311 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006312
Bruce Allan84527592008-11-21 17:00:22 -08006313 /* save off EEPROM version number */
6314 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6315
Auke Kokbc7f75f2007-09-17 12:30:59 -07006316 /* reset the hardware with the new settings */
6317 e1000e_reset(adapter);
6318
Bruce Allanad680762008-03-28 09:15:03 -07006319 /*
6320 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006321 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006322 * under the control of the driver.
6323 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006324 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006325 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006326
Bruce Allanf2315bf2011-12-16 00:46:59 +00006327 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006328 err = register_netdev(netdev);
6329 if (err)
6330 goto err_register;
6331
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006332 /* carrier off reporting is important to ethtool even BEFORE open */
6333 netif_carrier_off(netdev);
6334
Auke Kokbc7f75f2007-09-17 12:30:59 -07006335 e1000_print_device_info(adapter);
6336
Alan Sternf3ec4f82010-06-08 15:23:51 -04006337 if (pci_dev_run_wake(pdev))
6338 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006339
Auke Kokbc7f75f2007-09-17 12:30:59 -07006340 return 0;
6341
6342err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006343 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006344 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006345err_eeprom:
6346 if (!e1000_check_reset_block(&adapter->hw))
6347 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006348err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006349 kfree(adapter->tx_ring);
6350 kfree(adapter->rx_ring);
6351err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006352 if (adapter->hw.flash_address)
6353 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006354 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006355err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006356 iounmap(adapter->hw.hw_addr);
6357err_ioremap:
6358 free_netdev(netdev);
6359err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006360 pci_release_selected_regions(pdev,
6361 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006362err_pci_reg:
6363err_dma:
6364 pci_disable_device(pdev);
6365 return err;
6366}
6367
6368/**
6369 * e1000_remove - Device Removal Routine
6370 * @pdev: PCI device information struct
6371 *
6372 * e1000_remove is called by the PCI subsystem to alert the driver
6373 * that it should release a PCI device. The could be caused by a
6374 * Hot-Plug event, or because the driver is going to be removed from
6375 * memory.
6376 **/
6377static void __devexit e1000_remove(struct pci_dev *pdev)
6378{
6379 struct net_device *netdev = pci_get_drvdata(pdev);
6380 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006381 bool down = test_bit(__E1000_DOWN, &adapter->state);
6382
Bruce Allanad680762008-03-28 09:15:03 -07006383 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006384 * The timers may be rescheduled, so explicitly disable them
6385 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006386 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006387 if (!down)
6388 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006389 del_timer_sync(&adapter->watchdog_timer);
6390 del_timer_sync(&adapter->phy_info_timer);
6391
Bruce Allan41cec6f2009-11-20 23:28:56 +00006392 cancel_work_sync(&adapter->reset_task);
6393 cancel_work_sync(&adapter->watchdog_task);
6394 cancel_work_sync(&adapter->downshift_task);
6395 cancel_work_sync(&adapter->update_phy_task);
6396 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006397
Bruce Allan17f208d2009-12-01 15:47:22 +00006398 if (!(netdev->flags & IFF_UP))
6399 e1000_power_down_phy(adapter);
6400
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006401 /* Don't lie to e1000_close() down the road. */
6402 if (!down)
6403 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006404 unregister_netdev(netdev);
6405
Alan Sternf3ec4f82010-06-08 15:23:51 -04006406 if (pci_dev_run_wake(pdev))
6407 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006408
Bruce Allanad680762008-03-28 09:15:03 -07006409 /*
6410 * Release control of h/w to f/w. If f/w is AMT enabled, this
6411 * would have already happened in close and is redundant.
6412 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006413 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006414
Bruce Allan4662e822008-08-26 18:37:06 -07006415 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006416 kfree(adapter->tx_ring);
6417 kfree(adapter->rx_ring);
6418
6419 iounmap(adapter->hw.hw_addr);
6420 if (adapter->hw.flash_address)
6421 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006422 pci_release_selected_regions(pdev,
6423 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006424
6425 free_netdev(netdev);
6426
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006427 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006428 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006429
Auke Kokbc7f75f2007-09-17 12:30:59 -07006430 pci_disable_device(pdev);
6431}
6432
6433/* PCI Error Recovery (ERS) */
6434static struct pci_error_handlers e1000_err_handler = {
6435 .error_detected = e1000_io_error_detected,
6436 .slot_reset = e1000_io_slot_reset,
6437 .resume = e1000_io_resume,
6438};
6439
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006440static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006441 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6442 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6443 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6444 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6445 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6446 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006447 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6448 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6449 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006450
Auke Kokbc7f75f2007-09-17 12:30:59 -07006451 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6452 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6453 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6454 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006455
Auke Kokbc7f75f2007-09-17 12:30:59 -07006456 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6457 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6458 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006459
Bruce Allan4662e822008-08-26 18:37:06 -07006460 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006461 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006462 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006463
Auke Kokbc7f75f2007-09-17 12:30:59 -07006464 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6465 board_80003es2lan },
6466 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6467 board_80003es2lan },
6468 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6469 board_80003es2lan },
6470 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6471 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006472
Auke Kokbc7f75f2007-09-17 12:30:59 -07006473 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6474 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6475 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6476 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6477 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6478 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6479 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006480 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006481
Auke Kokbc7f75f2007-09-17 12:30:59 -07006482 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6483 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6484 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6485 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6486 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006487 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006488 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6489 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6490 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6491
6492 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6493 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6494 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006495
Bruce Allanf4187b52008-08-26 18:36:50 -07006496 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6497 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006498 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006499
Bruce Allana4f58f52009-06-02 11:29:18 +00006500 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6501 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6502 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6503 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6504
Bruce Alland3738bb2010-06-16 13:27:28 +00006505 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6506 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6507
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006508 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006509};
6510MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6511
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006512#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006513static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006514 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6515 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6516 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006517};
David S. Millere50208a2010-03-16 23:36:24 -07006518#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006519
Auke Kokbc7f75f2007-09-17 12:30:59 -07006520/* PCI Device API Driver */
6521static struct pci_driver e1000_driver = {
6522 .name = e1000e_driver_name,
6523 .id_table = e1000_pci_tbl,
6524 .probe = e1000_probe,
6525 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006526#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006527 .driver = {
6528 .pm = &e1000_pm_ops,
6529 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006530#endif
6531 .shutdown = e1000_shutdown,
6532 .err_handler = &e1000_err_handler
6533};
6534
6535/**
6536 * e1000_init_module - Driver Registration Routine
6537 *
6538 * e1000_init_module is the first routine called when the driver is
6539 * loaded. All it does is register with the PCI subsystem.
6540 **/
6541static int __init e1000_init_module(void)
6542{
6543 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006544 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6545 e1000e_driver_version);
Bruce Allanf5e261e2012-01-01 16:00:03 +00006546 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006547 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006548
Auke Kokbc7f75f2007-09-17 12:30:59 -07006549 return ret;
6550}
6551module_init(e1000_init_module);
6552
6553/**
6554 * e1000_exit_module - Driver Exit Cleanup Routine
6555 *
6556 * e1000_exit_module is called just before the driver is removed
6557 * from memory.
6558 **/
6559static void __exit e1000_exit_module(void)
6560{
6561 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006562}
6563module_exit(e1000_exit_module);
6564
6565
6566MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6567MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6568MODULE_LICENSE("GPL");
6569MODULE_VERSION(DRV_VERSION);
6570
6571/* e1000_main.c */