blob: 7a1ea1d6f58044df497ecb34984992f927a06a50 [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
Auke Kokbc7f75f2007-09-17 12:30:59 -0700490 * @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
494 **/
495static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
496 u32 csum, struct sk_buff *skb)
497{
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
503 /* Ignore Checksum bit is set */
504 if (status & E1000_RXD_STAT_IXSM)
505 return;
506 /* TCP/UDP checksum error bit is set */
507 if (errors & E1000_RXD_ERR_TCPE) {
508 /* let the stack verify checksum errors */
509 adapter->hw_csum_err++;
510 return;
511 }
512
513 /* TCP/UDP Checksum has not been calculated */
514 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
515 return;
516
517 /* It must be a TCP or UDP packet with a valid checksum */
518 if (status & E1000_RXD_STAT_TCPCS) {
519 /* TCP checksum is good */
520 skb->ip_summed = CHECKSUM_UNNECESSARY;
521 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700522 /*
523 * IP fragment with UDP payload
524 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700525 * and then put the value in host order for further stack use.
526 */
Al Viroa39fe742007-12-11 19:50:34 +0000527 __sum16 sum = (__force __sum16)htons(csum);
528 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700529 skb->ip_summed = CHECKSUM_COMPLETE;
530 }
531 adapter->hw_csum_good++;
532}
533
534/**
David S. Miller823dcd22011-08-20 10:39:12 -0700535 * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa()
536 * @hw: pointer to the HW structure
537 * @tail: address of tail descriptor register
538 * @i: value to write to tail descriptor register
539 *
540 * When updating the tail register, the ME could be accessing Host CSR
541 * registers at the same time. Normally, this is handled in h/w by an
542 * arbiter but on some parts there is a bug that acknowledges Host accesses
543 * later than it should which could result in the descriptor register to
544 * have an incorrect value. Workaround this by checking the FWSM register
545 * which has bit 24 set while ME is accessing Host CSR registers, wait
546 * if it is set and try again a number of times.
547 **/
548static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, u8 __iomem * tail,
549 unsigned int i)
550{
551 unsigned int j = 0;
552
553 while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) &&
554 (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI))
555 udelay(50);
556
557 writel(i, tail);
558
559 if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail)))
560 return E1000_ERR_SWFW_SYNC;
561
562 return 0;
563}
564
565static void e1000e_update_rdt_wa(struct e1000_adapter *adapter, unsigned int i)
566{
567 u8 __iomem *tail = (adapter->hw.hw_addr + adapter->rx_ring->tail);
568 struct e1000_hw *hw = &adapter->hw;
569
570 if (e1000e_update_tail_wa(hw, tail, i)) {
571 u32 rctl = er32(RCTL);
572 ew32(RCTL, rctl & ~E1000_RCTL_EN);
573 e_err("ME firmware caused invalid RDT - resetting\n");
574 schedule_work(&adapter->reset_task);
575 }
576}
577
578static void e1000e_update_tdt_wa(struct e1000_adapter *adapter, unsigned int i)
579{
580 u8 __iomem *tail = (adapter->hw.hw_addr + adapter->tx_ring->tail);
581 struct e1000_hw *hw = &adapter->hw;
582
583 if (e1000e_update_tail_wa(hw, tail, i)) {
584 u32 tctl = er32(TCTL);
585 ew32(TCTL, tctl & ~E1000_TCTL_EN);
586 e_err("ME firmware caused invalid TDT - resetting\n");
587 schedule_work(&adapter->reset_task);
588 }
589}
590
591/**
Bruce Allan5f450212011-07-22 06:21:46 +0000592 * e1000_alloc_rx_buffers - Replace used receive buffers
Auke Kokbc7f75f2007-09-17 12:30:59 -0700593 * @adapter: address of board private structure
594 **/
595static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000596 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700597{
598 struct net_device *netdev = adapter->netdev;
599 struct pci_dev *pdev = adapter->pdev;
600 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +0000601 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602 struct e1000_buffer *buffer_info;
603 struct sk_buff *skb;
604 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000605 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700606
607 i = rx_ring->next_to_use;
608 buffer_info = &rx_ring->buffer_info[i];
609
610 while (cleaned_count--) {
611 skb = buffer_info->skb;
612 if (skb) {
613 skb_trim(skb, 0);
614 goto map_skb;
615 }
616
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000617 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700618 if (!skb) {
619 /* Better luck next round */
620 adapter->alloc_rx_buff_failed++;
621 break;
622 }
623
Auke Kokbc7f75f2007-09-17 12:30:59 -0700624 buffer_info->skb = skb;
625map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000626 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000628 DMA_FROM_DEVICE);
629 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000630 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700631 adapter->rx_dma_failed++;
632 break;
633 }
634
Bruce Allan5f450212011-07-22 06:21:46 +0000635 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
636 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700637
Tom Herbert50849d72010-05-05 14:02:49 +0000638 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
639 /*
640 * Force memory writes to complete before letting h/w
641 * know there are new descriptors to fetch. (Only
642 * applicable for weak-ordered memory model archs,
643 * such as IA-64).
644 */
645 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700646 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
647 e1000e_update_rdt_wa(adapter, i);
648 else
649 writel(i, adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000650 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700651 i++;
652 if (i == rx_ring->count)
653 i = 0;
654 buffer_info = &rx_ring->buffer_info[i];
655 }
656
Tom Herbert50849d72010-05-05 14:02:49 +0000657 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700658}
659
660/**
661 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
662 * @adapter: address of board private structure
663 **/
664static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000665 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700666{
667 struct net_device *netdev = adapter->netdev;
668 struct pci_dev *pdev = adapter->pdev;
669 union e1000_rx_desc_packet_split *rx_desc;
670 struct e1000_ring *rx_ring = adapter->rx_ring;
671 struct e1000_buffer *buffer_info;
672 struct e1000_ps_page *ps_page;
673 struct sk_buff *skb;
674 unsigned int i, j;
675
676 i = rx_ring->next_to_use;
677 buffer_info = &rx_ring->buffer_info[i];
678
679 while (cleaned_count--) {
680 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
681
682 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700683 ps_page = &buffer_info->ps_pages[j];
684 if (j >= adapter->rx_ps_pages) {
685 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000686 rx_desc->read.buffer_addr[j + 1] =
687 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700688 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700689 }
Auke Kok47f44e42007-10-25 13:57:44 -0700690 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000691 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700692 if (!ps_page->page) {
693 adapter->alloc_rx_buff_failed++;
694 goto no_buffers;
695 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000696 ps_page->dma = dma_map_page(&pdev->dev,
697 ps_page->page,
698 0, PAGE_SIZE,
699 DMA_FROM_DEVICE);
700 if (dma_mapping_error(&pdev->dev,
701 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700702 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000703 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700704 adapter->rx_dma_failed++;
705 goto no_buffers;
706 }
707 }
708 /*
709 * Refresh the desc even if buffer_addrs
710 * didn't change because each write-back
711 * erases this info.
712 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000713 rx_desc->read.buffer_addr[j + 1] =
714 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700715 }
716
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000717 skb = __netdev_alloc_skb_ip_align(netdev,
718 adapter->rx_ps_bsize0,
719 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700720
721 if (!skb) {
722 adapter->alloc_rx_buff_failed++;
723 break;
724 }
725
Auke Kokbc7f75f2007-09-17 12:30:59 -0700726 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000727 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700728 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000729 DMA_FROM_DEVICE);
730 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000731 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700732 adapter->rx_dma_failed++;
733 /* cleanup skb */
734 dev_kfree_skb_any(skb);
735 buffer_info->skb = NULL;
736 break;
737 }
738
739 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
740
Tom Herbert50849d72010-05-05 14:02:49 +0000741 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
742 /*
743 * Force memory writes to complete before letting h/w
744 * know there are new descriptors to fetch. (Only
745 * applicable for weak-ordered memory model archs,
746 * such as IA-64).
747 */
748 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700749 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
750 e1000e_update_rdt_wa(adapter, i << 1);
751 else
752 writel(i << 1,
753 adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000754 }
755
Auke Kokbc7f75f2007-09-17 12:30:59 -0700756 i++;
757 if (i == rx_ring->count)
758 i = 0;
759 buffer_info = &rx_ring->buffer_info[i];
760 }
761
762no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000763 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700764}
765
766/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700767 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
768 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700769 * @cleaned_count: number of buffers to allocate this pass
770 **/
771
772static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000773 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700774{
775 struct net_device *netdev = adapter->netdev;
776 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000777 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700778 struct e1000_ring *rx_ring = adapter->rx_ring;
779 struct e1000_buffer *buffer_info;
780 struct sk_buff *skb;
781 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000782 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700783
784 i = rx_ring->next_to_use;
785 buffer_info = &rx_ring->buffer_info[i];
786
787 while (cleaned_count--) {
788 skb = buffer_info->skb;
789 if (skb) {
790 skb_trim(skb, 0);
791 goto check_page;
792 }
793
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000794 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700795 if (unlikely(!skb)) {
796 /* Better luck next round */
797 adapter->alloc_rx_buff_failed++;
798 break;
799 }
800
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700801 buffer_info->skb = skb;
802check_page:
803 /* allocate a new page if necessary */
804 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000805 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700806 if (unlikely(!buffer_info->page)) {
807 adapter->alloc_rx_buff_failed++;
808 break;
809 }
810 }
811
812 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000813 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700814 buffer_info->page, 0,
815 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000816 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700817
Bruce Allan5f450212011-07-22 06:21:46 +0000818 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
819 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700820
821 if (unlikely(++i == rx_ring->count))
822 i = 0;
823 buffer_info = &rx_ring->buffer_info[i];
824 }
825
826 if (likely(rx_ring->next_to_use != i)) {
827 rx_ring->next_to_use = i;
828 if (unlikely(i-- == 0))
829 i = (rx_ring->count - 1);
830
831 /* Force memory writes to complete before letting h/w
832 * know there are new descriptors to fetch. (Only
833 * applicable for weak-ordered memory model archs,
834 * such as IA-64). */
835 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700836 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
837 e1000e_update_rdt_wa(adapter, i);
838 else
839 writel(i, adapter->hw.hw_addr + rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700840 }
841}
842
843/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700844 * e1000_clean_rx_irq - Send received data up the network stack; legacy
845 * @adapter: board private structure
846 *
847 * the return value indicates whether actual cleaning was done, there
848 * is no guarantee that everything was cleaned
849 **/
850static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
851 int *work_done, int work_to_do)
852{
853 struct net_device *netdev = adapter->netdev;
854 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000855 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700856 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +0000857 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700858 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000859 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860 unsigned int i;
861 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000862 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700863 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
864
865 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000866 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
867 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700868 buffer_info = &rx_ring->buffer_info[i];
869
Bruce Allan5f450212011-07-22 06:21:46 +0000870 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700871 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700872
873 if (*work_done >= work_to_do)
874 break;
875 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000876 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700877
Auke Kokbc7f75f2007-09-17 12:30:59 -0700878 skb = buffer_info->skb;
879 buffer_info->skb = NULL;
880
881 prefetch(skb->data - NET_IP_ALIGN);
882
883 i++;
884 if (i == rx_ring->count)
885 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000886 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700887 prefetch(next_rxd);
888
889 next_buffer = &rx_ring->buffer_info[i];
890
Rusty Russell3db1cd52011-12-19 13:56:45 +0000891 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700892 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000893 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700894 buffer_info->dma,
895 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000896 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700897 buffer_info->dma = 0;
898
Bruce Allan5f450212011-07-22 06:21:46 +0000899 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700900
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000901 /*
902 * !EOP means multiple descriptors were used to store a single
903 * packet, if that's the case we need to toss it. In fact, we
904 * need to toss every packet with the EOP bit clear and the
905 * next frame that _does_ have the EOP bit set, as it is by
906 * definition only a frame fragment
907 */
Bruce Allan5f450212011-07-22 06:21:46 +0000908 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000909 adapter->flags2 |= FLAG2_IS_DISCARDING;
910
911 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700912 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000913 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700914 /* recycle */
915 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000916 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000917 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918 goto next_desc;
919 }
920
Bruce Allan5f450212011-07-22 06:21:46 +0000921 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700922 /* recycle */
923 buffer_info->skb = skb;
924 goto next_desc;
925 }
926
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000927 /* adjust length to remove Ethernet CRC */
928 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
929 length -= 4;
930
Auke Kokbc7f75f2007-09-17 12:30:59 -0700931 total_rx_bytes += length;
932 total_rx_packets++;
933
Bruce Allanad680762008-03-28 09:15:03 -0700934 /*
935 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700936 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700937 * of reassembly being done in the stack
938 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939 if (length < copybreak) {
940 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000941 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700942 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700943 skb_copy_to_linear_data_offset(new_skb,
944 -NET_IP_ALIGN,
945 (skb->data -
946 NET_IP_ALIGN),
947 (length +
948 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700949 /* save the skb in buffer_info as good */
950 buffer_info->skb = skb;
951 skb = new_skb;
952 }
953 /* else just continue with the old one */
954 }
955 /* end copybreak code */
956 skb_put(skb, length);
957
958 /* Receive Checksum Offload */
Bruce Allan5f450212011-07-22 06:21:46 +0000959 e1000_rx_checksum(adapter, staterr,
960 le16_to_cpu(rx_desc->wb.lower.hi_dword.
961 csum_ip.csum), skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700962
Bruce Allan5f450212011-07-22 06:21:46 +0000963 e1000_receive_skb(adapter, netdev, skb, staterr,
964 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700965
966next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +0000967 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700968
969 /* return some buffers to hardware, one at a time is too slow */
970 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000971 adapter->alloc_rx_buf(adapter, cleaned_count,
972 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973 cleaned_count = 0;
974 }
975
976 /* use prefetched values */
977 rx_desc = next_rxd;
978 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000979
980 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700981 }
982 rx_ring->next_to_clean = i;
983
984 cleaned_count = e1000_desc_unused(rx_ring);
985 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000986 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700987
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700989 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 return cleaned;
991}
992
Auke Kokbc7f75f2007-09-17 12:30:59 -0700993static void e1000_put_txbuf(struct e1000_adapter *adapter,
994 struct e1000_buffer *buffer_info)
995{
Alexander Duyck03b13202009-12-02 16:45:31 +0000996 if (buffer_info->dma) {
997 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +0000998 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
999 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001000 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001001 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1002 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001003 buffer_info->dma = 0;
1004 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005 if (buffer_info->skb) {
1006 dev_kfree_skb_any(buffer_info->skb);
1007 buffer_info->skb = NULL;
1008 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001009 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010}
1011
Bruce Allan41cec6f2009-11-20 23:28:56 +00001012static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001013{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001014 struct e1000_adapter *adapter = container_of(work,
1015 struct e1000_adapter,
1016 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001017 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001018 struct e1000_ring *tx_ring = adapter->tx_ring;
1019 unsigned int i = tx_ring->next_to_clean;
1020 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1021 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001022 struct e1000_hw *hw = &adapter->hw;
1023 u16 phy_status, phy_1000t_status, phy_ext_status;
1024 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001025
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001026 if (test_bit(__E1000_DOWN, &adapter->state))
1027 return;
1028
Jeff Kirsher09357b02011-11-18 14:25:00 +00001029 if (!adapter->tx_hang_recheck &&
1030 (adapter->flags2 & FLAG2_DMA_BURST)) {
1031 /* May be block on write-back, flush and detect again
1032 * flush pending descriptor writebacks to memory
1033 */
1034 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1035 /* execute the writes immediately */
1036 e1e_flush();
1037 adapter->tx_hang_recheck = true;
1038 return;
1039 }
1040 /* Real hang detected */
1041 adapter->tx_hang_recheck = false;
1042 netif_stop_queue(netdev);
1043
Bruce Allan41cec6f2009-11-20 23:28:56 +00001044 e1e_rphy(hw, PHY_STATUS, &phy_status);
1045 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1046 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1047
1048 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1049
1050 /* detected Hardware unit hang */
1051 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001052 " TDH <%x>\n"
1053 " TDT <%x>\n"
1054 " next_to_use <%x>\n"
1055 " next_to_clean <%x>\n"
1056 "buffer_info[next_to_clean]:\n"
1057 " time_stamp <%lx>\n"
1058 " next_to_watch <%x>\n"
1059 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001060 " next_to_watch.status <%x>\n"
1061 "MAC Status <%x>\n"
1062 "PHY Status <%x>\n"
1063 "PHY 1000BASE-T Status <%x>\n"
1064 "PHY Extended Status <%x>\n"
1065 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001066 readl(adapter->hw.hw_addr + tx_ring->head),
1067 readl(adapter->hw.hw_addr + tx_ring->tail),
1068 tx_ring->next_to_use,
1069 tx_ring->next_to_clean,
1070 tx_ring->buffer_info[eop].time_stamp,
1071 eop,
1072 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001073 eop_desc->upper.fields.status,
1074 er32(STATUS),
1075 phy_status,
1076 phy_1000t_status,
1077 phy_ext_status,
1078 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001079}
1080
1081/**
1082 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1083 * @adapter: board private structure
1084 *
1085 * the return value indicates whether actual cleaning was done, there
1086 * is no guarantee that everything was cleaned
1087 **/
1088static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
1089{
1090 struct net_device *netdev = adapter->netdev;
1091 struct e1000_hw *hw = &adapter->hw;
1092 struct e1000_ring *tx_ring = adapter->tx_ring;
1093 struct e1000_tx_desc *tx_desc, *eop_desc;
1094 struct e1000_buffer *buffer_info;
1095 unsigned int i, eop;
1096 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001098 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099
1100 i = tx_ring->next_to_clean;
1101 eop = tx_ring->buffer_info[i].next_to_watch;
1102 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1103
Alexander Duyck12d04a32009-03-25 22:05:03 +00001104 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1105 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001106 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001107 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001108 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001109 tx_desc = E1000_TX_DESC(*tx_ring, i);
1110 buffer_info = &tx_ring->buffer_info[i];
1111 cleaned = (i == eop);
1112
1113 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001114 total_tx_packets += buffer_info->segs;
1115 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001116 if (buffer_info->skb) {
1117 bytes_compl += buffer_info->skb->len;
1118 pkts_compl++;
1119 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001120 }
1121
1122 e1000_put_txbuf(adapter, buffer_info);
1123 tx_desc->upper.data = 0;
1124
1125 i++;
1126 if (i == tx_ring->count)
1127 i = 0;
1128 }
1129
Terry Loftindac87612010-04-09 10:29:49 +00001130 if (i == tx_ring->next_to_use)
1131 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001132 eop = tx_ring->buffer_info[i].next_to_watch;
1133 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001134 }
1135
1136 tx_ring->next_to_clean = i;
1137
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001138 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1139
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001141 if (count && netif_carrier_ok(netdev) &&
1142 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143 /* Make sure that anybody stopping the queue after this
1144 * sees the new next_to_clean.
1145 */
1146 smp_mb();
1147
1148 if (netif_queue_stopped(netdev) &&
1149 !(test_bit(__E1000_DOWN, &adapter->state))) {
1150 netif_wake_queue(netdev);
1151 ++adapter->restart_queue;
1152 }
1153 }
1154
1155 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001156 /*
1157 * Detect a transmit hang in hardware, this serializes the
1158 * check with the clearing of time_stamp and movement of i
1159 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001160 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001161 if (tx_ring->buffer_info[i].time_stamp &&
1162 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001163 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001164 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001165 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001166 else
1167 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001168 }
1169 adapter->total_tx_bytes += total_tx_bytes;
1170 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001171 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001172}
1173
1174/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001175 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1176 * @adapter: board private structure
1177 *
1178 * the return value indicates whether actual cleaning was done, there
1179 * is no guarantee that everything was cleaned
1180 **/
1181static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1182 int *work_done, int work_to_do)
1183{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001184 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1186 struct net_device *netdev = adapter->netdev;
1187 struct pci_dev *pdev = adapter->pdev;
1188 struct e1000_ring *rx_ring = adapter->rx_ring;
1189 struct e1000_buffer *buffer_info, *next_buffer;
1190 struct e1000_ps_page *ps_page;
1191 struct sk_buff *skb;
1192 unsigned int i, j;
1193 u32 length, staterr;
1194 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001195 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001196 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1197
1198 i = rx_ring->next_to_clean;
1199 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1200 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1201 buffer_info = &rx_ring->buffer_info[i];
1202
1203 while (staterr & E1000_RXD_STAT_DD) {
1204 if (*work_done >= work_to_do)
1205 break;
1206 (*work_done)++;
1207 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001208 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209
1210 /* in the packet split case this is header only */
1211 prefetch(skb->data - NET_IP_ALIGN);
1212
1213 i++;
1214 if (i == rx_ring->count)
1215 i = 0;
1216 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1217 prefetch(next_rxd);
1218
1219 next_buffer = &rx_ring->buffer_info[i];
1220
Rusty Russell3db1cd52011-12-19 13:56:45 +00001221 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001222 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001223 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001224 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001225 buffer_info->dma = 0;
1226
Bruce Allanaf667a22010-12-31 06:10:01 +00001227 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001228 if (!(staterr & E1000_RXD_STAT_EOP))
1229 adapter->flags2 |= FLAG2_IS_DISCARDING;
1230
1231 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001232 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001234 if (staterr & E1000_RXD_STAT_EOP)
1235 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001236 goto next_desc;
1237 }
1238
1239 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1240 dev_kfree_skb_irq(skb);
1241 goto next_desc;
1242 }
1243
1244 length = le16_to_cpu(rx_desc->wb.middle.length0);
1245
1246 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001247 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001248 dev_kfree_skb_irq(skb);
1249 goto next_desc;
1250 }
1251
1252 /* Good Receive */
1253 skb_put(skb, length);
1254
1255 {
Bruce Allanad680762008-03-28 09:15:03 -07001256 /*
1257 * this looks ugly, but it seems compiler issues make it
1258 * more efficient than reusing j
1259 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1261
Bruce Allanad680762008-03-28 09:15:03 -07001262 /*
1263 * page alloc/put takes too long and effects small packet
1264 * throughput, so unsplit small packets and save the alloc/put
1265 * only valid in softirq (napi) context to call kmap_*
1266 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001267 if (l1 && (l1 <= copybreak) &&
1268 ((length + l1) <= adapter->rx_ps_bsize0)) {
1269 u8 *vaddr;
1270
Auke Kok47f44e42007-10-25 13:57:44 -07001271 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001272
Bruce Allanad680762008-03-28 09:15:03 -07001273 /*
1274 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001275 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001276 * very long
1277 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001278 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1279 PAGE_SIZE, DMA_FROM_DEVICE);
Cong Wang46790262011-11-25 23:14:23 +08001280 vaddr = kmap_atomic(ps_page->page);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001281 memcpy(skb_tail_pointer(skb), vaddr, l1);
Cong Wang46790262011-11-25 23:14:23 +08001282 kunmap_atomic(vaddr);
Nick Nunley0be3f552010-04-27 13:09:05 +00001283 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1284 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001285
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001286 /* remove the CRC */
1287 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1288 l1 -= 4;
1289
Auke Kokbc7f75f2007-09-17 12:30:59 -07001290 skb_put(skb, l1);
1291 goto copydone;
1292 } /* if */
1293 }
1294
1295 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1296 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1297 if (!length)
1298 break;
1299
Auke Kok47f44e42007-10-25 13:57:44 -07001300 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001301 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1302 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001303 ps_page->dma = 0;
1304 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1305 ps_page->page = NULL;
1306 skb->len += length;
1307 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001308 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001309 }
1310
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001311 /* strip the ethernet crc, problem is we're using pages now so
1312 * this whole operation can get a little cpu intensive
1313 */
1314 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1315 pskb_trim(skb, skb->len - 4);
1316
Auke Kokbc7f75f2007-09-17 12:30:59 -07001317copydone:
1318 total_rx_bytes += skb->len;
1319 total_rx_packets++;
1320
1321 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1322 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1323
1324 if (rx_desc->wb.upper.header_status &
1325 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1326 adapter->rx_hdr_split++;
1327
1328 e1000_receive_skb(adapter, netdev, skb,
1329 staterr, rx_desc->wb.middle.vlan);
1330
1331next_desc:
1332 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1333 buffer_info->skb = NULL;
1334
1335 /* return some buffers to hardware, one at a time is too slow */
1336 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001337 adapter->alloc_rx_buf(adapter, cleaned_count,
1338 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001339 cleaned_count = 0;
1340 }
1341
1342 /* use prefetched values */
1343 rx_desc = next_rxd;
1344 buffer_info = next_buffer;
1345
1346 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1347 }
1348 rx_ring->next_to_clean = i;
1349
1350 cleaned_count = e1000_desc_unused(rx_ring);
1351 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001352 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001353
Auke Kokbc7f75f2007-09-17 12:30:59 -07001354 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001355 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001356 return cleaned;
1357}
1358
1359/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001360 * e1000_consume_page - helper function
1361 **/
1362static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1363 u16 length)
1364{
1365 bi->page = NULL;
1366 skb->len += length;
1367 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001368 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001369}
1370
1371/**
1372 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1373 * @adapter: board private structure
1374 *
1375 * the return value indicates whether actual cleaning was done, there
1376 * is no guarantee that everything was cleaned
1377 **/
1378
1379static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1380 int *work_done, int work_to_do)
1381{
1382 struct net_device *netdev = adapter->netdev;
1383 struct pci_dev *pdev = adapter->pdev;
1384 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +00001385 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001386 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001387 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001388 unsigned int i;
1389 int cleaned_count = 0;
1390 bool cleaned = false;
1391 unsigned int total_rx_bytes=0, total_rx_packets=0;
1392
1393 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001394 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1395 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001396 buffer_info = &rx_ring->buffer_info[i];
1397
Bruce Allan5f450212011-07-22 06:21:46 +00001398 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001399 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001400
1401 if (*work_done >= work_to_do)
1402 break;
1403 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001404 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001405
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001406 skb = buffer_info->skb;
1407 buffer_info->skb = NULL;
1408
1409 ++i;
1410 if (i == rx_ring->count)
1411 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001412 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001413 prefetch(next_rxd);
1414
1415 next_buffer = &rx_ring->buffer_info[i];
1416
1417 cleaned = true;
1418 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001419 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1420 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001421 buffer_info->dma = 0;
1422
Bruce Allan5f450212011-07-22 06:21:46 +00001423 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001424
1425 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001426 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1427 (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
1428 /* recycle both page and skb */
1429 buffer_info->skb = skb;
1430 /* an error means any chain goes out the window too */
1431 if (rx_ring->rx_skb_top)
1432 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1433 rx_ring->rx_skb_top = NULL;
1434 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001435 }
1436
Bruce Allanf0f1a172010-12-11 05:53:32 +00001437#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001438 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001439 /* this descriptor is only the beginning (or middle) */
1440 if (!rxtop) {
1441 /* this is the beginning of a chain */
1442 rxtop = skb;
1443 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1444 0, length);
1445 } else {
1446 /* this is the middle of a chain */
1447 skb_fill_page_desc(rxtop,
1448 skb_shinfo(rxtop)->nr_frags,
1449 buffer_info->page, 0, length);
1450 /* re-use the skb, only consumed the page */
1451 buffer_info->skb = skb;
1452 }
1453 e1000_consume_page(buffer_info, rxtop, length);
1454 goto next_desc;
1455 } else {
1456 if (rxtop) {
1457 /* end of the chain */
1458 skb_fill_page_desc(rxtop,
1459 skb_shinfo(rxtop)->nr_frags,
1460 buffer_info->page, 0, length);
1461 /* re-use the current skb, we only consumed the
1462 * page */
1463 buffer_info->skb = skb;
1464 skb = rxtop;
1465 rxtop = NULL;
1466 e1000_consume_page(buffer_info, skb, length);
1467 } else {
1468 /* no chain, got EOP, this buf is the packet
1469 * copybreak to save the put_page/alloc_page */
1470 if (length <= copybreak &&
1471 skb_tailroom(skb) >= length) {
1472 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001473 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001474 memcpy(skb_tail_pointer(skb), vaddr,
1475 length);
Cong Wang46790262011-11-25 23:14:23 +08001476 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001477 /* re-use the page, so don't erase
1478 * buffer_info->page */
1479 skb_put(skb, length);
1480 } else {
1481 skb_fill_page_desc(skb, 0,
1482 buffer_info->page, 0,
1483 length);
1484 e1000_consume_page(buffer_info, skb,
1485 length);
1486 }
1487 }
1488 }
1489
1490 /* Receive Checksum Offload XXX recompute due to CRC strip? */
Bruce Allan5f450212011-07-22 06:21:46 +00001491 e1000_rx_checksum(adapter, staterr,
1492 le16_to_cpu(rx_desc->wb.lower.hi_dword.
1493 csum_ip.csum), skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001494
1495 /* probably a little skewed due to removing CRC */
1496 total_rx_bytes += skb->len;
1497 total_rx_packets++;
1498
1499 /* eth type trans needs skb->data to point to something */
1500 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001501 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001502 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001503 goto next_desc;
1504 }
1505
Bruce Allan5f450212011-07-22 06:21:46 +00001506 e1000_receive_skb(adapter, netdev, skb, staterr,
1507 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001508
1509next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001510 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001511
1512 /* return some buffers to hardware, one at a time is too slow */
1513 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001514 adapter->alloc_rx_buf(adapter, cleaned_count,
1515 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001516 cleaned_count = 0;
1517 }
1518
1519 /* use prefetched values */
1520 rx_desc = next_rxd;
1521 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001522
1523 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001524 }
1525 rx_ring->next_to_clean = i;
1526
1527 cleaned_count = e1000_desc_unused(rx_ring);
1528 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001529 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001530
1531 adapter->total_rx_bytes += total_rx_bytes;
1532 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001533 return cleaned;
1534}
1535
1536/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001537 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1538 * @adapter: board private structure
1539 **/
1540static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1541{
1542 struct e1000_ring *rx_ring = adapter->rx_ring;
1543 struct e1000_buffer *buffer_info;
1544 struct e1000_ps_page *ps_page;
1545 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001546 unsigned int i, j;
1547
1548 /* Free all the Rx ring sk_buffs */
1549 for (i = 0; i < rx_ring->count; i++) {
1550 buffer_info = &rx_ring->buffer_info[i];
1551 if (buffer_info->dma) {
1552 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001553 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001554 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001555 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001556 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001557 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001558 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001559 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001560 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001561 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001563 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001564 buffer_info->dma = 0;
1565 }
1566
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001567 if (buffer_info->page) {
1568 put_page(buffer_info->page);
1569 buffer_info->page = NULL;
1570 }
1571
Auke Kokbc7f75f2007-09-17 12:30:59 -07001572 if (buffer_info->skb) {
1573 dev_kfree_skb(buffer_info->skb);
1574 buffer_info->skb = NULL;
1575 }
1576
1577 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001578 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001579 if (!ps_page->page)
1580 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001581 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1582 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001583 ps_page->dma = 0;
1584 put_page(ps_page->page);
1585 ps_page->page = NULL;
1586 }
1587 }
1588
1589 /* there also may be some cached data from a chained receive */
1590 if (rx_ring->rx_skb_top) {
1591 dev_kfree_skb(rx_ring->rx_skb_top);
1592 rx_ring->rx_skb_top = NULL;
1593 }
1594
Auke Kokbc7f75f2007-09-17 12:30:59 -07001595 /* Zero out the descriptor ring */
1596 memset(rx_ring->desc, 0, rx_ring->size);
1597
1598 rx_ring->next_to_clean = 0;
1599 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001600 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001601
1602 writel(0, adapter->hw.hw_addr + rx_ring->head);
1603 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1604}
1605
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001606static void e1000e_downshift_workaround(struct work_struct *work)
1607{
1608 struct e1000_adapter *adapter = container_of(work,
1609 struct e1000_adapter, downshift_task);
1610
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001611 if (test_bit(__E1000_DOWN, &adapter->state))
1612 return;
1613
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001614 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1615}
1616
Auke Kokbc7f75f2007-09-17 12:30:59 -07001617/**
1618 * e1000_intr_msi - Interrupt Handler
1619 * @irq: interrupt number
1620 * @data: pointer to a network interface device structure
1621 **/
1622static irqreturn_t e1000_intr_msi(int irq, void *data)
1623{
1624 struct net_device *netdev = data;
1625 struct e1000_adapter *adapter = netdev_priv(netdev);
1626 struct e1000_hw *hw = &adapter->hw;
1627 u32 icr = er32(ICR);
1628
Bruce Allanad680762008-03-28 09:15:03 -07001629 /*
1630 * read ICR disables interrupts using IAM
1631 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001632
dave graham573cca82009-02-10 12:52:05 +00001633 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001635 /*
1636 * ICH8 workaround-- Call gig speed drop workaround on cable
1637 * disconnect (LSC) before accessing any PHY registers
1638 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001639 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1640 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001641 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001642
Bruce Allanad680762008-03-28 09:15:03 -07001643 /*
1644 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001645 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001646 * adapter in watchdog
1647 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001648 if (netif_carrier_ok(netdev) &&
1649 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1650 /* disable receives */
1651 u32 rctl = er32(RCTL);
1652 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001653 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654 }
1655 /* guard against interrupt when we're going down */
1656 if (!test_bit(__E1000_DOWN, &adapter->state))
1657 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1658 }
1659
Ben Hutchings288379f2009-01-19 16:43:59 -08001660 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001661 adapter->total_tx_bytes = 0;
1662 adapter->total_tx_packets = 0;
1663 adapter->total_rx_bytes = 0;
1664 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001665 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666 }
1667
1668 return IRQ_HANDLED;
1669}
1670
1671/**
1672 * e1000_intr - Interrupt Handler
1673 * @irq: interrupt number
1674 * @data: pointer to a network interface device structure
1675 **/
1676static irqreturn_t e1000_intr(int irq, void *data)
1677{
1678 struct net_device *netdev = data;
1679 struct e1000_adapter *adapter = netdev_priv(netdev);
1680 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001682
Bruce Allana68ea772009-11-20 23:23:16 +00001683 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001684 return IRQ_NONE; /* Not our interrupt */
1685
Bruce Allanad680762008-03-28 09:15:03 -07001686 /*
1687 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1688 * not set, then the adapter didn't send an interrupt
1689 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001690 if (!(icr & E1000_ICR_INT_ASSERTED))
1691 return IRQ_NONE;
1692
Bruce Allanad680762008-03-28 09:15:03 -07001693 /*
1694 * Interrupt Auto-Mask...upon reading ICR,
1695 * interrupts are masked. No need for the
1696 * IMC write
1697 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001698
dave graham573cca82009-02-10 12:52:05 +00001699 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001700 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001701 /*
1702 * ICH8 workaround-- Call gig speed drop workaround on cable
1703 * disconnect (LSC) before accessing any PHY registers
1704 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1706 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001707 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708
Bruce Allanad680762008-03-28 09:15:03 -07001709 /*
1710 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001711 * For packet buffer work-around on link down event;
1712 * disable receives here in the ISR and
1713 * reset adapter in watchdog
1714 */
1715 if (netif_carrier_ok(netdev) &&
1716 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1717 /* disable receives */
1718 rctl = er32(RCTL);
1719 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001720 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721 }
1722 /* guard against interrupt when we're going down */
1723 if (!test_bit(__E1000_DOWN, &adapter->state))
1724 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1725 }
1726
Ben Hutchings288379f2009-01-19 16:43:59 -08001727 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001728 adapter->total_tx_bytes = 0;
1729 adapter->total_tx_packets = 0;
1730 adapter->total_rx_bytes = 0;
1731 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001732 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001733 }
1734
1735 return IRQ_HANDLED;
1736}
1737
Bruce Allan4662e822008-08-26 18:37:06 -07001738static irqreturn_t e1000_msix_other(int irq, void *data)
1739{
1740 struct net_device *netdev = data;
1741 struct e1000_adapter *adapter = netdev_priv(netdev);
1742 struct e1000_hw *hw = &adapter->hw;
1743 u32 icr = er32(ICR);
1744
1745 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001746 if (!test_bit(__E1000_DOWN, &adapter->state))
1747 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001748 return IRQ_NONE;
1749 }
1750
1751 if (icr & adapter->eiac_mask)
1752 ew32(ICS, (icr & adapter->eiac_mask));
1753
1754 if (icr & E1000_ICR_OTHER) {
1755 if (!(icr & E1000_ICR_LSC))
1756 goto no_link_interrupt;
1757 hw->mac.get_link_status = 1;
1758 /* guard against interrupt when we're going down */
1759 if (!test_bit(__E1000_DOWN, &adapter->state))
1760 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1761 }
1762
1763no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001764 if (!test_bit(__E1000_DOWN, &adapter->state))
1765 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001766
1767 return IRQ_HANDLED;
1768}
1769
1770
1771static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1772{
1773 struct net_device *netdev = data;
1774 struct e1000_adapter *adapter = netdev_priv(netdev);
1775 struct e1000_hw *hw = &adapter->hw;
1776 struct e1000_ring *tx_ring = adapter->tx_ring;
1777
1778
1779 adapter->total_tx_bytes = 0;
1780 adapter->total_tx_packets = 0;
1781
1782 if (!e1000_clean_tx_irq(adapter))
1783 /* Ring was not completely cleaned, so fire another interrupt */
1784 ew32(ICS, tx_ring->ims_val);
1785
1786 return IRQ_HANDLED;
1787}
1788
1789static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1790{
1791 struct net_device *netdev = data;
1792 struct e1000_adapter *adapter = netdev_priv(netdev);
1793
1794 /* Write the ITR value calculated at the end of the
1795 * previous interrupt.
1796 */
1797 if (adapter->rx_ring->set_itr) {
1798 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1799 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1800 adapter->rx_ring->set_itr = 0;
1801 }
1802
Ben Hutchings288379f2009-01-19 16:43:59 -08001803 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001804 adapter->total_rx_bytes = 0;
1805 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001806 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001807 }
1808 return IRQ_HANDLED;
1809}
1810
1811/**
1812 * e1000_configure_msix - Configure MSI-X hardware
1813 *
1814 * e1000_configure_msix sets up the hardware to properly
1815 * generate MSI-X interrupts.
1816 **/
1817static void e1000_configure_msix(struct e1000_adapter *adapter)
1818{
1819 struct e1000_hw *hw = &adapter->hw;
1820 struct e1000_ring *rx_ring = adapter->rx_ring;
1821 struct e1000_ring *tx_ring = adapter->tx_ring;
1822 int vector = 0;
1823 u32 ctrl_ext, ivar = 0;
1824
1825 adapter->eiac_mask = 0;
1826
1827 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1828 if (hw->mac.type == e1000_82574) {
1829 u32 rfctl = er32(RFCTL);
1830 rfctl |= E1000_RFCTL_ACK_DIS;
1831 ew32(RFCTL, rfctl);
1832 }
1833
1834#define E1000_IVAR_INT_ALLOC_VALID 0x8
1835 /* Configure Rx vector */
1836 rx_ring->ims_val = E1000_IMS_RXQ0;
1837 adapter->eiac_mask |= rx_ring->ims_val;
1838 if (rx_ring->itr_val)
1839 writel(1000000000 / (rx_ring->itr_val * 256),
1840 hw->hw_addr + rx_ring->itr_register);
1841 else
1842 writel(1, hw->hw_addr + rx_ring->itr_register);
1843 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1844
1845 /* Configure Tx vector */
1846 tx_ring->ims_val = E1000_IMS_TXQ0;
1847 vector++;
1848 if (tx_ring->itr_val)
1849 writel(1000000000 / (tx_ring->itr_val * 256),
1850 hw->hw_addr + tx_ring->itr_register);
1851 else
1852 writel(1, hw->hw_addr + tx_ring->itr_register);
1853 adapter->eiac_mask |= tx_ring->ims_val;
1854 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1855
1856 /* set vector for Other Causes, e.g. link changes */
1857 vector++;
1858 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1859 if (rx_ring->itr_val)
1860 writel(1000000000 / (rx_ring->itr_val * 256),
1861 hw->hw_addr + E1000_EITR_82574(vector));
1862 else
1863 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1864
1865 /* Cause Tx interrupts on every write back */
1866 ivar |= (1 << 31);
1867
1868 ew32(IVAR, ivar);
1869
1870 /* enable MSI-X PBA support */
1871 ctrl_ext = er32(CTRL_EXT);
1872 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1873
1874 /* Auto-Mask Other interrupts upon ICR read */
1875#define E1000_EIAC_MASK_82574 0x01F00000
1876 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1877 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1878 ew32(CTRL_EXT, ctrl_ext);
1879 e1e_flush();
1880}
1881
1882void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1883{
1884 if (adapter->msix_entries) {
1885 pci_disable_msix(adapter->pdev);
1886 kfree(adapter->msix_entries);
1887 adapter->msix_entries = NULL;
1888 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1889 pci_disable_msi(adapter->pdev);
1890 adapter->flags &= ~FLAG_MSI_ENABLED;
1891 }
Bruce Allan4662e822008-08-26 18:37:06 -07001892}
1893
1894/**
1895 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1896 *
1897 * Attempt to configure interrupts using the best available
1898 * capabilities of the hardware and kernel.
1899 **/
1900void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1901{
1902 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001903 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001904
1905 switch (adapter->int_mode) {
1906 case E1000E_INT_MODE_MSIX:
1907 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001908 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1909 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001910 sizeof(struct msix_entry),
1911 GFP_KERNEL);
1912 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001913 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001914 adapter->msix_entries[i].entry = i;
1915
1916 err = pci_enable_msix(adapter->pdev,
1917 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001918 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001919 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001920 return;
1921 }
1922 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00001923 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001924 e1000e_reset_interrupt_capability(adapter);
1925 }
1926 adapter->int_mode = E1000E_INT_MODE_MSI;
1927 /* Fall through */
1928 case E1000E_INT_MODE_MSI:
1929 if (!pci_enable_msi(adapter->pdev)) {
1930 adapter->flags |= FLAG_MSI_ENABLED;
1931 } else {
1932 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00001933 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001934 }
1935 /* Fall through */
1936 case E1000E_INT_MODE_LEGACY:
1937 /* Don't do anything; this is the system default */
1938 break;
1939 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001940
1941 /* store the number of vectors being used */
1942 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001943}
1944
1945/**
1946 * e1000_request_msix - Initialize MSI-X interrupts
1947 *
1948 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1949 * kernel.
1950 **/
1951static int e1000_request_msix(struct e1000_adapter *adapter)
1952{
1953 struct net_device *netdev = adapter->netdev;
1954 int err = 0, vector = 0;
1955
1956 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001957 snprintf(adapter->rx_ring->name,
1958 sizeof(adapter->rx_ring->name) - 1,
1959 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001960 else
1961 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1962 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001963 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001964 netdev);
1965 if (err)
1966 goto out;
1967 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1968 adapter->rx_ring->itr_val = adapter->itr;
1969 vector++;
1970
1971 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001972 snprintf(adapter->tx_ring->name,
1973 sizeof(adapter->tx_ring->name) - 1,
1974 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001975 else
1976 memcpy(adapter->tx_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_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001979 netdev);
1980 if (err)
1981 goto out;
1982 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1983 adapter->tx_ring->itr_val = adapter->itr;
1984 vector++;
1985
1986 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001987 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001988 if (err)
1989 goto out;
1990
1991 e1000_configure_msix(adapter);
1992 return 0;
1993out:
1994 return err;
1995}
1996
Bruce Allanf8d59f72008-08-08 18:36:11 -07001997/**
1998 * e1000_request_irq - initialize interrupts
1999 *
2000 * Attempts to configure interrupts using the best available
2001 * capabilities of the hardware and kernel.
2002 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002003static int e1000_request_irq(struct e1000_adapter *adapter)
2004{
2005 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002006 int err;
2007
Bruce Allan4662e822008-08-26 18:37:06 -07002008 if (adapter->msix_entries) {
2009 err = e1000_request_msix(adapter);
2010 if (!err)
2011 return err;
2012 /* fall back to MSI */
2013 e1000e_reset_interrupt_capability(adapter);
2014 adapter->int_mode = E1000E_INT_MODE_MSI;
2015 e1000e_set_interrupt_capability(adapter);
2016 }
2017 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002018 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002019 netdev->name, netdev);
2020 if (!err)
2021 return err;
2022
2023 /* fall back to legacy interrupt */
2024 e1000e_reset_interrupt_capability(adapter);
2025 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002026 }
2027
Joe Perchesa0607fd2009-11-18 23:29:17 -08002028 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002029 netdev->name, netdev);
2030 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002031 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002032
2033 return err;
2034}
2035
2036static void e1000_free_irq(struct e1000_adapter *adapter)
2037{
2038 struct net_device *netdev = adapter->netdev;
2039
Bruce Allan4662e822008-08-26 18:37:06 -07002040 if (adapter->msix_entries) {
2041 int vector = 0;
2042
2043 free_irq(adapter->msix_entries[vector].vector, netdev);
2044 vector++;
2045
2046 free_irq(adapter->msix_entries[vector].vector, netdev);
2047 vector++;
2048
2049 /* Other Causes interrupt vector */
2050 free_irq(adapter->msix_entries[vector].vector, netdev);
2051 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002052 }
Bruce Allan4662e822008-08-26 18:37:06 -07002053
2054 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002055}
2056
2057/**
2058 * e1000_irq_disable - Mask off interrupt generation on the NIC
2059 **/
2060static void e1000_irq_disable(struct e1000_adapter *adapter)
2061{
2062 struct e1000_hw *hw = &adapter->hw;
2063
Auke Kokbc7f75f2007-09-17 12:30:59 -07002064 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002065 if (adapter->msix_entries)
2066 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002067 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002068
2069 if (adapter->msix_entries) {
2070 int i;
2071 for (i = 0; i < adapter->num_vectors; i++)
2072 synchronize_irq(adapter->msix_entries[i].vector);
2073 } else {
2074 synchronize_irq(adapter->pdev->irq);
2075 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002076}
2077
2078/**
2079 * e1000_irq_enable - Enable default interrupt generation settings
2080 **/
2081static void e1000_irq_enable(struct e1000_adapter *adapter)
2082{
2083 struct e1000_hw *hw = &adapter->hw;
2084
Bruce Allan4662e822008-08-26 18:37:06 -07002085 if (adapter->msix_entries) {
2086 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2087 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2088 } else {
2089 ew32(IMS, IMS_ENABLE_MASK);
2090 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002091 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002092}
2093
2094/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002095 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002096 * @adapter: address of board private structure
2097 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002098 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002099 * For ASF and Pass Through versions of f/w this means that
2100 * the driver is loaded. For AMT version (only with 82573)
2101 * of the f/w this means that the network i/f is open.
2102 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002103void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002104{
2105 struct e1000_hw *hw = &adapter->hw;
2106 u32 ctrl_ext;
2107 u32 swsm;
2108
2109 /* Let firmware know the driver has taken over */
2110 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2111 swsm = er32(SWSM);
2112 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2113 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2114 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002115 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002116 }
2117}
2118
2119/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002120 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002121 * @adapter: address of board private structure
2122 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002123 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002124 * For ASF and Pass Through versions of f/w this means that the
2125 * driver is no longer loaded. For AMT version (only with 82573) i
2126 * of the f/w this means that the network i/f is closed.
2127 *
2128 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002129void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002130{
2131 struct e1000_hw *hw = &adapter->hw;
2132 u32 ctrl_ext;
2133 u32 swsm;
2134
2135 /* Let firmware taken over control of h/w */
2136 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2137 swsm = er32(SWSM);
2138 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2139 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2140 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002141 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002142 }
2143}
2144
Auke Kokbc7f75f2007-09-17 12:30:59 -07002145/**
2146 * @e1000_alloc_ring - allocate memory for a ring structure
2147 **/
2148static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2149 struct e1000_ring *ring)
2150{
2151 struct pci_dev *pdev = adapter->pdev;
2152
2153 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2154 GFP_KERNEL);
2155 if (!ring->desc)
2156 return -ENOMEM;
2157
2158 return 0;
2159}
2160
2161/**
2162 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2163 * @adapter: board private structure
2164 *
2165 * Return 0 on success, negative on failure
2166 **/
2167int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2168{
2169 struct e1000_ring *tx_ring = adapter->tx_ring;
2170 int err = -ENOMEM, size;
2171
2172 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002173 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002174 if (!tx_ring->buffer_info)
2175 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002176
2177 /* round up to nearest 4K */
2178 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2179 tx_ring->size = ALIGN(tx_ring->size, 4096);
2180
2181 err = e1000_alloc_ring_dma(adapter, tx_ring);
2182 if (err)
2183 goto err;
2184
2185 tx_ring->next_to_use = 0;
2186 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002187
2188 return 0;
2189err:
2190 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002191 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002192 return err;
2193}
2194
2195/**
2196 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2197 * @adapter: board private structure
2198 *
2199 * Returns 0 on success, negative on failure
2200 **/
2201int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2202{
2203 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002204 struct e1000_buffer *buffer_info;
2205 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002206
2207 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002208 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002209 if (!rx_ring->buffer_info)
2210 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002211
Auke Kok47f44e42007-10-25 13:57:44 -07002212 for (i = 0; i < rx_ring->count; i++) {
2213 buffer_info = &rx_ring->buffer_info[i];
2214 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2215 sizeof(struct e1000_ps_page),
2216 GFP_KERNEL);
2217 if (!buffer_info->ps_pages)
2218 goto err_pages;
2219 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002220
2221 desc_len = sizeof(union e1000_rx_desc_packet_split);
2222
2223 /* Round up to nearest 4K */
2224 rx_ring->size = rx_ring->count * desc_len;
2225 rx_ring->size = ALIGN(rx_ring->size, 4096);
2226
2227 err = e1000_alloc_ring_dma(adapter, rx_ring);
2228 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002229 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002230
2231 rx_ring->next_to_clean = 0;
2232 rx_ring->next_to_use = 0;
2233 rx_ring->rx_skb_top = NULL;
2234
2235 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002236
2237err_pages:
2238 for (i = 0; i < rx_ring->count; i++) {
2239 buffer_info = &rx_ring->buffer_info[i];
2240 kfree(buffer_info->ps_pages);
2241 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002242err:
2243 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002244 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002245 return err;
2246}
2247
2248/**
2249 * e1000_clean_tx_ring - Free Tx Buffers
2250 * @adapter: board private structure
2251 **/
2252static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2253{
2254 struct e1000_ring *tx_ring = adapter->tx_ring;
2255 struct e1000_buffer *buffer_info;
2256 unsigned long size;
2257 unsigned int i;
2258
2259 for (i = 0; i < tx_ring->count; i++) {
2260 buffer_info = &tx_ring->buffer_info[i];
2261 e1000_put_txbuf(adapter, buffer_info);
2262 }
2263
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002264 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002265 size = sizeof(struct e1000_buffer) * tx_ring->count;
2266 memset(tx_ring->buffer_info, 0, size);
2267
2268 memset(tx_ring->desc, 0, tx_ring->size);
2269
2270 tx_ring->next_to_use = 0;
2271 tx_ring->next_to_clean = 0;
2272
2273 writel(0, adapter->hw.hw_addr + tx_ring->head);
2274 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2275}
2276
2277/**
2278 * e1000e_free_tx_resources - Free Tx Resources per Queue
2279 * @adapter: board private structure
2280 *
2281 * Free all transmit software resources
2282 **/
2283void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2284{
2285 struct pci_dev *pdev = adapter->pdev;
2286 struct e1000_ring *tx_ring = adapter->tx_ring;
2287
2288 e1000_clean_tx_ring(adapter);
2289
2290 vfree(tx_ring->buffer_info);
2291 tx_ring->buffer_info = NULL;
2292
2293 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2294 tx_ring->dma);
2295 tx_ring->desc = NULL;
2296}
2297
2298/**
2299 * e1000e_free_rx_resources - Free Rx Resources
2300 * @adapter: board private structure
2301 *
2302 * Free all receive software resources
2303 **/
2304
2305void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2306{
2307 struct pci_dev *pdev = adapter->pdev;
2308 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002309 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002310
2311 e1000_clean_rx_ring(adapter);
2312
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002313 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002314 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002315
Auke Kokbc7f75f2007-09-17 12:30:59 -07002316 vfree(rx_ring->buffer_info);
2317 rx_ring->buffer_info = NULL;
2318
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2320 rx_ring->dma);
2321 rx_ring->desc = NULL;
2322}
2323
2324/**
2325 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002326 * @adapter: pointer to adapter
2327 * @itr_setting: current adapter->itr
2328 * @packets: the number of packets during this measurement interval
2329 * @bytes: the number of bytes during this measurement interval
2330 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002331 * Stores a new ITR value based on packets and byte
2332 * counts during the last interrupt. The advantage of per interrupt
2333 * computation is faster updates and more accurate ITR for the current
2334 * traffic pattern. Constants in this function were computed
2335 * based on theoretical maximum wire speed and thresholds were set based
2336 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002337 * while increasing bulk throughput. This functionality is controlled
2338 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002339 **/
2340static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2341 u16 itr_setting, int packets,
2342 int bytes)
2343{
2344 unsigned int retval = itr_setting;
2345
2346 if (packets == 0)
2347 goto update_itr_done;
2348
2349 switch (itr_setting) {
2350 case lowest_latency:
2351 /* handle TSO and jumbo frames */
2352 if (bytes/packets > 8000)
2353 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002354 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002355 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356 break;
2357 case low_latency: /* 50 usec aka 20000 ints/s */
2358 if (bytes > 10000) {
2359 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002360 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002361 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002362 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002363 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002364 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366 } else if (bytes/packets > 2000) {
2367 retval = bulk_latency;
2368 } else if (packets <= 2 && bytes < 512) {
2369 retval = lowest_latency;
2370 }
2371 break;
2372 case bulk_latency: /* 250 usec aka 4000 ints/s */
2373 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002374 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002375 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002376 } else if (bytes < 6000) {
2377 retval = low_latency;
2378 }
2379 break;
2380 }
2381
2382update_itr_done:
2383 return retval;
2384}
2385
2386static void e1000_set_itr(struct e1000_adapter *adapter)
2387{
2388 struct e1000_hw *hw = &adapter->hw;
2389 u16 current_itr;
2390 u32 new_itr = adapter->itr;
2391
2392 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2393 if (adapter->link_speed != SPEED_1000) {
2394 current_itr = 0;
2395 new_itr = 4000;
2396 goto set_itr_now;
2397 }
2398
Bruce Allan828bac82010-09-29 21:39:37 +00002399 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2400 new_itr = 0;
2401 goto set_itr_now;
2402 }
2403
Auke Kokbc7f75f2007-09-17 12:30:59 -07002404 adapter->tx_itr = e1000_update_itr(adapter,
2405 adapter->tx_itr,
2406 adapter->total_tx_packets,
2407 adapter->total_tx_bytes);
2408 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2409 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2410 adapter->tx_itr = low_latency;
2411
2412 adapter->rx_itr = e1000_update_itr(adapter,
2413 adapter->rx_itr,
2414 adapter->total_rx_packets,
2415 adapter->total_rx_bytes);
2416 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2417 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2418 adapter->rx_itr = low_latency;
2419
2420 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2421
2422 switch (current_itr) {
2423 /* counts and packets in update_itr are dependent on these numbers */
2424 case lowest_latency:
2425 new_itr = 70000;
2426 break;
2427 case low_latency:
2428 new_itr = 20000; /* aka hwitr = ~200 */
2429 break;
2430 case bulk_latency:
2431 new_itr = 4000;
2432 break;
2433 default:
2434 break;
2435 }
2436
2437set_itr_now:
2438 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002439 /*
2440 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002441 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002442 * increasing
2443 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002444 new_itr = new_itr > adapter->itr ?
2445 min(adapter->itr + (new_itr >> 2), new_itr) :
2446 new_itr;
2447 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002448 adapter->rx_ring->itr_val = new_itr;
2449 if (adapter->msix_entries)
2450 adapter->rx_ring->set_itr = 1;
2451 else
Bruce Allan828bac82010-09-29 21:39:37 +00002452 if (new_itr)
2453 ew32(ITR, 1000000000 / (new_itr * 256));
2454 else
2455 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002456 }
2457}
2458
2459/**
Bruce Allan4662e822008-08-26 18:37:06 -07002460 * e1000_alloc_queues - Allocate memory for all rings
2461 * @adapter: board private structure to initialize
2462 **/
2463static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2464{
2465 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2466 if (!adapter->tx_ring)
2467 goto err;
2468
2469 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2470 if (!adapter->rx_ring)
2471 goto err;
2472
2473 return 0;
2474err:
2475 e_err("Unable to allocate memory for queues\n");
2476 kfree(adapter->rx_ring);
2477 kfree(adapter->tx_ring);
2478 return -ENOMEM;
2479}
2480
2481/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002482 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002483 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002484 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002485 **/
2486static int e1000_clean(struct napi_struct *napi, int budget)
2487{
2488 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002489 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002490 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002491 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002492
Wang Chen4cf16532008-11-12 23:38:14 -08002493 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002494
Bruce Allan4662e822008-08-26 18:37:06 -07002495 if (adapter->msix_entries &&
2496 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2497 goto clean_rx;
2498
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002499 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500
Bruce Allan4662e822008-08-26 18:37:06 -07002501clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502 adapter->clean_rx(adapter, &work_done, budget);
2503
Alexander Duyck12d04a32009-03-25 22:05:03 +00002504 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002505 work_done = budget;
2506
David S. Miller53e52c72008-01-07 21:06:12 -08002507 /* If budget not fully consumed, exit the polling mode */
2508 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 if (adapter->itr_setting & 3)
2510 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002511 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002512 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2513 if (adapter->msix_entries)
2514 ew32(IMS, adapter->rx_ring->ims_val);
2515 else
2516 e1000_irq_enable(adapter);
2517 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002518 }
2519
2520 return work_done;
2521}
2522
Jiri Pirko8e586132011-12-08 19:52:37 -05002523static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002524{
2525 struct e1000_adapter *adapter = netdev_priv(netdev);
2526 struct e1000_hw *hw = &adapter->hw;
2527 u32 vfta, index;
2528
2529 /* don't update vlan cookie if already programmed */
2530 if ((adapter->hw.mng_cookie.status &
2531 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2532 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002533 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002534
Auke Kokbc7f75f2007-09-17 12:30:59 -07002535 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002536 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2537 index = (vid >> 5) & 0x7F;
2538 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2539 vfta |= (1 << (vid & 0x1F));
2540 hw->mac.ops.write_vfta(hw, index, vfta);
2541 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002542
2543 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002544
2545 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002546}
2547
Jiri Pirko8e586132011-12-08 19:52:37 -05002548static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002549{
2550 struct e1000_adapter *adapter = netdev_priv(netdev);
2551 struct e1000_hw *hw = &adapter->hw;
2552 u32 vfta, index;
2553
Auke Kokbc7f75f2007-09-17 12:30:59 -07002554 if ((adapter->hw.mng_cookie.status &
2555 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2556 (vid == adapter->mng_vlan_id)) {
2557 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002558 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002559 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560 }
2561
2562 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002563 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2564 index = (vid >> 5) & 0x7F;
2565 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2566 vfta &= ~(1 << (vid & 0x1F));
2567 hw->mac.ops.write_vfta(hw, index, vfta);
2568 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002569
2570 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002571
2572 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002573}
2574
2575/**
2576 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2577 * @adapter: board private structure to initialize
2578 **/
2579static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2580{
2581 struct net_device *netdev = adapter->netdev;
2582 struct e1000_hw *hw = &adapter->hw;
2583 u32 rctl;
2584
2585 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2586 /* disable VLAN receive filtering */
2587 rctl = er32(RCTL);
2588 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2589 ew32(RCTL, rctl);
2590
2591 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2592 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2593 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2594 }
2595 }
2596}
2597
2598/**
2599 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2600 * @adapter: board private structure to initialize
2601 **/
2602static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2603{
2604 struct e1000_hw *hw = &adapter->hw;
2605 u32 rctl;
2606
2607 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2608 /* enable VLAN receive filtering */
2609 rctl = er32(RCTL);
2610 rctl |= E1000_RCTL_VFE;
2611 rctl &= ~E1000_RCTL_CFIEN;
2612 ew32(RCTL, rctl);
2613 }
2614}
2615
2616/**
2617 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2618 * @adapter: board private structure to initialize
2619 **/
2620static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2621{
2622 struct e1000_hw *hw = &adapter->hw;
2623 u32 ctrl;
2624
2625 /* disable VLAN tag insert/strip */
2626 ctrl = er32(CTRL);
2627 ctrl &= ~E1000_CTRL_VME;
2628 ew32(CTRL, ctrl);
2629}
2630
2631/**
2632 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2633 * @adapter: board private structure to initialize
2634 **/
2635static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2636{
2637 struct e1000_hw *hw = &adapter->hw;
2638 u32 ctrl;
2639
2640 /* enable VLAN tag insert/strip */
2641 ctrl = er32(CTRL);
2642 ctrl |= E1000_CTRL_VME;
2643 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002644}
2645
2646static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2647{
2648 struct net_device *netdev = adapter->netdev;
2649 u16 vid = adapter->hw.mng_cookie.vlan_id;
2650 u16 old_vid = adapter->mng_vlan_id;
2651
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002652 if (adapter->hw.mng_cookie.status &
2653 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2654 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002655 adapter->mng_vlan_id = vid;
2656 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002657
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002658 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2659 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002660}
2661
2662static void e1000_restore_vlan(struct e1000_adapter *adapter)
2663{
2664 u16 vid;
2665
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002666 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002667
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002668 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002669 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002670}
2671
Bruce Allancd791612010-05-10 14:59:51 +00002672static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002673{
2674 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002675 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002676
2677 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2678 return;
2679
2680 manc = er32(MANC);
2681
Bruce Allanad680762008-03-28 09:15:03 -07002682 /*
2683 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002684 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002685 * the packets will be handled on SMBUS
2686 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002687 manc |= E1000_MANC_EN_MNG2HOST;
2688 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002689
2690 switch (hw->mac.type) {
2691 default:
2692 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2693 break;
2694 case e1000_82574:
2695 case e1000_82583:
2696 /*
2697 * Check if IPMI pass-through decision filter already exists;
2698 * if so, enable it.
2699 */
2700 for (i = 0, j = 0; i < 8; i++) {
2701 mdef = er32(MDEF(i));
2702
2703 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002704 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002705 continue;
2706
2707 /* Enable this decision filter in MANC2H */
2708 if (mdef)
2709 manc2h |= (1 << i);
2710
2711 j |= mdef;
2712 }
2713
2714 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2715 break;
2716
2717 /* Create new decision filter in an empty filter */
2718 for (i = 0, j = 0; i < 8; i++)
2719 if (er32(MDEF(i)) == 0) {
2720 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2721 E1000_MDEF_PORT_664));
2722 manc2h |= (1 << 1);
2723 j++;
2724 break;
2725 }
2726
2727 if (!j)
2728 e_warn("Unable to create IPMI pass-through filter\n");
2729 break;
2730 }
2731
Auke Kokbc7f75f2007-09-17 12:30:59 -07002732 ew32(MANC2H, manc2h);
2733 ew32(MANC, manc);
2734}
2735
2736/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002737 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002738 * @adapter: board private structure
2739 *
2740 * Configure the Tx unit of the MAC after a reset.
2741 **/
2742static void e1000_configure_tx(struct e1000_adapter *adapter)
2743{
2744 struct e1000_hw *hw = &adapter->hw;
2745 struct e1000_ring *tx_ring = adapter->tx_ring;
2746 u64 tdba;
2747 u32 tdlen, tctl, tipg, tarc;
2748 u32 ipgr1, ipgr2;
2749
2750 /* Setup the HW Tx Head and Tail descriptor pointers */
2751 tdba = tx_ring->dma;
2752 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002753 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002754 ew32(TDBAH, (tdba >> 32));
2755 ew32(TDLEN, tdlen);
2756 ew32(TDH, 0);
2757 ew32(TDT, 0);
2758 tx_ring->head = E1000_TDH;
2759 tx_ring->tail = E1000_TDT;
2760
2761 /* Set the default values for the Tx Inter Packet Gap timer */
2762 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2763 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2764 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2765
2766 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2767 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2768
2769 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2770 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2771 ew32(TIPG, tipg);
2772
2773 /* Set the Tx Interrupt Delay register */
2774 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002775 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002776 ew32(TADV, adapter->tx_abs_int_delay);
2777
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002778 if (adapter->flags2 & FLAG2_DMA_BURST) {
2779 u32 txdctl = er32(TXDCTL(0));
2780 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2781 E1000_TXDCTL_WTHRESH);
2782 /*
2783 * set up some performance related parameters to encourage the
2784 * hardware to use the bus more efficiently in bursts, depends
2785 * on the tx_int_delay to be enabled,
2786 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2787 * hthresh = 1 ==> prefetch when one or more available
2788 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2789 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002790 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002791 */
2792 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2793 ew32(TXDCTL(0), txdctl);
2794 /* erratum work around: set txdctl the same for both queues */
2795 ew32(TXDCTL(1), txdctl);
2796 }
2797
Auke Kokbc7f75f2007-09-17 12:30:59 -07002798 /* Program the Transmit Control Register */
2799 tctl = er32(TCTL);
2800 tctl &= ~E1000_TCTL_CT;
2801 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2802 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2803
2804 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002805 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002806 /*
2807 * set the speed mode bit, we'll clear it if we're not at
2808 * gigabit link later
2809 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002810#define SPEED_MODE_BIT (1 << 21)
2811 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002812 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813 }
2814
2815 /* errata: program both queues to unweighted RR */
2816 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002817 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002818 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002819 ew32(TARC(0), tarc);
2820 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002821 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002822 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002823 }
2824
Auke Kokbc7f75f2007-09-17 12:30:59 -07002825 /* Setup Transmit Descriptor Settings for eop descriptor */
2826 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2827
2828 /* only set IDE if we are delaying interrupts using the timers */
2829 if (adapter->tx_int_delay)
2830 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2831
2832 /* enable Report Status bit */
2833 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2834
2835 ew32(TCTL, tctl);
2836
Simon Hormanedfea6e62009-06-08 14:28:36 +00002837 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838}
2839
2840/**
2841 * e1000_setup_rctl - configure the receive control registers
2842 * @adapter: Board private structure
2843 **/
2844#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2845 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2846static void e1000_setup_rctl(struct e1000_adapter *adapter)
2847{
2848 struct e1000_hw *hw = &adapter->hw;
2849 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002850 u32 pages = 0;
2851
Bruce Allana1ce6472010-09-22 17:16:40 +00002852 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2853 if (hw->mac.type == e1000_pch2lan) {
2854 s32 ret_val;
2855
2856 if (adapter->netdev->mtu > ETH_DATA_LEN)
2857 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2858 else
2859 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002860
2861 if (ret_val)
2862 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002863 }
2864
Auke Kokbc7f75f2007-09-17 12:30:59 -07002865 /* Program MC offset vector base */
2866 rctl = er32(RCTL);
2867 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2868 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2869 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2870 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2871
2872 /* Do not Store bad packets */
2873 rctl &= ~E1000_RCTL_SBP;
2874
2875 /* Enable Long Packet receive */
2876 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2877 rctl &= ~E1000_RCTL_LPE;
2878 else
2879 rctl |= E1000_RCTL_LPE;
2880
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002881 /* Some systems expect that the CRC is included in SMBUS traffic. The
2882 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2883 * host memory when this is enabled
2884 */
2885 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2886 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002887
Bruce Allana4f58f52009-06-02 11:29:18 +00002888 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2889 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2890 u16 phy_data;
2891
2892 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2893 phy_data &= 0xfff8;
2894 phy_data |= (1 << 2);
2895 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2896
2897 e1e_rphy(hw, 22, &phy_data);
2898 phy_data &= 0x0fff;
2899 phy_data |= (1 << 14);
2900 e1e_wphy(hw, 0x10, 0x2823);
2901 e1e_wphy(hw, 0x11, 0x0003);
2902 e1e_wphy(hw, 22, phy_data);
2903 }
2904
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905 /* Setup buffer sizes */
2906 rctl &= ~E1000_RCTL_SZ_4096;
2907 rctl |= E1000_RCTL_BSEX;
2908 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002909 case 2048:
2910 default:
2911 rctl |= E1000_RCTL_SZ_2048;
2912 rctl &= ~E1000_RCTL_BSEX;
2913 break;
2914 case 4096:
2915 rctl |= E1000_RCTL_SZ_4096;
2916 break;
2917 case 8192:
2918 rctl |= E1000_RCTL_SZ_8192;
2919 break;
2920 case 16384:
2921 rctl |= E1000_RCTL_SZ_16384;
2922 break;
2923 }
2924
Bruce Allan5f450212011-07-22 06:21:46 +00002925 /* Enable Extended Status in all Receive Descriptors */
2926 rfctl = er32(RFCTL);
2927 rfctl |= E1000_RFCTL_EXTEN;
2928
Auke Kokbc7f75f2007-09-17 12:30:59 -07002929 /*
2930 * 82571 and greater support packet-split where the protocol
2931 * header is placed in skb->data and the packet data is
2932 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2933 * In the case of a non-split, skb->data is linearly filled,
2934 * followed by the page buffers. Therefore, skb->data is
2935 * sized to hold the largest protocol header.
2936 *
2937 * allocations using alloc_page take too long for regular MTU
2938 * so only enable packet split for jumbo frames
2939 *
2940 * Using pages when the page size is greater than 16k wastes
2941 * a lot of memory, since we allocate 3 pages at all times
2942 * per packet.
2943 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002944 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fe2010-06-17 18:59:27 +00002945 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002946 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002947 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002948 else
2949 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002950
2951 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002952 u32 psrctl = 0;
2953
Bruce Allanad680762008-03-28 09:15:03 -07002954 /*
2955 * disable packet split support for IPv6 extension headers,
2956 * because some malformed IPv6 headers can hang the Rx
2957 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2959 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2960
Auke Kok140a7482007-10-25 13:57:58 -07002961 /* Enable Packet split descriptors */
2962 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002963
2964 psrctl |= adapter->rx_ps_bsize0 >>
2965 E1000_PSRCTL_BSIZE0_SHIFT;
2966
2967 switch (adapter->rx_ps_pages) {
2968 case 3:
2969 psrctl |= PAGE_SIZE <<
2970 E1000_PSRCTL_BSIZE3_SHIFT;
2971 case 2:
2972 psrctl |= PAGE_SIZE <<
2973 E1000_PSRCTL_BSIZE2_SHIFT;
2974 case 1:
2975 psrctl |= PAGE_SIZE >>
2976 E1000_PSRCTL_BSIZE1_SHIFT;
2977 break;
2978 }
2979
2980 ew32(PSRCTL, psrctl);
2981 }
2982
Bruce Allan5f450212011-07-22 06:21:46 +00002983 ew32(RFCTL, rfctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002984 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002985 /* just started the receive unit, no need to restart */
2986 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002987}
2988
2989/**
2990 * e1000_configure_rx - Configure Receive Unit after Reset
2991 * @adapter: board private structure
2992 *
2993 * Configure the Rx unit of the MAC after a reset.
2994 **/
2995static void e1000_configure_rx(struct e1000_adapter *adapter)
2996{
2997 struct e1000_hw *hw = &adapter->hw;
2998 struct e1000_ring *rx_ring = adapter->rx_ring;
2999 u64 rdba;
3000 u32 rdlen, rctl, rxcsum, ctrl_ext;
3001
3002 if (adapter->rx_ps_pages) {
3003 /* this is a 32 byte descriptor */
3004 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003005 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003006 adapter->clean_rx = e1000_clean_rx_irq_ps;
3007 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003008 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003009 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003010 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3011 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003012 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003013 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003014 adapter->clean_rx = e1000_clean_rx_irq;
3015 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3016 }
3017
3018 /* disable receives while setting up the descriptors */
3019 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003020 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3021 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003022 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003023 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003024
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003025 if (adapter->flags2 & FLAG2_DMA_BURST) {
3026 /*
3027 * set the writeback threshold (only takes effect if the RDTR
3028 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003029 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003030 * granularity = 01
3031 * wthresh = 04,
3032 * hthresh = 04,
3033 * pthresh = 0x20
3034 */
3035 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3036 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3037
3038 /*
3039 * override the delay timers for enabling bursting, only if
3040 * the value was not set by the user via module options
3041 */
3042 if (adapter->rx_int_delay == DEFAULT_RDTR)
3043 adapter->rx_int_delay = BURST_RDTR;
3044 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3045 adapter->rx_abs_int_delay = BURST_RADV;
3046 }
3047
Auke Kokbc7f75f2007-09-17 12:30:59 -07003048 /* set the Receive Delay Timer Register */
3049 ew32(RDTR, adapter->rx_int_delay);
3050
3051 /* irq moderation */
3052 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003053 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003054 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003055
3056 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003057 /* Auto-Mask interrupts upon ICR access */
3058 ctrl_ext |= E1000_CTRL_EXT_IAME;
3059 ew32(IAM, 0xffffffff);
3060 ew32(CTRL_EXT, ctrl_ext);
3061 e1e_flush();
3062
Bruce Allanad680762008-03-28 09:15:03 -07003063 /*
3064 * Setup the HW Rx Head and Tail Descriptor Pointers and
3065 * the Base and Length of the Rx Descriptor Ring
3066 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003067 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07003068 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003069 ew32(RDBAH, (rdba >> 32));
3070 ew32(RDLEN, rdlen);
3071 ew32(RDH, 0);
3072 ew32(RDT, 0);
3073 rx_ring->head = E1000_RDH;
3074 rx_ring->tail = E1000_RDT;
3075
3076 /* Enable Receive Checksum Offload for TCP and UDP */
3077 rxcsum = er32(RXCSUM);
Bruce Allandc221292011-08-19 03:23:48 +00003078 if (adapter->netdev->features & NETIF_F_RXCSUM) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003079 rxcsum |= E1000_RXCSUM_TUOFL;
3080
Bruce Allanad680762008-03-28 09:15:03 -07003081 /*
3082 * IPv4 payload checksum for UDP fragments must be
3083 * used in conjunction with packet-split.
3084 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003085 if (adapter->rx_ps_pages)
3086 rxcsum |= E1000_RXCSUM_IPPCSE;
3087 } else {
3088 rxcsum &= ~E1000_RXCSUM_TUOFL;
3089 /* no need to clear IPPCSE as it defaults to 0 */
3090 }
3091 ew32(RXCSUM, rxcsum);
3092
Bruce Allanad680762008-03-28 09:15:03 -07003093 /*
3094 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07003095 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07003096 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
3097 */
Bruce Allan828bac82010-09-29 21:39:37 +00003098 if ((adapter->flags & FLAG_HAS_ERT) ||
3099 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003100 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3101 u32 rxdctl = er32(RXDCTL(0));
3102 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00003103 if (adapter->flags & FLAG_HAS_ERT)
3104 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00003105 /*
3106 * With jumbo frames and early-receive enabled,
3107 * excessive C-state transition latencies result in
3108 * dropped transactions.
3109 */
Bruce Allanaf667a22010-12-31 06:10:01 +00003110 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003111 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003112 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3113 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003114 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003115 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003116
3117 /* Enable Receives */
3118 ew32(RCTL, rctl);
3119}
3120
3121/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003122 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003123 * @netdev: network interface device structure
3124 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003125 * Writes multicast address list to the MTA hash table.
3126 * Returns: -ENOMEM on failure
3127 * 0 on no addresses written
3128 * X on writing X addresses to MTA
3129 */
3130static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003131{
3132 struct e1000_adapter *adapter = netdev_priv(netdev);
3133 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003134 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003135 u8 *mta_list;
3136 int i;
3137
3138 if (netdev_mc_empty(netdev)) {
3139 /* nothing to program, so clear mc list */
3140 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3141 return 0;
3142 }
3143
3144 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3145 if (!mta_list)
3146 return -ENOMEM;
3147
3148 /* update_mc_addr_list expects a packed array of only addresses. */
3149 i = 0;
3150 netdev_for_each_mc_addr(ha, netdev)
3151 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3152
3153 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3154 kfree(mta_list);
3155
3156 return netdev_mc_count(netdev);
3157}
3158
3159/**
3160 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3161 * @netdev: network interface device structure
3162 *
3163 * Writes unicast address list to the RAR table.
3164 * Returns: -ENOMEM on failure/insufficient address space
3165 * 0 on no addresses written
3166 * X on writing X addresses to the RAR table
3167 **/
3168static int e1000e_write_uc_addr_list(struct net_device *netdev)
3169{
3170 struct e1000_adapter *adapter = netdev_priv(netdev);
3171 struct e1000_hw *hw = &adapter->hw;
3172 unsigned int rar_entries = hw->mac.rar_entry_count;
3173 int count = 0;
3174
3175 /* save a rar entry for our hardware address */
3176 rar_entries--;
3177
3178 /* save a rar entry for the LAA workaround */
3179 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3180 rar_entries--;
3181
3182 /* return ENOMEM indicating insufficient memory for addresses */
3183 if (netdev_uc_count(netdev) > rar_entries)
3184 return -ENOMEM;
3185
3186 if (!netdev_uc_empty(netdev) && rar_entries) {
3187 struct netdev_hw_addr *ha;
3188
3189 /*
3190 * write the addresses in reverse order to avoid write
3191 * combining
3192 */
3193 netdev_for_each_uc_addr(ha, netdev) {
3194 if (!rar_entries)
3195 break;
3196 e1000e_rar_set(hw, ha->addr, rar_entries--);
3197 count++;
3198 }
3199 }
3200
3201 /* zero out the remaining RAR entries not used above */
3202 for (; rar_entries > 0; rar_entries--) {
3203 ew32(RAH(rar_entries), 0);
3204 ew32(RAL(rar_entries), 0);
3205 }
3206 e1e_flush();
3207
3208 return count;
3209}
3210
3211/**
3212 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3213 * @netdev: network interface device structure
3214 *
3215 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3216 * address list or the network interface flags are updated. This routine is
3217 * responsible for configuring the hardware for proper unicast, multicast,
3218 * promiscuous mode, and all-multi behavior.
3219 **/
3220static void e1000e_set_rx_mode(struct net_device *netdev)
3221{
3222 struct e1000_adapter *adapter = netdev_priv(netdev);
3223 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003224 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003225
3226 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003227 rctl = er32(RCTL);
3228
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003229 /* clear the affected bits */
3230 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3231
Auke Kokbc7f75f2007-09-17 12:30:59 -07003232 if (netdev->flags & IFF_PROMISC) {
3233 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003234 /* Do not hardware filter VLANs in promisc mode */
3235 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003236 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003237 int count;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003238 if (netdev->flags & IFF_ALLMULTI) {
3239 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003240 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003241 /*
3242 * Write addresses to the MTA, if the attempt fails
3243 * then we should just turn on promiscuous mode so
3244 * that we can at least receive multicast traffic
3245 */
3246 count = e1000e_write_mc_addr_list(netdev);
3247 if (count < 0)
3248 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003249 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003250 e1000e_vlan_filter_enable(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003251 /*
3252 * Write addresses to available RAR registers, if there is not
3253 * sufficient space to store all the addresses then enable
3254 * unicast promiscuous mode
3255 */
3256 count = e1000e_write_uc_addr_list(netdev);
3257 if (count < 0)
3258 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003259 }
3260
3261 ew32(RCTL, rctl);
3262
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003263 if (netdev->features & NETIF_F_HW_VLAN_RX)
3264 e1000e_vlan_strip_enable(adapter);
3265 else
3266 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003267}
3268
3269/**
Bruce Allanad680762008-03-28 09:15:03 -07003270 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003271 * @adapter: private board structure
3272 **/
3273static void e1000_configure(struct e1000_adapter *adapter)
3274{
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003275 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003276
3277 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003278 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003279
3280 e1000_configure_tx(adapter);
3281 e1000_setup_rctl(adapter);
3282 e1000_configure_rx(adapter);
Jeff Kirsherc2fed992011-07-12 16:10:12 +00003283 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring),
3284 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003285}
3286
3287/**
3288 * e1000e_power_up_phy - restore link in case the phy was powered down
3289 * @adapter: address of board private structure
3290 *
3291 * The phy may be powered down to save power and turn off link when the
3292 * driver is unloaded and wake on lan is not enabled (among others)
3293 * *** this routine MUST be followed by a call to e1000e_reset ***
3294 **/
3295void e1000e_power_up_phy(struct e1000_adapter *adapter)
3296{
Bruce Allan17f208d2009-12-01 15:47:22 +00003297 if (adapter->hw.phy.ops.power_up)
3298 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003299
3300 adapter->hw.mac.ops.setup_link(&adapter->hw);
3301}
3302
3303/**
3304 * e1000_power_down_phy - Power down the PHY
3305 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003306 * Power down the PHY so no link is implied when interface is down.
3307 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003308 */
3309static void e1000_power_down_phy(struct e1000_adapter *adapter)
3310{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003311 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003312 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003313 return;
3314
Bruce Allan17f208d2009-12-01 15:47:22 +00003315 if (adapter->hw.phy.ops.power_down)
3316 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003317}
3318
3319/**
3320 * e1000e_reset - bring the hardware into a known good state
3321 *
3322 * This function boots the hardware and enables some settings that
3323 * require a configuration cycle of the hardware - those cannot be
3324 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003325 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003326 */
3327void e1000e_reset(struct e1000_adapter *adapter)
3328{
3329 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003330 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003331 struct e1000_hw *hw = &adapter->hw;
3332 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003333 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003334 u16 hwm;
3335
Bruce Allanad680762008-03-28 09:15:03 -07003336 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003337 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003338
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003339 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003340 /*
3341 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003342 * large enough to accommodate two full transmit packets,
3343 * rounded up to the next 1KB and expressed in KB. Likewise,
3344 * the Rx FIFO should be large enough to accommodate at least
3345 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003346 * expressed in KB.
3347 */
Auke Kokdf762462007-10-25 13:57:53 -07003348 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003349 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003350 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003351 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003352 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003353 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003354 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003355 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003356 */
3357 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003358 sizeof(struct e1000_tx_desc) -
3359 ETH_FCS_LEN) * 2;
3360 min_tx_space = ALIGN(min_tx_space, 1024);
3361 min_tx_space >>= 10;
3362 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003363 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003364 min_rx_space = ALIGN(min_rx_space, 1024);
3365 min_rx_space >>= 10;
3366
Bruce Allanad680762008-03-28 09:15:03 -07003367 /*
3368 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003369 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003370 * allocation, take space away from current Rx allocation
3371 */
Auke Kokdf762462007-10-25 13:57:53 -07003372 if ((tx_space < min_tx_space) &&
3373 ((min_tx_space - tx_space) < pba)) {
3374 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003375
Bruce Allanad680762008-03-28 09:15:03 -07003376 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003377 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003378 * adjustment or use Early Receive if available
3379 */
Auke Kokdf762462007-10-25 13:57:53 -07003380 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003381 (!(adapter->flags & FLAG_HAS_ERT)))
3382 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003383 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003384 }
Auke Kokdf762462007-10-25 13:57:53 -07003385
3386 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003387 }
3388
Bruce Allanad680762008-03-28 09:15:03 -07003389 /*
3390 * flow control settings
3391 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003392 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003393 * (or the size used for early receive) above it in the Rx FIFO.
3394 * Set it to the lower of:
3395 * - 90% of the Rx FIFO size, and
3396 * - the full Rx FIFO size minus the early receive size (for parts
3397 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003398 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003399 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003400 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3401 fc->pause_time = 0xFFFF;
3402 else
3403 fc->pause_time = E1000_FC_PAUSE_TIME;
3404 fc->send_xon = 1;
3405 fc->current_mode = fc->requested_mode;
3406
3407 switch (hw->mac.type) {
3408 default:
3409 if ((adapter->flags & FLAG_HAS_ERT) &&
3410 (adapter->netdev->mtu > ETH_DATA_LEN))
3411 hwm = min(((pba << 10) * 9 / 10),
3412 ((pba << 10) - (E1000_ERT_2048 << 3)));
3413 else
3414 hwm = min(((pba << 10) * 9 / 10),
3415 ((pba << 10) - adapter->max_frame_size));
3416
3417 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3418 fc->low_water = fc->high_water - 8;
3419 break;
3420 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003421 /*
3422 * Workaround PCH LOM adapter hangs with certain network
3423 * loads. If hangs persist, try disabling Tx flow control.
3424 */
3425 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3426 fc->high_water = 0x3500;
3427 fc->low_water = 0x1500;
3428 } else {
3429 fc->high_water = 0x5000;
3430 fc->low_water = 0x3000;
3431 }
Bruce Allana3055952010-05-10 15:02:12 +00003432 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003433 break;
3434 case e1000_pch2lan:
3435 fc->high_water = 0x05C20;
3436 fc->low_water = 0x05048;
3437 fc->pause_time = 0x0650;
3438 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003439 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3440 pba = 14;
3441 ew32(PBA, pba);
3442 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003443 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003444 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003445
Bruce Allan828bac82010-09-29 21:39:37 +00003446 /*
3447 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3448 * fit in receive buffer and early-receive not supported.
3449 */
3450 if (adapter->itr_setting & 0x3) {
3451 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3452 !(adapter->flags & FLAG_HAS_ERT)) {
3453 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3454 dev_info(&adapter->pdev->dev,
3455 "Interrupt Throttle Rate turned off\n");
3456 adapter->flags2 |= FLAG2_DISABLE_AIM;
3457 ew32(ITR, 0);
3458 }
3459 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3460 dev_info(&adapter->pdev->dev,
3461 "Interrupt Throttle Rate turned on\n");
3462 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3463 adapter->itr = 20000;
3464 ew32(ITR, 1000000000 / (adapter->itr * 256));
3465 }
3466 }
3467
Auke Kokbc7f75f2007-09-17 12:30:59 -07003468 /* Allow time for pending master requests to run */
3469 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003470
3471 /*
3472 * For parts with AMT enabled, let the firmware know
3473 * that the network interface is in control
3474 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003475 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003476 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003477
Auke Kokbc7f75f2007-09-17 12:30:59 -07003478 ew32(WUC, 0);
3479
3480 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003481 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003482
3483 e1000_update_mng_vlan(adapter);
3484
3485 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3486 ew32(VET, ETH_P_8021Q);
3487
3488 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003489
3490 if (!netif_running(adapter->netdev) &&
3491 !test_bit(__E1000_TESTING, &adapter->state)) {
3492 e1000_power_down_phy(adapter);
3493 return;
3494 }
3495
Auke Kokbc7f75f2007-09-17 12:30:59 -07003496 e1000_get_phy_info(hw);
3497
Bruce Allan918d7192009-06-02 11:28:20 +00003498 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3499 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003500 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003501 /*
3502 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003503 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003504 * different we would do if it failed
3505 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003506 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3507 phy_data &= ~IGP02E1000_PM_SPD;
3508 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3509 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003510}
3511
3512int e1000e_up(struct e1000_adapter *adapter)
3513{
3514 struct e1000_hw *hw = &adapter->hw;
3515
3516 /* hardware has been reset, we need to reload some things */
3517 e1000_configure(adapter);
3518
3519 clear_bit(__E1000_DOWN, &adapter->state);
3520
Bruce Allan4662e822008-08-26 18:37:06 -07003521 if (adapter->msix_entries)
3522 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003523 e1000_irq_enable(adapter);
3524
Bruce Allan400484f2011-05-13 07:20:03 +00003525 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003526
Auke Kokbc7f75f2007-09-17 12:30:59 -07003527 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003528 if (adapter->msix_entries)
3529 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3530 else
3531 ew32(ICS, E1000_ICS_LSC);
3532
Auke Kokbc7f75f2007-09-17 12:30:59 -07003533 return 0;
3534}
3535
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003536static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3537{
3538 struct e1000_hw *hw = &adapter->hw;
3539
3540 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3541 return;
3542
3543 /* flush pending descriptor writebacks to memory */
3544 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3545 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3546
3547 /* execute the writes immediately */
3548 e1e_flush();
3549}
3550
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003551static void e1000e_update_stats(struct e1000_adapter *adapter);
3552
Auke Kokbc7f75f2007-09-17 12:30:59 -07003553void e1000e_down(struct e1000_adapter *adapter)
3554{
3555 struct net_device *netdev = adapter->netdev;
3556 struct e1000_hw *hw = &adapter->hw;
3557 u32 tctl, rctl;
3558
Bruce Allanad680762008-03-28 09:15:03 -07003559 /*
3560 * signal that we're down so the interrupt handler does not
3561 * reschedule our watchdog timer
3562 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003563 set_bit(__E1000_DOWN, &adapter->state);
3564
3565 /* disable receives in the hardware */
3566 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003567 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3568 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003569 /* flush and sleep below */
3570
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003571 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003572
3573 /* disable transmits in the hardware */
3574 tctl = er32(TCTL);
3575 tctl &= ~E1000_TCTL_EN;
3576 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003577
Auke Kokbc7f75f2007-09-17 12:30:59 -07003578 /* flush both disables and wait for them to finish */
3579 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003580 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003581
Auke Kokbc7f75f2007-09-17 12:30:59 -07003582 e1000_irq_disable(adapter);
3583
3584 del_timer_sync(&adapter->watchdog_timer);
3585 del_timer_sync(&adapter->phy_info_timer);
3586
Auke Kokbc7f75f2007-09-17 12:30:59 -07003587 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003588
3589 spin_lock(&adapter->stats64_lock);
3590 e1000e_update_stats(adapter);
3591 spin_unlock(&adapter->stats64_lock);
3592
Bruce Allan400484f2011-05-13 07:20:03 +00003593 e1000e_flush_descriptors(adapter);
3594 e1000_clean_tx_ring(adapter);
3595 e1000_clean_rx_ring(adapter);
3596
Auke Kokbc7f75f2007-09-17 12:30:59 -07003597 adapter->link_speed = 0;
3598 adapter->link_duplex = 0;
3599
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003600 if (!pci_channel_offline(adapter->pdev))
3601 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003602
Auke Kokbc7f75f2007-09-17 12:30:59 -07003603 /*
3604 * TODO: for power management, we could drop the link and
3605 * pci_disable_device here.
3606 */
3607}
3608
3609void e1000e_reinit_locked(struct e1000_adapter *adapter)
3610{
3611 might_sleep();
3612 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003613 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003614 e1000e_down(adapter);
3615 e1000e_up(adapter);
3616 clear_bit(__E1000_RESETTING, &adapter->state);
3617}
3618
3619/**
3620 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3621 * @adapter: board private structure to initialize
3622 *
3623 * e1000_sw_init initializes the Adapter private data structure.
3624 * Fields are initialized based on PCI device information and
3625 * OS network device settings (MTU size).
3626 **/
3627static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3628{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003629 struct net_device *netdev = adapter->netdev;
3630
3631 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3632 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003633 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3634 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003635
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003636 spin_lock_init(&adapter->stats64_lock);
3637
Bruce Allan4662e822008-08-26 18:37:06 -07003638 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003639
Bruce Allan4662e822008-08-26 18:37:06 -07003640 if (e1000_alloc_queues(adapter))
3641 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003642
Auke Kokbc7f75f2007-09-17 12:30:59 -07003643 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003644 e1000_irq_disable(adapter);
3645
Auke Kokbc7f75f2007-09-17 12:30:59 -07003646 set_bit(__E1000_DOWN, &adapter->state);
3647 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003648}
3649
3650/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003651 * e1000_intr_msi_test - Interrupt Handler
3652 * @irq: interrupt number
3653 * @data: pointer to a network interface device structure
3654 **/
3655static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3656{
3657 struct net_device *netdev = data;
3658 struct e1000_adapter *adapter = netdev_priv(netdev);
3659 struct e1000_hw *hw = &adapter->hw;
3660 u32 icr = er32(ICR);
3661
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003662 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003663 if (icr & E1000_ICR_RXSEQ) {
3664 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3665 wmb();
3666 }
3667
3668 return IRQ_HANDLED;
3669}
3670
3671/**
3672 * e1000_test_msi_interrupt - Returns 0 for successful test
3673 * @adapter: board private struct
3674 *
3675 * code flow taken from tg3.c
3676 **/
3677static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3678{
3679 struct net_device *netdev = adapter->netdev;
3680 struct e1000_hw *hw = &adapter->hw;
3681 int err;
3682
3683 /* poll_enable hasn't been called yet, so don't need disable */
3684 /* clear any pending events */
3685 er32(ICR);
3686
3687 /* free the real vector and request a test handler */
3688 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003689 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003690
3691 /* Assume that the test fails, if it succeeds then the test
3692 * MSI irq handler will unset this flag */
3693 adapter->flags |= FLAG_MSI_TEST_FAILED;
3694
3695 err = pci_enable_msi(adapter->pdev);
3696 if (err)
3697 goto msi_test_failed;
3698
Joe Perchesa0607fd2009-11-18 23:29:17 -08003699 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003700 netdev->name, netdev);
3701 if (err) {
3702 pci_disable_msi(adapter->pdev);
3703 goto msi_test_failed;
3704 }
3705
3706 wmb();
3707
3708 e1000_irq_enable(adapter);
3709
3710 /* fire an unusual interrupt on the test handler */
3711 ew32(ICS, E1000_ICS_RXSEQ);
3712 e1e_flush();
3713 msleep(50);
3714
3715 e1000_irq_disable(adapter);
3716
3717 rmb();
3718
3719 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003720 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003721 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3722 } else
3723 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003724
3725 free_irq(adapter->pdev->irq, netdev);
3726 pci_disable_msi(adapter->pdev);
3727
Bruce Allanf8d59f72008-08-08 18:36:11 -07003728msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003729 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003730 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003731}
3732
3733/**
3734 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3735 * @adapter: board private struct
3736 *
3737 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3738 **/
3739static int e1000_test_msi(struct e1000_adapter *adapter)
3740{
3741 int err;
3742 u16 pci_cmd;
3743
3744 if (!(adapter->flags & FLAG_MSI_ENABLED))
3745 return 0;
3746
3747 /* disable SERR in case the MSI write causes a master abort */
3748 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003749 if (pci_cmd & PCI_COMMAND_SERR)
3750 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3751 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003752
3753 err = e1000_test_msi_interrupt(adapter);
3754
Dean Nelson36f24072010-06-29 18:12:05 +00003755 /* re-enable SERR */
3756 if (pci_cmd & PCI_COMMAND_SERR) {
3757 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3758 pci_cmd |= PCI_COMMAND_SERR;
3759 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3760 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003761
Bruce Allanf8d59f72008-08-08 18:36:11 -07003762 return err;
3763}
3764
3765/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003766 * e1000_open - Called when a network interface is made active
3767 * @netdev: network interface device structure
3768 *
3769 * Returns 0 on success, negative value on failure
3770 *
3771 * The open entry point is called when a network interface is made
3772 * active by the system (IFF_UP). At this point all resources needed
3773 * for transmit and receive operations are allocated, the interrupt
3774 * handler is registered with the OS, the watchdog timer is started,
3775 * and the stack is notified that the interface is ready.
3776 **/
3777static int e1000_open(struct net_device *netdev)
3778{
3779 struct e1000_adapter *adapter = netdev_priv(netdev);
3780 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003781 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003782 int err;
3783
3784 /* disallow open during test */
3785 if (test_bit(__E1000_TESTING, &adapter->state))
3786 return -EBUSY;
3787
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003788 pm_runtime_get_sync(&pdev->dev);
3789
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003790 netif_carrier_off(netdev);
3791
Auke Kokbc7f75f2007-09-17 12:30:59 -07003792 /* allocate transmit descriptors */
3793 err = e1000e_setup_tx_resources(adapter);
3794 if (err)
3795 goto err_setup_tx;
3796
3797 /* allocate receive descriptors */
3798 err = e1000e_setup_rx_resources(adapter);
3799 if (err)
3800 goto err_setup_rx;
3801
Bruce Allan11b08be2010-05-10 14:59:31 +00003802 /*
3803 * If AMT is enabled, let the firmware know that the network
3804 * interface is now open and reset the part to a known state.
3805 */
3806 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003807 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003808 e1000e_reset(adapter);
3809 }
3810
Auke Kokbc7f75f2007-09-17 12:30:59 -07003811 e1000e_power_up_phy(adapter);
3812
3813 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3814 if ((adapter->hw.mng_cookie.status &
3815 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3816 e1000_update_mng_vlan(adapter);
3817
Florian Micklerc128ec22010-08-02 14:27:00 +00003818 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003819 if ((adapter->flags & FLAG_HAS_ERT) ||
3820 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003821 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3822 PM_QOS_CPU_DMA_LATENCY,
3823 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003824
Bruce Allanad680762008-03-28 09:15:03 -07003825 /*
Bruce Allanad680762008-03-28 09:15:03 -07003826 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003827 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3828 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003829 * clean_rx handler before we do so.
3830 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003831 e1000_configure(adapter);
3832
3833 err = e1000_request_irq(adapter);
3834 if (err)
3835 goto err_req_irq;
3836
Bruce Allanf8d59f72008-08-08 18:36:11 -07003837 /*
3838 * Work around PCIe errata with MSI interrupts causing some chipsets to
3839 * ignore e1000e MSI messages, which means we need to test our MSI
3840 * interrupt now
3841 */
Bruce Allan4662e822008-08-26 18:37:06 -07003842 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003843 err = e1000_test_msi(adapter);
3844 if (err) {
3845 e_err("Interrupt allocation failed\n");
3846 goto err_req_irq;
3847 }
3848 }
3849
Auke Kokbc7f75f2007-09-17 12:30:59 -07003850 /* From here on the code is the same as e1000e_up() */
3851 clear_bit(__E1000_DOWN, &adapter->state);
3852
3853 napi_enable(&adapter->napi);
3854
3855 e1000_irq_enable(adapter);
3856
Jeff Kirsher09357b02011-11-18 14:25:00 +00003857 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003858 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003859
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003860 adapter->idle_check = true;
3861 pm_runtime_put(&pdev->dev);
3862
Auke Kokbc7f75f2007-09-17 12:30:59 -07003863 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003864 if (adapter->msix_entries)
3865 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3866 else
3867 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003868
3869 return 0;
3870
3871err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003872 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003873 e1000_power_down_phy(adapter);
3874 e1000e_free_rx_resources(adapter);
3875err_setup_rx:
3876 e1000e_free_tx_resources(adapter);
3877err_setup_tx:
3878 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003879 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003880
3881 return err;
3882}
3883
3884/**
3885 * e1000_close - Disables a network interface
3886 * @netdev: network interface device structure
3887 *
3888 * Returns 0, this is not allowed to fail
3889 *
3890 * The close entry point is called when an interface is de-activated
3891 * by the OS. The hardware is still under the drivers control, but
3892 * needs to be disabled. A global MAC reset is issued to stop the
3893 * hardware, and all transmit and receive resources are freed.
3894 **/
3895static int e1000_close(struct net_device *netdev)
3896{
3897 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003898 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003899
3900 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003901
3902 pm_runtime_get_sync(&pdev->dev);
3903
Bruce Allan5f4a7802011-11-29 08:09:19 +00003904 napi_disable(&adapter->napi);
3905
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003906 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3907 e1000e_down(adapter);
3908 e1000_free_irq(adapter);
3909 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003910 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003911
3912 e1000e_free_tx_resources(adapter);
3913 e1000e_free_rx_resources(adapter);
3914
Bruce Allanad680762008-03-28 09:15:03 -07003915 /*
3916 * kill manageability vlan ID if supported, but not if a vlan with
3917 * the same ID is registered on the host OS (let 8021q kill it)
3918 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003919 if (adapter->hw.mng_cookie.status &
3920 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003921 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3922
Bruce Allanad680762008-03-28 09:15:03 -07003923 /*
3924 * If AMT is enabled, let the firmware know that the network
3925 * interface is now closed
3926 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003927 if ((adapter->flags & FLAG_HAS_AMT) &&
3928 !test_bit(__E1000_TESTING, &adapter->state))
3929 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003930
Bruce Allan828bac82010-09-29 21:39:37 +00003931 if ((adapter->flags & FLAG_HAS_ERT) ||
3932 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003933 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003934
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003935 pm_runtime_put_sync(&pdev->dev);
3936
Auke Kokbc7f75f2007-09-17 12:30:59 -07003937 return 0;
3938}
3939/**
3940 * e1000_set_mac - Change the Ethernet Address of the NIC
3941 * @netdev: network interface device structure
3942 * @p: pointer to an address structure
3943 *
3944 * Returns 0 on success, negative on failure
3945 **/
3946static int e1000_set_mac(struct net_device *netdev, void *p)
3947{
3948 struct e1000_adapter *adapter = netdev_priv(netdev);
3949 struct sockaddr *addr = p;
3950
3951 if (!is_valid_ether_addr(addr->sa_data))
3952 return -EADDRNOTAVAIL;
3953
3954 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3955 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3956
3957 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3958
3959 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3960 /* activate the work around */
3961 e1000e_set_laa_state_82571(&adapter->hw, 1);
3962
Bruce Allanad680762008-03-28 09:15:03 -07003963 /*
3964 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003965 * between the time RAR[0] gets clobbered and the time it
3966 * gets fixed (in e1000_watchdog), the actual LAA is in one
3967 * of the RARs and no incoming packets directed to this port
3968 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003969 * RAR[14]
3970 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003971 e1000e_rar_set(&adapter->hw,
3972 adapter->hw.mac.addr,
3973 adapter->hw.mac.rar_entry_count - 1);
3974 }
3975
3976 return 0;
3977}
3978
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003979/**
3980 * e1000e_update_phy_task - work thread to update phy
3981 * @work: pointer to our work struct
3982 *
3983 * this worker thread exists because we must acquire a
3984 * semaphore to read the phy, which we could msleep while
3985 * waiting for it, and we can't msleep in a timer.
3986 **/
3987static void e1000e_update_phy_task(struct work_struct *work)
3988{
3989 struct e1000_adapter *adapter = container_of(work,
3990 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003991
3992 if (test_bit(__E1000_DOWN, &adapter->state))
3993 return;
3994
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003995 e1000_get_phy_info(&adapter->hw);
3996}
3997
Bruce Allanad680762008-03-28 09:15:03 -07003998/*
3999 * Need to wait a few seconds after link up to get diagnostic information from
4000 * the phy
4001 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004002static void e1000_update_phy_info(unsigned long data)
4003{
4004 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004005
4006 if (test_bit(__E1000_DOWN, &adapter->state))
4007 return;
4008
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004009 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004010}
4011
4012/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004013 * e1000e_update_phy_stats - Update the PHY statistics counters
4014 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004015 *
4016 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004017 **/
4018static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4019{
4020 struct e1000_hw *hw = &adapter->hw;
4021 s32 ret_val;
4022 u16 phy_data;
4023
4024 ret_val = hw->phy.ops.acquire(hw);
4025 if (ret_val)
4026 return;
4027
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004028 /*
4029 * A page set is expensive so check if already on desired page.
4030 * If not, set to the page with the PHY status registers.
4031 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004032 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004033 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4034 &phy_data);
4035 if (ret_val)
4036 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004037 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4038 ret_val = hw->phy.ops.set_page(hw,
4039 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004040 if (ret_val)
4041 goto release;
4042 }
4043
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004044 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004045 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4046 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004047 if (!ret_val)
4048 adapter->stats.scc += phy_data;
4049
4050 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004051 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4052 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004053 if (!ret_val)
4054 adapter->stats.ecol += phy_data;
4055
4056 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004057 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4058 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004059 if (!ret_val)
4060 adapter->stats.mcc += phy_data;
4061
4062 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004063 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4064 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004065 if (!ret_val)
4066 adapter->stats.latecol += phy_data;
4067
4068 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004069 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4070 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004071 if (!ret_val)
4072 hw->mac.collision_delta = phy_data;
4073
4074 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004075 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4076 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004077 if (!ret_val)
4078 adapter->stats.dc += phy_data;
4079
4080 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004081 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4082 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004083 if (!ret_val)
4084 adapter->stats.tncrs += phy_data;
4085
4086release:
4087 hw->phy.ops.release(hw);
4088}
4089
4090/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004091 * e1000e_update_stats - Update the board statistics counters
4092 * @adapter: board private structure
4093 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004094static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004095{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004096 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004097 struct e1000_hw *hw = &adapter->hw;
4098 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004099
4100 /*
4101 * Prevent stats update while adapter is being reset, or if the pci
4102 * connection is down.
4103 */
4104 if (adapter->link_speed == 0)
4105 return;
4106 if (pci_channel_offline(pdev))
4107 return;
4108
Auke Kokbc7f75f2007-09-17 12:30:59 -07004109 adapter->stats.crcerrs += er32(CRCERRS);
4110 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004111 adapter->stats.gorc += er32(GORCL);
4112 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004113 adapter->stats.bprc += er32(BPRC);
4114 adapter->stats.mprc += er32(MPRC);
4115 adapter->stats.roc += er32(ROC);
4116
Auke Kokbc7f75f2007-09-17 12:30:59 -07004117 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004118
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004119 /* Half-duplex statistics */
4120 if (adapter->link_duplex == HALF_DUPLEX) {
4121 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4122 e1000e_update_phy_stats(adapter);
4123 } else {
4124 adapter->stats.scc += er32(SCC);
4125 adapter->stats.ecol += er32(ECOL);
4126 adapter->stats.mcc += er32(MCC);
4127 adapter->stats.latecol += er32(LATECOL);
4128 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004129
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004130 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004131
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004132 if ((hw->mac.type != e1000_82574) &&
4133 (hw->mac.type != e1000_82583))
4134 adapter->stats.tncrs += er32(TNCRS);
4135 }
4136 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004137 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004138
Auke Kokbc7f75f2007-09-17 12:30:59 -07004139 adapter->stats.xonrxc += er32(XONRXC);
4140 adapter->stats.xontxc += er32(XONTXC);
4141 adapter->stats.xoffrxc += er32(XOFFRXC);
4142 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004143 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004144 adapter->stats.gotc += er32(GOTCL);
4145 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004146 adapter->stats.rnbc += er32(RNBC);
4147 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004148
4149 adapter->stats.mptc += er32(MPTC);
4150 adapter->stats.bptc += er32(BPTC);
4151
4152 /* used for adaptive IFS */
4153
4154 hw->mac.tx_packet_delta = er32(TPT);
4155 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004156
4157 adapter->stats.algnerrc += er32(ALGNERRC);
4158 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004159 adapter->stats.cexterr += er32(CEXTERR);
4160 adapter->stats.tsctc += er32(TSCTC);
4161 adapter->stats.tsctfc += er32(TSCTFC);
4162
Auke Kokbc7f75f2007-09-17 12:30:59 -07004163 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004164 netdev->stats.multicast = adapter->stats.mprc;
4165 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004166
4167 /* Rx Errors */
4168
Bruce Allanad680762008-03-28 09:15:03 -07004169 /*
4170 * RLEC on some newer hardware can be incorrect so build
4171 * our own version based on RUC and ROC
4172 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004173 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004174 adapter->stats.crcerrs + adapter->stats.algnerrc +
4175 adapter->stats.ruc + adapter->stats.roc +
4176 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004177 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004178 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004179 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4180 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4181 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004182
4183 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004184 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004185 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004186 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4187 netdev->stats.tx_window_errors = adapter->stats.latecol;
4188 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004189
4190 /* Tx Dropped needs to be maintained elsewhere */
4191
Auke Kokbc7f75f2007-09-17 12:30:59 -07004192 /* Management Stats */
4193 adapter->stats.mgptc += er32(MGTPTC);
4194 adapter->stats.mgprc += er32(MGTPRC);
4195 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004196}
4197
Bruce Allan7c257692008-04-23 11:09:00 -07004198/**
4199 * e1000_phy_read_status - Update the PHY register status snapshot
4200 * @adapter: board private structure
4201 **/
4202static void e1000_phy_read_status(struct e1000_adapter *adapter)
4203{
4204 struct e1000_hw *hw = &adapter->hw;
4205 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004206
4207 if ((er32(STATUS) & E1000_STATUS_LU) &&
4208 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004209 int ret_val;
4210
Bruce Allan7c257692008-04-23 11:09:00 -07004211 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4212 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4213 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4214 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4215 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4216 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4217 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4218 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4219 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004220 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004221 } else {
4222 /*
4223 * Do not read PHY registers if link is not up
4224 * Set values to typical power-on defaults
4225 */
4226 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4227 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4228 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4229 BMSR_ERCAP);
4230 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4231 ADVERTISE_ALL | ADVERTISE_CSMA);
4232 phy->lpa = 0;
4233 phy->expansion = EXPANSION_ENABLENPAGE;
4234 phy->ctrl1000 = ADVERTISE_1000FULL;
4235 phy->stat1000 = 0;
4236 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4237 }
Bruce Allan7c257692008-04-23 11:09:00 -07004238}
4239
Auke Kokbc7f75f2007-09-17 12:30:59 -07004240static void e1000_print_link_info(struct e1000_adapter *adapter)
4241{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004242 struct e1000_hw *hw = &adapter->hw;
4243 u32 ctrl = er32(CTRL);
4244
Bruce Allan8f12fe82008-11-21 16:54:43 -08004245 /* Link status message must follow this format for user tools */
Jeff Kirsheref456f82011-11-03 11:40:28 +00004246 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4247 adapter->netdev->name,
4248 adapter->link_speed,
4249 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4250 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4251 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4252 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004253}
4254
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004255static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004256{
4257 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004258 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004259 s32 ret_val = 0;
4260
4261 /*
4262 * get_link_status is set on LSC (link status) interrupt or
4263 * Rx sequence error interrupt. get_link_status will stay
4264 * false until the check_for_link establishes link
4265 * for copper adapters ONLY
4266 */
4267 switch (hw->phy.media_type) {
4268 case e1000_media_type_copper:
4269 if (hw->mac.get_link_status) {
4270 ret_val = hw->mac.ops.check_for_link(hw);
4271 link_active = !hw->mac.get_link_status;
4272 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004273 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004274 }
4275 break;
4276 case e1000_media_type_fiber:
4277 ret_val = hw->mac.ops.check_for_link(hw);
4278 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4279 break;
4280 case e1000_media_type_internal_serdes:
4281 ret_val = hw->mac.ops.check_for_link(hw);
4282 link_active = adapter->hw.mac.serdes_has_link;
4283 break;
4284 default:
4285 case e1000_media_type_unknown:
4286 break;
4287 }
4288
4289 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4290 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4291 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004292 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004293 }
4294
4295 return link_active;
4296}
4297
4298static void e1000e_enable_receives(struct e1000_adapter *adapter)
4299{
4300 /* make sure the receive unit is started */
4301 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4302 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4303 struct e1000_hw *hw = &adapter->hw;
4304 u32 rctl = er32(RCTL);
4305 ew32(RCTL, rctl | E1000_RCTL_EN);
4306 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4307 }
4308}
4309
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004310static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4311{
4312 struct e1000_hw *hw = &adapter->hw;
4313
4314 /*
4315 * With 82574 controllers, PHY needs to be checked periodically
4316 * for hung state and reset, if two calls return true
4317 */
4318 if (e1000_check_phy_82574(hw))
4319 adapter->phy_hang_count++;
4320 else
4321 adapter->phy_hang_count = 0;
4322
4323 if (adapter->phy_hang_count > 1) {
4324 adapter->phy_hang_count = 0;
4325 schedule_work(&adapter->reset_task);
4326 }
4327}
4328
Auke Kokbc7f75f2007-09-17 12:30:59 -07004329/**
4330 * e1000_watchdog - Timer Call-back
4331 * @data: pointer to adapter cast into an unsigned long
4332 **/
4333static void e1000_watchdog(unsigned long data)
4334{
4335 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4336
4337 /* Do the rest outside of interrupt context */
4338 schedule_work(&adapter->watchdog_task);
4339
4340 /* TODO: make this use queue_delayed_work() */
4341}
4342
4343static void e1000_watchdog_task(struct work_struct *work)
4344{
4345 struct e1000_adapter *adapter = container_of(work,
4346 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004347 struct net_device *netdev = adapter->netdev;
4348 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004349 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004350 struct e1000_ring *tx_ring = adapter->tx_ring;
4351 struct e1000_hw *hw = &adapter->hw;
4352 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004353
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004354 if (test_bit(__E1000_DOWN, &adapter->state))
4355 return;
4356
David S. Millerb405e8d2010-02-04 22:31:41 -08004357 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004358 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004359 /* Cancel scheduled suspend requests. */
4360 pm_runtime_resume(netdev->dev.parent);
4361
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004362 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004363 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004364 }
4365
4366 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4367 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4368 e1000_update_mng_vlan(adapter);
4369
Auke Kokbc7f75f2007-09-17 12:30:59 -07004370 if (link) {
4371 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004372 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004373
4374 /* Cancel scheduled suspend requests. */
4375 pm_runtime_resume(netdev->dev.parent);
4376
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004377 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004378 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004379 mac->ops.get_link_up_info(&adapter->hw,
4380 &adapter->link_speed,
4381 &adapter->link_duplex);
4382 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004383 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004384 * On supported PHYs, check for duplex mismatch only
4385 * if link has autonegotiated at 10/100 half
4386 */
4387 if ((hw->phy.type == e1000_phy_igp_3 ||
4388 hw->phy.type == e1000_phy_bm) &&
4389 (hw->mac.autoneg == true) &&
4390 (adapter->link_speed == SPEED_10 ||
4391 adapter->link_speed == SPEED_100) &&
4392 (adapter->link_duplex == HALF_DUPLEX)) {
4393 u16 autoneg_exp;
4394
4395 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4396
4397 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004398 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 -07004399 }
4400
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004401 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004402 adapter->tx_timeout_factor = 1;
4403 switch (adapter->link_speed) {
4404 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004405 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004406 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407 break;
4408 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004409 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004410 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004411 break;
4412 }
4413
Bruce Allanad680762008-03-28 09:15:03 -07004414 /*
4415 * workaround: re-program speed mode bit after
4416 * link-up event
4417 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004418 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4419 !txb2b) {
4420 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004421 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004422 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004423 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004424 }
4425
Bruce Allanad680762008-03-28 09:15:03 -07004426 /*
4427 * disable TSO for pcie and 10/100 speeds, to avoid
4428 * some hardware issues
4429 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004430 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4431 switch (adapter->link_speed) {
4432 case SPEED_10:
4433 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004434 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004435 netdev->features &= ~NETIF_F_TSO;
4436 netdev->features &= ~NETIF_F_TSO6;
4437 break;
4438 case SPEED_1000:
4439 netdev->features |= NETIF_F_TSO;
4440 netdev->features |= NETIF_F_TSO6;
4441 break;
4442 default:
4443 /* oops */
4444 break;
4445 }
4446 }
4447
Bruce Allanad680762008-03-28 09:15:03 -07004448 /*
4449 * enable transmits in the hardware, need to do this
4450 * after setting TARC(0)
4451 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004452 tctl = er32(TCTL);
4453 tctl |= E1000_TCTL_EN;
4454 ew32(TCTL, tctl);
4455
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004456 /*
4457 * Perform any post-link-up configuration before
4458 * reporting link up.
4459 */
4460 if (phy->ops.cfg_on_link_up)
4461 phy->ops.cfg_on_link_up(hw);
4462
Auke Kokbc7f75f2007-09-17 12:30:59 -07004463 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004464
4465 if (!test_bit(__E1000_DOWN, &adapter->state))
4466 mod_timer(&adapter->phy_info_timer,
4467 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004468 }
4469 } else {
4470 if (netif_carrier_ok(netdev)) {
4471 adapter->link_speed = 0;
4472 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004473 /* Link status message must follow this format */
4474 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4475 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004476 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004477 if (!test_bit(__E1000_DOWN, &adapter->state))
4478 mod_timer(&adapter->phy_info_timer,
4479 round_jiffies(jiffies + 2 * HZ));
4480
4481 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4482 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004483 else
4484 pm_schedule_suspend(netdev->dev.parent,
4485 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004486 }
4487 }
4488
4489link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004490 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004491 e1000e_update_stats(adapter);
4492
4493 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4494 adapter->tpt_old = adapter->stats.tpt;
4495 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4496 adapter->colc_old = adapter->stats.colc;
4497
Bruce Allan7c257692008-04-23 11:09:00 -07004498 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4499 adapter->gorc_old = adapter->stats.gorc;
4500 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4501 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004502 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004503
4504 e1000e_update_adaptive(&adapter->hw);
4505
Bruce Allan90da0662011-01-06 07:02:53 +00004506 if (!netif_carrier_ok(netdev) &&
4507 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4508 /*
4509 * We've lost link, so the controller stops DMA,
4510 * but we've got queued Tx work that's never going
4511 * to get done, so reset controller to flush Tx.
4512 * (Do the reset outside of interrupt context).
4513 */
Bruce Allan90da0662011-01-06 07:02:53 +00004514 schedule_work(&adapter->reset_task);
4515 /* return immediately since reset is imminent */
4516 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004517 }
4518
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004519 /* Simple mode for Interrupt Throttle Rate (ITR) */
4520 if (adapter->itr_setting == 4) {
4521 /*
4522 * Symmetric Tx/Rx gets a reduced ITR=2000;
4523 * Total asymmetrical Tx or Rx gets ITR=8000;
4524 * everyone else is between 2000-8000.
4525 */
4526 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4527 u32 dif = (adapter->gotc > adapter->gorc ?
4528 adapter->gotc - adapter->gorc :
4529 adapter->gorc - adapter->gotc) / 10000;
4530 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4531
4532 ew32(ITR, 1000000000 / (itr * 256));
4533 }
4534
Bruce Allanad680762008-03-28 09:15:03 -07004535 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004536 if (adapter->msix_entries)
4537 ew32(ICS, adapter->rx_ring->ims_val);
4538 else
4539 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004541 /* flush pending descriptors to memory before detecting Tx hang */
4542 e1000e_flush_descriptors(adapter);
4543
Auke Kokbc7f75f2007-09-17 12:30:59 -07004544 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004545 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004546
Bruce Allanad680762008-03-28 09:15:03 -07004547 /*
4548 * With 82571 controllers, LAA may be overwritten due to controller
4549 * reset from the other port. Set the appropriate LAA in RAR[0]
4550 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004551 if (e1000e_get_laa_state_82571(hw))
4552 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4553
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004554 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4555 e1000e_check_82574_phy_workaround(adapter);
4556
Auke Kokbc7f75f2007-09-17 12:30:59 -07004557 /* Reset the timer */
4558 if (!test_bit(__E1000_DOWN, &adapter->state))
4559 mod_timer(&adapter->watchdog_timer,
4560 round_jiffies(jiffies + 2 * HZ));
4561}
4562
4563#define E1000_TX_FLAGS_CSUM 0x00000001
4564#define E1000_TX_FLAGS_VLAN 0x00000002
4565#define E1000_TX_FLAGS_TSO 0x00000004
4566#define E1000_TX_FLAGS_IPV4 0x00000008
4567#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4568#define E1000_TX_FLAGS_VLAN_SHIFT 16
4569
4570static int e1000_tso(struct e1000_adapter *adapter,
4571 struct sk_buff *skb)
4572{
4573 struct e1000_ring *tx_ring = adapter->tx_ring;
4574 struct e1000_context_desc *context_desc;
4575 struct e1000_buffer *buffer_info;
4576 unsigned int i;
4577 u32 cmd_length = 0;
4578 u16 ipcse = 0, tucse, mss;
4579 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004580
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004581 if (!skb_is_gso(skb))
4582 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004583
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004584 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004585 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4586
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004587 if (err)
4588 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004589 }
4590
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004591 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4592 mss = skb_shinfo(skb)->gso_size;
4593 if (skb->protocol == htons(ETH_P_IP)) {
4594 struct iphdr *iph = ip_hdr(skb);
4595 iph->tot_len = 0;
4596 iph->check = 0;
4597 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4598 0, IPPROTO_TCP, 0);
4599 cmd_length = E1000_TXD_CMD_IP;
4600 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004601 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004602 ipv6_hdr(skb)->payload_len = 0;
4603 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4604 &ipv6_hdr(skb)->daddr,
4605 0, IPPROTO_TCP, 0);
4606 ipcse = 0;
4607 }
4608 ipcss = skb_network_offset(skb);
4609 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4610 tucss = skb_transport_offset(skb);
4611 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4612 tucse = 0;
4613
4614 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4615 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4616
4617 i = tx_ring->next_to_use;
4618 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4619 buffer_info = &tx_ring->buffer_info[i];
4620
4621 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4622 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4623 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4624 context_desc->upper_setup.tcp_fields.tucss = tucss;
4625 context_desc->upper_setup.tcp_fields.tucso = tucso;
4626 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4627 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4628 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4629 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4630
4631 buffer_info->time_stamp = jiffies;
4632 buffer_info->next_to_watch = i;
4633
4634 i++;
4635 if (i == tx_ring->count)
4636 i = 0;
4637 tx_ring->next_to_use = i;
4638
4639 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004640}
4641
4642static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4643{
4644 struct e1000_ring *tx_ring = adapter->tx_ring;
4645 struct e1000_context_desc *context_desc;
4646 struct e1000_buffer *buffer_info;
4647 unsigned int i;
4648 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004649 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004650 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004651
Dave Grahamaf807c82008-10-09 14:28:58 -07004652 if (skb->ip_summed != CHECKSUM_PARTIAL)
4653 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004654
Arthur Jones5f66f202009-03-19 01:13:08 +00004655 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4656 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4657 else
4658 protocol = skb->protocol;
4659
Arthur Jones3f518392009-03-20 15:56:35 -07004660 switch (protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08004661 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004662 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4663 cmd_len |= E1000_TXD_CMD_TCP;
4664 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08004665 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004666 /* XXX not handling all IPV6 headers */
4667 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4668 cmd_len |= E1000_TXD_CMD_TCP;
4669 break;
4670 default:
4671 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004672 e_warn("checksum_partial proto=%x!\n",
4673 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004674 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004675 }
4676
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004677 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004678
4679 i = tx_ring->next_to_use;
4680 buffer_info = &tx_ring->buffer_info[i];
4681 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4682
4683 context_desc->lower_setup.ip_config = 0;
4684 context_desc->upper_setup.tcp_fields.tucss = css;
4685 context_desc->upper_setup.tcp_fields.tucso =
4686 css + skb->csum_offset;
4687 context_desc->upper_setup.tcp_fields.tucse = 0;
4688 context_desc->tcp_seg_setup.data = 0;
4689 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4690
4691 buffer_info->time_stamp = jiffies;
4692 buffer_info->next_to_watch = i;
4693
4694 i++;
4695 if (i == tx_ring->count)
4696 i = 0;
4697 tx_ring->next_to_use = i;
4698
4699 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004700}
4701
4702#define E1000_MAX_PER_TXD 8192
4703#define E1000_MAX_TXD_PWR 12
4704
4705static int e1000_tx_map(struct e1000_adapter *adapter,
4706 struct sk_buff *skb, unsigned int first,
4707 unsigned int max_per_txd, unsigned int nr_frags,
4708 unsigned int mss)
4709{
4710 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004711 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004712 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004713 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004714 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004715 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004716
4717 i = tx_ring->next_to_use;
4718
4719 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004720 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004721 size = min(len, max_per_txd);
4722
Auke Kokbc7f75f2007-09-17 12:30:59 -07004723 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004724 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004725 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004726 buffer_info->dma = dma_map_single(&pdev->dev,
4727 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004728 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004729 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004730 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004731 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004732
4733 len -= size;
4734 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004735 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004736
4737 if (len) {
4738 i++;
4739 if (i == tx_ring->count)
4740 i = 0;
4741 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004742 }
4743
4744 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004745 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004746
4747 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004748 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004749 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004750
4751 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004752 i++;
4753 if (i == tx_ring->count)
4754 i = 0;
4755
Auke Kokbc7f75f2007-09-17 12:30:59 -07004756 buffer_info = &tx_ring->buffer_info[i];
4757 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004758
4759 buffer_info->length = size;
4760 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004761 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004762 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4763 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004764 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004765 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004766 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004767
4768 len -= size;
4769 offset += size;
4770 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004771 }
4772 }
4773
Bruce Allanaf667a22010-12-31 06:10:01 +00004774 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004775 /* multiply data chunks by size of headers */
4776 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4777
Auke Kokbc7f75f2007-09-17 12:30:59 -07004778 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004779 tx_ring->buffer_info[i].segs = segs;
4780 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004781 tx_ring->buffer_info[first].next_to_watch = i;
4782
4783 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004784
4785dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004786 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004787 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004788 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004789 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004790
4791 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004792 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004793 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004794 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004795 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004796 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004797 }
4798
4799 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004800}
4801
4802static void e1000_tx_queue(struct e1000_adapter *adapter,
4803 int tx_flags, int count)
4804{
4805 struct e1000_ring *tx_ring = adapter->tx_ring;
4806 struct e1000_tx_desc *tx_desc = NULL;
4807 struct e1000_buffer *buffer_info;
4808 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4809 unsigned int i;
4810
4811 if (tx_flags & E1000_TX_FLAGS_TSO) {
4812 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4813 E1000_TXD_CMD_TSE;
4814 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4815
4816 if (tx_flags & E1000_TX_FLAGS_IPV4)
4817 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4818 }
4819
4820 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4821 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4822 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4823 }
4824
4825 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4826 txd_lower |= E1000_TXD_CMD_VLE;
4827 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4828 }
4829
4830 i = tx_ring->next_to_use;
4831
Bruce Allan36b973d2010-11-24 07:42:43 +00004832 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004833 buffer_info = &tx_ring->buffer_info[i];
4834 tx_desc = E1000_TX_DESC(*tx_ring, i);
4835 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4836 tx_desc->lower.data =
4837 cpu_to_le32(txd_lower | buffer_info->length);
4838 tx_desc->upper.data = cpu_to_le32(txd_upper);
4839
4840 i++;
4841 if (i == tx_ring->count)
4842 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004843 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004844
4845 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4846
Bruce Allanad680762008-03-28 09:15:03 -07004847 /*
4848 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004849 * know there are new descriptors to fetch. (Only
4850 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004851 * such as IA-64).
4852 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004853 wmb();
4854
4855 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004856
4857 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4858 e1000e_update_tdt_wa(adapter, i);
4859 else
4860 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4861
Bruce Allanad680762008-03-28 09:15:03 -07004862 /*
4863 * we need this if more than one processor can write to our tail
4864 * at a time, it synchronizes IO on IA64/Altix systems
4865 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004866 mmiowb();
4867}
4868
4869#define MINIMUM_DHCP_PACKET_SIZE 282
4870static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4871 struct sk_buff *skb)
4872{
4873 struct e1000_hw *hw = &adapter->hw;
4874 u16 length, offset;
4875
4876 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004877 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4878 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004879 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4880 return 0;
4881 }
4882
4883 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4884 return 0;
4885
4886 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4887 return 0;
4888
4889 {
4890 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4891 struct udphdr *udp;
4892
4893 if (ip->protocol != IPPROTO_UDP)
4894 return 0;
4895
4896 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4897 if (ntohs(udp->dest) != 67)
4898 return 0;
4899
4900 offset = (u8 *)udp + 8 - skb->data;
4901 length = skb->len - offset;
4902 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4903 }
4904
4905 return 0;
4906}
4907
4908static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4909{
4910 struct e1000_adapter *adapter = netdev_priv(netdev);
4911
4912 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004913 /*
4914 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004915 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004916 * but since that doesn't exist yet, just open code it.
4917 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004918 smp_mb();
4919
Bruce Allanad680762008-03-28 09:15:03 -07004920 /*
4921 * We need to check again in a case another CPU has just
4922 * made room available.
4923 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004924 if (e1000_desc_unused(adapter->tx_ring) < size)
4925 return -EBUSY;
4926
4927 /* A reprieve! */
4928 netif_start_queue(netdev);
4929 ++adapter->restart_queue;
4930 return 0;
4931}
4932
4933static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4934{
4935 struct e1000_adapter *adapter = netdev_priv(netdev);
4936
4937 if (e1000_desc_unused(adapter->tx_ring) >= size)
4938 return 0;
4939 return __e1000_maybe_stop_tx(netdev, size);
4940}
4941
4942#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004943static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4944 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004945{
4946 struct e1000_adapter *adapter = netdev_priv(netdev);
4947 struct e1000_ring *tx_ring = adapter->tx_ring;
4948 unsigned int first;
4949 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4950 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4951 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004952 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004953 unsigned int nr_frags;
4954 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004955 int count = 0;
4956 int tso;
4957 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004958
4959 if (test_bit(__E1000_DOWN, &adapter->state)) {
4960 dev_kfree_skb_any(skb);
4961 return NETDEV_TX_OK;
4962 }
4963
4964 if (skb->len <= 0) {
4965 dev_kfree_skb_any(skb);
4966 return NETDEV_TX_OK;
4967 }
4968
4969 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004970 /*
4971 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004972 * make sure there is enough room in the FIFO before
4973 * initiating the DMA for each buffer. The calc is:
4974 * 4 = ceil(buffer len/mss). To make sure we don't
4975 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004976 * drops.
4977 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004978 if (mss) {
4979 u8 hdr_len;
4980 max_per_txd = min(mss << 2, max_per_txd);
4981 max_txd_pwr = fls(max_per_txd) - 1;
4982
Bruce Allanad680762008-03-28 09:15:03 -07004983 /*
4984 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4985 * points to just header, pull a few bytes of payload from
4986 * frags into skb->data
4987 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004988 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004989 /*
4990 * we do this workaround for ES2LAN, but it is un-necessary,
4991 * avoiding it could save a lot of cycles
4992 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004993 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004994 unsigned int pull_size;
4995
4996 pull_size = min((unsigned int)4, skb->data_len);
4997 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004998 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004999 dev_kfree_skb_any(skb);
5000 return NETDEV_TX_OK;
5001 }
Eric Dumazete743d312010-04-14 15:59:40 -07005002 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005003 }
5004 }
5005
5006 /* reserve a descriptor for the offload context */
5007 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5008 count++;
5009 count++;
5010
5011 count += TXD_USE_COUNT(len, max_txd_pwr);
5012
5013 nr_frags = skb_shinfo(skb)->nr_frags;
5014 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00005015 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07005016 max_txd_pwr);
5017
5018 if (adapter->hw.mac.tx_pkt_filtering)
5019 e1000_transfer_dhcp_info(adapter, skb);
5020
Bruce Allanad680762008-03-28 09:15:03 -07005021 /*
5022 * need: count + 2 desc gap to keep tail from touching
5023 * head, otherwise try next time
5024 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00005025 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005026 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005027
Jesse Grosseab6d182010-10-20 13:56:03 +00005028 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005029 tx_flags |= E1000_TX_FLAGS_VLAN;
5030 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5031 }
5032
5033 first = tx_ring->next_to_use;
5034
5035 tso = e1000_tso(adapter, skb);
5036 if (tso < 0) {
5037 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005038 return NETDEV_TX_OK;
5039 }
5040
5041 if (tso)
5042 tx_flags |= E1000_TX_FLAGS_TSO;
5043 else if (e1000_tx_csum(adapter, skb))
5044 tx_flags |= E1000_TX_FLAGS_CSUM;
5045
Bruce Allanad680762008-03-28 09:15:03 -07005046 /*
5047 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005048 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005049 * no longer assume, we must.
5050 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005051 if (skb->protocol == htons(ETH_P_IP))
5052 tx_flags |= E1000_TX_FLAGS_IPV4;
5053
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005054 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005055 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005056 if (count) {
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005057 netdev_sent_queue(netdev, skb->len);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005058 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005059 /* Make sure there is space in the ring for the next send. */
5060 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
5061
5062 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005063 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005064 tx_ring->buffer_info[first].time_stamp = 0;
5065 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005066 }
5067
Auke Kokbc7f75f2007-09-17 12:30:59 -07005068 return NETDEV_TX_OK;
5069}
5070
5071/**
5072 * e1000_tx_timeout - Respond to a Tx Hang
5073 * @netdev: network interface device structure
5074 **/
5075static void e1000_tx_timeout(struct net_device *netdev)
5076{
5077 struct e1000_adapter *adapter = netdev_priv(netdev);
5078
5079 /* Do the reset outside of interrupt context */
5080 adapter->tx_timeout_count++;
5081 schedule_work(&adapter->reset_task);
5082}
5083
5084static void e1000_reset_task(struct work_struct *work)
5085{
5086 struct e1000_adapter *adapter;
5087 adapter = container_of(work, struct e1000_adapter, reset_task);
5088
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005089 /* don't run the task if already down */
5090 if (test_bit(__E1000_DOWN, &adapter->state))
5091 return;
5092
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005093 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5094 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5095 e1000e_dump(adapter);
5096 e_err("Reset adapter\n");
5097 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005098 e1000e_reinit_locked(adapter);
5099}
5100
5101/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005102 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005103 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005104 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005105 *
5106 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005108struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5109 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005110{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005111 struct e1000_adapter *adapter = netdev_priv(netdev);
5112
5113 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5114 spin_lock(&adapter->stats64_lock);
5115 e1000e_update_stats(adapter);
5116 /* Fill out the OS statistics structure */
5117 stats->rx_bytes = adapter->stats.gorc;
5118 stats->rx_packets = adapter->stats.gprc;
5119 stats->tx_bytes = adapter->stats.gotc;
5120 stats->tx_packets = adapter->stats.gptc;
5121 stats->multicast = adapter->stats.mprc;
5122 stats->collisions = adapter->stats.colc;
5123
5124 /* Rx Errors */
5125
5126 /*
5127 * RLEC on some newer hardware can be incorrect so build
5128 * our own version based on RUC and ROC
5129 */
5130 stats->rx_errors = adapter->stats.rxerrc +
5131 adapter->stats.crcerrs + adapter->stats.algnerrc +
5132 adapter->stats.ruc + adapter->stats.roc +
5133 adapter->stats.cexterr;
5134 stats->rx_length_errors = adapter->stats.ruc +
5135 adapter->stats.roc;
5136 stats->rx_crc_errors = adapter->stats.crcerrs;
5137 stats->rx_frame_errors = adapter->stats.algnerrc;
5138 stats->rx_missed_errors = adapter->stats.mpc;
5139
5140 /* Tx Errors */
5141 stats->tx_errors = adapter->stats.ecol +
5142 adapter->stats.latecol;
5143 stats->tx_aborted_errors = adapter->stats.ecol;
5144 stats->tx_window_errors = adapter->stats.latecol;
5145 stats->tx_carrier_errors = adapter->stats.tncrs;
5146
5147 /* Tx Dropped needs to be maintained elsewhere */
5148
5149 spin_unlock(&adapter->stats64_lock);
5150 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005151}
5152
5153/**
5154 * e1000_change_mtu - Change the Maximum Transfer Unit
5155 * @netdev: network interface device structure
5156 * @new_mtu: new value for maximum frame size
5157 *
5158 * Returns 0 on success, negative on failure
5159 **/
5160static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5161{
5162 struct e1000_adapter *adapter = netdev_priv(netdev);
5163 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5164
Bruce Allan2adc55c2009-06-02 11:28:58 +00005165 /* Jumbo frame support */
5166 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5167 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5168 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005169 return -EINVAL;
5170 }
5171
Bruce Allan2adc55c2009-06-02 11:28:58 +00005172 /* Supported frame sizes */
5173 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5174 (max_frame > adapter->max_hw_frame_size)) {
5175 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005176 return -EINVAL;
5177 }
5178
Bruce Allana1ce6472010-09-22 17:16:40 +00005179 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5180 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5181 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5182 (new_mtu > ETH_DATA_LEN)) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00005183 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005184 return -EINVAL;
5185 }
5186
Bruce Allan6f461f62010-04-27 03:33:04 +00005187 /* 82573 Errata 17 */
5188 if (((adapter->hw.mac.type == e1000_82573) ||
5189 (adapter->hw.mac.type == e1000_82574)) &&
5190 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5191 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5192 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5193 }
5194
Auke Kokbc7f75f2007-09-17 12:30:59 -07005195 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005196 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005197 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005198 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005199 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5200 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005201 if (netif_running(netdev))
5202 e1000e_down(adapter);
5203
Bruce Allanad680762008-03-28 09:15:03 -07005204 /*
5205 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005206 * means we reserve 2 more, this pushes us to allocate from the next
5207 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005208 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005209 * However with the new *_jumbo_rx* routines, jumbo receives will use
5210 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005211 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005212
Jesse Brandeburg99261462010-01-22 22:56:16 +00005213 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005214 adapter->rx_buffer_len = 2048;
5215 else
5216 adapter->rx_buffer_len = 4096;
5217
5218 /* adjust allocation if LPE protects us, and we aren't using SBP */
5219 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5220 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5221 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005222 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005223
Auke Kokbc7f75f2007-09-17 12:30:59 -07005224 if (netif_running(netdev))
5225 e1000e_up(adapter);
5226 else
5227 e1000e_reset(adapter);
5228
5229 clear_bit(__E1000_RESETTING, &adapter->state);
5230
5231 return 0;
5232}
5233
5234static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5235 int cmd)
5236{
5237 struct e1000_adapter *adapter = netdev_priv(netdev);
5238 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005239
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005240 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005241 return -EOPNOTSUPP;
5242
5243 switch (cmd) {
5244 case SIOCGMIIPHY:
5245 data->phy_id = adapter->hw.phy.addr;
5246 break;
5247 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005248 e1000_phy_read_status(adapter);
5249
Bruce Allan7c257692008-04-23 11:09:00 -07005250 switch (data->reg_num & 0x1F) {
5251 case MII_BMCR:
5252 data->val_out = adapter->phy_regs.bmcr;
5253 break;
5254 case MII_BMSR:
5255 data->val_out = adapter->phy_regs.bmsr;
5256 break;
5257 case MII_PHYSID1:
5258 data->val_out = (adapter->hw.phy.id >> 16);
5259 break;
5260 case MII_PHYSID2:
5261 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5262 break;
5263 case MII_ADVERTISE:
5264 data->val_out = adapter->phy_regs.advertise;
5265 break;
5266 case MII_LPA:
5267 data->val_out = adapter->phy_regs.lpa;
5268 break;
5269 case MII_EXPANSION:
5270 data->val_out = adapter->phy_regs.expansion;
5271 break;
5272 case MII_CTRL1000:
5273 data->val_out = adapter->phy_regs.ctrl1000;
5274 break;
5275 case MII_STAT1000:
5276 data->val_out = adapter->phy_regs.stat1000;
5277 break;
5278 case MII_ESTATUS:
5279 data->val_out = adapter->phy_regs.estatus;
5280 break;
5281 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005282 return -EIO;
5283 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005284 break;
5285 case SIOCSMIIREG:
5286 default:
5287 return -EOPNOTSUPP;
5288 }
5289 return 0;
5290}
5291
5292static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5293{
5294 switch (cmd) {
5295 case SIOCGMIIPHY:
5296 case SIOCGMIIREG:
5297 case SIOCSMIIREG:
5298 return e1000_mii_ioctl(netdev, ifr, cmd);
5299 default:
5300 return -EOPNOTSUPP;
5301 }
5302}
5303
Bruce Allana4f58f52009-06-02 11:29:18 +00005304static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5305{
5306 struct e1000_hw *hw = &adapter->hw;
5307 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005308 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005309 int retval = 0;
5310
5311 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005312 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005313
Bruce Allan2b6b1682011-05-13 07:20:09 +00005314 retval = hw->phy.ops.acquire(hw);
5315 if (retval) {
5316 e_err("Could not acquire PHY\n");
5317 return retval;
5318 }
5319
5320 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5321 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5322 if (retval)
5323 goto out;
5324
5325 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005326 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5327 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005328 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5329 (u16)(mac_reg & 0xFFFF));
5330 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5331 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005332 }
5333
5334 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005335 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005336 mac_reg = er32(RCTL);
5337 if (mac_reg & E1000_RCTL_UPE)
5338 phy_reg |= BM_RCTL_UPE;
5339 if (mac_reg & E1000_RCTL_MPE)
5340 phy_reg |= BM_RCTL_MPE;
5341 phy_reg &= ~(BM_RCTL_MO_MASK);
5342 if (mac_reg & E1000_RCTL_MO_3)
5343 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5344 << BM_RCTL_MO_SHIFT);
5345 if (mac_reg & E1000_RCTL_BAM)
5346 phy_reg |= BM_RCTL_BAM;
5347 if (mac_reg & E1000_RCTL_PMCF)
5348 phy_reg |= BM_RCTL_PMCF;
5349 mac_reg = er32(CTRL);
5350 if (mac_reg & E1000_CTRL_RFCE)
5351 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005352 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005353
5354 /* enable PHY wakeup in MAC register */
5355 ew32(WUFC, wufc);
5356 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5357
5358 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005359 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5360 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005361
5362 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005363 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5364 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005365 if (retval)
5366 e_err("Could not set PHY Host Wakeup bit\n");
5367out:
Bruce Allan94d81862009-11-20 23:25:26 +00005368 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005369
5370 return retval;
5371}
5372
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005373static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5374 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005375{
5376 struct net_device *netdev = pci_get_drvdata(pdev);
5377 struct e1000_adapter *adapter = netdev_priv(netdev);
5378 struct e1000_hw *hw = &adapter->hw;
5379 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005380 /* Runtime suspend should only enable wakeup for link changes */
5381 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005382 int retval = 0;
5383
5384 netif_device_detach(netdev);
5385
5386 if (netif_running(netdev)) {
5387 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5388 e1000e_down(adapter);
5389 e1000_free_irq(adapter);
5390 }
Bruce Allan4662e822008-08-26 18:37:06 -07005391 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005392
5393 retval = pci_save_state(pdev);
5394 if (retval)
5395 return retval;
5396
5397 status = er32(STATUS);
5398 if (status & E1000_STATUS_LU)
5399 wufc &= ~E1000_WUFC_LNKC;
5400
5401 if (wufc) {
5402 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005403 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005404
5405 /* turn on all-multi mode if wake on multicast is enabled */
5406 if (wufc & E1000_WUFC_MC) {
5407 rctl = er32(RCTL);
5408 rctl |= E1000_RCTL_MPE;
5409 ew32(RCTL, rctl);
5410 }
5411
5412 ctrl = er32(CTRL);
5413 /* advertise wake from D3Cold */
5414 #define E1000_CTRL_ADVD3WUC 0x00100000
5415 /* phy power management enable */
5416 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005417 ctrl |= E1000_CTRL_ADVD3WUC;
5418 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5419 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005420 ew32(CTRL, ctrl);
5421
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005422 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5423 adapter->hw.phy.media_type ==
5424 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005425 /* keep the laser running in D3 */
5426 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005427 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005428 ew32(CTRL_EXT, ctrl_ext);
5429 }
5430
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005431 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005432 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005433
Auke Kokbc7f75f2007-09-17 12:30:59 -07005434 /* Allow time for pending master requests to run */
5435 e1000e_disable_pcie_master(&adapter->hw);
5436
Bruce Allan82776a42009-08-14 14:35:33 +00005437 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005438 /* enable wakeup by the PHY */
5439 retval = e1000_init_phy_wakeup(adapter, wufc);
5440 if (retval)
5441 return retval;
5442 } else {
5443 /* enable wakeup by the MAC */
5444 ew32(WUFC, wufc);
5445 ew32(WUC, E1000_WUC_PME_EN);
5446 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005447 } else {
5448 ew32(WUC, 0);
5449 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005450 }
5451
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005452 *enable_wake = !!wufc;
5453
Auke Kokbc7f75f2007-09-17 12:30:59 -07005454 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005455 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5456 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005457 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005458
5459 if (adapter->hw.phy.type == e1000_phy_igp_3)
5460 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5461
Bruce Allanad680762008-03-28 09:15:03 -07005462 /*
5463 * Release control of h/w to f/w. If f/w is AMT enabled, this
5464 * would have already happened in close and is redundant.
5465 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005466 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005467
5468 pci_disable_device(pdev);
5469
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005470 return 0;
5471}
5472
5473static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5474{
5475 if (sleep && wake) {
5476 pci_prepare_to_sleep(pdev);
5477 return;
5478 }
5479
5480 pci_wake_from_d3(pdev, wake);
5481 pci_set_power_state(pdev, PCI_D3hot);
5482}
5483
5484static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5485 bool wake)
5486{
5487 struct net_device *netdev = pci_get_drvdata(pdev);
5488 struct e1000_adapter *adapter = netdev_priv(netdev);
5489
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005490 /*
5491 * The pci-e switch on some quad port adapters will report a
5492 * correctable error when the MAC transitions from D0 to D3. To
5493 * prevent this we need to mask off the correctable errors on the
5494 * downstream port of the pci-e switch.
5495 */
5496 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5497 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005498 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005499 u16 devctl;
5500
5501 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5502 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5503 (devctl & ~PCI_EXP_DEVCTL_CERE));
5504
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005505 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005506
5507 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5508 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005509 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005510 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005511}
5512
Bruce Allan6f461f62010-04-27 03:33:04 +00005513#ifdef CONFIG_PCIEASPM
5514static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5515{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005516 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005517}
5518#else
5519static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005520{
5521 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005522 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005523
5524 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005525 * Both device and parent should have the same ASPM setting.
5526 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005527 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005528 pos = pci_pcie_cap(pdev);
5529 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5530 reg16 &= ~state;
5531 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5532
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005533 if (!pdev->bus->self)
5534 return;
5535
Bruce Allan6f461f62010-04-27 03:33:04 +00005536 pos = pci_pcie_cap(pdev->bus->self);
5537 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5538 reg16 &= ~state;
5539 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5540}
5541#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005542static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005543{
5544 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5545 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5546 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5547
5548 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005549}
5550
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005551#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005552static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005553{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005554 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005555}
5556
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005557static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005558{
5559 struct net_device *netdev = pci_get_drvdata(pdev);
5560 struct e1000_adapter *adapter = netdev_priv(netdev);
5561 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005562 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005563 u32 err;
5564
Bruce Allan78cd29d2011-03-24 03:09:03 +00005565 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5566 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5567 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5568 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5569 if (aspm_disable_flag)
5570 e1000e_disable_aspm(pdev, aspm_disable_flag);
5571
Auke Kokbc7f75f2007-09-17 12:30:59 -07005572 pci_set_power_state(pdev, PCI_D0);
5573 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005574 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005575
Bruce Allan4662e822008-08-26 18:37:06 -07005576 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005577 if (netif_running(netdev)) {
5578 err = e1000_request_irq(adapter);
5579 if (err)
5580 return err;
5581 }
5582
Bruce Allan99730e42011-05-13 07:19:48 +00005583 if (hw->mac.type == e1000_pch2lan)
5584 e1000_resume_workarounds_pchlan(&adapter->hw);
5585
Auke Kokbc7f75f2007-09-17 12:30:59 -07005586 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005587
5588 /* report the system wakeup cause from S3/S4 */
5589 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5590 u16 phy_data;
5591
5592 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5593 if (phy_data) {
5594 e_info("PHY Wakeup cause - %s\n",
5595 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5596 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5597 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5598 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005599 phy_data & E1000_WUS_LNKC ?
5600 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005601 }
5602 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5603 } else {
5604 u32 wus = er32(WUS);
5605 if (wus) {
5606 e_info("MAC Wakeup cause - %s\n",
5607 wus & E1000_WUS_EX ? "Unicast Packet" :
5608 wus & E1000_WUS_MC ? "Multicast Packet" :
5609 wus & E1000_WUS_BC ? "Broadcast Packet" :
5610 wus & E1000_WUS_MAG ? "Magic Packet" :
5611 wus & E1000_WUS_LNKC ? "Link Status Change" :
5612 "other");
5613 }
5614 ew32(WUS, ~0);
5615 }
5616
Auke Kokbc7f75f2007-09-17 12:30:59 -07005617 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005618
Bruce Allancd791612010-05-10 14:59:51 +00005619 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005620
5621 if (netif_running(netdev))
5622 e1000e_up(adapter);
5623
5624 netif_device_attach(netdev);
5625
Bruce Allanad680762008-03-28 09:15:03 -07005626 /*
5627 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005628 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005629 * under the control of the driver.
5630 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005631 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005632 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005633
5634 return 0;
5635}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005636
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005637#ifdef CONFIG_PM_SLEEP
5638static int e1000_suspend(struct device *dev)
5639{
5640 struct pci_dev *pdev = to_pci_dev(dev);
5641 int retval;
5642 bool wake;
5643
5644 retval = __e1000_shutdown(pdev, &wake, false);
5645 if (!retval)
5646 e1000_complete_shutdown(pdev, true, wake);
5647
5648 return retval;
5649}
5650
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005651static int e1000_resume(struct device *dev)
5652{
5653 struct pci_dev *pdev = to_pci_dev(dev);
5654 struct net_device *netdev = pci_get_drvdata(pdev);
5655 struct e1000_adapter *adapter = netdev_priv(netdev);
5656
5657 if (e1000e_pm_ready(adapter))
5658 adapter->idle_check = true;
5659
5660 return __e1000_resume(pdev);
5661}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005662#endif /* CONFIG_PM_SLEEP */
5663
5664#ifdef CONFIG_PM_RUNTIME
5665static int e1000_runtime_suspend(struct device *dev)
5666{
5667 struct pci_dev *pdev = to_pci_dev(dev);
5668 struct net_device *netdev = pci_get_drvdata(pdev);
5669 struct e1000_adapter *adapter = netdev_priv(netdev);
5670
5671 if (e1000e_pm_ready(adapter)) {
5672 bool wake;
5673
5674 __e1000_shutdown(pdev, &wake, true);
5675 }
5676
5677 return 0;
5678}
5679
5680static int e1000_idle(struct device *dev)
5681{
5682 struct pci_dev *pdev = to_pci_dev(dev);
5683 struct net_device *netdev = pci_get_drvdata(pdev);
5684 struct e1000_adapter *adapter = netdev_priv(netdev);
5685
5686 if (!e1000e_pm_ready(adapter))
5687 return 0;
5688
5689 if (adapter->idle_check) {
5690 adapter->idle_check = false;
5691 if (!e1000e_has_link(adapter))
5692 pm_schedule_suspend(dev, MSEC_PER_SEC);
5693 }
5694
5695 return -EBUSY;
5696}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005697
5698static int e1000_runtime_resume(struct device *dev)
5699{
5700 struct pci_dev *pdev = to_pci_dev(dev);
5701 struct net_device *netdev = pci_get_drvdata(pdev);
5702 struct e1000_adapter *adapter = netdev_priv(netdev);
5703
5704 if (!e1000e_pm_ready(adapter))
5705 return 0;
5706
5707 adapter->idle_check = !dev->power.runtime_auto;
5708 return __e1000_resume(pdev);
5709}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005710#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005711#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005712
5713static void e1000_shutdown(struct pci_dev *pdev)
5714{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005715 bool wake = false;
5716
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005717 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005718
5719 if (system_state == SYSTEM_POWER_OFF)
5720 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005721}
5722
5723#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005724
5725static irqreturn_t e1000_intr_msix(int irq, void *data)
5726{
5727 struct net_device *netdev = data;
5728 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005729
5730 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005731 int vector, msix_irq;
5732
Dongdong Deng147b2c82010-11-16 19:50:15 -08005733 vector = 0;
5734 msix_irq = adapter->msix_entries[vector].vector;
5735 disable_irq(msix_irq);
5736 e1000_intr_msix_rx(msix_irq, netdev);
5737 enable_irq(msix_irq);
5738
5739 vector++;
5740 msix_irq = adapter->msix_entries[vector].vector;
5741 disable_irq(msix_irq);
5742 e1000_intr_msix_tx(msix_irq, netdev);
5743 enable_irq(msix_irq);
5744
5745 vector++;
5746 msix_irq = adapter->msix_entries[vector].vector;
5747 disable_irq(msix_irq);
5748 e1000_msix_other(msix_irq, netdev);
5749 enable_irq(msix_irq);
5750 }
5751
5752 return IRQ_HANDLED;
5753}
5754
Auke Kokbc7f75f2007-09-17 12:30:59 -07005755/*
5756 * Polling 'interrupt' - used by things like netconsole to send skbs
5757 * without having to re-enable interrupts. It's not called while
5758 * the interrupt routine is executing.
5759 */
5760static void e1000_netpoll(struct net_device *netdev)
5761{
5762 struct e1000_adapter *adapter = netdev_priv(netdev);
5763
Dongdong Deng147b2c82010-11-16 19:50:15 -08005764 switch (adapter->int_mode) {
5765 case E1000E_INT_MODE_MSIX:
5766 e1000_intr_msix(adapter->pdev->irq, netdev);
5767 break;
5768 case E1000E_INT_MODE_MSI:
5769 disable_irq(adapter->pdev->irq);
5770 e1000_intr_msi(adapter->pdev->irq, netdev);
5771 enable_irq(adapter->pdev->irq);
5772 break;
5773 default: /* E1000E_INT_MODE_LEGACY */
5774 disable_irq(adapter->pdev->irq);
5775 e1000_intr(adapter->pdev->irq, netdev);
5776 enable_irq(adapter->pdev->irq);
5777 break;
5778 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005779}
5780#endif
5781
5782/**
5783 * e1000_io_error_detected - called when PCI error is detected
5784 * @pdev: Pointer to PCI device
5785 * @state: The current pci connection state
5786 *
5787 * This function is called after a PCI bus error affecting
5788 * this device has been detected.
5789 */
5790static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5791 pci_channel_state_t state)
5792{
5793 struct net_device *netdev = pci_get_drvdata(pdev);
5794 struct e1000_adapter *adapter = netdev_priv(netdev);
5795
5796 netif_device_detach(netdev);
5797
Mike Masonc93b5a72009-06-30 12:45:53 +00005798 if (state == pci_channel_io_perm_failure)
5799 return PCI_ERS_RESULT_DISCONNECT;
5800
Auke Kokbc7f75f2007-09-17 12:30:59 -07005801 if (netif_running(netdev))
5802 e1000e_down(adapter);
5803 pci_disable_device(pdev);
5804
5805 /* Request a slot slot reset. */
5806 return PCI_ERS_RESULT_NEED_RESET;
5807}
5808
5809/**
5810 * e1000_io_slot_reset - called after the pci bus has been reset.
5811 * @pdev: Pointer to PCI device
5812 *
5813 * Restart the card from scratch, as if from a cold-boot. Implementation
5814 * resembles the first-half of the e1000_resume routine.
5815 */
5816static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5817{
5818 struct net_device *netdev = pci_get_drvdata(pdev);
5819 struct e1000_adapter *adapter = netdev_priv(netdev);
5820 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005821 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005822 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005823 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005824
Bruce Allan78cd29d2011-03-24 03:09:03 +00005825 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5826 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005827 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005828 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5829 if (aspm_disable_flag)
5830 e1000e_disable_aspm(pdev, aspm_disable_flag);
5831
Bruce Allanf0f422e2008-08-04 17:21:53 -07005832 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005833 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005834 dev_err(&pdev->dev,
5835 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005836 result = PCI_ERS_RESULT_DISCONNECT;
5837 } else {
5838 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005839 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005840 pci_restore_state(pdev);
5841
5842 pci_enable_wake(pdev, PCI_D3hot, 0);
5843 pci_enable_wake(pdev, PCI_D3cold, 0);
5844
5845 e1000e_reset(adapter);
5846 ew32(WUS, ~0);
5847 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005848 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005849
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005850 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005851
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005852 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005853}
5854
5855/**
5856 * e1000_io_resume - called when traffic can start flowing again.
5857 * @pdev: Pointer to PCI device
5858 *
5859 * This callback is called when the error recovery driver tells us that
5860 * its OK to resume normal operation. Implementation resembles the
5861 * second-half of the e1000_resume routine.
5862 */
5863static void e1000_io_resume(struct pci_dev *pdev)
5864{
5865 struct net_device *netdev = pci_get_drvdata(pdev);
5866 struct e1000_adapter *adapter = netdev_priv(netdev);
5867
Bruce Allancd791612010-05-10 14:59:51 +00005868 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005869
5870 if (netif_running(netdev)) {
5871 if (e1000e_up(adapter)) {
5872 dev_err(&pdev->dev,
5873 "can't bring device back up after reset\n");
5874 return;
5875 }
5876 }
5877
5878 netif_device_attach(netdev);
5879
Bruce Allanad680762008-03-28 09:15:03 -07005880 /*
5881 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005882 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005883 * under the control of the driver.
5884 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005885 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005886 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005887
5888}
5889
5890static void e1000_print_device_info(struct e1000_adapter *adapter)
5891{
5892 struct e1000_hw *hw = &adapter->hw;
5893 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005894 u32 ret_val;
5895 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005896
5897 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005898 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005899 /* bus width */
5900 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5901 "Width x1"),
5902 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005903 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005904 e_info("Intel(R) PRO/%s Network Connection\n",
5905 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005906 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5907 E1000_PBANUM_LENGTH);
5908 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005909 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005910 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5911 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005912}
5913
Auke Kok10aa4c02008-08-04 17:21:20 -07005914static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5915{
5916 struct e1000_hw *hw = &adapter->hw;
5917 int ret_val;
5918 u16 buf = 0;
5919
5920 if (hw->mac.type != e1000_82573)
5921 return;
5922
5923 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005924 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005925 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005926 dev_warn(&adapter->pdev->dev,
5927 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005928 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005929}
5930
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005931static int e1000_set_features(struct net_device *netdev,
5932 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00005933{
5934 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005935 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00005936
5937 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5938 adapter->flags |= FLAG_TSO_FORCE;
5939
5940 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
5941 NETIF_F_RXCSUM)))
5942 return 0;
5943
5944 if (netif_running(netdev))
5945 e1000e_reinit_locked(adapter);
5946 else
5947 e1000e_reset(adapter);
5948
5949 return 0;
5950}
5951
Stephen Hemminger651c2462008-11-19 21:57:48 -08005952static const struct net_device_ops e1000e_netdev_ops = {
5953 .ndo_open = e1000_open,
5954 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005955 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005956 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005957 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005958 .ndo_set_mac_address = e1000_set_mac,
5959 .ndo_change_mtu = e1000_change_mtu,
5960 .ndo_do_ioctl = e1000_ioctl,
5961 .ndo_tx_timeout = e1000_tx_timeout,
5962 .ndo_validate_addr = eth_validate_addr,
5963
Stephen Hemminger651c2462008-11-19 21:57:48 -08005964 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5965 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5966#ifdef CONFIG_NET_POLL_CONTROLLER
5967 .ndo_poll_controller = e1000_netpoll,
5968#endif
Bruce Allandc221292011-08-19 03:23:48 +00005969 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005970};
5971
Auke Kokbc7f75f2007-09-17 12:30:59 -07005972/**
5973 * e1000_probe - Device Initialization Routine
5974 * @pdev: PCI device information struct
5975 * @ent: entry in e1000_pci_tbl
5976 *
5977 * Returns 0 on success, negative on failure
5978 *
5979 * e1000_probe initializes an adapter identified by a pci_dev structure.
5980 * The OS initialization, configuring of the adapter private structure,
5981 * and a hardware reset occur.
5982 **/
5983static int __devinit e1000_probe(struct pci_dev *pdev,
5984 const struct pci_device_id *ent)
5985{
5986 struct net_device *netdev;
5987 struct e1000_adapter *adapter;
5988 struct e1000_hw *hw;
5989 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005990 resource_size_t mmio_start, mmio_len;
5991 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005992
5993 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005994 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005995 int i, err, pci_using_dac;
5996 u16 eeprom_data = 0;
5997 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5998
Bruce Allan78cd29d2011-03-24 03:09:03 +00005999 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6000 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006001 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006002 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6003 if (aspm_disable_flag)
6004 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006005
Bruce Allanf0f422e2008-08-04 17:21:53 -07006006 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006007 if (err)
6008 return err;
6009
6010 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006011 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006012 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006013 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006014 if (!err)
6015 pci_using_dac = 1;
6016 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006017 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006018 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006019 err = dma_set_coherent_mask(&pdev->dev,
6020 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006021 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006022 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006023 goto err_dma;
6024 }
6025 }
6026 }
6027
Arjan van de Vene8de1482008-10-22 19:55:31 -07006028 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006029 pci_select_bars(pdev, IORESOURCE_MEM),
6030 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006031 if (err)
6032 goto err_pci_reg;
6033
Xiaotian Feng68eac462009-08-14 14:35:52 +00006034 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006035 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006036
Auke Kokbc7f75f2007-09-17 12:30:59 -07006037 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006038 /* PCI config space info */
6039 err = pci_save_state(pdev);
6040 if (err)
6041 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006042
6043 err = -ENOMEM;
6044 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6045 if (!netdev)
6046 goto err_alloc_etherdev;
6047
Auke Kokbc7f75f2007-09-17 12:30:59 -07006048 SET_NETDEV_DEV(netdev, &pdev->dev);
6049
Tom Herbertf85e4df2010-05-05 14:03:32 +00006050 netdev->irq = pdev->irq;
6051
Auke Kokbc7f75f2007-09-17 12:30:59 -07006052 pci_set_drvdata(pdev, netdev);
6053 adapter = netdev_priv(netdev);
6054 hw = &adapter->hw;
6055 adapter->netdev = netdev;
6056 adapter->pdev = pdev;
6057 adapter->ei = ei;
6058 adapter->pba = ei->pba;
6059 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006060 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006061 adapter->hw.adapter = adapter;
6062 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006063 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006064 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6065
6066 mmio_start = pci_resource_start(pdev, 0);
6067 mmio_len = pci_resource_len(pdev, 0);
6068
6069 err = -EIO;
6070 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6071 if (!adapter->hw.hw_addr)
6072 goto err_ioremap;
6073
6074 if ((adapter->flags & FLAG_HAS_FLASH) &&
6075 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6076 flash_start = pci_resource_start(pdev, 1);
6077 flash_len = pci_resource_len(pdev, 1);
6078 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6079 if (!adapter->hw.flash_address)
6080 goto err_flashmap;
6081 }
6082
6083 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006084 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006085 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006086 netdev->watchdog_timeo = 5 * HZ;
6087 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006088 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
6089
6090 netdev->mem_start = mmio_start;
6091 netdev->mem_end = mmio_start + mmio_len;
6092
6093 adapter->bd_number = cards_found++;
6094
Bruce Allan4662e822008-08-26 18:37:06 -07006095 e1000e_check_options(adapter);
6096
Auke Kokbc7f75f2007-09-17 12:30:59 -07006097 /* setup adapter struct */
6098 err = e1000_sw_init(adapter);
6099 if (err)
6100 goto err_sw_init;
6101
Auke Kokbc7f75f2007-09-17 12:30:59 -07006102 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6103 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6104 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6105
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006106 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006107 if (err)
6108 goto err_hw_init;
6109
Bruce Allan4a770352008-10-01 17:18:35 -07006110 if ((adapter->flags & FLAG_IS_ICH) &&
6111 (adapter->flags & FLAG_READ_ONLY_NVM))
6112 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6113
Auke Kokbc7f75f2007-09-17 12:30:59 -07006114 hw->mac.ops.get_bus_info(&adapter->hw);
6115
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006116 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006117
6118 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006119 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006120 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6121 adapter->hw.phy.disable_polarity_correction = 0;
6122 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6123 }
6124
6125 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006126 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006127
Bruce Allandc221292011-08-19 03:23:48 +00006128 /* Set initial default active device features */
6129 netdev->features = (NETIF_F_SG |
6130 NETIF_F_HW_VLAN_RX |
6131 NETIF_F_HW_VLAN_TX |
6132 NETIF_F_TSO |
6133 NETIF_F_TSO6 |
6134 NETIF_F_RXCSUM |
6135 NETIF_F_HW_CSUM);
6136
6137 /* Set user-changeable features (subset of all device features) */
6138 netdev->hw_features = netdev->features;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006139
6140 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6141 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6142
Bruce Allandc221292011-08-19 03:23:48 +00006143 netdev->vlan_features |= (NETIF_F_SG |
6144 NETIF_F_TSO |
6145 NETIF_F_TSO6 |
6146 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006147
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006148 netdev->priv_flags |= IFF_UNICAST_FLT;
6149
Yi Zou7b872a52010-09-22 17:57:58 +00006150 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006151 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006152 netdev->vlan_features |= NETIF_F_HIGHDMA;
6153 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006154
Auke Kokbc7f75f2007-09-17 12:30:59 -07006155 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6156 adapter->flags |= FLAG_MNG_PT_ENABLED;
6157
Bruce Allanad680762008-03-28 09:15:03 -07006158 /*
6159 * before reading the NVM, reset the controller to
6160 * put the device in a known good starting state
6161 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006162 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6163
6164 /*
6165 * systems with ASPM and others may see the checksum fail on the first
6166 * attempt. Let's give it a few tries
6167 */
6168 for (i = 0;; i++) {
6169 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6170 break;
6171 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006172 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006173 err = -EIO;
6174 goto err_eeprom;
6175 }
6176 }
6177
Auke Kok10aa4c02008-08-04 17:21:20 -07006178 e1000_eeprom_checks(adapter);
6179
Bruce Allan608f8a02010-01-13 02:04:58 +00006180 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006181 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006182 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006183
6184 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6185 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6186
6187 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006188 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006189 err = -EIO;
6190 goto err_eeprom;
6191 }
6192
6193 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006194 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006195 adapter->watchdog_timer.data = (unsigned long) adapter;
6196
6197 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006198 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006199 adapter->phy_info_timer.data = (unsigned long) adapter;
6200
6201 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6202 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006203 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6204 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006205 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006206
Auke Kokbc7f75f2007-09-17 12:30:59 -07006207 /* Initialize link parameters. User can change them with ethtool */
6208 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006209 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006210 adapter->hw.fc.requested_mode = e1000_fc_default;
6211 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006212 adapter->hw.phy.autoneg_advertised = 0x2f;
6213
6214 /* ring size defaults */
6215 adapter->rx_ring->count = 256;
6216 adapter->tx_ring->count = 256;
6217
6218 /*
6219 * Initial Wake on LAN setting - If APM wake is enabled in
6220 * the EEPROM, enable the ACPI Magic Packet filter
6221 */
6222 if (adapter->flags & FLAG_APME_IN_WUC) {
6223 /* APME bit in EEPROM is mapped to WUC.APME */
6224 eeprom_data = er32(WUC);
6225 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006226 if ((hw->mac.type > e1000_ich10lan) &&
6227 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006228 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006229 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6230 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6231 (adapter->hw.bus.func == 1))
6232 e1000_read_nvm(&adapter->hw,
6233 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6234 else
6235 e1000_read_nvm(&adapter->hw,
6236 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6237 }
6238
6239 /* fetch WoL from EEPROM */
6240 if (eeprom_data & eeprom_apme_mask)
6241 adapter->eeprom_wol |= E1000_WUFC_MAG;
6242
6243 /*
6244 * now that we have the eeprom settings, apply the special cases
6245 * where the eeprom may be wrong or the board simply won't support
6246 * wake on lan on a particular port
6247 */
6248 if (!(adapter->flags & FLAG_HAS_WOL))
6249 adapter->eeprom_wol = 0;
6250
6251 /* initialize the wol settings based on the eeprom settings */
6252 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006253 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006254
Bruce Allan84527592008-11-21 17:00:22 -08006255 /* save off EEPROM version number */
6256 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6257
Auke Kokbc7f75f2007-09-17 12:30:59 -07006258 /* reset the hardware with the new settings */
6259 e1000e_reset(adapter);
6260
Bruce Allanad680762008-03-28 09:15:03 -07006261 /*
6262 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006263 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006264 * under the control of the driver.
6265 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006266 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006267 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006268
Bruce Allane0dc4f12011-01-06 14:29:50 +00006269 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006270 err = register_netdev(netdev);
6271 if (err)
6272 goto err_register;
6273
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006274 /* carrier off reporting is important to ethtool even BEFORE open */
6275 netif_carrier_off(netdev);
6276
Auke Kokbc7f75f2007-09-17 12:30:59 -07006277 e1000_print_device_info(adapter);
6278
Alan Sternf3ec4f82010-06-08 15:23:51 -04006279 if (pci_dev_run_wake(pdev))
6280 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006281
Auke Kokbc7f75f2007-09-17 12:30:59 -07006282 return 0;
6283
6284err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006285 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006286 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006287err_eeprom:
6288 if (!e1000_check_reset_block(&adapter->hw))
6289 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006290err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006291 kfree(adapter->tx_ring);
6292 kfree(adapter->rx_ring);
6293err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006294 if (adapter->hw.flash_address)
6295 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006296 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006297err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006298 iounmap(adapter->hw.hw_addr);
6299err_ioremap:
6300 free_netdev(netdev);
6301err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006302 pci_release_selected_regions(pdev,
6303 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006304err_pci_reg:
6305err_dma:
6306 pci_disable_device(pdev);
6307 return err;
6308}
6309
6310/**
6311 * e1000_remove - Device Removal Routine
6312 * @pdev: PCI device information struct
6313 *
6314 * e1000_remove is called by the PCI subsystem to alert the driver
6315 * that it should release a PCI device. The could be caused by a
6316 * Hot-Plug event, or because the driver is going to be removed from
6317 * memory.
6318 **/
6319static void __devexit e1000_remove(struct pci_dev *pdev)
6320{
6321 struct net_device *netdev = pci_get_drvdata(pdev);
6322 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006323 bool down = test_bit(__E1000_DOWN, &adapter->state);
6324
Bruce Allanad680762008-03-28 09:15:03 -07006325 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006326 * The timers may be rescheduled, so explicitly disable them
6327 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006328 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006329 if (!down)
6330 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006331 del_timer_sync(&adapter->watchdog_timer);
6332 del_timer_sync(&adapter->phy_info_timer);
6333
Bruce Allan41cec6f2009-11-20 23:28:56 +00006334 cancel_work_sync(&adapter->reset_task);
6335 cancel_work_sync(&adapter->watchdog_task);
6336 cancel_work_sync(&adapter->downshift_task);
6337 cancel_work_sync(&adapter->update_phy_task);
6338 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006339
Bruce Allan17f208d2009-12-01 15:47:22 +00006340 if (!(netdev->flags & IFF_UP))
6341 e1000_power_down_phy(adapter);
6342
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006343 /* Don't lie to e1000_close() down the road. */
6344 if (!down)
6345 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006346 unregister_netdev(netdev);
6347
Alan Sternf3ec4f82010-06-08 15:23:51 -04006348 if (pci_dev_run_wake(pdev))
6349 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006350
Bruce Allanad680762008-03-28 09:15:03 -07006351 /*
6352 * Release control of h/w to f/w. If f/w is AMT enabled, this
6353 * would have already happened in close and is redundant.
6354 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006355 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006356
Bruce Allan4662e822008-08-26 18:37:06 -07006357 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006358 kfree(adapter->tx_ring);
6359 kfree(adapter->rx_ring);
6360
6361 iounmap(adapter->hw.hw_addr);
6362 if (adapter->hw.flash_address)
6363 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006364 pci_release_selected_regions(pdev,
6365 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006366
6367 free_netdev(netdev);
6368
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006369 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006370 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006371
Auke Kokbc7f75f2007-09-17 12:30:59 -07006372 pci_disable_device(pdev);
6373}
6374
6375/* PCI Error Recovery (ERS) */
6376static struct pci_error_handlers e1000_err_handler = {
6377 .error_detected = e1000_io_error_detected,
6378 .slot_reset = e1000_io_slot_reset,
6379 .resume = e1000_io_resume,
6380};
6381
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006382static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006383 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6384 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6385 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6386 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6387 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6388 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006389 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6390 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6391 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006392
Auke Kokbc7f75f2007-09-17 12:30:59 -07006393 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6394 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6395 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6396 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006397
Auke Kokbc7f75f2007-09-17 12:30:59 -07006398 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6399 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6400 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006401
Bruce Allan4662e822008-08-26 18:37:06 -07006402 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006403 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006404 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006405
Auke Kokbc7f75f2007-09-17 12:30:59 -07006406 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6407 board_80003es2lan },
6408 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6409 board_80003es2lan },
6410 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6411 board_80003es2lan },
6412 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6413 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006414
Auke Kokbc7f75f2007-09-17 12:30:59 -07006415 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6416 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6417 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6418 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6419 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6420 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6421 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006422 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006423
Auke Kokbc7f75f2007-09-17 12:30:59 -07006424 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6425 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6426 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6427 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6428 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006429 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006430 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6431 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6432 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6433
6434 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6435 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6436 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006437
Bruce Allanf4187b52008-08-26 18:36:50 -07006438 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6439 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006440 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006441
Bruce Allana4f58f52009-06-02 11:29:18 +00006442 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6443 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6444 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6445 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6446
Bruce Alland3738bb2010-06-16 13:27:28 +00006447 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6448 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6449
Auke Kokbc7f75f2007-09-17 12:30:59 -07006450 { } /* terminate list */
6451};
6452MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6453
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006454#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006455static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006456 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6457 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6458 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006459};
David S. Millere50208a2010-03-16 23:36:24 -07006460#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006461
Auke Kokbc7f75f2007-09-17 12:30:59 -07006462/* PCI Device API Driver */
6463static struct pci_driver e1000_driver = {
6464 .name = e1000e_driver_name,
6465 .id_table = e1000_pci_tbl,
6466 .probe = e1000_probe,
6467 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006468#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006469 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006470#endif
6471 .shutdown = e1000_shutdown,
6472 .err_handler = &e1000_err_handler
6473};
6474
6475/**
6476 * e1000_init_module - Driver Registration Routine
6477 *
6478 * e1000_init_module is the first routine called when the driver is
6479 * loaded. All it does is register with the PCI subsystem.
6480 **/
6481static int __init e1000_init_module(void)
6482{
6483 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006484 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6485 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006486 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006487 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006488
Auke Kokbc7f75f2007-09-17 12:30:59 -07006489 return ret;
6490}
6491module_init(e1000_init_module);
6492
6493/**
6494 * e1000_exit_module - Driver Exit Cleanup Routine
6495 *
6496 * e1000_exit_module is called just before the driver is removed
6497 * from memory.
6498 **/
6499static void __exit e1000_exit_module(void)
6500{
6501 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006502}
6503module_exit(e1000_exit_module);
6504
6505
6506MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6507MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6508MODULE_LICENSE("GPL");
6509MODULE_VERSION(DRV_VERSION);
6510
6511/* e1000_main.c */