blob: 80e69d37b3c771691f78491604185f607d32b15d [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allan8544b9f2010-03-24 12:55:30 +000029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/vmalloc.h>
36#include <linux/pagemap.h>
37#include <linux/delay.h>
38#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000039#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070040#include <linux/tcp.h>
41#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070043#include <net/checksum.h>
44#include <net/ip6_checksum.h>
45#include <linux/mii.h>
46#include <linux/ethtool.h>
47#include <linux/if_vlan.h>
48#include <linux/cpu.h>
49#include <linux/smp.h>
Linus Torvalds7e0bb712011-10-25 15:18:39 +020050#include <linux/pm_qos.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000051#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000052#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040053#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070054
55#include "e1000.h"
56
Bruce Allanb3ccf262011-05-19 01:53:41 +000057#define DRV_EXTRAVERSION "-k"
Bruce Allanc14c6432010-06-16 13:28:34 +000058
Bruce Allanc5778b42011-07-29 05:53:12 +000059#define DRV_VERSION "1.5.1" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070060char e1000e_driver_name[] = "e1000e";
61const char e1000e_driver_version[] = DRV_VERSION;
62
Bruce Allan78cd29d2011-03-24 03:09:03 +000063static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
64
Auke Kokbc7f75f2007-09-17 12:30:59 -070065static const struct e1000_info *e1000_info_tbl[] = {
66 [board_82571] = &e1000_82571_info,
67 [board_82572] = &e1000_82572_info,
68 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070069 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000070 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070071 [board_80003es2lan] = &e1000_es2_info,
72 [board_ich8lan] = &e1000_ich8_info,
73 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070074 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000075 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000076 [board_pch2lan] = &e1000_pch2_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070077};
78
Taku Izumi84f4ee92010-04-27 14:39:08 +000079struct e1000_reg_info {
80 u32 ofs;
81 char *name;
82};
83
Bruce Allanaf667a22010-12-31 06:10:01 +000084#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
85#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
86#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
87#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
88#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000089
Bruce Allanaf667a22010-12-31 06:10:01 +000090#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
91#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
92#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
93#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
94#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000095
96static const struct e1000_reg_info e1000_reg_info_tbl[] = {
97
98 /* General Registers */
99 {E1000_CTRL, "CTRL"},
100 {E1000_STATUS, "STATUS"},
101 {E1000_CTRL_EXT, "CTRL_EXT"},
102
103 /* Interrupt Registers */
104 {E1000_ICR, "ICR"},
105
Bruce Allanaf667a22010-12-31 06:10:01 +0000106 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000107 {E1000_RCTL, "RCTL"},
108 {E1000_RDLEN, "RDLEN"},
109 {E1000_RDH, "RDH"},
110 {E1000_RDT, "RDT"},
111 {E1000_RDTR, "RDTR"},
112 {E1000_RXDCTL(0), "RXDCTL"},
113 {E1000_ERT, "ERT"},
114 {E1000_RDBAL, "RDBAL"},
115 {E1000_RDBAH, "RDBAH"},
116 {E1000_RDFH, "RDFH"},
117 {E1000_RDFT, "RDFT"},
118 {E1000_RDFHS, "RDFHS"},
119 {E1000_RDFTS, "RDFTS"},
120 {E1000_RDFPC, "RDFPC"},
121
Bruce Allanaf667a22010-12-31 06:10:01 +0000122 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000123 {E1000_TCTL, "TCTL"},
124 {E1000_TDBAL, "TDBAL"},
125 {E1000_TDBAH, "TDBAH"},
126 {E1000_TDLEN, "TDLEN"},
127 {E1000_TDH, "TDH"},
128 {E1000_TDT, "TDT"},
129 {E1000_TIDV, "TIDV"},
130 {E1000_TXDCTL(0), "TXDCTL"},
131 {E1000_TADV, "TADV"},
132 {E1000_TARC(0), "TARC"},
133 {E1000_TDFH, "TDFH"},
134 {E1000_TDFT, "TDFT"},
135 {E1000_TDFHS, "TDFHS"},
136 {E1000_TDFTS, "TDFTS"},
137 {E1000_TDFPC, "TDFPC"},
138
139 /* List Terminator */
140 {}
141};
142
143/*
144 * e1000_regdump - register printout routine
145 */
146static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
147{
148 int n = 0;
149 char rname[16];
150 u32 regs[8];
151
152 switch (reginfo->ofs) {
153 case E1000_RXDCTL(0):
154 for (n = 0; n < 2; n++)
155 regs[n] = __er32(hw, E1000_RXDCTL(n));
156 break;
157 case E1000_TXDCTL(0):
158 for (n = 0; n < 2; n++)
159 regs[n] = __er32(hw, E1000_TXDCTL(n));
160 break;
161 case E1000_TARC(0):
162 for (n = 0; n < 2; n++)
163 regs[n] = __er32(hw, E1000_TARC(n));
164 break;
165 default:
166 printk(KERN_INFO "%-15s %08x\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000167 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000168 return;
169 }
170
171 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
172 printk(KERN_INFO "%-15s ", rname);
173 for (n = 0; n < 2; n++)
174 printk(KERN_CONT "%08x ", regs[n]);
175 printk(KERN_CONT "\n");
176}
177
Taku Izumi84f4ee92010-04-27 14:39:08 +0000178/*
Bruce Allanaf667a22010-12-31 06:10:01 +0000179 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Taku Izumi84f4ee92010-04-27 14:39:08 +0000180 */
181static void e1000e_dump(struct e1000_adapter *adapter)
182{
183 struct net_device *netdev = adapter->netdev;
184 struct e1000_hw *hw = &adapter->hw;
185 struct e1000_reg_info *reginfo;
186 struct e1000_ring *tx_ring = adapter->tx_ring;
187 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000188 struct my_u0 {
189 u64 a;
190 u64 b;
191 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000192 struct e1000_buffer *buffer_info;
193 struct e1000_ring *rx_ring = adapter->rx_ring;
194 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000195 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000196 struct my_u1 {
197 u64 a;
198 u64 b;
199 u64 c;
200 u64 d;
201 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000202 u32 staterr;
203 int i = 0;
204
205 if (!netif_msg_hw(adapter))
206 return;
207
208 /* Print netdevice Info */
209 if (netdev) {
210 dev_info(&adapter->pdev->dev, "Net device Info\n");
211 printk(KERN_INFO "Device Name state "
Bruce Allanaf667a22010-12-31 06:10:01 +0000212 "trans_start last_rx\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000213 printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000214 netdev->name, netdev->state, netdev->trans_start,
215 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000216 }
217
218 /* Print Registers */
219 dev_info(&adapter->pdev->dev, "Register Dump\n");
220 printk(KERN_INFO " Register Name Value\n");
221 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
222 reginfo->name; reginfo++) {
223 e1000_regdump(hw, reginfo);
224 }
225
Bruce Allanaf667a22010-12-31 06:10:01 +0000226 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000227 if (!netdev || !netif_running(netdev))
228 goto exit;
229
Bruce Allanaf667a22010-12-31 06:10:01 +0000230 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000231 printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000232 " leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000233 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
234 printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
Bruce Allanaf667a22010-12-31 06:10:01 +0000235 0, tx_ring->next_to_use, tx_ring->next_to_clean,
236 (unsigned long long)buffer_info->dma,
237 buffer_info->length,
238 buffer_info->next_to_watch,
239 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000240
Bruce Allanaf667a22010-12-31 06:10:01 +0000241 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000242 if (!netif_msg_tx_done(adapter))
243 goto rx_ring_summary;
244
Bruce Allanaf667a22010-12-31 06:10:01 +0000245 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000246
247 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
248 *
249 * Legacy Transmit Descriptor
250 * +--------------------------------------------------------------+
251 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
252 * +--------------------------------------------------------------+
253 * 8 | Special | CSS | Status | CMD | CSO | Length |
254 * +--------------------------------------------------------------+
255 * 63 48 47 36 35 32 31 24 23 16 15 0
256 *
257 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
258 * 63 48 47 40 39 32 31 16 15 8 7 0
259 * +----------------------------------------------------------------+
260 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
261 * +----------------------------------------------------------------+
262 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
263 * +----------------------------------------------------------------+
264 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
265 *
266 * Extended Data Descriptor (DTYP=0x1)
267 * +----------------------------------------------------------------+
268 * 0 | Buffer Address [63:0] |
269 * +----------------------------------------------------------------+
270 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
271 * +----------------------------------------------------------------+
272 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
273 */
274 printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000275 " [bi->dma ] leng ntw timestamp bi->skb "
276 "<-- Legacy format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000277 printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000278 " [bi->dma ] leng ntw timestamp bi->skb "
279 "<-- Ext Context format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000280 printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]"
Bruce Allanaf667a22010-12-31 06:10:01 +0000281 " [bi->dma ] leng ntw timestamp bi->skb "
282 "<-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000283 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
284 tx_desc = E1000_TX_DESC(*tx_ring, i);
285 buffer_info = &tx_ring->buffer_info[i];
286 u0 = (struct my_u0 *)tx_desc;
287 printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000288 "%04X %3X %016llX %p",
289 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
290 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), i,
Bruce Allan8eb64e62010-06-29 18:12:30 +0000291 (unsigned long long)le64_to_cpu(u0->a),
292 (unsigned long long)le64_to_cpu(u0->b),
293 (unsigned long long)buffer_info->dma,
294 buffer_info->length, buffer_info->next_to_watch,
295 (unsigned long long)buffer_info->time_stamp,
Taku Izumi84f4ee92010-04-27 14:39:08 +0000296 buffer_info->skb);
297 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
298 printk(KERN_CONT " NTC/U\n");
299 else if (i == tx_ring->next_to_use)
300 printk(KERN_CONT " NTU\n");
301 else if (i == tx_ring->next_to_clean)
302 printk(KERN_CONT " NTC\n");
303 else
304 printk(KERN_CONT "\n");
305
306 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
307 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Bruce Allanaf667a22010-12-31 06:10:01 +0000308 16, 1, phys_to_virt(buffer_info->dma),
309 buffer_info->length, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000310 }
311
Bruce Allanaf667a22010-12-31 06:10:01 +0000312 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000313rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000314 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000315 printk(KERN_INFO "Queue [NTU] [NTC]\n");
316 printk(KERN_INFO " %5d %5X %5X\n", 0,
Bruce Allanaf667a22010-12-31 06:10:01 +0000317 rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000318
Bruce Allanaf667a22010-12-31 06:10:01 +0000319 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000320 if (!netif_msg_rx_status(adapter))
321 goto exit;
322
Bruce Allanaf667a22010-12-31 06:10:01 +0000323 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000324 switch (adapter->rx_ps_pages) {
325 case 1:
326 case 2:
327 case 3:
328 /* [Extended] Packet Split Receive Descriptor Format
329 *
330 * +-----------------------------------------------------+
331 * 0 | Buffer Address 0 [63:0] |
332 * +-----------------------------------------------------+
333 * 8 | Buffer Address 1 [63:0] |
334 * +-----------------------------------------------------+
335 * 16 | Buffer Address 2 [63:0] |
336 * +-----------------------------------------------------+
337 * 24 | Buffer Address 3 [63:0] |
338 * +-----------------------------------------------------+
339 */
340 printk(KERN_INFO "R [desc] [buffer 0 63:0 ] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000341 "[buffer 1 63:0 ] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000342 "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] "
343 "[bi->skb] <-- Ext Pkt Split format\n");
344 /* [Extended] Receive Descriptor (Write-Back) Format
345 *
346 * 63 48 47 32 31 13 12 8 7 4 3 0
347 * +------------------------------------------------------+
348 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
349 * | Checksum | Ident | | Queue | | Type |
350 * +------------------------------------------------------+
351 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
352 * +------------------------------------------------------+
353 * 63 48 47 32 31 20 19 0
354 */
355 printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] "
Bruce Allanaf667a22010-12-31 06:10:01 +0000356 "[vl l0 ee es] "
Taku Izumi84f4ee92010-04-27 14:39:08 +0000357 "[ l3 l2 l1 hs] [reserved ] ---------------- "
358 "[bi->skb] <-- Ext Rx Write-Back format\n");
359 for (i = 0; i < rx_ring->count; i++) {
360 buffer_info = &rx_ring->buffer_info[i];
361 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
362 u1 = (struct my_u1 *)rx_desc_ps;
363 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000364 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000365 if (staterr & E1000_RXD_STAT_DD) {
366 /* Descriptor Done */
367 printk(KERN_INFO "RWB[0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000368 "%016llX %016llX %016llX "
369 "---------------- %p", i,
370 (unsigned long long)le64_to_cpu(u1->a),
371 (unsigned long long)le64_to_cpu(u1->b),
372 (unsigned long long)le64_to_cpu(u1->c),
373 (unsigned long long)le64_to_cpu(u1->d),
374 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000375 } else {
376 printk(KERN_INFO "R [0x%03X] %016llX "
Bruce Allanaf667a22010-12-31 06:10:01 +0000377 "%016llX %016llX %016llX %016llX %p", i,
378 (unsigned long long)le64_to_cpu(u1->a),
379 (unsigned long long)le64_to_cpu(u1->b),
380 (unsigned long long)le64_to_cpu(u1->c),
381 (unsigned long long)le64_to_cpu(u1->d),
382 (unsigned long long)buffer_info->dma,
383 buffer_info->skb);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000384
385 if (netif_msg_pktdata(adapter))
386 print_hex_dump(KERN_INFO, "",
387 DUMP_PREFIX_ADDRESS, 16, 1,
388 phys_to_virt(buffer_info->dma),
389 adapter->rx_ps_bsize0, true);
390 }
391
392 if (i == rx_ring->next_to_use)
393 printk(KERN_CONT " NTU\n");
394 else if (i == rx_ring->next_to_clean)
395 printk(KERN_CONT " NTC\n");
396 else
397 printk(KERN_CONT "\n");
398 }
399 break;
400 default:
401 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000402 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000403 *
Bruce Allan5f450212011-07-22 06:21:46 +0000404 * +-----------------------------------------------------+
405 * 0 | Buffer Address [63:0] |
406 * +-----------------------------------------------------+
407 * 8 | Reserved |
408 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000409 */
Bruce Allan5f450212011-07-22 06:21:46 +0000410 printk(KERN_INFO "R [desc] [buf addr 63:0 ] "
411 "[reserved 63:0 ] [bi->dma ] "
412 "[bi->skb] <-- Ext (Read) format\n");
413 /* Extended Receive Descriptor (Write-Back) Format
414 *
415 * 63 48 47 32 31 24 23 4 3 0
416 * +------------------------------------------------------+
417 * | RSS Hash | | | |
418 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
419 * | Packet | IP | | | Type |
420 * | Checksum | Ident | | | |
421 * +------------------------------------------------------+
422 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
423 * +------------------------------------------------------+
424 * 63 48 47 32 31 20 19 0
425 */
426 printk(KERN_INFO "RWB[desc] [cs ipid mrq] "
427 "[vt ln xe xs] "
428 "[bi->skb] <-- Ext (Write-Back) format\n");
429
430 for (i = 0; i < rx_ring->count; i++) {
Taku Izumi84f4ee92010-04-27 14:39:08 +0000431 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000432 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
433 u1 = (struct my_u1 *)rx_desc;
434 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
435 if (staterr & E1000_RXD_STAT_DD) {
436 /* Descriptor Done */
437 printk(KERN_INFO "RWB[0x%03X] %016llX "
438 "%016llX ---------------- %p", i,
439 (unsigned long long)le64_to_cpu(u1->a),
440 (unsigned long long)le64_to_cpu(u1->b),
441 buffer_info->skb);
442 } else {
443 printk(KERN_INFO "R [0x%03X] %016llX "
444 "%016llX %016llX %p", i,
445 (unsigned long long)le64_to_cpu(u1->a),
446 (unsigned long long)le64_to_cpu(u1->b),
447 (unsigned long long)buffer_info->dma,
448 buffer_info->skb);
449
450 if (netif_msg_pktdata(adapter))
451 print_hex_dump(KERN_INFO, "",
452 DUMP_PREFIX_ADDRESS, 16,
453 1,
454 phys_to_virt
455 (buffer_info->dma),
456 adapter->rx_buffer_len,
457 true);
458 }
459
Taku Izumi84f4ee92010-04-27 14:39:08 +0000460 if (i == rx_ring->next_to_use)
461 printk(KERN_CONT " NTU\n");
462 else if (i == rx_ring->next_to_clean)
463 printk(KERN_CONT " NTC\n");
464 else
465 printk(KERN_CONT "\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000466 }
467 }
468
469exit:
470 return;
471}
472
Auke Kokbc7f75f2007-09-17 12:30:59 -0700473/**
474 * e1000_desc_unused - calculate if we have unused descriptors
475 **/
476static int e1000_desc_unused(struct e1000_ring *ring)
477{
478 if (ring->next_to_clean > ring->next_to_use)
479 return ring->next_to_clean - ring->next_to_use - 1;
480
481 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
482}
483
484/**
Bruce Allanad680762008-03-28 09:15:03 -0700485 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700486 * @adapter: board private structure
487 * @status: descriptor status field as written by hardware
488 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
489 * @skb: pointer to sk_buff to be indicated to stack
490 **/
491static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000492 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000493 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700494{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000495 u16 tag = le16_to_cpu(vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700496 skb->protocol = eth_type_trans(skb, netdev);
497
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000498 if (status & E1000_RXD_STAT_VP)
499 __vlan_hwaccel_put_tag(skb, tag);
500
501 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700502}
503
504/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000505 * e1000_rx_checksum - Receive Checksum Offload
Auke Kokbc7f75f2007-09-17 12:30:59 -0700506 * @adapter: board private structure
507 * @status_err: receive descriptor status and error fields
508 * @csum: receive descriptor csum field
509 * @sk_buff: socket buffer with received data
510 **/
511static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
512 u32 csum, struct sk_buff *skb)
513{
514 u16 status = (u16)status_err;
515 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700516
517 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700518
519 /* Ignore Checksum bit is set */
520 if (status & E1000_RXD_STAT_IXSM)
521 return;
522 /* TCP/UDP checksum error bit is set */
523 if (errors & E1000_RXD_ERR_TCPE) {
524 /* let the stack verify checksum errors */
525 adapter->hw_csum_err++;
526 return;
527 }
528
529 /* TCP/UDP Checksum has not been calculated */
530 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
531 return;
532
533 /* It must be a TCP or UDP packet with a valid checksum */
534 if (status & E1000_RXD_STAT_TCPCS) {
535 /* TCP checksum is good */
536 skb->ip_summed = CHECKSUM_UNNECESSARY;
537 } else {
Bruce Allanad680762008-03-28 09:15:03 -0700538 /*
539 * IP fragment with UDP payload
540 * Hardware complements the payload checksum, so we undo it
Auke Kokbc7f75f2007-09-17 12:30:59 -0700541 * and then put the value in host order for further stack use.
542 */
Al Viroa39fe742007-12-11 19:50:34 +0000543 __sum16 sum = (__force __sum16)htons(csum);
544 skb->csum = csum_unfold(~sum);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700545 skb->ip_summed = CHECKSUM_COMPLETE;
546 }
547 adapter->hw_csum_good++;
548}
549
550/**
David S. Miller823dcd22011-08-20 10:39:12 -0700551 * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa()
552 * @hw: pointer to the HW structure
553 * @tail: address of tail descriptor register
554 * @i: value to write to tail descriptor register
555 *
556 * When updating the tail register, the ME could be accessing Host CSR
557 * registers at the same time. Normally, this is handled in h/w by an
558 * arbiter but on some parts there is a bug that acknowledges Host accesses
559 * later than it should which could result in the descriptor register to
560 * have an incorrect value. Workaround this by checking the FWSM register
561 * which has bit 24 set while ME is accessing Host CSR registers, wait
562 * if it is set and try again a number of times.
563 **/
564static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, u8 __iomem * tail,
565 unsigned int i)
566{
567 unsigned int j = 0;
568
569 while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) &&
570 (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI))
571 udelay(50);
572
573 writel(i, tail);
574
575 if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail)))
576 return E1000_ERR_SWFW_SYNC;
577
578 return 0;
579}
580
581static void e1000e_update_rdt_wa(struct e1000_adapter *adapter, unsigned int i)
582{
583 u8 __iomem *tail = (adapter->hw.hw_addr + adapter->rx_ring->tail);
584 struct e1000_hw *hw = &adapter->hw;
585
586 if (e1000e_update_tail_wa(hw, tail, i)) {
587 u32 rctl = er32(RCTL);
588 ew32(RCTL, rctl & ~E1000_RCTL_EN);
589 e_err("ME firmware caused invalid RDT - resetting\n");
590 schedule_work(&adapter->reset_task);
591 }
592}
593
594static void e1000e_update_tdt_wa(struct e1000_adapter *adapter, unsigned int i)
595{
596 u8 __iomem *tail = (adapter->hw.hw_addr + adapter->tx_ring->tail);
597 struct e1000_hw *hw = &adapter->hw;
598
599 if (e1000e_update_tail_wa(hw, tail, i)) {
600 u32 tctl = er32(TCTL);
601 ew32(TCTL, tctl & ~E1000_TCTL_EN);
602 e_err("ME firmware caused invalid TDT - resetting\n");
603 schedule_work(&adapter->reset_task);
604 }
605}
606
607/**
Bruce Allan5f450212011-07-22 06:21:46 +0000608 * e1000_alloc_rx_buffers - Replace used receive buffers
Auke Kokbc7f75f2007-09-17 12:30:59 -0700609 * @adapter: address of board private structure
610 **/
611static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000612 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613{
614 struct net_device *netdev = adapter->netdev;
615 struct pci_dev *pdev = adapter->pdev;
616 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +0000617 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700618 struct e1000_buffer *buffer_info;
619 struct sk_buff *skb;
620 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000621 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700622
623 i = rx_ring->next_to_use;
624 buffer_info = &rx_ring->buffer_info[i];
625
626 while (cleaned_count--) {
627 skb = buffer_info->skb;
628 if (skb) {
629 skb_trim(skb, 0);
630 goto map_skb;
631 }
632
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000633 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700634 if (!skb) {
635 /* Better luck next round */
636 adapter->alloc_rx_buff_failed++;
637 break;
638 }
639
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640 buffer_info->skb = skb;
641map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000642 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700643 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000644 DMA_FROM_DEVICE);
645 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000646 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700647 adapter->rx_dma_failed++;
648 break;
649 }
650
Bruce Allan5f450212011-07-22 06:21:46 +0000651 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
652 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700653
Tom Herbert50849d72010-05-05 14:02:49 +0000654 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
655 /*
656 * Force memory writes to complete before letting h/w
657 * know there are new descriptors to fetch. (Only
658 * applicable for weak-ordered memory model archs,
659 * such as IA-64).
660 */
661 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700662 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
663 e1000e_update_rdt_wa(adapter, i);
664 else
665 writel(i, adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000666 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700667 i++;
668 if (i == rx_ring->count)
669 i = 0;
670 buffer_info = &rx_ring->buffer_info[i];
671 }
672
Tom Herbert50849d72010-05-05 14:02:49 +0000673 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674}
675
676/**
677 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
678 * @adapter: address of board private structure
679 **/
680static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000681 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700682{
683 struct net_device *netdev = adapter->netdev;
684 struct pci_dev *pdev = adapter->pdev;
685 union e1000_rx_desc_packet_split *rx_desc;
686 struct e1000_ring *rx_ring = adapter->rx_ring;
687 struct e1000_buffer *buffer_info;
688 struct e1000_ps_page *ps_page;
689 struct sk_buff *skb;
690 unsigned int i, j;
691
692 i = rx_ring->next_to_use;
693 buffer_info = &rx_ring->buffer_info[i];
694
695 while (cleaned_count--) {
696 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
697
698 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700699 ps_page = &buffer_info->ps_pages[j];
700 if (j >= adapter->rx_ps_pages) {
701 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000702 rx_desc->read.buffer_addr[j + 1] =
703 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700704 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705 }
Auke Kok47f44e42007-10-25 13:57:44 -0700706 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000707 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700708 if (!ps_page->page) {
709 adapter->alloc_rx_buff_failed++;
710 goto no_buffers;
711 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000712 ps_page->dma = dma_map_page(&pdev->dev,
713 ps_page->page,
714 0, PAGE_SIZE,
715 DMA_FROM_DEVICE);
716 if (dma_mapping_error(&pdev->dev,
717 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700718 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000719 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700720 adapter->rx_dma_failed++;
721 goto no_buffers;
722 }
723 }
724 /*
725 * Refresh the desc even if buffer_addrs
726 * didn't change because each write-back
727 * erases this info.
728 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000729 rx_desc->read.buffer_addr[j + 1] =
730 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700731 }
732
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000733 skb = __netdev_alloc_skb_ip_align(netdev,
734 adapter->rx_ps_bsize0,
735 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700736
737 if (!skb) {
738 adapter->alloc_rx_buff_failed++;
739 break;
740 }
741
Auke Kokbc7f75f2007-09-17 12:30:59 -0700742 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000743 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700744 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000745 DMA_FROM_DEVICE);
746 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000747 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700748 adapter->rx_dma_failed++;
749 /* cleanup skb */
750 dev_kfree_skb_any(skb);
751 buffer_info->skb = NULL;
752 break;
753 }
754
755 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
756
Tom Herbert50849d72010-05-05 14:02:49 +0000757 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
758 /*
759 * Force memory writes to complete before letting h/w
760 * know there are new descriptors to fetch. (Only
761 * applicable for weak-ordered memory model archs,
762 * such as IA-64).
763 */
764 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700765 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
766 e1000e_update_rdt_wa(adapter, i << 1);
767 else
768 writel(i << 1,
769 adapter->hw.hw_addr + rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000770 }
771
Auke Kokbc7f75f2007-09-17 12:30:59 -0700772 i++;
773 if (i == rx_ring->count)
774 i = 0;
775 buffer_info = &rx_ring->buffer_info[i];
776 }
777
778no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000779 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700780}
781
782/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700783 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
784 * @adapter: address of board private structure
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700785 * @cleaned_count: number of buffers to allocate this pass
786 **/
787
788static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000789 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700790{
791 struct net_device *netdev = adapter->netdev;
792 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000793 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700794 struct e1000_ring *rx_ring = adapter->rx_ring;
795 struct e1000_buffer *buffer_info;
796 struct sk_buff *skb;
797 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000798 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700799
800 i = rx_ring->next_to_use;
801 buffer_info = &rx_ring->buffer_info[i];
802
803 while (cleaned_count--) {
804 skb = buffer_info->skb;
805 if (skb) {
806 skb_trim(skb, 0);
807 goto check_page;
808 }
809
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000810 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700811 if (unlikely(!skb)) {
812 /* Better luck next round */
813 adapter->alloc_rx_buff_failed++;
814 break;
815 }
816
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700817 buffer_info->skb = skb;
818check_page:
819 /* allocate a new page if necessary */
820 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000821 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700822 if (unlikely(!buffer_info->page)) {
823 adapter->alloc_rx_buff_failed++;
824 break;
825 }
826 }
827
828 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000829 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700830 buffer_info->page, 0,
831 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000832 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700833
Bruce Allan5f450212011-07-22 06:21:46 +0000834 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
835 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700836
837 if (unlikely(++i == rx_ring->count))
838 i = 0;
839 buffer_info = &rx_ring->buffer_info[i];
840 }
841
842 if (likely(rx_ring->next_to_use != i)) {
843 rx_ring->next_to_use = i;
844 if (unlikely(i-- == 0))
845 i = (rx_ring->count - 1);
846
847 /* Force memory writes to complete before letting h/w
848 * know there are new descriptors to fetch. (Only
849 * applicable for weak-ordered memory model archs,
850 * such as IA-64). */
851 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700852 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
853 e1000e_update_rdt_wa(adapter, i);
854 else
855 writel(i, adapter->hw.hw_addr + rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700856 }
857}
858
859/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860 * e1000_clean_rx_irq - Send received data up the network stack; legacy
861 * @adapter: board private structure
862 *
863 * the return value indicates whether actual cleaning was done, there
864 * is no guarantee that everything was cleaned
865 **/
866static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
867 int *work_done, int work_to_do)
868{
869 struct net_device *netdev = adapter->netdev;
870 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000871 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700872 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +0000873 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700874 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000875 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700876 unsigned int i;
877 int cleaned_count = 0;
878 bool cleaned = 0;
879 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
880
881 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000882 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
883 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700884 buffer_info = &rx_ring->buffer_info[i];
885
Bruce Allan5f450212011-07-22 06:21:46 +0000886 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700887 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700888
889 if (*work_done >= work_to_do)
890 break;
891 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000892 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700893
Auke Kokbc7f75f2007-09-17 12:30:59 -0700894 skb = buffer_info->skb;
895 buffer_info->skb = NULL;
896
897 prefetch(skb->data - NET_IP_ALIGN);
898
899 i++;
900 if (i == rx_ring->count)
901 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000902 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700903 prefetch(next_rxd);
904
905 next_buffer = &rx_ring->buffer_info[i];
906
907 cleaned = 1;
908 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000909 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700910 buffer_info->dma,
911 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000912 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700913 buffer_info->dma = 0;
914
Bruce Allan5f450212011-07-22 06:21:46 +0000915 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700916
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000917 /*
918 * !EOP means multiple descriptors were used to store a single
919 * packet, if that's the case we need to toss it. In fact, we
920 * need to toss every packet with the EOP bit clear and the
921 * next frame that _does_ have the EOP bit set, as it is by
922 * definition only a frame fragment
923 */
Bruce Allan5f450212011-07-22 06:21:46 +0000924 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000925 adapter->flags2 |= FLAG2_IS_DISCARDING;
926
927 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700928 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000929 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700930 /* recycle */
931 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000932 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000933 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700934 goto next_desc;
935 }
936
Bruce Allan5f450212011-07-22 06:21:46 +0000937 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700938 /* recycle */
939 buffer_info->skb = skb;
940 goto next_desc;
941 }
942
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000943 /* adjust length to remove Ethernet CRC */
944 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
945 length -= 4;
946
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947 total_rx_bytes += length;
948 total_rx_packets++;
949
Bruce Allanad680762008-03-28 09:15:03 -0700950 /*
951 * code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700953 * of reassembly being done in the stack
954 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700955 if (length < copybreak) {
956 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000957 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700958 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700959 skb_copy_to_linear_data_offset(new_skb,
960 -NET_IP_ALIGN,
961 (skb->data -
962 NET_IP_ALIGN),
963 (length +
964 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700965 /* save the skb in buffer_info as good */
966 buffer_info->skb = skb;
967 skb = new_skb;
968 }
969 /* else just continue with the old one */
970 }
971 /* end copybreak code */
972 skb_put(skb, length);
973
974 /* Receive Checksum Offload */
Bruce Allan5f450212011-07-22 06:21:46 +0000975 e1000_rx_checksum(adapter, staterr,
976 le16_to_cpu(rx_desc->wb.lower.hi_dword.
977 csum_ip.csum), skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978
Bruce Allan5f450212011-07-22 06:21:46 +0000979 e1000_receive_skb(adapter, netdev, skb, staterr,
980 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700981
982next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +0000983 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700984
985 /* return some buffers to hardware, one at a time is too slow */
986 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000987 adapter->alloc_rx_buf(adapter, cleaned_count,
988 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700989 cleaned_count = 0;
990 }
991
992 /* use prefetched values */
993 rx_desc = next_rxd;
994 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000995
996 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700997 }
998 rx_ring->next_to_clean = i;
999
1000 cleaned_count = e1000_desc_unused(rx_ring);
1001 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001002 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003
Auke Kokbc7f75f2007-09-17 12:30:59 -07001004 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001005 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001006 return cleaned;
1007}
1008
Auke Kokbc7f75f2007-09-17 12:30:59 -07001009static void e1000_put_txbuf(struct e1000_adapter *adapter,
1010 struct e1000_buffer *buffer_info)
1011{
Alexander Duyck03b13202009-12-02 16:45:31 +00001012 if (buffer_info->dma) {
1013 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001014 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1015 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001016 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001017 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1018 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001019 buffer_info->dma = 0;
1020 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001021 if (buffer_info->skb) {
1022 dev_kfree_skb_any(buffer_info->skb);
1023 buffer_info->skb = NULL;
1024 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001025 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026}
1027
Bruce Allan41cec6f2009-11-20 23:28:56 +00001028static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001029{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001030 struct e1000_adapter *adapter = container_of(work,
1031 struct e1000_adapter,
1032 print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001033 struct e1000_ring *tx_ring = adapter->tx_ring;
1034 unsigned int i = tx_ring->next_to_clean;
1035 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1036 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001037 struct e1000_hw *hw = &adapter->hw;
1038 u16 phy_status, phy_1000t_status, phy_ext_status;
1039 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001041 if (test_bit(__E1000_DOWN, &adapter->state))
1042 return;
1043
Bruce Allan41cec6f2009-11-20 23:28:56 +00001044 e1e_rphy(hw, PHY_STATUS, &phy_status);
1045 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1046 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1047
1048 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1049
1050 /* detected Hardware unit hang */
1051 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001052 " TDH <%x>\n"
1053 " TDT <%x>\n"
1054 " next_to_use <%x>\n"
1055 " next_to_clean <%x>\n"
1056 "buffer_info[next_to_clean]:\n"
1057 " time_stamp <%lx>\n"
1058 " next_to_watch <%x>\n"
1059 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001060 " next_to_watch.status <%x>\n"
1061 "MAC Status <%x>\n"
1062 "PHY Status <%x>\n"
1063 "PHY 1000BASE-T Status <%x>\n"
1064 "PHY Extended Status <%x>\n"
1065 "PCI Status <%x>\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001066 readl(adapter->hw.hw_addr + tx_ring->head),
1067 readl(adapter->hw.hw_addr + tx_ring->tail),
1068 tx_ring->next_to_use,
1069 tx_ring->next_to_clean,
1070 tx_ring->buffer_info[eop].time_stamp,
1071 eop,
1072 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001073 eop_desc->upper.fields.status,
1074 er32(STATUS),
1075 phy_status,
1076 phy_1000t_status,
1077 phy_ext_status,
1078 pci_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001079}
1080
1081/**
1082 * e1000_clean_tx_irq - Reclaim resources after transmit completes
1083 * @adapter: board private structure
1084 *
1085 * the return value indicates whether actual cleaning was done, there
1086 * is no guarantee that everything was cleaned
1087 **/
1088static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
1089{
1090 struct net_device *netdev = adapter->netdev;
1091 struct e1000_hw *hw = &adapter->hw;
1092 struct e1000_ring *tx_ring = adapter->tx_ring;
1093 struct e1000_tx_desc *tx_desc, *eop_desc;
1094 struct e1000_buffer *buffer_info;
1095 unsigned int i, eop;
1096 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
1098
1099 i = tx_ring->next_to_clean;
1100 eop = tx_ring->buffer_info[i].next_to_watch;
1101 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1102
Alexander Duyck12d04a32009-03-25 22:05:03 +00001103 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1104 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001105 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001106 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001107 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001108 tx_desc = E1000_TX_DESC(*tx_ring, i);
1109 buffer_info = &tx_ring->buffer_info[i];
1110 cleaned = (i == eop);
1111
1112 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001113 total_tx_packets += buffer_info->segs;
1114 total_tx_bytes += buffer_info->bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115 }
1116
1117 e1000_put_txbuf(adapter, buffer_info);
1118 tx_desc->upper.data = 0;
1119
1120 i++;
1121 if (i == tx_ring->count)
1122 i = 0;
1123 }
1124
Terry Loftindac87612010-04-09 10:29:49 +00001125 if (i == tx_ring->next_to_use)
1126 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127 eop = tx_ring->buffer_info[i].next_to_watch;
1128 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129 }
1130
1131 tx_ring->next_to_clean = i;
1132
1133#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001134 if (count && netif_carrier_ok(netdev) &&
1135 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001136 /* Make sure that anybody stopping the queue after this
1137 * sees the new next_to_clean.
1138 */
1139 smp_mb();
1140
1141 if (netif_queue_stopped(netdev) &&
1142 !(test_bit(__E1000_DOWN, &adapter->state))) {
1143 netif_wake_queue(netdev);
1144 ++adapter->restart_queue;
1145 }
1146 }
1147
1148 if (adapter->detect_tx_hung) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001149 /*
1150 * Detect a transmit hang in hardware, this serializes the
1151 * check with the clearing of time_stamp and movement of i
1152 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001153 adapter->detect_tx_hung = 0;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001154 if (tx_ring->buffer_info[i].time_stamp &&
1155 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001156 + (adapter->tx_timeout_factor * HZ)) &&
1157 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Bruce Allan41cec6f2009-11-20 23:28:56 +00001158 schedule_work(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001159 netif_stop_queue(netdev);
1160 }
1161 }
1162 adapter->total_tx_bytes += total_tx_bytes;
1163 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001164 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001165}
1166
1167/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001168 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
1169 * @adapter: board private structure
1170 *
1171 * the return value indicates whether actual cleaning was done, there
1172 * is no guarantee that everything was cleaned
1173 **/
1174static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1175 int *work_done, int work_to_do)
1176{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001177 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001178 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1179 struct net_device *netdev = adapter->netdev;
1180 struct pci_dev *pdev = adapter->pdev;
1181 struct e1000_ring *rx_ring = adapter->rx_ring;
1182 struct e1000_buffer *buffer_info, *next_buffer;
1183 struct e1000_ps_page *ps_page;
1184 struct sk_buff *skb;
1185 unsigned int i, j;
1186 u32 length, staterr;
1187 int cleaned_count = 0;
1188 bool cleaned = 0;
1189 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1190
1191 i = rx_ring->next_to_clean;
1192 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1193 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1194 buffer_info = &rx_ring->buffer_info[i];
1195
1196 while (staterr & E1000_RXD_STAT_DD) {
1197 if (*work_done >= work_to_do)
1198 break;
1199 (*work_done)++;
1200 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001201 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202
1203 /* in the packet split case this is header only */
1204 prefetch(skb->data - NET_IP_ALIGN);
1205
1206 i++;
1207 if (i == rx_ring->count)
1208 i = 0;
1209 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1210 prefetch(next_rxd);
1211
1212 next_buffer = &rx_ring->buffer_info[i];
1213
1214 cleaned = 1;
1215 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001216 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001217 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001218 buffer_info->dma = 0;
1219
Bruce Allanaf667a22010-12-31 06:10:01 +00001220 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001221 if (!(staterr & E1000_RXD_STAT_EOP))
1222 adapter->flags2 |= FLAG2_IS_DISCARDING;
1223
1224 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001225 e_dbg("Packet Split buffers didn't pick up the full "
1226 "packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001227 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001228 if (staterr & E1000_RXD_STAT_EOP)
1229 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001230 goto next_desc;
1231 }
1232
1233 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
1234 dev_kfree_skb_irq(skb);
1235 goto next_desc;
1236 }
1237
1238 length = le16_to_cpu(rx_desc->wb.middle.length0);
1239
1240 if (!length) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001241 e_dbg("Last part of the packet spanning multiple "
1242 "descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001243 dev_kfree_skb_irq(skb);
1244 goto next_desc;
1245 }
1246
1247 /* Good Receive */
1248 skb_put(skb, length);
1249
1250 {
Bruce Allanad680762008-03-28 09:15:03 -07001251 /*
1252 * this looks ugly, but it seems compiler issues make it
1253 * more efficient than reusing j
1254 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001255 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
1256
Bruce Allanad680762008-03-28 09:15:03 -07001257 /*
1258 * page alloc/put takes too long and effects small packet
1259 * throughput, so unsplit small packets and save the alloc/put
1260 * only valid in softirq (napi) context to call kmap_*
1261 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001262 if (l1 && (l1 <= copybreak) &&
1263 ((length + l1) <= adapter->rx_ps_bsize0)) {
1264 u8 *vaddr;
1265
Auke Kok47f44e42007-10-25 13:57:44 -07001266 ps_page = &buffer_info->ps_pages[0];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001267
Bruce Allanad680762008-03-28 09:15:03 -07001268 /*
1269 * there is no documentation about how to call
Auke Kokbc7f75f2007-09-17 12:30:59 -07001270 * kmap_atomic, so we can't hold the mapping
Bruce Allanad680762008-03-28 09:15:03 -07001271 * very long
1272 */
Nick Nunley0be3f552010-04-27 13:09:05 +00001273 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
1274 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001275 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
1276 memcpy(skb_tail_pointer(skb), vaddr, l1);
1277 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
Nick Nunley0be3f552010-04-27 13:09:05 +00001278 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
1279 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kok140a7482007-10-25 13:57:58 -07001280
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001281 /* remove the CRC */
1282 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1283 l1 -= 4;
1284
Auke Kokbc7f75f2007-09-17 12:30:59 -07001285 skb_put(skb, l1);
1286 goto copydone;
1287 } /* if */
1288 }
1289
1290 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1291 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1292 if (!length)
1293 break;
1294
Auke Kok47f44e42007-10-25 13:57:44 -07001295 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001296 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1297 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001298 ps_page->dma = 0;
1299 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1300 ps_page->page = NULL;
1301 skb->len += length;
1302 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001303 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001304 }
1305
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001306 /* strip the ethernet crc, problem is we're using pages now so
1307 * this whole operation can get a little cpu intensive
1308 */
1309 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
1310 pskb_trim(skb, skb->len - 4);
1311
Auke Kokbc7f75f2007-09-17 12:30:59 -07001312copydone:
1313 total_rx_bytes += skb->len;
1314 total_rx_packets++;
1315
1316 e1000_rx_checksum(adapter, staterr, le16_to_cpu(
1317 rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
1318
1319 if (rx_desc->wb.upper.header_status &
1320 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1321 adapter->rx_hdr_split++;
1322
1323 e1000_receive_skb(adapter, netdev, skb,
1324 staterr, rx_desc->wb.middle.vlan);
1325
1326next_desc:
1327 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1328 buffer_info->skb = NULL;
1329
1330 /* return some buffers to hardware, one at a time is too slow */
1331 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001332 adapter->alloc_rx_buf(adapter, cleaned_count,
1333 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001334 cleaned_count = 0;
1335 }
1336
1337 /* use prefetched values */
1338 rx_desc = next_rxd;
1339 buffer_info = next_buffer;
1340
1341 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1342 }
1343 rx_ring->next_to_clean = i;
1344
1345 cleaned_count = e1000_desc_unused(rx_ring);
1346 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001347 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001348
Auke Kokbc7f75f2007-09-17 12:30:59 -07001349 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001350 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001351 return cleaned;
1352}
1353
1354/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001355 * e1000_consume_page - helper function
1356 **/
1357static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1358 u16 length)
1359{
1360 bi->page = NULL;
1361 skb->len += length;
1362 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001363 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001364}
1365
1366/**
1367 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1368 * @adapter: board private structure
1369 *
1370 * the return value indicates whether actual cleaning was done, there
1371 * is no guarantee that everything was cleaned
1372 **/
1373
1374static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1375 int *work_done, int work_to_do)
1376{
1377 struct net_device *netdev = adapter->netdev;
1378 struct pci_dev *pdev = adapter->pdev;
1379 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan5f450212011-07-22 06:21:46 +00001380 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001381 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001382 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001383 unsigned int i;
1384 int cleaned_count = 0;
1385 bool cleaned = false;
1386 unsigned int total_rx_bytes=0, total_rx_packets=0;
1387
1388 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001389 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1390 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001391 buffer_info = &rx_ring->buffer_info[i];
1392
Bruce Allan5f450212011-07-22 06:21:46 +00001393 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001394 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001395
1396 if (*work_done >= work_to_do)
1397 break;
1398 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001399 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001400
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001401 skb = buffer_info->skb;
1402 buffer_info->skb = NULL;
1403
1404 ++i;
1405 if (i == rx_ring->count)
1406 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001407 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001408 prefetch(next_rxd);
1409
1410 next_buffer = &rx_ring->buffer_info[i];
1411
1412 cleaned = true;
1413 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001414 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1415 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001416 buffer_info->dma = 0;
1417
Bruce Allan5f450212011-07-22 06:21:46 +00001418 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001419
1420 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001421 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
1422 (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) {
1423 /* recycle both page and skb */
1424 buffer_info->skb = skb;
1425 /* an error means any chain goes out the window too */
1426 if (rx_ring->rx_skb_top)
1427 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1428 rx_ring->rx_skb_top = NULL;
1429 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001430 }
1431
Bruce Allanf0f1a172010-12-11 05:53:32 +00001432#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001433 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001434 /* this descriptor is only the beginning (or middle) */
1435 if (!rxtop) {
1436 /* this is the beginning of a chain */
1437 rxtop = skb;
1438 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1439 0, length);
1440 } else {
1441 /* this is the middle of a chain */
1442 skb_fill_page_desc(rxtop,
1443 skb_shinfo(rxtop)->nr_frags,
1444 buffer_info->page, 0, length);
1445 /* re-use the skb, only consumed the page */
1446 buffer_info->skb = skb;
1447 }
1448 e1000_consume_page(buffer_info, rxtop, length);
1449 goto next_desc;
1450 } else {
1451 if (rxtop) {
1452 /* end of the chain */
1453 skb_fill_page_desc(rxtop,
1454 skb_shinfo(rxtop)->nr_frags,
1455 buffer_info->page, 0, length);
1456 /* re-use the current skb, we only consumed the
1457 * page */
1458 buffer_info->skb = skb;
1459 skb = rxtop;
1460 rxtop = NULL;
1461 e1000_consume_page(buffer_info, skb, length);
1462 } else {
1463 /* no chain, got EOP, this buf is the packet
1464 * copybreak to save the put_page/alloc_page */
1465 if (length <= copybreak &&
1466 skb_tailroom(skb) >= length) {
1467 u8 *vaddr;
1468 vaddr = kmap_atomic(buffer_info->page,
1469 KM_SKB_DATA_SOFTIRQ);
1470 memcpy(skb_tail_pointer(skb), vaddr,
1471 length);
1472 kunmap_atomic(vaddr,
1473 KM_SKB_DATA_SOFTIRQ);
1474 /* re-use the page, so don't erase
1475 * buffer_info->page */
1476 skb_put(skb, length);
1477 } else {
1478 skb_fill_page_desc(skb, 0,
1479 buffer_info->page, 0,
1480 length);
1481 e1000_consume_page(buffer_info, skb,
1482 length);
1483 }
1484 }
1485 }
1486
1487 /* Receive Checksum Offload XXX recompute due to CRC strip? */
Bruce Allan5f450212011-07-22 06:21:46 +00001488 e1000_rx_checksum(adapter, staterr,
1489 le16_to_cpu(rx_desc->wb.lower.hi_dword.
1490 csum_ip.csum), skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001491
1492 /* probably a little skewed due to removing CRC */
1493 total_rx_bytes += skb->len;
1494 total_rx_packets++;
1495
1496 /* eth type trans needs skb->data to point to something */
1497 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001498 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001499 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001500 goto next_desc;
1501 }
1502
Bruce Allan5f450212011-07-22 06:21:46 +00001503 e1000_receive_skb(adapter, netdev, skb, staterr,
1504 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001505
1506next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001507 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001508
1509 /* return some buffers to hardware, one at a time is too slow */
1510 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001511 adapter->alloc_rx_buf(adapter, cleaned_count,
1512 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001513 cleaned_count = 0;
1514 }
1515
1516 /* use prefetched values */
1517 rx_desc = next_rxd;
1518 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001519
1520 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001521 }
1522 rx_ring->next_to_clean = i;
1523
1524 cleaned_count = e1000_desc_unused(rx_ring);
1525 if (cleaned_count)
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001526 adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001527
1528 adapter->total_rx_bytes += total_rx_bytes;
1529 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001530 return cleaned;
1531}
1532
1533/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001534 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1535 * @adapter: board private structure
1536 **/
1537static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1538{
1539 struct e1000_ring *rx_ring = adapter->rx_ring;
1540 struct e1000_buffer *buffer_info;
1541 struct e1000_ps_page *ps_page;
1542 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001543 unsigned int i, j;
1544
1545 /* Free all the Rx ring sk_buffs */
1546 for (i = 0; i < rx_ring->count; i++) {
1547 buffer_info = &rx_ring->buffer_info[i];
1548 if (buffer_info->dma) {
1549 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001550 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001551 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001552 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001553 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001554 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001555 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001556 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001557 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001558 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001559 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001560 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001561 buffer_info->dma = 0;
1562 }
1563
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001564 if (buffer_info->page) {
1565 put_page(buffer_info->page);
1566 buffer_info->page = NULL;
1567 }
1568
Auke Kokbc7f75f2007-09-17 12:30:59 -07001569 if (buffer_info->skb) {
1570 dev_kfree_skb(buffer_info->skb);
1571 buffer_info->skb = NULL;
1572 }
1573
1574 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001575 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001576 if (!ps_page->page)
1577 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001578 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1579 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001580 ps_page->dma = 0;
1581 put_page(ps_page->page);
1582 ps_page->page = NULL;
1583 }
1584 }
1585
1586 /* there also may be some cached data from a chained receive */
1587 if (rx_ring->rx_skb_top) {
1588 dev_kfree_skb(rx_ring->rx_skb_top);
1589 rx_ring->rx_skb_top = NULL;
1590 }
1591
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592 /* Zero out the descriptor ring */
1593 memset(rx_ring->desc, 0, rx_ring->size);
1594
1595 rx_ring->next_to_clean = 0;
1596 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001597 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001598
1599 writel(0, adapter->hw.hw_addr + rx_ring->head);
1600 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1601}
1602
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001603static void e1000e_downshift_workaround(struct work_struct *work)
1604{
1605 struct e1000_adapter *adapter = container_of(work,
1606 struct e1000_adapter, downshift_task);
1607
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001608 if (test_bit(__E1000_DOWN, &adapter->state))
1609 return;
1610
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001611 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1612}
1613
Auke Kokbc7f75f2007-09-17 12:30:59 -07001614/**
1615 * e1000_intr_msi - Interrupt Handler
1616 * @irq: interrupt number
1617 * @data: pointer to a network interface device structure
1618 **/
1619static irqreturn_t e1000_intr_msi(int irq, void *data)
1620{
1621 struct net_device *netdev = data;
1622 struct e1000_adapter *adapter = netdev_priv(netdev);
1623 struct e1000_hw *hw = &adapter->hw;
1624 u32 icr = er32(ICR);
1625
Bruce Allanad680762008-03-28 09:15:03 -07001626 /*
1627 * read ICR disables interrupts using IAM
1628 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001629
dave graham573cca82009-02-10 12:52:05 +00001630 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001631 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001632 /*
1633 * ICH8 workaround-- Call gig speed drop workaround on cable
1634 * disconnect (LSC) before accessing any PHY registers
1635 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1637 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001638 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001639
Bruce Allanad680762008-03-28 09:15:03 -07001640 /*
1641 * 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001642 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001643 * adapter in watchdog
1644 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001645 if (netif_carrier_ok(netdev) &&
1646 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1647 /* disable receives */
1648 u32 rctl = er32(RCTL);
1649 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001650 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001651 }
1652 /* guard against interrupt when we're going down */
1653 if (!test_bit(__E1000_DOWN, &adapter->state))
1654 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1655 }
1656
Ben Hutchings288379f2009-01-19 16:43:59 -08001657 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001658 adapter->total_tx_bytes = 0;
1659 adapter->total_tx_packets = 0;
1660 adapter->total_rx_bytes = 0;
1661 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001662 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001663 }
1664
1665 return IRQ_HANDLED;
1666}
1667
1668/**
1669 * e1000_intr - Interrupt Handler
1670 * @irq: interrupt number
1671 * @data: pointer to a network interface device structure
1672 **/
1673static irqreturn_t e1000_intr(int irq, void *data)
1674{
1675 struct net_device *netdev = data;
1676 struct e1000_adapter *adapter = netdev_priv(netdev);
1677 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001679
Bruce Allana68ea772009-11-20 23:23:16 +00001680 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681 return IRQ_NONE; /* Not our interrupt */
1682
Bruce Allanad680762008-03-28 09:15:03 -07001683 /*
1684 * IMS will not auto-mask if INT_ASSERTED is not set, and if it is
1685 * not set, then the adapter didn't send an interrupt
1686 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687 if (!(icr & E1000_ICR_INT_ASSERTED))
1688 return IRQ_NONE;
1689
Bruce Allanad680762008-03-28 09:15:03 -07001690 /*
1691 * Interrupt Auto-Mask...upon reading ICR,
1692 * interrupts are masked. No need for the
1693 * IMC write
1694 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001695
dave graham573cca82009-02-10 12:52:05 +00001696 if (icr & E1000_ICR_LSC) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001697 hw->mac.get_link_status = 1;
Bruce Allanad680762008-03-28 09:15:03 -07001698 /*
1699 * ICH8 workaround-- Call gig speed drop workaround on cable
1700 * disconnect (LSC) before accessing any PHY registers
1701 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001702 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1703 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001704 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705
Bruce Allanad680762008-03-28 09:15:03 -07001706 /*
1707 * 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708 * For packet buffer work-around on link down event;
1709 * disable receives here in the ISR and
1710 * reset adapter in watchdog
1711 */
1712 if (netif_carrier_ok(netdev) &&
1713 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1714 /* disable receives */
1715 rctl = er32(RCTL);
1716 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001717 adapter->flags |= FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001718 }
1719 /* guard against interrupt when we're going down */
1720 if (!test_bit(__E1000_DOWN, &adapter->state))
1721 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1722 }
1723
Ben Hutchings288379f2009-01-19 16:43:59 -08001724 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001725 adapter->total_tx_bytes = 0;
1726 adapter->total_tx_packets = 0;
1727 adapter->total_rx_bytes = 0;
1728 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001729 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001730 }
1731
1732 return IRQ_HANDLED;
1733}
1734
Bruce Allan4662e822008-08-26 18:37:06 -07001735static irqreturn_t e1000_msix_other(int irq, void *data)
1736{
1737 struct net_device *netdev = data;
1738 struct e1000_adapter *adapter = netdev_priv(netdev);
1739 struct e1000_hw *hw = &adapter->hw;
1740 u32 icr = er32(ICR);
1741
1742 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001743 if (!test_bit(__E1000_DOWN, &adapter->state))
1744 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001745 return IRQ_NONE;
1746 }
1747
1748 if (icr & adapter->eiac_mask)
1749 ew32(ICS, (icr & adapter->eiac_mask));
1750
1751 if (icr & E1000_ICR_OTHER) {
1752 if (!(icr & E1000_ICR_LSC))
1753 goto no_link_interrupt;
1754 hw->mac.get_link_status = 1;
1755 /* guard against interrupt when we're going down */
1756 if (!test_bit(__E1000_DOWN, &adapter->state))
1757 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1758 }
1759
1760no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001761 if (!test_bit(__E1000_DOWN, &adapter->state))
1762 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001763
1764 return IRQ_HANDLED;
1765}
1766
1767
1768static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1769{
1770 struct net_device *netdev = data;
1771 struct e1000_adapter *adapter = netdev_priv(netdev);
1772 struct e1000_hw *hw = &adapter->hw;
1773 struct e1000_ring *tx_ring = adapter->tx_ring;
1774
1775
1776 adapter->total_tx_bytes = 0;
1777 adapter->total_tx_packets = 0;
1778
1779 if (!e1000_clean_tx_irq(adapter))
1780 /* Ring was not completely cleaned, so fire another interrupt */
1781 ew32(ICS, tx_ring->ims_val);
1782
1783 return IRQ_HANDLED;
1784}
1785
1786static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1787{
1788 struct net_device *netdev = data;
1789 struct e1000_adapter *adapter = netdev_priv(netdev);
1790
1791 /* Write the ITR value calculated at the end of the
1792 * previous interrupt.
1793 */
1794 if (adapter->rx_ring->set_itr) {
1795 writel(1000000000 / (adapter->rx_ring->itr_val * 256),
1796 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
1797 adapter->rx_ring->set_itr = 0;
1798 }
1799
Ben Hutchings288379f2009-01-19 16:43:59 -08001800 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001801 adapter->total_rx_bytes = 0;
1802 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001803 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001804 }
1805 return IRQ_HANDLED;
1806}
1807
1808/**
1809 * e1000_configure_msix - Configure MSI-X hardware
1810 *
1811 * e1000_configure_msix sets up the hardware to properly
1812 * generate MSI-X interrupts.
1813 **/
1814static void e1000_configure_msix(struct e1000_adapter *adapter)
1815{
1816 struct e1000_hw *hw = &adapter->hw;
1817 struct e1000_ring *rx_ring = adapter->rx_ring;
1818 struct e1000_ring *tx_ring = adapter->tx_ring;
1819 int vector = 0;
1820 u32 ctrl_ext, ivar = 0;
1821
1822 adapter->eiac_mask = 0;
1823
1824 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1825 if (hw->mac.type == e1000_82574) {
1826 u32 rfctl = er32(RFCTL);
1827 rfctl |= E1000_RFCTL_ACK_DIS;
1828 ew32(RFCTL, rfctl);
1829 }
1830
1831#define E1000_IVAR_INT_ALLOC_VALID 0x8
1832 /* Configure Rx vector */
1833 rx_ring->ims_val = E1000_IMS_RXQ0;
1834 adapter->eiac_mask |= rx_ring->ims_val;
1835 if (rx_ring->itr_val)
1836 writel(1000000000 / (rx_ring->itr_val * 256),
1837 hw->hw_addr + rx_ring->itr_register);
1838 else
1839 writel(1, hw->hw_addr + rx_ring->itr_register);
1840 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1841
1842 /* Configure Tx vector */
1843 tx_ring->ims_val = E1000_IMS_TXQ0;
1844 vector++;
1845 if (tx_ring->itr_val)
1846 writel(1000000000 / (tx_ring->itr_val * 256),
1847 hw->hw_addr + tx_ring->itr_register);
1848 else
1849 writel(1, hw->hw_addr + tx_ring->itr_register);
1850 adapter->eiac_mask |= tx_ring->ims_val;
1851 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1852
1853 /* set vector for Other Causes, e.g. link changes */
1854 vector++;
1855 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1856 if (rx_ring->itr_val)
1857 writel(1000000000 / (rx_ring->itr_val * 256),
1858 hw->hw_addr + E1000_EITR_82574(vector));
1859 else
1860 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1861
1862 /* Cause Tx interrupts on every write back */
1863 ivar |= (1 << 31);
1864
1865 ew32(IVAR, ivar);
1866
1867 /* enable MSI-X PBA support */
1868 ctrl_ext = er32(CTRL_EXT);
1869 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1870
1871 /* Auto-Mask Other interrupts upon ICR read */
1872#define E1000_EIAC_MASK_82574 0x01F00000
1873 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1874 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1875 ew32(CTRL_EXT, ctrl_ext);
1876 e1e_flush();
1877}
1878
1879void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1880{
1881 if (adapter->msix_entries) {
1882 pci_disable_msix(adapter->pdev);
1883 kfree(adapter->msix_entries);
1884 adapter->msix_entries = NULL;
1885 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1886 pci_disable_msi(adapter->pdev);
1887 adapter->flags &= ~FLAG_MSI_ENABLED;
1888 }
Bruce Allan4662e822008-08-26 18:37:06 -07001889}
1890
1891/**
1892 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1893 *
1894 * Attempt to configure interrupts using the best available
1895 * capabilities of the hardware and kernel.
1896 **/
1897void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1898{
1899 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001900 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001901
1902 switch (adapter->int_mode) {
1903 case E1000E_INT_MODE_MSIX:
1904 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001905 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1906 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001907 sizeof(struct msix_entry),
1908 GFP_KERNEL);
1909 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001910 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001911 adapter->msix_entries[i].entry = i;
1912
1913 err = pci_enable_msix(adapter->pdev,
1914 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001915 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001916 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001917 return;
1918 }
1919 /* MSI-X failed, so fall through and try MSI */
1920 e_err("Failed to initialize MSI-X interrupts. "
1921 "Falling back to MSI interrupts.\n");
1922 e1000e_reset_interrupt_capability(adapter);
1923 }
1924 adapter->int_mode = E1000E_INT_MODE_MSI;
1925 /* Fall through */
1926 case E1000E_INT_MODE_MSI:
1927 if (!pci_enable_msi(adapter->pdev)) {
1928 adapter->flags |= FLAG_MSI_ENABLED;
1929 } else {
1930 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1931 e_err("Failed to initialize MSI interrupts. Falling "
1932 "back to legacy interrupts.\n");
1933 }
1934 /* Fall through */
1935 case E1000E_INT_MODE_LEGACY:
1936 /* Don't do anything; this is the system default */
1937 break;
1938 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001939
1940 /* store the number of vectors being used */
1941 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001942}
1943
1944/**
1945 * e1000_request_msix - Initialize MSI-X interrupts
1946 *
1947 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1948 * kernel.
1949 **/
1950static int e1000_request_msix(struct e1000_adapter *adapter)
1951{
1952 struct net_device *netdev = adapter->netdev;
1953 int err = 0, vector = 0;
1954
1955 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001956 snprintf(adapter->rx_ring->name,
1957 sizeof(adapter->rx_ring->name) - 1,
1958 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001959 else
1960 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1961 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001962 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001963 netdev);
1964 if (err)
1965 goto out;
1966 adapter->rx_ring->itr_register = E1000_EITR_82574(vector);
1967 adapter->rx_ring->itr_val = adapter->itr;
1968 vector++;
1969
1970 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001971 snprintf(adapter->tx_ring->name,
1972 sizeof(adapter->tx_ring->name) - 1,
1973 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001974 else
1975 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1976 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001977 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001978 netdev);
1979 if (err)
1980 goto out;
1981 adapter->tx_ring->itr_register = E1000_EITR_82574(vector);
1982 adapter->tx_ring->itr_val = adapter->itr;
1983 vector++;
1984
1985 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001986 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001987 if (err)
1988 goto out;
1989
1990 e1000_configure_msix(adapter);
1991 return 0;
1992out:
1993 return err;
1994}
1995
Bruce Allanf8d59f72008-08-08 18:36:11 -07001996/**
1997 * e1000_request_irq - initialize interrupts
1998 *
1999 * Attempts to configure interrupts using the best available
2000 * capabilities of the hardware and kernel.
2001 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002002static int e1000_request_irq(struct e1000_adapter *adapter)
2003{
2004 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002005 int err;
2006
Bruce Allan4662e822008-08-26 18:37:06 -07002007 if (adapter->msix_entries) {
2008 err = e1000_request_msix(adapter);
2009 if (!err)
2010 return err;
2011 /* fall back to MSI */
2012 e1000e_reset_interrupt_capability(adapter);
2013 adapter->int_mode = E1000E_INT_MODE_MSI;
2014 e1000e_set_interrupt_capability(adapter);
2015 }
2016 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002017 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002018 netdev->name, netdev);
2019 if (!err)
2020 return err;
2021
2022 /* fall back to legacy interrupt */
2023 e1000e_reset_interrupt_capability(adapter);
2024 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002025 }
2026
Joe Perchesa0607fd2009-11-18 23:29:17 -08002027 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002028 netdev->name, netdev);
2029 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002030 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002031
2032 return err;
2033}
2034
2035static void e1000_free_irq(struct e1000_adapter *adapter)
2036{
2037 struct net_device *netdev = adapter->netdev;
2038
Bruce Allan4662e822008-08-26 18:37:06 -07002039 if (adapter->msix_entries) {
2040 int vector = 0;
2041
2042 free_irq(adapter->msix_entries[vector].vector, netdev);
2043 vector++;
2044
2045 free_irq(adapter->msix_entries[vector].vector, netdev);
2046 vector++;
2047
2048 /* Other Causes interrupt vector */
2049 free_irq(adapter->msix_entries[vector].vector, netdev);
2050 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002051 }
Bruce Allan4662e822008-08-26 18:37:06 -07002052
2053 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002054}
2055
2056/**
2057 * e1000_irq_disable - Mask off interrupt generation on the NIC
2058 **/
2059static void e1000_irq_disable(struct e1000_adapter *adapter)
2060{
2061 struct e1000_hw *hw = &adapter->hw;
2062
Auke Kokbc7f75f2007-09-17 12:30:59 -07002063 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002064 if (adapter->msix_entries)
2065 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002066 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002067
2068 if (adapter->msix_entries) {
2069 int i;
2070 for (i = 0; i < adapter->num_vectors; i++)
2071 synchronize_irq(adapter->msix_entries[i].vector);
2072 } else {
2073 synchronize_irq(adapter->pdev->irq);
2074 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002075}
2076
2077/**
2078 * e1000_irq_enable - Enable default interrupt generation settings
2079 **/
2080static void e1000_irq_enable(struct e1000_adapter *adapter)
2081{
2082 struct e1000_hw *hw = &adapter->hw;
2083
Bruce Allan4662e822008-08-26 18:37:06 -07002084 if (adapter->msix_entries) {
2085 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2086 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2087 } else {
2088 ew32(IMS, IMS_ENABLE_MASK);
2089 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002090 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002091}
2092
2093/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002094 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002095 * @adapter: address of board private structure
2096 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002097 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002098 * For ASF and Pass Through versions of f/w this means that
2099 * the driver is loaded. For AMT version (only with 82573)
2100 * of the f/w this means that the network i/f is open.
2101 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002102void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002103{
2104 struct e1000_hw *hw = &adapter->hw;
2105 u32 ctrl_ext;
2106 u32 swsm;
2107
2108 /* Let firmware know the driver has taken over */
2109 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2110 swsm = er32(SWSM);
2111 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2112 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2113 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002114 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002115 }
2116}
2117
2118/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002119 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002120 * @adapter: address of board private structure
2121 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002122 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002123 * For ASF and Pass Through versions of f/w this means that the
2124 * driver is no longer loaded. For AMT version (only with 82573) i
2125 * of the f/w this means that the network i/f is closed.
2126 *
2127 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002128void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002129{
2130 struct e1000_hw *hw = &adapter->hw;
2131 u32 ctrl_ext;
2132 u32 swsm;
2133
2134 /* Let firmware taken over control of h/w */
2135 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2136 swsm = er32(SWSM);
2137 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2138 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2139 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002140 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002141 }
2142}
2143
Auke Kokbc7f75f2007-09-17 12:30:59 -07002144/**
2145 * @e1000_alloc_ring - allocate memory for a ring structure
2146 **/
2147static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2148 struct e1000_ring *ring)
2149{
2150 struct pci_dev *pdev = adapter->pdev;
2151
2152 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2153 GFP_KERNEL);
2154 if (!ring->desc)
2155 return -ENOMEM;
2156
2157 return 0;
2158}
2159
2160/**
2161 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
2162 * @adapter: board private structure
2163 *
2164 * Return 0 on success, negative on failure
2165 **/
2166int e1000e_setup_tx_resources(struct e1000_adapter *adapter)
2167{
2168 struct e1000_ring *tx_ring = adapter->tx_ring;
2169 int err = -ENOMEM, size;
2170
2171 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002172 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002173 if (!tx_ring->buffer_info)
2174 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002175
2176 /* round up to nearest 4K */
2177 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2178 tx_ring->size = ALIGN(tx_ring->size, 4096);
2179
2180 err = e1000_alloc_ring_dma(adapter, tx_ring);
2181 if (err)
2182 goto err;
2183
2184 tx_ring->next_to_use = 0;
2185 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002186
2187 return 0;
2188err:
2189 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002190 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002191 return err;
2192}
2193
2194/**
2195 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
2196 * @adapter: board private structure
2197 *
2198 * Returns 0 on success, negative on failure
2199 **/
2200int e1000e_setup_rx_resources(struct e1000_adapter *adapter)
2201{
2202 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002203 struct e1000_buffer *buffer_info;
2204 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002205
2206 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002207 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002208 if (!rx_ring->buffer_info)
2209 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002210
Auke Kok47f44e42007-10-25 13:57:44 -07002211 for (i = 0; i < rx_ring->count; i++) {
2212 buffer_info = &rx_ring->buffer_info[i];
2213 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2214 sizeof(struct e1000_ps_page),
2215 GFP_KERNEL);
2216 if (!buffer_info->ps_pages)
2217 goto err_pages;
2218 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002219
2220 desc_len = sizeof(union e1000_rx_desc_packet_split);
2221
2222 /* Round up to nearest 4K */
2223 rx_ring->size = rx_ring->count * desc_len;
2224 rx_ring->size = ALIGN(rx_ring->size, 4096);
2225
2226 err = e1000_alloc_ring_dma(adapter, rx_ring);
2227 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002228 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229
2230 rx_ring->next_to_clean = 0;
2231 rx_ring->next_to_use = 0;
2232 rx_ring->rx_skb_top = NULL;
2233
2234 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002235
2236err_pages:
2237 for (i = 0; i < rx_ring->count; i++) {
2238 buffer_info = &rx_ring->buffer_info[i];
2239 kfree(buffer_info->ps_pages);
2240 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002241err:
2242 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002243 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244 return err;
2245}
2246
2247/**
2248 * e1000_clean_tx_ring - Free Tx Buffers
2249 * @adapter: board private structure
2250 **/
2251static void e1000_clean_tx_ring(struct e1000_adapter *adapter)
2252{
2253 struct e1000_ring *tx_ring = adapter->tx_ring;
2254 struct e1000_buffer *buffer_info;
2255 unsigned long size;
2256 unsigned int i;
2257
2258 for (i = 0; i < tx_ring->count; i++) {
2259 buffer_info = &tx_ring->buffer_info[i];
2260 e1000_put_txbuf(adapter, buffer_info);
2261 }
2262
2263 size = sizeof(struct e1000_buffer) * tx_ring->count;
2264 memset(tx_ring->buffer_info, 0, size);
2265
2266 memset(tx_ring->desc, 0, tx_ring->size);
2267
2268 tx_ring->next_to_use = 0;
2269 tx_ring->next_to_clean = 0;
2270
2271 writel(0, adapter->hw.hw_addr + tx_ring->head);
2272 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2273}
2274
2275/**
2276 * e1000e_free_tx_resources - Free Tx Resources per Queue
2277 * @adapter: board private structure
2278 *
2279 * Free all transmit software resources
2280 **/
2281void e1000e_free_tx_resources(struct e1000_adapter *adapter)
2282{
2283 struct pci_dev *pdev = adapter->pdev;
2284 struct e1000_ring *tx_ring = adapter->tx_ring;
2285
2286 e1000_clean_tx_ring(adapter);
2287
2288 vfree(tx_ring->buffer_info);
2289 tx_ring->buffer_info = NULL;
2290
2291 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2292 tx_ring->dma);
2293 tx_ring->desc = NULL;
2294}
2295
2296/**
2297 * e1000e_free_rx_resources - Free Rx Resources
2298 * @adapter: board private structure
2299 *
2300 * Free all receive software resources
2301 **/
2302
2303void e1000e_free_rx_resources(struct e1000_adapter *adapter)
2304{
2305 struct pci_dev *pdev = adapter->pdev;
2306 struct e1000_ring *rx_ring = adapter->rx_ring;
Auke Kok47f44e42007-10-25 13:57:44 -07002307 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002308
2309 e1000_clean_rx_ring(adapter);
2310
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002311 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002312 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002313
Auke Kokbc7f75f2007-09-17 12:30:59 -07002314 vfree(rx_ring->buffer_info);
2315 rx_ring->buffer_info = NULL;
2316
Auke Kokbc7f75f2007-09-17 12:30:59 -07002317 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2318 rx_ring->dma);
2319 rx_ring->desc = NULL;
2320}
2321
2322/**
2323 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002324 * @adapter: pointer to adapter
2325 * @itr_setting: current adapter->itr
2326 * @packets: the number of packets during this measurement interval
2327 * @bytes: the number of bytes during this measurement interval
2328 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002329 * Stores a new ITR value based on packets and byte
2330 * counts during the last interrupt. The advantage of per interrupt
2331 * computation is faster updates and more accurate ITR for the current
2332 * traffic pattern. Constants in this function were computed
2333 * based on theoretical maximum wire speed and thresholds were set based
2334 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002335 * while increasing bulk throughput. This functionality is controlled
2336 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002337 **/
2338static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2339 u16 itr_setting, int packets,
2340 int bytes)
2341{
2342 unsigned int retval = itr_setting;
2343
2344 if (packets == 0)
2345 goto update_itr_done;
2346
2347 switch (itr_setting) {
2348 case lowest_latency:
2349 /* handle TSO and jumbo frames */
2350 if (bytes/packets > 8000)
2351 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002352 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002353 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002354 break;
2355 case low_latency: /* 50 usec aka 20000 ints/s */
2356 if (bytes > 10000) {
2357 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002358 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002360 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002361 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002362 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002363 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002364 } else if (bytes/packets > 2000) {
2365 retval = bulk_latency;
2366 } else if (packets <= 2 && bytes < 512) {
2367 retval = lowest_latency;
2368 }
2369 break;
2370 case bulk_latency: /* 250 usec aka 4000 ints/s */
2371 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002372 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002374 } else if (bytes < 6000) {
2375 retval = low_latency;
2376 }
2377 break;
2378 }
2379
2380update_itr_done:
2381 return retval;
2382}
2383
2384static void e1000_set_itr(struct e1000_adapter *adapter)
2385{
2386 struct e1000_hw *hw = &adapter->hw;
2387 u16 current_itr;
2388 u32 new_itr = adapter->itr;
2389
2390 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2391 if (adapter->link_speed != SPEED_1000) {
2392 current_itr = 0;
2393 new_itr = 4000;
2394 goto set_itr_now;
2395 }
2396
Bruce Allan828bac82010-09-29 21:39:37 +00002397 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2398 new_itr = 0;
2399 goto set_itr_now;
2400 }
2401
Auke Kokbc7f75f2007-09-17 12:30:59 -07002402 adapter->tx_itr = e1000_update_itr(adapter,
2403 adapter->tx_itr,
2404 adapter->total_tx_packets,
2405 adapter->total_tx_bytes);
2406 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2407 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2408 adapter->tx_itr = low_latency;
2409
2410 adapter->rx_itr = e1000_update_itr(adapter,
2411 adapter->rx_itr,
2412 adapter->total_rx_packets,
2413 adapter->total_rx_bytes);
2414 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2415 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2416 adapter->rx_itr = low_latency;
2417
2418 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2419
2420 switch (current_itr) {
2421 /* counts and packets in update_itr are dependent on these numbers */
2422 case lowest_latency:
2423 new_itr = 70000;
2424 break;
2425 case low_latency:
2426 new_itr = 20000; /* aka hwitr = ~200 */
2427 break;
2428 case bulk_latency:
2429 new_itr = 4000;
2430 break;
2431 default:
2432 break;
2433 }
2434
2435set_itr_now:
2436 if (new_itr != adapter->itr) {
Bruce Allanad680762008-03-28 09:15:03 -07002437 /*
2438 * this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002439 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002440 * increasing
2441 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002442 new_itr = new_itr > adapter->itr ?
2443 min(adapter->itr + (new_itr >> 2), new_itr) :
2444 new_itr;
2445 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002446 adapter->rx_ring->itr_val = new_itr;
2447 if (adapter->msix_entries)
2448 adapter->rx_ring->set_itr = 1;
2449 else
Bruce Allan828bac82010-09-29 21:39:37 +00002450 if (new_itr)
2451 ew32(ITR, 1000000000 / (new_itr * 256));
2452 else
2453 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 }
2455}
2456
2457/**
Bruce Allan4662e822008-08-26 18:37:06 -07002458 * e1000_alloc_queues - Allocate memory for all rings
2459 * @adapter: board private structure to initialize
2460 **/
2461static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
2462{
2463 adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2464 if (!adapter->tx_ring)
2465 goto err;
2466
2467 adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
2468 if (!adapter->rx_ring)
2469 goto err;
2470
2471 return 0;
2472err:
2473 e_err("Unable to allocate memory for queues\n");
2474 kfree(adapter->rx_ring);
2475 kfree(adapter->tx_ring);
2476 return -ENOMEM;
2477}
2478
2479/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002480 * e1000_clean - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002481 * @napi: struct associated with this polling callback
Auke Kok489815c2008-02-21 15:11:07 -08002482 * @budget: amount of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483 **/
2484static int e1000_clean(struct napi_struct *napi, int budget)
2485{
2486 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002487 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002488 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002489 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002490
Wang Chen4cf16532008-11-12 23:38:14 -08002491 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002492
Bruce Allan4662e822008-08-26 18:37:06 -07002493 if (adapter->msix_entries &&
2494 !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2495 goto clean_rx;
2496
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00002497 tx_cleaned = e1000_clean_tx_irq(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002498
Bruce Allan4662e822008-08-26 18:37:06 -07002499clean_rx:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500 adapter->clean_rx(adapter, &work_done, budget);
2501
Alexander Duyck12d04a32009-03-25 22:05:03 +00002502 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002503 work_done = budget;
2504
David S. Miller53e52c72008-01-07 21:06:12 -08002505 /* If budget not fully consumed, exit the polling mode */
2506 if (work_done < budget) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002507 if (adapter->itr_setting & 3)
2508 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002509 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002510 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2511 if (adapter->msix_entries)
2512 ew32(IMS, adapter->rx_ring->ims_val);
2513 else
2514 e1000_irq_enable(adapter);
2515 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002516 }
2517
2518 return work_done;
2519}
2520
2521static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2522{
2523 struct e1000_adapter *adapter = netdev_priv(netdev);
2524 struct e1000_hw *hw = &adapter->hw;
2525 u32 vfta, index;
2526
2527 /* don't update vlan cookie if already programmed */
2528 if ((adapter->hw.mng_cookie.status &
2529 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2530 (vid == adapter->mng_vlan_id))
2531 return;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002532
Auke Kokbc7f75f2007-09-17 12:30:59 -07002533 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002534 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2535 index = (vid >> 5) & 0x7F;
2536 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2537 vfta |= (1 << (vid & 0x1F));
2538 hw->mac.ops.write_vfta(hw, index, vfta);
2539 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002540
2541 set_bit(vid, adapter->active_vlans);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002542}
2543
2544static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2545{
2546 struct e1000_adapter *adapter = netdev_priv(netdev);
2547 struct e1000_hw *hw = &adapter->hw;
2548 u32 vfta, index;
2549
Auke Kokbc7f75f2007-09-17 12:30:59 -07002550 if ((adapter->hw.mng_cookie.status &
2551 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2552 (vid == adapter->mng_vlan_id)) {
2553 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002554 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002555 return;
2556 }
2557
2558 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002559 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2560 index = (vid >> 5) & 0x7F;
2561 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2562 vfta &= ~(1 << (vid & 0x1F));
2563 hw->mac.ops.write_vfta(hw, index, vfta);
2564 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002565
2566 clear_bit(vid, adapter->active_vlans);
2567}
2568
2569/**
2570 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2571 * @adapter: board private structure to initialize
2572 **/
2573static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2574{
2575 struct net_device *netdev = adapter->netdev;
2576 struct e1000_hw *hw = &adapter->hw;
2577 u32 rctl;
2578
2579 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2580 /* disable VLAN receive filtering */
2581 rctl = er32(RCTL);
2582 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2583 ew32(RCTL, rctl);
2584
2585 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2586 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2587 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2588 }
2589 }
2590}
2591
2592/**
2593 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2594 * @adapter: board private structure to initialize
2595 **/
2596static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2597{
2598 struct e1000_hw *hw = &adapter->hw;
2599 u32 rctl;
2600
2601 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2602 /* enable VLAN receive filtering */
2603 rctl = er32(RCTL);
2604 rctl |= E1000_RCTL_VFE;
2605 rctl &= ~E1000_RCTL_CFIEN;
2606 ew32(RCTL, rctl);
2607 }
2608}
2609
2610/**
2611 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2612 * @adapter: board private structure to initialize
2613 **/
2614static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2615{
2616 struct e1000_hw *hw = &adapter->hw;
2617 u32 ctrl;
2618
2619 /* disable VLAN tag insert/strip */
2620 ctrl = er32(CTRL);
2621 ctrl &= ~E1000_CTRL_VME;
2622 ew32(CTRL, ctrl);
2623}
2624
2625/**
2626 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2627 * @adapter: board private structure to initialize
2628 **/
2629static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2630{
2631 struct e1000_hw *hw = &adapter->hw;
2632 u32 ctrl;
2633
2634 /* enable VLAN tag insert/strip */
2635 ctrl = er32(CTRL);
2636 ctrl |= E1000_CTRL_VME;
2637 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002638}
2639
2640static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2641{
2642 struct net_device *netdev = adapter->netdev;
2643 u16 vid = adapter->hw.mng_cookie.vlan_id;
2644 u16 old_vid = adapter->mng_vlan_id;
2645
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002646 if (adapter->hw.mng_cookie.status &
2647 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2648 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002649 adapter->mng_vlan_id = vid;
2650 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002651
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002652 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2653 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002654}
2655
2656static void e1000_restore_vlan(struct e1000_adapter *adapter)
2657{
2658 u16 vid;
2659
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002660 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002661
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002662 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002664}
2665
Bruce Allancd791612010-05-10 14:59:51 +00002666static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002667{
2668 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002669 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002670
2671 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2672 return;
2673
2674 manc = er32(MANC);
2675
Bruce Allanad680762008-03-28 09:15:03 -07002676 /*
2677 * enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002678 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002679 * the packets will be handled on SMBUS
2680 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002681 manc |= E1000_MANC_EN_MNG2HOST;
2682 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002683
2684 switch (hw->mac.type) {
2685 default:
2686 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2687 break;
2688 case e1000_82574:
2689 case e1000_82583:
2690 /*
2691 * Check if IPMI pass-through decision filter already exists;
2692 * if so, enable it.
2693 */
2694 for (i = 0, j = 0; i < 8; i++) {
2695 mdef = er32(MDEF(i));
2696
2697 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002698 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002699 continue;
2700
2701 /* Enable this decision filter in MANC2H */
2702 if (mdef)
2703 manc2h |= (1 << i);
2704
2705 j |= mdef;
2706 }
2707
2708 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2709 break;
2710
2711 /* Create new decision filter in an empty filter */
2712 for (i = 0, j = 0; i < 8; i++)
2713 if (er32(MDEF(i)) == 0) {
2714 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2715 E1000_MDEF_PORT_664));
2716 manc2h |= (1 << 1);
2717 j++;
2718 break;
2719 }
2720
2721 if (!j)
2722 e_warn("Unable to create IPMI pass-through filter\n");
2723 break;
2724 }
2725
Auke Kokbc7f75f2007-09-17 12:30:59 -07002726 ew32(MANC2H, manc2h);
2727 ew32(MANC, manc);
2728}
2729
2730/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002731 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002732 * @adapter: board private structure
2733 *
2734 * Configure the Tx unit of the MAC after a reset.
2735 **/
2736static void e1000_configure_tx(struct e1000_adapter *adapter)
2737{
2738 struct e1000_hw *hw = &adapter->hw;
2739 struct e1000_ring *tx_ring = adapter->tx_ring;
2740 u64 tdba;
2741 u32 tdlen, tctl, tipg, tarc;
2742 u32 ipgr1, ipgr2;
2743
2744 /* Setup the HW Tx Head and Tail descriptor pointers */
2745 tdba = tx_ring->dma;
2746 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Yang Hongyang284901a2009-04-06 19:01:15 -07002747 ew32(TDBAL, (tdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002748 ew32(TDBAH, (tdba >> 32));
2749 ew32(TDLEN, tdlen);
2750 ew32(TDH, 0);
2751 ew32(TDT, 0);
2752 tx_ring->head = E1000_TDH;
2753 tx_ring->tail = E1000_TDT;
2754
2755 /* Set the default values for the Tx Inter Packet Gap timer */
2756 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */
2757 ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */
2758 ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */
2759
2760 if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN)
2761 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */
2762
2763 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
2764 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
2765 ew32(TIPG, tipg);
2766
2767 /* Set the Tx Interrupt Delay register */
2768 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002769 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002770 ew32(TADV, adapter->tx_abs_int_delay);
2771
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002772 if (adapter->flags2 & FLAG2_DMA_BURST) {
2773 u32 txdctl = er32(TXDCTL(0));
2774 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2775 E1000_TXDCTL_WTHRESH);
2776 /*
2777 * set up some performance related parameters to encourage the
2778 * hardware to use the bus more efficiently in bursts, depends
2779 * on the tx_int_delay to be enabled,
2780 * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time
2781 * hthresh = 1 ==> prefetch when one or more available
2782 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2783 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002784 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002785 */
2786 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2787 ew32(TXDCTL(0), txdctl);
2788 /* erratum work around: set txdctl the same for both queues */
2789 ew32(TXDCTL(1), txdctl);
2790 }
2791
Auke Kokbc7f75f2007-09-17 12:30:59 -07002792 /* Program the Transmit Control Register */
2793 tctl = er32(TCTL);
2794 tctl &= ~E1000_TCTL_CT;
2795 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2796 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2797
2798 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002799 tarc = er32(TARC(0));
Bruce Allanad680762008-03-28 09:15:03 -07002800 /*
2801 * set the speed mode bit, we'll clear it if we're not at
2802 * gigabit link later
2803 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002804#define SPEED_MODE_BIT (1 << 21)
2805 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002806 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002807 }
2808
2809 /* errata: program both queues to unweighted RR */
2810 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002811 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002812 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002813 ew32(TARC(0), tarc);
2814 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002816 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002817 }
2818
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819 /* Setup Transmit Descriptor Settings for eop descriptor */
2820 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2821
2822 /* only set IDE if we are delaying interrupts using the timers */
2823 if (adapter->tx_int_delay)
2824 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2825
2826 /* enable Report Status bit */
2827 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2828
2829 ew32(TCTL, tctl);
2830
Simon Hormanedfea6e62009-06-08 14:28:36 +00002831 e1000e_config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832}
2833
2834/**
2835 * e1000_setup_rctl - configure the receive control registers
2836 * @adapter: Board private structure
2837 **/
2838#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2839 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2840static void e1000_setup_rctl(struct e1000_adapter *adapter)
2841{
2842 struct e1000_hw *hw = &adapter->hw;
2843 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844 u32 pages = 0;
2845
Bruce Allana1ce6472010-09-22 17:16:40 +00002846 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2847 if (hw->mac.type == e1000_pch2lan) {
2848 s32 ret_val;
2849
2850 if (adapter->netdev->mtu > ETH_DATA_LEN)
2851 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2852 else
2853 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002854
2855 if (ret_val)
2856 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002857 }
2858
Auke Kokbc7f75f2007-09-17 12:30:59 -07002859 /* Program MC offset vector base */
2860 rctl = er32(RCTL);
2861 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2862 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2863 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2864 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2865
2866 /* Do not Store bad packets */
2867 rctl &= ~E1000_RCTL_SBP;
2868
2869 /* Enable Long Packet receive */
2870 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2871 rctl &= ~E1000_RCTL_LPE;
2872 else
2873 rctl |= E1000_RCTL_LPE;
2874
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002875 /* Some systems expect that the CRC is included in SMBUS traffic. The
2876 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2877 * host memory when this is enabled
2878 */
2879 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2880 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002881
Bruce Allana4f58f52009-06-02 11:29:18 +00002882 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2883 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2884 u16 phy_data;
2885
2886 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2887 phy_data &= 0xfff8;
2888 phy_data |= (1 << 2);
2889 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2890
2891 e1e_rphy(hw, 22, &phy_data);
2892 phy_data &= 0x0fff;
2893 phy_data |= (1 << 14);
2894 e1e_wphy(hw, 0x10, 0x2823);
2895 e1e_wphy(hw, 0x11, 0x0003);
2896 e1e_wphy(hw, 22, phy_data);
2897 }
2898
Auke Kokbc7f75f2007-09-17 12:30:59 -07002899 /* Setup buffer sizes */
2900 rctl &= ~E1000_RCTL_SZ_4096;
2901 rctl |= E1000_RCTL_BSEX;
2902 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002903 case 2048:
2904 default:
2905 rctl |= E1000_RCTL_SZ_2048;
2906 rctl &= ~E1000_RCTL_BSEX;
2907 break;
2908 case 4096:
2909 rctl |= E1000_RCTL_SZ_4096;
2910 break;
2911 case 8192:
2912 rctl |= E1000_RCTL_SZ_8192;
2913 break;
2914 case 16384:
2915 rctl |= E1000_RCTL_SZ_16384;
2916 break;
2917 }
2918
Bruce Allan5f450212011-07-22 06:21:46 +00002919 /* Enable Extended Status in all Receive Descriptors */
2920 rfctl = er32(RFCTL);
2921 rfctl |= E1000_RFCTL_EXTEN;
2922
Auke Kokbc7f75f2007-09-17 12:30:59 -07002923 /*
2924 * 82571 and greater support packet-split where the protocol
2925 * header is placed in skb->data and the packet data is
2926 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2927 * In the case of a non-split, skb->data is linearly filled,
2928 * followed by the page buffers. Therefore, skb->data is
2929 * sized to hold the largest protocol header.
2930 *
2931 * allocations using alloc_page take too long for regular MTU
2932 * so only enable packet split for jumbo frames
2933 *
2934 * Using pages when the page size is greater than 16k wastes
2935 * a lot of memory, since we allocate 3 pages at all times
2936 * per packet.
2937 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002938 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allandbcb9fec2010-06-17 18:59:27 +00002939 if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) &&
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002940 (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002941 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002942 else
2943 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002944
2945 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002946 u32 psrctl = 0;
2947
Bruce Allanad680762008-03-28 09:15:03 -07002948 /*
2949 * disable packet split support for IPv6 extension headers,
2950 * because some malformed IPv6 headers can hang the Rx
2951 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002952 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2953 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2954
Auke Kok140a7482007-10-25 13:57:58 -07002955 /* Enable Packet split descriptors */
2956 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002957
2958 psrctl |= adapter->rx_ps_bsize0 >>
2959 E1000_PSRCTL_BSIZE0_SHIFT;
2960
2961 switch (adapter->rx_ps_pages) {
2962 case 3:
2963 psrctl |= PAGE_SIZE <<
2964 E1000_PSRCTL_BSIZE3_SHIFT;
2965 case 2:
2966 psrctl |= PAGE_SIZE <<
2967 E1000_PSRCTL_BSIZE2_SHIFT;
2968 case 1:
2969 psrctl |= PAGE_SIZE >>
2970 E1000_PSRCTL_BSIZE1_SHIFT;
2971 break;
2972 }
2973
2974 ew32(PSRCTL, psrctl);
2975 }
2976
Bruce Allan5f450212011-07-22 06:21:46 +00002977 ew32(RFCTL, rfctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002978 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002979 /* just started the receive unit, no need to restart */
2980 adapter->flags &= ~FLAG_RX_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002981}
2982
2983/**
2984 * e1000_configure_rx - Configure Receive Unit after Reset
2985 * @adapter: board private structure
2986 *
2987 * Configure the Rx unit of the MAC after a reset.
2988 **/
2989static void e1000_configure_rx(struct e1000_adapter *adapter)
2990{
2991 struct e1000_hw *hw = &adapter->hw;
2992 struct e1000_ring *rx_ring = adapter->rx_ring;
2993 u64 rdba;
2994 u32 rdlen, rctl, rxcsum, ctrl_ext;
2995
2996 if (adapter->rx_ps_pages) {
2997 /* this is a 32 byte descriptor */
2998 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00002999 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003000 adapter->clean_rx = e1000_clean_rx_irq_ps;
3001 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003002 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003003 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003004 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3005 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003006 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003007 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003008 adapter->clean_rx = e1000_clean_rx_irq;
3009 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3010 }
3011
3012 /* disable receives while setting up the descriptors */
3013 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003014 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3015 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003016 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003017 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003018
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003019 if (adapter->flags2 & FLAG2_DMA_BURST) {
3020 /*
3021 * set the writeback threshold (only takes effect if the RDTR
3022 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003023 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003024 * granularity = 01
3025 * wthresh = 04,
3026 * hthresh = 04,
3027 * pthresh = 0x20
3028 */
3029 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3030 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3031
3032 /*
3033 * override the delay timers for enabling bursting, only if
3034 * the value was not set by the user via module options
3035 */
3036 if (adapter->rx_int_delay == DEFAULT_RDTR)
3037 adapter->rx_int_delay = BURST_RDTR;
3038 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3039 adapter->rx_abs_int_delay = BURST_RADV;
3040 }
3041
Auke Kokbc7f75f2007-09-17 12:30:59 -07003042 /* set the Receive Delay Timer Register */
3043 ew32(RDTR, adapter->rx_int_delay);
3044
3045 /* irq moderation */
3046 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003047 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Bruce Allanad680762008-03-28 09:15:03 -07003048 ew32(ITR, 1000000000 / (adapter->itr * 256));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003049
3050 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003051 /* Auto-Mask interrupts upon ICR access */
3052 ctrl_ext |= E1000_CTRL_EXT_IAME;
3053 ew32(IAM, 0xffffffff);
3054 ew32(CTRL_EXT, ctrl_ext);
3055 e1e_flush();
3056
Bruce Allanad680762008-03-28 09:15:03 -07003057 /*
3058 * Setup the HW Rx Head and Tail Descriptor Pointers and
3059 * the Base and Length of the Rx Descriptor Ring
3060 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003061 rdba = rx_ring->dma;
Yang Hongyang284901a2009-04-06 19:01:15 -07003062 ew32(RDBAL, (rdba & DMA_BIT_MASK(32)));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003063 ew32(RDBAH, (rdba >> 32));
3064 ew32(RDLEN, rdlen);
3065 ew32(RDH, 0);
3066 ew32(RDT, 0);
3067 rx_ring->head = E1000_RDH;
3068 rx_ring->tail = E1000_RDT;
3069
3070 /* Enable Receive Checksum Offload for TCP and UDP */
3071 rxcsum = er32(RXCSUM);
Bruce Allandc221292011-08-19 03:23:48 +00003072 if (adapter->netdev->features & NETIF_F_RXCSUM) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003073 rxcsum |= E1000_RXCSUM_TUOFL;
3074
Bruce Allanad680762008-03-28 09:15:03 -07003075 /*
3076 * IPv4 payload checksum for UDP fragments must be
3077 * used in conjunction with packet-split.
3078 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003079 if (adapter->rx_ps_pages)
3080 rxcsum |= E1000_RXCSUM_IPPCSE;
3081 } else {
3082 rxcsum &= ~E1000_RXCSUM_TUOFL;
3083 /* no need to clear IPPCSE as it defaults to 0 */
3084 }
3085 ew32(RXCSUM, rxcsum);
3086
Bruce Allanad680762008-03-28 09:15:03 -07003087 /*
3088 * Enable early receives on supported devices, only takes effect when
Auke Kokbc7f75f2007-09-17 12:30:59 -07003089 * packet size is equal or larger than the specified value (in 8 byte
Bruce Allanad680762008-03-28 09:15:03 -07003090 * units), e.g. using jumbo frames when setting to E1000_ERT_2048
3091 */
Bruce Allan828bac82010-09-29 21:39:37 +00003092 if ((adapter->flags & FLAG_HAS_ERT) ||
3093 (adapter->hw.mac.type == e1000_pch2lan)) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003094 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3095 u32 rxdctl = er32(RXDCTL(0));
3096 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan828bac82010-09-29 21:39:37 +00003097 if (adapter->flags & FLAG_HAS_ERT)
3098 ew32(ERT, E1000_ERT_2048 | (1 << 13));
Bruce Allan53ec5492009-11-20 23:27:40 +00003099 /*
3100 * With jumbo frames and early-receive enabled,
3101 * excessive C-state transition latencies result in
3102 * dropped transactions.
3103 */
Bruce Allanaf667a22010-12-31 06:10:01 +00003104 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003105 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003106 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3107 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003108 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003109 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003110
3111 /* Enable Receives */
3112 ew32(RCTL, rctl);
3113}
3114
3115/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003116 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003117 * @netdev: network interface device structure
3118 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003119 * Writes multicast address list to the MTA hash table.
3120 * Returns: -ENOMEM on failure
3121 * 0 on no addresses written
3122 * X on writing X addresses to MTA
3123 */
3124static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003125{
3126 struct e1000_adapter *adapter = netdev_priv(netdev);
3127 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003128 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003129 u8 *mta_list;
3130 int i;
3131
3132 if (netdev_mc_empty(netdev)) {
3133 /* nothing to program, so clear mc list */
3134 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3135 return 0;
3136 }
3137
3138 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3139 if (!mta_list)
3140 return -ENOMEM;
3141
3142 /* update_mc_addr_list expects a packed array of only addresses. */
3143 i = 0;
3144 netdev_for_each_mc_addr(ha, netdev)
3145 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3146
3147 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3148 kfree(mta_list);
3149
3150 return netdev_mc_count(netdev);
3151}
3152
3153/**
3154 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3155 * @netdev: network interface device structure
3156 *
3157 * Writes unicast address list to the RAR table.
3158 * Returns: -ENOMEM on failure/insufficient address space
3159 * 0 on no addresses written
3160 * X on writing X addresses to the RAR table
3161 **/
3162static int e1000e_write_uc_addr_list(struct net_device *netdev)
3163{
3164 struct e1000_adapter *adapter = netdev_priv(netdev);
3165 struct e1000_hw *hw = &adapter->hw;
3166 unsigned int rar_entries = hw->mac.rar_entry_count;
3167 int count = 0;
3168
3169 /* save a rar entry for our hardware address */
3170 rar_entries--;
3171
3172 /* save a rar entry for the LAA workaround */
3173 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3174 rar_entries--;
3175
3176 /* return ENOMEM indicating insufficient memory for addresses */
3177 if (netdev_uc_count(netdev) > rar_entries)
3178 return -ENOMEM;
3179
3180 if (!netdev_uc_empty(netdev) && rar_entries) {
3181 struct netdev_hw_addr *ha;
3182
3183 /*
3184 * write the addresses in reverse order to avoid write
3185 * combining
3186 */
3187 netdev_for_each_uc_addr(ha, netdev) {
3188 if (!rar_entries)
3189 break;
3190 e1000e_rar_set(hw, ha->addr, rar_entries--);
3191 count++;
3192 }
3193 }
3194
3195 /* zero out the remaining RAR entries not used above */
3196 for (; rar_entries > 0; rar_entries--) {
3197 ew32(RAH(rar_entries), 0);
3198 ew32(RAL(rar_entries), 0);
3199 }
3200 e1e_flush();
3201
3202 return count;
3203}
3204
3205/**
3206 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3207 * @netdev: network interface device structure
3208 *
3209 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3210 * address list or the network interface flags are updated. This routine is
3211 * responsible for configuring the hardware for proper unicast, multicast,
3212 * promiscuous mode, and all-multi behavior.
3213 **/
3214static void e1000e_set_rx_mode(struct net_device *netdev)
3215{
3216 struct e1000_adapter *adapter = netdev_priv(netdev);
3217 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003218 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003219
3220 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003221 rctl = er32(RCTL);
3222
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003223 /* clear the affected bits */
3224 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3225
Auke Kokbc7f75f2007-09-17 12:30:59 -07003226 if (netdev->flags & IFF_PROMISC) {
3227 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003228 /* Do not hardware filter VLANs in promisc mode */
3229 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003230 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003231 int count;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003232 if (netdev->flags & IFF_ALLMULTI) {
3233 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003234 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003235 /*
3236 * Write addresses to the MTA, if the attempt fails
3237 * then we should just turn on promiscuous mode so
3238 * that we can at least receive multicast traffic
3239 */
3240 count = e1000e_write_mc_addr_list(netdev);
3241 if (count < 0)
3242 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003243 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003244 e1000e_vlan_filter_enable(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003245 /*
3246 * Write addresses to available RAR registers, if there is not
3247 * sufficient space to store all the addresses then enable
3248 * unicast promiscuous mode
3249 */
3250 count = e1000e_write_uc_addr_list(netdev);
3251 if (count < 0)
3252 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003253 }
3254
3255 ew32(RCTL, rctl);
3256
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003257 if (netdev->features & NETIF_F_HW_VLAN_RX)
3258 e1000e_vlan_strip_enable(adapter);
3259 else
3260 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003261}
3262
3263/**
Bruce Allanad680762008-03-28 09:15:03 -07003264 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003265 * @adapter: private board structure
3266 **/
3267static void e1000_configure(struct e1000_adapter *adapter)
3268{
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003269 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003270
3271 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003272 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003273
3274 e1000_configure_tx(adapter);
3275 e1000_setup_rctl(adapter);
3276 e1000_configure_rx(adapter);
Jeff Kirsherc2fed992011-07-12 16:10:12 +00003277 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring),
3278 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003279}
3280
3281/**
3282 * e1000e_power_up_phy - restore link in case the phy was powered down
3283 * @adapter: address of board private structure
3284 *
3285 * The phy may be powered down to save power and turn off link when the
3286 * driver is unloaded and wake on lan is not enabled (among others)
3287 * *** this routine MUST be followed by a call to e1000e_reset ***
3288 **/
3289void e1000e_power_up_phy(struct e1000_adapter *adapter)
3290{
Bruce Allan17f208d2009-12-01 15:47:22 +00003291 if (adapter->hw.phy.ops.power_up)
3292 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003293
3294 adapter->hw.mac.ops.setup_link(&adapter->hw);
3295}
3296
3297/**
3298 * e1000_power_down_phy - Power down the PHY
3299 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003300 * Power down the PHY so no link is implied when interface is down.
3301 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003302 */
3303static void e1000_power_down_phy(struct e1000_adapter *adapter)
3304{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003305 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003306 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003307 return;
3308
Bruce Allan17f208d2009-12-01 15:47:22 +00003309 if (adapter->hw.phy.ops.power_down)
3310 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003311}
3312
3313/**
3314 * e1000e_reset - bring the hardware into a known good state
3315 *
3316 * This function boots the hardware and enables some settings that
3317 * require a configuration cycle of the hardware - those cannot be
3318 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003319 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003320 */
3321void e1000e_reset(struct e1000_adapter *adapter)
3322{
3323 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003324 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325 struct e1000_hw *hw = &adapter->hw;
3326 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003327 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003328 u16 hwm;
3329
Bruce Allanad680762008-03-28 09:15:03 -07003330 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003331 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003332
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003333 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003334 /*
3335 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003336 * large enough to accommodate two full transmit packets,
3337 * rounded up to the next 1KB and expressed in KB. Likewise,
3338 * the Rx FIFO should be large enough to accommodate at least
3339 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003340 * expressed in KB.
3341 */
Auke Kokdf762462007-10-25 13:57:53 -07003342 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003343 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003344 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003345 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003346 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003347 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003348 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003349 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003350 */
3351 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003352 sizeof(struct e1000_tx_desc) -
3353 ETH_FCS_LEN) * 2;
3354 min_tx_space = ALIGN(min_tx_space, 1024);
3355 min_tx_space >>= 10;
3356 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003357 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003358 min_rx_space = ALIGN(min_rx_space, 1024);
3359 min_rx_space >>= 10;
3360
Bruce Allanad680762008-03-28 09:15:03 -07003361 /*
3362 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003363 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003364 * allocation, take space away from current Rx allocation
3365 */
Auke Kokdf762462007-10-25 13:57:53 -07003366 if ((tx_space < min_tx_space) &&
3367 ((min_tx_space - tx_space) < pba)) {
3368 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003369
Bruce Allanad680762008-03-28 09:15:03 -07003370 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003371 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003372 * adjustment or use Early Receive if available
3373 */
Auke Kokdf762462007-10-25 13:57:53 -07003374 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003375 (!(adapter->flags & FLAG_HAS_ERT)))
3376 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003377 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003378 }
Auke Kokdf762462007-10-25 13:57:53 -07003379
3380 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003381 }
3382
Bruce Allanad680762008-03-28 09:15:03 -07003383 /*
3384 * flow control settings
3385 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003386 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003387 * (or the size used for early receive) above it in the Rx FIFO.
3388 * Set it to the lower of:
3389 * - 90% of the Rx FIFO size, and
3390 * - the full Rx FIFO size minus the early receive size (for parts
3391 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003392 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003393 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003394 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3395 fc->pause_time = 0xFFFF;
3396 else
3397 fc->pause_time = E1000_FC_PAUSE_TIME;
3398 fc->send_xon = 1;
3399 fc->current_mode = fc->requested_mode;
3400
3401 switch (hw->mac.type) {
3402 default:
3403 if ((adapter->flags & FLAG_HAS_ERT) &&
3404 (adapter->netdev->mtu > ETH_DATA_LEN))
3405 hwm = min(((pba << 10) * 9 / 10),
3406 ((pba << 10) - (E1000_ERT_2048 << 3)));
3407 else
3408 hwm = min(((pba << 10) * 9 / 10),
3409 ((pba << 10) - adapter->max_frame_size));
3410
3411 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3412 fc->low_water = fc->high_water - 8;
3413 break;
3414 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003415 /*
3416 * Workaround PCH LOM adapter hangs with certain network
3417 * loads. If hangs persist, try disabling Tx flow control.
3418 */
3419 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3420 fc->high_water = 0x3500;
3421 fc->low_water = 0x1500;
3422 } else {
3423 fc->high_water = 0x5000;
3424 fc->low_water = 0x3000;
3425 }
Bruce Allana3055952010-05-10 15:02:12 +00003426 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003427 break;
3428 case e1000_pch2lan:
3429 fc->high_water = 0x05C20;
3430 fc->low_water = 0x05048;
3431 fc->pause_time = 0x0650;
3432 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003433 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3434 pba = 14;
3435 ew32(PBA, pba);
3436 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003437 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003438 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003439
Bruce Allan828bac82010-09-29 21:39:37 +00003440 /*
3441 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3442 * fit in receive buffer and early-receive not supported.
3443 */
3444 if (adapter->itr_setting & 0x3) {
3445 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3446 !(adapter->flags & FLAG_HAS_ERT)) {
3447 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3448 dev_info(&adapter->pdev->dev,
3449 "Interrupt Throttle Rate turned off\n");
3450 adapter->flags2 |= FLAG2_DISABLE_AIM;
3451 ew32(ITR, 0);
3452 }
3453 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3454 dev_info(&adapter->pdev->dev,
3455 "Interrupt Throttle Rate turned on\n");
3456 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3457 adapter->itr = 20000;
3458 ew32(ITR, 1000000000 / (adapter->itr * 256));
3459 }
3460 }
3461
Auke Kokbc7f75f2007-09-17 12:30:59 -07003462 /* Allow time for pending master requests to run */
3463 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003464
3465 /*
3466 * For parts with AMT enabled, let the firmware know
3467 * that the network interface is in control
3468 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003469 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003470 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003471
Auke Kokbc7f75f2007-09-17 12:30:59 -07003472 ew32(WUC, 0);
3473
3474 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003475 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003476
3477 e1000_update_mng_vlan(adapter);
3478
3479 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3480 ew32(VET, ETH_P_8021Q);
3481
3482 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003483
3484 if (!netif_running(adapter->netdev) &&
3485 !test_bit(__E1000_TESTING, &adapter->state)) {
3486 e1000_power_down_phy(adapter);
3487 return;
3488 }
3489
Auke Kokbc7f75f2007-09-17 12:30:59 -07003490 e1000_get_phy_info(hw);
3491
Bruce Allan918d7192009-06-02 11:28:20 +00003492 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3493 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003494 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003495 /*
3496 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003497 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003498 * different we would do if it failed
3499 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003500 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3501 phy_data &= ~IGP02E1000_PM_SPD;
3502 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3503 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003504}
3505
3506int e1000e_up(struct e1000_adapter *adapter)
3507{
3508 struct e1000_hw *hw = &adapter->hw;
3509
3510 /* hardware has been reset, we need to reload some things */
3511 e1000_configure(adapter);
3512
3513 clear_bit(__E1000_DOWN, &adapter->state);
3514
3515 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003516 if (adapter->msix_entries)
3517 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003518 e1000_irq_enable(adapter);
3519
Bruce Allan400484f2011-05-13 07:20:03 +00003520 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003521
Auke Kokbc7f75f2007-09-17 12:30:59 -07003522 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003523 if (adapter->msix_entries)
3524 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3525 else
3526 ew32(ICS, E1000_ICS_LSC);
3527
Auke Kokbc7f75f2007-09-17 12:30:59 -07003528 return 0;
3529}
3530
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003531static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3532{
3533 struct e1000_hw *hw = &adapter->hw;
3534
3535 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3536 return;
3537
3538 /* flush pending descriptor writebacks to memory */
3539 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3540 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3541
3542 /* execute the writes immediately */
3543 e1e_flush();
3544}
3545
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003546static void e1000e_update_stats(struct e1000_adapter *adapter);
3547
Auke Kokbc7f75f2007-09-17 12:30:59 -07003548void e1000e_down(struct e1000_adapter *adapter)
3549{
3550 struct net_device *netdev = adapter->netdev;
3551 struct e1000_hw *hw = &adapter->hw;
3552 u32 tctl, rctl;
3553
Bruce Allanad680762008-03-28 09:15:03 -07003554 /*
3555 * signal that we're down so the interrupt handler does not
3556 * reschedule our watchdog timer
3557 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003558 set_bit(__E1000_DOWN, &adapter->state);
3559
3560 /* disable receives in the hardware */
3561 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003562 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3563 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003564 /* flush and sleep below */
3565
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003566 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003567
3568 /* disable transmits in the hardware */
3569 tctl = er32(TCTL);
3570 tctl &= ~E1000_TCTL_EN;
3571 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003572
Auke Kokbc7f75f2007-09-17 12:30:59 -07003573 /* flush both disables and wait for them to finish */
3574 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003575 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003576
3577 napi_disable(&adapter->napi);
3578 e1000_irq_disable(adapter);
3579
3580 del_timer_sync(&adapter->watchdog_timer);
3581 del_timer_sync(&adapter->phy_info_timer);
3582
Auke Kokbc7f75f2007-09-17 12:30:59 -07003583 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003584
3585 spin_lock(&adapter->stats64_lock);
3586 e1000e_update_stats(adapter);
3587 spin_unlock(&adapter->stats64_lock);
3588
Bruce Allan400484f2011-05-13 07:20:03 +00003589 e1000e_flush_descriptors(adapter);
3590 e1000_clean_tx_ring(adapter);
3591 e1000_clean_rx_ring(adapter);
3592
Auke Kokbc7f75f2007-09-17 12:30:59 -07003593 adapter->link_speed = 0;
3594 adapter->link_duplex = 0;
3595
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003596 if (!pci_channel_offline(adapter->pdev))
3597 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003598
Auke Kokbc7f75f2007-09-17 12:30:59 -07003599 /*
3600 * TODO: for power management, we could drop the link and
3601 * pci_disable_device here.
3602 */
3603}
3604
3605void e1000e_reinit_locked(struct e1000_adapter *adapter)
3606{
3607 might_sleep();
3608 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003609 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003610 e1000e_down(adapter);
3611 e1000e_up(adapter);
3612 clear_bit(__E1000_RESETTING, &adapter->state);
3613}
3614
3615/**
3616 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3617 * @adapter: board private structure to initialize
3618 *
3619 * e1000_sw_init initializes the Adapter private data structure.
3620 * Fields are initialized based on PCI device information and
3621 * OS network device settings (MTU size).
3622 **/
3623static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3624{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003625 struct net_device *netdev = adapter->netdev;
3626
3627 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3628 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003629 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3630 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003631
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003632 spin_lock_init(&adapter->stats64_lock);
3633
Bruce Allan4662e822008-08-26 18:37:06 -07003634 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003635
Bruce Allan4662e822008-08-26 18:37:06 -07003636 if (e1000_alloc_queues(adapter))
3637 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003638
Auke Kokbc7f75f2007-09-17 12:30:59 -07003639 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003640 e1000_irq_disable(adapter);
3641
Auke Kokbc7f75f2007-09-17 12:30:59 -07003642 set_bit(__E1000_DOWN, &adapter->state);
3643 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003644}
3645
3646/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003647 * e1000_intr_msi_test - Interrupt Handler
3648 * @irq: interrupt number
3649 * @data: pointer to a network interface device structure
3650 **/
3651static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3652{
3653 struct net_device *netdev = data;
3654 struct e1000_adapter *adapter = netdev_priv(netdev);
3655 struct e1000_hw *hw = &adapter->hw;
3656 u32 icr = er32(ICR);
3657
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003658 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003659 if (icr & E1000_ICR_RXSEQ) {
3660 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3661 wmb();
3662 }
3663
3664 return IRQ_HANDLED;
3665}
3666
3667/**
3668 * e1000_test_msi_interrupt - Returns 0 for successful test
3669 * @adapter: board private struct
3670 *
3671 * code flow taken from tg3.c
3672 **/
3673static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3674{
3675 struct net_device *netdev = adapter->netdev;
3676 struct e1000_hw *hw = &adapter->hw;
3677 int err;
3678
3679 /* poll_enable hasn't been called yet, so don't need disable */
3680 /* clear any pending events */
3681 er32(ICR);
3682
3683 /* free the real vector and request a test handler */
3684 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003685 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003686
3687 /* Assume that the test fails, if it succeeds then the test
3688 * MSI irq handler will unset this flag */
3689 adapter->flags |= FLAG_MSI_TEST_FAILED;
3690
3691 err = pci_enable_msi(adapter->pdev);
3692 if (err)
3693 goto msi_test_failed;
3694
Joe Perchesa0607fd2009-11-18 23:29:17 -08003695 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003696 netdev->name, netdev);
3697 if (err) {
3698 pci_disable_msi(adapter->pdev);
3699 goto msi_test_failed;
3700 }
3701
3702 wmb();
3703
3704 e1000_irq_enable(adapter);
3705
3706 /* fire an unusual interrupt on the test handler */
3707 ew32(ICS, E1000_ICS_RXSEQ);
3708 e1e_flush();
3709 msleep(50);
3710
3711 e1000_irq_disable(adapter);
3712
3713 rmb();
3714
3715 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003716 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003717 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3718 } else
3719 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003720
3721 free_irq(adapter->pdev->irq, netdev);
3722 pci_disable_msi(adapter->pdev);
3723
Bruce Allanf8d59f72008-08-08 18:36:11 -07003724msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003725 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003726 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003727}
3728
3729/**
3730 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3731 * @adapter: board private struct
3732 *
3733 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3734 **/
3735static int e1000_test_msi(struct e1000_adapter *adapter)
3736{
3737 int err;
3738 u16 pci_cmd;
3739
3740 if (!(adapter->flags & FLAG_MSI_ENABLED))
3741 return 0;
3742
3743 /* disable SERR in case the MSI write causes a master abort */
3744 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003745 if (pci_cmd & PCI_COMMAND_SERR)
3746 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3747 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003748
3749 err = e1000_test_msi_interrupt(adapter);
3750
Dean Nelson36f24072010-06-29 18:12:05 +00003751 /* re-enable SERR */
3752 if (pci_cmd & PCI_COMMAND_SERR) {
3753 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3754 pci_cmd |= PCI_COMMAND_SERR;
3755 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3756 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003757
Bruce Allanf8d59f72008-08-08 18:36:11 -07003758 return err;
3759}
3760
3761/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003762 * e1000_open - Called when a network interface is made active
3763 * @netdev: network interface device structure
3764 *
3765 * Returns 0 on success, negative value on failure
3766 *
3767 * The open entry point is called when a network interface is made
3768 * active by the system (IFF_UP). At this point all resources needed
3769 * for transmit and receive operations are allocated, the interrupt
3770 * handler is registered with the OS, the watchdog timer is started,
3771 * and the stack is notified that the interface is ready.
3772 **/
3773static int e1000_open(struct net_device *netdev)
3774{
3775 struct e1000_adapter *adapter = netdev_priv(netdev);
3776 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003777 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003778 int err;
3779
3780 /* disallow open during test */
3781 if (test_bit(__E1000_TESTING, &adapter->state))
3782 return -EBUSY;
3783
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003784 pm_runtime_get_sync(&pdev->dev);
3785
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003786 netif_carrier_off(netdev);
3787
Auke Kokbc7f75f2007-09-17 12:30:59 -07003788 /* allocate transmit descriptors */
3789 err = e1000e_setup_tx_resources(adapter);
3790 if (err)
3791 goto err_setup_tx;
3792
3793 /* allocate receive descriptors */
3794 err = e1000e_setup_rx_resources(adapter);
3795 if (err)
3796 goto err_setup_rx;
3797
Bruce Allan11b08be2010-05-10 14:59:31 +00003798 /*
3799 * If AMT is enabled, let the firmware know that the network
3800 * interface is now open and reset the part to a known state.
3801 */
3802 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003803 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003804 e1000e_reset(adapter);
3805 }
3806
Auke Kokbc7f75f2007-09-17 12:30:59 -07003807 e1000e_power_up_phy(adapter);
3808
3809 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3810 if ((adapter->hw.mng_cookie.status &
3811 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3812 e1000_update_mng_vlan(adapter);
3813
Florian Micklerc128ec22010-08-02 14:27:00 +00003814 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003815 if ((adapter->flags & FLAG_HAS_ERT) ||
3816 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003817 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3818 PM_QOS_CPU_DMA_LATENCY,
3819 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003820
Bruce Allanad680762008-03-28 09:15:03 -07003821 /*
Bruce Allanad680762008-03-28 09:15:03 -07003822 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003823 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3824 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003825 * clean_rx handler before we do so.
3826 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003827 e1000_configure(adapter);
3828
3829 err = e1000_request_irq(adapter);
3830 if (err)
3831 goto err_req_irq;
3832
Bruce Allanf8d59f72008-08-08 18:36:11 -07003833 /*
3834 * Work around PCIe errata with MSI interrupts causing some chipsets to
3835 * ignore e1000e MSI messages, which means we need to test our MSI
3836 * interrupt now
3837 */
Bruce Allan4662e822008-08-26 18:37:06 -07003838 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003839 err = e1000_test_msi(adapter);
3840 if (err) {
3841 e_err("Interrupt allocation failed\n");
3842 goto err_req_irq;
3843 }
3844 }
3845
Auke Kokbc7f75f2007-09-17 12:30:59 -07003846 /* From here on the code is the same as e1000e_up() */
3847 clear_bit(__E1000_DOWN, &adapter->state);
3848
3849 napi_enable(&adapter->napi);
3850
3851 e1000_irq_enable(adapter);
3852
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003853 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003854
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003855 adapter->idle_check = true;
3856 pm_runtime_put(&pdev->dev);
3857
Auke Kokbc7f75f2007-09-17 12:30:59 -07003858 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003859 if (adapter->msix_entries)
3860 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3861 else
3862 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003863
3864 return 0;
3865
3866err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003867 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003868 e1000_power_down_phy(adapter);
3869 e1000e_free_rx_resources(adapter);
3870err_setup_rx:
3871 e1000e_free_tx_resources(adapter);
3872err_setup_tx:
3873 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003874 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003875
3876 return err;
3877}
3878
3879/**
3880 * e1000_close - Disables a network interface
3881 * @netdev: network interface device structure
3882 *
3883 * Returns 0, this is not allowed to fail
3884 *
3885 * The close entry point is called when an interface is de-activated
3886 * by the OS. The hardware is still under the drivers control, but
3887 * needs to be disabled. A global MAC reset is issued to stop the
3888 * hardware, and all transmit and receive resources are freed.
3889 **/
3890static int e1000_close(struct net_device *netdev)
3891{
3892 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003893 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003894
3895 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003896
3897 pm_runtime_get_sync(&pdev->dev);
3898
3899 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3900 e1000e_down(adapter);
3901 e1000_free_irq(adapter);
3902 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003903 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003904
3905 e1000e_free_tx_resources(adapter);
3906 e1000e_free_rx_resources(adapter);
3907
Bruce Allanad680762008-03-28 09:15:03 -07003908 /*
3909 * kill manageability vlan ID if supported, but not if a vlan with
3910 * the same ID is registered on the host OS (let 8021q kill it)
3911 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003912 if (adapter->hw.mng_cookie.status &
3913 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003914 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3915
Bruce Allanad680762008-03-28 09:15:03 -07003916 /*
3917 * If AMT is enabled, let the firmware know that the network
3918 * interface is now closed
3919 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003920 if ((adapter->flags & FLAG_HAS_AMT) &&
3921 !test_bit(__E1000_TESTING, &adapter->state))
3922 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003923
Bruce Allan828bac82010-09-29 21:39:37 +00003924 if ((adapter->flags & FLAG_HAS_ERT) ||
3925 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003926 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003927
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003928 pm_runtime_put_sync(&pdev->dev);
3929
Auke Kokbc7f75f2007-09-17 12:30:59 -07003930 return 0;
3931}
3932/**
3933 * e1000_set_mac - Change the Ethernet Address of the NIC
3934 * @netdev: network interface device structure
3935 * @p: pointer to an address structure
3936 *
3937 * Returns 0 on success, negative on failure
3938 **/
3939static int e1000_set_mac(struct net_device *netdev, void *p)
3940{
3941 struct e1000_adapter *adapter = netdev_priv(netdev);
3942 struct sockaddr *addr = p;
3943
3944 if (!is_valid_ether_addr(addr->sa_data))
3945 return -EADDRNOTAVAIL;
3946
3947 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3948 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3949
3950 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3951
3952 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3953 /* activate the work around */
3954 e1000e_set_laa_state_82571(&adapter->hw, 1);
3955
Bruce Allanad680762008-03-28 09:15:03 -07003956 /*
3957 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003958 * between the time RAR[0] gets clobbered and the time it
3959 * gets fixed (in e1000_watchdog), the actual LAA is in one
3960 * of the RARs and no incoming packets directed to this port
3961 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003962 * RAR[14]
3963 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003964 e1000e_rar_set(&adapter->hw,
3965 adapter->hw.mac.addr,
3966 adapter->hw.mac.rar_entry_count - 1);
3967 }
3968
3969 return 0;
3970}
3971
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003972/**
3973 * e1000e_update_phy_task - work thread to update phy
3974 * @work: pointer to our work struct
3975 *
3976 * this worker thread exists because we must acquire a
3977 * semaphore to read the phy, which we could msleep while
3978 * waiting for it, and we can't msleep in a timer.
3979 **/
3980static void e1000e_update_phy_task(struct work_struct *work)
3981{
3982 struct e1000_adapter *adapter = container_of(work,
3983 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003984
3985 if (test_bit(__E1000_DOWN, &adapter->state))
3986 return;
3987
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003988 e1000_get_phy_info(&adapter->hw);
3989}
3990
Bruce Allanad680762008-03-28 09:15:03 -07003991/*
3992 * Need to wait a few seconds after link up to get diagnostic information from
3993 * the phy
3994 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003995static void e1000_update_phy_info(unsigned long data)
3996{
3997 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003998
3999 if (test_bit(__E1000_DOWN, &adapter->state))
4000 return;
4001
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004002 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004003}
4004
4005/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004006 * e1000e_update_phy_stats - Update the PHY statistics counters
4007 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004008 *
4009 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004010 **/
4011static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4012{
4013 struct e1000_hw *hw = &adapter->hw;
4014 s32 ret_val;
4015 u16 phy_data;
4016
4017 ret_val = hw->phy.ops.acquire(hw);
4018 if (ret_val)
4019 return;
4020
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004021 /*
4022 * A page set is expensive so check if already on desired page.
4023 * If not, set to the page with the PHY status registers.
4024 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004025 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004026 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4027 &phy_data);
4028 if (ret_val)
4029 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004030 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4031 ret_val = hw->phy.ops.set_page(hw,
4032 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004033 if (ret_val)
4034 goto release;
4035 }
4036
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004037 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004038 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4039 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004040 if (!ret_val)
4041 adapter->stats.scc += phy_data;
4042
4043 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004044 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4045 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004046 if (!ret_val)
4047 adapter->stats.ecol += phy_data;
4048
4049 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004050 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4051 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004052 if (!ret_val)
4053 adapter->stats.mcc += phy_data;
4054
4055 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004056 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4057 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004058 if (!ret_val)
4059 adapter->stats.latecol += phy_data;
4060
4061 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004062 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4063 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004064 if (!ret_val)
4065 hw->mac.collision_delta = phy_data;
4066
4067 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004068 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4069 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004070 if (!ret_val)
4071 adapter->stats.dc += phy_data;
4072
4073 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004074 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4075 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004076 if (!ret_val)
4077 adapter->stats.tncrs += phy_data;
4078
4079release:
4080 hw->phy.ops.release(hw);
4081}
4082
4083/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004084 * e1000e_update_stats - Update the board statistics counters
4085 * @adapter: board private structure
4086 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004087static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004089 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004090 struct e1000_hw *hw = &adapter->hw;
4091 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004092
4093 /*
4094 * Prevent stats update while adapter is being reset, or if the pci
4095 * connection is down.
4096 */
4097 if (adapter->link_speed == 0)
4098 return;
4099 if (pci_channel_offline(pdev))
4100 return;
4101
Auke Kokbc7f75f2007-09-17 12:30:59 -07004102 adapter->stats.crcerrs += er32(CRCERRS);
4103 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004104 adapter->stats.gorc += er32(GORCL);
4105 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004106 adapter->stats.bprc += er32(BPRC);
4107 adapter->stats.mprc += er32(MPRC);
4108 adapter->stats.roc += er32(ROC);
4109
Auke Kokbc7f75f2007-09-17 12:30:59 -07004110 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004111
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004112 /* Half-duplex statistics */
4113 if (adapter->link_duplex == HALF_DUPLEX) {
4114 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4115 e1000e_update_phy_stats(adapter);
4116 } else {
4117 adapter->stats.scc += er32(SCC);
4118 adapter->stats.ecol += er32(ECOL);
4119 adapter->stats.mcc += er32(MCC);
4120 adapter->stats.latecol += er32(LATECOL);
4121 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004122
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004123 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004124
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004125 if ((hw->mac.type != e1000_82574) &&
4126 (hw->mac.type != e1000_82583))
4127 adapter->stats.tncrs += er32(TNCRS);
4128 }
4129 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004130 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004131
Auke Kokbc7f75f2007-09-17 12:30:59 -07004132 adapter->stats.xonrxc += er32(XONRXC);
4133 adapter->stats.xontxc += er32(XONTXC);
4134 adapter->stats.xoffrxc += er32(XOFFRXC);
4135 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004136 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004137 adapter->stats.gotc += er32(GOTCL);
4138 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004139 adapter->stats.rnbc += er32(RNBC);
4140 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004141
4142 adapter->stats.mptc += er32(MPTC);
4143 adapter->stats.bptc += er32(BPTC);
4144
4145 /* used for adaptive IFS */
4146
4147 hw->mac.tx_packet_delta = er32(TPT);
4148 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004149
4150 adapter->stats.algnerrc += er32(ALGNERRC);
4151 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004152 adapter->stats.cexterr += er32(CEXTERR);
4153 adapter->stats.tsctc += er32(TSCTC);
4154 adapter->stats.tsctfc += er32(TSCTFC);
4155
Auke Kokbc7f75f2007-09-17 12:30:59 -07004156 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004157 netdev->stats.multicast = adapter->stats.mprc;
4158 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004159
4160 /* Rx Errors */
4161
Bruce Allanad680762008-03-28 09:15:03 -07004162 /*
4163 * RLEC on some newer hardware can be incorrect so build
4164 * our own version based on RUC and ROC
4165 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004166 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004167 adapter->stats.crcerrs + adapter->stats.algnerrc +
4168 adapter->stats.ruc + adapter->stats.roc +
4169 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004170 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004171 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004172 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4173 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4174 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004175
4176 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004177 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004178 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004179 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4180 netdev->stats.tx_window_errors = adapter->stats.latecol;
4181 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004182
4183 /* Tx Dropped needs to be maintained elsewhere */
4184
Auke Kokbc7f75f2007-09-17 12:30:59 -07004185 /* Management Stats */
4186 adapter->stats.mgptc += er32(MGTPTC);
4187 adapter->stats.mgprc += er32(MGTPRC);
4188 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004189}
4190
Bruce Allan7c257692008-04-23 11:09:00 -07004191/**
4192 * e1000_phy_read_status - Update the PHY register status snapshot
4193 * @adapter: board private structure
4194 **/
4195static void e1000_phy_read_status(struct e1000_adapter *adapter)
4196{
4197 struct e1000_hw *hw = &adapter->hw;
4198 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004199
4200 if ((er32(STATUS) & E1000_STATUS_LU) &&
4201 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004202 int ret_val;
4203
Bruce Allan7c257692008-04-23 11:09:00 -07004204 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4205 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4206 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4207 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4208 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4209 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4210 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4211 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4212 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004213 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004214 } else {
4215 /*
4216 * Do not read PHY registers if link is not up
4217 * Set values to typical power-on defaults
4218 */
4219 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4220 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4221 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4222 BMSR_ERCAP);
4223 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4224 ADVERTISE_ALL | ADVERTISE_CSMA);
4225 phy->lpa = 0;
4226 phy->expansion = EXPANSION_ENABLENPAGE;
4227 phy->ctrl1000 = ADVERTISE_1000FULL;
4228 phy->stat1000 = 0;
4229 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4230 }
Bruce Allan7c257692008-04-23 11:09:00 -07004231}
4232
Auke Kokbc7f75f2007-09-17 12:30:59 -07004233static void e1000_print_link_info(struct e1000_adapter *adapter)
4234{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004235 struct e1000_hw *hw = &adapter->hw;
4236 u32 ctrl = er32(CTRL);
4237
Bruce Allan8f12fe82008-11-21 16:54:43 -08004238 /* Link status message must follow this format for user tools */
4239 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4240 "Flow Control: %s\n",
4241 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004242 adapter->link_speed,
4243 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004244 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004245 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004246 "Rx/Tx" :
4247 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4248 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004249}
4250
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004251static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004252{
4253 struct e1000_hw *hw = &adapter->hw;
4254 bool link_active = 0;
4255 s32 ret_val = 0;
4256
4257 /*
4258 * get_link_status is set on LSC (link status) interrupt or
4259 * Rx sequence error interrupt. get_link_status will stay
4260 * false until the check_for_link establishes link
4261 * for copper adapters ONLY
4262 */
4263 switch (hw->phy.media_type) {
4264 case e1000_media_type_copper:
4265 if (hw->mac.get_link_status) {
4266 ret_val = hw->mac.ops.check_for_link(hw);
4267 link_active = !hw->mac.get_link_status;
4268 } else {
4269 link_active = 1;
4270 }
4271 break;
4272 case e1000_media_type_fiber:
4273 ret_val = hw->mac.ops.check_for_link(hw);
4274 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4275 break;
4276 case e1000_media_type_internal_serdes:
4277 ret_val = hw->mac.ops.check_for_link(hw);
4278 link_active = adapter->hw.mac.serdes_has_link;
4279 break;
4280 default:
4281 case e1000_media_type_unknown:
4282 break;
4283 }
4284
4285 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4286 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4287 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004288 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004289 }
4290
4291 return link_active;
4292}
4293
4294static void e1000e_enable_receives(struct e1000_adapter *adapter)
4295{
4296 /* make sure the receive unit is started */
4297 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4298 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4299 struct e1000_hw *hw = &adapter->hw;
4300 u32 rctl = er32(RCTL);
4301 ew32(RCTL, rctl | E1000_RCTL_EN);
4302 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4303 }
4304}
4305
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004306static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4307{
4308 struct e1000_hw *hw = &adapter->hw;
4309
4310 /*
4311 * With 82574 controllers, PHY needs to be checked periodically
4312 * for hung state and reset, if two calls return true
4313 */
4314 if (e1000_check_phy_82574(hw))
4315 adapter->phy_hang_count++;
4316 else
4317 adapter->phy_hang_count = 0;
4318
4319 if (adapter->phy_hang_count > 1) {
4320 adapter->phy_hang_count = 0;
4321 schedule_work(&adapter->reset_task);
4322 }
4323}
4324
Auke Kokbc7f75f2007-09-17 12:30:59 -07004325/**
4326 * e1000_watchdog - Timer Call-back
4327 * @data: pointer to adapter cast into an unsigned long
4328 **/
4329static void e1000_watchdog(unsigned long data)
4330{
4331 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4332
4333 /* Do the rest outside of interrupt context */
4334 schedule_work(&adapter->watchdog_task);
4335
4336 /* TODO: make this use queue_delayed_work() */
4337}
4338
4339static void e1000_watchdog_task(struct work_struct *work)
4340{
4341 struct e1000_adapter *adapter = container_of(work,
4342 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004343 struct net_device *netdev = adapter->netdev;
4344 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004345 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004346 struct e1000_ring *tx_ring = adapter->tx_ring;
4347 struct e1000_hw *hw = &adapter->hw;
4348 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004349
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004350 if (test_bit(__E1000_DOWN, &adapter->state))
4351 return;
4352
David S. Millerb405e8d2010-02-04 22:31:41 -08004353 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004354 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004355 /* Cancel scheduled suspend requests. */
4356 pm_runtime_resume(netdev->dev.parent);
4357
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004358 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004359 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004360 }
4361
4362 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4363 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4364 e1000_update_mng_vlan(adapter);
4365
Auke Kokbc7f75f2007-09-17 12:30:59 -07004366 if (link) {
4367 if (!netif_carrier_ok(netdev)) {
4368 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004369
4370 /* Cancel scheduled suspend requests. */
4371 pm_runtime_resume(netdev->dev.parent);
4372
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004373 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004374 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004375 mac->ops.get_link_up_info(&adapter->hw,
4376 &adapter->link_speed,
4377 &adapter->link_duplex);
4378 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004379 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004380 * On supported PHYs, check for duplex mismatch only
4381 * if link has autonegotiated at 10/100 half
4382 */
4383 if ((hw->phy.type == e1000_phy_igp_3 ||
4384 hw->phy.type == e1000_phy_bm) &&
4385 (hw->mac.autoneg == true) &&
4386 (adapter->link_speed == SPEED_10 ||
4387 adapter->link_speed == SPEED_100) &&
4388 (adapter->link_duplex == HALF_DUPLEX)) {
4389 u16 autoneg_exp;
4390
4391 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4392
4393 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4394 e_info("Autonegotiated half duplex but"
4395 " link partner cannot autoneg. "
4396 " Try forcing full duplex if "
4397 "link gets many collisions.\n");
4398 }
4399
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004400 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004401 adapter->tx_timeout_factor = 1;
4402 switch (adapter->link_speed) {
4403 case SPEED_10:
4404 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004405 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004406 break;
4407 case SPEED_100:
4408 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004409 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004410 break;
4411 }
4412
Bruce Allanad680762008-03-28 09:15:03 -07004413 /*
4414 * workaround: re-program speed mode bit after
4415 * link-up event
4416 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004417 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4418 !txb2b) {
4419 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004420 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004421 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004422 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004423 }
4424
Bruce Allanad680762008-03-28 09:15:03 -07004425 /*
4426 * disable TSO for pcie and 10/100 speeds, to avoid
4427 * some hardware issues
4428 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004429 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4430 switch (adapter->link_speed) {
4431 case SPEED_10:
4432 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004433 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004434 netdev->features &= ~NETIF_F_TSO;
4435 netdev->features &= ~NETIF_F_TSO6;
4436 break;
4437 case SPEED_1000:
4438 netdev->features |= NETIF_F_TSO;
4439 netdev->features |= NETIF_F_TSO6;
4440 break;
4441 default:
4442 /* oops */
4443 break;
4444 }
4445 }
4446
Bruce Allanad680762008-03-28 09:15:03 -07004447 /*
4448 * enable transmits in the hardware, need to do this
4449 * after setting TARC(0)
4450 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004451 tctl = er32(TCTL);
4452 tctl |= E1000_TCTL_EN;
4453 ew32(TCTL, tctl);
4454
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004455 /*
4456 * Perform any post-link-up configuration before
4457 * reporting link up.
4458 */
4459 if (phy->ops.cfg_on_link_up)
4460 phy->ops.cfg_on_link_up(hw);
4461
Auke Kokbc7f75f2007-09-17 12:30:59 -07004462 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004463
4464 if (!test_bit(__E1000_DOWN, &adapter->state))
4465 mod_timer(&adapter->phy_info_timer,
4466 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004467 }
4468 } else {
4469 if (netif_carrier_ok(netdev)) {
4470 adapter->link_speed = 0;
4471 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004472 /* Link status message must follow this format */
4473 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4474 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004475 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004476 if (!test_bit(__E1000_DOWN, &adapter->state))
4477 mod_timer(&adapter->phy_info_timer,
4478 round_jiffies(jiffies + 2 * HZ));
4479
4480 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4481 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004482 else
4483 pm_schedule_suspend(netdev->dev.parent,
4484 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004485 }
4486 }
4487
4488link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004489 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004490 e1000e_update_stats(adapter);
4491
4492 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4493 adapter->tpt_old = adapter->stats.tpt;
4494 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4495 adapter->colc_old = adapter->stats.colc;
4496
Bruce Allan7c257692008-04-23 11:09:00 -07004497 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4498 adapter->gorc_old = adapter->stats.gorc;
4499 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4500 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004501 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004502
4503 e1000e_update_adaptive(&adapter->hw);
4504
Bruce Allan90da0662011-01-06 07:02:53 +00004505 if (!netif_carrier_ok(netdev) &&
4506 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4507 /*
4508 * We've lost link, so the controller stops DMA,
4509 * but we've got queued Tx work that's never going
4510 * to get done, so reset controller to flush Tx.
4511 * (Do the reset outside of interrupt context).
4512 */
Bruce Allan90da0662011-01-06 07:02:53 +00004513 schedule_work(&adapter->reset_task);
4514 /* return immediately since reset is imminent */
4515 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004516 }
4517
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004518 /* Simple mode for Interrupt Throttle Rate (ITR) */
4519 if (adapter->itr_setting == 4) {
4520 /*
4521 * Symmetric Tx/Rx gets a reduced ITR=2000;
4522 * Total asymmetrical Tx or Rx gets ITR=8000;
4523 * everyone else is between 2000-8000.
4524 */
4525 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4526 u32 dif = (adapter->gotc > adapter->gorc ?
4527 adapter->gotc - adapter->gorc :
4528 adapter->gorc - adapter->gotc) / 10000;
4529 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4530
4531 ew32(ITR, 1000000000 / (itr * 256));
4532 }
4533
Bruce Allanad680762008-03-28 09:15:03 -07004534 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004535 if (adapter->msix_entries)
4536 ew32(ICS, adapter->rx_ring->ims_val);
4537 else
4538 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004539
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004540 /* flush pending descriptors to memory before detecting Tx hang */
4541 e1000e_flush_descriptors(adapter);
4542
Auke Kokbc7f75f2007-09-17 12:30:59 -07004543 /* Force detection of hung controller every watchdog period */
4544 adapter->detect_tx_hung = 1;
4545
Bruce Allanad680762008-03-28 09:15:03 -07004546 /*
4547 * With 82571 controllers, LAA may be overwritten due to controller
4548 * reset from the other port. Set the appropriate LAA in RAR[0]
4549 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004550 if (e1000e_get_laa_state_82571(hw))
4551 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4552
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004553 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4554 e1000e_check_82574_phy_workaround(adapter);
4555
Auke Kokbc7f75f2007-09-17 12:30:59 -07004556 /* Reset the timer */
4557 if (!test_bit(__E1000_DOWN, &adapter->state))
4558 mod_timer(&adapter->watchdog_timer,
4559 round_jiffies(jiffies + 2 * HZ));
4560}
4561
4562#define E1000_TX_FLAGS_CSUM 0x00000001
4563#define E1000_TX_FLAGS_VLAN 0x00000002
4564#define E1000_TX_FLAGS_TSO 0x00000004
4565#define E1000_TX_FLAGS_IPV4 0x00000008
4566#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4567#define E1000_TX_FLAGS_VLAN_SHIFT 16
4568
4569static int e1000_tso(struct e1000_adapter *adapter,
4570 struct sk_buff *skb)
4571{
4572 struct e1000_ring *tx_ring = adapter->tx_ring;
4573 struct e1000_context_desc *context_desc;
4574 struct e1000_buffer *buffer_info;
4575 unsigned int i;
4576 u32 cmd_length = 0;
4577 u16 ipcse = 0, tucse, mss;
4578 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004579
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004580 if (!skb_is_gso(skb))
4581 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004582
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004583 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004584 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4585
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004586 if (err)
4587 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004588 }
4589
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004590 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4591 mss = skb_shinfo(skb)->gso_size;
4592 if (skb->protocol == htons(ETH_P_IP)) {
4593 struct iphdr *iph = ip_hdr(skb);
4594 iph->tot_len = 0;
4595 iph->check = 0;
4596 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4597 0, IPPROTO_TCP, 0);
4598 cmd_length = E1000_TXD_CMD_IP;
4599 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004600 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004601 ipv6_hdr(skb)->payload_len = 0;
4602 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4603 &ipv6_hdr(skb)->daddr,
4604 0, IPPROTO_TCP, 0);
4605 ipcse = 0;
4606 }
4607 ipcss = skb_network_offset(skb);
4608 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4609 tucss = skb_transport_offset(skb);
4610 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4611 tucse = 0;
4612
4613 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4614 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4615
4616 i = tx_ring->next_to_use;
4617 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4618 buffer_info = &tx_ring->buffer_info[i];
4619
4620 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4621 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4622 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4623 context_desc->upper_setup.tcp_fields.tucss = tucss;
4624 context_desc->upper_setup.tcp_fields.tucso = tucso;
4625 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4626 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4627 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4628 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4629
4630 buffer_info->time_stamp = jiffies;
4631 buffer_info->next_to_watch = i;
4632
4633 i++;
4634 if (i == tx_ring->count)
4635 i = 0;
4636 tx_ring->next_to_use = i;
4637
4638 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004639}
4640
4641static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4642{
4643 struct e1000_ring *tx_ring = adapter->tx_ring;
4644 struct e1000_context_desc *context_desc;
4645 struct e1000_buffer *buffer_info;
4646 unsigned int i;
4647 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004648 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004649 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004650
Dave Grahamaf807c82008-10-09 14:28:58 -07004651 if (skb->ip_summed != CHECKSUM_PARTIAL)
4652 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004653
Arthur Jones5f66f202009-03-19 01:13:08 +00004654 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4655 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4656 else
4657 protocol = skb->protocol;
4658
Arthur Jones3f518392009-03-20 15:56:35 -07004659 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004660 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004661 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4662 cmd_len |= E1000_TXD_CMD_TCP;
4663 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004664 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004665 /* XXX not handling all IPV6 headers */
4666 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4667 cmd_len |= E1000_TXD_CMD_TCP;
4668 break;
4669 default:
4670 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004671 e_warn("checksum_partial proto=%x!\n",
4672 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004673 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004674 }
4675
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004676 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004677
4678 i = tx_ring->next_to_use;
4679 buffer_info = &tx_ring->buffer_info[i];
4680 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4681
4682 context_desc->lower_setup.ip_config = 0;
4683 context_desc->upper_setup.tcp_fields.tucss = css;
4684 context_desc->upper_setup.tcp_fields.tucso =
4685 css + skb->csum_offset;
4686 context_desc->upper_setup.tcp_fields.tucse = 0;
4687 context_desc->tcp_seg_setup.data = 0;
4688 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4689
4690 buffer_info->time_stamp = jiffies;
4691 buffer_info->next_to_watch = i;
4692
4693 i++;
4694 if (i == tx_ring->count)
4695 i = 0;
4696 tx_ring->next_to_use = i;
4697
4698 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004699}
4700
4701#define E1000_MAX_PER_TXD 8192
4702#define E1000_MAX_TXD_PWR 12
4703
4704static int e1000_tx_map(struct e1000_adapter *adapter,
4705 struct sk_buff *skb, unsigned int first,
4706 unsigned int max_per_txd, unsigned int nr_frags,
4707 unsigned int mss)
4708{
4709 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004710 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004711 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004712 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004713 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004714 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004715
4716 i = tx_ring->next_to_use;
4717
4718 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004719 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004720 size = min(len, max_per_txd);
4721
Auke Kokbc7f75f2007-09-17 12:30:59 -07004722 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004723 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004724 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004725 buffer_info->dma = dma_map_single(&pdev->dev,
4726 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004727 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004728 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004729 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004730 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004731
4732 len -= size;
4733 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004734 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004735
4736 if (len) {
4737 i++;
4738 if (i == tx_ring->count)
4739 i = 0;
4740 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004741 }
4742
4743 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004744 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004745
4746 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004747 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004748 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004749
4750 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004751 i++;
4752 if (i == tx_ring->count)
4753 i = 0;
4754
Auke Kokbc7f75f2007-09-17 12:30:59 -07004755 buffer_info = &tx_ring->buffer_info[i];
4756 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004757
4758 buffer_info->length = size;
4759 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004760 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004761 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4762 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004763 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004764 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004765 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004766
4767 len -= size;
4768 offset += size;
4769 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004770 }
4771 }
4772
Bruce Allanaf667a22010-12-31 06:10:01 +00004773 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004774 /* multiply data chunks by size of headers */
4775 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4776
Auke Kokbc7f75f2007-09-17 12:30:59 -07004777 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004778 tx_ring->buffer_info[i].segs = segs;
4779 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004780 tx_ring->buffer_info[first].next_to_watch = i;
4781
4782 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004783
4784dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004785 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004786 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004787 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004788 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004789
4790 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004791 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004792 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004793 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004794 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004795 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004796 }
4797
4798 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004799}
4800
4801static void e1000_tx_queue(struct e1000_adapter *adapter,
4802 int tx_flags, int count)
4803{
4804 struct e1000_ring *tx_ring = adapter->tx_ring;
4805 struct e1000_tx_desc *tx_desc = NULL;
4806 struct e1000_buffer *buffer_info;
4807 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4808 unsigned int i;
4809
4810 if (tx_flags & E1000_TX_FLAGS_TSO) {
4811 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4812 E1000_TXD_CMD_TSE;
4813 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4814
4815 if (tx_flags & E1000_TX_FLAGS_IPV4)
4816 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4817 }
4818
4819 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4820 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4821 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4822 }
4823
4824 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4825 txd_lower |= E1000_TXD_CMD_VLE;
4826 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4827 }
4828
4829 i = tx_ring->next_to_use;
4830
Bruce Allan36b973d2010-11-24 07:42:43 +00004831 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004832 buffer_info = &tx_ring->buffer_info[i];
4833 tx_desc = E1000_TX_DESC(*tx_ring, i);
4834 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4835 tx_desc->lower.data =
4836 cpu_to_le32(txd_lower | buffer_info->length);
4837 tx_desc->upper.data = cpu_to_le32(txd_upper);
4838
4839 i++;
4840 if (i == tx_ring->count)
4841 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004842 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004843
4844 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4845
Bruce Allanad680762008-03-28 09:15:03 -07004846 /*
4847 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004848 * know there are new descriptors to fetch. (Only
4849 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004850 * such as IA-64).
4851 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004852 wmb();
4853
4854 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004855
4856 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4857 e1000e_update_tdt_wa(adapter, i);
4858 else
4859 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4860
Bruce Allanad680762008-03-28 09:15:03 -07004861 /*
4862 * we need this if more than one processor can write to our tail
4863 * at a time, it synchronizes IO on IA64/Altix systems
4864 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004865 mmiowb();
4866}
4867
4868#define MINIMUM_DHCP_PACKET_SIZE 282
4869static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4870 struct sk_buff *skb)
4871{
4872 struct e1000_hw *hw = &adapter->hw;
4873 u16 length, offset;
4874
4875 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004876 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4877 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004878 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4879 return 0;
4880 }
4881
4882 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4883 return 0;
4884
4885 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4886 return 0;
4887
4888 {
4889 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4890 struct udphdr *udp;
4891
4892 if (ip->protocol != IPPROTO_UDP)
4893 return 0;
4894
4895 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4896 if (ntohs(udp->dest) != 67)
4897 return 0;
4898
4899 offset = (u8 *)udp + 8 - skb->data;
4900 length = skb->len - offset;
4901 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4902 }
4903
4904 return 0;
4905}
4906
4907static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4908{
4909 struct e1000_adapter *adapter = netdev_priv(netdev);
4910
4911 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004912 /*
4913 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004914 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004915 * but since that doesn't exist yet, just open code it.
4916 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004917 smp_mb();
4918
Bruce Allanad680762008-03-28 09:15:03 -07004919 /*
4920 * We need to check again in a case another CPU has just
4921 * made room available.
4922 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004923 if (e1000_desc_unused(adapter->tx_ring) < size)
4924 return -EBUSY;
4925
4926 /* A reprieve! */
4927 netif_start_queue(netdev);
4928 ++adapter->restart_queue;
4929 return 0;
4930}
4931
4932static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4933{
4934 struct e1000_adapter *adapter = netdev_priv(netdev);
4935
4936 if (e1000_desc_unused(adapter->tx_ring) >= size)
4937 return 0;
4938 return __e1000_maybe_stop_tx(netdev, size);
4939}
4940
4941#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004942static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4943 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004944{
4945 struct e1000_adapter *adapter = netdev_priv(netdev);
4946 struct e1000_ring *tx_ring = adapter->tx_ring;
4947 unsigned int first;
4948 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4949 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4950 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004951 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004952 unsigned int nr_frags;
4953 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004954 int count = 0;
4955 int tso;
4956 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004957
4958 if (test_bit(__E1000_DOWN, &adapter->state)) {
4959 dev_kfree_skb_any(skb);
4960 return NETDEV_TX_OK;
4961 }
4962
4963 if (skb->len <= 0) {
4964 dev_kfree_skb_any(skb);
4965 return NETDEV_TX_OK;
4966 }
4967
4968 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004969 /*
4970 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004971 * make sure there is enough room in the FIFO before
4972 * initiating the DMA for each buffer. The calc is:
4973 * 4 = ceil(buffer len/mss). To make sure we don't
4974 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004975 * drops.
4976 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004977 if (mss) {
4978 u8 hdr_len;
4979 max_per_txd = min(mss << 2, max_per_txd);
4980 max_txd_pwr = fls(max_per_txd) - 1;
4981
Bruce Allanad680762008-03-28 09:15:03 -07004982 /*
4983 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4984 * points to just header, pull a few bytes of payload from
4985 * frags into skb->data
4986 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004987 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004988 /*
4989 * we do this workaround for ES2LAN, but it is un-necessary,
4990 * avoiding it could save a lot of cycles
4991 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004992 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004993 unsigned int pull_size;
4994
4995 pull_size = min((unsigned int)4, skb->data_len);
4996 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004997 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998 dev_kfree_skb_any(skb);
4999 return NETDEV_TX_OK;
5000 }
Eric Dumazete743d312010-04-14 15:59:40 -07005001 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005002 }
5003 }
5004
5005 /* reserve a descriptor for the offload context */
5006 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5007 count++;
5008 count++;
5009
5010 count += TXD_USE_COUNT(len, max_txd_pwr);
5011
5012 nr_frags = skb_shinfo(skb)->nr_frags;
5013 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00005014 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07005015 max_txd_pwr);
5016
5017 if (adapter->hw.mac.tx_pkt_filtering)
5018 e1000_transfer_dhcp_info(adapter, skb);
5019
Bruce Allanad680762008-03-28 09:15:03 -07005020 /*
5021 * need: count + 2 desc gap to keep tail from touching
5022 * head, otherwise try next time
5023 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00005024 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005025 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005026
Jesse Grosseab6d182010-10-20 13:56:03 +00005027 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005028 tx_flags |= E1000_TX_FLAGS_VLAN;
5029 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5030 }
5031
5032 first = tx_ring->next_to_use;
5033
5034 tso = e1000_tso(adapter, skb);
5035 if (tso < 0) {
5036 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037 return NETDEV_TX_OK;
5038 }
5039
5040 if (tso)
5041 tx_flags |= E1000_TX_FLAGS_TSO;
5042 else if (e1000_tx_csum(adapter, skb))
5043 tx_flags |= E1000_TX_FLAGS_CSUM;
5044
Bruce Allanad680762008-03-28 09:15:03 -07005045 /*
5046 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005047 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005048 * no longer assume, we must.
5049 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005050 if (skb->protocol == htons(ETH_P_IP))
5051 tx_flags |= E1000_TX_FLAGS_IPV4;
5052
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005053 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005054 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005055 if (count) {
5056 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005057 /* Make sure there is space in the ring for the next send. */
5058 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
5059
5060 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005061 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005062 tx_ring->buffer_info[first].time_stamp = 0;
5063 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005064 }
5065
Auke Kokbc7f75f2007-09-17 12:30:59 -07005066 return NETDEV_TX_OK;
5067}
5068
5069/**
5070 * e1000_tx_timeout - Respond to a Tx Hang
5071 * @netdev: network interface device structure
5072 **/
5073static void e1000_tx_timeout(struct net_device *netdev)
5074{
5075 struct e1000_adapter *adapter = netdev_priv(netdev);
5076
5077 /* Do the reset outside of interrupt context */
5078 adapter->tx_timeout_count++;
5079 schedule_work(&adapter->reset_task);
5080}
5081
5082static void e1000_reset_task(struct work_struct *work)
5083{
5084 struct e1000_adapter *adapter;
5085 adapter = container_of(work, struct e1000_adapter, reset_task);
5086
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005087 /* don't run the task if already down */
5088 if (test_bit(__E1000_DOWN, &adapter->state))
5089 return;
5090
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005091 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5092 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5093 e1000e_dump(adapter);
5094 e_err("Reset adapter\n");
5095 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005096 e1000e_reinit_locked(adapter);
5097}
5098
5099/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005100 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005101 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005102 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005103 *
5104 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005105 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005106struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5107 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005108{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005109 struct e1000_adapter *adapter = netdev_priv(netdev);
5110
5111 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5112 spin_lock(&adapter->stats64_lock);
5113 e1000e_update_stats(adapter);
5114 /* Fill out the OS statistics structure */
5115 stats->rx_bytes = adapter->stats.gorc;
5116 stats->rx_packets = adapter->stats.gprc;
5117 stats->tx_bytes = adapter->stats.gotc;
5118 stats->tx_packets = adapter->stats.gptc;
5119 stats->multicast = adapter->stats.mprc;
5120 stats->collisions = adapter->stats.colc;
5121
5122 /* Rx Errors */
5123
5124 /*
5125 * RLEC on some newer hardware can be incorrect so build
5126 * our own version based on RUC and ROC
5127 */
5128 stats->rx_errors = adapter->stats.rxerrc +
5129 adapter->stats.crcerrs + adapter->stats.algnerrc +
5130 adapter->stats.ruc + adapter->stats.roc +
5131 adapter->stats.cexterr;
5132 stats->rx_length_errors = adapter->stats.ruc +
5133 adapter->stats.roc;
5134 stats->rx_crc_errors = adapter->stats.crcerrs;
5135 stats->rx_frame_errors = adapter->stats.algnerrc;
5136 stats->rx_missed_errors = adapter->stats.mpc;
5137
5138 /* Tx Errors */
5139 stats->tx_errors = adapter->stats.ecol +
5140 adapter->stats.latecol;
5141 stats->tx_aborted_errors = adapter->stats.ecol;
5142 stats->tx_window_errors = adapter->stats.latecol;
5143 stats->tx_carrier_errors = adapter->stats.tncrs;
5144
5145 /* Tx Dropped needs to be maintained elsewhere */
5146
5147 spin_unlock(&adapter->stats64_lock);
5148 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005149}
5150
5151/**
5152 * e1000_change_mtu - Change the Maximum Transfer Unit
5153 * @netdev: network interface device structure
5154 * @new_mtu: new value for maximum frame size
5155 *
5156 * Returns 0 on success, negative on failure
5157 **/
5158static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5159{
5160 struct e1000_adapter *adapter = netdev_priv(netdev);
5161 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5162
Bruce Allan2adc55c2009-06-02 11:28:58 +00005163 /* Jumbo frame support */
5164 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5165 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5166 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005167 return -EINVAL;
5168 }
5169
Bruce Allan2adc55c2009-06-02 11:28:58 +00005170 /* Supported frame sizes */
5171 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5172 (max_frame > adapter->max_hw_frame_size)) {
5173 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005174 return -EINVAL;
5175 }
5176
Bruce Allana1ce6472010-09-22 17:16:40 +00005177 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5178 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5179 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5180 (new_mtu > ETH_DATA_LEN)) {
5181 e_err("Jumbo Frames not supported on 82579 when CRC "
5182 "stripping is disabled.\n");
5183 return -EINVAL;
5184 }
5185
Bruce Allan6f461f62010-04-27 03:33:04 +00005186 /* 82573 Errata 17 */
5187 if (((adapter->hw.mac.type == e1000_82573) ||
5188 (adapter->hw.mac.type == e1000_82574)) &&
5189 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5190 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5191 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5192 }
5193
Auke Kokbc7f75f2007-09-17 12:30:59 -07005194 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005195 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005196 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005197 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005198 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5199 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005200 if (netif_running(netdev))
5201 e1000e_down(adapter);
5202
Bruce Allanad680762008-03-28 09:15:03 -07005203 /*
5204 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005205 * means we reserve 2 more, this pushes us to allocate from the next
5206 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005207 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005208 * However with the new *_jumbo_rx* routines, jumbo receives will use
5209 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005210 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005211
Jesse Brandeburg99261462010-01-22 22:56:16 +00005212 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213 adapter->rx_buffer_len = 2048;
5214 else
5215 adapter->rx_buffer_len = 4096;
5216
5217 /* adjust allocation if LPE protects us, and we aren't using SBP */
5218 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5219 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5220 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005221 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005222
Auke Kokbc7f75f2007-09-17 12:30:59 -07005223 if (netif_running(netdev))
5224 e1000e_up(adapter);
5225 else
5226 e1000e_reset(adapter);
5227
5228 clear_bit(__E1000_RESETTING, &adapter->state);
5229
5230 return 0;
5231}
5232
5233static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5234 int cmd)
5235{
5236 struct e1000_adapter *adapter = netdev_priv(netdev);
5237 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005238
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005239 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005240 return -EOPNOTSUPP;
5241
5242 switch (cmd) {
5243 case SIOCGMIIPHY:
5244 data->phy_id = adapter->hw.phy.addr;
5245 break;
5246 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005247 e1000_phy_read_status(adapter);
5248
Bruce Allan7c257692008-04-23 11:09:00 -07005249 switch (data->reg_num & 0x1F) {
5250 case MII_BMCR:
5251 data->val_out = adapter->phy_regs.bmcr;
5252 break;
5253 case MII_BMSR:
5254 data->val_out = adapter->phy_regs.bmsr;
5255 break;
5256 case MII_PHYSID1:
5257 data->val_out = (adapter->hw.phy.id >> 16);
5258 break;
5259 case MII_PHYSID2:
5260 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5261 break;
5262 case MII_ADVERTISE:
5263 data->val_out = adapter->phy_regs.advertise;
5264 break;
5265 case MII_LPA:
5266 data->val_out = adapter->phy_regs.lpa;
5267 break;
5268 case MII_EXPANSION:
5269 data->val_out = adapter->phy_regs.expansion;
5270 break;
5271 case MII_CTRL1000:
5272 data->val_out = adapter->phy_regs.ctrl1000;
5273 break;
5274 case MII_STAT1000:
5275 data->val_out = adapter->phy_regs.stat1000;
5276 break;
5277 case MII_ESTATUS:
5278 data->val_out = adapter->phy_regs.estatus;
5279 break;
5280 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005281 return -EIO;
5282 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005283 break;
5284 case SIOCSMIIREG:
5285 default:
5286 return -EOPNOTSUPP;
5287 }
5288 return 0;
5289}
5290
5291static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5292{
5293 switch (cmd) {
5294 case SIOCGMIIPHY:
5295 case SIOCGMIIREG:
5296 case SIOCSMIIREG:
5297 return e1000_mii_ioctl(netdev, ifr, cmd);
5298 default:
5299 return -EOPNOTSUPP;
5300 }
5301}
5302
Bruce Allana4f58f52009-06-02 11:29:18 +00005303static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5304{
5305 struct e1000_hw *hw = &adapter->hw;
5306 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005307 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005308 int retval = 0;
5309
5310 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005311 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005312
Bruce Allan2b6b1682011-05-13 07:20:09 +00005313 retval = hw->phy.ops.acquire(hw);
5314 if (retval) {
5315 e_err("Could not acquire PHY\n");
5316 return retval;
5317 }
5318
5319 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5320 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5321 if (retval)
5322 goto out;
5323
5324 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005325 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5326 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005327 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5328 (u16)(mac_reg & 0xFFFF));
5329 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5330 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005331 }
5332
5333 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005334 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005335 mac_reg = er32(RCTL);
5336 if (mac_reg & E1000_RCTL_UPE)
5337 phy_reg |= BM_RCTL_UPE;
5338 if (mac_reg & E1000_RCTL_MPE)
5339 phy_reg |= BM_RCTL_MPE;
5340 phy_reg &= ~(BM_RCTL_MO_MASK);
5341 if (mac_reg & E1000_RCTL_MO_3)
5342 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5343 << BM_RCTL_MO_SHIFT);
5344 if (mac_reg & E1000_RCTL_BAM)
5345 phy_reg |= BM_RCTL_BAM;
5346 if (mac_reg & E1000_RCTL_PMCF)
5347 phy_reg |= BM_RCTL_PMCF;
5348 mac_reg = er32(CTRL);
5349 if (mac_reg & E1000_CTRL_RFCE)
5350 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005351 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005352
5353 /* enable PHY wakeup in MAC register */
5354 ew32(WUFC, wufc);
5355 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5356
5357 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005358 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5359 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005360
5361 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005362 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5363 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005364 if (retval)
5365 e_err("Could not set PHY Host Wakeup bit\n");
5366out:
Bruce Allan94d81862009-11-20 23:25:26 +00005367 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005368
5369 return retval;
5370}
5371
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005372static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5373 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005374{
5375 struct net_device *netdev = pci_get_drvdata(pdev);
5376 struct e1000_adapter *adapter = netdev_priv(netdev);
5377 struct e1000_hw *hw = &adapter->hw;
5378 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005379 /* Runtime suspend should only enable wakeup for link changes */
5380 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005381 int retval = 0;
5382
5383 netif_device_detach(netdev);
5384
5385 if (netif_running(netdev)) {
5386 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5387 e1000e_down(adapter);
5388 e1000_free_irq(adapter);
5389 }
Bruce Allan4662e822008-08-26 18:37:06 -07005390 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005391
5392 retval = pci_save_state(pdev);
5393 if (retval)
5394 return retval;
5395
5396 status = er32(STATUS);
5397 if (status & E1000_STATUS_LU)
5398 wufc &= ~E1000_WUFC_LNKC;
5399
5400 if (wufc) {
5401 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005402 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005403
5404 /* turn on all-multi mode if wake on multicast is enabled */
5405 if (wufc & E1000_WUFC_MC) {
5406 rctl = er32(RCTL);
5407 rctl |= E1000_RCTL_MPE;
5408 ew32(RCTL, rctl);
5409 }
5410
5411 ctrl = er32(CTRL);
5412 /* advertise wake from D3Cold */
5413 #define E1000_CTRL_ADVD3WUC 0x00100000
5414 /* phy power management enable */
5415 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005416 ctrl |= E1000_CTRL_ADVD3WUC;
5417 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5418 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005419 ew32(CTRL, ctrl);
5420
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005421 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5422 adapter->hw.phy.media_type ==
5423 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005424 /* keep the laser running in D3 */
5425 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005426 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005427 ew32(CTRL_EXT, ctrl_ext);
5428 }
5429
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005430 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005431 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005432
Auke Kokbc7f75f2007-09-17 12:30:59 -07005433 /* Allow time for pending master requests to run */
5434 e1000e_disable_pcie_master(&adapter->hw);
5435
Bruce Allan82776a42009-08-14 14:35:33 +00005436 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005437 /* enable wakeup by the PHY */
5438 retval = e1000_init_phy_wakeup(adapter, wufc);
5439 if (retval)
5440 return retval;
5441 } else {
5442 /* enable wakeup by the MAC */
5443 ew32(WUFC, wufc);
5444 ew32(WUC, E1000_WUC_PME_EN);
5445 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005446 } else {
5447 ew32(WUC, 0);
5448 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005449 }
5450
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005451 *enable_wake = !!wufc;
5452
Auke Kokbc7f75f2007-09-17 12:30:59 -07005453 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005454 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5455 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005456 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005457
5458 if (adapter->hw.phy.type == e1000_phy_igp_3)
5459 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5460
Bruce Allanad680762008-03-28 09:15:03 -07005461 /*
5462 * Release control of h/w to f/w. If f/w is AMT enabled, this
5463 * would have already happened in close and is redundant.
5464 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005465 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005466
5467 pci_disable_device(pdev);
5468
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005469 return 0;
5470}
5471
5472static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5473{
5474 if (sleep && wake) {
5475 pci_prepare_to_sleep(pdev);
5476 return;
5477 }
5478
5479 pci_wake_from_d3(pdev, wake);
5480 pci_set_power_state(pdev, PCI_D3hot);
5481}
5482
5483static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5484 bool wake)
5485{
5486 struct net_device *netdev = pci_get_drvdata(pdev);
5487 struct e1000_adapter *adapter = netdev_priv(netdev);
5488
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005489 /*
5490 * The pci-e switch on some quad port adapters will report a
5491 * correctable error when the MAC transitions from D0 to D3. To
5492 * prevent this we need to mask off the correctable errors on the
5493 * downstream port of the pci-e switch.
5494 */
5495 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5496 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005497 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005498 u16 devctl;
5499
5500 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5501 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5502 (devctl & ~PCI_EXP_DEVCTL_CERE));
5503
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005504 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005505
5506 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5507 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005508 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005509 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005510}
5511
Bruce Allan6f461f62010-04-27 03:33:04 +00005512#ifdef CONFIG_PCIEASPM
5513static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5514{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005515 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005516}
5517#else
5518static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005519{
5520 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005521 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005522
5523 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005524 * Both device and parent should have the same ASPM setting.
5525 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005526 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005527 pos = pci_pcie_cap(pdev);
5528 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5529 reg16 &= ~state;
5530 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5531
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005532 if (!pdev->bus->self)
5533 return;
5534
Bruce Allan6f461f62010-04-27 03:33:04 +00005535 pos = pci_pcie_cap(pdev->bus->self);
5536 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5537 reg16 &= ~state;
5538 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5539}
5540#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005541static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005542{
5543 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5544 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5545 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5546
5547 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005548}
5549
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005550#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005551static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005552{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005553 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005554}
5555
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005556static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005557{
5558 struct net_device *netdev = pci_get_drvdata(pdev);
5559 struct e1000_adapter *adapter = netdev_priv(netdev);
5560 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005561 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005562 u32 err;
5563
Bruce Allan78cd29d2011-03-24 03:09:03 +00005564 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5565 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5566 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5567 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5568 if (aspm_disable_flag)
5569 e1000e_disable_aspm(pdev, aspm_disable_flag);
5570
Auke Kokbc7f75f2007-09-17 12:30:59 -07005571 pci_set_power_state(pdev, PCI_D0);
5572 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005573 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005574
Bruce Allan4662e822008-08-26 18:37:06 -07005575 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005576 if (netif_running(netdev)) {
5577 err = e1000_request_irq(adapter);
5578 if (err)
5579 return err;
5580 }
5581
Bruce Allan99730e42011-05-13 07:19:48 +00005582 if (hw->mac.type == e1000_pch2lan)
5583 e1000_resume_workarounds_pchlan(&adapter->hw);
5584
Auke Kokbc7f75f2007-09-17 12:30:59 -07005585 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005586
5587 /* report the system wakeup cause from S3/S4 */
5588 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5589 u16 phy_data;
5590
5591 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5592 if (phy_data) {
5593 e_info("PHY Wakeup cause - %s\n",
5594 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5595 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5596 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5597 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5598 phy_data & E1000_WUS_LNKC ? "Link Status "
5599 " Change" : "other");
5600 }
5601 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5602 } else {
5603 u32 wus = er32(WUS);
5604 if (wus) {
5605 e_info("MAC Wakeup cause - %s\n",
5606 wus & E1000_WUS_EX ? "Unicast Packet" :
5607 wus & E1000_WUS_MC ? "Multicast Packet" :
5608 wus & E1000_WUS_BC ? "Broadcast Packet" :
5609 wus & E1000_WUS_MAG ? "Magic Packet" :
5610 wus & E1000_WUS_LNKC ? "Link Status Change" :
5611 "other");
5612 }
5613 ew32(WUS, ~0);
5614 }
5615
Auke Kokbc7f75f2007-09-17 12:30:59 -07005616 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005617
Bruce Allancd791612010-05-10 14:59:51 +00005618 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005619
5620 if (netif_running(netdev))
5621 e1000e_up(adapter);
5622
5623 netif_device_attach(netdev);
5624
Bruce Allanad680762008-03-28 09:15:03 -07005625 /*
5626 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005627 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005628 * under the control of the driver.
5629 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005630 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005631 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005632
5633 return 0;
5634}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005635
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005636#ifdef CONFIG_PM_SLEEP
5637static int e1000_suspend(struct device *dev)
5638{
5639 struct pci_dev *pdev = to_pci_dev(dev);
5640 int retval;
5641 bool wake;
5642
5643 retval = __e1000_shutdown(pdev, &wake, false);
5644 if (!retval)
5645 e1000_complete_shutdown(pdev, true, wake);
5646
5647 return retval;
5648}
5649
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005650static int e1000_resume(struct device *dev)
5651{
5652 struct pci_dev *pdev = to_pci_dev(dev);
5653 struct net_device *netdev = pci_get_drvdata(pdev);
5654 struct e1000_adapter *adapter = netdev_priv(netdev);
5655
5656 if (e1000e_pm_ready(adapter))
5657 adapter->idle_check = true;
5658
5659 return __e1000_resume(pdev);
5660}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005661#endif /* CONFIG_PM_SLEEP */
5662
5663#ifdef CONFIG_PM_RUNTIME
5664static int e1000_runtime_suspend(struct device *dev)
5665{
5666 struct pci_dev *pdev = to_pci_dev(dev);
5667 struct net_device *netdev = pci_get_drvdata(pdev);
5668 struct e1000_adapter *adapter = netdev_priv(netdev);
5669
5670 if (e1000e_pm_ready(adapter)) {
5671 bool wake;
5672
5673 __e1000_shutdown(pdev, &wake, true);
5674 }
5675
5676 return 0;
5677}
5678
5679static int e1000_idle(struct device *dev)
5680{
5681 struct pci_dev *pdev = to_pci_dev(dev);
5682 struct net_device *netdev = pci_get_drvdata(pdev);
5683 struct e1000_adapter *adapter = netdev_priv(netdev);
5684
5685 if (!e1000e_pm_ready(adapter))
5686 return 0;
5687
5688 if (adapter->idle_check) {
5689 adapter->idle_check = false;
5690 if (!e1000e_has_link(adapter))
5691 pm_schedule_suspend(dev, MSEC_PER_SEC);
5692 }
5693
5694 return -EBUSY;
5695}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005696
5697static int e1000_runtime_resume(struct device *dev)
5698{
5699 struct pci_dev *pdev = to_pci_dev(dev);
5700 struct net_device *netdev = pci_get_drvdata(pdev);
5701 struct e1000_adapter *adapter = netdev_priv(netdev);
5702
5703 if (!e1000e_pm_ready(adapter))
5704 return 0;
5705
5706 adapter->idle_check = !dev->power.runtime_auto;
5707 return __e1000_resume(pdev);
5708}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005709#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005710#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005711
5712static void e1000_shutdown(struct pci_dev *pdev)
5713{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005714 bool wake = false;
5715
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005716 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005717
5718 if (system_state == SYSTEM_POWER_OFF)
5719 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005720}
5721
5722#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005723
5724static irqreturn_t e1000_intr_msix(int irq, void *data)
5725{
5726 struct net_device *netdev = data;
5727 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005728
5729 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005730 int vector, msix_irq;
5731
Dongdong Deng147b2c82010-11-16 19:50:15 -08005732 vector = 0;
5733 msix_irq = adapter->msix_entries[vector].vector;
5734 disable_irq(msix_irq);
5735 e1000_intr_msix_rx(msix_irq, netdev);
5736 enable_irq(msix_irq);
5737
5738 vector++;
5739 msix_irq = adapter->msix_entries[vector].vector;
5740 disable_irq(msix_irq);
5741 e1000_intr_msix_tx(msix_irq, netdev);
5742 enable_irq(msix_irq);
5743
5744 vector++;
5745 msix_irq = adapter->msix_entries[vector].vector;
5746 disable_irq(msix_irq);
5747 e1000_msix_other(msix_irq, netdev);
5748 enable_irq(msix_irq);
5749 }
5750
5751 return IRQ_HANDLED;
5752}
5753
Auke Kokbc7f75f2007-09-17 12:30:59 -07005754/*
5755 * Polling 'interrupt' - used by things like netconsole to send skbs
5756 * without having to re-enable interrupts. It's not called while
5757 * the interrupt routine is executing.
5758 */
5759static void e1000_netpoll(struct net_device *netdev)
5760{
5761 struct e1000_adapter *adapter = netdev_priv(netdev);
5762
Dongdong Deng147b2c82010-11-16 19:50:15 -08005763 switch (adapter->int_mode) {
5764 case E1000E_INT_MODE_MSIX:
5765 e1000_intr_msix(adapter->pdev->irq, netdev);
5766 break;
5767 case E1000E_INT_MODE_MSI:
5768 disable_irq(adapter->pdev->irq);
5769 e1000_intr_msi(adapter->pdev->irq, netdev);
5770 enable_irq(adapter->pdev->irq);
5771 break;
5772 default: /* E1000E_INT_MODE_LEGACY */
5773 disable_irq(adapter->pdev->irq);
5774 e1000_intr(adapter->pdev->irq, netdev);
5775 enable_irq(adapter->pdev->irq);
5776 break;
5777 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005778}
5779#endif
5780
5781/**
5782 * e1000_io_error_detected - called when PCI error is detected
5783 * @pdev: Pointer to PCI device
5784 * @state: The current pci connection state
5785 *
5786 * This function is called after a PCI bus error affecting
5787 * this device has been detected.
5788 */
5789static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5790 pci_channel_state_t state)
5791{
5792 struct net_device *netdev = pci_get_drvdata(pdev);
5793 struct e1000_adapter *adapter = netdev_priv(netdev);
5794
5795 netif_device_detach(netdev);
5796
Mike Masonc93b5a72009-06-30 12:45:53 +00005797 if (state == pci_channel_io_perm_failure)
5798 return PCI_ERS_RESULT_DISCONNECT;
5799
Auke Kokbc7f75f2007-09-17 12:30:59 -07005800 if (netif_running(netdev))
5801 e1000e_down(adapter);
5802 pci_disable_device(pdev);
5803
5804 /* Request a slot slot reset. */
5805 return PCI_ERS_RESULT_NEED_RESET;
5806}
5807
5808/**
5809 * e1000_io_slot_reset - called after the pci bus has been reset.
5810 * @pdev: Pointer to PCI device
5811 *
5812 * Restart the card from scratch, as if from a cold-boot. Implementation
5813 * resembles the first-half of the e1000_resume routine.
5814 */
5815static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5816{
5817 struct net_device *netdev = pci_get_drvdata(pdev);
5818 struct e1000_adapter *adapter = netdev_priv(netdev);
5819 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005820 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005821 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005822 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005823
Bruce Allan78cd29d2011-03-24 03:09:03 +00005824 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5825 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005826 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005827 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5828 if (aspm_disable_flag)
5829 e1000e_disable_aspm(pdev, aspm_disable_flag);
5830
Bruce Allanf0f422e2008-08-04 17:21:53 -07005831 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005832 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005833 dev_err(&pdev->dev,
5834 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005835 result = PCI_ERS_RESULT_DISCONNECT;
5836 } else {
5837 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005838 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005839 pci_restore_state(pdev);
5840
5841 pci_enable_wake(pdev, PCI_D3hot, 0);
5842 pci_enable_wake(pdev, PCI_D3cold, 0);
5843
5844 e1000e_reset(adapter);
5845 ew32(WUS, ~0);
5846 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005847 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005848
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005849 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005850
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005851 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005852}
5853
5854/**
5855 * e1000_io_resume - called when traffic can start flowing again.
5856 * @pdev: Pointer to PCI device
5857 *
5858 * This callback is called when the error recovery driver tells us that
5859 * its OK to resume normal operation. Implementation resembles the
5860 * second-half of the e1000_resume routine.
5861 */
5862static void e1000_io_resume(struct pci_dev *pdev)
5863{
5864 struct net_device *netdev = pci_get_drvdata(pdev);
5865 struct e1000_adapter *adapter = netdev_priv(netdev);
5866
Bruce Allancd791612010-05-10 14:59:51 +00005867 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005868
5869 if (netif_running(netdev)) {
5870 if (e1000e_up(adapter)) {
5871 dev_err(&pdev->dev,
5872 "can't bring device back up after reset\n");
5873 return;
5874 }
5875 }
5876
5877 netif_device_attach(netdev);
5878
Bruce Allanad680762008-03-28 09:15:03 -07005879 /*
5880 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005881 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005882 * under the control of the driver.
5883 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005884 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005885 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005886
5887}
5888
5889static void e1000_print_device_info(struct e1000_adapter *adapter)
5890{
5891 struct e1000_hw *hw = &adapter->hw;
5892 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005893 u32 ret_val;
5894 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005895
5896 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005897 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005898 /* bus width */
5899 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5900 "Width x1"),
5901 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005902 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005903 e_info("Intel(R) PRO/%s Network Connection\n",
5904 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005905 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5906 E1000_PBANUM_LENGTH);
5907 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005908 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005909 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5910 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005911}
5912
Auke Kok10aa4c02008-08-04 17:21:20 -07005913static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5914{
5915 struct e1000_hw *hw = &adapter->hw;
5916 int ret_val;
5917 u16 buf = 0;
5918
5919 if (hw->mac.type != e1000_82573)
5920 return;
5921
5922 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005923 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005924 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005925 dev_warn(&adapter->pdev->dev,
5926 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005927 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005928}
5929
Bruce Allandc221292011-08-19 03:23:48 +00005930static int e1000_set_features(struct net_device *netdev, u32 features)
5931{
5932 struct e1000_adapter *adapter = netdev_priv(netdev);
5933 u32 changed = features ^ netdev->features;
5934
5935 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5936 adapter->flags |= FLAG_TSO_FORCE;
5937
5938 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
5939 NETIF_F_RXCSUM)))
5940 return 0;
5941
5942 if (netif_running(netdev))
5943 e1000e_reinit_locked(adapter);
5944 else
5945 e1000e_reset(adapter);
5946
5947 return 0;
5948}
5949
Stephen Hemminger651c2462008-11-19 21:57:48 -08005950static const struct net_device_ops e1000e_netdev_ops = {
5951 .ndo_open = e1000_open,
5952 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005953 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005954 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005955 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005956 .ndo_set_mac_address = e1000_set_mac,
5957 .ndo_change_mtu = e1000_change_mtu,
5958 .ndo_do_ioctl = e1000_ioctl,
5959 .ndo_tx_timeout = e1000_tx_timeout,
5960 .ndo_validate_addr = eth_validate_addr,
5961
Stephen Hemminger651c2462008-11-19 21:57:48 -08005962 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5963 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5964#ifdef CONFIG_NET_POLL_CONTROLLER
5965 .ndo_poll_controller = e1000_netpoll,
5966#endif
Bruce Allandc221292011-08-19 03:23:48 +00005967 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005968};
5969
Auke Kokbc7f75f2007-09-17 12:30:59 -07005970/**
5971 * e1000_probe - Device Initialization Routine
5972 * @pdev: PCI device information struct
5973 * @ent: entry in e1000_pci_tbl
5974 *
5975 * Returns 0 on success, negative on failure
5976 *
5977 * e1000_probe initializes an adapter identified by a pci_dev structure.
5978 * The OS initialization, configuring of the adapter private structure,
5979 * and a hardware reset occur.
5980 **/
5981static int __devinit e1000_probe(struct pci_dev *pdev,
5982 const struct pci_device_id *ent)
5983{
5984 struct net_device *netdev;
5985 struct e1000_adapter *adapter;
5986 struct e1000_hw *hw;
5987 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005988 resource_size_t mmio_start, mmio_len;
5989 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005990
5991 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005992 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005993 int i, err, pci_using_dac;
5994 u16 eeprom_data = 0;
5995 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5996
Bruce Allan78cd29d2011-03-24 03:09:03 +00005997 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
5998 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005999 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006000 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6001 if (aspm_disable_flag)
6002 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006003
Bruce Allanf0f422e2008-08-04 17:21:53 -07006004 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006005 if (err)
6006 return err;
6007
6008 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006009 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006010 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006011 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006012 if (!err)
6013 pci_using_dac = 1;
6014 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006015 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006016 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006017 err = dma_set_coherent_mask(&pdev->dev,
6018 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006019 if (err) {
6020 dev_err(&pdev->dev, "No usable DMA "
6021 "configuration, aborting\n");
6022 goto err_dma;
6023 }
6024 }
6025 }
6026
Arjan van de Vene8de1482008-10-22 19:55:31 -07006027 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006028 pci_select_bars(pdev, IORESOURCE_MEM),
6029 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006030 if (err)
6031 goto err_pci_reg;
6032
Xiaotian Feng68eac462009-08-14 14:35:52 +00006033 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006034 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006035
Auke Kokbc7f75f2007-09-17 12:30:59 -07006036 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006037 /* PCI config space info */
6038 err = pci_save_state(pdev);
6039 if (err)
6040 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006041
6042 err = -ENOMEM;
6043 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6044 if (!netdev)
6045 goto err_alloc_etherdev;
6046
Auke Kokbc7f75f2007-09-17 12:30:59 -07006047 SET_NETDEV_DEV(netdev, &pdev->dev);
6048
Tom Herbertf85e4df2010-05-05 14:03:32 +00006049 netdev->irq = pdev->irq;
6050
Auke Kokbc7f75f2007-09-17 12:30:59 -07006051 pci_set_drvdata(pdev, netdev);
6052 adapter = netdev_priv(netdev);
6053 hw = &adapter->hw;
6054 adapter->netdev = netdev;
6055 adapter->pdev = pdev;
6056 adapter->ei = ei;
6057 adapter->pba = ei->pba;
6058 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006059 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006060 adapter->hw.adapter = adapter;
6061 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006062 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006063 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
6064
6065 mmio_start = pci_resource_start(pdev, 0);
6066 mmio_len = pci_resource_len(pdev, 0);
6067
6068 err = -EIO;
6069 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6070 if (!adapter->hw.hw_addr)
6071 goto err_ioremap;
6072
6073 if ((adapter->flags & FLAG_HAS_FLASH) &&
6074 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6075 flash_start = pci_resource_start(pdev, 1);
6076 flash_len = pci_resource_len(pdev, 1);
6077 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6078 if (!adapter->hw.flash_address)
6079 goto err_flashmap;
6080 }
6081
6082 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006083 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006084 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006085 netdev->watchdog_timeo = 5 * HZ;
6086 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006087 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
6088
6089 netdev->mem_start = mmio_start;
6090 netdev->mem_end = mmio_start + mmio_len;
6091
6092 adapter->bd_number = cards_found++;
6093
Bruce Allan4662e822008-08-26 18:37:06 -07006094 e1000e_check_options(adapter);
6095
Auke Kokbc7f75f2007-09-17 12:30:59 -07006096 /* setup adapter struct */
6097 err = e1000_sw_init(adapter);
6098 if (err)
6099 goto err_sw_init;
6100
Auke Kokbc7f75f2007-09-17 12:30:59 -07006101 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6102 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6103 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6104
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006105 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006106 if (err)
6107 goto err_hw_init;
6108
Bruce Allan4a770352008-10-01 17:18:35 -07006109 if ((adapter->flags & FLAG_IS_ICH) &&
6110 (adapter->flags & FLAG_READ_ONLY_NVM))
6111 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6112
Auke Kokbc7f75f2007-09-17 12:30:59 -07006113 hw->mac.ops.get_bus_info(&adapter->hw);
6114
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006115 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006116
6117 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006118 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006119 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6120 adapter->hw.phy.disable_polarity_correction = 0;
6121 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6122 }
6123
6124 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006125 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006126
Bruce Allandc221292011-08-19 03:23:48 +00006127 /* Set initial default active device features */
6128 netdev->features = (NETIF_F_SG |
6129 NETIF_F_HW_VLAN_RX |
6130 NETIF_F_HW_VLAN_TX |
6131 NETIF_F_TSO |
6132 NETIF_F_TSO6 |
6133 NETIF_F_RXCSUM |
6134 NETIF_F_HW_CSUM);
6135
6136 /* Set user-changeable features (subset of all device features) */
6137 netdev->hw_features = netdev->features;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006138
6139 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6140 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6141
Bruce Allandc221292011-08-19 03:23:48 +00006142 netdev->vlan_features |= (NETIF_F_SG |
6143 NETIF_F_TSO |
6144 NETIF_F_TSO6 |
6145 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006146
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006147 netdev->priv_flags |= IFF_UNICAST_FLT;
6148
Yi Zou7b872a52010-09-22 17:57:58 +00006149 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006150 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006151 netdev->vlan_features |= NETIF_F_HIGHDMA;
6152 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006153
Auke Kokbc7f75f2007-09-17 12:30:59 -07006154 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6155 adapter->flags |= FLAG_MNG_PT_ENABLED;
6156
Bruce Allanad680762008-03-28 09:15:03 -07006157 /*
6158 * before reading the NVM, reset the controller to
6159 * put the device in a known good starting state
6160 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006161 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6162
6163 /*
6164 * systems with ASPM and others may see the checksum fail on the first
6165 * attempt. Let's give it a few tries
6166 */
6167 for (i = 0;; i++) {
6168 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6169 break;
6170 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006171 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006172 err = -EIO;
6173 goto err_eeprom;
6174 }
6175 }
6176
Auke Kok10aa4c02008-08-04 17:21:20 -07006177 e1000_eeprom_checks(adapter);
6178
Bruce Allan608f8a02010-01-13 02:04:58 +00006179 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006180 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006181 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006182
6183 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6184 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6185
6186 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006187 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006188 err = -EIO;
6189 goto err_eeprom;
6190 }
6191
6192 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006193 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006194 adapter->watchdog_timer.data = (unsigned long) adapter;
6195
6196 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006197 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006198 adapter->phy_info_timer.data = (unsigned long) adapter;
6199
6200 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6201 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006202 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6203 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006204 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006205
Auke Kokbc7f75f2007-09-17 12:30:59 -07006206 /* Initialize link parameters. User can change them with ethtool */
6207 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07006208 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006209 adapter->hw.fc.requested_mode = e1000_fc_default;
6210 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006211 adapter->hw.phy.autoneg_advertised = 0x2f;
6212
6213 /* ring size defaults */
6214 adapter->rx_ring->count = 256;
6215 adapter->tx_ring->count = 256;
6216
6217 /*
6218 * Initial Wake on LAN setting - If APM wake is enabled in
6219 * the EEPROM, enable the ACPI Magic Packet filter
6220 */
6221 if (adapter->flags & FLAG_APME_IN_WUC) {
6222 /* APME bit in EEPROM is mapped to WUC.APME */
6223 eeprom_data = er32(WUC);
6224 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006225 if ((hw->mac.type > e1000_ich10lan) &&
6226 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006227 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006228 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6229 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6230 (adapter->hw.bus.func == 1))
6231 e1000_read_nvm(&adapter->hw,
6232 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6233 else
6234 e1000_read_nvm(&adapter->hw,
6235 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6236 }
6237
6238 /* fetch WoL from EEPROM */
6239 if (eeprom_data & eeprom_apme_mask)
6240 adapter->eeprom_wol |= E1000_WUFC_MAG;
6241
6242 /*
6243 * now that we have the eeprom settings, apply the special cases
6244 * where the eeprom may be wrong or the board simply won't support
6245 * wake on lan on a particular port
6246 */
6247 if (!(adapter->flags & FLAG_HAS_WOL))
6248 adapter->eeprom_wol = 0;
6249
6250 /* initialize the wol settings based on the eeprom settings */
6251 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006252 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006253
Bruce Allan84527592008-11-21 17:00:22 -08006254 /* save off EEPROM version number */
6255 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6256
Auke Kokbc7f75f2007-09-17 12:30:59 -07006257 /* reset the hardware with the new settings */
6258 e1000e_reset(adapter);
6259
Bruce Allanad680762008-03-28 09:15:03 -07006260 /*
6261 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006262 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006263 * under the control of the driver.
6264 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006265 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006266 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006267
Bruce Allane0dc4f12011-01-06 14:29:50 +00006268 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006269 err = register_netdev(netdev);
6270 if (err)
6271 goto err_register;
6272
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006273 /* carrier off reporting is important to ethtool even BEFORE open */
6274 netif_carrier_off(netdev);
6275
Auke Kokbc7f75f2007-09-17 12:30:59 -07006276 e1000_print_device_info(adapter);
6277
Alan Sternf3ec4f82010-06-08 15:23:51 -04006278 if (pci_dev_run_wake(pdev))
6279 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006280
Auke Kokbc7f75f2007-09-17 12:30:59 -07006281 return 0;
6282
6283err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006284 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006285 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006286err_eeprom:
6287 if (!e1000_check_reset_block(&adapter->hw))
6288 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006289err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006290 kfree(adapter->tx_ring);
6291 kfree(adapter->rx_ring);
6292err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006293 if (adapter->hw.flash_address)
6294 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006295 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006296err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006297 iounmap(adapter->hw.hw_addr);
6298err_ioremap:
6299 free_netdev(netdev);
6300err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006301 pci_release_selected_regions(pdev,
6302 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006303err_pci_reg:
6304err_dma:
6305 pci_disable_device(pdev);
6306 return err;
6307}
6308
6309/**
6310 * e1000_remove - Device Removal Routine
6311 * @pdev: PCI device information struct
6312 *
6313 * e1000_remove is called by the PCI subsystem to alert the driver
6314 * that it should release a PCI device. The could be caused by a
6315 * Hot-Plug event, or because the driver is going to be removed from
6316 * memory.
6317 **/
6318static void __devexit e1000_remove(struct pci_dev *pdev)
6319{
6320 struct net_device *netdev = pci_get_drvdata(pdev);
6321 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006322 bool down = test_bit(__E1000_DOWN, &adapter->state);
6323
Bruce Allanad680762008-03-28 09:15:03 -07006324 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006325 * The timers may be rescheduled, so explicitly disable them
6326 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006327 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006328 if (!down)
6329 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006330 del_timer_sync(&adapter->watchdog_timer);
6331 del_timer_sync(&adapter->phy_info_timer);
6332
Bruce Allan41cec6f2009-11-20 23:28:56 +00006333 cancel_work_sync(&adapter->reset_task);
6334 cancel_work_sync(&adapter->watchdog_task);
6335 cancel_work_sync(&adapter->downshift_task);
6336 cancel_work_sync(&adapter->update_phy_task);
6337 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006338
Bruce Allan17f208d2009-12-01 15:47:22 +00006339 if (!(netdev->flags & IFF_UP))
6340 e1000_power_down_phy(adapter);
6341
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006342 /* Don't lie to e1000_close() down the road. */
6343 if (!down)
6344 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006345 unregister_netdev(netdev);
6346
Alan Sternf3ec4f82010-06-08 15:23:51 -04006347 if (pci_dev_run_wake(pdev))
6348 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006349
Bruce Allanad680762008-03-28 09:15:03 -07006350 /*
6351 * Release control of h/w to f/w. If f/w is AMT enabled, this
6352 * would have already happened in close and is redundant.
6353 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006354 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006355
Bruce Allan4662e822008-08-26 18:37:06 -07006356 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006357 kfree(adapter->tx_ring);
6358 kfree(adapter->rx_ring);
6359
6360 iounmap(adapter->hw.hw_addr);
6361 if (adapter->hw.flash_address)
6362 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006363 pci_release_selected_regions(pdev,
6364 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006365
6366 free_netdev(netdev);
6367
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006368 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006369 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006370
Auke Kokbc7f75f2007-09-17 12:30:59 -07006371 pci_disable_device(pdev);
6372}
6373
6374/* PCI Error Recovery (ERS) */
6375static struct pci_error_handlers e1000_err_handler = {
6376 .error_detected = e1000_io_error_detected,
6377 .slot_reset = e1000_io_slot_reset,
6378 .resume = e1000_io_resume,
6379};
6380
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006381static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006382 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6383 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6384 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6385 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6386 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6387 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006388 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6389 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6390 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006391
Auke Kokbc7f75f2007-09-17 12:30:59 -07006392 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6393 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6394 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6395 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006396
Auke Kokbc7f75f2007-09-17 12:30:59 -07006397 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6398 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6399 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006400
Bruce Allan4662e822008-08-26 18:37:06 -07006401 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006402 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006403 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006404
Auke Kokbc7f75f2007-09-17 12:30:59 -07006405 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6406 board_80003es2lan },
6407 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6408 board_80003es2lan },
6409 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6410 board_80003es2lan },
6411 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6412 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006413
Auke Kokbc7f75f2007-09-17 12:30:59 -07006414 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6415 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6416 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6417 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6418 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6419 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6420 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006421 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006422
Auke Kokbc7f75f2007-09-17 12:30:59 -07006423 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6424 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6425 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6426 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6427 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006428 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006429 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6430 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6431 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6432
6433 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6434 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6435 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006436
Bruce Allanf4187b52008-08-26 18:36:50 -07006437 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6438 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006439 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006440
Bruce Allana4f58f52009-06-02 11:29:18 +00006441 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6442 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6443 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6444 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6445
Bruce Alland3738bb2010-06-16 13:27:28 +00006446 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6447 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6448
Auke Kokbc7f75f2007-09-17 12:30:59 -07006449 { } /* terminate list */
6450};
6451MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6452
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006453#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006454static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006455 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6456 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6457 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006458};
David S. Millere50208a2010-03-16 23:36:24 -07006459#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006460
Auke Kokbc7f75f2007-09-17 12:30:59 -07006461/* PCI Device API Driver */
6462static struct pci_driver e1000_driver = {
6463 .name = e1000e_driver_name,
6464 .id_table = e1000_pci_tbl,
6465 .probe = e1000_probe,
6466 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006467#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006468 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006469#endif
6470 .shutdown = e1000_shutdown,
6471 .err_handler = &e1000_err_handler
6472};
6473
6474/**
6475 * e1000_init_module - Driver Registration Routine
6476 *
6477 * e1000_init_module is the first routine called when the driver is
6478 * loaded. All it does is register with the PCI subsystem.
6479 **/
6480static int __init e1000_init_module(void)
6481{
6482 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006483 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6484 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006485 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006486 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006487
Auke Kokbc7f75f2007-09-17 12:30:59 -07006488 return ret;
6489}
6490module_init(e1000_init_module);
6491
6492/**
6493 * e1000_exit_module - Driver Exit Cleanup Routine
6494 *
6495 * e1000_exit_module is called just before the driver is removed
6496 * from memory.
6497 **/
6498static void __exit e1000_exit_module(void)
6499{
6500 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006501}
6502module_exit(e1000_exit_module);
6503
6504
6505MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6506MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6507MODULE_LICENSE("GPL");
6508MODULE_VERSION(DRV_VERSION);
6509
6510/* e1000_main.c */