blob: 4deb67d98e36297b54f8427673887b6a796a57c7 [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>
39#include <linux/tcp.h>
40#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/mii.h>
45#include <linux/ethtool.h>
46#include <linux/if_vlan.h>
47#include <linux/cpu.h>
48#include <linux/smp.h>
Bruce Allan97ac8ca2008-04-29 09:16:05 -070049#include <linux/pm_qos_params.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000050#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000051#include <linux/aer.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070052
53#include "e1000.h"
54
Bruce Allanc14c6432010-06-16 13:28:34 +000055#define DRV_EXTRAVERSION "-k2"
56
Bruce Allan70d279a2011-02-26 03:12:19 +000057#define DRV_VERSION "1.3.10" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070058char e1000e_driver_name[] = "e1000e";
59const char e1000e_driver_version[] = DRV_VERSION;
60
Bruce Allan78cd29d2011-03-24 03:09:03 +000061static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
62
Auke Kokbc7f75f2007-09-17 12:30:59 -070063static const struct e1000_info *e1000_info_tbl[] = {
64 [board_82571] = &e1000_82571_info,
65 [board_82572] = &e1000_82572_info,
66 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070067 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000068 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070069 [board_80003es2lan] = &e1000_es2_info,
70 [board_ich8lan] = &e1000_ich8_info,
71 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070072 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000073 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000074 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070075};
76
Taku Izumi84f4ee92010-04-27 14:39:08 +000077struct e1000_reg_info {
78 u32 ofs;
79 char *name;
80};
81
Bruce Allanaf667a22010-12-31 06:10:01 +000082#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
83#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
84#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
85#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
86#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000087
Bruce Allanaf667a22010-12-31 06:10:01 +000088#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
89#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
90#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
91#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
92#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000093
94static const struct e1000_reg_info e1000_reg_info_tbl[] = {
95
96 /* General Registers */
97 {E1000_CTRL, "CTRL"},
98 {E1000_STATUS, "STATUS"},
99 {E1000_CTRL_EXT, "CTRL_EXT"},
100
101 /* Interrupt Registers */
102 {E1000_ICR, "ICR"},
103
Bruce Allanaf667a22010-12-31 06:10:01 +0000104 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000105 {E1000_RCTL, "RCTL"},
106 {E1000_RDLEN, "RDLEN"},
107 {E1000_RDH, "RDH"},
108 {E1000_RDT, "RDT"},
109 {E1000_RDTR, "RDTR"},
110 {E1000_RXDCTL(0), "RXDCTL"},
111 {E1000_ERT, "ERT"},
112 {E1000_RDBAL, "RDBAL"},
113 {E1000_RDBAH, "RDBAH"},
114 {E1000_RDFH, "RDFH"},
115 {E1000_RDFT, "RDFT"},
116 {E1000_RDFHS, "RDFHS"},
117 {E1000_RDFTS, "RDFTS"},
118 {E1000_RDFPC, "RDFPC"},
119
Bruce Allanaf667a22010-12-31 06:10:01 +0000120 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000121 {E1000_TCTL, "TCTL"},
122 {E1000_TDBAL, "TDBAL"},
123 {E1000_TDBAH, "TDBAH"},
124 {E1000_TDLEN, "TDLEN"},
125 {E1000_TDH, "TDH"},
126 {E1000_TDT, "TDT"},
127 {E1000_TIDV, "TIDV"},
128 {E1000_TXDCTL(0), "TXDCTL"},
129 {E1000_TADV, "TADV"},
130 {E1000_TARC(0), "TARC"},
131 {E1000_TDFH, "TDFH"},
132 {E1000_TDFT, "TDFT"},
133 {E1000_TDFHS, "TDFHS"},
134 {E1000_TDFTS, "TDFTS"},
135 {E1000_TDFPC, "TDFPC"},
136
137 /* List Terminator */
138 {}
139};
140
141/*
142 * e1000_regdump - register printout routine
143 */
144static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
145{
146 int n = 0;
147 char rname[16];
148 u32 regs[8];
149
150 switch (reginfo->ofs) {
151 case E1000_RXDCTL(0):
152 for (n = 0; n < 2; n++)
153 regs[n] = __er32(hw, E1000_RXDCTL(n));
154 break;
155 case E1000_TXDCTL(0):
156 for (n = 0; n < 2; n++)
157 regs[n] = __er32(hw, E1000_TXDCTL(n));
158 break;
159 case E1000_TARC(0):
160 for (n = 0; n < 2; n++)
161 regs[n] = __er32(hw, E1000_TARC(n));
162 break;
163 default:
164 printk(KERN_INFO "%-15s %08x\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000165 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000166 return;
167 }
168
169 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
170 printk(KERN_INFO "%-15s ", rname);
171 for (n = 0; n < 2; n++)
172 printk(KERN_CONT "%08x ", regs[n]);
173 printk(KERN_CONT "\n");
174}
175
Taku Izumi84f4ee92010-04-27 14:39:08 +0000176/*
Bruce Allanaf667a22010-12-31 06:10:01 +0000177 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Taku Izumi84f4ee92010-04-27 14:39:08 +0000178 */
179static void e1000e_dump(struct e1000_adapter *adapter)
180{
181 struct net_device *netdev = adapter->netdev;
182 struct e1000_hw *hw = &adapter->hw;
183 struct e1000_reg_info *reginfo;
184 struct e1000_ring *tx_ring = adapter->tx_ring;
185 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000186 struct my_u0 {
187 u64 a;
188 u64 b;
189 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000190 struct e1000_buffer *buffer_info;
191 struct e1000_ring *rx_ring = adapter->rx_ring;
192 union e1000_rx_desc_packet_split *rx_desc_ps;
193 struct e1000_rx_desc *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000194 struct my_u1 {
195 u64 a;
196 u64 b;
197 u64 c;
198 u64 d;
199 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000200 u32 staterr;
201 int i = 0;
202
203 if (!netif_msg_hw(adapter))
204 return;
205
206 /* Print netdevice Info */
207 if (netdev) {
208 dev_info(&adapter->pdev->dev, "Net device Info\n");
209 printk(KERN_INFO "Device Name state "
Bruce Allanaf667a22010-12-31 06:10:01 +0000210 "trans_start last_rx\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000211 printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000212 netdev->name, netdev->state, netdev->trans_start,
213 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000214 }
215
216 /* Print Registers */
217 dev_info(&adapter->pdev->dev, "Register Dump\n");
218 printk(KERN_INFO " Register Name Value\n");
219 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
220 reginfo->name; reginfo++) {
221 e1000_regdump(hw, reginfo);
222 }
223
Bruce Allanaf667a22010-12-31 06:10:01 +0000224 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000225 if (!netdev || !netif_running(netdev))
226 goto exit;
227
Bruce Allanaf667a22010-12-31 06:10:01 +0000228 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000229 printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000230 " leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000231 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
232 printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000233 0, tx_ring->next_to_use, tx_ring->next_to_clean,
234 (unsigned long long)buffer_info->dma,
235 buffer_info->length,
236 buffer_info->next_to_watch,
237 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000238
Bruce Allanaf667a22010-12-31 06:10:01 +0000239 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000240 if (!netif_msg_tx_done(adapter))
241 goto rx_ring_summary;
242
Bruce Allanaf667a22010-12-31 06:10:01 +0000243 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000244
245 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
246 *
247 * Legacy Transmit Descriptor
248 * +--------------------------------------------------------------+
249 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
250 * +--------------------------------------------------------------+
251 * 8 | Special | CSS | Status | CMD | CSO | Length |
252 * +--------------------------------------------------------------+
253 * 63 48 47 36 35 32 31 24 23 16 15 0
254 *
255 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
256 * 63 48 47 40 39 32 31 16 15 8 7 0
257 * +----------------------------------------------------------------+
258 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
259 * +----------------------------------------------------------------+
260 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
261 * +----------------------------------------------------------------+
262 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
263 *
264 * Extended Data Descriptor (DTYP=0x1)
265 * +----------------------------------------------------------------+
266 * 0 | Buffer Address [63:0] |
267 * +----------------------------------------------------------------+
268 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
269 * +----------------------------------------------------------------+
270 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
271 */
272 printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000273 " [bi->dma ] leng ntw timestamp bi->skb "
274 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000275 printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000276 " [bi->dma ] leng ntw timestamp bi->skb "
277 "<-- Ext Context format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000278 printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000279 " [bi->dma ] leng ntw timestamp bi->skb "
280 "<-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000281 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
282 tx_desc = E1000_TX_DESC(*tx_ring, i);
283 buffer_info = &tx_ring->buffer_info[i];
284 u0 = (struct my_u0 *)tx_desc;
285 printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000286 "%04X %3X %016llX %p",
287 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
288 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), i,
Bruce Allan8eb64e62010-06-29 18:12:30 +0000289 (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,
Taku Izumi84f4ee92010-04-27 14:39:08 +0000294 buffer_info->skb);
295 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
296 printk(KERN_CONT " NTC/U\n");
297 else if (i == tx_ring->next_to_use)
298 printk(KERN_CONT " NTU\n");
299 else if (i == tx_ring->next_to_clean)
300 printk(KERN_CONT " NTC\n");
301 else
302 printk(KERN_CONT "\n");
303
304 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
305 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Bruce Allanaf667a22010-12-31 06:10:01 +0000306 16, 1, phys_to_virt(buffer_info->dma),
307 buffer_info->length, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000308 }
309
Bruce Allanaf667a22010-12-31 06:10:01 +0000310 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000311rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000312 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000313 printk(KERN_INFO "Queue [NTU] [NTC]\n");
314 printk(KERN_INFO " %5d %5X %5X\n", 0,
Bruce Allanaf667a22010-12-31 06:10:01 +0000315 rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000316
Bruce Allanaf667a22010-12-31 06:10:01 +0000317 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000318 if (!netif_msg_rx_status(adapter))
319 goto exit;
320
Bruce Allanaf667a22010-12-31 06:10:01 +0000321 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000322 switch (adapter->rx_ps_pages) {
323 case 1:
324 case 2:
325 case 3:
326 /* [Extended] Packet Split Receive Descriptor Format
327 *
328 * +-----------------------------------------------------+
329 * 0 | Buffer Address 0 [63:0] |
330 * +-----------------------------------------------------+
331 * 8 | Buffer Address 1 [63:0] |
332 * +-----------------------------------------------------+
333 * 16 | Buffer Address 2 [63:0] |
334 * +-----------------------------------------------------+
335 * 24 | Buffer Address 3 [63:0] |
336 * +-----------------------------------------------------+
337 */
338 printk(KERN_INFO "R [desc] [buffer 0 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000339 "[buffer 1 63:0 ] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000340 "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] "
341 "[bi->skb] <-- Ext Pkt Split format\n");
342 /* [Extended] Receive Descriptor (Write-Back) Format
343 *
344 * 63 48 47 32 31 13 12 8 7 4 3 0
345 * +------------------------------------------------------+
346 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
347 * | Checksum | Ident | | Queue | | Type |
348 * +------------------------------------------------------+
349 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
350 * +------------------------------------------------------+
351 * 63 48 47 32 31 20 19 0
352 */
353 printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000354 "[vl l0 ee es] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000355 "[ l3 l2 l1 hs] [reserved ] ---------------- "
356 "[bi->skb] <-- Ext Rx Write-Back format\n");
357 for (i = 0; i < rx_ring->count; i++) {
358 buffer_info = &rx_ring->buffer_info[i];
359 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
360 u1 = (struct my_u1 *)rx_desc_ps;
361 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000362 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000363 if (staterr & E1000_RXD_STAT_DD) {
364 /* Descriptor Done */
365 printk(KERN_INFO "RWB[0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000366 "%016llX %016llX %016llX "
367 "---------------- %p", i,
368 (unsigned long long)le64_to_cpu(u1->a),
369 (unsigned long long)le64_to_cpu(u1->b),
370 (unsigned long long)le64_to_cpu(u1->c),
371 (unsigned long long)le64_to_cpu(u1->d),
372 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000373 } else {
374 printk(KERN_INFO "R [0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000375 "%016llX %016llX %016llX %016llX %p", i,
376 (unsigned long long)le64_to_cpu(u1->a),
377 (unsigned long long)le64_to_cpu(u1->b),
378 (unsigned long long)le64_to_cpu(u1->c),
379 (unsigned long long)le64_to_cpu(u1->d),
380 (unsigned long long)buffer_info->dma,
381 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000382
383 if (netif_msg_pktdata(adapter))
384 print_hex_dump(KERN_INFO, "",
385 DUMP_PREFIX_ADDRESS, 16, 1,
386 phys_to_virt(buffer_info->dma),
387 adapter->rx_ps_bsize0, true);
388 }
389
390 if (i == rx_ring->next_to_use)
391 printk(KERN_CONT " NTU\n");
392 else if (i == rx_ring->next_to_clean)
393 printk(KERN_CONT " NTC\n");
394 else
395 printk(KERN_CONT "\n");
396 }
397 break;
398 default:
399 case 0:
400 /* Legacy Receive Descriptor Format
401 *
402 * +-----------------------------------------------------+
403 * | Buffer Address [63:0] |
404 * +-----------------------------------------------------+
405 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
406 * +-----------------------------------------------------+
407 * 63 48 47 40 39 32 31 16 15 0
408 */
409 printk(KERN_INFO "Rl[desc] [address 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000410 "[vl er S cks ln] [bi->dma ] [bi->skb] "
411 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000412 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
413 rx_desc = E1000_RX_DESC(*rx_ring, i);
414 buffer_info = &rx_ring->buffer_info[i];
415 u0 = (struct my_u0 *)rx_desc;
416 printk(KERN_INFO "Rl[0x%03X] %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000417 "%016llX %p", i,
418 (unsigned long long)le64_to_cpu(u0->a),
419 (unsigned long long)le64_to_cpu(u0->b),
420 (unsigned long long)buffer_info->dma,
421 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000422 if (i == rx_ring->next_to_use)
423 printk(KERN_CONT " NTU\n");
424 else if (i == rx_ring->next_to_clean)
425 printk(KERN_CONT " NTC\n");
426 else
427 printk(KERN_CONT "\n");
428
429 if (netif_msg_pktdata(adapter))
430 print_hex_dump(KERN_INFO, "",
Bruce Allanaf667a22010-12-31 06:10:01 +0000431 DUMP_PREFIX_ADDRESS,
432 16, 1,
433 phys_to_virt(buffer_info->dma),
434 adapter->rx_buffer_len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000435 }
436 }
437
438exit:
439 return;
440}
441
Auke Kokbc7f75f2007-09-17 12:30:59 -0700442/**
443 * e1000_desc_unused - calculate if we have unused descriptors
444 **/
445static int e1000_desc_unused(struct e1000_ring *ring)
446{
447 if (ring->next_to_clean > ring->next_to_use)
448 return ring->next_to_clean - ring->next_to_use - 1;
449
450 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
451}
452
453/**
Bruce Allanad680762008-03-28 09:15:03 -0700454 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700455 * @adapter: board private structure
456 * @status: descriptor status field as written by hardware
457 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
458 * @skb: pointer to sk_buff to be indicated to stack
459 **/
460static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000461 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000462 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700463{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000464 u16 tag = le16_to_cpu(vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700465 skb->protocol = eth_type_trans(skb, netdev);
466
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000467 if (status & E1000_RXD_STAT_VP)
468 __vlan_hwaccel_put_tag(skb, tag);
469
470 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700471}
472
473/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000474 * e1000_rx_checksum - Receive Checksum Offload
Auke Kokbc7f75f2007-09-17 12:30:59 -0700475 * @adapter: board private structure
476 * @status_err: receive descriptor status and error fields
477 * @csum: receive descriptor csum field
478 * @sk_buff: socket buffer with received data
479 **/
480static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
481 u32 csum, struct sk_buff *skb)
482{
483 u16 status = (u16)status_err;
484 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700485
486 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700487
488 /* Ignore Checksum bit is set */
489 if (status & E1000_RXD_STAT_IXSM)
490 return;
491 /* TCP/UDP checksum error bit is set */
492 if (errors & E1000_RXD_ERR_TCPE) {
493 /* let the stack verify checksum errors */
494 adapter->hw_csum_err++;
495 return;
496 }
497
498 /* TCP/UDP Checksum has not been calculated */
499 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
500 return;
501
502 /* It must be a TCP or UDP packet with a valid checksum */
503 if (status & E1000_RXD_STAT_TCPCS) {
504 /* TCP checksum is good */
505 skb->ip_summed = CHECKSUM_UNNECESSARY;
506 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700507 /*
508 * IP fragment with UDP payload
509 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700510 * and then put the value in host order for further stack use.
511 */
Al Viroa39fe742007-12-11 19:50:34 +0000512 __sum16 sum = (__force __sum16)htons(csum);
513 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700514 skb->ip_summed = CHECKSUM_COMPLETE;
515 }
516 adapter->hw_csum_good++;
517}
518
519/**
520 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
521 * @adapter: address of board private structure
522 **/
523static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
524 int cleaned_count)
525{
526 struct net_device *netdev = adapter->netdev;
527 struct pci_dev *pdev = adapter->pdev;
528 struct e1000_ring *rx_ring = adapter->rx_ring;
529 struct e1000_rx_desc *rx_desc;
530 struct e1000_buffer *buffer_info;
531 struct sk_buff *skb;
532 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000533 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700534
535 i = rx_ring->next_to_use;
536 buffer_info = &rx_ring->buffer_info[i];
537
538 while (cleaned_count--) {
539 skb = buffer_info->skb;
540 if (skb) {
541 skb_trim(skb, 0);
542 goto map_skb;
543 }
544
Eric Dumazet89d71a62009-10-13 05:34:20 +0000545 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700546 if (!skb) {
547 /* Better luck next round */
548 adapter->alloc_rx_buff_failed++;
549 break;
550 }
551
Auke Kokbc7f75f2007-09-17 12:30:59 -0700552 buffer_info->skb = skb;
553map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000554 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700555 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000556 DMA_FROM_DEVICE);
557 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000558 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700559 adapter->rx_dma_failed++;
560 break;
561 }
562
563 rx_desc = E1000_RX_DESC(*rx_ring, i);
564 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
565
Tom Herbert50849d72010-05-05 14:02:49 +0000566 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
567 /*
568 * Force memory writes to complete before letting h/w
569 * know there are new descriptors to fetch. (Only
570 * applicable for weak-ordered memory model archs,
571 * such as IA-64).
572 */
573 wmb();
574 writel(i, adapter->hw.hw_addr + rx_ring->tail);
575 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700576 i++;
577 if (i == rx_ring->count)
578 i = 0;
579 buffer_info = &rx_ring->buffer_info[i];
580 }
581
Tom Herbert50849d72010-05-05 14:02:49 +0000582 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700583}
584
585/**
586 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
587 * @adapter: address of board private structure
588 **/
589static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
590 int cleaned_count)
591{
592 struct net_device *netdev = adapter->netdev;
593 struct pci_dev *pdev = adapter->pdev;
594 union e1000_rx_desc_packet_split *rx_desc;
595 struct e1000_ring *rx_ring = adapter->rx_ring;
596 struct e1000_buffer *buffer_info;
597 struct e1000_ps_page *ps_page;
598 struct sk_buff *skb;
599 unsigned int i, j;
600
601 i = rx_ring->next_to_use;
602 buffer_info = &rx_ring->buffer_info[i];
603
604 while (cleaned_count--) {
605 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
606
607 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700608 ps_page = &buffer_info->ps_pages[j];
609 if (j >= adapter->rx_ps_pages) {
610 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000611 rx_desc->read.buffer_addr[j + 1] =
612 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700613 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614 }
Auke Kok47f44e42007-10-25 13:57:44 -0700615 if (!ps_page->page) {
616 ps_page->page = alloc_page(GFP_ATOMIC);
617 if (!ps_page->page) {
618 adapter->alloc_rx_buff_failed++;
619 goto no_buffers;
620 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000621 ps_page->dma = dma_map_page(&pdev->dev,
622 ps_page->page,
623 0, PAGE_SIZE,
624 DMA_FROM_DEVICE);
625 if (dma_mapping_error(&pdev->dev,
626 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700627 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000628 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700629 adapter->rx_dma_failed++;
630 goto no_buffers;
631 }
632 }
633 /*
634 * Refresh the desc even if buffer_addrs
635 * didn't change because each write-back
636 * erases this info.
637 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000638 rx_desc->read.buffer_addr[j + 1] =
639 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640 }
641
Eric Dumazet89d71a62009-10-13 05:34:20 +0000642 skb = netdev_alloc_skb_ip_align(netdev,
643 adapter->rx_ps_bsize0);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644
645 if (!skb) {
646 adapter->alloc_rx_buff_failed++;
647 break;
648 }
649
Auke Kokbc7f75f2007-09-17 12:30:59 -0700650 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000651 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700652 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000653 DMA_FROM_DEVICE);
654 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000655 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700656 adapter->rx_dma_failed++;
657 /* cleanup skb */
658 dev_kfree_skb_any(skb);
659 buffer_info->skb = NULL;
660 break;
661 }
662
663 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
664
Tom Herbert50849d72010-05-05 14:02:49 +0000665 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
666 /*
667 * Force memory writes to complete before letting h/w
668 * know there are new descriptors to fetch. (Only
669 * applicable for weak-ordered memory model archs,
670 * such as IA-64).
671 */
672 wmb();
Bruce Allanaf667a22010-12-31 06:10:01 +0000673 writel(i << 1, adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000674 }
675
Auke Kokbc7f75f2007-09-17 12:30:59 -0700676 i++;
677 if (i == rx_ring->count)
678 i = 0;
679 buffer_info = &rx_ring->buffer_info[i];
680 }
681
682no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000683 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700684}
685
686/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700687 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
688 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700689 * @cleaned_count: number of buffers to allocate this pass
690 **/
691
692static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
693 int cleaned_count)
694{
695 struct net_device *netdev = adapter->netdev;
696 struct pci_dev *pdev = adapter->pdev;
697 struct e1000_rx_desc *rx_desc;
698 struct e1000_ring *rx_ring = adapter->rx_ring;
699 struct e1000_buffer *buffer_info;
700 struct sk_buff *skb;
701 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000702 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700703
704 i = rx_ring->next_to_use;
705 buffer_info = &rx_ring->buffer_info[i];
706
707 while (cleaned_count--) {
708 skb = buffer_info->skb;
709 if (skb) {
710 skb_trim(skb, 0);
711 goto check_page;
712 }
713
Eric Dumazet89d71a62009-10-13 05:34:20 +0000714 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700715 if (unlikely(!skb)) {
716 /* Better luck next round */
717 adapter->alloc_rx_buff_failed++;
718 break;
719 }
720
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700721 buffer_info->skb = skb;
722check_page:
723 /* allocate a new page if necessary */
724 if (!buffer_info->page) {
725 buffer_info->page = alloc_page(GFP_ATOMIC);
726 if (unlikely(!buffer_info->page)) {
727 adapter->alloc_rx_buff_failed++;
728 break;
729 }
730 }
731
732 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000733 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700734 buffer_info->page, 0,
735 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000736 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700737
738 rx_desc = E1000_RX_DESC(*rx_ring, i);
739 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
740
741 if (unlikely(++i == rx_ring->count))
742 i = 0;
743 buffer_info = &rx_ring->buffer_info[i];
744 }
745
746 if (likely(rx_ring->next_to_use != i)) {
747 rx_ring->next_to_use = i;
748 if (unlikely(i-- == 0))
749 i = (rx_ring->count - 1);
750
751 /* Force memory writes to complete before letting h/w
752 * know there are new descriptors to fetch. (Only
753 * applicable for weak-ordered memory model archs,
754 * such as IA-64). */
755 wmb();
756 writel(i, adapter->hw.hw_addr + rx_ring->tail);
757 }
758}
759
760/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700761 * e1000_clean_rx_irq - Send received data up the network stack; legacy
762 * @adapter: board private structure
763 *
764 * the return value indicates whether actual cleaning was done, there
765 * is no guarantee that everything was cleaned
766 **/
767static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
768 int *work_done, int work_to_do)
769{
770 struct net_device *netdev = adapter->netdev;
771 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000772 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700773 struct e1000_ring *rx_ring = adapter->rx_ring;
774 struct e1000_rx_desc *rx_desc, *next_rxd;
775 struct e1000_buffer *buffer_info, *next_buffer;
776 u32 length;
777 unsigned int i;
778 int cleaned_count = 0;
779 bool cleaned = 0;
780 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
781
782 i = rx_ring->next_to_clean;
783 rx_desc = E1000_RX_DESC(*rx_ring, i);
784 buffer_info = &rx_ring->buffer_info[i];
785
786 while (rx_desc->status & E1000_RXD_STAT_DD) {
787 struct sk_buff *skb;
788 u8 status;
789
790 if (*work_done >= work_to_do)
791 break;
792 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000793 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700794
795 status = rx_desc->status;
796 skb = buffer_info->skb;
797 buffer_info->skb = NULL;
798
799 prefetch(skb->data - NET_IP_ALIGN);
800
801 i++;
802 if (i == rx_ring->count)
803 i = 0;
804 next_rxd = E1000_RX_DESC(*rx_ring, i);
805 prefetch(next_rxd);
806
807 next_buffer = &rx_ring->buffer_info[i];
808
809 cleaned = 1;
810 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000811 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700812 buffer_info->dma,
813 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000814 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700815 buffer_info->dma = 0;
816
817 length = le16_to_cpu(rx_desc->length);
818
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000819 /*
820 * !EOP means multiple descriptors were used to store a single
821 * packet, if that's the case we need to toss it. In fact, we
822 * need to toss every packet with the EOP bit clear and the
823 * next frame that _does_ have the EOP bit set, as it is by
824 * definition only a frame fragment
825 */
826 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
827 adapter->flags2 |= FLAG2_IS_DISCARDING;
828
829 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700830 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000831 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700832 /* recycle */
833 buffer_info->skb = skb;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000834 if (status & E1000_RXD_STAT_EOP)
835 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700836 goto next_desc;
837 }
838
839 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
840 /* recycle */
841 buffer_info->skb = skb;
842 goto next_desc;
843 }
844
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000845 /* adjust length to remove Ethernet CRC */
846 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
847 length -= 4;
848
Auke Kokbc7f75f2007-09-17 12:30:59 -0700849 total_rx_bytes += length;
850 total_rx_packets++;
851
Bruce Allanad680762008-03-28 09:15:03 -0700852 /*
853 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700854 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700855 * of reassembly being done in the stack
856 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700857 if (length < copybreak) {
858 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000859 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700861 skb_copy_to_linear_data_offset(new_skb,
862 -NET_IP_ALIGN,
863 (skb->data -
864 NET_IP_ALIGN),
865 (length +
866 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700867 /* save the skb in buffer_info as good */
868 buffer_info->skb = skb;
869 skb = new_skb;
870 }
871 /* else just continue with the old one */
872 }
873 /* end copybreak code */
874 skb_put(skb, length);
875
876 /* Receive Checksum Offload */
877 e1000_rx_checksum(adapter,
878 (u32)(status) |
879 ((u32)(rx_desc->errors) << 24),
880 le16_to_cpu(rx_desc->csum), skb);
881
882 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
883
884next_desc:
885 rx_desc->status = 0;
886
887 /* return some buffers to hardware, one at a time is too slow */
888 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
889 adapter->alloc_rx_buf(adapter, cleaned_count);
890 cleaned_count = 0;
891 }
892
893 /* use prefetched values */
894 rx_desc = next_rxd;
895 buffer_info = next_buffer;
896 }
897 rx_ring->next_to_clean = i;
898
899 cleaned_count = e1000_desc_unused(rx_ring);
900 if (cleaned_count)
901 adapter->alloc_rx_buf(adapter, cleaned_count);
902
Auke Kokbc7f75f2007-09-17 12:30:59 -0700903 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700904 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700905 return cleaned;
906}
907
Auke Kokbc7f75f2007-09-17 12:30:59 -0700908static void e1000_put_txbuf(struct e1000_adapter *adapter,
909 struct e1000_buffer *buffer_info)
910{
Alexander Duyck03b13202009-12-02 16:45:31 +0000911 if (buffer_info->dma) {
912 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +0000913 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
914 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000915 else
Nick Nunley0be3f552010-04-27 13:09:05 +0000916 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
917 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +0000918 buffer_info->dma = 0;
919 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700920 if (buffer_info->skb) {
921 dev_kfree_skb_any(buffer_info->skb);
922 buffer_info->skb = NULL;
923 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +0000924 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700925}
926
Bruce Allan41cec6f2009-11-20 23:28:56 +0000927static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700928{
Bruce Allan41cec6f2009-11-20 23:28:56 +0000929 struct e1000_adapter *adapter = container_of(work,
930 struct e1000_adapter,
931 print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932 struct e1000_ring *tx_ring = adapter->tx_ring;
933 unsigned int i = tx_ring->next_to_clean;
934 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
935 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +0000936 struct e1000_hw *hw = &adapter->hw;
937 u16 phy_status, phy_1000t_status, phy_ext_status;
938 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939
Jesse Brandeburg615b32a2011-02-02 10:19:45 +0000940 if (test_bit(__E1000_DOWN, &adapter->state))
941 return;
942
Bruce Allan41cec6f2009-11-20 23:28:56 +0000943 e1e_rphy(hw, PHY_STATUS, &phy_status);
944 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
945 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
946
947 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
948
949 /* detected Hardware unit hang */
950 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700951 " TDH <%x>\n"
952 " TDT <%x>\n"
953 " next_to_use <%x>\n"
954 " next_to_clean <%x>\n"
955 "buffer_info[next_to_clean]:\n"
956 " time_stamp <%lx>\n"
957 " next_to_watch <%x>\n"
958 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +0000959 " next_to_watch.status <%x>\n"
960 "MAC Status <%x>\n"
961 "PHY Status <%x>\n"
962 "PHY 1000BASE-T Status <%x>\n"
963 "PHY Extended Status <%x>\n"
964 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700965 readl(adapter->hw.hw_addr + tx_ring->head),
966 readl(adapter->hw.hw_addr + tx_ring->tail),
967 tx_ring->next_to_use,
968 tx_ring->next_to_clean,
969 tx_ring->buffer_info[eop].time_stamp,
970 eop,
971 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +0000972 eop_desc->upper.fields.status,
973 er32(STATUS),
974 phy_status,
975 phy_1000t_status,
976 phy_ext_status,
977 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978}
979
980/**
981 * e1000_clean_tx_irq - Reclaim resources after transmit completes
982 * @adapter: board private structure
983 *
984 * the return value indicates whether actual cleaning was done, there
985 * is no guarantee that everything was cleaned
986 **/
987static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
988{
989 struct net_device *netdev = adapter->netdev;
990 struct e1000_hw *hw = &adapter->hw;
991 struct e1000_ring *tx_ring = adapter->tx_ring;
992 struct e1000_tx_desc *tx_desc, *eop_desc;
993 struct e1000_buffer *buffer_info;
994 unsigned int i, eop;
995 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700996 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
997
998 i = tx_ring->next_to_clean;
999 eop = tx_ring->buffer_info[i].next_to_watch;
1000 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1001
Alexander Duyck12d04a32009-03-25 22:05:03 +00001002 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1003 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001004 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001005 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001006 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001007 tx_desc = E1000_TX_DESC(*tx_ring, i);
1008 buffer_info = &tx_ring->buffer_info[i];
1009 cleaned = (i == eop);
1010
1011 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001012 total_tx_packets += buffer_info->segs;
1013 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014 }
1015
1016 e1000_put_txbuf(adapter, buffer_info);
1017 tx_desc->upper.data = 0;
1018
1019 i++;
1020 if (i == tx_ring->count)
1021 i = 0;
1022 }
1023
Terry Loftindac87612010-04-09 10:29:49 +00001024 if (i == tx_ring->next_to_use)
1025 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026 eop = tx_ring->buffer_info[i].next_to_watch;
1027 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001028 }
1029
1030 tx_ring->next_to_clean = i;
1031
1032#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001033 if (count && netif_carrier_ok(netdev) &&
1034 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035 /* Make sure that anybody stopping the queue after this
1036 * sees the new next_to_clean.
1037 */
1038 smp_mb();
1039
1040 if (netif_queue_stopped(netdev) &&
1041 !(test_bit(__E1000_DOWN, &adapter->state))) {
1042 netif_wake_queue(netdev);
1043 ++adapter->restart_queue;
1044 }
1045 }
1046
1047 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001048 /*
1049 * Detect a transmit hang in hardware, this serializes the
1050 * check with the clearing of time_stamp and movement of i
1051 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001052 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001053 if (tx_ring->buffer_info[i].time_stamp &&
1054 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001055 + (adapter->tx_timeout_factor * HZ)) &&
1056 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001057 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058 netif_stop_queue(netdev);
1059 }
1060 }
1061 adapter->total_tx_bytes += total_tx_bytes;
1062 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001063 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001064}
1065
1066/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001067 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1068 * @adapter: board private structure
1069 *
1070 * the return value indicates whether actual cleaning was done, there
1071 * is no guarantee that everything was cleaned
1072 **/
1073static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1074 int *work_done, int work_to_do)
1075{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001076 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001077 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1078 struct net_device *netdev = adapter->netdev;
1079 struct pci_dev *pdev = adapter->pdev;
1080 struct e1000_ring *rx_ring = adapter->rx_ring;
1081 struct e1000_buffer *buffer_info, *next_buffer;
1082 struct e1000_ps_page *ps_page;
1083 struct sk_buff *skb;
1084 unsigned int i, j;
1085 u32 length, staterr;
1086 int cleaned_count = 0;
1087 bool cleaned = 0;
1088 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1089
1090 i = rx_ring->next_to_clean;
1091 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1092 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1093 buffer_info = &rx_ring->buffer_info[i];
1094
1095 while (staterr & E1000_RXD_STAT_DD) {
1096 if (*work_done >= work_to_do)
1097 break;
1098 (*work_done)++;
1099 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001100 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001101
1102 /* in the packet split case this is header only */
1103 prefetch(skb->data - NET_IP_ALIGN);
1104
1105 i++;
1106 if (i == rx_ring->count)
1107 i = 0;
1108 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1109 prefetch(next_rxd);
1110
1111 next_buffer = &rx_ring->buffer_info[i];
1112
1113 cleaned = 1;
1114 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001115 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001116 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001117 buffer_info->dma = 0;
1118
Bruce Allanaf667a22010-12-31 06:10:01 +00001119 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001120 if (!(staterr & E1000_RXD_STAT_EOP))
1121 adapter->flags2 |= FLAG2_IS_DISCARDING;
1122
1123 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001124 e_dbg("Packet Split buffers didn't pick up the full "
1125 "packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001126 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001127 if (staterr & E1000_RXD_STAT_EOP)
1128 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129 goto next_desc;
1130 }
1131
1132 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1133 dev_kfree_skb_irq(skb);
1134 goto next_desc;
1135 }
1136
1137 length = le16_to_cpu(rx_desc->wb.middle.length0);
1138
1139 if (!length) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001140 e_dbg("Last part of the packet spanning multiple "
1141 "descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001142 dev_kfree_skb_irq(skb);
1143 goto next_desc;
1144 }
1145
1146 /* Good Receive */
1147 skb_put(skb, length);
1148
1149 {
Bruce Allanad680762008-03-28 09:15:03 -07001150 /*
1151 * this looks ugly, but it seems compiler issues make it
1152 * more efficient than reusing j
1153 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001154 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1155
Bruce Allanad680762008-03-28 09:15:03 -07001156 /*
1157 * page alloc/put takes too long and effects small packet
1158 * throughput, so unsplit small packets and save the alloc/put
1159 * only valid in softirq (napi) context to call kmap_*
1160 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001161 if (l1 && (l1 <= copybreak) &&
1162 ((length + l1) <= adapter->rx_ps_bsize0)) {
1163 u8 *vaddr;
1164
Auke Kok47f44e42007-10-25 13:57:44 -07001165 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166
Bruce Allanad680762008-03-28 09:15:03 -07001167 /*
1168 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001169 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001170 * very long
1171 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001172 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1173 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001174 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1175 memcpy(skb_tail_pointer(skb), vaddr, l1);
1176 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001177 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1178 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001179
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001180 /* remove the CRC */
1181 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1182 l1 -= 4;
1183
Auke Kokbc7f75f2007-09-17 12:30:59 -07001184 skb_put(skb, l1);
1185 goto copydone;
1186 } /* if */
1187 }
1188
1189 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1190 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1191 if (!length)
1192 break;
1193
Auke Kok47f44e42007-10-25 13:57:44 -07001194 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001195 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1196 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001197 ps_page->dma = 0;
1198 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1199 ps_page->page = NULL;
1200 skb->len += length;
1201 skb->data_len += length;
1202 skb->truesize += length;
1203 }
1204
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001205 /* strip the ethernet crc, problem is we're using pages now so
1206 * this whole operation can get a little cpu intensive
1207 */
1208 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1209 pskb_trim(skb, skb->len - 4);
1210
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211copydone:
1212 total_rx_bytes += skb->len;
1213 total_rx_packets++;
1214
1215 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1216 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1217
1218 if (rx_desc->wb.upper.header_status &
1219 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1220 adapter->rx_hdr_split++;
1221
1222 e1000_receive_skb(adapter, netdev, skb,
1223 staterr, rx_desc->wb.middle.vlan);
1224
1225next_desc:
1226 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1227 buffer_info->skb = NULL;
1228
1229 /* return some buffers to hardware, one at a time is too slow */
1230 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1231 adapter->alloc_rx_buf(adapter, cleaned_count);
1232 cleaned_count = 0;
1233 }
1234
1235 /* use prefetched values */
1236 rx_desc = next_rxd;
1237 buffer_info = next_buffer;
1238
1239 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1240 }
1241 rx_ring->next_to_clean = i;
1242
1243 cleaned_count = e1000_desc_unused(rx_ring);
1244 if (cleaned_count)
1245 adapter->alloc_rx_buf(adapter, cleaned_count);
1246
Auke Kokbc7f75f2007-09-17 12:30:59 -07001247 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001248 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249 return cleaned;
1250}
1251
1252/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001253 * e1000_consume_page - helper function
1254 **/
1255static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1256 u16 length)
1257{
1258 bi->page = NULL;
1259 skb->len += length;
1260 skb->data_len += length;
1261 skb->truesize += length;
1262}
1263
1264/**
1265 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1266 * @adapter: board private structure
1267 *
1268 * the return value indicates whether actual cleaning was done, there
1269 * is no guarantee that everything was cleaned
1270 **/
1271
1272static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1273 int *work_done, int work_to_do)
1274{
1275 struct net_device *netdev = adapter->netdev;
1276 struct pci_dev *pdev = adapter->pdev;
1277 struct e1000_ring *rx_ring = adapter->rx_ring;
1278 struct e1000_rx_desc *rx_desc, *next_rxd;
1279 struct e1000_buffer *buffer_info, *next_buffer;
1280 u32 length;
1281 unsigned int i;
1282 int cleaned_count = 0;
1283 bool cleaned = false;
1284 unsigned int total_rx_bytes=0, total_rx_packets=0;
1285
1286 i = rx_ring->next_to_clean;
1287 rx_desc = E1000_RX_DESC(*rx_ring, i);
1288 buffer_info = &rx_ring->buffer_info[i];
1289
1290 while (rx_desc->status & E1000_RXD_STAT_DD) {
1291 struct sk_buff *skb;
1292 u8 status;
1293
1294 if (*work_done >= work_to_do)
1295 break;
1296 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001297 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001298
1299 status = rx_desc->status;
1300 skb = buffer_info->skb;
1301 buffer_info->skb = NULL;
1302
1303 ++i;
1304 if (i == rx_ring->count)
1305 i = 0;
1306 next_rxd = E1000_RX_DESC(*rx_ring, i);
1307 prefetch(next_rxd);
1308
1309 next_buffer = &rx_ring->buffer_info[i];
1310
1311 cleaned = true;
1312 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001313 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1314 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001315 buffer_info->dma = 0;
1316
1317 length = le16_to_cpu(rx_desc->length);
1318
1319 /* errors is only valid for DD + EOP descriptors */
1320 if (unlikely((status & E1000_RXD_STAT_EOP) &&
1321 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
1322 /* recycle both page and skb */
1323 buffer_info->skb = skb;
1324 /* an error means any chain goes out the window
1325 * too */
1326 if (rx_ring->rx_skb_top)
Bruce Allanef5ab892011-02-10 08:17:21 +00001327 dev_kfree_skb_irq(rx_ring->rx_skb_top);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001328 rx_ring->rx_skb_top = NULL;
1329 goto next_desc;
1330 }
1331
Bruce Allanf0f1a172010-12-11 05:53:32 +00001332#define rxtop (rx_ring->rx_skb_top)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001333 if (!(status & E1000_RXD_STAT_EOP)) {
1334 /* this descriptor is only the beginning (or middle) */
1335 if (!rxtop) {
1336 /* this is the beginning of a chain */
1337 rxtop = skb;
1338 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1339 0, length);
1340 } else {
1341 /* this is the middle of a chain */
1342 skb_fill_page_desc(rxtop,
1343 skb_shinfo(rxtop)->nr_frags,
1344 buffer_info->page, 0, length);
1345 /* re-use the skb, only consumed the page */
1346 buffer_info->skb = skb;
1347 }
1348 e1000_consume_page(buffer_info, rxtop, length);
1349 goto next_desc;
1350 } else {
1351 if (rxtop) {
1352 /* end of the chain */
1353 skb_fill_page_desc(rxtop,
1354 skb_shinfo(rxtop)->nr_frags,
1355 buffer_info->page, 0, length);
1356 /* re-use the current skb, we only consumed the
1357 * page */
1358 buffer_info->skb = skb;
1359 skb = rxtop;
1360 rxtop = NULL;
1361 e1000_consume_page(buffer_info, skb, length);
1362 } else {
1363 /* no chain, got EOP, this buf is the packet
1364 * copybreak to save the put_page/alloc_page */
1365 if (length <= copybreak &&
1366 skb_tailroom(skb) >= length) {
1367 u8 *vaddr;
1368 vaddr = kmap_atomic(buffer_info->page,
1369 KM_SKB_DATA_SOFTIRQ);
1370 memcpy(skb_tail_pointer(skb), vaddr,
1371 length);
1372 kunmap_atomic(vaddr,
1373 KM_SKB_DATA_SOFTIRQ);
1374 /* re-use the page, so don't erase
1375 * buffer_info->page */
1376 skb_put(skb, length);
1377 } else {
1378 skb_fill_page_desc(skb, 0,
1379 buffer_info->page, 0,
1380 length);
1381 e1000_consume_page(buffer_info, skb,
1382 length);
1383 }
1384 }
1385 }
1386
1387 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1388 e1000_rx_checksum(adapter,
1389 (u32)(status) |
1390 ((u32)(rx_desc->errors) << 24),
1391 le16_to_cpu(rx_desc->csum), skb);
1392
1393 /* probably a little skewed due to removing CRC */
1394 total_rx_bytes += skb->len;
1395 total_rx_packets++;
1396
1397 /* eth type trans needs skb->data to point to something */
1398 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001399 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001400 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001401 goto next_desc;
1402 }
1403
1404 e1000_receive_skb(adapter, netdev, skb, status,
1405 rx_desc->special);
1406
1407next_desc:
1408 rx_desc->status = 0;
1409
1410 /* return some buffers to hardware, one at a time is too slow */
1411 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1412 adapter->alloc_rx_buf(adapter, cleaned_count);
1413 cleaned_count = 0;
1414 }
1415
1416 /* use prefetched values */
1417 rx_desc = next_rxd;
1418 buffer_info = next_buffer;
1419 }
1420 rx_ring->next_to_clean = i;
1421
1422 cleaned_count = e1000_desc_unused(rx_ring);
1423 if (cleaned_count)
1424 adapter->alloc_rx_buf(adapter, cleaned_count);
1425
1426 adapter->total_rx_bytes += total_rx_bytes;
1427 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001428 return cleaned;
1429}
1430
1431/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001432 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1433 * @adapter: board private structure
1434 **/
1435static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1436{
1437 struct e1000_ring *rx_ring = adapter->rx_ring;
1438 struct e1000_buffer *buffer_info;
1439 struct e1000_ps_page *ps_page;
1440 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001441 unsigned int i, j;
1442
1443 /* Free all the Rx ring sk_buffs */
1444 for (i = 0; i < rx_ring->count; i++) {
1445 buffer_info = &rx_ring->buffer_info[i];
1446 if (buffer_info->dma) {
1447 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001448 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001449 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001450 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001451 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001452 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001453 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001454 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001455 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001456 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001457 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001458 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001459 buffer_info->dma = 0;
1460 }
1461
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001462 if (buffer_info->page) {
1463 put_page(buffer_info->page);
1464 buffer_info->page = NULL;
1465 }
1466
Auke Kokbc7f75f2007-09-17 12:30:59 -07001467 if (buffer_info->skb) {
1468 dev_kfree_skb(buffer_info->skb);
1469 buffer_info->skb = NULL;
1470 }
1471
1472 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001473 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001474 if (!ps_page->page)
1475 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001476 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1477 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001478 ps_page->dma = 0;
1479 put_page(ps_page->page);
1480 ps_page->page = NULL;
1481 }
1482 }
1483
1484 /* there also may be some cached data from a chained receive */
1485 if (rx_ring->rx_skb_top) {
1486 dev_kfree_skb(rx_ring->rx_skb_top);
1487 rx_ring->rx_skb_top = NULL;
1488 }
1489
Auke Kokbc7f75f2007-09-17 12:30:59 -07001490 /* Zero out the descriptor ring */
1491 memset(rx_ring->desc, 0, rx_ring->size);
1492
1493 rx_ring->next_to_clean = 0;
1494 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001495 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001496
1497 writel(0, adapter->hw.hw_addr + rx_ring->head);
1498 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1499}
1500
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001501static void e1000e_downshift_workaround(struct work_struct *work)
1502{
1503 struct e1000_adapter *adapter = container_of(work,
1504 struct e1000_adapter, downshift_task);
1505
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001506 if (test_bit(__E1000_DOWN, &adapter->state))
1507 return;
1508
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001509 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1510}
1511
Auke Kokbc7f75f2007-09-17 12:30:59 -07001512/**
1513 * e1000_intr_msi - Interrupt Handler
1514 * @irq: interrupt number
1515 * @data: pointer to a network interface device structure
1516 **/
1517static irqreturn_t e1000_intr_msi(int irq, void *data)
1518{
1519 struct net_device *netdev = data;
1520 struct e1000_adapter *adapter = netdev_priv(netdev);
1521 struct e1000_hw *hw = &adapter->hw;
1522 u32 icr = er32(ICR);
1523
Bruce Allanad680762008-03-28 09:15:03 -07001524 /*
1525 * read ICR disables interrupts using IAM
1526 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001527
dave graham573cca82009-02-10 12:52:05 +00001528 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001529 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001530 /*
1531 * ICH8 workaround-- Call gig speed drop workaround on cable
1532 * disconnect (LSC) before accessing any PHY registers
1533 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001534 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1535 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001536 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001537
Bruce Allanad680762008-03-28 09:15:03 -07001538 /*
1539 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001540 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001541 * adapter in watchdog
1542 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001543 if (netif_carrier_ok(netdev) &&
1544 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1545 /* disable receives */
1546 u32 rctl = er32(RCTL);
1547 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001548 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001549 }
1550 /* guard against interrupt when we're going down */
1551 if (!test_bit(__E1000_DOWN, &adapter->state))
1552 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1553 }
1554
Ben Hutchings288379f2009-01-19 16:43:59 -08001555 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001556 adapter->total_tx_bytes = 0;
1557 adapter->total_tx_packets = 0;
1558 adapter->total_rx_bytes = 0;
1559 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001560 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001561 }
1562
1563 return IRQ_HANDLED;
1564}
1565
1566/**
1567 * e1000_intr - Interrupt Handler
1568 * @irq: interrupt number
1569 * @data: pointer to a network interface device structure
1570 **/
1571static irqreturn_t e1000_intr(int irq, void *data)
1572{
1573 struct net_device *netdev = data;
1574 struct e1000_adapter *adapter = netdev_priv(netdev);
1575 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001576 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001577
Bruce Allana68ea772009-11-20 23:23:16 +00001578 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001579 return IRQ_NONE; /* Not our interrupt */
1580
Bruce Allanad680762008-03-28 09:15:03 -07001581 /*
1582 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1583 * not set, then the adapter didn't send an interrupt
1584 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585 if (!(icr & E1000_ICR_INT_ASSERTED))
1586 return IRQ_NONE;
1587
Bruce Allanad680762008-03-28 09:15:03 -07001588 /*
1589 * Interrupt Auto-Mask...upon reading ICR,
1590 * interrupts are masked. No need for the
1591 * IMC write
1592 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001593
dave graham573cca82009-02-10 12:52:05 +00001594 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001595 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001596 /*
1597 * ICH8 workaround-- Call gig speed drop workaround on cable
1598 * disconnect (LSC) before accessing any PHY registers
1599 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001600 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1601 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001602 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001603
Bruce Allanad680762008-03-28 09:15:03 -07001604 /*
1605 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001606 * For packet buffer work-around on link down event;
1607 * disable receives here in the ISR and
1608 * reset adapter in watchdog
1609 */
1610 if (netif_carrier_ok(netdev) &&
1611 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1612 /* disable receives */
1613 rctl = er32(RCTL);
1614 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001615 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616 }
1617 /* guard against interrupt when we're going down */
1618 if (!test_bit(__E1000_DOWN, &adapter->state))
1619 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1620 }
1621
Ben Hutchings288379f2009-01-19 16:43:59 -08001622 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001623 adapter->total_tx_bytes = 0;
1624 adapter->total_tx_packets = 0;
1625 adapter->total_rx_bytes = 0;
1626 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001627 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001628 }
1629
1630 return IRQ_HANDLED;
1631}
1632
Bruce Allan4662e822008-08-26 18:37:06 -07001633static irqreturn_t e1000_msix_other(int irq, void *data)
1634{
1635 struct net_device *netdev = data;
1636 struct e1000_adapter *adapter = netdev_priv(netdev);
1637 struct e1000_hw *hw = &adapter->hw;
1638 u32 icr = er32(ICR);
1639
1640 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001641 if (!test_bit(__E1000_DOWN, &adapter->state))
1642 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001643 return IRQ_NONE;
1644 }
1645
1646 if (icr & adapter->eiac_mask)
1647 ew32(ICS, (icr & adapter->eiac_mask));
1648
1649 if (icr & E1000_ICR_OTHER) {
1650 if (!(icr & E1000_ICR_LSC))
1651 goto no_link_interrupt;
1652 hw->mac.get_link_status = 1;
1653 /* guard against interrupt when we're going down */
1654 if (!test_bit(__E1000_DOWN, &adapter->state))
1655 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1656 }
1657
1658no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001659 if (!test_bit(__E1000_DOWN, &adapter->state))
1660 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001661
1662 return IRQ_HANDLED;
1663}
1664
1665
1666static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1667{
1668 struct net_device *netdev = data;
1669 struct e1000_adapter *adapter = netdev_priv(netdev);
1670 struct e1000_hw *hw = &adapter->hw;
1671 struct e1000_ring *tx_ring = adapter->tx_ring;
1672
1673
1674 adapter->total_tx_bytes = 0;
1675 adapter->total_tx_packets = 0;
1676
1677 if (!e1000_clean_tx_irq(adapter))
1678 /* Ring was not completely cleaned, so fire another interrupt */
1679 ew32(ICS, tx_ring->ims_val);
1680
1681 return IRQ_HANDLED;
1682}
1683
1684static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1685{
1686 struct net_device *netdev = data;
1687 struct e1000_adapter *adapter = netdev_priv(netdev);
1688
1689 /* Write the ITR value calculated at the end of the
1690 * previous interrupt.
1691 */
1692 if (adapter->rx_ring->set_itr) {
1693 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1694 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1695 adapter->rx_ring->set_itr = 0;
1696 }
1697
Ben Hutchings288379f2009-01-19 16:43:59 -08001698 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001699 adapter->total_rx_bytes = 0;
1700 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001701 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001702 }
1703 return IRQ_HANDLED;
1704}
1705
1706/**
1707 * e1000_configure_msix - Configure MSI-X hardware
1708 *
1709 * e1000_configure_msix sets up the hardware to properly
1710 * generate MSI-X interrupts.
1711 **/
1712static void e1000_configure_msix(struct e1000_adapter *adapter)
1713{
1714 struct e1000_hw *hw = &adapter->hw;
1715 struct e1000_ring *rx_ring = adapter->rx_ring;
1716 struct e1000_ring *tx_ring = adapter->tx_ring;
1717 int vector = 0;
1718 u32 ctrl_ext, ivar = 0;
1719
1720 adapter->eiac_mask = 0;
1721
1722 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1723 if (hw->mac.type == e1000_82574) {
1724 u32 rfctl = er32(RFCTL);
1725 rfctl |= E1000_RFCTL_ACK_DIS;
1726 ew32(RFCTL, rfctl);
1727 }
1728
1729#define E1000_IVAR_INT_ALLOC_VALID 0x8
1730 /* Configure Rx vector */
1731 rx_ring->ims_val = E1000_IMS_RXQ0;
1732 adapter->eiac_mask |= rx_ring->ims_val;
1733 if (rx_ring->itr_val)
1734 writel(1000000000 / (rx_ring->itr_val * 256),
1735 hw->hw_addr + rx_ring->itr_register);
1736 else
1737 writel(1, hw->hw_addr + rx_ring->itr_register);
1738 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1739
1740 /* Configure Tx vector */
1741 tx_ring->ims_val = E1000_IMS_TXQ0;
1742 vector++;
1743 if (tx_ring->itr_val)
1744 writel(1000000000 / (tx_ring->itr_val * 256),
1745 hw->hw_addr + tx_ring->itr_register);
1746 else
1747 writel(1, hw->hw_addr + tx_ring->itr_register);
1748 adapter->eiac_mask |= tx_ring->ims_val;
1749 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1750
1751 /* set vector for Other Causes, e.g. link changes */
1752 vector++;
1753 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1754 if (rx_ring->itr_val)
1755 writel(1000000000 / (rx_ring->itr_val * 256),
1756 hw->hw_addr + E1000_EITR_82574(vector));
1757 else
1758 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1759
1760 /* Cause Tx interrupts on every write back */
1761 ivar |= (1 << 31);
1762
1763 ew32(IVAR, ivar);
1764
1765 /* enable MSI-X PBA support */
1766 ctrl_ext = er32(CTRL_EXT);
1767 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1768
1769 /* Auto-Mask Other interrupts upon ICR read */
1770#define E1000_EIAC_MASK_82574 0x01F00000
1771 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1772 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1773 ew32(CTRL_EXT, ctrl_ext);
1774 e1e_flush();
1775}
1776
1777void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1778{
1779 if (adapter->msix_entries) {
1780 pci_disable_msix(adapter->pdev);
1781 kfree(adapter->msix_entries);
1782 adapter->msix_entries = NULL;
1783 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1784 pci_disable_msi(adapter->pdev);
1785 adapter->flags &= ~FLAG_MSI_ENABLED;
1786 }
Bruce Allan4662e822008-08-26 18:37:06 -07001787}
1788
1789/**
1790 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1791 *
1792 * Attempt to configure interrupts using the best available
1793 * capabilities of the hardware and kernel.
1794 **/
1795void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1796{
1797 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001798 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001799
1800 switch (adapter->int_mode) {
1801 case E1000E_INT_MODE_MSIX:
1802 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001803 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1804 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001805 sizeof(struct msix_entry),
1806 GFP_KERNEL);
1807 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001808 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001809 adapter->msix_entries[i].entry = i;
1810
1811 err = pci_enable_msix(adapter->pdev,
1812 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001813 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001814 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001815 return;
1816 }
1817 /* MSI-X failed, so fall through and try MSI */
1818 e_err("Failed to initialize MSI-X interrupts. "
1819 "Falling back to MSI interrupts.\n");
1820 e1000e_reset_interrupt_capability(adapter);
1821 }
1822 adapter->int_mode = E1000E_INT_MODE_MSI;
1823 /* Fall through */
1824 case E1000E_INT_MODE_MSI:
1825 if (!pci_enable_msi(adapter->pdev)) {
1826 adapter->flags |= FLAG_MSI_ENABLED;
1827 } else {
1828 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1829 e_err("Failed to initialize MSI interrupts. Falling "
1830 "back to legacy interrupts.\n");
1831 }
1832 /* Fall through */
1833 case E1000E_INT_MODE_LEGACY:
1834 /* Don't do anything; this is the system default */
1835 break;
1836 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001837
1838 /* store the number of vectors being used */
1839 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001840}
1841
1842/**
1843 * e1000_request_msix - Initialize MSI-X interrupts
1844 *
1845 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1846 * kernel.
1847 **/
1848static int e1000_request_msix(struct e1000_adapter *adapter)
1849{
1850 struct net_device *netdev = adapter->netdev;
1851 int err = 0, vector = 0;
1852
1853 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001854 snprintf(adapter->rx_ring->name,
1855 sizeof(adapter->rx_ring->name) - 1,
1856 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001857 else
1858 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1859 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001860 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001861 netdev);
1862 if (err)
1863 goto out;
1864 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1865 adapter->rx_ring->itr_val = adapter->itr;
1866 vector++;
1867
1868 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001869 snprintf(adapter->tx_ring->name,
1870 sizeof(adapter->tx_ring->name) - 1,
1871 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001872 else
1873 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1874 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001875 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001876 netdev);
1877 if (err)
1878 goto out;
1879 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1880 adapter->tx_ring->itr_val = adapter->itr;
1881 vector++;
1882
1883 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001884 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001885 if (err)
1886 goto out;
1887
1888 e1000_configure_msix(adapter);
1889 return 0;
1890out:
1891 return err;
1892}
1893
Bruce Allanf8d59f72008-08-08 18:36:11 -07001894/**
1895 * e1000_request_irq - initialize interrupts
1896 *
1897 * Attempts to configure interrupts using the best available
1898 * capabilities of the hardware and kernel.
1899 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001900static int e1000_request_irq(struct e1000_adapter *adapter)
1901{
1902 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001903 int err;
1904
Bruce Allan4662e822008-08-26 18:37:06 -07001905 if (adapter->msix_entries) {
1906 err = e1000_request_msix(adapter);
1907 if (!err)
1908 return err;
1909 /* fall back to MSI */
1910 e1000e_reset_interrupt_capability(adapter);
1911 adapter->int_mode = E1000E_INT_MODE_MSI;
1912 e1000e_set_interrupt_capability(adapter);
1913 }
1914 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001915 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001916 netdev->name, netdev);
1917 if (!err)
1918 return err;
1919
1920 /* fall back to legacy interrupt */
1921 e1000e_reset_interrupt_capability(adapter);
1922 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001923 }
1924
Joe Perchesa0607fd2009-11-18 23:29:17 -08001925 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001926 netdev->name, netdev);
1927 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001928 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001929
1930 return err;
1931}
1932
1933static void e1000_free_irq(struct e1000_adapter *adapter)
1934{
1935 struct net_device *netdev = adapter->netdev;
1936
Bruce Allan4662e822008-08-26 18:37:06 -07001937 if (adapter->msix_entries) {
1938 int vector = 0;
1939
1940 free_irq(adapter->msix_entries[vector].vector, netdev);
1941 vector++;
1942
1943 free_irq(adapter->msix_entries[vector].vector, netdev);
1944 vector++;
1945
1946 /* Other Causes interrupt vector */
1947 free_irq(adapter->msix_entries[vector].vector, netdev);
1948 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001949 }
Bruce Allan4662e822008-08-26 18:37:06 -07001950
1951 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001952}
1953
1954/**
1955 * e1000_irq_disable - Mask off interrupt generation on the NIC
1956 **/
1957static void e1000_irq_disable(struct e1000_adapter *adapter)
1958{
1959 struct e1000_hw *hw = &adapter->hw;
1960
Auke Kokbc7f75f2007-09-17 12:30:59 -07001961 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001962 if (adapter->msix_entries)
1963 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001964 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001965
1966 if (adapter->msix_entries) {
1967 int i;
1968 for (i = 0; i < adapter->num_vectors; i++)
1969 synchronize_irq(adapter->msix_entries[i].vector);
1970 } else {
1971 synchronize_irq(adapter->pdev->irq);
1972 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001973}
1974
1975/**
1976 * e1000_irq_enable - Enable default interrupt generation settings
1977 **/
1978static void e1000_irq_enable(struct e1000_adapter *adapter)
1979{
1980 struct e1000_hw *hw = &adapter->hw;
1981
Bruce Allan4662e822008-08-26 18:37:06 -07001982 if (adapter->msix_entries) {
1983 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1984 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1985 } else {
1986 ew32(IMS, IMS_ENABLE_MASK);
1987 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001988 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001989}
1990
1991/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001992 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07001993 * @adapter: address of board private structure
1994 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001995 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001996 * For ASF and Pass Through versions of f/w this means that
1997 * the driver is loaded. For AMT version (only with 82573)
1998 * of the f/w this means that the network i/f is open.
1999 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002000void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002001{
2002 struct e1000_hw *hw = &adapter->hw;
2003 u32 ctrl_ext;
2004 u32 swsm;
2005
2006 /* Let firmware know the driver has taken over */
2007 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2008 swsm = er32(SWSM);
2009 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2010 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2011 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002012 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002013 }
2014}
2015
2016/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002017 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002018 * @adapter: address of board private structure
2019 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002020 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002021 * For ASF and Pass Through versions of f/w this means that the
2022 * driver is no longer loaded. For AMT version (only with 82573) i
2023 * of the f/w this means that the network i/f is closed.
2024 *
2025 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002026void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002027{
2028 struct e1000_hw *hw = &adapter->hw;
2029 u32 ctrl_ext;
2030 u32 swsm;
2031
2032 /* Let firmware taken over control of h/w */
2033 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2034 swsm = er32(SWSM);
2035 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2036 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2037 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002038 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002039 }
2040}
2041
Auke Kokbc7f75f2007-09-17 12:30:59 -07002042/**
2043 * @e1000_alloc_ring - allocate memory for a ring structure
2044 **/
2045static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2046 struct e1000_ring *ring)
2047{
2048 struct pci_dev *pdev = adapter->pdev;
2049
2050 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2051 GFP_KERNEL);
2052 if (!ring->desc)
2053 return -ENOMEM;
2054
2055 return 0;
2056}
2057
2058/**
2059 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2060 * @adapter: board private structure
2061 *
2062 * Return 0 on success, negative on failure
2063 **/
2064int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2065{
2066 struct e1000_ring *tx_ring = adapter->tx_ring;
2067 int err = -ENOMEM, size;
2068
2069 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002070 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002071 if (!tx_ring->buffer_info)
2072 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002073
2074 /* round up to nearest 4K */
2075 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2076 tx_ring->size = ALIGN(tx_ring->size, 4096);
2077
2078 err = e1000_alloc_ring_dma(adapter, tx_ring);
2079 if (err)
2080 goto err;
2081
2082 tx_ring->next_to_use = 0;
2083 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002084
2085 return 0;
2086err:
2087 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002088 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002089 return err;
2090}
2091
2092/**
2093 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2094 * @adapter: board private structure
2095 *
2096 * Returns 0 on success, negative on failure
2097 **/
2098int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2099{
2100 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002101 struct e1000_buffer *buffer_info;
2102 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002103
2104 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002105 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002106 if (!rx_ring->buffer_info)
2107 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002108
Auke Kok47f44e42007-10-25 13:57:44 -07002109 for (i = 0; i < rx_ring->count; i++) {
2110 buffer_info = &rx_ring->buffer_info[i];
2111 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2112 sizeof(struct e1000_ps_page),
2113 GFP_KERNEL);
2114 if (!buffer_info->ps_pages)
2115 goto err_pages;
2116 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002117
2118 desc_len = sizeof(union e1000_rx_desc_packet_split);
2119
2120 /* Round up to nearest 4K */
2121 rx_ring->size = rx_ring->count * desc_len;
2122 rx_ring->size = ALIGN(rx_ring->size, 4096);
2123
2124 err = e1000_alloc_ring_dma(adapter, rx_ring);
2125 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002126 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002127
2128 rx_ring->next_to_clean = 0;
2129 rx_ring->next_to_use = 0;
2130 rx_ring->rx_skb_top = NULL;
2131
2132 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002133
2134err_pages:
2135 for (i = 0; i < rx_ring->count; i++) {
2136 buffer_info = &rx_ring->buffer_info[i];
2137 kfree(buffer_info->ps_pages);
2138 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002139err:
2140 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002141 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002142 return err;
2143}
2144
2145/**
2146 * e1000_clean_tx_ring - Free Tx Buffers
2147 * @adapter: board private structure
2148 **/
2149static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2150{
2151 struct e1000_ring *tx_ring = adapter->tx_ring;
2152 struct e1000_buffer *buffer_info;
2153 unsigned long size;
2154 unsigned int i;
2155
2156 for (i = 0; i < tx_ring->count; i++) {
2157 buffer_info = &tx_ring->buffer_info[i];
2158 e1000_put_txbuf(adapter, buffer_info);
2159 }
2160
2161 size = sizeof(struct e1000_buffer) * tx_ring->count;
2162 memset(tx_ring->buffer_info, 0, size);
2163
2164 memset(tx_ring->desc, 0, tx_ring->size);
2165
2166 tx_ring->next_to_use = 0;
2167 tx_ring->next_to_clean = 0;
2168
2169 writel(0, adapter->hw.hw_addr + tx_ring->head);
2170 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2171}
2172
2173/**
2174 * e1000e_free_tx_resources - Free Tx Resources per Queue
2175 * @adapter: board private structure
2176 *
2177 * Free all transmit software resources
2178 **/
2179void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2180{
2181 struct pci_dev *pdev = adapter->pdev;
2182 struct e1000_ring *tx_ring = adapter->tx_ring;
2183
2184 e1000_clean_tx_ring(adapter);
2185
2186 vfree(tx_ring->buffer_info);
2187 tx_ring->buffer_info = NULL;
2188
2189 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2190 tx_ring->dma);
2191 tx_ring->desc = NULL;
2192}
2193
2194/**
2195 * e1000e_free_rx_resources - Free Rx Resources
2196 * @adapter: board private structure
2197 *
2198 * Free all receive software resources
2199 **/
2200
2201void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2202{
2203 struct pci_dev *pdev = adapter->pdev;
2204 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002205 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002206
2207 e1000_clean_rx_ring(adapter);
2208
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002209 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002210 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002211
Auke Kokbc7f75f2007-09-17 12:30:59 -07002212 vfree(rx_ring->buffer_info);
2213 rx_ring->buffer_info = NULL;
2214
Auke Kokbc7f75f2007-09-17 12:30:59 -07002215 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2216 rx_ring->dma);
2217 rx_ring->desc = NULL;
2218}
2219
2220/**
2221 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002222 * @adapter: pointer to adapter
2223 * @itr_setting: current adapter->itr
2224 * @packets: the number of packets during this measurement interval
2225 * @bytes: the number of bytes during this measurement interval
2226 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002227 * Stores a new ITR value based on packets and byte
2228 * counts during the last interrupt. The advantage of per interrupt
2229 * computation is faster updates and more accurate ITR for the current
2230 * traffic pattern. Constants in this function were computed
2231 * based on theoretical maximum wire speed and thresholds were set based
2232 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002233 * while increasing bulk throughput. This functionality is controlled
2234 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002235 **/
2236static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2237 u16 itr_setting, int packets,
2238 int bytes)
2239{
2240 unsigned int retval = itr_setting;
2241
2242 if (packets == 0)
2243 goto update_itr_done;
2244
2245 switch (itr_setting) {
2246 case lowest_latency:
2247 /* handle TSO and jumbo frames */
2248 if (bytes/packets > 8000)
2249 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002250 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002252 break;
2253 case low_latency: /* 50 usec aka 20000 ints/s */
2254 if (bytes > 10000) {
2255 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002256 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002257 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002258 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002260 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002261 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002262 } else if (bytes/packets > 2000) {
2263 retval = bulk_latency;
2264 } else if (packets <= 2 && bytes < 512) {
2265 retval = lowest_latency;
2266 }
2267 break;
2268 case bulk_latency: /* 250 usec aka 4000 ints/s */
2269 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002270 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002271 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002272 } else if (bytes < 6000) {
2273 retval = low_latency;
2274 }
2275 break;
2276 }
2277
2278update_itr_done:
2279 return retval;
2280}
2281
2282static void e1000_set_itr(struct e1000_adapter *adapter)
2283{
2284 struct e1000_hw *hw = &adapter->hw;
2285 u16 current_itr;
2286 u32 new_itr = adapter->itr;
2287
2288 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2289 if (adapter->link_speed != SPEED_1000) {
2290 current_itr = 0;
2291 new_itr = 4000;
2292 goto set_itr_now;
2293 }
2294
Bruce Allan828bac82010-09-29 21:39:37 +00002295 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2296 new_itr = 0;
2297 goto set_itr_now;
2298 }
2299
Auke Kokbc7f75f2007-09-17 12:30:59 -07002300 adapter->tx_itr = e1000_update_itr(adapter,
2301 adapter->tx_itr,
2302 adapter->total_tx_packets,
2303 adapter->total_tx_bytes);
2304 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2305 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2306 adapter->tx_itr = low_latency;
2307
2308 adapter->rx_itr = e1000_update_itr(adapter,
2309 adapter->rx_itr,
2310 adapter->total_rx_packets,
2311 adapter->total_rx_bytes);
2312 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2313 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2314 adapter->rx_itr = low_latency;
2315
2316 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2317
2318 switch (current_itr) {
2319 /* counts and packets in update_itr are dependent on these numbers */
2320 case lowest_latency:
2321 new_itr = 70000;
2322 break;
2323 case low_latency:
2324 new_itr = 20000; /* aka hwitr = ~200 */
2325 break;
2326 case bulk_latency:
2327 new_itr = 4000;
2328 break;
2329 default:
2330 break;
2331 }
2332
2333set_itr_now:
2334 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002335 /*
2336 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002337 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002338 * increasing
2339 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002340 new_itr = new_itr > adapter->itr ?
2341 min(adapter->itr + (new_itr >> 2), new_itr) :
2342 new_itr;
2343 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002344 adapter->rx_ring->itr_val = new_itr;
2345 if (adapter->msix_entries)
2346 adapter->rx_ring->set_itr = 1;
2347 else
Bruce Allan828bac82010-09-29 21:39:37 +00002348 if (new_itr)
2349 ew32(ITR, 1000000000 / (new_itr * 256));
2350 else
2351 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002352 }
2353}
2354
2355/**
Bruce Allan4662e822008-08-26 18:37:06 -07002356 * e1000_alloc_queues - Allocate memory for all rings
2357 * @adapter: board private structure to initialize
2358 **/
2359static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2360{
2361 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2362 if (!adapter->tx_ring)
2363 goto err;
2364
2365 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2366 if (!adapter->rx_ring)
2367 goto err;
2368
2369 return 0;
2370err:
2371 e_err("Unable to allocate memory for queues\n");
2372 kfree(adapter->rx_ring);
2373 kfree(adapter->tx_ring);
2374 return -ENOMEM;
2375}
2376
2377/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002379 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002380 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002381 **/
2382static int e1000_clean(struct napi_struct *napi, int budget)
2383{
2384 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002385 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002386 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002387 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002388
Wang Chen4cf16532008-11-12 23:38:14 -08002389 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002390
Bruce Allan4662e822008-08-26 18:37:06 -07002391 if (adapter->msix_entries &&
2392 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2393 goto clean_rx;
2394
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002395 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002396
Bruce Allan4662e822008-08-26 18:37:06 -07002397clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398 adapter->clean_rx(adapter, &work_done, budget);
2399
Alexander Duyck12d04a32009-03-25 22:05:03 +00002400 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002401 work_done = budget;
2402
David S. Miller53e52c72008-01-07 21:06:12 -08002403 /* If budget not fully consumed, exit the polling mode */
2404 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002405 if (adapter->itr_setting & 3)
2406 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002407 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002408 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2409 if (adapter->msix_entries)
2410 ew32(IMS, adapter->rx_ring->ims_val);
2411 else
2412 e1000_irq_enable(adapter);
2413 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002414 }
2415
2416 return work_done;
2417}
2418
2419static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2420{
2421 struct e1000_adapter *adapter = netdev_priv(netdev);
2422 struct e1000_hw *hw = &adapter->hw;
2423 u32 vfta, index;
2424
2425 /* don't update vlan cookie if already programmed */
2426 if ((adapter->hw.mng_cookie.status &
2427 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2428 (vid == adapter->mng_vlan_id))
2429 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002430
Auke Kokbc7f75f2007-09-17 12:30:59 -07002431 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002432 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2433 index = (vid >> 5) & 0x7F;
2434 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2435 vfta |= (1 << (vid & 0x1F));
2436 hw->mac.ops.write_vfta(hw, index, vfta);
2437 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002438
2439 set_bit(vid, adapter->active_vlans);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440}
2441
2442static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2443{
2444 struct e1000_adapter *adapter = netdev_priv(netdev);
2445 struct e1000_hw *hw = &adapter->hw;
2446 u32 vfta, index;
2447
Auke Kokbc7f75f2007-09-17 12:30:59 -07002448 if ((adapter->hw.mng_cookie.status &
2449 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2450 (vid == adapter->mng_vlan_id)) {
2451 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002452 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002453 return;
2454 }
2455
2456 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002457 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2458 index = (vid >> 5) & 0x7F;
2459 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2460 vfta &= ~(1 << (vid & 0x1F));
2461 hw->mac.ops.write_vfta(hw, index, vfta);
2462 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002463
2464 clear_bit(vid, adapter->active_vlans);
2465}
2466
2467/**
2468 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2469 * @adapter: board private structure to initialize
2470 **/
2471static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2472{
2473 struct net_device *netdev = adapter->netdev;
2474 struct e1000_hw *hw = &adapter->hw;
2475 u32 rctl;
2476
2477 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2478 /* disable VLAN receive filtering */
2479 rctl = er32(RCTL);
2480 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2481 ew32(RCTL, rctl);
2482
2483 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2484 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2485 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2486 }
2487 }
2488}
2489
2490/**
2491 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2492 * @adapter: board private structure to initialize
2493 **/
2494static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2495{
2496 struct e1000_hw *hw = &adapter->hw;
2497 u32 rctl;
2498
2499 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2500 /* enable VLAN receive filtering */
2501 rctl = er32(RCTL);
2502 rctl |= E1000_RCTL_VFE;
2503 rctl &= ~E1000_RCTL_CFIEN;
2504 ew32(RCTL, rctl);
2505 }
2506}
2507
2508/**
2509 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2510 * @adapter: board private structure to initialize
2511 **/
2512static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2513{
2514 struct e1000_hw *hw = &adapter->hw;
2515 u32 ctrl;
2516
2517 /* disable VLAN tag insert/strip */
2518 ctrl = er32(CTRL);
2519 ctrl &= ~E1000_CTRL_VME;
2520 ew32(CTRL, ctrl);
2521}
2522
2523/**
2524 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2525 * @adapter: board private structure to initialize
2526 **/
2527static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2528{
2529 struct e1000_hw *hw = &adapter->hw;
2530 u32 ctrl;
2531
2532 /* enable VLAN tag insert/strip */
2533 ctrl = er32(CTRL);
2534 ctrl |= E1000_CTRL_VME;
2535 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002536}
2537
2538static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2539{
2540 struct net_device *netdev = adapter->netdev;
2541 u16 vid = adapter->hw.mng_cookie.vlan_id;
2542 u16 old_vid = adapter->mng_vlan_id;
2543
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002544 if (adapter->hw.mng_cookie.status &
2545 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2546 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002547 adapter->mng_vlan_id = vid;
2548 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002549
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002550 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2551 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002552}
2553
2554static void e1000_restore_vlan(struct e1000_adapter *adapter)
2555{
2556 u16 vid;
2557
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002558 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002559
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002560 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002561 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002562}
2563
Bruce Allancd791612010-05-10 14:59:51 +00002564static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002565{
2566 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002567 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002568
2569 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2570 return;
2571
2572 manc = er32(MANC);
2573
Bruce Allanad680762008-03-28 09:15:03 -07002574 /*
2575 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002576 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002577 * the packets will be handled on SMBUS
2578 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002579 manc |= E1000_MANC_EN_MNG2HOST;
2580 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002581
2582 switch (hw->mac.type) {
2583 default:
2584 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2585 break;
2586 case e1000_82574:
2587 case e1000_82583:
2588 /*
2589 * Check if IPMI pass-through decision filter already exists;
2590 * if so, enable it.
2591 */
2592 for (i = 0, j = 0; i < 8; i++) {
2593 mdef = er32(MDEF(i));
2594
2595 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002596 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002597 continue;
2598
2599 /* Enable this decision filter in MANC2H */
2600 if (mdef)
2601 manc2h |= (1 << i);
2602
2603 j |= mdef;
2604 }
2605
2606 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2607 break;
2608
2609 /* Create new decision filter in an empty filter */
2610 for (i = 0, j = 0; i < 8; i++)
2611 if (er32(MDEF(i)) == 0) {
2612 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2613 E1000_MDEF_PORT_664));
2614 manc2h |= (1 << 1);
2615 j++;
2616 break;
2617 }
2618
2619 if (!j)
2620 e_warn("Unable to create IPMI pass-through filter\n");
2621 break;
2622 }
2623
Auke Kokbc7f75f2007-09-17 12:30:59 -07002624 ew32(MANC2H, manc2h);
2625 ew32(MANC, manc);
2626}
2627
2628/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002629 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002630 * @adapter: board private structure
2631 *
2632 * Configure the Tx unit of the MAC after a reset.
2633 **/
2634static void e1000_configure_tx(struct e1000_adapter *adapter)
2635{
2636 struct e1000_hw *hw = &adapter->hw;
2637 struct e1000_ring *tx_ring = adapter->tx_ring;
2638 u64 tdba;
2639 u32 tdlen, tctl, tipg, tarc;
2640 u32 ipgr1, ipgr2;
2641
2642 /* Setup the HW Tx Head and Tail descriptor pointers */
2643 tdba = tx_ring->dma;
2644 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002645 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002646 ew32(TDBAH, (tdba >> 32));
2647 ew32(TDLEN, tdlen);
2648 ew32(TDH, 0);
2649 ew32(TDT, 0);
2650 tx_ring->head = E1000_TDH;
2651 tx_ring->tail = E1000_TDT;
2652
2653 /* Set the default values for the Tx Inter Packet Gap timer */
2654 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2655 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2656 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2657
2658 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2659 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2660
2661 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2662 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2663 ew32(TIPG, tipg);
2664
2665 /* Set the Tx Interrupt Delay register */
2666 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002667 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002668 ew32(TADV, adapter->tx_abs_int_delay);
2669
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002670 if (adapter->flags2 & FLAG2_DMA_BURST) {
2671 u32 txdctl = er32(TXDCTL(0));
2672 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2673 E1000_TXDCTL_WTHRESH);
2674 /*
2675 * set up some performance related parameters to encourage the
2676 * hardware to use the bus more efficiently in bursts, depends
2677 * on the tx_int_delay to be enabled,
2678 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2679 * hthresh = 1 ==> prefetch when one or more available
2680 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2681 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002682 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002683 */
2684 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2685 ew32(TXDCTL(0), txdctl);
2686 /* erratum work around: set txdctl the same for both queues */
2687 ew32(TXDCTL(1), txdctl);
2688 }
2689
Auke Kokbc7f75f2007-09-17 12:30:59 -07002690 /* Program the Transmit Control Register */
2691 tctl = er32(TCTL);
2692 tctl &= ~E1000_TCTL_CT;
2693 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2694 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2695
2696 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002697 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002698 /*
2699 * set the speed mode bit, we'll clear it if we're not at
2700 * gigabit link later
2701 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002702#define SPEED_MODE_BIT (1 << 21)
2703 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002704 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705 }
2706
2707 /* errata: program both queues to unweighted RR */
2708 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002709 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002710 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002711 ew32(TARC(0), tarc);
2712 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002713 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002714 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002715 }
2716
Auke Kokbc7f75f2007-09-17 12:30:59 -07002717 /* Setup Transmit Descriptor Settings for eop descriptor */
2718 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2719
2720 /* only set IDE if we are delaying interrupts using the timers */
2721 if (adapter->tx_int_delay)
2722 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2723
2724 /* enable Report Status bit */
2725 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2726
2727 ew32(TCTL, tctl);
2728
Simon Hormanedfea6e62009-06-08 14:28:36 +00002729 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002730}
2731
2732/**
2733 * e1000_setup_rctl - configure the receive control registers
2734 * @adapter: Board private structure
2735 **/
2736#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2737 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2738static void e1000_setup_rctl(struct e1000_adapter *adapter)
2739{
2740 struct e1000_hw *hw = &adapter->hw;
2741 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002742 u32 pages = 0;
2743
Bruce Allana1ce6472010-09-22 17:16:40 +00002744 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2745 if (hw->mac.type == e1000_pch2lan) {
2746 s32 ret_val;
2747
2748 if (adapter->netdev->mtu > ETH_DATA_LEN)
2749 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2750 else
2751 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002752
2753 if (ret_val)
2754 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002755 }
2756
Auke Kokbc7f75f2007-09-17 12:30:59 -07002757 /* Program MC offset vector base */
2758 rctl = er32(RCTL);
2759 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2760 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2761 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2762 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2763
2764 /* Do not Store bad packets */
2765 rctl &= ~E1000_RCTL_SBP;
2766
2767 /* Enable Long Packet receive */
2768 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2769 rctl &= ~E1000_RCTL_LPE;
2770 else
2771 rctl |= E1000_RCTL_LPE;
2772
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002773 /* Some systems expect that the CRC is included in SMBUS traffic. The
2774 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2775 * host memory when this is enabled
2776 */
2777 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2778 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002779
Bruce Allana4f58f52009-06-02 11:29:18 +00002780 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2781 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2782 u16 phy_data;
2783
2784 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2785 phy_data &= 0xfff8;
2786 phy_data |= (1 << 2);
2787 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2788
2789 e1e_rphy(hw, 22, &phy_data);
2790 phy_data &= 0x0fff;
2791 phy_data |= (1 << 14);
2792 e1e_wphy(hw, 0x10, 0x2823);
2793 e1e_wphy(hw, 0x11, 0x0003);
2794 e1e_wphy(hw, 22, phy_data);
2795 }
2796
Auke Kokbc7f75f2007-09-17 12:30:59 -07002797 /* Setup buffer sizes */
2798 rctl &= ~E1000_RCTL_SZ_4096;
2799 rctl |= E1000_RCTL_BSEX;
2800 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801 case 2048:
2802 default:
2803 rctl |= E1000_RCTL_SZ_2048;
2804 rctl &= ~E1000_RCTL_BSEX;
2805 break;
2806 case 4096:
2807 rctl |= E1000_RCTL_SZ_4096;
2808 break;
2809 case 8192:
2810 rctl |= E1000_RCTL_SZ_8192;
2811 break;
2812 case 16384:
2813 rctl |= E1000_RCTL_SZ_16384;
2814 break;
2815 }
2816
2817 /*
2818 * 82571 and greater support packet-split where the protocol
2819 * header is placed in skb->data and the packet data is
2820 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2821 * In the case of a non-split, skb->data is linearly filled,
2822 * followed by the page buffers. Therefore, skb->data is
2823 * sized to hold the largest protocol header.
2824 *
2825 * allocations using alloc_page take too long for regular MTU
2826 * so only enable packet split for jumbo frames
2827 *
2828 * Using pages when the page size is greater than 16k wastes
2829 * a lot of memory, since we allocate 3 pages at all times
2830 * per packet.
2831 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fec2010-06-17 18:59:27 +00002833 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002834 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002836 else
2837 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838
2839 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002840 u32 psrctl = 0;
2841
Auke Kokbc7f75f2007-09-17 12:30:59 -07002842 /* Configure extra packet-split registers */
2843 rfctl = er32(RFCTL);
2844 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002845 /*
2846 * disable packet split support for IPv6 extension headers,
2847 * because some malformed IPv6 headers can hang the Rx
2848 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002849 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2850 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2851
2852 ew32(RFCTL, rfctl);
2853
Auke Kok140a7482007-10-25 13:57:58 -07002854 /* Enable Packet split descriptors */
2855 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002856
2857 psrctl |= adapter->rx_ps_bsize0 >>
2858 E1000_PSRCTL_BSIZE0_SHIFT;
2859
2860 switch (adapter->rx_ps_pages) {
2861 case 3:
2862 psrctl |= PAGE_SIZE <<
2863 E1000_PSRCTL_BSIZE3_SHIFT;
2864 case 2:
2865 psrctl |= PAGE_SIZE <<
2866 E1000_PSRCTL_BSIZE2_SHIFT;
2867 case 1:
2868 psrctl |= PAGE_SIZE >>
2869 E1000_PSRCTL_BSIZE1_SHIFT;
2870 break;
2871 }
2872
2873 ew32(PSRCTL, psrctl);
2874 }
2875
2876 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002877 /* just started the receive unit, no need to restart */
2878 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002879}
2880
2881/**
2882 * e1000_configure_rx - Configure Receive Unit after Reset
2883 * @adapter: board private structure
2884 *
2885 * Configure the Rx unit of the MAC after a reset.
2886 **/
2887static void e1000_configure_rx(struct e1000_adapter *adapter)
2888{
2889 struct e1000_hw *hw = &adapter->hw;
2890 struct e1000_ring *rx_ring = adapter->rx_ring;
2891 u64 rdba;
2892 u32 rdlen, rctl, rxcsum, ctrl_ext;
2893
2894 if (adapter->rx_ps_pages) {
2895 /* this is a 32 byte descriptor */
2896 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002897 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002898 adapter->clean_rx = e1000_clean_rx_irq_ps;
2899 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002900 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2901 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2902 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2903 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002904 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002905 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002906 adapter->clean_rx = e1000_clean_rx_irq;
2907 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2908 }
2909
2910 /* disable receives while setting up the descriptors */
2911 rctl = er32(RCTL);
2912 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2913 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00002914 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002915
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002916 if (adapter->flags2 & FLAG2_DMA_BURST) {
2917 /*
2918 * set the writeback threshold (only takes effect if the RDTR
2919 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00002920 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002921 * granularity = 01
2922 * wthresh = 04,
2923 * hthresh = 04,
2924 * pthresh = 0x20
2925 */
2926 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
2927 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
2928
2929 /*
2930 * override the delay timers for enabling bursting, only if
2931 * the value was not set by the user via module options
2932 */
2933 if (adapter->rx_int_delay == DEFAULT_RDTR)
2934 adapter->rx_int_delay = BURST_RDTR;
2935 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
2936 adapter->rx_abs_int_delay = BURST_RADV;
2937 }
2938
Auke Kokbc7f75f2007-09-17 12:30:59 -07002939 /* set the Receive Delay Timer Register */
2940 ew32(RDTR, adapter->rx_int_delay);
2941
2942 /* irq moderation */
2943 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00002944 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07002945 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946
2947 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002948 /* Auto-Mask interrupts upon ICR access */
2949 ctrl_ext |= E1000_CTRL_EXT_IAME;
2950 ew32(IAM, 0xffffffff);
2951 ew32(CTRL_EXT, ctrl_ext);
2952 e1e_flush();
2953
Bruce Allanad680762008-03-28 09:15:03 -07002954 /*
2955 * Setup the HW Rx Head and Tail Descriptor Pointers and
2956 * the Base and Length of the Rx Descriptor Ring
2957 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002959 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002960 ew32(RDBAH, (rdba >> 32));
2961 ew32(RDLEN, rdlen);
2962 ew32(RDH, 0);
2963 ew32(RDT, 0);
2964 rx_ring->head = E1000_RDH;
2965 rx_ring->tail = E1000_RDT;
2966
2967 /* Enable Receive Checksum Offload for TCP and UDP */
2968 rxcsum = er32(RXCSUM);
2969 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2970 rxcsum |= E1000_RXCSUM_TUOFL;
2971
Bruce Allanad680762008-03-28 09:15:03 -07002972 /*
2973 * IPv4 payload checksum for UDP fragments must be
2974 * used in conjunction with packet-split.
2975 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002976 if (adapter->rx_ps_pages)
2977 rxcsum |= E1000_RXCSUM_IPPCSE;
2978 } else {
2979 rxcsum &= ~E1000_RXCSUM_TUOFL;
2980 /* no need to clear IPPCSE as it defaults to 0 */
2981 }
2982 ew32(RXCSUM, rxcsum);
2983
Bruce Allanad680762008-03-28 09:15:03 -07002984 /*
2985 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002986 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002987 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2988 */
Bruce Allan828bac82010-09-29 21:39:37 +00002989 if ((adapter->flags & FLAG_HAS_ERT) ||
2990 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00002991 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2992 u32 rxdctl = er32(RXDCTL(0));
2993 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00002994 if (adapter->flags & FLAG_HAS_ERT)
2995 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00002996 /*
2997 * With jumbo frames and early-receive enabled,
2998 * excessive C-state transition latencies result in
2999 * dropped transactions.
3000 */
Bruce Allanaf667a22010-12-31 06:10:01 +00003001 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003002 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003003 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3004 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003005 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003006 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003007
3008 /* Enable Receives */
3009 ew32(RCTL, rctl);
3010}
3011
3012/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003013 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07003014 * @hw: pointer to the HW structure
3015 * @mc_addr_list: array of multicast addresses to program
3016 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07003017 *
Bruce Allanab8932f2010-01-13 02:05:38 +00003018 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003019 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003020 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003021static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003022 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003023{
Bruce Allanab8932f2010-01-13 02:05:38 +00003024 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003025}
3026
3027/**
3028 * e1000_set_multi - Multicast and Promiscuous mode set
3029 * @netdev: network interface device structure
3030 *
3031 * The set_multi entry point is called whenever the multicast address
3032 * list or the network interface flags are updated. This routine is
3033 * responsible for configuring the hardware for proper multicast,
3034 * promiscuous mode, and all-multi behavior.
3035 **/
3036static void e1000_set_multi(struct net_device *netdev)
3037{
3038 struct e1000_adapter *adapter = netdev_priv(netdev);
3039 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003040 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003041 u8 *mta_list;
3042 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003043
3044 /* Check for Promiscuous and All Multicast modes */
3045
3046 rctl = er32(RCTL);
3047
3048 if (netdev->flags & IFF_PROMISC) {
3049 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003050 rctl &= ~E1000_RCTL_VFE;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003051 /* Do not hardware filter VLANs in promisc mode */
3052 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003053 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003054 if (netdev->flags & IFF_ALLMULTI) {
3055 rctl |= E1000_RCTL_MPE;
3056 rctl &= ~E1000_RCTL_UPE;
3057 } else {
3058 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3059 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003060 e1000e_vlan_filter_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003061 }
3062
3063 ew32(RCTL, rctl);
3064
Jiri Pirko7aeef972010-02-05 02:52:39 +00003065 if (!netdev_mc_empty(netdev)) {
Bruce Allan90da0662011-01-06 07:02:53 +00003066 int i = 0;
3067
Jiri Pirko7aeef972010-02-05 02:52:39 +00003068 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003069 if (!mta_list)
3070 return;
3071
3072 /* prepare a packed array of only addresses. */
Jiri Pirko22bedad32010-04-01 21:22:57 +00003073 netdev_for_each_mc_addr(ha, netdev)
3074 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003075
Bruce Allanab8932f2010-01-13 02:05:38 +00003076 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003077 kfree(mta_list);
3078 } else {
3079 /*
3080 * if we're called from probe, we might not have
3081 * anything to do here, so clear out the list
3082 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003083 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003084 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003085
3086 if (netdev->features & NETIF_F_HW_VLAN_RX)
3087 e1000e_vlan_strip_enable(adapter);
3088 else
3089 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003090}
3091
3092/**
Bruce Allanad680762008-03-28 09:15:03 -07003093 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003094 * @adapter: private board structure
3095 **/
3096static void e1000_configure(struct e1000_adapter *adapter)
3097{
3098 e1000_set_multi(adapter->netdev);
3099
3100 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003101 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003102
3103 e1000_configure_tx(adapter);
3104 e1000_setup_rctl(adapter);
3105 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003106 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003107}
3108
3109/**
3110 * e1000e_power_up_phy - restore link in case the phy was powered down
3111 * @adapter: address of board private structure
3112 *
3113 * The phy may be powered down to save power and turn off link when the
3114 * driver is unloaded and wake on lan is not enabled (among others)
3115 * *** this routine MUST be followed by a call to e1000e_reset ***
3116 **/
3117void e1000e_power_up_phy(struct e1000_adapter *adapter)
3118{
Bruce Allan17f208d2009-12-01 15:47:22 +00003119 if (adapter->hw.phy.ops.power_up)
3120 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003121
3122 adapter->hw.mac.ops.setup_link(&adapter->hw);
3123}
3124
3125/**
3126 * e1000_power_down_phy - Power down the PHY
3127 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003128 * Power down the PHY so no link is implied when interface is down.
3129 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003130 */
3131static void e1000_power_down_phy(struct e1000_adapter *adapter)
3132{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003133 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003134 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003135 return;
3136
Bruce Allan17f208d2009-12-01 15:47:22 +00003137 if (adapter->hw.phy.ops.power_down)
3138 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003139}
3140
3141/**
3142 * e1000e_reset - bring the hardware into a known good state
3143 *
3144 * This function boots the hardware and enables some settings that
3145 * require a configuration cycle of the hardware - those cannot be
3146 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003147 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003148 */
3149void e1000e_reset(struct e1000_adapter *adapter)
3150{
3151 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003152 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003153 struct e1000_hw *hw = &adapter->hw;
3154 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003155 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003156 u16 hwm;
3157
Bruce Allanad680762008-03-28 09:15:03 -07003158 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003159 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003160
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003161 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003162 /*
3163 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003164 * large enough to accommodate two full transmit packets,
3165 * rounded up to the next 1KB and expressed in KB. Likewise,
3166 * the Rx FIFO should be large enough to accommodate at least
3167 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003168 * expressed in KB.
3169 */
Auke Kokdf762462007-10-25 13:57:53 -07003170 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003171 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003172 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003173 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003174 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003175 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003176 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003177 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003178 */
3179 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003180 sizeof(struct e1000_tx_desc) -
3181 ETH_FCS_LEN) * 2;
3182 min_tx_space = ALIGN(min_tx_space, 1024);
3183 min_tx_space >>= 10;
3184 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003185 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003186 min_rx_space = ALIGN(min_rx_space, 1024);
3187 min_rx_space >>= 10;
3188
Bruce Allanad680762008-03-28 09:15:03 -07003189 /*
3190 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003191 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003192 * allocation, take space away from current Rx allocation
3193 */
Auke Kokdf762462007-10-25 13:57:53 -07003194 if ((tx_space < min_tx_space) &&
3195 ((min_tx_space - tx_space) < pba)) {
3196 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003197
Bruce Allanad680762008-03-28 09:15:03 -07003198 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003199 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003200 * adjustment or use Early Receive if available
3201 */
Auke Kokdf762462007-10-25 13:57:53 -07003202 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003203 (!(adapter->flags & FLAG_HAS_ERT)))
3204 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003205 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003206 }
Auke Kokdf762462007-10-25 13:57:53 -07003207
3208 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003209 }
3210
Bruce Allanad680762008-03-28 09:15:03 -07003211 /*
3212 * flow control settings
3213 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003214 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003215 * (or the size used for early receive) above it in the Rx FIFO.
3216 * Set it to the lower of:
3217 * - 90% of the Rx FIFO size, and
3218 * - the full Rx FIFO size minus the early receive size (for parts
3219 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003220 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003221 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003222 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3223 fc->pause_time = 0xFFFF;
3224 else
3225 fc->pause_time = E1000_FC_PAUSE_TIME;
3226 fc->send_xon = 1;
3227 fc->current_mode = fc->requested_mode;
3228
3229 switch (hw->mac.type) {
3230 default:
3231 if ((adapter->flags & FLAG_HAS_ERT) &&
3232 (adapter->netdev->mtu > ETH_DATA_LEN))
3233 hwm = min(((pba << 10) * 9 / 10),
3234 ((pba << 10) - (E1000_ERT_2048 << 3)));
3235 else
3236 hwm = min(((pba << 10) * 9 / 10),
3237 ((pba << 10) - adapter->max_frame_size));
3238
3239 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3240 fc->low_water = fc->high_water - 8;
3241 break;
3242 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003243 /*
3244 * Workaround PCH LOM adapter hangs with certain network
3245 * loads. If hangs persist, try disabling Tx flow control.
3246 */
3247 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3248 fc->high_water = 0x3500;
3249 fc->low_water = 0x1500;
3250 } else {
3251 fc->high_water = 0x5000;
3252 fc->low_water = 0x3000;
3253 }
Bruce Allana3055952010-05-10 15:02:12 +00003254 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003255 break;
3256 case e1000_pch2lan:
3257 fc->high_water = 0x05C20;
3258 fc->low_water = 0x05048;
3259 fc->pause_time = 0x0650;
3260 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003261 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3262 pba = 14;
3263 ew32(PBA, pba);
3264 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003265 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003266 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003267
Bruce Allan828bac82010-09-29 21:39:37 +00003268 /*
3269 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3270 * fit in receive buffer and early-receive not supported.
3271 */
3272 if (adapter->itr_setting & 0x3) {
3273 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3274 !(adapter->flags & FLAG_HAS_ERT)) {
3275 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3276 dev_info(&adapter->pdev->dev,
3277 "Interrupt Throttle Rate turned off\n");
3278 adapter->flags2 |= FLAG2_DISABLE_AIM;
3279 ew32(ITR, 0);
3280 }
3281 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3282 dev_info(&adapter->pdev->dev,
3283 "Interrupt Throttle Rate turned on\n");
3284 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3285 adapter->itr = 20000;
3286 ew32(ITR, 1000000000 / (adapter->itr * 256));
3287 }
3288 }
3289
Auke Kokbc7f75f2007-09-17 12:30:59 -07003290 /* Allow time for pending master requests to run */
3291 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003292
3293 /*
3294 * For parts with AMT enabled, let the firmware know
3295 * that the network interface is in control
3296 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003297 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003298 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003299
Auke Kokbc7f75f2007-09-17 12:30:59 -07003300 ew32(WUC, 0);
3301
3302 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003303 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003304
3305 e1000_update_mng_vlan(adapter);
3306
3307 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3308 ew32(VET, ETH_P_8021Q);
3309
3310 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003311
3312 if (!netif_running(adapter->netdev) &&
3313 !test_bit(__E1000_TESTING, &adapter->state)) {
3314 e1000_power_down_phy(adapter);
3315 return;
3316 }
3317
Auke Kokbc7f75f2007-09-17 12:30:59 -07003318 e1000_get_phy_info(hw);
3319
Bruce Allan918d7192009-06-02 11:28:20 +00003320 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3321 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003322 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003323 /*
3324 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003326 * different we would do if it failed
3327 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003328 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3329 phy_data &= ~IGP02E1000_PM_SPD;
3330 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3331 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003332}
3333
3334int e1000e_up(struct e1000_adapter *adapter)
3335{
3336 struct e1000_hw *hw = &adapter->hw;
3337
3338 /* hardware has been reset, we need to reload some things */
3339 e1000_configure(adapter);
3340
3341 clear_bit(__E1000_DOWN, &adapter->state);
3342
3343 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003344 if (adapter->msix_entries)
3345 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003346 e1000_irq_enable(adapter);
3347
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003348 netif_wake_queue(adapter->netdev);
3349
Auke Kokbc7f75f2007-09-17 12:30:59 -07003350 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003351 if (adapter->msix_entries)
3352 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3353 else
3354 ew32(ICS, E1000_ICS_LSC);
3355
Auke Kokbc7f75f2007-09-17 12:30:59 -07003356 return 0;
3357}
3358
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003359static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3360{
3361 struct e1000_hw *hw = &adapter->hw;
3362
3363 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3364 return;
3365
3366 /* flush pending descriptor writebacks to memory */
3367 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3368 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3369
3370 /* execute the writes immediately */
3371 e1e_flush();
3372}
3373
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003374static void e1000e_update_stats(struct e1000_adapter *adapter);
3375
Auke Kokbc7f75f2007-09-17 12:30:59 -07003376void e1000e_down(struct e1000_adapter *adapter)
3377{
3378 struct net_device *netdev = adapter->netdev;
3379 struct e1000_hw *hw = &adapter->hw;
3380 u32 tctl, rctl;
3381
Bruce Allanad680762008-03-28 09:15:03 -07003382 /*
3383 * signal that we're down so the interrupt handler does not
3384 * reschedule our watchdog timer
3385 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003386 set_bit(__E1000_DOWN, &adapter->state);
3387
3388 /* disable receives in the hardware */
3389 rctl = er32(RCTL);
3390 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3391 /* flush and sleep below */
3392
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003393 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003394
3395 /* disable transmits in the hardware */
3396 tctl = er32(TCTL);
3397 tctl &= ~E1000_TCTL_EN;
3398 ew32(TCTL, tctl);
3399 /* flush both disables and wait for them to finish */
3400 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003401 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003402
3403 napi_disable(&adapter->napi);
3404 e1000_irq_disable(adapter);
3405
3406 del_timer_sync(&adapter->watchdog_timer);
3407 del_timer_sync(&adapter->phy_info_timer);
3408
Auke Kokbc7f75f2007-09-17 12:30:59 -07003409 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003410
3411 spin_lock(&adapter->stats64_lock);
3412 e1000e_update_stats(adapter);
3413 spin_unlock(&adapter->stats64_lock);
3414
Auke Kokbc7f75f2007-09-17 12:30:59 -07003415 adapter->link_speed = 0;
3416 adapter->link_duplex = 0;
3417
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003418 if (!pci_channel_offline(adapter->pdev))
3419 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003420
3421 e1000e_flush_descriptors(adapter);
3422
Auke Kokbc7f75f2007-09-17 12:30:59 -07003423 e1000_clean_tx_ring(adapter);
3424 e1000_clean_rx_ring(adapter);
3425
3426 /*
3427 * TODO: for power management, we could drop the link and
3428 * pci_disable_device here.
3429 */
3430}
3431
3432void e1000e_reinit_locked(struct e1000_adapter *adapter)
3433{
3434 might_sleep();
3435 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003436 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003437 e1000e_down(adapter);
3438 e1000e_up(adapter);
3439 clear_bit(__E1000_RESETTING, &adapter->state);
3440}
3441
3442/**
3443 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3444 * @adapter: board private structure to initialize
3445 *
3446 * e1000_sw_init initializes the Adapter private data structure.
3447 * Fields are initialized based on PCI device information and
3448 * OS network device settings (MTU size).
3449 **/
3450static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3451{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003452 struct net_device *netdev = adapter->netdev;
3453
3454 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3455 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003456 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3457 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003458
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003459 spin_lock_init(&adapter->stats64_lock);
3460
Bruce Allan4662e822008-08-26 18:37:06 -07003461 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003462
Bruce Allan4662e822008-08-26 18:37:06 -07003463 if (e1000_alloc_queues(adapter))
3464 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003465
Auke Kokbc7f75f2007-09-17 12:30:59 -07003466 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003467 e1000_irq_disable(adapter);
3468
Auke Kokbc7f75f2007-09-17 12:30:59 -07003469 set_bit(__E1000_DOWN, &adapter->state);
3470 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003471}
3472
3473/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003474 * e1000_intr_msi_test - Interrupt Handler
3475 * @irq: interrupt number
3476 * @data: pointer to a network interface device structure
3477 **/
3478static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3479{
3480 struct net_device *netdev = data;
3481 struct e1000_adapter *adapter = netdev_priv(netdev);
3482 struct e1000_hw *hw = &adapter->hw;
3483 u32 icr = er32(ICR);
3484
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003485 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003486 if (icr & E1000_ICR_RXSEQ) {
3487 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3488 wmb();
3489 }
3490
3491 return IRQ_HANDLED;
3492}
3493
3494/**
3495 * e1000_test_msi_interrupt - Returns 0 for successful test
3496 * @adapter: board private struct
3497 *
3498 * code flow taken from tg3.c
3499 **/
3500static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3501{
3502 struct net_device *netdev = adapter->netdev;
3503 struct e1000_hw *hw = &adapter->hw;
3504 int err;
3505
3506 /* poll_enable hasn't been called yet, so don't need disable */
3507 /* clear any pending events */
3508 er32(ICR);
3509
3510 /* free the real vector and request a test handler */
3511 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003512 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003513
3514 /* Assume that the test fails, if it succeeds then the test
3515 * MSI irq handler will unset this flag */
3516 adapter->flags |= FLAG_MSI_TEST_FAILED;
3517
3518 err = pci_enable_msi(adapter->pdev);
3519 if (err)
3520 goto msi_test_failed;
3521
Joe Perchesa0607fd2009-11-18 23:29:17 -08003522 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003523 netdev->name, netdev);
3524 if (err) {
3525 pci_disable_msi(adapter->pdev);
3526 goto msi_test_failed;
3527 }
3528
3529 wmb();
3530
3531 e1000_irq_enable(adapter);
3532
3533 /* fire an unusual interrupt on the test handler */
3534 ew32(ICS, E1000_ICS_RXSEQ);
3535 e1e_flush();
3536 msleep(50);
3537
3538 e1000_irq_disable(adapter);
3539
3540 rmb();
3541
3542 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003543 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003544 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3545 } else
3546 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003547
3548 free_irq(adapter->pdev->irq, netdev);
3549 pci_disable_msi(adapter->pdev);
3550
Bruce Allanf8d59f72008-08-08 18:36:11 -07003551msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003552 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003553 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003554}
3555
3556/**
3557 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3558 * @adapter: board private struct
3559 *
3560 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3561 **/
3562static int e1000_test_msi(struct e1000_adapter *adapter)
3563{
3564 int err;
3565 u16 pci_cmd;
3566
3567 if (!(adapter->flags & FLAG_MSI_ENABLED))
3568 return 0;
3569
3570 /* disable SERR in case the MSI write causes a master abort */
3571 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003572 if (pci_cmd & PCI_COMMAND_SERR)
3573 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3574 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003575
3576 err = e1000_test_msi_interrupt(adapter);
3577
Dean Nelson36f24072010-06-29 18:12:05 +00003578 /* re-enable SERR */
3579 if (pci_cmd & PCI_COMMAND_SERR) {
3580 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3581 pci_cmd |= PCI_COMMAND_SERR;
3582 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3583 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003584
Bruce Allanf8d59f72008-08-08 18:36:11 -07003585 return err;
3586}
3587
3588/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003589 * e1000_open - Called when a network interface is made active
3590 * @netdev: network interface device structure
3591 *
3592 * Returns 0 on success, negative value on failure
3593 *
3594 * The open entry point is called when a network interface is made
3595 * active by the system (IFF_UP). At this point all resources needed
3596 * for transmit and receive operations are allocated, the interrupt
3597 * handler is registered with the OS, the watchdog timer is started,
3598 * and the stack is notified that the interface is ready.
3599 **/
3600static int e1000_open(struct net_device *netdev)
3601{
3602 struct e1000_adapter *adapter = netdev_priv(netdev);
3603 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003604 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003605 int err;
3606
3607 /* disallow open during test */
3608 if (test_bit(__E1000_TESTING, &adapter->state))
3609 return -EBUSY;
3610
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003611 pm_runtime_get_sync(&pdev->dev);
3612
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003613 netif_carrier_off(netdev);
3614
Auke Kokbc7f75f2007-09-17 12:30:59 -07003615 /* allocate transmit descriptors */
3616 err = e1000e_setup_tx_resources(adapter);
3617 if (err)
3618 goto err_setup_tx;
3619
3620 /* allocate receive descriptors */
3621 err = e1000e_setup_rx_resources(adapter);
3622 if (err)
3623 goto err_setup_rx;
3624
Bruce Allan11b08be2010-05-10 14:59:31 +00003625 /*
3626 * If AMT is enabled, let the firmware know that the network
3627 * interface is now open and reset the part to a known state.
3628 */
3629 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003630 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003631 e1000e_reset(adapter);
3632 }
3633
Auke Kokbc7f75f2007-09-17 12:30:59 -07003634 e1000e_power_up_phy(adapter);
3635
3636 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3637 if ((adapter->hw.mng_cookie.status &
3638 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3639 e1000_update_mng_vlan(adapter);
3640
Florian Micklerc128ec22010-08-02 14:27:00 +00003641 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003642 if ((adapter->flags & FLAG_HAS_ERT) ||
3643 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003644 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3645 PM_QOS_CPU_DMA_LATENCY,
3646 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003647
Bruce Allanad680762008-03-28 09:15:03 -07003648 /*
Bruce Allanad680762008-03-28 09:15:03 -07003649 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003650 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3651 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003652 * clean_rx handler before we do so.
3653 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003654 e1000_configure(adapter);
3655
3656 err = e1000_request_irq(adapter);
3657 if (err)
3658 goto err_req_irq;
3659
Bruce Allanf8d59f72008-08-08 18:36:11 -07003660 /*
3661 * Work around PCIe errata with MSI interrupts causing some chipsets to
3662 * ignore e1000e MSI messages, which means we need to test our MSI
3663 * interrupt now
3664 */
Bruce Allan4662e822008-08-26 18:37:06 -07003665 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003666 err = e1000_test_msi(adapter);
3667 if (err) {
3668 e_err("Interrupt allocation failed\n");
3669 goto err_req_irq;
3670 }
3671 }
3672
Auke Kokbc7f75f2007-09-17 12:30:59 -07003673 /* From here on the code is the same as e1000e_up() */
3674 clear_bit(__E1000_DOWN, &adapter->state);
3675
3676 napi_enable(&adapter->napi);
3677
3678 e1000_irq_enable(adapter);
3679
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003680 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003681
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003682 adapter->idle_check = true;
3683 pm_runtime_put(&pdev->dev);
3684
Auke Kokbc7f75f2007-09-17 12:30:59 -07003685 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003686 if (adapter->msix_entries)
3687 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3688 else
3689 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003690
3691 return 0;
3692
3693err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003694 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003695 e1000_power_down_phy(adapter);
3696 e1000e_free_rx_resources(adapter);
3697err_setup_rx:
3698 e1000e_free_tx_resources(adapter);
3699err_setup_tx:
3700 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003701 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003702
3703 return err;
3704}
3705
3706/**
3707 * e1000_close - Disables a network interface
3708 * @netdev: network interface device structure
3709 *
3710 * Returns 0, this is not allowed to fail
3711 *
3712 * The close entry point is called when an interface is de-activated
3713 * by the OS. The hardware is still under the drivers control, but
3714 * needs to be disabled. A global MAC reset is issued to stop the
3715 * hardware, and all transmit and receive resources are freed.
3716 **/
3717static int e1000_close(struct net_device *netdev)
3718{
3719 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003720 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003721
3722 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003723
3724 pm_runtime_get_sync(&pdev->dev);
3725
3726 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3727 e1000e_down(adapter);
3728 e1000_free_irq(adapter);
3729 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003730 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003731
3732 e1000e_free_tx_resources(adapter);
3733 e1000e_free_rx_resources(adapter);
3734
Bruce Allanad680762008-03-28 09:15:03 -07003735 /*
3736 * kill manageability vlan ID if supported, but not if a vlan with
3737 * the same ID is registered on the host OS (let 8021q kill it)
3738 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003739 if (adapter->hw.mng_cookie.status &
3740 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003741 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3742
Bruce Allanad680762008-03-28 09:15:03 -07003743 /*
3744 * If AMT is enabled, let the firmware know that the network
3745 * interface is now closed
3746 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003747 if ((adapter->flags & FLAG_HAS_AMT) &&
3748 !test_bit(__E1000_TESTING, &adapter->state))
3749 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750
Bruce Allan828bac82010-09-29 21:39:37 +00003751 if ((adapter->flags & FLAG_HAS_ERT) ||
3752 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003753 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003754
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003755 pm_runtime_put_sync(&pdev->dev);
3756
Auke Kokbc7f75f2007-09-17 12:30:59 -07003757 return 0;
3758}
3759/**
3760 * e1000_set_mac - Change the Ethernet Address of the NIC
3761 * @netdev: network interface device structure
3762 * @p: pointer to an address structure
3763 *
3764 * Returns 0 on success, negative on failure
3765 **/
3766static int e1000_set_mac(struct net_device *netdev, void *p)
3767{
3768 struct e1000_adapter *adapter = netdev_priv(netdev);
3769 struct sockaddr *addr = p;
3770
3771 if (!is_valid_ether_addr(addr->sa_data))
3772 return -EADDRNOTAVAIL;
3773
3774 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3775 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3776
3777 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3778
3779 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3780 /* activate the work around */
3781 e1000e_set_laa_state_82571(&adapter->hw, 1);
3782
Bruce Allanad680762008-03-28 09:15:03 -07003783 /*
3784 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003785 * between the time RAR[0] gets clobbered and the time it
3786 * gets fixed (in e1000_watchdog), the actual LAA is in one
3787 * of the RARs and no incoming packets directed to this port
3788 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003789 * RAR[14]
3790 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003791 e1000e_rar_set(&adapter->hw,
3792 adapter->hw.mac.addr,
3793 adapter->hw.mac.rar_entry_count - 1);
3794 }
3795
3796 return 0;
3797}
3798
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003799/**
3800 * e1000e_update_phy_task - work thread to update phy
3801 * @work: pointer to our work struct
3802 *
3803 * this worker thread exists because we must acquire a
3804 * semaphore to read the phy, which we could msleep while
3805 * waiting for it, and we can't msleep in a timer.
3806 **/
3807static void e1000e_update_phy_task(struct work_struct *work)
3808{
3809 struct e1000_adapter *adapter = container_of(work,
3810 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003811
3812 if (test_bit(__E1000_DOWN, &adapter->state))
3813 return;
3814
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003815 e1000_get_phy_info(&adapter->hw);
3816}
3817
Bruce Allanad680762008-03-28 09:15:03 -07003818/*
3819 * Need to wait a few seconds after link up to get diagnostic information from
3820 * the phy
3821 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003822static void e1000_update_phy_info(unsigned long data)
3823{
3824 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003825
3826 if (test_bit(__E1000_DOWN, &adapter->state))
3827 return;
3828
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003829 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003830}
3831
3832/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003833 * e1000e_update_phy_stats - Update the PHY statistics counters
3834 * @adapter: board private structure
3835 **/
3836static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3837{
3838 struct e1000_hw *hw = &adapter->hw;
3839 s32 ret_val;
3840 u16 phy_data;
3841
3842 ret_val = hw->phy.ops.acquire(hw);
3843 if (ret_val)
3844 return;
3845
3846 hw->phy.addr = 1;
3847
3848#define HV_PHY_STATS_PAGE 778
3849 /*
3850 * A page set is expensive so check if already on desired page.
3851 * If not, set to the page with the PHY status registers.
3852 */
3853 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3854 &phy_data);
3855 if (ret_val)
3856 goto release;
3857 if (phy_data != (HV_PHY_STATS_PAGE << IGP_PAGE_SHIFT)) {
3858 ret_val = e1000e_write_phy_reg_mdic(hw,
3859 IGP01E1000_PHY_PAGE_SELECT,
3860 (HV_PHY_STATS_PAGE <<
3861 IGP_PAGE_SHIFT));
3862 if (ret_val)
3863 goto release;
3864 }
3865
3866 /* Read/clear the upper 16-bit registers and read/accumulate lower */
3867
3868 /* Single Collision Count */
3869 e1000e_read_phy_reg_mdic(hw, HV_SCC_UPPER & MAX_PHY_REG_ADDRESS,
3870 &phy_data);
3871 ret_val = e1000e_read_phy_reg_mdic(hw,
3872 HV_SCC_LOWER & MAX_PHY_REG_ADDRESS,
3873 &phy_data);
3874 if (!ret_val)
3875 adapter->stats.scc += phy_data;
3876
3877 /* Excessive Collision Count */
3878 e1000e_read_phy_reg_mdic(hw, HV_ECOL_UPPER & MAX_PHY_REG_ADDRESS,
3879 &phy_data);
3880 ret_val = e1000e_read_phy_reg_mdic(hw,
3881 HV_ECOL_LOWER & MAX_PHY_REG_ADDRESS,
3882 &phy_data);
3883 if (!ret_val)
3884 adapter->stats.ecol += phy_data;
3885
3886 /* Multiple Collision Count */
3887 e1000e_read_phy_reg_mdic(hw, HV_MCC_UPPER & MAX_PHY_REG_ADDRESS,
3888 &phy_data);
3889 ret_val = e1000e_read_phy_reg_mdic(hw,
3890 HV_MCC_LOWER & MAX_PHY_REG_ADDRESS,
3891 &phy_data);
3892 if (!ret_val)
3893 adapter->stats.mcc += phy_data;
3894
3895 /* Late Collision Count */
3896 e1000e_read_phy_reg_mdic(hw, HV_LATECOL_UPPER & MAX_PHY_REG_ADDRESS,
3897 &phy_data);
3898 ret_val = e1000e_read_phy_reg_mdic(hw,
3899 HV_LATECOL_LOWER &
3900 MAX_PHY_REG_ADDRESS,
3901 &phy_data);
3902 if (!ret_val)
3903 adapter->stats.latecol += phy_data;
3904
3905 /* Collision Count - also used for adaptive IFS */
3906 e1000e_read_phy_reg_mdic(hw, HV_COLC_UPPER & MAX_PHY_REG_ADDRESS,
3907 &phy_data);
3908 ret_val = e1000e_read_phy_reg_mdic(hw,
3909 HV_COLC_LOWER & MAX_PHY_REG_ADDRESS,
3910 &phy_data);
3911 if (!ret_val)
3912 hw->mac.collision_delta = phy_data;
3913
3914 /* Defer Count */
3915 e1000e_read_phy_reg_mdic(hw, HV_DC_UPPER & MAX_PHY_REG_ADDRESS,
3916 &phy_data);
3917 ret_val = e1000e_read_phy_reg_mdic(hw,
3918 HV_DC_LOWER & MAX_PHY_REG_ADDRESS,
3919 &phy_data);
3920 if (!ret_val)
3921 adapter->stats.dc += phy_data;
3922
3923 /* Transmit with no CRS */
3924 e1000e_read_phy_reg_mdic(hw, HV_TNCRS_UPPER & MAX_PHY_REG_ADDRESS,
3925 &phy_data);
3926 ret_val = e1000e_read_phy_reg_mdic(hw,
3927 HV_TNCRS_LOWER & MAX_PHY_REG_ADDRESS,
3928 &phy_data);
3929 if (!ret_val)
3930 adapter->stats.tncrs += phy_data;
3931
3932release:
3933 hw->phy.ops.release(hw);
3934}
3935
3936/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003937 * e1000e_update_stats - Update the board statistics counters
3938 * @adapter: board private structure
3939 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003940static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003942 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003943 struct e1000_hw *hw = &adapter->hw;
3944 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003945
3946 /*
3947 * Prevent stats update while adapter is being reset, or if the pci
3948 * connection is down.
3949 */
3950 if (adapter->link_speed == 0)
3951 return;
3952 if (pci_channel_offline(pdev))
3953 return;
3954
Auke Kokbc7f75f2007-09-17 12:30:59 -07003955 adapter->stats.crcerrs += er32(CRCERRS);
3956 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003957 adapter->stats.gorc += er32(GORCL);
3958 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003959 adapter->stats.bprc += er32(BPRC);
3960 adapter->stats.mprc += er32(MPRC);
3961 adapter->stats.roc += er32(ROC);
3962
Auke Kokbc7f75f2007-09-17 12:30:59 -07003963 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003964
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003965 /* Half-duplex statistics */
3966 if (adapter->link_duplex == HALF_DUPLEX) {
3967 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
3968 e1000e_update_phy_stats(adapter);
3969 } else {
3970 adapter->stats.scc += er32(SCC);
3971 adapter->stats.ecol += er32(ECOL);
3972 adapter->stats.mcc += er32(MCC);
3973 adapter->stats.latecol += er32(LATECOL);
3974 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003975
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003976 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003977
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003978 if ((hw->mac.type != e1000_82574) &&
3979 (hw->mac.type != e1000_82583))
3980 adapter->stats.tncrs += er32(TNCRS);
3981 }
3982 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003983 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003984
Auke Kokbc7f75f2007-09-17 12:30:59 -07003985 adapter->stats.xonrxc += er32(XONRXC);
3986 adapter->stats.xontxc += er32(XONTXC);
3987 adapter->stats.xoffrxc += er32(XOFFRXC);
3988 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003989 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003990 adapter->stats.gotc += er32(GOTCL);
3991 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003992 adapter->stats.rnbc += er32(RNBC);
3993 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003994
3995 adapter->stats.mptc += er32(MPTC);
3996 adapter->stats.bptc += er32(BPTC);
3997
3998 /* used for adaptive IFS */
3999
4000 hw->mac.tx_packet_delta = er32(TPT);
4001 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004002
4003 adapter->stats.algnerrc += er32(ALGNERRC);
4004 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004005 adapter->stats.cexterr += er32(CEXTERR);
4006 adapter->stats.tsctc += er32(TSCTC);
4007 adapter->stats.tsctfc += er32(TSCTFC);
4008
Auke Kokbc7f75f2007-09-17 12:30:59 -07004009 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004010 netdev->stats.multicast = adapter->stats.mprc;
4011 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004012
4013 /* Rx Errors */
4014
Bruce Allanad680762008-03-28 09:15:03 -07004015 /*
4016 * RLEC on some newer hardware can be incorrect so build
4017 * our own version based on RUC and ROC
4018 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004019 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004020 adapter->stats.crcerrs + adapter->stats.algnerrc +
4021 adapter->stats.ruc + adapter->stats.roc +
4022 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004023 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004024 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004025 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4026 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4027 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004028
4029 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004030 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004031 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004032 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4033 netdev->stats.tx_window_errors = adapter->stats.latecol;
4034 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004035
4036 /* Tx Dropped needs to be maintained elsewhere */
4037
Auke Kokbc7f75f2007-09-17 12:30:59 -07004038 /* Management Stats */
4039 adapter->stats.mgptc += er32(MGTPTC);
4040 adapter->stats.mgprc += er32(MGTPRC);
4041 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004042}
4043
Bruce Allan7c257692008-04-23 11:09:00 -07004044/**
4045 * e1000_phy_read_status - Update the PHY register status snapshot
4046 * @adapter: board private structure
4047 **/
4048static void e1000_phy_read_status(struct e1000_adapter *adapter)
4049{
4050 struct e1000_hw *hw = &adapter->hw;
4051 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004052
4053 if ((er32(STATUS) & E1000_STATUS_LU) &&
4054 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004055 int ret_val;
4056
Bruce Allan7c257692008-04-23 11:09:00 -07004057 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4058 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4059 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4060 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4061 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4062 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4063 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4064 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4065 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004066 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004067 } else {
4068 /*
4069 * Do not read PHY registers if link is not up
4070 * Set values to typical power-on defaults
4071 */
4072 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4073 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4074 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4075 BMSR_ERCAP);
4076 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4077 ADVERTISE_ALL | ADVERTISE_CSMA);
4078 phy->lpa = 0;
4079 phy->expansion = EXPANSION_ENABLENPAGE;
4080 phy->ctrl1000 = ADVERTISE_1000FULL;
4081 phy->stat1000 = 0;
4082 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4083 }
Bruce Allan7c257692008-04-23 11:09:00 -07004084}
4085
Auke Kokbc7f75f2007-09-17 12:30:59 -07004086static void e1000_print_link_info(struct e1000_adapter *adapter)
4087{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088 struct e1000_hw *hw = &adapter->hw;
4089 u32 ctrl = er32(CTRL);
4090
Bruce Allan8f12fe82008-11-21 16:54:43 -08004091 /* Link status message must follow this format for user tools */
4092 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4093 "Flow Control: %s\n",
4094 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004095 adapter->link_speed,
4096 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004097 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004098 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004099 "Rx/Tx" :
4100 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4101 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004102}
4103
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004104static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004105{
4106 struct e1000_hw *hw = &adapter->hw;
4107 bool link_active = 0;
4108 s32 ret_val = 0;
4109
4110 /*
4111 * get_link_status is set on LSC (link status) interrupt or
4112 * Rx sequence error interrupt. get_link_status will stay
4113 * false until the check_for_link establishes link
4114 * for copper adapters ONLY
4115 */
4116 switch (hw->phy.media_type) {
4117 case e1000_media_type_copper:
4118 if (hw->mac.get_link_status) {
4119 ret_val = hw->mac.ops.check_for_link(hw);
4120 link_active = !hw->mac.get_link_status;
4121 } else {
4122 link_active = 1;
4123 }
4124 break;
4125 case e1000_media_type_fiber:
4126 ret_val = hw->mac.ops.check_for_link(hw);
4127 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4128 break;
4129 case e1000_media_type_internal_serdes:
4130 ret_val = hw->mac.ops.check_for_link(hw);
4131 link_active = adapter->hw.mac.serdes_has_link;
4132 break;
4133 default:
4134 case e1000_media_type_unknown:
4135 break;
4136 }
4137
4138 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4139 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4140 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004141 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004142 }
4143
4144 return link_active;
4145}
4146
4147static void e1000e_enable_receives(struct e1000_adapter *adapter)
4148{
4149 /* make sure the receive unit is started */
4150 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4151 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4152 struct e1000_hw *hw = &adapter->hw;
4153 u32 rctl = er32(RCTL);
4154 ew32(RCTL, rctl | E1000_RCTL_EN);
4155 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4156 }
4157}
4158
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004159static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4160{
4161 struct e1000_hw *hw = &adapter->hw;
4162
4163 /*
4164 * With 82574 controllers, PHY needs to be checked periodically
4165 * for hung state and reset, if two calls return true
4166 */
4167 if (e1000_check_phy_82574(hw))
4168 adapter->phy_hang_count++;
4169 else
4170 adapter->phy_hang_count = 0;
4171
4172 if (adapter->phy_hang_count > 1) {
4173 adapter->phy_hang_count = 0;
4174 schedule_work(&adapter->reset_task);
4175 }
4176}
4177
Auke Kokbc7f75f2007-09-17 12:30:59 -07004178/**
4179 * e1000_watchdog - Timer Call-back
4180 * @data: pointer to adapter cast into an unsigned long
4181 **/
4182static void e1000_watchdog(unsigned long data)
4183{
4184 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4185
4186 /* Do the rest outside of interrupt context */
4187 schedule_work(&adapter->watchdog_task);
4188
4189 /* TODO: make this use queue_delayed_work() */
4190}
4191
4192static void e1000_watchdog_task(struct work_struct *work)
4193{
4194 struct e1000_adapter *adapter = container_of(work,
4195 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004196 struct net_device *netdev = adapter->netdev;
4197 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004198 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004199 struct e1000_ring *tx_ring = adapter->tx_ring;
4200 struct e1000_hw *hw = &adapter->hw;
4201 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004202
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004203 if (test_bit(__E1000_DOWN, &adapter->state))
4204 return;
4205
David S. Millerb405e8d2010-02-04 22:31:41 -08004206 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004207 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004208 /* Cancel scheduled suspend requests. */
4209 pm_runtime_resume(netdev->dev.parent);
4210
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004211 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004212 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004213 }
4214
4215 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4216 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4217 e1000_update_mng_vlan(adapter);
4218
Auke Kokbc7f75f2007-09-17 12:30:59 -07004219 if (link) {
4220 if (!netif_carrier_ok(netdev)) {
4221 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004222
4223 /* Cancel scheduled suspend requests. */
4224 pm_runtime_resume(netdev->dev.parent);
4225
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004226 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004227 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004228 mac->ops.get_link_up_info(&adapter->hw,
4229 &adapter->link_speed,
4230 &adapter->link_duplex);
4231 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004232 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004233 * On supported PHYs, check for duplex mismatch only
4234 * if link has autonegotiated at 10/100 half
4235 */
4236 if ((hw->phy.type == e1000_phy_igp_3 ||
4237 hw->phy.type == e1000_phy_bm) &&
4238 (hw->mac.autoneg == true) &&
4239 (adapter->link_speed == SPEED_10 ||
4240 adapter->link_speed == SPEED_100) &&
4241 (adapter->link_duplex == HALF_DUPLEX)) {
4242 u16 autoneg_exp;
4243
4244 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4245
4246 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4247 e_info("Autonegotiated half duplex but"
4248 " link partner cannot autoneg. "
4249 " Try forcing full duplex if "
4250 "link gets many collisions.\n");
4251 }
4252
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004253 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004254 adapter->tx_timeout_factor = 1;
4255 switch (adapter->link_speed) {
4256 case SPEED_10:
4257 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004258 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004259 break;
4260 case SPEED_100:
4261 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004262 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004263 break;
4264 }
4265
Bruce Allanad680762008-03-28 09:15:03 -07004266 /*
4267 * workaround: re-program speed mode bit after
4268 * link-up event
4269 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004270 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4271 !txb2b) {
4272 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004273 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004274 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004275 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004276 }
4277
Bruce Allanad680762008-03-28 09:15:03 -07004278 /*
4279 * disable TSO for pcie and 10/100 speeds, to avoid
4280 * some hardware issues
4281 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004282 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4283 switch (adapter->link_speed) {
4284 case SPEED_10:
4285 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004286 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004287 netdev->features &= ~NETIF_F_TSO;
4288 netdev->features &= ~NETIF_F_TSO6;
4289 break;
4290 case SPEED_1000:
4291 netdev->features |= NETIF_F_TSO;
4292 netdev->features |= NETIF_F_TSO6;
4293 break;
4294 default:
4295 /* oops */
4296 break;
4297 }
4298 }
4299
Bruce Allanad680762008-03-28 09:15:03 -07004300 /*
4301 * enable transmits in the hardware, need to do this
4302 * after setting TARC(0)
4303 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004304 tctl = er32(TCTL);
4305 tctl |= E1000_TCTL_EN;
4306 ew32(TCTL, tctl);
4307
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004308 /*
4309 * Perform any post-link-up configuration before
4310 * reporting link up.
4311 */
4312 if (phy->ops.cfg_on_link_up)
4313 phy->ops.cfg_on_link_up(hw);
4314
Auke Kokbc7f75f2007-09-17 12:30:59 -07004315 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004316
4317 if (!test_bit(__E1000_DOWN, &adapter->state))
4318 mod_timer(&adapter->phy_info_timer,
4319 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004320 }
4321 } else {
4322 if (netif_carrier_ok(netdev)) {
4323 adapter->link_speed = 0;
4324 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004325 /* Link status message must follow this format */
4326 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4327 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004328 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004329 if (!test_bit(__E1000_DOWN, &adapter->state))
4330 mod_timer(&adapter->phy_info_timer,
4331 round_jiffies(jiffies + 2 * HZ));
4332
4333 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4334 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004335 else
4336 pm_schedule_suspend(netdev->dev.parent,
4337 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004338 }
4339 }
4340
4341link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004342 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004343 e1000e_update_stats(adapter);
4344
4345 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4346 adapter->tpt_old = adapter->stats.tpt;
4347 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4348 adapter->colc_old = adapter->stats.colc;
4349
Bruce Allan7c257692008-04-23 11:09:00 -07004350 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4351 adapter->gorc_old = adapter->stats.gorc;
4352 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4353 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004354 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004355
4356 e1000e_update_adaptive(&adapter->hw);
4357
Bruce Allan90da0662011-01-06 07:02:53 +00004358 if (!netif_carrier_ok(netdev) &&
4359 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4360 /*
4361 * We've lost link, so the controller stops DMA,
4362 * but we've got queued Tx work that's never going
4363 * to get done, so reset controller to flush Tx.
4364 * (Do the reset outside of interrupt context).
4365 */
Bruce Allan90da0662011-01-06 07:02:53 +00004366 schedule_work(&adapter->reset_task);
4367 /* return immediately since reset is imminent */
4368 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004369 }
4370
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004371 /* Simple mode for Interrupt Throttle Rate (ITR) */
4372 if (adapter->itr_setting == 4) {
4373 /*
4374 * Symmetric Tx/Rx gets a reduced ITR=2000;
4375 * Total asymmetrical Tx or Rx gets ITR=8000;
4376 * everyone else is between 2000-8000.
4377 */
4378 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4379 u32 dif = (adapter->gotc > adapter->gorc ?
4380 adapter->gotc - adapter->gorc :
4381 adapter->gorc - adapter->gotc) / 10000;
4382 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4383
4384 ew32(ITR, 1000000000 / (itr * 256));
4385 }
4386
Bruce Allanad680762008-03-28 09:15:03 -07004387 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004388 if (adapter->msix_entries)
4389 ew32(ICS, adapter->rx_ring->ims_val);
4390 else
4391 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004392
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004393 /* flush pending descriptors to memory before detecting Tx hang */
4394 e1000e_flush_descriptors(adapter);
4395
Auke Kokbc7f75f2007-09-17 12:30:59 -07004396 /* Force detection of hung controller every watchdog period */
4397 adapter->detect_tx_hung = 1;
4398
Bruce Allanad680762008-03-28 09:15:03 -07004399 /*
4400 * With 82571 controllers, LAA may be overwritten due to controller
4401 * reset from the other port. Set the appropriate LAA in RAR[0]
4402 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004403 if (e1000e_get_laa_state_82571(hw))
4404 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4405
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004406 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4407 e1000e_check_82574_phy_workaround(adapter);
4408
Auke Kokbc7f75f2007-09-17 12:30:59 -07004409 /* Reset the timer */
4410 if (!test_bit(__E1000_DOWN, &adapter->state))
4411 mod_timer(&adapter->watchdog_timer,
4412 round_jiffies(jiffies + 2 * HZ));
4413}
4414
4415#define E1000_TX_FLAGS_CSUM 0x00000001
4416#define E1000_TX_FLAGS_VLAN 0x00000002
4417#define E1000_TX_FLAGS_TSO 0x00000004
4418#define E1000_TX_FLAGS_IPV4 0x00000008
4419#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4420#define E1000_TX_FLAGS_VLAN_SHIFT 16
4421
4422static int e1000_tso(struct e1000_adapter *adapter,
4423 struct sk_buff *skb)
4424{
4425 struct e1000_ring *tx_ring = adapter->tx_ring;
4426 struct e1000_context_desc *context_desc;
4427 struct e1000_buffer *buffer_info;
4428 unsigned int i;
4429 u32 cmd_length = 0;
4430 u16 ipcse = 0, tucse, mss;
4431 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004432
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004433 if (!skb_is_gso(skb))
4434 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004435
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004436 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004437 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4438
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004439 if (err)
4440 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004441 }
4442
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004443 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4444 mss = skb_shinfo(skb)->gso_size;
4445 if (skb->protocol == htons(ETH_P_IP)) {
4446 struct iphdr *iph = ip_hdr(skb);
4447 iph->tot_len = 0;
4448 iph->check = 0;
4449 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4450 0, IPPROTO_TCP, 0);
4451 cmd_length = E1000_TXD_CMD_IP;
4452 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004453 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004454 ipv6_hdr(skb)->payload_len = 0;
4455 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4456 &ipv6_hdr(skb)->daddr,
4457 0, IPPROTO_TCP, 0);
4458 ipcse = 0;
4459 }
4460 ipcss = skb_network_offset(skb);
4461 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4462 tucss = skb_transport_offset(skb);
4463 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4464 tucse = 0;
4465
4466 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4467 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4468
4469 i = tx_ring->next_to_use;
4470 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4471 buffer_info = &tx_ring->buffer_info[i];
4472
4473 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4474 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4475 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4476 context_desc->upper_setup.tcp_fields.tucss = tucss;
4477 context_desc->upper_setup.tcp_fields.tucso = tucso;
4478 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4479 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4480 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4481 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4482
4483 buffer_info->time_stamp = jiffies;
4484 buffer_info->next_to_watch = i;
4485
4486 i++;
4487 if (i == tx_ring->count)
4488 i = 0;
4489 tx_ring->next_to_use = i;
4490
4491 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004492}
4493
4494static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4495{
4496 struct e1000_ring *tx_ring = adapter->tx_ring;
4497 struct e1000_context_desc *context_desc;
4498 struct e1000_buffer *buffer_info;
4499 unsigned int i;
4500 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004501 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004502 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004503
Dave Grahamaf807c82008-10-09 14:28:58 -07004504 if (skb->ip_summed != CHECKSUM_PARTIAL)
4505 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004506
Arthur Jones5f66f202009-03-19 01:13:08 +00004507 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4508 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4509 else
4510 protocol = skb->protocol;
4511
Arthur Jones3f518392009-03-20 15:56:35 -07004512 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004513 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004514 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4515 cmd_len |= E1000_TXD_CMD_TCP;
4516 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004517 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004518 /* XXX not handling all IPV6 headers */
4519 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4520 cmd_len |= E1000_TXD_CMD_TCP;
4521 break;
4522 default:
4523 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004524 e_warn("checksum_partial proto=%x!\n",
4525 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004526 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004527 }
4528
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004529 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004530
4531 i = tx_ring->next_to_use;
4532 buffer_info = &tx_ring->buffer_info[i];
4533 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4534
4535 context_desc->lower_setup.ip_config = 0;
4536 context_desc->upper_setup.tcp_fields.tucss = css;
4537 context_desc->upper_setup.tcp_fields.tucso =
4538 css + skb->csum_offset;
4539 context_desc->upper_setup.tcp_fields.tucse = 0;
4540 context_desc->tcp_seg_setup.data = 0;
4541 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4542
4543 buffer_info->time_stamp = jiffies;
4544 buffer_info->next_to_watch = i;
4545
4546 i++;
4547 if (i == tx_ring->count)
4548 i = 0;
4549 tx_ring->next_to_use = i;
4550
4551 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004552}
4553
4554#define E1000_MAX_PER_TXD 8192
4555#define E1000_MAX_TXD_PWR 12
4556
4557static int e1000_tx_map(struct e1000_adapter *adapter,
4558 struct sk_buff *skb, unsigned int first,
4559 unsigned int max_per_txd, unsigned int nr_frags,
4560 unsigned int mss)
4561{
4562 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004563 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004564 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004565 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004566 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004567 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004568
4569 i = tx_ring->next_to_use;
4570
4571 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004572 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004573 size = min(len, max_per_txd);
4574
Auke Kokbc7f75f2007-09-17 12:30:59 -07004575 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004576 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004577 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004578 buffer_info->dma = dma_map_single(&pdev->dev,
4579 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004580 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004581 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004582 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004583 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004584
4585 len -= size;
4586 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004587 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004588
4589 if (len) {
4590 i++;
4591 if (i == tx_ring->count)
4592 i = 0;
4593 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004594 }
4595
4596 for (f = 0; f < nr_frags; f++) {
4597 struct skb_frag_struct *frag;
4598
4599 frag = &skb_shinfo(skb)->frags[f];
4600 len = frag->size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004601 offset = frag->page_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004602
4603 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004604 i++;
4605 if (i == tx_ring->count)
4606 i = 0;
4607
Auke Kokbc7f75f2007-09-17 12:30:59 -07004608 buffer_info = &tx_ring->buffer_info[i];
4609 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004610
4611 buffer_info->length = size;
4612 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004613 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004614 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
Alexander Duyck03b13202009-12-02 16:45:31 +00004615 offset, size,
Nick Nunley0be3f552010-04-27 13:09:05 +00004616 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004617 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004618 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004619 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004620
4621 len -= size;
4622 offset += size;
4623 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004624 }
4625 }
4626
Bruce Allanaf667a22010-12-31 06:10:01 +00004627 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004628 /* multiply data chunks by size of headers */
4629 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4630
Auke Kokbc7f75f2007-09-17 12:30:59 -07004631 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004632 tx_ring->buffer_info[i].segs = segs;
4633 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004634 tx_ring->buffer_info[first].next_to_watch = i;
4635
4636 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004637
4638dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004639 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004640 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004641 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004642 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004643
4644 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004645 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004646 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004647 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004648 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004649 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004650 }
4651
4652 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004653}
4654
4655static void e1000_tx_queue(struct e1000_adapter *adapter,
4656 int tx_flags, int count)
4657{
4658 struct e1000_ring *tx_ring = adapter->tx_ring;
4659 struct e1000_tx_desc *tx_desc = NULL;
4660 struct e1000_buffer *buffer_info;
4661 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4662 unsigned int i;
4663
4664 if (tx_flags & E1000_TX_FLAGS_TSO) {
4665 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4666 E1000_TXD_CMD_TSE;
4667 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4668
4669 if (tx_flags & E1000_TX_FLAGS_IPV4)
4670 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4671 }
4672
4673 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4674 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4675 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4676 }
4677
4678 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4679 txd_lower |= E1000_TXD_CMD_VLE;
4680 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4681 }
4682
4683 i = tx_ring->next_to_use;
4684
Bruce Allan36b973d2010-11-24 07:42:43 +00004685 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004686 buffer_info = &tx_ring->buffer_info[i];
4687 tx_desc = E1000_TX_DESC(*tx_ring, i);
4688 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4689 tx_desc->lower.data =
4690 cpu_to_le32(txd_lower | buffer_info->length);
4691 tx_desc->upper.data = cpu_to_le32(txd_upper);
4692
4693 i++;
4694 if (i == tx_ring->count)
4695 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004696 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004697
4698 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4699
Bruce Allanad680762008-03-28 09:15:03 -07004700 /*
4701 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004702 * know there are new descriptors to fetch. (Only
4703 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004704 * such as IA-64).
4705 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004706 wmb();
4707
4708 tx_ring->next_to_use = i;
4709 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07004710 /*
4711 * we need this if more than one processor can write to our tail
4712 * at a time, it synchronizes IO on IA64/Altix systems
4713 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004714 mmiowb();
4715}
4716
4717#define MINIMUM_DHCP_PACKET_SIZE 282
4718static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4719 struct sk_buff *skb)
4720{
4721 struct e1000_hw *hw = &adapter->hw;
4722 u16 length, offset;
4723
4724 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004725 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4726 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004727 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4728 return 0;
4729 }
4730
4731 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4732 return 0;
4733
4734 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4735 return 0;
4736
4737 {
4738 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4739 struct udphdr *udp;
4740
4741 if (ip->protocol != IPPROTO_UDP)
4742 return 0;
4743
4744 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4745 if (ntohs(udp->dest) != 67)
4746 return 0;
4747
4748 offset = (u8 *)udp + 8 - skb->data;
4749 length = skb->len - offset;
4750 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4751 }
4752
4753 return 0;
4754}
4755
4756static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4757{
4758 struct e1000_adapter *adapter = netdev_priv(netdev);
4759
4760 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004761 /*
4762 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004763 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004764 * but since that doesn't exist yet, just open code it.
4765 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004766 smp_mb();
4767
Bruce Allanad680762008-03-28 09:15:03 -07004768 /*
4769 * We need to check again in a case another CPU has just
4770 * made room available.
4771 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004772 if (e1000_desc_unused(adapter->tx_ring) < size)
4773 return -EBUSY;
4774
4775 /* A reprieve! */
4776 netif_start_queue(netdev);
4777 ++adapter->restart_queue;
4778 return 0;
4779}
4780
4781static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4782{
4783 struct e1000_adapter *adapter = netdev_priv(netdev);
4784
4785 if (e1000_desc_unused(adapter->tx_ring) >= size)
4786 return 0;
4787 return __e1000_maybe_stop_tx(netdev, size);
4788}
4789
4790#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004791static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4792 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004793{
4794 struct e1000_adapter *adapter = netdev_priv(netdev);
4795 struct e1000_ring *tx_ring = adapter->tx_ring;
4796 unsigned int first;
4797 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4798 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4799 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004800 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004801 unsigned int nr_frags;
4802 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004803 int count = 0;
4804 int tso;
4805 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004806
4807 if (test_bit(__E1000_DOWN, &adapter->state)) {
4808 dev_kfree_skb_any(skb);
4809 return NETDEV_TX_OK;
4810 }
4811
4812 if (skb->len <= 0) {
4813 dev_kfree_skb_any(skb);
4814 return NETDEV_TX_OK;
4815 }
4816
4817 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004818 /*
4819 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004820 * make sure there is enough room in the FIFO before
4821 * initiating the DMA for each buffer. The calc is:
4822 * 4 = ceil(buffer len/mss). To make sure we don't
4823 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004824 * drops.
4825 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004826 if (mss) {
4827 u8 hdr_len;
4828 max_per_txd = min(mss << 2, max_per_txd);
4829 max_txd_pwr = fls(max_per_txd) - 1;
4830
Bruce Allanad680762008-03-28 09:15:03 -07004831 /*
4832 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4833 * points to just header, pull a few bytes of payload from
4834 * frags into skb->data
4835 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004836 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004837 /*
4838 * we do this workaround for ES2LAN, but it is un-necessary,
4839 * avoiding it could save a lot of cycles
4840 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004841 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004842 unsigned int pull_size;
4843
4844 pull_size = min((unsigned int)4, skb->data_len);
4845 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004846 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004847 dev_kfree_skb_any(skb);
4848 return NETDEV_TX_OK;
4849 }
Eric Dumazete743d312010-04-14 15:59:40 -07004850 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004851 }
4852 }
4853
4854 /* reserve a descriptor for the offload context */
4855 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4856 count++;
4857 count++;
4858
4859 count += TXD_USE_COUNT(len, max_txd_pwr);
4860
4861 nr_frags = skb_shinfo(skb)->nr_frags;
4862 for (f = 0; f < nr_frags; f++)
4863 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4864 max_txd_pwr);
4865
4866 if (adapter->hw.mac.tx_pkt_filtering)
4867 e1000_transfer_dhcp_info(adapter, skb);
4868
Bruce Allanad680762008-03-28 09:15:03 -07004869 /*
4870 * need: count + 2 desc gap to keep tail from touching
4871 * head, otherwise try next time
4872 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004873 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004874 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004875
Jesse Grosseab6d182010-10-20 13:56:03 +00004876 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004877 tx_flags |= E1000_TX_FLAGS_VLAN;
4878 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4879 }
4880
4881 first = tx_ring->next_to_use;
4882
4883 tso = e1000_tso(adapter, skb);
4884 if (tso < 0) {
4885 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004886 return NETDEV_TX_OK;
4887 }
4888
4889 if (tso)
4890 tx_flags |= E1000_TX_FLAGS_TSO;
4891 else if (e1000_tx_csum(adapter, skb))
4892 tx_flags |= E1000_TX_FLAGS_CSUM;
4893
Bruce Allanad680762008-03-28 09:15:03 -07004894 /*
4895 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004896 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004897 * no longer assume, we must.
4898 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004899 if (skb->protocol == htons(ETH_P_IP))
4900 tx_flags |= E1000_TX_FLAGS_IPV4;
4901
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004902 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004903 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004904 if (count) {
4905 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004906 /* Make sure there is space in the ring for the next send. */
4907 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4908
4909 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004910 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004911 tx_ring->buffer_info[first].time_stamp = 0;
4912 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004913 }
4914
Auke Kokbc7f75f2007-09-17 12:30:59 -07004915 return NETDEV_TX_OK;
4916}
4917
4918/**
4919 * e1000_tx_timeout - Respond to a Tx Hang
4920 * @netdev: network interface device structure
4921 **/
4922static void e1000_tx_timeout(struct net_device *netdev)
4923{
4924 struct e1000_adapter *adapter = netdev_priv(netdev);
4925
4926 /* Do the reset outside of interrupt context */
4927 adapter->tx_timeout_count++;
4928 schedule_work(&adapter->reset_task);
4929}
4930
4931static void e1000_reset_task(struct work_struct *work)
4932{
4933 struct e1000_adapter *adapter;
4934 adapter = container_of(work, struct e1000_adapter, reset_task);
4935
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004936 /* don't run the task if already down */
4937 if (test_bit(__E1000_DOWN, &adapter->state))
4938 return;
4939
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00004940 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4941 (adapter->flags & FLAG_RX_RESTART_NOW))) {
4942 e1000e_dump(adapter);
4943 e_err("Reset adapter\n");
4944 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004945 e1000e_reinit_locked(adapter);
4946}
4947
4948/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004949 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07004950 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004951 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07004952 *
4953 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004954 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004955struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
4956 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004957{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004958 struct e1000_adapter *adapter = netdev_priv(netdev);
4959
4960 memset(stats, 0, sizeof(struct rtnl_link_stats64));
4961 spin_lock(&adapter->stats64_lock);
4962 e1000e_update_stats(adapter);
4963 /* Fill out the OS statistics structure */
4964 stats->rx_bytes = adapter->stats.gorc;
4965 stats->rx_packets = adapter->stats.gprc;
4966 stats->tx_bytes = adapter->stats.gotc;
4967 stats->tx_packets = adapter->stats.gptc;
4968 stats->multicast = adapter->stats.mprc;
4969 stats->collisions = adapter->stats.colc;
4970
4971 /* Rx Errors */
4972
4973 /*
4974 * RLEC on some newer hardware can be incorrect so build
4975 * our own version based on RUC and ROC
4976 */
4977 stats->rx_errors = adapter->stats.rxerrc +
4978 adapter->stats.crcerrs + adapter->stats.algnerrc +
4979 adapter->stats.ruc + adapter->stats.roc +
4980 adapter->stats.cexterr;
4981 stats->rx_length_errors = adapter->stats.ruc +
4982 adapter->stats.roc;
4983 stats->rx_crc_errors = adapter->stats.crcerrs;
4984 stats->rx_frame_errors = adapter->stats.algnerrc;
4985 stats->rx_missed_errors = adapter->stats.mpc;
4986
4987 /* Tx Errors */
4988 stats->tx_errors = adapter->stats.ecol +
4989 adapter->stats.latecol;
4990 stats->tx_aborted_errors = adapter->stats.ecol;
4991 stats->tx_window_errors = adapter->stats.latecol;
4992 stats->tx_carrier_errors = adapter->stats.tncrs;
4993
4994 /* Tx Dropped needs to be maintained elsewhere */
4995
4996 spin_unlock(&adapter->stats64_lock);
4997 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998}
4999
5000/**
5001 * e1000_change_mtu - Change the Maximum Transfer Unit
5002 * @netdev: network interface device structure
5003 * @new_mtu: new value for maximum frame size
5004 *
5005 * Returns 0 on success, negative on failure
5006 **/
5007static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5008{
5009 struct e1000_adapter *adapter = netdev_priv(netdev);
5010 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5011
Bruce Allan2adc55c2009-06-02 11:28:58 +00005012 /* Jumbo frame support */
5013 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5014 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5015 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005016 return -EINVAL;
5017 }
5018
Bruce Allan2adc55c2009-06-02 11:28:58 +00005019 /* Supported frame sizes */
5020 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5021 (max_frame > adapter->max_hw_frame_size)) {
5022 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005023 return -EINVAL;
5024 }
5025
Bruce Allana1ce6472010-09-22 17:16:40 +00005026 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5027 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5028 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5029 (new_mtu > ETH_DATA_LEN)) {
5030 e_err("Jumbo Frames not supported on 82579 when CRC "
5031 "stripping is disabled.\n");
5032 return -EINVAL;
5033 }
5034
Bruce Allan6f461f62010-04-27 03:33:04 +00005035 /* 82573 Errata 17 */
5036 if (((adapter->hw.mac.type == e1000_82573) ||
5037 (adapter->hw.mac.type == e1000_82574)) &&
5038 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5039 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5040 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5041 }
5042
Auke Kokbc7f75f2007-09-17 12:30:59 -07005043 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005044 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005045 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005046 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005047 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5048 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005049 if (netif_running(netdev))
5050 e1000e_down(adapter);
5051
Bruce Allanad680762008-03-28 09:15:03 -07005052 /*
5053 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005054 * means we reserve 2 more, this pushes us to allocate from the next
5055 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005056 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005057 * However with the new *_jumbo_rx* routines, jumbo receives will use
5058 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005059 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005060
Jesse Brandeburg99261462010-01-22 22:56:16 +00005061 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005062 adapter->rx_buffer_len = 2048;
5063 else
5064 adapter->rx_buffer_len = 4096;
5065
5066 /* adjust allocation if LPE protects us, and we aren't using SBP */
5067 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5068 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5069 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005070 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005071
Auke Kokbc7f75f2007-09-17 12:30:59 -07005072 if (netif_running(netdev))
5073 e1000e_up(adapter);
5074 else
5075 e1000e_reset(adapter);
5076
5077 clear_bit(__E1000_RESETTING, &adapter->state);
5078
5079 return 0;
5080}
5081
5082static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5083 int cmd)
5084{
5085 struct e1000_adapter *adapter = netdev_priv(netdev);
5086 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005087
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005088 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005089 return -EOPNOTSUPP;
5090
5091 switch (cmd) {
5092 case SIOCGMIIPHY:
5093 data->phy_id = adapter->hw.phy.addr;
5094 break;
5095 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005096 e1000_phy_read_status(adapter);
5097
Bruce Allan7c257692008-04-23 11:09:00 -07005098 switch (data->reg_num & 0x1F) {
5099 case MII_BMCR:
5100 data->val_out = adapter->phy_regs.bmcr;
5101 break;
5102 case MII_BMSR:
5103 data->val_out = adapter->phy_regs.bmsr;
5104 break;
5105 case MII_PHYSID1:
5106 data->val_out = (adapter->hw.phy.id >> 16);
5107 break;
5108 case MII_PHYSID2:
5109 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5110 break;
5111 case MII_ADVERTISE:
5112 data->val_out = adapter->phy_regs.advertise;
5113 break;
5114 case MII_LPA:
5115 data->val_out = adapter->phy_regs.lpa;
5116 break;
5117 case MII_EXPANSION:
5118 data->val_out = adapter->phy_regs.expansion;
5119 break;
5120 case MII_CTRL1000:
5121 data->val_out = adapter->phy_regs.ctrl1000;
5122 break;
5123 case MII_STAT1000:
5124 data->val_out = adapter->phy_regs.stat1000;
5125 break;
5126 case MII_ESTATUS:
5127 data->val_out = adapter->phy_regs.estatus;
5128 break;
5129 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005130 return -EIO;
5131 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005132 break;
5133 case SIOCSMIIREG:
5134 default:
5135 return -EOPNOTSUPP;
5136 }
5137 return 0;
5138}
5139
5140static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5141{
5142 switch (cmd) {
5143 case SIOCGMIIPHY:
5144 case SIOCGMIIREG:
5145 case SIOCSMIIREG:
5146 return e1000_mii_ioctl(netdev, ifr, cmd);
5147 default:
5148 return -EOPNOTSUPP;
5149 }
5150}
5151
Bruce Allana4f58f52009-06-02 11:29:18 +00005152static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5153{
5154 struct e1000_hw *hw = &adapter->hw;
5155 u32 i, mac_reg;
5156 u16 phy_reg;
5157 int retval = 0;
5158
5159 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005160 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005161
5162 /* copy MAC MTA to PHY MTA */
5163 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5164 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5165 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
5166 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
5167 }
5168
5169 /* configure PHY Rx Control register */
5170 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
5171 mac_reg = er32(RCTL);
5172 if (mac_reg & E1000_RCTL_UPE)
5173 phy_reg |= BM_RCTL_UPE;
5174 if (mac_reg & E1000_RCTL_MPE)
5175 phy_reg |= BM_RCTL_MPE;
5176 phy_reg &= ~(BM_RCTL_MO_MASK);
5177 if (mac_reg & E1000_RCTL_MO_3)
5178 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5179 << BM_RCTL_MO_SHIFT);
5180 if (mac_reg & E1000_RCTL_BAM)
5181 phy_reg |= BM_RCTL_BAM;
5182 if (mac_reg & E1000_RCTL_PMCF)
5183 phy_reg |= BM_RCTL_PMCF;
5184 mac_reg = er32(CTRL);
5185 if (mac_reg & E1000_CTRL_RFCE)
5186 phy_reg |= BM_RCTL_RFCE;
5187 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
5188
5189 /* enable PHY wakeup in MAC register */
5190 ew32(WUFC, wufc);
5191 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5192
5193 /* configure and enable PHY wakeup in PHY registers */
5194 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
5195 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5196
5197 /* activate PHY wakeup */
Bruce Allan94d81862009-11-20 23:25:26 +00005198 retval = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005199 if (retval) {
5200 e_err("Could not acquire PHY\n");
5201 return retval;
5202 }
5203 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
5204 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
5205 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
5206 if (retval) {
5207 e_err("Could not read PHY page 769\n");
5208 goto out;
5209 }
5210 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5211 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
5212 if (retval)
5213 e_err("Could not set PHY Host Wakeup bit\n");
5214out:
Bruce Allan94d81862009-11-20 23:25:26 +00005215 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005216
5217 return retval;
5218}
5219
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005220static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5221 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005222{
5223 struct net_device *netdev = pci_get_drvdata(pdev);
5224 struct e1000_adapter *adapter = netdev_priv(netdev);
5225 struct e1000_hw *hw = &adapter->hw;
5226 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005227 /* Runtime suspend should only enable wakeup for link changes */
5228 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005229 int retval = 0;
5230
5231 netif_device_detach(netdev);
5232
5233 if (netif_running(netdev)) {
5234 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5235 e1000e_down(adapter);
5236 e1000_free_irq(adapter);
5237 }
Bruce Allan4662e822008-08-26 18:37:06 -07005238 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005239
5240 retval = pci_save_state(pdev);
5241 if (retval)
5242 return retval;
5243
5244 status = er32(STATUS);
5245 if (status & E1000_STATUS_LU)
5246 wufc &= ~E1000_WUFC_LNKC;
5247
5248 if (wufc) {
5249 e1000_setup_rctl(adapter);
5250 e1000_set_multi(netdev);
5251
5252 /* turn on all-multi mode if wake on multicast is enabled */
5253 if (wufc & E1000_WUFC_MC) {
5254 rctl = er32(RCTL);
5255 rctl |= E1000_RCTL_MPE;
5256 ew32(RCTL, rctl);
5257 }
5258
5259 ctrl = er32(CTRL);
5260 /* advertise wake from D3Cold */
5261 #define E1000_CTRL_ADVD3WUC 0x00100000
5262 /* phy power management enable */
5263 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005264 ctrl |= E1000_CTRL_ADVD3WUC;
5265 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5266 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005267 ew32(CTRL, ctrl);
5268
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005269 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5270 adapter->hw.phy.media_type ==
5271 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005272 /* keep the laser running in D3 */
5273 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005274 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005275 ew32(CTRL_EXT, ctrl_ext);
5276 }
5277
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005278 if (adapter->flags & FLAG_IS_ICH)
5279 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
5280
Auke Kokbc7f75f2007-09-17 12:30:59 -07005281 /* Allow time for pending master requests to run */
5282 e1000e_disable_pcie_master(&adapter->hw);
5283
Bruce Allan82776a42009-08-14 14:35:33 +00005284 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005285 /* enable wakeup by the PHY */
5286 retval = e1000_init_phy_wakeup(adapter, wufc);
5287 if (retval)
5288 return retval;
5289 } else {
5290 /* enable wakeup by the MAC */
5291 ew32(WUFC, wufc);
5292 ew32(WUC, E1000_WUC_PME_EN);
5293 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005294 } else {
5295 ew32(WUC, 0);
5296 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005297 }
5298
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005299 *enable_wake = !!wufc;
5300
Auke Kokbc7f75f2007-09-17 12:30:59 -07005301 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005302 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5303 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005304 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005305
5306 if (adapter->hw.phy.type == e1000_phy_igp_3)
5307 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5308
Bruce Allanad680762008-03-28 09:15:03 -07005309 /*
5310 * Release control of h/w to f/w. If f/w is AMT enabled, this
5311 * would have already happened in close and is redundant.
5312 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005313 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005314
5315 pci_disable_device(pdev);
5316
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005317 return 0;
5318}
5319
5320static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5321{
5322 if (sleep && wake) {
5323 pci_prepare_to_sleep(pdev);
5324 return;
5325 }
5326
5327 pci_wake_from_d3(pdev, wake);
5328 pci_set_power_state(pdev, PCI_D3hot);
5329}
5330
5331static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5332 bool wake)
5333{
5334 struct net_device *netdev = pci_get_drvdata(pdev);
5335 struct e1000_adapter *adapter = netdev_priv(netdev);
5336
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005337 /*
5338 * The pci-e switch on some quad port adapters will report a
5339 * correctable error when the MAC transitions from D0 to D3. To
5340 * prevent this we need to mask off the correctable errors on the
5341 * downstream port of the pci-e switch.
5342 */
5343 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5344 struct pci_dev *us_dev = pdev->bus->self;
5345 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
5346 u16 devctl;
5347
5348 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5349 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5350 (devctl & ~PCI_EXP_DEVCTL_CERE));
5351
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005352 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005353
5354 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5355 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005356 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005357 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005358}
5359
Bruce Allan6f461f62010-04-27 03:33:04 +00005360#ifdef CONFIG_PCIEASPM
5361static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5362{
5363 pci_disable_link_state(pdev, state);
5364}
5365#else
5366static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005367{
5368 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005369 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005370
5371 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005372 * Both device and parent should have the same ASPM setting.
5373 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005374 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005375 pos = pci_pcie_cap(pdev);
5376 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5377 reg16 &= ~state;
5378 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5379
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005380 if (!pdev->bus->self)
5381 return;
5382
Bruce Allan6f461f62010-04-27 03:33:04 +00005383 pos = pci_pcie_cap(pdev->bus->self);
5384 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5385 reg16 &= ~state;
5386 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5387}
5388#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005389static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005390{
5391 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5392 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5393 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5394
5395 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005396}
5397
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005398#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005399static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005400{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005401 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005402}
5403
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005404static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005405{
5406 struct net_device *netdev = pci_get_drvdata(pdev);
5407 struct e1000_adapter *adapter = netdev_priv(netdev);
5408 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005409 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005410 u32 err;
5411
Bruce Allan78cd29d2011-03-24 03:09:03 +00005412 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5413 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5414 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5415 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5416 if (aspm_disable_flag)
5417 e1000e_disable_aspm(pdev, aspm_disable_flag);
5418
Auke Kokbc7f75f2007-09-17 12:30:59 -07005419 pci_set_power_state(pdev, PCI_D0);
5420 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005421 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005422
Bruce Allan4662e822008-08-26 18:37:06 -07005423 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005424 if (netif_running(netdev)) {
5425 err = e1000_request_irq(adapter);
5426 if (err)
5427 return err;
5428 }
5429
5430 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005431
5432 /* report the system wakeup cause from S3/S4 */
5433 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5434 u16 phy_data;
5435
5436 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5437 if (phy_data) {
5438 e_info("PHY Wakeup cause - %s\n",
5439 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5440 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5441 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5442 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5443 phy_data & E1000_WUS_LNKC ? "Link Status "
5444 " Change" : "other");
5445 }
5446 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5447 } else {
5448 u32 wus = er32(WUS);
5449 if (wus) {
5450 e_info("MAC Wakeup cause - %s\n",
5451 wus & E1000_WUS_EX ? "Unicast Packet" :
5452 wus & E1000_WUS_MC ? "Multicast Packet" :
5453 wus & E1000_WUS_BC ? "Broadcast Packet" :
5454 wus & E1000_WUS_MAG ? "Magic Packet" :
5455 wus & E1000_WUS_LNKC ? "Link Status Change" :
5456 "other");
5457 }
5458 ew32(WUS, ~0);
5459 }
5460
Auke Kokbc7f75f2007-09-17 12:30:59 -07005461 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005462
Bruce Allancd791612010-05-10 14:59:51 +00005463 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005464
5465 if (netif_running(netdev))
5466 e1000e_up(adapter);
5467
5468 netif_device_attach(netdev);
5469
Bruce Allanad680762008-03-28 09:15:03 -07005470 /*
5471 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005472 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005473 * under the control of the driver.
5474 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005475 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005476 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005477
5478 return 0;
5479}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005480
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005481#ifdef CONFIG_PM_SLEEP
5482static int e1000_suspend(struct device *dev)
5483{
5484 struct pci_dev *pdev = to_pci_dev(dev);
5485 int retval;
5486 bool wake;
5487
5488 retval = __e1000_shutdown(pdev, &wake, false);
5489 if (!retval)
5490 e1000_complete_shutdown(pdev, true, wake);
5491
5492 return retval;
5493}
5494
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005495static int e1000_resume(struct device *dev)
5496{
5497 struct pci_dev *pdev = to_pci_dev(dev);
5498 struct net_device *netdev = pci_get_drvdata(pdev);
5499 struct e1000_adapter *adapter = netdev_priv(netdev);
5500
5501 if (e1000e_pm_ready(adapter))
5502 adapter->idle_check = true;
5503
5504 return __e1000_resume(pdev);
5505}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005506#endif /* CONFIG_PM_SLEEP */
5507
5508#ifdef CONFIG_PM_RUNTIME
5509static int e1000_runtime_suspend(struct device *dev)
5510{
5511 struct pci_dev *pdev = to_pci_dev(dev);
5512 struct net_device *netdev = pci_get_drvdata(pdev);
5513 struct e1000_adapter *adapter = netdev_priv(netdev);
5514
5515 if (e1000e_pm_ready(adapter)) {
5516 bool wake;
5517
5518 __e1000_shutdown(pdev, &wake, true);
5519 }
5520
5521 return 0;
5522}
5523
5524static int e1000_idle(struct device *dev)
5525{
5526 struct pci_dev *pdev = to_pci_dev(dev);
5527 struct net_device *netdev = pci_get_drvdata(pdev);
5528 struct e1000_adapter *adapter = netdev_priv(netdev);
5529
5530 if (!e1000e_pm_ready(adapter))
5531 return 0;
5532
5533 if (adapter->idle_check) {
5534 adapter->idle_check = false;
5535 if (!e1000e_has_link(adapter))
5536 pm_schedule_suspend(dev, MSEC_PER_SEC);
5537 }
5538
5539 return -EBUSY;
5540}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005541
5542static int e1000_runtime_resume(struct device *dev)
5543{
5544 struct pci_dev *pdev = to_pci_dev(dev);
5545 struct net_device *netdev = pci_get_drvdata(pdev);
5546 struct e1000_adapter *adapter = netdev_priv(netdev);
5547
5548 if (!e1000e_pm_ready(adapter))
5549 return 0;
5550
5551 adapter->idle_check = !dev->power.runtime_auto;
5552 return __e1000_resume(pdev);
5553}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005554#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005555#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005556
5557static void e1000_shutdown(struct pci_dev *pdev)
5558{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005559 bool wake = false;
5560
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005561 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005562
5563 if (system_state == SYSTEM_POWER_OFF)
5564 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005565}
5566
5567#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005568
5569static irqreturn_t e1000_intr_msix(int irq, void *data)
5570{
5571 struct net_device *netdev = data;
5572 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005573
5574 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005575 int vector, msix_irq;
5576
Dongdong Deng147b2c82010-11-16 19:50:15 -08005577 vector = 0;
5578 msix_irq = adapter->msix_entries[vector].vector;
5579 disable_irq(msix_irq);
5580 e1000_intr_msix_rx(msix_irq, netdev);
5581 enable_irq(msix_irq);
5582
5583 vector++;
5584 msix_irq = adapter->msix_entries[vector].vector;
5585 disable_irq(msix_irq);
5586 e1000_intr_msix_tx(msix_irq, netdev);
5587 enable_irq(msix_irq);
5588
5589 vector++;
5590 msix_irq = adapter->msix_entries[vector].vector;
5591 disable_irq(msix_irq);
5592 e1000_msix_other(msix_irq, netdev);
5593 enable_irq(msix_irq);
5594 }
5595
5596 return IRQ_HANDLED;
5597}
5598
Auke Kokbc7f75f2007-09-17 12:30:59 -07005599/*
5600 * Polling 'interrupt' - used by things like netconsole to send skbs
5601 * without having to re-enable interrupts. It's not called while
5602 * the interrupt routine is executing.
5603 */
5604static void e1000_netpoll(struct net_device *netdev)
5605{
5606 struct e1000_adapter *adapter = netdev_priv(netdev);
5607
Dongdong Deng147b2c82010-11-16 19:50:15 -08005608 switch (adapter->int_mode) {
5609 case E1000E_INT_MODE_MSIX:
5610 e1000_intr_msix(adapter->pdev->irq, netdev);
5611 break;
5612 case E1000E_INT_MODE_MSI:
5613 disable_irq(adapter->pdev->irq);
5614 e1000_intr_msi(adapter->pdev->irq, netdev);
5615 enable_irq(adapter->pdev->irq);
5616 break;
5617 default: /* E1000E_INT_MODE_LEGACY */
5618 disable_irq(adapter->pdev->irq);
5619 e1000_intr(adapter->pdev->irq, netdev);
5620 enable_irq(adapter->pdev->irq);
5621 break;
5622 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005623}
5624#endif
5625
5626/**
5627 * e1000_io_error_detected - called when PCI error is detected
5628 * @pdev: Pointer to PCI device
5629 * @state: The current pci connection state
5630 *
5631 * This function is called after a PCI bus error affecting
5632 * this device has been detected.
5633 */
5634static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5635 pci_channel_state_t state)
5636{
5637 struct net_device *netdev = pci_get_drvdata(pdev);
5638 struct e1000_adapter *adapter = netdev_priv(netdev);
5639
5640 netif_device_detach(netdev);
5641
Mike Masonc93b5a72009-06-30 12:45:53 +00005642 if (state == pci_channel_io_perm_failure)
5643 return PCI_ERS_RESULT_DISCONNECT;
5644
Auke Kokbc7f75f2007-09-17 12:30:59 -07005645 if (netif_running(netdev))
5646 e1000e_down(adapter);
5647 pci_disable_device(pdev);
5648
5649 /* Request a slot slot reset. */
5650 return PCI_ERS_RESULT_NEED_RESET;
5651}
5652
5653/**
5654 * e1000_io_slot_reset - called after the pci bus has been reset.
5655 * @pdev: Pointer to PCI device
5656 *
5657 * Restart the card from scratch, as if from a cold-boot. Implementation
5658 * resembles the first-half of the e1000_resume routine.
5659 */
5660static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5661{
5662 struct net_device *netdev = pci_get_drvdata(pdev);
5663 struct e1000_adapter *adapter = netdev_priv(netdev);
5664 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005665 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005666 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005667 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005668
Bruce Allan78cd29d2011-03-24 03:09:03 +00005669 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5670 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005671 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005672 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5673 if (aspm_disable_flag)
5674 e1000e_disable_aspm(pdev, aspm_disable_flag);
5675
Bruce Allanf0f422e2008-08-04 17:21:53 -07005676 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005677 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005678 dev_err(&pdev->dev,
5679 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005680 result = PCI_ERS_RESULT_DISCONNECT;
5681 } else {
5682 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005683 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005684 pci_restore_state(pdev);
5685
5686 pci_enable_wake(pdev, PCI_D3hot, 0);
5687 pci_enable_wake(pdev, PCI_D3cold, 0);
5688
5689 e1000e_reset(adapter);
5690 ew32(WUS, ~0);
5691 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005692 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005693
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005694 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005695
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005696 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005697}
5698
5699/**
5700 * e1000_io_resume - called when traffic can start flowing again.
5701 * @pdev: Pointer to PCI device
5702 *
5703 * This callback is called when the error recovery driver tells us that
5704 * its OK to resume normal operation. Implementation resembles the
5705 * second-half of the e1000_resume routine.
5706 */
5707static void e1000_io_resume(struct pci_dev *pdev)
5708{
5709 struct net_device *netdev = pci_get_drvdata(pdev);
5710 struct e1000_adapter *adapter = netdev_priv(netdev);
5711
Bruce Allancd791612010-05-10 14:59:51 +00005712 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005713
5714 if (netif_running(netdev)) {
5715 if (e1000e_up(adapter)) {
5716 dev_err(&pdev->dev,
5717 "can't bring device back up after reset\n");
5718 return;
5719 }
5720 }
5721
5722 netif_device_attach(netdev);
5723
Bruce Allanad680762008-03-28 09:15:03 -07005724 /*
5725 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005726 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005727 * under the control of the driver.
5728 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005729 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005730 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005731
5732}
5733
5734static void e1000_print_device_info(struct e1000_adapter *adapter)
5735{
5736 struct e1000_hw *hw = &adapter->hw;
5737 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005738 u32 ret_val;
5739 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005740
5741 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005742 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005743 /* bus width */
5744 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5745 "Width x1"),
5746 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005747 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005748 e_info("Intel(R) PRO/%s Network Connection\n",
5749 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005750 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5751 E1000_PBANUM_LENGTH);
5752 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005753 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005754 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5755 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005756}
5757
Auke Kok10aa4c02008-08-04 17:21:20 -07005758static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5759{
5760 struct e1000_hw *hw = &adapter->hw;
5761 int ret_val;
5762 u16 buf = 0;
5763
5764 if (hw->mac.type != e1000_82573)
5765 return;
5766
5767 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005768 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005769 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005770 dev_warn(&adapter->pdev->dev,
5771 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005772 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005773}
5774
Stephen Hemminger651c2462008-11-19 21:57:48 -08005775static const struct net_device_ops e1000e_netdev_ops = {
5776 .ndo_open = e1000_open,
5777 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005778 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005779 .ndo_get_stats64 = e1000e_get_stats64,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005780 .ndo_set_multicast_list = e1000_set_multi,
5781 .ndo_set_mac_address = e1000_set_mac,
5782 .ndo_change_mtu = e1000_change_mtu,
5783 .ndo_do_ioctl = e1000_ioctl,
5784 .ndo_tx_timeout = e1000_tx_timeout,
5785 .ndo_validate_addr = eth_validate_addr,
5786
Stephen Hemminger651c2462008-11-19 21:57:48 -08005787 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5788 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5789#ifdef CONFIG_NET_POLL_CONTROLLER
5790 .ndo_poll_controller = e1000_netpoll,
5791#endif
5792};
5793
Auke Kokbc7f75f2007-09-17 12:30:59 -07005794/**
5795 * e1000_probe - Device Initialization Routine
5796 * @pdev: PCI device information struct
5797 * @ent: entry in e1000_pci_tbl
5798 *
5799 * Returns 0 on success, negative on failure
5800 *
5801 * e1000_probe initializes an adapter identified by a pci_dev structure.
5802 * The OS initialization, configuring of the adapter private structure,
5803 * and a hardware reset occur.
5804 **/
5805static int __devinit e1000_probe(struct pci_dev *pdev,
5806 const struct pci_device_id *ent)
5807{
5808 struct net_device *netdev;
5809 struct e1000_adapter *adapter;
5810 struct e1000_hw *hw;
5811 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005812 resource_size_t mmio_start, mmio_len;
5813 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005814
5815 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005816 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005817 int i, err, pci_using_dac;
5818 u16 eeprom_data = 0;
5819 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5820
Bruce Allan78cd29d2011-03-24 03:09:03 +00005821 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
5822 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005823 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005824 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5825 if (aspm_disable_flag)
5826 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005827
Bruce Allanf0f422e2008-08-04 17:21:53 -07005828 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005829 if (err)
5830 return err;
5831
5832 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005833 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005834 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005835 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005836 if (!err)
5837 pci_using_dac = 1;
5838 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005839 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005840 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005841 err = dma_set_coherent_mask(&pdev->dev,
5842 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005843 if (err) {
5844 dev_err(&pdev->dev, "No usable DMA "
5845 "configuration, aborting\n");
5846 goto err_dma;
5847 }
5848 }
5849 }
5850
Arjan van de Vene8de1482008-10-22 19:55:31 -07005851 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005852 pci_select_bars(pdev, IORESOURCE_MEM),
5853 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005854 if (err)
5855 goto err_pci_reg;
5856
Xiaotian Feng68eac462009-08-14 14:35:52 +00005857 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005858 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005859
Auke Kokbc7f75f2007-09-17 12:30:59 -07005860 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005861 /* PCI config space info */
5862 err = pci_save_state(pdev);
5863 if (err)
5864 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005865
5866 err = -ENOMEM;
5867 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5868 if (!netdev)
5869 goto err_alloc_etherdev;
5870
Auke Kokbc7f75f2007-09-17 12:30:59 -07005871 SET_NETDEV_DEV(netdev, &pdev->dev);
5872
Tom Herbertf85e4df2010-05-05 14:03:32 +00005873 netdev->irq = pdev->irq;
5874
Auke Kokbc7f75f2007-09-17 12:30:59 -07005875 pci_set_drvdata(pdev, netdev);
5876 adapter = netdev_priv(netdev);
5877 hw = &adapter->hw;
5878 adapter->netdev = netdev;
5879 adapter->pdev = pdev;
5880 adapter->ei = ei;
5881 adapter->pba = ei->pba;
5882 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005883 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005884 adapter->hw.adapter = adapter;
5885 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005886 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005887 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5888
5889 mmio_start = pci_resource_start(pdev, 0);
5890 mmio_len = pci_resource_len(pdev, 0);
5891
5892 err = -EIO;
5893 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5894 if (!adapter->hw.hw_addr)
5895 goto err_ioremap;
5896
5897 if ((adapter->flags & FLAG_HAS_FLASH) &&
5898 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5899 flash_start = pci_resource_start(pdev, 1);
5900 flash_len = pci_resource_len(pdev, 1);
5901 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5902 if (!adapter->hw.flash_address)
5903 goto err_flashmap;
5904 }
5905
5906 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005907 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005908 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005909 netdev->watchdog_timeo = 5 * HZ;
5910 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005911 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5912
5913 netdev->mem_start = mmio_start;
5914 netdev->mem_end = mmio_start + mmio_len;
5915
5916 adapter->bd_number = cards_found++;
5917
Bruce Allan4662e822008-08-26 18:37:06 -07005918 e1000e_check_options(adapter);
5919
Auke Kokbc7f75f2007-09-17 12:30:59 -07005920 /* setup adapter struct */
5921 err = e1000_sw_init(adapter);
5922 if (err)
5923 goto err_sw_init;
5924
Auke Kokbc7f75f2007-09-17 12:30:59 -07005925 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5926 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5927 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5928
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005929 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005930 if (err)
5931 goto err_hw_init;
5932
Bruce Allan4a770352008-10-01 17:18:35 -07005933 if ((adapter->flags & FLAG_IS_ICH) &&
5934 (adapter->flags & FLAG_READ_ONLY_NVM))
5935 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5936
Auke Kokbc7f75f2007-09-17 12:30:59 -07005937 hw->mac.ops.get_bus_info(&adapter->hw);
5938
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005939 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005940
5941 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005942 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005943 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5944 adapter->hw.phy.disable_polarity_correction = 0;
5945 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5946 }
5947
5948 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005949 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005950
5951 netdev->features = NETIF_F_SG |
5952 NETIF_F_HW_CSUM |
5953 NETIF_F_HW_VLAN_TX |
5954 NETIF_F_HW_VLAN_RX;
5955
5956 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5957 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5958
5959 netdev->features |= NETIF_F_TSO;
5960 netdev->features |= NETIF_F_TSO6;
5961
Jeff Kirshera5136e22008-06-05 04:07:28 -07005962 netdev->vlan_features |= NETIF_F_TSO;
5963 netdev->vlan_features |= NETIF_F_TSO6;
5964 netdev->vlan_features |= NETIF_F_HW_CSUM;
5965 netdev->vlan_features |= NETIF_F_SG;
5966
Yi Zou7b872a52010-09-22 17:57:58 +00005967 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005968 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00005969 netdev->vlan_features |= NETIF_F_HIGHDMA;
5970 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005971
Auke Kokbc7f75f2007-09-17 12:30:59 -07005972 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5973 adapter->flags |= FLAG_MNG_PT_ENABLED;
5974
Bruce Allanad680762008-03-28 09:15:03 -07005975 /*
5976 * before reading the NVM, reset the controller to
5977 * put the device in a known good starting state
5978 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005979 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5980
5981 /*
5982 * systems with ASPM and others may see the checksum fail on the first
5983 * attempt. Let's give it a few tries
5984 */
5985 for (i = 0;; i++) {
5986 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5987 break;
5988 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005989 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005990 err = -EIO;
5991 goto err_eeprom;
5992 }
5993 }
5994
Auke Kok10aa4c02008-08-04 17:21:20 -07005995 e1000_eeprom_checks(adapter);
5996
Bruce Allan608f8a02010-01-13 02:04:58 +00005997 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005998 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005999 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006000
6001 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6002 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6003
6004 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006005 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006006 err = -EIO;
6007 goto err_eeprom;
6008 }
6009
6010 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006011 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006012 adapter->watchdog_timer.data = (unsigned long) adapter;
6013
6014 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006015 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006016 adapter->phy_info_timer.data = (unsigned long) adapter;
6017
6018 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6019 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006020 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6021 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006022 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Holger Eitzenberger9633e632010-11-17 15:43:52 +00006023 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006024
Auke Kokbc7f75f2007-09-17 12:30:59 -07006025 /* Initialize link parameters. User can change them with ethtool */
6026 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07006027 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006028 adapter->hw.fc.requested_mode = e1000_fc_default;
6029 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006030 adapter->hw.phy.autoneg_advertised = 0x2f;
6031
6032 /* ring size defaults */
6033 adapter->rx_ring->count = 256;
6034 adapter->tx_ring->count = 256;
6035
6036 /*
6037 * Initial Wake on LAN setting - If APM wake is enabled in
6038 * the EEPROM, enable the ACPI Magic Packet filter
6039 */
6040 if (adapter->flags & FLAG_APME_IN_WUC) {
6041 /* APME bit in EEPROM is mapped to WUC.APME */
6042 eeprom_data = er32(WUC);
6043 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006044 if ((hw->mac.type > e1000_ich10lan) &&
6045 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006046 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006047 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6048 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6049 (adapter->hw.bus.func == 1))
6050 e1000_read_nvm(&adapter->hw,
6051 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6052 else
6053 e1000_read_nvm(&adapter->hw,
6054 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6055 }
6056
6057 /* fetch WoL from EEPROM */
6058 if (eeprom_data & eeprom_apme_mask)
6059 adapter->eeprom_wol |= E1000_WUFC_MAG;
6060
6061 /*
6062 * now that we have the eeprom settings, apply the special cases
6063 * where the eeprom may be wrong or the board simply won't support
6064 * wake on lan on a particular port
6065 */
6066 if (!(adapter->flags & FLAG_HAS_WOL))
6067 adapter->eeprom_wol = 0;
6068
6069 /* initialize the wol settings based on the eeprom settings */
6070 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006071 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006072
Bruce Allan84527592008-11-21 17:00:22 -08006073 /* save off EEPROM version number */
6074 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6075
Auke Kokbc7f75f2007-09-17 12:30:59 -07006076 /* reset the hardware with the new settings */
6077 e1000e_reset(adapter);
6078
Bruce Allanad680762008-03-28 09:15:03 -07006079 /*
6080 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006081 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006082 * under the control of the driver.
6083 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006084 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006085 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006086
Bruce Allane0dc4f12011-01-06 14:29:50 +00006087 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006088 err = register_netdev(netdev);
6089 if (err)
6090 goto err_register;
6091
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006092 /* carrier off reporting is important to ethtool even BEFORE open */
6093 netif_carrier_off(netdev);
6094
Auke Kokbc7f75f2007-09-17 12:30:59 -07006095 e1000_print_device_info(adapter);
6096
Alan Sternf3ec4f82010-06-08 15:23:51 -04006097 if (pci_dev_run_wake(pdev))
6098 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006099
Auke Kokbc7f75f2007-09-17 12:30:59 -07006100 return 0;
6101
6102err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006103 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006104 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006105err_eeprom:
6106 if (!e1000_check_reset_block(&adapter->hw))
6107 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006108err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006109 kfree(adapter->tx_ring);
6110 kfree(adapter->rx_ring);
6111err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006112 if (adapter->hw.flash_address)
6113 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006114 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006115err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006116 iounmap(adapter->hw.hw_addr);
6117err_ioremap:
6118 free_netdev(netdev);
6119err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006120 pci_release_selected_regions(pdev,
6121 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006122err_pci_reg:
6123err_dma:
6124 pci_disable_device(pdev);
6125 return err;
6126}
6127
6128/**
6129 * e1000_remove - Device Removal Routine
6130 * @pdev: PCI device information struct
6131 *
6132 * e1000_remove is called by the PCI subsystem to alert the driver
6133 * that it should release a PCI device. The could be caused by a
6134 * Hot-Plug event, or because the driver is going to be removed from
6135 * memory.
6136 **/
6137static void __devexit e1000_remove(struct pci_dev *pdev)
6138{
6139 struct net_device *netdev = pci_get_drvdata(pdev);
6140 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006141 bool down = test_bit(__E1000_DOWN, &adapter->state);
6142
Bruce Allanad680762008-03-28 09:15:03 -07006143 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006144 * The timers may be rescheduled, so explicitly disable them
6145 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006146 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006147 if (!down)
6148 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006149 del_timer_sync(&adapter->watchdog_timer);
6150 del_timer_sync(&adapter->phy_info_timer);
6151
Bruce Allan41cec6f2009-11-20 23:28:56 +00006152 cancel_work_sync(&adapter->reset_task);
6153 cancel_work_sync(&adapter->watchdog_task);
6154 cancel_work_sync(&adapter->downshift_task);
6155 cancel_work_sync(&adapter->update_phy_task);
Tejun Heo23f333a2010-12-12 16:45:14 +01006156 cancel_work_sync(&adapter->led_blink_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006157 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006158
Bruce Allan17f208d2009-12-01 15:47:22 +00006159 if (!(netdev->flags & IFF_UP))
6160 e1000_power_down_phy(adapter);
6161
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006162 /* Don't lie to e1000_close() down the road. */
6163 if (!down)
6164 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006165 unregister_netdev(netdev);
6166
Alan Sternf3ec4f82010-06-08 15:23:51 -04006167 if (pci_dev_run_wake(pdev))
6168 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006169
Bruce Allanad680762008-03-28 09:15:03 -07006170 /*
6171 * Release control of h/w to f/w. If f/w is AMT enabled, this
6172 * would have already happened in close and is redundant.
6173 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006174 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006175
Bruce Allan4662e822008-08-26 18:37:06 -07006176 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006177 kfree(adapter->tx_ring);
6178 kfree(adapter->rx_ring);
6179
6180 iounmap(adapter->hw.hw_addr);
6181 if (adapter->hw.flash_address)
6182 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006183 pci_release_selected_regions(pdev,
6184 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006185
6186 free_netdev(netdev);
6187
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006188 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006189 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006190
Auke Kokbc7f75f2007-09-17 12:30:59 -07006191 pci_disable_device(pdev);
6192}
6193
6194/* PCI Error Recovery (ERS) */
6195static struct pci_error_handlers e1000_err_handler = {
6196 .error_detected = e1000_io_error_detected,
6197 .slot_reset = e1000_io_slot_reset,
6198 .resume = e1000_io_resume,
6199};
6200
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006201static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006202 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6203 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6204 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6205 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6206 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6207 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006208 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6209 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6210 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006211
Auke Kokbc7f75f2007-09-17 12:30:59 -07006212 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6213 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6214 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6215 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006216
Auke Kokbc7f75f2007-09-17 12:30:59 -07006217 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6218 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6219 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006220
Bruce Allan4662e822008-08-26 18:37:06 -07006221 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006222 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006223 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006224
Auke Kokbc7f75f2007-09-17 12:30:59 -07006225 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6226 board_80003es2lan },
6227 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6228 board_80003es2lan },
6229 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6230 board_80003es2lan },
6231 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6232 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006233
Auke Kokbc7f75f2007-09-17 12:30:59 -07006234 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6235 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6236 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6237 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6238 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6239 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6240 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006241 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006242
Auke Kokbc7f75f2007-09-17 12:30:59 -07006243 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6244 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6245 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6246 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6247 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006248 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006249 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6250 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6251 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6252
6253 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6254 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6255 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006256
Bruce Allanf4187b52008-08-26 18:36:50 -07006257 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6258 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006259 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006260
Bruce Allana4f58f52009-06-02 11:29:18 +00006261 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6262 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6263 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6264 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6265
Bruce Alland3738bb2010-06-16 13:27:28 +00006266 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6267 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6268
Auke Kokbc7f75f2007-09-17 12:30:59 -07006269 { } /* terminate list */
6270};
6271MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6272
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006273#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006274static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006275 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6276 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6277 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006278};
David S. Millere50208a2010-03-16 23:36:24 -07006279#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006280
Auke Kokbc7f75f2007-09-17 12:30:59 -07006281/* PCI Device API Driver */
6282static struct pci_driver e1000_driver = {
6283 .name = e1000e_driver_name,
6284 .id_table = e1000_pci_tbl,
6285 .probe = e1000_probe,
6286 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006287#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006288 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006289#endif
6290 .shutdown = e1000_shutdown,
6291 .err_handler = &e1000_err_handler
6292};
6293
6294/**
6295 * e1000_init_module - Driver Registration Routine
6296 *
6297 * e1000_init_module is the first routine called when the driver is
6298 * loaded. All it does is register with the PCI subsystem.
6299 **/
6300static int __init e1000_init_module(void)
6301{
6302 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006303 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6304 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006305 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006306 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006307
Auke Kokbc7f75f2007-09-17 12:30:59 -07006308 return ret;
6309}
6310module_init(e1000_init_module);
6311
6312/**
6313 * e1000_exit_module - Driver Exit Cleanup Routine
6314 *
6315 * e1000_exit_module is called just before the driver is removed
6316 * from memory.
6317 **/
6318static void __exit e1000_exit_module(void)
6319{
6320 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006321}
6322module_exit(e1000_exit_module);
6323
6324
6325MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6326MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6327MODULE_LICENSE("GPL");
6328MODULE_VERSION(DRV_VERSION);
6329
6330/* e1000_main.c */