blob: 462bdeec90e487585adb646a674d91e247baf3f7 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allan8544b9f2010-03-24 12:55:30 +000029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/vmalloc.h>
36#include <linux/pagemap.h>
37#include <linux/delay.h>
38#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000039#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070040#include <linux/tcp.h>
41#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070043#include <net/checksum.h>
44#include <net/ip6_checksum.h>
45#include <linux/mii.h>
46#include <linux/ethtool.h>
47#include <linux/if_vlan.h>
48#include <linux/cpu.h>
49#include <linux/smp.h>
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 Allanc5778b42011-07-29 05:53:12 +000059#define DRV_VERSION "1.5.1" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070060char e1000e_driver_name[] = "e1000e";
61const char e1000e_driver_version[] = DRV_VERSION;
62
Bruce Allan78cd29d2011-03-24 03:09:03 +000063static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
64
Auke Kokbc7f75f2007-09-17 12:30:59 -070065static const struct e1000_info *e1000_info_tbl[] = {
66 [board_82571] = &e1000_82571_info,
67 [board_82572] = &e1000_82572_info,
68 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070069 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000070 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070071 [board_80003es2lan] = &e1000_es2_info,
72 [board_ich8lan] = &e1000_ich8_info,
73 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070074 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000075 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000076 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070077};
78
Taku Izumi84f4ee92010-04-27 14:39:08 +000079struct e1000_reg_info {
80 u32 ofs;
81 char *name;
82};
83
Bruce Allanaf667a22010-12-31 06:10:01 +000084#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
85#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
86#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
87#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
88#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000089
Bruce Allanaf667a22010-12-31 06:10:01 +000090#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
91#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
92#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
93#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
94#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000095
96static const struct e1000_reg_info e1000_reg_info_tbl[] = {
97
98 /* General Registers */
99 {E1000_CTRL, "CTRL"},
100 {E1000_STATUS, "STATUS"},
101 {E1000_CTRL_EXT, "CTRL_EXT"},
102
103 /* Interrupt Registers */
104 {E1000_ICR, "ICR"},
105
Bruce Allanaf667a22010-12-31 06:10:01 +0000106 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000107 {E1000_RCTL, "RCTL"},
108 {E1000_RDLEN, "RDLEN"},
109 {E1000_RDH, "RDH"},
110 {E1000_RDT, "RDT"},
111 {E1000_RDTR, "RDTR"},
112 {E1000_RXDCTL(0), "RXDCTL"},
113 {E1000_ERT, "ERT"},
114 {E1000_RDBAL, "RDBAL"},
115 {E1000_RDBAH, "RDBAH"},
116 {E1000_RDFH, "RDFH"},
117 {E1000_RDFT, "RDFT"},
118 {E1000_RDFHS, "RDFHS"},
119 {E1000_RDFTS, "RDFTS"},
120 {E1000_RDFPC, "RDFPC"},
121
Bruce Allanaf667a22010-12-31 06:10:01 +0000122 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000123 {E1000_TCTL, "TCTL"},
124 {E1000_TDBAL, "TDBAL"},
125 {E1000_TDBAH, "TDBAH"},
126 {E1000_TDLEN, "TDLEN"},
127 {E1000_TDH, "TDH"},
128 {E1000_TDT, "TDT"},
129 {E1000_TIDV, "TIDV"},
130 {E1000_TXDCTL(0), "TXDCTL"},
131 {E1000_TADV, "TADV"},
132 {E1000_TARC(0), "TARC"},
133 {E1000_TDFH, "TDFH"},
134 {E1000_TDFT, "TDFT"},
135 {E1000_TDFHS, "TDFHS"},
136 {E1000_TDFTS, "TDFTS"},
137 {E1000_TDFPC, "TDFPC"},
138
139 /* List Terminator */
140 {}
141};
142
143/*
144 * e1000_regdump - register printout routine
145 */
146static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
147{
148 int n = 0;
149 char rname[16];
150 u32 regs[8];
151
152 switch (reginfo->ofs) {
153 case E1000_RXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_RXDCTL(n));
156 break;
157 case E1000_TXDCTL(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TXDCTL(n));
160 break;
161 case E1000_TARC(0):
162 for (n = 0; n < 2; n++)
163 regs[n] = __er32(hw, E1000_TARC(n));
164 break;
165 default:
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 {
186 u64 a;
187 u64 b;
188 } *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 {
194 u64 a;
195 u64 b;
196 u64 c;
197 u64 d;
198 } *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))
224 goto exit;
225
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))
311 goto exit;
312
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 }
452
453exit:
454 return;
455}
456
Auke Kokbc7f75f2007-09-17 12:30:59 -0700457/**
458 * e1000_desc_unused - calculate if we have unused descriptors
459 **/
460static int e1000_desc_unused(struct e1000_ring *ring)
461{
462 if (ring->next_to_clean > ring->next_to_use)
463 return ring->next_to_clean - ring->next_to_use - 1;
464
465 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
466}
467
468/**
Bruce Allanad680762008-03-28 09:15:03 -0700469 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700470 * @adapter: board private structure
471 * @status: descriptor status field as written by hardware
472 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
473 * @skb: pointer to sk_buff to be indicated to stack
474 **/
475static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000476 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000477 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700478{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000479 u16 tag = le16_to_cpu(vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700480 skb->protocol = eth_type_trans(skb, netdev);
481
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000482 if (status & E1000_RXD_STAT_VP)
483 __vlan_hwaccel_put_tag(skb, tag);
484
485 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700486}
487
488/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000489 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000490 * @adapter: board private structure
491 * @status_err: receive descriptor status and error fields
492 * @csum: receive descriptor csum field
493 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700494 **/
495static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allanafd12932012-01-05 00:34:05 +0000496 __le16 csum, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700497{
498 u16 status = (u16)status_err;
499 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700500
501 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700502
Bruce Allanafd12932012-01-05 00:34:05 +0000503 /* Rx checksum disabled */
504 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
505 return;
506
Auke Kokbc7f75f2007-09-17 12:30:59 -0700507 /* Ignore Checksum bit is set */
508 if (status & E1000_RXD_STAT_IXSM)
509 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000510
Auke Kokbc7f75f2007-09-17 12:30:59 -0700511 /* TCP/UDP checksum error bit is set */
512 if (errors & E1000_RXD_ERR_TCPE) {
513 /* let the stack verify checksum errors */
514 adapter->hw_csum_err++;
515 return;
516 }
517
518 /* TCP/UDP Checksum has not been calculated */
519 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
520 return;
521
522 /* It must be a TCP or UDP packet with a valid checksum */
523 if (status & E1000_RXD_STAT_TCPCS) {
524 /* TCP checksum is good */
525 skb->ip_summed = CHECKSUM_UNNECESSARY;
526 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700527 /*
528 * IP fragment with UDP payload
529 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700530 * and then put the value in host order for further stack use.
531 */
Bruce Allanafd12932012-01-05 00:34:05 +0000532 __sum16 sum = (__force __sum16)swab16((__force u16)csum);
Al Viroa39fe742007-12-11 19:50:34 +0000533 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700534 skb->ip_summed = CHECKSUM_COMPLETE;
535 }
536 adapter->hw_csum_good++;
537}
538
539/**
David S. Miller823dcd22011-08-20 10:39:12 -0700540 * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa()
541 * @hw: pointer to the HW structure
542 * @tail: address of tail descriptor register
543 * @i: value to write to tail descriptor register
544 *
545 * When updating the tail register, the ME could be accessing Host CSR
546 * registers at the same time. Normally, this is handled in h/w by an
547 * arbiter but on some parts there is a bug that acknowledges Host accesses
548 * later than it should which could result in the descriptor register to
549 * have an incorrect value. Workaround this by checking the FWSM register
550 * which has bit 24 set while ME is accessing Host CSR registers, wait
551 * if it is set and try again a number of times.
552 **/
Bruce Allanc5083cf2011-12-16 00:45:40 +0000553static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, void __iomem *tail,
David S. Miller823dcd22011-08-20 10:39:12 -0700554 unsigned int i)
555{
556 unsigned int j = 0;
557
558 while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) &&
559 (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI))
560 udelay(50);
561
562 writel(i, tail);
563
564 if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail)))
565 return E1000_ERR_SWFW_SYNC;
566
567 return 0;
568}
569
570static void e1000e_update_rdt_wa(struct e1000_adapter *adapter, unsigned int i)
571{
David S. Miller823dcd22011-08-20 10:39:12 -0700572 struct e1000_hw *hw = &adapter->hw;
573
Bruce Allanc5083cf2011-12-16 00:45:40 +0000574 if (e1000e_update_tail_wa(hw, adapter->rx_ring->tail, i)) {
David S. Miller823dcd22011-08-20 10:39:12 -0700575 u32 rctl = er32(RCTL);
576 ew32(RCTL, rctl & ~E1000_RCTL_EN);
577 e_err("ME firmware caused invalid RDT - resetting\n");
578 schedule_work(&adapter->reset_task);
579 }
580}
581
582static void e1000e_update_tdt_wa(struct e1000_adapter *adapter, unsigned int i)
583{
David S. Miller823dcd22011-08-20 10:39:12 -0700584 struct e1000_hw *hw = &adapter->hw;
585
Bruce Allanc5083cf2011-12-16 00:45:40 +0000586 if (e1000e_update_tail_wa(hw, adapter->tx_ring->tail, i)) {
David S. Miller823dcd22011-08-20 10:39:12 -0700587 u32 tctl = er32(TCTL);
588 ew32(TCTL, tctl & ~E1000_TCTL_EN);
589 e_err("ME firmware caused invalid TDT - resetting\n");
590 schedule_work(&adapter->reset_task);
591 }
592}
593
594/**
Bruce Allan5f450212011-07-22 06:21:46 +0000595 * e1000_alloc_rx_buffers - Replace used receive buffers
Auke Kokbc7f75f2007-09-17 12:30:59 -0700596 * @adapter: address of board private structure
597 **/
598static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000599 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700600{
601 struct net_device *netdev = adapter->netdev;
602 struct pci_dev *pdev = adapter->pdev;
603 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +0000604 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700605 struct e1000_buffer *buffer_info;
606 struct sk_buff *skb;
607 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000608 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700609
610 i = rx_ring->next_to_use;
611 buffer_info = &rx_ring->buffer_info[i];
612
613 while (cleaned_count--) {
614 skb = buffer_info->skb;
615 if (skb) {
616 skb_trim(skb, 0);
617 goto map_skb;
618 }
619
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000620 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700621 if (!skb) {
622 /* Better luck next round */
623 adapter->alloc_rx_buff_failed++;
624 break;
625 }
626
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627 buffer_info->skb = skb;
628map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000629 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000631 DMA_FROM_DEVICE);
632 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000633 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700634 adapter->rx_dma_failed++;
635 break;
636 }
637
Bruce Allan5f450212011-07-22 06:21:46 +0000638 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
639 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640
Tom Herbert50849d72010-05-05 14:02:49 +0000641 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
642 /*
643 * Force memory writes to complete before letting h/w
644 * know there are new descriptors to fetch. (Only
645 * applicable for weak-ordered memory model archs,
646 * such as IA-64).
647 */
648 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700649 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
650 e1000e_update_rdt_wa(adapter, i);
651 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000652 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000653 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700654 i++;
655 if (i == rx_ring->count)
656 i = 0;
657 buffer_info = &rx_ring->buffer_info[i];
658 }
659
Tom Herbert50849d72010-05-05 14:02:49 +0000660 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700661}
662
663/**
664 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
665 * @adapter: address of board private structure
666 **/
667static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000668 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700669{
670 struct net_device *netdev = adapter->netdev;
671 struct pci_dev *pdev = adapter->pdev;
672 union e1000_rx_desc_packet_split *rx_desc;
673 struct e1000_ring *rx_ring = adapter->rx_ring;
674 struct e1000_buffer *buffer_info;
675 struct e1000_ps_page *ps_page;
676 struct sk_buff *skb;
677 unsigned int i, j;
678
679 i = rx_ring->next_to_use;
680 buffer_info = &rx_ring->buffer_info[i];
681
682 while (cleaned_count--) {
683 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
684
685 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700686 ps_page = &buffer_info->ps_pages[j];
687 if (j >= adapter->rx_ps_pages) {
688 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000689 rx_desc->read.buffer_addr[j + 1] =
690 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700691 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700692 }
Auke Kok47f44e42007-10-25 13:57:44 -0700693 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000694 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700695 if (!ps_page->page) {
696 adapter->alloc_rx_buff_failed++;
697 goto no_buffers;
698 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000699 ps_page->dma = dma_map_page(&pdev->dev,
700 ps_page->page,
701 0, PAGE_SIZE,
702 DMA_FROM_DEVICE);
703 if (dma_mapping_error(&pdev->dev,
704 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700705 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000706 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700707 adapter->rx_dma_failed++;
708 goto no_buffers;
709 }
710 }
711 /*
712 * Refresh the desc even if buffer_addrs
713 * didn't change because each write-back
714 * erases this info.
715 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000716 rx_desc->read.buffer_addr[j + 1] =
717 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700718 }
719
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000720 skb = __netdev_alloc_skb_ip_align(netdev,
721 adapter->rx_ps_bsize0,
722 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700723
724 if (!skb) {
725 adapter->alloc_rx_buff_failed++;
726 break;
727 }
728
Auke Kokbc7f75f2007-09-17 12:30:59 -0700729 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000730 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700731 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000732 DMA_FROM_DEVICE);
733 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000734 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700735 adapter->rx_dma_failed++;
736 /* cleanup skb */
737 dev_kfree_skb_any(skb);
738 buffer_info->skb = NULL;
739 break;
740 }
741
742 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
743
Tom Herbert50849d72010-05-05 14:02:49 +0000744 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
745 /*
746 * Force memory writes to complete before letting h/w
747 * know there are new descriptors to fetch. (Only
748 * applicable for weak-ordered memory model archs,
749 * such as IA-64).
750 */
751 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700752 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
753 e1000e_update_rdt_wa(adapter, i << 1);
754 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000755 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000756 }
757
Auke Kokbc7f75f2007-09-17 12:30:59 -0700758 i++;
759 if (i == rx_ring->count)
760 i = 0;
761 buffer_info = &rx_ring->buffer_info[i];
762 }
763
764no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000765 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700766}
767
768/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700769 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
770 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700771 * @cleaned_count: number of buffers to allocate this pass
772 **/
773
774static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000775 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700776{
777 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_ring *rx_ring = adapter->rx_ring;
781 struct e1000_buffer *buffer_info;
782 struct sk_buff *skb;
783 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000784 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700785
786 i = rx_ring->next_to_use;
787 buffer_info = &rx_ring->buffer_info[i];
788
789 while (cleaned_count--) {
790 skb = buffer_info->skb;
791 if (skb) {
792 skb_trim(skb, 0);
793 goto check_page;
794 }
795
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000796 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700797 if (unlikely(!skb)) {
798 /* Better luck next round */
799 adapter->alloc_rx_buff_failed++;
800 break;
801 }
802
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700803 buffer_info->skb = skb;
804check_page:
805 /* allocate a new page if necessary */
806 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000807 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700808 if (unlikely(!buffer_info->page)) {
809 adapter->alloc_rx_buff_failed++;
810 break;
811 }
812 }
813
814 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000815 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700816 buffer_info->page, 0,
817 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000818 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700819
Bruce Allan5f450212011-07-22 06:21:46 +0000820 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
821 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700822
823 if (unlikely(++i == rx_ring->count))
824 i = 0;
825 buffer_info = &rx_ring->buffer_info[i];
826 }
827
828 if (likely(rx_ring->next_to_use != i)) {
829 rx_ring->next_to_use = i;
830 if (unlikely(i-- == 0))
831 i = (rx_ring->count - 1);
832
833 /* Force memory writes to complete before letting h/w
834 * know there are new descriptors to fetch. (Only
835 * applicable for weak-ordered memory model archs,
836 * such as IA-64). */
837 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700838 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
839 e1000e_update_rdt_wa(adapter, i);
840 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000841 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700842 }
843}
844
Bruce Allan70495a52012-01-11 01:26:50 +0000845static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
846 struct sk_buff *skb)
847{
848 if (netdev->features & NETIF_F_RXHASH)
849 skb->rxhash = le32_to_cpu(rss);
850}
851
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700852/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700853 * e1000_clean_rx_irq - Send received data up the network stack; legacy
854 * @adapter: board private structure
855 *
856 * the return value indicates whether actual cleaning was done, there
857 * is no guarantee that everything was cleaned
858 **/
859static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
860 int *work_done, int work_to_do)
861{
862 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;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700865 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +0000866 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700867 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000868 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700869 unsigned int i;
870 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000871 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700872 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
873
874 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000875 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
876 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700877 buffer_info = &rx_ring->buffer_info[i];
878
Bruce Allan5f450212011-07-22 06:21:46 +0000879 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700880 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700881
882 if (*work_done >= work_to_do)
883 break;
884 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000885 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700886
Auke Kokbc7f75f2007-09-17 12:30:59 -0700887 skb = buffer_info->skb;
888 buffer_info->skb = NULL;
889
890 prefetch(skb->data - NET_IP_ALIGN);
891
892 i++;
893 if (i == rx_ring->count)
894 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000895 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700896 prefetch(next_rxd);
897
898 next_buffer = &rx_ring->buffer_info[i];
899
Rusty Russell3db1cd52011-12-19 13:56:45 +0000900 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000902 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700903 buffer_info->dma,
904 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000905 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700906 buffer_info->dma = 0;
907
Bruce Allan5f450212011-07-22 06:21:46 +0000908 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700909
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000910 /*
911 * !EOP means multiple descriptors were used to store a single
912 * packet, if that's the case we need to toss it. In fact, we
913 * need to toss every packet with the EOP bit clear and the
914 * next frame that _does_ have the EOP bit set, as it is by
915 * definition only a frame fragment
916 */
Bruce Allan5f450212011-07-22 06:21:46 +0000917 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000918 adapter->flags2 |= FLAG2_IS_DISCARDING;
919
920 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700921 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000922 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700923 /* recycle */
924 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000925 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000926 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700927 goto next_desc;
928 }
929
Bruce Allan5f450212011-07-22 06:21:46 +0000930 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700931 /* recycle */
932 buffer_info->skb = skb;
933 goto next_desc;
934 }
935
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000936 /* adjust length to remove Ethernet CRC */
937 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
938 length -= 4;
939
Auke Kokbc7f75f2007-09-17 12:30:59 -0700940 total_rx_bytes += length;
941 total_rx_packets++;
942
Bruce Allanad680762008-03-28 09:15:03 -0700943 /*
944 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700945 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700946 * of reassembly being done in the stack
947 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700948 if (length < copybreak) {
949 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000950 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700951 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700952 skb_copy_to_linear_data_offset(new_skb,
953 -NET_IP_ALIGN,
954 (skb->data -
955 NET_IP_ALIGN),
956 (length +
957 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700958 /* save the skb in buffer_info as good */
959 buffer_info->skb = skb;
960 skb = new_skb;
961 }
962 /* else just continue with the old one */
963 }
964 /* end copybreak code */
965 skb_put(skb, length);
966
967 /* Receive Checksum Offload */
Bruce Allan5f450212011-07-22 06:21:46 +0000968 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +0000969 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700970
Bruce Allan70495a52012-01-11 01:26:50 +0000971 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
972
Bruce Allan5f450212011-07-22 06:21:46 +0000973 e1000_receive_skb(adapter, netdev, skb, staterr,
974 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700975
976next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +0000977 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978
979 /* return some buffers to hardware, one at a time is too slow */
980 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000981 adapter->alloc_rx_buf(adapter, cleaned_count,
982 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700983 cleaned_count = 0;
984 }
985
986 /* use prefetched values */
987 rx_desc = next_rxd;
988 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000989
990 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 }
992 rx_ring->next_to_clean = i;
993
994 cleaned_count = e1000_desc_unused(rx_ring);
995 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000996 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700997
Auke Kokbc7f75f2007-09-17 12:30:59 -0700998 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700999 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001000 return cleaned;
1001}
1002
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003static void e1000_put_txbuf(struct e1000_adapter *adapter,
1004 struct e1000_buffer *buffer_info)
1005{
Alexander Duyck03b13202009-12-02 16:45:31 +00001006 if (buffer_info->dma) {
1007 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001008 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1009 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001010 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001011 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1012 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001013 buffer_info->dma = 0;
1014 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001015 if (buffer_info->skb) {
1016 dev_kfree_skb_any(buffer_info->skb);
1017 buffer_info->skb = NULL;
1018 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001019 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001020}
1021
Bruce Allan41cec6f2009-11-20 23:28:56 +00001022static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001024 struct e1000_adapter *adapter = container_of(work,
1025 struct e1000_adapter,
1026 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001027 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001028 struct e1000_ring *tx_ring = adapter->tx_ring;
1029 unsigned int i = tx_ring->next_to_clean;
1030 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1031 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001032 struct e1000_hw *hw = &adapter->hw;
1033 u16 phy_status, phy_1000t_status, phy_ext_status;
1034 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001036 if (test_bit(__E1000_DOWN, &adapter->state))
1037 return;
1038
Jeff Kirsher09357b02011-11-18 14:25:00 +00001039 if (!adapter->tx_hang_recheck &&
1040 (adapter->flags2 & FLAG2_DMA_BURST)) {
1041 /* May be block on write-back, flush and detect again
1042 * flush pending descriptor writebacks to memory
1043 */
1044 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1045 /* execute the writes immediately */
1046 e1e_flush();
1047 adapter->tx_hang_recheck = true;
1048 return;
1049 }
1050 /* Real hang detected */
1051 adapter->tx_hang_recheck = false;
1052 netif_stop_queue(netdev);
1053
Bruce Allan41cec6f2009-11-20 23:28:56 +00001054 e1e_rphy(hw, PHY_STATUS, &phy_status);
1055 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1056 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1057
1058 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1059
1060 /* detected Hardware unit hang */
1061 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001062 " TDH <%x>\n"
1063 " TDT <%x>\n"
1064 " next_to_use <%x>\n"
1065 " next_to_clean <%x>\n"
1066 "buffer_info[next_to_clean]:\n"
1067 " time_stamp <%lx>\n"
1068 " next_to_watch <%x>\n"
1069 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001070 " next_to_watch.status <%x>\n"
1071 "MAC Status <%x>\n"
1072 "PHY Status <%x>\n"
1073 "PHY 1000BASE-T Status <%x>\n"
1074 "PHY Extended Status <%x>\n"
1075 "PCI Status <%x>\n",
Bruce Allanc5083cf2011-12-16 00:45:40 +00001076 readl(tx_ring->head),
1077 readl(tx_ring->tail),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001078 tx_ring->next_to_use,
1079 tx_ring->next_to_clean,
1080 tx_ring->buffer_info[eop].time_stamp,
1081 eop,
1082 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001083 eop_desc->upper.fields.status,
1084 er32(STATUS),
1085 phy_status,
1086 phy_1000t_status,
1087 phy_ext_status,
1088 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001089}
1090
1091/**
1092 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1093 * @adapter: board private structure
1094 *
1095 * the return value indicates whether actual cleaning was done, there
1096 * is no guarantee that everything was cleaned
1097 **/
1098static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
1099{
1100 struct net_device *netdev = adapter->netdev;
1101 struct e1000_hw *hw = &adapter->hw;
1102 struct e1000_ring *tx_ring = adapter->tx_ring;
1103 struct e1000_tx_desc *tx_desc, *eop_desc;
1104 struct e1000_buffer *buffer_info;
1105 unsigned int i, eop;
1106 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001107 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001108 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001109
1110 i = tx_ring->next_to_clean;
1111 eop = tx_ring->buffer_info[i].next_to_watch;
1112 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1113
Alexander Duyck12d04a32009-03-25 22:05:03 +00001114 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1115 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001116 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001117 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001118 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001119 tx_desc = E1000_TX_DESC(*tx_ring, i);
1120 buffer_info = &tx_ring->buffer_info[i];
1121 cleaned = (i == eop);
1122
1123 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001124 total_tx_packets += buffer_info->segs;
1125 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001126 if (buffer_info->skb) {
1127 bytes_compl += buffer_info->skb->len;
1128 pkts_compl++;
1129 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001130 }
1131
1132 e1000_put_txbuf(adapter, buffer_info);
1133 tx_desc->upper.data = 0;
1134
1135 i++;
1136 if (i == tx_ring->count)
1137 i = 0;
1138 }
1139
Terry Loftindac87612010-04-09 10:29:49 +00001140 if (i == tx_ring->next_to_use)
1141 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001142 eop = tx_ring->buffer_info[i].next_to_watch;
1143 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144 }
1145
1146 tx_ring->next_to_clean = i;
1147
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001148 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1149
Auke Kokbc7f75f2007-09-17 12:30:59 -07001150#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001151 if (count && netif_carrier_ok(netdev) &&
1152 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001153 /* Make sure that anybody stopping the queue after this
1154 * sees the new next_to_clean.
1155 */
1156 smp_mb();
1157
1158 if (netif_queue_stopped(netdev) &&
1159 !(test_bit(__E1000_DOWN, &adapter->state))) {
1160 netif_wake_queue(netdev);
1161 ++adapter->restart_queue;
1162 }
1163 }
1164
1165 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001166 /*
1167 * Detect a transmit hang in hardware, this serializes the
1168 * check with the clearing of time_stamp and movement of i
1169 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001170 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001171 if (tx_ring->buffer_info[i].time_stamp &&
1172 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001173 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001174 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001175 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001176 else
1177 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001178 }
1179 adapter->total_tx_bytes += total_tx_bytes;
1180 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001181 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001182}
1183
1184/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1186 * @adapter: board private structure
1187 *
1188 * the return value indicates whether actual cleaning was done, there
1189 * is no guarantee that everything was cleaned
1190 **/
1191static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1192 int *work_done, int work_to_do)
1193{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001194 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001195 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1196 struct net_device *netdev = adapter->netdev;
1197 struct pci_dev *pdev = adapter->pdev;
1198 struct e1000_ring *rx_ring = adapter->rx_ring;
1199 struct e1000_buffer *buffer_info, *next_buffer;
1200 struct e1000_ps_page *ps_page;
1201 struct sk_buff *skb;
1202 unsigned int i, j;
1203 u32 length, staterr;
1204 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001205 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001206 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1207
1208 i = rx_ring->next_to_clean;
1209 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1210 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1211 buffer_info = &rx_ring->buffer_info[i];
1212
1213 while (staterr & E1000_RXD_STAT_DD) {
1214 if (*work_done >= work_to_do)
1215 break;
1216 (*work_done)++;
1217 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001218 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001219
1220 /* in the packet split case this is header only */
1221 prefetch(skb->data - NET_IP_ALIGN);
1222
1223 i++;
1224 if (i == rx_ring->count)
1225 i = 0;
1226 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1227 prefetch(next_rxd);
1228
1229 next_buffer = &rx_ring->buffer_info[i];
1230
Rusty Russell3db1cd52011-12-19 13:56:45 +00001231 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001232 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001233 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001234 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001235 buffer_info->dma = 0;
1236
Bruce Allanaf667a22010-12-31 06:10:01 +00001237 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001238 if (!(staterr & E1000_RXD_STAT_EOP))
1239 adapter->flags2 |= FLAG2_IS_DISCARDING;
1240
1241 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001242 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001243 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001244 if (staterr & E1000_RXD_STAT_EOP)
1245 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001246 goto next_desc;
1247 }
1248
1249 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1250 dev_kfree_skb_irq(skb);
1251 goto next_desc;
1252 }
1253
1254 length = le16_to_cpu(rx_desc->wb.middle.length0);
1255
1256 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001257 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001258 dev_kfree_skb_irq(skb);
1259 goto next_desc;
1260 }
1261
1262 /* Good Receive */
1263 skb_put(skb, length);
1264
1265 {
Bruce Allanad680762008-03-28 09:15:03 -07001266 /*
1267 * this looks ugly, but it seems compiler issues make it
1268 * more efficient than reusing j
1269 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001270 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1271
Bruce Allanad680762008-03-28 09:15:03 -07001272 /*
1273 * page alloc/put takes too long and effects small packet
1274 * throughput, so unsplit small packets and save the alloc/put
1275 * only valid in softirq (napi) context to call kmap_*
1276 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001277 if (l1 && (l1 <= copybreak) &&
1278 ((length + l1) <= adapter->rx_ps_bsize0)) {
1279 u8 *vaddr;
1280
Auke Kok47f44e42007-10-25 13:57:44 -07001281 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282
Bruce Allanad680762008-03-28 09:15:03 -07001283 /*
1284 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001285 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001286 * very long
1287 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001288 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1289 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001290 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1291 memcpy(skb_tail_pointer(skb), vaddr, l1);
1292 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001293 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1294 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001295
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001296 /* remove the CRC */
1297 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1298 l1 -= 4;
1299
Auke Kokbc7f75f2007-09-17 12:30:59 -07001300 skb_put(skb, l1);
1301 goto copydone;
1302 } /* if */
1303 }
1304
1305 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1306 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1307 if (!length)
1308 break;
1309
Auke Kok47f44e42007-10-25 13:57:44 -07001310 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001311 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1312 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001313 ps_page->dma = 0;
1314 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1315 ps_page->page = NULL;
1316 skb->len += length;
1317 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001318 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001319 }
1320
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001321 /* strip the ethernet crc, problem is we're using pages now so
1322 * this whole operation can get a little cpu intensive
1323 */
1324 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1325 pskb_trim(skb, skb->len - 4);
1326
Auke Kokbc7f75f2007-09-17 12:30:59 -07001327copydone:
1328 total_rx_bytes += skb->len;
1329 total_rx_packets++;
1330
Bruce Allanafd12932012-01-05 00:34:05 +00001331 e1000_rx_checksum(adapter, staterr,
1332 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001333
Bruce Allan70495a52012-01-11 01:26:50 +00001334 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1335
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336 if (rx_desc->wb.upper.header_status &
1337 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1338 adapter->rx_hdr_split++;
1339
1340 e1000_receive_skb(adapter, netdev, skb,
1341 staterr, rx_desc->wb.middle.vlan);
1342
1343next_desc:
1344 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1345 buffer_info->skb = NULL;
1346
1347 /* return some buffers to hardware, one at a time is too slow */
1348 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001349 adapter->alloc_rx_buf(adapter, cleaned_count,
1350 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001351 cleaned_count = 0;
1352 }
1353
1354 /* use prefetched values */
1355 rx_desc = next_rxd;
1356 buffer_info = next_buffer;
1357
1358 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1359 }
1360 rx_ring->next_to_clean = i;
1361
1362 cleaned_count = e1000_desc_unused(rx_ring);
1363 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001364 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001365
Auke Kokbc7f75f2007-09-17 12:30:59 -07001366 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001367 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001368 return cleaned;
1369}
1370
1371/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001372 * e1000_consume_page - helper function
1373 **/
1374static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1375 u16 length)
1376{
1377 bi->page = NULL;
1378 skb->len += length;
1379 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001380 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001381}
1382
1383/**
1384 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1385 * @adapter: board private structure
1386 *
1387 * the return value indicates whether actual cleaning was done, there
1388 * is no guarantee that everything was cleaned
1389 **/
1390
1391static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1392 int *work_done, int work_to_do)
1393{
1394 struct net_device *netdev = adapter->netdev;
1395 struct pci_dev *pdev = adapter->pdev;
1396 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +00001397 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001398 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001399 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001400 unsigned int i;
1401 int cleaned_count = 0;
1402 bool cleaned = false;
1403 unsigned int total_rx_bytes=0, total_rx_packets=0;
1404
1405 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001406 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1407 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001408 buffer_info = &rx_ring->buffer_info[i];
1409
Bruce Allan5f450212011-07-22 06:21:46 +00001410 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001411 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001412
1413 if (*work_done >= work_to_do)
1414 break;
1415 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001416 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001417
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001418 skb = buffer_info->skb;
1419 buffer_info->skb = NULL;
1420
1421 ++i;
1422 if (i == rx_ring->count)
1423 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001424 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001425 prefetch(next_rxd);
1426
1427 next_buffer = &rx_ring->buffer_info[i];
1428
1429 cleaned = true;
1430 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001431 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1432 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001433 buffer_info->dma = 0;
1434
Bruce Allan5f450212011-07-22 06:21:46 +00001435 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001436
1437 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001438 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1439 (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
1440 /* recycle both page and skb */
1441 buffer_info->skb = skb;
1442 /* an error means any chain goes out the window too */
1443 if (rx_ring->rx_skb_top)
1444 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1445 rx_ring->rx_skb_top = NULL;
1446 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001447 }
1448
Bruce Allanf0f1a172010-12-11 05:53:32 +00001449#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001450 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001451 /* this descriptor is only the beginning (or middle) */
1452 if (!rxtop) {
1453 /* this is the beginning of a chain */
1454 rxtop = skb;
1455 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1456 0, length);
1457 } else {
1458 /* this is the middle of a chain */
1459 skb_fill_page_desc(rxtop,
1460 skb_shinfo(rxtop)->nr_frags,
1461 buffer_info->page, 0, length);
1462 /* re-use the skb, only consumed the page */
1463 buffer_info->skb = skb;
1464 }
1465 e1000_consume_page(buffer_info, rxtop, length);
1466 goto next_desc;
1467 } else {
1468 if (rxtop) {
1469 /* end of the chain */
1470 skb_fill_page_desc(rxtop,
1471 skb_shinfo(rxtop)->nr_frags,
1472 buffer_info->page, 0, length);
1473 /* re-use the current skb, we only consumed the
1474 * page */
1475 buffer_info->skb = skb;
1476 skb = rxtop;
1477 rxtop = NULL;
1478 e1000_consume_page(buffer_info, skb, length);
1479 } else {
1480 /* no chain, got EOP, this buf is the packet
1481 * copybreak to save the put_page/alloc_page */
1482 if (length <= copybreak &&
1483 skb_tailroom(skb) >= length) {
1484 u8 *vaddr;
1485 vaddr = kmap_atomic(buffer_info->page,
1486 KM_SKB_DATA_SOFTIRQ);
1487 memcpy(skb_tail_pointer(skb), vaddr,
1488 length);
1489 kunmap_atomic(vaddr,
1490 KM_SKB_DATA_SOFTIRQ);
1491 /* re-use the page, so don't erase
1492 * buffer_info->page */
1493 skb_put(skb, length);
1494 } else {
1495 skb_fill_page_desc(skb, 0,
1496 buffer_info->page, 0,
1497 length);
1498 e1000_consume_page(buffer_info, skb,
1499 length);
1500 }
1501 }
1502 }
1503
1504 /* Receive Checksum Offload XXX recompute due to CRC strip? */
Bruce Allan5f450212011-07-22 06:21:46 +00001505 e1000_rx_checksum(adapter, staterr,
Bruce Allanafd12932012-01-05 00:34:05 +00001506 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001507
Bruce Allan70495a52012-01-11 01:26:50 +00001508 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1509
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001510 /* probably a little skewed due to removing CRC */
1511 total_rx_bytes += skb->len;
1512 total_rx_packets++;
1513
1514 /* eth type trans needs skb->data to point to something */
1515 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001516 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001517 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001518 goto next_desc;
1519 }
1520
Bruce Allan5f450212011-07-22 06:21:46 +00001521 e1000_receive_skb(adapter, netdev, skb, staterr,
1522 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001523
1524next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001525 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001526
1527 /* return some buffers to hardware, one at a time is too slow */
1528 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001529 adapter->alloc_rx_buf(adapter, cleaned_count,
1530 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001531 cleaned_count = 0;
1532 }
1533
1534 /* use prefetched values */
1535 rx_desc = next_rxd;
1536 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001537
1538 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001539 }
1540 rx_ring->next_to_clean = i;
1541
1542 cleaned_count = e1000_desc_unused(rx_ring);
1543 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001544 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001545
1546 adapter->total_rx_bytes += total_rx_bytes;
1547 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001548 return cleaned;
1549}
1550
1551/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001552 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1553 * @adapter: board private structure
1554 **/
1555static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1556{
1557 struct e1000_ring *rx_ring = adapter->rx_ring;
1558 struct e1000_buffer *buffer_info;
1559 struct e1000_ps_page *ps_page;
1560 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001561 unsigned int i, j;
1562
1563 /* Free all the Rx ring sk_buffs */
1564 for (i = 0; i < rx_ring->count; i++) {
1565 buffer_info = &rx_ring->buffer_info[i];
1566 if (buffer_info->dma) {
1567 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001568 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001569 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001570 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001571 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001572 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001573 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001574 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001575 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001576 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001578 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001579 buffer_info->dma = 0;
1580 }
1581
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001582 if (buffer_info->page) {
1583 put_page(buffer_info->page);
1584 buffer_info->page = NULL;
1585 }
1586
Auke Kokbc7f75f2007-09-17 12:30:59 -07001587 if (buffer_info->skb) {
1588 dev_kfree_skb(buffer_info->skb);
1589 buffer_info->skb = NULL;
1590 }
1591
1592 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001593 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001594 if (!ps_page->page)
1595 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001596 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1597 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001598 ps_page->dma = 0;
1599 put_page(ps_page->page);
1600 ps_page->page = NULL;
1601 }
1602 }
1603
1604 /* there also may be some cached data from a chained receive */
1605 if (rx_ring->rx_skb_top) {
1606 dev_kfree_skb(rx_ring->rx_skb_top);
1607 rx_ring->rx_skb_top = NULL;
1608 }
1609
Auke Kokbc7f75f2007-09-17 12:30:59 -07001610 /* Zero out the descriptor ring */
1611 memset(rx_ring->desc, 0, rx_ring->size);
1612
1613 rx_ring->next_to_clean = 0;
1614 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001615 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616
Bruce Allanc5083cf2011-12-16 00:45:40 +00001617 writel(0, rx_ring->head);
1618 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001619}
1620
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001621static void e1000e_downshift_workaround(struct work_struct *work)
1622{
1623 struct e1000_adapter *adapter = container_of(work,
1624 struct e1000_adapter, downshift_task);
1625
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001626 if (test_bit(__E1000_DOWN, &adapter->state))
1627 return;
1628
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001629 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1630}
1631
Auke Kokbc7f75f2007-09-17 12:30:59 -07001632/**
1633 * e1000_intr_msi - Interrupt Handler
1634 * @irq: interrupt number
1635 * @data: pointer to a network interface device structure
1636 **/
1637static irqreturn_t e1000_intr_msi(int irq, void *data)
1638{
1639 struct net_device *netdev = data;
1640 struct e1000_adapter *adapter = netdev_priv(netdev);
1641 struct e1000_hw *hw = &adapter->hw;
1642 u32 icr = er32(ICR);
1643
Bruce Allanad680762008-03-28 09:15:03 -07001644 /*
1645 * read ICR disables interrupts using IAM
1646 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001647
dave graham573cca82009-02-10 12:52:05 +00001648 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001649 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001650 /*
1651 * ICH8 workaround-- Call gig speed drop workaround on cable
1652 * disconnect (LSC) before accessing any PHY registers
1653 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1655 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001656 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001657
Bruce Allanad680762008-03-28 09:15:03 -07001658 /*
1659 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001660 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001661 * adapter in watchdog
1662 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001663 if (netif_carrier_ok(netdev) &&
1664 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1665 /* disable receives */
1666 u32 rctl = er32(RCTL);
1667 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001668 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001669 }
1670 /* guard against interrupt when we're going down */
1671 if (!test_bit(__E1000_DOWN, &adapter->state))
1672 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1673 }
1674
Ben Hutchings288379f2009-01-19 16:43:59 -08001675 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001676 adapter->total_tx_bytes = 0;
1677 adapter->total_tx_packets = 0;
1678 adapter->total_rx_bytes = 0;
1679 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001680 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681 }
1682
1683 return IRQ_HANDLED;
1684}
1685
1686/**
1687 * e1000_intr - Interrupt Handler
1688 * @irq: interrupt number
1689 * @data: pointer to a network interface device structure
1690 **/
1691static irqreturn_t e1000_intr(int irq, void *data)
1692{
1693 struct net_device *netdev = data;
1694 struct e1000_adapter *adapter = netdev_priv(netdev);
1695 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001696 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001697
Bruce Allana68ea772009-11-20 23:23:16 +00001698 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001699 return IRQ_NONE; /* Not our interrupt */
1700
Bruce Allanad680762008-03-28 09:15:03 -07001701 /*
1702 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1703 * not set, then the adapter didn't send an interrupt
1704 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705 if (!(icr & E1000_ICR_INT_ASSERTED))
1706 return IRQ_NONE;
1707
Bruce Allanad680762008-03-28 09:15:03 -07001708 /*
1709 * Interrupt Auto-Mask...upon reading ICR,
1710 * interrupts are masked. No need for the
1711 * IMC write
1712 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001713
dave graham573cca82009-02-10 12:52:05 +00001714 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001715 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001716 /*
1717 * ICH8 workaround-- Call gig speed drop workaround on cable
1718 * disconnect (LSC) before accessing any PHY registers
1719 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001720 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1721 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001722 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001723
Bruce Allanad680762008-03-28 09:15:03 -07001724 /*
1725 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001726 * For packet buffer work-around on link down event;
1727 * disable receives here in the ISR and
1728 * reset adapter in watchdog
1729 */
1730 if (netif_carrier_ok(netdev) &&
1731 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1732 /* disable receives */
1733 rctl = er32(RCTL);
1734 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001735 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001736 }
1737 /* guard against interrupt when we're going down */
1738 if (!test_bit(__E1000_DOWN, &adapter->state))
1739 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1740 }
1741
Ben Hutchings288379f2009-01-19 16:43:59 -08001742 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001743 adapter->total_tx_bytes = 0;
1744 adapter->total_tx_packets = 0;
1745 adapter->total_rx_bytes = 0;
1746 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001747 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001748 }
1749
1750 return IRQ_HANDLED;
1751}
1752
Bruce Allan4662e822008-08-26 18:37:06 -07001753static irqreturn_t e1000_msix_other(int irq, void *data)
1754{
1755 struct net_device *netdev = data;
1756 struct e1000_adapter *adapter = netdev_priv(netdev);
1757 struct e1000_hw *hw = &adapter->hw;
1758 u32 icr = er32(ICR);
1759
1760 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001761 if (!test_bit(__E1000_DOWN, &adapter->state))
1762 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001763 return IRQ_NONE;
1764 }
1765
1766 if (icr & adapter->eiac_mask)
1767 ew32(ICS, (icr & adapter->eiac_mask));
1768
1769 if (icr & E1000_ICR_OTHER) {
1770 if (!(icr & E1000_ICR_LSC))
1771 goto no_link_interrupt;
1772 hw->mac.get_link_status = 1;
1773 /* guard against interrupt when we're going down */
1774 if (!test_bit(__E1000_DOWN, &adapter->state))
1775 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1776 }
1777
1778no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001779 if (!test_bit(__E1000_DOWN, &adapter->state))
1780 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001781
1782 return IRQ_HANDLED;
1783}
1784
1785
1786static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1787{
1788 struct net_device *netdev = data;
1789 struct e1000_adapter *adapter = netdev_priv(netdev);
1790 struct e1000_hw *hw = &adapter->hw;
1791 struct e1000_ring *tx_ring = adapter->tx_ring;
1792
1793
1794 adapter->total_tx_bytes = 0;
1795 adapter->total_tx_packets = 0;
1796
1797 if (!e1000_clean_tx_irq(adapter))
1798 /* Ring was not completely cleaned, so fire another interrupt */
1799 ew32(ICS, tx_ring->ims_val);
1800
1801 return IRQ_HANDLED;
1802}
1803
1804static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1805{
1806 struct net_device *netdev = data;
1807 struct e1000_adapter *adapter = netdev_priv(netdev);
1808
1809 /* Write the ITR value calculated at the end of the
1810 * previous interrupt.
1811 */
1812 if (adapter->rx_ring->set_itr) {
1813 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001814 adapter->rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001815 adapter->rx_ring->set_itr = 0;
1816 }
1817
Ben Hutchings288379f2009-01-19 16:43:59 -08001818 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001819 adapter->total_rx_bytes = 0;
1820 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001821 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001822 }
1823 return IRQ_HANDLED;
1824}
1825
1826/**
1827 * e1000_configure_msix - Configure MSI-X hardware
1828 *
1829 * e1000_configure_msix sets up the hardware to properly
1830 * generate MSI-X interrupts.
1831 **/
1832static void e1000_configure_msix(struct e1000_adapter *adapter)
1833{
1834 struct e1000_hw *hw = &adapter->hw;
1835 struct e1000_ring *rx_ring = adapter->rx_ring;
1836 struct e1000_ring *tx_ring = adapter->tx_ring;
1837 int vector = 0;
1838 u32 ctrl_ext, ivar = 0;
1839
1840 adapter->eiac_mask = 0;
1841
1842 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1843 if (hw->mac.type == e1000_82574) {
1844 u32 rfctl = er32(RFCTL);
1845 rfctl |= E1000_RFCTL_ACK_DIS;
1846 ew32(RFCTL, rfctl);
1847 }
1848
1849#define E1000_IVAR_INT_ALLOC_VALID 0x8
1850 /* Configure Rx vector */
1851 rx_ring->ims_val = E1000_IMS_RXQ0;
1852 adapter->eiac_mask |= rx_ring->ims_val;
1853 if (rx_ring->itr_val)
1854 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001855 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001856 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001857 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001858 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1859
1860 /* Configure Tx vector */
1861 tx_ring->ims_val = E1000_IMS_TXQ0;
1862 vector++;
1863 if (tx_ring->itr_val)
1864 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001865 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001866 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001867 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001868 adapter->eiac_mask |= tx_ring->ims_val;
1869 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1870
1871 /* set vector for Other Causes, e.g. link changes */
1872 vector++;
1873 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1874 if (rx_ring->itr_val)
1875 writel(1000000000 / (rx_ring->itr_val * 256),
1876 hw->hw_addr + E1000_EITR_82574(vector));
1877 else
1878 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1879
1880 /* Cause Tx interrupts on every write back */
1881 ivar |= (1 << 31);
1882
1883 ew32(IVAR, ivar);
1884
1885 /* enable MSI-X PBA support */
1886 ctrl_ext = er32(CTRL_EXT);
1887 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1888
1889 /* Auto-Mask Other interrupts upon ICR read */
1890#define E1000_EIAC_MASK_82574 0x01F00000
1891 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1892 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1893 ew32(CTRL_EXT, ctrl_ext);
1894 e1e_flush();
1895}
1896
1897void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1898{
1899 if (adapter->msix_entries) {
1900 pci_disable_msix(adapter->pdev);
1901 kfree(adapter->msix_entries);
1902 adapter->msix_entries = NULL;
1903 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1904 pci_disable_msi(adapter->pdev);
1905 adapter->flags &= ~FLAG_MSI_ENABLED;
1906 }
Bruce Allan4662e822008-08-26 18:37:06 -07001907}
1908
1909/**
1910 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1911 *
1912 * Attempt to configure interrupts using the best available
1913 * capabilities of the hardware and kernel.
1914 **/
1915void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1916{
1917 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001918 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001919
1920 switch (adapter->int_mode) {
1921 case E1000E_INT_MODE_MSIX:
1922 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001923 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1924 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001925 sizeof(struct msix_entry),
1926 GFP_KERNEL);
1927 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001928 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001929 adapter->msix_entries[i].entry = i;
1930
1931 err = pci_enable_msix(adapter->pdev,
1932 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001933 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001934 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001935 return;
1936 }
1937 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00001938 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001939 e1000e_reset_interrupt_capability(adapter);
1940 }
1941 adapter->int_mode = E1000E_INT_MODE_MSI;
1942 /* Fall through */
1943 case E1000E_INT_MODE_MSI:
1944 if (!pci_enable_msi(adapter->pdev)) {
1945 adapter->flags |= FLAG_MSI_ENABLED;
1946 } else {
1947 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00001948 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001949 }
1950 /* Fall through */
1951 case E1000E_INT_MODE_LEGACY:
1952 /* Don't do anything; this is the system default */
1953 break;
1954 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001955
1956 /* store the number of vectors being used */
1957 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001958}
1959
1960/**
1961 * e1000_request_msix - Initialize MSI-X interrupts
1962 *
1963 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1964 * kernel.
1965 **/
1966static int e1000_request_msix(struct e1000_adapter *adapter)
1967{
1968 struct net_device *netdev = adapter->netdev;
1969 int err = 0, vector = 0;
1970
1971 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001972 snprintf(adapter->rx_ring->name,
1973 sizeof(adapter->rx_ring->name) - 1,
1974 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001975 else
1976 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1977 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001978 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001979 netdev);
1980 if (err)
1981 goto out;
Bruce Allanc5083cf2011-12-16 00:45:40 +00001982 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
1983 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07001984 adapter->rx_ring->itr_val = adapter->itr;
1985 vector++;
1986
1987 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001988 snprintf(adapter->tx_ring->name,
1989 sizeof(adapter->tx_ring->name) - 1,
1990 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001991 else
1992 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1993 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001994 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001995 netdev);
1996 if (err)
1997 goto out;
Bruce Allanc5083cf2011-12-16 00:45:40 +00001998 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
1999 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002000 adapter->tx_ring->itr_val = adapter->itr;
2001 vector++;
2002
2003 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002004 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002005 if (err)
2006 goto out;
2007
2008 e1000_configure_msix(adapter);
2009 return 0;
2010out:
2011 return err;
2012}
2013
Bruce Allanf8d59f72008-08-08 18:36:11 -07002014/**
2015 * e1000_request_irq - initialize interrupts
2016 *
2017 * Attempts to configure interrupts using the best available
2018 * capabilities of the hardware and kernel.
2019 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002020static int e1000_request_irq(struct e1000_adapter *adapter)
2021{
2022 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002023 int err;
2024
Bruce Allan4662e822008-08-26 18:37:06 -07002025 if (adapter->msix_entries) {
2026 err = e1000_request_msix(adapter);
2027 if (!err)
2028 return err;
2029 /* fall back to MSI */
2030 e1000e_reset_interrupt_capability(adapter);
2031 adapter->int_mode = E1000E_INT_MODE_MSI;
2032 e1000e_set_interrupt_capability(adapter);
2033 }
2034 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002035 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002036 netdev->name, netdev);
2037 if (!err)
2038 return err;
2039
2040 /* fall back to legacy interrupt */
2041 e1000e_reset_interrupt_capability(adapter);
2042 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002043 }
2044
Joe Perchesa0607fd2009-11-18 23:29:17 -08002045 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002046 netdev->name, netdev);
2047 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002048 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002049
2050 return err;
2051}
2052
2053static void e1000_free_irq(struct e1000_adapter *adapter)
2054{
2055 struct net_device *netdev = adapter->netdev;
2056
Bruce Allan4662e822008-08-26 18:37:06 -07002057 if (adapter->msix_entries) {
2058 int vector = 0;
2059
2060 free_irq(adapter->msix_entries[vector].vector, netdev);
2061 vector++;
2062
2063 free_irq(adapter->msix_entries[vector].vector, netdev);
2064 vector++;
2065
2066 /* Other Causes interrupt vector */
2067 free_irq(adapter->msix_entries[vector].vector, netdev);
2068 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002069 }
Bruce Allan4662e822008-08-26 18:37:06 -07002070
2071 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002072}
2073
2074/**
2075 * e1000_irq_disable - Mask off interrupt generation on the NIC
2076 **/
2077static void e1000_irq_disable(struct e1000_adapter *adapter)
2078{
2079 struct e1000_hw *hw = &adapter->hw;
2080
Auke Kokbc7f75f2007-09-17 12:30:59 -07002081 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002082 if (adapter->msix_entries)
2083 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002084 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002085
2086 if (adapter->msix_entries) {
2087 int i;
2088 for (i = 0; i < adapter->num_vectors; i++)
2089 synchronize_irq(adapter->msix_entries[i].vector);
2090 } else {
2091 synchronize_irq(adapter->pdev->irq);
2092 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002093}
2094
2095/**
2096 * e1000_irq_enable - Enable default interrupt generation settings
2097 **/
2098static void e1000_irq_enable(struct e1000_adapter *adapter)
2099{
2100 struct e1000_hw *hw = &adapter->hw;
2101
Bruce Allan4662e822008-08-26 18:37:06 -07002102 if (adapter->msix_entries) {
2103 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2104 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2105 } else {
2106 ew32(IMS, IMS_ENABLE_MASK);
2107 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002108 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002109}
2110
2111/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002112 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002113 * @adapter: address of board private structure
2114 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002115 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002116 * For ASF and Pass Through versions of f/w this means that
2117 * the driver is loaded. For AMT version (only with 82573)
2118 * of the f/w this means that the network i/f is open.
2119 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002120void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002121{
2122 struct e1000_hw *hw = &adapter->hw;
2123 u32 ctrl_ext;
2124 u32 swsm;
2125
2126 /* Let firmware know the driver has taken over */
2127 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2128 swsm = er32(SWSM);
2129 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2130 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2131 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002132 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002133 }
2134}
2135
2136/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002137 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002138 * @adapter: address of board private structure
2139 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002140 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002141 * For ASF and Pass Through versions of f/w this means that the
2142 * driver is no longer loaded. For AMT version (only with 82573) i
2143 * of the f/w this means that the network i/f is closed.
2144 *
2145 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002146void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002147{
2148 struct e1000_hw *hw = &adapter->hw;
2149 u32 ctrl_ext;
2150 u32 swsm;
2151
2152 /* Let firmware taken over control of h/w */
2153 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2154 swsm = er32(SWSM);
2155 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2156 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2157 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002158 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002159 }
2160}
2161
Auke Kokbc7f75f2007-09-17 12:30:59 -07002162/**
2163 * @e1000_alloc_ring - allocate memory for a ring structure
2164 **/
2165static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2166 struct e1000_ring *ring)
2167{
2168 struct pci_dev *pdev = adapter->pdev;
2169
2170 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2171 GFP_KERNEL);
2172 if (!ring->desc)
2173 return -ENOMEM;
2174
2175 return 0;
2176}
2177
2178/**
2179 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2180 * @adapter: board private structure
2181 *
2182 * Return 0 on success, negative on failure
2183 **/
2184int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2185{
2186 struct e1000_ring *tx_ring = adapter->tx_ring;
2187 int err = -ENOMEM, size;
2188
2189 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002190 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002191 if (!tx_ring->buffer_info)
2192 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002193
2194 /* round up to nearest 4K */
2195 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2196 tx_ring->size = ALIGN(tx_ring->size, 4096);
2197
2198 err = e1000_alloc_ring_dma(adapter, tx_ring);
2199 if (err)
2200 goto err;
2201
2202 tx_ring->next_to_use = 0;
2203 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002204
2205 return 0;
2206err:
2207 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002208 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002209 return err;
2210}
2211
2212/**
2213 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2214 * @adapter: board private structure
2215 *
2216 * Returns 0 on success, negative on failure
2217 **/
2218int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2219{
2220 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002221 struct e1000_buffer *buffer_info;
2222 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002223
2224 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002225 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002226 if (!rx_ring->buffer_info)
2227 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002228
Auke Kok47f44e42007-10-25 13:57:44 -07002229 for (i = 0; i < rx_ring->count; i++) {
2230 buffer_info = &rx_ring->buffer_info[i];
2231 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2232 sizeof(struct e1000_ps_page),
2233 GFP_KERNEL);
2234 if (!buffer_info->ps_pages)
2235 goto err_pages;
2236 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002237
2238 desc_len = sizeof(union e1000_rx_desc_packet_split);
2239
2240 /* Round up to nearest 4K */
2241 rx_ring->size = rx_ring->count * desc_len;
2242 rx_ring->size = ALIGN(rx_ring->size, 4096);
2243
2244 err = e1000_alloc_ring_dma(adapter, rx_ring);
2245 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002246 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002247
2248 rx_ring->next_to_clean = 0;
2249 rx_ring->next_to_use = 0;
2250 rx_ring->rx_skb_top = NULL;
2251
2252 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002253
2254err_pages:
2255 for (i = 0; i < rx_ring->count; i++) {
2256 buffer_info = &rx_ring->buffer_info[i];
2257 kfree(buffer_info->ps_pages);
2258 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259err:
2260 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002261 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002262 return err;
2263}
2264
2265/**
2266 * e1000_clean_tx_ring - Free Tx Buffers
2267 * @adapter: board private structure
2268 **/
2269static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2270{
2271 struct e1000_ring *tx_ring = adapter->tx_ring;
2272 struct e1000_buffer *buffer_info;
2273 unsigned long size;
2274 unsigned int i;
2275
2276 for (i = 0; i < tx_ring->count; i++) {
2277 buffer_info = &tx_ring->buffer_info[i];
2278 e1000_put_txbuf(adapter, buffer_info);
2279 }
2280
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002281 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002282 size = sizeof(struct e1000_buffer) * tx_ring->count;
2283 memset(tx_ring->buffer_info, 0, size);
2284
2285 memset(tx_ring->desc, 0, tx_ring->size);
2286
2287 tx_ring->next_to_use = 0;
2288 tx_ring->next_to_clean = 0;
2289
Bruce Allanc5083cf2011-12-16 00:45:40 +00002290 writel(0, tx_ring->head);
2291 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002292}
2293
2294/**
2295 * e1000e_free_tx_resources - Free Tx Resources per Queue
2296 * @adapter: board private structure
2297 *
2298 * Free all transmit software resources
2299 **/
2300void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2301{
2302 struct pci_dev *pdev = adapter->pdev;
2303 struct e1000_ring *tx_ring = adapter->tx_ring;
2304
2305 e1000_clean_tx_ring(adapter);
2306
2307 vfree(tx_ring->buffer_info);
2308 tx_ring->buffer_info = NULL;
2309
2310 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2311 tx_ring->dma);
2312 tx_ring->desc = NULL;
2313}
2314
2315/**
2316 * e1000e_free_rx_resources - Free Rx Resources
2317 * @adapter: board private structure
2318 *
2319 * Free all receive software resources
2320 **/
2321
2322void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2323{
2324 struct pci_dev *pdev = adapter->pdev;
2325 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002326 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327
2328 e1000_clean_rx_ring(adapter);
2329
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002330 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002331 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002332
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333 vfree(rx_ring->buffer_info);
2334 rx_ring->buffer_info = NULL;
2335
Auke Kokbc7f75f2007-09-17 12:30:59 -07002336 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2337 rx_ring->dma);
2338 rx_ring->desc = NULL;
2339}
2340
2341/**
2342 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002343 * @adapter: pointer to adapter
2344 * @itr_setting: current adapter->itr
2345 * @packets: the number of packets during this measurement interval
2346 * @bytes: the number of bytes during this measurement interval
2347 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002348 * Stores a new ITR value based on packets and byte
2349 * counts during the last interrupt. The advantage of per interrupt
2350 * computation is faster updates and more accurate ITR for the current
2351 * traffic pattern. Constants in this function were computed
2352 * based on theoretical maximum wire speed and thresholds were set based
2353 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002354 * while increasing bulk throughput. This functionality is controlled
2355 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356 **/
2357static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2358 u16 itr_setting, int packets,
2359 int bytes)
2360{
2361 unsigned int retval = itr_setting;
2362
2363 if (packets == 0)
2364 goto update_itr_done;
2365
2366 switch (itr_setting) {
2367 case lowest_latency:
2368 /* handle TSO and jumbo frames */
2369 if (bytes/packets > 8000)
2370 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002371 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002372 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373 break;
2374 case low_latency: /* 50 usec aka 20000 ints/s */
2375 if (bytes > 10000) {
2376 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002377 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002379 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002380 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002381 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002383 } else if (bytes/packets > 2000) {
2384 retval = bulk_latency;
2385 } else if (packets <= 2 && bytes < 512) {
2386 retval = lowest_latency;
2387 }
2388 break;
2389 case bulk_latency: /* 250 usec aka 4000 ints/s */
2390 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002391 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002392 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002393 } else if (bytes < 6000) {
2394 retval = low_latency;
2395 }
2396 break;
2397 }
2398
2399update_itr_done:
2400 return retval;
2401}
2402
2403static void e1000_set_itr(struct e1000_adapter *adapter)
2404{
2405 struct e1000_hw *hw = &adapter->hw;
2406 u16 current_itr;
2407 u32 new_itr = adapter->itr;
2408
2409 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2410 if (adapter->link_speed != SPEED_1000) {
2411 current_itr = 0;
2412 new_itr = 4000;
2413 goto set_itr_now;
2414 }
2415
Bruce Allan828bac82010-09-29 21:39:37 +00002416 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2417 new_itr = 0;
2418 goto set_itr_now;
2419 }
2420
Auke Kokbc7f75f2007-09-17 12:30:59 -07002421 adapter->tx_itr = e1000_update_itr(adapter,
2422 adapter->tx_itr,
2423 adapter->total_tx_packets,
2424 adapter->total_tx_bytes);
2425 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2426 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2427 adapter->tx_itr = low_latency;
2428
2429 adapter->rx_itr = e1000_update_itr(adapter,
2430 adapter->rx_itr,
2431 adapter->total_rx_packets,
2432 adapter->total_rx_bytes);
2433 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2434 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2435 adapter->rx_itr = low_latency;
2436
2437 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2438
2439 switch (current_itr) {
2440 /* counts and packets in update_itr are dependent on these numbers */
2441 case lowest_latency:
2442 new_itr = 70000;
2443 break;
2444 case low_latency:
2445 new_itr = 20000; /* aka hwitr = ~200 */
2446 break;
2447 case bulk_latency:
2448 new_itr = 4000;
2449 break;
2450 default:
2451 break;
2452 }
2453
2454set_itr_now:
2455 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002456 /*
2457 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002458 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002459 * increasing
2460 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002461 new_itr = new_itr > adapter->itr ?
2462 min(adapter->itr + (new_itr >> 2), new_itr) :
2463 new_itr;
2464 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002465 adapter->rx_ring->itr_val = new_itr;
2466 if (adapter->msix_entries)
2467 adapter->rx_ring->set_itr = 1;
2468 else
Bruce Allan828bac82010-09-29 21:39:37 +00002469 if (new_itr)
2470 ew32(ITR, 1000000000 / (new_itr * 256));
2471 else
2472 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002473 }
2474}
2475
2476/**
Bruce Allan4662e822008-08-26 18:37:06 -07002477 * e1000_alloc_queues - Allocate memory for all rings
2478 * @adapter: board private structure to initialize
2479 **/
2480static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2481{
2482 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2483 if (!adapter->tx_ring)
2484 goto err;
2485
2486 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2487 if (!adapter->rx_ring)
2488 goto err;
2489
2490 return 0;
2491err:
2492 e_err("Unable to allocate memory for queues\n");
2493 kfree(adapter->rx_ring);
2494 kfree(adapter->tx_ring);
2495 return -ENOMEM;
2496}
2497
2498/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002499 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002500 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002501 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502 **/
2503static int e1000_clean(struct napi_struct *napi, int budget)
2504{
2505 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002506 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002507 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002508 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509
Wang Chen4cf16532008-11-12 23:38:14 -08002510 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002511
Bruce Allan4662e822008-08-26 18:37:06 -07002512 if (adapter->msix_entries &&
2513 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2514 goto clean_rx;
2515
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002516 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002517
Bruce Allan4662e822008-08-26 18:37:06 -07002518clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002519 adapter->clean_rx(adapter, &work_done, budget);
2520
Alexander Duyck12d04a32009-03-25 22:05:03 +00002521 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002522 work_done = budget;
2523
David S. Miller53e52c72008-01-07 21:06:12 -08002524 /* If budget not fully consumed, exit the polling mode */
2525 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526 if (adapter->itr_setting & 3)
2527 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002528 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002529 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2530 if (adapter->msix_entries)
2531 ew32(IMS, adapter->rx_ring->ims_val);
2532 else
2533 e1000_irq_enable(adapter);
2534 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002535 }
2536
2537 return work_done;
2538}
2539
Jiri Pirko8e586132011-12-08 19:52:37 -05002540static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002541{
2542 struct e1000_adapter *adapter = netdev_priv(netdev);
2543 struct e1000_hw *hw = &adapter->hw;
2544 u32 vfta, index;
2545
2546 /* don't update vlan cookie if already programmed */
2547 if ((adapter->hw.mng_cookie.status &
2548 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2549 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002550 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002551
Auke Kokbc7f75f2007-09-17 12:30:59 -07002552 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002553 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2554 index = (vid >> 5) & 0x7F;
2555 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2556 vfta |= (1 << (vid & 0x1F));
2557 hw->mac.ops.write_vfta(hw, index, vfta);
2558 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002559
2560 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002561
2562 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563}
2564
Jiri Pirko8e586132011-12-08 19:52:37 -05002565static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566{
2567 struct e1000_adapter *adapter = netdev_priv(netdev);
2568 struct e1000_hw *hw = &adapter->hw;
2569 u32 vfta, index;
2570
Auke Kokbc7f75f2007-09-17 12:30:59 -07002571 if ((adapter->hw.mng_cookie.status &
2572 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2573 (vid == adapter->mng_vlan_id)) {
2574 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002575 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002576 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577 }
2578
2579 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002580 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2581 index = (vid >> 5) & 0x7F;
2582 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2583 vfta &= ~(1 << (vid & 0x1F));
2584 hw->mac.ops.write_vfta(hw, index, vfta);
2585 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002586
2587 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002588
2589 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002590}
2591
2592/**
2593 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2594 * @adapter: board private structure to initialize
2595 **/
2596static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2597{
2598 struct net_device *netdev = adapter->netdev;
2599 struct e1000_hw *hw = &adapter->hw;
2600 u32 rctl;
2601
2602 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2603 /* disable VLAN receive filtering */
2604 rctl = er32(RCTL);
2605 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2606 ew32(RCTL, rctl);
2607
2608 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2609 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2610 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2611 }
2612 }
2613}
2614
2615/**
2616 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2617 * @adapter: board private structure to initialize
2618 **/
2619static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2620{
2621 struct e1000_hw *hw = &adapter->hw;
2622 u32 rctl;
2623
2624 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2625 /* enable VLAN receive filtering */
2626 rctl = er32(RCTL);
2627 rctl |= E1000_RCTL_VFE;
2628 rctl &= ~E1000_RCTL_CFIEN;
2629 ew32(RCTL, rctl);
2630 }
2631}
2632
2633/**
2634 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2635 * @adapter: board private structure to initialize
2636 **/
2637static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2638{
2639 struct e1000_hw *hw = &adapter->hw;
2640 u32 ctrl;
2641
2642 /* disable VLAN tag insert/strip */
2643 ctrl = er32(CTRL);
2644 ctrl &= ~E1000_CTRL_VME;
2645 ew32(CTRL, ctrl);
2646}
2647
2648/**
2649 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2650 * @adapter: board private structure to initialize
2651 **/
2652static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2653{
2654 struct e1000_hw *hw = &adapter->hw;
2655 u32 ctrl;
2656
2657 /* enable VLAN tag insert/strip */
2658 ctrl = er32(CTRL);
2659 ctrl |= E1000_CTRL_VME;
2660 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002661}
2662
2663static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2664{
2665 struct net_device *netdev = adapter->netdev;
2666 u16 vid = adapter->hw.mng_cookie.vlan_id;
2667 u16 old_vid = adapter->mng_vlan_id;
2668
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002669 if (adapter->hw.mng_cookie.status &
2670 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2671 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002672 adapter->mng_vlan_id = vid;
2673 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002674
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002675 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2676 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002677}
2678
2679static void e1000_restore_vlan(struct e1000_adapter *adapter)
2680{
2681 u16 vid;
2682
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002683 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002684
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002685 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002686 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002687}
2688
Bruce Allancd791612010-05-10 14:59:51 +00002689static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002690{
2691 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002692 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002693
2694 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2695 return;
2696
2697 manc = er32(MANC);
2698
Bruce Allanad680762008-03-28 09:15:03 -07002699 /*
2700 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002701 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002702 * the packets will be handled on SMBUS
2703 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002704 manc |= E1000_MANC_EN_MNG2HOST;
2705 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002706
2707 switch (hw->mac.type) {
2708 default:
2709 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2710 break;
2711 case e1000_82574:
2712 case e1000_82583:
2713 /*
2714 * Check if IPMI pass-through decision filter already exists;
2715 * if so, enable it.
2716 */
2717 for (i = 0, j = 0; i < 8; i++) {
2718 mdef = er32(MDEF(i));
2719
2720 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002721 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002722 continue;
2723
2724 /* Enable this decision filter in MANC2H */
2725 if (mdef)
2726 manc2h |= (1 << i);
2727
2728 j |= mdef;
2729 }
2730
2731 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2732 break;
2733
2734 /* Create new decision filter in an empty filter */
2735 for (i = 0, j = 0; i < 8; i++)
2736 if (er32(MDEF(i)) == 0) {
2737 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2738 E1000_MDEF_PORT_664));
2739 manc2h |= (1 << 1);
2740 j++;
2741 break;
2742 }
2743
2744 if (!j)
2745 e_warn("Unable to create IPMI pass-through filter\n");
2746 break;
2747 }
2748
Auke Kokbc7f75f2007-09-17 12:30:59 -07002749 ew32(MANC2H, manc2h);
2750 ew32(MANC, manc);
2751}
2752
2753/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002754 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002755 * @adapter: board private structure
2756 *
2757 * Configure the Tx unit of the MAC after a reset.
2758 **/
2759static void e1000_configure_tx(struct e1000_adapter *adapter)
2760{
2761 struct e1000_hw *hw = &adapter->hw;
2762 struct e1000_ring *tx_ring = adapter->tx_ring;
2763 u64 tdba;
2764 u32 tdlen, tctl, tipg, tarc;
2765 u32 ipgr1, ipgr2;
2766
2767 /* Setup the HW Tx Head and Tail descriptor pointers */
2768 tdba = tx_ring->dma;
2769 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002770 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002771 ew32(TDBAH, (tdba >> 32));
2772 ew32(TDLEN, tdlen);
2773 ew32(TDH, 0);
2774 ew32(TDT, 0);
Bruce Allanc5083cf2011-12-16 00:45:40 +00002775 tx_ring->head = adapter->hw.hw_addr + E1000_TDH;
2776 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002777
2778 /* Set the default values for the Tx Inter Packet Gap timer */
2779 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2780 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2781 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2782
2783 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2784 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2785
2786 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2787 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2788 ew32(TIPG, tipg);
2789
2790 /* Set the Tx Interrupt Delay register */
2791 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002792 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002793 ew32(TADV, adapter->tx_abs_int_delay);
2794
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002795 if (adapter->flags2 & FLAG2_DMA_BURST) {
2796 u32 txdctl = er32(TXDCTL(0));
2797 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2798 E1000_TXDCTL_WTHRESH);
2799 /*
2800 * set up some performance related parameters to encourage the
2801 * hardware to use the bus more efficiently in bursts, depends
2802 * on the tx_int_delay to be enabled,
2803 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2804 * hthresh = 1 ==> prefetch when one or more available
2805 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2806 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002807 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002808 */
2809 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2810 ew32(TXDCTL(0), txdctl);
2811 /* erratum work around: set txdctl the same for both queues */
2812 ew32(TXDCTL(1), txdctl);
2813 }
2814
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815 /* Program the Transmit Control Register */
2816 tctl = er32(TCTL);
2817 tctl &= ~E1000_TCTL_CT;
2818 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2819 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2820
2821 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002822 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002823 /*
2824 * set the speed mode bit, we'll clear it if we're not at
2825 * gigabit link later
2826 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002827#define SPEED_MODE_BIT (1 << 21)
2828 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002829 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002830 }
2831
2832 /* errata: program both queues to unweighted RR */
2833 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002834 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002836 ew32(TARC(0), tarc);
2837 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002839 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002840 }
2841
Auke Kokbc7f75f2007-09-17 12:30:59 -07002842 /* Setup Transmit Descriptor Settings for eop descriptor */
2843 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2844
2845 /* only set IDE if we are delaying interrupts using the timers */
2846 if (adapter->tx_int_delay)
2847 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2848
2849 /* enable Report Status bit */
2850 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2851
2852 ew32(TCTL, tctl);
2853
Simon Hormanedfea6e62009-06-08 14:28:36 +00002854 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002855}
2856
2857/**
2858 * e1000_setup_rctl - configure the receive control registers
2859 * @adapter: Board private structure
2860 **/
2861#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2862 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2863static void e1000_setup_rctl(struct e1000_adapter *adapter)
2864{
2865 struct e1000_hw *hw = &adapter->hw;
2866 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002867 u32 pages = 0;
2868
Bruce Allana1ce6472010-09-22 17:16:40 +00002869 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2870 if (hw->mac.type == e1000_pch2lan) {
2871 s32 ret_val;
2872
2873 if (adapter->netdev->mtu > ETH_DATA_LEN)
2874 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2875 else
2876 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002877
2878 if (ret_val)
2879 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002880 }
2881
Auke Kokbc7f75f2007-09-17 12:30:59 -07002882 /* Program MC offset vector base */
2883 rctl = er32(RCTL);
2884 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2885 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2886 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2887 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2888
2889 /* Do not Store bad packets */
2890 rctl &= ~E1000_RCTL_SBP;
2891
2892 /* Enable Long Packet receive */
2893 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2894 rctl &= ~E1000_RCTL_LPE;
2895 else
2896 rctl |= E1000_RCTL_LPE;
2897
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002898 /* Some systems expect that the CRC is included in SMBUS traffic. The
2899 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2900 * host memory when this is enabled
2901 */
2902 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2903 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002904
Bruce Allana4f58f52009-06-02 11:29:18 +00002905 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2906 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2907 u16 phy_data;
2908
2909 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2910 phy_data &= 0xfff8;
2911 phy_data |= (1 << 2);
2912 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2913
2914 e1e_rphy(hw, 22, &phy_data);
2915 phy_data &= 0x0fff;
2916 phy_data |= (1 << 14);
2917 e1e_wphy(hw, 0x10, 0x2823);
2918 e1e_wphy(hw, 0x11, 0x0003);
2919 e1e_wphy(hw, 22, phy_data);
2920 }
2921
Auke Kokbc7f75f2007-09-17 12:30:59 -07002922 /* Setup buffer sizes */
2923 rctl &= ~E1000_RCTL_SZ_4096;
2924 rctl |= E1000_RCTL_BSEX;
2925 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002926 case 2048:
2927 default:
2928 rctl |= E1000_RCTL_SZ_2048;
2929 rctl &= ~E1000_RCTL_BSEX;
2930 break;
2931 case 4096:
2932 rctl |= E1000_RCTL_SZ_4096;
2933 break;
2934 case 8192:
2935 rctl |= E1000_RCTL_SZ_8192;
2936 break;
2937 case 16384:
2938 rctl |= E1000_RCTL_SZ_16384;
2939 break;
2940 }
2941
Bruce Allan5f450212011-07-22 06:21:46 +00002942 /* Enable Extended Status in all Receive Descriptors */
2943 rfctl = er32(RFCTL);
2944 rfctl |= E1000_RFCTL_EXTEN;
2945
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946 /*
2947 * 82571 and greater support packet-split where the protocol
2948 * header is placed in skb->data and the packet data is
2949 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2950 * In the case of a non-split, skb->data is linearly filled,
2951 * followed by the page buffers. Therefore, skb->data is
2952 * sized to hold the largest protocol header.
2953 *
2954 * allocations using alloc_page take too long for regular MTU
2955 * so only enable packet split for jumbo frames
2956 *
2957 * Using pages when the page size is greater than 16k wastes
2958 * a lot of memory, since we allocate 3 pages at all times
2959 * per packet.
2960 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fe2010-06-17 18:59:27 +00002962 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002963 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002965 else
2966 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002967
2968 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002969 u32 psrctl = 0;
2970
Bruce Allanad680762008-03-28 09:15:03 -07002971 /*
2972 * disable packet split support for IPv6 extension headers,
2973 * because some malformed IPv6 headers can hang the Rx
2974 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002975 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2976 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2977
Auke Kok140a7482007-10-25 13:57:58 -07002978 /* Enable Packet split descriptors */
2979 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002980
2981 psrctl |= adapter->rx_ps_bsize0 >>
2982 E1000_PSRCTL_BSIZE0_SHIFT;
2983
2984 switch (adapter->rx_ps_pages) {
2985 case 3:
2986 psrctl |= PAGE_SIZE <<
2987 E1000_PSRCTL_BSIZE3_SHIFT;
2988 case 2:
2989 psrctl |= PAGE_SIZE <<
2990 E1000_PSRCTL_BSIZE2_SHIFT;
2991 case 1:
2992 psrctl |= PAGE_SIZE >>
2993 E1000_PSRCTL_BSIZE1_SHIFT;
2994 break;
2995 }
2996
2997 ew32(PSRCTL, psrctl);
2998 }
2999
Bruce Allan5f450212011-07-22 06:21:46 +00003000 ew32(RFCTL, rfctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003001 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003002 /* just started the receive unit, no need to restart */
3003 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003004}
3005
3006/**
3007 * e1000_configure_rx - Configure Receive Unit after Reset
3008 * @adapter: board private structure
3009 *
3010 * Configure the Rx unit of the MAC after a reset.
3011 **/
3012static void e1000_configure_rx(struct e1000_adapter *adapter)
3013{
3014 struct e1000_hw *hw = &adapter->hw;
3015 struct e1000_ring *rx_ring = adapter->rx_ring;
3016 u64 rdba;
3017 u32 rdlen, rctl, rxcsum, ctrl_ext;
3018
3019 if (adapter->rx_ps_pages) {
3020 /* this is a 32 byte descriptor */
3021 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003022 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003023 adapter->clean_rx = e1000_clean_rx_irq_ps;
3024 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003025 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003026 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003027 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3028 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003029 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003030 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003031 adapter->clean_rx = e1000_clean_rx_irq;
3032 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3033 }
3034
3035 /* disable receives while setting up the descriptors */
3036 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003037 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3038 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003039 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003040 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003041
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003042 if (adapter->flags2 & FLAG2_DMA_BURST) {
3043 /*
3044 * set the writeback threshold (only takes effect if the RDTR
3045 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003046 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003047 * granularity = 01
3048 * wthresh = 04,
3049 * hthresh = 04,
3050 * pthresh = 0x20
3051 */
3052 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3053 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3054
3055 /*
3056 * override the delay timers for enabling bursting, only if
3057 * the value was not set by the user via module options
3058 */
3059 if (adapter->rx_int_delay == DEFAULT_RDTR)
3060 adapter->rx_int_delay = BURST_RDTR;
3061 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3062 adapter->rx_abs_int_delay = BURST_RADV;
3063 }
3064
Auke Kokbc7f75f2007-09-17 12:30:59 -07003065 /* set the Receive Delay Timer Register */
3066 ew32(RDTR, adapter->rx_int_delay);
3067
3068 /* irq moderation */
3069 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003070 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003071 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003072
3073 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003074 /* Auto-Mask interrupts upon ICR access */
3075 ctrl_ext |= E1000_CTRL_EXT_IAME;
3076 ew32(IAM, 0xffffffff);
3077 ew32(CTRL_EXT, ctrl_ext);
3078 e1e_flush();
3079
Bruce Allanad680762008-03-28 09:15:03 -07003080 /*
3081 * Setup the HW Rx Head and Tail Descriptor Pointers and
3082 * the Base and Length of the Rx Descriptor Ring
3083 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003084 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07003085 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003086 ew32(RDBAH, (rdba >> 32));
3087 ew32(RDLEN, rdlen);
3088 ew32(RDH, 0);
3089 ew32(RDT, 0);
Bruce Allanc5083cf2011-12-16 00:45:40 +00003090 rx_ring->head = adapter->hw.hw_addr + E1000_RDH;
3091 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003092
3093 /* Enable Receive Checksum Offload for TCP and UDP */
3094 rxcsum = er32(RXCSUM);
Bruce Allandc221292011-08-19 03:23:48 +00003095 if (adapter->netdev->features & NETIF_F_RXCSUM) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096 rxcsum |= E1000_RXCSUM_TUOFL;
3097
Bruce Allanad680762008-03-28 09:15:03 -07003098 /*
3099 * IPv4 payload checksum for UDP fragments must be
3100 * used in conjunction with packet-split.
3101 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003102 if (adapter->rx_ps_pages)
3103 rxcsum |= E1000_RXCSUM_IPPCSE;
3104 } else {
3105 rxcsum &= ~E1000_RXCSUM_TUOFL;
3106 /* no need to clear IPPCSE as it defaults to 0 */
3107 }
3108 ew32(RXCSUM, rxcsum);
3109
Bruce Allanad680762008-03-28 09:15:03 -07003110 /*
3111 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07003112 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07003113 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
3114 */
Bruce Allan828bac82010-09-29 21:39:37 +00003115 if ((adapter->flags & FLAG_HAS_ERT) ||
3116 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003117 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3118 u32 rxdctl = er32(RXDCTL(0));
3119 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00003120 if (adapter->flags & FLAG_HAS_ERT)
3121 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00003122 /*
3123 * With jumbo frames and early-receive enabled,
3124 * excessive C-state transition latencies result in
3125 * dropped transactions.
3126 */
Bruce Allanaf667a22010-12-31 06:10:01 +00003127 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003128 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003129 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3130 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003131 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003132 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003133
3134 /* Enable Receives */
3135 ew32(RCTL, rctl);
3136}
3137
3138/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003139 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003140 * @netdev: network interface device structure
3141 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003142 * Writes multicast address list to the MTA hash table.
3143 * Returns: -ENOMEM on failure
3144 * 0 on no addresses written
3145 * X on writing X addresses to MTA
3146 */
3147static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003148{
3149 struct e1000_adapter *adapter = netdev_priv(netdev);
3150 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003151 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003152 u8 *mta_list;
3153 int i;
3154
3155 if (netdev_mc_empty(netdev)) {
3156 /* nothing to program, so clear mc list */
3157 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3158 return 0;
3159 }
3160
3161 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3162 if (!mta_list)
3163 return -ENOMEM;
3164
3165 /* update_mc_addr_list expects a packed array of only addresses. */
3166 i = 0;
3167 netdev_for_each_mc_addr(ha, netdev)
3168 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3169
3170 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3171 kfree(mta_list);
3172
3173 return netdev_mc_count(netdev);
3174}
3175
3176/**
3177 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3178 * @netdev: network interface device structure
3179 *
3180 * Writes unicast address list to the RAR table.
3181 * Returns: -ENOMEM on failure/insufficient address space
3182 * 0 on no addresses written
3183 * X on writing X addresses to the RAR table
3184 **/
3185static int e1000e_write_uc_addr_list(struct net_device *netdev)
3186{
3187 struct e1000_adapter *adapter = netdev_priv(netdev);
3188 struct e1000_hw *hw = &adapter->hw;
3189 unsigned int rar_entries = hw->mac.rar_entry_count;
3190 int count = 0;
3191
3192 /* save a rar entry for our hardware address */
3193 rar_entries--;
3194
3195 /* save a rar entry for the LAA workaround */
3196 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3197 rar_entries--;
3198
3199 /* return ENOMEM indicating insufficient memory for addresses */
3200 if (netdev_uc_count(netdev) > rar_entries)
3201 return -ENOMEM;
3202
3203 if (!netdev_uc_empty(netdev) && rar_entries) {
3204 struct netdev_hw_addr *ha;
3205
3206 /*
3207 * write the addresses in reverse order to avoid write
3208 * combining
3209 */
3210 netdev_for_each_uc_addr(ha, netdev) {
3211 if (!rar_entries)
3212 break;
3213 e1000e_rar_set(hw, ha->addr, rar_entries--);
3214 count++;
3215 }
3216 }
3217
3218 /* zero out the remaining RAR entries not used above */
3219 for (; rar_entries > 0; rar_entries--) {
3220 ew32(RAH(rar_entries), 0);
3221 ew32(RAL(rar_entries), 0);
3222 }
3223 e1e_flush();
3224
3225 return count;
3226}
3227
3228/**
3229 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3230 * @netdev: network interface device structure
3231 *
3232 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3233 * address list or the network interface flags are updated. This routine is
3234 * responsible for configuring the hardware for proper unicast, multicast,
3235 * promiscuous mode, and all-multi behavior.
3236 **/
3237static void e1000e_set_rx_mode(struct net_device *netdev)
3238{
3239 struct e1000_adapter *adapter = netdev_priv(netdev);
3240 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003241 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003242
3243 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003244 rctl = er32(RCTL);
3245
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003246 /* clear the affected bits */
3247 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3248
Auke Kokbc7f75f2007-09-17 12:30:59 -07003249 if (netdev->flags & IFF_PROMISC) {
3250 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003251 /* Do not hardware filter VLANs in promisc mode */
3252 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003253 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003254 int count;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003255 if (netdev->flags & IFF_ALLMULTI) {
3256 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003257 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003258 /*
3259 * Write addresses to the MTA, if the attempt fails
3260 * then we should just turn on promiscuous mode so
3261 * that we can at least receive multicast traffic
3262 */
3263 count = e1000e_write_mc_addr_list(netdev);
3264 if (count < 0)
3265 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003266 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003267 e1000e_vlan_filter_enable(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003268 /*
3269 * Write addresses to available RAR registers, if there is not
3270 * sufficient space to store all the addresses then enable
3271 * unicast promiscuous mode
3272 */
3273 count = e1000e_write_uc_addr_list(netdev);
3274 if (count < 0)
3275 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003276 }
3277
3278 ew32(RCTL, rctl);
3279
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003280 if (netdev->features & NETIF_F_HW_VLAN_RX)
3281 e1000e_vlan_strip_enable(adapter);
3282 else
3283 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003284}
3285
Bruce Allan70495a52012-01-11 01:26:50 +00003286static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3287{
3288 struct e1000_hw *hw = &adapter->hw;
3289 u32 mrqc, rxcsum;
3290 int i;
3291 static const u32 rsskey[10] = {
3292 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3293 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3294 };
3295
3296 /* Fill out hash function seed */
3297 for (i = 0; i < 10; i++)
3298 ew32(RSSRK(i), rsskey[i]);
3299
3300 /* Direct all traffic to queue 0 */
3301 for (i = 0; i < 32; i++)
3302 ew32(RETA(i), 0);
3303
3304 /*
3305 * Disable raw packet checksumming so that RSS hash is placed in
3306 * descriptor on writeback.
3307 */
3308 rxcsum = er32(RXCSUM);
3309 rxcsum |= E1000_RXCSUM_PCSD;
3310
3311 ew32(RXCSUM, rxcsum);
3312
3313 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3314 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3315 E1000_MRQC_RSS_FIELD_IPV6 |
3316 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3317 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3318
3319 ew32(MRQC, mrqc);
3320}
3321
Auke Kokbc7f75f2007-09-17 12:30:59 -07003322/**
Bruce Allanad680762008-03-28 09:15:03 -07003323 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003324 * @adapter: private board structure
3325 **/
3326static void e1000_configure(struct e1000_adapter *adapter)
3327{
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003328 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003329
3330 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003331 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003332
3333 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003334
3335 if (adapter->netdev->features & NETIF_F_RXHASH)
3336 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003337 e1000_setup_rctl(adapter);
3338 e1000_configure_rx(adapter);
Jeff Kirsherc2fed992011-07-12 16:10:12 +00003339 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring),
3340 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003341}
3342
3343/**
3344 * e1000e_power_up_phy - restore link in case the phy was powered down
3345 * @adapter: address of board private structure
3346 *
3347 * The phy may be powered down to save power and turn off link when the
3348 * driver is unloaded and wake on lan is not enabled (among others)
3349 * *** this routine MUST be followed by a call to e1000e_reset ***
3350 **/
3351void e1000e_power_up_phy(struct e1000_adapter *adapter)
3352{
Bruce Allan17f208d2009-12-01 15:47:22 +00003353 if (adapter->hw.phy.ops.power_up)
3354 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003355
3356 adapter->hw.mac.ops.setup_link(&adapter->hw);
3357}
3358
3359/**
3360 * e1000_power_down_phy - Power down the PHY
3361 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003362 * Power down the PHY so no link is implied when interface is down.
3363 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003364 */
3365static void e1000_power_down_phy(struct e1000_adapter *adapter)
3366{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003367 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003368 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003369 return;
3370
Bruce Allan17f208d2009-12-01 15:47:22 +00003371 if (adapter->hw.phy.ops.power_down)
3372 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003373}
3374
3375/**
3376 * e1000e_reset - bring the hardware into a known good state
3377 *
3378 * This function boots the hardware and enables some settings that
3379 * require a configuration cycle of the hardware - those cannot be
3380 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003381 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003382 */
3383void e1000e_reset(struct e1000_adapter *adapter)
3384{
3385 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003386 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003387 struct e1000_hw *hw = &adapter->hw;
3388 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003389 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003390 u16 hwm;
3391
Bruce Allanad680762008-03-28 09:15:03 -07003392 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003393 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003394
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003395 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003396 /*
3397 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003398 * large enough to accommodate two full transmit packets,
3399 * rounded up to the next 1KB and expressed in KB. Likewise,
3400 * the Rx FIFO should be large enough to accommodate at least
3401 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003402 * expressed in KB.
3403 */
Auke Kokdf762462007-10-25 13:57:53 -07003404 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003405 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003406 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003407 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003408 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003409 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003410 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003411 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003412 */
3413 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003414 sizeof(struct e1000_tx_desc) -
3415 ETH_FCS_LEN) * 2;
3416 min_tx_space = ALIGN(min_tx_space, 1024);
3417 min_tx_space >>= 10;
3418 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003419 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003420 min_rx_space = ALIGN(min_rx_space, 1024);
3421 min_rx_space >>= 10;
3422
Bruce Allanad680762008-03-28 09:15:03 -07003423 /*
3424 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003425 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003426 * allocation, take space away from current Rx allocation
3427 */
Auke Kokdf762462007-10-25 13:57:53 -07003428 if ((tx_space < min_tx_space) &&
3429 ((min_tx_space - tx_space) < pba)) {
3430 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003431
Bruce Allanad680762008-03-28 09:15:03 -07003432 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003433 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003434 * adjustment or use Early Receive if available
3435 */
Auke Kokdf762462007-10-25 13:57:53 -07003436 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003437 (!(adapter->flags & FLAG_HAS_ERT)))
3438 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003439 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003440 }
Auke Kokdf762462007-10-25 13:57:53 -07003441
3442 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003443 }
3444
Bruce Allanad680762008-03-28 09:15:03 -07003445 /*
3446 * flow control settings
3447 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003448 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003449 * (or the size used for early receive) above it in the Rx FIFO.
3450 * Set it to the lower of:
3451 * - 90% of the Rx FIFO size, and
3452 * - the full Rx FIFO size minus the early receive size (for parts
3453 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003454 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003455 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003456 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3457 fc->pause_time = 0xFFFF;
3458 else
3459 fc->pause_time = E1000_FC_PAUSE_TIME;
3460 fc->send_xon = 1;
3461 fc->current_mode = fc->requested_mode;
3462
3463 switch (hw->mac.type) {
3464 default:
3465 if ((adapter->flags & FLAG_HAS_ERT) &&
3466 (adapter->netdev->mtu > ETH_DATA_LEN))
3467 hwm = min(((pba << 10) * 9 / 10),
3468 ((pba << 10) - (E1000_ERT_2048 << 3)));
3469 else
3470 hwm = min(((pba << 10) * 9 / 10),
3471 ((pba << 10) - adapter->max_frame_size));
3472
3473 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3474 fc->low_water = fc->high_water - 8;
3475 break;
3476 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003477 /*
3478 * Workaround PCH LOM adapter hangs with certain network
3479 * loads. If hangs persist, try disabling Tx flow control.
3480 */
3481 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3482 fc->high_water = 0x3500;
3483 fc->low_water = 0x1500;
3484 } else {
3485 fc->high_water = 0x5000;
3486 fc->low_water = 0x3000;
3487 }
Bruce Allana3055952010-05-10 15:02:12 +00003488 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003489 break;
3490 case e1000_pch2lan:
3491 fc->high_water = 0x05C20;
3492 fc->low_water = 0x05048;
3493 fc->pause_time = 0x0650;
3494 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003495 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3496 pba = 14;
3497 ew32(PBA, pba);
3498 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003499 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003500 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003501
Bruce Allan828bac82010-09-29 21:39:37 +00003502 /*
3503 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3504 * fit in receive buffer and early-receive not supported.
3505 */
3506 if (adapter->itr_setting & 0x3) {
3507 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3508 !(adapter->flags & FLAG_HAS_ERT)) {
3509 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3510 dev_info(&adapter->pdev->dev,
3511 "Interrupt Throttle Rate turned off\n");
3512 adapter->flags2 |= FLAG2_DISABLE_AIM;
3513 ew32(ITR, 0);
3514 }
3515 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3516 dev_info(&adapter->pdev->dev,
3517 "Interrupt Throttle Rate turned on\n");
3518 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3519 adapter->itr = 20000;
3520 ew32(ITR, 1000000000 / (adapter->itr * 256));
3521 }
3522 }
3523
Auke Kokbc7f75f2007-09-17 12:30:59 -07003524 /* Allow time for pending master requests to run */
3525 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003526
3527 /*
3528 * For parts with AMT enabled, let the firmware know
3529 * that the network interface is in control
3530 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003531 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003532 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003533
Auke Kokbc7f75f2007-09-17 12:30:59 -07003534 ew32(WUC, 0);
3535
3536 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003537 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003538
3539 e1000_update_mng_vlan(adapter);
3540
3541 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3542 ew32(VET, ETH_P_8021Q);
3543
3544 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003545
3546 if (!netif_running(adapter->netdev) &&
3547 !test_bit(__E1000_TESTING, &adapter->state)) {
3548 e1000_power_down_phy(adapter);
3549 return;
3550 }
3551
Auke Kokbc7f75f2007-09-17 12:30:59 -07003552 e1000_get_phy_info(hw);
3553
Bruce Allan918d7192009-06-02 11:28:20 +00003554 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3555 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003556 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003557 /*
3558 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003559 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003560 * different we would do if it failed
3561 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003562 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3563 phy_data &= ~IGP02E1000_PM_SPD;
3564 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3565 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003566}
3567
3568int e1000e_up(struct e1000_adapter *adapter)
3569{
3570 struct e1000_hw *hw = &adapter->hw;
3571
3572 /* hardware has been reset, we need to reload some things */
3573 e1000_configure(adapter);
3574
3575 clear_bit(__E1000_DOWN, &adapter->state);
3576
Bruce Allan4662e822008-08-26 18:37:06 -07003577 if (adapter->msix_entries)
3578 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003579 e1000_irq_enable(adapter);
3580
Bruce Allan400484f2011-05-13 07:20:03 +00003581 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003582
Auke Kokbc7f75f2007-09-17 12:30:59 -07003583 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003584 if (adapter->msix_entries)
3585 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3586 else
3587 ew32(ICS, E1000_ICS_LSC);
3588
Auke Kokbc7f75f2007-09-17 12:30:59 -07003589 return 0;
3590}
3591
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003592static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3593{
3594 struct e1000_hw *hw = &adapter->hw;
3595
3596 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3597 return;
3598
3599 /* flush pending descriptor writebacks to memory */
3600 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3601 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3602
3603 /* execute the writes immediately */
3604 e1e_flush();
3605}
3606
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003607static void e1000e_update_stats(struct e1000_adapter *adapter);
3608
Auke Kokbc7f75f2007-09-17 12:30:59 -07003609void e1000e_down(struct e1000_adapter *adapter)
3610{
3611 struct net_device *netdev = adapter->netdev;
3612 struct e1000_hw *hw = &adapter->hw;
3613 u32 tctl, rctl;
3614
Bruce Allanad680762008-03-28 09:15:03 -07003615 /*
3616 * signal that we're down so the interrupt handler does not
3617 * reschedule our watchdog timer
3618 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003619 set_bit(__E1000_DOWN, &adapter->state);
3620
3621 /* disable receives in the hardware */
3622 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003623 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3624 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003625 /* flush and sleep below */
3626
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003627 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003628
3629 /* disable transmits in the hardware */
3630 tctl = er32(TCTL);
3631 tctl &= ~E1000_TCTL_EN;
3632 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003633
Auke Kokbc7f75f2007-09-17 12:30:59 -07003634 /* flush both disables and wait for them to finish */
3635 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003636 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003637
Auke Kokbc7f75f2007-09-17 12:30:59 -07003638 e1000_irq_disable(adapter);
3639
3640 del_timer_sync(&adapter->watchdog_timer);
3641 del_timer_sync(&adapter->phy_info_timer);
3642
Auke Kokbc7f75f2007-09-17 12:30:59 -07003643 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003644
3645 spin_lock(&adapter->stats64_lock);
3646 e1000e_update_stats(adapter);
3647 spin_unlock(&adapter->stats64_lock);
3648
Bruce Allan400484f2011-05-13 07:20:03 +00003649 e1000e_flush_descriptors(adapter);
3650 e1000_clean_tx_ring(adapter);
3651 e1000_clean_rx_ring(adapter);
3652
Auke Kokbc7f75f2007-09-17 12:30:59 -07003653 adapter->link_speed = 0;
3654 adapter->link_duplex = 0;
3655
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003656 if (!pci_channel_offline(adapter->pdev))
3657 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003658
Auke Kokbc7f75f2007-09-17 12:30:59 -07003659 /*
3660 * TODO: for power management, we could drop the link and
3661 * pci_disable_device here.
3662 */
3663}
3664
3665void e1000e_reinit_locked(struct e1000_adapter *adapter)
3666{
3667 might_sleep();
3668 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003669 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003670 e1000e_down(adapter);
3671 e1000e_up(adapter);
3672 clear_bit(__E1000_RESETTING, &adapter->state);
3673}
3674
3675/**
3676 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3677 * @adapter: board private structure to initialize
3678 *
3679 * e1000_sw_init initializes the Adapter private data structure.
3680 * Fields are initialized based on PCI device information and
3681 * OS network device settings (MTU size).
3682 **/
3683static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3684{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003685 struct net_device *netdev = adapter->netdev;
3686
3687 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3688 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003689 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3690 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003692 spin_lock_init(&adapter->stats64_lock);
3693
Bruce Allan4662e822008-08-26 18:37:06 -07003694 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003695
Bruce Allan4662e822008-08-26 18:37:06 -07003696 if (e1000_alloc_queues(adapter))
3697 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003698
Auke Kokbc7f75f2007-09-17 12:30:59 -07003699 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003700 e1000_irq_disable(adapter);
3701
Auke Kokbc7f75f2007-09-17 12:30:59 -07003702 set_bit(__E1000_DOWN, &adapter->state);
3703 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003704}
3705
3706/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003707 * e1000_intr_msi_test - Interrupt Handler
3708 * @irq: interrupt number
3709 * @data: pointer to a network interface device structure
3710 **/
3711static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3712{
3713 struct net_device *netdev = data;
3714 struct e1000_adapter *adapter = netdev_priv(netdev);
3715 struct e1000_hw *hw = &adapter->hw;
3716 u32 icr = er32(ICR);
3717
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003718 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003719 if (icr & E1000_ICR_RXSEQ) {
3720 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3721 wmb();
3722 }
3723
3724 return IRQ_HANDLED;
3725}
3726
3727/**
3728 * e1000_test_msi_interrupt - Returns 0 for successful test
3729 * @adapter: board private struct
3730 *
3731 * code flow taken from tg3.c
3732 **/
3733static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3734{
3735 struct net_device *netdev = adapter->netdev;
3736 struct e1000_hw *hw = &adapter->hw;
3737 int err;
3738
3739 /* poll_enable hasn't been called yet, so don't need disable */
3740 /* clear any pending events */
3741 er32(ICR);
3742
3743 /* free the real vector and request a test handler */
3744 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003745 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003746
3747 /* Assume that the test fails, if it succeeds then the test
3748 * MSI irq handler will unset this flag */
3749 adapter->flags |= FLAG_MSI_TEST_FAILED;
3750
3751 err = pci_enable_msi(adapter->pdev);
3752 if (err)
3753 goto msi_test_failed;
3754
Joe Perchesa0607fd2009-11-18 23:29:17 -08003755 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003756 netdev->name, netdev);
3757 if (err) {
3758 pci_disable_msi(adapter->pdev);
3759 goto msi_test_failed;
3760 }
3761
3762 wmb();
3763
3764 e1000_irq_enable(adapter);
3765
3766 /* fire an unusual interrupt on the test handler */
3767 ew32(ICS, E1000_ICS_RXSEQ);
3768 e1e_flush();
3769 msleep(50);
3770
3771 e1000_irq_disable(adapter);
3772
3773 rmb();
3774
3775 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003776 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003777 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3778 } else
3779 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003780
3781 free_irq(adapter->pdev->irq, netdev);
3782 pci_disable_msi(adapter->pdev);
3783
Bruce Allanf8d59f72008-08-08 18:36:11 -07003784msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003785 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003786 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003787}
3788
3789/**
3790 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3791 * @adapter: board private struct
3792 *
3793 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3794 **/
3795static int e1000_test_msi(struct e1000_adapter *adapter)
3796{
3797 int err;
3798 u16 pci_cmd;
3799
3800 if (!(adapter->flags & FLAG_MSI_ENABLED))
3801 return 0;
3802
3803 /* disable SERR in case the MSI write causes a master abort */
3804 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003805 if (pci_cmd & PCI_COMMAND_SERR)
3806 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3807 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003808
3809 err = e1000_test_msi_interrupt(adapter);
3810
Dean Nelson36f24072010-06-29 18:12:05 +00003811 /* re-enable SERR */
3812 if (pci_cmd & PCI_COMMAND_SERR) {
3813 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3814 pci_cmd |= PCI_COMMAND_SERR;
3815 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3816 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003817
Bruce Allanf8d59f72008-08-08 18:36:11 -07003818 return err;
3819}
3820
3821/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003822 * e1000_open - Called when a network interface is made active
3823 * @netdev: network interface device structure
3824 *
3825 * Returns 0 on success, negative value on failure
3826 *
3827 * The open entry point is called when a network interface is made
3828 * active by the system (IFF_UP). At this point all resources needed
3829 * for transmit and receive operations are allocated, the interrupt
3830 * handler is registered with the OS, the watchdog timer is started,
3831 * and the stack is notified that the interface is ready.
3832 **/
3833static int e1000_open(struct net_device *netdev)
3834{
3835 struct e1000_adapter *adapter = netdev_priv(netdev);
3836 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003837 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003838 int err;
3839
3840 /* disallow open during test */
3841 if (test_bit(__E1000_TESTING, &adapter->state))
3842 return -EBUSY;
3843
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003844 pm_runtime_get_sync(&pdev->dev);
3845
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003846 netif_carrier_off(netdev);
3847
Auke Kokbc7f75f2007-09-17 12:30:59 -07003848 /* allocate transmit descriptors */
3849 err = e1000e_setup_tx_resources(adapter);
3850 if (err)
3851 goto err_setup_tx;
3852
3853 /* allocate receive descriptors */
3854 err = e1000e_setup_rx_resources(adapter);
3855 if (err)
3856 goto err_setup_rx;
3857
Bruce Allan11b08be2010-05-10 14:59:31 +00003858 /*
3859 * If AMT is enabled, let the firmware know that the network
3860 * interface is now open and reset the part to a known state.
3861 */
3862 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003863 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003864 e1000e_reset(adapter);
3865 }
3866
Auke Kokbc7f75f2007-09-17 12:30:59 -07003867 e1000e_power_up_phy(adapter);
3868
3869 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3870 if ((adapter->hw.mng_cookie.status &
3871 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3872 e1000_update_mng_vlan(adapter);
3873
Florian Micklerc128ec22010-08-02 14:27:00 +00003874 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003875 if ((adapter->flags & FLAG_HAS_ERT) ||
3876 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003877 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3878 PM_QOS_CPU_DMA_LATENCY,
3879 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003880
Bruce Allanad680762008-03-28 09:15:03 -07003881 /*
Bruce Allanad680762008-03-28 09:15:03 -07003882 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003883 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3884 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003885 * clean_rx handler before we do so.
3886 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003887 e1000_configure(adapter);
3888
3889 err = e1000_request_irq(adapter);
3890 if (err)
3891 goto err_req_irq;
3892
Bruce Allanf8d59f72008-08-08 18:36:11 -07003893 /*
3894 * Work around PCIe errata with MSI interrupts causing some chipsets to
3895 * ignore e1000e MSI messages, which means we need to test our MSI
3896 * interrupt now
3897 */
Bruce Allan4662e822008-08-26 18:37:06 -07003898 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003899 err = e1000_test_msi(adapter);
3900 if (err) {
3901 e_err("Interrupt allocation failed\n");
3902 goto err_req_irq;
3903 }
3904 }
3905
Auke Kokbc7f75f2007-09-17 12:30:59 -07003906 /* From here on the code is the same as e1000e_up() */
3907 clear_bit(__E1000_DOWN, &adapter->state);
3908
3909 napi_enable(&adapter->napi);
3910
3911 e1000_irq_enable(adapter);
3912
Jeff Kirsher09357b02011-11-18 14:25:00 +00003913 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003914 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003915
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003916 adapter->idle_check = true;
3917 pm_runtime_put(&pdev->dev);
3918
Auke Kokbc7f75f2007-09-17 12:30:59 -07003919 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003920 if (adapter->msix_entries)
3921 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3922 else
3923 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003924
3925 return 0;
3926
3927err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003928 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003929 e1000_power_down_phy(adapter);
3930 e1000e_free_rx_resources(adapter);
3931err_setup_rx:
3932 e1000e_free_tx_resources(adapter);
3933err_setup_tx:
3934 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003935 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003936
3937 return err;
3938}
3939
3940/**
3941 * e1000_close - Disables a network interface
3942 * @netdev: network interface device structure
3943 *
3944 * Returns 0, this is not allowed to fail
3945 *
3946 * The close entry point is called when an interface is de-activated
3947 * by the OS. The hardware is still under the drivers control, but
3948 * needs to be disabled. A global MAC reset is issued to stop the
3949 * hardware, and all transmit and receive resources are freed.
3950 **/
3951static int e1000_close(struct net_device *netdev)
3952{
3953 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003954 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003955
3956 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003957
3958 pm_runtime_get_sync(&pdev->dev);
3959
Bruce Allan5f4a7802011-11-29 08:09:19 +00003960 napi_disable(&adapter->napi);
3961
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003962 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3963 e1000e_down(adapter);
3964 e1000_free_irq(adapter);
3965 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003966 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003967
3968 e1000e_free_tx_resources(adapter);
3969 e1000e_free_rx_resources(adapter);
3970
Bruce Allanad680762008-03-28 09:15:03 -07003971 /*
3972 * kill manageability vlan ID if supported, but not if a vlan with
3973 * the same ID is registered on the host OS (let 8021q kill it)
3974 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003975 if (adapter->hw.mng_cookie.status &
3976 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003977 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3978
Bruce Allanad680762008-03-28 09:15:03 -07003979 /*
3980 * If AMT is enabled, let the firmware know that the network
3981 * interface is now closed
3982 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003983 if ((adapter->flags & FLAG_HAS_AMT) &&
3984 !test_bit(__E1000_TESTING, &adapter->state))
3985 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003986
Bruce Allan828bac82010-09-29 21:39:37 +00003987 if ((adapter->flags & FLAG_HAS_ERT) ||
3988 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003989 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003990
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003991 pm_runtime_put_sync(&pdev->dev);
3992
Auke Kokbc7f75f2007-09-17 12:30:59 -07003993 return 0;
3994}
3995/**
3996 * e1000_set_mac - Change the Ethernet Address of the NIC
3997 * @netdev: network interface device structure
3998 * @p: pointer to an address structure
3999 *
4000 * Returns 0 on success, negative on failure
4001 **/
4002static int e1000_set_mac(struct net_device *netdev, void *p)
4003{
4004 struct e1000_adapter *adapter = netdev_priv(netdev);
4005 struct sockaddr *addr = p;
4006
4007 if (!is_valid_ether_addr(addr->sa_data))
4008 return -EADDRNOTAVAIL;
4009
4010 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4011 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4012
4013 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
4014
4015 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4016 /* activate the work around */
4017 e1000e_set_laa_state_82571(&adapter->hw, 1);
4018
Bruce Allanad680762008-03-28 09:15:03 -07004019 /*
4020 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004021 * between the time RAR[0] gets clobbered and the time it
4022 * gets fixed (in e1000_watchdog), the actual LAA is in one
4023 * of the RARs and no incoming packets directed to this port
4024 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004025 * RAR[14]
4026 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004027 e1000e_rar_set(&adapter->hw,
4028 adapter->hw.mac.addr,
4029 adapter->hw.mac.rar_entry_count - 1);
4030 }
4031
4032 return 0;
4033}
4034
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004035/**
4036 * e1000e_update_phy_task - work thread to update phy
4037 * @work: pointer to our work struct
4038 *
4039 * this worker thread exists because we must acquire a
4040 * semaphore to read the phy, which we could msleep while
4041 * waiting for it, and we can't msleep in a timer.
4042 **/
4043static void e1000e_update_phy_task(struct work_struct *work)
4044{
4045 struct e1000_adapter *adapter = container_of(work,
4046 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004047
4048 if (test_bit(__E1000_DOWN, &adapter->state))
4049 return;
4050
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004051 e1000_get_phy_info(&adapter->hw);
4052}
4053
Bruce Allanad680762008-03-28 09:15:03 -07004054/*
4055 * Need to wait a few seconds after link up to get diagnostic information from
4056 * the phy
4057 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004058static void e1000_update_phy_info(unsigned long data)
4059{
4060 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004061
4062 if (test_bit(__E1000_DOWN, &adapter->state))
4063 return;
4064
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004065 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004066}
4067
4068/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004069 * e1000e_update_phy_stats - Update the PHY statistics counters
4070 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004071 *
4072 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004073 **/
4074static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4075{
4076 struct e1000_hw *hw = &adapter->hw;
4077 s32 ret_val;
4078 u16 phy_data;
4079
4080 ret_val = hw->phy.ops.acquire(hw);
4081 if (ret_val)
4082 return;
4083
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004084 /*
4085 * A page set is expensive so check if already on desired page.
4086 * If not, set to the page with the PHY status registers.
4087 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004088 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004089 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4090 &phy_data);
4091 if (ret_val)
4092 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004093 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4094 ret_val = hw->phy.ops.set_page(hw,
4095 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004096 if (ret_val)
4097 goto release;
4098 }
4099
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004100 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004101 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4102 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004103 if (!ret_val)
4104 adapter->stats.scc += phy_data;
4105
4106 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004107 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4108 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004109 if (!ret_val)
4110 adapter->stats.ecol += phy_data;
4111
4112 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004113 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4114 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004115 if (!ret_val)
4116 adapter->stats.mcc += phy_data;
4117
4118 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004119 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4120 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004121 if (!ret_val)
4122 adapter->stats.latecol += phy_data;
4123
4124 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004125 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4126 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004127 if (!ret_val)
4128 hw->mac.collision_delta = phy_data;
4129
4130 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004131 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4132 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004133 if (!ret_val)
4134 adapter->stats.dc += phy_data;
4135
4136 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004137 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4138 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004139 if (!ret_val)
4140 adapter->stats.tncrs += phy_data;
4141
4142release:
4143 hw->phy.ops.release(hw);
4144}
4145
4146/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004147 * e1000e_update_stats - Update the board statistics counters
4148 * @adapter: board private structure
4149 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004150static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004151{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004152 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004153 struct e1000_hw *hw = &adapter->hw;
4154 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004155
4156 /*
4157 * Prevent stats update while adapter is being reset, or if the pci
4158 * connection is down.
4159 */
4160 if (adapter->link_speed == 0)
4161 return;
4162 if (pci_channel_offline(pdev))
4163 return;
4164
Auke Kokbc7f75f2007-09-17 12:30:59 -07004165 adapter->stats.crcerrs += er32(CRCERRS);
4166 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004167 adapter->stats.gorc += er32(GORCL);
4168 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004169 adapter->stats.bprc += er32(BPRC);
4170 adapter->stats.mprc += er32(MPRC);
4171 adapter->stats.roc += er32(ROC);
4172
Auke Kokbc7f75f2007-09-17 12:30:59 -07004173 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004174
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004175 /* Half-duplex statistics */
4176 if (adapter->link_duplex == HALF_DUPLEX) {
4177 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4178 e1000e_update_phy_stats(adapter);
4179 } else {
4180 adapter->stats.scc += er32(SCC);
4181 adapter->stats.ecol += er32(ECOL);
4182 adapter->stats.mcc += er32(MCC);
4183 adapter->stats.latecol += er32(LATECOL);
4184 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004185
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004186 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004187
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004188 if ((hw->mac.type != e1000_82574) &&
4189 (hw->mac.type != e1000_82583))
4190 adapter->stats.tncrs += er32(TNCRS);
4191 }
4192 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004193 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004194
Auke Kokbc7f75f2007-09-17 12:30:59 -07004195 adapter->stats.xonrxc += er32(XONRXC);
4196 adapter->stats.xontxc += er32(XONTXC);
4197 adapter->stats.xoffrxc += er32(XOFFRXC);
4198 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004199 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004200 adapter->stats.gotc += er32(GOTCL);
4201 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004202 adapter->stats.rnbc += er32(RNBC);
4203 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004204
4205 adapter->stats.mptc += er32(MPTC);
4206 adapter->stats.bptc += er32(BPTC);
4207
4208 /* used for adaptive IFS */
4209
4210 hw->mac.tx_packet_delta = er32(TPT);
4211 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004212
4213 adapter->stats.algnerrc += er32(ALGNERRC);
4214 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004215 adapter->stats.cexterr += er32(CEXTERR);
4216 adapter->stats.tsctc += er32(TSCTC);
4217 adapter->stats.tsctfc += er32(TSCTFC);
4218
Auke Kokbc7f75f2007-09-17 12:30:59 -07004219 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004220 netdev->stats.multicast = adapter->stats.mprc;
4221 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222
4223 /* Rx Errors */
4224
Bruce Allanad680762008-03-28 09:15:03 -07004225 /*
4226 * RLEC on some newer hardware can be incorrect so build
4227 * our own version based on RUC and ROC
4228 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004229 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004230 adapter->stats.crcerrs + adapter->stats.algnerrc +
4231 adapter->stats.ruc + adapter->stats.roc +
4232 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004233 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004234 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004235 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4236 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4237 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004238
4239 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004240 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004241 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004242 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4243 netdev->stats.tx_window_errors = adapter->stats.latecol;
4244 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004245
4246 /* Tx Dropped needs to be maintained elsewhere */
4247
Auke Kokbc7f75f2007-09-17 12:30:59 -07004248 /* Management Stats */
4249 adapter->stats.mgptc += er32(MGTPTC);
4250 adapter->stats.mgprc += er32(MGTPRC);
4251 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004252}
4253
Bruce Allan7c257692008-04-23 11:09:00 -07004254/**
4255 * e1000_phy_read_status - Update the PHY register status snapshot
4256 * @adapter: board private structure
4257 **/
4258static void e1000_phy_read_status(struct e1000_adapter *adapter)
4259{
4260 struct e1000_hw *hw = &adapter->hw;
4261 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004262
4263 if ((er32(STATUS) & E1000_STATUS_LU) &&
4264 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004265 int ret_val;
4266
Bruce Allan7c257692008-04-23 11:09:00 -07004267 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4268 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4269 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4270 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4271 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4272 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4273 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4274 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4275 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004276 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004277 } else {
4278 /*
4279 * Do not read PHY registers if link is not up
4280 * Set values to typical power-on defaults
4281 */
4282 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4283 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4284 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4285 BMSR_ERCAP);
4286 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4287 ADVERTISE_ALL | ADVERTISE_CSMA);
4288 phy->lpa = 0;
4289 phy->expansion = EXPANSION_ENABLENPAGE;
4290 phy->ctrl1000 = ADVERTISE_1000FULL;
4291 phy->stat1000 = 0;
4292 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4293 }
Bruce Allan7c257692008-04-23 11:09:00 -07004294}
4295
Auke Kokbc7f75f2007-09-17 12:30:59 -07004296static void e1000_print_link_info(struct e1000_adapter *adapter)
4297{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004298 struct e1000_hw *hw = &adapter->hw;
4299 u32 ctrl = er32(CTRL);
4300
Bruce Allan8f12fe82008-11-21 16:54:43 -08004301 /* Link status message must follow this format for user tools */
Jeff Kirsheref456f82011-11-03 11:40:28 +00004302 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4303 adapter->netdev->name,
4304 adapter->link_speed,
4305 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4306 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4307 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4308 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004309}
4310
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004311static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004312{
4313 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004314 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004315 s32 ret_val = 0;
4316
4317 /*
4318 * get_link_status is set on LSC (link status) interrupt or
4319 * Rx sequence error interrupt. get_link_status will stay
4320 * false until the check_for_link establishes link
4321 * for copper adapters ONLY
4322 */
4323 switch (hw->phy.media_type) {
4324 case e1000_media_type_copper:
4325 if (hw->mac.get_link_status) {
4326 ret_val = hw->mac.ops.check_for_link(hw);
4327 link_active = !hw->mac.get_link_status;
4328 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004329 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004330 }
4331 break;
4332 case e1000_media_type_fiber:
4333 ret_val = hw->mac.ops.check_for_link(hw);
4334 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4335 break;
4336 case e1000_media_type_internal_serdes:
4337 ret_val = hw->mac.ops.check_for_link(hw);
4338 link_active = adapter->hw.mac.serdes_has_link;
4339 break;
4340 default:
4341 case e1000_media_type_unknown:
4342 break;
4343 }
4344
4345 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4346 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4347 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004348 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004349 }
4350
4351 return link_active;
4352}
4353
4354static void e1000e_enable_receives(struct e1000_adapter *adapter)
4355{
4356 /* make sure the receive unit is started */
4357 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4358 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4359 struct e1000_hw *hw = &adapter->hw;
4360 u32 rctl = er32(RCTL);
4361 ew32(RCTL, rctl | E1000_RCTL_EN);
4362 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4363 }
4364}
4365
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004366static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4367{
4368 struct e1000_hw *hw = &adapter->hw;
4369
4370 /*
4371 * With 82574 controllers, PHY needs to be checked periodically
4372 * for hung state and reset, if two calls return true
4373 */
4374 if (e1000_check_phy_82574(hw))
4375 adapter->phy_hang_count++;
4376 else
4377 adapter->phy_hang_count = 0;
4378
4379 if (adapter->phy_hang_count > 1) {
4380 adapter->phy_hang_count = 0;
4381 schedule_work(&adapter->reset_task);
4382 }
4383}
4384
Auke Kokbc7f75f2007-09-17 12:30:59 -07004385/**
4386 * e1000_watchdog - Timer Call-back
4387 * @data: pointer to adapter cast into an unsigned long
4388 **/
4389static void e1000_watchdog(unsigned long data)
4390{
4391 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4392
4393 /* Do the rest outside of interrupt context */
4394 schedule_work(&adapter->watchdog_task);
4395
4396 /* TODO: make this use queue_delayed_work() */
4397}
4398
4399static void e1000_watchdog_task(struct work_struct *work)
4400{
4401 struct e1000_adapter *adapter = container_of(work,
4402 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004403 struct net_device *netdev = adapter->netdev;
4404 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004405 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004406 struct e1000_ring *tx_ring = adapter->tx_ring;
4407 struct e1000_hw *hw = &adapter->hw;
4408 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004409
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004410 if (test_bit(__E1000_DOWN, &adapter->state))
4411 return;
4412
David S. Millerb405e8d2010-02-04 22:31:41 -08004413 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004414 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004415 /* Cancel scheduled suspend requests. */
4416 pm_runtime_resume(netdev->dev.parent);
4417
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004418 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004419 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004420 }
4421
4422 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4423 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4424 e1000_update_mng_vlan(adapter);
4425
Auke Kokbc7f75f2007-09-17 12:30:59 -07004426 if (link) {
4427 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004428 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004429
4430 /* Cancel scheduled suspend requests. */
4431 pm_runtime_resume(netdev->dev.parent);
4432
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004433 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004434 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004435 mac->ops.get_link_up_info(&adapter->hw,
4436 &adapter->link_speed,
4437 &adapter->link_duplex);
4438 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004439 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004440 * On supported PHYs, check for duplex mismatch only
4441 * if link has autonegotiated at 10/100 half
4442 */
4443 if ((hw->phy.type == e1000_phy_igp_3 ||
4444 hw->phy.type == e1000_phy_bm) &&
4445 (hw->mac.autoneg == true) &&
4446 (adapter->link_speed == SPEED_10 ||
4447 adapter->link_speed == SPEED_100) &&
4448 (adapter->link_duplex == HALF_DUPLEX)) {
4449 u16 autoneg_exp;
4450
4451 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4452
4453 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004454 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 -07004455 }
4456
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004457 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004458 adapter->tx_timeout_factor = 1;
4459 switch (adapter->link_speed) {
4460 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004461 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004462 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004463 break;
4464 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004465 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004466 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004467 break;
4468 }
4469
Bruce Allanad680762008-03-28 09:15:03 -07004470 /*
4471 * workaround: re-program speed mode bit after
4472 * link-up event
4473 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004474 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4475 !txb2b) {
4476 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004477 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004478 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004479 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004480 }
4481
Bruce Allanad680762008-03-28 09:15:03 -07004482 /*
4483 * disable TSO for pcie and 10/100 speeds, to avoid
4484 * some hardware issues
4485 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004486 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4487 switch (adapter->link_speed) {
4488 case SPEED_10:
4489 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004490 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004491 netdev->features &= ~NETIF_F_TSO;
4492 netdev->features &= ~NETIF_F_TSO6;
4493 break;
4494 case SPEED_1000:
4495 netdev->features |= NETIF_F_TSO;
4496 netdev->features |= NETIF_F_TSO6;
4497 break;
4498 default:
4499 /* oops */
4500 break;
4501 }
4502 }
4503
Bruce Allanad680762008-03-28 09:15:03 -07004504 /*
4505 * enable transmits in the hardware, need to do this
4506 * after setting TARC(0)
4507 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004508 tctl = er32(TCTL);
4509 tctl |= E1000_TCTL_EN;
4510 ew32(TCTL, tctl);
4511
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004512 /*
4513 * Perform any post-link-up configuration before
4514 * reporting link up.
4515 */
4516 if (phy->ops.cfg_on_link_up)
4517 phy->ops.cfg_on_link_up(hw);
4518
Auke Kokbc7f75f2007-09-17 12:30:59 -07004519 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004520
4521 if (!test_bit(__E1000_DOWN, &adapter->state))
4522 mod_timer(&adapter->phy_info_timer,
4523 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004524 }
4525 } else {
4526 if (netif_carrier_ok(netdev)) {
4527 adapter->link_speed = 0;
4528 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004529 /* Link status message must follow this format */
4530 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4531 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004532 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004533 if (!test_bit(__E1000_DOWN, &adapter->state))
4534 mod_timer(&adapter->phy_info_timer,
4535 round_jiffies(jiffies + 2 * HZ));
4536
4537 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4538 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004539 else
4540 pm_schedule_suspend(netdev->dev.parent,
4541 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004542 }
4543 }
4544
4545link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004546 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004547 e1000e_update_stats(adapter);
4548
4549 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4550 adapter->tpt_old = adapter->stats.tpt;
4551 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4552 adapter->colc_old = adapter->stats.colc;
4553
Bruce Allan7c257692008-04-23 11:09:00 -07004554 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4555 adapter->gorc_old = adapter->stats.gorc;
4556 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4557 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004558 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004559
4560 e1000e_update_adaptive(&adapter->hw);
4561
Bruce Allan90da0662011-01-06 07:02:53 +00004562 if (!netif_carrier_ok(netdev) &&
4563 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4564 /*
4565 * We've lost link, so the controller stops DMA,
4566 * but we've got queued Tx work that's never going
4567 * to get done, so reset controller to flush Tx.
4568 * (Do the reset outside of interrupt context).
4569 */
Bruce Allan90da0662011-01-06 07:02:53 +00004570 schedule_work(&adapter->reset_task);
4571 /* return immediately since reset is imminent */
4572 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004573 }
4574
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004575 /* Simple mode for Interrupt Throttle Rate (ITR) */
4576 if (adapter->itr_setting == 4) {
4577 /*
4578 * Symmetric Tx/Rx gets a reduced ITR=2000;
4579 * Total asymmetrical Tx or Rx gets ITR=8000;
4580 * everyone else is between 2000-8000.
4581 */
4582 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4583 u32 dif = (adapter->gotc > adapter->gorc ?
4584 adapter->gotc - adapter->gorc :
4585 adapter->gorc - adapter->gotc) / 10000;
4586 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4587
4588 ew32(ITR, 1000000000 / (itr * 256));
4589 }
4590
Bruce Allanad680762008-03-28 09:15:03 -07004591 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004592 if (adapter->msix_entries)
4593 ew32(ICS, adapter->rx_ring->ims_val);
4594 else
4595 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004596
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004597 /* flush pending descriptors to memory before detecting Tx hang */
4598 e1000e_flush_descriptors(adapter);
4599
Auke Kokbc7f75f2007-09-17 12:30:59 -07004600 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004601 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004602
Bruce Allanad680762008-03-28 09:15:03 -07004603 /*
4604 * With 82571 controllers, LAA may be overwritten due to controller
4605 * reset from the other port. Set the appropriate LAA in RAR[0]
4606 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004607 if (e1000e_get_laa_state_82571(hw))
4608 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4609
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004610 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4611 e1000e_check_82574_phy_workaround(adapter);
4612
Auke Kokbc7f75f2007-09-17 12:30:59 -07004613 /* Reset the timer */
4614 if (!test_bit(__E1000_DOWN, &adapter->state))
4615 mod_timer(&adapter->watchdog_timer,
4616 round_jiffies(jiffies + 2 * HZ));
4617}
4618
4619#define E1000_TX_FLAGS_CSUM 0x00000001
4620#define E1000_TX_FLAGS_VLAN 0x00000002
4621#define E1000_TX_FLAGS_TSO 0x00000004
4622#define E1000_TX_FLAGS_IPV4 0x00000008
4623#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4624#define E1000_TX_FLAGS_VLAN_SHIFT 16
4625
4626static int e1000_tso(struct e1000_adapter *adapter,
4627 struct sk_buff *skb)
4628{
4629 struct e1000_ring *tx_ring = adapter->tx_ring;
4630 struct e1000_context_desc *context_desc;
4631 struct e1000_buffer *buffer_info;
4632 unsigned int i;
4633 u32 cmd_length = 0;
4634 u16 ipcse = 0, tucse, mss;
4635 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004636
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004637 if (!skb_is_gso(skb))
4638 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004639
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004640 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004641 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4642
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004643 if (err)
4644 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004645 }
4646
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004647 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4648 mss = skb_shinfo(skb)->gso_size;
4649 if (skb->protocol == htons(ETH_P_IP)) {
4650 struct iphdr *iph = ip_hdr(skb);
4651 iph->tot_len = 0;
4652 iph->check = 0;
4653 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4654 0, IPPROTO_TCP, 0);
4655 cmd_length = E1000_TXD_CMD_IP;
4656 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004657 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004658 ipv6_hdr(skb)->payload_len = 0;
4659 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4660 &ipv6_hdr(skb)->daddr,
4661 0, IPPROTO_TCP, 0);
4662 ipcse = 0;
4663 }
4664 ipcss = skb_network_offset(skb);
4665 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4666 tucss = skb_transport_offset(skb);
4667 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4668 tucse = 0;
4669
4670 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4671 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4672
4673 i = tx_ring->next_to_use;
4674 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4675 buffer_info = &tx_ring->buffer_info[i];
4676
4677 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4678 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4679 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4680 context_desc->upper_setup.tcp_fields.tucss = tucss;
4681 context_desc->upper_setup.tcp_fields.tucso = tucso;
4682 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4683 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4684 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4685 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4686
4687 buffer_info->time_stamp = jiffies;
4688 buffer_info->next_to_watch = i;
4689
4690 i++;
4691 if (i == tx_ring->count)
4692 i = 0;
4693 tx_ring->next_to_use = i;
4694
4695 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004696}
4697
4698static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4699{
4700 struct e1000_ring *tx_ring = adapter->tx_ring;
4701 struct e1000_context_desc *context_desc;
4702 struct e1000_buffer *buffer_info;
4703 unsigned int i;
4704 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004705 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004706 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004707
Dave Grahamaf807c82008-10-09 14:28:58 -07004708 if (skb->ip_summed != CHECKSUM_PARTIAL)
4709 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004710
Arthur Jones5f66f202009-03-19 01:13:08 +00004711 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4712 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4713 else
4714 protocol = skb->protocol;
4715
Arthur Jones3f518392009-03-20 15:56:35 -07004716 switch (protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08004717 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004718 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4719 cmd_len |= E1000_TXD_CMD_TCP;
4720 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08004721 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004722 /* XXX not handling all IPV6 headers */
4723 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4724 cmd_len |= E1000_TXD_CMD_TCP;
4725 break;
4726 default:
4727 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004728 e_warn("checksum_partial proto=%x!\n",
4729 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004730 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004731 }
4732
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004733 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004734
4735 i = tx_ring->next_to_use;
4736 buffer_info = &tx_ring->buffer_info[i];
4737 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4738
4739 context_desc->lower_setup.ip_config = 0;
4740 context_desc->upper_setup.tcp_fields.tucss = css;
4741 context_desc->upper_setup.tcp_fields.tucso =
4742 css + skb->csum_offset;
4743 context_desc->upper_setup.tcp_fields.tucse = 0;
4744 context_desc->tcp_seg_setup.data = 0;
4745 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4746
4747 buffer_info->time_stamp = jiffies;
4748 buffer_info->next_to_watch = i;
4749
4750 i++;
4751 if (i == tx_ring->count)
4752 i = 0;
4753 tx_ring->next_to_use = i;
4754
4755 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004756}
4757
4758#define E1000_MAX_PER_TXD 8192
4759#define E1000_MAX_TXD_PWR 12
4760
4761static int e1000_tx_map(struct e1000_adapter *adapter,
4762 struct sk_buff *skb, unsigned int first,
4763 unsigned int max_per_txd, unsigned int nr_frags,
4764 unsigned int mss)
4765{
4766 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004767 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004768 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004769 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004770 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004771 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004772
4773 i = tx_ring->next_to_use;
4774
4775 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004776 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004777 size = min(len, max_per_txd);
4778
Auke Kokbc7f75f2007-09-17 12:30:59 -07004779 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004780 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004781 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004782 buffer_info->dma = dma_map_single(&pdev->dev,
4783 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004784 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004785 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004786 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004787 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004788
4789 len -= size;
4790 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004791 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004792
4793 if (len) {
4794 i++;
4795 if (i == tx_ring->count)
4796 i = 0;
4797 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004798 }
4799
4800 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004801 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004802
4803 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004804 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004805 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004806
4807 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004808 i++;
4809 if (i == tx_ring->count)
4810 i = 0;
4811
Auke Kokbc7f75f2007-09-17 12:30:59 -07004812 buffer_info = &tx_ring->buffer_info[i];
4813 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004814
4815 buffer_info->length = size;
4816 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004817 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004818 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4819 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004820 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004821 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004822 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004823
4824 len -= size;
4825 offset += size;
4826 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004827 }
4828 }
4829
Bruce Allanaf667a22010-12-31 06:10:01 +00004830 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004831 /* multiply data chunks by size of headers */
4832 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4833
Auke Kokbc7f75f2007-09-17 12:30:59 -07004834 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004835 tx_ring->buffer_info[i].segs = segs;
4836 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004837 tx_ring->buffer_info[first].next_to_watch = i;
4838
4839 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004840
4841dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004842 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004843 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004844 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004845 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004846
4847 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004848 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004849 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004850 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004851 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004852 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004853 }
4854
4855 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004856}
4857
4858static void e1000_tx_queue(struct e1000_adapter *adapter,
4859 int tx_flags, int count)
4860{
4861 struct e1000_ring *tx_ring = adapter->tx_ring;
4862 struct e1000_tx_desc *tx_desc = NULL;
4863 struct e1000_buffer *buffer_info;
4864 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4865 unsigned int i;
4866
4867 if (tx_flags & E1000_TX_FLAGS_TSO) {
4868 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4869 E1000_TXD_CMD_TSE;
4870 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4871
4872 if (tx_flags & E1000_TX_FLAGS_IPV4)
4873 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4874 }
4875
4876 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4877 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4878 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4879 }
4880
4881 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4882 txd_lower |= E1000_TXD_CMD_VLE;
4883 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4884 }
4885
4886 i = tx_ring->next_to_use;
4887
Bruce Allan36b973d2010-11-24 07:42:43 +00004888 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004889 buffer_info = &tx_ring->buffer_info[i];
4890 tx_desc = E1000_TX_DESC(*tx_ring, i);
4891 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4892 tx_desc->lower.data =
4893 cpu_to_le32(txd_lower | buffer_info->length);
4894 tx_desc->upper.data = cpu_to_le32(txd_upper);
4895
4896 i++;
4897 if (i == tx_ring->count)
4898 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004899 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004900
4901 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4902
Bruce Allanad680762008-03-28 09:15:03 -07004903 /*
4904 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004905 * know there are new descriptors to fetch. (Only
4906 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004907 * such as IA-64).
4908 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004909 wmb();
4910
4911 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004912
4913 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4914 e1000e_update_tdt_wa(adapter, i);
4915 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00004916 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07004917
Bruce Allanad680762008-03-28 09:15:03 -07004918 /*
4919 * we need this if more than one processor can write to our tail
4920 * at a time, it synchronizes IO on IA64/Altix systems
4921 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004922 mmiowb();
4923}
4924
4925#define MINIMUM_DHCP_PACKET_SIZE 282
4926static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4927 struct sk_buff *skb)
4928{
4929 struct e1000_hw *hw = &adapter->hw;
4930 u16 length, offset;
4931
4932 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004933 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4934 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004935 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4936 return 0;
4937 }
4938
4939 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4940 return 0;
4941
4942 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4943 return 0;
4944
4945 {
4946 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4947 struct udphdr *udp;
4948
4949 if (ip->protocol != IPPROTO_UDP)
4950 return 0;
4951
4952 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4953 if (ntohs(udp->dest) != 67)
4954 return 0;
4955
4956 offset = (u8 *)udp + 8 - skb->data;
4957 length = skb->len - offset;
4958 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4959 }
4960
4961 return 0;
4962}
4963
4964static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4965{
4966 struct e1000_adapter *adapter = netdev_priv(netdev);
4967
4968 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004969 /*
4970 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004971 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004972 * but since that doesn't exist yet, just open code it.
4973 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004974 smp_mb();
4975
Bruce Allanad680762008-03-28 09:15:03 -07004976 /*
4977 * We need to check again in a case another CPU has just
4978 * made room available.
4979 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004980 if (e1000_desc_unused(adapter->tx_ring) < size)
4981 return -EBUSY;
4982
4983 /* A reprieve! */
4984 netif_start_queue(netdev);
4985 ++adapter->restart_queue;
4986 return 0;
4987}
4988
4989static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4990{
4991 struct e1000_adapter *adapter = netdev_priv(netdev);
4992
4993 if (e1000_desc_unused(adapter->tx_ring) >= size)
4994 return 0;
4995 return __e1000_maybe_stop_tx(netdev, size);
4996}
4997
4998#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004999static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5000 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005001{
5002 struct e1000_adapter *adapter = netdev_priv(netdev);
5003 struct e1000_ring *tx_ring = adapter->tx_ring;
5004 unsigned int first;
5005 unsigned int max_per_txd = E1000_MAX_PER_TXD;
5006 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
5007 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005008 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005009 unsigned int nr_frags;
5010 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005011 int count = 0;
5012 int tso;
5013 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005014
5015 if (test_bit(__E1000_DOWN, &adapter->state)) {
5016 dev_kfree_skb_any(skb);
5017 return NETDEV_TX_OK;
5018 }
5019
5020 if (skb->len <= 0) {
5021 dev_kfree_skb_any(skb);
5022 return NETDEV_TX_OK;
5023 }
5024
5025 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07005026 /*
5027 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07005028 * make sure there is enough room in the FIFO before
5029 * initiating the DMA for each buffer. The calc is:
5030 * 4 = ceil(buffer len/mss). To make sure we don't
5031 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07005032 * drops.
5033 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005034 if (mss) {
5035 u8 hdr_len;
5036 max_per_txd = min(mss << 2, max_per_txd);
5037 max_txd_pwr = fls(max_per_txd) - 1;
5038
Bruce Allanad680762008-03-28 09:15:03 -07005039 /*
5040 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
5041 * points to just header, pull a few bytes of payload from
5042 * frags into skb->data
5043 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005044 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07005045 /*
5046 * we do this workaround for ES2LAN, but it is un-necessary,
5047 * avoiding it could save a lot of cycles
5048 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005049 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005050 unsigned int pull_size;
5051
5052 pull_size = min((unsigned int)4, skb->data_len);
5053 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005054 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005055 dev_kfree_skb_any(skb);
5056 return NETDEV_TX_OK;
5057 }
Eric Dumazete743d312010-04-14 15:59:40 -07005058 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005059 }
5060 }
5061
5062 /* reserve a descriptor for the offload context */
5063 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5064 count++;
5065 count++;
5066
5067 count += TXD_USE_COUNT(len, max_txd_pwr);
5068
5069 nr_frags = skb_shinfo(skb)->nr_frags;
5070 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00005071 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07005072 max_txd_pwr);
5073
5074 if (adapter->hw.mac.tx_pkt_filtering)
5075 e1000_transfer_dhcp_info(adapter, skb);
5076
Bruce Allanad680762008-03-28 09:15:03 -07005077 /*
5078 * need: count + 2 desc gap to keep tail from touching
5079 * head, otherwise try next time
5080 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00005081 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005082 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005083
Jesse Grosseab6d182010-10-20 13:56:03 +00005084 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005085 tx_flags |= E1000_TX_FLAGS_VLAN;
5086 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5087 }
5088
5089 first = tx_ring->next_to_use;
5090
5091 tso = e1000_tso(adapter, skb);
5092 if (tso < 0) {
5093 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005094 return NETDEV_TX_OK;
5095 }
5096
5097 if (tso)
5098 tx_flags |= E1000_TX_FLAGS_TSO;
5099 else if (e1000_tx_csum(adapter, skb))
5100 tx_flags |= E1000_TX_FLAGS_CSUM;
5101
Bruce Allanad680762008-03-28 09:15:03 -07005102 /*
5103 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005104 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005105 * no longer assume, we must.
5106 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107 if (skb->protocol == htons(ETH_P_IP))
5108 tx_flags |= E1000_TX_FLAGS_IPV4;
5109
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005110 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005111 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005112 if (count) {
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005113 netdev_sent_queue(netdev, skb->len);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005114 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005115 /* Make sure there is space in the ring for the next send. */
5116 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
5117
5118 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005119 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005120 tx_ring->buffer_info[first].time_stamp = 0;
5121 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005122 }
5123
Auke Kokbc7f75f2007-09-17 12:30:59 -07005124 return NETDEV_TX_OK;
5125}
5126
5127/**
5128 * e1000_tx_timeout - Respond to a Tx Hang
5129 * @netdev: network interface device structure
5130 **/
5131static void e1000_tx_timeout(struct net_device *netdev)
5132{
5133 struct e1000_adapter *adapter = netdev_priv(netdev);
5134
5135 /* Do the reset outside of interrupt context */
5136 adapter->tx_timeout_count++;
5137 schedule_work(&adapter->reset_task);
5138}
5139
5140static void e1000_reset_task(struct work_struct *work)
5141{
5142 struct e1000_adapter *adapter;
5143 adapter = container_of(work, struct e1000_adapter, reset_task);
5144
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005145 /* don't run the task if already down */
5146 if (test_bit(__E1000_DOWN, &adapter->state))
5147 return;
5148
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005149 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5150 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5151 e1000e_dump(adapter);
5152 e_err("Reset adapter\n");
5153 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005154 e1000e_reinit_locked(adapter);
5155}
5156
5157/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005158 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005159 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005160 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005161 *
5162 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005163 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005164struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5165 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005166{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005167 struct e1000_adapter *adapter = netdev_priv(netdev);
5168
5169 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5170 spin_lock(&adapter->stats64_lock);
5171 e1000e_update_stats(adapter);
5172 /* Fill out the OS statistics structure */
5173 stats->rx_bytes = adapter->stats.gorc;
5174 stats->rx_packets = adapter->stats.gprc;
5175 stats->tx_bytes = adapter->stats.gotc;
5176 stats->tx_packets = adapter->stats.gptc;
5177 stats->multicast = adapter->stats.mprc;
5178 stats->collisions = adapter->stats.colc;
5179
5180 /* Rx Errors */
5181
5182 /*
5183 * RLEC on some newer hardware can be incorrect so build
5184 * our own version based on RUC and ROC
5185 */
5186 stats->rx_errors = adapter->stats.rxerrc +
5187 adapter->stats.crcerrs + adapter->stats.algnerrc +
5188 adapter->stats.ruc + adapter->stats.roc +
5189 adapter->stats.cexterr;
5190 stats->rx_length_errors = adapter->stats.ruc +
5191 adapter->stats.roc;
5192 stats->rx_crc_errors = adapter->stats.crcerrs;
5193 stats->rx_frame_errors = adapter->stats.algnerrc;
5194 stats->rx_missed_errors = adapter->stats.mpc;
5195
5196 /* Tx Errors */
5197 stats->tx_errors = adapter->stats.ecol +
5198 adapter->stats.latecol;
5199 stats->tx_aborted_errors = adapter->stats.ecol;
5200 stats->tx_window_errors = adapter->stats.latecol;
5201 stats->tx_carrier_errors = adapter->stats.tncrs;
5202
5203 /* Tx Dropped needs to be maintained elsewhere */
5204
5205 spin_unlock(&adapter->stats64_lock);
5206 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005207}
5208
5209/**
5210 * e1000_change_mtu - Change the Maximum Transfer Unit
5211 * @netdev: network interface device structure
5212 * @new_mtu: new value for maximum frame size
5213 *
5214 * Returns 0 on success, negative on failure
5215 **/
5216static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5217{
5218 struct e1000_adapter *adapter = netdev_priv(netdev);
5219 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5220
Bruce Allan2adc55c2009-06-02 11:28:58 +00005221 /* Jumbo frame support */
Bruce Allan70495a52012-01-11 01:26:50 +00005222 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) {
5223 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5224 e_err("Jumbo Frames not supported.\n");
5225 return -EINVAL;
5226 }
5227
5228 /*
5229 * IP payload checksum (enabled with jumbos/packet-split when
5230 * Rx checksum is enabled) and generation of RSS hash is
5231 * mutually exclusive in the hardware.
5232 */
5233 if ((netdev->features & NETIF_F_RXCSUM) &&
5234 (netdev->features & NETIF_F_RXHASH)) {
5235 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");
5236 return -EINVAL;
5237 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005238 }
5239
Bruce Allan2adc55c2009-06-02 11:28:58 +00005240 /* Supported frame sizes */
5241 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5242 (max_frame > adapter->max_hw_frame_size)) {
5243 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005244 return -EINVAL;
5245 }
5246
Bruce Allana1ce6472010-09-22 17:16:40 +00005247 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5248 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5249 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5250 (new_mtu > ETH_DATA_LEN)) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00005251 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005252 return -EINVAL;
5253 }
5254
Bruce Allan6f461f62010-04-27 03:33:04 +00005255 /* 82573 Errata 17 */
5256 if (((adapter->hw.mac.type == e1000_82573) ||
5257 (adapter->hw.mac.type == e1000_82574)) &&
5258 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5259 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5260 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5261 }
5262
Auke Kokbc7f75f2007-09-17 12:30:59 -07005263 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005264 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005265 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005266 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005267 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5268 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005269 if (netif_running(netdev))
5270 e1000e_down(adapter);
5271
Bruce Allanad680762008-03-28 09:15:03 -07005272 /*
5273 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005274 * means we reserve 2 more, this pushes us to allocate from the next
5275 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005276 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005277 * However with the new *_jumbo_rx* routines, jumbo receives will use
5278 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005279 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005280
Jesse Brandeburg99261462010-01-22 22:56:16 +00005281 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005282 adapter->rx_buffer_len = 2048;
5283 else
5284 adapter->rx_buffer_len = 4096;
5285
5286 /* adjust allocation if LPE protects us, and we aren't using SBP */
5287 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5288 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5289 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005290 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005291
Auke Kokbc7f75f2007-09-17 12:30:59 -07005292 if (netif_running(netdev))
5293 e1000e_up(adapter);
5294 else
5295 e1000e_reset(adapter);
5296
5297 clear_bit(__E1000_RESETTING, &adapter->state);
5298
5299 return 0;
5300}
5301
5302static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5303 int cmd)
5304{
5305 struct e1000_adapter *adapter = netdev_priv(netdev);
5306 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005307
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005308 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005309 return -EOPNOTSUPP;
5310
5311 switch (cmd) {
5312 case SIOCGMIIPHY:
5313 data->phy_id = adapter->hw.phy.addr;
5314 break;
5315 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005316 e1000_phy_read_status(adapter);
5317
Bruce Allan7c257692008-04-23 11:09:00 -07005318 switch (data->reg_num & 0x1F) {
5319 case MII_BMCR:
5320 data->val_out = adapter->phy_regs.bmcr;
5321 break;
5322 case MII_BMSR:
5323 data->val_out = adapter->phy_regs.bmsr;
5324 break;
5325 case MII_PHYSID1:
5326 data->val_out = (adapter->hw.phy.id >> 16);
5327 break;
5328 case MII_PHYSID2:
5329 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5330 break;
5331 case MII_ADVERTISE:
5332 data->val_out = adapter->phy_regs.advertise;
5333 break;
5334 case MII_LPA:
5335 data->val_out = adapter->phy_regs.lpa;
5336 break;
5337 case MII_EXPANSION:
5338 data->val_out = adapter->phy_regs.expansion;
5339 break;
5340 case MII_CTRL1000:
5341 data->val_out = adapter->phy_regs.ctrl1000;
5342 break;
5343 case MII_STAT1000:
5344 data->val_out = adapter->phy_regs.stat1000;
5345 break;
5346 case MII_ESTATUS:
5347 data->val_out = adapter->phy_regs.estatus;
5348 break;
5349 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005350 return -EIO;
5351 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005352 break;
5353 case SIOCSMIIREG:
5354 default:
5355 return -EOPNOTSUPP;
5356 }
5357 return 0;
5358}
5359
5360static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5361{
5362 switch (cmd) {
5363 case SIOCGMIIPHY:
5364 case SIOCGMIIREG:
5365 case SIOCSMIIREG:
5366 return e1000_mii_ioctl(netdev, ifr, cmd);
5367 default:
5368 return -EOPNOTSUPP;
5369 }
5370}
5371
Bruce Allana4f58f52009-06-02 11:29:18 +00005372static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5373{
5374 struct e1000_hw *hw = &adapter->hw;
5375 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005376 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005377 int retval = 0;
5378
5379 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005380 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005381
Bruce Allan2b6b1682011-05-13 07:20:09 +00005382 retval = hw->phy.ops.acquire(hw);
5383 if (retval) {
5384 e_err("Could not acquire PHY\n");
5385 return retval;
5386 }
5387
5388 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5389 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5390 if (retval)
5391 goto out;
5392
5393 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005394 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5395 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005396 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5397 (u16)(mac_reg & 0xFFFF));
5398 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5399 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005400 }
5401
5402 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005403 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005404 mac_reg = er32(RCTL);
5405 if (mac_reg & E1000_RCTL_UPE)
5406 phy_reg |= BM_RCTL_UPE;
5407 if (mac_reg & E1000_RCTL_MPE)
5408 phy_reg |= BM_RCTL_MPE;
5409 phy_reg &= ~(BM_RCTL_MO_MASK);
5410 if (mac_reg & E1000_RCTL_MO_3)
5411 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5412 << BM_RCTL_MO_SHIFT);
5413 if (mac_reg & E1000_RCTL_BAM)
5414 phy_reg |= BM_RCTL_BAM;
5415 if (mac_reg & E1000_RCTL_PMCF)
5416 phy_reg |= BM_RCTL_PMCF;
5417 mac_reg = er32(CTRL);
5418 if (mac_reg & E1000_CTRL_RFCE)
5419 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005420 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005421
5422 /* enable PHY wakeup in MAC register */
5423 ew32(WUFC, wufc);
5424 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5425
5426 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005427 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5428 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005429
5430 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005431 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5432 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005433 if (retval)
5434 e_err("Could not set PHY Host Wakeup bit\n");
5435out:
Bruce Allan94d81862009-11-20 23:25:26 +00005436 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005437
5438 return retval;
5439}
5440
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005441static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5442 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005443{
5444 struct net_device *netdev = pci_get_drvdata(pdev);
5445 struct e1000_adapter *adapter = netdev_priv(netdev);
5446 struct e1000_hw *hw = &adapter->hw;
5447 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005448 /* Runtime suspend should only enable wakeup for link changes */
5449 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005450 int retval = 0;
5451
5452 netif_device_detach(netdev);
5453
5454 if (netif_running(netdev)) {
5455 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5456 e1000e_down(adapter);
5457 e1000_free_irq(adapter);
5458 }
Bruce Allan4662e822008-08-26 18:37:06 -07005459 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005460
5461 retval = pci_save_state(pdev);
5462 if (retval)
5463 return retval;
5464
5465 status = er32(STATUS);
5466 if (status & E1000_STATUS_LU)
5467 wufc &= ~E1000_WUFC_LNKC;
5468
5469 if (wufc) {
5470 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005471 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005472
5473 /* turn on all-multi mode if wake on multicast is enabled */
5474 if (wufc & E1000_WUFC_MC) {
5475 rctl = er32(RCTL);
5476 rctl |= E1000_RCTL_MPE;
5477 ew32(RCTL, rctl);
5478 }
5479
5480 ctrl = er32(CTRL);
5481 /* advertise wake from D3Cold */
5482 #define E1000_CTRL_ADVD3WUC 0x00100000
5483 /* phy power management enable */
5484 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005485 ctrl |= E1000_CTRL_ADVD3WUC;
5486 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5487 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005488 ew32(CTRL, ctrl);
5489
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005490 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5491 adapter->hw.phy.media_type ==
5492 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005493 /* keep the laser running in D3 */
5494 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005495 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005496 ew32(CTRL_EXT, ctrl_ext);
5497 }
5498
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005499 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005500 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005501
Auke Kokbc7f75f2007-09-17 12:30:59 -07005502 /* Allow time for pending master requests to run */
5503 e1000e_disable_pcie_master(&adapter->hw);
5504
Bruce Allan82776a42009-08-14 14:35:33 +00005505 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005506 /* enable wakeup by the PHY */
5507 retval = e1000_init_phy_wakeup(adapter, wufc);
5508 if (retval)
5509 return retval;
5510 } else {
5511 /* enable wakeup by the MAC */
5512 ew32(WUFC, wufc);
5513 ew32(WUC, E1000_WUC_PME_EN);
5514 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005515 } else {
5516 ew32(WUC, 0);
5517 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005518 }
5519
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005520 *enable_wake = !!wufc;
5521
Auke Kokbc7f75f2007-09-17 12:30:59 -07005522 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005523 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5524 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005525 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005526
5527 if (adapter->hw.phy.type == e1000_phy_igp_3)
5528 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5529
Bruce Allanad680762008-03-28 09:15:03 -07005530 /*
5531 * Release control of h/w to f/w. If f/w is AMT enabled, this
5532 * would have already happened in close and is redundant.
5533 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005534 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005535
5536 pci_disable_device(pdev);
5537
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005538 return 0;
5539}
5540
5541static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5542{
5543 if (sleep && wake) {
5544 pci_prepare_to_sleep(pdev);
5545 return;
5546 }
5547
5548 pci_wake_from_d3(pdev, wake);
5549 pci_set_power_state(pdev, PCI_D3hot);
5550}
5551
5552static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5553 bool wake)
5554{
5555 struct net_device *netdev = pci_get_drvdata(pdev);
5556 struct e1000_adapter *adapter = netdev_priv(netdev);
5557
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005558 /*
5559 * The pci-e switch on some quad port adapters will report a
5560 * correctable error when the MAC transitions from D0 to D3. To
5561 * prevent this we need to mask off the correctable errors on the
5562 * downstream port of the pci-e switch.
5563 */
5564 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5565 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005566 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005567 u16 devctl;
5568
5569 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5570 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5571 (devctl & ~PCI_EXP_DEVCTL_CERE));
5572
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005573 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005574
5575 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5576 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005577 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005578 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005579}
5580
Bruce Allan6f461f62010-04-27 03:33:04 +00005581#ifdef CONFIG_PCIEASPM
5582static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5583{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005584 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005585}
5586#else
5587static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005588{
5589 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005590 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005591
5592 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005593 * Both device and parent should have the same ASPM setting.
5594 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005595 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005596 pos = pci_pcie_cap(pdev);
5597 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5598 reg16 &= ~state;
5599 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5600
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005601 if (!pdev->bus->self)
5602 return;
5603
Bruce Allan6f461f62010-04-27 03:33:04 +00005604 pos = pci_pcie_cap(pdev->bus->self);
5605 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5606 reg16 &= ~state;
5607 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5608}
5609#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005610static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005611{
5612 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5613 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5614 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5615
5616 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005617}
5618
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005619#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005620static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005621{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005622 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005623}
5624
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005625static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005626{
5627 struct net_device *netdev = pci_get_drvdata(pdev);
5628 struct e1000_adapter *adapter = netdev_priv(netdev);
5629 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005630 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005631 u32 err;
5632
Bruce Allan78cd29d2011-03-24 03:09:03 +00005633 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5634 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5635 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5636 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5637 if (aspm_disable_flag)
5638 e1000e_disable_aspm(pdev, aspm_disable_flag);
5639
Auke Kokbc7f75f2007-09-17 12:30:59 -07005640 pci_set_power_state(pdev, PCI_D0);
5641 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005642 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005643
Bruce Allan4662e822008-08-26 18:37:06 -07005644 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005645 if (netif_running(netdev)) {
5646 err = e1000_request_irq(adapter);
5647 if (err)
5648 return err;
5649 }
5650
Bruce Allan99730e42011-05-13 07:19:48 +00005651 if (hw->mac.type == e1000_pch2lan)
5652 e1000_resume_workarounds_pchlan(&adapter->hw);
5653
Auke Kokbc7f75f2007-09-17 12:30:59 -07005654 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005655
5656 /* report the system wakeup cause from S3/S4 */
5657 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5658 u16 phy_data;
5659
5660 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5661 if (phy_data) {
5662 e_info("PHY Wakeup cause - %s\n",
5663 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5664 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5665 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5666 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005667 phy_data & E1000_WUS_LNKC ?
5668 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005669 }
5670 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5671 } else {
5672 u32 wus = er32(WUS);
5673 if (wus) {
5674 e_info("MAC Wakeup cause - %s\n",
5675 wus & E1000_WUS_EX ? "Unicast Packet" :
5676 wus & E1000_WUS_MC ? "Multicast Packet" :
5677 wus & E1000_WUS_BC ? "Broadcast Packet" :
5678 wus & E1000_WUS_MAG ? "Magic Packet" :
5679 wus & E1000_WUS_LNKC ? "Link Status Change" :
5680 "other");
5681 }
5682 ew32(WUS, ~0);
5683 }
5684
Auke Kokbc7f75f2007-09-17 12:30:59 -07005685 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005686
Bruce Allancd791612010-05-10 14:59:51 +00005687 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005688
5689 if (netif_running(netdev))
5690 e1000e_up(adapter);
5691
5692 netif_device_attach(netdev);
5693
Bruce Allanad680762008-03-28 09:15:03 -07005694 /*
5695 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005696 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005697 * under the control of the driver.
5698 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005699 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005700 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005701
5702 return 0;
5703}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005704
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005705#ifdef CONFIG_PM_SLEEP
5706static int e1000_suspend(struct device *dev)
5707{
5708 struct pci_dev *pdev = to_pci_dev(dev);
5709 int retval;
5710 bool wake;
5711
5712 retval = __e1000_shutdown(pdev, &wake, false);
5713 if (!retval)
5714 e1000_complete_shutdown(pdev, true, wake);
5715
5716 return retval;
5717}
5718
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005719static int e1000_resume(struct device *dev)
5720{
5721 struct pci_dev *pdev = to_pci_dev(dev);
5722 struct net_device *netdev = pci_get_drvdata(pdev);
5723 struct e1000_adapter *adapter = netdev_priv(netdev);
5724
5725 if (e1000e_pm_ready(adapter))
5726 adapter->idle_check = true;
5727
5728 return __e1000_resume(pdev);
5729}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005730#endif /* CONFIG_PM_SLEEP */
5731
5732#ifdef CONFIG_PM_RUNTIME
5733static int e1000_runtime_suspend(struct device *dev)
5734{
5735 struct pci_dev *pdev = to_pci_dev(dev);
5736 struct net_device *netdev = pci_get_drvdata(pdev);
5737 struct e1000_adapter *adapter = netdev_priv(netdev);
5738
5739 if (e1000e_pm_ready(adapter)) {
5740 bool wake;
5741
5742 __e1000_shutdown(pdev, &wake, true);
5743 }
5744
5745 return 0;
5746}
5747
5748static int e1000_idle(struct device *dev)
5749{
5750 struct pci_dev *pdev = to_pci_dev(dev);
5751 struct net_device *netdev = pci_get_drvdata(pdev);
5752 struct e1000_adapter *adapter = netdev_priv(netdev);
5753
5754 if (!e1000e_pm_ready(adapter))
5755 return 0;
5756
5757 if (adapter->idle_check) {
5758 adapter->idle_check = false;
5759 if (!e1000e_has_link(adapter))
5760 pm_schedule_suspend(dev, MSEC_PER_SEC);
5761 }
5762
5763 return -EBUSY;
5764}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005765
5766static int e1000_runtime_resume(struct device *dev)
5767{
5768 struct pci_dev *pdev = to_pci_dev(dev);
5769 struct net_device *netdev = pci_get_drvdata(pdev);
5770 struct e1000_adapter *adapter = netdev_priv(netdev);
5771
5772 if (!e1000e_pm_ready(adapter))
5773 return 0;
5774
5775 adapter->idle_check = !dev->power.runtime_auto;
5776 return __e1000_resume(pdev);
5777}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005778#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005779#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005780
5781static void e1000_shutdown(struct pci_dev *pdev)
5782{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005783 bool wake = false;
5784
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005785 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005786
5787 if (system_state == SYSTEM_POWER_OFF)
5788 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005789}
5790
5791#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005792
5793static irqreturn_t e1000_intr_msix(int irq, void *data)
5794{
5795 struct net_device *netdev = data;
5796 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005797
5798 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005799 int vector, msix_irq;
5800
Dongdong Deng147b2c82010-11-16 19:50:15 -08005801 vector = 0;
5802 msix_irq = adapter->msix_entries[vector].vector;
5803 disable_irq(msix_irq);
5804 e1000_intr_msix_rx(msix_irq, netdev);
5805 enable_irq(msix_irq);
5806
5807 vector++;
5808 msix_irq = adapter->msix_entries[vector].vector;
5809 disable_irq(msix_irq);
5810 e1000_intr_msix_tx(msix_irq, netdev);
5811 enable_irq(msix_irq);
5812
5813 vector++;
5814 msix_irq = adapter->msix_entries[vector].vector;
5815 disable_irq(msix_irq);
5816 e1000_msix_other(msix_irq, netdev);
5817 enable_irq(msix_irq);
5818 }
5819
5820 return IRQ_HANDLED;
5821}
5822
Auke Kokbc7f75f2007-09-17 12:30:59 -07005823/*
5824 * Polling 'interrupt' - used by things like netconsole to send skbs
5825 * without having to re-enable interrupts. It's not called while
5826 * the interrupt routine is executing.
5827 */
5828static void e1000_netpoll(struct net_device *netdev)
5829{
5830 struct e1000_adapter *adapter = netdev_priv(netdev);
5831
Dongdong Deng147b2c82010-11-16 19:50:15 -08005832 switch (adapter->int_mode) {
5833 case E1000E_INT_MODE_MSIX:
5834 e1000_intr_msix(adapter->pdev->irq, netdev);
5835 break;
5836 case E1000E_INT_MODE_MSI:
5837 disable_irq(adapter->pdev->irq);
5838 e1000_intr_msi(adapter->pdev->irq, netdev);
5839 enable_irq(adapter->pdev->irq);
5840 break;
5841 default: /* E1000E_INT_MODE_LEGACY */
5842 disable_irq(adapter->pdev->irq);
5843 e1000_intr(adapter->pdev->irq, netdev);
5844 enable_irq(adapter->pdev->irq);
5845 break;
5846 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005847}
5848#endif
5849
5850/**
5851 * e1000_io_error_detected - called when PCI error is detected
5852 * @pdev: Pointer to PCI device
5853 * @state: The current pci connection state
5854 *
5855 * This function is called after a PCI bus error affecting
5856 * this device has been detected.
5857 */
5858static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5859 pci_channel_state_t state)
5860{
5861 struct net_device *netdev = pci_get_drvdata(pdev);
5862 struct e1000_adapter *adapter = netdev_priv(netdev);
5863
5864 netif_device_detach(netdev);
5865
Mike Masonc93b5a72009-06-30 12:45:53 +00005866 if (state == pci_channel_io_perm_failure)
5867 return PCI_ERS_RESULT_DISCONNECT;
5868
Auke Kokbc7f75f2007-09-17 12:30:59 -07005869 if (netif_running(netdev))
5870 e1000e_down(adapter);
5871 pci_disable_device(pdev);
5872
5873 /* Request a slot slot reset. */
5874 return PCI_ERS_RESULT_NEED_RESET;
5875}
5876
5877/**
5878 * e1000_io_slot_reset - called after the pci bus has been reset.
5879 * @pdev: Pointer to PCI device
5880 *
5881 * Restart the card from scratch, as if from a cold-boot. Implementation
5882 * resembles the first-half of the e1000_resume routine.
5883 */
5884static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5885{
5886 struct net_device *netdev = pci_get_drvdata(pdev);
5887 struct e1000_adapter *adapter = netdev_priv(netdev);
5888 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005889 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005890 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005891 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005892
Bruce Allan78cd29d2011-03-24 03:09:03 +00005893 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5894 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005895 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005896 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5897 if (aspm_disable_flag)
5898 e1000e_disable_aspm(pdev, aspm_disable_flag);
5899
Bruce Allanf0f422e2008-08-04 17:21:53 -07005900 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005901 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005902 dev_err(&pdev->dev,
5903 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005904 result = PCI_ERS_RESULT_DISCONNECT;
5905 } else {
5906 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005907 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005908 pci_restore_state(pdev);
5909
5910 pci_enable_wake(pdev, PCI_D3hot, 0);
5911 pci_enable_wake(pdev, PCI_D3cold, 0);
5912
5913 e1000e_reset(adapter);
5914 ew32(WUS, ~0);
5915 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005916 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005917
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005918 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005919
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005920 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005921}
5922
5923/**
5924 * e1000_io_resume - called when traffic can start flowing again.
5925 * @pdev: Pointer to PCI device
5926 *
5927 * This callback is called when the error recovery driver tells us that
5928 * its OK to resume normal operation. Implementation resembles the
5929 * second-half of the e1000_resume routine.
5930 */
5931static void e1000_io_resume(struct pci_dev *pdev)
5932{
5933 struct net_device *netdev = pci_get_drvdata(pdev);
5934 struct e1000_adapter *adapter = netdev_priv(netdev);
5935
Bruce Allancd791612010-05-10 14:59:51 +00005936 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005937
5938 if (netif_running(netdev)) {
5939 if (e1000e_up(adapter)) {
5940 dev_err(&pdev->dev,
5941 "can't bring device back up after reset\n");
5942 return;
5943 }
5944 }
5945
5946 netif_device_attach(netdev);
5947
Bruce Allanad680762008-03-28 09:15:03 -07005948 /*
5949 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005950 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005951 * under the control of the driver.
5952 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005953 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005954 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955
5956}
5957
5958static void e1000_print_device_info(struct e1000_adapter *adapter)
5959{
5960 struct e1000_hw *hw = &adapter->hw;
5961 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005962 u32 ret_val;
5963 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005964
5965 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005966 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005967 /* bus width */
5968 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5969 "Width x1"),
5970 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005971 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005972 e_info("Intel(R) PRO/%s Network Connection\n",
5973 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005974 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5975 E1000_PBANUM_LENGTH);
5976 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005977 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005978 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5979 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005980}
5981
Auke Kok10aa4c02008-08-04 17:21:20 -07005982static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5983{
5984 struct e1000_hw *hw = &adapter->hw;
5985 int ret_val;
5986 u16 buf = 0;
5987
5988 if (hw->mac.type != e1000_82573)
5989 return;
5990
5991 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005992 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005993 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005994 dev_warn(&adapter->pdev->dev,
5995 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005996 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005997}
5998
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005999static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006000 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006001{
6002 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006003 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006004
6005 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6006 adapter->flags |= FLAG_TSO_FORCE;
6007
6008 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Bruce Allan70495a52012-01-11 01:26:50 +00006009 NETIF_F_RXCSUM | NETIF_F_RXHASH)))
Bruce Allandc221292011-08-19 03:23:48 +00006010 return 0;
6011
Bruce Allan70495a52012-01-11 01:26:50 +00006012 /*
6013 * IP payload checksum (enabled with jumbos/packet-split when Rx
6014 * checksum is enabled) and generation of RSS hash is mutually
6015 * exclusive in the hardware.
6016 */
6017 if (adapter->rx_ps_pages &&
6018 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
6019 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");
6020 return -EINVAL;
6021 }
6022
6023 netdev->features = features;
6024
Bruce Allandc221292011-08-19 03:23:48 +00006025 if (netif_running(netdev))
6026 e1000e_reinit_locked(adapter);
6027 else
6028 e1000e_reset(adapter);
6029
6030 return 0;
6031}
6032
Stephen Hemminger651c2462008-11-19 21:57:48 -08006033static const struct net_device_ops e1000e_netdev_ops = {
6034 .ndo_open = e1000_open,
6035 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006036 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006037 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006038 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006039 .ndo_set_mac_address = e1000_set_mac,
6040 .ndo_change_mtu = e1000_change_mtu,
6041 .ndo_do_ioctl = e1000_ioctl,
6042 .ndo_tx_timeout = e1000_tx_timeout,
6043 .ndo_validate_addr = eth_validate_addr,
6044
Stephen Hemminger651c2462008-11-19 21:57:48 -08006045 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6046 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6047#ifdef CONFIG_NET_POLL_CONTROLLER
6048 .ndo_poll_controller = e1000_netpoll,
6049#endif
Bruce Allandc221292011-08-19 03:23:48 +00006050 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006051};
6052
Auke Kokbc7f75f2007-09-17 12:30:59 -07006053/**
6054 * e1000_probe - Device Initialization Routine
6055 * @pdev: PCI device information struct
6056 * @ent: entry in e1000_pci_tbl
6057 *
6058 * Returns 0 on success, negative on failure
6059 *
6060 * e1000_probe initializes an adapter identified by a pci_dev structure.
6061 * The OS initialization, configuring of the adapter private structure,
6062 * and a hardware reset occur.
6063 **/
6064static int __devinit e1000_probe(struct pci_dev *pdev,
6065 const struct pci_device_id *ent)
6066{
6067 struct net_device *netdev;
6068 struct e1000_adapter *adapter;
6069 struct e1000_hw *hw;
6070 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006071 resource_size_t mmio_start, mmio_len;
6072 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006073
6074 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006075 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006076 int i, err, pci_using_dac;
6077 u16 eeprom_data = 0;
6078 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6079
Bruce Allan78cd29d2011-03-24 03:09:03 +00006080 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6081 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006082 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006083 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6084 if (aspm_disable_flag)
6085 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006086
Bruce Allanf0f422e2008-08-04 17:21:53 -07006087 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006088 if (err)
6089 return err;
6090
6091 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006092 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006093 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006094 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006095 if (!err)
6096 pci_using_dac = 1;
6097 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006098 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006099 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006100 err = dma_set_coherent_mask(&pdev->dev,
6101 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006102 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006103 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006104 goto err_dma;
6105 }
6106 }
6107 }
6108
Arjan van de Vene8de1482008-10-22 19:55:31 -07006109 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006110 pci_select_bars(pdev, IORESOURCE_MEM),
6111 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006112 if (err)
6113 goto err_pci_reg;
6114
Xiaotian Feng68eac462009-08-14 14:35:52 +00006115 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006116 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006117
Auke Kokbc7f75f2007-09-17 12:30:59 -07006118 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006119 /* PCI config space info */
6120 err = pci_save_state(pdev);
6121 if (err)
6122 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006123
6124 err = -ENOMEM;
6125 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6126 if (!netdev)
6127 goto err_alloc_etherdev;
6128
Auke Kokbc7f75f2007-09-17 12:30:59 -07006129 SET_NETDEV_DEV(netdev, &pdev->dev);
6130
Tom Herbertf85e4df2010-05-05 14:03:32 +00006131 netdev->irq = pdev->irq;
6132
Auke Kokbc7f75f2007-09-17 12:30:59 -07006133 pci_set_drvdata(pdev, netdev);
6134 adapter = netdev_priv(netdev);
6135 hw = &adapter->hw;
6136 adapter->netdev = netdev;
6137 adapter->pdev = pdev;
6138 adapter->ei = ei;
6139 adapter->pba = ei->pba;
6140 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006141 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006142 adapter->hw.adapter = adapter;
6143 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006144 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006145 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6146
6147 mmio_start = pci_resource_start(pdev, 0);
6148 mmio_len = pci_resource_len(pdev, 0);
6149
6150 err = -EIO;
6151 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6152 if (!adapter->hw.hw_addr)
6153 goto err_ioremap;
6154
6155 if ((adapter->flags & FLAG_HAS_FLASH) &&
6156 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6157 flash_start = pci_resource_start(pdev, 1);
6158 flash_len = pci_resource_len(pdev, 1);
6159 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6160 if (!adapter->hw.flash_address)
6161 goto err_flashmap;
6162 }
6163
6164 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006165 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006166 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006167 netdev->watchdog_timeo = 5 * HZ;
6168 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006169 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
6170
6171 netdev->mem_start = mmio_start;
6172 netdev->mem_end = mmio_start + mmio_len;
6173
6174 adapter->bd_number = cards_found++;
6175
Bruce Allan4662e822008-08-26 18:37:06 -07006176 e1000e_check_options(adapter);
6177
Auke Kokbc7f75f2007-09-17 12:30:59 -07006178 /* setup adapter struct */
6179 err = e1000_sw_init(adapter);
6180 if (err)
6181 goto err_sw_init;
6182
Auke Kokbc7f75f2007-09-17 12:30:59 -07006183 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6184 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6185 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6186
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006187 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006188 if (err)
6189 goto err_hw_init;
6190
Bruce Allan4a770352008-10-01 17:18:35 -07006191 if ((adapter->flags & FLAG_IS_ICH) &&
6192 (adapter->flags & FLAG_READ_ONLY_NVM))
6193 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6194
Auke Kokbc7f75f2007-09-17 12:30:59 -07006195 hw->mac.ops.get_bus_info(&adapter->hw);
6196
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006197 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006198
6199 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006200 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006201 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6202 adapter->hw.phy.disable_polarity_correction = 0;
6203 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6204 }
6205
6206 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006207 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006208
Bruce Allandc221292011-08-19 03:23:48 +00006209 /* Set initial default active device features */
6210 netdev->features = (NETIF_F_SG |
6211 NETIF_F_HW_VLAN_RX |
6212 NETIF_F_HW_VLAN_TX |
6213 NETIF_F_TSO |
6214 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006215 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006216 NETIF_F_RXCSUM |
6217 NETIF_F_HW_CSUM);
6218
6219 /* Set user-changeable features (subset of all device features) */
6220 netdev->hw_features = netdev->features;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006221
6222 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6223 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6224
Bruce Allandc221292011-08-19 03:23:48 +00006225 netdev->vlan_features |= (NETIF_F_SG |
6226 NETIF_F_TSO |
6227 NETIF_F_TSO6 |
6228 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006229
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006230 netdev->priv_flags |= IFF_UNICAST_FLT;
6231
Yi Zou7b872a52010-09-22 17:57:58 +00006232 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006233 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006234 netdev->vlan_features |= NETIF_F_HIGHDMA;
6235 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006236
Auke Kokbc7f75f2007-09-17 12:30:59 -07006237 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6238 adapter->flags |= FLAG_MNG_PT_ENABLED;
6239
Bruce Allanad680762008-03-28 09:15:03 -07006240 /*
6241 * before reading the NVM, reset the controller to
6242 * put the device in a known good starting state
6243 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006244 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6245
6246 /*
6247 * systems with ASPM and others may see the checksum fail on the first
6248 * attempt. Let's give it a few tries
6249 */
6250 for (i = 0;; i++) {
6251 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6252 break;
6253 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006254 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006255 err = -EIO;
6256 goto err_eeprom;
6257 }
6258 }
6259
Auke Kok10aa4c02008-08-04 17:21:20 -07006260 e1000_eeprom_checks(adapter);
6261
Bruce Allan608f8a02010-01-13 02:04:58 +00006262 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006263 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006264 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006265
6266 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6267 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6268
6269 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006270 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006271 err = -EIO;
6272 goto err_eeprom;
6273 }
6274
6275 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006276 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006277 adapter->watchdog_timer.data = (unsigned long) adapter;
6278
6279 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006280 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006281 adapter->phy_info_timer.data = (unsigned long) adapter;
6282
6283 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6284 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006285 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6286 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006287 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006288
Auke Kokbc7f75f2007-09-17 12:30:59 -07006289 /* Initialize link parameters. User can change them with ethtool */
6290 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006291 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006292 adapter->hw.fc.requested_mode = e1000_fc_default;
6293 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006294 adapter->hw.phy.autoneg_advertised = 0x2f;
6295
6296 /* ring size defaults */
6297 adapter->rx_ring->count = 256;
6298 adapter->tx_ring->count = 256;
6299
6300 /*
6301 * Initial Wake on LAN setting - If APM wake is enabled in
6302 * the EEPROM, enable the ACPI Magic Packet filter
6303 */
6304 if (adapter->flags & FLAG_APME_IN_WUC) {
6305 /* APME bit in EEPROM is mapped to WUC.APME */
6306 eeprom_data = er32(WUC);
6307 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006308 if ((hw->mac.type > e1000_ich10lan) &&
6309 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006310 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006311 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6312 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6313 (adapter->hw.bus.func == 1))
6314 e1000_read_nvm(&adapter->hw,
6315 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6316 else
6317 e1000_read_nvm(&adapter->hw,
6318 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6319 }
6320
6321 /* fetch WoL from EEPROM */
6322 if (eeprom_data & eeprom_apme_mask)
6323 adapter->eeprom_wol |= E1000_WUFC_MAG;
6324
6325 /*
6326 * now that we have the eeprom settings, apply the special cases
6327 * where the eeprom may be wrong or the board simply won't support
6328 * wake on lan on a particular port
6329 */
6330 if (!(adapter->flags & FLAG_HAS_WOL))
6331 adapter->eeprom_wol = 0;
6332
6333 /* initialize the wol settings based on the eeprom settings */
6334 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006335 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006336
Bruce Allan84527592008-11-21 17:00:22 -08006337 /* save off EEPROM version number */
6338 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6339
Auke Kokbc7f75f2007-09-17 12:30:59 -07006340 /* reset the hardware with the new settings */
6341 e1000e_reset(adapter);
6342
Bruce Allanad680762008-03-28 09:15:03 -07006343 /*
6344 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006345 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006346 * under the control of the driver.
6347 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006348 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006349 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006350
Bruce Allane0dc4f12011-01-06 14:29:50 +00006351 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006352 err = register_netdev(netdev);
6353 if (err)
6354 goto err_register;
6355
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006356 /* carrier off reporting is important to ethtool even BEFORE open */
6357 netif_carrier_off(netdev);
6358
Auke Kokbc7f75f2007-09-17 12:30:59 -07006359 e1000_print_device_info(adapter);
6360
Alan Sternf3ec4f82010-06-08 15:23:51 -04006361 if (pci_dev_run_wake(pdev))
6362 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006363
Auke Kokbc7f75f2007-09-17 12:30:59 -07006364 return 0;
6365
6366err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006367 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006368 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006369err_eeprom:
6370 if (!e1000_check_reset_block(&adapter->hw))
6371 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006372err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006373 kfree(adapter->tx_ring);
6374 kfree(adapter->rx_ring);
6375err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006376 if (adapter->hw.flash_address)
6377 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006378 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006379err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006380 iounmap(adapter->hw.hw_addr);
6381err_ioremap:
6382 free_netdev(netdev);
6383err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006384 pci_release_selected_regions(pdev,
6385 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006386err_pci_reg:
6387err_dma:
6388 pci_disable_device(pdev);
6389 return err;
6390}
6391
6392/**
6393 * e1000_remove - Device Removal Routine
6394 * @pdev: PCI device information struct
6395 *
6396 * e1000_remove is called by the PCI subsystem to alert the driver
6397 * that it should release a PCI device. The could be caused by a
6398 * Hot-Plug event, or because the driver is going to be removed from
6399 * memory.
6400 **/
6401static void __devexit e1000_remove(struct pci_dev *pdev)
6402{
6403 struct net_device *netdev = pci_get_drvdata(pdev);
6404 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006405 bool down = test_bit(__E1000_DOWN, &adapter->state);
6406
Bruce Allanad680762008-03-28 09:15:03 -07006407 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006408 * The timers may be rescheduled, so explicitly disable them
6409 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006410 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006411 if (!down)
6412 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006413 del_timer_sync(&adapter->watchdog_timer);
6414 del_timer_sync(&adapter->phy_info_timer);
6415
Bruce Allan41cec6f2009-11-20 23:28:56 +00006416 cancel_work_sync(&adapter->reset_task);
6417 cancel_work_sync(&adapter->watchdog_task);
6418 cancel_work_sync(&adapter->downshift_task);
6419 cancel_work_sync(&adapter->update_phy_task);
6420 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006421
Bruce Allan17f208d2009-12-01 15:47:22 +00006422 if (!(netdev->flags & IFF_UP))
6423 e1000_power_down_phy(adapter);
6424
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006425 /* Don't lie to e1000_close() down the road. */
6426 if (!down)
6427 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006428 unregister_netdev(netdev);
6429
Alan Sternf3ec4f82010-06-08 15:23:51 -04006430 if (pci_dev_run_wake(pdev))
6431 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006432
Bruce Allanad680762008-03-28 09:15:03 -07006433 /*
6434 * Release control of h/w to f/w. If f/w is AMT enabled, this
6435 * would have already happened in close and is redundant.
6436 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006437 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006438
Bruce Allan4662e822008-08-26 18:37:06 -07006439 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006440 kfree(adapter->tx_ring);
6441 kfree(adapter->rx_ring);
6442
6443 iounmap(adapter->hw.hw_addr);
6444 if (adapter->hw.flash_address)
6445 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006446 pci_release_selected_regions(pdev,
6447 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006448
6449 free_netdev(netdev);
6450
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006451 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006452 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006453
Auke Kokbc7f75f2007-09-17 12:30:59 -07006454 pci_disable_device(pdev);
6455}
6456
6457/* PCI Error Recovery (ERS) */
6458static struct pci_error_handlers e1000_err_handler = {
6459 .error_detected = e1000_io_error_detected,
6460 .slot_reset = e1000_io_slot_reset,
6461 .resume = e1000_io_resume,
6462};
6463
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006464static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006465 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6466 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6467 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6468 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6469 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6470 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006471 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6472 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6473 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006474
Auke Kokbc7f75f2007-09-17 12:30:59 -07006475 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6476 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6477 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6478 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006479
Auke Kokbc7f75f2007-09-17 12:30:59 -07006480 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6481 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6482 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006483
Bruce Allan4662e822008-08-26 18:37:06 -07006484 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006485 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006486 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006487
Auke Kokbc7f75f2007-09-17 12:30:59 -07006488 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6489 board_80003es2lan },
6490 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6491 board_80003es2lan },
6492 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6493 board_80003es2lan },
6494 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6495 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006496
Auke Kokbc7f75f2007-09-17 12:30:59 -07006497 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6498 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6499 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6500 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6501 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6502 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6503 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006504 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006505
Auke Kokbc7f75f2007-09-17 12:30:59 -07006506 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6507 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6508 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6509 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6510 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006511 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006512 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6513 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6514 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6515
6516 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6517 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6518 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006519
Bruce Allanf4187b52008-08-26 18:36:50 -07006520 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6521 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006522 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006523
Bruce Allana4f58f52009-06-02 11:29:18 +00006524 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6525 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6526 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6527 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6528
Bruce Alland3738bb2010-06-16 13:27:28 +00006529 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6530 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6531
Auke Kokbc7f75f2007-09-17 12:30:59 -07006532 { } /* terminate list */
6533};
6534MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6535
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006536#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006537static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006538 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6539 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6540 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006541};
David S. Millere50208a2010-03-16 23:36:24 -07006542#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006543
Auke Kokbc7f75f2007-09-17 12:30:59 -07006544/* PCI Device API Driver */
6545static struct pci_driver e1000_driver = {
6546 .name = e1000e_driver_name,
6547 .id_table = e1000_pci_tbl,
6548 .probe = e1000_probe,
6549 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006550#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006551 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006552#endif
6553 .shutdown = e1000_shutdown,
6554 .err_handler = &e1000_err_handler
6555};
6556
6557/**
6558 * e1000_init_module - Driver Registration Routine
6559 *
6560 * e1000_init_module is the first routine called when the driver is
6561 * loaded. All it does is register with the PCI subsystem.
6562 **/
6563static int __init e1000_init_module(void)
6564{
6565 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006566 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6567 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006568 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006569 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006570
Auke Kokbc7f75f2007-09-17 12:30:59 -07006571 return ret;
6572}
6573module_init(e1000_init_module);
6574
6575/**
6576 * e1000_exit_module - Driver Exit Cleanup Routine
6577 *
6578 * e1000_exit_module is called just before the driver is removed
6579 * from memory.
6580 **/
6581static void __exit e1000_exit_module(void)
6582{
6583 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006584}
6585module_exit(e1000_exit_module);
6586
6587
6588MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6589MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6590MODULE_LICENSE("GPL");
6591MODULE_VERSION(DRV_VERSION);
6592
6593/* e1000_main.c */