blob: 90953b4d6bfaa28e7191b39066514180137c5136 [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 Brandeburgb94b5022010-01-19 14:15:59 +0000901 /*
902 * !EOP means multiple descriptors were used to store a single
903 * packet, if that's the case we need to toss it. In fact, we
904 * need to toss every packet with the EOP bit clear and the
905 * next frame that _does_ have the EOP bit set, as it is by
906 * definition only a frame fragment
907 */
Bruce Allan5f450212011-07-22 06:21:46 +0000908 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000909 adapter->flags2 |= FLAG2_IS_DISCARDING;
910
911 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700912 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000913 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700914 /* recycle */
915 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000916 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000917 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918 goto next_desc;
919 }
920
Bruce Allan5f450212011-07-22 06:21:46 +0000921 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700922 /* recycle */
923 buffer_info->skb = skb;
924 goto next_desc;
925 }
926
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000927 /* adjust length to remove Ethernet CRC */
928 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
929 length -= 4;
930
Auke Kokbc7f75f2007-09-17 12:30:59 -0700931 total_rx_bytes += length;
932 total_rx_packets++;
933
Bruce Allanad680762008-03-28 09:15:03 -0700934 /*
935 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700936 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700937 * of reassembly being done in the stack
938 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939 if (length < copybreak) {
940 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000941 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700942 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700943 skb_copy_to_linear_data_offset(new_skb,
944 -NET_IP_ALIGN,
945 (skb->data -
946 NET_IP_ALIGN),
947 (length +
948 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700949 /* save the skb in buffer_info as good */
950 buffer_info->skb = skb;
951 skb = new_skb;
952 }
953 /* else just continue with the old one */
954 }
955 /* end copybreak code */
956 skb_put(skb, length);
957
958 /* Receive Checksum Offload */
Bruce Allan5f450212011-07-22 06:21:46 +0000959 e1000_rx_checksum(adapter, staterr,
960 le16_to_cpu(rx_desc->wb.lower.hi_dword.
961 csum_ip.csum), skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700962
Bruce Allan5f450212011-07-22 06:21:46 +0000963 e1000_receive_skb(adapter, netdev, skb, staterr,
964 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700965
966next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +0000967 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700968
969 /* return some buffers to hardware, one at a time is too slow */
970 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000971 adapter->alloc_rx_buf(adapter, cleaned_count,
972 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973 cleaned_count = 0;
974 }
975
976 /* use prefetched values */
977 rx_desc = next_rxd;
978 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000979
980 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700981 }
982 rx_ring->next_to_clean = i;
983
984 cleaned_count = e1000_desc_unused(rx_ring);
985 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000986 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700987
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700989 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 return cleaned;
991}
992
Auke Kokbc7f75f2007-09-17 12:30:59 -0700993static void e1000_put_txbuf(struct e1000_adapter *adapter,
994 struct e1000_buffer *buffer_info)
995{
Alexander Duyck03b13202009-12-02 16:45:31 +0000996 if (buffer_info->dma) {
997 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +0000998 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
999 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001000 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001001 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1002 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001003 buffer_info->dma = 0;
1004 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005 if (buffer_info->skb) {
1006 dev_kfree_skb_any(buffer_info->skb);
1007 buffer_info->skb = NULL;
1008 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001009 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010}
1011
Bruce Allan41cec6f2009-11-20 23:28:56 +00001012static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001013{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001014 struct e1000_adapter *adapter = container_of(work,
1015 struct e1000_adapter,
1016 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001017 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001018 struct e1000_ring *tx_ring = adapter->tx_ring;
1019 unsigned int i = tx_ring->next_to_clean;
1020 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1021 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001022 struct e1000_hw *hw = &adapter->hw;
1023 u16 phy_status, phy_1000t_status, phy_ext_status;
1024 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001025
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001026 if (test_bit(__E1000_DOWN, &adapter->state))
1027 return;
1028
Jeff Kirsher09357b02011-11-18 14:25:00 +00001029 if (!adapter->tx_hang_recheck &&
1030 (adapter->flags2 & FLAG2_DMA_BURST)) {
1031 /* May be block on write-back, flush and detect again
1032 * flush pending descriptor writebacks to memory
1033 */
1034 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1035 /* execute the writes immediately */
1036 e1e_flush();
1037 adapter->tx_hang_recheck = true;
1038 return;
1039 }
1040 /* Real hang detected */
1041 adapter->tx_hang_recheck = false;
1042 netif_stop_queue(netdev);
1043
Bruce Allan41cec6f2009-11-20 23:28:56 +00001044 e1e_rphy(hw, PHY_STATUS, &phy_status);
1045 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1046 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1047
1048 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1049
1050 /* detected Hardware unit hang */
1051 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001052 " TDH <%x>\n"
1053 " TDT <%x>\n"
1054 " next_to_use <%x>\n"
1055 " next_to_clean <%x>\n"
1056 "buffer_info[next_to_clean]:\n"
1057 " time_stamp <%lx>\n"
1058 " next_to_watch <%x>\n"
1059 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001060 " next_to_watch.status <%x>\n"
1061 "MAC Status <%x>\n"
1062 "PHY Status <%x>\n"
1063 "PHY 1000BASE-T Status <%x>\n"
1064 "PHY Extended Status <%x>\n"
1065 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001066 readl(adapter->hw.hw_addr + tx_ring->head),
1067 readl(adapter->hw.hw_addr + tx_ring->tail),
1068 tx_ring->next_to_use,
1069 tx_ring->next_to_clean,
1070 tx_ring->buffer_info[eop].time_stamp,
1071 eop,
1072 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001073 eop_desc->upper.fields.status,
1074 er32(STATUS),
1075 phy_status,
1076 phy_1000t_status,
1077 phy_ext_status,
1078 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001079}
1080
1081/**
1082 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1083 * @adapter: board private structure
1084 *
1085 * the return value indicates whether actual cleaning was done, there
1086 * is no guarantee that everything was cleaned
1087 **/
1088static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
1089{
1090 struct net_device *netdev = adapter->netdev;
1091 struct e1000_hw *hw = &adapter->hw;
1092 struct e1000_ring *tx_ring = adapter->tx_ring;
1093 struct e1000_tx_desc *tx_desc, *eop_desc;
1094 struct e1000_buffer *buffer_info;
1095 unsigned int i, eop;
1096 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001098 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099
1100 i = tx_ring->next_to_clean;
1101 eop = tx_ring->buffer_info[i].next_to_watch;
1102 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1103
Alexander Duyck12d04a32009-03-25 22:05:03 +00001104 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1105 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001106 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001107 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001108 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001109 tx_desc = E1000_TX_DESC(*tx_ring, i);
1110 buffer_info = &tx_ring->buffer_info[i];
1111 cleaned = (i == eop);
1112
1113 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001114 total_tx_packets += buffer_info->segs;
1115 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001116 if (buffer_info->skb) {
1117 bytes_compl += buffer_info->skb->len;
1118 pkts_compl++;
1119 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001120 }
1121
1122 e1000_put_txbuf(adapter, buffer_info);
1123 tx_desc->upper.data = 0;
1124
1125 i++;
1126 if (i == tx_ring->count)
1127 i = 0;
1128 }
1129
Terry Loftindac87612010-04-09 10:29:49 +00001130 if (i == tx_ring->next_to_use)
1131 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001132 eop = tx_ring->buffer_info[i].next_to_watch;
1133 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001134 }
1135
1136 tx_ring->next_to_clean = i;
1137
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001138 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1139
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001141 if (count && netif_carrier_ok(netdev) &&
1142 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143 /* Make sure that anybody stopping the queue after this
1144 * sees the new next_to_clean.
1145 */
1146 smp_mb();
1147
1148 if (netif_queue_stopped(netdev) &&
1149 !(test_bit(__E1000_DOWN, &adapter->state))) {
1150 netif_wake_queue(netdev);
1151 ++adapter->restart_queue;
1152 }
1153 }
1154
1155 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001156 /*
1157 * Detect a transmit hang in hardware, this serializes the
1158 * check with the clearing of time_stamp and movement of i
1159 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001161 if (tx_ring->buffer_info[i].time_stamp &&
1162 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001163 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001164 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001165 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001166 else
1167 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001168 }
1169 adapter->total_tx_bytes += total_tx_bytes;
1170 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001171 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001172}
1173
1174/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001175 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1176 * @adapter: board private structure
1177 *
1178 * the return value indicates whether actual cleaning was done, there
1179 * is no guarantee that everything was cleaned
1180 **/
1181static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1182 int *work_done, int work_to_do)
1183{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001184 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1186 struct net_device *netdev = adapter->netdev;
1187 struct pci_dev *pdev = adapter->pdev;
1188 struct e1000_ring *rx_ring = adapter->rx_ring;
1189 struct e1000_buffer *buffer_info, *next_buffer;
1190 struct e1000_ps_page *ps_page;
1191 struct sk_buff *skb;
1192 unsigned int i, j;
1193 u32 length, staterr;
1194 int cleaned_count = 0;
1195 bool cleaned = 0;
1196 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1197
1198 i = rx_ring->next_to_clean;
1199 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1200 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1201 buffer_info = &rx_ring->buffer_info[i];
1202
1203 while (staterr & E1000_RXD_STAT_DD) {
1204 if (*work_done >= work_to_do)
1205 break;
1206 (*work_done)++;
1207 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001208 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209
1210 /* in the packet split case this is header only */
1211 prefetch(skb->data - NET_IP_ALIGN);
1212
1213 i++;
1214 if (i == rx_ring->count)
1215 i = 0;
1216 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1217 prefetch(next_rxd);
1218
1219 next_buffer = &rx_ring->buffer_info[i];
1220
1221 cleaned = 1;
1222 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001223 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001224 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001225 buffer_info->dma = 0;
1226
Bruce Allanaf667a22010-12-31 06:10:01 +00001227 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001228 if (!(staterr & E1000_RXD_STAT_EOP))
1229 adapter->flags2 |= FLAG2_IS_DISCARDING;
1230
1231 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001232 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001234 if (staterr & E1000_RXD_STAT_EOP)
1235 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001236 goto next_desc;
1237 }
1238
1239 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1240 dev_kfree_skb_irq(skb);
1241 goto next_desc;
1242 }
1243
1244 length = le16_to_cpu(rx_desc->wb.middle.length0);
1245
1246 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001247 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001248 dev_kfree_skb_irq(skb);
1249 goto next_desc;
1250 }
1251
1252 /* Good Receive */
1253 skb_put(skb, length);
1254
1255 {
Bruce Allanad680762008-03-28 09:15:03 -07001256 /*
1257 * this looks ugly, but it seems compiler issues make it
1258 * more efficient than reusing j
1259 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1261
Bruce Allanad680762008-03-28 09:15:03 -07001262 /*
1263 * page alloc/put takes too long and effects small packet
1264 * throughput, so unsplit small packets and save the alloc/put
1265 * only valid in softirq (napi) context to call kmap_*
1266 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001267 if (l1 && (l1 <= copybreak) &&
1268 ((length + l1) <= adapter->rx_ps_bsize0)) {
1269 u8 *vaddr;
1270
Auke Kok47f44e42007-10-25 13:57:44 -07001271 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001272
Bruce Allanad680762008-03-28 09:15:03 -07001273 /*
1274 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001275 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001276 * very long
1277 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001278 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1279 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001280 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1281 memcpy(skb_tail_pointer(skb), vaddr, l1);
1282 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001283 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1284 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001285
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001286 /* remove the CRC */
1287 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1288 l1 -= 4;
1289
Auke Kokbc7f75f2007-09-17 12:30:59 -07001290 skb_put(skb, l1);
1291 goto copydone;
1292 } /* if */
1293 }
1294
1295 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1296 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1297 if (!length)
1298 break;
1299
Auke Kok47f44e42007-10-25 13:57:44 -07001300 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001301 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1302 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001303 ps_page->dma = 0;
1304 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1305 ps_page->page = NULL;
1306 skb->len += length;
1307 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001308 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001309 }
1310
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001311 /* strip the ethernet crc, problem is we're using pages now so
1312 * this whole operation can get a little cpu intensive
1313 */
1314 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1315 pskb_trim(skb, skb->len - 4);
1316
Auke Kokbc7f75f2007-09-17 12:30:59 -07001317copydone:
1318 total_rx_bytes += skb->len;
1319 total_rx_packets++;
1320
1321 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1322 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1323
1324 if (rx_desc->wb.upper.header_status &
1325 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1326 adapter->rx_hdr_split++;
1327
1328 e1000_receive_skb(adapter, netdev, skb,
1329 staterr, rx_desc->wb.middle.vlan);
1330
1331next_desc:
1332 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1333 buffer_info->skb = NULL;
1334
1335 /* return some buffers to hardware, one at a time is too slow */
1336 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001337 adapter->alloc_rx_buf(adapter, cleaned_count,
1338 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001339 cleaned_count = 0;
1340 }
1341
1342 /* use prefetched values */
1343 rx_desc = next_rxd;
1344 buffer_info = next_buffer;
1345
1346 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1347 }
1348 rx_ring->next_to_clean = i;
1349
1350 cleaned_count = e1000_desc_unused(rx_ring);
1351 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001352 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001353
Auke Kokbc7f75f2007-09-17 12:30:59 -07001354 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001355 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001356 return cleaned;
1357}
1358
1359/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001360 * e1000_consume_page - helper function
1361 **/
1362static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1363 u16 length)
1364{
1365 bi->page = NULL;
1366 skb->len += length;
1367 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001368 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001369}
1370
1371/**
1372 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1373 * @adapter: board private structure
1374 *
1375 * the return value indicates whether actual cleaning was done, there
1376 * is no guarantee that everything was cleaned
1377 **/
1378
1379static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1380 int *work_done, int work_to_do)
1381{
1382 struct net_device *netdev = adapter->netdev;
1383 struct pci_dev *pdev = adapter->pdev;
1384 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +00001385 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001386 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001387 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001388 unsigned int i;
1389 int cleaned_count = 0;
1390 bool cleaned = false;
1391 unsigned int total_rx_bytes=0, total_rx_packets=0;
1392
1393 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001394 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1395 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001396 buffer_info = &rx_ring->buffer_info[i];
1397
Bruce Allan5f450212011-07-22 06:21:46 +00001398 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001399 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001400
1401 if (*work_done >= work_to_do)
1402 break;
1403 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001404 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001405
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001406 skb = buffer_info->skb;
1407 buffer_info->skb = NULL;
1408
1409 ++i;
1410 if (i == rx_ring->count)
1411 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001412 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001413 prefetch(next_rxd);
1414
1415 next_buffer = &rx_ring->buffer_info[i];
1416
1417 cleaned = true;
1418 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001419 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1420 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001421 buffer_info->dma = 0;
1422
Bruce Allan5f450212011-07-22 06:21:46 +00001423 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001424
1425 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001426 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1427 (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
1428 /* recycle both page and skb */
1429 buffer_info->skb = skb;
1430 /* an error means any chain goes out the window too */
1431 if (rx_ring->rx_skb_top)
1432 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1433 rx_ring->rx_skb_top = NULL;
1434 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001435 }
1436
Bruce Allanf0f1a172010-12-11 05:53:32 +00001437#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001438 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001439 /* this descriptor is only the beginning (or middle) */
1440 if (!rxtop) {
1441 /* this is the beginning of a chain */
1442 rxtop = skb;
1443 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1444 0, length);
1445 } else {
1446 /* this is the middle of a chain */
1447 skb_fill_page_desc(rxtop,
1448 skb_shinfo(rxtop)->nr_frags,
1449 buffer_info->page, 0, length);
1450 /* re-use the skb, only consumed the page */
1451 buffer_info->skb = skb;
1452 }
1453 e1000_consume_page(buffer_info, rxtop, length);
1454 goto next_desc;
1455 } else {
1456 if (rxtop) {
1457 /* end of the chain */
1458 skb_fill_page_desc(rxtop,
1459 skb_shinfo(rxtop)->nr_frags,
1460 buffer_info->page, 0, length);
1461 /* re-use the current skb, we only consumed the
1462 * page */
1463 buffer_info->skb = skb;
1464 skb = rxtop;
1465 rxtop = NULL;
1466 e1000_consume_page(buffer_info, skb, length);
1467 } else {
1468 /* no chain, got EOP, this buf is the packet
1469 * copybreak to save the put_page/alloc_page */
1470 if (length <= copybreak &&
1471 skb_tailroom(skb) >= length) {
1472 u8 *vaddr;
1473 vaddr = kmap_atomic(buffer_info->page,
1474 KM_SKB_DATA_SOFTIRQ);
1475 memcpy(skb_tail_pointer(skb), vaddr,
1476 length);
1477 kunmap_atomic(vaddr,
1478 KM_SKB_DATA_SOFTIRQ);
1479 /* re-use the page, so don't erase
1480 * buffer_info->page */
1481 skb_put(skb, length);
1482 } else {
1483 skb_fill_page_desc(skb, 0,
1484 buffer_info->page, 0,
1485 length);
1486 e1000_consume_page(buffer_info, skb,
1487 length);
1488 }
1489 }
1490 }
1491
1492 /* Receive Checksum Offload XXX recompute due to CRC strip? */
Bruce Allan5f450212011-07-22 06:21:46 +00001493 e1000_rx_checksum(adapter, staterr,
1494 le16_to_cpu(rx_desc->wb.lower.hi_dword.
1495 csum_ip.csum), skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001496
1497 /* probably a little skewed due to removing CRC */
1498 total_rx_bytes += skb->len;
1499 total_rx_packets++;
1500
1501 /* eth type trans needs skb->data to point to something */
1502 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001503 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001504 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001505 goto next_desc;
1506 }
1507
Bruce Allan5f450212011-07-22 06:21:46 +00001508 e1000_receive_skb(adapter, netdev, skb, staterr,
1509 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001510
1511next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001512 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001513
1514 /* return some buffers to hardware, one at a time is too slow */
1515 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001516 adapter->alloc_rx_buf(adapter, cleaned_count,
1517 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001518 cleaned_count = 0;
1519 }
1520
1521 /* use prefetched values */
1522 rx_desc = next_rxd;
1523 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001524
1525 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001526 }
1527 rx_ring->next_to_clean = i;
1528
1529 cleaned_count = e1000_desc_unused(rx_ring);
1530 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001531 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001532
1533 adapter->total_rx_bytes += total_rx_bytes;
1534 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001535 return cleaned;
1536}
1537
1538/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001539 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1540 * @adapter: board private structure
1541 **/
1542static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1543{
1544 struct e1000_ring *rx_ring = adapter->rx_ring;
1545 struct e1000_buffer *buffer_info;
1546 struct e1000_ps_page *ps_page;
1547 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001548 unsigned int i, j;
1549
1550 /* Free all the Rx ring sk_buffs */
1551 for (i = 0; i < rx_ring->count; i++) {
1552 buffer_info = &rx_ring->buffer_info[i];
1553 if (buffer_info->dma) {
1554 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001555 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001556 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001557 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001558 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001559 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001560 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001561 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001563 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001564 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001565 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001566 buffer_info->dma = 0;
1567 }
1568
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001569 if (buffer_info->page) {
1570 put_page(buffer_info->page);
1571 buffer_info->page = NULL;
1572 }
1573
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574 if (buffer_info->skb) {
1575 dev_kfree_skb(buffer_info->skb);
1576 buffer_info->skb = NULL;
1577 }
1578
1579 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001580 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001581 if (!ps_page->page)
1582 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001583 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1584 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585 ps_page->dma = 0;
1586 put_page(ps_page->page);
1587 ps_page->page = NULL;
1588 }
1589 }
1590
1591 /* there also may be some cached data from a chained receive */
1592 if (rx_ring->rx_skb_top) {
1593 dev_kfree_skb(rx_ring->rx_skb_top);
1594 rx_ring->rx_skb_top = NULL;
1595 }
1596
Auke Kokbc7f75f2007-09-17 12:30:59 -07001597 /* Zero out the descriptor ring */
1598 memset(rx_ring->desc, 0, rx_ring->size);
1599
1600 rx_ring->next_to_clean = 0;
1601 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001602 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001603
1604 writel(0, adapter->hw.hw_addr + rx_ring->head);
1605 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1606}
1607
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001608static void e1000e_downshift_workaround(struct work_struct *work)
1609{
1610 struct e1000_adapter *adapter = container_of(work,
1611 struct e1000_adapter, downshift_task);
1612
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001613 if (test_bit(__E1000_DOWN, &adapter->state))
1614 return;
1615
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001616 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1617}
1618
Auke Kokbc7f75f2007-09-17 12:30:59 -07001619/**
1620 * e1000_intr_msi - Interrupt Handler
1621 * @irq: interrupt number
1622 * @data: pointer to a network interface device structure
1623 **/
1624static irqreturn_t e1000_intr_msi(int irq, void *data)
1625{
1626 struct net_device *netdev = data;
1627 struct e1000_adapter *adapter = netdev_priv(netdev);
1628 struct e1000_hw *hw = &adapter->hw;
1629 u32 icr = er32(ICR);
1630
Bruce Allanad680762008-03-28 09:15:03 -07001631 /*
1632 * read ICR disables interrupts using IAM
1633 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634
dave graham573cca82009-02-10 12:52:05 +00001635 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001637 /*
1638 * ICH8 workaround-- Call gig speed drop workaround on cable
1639 * disconnect (LSC) before accessing any PHY registers
1640 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1642 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001643 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001644
Bruce Allanad680762008-03-28 09:15:03 -07001645 /*
1646 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001647 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001648 * adapter in watchdog
1649 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001650 if (netif_carrier_ok(netdev) &&
1651 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1652 /* disable receives */
1653 u32 rctl = er32(RCTL);
1654 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001655 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001656 }
1657 /* guard against interrupt when we're going down */
1658 if (!test_bit(__E1000_DOWN, &adapter->state))
1659 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1660 }
1661
Ben Hutchings288379f2009-01-19 16:43:59 -08001662 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001663 adapter->total_tx_bytes = 0;
1664 adapter->total_tx_packets = 0;
1665 adapter->total_rx_bytes = 0;
1666 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001667 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001668 }
1669
1670 return IRQ_HANDLED;
1671}
1672
1673/**
1674 * e1000_intr - Interrupt Handler
1675 * @irq: interrupt number
1676 * @data: pointer to a network interface device structure
1677 **/
1678static irqreturn_t e1000_intr(int irq, void *data)
1679{
1680 struct net_device *netdev = data;
1681 struct e1000_adapter *adapter = netdev_priv(netdev);
1682 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001683 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001684
Bruce Allana68ea772009-11-20 23:23:16 +00001685 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001686 return IRQ_NONE; /* Not our interrupt */
1687
Bruce Allanad680762008-03-28 09:15:03 -07001688 /*
1689 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1690 * not set, then the adapter didn't send an interrupt
1691 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001692 if (!(icr & E1000_ICR_INT_ASSERTED))
1693 return IRQ_NONE;
1694
Bruce Allanad680762008-03-28 09:15:03 -07001695 /*
1696 * Interrupt Auto-Mask...upon reading ICR,
1697 * interrupts are masked. No need for the
1698 * IMC write
1699 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001700
dave graham573cca82009-02-10 12:52:05 +00001701 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001702 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001703 /*
1704 * ICH8 workaround-- Call gig speed drop workaround on cable
1705 * disconnect (LSC) before accessing any PHY registers
1706 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1708 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001709 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001710
Bruce Allanad680762008-03-28 09:15:03 -07001711 /*
1712 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001713 * For packet buffer work-around on link down event;
1714 * disable receives here in the ISR and
1715 * reset adapter in watchdog
1716 */
1717 if (netif_carrier_ok(netdev) &&
1718 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1719 /* disable receives */
1720 rctl = er32(RCTL);
1721 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001722 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001723 }
1724 /* guard against interrupt when we're going down */
1725 if (!test_bit(__E1000_DOWN, &adapter->state))
1726 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1727 }
1728
Ben Hutchings288379f2009-01-19 16:43:59 -08001729 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001730 adapter->total_tx_bytes = 0;
1731 adapter->total_tx_packets = 0;
1732 adapter->total_rx_bytes = 0;
1733 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001734 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001735 }
1736
1737 return IRQ_HANDLED;
1738}
1739
Bruce Allan4662e822008-08-26 18:37:06 -07001740static irqreturn_t e1000_msix_other(int irq, void *data)
1741{
1742 struct net_device *netdev = data;
1743 struct e1000_adapter *adapter = netdev_priv(netdev);
1744 struct e1000_hw *hw = &adapter->hw;
1745 u32 icr = er32(ICR);
1746
1747 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001748 if (!test_bit(__E1000_DOWN, &adapter->state))
1749 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001750 return IRQ_NONE;
1751 }
1752
1753 if (icr & adapter->eiac_mask)
1754 ew32(ICS, (icr & adapter->eiac_mask));
1755
1756 if (icr & E1000_ICR_OTHER) {
1757 if (!(icr & E1000_ICR_LSC))
1758 goto no_link_interrupt;
1759 hw->mac.get_link_status = 1;
1760 /* guard against interrupt when we're going down */
1761 if (!test_bit(__E1000_DOWN, &adapter->state))
1762 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1763 }
1764
1765no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001766 if (!test_bit(__E1000_DOWN, &adapter->state))
1767 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001768
1769 return IRQ_HANDLED;
1770}
1771
1772
1773static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1774{
1775 struct net_device *netdev = data;
1776 struct e1000_adapter *adapter = netdev_priv(netdev);
1777 struct e1000_hw *hw = &adapter->hw;
1778 struct e1000_ring *tx_ring = adapter->tx_ring;
1779
1780
1781 adapter->total_tx_bytes = 0;
1782 adapter->total_tx_packets = 0;
1783
1784 if (!e1000_clean_tx_irq(adapter))
1785 /* Ring was not completely cleaned, so fire another interrupt */
1786 ew32(ICS, tx_ring->ims_val);
1787
1788 return IRQ_HANDLED;
1789}
1790
1791static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1792{
1793 struct net_device *netdev = data;
1794 struct e1000_adapter *adapter = netdev_priv(netdev);
1795
1796 /* Write the ITR value calculated at the end of the
1797 * previous interrupt.
1798 */
1799 if (adapter->rx_ring->set_itr) {
1800 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1801 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1802 adapter->rx_ring->set_itr = 0;
1803 }
1804
Ben Hutchings288379f2009-01-19 16:43:59 -08001805 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001806 adapter->total_rx_bytes = 0;
1807 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001808 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001809 }
1810 return IRQ_HANDLED;
1811}
1812
1813/**
1814 * e1000_configure_msix - Configure MSI-X hardware
1815 *
1816 * e1000_configure_msix sets up the hardware to properly
1817 * generate MSI-X interrupts.
1818 **/
1819static void e1000_configure_msix(struct e1000_adapter *adapter)
1820{
1821 struct e1000_hw *hw = &adapter->hw;
1822 struct e1000_ring *rx_ring = adapter->rx_ring;
1823 struct e1000_ring *tx_ring = adapter->tx_ring;
1824 int vector = 0;
1825 u32 ctrl_ext, ivar = 0;
1826
1827 adapter->eiac_mask = 0;
1828
1829 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1830 if (hw->mac.type == e1000_82574) {
1831 u32 rfctl = er32(RFCTL);
1832 rfctl |= E1000_RFCTL_ACK_DIS;
1833 ew32(RFCTL, rfctl);
1834 }
1835
1836#define E1000_IVAR_INT_ALLOC_VALID 0x8
1837 /* Configure Rx vector */
1838 rx_ring->ims_val = E1000_IMS_RXQ0;
1839 adapter->eiac_mask |= rx_ring->ims_val;
1840 if (rx_ring->itr_val)
1841 writel(1000000000 / (rx_ring->itr_val * 256),
1842 hw->hw_addr + rx_ring->itr_register);
1843 else
1844 writel(1, hw->hw_addr + rx_ring->itr_register);
1845 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1846
1847 /* Configure Tx vector */
1848 tx_ring->ims_val = E1000_IMS_TXQ0;
1849 vector++;
1850 if (tx_ring->itr_val)
1851 writel(1000000000 / (tx_ring->itr_val * 256),
1852 hw->hw_addr + tx_ring->itr_register);
1853 else
1854 writel(1, hw->hw_addr + tx_ring->itr_register);
1855 adapter->eiac_mask |= tx_ring->ims_val;
1856 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1857
1858 /* set vector for Other Causes, e.g. link changes */
1859 vector++;
1860 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1861 if (rx_ring->itr_val)
1862 writel(1000000000 / (rx_ring->itr_val * 256),
1863 hw->hw_addr + E1000_EITR_82574(vector));
1864 else
1865 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1866
1867 /* Cause Tx interrupts on every write back */
1868 ivar |= (1 << 31);
1869
1870 ew32(IVAR, ivar);
1871
1872 /* enable MSI-X PBA support */
1873 ctrl_ext = er32(CTRL_EXT);
1874 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1875
1876 /* Auto-Mask Other interrupts upon ICR read */
1877#define E1000_EIAC_MASK_82574 0x01F00000
1878 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1879 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1880 ew32(CTRL_EXT, ctrl_ext);
1881 e1e_flush();
1882}
1883
1884void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1885{
1886 if (adapter->msix_entries) {
1887 pci_disable_msix(adapter->pdev);
1888 kfree(adapter->msix_entries);
1889 adapter->msix_entries = NULL;
1890 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1891 pci_disable_msi(adapter->pdev);
1892 adapter->flags &= ~FLAG_MSI_ENABLED;
1893 }
Bruce Allan4662e822008-08-26 18:37:06 -07001894}
1895
1896/**
1897 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1898 *
1899 * Attempt to configure interrupts using the best available
1900 * capabilities of the hardware and kernel.
1901 **/
1902void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1903{
1904 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001905 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001906
1907 switch (adapter->int_mode) {
1908 case E1000E_INT_MODE_MSIX:
1909 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001910 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1911 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001912 sizeof(struct msix_entry),
1913 GFP_KERNEL);
1914 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001915 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001916 adapter->msix_entries[i].entry = i;
1917
1918 err = pci_enable_msix(adapter->pdev,
1919 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001920 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001921 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001922 return;
1923 }
1924 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00001925 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001926 e1000e_reset_interrupt_capability(adapter);
1927 }
1928 adapter->int_mode = E1000E_INT_MODE_MSI;
1929 /* Fall through */
1930 case E1000E_INT_MODE_MSI:
1931 if (!pci_enable_msi(adapter->pdev)) {
1932 adapter->flags |= FLAG_MSI_ENABLED;
1933 } else {
1934 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00001935 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001936 }
1937 /* Fall through */
1938 case E1000E_INT_MODE_LEGACY:
1939 /* Don't do anything; this is the system default */
1940 break;
1941 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001942
1943 /* store the number of vectors being used */
1944 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001945}
1946
1947/**
1948 * e1000_request_msix - Initialize MSI-X interrupts
1949 *
1950 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1951 * kernel.
1952 **/
1953static int e1000_request_msix(struct e1000_adapter *adapter)
1954{
1955 struct net_device *netdev = adapter->netdev;
1956 int err = 0, vector = 0;
1957
1958 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001959 snprintf(adapter->rx_ring->name,
1960 sizeof(adapter->rx_ring->name) - 1,
1961 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001962 else
1963 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1964 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001965 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001966 netdev);
1967 if (err)
1968 goto out;
1969 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1970 adapter->rx_ring->itr_val = adapter->itr;
1971 vector++;
1972
1973 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001974 snprintf(adapter->tx_ring->name,
1975 sizeof(adapter->tx_ring->name) - 1,
1976 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001977 else
1978 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1979 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001980 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001981 netdev);
1982 if (err)
1983 goto out;
1984 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1985 adapter->tx_ring->itr_val = adapter->itr;
1986 vector++;
1987
1988 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001989 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001990 if (err)
1991 goto out;
1992
1993 e1000_configure_msix(adapter);
1994 return 0;
1995out:
1996 return err;
1997}
1998
Bruce Allanf8d59f72008-08-08 18:36:11 -07001999/**
2000 * e1000_request_irq - initialize interrupts
2001 *
2002 * Attempts to configure interrupts using the best available
2003 * capabilities of the hardware and kernel.
2004 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002005static int e1000_request_irq(struct e1000_adapter *adapter)
2006{
2007 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002008 int err;
2009
Bruce Allan4662e822008-08-26 18:37:06 -07002010 if (adapter->msix_entries) {
2011 err = e1000_request_msix(adapter);
2012 if (!err)
2013 return err;
2014 /* fall back to MSI */
2015 e1000e_reset_interrupt_capability(adapter);
2016 adapter->int_mode = E1000E_INT_MODE_MSI;
2017 e1000e_set_interrupt_capability(adapter);
2018 }
2019 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002020 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002021 netdev->name, netdev);
2022 if (!err)
2023 return err;
2024
2025 /* fall back to legacy interrupt */
2026 e1000e_reset_interrupt_capability(adapter);
2027 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002028 }
2029
Joe Perchesa0607fd2009-11-18 23:29:17 -08002030 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002031 netdev->name, netdev);
2032 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002033 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002034
2035 return err;
2036}
2037
2038static void e1000_free_irq(struct e1000_adapter *adapter)
2039{
2040 struct net_device *netdev = adapter->netdev;
2041
Bruce Allan4662e822008-08-26 18:37:06 -07002042 if (adapter->msix_entries) {
2043 int vector = 0;
2044
2045 free_irq(adapter->msix_entries[vector].vector, netdev);
2046 vector++;
2047
2048 free_irq(adapter->msix_entries[vector].vector, netdev);
2049 vector++;
2050
2051 /* Other Causes interrupt vector */
2052 free_irq(adapter->msix_entries[vector].vector, netdev);
2053 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002054 }
Bruce Allan4662e822008-08-26 18:37:06 -07002055
2056 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002057}
2058
2059/**
2060 * e1000_irq_disable - Mask off interrupt generation on the NIC
2061 **/
2062static void e1000_irq_disable(struct e1000_adapter *adapter)
2063{
2064 struct e1000_hw *hw = &adapter->hw;
2065
Auke Kokbc7f75f2007-09-17 12:30:59 -07002066 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002067 if (adapter->msix_entries)
2068 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002069 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002070
2071 if (adapter->msix_entries) {
2072 int i;
2073 for (i = 0; i < adapter->num_vectors; i++)
2074 synchronize_irq(adapter->msix_entries[i].vector);
2075 } else {
2076 synchronize_irq(adapter->pdev->irq);
2077 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002078}
2079
2080/**
2081 * e1000_irq_enable - Enable default interrupt generation settings
2082 **/
2083static void e1000_irq_enable(struct e1000_adapter *adapter)
2084{
2085 struct e1000_hw *hw = &adapter->hw;
2086
Bruce Allan4662e822008-08-26 18:37:06 -07002087 if (adapter->msix_entries) {
2088 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2089 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2090 } else {
2091 ew32(IMS, IMS_ENABLE_MASK);
2092 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002093 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002094}
2095
2096/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002097 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002098 * @adapter: address of board private structure
2099 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002100 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002101 * For ASF and Pass Through versions of f/w this means that
2102 * the driver is loaded. For AMT version (only with 82573)
2103 * of the f/w this means that the network i/f is open.
2104 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002105void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002106{
2107 struct e1000_hw *hw = &adapter->hw;
2108 u32 ctrl_ext;
2109 u32 swsm;
2110
2111 /* Let firmware know the driver has taken over */
2112 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2113 swsm = er32(SWSM);
2114 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2115 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2116 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002117 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002118 }
2119}
2120
2121/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002122 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002123 * @adapter: address of board private structure
2124 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002125 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002126 * For ASF and Pass Through versions of f/w this means that the
2127 * driver is no longer loaded. For AMT version (only with 82573) i
2128 * of the f/w this means that the network i/f is closed.
2129 *
2130 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002131void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002132{
2133 struct e1000_hw *hw = &adapter->hw;
2134 u32 ctrl_ext;
2135 u32 swsm;
2136
2137 /* Let firmware taken over control of h/w */
2138 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2139 swsm = er32(SWSM);
2140 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2141 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2142 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002143 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002144 }
2145}
2146
Auke Kokbc7f75f2007-09-17 12:30:59 -07002147/**
2148 * @e1000_alloc_ring - allocate memory for a ring structure
2149 **/
2150static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2151 struct e1000_ring *ring)
2152{
2153 struct pci_dev *pdev = adapter->pdev;
2154
2155 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2156 GFP_KERNEL);
2157 if (!ring->desc)
2158 return -ENOMEM;
2159
2160 return 0;
2161}
2162
2163/**
2164 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2165 * @adapter: board private structure
2166 *
2167 * Return 0 on success, negative on failure
2168 **/
2169int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2170{
2171 struct e1000_ring *tx_ring = adapter->tx_ring;
2172 int err = -ENOMEM, size;
2173
2174 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002175 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002176 if (!tx_ring->buffer_info)
2177 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002178
2179 /* round up to nearest 4K */
2180 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2181 tx_ring->size = ALIGN(tx_ring->size, 4096);
2182
2183 err = e1000_alloc_ring_dma(adapter, tx_ring);
2184 if (err)
2185 goto err;
2186
2187 tx_ring->next_to_use = 0;
2188 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002189
2190 return 0;
2191err:
2192 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002193 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002194 return err;
2195}
2196
2197/**
2198 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2199 * @adapter: board private structure
2200 *
2201 * Returns 0 on success, negative on failure
2202 **/
2203int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2204{
2205 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002206 struct e1000_buffer *buffer_info;
2207 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002208
2209 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002210 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002211 if (!rx_ring->buffer_info)
2212 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002213
Auke Kok47f44e42007-10-25 13:57:44 -07002214 for (i = 0; i < rx_ring->count; i++) {
2215 buffer_info = &rx_ring->buffer_info[i];
2216 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2217 sizeof(struct e1000_ps_page),
2218 GFP_KERNEL);
2219 if (!buffer_info->ps_pages)
2220 goto err_pages;
2221 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002222
2223 desc_len = sizeof(union e1000_rx_desc_packet_split);
2224
2225 /* Round up to nearest 4K */
2226 rx_ring->size = rx_ring->count * desc_len;
2227 rx_ring->size = ALIGN(rx_ring->size, 4096);
2228
2229 err = e1000_alloc_ring_dma(adapter, rx_ring);
2230 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002231 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002232
2233 rx_ring->next_to_clean = 0;
2234 rx_ring->next_to_use = 0;
2235 rx_ring->rx_skb_top = NULL;
2236
2237 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002238
2239err_pages:
2240 for (i = 0; i < rx_ring->count; i++) {
2241 buffer_info = &rx_ring->buffer_info[i];
2242 kfree(buffer_info->ps_pages);
2243 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244err:
2245 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002246 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002247 return err;
2248}
2249
2250/**
2251 * e1000_clean_tx_ring - Free Tx Buffers
2252 * @adapter: board private structure
2253 **/
2254static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2255{
2256 struct e1000_ring *tx_ring = adapter->tx_ring;
2257 struct e1000_buffer *buffer_info;
2258 unsigned long size;
2259 unsigned int i;
2260
2261 for (i = 0; i < tx_ring->count; i++) {
2262 buffer_info = &tx_ring->buffer_info[i];
2263 e1000_put_txbuf(adapter, buffer_info);
2264 }
2265
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002266 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002267 size = sizeof(struct e1000_buffer) * tx_ring->count;
2268 memset(tx_ring->buffer_info, 0, size);
2269
2270 memset(tx_ring->desc, 0, tx_ring->size);
2271
2272 tx_ring->next_to_use = 0;
2273 tx_ring->next_to_clean = 0;
2274
2275 writel(0, adapter->hw.hw_addr + tx_ring->head);
2276 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2277}
2278
2279/**
2280 * e1000e_free_tx_resources - Free Tx Resources per Queue
2281 * @adapter: board private structure
2282 *
2283 * Free all transmit software resources
2284 **/
2285void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2286{
2287 struct pci_dev *pdev = adapter->pdev;
2288 struct e1000_ring *tx_ring = adapter->tx_ring;
2289
2290 e1000_clean_tx_ring(adapter);
2291
2292 vfree(tx_ring->buffer_info);
2293 tx_ring->buffer_info = NULL;
2294
2295 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2296 tx_ring->dma);
2297 tx_ring->desc = NULL;
2298}
2299
2300/**
2301 * e1000e_free_rx_resources - Free Rx Resources
2302 * @adapter: board private structure
2303 *
2304 * Free all receive software resources
2305 **/
2306
2307void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2308{
2309 struct pci_dev *pdev = adapter->pdev;
2310 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002311 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002312
2313 e1000_clean_rx_ring(adapter);
2314
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002315 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002316 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002317
Auke Kokbc7f75f2007-09-17 12:30:59 -07002318 vfree(rx_ring->buffer_info);
2319 rx_ring->buffer_info = NULL;
2320
Auke Kokbc7f75f2007-09-17 12:30:59 -07002321 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2322 rx_ring->dma);
2323 rx_ring->desc = NULL;
2324}
2325
2326/**
2327 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002328 * @adapter: pointer to adapter
2329 * @itr_setting: current adapter->itr
2330 * @packets: the number of packets during this measurement interval
2331 * @bytes: the number of bytes during this measurement interval
2332 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333 * Stores a new ITR value based on packets and byte
2334 * counts during the last interrupt. The advantage of per interrupt
2335 * computation is faster updates and more accurate ITR for the current
2336 * traffic pattern. Constants in this function were computed
2337 * based on theoretical maximum wire speed and thresholds were set based
2338 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002339 * while increasing bulk throughput. This functionality is controlled
2340 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341 **/
2342static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2343 u16 itr_setting, int packets,
2344 int bytes)
2345{
2346 unsigned int retval = itr_setting;
2347
2348 if (packets == 0)
2349 goto update_itr_done;
2350
2351 switch (itr_setting) {
2352 case lowest_latency:
2353 /* handle TSO and jumbo frames */
2354 if (bytes/packets > 8000)
2355 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002356 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002357 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002358 break;
2359 case low_latency: /* 50 usec aka 20000 ints/s */
2360 if (bytes > 10000) {
2361 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002362 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002363 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002364 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002366 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002367 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002368 } else if (bytes/packets > 2000) {
2369 retval = bulk_latency;
2370 } else if (packets <= 2 && bytes < 512) {
2371 retval = lowest_latency;
2372 }
2373 break;
2374 case bulk_latency: /* 250 usec aka 4000 ints/s */
2375 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002376 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002377 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378 } else if (bytes < 6000) {
2379 retval = low_latency;
2380 }
2381 break;
2382 }
2383
2384update_itr_done:
2385 return retval;
2386}
2387
2388static void e1000_set_itr(struct e1000_adapter *adapter)
2389{
2390 struct e1000_hw *hw = &adapter->hw;
2391 u16 current_itr;
2392 u32 new_itr = adapter->itr;
2393
2394 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2395 if (adapter->link_speed != SPEED_1000) {
2396 current_itr = 0;
2397 new_itr = 4000;
2398 goto set_itr_now;
2399 }
2400
Bruce Allan828bac82010-09-29 21:39:37 +00002401 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2402 new_itr = 0;
2403 goto set_itr_now;
2404 }
2405
Auke Kokbc7f75f2007-09-17 12:30:59 -07002406 adapter->tx_itr = e1000_update_itr(adapter,
2407 adapter->tx_itr,
2408 adapter->total_tx_packets,
2409 adapter->total_tx_bytes);
2410 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2411 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2412 adapter->tx_itr = low_latency;
2413
2414 adapter->rx_itr = e1000_update_itr(adapter,
2415 adapter->rx_itr,
2416 adapter->total_rx_packets,
2417 adapter->total_rx_bytes);
2418 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2419 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2420 adapter->rx_itr = low_latency;
2421
2422 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2423
2424 switch (current_itr) {
2425 /* counts and packets in update_itr are dependent on these numbers */
2426 case lowest_latency:
2427 new_itr = 70000;
2428 break;
2429 case low_latency:
2430 new_itr = 20000; /* aka hwitr = ~200 */
2431 break;
2432 case bulk_latency:
2433 new_itr = 4000;
2434 break;
2435 default:
2436 break;
2437 }
2438
2439set_itr_now:
2440 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002441 /*
2442 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002443 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002444 * increasing
2445 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446 new_itr = new_itr > adapter->itr ?
2447 min(adapter->itr + (new_itr >> 2), new_itr) :
2448 new_itr;
2449 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002450 adapter->rx_ring->itr_val = new_itr;
2451 if (adapter->msix_entries)
2452 adapter->rx_ring->set_itr = 1;
2453 else
Bruce Allan828bac82010-09-29 21:39:37 +00002454 if (new_itr)
2455 ew32(ITR, 1000000000 / (new_itr * 256));
2456 else
2457 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002458 }
2459}
2460
2461/**
Bruce Allan4662e822008-08-26 18:37:06 -07002462 * e1000_alloc_queues - Allocate memory for all rings
2463 * @adapter: board private structure to initialize
2464 **/
2465static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2466{
2467 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2468 if (!adapter->tx_ring)
2469 goto err;
2470
2471 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2472 if (!adapter->rx_ring)
2473 goto err;
2474
2475 return 0;
2476err:
2477 e_err("Unable to allocate memory for queues\n");
2478 kfree(adapter->rx_ring);
2479 kfree(adapter->tx_ring);
2480 return -ENOMEM;
2481}
2482
2483/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002484 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002485 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002486 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002487 **/
2488static int e1000_clean(struct napi_struct *napi, int budget)
2489{
2490 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002491 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002492 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002493 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002494
Wang Chen4cf16532008-11-12 23:38:14 -08002495 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002496
Bruce Allan4662e822008-08-26 18:37:06 -07002497 if (adapter->msix_entries &&
2498 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2499 goto clean_rx;
2500
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002501 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502
Bruce Allan4662e822008-08-26 18:37:06 -07002503clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002504 adapter->clean_rx(adapter, &work_done, budget);
2505
Alexander Duyck12d04a32009-03-25 22:05:03 +00002506 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002507 work_done = budget;
2508
David S. Miller53e52c72008-01-07 21:06:12 -08002509 /* If budget not fully consumed, exit the polling mode */
2510 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002511 if (adapter->itr_setting & 3)
2512 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002513 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002514 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2515 if (adapter->msix_entries)
2516 ew32(IMS, adapter->rx_ring->ims_val);
2517 else
2518 e1000_irq_enable(adapter);
2519 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520 }
2521
2522 return work_done;
2523}
2524
Jiri Pirko8e586132011-12-08 19:52:37 -05002525static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526{
2527 struct e1000_adapter *adapter = netdev_priv(netdev);
2528 struct e1000_hw *hw = &adapter->hw;
2529 u32 vfta, index;
2530
2531 /* don't update vlan cookie if already programmed */
2532 if ((adapter->hw.mng_cookie.status &
2533 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2534 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002535 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002536
Auke Kokbc7f75f2007-09-17 12:30:59 -07002537 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002538 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2539 index = (vid >> 5) & 0x7F;
2540 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2541 vfta |= (1 << (vid & 0x1F));
2542 hw->mac.ops.write_vfta(hw, index, vfta);
2543 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002544
2545 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002546
2547 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002548}
2549
Jiri Pirko8e586132011-12-08 19:52:37 -05002550static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002551{
2552 struct e1000_adapter *adapter = netdev_priv(netdev);
2553 struct e1000_hw *hw = &adapter->hw;
2554 u32 vfta, index;
2555
Auke Kokbc7f75f2007-09-17 12:30:59 -07002556 if ((adapter->hw.mng_cookie.status &
2557 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2558 (vid == adapter->mng_vlan_id)) {
2559 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002560 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002561 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002562 }
2563
2564 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002565 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2566 index = (vid >> 5) & 0x7F;
2567 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2568 vfta &= ~(1 << (vid & 0x1F));
2569 hw->mac.ops.write_vfta(hw, index, vfta);
2570 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002571
2572 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002573
2574 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002575}
2576
2577/**
2578 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2579 * @adapter: board private structure to initialize
2580 **/
2581static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2582{
2583 struct net_device *netdev = adapter->netdev;
2584 struct e1000_hw *hw = &adapter->hw;
2585 u32 rctl;
2586
2587 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2588 /* disable VLAN receive filtering */
2589 rctl = er32(RCTL);
2590 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2591 ew32(RCTL, rctl);
2592
2593 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2594 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2595 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2596 }
2597 }
2598}
2599
2600/**
2601 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2602 * @adapter: board private structure to initialize
2603 **/
2604static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2605{
2606 struct e1000_hw *hw = &adapter->hw;
2607 u32 rctl;
2608
2609 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2610 /* enable VLAN receive filtering */
2611 rctl = er32(RCTL);
2612 rctl |= E1000_RCTL_VFE;
2613 rctl &= ~E1000_RCTL_CFIEN;
2614 ew32(RCTL, rctl);
2615 }
2616}
2617
2618/**
2619 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2620 * @adapter: board private structure to initialize
2621 **/
2622static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2623{
2624 struct e1000_hw *hw = &adapter->hw;
2625 u32 ctrl;
2626
2627 /* disable VLAN tag insert/strip */
2628 ctrl = er32(CTRL);
2629 ctrl &= ~E1000_CTRL_VME;
2630 ew32(CTRL, ctrl);
2631}
2632
2633/**
2634 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2635 * @adapter: board private structure to initialize
2636 **/
2637static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2638{
2639 struct e1000_hw *hw = &adapter->hw;
2640 u32 ctrl;
2641
2642 /* enable VLAN tag insert/strip */
2643 ctrl = er32(CTRL);
2644 ctrl |= E1000_CTRL_VME;
2645 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002646}
2647
2648static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2649{
2650 struct net_device *netdev = adapter->netdev;
2651 u16 vid = adapter->hw.mng_cookie.vlan_id;
2652 u16 old_vid = adapter->mng_vlan_id;
2653
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002654 if (adapter->hw.mng_cookie.status &
2655 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2656 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002657 adapter->mng_vlan_id = vid;
2658 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002659
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002660 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2661 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002662}
2663
2664static void e1000_restore_vlan(struct e1000_adapter *adapter)
2665{
2666 u16 vid;
2667
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002668 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002669
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002670 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002671 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002672}
2673
Bruce Allancd791612010-05-10 14:59:51 +00002674static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002675{
2676 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002677 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002678
2679 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2680 return;
2681
2682 manc = er32(MANC);
2683
Bruce Allanad680762008-03-28 09:15:03 -07002684 /*
2685 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002686 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002687 * the packets will be handled on SMBUS
2688 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002689 manc |= E1000_MANC_EN_MNG2HOST;
2690 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002691
2692 switch (hw->mac.type) {
2693 default:
2694 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2695 break;
2696 case e1000_82574:
2697 case e1000_82583:
2698 /*
2699 * Check if IPMI pass-through decision filter already exists;
2700 * if so, enable it.
2701 */
2702 for (i = 0, j = 0; i < 8; i++) {
2703 mdef = er32(MDEF(i));
2704
2705 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002706 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002707 continue;
2708
2709 /* Enable this decision filter in MANC2H */
2710 if (mdef)
2711 manc2h |= (1 << i);
2712
2713 j |= mdef;
2714 }
2715
2716 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2717 break;
2718
2719 /* Create new decision filter in an empty filter */
2720 for (i = 0, j = 0; i < 8; i++)
2721 if (er32(MDEF(i)) == 0) {
2722 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2723 E1000_MDEF_PORT_664));
2724 manc2h |= (1 << 1);
2725 j++;
2726 break;
2727 }
2728
2729 if (!j)
2730 e_warn("Unable to create IPMI pass-through filter\n");
2731 break;
2732 }
2733
Auke Kokbc7f75f2007-09-17 12:30:59 -07002734 ew32(MANC2H, manc2h);
2735 ew32(MANC, manc);
2736}
2737
2738/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002739 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002740 * @adapter: board private structure
2741 *
2742 * Configure the Tx unit of the MAC after a reset.
2743 **/
2744static void e1000_configure_tx(struct e1000_adapter *adapter)
2745{
2746 struct e1000_hw *hw = &adapter->hw;
2747 struct e1000_ring *tx_ring = adapter->tx_ring;
2748 u64 tdba;
2749 u32 tdlen, tctl, tipg, tarc;
2750 u32 ipgr1, ipgr2;
2751
2752 /* Setup the HW Tx Head and Tail descriptor pointers */
2753 tdba = tx_ring->dma;
2754 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002755 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002756 ew32(TDBAH, (tdba >> 32));
2757 ew32(TDLEN, tdlen);
2758 ew32(TDH, 0);
2759 ew32(TDT, 0);
2760 tx_ring->head = E1000_TDH;
2761 tx_ring->tail = E1000_TDT;
2762
2763 /* Set the default values for the Tx Inter Packet Gap timer */
2764 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2765 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2766 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2767
2768 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2769 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2770
2771 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2772 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2773 ew32(TIPG, tipg);
2774
2775 /* Set the Tx Interrupt Delay register */
2776 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002777 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002778 ew32(TADV, adapter->tx_abs_int_delay);
2779
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002780 if (adapter->flags2 & FLAG2_DMA_BURST) {
2781 u32 txdctl = er32(TXDCTL(0));
2782 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2783 E1000_TXDCTL_WTHRESH);
2784 /*
2785 * set up some performance related parameters to encourage the
2786 * hardware to use the bus more efficiently in bursts, depends
2787 * on the tx_int_delay to be enabled,
2788 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2789 * hthresh = 1 ==> prefetch when one or more available
2790 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2791 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002792 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002793 */
2794 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2795 ew32(TXDCTL(0), txdctl);
2796 /* erratum work around: set txdctl the same for both queues */
2797 ew32(TXDCTL(1), txdctl);
2798 }
2799
Auke Kokbc7f75f2007-09-17 12:30:59 -07002800 /* Program the Transmit Control Register */
2801 tctl = er32(TCTL);
2802 tctl &= ~E1000_TCTL_CT;
2803 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2804 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2805
2806 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002807 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002808 /*
2809 * set the speed mode bit, we'll clear it if we're not at
2810 * gigabit link later
2811 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002812#define SPEED_MODE_BIT (1 << 21)
2813 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002814 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815 }
2816
2817 /* errata: program both queues to unweighted RR */
2818 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002819 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002820 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002821 ew32(TARC(0), tarc);
2822 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002823 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002824 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002825 }
2826
Auke Kokbc7f75f2007-09-17 12:30:59 -07002827 /* Setup Transmit Descriptor Settings for eop descriptor */
2828 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2829
2830 /* only set IDE if we are delaying interrupts using the timers */
2831 if (adapter->tx_int_delay)
2832 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2833
2834 /* enable Report Status bit */
2835 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2836
2837 ew32(TCTL, tctl);
2838
Simon Hormanedfea6e62009-06-08 14:28:36 +00002839 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002840}
2841
2842/**
2843 * e1000_setup_rctl - configure the receive control registers
2844 * @adapter: Board private structure
2845 **/
2846#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2847 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2848static void e1000_setup_rctl(struct e1000_adapter *adapter)
2849{
2850 struct e1000_hw *hw = &adapter->hw;
2851 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002852 u32 pages = 0;
2853
Bruce Allana1ce6472010-09-22 17:16:40 +00002854 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2855 if (hw->mac.type == e1000_pch2lan) {
2856 s32 ret_val;
2857
2858 if (adapter->netdev->mtu > ETH_DATA_LEN)
2859 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2860 else
2861 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002862
2863 if (ret_val)
2864 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002865 }
2866
Auke Kokbc7f75f2007-09-17 12:30:59 -07002867 /* Program MC offset vector base */
2868 rctl = er32(RCTL);
2869 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2870 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2871 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2872 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2873
2874 /* Do not Store bad packets */
2875 rctl &= ~E1000_RCTL_SBP;
2876
2877 /* Enable Long Packet receive */
2878 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2879 rctl &= ~E1000_RCTL_LPE;
2880 else
2881 rctl |= E1000_RCTL_LPE;
2882
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002883 /* Some systems expect that the CRC is included in SMBUS traffic. The
2884 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2885 * host memory when this is enabled
2886 */
2887 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2888 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002889
Bruce Allana4f58f52009-06-02 11:29:18 +00002890 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2891 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2892 u16 phy_data;
2893
2894 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2895 phy_data &= 0xfff8;
2896 phy_data |= (1 << 2);
2897 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2898
2899 e1e_rphy(hw, 22, &phy_data);
2900 phy_data &= 0x0fff;
2901 phy_data |= (1 << 14);
2902 e1e_wphy(hw, 0x10, 0x2823);
2903 e1e_wphy(hw, 0x11, 0x0003);
2904 e1e_wphy(hw, 22, phy_data);
2905 }
2906
Auke Kokbc7f75f2007-09-17 12:30:59 -07002907 /* Setup buffer sizes */
2908 rctl &= ~E1000_RCTL_SZ_4096;
2909 rctl |= E1000_RCTL_BSEX;
2910 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002911 case 2048:
2912 default:
2913 rctl |= E1000_RCTL_SZ_2048;
2914 rctl &= ~E1000_RCTL_BSEX;
2915 break;
2916 case 4096:
2917 rctl |= E1000_RCTL_SZ_4096;
2918 break;
2919 case 8192:
2920 rctl |= E1000_RCTL_SZ_8192;
2921 break;
2922 case 16384:
2923 rctl |= E1000_RCTL_SZ_16384;
2924 break;
2925 }
2926
Bruce Allan5f450212011-07-22 06:21:46 +00002927 /* Enable Extended Status in all Receive Descriptors */
2928 rfctl = er32(RFCTL);
2929 rfctl |= E1000_RFCTL_EXTEN;
2930
Auke Kokbc7f75f2007-09-17 12:30:59 -07002931 /*
2932 * 82571 and greater support packet-split where the protocol
2933 * header is placed in skb->data and the packet data is
2934 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2935 * In the case of a non-split, skb->data is linearly filled,
2936 * followed by the page buffers. Therefore, skb->data is
2937 * sized to hold the largest protocol header.
2938 *
2939 * allocations using alloc_page take too long for regular MTU
2940 * so only enable packet split for jumbo frames
2941 *
2942 * Using pages when the page size is greater than 16k wastes
2943 * a lot of memory, since we allocate 3 pages at all times
2944 * per packet.
2945 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fe2010-06-17 18:59:27 +00002947 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002948 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002949 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002950 else
2951 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002952
2953 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002954 u32 psrctl = 0;
2955
Bruce Allanad680762008-03-28 09:15:03 -07002956 /*
2957 * disable packet split support for IPv6 extension headers,
2958 * because some malformed IPv6 headers can hang the Rx
2959 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002960 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2961 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2962
Auke Kok140a7482007-10-25 13:57:58 -07002963 /* Enable Packet split descriptors */
2964 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002965
2966 psrctl |= adapter->rx_ps_bsize0 >>
2967 E1000_PSRCTL_BSIZE0_SHIFT;
2968
2969 switch (adapter->rx_ps_pages) {
2970 case 3:
2971 psrctl |= PAGE_SIZE <<
2972 E1000_PSRCTL_BSIZE3_SHIFT;
2973 case 2:
2974 psrctl |= PAGE_SIZE <<
2975 E1000_PSRCTL_BSIZE2_SHIFT;
2976 case 1:
2977 psrctl |= PAGE_SIZE >>
2978 E1000_PSRCTL_BSIZE1_SHIFT;
2979 break;
2980 }
2981
2982 ew32(PSRCTL, psrctl);
2983 }
2984
Bruce Allan5f450212011-07-22 06:21:46 +00002985 ew32(RFCTL, rfctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002986 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002987 /* just started the receive unit, no need to restart */
2988 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002989}
2990
2991/**
2992 * e1000_configure_rx - Configure Receive Unit after Reset
2993 * @adapter: board private structure
2994 *
2995 * Configure the Rx unit of the MAC after a reset.
2996 **/
2997static void e1000_configure_rx(struct e1000_adapter *adapter)
2998{
2999 struct e1000_hw *hw = &adapter->hw;
3000 struct e1000_ring *rx_ring = adapter->rx_ring;
3001 u64 rdba;
3002 u32 rdlen, rctl, rxcsum, ctrl_ext;
3003
3004 if (adapter->rx_ps_pages) {
3005 /* this is a 32 byte descriptor */
3006 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003007 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003008 adapter->clean_rx = e1000_clean_rx_irq_ps;
3009 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003010 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003011 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003012 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3013 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003014 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003015 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003016 adapter->clean_rx = e1000_clean_rx_irq;
3017 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3018 }
3019
3020 /* disable receives while setting up the descriptors */
3021 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003022 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3023 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003024 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003025 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003026
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003027 if (adapter->flags2 & FLAG2_DMA_BURST) {
3028 /*
3029 * set the writeback threshold (only takes effect if the RDTR
3030 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003031 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003032 * granularity = 01
3033 * wthresh = 04,
3034 * hthresh = 04,
3035 * pthresh = 0x20
3036 */
3037 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3038 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3039
3040 /*
3041 * override the delay timers for enabling bursting, only if
3042 * the value was not set by the user via module options
3043 */
3044 if (adapter->rx_int_delay == DEFAULT_RDTR)
3045 adapter->rx_int_delay = BURST_RDTR;
3046 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3047 adapter->rx_abs_int_delay = BURST_RADV;
3048 }
3049
Auke Kokbc7f75f2007-09-17 12:30:59 -07003050 /* set the Receive Delay Timer Register */
3051 ew32(RDTR, adapter->rx_int_delay);
3052
3053 /* irq moderation */
3054 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003055 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003056 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003057
3058 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003059 /* Auto-Mask interrupts upon ICR access */
3060 ctrl_ext |= E1000_CTRL_EXT_IAME;
3061 ew32(IAM, 0xffffffff);
3062 ew32(CTRL_EXT, ctrl_ext);
3063 e1e_flush();
3064
Bruce Allanad680762008-03-28 09:15:03 -07003065 /*
3066 * Setup the HW Rx Head and Tail Descriptor Pointers and
3067 * the Base and Length of the Rx Descriptor Ring
3068 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003069 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07003070 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003071 ew32(RDBAH, (rdba >> 32));
3072 ew32(RDLEN, rdlen);
3073 ew32(RDH, 0);
3074 ew32(RDT, 0);
3075 rx_ring->head = E1000_RDH;
3076 rx_ring->tail = E1000_RDT;
3077
3078 /* Enable Receive Checksum Offload for TCP and UDP */
3079 rxcsum = er32(RXCSUM);
Bruce Allandc221292011-08-19 03:23:48 +00003080 if (adapter->netdev->features & NETIF_F_RXCSUM) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081 rxcsum |= E1000_RXCSUM_TUOFL;
3082
Bruce Allanad680762008-03-28 09:15:03 -07003083 /*
3084 * IPv4 payload checksum for UDP fragments must be
3085 * used in conjunction with packet-split.
3086 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003087 if (adapter->rx_ps_pages)
3088 rxcsum |= E1000_RXCSUM_IPPCSE;
3089 } else {
3090 rxcsum &= ~E1000_RXCSUM_TUOFL;
3091 /* no need to clear IPPCSE as it defaults to 0 */
3092 }
3093 ew32(RXCSUM, rxcsum);
3094
Bruce Allanad680762008-03-28 09:15:03 -07003095 /*
3096 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07003097 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07003098 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
3099 */
Bruce Allan828bac82010-09-29 21:39:37 +00003100 if ((adapter->flags & FLAG_HAS_ERT) ||
3101 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003102 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3103 u32 rxdctl = er32(RXDCTL(0));
3104 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00003105 if (adapter->flags & FLAG_HAS_ERT)
3106 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00003107 /*
3108 * With jumbo frames and early-receive enabled,
3109 * excessive C-state transition latencies result in
3110 * dropped transactions.
3111 */
Bruce Allanaf667a22010-12-31 06:10:01 +00003112 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003113 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003114 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3115 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003116 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003117 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003118
3119 /* Enable Receives */
3120 ew32(RCTL, rctl);
3121}
3122
3123/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003124 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003125 * @netdev: network interface device structure
3126 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003127 * Writes multicast address list to the MTA hash table.
3128 * Returns: -ENOMEM on failure
3129 * 0 on no addresses written
3130 * X on writing X addresses to MTA
3131 */
3132static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003133{
3134 struct e1000_adapter *adapter = netdev_priv(netdev);
3135 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad2010-04-01 21:22:57 +00003136 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003137 u8 *mta_list;
3138 int i;
3139
3140 if (netdev_mc_empty(netdev)) {
3141 /* nothing to program, so clear mc list */
3142 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3143 return 0;
3144 }
3145
3146 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3147 if (!mta_list)
3148 return -ENOMEM;
3149
3150 /* update_mc_addr_list expects a packed array of only addresses. */
3151 i = 0;
3152 netdev_for_each_mc_addr(ha, netdev)
3153 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3154
3155 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3156 kfree(mta_list);
3157
3158 return netdev_mc_count(netdev);
3159}
3160
3161/**
3162 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3163 * @netdev: network interface device structure
3164 *
3165 * Writes unicast address list to the RAR table.
3166 * Returns: -ENOMEM on failure/insufficient address space
3167 * 0 on no addresses written
3168 * X on writing X addresses to the RAR table
3169 **/
3170static int e1000e_write_uc_addr_list(struct net_device *netdev)
3171{
3172 struct e1000_adapter *adapter = netdev_priv(netdev);
3173 struct e1000_hw *hw = &adapter->hw;
3174 unsigned int rar_entries = hw->mac.rar_entry_count;
3175 int count = 0;
3176
3177 /* save a rar entry for our hardware address */
3178 rar_entries--;
3179
3180 /* save a rar entry for the LAA workaround */
3181 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3182 rar_entries--;
3183
3184 /* return ENOMEM indicating insufficient memory for addresses */
3185 if (netdev_uc_count(netdev) > rar_entries)
3186 return -ENOMEM;
3187
3188 if (!netdev_uc_empty(netdev) && rar_entries) {
3189 struct netdev_hw_addr *ha;
3190
3191 /*
3192 * write the addresses in reverse order to avoid write
3193 * combining
3194 */
3195 netdev_for_each_uc_addr(ha, netdev) {
3196 if (!rar_entries)
3197 break;
3198 e1000e_rar_set(hw, ha->addr, rar_entries--);
3199 count++;
3200 }
3201 }
3202
3203 /* zero out the remaining RAR entries not used above */
3204 for (; rar_entries > 0; rar_entries--) {
3205 ew32(RAH(rar_entries), 0);
3206 ew32(RAL(rar_entries), 0);
3207 }
3208 e1e_flush();
3209
3210 return count;
3211}
3212
3213/**
3214 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3215 * @netdev: network interface device structure
3216 *
3217 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3218 * address list or the network interface flags are updated. This routine is
3219 * responsible for configuring the hardware for proper unicast, multicast,
3220 * promiscuous mode, and all-multi behavior.
3221 **/
3222static void e1000e_set_rx_mode(struct net_device *netdev)
3223{
3224 struct e1000_adapter *adapter = netdev_priv(netdev);
3225 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003226 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003227
3228 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003229 rctl = er32(RCTL);
3230
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003231 /* clear the affected bits */
3232 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3233
Auke Kokbc7f75f2007-09-17 12:30:59 -07003234 if (netdev->flags & IFF_PROMISC) {
3235 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003236 /* Do not hardware filter VLANs in promisc mode */
3237 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003238 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003239 int count;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003240 if (netdev->flags & IFF_ALLMULTI) {
3241 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003242 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003243 /*
3244 * Write addresses to the MTA, if the attempt fails
3245 * then we should just turn on promiscuous mode so
3246 * that we can at least receive multicast traffic
3247 */
3248 count = e1000e_write_mc_addr_list(netdev);
3249 if (count < 0)
3250 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003251 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003252 e1000e_vlan_filter_enable(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003253 /*
3254 * Write addresses to available RAR registers, if there is not
3255 * sufficient space to store all the addresses then enable
3256 * unicast promiscuous mode
3257 */
3258 count = e1000e_write_uc_addr_list(netdev);
3259 if (count < 0)
3260 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003261 }
3262
3263 ew32(RCTL, rctl);
3264
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003265 if (netdev->features & NETIF_F_HW_VLAN_RX)
3266 e1000e_vlan_strip_enable(adapter);
3267 else
3268 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003269}
3270
3271/**
Bruce Allanad680762008-03-28 09:15:03 -07003272 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003273 * @adapter: private board structure
3274 **/
3275static void e1000_configure(struct e1000_adapter *adapter)
3276{
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003277 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003278
3279 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003280 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003281
3282 e1000_configure_tx(adapter);
3283 e1000_setup_rctl(adapter);
3284 e1000_configure_rx(adapter);
Jeff Kirsherc2fed992011-07-12 16:10:12 +00003285 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring),
3286 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003287}
3288
3289/**
3290 * e1000e_power_up_phy - restore link in case the phy was powered down
3291 * @adapter: address of board private structure
3292 *
3293 * The phy may be powered down to save power and turn off link when the
3294 * driver is unloaded and wake on lan is not enabled (among others)
3295 * *** this routine MUST be followed by a call to e1000e_reset ***
3296 **/
3297void e1000e_power_up_phy(struct e1000_adapter *adapter)
3298{
Bruce Allan17f208d2009-12-01 15:47:22 +00003299 if (adapter->hw.phy.ops.power_up)
3300 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003301
3302 adapter->hw.mac.ops.setup_link(&adapter->hw);
3303}
3304
3305/**
3306 * e1000_power_down_phy - Power down the PHY
3307 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003308 * Power down the PHY so no link is implied when interface is down.
3309 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003310 */
3311static void e1000_power_down_phy(struct e1000_adapter *adapter)
3312{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003313 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003314 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003315 return;
3316
Bruce Allan17f208d2009-12-01 15:47:22 +00003317 if (adapter->hw.phy.ops.power_down)
3318 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003319}
3320
3321/**
3322 * e1000e_reset - bring the hardware into a known good state
3323 *
3324 * This function boots the hardware and enables some settings that
3325 * require a configuration cycle of the hardware - those cannot be
3326 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003327 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003328 */
3329void e1000e_reset(struct e1000_adapter *adapter)
3330{
3331 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003332 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003333 struct e1000_hw *hw = &adapter->hw;
3334 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003335 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003336 u16 hwm;
3337
Bruce Allanad680762008-03-28 09:15:03 -07003338 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003339 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003340
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003341 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003342 /*
3343 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003344 * large enough to accommodate two full transmit packets,
3345 * rounded up to the next 1KB and expressed in KB. Likewise,
3346 * the Rx FIFO should be large enough to accommodate at least
3347 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003348 * expressed in KB.
3349 */
Auke Kokdf762462007-10-25 13:57:53 -07003350 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003351 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003352 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003353 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003354 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003355 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003356 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003357 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003358 */
3359 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003360 sizeof(struct e1000_tx_desc) -
3361 ETH_FCS_LEN) * 2;
3362 min_tx_space = ALIGN(min_tx_space, 1024);
3363 min_tx_space >>= 10;
3364 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003365 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003366 min_rx_space = ALIGN(min_rx_space, 1024);
3367 min_rx_space >>= 10;
3368
Bruce Allanad680762008-03-28 09:15:03 -07003369 /*
3370 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003371 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003372 * allocation, take space away from current Rx allocation
3373 */
Auke Kokdf762462007-10-25 13:57:53 -07003374 if ((tx_space < min_tx_space) &&
3375 ((min_tx_space - tx_space) < pba)) {
3376 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003377
Bruce Allanad680762008-03-28 09:15:03 -07003378 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003379 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003380 * adjustment or use Early Receive if available
3381 */
Auke Kokdf762462007-10-25 13:57:53 -07003382 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003383 (!(adapter->flags & FLAG_HAS_ERT)))
3384 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003385 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003386 }
Auke Kokdf762462007-10-25 13:57:53 -07003387
3388 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003389 }
3390
Bruce Allanad680762008-03-28 09:15:03 -07003391 /*
3392 * flow control settings
3393 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003394 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003395 * (or the size used for early receive) above it in the Rx FIFO.
3396 * Set it to the lower of:
3397 * - 90% of the Rx FIFO size, and
3398 * - the full Rx FIFO size minus the early receive size (for parts
3399 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003400 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003401 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003402 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3403 fc->pause_time = 0xFFFF;
3404 else
3405 fc->pause_time = E1000_FC_PAUSE_TIME;
3406 fc->send_xon = 1;
3407 fc->current_mode = fc->requested_mode;
3408
3409 switch (hw->mac.type) {
3410 default:
3411 if ((adapter->flags & FLAG_HAS_ERT) &&
3412 (adapter->netdev->mtu > ETH_DATA_LEN))
3413 hwm = min(((pba << 10) * 9 / 10),
3414 ((pba << 10) - (E1000_ERT_2048 << 3)));
3415 else
3416 hwm = min(((pba << 10) * 9 / 10),
3417 ((pba << 10) - adapter->max_frame_size));
3418
3419 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3420 fc->low_water = fc->high_water - 8;
3421 break;
3422 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003423 /*
3424 * Workaround PCH LOM adapter hangs with certain network
3425 * loads. If hangs persist, try disabling Tx flow control.
3426 */
3427 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3428 fc->high_water = 0x3500;
3429 fc->low_water = 0x1500;
3430 } else {
3431 fc->high_water = 0x5000;
3432 fc->low_water = 0x3000;
3433 }
Bruce Allana3055952010-05-10 15:02:12 +00003434 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003435 break;
3436 case e1000_pch2lan:
3437 fc->high_water = 0x05C20;
3438 fc->low_water = 0x05048;
3439 fc->pause_time = 0x0650;
3440 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003441 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3442 pba = 14;
3443 ew32(PBA, pba);
3444 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003445 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003446 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003447
Bruce Allan828bac82010-09-29 21:39:37 +00003448 /*
3449 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3450 * fit in receive buffer and early-receive not supported.
3451 */
3452 if (adapter->itr_setting & 0x3) {
3453 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3454 !(adapter->flags & FLAG_HAS_ERT)) {
3455 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3456 dev_info(&adapter->pdev->dev,
3457 "Interrupt Throttle Rate turned off\n");
3458 adapter->flags2 |= FLAG2_DISABLE_AIM;
3459 ew32(ITR, 0);
3460 }
3461 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3462 dev_info(&adapter->pdev->dev,
3463 "Interrupt Throttle Rate turned on\n");
3464 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3465 adapter->itr = 20000;
3466 ew32(ITR, 1000000000 / (adapter->itr * 256));
3467 }
3468 }
3469
Auke Kokbc7f75f2007-09-17 12:30:59 -07003470 /* Allow time for pending master requests to run */
3471 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003472
3473 /*
3474 * For parts with AMT enabled, let the firmware know
3475 * that the network interface is in control
3476 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003477 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003478 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003479
Auke Kokbc7f75f2007-09-17 12:30:59 -07003480 ew32(WUC, 0);
3481
3482 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003483 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003484
3485 e1000_update_mng_vlan(adapter);
3486
3487 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3488 ew32(VET, ETH_P_8021Q);
3489
3490 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003491
3492 if (!netif_running(adapter->netdev) &&
3493 !test_bit(__E1000_TESTING, &adapter->state)) {
3494 e1000_power_down_phy(adapter);
3495 return;
3496 }
3497
Auke Kokbc7f75f2007-09-17 12:30:59 -07003498 e1000_get_phy_info(hw);
3499
Bruce Allan918d7192009-06-02 11:28:20 +00003500 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3501 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003502 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003503 /*
3504 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003505 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003506 * different we would do if it failed
3507 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003508 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3509 phy_data &= ~IGP02E1000_PM_SPD;
3510 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3511 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003512}
3513
3514int e1000e_up(struct e1000_adapter *adapter)
3515{
3516 struct e1000_hw *hw = &adapter->hw;
3517
3518 /* hardware has been reset, we need to reload some things */
3519 e1000_configure(adapter);
3520
3521 clear_bit(__E1000_DOWN, &adapter->state);
3522
Bruce Allan4662e822008-08-26 18:37:06 -07003523 if (adapter->msix_entries)
3524 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003525 e1000_irq_enable(adapter);
3526
Bruce Allan400484f2011-05-13 07:20:03 +00003527 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003528
Auke Kokbc7f75f2007-09-17 12:30:59 -07003529 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003530 if (adapter->msix_entries)
3531 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3532 else
3533 ew32(ICS, E1000_ICS_LSC);
3534
Auke Kokbc7f75f2007-09-17 12:30:59 -07003535 return 0;
3536}
3537
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003538static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3539{
3540 struct e1000_hw *hw = &adapter->hw;
3541
3542 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3543 return;
3544
3545 /* flush pending descriptor writebacks to memory */
3546 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3547 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3548
3549 /* execute the writes immediately */
3550 e1e_flush();
3551}
3552
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003553static void e1000e_update_stats(struct e1000_adapter *adapter);
3554
Auke Kokbc7f75f2007-09-17 12:30:59 -07003555void e1000e_down(struct e1000_adapter *adapter)
3556{
3557 struct net_device *netdev = adapter->netdev;
3558 struct e1000_hw *hw = &adapter->hw;
3559 u32 tctl, rctl;
3560
Bruce Allanad680762008-03-28 09:15:03 -07003561 /*
3562 * signal that we're down so the interrupt handler does not
3563 * reschedule our watchdog timer
3564 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003565 set_bit(__E1000_DOWN, &adapter->state);
3566
3567 /* disable receives in the hardware */
3568 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003569 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3570 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003571 /* flush and sleep below */
3572
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003573 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003574
3575 /* disable transmits in the hardware */
3576 tctl = er32(TCTL);
3577 tctl &= ~E1000_TCTL_EN;
3578 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003579
Auke Kokbc7f75f2007-09-17 12:30:59 -07003580 /* flush both disables and wait for them to finish */
3581 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003582 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003583
Auke Kokbc7f75f2007-09-17 12:30:59 -07003584 e1000_irq_disable(adapter);
3585
3586 del_timer_sync(&adapter->watchdog_timer);
3587 del_timer_sync(&adapter->phy_info_timer);
3588
Auke Kokbc7f75f2007-09-17 12:30:59 -07003589 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003590
3591 spin_lock(&adapter->stats64_lock);
3592 e1000e_update_stats(adapter);
3593 spin_unlock(&adapter->stats64_lock);
3594
Bruce Allan400484f2011-05-13 07:20:03 +00003595 e1000e_flush_descriptors(adapter);
3596 e1000_clean_tx_ring(adapter);
3597 e1000_clean_rx_ring(adapter);
3598
Auke Kokbc7f75f2007-09-17 12:30:59 -07003599 adapter->link_speed = 0;
3600 adapter->link_duplex = 0;
3601
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003602 if (!pci_channel_offline(adapter->pdev))
3603 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003604
Auke Kokbc7f75f2007-09-17 12:30:59 -07003605 /*
3606 * TODO: for power management, we could drop the link and
3607 * pci_disable_device here.
3608 */
3609}
3610
3611void e1000e_reinit_locked(struct e1000_adapter *adapter)
3612{
3613 might_sleep();
3614 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003615 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003616 e1000e_down(adapter);
3617 e1000e_up(adapter);
3618 clear_bit(__E1000_RESETTING, &adapter->state);
3619}
3620
3621/**
3622 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3623 * @adapter: board private structure to initialize
3624 *
3625 * e1000_sw_init initializes the Adapter private data structure.
3626 * Fields are initialized based on PCI device information and
3627 * OS network device settings (MTU size).
3628 **/
3629static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3630{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003631 struct net_device *netdev = adapter->netdev;
3632
3633 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3634 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003635 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3636 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003637
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003638 spin_lock_init(&adapter->stats64_lock);
3639
Bruce Allan4662e822008-08-26 18:37:06 -07003640 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003641
Bruce Allan4662e822008-08-26 18:37:06 -07003642 if (e1000_alloc_queues(adapter))
3643 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003644
Auke Kokbc7f75f2007-09-17 12:30:59 -07003645 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003646 e1000_irq_disable(adapter);
3647
Auke Kokbc7f75f2007-09-17 12:30:59 -07003648 set_bit(__E1000_DOWN, &adapter->state);
3649 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003650}
3651
3652/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003653 * e1000_intr_msi_test - Interrupt Handler
3654 * @irq: interrupt number
3655 * @data: pointer to a network interface device structure
3656 **/
3657static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3658{
3659 struct net_device *netdev = data;
3660 struct e1000_adapter *adapter = netdev_priv(netdev);
3661 struct e1000_hw *hw = &adapter->hw;
3662 u32 icr = er32(ICR);
3663
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003664 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003665 if (icr & E1000_ICR_RXSEQ) {
3666 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3667 wmb();
3668 }
3669
3670 return IRQ_HANDLED;
3671}
3672
3673/**
3674 * e1000_test_msi_interrupt - Returns 0 for successful test
3675 * @adapter: board private struct
3676 *
3677 * code flow taken from tg3.c
3678 **/
3679static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3680{
3681 struct net_device *netdev = adapter->netdev;
3682 struct e1000_hw *hw = &adapter->hw;
3683 int err;
3684
3685 /* poll_enable hasn't been called yet, so don't need disable */
3686 /* clear any pending events */
3687 er32(ICR);
3688
3689 /* free the real vector and request a test handler */
3690 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003691 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003692
3693 /* Assume that the test fails, if it succeeds then the test
3694 * MSI irq handler will unset this flag */
3695 adapter->flags |= FLAG_MSI_TEST_FAILED;
3696
3697 err = pci_enable_msi(adapter->pdev);
3698 if (err)
3699 goto msi_test_failed;
3700
Joe Perchesa0607fd2009-11-18 23:29:17 -08003701 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003702 netdev->name, netdev);
3703 if (err) {
3704 pci_disable_msi(adapter->pdev);
3705 goto msi_test_failed;
3706 }
3707
3708 wmb();
3709
3710 e1000_irq_enable(adapter);
3711
3712 /* fire an unusual interrupt on the test handler */
3713 ew32(ICS, E1000_ICS_RXSEQ);
3714 e1e_flush();
3715 msleep(50);
3716
3717 e1000_irq_disable(adapter);
3718
3719 rmb();
3720
3721 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003722 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003723 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3724 } else
3725 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003726
3727 free_irq(adapter->pdev->irq, netdev);
3728 pci_disable_msi(adapter->pdev);
3729
Bruce Allanf8d59f72008-08-08 18:36:11 -07003730msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003731 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003732 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003733}
3734
3735/**
3736 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3737 * @adapter: board private struct
3738 *
3739 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3740 **/
3741static int e1000_test_msi(struct e1000_adapter *adapter)
3742{
3743 int err;
3744 u16 pci_cmd;
3745
3746 if (!(adapter->flags & FLAG_MSI_ENABLED))
3747 return 0;
3748
3749 /* disable SERR in case the MSI write causes a master abort */
3750 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003751 if (pci_cmd & PCI_COMMAND_SERR)
3752 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3753 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003754
3755 err = e1000_test_msi_interrupt(adapter);
3756
Dean Nelson36f24072010-06-29 18:12:05 +00003757 /* re-enable SERR */
3758 if (pci_cmd & PCI_COMMAND_SERR) {
3759 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3760 pci_cmd |= PCI_COMMAND_SERR;
3761 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3762 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003763
Bruce Allanf8d59f72008-08-08 18:36:11 -07003764 return err;
3765}
3766
3767/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003768 * e1000_open - Called when a network interface is made active
3769 * @netdev: network interface device structure
3770 *
3771 * Returns 0 on success, negative value on failure
3772 *
3773 * The open entry point is called when a network interface is made
3774 * active by the system (IFF_UP). At this point all resources needed
3775 * for transmit and receive operations are allocated, the interrupt
3776 * handler is registered with the OS, the watchdog timer is started,
3777 * and the stack is notified that the interface is ready.
3778 **/
3779static int e1000_open(struct net_device *netdev)
3780{
3781 struct e1000_adapter *adapter = netdev_priv(netdev);
3782 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003783 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003784 int err;
3785
3786 /* disallow open during test */
3787 if (test_bit(__E1000_TESTING, &adapter->state))
3788 return -EBUSY;
3789
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003790 pm_runtime_get_sync(&pdev->dev);
3791
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003792 netif_carrier_off(netdev);
3793
Auke Kokbc7f75f2007-09-17 12:30:59 -07003794 /* allocate transmit descriptors */
3795 err = e1000e_setup_tx_resources(adapter);
3796 if (err)
3797 goto err_setup_tx;
3798
3799 /* allocate receive descriptors */
3800 err = e1000e_setup_rx_resources(adapter);
3801 if (err)
3802 goto err_setup_rx;
3803
Bruce Allan11b08be2010-05-10 14:59:31 +00003804 /*
3805 * If AMT is enabled, let the firmware know that the network
3806 * interface is now open and reset the part to a known state.
3807 */
3808 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003809 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003810 e1000e_reset(adapter);
3811 }
3812
Auke Kokbc7f75f2007-09-17 12:30:59 -07003813 e1000e_power_up_phy(adapter);
3814
3815 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3816 if ((adapter->hw.mng_cookie.status &
3817 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3818 e1000_update_mng_vlan(adapter);
3819
Florian Micklerc128ec22010-08-02 14:27:00 +00003820 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003821 if ((adapter->flags & FLAG_HAS_ERT) ||
3822 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003823 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3824 PM_QOS_CPU_DMA_LATENCY,
3825 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003826
Bruce Allanad680762008-03-28 09:15:03 -07003827 /*
Bruce Allanad680762008-03-28 09:15:03 -07003828 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003829 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3830 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003831 * clean_rx handler before we do so.
3832 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003833 e1000_configure(adapter);
3834
3835 err = e1000_request_irq(adapter);
3836 if (err)
3837 goto err_req_irq;
3838
Bruce Allanf8d59f72008-08-08 18:36:11 -07003839 /*
3840 * Work around PCIe errata with MSI interrupts causing some chipsets to
3841 * ignore e1000e MSI messages, which means we need to test our MSI
3842 * interrupt now
3843 */
Bruce Allan4662e822008-08-26 18:37:06 -07003844 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003845 err = e1000_test_msi(adapter);
3846 if (err) {
3847 e_err("Interrupt allocation failed\n");
3848 goto err_req_irq;
3849 }
3850 }
3851
Auke Kokbc7f75f2007-09-17 12:30:59 -07003852 /* From here on the code is the same as e1000e_up() */
3853 clear_bit(__E1000_DOWN, &adapter->state);
3854
3855 napi_enable(&adapter->napi);
3856
3857 e1000_irq_enable(adapter);
3858
Jeff Kirsher09357b02011-11-18 14:25:00 +00003859 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003860 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003861
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003862 adapter->idle_check = true;
3863 pm_runtime_put(&pdev->dev);
3864
Auke Kokbc7f75f2007-09-17 12:30:59 -07003865 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003866 if (adapter->msix_entries)
3867 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3868 else
3869 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003870
3871 return 0;
3872
3873err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003874 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003875 e1000_power_down_phy(adapter);
3876 e1000e_free_rx_resources(adapter);
3877err_setup_rx:
3878 e1000e_free_tx_resources(adapter);
3879err_setup_tx:
3880 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003881 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003882
3883 return err;
3884}
3885
3886/**
3887 * e1000_close - Disables a network interface
3888 * @netdev: network interface device structure
3889 *
3890 * Returns 0, this is not allowed to fail
3891 *
3892 * The close entry point is called when an interface is de-activated
3893 * by the OS. The hardware is still under the drivers control, but
3894 * needs to be disabled. A global MAC reset is issued to stop the
3895 * hardware, and all transmit and receive resources are freed.
3896 **/
3897static int e1000_close(struct net_device *netdev)
3898{
3899 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003900 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003901
3902 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003903
3904 pm_runtime_get_sync(&pdev->dev);
3905
Bruce Allan5f4a7802011-11-29 08:09:19 +00003906 napi_disable(&adapter->napi);
3907
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003908 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3909 e1000e_down(adapter);
3910 e1000_free_irq(adapter);
3911 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003912 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003913
3914 e1000e_free_tx_resources(adapter);
3915 e1000e_free_rx_resources(adapter);
3916
Bruce Allanad680762008-03-28 09:15:03 -07003917 /*
3918 * kill manageability vlan ID if supported, but not if a vlan with
3919 * the same ID is registered on the host OS (let 8021q kill it)
3920 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003921 if (adapter->hw.mng_cookie.status &
3922 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003923 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3924
Bruce Allanad680762008-03-28 09:15:03 -07003925 /*
3926 * If AMT is enabled, let the firmware know that the network
3927 * interface is now closed
3928 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003929 if ((adapter->flags & FLAG_HAS_AMT) &&
3930 !test_bit(__E1000_TESTING, &adapter->state))
3931 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003932
Bruce Allan828bac82010-09-29 21:39:37 +00003933 if ((adapter->flags & FLAG_HAS_ERT) ||
3934 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003935 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003936
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003937 pm_runtime_put_sync(&pdev->dev);
3938
Auke Kokbc7f75f2007-09-17 12:30:59 -07003939 return 0;
3940}
3941/**
3942 * e1000_set_mac - Change the Ethernet Address of the NIC
3943 * @netdev: network interface device structure
3944 * @p: pointer to an address structure
3945 *
3946 * Returns 0 on success, negative on failure
3947 **/
3948static int e1000_set_mac(struct net_device *netdev, void *p)
3949{
3950 struct e1000_adapter *adapter = netdev_priv(netdev);
3951 struct sockaddr *addr = p;
3952
3953 if (!is_valid_ether_addr(addr->sa_data))
3954 return -EADDRNOTAVAIL;
3955
3956 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3957 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3958
3959 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3960
3961 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3962 /* activate the work around */
3963 e1000e_set_laa_state_82571(&adapter->hw, 1);
3964
Bruce Allanad680762008-03-28 09:15:03 -07003965 /*
3966 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003967 * between the time RAR[0] gets clobbered and the time it
3968 * gets fixed (in e1000_watchdog), the actual LAA is in one
3969 * of the RARs and no incoming packets directed to this port
3970 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003971 * RAR[14]
3972 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003973 e1000e_rar_set(&adapter->hw,
3974 adapter->hw.mac.addr,
3975 adapter->hw.mac.rar_entry_count - 1);
3976 }
3977
3978 return 0;
3979}
3980
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003981/**
3982 * e1000e_update_phy_task - work thread to update phy
3983 * @work: pointer to our work struct
3984 *
3985 * this worker thread exists because we must acquire a
3986 * semaphore to read the phy, which we could msleep while
3987 * waiting for it, and we can't msleep in a timer.
3988 **/
3989static void e1000e_update_phy_task(struct work_struct *work)
3990{
3991 struct e1000_adapter *adapter = container_of(work,
3992 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003993
3994 if (test_bit(__E1000_DOWN, &adapter->state))
3995 return;
3996
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003997 e1000_get_phy_info(&adapter->hw);
3998}
3999
Bruce Allanad680762008-03-28 09:15:03 -07004000/*
4001 * Need to wait a few seconds after link up to get diagnostic information from
4002 * the phy
4003 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004004static void e1000_update_phy_info(unsigned long data)
4005{
4006 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004007
4008 if (test_bit(__E1000_DOWN, &adapter->state))
4009 return;
4010
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004011 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004012}
4013
4014/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004015 * e1000e_update_phy_stats - Update the PHY statistics counters
4016 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004017 *
4018 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004019 **/
4020static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4021{
4022 struct e1000_hw *hw = &adapter->hw;
4023 s32 ret_val;
4024 u16 phy_data;
4025
4026 ret_val = hw->phy.ops.acquire(hw);
4027 if (ret_val)
4028 return;
4029
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004030 /*
4031 * A page set is expensive so check if already on desired page.
4032 * If not, set to the page with the PHY status registers.
4033 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004034 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004035 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4036 &phy_data);
4037 if (ret_val)
4038 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004039 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4040 ret_val = hw->phy.ops.set_page(hw,
4041 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004042 if (ret_val)
4043 goto release;
4044 }
4045
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004046 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004047 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4048 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004049 if (!ret_val)
4050 adapter->stats.scc += phy_data;
4051
4052 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004053 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4054 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004055 if (!ret_val)
4056 adapter->stats.ecol += phy_data;
4057
4058 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004059 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4060 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004061 if (!ret_val)
4062 adapter->stats.mcc += phy_data;
4063
4064 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004065 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4066 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004067 if (!ret_val)
4068 adapter->stats.latecol += phy_data;
4069
4070 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004071 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4072 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004073 if (!ret_val)
4074 hw->mac.collision_delta = phy_data;
4075
4076 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004077 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4078 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004079 if (!ret_val)
4080 adapter->stats.dc += phy_data;
4081
4082 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004083 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4084 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004085 if (!ret_val)
4086 adapter->stats.tncrs += phy_data;
4087
4088release:
4089 hw->phy.ops.release(hw);
4090}
4091
4092/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004093 * e1000e_update_stats - Update the board statistics counters
4094 * @adapter: board private structure
4095 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004096static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004097{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004098 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004099 struct e1000_hw *hw = &adapter->hw;
4100 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004101
4102 /*
4103 * Prevent stats update while adapter is being reset, or if the pci
4104 * connection is down.
4105 */
4106 if (adapter->link_speed == 0)
4107 return;
4108 if (pci_channel_offline(pdev))
4109 return;
4110
Auke Kokbc7f75f2007-09-17 12:30:59 -07004111 adapter->stats.crcerrs += er32(CRCERRS);
4112 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004113 adapter->stats.gorc += er32(GORCL);
4114 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004115 adapter->stats.bprc += er32(BPRC);
4116 adapter->stats.mprc += er32(MPRC);
4117 adapter->stats.roc += er32(ROC);
4118
Auke Kokbc7f75f2007-09-17 12:30:59 -07004119 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004120
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004121 /* Half-duplex statistics */
4122 if (adapter->link_duplex == HALF_DUPLEX) {
4123 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4124 e1000e_update_phy_stats(adapter);
4125 } else {
4126 adapter->stats.scc += er32(SCC);
4127 adapter->stats.ecol += er32(ECOL);
4128 adapter->stats.mcc += er32(MCC);
4129 adapter->stats.latecol += er32(LATECOL);
4130 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004131
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004132 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004133
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004134 if ((hw->mac.type != e1000_82574) &&
4135 (hw->mac.type != e1000_82583))
4136 adapter->stats.tncrs += er32(TNCRS);
4137 }
4138 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004139 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004140
Auke Kokbc7f75f2007-09-17 12:30:59 -07004141 adapter->stats.xonrxc += er32(XONRXC);
4142 adapter->stats.xontxc += er32(XONTXC);
4143 adapter->stats.xoffrxc += er32(XOFFRXC);
4144 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004145 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004146 adapter->stats.gotc += er32(GOTCL);
4147 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004148 adapter->stats.rnbc += er32(RNBC);
4149 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004150
4151 adapter->stats.mptc += er32(MPTC);
4152 adapter->stats.bptc += er32(BPTC);
4153
4154 /* used for adaptive IFS */
4155
4156 hw->mac.tx_packet_delta = er32(TPT);
4157 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004158
4159 adapter->stats.algnerrc += er32(ALGNERRC);
4160 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004161 adapter->stats.cexterr += er32(CEXTERR);
4162 adapter->stats.tsctc += er32(TSCTC);
4163 adapter->stats.tsctfc += er32(TSCTFC);
4164
Auke Kokbc7f75f2007-09-17 12:30:59 -07004165 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004166 netdev->stats.multicast = adapter->stats.mprc;
4167 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004168
4169 /* Rx Errors */
4170
Bruce Allanad680762008-03-28 09:15:03 -07004171 /*
4172 * RLEC on some newer hardware can be incorrect so build
4173 * our own version based on RUC and ROC
4174 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004175 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176 adapter->stats.crcerrs + adapter->stats.algnerrc +
4177 adapter->stats.ruc + adapter->stats.roc +
4178 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004179 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004180 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004181 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4182 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4183 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004184
4185 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004186 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004187 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004188 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4189 netdev->stats.tx_window_errors = adapter->stats.latecol;
4190 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004191
4192 /* Tx Dropped needs to be maintained elsewhere */
4193
Auke Kokbc7f75f2007-09-17 12:30:59 -07004194 /* Management Stats */
4195 adapter->stats.mgptc += er32(MGTPTC);
4196 adapter->stats.mgprc += er32(MGTPRC);
4197 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004198}
4199
Bruce Allan7c257692008-04-23 11:09:00 -07004200/**
4201 * e1000_phy_read_status - Update the PHY register status snapshot
4202 * @adapter: board private structure
4203 **/
4204static void e1000_phy_read_status(struct e1000_adapter *adapter)
4205{
4206 struct e1000_hw *hw = &adapter->hw;
4207 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004208
4209 if ((er32(STATUS) & E1000_STATUS_LU) &&
4210 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004211 int ret_val;
4212
Bruce Allan7c257692008-04-23 11:09:00 -07004213 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4214 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4215 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4216 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4217 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4218 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4219 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4220 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4221 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004222 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004223 } else {
4224 /*
4225 * Do not read PHY registers if link is not up
4226 * Set values to typical power-on defaults
4227 */
4228 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4229 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4230 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4231 BMSR_ERCAP);
4232 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4233 ADVERTISE_ALL | ADVERTISE_CSMA);
4234 phy->lpa = 0;
4235 phy->expansion = EXPANSION_ENABLENPAGE;
4236 phy->ctrl1000 = ADVERTISE_1000FULL;
4237 phy->stat1000 = 0;
4238 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4239 }
Bruce Allan7c257692008-04-23 11:09:00 -07004240}
4241
Auke Kokbc7f75f2007-09-17 12:30:59 -07004242static void e1000_print_link_info(struct e1000_adapter *adapter)
4243{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004244 struct e1000_hw *hw = &adapter->hw;
4245 u32 ctrl = er32(CTRL);
4246
Bruce Allan8f12fe82008-11-21 16:54:43 -08004247 /* Link status message must follow this format for user tools */
Jeff Kirsheref456f82011-11-03 11:40:28 +00004248 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4249 adapter->netdev->name,
4250 adapter->link_speed,
4251 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4252 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4253 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4254 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004255}
4256
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004257static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004258{
4259 struct e1000_hw *hw = &adapter->hw;
4260 bool link_active = 0;
4261 s32 ret_val = 0;
4262
4263 /*
4264 * get_link_status is set on LSC (link status) interrupt or
4265 * Rx sequence error interrupt. get_link_status will stay
4266 * false until the check_for_link establishes link
4267 * for copper adapters ONLY
4268 */
4269 switch (hw->phy.media_type) {
4270 case e1000_media_type_copper:
4271 if (hw->mac.get_link_status) {
4272 ret_val = hw->mac.ops.check_for_link(hw);
4273 link_active = !hw->mac.get_link_status;
4274 } else {
4275 link_active = 1;
4276 }
4277 break;
4278 case e1000_media_type_fiber:
4279 ret_val = hw->mac.ops.check_for_link(hw);
4280 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4281 break;
4282 case e1000_media_type_internal_serdes:
4283 ret_val = hw->mac.ops.check_for_link(hw);
4284 link_active = adapter->hw.mac.serdes_has_link;
4285 break;
4286 default:
4287 case e1000_media_type_unknown:
4288 break;
4289 }
4290
4291 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4292 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4293 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004294 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004295 }
4296
4297 return link_active;
4298}
4299
4300static void e1000e_enable_receives(struct e1000_adapter *adapter)
4301{
4302 /* make sure the receive unit is started */
4303 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4304 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4305 struct e1000_hw *hw = &adapter->hw;
4306 u32 rctl = er32(RCTL);
4307 ew32(RCTL, rctl | E1000_RCTL_EN);
4308 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4309 }
4310}
4311
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004312static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4313{
4314 struct e1000_hw *hw = &adapter->hw;
4315
4316 /*
4317 * With 82574 controllers, PHY needs to be checked periodically
4318 * for hung state and reset, if two calls return true
4319 */
4320 if (e1000_check_phy_82574(hw))
4321 adapter->phy_hang_count++;
4322 else
4323 adapter->phy_hang_count = 0;
4324
4325 if (adapter->phy_hang_count > 1) {
4326 adapter->phy_hang_count = 0;
4327 schedule_work(&adapter->reset_task);
4328 }
4329}
4330
Auke Kokbc7f75f2007-09-17 12:30:59 -07004331/**
4332 * e1000_watchdog - Timer Call-back
4333 * @data: pointer to adapter cast into an unsigned long
4334 **/
4335static void e1000_watchdog(unsigned long data)
4336{
4337 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4338
4339 /* Do the rest outside of interrupt context */
4340 schedule_work(&adapter->watchdog_task);
4341
4342 /* TODO: make this use queue_delayed_work() */
4343}
4344
4345static void e1000_watchdog_task(struct work_struct *work)
4346{
4347 struct e1000_adapter *adapter = container_of(work,
4348 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004349 struct net_device *netdev = adapter->netdev;
4350 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004351 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004352 struct e1000_ring *tx_ring = adapter->tx_ring;
4353 struct e1000_hw *hw = &adapter->hw;
4354 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004355
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004356 if (test_bit(__E1000_DOWN, &adapter->state))
4357 return;
4358
David S. Millerb405e8d2010-02-04 22:31:41 -08004359 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004360 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004361 /* Cancel scheduled suspend requests. */
4362 pm_runtime_resume(netdev->dev.parent);
4363
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004364 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004365 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004366 }
4367
4368 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4369 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4370 e1000_update_mng_vlan(adapter);
4371
Auke Kokbc7f75f2007-09-17 12:30:59 -07004372 if (link) {
4373 if (!netif_carrier_ok(netdev)) {
4374 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004375
4376 /* Cancel scheduled suspend requests. */
4377 pm_runtime_resume(netdev->dev.parent);
4378
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004379 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004380 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004381 mac->ops.get_link_up_info(&adapter->hw,
4382 &adapter->link_speed,
4383 &adapter->link_duplex);
4384 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004385 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004386 * On supported PHYs, check for duplex mismatch only
4387 * if link has autonegotiated at 10/100 half
4388 */
4389 if ((hw->phy.type == e1000_phy_igp_3 ||
4390 hw->phy.type == e1000_phy_bm) &&
4391 (hw->mac.autoneg == true) &&
4392 (adapter->link_speed == SPEED_10 ||
4393 adapter->link_speed == SPEED_100) &&
4394 (adapter->link_duplex == HALF_DUPLEX)) {
4395 u16 autoneg_exp;
4396
4397 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4398
4399 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004400 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 -07004401 }
4402
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004403 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004404 adapter->tx_timeout_factor = 1;
4405 switch (adapter->link_speed) {
4406 case SPEED_10:
4407 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004408 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004409 break;
4410 case SPEED_100:
4411 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004412 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004413 break;
4414 }
4415
Bruce Allanad680762008-03-28 09:15:03 -07004416 /*
4417 * workaround: re-program speed mode bit after
4418 * link-up event
4419 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004420 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4421 !txb2b) {
4422 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004423 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004424 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004425 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004426 }
4427
Bruce Allanad680762008-03-28 09:15:03 -07004428 /*
4429 * disable TSO for pcie and 10/100 speeds, to avoid
4430 * some hardware issues
4431 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004432 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4433 switch (adapter->link_speed) {
4434 case SPEED_10:
4435 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004436 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004437 netdev->features &= ~NETIF_F_TSO;
4438 netdev->features &= ~NETIF_F_TSO6;
4439 break;
4440 case SPEED_1000:
4441 netdev->features |= NETIF_F_TSO;
4442 netdev->features |= NETIF_F_TSO6;
4443 break;
4444 default:
4445 /* oops */
4446 break;
4447 }
4448 }
4449
Bruce Allanad680762008-03-28 09:15:03 -07004450 /*
4451 * enable transmits in the hardware, need to do this
4452 * after setting TARC(0)
4453 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004454 tctl = er32(TCTL);
4455 tctl |= E1000_TCTL_EN;
4456 ew32(TCTL, tctl);
4457
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004458 /*
4459 * Perform any post-link-up configuration before
4460 * reporting link up.
4461 */
4462 if (phy->ops.cfg_on_link_up)
4463 phy->ops.cfg_on_link_up(hw);
4464
Auke Kokbc7f75f2007-09-17 12:30:59 -07004465 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004466
4467 if (!test_bit(__E1000_DOWN, &adapter->state))
4468 mod_timer(&adapter->phy_info_timer,
4469 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004470 }
4471 } else {
4472 if (netif_carrier_ok(netdev)) {
4473 adapter->link_speed = 0;
4474 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004475 /* Link status message must follow this format */
4476 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4477 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004478 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004479 if (!test_bit(__E1000_DOWN, &adapter->state))
4480 mod_timer(&adapter->phy_info_timer,
4481 round_jiffies(jiffies + 2 * HZ));
4482
4483 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4484 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004485 else
4486 pm_schedule_suspend(netdev->dev.parent,
4487 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004488 }
4489 }
4490
4491link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004492 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004493 e1000e_update_stats(adapter);
4494
4495 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4496 adapter->tpt_old = adapter->stats.tpt;
4497 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4498 adapter->colc_old = adapter->stats.colc;
4499
Bruce Allan7c257692008-04-23 11:09:00 -07004500 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4501 adapter->gorc_old = adapter->stats.gorc;
4502 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4503 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004504 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004505
4506 e1000e_update_adaptive(&adapter->hw);
4507
Bruce Allan90da0662011-01-06 07:02:53 +00004508 if (!netif_carrier_ok(netdev) &&
4509 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4510 /*
4511 * We've lost link, so the controller stops DMA,
4512 * but we've got queued Tx work that's never going
4513 * to get done, so reset controller to flush Tx.
4514 * (Do the reset outside of interrupt context).
4515 */
Bruce Allan90da0662011-01-06 07:02:53 +00004516 schedule_work(&adapter->reset_task);
4517 /* return immediately since reset is imminent */
4518 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004519 }
4520
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004521 /* Simple mode for Interrupt Throttle Rate (ITR) */
4522 if (adapter->itr_setting == 4) {
4523 /*
4524 * Symmetric Tx/Rx gets a reduced ITR=2000;
4525 * Total asymmetrical Tx or Rx gets ITR=8000;
4526 * everyone else is between 2000-8000.
4527 */
4528 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4529 u32 dif = (adapter->gotc > adapter->gorc ?
4530 adapter->gotc - adapter->gorc :
4531 adapter->gorc - adapter->gotc) / 10000;
4532 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4533
4534 ew32(ITR, 1000000000 / (itr * 256));
4535 }
4536
Bruce Allanad680762008-03-28 09:15:03 -07004537 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004538 if (adapter->msix_entries)
4539 ew32(ICS, adapter->rx_ring->ims_val);
4540 else
4541 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004542
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004543 /* flush pending descriptors to memory before detecting Tx hang */
4544 e1000e_flush_descriptors(adapter);
4545
Auke Kokbc7f75f2007-09-17 12:30:59 -07004546 /* Force detection of hung controller every watchdog period */
4547 adapter->detect_tx_hung = 1;
4548
Bruce Allanad680762008-03-28 09:15:03 -07004549 /*
4550 * With 82571 controllers, LAA may be overwritten due to controller
4551 * reset from the other port. Set the appropriate LAA in RAR[0]
4552 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004553 if (e1000e_get_laa_state_82571(hw))
4554 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4555
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004556 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4557 e1000e_check_82574_phy_workaround(adapter);
4558
Auke Kokbc7f75f2007-09-17 12:30:59 -07004559 /* Reset the timer */
4560 if (!test_bit(__E1000_DOWN, &adapter->state))
4561 mod_timer(&adapter->watchdog_timer,
4562 round_jiffies(jiffies + 2 * HZ));
4563}
4564
4565#define E1000_TX_FLAGS_CSUM 0x00000001
4566#define E1000_TX_FLAGS_VLAN 0x00000002
4567#define E1000_TX_FLAGS_TSO 0x00000004
4568#define E1000_TX_FLAGS_IPV4 0x00000008
4569#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4570#define E1000_TX_FLAGS_VLAN_SHIFT 16
4571
4572static int e1000_tso(struct e1000_adapter *adapter,
4573 struct sk_buff *skb)
4574{
4575 struct e1000_ring *tx_ring = adapter->tx_ring;
4576 struct e1000_context_desc *context_desc;
4577 struct e1000_buffer *buffer_info;
4578 unsigned int i;
4579 u32 cmd_length = 0;
4580 u16 ipcse = 0, tucse, mss;
4581 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004582
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004583 if (!skb_is_gso(skb))
4584 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004585
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004586 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004587 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4588
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004589 if (err)
4590 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004591 }
4592
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004593 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4594 mss = skb_shinfo(skb)->gso_size;
4595 if (skb->protocol == htons(ETH_P_IP)) {
4596 struct iphdr *iph = ip_hdr(skb);
4597 iph->tot_len = 0;
4598 iph->check = 0;
4599 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4600 0, IPPROTO_TCP, 0);
4601 cmd_length = E1000_TXD_CMD_IP;
4602 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004603 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004604 ipv6_hdr(skb)->payload_len = 0;
4605 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4606 &ipv6_hdr(skb)->daddr,
4607 0, IPPROTO_TCP, 0);
4608 ipcse = 0;
4609 }
4610 ipcss = skb_network_offset(skb);
4611 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4612 tucss = skb_transport_offset(skb);
4613 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4614 tucse = 0;
4615
4616 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4617 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4618
4619 i = tx_ring->next_to_use;
4620 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4621 buffer_info = &tx_ring->buffer_info[i];
4622
4623 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4624 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4625 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4626 context_desc->upper_setup.tcp_fields.tucss = tucss;
4627 context_desc->upper_setup.tcp_fields.tucso = tucso;
4628 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4629 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4630 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4631 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4632
4633 buffer_info->time_stamp = jiffies;
4634 buffer_info->next_to_watch = i;
4635
4636 i++;
4637 if (i == tx_ring->count)
4638 i = 0;
4639 tx_ring->next_to_use = i;
4640
4641 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004642}
4643
4644static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4645{
4646 struct e1000_ring *tx_ring = adapter->tx_ring;
4647 struct e1000_context_desc *context_desc;
4648 struct e1000_buffer *buffer_info;
4649 unsigned int i;
4650 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004651 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004652 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004653
Dave Grahamaf807c82008-10-09 14:28:58 -07004654 if (skb->ip_summed != CHECKSUM_PARTIAL)
4655 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004656
Arthur Jones5f66f202009-03-19 01:13:08 +00004657 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4658 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4659 else
4660 protocol = skb->protocol;
4661
Arthur Jones3f518392009-03-20 15:56:35 -07004662 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004663 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004664 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4665 cmd_len |= E1000_TXD_CMD_TCP;
4666 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004667 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004668 /* XXX not handling all IPV6 headers */
4669 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4670 cmd_len |= E1000_TXD_CMD_TCP;
4671 break;
4672 default:
4673 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004674 e_warn("checksum_partial proto=%x!\n",
4675 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004676 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004677 }
4678
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004679 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004680
4681 i = tx_ring->next_to_use;
4682 buffer_info = &tx_ring->buffer_info[i];
4683 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4684
4685 context_desc->lower_setup.ip_config = 0;
4686 context_desc->upper_setup.tcp_fields.tucss = css;
4687 context_desc->upper_setup.tcp_fields.tucso =
4688 css + skb->csum_offset;
4689 context_desc->upper_setup.tcp_fields.tucse = 0;
4690 context_desc->tcp_seg_setup.data = 0;
4691 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4692
4693 buffer_info->time_stamp = jiffies;
4694 buffer_info->next_to_watch = i;
4695
4696 i++;
4697 if (i == tx_ring->count)
4698 i = 0;
4699 tx_ring->next_to_use = i;
4700
4701 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004702}
4703
4704#define E1000_MAX_PER_TXD 8192
4705#define E1000_MAX_TXD_PWR 12
4706
4707static int e1000_tx_map(struct e1000_adapter *adapter,
4708 struct sk_buff *skb, unsigned int first,
4709 unsigned int max_per_txd, unsigned int nr_frags,
4710 unsigned int mss)
4711{
4712 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004713 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004714 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004715 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004716 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004717 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004718
4719 i = tx_ring->next_to_use;
4720
4721 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004722 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004723 size = min(len, max_per_txd);
4724
Auke Kokbc7f75f2007-09-17 12:30:59 -07004725 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004726 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004727 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004728 buffer_info->dma = dma_map_single(&pdev->dev,
4729 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004730 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004731 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004732 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004733 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004734
4735 len -= size;
4736 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004737 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004738
4739 if (len) {
4740 i++;
4741 if (i == tx_ring->count)
4742 i = 0;
4743 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004744 }
4745
4746 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004747 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004748
4749 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004750 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004751 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004752
4753 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004754 i++;
4755 if (i == tx_ring->count)
4756 i = 0;
4757
Auke Kokbc7f75f2007-09-17 12:30:59 -07004758 buffer_info = &tx_ring->buffer_info[i];
4759 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004760
4761 buffer_info->length = size;
4762 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004763 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004764 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4765 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004766 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004767 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004768 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004769
4770 len -= size;
4771 offset += size;
4772 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004773 }
4774 }
4775
Bruce Allanaf667a22010-12-31 06:10:01 +00004776 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004777 /* multiply data chunks by size of headers */
4778 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4779
Auke Kokbc7f75f2007-09-17 12:30:59 -07004780 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004781 tx_ring->buffer_info[i].segs = segs;
4782 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004783 tx_ring->buffer_info[first].next_to_watch = i;
4784
4785 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004786
4787dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004788 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004789 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004790 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004791 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004792
4793 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004794 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004795 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004796 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004797 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004798 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004799 }
4800
4801 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004802}
4803
4804static void e1000_tx_queue(struct e1000_adapter *adapter,
4805 int tx_flags, int count)
4806{
4807 struct e1000_ring *tx_ring = adapter->tx_ring;
4808 struct e1000_tx_desc *tx_desc = NULL;
4809 struct e1000_buffer *buffer_info;
4810 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4811 unsigned int i;
4812
4813 if (tx_flags & E1000_TX_FLAGS_TSO) {
4814 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4815 E1000_TXD_CMD_TSE;
4816 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4817
4818 if (tx_flags & E1000_TX_FLAGS_IPV4)
4819 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4820 }
4821
4822 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4823 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4824 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4825 }
4826
4827 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4828 txd_lower |= E1000_TXD_CMD_VLE;
4829 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4830 }
4831
4832 i = tx_ring->next_to_use;
4833
Bruce Allan36b973d2010-11-24 07:42:43 +00004834 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004835 buffer_info = &tx_ring->buffer_info[i];
4836 tx_desc = E1000_TX_DESC(*tx_ring, i);
4837 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4838 tx_desc->lower.data =
4839 cpu_to_le32(txd_lower | buffer_info->length);
4840 tx_desc->upper.data = cpu_to_le32(txd_upper);
4841
4842 i++;
4843 if (i == tx_ring->count)
4844 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004845 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004846
4847 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4848
Bruce Allanad680762008-03-28 09:15:03 -07004849 /*
4850 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004851 * know there are new descriptors to fetch. (Only
4852 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004853 * such as IA-64).
4854 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004855 wmb();
4856
4857 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004858
4859 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4860 e1000e_update_tdt_wa(adapter, i);
4861 else
4862 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4863
Bruce Allanad680762008-03-28 09:15:03 -07004864 /*
4865 * we need this if more than one processor can write to our tail
4866 * at a time, it synchronizes IO on IA64/Altix systems
4867 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004868 mmiowb();
4869}
4870
4871#define MINIMUM_DHCP_PACKET_SIZE 282
4872static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4873 struct sk_buff *skb)
4874{
4875 struct e1000_hw *hw = &adapter->hw;
4876 u16 length, offset;
4877
4878 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004879 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4880 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004881 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4882 return 0;
4883 }
4884
4885 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4886 return 0;
4887
4888 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4889 return 0;
4890
4891 {
4892 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4893 struct udphdr *udp;
4894
4895 if (ip->protocol != IPPROTO_UDP)
4896 return 0;
4897
4898 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4899 if (ntohs(udp->dest) != 67)
4900 return 0;
4901
4902 offset = (u8 *)udp + 8 - skb->data;
4903 length = skb->len - offset;
4904 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4905 }
4906
4907 return 0;
4908}
4909
4910static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4911{
4912 struct e1000_adapter *adapter = netdev_priv(netdev);
4913
4914 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004915 /*
4916 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004917 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004918 * but since that doesn't exist yet, just open code it.
4919 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004920 smp_mb();
4921
Bruce Allanad680762008-03-28 09:15:03 -07004922 /*
4923 * We need to check again in a case another CPU has just
4924 * made room available.
4925 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004926 if (e1000_desc_unused(adapter->tx_ring) < size)
4927 return -EBUSY;
4928
4929 /* A reprieve! */
4930 netif_start_queue(netdev);
4931 ++adapter->restart_queue;
4932 return 0;
4933}
4934
4935static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4936{
4937 struct e1000_adapter *adapter = netdev_priv(netdev);
4938
4939 if (e1000_desc_unused(adapter->tx_ring) >= size)
4940 return 0;
4941 return __e1000_maybe_stop_tx(netdev, size);
4942}
4943
4944#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004945static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4946 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004947{
4948 struct e1000_adapter *adapter = netdev_priv(netdev);
4949 struct e1000_ring *tx_ring = adapter->tx_ring;
4950 unsigned int first;
4951 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4952 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4953 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004954 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004955 unsigned int nr_frags;
4956 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004957 int count = 0;
4958 int tso;
4959 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004960
4961 if (test_bit(__E1000_DOWN, &adapter->state)) {
4962 dev_kfree_skb_any(skb);
4963 return NETDEV_TX_OK;
4964 }
4965
4966 if (skb->len <= 0) {
4967 dev_kfree_skb_any(skb);
4968 return NETDEV_TX_OK;
4969 }
4970
4971 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004972 /*
4973 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004974 * make sure there is enough room in the FIFO before
4975 * initiating the DMA for each buffer. The calc is:
4976 * 4 = ceil(buffer len/mss). To make sure we don't
4977 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004978 * drops.
4979 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004980 if (mss) {
4981 u8 hdr_len;
4982 max_per_txd = min(mss << 2, max_per_txd);
4983 max_txd_pwr = fls(max_per_txd) - 1;
4984
Bruce Allanad680762008-03-28 09:15:03 -07004985 /*
4986 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4987 * points to just header, pull a few bytes of payload from
4988 * frags into skb->data
4989 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004990 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004991 /*
4992 * we do this workaround for ES2LAN, but it is un-necessary,
4993 * avoiding it could save a lot of cycles
4994 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004995 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004996 unsigned int pull_size;
4997
4998 pull_size = min((unsigned int)4, skb->data_len);
4999 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005000 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005001 dev_kfree_skb_any(skb);
5002 return NETDEV_TX_OK;
5003 }
Eric Dumazete743d312010-04-14 15:59:40 -07005004 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005005 }
5006 }
5007
5008 /* reserve a descriptor for the offload context */
5009 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5010 count++;
5011 count++;
5012
5013 count += TXD_USE_COUNT(len, max_txd_pwr);
5014
5015 nr_frags = skb_shinfo(skb)->nr_frags;
5016 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00005017 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07005018 max_txd_pwr);
5019
5020 if (adapter->hw.mac.tx_pkt_filtering)
5021 e1000_transfer_dhcp_info(adapter, skb);
5022
Bruce Allanad680762008-03-28 09:15:03 -07005023 /*
5024 * need: count + 2 desc gap to keep tail from touching
5025 * head, otherwise try next time
5026 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00005027 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005028 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005029
Jesse Grosseab6d182010-10-20 13:56:03 +00005030 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005031 tx_flags |= E1000_TX_FLAGS_VLAN;
5032 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5033 }
5034
5035 first = tx_ring->next_to_use;
5036
5037 tso = e1000_tso(adapter, skb);
5038 if (tso < 0) {
5039 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005040 return NETDEV_TX_OK;
5041 }
5042
5043 if (tso)
5044 tx_flags |= E1000_TX_FLAGS_TSO;
5045 else if (e1000_tx_csum(adapter, skb))
5046 tx_flags |= E1000_TX_FLAGS_CSUM;
5047
Bruce Allanad680762008-03-28 09:15:03 -07005048 /*
5049 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005050 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005051 * no longer assume, we must.
5052 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005053 if (skb->protocol == htons(ETH_P_IP))
5054 tx_flags |= E1000_TX_FLAGS_IPV4;
5055
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005056 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005057 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005058 if (count) {
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005059 netdev_sent_queue(netdev, skb->len);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005060 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005061 /* Make sure there is space in the ring for the next send. */
5062 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
5063
5064 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005065 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005066 tx_ring->buffer_info[first].time_stamp = 0;
5067 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005068 }
5069
Auke Kokbc7f75f2007-09-17 12:30:59 -07005070 return NETDEV_TX_OK;
5071}
5072
5073/**
5074 * e1000_tx_timeout - Respond to a Tx Hang
5075 * @netdev: network interface device structure
5076 **/
5077static void e1000_tx_timeout(struct net_device *netdev)
5078{
5079 struct e1000_adapter *adapter = netdev_priv(netdev);
5080
5081 /* Do the reset outside of interrupt context */
5082 adapter->tx_timeout_count++;
5083 schedule_work(&adapter->reset_task);
5084}
5085
5086static void e1000_reset_task(struct work_struct *work)
5087{
5088 struct e1000_adapter *adapter;
5089 adapter = container_of(work, struct e1000_adapter, reset_task);
5090
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005091 /* don't run the task if already down */
5092 if (test_bit(__E1000_DOWN, &adapter->state))
5093 return;
5094
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005095 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5096 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5097 e1000e_dump(adapter);
5098 e_err("Reset adapter\n");
5099 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005100 e1000e_reinit_locked(adapter);
5101}
5102
5103/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005104 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005105 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005106 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107 *
5108 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005109 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005110struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5111 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005112{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005113 struct e1000_adapter *adapter = netdev_priv(netdev);
5114
5115 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5116 spin_lock(&adapter->stats64_lock);
5117 e1000e_update_stats(adapter);
5118 /* Fill out the OS statistics structure */
5119 stats->rx_bytes = adapter->stats.gorc;
5120 stats->rx_packets = adapter->stats.gprc;
5121 stats->tx_bytes = adapter->stats.gotc;
5122 stats->tx_packets = adapter->stats.gptc;
5123 stats->multicast = adapter->stats.mprc;
5124 stats->collisions = adapter->stats.colc;
5125
5126 /* Rx Errors */
5127
5128 /*
5129 * RLEC on some newer hardware can be incorrect so build
5130 * our own version based on RUC and ROC
5131 */
5132 stats->rx_errors = adapter->stats.rxerrc +
5133 adapter->stats.crcerrs + adapter->stats.algnerrc +
5134 adapter->stats.ruc + adapter->stats.roc +
5135 adapter->stats.cexterr;
5136 stats->rx_length_errors = adapter->stats.ruc +
5137 adapter->stats.roc;
5138 stats->rx_crc_errors = adapter->stats.crcerrs;
5139 stats->rx_frame_errors = adapter->stats.algnerrc;
5140 stats->rx_missed_errors = adapter->stats.mpc;
5141
5142 /* Tx Errors */
5143 stats->tx_errors = adapter->stats.ecol +
5144 adapter->stats.latecol;
5145 stats->tx_aborted_errors = adapter->stats.ecol;
5146 stats->tx_window_errors = adapter->stats.latecol;
5147 stats->tx_carrier_errors = adapter->stats.tncrs;
5148
5149 /* Tx Dropped needs to be maintained elsewhere */
5150
5151 spin_unlock(&adapter->stats64_lock);
5152 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005153}
5154
5155/**
5156 * e1000_change_mtu - Change the Maximum Transfer Unit
5157 * @netdev: network interface device structure
5158 * @new_mtu: new value for maximum frame size
5159 *
5160 * Returns 0 on success, negative on failure
5161 **/
5162static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5163{
5164 struct e1000_adapter *adapter = netdev_priv(netdev);
5165 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5166
Bruce Allan2adc55c2009-06-02 11:28:58 +00005167 /* Jumbo frame support */
5168 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5169 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5170 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005171 return -EINVAL;
5172 }
5173
Bruce Allan2adc55c2009-06-02 11:28:58 +00005174 /* Supported frame sizes */
5175 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5176 (max_frame > adapter->max_hw_frame_size)) {
5177 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005178 return -EINVAL;
5179 }
5180
Bruce Allana1ce6472010-09-22 17:16:40 +00005181 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5182 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5183 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5184 (new_mtu > ETH_DATA_LEN)) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00005185 e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005186 return -EINVAL;
5187 }
5188
Bruce Allan6f461f62010-04-27 03:33:04 +00005189 /* 82573 Errata 17 */
5190 if (((adapter->hw.mac.type == e1000_82573) ||
5191 (adapter->hw.mac.type == e1000_82574)) &&
5192 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5193 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5194 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5195 }
5196
Auke Kokbc7f75f2007-09-17 12:30:59 -07005197 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005198 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005199 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005200 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005201 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5202 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005203 if (netif_running(netdev))
5204 e1000e_down(adapter);
5205
Bruce Allanad680762008-03-28 09:15:03 -07005206 /*
5207 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005208 * means we reserve 2 more, this pushes us to allocate from the next
5209 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005210 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005211 * However with the new *_jumbo_rx* routines, jumbo receives will use
5212 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005213 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005214
Jesse Brandeburg99261462010-01-22 22:56:16 +00005215 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005216 adapter->rx_buffer_len = 2048;
5217 else
5218 adapter->rx_buffer_len = 4096;
5219
5220 /* adjust allocation if LPE protects us, and we aren't using SBP */
5221 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5222 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5223 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005224 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005225
Auke Kokbc7f75f2007-09-17 12:30:59 -07005226 if (netif_running(netdev))
5227 e1000e_up(adapter);
5228 else
5229 e1000e_reset(adapter);
5230
5231 clear_bit(__E1000_RESETTING, &adapter->state);
5232
5233 return 0;
5234}
5235
5236static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5237 int cmd)
5238{
5239 struct e1000_adapter *adapter = netdev_priv(netdev);
5240 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005241
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005242 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005243 return -EOPNOTSUPP;
5244
5245 switch (cmd) {
5246 case SIOCGMIIPHY:
5247 data->phy_id = adapter->hw.phy.addr;
5248 break;
5249 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005250 e1000_phy_read_status(adapter);
5251
Bruce Allan7c257692008-04-23 11:09:00 -07005252 switch (data->reg_num & 0x1F) {
5253 case MII_BMCR:
5254 data->val_out = adapter->phy_regs.bmcr;
5255 break;
5256 case MII_BMSR:
5257 data->val_out = adapter->phy_regs.bmsr;
5258 break;
5259 case MII_PHYSID1:
5260 data->val_out = (adapter->hw.phy.id >> 16);
5261 break;
5262 case MII_PHYSID2:
5263 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5264 break;
5265 case MII_ADVERTISE:
5266 data->val_out = adapter->phy_regs.advertise;
5267 break;
5268 case MII_LPA:
5269 data->val_out = adapter->phy_regs.lpa;
5270 break;
5271 case MII_EXPANSION:
5272 data->val_out = adapter->phy_regs.expansion;
5273 break;
5274 case MII_CTRL1000:
5275 data->val_out = adapter->phy_regs.ctrl1000;
5276 break;
5277 case MII_STAT1000:
5278 data->val_out = adapter->phy_regs.stat1000;
5279 break;
5280 case MII_ESTATUS:
5281 data->val_out = adapter->phy_regs.estatus;
5282 break;
5283 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005284 return -EIO;
5285 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005286 break;
5287 case SIOCSMIIREG:
5288 default:
5289 return -EOPNOTSUPP;
5290 }
5291 return 0;
5292}
5293
5294static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5295{
5296 switch (cmd) {
5297 case SIOCGMIIPHY:
5298 case SIOCGMIIREG:
5299 case SIOCSMIIREG:
5300 return e1000_mii_ioctl(netdev, ifr, cmd);
5301 default:
5302 return -EOPNOTSUPP;
5303 }
5304}
5305
Bruce Allana4f58f52009-06-02 11:29:18 +00005306static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5307{
5308 struct e1000_hw *hw = &adapter->hw;
5309 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005310 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005311 int retval = 0;
5312
5313 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005314 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005315
Bruce Allan2b6b1682011-05-13 07:20:09 +00005316 retval = hw->phy.ops.acquire(hw);
5317 if (retval) {
5318 e_err("Could not acquire PHY\n");
5319 return retval;
5320 }
5321
5322 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5323 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5324 if (retval)
5325 goto out;
5326
5327 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005328 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5329 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005330 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5331 (u16)(mac_reg & 0xFFFF));
5332 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5333 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005334 }
5335
5336 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005337 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005338 mac_reg = er32(RCTL);
5339 if (mac_reg & E1000_RCTL_UPE)
5340 phy_reg |= BM_RCTL_UPE;
5341 if (mac_reg & E1000_RCTL_MPE)
5342 phy_reg |= BM_RCTL_MPE;
5343 phy_reg &= ~(BM_RCTL_MO_MASK);
5344 if (mac_reg & E1000_RCTL_MO_3)
5345 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5346 << BM_RCTL_MO_SHIFT);
5347 if (mac_reg & E1000_RCTL_BAM)
5348 phy_reg |= BM_RCTL_BAM;
5349 if (mac_reg & E1000_RCTL_PMCF)
5350 phy_reg |= BM_RCTL_PMCF;
5351 mac_reg = er32(CTRL);
5352 if (mac_reg & E1000_CTRL_RFCE)
5353 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005354 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005355
5356 /* enable PHY wakeup in MAC register */
5357 ew32(WUFC, wufc);
5358 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5359
5360 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005361 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5362 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005363
5364 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005365 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5366 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005367 if (retval)
5368 e_err("Could not set PHY Host Wakeup bit\n");
5369out:
Bruce Allan94d81862009-11-20 23:25:26 +00005370 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005371
5372 return retval;
5373}
5374
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005375static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5376 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005377{
5378 struct net_device *netdev = pci_get_drvdata(pdev);
5379 struct e1000_adapter *adapter = netdev_priv(netdev);
5380 struct e1000_hw *hw = &adapter->hw;
5381 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005382 /* Runtime suspend should only enable wakeup for link changes */
5383 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005384 int retval = 0;
5385
5386 netif_device_detach(netdev);
5387
5388 if (netif_running(netdev)) {
5389 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5390 e1000e_down(adapter);
5391 e1000_free_irq(adapter);
5392 }
Bruce Allan4662e822008-08-26 18:37:06 -07005393 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005394
5395 retval = pci_save_state(pdev);
5396 if (retval)
5397 return retval;
5398
5399 status = er32(STATUS);
5400 if (status & E1000_STATUS_LU)
5401 wufc &= ~E1000_WUFC_LNKC;
5402
5403 if (wufc) {
5404 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005405 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005406
5407 /* turn on all-multi mode if wake on multicast is enabled */
5408 if (wufc & E1000_WUFC_MC) {
5409 rctl = er32(RCTL);
5410 rctl |= E1000_RCTL_MPE;
5411 ew32(RCTL, rctl);
5412 }
5413
5414 ctrl = er32(CTRL);
5415 /* advertise wake from D3Cold */
5416 #define E1000_CTRL_ADVD3WUC 0x00100000
5417 /* phy power management enable */
5418 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005419 ctrl |= E1000_CTRL_ADVD3WUC;
5420 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5421 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005422 ew32(CTRL, ctrl);
5423
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005424 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5425 adapter->hw.phy.media_type ==
5426 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005427 /* keep the laser running in D3 */
5428 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005429 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005430 ew32(CTRL_EXT, ctrl_ext);
5431 }
5432
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005433 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005434 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005435
Auke Kokbc7f75f2007-09-17 12:30:59 -07005436 /* Allow time for pending master requests to run */
5437 e1000e_disable_pcie_master(&adapter->hw);
5438
Bruce Allan82776a42009-08-14 14:35:33 +00005439 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005440 /* enable wakeup by the PHY */
5441 retval = e1000_init_phy_wakeup(adapter, wufc);
5442 if (retval)
5443 return retval;
5444 } else {
5445 /* enable wakeup by the MAC */
5446 ew32(WUFC, wufc);
5447 ew32(WUC, E1000_WUC_PME_EN);
5448 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005449 } else {
5450 ew32(WUC, 0);
5451 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005452 }
5453
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005454 *enable_wake = !!wufc;
5455
Auke Kokbc7f75f2007-09-17 12:30:59 -07005456 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005457 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5458 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005459 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005460
5461 if (adapter->hw.phy.type == e1000_phy_igp_3)
5462 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5463
Bruce Allanad680762008-03-28 09:15:03 -07005464 /*
5465 * Release control of h/w to f/w. If f/w is AMT enabled, this
5466 * would have already happened in close and is redundant.
5467 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005468 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005469
5470 pci_disable_device(pdev);
5471
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005472 return 0;
5473}
5474
5475static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5476{
5477 if (sleep && wake) {
5478 pci_prepare_to_sleep(pdev);
5479 return;
5480 }
5481
5482 pci_wake_from_d3(pdev, wake);
5483 pci_set_power_state(pdev, PCI_D3hot);
5484}
5485
5486static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5487 bool wake)
5488{
5489 struct net_device *netdev = pci_get_drvdata(pdev);
5490 struct e1000_adapter *adapter = netdev_priv(netdev);
5491
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005492 /*
5493 * The pci-e switch on some quad port adapters will report a
5494 * correctable error when the MAC transitions from D0 to D3. To
5495 * prevent this we need to mask off the correctable errors on the
5496 * downstream port of the pci-e switch.
5497 */
5498 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5499 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005500 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005501 u16 devctl;
5502
5503 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5504 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5505 (devctl & ~PCI_EXP_DEVCTL_CERE));
5506
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005507 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005508
5509 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5510 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005511 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005512 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005513}
5514
Bruce Allan6f461f62010-04-27 03:33:04 +00005515#ifdef CONFIG_PCIEASPM
5516static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5517{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005518 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005519}
5520#else
5521static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005522{
5523 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005524 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005525
5526 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005527 * Both device and parent should have the same ASPM setting.
5528 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005529 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005530 pos = pci_pcie_cap(pdev);
5531 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5532 reg16 &= ~state;
5533 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5534
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005535 if (!pdev->bus->self)
5536 return;
5537
Bruce Allan6f461f62010-04-27 03:33:04 +00005538 pos = pci_pcie_cap(pdev->bus->self);
5539 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5540 reg16 &= ~state;
5541 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5542}
5543#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005544static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005545{
5546 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5547 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5548 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5549
5550 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005551}
5552
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005553#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005554static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005555{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005556 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005557}
5558
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005559static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005560{
5561 struct net_device *netdev = pci_get_drvdata(pdev);
5562 struct e1000_adapter *adapter = netdev_priv(netdev);
5563 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005564 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005565 u32 err;
5566
Bruce Allan78cd29d2011-03-24 03:09:03 +00005567 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5568 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5569 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5570 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5571 if (aspm_disable_flag)
5572 e1000e_disable_aspm(pdev, aspm_disable_flag);
5573
Auke Kokbc7f75f2007-09-17 12:30:59 -07005574 pci_set_power_state(pdev, PCI_D0);
5575 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005576 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005577
Bruce Allan4662e822008-08-26 18:37:06 -07005578 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005579 if (netif_running(netdev)) {
5580 err = e1000_request_irq(adapter);
5581 if (err)
5582 return err;
5583 }
5584
Bruce Allan99730e42011-05-13 07:19:48 +00005585 if (hw->mac.type == e1000_pch2lan)
5586 e1000_resume_workarounds_pchlan(&adapter->hw);
5587
Auke Kokbc7f75f2007-09-17 12:30:59 -07005588 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005589
5590 /* report the system wakeup cause from S3/S4 */
5591 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5592 u16 phy_data;
5593
5594 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5595 if (phy_data) {
5596 e_info("PHY Wakeup cause - %s\n",
5597 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5598 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5599 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5600 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005601 phy_data & E1000_WUS_LNKC ?
5602 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005603 }
5604 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5605 } else {
5606 u32 wus = er32(WUS);
5607 if (wus) {
5608 e_info("MAC Wakeup cause - %s\n",
5609 wus & E1000_WUS_EX ? "Unicast Packet" :
5610 wus & E1000_WUS_MC ? "Multicast Packet" :
5611 wus & E1000_WUS_BC ? "Broadcast Packet" :
5612 wus & E1000_WUS_MAG ? "Magic Packet" :
5613 wus & E1000_WUS_LNKC ? "Link Status Change" :
5614 "other");
5615 }
5616 ew32(WUS, ~0);
5617 }
5618
Auke Kokbc7f75f2007-09-17 12:30:59 -07005619 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005620
Bruce Allancd791612010-05-10 14:59:51 +00005621 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005622
5623 if (netif_running(netdev))
5624 e1000e_up(adapter);
5625
5626 netif_device_attach(netdev);
5627
Bruce Allanad680762008-03-28 09:15:03 -07005628 /*
5629 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005630 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005631 * under the control of the driver.
5632 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005633 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005634 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005635
5636 return 0;
5637}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005638
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005639#ifdef CONFIG_PM_SLEEP
5640static int e1000_suspend(struct device *dev)
5641{
5642 struct pci_dev *pdev = to_pci_dev(dev);
5643 int retval;
5644 bool wake;
5645
5646 retval = __e1000_shutdown(pdev, &wake, false);
5647 if (!retval)
5648 e1000_complete_shutdown(pdev, true, wake);
5649
5650 return retval;
5651}
5652
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005653static int e1000_resume(struct device *dev)
5654{
5655 struct pci_dev *pdev = to_pci_dev(dev);
5656 struct net_device *netdev = pci_get_drvdata(pdev);
5657 struct e1000_adapter *adapter = netdev_priv(netdev);
5658
5659 if (e1000e_pm_ready(adapter))
5660 adapter->idle_check = true;
5661
5662 return __e1000_resume(pdev);
5663}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005664#endif /* CONFIG_PM_SLEEP */
5665
5666#ifdef CONFIG_PM_RUNTIME
5667static int e1000_runtime_suspend(struct device *dev)
5668{
5669 struct pci_dev *pdev = to_pci_dev(dev);
5670 struct net_device *netdev = pci_get_drvdata(pdev);
5671 struct e1000_adapter *adapter = netdev_priv(netdev);
5672
5673 if (e1000e_pm_ready(adapter)) {
5674 bool wake;
5675
5676 __e1000_shutdown(pdev, &wake, true);
5677 }
5678
5679 return 0;
5680}
5681
5682static int e1000_idle(struct device *dev)
5683{
5684 struct pci_dev *pdev = to_pci_dev(dev);
5685 struct net_device *netdev = pci_get_drvdata(pdev);
5686 struct e1000_adapter *adapter = netdev_priv(netdev);
5687
5688 if (!e1000e_pm_ready(adapter))
5689 return 0;
5690
5691 if (adapter->idle_check) {
5692 adapter->idle_check = false;
5693 if (!e1000e_has_link(adapter))
5694 pm_schedule_suspend(dev, MSEC_PER_SEC);
5695 }
5696
5697 return -EBUSY;
5698}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005699
5700static int e1000_runtime_resume(struct device *dev)
5701{
5702 struct pci_dev *pdev = to_pci_dev(dev);
5703 struct net_device *netdev = pci_get_drvdata(pdev);
5704 struct e1000_adapter *adapter = netdev_priv(netdev);
5705
5706 if (!e1000e_pm_ready(adapter))
5707 return 0;
5708
5709 adapter->idle_check = !dev->power.runtime_auto;
5710 return __e1000_resume(pdev);
5711}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005712#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005713#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005714
5715static void e1000_shutdown(struct pci_dev *pdev)
5716{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005717 bool wake = false;
5718
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005719 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005720
5721 if (system_state == SYSTEM_POWER_OFF)
5722 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005723}
5724
5725#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005726
5727static irqreturn_t e1000_intr_msix(int irq, void *data)
5728{
5729 struct net_device *netdev = data;
5730 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005731
5732 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005733 int vector, msix_irq;
5734
Dongdong Deng147b2c82010-11-16 19:50:15 -08005735 vector = 0;
5736 msix_irq = adapter->msix_entries[vector].vector;
5737 disable_irq(msix_irq);
5738 e1000_intr_msix_rx(msix_irq, netdev);
5739 enable_irq(msix_irq);
5740
5741 vector++;
5742 msix_irq = adapter->msix_entries[vector].vector;
5743 disable_irq(msix_irq);
5744 e1000_intr_msix_tx(msix_irq, netdev);
5745 enable_irq(msix_irq);
5746
5747 vector++;
5748 msix_irq = adapter->msix_entries[vector].vector;
5749 disable_irq(msix_irq);
5750 e1000_msix_other(msix_irq, netdev);
5751 enable_irq(msix_irq);
5752 }
5753
5754 return IRQ_HANDLED;
5755}
5756
Auke Kokbc7f75f2007-09-17 12:30:59 -07005757/*
5758 * Polling 'interrupt' - used by things like netconsole to send skbs
5759 * without having to re-enable interrupts. It's not called while
5760 * the interrupt routine is executing.
5761 */
5762static void e1000_netpoll(struct net_device *netdev)
5763{
5764 struct e1000_adapter *adapter = netdev_priv(netdev);
5765
Dongdong Deng147b2c82010-11-16 19:50:15 -08005766 switch (adapter->int_mode) {
5767 case E1000E_INT_MODE_MSIX:
5768 e1000_intr_msix(adapter->pdev->irq, netdev);
5769 break;
5770 case E1000E_INT_MODE_MSI:
5771 disable_irq(adapter->pdev->irq);
5772 e1000_intr_msi(adapter->pdev->irq, netdev);
5773 enable_irq(adapter->pdev->irq);
5774 break;
5775 default: /* E1000E_INT_MODE_LEGACY */
5776 disable_irq(adapter->pdev->irq);
5777 e1000_intr(adapter->pdev->irq, netdev);
5778 enable_irq(adapter->pdev->irq);
5779 break;
5780 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005781}
5782#endif
5783
5784/**
5785 * e1000_io_error_detected - called when PCI error is detected
5786 * @pdev: Pointer to PCI device
5787 * @state: The current pci connection state
5788 *
5789 * This function is called after a PCI bus error affecting
5790 * this device has been detected.
5791 */
5792static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5793 pci_channel_state_t state)
5794{
5795 struct net_device *netdev = pci_get_drvdata(pdev);
5796 struct e1000_adapter *adapter = netdev_priv(netdev);
5797
5798 netif_device_detach(netdev);
5799
Mike Masonc93b5a72009-06-30 12:45:53 +00005800 if (state == pci_channel_io_perm_failure)
5801 return PCI_ERS_RESULT_DISCONNECT;
5802
Auke Kokbc7f75f2007-09-17 12:30:59 -07005803 if (netif_running(netdev))
5804 e1000e_down(adapter);
5805 pci_disable_device(pdev);
5806
5807 /* Request a slot slot reset. */
5808 return PCI_ERS_RESULT_NEED_RESET;
5809}
5810
5811/**
5812 * e1000_io_slot_reset - called after the pci bus has been reset.
5813 * @pdev: Pointer to PCI device
5814 *
5815 * Restart the card from scratch, as if from a cold-boot. Implementation
5816 * resembles the first-half of the e1000_resume routine.
5817 */
5818static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5819{
5820 struct net_device *netdev = pci_get_drvdata(pdev);
5821 struct e1000_adapter *adapter = netdev_priv(netdev);
5822 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005823 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005824 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005825 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005826
Bruce Allan78cd29d2011-03-24 03:09:03 +00005827 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5828 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005829 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005830 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5831 if (aspm_disable_flag)
5832 e1000e_disable_aspm(pdev, aspm_disable_flag);
5833
Bruce Allanf0f422e2008-08-04 17:21:53 -07005834 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005835 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005836 dev_err(&pdev->dev,
5837 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005838 result = PCI_ERS_RESULT_DISCONNECT;
5839 } else {
5840 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005841 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005842 pci_restore_state(pdev);
5843
5844 pci_enable_wake(pdev, PCI_D3hot, 0);
5845 pci_enable_wake(pdev, PCI_D3cold, 0);
5846
5847 e1000e_reset(adapter);
5848 ew32(WUS, ~0);
5849 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005850 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005851
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005852 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005853
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005854 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005855}
5856
5857/**
5858 * e1000_io_resume - called when traffic can start flowing again.
5859 * @pdev: Pointer to PCI device
5860 *
5861 * This callback is called when the error recovery driver tells us that
5862 * its OK to resume normal operation. Implementation resembles the
5863 * second-half of the e1000_resume routine.
5864 */
5865static void e1000_io_resume(struct pci_dev *pdev)
5866{
5867 struct net_device *netdev = pci_get_drvdata(pdev);
5868 struct e1000_adapter *adapter = netdev_priv(netdev);
5869
Bruce Allancd791612010-05-10 14:59:51 +00005870 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005871
5872 if (netif_running(netdev)) {
5873 if (e1000e_up(adapter)) {
5874 dev_err(&pdev->dev,
5875 "can't bring device back up after reset\n");
5876 return;
5877 }
5878 }
5879
5880 netif_device_attach(netdev);
5881
Bruce Allanad680762008-03-28 09:15:03 -07005882 /*
5883 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005884 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005885 * under the control of the driver.
5886 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005887 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005888 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005889
5890}
5891
5892static void e1000_print_device_info(struct e1000_adapter *adapter)
5893{
5894 struct e1000_hw *hw = &adapter->hw;
5895 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005896 u32 ret_val;
5897 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005898
5899 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005900 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005901 /* bus width */
5902 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5903 "Width x1"),
5904 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005905 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005906 e_info("Intel(R) PRO/%s Network Connection\n",
5907 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005908 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5909 E1000_PBANUM_LENGTH);
5910 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005911 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005912 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5913 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005914}
5915
Auke Kok10aa4c02008-08-04 17:21:20 -07005916static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5917{
5918 struct e1000_hw *hw = &adapter->hw;
5919 int ret_val;
5920 u16 buf = 0;
5921
5922 if (hw->mac.type != e1000_82573)
5923 return;
5924
5925 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005926 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005927 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005928 dev_warn(&adapter->pdev->dev,
5929 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005930 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005931}
5932
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005933static int e1000_set_features(struct net_device *netdev,
5934 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00005935{
5936 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005937 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00005938
5939 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5940 adapter->flags |= FLAG_TSO_FORCE;
5941
5942 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
5943 NETIF_F_RXCSUM)))
5944 return 0;
5945
5946 if (netif_running(netdev))
5947 e1000e_reinit_locked(adapter);
5948 else
5949 e1000e_reset(adapter);
5950
5951 return 0;
5952}
5953
Stephen Hemminger651c2462008-11-19 21:57:48 -08005954static const struct net_device_ops e1000e_netdev_ops = {
5955 .ndo_open = e1000_open,
5956 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005957 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005958 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005959 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005960 .ndo_set_mac_address = e1000_set_mac,
5961 .ndo_change_mtu = e1000_change_mtu,
5962 .ndo_do_ioctl = e1000_ioctl,
5963 .ndo_tx_timeout = e1000_tx_timeout,
5964 .ndo_validate_addr = eth_validate_addr,
5965
Stephen Hemminger651c2462008-11-19 21:57:48 -08005966 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5967 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5968#ifdef CONFIG_NET_POLL_CONTROLLER
5969 .ndo_poll_controller = e1000_netpoll,
5970#endif
Bruce Allandc221292011-08-19 03:23:48 +00005971 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005972};
5973
Auke Kokbc7f75f2007-09-17 12:30:59 -07005974/**
5975 * e1000_probe - Device Initialization Routine
5976 * @pdev: PCI device information struct
5977 * @ent: entry in e1000_pci_tbl
5978 *
5979 * Returns 0 on success, negative on failure
5980 *
5981 * e1000_probe initializes an adapter identified by a pci_dev structure.
5982 * The OS initialization, configuring of the adapter private structure,
5983 * and a hardware reset occur.
5984 **/
5985static int __devinit e1000_probe(struct pci_dev *pdev,
5986 const struct pci_device_id *ent)
5987{
5988 struct net_device *netdev;
5989 struct e1000_adapter *adapter;
5990 struct e1000_hw *hw;
5991 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005992 resource_size_t mmio_start, mmio_len;
5993 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005994
5995 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005996 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005997 int i, err, pci_using_dac;
5998 u16 eeprom_data = 0;
5999 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6000
Bruce Allan78cd29d2011-03-24 03:09:03 +00006001 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6002 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006003 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006004 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6005 if (aspm_disable_flag)
6006 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006007
Bruce Allanf0f422e2008-08-04 17:21:53 -07006008 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006009 if (err)
6010 return err;
6011
6012 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006013 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006014 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006015 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006016 if (!err)
6017 pci_using_dac = 1;
6018 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006019 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006020 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006021 err = dma_set_coherent_mask(&pdev->dev,
6022 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006023 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006024 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006025 goto err_dma;
6026 }
6027 }
6028 }
6029
Arjan van de Vene8de1482008-10-22 19:55:31 -07006030 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006031 pci_select_bars(pdev, IORESOURCE_MEM),
6032 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006033 if (err)
6034 goto err_pci_reg;
6035
Xiaotian Feng68eac462009-08-14 14:35:52 +00006036 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006037 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006038
Auke Kokbc7f75f2007-09-17 12:30:59 -07006039 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006040 /* PCI config space info */
6041 err = pci_save_state(pdev);
6042 if (err)
6043 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006044
6045 err = -ENOMEM;
6046 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6047 if (!netdev)
6048 goto err_alloc_etherdev;
6049
Auke Kokbc7f75f2007-09-17 12:30:59 -07006050 SET_NETDEV_DEV(netdev, &pdev->dev);
6051
Tom Herbertf85e4df2010-05-05 14:03:32 +00006052 netdev->irq = pdev->irq;
6053
Auke Kokbc7f75f2007-09-17 12:30:59 -07006054 pci_set_drvdata(pdev, netdev);
6055 adapter = netdev_priv(netdev);
6056 hw = &adapter->hw;
6057 adapter->netdev = netdev;
6058 adapter->pdev = pdev;
6059 adapter->ei = ei;
6060 adapter->pba = ei->pba;
6061 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006062 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006063 adapter->hw.adapter = adapter;
6064 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006065 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006066 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6067
6068 mmio_start = pci_resource_start(pdev, 0);
6069 mmio_len = pci_resource_len(pdev, 0);
6070
6071 err = -EIO;
6072 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6073 if (!adapter->hw.hw_addr)
6074 goto err_ioremap;
6075
6076 if ((adapter->flags & FLAG_HAS_FLASH) &&
6077 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6078 flash_start = pci_resource_start(pdev, 1);
6079 flash_len = pci_resource_len(pdev, 1);
6080 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6081 if (!adapter->hw.flash_address)
6082 goto err_flashmap;
6083 }
6084
6085 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006086 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006087 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006088 netdev->watchdog_timeo = 5 * HZ;
6089 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006090 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
6091
6092 netdev->mem_start = mmio_start;
6093 netdev->mem_end = mmio_start + mmio_len;
6094
6095 adapter->bd_number = cards_found++;
6096
Bruce Allan4662e822008-08-26 18:37:06 -07006097 e1000e_check_options(adapter);
6098
Auke Kokbc7f75f2007-09-17 12:30:59 -07006099 /* setup adapter struct */
6100 err = e1000_sw_init(adapter);
6101 if (err)
6102 goto err_sw_init;
6103
Auke Kokbc7f75f2007-09-17 12:30:59 -07006104 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6105 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6106 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6107
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006108 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006109 if (err)
6110 goto err_hw_init;
6111
Bruce Allan4a770352008-10-01 17:18:35 -07006112 if ((adapter->flags & FLAG_IS_ICH) &&
6113 (adapter->flags & FLAG_READ_ONLY_NVM))
6114 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6115
Auke Kokbc7f75f2007-09-17 12:30:59 -07006116 hw->mac.ops.get_bus_info(&adapter->hw);
6117
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006118 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006119
6120 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006121 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006122 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6123 adapter->hw.phy.disable_polarity_correction = 0;
6124 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6125 }
6126
6127 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006128 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006129
Bruce Allandc221292011-08-19 03:23:48 +00006130 /* Set initial default active device features */
6131 netdev->features = (NETIF_F_SG |
6132 NETIF_F_HW_VLAN_RX |
6133 NETIF_F_HW_VLAN_TX |
6134 NETIF_F_TSO |
6135 NETIF_F_TSO6 |
6136 NETIF_F_RXCSUM |
6137 NETIF_F_HW_CSUM);
6138
6139 /* Set user-changeable features (subset of all device features) */
6140 netdev->hw_features = netdev->features;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006141
6142 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6143 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6144
Bruce Allandc221292011-08-19 03:23:48 +00006145 netdev->vlan_features |= (NETIF_F_SG |
6146 NETIF_F_TSO |
6147 NETIF_F_TSO6 |
6148 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006149
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006150 netdev->priv_flags |= IFF_UNICAST_FLT;
6151
Yi Zou7b872a52010-09-22 17:57:58 +00006152 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006153 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006154 netdev->vlan_features |= NETIF_F_HIGHDMA;
6155 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006156
Auke Kokbc7f75f2007-09-17 12:30:59 -07006157 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6158 adapter->flags |= FLAG_MNG_PT_ENABLED;
6159
Bruce Allanad680762008-03-28 09:15:03 -07006160 /*
6161 * before reading the NVM, reset the controller to
6162 * put the device in a known good starting state
6163 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006164 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6165
6166 /*
6167 * systems with ASPM and others may see the checksum fail on the first
6168 * attempt. Let's give it a few tries
6169 */
6170 for (i = 0;; i++) {
6171 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6172 break;
6173 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006174 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006175 err = -EIO;
6176 goto err_eeprom;
6177 }
6178 }
6179
Auke Kok10aa4c02008-08-04 17:21:20 -07006180 e1000_eeprom_checks(adapter);
6181
Bruce Allan608f8a02010-01-13 02:04:58 +00006182 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006183 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006184 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006185
6186 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6187 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6188
6189 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006190 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006191 err = -EIO;
6192 goto err_eeprom;
6193 }
6194
6195 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006196 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006197 adapter->watchdog_timer.data = (unsigned long) adapter;
6198
6199 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006200 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006201 adapter->phy_info_timer.data = (unsigned long) adapter;
6202
6203 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6204 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006205 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6206 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006207 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006208
Auke Kokbc7f75f2007-09-17 12:30:59 -07006209 /* Initialize link parameters. User can change them with ethtool */
6210 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07006211 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006212 adapter->hw.fc.requested_mode = e1000_fc_default;
6213 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006214 adapter->hw.phy.autoneg_advertised = 0x2f;
6215
6216 /* ring size defaults */
6217 adapter->rx_ring->count = 256;
6218 adapter->tx_ring->count = 256;
6219
6220 /*
6221 * Initial Wake on LAN setting - If APM wake is enabled in
6222 * the EEPROM, enable the ACPI Magic Packet filter
6223 */
6224 if (adapter->flags & FLAG_APME_IN_WUC) {
6225 /* APME bit in EEPROM is mapped to WUC.APME */
6226 eeprom_data = er32(WUC);
6227 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006228 if ((hw->mac.type > e1000_ich10lan) &&
6229 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006230 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006231 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6232 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6233 (adapter->hw.bus.func == 1))
6234 e1000_read_nvm(&adapter->hw,
6235 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6236 else
6237 e1000_read_nvm(&adapter->hw,
6238 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6239 }
6240
6241 /* fetch WoL from EEPROM */
6242 if (eeprom_data & eeprom_apme_mask)
6243 adapter->eeprom_wol |= E1000_WUFC_MAG;
6244
6245 /*
6246 * now that we have the eeprom settings, apply the special cases
6247 * where the eeprom may be wrong or the board simply won't support
6248 * wake on lan on a particular port
6249 */
6250 if (!(adapter->flags & FLAG_HAS_WOL))
6251 adapter->eeprom_wol = 0;
6252
6253 /* initialize the wol settings based on the eeprom settings */
6254 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006255 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006256
Bruce Allan84527592008-11-21 17:00:22 -08006257 /* save off EEPROM version number */
6258 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6259
Auke Kokbc7f75f2007-09-17 12:30:59 -07006260 /* reset the hardware with the new settings */
6261 e1000e_reset(adapter);
6262
Bruce Allanad680762008-03-28 09:15:03 -07006263 /*
6264 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006265 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006266 * under the control of the driver.
6267 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006268 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006269 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006270
Bruce Allane0dc4f12011-01-06 14:29:50 +00006271 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006272 err = register_netdev(netdev);
6273 if (err)
6274 goto err_register;
6275
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006276 /* carrier off reporting is important to ethtool even BEFORE open */
6277 netif_carrier_off(netdev);
6278
Auke Kokbc7f75f2007-09-17 12:30:59 -07006279 e1000_print_device_info(adapter);
6280
Alan Sternf3ec4f82010-06-08 15:23:51 -04006281 if (pci_dev_run_wake(pdev))
6282 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006283
Auke Kokbc7f75f2007-09-17 12:30:59 -07006284 return 0;
6285
6286err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006287 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006288 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006289err_eeprom:
6290 if (!e1000_check_reset_block(&adapter->hw))
6291 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006292err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006293 kfree(adapter->tx_ring);
6294 kfree(adapter->rx_ring);
6295err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006296 if (adapter->hw.flash_address)
6297 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006298 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006299err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006300 iounmap(adapter->hw.hw_addr);
6301err_ioremap:
6302 free_netdev(netdev);
6303err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006304 pci_release_selected_regions(pdev,
6305 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006306err_pci_reg:
6307err_dma:
6308 pci_disable_device(pdev);
6309 return err;
6310}
6311
6312/**
6313 * e1000_remove - Device Removal Routine
6314 * @pdev: PCI device information struct
6315 *
6316 * e1000_remove is called by the PCI subsystem to alert the driver
6317 * that it should release a PCI device. The could be caused by a
6318 * Hot-Plug event, or because the driver is going to be removed from
6319 * memory.
6320 **/
6321static void __devexit e1000_remove(struct pci_dev *pdev)
6322{
6323 struct net_device *netdev = pci_get_drvdata(pdev);
6324 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006325 bool down = test_bit(__E1000_DOWN, &adapter->state);
6326
Bruce Allanad680762008-03-28 09:15:03 -07006327 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006328 * The timers may be rescheduled, so explicitly disable them
6329 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006330 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006331 if (!down)
6332 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006333 del_timer_sync(&adapter->watchdog_timer);
6334 del_timer_sync(&adapter->phy_info_timer);
6335
Bruce Allan41cec6f2009-11-20 23:28:56 +00006336 cancel_work_sync(&adapter->reset_task);
6337 cancel_work_sync(&adapter->watchdog_task);
6338 cancel_work_sync(&adapter->downshift_task);
6339 cancel_work_sync(&adapter->update_phy_task);
6340 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006341
Bruce Allan17f208d2009-12-01 15:47:22 +00006342 if (!(netdev->flags & IFF_UP))
6343 e1000_power_down_phy(adapter);
6344
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006345 /* Don't lie to e1000_close() down the road. */
6346 if (!down)
6347 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006348 unregister_netdev(netdev);
6349
Alan Sternf3ec4f82010-06-08 15:23:51 -04006350 if (pci_dev_run_wake(pdev))
6351 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006352
Bruce Allanad680762008-03-28 09:15:03 -07006353 /*
6354 * Release control of h/w to f/w. If f/w is AMT enabled, this
6355 * would have already happened in close and is redundant.
6356 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006357 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006358
Bruce Allan4662e822008-08-26 18:37:06 -07006359 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006360 kfree(adapter->tx_ring);
6361 kfree(adapter->rx_ring);
6362
6363 iounmap(adapter->hw.hw_addr);
6364 if (adapter->hw.flash_address)
6365 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006366 pci_release_selected_regions(pdev,
6367 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006368
6369 free_netdev(netdev);
6370
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006371 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006372 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006373
Auke Kokbc7f75f2007-09-17 12:30:59 -07006374 pci_disable_device(pdev);
6375}
6376
6377/* PCI Error Recovery (ERS) */
6378static struct pci_error_handlers e1000_err_handler = {
6379 .error_detected = e1000_io_error_detected,
6380 .slot_reset = e1000_io_slot_reset,
6381 .resume = e1000_io_resume,
6382};
6383
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006384static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006385 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6386 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6387 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6388 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6389 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6390 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006391 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6392 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6393 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006394
Auke Kokbc7f75f2007-09-17 12:30:59 -07006395 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6396 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6397 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6398 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006399
Auke Kokbc7f75f2007-09-17 12:30:59 -07006400 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6401 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6402 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006403
Bruce Allan4662e822008-08-26 18:37:06 -07006404 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006405 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006406 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006407
Auke Kokbc7f75f2007-09-17 12:30:59 -07006408 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6409 board_80003es2lan },
6410 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6411 board_80003es2lan },
6412 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6413 board_80003es2lan },
6414 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6415 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006416
Auke Kokbc7f75f2007-09-17 12:30:59 -07006417 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6418 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6419 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6420 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6421 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6422 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6423 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006424 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006425
Auke Kokbc7f75f2007-09-17 12:30:59 -07006426 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6427 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6428 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6429 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6430 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006431 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006432 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6433 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6434 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6435
6436 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6437 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6438 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006439
Bruce Allanf4187b52008-08-26 18:36:50 -07006440 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6441 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006442 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006443
Bruce Allana4f58f52009-06-02 11:29:18 +00006444 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6445 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6446 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6447 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6448
Bruce Alland3738bb2010-06-16 13:27:28 +00006449 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6450 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6451
Auke Kokbc7f75f2007-09-17 12:30:59 -07006452 { } /* terminate list */
6453};
6454MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6455
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006456#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006457static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006458 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6459 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6460 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006461};
David S. Millere50208a2010-03-16 23:36:24 -07006462#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006463
Auke Kokbc7f75f2007-09-17 12:30:59 -07006464/* PCI Device API Driver */
6465static struct pci_driver e1000_driver = {
6466 .name = e1000e_driver_name,
6467 .id_table = e1000_pci_tbl,
6468 .probe = e1000_probe,
6469 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006470#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006471 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006472#endif
6473 .shutdown = e1000_shutdown,
6474 .err_handler = &e1000_err_handler
6475};
6476
6477/**
6478 * e1000_init_module - Driver Registration Routine
6479 *
6480 * e1000_init_module is the first routine called when the driver is
6481 * loaded. All it does is register with the PCI subsystem.
6482 **/
6483static int __init e1000_init_module(void)
6484{
6485 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006486 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6487 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006488 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006489 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006490
Auke Kokbc7f75f2007-09-17 12:30:59 -07006491 return ret;
6492}
6493module_init(e1000_init_module);
6494
6495/**
6496 * e1000_exit_module - Driver Exit Cleanup Routine
6497 *
6498 * e1000_exit_module is called just before the driver is removed
6499 * from memory.
6500 **/
6501static void __exit e1000_exit_module(void)
6502{
6503 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006504}
6505module_exit(e1000_exit_module);
6506
6507
6508MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6509MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6510MODULE_LICENSE("GPL");
6511MODULE_VERSION(DRV_VERSION);
6512
6513/* e1000_main.c */