blob: 680312710a786dd9830e1c35067a66abb4db2d48 [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>
Bruce Allan97ac8ca2008-04-29 09:16:05 -070050#include <linux/pm_qos_params.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 Allandbcb9fe2010-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/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003116 * e1000_update_mc_addr_list - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -07003117 * @hw: pointer to the HW structure
3118 * @mc_addr_list: array of multicast addresses to program
3119 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -07003120 *
Bruce Allanab8932f2010-01-13 02:05:38 +00003121 * Updates the Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003122 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003123 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003124static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
Bruce Allanab8932f2010-01-13 02:05:38 +00003125 u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003126{
Bruce Allanab8932f2010-01-13 02:05:38 +00003127 hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128}
3129
3130/**
3131 * e1000_set_multi - Multicast and Promiscuous mode set
3132 * @netdev: network interface device structure
3133 *
3134 * The set_multi entry point is called whenever the multicast address
3135 * list or the network interface flags are updated. This routine is
3136 * responsible for configuring the hardware for proper multicast,
3137 * promiscuous mode, and all-multi behavior.
3138 **/
3139static void e1000_set_multi(struct net_device *netdev)
3140{
3141 struct e1000_adapter *adapter = netdev_priv(netdev);
3142 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003143 struct netdev_hw_addr *ha;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003144 u8 *mta_list;
3145 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146
3147 /* Check for Promiscuous and All Multicast modes */
3148
3149 rctl = er32(RCTL);
3150
3151 if (netdev->flags & IFF_PROMISC) {
3152 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003153 rctl &= ~E1000_RCTL_VFE;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003154 /* Do not hardware filter VLANs in promisc mode */
3155 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003156 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003157 if (netdev->flags & IFF_ALLMULTI) {
3158 rctl |= E1000_RCTL_MPE;
3159 rctl &= ~E1000_RCTL_UPE;
3160 } else {
3161 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3162 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003163 e1000e_vlan_filter_enable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003164 }
3165
3166 ew32(RCTL, rctl);
3167
Jiri Pirko7aeef972010-02-05 02:52:39 +00003168 if (!netdev_mc_empty(netdev)) {
Bruce Allan90da0662011-01-06 07:02:53 +00003169 int i = 0;
3170
Jiri Pirko7aeef972010-02-05 02:52:39 +00003171 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003172 if (!mta_list)
3173 return;
3174
3175 /* prepare a packed array of only addresses. */
Jiri Pirko22bedad32010-04-01 21:22:57 +00003176 netdev_for_each_mc_addr(ha, netdev)
3177 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003178
Bruce Allanab8932f2010-01-13 02:05:38 +00003179 e1000_update_mc_addr_list(hw, mta_list, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003180 kfree(mta_list);
3181 } else {
3182 /*
3183 * if we're called from probe, we might not have
3184 * anything to do here, so clear out the list
3185 */
Bruce Allanab8932f2010-01-13 02:05:38 +00003186 e1000_update_mc_addr_list(hw, NULL, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003187 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003188
3189 if (netdev->features & NETIF_F_HW_VLAN_RX)
3190 e1000e_vlan_strip_enable(adapter);
3191 else
3192 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003193}
3194
3195/**
Bruce Allanad680762008-03-28 09:15:03 -07003196 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003197 * @adapter: private board structure
3198 **/
3199static void e1000_configure(struct e1000_adapter *adapter)
3200{
3201 e1000_set_multi(adapter->netdev);
3202
3203 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003204 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003205
3206 e1000_configure_tx(adapter);
3207 e1000_setup_rctl(adapter);
3208 e1000_configure_rx(adapter);
Jeff Kirsherc2fed992011-07-12 16:10:12 +00003209 adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring),
3210 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003211}
3212
3213/**
3214 * e1000e_power_up_phy - restore link in case the phy was powered down
3215 * @adapter: address of board private structure
3216 *
3217 * The phy may be powered down to save power and turn off link when the
3218 * driver is unloaded and wake on lan is not enabled (among others)
3219 * *** this routine MUST be followed by a call to e1000e_reset ***
3220 **/
3221void e1000e_power_up_phy(struct e1000_adapter *adapter)
3222{
Bruce Allan17f208d2009-12-01 15:47:22 +00003223 if (adapter->hw.phy.ops.power_up)
3224 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003225
3226 adapter->hw.mac.ops.setup_link(&adapter->hw);
3227}
3228
3229/**
3230 * e1000_power_down_phy - Power down the PHY
3231 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003232 * Power down the PHY so no link is implied when interface is down.
3233 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003234 */
3235static void e1000_power_down_phy(struct e1000_adapter *adapter)
3236{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003237 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003238 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003239 return;
3240
Bruce Allan17f208d2009-12-01 15:47:22 +00003241 if (adapter->hw.phy.ops.power_down)
3242 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003243}
3244
3245/**
3246 * e1000e_reset - bring the hardware into a known good state
3247 *
3248 * This function boots the hardware and enables some settings that
3249 * require a configuration cycle of the hardware - those cannot be
3250 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003251 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003252 */
3253void e1000e_reset(struct e1000_adapter *adapter)
3254{
3255 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003256 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003257 struct e1000_hw *hw = &adapter->hw;
3258 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003259 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003260 u16 hwm;
3261
Bruce Allanad680762008-03-28 09:15:03 -07003262 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003263 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003264
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003265 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allanad680762008-03-28 09:15:03 -07003266 /*
3267 * To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003268 * large enough to accommodate two full transmit packets,
3269 * rounded up to the next 1KB and expressed in KB. Likewise,
3270 * the Rx FIFO should be large enough to accommodate at least
3271 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003272 * expressed in KB.
3273 */
Auke Kokdf762462007-10-25 13:57:53 -07003274 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003275 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003276 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003277 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003278 pba &= 0xffff;
Bruce Allanad680762008-03-28 09:15:03 -07003279 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003280 * the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003281 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003282 */
3283 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003284 sizeof(struct e1000_tx_desc) -
3285 ETH_FCS_LEN) * 2;
3286 min_tx_space = ALIGN(min_tx_space, 1024);
3287 min_tx_space >>= 10;
3288 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003289 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003290 min_rx_space = ALIGN(min_rx_space, 1024);
3291 min_rx_space >>= 10;
3292
Bruce Allanad680762008-03-28 09:15:03 -07003293 /*
3294 * If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003295 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003296 * allocation, take space away from current Rx allocation
3297 */
Auke Kokdf762462007-10-25 13:57:53 -07003298 if ((tx_space < min_tx_space) &&
3299 ((min_tx_space - tx_space) < pba)) {
3300 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003301
Bruce Allanad680762008-03-28 09:15:03 -07003302 /*
Bruce Allanaf667a22010-12-31 06:10:01 +00003303 * if short on Rx space, Rx wins and must trump Tx
Bruce Allanad680762008-03-28 09:15:03 -07003304 * adjustment or use Early Receive if available
3305 */
Auke Kokdf762462007-10-25 13:57:53 -07003306 if ((pba < min_rx_space) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07003307 (!(adapter->flags & FLAG_HAS_ERT)))
3308 /* ERT enabled in e1000_configure_rx */
Auke Kokdf762462007-10-25 13:57:53 -07003309 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003310 }
Auke Kokdf762462007-10-25 13:57:53 -07003311
3312 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003313 }
3314
Bruce Allanad680762008-03-28 09:15:03 -07003315 /*
3316 * flow control settings
3317 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003318 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003319 * (or the size used for early receive) above it in the Rx FIFO.
3320 * Set it to the lower of:
3321 * - 90% of the Rx FIFO size, and
3322 * - the full Rx FIFO size minus the early receive size (for parts
3323 * with ERT support assuming ERT set to E1000_ERT_2048), or
Bruce Allan38eb3942009-11-19 12:34:20 +00003324 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003325 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003326 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3327 fc->pause_time = 0xFFFF;
3328 else
3329 fc->pause_time = E1000_FC_PAUSE_TIME;
3330 fc->send_xon = 1;
3331 fc->current_mode = fc->requested_mode;
3332
3333 switch (hw->mac.type) {
3334 default:
3335 if ((adapter->flags & FLAG_HAS_ERT) &&
3336 (adapter->netdev->mtu > ETH_DATA_LEN))
3337 hwm = min(((pba << 10) * 9 / 10),
3338 ((pba << 10) - (E1000_ERT_2048 << 3)));
3339 else
3340 hwm = min(((pba << 10) * 9 / 10),
3341 ((pba << 10) - adapter->max_frame_size));
3342
3343 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3344 fc->low_water = fc->high_water - 8;
3345 break;
3346 case e1000_pchlan:
Bruce Allan38eb3942009-11-19 12:34:20 +00003347 /*
3348 * Workaround PCH LOM adapter hangs with certain network
3349 * loads. If hangs persist, try disabling Tx flow control.
3350 */
3351 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3352 fc->high_water = 0x3500;
3353 fc->low_water = 0x1500;
3354 } else {
3355 fc->high_water = 0x5000;
3356 fc->low_water = 0x3000;
3357 }
Bruce Allana3055952010-05-10 15:02:12 +00003358 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003359 break;
3360 case e1000_pch2lan:
3361 fc->high_water = 0x05C20;
3362 fc->low_water = 0x05048;
3363 fc->pause_time = 0x0650;
3364 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003365 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3366 pba = 14;
3367 ew32(PBA, pba);
3368 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003369 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003370 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003371
Bruce Allan828bac82010-09-29 21:39:37 +00003372 /*
3373 * Disable Adaptive Interrupt Moderation if 2 full packets cannot
3374 * fit in receive buffer and early-receive not supported.
3375 */
3376 if (adapter->itr_setting & 0x3) {
3377 if (((adapter->max_frame_size * 2) > (pba << 10)) &&
3378 !(adapter->flags & FLAG_HAS_ERT)) {
3379 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3380 dev_info(&adapter->pdev->dev,
3381 "Interrupt Throttle Rate turned off\n");
3382 adapter->flags2 |= FLAG2_DISABLE_AIM;
3383 ew32(ITR, 0);
3384 }
3385 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3386 dev_info(&adapter->pdev->dev,
3387 "Interrupt Throttle Rate turned on\n");
3388 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3389 adapter->itr = 20000;
3390 ew32(ITR, 1000000000 / (adapter->itr * 256));
3391 }
3392 }
3393
Auke Kokbc7f75f2007-09-17 12:30:59 -07003394 /* Allow time for pending master requests to run */
3395 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003396
3397 /*
3398 * For parts with AMT enabled, let the firmware know
3399 * that the network interface is in control
3400 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003401 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003402 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003403
Auke Kokbc7f75f2007-09-17 12:30:59 -07003404 ew32(WUC, 0);
3405
3406 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003407 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003408
3409 e1000_update_mng_vlan(adapter);
3410
3411 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3412 ew32(VET, ETH_P_8021Q);
3413
3414 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003415
3416 if (!netif_running(adapter->netdev) &&
3417 !test_bit(__E1000_TESTING, &adapter->state)) {
3418 e1000_power_down_phy(adapter);
3419 return;
3420 }
3421
Auke Kokbc7f75f2007-09-17 12:30:59 -07003422 e1000_get_phy_info(hw);
3423
Bruce Allan918d7192009-06-02 11:28:20 +00003424 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3425 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426 u16 phy_data = 0;
Bruce Allanad680762008-03-28 09:15:03 -07003427 /*
3428 * speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003429 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003430 * different we would do if it failed
3431 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003432 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3433 phy_data &= ~IGP02E1000_PM_SPD;
3434 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3435 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003436}
3437
3438int e1000e_up(struct e1000_adapter *adapter)
3439{
3440 struct e1000_hw *hw = &adapter->hw;
3441
3442 /* hardware has been reset, we need to reload some things */
3443 e1000_configure(adapter);
3444
3445 clear_bit(__E1000_DOWN, &adapter->state);
3446
3447 napi_enable(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07003448 if (adapter->msix_entries)
3449 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003450 e1000_irq_enable(adapter);
3451
Bruce Allan400484f2011-05-13 07:20:03 +00003452 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003453
Auke Kokbc7f75f2007-09-17 12:30:59 -07003454 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003455 if (adapter->msix_entries)
3456 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3457 else
3458 ew32(ICS, E1000_ICS_LSC);
3459
Auke Kokbc7f75f2007-09-17 12:30:59 -07003460 return 0;
3461}
3462
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003463static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3464{
3465 struct e1000_hw *hw = &adapter->hw;
3466
3467 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3468 return;
3469
3470 /* flush pending descriptor writebacks to memory */
3471 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3472 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3473
3474 /* execute the writes immediately */
3475 e1e_flush();
3476}
3477
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003478static void e1000e_update_stats(struct e1000_adapter *adapter);
3479
Auke Kokbc7f75f2007-09-17 12:30:59 -07003480void e1000e_down(struct e1000_adapter *adapter)
3481{
3482 struct net_device *netdev = adapter->netdev;
3483 struct e1000_hw *hw = &adapter->hw;
3484 u32 tctl, rctl;
3485
Bruce Allanad680762008-03-28 09:15:03 -07003486 /*
3487 * signal that we're down so the interrupt handler does not
3488 * reschedule our watchdog timer
3489 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003490 set_bit(__E1000_DOWN, &adapter->state);
3491
3492 /* disable receives in the hardware */
3493 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003494 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3495 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003496 /* flush and sleep below */
3497
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003498 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003499
3500 /* disable transmits in the hardware */
3501 tctl = er32(TCTL);
3502 tctl &= ~E1000_TCTL_EN;
3503 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003504
Auke Kokbc7f75f2007-09-17 12:30:59 -07003505 /* flush both disables and wait for them to finish */
3506 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003507 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003508
3509 napi_disable(&adapter->napi);
3510 e1000_irq_disable(adapter);
3511
3512 del_timer_sync(&adapter->watchdog_timer);
3513 del_timer_sync(&adapter->phy_info_timer);
3514
Auke Kokbc7f75f2007-09-17 12:30:59 -07003515 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003516
3517 spin_lock(&adapter->stats64_lock);
3518 e1000e_update_stats(adapter);
3519 spin_unlock(&adapter->stats64_lock);
3520
Bruce Allan400484f2011-05-13 07:20:03 +00003521 e1000e_flush_descriptors(adapter);
3522 e1000_clean_tx_ring(adapter);
3523 e1000_clean_rx_ring(adapter);
3524
Auke Kokbc7f75f2007-09-17 12:30:59 -07003525 adapter->link_speed = 0;
3526 adapter->link_duplex = 0;
3527
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003528 if (!pci_channel_offline(adapter->pdev))
3529 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003530
Auke Kokbc7f75f2007-09-17 12:30:59 -07003531 /*
3532 * TODO: for power management, we could drop the link and
3533 * pci_disable_device here.
3534 */
3535}
3536
3537void e1000e_reinit_locked(struct e1000_adapter *adapter)
3538{
3539 might_sleep();
3540 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003541 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003542 e1000e_down(adapter);
3543 e1000e_up(adapter);
3544 clear_bit(__E1000_RESETTING, &adapter->state);
3545}
3546
3547/**
3548 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3549 * @adapter: board private structure to initialize
3550 *
3551 * e1000_sw_init initializes the Adapter private data structure.
3552 * Fields are initialized based on PCI device information and
3553 * OS network device settings (MTU size).
3554 **/
3555static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
3556{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003557 struct net_device *netdev = adapter->netdev;
3558
3559 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3560 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003561 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3562 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003563
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003564 spin_lock_init(&adapter->stats64_lock);
3565
Bruce Allan4662e822008-08-26 18:37:06 -07003566 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003567
Bruce Allan4662e822008-08-26 18:37:06 -07003568 if (e1000_alloc_queues(adapter))
3569 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003570
Auke Kokbc7f75f2007-09-17 12:30:59 -07003571 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003572 e1000_irq_disable(adapter);
3573
Auke Kokbc7f75f2007-09-17 12:30:59 -07003574 set_bit(__E1000_DOWN, &adapter->state);
3575 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003576}
3577
3578/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003579 * e1000_intr_msi_test - Interrupt Handler
3580 * @irq: interrupt number
3581 * @data: pointer to a network interface device structure
3582 **/
3583static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3584{
3585 struct net_device *netdev = data;
3586 struct e1000_adapter *adapter = netdev_priv(netdev);
3587 struct e1000_hw *hw = &adapter->hw;
3588 u32 icr = er32(ICR);
3589
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003590 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003591 if (icr & E1000_ICR_RXSEQ) {
3592 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
3593 wmb();
3594 }
3595
3596 return IRQ_HANDLED;
3597}
3598
3599/**
3600 * e1000_test_msi_interrupt - Returns 0 for successful test
3601 * @adapter: board private struct
3602 *
3603 * code flow taken from tg3.c
3604 **/
3605static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3606{
3607 struct net_device *netdev = adapter->netdev;
3608 struct e1000_hw *hw = &adapter->hw;
3609 int err;
3610
3611 /* poll_enable hasn't been called yet, so don't need disable */
3612 /* clear any pending events */
3613 er32(ICR);
3614
3615 /* free the real vector and request a test handler */
3616 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003617 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003618
3619 /* Assume that the test fails, if it succeeds then the test
3620 * MSI irq handler will unset this flag */
3621 adapter->flags |= FLAG_MSI_TEST_FAILED;
3622
3623 err = pci_enable_msi(adapter->pdev);
3624 if (err)
3625 goto msi_test_failed;
3626
Joe Perchesa0607fd2009-11-18 23:29:17 -08003627 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003628 netdev->name, netdev);
3629 if (err) {
3630 pci_disable_msi(adapter->pdev);
3631 goto msi_test_failed;
3632 }
3633
3634 wmb();
3635
3636 e1000_irq_enable(adapter);
3637
3638 /* fire an unusual interrupt on the test handler */
3639 ew32(ICS, E1000_ICS_RXSEQ);
3640 e1e_flush();
3641 msleep(50);
3642
3643 e1000_irq_disable(adapter);
3644
3645 rmb();
3646
3647 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003648 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003649 e_info("MSI interrupt test failed, using legacy interrupt.\n");
3650 } else
3651 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allanf8d59f72008-08-08 18:36:11 -07003652
3653 free_irq(adapter->pdev->irq, netdev);
3654 pci_disable_msi(adapter->pdev);
3655
Bruce Allanf8d59f72008-08-08 18:36:11 -07003656msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003657 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003658 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003659}
3660
3661/**
3662 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3663 * @adapter: board private struct
3664 *
3665 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3666 **/
3667static int e1000_test_msi(struct e1000_adapter *adapter)
3668{
3669 int err;
3670 u16 pci_cmd;
3671
3672 if (!(adapter->flags & FLAG_MSI_ENABLED))
3673 return 0;
3674
3675 /* disable SERR in case the MSI write causes a master abort */
3676 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003677 if (pci_cmd & PCI_COMMAND_SERR)
3678 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3679 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003680
3681 err = e1000_test_msi_interrupt(adapter);
3682
Dean Nelson36f24072010-06-29 18:12:05 +00003683 /* re-enable SERR */
3684 if (pci_cmd & PCI_COMMAND_SERR) {
3685 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3686 pci_cmd |= PCI_COMMAND_SERR;
3687 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3688 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003689
Bruce Allanf8d59f72008-08-08 18:36:11 -07003690 return err;
3691}
3692
3693/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003694 * e1000_open - Called when a network interface is made active
3695 * @netdev: network interface device structure
3696 *
3697 * Returns 0 on success, negative value on failure
3698 *
3699 * The open entry point is called when a network interface is made
3700 * active by the system (IFF_UP). At this point all resources needed
3701 * for transmit and receive operations are allocated, the interrupt
3702 * handler is registered with the OS, the watchdog timer is started,
3703 * and the stack is notified that the interface is ready.
3704 **/
3705static int e1000_open(struct net_device *netdev)
3706{
3707 struct e1000_adapter *adapter = netdev_priv(netdev);
3708 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003709 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003710 int err;
3711
3712 /* disallow open during test */
3713 if (test_bit(__E1000_TESTING, &adapter->state))
3714 return -EBUSY;
3715
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003716 pm_runtime_get_sync(&pdev->dev);
3717
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003718 netif_carrier_off(netdev);
3719
Auke Kokbc7f75f2007-09-17 12:30:59 -07003720 /* allocate transmit descriptors */
3721 err = e1000e_setup_tx_resources(adapter);
3722 if (err)
3723 goto err_setup_tx;
3724
3725 /* allocate receive descriptors */
3726 err = e1000e_setup_rx_resources(adapter);
3727 if (err)
3728 goto err_setup_rx;
3729
Bruce Allan11b08be2010-05-10 14:59:31 +00003730 /*
3731 * If AMT is enabled, let the firmware know that the network
3732 * interface is now open and reset the part to a known state.
3733 */
3734 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003735 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003736 e1000e_reset(adapter);
3737 }
3738
Auke Kokbc7f75f2007-09-17 12:30:59 -07003739 e1000e_power_up_phy(adapter);
3740
3741 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3742 if ((adapter->hw.mng_cookie.status &
3743 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3744 e1000_update_mng_vlan(adapter);
3745
Florian Micklerc128ec22010-08-02 14:27:00 +00003746 /* DMA latency requirement to workaround early-receive/jumbo issue */
Bruce Allan828bac82010-09-29 21:39:37 +00003747 if ((adapter->flags & FLAG_HAS_ERT) ||
3748 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003749 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3750 PM_QOS_CPU_DMA_LATENCY,
3751 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003752
Bruce Allanad680762008-03-28 09:15:03 -07003753 /*
Bruce Allanad680762008-03-28 09:15:03 -07003754 * before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003755 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3756 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003757 * clean_rx handler before we do so.
3758 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759 e1000_configure(adapter);
3760
3761 err = e1000_request_irq(adapter);
3762 if (err)
3763 goto err_req_irq;
3764
Bruce Allanf8d59f72008-08-08 18:36:11 -07003765 /*
3766 * Work around PCIe errata with MSI interrupts causing some chipsets to
3767 * ignore e1000e MSI messages, which means we need to test our MSI
3768 * interrupt now
3769 */
Bruce Allan4662e822008-08-26 18:37:06 -07003770 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003771 err = e1000_test_msi(adapter);
3772 if (err) {
3773 e_err("Interrupt allocation failed\n");
3774 goto err_req_irq;
3775 }
3776 }
3777
Auke Kokbc7f75f2007-09-17 12:30:59 -07003778 /* From here on the code is the same as e1000e_up() */
3779 clear_bit(__E1000_DOWN, &adapter->state);
3780
3781 napi_enable(&adapter->napi);
3782
3783 e1000_irq_enable(adapter);
3784
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003785 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003786
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003787 adapter->idle_check = true;
3788 pm_runtime_put(&pdev->dev);
3789
Auke Kokbc7f75f2007-09-17 12:30:59 -07003790 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003791 if (adapter->msix_entries)
3792 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3793 else
3794 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003795
3796 return 0;
3797
3798err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003799 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003800 e1000_power_down_phy(adapter);
3801 e1000e_free_rx_resources(adapter);
3802err_setup_rx:
3803 e1000e_free_tx_resources(adapter);
3804err_setup_tx:
3805 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003806 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003807
3808 return err;
3809}
3810
3811/**
3812 * e1000_close - Disables a network interface
3813 * @netdev: network interface device structure
3814 *
3815 * Returns 0, this is not allowed to fail
3816 *
3817 * The close entry point is called when an interface is de-activated
3818 * by the OS. The hardware is still under the drivers control, but
3819 * needs to be disabled. A global MAC reset is issued to stop the
3820 * hardware, and all transmit and receive resources are freed.
3821 **/
3822static int e1000_close(struct net_device *netdev)
3823{
3824 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003825 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003826
3827 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003828
3829 pm_runtime_get_sync(&pdev->dev);
3830
3831 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3832 e1000e_down(adapter);
3833 e1000_free_irq(adapter);
3834 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003835 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003836
3837 e1000e_free_tx_resources(adapter);
3838 e1000e_free_rx_resources(adapter);
3839
Bruce Allanad680762008-03-28 09:15:03 -07003840 /*
3841 * kill manageability vlan ID if supported, but not if a vlan with
3842 * the same ID is registered on the host OS (let 8021q kill it)
3843 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003844 if (adapter->hw.mng_cookie.status &
3845 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003846 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3847
Bruce Allanad680762008-03-28 09:15:03 -07003848 /*
3849 * If AMT is enabled, let the firmware know that the network
3850 * interface is now closed
3851 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003852 if ((adapter->flags & FLAG_HAS_AMT) &&
3853 !test_bit(__E1000_TESTING, &adapter->state))
3854 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003855
Bruce Allan828bac82010-09-29 21:39:37 +00003856 if ((adapter->flags & FLAG_HAS_ERT) ||
3857 (adapter->hw.mac.type == e1000_pch2lan))
Linus Torvalds6ba74012010-08-04 11:47:58 -07003858 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003859
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003860 pm_runtime_put_sync(&pdev->dev);
3861
Auke Kokbc7f75f2007-09-17 12:30:59 -07003862 return 0;
3863}
3864/**
3865 * e1000_set_mac - Change the Ethernet Address of the NIC
3866 * @netdev: network interface device structure
3867 * @p: pointer to an address structure
3868 *
3869 * Returns 0 on success, negative on failure
3870 **/
3871static int e1000_set_mac(struct net_device *netdev, void *p)
3872{
3873 struct e1000_adapter *adapter = netdev_priv(netdev);
3874 struct sockaddr *addr = p;
3875
3876 if (!is_valid_ether_addr(addr->sa_data))
3877 return -EADDRNOTAVAIL;
3878
3879 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3880 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3881
3882 e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
3883
3884 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
3885 /* activate the work around */
3886 e1000e_set_laa_state_82571(&adapter->hw, 1);
3887
Bruce Allanad680762008-03-28 09:15:03 -07003888 /*
3889 * Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07003890 * between the time RAR[0] gets clobbered and the time it
3891 * gets fixed (in e1000_watchdog), the actual LAA is in one
3892 * of the RARs and no incoming packets directed to this port
3893 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07003894 * RAR[14]
3895 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003896 e1000e_rar_set(&adapter->hw,
3897 adapter->hw.mac.addr,
3898 adapter->hw.mac.rar_entry_count - 1);
3899 }
3900
3901 return 0;
3902}
3903
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003904/**
3905 * e1000e_update_phy_task - work thread to update phy
3906 * @work: pointer to our work struct
3907 *
3908 * this worker thread exists because we must acquire a
3909 * semaphore to read the phy, which we could msleep while
3910 * waiting for it, and we can't msleep in a timer.
3911 **/
3912static void e1000e_update_phy_task(struct work_struct *work)
3913{
3914 struct e1000_adapter *adapter = container_of(work,
3915 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003916
3917 if (test_bit(__E1000_DOWN, &adapter->state))
3918 return;
3919
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003920 e1000_get_phy_info(&adapter->hw);
3921}
3922
Bruce Allanad680762008-03-28 09:15:03 -07003923/*
3924 * Need to wait a few seconds after link up to get diagnostic information from
3925 * the phy
3926 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003927static void e1000_update_phy_info(unsigned long data)
3928{
3929 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00003930
3931 if (test_bit(__E1000_DOWN, &adapter->state))
3932 return;
3933
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07003934 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003935}
3936
3937/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003938 * e1000e_update_phy_stats - Update the PHY statistics counters
3939 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00003940 *
3941 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003942 **/
3943static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
3944{
3945 struct e1000_hw *hw = &adapter->hw;
3946 s32 ret_val;
3947 u16 phy_data;
3948
3949 ret_val = hw->phy.ops.acquire(hw);
3950 if (ret_val)
3951 return;
3952
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003953 /*
3954 * A page set is expensive so check if already on desired page.
3955 * If not, set to the page with the PHY status registers.
3956 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003957 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003958 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3959 &phy_data);
3960 if (ret_val)
3961 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00003962 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
3963 ret_val = hw->phy.ops.set_page(hw,
3964 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003965 if (ret_val)
3966 goto release;
3967 }
3968
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003969 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003970 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
3971 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003972 if (!ret_val)
3973 adapter->stats.scc += phy_data;
3974
3975 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003976 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
3977 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003978 if (!ret_val)
3979 adapter->stats.ecol += phy_data;
3980
3981 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003982 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
3983 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003984 if (!ret_val)
3985 adapter->stats.mcc += phy_data;
3986
3987 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003988 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
3989 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003990 if (!ret_val)
3991 adapter->stats.latecol += phy_data;
3992
3993 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00003994 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
3995 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003996 if (!ret_val)
3997 hw->mac.collision_delta = phy_data;
3998
3999 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004000 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4001 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004002 if (!ret_val)
4003 adapter->stats.dc += phy_data;
4004
4005 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004006 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4007 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004008 if (!ret_val)
4009 adapter->stats.tncrs += phy_data;
4010
4011release:
4012 hw->phy.ops.release(hw);
4013}
4014
4015/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004016 * e1000e_update_stats - Update the board statistics counters
4017 * @adapter: board private structure
4018 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004019static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004020{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004021 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004022 struct e1000_hw *hw = &adapter->hw;
4023 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004024
4025 /*
4026 * Prevent stats update while adapter is being reset, or if the pci
4027 * connection is down.
4028 */
4029 if (adapter->link_speed == 0)
4030 return;
4031 if (pci_channel_offline(pdev))
4032 return;
4033
Auke Kokbc7f75f2007-09-17 12:30:59 -07004034 adapter->stats.crcerrs += er32(CRCERRS);
4035 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004036 adapter->stats.gorc += er32(GORCL);
4037 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004038 adapter->stats.bprc += er32(BPRC);
4039 adapter->stats.mprc += er32(MPRC);
4040 adapter->stats.roc += er32(ROC);
4041
Auke Kokbc7f75f2007-09-17 12:30:59 -07004042 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004043
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004044 /* Half-duplex statistics */
4045 if (adapter->link_duplex == HALF_DUPLEX) {
4046 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4047 e1000e_update_phy_stats(adapter);
4048 } else {
4049 adapter->stats.scc += er32(SCC);
4050 adapter->stats.ecol += er32(ECOL);
4051 adapter->stats.mcc += er32(MCC);
4052 adapter->stats.latecol += er32(LATECOL);
4053 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004054
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004055 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004056
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004057 if ((hw->mac.type != e1000_82574) &&
4058 (hw->mac.type != e1000_82583))
4059 adapter->stats.tncrs += er32(TNCRS);
4060 }
4061 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004062 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004063
Auke Kokbc7f75f2007-09-17 12:30:59 -07004064 adapter->stats.xonrxc += er32(XONRXC);
4065 adapter->stats.xontxc += er32(XONTXC);
4066 adapter->stats.xoffrxc += er32(XOFFRXC);
4067 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004068 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004069 adapter->stats.gotc += er32(GOTCL);
4070 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004071 adapter->stats.rnbc += er32(RNBC);
4072 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004073
4074 adapter->stats.mptc += er32(MPTC);
4075 adapter->stats.bptc += er32(BPTC);
4076
4077 /* used for adaptive IFS */
4078
4079 hw->mac.tx_packet_delta = er32(TPT);
4080 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004081
4082 adapter->stats.algnerrc += er32(ALGNERRC);
4083 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004084 adapter->stats.cexterr += er32(CEXTERR);
4085 adapter->stats.tsctc += er32(TSCTC);
4086 adapter->stats.tsctfc += er32(TSCTFC);
4087
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004089 netdev->stats.multicast = adapter->stats.mprc;
4090 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004091
4092 /* Rx Errors */
4093
Bruce Allanad680762008-03-28 09:15:03 -07004094 /*
4095 * RLEC on some newer hardware can be incorrect so build
4096 * our own version based on RUC and ROC
4097 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004098 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004099 adapter->stats.crcerrs + adapter->stats.algnerrc +
4100 adapter->stats.ruc + adapter->stats.roc +
4101 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004102 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004103 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004104 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4105 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4106 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004107
4108 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004109 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004110 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004111 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4112 netdev->stats.tx_window_errors = adapter->stats.latecol;
4113 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004114
4115 /* Tx Dropped needs to be maintained elsewhere */
4116
Auke Kokbc7f75f2007-09-17 12:30:59 -07004117 /* Management Stats */
4118 adapter->stats.mgptc += er32(MGTPTC);
4119 adapter->stats.mgprc += er32(MGTPRC);
4120 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004121}
4122
Bruce Allan7c257692008-04-23 11:09:00 -07004123/**
4124 * e1000_phy_read_status - Update the PHY register status snapshot
4125 * @adapter: board private structure
4126 **/
4127static void e1000_phy_read_status(struct e1000_adapter *adapter)
4128{
4129 struct e1000_hw *hw = &adapter->hw;
4130 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004131
4132 if ((er32(STATUS) & E1000_STATUS_LU) &&
4133 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004134 int ret_val;
4135
Bruce Allan7c257692008-04-23 11:09:00 -07004136 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4137 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4138 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4139 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4140 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4141 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4142 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4143 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4144 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004145 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004146 } else {
4147 /*
4148 * Do not read PHY registers if link is not up
4149 * Set values to typical power-on defaults
4150 */
4151 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4152 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4153 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4154 BMSR_ERCAP);
4155 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4156 ADVERTISE_ALL | ADVERTISE_CSMA);
4157 phy->lpa = 0;
4158 phy->expansion = EXPANSION_ENABLENPAGE;
4159 phy->ctrl1000 = ADVERTISE_1000FULL;
4160 phy->stat1000 = 0;
4161 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4162 }
Bruce Allan7c257692008-04-23 11:09:00 -07004163}
4164
Auke Kokbc7f75f2007-09-17 12:30:59 -07004165static void e1000_print_link_info(struct e1000_adapter *adapter)
4166{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004167 struct e1000_hw *hw = &adapter->hw;
4168 u32 ctrl = er32(CTRL);
4169
Bruce Allan8f12fe82008-11-21 16:54:43 -08004170 /* Link status message must follow this format for user tools */
4171 printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, "
4172 "Flow Control: %s\n",
4173 adapter->netdev->name,
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004174 adapter->link_speed,
4175 (adapter->link_duplex == FULL_DUPLEX) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004176 "Full Duplex" : "Half Duplex",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004177 ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ?
Bruce Allanaf667a22010-12-31 06:10:01 +00004178 "Rx/Tx" :
4179 ((ctrl & E1000_CTRL_RFCE) ? "Rx" :
4180 ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None")));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004181}
4182
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004183static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004184{
4185 struct e1000_hw *hw = &adapter->hw;
4186 bool link_active = 0;
4187 s32 ret_val = 0;
4188
4189 /*
4190 * get_link_status is set on LSC (link status) interrupt or
4191 * Rx sequence error interrupt. get_link_status will stay
4192 * false until the check_for_link establishes link
4193 * for copper adapters ONLY
4194 */
4195 switch (hw->phy.media_type) {
4196 case e1000_media_type_copper:
4197 if (hw->mac.get_link_status) {
4198 ret_val = hw->mac.ops.check_for_link(hw);
4199 link_active = !hw->mac.get_link_status;
4200 } else {
4201 link_active = 1;
4202 }
4203 break;
4204 case e1000_media_type_fiber:
4205 ret_val = hw->mac.ops.check_for_link(hw);
4206 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4207 break;
4208 case e1000_media_type_internal_serdes:
4209 ret_val = hw->mac.ops.check_for_link(hw);
4210 link_active = adapter->hw.mac.serdes_has_link;
4211 break;
4212 default:
4213 case e1000_media_type_unknown:
4214 break;
4215 }
4216
4217 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4218 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4219 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004220 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004221 }
4222
4223 return link_active;
4224}
4225
4226static void e1000e_enable_receives(struct e1000_adapter *adapter)
4227{
4228 /* make sure the receive unit is started */
4229 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
4230 (adapter->flags & FLAG_RX_RESTART_NOW)) {
4231 struct e1000_hw *hw = &adapter->hw;
4232 u32 rctl = er32(RCTL);
4233 ew32(RCTL, rctl | E1000_RCTL_EN);
4234 adapter->flags &= ~FLAG_RX_RESTART_NOW;
4235 }
4236}
4237
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004238static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4239{
4240 struct e1000_hw *hw = &adapter->hw;
4241
4242 /*
4243 * With 82574 controllers, PHY needs to be checked periodically
4244 * for hung state and reset, if two calls return true
4245 */
4246 if (e1000_check_phy_82574(hw))
4247 adapter->phy_hang_count++;
4248 else
4249 adapter->phy_hang_count = 0;
4250
4251 if (adapter->phy_hang_count > 1) {
4252 adapter->phy_hang_count = 0;
4253 schedule_work(&adapter->reset_task);
4254 }
4255}
4256
Auke Kokbc7f75f2007-09-17 12:30:59 -07004257/**
4258 * e1000_watchdog - Timer Call-back
4259 * @data: pointer to adapter cast into an unsigned long
4260 **/
4261static void e1000_watchdog(unsigned long data)
4262{
4263 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4264
4265 /* Do the rest outside of interrupt context */
4266 schedule_work(&adapter->watchdog_task);
4267
4268 /* TODO: make this use queue_delayed_work() */
4269}
4270
4271static void e1000_watchdog_task(struct work_struct *work)
4272{
4273 struct e1000_adapter *adapter = container_of(work,
4274 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004275 struct net_device *netdev = adapter->netdev;
4276 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004277 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004278 struct e1000_ring *tx_ring = adapter->tx_ring;
4279 struct e1000_hw *hw = &adapter->hw;
4280 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004281
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004282 if (test_bit(__E1000_DOWN, &adapter->state))
4283 return;
4284
David S. Millerb405e8d2010-02-04 22:31:41 -08004285 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004286 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004287 /* Cancel scheduled suspend requests. */
4288 pm_runtime_resume(netdev->dev.parent);
4289
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004290 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004291 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004292 }
4293
4294 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4295 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4296 e1000_update_mng_vlan(adapter);
4297
Auke Kokbc7f75f2007-09-17 12:30:59 -07004298 if (link) {
4299 if (!netif_carrier_ok(netdev)) {
4300 bool txb2b = 1;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004301
4302 /* Cancel scheduled suspend requests. */
4303 pm_runtime_resume(netdev->dev.parent);
4304
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004305 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004306 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004307 mac->ops.get_link_up_info(&adapter->hw,
4308 &adapter->link_speed,
4309 &adapter->link_duplex);
4310 e1000_print_link_info(adapter);
Bruce Allanad680762008-03-28 09:15:03 -07004311 /*
Bruce Allanf4187b52008-08-26 18:36:50 -07004312 * On supported PHYs, check for duplex mismatch only
4313 * if link has autonegotiated at 10/100 half
4314 */
4315 if ((hw->phy.type == e1000_phy_igp_3 ||
4316 hw->phy.type == e1000_phy_bm) &&
4317 (hw->mac.autoneg == true) &&
4318 (adapter->link_speed == SPEED_10 ||
4319 adapter->link_speed == SPEED_100) &&
4320 (adapter->link_duplex == HALF_DUPLEX)) {
4321 u16 autoneg_exp;
4322
4323 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4324
4325 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
4326 e_info("Autonegotiated half duplex but"
4327 " link partner cannot autoneg. "
4328 " Try forcing full duplex if "
4329 "link gets many collisions.\n");
4330 }
4331
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004332 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004333 adapter->tx_timeout_factor = 1;
4334 switch (adapter->link_speed) {
4335 case SPEED_10:
4336 txb2b = 0;
Bruce Allan10f1b492008-08-08 18:36:01 -07004337 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004338 break;
4339 case SPEED_100:
4340 txb2b = 0;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004341 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004342 break;
4343 }
4344
Bruce Allanad680762008-03-28 09:15:03 -07004345 /*
4346 * workaround: re-program speed mode bit after
4347 * link-up event
4348 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004349 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4350 !txb2b) {
4351 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004352 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004353 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004354 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004355 }
4356
Bruce Allanad680762008-03-28 09:15:03 -07004357 /*
4358 * disable TSO for pcie and 10/100 speeds, to avoid
4359 * some hardware issues
4360 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004361 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4362 switch (adapter->link_speed) {
4363 case SPEED_10:
4364 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004365 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004366 netdev->features &= ~NETIF_F_TSO;
4367 netdev->features &= ~NETIF_F_TSO6;
4368 break;
4369 case SPEED_1000:
4370 netdev->features |= NETIF_F_TSO;
4371 netdev->features |= NETIF_F_TSO6;
4372 break;
4373 default:
4374 /* oops */
4375 break;
4376 }
4377 }
4378
Bruce Allanad680762008-03-28 09:15:03 -07004379 /*
4380 * enable transmits in the hardware, need to do this
4381 * after setting TARC(0)
4382 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004383 tctl = er32(TCTL);
4384 tctl |= E1000_TCTL_EN;
4385 ew32(TCTL, tctl);
4386
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004387 /*
4388 * Perform any post-link-up configuration before
4389 * reporting link up.
4390 */
4391 if (phy->ops.cfg_on_link_up)
4392 phy->ops.cfg_on_link_up(hw);
4393
Auke Kokbc7f75f2007-09-17 12:30:59 -07004394 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004395
4396 if (!test_bit(__E1000_DOWN, &adapter->state))
4397 mod_timer(&adapter->phy_info_timer,
4398 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004399 }
4400 } else {
4401 if (netif_carrier_ok(netdev)) {
4402 adapter->link_speed = 0;
4403 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004404 /* Link status message must follow this format */
4405 printk(KERN_INFO "e1000e: %s NIC Link is Down\n",
4406 adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004408 if (!test_bit(__E1000_DOWN, &adapter->state))
4409 mod_timer(&adapter->phy_info_timer,
4410 round_jiffies(jiffies + 2 * HZ));
4411
4412 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
4413 schedule_work(&adapter->reset_task);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004414 else
4415 pm_schedule_suspend(netdev->dev.parent,
4416 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004417 }
4418 }
4419
4420link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004421 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004422 e1000e_update_stats(adapter);
4423
4424 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4425 adapter->tpt_old = adapter->stats.tpt;
4426 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4427 adapter->colc_old = adapter->stats.colc;
4428
Bruce Allan7c257692008-04-23 11:09:00 -07004429 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4430 adapter->gorc_old = adapter->stats.gorc;
4431 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4432 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004433 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004434
4435 e1000e_update_adaptive(&adapter->hw);
4436
Bruce Allan90da0662011-01-06 07:02:53 +00004437 if (!netif_carrier_ok(netdev) &&
4438 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) {
4439 /*
4440 * We've lost link, so the controller stops DMA,
4441 * but we've got queued Tx work that's never going
4442 * to get done, so reset controller to flush Tx.
4443 * (Do the reset outside of interrupt context).
4444 */
Bruce Allan90da0662011-01-06 07:02:53 +00004445 schedule_work(&adapter->reset_task);
4446 /* return immediately since reset is imminent */
4447 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004448 }
4449
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004450 /* Simple mode for Interrupt Throttle Rate (ITR) */
4451 if (adapter->itr_setting == 4) {
4452 /*
4453 * Symmetric Tx/Rx gets a reduced ITR=2000;
4454 * Total asymmetrical Tx or Rx gets ITR=8000;
4455 * everyone else is between 2000-8000.
4456 */
4457 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4458 u32 dif = (adapter->gotc > adapter->gorc ?
4459 adapter->gotc - adapter->gorc :
4460 adapter->gorc - adapter->gotc) / 10000;
4461 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4462
4463 ew32(ITR, 1000000000 / (itr * 256));
4464 }
4465
Bruce Allanad680762008-03-28 09:15:03 -07004466 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004467 if (adapter->msix_entries)
4468 ew32(ICS, adapter->rx_ring->ims_val);
4469 else
4470 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004471
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004472 /* flush pending descriptors to memory before detecting Tx hang */
4473 e1000e_flush_descriptors(adapter);
4474
Auke Kokbc7f75f2007-09-17 12:30:59 -07004475 /* Force detection of hung controller every watchdog period */
4476 adapter->detect_tx_hung = 1;
4477
Bruce Allanad680762008-03-28 09:15:03 -07004478 /*
4479 * With 82571 controllers, LAA may be overwritten due to controller
4480 * reset from the other port. Set the appropriate LAA in RAR[0]
4481 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004482 if (e1000e_get_laa_state_82571(hw))
4483 e1000e_rar_set(hw, adapter->hw.mac.addr, 0);
4484
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004485 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4486 e1000e_check_82574_phy_workaround(adapter);
4487
Auke Kokbc7f75f2007-09-17 12:30:59 -07004488 /* Reset the timer */
4489 if (!test_bit(__E1000_DOWN, &adapter->state))
4490 mod_timer(&adapter->watchdog_timer,
4491 round_jiffies(jiffies + 2 * HZ));
4492}
4493
4494#define E1000_TX_FLAGS_CSUM 0x00000001
4495#define E1000_TX_FLAGS_VLAN 0x00000002
4496#define E1000_TX_FLAGS_TSO 0x00000004
4497#define E1000_TX_FLAGS_IPV4 0x00000008
4498#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4499#define E1000_TX_FLAGS_VLAN_SHIFT 16
4500
4501static int e1000_tso(struct e1000_adapter *adapter,
4502 struct sk_buff *skb)
4503{
4504 struct e1000_ring *tx_ring = adapter->tx_ring;
4505 struct e1000_context_desc *context_desc;
4506 struct e1000_buffer *buffer_info;
4507 unsigned int i;
4508 u32 cmd_length = 0;
4509 u16 ipcse = 0, tucse, mss;
4510 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004511
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004512 if (!skb_is_gso(skb))
4513 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004514
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004515 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004516 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4517
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004518 if (err)
4519 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004520 }
4521
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004522 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4523 mss = skb_shinfo(skb)->gso_size;
4524 if (skb->protocol == htons(ETH_P_IP)) {
4525 struct iphdr *iph = ip_hdr(skb);
4526 iph->tot_len = 0;
4527 iph->check = 0;
4528 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4529 0, IPPROTO_TCP, 0);
4530 cmd_length = E1000_TXD_CMD_IP;
4531 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004532 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004533 ipv6_hdr(skb)->payload_len = 0;
4534 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4535 &ipv6_hdr(skb)->daddr,
4536 0, IPPROTO_TCP, 0);
4537 ipcse = 0;
4538 }
4539 ipcss = skb_network_offset(skb);
4540 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4541 tucss = skb_transport_offset(skb);
4542 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
4543 tucse = 0;
4544
4545 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4546 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4547
4548 i = tx_ring->next_to_use;
4549 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4550 buffer_info = &tx_ring->buffer_info[i];
4551
4552 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4553 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4554 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4555 context_desc->upper_setup.tcp_fields.tucss = tucss;
4556 context_desc->upper_setup.tcp_fields.tucso = tucso;
4557 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
4558 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4559 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4560 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4561
4562 buffer_info->time_stamp = jiffies;
4563 buffer_info->next_to_watch = i;
4564
4565 i++;
4566 if (i == tx_ring->count)
4567 i = 0;
4568 tx_ring->next_to_use = i;
4569
4570 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004571}
4572
4573static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
4574{
4575 struct e1000_ring *tx_ring = adapter->tx_ring;
4576 struct e1000_context_desc *context_desc;
4577 struct e1000_buffer *buffer_info;
4578 unsigned int i;
4579 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004580 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004581 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004582
Dave Grahamaf807c82008-10-09 14:28:58 -07004583 if (skb->ip_summed != CHECKSUM_PARTIAL)
4584 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004585
Arthur Jones5f66f202009-03-19 01:13:08 +00004586 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4587 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4588 else
4589 protocol = skb->protocol;
4590
Arthur Jones3f518392009-03-20 15:56:35 -07004591 switch (protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08004592 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004593 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4594 cmd_len |= E1000_TXD_CMD_TCP;
4595 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08004596 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004597 /* XXX not handling all IPV6 headers */
4598 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4599 cmd_len |= E1000_TXD_CMD_TCP;
4600 break;
4601 default:
4602 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004603 e_warn("checksum_partial proto=%x!\n",
4604 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004605 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004606 }
4607
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004608 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004609
4610 i = tx_ring->next_to_use;
4611 buffer_info = &tx_ring->buffer_info[i];
4612 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4613
4614 context_desc->lower_setup.ip_config = 0;
4615 context_desc->upper_setup.tcp_fields.tucss = css;
4616 context_desc->upper_setup.tcp_fields.tucso =
4617 css + skb->csum_offset;
4618 context_desc->upper_setup.tcp_fields.tucse = 0;
4619 context_desc->tcp_seg_setup.data = 0;
4620 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4621
4622 buffer_info->time_stamp = jiffies;
4623 buffer_info->next_to_watch = i;
4624
4625 i++;
4626 if (i == tx_ring->count)
4627 i = 0;
4628 tx_ring->next_to_use = i;
4629
4630 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004631}
4632
4633#define E1000_MAX_PER_TXD 8192
4634#define E1000_MAX_TXD_PWR 12
4635
4636static int e1000_tx_map(struct e1000_adapter *adapter,
4637 struct sk_buff *skb, unsigned int first,
4638 unsigned int max_per_txd, unsigned int nr_frags,
4639 unsigned int mss)
4640{
4641 struct e1000_ring *tx_ring = adapter->tx_ring;
Alexander Duyck03b13202009-12-02 16:45:31 +00004642 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004643 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004644 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004645 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004646 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004647
4648 i = tx_ring->next_to_use;
4649
4650 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004651 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004652 size = min(len, max_per_txd);
4653
Auke Kokbc7f75f2007-09-17 12:30:59 -07004654 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004655 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004656 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004657 buffer_info->dma = dma_map_single(&pdev->dev,
4658 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004659 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004660 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004661 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004662 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004663
4664 len -= size;
4665 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004666 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004667
4668 if (len) {
4669 i++;
4670 if (i == tx_ring->count)
4671 i = 0;
4672 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004673 }
4674
4675 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004676 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004677
4678 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004679 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004680 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004681
4682 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004683 i++;
4684 if (i == tx_ring->count)
4685 i = 0;
4686
Auke Kokbc7f75f2007-09-17 12:30:59 -07004687 buffer_info = &tx_ring->buffer_info[i];
4688 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004689
4690 buffer_info->length = size;
4691 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004692 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004693 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4694 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004695 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004696 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004697 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004698
4699 len -= size;
4700 offset += size;
4701 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004702 }
4703 }
4704
Bruce Allanaf667a22010-12-31 06:10:01 +00004705 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004706 /* multiply data chunks by size of headers */
4707 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4708
Auke Kokbc7f75f2007-09-17 12:30:59 -07004709 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004710 tx_ring->buffer_info[i].segs = segs;
4711 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004712 tx_ring->buffer_info[first].next_to_watch = i;
4713
4714 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004715
4716dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004717 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004718 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004719 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004720 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004721
4722 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004723 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004724 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004725 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004726 buffer_info = &tx_ring->buffer_info[i];
Joe Perches1d51c412010-11-14 17:04:32 +00004727 e1000_put_txbuf(adapter, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004728 }
4729
4730 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004731}
4732
4733static void e1000_tx_queue(struct e1000_adapter *adapter,
4734 int tx_flags, int count)
4735{
4736 struct e1000_ring *tx_ring = adapter->tx_ring;
4737 struct e1000_tx_desc *tx_desc = NULL;
4738 struct e1000_buffer *buffer_info;
4739 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4740 unsigned int i;
4741
4742 if (tx_flags & E1000_TX_FLAGS_TSO) {
4743 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4744 E1000_TXD_CMD_TSE;
4745 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4746
4747 if (tx_flags & E1000_TX_FLAGS_IPV4)
4748 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4749 }
4750
4751 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4752 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4753 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4754 }
4755
4756 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4757 txd_lower |= E1000_TXD_CMD_VLE;
4758 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4759 }
4760
4761 i = tx_ring->next_to_use;
4762
Bruce Allan36b973d2010-11-24 07:42:43 +00004763 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004764 buffer_info = &tx_ring->buffer_info[i];
4765 tx_desc = E1000_TX_DESC(*tx_ring, i);
4766 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4767 tx_desc->lower.data =
4768 cpu_to_le32(txd_lower | buffer_info->length);
4769 tx_desc->upper.data = cpu_to_le32(txd_upper);
4770
4771 i++;
4772 if (i == tx_ring->count)
4773 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004774 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004775
4776 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4777
Bruce Allanad680762008-03-28 09:15:03 -07004778 /*
4779 * Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004780 * know there are new descriptors to fetch. (Only
4781 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004782 * such as IA-64).
4783 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004784 wmb();
4785
4786 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004787
4788 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
4789 e1000e_update_tdt_wa(adapter, i);
4790 else
4791 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4792
Bruce Allanad680762008-03-28 09:15:03 -07004793 /*
4794 * we need this if more than one processor can write to our tail
4795 * at a time, it synchronizes IO on IA64/Altix systems
4796 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004797 mmiowb();
4798}
4799
4800#define MINIMUM_DHCP_PACKET_SIZE 282
4801static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4802 struct sk_buff *skb)
4803{
4804 struct e1000_hw *hw = &adapter->hw;
4805 u16 length, offset;
4806
4807 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004808 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4809 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004810 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4811 return 0;
4812 }
4813
4814 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4815 return 0;
4816
4817 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4818 return 0;
4819
4820 {
4821 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4822 struct udphdr *udp;
4823
4824 if (ip->protocol != IPPROTO_UDP)
4825 return 0;
4826
4827 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4828 if (ntohs(udp->dest) != 67)
4829 return 0;
4830
4831 offset = (u8 *)udp + 8 - skb->data;
4832 length = skb->len - offset;
4833 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4834 }
4835
4836 return 0;
4837}
4838
4839static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
4840{
4841 struct e1000_adapter *adapter = netdev_priv(netdev);
4842
4843 netif_stop_queue(netdev);
Bruce Allanad680762008-03-28 09:15:03 -07004844 /*
4845 * Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004846 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004847 * but since that doesn't exist yet, just open code it.
4848 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004849 smp_mb();
4850
Bruce Allanad680762008-03-28 09:15:03 -07004851 /*
4852 * We need to check again in a case another CPU has just
4853 * made room available.
4854 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004855 if (e1000_desc_unused(adapter->tx_ring) < size)
4856 return -EBUSY;
4857
4858 /* A reprieve! */
4859 netif_start_queue(netdev);
4860 ++adapter->restart_queue;
4861 return 0;
4862}
4863
4864static int e1000_maybe_stop_tx(struct net_device *netdev, int size)
4865{
4866 struct e1000_adapter *adapter = netdev_priv(netdev);
4867
4868 if (e1000_desc_unused(adapter->tx_ring) >= size)
4869 return 0;
4870 return __e1000_maybe_stop_tx(netdev, size);
4871}
4872
4873#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004874static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4875 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004876{
4877 struct e1000_adapter *adapter = netdev_priv(netdev);
4878 struct e1000_ring *tx_ring = adapter->tx_ring;
4879 unsigned int first;
4880 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4881 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4882 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004883 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004884 unsigned int nr_frags;
4885 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004886 int count = 0;
4887 int tso;
4888 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004889
4890 if (test_bit(__E1000_DOWN, &adapter->state)) {
4891 dev_kfree_skb_any(skb);
4892 return NETDEV_TX_OK;
4893 }
4894
4895 if (skb->len <= 0) {
4896 dev_kfree_skb_any(skb);
4897 return NETDEV_TX_OK;
4898 }
4899
4900 mss = skb_shinfo(skb)->gso_size;
Bruce Allanad680762008-03-28 09:15:03 -07004901 /*
4902 * The controller does a simple calculation to
Auke Kokbc7f75f2007-09-17 12:30:59 -07004903 * make sure there is enough room in the FIFO before
4904 * initiating the DMA for each buffer. The calc is:
4905 * 4 = ceil(buffer len/mss). To make sure we don't
4906 * overrun the FIFO, adjust the max buffer len if mss
Bruce Allanad680762008-03-28 09:15:03 -07004907 * drops.
4908 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004909 if (mss) {
4910 u8 hdr_len;
4911 max_per_txd = min(mss << 2, max_per_txd);
4912 max_txd_pwr = fls(max_per_txd) - 1;
4913
Bruce Allanad680762008-03-28 09:15:03 -07004914 /*
4915 * TSO Workaround for 82571/2/3 Controllers -- if skb->data
4916 * points to just header, pull a few bytes of payload from
4917 * frags into skb->data
4918 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004919 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allanad680762008-03-28 09:15:03 -07004920 /*
4921 * we do this workaround for ES2LAN, but it is un-necessary,
4922 * avoiding it could save a lot of cycles
4923 */
Auke Kok4e6c7092007-10-05 14:15:23 -07004924 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004925 unsigned int pull_size;
4926
4927 pull_size = min((unsigned int)4, skb->data_len);
4928 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004929 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004930 dev_kfree_skb_any(skb);
4931 return NETDEV_TX_OK;
4932 }
Eric Dumazete743d312010-04-14 15:59:40 -07004933 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004934 }
4935 }
4936
4937 /* reserve a descriptor for the offload context */
4938 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
4939 count++;
4940 count++;
4941
4942 count += TXD_USE_COUNT(len, max_txd_pwr);
4943
4944 nr_frags = skb_shinfo(skb)->nr_frags;
4945 for (f = 0; f < nr_frags; f++)
Eric Dumazet9e903e02011-10-18 21:00:24 +00004946 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
Auke Kokbc7f75f2007-09-17 12:30:59 -07004947 max_txd_pwr);
4948
4949 if (adapter->hw.mac.tx_pkt_filtering)
4950 e1000_transfer_dhcp_info(adapter, skb);
4951
Bruce Allanad680762008-03-28 09:15:03 -07004952 /*
4953 * need: count + 2 desc gap to keep tail from touching
4954 * head, otherwise try next time
4955 */
Jesse Brandeburg92af3e92009-01-19 14:17:08 +00004956 if (e1000_maybe_stop_tx(netdev, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004957 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004958
Jesse Grosseab6d182010-10-20 13:56:03 +00004959 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004960 tx_flags |= E1000_TX_FLAGS_VLAN;
4961 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
4962 }
4963
4964 first = tx_ring->next_to_use;
4965
4966 tso = e1000_tso(adapter, skb);
4967 if (tso < 0) {
4968 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004969 return NETDEV_TX_OK;
4970 }
4971
4972 if (tso)
4973 tx_flags |= E1000_TX_FLAGS_TSO;
4974 else if (e1000_tx_csum(adapter, skb))
4975 tx_flags |= E1000_TX_FLAGS_CSUM;
4976
Bruce Allanad680762008-03-28 09:15:03 -07004977 /*
4978 * Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004979 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07004980 * no longer assume, we must.
4981 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004982 if (skb->protocol == htons(ETH_P_IP))
4983 tx_flags |= E1000_TX_FLAGS_IPV4;
4984
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004985 /* if count is 0 then mapping error has occurred */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004986 count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004987 if (count) {
4988 e1000_tx_queue(adapter, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004989 /* Make sure there is space in the ring for the next send. */
4990 e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2);
4991
4992 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004993 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004994 tx_ring->buffer_info[first].time_stamp = 0;
4995 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004996 }
4997
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998 return NETDEV_TX_OK;
4999}
5000
5001/**
5002 * e1000_tx_timeout - Respond to a Tx Hang
5003 * @netdev: network interface device structure
5004 **/
5005static void e1000_tx_timeout(struct net_device *netdev)
5006{
5007 struct e1000_adapter *adapter = netdev_priv(netdev);
5008
5009 /* Do the reset outside of interrupt context */
5010 adapter->tx_timeout_count++;
5011 schedule_work(&adapter->reset_task);
5012}
5013
5014static void e1000_reset_task(struct work_struct *work)
5015{
5016 struct e1000_adapter *adapter;
5017 adapter = container_of(work, struct e1000_adapter, reset_task);
5018
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005019 /* don't run the task if already down */
5020 if (test_bit(__E1000_DOWN, &adapter->state))
5021 return;
5022
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005023 if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
5024 (adapter->flags & FLAG_RX_RESTART_NOW))) {
5025 e1000e_dump(adapter);
5026 e_err("Reset adapter\n");
5027 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005028 e1000e_reinit_locked(adapter);
5029}
5030
5031/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005032 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005033 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005034 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005035 *
5036 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005038struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5039 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005040{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005041 struct e1000_adapter *adapter = netdev_priv(netdev);
5042
5043 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5044 spin_lock(&adapter->stats64_lock);
5045 e1000e_update_stats(adapter);
5046 /* Fill out the OS statistics structure */
5047 stats->rx_bytes = adapter->stats.gorc;
5048 stats->rx_packets = adapter->stats.gprc;
5049 stats->tx_bytes = adapter->stats.gotc;
5050 stats->tx_packets = adapter->stats.gptc;
5051 stats->multicast = adapter->stats.mprc;
5052 stats->collisions = adapter->stats.colc;
5053
5054 /* Rx Errors */
5055
5056 /*
5057 * RLEC on some newer hardware can be incorrect so build
5058 * our own version based on RUC and ROC
5059 */
5060 stats->rx_errors = adapter->stats.rxerrc +
5061 adapter->stats.crcerrs + adapter->stats.algnerrc +
5062 adapter->stats.ruc + adapter->stats.roc +
5063 adapter->stats.cexterr;
5064 stats->rx_length_errors = adapter->stats.ruc +
5065 adapter->stats.roc;
5066 stats->rx_crc_errors = adapter->stats.crcerrs;
5067 stats->rx_frame_errors = adapter->stats.algnerrc;
5068 stats->rx_missed_errors = adapter->stats.mpc;
5069
5070 /* Tx Errors */
5071 stats->tx_errors = adapter->stats.ecol +
5072 adapter->stats.latecol;
5073 stats->tx_aborted_errors = adapter->stats.ecol;
5074 stats->tx_window_errors = adapter->stats.latecol;
5075 stats->tx_carrier_errors = adapter->stats.tncrs;
5076
5077 /* Tx Dropped needs to be maintained elsewhere */
5078
5079 spin_unlock(&adapter->stats64_lock);
5080 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005081}
5082
5083/**
5084 * e1000_change_mtu - Change the Maximum Transfer Unit
5085 * @netdev: network interface device structure
5086 * @new_mtu: new value for maximum frame size
5087 *
5088 * Returns 0 on success, negative on failure
5089 **/
5090static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5091{
5092 struct e1000_adapter *adapter = netdev_priv(netdev);
5093 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5094
Bruce Allan2adc55c2009-06-02 11:28:58 +00005095 /* Jumbo frame support */
5096 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5097 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5098 e_err("Jumbo Frames not supported.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005099 return -EINVAL;
5100 }
5101
Bruce Allan2adc55c2009-06-02 11:28:58 +00005102 /* Supported frame sizes */
5103 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5104 (max_frame > adapter->max_hw_frame_size)) {
5105 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005106 return -EINVAL;
5107 }
5108
Bruce Allana1ce6472010-09-22 17:16:40 +00005109 /* Jumbo frame workaround on 82579 requires CRC be stripped */
5110 if ((adapter->hw.mac.type == e1000_pch2lan) &&
5111 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5112 (new_mtu > ETH_DATA_LEN)) {
5113 e_err("Jumbo Frames not supported on 82579 when CRC "
5114 "stripping is disabled.\n");
5115 return -EINVAL;
5116 }
5117
Bruce Allan6f461f62010-04-27 03:33:04 +00005118 /* 82573 Errata 17 */
5119 if (((adapter->hw.mac.type == e1000_82573) ||
5120 (adapter->hw.mac.type == e1000_82574)) &&
5121 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
5122 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
5123 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
5124 }
5125
Auke Kokbc7f75f2007-09-17 12:30:59 -07005126 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005127 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005128 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005129 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005130 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5131 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005132 if (netif_running(netdev))
5133 e1000e_down(adapter);
5134
Bruce Allanad680762008-03-28 09:15:03 -07005135 /*
5136 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005137 * means we reserve 2 more, this pushes us to allocate from the next
5138 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005139 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005140 * However with the new *_jumbo_rx* routines, jumbo receives will use
5141 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005142 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005143
Jesse Brandeburg99261462010-01-22 22:56:16 +00005144 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005145 adapter->rx_buffer_len = 2048;
5146 else
5147 adapter->rx_buffer_len = 4096;
5148
5149 /* adjust allocation if LPE protects us, and we aren't using SBP */
5150 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5151 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5152 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005153 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005154
Auke Kokbc7f75f2007-09-17 12:30:59 -07005155 if (netif_running(netdev))
5156 e1000e_up(adapter);
5157 else
5158 e1000e_reset(adapter);
5159
5160 clear_bit(__E1000_RESETTING, &adapter->state);
5161
5162 return 0;
5163}
5164
5165static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5166 int cmd)
5167{
5168 struct e1000_adapter *adapter = netdev_priv(netdev);
5169 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005170
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005171 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005172 return -EOPNOTSUPP;
5173
5174 switch (cmd) {
5175 case SIOCGMIIPHY:
5176 data->phy_id = adapter->hw.phy.addr;
5177 break;
5178 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005179 e1000_phy_read_status(adapter);
5180
Bruce Allan7c257692008-04-23 11:09:00 -07005181 switch (data->reg_num & 0x1F) {
5182 case MII_BMCR:
5183 data->val_out = adapter->phy_regs.bmcr;
5184 break;
5185 case MII_BMSR:
5186 data->val_out = adapter->phy_regs.bmsr;
5187 break;
5188 case MII_PHYSID1:
5189 data->val_out = (adapter->hw.phy.id >> 16);
5190 break;
5191 case MII_PHYSID2:
5192 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5193 break;
5194 case MII_ADVERTISE:
5195 data->val_out = adapter->phy_regs.advertise;
5196 break;
5197 case MII_LPA:
5198 data->val_out = adapter->phy_regs.lpa;
5199 break;
5200 case MII_EXPANSION:
5201 data->val_out = adapter->phy_regs.expansion;
5202 break;
5203 case MII_CTRL1000:
5204 data->val_out = adapter->phy_regs.ctrl1000;
5205 break;
5206 case MII_STAT1000:
5207 data->val_out = adapter->phy_regs.stat1000;
5208 break;
5209 case MII_ESTATUS:
5210 data->val_out = adapter->phy_regs.estatus;
5211 break;
5212 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213 return -EIO;
5214 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005215 break;
5216 case SIOCSMIIREG:
5217 default:
5218 return -EOPNOTSUPP;
5219 }
5220 return 0;
5221}
5222
5223static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5224{
5225 switch (cmd) {
5226 case SIOCGMIIPHY:
5227 case SIOCGMIIREG:
5228 case SIOCSMIIREG:
5229 return e1000_mii_ioctl(netdev, ifr, cmd);
5230 default:
5231 return -EOPNOTSUPP;
5232 }
5233}
5234
Bruce Allana4f58f52009-06-02 11:29:18 +00005235static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5236{
5237 struct e1000_hw *hw = &adapter->hw;
5238 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005239 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005240 int retval = 0;
5241
5242 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005243 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005244
Bruce Allan2b6b1682011-05-13 07:20:09 +00005245 retval = hw->phy.ops.acquire(hw);
5246 if (retval) {
5247 e_err("Could not acquire PHY\n");
5248 return retval;
5249 }
5250
5251 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5252 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5253 if (retval)
5254 goto out;
5255
5256 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005257 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5258 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005259 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5260 (u16)(mac_reg & 0xFFFF));
5261 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5262 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005263 }
5264
5265 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005266 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005267 mac_reg = er32(RCTL);
5268 if (mac_reg & E1000_RCTL_UPE)
5269 phy_reg |= BM_RCTL_UPE;
5270 if (mac_reg & E1000_RCTL_MPE)
5271 phy_reg |= BM_RCTL_MPE;
5272 phy_reg &= ~(BM_RCTL_MO_MASK);
5273 if (mac_reg & E1000_RCTL_MO_3)
5274 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5275 << BM_RCTL_MO_SHIFT);
5276 if (mac_reg & E1000_RCTL_BAM)
5277 phy_reg |= BM_RCTL_BAM;
5278 if (mac_reg & E1000_RCTL_PMCF)
5279 phy_reg |= BM_RCTL_PMCF;
5280 mac_reg = er32(CTRL);
5281 if (mac_reg & E1000_CTRL_RFCE)
5282 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005283 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005284
5285 /* enable PHY wakeup in MAC register */
5286 ew32(WUFC, wufc);
5287 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5288
5289 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005290 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5291 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005292
5293 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005294 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5295 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005296 if (retval)
5297 e_err("Could not set PHY Host Wakeup bit\n");
5298out:
Bruce Allan94d81862009-11-20 23:25:26 +00005299 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005300
5301 return retval;
5302}
5303
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005304static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5305 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005306{
5307 struct net_device *netdev = pci_get_drvdata(pdev);
5308 struct e1000_adapter *adapter = netdev_priv(netdev);
5309 struct e1000_hw *hw = &adapter->hw;
5310 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005311 /* Runtime suspend should only enable wakeup for link changes */
5312 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005313 int retval = 0;
5314
5315 netif_device_detach(netdev);
5316
5317 if (netif_running(netdev)) {
5318 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5319 e1000e_down(adapter);
5320 e1000_free_irq(adapter);
5321 }
Bruce Allan4662e822008-08-26 18:37:06 -07005322 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005323
5324 retval = pci_save_state(pdev);
5325 if (retval)
5326 return retval;
5327
5328 status = er32(STATUS);
5329 if (status & E1000_STATUS_LU)
5330 wufc &= ~E1000_WUFC_LNKC;
5331
5332 if (wufc) {
5333 e1000_setup_rctl(adapter);
5334 e1000_set_multi(netdev);
5335
5336 /* turn on all-multi mode if wake on multicast is enabled */
5337 if (wufc & E1000_WUFC_MC) {
5338 rctl = er32(RCTL);
5339 rctl |= E1000_RCTL_MPE;
5340 ew32(RCTL, rctl);
5341 }
5342
5343 ctrl = er32(CTRL);
5344 /* advertise wake from D3Cold */
5345 #define E1000_CTRL_ADVD3WUC 0x00100000
5346 /* phy power management enable */
5347 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005348 ctrl |= E1000_CTRL_ADVD3WUC;
5349 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5350 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005351 ew32(CTRL, ctrl);
5352
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005353 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5354 adapter->hw.phy.media_type ==
5355 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005356 /* keep the laser running in D3 */
5357 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005358 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005359 ew32(CTRL_EXT, ctrl_ext);
5360 }
5361
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005362 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005363 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005364
Auke Kokbc7f75f2007-09-17 12:30:59 -07005365 /* Allow time for pending master requests to run */
5366 e1000e_disable_pcie_master(&adapter->hw);
5367
Bruce Allan82776a42009-08-14 14:35:33 +00005368 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005369 /* enable wakeup by the PHY */
5370 retval = e1000_init_phy_wakeup(adapter, wufc);
5371 if (retval)
5372 return retval;
5373 } else {
5374 /* enable wakeup by the MAC */
5375 ew32(WUFC, wufc);
5376 ew32(WUC, E1000_WUC_PME_EN);
5377 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005378 } else {
5379 ew32(WUC, 0);
5380 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005381 }
5382
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005383 *enable_wake = !!wufc;
5384
Auke Kokbc7f75f2007-09-17 12:30:59 -07005385 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005386 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5387 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005388 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005389
5390 if (adapter->hw.phy.type == e1000_phy_igp_3)
5391 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5392
Bruce Allanad680762008-03-28 09:15:03 -07005393 /*
5394 * Release control of h/w to f/w. If f/w is AMT enabled, this
5395 * would have already happened in close and is redundant.
5396 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005397 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005398
5399 pci_disable_device(pdev);
5400
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005401 return 0;
5402}
5403
5404static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5405{
5406 if (sleep && wake) {
5407 pci_prepare_to_sleep(pdev);
5408 return;
5409 }
5410
5411 pci_wake_from_d3(pdev, wake);
5412 pci_set_power_state(pdev, PCI_D3hot);
5413}
5414
5415static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5416 bool wake)
5417{
5418 struct net_device *netdev = pci_get_drvdata(pdev);
5419 struct e1000_adapter *adapter = netdev_priv(netdev);
5420
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005421 /*
5422 * The pci-e switch on some quad port adapters will report a
5423 * correctable error when the MAC transitions from D0 to D3. To
5424 * prevent this we need to mask off the correctable errors on the
5425 * downstream port of the pci-e switch.
5426 */
5427 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5428 struct pci_dev *us_dev = pdev->bus->self;
Jon Mason353064d2011-06-27 07:43:47 +00005429 int pos = pci_pcie_cap(us_dev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005430 u16 devctl;
5431
5432 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl);
5433 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL,
5434 (devctl & ~PCI_EXP_DEVCTL_CERE));
5435
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005436 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005437
5438 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl);
5439 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005440 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005441 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005442}
5443
Bruce Allan6f461f62010-04-27 03:33:04 +00005444#ifdef CONFIG_PCIEASPM
5445static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5446{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005447 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005448}
5449#else
5450static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005451{
5452 int pos;
Bruce Allan6f461f62010-04-27 03:33:04 +00005453 u16 reg16;
Auke Kok1eae4eb2007-10-31 15:22:00 -07005454
5455 /*
Bruce Allan6f461f62010-04-27 03:33:04 +00005456 * Both device and parent should have the same ASPM setting.
5457 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005458 */
Bruce Allan6f461f62010-04-27 03:33:04 +00005459 pos = pci_pcie_cap(pdev);
5460 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5461 reg16 &= ~state;
5462 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5463
Anton Blanchard0c75ba22010-04-28 21:46:06 +00005464 if (!pdev->bus->self)
5465 return;
5466
Bruce Allan6f461f62010-04-27 03:33:04 +00005467 pos = pci_pcie_cap(pdev->bus->self);
5468 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5469 reg16 &= ~state;
5470 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5471}
5472#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005473static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005474{
5475 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5476 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5477 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5478
5479 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005480}
5481
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005482#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005483static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005484{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005485 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005486}
5487
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005488static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005489{
5490 struct net_device *netdev = pci_get_drvdata(pdev);
5491 struct e1000_adapter *adapter = netdev_priv(netdev);
5492 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005493 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005494 u32 err;
5495
Bruce Allan78cd29d2011-03-24 03:09:03 +00005496 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5497 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5498 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5499 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5500 if (aspm_disable_flag)
5501 e1000e_disable_aspm(pdev, aspm_disable_flag);
5502
Auke Kokbc7f75f2007-09-17 12:30:59 -07005503 pci_set_power_state(pdev, PCI_D0);
5504 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005505 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005506
Bruce Allan4662e822008-08-26 18:37:06 -07005507 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005508 if (netif_running(netdev)) {
5509 err = e1000_request_irq(adapter);
5510 if (err)
5511 return err;
5512 }
5513
Bruce Allan99730e42011-05-13 07:19:48 +00005514 if (hw->mac.type == e1000_pch2lan)
5515 e1000_resume_workarounds_pchlan(&adapter->hw);
5516
Auke Kokbc7f75f2007-09-17 12:30:59 -07005517 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005518
5519 /* report the system wakeup cause from S3/S4 */
5520 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5521 u16 phy_data;
5522
5523 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5524 if (phy_data) {
5525 e_info("PHY Wakeup cause - %s\n",
5526 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5527 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5528 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5529 phy_data & E1000_WUS_MAG ? "Magic Packet" :
5530 phy_data & E1000_WUS_LNKC ? "Link Status "
5531 " Change" : "other");
5532 }
5533 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5534 } else {
5535 u32 wus = er32(WUS);
5536 if (wus) {
5537 e_info("MAC Wakeup cause - %s\n",
5538 wus & E1000_WUS_EX ? "Unicast Packet" :
5539 wus & E1000_WUS_MC ? "Multicast Packet" :
5540 wus & E1000_WUS_BC ? "Broadcast Packet" :
5541 wus & E1000_WUS_MAG ? "Magic Packet" :
5542 wus & E1000_WUS_LNKC ? "Link Status Change" :
5543 "other");
5544 }
5545 ew32(WUS, ~0);
5546 }
5547
Auke Kokbc7f75f2007-09-17 12:30:59 -07005548 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005549
Bruce Allancd791612010-05-10 14:59:51 +00005550 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005551
5552 if (netif_running(netdev))
5553 e1000e_up(adapter);
5554
5555 netif_device_attach(netdev);
5556
Bruce Allanad680762008-03-28 09:15:03 -07005557 /*
5558 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005559 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005560 * under the control of the driver.
5561 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005562 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005563 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005564
5565 return 0;
5566}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005567
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005568#ifdef CONFIG_PM_SLEEP
5569static int e1000_suspend(struct device *dev)
5570{
5571 struct pci_dev *pdev = to_pci_dev(dev);
5572 int retval;
5573 bool wake;
5574
5575 retval = __e1000_shutdown(pdev, &wake, false);
5576 if (!retval)
5577 e1000_complete_shutdown(pdev, true, wake);
5578
5579 return retval;
5580}
5581
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005582static int e1000_resume(struct device *dev)
5583{
5584 struct pci_dev *pdev = to_pci_dev(dev);
5585 struct net_device *netdev = pci_get_drvdata(pdev);
5586 struct e1000_adapter *adapter = netdev_priv(netdev);
5587
5588 if (e1000e_pm_ready(adapter))
5589 adapter->idle_check = true;
5590
5591 return __e1000_resume(pdev);
5592}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005593#endif /* CONFIG_PM_SLEEP */
5594
5595#ifdef CONFIG_PM_RUNTIME
5596static int e1000_runtime_suspend(struct device *dev)
5597{
5598 struct pci_dev *pdev = to_pci_dev(dev);
5599 struct net_device *netdev = pci_get_drvdata(pdev);
5600 struct e1000_adapter *adapter = netdev_priv(netdev);
5601
5602 if (e1000e_pm_ready(adapter)) {
5603 bool wake;
5604
5605 __e1000_shutdown(pdev, &wake, true);
5606 }
5607
5608 return 0;
5609}
5610
5611static int e1000_idle(struct device *dev)
5612{
5613 struct pci_dev *pdev = to_pci_dev(dev);
5614 struct net_device *netdev = pci_get_drvdata(pdev);
5615 struct e1000_adapter *adapter = netdev_priv(netdev);
5616
5617 if (!e1000e_pm_ready(adapter))
5618 return 0;
5619
5620 if (adapter->idle_check) {
5621 adapter->idle_check = false;
5622 if (!e1000e_has_link(adapter))
5623 pm_schedule_suspend(dev, MSEC_PER_SEC);
5624 }
5625
5626 return -EBUSY;
5627}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005628
5629static int e1000_runtime_resume(struct device *dev)
5630{
5631 struct pci_dev *pdev = to_pci_dev(dev);
5632 struct net_device *netdev = pci_get_drvdata(pdev);
5633 struct e1000_adapter *adapter = netdev_priv(netdev);
5634
5635 if (!e1000e_pm_ready(adapter))
5636 return 0;
5637
5638 adapter->idle_check = !dev->power.runtime_auto;
5639 return __e1000_resume(pdev);
5640}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005641#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005642#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005643
5644static void e1000_shutdown(struct pci_dev *pdev)
5645{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005646 bool wake = false;
5647
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005648 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005649
5650 if (system_state == SYSTEM_POWER_OFF)
5651 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005652}
5653
5654#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005655
5656static irqreturn_t e1000_intr_msix(int irq, void *data)
5657{
5658 struct net_device *netdev = data;
5659 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005660
5661 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005662 int vector, msix_irq;
5663
Dongdong Deng147b2c82010-11-16 19:50:15 -08005664 vector = 0;
5665 msix_irq = adapter->msix_entries[vector].vector;
5666 disable_irq(msix_irq);
5667 e1000_intr_msix_rx(msix_irq, netdev);
5668 enable_irq(msix_irq);
5669
5670 vector++;
5671 msix_irq = adapter->msix_entries[vector].vector;
5672 disable_irq(msix_irq);
5673 e1000_intr_msix_tx(msix_irq, netdev);
5674 enable_irq(msix_irq);
5675
5676 vector++;
5677 msix_irq = adapter->msix_entries[vector].vector;
5678 disable_irq(msix_irq);
5679 e1000_msix_other(msix_irq, netdev);
5680 enable_irq(msix_irq);
5681 }
5682
5683 return IRQ_HANDLED;
5684}
5685
Auke Kokbc7f75f2007-09-17 12:30:59 -07005686/*
5687 * Polling 'interrupt' - used by things like netconsole to send skbs
5688 * without having to re-enable interrupts. It's not called while
5689 * the interrupt routine is executing.
5690 */
5691static void e1000_netpoll(struct net_device *netdev)
5692{
5693 struct e1000_adapter *adapter = netdev_priv(netdev);
5694
Dongdong Deng147b2c82010-11-16 19:50:15 -08005695 switch (adapter->int_mode) {
5696 case E1000E_INT_MODE_MSIX:
5697 e1000_intr_msix(adapter->pdev->irq, netdev);
5698 break;
5699 case E1000E_INT_MODE_MSI:
5700 disable_irq(adapter->pdev->irq);
5701 e1000_intr_msi(adapter->pdev->irq, netdev);
5702 enable_irq(adapter->pdev->irq);
5703 break;
5704 default: /* E1000E_INT_MODE_LEGACY */
5705 disable_irq(adapter->pdev->irq);
5706 e1000_intr(adapter->pdev->irq, netdev);
5707 enable_irq(adapter->pdev->irq);
5708 break;
5709 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005710}
5711#endif
5712
5713/**
5714 * e1000_io_error_detected - called when PCI error is detected
5715 * @pdev: Pointer to PCI device
5716 * @state: The current pci connection state
5717 *
5718 * This function is called after a PCI bus error affecting
5719 * this device has been detected.
5720 */
5721static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5722 pci_channel_state_t state)
5723{
5724 struct net_device *netdev = pci_get_drvdata(pdev);
5725 struct e1000_adapter *adapter = netdev_priv(netdev);
5726
5727 netif_device_detach(netdev);
5728
Mike Masonc93b5a72009-06-30 12:45:53 +00005729 if (state == pci_channel_io_perm_failure)
5730 return PCI_ERS_RESULT_DISCONNECT;
5731
Auke Kokbc7f75f2007-09-17 12:30:59 -07005732 if (netif_running(netdev))
5733 e1000e_down(adapter);
5734 pci_disable_device(pdev);
5735
5736 /* Request a slot slot reset. */
5737 return PCI_ERS_RESULT_NEED_RESET;
5738}
5739
5740/**
5741 * e1000_io_slot_reset - called after the pci bus has been reset.
5742 * @pdev: Pointer to PCI device
5743 *
5744 * Restart the card from scratch, as if from a cold-boot. Implementation
5745 * resembles the first-half of the e1000_resume routine.
5746 */
5747static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5748{
5749 struct net_device *netdev = pci_get_drvdata(pdev);
5750 struct e1000_adapter *adapter = netdev_priv(netdev);
5751 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005752 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005753 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005754 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005755
Bruce Allan78cd29d2011-03-24 03:09:03 +00005756 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5757 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005758 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005759 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5760 if (aspm_disable_flag)
5761 e1000e_disable_aspm(pdev, aspm_disable_flag);
5762
Bruce Allanf0f422e2008-08-04 17:21:53 -07005763 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005764 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005765 dev_err(&pdev->dev,
5766 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005767 result = PCI_ERS_RESULT_DISCONNECT;
5768 } else {
5769 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005770 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005771 pci_restore_state(pdev);
5772
5773 pci_enable_wake(pdev, PCI_D3hot, 0);
5774 pci_enable_wake(pdev, PCI_D3cold, 0);
5775
5776 e1000e_reset(adapter);
5777 ew32(WUS, ~0);
5778 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005779 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005780
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005781 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005782
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005783 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005784}
5785
5786/**
5787 * e1000_io_resume - called when traffic can start flowing again.
5788 * @pdev: Pointer to PCI device
5789 *
5790 * This callback is called when the error recovery driver tells us that
5791 * its OK to resume normal operation. Implementation resembles the
5792 * second-half of the e1000_resume routine.
5793 */
5794static void e1000_io_resume(struct pci_dev *pdev)
5795{
5796 struct net_device *netdev = pci_get_drvdata(pdev);
5797 struct e1000_adapter *adapter = netdev_priv(netdev);
5798
Bruce Allancd791612010-05-10 14:59:51 +00005799 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005800
5801 if (netif_running(netdev)) {
5802 if (e1000e_up(adapter)) {
5803 dev_err(&pdev->dev,
5804 "can't bring device back up after reset\n");
5805 return;
5806 }
5807 }
5808
5809 netif_device_attach(netdev);
5810
Bruce Allanad680762008-03-28 09:15:03 -07005811 /*
5812 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005813 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005814 * under the control of the driver.
5815 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005816 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005817 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005818
5819}
5820
5821static void e1000_print_device_info(struct e1000_adapter *adapter)
5822{
5823 struct e1000_hw *hw = &adapter->hw;
5824 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005825 u32 ret_val;
5826 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005827
5828 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005829 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005830 /* bus width */
5831 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5832 "Width x1"),
5833 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005834 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005835 e_info("Intel(R) PRO/%s Network Connection\n",
5836 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005837 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5838 E1000_PBANUM_LENGTH);
5839 if (ret_val)
Bruce Allane0dc4f12011-01-06 14:29:50 +00005840 strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1);
Bruce Allan073287c2010-11-24 06:01:51 +00005841 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5842 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005843}
5844
Auke Kok10aa4c02008-08-04 17:21:20 -07005845static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5846{
5847 struct e1000_hw *hw = &adapter->hw;
5848 int ret_val;
5849 u16 buf = 0;
5850
5851 if (hw->mac.type != e1000_82573)
5852 return;
5853
5854 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane2434552008-11-21 17:02:41 -08005855 if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005856 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005857 dev_warn(&adapter->pdev->dev,
5858 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005859 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005860}
5861
Bruce Allandc221292011-08-19 03:23:48 +00005862static int e1000_set_features(struct net_device *netdev, u32 features)
5863{
5864 struct e1000_adapter *adapter = netdev_priv(netdev);
5865 u32 changed = features ^ netdev->features;
5866
5867 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5868 adapter->flags |= FLAG_TSO_FORCE;
5869
5870 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
5871 NETIF_F_RXCSUM)))
5872 return 0;
5873
5874 if (netif_running(netdev))
5875 e1000e_reinit_locked(adapter);
5876 else
5877 e1000e_reset(adapter);
5878
5879 return 0;
5880}
5881
Stephen Hemminger651c2462008-11-19 21:57:48 -08005882static const struct net_device_ops e1000e_netdev_ops = {
5883 .ndo_open = e1000_open,
5884 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005885 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005886 .ndo_get_stats64 = e1000e_get_stats64,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00005887 .ndo_set_rx_mode = e1000_set_multi,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005888 .ndo_set_mac_address = e1000_set_mac,
5889 .ndo_change_mtu = e1000_change_mtu,
5890 .ndo_do_ioctl = e1000_ioctl,
5891 .ndo_tx_timeout = e1000_tx_timeout,
5892 .ndo_validate_addr = eth_validate_addr,
5893
Stephen Hemminger651c2462008-11-19 21:57:48 -08005894 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
5895 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
5896#ifdef CONFIG_NET_POLL_CONTROLLER
5897 .ndo_poll_controller = e1000_netpoll,
5898#endif
Bruce Allandc221292011-08-19 03:23:48 +00005899 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08005900};
5901
Auke Kokbc7f75f2007-09-17 12:30:59 -07005902/**
5903 * e1000_probe - Device Initialization Routine
5904 * @pdev: PCI device information struct
5905 * @ent: entry in e1000_pci_tbl
5906 *
5907 * Returns 0 on success, negative on failure
5908 *
5909 * e1000_probe initializes an adapter identified by a pci_dev structure.
5910 * The OS initialization, configuring of the adapter private structure,
5911 * and a hardware reset occur.
5912 **/
5913static int __devinit e1000_probe(struct pci_dev *pdev,
5914 const struct pci_device_id *ent)
5915{
5916 struct net_device *netdev;
5917 struct e1000_adapter *adapter;
5918 struct e1000_hw *hw;
5919 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05005920 resource_size_t mmio_start, mmio_len;
5921 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005922
5923 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005924 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005925 int i, err, pci_using_dac;
5926 u16 eeprom_data = 0;
5927 u16 eeprom_apme_mask = E1000_EEPROM_APME;
5928
Bruce Allan78cd29d2011-03-24 03:09:03 +00005929 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
5930 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005931 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005932 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5933 if (aspm_disable_flag)
5934 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005935
Bruce Allanf0f422e2008-08-04 17:21:53 -07005936 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005937 if (err)
5938 return err;
5939
5940 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00005941 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005942 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005943 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005944 if (!err)
5945 pci_using_dac = 1;
5946 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00005947 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005948 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00005949 err = dma_set_coherent_mask(&pdev->dev,
5950 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005951 if (err) {
5952 dev_err(&pdev->dev, "No usable DMA "
5953 "configuration, aborting\n");
5954 goto err_dma;
5955 }
5956 }
5957 }
5958
Arjan van de Vene8de1482008-10-22 19:55:31 -07005959 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07005960 pci_select_bars(pdev, IORESOURCE_MEM),
5961 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005962 if (err)
5963 goto err_pci_reg;
5964
Xiaotian Feng68eac462009-08-14 14:35:52 +00005965 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07005966 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00005967
Auke Kokbc7f75f2007-09-17 12:30:59 -07005968 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08005969 /* PCI config space info */
5970 err = pci_save_state(pdev);
5971 if (err)
5972 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005973
5974 err = -ENOMEM;
5975 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
5976 if (!netdev)
5977 goto err_alloc_etherdev;
5978
Auke Kokbc7f75f2007-09-17 12:30:59 -07005979 SET_NETDEV_DEV(netdev, &pdev->dev);
5980
Tom Herbertf85e4df2010-05-05 14:03:32 +00005981 netdev->irq = pdev->irq;
5982
Auke Kokbc7f75f2007-09-17 12:30:59 -07005983 pci_set_drvdata(pdev, netdev);
5984 adapter = netdev_priv(netdev);
5985 hw = &adapter->hw;
5986 adapter->netdev = netdev;
5987 adapter->pdev = pdev;
5988 adapter->ei = ei;
5989 adapter->pba = ei->pba;
5990 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00005991 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005992 adapter->hw.adapter = adapter;
5993 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00005994 adapter->max_hw_frame_size = ei->max_hw_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005995 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
5996
5997 mmio_start = pci_resource_start(pdev, 0);
5998 mmio_len = pci_resource_len(pdev, 0);
5999
6000 err = -EIO;
6001 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6002 if (!adapter->hw.hw_addr)
6003 goto err_ioremap;
6004
6005 if ((adapter->flags & FLAG_HAS_FLASH) &&
6006 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6007 flash_start = pci_resource_start(pdev, 1);
6008 flash_len = pci_resource_len(pdev, 1);
6009 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6010 if (!adapter->hw.flash_address)
6011 goto err_flashmap;
6012 }
6013
6014 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006015 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006016 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006017 netdev->watchdog_timeo = 5 * HZ;
6018 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006019 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
6020
6021 netdev->mem_start = mmio_start;
6022 netdev->mem_end = mmio_start + mmio_len;
6023
6024 adapter->bd_number = cards_found++;
6025
Bruce Allan4662e822008-08-26 18:37:06 -07006026 e1000e_check_options(adapter);
6027
Auke Kokbc7f75f2007-09-17 12:30:59 -07006028 /* setup adapter struct */
6029 err = e1000_sw_init(adapter);
6030 if (err)
6031 goto err_sw_init;
6032
Auke Kokbc7f75f2007-09-17 12:30:59 -07006033 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6034 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6035 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6036
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006037 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006038 if (err)
6039 goto err_hw_init;
6040
Bruce Allan4a770352008-10-01 17:18:35 -07006041 if ((adapter->flags & FLAG_IS_ICH) &&
6042 (adapter->flags & FLAG_READ_ONLY_NVM))
6043 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6044
Auke Kokbc7f75f2007-09-17 12:30:59 -07006045 hw->mac.ops.get_bus_info(&adapter->hw);
6046
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006047 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006048
6049 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006050 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006051 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6052 adapter->hw.phy.disable_polarity_correction = 0;
6053 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6054 }
6055
6056 if (e1000_check_reset_block(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006057 e_info("PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006058
Bruce Allandc221292011-08-19 03:23:48 +00006059 /* Set initial default active device features */
6060 netdev->features = (NETIF_F_SG |
6061 NETIF_F_HW_VLAN_RX |
6062 NETIF_F_HW_VLAN_TX |
6063 NETIF_F_TSO |
6064 NETIF_F_TSO6 |
6065 NETIF_F_RXCSUM |
6066 NETIF_F_HW_CSUM);
6067
6068 /* Set user-changeable features (subset of all device features) */
6069 netdev->hw_features = netdev->features;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006070
6071 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6072 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6073
Bruce Allandc221292011-08-19 03:23:48 +00006074 netdev->vlan_features |= (NETIF_F_SG |
6075 NETIF_F_TSO |
6076 NETIF_F_TSO6 |
6077 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006078
Yi Zou7b872a52010-09-22 17:57:58 +00006079 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006080 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006081 netdev->vlan_features |= NETIF_F_HIGHDMA;
6082 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006083
Auke Kokbc7f75f2007-09-17 12:30:59 -07006084 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6085 adapter->flags |= FLAG_MNG_PT_ENABLED;
6086
Bruce Allanad680762008-03-28 09:15:03 -07006087 /*
6088 * before reading the NVM, reset the controller to
6089 * put the device in a known good starting state
6090 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006091 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6092
6093 /*
6094 * systems with ASPM and others may see the checksum fail on the first
6095 * attempt. Let's give it a few tries
6096 */
6097 for (i = 0;; i++) {
6098 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6099 break;
6100 if (i == 2) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006101 e_err("The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006102 err = -EIO;
6103 goto err_eeprom;
6104 }
6105 }
6106
Auke Kok10aa4c02008-08-04 17:21:20 -07006107 e1000_eeprom_checks(adapter);
6108
Bruce Allan608f8a02010-01-13 02:04:58 +00006109 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006110 if (e1000e_read_mac_addr(&adapter->hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006111 e_err("NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006112
6113 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
6114 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
6115
6116 if (!is_valid_ether_addr(netdev->perm_addr)) {
Johannes Berg7c510e42008-10-27 17:47:26 -07006117 e_err("Invalid MAC Address: %pM\n", netdev->perm_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006118 err = -EIO;
6119 goto err_eeprom;
6120 }
6121
6122 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006123 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006124 adapter->watchdog_timer.data = (unsigned long) adapter;
6125
6126 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006127 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006128 adapter->phy_info_timer.data = (unsigned long) adapter;
6129
6130 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6131 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006132 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6133 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006134 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006135
Auke Kokbc7f75f2007-09-17 12:30:59 -07006136 /* Initialize link parameters. User can change them with ethtool */
6137 adapter->hw.mac.autoneg = 1;
Auke Kok309af402007-10-05 15:22:02 -07006138 adapter->fc_autoneg = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006139 adapter->hw.fc.requested_mode = e1000_fc_default;
6140 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006141 adapter->hw.phy.autoneg_advertised = 0x2f;
6142
6143 /* ring size defaults */
6144 adapter->rx_ring->count = 256;
6145 adapter->tx_ring->count = 256;
6146
6147 /*
6148 * Initial Wake on LAN setting - If APM wake is enabled in
6149 * the EEPROM, enable the ACPI Magic Packet filter
6150 */
6151 if (adapter->flags & FLAG_APME_IN_WUC) {
6152 /* APME bit in EEPROM is mapped to WUC.APME */
6153 eeprom_data = er32(WUC);
6154 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006155 if ((hw->mac.type > e1000_ich10lan) &&
6156 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006157 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006158 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6159 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6160 (adapter->hw.bus.func == 1))
6161 e1000_read_nvm(&adapter->hw,
6162 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
6163 else
6164 e1000_read_nvm(&adapter->hw,
6165 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
6166 }
6167
6168 /* fetch WoL from EEPROM */
6169 if (eeprom_data & eeprom_apme_mask)
6170 adapter->eeprom_wol |= E1000_WUFC_MAG;
6171
6172 /*
6173 * now that we have the eeprom settings, apply the special cases
6174 * where the eeprom may be wrong or the board simply won't support
6175 * wake on lan on a particular port
6176 */
6177 if (!(adapter->flags & FLAG_HAS_WOL))
6178 adapter->eeprom_wol = 0;
6179
6180 /* initialize the wol settings based on the eeprom settings */
6181 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006182 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006183
Bruce Allan84527592008-11-21 17:00:22 -08006184 /* save off EEPROM version number */
6185 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6186
Auke Kokbc7f75f2007-09-17 12:30:59 -07006187 /* reset the hardware with the new settings */
6188 e1000e_reset(adapter);
6189
Bruce Allanad680762008-03-28 09:15:03 -07006190 /*
6191 * If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006192 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006193 * under the control of the driver.
6194 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006195 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006196 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006197
Bruce Allane0dc4f12011-01-06 14:29:50 +00006198 strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006199 err = register_netdev(netdev);
6200 if (err)
6201 goto err_register;
6202
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006203 /* carrier off reporting is important to ethtool even BEFORE open */
6204 netif_carrier_off(netdev);
6205
Auke Kokbc7f75f2007-09-17 12:30:59 -07006206 e1000_print_device_info(adapter);
6207
Alan Sternf3ec4f82010-06-08 15:23:51 -04006208 if (pci_dev_run_wake(pdev))
6209 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006210
Auke Kokbc7f75f2007-09-17 12:30:59 -07006211 return 0;
6212
6213err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006214 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006215 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006216err_eeprom:
6217 if (!e1000_check_reset_block(&adapter->hw))
6218 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006219err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006220 kfree(adapter->tx_ring);
6221 kfree(adapter->rx_ring);
6222err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006223 if (adapter->hw.flash_address)
6224 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006225 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006226err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006227 iounmap(adapter->hw.hw_addr);
6228err_ioremap:
6229 free_netdev(netdev);
6230err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006231 pci_release_selected_regions(pdev,
6232 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006233err_pci_reg:
6234err_dma:
6235 pci_disable_device(pdev);
6236 return err;
6237}
6238
6239/**
6240 * e1000_remove - Device Removal Routine
6241 * @pdev: PCI device information struct
6242 *
6243 * e1000_remove is called by the PCI subsystem to alert the driver
6244 * that it should release a PCI device. The could be caused by a
6245 * Hot-Plug event, or because the driver is going to be removed from
6246 * memory.
6247 **/
6248static void __devexit e1000_remove(struct pci_dev *pdev)
6249{
6250 struct net_device *netdev = pci_get_drvdata(pdev);
6251 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006252 bool down = test_bit(__E1000_DOWN, &adapter->state);
6253
Bruce Allanad680762008-03-28 09:15:03 -07006254 /*
Tejun Heo23f333a2010-12-12 16:45:14 +01006255 * The timers may be rescheduled, so explicitly disable them
6256 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006257 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006258 if (!down)
6259 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006260 del_timer_sync(&adapter->watchdog_timer);
6261 del_timer_sync(&adapter->phy_info_timer);
6262
Bruce Allan41cec6f2009-11-20 23:28:56 +00006263 cancel_work_sync(&adapter->reset_task);
6264 cancel_work_sync(&adapter->watchdog_task);
6265 cancel_work_sync(&adapter->downshift_task);
6266 cancel_work_sync(&adapter->update_phy_task);
6267 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006268
Bruce Allan17f208d2009-12-01 15:47:22 +00006269 if (!(netdev->flags & IFF_UP))
6270 e1000_power_down_phy(adapter);
6271
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006272 /* Don't lie to e1000_close() down the road. */
6273 if (!down)
6274 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006275 unregister_netdev(netdev);
6276
Alan Sternf3ec4f82010-06-08 15:23:51 -04006277 if (pci_dev_run_wake(pdev))
6278 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006279
Bruce Allanad680762008-03-28 09:15:03 -07006280 /*
6281 * Release control of h/w to f/w. If f/w is AMT enabled, this
6282 * would have already happened in close and is redundant.
6283 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006284 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006285
Bruce Allan4662e822008-08-26 18:37:06 -07006286 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006287 kfree(adapter->tx_ring);
6288 kfree(adapter->rx_ring);
6289
6290 iounmap(adapter->hw.hw_addr);
6291 if (adapter->hw.flash_address)
6292 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006293 pci_release_selected_regions(pdev,
6294 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006295
6296 free_netdev(netdev);
6297
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006298 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006299 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006300
Auke Kokbc7f75f2007-09-17 12:30:59 -07006301 pci_disable_device(pdev);
6302}
6303
6304/* PCI Error Recovery (ERS) */
6305static struct pci_error_handlers e1000_err_handler = {
6306 .error_detected = e1000_io_error_detected,
6307 .slot_reset = e1000_io_slot_reset,
6308 .resume = e1000_io_resume,
6309};
6310
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006311static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006312 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6313 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6314 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6315 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6316 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6317 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006318 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6319 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6320 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006321
Auke Kokbc7f75f2007-09-17 12:30:59 -07006322 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6323 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6324 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6325 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006326
Auke Kokbc7f75f2007-09-17 12:30:59 -07006327 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6328 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6329 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006330
Bruce Allan4662e822008-08-26 18:37:06 -07006331 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006332 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006333 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006334
Auke Kokbc7f75f2007-09-17 12:30:59 -07006335 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6336 board_80003es2lan },
6337 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6338 board_80003es2lan },
6339 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6340 board_80003es2lan },
6341 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6342 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006343
Auke Kokbc7f75f2007-09-17 12:30:59 -07006344 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6345 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6346 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6347 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6348 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6349 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6350 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006351 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006352
Auke Kokbc7f75f2007-09-17 12:30:59 -07006353 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6354 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6355 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6356 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6357 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006358 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006359 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6360 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6361 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6362
6363 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6364 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6365 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006366
Bruce Allanf4187b52008-08-26 18:36:50 -07006367 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6368 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006369 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006370
Bruce Allana4f58f52009-06-02 11:29:18 +00006371 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6372 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6373 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6374 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6375
Bruce Alland3738bb2010-06-16 13:27:28 +00006376 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6377 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6378
Auke Kokbc7f75f2007-09-17 12:30:59 -07006379 { } /* terminate list */
6380};
6381MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6382
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006383#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006384static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006385 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6386 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6387 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006388};
David S. Millere50208a2010-03-16 23:36:24 -07006389#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006390
Auke Kokbc7f75f2007-09-17 12:30:59 -07006391/* PCI Device API Driver */
6392static struct pci_driver e1000_driver = {
6393 .name = e1000e_driver_name,
6394 .id_table = e1000_pci_tbl,
6395 .probe = e1000_probe,
6396 .remove = __devexit_p(e1000_remove),
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006397#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006398 .driver.pm = &e1000_pm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07006399#endif
6400 .shutdown = e1000_shutdown,
6401 .err_handler = &e1000_err_handler
6402};
6403
6404/**
6405 * e1000_init_module - Driver Registration Routine
6406 *
6407 * e1000_init_module is the first routine called when the driver is
6408 * loaded. All it does is register with the PCI subsystem.
6409 **/
6410static int __init e1000_init_module(void)
6411{
6412 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006413 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6414 e1000e_driver_version);
Bruce Allan0d6057e2011-01-04 01:16:44 +00006415 pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006416 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006417
Auke Kokbc7f75f2007-09-17 12:30:59 -07006418 return ret;
6419}
6420module_init(e1000_init_module);
6421
6422/**
6423 * e1000_exit_module - Driver Exit Cleanup Routine
6424 *
6425 * e1000_exit_module is called just before the driver is removed
6426 * from memory.
6427 **/
6428static void __exit e1000_exit_module(void)
6429{
6430 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006431}
6432module_exit(e1000_exit_module);
6433
6434
6435MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6436MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6437MODULE_LICENSE("GPL");
6438MODULE_VERSION(DRV_VERSION);
6439
6440/* e1000_main.c */