blob: 1c18f26b0812ac962708c68711abe58167c0eee0 [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 Allanc920aa82010-12-01 08:45:24 +000057#define DRV_VERSION "1.2.20" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070058char e1000e_driver_name[] = "e1000e";
59const char e1000e_driver_version[] = DRV_VERSION;
60
61static const struct e1000_info *e1000_info_tbl[] = {
62 [board_82571] = &e1000_82571_info,
63 [board_82572] = &e1000_82572_info,
64 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070065 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000066 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070067 [board_80003es2lan] = &e1000_es2_info,
68 [board_ich8lan] = &e1000_ich8_info,
69 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070070 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000071 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000072 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070073};
74
Taku Izumi84f4ee92010-04-27 14:39:08 +000075struct e1000_reg_info {
76 u32 ofs;
77 char *name;
78};
79
Bruce Allanaf667a22010-12-31 06:10:01 +000080#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
81#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
82#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
83#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
84#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000085
Bruce Allanaf667a22010-12-31 06:10:01 +000086#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
87#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
88#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
89#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
90#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000091
92static const struct e1000_reg_info e1000_reg_info_tbl[] = {
93
94 /* General Registers */
95 {E1000_CTRL, "CTRL"},
96 {E1000_STATUS, "STATUS"},
97 {E1000_CTRL_EXT, "CTRL_EXT"},
98
99 /* Interrupt Registers */
100 {E1000_ICR, "ICR"},
101
Bruce Allanaf667a22010-12-31 06:10:01 +0000102 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000103 {E1000_RCTL, "RCTL"},
104 {E1000_RDLEN, "RDLEN"},
105 {E1000_RDH, "RDH"},
106 {E1000_RDT, "RDT"},
107 {E1000_RDTR, "RDTR"},
108 {E1000_RXDCTL(0), "RXDCTL"},
109 {E1000_ERT, "ERT"},
110 {E1000_RDBAL, "RDBAL"},
111 {E1000_RDBAH, "RDBAH"},
112 {E1000_RDFH, "RDFH"},
113 {E1000_RDFT, "RDFT"},
114 {E1000_RDFHS, "RDFHS"},
115 {E1000_RDFTS, "RDFTS"},
116 {E1000_RDFPC, "RDFPC"},
117
Bruce Allanaf667a22010-12-31 06:10:01 +0000118 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000119 {E1000_TCTL, "TCTL"},
120 {E1000_TDBAL, "TDBAL"},
121 {E1000_TDBAH, "TDBAH"},
122 {E1000_TDLEN, "TDLEN"},
123 {E1000_TDH, "TDH"},
124 {E1000_TDT, "TDT"},
125 {E1000_TIDV, "TIDV"},
126 {E1000_TXDCTL(0), "TXDCTL"},
127 {E1000_TADV, "TADV"},
128 {E1000_TARC(0), "TARC"},
129 {E1000_TDFH, "TDFH"},
130 {E1000_TDFT, "TDFT"},
131 {E1000_TDFHS, "TDFHS"},
132 {E1000_TDFTS, "TDFTS"},
133 {E1000_TDFPC, "TDFPC"},
134
135 /* List Terminator */
136 {}
137};
138
139/*
140 * e1000_regdump - register printout routine
141 */
142static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
143{
144 int n = 0;
145 char rname[16];
146 u32 regs[8];
147
148 switch (reginfo->ofs) {
149 case E1000_RXDCTL(0):
150 for (n = 0; n < 2; n++)
151 regs[n] = __er32(hw, E1000_RXDCTL(n));
152 break;
153 case E1000_TXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_TXDCTL(n));
156 break;
157 case E1000_TARC(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TARC(n));
160 break;
161 default:
162 printk(KERN_INFO "%-15s %08x\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000163 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000164 return;
165 }
166
167 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
168 printk(KERN_INFO "%-15s ", rname);
169 for (n = 0; n < 2; n++)
170 printk(KERN_CONT "%08x ", regs[n]);
171 printk(KERN_CONT "\n");
172}
173
Taku Izumi84f4ee92010-04-27 14:39:08 +0000174/*
Bruce Allanaf667a22010-12-31 06:10:01 +0000175 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Taku Izumi84f4ee92010-04-27 14:39:08 +0000176 */
177static void e1000e_dump(struct e1000_adapter *adapter)
178{
179 struct net_device *netdev = adapter->netdev;
180 struct e1000_hw *hw = &adapter->hw;
181 struct e1000_reg_info *reginfo;
182 struct e1000_ring *tx_ring = adapter->tx_ring;
183 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000184 struct my_u0 {
185 u64 a;
186 u64 b;
187 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000188 struct e1000_buffer *buffer_info;
189 struct e1000_ring *rx_ring = adapter->rx_ring;
190 union e1000_rx_desc_packet_split *rx_desc_ps;
191 struct e1000_rx_desc *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000192 struct my_u1 {
193 u64 a;
194 u64 b;
195 u64 c;
196 u64 d;
197 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000198 u32 staterr;
199 int i = 0;
200
201 if (!netif_msg_hw(adapter))
202 return;
203
204 /* Print netdevice Info */
205 if (netdev) {
206 dev_info(&adapter->pdev->dev, "Net device Info\n");
207 printk(KERN_INFO "Device Name state "
Bruce Allanaf667a22010-12-31 06:10:01 +0000208 "trans_start last_rx\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000209 printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000210 netdev->name, netdev->state, netdev->trans_start,
211 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000212 }
213
214 /* Print Registers */
215 dev_info(&adapter->pdev->dev, "Register Dump\n");
216 printk(KERN_INFO " Register Name Value\n");
217 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
218 reginfo->name; reginfo++) {
219 e1000_regdump(hw, reginfo);
220 }
221
Bruce Allanaf667a22010-12-31 06:10:01 +0000222 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000223 if (!netdev || !netif_running(netdev))
224 goto exit;
225
Bruce Allanaf667a22010-12-31 06:10:01 +0000226 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000227 printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000228 " leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000229 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
230 printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000231 0, tx_ring->next_to_use, tx_ring->next_to_clean,
232 (unsigned long long)buffer_info->dma,
233 buffer_info->length,
234 buffer_info->next_to_watch,
235 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000236
Bruce Allanaf667a22010-12-31 06:10:01 +0000237 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000238 if (!netif_msg_tx_done(adapter))
239 goto rx_ring_summary;
240
Bruce Allanaf667a22010-12-31 06:10:01 +0000241 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000242
243 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
244 *
245 * Legacy Transmit Descriptor
246 * +--------------------------------------------------------------+
247 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
248 * +--------------------------------------------------------------+
249 * 8 | Special | CSS | Status | CMD | CSO | Length |
250 * +--------------------------------------------------------------+
251 * 63 48 47 36 35 32 31 24 23 16 15 0
252 *
253 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
254 * 63 48 47 40 39 32 31 16 15 8 7 0
255 * +----------------------------------------------------------------+
256 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
257 * +----------------------------------------------------------------+
258 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
259 * +----------------------------------------------------------------+
260 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
261 *
262 * Extended Data Descriptor (DTYP=0x1)
263 * +----------------------------------------------------------------+
264 * 0 | Buffer Address [63:0] |
265 * +----------------------------------------------------------------+
266 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
267 * +----------------------------------------------------------------+
268 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
269 */
270 printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000271 " [bi->dma ] leng ntw timestamp bi->skb "
272 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000273 printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000274 " [bi->dma ] leng ntw timestamp bi->skb "
275 "<-- Ext Context format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000276 printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000277 " [bi->dma ] leng ntw timestamp bi->skb "
278 "<-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000279 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
280 tx_desc = E1000_TX_DESC(*tx_ring, i);
281 buffer_info = &tx_ring->buffer_info[i];
282 u0 = (struct my_u0 *)tx_desc;
283 printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000284 "%04X %3X %016llX %p",
285 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
286 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), i,
Bruce Allan8eb64e62010-06-29 18:12:30 +0000287 (unsigned long long)le64_to_cpu(u0->a),
288 (unsigned long long)le64_to_cpu(u0->b),
289 (unsigned long long)buffer_info->dma,
290 buffer_info->length, buffer_info->next_to_watch,
291 (unsigned long long)buffer_info->time_stamp,
Taku Izumi84f4ee92010-04-27 14:39:08 +0000292 buffer_info->skb);
293 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
294 printk(KERN_CONT " NTC/U\n");
295 else if (i == tx_ring->next_to_use)
296 printk(KERN_CONT " NTU\n");
297 else if (i == tx_ring->next_to_clean)
298 printk(KERN_CONT " NTC\n");
299 else
300 printk(KERN_CONT "\n");
301
302 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
303 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Bruce Allanaf667a22010-12-31 06:10:01 +0000304 16, 1, phys_to_virt(buffer_info->dma),
305 buffer_info->length, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000306 }
307
Bruce Allanaf667a22010-12-31 06:10:01 +0000308 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000309rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000310 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000311 printk(KERN_INFO "Queue [NTU] [NTC]\n");
312 printk(KERN_INFO " %5d %5X %5X\n", 0,
Bruce Allanaf667a22010-12-31 06:10:01 +0000313 rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000314
Bruce Allanaf667a22010-12-31 06:10:01 +0000315 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000316 if (!netif_msg_rx_status(adapter))
317 goto exit;
318
Bruce Allanaf667a22010-12-31 06:10:01 +0000319 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000320 switch (adapter->rx_ps_pages) {
321 case 1:
322 case 2:
323 case 3:
324 /* [Extended] Packet Split Receive Descriptor Format
325 *
326 * +-----------------------------------------------------+
327 * 0 | Buffer Address 0 [63:0] |
328 * +-----------------------------------------------------+
329 * 8 | Buffer Address 1 [63:0] |
330 * +-----------------------------------------------------+
331 * 16 | Buffer Address 2 [63:0] |
332 * +-----------------------------------------------------+
333 * 24 | Buffer Address 3 [63:0] |
334 * +-----------------------------------------------------+
335 */
336 printk(KERN_INFO "R [desc] [buffer 0 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000337 "[buffer 1 63:0 ] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000338 "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] "
339 "[bi->skb] <-- Ext Pkt Split format\n");
340 /* [Extended] Receive Descriptor (Write-Back) Format
341 *
342 * 63 48 47 32 31 13 12 8 7 4 3 0
343 * +------------------------------------------------------+
344 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
345 * | Checksum | Ident | | Queue | | Type |
346 * +------------------------------------------------------+
347 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
348 * +------------------------------------------------------+
349 * 63 48 47 32 31 20 19 0
350 */
351 printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000352 "[vl l0 ee es] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000353 "[ l3 l2 l1 hs] [reserved ] ---------------- "
354 "[bi->skb] <-- Ext Rx Write-Back format\n");
355 for (i = 0; i < rx_ring->count; i++) {
356 buffer_info = &rx_ring->buffer_info[i];
357 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
358 u1 = (struct my_u1 *)rx_desc_ps;
359 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000360 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000361 if (staterr & E1000_RXD_STAT_DD) {
362 /* Descriptor Done */
363 printk(KERN_INFO "RWB[0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000364 "%016llX %016llX %016llX "
365 "---------------- %p", i,
366 (unsigned long long)le64_to_cpu(u1->a),
367 (unsigned long long)le64_to_cpu(u1->b),
368 (unsigned long long)le64_to_cpu(u1->c),
369 (unsigned long long)le64_to_cpu(u1->d),
370 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000371 } else {
372 printk(KERN_INFO "R [0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000373 "%016llX %016llX %016llX %016llX %p", i,
374 (unsigned long long)le64_to_cpu(u1->a),
375 (unsigned long long)le64_to_cpu(u1->b),
376 (unsigned long long)le64_to_cpu(u1->c),
377 (unsigned long long)le64_to_cpu(u1->d),
378 (unsigned long long)buffer_info->dma,
379 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000380
381 if (netif_msg_pktdata(adapter))
382 print_hex_dump(KERN_INFO, "",
383 DUMP_PREFIX_ADDRESS, 16, 1,
384 phys_to_virt(buffer_info->dma),
385 adapter->rx_ps_bsize0, true);
386 }
387
388 if (i == rx_ring->next_to_use)
389 printk(KERN_CONT " NTU\n");
390 else if (i == rx_ring->next_to_clean)
391 printk(KERN_CONT " NTC\n");
392 else
393 printk(KERN_CONT "\n");
394 }
395 break;
396 default:
397 case 0:
398 /* Legacy Receive Descriptor Format
399 *
400 * +-----------------------------------------------------+
401 * | Buffer Address [63:0] |
402 * +-----------------------------------------------------+
403 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
404 * +-----------------------------------------------------+
405 * 63 48 47 40 39 32 31 16 15 0
406 */
407 printk(KERN_INFO "Rl[desc] [address 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000408 "[vl er S cks ln] [bi->dma ] [bi->skb] "
409 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000410 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
411 rx_desc = E1000_RX_DESC(*rx_ring, i);
412 buffer_info = &rx_ring->buffer_info[i];
413 u0 = (struct my_u0 *)rx_desc;
414 printk(KERN_INFO "Rl[0x%03X] %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000415 "%016llX %p", i,
416 (unsigned long long)le64_to_cpu(u0->a),
417 (unsigned long long)le64_to_cpu(u0->b),
418 (unsigned long long)buffer_info->dma,
419 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000420 if (i == rx_ring->next_to_use)
421 printk(KERN_CONT " NTU\n");
422 else if (i == rx_ring->next_to_clean)
423 printk(KERN_CONT " NTC\n");
424 else
425 printk(KERN_CONT "\n");
426
427 if (netif_msg_pktdata(adapter))
428 print_hex_dump(KERN_INFO, "",
Bruce Allanaf667a22010-12-31 06:10:01 +0000429 DUMP_PREFIX_ADDRESS,
430 16, 1,
431 phys_to_virt(buffer_info->dma),
432 adapter->rx_buffer_len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000433 }
434 }
435
436exit:
437 return;
438}
439
Auke Kokbc7f75f2007-09-17 12:30:59 -0700440/**
441 * e1000_desc_unused - calculate if we have unused descriptors
442 **/
443static int e1000_desc_unused(struct e1000_ring *ring)
444{
445 if (ring->next_to_clean > ring->next_to_use)
446 return ring->next_to_clean - ring->next_to_use - 1;
447
448 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
449}
450
451/**
Bruce Allanad680762008-03-28 09:15:03 -0700452 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700453 * @adapter: board private structure
454 * @status: descriptor status field as written by hardware
455 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
456 * @skb: pointer to sk_buff to be indicated to stack
457 **/
458static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000459 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000460 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700461{
462 skb->protocol = eth_type_trans(skb, netdev);
463
464 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
Herbert Xuc405b822009-01-14 20:37:59 -0800465 vlan_gro_receive(&adapter->napi, adapter->vlgrp,
466 le16_to_cpu(vlan), skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700467 else
Herbert Xu89c88b12008-12-15 23:46:15 -0800468 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700469}
470
471/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000472 * e1000_rx_checksum - Receive Checksum Offload
Auke Kokbc7f75f2007-09-17 12:30:59 -0700473 * @adapter: board private structure
474 * @status_err: receive descriptor status and error fields
475 * @csum: receive descriptor csum field
476 * @sk_buff: socket buffer with received data
477 **/
478static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
479 u32 csum, struct sk_buff *skb)
480{
481 u16 status = (u16)status_err;
482 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700483
484 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700485
486 /* Ignore Checksum bit is set */
487 if (status & E1000_RXD_STAT_IXSM)
488 return;
489 /* TCP/UDP checksum error bit is set */
490 if (errors & E1000_RXD_ERR_TCPE) {
491 /* let the stack verify checksum errors */
492 adapter->hw_csum_err++;
493 return;
494 }
495
496 /* TCP/UDP Checksum has not been calculated */
497 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
498 return;
499
500 /* It must be a TCP or UDP packet with a valid checksum */
501 if (status & E1000_RXD_STAT_TCPCS) {
502 /* TCP checksum is good */
503 skb->ip_summed = CHECKSUM_UNNECESSARY;
504 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700505 /*
506 * IP fragment with UDP payload
507 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700508 * and then put the value in host order for further stack use.
509 */
Al Viroa39fe742007-12-11 19:50:34 +0000510 __sum16 sum = (__force __sum16)htons(csum);
511 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700512 skb->ip_summed = CHECKSUM_COMPLETE;
513 }
514 adapter->hw_csum_good++;
515}
516
517/**
518 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
519 * @adapter: address of board private structure
520 **/
521static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
522 int cleaned_count)
523{
524 struct net_device *netdev = adapter->netdev;
525 struct pci_dev *pdev = adapter->pdev;
526 struct e1000_ring *rx_ring = adapter->rx_ring;
527 struct e1000_rx_desc *rx_desc;
528 struct e1000_buffer *buffer_info;
529 struct sk_buff *skb;
530 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000531 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532
533 i = rx_ring->next_to_use;
534 buffer_info = &rx_ring->buffer_info[i];
535
536 while (cleaned_count--) {
537 skb = buffer_info->skb;
538 if (skb) {
539 skb_trim(skb, 0);
540 goto map_skb;
541 }
542
Eric Dumazet89d71a62009-10-13 05:34:20 +0000543 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700544 if (!skb) {
545 /* Better luck next round */
546 adapter->alloc_rx_buff_failed++;
547 break;
548 }
549
Auke Kokbc7f75f2007-09-17 12:30:59 -0700550 buffer_info->skb = skb;
551map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000552 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700553 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000554 DMA_FROM_DEVICE);
555 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000556 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557 adapter->rx_dma_failed++;
558 break;
559 }
560
561 rx_desc = E1000_RX_DESC(*rx_ring, i);
562 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
563
Tom Herbert50849d72010-05-05 14:02:49 +0000564 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
565 /*
566 * Force memory writes to complete before letting h/w
567 * know there are new descriptors to fetch. (Only
568 * applicable for weak-ordered memory model archs,
569 * such as IA-64).
570 */
571 wmb();
572 writel(i, adapter->hw.hw_addr + rx_ring->tail);
573 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700574 i++;
575 if (i == rx_ring->count)
576 i = 0;
577 buffer_info = &rx_ring->buffer_info[i];
578 }
579
Tom Herbert50849d72010-05-05 14:02:49 +0000580 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700581}
582
583/**
584 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
585 * @adapter: address of board private structure
586 **/
587static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
588 int cleaned_count)
589{
590 struct net_device *netdev = adapter->netdev;
591 struct pci_dev *pdev = adapter->pdev;
592 union e1000_rx_desc_packet_split *rx_desc;
593 struct e1000_ring *rx_ring = adapter->rx_ring;
594 struct e1000_buffer *buffer_info;
595 struct e1000_ps_page *ps_page;
596 struct sk_buff *skb;
597 unsigned int i, j;
598
599 i = rx_ring->next_to_use;
600 buffer_info = &rx_ring->buffer_info[i];
601
602 while (cleaned_count--) {
603 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
604
605 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700606 ps_page = &buffer_info->ps_pages[j];
607 if (j >= adapter->rx_ps_pages) {
608 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000609 rx_desc->read.buffer_addr[j + 1] =
610 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700611 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700612 }
Auke Kok47f44e42007-10-25 13:57:44 -0700613 if (!ps_page->page) {
614 ps_page->page = alloc_page(GFP_ATOMIC);
615 if (!ps_page->page) {
616 adapter->alloc_rx_buff_failed++;
617 goto no_buffers;
618 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000619 ps_page->dma = dma_map_page(&pdev->dev,
620 ps_page->page,
621 0, PAGE_SIZE,
622 DMA_FROM_DEVICE);
623 if (dma_mapping_error(&pdev->dev,
624 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700625 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000626 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700627 adapter->rx_dma_failed++;
628 goto no_buffers;
629 }
630 }
631 /*
632 * Refresh the desc even if buffer_addrs
633 * didn't change because each write-back
634 * erases this info.
635 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000636 rx_desc->read.buffer_addr[j + 1] =
637 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700638 }
639
Eric Dumazet89d71a62009-10-13 05:34:20 +0000640 skb = netdev_alloc_skb_ip_align(netdev,
641 adapter->rx_ps_bsize0);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700642
643 if (!skb) {
644 adapter->alloc_rx_buff_failed++;
645 break;
646 }
647
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000649 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700650 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000651 DMA_FROM_DEVICE);
652 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000653 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700654 adapter->rx_dma_failed++;
655 /* cleanup skb */
656 dev_kfree_skb_any(skb);
657 buffer_info->skb = NULL;
658 break;
659 }
660
661 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
662
Tom Herbert50849d72010-05-05 14:02:49 +0000663 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
664 /*
665 * Force memory writes to complete before letting h/w
666 * know there are new descriptors to fetch. (Only
667 * applicable for weak-ordered memory model archs,
668 * such as IA-64).
669 */
670 wmb();
Bruce Allanaf667a22010-12-31 06:10:01 +0000671 writel(i << 1, adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000672 }
673
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674 i++;
675 if (i == rx_ring->count)
676 i = 0;
677 buffer_info = &rx_ring->buffer_info[i];
678 }
679
680no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000681 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700682}
683
684/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700685 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
686 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700687 * @cleaned_count: number of buffers to allocate this pass
688 **/
689
690static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
691 int cleaned_count)
692{
693 struct net_device *netdev = adapter->netdev;
694 struct pci_dev *pdev = adapter->pdev;
695 struct e1000_rx_desc *rx_desc;
696 struct e1000_ring *rx_ring = adapter->rx_ring;
697 struct e1000_buffer *buffer_info;
698 struct sk_buff *skb;
699 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000700 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700701
702 i = rx_ring->next_to_use;
703 buffer_info = &rx_ring->buffer_info[i];
704
705 while (cleaned_count--) {
706 skb = buffer_info->skb;
707 if (skb) {
708 skb_trim(skb, 0);
709 goto check_page;
710 }
711
Eric Dumazet89d71a62009-10-13 05:34:20 +0000712 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700713 if (unlikely(!skb)) {
714 /* Better luck next round */
715 adapter->alloc_rx_buff_failed++;
716 break;
717 }
718
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700719 buffer_info->skb = skb;
720check_page:
721 /* allocate a new page if necessary */
722 if (!buffer_info->page) {
723 buffer_info->page = alloc_page(GFP_ATOMIC);
724 if (unlikely(!buffer_info->page)) {
725 adapter->alloc_rx_buff_failed++;
726 break;
727 }
728 }
729
730 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000731 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700732 buffer_info->page, 0,
733 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000734 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700735
736 rx_desc = E1000_RX_DESC(*rx_ring, i);
737 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
738
739 if (unlikely(++i == rx_ring->count))
740 i = 0;
741 buffer_info = &rx_ring->buffer_info[i];
742 }
743
744 if (likely(rx_ring->next_to_use != i)) {
745 rx_ring->next_to_use = i;
746 if (unlikely(i-- == 0))
747 i = (rx_ring->count - 1);
748
749 /* Force memory writes to complete before letting h/w
750 * know there are new descriptors to fetch. (Only
751 * applicable for weak-ordered memory model archs,
752 * such as IA-64). */
753 wmb();
754 writel(i, adapter->hw.hw_addr + rx_ring->tail);
755 }
756}
757
758/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700759 * e1000_clean_rx_irq - Send received data up the network stack; legacy
760 * @adapter: board private structure
761 *
762 * the return value indicates whether actual cleaning was done, there
763 * is no guarantee that everything was cleaned
764 **/
765static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
766 int *work_done, int work_to_do)
767{
768 struct net_device *netdev = adapter->netdev;
769 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000770 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700771 struct e1000_ring *rx_ring = adapter->rx_ring;
772 struct e1000_rx_desc *rx_desc, *next_rxd;
773 struct e1000_buffer *buffer_info, *next_buffer;
774 u32 length;
775 unsigned int i;
776 int cleaned_count = 0;
777 bool cleaned = 0;
778 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
779
780 i = rx_ring->next_to_clean;
781 rx_desc = E1000_RX_DESC(*rx_ring, i);
782 buffer_info = &rx_ring->buffer_info[i];
783
784 while (rx_desc->status & E1000_RXD_STAT_DD) {
785 struct sk_buff *skb;
786 u8 status;
787
788 if (*work_done >= work_to_do)
789 break;
790 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000791 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700792
793 status = rx_desc->status;
794 skb = buffer_info->skb;
795 buffer_info->skb = NULL;
796
797 prefetch(skb->data - NET_IP_ALIGN);
798
799 i++;
800 if (i == rx_ring->count)
801 i = 0;
802 next_rxd = E1000_RX_DESC(*rx_ring, i);
803 prefetch(next_rxd);
804
805 next_buffer = &rx_ring->buffer_info[i];
806
807 cleaned = 1;
808 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000809 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810 buffer_info->dma,
811 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000812 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700813 buffer_info->dma = 0;
814
815 length = le16_to_cpu(rx_desc->length);
816
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000817 /*
818 * !EOP means multiple descriptors were used to store a single
819 * packet, if that's the case we need to toss it. In fact, we
820 * need to toss every packet with the EOP bit clear and the
821 * next frame that _does_ have the EOP bit set, as it is by
822 * definition only a frame fragment
823 */
824 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
825 adapter->flags2 |= FLAG2_IS_DISCARDING;
826
827 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700828 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000829 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700830 /* recycle */
831 buffer_info->skb = skb;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000832 if (status & E1000_RXD_STAT_EOP)
833 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700834 goto next_desc;
835 }
836
837 if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
838 /* recycle */
839 buffer_info->skb = skb;
840 goto next_desc;
841 }
842
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000843 /* adjust length to remove Ethernet CRC */
844 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
845 length -= 4;
846
Auke Kokbc7f75f2007-09-17 12:30:59 -0700847 total_rx_bytes += length;
848 total_rx_packets++;
849
Bruce Allanad680762008-03-28 09:15:03 -0700850 /*
851 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700853 * of reassembly being done in the stack
854 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700855 if (length < copybreak) {
856 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000857 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700858 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700859 skb_copy_to_linear_data_offset(new_skb,
860 -NET_IP_ALIGN,
861 (skb->data -
862 NET_IP_ALIGN),
863 (length +
864 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700865 /* save the skb in buffer_info as good */
866 buffer_info->skb = skb;
867 skb = new_skb;
868 }
869 /* else just continue with the old one */
870 }
871 /* end copybreak code */
872 skb_put(skb, length);
873
874 /* Receive Checksum Offload */
875 e1000_rx_checksum(adapter,
876 (u32)(status) |
877 ((u32)(rx_desc->errors) << 24),
878 le16_to_cpu(rx_desc->csum), skb);
879
880 e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special);
881
882next_desc:
883 rx_desc->status = 0;
884
885 /* return some buffers to hardware, one at a time is too slow */
886 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
887 adapter->alloc_rx_buf(adapter, cleaned_count);
888 cleaned_count = 0;
889 }
890
891 /* use prefetched values */
892 rx_desc = next_rxd;
893 buffer_info = next_buffer;
894 }
895 rx_ring->next_to_clean = i;
896
897 cleaned_count = e1000_desc_unused(rx_ring);
898 if (cleaned_count)
899 adapter->alloc_rx_buf(adapter, cleaned_count);
900
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700902 adapter->total_rx_packets += total_rx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +0000903 netdev->stats.rx_bytes += total_rx_bytes;
904 netdev->stats.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
Bruce Allan41cec6f2009-11-20 23:28:56 +0000940 e1e_rphy(hw, PHY_STATUS, &phy_status);
941 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
942 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
943
944 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
945
946 /* detected Hardware unit hang */
947 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700948 " TDH <%x>\n"
949 " TDT <%x>\n"
950 " next_to_use <%x>\n"
951 " next_to_clean <%x>\n"
952 "buffer_info[next_to_clean]:\n"
953 " time_stamp <%lx>\n"
954 " next_to_watch <%x>\n"
955 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +0000956 " next_to_watch.status <%x>\n"
957 "MAC Status <%x>\n"
958 "PHY Status <%x>\n"
959 "PHY 1000BASE-T Status <%x>\n"
960 "PHY Extended Status <%x>\n"
961 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700962 readl(adapter->hw.hw_addr + tx_ring->head),
963 readl(adapter->hw.hw_addr + tx_ring->tail),
964 tx_ring->next_to_use,
965 tx_ring->next_to_clean,
966 tx_ring->buffer_info[eop].time_stamp,
967 eop,
968 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +0000969 eop_desc->upper.fields.status,
970 er32(STATUS),
971 phy_status,
972 phy_1000t_status,
973 phy_ext_status,
974 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700975}
976
977/**
978 * e1000_clean_tx_irq - Reclaim resources after transmit completes
979 * @adapter: board private structure
980 *
981 * the return value indicates whether actual cleaning was done, there
982 * is no guarantee that everything was cleaned
983 **/
984static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
985{
986 struct net_device *netdev = adapter->netdev;
987 struct e1000_hw *hw = &adapter->hw;
988 struct e1000_ring *tx_ring = adapter->tx_ring;
989 struct e1000_tx_desc *tx_desc, *eop_desc;
990 struct e1000_buffer *buffer_info;
991 unsigned int i, eop;
992 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700993 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
994
995 i = tx_ring->next_to_clean;
996 eop = tx_ring->buffer_info[i].next_to_watch;
997 eop_desc = E1000_TX_DESC(*tx_ring, eop);
998
Alexander Duyck12d04a32009-03-25 22:05:03 +0000999 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1000 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001001 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001002 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001003 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001004 tx_desc = E1000_TX_DESC(*tx_ring, i);
1005 buffer_info = &tx_ring->buffer_info[i];
1006 cleaned = (i == eop);
1007
1008 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001009 total_tx_packets += buffer_info->segs;
1010 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001011 }
1012
1013 e1000_put_txbuf(adapter, buffer_info);
1014 tx_desc->upper.data = 0;
1015
1016 i++;
1017 if (i == tx_ring->count)
1018 i = 0;
1019 }
1020
Terry Loftindac87612010-04-09 10:29:49 +00001021 if (i == tx_ring->next_to_use)
1022 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023 eop = tx_ring->buffer_info[i].next_to_watch;
1024 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001025 }
1026
1027 tx_ring->next_to_clean = i;
1028
1029#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001030 if (count && netif_carrier_ok(netdev) &&
1031 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001032 /* Make sure that anybody stopping the queue after this
1033 * sees the new next_to_clean.
1034 */
1035 smp_mb();
1036
1037 if (netif_queue_stopped(netdev) &&
1038 !(test_bit(__E1000_DOWN, &adapter->state))) {
1039 netif_wake_queue(netdev);
1040 ++adapter->restart_queue;
1041 }
1042 }
1043
1044 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001045 /*
1046 * Detect a transmit hang in hardware, this serializes the
1047 * check with the clearing of time_stamp and movement of i
1048 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001050 if (tx_ring->buffer_info[i].time_stamp &&
1051 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001052 + (adapter->tx_timeout_factor * HZ)) &&
1053 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001054 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001055 netif_stop_queue(netdev);
1056 }
1057 }
1058 adapter->total_tx_bytes += total_tx_bytes;
1059 adapter->total_tx_packets += total_tx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +00001060 netdev->stats.tx_bytes += total_tx_bytes;
1061 netdev->stats.tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001062 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001063}
1064
1065/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001066 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1067 * @adapter: board private structure
1068 *
1069 * the return value indicates whether actual cleaning was done, there
1070 * is no guarantee that everything was cleaned
1071 **/
1072static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1073 int *work_done, int work_to_do)
1074{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001075 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001076 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1077 struct net_device *netdev = adapter->netdev;
1078 struct pci_dev *pdev = adapter->pdev;
1079 struct e1000_ring *rx_ring = adapter->rx_ring;
1080 struct e1000_buffer *buffer_info, *next_buffer;
1081 struct e1000_ps_page *ps_page;
1082 struct sk_buff *skb;
1083 unsigned int i, j;
1084 u32 length, staterr;
1085 int cleaned_count = 0;
1086 bool cleaned = 0;
1087 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1088
1089 i = rx_ring->next_to_clean;
1090 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1091 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1092 buffer_info = &rx_ring->buffer_info[i];
1093
1094 while (staterr & E1000_RXD_STAT_DD) {
1095 if (*work_done >= work_to_do)
1096 break;
1097 (*work_done)++;
1098 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001099 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001100
1101 /* in the packet split case this is header only */
1102 prefetch(skb->data - NET_IP_ALIGN);
1103
1104 i++;
1105 if (i == rx_ring->count)
1106 i = 0;
1107 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1108 prefetch(next_rxd);
1109
1110 next_buffer = &rx_ring->buffer_info[i];
1111
1112 cleaned = 1;
1113 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001114 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001115 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001116 buffer_info->dma = 0;
1117
Bruce Allanaf667a22010-12-31 06:10:01 +00001118 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001119 if (!(staterr & E1000_RXD_STAT_EOP))
1120 adapter->flags2 |= FLAG2_IS_DISCARDING;
1121
1122 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001123 e_dbg("Packet Split buffers didn't pick up the full "
1124 "packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001125 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001126 if (staterr & E1000_RXD_STAT_EOP)
1127 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128 goto next_desc;
1129 }
1130
1131 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1132 dev_kfree_skb_irq(skb);
1133 goto next_desc;
1134 }
1135
1136 length = le16_to_cpu(rx_desc->wb.middle.length0);
1137
1138 if (!length) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001139 e_dbg("Last part of the packet spanning multiple "
1140 "descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001141 dev_kfree_skb_irq(skb);
1142 goto next_desc;
1143 }
1144
1145 /* Good Receive */
1146 skb_put(skb, length);
1147
1148 {
Bruce Allanad680762008-03-28 09:15:03 -07001149 /*
1150 * this looks ugly, but it seems compiler issues make it
1151 * more efficient than reusing j
1152 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001153 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1154
Bruce Allanad680762008-03-28 09:15:03 -07001155 /*
1156 * page alloc/put takes too long and effects small packet
1157 * throughput, so unsplit small packets and save the alloc/put
1158 * only valid in softirq (napi) context to call kmap_*
1159 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160 if (l1 && (l1 <= copybreak) &&
1161 ((length + l1) <= adapter->rx_ps_bsize0)) {
1162 u8 *vaddr;
1163
Auke Kok47f44e42007-10-25 13:57:44 -07001164 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001165
Bruce Allanad680762008-03-28 09:15:03 -07001166 /*
1167 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001168 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001169 * very long
1170 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001171 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1172 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001173 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1174 memcpy(skb_tail_pointer(skb), vaddr, l1);
1175 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001176 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1177 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001178
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001179 /* remove the CRC */
1180 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1181 l1 -= 4;
1182
Auke Kokbc7f75f2007-09-17 12:30:59 -07001183 skb_put(skb, l1);
1184 goto copydone;
1185 } /* if */
1186 }
1187
1188 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1189 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1190 if (!length)
1191 break;
1192
Auke Kok47f44e42007-10-25 13:57:44 -07001193 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001194 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1195 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001196 ps_page->dma = 0;
1197 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1198 ps_page->page = NULL;
1199 skb->len += length;
1200 skb->data_len += length;
1201 skb->truesize += length;
1202 }
1203
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001204 /* strip the ethernet crc, problem is we're using pages now so
1205 * this whole operation can get a little cpu intensive
1206 */
1207 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1208 pskb_trim(skb, skb->len - 4);
1209
Auke Kokbc7f75f2007-09-17 12:30:59 -07001210copydone:
1211 total_rx_bytes += skb->len;
1212 total_rx_packets++;
1213
1214 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1215 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1216
1217 if (rx_desc->wb.upper.header_status &
1218 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1219 adapter->rx_hdr_split++;
1220
1221 e1000_receive_skb(adapter, netdev, skb,
1222 staterr, rx_desc->wb.middle.vlan);
1223
1224next_desc:
1225 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1226 buffer_info->skb = NULL;
1227
1228 /* return some buffers to hardware, one at a time is too slow */
1229 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
1230 adapter->alloc_rx_buf(adapter, cleaned_count);
1231 cleaned_count = 0;
1232 }
1233
1234 /* use prefetched values */
1235 rx_desc = next_rxd;
1236 buffer_info = next_buffer;
1237
1238 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1239 }
1240 rx_ring->next_to_clean = i;
1241
1242 cleaned_count = e1000_desc_unused(rx_ring);
1243 if (cleaned_count)
1244 adapter->alloc_rx_buf(adapter, cleaned_count);
1245
Auke Kokbc7f75f2007-09-17 12:30:59 -07001246 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001247 adapter->total_rx_packets += total_rx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +00001248 netdev->stats.rx_bytes += total_rx_bytes;
1249 netdev->stats.rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 return cleaned;
1251}
1252
1253/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001254 * e1000_consume_page - helper function
1255 **/
1256static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1257 u16 length)
1258{
1259 bi->page = NULL;
1260 skb->len += length;
1261 skb->data_len += length;
1262 skb->truesize += length;
1263}
1264
1265/**
1266 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1267 * @adapter: board private structure
1268 *
1269 * the return value indicates whether actual cleaning was done, there
1270 * is no guarantee that everything was cleaned
1271 **/
1272
1273static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1274 int *work_done, int work_to_do)
1275{
1276 struct net_device *netdev = adapter->netdev;
1277 struct pci_dev *pdev = adapter->pdev;
1278 struct e1000_ring *rx_ring = adapter->rx_ring;
1279 struct e1000_rx_desc *rx_desc, *next_rxd;
1280 struct e1000_buffer *buffer_info, *next_buffer;
1281 u32 length;
1282 unsigned int i;
1283 int cleaned_count = 0;
1284 bool cleaned = false;
1285 unsigned int total_rx_bytes=0, total_rx_packets=0;
1286
1287 i = rx_ring->next_to_clean;
1288 rx_desc = E1000_RX_DESC(*rx_ring, i);
1289 buffer_info = &rx_ring->buffer_info[i];
1290
1291 while (rx_desc->status & E1000_RXD_STAT_DD) {
1292 struct sk_buff *skb;
1293 u8 status;
1294
1295 if (*work_done >= work_to_do)
1296 break;
1297 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001298 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001299
1300 status = rx_desc->status;
1301 skb = buffer_info->skb;
1302 buffer_info->skb = NULL;
1303
1304 ++i;
1305 if (i == rx_ring->count)
1306 i = 0;
1307 next_rxd = E1000_RX_DESC(*rx_ring, i);
1308 prefetch(next_rxd);
1309
1310 next_buffer = &rx_ring->buffer_info[i];
1311
1312 cleaned = true;
1313 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001314 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1315 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001316 buffer_info->dma = 0;
1317
1318 length = le16_to_cpu(rx_desc->length);
1319
1320 /* errors is only valid for DD + EOP descriptors */
1321 if (unlikely((status & E1000_RXD_STAT_EOP) &&
1322 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
1323 /* recycle both page and skb */
1324 buffer_info->skb = skb;
1325 /* an error means any chain goes out the window
1326 * too */
1327 if (rx_ring->rx_skb_top)
1328 dev_kfree_skb(rx_ring->rx_skb_top);
1329 rx_ring->rx_skb_top = NULL;
1330 goto next_desc;
1331 }
1332
Bruce Allanf0f1a172010-12-11 05:53:32 +00001333#define rxtop (rx_ring->rx_skb_top)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001334 if (!(status & E1000_RXD_STAT_EOP)) {
1335 /* this descriptor is only the beginning (or middle) */
1336 if (!rxtop) {
1337 /* this is the beginning of a chain */
1338 rxtop = skb;
1339 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1340 0, length);
1341 } else {
1342 /* this is the middle of a chain */
1343 skb_fill_page_desc(rxtop,
1344 skb_shinfo(rxtop)->nr_frags,
1345 buffer_info->page, 0, length);
1346 /* re-use the skb, only consumed the page */
1347 buffer_info->skb = skb;
1348 }
1349 e1000_consume_page(buffer_info, rxtop, length);
1350 goto next_desc;
1351 } else {
1352 if (rxtop) {
1353 /* end of the chain */
1354 skb_fill_page_desc(rxtop,
1355 skb_shinfo(rxtop)->nr_frags,
1356 buffer_info->page, 0, length);
1357 /* re-use the current skb, we only consumed the
1358 * page */
1359 buffer_info->skb = skb;
1360 skb = rxtop;
1361 rxtop = NULL;
1362 e1000_consume_page(buffer_info, skb, length);
1363 } else {
1364 /* no chain, got EOP, this buf is the packet
1365 * copybreak to save the put_page/alloc_page */
1366 if (length <= copybreak &&
1367 skb_tailroom(skb) >= length) {
1368 u8 *vaddr;
1369 vaddr = kmap_atomic(buffer_info->page,
1370 KM_SKB_DATA_SOFTIRQ);
1371 memcpy(skb_tail_pointer(skb), vaddr,
1372 length);
1373 kunmap_atomic(vaddr,
1374 KM_SKB_DATA_SOFTIRQ);
1375 /* re-use the page, so don't erase
1376 * buffer_info->page */
1377 skb_put(skb, length);
1378 } else {
1379 skb_fill_page_desc(skb, 0,
1380 buffer_info->page, 0,
1381 length);
1382 e1000_consume_page(buffer_info, skb,
1383 length);
1384 }
1385 }
1386 }
1387
1388 /* Receive Checksum Offload XXX recompute due to CRC strip? */
1389 e1000_rx_checksum(adapter,
1390 (u32)(status) |
1391 ((u32)(rx_desc->errors) << 24),
1392 le16_to_cpu(rx_desc->csum), skb);
1393
1394 /* probably a little skewed due to removing CRC */
1395 total_rx_bytes += skb->len;
1396 total_rx_packets++;
1397
1398 /* eth type trans needs skb->data to point to something */
1399 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001400 e_err("pskb_may_pull failed.\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001401 dev_kfree_skb(skb);
1402 goto next_desc;
1403 }
1404
1405 e1000_receive_skb(adapter, netdev, skb, status,
1406 rx_desc->special);
1407
1408next_desc:
1409 rx_desc->status = 0;
1410
1411 /* return some buffers to hardware, one at a time is too slow */
1412 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
1413 adapter->alloc_rx_buf(adapter, cleaned_count);
1414 cleaned_count = 0;
1415 }
1416
1417 /* use prefetched values */
1418 rx_desc = next_rxd;
1419 buffer_info = next_buffer;
1420 }
1421 rx_ring->next_to_clean = i;
1422
1423 cleaned_count = e1000_desc_unused(rx_ring);
1424 if (cleaned_count)
1425 adapter->alloc_rx_buf(adapter, cleaned_count);
1426
1427 adapter->total_rx_bytes += total_rx_bytes;
1428 adapter->total_rx_packets += total_rx_packets;
Ajit Khaparde7274c202009-10-07 02:44:26 +00001429 netdev->stats.rx_bytes += total_rx_bytes;
1430 netdev->stats.rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001431 return cleaned;
1432}
1433
1434/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001435 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1436 * @adapter: board private structure
1437 **/
1438static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1439{
1440 struct e1000_ring *rx_ring = adapter->rx_ring;
1441 struct e1000_buffer *buffer_info;
1442 struct e1000_ps_page *ps_page;
1443 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001444 unsigned int i, j;
1445
1446 /* Free all the Rx ring sk_buffs */
1447 for (i = 0; i < rx_ring->count; i++) {
1448 buffer_info = &rx_ring->buffer_info[i];
1449 if (buffer_info->dma) {
1450 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001451 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001452 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001453 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001454 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001455 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001456 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001457 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001458 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001459 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001460 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001461 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001462 buffer_info->dma = 0;
1463 }
1464
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001465 if (buffer_info->page) {
1466 put_page(buffer_info->page);
1467 buffer_info->page = NULL;
1468 }
1469
Auke Kokbc7f75f2007-09-17 12:30:59 -07001470 if (buffer_info->skb) {
1471 dev_kfree_skb(buffer_info->skb);
1472 buffer_info->skb = NULL;
1473 }
1474
1475 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001476 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001477 if (!ps_page->page)
1478 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001479 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1480 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001481 ps_page->dma = 0;
1482 put_page(ps_page->page);
1483 ps_page->page = NULL;
1484 }
1485 }
1486
1487 /* there also may be some cached data from a chained receive */
1488 if (rx_ring->rx_skb_top) {
1489 dev_kfree_skb(rx_ring->rx_skb_top);
1490 rx_ring->rx_skb_top = NULL;
1491 }
1492
Auke Kokbc7f75f2007-09-17 12:30:59 -07001493 /* Zero out the descriptor ring */
1494 memset(rx_ring->desc, 0, rx_ring->size);
1495
1496 rx_ring->next_to_clean = 0;
1497 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001498 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001499
1500 writel(0, adapter->hw.hw_addr + rx_ring->head);
1501 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1502}
1503
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001504static void e1000e_downshift_workaround(struct work_struct *work)
1505{
1506 struct e1000_adapter *adapter = container_of(work,
1507 struct e1000_adapter, downshift_task);
1508
1509 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))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001854 sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001855 else
1856 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1857 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001858 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001859 netdev);
1860 if (err)
1861 goto out;
1862 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1863 adapter->rx_ring->itr_val = adapter->itr;
1864 vector++;
1865
1866 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -08001867 sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001868 else
1869 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1870 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001871 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001872 netdev);
1873 if (err)
1874 goto out;
1875 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1876 adapter->tx_ring->itr_val = adapter->itr;
1877 vector++;
1878
1879 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001880 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001881 if (err)
1882 goto out;
1883
1884 e1000_configure_msix(adapter);
1885 return 0;
1886out:
1887 return err;
1888}
1889
Bruce Allanf8d59f72008-08-08 18:36:11 -07001890/**
1891 * e1000_request_irq - initialize interrupts
1892 *
1893 * Attempts to configure interrupts using the best available
1894 * capabilities of the hardware and kernel.
1895 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07001896static int e1000_request_irq(struct e1000_adapter *adapter)
1897{
1898 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001899 int err;
1900
Bruce Allan4662e822008-08-26 18:37:06 -07001901 if (adapter->msix_entries) {
1902 err = e1000_request_msix(adapter);
1903 if (!err)
1904 return err;
1905 /* fall back to MSI */
1906 e1000e_reset_interrupt_capability(adapter);
1907 adapter->int_mode = E1000E_INT_MODE_MSI;
1908 e1000e_set_interrupt_capability(adapter);
1909 }
1910 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001911 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07001912 netdev->name, netdev);
1913 if (!err)
1914 return err;
1915
1916 /* fall back to legacy interrupt */
1917 e1000e_reset_interrupt_capability(adapter);
1918 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001919 }
1920
Joe Perchesa0607fd2009-11-18 23:29:17 -08001921 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07001922 netdev->name, netdev);
1923 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07001924 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001925
1926 return err;
1927}
1928
1929static void e1000_free_irq(struct e1000_adapter *adapter)
1930{
1931 struct net_device *netdev = adapter->netdev;
1932
Bruce Allan4662e822008-08-26 18:37:06 -07001933 if (adapter->msix_entries) {
1934 int vector = 0;
1935
1936 free_irq(adapter->msix_entries[vector].vector, netdev);
1937 vector++;
1938
1939 free_irq(adapter->msix_entries[vector].vector, netdev);
1940 vector++;
1941
1942 /* Other Causes interrupt vector */
1943 free_irq(adapter->msix_entries[vector].vector, netdev);
1944 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001945 }
Bruce Allan4662e822008-08-26 18:37:06 -07001946
1947 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001948}
1949
1950/**
1951 * e1000_irq_disable - Mask off interrupt generation on the NIC
1952 **/
1953static void e1000_irq_disable(struct e1000_adapter *adapter)
1954{
1955 struct e1000_hw *hw = &adapter->hw;
1956
Auke Kokbc7f75f2007-09-17 12:30:59 -07001957 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07001958 if (adapter->msix_entries)
1959 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001960 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001961
1962 if (adapter->msix_entries) {
1963 int i;
1964 for (i = 0; i < adapter->num_vectors; i++)
1965 synchronize_irq(adapter->msix_entries[i].vector);
1966 } else {
1967 synchronize_irq(adapter->pdev->irq);
1968 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001969}
1970
1971/**
1972 * e1000_irq_enable - Enable default interrupt generation settings
1973 **/
1974static void e1000_irq_enable(struct e1000_adapter *adapter)
1975{
1976 struct e1000_hw *hw = &adapter->hw;
1977
Bruce Allan4662e822008-08-26 18:37:06 -07001978 if (adapter->msix_entries) {
1979 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
1980 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
1981 } else {
1982 ew32(IMS, IMS_ENABLE_MASK);
1983 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07001984 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001985}
1986
1987/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001988 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07001989 * @adapter: address of board private structure
1990 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001991 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001992 * For ASF and Pass Through versions of f/w this means that
1993 * the driver is loaded. For AMT version (only with 82573)
1994 * of the f/w this means that the network i/f is open.
1995 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001996void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001997{
1998 struct e1000_hw *hw = &adapter->hw;
1999 u32 ctrl_ext;
2000 u32 swsm;
2001
2002 /* Let firmware know the driver has taken over */
2003 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2004 swsm = er32(SWSM);
2005 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2006 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2007 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002008 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002009 }
2010}
2011
2012/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002013 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002014 * @adapter: address of board private structure
2015 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002016 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002017 * For ASF and Pass Through versions of f/w this means that the
2018 * driver is no longer loaded. For AMT version (only with 82573) i
2019 * of the f/w this means that the network i/f is closed.
2020 *
2021 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002022void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002023{
2024 struct e1000_hw *hw = &adapter->hw;
2025 u32 ctrl_ext;
2026 u32 swsm;
2027
2028 /* Let firmware taken over control of h/w */
2029 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2030 swsm = er32(SWSM);
2031 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2032 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2033 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002034 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002035 }
2036}
2037
Auke Kokbc7f75f2007-09-17 12:30:59 -07002038/**
2039 * @e1000_alloc_ring - allocate memory for a ring structure
2040 **/
2041static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2042 struct e1000_ring *ring)
2043{
2044 struct pci_dev *pdev = adapter->pdev;
2045
2046 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2047 GFP_KERNEL);
2048 if (!ring->desc)
2049 return -ENOMEM;
2050
2051 return 0;
2052}
2053
2054/**
2055 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2056 * @adapter: board private structure
2057 *
2058 * Return 0 on success, negative on failure
2059 **/
2060int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2061{
2062 struct e1000_ring *tx_ring = adapter->tx_ring;
2063 int err = -ENOMEM, size;
2064
2065 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002066 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002067 if (!tx_ring->buffer_info)
2068 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002069
2070 /* round up to nearest 4K */
2071 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2072 tx_ring->size = ALIGN(tx_ring->size, 4096);
2073
2074 err = e1000_alloc_ring_dma(adapter, tx_ring);
2075 if (err)
2076 goto err;
2077
2078 tx_ring->next_to_use = 0;
2079 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002080
2081 return 0;
2082err:
2083 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002084 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002085 return err;
2086}
2087
2088/**
2089 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2090 * @adapter: board private structure
2091 *
2092 * Returns 0 on success, negative on failure
2093 **/
2094int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2095{
2096 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002097 struct e1000_buffer *buffer_info;
2098 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002099
2100 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002101 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002102 if (!rx_ring->buffer_info)
2103 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002104
Auke Kok47f44e42007-10-25 13:57:44 -07002105 for (i = 0; i < rx_ring->count; i++) {
2106 buffer_info = &rx_ring->buffer_info[i];
2107 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2108 sizeof(struct e1000_ps_page),
2109 GFP_KERNEL);
2110 if (!buffer_info->ps_pages)
2111 goto err_pages;
2112 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002113
2114 desc_len = sizeof(union e1000_rx_desc_packet_split);
2115
2116 /* Round up to nearest 4K */
2117 rx_ring->size = rx_ring->count * desc_len;
2118 rx_ring->size = ALIGN(rx_ring->size, 4096);
2119
2120 err = e1000_alloc_ring_dma(adapter, rx_ring);
2121 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002122 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002123
2124 rx_ring->next_to_clean = 0;
2125 rx_ring->next_to_use = 0;
2126 rx_ring->rx_skb_top = NULL;
2127
2128 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002129
2130err_pages:
2131 for (i = 0; i < rx_ring->count; i++) {
2132 buffer_info = &rx_ring->buffer_info[i];
2133 kfree(buffer_info->ps_pages);
2134 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002135err:
2136 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002137 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002138 return err;
2139}
2140
2141/**
2142 * e1000_clean_tx_ring - Free Tx Buffers
2143 * @adapter: board private structure
2144 **/
2145static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2146{
2147 struct e1000_ring *tx_ring = adapter->tx_ring;
2148 struct e1000_buffer *buffer_info;
2149 unsigned long size;
2150 unsigned int i;
2151
2152 for (i = 0; i < tx_ring->count; i++) {
2153 buffer_info = &tx_ring->buffer_info[i];
2154 e1000_put_txbuf(adapter, buffer_info);
2155 }
2156
2157 size = sizeof(struct e1000_buffer) * tx_ring->count;
2158 memset(tx_ring->buffer_info, 0, size);
2159
2160 memset(tx_ring->desc, 0, tx_ring->size);
2161
2162 tx_ring->next_to_use = 0;
2163 tx_ring->next_to_clean = 0;
2164
2165 writel(0, adapter->hw.hw_addr + tx_ring->head);
2166 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2167}
2168
2169/**
2170 * e1000e_free_tx_resources - Free Tx Resources per Queue
2171 * @adapter: board private structure
2172 *
2173 * Free all transmit software resources
2174 **/
2175void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2176{
2177 struct pci_dev *pdev = adapter->pdev;
2178 struct e1000_ring *tx_ring = adapter->tx_ring;
2179
2180 e1000_clean_tx_ring(adapter);
2181
2182 vfree(tx_ring->buffer_info);
2183 tx_ring->buffer_info = NULL;
2184
2185 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2186 tx_ring->dma);
2187 tx_ring->desc = NULL;
2188}
2189
2190/**
2191 * e1000e_free_rx_resources - Free Rx Resources
2192 * @adapter: board private structure
2193 *
2194 * Free all receive software resources
2195 **/
2196
2197void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2198{
2199 struct pci_dev *pdev = adapter->pdev;
2200 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002201 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002202
2203 e1000_clean_rx_ring(adapter);
2204
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002205 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002206 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002207
Auke Kokbc7f75f2007-09-17 12:30:59 -07002208 vfree(rx_ring->buffer_info);
2209 rx_ring->buffer_info = NULL;
2210
Auke Kokbc7f75f2007-09-17 12:30:59 -07002211 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2212 rx_ring->dma);
2213 rx_ring->desc = NULL;
2214}
2215
2216/**
2217 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002218 * @adapter: pointer to adapter
2219 * @itr_setting: current adapter->itr
2220 * @packets: the number of packets during this measurement interval
2221 * @bytes: the number of bytes during this measurement interval
2222 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002223 * Stores a new ITR value based on packets and byte
2224 * counts during the last interrupt. The advantage of per interrupt
2225 * computation is faster updates and more accurate ITR for the current
2226 * traffic pattern. Constants in this function were computed
2227 * based on theoretical maximum wire speed and thresholds were set based
2228 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002229 * while increasing bulk throughput. This functionality is controlled
2230 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002231 **/
2232static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2233 u16 itr_setting, int packets,
2234 int bytes)
2235{
2236 unsigned int retval = itr_setting;
2237
2238 if (packets == 0)
2239 goto update_itr_done;
2240
2241 switch (itr_setting) {
2242 case lowest_latency:
2243 /* handle TSO and jumbo frames */
2244 if (bytes/packets > 8000)
2245 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002246 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002247 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002248 break;
2249 case low_latency: /* 50 usec aka 20000 ints/s */
2250 if (bytes > 10000) {
2251 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002252 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002254 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002255 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002256 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002257 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002258 } else if (bytes/packets > 2000) {
2259 retval = bulk_latency;
2260 } else if (packets <= 2 && bytes < 512) {
2261 retval = lowest_latency;
2262 }
2263 break;
2264 case bulk_latency: /* 250 usec aka 4000 ints/s */
2265 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002266 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002267 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002268 } else if (bytes < 6000) {
2269 retval = low_latency;
2270 }
2271 break;
2272 }
2273
2274update_itr_done:
2275 return retval;
2276}
2277
2278static void e1000_set_itr(struct e1000_adapter *adapter)
2279{
2280 struct e1000_hw *hw = &adapter->hw;
2281 u16 current_itr;
2282 u32 new_itr = adapter->itr;
2283
2284 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2285 if (adapter->link_speed != SPEED_1000) {
2286 current_itr = 0;
2287 new_itr = 4000;
2288 goto set_itr_now;
2289 }
2290
Bruce Allan828bac82010-09-29 21:39:37 +00002291 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2292 new_itr = 0;
2293 goto set_itr_now;
2294 }
2295
Auke Kokbc7f75f2007-09-17 12:30:59 -07002296 adapter->tx_itr = e1000_update_itr(adapter,
2297 adapter->tx_itr,
2298 adapter->total_tx_packets,
2299 adapter->total_tx_bytes);
2300 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2301 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2302 adapter->tx_itr = low_latency;
2303
2304 adapter->rx_itr = e1000_update_itr(adapter,
2305 adapter->rx_itr,
2306 adapter->total_rx_packets,
2307 adapter->total_rx_bytes);
2308 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2309 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2310 adapter->rx_itr = low_latency;
2311
2312 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2313
2314 switch (current_itr) {
2315 /* counts and packets in update_itr are dependent on these numbers */
2316 case lowest_latency:
2317 new_itr = 70000;
2318 break;
2319 case low_latency:
2320 new_itr = 20000; /* aka hwitr = ~200 */
2321 break;
2322 case bulk_latency:
2323 new_itr = 4000;
2324 break;
2325 default:
2326 break;
2327 }
2328
2329set_itr_now:
2330 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002331 /*
2332 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002334 * increasing
2335 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002336 new_itr = new_itr > adapter->itr ?
2337 min(adapter->itr + (new_itr >> 2), new_itr) :
2338 new_itr;
2339 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002340 adapter->rx_ring->itr_val = new_itr;
2341 if (adapter->msix_entries)
2342 adapter->rx_ring->set_itr = 1;
2343 else
Bruce Allan828bac82010-09-29 21:39:37 +00002344 if (new_itr)
2345 ew32(ITR, 1000000000 / (new_itr * 256));
2346 else
2347 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002348 }
2349}
2350
2351/**
Bruce Allan4662e822008-08-26 18:37:06 -07002352 * e1000_alloc_queues - Allocate memory for all rings
2353 * @adapter: board private structure to initialize
2354 **/
2355static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2356{
2357 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2358 if (!adapter->tx_ring)
2359 goto err;
2360
2361 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2362 if (!adapter->rx_ring)
2363 goto err;
2364
2365 return 0;
2366err:
2367 e_err("Unable to allocate memory for queues\n");
2368 kfree(adapter->rx_ring);
2369 kfree(adapter->tx_ring);
2370 return -ENOMEM;
2371}
2372
2373/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002374 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002375 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002376 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002377 **/
2378static int e1000_clean(struct napi_struct *napi, int budget)
2379{
2380 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002381 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002383 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384
Wang Chen4cf16532008-11-12 23:38:14 -08002385 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002386
Bruce Allan4662e822008-08-26 18:37:06 -07002387 if (adapter->msix_entries &&
2388 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2389 goto clean_rx;
2390
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002391 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002392
Bruce Allan4662e822008-08-26 18:37:06 -07002393clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002394 adapter->clean_rx(adapter, &work_done, budget);
2395
Alexander Duyck12d04a32009-03-25 22:05:03 +00002396 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002397 work_done = budget;
2398
David S. Miller53e52c72008-01-07 21:06:12 -08002399 /* If budget not fully consumed, exit the polling mode */
2400 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002401 if (adapter->itr_setting & 3)
2402 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002403 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002404 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2405 if (adapter->msix_entries)
2406 ew32(IMS, adapter->rx_ring->ims_val);
2407 else
2408 e1000_irq_enable(adapter);
2409 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410 }
2411
2412 return work_done;
2413}
2414
2415static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2416{
2417 struct e1000_adapter *adapter = netdev_priv(netdev);
2418 struct e1000_hw *hw = &adapter->hw;
2419 u32 vfta, index;
2420
2421 /* don't update vlan cookie if already programmed */
2422 if ((adapter->hw.mng_cookie.status &
2423 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2424 (vid == adapter->mng_vlan_id))
2425 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002426
Auke Kokbc7f75f2007-09-17 12:30:59 -07002427 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002428 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2429 index = (vid >> 5) & 0x7F;
2430 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2431 vfta |= (1 << (vid & 0x1F));
2432 hw->mac.ops.write_vfta(hw, index, vfta);
2433 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434}
2435
2436static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2437{
2438 struct e1000_adapter *adapter = netdev_priv(netdev);
2439 struct e1000_hw *hw = &adapter->hw;
2440 u32 vfta, index;
2441
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002442 if (!test_bit(__E1000_DOWN, &adapter->state))
2443 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002444 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002445
2446 if (!test_bit(__E1000_DOWN, &adapter->state))
2447 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002448
2449 if ((adapter->hw.mng_cookie.status &
2450 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2451 (vid == adapter->mng_vlan_id)) {
2452 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002453 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 return;
2455 }
2456
2457 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002458 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2459 index = (vid >> 5) & 0x7F;
2460 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2461 vfta &= ~(1 << (vid & 0x1F));
2462 hw->mac.ops.write_vfta(hw, index, vfta);
2463 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002464}
2465
2466static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2467{
2468 struct net_device *netdev = adapter->netdev;
2469 u16 vid = adapter->hw.mng_cookie.vlan_id;
2470 u16 old_vid = adapter->mng_vlan_id;
2471
2472 if (!adapter->vlgrp)
2473 return;
2474
2475 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
2476 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2477 if (adapter->hw.mng_cookie.status &
2478 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2479 e1000_vlan_rx_add_vid(netdev, vid);
2480 adapter->mng_vlan_id = vid;
2481 }
2482
2483 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
2484 (vid != old_vid) &&
2485 !vlan_group_get_device(adapter->vlgrp, old_vid))
2486 e1000_vlan_rx_kill_vid(netdev, old_vid);
2487 } else {
2488 adapter->mng_vlan_id = vid;
2489 }
2490}
2491
2492
2493static void e1000_vlan_rx_register(struct net_device *netdev,
2494 struct vlan_group *grp)
2495{
2496 struct e1000_adapter *adapter = netdev_priv(netdev);
2497 struct e1000_hw *hw = &adapter->hw;
2498 u32 ctrl, rctl;
2499
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002500 if (!test_bit(__E1000_DOWN, &adapter->state))
2501 e1000_irq_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502 adapter->vlgrp = grp;
2503
2504 if (grp) {
2505 /* enable VLAN tag insert/strip */
2506 ctrl = er32(CTRL);
2507 ctrl |= E1000_CTRL_VME;
2508 ew32(CTRL, ctrl);
2509
2510 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2511 /* enable VLAN receive filtering */
2512 rctl = er32(RCTL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002513 rctl &= ~E1000_RCTL_CFIEN;
2514 ew32(RCTL, rctl);
2515 e1000_update_mng_vlan(adapter);
2516 }
2517 } else {
2518 /* disable VLAN tag insert/strip */
2519 ctrl = er32(CTRL);
2520 ctrl &= ~E1000_CTRL_VME;
2521 ew32(CTRL, ctrl);
2522
2523 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002524 if (adapter->mng_vlan_id !=
2525 (u16)E1000_MNG_VLAN_NONE) {
2526 e1000_vlan_rx_kill_vid(netdev,
2527 adapter->mng_vlan_id);
2528 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2529 }
2530 }
2531 }
2532
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002533 if (!test_bit(__E1000_DOWN, &adapter->state))
2534 e1000_irq_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002535}
2536
2537static void e1000_restore_vlan(struct e1000_adapter *adapter)
2538{
2539 u16 vid;
2540
2541 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2542
2543 if (!adapter->vlgrp)
2544 return;
2545
Jesse Grossb7381272010-10-20 13:56:02 +00002546 for (vid = 0; vid < VLAN_N_VID; vid++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002547 if (!vlan_group_get_device(adapter->vlgrp, vid))
2548 continue;
2549 e1000_vlan_rx_add_vid(adapter->netdev, vid);
2550 }
2551}
2552
Bruce Allancd791612010-05-10 14:59:51 +00002553static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002554{
2555 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002556 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002557
2558 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2559 return;
2560
2561 manc = er32(MANC);
2562
Bruce Allanad680762008-03-28 09:15:03 -07002563 /*
2564 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002565 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002566 * the packets will be handled on SMBUS
2567 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002568 manc |= E1000_MANC_EN_MNG2HOST;
2569 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002570
2571 switch (hw->mac.type) {
2572 default:
2573 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2574 break;
2575 case e1000_82574:
2576 case e1000_82583:
2577 /*
2578 * Check if IPMI pass-through decision filter already exists;
2579 * if so, enable it.
2580 */
2581 for (i = 0, j = 0; i < 8; i++) {
2582 mdef = er32(MDEF(i));
2583
2584 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002585 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002586 continue;
2587
2588 /* Enable this decision filter in MANC2H */
2589 if (mdef)
2590 manc2h |= (1 << i);
2591
2592 j |= mdef;
2593 }
2594
2595 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2596 break;
2597
2598 /* Create new decision filter in an empty filter */
2599 for (i = 0, j = 0; i < 8; i++)
2600 if (er32(MDEF(i)) == 0) {
2601 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2602 E1000_MDEF_PORT_664));
2603 manc2h |= (1 << 1);
2604 j++;
2605 break;
2606 }
2607
2608 if (!j)
2609 e_warn("Unable to create IPMI pass-through filter\n");
2610 break;
2611 }
2612
Auke Kokbc7f75f2007-09-17 12:30:59 -07002613 ew32(MANC2H, manc2h);
2614 ew32(MANC, manc);
2615}
2616
2617/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002618 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002619 * @adapter: board private structure
2620 *
2621 * Configure the Tx unit of the MAC after a reset.
2622 **/
2623static void e1000_configure_tx(struct e1000_adapter *adapter)
2624{
2625 struct e1000_hw *hw = &adapter->hw;
2626 struct e1000_ring *tx_ring = adapter->tx_ring;
2627 u64 tdba;
2628 u32 tdlen, tctl, tipg, tarc;
2629 u32 ipgr1, ipgr2;
2630
2631 /* Setup the HW Tx Head and Tail descriptor pointers */
2632 tdba = tx_ring->dma;
2633 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002634 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002635 ew32(TDBAH, (tdba >> 32));
2636 ew32(TDLEN, tdlen);
2637 ew32(TDH, 0);
2638 ew32(TDT, 0);
2639 tx_ring->head = E1000_TDH;
2640 tx_ring->tail = E1000_TDT;
2641
2642 /* Set the default values for the Tx Inter Packet Gap timer */
2643 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2644 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2645 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2646
2647 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2648 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2649
2650 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2651 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2652 ew32(TIPG, tipg);
2653
2654 /* Set the Tx Interrupt Delay register */
2655 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002656 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002657 ew32(TADV, adapter->tx_abs_int_delay);
2658
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002659 if (adapter->flags2 & FLAG2_DMA_BURST) {
2660 u32 txdctl = er32(TXDCTL(0));
2661 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2662 E1000_TXDCTL_WTHRESH);
2663 /*
2664 * set up some performance related parameters to encourage the
2665 * hardware to use the bus more efficiently in bursts, depends
2666 * on the tx_int_delay to be enabled,
2667 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2668 * hthresh = 1 ==> prefetch when one or more available
2669 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2670 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002671 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002672 */
2673 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2674 ew32(TXDCTL(0), txdctl);
2675 /* erratum work around: set txdctl the same for both queues */
2676 ew32(TXDCTL(1), txdctl);
2677 }
2678
Auke Kokbc7f75f2007-09-17 12:30:59 -07002679 /* Program the Transmit Control Register */
2680 tctl = er32(TCTL);
2681 tctl &= ~E1000_TCTL_CT;
2682 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2683 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2684
2685 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002686 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002687 /*
2688 * set the speed mode bit, we'll clear it if we're not at
2689 * gigabit link later
2690 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002691#define SPEED_MODE_BIT (1 << 21)
2692 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002693 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694 }
2695
2696 /* errata: program both queues to unweighted RR */
2697 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002698 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002699 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002700 ew32(TARC(0), tarc);
2701 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002702 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002703 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002704 }
2705
Auke Kokbc7f75f2007-09-17 12:30:59 -07002706 /* Setup Transmit Descriptor Settings for eop descriptor */
2707 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2708
2709 /* only set IDE if we are delaying interrupts using the timers */
2710 if (adapter->tx_int_delay)
2711 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2712
2713 /* enable Report Status bit */
2714 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2715
2716 ew32(TCTL, tctl);
2717
Simon Hormanedfea6e62009-06-08 14:28:36 +00002718 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002719}
2720
2721/**
2722 * e1000_setup_rctl - configure the receive control registers
2723 * @adapter: Board private structure
2724 **/
2725#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2726 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2727static void e1000_setup_rctl(struct e1000_adapter *adapter)
2728{
2729 struct e1000_hw *hw = &adapter->hw;
2730 u32 rctl, rfctl;
2731 u32 psrctl = 0;
2732 u32 pages = 0;
2733
Bruce Allana1ce6472010-09-22 17:16:40 +00002734 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2735 if (hw->mac.type == e1000_pch2lan) {
2736 s32 ret_val;
2737
2738 if (adapter->netdev->mtu > ETH_DATA_LEN)
2739 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2740 else
2741 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002742
2743 if (ret_val)
2744 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002745 }
2746
Auke Kokbc7f75f2007-09-17 12:30:59 -07002747 /* Program MC offset vector base */
2748 rctl = er32(RCTL);
2749 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2750 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2751 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2752 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2753
2754 /* Do not Store bad packets */
2755 rctl &= ~E1000_RCTL_SBP;
2756
2757 /* Enable Long Packet receive */
2758 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2759 rctl &= ~E1000_RCTL_LPE;
2760 else
2761 rctl |= E1000_RCTL_LPE;
2762
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002763 /* Some systems expect that the CRC is included in SMBUS traffic. The
2764 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2765 * host memory when this is enabled
2766 */
2767 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2768 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002769
Bruce Allana4f58f52009-06-02 11:29:18 +00002770 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2771 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2772 u16 phy_data;
2773
2774 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2775 phy_data &= 0xfff8;
2776 phy_data |= (1 << 2);
2777 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2778
2779 e1e_rphy(hw, 22, &phy_data);
2780 phy_data &= 0x0fff;
2781 phy_data |= (1 << 14);
2782 e1e_wphy(hw, 0x10, 0x2823);
2783 e1e_wphy(hw, 0x11, 0x0003);
2784 e1e_wphy(hw, 22, phy_data);
2785 }
2786
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787 /* Setup buffer sizes */
2788 rctl &= ~E1000_RCTL_SZ_4096;
2789 rctl |= E1000_RCTL_BSEX;
2790 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002791 case 2048:
2792 default:
2793 rctl |= E1000_RCTL_SZ_2048;
2794 rctl &= ~E1000_RCTL_BSEX;
2795 break;
2796 case 4096:
2797 rctl |= E1000_RCTL_SZ_4096;
2798 break;
2799 case 8192:
2800 rctl |= E1000_RCTL_SZ_8192;
2801 break;
2802 case 16384:
2803 rctl |= E1000_RCTL_SZ_16384;
2804 break;
2805 }
2806
2807 /*
2808 * 82571 and greater support packet-split where the protocol
2809 * header is placed in skb->data and the packet data is
2810 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2811 * In the case of a non-split, skb->data is linearly filled,
2812 * followed by the page buffers. Therefore, skb->data is
2813 * sized to hold the largest protocol header.
2814 *
2815 * allocations using alloc_page take too long for regular MTU
2816 * so only enable packet split for jumbo frames
2817 *
2818 * Using pages when the page size is greater than 16k wastes
2819 * a lot of memory, since we allocate 3 pages at all times
2820 * per packet.
2821 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002822 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fec2010-06-17 18:59:27 +00002823 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002824 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002825 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002826 else
2827 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002828
2829 if (adapter->rx_ps_pages) {
2830 /* Configure extra packet-split registers */
2831 rfctl = er32(RFCTL);
2832 rfctl |= E1000_RFCTL_EXTEN;
Bruce Allanad680762008-03-28 09:15:03 -07002833 /*
2834 * disable packet split support for IPv6 extension headers,
2835 * because some malformed IPv6 headers can hang the Rx
2836 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002837 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2838 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2839
2840 ew32(RFCTL, rfctl);
2841
Auke Kok140a7482007-10-25 13:57:58 -07002842 /* Enable Packet split descriptors */
2843 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844
2845 psrctl |= adapter->rx_ps_bsize0 >>
2846 E1000_PSRCTL_BSIZE0_SHIFT;
2847
2848 switch (adapter->rx_ps_pages) {
2849 case 3:
2850 psrctl |= PAGE_SIZE <<
2851 E1000_PSRCTL_BSIZE3_SHIFT;
2852 case 2:
2853 psrctl |= PAGE_SIZE <<
2854 E1000_PSRCTL_BSIZE2_SHIFT;
2855 case 1:
2856 psrctl |= PAGE_SIZE >>
2857 E1000_PSRCTL_BSIZE1_SHIFT;
2858 break;
2859 }
2860
2861 ew32(PSRCTL, psrctl);
2862 }
2863
2864 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002865 /* just started the receive unit, no need to restart */
2866 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002867}
2868
2869/**
2870 * e1000_configure_rx - Configure Receive Unit after Reset
2871 * @adapter: board private structure
2872 *
2873 * Configure the Rx unit of the MAC after a reset.
2874 **/
2875static void e1000_configure_rx(struct e1000_adapter *adapter)
2876{
2877 struct e1000_hw *hw = &adapter->hw;
2878 struct e1000_ring *rx_ring = adapter->rx_ring;
2879 u64 rdba;
2880 u32 rdlen, rctl, rxcsum, ctrl_ext;
2881
2882 if (adapter->rx_ps_pages) {
2883 /* this is a 32 byte descriptor */
2884 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002885 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002886 adapter->clean_rx = e1000_clean_rx_irq_ps;
2887 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002888 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
2889 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
2890 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
2891 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002892 } else {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002893 rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002894 adapter->clean_rx = e1000_clean_rx_irq;
2895 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2896 }
2897
2898 /* disable receives while setting up the descriptors */
2899 rctl = er32(RCTL);
2900 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2901 e1e_flush();
2902 msleep(10);
2903
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002904 if (adapter->flags2 & FLAG2_DMA_BURST) {
2905 /*
2906 * set the writeback threshold (only takes effect if the RDTR
2907 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00002908 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002909 * granularity = 01
2910 * wthresh = 04,
2911 * hthresh = 04,
2912 * pthresh = 0x20
2913 */
2914 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
2915 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
2916
2917 /*
2918 * override the delay timers for enabling bursting, only if
2919 * the value was not set by the user via module options
2920 */
2921 if (adapter->rx_int_delay == DEFAULT_RDTR)
2922 adapter->rx_int_delay = BURST_RDTR;
2923 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
2924 adapter->rx_abs_int_delay = BURST_RADV;
2925 }
2926
Auke Kokbc7f75f2007-09-17 12:30:59 -07002927 /* set the Receive Delay Timer Register */
2928 ew32(RDTR, adapter->rx_int_delay);
2929
2930 /* irq moderation */
2931 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00002932 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07002933 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002934
2935 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002936 /* Auto-Mask interrupts upon ICR access */
2937 ctrl_ext |= E1000_CTRL_EXT_IAME;
2938 ew32(IAM, 0xffffffff);
2939 ew32(CTRL_EXT, ctrl_ext);
2940 e1e_flush();
2941
Bruce Allanad680762008-03-28 09:15:03 -07002942 /*
2943 * Setup the HW Rx Head and Tail Descriptor Pointers and
2944 * the Base and Length of the Rx Descriptor Ring
2945 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07002947 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002948 ew32(RDBAH, (rdba >> 32));
2949 ew32(RDLEN, rdlen);
2950 ew32(RDH, 0);
2951 ew32(RDT, 0);
2952 rx_ring->head = E1000_RDH;
2953 rx_ring->tail = E1000_RDT;
2954
2955 /* Enable Receive Checksum Offload for TCP and UDP */
2956 rxcsum = er32(RXCSUM);
2957 if (adapter->flags & FLAG_RX_CSUM_ENABLED) {
2958 rxcsum |= E1000_RXCSUM_TUOFL;
2959
Bruce Allanad680762008-03-28 09:15:03 -07002960 /*
2961 * IPv4 payload checksum for UDP fragments must be
2962 * used in conjunction with packet-split.
2963 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964 if (adapter->rx_ps_pages)
2965 rxcsum |= E1000_RXCSUM_IPPCSE;
2966 } else {
2967 rxcsum &= ~E1000_RXCSUM_TUOFL;
2968 /* no need to clear IPPCSE as it defaults to 0 */
2969 }
2970 ew32(RXCSUM, rxcsum);
2971
Bruce Allanad680762008-03-28 09:15:03 -07002972 /*
2973 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07002974 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07002975 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
2976 */
Bruce Allan828bac82010-09-29 21:39:37 +00002977 if ((adapter->flags & FLAG_HAS_ERT) ||
2978 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00002979 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2980 u32 rxdctl = er32(RXDCTL(0));
2981 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00002982 if (adapter->flags & FLAG_HAS_ERT)
2983 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00002984 /*
2985 * With jumbo frames and early-receive enabled,
2986 * excessive C-state transition latencies result in
2987 * dropped transactions.
2988 */
Bruce Allanaf667a22010-12-31 06:10:01 +00002989 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00002990 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00002991 pm_qos_update_request(&adapter->netdev->pm_qos_req,
2992 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00002993 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002994 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002995
2996 /* Enable Receives */
2997 ew32(RCTL, rctl);
2998}
2999
3000/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003001 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07003002 * @hw: pointer to the HW structure
3003 * @mc_addr_list: array of multicast addresses to program
3004 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07003005 *
Bruce Allanab8932f2010-01-13 02:05:38 +00003006 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003007 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003008 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003009static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003010 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003011{
Bruce Allanab8932f2010-01-13 02:05:38 +00003012 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003013}
3014
3015/**
3016 * e1000_set_multi - Multicast and Promiscuous mode set
3017 * @netdev: network interface device structure
3018 *
3019 * The set_multi entry point is called whenever the multicast address
3020 * list or the network interface flags are updated. This routine is
3021 * responsible for configuring the hardware for proper multicast,
3022 * promiscuous mode, and all-multi behavior.
3023 **/
3024static void e1000_set_multi(struct net_device *netdev)
3025{
3026 struct e1000_adapter *adapter = netdev_priv(netdev);
3027 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003028 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003029 u8 *mta_list;
3030 u32 rctl;
3031 int i;
3032
3033 /* Check for Promiscuous and All Multicast modes */
3034
3035 rctl = er32(RCTL);
3036
3037 if (netdev->flags & IFF_PROMISC) {
3038 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003039 rctl &= ~E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003040 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003041 if (netdev->flags & IFF_ALLMULTI) {
3042 rctl |= E1000_RCTL_MPE;
3043 rctl &= ~E1000_RCTL_UPE;
3044 } else {
3045 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3046 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07003047 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardy746b9f02008-07-16 20:15:45 -07003048 rctl |= E1000_RCTL_VFE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003049 }
3050
3051 ew32(RCTL, rctl);
3052
Jiri Pirko7aeef972010-02-05 02:52:39 +00003053 if (!netdev_mc_empty(netdev)) {
3054 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003055 if (!mta_list)
3056 return;
3057
3058 /* prepare a packed array of only addresses. */
Jiri Pirko7aeef972010-02-05 02:52:39 +00003059 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003060 netdev_for_each_mc_addr(ha, netdev)
3061 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003062
Bruce Allanab8932f2010-01-13 02:05:38 +00003063 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003064 kfree(mta_list);
3065 } else {
3066 /*
3067 * if we're called from probe, we might not have
3068 * anything to do here, so clear out the list
3069 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003070 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003071 }
3072}
3073
3074/**
Bruce Allanad680762008-03-28 09:15:03 -07003075 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003076 * @adapter: private board structure
3077 **/
3078static void e1000_configure(struct e1000_adapter *adapter)
3079{
3080 e1000_set_multi(adapter->netdev);
3081
3082 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003083 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003084
3085 e1000_configure_tx(adapter);
3086 e1000_setup_rctl(adapter);
3087 e1000_configure_rx(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07003088 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003089}
3090
3091/**
3092 * e1000e_power_up_phy - restore link in case the phy was powered down
3093 * @adapter: address of board private structure
3094 *
3095 * The phy may be powered down to save power and turn off link when the
3096 * driver is unloaded and wake on lan is not enabled (among others)
3097 * *** this routine MUST be followed by a call to e1000e_reset ***
3098 **/
3099void e1000e_power_up_phy(struct e1000_adapter *adapter)
3100{
Bruce Allan17f208d2009-12-01 15:47:22 +00003101 if (adapter->hw.phy.ops.power_up)
3102 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003103
3104 adapter->hw.mac.ops.setup_link(&adapter->hw);
3105}
3106
3107/**
3108 * e1000_power_down_phy - Power down the PHY
3109 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003110 * Power down the PHY so no link is implied when interface is down.
3111 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003112 */
3113static void e1000_power_down_phy(struct e1000_adapter *adapter)
3114{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003115 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003116 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003117 return;
3118
Bruce Allan17f208d2009-12-01 15:47:22 +00003119 if (adapter->hw.phy.ops.power_down)
3120 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003121}
3122
3123/**
3124 * e1000e_reset - bring the hardware into a known good state
3125 *
3126 * This function boots the hardware and enables some settings that
3127 * require a configuration cycle of the hardware - those cannot be
3128 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003129 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003130 */
3131void e1000e_reset(struct e1000_adapter *adapter)
3132{
3133 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003134 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003135 struct e1000_hw *hw = &adapter->hw;
3136 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003137 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003138 u16 hwm;
3139
Bruce Allanad680762008-03-28 09:15:03 -07003140 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003141 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003142
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003143 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003144 /*
3145 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146 * large enough to accommodate two full transmit packets,
3147 * rounded up to the next 1KB and expressed in KB. Likewise,
3148 * the Rx FIFO should be large enough to accommodate at least
3149 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003150 * expressed in KB.
3151 */
Auke Kokdf762462007-10-25 13:57:53 -07003152 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003153 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003154 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003155 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003156 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003157 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003158 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003159 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003160 */
3161 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003162 sizeof(struct e1000_tx_desc) -
3163 ETH_FCS_LEN) * 2;
3164 min_tx_space = ALIGN(min_tx_space, 1024);
3165 min_tx_space >>= 10;
3166 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003167 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003168 min_rx_space = ALIGN(min_rx_space, 1024);
3169 min_rx_space >>= 10;
3170
Bruce Allanad680762008-03-28 09:15:03 -07003171 /*
3172 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003173 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003174 * allocation, take space away from current Rx allocation
3175 */
Auke Kokdf762462007-10-25 13:57:53 -07003176 if ((tx_space < min_tx_space) &&
3177 ((min_tx_space - tx_space) < pba)) {
3178 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003179
Bruce Allanad680762008-03-28 09:15:03 -07003180 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003181 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003182 * adjustment or use Early Receive if available
3183 */
Auke Kokdf762462007-10-25 13:57:53 -07003184 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003185 (!(adapter->flags & FLAG_HAS_ERT)))
3186 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003187 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003188 }
Auke Kokdf762462007-10-25 13:57:53 -07003189
3190 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003191 }
3192
Bruce Allanad680762008-03-28 09:15:03 -07003193 /*
3194 * flow control settings
3195 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003196 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003197 * (or the size used for early receive) above it in the Rx FIFO.
3198 * Set it to the lower of:
3199 * - 90% of the Rx FIFO size, and
3200 * - the full Rx FIFO size minus the early receive size (for parts
3201 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003202 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003203 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003204 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3205 fc->pause_time = 0xFFFF;
3206 else
3207 fc->pause_time = E1000_FC_PAUSE_TIME;
3208 fc->send_xon = 1;
3209 fc->current_mode = fc->requested_mode;
3210
3211 switch (hw->mac.type) {
3212 default:
3213 if ((adapter->flags & FLAG_HAS_ERT) &&
3214 (adapter->netdev->mtu > ETH_DATA_LEN))
3215 hwm = min(((pba << 10) * 9 / 10),
3216 ((pba << 10) - (E1000_ERT_2048 << 3)));
3217 else
3218 hwm = min(((pba << 10) * 9 / 10),
3219 ((pba << 10) - adapter->max_frame_size));
3220
3221 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3222 fc->low_water = fc->high_water - 8;
3223 break;
3224 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003225 /*
3226 * Workaround PCH LOM adapter hangs with certain network
3227 * loads. If hangs persist, try disabling Tx flow control.
3228 */
3229 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3230 fc->high_water = 0x3500;
3231 fc->low_water = 0x1500;
3232 } else {
3233 fc->high_water = 0x5000;
3234 fc->low_water = 0x3000;
3235 }
Bruce Allana3055952010-05-10 15:02:12 +00003236 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003237 break;
3238 case e1000_pch2lan:
3239 fc->high_water = 0x05C20;
3240 fc->low_water = 0x05048;
3241 fc->pause_time = 0x0650;
3242 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003243 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3244 pba = 14;
3245 ew32(PBA, pba);
3246 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003247 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003248 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003249
Bruce Allan828bac82010-09-29 21:39:37 +00003250 /*
3251 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3252 * fit in receive buffer and early-receive not supported.
3253 */
3254 if (adapter->itr_setting & 0x3) {
3255 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3256 !(adapter->flags & FLAG_HAS_ERT)) {
3257 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3258 dev_info(&adapter->pdev->dev,
3259 "Interrupt Throttle Rate turned off\n");
3260 adapter->flags2 |= FLAG2_DISABLE_AIM;
3261 ew32(ITR, 0);
3262 }
3263 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3264 dev_info(&adapter->pdev->dev,
3265 "Interrupt Throttle Rate turned on\n");
3266 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3267 adapter->itr = 20000;
3268 ew32(ITR, 1000000000 / (adapter->itr * 256));
3269 }
3270 }
3271
Auke Kokbc7f75f2007-09-17 12:30:59 -07003272 /* Allow time for pending master requests to run */
3273 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003274
3275 /*
3276 * For parts with AMT enabled, let the firmware know
3277 * that the network interface is in control
3278 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003279 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003280 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003281
Auke Kokbc7f75f2007-09-17 12:30:59 -07003282 ew32(WUC, 0);
3283
3284 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003285 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003286
3287 e1000_update_mng_vlan(adapter);
3288
3289 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3290 ew32(VET, ETH_P_8021Q);
3291
3292 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003293
3294 if (!netif_running(adapter->netdev) &&
3295 !test_bit(__E1000_TESTING, &adapter->state)) {
3296 e1000_power_down_phy(adapter);
3297 return;
3298 }
3299
Auke Kokbc7f75f2007-09-17 12:30:59 -07003300 e1000_get_phy_info(hw);
3301
Bruce Allan918d7192009-06-02 11:28:20 +00003302 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3303 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003304 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003305 /*
3306 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003307 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003308 * different we would do if it failed
3309 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003310 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3311 phy_data &= ~IGP02E1000_PM_SPD;
3312 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3313 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003314}
3315
3316int e1000e_up(struct e1000_adapter *adapter)
3317{
3318 struct e1000_hw *hw = &adapter->hw;
3319
3320 /* hardware has been reset, we need to reload some things */
3321 e1000_configure(adapter);
3322
3323 clear_bit(__E1000_DOWN, &adapter->state);
3324
3325 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003326 if (adapter->msix_entries)
3327 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003328 e1000_irq_enable(adapter);
3329
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003330 netif_wake_queue(adapter->netdev);
3331
Auke Kokbc7f75f2007-09-17 12:30:59 -07003332 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003333 if (adapter->msix_entries)
3334 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3335 else
3336 ew32(ICS, E1000_ICS_LSC);
3337
Auke Kokbc7f75f2007-09-17 12:30:59 -07003338 return 0;
3339}
3340
3341void e1000e_down(struct e1000_adapter *adapter)
3342{
3343 struct net_device *netdev = adapter->netdev;
3344 struct e1000_hw *hw = &adapter->hw;
3345 u32 tctl, rctl;
3346
Bruce Allanad680762008-03-28 09:15:03 -07003347 /*
3348 * signal that we're down so the interrupt handler does not
3349 * reschedule our watchdog timer
3350 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003351 set_bit(__E1000_DOWN, &adapter->state);
3352
3353 /* disable receives in the hardware */
3354 rctl = er32(RCTL);
3355 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3356 /* flush and sleep below */
3357
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003358 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003359
3360 /* disable transmits in the hardware */
3361 tctl = er32(TCTL);
3362 tctl &= ~E1000_TCTL_EN;
3363 ew32(TCTL, tctl);
3364 /* flush both disables and wait for them to finish */
3365 e1e_flush();
3366 msleep(10);
3367
3368 napi_disable(&adapter->napi);
3369 e1000_irq_disable(adapter);
3370
3371 del_timer_sync(&adapter->watchdog_timer);
3372 del_timer_sync(&adapter->phy_info_timer);
3373
Auke Kokbc7f75f2007-09-17 12:30:59 -07003374 netif_carrier_off(netdev);
3375 adapter->link_speed = 0;
3376 adapter->link_duplex = 0;
3377
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003378 if (!pci_channel_offline(adapter->pdev))
3379 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003380 e1000_clean_tx_ring(adapter);
3381 e1000_clean_rx_ring(adapter);
3382
3383 /*
3384 * TODO: for power management, we could drop the link and
3385 * pci_disable_device here.
3386 */
3387}
3388
3389void e1000e_reinit_locked(struct e1000_adapter *adapter)
3390{
3391 might_sleep();
3392 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
3393 msleep(1);
3394 e1000e_down(adapter);
3395 e1000e_up(adapter);
3396 clear_bit(__E1000_RESETTING, &adapter->state);
3397}
3398
3399/**
3400 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3401 * @adapter: board private structure to initialize
3402 *
3403 * e1000_sw_init initializes the Adapter private data structure.
3404 * Fields are initialized based on PCI device information and
3405 * OS network device settings (MTU size).
3406 **/
3407static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3408{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003409 struct net_device *netdev = adapter->netdev;
3410
3411 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3412 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003413 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3414 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003415
Bruce Allan4662e822008-08-26 18:37:06 -07003416 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003417
Bruce Allan4662e822008-08-26 18:37:06 -07003418 if (e1000_alloc_queues(adapter))
3419 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003420
Auke Kokbc7f75f2007-09-17 12:30:59 -07003421 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003422 e1000_irq_disable(adapter);
3423
Auke Kokbc7f75f2007-09-17 12:30:59 -07003424 set_bit(__E1000_DOWN, &adapter->state);
3425 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426}
3427
3428/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003429 * e1000_intr_msi_test - Interrupt Handler
3430 * @irq: interrupt number
3431 * @data: pointer to a network interface device structure
3432 **/
3433static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3434{
3435 struct net_device *netdev = data;
3436 struct e1000_adapter *adapter = netdev_priv(netdev);
3437 struct e1000_hw *hw = &adapter->hw;
3438 u32 icr = er32(ICR);
3439
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003440 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003441 if (icr & E1000_ICR_RXSEQ) {
3442 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3443 wmb();
3444 }
3445
3446 return IRQ_HANDLED;
3447}
3448
3449/**
3450 * e1000_test_msi_interrupt - Returns 0 for successful test
3451 * @adapter: board private struct
3452 *
3453 * code flow taken from tg3.c
3454 **/
3455static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3456{
3457 struct net_device *netdev = adapter->netdev;
3458 struct e1000_hw *hw = &adapter->hw;
3459 int err;
3460
3461 /* poll_enable hasn't been called yet, so don't need disable */
3462 /* clear any pending events */
3463 er32(ICR);
3464
3465 /* free the real vector and request a test handler */
3466 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003467 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003468
3469 /* Assume that the test fails, if it succeeds then the test
3470 * MSI irq handler will unset this flag */
3471 adapter->flags |= FLAG_MSI_TEST_FAILED;
3472
3473 err = pci_enable_msi(adapter->pdev);
3474 if (err)
3475 goto msi_test_failed;
3476
Joe Perchesa0607fd2009-11-18 23:29:17 -08003477 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003478 netdev->name, netdev);
3479 if (err) {
3480 pci_disable_msi(adapter->pdev);
3481 goto msi_test_failed;
3482 }
3483
3484 wmb();
3485
3486 e1000_irq_enable(adapter);
3487
3488 /* fire an unusual interrupt on the test handler */
3489 ew32(ICS, E1000_ICS_RXSEQ);
3490 e1e_flush();
3491 msleep(50);
3492
3493 e1000_irq_disable(adapter);
3494
3495 rmb();
3496
3497 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003498 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003499 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3500 } else
3501 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003502
3503 free_irq(adapter->pdev->irq, netdev);
3504 pci_disable_msi(adapter->pdev);
3505
Bruce Allanf8d59f72008-08-08 18:36:11 -07003506msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003507 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003508 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003509}
3510
3511/**
3512 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3513 * @adapter: board private struct
3514 *
3515 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3516 **/
3517static int e1000_test_msi(struct e1000_adapter *adapter)
3518{
3519 int err;
3520 u16 pci_cmd;
3521
3522 if (!(adapter->flags & FLAG_MSI_ENABLED))
3523 return 0;
3524
3525 /* disable SERR in case the MSI write causes a master abort */
3526 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003527 if (pci_cmd & PCI_COMMAND_SERR)
3528 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3529 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003530
3531 err = e1000_test_msi_interrupt(adapter);
3532
Dean Nelson36f24072010-06-29 18:12:05 +00003533 /* re-enable SERR */
3534 if (pci_cmd & PCI_COMMAND_SERR) {
3535 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3536 pci_cmd |= PCI_COMMAND_SERR;
3537 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3538 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003539
Bruce Allanf8d59f72008-08-08 18:36:11 -07003540 return err;
3541}
3542
3543/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003544 * e1000_open - Called when a network interface is made active
3545 * @netdev: network interface device structure
3546 *
3547 * Returns 0 on success, negative value on failure
3548 *
3549 * The open entry point is called when a network interface is made
3550 * active by the system (IFF_UP). At this point all resources needed
3551 * for transmit and receive operations are allocated, the interrupt
3552 * handler is registered with the OS, the watchdog timer is started,
3553 * and the stack is notified that the interface is ready.
3554 **/
3555static int e1000_open(struct net_device *netdev)
3556{
3557 struct e1000_adapter *adapter = netdev_priv(netdev);
3558 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003559 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003560 int err;
3561
3562 /* disallow open during test */
3563 if (test_bit(__E1000_TESTING, &adapter->state))
3564 return -EBUSY;
3565
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003566 pm_runtime_get_sync(&pdev->dev);
3567
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003568 netif_carrier_off(netdev);
3569
Auke Kokbc7f75f2007-09-17 12:30:59 -07003570 /* allocate transmit descriptors */
3571 err = e1000e_setup_tx_resources(adapter);
3572 if (err)
3573 goto err_setup_tx;
3574
3575 /* allocate receive descriptors */
3576 err = e1000e_setup_rx_resources(adapter);
3577 if (err)
3578 goto err_setup_rx;
3579
Bruce Allan11b08be2010-05-10 14:59:31 +00003580 /*
3581 * If AMT is enabled, let the firmware know that the network
3582 * interface is now open and reset the part to a known state.
3583 */
3584 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003585 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003586 e1000e_reset(adapter);
3587 }
3588
Auke Kokbc7f75f2007-09-17 12:30:59 -07003589 e1000e_power_up_phy(adapter);
3590
3591 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3592 if ((adapter->hw.mng_cookie.status &
3593 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3594 e1000_update_mng_vlan(adapter);
3595
Florian Micklerc128ec22010-08-02 14:27:00 +00003596 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003597 if ((adapter->flags & FLAG_HAS_ERT) ||
3598 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003599 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3600 PM_QOS_CPU_DMA_LATENCY,
3601 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003602
Bruce Allanad680762008-03-28 09:15:03 -07003603 /*
Bruce Allanad680762008-03-28 09:15:03 -07003604 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003605 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3606 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003607 * clean_rx handler before we do so.
3608 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003609 e1000_configure(adapter);
3610
3611 err = e1000_request_irq(adapter);
3612 if (err)
3613 goto err_req_irq;
3614
Bruce Allanf8d59f72008-08-08 18:36:11 -07003615 /*
3616 * Work around PCIe errata with MSI interrupts causing some chipsets to
3617 * ignore e1000e MSI messages, which means we need to test our MSI
3618 * interrupt now
3619 */
Bruce Allan4662e822008-08-26 18:37:06 -07003620 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003621 err = e1000_test_msi(adapter);
3622 if (err) {
3623 e_err("Interrupt allocation failed\n");
3624 goto err_req_irq;
3625 }
3626 }
3627
Auke Kokbc7f75f2007-09-17 12:30:59 -07003628 /* From here on the code is the same as e1000e_up() */
3629 clear_bit(__E1000_DOWN, &adapter->state);
3630
3631 napi_enable(&adapter->napi);
3632
3633 e1000_irq_enable(adapter);
3634
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003635 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003636
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003637 adapter->idle_check = true;
3638 pm_runtime_put(&pdev->dev);
3639
Auke Kokbc7f75f2007-09-17 12:30:59 -07003640 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003641 if (adapter->msix_entries)
3642 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3643 else
3644 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003645
3646 return 0;
3647
3648err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003649 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003650 e1000_power_down_phy(adapter);
3651 e1000e_free_rx_resources(adapter);
3652err_setup_rx:
3653 e1000e_free_tx_resources(adapter);
3654err_setup_tx:
3655 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003656 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003657
3658 return err;
3659}
3660
3661/**
3662 * e1000_close - Disables a network interface
3663 * @netdev: network interface device structure
3664 *
3665 * Returns 0, this is not allowed to fail
3666 *
3667 * The close entry point is called when an interface is de-activated
3668 * by the OS. The hardware is still under the drivers control, but
3669 * needs to be disabled. A global MAC reset is issued to stop the
3670 * hardware, and all transmit and receive resources are freed.
3671 **/
3672static int e1000_close(struct net_device *netdev)
3673{
3674 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003675 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003676
3677 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003678
3679 pm_runtime_get_sync(&pdev->dev);
3680
3681 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3682 e1000e_down(adapter);
3683 e1000_free_irq(adapter);
3684 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003685 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003686
3687 e1000e_free_tx_resources(adapter);
3688 e1000e_free_rx_resources(adapter);
3689
Bruce Allanad680762008-03-28 09:15:03 -07003690 /*
3691 * kill manageability vlan ID if supported, but not if a vlan with
3692 * the same ID is registered on the host OS (let 8021q kill it)
3693 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003694 if ((adapter->hw.mng_cookie.status &
3695 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
3696 !(adapter->vlgrp &&
3697 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
3698 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3699
Bruce Allanad680762008-03-28 09:15:03 -07003700 /*
3701 * If AMT is enabled, let the firmware know that the network
3702 * interface is now closed
3703 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003704 if ((adapter->flags & FLAG_HAS_AMT) &&
3705 !test_bit(__E1000_TESTING, &adapter->state))
3706 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003707
Bruce Allan828bac82010-09-29 21:39:37 +00003708 if ((adapter->flags & FLAG_HAS_ERT) ||
3709 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003710 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003711
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003712 pm_runtime_put_sync(&pdev->dev);
3713
Auke Kokbc7f75f2007-09-17 12:30:59 -07003714 return 0;
3715}
3716/**
3717 * e1000_set_mac - Change the Ethernet Address of the NIC
3718 * @netdev: network interface device structure
3719 * @p: pointer to an address structure
3720 *
3721 * Returns 0 on success, negative on failure
3722 **/
3723static int e1000_set_mac(struct net_device *netdev, void *p)
3724{
3725 struct e1000_adapter *adapter = netdev_priv(netdev);
3726 struct sockaddr *addr = p;
3727
3728 if (!is_valid_ether_addr(addr->sa_data))
3729 return -EADDRNOTAVAIL;
3730
3731 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3732 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3733
3734 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3735
3736 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3737 /* activate the work around */
3738 e1000e_set_laa_state_82571(&adapter->hw, 1);
3739
Bruce Allanad680762008-03-28 09:15:03 -07003740 /*
3741 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003742 * between the time RAR[0] gets clobbered and the time it
3743 * gets fixed (in e1000_watchdog), the actual LAA is in one
3744 * of the RARs and no incoming packets directed to this port
3745 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003746 * RAR[14]
3747 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003748 e1000e_rar_set(&adapter->hw,
3749 adapter->hw.mac.addr,
3750 adapter->hw.mac.rar_entry_count - 1);
3751 }
3752
3753 return 0;
3754}
3755
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003756/**
3757 * e1000e_update_phy_task - work thread to update phy
3758 * @work: pointer to our work struct
3759 *
3760 * this worker thread exists because we must acquire a
3761 * semaphore to read the phy, which we could msleep while
3762 * waiting for it, and we can't msleep in a timer.
3763 **/
3764static void e1000e_update_phy_task(struct work_struct *work)
3765{
3766 struct e1000_adapter *adapter = container_of(work,
3767 struct e1000_adapter, update_phy_task);
3768 e1000_get_phy_info(&adapter->hw);
3769}
3770
Bruce Allanad680762008-03-28 09:15:03 -07003771/*
3772 * Need to wait a few seconds after link up to get diagnostic information from
3773 * the phy
3774 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003775static void e1000_update_phy_info(unsigned long data)
3776{
3777 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003778 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003779}
3780
3781/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003782 * e1000e_update_phy_stats - Update the PHY statistics counters
3783 * @adapter: board private structure
3784 **/
3785static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3786{
3787 struct e1000_hw *hw = &adapter->hw;
3788 s32 ret_val;
3789 u16 phy_data;
3790
3791 ret_val = hw->phy.ops.acquire(hw);
3792 if (ret_val)
3793 return;
3794
3795 hw->phy.addr = 1;
3796
3797#define HV_PHY_STATS_PAGE 778
3798 /*
3799 * A page set is expensive so check if already on desired page.
3800 * If not, set to the page with the PHY status registers.
3801 */
3802 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3803 &phy_data);
3804 if (ret_val)
3805 goto release;
3806 if (phy_data != (HV_PHY_STATS_PAGE << IGP_PAGE_SHIFT)) {
3807 ret_val = e1000e_write_phy_reg_mdic(hw,
3808 IGP01E1000_PHY_PAGE_SELECT,
3809 (HV_PHY_STATS_PAGE <<
3810 IGP_PAGE_SHIFT));
3811 if (ret_val)
3812 goto release;
3813 }
3814
3815 /* Read/clear the upper 16-bit registers and read/accumulate lower */
3816
3817 /* Single Collision Count */
3818 e1000e_read_phy_reg_mdic(hw, HV_SCC_UPPER & MAX_PHY_REG_ADDRESS,
3819 &phy_data);
3820 ret_val = e1000e_read_phy_reg_mdic(hw,
3821 HV_SCC_LOWER & MAX_PHY_REG_ADDRESS,
3822 &phy_data);
3823 if (!ret_val)
3824 adapter->stats.scc += phy_data;
3825
3826 /* Excessive Collision Count */
3827 e1000e_read_phy_reg_mdic(hw, HV_ECOL_UPPER & MAX_PHY_REG_ADDRESS,
3828 &phy_data);
3829 ret_val = e1000e_read_phy_reg_mdic(hw,
3830 HV_ECOL_LOWER & MAX_PHY_REG_ADDRESS,
3831 &phy_data);
3832 if (!ret_val)
3833 adapter->stats.ecol += phy_data;
3834
3835 /* Multiple Collision Count */
3836 e1000e_read_phy_reg_mdic(hw, HV_MCC_UPPER & MAX_PHY_REG_ADDRESS,
3837 &phy_data);
3838 ret_val = e1000e_read_phy_reg_mdic(hw,
3839 HV_MCC_LOWER & MAX_PHY_REG_ADDRESS,
3840 &phy_data);
3841 if (!ret_val)
3842 adapter->stats.mcc += phy_data;
3843
3844 /* Late Collision Count */
3845 e1000e_read_phy_reg_mdic(hw, HV_LATECOL_UPPER & MAX_PHY_REG_ADDRESS,
3846 &phy_data);
3847 ret_val = e1000e_read_phy_reg_mdic(hw,
3848 HV_LATECOL_LOWER &
3849 MAX_PHY_REG_ADDRESS,
3850 &phy_data);
3851 if (!ret_val)
3852 adapter->stats.latecol += phy_data;
3853
3854 /* Collision Count - also used for adaptive IFS */
3855 e1000e_read_phy_reg_mdic(hw, HV_COLC_UPPER & MAX_PHY_REG_ADDRESS,
3856 &phy_data);
3857 ret_val = e1000e_read_phy_reg_mdic(hw,
3858 HV_COLC_LOWER & MAX_PHY_REG_ADDRESS,
3859 &phy_data);
3860 if (!ret_val)
3861 hw->mac.collision_delta = phy_data;
3862
3863 /* Defer Count */
3864 e1000e_read_phy_reg_mdic(hw, HV_DC_UPPER & MAX_PHY_REG_ADDRESS,
3865 &phy_data);
3866 ret_val = e1000e_read_phy_reg_mdic(hw,
3867 HV_DC_LOWER & MAX_PHY_REG_ADDRESS,
3868 &phy_data);
3869 if (!ret_val)
3870 adapter->stats.dc += phy_data;
3871
3872 /* Transmit with no CRS */
3873 e1000e_read_phy_reg_mdic(hw, HV_TNCRS_UPPER & MAX_PHY_REG_ADDRESS,
3874 &phy_data);
3875 ret_val = e1000e_read_phy_reg_mdic(hw,
3876 HV_TNCRS_LOWER & MAX_PHY_REG_ADDRESS,
3877 &phy_data);
3878 if (!ret_val)
3879 adapter->stats.tncrs += phy_data;
3880
3881release:
3882 hw->phy.ops.release(hw);
3883}
3884
3885/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003886 * e1000e_update_stats - Update the board statistics counters
3887 * @adapter: board private structure
3888 **/
3889void e1000e_update_stats(struct e1000_adapter *adapter)
3890{
Ajit Khaparde7274c202009-10-07 02:44:26 +00003891 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003892 struct e1000_hw *hw = &adapter->hw;
3893 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003894
3895 /*
3896 * Prevent stats update while adapter is being reset, or if the pci
3897 * connection is down.
3898 */
3899 if (adapter->link_speed == 0)
3900 return;
3901 if (pci_channel_offline(pdev))
3902 return;
3903
Auke Kokbc7f75f2007-09-17 12:30:59 -07003904 adapter->stats.crcerrs += er32(CRCERRS);
3905 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07003906 adapter->stats.gorc += er32(GORCL);
3907 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003908 adapter->stats.bprc += er32(BPRC);
3909 adapter->stats.mprc += er32(MPRC);
3910 adapter->stats.roc += er32(ROC);
3911
Auke Kokbc7f75f2007-09-17 12:30:59 -07003912 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003913
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003914 /* Half-duplex statistics */
3915 if (adapter->link_duplex == HALF_DUPLEX) {
3916 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
3917 e1000e_update_phy_stats(adapter);
3918 } else {
3919 adapter->stats.scc += er32(SCC);
3920 adapter->stats.ecol += er32(ECOL);
3921 adapter->stats.mcc += er32(MCC);
3922 adapter->stats.latecol += er32(LATECOL);
3923 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003924
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003925 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003926
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003927 if ((hw->mac.type != e1000_82574) &&
3928 (hw->mac.type != e1000_82583))
3929 adapter->stats.tncrs += er32(TNCRS);
3930 }
3931 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00003932 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003933
Auke Kokbc7f75f2007-09-17 12:30:59 -07003934 adapter->stats.xonrxc += er32(XONRXC);
3935 adapter->stats.xontxc += er32(XONTXC);
3936 adapter->stats.xoffrxc += er32(XOFFRXC);
3937 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003938 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07003939 adapter->stats.gotc += er32(GOTCL);
3940 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941 adapter->stats.rnbc += er32(RNBC);
3942 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003943
3944 adapter->stats.mptc += er32(MPTC);
3945 adapter->stats.bptc += er32(BPTC);
3946
3947 /* used for adaptive IFS */
3948
3949 hw->mac.tx_packet_delta = er32(TPT);
3950 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003951
3952 adapter->stats.algnerrc += er32(ALGNERRC);
3953 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003954 adapter->stats.cexterr += er32(CEXTERR);
3955 adapter->stats.tsctc += er32(TSCTC);
3956 adapter->stats.tsctfc += er32(TSCTFC);
3957
Auke Kokbc7f75f2007-09-17 12:30:59 -07003958 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003959 netdev->stats.multicast = adapter->stats.mprc;
3960 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003961
3962 /* Rx Errors */
3963
Bruce Allanad680762008-03-28 09:15:03 -07003964 /*
3965 * RLEC on some newer hardware can be incorrect so build
3966 * our own version based on RUC and ROC
3967 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003968 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003969 adapter->stats.crcerrs + adapter->stats.algnerrc +
3970 adapter->stats.ruc + adapter->stats.roc +
3971 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003972 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003973 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003974 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3975 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3976 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003977
3978 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00003979 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003980 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00003981 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3982 netdev->stats.tx_window_errors = adapter->stats.latecol;
3983 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003984
3985 /* Tx Dropped needs to be maintained elsewhere */
3986
Auke Kokbc7f75f2007-09-17 12:30:59 -07003987 /* Management Stats */
3988 adapter->stats.mgptc += er32(MGTPTC);
3989 adapter->stats.mgprc += er32(MGTPRC);
3990 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003991}
3992
Bruce Allan7c257692008-04-23 11:09:00 -07003993/**
3994 * e1000_phy_read_status - Update the PHY register status snapshot
3995 * @adapter: board private structure
3996 **/
3997static void e1000_phy_read_status(struct e1000_adapter *adapter)
3998{
3999 struct e1000_hw *hw = &adapter->hw;
4000 struct e1000_phy_regs *phy = &adapter->phy_regs;
4001 int ret_val;
Bruce Allan7c257692008-04-23 11:09:00 -07004002
4003 if ((er32(STATUS) & E1000_STATUS_LU) &&
4004 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
4005 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4006 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4007 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4008 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4009 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4010 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4011 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4012 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4013 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004014 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004015 } else {
4016 /*
4017 * Do not read PHY registers if link is not up
4018 * Set values to typical power-on defaults
4019 */
4020 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4021 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4022 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4023 BMSR_ERCAP);
4024 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4025 ADVERTISE_ALL | ADVERTISE_CSMA);
4026 phy->lpa = 0;
4027 phy->expansion = EXPANSION_ENABLENPAGE;
4028 phy->ctrl1000 = ADVERTISE_1000FULL;
4029 phy->stat1000 = 0;
4030 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4031 }
Bruce Allan7c257692008-04-23 11:09:00 -07004032}
4033
Auke Kokbc7f75f2007-09-17 12:30:59 -07004034static void e1000_print_link_info(struct e1000_adapter *adapter)
4035{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004036 struct e1000_hw *hw = &adapter->hw;
4037 u32 ctrl = er32(CTRL);
4038
Bruce Allan8f12fe82008-11-21 16:54:43 -08004039 /* Link status message must follow this format for user tools */
4040 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4041 "Flow Control: %s\n",
4042 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004043 adapter->link_speed,
4044 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004045 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004046 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004047 "Rx/Tx" :
4048 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4049 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004050}
4051
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004052static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004053{
4054 struct e1000_hw *hw = &adapter->hw;
4055 bool link_active = 0;
4056 s32 ret_val = 0;
4057
4058 /*
4059 * get_link_status is set on LSC (link status) interrupt or
4060 * Rx sequence error interrupt. get_link_status will stay
4061 * false until the check_for_link establishes link
4062 * for copper adapters ONLY
4063 */
4064 switch (hw->phy.media_type) {
4065 case e1000_media_type_copper:
4066 if (hw->mac.get_link_status) {
4067 ret_val = hw->mac.ops.check_for_link(hw);
4068 link_active = !hw->mac.get_link_status;
4069 } else {
4070 link_active = 1;
4071 }
4072 break;
4073 case e1000_media_type_fiber:
4074 ret_val = hw->mac.ops.check_for_link(hw);
4075 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4076 break;
4077 case e1000_media_type_internal_serdes:
4078 ret_val = hw->mac.ops.check_for_link(hw);
4079 link_active = adapter->hw.mac.serdes_has_link;
4080 break;
4081 default:
4082 case e1000_media_type_unknown:
4083 break;
4084 }
4085
4086 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4087 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4088 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004089 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004090 }
4091
4092 return link_active;
4093}
4094
4095static void e1000e_enable_receives(struct e1000_adapter *adapter)
4096{
4097 /* make sure the receive unit is started */
4098 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4099 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4100 struct e1000_hw *hw = &adapter->hw;
4101 u32 rctl = er32(RCTL);
4102 ew32(RCTL, rctl | E1000_RCTL_EN);
4103 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4104 }
4105}
4106
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004107static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4108{
4109 struct e1000_hw *hw = &adapter->hw;
4110
4111 /*
4112 * With 82574 controllers, PHY needs to be checked periodically
4113 * for hung state and reset, if two calls return true
4114 */
4115 if (e1000_check_phy_82574(hw))
4116 adapter->phy_hang_count++;
4117 else
4118 adapter->phy_hang_count = 0;
4119
4120 if (adapter->phy_hang_count > 1) {
4121 adapter->phy_hang_count = 0;
4122 schedule_work(&adapter->reset_task);
4123 }
4124}
4125
Auke Kokbc7f75f2007-09-17 12:30:59 -07004126/**
4127 * e1000_watchdog - Timer Call-back
4128 * @data: pointer to adapter cast into an unsigned long
4129 **/
4130static void e1000_watchdog(unsigned long data)
4131{
4132 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4133
4134 /* Do the rest outside of interrupt context */
4135 schedule_work(&adapter->watchdog_task);
4136
4137 /* TODO: make this use queue_delayed_work() */
4138}
4139
4140static void e1000_watchdog_task(struct work_struct *work)
4141{
4142 struct e1000_adapter *adapter = container_of(work,
4143 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004144 struct net_device *netdev = adapter->netdev;
4145 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004146 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004147 struct e1000_ring *tx_ring = adapter->tx_ring;
4148 struct e1000_hw *hw = &adapter->hw;
4149 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004150 int tx_pending = 0;
4151
David S. Millerb405e8d2010-02-04 22:31:41 -08004152 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004153 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004154 /* Cancel scheduled suspend requests. */
4155 pm_runtime_resume(netdev->dev.parent);
4156
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004157 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004158 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004159 }
4160
4161 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4162 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4163 e1000_update_mng_vlan(adapter);
4164
Auke Kokbc7f75f2007-09-17 12:30:59 -07004165 if (link) {
4166 if (!netif_carrier_ok(netdev)) {
4167 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004168
4169 /* Cancel scheduled suspend requests. */
4170 pm_runtime_resume(netdev->dev.parent);
4171
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004172 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004173 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004174 mac->ops.get_link_up_info(&adapter->hw,
4175 &adapter->link_speed,
4176 &adapter->link_duplex);
4177 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004178 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004179 * On supported PHYs, check for duplex mismatch only
4180 * if link has autonegotiated at 10/100 half
4181 */
4182 if ((hw->phy.type == e1000_phy_igp_3 ||
4183 hw->phy.type == e1000_phy_bm) &&
4184 (hw->mac.autoneg == true) &&
4185 (adapter->link_speed == SPEED_10 ||
4186 adapter->link_speed == SPEED_100) &&
4187 (adapter->link_duplex == HALF_DUPLEX)) {
4188 u16 autoneg_exp;
4189
4190 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4191
4192 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4193 e_info("Autonegotiated half duplex but"
4194 " link partner cannot autoneg. "
4195 " Try forcing full duplex if "
4196 "link gets many collisions.\n");
4197 }
4198
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004199 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004200 adapter->tx_timeout_factor = 1;
4201 switch (adapter->link_speed) {
4202 case SPEED_10:
4203 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004204 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004205 break;
4206 case SPEED_100:
4207 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004208 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004209 break;
4210 }
4211
Bruce Allanad680762008-03-28 09:15:03 -07004212 /*
4213 * workaround: re-program speed mode bit after
4214 * link-up event
4215 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004216 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4217 !txb2b) {
4218 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004219 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004220 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004221 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222 }
4223
Bruce Allanad680762008-03-28 09:15:03 -07004224 /*
4225 * disable TSO for pcie and 10/100 speeds, to avoid
4226 * some hardware issues
4227 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004228 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4229 switch (adapter->link_speed) {
4230 case SPEED_10:
4231 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004232 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004233 netdev->features &= ~NETIF_F_TSO;
4234 netdev->features &= ~NETIF_F_TSO6;
4235 break;
4236 case SPEED_1000:
4237 netdev->features |= NETIF_F_TSO;
4238 netdev->features |= NETIF_F_TSO6;
4239 break;
4240 default:
4241 /* oops */
4242 break;
4243 }
4244 }
4245
Bruce Allanad680762008-03-28 09:15:03 -07004246 /*
4247 * enable transmits in the hardware, need to do this
4248 * after setting TARC(0)
4249 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004250 tctl = er32(TCTL);
4251 tctl |= E1000_TCTL_EN;
4252 ew32(TCTL, tctl);
4253
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004254 /*
4255 * Perform any post-link-up configuration before
4256 * reporting link up.
4257 */
4258 if (phy->ops.cfg_on_link_up)
4259 phy->ops.cfg_on_link_up(hw);
4260
Auke Kokbc7f75f2007-09-17 12:30:59 -07004261 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004262
4263 if (!test_bit(__E1000_DOWN, &adapter->state))
4264 mod_timer(&adapter->phy_info_timer,
4265 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004266 }
4267 } else {
4268 if (netif_carrier_ok(netdev)) {
4269 adapter->link_speed = 0;
4270 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004271 /* Link status message must follow this format */
4272 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4273 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004274 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004275 if (!test_bit(__E1000_DOWN, &adapter->state))
4276 mod_timer(&adapter->phy_info_timer,
4277 round_jiffies(jiffies + 2 * HZ));
4278
4279 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4280 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004281 else
4282 pm_schedule_suspend(netdev->dev.parent,
4283 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004284 }
4285 }
4286
4287link_up:
4288 e1000e_update_stats(adapter);
4289
4290 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4291 adapter->tpt_old = adapter->stats.tpt;
4292 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4293 adapter->colc_old = adapter->stats.colc;
4294
Bruce Allan7c257692008-04-23 11:09:00 -07004295 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4296 adapter->gorc_old = adapter->stats.gorc;
4297 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4298 adapter->gotc_old = adapter->stats.gotc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004299
4300 e1000e_update_adaptive(&adapter->hw);
4301
4302 if (!netif_carrier_ok(netdev)) {
4303 tx_pending = (e1000_desc_unused(tx_ring) + 1 <
4304 tx_ring->count);
4305 if (tx_pending) {
Bruce Allanad680762008-03-28 09:15:03 -07004306 /*
4307 * We've lost link, so the controller stops DMA,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004308 * but we've got queued Tx work that's never going
4309 * to get done, so reset controller to flush Tx.
Bruce Allanad680762008-03-28 09:15:03 -07004310 * (Do the reset outside of interrupt context).
4311 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004312 adapter->tx_timeout_count++;
4313 schedule_work(&adapter->reset_task);
Jesse Brandeburgc2d5ab42009-05-07 11:07:35 +00004314 /* return immediately since reset is imminent */
4315 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004316 }
4317 }
4318
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004319 /* Simple mode for Interrupt Throttle Rate (ITR) */
4320 if (adapter->itr_setting == 4) {
4321 /*
4322 * Symmetric Tx/Rx gets a reduced ITR=2000;
4323 * Total asymmetrical Tx or Rx gets ITR=8000;
4324 * everyone else is between 2000-8000.
4325 */
4326 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4327 u32 dif = (adapter->gotc > adapter->gorc ?
4328 adapter->gotc - adapter->gorc :
4329 adapter->gorc - adapter->gotc) / 10000;
4330 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4331
4332 ew32(ITR, 1000000000 / (itr * 256));
4333 }
4334
Bruce Allanad680762008-03-28 09:15:03 -07004335 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004336 if (adapter->msix_entries)
4337 ew32(ICS, adapter->rx_ring->ims_val);
4338 else
4339 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004340
4341 /* Force detection of hung controller every watchdog period */
4342 adapter->detect_tx_hung = 1;
4343
Bruce Allanaf667a22010-12-31 06:10:01 +00004344 /* flush partial descriptors to memory before detecting Tx hang */
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00004345 if (adapter->flags2 & FLAG2_DMA_BURST) {
4346 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
4347 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
4348 /*
4349 * no need to flush the writes because the timeout code does
4350 * an er32 first thing
4351 */
4352 }
4353
Bruce Allanad680762008-03-28 09:15:03 -07004354 /*
4355 * With 82571 controllers, LAA may be overwritten due to controller
4356 * reset from the other port. Set the appropriate LAA in RAR[0]
4357 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004358 if (e1000e_get_laa_state_82571(hw))
4359 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4360
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004361 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4362 e1000e_check_82574_phy_workaround(adapter);
4363
Auke Kokbc7f75f2007-09-17 12:30:59 -07004364 /* Reset the timer */
4365 if (!test_bit(__E1000_DOWN, &adapter->state))
4366 mod_timer(&adapter->watchdog_timer,
4367 round_jiffies(jiffies + 2 * HZ));
4368}
4369
4370#define E1000_TX_FLAGS_CSUM 0x00000001
4371#define E1000_TX_FLAGS_VLAN 0x00000002
4372#define E1000_TX_FLAGS_TSO 0x00000004
4373#define E1000_TX_FLAGS_IPV4 0x00000008
4374#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4375#define E1000_TX_FLAGS_VLAN_SHIFT 16
4376
4377static int e1000_tso(struct e1000_adapter *adapter,
4378 struct sk_buff *skb)
4379{
4380 struct e1000_ring *tx_ring = adapter->tx_ring;
4381 struct e1000_context_desc *context_desc;
4382 struct e1000_buffer *buffer_info;
4383 unsigned int i;
4384 u32 cmd_length = 0;
4385 u16 ipcse = 0, tucse, mss;
4386 u8 ipcss, ipcso, tucss, tucso, hdr_len;
4387 int err;
4388
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004389 if (!skb_is_gso(skb))
4390 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004391
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004392 if (skb_header_cloned(skb)) {
4393 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4394 if (err)
4395 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004396 }
4397
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004398 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4399 mss = skb_shinfo(skb)->gso_size;
4400 if (skb->protocol == htons(ETH_P_IP)) {
4401 struct iphdr *iph = ip_hdr(skb);
4402 iph->tot_len = 0;
4403 iph->check = 0;
4404 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4405 0, IPPROTO_TCP, 0);
4406 cmd_length = E1000_TXD_CMD_IP;
4407 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004408 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004409 ipv6_hdr(skb)->payload_len = 0;
4410 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4411 &ipv6_hdr(skb)->daddr,
4412 0, IPPROTO_TCP, 0);
4413 ipcse = 0;
4414 }
4415 ipcss = skb_network_offset(skb);
4416 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4417 tucss = skb_transport_offset(skb);
4418 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4419 tucse = 0;
4420
4421 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4422 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4423
4424 i = tx_ring->next_to_use;
4425 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4426 buffer_info = &tx_ring->buffer_info[i];
4427
4428 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4429 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4430 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4431 context_desc->upper_setup.tcp_fields.tucss = tucss;
4432 context_desc->upper_setup.tcp_fields.tucso = tucso;
4433 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4434 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4435 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4436 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4437
4438 buffer_info->time_stamp = jiffies;
4439 buffer_info->next_to_watch = i;
4440
4441 i++;
4442 if (i == tx_ring->count)
4443 i = 0;
4444 tx_ring->next_to_use = i;
4445
4446 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004447}
4448
4449static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4450{
4451 struct e1000_ring *tx_ring = adapter->tx_ring;
4452 struct e1000_context_desc *context_desc;
4453 struct e1000_buffer *buffer_info;
4454 unsigned int i;
4455 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004456 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004457 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004458
Dave Grahamaf807c82008-10-09 14:28:58 -07004459 if (skb->ip_summed != CHECKSUM_PARTIAL)
4460 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004461
Arthur Jones5f66f202009-03-19 01:13:08 +00004462 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4463 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4464 else
4465 protocol = skb->protocol;
4466
Arthur Jones3f518392009-03-20 15:56:35 -07004467 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004468 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004469 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4470 cmd_len |= E1000_TXD_CMD_TCP;
4471 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004472 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004473 /* XXX not handling all IPV6 headers */
4474 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4475 cmd_len |= E1000_TXD_CMD_TCP;
4476 break;
4477 default:
4478 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004479 e_warn("checksum_partial proto=%x!\n",
4480 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004481 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004482 }
4483
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004484 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004485
4486 i = tx_ring->next_to_use;
4487 buffer_info = &tx_ring->buffer_info[i];
4488 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4489
4490 context_desc->lower_setup.ip_config = 0;
4491 context_desc->upper_setup.tcp_fields.tucss = css;
4492 context_desc->upper_setup.tcp_fields.tucso =
4493 css + skb->csum_offset;
4494 context_desc->upper_setup.tcp_fields.tucse = 0;
4495 context_desc->tcp_seg_setup.data = 0;
4496 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4497
4498 buffer_info->time_stamp = jiffies;
4499 buffer_info->next_to_watch = i;
4500
4501 i++;
4502 if (i == tx_ring->count)
4503 i = 0;
4504 tx_ring->next_to_use = i;
4505
4506 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004507}
4508
4509#define E1000_MAX_PER_TXD 8192
4510#define E1000_MAX_TXD_PWR 12
4511
4512static int e1000_tx_map(struct e1000_adapter *adapter,
4513 struct sk_buff *skb, unsigned int first,
4514 unsigned int max_per_txd, unsigned int nr_frags,
4515 unsigned int mss)
4516{
4517 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004518 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004519 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004520 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004521 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004522 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004523
4524 i = tx_ring->next_to_use;
4525
4526 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004527 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004528 size = min(len, max_per_txd);
4529
Auke Kokbc7f75f2007-09-17 12:30:59 -07004530 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004531 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004532 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004533 buffer_info->dma = dma_map_single(&pdev->dev,
4534 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004535 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004536 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004537 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004538 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004539
4540 len -= size;
4541 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004542 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004543
4544 if (len) {
4545 i++;
4546 if (i == tx_ring->count)
4547 i = 0;
4548 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004549 }
4550
4551 for (f = 0; f < nr_frags; f++) {
4552 struct skb_frag_struct *frag;
4553
4554 frag = &skb_shinfo(skb)->frags[f];
4555 len = frag->size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004556 offset = frag->page_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004557
4558 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004559 i++;
4560 if (i == tx_ring->count)
4561 i = 0;
4562
Auke Kokbc7f75f2007-09-17 12:30:59 -07004563 buffer_info = &tx_ring->buffer_info[i];
4564 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004565
4566 buffer_info->length = size;
4567 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004568 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004569 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
Alexander Duyck03b13202009-12-02 16:45:31 +00004570 offset, size,
Nick Nunley0be3f552010-04-27 13:09:05 +00004571 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004572 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004573 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004574 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004575
4576 len -= size;
4577 offset += size;
4578 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004579 }
4580 }
4581
Bruce Allanaf667a22010-12-31 06:10:01 +00004582 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004583 /* multiply data chunks by size of headers */
4584 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4585
Auke Kokbc7f75f2007-09-17 12:30:59 -07004586 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004587 tx_ring->buffer_info[i].segs = segs;
4588 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004589 tx_ring->buffer_info[first].next_to_watch = i;
4590
4591 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004592
4593dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004594 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004595 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004596 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004597 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004598
4599 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004600 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004601 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004602 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004603 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004604 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004605 }
4606
4607 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004608}
4609
4610static void e1000_tx_queue(struct e1000_adapter *adapter,
4611 int tx_flags, int count)
4612{
4613 struct e1000_ring *tx_ring = adapter->tx_ring;
4614 struct e1000_tx_desc *tx_desc = NULL;
4615 struct e1000_buffer *buffer_info;
4616 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4617 unsigned int i;
4618
4619 if (tx_flags & E1000_TX_FLAGS_TSO) {
4620 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4621 E1000_TXD_CMD_TSE;
4622 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4623
4624 if (tx_flags & E1000_TX_FLAGS_IPV4)
4625 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4626 }
4627
4628 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4629 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4630 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4631 }
4632
4633 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4634 txd_lower |= E1000_TXD_CMD_VLE;
4635 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4636 }
4637
4638 i = tx_ring->next_to_use;
4639
Bruce Allan36b973d2010-11-24 07:42:43 +00004640 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004641 buffer_info = &tx_ring->buffer_info[i];
4642 tx_desc = E1000_TX_DESC(*tx_ring, i);
4643 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4644 tx_desc->lower.data =
4645 cpu_to_le32(txd_lower | buffer_info->length);
4646 tx_desc->upper.data = cpu_to_le32(txd_upper);
4647
4648 i++;
4649 if (i == tx_ring->count)
4650 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004651 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004652
4653 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4654
Bruce Allanad680762008-03-28 09:15:03 -07004655 /*
4656 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004657 * know there are new descriptors to fetch. (Only
4658 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004659 * such as IA-64).
4660 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004661 wmb();
4662
4663 tx_ring->next_to_use = i;
4664 writel(i, adapter->hw.hw_addr + tx_ring->tail);
Bruce Allanad680762008-03-28 09:15:03 -07004665 /*
4666 * we need this if more than one processor can write to our tail
4667 * at a time, it synchronizes IO on IA64/Altix systems
4668 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004669 mmiowb();
4670}
4671
4672#define MINIMUM_DHCP_PACKET_SIZE 282
4673static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4674 struct sk_buff *skb)
4675{
4676 struct e1000_hw *hw = &adapter->hw;
4677 u16 length, offset;
4678
4679 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004680 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4681 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004682 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4683 return 0;
4684 }
4685
4686 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4687 return 0;
4688
4689 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4690 return 0;
4691
4692 {
4693 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4694 struct udphdr *udp;
4695
4696 if (ip->protocol != IPPROTO_UDP)
4697 return 0;
4698
4699 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4700 if (ntohs(udp->dest) != 67)
4701 return 0;
4702
4703 offset = (u8 *)udp + 8 - skb->data;
4704 length = skb->len - offset;
4705 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4706 }
4707
4708 return 0;
4709}
4710
4711static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4712{
4713 struct e1000_adapter *adapter = netdev_priv(netdev);
4714
4715 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004716 /*
4717 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004718 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004719 * but since that doesn't exist yet, just open code it.
4720 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004721 smp_mb();
4722
Bruce Allanad680762008-03-28 09:15:03 -07004723 /*
4724 * We need to check again in a case another CPU has just
4725 * made room available.
4726 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004727 if (e1000_desc_unused(adapter->tx_ring) < size)
4728 return -EBUSY;
4729
4730 /* A reprieve! */
4731 netif_start_queue(netdev);
4732 ++adapter->restart_queue;
4733 return 0;
4734}
4735
4736static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4737{
4738 struct e1000_adapter *adapter = netdev_priv(netdev);
4739
4740 if (e1000_desc_unused(adapter->tx_ring) >= size)
4741 return 0;
4742 return __e1000_maybe_stop_tx(netdev, size);
4743}
4744
4745#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004746static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4747 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004748{
4749 struct e1000_adapter *adapter = netdev_priv(netdev);
4750 struct e1000_ring *tx_ring = adapter->tx_ring;
4751 unsigned int first;
4752 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4753 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4754 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004755 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004756 unsigned int nr_frags;
4757 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004758 int count = 0;
4759 int tso;
4760 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004761
4762 if (test_bit(__E1000_DOWN, &adapter->state)) {
4763 dev_kfree_skb_any(skb);
4764 return NETDEV_TX_OK;
4765 }
4766
4767 if (skb->len <= 0) {
4768 dev_kfree_skb_any(skb);
4769 return NETDEV_TX_OK;
4770 }
4771
4772 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004773 /*
4774 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004775 * make sure there is enough room in the FIFO before
4776 * initiating the DMA for each buffer. The calc is:
4777 * 4 = ceil(buffer len/mss). To make sure we don't
4778 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004779 * drops.
4780 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004781 if (mss) {
4782 u8 hdr_len;
4783 max_per_txd = min(mss << 2, max_per_txd);
4784 max_txd_pwr = fls(max_per_txd) - 1;
4785
Bruce Allanad680762008-03-28 09:15:03 -07004786 /*
4787 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4788 * points to just header, pull a few bytes of payload from
4789 * frags into skb->data
4790 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004791 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004792 /*
4793 * we do this workaround for ES2LAN, but it is un-necessary,
4794 * avoiding it could save a lot of cycles
4795 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004796 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004797 unsigned int pull_size;
4798
4799 pull_size = min((unsigned int)4, skb->data_len);
4800 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004801 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004802 dev_kfree_skb_any(skb);
4803 return NETDEV_TX_OK;
4804 }
Eric Dumazete743d312010-04-14 15:59:40 -07004805 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004806 }
4807 }
4808
4809 /* reserve a descriptor for the offload context */
4810 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4811 count++;
4812 count++;
4813
4814 count += TXD_USE_COUNT(len, max_txd_pwr);
4815
4816 nr_frags = skb_shinfo(skb)->nr_frags;
4817 for (f = 0; f < nr_frags; f++)
4818 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
4819 max_txd_pwr);
4820
4821 if (adapter->hw.mac.tx_pkt_filtering)
4822 e1000_transfer_dhcp_info(adapter, skb);
4823
Bruce Allanad680762008-03-28 09:15:03 -07004824 /*
4825 * need: count + 2 desc gap to keep tail from touching
4826 * head, otherwise try next time
4827 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004828 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004829 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004830
Jesse Grosseab6d182010-10-20 13:56:03 +00004831 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004832 tx_flags |= E1000_TX_FLAGS_VLAN;
4833 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4834 }
4835
4836 first = tx_ring->next_to_use;
4837
4838 tso = e1000_tso(adapter, skb);
4839 if (tso < 0) {
4840 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004841 return NETDEV_TX_OK;
4842 }
4843
4844 if (tso)
4845 tx_flags |= E1000_TX_FLAGS_TSO;
4846 else if (e1000_tx_csum(adapter, skb))
4847 tx_flags |= E1000_TX_FLAGS_CSUM;
4848
Bruce Allanad680762008-03-28 09:15:03 -07004849 /*
4850 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004851 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004852 * no longer assume, we must.
4853 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004854 if (skb->protocol == htons(ETH_P_IP))
4855 tx_flags |= E1000_TX_FLAGS_IPV4;
4856
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004857 /* if count is 0 then mapping error has occured */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004858 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004859 if (count) {
4860 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004861 /* Make sure there is space in the ring for the next send. */
4862 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4863
4864 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004865 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004866 tx_ring->buffer_info[first].time_stamp = 0;
4867 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004868 }
4869
Auke Kokbc7f75f2007-09-17 12:30:59 -07004870 return NETDEV_TX_OK;
4871}
4872
4873/**
4874 * e1000_tx_timeout - Respond to a Tx Hang
4875 * @netdev: network interface device structure
4876 **/
4877static void e1000_tx_timeout(struct net_device *netdev)
4878{
4879 struct e1000_adapter *adapter = netdev_priv(netdev);
4880
4881 /* Do the reset outside of interrupt context */
4882 adapter->tx_timeout_count++;
4883 schedule_work(&adapter->reset_task);
4884}
4885
4886static void e1000_reset_task(struct work_struct *work)
4887{
4888 struct e1000_adapter *adapter;
4889 adapter = container_of(work, struct e1000_adapter, reset_task);
4890
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00004891 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4892 (adapter->flags & FLAG_RX_RESTART_NOW))) {
4893 e1000e_dump(adapter);
4894 e_err("Reset adapter\n");
4895 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004896 e1000e_reinit_locked(adapter);
4897}
4898
4899/**
4900 * e1000_get_stats - Get System Network Statistics
4901 * @netdev: network interface device structure
4902 *
4903 * Returns the address of the device statistics structure.
4904 * The statistics are actually updated from the timer callback.
4905 **/
4906static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
4907{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004908 /* only return the current stats */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004909 return &netdev->stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004910}
4911
4912/**
4913 * e1000_change_mtu - Change the Maximum Transfer Unit
4914 * @netdev: network interface device structure
4915 * @new_mtu: new value for maximum frame size
4916 *
4917 * Returns 0 on success, negative on failure
4918 **/
4919static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4920{
4921 struct e1000_adapter *adapter = netdev_priv(netdev);
4922 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4923
Bruce Allan2adc55c2009-06-02 11:28:58 +00004924 /* Jumbo frame support */
4925 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
4926 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
4927 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004928 return -EINVAL;
4929 }
4930
Bruce Allan2adc55c2009-06-02 11:28:58 +00004931 /* Supported frame sizes */
4932 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
4933 (max_frame > adapter->max_hw_frame_size)) {
4934 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004935 return -EINVAL;
4936 }
4937
Bruce Allana1ce6472010-09-22 17:16:40 +00004938 /* Jumbo frame workaround on 82579 requires CRC be stripped */
4939 if ((adapter->hw.mac.type == e1000_pch2lan) &&
4940 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
4941 (new_mtu > ETH_DATA_LEN)) {
4942 e_err("Jumbo Frames not supported on 82579 when CRC "
4943 "stripping is disabled.\n");
4944 return -EINVAL;
4945 }
4946
Bruce Allan6f461f62010-04-27 03:33:04 +00004947 /* 82573 Errata 17 */
4948 if (((adapter->hw.mac.type == e1000_82573) ||
4949 (adapter->hw.mac.type == e1000_82574)) &&
4950 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
4951 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
4952 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
4953 }
4954
Auke Kokbc7f75f2007-09-17 12:30:59 -07004955 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4956 msleep(1);
Bruce Allan610c9922009-11-19 12:35:45 +00004957 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004958 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00004959 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
4960 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004961 if (netif_running(netdev))
4962 e1000e_down(adapter);
4963
Bruce Allanad680762008-03-28 09:15:03 -07004964 /*
4965 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07004966 * means we reserve 2 more, this pushes us to allocate from the next
4967 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07004968 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004969 * However with the new *_jumbo_rx* routines, jumbo receives will use
4970 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07004971 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004972
Jesse Brandeburg99261462010-01-22 22:56:16 +00004973 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004974 adapter->rx_buffer_len = 2048;
4975 else
4976 adapter->rx_buffer_len = 4096;
4977
4978 /* adjust allocation if LPE protects us, and we aren't using SBP */
4979 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
4980 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
4981 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07004982 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004983
Auke Kokbc7f75f2007-09-17 12:30:59 -07004984 if (netif_running(netdev))
4985 e1000e_up(adapter);
4986 else
4987 e1000e_reset(adapter);
4988
4989 clear_bit(__E1000_RESETTING, &adapter->state);
4990
4991 return 0;
4992}
4993
4994static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4995 int cmd)
4996{
4997 struct e1000_adapter *adapter = netdev_priv(netdev);
4998 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004999
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005000 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005001 return -EOPNOTSUPP;
5002
5003 switch (cmd) {
5004 case SIOCGMIIPHY:
5005 data->phy_id = adapter->hw.phy.addr;
5006 break;
5007 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005008 e1000_phy_read_status(adapter);
5009
Bruce Allan7c257692008-04-23 11:09:00 -07005010 switch (data->reg_num & 0x1F) {
5011 case MII_BMCR:
5012 data->val_out = adapter->phy_regs.bmcr;
5013 break;
5014 case MII_BMSR:
5015 data->val_out = adapter->phy_regs.bmsr;
5016 break;
5017 case MII_PHYSID1:
5018 data->val_out = (adapter->hw.phy.id >> 16);
5019 break;
5020 case MII_PHYSID2:
5021 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5022 break;
5023 case MII_ADVERTISE:
5024 data->val_out = adapter->phy_regs.advertise;
5025 break;
5026 case MII_LPA:
5027 data->val_out = adapter->phy_regs.lpa;
5028 break;
5029 case MII_EXPANSION:
5030 data->val_out = adapter->phy_regs.expansion;
5031 break;
5032 case MII_CTRL1000:
5033 data->val_out = adapter->phy_regs.ctrl1000;
5034 break;
5035 case MII_STAT1000:
5036 data->val_out = adapter->phy_regs.stat1000;
5037 break;
5038 case MII_ESTATUS:
5039 data->val_out = adapter->phy_regs.estatus;
5040 break;
5041 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005042 return -EIO;
5043 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005044 break;
5045 case SIOCSMIIREG:
5046 default:
5047 return -EOPNOTSUPP;
5048 }
5049 return 0;
5050}
5051
5052static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5053{
5054 switch (cmd) {
5055 case SIOCGMIIPHY:
5056 case SIOCGMIIREG:
5057 case SIOCSMIIREG:
5058 return e1000_mii_ioctl(netdev, ifr, cmd);
5059 default:
5060 return -EOPNOTSUPP;
5061 }
5062}
5063
Bruce Allana4f58f52009-06-02 11:29:18 +00005064static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5065{
5066 struct e1000_hw *hw = &adapter->hw;
5067 u32 i, mac_reg;
5068 u16 phy_reg;
5069 int retval = 0;
5070
5071 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005072 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005073
5074 /* copy MAC MTA to PHY MTA */
5075 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5076 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
5077 e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF));
5078 e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF));
5079 }
5080
5081 /* configure PHY Rx Control register */
5082 e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg);
5083 mac_reg = er32(RCTL);
5084 if (mac_reg & E1000_RCTL_UPE)
5085 phy_reg |= BM_RCTL_UPE;
5086 if (mac_reg & E1000_RCTL_MPE)
5087 phy_reg |= BM_RCTL_MPE;
5088 phy_reg &= ~(BM_RCTL_MO_MASK);
5089 if (mac_reg & E1000_RCTL_MO_3)
5090 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5091 << BM_RCTL_MO_SHIFT);
5092 if (mac_reg & E1000_RCTL_BAM)
5093 phy_reg |= BM_RCTL_BAM;
5094 if (mac_reg & E1000_RCTL_PMCF)
5095 phy_reg |= BM_RCTL_PMCF;
5096 mac_reg = er32(CTRL);
5097 if (mac_reg & E1000_CTRL_RFCE)
5098 phy_reg |= BM_RCTL_RFCE;
5099 e1e_wphy(&adapter->hw, BM_RCTL, phy_reg);
5100
5101 /* enable PHY wakeup in MAC register */
5102 ew32(WUFC, wufc);
5103 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5104
5105 /* configure and enable PHY wakeup in PHY registers */
5106 e1e_wphy(&adapter->hw, BM_WUFC, wufc);
5107 e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
5108
5109 /* activate PHY wakeup */
Bruce Allan94d81862009-11-20 23:25:26 +00005110 retval = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005111 if (retval) {
5112 e_err("Could not acquire PHY\n");
5113 return retval;
5114 }
5115 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
5116 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
5117 retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
5118 if (retval) {
5119 e_err("Could not read PHY page 769\n");
5120 goto out;
5121 }
5122 phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5123 retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
5124 if (retval)
5125 e_err("Could not set PHY Host Wakeup bit\n");
5126out:
Bruce Allan94d81862009-11-20 23:25:26 +00005127 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005128
5129 return retval;
5130}
5131
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005132static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5133 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005134{
5135 struct net_device *netdev = pci_get_drvdata(pdev);
5136 struct e1000_adapter *adapter = netdev_priv(netdev);
5137 struct e1000_hw *hw = &adapter->hw;
5138 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005139 /* Runtime suspend should only enable wakeup for link changes */
5140 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005141 int retval = 0;
5142
5143 netif_device_detach(netdev);
5144
5145 if (netif_running(netdev)) {
5146 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5147 e1000e_down(adapter);
5148 e1000_free_irq(adapter);
5149 }
Bruce Allan4662e822008-08-26 18:37:06 -07005150 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005151
5152 retval = pci_save_state(pdev);
5153 if (retval)
5154 return retval;
5155
5156 status = er32(STATUS);
5157 if (status & E1000_STATUS_LU)
5158 wufc &= ~E1000_WUFC_LNKC;
5159
5160 if (wufc) {
5161 e1000_setup_rctl(adapter);
5162 e1000_set_multi(netdev);
5163
5164 /* turn on all-multi mode if wake on multicast is enabled */
5165 if (wufc & E1000_WUFC_MC) {
5166 rctl = er32(RCTL);
5167 rctl |= E1000_RCTL_MPE;
5168 ew32(RCTL, rctl);
5169 }
5170
5171 ctrl = er32(CTRL);
5172 /* advertise wake from D3Cold */
5173 #define E1000_CTRL_ADVD3WUC 0x00100000
5174 /* phy power management enable */
5175 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005176 ctrl |= E1000_CTRL_ADVD3WUC;
5177 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5178 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005179 ew32(CTRL, ctrl);
5180
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005181 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5182 adapter->hw.phy.media_type ==
5183 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005184 /* keep the laser running in D3 */
5185 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005186 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005187 ew32(CTRL_EXT, ctrl_ext);
5188 }
5189
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005190 if (adapter->flags & FLAG_IS_ICH)
5191 e1000e_disable_gig_wol_ich8lan(&adapter->hw);
5192
Auke Kokbc7f75f2007-09-17 12:30:59 -07005193 /* Allow time for pending master requests to run */
5194 e1000e_disable_pcie_master(&adapter->hw);
5195
Bruce Allan82776a42009-08-14 14:35:33 +00005196 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005197 /* enable wakeup by the PHY */
5198 retval = e1000_init_phy_wakeup(adapter, wufc);
5199 if (retval)
5200 return retval;
5201 } else {
5202 /* enable wakeup by the MAC */
5203 ew32(WUFC, wufc);
5204 ew32(WUC, E1000_WUC_PME_EN);
5205 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005206 } else {
5207 ew32(WUC, 0);
5208 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005209 }
5210
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005211 *enable_wake = !!wufc;
5212
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005214 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5215 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005216 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005217
5218 if (adapter->hw.phy.type == e1000_phy_igp_3)
5219 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5220
Bruce Allanad680762008-03-28 09:15:03 -07005221 /*
5222 * Release control of h/w to f/w. If f/w is AMT enabled, this
5223 * would have already happened in close and is redundant.
5224 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005225 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005226
5227 pci_disable_device(pdev);
5228
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005229 return 0;
5230}
5231
5232static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5233{
5234 if (sleep && wake) {
5235 pci_prepare_to_sleep(pdev);
5236 return;
5237 }
5238
5239 pci_wake_from_d3(pdev, wake);
5240 pci_set_power_state(pdev, PCI_D3hot);
5241}
5242
5243static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5244 bool wake)
5245{
5246 struct net_device *netdev = pci_get_drvdata(pdev);
5247 struct e1000_adapter *adapter = netdev_priv(netdev);
5248
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005249 /*
5250 * The pci-e switch on some quad port adapters will report a
5251 * correctable error when the MAC transitions from D0 to D3. To
5252 * prevent this we need to mask off the correctable errors on the
5253 * downstream port of the pci-e switch.
5254 */
5255 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5256 struct pci_dev *us_dev = pdev->bus->self;
5257 int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
5258 u16 devctl;
5259
5260 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5261 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5262 (devctl & ~PCI_EXP_DEVCTL_CERE));
5263
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005264 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005265
5266 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5267 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005268 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005269 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005270}
5271
Bruce Allan6f461f62010-04-27 03:33:04 +00005272#ifdef CONFIG_PCIEASPM
5273static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5274{
5275 pci_disable_link_state(pdev, state);
5276}
5277#else
5278static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005279{
5280 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005281 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005282
5283 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005284 * Both device and parent should have the same ASPM setting.
5285 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005286 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005287 pos = pci_pcie_cap(pdev);
5288 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5289 reg16 &= ~state;
5290 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5291
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005292 if (!pdev->bus->self)
5293 return;
5294
Bruce Allan6f461f62010-04-27 03:33:04 +00005295 pos = pci_pcie_cap(pdev->bus->self);
5296 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5297 reg16 &= ~state;
5298 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5299}
5300#endif
5301void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5302{
5303 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5304 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5305 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5306
5307 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005308}
5309
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005310#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005311static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005312{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005313 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005314}
5315
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005316static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005317{
5318 struct net_device *netdev = pci_get_drvdata(pdev);
5319 struct e1000_adapter *adapter = netdev_priv(netdev);
5320 struct e1000_hw *hw = &adapter->hw;
5321 u32 err;
5322
5323 pci_set_power_state(pdev, PCI_D0);
5324 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005325 pci_save_state(pdev);
Bruce Allan6f461f62010-04-27 03:33:04 +00005326 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5327 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005328
Bruce Allan4662e822008-08-26 18:37:06 -07005329 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005330 if (netif_running(netdev)) {
5331 err = e1000_request_irq(adapter);
5332 if (err)
5333 return err;
5334 }
5335
5336 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005337
5338 /* report the system wakeup cause from S3/S4 */
5339 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5340 u16 phy_data;
5341
5342 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5343 if (phy_data) {
5344 e_info("PHY Wakeup cause - %s\n",
5345 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5346 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5347 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5348 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5349 phy_data & E1000_WUS_LNKC ? "Link Status "
5350 " Change" : "other");
5351 }
5352 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5353 } else {
5354 u32 wus = er32(WUS);
5355 if (wus) {
5356 e_info("MAC Wakeup cause - %s\n",
5357 wus & E1000_WUS_EX ? "Unicast Packet" :
5358 wus & E1000_WUS_MC ? "Multicast Packet" :
5359 wus & E1000_WUS_BC ? "Broadcast Packet" :
5360 wus & E1000_WUS_MAG ? "Magic Packet" :
5361 wus & E1000_WUS_LNKC ? "Link Status Change" :
5362 "other");
5363 }
5364 ew32(WUS, ~0);
5365 }
5366
Auke Kokbc7f75f2007-09-17 12:30:59 -07005367 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005368
Bruce Allancd791612010-05-10 14:59:51 +00005369 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005370
5371 if (netif_running(netdev))
5372 e1000e_up(adapter);
5373
5374 netif_device_attach(netdev);
5375
Bruce Allanad680762008-03-28 09:15:03 -07005376 /*
5377 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005378 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005379 * under the control of the driver.
5380 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005381 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005382 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005383
5384 return 0;
5385}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005386
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005387#ifdef CONFIG_PM_SLEEP
5388static int e1000_suspend(struct device *dev)
5389{
5390 struct pci_dev *pdev = to_pci_dev(dev);
5391 int retval;
5392 bool wake;
5393
5394 retval = __e1000_shutdown(pdev, &wake, false);
5395 if (!retval)
5396 e1000_complete_shutdown(pdev, true, wake);
5397
5398 return retval;
5399}
5400
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005401static int e1000_resume(struct device *dev)
5402{
5403 struct pci_dev *pdev = to_pci_dev(dev);
5404 struct net_device *netdev = pci_get_drvdata(pdev);
5405 struct e1000_adapter *adapter = netdev_priv(netdev);
5406
5407 if (e1000e_pm_ready(adapter))
5408 adapter->idle_check = true;
5409
5410 return __e1000_resume(pdev);
5411}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005412#endif /* CONFIG_PM_SLEEP */
5413
5414#ifdef CONFIG_PM_RUNTIME
5415static int e1000_runtime_suspend(struct device *dev)
5416{
5417 struct pci_dev *pdev = to_pci_dev(dev);
5418 struct net_device *netdev = pci_get_drvdata(pdev);
5419 struct e1000_adapter *adapter = netdev_priv(netdev);
5420
5421 if (e1000e_pm_ready(adapter)) {
5422 bool wake;
5423
5424 __e1000_shutdown(pdev, &wake, true);
5425 }
5426
5427 return 0;
5428}
5429
5430static int e1000_idle(struct device *dev)
5431{
5432 struct pci_dev *pdev = to_pci_dev(dev);
5433 struct net_device *netdev = pci_get_drvdata(pdev);
5434 struct e1000_adapter *adapter = netdev_priv(netdev);
5435
5436 if (!e1000e_pm_ready(adapter))
5437 return 0;
5438
5439 if (adapter->idle_check) {
5440 adapter->idle_check = false;
5441 if (!e1000e_has_link(adapter))
5442 pm_schedule_suspend(dev, MSEC_PER_SEC);
5443 }
5444
5445 return -EBUSY;
5446}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005447
5448static int e1000_runtime_resume(struct device *dev)
5449{
5450 struct pci_dev *pdev = to_pci_dev(dev);
5451 struct net_device *netdev = pci_get_drvdata(pdev);
5452 struct e1000_adapter *adapter = netdev_priv(netdev);
5453
5454 if (!e1000e_pm_ready(adapter))
5455 return 0;
5456
5457 adapter->idle_check = !dev->power.runtime_auto;
5458 return __e1000_resume(pdev);
5459}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005460#endif /* CONFIG_PM_RUNTIME */
5461#endif /* CONFIG_PM_OPS */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005462
5463static void e1000_shutdown(struct pci_dev *pdev)
5464{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005465 bool wake = false;
5466
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005467 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005468
5469 if (system_state == SYSTEM_POWER_OFF)
5470 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005471}
5472
5473#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005474
5475static irqreturn_t e1000_intr_msix(int irq, void *data)
5476{
5477 struct net_device *netdev = data;
5478 struct e1000_adapter *adapter = netdev_priv(netdev);
5479 int vector, msix_irq;
5480
5481 if (adapter->msix_entries) {
5482 vector = 0;
5483 msix_irq = adapter->msix_entries[vector].vector;
5484 disable_irq(msix_irq);
5485 e1000_intr_msix_rx(msix_irq, netdev);
5486 enable_irq(msix_irq);
5487
5488 vector++;
5489 msix_irq = adapter->msix_entries[vector].vector;
5490 disable_irq(msix_irq);
5491 e1000_intr_msix_tx(msix_irq, netdev);
5492 enable_irq(msix_irq);
5493
5494 vector++;
5495 msix_irq = adapter->msix_entries[vector].vector;
5496 disable_irq(msix_irq);
5497 e1000_msix_other(msix_irq, netdev);
5498 enable_irq(msix_irq);
5499 }
5500
5501 return IRQ_HANDLED;
5502}
5503
Auke Kokbc7f75f2007-09-17 12:30:59 -07005504/*
5505 * Polling 'interrupt' - used by things like netconsole to send skbs
5506 * without having to re-enable interrupts. It's not called while
5507 * the interrupt routine is executing.
5508 */
5509static void e1000_netpoll(struct net_device *netdev)
5510{
5511 struct e1000_adapter *adapter = netdev_priv(netdev);
5512
Dongdong Deng147b2c82010-11-16 19:50:15 -08005513 switch (adapter->int_mode) {
5514 case E1000E_INT_MODE_MSIX:
5515 e1000_intr_msix(adapter->pdev->irq, netdev);
5516 break;
5517 case E1000E_INT_MODE_MSI:
5518 disable_irq(adapter->pdev->irq);
5519 e1000_intr_msi(adapter->pdev->irq, netdev);
5520 enable_irq(adapter->pdev->irq);
5521 break;
5522 default: /* E1000E_INT_MODE_LEGACY */
5523 disable_irq(adapter->pdev->irq);
5524 e1000_intr(adapter->pdev->irq, netdev);
5525 enable_irq(adapter->pdev->irq);
5526 break;
5527 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005528}
5529#endif
5530
5531/**
5532 * e1000_io_error_detected - called when PCI error is detected
5533 * @pdev: Pointer to PCI device
5534 * @state: The current pci connection state
5535 *
5536 * This function is called after a PCI bus error affecting
5537 * this device has been detected.
5538 */
5539static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5540 pci_channel_state_t state)
5541{
5542 struct net_device *netdev = pci_get_drvdata(pdev);
5543 struct e1000_adapter *adapter = netdev_priv(netdev);
5544
5545 netif_device_detach(netdev);
5546
Mike Masonc93b5a72009-06-30 12:45:53 +00005547 if (state == pci_channel_io_perm_failure)
5548 return PCI_ERS_RESULT_DISCONNECT;
5549
Auke Kokbc7f75f2007-09-17 12:30:59 -07005550 if (netif_running(netdev))
5551 e1000e_down(adapter);
5552 pci_disable_device(pdev);
5553
5554 /* Request a slot slot reset. */
5555 return PCI_ERS_RESULT_NEED_RESET;
5556}
5557
5558/**
5559 * e1000_io_slot_reset - called after the pci bus has been reset.
5560 * @pdev: Pointer to PCI device
5561 *
5562 * Restart the card from scratch, as if from a cold-boot. Implementation
5563 * resembles the first-half of the e1000_resume routine.
5564 */
5565static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5566{
5567 struct net_device *netdev = pci_get_drvdata(pdev);
5568 struct e1000_adapter *adapter = netdev_priv(netdev);
5569 struct e1000_hw *hw = &adapter->hw;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005570 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005571 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005572
Bruce Allan6f461f62010-04-27 03:33:04 +00005573 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5574 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Bruce Allanf0f422e2008-08-04 17:21:53 -07005575 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005576 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005577 dev_err(&pdev->dev,
5578 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005579 result = PCI_ERS_RESULT_DISCONNECT;
5580 } else {
5581 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005582 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005583 pci_restore_state(pdev);
5584
5585 pci_enable_wake(pdev, PCI_D3hot, 0);
5586 pci_enable_wake(pdev, PCI_D3cold, 0);
5587
5588 e1000e_reset(adapter);
5589 ew32(WUS, ~0);
5590 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005591 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005592
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005593 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005594
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005595 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005596}
5597
5598/**
5599 * e1000_io_resume - called when traffic can start flowing again.
5600 * @pdev: Pointer to PCI device
5601 *
5602 * This callback is called when the error recovery driver tells us that
5603 * its OK to resume normal operation. Implementation resembles the
5604 * second-half of the e1000_resume routine.
5605 */
5606static void e1000_io_resume(struct pci_dev *pdev)
5607{
5608 struct net_device *netdev = pci_get_drvdata(pdev);
5609 struct e1000_adapter *adapter = netdev_priv(netdev);
5610
Bruce Allancd791612010-05-10 14:59:51 +00005611 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005612
5613 if (netif_running(netdev)) {
5614 if (e1000e_up(adapter)) {
5615 dev_err(&pdev->dev,
5616 "can't bring device back up after reset\n");
5617 return;
5618 }
5619 }
5620
5621 netif_device_attach(netdev);
5622
Bruce Allanad680762008-03-28 09:15:03 -07005623 /*
5624 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005625 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005626 * under the control of the driver.
5627 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005628 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005629 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005630
5631}
5632
5633static void e1000_print_device_info(struct e1000_adapter *adapter)
5634{
5635 struct e1000_hw *hw = &adapter->hw;
5636 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005637 u32 ret_val;
5638 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005639
5640 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005641 e_info("(PCI Express:2.5GB/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005642 /* bus width */
5643 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5644 "Width x1"),
5645 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005646 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005647 e_info("Intel(R) PRO/%s Network Connection\n",
5648 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005649 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5650 E1000_PBANUM_LENGTH);
5651 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005652 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005653 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5654 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005655}
5656
Auke Kok10aa4c02008-08-04 17:21:20 -07005657static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5658{
5659 struct e1000_hw *hw = &adapter->hw;
5660 int ret_val;
5661 u16 buf = 0;
5662
5663 if (hw->mac.type != e1000_82573)
5664 return;
5665
5666 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005667 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005668 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005669 dev_warn(&adapter->pdev->dev,
5670 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005671 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005672}
5673
Stephen Hemminger651c2462008-11-19 21:57:48 -08005674static const struct net_device_ops e1000e_netdev_ops = {
5675 .ndo_open = e1000_open,
5676 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005677 .ndo_start_xmit = e1000_xmit_frame,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005678 .ndo_get_stats = e1000_get_stats,
5679 .ndo_set_multicast_list = e1000_set_multi,
5680 .ndo_set_mac_address = e1000_set_mac,
5681 .ndo_change_mtu = e1000_change_mtu,
5682 .ndo_do_ioctl = e1000_ioctl,
5683 .ndo_tx_timeout = e1000_tx_timeout,
5684 .ndo_validate_addr = eth_validate_addr,
5685
5686 .ndo_vlan_rx_register = e1000_vlan_rx_register,
5687 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5688 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5689#ifdef CONFIG_NET_POLL_CONTROLLER
5690 .ndo_poll_controller = e1000_netpoll,
5691#endif
5692};
5693
Auke Kokbc7f75f2007-09-17 12:30:59 -07005694/**
5695 * e1000_probe - Device Initialization Routine
5696 * @pdev: PCI device information struct
5697 * @ent: entry in e1000_pci_tbl
5698 *
5699 * Returns 0 on success, negative on failure
5700 *
5701 * e1000_probe initializes an adapter identified by a pci_dev structure.
5702 * The OS initialization, configuring of the adapter private structure,
5703 * and a hardware reset occur.
5704 **/
5705static int __devinit e1000_probe(struct pci_dev *pdev,
5706 const struct pci_device_id *ent)
5707{
5708 struct net_device *netdev;
5709 struct e1000_adapter *adapter;
5710 struct e1000_hw *hw;
5711 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005712 resource_size_t mmio_start, mmio_len;
5713 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005714
5715 static int cards_found;
5716 int i, err, pci_using_dac;
5717 u16 eeprom_data = 0;
5718 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5719
Bruce Allan6f461f62010-04-27 03:33:04 +00005720 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
5721 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005722
Bruce Allanf0f422e2008-08-04 17:21:53 -07005723 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005724 if (err)
5725 return err;
5726
5727 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005728 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005729 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005730 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005731 if (!err)
5732 pci_using_dac = 1;
5733 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005734 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005735 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005736 err = dma_set_coherent_mask(&pdev->dev,
5737 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005738 if (err) {
5739 dev_err(&pdev->dev, "No usable DMA "
5740 "configuration, aborting\n");
5741 goto err_dma;
5742 }
5743 }
5744 }
5745
Arjan van de Vene8de1482008-10-22 19:55:31 -07005746 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005747 pci_select_bars(pdev, IORESOURCE_MEM),
5748 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005749 if (err)
5750 goto err_pci_reg;
5751
Xiaotian Feng68eac462009-08-14 14:35:52 +00005752 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005753 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005754
Auke Kokbc7f75f2007-09-17 12:30:59 -07005755 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005756 /* PCI config space info */
5757 err = pci_save_state(pdev);
5758 if (err)
5759 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005760
5761 err = -ENOMEM;
5762 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5763 if (!netdev)
5764 goto err_alloc_etherdev;
5765
Auke Kokbc7f75f2007-09-17 12:30:59 -07005766 SET_NETDEV_DEV(netdev, &pdev->dev);
5767
Tom Herbertf85e4df2010-05-05 14:03:32 +00005768 netdev->irq = pdev->irq;
5769
Auke Kokbc7f75f2007-09-17 12:30:59 -07005770 pci_set_drvdata(pdev, netdev);
5771 adapter = netdev_priv(netdev);
5772 hw = &adapter->hw;
5773 adapter->netdev = netdev;
5774 adapter->pdev = pdev;
5775 adapter->ei = ei;
5776 adapter->pba = ei->pba;
5777 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005778 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005779 adapter->hw.adapter = adapter;
5780 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005781 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005782 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5783
5784 mmio_start = pci_resource_start(pdev, 0);
5785 mmio_len = pci_resource_len(pdev, 0);
5786
5787 err = -EIO;
5788 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
5789 if (!adapter->hw.hw_addr)
5790 goto err_ioremap;
5791
5792 if ((adapter->flags & FLAG_HAS_FLASH) &&
5793 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
5794 flash_start = pci_resource_start(pdev, 1);
5795 flash_len = pci_resource_len(pdev, 1);
5796 adapter->hw.flash_address = ioremap(flash_start, flash_len);
5797 if (!adapter->hw.flash_address)
5798 goto err_flashmap;
5799 }
5800
5801 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08005802 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005803 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005804 netdev->watchdog_timeo = 5 * HZ;
5805 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005806 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
5807
5808 netdev->mem_start = mmio_start;
5809 netdev->mem_end = mmio_start + mmio_len;
5810
5811 adapter->bd_number = cards_found++;
5812
Bruce Allan4662e822008-08-26 18:37:06 -07005813 e1000e_check_options(adapter);
5814
Auke Kokbc7f75f2007-09-17 12:30:59 -07005815 /* setup adapter struct */
5816 err = e1000_sw_init(adapter);
5817 if (err)
5818 goto err_sw_init;
5819
Auke Kokbc7f75f2007-09-17 12:30:59 -07005820 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
5821 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
5822 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
5823
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005824 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005825 if (err)
5826 goto err_hw_init;
5827
Bruce Allan4a770352008-10-01 17:18:35 -07005828 if ((adapter->flags & FLAG_IS_ICH) &&
5829 (adapter->flags & FLAG_READ_ONLY_NVM))
5830 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
5831
Auke Kokbc7f75f2007-09-17 12:30:59 -07005832 hw->mac.ops.get_bus_info(&adapter->hw);
5833
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005834 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005835
5836 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005837 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005838 adapter->hw.phy.mdix = AUTO_ALL_MODES;
5839 adapter->hw.phy.disable_polarity_correction = 0;
5840 adapter->hw.phy.ms_type = e1000_ms_hw_default;
5841 }
5842
5843 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005844 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005845
5846 netdev->features = NETIF_F_SG |
5847 NETIF_F_HW_CSUM |
5848 NETIF_F_HW_VLAN_TX |
5849 NETIF_F_HW_VLAN_RX;
5850
5851 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
5852 netdev->features |= NETIF_F_HW_VLAN_FILTER;
5853
5854 netdev->features |= NETIF_F_TSO;
5855 netdev->features |= NETIF_F_TSO6;
5856
Jeff Kirshera5136e22008-06-05 04:07:28 -07005857 netdev->vlan_features |= NETIF_F_TSO;
5858 netdev->vlan_features |= NETIF_F_TSO6;
5859 netdev->vlan_features |= NETIF_F_HW_CSUM;
5860 netdev->vlan_features |= NETIF_F_SG;
5861
Yi Zou7b872a52010-09-22 17:57:58 +00005862 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005863 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00005864 netdev->vlan_features |= NETIF_F_HIGHDMA;
5865 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005866
Auke Kokbc7f75f2007-09-17 12:30:59 -07005867 if (e1000e_enable_mng_pass_thru(&adapter->hw))
5868 adapter->flags |= FLAG_MNG_PT_ENABLED;
5869
Bruce Allanad680762008-03-28 09:15:03 -07005870 /*
5871 * before reading the NVM, reset the controller to
5872 * put the device in a known good starting state
5873 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005874 adapter->hw.mac.ops.reset_hw(&adapter->hw);
5875
5876 /*
5877 * systems with ASPM and others may see the checksum fail on the first
5878 * attempt. Let's give it a few tries
5879 */
5880 for (i = 0;; i++) {
5881 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
5882 break;
5883 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005884 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005885 err = -EIO;
5886 goto err_eeprom;
5887 }
5888 }
5889
Auke Kok10aa4c02008-08-04 17:21:20 -07005890 e1000_eeprom_checks(adapter);
5891
Bruce Allan608f8a02010-01-13 02:04:58 +00005892 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005893 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005894 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005895
5896 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
5897 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
5898
5899 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07005900 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005901 err = -EIO;
5902 goto err_eeprom;
5903 }
5904
5905 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005906 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005907 adapter->watchdog_timer.data = (unsigned long) adapter;
5908
5909 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00005910 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005911 adapter->phy_info_timer.data = (unsigned long) adapter;
5912
5913 INIT_WORK(&adapter->reset_task, e1000_reset_task);
5914 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07005915 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
5916 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00005917 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Holger Eitzenberger9633e632010-11-17 15:43:52 +00005918 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005919
Auke Kokbc7f75f2007-09-17 12:30:59 -07005920 /* Initialize link parameters. User can change them with ethtool */
5921 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07005922 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08005923 adapter->hw.fc.requested_mode = e1000_fc_default;
5924 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005925 adapter->hw.phy.autoneg_advertised = 0x2f;
5926
5927 /* ring size defaults */
5928 adapter->rx_ring->count = 256;
5929 adapter->tx_ring->count = 256;
5930
5931 /*
5932 * Initial Wake on LAN setting - If APM wake is enabled in
5933 * the EEPROM, enable the ACPI Magic Packet filter
5934 */
5935 if (adapter->flags & FLAG_APME_IN_WUC) {
5936 /* APME bit in EEPROM is mapped to WUC.APME */
5937 eeprom_data = er32(WUC);
5938 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allana4f58f52009-06-02 11:29:18 +00005939 if (eeprom_data & E1000_WUC_PHY_WAKE)
5940 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005941 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
5942 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
5943 (adapter->hw.bus.func == 1))
5944 e1000_read_nvm(&adapter->hw,
5945 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
5946 else
5947 e1000_read_nvm(&adapter->hw,
5948 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
5949 }
5950
5951 /* fetch WoL from EEPROM */
5952 if (eeprom_data & eeprom_apme_mask)
5953 adapter->eeprom_wol |= E1000_WUFC_MAG;
5954
5955 /*
5956 * now that we have the eeprom settings, apply the special cases
5957 * where the eeprom may be wrong or the board simply won't support
5958 * wake on lan on a particular port
5959 */
5960 if (!(adapter->flags & FLAG_HAS_WOL))
5961 adapter->eeprom_wol = 0;
5962
5963 /* initialize the wol settings based on the eeprom settings */
5964 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00005965 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005966
Bruce Allan84527592008-11-21 17:00:22 -08005967 /* save off EEPROM version number */
5968 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
5969
Auke Kokbc7f75f2007-09-17 12:30:59 -07005970 /* reset the hardware with the new settings */
5971 e1000e_reset(adapter);
5972
Bruce Allanad680762008-03-28 09:15:03 -07005973 /*
5974 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005975 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005976 * under the control of the driver.
5977 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005978 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005979 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005980
Bruce Allane0dc4f12011-01-06 14:29:50 +00005981 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005982 err = register_netdev(netdev);
5983 if (err)
5984 goto err_register;
5985
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00005986 /* carrier off reporting is important to ethtool even BEFORE open */
5987 netif_carrier_off(netdev);
5988
Auke Kokbc7f75f2007-09-17 12:30:59 -07005989 e1000_print_device_info(adapter);
5990
Alan Sternf3ec4f82010-06-08 15:23:51 -04005991 if (pci_dev_run_wake(pdev))
5992 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005993
Auke Kokbc7f75f2007-09-17 12:30:59 -07005994 return 0;
5995
5996err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005997 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005998 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005999err_eeprom:
6000 if (!e1000_check_reset_block(&adapter->hw))
6001 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006002err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006003 kfree(adapter->tx_ring);
6004 kfree(adapter->rx_ring);
6005err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006006 if (adapter->hw.flash_address)
6007 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006008 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006009err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006010 iounmap(adapter->hw.hw_addr);
6011err_ioremap:
6012 free_netdev(netdev);
6013err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006014 pci_release_selected_regions(pdev,
6015 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006016err_pci_reg:
6017err_dma:
6018 pci_disable_device(pdev);
6019 return err;
6020}
6021
6022/**
6023 * e1000_remove - Device Removal Routine
6024 * @pdev: PCI device information struct
6025 *
6026 * e1000_remove is called by the PCI subsystem to alert the driver
6027 * that it should release a PCI device. The could be caused by a
6028 * Hot-Plug event, or because the driver is going to be removed from
6029 * memory.
6030 **/
6031static void __devexit e1000_remove(struct pci_dev *pdev)
6032{
6033 struct net_device *netdev = pci_get_drvdata(pdev);
6034 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006035 bool down = test_bit(__E1000_DOWN, &adapter->state);
6036
Bruce Allanad680762008-03-28 09:15:03 -07006037 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006038 * The timers may be rescheduled, so explicitly disable them
6039 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006040 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006041 if (!down)
6042 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006043 del_timer_sync(&adapter->watchdog_timer);
6044 del_timer_sync(&adapter->phy_info_timer);
6045
Bruce Allan41cec6f2009-11-20 23:28:56 +00006046 cancel_work_sync(&adapter->reset_task);
6047 cancel_work_sync(&adapter->watchdog_task);
6048 cancel_work_sync(&adapter->downshift_task);
6049 cancel_work_sync(&adapter->update_phy_task);
Tejun Heo23f333a2010-12-12 16:45:14 +01006050 cancel_work_sync(&adapter->led_blink_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006051 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006052
Bruce Allan17f208d2009-12-01 15:47:22 +00006053 if (!(netdev->flags & IFF_UP))
6054 e1000_power_down_phy(adapter);
6055
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006056 /* Don't lie to e1000_close() down the road. */
6057 if (!down)
6058 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006059 unregister_netdev(netdev);
6060
Alan Sternf3ec4f82010-06-08 15:23:51 -04006061 if (pci_dev_run_wake(pdev))
6062 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006063
Bruce Allanad680762008-03-28 09:15:03 -07006064 /*
6065 * Release control of h/w to f/w. If f/w is AMT enabled, this
6066 * would have already happened in close and is redundant.
6067 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006068 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006069
Bruce Allan4662e822008-08-26 18:37:06 -07006070 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006071 kfree(adapter->tx_ring);
6072 kfree(adapter->rx_ring);
6073
6074 iounmap(adapter->hw.hw_addr);
6075 if (adapter->hw.flash_address)
6076 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006077 pci_release_selected_regions(pdev,
6078 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006079
6080 free_netdev(netdev);
6081
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006082 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006083 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006084
Auke Kokbc7f75f2007-09-17 12:30:59 -07006085 pci_disable_device(pdev);
6086}
6087
6088/* PCI Error Recovery (ERS) */
6089static struct pci_error_handlers e1000_err_handler = {
6090 .error_detected = e1000_io_error_detected,
6091 .slot_reset = e1000_io_slot_reset,
6092 .resume = e1000_io_resume,
6093};
6094
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006095static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006096 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6097 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6098 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6099 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6100 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6101 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006102 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6103 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6104 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006105
Auke Kokbc7f75f2007-09-17 12:30:59 -07006106 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6107 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6108 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6109 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006110
Auke Kokbc7f75f2007-09-17 12:30:59 -07006111 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6112 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6113 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006114
Bruce Allan4662e822008-08-26 18:37:06 -07006115 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006116 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006117 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006118
Auke Kokbc7f75f2007-09-17 12:30:59 -07006119 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6120 board_80003es2lan },
6121 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6122 board_80003es2lan },
6123 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6124 board_80003es2lan },
6125 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6126 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006127
Auke Kokbc7f75f2007-09-17 12:30:59 -07006128 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6129 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6130 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6131 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6132 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6133 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6134 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006135 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006136
Auke Kokbc7f75f2007-09-17 12:30:59 -07006137 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6138 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6139 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6140 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6141 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006142 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006143 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6144 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6145 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6146
6147 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6148 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6149 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006150
Bruce Allanf4187b52008-08-26 18:36:50 -07006151 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6152 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006153 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006154
Bruce Allana4f58f52009-06-02 11:29:18 +00006155 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6156 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6157 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6158 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6159
Bruce Alland3738bb2010-06-16 13:27:28 +00006160 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6161 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6162
Auke Kokbc7f75f2007-09-17 12:30:59 -07006163 { } /* terminate list */
6164};
6165MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6166
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006167#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006168static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006169 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6170 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6171 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006172};
David S. Millere50208a2010-03-16 23:36:24 -07006173#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006174
Auke Kokbc7f75f2007-09-17 12:30:59 -07006175/* PCI Device API Driver */
6176static struct pci_driver e1000_driver = {
6177 .name = e1000e_driver_name,
6178 .id_table = e1000_pci_tbl,
6179 .probe = e1000_probe,
6180 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006181#ifdef CONFIG_PM_OPS
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006182 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006183#endif
6184 .shutdown = e1000_shutdown,
6185 .err_handler = &e1000_err_handler
6186};
6187
6188/**
6189 * e1000_init_module - Driver Registration Routine
6190 *
6191 * e1000_init_module is the first routine called when the driver is
6192 * loaded. All it does is register with the PCI subsystem.
6193 **/
6194static int __init e1000_init_module(void)
6195{
6196 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006197 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6198 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006199 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006200 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006201
Auke Kokbc7f75f2007-09-17 12:30:59 -07006202 return ret;
6203}
6204module_init(e1000_init_module);
6205
6206/**
6207 * e1000_exit_module - Driver Exit Cleanup Routine
6208 *
6209 * e1000_exit_module is called just before the driver is removed
6210 * from memory.
6211 **/
6212static void __exit e1000_exit_module(void)
6213{
6214 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006215}
6216module_exit(e1000_exit_module);
6217
6218
6219MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6220MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6221MODULE_LICENSE("GPL");
6222MODULE_VERSION(DRV_VERSION);
6223
6224/* e1000_main.c */