blob: 05344d6c0a8bfa3e93ae090db9e4a510a20153d0 [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;
862 bool cleaned = 0;
863 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
891 cleaned = 1;
892 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 Brandeburgb94b50282010-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 Brandeburgb94b50282010-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 Brandeburgb94b50282010-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);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001017 struct e1000_ring *tx_ring = adapter->tx_ring;
1018 unsigned int i = tx_ring->next_to_clean;
1019 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1020 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001021 struct e1000_hw *hw = &adapter->hw;
1022 u16 phy_status, phy_1000t_status, phy_ext_status;
1023 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001025 if (test_bit(__E1000_DOWN, &adapter->state))
1026 return;
1027
Bruce Allan41cec6f2009-11-20 23:28:56 +00001028 e1e_rphy(hw, PHY_STATUS, &phy_status);
1029 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1030 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1031
1032 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1033
1034 /* detected Hardware unit hang */
1035 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001036 " TDH <%x>\n"
1037 " TDT <%x>\n"
1038 " next_to_use <%x>\n"
1039 " next_to_clean <%x>\n"
1040 "buffer_info[next_to_clean]:\n"
1041 " time_stamp <%lx>\n"
1042 " next_to_watch <%x>\n"
1043 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001044 " next_to_watch.status <%x>\n"
1045 "MAC Status <%x>\n"
1046 "PHY Status <%x>\n"
1047 "PHY 1000BASE-T Status <%x>\n"
1048 "PHY Extended Status <%x>\n"
1049 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001050 readl(adapter->hw.hw_addr + tx_ring->head),
1051 readl(adapter->hw.hw_addr + tx_ring->tail),
1052 tx_ring->next_to_use,
1053 tx_ring->next_to_clean,
1054 tx_ring->buffer_info[eop].time_stamp,
1055 eop,
1056 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001057 eop_desc->upper.fields.status,
1058 er32(STATUS),
1059 phy_status,
1060 phy_1000t_status,
1061 phy_ext_status,
1062 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001063}
1064
1065/**
1066 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1067 * @adapter: board private structure
1068 *
1069 * the return value indicates whether actual cleaning was done, there
1070 * is no guarantee that everything was cleaned
1071 **/
1072static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
1073{
1074 struct net_device *netdev = adapter->netdev;
1075 struct e1000_hw *hw = &adapter->hw;
1076 struct e1000_ring *tx_ring = adapter->tx_ring;
1077 struct e1000_tx_desc *tx_desc, *eop_desc;
1078 struct e1000_buffer *buffer_info;
1079 unsigned int i, eop;
1080 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001081 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1082
1083 i = tx_ring->next_to_clean;
1084 eop = tx_ring->buffer_info[i].next_to_watch;
1085 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1086
Alexander Duyck12d04a32009-03-25 22:05:03 +00001087 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1088 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001089 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001090 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001091 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001092 tx_desc = E1000_TX_DESC(*tx_ring, i);
1093 buffer_info = &tx_ring->buffer_info[i];
1094 cleaned = (i == eop);
1095
1096 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001097 total_tx_packets += buffer_info->segs;
1098 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099 }
1100
1101 e1000_put_txbuf(adapter, buffer_info);
1102 tx_desc->upper.data = 0;
1103
1104 i++;
1105 if (i == tx_ring->count)
1106 i = 0;
1107 }
1108
Terry Loftindac87612010-04-09 10:29:49 +00001109 if (i == tx_ring->next_to_use)
1110 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001111 eop = tx_ring->buffer_info[i].next_to_watch;
1112 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001113 }
1114
1115 tx_ring->next_to_clean = i;
1116
1117#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001118 if (count && netif_carrier_ok(netdev) &&
1119 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001120 /* Make sure that anybody stopping the queue after this
1121 * sees the new next_to_clean.
1122 */
1123 smp_mb();
1124
1125 if (netif_queue_stopped(netdev) &&
1126 !(test_bit(__E1000_DOWN, &adapter->state))) {
1127 netif_wake_queue(netdev);
1128 ++adapter->restart_queue;
1129 }
1130 }
1131
1132 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001133 /*
1134 * Detect a transmit hang in hardware, this serializes the
1135 * check with the clearing of time_stamp and movement of i
1136 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001137 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001138 if (tx_ring->buffer_info[i].time_stamp &&
1139 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001140 + (adapter->tx_timeout_factor * HZ)) &&
1141 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001142 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143 netif_stop_queue(netdev);
1144 }
1145 }
1146 adapter->total_tx_bytes += total_tx_bytes;
1147 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001148 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001149}
1150
1151/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001152 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1153 * @adapter: board private structure
1154 *
1155 * the return value indicates whether actual cleaning was done, there
1156 * is no guarantee that everything was cleaned
1157 **/
1158static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1159 int *work_done, int work_to_do)
1160{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001161 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001162 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1163 struct net_device *netdev = adapter->netdev;
1164 struct pci_dev *pdev = adapter->pdev;
1165 struct e1000_ring *rx_ring = adapter->rx_ring;
1166 struct e1000_buffer *buffer_info, *next_buffer;
1167 struct e1000_ps_page *ps_page;
1168 struct sk_buff *skb;
1169 unsigned int i, j;
1170 u32 length, staterr;
1171 int cleaned_count = 0;
1172 bool cleaned = 0;
1173 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1174
1175 i = rx_ring->next_to_clean;
1176 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1177 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1178 buffer_info = &rx_ring->buffer_info[i];
1179
1180 while (staterr & E1000_RXD_STAT_DD) {
1181 if (*work_done >= work_to_do)
1182 break;
1183 (*work_done)++;
1184 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001185 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186
1187 /* in the packet split case this is header only */
1188 prefetch(skb->data - NET_IP_ALIGN);
1189
1190 i++;
1191 if (i == rx_ring->count)
1192 i = 0;
1193 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1194 prefetch(next_rxd);
1195
1196 next_buffer = &rx_ring->buffer_info[i];
1197
1198 cleaned = 1;
1199 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001200 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001201 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202 buffer_info->dma = 0;
1203
Bruce Allanaf667a22010-12-31 06:10:01 +00001204 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b50282010-01-19 14:15:59 +00001205 if (!(staterr & E1000_RXD_STAT_EOP))
1206 adapter->flags2 |= FLAG2_IS_DISCARDING;
1207
1208 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001209 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001210 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b50282010-01-19 14:15:59 +00001211 if (staterr & E1000_RXD_STAT_EOP)
1212 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213 goto next_desc;
1214 }
1215
1216 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1217 dev_kfree_skb_irq(skb);
1218 goto next_desc;
1219 }
1220
1221 length = le16_to_cpu(rx_desc->wb.middle.length0);
1222
1223 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001224 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001225 dev_kfree_skb_irq(skb);
1226 goto next_desc;
1227 }
1228
1229 /* Good Receive */
1230 skb_put(skb, length);
1231
1232 {
Bruce Allanad680762008-03-28 09:15:03 -07001233 /*
1234 * this looks ugly, but it seems compiler issues make it
1235 * more efficient than reusing j
1236 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001237 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1238
Bruce Allanad680762008-03-28 09:15:03 -07001239 /*
1240 * page alloc/put takes too long and effects small packet
1241 * throughput, so unsplit small packets and save the alloc/put
1242 * only valid in softirq (napi) context to call kmap_*
1243 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 if (l1 && (l1 <= copybreak) &&
1245 ((length + l1) <= adapter->rx_ps_bsize0)) {
1246 u8 *vaddr;
1247
Auke Kok47f44e42007-10-25 13:57:44 -07001248 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249
Bruce Allanad680762008-03-28 09:15:03 -07001250 /*
1251 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001252 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001253 * very long
1254 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001255 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1256 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001257 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1258 memcpy(skb_tail_pointer(skb), vaddr, l1);
1259 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001260 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1261 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001262
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001263 /* remove the CRC */
1264 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1265 l1 -= 4;
1266
Auke Kokbc7f75f2007-09-17 12:30:59 -07001267 skb_put(skb, l1);
1268 goto copydone;
1269 } /* if */
1270 }
1271
1272 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1273 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1274 if (!length)
1275 break;
1276
Auke Kok47f44e42007-10-25 13:57:44 -07001277 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001278 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1279 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001280 ps_page->dma = 0;
1281 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1282 ps_page->page = NULL;
1283 skb->len += length;
1284 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001285 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001286 }
1287
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001288 /* strip the ethernet crc, problem is we're using pages now so
1289 * this whole operation can get a little cpu intensive
1290 */
1291 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1292 pskb_trim(skb, skb->len - 4);
1293
Auke Kokbc7f75f2007-09-17 12:30:59 -07001294copydone:
1295 total_rx_bytes += skb->len;
1296 total_rx_packets++;
1297
1298 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1299 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1300
1301 if (rx_desc->wb.upper.header_status &
1302 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1303 adapter->rx_hdr_split++;
1304
1305 e1000_receive_skb(adapter, netdev, skb,
1306 staterr, rx_desc->wb.middle.vlan);
1307
1308next_desc:
1309 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1310 buffer_info->skb = NULL;
1311
1312 /* return some buffers to hardware, one at a time is too slow */
1313 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001314 adapter->alloc_rx_buf(adapter, cleaned_count,
1315 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001316 cleaned_count = 0;
1317 }
1318
1319 /* use prefetched values */
1320 rx_desc = next_rxd;
1321 buffer_info = next_buffer;
1322
1323 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1324 }
1325 rx_ring->next_to_clean = i;
1326
1327 cleaned_count = e1000_desc_unused(rx_ring);
1328 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001329 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001330
Auke Kokbc7f75f2007-09-17 12:30:59 -07001331 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001332 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001333 return cleaned;
1334}
1335
1336/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001337 * e1000_consume_page - helper function
1338 **/
1339static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1340 u16 length)
1341{
1342 bi->page = NULL;
1343 skb->len += length;
1344 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001345 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001346}
1347
1348/**
1349 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1350 * @adapter: board private structure
1351 *
1352 * the return value indicates whether actual cleaning was done, there
1353 * is no guarantee that everything was cleaned
1354 **/
1355
1356static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1357 int *work_done, int work_to_do)
1358{
1359 struct net_device *netdev = adapter->netdev;
1360 struct pci_dev *pdev = adapter->pdev;
1361 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +00001362 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001363 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001364 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001365 unsigned int i;
1366 int cleaned_count = 0;
1367 bool cleaned = false;
1368 unsigned int total_rx_bytes=0, total_rx_packets=0;
1369
1370 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001371 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1372 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001373 buffer_info = &rx_ring->buffer_info[i];
1374
Bruce Allan5f450212011-07-22 06:21:46 +00001375 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001376 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001377
1378 if (*work_done >= work_to_do)
1379 break;
1380 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001381 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001382
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001383 skb = buffer_info->skb;
1384 buffer_info->skb = NULL;
1385
1386 ++i;
1387 if (i == rx_ring->count)
1388 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001389 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001390 prefetch(next_rxd);
1391
1392 next_buffer = &rx_ring->buffer_info[i];
1393
1394 cleaned = true;
1395 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001396 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1397 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001398 buffer_info->dma = 0;
1399
Bruce Allan5f450212011-07-22 06:21:46 +00001400 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001401
1402 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001403 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1404 (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
1405 /* recycle both page and skb */
1406 buffer_info->skb = skb;
1407 /* an error means any chain goes out the window too */
1408 if (rx_ring->rx_skb_top)
1409 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1410 rx_ring->rx_skb_top = NULL;
1411 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001412 }
1413
Bruce Allanf0f1a172010-12-11 05:53:32 +00001414#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001415 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001416 /* this descriptor is only the beginning (or middle) */
1417 if (!rxtop) {
1418 /* this is the beginning of a chain */
1419 rxtop = skb;
1420 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1421 0, length);
1422 } else {
1423 /* this is the middle of a chain */
1424 skb_fill_page_desc(rxtop,
1425 skb_shinfo(rxtop)->nr_frags,
1426 buffer_info->page, 0, length);
1427 /* re-use the skb, only consumed the page */
1428 buffer_info->skb = skb;
1429 }
1430 e1000_consume_page(buffer_info, rxtop, length);
1431 goto next_desc;
1432 } else {
1433 if (rxtop) {
1434 /* end of the chain */
1435 skb_fill_page_desc(rxtop,
1436 skb_shinfo(rxtop)->nr_frags,
1437 buffer_info->page, 0, length);
1438 /* re-use the current skb, we only consumed the
1439 * page */
1440 buffer_info->skb = skb;
1441 skb = rxtop;
1442 rxtop = NULL;
1443 e1000_consume_page(buffer_info, skb, length);
1444 } else {
1445 /* no chain, got EOP, this buf is the packet
1446 * copybreak to save the put_page/alloc_page */
1447 if (length <= copybreak &&
1448 skb_tailroom(skb) >= length) {
1449 u8 *vaddr;
1450 vaddr = kmap_atomic(buffer_info->page,
1451 KM_SKB_DATA_SOFTIRQ);
1452 memcpy(skb_tail_pointer(skb), vaddr,
1453 length);
1454 kunmap_atomic(vaddr,
1455 KM_SKB_DATA_SOFTIRQ);
1456 /* re-use the page, so don't erase
1457 * buffer_info->page */
1458 skb_put(skb, length);
1459 } else {
1460 skb_fill_page_desc(skb, 0,
1461 buffer_info->page, 0,
1462 length);
1463 e1000_consume_page(buffer_info, skb,
1464 length);
1465 }
1466 }
1467 }
1468
1469 /* Receive Checksum Offload XXX recompute due to CRC strip? */
Bruce Allan5f450212011-07-22 06:21:46 +00001470 e1000_rx_checksum(adapter, staterr,
1471 le16_to_cpu(rx_desc->wb.lower.hi_dword.
1472 csum_ip.csum), skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001473
1474 /* probably a little skewed due to removing CRC */
1475 total_rx_bytes += skb->len;
1476 total_rx_packets++;
1477
1478 /* eth type trans needs skb->data to point to something */
1479 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001480 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001481 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001482 goto next_desc;
1483 }
1484
Bruce Allan5f450212011-07-22 06:21:46 +00001485 e1000_receive_skb(adapter, netdev, skb, staterr,
1486 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001487
1488next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001489 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001490
1491 /* return some buffers to hardware, one at a time is too slow */
1492 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001493 adapter->alloc_rx_buf(adapter, cleaned_count,
1494 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001495 cleaned_count = 0;
1496 }
1497
1498 /* use prefetched values */
1499 rx_desc = next_rxd;
1500 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001501
1502 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001503 }
1504 rx_ring->next_to_clean = i;
1505
1506 cleaned_count = e1000_desc_unused(rx_ring);
1507 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001508 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001509
1510 adapter->total_rx_bytes += total_rx_bytes;
1511 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001512 return cleaned;
1513}
1514
1515/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001516 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1517 * @adapter: board private structure
1518 **/
1519static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1520{
1521 struct e1000_ring *rx_ring = adapter->rx_ring;
1522 struct e1000_buffer *buffer_info;
1523 struct e1000_ps_page *ps_page;
1524 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001525 unsigned int i, j;
1526
1527 /* Free all the Rx ring sk_buffs */
1528 for (i = 0; i < rx_ring->count; i++) {
1529 buffer_info = &rx_ring->buffer_info[i];
1530 if (buffer_info->dma) {
1531 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001532 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001533 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001534 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001535 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001536 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001537 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001538 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001539 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001540 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001541 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001542 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001543 buffer_info->dma = 0;
1544 }
1545
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001546 if (buffer_info->page) {
1547 put_page(buffer_info->page);
1548 buffer_info->page = NULL;
1549 }
1550
Auke Kokbc7f75f2007-09-17 12:30:59 -07001551 if (buffer_info->skb) {
1552 dev_kfree_skb(buffer_info->skb);
1553 buffer_info->skb = NULL;
1554 }
1555
1556 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001557 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001558 if (!ps_page->page)
1559 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001560 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1561 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562 ps_page->dma = 0;
1563 put_page(ps_page->page);
1564 ps_page->page = NULL;
1565 }
1566 }
1567
1568 /* there also may be some cached data from a chained receive */
1569 if (rx_ring->rx_skb_top) {
1570 dev_kfree_skb(rx_ring->rx_skb_top);
1571 rx_ring->rx_skb_top = NULL;
1572 }
1573
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574 /* Zero out the descriptor ring */
1575 memset(rx_ring->desc, 0, rx_ring->size);
1576
1577 rx_ring->next_to_clean = 0;
1578 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b50282010-01-19 14:15:59 +00001579 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001580
1581 writel(0, adapter->hw.hw_addr + rx_ring->head);
1582 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1583}
1584
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001585static void e1000e_downshift_workaround(struct work_struct *work)
1586{
1587 struct e1000_adapter *adapter = container_of(work,
1588 struct e1000_adapter, downshift_task);
1589
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001590 if (test_bit(__E1000_DOWN, &adapter->state))
1591 return;
1592
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001593 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1594}
1595
Auke Kokbc7f75f2007-09-17 12:30:59 -07001596/**
1597 * e1000_intr_msi - Interrupt Handler
1598 * @irq: interrupt number
1599 * @data: pointer to a network interface device structure
1600 **/
1601static irqreturn_t e1000_intr_msi(int irq, void *data)
1602{
1603 struct net_device *netdev = data;
1604 struct e1000_adapter *adapter = netdev_priv(netdev);
1605 struct e1000_hw *hw = &adapter->hw;
1606 u32 icr = er32(ICR);
1607
Bruce Allanad680762008-03-28 09:15:03 -07001608 /*
1609 * read ICR disables interrupts using IAM
1610 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001611
dave graham573cca82009-02-10 12:52:05 +00001612 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001613 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001614 /*
1615 * ICH8 workaround-- Call gig speed drop workaround on cable
1616 * disconnect (LSC) before accessing any PHY registers
1617 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001618 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1619 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001620 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001621
Bruce Allanad680762008-03-28 09:15:03 -07001622 /*
1623 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001624 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001625 * adapter in watchdog
1626 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001627 if (netif_carrier_ok(netdev) &&
1628 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1629 /* disable receives */
1630 u32 rctl = er32(RCTL);
1631 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001632 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001633 }
1634 /* guard against interrupt when we're going down */
1635 if (!test_bit(__E1000_DOWN, &adapter->state))
1636 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1637 }
1638
Ben Hutchings288379f2009-01-19 16:43:59 -08001639 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001640 adapter->total_tx_bytes = 0;
1641 adapter->total_tx_packets = 0;
1642 adapter->total_rx_bytes = 0;
1643 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001644 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001645 }
1646
1647 return IRQ_HANDLED;
1648}
1649
1650/**
1651 * e1000_intr - Interrupt Handler
1652 * @irq: interrupt number
1653 * @data: pointer to a network interface device structure
1654 **/
1655static irqreturn_t e1000_intr(int irq, void *data)
1656{
1657 struct net_device *netdev = data;
1658 struct e1000_adapter *adapter = netdev_priv(netdev);
1659 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001660 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001661
Bruce Allana68ea772009-11-20 23:23:16 +00001662 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001663 return IRQ_NONE; /* Not our interrupt */
1664
Bruce Allanad680762008-03-28 09:15:03 -07001665 /*
1666 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1667 * not set, then the adapter didn't send an interrupt
1668 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001669 if (!(icr & E1000_ICR_INT_ASSERTED))
1670 return IRQ_NONE;
1671
Bruce Allanad680762008-03-28 09:15:03 -07001672 /*
1673 * Interrupt Auto-Mask...upon reading ICR,
1674 * interrupts are masked. No need for the
1675 * IMC write
1676 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001677
dave graham573cca82009-02-10 12:52:05 +00001678 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001679 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001680 /*
1681 * ICH8 workaround-- Call gig speed drop workaround on cable
1682 * disconnect (LSC) before accessing any PHY registers
1683 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001684 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1685 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001686 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687
Bruce Allanad680762008-03-28 09:15:03 -07001688 /*
1689 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001690 * For packet buffer work-around on link down event;
1691 * disable receives here in the ISR and
1692 * reset adapter in watchdog
1693 */
1694 if (netif_carrier_ok(netdev) &&
1695 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1696 /* disable receives */
1697 rctl = er32(RCTL);
1698 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001699 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001700 }
1701 /* guard against interrupt when we're going down */
1702 if (!test_bit(__E1000_DOWN, &adapter->state))
1703 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1704 }
1705
Ben Hutchings288379f2009-01-19 16:43:59 -08001706 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707 adapter->total_tx_bytes = 0;
1708 adapter->total_tx_packets = 0;
1709 adapter->total_rx_bytes = 0;
1710 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001711 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001712 }
1713
1714 return IRQ_HANDLED;
1715}
1716
Bruce Allan4662e822008-08-26 18:37:06 -07001717static irqreturn_t e1000_msix_other(int irq, void *data)
1718{
1719 struct net_device *netdev = data;
1720 struct e1000_adapter *adapter = netdev_priv(netdev);
1721 struct e1000_hw *hw = &adapter->hw;
1722 u32 icr = er32(ICR);
1723
1724 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001725 if (!test_bit(__E1000_DOWN, &adapter->state))
1726 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001727 return IRQ_NONE;
1728 }
1729
1730 if (icr & adapter->eiac_mask)
1731 ew32(ICS, (icr & adapter->eiac_mask));
1732
1733 if (icr & E1000_ICR_OTHER) {
1734 if (!(icr & E1000_ICR_LSC))
1735 goto no_link_interrupt;
1736 hw->mac.get_link_status = 1;
1737 /* guard against interrupt when we're going down */
1738 if (!test_bit(__E1000_DOWN, &adapter->state))
1739 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1740 }
1741
1742no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001743 if (!test_bit(__E1000_DOWN, &adapter->state))
1744 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001745
1746 return IRQ_HANDLED;
1747}
1748
1749
1750static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1751{
1752 struct net_device *netdev = data;
1753 struct e1000_adapter *adapter = netdev_priv(netdev);
1754 struct e1000_hw *hw = &adapter->hw;
1755 struct e1000_ring *tx_ring = adapter->tx_ring;
1756
1757
1758 adapter->total_tx_bytes = 0;
1759 adapter->total_tx_packets = 0;
1760
1761 if (!e1000_clean_tx_irq(adapter))
1762 /* Ring was not completely cleaned, so fire another interrupt */
1763 ew32(ICS, tx_ring->ims_val);
1764
1765 return IRQ_HANDLED;
1766}
1767
1768static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1769{
1770 struct net_device *netdev = data;
1771 struct e1000_adapter *adapter = netdev_priv(netdev);
1772
1773 /* Write the ITR value calculated at the end of the
1774 * previous interrupt.
1775 */
1776 if (adapter->rx_ring->set_itr) {
1777 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1778 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1779 adapter->rx_ring->set_itr = 0;
1780 }
1781
Ben Hutchings288379f2009-01-19 16:43:59 -08001782 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001783 adapter->total_rx_bytes = 0;
1784 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001785 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001786 }
1787 return IRQ_HANDLED;
1788}
1789
1790/**
1791 * e1000_configure_msix - Configure MSI-X hardware
1792 *
1793 * e1000_configure_msix sets up the hardware to properly
1794 * generate MSI-X interrupts.
1795 **/
1796static void e1000_configure_msix(struct e1000_adapter *adapter)
1797{
1798 struct e1000_hw *hw = &adapter->hw;
1799 struct e1000_ring *rx_ring = adapter->rx_ring;
1800 struct e1000_ring *tx_ring = adapter->tx_ring;
1801 int vector = 0;
1802 u32 ctrl_ext, ivar = 0;
1803
1804 adapter->eiac_mask = 0;
1805
1806 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1807 if (hw->mac.type == e1000_82574) {
1808 u32 rfctl = er32(RFCTL);
1809 rfctl |= E1000_RFCTL_ACK_DIS;
1810 ew32(RFCTL, rfctl);
1811 }
1812
1813#define E1000_IVAR_INT_ALLOC_VALID 0x8
1814 /* Configure Rx vector */
1815 rx_ring->ims_val = E1000_IMS_RXQ0;
1816 adapter->eiac_mask |= rx_ring->ims_val;
1817 if (rx_ring->itr_val)
1818 writel(1000000000 / (rx_ring->itr_val * 256),
1819 hw->hw_addr + rx_ring->itr_register);
1820 else
1821 writel(1, hw->hw_addr + rx_ring->itr_register);
1822 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1823
1824 /* Configure Tx vector */
1825 tx_ring->ims_val = E1000_IMS_TXQ0;
1826 vector++;
1827 if (tx_ring->itr_val)
1828 writel(1000000000 / (tx_ring->itr_val * 256),
1829 hw->hw_addr + tx_ring->itr_register);
1830 else
1831 writel(1, hw->hw_addr + tx_ring->itr_register);
1832 adapter->eiac_mask |= tx_ring->ims_val;
1833 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1834
1835 /* set vector for Other Causes, e.g. link changes */
1836 vector++;
1837 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1838 if (rx_ring->itr_val)
1839 writel(1000000000 / (rx_ring->itr_val * 256),
1840 hw->hw_addr + E1000_EITR_82574(vector));
1841 else
1842 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1843
1844 /* Cause Tx interrupts on every write back */
1845 ivar |= (1 << 31);
1846
1847 ew32(IVAR, ivar);
1848
1849 /* enable MSI-X PBA support */
1850 ctrl_ext = er32(CTRL_EXT);
1851 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1852
1853 /* Auto-Mask Other interrupts upon ICR read */
1854#define E1000_EIAC_MASK_82574 0x01F00000
1855 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1856 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1857 ew32(CTRL_EXT, ctrl_ext);
1858 e1e_flush();
1859}
1860
1861void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1862{
1863 if (adapter->msix_entries) {
1864 pci_disable_msix(adapter->pdev);
1865 kfree(adapter->msix_entries);
1866 adapter->msix_entries = NULL;
1867 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1868 pci_disable_msi(adapter->pdev);
1869 adapter->flags &= ~FLAG_MSI_ENABLED;
1870 }
Bruce Allan4662e822008-08-26 18:37:06 -07001871}
1872
1873/**
1874 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1875 *
1876 * Attempt to configure interrupts using the best available
1877 * capabilities of the hardware and kernel.
1878 **/
1879void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1880{
1881 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001882 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001883
1884 switch (adapter->int_mode) {
1885 case E1000E_INT_MODE_MSIX:
1886 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001887 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1888 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001889 sizeof(struct msix_entry),
1890 GFP_KERNEL);
1891 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001892 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001893 adapter->msix_entries[i].entry = i;
1894
1895 err = pci_enable_msix(adapter->pdev,
1896 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001897 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001898 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001899 return;
1900 }
1901 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00001902 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001903 e1000e_reset_interrupt_capability(adapter);
1904 }
1905 adapter->int_mode = E1000E_INT_MODE_MSI;
1906 /* Fall through */
1907 case E1000E_INT_MODE_MSI:
1908 if (!pci_enable_msi(adapter->pdev)) {
1909 adapter->flags |= FLAG_MSI_ENABLED;
1910 } else {
1911 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00001912 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001913 }
1914 /* Fall through */
1915 case E1000E_INT_MODE_LEGACY:
1916 /* Don't do anything; this is the system default */
1917 break;
1918 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001919
1920 /* store the number of vectors being used */
1921 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001922}
1923
1924/**
1925 * e1000_request_msix - Initialize MSI-X interrupts
1926 *
1927 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1928 * kernel.
1929 **/
1930static int e1000_request_msix(struct e1000_adapter *adapter)
1931{
1932 struct net_device *netdev = adapter->netdev;
1933 int err = 0, vector = 0;
1934
1935 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001936 snprintf(adapter->rx_ring->name,
1937 sizeof(adapter->rx_ring->name) - 1,
1938 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001939 else
1940 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1941 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001942 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001943 netdev);
1944 if (err)
1945 goto out;
1946 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1947 adapter->rx_ring->itr_val = adapter->itr;
1948 vector++;
1949
1950 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001951 snprintf(adapter->tx_ring->name,
1952 sizeof(adapter->tx_ring->name) - 1,
1953 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001954 else
1955 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1956 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001957 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001958 netdev);
1959 if (err)
1960 goto out;
1961 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1962 adapter->tx_ring->itr_val = adapter->itr;
1963 vector++;
1964
1965 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001966 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001967 if (err)
1968 goto out;
1969
1970 e1000_configure_msix(adapter);
1971 return 0;
1972out:
1973 return err;
1974}
1975
Bruce Allanf8d59f72008-08-08 18:36:11 -07001976/**
1977 * e1000_request_irq - initialize interrupts
1978 *
1979 * Attempts to configure interrupts using the best available
1980 * capabilities of the hardware and kernel.
1981 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001982static int e1000_request_irq(struct e1000_adapter *adapter)
1983{
1984 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001985 int err;
1986
Bruce Allan4662e822008-08-26 18:37:06 -07001987 if (adapter->msix_entries) {
1988 err = e1000_request_msix(adapter);
1989 if (!err)
1990 return err;
1991 /* fall back to MSI */
1992 e1000e_reset_interrupt_capability(adapter);
1993 adapter->int_mode = E1000E_INT_MODE_MSI;
1994 e1000e_set_interrupt_capability(adapter);
1995 }
1996 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001997 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001998 netdev->name, netdev);
1999 if (!err)
2000 return err;
2001
2002 /* fall back to legacy interrupt */
2003 e1000e_reset_interrupt_capability(adapter);
2004 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002005 }
2006
Joe Perchesa0607fd2009-11-18 23:29:17 -08002007 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002008 netdev->name, netdev);
2009 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002010 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002011
2012 return err;
2013}
2014
2015static void e1000_free_irq(struct e1000_adapter *adapter)
2016{
2017 struct net_device *netdev = adapter->netdev;
2018
Bruce Allan4662e822008-08-26 18:37:06 -07002019 if (adapter->msix_entries) {
2020 int vector = 0;
2021
2022 free_irq(adapter->msix_entries[vector].vector, netdev);
2023 vector++;
2024
2025 free_irq(adapter->msix_entries[vector].vector, netdev);
2026 vector++;
2027
2028 /* Other Causes interrupt vector */
2029 free_irq(adapter->msix_entries[vector].vector, netdev);
2030 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002031 }
Bruce Allan4662e822008-08-26 18:37:06 -07002032
2033 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002034}
2035
2036/**
2037 * e1000_irq_disable - Mask off interrupt generation on the NIC
2038 **/
2039static void e1000_irq_disable(struct e1000_adapter *adapter)
2040{
2041 struct e1000_hw *hw = &adapter->hw;
2042
Auke Kokbc7f75f2007-09-17 12:30:59 -07002043 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002044 if (adapter->msix_entries)
2045 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002046 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002047
2048 if (adapter->msix_entries) {
2049 int i;
2050 for (i = 0; i < adapter->num_vectors; i++)
2051 synchronize_irq(adapter->msix_entries[i].vector);
2052 } else {
2053 synchronize_irq(adapter->pdev->irq);
2054 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002055}
2056
2057/**
2058 * e1000_irq_enable - Enable default interrupt generation settings
2059 **/
2060static void e1000_irq_enable(struct e1000_adapter *adapter)
2061{
2062 struct e1000_hw *hw = &adapter->hw;
2063
Bruce Allan4662e822008-08-26 18:37:06 -07002064 if (adapter->msix_entries) {
2065 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2066 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2067 } else {
2068 ew32(IMS, IMS_ENABLE_MASK);
2069 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002070 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002071}
2072
2073/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002074 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002075 * @adapter: address of board private structure
2076 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002077 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002078 * For ASF and Pass Through versions of f/w this means that
2079 * the driver is loaded. For AMT version (only with 82573)
2080 * of the f/w this means that the network i/f is open.
2081 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002082void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002083{
2084 struct e1000_hw *hw = &adapter->hw;
2085 u32 ctrl_ext;
2086 u32 swsm;
2087
2088 /* Let firmware know the driver has taken over */
2089 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2090 swsm = er32(SWSM);
2091 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2092 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2093 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002094 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002095 }
2096}
2097
2098/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002099 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002100 * @adapter: address of board private structure
2101 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002102 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002103 * For ASF and Pass Through versions of f/w this means that the
2104 * driver is no longer loaded. For AMT version (only with 82573) i
2105 * of the f/w this means that the network i/f is closed.
2106 *
2107 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002108void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002109{
2110 struct e1000_hw *hw = &adapter->hw;
2111 u32 ctrl_ext;
2112 u32 swsm;
2113
2114 /* Let firmware taken over control of h/w */
2115 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2116 swsm = er32(SWSM);
2117 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2118 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2119 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002120 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002121 }
2122}
2123
Auke Kokbc7f75f2007-09-17 12:30:59 -07002124/**
2125 * @e1000_alloc_ring - allocate memory for a ring structure
2126 **/
2127static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2128 struct e1000_ring *ring)
2129{
2130 struct pci_dev *pdev = adapter->pdev;
2131
2132 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2133 GFP_KERNEL);
2134 if (!ring->desc)
2135 return -ENOMEM;
2136
2137 return 0;
2138}
2139
2140/**
2141 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2142 * @adapter: board private structure
2143 *
2144 * Return 0 on success, negative on failure
2145 **/
2146int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2147{
2148 struct e1000_ring *tx_ring = adapter->tx_ring;
2149 int err = -ENOMEM, size;
2150
2151 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002152 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002153 if (!tx_ring->buffer_info)
2154 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002155
2156 /* round up to nearest 4K */
2157 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2158 tx_ring->size = ALIGN(tx_ring->size, 4096);
2159
2160 err = e1000_alloc_ring_dma(adapter, tx_ring);
2161 if (err)
2162 goto err;
2163
2164 tx_ring->next_to_use = 0;
2165 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002166
2167 return 0;
2168err:
2169 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002170 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002171 return err;
2172}
2173
2174/**
2175 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2176 * @adapter: board private structure
2177 *
2178 * Returns 0 on success, negative on failure
2179 **/
2180int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2181{
2182 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002183 struct e1000_buffer *buffer_info;
2184 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002185
2186 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002187 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002188 if (!rx_ring->buffer_info)
2189 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190
Auke Kok47f44e42007-10-25 13:57:44 -07002191 for (i = 0; i < rx_ring->count; i++) {
2192 buffer_info = &rx_ring->buffer_info[i];
2193 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2194 sizeof(struct e1000_ps_page),
2195 GFP_KERNEL);
2196 if (!buffer_info->ps_pages)
2197 goto err_pages;
2198 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002199
2200 desc_len = sizeof(union e1000_rx_desc_packet_split);
2201
2202 /* Round up to nearest 4K */
2203 rx_ring->size = rx_ring->count * desc_len;
2204 rx_ring->size = ALIGN(rx_ring->size, 4096);
2205
2206 err = e1000_alloc_ring_dma(adapter, rx_ring);
2207 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002208 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002209
2210 rx_ring->next_to_clean = 0;
2211 rx_ring->next_to_use = 0;
2212 rx_ring->rx_skb_top = NULL;
2213
2214 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002215
2216err_pages:
2217 for (i = 0; i < rx_ring->count; i++) {
2218 buffer_info = &rx_ring->buffer_info[i];
2219 kfree(buffer_info->ps_pages);
2220 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002221err:
2222 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002223 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002224 return err;
2225}
2226
2227/**
2228 * e1000_clean_tx_ring - Free Tx Buffers
2229 * @adapter: board private structure
2230 **/
2231static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2232{
2233 struct e1000_ring *tx_ring = adapter->tx_ring;
2234 struct e1000_buffer *buffer_info;
2235 unsigned long size;
2236 unsigned int i;
2237
2238 for (i = 0; i < tx_ring->count; i++) {
2239 buffer_info = &tx_ring->buffer_info[i];
2240 e1000_put_txbuf(adapter, buffer_info);
2241 }
2242
2243 size = sizeof(struct e1000_buffer) * tx_ring->count;
2244 memset(tx_ring->buffer_info, 0, size);
2245
2246 memset(tx_ring->desc, 0, tx_ring->size);
2247
2248 tx_ring->next_to_use = 0;
2249 tx_ring->next_to_clean = 0;
2250
2251 writel(0, adapter->hw.hw_addr + tx_ring->head);
2252 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2253}
2254
2255/**
2256 * e1000e_free_tx_resources - Free Tx Resources per Queue
2257 * @adapter: board private structure
2258 *
2259 * Free all transmit software resources
2260 **/
2261void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2262{
2263 struct pci_dev *pdev = adapter->pdev;
2264 struct e1000_ring *tx_ring = adapter->tx_ring;
2265
2266 e1000_clean_tx_ring(adapter);
2267
2268 vfree(tx_ring->buffer_info);
2269 tx_ring->buffer_info = NULL;
2270
2271 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2272 tx_ring->dma);
2273 tx_ring->desc = NULL;
2274}
2275
2276/**
2277 * e1000e_free_rx_resources - Free Rx Resources
2278 * @adapter: board private structure
2279 *
2280 * Free all receive software resources
2281 **/
2282
2283void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2284{
2285 struct pci_dev *pdev = adapter->pdev;
2286 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002287 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288
2289 e1000_clean_rx_ring(adapter);
2290
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002291 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002292 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002293
Auke Kokbc7f75f2007-09-17 12:30:59 -07002294 vfree(rx_ring->buffer_info);
2295 rx_ring->buffer_info = NULL;
2296
Auke Kokbc7f75f2007-09-17 12:30:59 -07002297 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2298 rx_ring->dma);
2299 rx_ring->desc = NULL;
2300}
2301
2302/**
2303 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002304 * @adapter: pointer to adapter
2305 * @itr_setting: current adapter->itr
2306 * @packets: the number of packets during this measurement interval
2307 * @bytes: the number of bytes during this measurement interval
2308 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002309 * Stores a new ITR value based on packets and byte
2310 * counts during the last interrupt. The advantage of per interrupt
2311 * computation is faster updates and more accurate ITR for the current
2312 * traffic pattern. Constants in this function were computed
2313 * based on theoretical maximum wire speed and thresholds were set based
2314 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002315 * while increasing bulk throughput. This functionality is controlled
2316 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002317 **/
2318static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2319 u16 itr_setting, int packets,
2320 int bytes)
2321{
2322 unsigned int retval = itr_setting;
2323
2324 if (packets == 0)
2325 goto update_itr_done;
2326
2327 switch (itr_setting) {
2328 case lowest_latency:
2329 /* handle TSO and jumbo frames */
2330 if (bytes/packets > 8000)
2331 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002332 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334 break;
2335 case low_latency: /* 50 usec aka 20000 ints/s */
2336 if (bytes > 10000) {
2337 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002338 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002339 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002340 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002342 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002343 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344 } else if (bytes/packets > 2000) {
2345 retval = bulk_latency;
2346 } else if (packets <= 2 && bytes < 512) {
2347 retval = lowest_latency;
2348 }
2349 break;
2350 case bulk_latency: /* 250 usec aka 4000 ints/s */
2351 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002352 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002353 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002354 } else if (bytes < 6000) {
2355 retval = low_latency;
2356 }
2357 break;
2358 }
2359
2360update_itr_done:
2361 return retval;
2362}
2363
2364static void e1000_set_itr(struct e1000_adapter *adapter)
2365{
2366 struct e1000_hw *hw = &adapter->hw;
2367 u16 current_itr;
2368 u32 new_itr = adapter->itr;
2369
2370 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2371 if (adapter->link_speed != SPEED_1000) {
2372 current_itr = 0;
2373 new_itr = 4000;
2374 goto set_itr_now;
2375 }
2376
Bruce Allan828bac82010-09-29 21:39:37 +00002377 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2378 new_itr = 0;
2379 goto set_itr_now;
2380 }
2381
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382 adapter->tx_itr = e1000_update_itr(adapter,
2383 adapter->tx_itr,
2384 adapter->total_tx_packets,
2385 adapter->total_tx_bytes);
2386 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2387 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2388 adapter->tx_itr = low_latency;
2389
2390 adapter->rx_itr = e1000_update_itr(adapter,
2391 adapter->rx_itr,
2392 adapter->total_rx_packets,
2393 adapter->total_rx_bytes);
2394 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2395 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2396 adapter->rx_itr = low_latency;
2397
2398 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2399
2400 switch (current_itr) {
2401 /* counts and packets in update_itr are dependent on these numbers */
2402 case lowest_latency:
2403 new_itr = 70000;
2404 break;
2405 case low_latency:
2406 new_itr = 20000; /* aka hwitr = ~200 */
2407 break;
2408 case bulk_latency:
2409 new_itr = 4000;
2410 break;
2411 default:
2412 break;
2413 }
2414
2415set_itr_now:
2416 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002417 /*
2418 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002419 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002420 * increasing
2421 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002422 new_itr = new_itr > adapter->itr ?
2423 min(adapter->itr + (new_itr >> 2), new_itr) :
2424 new_itr;
2425 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002426 adapter->rx_ring->itr_val = new_itr;
2427 if (adapter->msix_entries)
2428 adapter->rx_ring->set_itr = 1;
2429 else
Bruce Allan828bac82010-09-29 21:39:37 +00002430 if (new_itr)
2431 ew32(ITR, 1000000000 / (new_itr * 256));
2432 else
2433 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434 }
2435}
2436
2437/**
Bruce Allan4662e822008-08-26 18:37:06 -07002438 * e1000_alloc_queues - Allocate memory for all rings
2439 * @adapter: board private structure to initialize
2440 **/
2441static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2442{
2443 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2444 if (!adapter->tx_ring)
2445 goto err;
2446
2447 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2448 if (!adapter->rx_ring)
2449 goto err;
2450
2451 return 0;
2452err:
2453 e_err("Unable to allocate memory for queues\n");
2454 kfree(adapter->rx_ring);
2455 kfree(adapter->tx_ring);
2456 return -ENOMEM;
2457}
2458
2459/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002460 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002461 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002462 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002463 **/
2464static int e1000_clean(struct napi_struct *napi, int budget)
2465{
2466 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002467 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002468 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002469 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002470
Wang Chen4cf16532008-11-12 23:38:14 -08002471 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002472
Bruce Allan4662e822008-08-26 18:37:06 -07002473 if (adapter->msix_entries &&
2474 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2475 goto clean_rx;
2476
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002477 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002478
Bruce Allan4662e822008-08-26 18:37:06 -07002479clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002480 adapter->clean_rx(adapter, &work_done, budget);
2481
Alexander Duyck12d04a32009-03-25 22:05:03 +00002482 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002483 work_done = budget;
2484
David S. Miller53e52c72008-01-07 21:06:12 -08002485 /* If budget not fully consumed, exit the polling mode */
2486 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002487 if (adapter->itr_setting & 3)
2488 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002489 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002490 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2491 if (adapter->msix_entries)
2492 ew32(IMS, adapter->rx_ring->ims_val);
2493 else
2494 e1000_irq_enable(adapter);
2495 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002496 }
2497
2498 return work_done;
2499}
2500
2501static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2502{
2503 struct e1000_adapter *adapter = netdev_priv(netdev);
2504 struct e1000_hw *hw = &adapter->hw;
2505 u32 vfta, index;
2506
2507 /* don't update vlan cookie if already programmed */
2508 if ((adapter->hw.mng_cookie.status &
2509 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2510 (vid == adapter->mng_vlan_id))
2511 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002512
Auke Kokbc7f75f2007-09-17 12:30:59 -07002513 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002514 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2515 index = (vid >> 5) & 0x7F;
2516 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2517 vfta |= (1 << (vid & 0x1F));
2518 hw->mac.ops.write_vfta(hw, index, vfta);
2519 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002520
2521 set_bit(vid, adapter->active_vlans);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002522}
2523
2524static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2525{
2526 struct e1000_adapter *adapter = netdev_priv(netdev);
2527 struct e1000_hw *hw = &adapter->hw;
2528 u32 vfta, index;
2529
Auke Kokbc7f75f2007-09-17 12:30:59 -07002530 if ((adapter->hw.mng_cookie.status &
2531 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2532 (vid == adapter->mng_vlan_id)) {
2533 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002534 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002535 return;
2536 }
2537
2538 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002539 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2540 index = (vid >> 5) & 0x7F;
2541 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2542 vfta &= ~(1 << (vid & 0x1F));
2543 hw->mac.ops.write_vfta(hw, index, vfta);
2544 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002545
2546 clear_bit(vid, adapter->active_vlans);
2547}
2548
2549/**
2550 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2551 * @adapter: board private structure to initialize
2552 **/
2553static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2554{
2555 struct net_device *netdev = adapter->netdev;
2556 struct e1000_hw *hw = &adapter->hw;
2557 u32 rctl;
2558
2559 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2560 /* disable VLAN receive filtering */
2561 rctl = er32(RCTL);
2562 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2563 ew32(RCTL, rctl);
2564
2565 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2566 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2567 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2568 }
2569 }
2570}
2571
2572/**
2573 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2574 * @adapter: board private structure to initialize
2575 **/
2576static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2577{
2578 struct e1000_hw *hw = &adapter->hw;
2579 u32 rctl;
2580
2581 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2582 /* enable VLAN receive filtering */
2583 rctl = er32(RCTL);
2584 rctl |= E1000_RCTL_VFE;
2585 rctl &= ~E1000_RCTL_CFIEN;
2586 ew32(RCTL, rctl);
2587 }
2588}
2589
2590/**
2591 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2592 * @adapter: board private structure to initialize
2593 **/
2594static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2595{
2596 struct e1000_hw *hw = &adapter->hw;
2597 u32 ctrl;
2598
2599 /* disable VLAN tag insert/strip */
2600 ctrl = er32(CTRL);
2601 ctrl &= ~E1000_CTRL_VME;
2602 ew32(CTRL, ctrl);
2603}
2604
2605/**
2606 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2607 * @adapter: board private structure to initialize
2608 **/
2609static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2610{
2611 struct e1000_hw *hw = &adapter->hw;
2612 u32 ctrl;
2613
2614 /* enable VLAN tag insert/strip */
2615 ctrl = er32(CTRL);
2616 ctrl |= E1000_CTRL_VME;
2617 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002618}
2619
2620static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2621{
2622 struct net_device *netdev = adapter->netdev;
2623 u16 vid = adapter->hw.mng_cookie.vlan_id;
2624 u16 old_vid = adapter->mng_vlan_id;
2625
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002626 if (adapter->hw.mng_cookie.status &
2627 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2628 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002629 adapter->mng_vlan_id = vid;
2630 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002631
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002632 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2633 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002634}
2635
2636static void e1000_restore_vlan(struct e1000_adapter *adapter)
2637{
2638 u16 vid;
2639
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002640 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002641
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002642 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002643 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002644}
2645
Bruce Allancd791612010-05-10 14:59:51 +00002646static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002647{
2648 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002649 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002650
2651 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2652 return;
2653
2654 manc = er32(MANC);
2655
Bruce Allanad680762008-03-28 09:15:03 -07002656 /*
2657 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002658 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002659 * the packets will be handled on SMBUS
2660 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002661 manc |= E1000_MANC_EN_MNG2HOST;
2662 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002663
2664 switch (hw->mac.type) {
2665 default:
2666 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2667 break;
2668 case e1000_82574:
2669 case e1000_82583:
2670 /*
2671 * Check if IPMI pass-through decision filter already exists;
2672 * if so, enable it.
2673 */
2674 for (i = 0, j = 0; i < 8; i++) {
2675 mdef = er32(MDEF(i));
2676
2677 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002678 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002679 continue;
2680
2681 /* Enable this decision filter in MANC2H */
2682 if (mdef)
2683 manc2h |= (1 << i);
2684
2685 j |= mdef;
2686 }
2687
2688 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2689 break;
2690
2691 /* Create new decision filter in an empty filter */
2692 for (i = 0, j = 0; i < 8; i++)
2693 if (er32(MDEF(i)) == 0) {
2694 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2695 E1000_MDEF_PORT_664));
2696 manc2h |= (1 << 1);
2697 j++;
2698 break;
2699 }
2700
2701 if (!j)
2702 e_warn("Unable to create IPMI pass-through filter\n");
2703 break;
2704 }
2705
Auke Kokbc7f75f2007-09-17 12:30:59 -07002706 ew32(MANC2H, manc2h);
2707 ew32(MANC, manc);
2708}
2709
2710/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002711 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002712 * @adapter: board private structure
2713 *
2714 * Configure the Tx unit of the MAC after a reset.
2715 **/
2716static void e1000_configure_tx(struct e1000_adapter *adapter)
2717{
2718 struct e1000_hw *hw = &adapter->hw;
2719 struct e1000_ring *tx_ring = adapter->tx_ring;
2720 u64 tdba;
2721 u32 tdlen, tctl, tipg, tarc;
2722 u32 ipgr1, ipgr2;
2723
2724 /* Setup the HW Tx Head and Tail descriptor pointers */
2725 tdba = tx_ring->dma;
2726 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002727 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002728 ew32(TDBAH, (tdba >> 32));
2729 ew32(TDLEN, tdlen);
2730 ew32(TDH, 0);
2731 ew32(TDT, 0);
2732 tx_ring->head = E1000_TDH;
2733 tx_ring->tail = E1000_TDT;
2734
2735 /* Set the default values for the Tx Inter Packet Gap timer */
2736 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2737 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2738 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2739
2740 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2741 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2742
2743 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2744 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2745 ew32(TIPG, tipg);
2746
2747 /* Set the Tx Interrupt Delay register */
2748 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002749 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002750 ew32(TADV, adapter->tx_abs_int_delay);
2751
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002752 if (adapter->flags2 & FLAG2_DMA_BURST) {
2753 u32 txdctl = er32(TXDCTL(0));
2754 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2755 E1000_TXDCTL_WTHRESH);
2756 /*
2757 * set up some performance related parameters to encourage the
2758 * hardware to use the bus more efficiently in bursts, depends
2759 * on the tx_int_delay to be enabled,
2760 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2761 * hthresh = 1 ==> prefetch when one or more available
2762 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2763 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002764 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002765 */
2766 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2767 ew32(TXDCTL(0), txdctl);
2768 /* erratum work around: set txdctl the same for both queues */
2769 ew32(TXDCTL(1), txdctl);
2770 }
2771
Auke Kokbc7f75f2007-09-17 12:30:59 -07002772 /* Program the Transmit Control Register */
2773 tctl = er32(TCTL);
2774 tctl &= ~E1000_TCTL_CT;
2775 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2776 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2777
2778 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002779 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002780 /*
2781 * set the speed mode bit, we'll clear it if we're not at
2782 * gigabit link later
2783 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002784#define SPEED_MODE_BIT (1 << 21)
2785 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002786 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787 }
2788
2789 /* errata: program both queues to unweighted RR */
2790 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002791 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002792 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002793 ew32(TARC(0), tarc);
2794 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002795 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002796 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002797 }
2798
Auke Kokbc7f75f2007-09-17 12:30:59 -07002799 /* Setup Transmit Descriptor Settings for eop descriptor */
2800 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2801
2802 /* only set IDE if we are delaying interrupts using the timers */
2803 if (adapter->tx_int_delay)
2804 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2805
2806 /* enable Report Status bit */
2807 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2808
2809 ew32(TCTL, tctl);
2810
Simon Hormanedfea6e62009-06-08 14:28:36 +00002811 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002812}
2813
2814/**
2815 * e1000_setup_rctl - configure the receive control registers
2816 * @adapter: Board private structure
2817 **/
2818#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2819 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2820static void e1000_setup_rctl(struct e1000_adapter *adapter)
2821{
2822 struct e1000_hw *hw = &adapter->hw;
2823 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002824 u32 pages = 0;
2825
Bruce Allana1ce6472010-09-22 17:16:40 +00002826 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2827 if (hw->mac.type == e1000_pch2lan) {
2828 s32 ret_val;
2829
2830 if (adapter->netdev->mtu > ETH_DATA_LEN)
2831 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2832 else
2833 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002834
2835 if (ret_val)
2836 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002837 }
2838
Auke Kokbc7f75f2007-09-17 12:30:59 -07002839 /* Program MC offset vector base */
2840 rctl = er32(RCTL);
2841 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2842 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2843 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2844 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2845
2846 /* Do not Store bad packets */
2847 rctl &= ~E1000_RCTL_SBP;
2848
2849 /* Enable Long Packet receive */
2850 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2851 rctl &= ~E1000_RCTL_LPE;
2852 else
2853 rctl |= E1000_RCTL_LPE;
2854
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002855 /* Some systems expect that the CRC is included in SMBUS traffic. The
2856 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2857 * host memory when this is enabled
2858 */
2859 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2860 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002861
Bruce Allana4f58f52009-06-02 11:29:18 +00002862 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2863 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2864 u16 phy_data;
2865
2866 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2867 phy_data &= 0xfff8;
2868 phy_data |= (1 << 2);
2869 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2870
2871 e1e_rphy(hw, 22, &phy_data);
2872 phy_data &= 0x0fff;
2873 phy_data |= (1 << 14);
2874 e1e_wphy(hw, 0x10, 0x2823);
2875 e1e_wphy(hw, 0x11, 0x0003);
2876 e1e_wphy(hw, 22, phy_data);
2877 }
2878
Auke Kokbc7f75f2007-09-17 12:30:59 -07002879 /* Setup buffer sizes */
2880 rctl &= ~E1000_RCTL_SZ_4096;
2881 rctl |= E1000_RCTL_BSEX;
2882 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002883 case 2048:
2884 default:
2885 rctl |= E1000_RCTL_SZ_2048;
2886 rctl &= ~E1000_RCTL_BSEX;
2887 break;
2888 case 4096:
2889 rctl |= E1000_RCTL_SZ_4096;
2890 break;
2891 case 8192:
2892 rctl |= E1000_RCTL_SZ_8192;
2893 break;
2894 case 16384:
2895 rctl |= E1000_RCTL_SZ_16384;
2896 break;
2897 }
2898
Bruce Allan5f450212011-07-22 06:21:46 +00002899 /* Enable Extended Status in all Receive Descriptors */
2900 rfctl = er32(RFCTL);
2901 rfctl |= E1000_RFCTL_EXTEN;
2902
Auke Kokbc7f75f2007-09-17 12:30:59 -07002903 /*
2904 * 82571 and greater support packet-split where the protocol
2905 * header is placed in skb->data and the packet data is
2906 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2907 * In the case of a non-split, skb->data is linearly filled,
2908 * followed by the page buffers. Therefore, skb->data is
2909 * sized to hold the largest protocol header.
2910 *
2911 * allocations using alloc_page take too long for regular MTU
2912 * so only enable packet split for jumbo frames
2913 *
2914 * Using pages when the page size is greater than 16k wastes
2915 * a lot of memory, since we allocate 3 pages at all times
2916 * per packet.
2917 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002918 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fe2010-06-17 18:59:27 +00002919 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002920 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002921 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002922 else
2923 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002924
2925 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002926 u32 psrctl = 0;
2927
Bruce Allanad680762008-03-28 09:15:03 -07002928 /*
2929 * disable packet split support for IPv6 extension headers,
2930 * because some malformed IPv6 headers can hang the Rx
2931 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002932 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2933 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2934
Auke Kok140a7482007-10-25 13:57:58 -07002935 /* Enable Packet split descriptors */
2936 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002937
2938 psrctl |= adapter->rx_ps_bsize0 >>
2939 E1000_PSRCTL_BSIZE0_SHIFT;
2940
2941 switch (adapter->rx_ps_pages) {
2942 case 3:
2943 psrctl |= PAGE_SIZE <<
2944 E1000_PSRCTL_BSIZE3_SHIFT;
2945 case 2:
2946 psrctl |= PAGE_SIZE <<
2947 E1000_PSRCTL_BSIZE2_SHIFT;
2948 case 1:
2949 psrctl |= PAGE_SIZE >>
2950 E1000_PSRCTL_BSIZE1_SHIFT;
2951 break;
2952 }
2953
2954 ew32(PSRCTL, psrctl);
2955 }
2956
Bruce Allan5f450212011-07-22 06:21:46 +00002957 ew32(RFCTL, rfctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002959 /* just started the receive unit, no need to restart */
2960 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961}
2962
2963/**
2964 * e1000_configure_rx - Configure Receive Unit after Reset
2965 * @adapter: board private structure
2966 *
2967 * Configure the Rx unit of the MAC after a reset.
2968 **/
2969static void e1000_configure_rx(struct e1000_adapter *adapter)
2970{
2971 struct e1000_hw *hw = &adapter->hw;
2972 struct e1000_ring *rx_ring = adapter->rx_ring;
2973 u64 rdba;
2974 u32 rdlen, rctl, rxcsum, ctrl_ext;
2975
2976 if (adapter->rx_ps_pages) {
2977 /* this is a 32 byte descriptor */
2978 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002979 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002980 adapter->clean_rx = e1000_clean_rx_irq_ps;
2981 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002982 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00002983 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002984 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2985 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002986 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00002987 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002988 adapter->clean_rx = e1000_clean_rx_irq;
2989 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2990 }
2991
2992 /* disable receives while setting up the descriptors */
2993 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07002994 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
2995 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002996 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00002997 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002998
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002999 if (adapter->flags2 & FLAG2_DMA_BURST) {
3000 /*
3001 * set the writeback threshold (only takes effect if the RDTR
3002 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003003 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003004 * granularity = 01
3005 * wthresh = 04,
3006 * hthresh = 04,
3007 * pthresh = 0x20
3008 */
3009 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3010 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3011
3012 /*
3013 * override the delay timers for enabling bursting, only if
3014 * the value was not set by the user via module options
3015 */
3016 if (adapter->rx_int_delay == DEFAULT_RDTR)
3017 adapter->rx_int_delay = BURST_RDTR;
3018 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3019 adapter->rx_abs_int_delay = BURST_RADV;
3020 }
3021
Auke Kokbc7f75f2007-09-17 12:30:59 -07003022 /* set the Receive Delay Timer Register */
3023 ew32(RDTR, adapter->rx_int_delay);
3024
3025 /* irq moderation */
3026 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003027 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003028 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003029
3030 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003031 /* Auto-Mask interrupts upon ICR access */
3032 ctrl_ext |= E1000_CTRL_EXT_IAME;
3033 ew32(IAM, 0xffffffff);
3034 ew32(CTRL_EXT, ctrl_ext);
3035 e1e_flush();
3036
Bruce Allanad680762008-03-28 09:15:03 -07003037 /*
3038 * Setup the HW Rx Head and Tail Descriptor Pointers and
3039 * the Base and Length of the Rx Descriptor Ring
3040 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003041 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07003042 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003043 ew32(RDBAH, (rdba >> 32));
3044 ew32(RDLEN, rdlen);
3045 ew32(RDH, 0);
3046 ew32(RDT, 0);
3047 rx_ring->head = E1000_RDH;
3048 rx_ring->tail = E1000_RDT;
3049
3050 /* Enable Receive Checksum Offload for TCP and UDP */
3051 rxcsum = er32(RXCSUM);
Bruce Allandc221292011-08-19 03:23:48 +00003052 if (adapter->netdev->features & NETIF_F_RXCSUM) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003053 rxcsum |= E1000_RXCSUM_TUOFL;
3054
Bruce Allanad680762008-03-28 09:15:03 -07003055 /*
3056 * IPv4 payload checksum for UDP fragments must be
3057 * used in conjunction with packet-split.
3058 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003059 if (adapter->rx_ps_pages)
3060 rxcsum |= E1000_RXCSUM_IPPCSE;
3061 } else {
3062 rxcsum &= ~E1000_RXCSUM_TUOFL;
3063 /* no need to clear IPPCSE as it defaults to 0 */
3064 }
3065 ew32(RXCSUM, rxcsum);
3066
Bruce Allanad680762008-03-28 09:15:03 -07003067 /*
3068 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07003069 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07003070 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
3071 */
Bruce Allan828bac82010-09-29 21:39:37 +00003072 if ((adapter->flags & FLAG_HAS_ERT) ||
3073 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003074 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3075 u32 rxdctl = er32(RXDCTL(0));
3076 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00003077 if (adapter->flags & FLAG_HAS_ERT)
3078 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00003079 /*
3080 * With jumbo frames and early-receive enabled,
3081 * excessive C-state transition latencies result in
3082 * dropped transactions.
3083 */
Bruce Allanaf667a22010-12-31 06:10:01 +00003084 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003085 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003086 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3087 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003088 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003089 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003090
3091 /* Enable Receives */
3092 ew32(RCTL, rctl);
3093}
3094
3095/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003096 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003097 * @netdev: network interface device structure
3098 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003099 * Writes multicast address list to the MTA hash table.
3100 * Returns: -ENOMEM on failure
3101 * 0 on no addresses written
3102 * X on writing X addresses to MTA
3103 */
3104static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003105{
3106 struct e1000_adapter *adapter = netdev_priv(netdev);
3107 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad2010-04-01 21:22:57 +00003108 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003109 u8 *mta_list;
3110 int i;
3111
3112 if (netdev_mc_empty(netdev)) {
3113 /* nothing to program, so clear mc list */
3114 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3115 return 0;
3116 }
3117
3118 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3119 if (!mta_list)
3120 return -ENOMEM;
3121
3122 /* update_mc_addr_list expects a packed array of only addresses. */
3123 i = 0;
3124 netdev_for_each_mc_addr(ha, netdev)
3125 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3126
3127 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3128 kfree(mta_list);
3129
3130 return netdev_mc_count(netdev);
3131}
3132
3133/**
3134 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3135 * @netdev: network interface device structure
3136 *
3137 * Writes unicast address list to the RAR table.
3138 * Returns: -ENOMEM on failure/insufficient address space
3139 * 0 on no addresses written
3140 * X on writing X addresses to the RAR table
3141 **/
3142static int e1000e_write_uc_addr_list(struct net_device *netdev)
3143{
3144 struct e1000_adapter *adapter = netdev_priv(netdev);
3145 struct e1000_hw *hw = &adapter->hw;
3146 unsigned int rar_entries = hw->mac.rar_entry_count;
3147 int count = 0;
3148
3149 /* save a rar entry for our hardware address */
3150 rar_entries--;
3151
3152 /* save a rar entry for the LAA workaround */
3153 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3154 rar_entries--;
3155
3156 /* return ENOMEM indicating insufficient memory for addresses */
3157 if (netdev_uc_count(netdev) > rar_entries)
3158 return -ENOMEM;
3159
3160 if (!netdev_uc_empty(netdev) && rar_entries) {
3161 struct netdev_hw_addr *ha;
3162
3163 /*
3164 * write the addresses in reverse order to avoid write
3165 * combining
3166 */
3167 netdev_for_each_uc_addr(ha, netdev) {
3168 if (!rar_entries)
3169 break;
3170 e1000e_rar_set(hw, ha->addr, rar_entries--);
3171 count++;
3172 }
3173 }
3174
3175 /* zero out the remaining RAR entries not used above */
3176 for (; rar_entries > 0; rar_entries--) {
3177 ew32(RAH(rar_entries), 0);
3178 ew32(RAL(rar_entries), 0);
3179 }
3180 e1e_flush();
3181
3182 return count;
3183}
3184
3185/**
3186 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3187 * @netdev: network interface device structure
3188 *
3189 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3190 * address list or the network interface flags are updated. This routine is
3191 * responsible for configuring the hardware for proper unicast, multicast,
3192 * promiscuous mode, and all-multi behavior.
3193 **/
3194static void e1000e_set_rx_mode(struct net_device *netdev)
3195{
3196 struct e1000_adapter *adapter = netdev_priv(netdev);
3197 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003198 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003199
3200 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003201 rctl = er32(RCTL);
3202
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003203 /* clear the affected bits */
3204 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3205
Auke Kokbc7f75f2007-09-17 12:30:59 -07003206 if (netdev->flags & IFF_PROMISC) {
3207 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003208 /* Do not hardware filter VLANs in promisc mode */
3209 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003210 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003211 int count;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003212 if (netdev->flags & IFF_ALLMULTI) {
3213 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003214 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003215 /*
3216 * Write addresses to the MTA, if the attempt fails
3217 * then we should just turn on promiscuous mode so
3218 * that we can at least receive multicast traffic
3219 */
3220 count = e1000e_write_mc_addr_list(netdev);
3221 if (count < 0)
3222 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003223 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003224 e1000e_vlan_filter_enable(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003225 /*
3226 * Write addresses to available RAR registers, if there is not
3227 * sufficient space to store all the addresses then enable
3228 * unicast promiscuous mode
3229 */
3230 count = e1000e_write_uc_addr_list(netdev);
3231 if (count < 0)
3232 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003233 }
3234
3235 ew32(RCTL, rctl);
3236
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003237 if (netdev->features & NETIF_F_HW_VLAN_RX)
3238 e1000e_vlan_strip_enable(adapter);
3239 else
3240 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003241}
3242
3243/**
Bruce Allanad680762008-03-28 09:15:03 -07003244 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003245 * @adapter: private board structure
3246 **/
3247static void e1000_configure(struct e1000_adapter *adapter)
3248{
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003249 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003250
3251 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003252 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003253
3254 e1000_configure_tx(adapter);
3255 e1000_setup_rctl(adapter);
3256 e1000_configure_rx(adapter);
Jeff Kirsherc2fed992011-07-12 16:10:12 +00003257 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring),
3258 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003259}
3260
3261/**
3262 * e1000e_power_up_phy - restore link in case the phy was powered down
3263 * @adapter: address of board private structure
3264 *
3265 * The phy may be powered down to save power and turn off link when the
3266 * driver is unloaded and wake on lan is not enabled (among others)
3267 * *** this routine MUST be followed by a call to e1000e_reset ***
3268 **/
3269void e1000e_power_up_phy(struct e1000_adapter *adapter)
3270{
Bruce Allan17f208d2009-12-01 15:47:22 +00003271 if (adapter->hw.phy.ops.power_up)
3272 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003273
3274 adapter->hw.mac.ops.setup_link(&adapter->hw);
3275}
3276
3277/**
3278 * e1000_power_down_phy - Power down the PHY
3279 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003280 * Power down the PHY so no link is implied when interface is down.
3281 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003282 */
3283static void e1000_power_down_phy(struct e1000_adapter *adapter)
3284{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003285 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003286 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003287 return;
3288
Bruce Allan17f208d2009-12-01 15:47:22 +00003289 if (adapter->hw.phy.ops.power_down)
3290 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003291}
3292
3293/**
3294 * e1000e_reset - bring the hardware into a known good state
3295 *
3296 * This function boots the hardware and enables some settings that
3297 * require a configuration cycle of the hardware - those cannot be
3298 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003299 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003300 */
3301void e1000e_reset(struct e1000_adapter *adapter)
3302{
3303 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003304 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003305 struct e1000_hw *hw = &adapter->hw;
3306 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003307 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003308 u16 hwm;
3309
Bruce Allanad680762008-03-28 09:15:03 -07003310 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003311 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003312
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003313 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003314 /*
3315 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003316 * large enough to accommodate two full transmit packets,
3317 * rounded up to the next 1KB and expressed in KB. Likewise,
3318 * the Rx FIFO should be large enough to accommodate at least
3319 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003320 * expressed in KB.
3321 */
Auke Kokdf762462007-10-25 13:57:53 -07003322 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003323 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003324 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003326 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003327 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003328 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003329 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003330 */
3331 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003332 sizeof(struct e1000_tx_desc) -
3333 ETH_FCS_LEN) * 2;
3334 min_tx_space = ALIGN(min_tx_space, 1024);
3335 min_tx_space >>= 10;
3336 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003337 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003338 min_rx_space = ALIGN(min_rx_space, 1024);
3339 min_rx_space >>= 10;
3340
Bruce Allanad680762008-03-28 09:15:03 -07003341 /*
3342 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003343 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003344 * allocation, take space away from current Rx allocation
3345 */
Auke Kokdf762462007-10-25 13:57:53 -07003346 if ((tx_space < min_tx_space) &&
3347 ((min_tx_space - tx_space) < pba)) {
3348 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003349
Bruce Allanad680762008-03-28 09:15:03 -07003350 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003351 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003352 * adjustment or use Early Receive if available
3353 */
Auke Kokdf762462007-10-25 13:57:53 -07003354 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003355 (!(adapter->flags & FLAG_HAS_ERT)))
3356 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003357 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003358 }
Auke Kokdf762462007-10-25 13:57:53 -07003359
3360 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003361 }
3362
Bruce Allanad680762008-03-28 09:15:03 -07003363 /*
3364 * flow control settings
3365 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003366 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003367 * (or the size used for early receive) above it in the Rx FIFO.
3368 * Set it to the lower of:
3369 * - 90% of the Rx FIFO size, and
3370 * - the full Rx FIFO size minus the early receive size (for parts
3371 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003372 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003373 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003374 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3375 fc->pause_time = 0xFFFF;
3376 else
3377 fc->pause_time = E1000_FC_PAUSE_TIME;
3378 fc->send_xon = 1;
3379 fc->current_mode = fc->requested_mode;
3380
3381 switch (hw->mac.type) {
3382 default:
3383 if ((adapter->flags & FLAG_HAS_ERT) &&
3384 (adapter->netdev->mtu > ETH_DATA_LEN))
3385 hwm = min(((pba << 10) * 9 / 10),
3386 ((pba << 10) - (E1000_ERT_2048 << 3)));
3387 else
3388 hwm = min(((pba << 10) * 9 / 10),
3389 ((pba << 10) - adapter->max_frame_size));
3390
3391 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3392 fc->low_water = fc->high_water - 8;
3393 break;
3394 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003395 /*
3396 * Workaround PCH LOM adapter hangs with certain network
3397 * loads. If hangs persist, try disabling Tx flow control.
3398 */
3399 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3400 fc->high_water = 0x3500;
3401 fc->low_water = 0x1500;
3402 } else {
3403 fc->high_water = 0x5000;
3404 fc->low_water = 0x3000;
3405 }
Bruce Allana3055952010-05-10 15:02:12 +00003406 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003407 break;
3408 case e1000_pch2lan:
3409 fc->high_water = 0x05C20;
3410 fc->low_water = 0x05048;
3411 fc->pause_time = 0x0650;
3412 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003413 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3414 pba = 14;
3415 ew32(PBA, pba);
3416 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003417 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003418 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003419
Bruce Allan828bac82010-09-29 21:39:37 +00003420 /*
3421 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3422 * fit in receive buffer and early-receive not supported.
3423 */
3424 if (adapter->itr_setting & 0x3) {
3425 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3426 !(adapter->flags & FLAG_HAS_ERT)) {
3427 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3428 dev_info(&adapter->pdev->dev,
3429 "Interrupt Throttle Rate turned off\n");
3430 adapter->flags2 |= FLAG2_DISABLE_AIM;
3431 ew32(ITR, 0);
3432 }
3433 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3434 dev_info(&adapter->pdev->dev,
3435 "Interrupt Throttle Rate turned on\n");
3436 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3437 adapter->itr = 20000;
3438 ew32(ITR, 1000000000 / (adapter->itr * 256));
3439 }
3440 }
3441
Auke Kokbc7f75f2007-09-17 12:30:59 -07003442 /* Allow time for pending master requests to run */
3443 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003444
3445 /*
3446 * For parts with AMT enabled, let the firmware know
3447 * that the network interface is in control
3448 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003449 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003450 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003451
Auke Kokbc7f75f2007-09-17 12:30:59 -07003452 ew32(WUC, 0);
3453
3454 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003455 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003456
3457 e1000_update_mng_vlan(adapter);
3458
3459 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3460 ew32(VET, ETH_P_8021Q);
3461
3462 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003463
3464 if (!netif_running(adapter->netdev) &&
3465 !test_bit(__E1000_TESTING, &adapter->state)) {
3466 e1000_power_down_phy(adapter);
3467 return;
3468 }
3469
Auke Kokbc7f75f2007-09-17 12:30:59 -07003470 e1000_get_phy_info(hw);
3471
Bruce Allan918d7192009-06-02 11:28:20 +00003472 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3473 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003474 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003475 /*
3476 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003477 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003478 * different we would do if it failed
3479 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003480 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3481 phy_data &= ~IGP02E1000_PM_SPD;
3482 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3483 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003484}
3485
3486int e1000e_up(struct e1000_adapter *adapter)
3487{
3488 struct e1000_hw *hw = &adapter->hw;
3489
3490 /* hardware has been reset, we need to reload some things */
3491 e1000_configure(adapter);
3492
3493 clear_bit(__E1000_DOWN, &adapter->state);
3494
3495 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003496 if (adapter->msix_entries)
3497 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003498 e1000_irq_enable(adapter);
3499
Bruce Allan400484f2011-05-13 07:20:03 +00003500 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003501
Auke Kokbc7f75f2007-09-17 12:30:59 -07003502 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003503 if (adapter->msix_entries)
3504 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3505 else
3506 ew32(ICS, E1000_ICS_LSC);
3507
Auke Kokbc7f75f2007-09-17 12:30:59 -07003508 return 0;
3509}
3510
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003511static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3512{
3513 struct e1000_hw *hw = &adapter->hw;
3514
3515 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3516 return;
3517
3518 /* flush pending descriptor writebacks to memory */
3519 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3520 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3521
3522 /* execute the writes immediately */
3523 e1e_flush();
3524}
3525
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003526static void e1000e_update_stats(struct e1000_adapter *adapter);
3527
Auke Kokbc7f75f2007-09-17 12:30:59 -07003528void e1000e_down(struct e1000_adapter *adapter)
3529{
3530 struct net_device *netdev = adapter->netdev;
3531 struct e1000_hw *hw = &adapter->hw;
3532 u32 tctl, rctl;
3533
Bruce Allanad680762008-03-28 09:15:03 -07003534 /*
3535 * signal that we're down so the interrupt handler does not
3536 * reschedule our watchdog timer
3537 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003538 set_bit(__E1000_DOWN, &adapter->state);
3539
3540 /* disable receives in the hardware */
3541 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003542 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3543 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003544 /* flush and sleep below */
3545
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003546 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003547
3548 /* disable transmits in the hardware */
3549 tctl = er32(TCTL);
3550 tctl &= ~E1000_TCTL_EN;
3551 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003552
Auke Kokbc7f75f2007-09-17 12:30:59 -07003553 /* flush both disables and wait for them to finish */
3554 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003555 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003556
3557 napi_disable(&adapter->napi);
3558 e1000_irq_disable(adapter);
3559
3560 del_timer_sync(&adapter->watchdog_timer);
3561 del_timer_sync(&adapter->phy_info_timer);
3562
Auke Kokbc7f75f2007-09-17 12:30:59 -07003563 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003564
3565 spin_lock(&adapter->stats64_lock);
3566 e1000e_update_stats(adapter);
3567 spin_unlock(&adapter->stats64_lock);
3568
Bruce Allan400484f2011-05-13 07:20:03 +00003569 e1000e_flush_descriptors(adapter);
3570 e1000_clean_tx_ring(adapter);
3571 e1000_clean_rx_ring(adapter);
3572
Auke Kokbc7f75f2007-09-17 12:30:59 -07003573 adapter->link_speed = 0;
3574 adapter->link_duplex = 0;
3575
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003576 if (!pci_channel_offline(adapter->pdev))
3577 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003578
Auke Kokbc7f75f2007-09-17 12:30:59 -07003579 /*
3580 * TODO: for power management, we could drop the link and
3581 * pci_disable_device here.
3582 */
3583}
3584
3585void e1000e_reinit_locked(struct e1000_adapter *adapter)
3586{
3587 might_sleep();
3588 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003589 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003590 e1000e_down(adapter);
3591 e1000e_up(adapter);
3592 clear_bit(__E1000_RESETTING, &adapter->state);
3593}
3594
3595/**
3596 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3597 * @adapter: board private structure to initialize
3598 *
3599 * e1000_sw_init initializes the Adapter private data structure.
3600 * Fields are initialized based on PCI device information and
3601 * OS network device settings (MTU size).
3602 **/
3603static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3604{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003605 struct net_device *netdev = adapter->netdev;
3606
3607 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3608 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003609 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3610 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003611
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003612 spin_lock_init(&adapter->stats64_lock);
3613
Bruce Allan4662e822008-08-26 18:37:06 -07003614 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003615
Bruce Allan4662e822008-08-26 18:37:06 -07003616 if (e1000_alloc_queues(adapter))
3617 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003618
Auke Kokbc7f75f2007-09-17 12:30:59 -07003619 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003620 e1000_irq_disable(adapter);
3621
Auke Kokbc7f75f2007-09-17 12:30:59 -07003622 set_bit(__E1000_DOWN, &adapter->state);
3623 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003624}
3625
3626/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003627 * e1000_intr_msi_test - Interrupt Handler
3628 * @irq: interrupt number
3629 * @data: pointer to a network interface device structure
3630 **/
3631static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3632{
3633 struct net_device *netdev = data;
3634 struct e1000_adapter *adapter = netdev_priv(netdev);
3635 struct e1000_hw *hw = &adapter->hw;
3636 u32 icr = er32(ICR);
3637
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003638 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003639 if (icr & E1000_ICR_RXSEQ) {
3640 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3641 wmb();
3642 }
3643
3644 return IRQ_HANDLED;
3645}
3646
3647/**
3648 * e1000_test_msi_interrupt - Returns 0 for successful test
3649 * @adapter: board private struct
3650 *
3651 * code flow taken from tg3.c
3652 **/
3653static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3654{
3655 struct net_device *netdev = adapter->netdev;
3656 struct e1000_hw *hw = &adapter->hw;
3657 int err;
3658
3659 /* poll_enable hasn't been called yet, so don't need disable */
3660 /* clear any pending events */
3661 er32(ICR);
3662
3663 /* free the real vector and request a test handler */
3664 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003665 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003666
3667 /* Assume that the test fails, if it succeeds then the test
3668 * MSI irq handler will unset this flag */
3669 adapter->flags |= FLAG_MSI_TEST_FAILED;
3670
3671 err = pci_enable_msi(adapter->pdev);
3672 if (err)
3673 goto msi_test_failed;
3674
Joe Perchesa0607fd2009-11-18 23:29:17 -08003675 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003676 netdev->name, netdev);
3677 if (err) {
3678 pci_disable_msi(adapter->pdev);
3679 goto msi_test_failed;
3680 }
3681
3682 wmb();
3683
3684 e1000_irq_enable(adapter);
3685
3686 /* fire an unusual interrupt on the test handler */
3687 ew32(ICS, E1000_ICS_RXSEQ);
3688 e1e_flush();
3689 msleep(50);
3690
3691 e1000_irq_disable(adapter);
3692
3693 rmb();
3694
3695 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003696 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003697 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3698 } else
3699 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003700
3701 free_irq(adapter->pdev->irq, netdev);
3702 pci_disable_msi(adapter->pdev);
3703
Bruce Allanf8d59f72008-08-08 18:36:11 -07003704msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003705 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003706 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003707}
3708
3709/**
3710 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3711 * @adapter: board private struct
3712 *
3713 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3714 **/
3715static int e1000_test_msi(struct e1000_adapter *adapter)
3716{
3717 int err;
3718 u16 pci_cmd;
3719
3720 if (!(adapter->flags & FLAG_MSI_ENABLED))
3721 return 0;
3722
3723 /* disable SERR in case the MSI write causes a master abort */
3724 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003725 if (pci_cmd & PCI_COMMAND_SERR)
3726 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3727 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003728
3729 err = e1000_test_msi_interrupt(adapter);
3730
Dean Nelson36f24072010-06-29 18:12:05 +00003731 /* re-enable SERR */
3732 if (pci_cmd & PCI_COMMAND_SERR) {
3733 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3734 pci_cmd |= PCI_COMMAND_SERR;
3735 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3736 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003737
Bruce Allanf8d59f72008-08-08 18:36:11 -07003738 return err;
3739}
3740
3741/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003742 * e1000_open - Called when a network interface is made active
3743 * @netdev: network interface device structure
3744 *
3745 * Returns 0 on success, negative value on failure
3746 *
3747 * The open entry point is called when a network interface is made
3748 * active by the system (IFF_UP). At this point all resources needed
3749 * for transmit and receive operations are allocated, the interrupt
3750 * handler is registered with the OS, the watchdog timer is started,
3751 * and the stack is notified that the interface is ready.
3752 **/
3753static int e1000_open(struct net_device *netdev)
3754{
3755 struct e1000_adapter *adapter = netdev_priv(netdev);
3756 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003757 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003758 int err;
3759
3760 /* disallow open during test */
3761 if (test_bit(__E1000_TESTING, &adapter->state))
3762 return -EBUSY;
3763
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003764 pm_runtime_get_sync(&pdev->dev);
3765
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003766 netif_carrier_off(netdev);
3767
Auke Kokbc7f75f2007-09-17 12:30:59 -07003768 /* allocate transmit descriptors */
3769 err = e1000e_setup_tx_resources(adapter);
3770 if (err)
3771 goto err_setup_tx;
3772
3773 /* allocate receive descriptors */
3774 err = e1000e_setup_rx_resources(adapter);
3775 if (err)
3776 goto err_setup_rx;
3777
Bruce Allan11b08be2010-05-10 14:59:31 +00003778 /*
3779 * If AMT is enabled, let the firmware know that the network
3780 * interface is now open and reset the part to a known state.
3781 */
3782 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003783 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003784 e1000e_reset(adapter);
3785 }
3786
Auke Kokbc7f75f2007-09-17 12:30:59 -07003787 e1000e_power_up_phy(adapter);
3788
3789 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3790 if ((adapter->hw.mng_cookie.status &
3791 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3792 e1000_update_mng_vlan(adapter);
3793
Florian Micklerc128ec22010-08-02 14:27:00 +00003794 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003795 if ((adapter->flags & FLAG_HAS_ERT) ||
3796 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003797 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3798 PM_QOS_CPU_DMA_LATENCY,
3799 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003800
Bruce Allanad680762008-03-28 09:15:03 -07003801 /*
Bruce Allanad680762008-03-28 09:15:03 -07003802 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003803 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3804 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003805 * clean_rx handler before we do so.
3806 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003807 e1000_configure(adapter);
3808
3809 err = e1000_request_irq(adapter);
3810 if (err)
3811 goto err_req_irq;
3812
Bruce Allanf8d59f72008-08-08 18:36:11 -07003813 /*
3814 * Work around PCIe errata with MSI interrupts causing some chipsets to
3815 * ignore e1000e MSI messages, which means we need to test our MSI
3816 * interrupt now
3817 */
Bruce Allan4662e822008-08-26 18:37:06 -07003818 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003819 err = e1000_test_msi(adapter);
3820 if (err) {
3821 e_err("Interrupt allocation failed\n");
3822 goto err_req_irq;
3823 }
3824 }
3825
Auke Kokbc7f75f2007-09-17 12:30:59 -07003826 /* From here on the code is the same as e1000e_up() */
3827 clear_bit(__E1000_DOWN, &adapter->state);
3828
3829 napi_enable(&adapter->napi);
3830
3831 e1000_irq_enable(adapter);
3832
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003833 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003834
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003835 adapter->idle_check = true;
3836 pm_runtime_put(&pdev->dev);
3837
Auke Kokbc7f75f2007-09-17 12:30:59 -07003838 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003839 if (adapter->msix_entries)
3840 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3841 else
3842 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003843
3844 return 0;
3845
3846err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003847 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003848 e1000_power_down_phy(adapter);
3849 e1000e_free_rx_resources(adapter);
3850err_setup_rx:
3851 e1000e_free_tx_resources(adapter);
3852err_setup_tx:
3853 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003854 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003855
3856 return err;
3857}
3858
3859/**
3860 * e1000_close - Disables a network interface
3861 * @netdev: network interface device structure
3862 *
3863 * Returns 0, this is not allowed to fail
3864 *
3865 * The close entry point is called when an interface is de-activated
3866 * by the OS. The hardware is still under the drivers control, but
3867 * needs to be disabled. A global MAC reset is issued to stop the
3868 * hardware, and all transmit and receive resources are freed.
3869 **/
3870static int e1000_close(struct net_device *netdev)
3871{
3872 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003873 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003874
3875 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003876
3877 pm_runtime_get_sync(&pdev->dev);
3878
3879 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3880 e1000e_down(adapter);
3881 e1000_free_irq(adapter);
3882 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003883 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003884
3885 e1000e_free_tx_resources(adapter);
3886 e1000e_free_rx_resources(adapter);
3887
Bruce Allanad680762008-03-28 09:15:03 -07003888 /*
3889 * kill manageability vlan ID if supported, but not if a vlan with
3890 * the same ID is registered on the host OS (let 8021q kill it)
3891 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003892 if (adapter->hw.mng_cookie.status &
3893 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003894 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3895
Bruce Allanad680762008-03-28 09:15:03 -07003896 /*
3897 * If AMT is enabled, let the firmware know that the network
3898 * interface is now closed
3899 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003900 if ((adapter->flags & FLAG_HAS_AMT) &&
3901 !test_bit(__E1000_TESTING, &adapter->state))
3902 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003903
Bruce Allan828bac82010-09-29 21:39:37 +00003904 if ((adapter->flags & FLAG_HAS_ERT) ||
3905 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003906 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003907
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003908 pm_runtime_put_sync(&pdev->dev);
3909
Auke Kokbc7f75f2007-09-17 12:30:59 -07003910 return 0;
3911}
3912/**
3913 * e1000_set_mac - Change the Ethernet Address of the NIC
3914 * @netdev: network interface device structure
3915 * @p: pointer to an address structure
3916 *
3917 * Returns 0 on success, negative on failure
3918 **/
3919static int e1000_set_mac(struct net_device *netdev, void *p)
3920{
3921 struct e1000_adapter *adapter = netdev_priv(netdev);
3922 struct sockaddr *addr = p;
3923
3924 if (!is_valid_ether_addr(addr->sa_data))
3925 return -EADDRNOTAVAIL;
3926
3927 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3928 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3929
3930 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3931
3932 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3933 /* activate the work around */
3934 e1000e_set_laa_state_82571(&adapter->hw, 1);
3935
Bruce Allanad680762008-03-28 09:15:03 -07003936 /*
3937 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003938 * between the time RAR[0] gets clobbered and the time it
3939 * gets fixed (in e1000_watchdog), the actual LAA is in one
3940 * of the RARs and no incoming packets directed to this port
3941 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003942 * RAR[14]
3943 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003944 e1000e_rar_set(&adapter->hw,
3945 adapter->hw.mac.addr,
3946 adapter->hw.mac.rar_entry_count - 1);
3947 }
3948
3949 return 0;
3950}
3951
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003952/**
3953 * e1000e_update_phy_task - work thread to update phy
3954 * @work: pointer to our work struct
3955 *
3956 * this worker thread exists because we must acquire a
3957 * semaphore to read the phy, which we could msleep while
3958 * waiting for it, and we can't msleep in a timer.
3959 **/
3960static void e1000e_update_phy_task(struct work_struct *work)
3961{
3962 struct e1000_adapter *adapter = container_of(work,
3963 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003964
3965 if (test_bit(__E1000_DOWN, &adapter->state))
3966 return;
3967
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003968 e1000_get_phy_info(&adapter->hw);
3969}
3970
Bruce Allanad680762008-03-28 09:15:03 -07003971/*
3972 * Need to wait a few seconds after link up to get diagnostic information from
3973 * the phy
3974 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003975static void e1000_update_phy_info(unsigned long data)
3976{
3977 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003978
3979 if (test_bit(__E1000_DOWN, &adapter->state))
3980 return;
3981
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003982 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983}
3984
3985/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003986 * e1000e_update_phy_stats - Update the PHY statistics counters
3987 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00003988 *
3989 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003990 **/
3991static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3992{
3993 struct e1000_hw *hw = &adapter->hw;
3994 s32 ret_val;
3995 u16 phy_data;
3996
3997 ret_val = hw->phy.ops.acquire(hw);
3998 if (ret_val)
3999 return;
4000
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004001 /*
4002 * A page set is expensive so check if already on desired page.
4003 * If not, set to the page with the PHY status registers.
4004 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004005 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004006 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4007 &phy_data);
4008 if (ret_val)
4009 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004010 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4011 ret_val = hw->phy.ops.set_page(hw,
4012 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004013 if (ret_val)
4014 goto release;
4015 }
4016
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004017 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004018 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4019 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004020 if (!ret_val)
4021 adapter->stats.scc += phy_data;
4022
4023 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004024 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4025 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004026 if (!ret_val)
4027 adapter->stats.ecol += phy_data;
4028
4029 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004030 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4031 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004032 if (!ret_val)
4033 adapter->stats.mcc += phy_data;
4034
4035 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004036 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4037 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004038 if (!ret_val)
4039 adapter->stats.latecol += phy_data;
4040
4041 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004042 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4043 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004044 if (!ret_val)
4045 hw->mac.collision_delta = phy_data;
4046
4047 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004048 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4049 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004050 if (!ret_val)
4051 adapter->stats.dc += phy_data;
4052
4053 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004054 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4055 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004056 if (!ret_val)
4057 adapter->stats.tncrs += phy_data;
4058
4059release:
4060 hw->phy.ops.release(hw);
4061}
4062
4063/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004064 * e1000e_update_stats - Update the board statistics counters
4065 * @adapter: board private structure
4066 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004067static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004068{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004069 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004070 struct e1000_hw *hw = &adapter->hw;
4071 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004072
4073 /*
4074 * Prevent stats update while adapter is being reset, or if the pci
4075 * connection is down.
4076 */
4077 if (adapter->link_speed == 0)
4078 return;
4079 if (pci_channel_offline(pdev))
4080 return;
4081
Auke Kokbc7f75f2007-09-17 12:30:59 -07004082 adapter->stats.crcerrs += er32(CRCERRS);
4083 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004084 adapter->stats.gorc += er32(GORCL);
4085 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004086 adapter->stats.bprc += er32(BPRC);
4087 adapter->stats.mprc += er32(MPRC);
4088 adapter->stats.roc += er32(ROC);
4089
Auke Kokbc7f75f2007-09-17 12:30:59 -07004090 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004091
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004092 /* Half-duplex statistics */
4093 if (adapter->link_duplex == HALF_DUPLEX) {
4094 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4095 e1000e_update_phy_stats(adapter);
4096 } else {
4097 adapter->stats.scc += er32(SCC);
4098 adapter->stats.ecol += er32(ECOL);
4099 adapter->stats.mcc += er32(MCC);
4100 adapter->stats.latecol += er32(LATECOL);
4101 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004102
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004103 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004104
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004105 if ((hw->mac.type != e1000_82574) &&
4106 (hw->mac.type != e1000_82583))
4107 adapter->stats.tncrs += er32(TNCRS);
4108 }
4109 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004110 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004111
Auke Kokbc7f75f2007-09-17 12:30:59 -07004112 adapter->stats.xonrxc += er32(XONRXC);
4113 adapter->stats.xontxc += er32(XONTXC);
4114 adapter->stats.xoffrxc += er32(XOFFRXC);
4115 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004116 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004117 adapter->stats.gotc += er32(GOTCL);
4118 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004119 adapter->stats.rnbc += er32(RNBC);
4120 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004121
4122 adapter->stats.mptc += er32(MPTC);
4123 adapter->stats.bptc += er32(BPTC);
4124
4125 /* used for adaptive IFS */
4126
4127 hw->mac.tx_packet_delta = er32(TPT);
4128 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004129
4130 adapter->stats.algnerrc += er32(ALGNERRC);
4131 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004132 adapter->stats.cexterr += er32(CEXTERR);
4133 adapter->stats.tsctc += er32(TSCTC);
4134 adapter->stats.tsctfc += er32(TSCTFC);
4135
Auke Kokbc7f75f2007-09-17 12:30:59 -07004136 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004137 netdev->stats.multicast = adapter->stats.mprc;
4138 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004139
4140 /* Rx Errors */
4141
Bruce Allanad680762008-03-28 09:15:03 -07004142 /*
4143 * RLEC on some newer hardware can be incorrect so build
4144 * our own version based on RUC and ROC
4145 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004146 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004147 adapter->stats.crcerrs + adapter->stats.algnerrc +
4148 adapter->stats.ruc + adapter->stats.roc +
4149 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004150 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004151 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004152 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4153 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4154 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004155
4156 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004157 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004158 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004159 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4160 netdev->stats.tx_window_errors = adapter->stats.latecol;
4161 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004162
4163 /* Tx Dropped needs to be maintained elsewhere */
4164
Auke Kokbc7f75f2007-09-17 12:30:59 -07004165 /* Management Stats */
4166 adapter->stats.mgptc += er32(MGTPTC);
4167 adapter->stats.mgprc += er32(MGTPRC);
4168 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004169}
4170
Bruce Allan7c257692008-04-23 11:09:00 -07004171/**
4172 * e1000_phy_read_status - Update the PHY register status snapshot
4173 * @adapter: board private structure
4174 **/
4175static void e1000_phy_read_status(struct e1000_adapter *adapter)
4176{
4177 struct e1000_hw *hw = &adapter->hw;
4178 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004179
4180 if ((er32(STATUS) & E1000_STATUS_LU) &&
4181 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004182 int ret_val;
4183
Bruce Allan7c257692008-04-23 11:09:00 -07004184 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4185 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4186 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4187 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4188 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4189 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4190 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4191 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4192 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004193 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004194 } else {
4195 /*
4196 * Do not read PHY registers if link is not up
4197 * Set values to typical power-on defaults
4198 */
4199 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4200 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4201 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4202 BMSR_ERCAP);
4203 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4204 ADVERTISE_ALL | ADVERTISE_CSMA);
4205 phy->lpa = 0;
4206 phy->expansion = EXPANSION_ENABLENPAGE;
4207 phy->ctrl1000 = ADVERTISE_1000FULL;
4208 phy->stat1000 = 0;
4209 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4210 }
Bruce Allan7c257692008-04-23 11:09:00 -07004211}
4212
Auke Kokbc7f75f2007-09-17 12:30:59 -07004213static void e1000_print_link_info(struct e1000_adapter *adapter)
4214{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004215 struct e1000_hw *hw = &adapter->hw;
4216 u32 ctrl = er32(CTRL);
4217
Bruce Allan8f12fe82008-11-21 16:54:43 -08004218 /* Link status message must follow this format for user tools */
Jeff Kirsheref456f82011-11-03 11:40:28 +00004219 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4220 adapter->netdev->name,
4221 adapter->link_speed,
4222 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4223 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4224 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4225 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004226}
4227
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004228static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004229{
4230 struct e1000_hw *hw = &adapter->hw;
4231 bool link_active = 0;
4232 s32 ret_val = 0;
4233
4234 /*
4235 * get_link_status is set on LSC (link status) interrupt or
4236 * Rx sequence error interrupt. get_link_status will stay
4237 * false until the check_for_link establishes link
4238 * for copper adapters ONLY
4239 */
4240 switch (hw->phy.media_type) {
4241 case e1000_media_type_copper:
4242 if (hw->mac.get_link_status) {
4243 ret_val = hw->mac.ops.check_for_link(hw);
4244 link_active = !hw->mac.get_link_status;
4245 } else {
4246 link_active = 1;
4247 }
4248 break;
4249 case e1000_media_type_fiber:
4250 ret_val = hw->mac.ops.check_for_link(hw);
4251 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4252 break;
4253 case e1000_media_type_internal_serdes:
4254 ret_val = hw->mac.ops.check_for_link(hw);
4255 link_active = adapter->hw.mac.serdes_has_link;
4256 break;
4257 default:
4258 case e1000_media_type_unknown:
4259 break;
4260 }
4261
4262 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4263 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4264 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004265 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004266 }
4267
4268 return link_active;
4269}
4270
4271static void e1000e_enable_receives(struct e1000_adapter *adapter)
4272{
4273 /* make sure the receive unit is started */
4274 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4275 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4276 struct e1000_hw *hw = &adapter->hw;
4277 u32 rctl = er32(RCTL);
4278 ew32(RCTL, rctl | E1000_RCTL_EN);
4279 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4280 }
4281}
4282
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004283static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4284{
4285 struct e1000_hw *hw = &adapter->hw;
4286
4287 /*
4288 * With 82574 controllers, PHY needs to be checked periodically
4289 * for hung state and reset, if two calls return true
4290 */
4291 if (e1000_check_phy_82574(hw))
4292 adapter->phy_hang_count++;
4293 else
4294 adapter->phy_hang_count = 0;
4295
4296 if (adapter->phy_hang_count > 1) {
4297 adapter->phy_hang_count = 0;
4298 schedule_work(&adapter->reset_task);
4299 }
4300}
4301
Auke Kokbc7f75f2007-09-17 12:30:59 -07004302/**
4303 * e1000_watchdog - Timer Call-back
4304 * @data: pointer to adapter cast into an unsigned long
4305 **/
4306static void e1000_watchdog(unsigned long data)
4307{
4308 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4309
4310 /* Do the rest outside of interrupt context */
4311 schedule_work(&adapter->watchdog_task);
4312
4313 /* TODO: make this use queue_delayed_work() */
4314}
4315
4316static void e1000_watchdog_task(struct work_struct *work)
4317{
4318 struct e1000_adapter *adapter = container_of(work,
4319 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004320 struct net_device *netdev = adapter->netdev;
4321 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004322 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004323 struct e1000_ring *tx_ring = adapter->tx_ring;
4324 struct e1000_hw *hw = &adapter->hw;
4325 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004326
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004327 if (test_bit(__E1000_DOWN, &adapter->state))
4328 return;
4329
David S. Millerb405e8d2010-02-04 22:31:41 -08004330 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004331 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004332 /* Cancel scheduled suspend requests. */
4333 pm_runtime_resume(netdev->dev.parent);
4334
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004335 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004336 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004337 }
4338
4339 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4340 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4341 e1000_update_mng_vlan(adapter);
4342
Auke Kokbc7f75f2007-09-17 12:30:59 -07004343 if (link) {
4344 if (!netif_carrier_ok(netdev)) {
4345 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004346
4347 /* Cancel scheduled suspend requests. */
4348 pm_runtime_resume(netdev->dev.parent);
4349
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004350 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004351 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004352 mac->ops.get_link_up_info(&adapter->hw,
4353 &adapter->link_speed,
4354 &adapter->link_duplex);
4355 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004356 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004357 * On supported PHYs, check for duplex mismatch only
4358 * if link has autonegotiated at 10/100 half
4359 */
4360 if ((hw->phy.type == e1000_phy_igp_3 ||
4361 hw->phy.type == e1000_phy_bm) &&
4362 (hw->mac.autoneg == true) &&
4363 (adapter->link_speed == SPEED_10 ||
4364 adapter->link_speed == SPEED_100) &&
4365 (adapter->link_duplex == HALF_DUPLEX)) {
4366 u16 autoneg_exp;
4367
4368 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4369
4370 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004371 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 -07004372 }
4373
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004374 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004375 adapter->tx_timeout_factor = 1;
4376 switch (adapter->link_speed) {
4377 case SPEED_10:
4378 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004379 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004380 break;
4381 case SPEED_100:
4382 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004383 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004384 break;
4385 }
4386
Bruce Allanad680762008-03-28 09:15:03 -07004387 /*
4388 * workaround: re-program speed mode bit after
4389 * link-up event
4390 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004391 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4392 !txb2b) {
4393 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004394 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004395 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004396 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004397 }
4398
Bruce Allanad680762008-03-28 09:15:03 -07004399 /*
4400 * disable TSO for pcie and 10/100 speeds, to avoid
4401 * some hardware issues
4402 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004403 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4404 switch (adapter->link_speed) {
4405 case SPEED_10:
4406 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004407 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004408 netdev->features &= ~NETIF_F_TSO;
4409 netdev->features &= ~NETIF_F_TSO6;
4410 break;
4411 case SPEED_1000:
4412 netdev->features |= NETIF_F_TSO;
4413 netdev->features |= NETIF_F_TSO6;
4414 break;
4415 default:
4416 /* oops */
4417 break;
4418 }
4419 }
4420
Bruce Allanad680762008-03-28 09:15:03 -07004421 /*
4422 * enable transmits in the hardware, need to do this
4423 * after setting TARC(0)
4424 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004425 tctl = er32(TCTL);
4426 tctl |= E1000_TCTL_EN;
4427 ew32(TCTL, tctl);
4428
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004429 /*
4430 * Perform any post-link-up configuration before
4431 * reporting link up.
4432 */
4433 if (phy->ops.cfg_on_link_up)
4434 phy->ops.cfg_on_link_up(hw);
4435
Auke Kokbc7f75f2007-09-17 12:30:59 -07004436 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004437
4438 if (!test_bit(__E1000_DOWN, &adapter->state))
4439 mod_timer(&adapter->phy_info_timer,
4440 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004441 }
4442 } else {
4443 if (netif_carrier_ok(netdev)) {
4444 adapter->link_speed = 0;
4445 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004446 /* Link status message must follow this format */
4447 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4448 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004449 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004450 if (!test_bit(__E1000_DOWN, &adapter->state))
4451 mod_timer(&adapter->phy_info_timer,
4452 round_jiffies(jiffies + 2 * HZ));
4453
4454 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4455 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004456 else
4457 pm_schedule_suspend(netdev->dev.parent,
4458 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004459 }
4460 }
4461
4462link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004463 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004464 e1000e_update_stats(adapter);
4465
4466 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4467 adapter->tpt_old = adapter->stats.tpt;
4468 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4469 adapter->colc_old = adapter->stats.colc;
4470
Bruce Allan7c257692008-04-23 11:09:00 -07004471 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4472 adapter->gorc_old = adapter->stats.gorc;
4473 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4474 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004475 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004476
4477 e1000e_update_adaptive(&adapter->hw);
4478
Bruce Allan90da0662011-01-06 07:02:53 +00004479 if (!netif_carrier_ok(netdev) &&
4480 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4481 /*
4482 * We've lost link, so the controller stops DMA,
4483 * but we've got queued Tx work that's never going
4484 * to get done, so reset controller to flush Tx.
4485 * (Do the reset outside of interrupt context).
4486 */
Bruce Allan90da0662011-01-06 07:02:53 +00004487 schedule_work(&adapter->reset_task);
4488 /* return immediately since reset is imminent */
4489 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004490 }
4491
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004492 /* Simple mode for Interrupt Throttle Rate (ITR) */
4493 if (adapter->itr_setting == 4) {
4494 /*
4495 * Symmetric Tx/Rx gets a reduced ITR=2000;
4496 * Total asymmetrical Tx or Rx gets ITR=8000;
4497 * everyone else is between 2000-8000.
4498 */
4499 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4500 u32 dif = (adapter->gotc > adapter->gorc ?
4501 adapter->gotc - adapter->gorc :
4502 adapter->gorc - adapter->gotc) / 10000;
4503 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4504
4505 ew32(ITR, 1000000000 / (itr * 256));
4506 }
4507
Bruce Allanad680762008-03-28 09:15:03 -07004508 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004509 if (adapter->msix_entries)
4510 ew32(ICS, adapter->rx_ring->ims_val);
4511 else
4512 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004513
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004514 /* flush pending descriptors to memory before detecting Tx hang */
4515 e1000e_flush_descriptors(adapter);
4516
Auke Kokbc7f75f2007-09-17 12:30:59 -07004517 /* Force detection of hung controller every watchdog period */
4518 adapter->detect_tx_hung = 1;
4519
Bruce Allanad680762008-03-28 09:15:03 -07004520 /*
4521 * With 82571 controllers, LAA may be overwritten due to controller
4522 * reset from the other port. Set the appropriate LAA in RAR[0]
4523 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004524 if (e1000e_get_laa_state_82571(hw))
4525 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4526
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004527 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4528 e1000e_check_82574_phy_workaround(adapter);
4529
Auke Kokbc7f75f2007-09-17 12:30:59 -07004530 /* Reset the timer */
4531 if (!test_bit(__E1000_DOWN, &adapter->state))
4532 mod_timer(&adapter->watchdog_timer,
4533 round_jiffies(jiffies + 2 * HZ));
4534}
4535
4536#define E1000_TX_FLAGS_CSUM 0x00000001
4537#define E1000_TX_FLAGS_VLAN 0x00000002
4538#define E1000_TX_FLAGS_TSO 0x00000004
4539#define E1000_TX_FLAGS_IPV4 0x00000008
4540#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4541#define E1000_TX_FLAGS_VLAN_SHIFT 16
4542
4543static int e1000_tso(struct e1000_adapter *adapter,
4544 struct sk_buff *skb)
4545{
4546 struct e1000_ring *tx_ring = adapter->tx_ring;
4547 struct e1000_context_desc *context_desc;
4548 struct e1000_buffer *buffer_info;
4549 unsigned int i;
4550 u32 cmd_length = 0;
4551 u16 ipcse = 0, tucse, mss;
4552 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004553
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004554 if (!skb_is_gso(skb))
4555 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004556
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004557 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004558 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4559
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004560 if (err)
4561 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004562 }
4563
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004564 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4565 mss = skb_shinfo(skb)->gso_size;
4566 if (skb->protocol == htons(ETH_P_IP)) {
4567 struct iphdr *iph = ip_hdr(skb);
4568 iph->tot_len = 0;
4569 iph->check = 0;
4570 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4571 0, IPPROTO_TCP, 0);
4572 cmd_length = E1000_TXD_CMD_IP;
4573 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004574 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004575 ipv6_hdr(skb)->payload_len = 0;
4576 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4577 &ipv6_hdr(skb)->daddr,
4578 0, IPPROTO_TCP, 0);
4579 ipcse = 0;
4580 }
4581 ipcss = skb_network_offset(skb);
4582 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4583 tucss = skb_transport_offset(skb);
4584 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4585 tucse = 0;
4586
4587 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4588 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4589
4590 i = tx_ring->next_to_use;
4591 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4592 buffer_info = &tx_ring->buffer_info[i];
4593
4594 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4595 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4596 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4597 context_desc->upper_setup.tcp_fields.tucss = tucss;
4598 context_desc->upper_setup.tcp_fields.tucso = tucso;
4599 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4600 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4601 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4602 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4603
4604 buffer_info->time_stamp = jiffies;
4605 buffer_info->next_to_watch = i;
4606
4607 i++;
4608 if (i == tx_ring->count)
4609 i = 0;
4610 tx_ring->next_to_use = i;
4611
4612 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004613}
4614
4615static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4616{
4617 struct e1000_ring *tx_ring = adapter->tx_ring;
4618 struct e1000_context_desc *context_desc;
4619 struct e1000_buffer *buffer_info;
4620 unsigned int i;
4621 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004622 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004623 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004624
Dave Grahamaf807c82008-10-09 14:28:58 -07004625 if (skb->ip_summed != CHECKSUM_PARTIAL)
4626 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004627
Arthur Jones5f66f202009-03-19 01:13:08 +00004628 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4629 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4630 else
4631 protocol = skb->protocol;
4632
Arthur Jones3f518392009-03-20 15:56:35 -07004633 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004634 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004635 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4636 cmd_len |= E1000_TXD_CMD_TCP;
4637 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004638 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004639 /* XXX not handling all IPV6 headers */
4640 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4641 cmd_len |= E1000_TXD_CMD_TCP;
4642 break;
4643 default:
4644 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004645 e_warn("checksum_partial proto=%x!\n",
4646 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004647 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004648 }
4649
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004650 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004651
4652 i = tx_ring->next_to_use;
4653 buffer_info = &tx_ring->buffer_info[i];
4654 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4655
4656 context_desc->lower_setup.ip_config = 0;
4657 context_desc->upper_setup.tcp_fields.tucss = css;
4658 context_desc->upper_setup.tcp_fields.tucso =
4659 css + skb->csum_offset;
4660 context_desc->upper_setup.tcp_fields.tucse = 0;
4661 context_desc->tcp_seg_setup.data = 0;
4662 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4663
4664 buffer_info->time_stamp = jiffies;
4665 buffer_info->next_to_watch = i;
4666
4667 i++;
4668 if (i == tx_ring->count)
4669 i = 0;
4670 tx_ring->next_to_use = i;
4671
4672 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004673}
4674
4675#define E1000_MAX_PER_TXD 8192
4676#define E1000_MAX_TXD_PWR 12
4677
4678static int e1000_tx_map(struct e1000_adapter *adapter,
4679 struct sk_buff *skb, unsigned int first,
4680 unsigned int max_per_txd, unsigned int nr_frags,
4681 unsigned int mss)
4682{
4683 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004684 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004685 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004686 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004687 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004688 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004689
4690 i = tx_ring->next_to_use;
4691
4692 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004693 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004694 size = min(len, max_per_txd);
4695
Auke Kokbc7f75f2007-09-17 12:30:59 -07004696 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004697 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004698 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004699 buffer_info->dma = dma_map_single(&pdev->dev,
4700 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004701 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004702 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004703 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004704 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004705
4706 len -= size;
4707 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004708 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004709
4710 if (len) {
4711 i++;
4712 if (i == tx_ring->count)
4713 i = 0;
4714 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004715 }
4716
4717 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004718 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004719
4720 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004721 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004722 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004723
4724 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004725 i++;
4726 if (i == tx_ring->count)
4727 i = 0;
4728
Auke Kokbc7f75f2007-09-17 12:30:59 -07004729 buffer_info = &tx_ring->buffer_info[i];
4730 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004731
4732 buffer_info->length = size;
4733 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004734 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004735 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4736 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004737 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004738 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004739 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004740
4741 len -= size;
4742 offset += size;
4743 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004744 }
4745 }
4746
Bruce Allanaf667a22010-12-31 06:10:01 +00004747 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004748 /* multiply data chunks by size of headers */
4749 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4750
Auke Kokbc7f75f2007-09-17 12:30:59 -07004751 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004752 tx_ring->buffer_info[i].segs = segs;
4753 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004754 tx_ring->buffer_info[first].next_to_watch = i;
4755
4756 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004757
4758dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004759 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004760 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004761 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004762 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004763
4764 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004765 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004766 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004767 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004768 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004769 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004770 }
4771
4772 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004773}
4774
4775static void e1000_tx_queue(struct e1000_adapter *adapter,
4776 int tx_flags, int count)
4777{
4778 struct e1000_ring *tx_ring = adapter->tx_ring;
4779 struct e1000_tx_desc *tx_desc = NULL;
4780 struct e1000_buffer *buffer_info;
4781 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4782 unsigned int i;
4783
4784 if (tx_flags & E1000_TX_FLAGS_TSO) {
4785 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4786 E1000_TXD_CMD_TSE;
4787 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4788
4789 if (tx_flags & E1000_TX_FLAGS_IPV4)
4790 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4791 }
4792
4793 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4794 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4795 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4796 }
4797
4798 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4799 txd_lower |= E1000_TXD_CMD_VLE;
4800 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4801 }
4802
4803 i = tx_ring->next_to_use;
4804
Bruce Allan36b973d2010-11-24 07:42:43 +00004805 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004806 buffer_info = &tx_ring->buffer_info[i];
4807 tx_desc = E1000_TX_DESC(*tx_ring, i);
4808 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4809 tx_desc->lower.data =
4810 cpu_to_le32(txd_lower | buffer_info->length);
4811 tx_desc->upper.data = cpu_to_le32(txd_upper);
4812
4813 i++;
4814 if (i == tx_ring->count)
4815 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004816 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004817
4818 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4819
Bruce Allanad680762008-03-28 09:15:03 -07004820 /*
4821 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004822 * know there are new descriptors to fetch. (Only
4823 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004824 * such as IA-64).
4825 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004826 wmb();
4827
4828 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004829
4830 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4831 e1000e_update_tdt_wa(adapter, i);
4832 else
4833 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4834
Bruce Allanad680762008-03-28 09:15:03 -07004835 /*
4836 * we need this if more than one processor can write to our tail
4837 * at a time, it synchronizes IO on IA64/Altix systems
4838 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004839 mmiowb();
4840}
4841
4842#define MINIMUM_DHCP_PACKET_SIZE 282
4843static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4844 struct sk_buff *skb)
4845{
4846 struct e1000_hw *hw = &adapter->hw;
4847 u16 length, offset;
4848
4849 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004850 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4851 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004852 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4853 return 0;
4854 }
4855
4856 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4857 return 0;
4858
4859 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4860 return 0;
4861
4862 {
4863 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4864 struct udphdr *udp;
4865
4866 if (ip->protocol != IPPROTO_UDP)
4867 return 0;
4868
4869 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4870 if (ntohs(udp->dest) != 67)
4871 return 0;
4872
4873 offset = (u8 *)udp + 8 - skb->data;
4874 length = skb->len - offset;
4875 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4876 }
4877
4878 return 0;
4879}
4880
4881static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4882{
4883 struct e1000_adapter *adapter = netdev_priv(netdev);
4884
4885 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004886 /*
4887 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004888 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004889 * but since that doesn't exist yet, just open code it.
4890 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004891 smp_mb();
4892
Bruce Allanad680762008-03-28 09:15:03 -07004893 /*
4894 * We need to check again in a case another CPU has just
4895 * made room available.
4896 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004897 if (e1000_desc_unused(adapter->tx_ring) < size)
4898 return -EBUSY;
4899
4900 /* A reprieve! */
4901 netif_start_queue(netdev);
4902 ++adapter->restart_queue;
4903 return 0;
4904}
4905
4906static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4907{
4908 struct e1000_adapter *adapter = netdev_priv(netdev);
4909
4910 if (e1000_desc_unused(adapter->tx_ring) >= size)
4911 return 0;
4912 return __e1000_maybe_stop_tx(netdev, size);
4913}
4914
4915#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004916static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4917 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004918{
4919 struct e1000_adapter *adapter = netdev_priv(netdev);
4920 struct e1000_ring *tx_ring = adapter->tx_ring;
4921 unsigned int first;
4922 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4923 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4924 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004925 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004926 unsigned int nr_frags;
4927 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004928 int count = 0;
4929 int tso;
4930 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004931
4932 if (test_bit(__E1000_DOWN, &adapter->state)) {
4933 dev_kfree_skb_any(skb);
4934 return NETDEV_TX_OK;
4935 }
4936
4937 if (skb->len <= 0) {
4938 dev_kfree_skb_any(skb);
4939 return NETDEV_TX_OK;
4940 }
4941
4942 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004943 /*
4944 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004945 * make sure there is enough room in the FIFO before
4946 * initiating the DMA for each buffer. The calc is:
4947 * 4 = ceil(buffer len/mss). To make sure we don't
4948 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004949 * drops.
4950 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004951 if (mss) {
4952 u8 hdr_len;
4953 max_per_txd = min(mss << 2, max_per_txd);
4954 max_txd_pwr = fls(max_per_txd) - 1;
4955
Bruce Allanad680762008-03-28 09:15:03 -07004956 /*
4957 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4958 * points to just header, pull a few bytes of payload from
4959 * frags into skb->data
4960 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004961 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004962 /*
4963 * we do this workaround for ES2LAN, but it is un-necessary,
4964 * avoiding it could save a lot of cycles
4965 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004966 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004967 unsigned int pull_size;
4968
4969 pull_size = min((unsigned int)4, skb->data_len);
4970 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004971 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004972 dev_kfree_skb_any(skb);
4973 return NETDEV_TX_OK;
4974 }
Eric Dumazete743d312010-04-14 15:59:40 -07004975 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004976 }
4977 }
4978
4979 /* reserve a descriptor for the offload context */
4980 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4981 count++;
4982 count++;
4983
4984 count += TXD_USE_COUNT(len, max_txd_pwr);
4985
4986 nr_frags = skb_shinfo(skb)->nr_frags;
4987 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00004988 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07004989 max_txd_pwr);
4990
4991 if (adapter->hw.mac.tx_pkt_filtering)
4992 e1000_transfer_dhcp_info(adapter, skb);
4993
Bruce Allanad680762008-03-28 09:15:03 -07004994 /*
4995 * need: count + 2 desc gap to keep tail from touching
4996 * head, otherwise try next time
4997 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004998 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004999 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005000
Jesse Grosseab6d182010-10-20 13:56:03 +00005001 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005002 tx_flags |= E1000_TX_FLAGS_VLAN;
5003 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5004 }
5005
5006 first = tx_ring->next_to_use;
5007
5008 tso = e1000_tso(adapter, skb);
5009 if (tso < 0) {
5010 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005011 return NETDEV_TX_OK;
5012 }
5013
5014 if (tso)
5015 tx_flags |= E1000_TX_FLAGS_TSO;
5016 else if (e1000_tx_csum(adapter, skb))
5017 tx_flags |= E1000_TX_FLAGS_CSUM;
5018
Bruce Allanad680762008-03-28 09:15:03 -07005019 /*
5020 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005021 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005022 * no longer assume, we must.
5023 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005024 if (skb->protocol == htons(ETH_P_IP))
5025 tx_flags |= E1000_TX_FLAGS_IPV4;
5026
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005027 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005028 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005029 if (count) {
5030 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005031 /* Make sure there is space in the ring for the next send. */
5032 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
5033
5034 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005035 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005036 tx_ring->buffer_info[first].time_stamp = 0;
5037 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005038 }
5039
Auke Kokbc7f75f2007-09-17 12:30:59 -07005040 return NETDEV_TX_OK;
5041}
5042
5043/**
5044 * e1000_tx_timeout - Respond to a Tx Hang
5045 * @netdev: network interface device structure
5046 **/
5047static void e1000_tx_timeout(struct net_device *netdev)
5048{
5049 struct e1000_adapter *adapter = netdev_priv(netdev);
5050
5051 /* Do the reset outside of interrupt context */
5052 adapter->tx_timeout_count++;
5053 schedule_work(&adapter->reset_task);
5054}
5055
5056static void e1000_reset_task(struct work_struct *work)
5057{
5058 struct e1000_adapter *adapter;
5059 adapter = container_of(work, struct e1000_adapter, reset_task);
5060
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005061 /* don't run the task if already down */
5062 if (test_bit(__E1000_DOWN, &adapter->state))
5063 return;
5064
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005065 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5066 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5067 e1000e_dump(adapter);
5068 e_err("Reset adapter\n");
5069 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005070 e1000e_reinit_locked(adapter);
5071}
5072
5073/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005074 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005075 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005076 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005077 *
5078 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005079 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005080struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5081 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005082{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005083 struct e1000_adapter *adapter = netdev_priv(netdev);
5084
5085 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5086 spin_lock(&adapter->stats64_lock);
5087 e1000e_update_stats(adapter);
5088 /* Fill out the OS statistics structure */
5089 stats->rx_bytes = adapter->stats.gorc;
5090 stats->rx_packets = adapter->stats.gprc;
5091 stats->tx_bytes = adapter->stats.gotc;
5092 stats->tx_packets = adapter->stats.gptc;
5093 stats->multicast = adapter->stats.mprc;
5094 stats->collisions = adapter->stats.colc;
5095
5096 /* Rx Errors */
5097
5098 /*
5099 * RLEC on some newer hardware can be incorrect so build
5100 * our own version based on RUC and ROC
5101 */
5102 stats->rx_errors = adapter->stats.rxerrc +
5103 adapter->stats.crcerrs + adapter->stats.algnerrc +
5104 adapter->stats.ruc + adapter->stats.roc +
5105 adapter->stats.cexterr;
5106 stats->rx_length_errors = adapter->stats.ruc +
5107 adapter->stats.roc;
5108 stats->rx_crc_errors = adapter->stats.crcerrs;
5109 stats->rx_frame_errors = adapter->stats.algnerrc;
5110 stats->rx_missed_errors = adapter->stats.mpc;
5111
5112 /* Tx Errors */
5113 stats->tx_errors = adapter->stats.ecol +
5114 adapter->stats.latecol;
5115 stats->tx_aborted_errors = adapter->stats.ecol;
5116 stats->tx_window_errors = adapter->stats.latecol;
5117 stats->tx_carrier_errors = adapter->stats.tncrs;
5118
5119 /* Tx Dropped needs to be maintained elsewhere */
5120
5121 spin_unlock(&adapter->stats64_lock);
5122 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005123}
5124
5125/**
5126 * e1000_change_mtu - Change the Maximum Transfer Unit
5127 * @netdev: network interface device structure
5128 * @new_mtu: new value for maximum frame size
5129 *
5130 * Returns 0 on success, negative on failure
5131 **/
5132static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5133{
5134 struct e1000_adapter *adapter = netdev_priv(netdev);
5135 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5136
Bruce Allan2adc55c2009-06-02 11:28:58 +00005137 /* Jumbo frame support */
5138 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5139 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5140 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005141 return -EINVAL;
5142 }
5143
Bruce Allan2adc55c2009-06-02 11:28:58 +00005144 /* Supported frame sizes */
5145 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5146 (max_frame > adapter->max_hw_frame_size)) {
5147 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005148 return -EINVAL;
5149 }
5150
Bruce Allana1ce6472010-09-22 17:16:40 +00005151 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5152 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5153 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5154 (new_mtu > ETH_DATA_LEN)) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00005155 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005156 return -EINVAL;
5157 }
5158
Bruce Allan6f461f62010-04-27 03:33:04 +00005159 /* 82573 Errata 17 */
5160 if (((adapter->hw.mac.type == e1000_82573) ||
5161 (adapter->hw.mac.type == e1000_82574)) &&
5162 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5163 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5164 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5165 }
5166
Auke Kokbc7f75f2007-09-17 12:30:59 -07005167 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005168 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005169 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005170 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005171 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5172 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005173 if (netif_running(netdev))
5174 e1000e_down(adapter);
5175
Bruce Allanad680762008-03-28 09:15:03 -07005176 /*
5177 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005178 * means we reserve 2 more, this pushes us to allocate from the next
5179 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005180 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005181 * However with the new *_jumbo_rx* routines, jumbo receives will use
5182 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005183 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005184
Jesse Brandeburg99261462010-01-22 22:56:16 +00005185 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005186 adapter->rx_buffer_len = 2048;
5187 else
5188 adapter->rx_buffer_len = 4096;
5189
5190 /* adjust allocation if LPE protects us, and we aren't using SBP */
5191 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5192 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5193 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005194 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005195
Auke Kokbc7f75f2007-09-17 12:30:59 -07005196 if (netif_running(netdev))
5197 e1000e_up(adapter);
5198 else
5199 e1000e_reset(adapter);
5200
5201 clear_bit(__E1000_RESETTING, &adapter->state);
5202
5203 return 0;
5204}
5205
5206static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5207 int cmd)
5208{
5209 struct e1000_adapter *adapter = netdev_priv(netdev);
5210 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005211
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005212 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213 return -EOPNOTSUPP;
5214
5215 switch (cmd) {
5216 case SIOCGMIIPHY:
5217 data->phy_id = adapter->hw.phy.addr;
5218 break;
5219 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005220 e1000_phy_read_status(adapter);
5221
Bruce Allan7c257692008-04-23 11:09:00 -07005222 switch (data->reg_num & 0x1F) {
5223 case MII_BMCR:
5224 data->val_out = adapter->phy_regs.bmcr;
5225 break;
5226 case MII_BMSR:
5227 data->val_out = adapter->phy_regs.bmsr;
5228 break;
5229 case MII_PHYSID1:
5230 data->val_out = (adapter->hw.phy.id >> 16);
5231 break;
5232 case MII_PHYSID2:
5233 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5234 break;
5235 case MII_ADVERTISE:
5236 data->val_out = adapter->phy_regs.advertise;
5237 break;
5238 case MII_LPA:
5239 data->val_out = adapter->phy_regs.lpa;
5240 break;
5241 case MII_EXPANSION:
5242 data->val_out = adapter->phy_regs.expansion;
5243 break;
5244 case MII_CTRL1000:
5245 data->val_out = adapter->phy_regs.ctrl1000;
5246 break;
5247 case MII_STAT1000:
5248 data->val_out = adapter->phy_regs.stat1000;
5249 break;
5250 case MII_ESTATUS:
5251 data->val_out = adapter->phy_regs.estatus;
5252 break;
5253 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005254 return -EIO;
5255 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005256 break;
5257 case SIOCSMIIREG:
5258 default:
5259 return -EOPNOTSUPP;
5260 }
5261 return 0;
5262}
5263
5264static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5265{
5266 switch (cmd) {
5267 case SIOCGMIIPHY:
5268 case SIOCGMIIREG:
5269 case SIOCSMIIREG:
5270 return e1000_mii_ioctl(netdev, ifr, cmd);
5271 default:
5272 return -EOPNOTSUPP;
5273 }
5274}
5275
Bruce Allana4f58f52009-06-02 11:29:18 +00005276static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5277{
5278 struct e1000_hw *hw = &adapter->hw;
5279 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005280 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005281 int retval = 0;
5282
5283 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005284 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005285
Bruce Allan2b6b1682011-05-13 07:20:09 +00005286 retval = hw->phy.ops.acquire(hw);
5287 if (retval) {
5288 e_err("Could not acquire PHY\n");
5289 return retval;
5290 }
5291
5292 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5293 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5294 if (retval)
5295 goto out;
5296
5297 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005298 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5299 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005300 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5301 (u16)(mac_reg & 0xFFFF));
5302 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5303 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005304 }
5305
5306 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005307 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005308 mac_reg = er32(RCTL);
5309 if (mac_reg & E1000_RCTL_UPE)
5310 phy_reg |= BM_RCTL_UPE;
5311 if (mac_reg & E1000_RCTL_MPE)
5312 phy_reg |= BM_RCTL_MPE;
5313 phy_reg &= ~(BM_RCTL_MO_MASK);
5314 if (mac_reg & E1000_RCTL_MO_3)
5315 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5316 << BM_RCTL_MO_SHIFT);
5317 if (mac_reg & E1000_RCTL_BAM)
5318 phy_reg |= BM_RCTL_BAM;
5319 if (mac_reg & E1000_RCTL_PMCF)
5320 phy_reg |= BM_RCTL_PMCF;
5321 mac_reg = er32(CTRL);
5322 if (mac_reg & E1000_CTRL_RFCE)
5323 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005324 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005325
5326 /* enable PHY wakeup in MAC register */
5327 ew32(WUFC, wufc);
5328 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5329
5330 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005331 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5332 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005333
5334 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005335 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5336 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005337 if (retval)
5338 e_err("Could not set PHY Host Wakeup bit\n");
5339out:
Bruce Allan94d81862009-11-20 23:25:26 +00005340 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005341
5342 return retval;
5343}
5344
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005345static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5346 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005347{
5348 struct net_device *netdev = pci_get_drvdata(pdev);
5349 struct e1000_adapter *adapter = netdev_priv(netdev);
5350 struct e1000_hw *hw = &adapter->hw;
5351 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005352 /* Runtime suspend should only enable wakeup for link changes */
5353 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005354 int retval = 0;
5355
5356 netif_device_detach(netdev);
5357
5358 if (netif_running(netdev)) {
5359 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5360 e1000e_down(adapter);
5361 e1000_free_irq(adapter);
5362 }
Bruce Allan4662e822008-08-26 18:37:06 -07005363 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005364
5365 retval = pci_save_state(pdev);
5366 if (retval)
5367 return retval;
5368
5369 status = er32(STATUS);
5370 if (status & E1000_STATUS_LU)
5371 wufc &= ~E1000_WUFC_LNKC;
5372
5373 if (wufc) {
5374 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005375 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005376
5377 /* turn on all-multi mode if wake on multicast is enabled */
5378 if (wufc & E1000_WUFC_MC) {
5379 rctl = er32(RCTL);
5380 rctl |= E1000_RCTL_MPE;
5381 ew32(RCTL, rctl);
5382 }
5383
5384 ctrl = er32(CTRL);
5385 /* advertise wake from D3Cold */
5386 #define E1000_CTRL_ADVD3WUC 0x00100000
5387 /* phy power management enable */
5388 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005389 ctrl |= E1000_CTRL_ADVD3WUC;
5390 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5391 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005392 ew32(CTRL, ctrl);
5393
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005394 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5395 adapter->hw.phy.media_type ==
5396 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005397 /* keep the laser running in D3 */
5398 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005399 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005400 ew32(CTRL_EXT, ctrl_ext);
5401 }
5402
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005403 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005404 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005405
Auke Kokbc7f75f2007-09-17 12:30:59 -07005406 /* Allow time for pending master requests to run */
5407 e1000e_disable_pcie_master(&adapter->hw);
5408
Bruce Allan82776a42009-08-14 14:35:33 +00005409 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005410 /* enable wakeup by the PHY */
5411 retval = e1000_init_phy_wakeup(adapter, wufc);
5412 if (retval)
5413 return retval;
5414 } else {
5415 /* enable wakeup by the MAC */
5416 ew32(WUFC, wufc);
5417 ew32(WUC, E1000_WUC_PME_EN);
5418 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005419 } else {
5420 ew32(WUC, 0);
5421 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005422 }
5423
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005424 *enable_wake = !!wufc;
5425
Auke Kokbc7f75f2007-09-17 12:30:59 -07005426 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005427 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5428 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005429 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005430
5431 if (adapter->hw.phy.type == e1000_phy_igp_3)
5432 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5433
Bruce Allanad680762008-03-28 09:15:03 -07005434 /*
5435 * Release control of h/w to f/w. If f/w is AMT enabled, this
5436 * would have already happened in close and is redundant.
5437 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005438 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005439
5440 pci_disable_device(pdev);
5441
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005442 return 0;
5443}
5444
5445static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5446{
5447 if (sleep && wake) {
5448 pci_prepare_to_sleep(pdev);
5449 return;
5450 }
5451
5452 pci_wake_from_d3(pdev, wake);
5453 pci_set_power_state(pdev, PCI_D3hot);
5454}
5455
5456static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5457 bool wake)
5458{
5459 struct net_device *netdev = pci_get_drvdata(pdev);
5460 struct e1000_adapter *adapter = netdev_priv(netdev);
5461
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005462 /*
5463 * The pci-e switch on some quad port adapters will report a
5464 * correctable error when the MAC transitions from D0 to D3. To
5465 * prevent this we need to mask off the correctable errors on the
5466 * downstream port of the pci-e switch.
5467 */
5468 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5469 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005470 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005471 u16 devctl;
5472
5473 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5474 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5475 (devctl & ~PCI_EXP_DEVCTL_CERE));
5476
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005477 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005478
5479 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5480 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005481 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005482 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005483}
5484
Bruce Allan6f461f62010-04-27 03:33:04 +00005485#ifdef CONFIG_PCIEASPM
5486static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5487{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005488 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005489}
5490#else
5491static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005492{
5493 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005494 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005495
5496 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005497 * Both device and parent should have the same ASPM setting.
5498 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005499 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005500 pos = pci_pcie_cap(pdev);
5501 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5502 reg16 &= ~state;
5503 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5504
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005505 if (!pdev->bus->self)
5506 return;
5507
Bruce Allan6f461f62010-04-27 03:33:04 +00005508 pos = pci_pcie_cap(pdev->bus->self);
5509 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5510 reg16 &= ~state;
5511 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5512}
5513#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005514static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005515{
5516 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5517 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5518 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5519
5520 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005521}
5522
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005523#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005524static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005525{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005526 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005527}
5528
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005529static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005530{
5531 struct net_device *netdev = pci_get_drvdata(pdev);
5532 struct e1000_adapter *adapter = netdev_priv(netdev);
5533 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005534 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005535 u32 err;
5536
Bruce Allan78cd29d2011-03-24 03:09:03 +00005537 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5538 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5539 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5540 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5541 if (aspm_disable_flag)
5542 e1000e_disable_aspm(pdev, aspm_disable_flag);
5543
Auke Kokbc7f75f2007-09-17 12:30:59 -07005544 pci_set_power_state(pdev, PCI_D0);
5545 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005546 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005547
Bruce Allan4662e822008-08-26 18:37:06 -07005548 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005549 if (netif_running(netdev)) {
5550 err = e1000_request_irq(adapter);
5551 if (err)
5552 return err;
5553 }
5554
Bruce Allan99730e42011-05-13 07:19:48 +00005555 if (hw->mac.type == e1000_pch2lan)
5556 e1000_resume_workarounds_pchlan(&adapter->hw);
5557
Auke Kokbc7f75f2007-09-17 12:30:59 -07005558 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005559
5560 /* report the system wakeup cause from S3/S4 */
5561 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5562 u16 phy_data;
5563
5564 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5565 if (phy_data) {
5566 e_info("PHY Wakeup cause - %s\n",
5567 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5568 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5569 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5570 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005571 phy_data & E1000_WUS_LNKC ?
5572 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005573 }
5574 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5575 } else {
5576 u32 wus = er32(WUS);
5577 if (wus) {
5578 e_info("MAC Wakeup cause - %s\n",
5579 wus & E1000_WUS_EX ? "Unicast Packet" :
5580 wus & E1000_WUS_MC ? "Multicast Packet" :
5581 wus & E1000_WUS_BC ? "Broadcast Packet" :
5582 wus & E1000_WUS_MAG ? "Magic Packet" :
5583 wus & E1000_WUS_LNKC ? "Link Status Change" :
5584 "other");
5585 }
5586 ew32(WUS, ~0);
5587 }
5588
Auke Kokbc7f75f2007-09-17 12:30:59 -07005589 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005590
Bruce Allancd791612010-05-10 14:59:51 +00005591 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005592
5593 if (netif_running(netdev))
5594 e1000e_up(adapter);
5595
5596 netif_device_attach(netdev);
5597
Bruce Allanad680762008-03-28 09:15:03 -07005598 /*
5599 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005600 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005601 * under the control of the driver.
5602 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005603 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005604 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005605
5606 return 0;
5607}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005608
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005609#ifdef CONFIG_PM_SLEEP
5610static int e1000_suspend(struct device *dev)
5611{
5612 struct pci_dev *pdev = to_pci_dev(dev);
5613 int retval;
5614 bool wake;
5615
5616 retval = __e1000_shutdown(pdev, &wake, false);
5617 if (!retval)
5618 e1000_complete_shutdown(pdev, true, wake);
5619
5620 return retval;
5621}
5622
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005623static int e1000_resume(struct device *dev)
5624{
5625 struct pci_dev *pdev = to_pci_dev(dev);
5626 struct net_device *netdev = pci_get_drvdata(pdev);
5627 struct e1000_adapter *adapter = netdev_priv(netdev);
5628
5629 if (e1000e_pm_ready(adapter))
5630 adapter->idle_check = true;
5631
5632 return __e1000_resume(pdev);
5633}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005634#endif /* CONFIG_PM_SLEEP */
5635
5636#ifdef CONFIG_PM_RUNTIME
5637static int e1000_runtime_suspend(struct device *dev)
5638{
5639 struct pci_dev *pdev = to_pci_dev(dev);
5640 struct net_device *netdev = pci_get_drvdata(pdev);
5641 struct e1000_adapter *adapter = netdev_priv(netdev);
5642
5643 if (e1000e_pm_ready(adapter)) {
5644 bool wake;
5645
5646 __e1000_shutdown(pdev, &wake, true);
5647 }
5648
5649 return 0;
5650}
5651
5652static int e1000_idle(struct device *dev)
5653{
5654 struct pci_dev *pdev = to_pci_dev(dev);
5655 struct net_device *netdev = pci_get_drvdata(pdev);
5656 struct e1000_adapter *adapter = netdev_priv(netdev);
5657
5658 if (!e1000e_pm_ready(adapter))
5659 return 0;
5660
5661 if (adapter->idle_check) {
5662 adapter->idle_check = false;
5663 if (!e1000e_has_link(adapter))
5664 pm_schedule_suspend(dev, MSEC_PER_SEC);
5665 }
5666
5667 return -EBUSY;
5668}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005669
5670static int e1000_runtime_resume(struct device *dev)
5671{
5672 struct pci_dev *pdev = to_pci_dev(dev);
5673 struct net_device *netdev = pci_get_drvdata(pdev);
5674 struct e1000_adapter *adapter = netdev_priv(netdev);
5675
5676 if (!e1000e_pm_ready(adapter))
5677 return 0;
5678
5679 adapter->idle_check = !dev->power.runtime_auto;
5680 return __e1000_resume(pdev);
5681}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005682#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005683#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005684
5685static void e1000_shutdown(struct pci_dev *pdev)
5686{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005687 bool wake = false;
5688
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005689 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005690
5691 if (system_state == SYSTEM_POWER_OFF)
5692 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005693}
5694
5695#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005696
5697static irqreturn_t e1000_intr_msix(int irq, void *data)
5698{
5699 struct net_device *netdev = data;
5700 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005701
5702 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005703 int vector, msix_irq;
5704
Dongdong Deng147b2c82010-11-16 19:50:15 -08005705 vector = 0;
5706 msix_irq = adapter->msix_entries[vector].vector;
5707 disable_irq(msix_irq);
5708 e1000_intr_msix_rx(msix_irq, netdev);
5709 enable_irq(msix_irq);
5710
5711 vector++;
5712 msix_irq = adapter->msix_entries[vector].vector;
5713 disable_irq(msix_irq);
5714 e1000_intr_msix_tx(msix_irq, netdev);
5715 enable_irq(msix_irq);
5716
5717 vector++;
5718 msix_irq = adapter->msix_entries[vector].vector;
5719 disable_irq(msix_irq);
5720 e1000_msix_other(msix_irq, netdev);
5721 enable_irq(msix_irq);
5722 }
5723
5724 return IRQ_HANDLED;
5725}
5726
Auke Kokbc7f75f2007-09-17 12:30:59 -07005727/*
5728 * Polling 'interrupt' - used by things like netconsole to send skbs
5729 * without having to re-enable interrupts. It's not called while
5730 * the interrupt routine is executing.
5731 */
5732static void e1000_netpoll(struct net_device *netdev)
5733{
5734 struct e1000_adapter *adapter = netdev_priv(netdev);
5735
Dongdong Deng147b2c82010-11-16 19:50:15 -08005736 switch (adapter->int_mode) {
5737 case E1000E_INT_MODE_MSIX:
5738 e1000_intr_msix(adapter->pdev->irq, netdev);
5739 break;
5740 case E1000E_INT_MODE_MSI:
5741 disable_irq(adapter->pdev->irq);
5742 e1000_intr_msi(adapter->pdev->irq, netdev);
5743 enable_irq(adapter->pdev->irq);
5744 break;
5745 default: /* E1000E_INT_MODE_LEGACY */
5746 disable_irq(adapter->pdev->irq);
5747 e1000_intr(adapter->pdev->irq, netdev);
5748 enable_irq(adapter->pdev->irq);
5749 break;
5750 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005751}
5752#endif
5753
5754/**
5755 * e1000_io_error_detected - called when PCI error is detected
5756 * @pdev: Pointer to PCI device
5757 * @state: The current pci connection state
5758 *
5759 * This function is called after a PCI bus error affecting
5760 * this device has been detected.
5761 */
5762static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5763 pci_channel_state_t state)
5764{
5765 struct net_device *netdev = pci_get_drvdata(pdev);
5766 struct e1000_adapter *adapter = netdev_priv(netdev);
5767
5768 netif_device_detach(netdev);
5769
Mike Masonc93b5a72009-06-30 12:45:53 +00005770 if (state == pci_channel_io_perm_failure)
5771 return PCI_ERS_RESULT_DISCONNECT;
5772
Auke Kokbc7f75f2007-09-17 12:30:59 -07005773 if (netif_running(netdev))
5774 e1000e_down(adapter);
5775 pci_disable_device(pdev);
5776
5777 /* Request a slot slot reset. */
5778 return PCI_ERS_RESULT_NEED_RESET;
5779}
5780
5781/**
5782 * e1000_io_slot_reset - called after the pci bus has been reset.
5783 * @pdev: Pointer to PCI device
5784 *
5785 * Restart the card from scratch, as if from a cold-boot. Implementation
5786 * resembles the first-half of the e1000_resume routine.
5787 */
5788static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5789{
5790 struct net_device *netdev = pci_get_drvdata(pdev);
5791 struct e1000_adapter *adapter = netdev_priv(netdev);
5792 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005793 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005794 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005795 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005796
Bruce Allan78cd29d2011-03-24 03:09:03 +00005797 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5798 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005799 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005800 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5801 if (aspm_disable_flag)
5802 e1000e_disable_aspm(pdev, aspm_disable_flag);
5803
Bruce Allanf0f422e2008-08-04 17:21:53 -07005804 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005805 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005806 dev_err(&pdev->dev,
5807 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005808 result = PCI_ERS_RESULT_DISCONNECT;
5809 } else {
5810 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005811 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005812 pci_restore_state(pdev);
5813
5814 pci_enable_wake(pdev, PCI_D3hot, 0);
5815 pci_enable_wake(pdev, PCI_D3cold, 0);
5816
5817 e1000e_reset(adapter);
5818 ew32(WUS, ~0);
5819 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005820 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005821
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005822 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005823
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005824 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005825}
5826
5827/**
5828 * e1000_io_resume - called when traffic can start flowing again.
5829 * @pdev: Pointer to PCI device
5830 *
5831 * This callback is called when the error recovery driver tells us that
5832 * its OK to resume normal operation. Implementation resembles the
5833 * second-half of the e1000_resume routine.
5834 */
5835static void e1000_io_resume(struct pci_dev *pdev)
5836{
5837 struct net_device *netdev = pci_get_drvdata(pdev);
5838 struct e1000_adapter *adapter = netdev_priv(netdev);
5839
Bruce Allancd791612010-05-10 14:59:51 +00005840 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005841
5842 if (netif_running(netdev)) {
5843 if (e1000e_up(adapter)) {
5844 dev_err(&pdev->dev,
5845 "can't bring device back up after reset\n");
5846 return;
5847 }
5848 }
5849
5850 netif_device_attach(netdev);
5851
Bruce Allanad680762008-03-28 09:15:03 -07005852 /*
5853 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005854 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005855 * under the control of the driver.
5856 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005857 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005858 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005859
5860}
5861
5862static void e1000_print_device_info(struct e1000_adapter *adapter)
5863{
5864 struct e1000_hw *hw = &adapter->hw;
5865 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005866 u32 ret_val;
5867 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005868
5869 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005870 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005871 /* bus width */
5872 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5873 "Width x1"),
5874 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005875 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005876 e_info("Intel(R) PRO/%s Network Connection\n",
5877 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005878 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5879 E1000_PBANUM_LENGTH);
5880 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005881 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005882 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5883 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005884}
5885
Auke Kok10aa4c02008-08-04 17:21:20 -07005886static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5887{
5888 struct e1000_hw *hw = &adapter->hw;
5889 int ret_val;
5890 u16 buf = 0;
5891
5892 if (hw->mac.type != e1000_82573)
5893 return;
5894
5895 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005896 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005897 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005898 dev_warn(&adapter->pdev->dev,
5899 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005900 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005901}
5902
Bruce Allandc221292011-08-19 03:23:48 +00005903static int e1000_set_features(struct net_device *netdev, u32 features)
5904{
5905 struct e1000_adapter *adapter = netdev_priv(netdev);
5906 u32 changed = features ^ netdev->features;
5907
5908 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5909 adapter->flags |= FLAG_TSO_FORCE;
5910
5911 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
5912 NETIF_F_RXCSUM)))
5913 return 0;
5914
5915 if (netif_running(netdev))
5916 e1000e_reinit_locked(adapter);
5917 else
5918 e1000e_reset(adapter);
5919
5920 return 0;
5921}
5922
Stephen Hemminger651c2462008-11-19 21:57:48 -08005923static const struct net_device_ops e1000e_netdev_ops = {
5924 .ndo_open = e1000_open,
5925 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005926 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005927 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005928 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005929 .ndo_set_mac_address = e1000_set_mac,
5930 .ndo_change_mtu = e1000_change_mtu,
5931 .ndo_do_ioctl = e1000_ioctl,
5932 .ndo_tx_timeout = e1000_tx_timeout,
5933 .ndo_validate_addr = eth_validate_addr,
5934
Stephen Hemminger651c2462008-11-19 21:57:48 -08005935 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5936 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5937#ifdef CONFIG_NET_POLL_CONTROLLER
5938 .ndo_poll_controller = e1000_netpoll,
5939#endif
Bruce Allandc221292011-08-19 03:23:48 +00005940 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005941};
5942
Auke Kokbc7f75f2007-09-17 12:30:59 -07005943/**
5944 * e1000_probe - Device Initialization Routine
5945 * @pdev: PCI device information struct
5946 * @ent: entry in e1000_pci_tbl
5947 *
5948 * Returns 0 on success, negative on failure
5949 *
5950 * e1000_probe initializes an adapter identified by a pci_dev structure.
5951 * The OS initialization, configuring of the adapter private structure,
5952 * and a hardware reset occur.
5953 **/
5954static int __devinit e1000_probe(struct pci_dev *pdev,
5955 const struct pci_device_id *ent)
5956{
5957 struct net_device *netdev;
5958 struct e1000_adapter *adapter;
5959 struct e1000_hw *hw;
5960 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005961 resource_size_t mmio_start, mmio_len;
5962 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005963
5964 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005965 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005966 int i, err, pci_using_dac;
5967 u16 eeprom_data = 0;
5968 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5969
Bruce Allan78cd29d2011-03-24 03:09:03 +00005970 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
5971 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005972 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005973 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5974 if (aspm_disable_flag)
5975 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005976
Bruce Allanf0f422e2008-08-04 17:21:53 -07005977 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005978 if (err)
5979 return err;
5980
5981 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005982 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005983 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005984 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005985 if (!err)
5986 pci_using_dac = 1;
5987 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005988 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005989 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005990 err = dma_set_coherent_mask(&pdev->dev,
5991 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005992 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00005993 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005994 goto err_dma;
5995 }
5996 }
5997 }
5998
Arjan van de Vene8de1482008-10-22 19:55:31 -07005999 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006000 pci_select_bars(pdev, IORESOURCE_MEM),
6001 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006002 if (err)
6003 goto err_pci_reg;
6004
Xiaotian Feng68eac462009-08-14 14:35:52 +00006005 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006006 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006007
Auke Kokbc7f75f2007-09-17 12:30:59 -07006008 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006009 /* PCI config space info */
6010 err = pci_save_state(pdev);
6011 if (err)
6012 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006013
6014 err = -ENOMEM;
6015 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6016 if (!netdev)
6017 goto err_alloc_etherdev;
6018
Auke Kokbc7f75f2007-09-17 12:30:59 -07006019 SET_NETDEV_DEV(netdev, &pdev->dev);
6020
Tom Herbertf85e4df2010-05-05 14:03:32 +00006021 netdev->irq = pdev->irq;
6022
Auke Kokbc7f75f2007-09-17 12:30:59 -07006023 pci_set_drvdata(pdev, netdev);
6024 adapter = netdev_priv(netdev);
6025 hw = &adapter->hw;
6026 adapter->netdev = netdev;
6027 adapter->pdev = pdev;
6028 adapter->ei = ei;
6029 adapter->pba = ei->pba;
6030 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006031 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006032 adapter->hw.adapter = adapter;
6033 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006034 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006035 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6036
6037 mmio_start = pci_resource_start(pdev, 0);
6038 mmio_len = pci_resource_len(pdev, 0);
6039
6040 err = -EIO;
6041 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6042 if (!adapter->hw.hw_addr)
6043 goto err_ioremap;
6044
6045 if ((adapter->flags & FLAG_HAS_FLASH) &&
6046 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6047 flash_start = pci_resource_start(pdev, 1);
6048 flash_len = pci_resource_len(pdev, 1);
6049 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6050 if (!adapter->hw.flash_address)
6051 goto err_flashmap;
6052 }
6053
6054 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006055 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006056 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006057 netdev->watchdog_timeo = 5 * HZ;
6058 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006059 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
6060
6061 netdev->mem_start = mmio_start;
6062 netdev->mem_end = mmio_start + mmio_len;
6063
6064 adapter->bd_number = cards_found++;
6065
Bruce Allan4662e822008-08-26 18:37:06 -07006066 e1000e_check_options(adapter);
6067
Auke Kokbc7f75f2007-09-17 12:30:59 -07006068 /* setup adapter struct */
6069 err = e1000_sw_init(adapter);
6070 if (err)
6071 goto err_sw_init;
6072
Auke Kokbc7f75f2007-09-17 12:30:59 -07006073 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6074 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6075 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6076
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006077 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006078 if (err)
6079 goto err_hw_init;
6080
Bruce Allan4a770352008-10-01 17:18:35 -07006081 if ((adapter->flags & FLAG_IS_ICH) &&
6082 (adapter->flags & FLAG_READ_ONLY_NVM))
6083 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6084
Auke Kokbc7f75f2007-09-17 12:30:59 -07006085 hw->mac.ops.get_bus_info(&adapter->hw);
6086
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006087 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006088
6089 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006090 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006091 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6092 adapter->hw.phy.disable_polarity_correction = 0;
6093 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6094 }
6095
6096 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006097 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006098
Bruce Allandc221292011-08-19 03:23:48 +00006099 /* Set initial default active device features */
6100 netdev->features = (NETIF_F_SG |
6101 NETIF_F_HW_VLAN_RX |
6102 NETIF_F_HW_VLAN_TX |
6103 NETIF_F_TSO |
6104 NETIF_F_TSO6 |
6105 NETIF_F_RXCSUM |
6106 NETIF_F_HW_CSUM);
6107
6108 /* Set user-changeable features (subset of all device features) */
6109 netdev->hw_features = netdev->features;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006110
6111 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6112 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6113
Bruce Allandc221292011-08-19 03:23:48 +00006114 netdev->vlan_features |= (NETIF_F_SG |
6115 NETIF_F_TSO |
6116 NETIF_F_TSO6 |
6117 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006118
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006119 netdev->priv_flags |= IFF_UNICAST_FLT;
6120
Yi Zou7b872a52010-09-22 17:57:58 +00006121 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006122 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006123 netdev->vlan_features |= NETIF_F_HIGHDMA;
6124 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006125
Auke Kokbc7f75f2007-09-17 12:30:59 -07006126 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6127 adapter->flags |= FLAG_MNG_PT_ENABLED;
6128
Bruce Allanad680762008-03-28 09:15:03 -07006129 /*
6130 * before reading the NVM, reset the controller to
6131 * put the device in a known good starting state
6132 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006133 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6134
6135 /*
6136 * systems with ASPM and others may see the checksum fail on the first
6137 * attempt. Let's give it a few tries
6138 */
6139 for (i = 0;; i++) {
6140 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6141 break;
6142 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006143 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006144 err = -EIO;
6145 goto err_eeprom;
6146 }
6147 }
6148
Auke Kok10aa4c02008-08-04 17:21:20 -07006149 e1000_eeprom_checks(adapter);
6150
Bruce Allan608f8a02010-01-13 02:04:58 +00006151 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006152 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006153 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006154
6155 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6156 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6157
6158 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006159 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006160 err = -EIO;
6161 goto err_eeprom;
6162 }
6163
6164 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006165 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006166 adapter->watchdog_timer.data = (unsigned long) adapter;
6167
6168 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006169 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006170 adapter->phy_info_timer.data = (unsigned long) adapter;
6171
6172 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6173 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006174 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6175 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006176 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006177
Auke Kokbc7f75f2007-09-17 12:30:59 -07006178 /* Initialize link parameters. User can change them with ethtool */
6179 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07006180 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006181 adapter->hw.fc.requested_mode = e1000_fc_default;
6182 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006183 adapter->hw.phy.autoneg_advertised = 0x2f;
6184
6185 /* ring size defaults */
6186 adapter->rx_ring->count = 256;
6187 adapter->tx_ring->count = 256;
6188
6189 /*
6190 * Initial Wake on LAN setting - If APM wake is enabled in
6191 * the EEPROM, enable the ACPI Magic Packet filter
6192 */
6193 if (adapter->flags & FLAG_APME_IN_WUC) {
6194 /* APME bit in EEPROM is mapped to WUC.APME */
6195 eeprom_data = er32(WUC);
6196 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006197 if ((hw->mac.type > e1000_ich10lan) &&
6198 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006199 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006200 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6201 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6202 (adapter->hw.bus.func == 1))
6203 e1000_read_nvm(&adapter->hw,
6204 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6205 else
6206 e1000_read_nvm(&adapter->hw,
6207 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6208 }
6209
6210 /* fetch WoL from EEPROM */
6211 if (eeprom_data & eeprom_apme_mask)
6212 adapter->eeprom_wol |= E1000_WUFC_MAG;
6213
6214 /*
6215 * now that we have the eeprom settings, apply the special cases
6216 * where the eeprom may be wrong or the board simply won't support
6217 * wake on lan on a particular port
6218 */
6219 if (!(adapter->flags & FLAG_HAS_WOL))
6220 adapter->eeprom_wol = 0;
6221
6222 /* initialize the wol settings based on the eeprom settings */
6223 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006224 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006225
Bruce Allan84527592008-11-21 17:00:22 -08006226 /* save off EEPROM version number */
6227 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6228
Auke Kokbc7f75f2007-09-17 12:30:59 -07006229 /* reset the hardware with the new settings */
6230 e1000e_reset(adapter);
6231
Bruce Allanad680762008-03-28 09:15:03 -07006232 /*
6233 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006234 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006235 * under the control of the driver.
6236 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006237 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006238 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006239
Bruce Allane0dc4f12011-01-06 14:29:50 +00006240 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006241 err = register_netdev(netdev);
6242 if (err)
6243 goto err_register;
6244
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006245 /* carrier off reporting is important to ethtool even BEFORE open */
6246 netif_carrier_off(netdev);
6247
Auke Kokbc7f75f2007-09-17 12:30:59 -07006248 e1000_print_device_info(adapter);
6249
Alan Sternf3ec4f82010-06-08 15:23:51 -04006250 if (pci_dev_run_wake(pdev))
6251 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006252
Auke Kokbc7f75f2007-09-17 12:30:59 -07006253 return 0;
6254
6255err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006256 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006257 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006258err_eeprom:
6259 if (!e1000_check_reset_block(&adapter->hw))
6260 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006261err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006262 kfree(adapter->tx_ring);
6263 kfree(adapter->rx_ring);
6264err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006265 if (adapter->hw.flash_address)
6266 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006267 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006268err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006269 iounmap(adapter->hw.hw_addr);
6270err_ioremap:
6271 free_netdev(netdev);
6272err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006273 pci_release_selected_regions(pdev,
6274 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006275err_pci_reg:
6276err_dma:
6277 pci_disable_device(pdev);
6278 return err;
6279}
6280
6281/**
6282 * e1000_remove - Device Removal Routine
6283 * @pdev: PCI device information struct
6284 *
6285 * e1000_remove is called by the PCI subsystem to alert the driver
6286 * that it should release a PCI device. The could be caused by a
6287 * Hot-Plug event, or because the driver is going to be removed from
6288 * memory.
6289 **/
6290static void __devexit e1000_remove(struct pci_dev *pdev)
6291{
6292 struct net_device *netdev = pci_get_drvdata(pdev);
6293 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006294 bool down = test_bit(__E1000_DOWN, &adapter->state);
6295
Bruce Allanad680762008-03-28 09:15:03 -07006296 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006297 * The timers may be rescheduled, so explicitly disable them
6298 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006299 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006300 if (!down)
6301 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006302 del_timer_sync(&adapter->watchdog_timer);
6303 del_timer_sync(&adapter->phy_info_timer);
6304
Bruce Allan41cec6f2009-11-20 23:28:56 +00006305 cancel_work_sync(&adapter->reset_task);
6306 cancel_work_sync(&adapter->watchdog_task);
6307 cancel_work_sync(&adapter->downshift_task);
6308 cancel_work_sync(&adapter->update_phy_task);
6309 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006310
Bruce Allan17f208d2009-12-01 15:47:22 +00006311 if (!(netdev->flags & IFF_UP))
6312 e1000_power_down_phy(adapter);
6313
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006314 /* Don't lie to e1000_close() down the road. */
6315 if (!down)
6316 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006317 unregister_netdev(netdev);
6318
Alan Sternf3ec4f82010-06-08 15:23:51 -04006319 if (pci_dev_run_wake(pdev))
6320 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006321
Bruce Allanad680762008-03-28 09:15:03 -07006322 /*
6323 * Release control of h/w to f/w. If f/w is AMT enabled, this
6324 * would have already happened in close and is redundant.
6325 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006326 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006327
Bruce Allan4662e822008-08-26 18:37:06 -07006328 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006329 kfree(adapter->tx_ring);
6330 kfree(adapter->rx_ring);
6331
6332 iounmap(adapter->hw.hw_addr);
6333 if (adapter->hw.flash_address)
6334 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006335 pci_release_selected_regions(pdev,
6336 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006337
6338 free_netdev(netdev);
6339
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006340 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006341 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006342
Auke Kokbc7f75f2007-09-17 12:30:59 -07006343 pci_disable_device(pdev);
6344}
6345
6346/* PCI Error Recovery (ERS) */
6347static struct pci_error_handlers e1000_err_handler = {
6348 .error_detected = e1000_io_error_detected,
6349 .slot_reset = e1000_io_slot_reset,
6350 .resume = e1000_io_resume,
6351};
6352
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006353static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006354 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6355 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6356 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6357 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6358 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6359 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006360 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6361 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6362 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006363
Auke Kokbc7f75f2007-09-17 12:30:59 -07006364 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6365 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6366 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6367 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006368
Auke Kokbc7f75f2007-09-17 12:30:59 -07006369 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6370 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6371 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006372
Bruce Allan4662e822008-08-26 18:37:06 -07006373 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006374 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006375 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006376
Auke Kokbc7f75f2007-09-17 12:30:59 -07006377 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6378 board_80003es2lan },
6379 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6380 board_80003es2lan },
6381 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6382 board_80003es2lan },
6383 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6384 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006385
Auke Kokbc7f75f2007-09-17 12:30:59 -07006386 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6387 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6388 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6389 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6390 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6391 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6392 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006393 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006394
Auke Kokbc7f75f2007-09-17 12:30:59 -07006395 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6396 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6397 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6398 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6399 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006400 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006401 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6402 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6403 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6404
6405 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6406 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6407 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006408
Bruce Allanf4187b52008-08-26 18:36:50 -07006409 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6410 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006411 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006412
Bruce Allana4f58f52009-06-02 11:29:18 +00006413 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6414 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6415 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6416 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6417
Bruce Alland3738bb2010-06-16 13:27:28 +00006418 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6419 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6420
Auke Kokbc7f75f2007-09-17 12:30:59 -07006421 { } /* terminate list */
6422};
6423MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6424
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006425#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006426static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006427 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6428 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6429 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006430};
David S. Millere50208a2010-03-16 23:36:24 -07006431#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006432
Auke Kokbc7f75f2007-09-17 12:30:59 -07006433/* PCI Device API Driver */
6434static struct pci_driver e1000_driver = {
6435 .name = e1000e_driver_name,
6436 .id_table = e1000_pci_tbl,
6437 .probe = e1000_probe,
6438 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006439#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006440 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006441#endif
6442 .shutdown = e1000_shutdown,
6443 .err_handler = &e1000_err_handler
6444};
6445
6446/**
6447 * e1000_init_module - Driver Registration Routine
6448 *
6449 * e1000_init_module is the first routine called when the driver is
6450 * loaded. All it does is register with the PCI subsystem.
6451 **/
6452static int __init e1000_init_module(void)
6453{
6454 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006455 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6456 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006457 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006458 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006459
Auke Kokbc7f75f2007-09-17 12:30:59 -07006460 return ret;
6461}
6462module_init(e1000_init_module);
6463
6464/**
6465 * e1000_exit_module - Driver Exit Cleanup Routine
6466 *
6467 * e1000_exit_module is called just before the driver is removed
6468 * from memory.
6469 **/
6470static void __exit e1000_exit_module(void)
6471{
6472 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006473}
6474module_exit(e1000_exit_module);
6475
6476
6477MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6478MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6479MODULE_LICENSE("GPL");
6480MODULE_VERSION(DRV_VERSION);
6481
6482/* e1000_main.c */